package main import ( "encoding/json" "errors" "sort" stdio "git.novox.be/novox/mesh-sdk/go" "mesh-delivery-builder/internal/build" "mesh-delivery-builder/internal/versions" ) // unbuildableTool is builder_unbuildable (design 47 H2 ยง795, H-A-425): the builder's state unbuildable, the plans no seat builds, // read in one page of at most 768 KB (capped says what it left out), with the summary line of the rows read. func unbuildableTool(page func() (versions.StatePage, error)) stdio.Tool { return stdio.Tool{Name: build.UnbuildableTool, Description: "The modules whose artifact no build seat builds, or whose build seat no module claims, as the builder judged their plans " + "(its state " + build.UnbuildableState + ", worked out again at every start and every change of the seat list): each module, the fingerprint " + "judged, the artifact's language and kind, why and when; with the one summary line the builder says of them. At most 768 KB, capped " + "saying what was left out. Read-only.", Input: map[string]any{"type": "object", "properties": map[string]any{}}, Run: func(map[string]any) (any, error) { pg, err := page() if err != nil { return nil, err } rows := []build.Unbuildable{} var unread []string for k, raw := range pg.Values { var u build.Unbuildable if err := json.Unmarshal(raw, &u); err != nil || u.Module == "" { unread = append(unread, k) continue } rows = append(rows, u) } sort.Slice(rows, func(i, j int) bool { return rows[i].Module < rows[j].Module }) sort.Strings(unread) out := map[string]any{"line": build.UnbuildableLine(rows), "unbuildable": rows} if len(unread) > 0 { out["unreadable"] = unread } if pg.More { out["capped"] = versions.StateCapped{State: build.UnbuildableState, KeysRead: len(pg.Values), StateKeys: pg.Keys, StateBytes: pg.Bytes, InfoWords: pg.InfoWords} } return out, nil }} } // unbuildablePage is the first page of the state unbuildable; a runtime that pages nothing is read key by key. func unbuildablePage(s stdio.KeptState) func() (versions.StatePage, error) { return func() (versions.StatePage, error) { pg, err := onePage(s.Page, s.Info) if !errors.Is(err, errors.ErrUnsupported) { return pg, err } keys, err := s.Keys() if err != nil { return versions.StatePage{}, err } out := versions.StatePage{Values: map[string]json.RawMessage{}} for _, k := range keys { if e, err := s.Get(k); err == nil && e != nil { out.Values[k] = e.Value } } return out, nil } }