package main import ( "encoding/json" "errors" "fmt" "sort" "strings" "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" stdio "git.novox.be/novox/mesh-sdk/go" "mesh-delivery-builder/internal/build" "mesh-delivery-builder/internal/versions" ) // waitsTools are builder_waits, which reads the builder's toolchain waits, and builder_release, which builds an entry with // the running build module (design 47 G §276, §672): a hand act, recorded in the hand-act log first, then written to reasks // for the builder to answer. func waitsTools(rr versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool { str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) } return []stdio.Tool{ {Name: build.WaitsTool, Description: "The builder's toolchain waits: each entry held because its fingerprint names a toolchain version of its language other than the " + "agreed one, with its module, fingerprint, what it waits on (toolchain:@) and since when. It ends when the agreed toolchain " + "names that version (ran) or when " + build.ReleaseTool + " builds it with the running build module (released). Read-only.", Input: map[string]any{"type": "object", "properties": map[string]any{}}, Run: func(map[string]any) (any, error) { keys, err := rr.Keys() if err != nil { return nil, err } sort.Strings(keys) rows := []build.ToolchainWait{} for _, k := range keys { raw, ok, err := rr.Get(k) if err != nil || !ok { continue } var w build.ToolchainWait if json.Unmarshal(raw, &w) == nil { rows = append(rows, w) } } return map[string]any{"waits": rows}, nil }}, {Name: build.ReleaseTool, Description: "Build a held entry with the running build module now, whatever toolchain its fingerprint names (a toolchain wait of " + build.WaitsTool + "), and end its wait released. Written in the hand-act log (mesh-hand-acts).", Input: map[string]any{"type": "object", "required": []string{"module", "fp", "why"}, "properties": map[string]any{ "module": map[string]any{"type": "string", "description": "the module's name"}, "fp": map[string]any{"type": "string", "description": "its new-form fingerprint, src2:, as builder_waits shows it"}, "why": map[string]any{"type": "string", "description": "why, in plain words"}}}, Run: func(args map[string]any) (any, error) { key, value, err := build.NewRelease(str(args, "module"), str(args, "fp"), str(args, "why"), stdio.CallerOf(args), now()) if err != nil { return nil, err } if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("released the toolchain wait of %s at %s by hand", str(args, "module"), str(args, "fp")), Why: str(args, "why"), Cause: build.ReleaseTool, Verb: "release"}); err != nil { return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was released: %w", err) } raw, err := ask(key, value) if err != nil { return nil, err } a, err := build.DecodeReAsk(raw) if err != nil { return nil, err } if a.Refused { return nil, errors.New(a.Answer) } return map[string]any{"key": key, "answer": a.Answer}, nil }}, } }