Files
mesh-catalog/modules/mesh-knowledge/cmd/mesh-knowledge/highest.go
T
jschoubben 2369098303
mesh/merge-gate pass: builds mesh-issues, mesh-knowledge, records → novox; no bus step; every machine composes with the change as it did without (4 of 4 co…
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery superseded: a newer head of the same pull request
Nothing reads decision records from hq: records_decisions retired, reserve asks the knowledge base, an empty import refuses (hq issue 488)
Once the records leave hq (issue 426), records_decisions would answer every topic empty, reserve would read 0
and hand out 0001 from a counter not started, and import would say it created nothing as a success. reserve now
starts and raises its counters above mesh-knowledge's knowledge_highest, the floor alone starting one (with a
warning) when it is silent and nothing spent with neither.
2026-10-11 12:25:58 +02:00

63 lines
2.3 KiB
Go

package main
// The highest number held per kind (hq issue 488): what the issue tracker's reserve starts and raises its decision
// and research counters above (ADR 0275 rule 8, ADR 0290 rule 5), now that the records live here and hq's folders
// empty. Every number held counts — accepted, proposed, reserved or withdrawn — since each is spent.
import (
"context"
"errors"
"fmt"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// HighestTool is the module's tool the issue tracker asks.
const HighestTool = "knowledge_highest"
// Highest is the highest number held of each kind, and how many records are held.
type Highest struct {
Decision int `json:"decision"`
Research int `json:"research"`
Records int `json:"records"`
Says string `json:"says"`
}
// HighestHeld is the highest number held per kind. A knowledge base that holds no record answers none: a counter
// started from it would start at 1.
func (k *KB) HighestHeld() (*Highest, error) {
all, err := k.Store.All(context.Background())
if err != nil {
return nil, fmt.Errorf("the knowledge base cannot be read (%v); it answers no highest number", err)
}
h := &Highest{Records: len(all)}
for _, e := range all {
switch r := e.Current; r.Kind {
case KindDecision:
h.Decision = max(h.Decision, r.Number)
case KindResearch:
h.Research = max(h.Research, r.Number)
}
}
if h.Records == 0 {
return nil, errors.New("the knowledge base holds no record yet (it is imported from hq once): it answers no highest number")
}
h.Says = fmt.Sprintf("The highest numbers held, of %d records, every number spent counted: decision %04d, research %03d.",
h.Records, h.Decision, h.Research)
return h, nil
}
func highestTool(k *KB) stdio.Tool {
return stdio.Tool{Name: HighestTool,
Description: "The highest decision number and the highest research number the knowledge base holds, every number spent " +
"counted: accepted, proposed, reserved or withdrawn. The issue tracker starts and raises its counters above them. " +
"Refused while the knowledge base holds no record, or cannot be read: a number is never guessed.",
Input: schema(nil, map[string]any{}),
Run: func(m map[string]any) (any, error) {
if _, err := readArgs(HighestTool, m); err != nil {
return nil, err
}
return k.HighestHeld()
}}
}