Files
mesh-catalog/modules/claude-code/cmd/claude-code/proposal_tools.go
T
jochen 74e1be97ab
mesh/merge-gate fail: builds claude-code → ace, g14, novox, shanks; no bus step; a manifest the change touches fails the module check: claude-code uses the…
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
claude-code: an agent proposes a shared instruction section, and every node takes it only on the operator's warrant (hq ADR 0274)
Shared instructions were the terminal's alone since hq issue 340, because the tool runner cannot tell an
agent from the operator. The operator channel now proves who answered, so an agent may propose a section;
each node proves the router's warrant against the exact text itself and keeps what it approved in its own
file, so nothing written to the bus becomes active.
2026-10-10 03:40:48 +02:00

120 lines
4.8 KiB
Go

package main
// The tools and the watch of the shared instructions proposed for the operator's approval (novox/hq ADR 0274).
import (
"errors"
"strings"
"time"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/asks"
)
// Proposing is what the proposal tools reach: the `proposals` state, the operator channel, the controller's
// hand-act log, the clock and the managed directory. Nil outside a launch.
type Proposing struct {
Store ProposalStore
Bus AskBus
Record Recorder
Now func() time.Time
Write WriteManaged
}
var proposing *Proposing
// decideNow decides what the router closed, and renders when what reaches this node changed.
func (d *Proposing) decideNow(p Paths) {
changed, said, err := Reconcile(p, d.Store, d.Bus, d.Record, d.Now())
for _, line := range said {
say("%s", line)
}
if err != nil {
say("deciding the proposals: %v", err)
}
if changed {
if out, err := RenderNow(p, d.Write); err != nil {
say("rendering what the operator approved: %v", err)
} else {
for _, line := range out {
if !strings.HasSuffix(line, "unchanged") {
say("%s", line)
}
}
}
}
}
// watch decides on every word of the router's, every change of the proposals, and once a minute: a node that was
// away reads the router's record of what was decided meanwhile. One decider, woken by each.
func (d *Proposing) watch(p Paths) {
wake := make(chan struct{}, 1)
poke := func() {
select {
case wake <- struct{}{}:
default:
}
}
go persist("hearing the operator's answers", func() error {
return stdio.Subscribe(asks.Seat+".decided."+Module, func(stdio.Envelope) error { poke(); return nil })
}, func(n int) { say("hearing the operator's answers%s", refusals(n)) })
go persist("watching the proposals", func() error {
return stdio.State(ProposalsState).Watch("", func(stdio.StateChange) error { poke(); return nil })
}, func(n int) { say("watching the proposals%s", refusals(n)) })
go func() {
for range time.Tick(time.Minute) {
poke()
}
}()
poke()
for range wake {
d.decideNow(p)
}
}
func proposalTools(p Paths) []stdio.Tool {
notLaunched := errors.New("this module was not launched with the bus; nothing can be proposed")
return []stdio.Tool{
{Name: "claude_code_instructions_propose",
Description: "Propose an instruction section for every Claude session on the mesh (scope mesh) or on some nodes " +
"(scope node): a rule, a hand-over, the context a later session needs — or, with remove, the removal of one " +
"approved before. Nothing becomes active: the operator is asked on a channel that proves who answered " +
"(Telegram), shown the text (whole when it is short, else its first lines and its fingerprint), and the text " +
"reaches those sessions only on Approve. Decline, or no answer within a day, discards it. Refused for text " +
"that would run or read in something by itself (a shell line, front matter, an @ file reference), anything " +
"shaped like a secret, more than 16 KiB, a name set at the controller's terminal, or when no such channel is " +
"there (novox/hq ADR 0274, issue 340). claude_code_proposals shows where it stands.",
Input: map[string]any{
"scope": str("mesh (every node) or node (the nodes given, or this one)"),
"nodes": str("for scope node: a comma-separated list of nodes; absent is this node"),
"name": str("the section's name: lower-case letters, digits and -, e.g. handoff-from-g14"),
"text": str("the section's text, markdown, as every session will read it"),
"remove": map[string]any{"type": "boolean", "description": "propose removing the approved section of this name and scope instead"},
},
Run: func(a map[string]any) (any, error) {
if proposing == nil {
return nil, notLaunched
}
text, _ := a["text"].(string)
if text == "" {
text, _ = a["content"].(string)
}
return Propose(p, ProposeInput{Scope: scopeOf(a), Nodes: nodesOf(a["nodes"]), Name: strArg(a, "name"),
Text: text, Remove: boolArg(a, "remove")}, proposing.Store, proposing.Bus, proposing.Now())
}},
{Name: "claude_code_proposals",
Description: "The instruction sections proposed for the operator's approval (novox/hq ADR 0274), newest first: what " +
"each does, where it reaches, its fingerprint, and what this node made of it — waiting, approved, declined, " +
"discarded at expiry, or refused — and the sections approved here. With id, that proposal's whole text and " +
"digest: how the operator reads all of a long text before answering. Reads the router's word on each first.",
Input: map[string]any{"id": str("one proposal's id, for its whole text")},
Run: func(a map[string]any) (any, error) {
if proposing == nil {
return nil, notLaunched
}
proposing.decideNow(p)
return ListProposals(p, proposing.Store, proposing.Bus, strArg(a, "id"), proposing.Now())
}},
}
}