hand-acts read the whole log (84k entries, 47 MB) on every call and could never answer inside the call bound or the bus payload. It now reads from the newest entry backwards, page by page, and stops at the window's start, at 900 KiB of acts or at 20 s, saying complete: false, cut and why. warrants is bounded the same way. mesh-healers' start-up seed takes a partial answer and logs it, instead of retrying forever. Quick fix: this (mesh-catalog only, about 1.5 h). Thorough fix: also the tool runner never freezing on an oversized bundle line and logging unanswered calls (mesh-tools, a separate fix by another developer, lead's ruling Q3), and an SDK-side bound. Chosen here: quick for this module, the thorough part running beside it; the byte cap is the module's own (lead's ruling Q1, a `limit` argument is a later note). Claude-Session: https://claude.ai/code/session_01NcbgfFfQ4Z9UE5jK32PmE5
131 lines
5.6 KiB
Go
131 lines
5.6 KiB
Go
package main
|
|
|
|
// The seat's verbs (novox/hq ADR 0565 §10, §15): hand-act and warranted record, hand-acts reads both logs and, with
|
|
// warrants, every warrant recorded. A recovery is a call: a warrant whose act was lost is written again by asking
|
|
// warranted again, from the router's record.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// Verbs are the seat's verbs, as the manifest claims them.
|
|
var Verbs = []string{"hand-act", "hand-acts", "warranted"}
|
|
|
|
// Tool names.
|
|
const (
|
|
HandActTool = Seat + ".hand-act"
|
|
HandActsTool = Seat + ".hand-acts"
|
|
WarrantedTool = Seat + ".warranted"
|
|
// CopiedTool reads where the one-time copy of the controller's hand acts stands, CopyTool does it (copy.go).
|
|
CopiedTool = "hand_acts_copied"
|
|
CopyTool = "hand_acts_copy"
|
|
)
|
|
|
|
func obj(props map[string]any, required ...string) map[string]any {
|
|
m := map[string]any{"type": "object", "properties": props}
|
|
if len(required) > 0 {
|
|
m["required"] = required
|
|
}
|
|
return m
|
|
}
|
|
|
|
func str(d string) map[string]any { return map[string]any{"type": "string", "description": d} }
|
|
|
|
// Tools are what the runtime serves.
|
|
func Tools(l *Log) []stdio.Tool {
|
|
return []stdio.Tool{
|
|
{Name: HandActTool,
|
|
Description: "Record one act done by hand (novox/hq ADR 0565 §10): what was done, why, its cause in a word or a " +
|
|
"condition's kind (the word a second act for the same reason uses, which is how a repair done twice is " +
|
|
"found) and the condition it addresses. Who did it is the caller the runtime proves. verb is the act's " +
|
|
"verb as the log names it: a repair when not given, `hand-act drill` for a drill, or a recorder's own " +
|
|
"(`conditions silence`, `config set`). Said as act-recorded.",
|
|
Input: obj(map[string]any{"what": str("what was done"), "why": str("why, in a sentence"),
|
|
"cause": str("the cause, in a word or a condition's kind"), "condition": str("the condition's key, if any"),
|
|
"verb": str("the act's verb in the log; a repair when not given")}, "what", "why"),
|
|
Run: func(a map[string]any) (any, error) {
|
|
return l.HandAct(stdio.CallerOf(a), arg(a, "verb"), arg(a, "what"), arg(a, "why"), arg(a, "cause"), arg(a, "condition"))
|
|
}},
|
|
{Name: HandActsTool,
|
|
Description: "What was done by hand lately, from this seat's log (the controller's acts were copied into it), newest first: each act with who, why, its cause and which log holds it, and the causes repaired by " +
|
|
"hand twice or more within a fortnight (a healer is wanted). Narrowed by cause and who; warrants=true lists " +
|
|
"every warrant recorded instead.",
|
|
Input: obj(map[string]any{"days": map[string]any{"type": "number", "description": "how many days back (default 14)"},
|
|
"cause": str("only this cause"), "who": str("only acts whose who contains this"),
|
|
"warrants": str("\"true\": every warrant recorded, `<asker>.<ask>` with its act")}),
|
|
Run: func(a map[string]any) (any, error) {
|
|
if strings.EqualFold(arg(a, "warrants"), "true") || a["warrants"] == true {
|
|
return l.Warrants()
|
|
}
|
|
return l.HandActs(days(a), arg(a, "cause"), arg(a, "who")), nil
|
|
}},
|
|
{Name: WarrantedTool,
|
|
Description: "Record an asker's act on the operator's warrant (ADR 0274, ADR 0259): read from the router's own " +
|
|
"record of that ask — who chose, through which channel, with which proofs and which answer — never from the " +
|
|
"caller, once per ask; refused for an ask still open, ended without a choice, or another asker's.",
|
|
Input: obj(map[string]any{"asker": str("the module that asked"), "ask": str("its ask's id")}, "asker", "ask"),
|
|
Run: func(a map[string]any) (any, error) {
|
|
return l.Warranted(stdio.CallerOf(a), arg(a, "asker"), arg(a, "ask"))
|
|
}},
|
|
{Name: CopiedTool,
|
|
Description: "Where the one-time copy of the controller's hand acts into this seat's log ended (novox/hq research 072 " +
|
|
"row 26): the marker with when, by what and how many acts were copied, and how full the log is. The copy " +
|
|
"cannot run any more: the controller's log is no longer read. Changes nothing.",
|
|
Input: obj(map[string]any{}),
|
|
Run: func(map[string]any) (any, error) { return l.Copied() }},
|
|
{Name: CopyTool,
|
|
Description: "Answers that the copy is over (the controller's hand-act log " +
|
|
"is no longer read, novox/hq ADR 0571 §13) with the marker of the copy that was made; copies nothing.",
|
|
Input: obj(map[string]any{"top_up": str("\"true\": after the copy is done, append the acts written since")}),
|
|
Run: func(a map[string]any) (any, error) {
|
|
return l.Copy("tool, called by "+stdio.CallerOf(a), a["top_up"] == true || strings.EqualFold(arg(a, "top_up"), "true"))
|
|
}},
|
|
}
|
|
}
|
|
|
|
// Warrants is every warrant recorded, by key.
|
|
func (l *Log) Warrants() (any, error) {
|
|
keys, err := l.Store.Keys(WarrantsState)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the warrants cannot be read: %w", err)
|
|
}
|
|
sort.Strings(keys)
|
|
rows := map[string]json.RawMessage{}
|
|
size := 0
|
|
for i, k := range keys {
|
|
if raw, found, err := l.Store.Get(WarrantsState, k); err == nil && found {
|
|
if size += len(raw) + len(k); size > MaxAnswerBytes {
|
|
// Bounded like hand-acts: the answer always comes, and says what it left out.
|
|
return map[string]any{"warrants": rows, "count": len(rows), "complete": false, "cut": len(keys) - i}, nil
|
|
}
|
|
rows[k] = raw
|
|
}
|
|
}
|
|
return map[string]any{"warrants": rows, "count": len(rows), "complete": true}, nil
|
|
}
|
|
|
|
func arg(a map[string]any, k string) string {
|
|
s, _ := a[k].(string)
|
|
return strings.TrimSpace(s)
|
|
}
|
|
|
|
func days(a map[string]any) int {
|
|
switch v := a["days"].(type) {
|
|
case float64:
|
|
if v > 0 {
|
|
return int(v)
|
|
}
|
|
case string:
|
|
var n int
|
|
if _, err := fmt.Sscan(v, &n); err == nil && n > 0 {
|
|
return n
|
|
}
|
|
}
|
|
return 14
|
|
}
|