Merge pull request 'mesh-cli: nox licence prints the licences overview; every controller leftover removed (issue 1126 notes 151/152)' (#742) from fix/nox-licence-overview into main

This commit was merged in pull request #742.
This commit is contained in:
2026-11-22 20:02:14 +00:00
8 changed files with 390 additions and 116 deletions
+16 -12
View File
@@ -35,21 +35,24 @@ puts the call on the bus, as every agent session on the machine does. The consol
- **Who judges.** The seat that owns the job: a change of assignments is a proposal the operator approves
(`mesh-module-assigner.propose`), a config value is set with its why (`mesh-config.config`), a silence or a hand act is
recorded as one. Until novox/hq issue 1126 the controller ran these lines and judged the account (ADR 0272); with
the controller unassigned, that judgement went with it.
- **The map.** Every line the controller ran, and the seat verb or tool that does its job now, or none, is
`commands.go`'s table (and hq's `.work/1126/nox-map.md` while issue 1126 runs). A line no seat or module owns says
that it was the controller's, that the controller is unassigned, and what to use instead, and exits 1 having called
nothing. A line nox cannot read says how it is written and exits 2.
recorded as one.
- **The map.** Every line nox takes, and the seat verb or tool that does its job, is `commands.go`'s table. A line
nox does not know, or cannot read, says so and how lines are found or written, and exits 2 having called nothing.
- **Any address.** `nox call <address> [json]` calls any seat verb or tool; `nox search <words>` and
`nox describe <address>` find one and its arguments.
- **What is printed.** The owner's answer as the console gave it (JSON), on standard output with exit 0; an answer the
- **What is printed.** The owner's answer as the console gave it (JSON), or the line's table (`nox nodes`,
`nox licence`, `nox licence usage`; `--json` prints the answer raw), on standard output with exit 0; an answer the
console marks an error (a refusal, nothing serving, no answer within its bound) on standard error with exit 1. A
console that does not answer is said as nothing having been called; no answer in time is said as a call that may
have run.
- **`nox status`** is the delivery view's (`mesh-delivery-view.view_status`). When the view does not answer, nox says
so first, shows the open conditions and the deliveries under their own addresses, and exits 1: they are never
passed off as the status.
- **`nox licence`** (and `nox licence list`) is the operator's overview of the licences in one line
(one-question-one-tool): the licence manager's `licences` as one table (licence, kind, bound nodes, weekly, session
and sonnet usage with their resets, the token's expiry, failures, conditions, whether it is the target), then its
`bindings` (node, licence, since, why), every time local; with `--json` the two answers as one object
`{licences, bindings}`. `nox licence usage [<licence>]` is the manager's `usage` readings as a table.
- **`nox enrol open --key <file>`** runs here and asks nothing of the mesh (ADR 0587 §8).
A process that runs for a verb (it carries `MESH_VERB`) is refused before anything is called: a verb is never the
@@ -57,15 +60,16 @@ operator.
## What it does not do yet
- **No formatting beyond `nox nodes`.** Answers are the owners' JSON.
- **Lines with no owner.** Accepting a secret from a person, making or setting the operator key, opening a sealed
secret locally, registering a module from another repository and forgetting a module have no seat verb yet; nox
names what to use meanwhile.
- **No formatting beyond `nox nodes` and the licence lines.** Answers are the owners' JSON.
- **No line without a seat verb.** Accepting a secret from a person, making or setting the operator key, opening a
sealed secret locally, registering a module from another repository and forgetting a module have no seat verb yet,
so nox has no line for them.
## Tests
`go test ./...`: every owned line calls its owner's address with the arguments it reads, against a stand-in console
answering MCP `tools/call` as node-tools does; a line with no owner or not read calls nothing and says why; an error
answering MCP `tools/call` as node-tools does; a line not known or not read calls nothing and says why; the licence
lines print their tables from the manager's answers; an error
answer, a silent console and a verb's process are said; the status's fallback is labelled and exits 1; the console's
address is found; `enrol open` opens a sealed token locally; the module places the program and the console's address
and nothing else.
+22 -36
View File
@@ -1,8 +1,7 @@
package main
// Every command line nox takes, and the seat verb or module tool that owns its job now that the controller is
// unassigned (novox/hq issue 1126; the map is hq's .work/1126/nox-map.md). A line no seat or module owns says so and
// names what to use instead: it never fails silently, and it never pretends to have run.
// Every command line nox takes, and the seat verb or module tool that owns its job. A line nox does not know says so
// and calls nothing: it never fails silently, and it never pretends to have run.
import (
"encoding/json"
@@ -93,18 +92,25 @@ type command struct {
words []string
usage string
does string
// build reads the line and answers the call; nil for a line no seat owns.
// build reads the line and answers the call.
build func(l line) (call, error)
// allowed are the flags the line reads; any other is refused before anything is called.
allowed []string
// instead says, for a line with no owner, what to use; empty for one that is owned.
instead string
// render shapes a successful answer for reading; nil prints it as the console gave it.
// render shapes a successful answer for reading; nil prints it as the console gave it. With --json the answer is
// printed raw.
render func(text string) string
// also is a second call the line makes after the first, its answer read beside the first's; nil for a line of one
// call.
also *second
}
// gone is the reason every unowned line gives.
const gone = "this was the controller's, and the controller is unassigned (novox/hq issue 1126). Nothing was called"
// second is a line's second call: its address, asked with no arguments, the keys the two raw answers are printed
// under with --json, and the render that reads both answers.
type second struct {
address string
keys [2]string
render func(first, second string) string
}
// commands is every line, longest words first within a word.
var commands = []command{
@@ -120,8 +126,6 @@ var commands = []command{
{words: []string{"node", "public-domain"}, usage: "<node> [<domain> | --clear] [--why <text>]",
does: "the domain a node composes its routed names under; with a domain or --clear, proposed to assignments",
allowed: []string{"clear", "why"}, build: publicDomain},
{words: []string{"node", "add"}, instead: "a new machine joins through the seat mesh-node-enroller: nox enrol issue <node> --why <text>"},
{words: []string{"node", "networks"}, instead: "no seat keeps a node's routed networks yet; mesh-module-assigner.assignments shows what a node decides"},
{words: []string{"plan"}, usage: "<node>", does: "what the assigner wants the node to run", build: optNode("mesh-delivery-view.assigner_wants")},
{words: []string{"haves"}, usage: "[<node>]", does: "what each node runs, as its node-engine said", build: optNode("mesh-delivery-view.node_haves")},
{words: []string{"switch"}, does: "what each node runs, as its node-engine said", build: fixed("mesh-delivery-view.node_haves")},
@@ -135,7 +139,6 @@ var commands = []command{
{words: []string{"seats"}, does: "who holds each seat, and where", build: func(line) (call, error) {
return call{"mesh-module-assigner.assignments", map[string]any{"seats": "true"}}, nil
}},
{words: []string{"seat"}, instead: "a seat is held by placing its module: nox assign <node> <module> --why <text> (mesh-module-assigner.propose)"},
{words: []string{"assign"}, usage: "<node> <module>... --why <text>", does: "propose placing modules on a node",
allowed: []string{"why"}, build: placeModules("place")},
{words: []string{"unassign"}, usage: "<node> <module>... --why <text>", does: "propose taking modules off a node",
@@ -157,7 +160,6 @@ var commands = []command{
}},
{words: []string{"proposals"}, usage: "[<id>]", does: "the open proposals of assignments", build: optArg("mesh-module-assigner.proposals", "id")},
{words: []string{"overlay", "show"}, does: "every node's assignments, with its tunnel", build: fixed("mesh-module-assigner.assignments")},
{words: []string{"overlay"}, instead: "a node's tunnel is a decided field of its assignments: mesh-module-assigner.propose with op decide"},
// Deliveries and builds.
{words: []string{"deliveries"}, usage: "[--state s] [--repository owner/repo] [--group g] [--all]",
@@ -291,11 +293,7 @@ var commands = []command{
c, err := fixed("mesh-vault.secret_vault_export")(l)
return warranted(c, "the vault's sealed copies"), err
}},
{words: []string{"secret", "accept"}, instead: "mesh-vault.accept takes a value from the controller alone, and no seat takes one from a person yet; a module's own secret is asked at a desk (mesh-vault.secret-ask)"},
{words: []string{"secret", "recover"}, instead: "opening a sealed copy locally is not built yet (beside nox enrol open); nox secret export gives the sealed copies"},
{words: []string{"secret"}, instead: "nox secret export; mesh-vault.rotate makes one anew"},
{words: []string{"operator", "key", "show"}, does: "what needs a person's eye in the vault, the operator key among it", build: fixed("mesh-vault.vault_status")},
{words: []string{"operator"}, instead: "no seat sets or makes the operator key yet; nox operator key show reads it (mesh-vault.vault_status)"},
{words: []string{"rotate"}, usage: "[--node n --module m --name s | --provider n --provision p] --why <text>",
does: "make a secret anew", allowed: []string{"node", "module", "name", "provider", "provision", "consumer", "consumer_module", "why"},
build: func(l line) (call, error) {
@@ -353,7 +351,13 @@ var commands = []command{
}},
{words: []string{"images"}, usage: "<node>", does: "every container image a machine's wants and haves name", build: needArg("mesh-artifact-sweep.images", "node")},
{words: []string{"mirrors"}, does: "the bases the mesh copied into its store", build: fixed("mesh-artifact-sweep.mirrors")},
{words: []string{"licence", "list"}, does: "every licence the manager holds", build: fixed("anthropic-licence-manager.licences")},
// The operator's overview of the licences, in one line (one-question-one-tool).
{words: []string{"licence"}, does: "every licence: kind, bound nodes, usage and its resets, token expiry, failures, conditions, target; then the bindings",
build: fixed("anthropic-licence-manager.licences"), also: licenceBindings},
{words: []string{"licence", "list"}, does: "every licence: kind, bound nodes, usage and its resets, token expiry, failures, conditions, target; then the bindings",
build: fixed("anthropic-licence-manager.licences"), also: licenceBindings},
{words: []string{"licence", "usage"}, usage: "[<licence>]", does: "the usage readings, the latest first, of every licence or one",
build: optArg("anthropic-licence-manager.usage", "licence"), render: renderUsage},
{words: []string{"licence", "use"}, usage: "<consumer> <licence>", does: "move a node's agent to another licence",
build: func(l line) (call, error) {
if len(l.pos) != 2 {
@@ -363,7 +367,6 @@ var commands = []command{
}},
{words: []string{"licence", "refresh"}, usage: "[<licence>]", does: "refresh a licence now, or every due one", build: optArg("anthropic-licence-manager.refresh", "licence")},
{words: []string{"licence", "key"}, does: "the manager's public key", build: fixed("anthropic-licence-manager.public-key")},
{words: []string{"licence"}, instead: "anthropic-licence-manager.adopt takes an API key from a file on the manager's node; nox licence list|use|refresh|key"},
{words: []string{"module", "list"}, does: "every module the indexer holds", build: fixed("mesh-delivery-view.indexer_modules")},
{words: []string{"module", "show"}, usage: "<module>", does: "what the indexer holds of one module", build: needArg("mesh-delivery-view.indexer_module", "module")},
{words: []string{"head", "take"}, usage: "<owner/repository> <branch> --why <text>", does: "take a held head in by hand (design 47 H §742, H-A-105)", allowed: []string{"why"},
@@ -374,8 +377,6 @@ var commands = []command{
return call{"mesh-delivery-gate.gate_head_take", map[string]any{"repository": l.pos[0], "branch": l.pos[1], "why": l.flags["why"]}}, nil
}},
{words: []string{"head", "list"}, does: "every untaken head the gate holds", build: fixed("mesh-delivery-gate.gate_heads")},
{words: []string{"module"}, instead: "the indexer takes modules in from their repositories; nox module list|show, nox head take for a held head, and nothing forgets one by hand yet"},
{words: []string{"register"}, instead: "no seat registers a module from another repository yet (novox/hq ADR 0501 §4); nox head take <repository> <branch> takes a held head in"},
{words: []string{"account", "issue"}, usage: "<user>", does: "mint one bus account the grants part wants, now", build: needArg("mesh-vault.issue-account", "user")},
// Issues and records.
@@ -479,21 +480,6 @@ var commands = []command{
}},
}
// unowned are the controller's own lines that no seat or module took over, and what to use where there is anything.
var unowned = map[string]string{
"migrate": "", "prepare": "", "serve": "", "declare": "", "broker": "", "board": "", "api": "", "facts": "",
"rehearse": "", "take": "", "converge": "", "adopt": "", "move-placement": "", "move-config": "", "durations": "",
"data": "each machine's backups: nox call <node>/node-backup.backed-up",
"forget-checks": "nox checks <owner/repo>", "queue": "nox builds; nox stuck", "cancel": "nox deliveries",
"clear": "nox deliveries", "kill": "nox deliveries", "replay": "nox dead-letters",
"pause": "nox call <node>/node-build-go.pause (or node-build-node, node-build-image)",
"resume": "nox call <node>/node-build-go.resume (or node-build-node, node-build-image)",
"push": "a merge is delivered by mesh-delivery: nox deliveries; one version on one machine is mesh-delivery-assigner.assigner_put",
"deliver": "nox deliveries", "plans": "nox deliveries", "delivery-stop": "nox stalled",
"delivery-backups-again": "nox deliveries", "delivery-walks": "nox deliveries", "delivery-order": "nox deliveries",
"rollout": "nox upgrade <module>; delivery is mesh-delivery's: nox deliveries",
}
// find answers the command whose words begin the line, the longest first, and what follows them.
func find(args []string) (*command, []string) {
var best *command
+2 -3
View File
@@ -1,8 +1,7 @@
package main
// How mesh-cli reaches the mesh now that the controller is unassigned (novox/hq issue 1126): through this machine's
// console, the mesh MCP server the module node-tools serves on loopback (provision mcp-endpoint, ADR 0152: the
// machine's login is the authority). mesh-cli calls `mesh_call` with a seat verb's or a module tool's address, and the
// How mesh-cli reaches the mesh: through this machine's console, the mesh MCP server the module node-tools serves on
// loopback (provision mcp-endpoint, ADR 0152: the machine's login is the authority). mesh-cli calls `mesh_call` with a seat verb's or a module tool's address, and the
// console puts the call on the bus, the way every agent session on the machine does. mesh-cli holds no credential and
// keeps no bus account of its own.
+1 -1
View File
@@ -4,7 +4,7 @@ package main
//
// The seat mesh-node-enroller's `tokens` answers the token sealed to the operator key, which only the operator's private key
// opens; the mesh never holds it. This subcommand is local: it asks nothing of the node-engine's socket and nothing of
// the controller or the bus. It reads the sealed token (the base64 of the sealed box) on standard input and the private
// the bus. It reads the sealed token (the base64 of the sealed box) on standard input and the private
// key from a file (`--key`, the raw X25519 key in base64 that `operator key make` wrote), opens the box, and prints the
// token text a joining machine's `enrol` takes. The key is read from the file named and nowhere else, and never printed.
+176
View File
@@ -0,0 +1,176 @@
package main
// The operator's overview of the licences in one line (one-question-one-tool): the licence manager's licences and
// bindings as two tables, and its usage readings as one; every time is local.
import (
"encoding/json"
"fmt"
"strings"
"text/tabwriter"
"time"
)
// licenceBindings is the second call of `nox licence`: which licence each node is bound to, since when and why.
var licenceBindings = &second{address: "anthropic-licence-manager.bindings", keys: [2]string{"licences", "bindings"},
render: renderLicences}
// splitAnswer is the console's answer as its first JSON value and what the console said after it ("answered by ace").
func splitAnswer(text string) (json.RawMessage, string) {
dec := json.NewDecoder(strings.NewReader(text))
var v json.RawMessage
if err := dec.Decode(&v); err != nil {
return nil, text
}
return v, strings.TrimSpace(text[dec.InputOffset():])
}
// localTime is an RFC 3339 time in this machine's zone, to the minute; "-" for none, and the text itself when it is
// not one.
func localTime(s string) string {
if s == "" {
return "-"
}
t, err := time.Parse(time.RFC3339Nano, s)
if err != nil {
return s
}
return t.Local().Format("2006-01-02 15:04")
}
// percent is a reading with its reset when it has one; "-" for a reading the vendor did not give.
func percent(pct *float64, resets string) string {
if pct == nil {
return "-"
}
if resets == "" {
return fmt.Sprintf("%g %%", *pct)
}
return fmt.Sprintf("%g %% (resets %s)", *pct, localTime(resets))
}
func dashed(s string) string {
if s == "" {
return "-"
}
return s
}
// conditionNames are a licence's open conditions as their keys; a condition that is not a key is said as given.
func conditionNames(cs []json.RawMessage) string {
names := make([]string, 0, len(cs))
for _, c := range cs {
var s string
if json.Unmarshal(c, &s) == nil {
names = append(names, s)
continue
}
var o struct {
Key string `json:"key"`
}
if json.Unmarshal(c, &o) == nil && o.Key != "" {
names = append(names, o.Key)
continue
}
names = append(names, string(c))
}
return dashed(strings.Join(names, " "))
}
// renderLicences is the licences as one table, then the bindings as another; an answer it cannot read is printed as
// given.
func renderLicences(licences, bindings string) string {
var ls []struct {
Name string `json:"name"`
Kind string `json:"kind"`
Bound []string `json:"bound"`
Usage struct {
WeeklyPct *float64 `json:"weeklyPct"`
WeeklyResetsAt string `json:"weeklyResetsAt"`
SessionPct *float64 `json:"sessionPct"`
SessionResetsAt string `json:"sessionResetsAt"`
SonnetPct *float64 `json:"sonnetPct"`
} `json:"usage"`
AccessExpiresAt string `json:"accessExpiresAt"`
Failures int `json:"failures"`
Conditions []json.RawMessage `json:"conditions"`
Target bool `json:"target"`
}
var bs []struct {
Consumer string `json:"consumer"`
Licence string `json:"licence"`
Since string `json:"since"`
Why string `json:"why"`
}
lv, lafter := splitAnswer(licences)
bv, bafter := splitAnswer(bindings)
if lv == nil || json.Unmarshal(lv, &ls) != nil || bv == nil || json.Unmarshal(bv, &bs) != nil {
return licences + "\n" + bindings
}
var b strings.Builder
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "LICENCE\tKIND\tBOUND\tWEEKLY\tSESSION\tSONNET\tTOKEN EXPIRES\tFAILURES\tCONDITIONS\tTARGET")
for _, l := range ls {
target := "no"
if l.Target {
target = "yes"
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\n", l.Name, dashed(l.Kind), dashed(strings.Join(l.Bound, " ")),
percent(l.Usage.WeeklyPct, l.Usage.WeeklyResetsAt), percent(l.Usage.SessionPct, l.Usage.SessionResetsAt),
percent(l.Usage.SonnetPct, ""), localTime(l.AccessExpiresAt), l.Failures, conditionNames(l.Conditions), target)
}
w.Flush()
b.WriteString("\n")
w = tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NODE\tLICENCE\tSINCE\tWHY")
for _, x := range bs {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", x.Consumer, x.Licence, localTime(x.Since), dashed(x.Why))
}
w.Flush()
// Which machine answered each call, said once when both say the same.
for i, a := range []string{lafter, bafter} {
if a != "" && (i == 0 || a != lafter) {
b.WriteString(a + "\n")
}
}
return b.String()
}
// renderUsage is the usage readings as one table, the latest first as the manager answers them; an answer it cannot
// read is printed as given.
func renderUsage(text string) string {
var rs []struct {
At int64 `json:"at"`
Licence string `json:"licence"`
Reading struct {
WeeklyPct *float64 `json:"weeklyPct"`
WeeklyResetsAt string `json:"weeklyResetsAt"`
SessionPct *float64 `json:"sessionPct"`
SessionResetsAt string `json:"sessionResetsAt"`
SonnetResetsAt string `json:"sonnetResetsAt"`
} `json:"reading"`
}
v, after := splitAnswer(text)
if v == nil || json.Unmarshal(v, &rs) != nil {
return text
}
var b strings.Builder
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "LICENCE\tREAD AT\tWEEKLY\tSESSION\tRESETS")
for _, r := range rs {
var resets []string
for _, x := range [][2]string{{"weekly", r.Reading.WeeklyResetsAt}, {"session", r.Reading.SessionResetsAt},
{"sonnet", r.Reading.SonnetResetsAt}} {
if x[1] != "" {
resets = append(resets, x[0]+" "+localTime(x[1]))
}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", r.Licence, time.UnixMilli(r.At).Local().Format("2006-01-02 15:04"),
percent(r.Reading.WeeklyPct, ""), percent(r.Reading.SessionPct, ""), dashed(strings.Join(resets, ", ")))
}
w.Flush()
if after != "" {
b.WriteString(after + "\n")
}
return b.String()
}
+58 -26
View File
@@ -1,8 +1,8 @@
// Command mesh-cli is the operator's command on every node: `mesh-cli <command line>`, in interactive zsh also `nox`.
//
// Each line calls the seat verb or the module tool that owns its job (novox/hq issue 1126: the controller that ran
// these lines before is unassigned), through this machine's console, the mesh MCP server on loopback (console.go).
// A line no seat or module owns says so and names what to use instead. `enrol open` runs here and asks nothing.
// Each line calls the seat verb or the module tool that owns its job, through this machine's console, the mesh MCP
// server on loopback (console.go). A line nox does not know says so and calls nothing. `enrol open` runs here and asks
// nothing.
package main
import (
@@ -75,16 +75,10 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
}
c, rest := find(args)
if c == nil {
if instead, ok := unowned[args[0]]; ok {
return noOwner(args[0], instead, stderr)
}
fmt.Fprintf(stderr, "mesh-cli: %q is not a command. nox help lists them; nox search <words> finds a seat verb "+
"or a tool, and nox call <address> calls it\n", args[0])
return 2
}
if c.build == nil {
return noOwner(strings.Join(c.words, " "), c.instead, stderr)
}
k, err := c.read(rest)
if err != nil {
fmt.Fprintf(stderr, "mesh-cli: %v. Nothing was called\n nox %s %s\n", err, strings.Join(c.words, " "), c.usage)
@@ -100,7 +94,59 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
if k.Address == "mesh-delivery-view.view_status" {
return status(ctx, stdout, stderr)
}
return show(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args}, c.render, stdout, stderr)
render := c.render
l, _ := parseLine(rest)
if l.has("json") {
render = nil
}
if c.also != nil {
return showTwo(ctx, k, c.also, !l.has("json"), stdout, stderr)
}
return show(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args}, render, stdout, stderr)
}
// showTwo calls a line's two addresses in turn and prints both answers: through the line's render, or raw as one
// object under the line's two keys. The second is not called when the first fails, and either failing is said with
// exit 1.
func showTwo(ctx context.Context, first call, also *second, rendered bool, stdout, stderr io.Writer) int {
var texts [2]string
for i, k := range []call{first, {also.address, map[string]any{}}} {
a, err := consoleTool(ctx, "mesh_call", map[string]any{"address": k.Address, "arguments": k.Args})
if err != nil {
return failed(err, stderr)
}
if a.IsError {
fmt.Fprintln(stderr, "mesh-cli: "+k.Address+": "+strings.TrimRight(a.Text, "\n"))
return 1
}
texts[i] = a.Text
}
if rendered {
fmt.Fprintln(stdout, strings.TrimRight(also.render(texts[0], texts[1]), "\n"))
return 0
}
whole := map[string]json.RawMessage{}
var after []string
for i, text := range texts {
v, rest := splitAnswer(text)
if v == nil {
fmt.Fprintf(stderr, "mesh-cli: %s answered no JSON: %q\n", []string{first.Address, also.address}[i], text)
return 1
}
whole[also.keys[i]] = v
if rest != "" && (len(after) == 0 || after[0] != rest) {
after = append(after, rest)
}
}
b, err := json.MarshalIndent(whole, "", " ")
if err != nil {
return failed(err, stderr)
}
fmt.Fprintln(stdout, string(b))
for _, a := range after {
fmt.Fprintln(stdout, a)
}
return 0
}
// recordAct records the hand act a sensitive vault verb is warranted by, through mesh-hand-acts, and answers its id;
@@ -127,17 +173,6 @@ func recordAct(ctx context.Context, h handAct, stderr io.Writer) (string, int) {
return rec.Act.ID, 0
}
// noOwner says a line has no owner since the controller went, and what to use.
func noOwner(what, instead string, stderr io.Writer) int {
fmt.Fprintf(stderr, "mesh-cli: nox %s: %s.\n", what, gone)
if instead != "" {
fmt.Fprintf(stderr, " instead: %s\n", instead)
} else {
fmt.Fprintln(stderr, " no seat or module does this now; nox search <words> finds what does nearby")
}
return 1
}
// show calls one of the console's tools and prints what it answered: an answer marked an error on standard error, with
// exit 1.
func show(ctx context.Context, tool string, args map[string]any, render func(string) string, stdout, stderr io.Writer) int {
@@ -218,14 +253,11 @@ func usage() string {
b.WriteString(`mesh-cli: the operator's command (nox in interactive zsh)
Each line calls the seat verb or module tool that owns the job, through this machine's console (the mesh MCP
server on loopback). The controller that ran these lines before is unassigned (novox/hq issue 1126).
server on loopback).
`)
lines := make([]string, 0, len(commands))
for _, c := range commands {
if c.build == nil {
continue
}
lines = append(lines, fmt.Sprintf(" nox %s %s\n %s", strings.Join(c.words, " "), c.usage, c.does))
}
sort.Strings(lines)
@@ -239,7 +271,7 @@ server on loopback). The controller that ran these lines before is unassigned (n
open an enrolment token sealed to the operator key, here; asks nothing of the mesh
nox version
Every answer is the owner's own, as JSON. A line the controller ran that no seat owns says so and what to use.
Every answer is the owner's own, as JSON, or a table where the line says so; --json prints it raw.
`)
return b.String()
}
+112 -35
View File
@@ -77,8 +77,8 @@ func runLine(args ...string) (int, string, string) {
return code, out.String(), errOut.String()
}
// Every owned line calls the seat verb or module tool that owns its job, with the arguments the owner reads
// (novox/hq issue 1126; hq .work/1126/nox-map.md), and prints its answer.
// Every line calls the seat verb or module tool that owns its job, with the arguments the owner reads, and prints its
// answer.
func TestEachLineCallsItsOwner(t *testing.T) {
now = func() time.Time { return time.Date(2026, 11, 2, 10, 0, 0, 0, time.UTC) }
t.Cleanup(func() { now = time.Now })
@@ -121,14 +121,14 @@ func TestEachLineCallsItsOwner(t *testing.T) {
{"settings clear zsh execute --node g14 --why test", "mesh-config.config", `{"action":"clear","key":"execute","module":"zsh","node":"g14","why":"test"}`},
{"config history --key k --limit 5", "mesh-config.config", `{"action":"history","key":"k","limit":5}`},
{"operator key show", "mesh-vault.vault_status", `{}`},
// A cleanup without --confirm deletes nothing, so no hand act is recorded for it (issue 1126 review 2).
// A cleanup without --confirm deletes nothing, so no hand act is recorded for it.
{"cleanup delete ace.plex --why dry", "mesh-vault.provisioner_delete", `{"consumer":"ace.plex","why":"dry"}`},
{"collect --confirm --why space", "mesh-artifact-sweep.collect", `{"confirm":"true","why":"space"}`},
{"images ace", "mesh-artifact-sweep.images", `{"node":"ace"}`},
{"licence use g14 work", "anthropic-licence-manager.switch", `{"consumer":"g14","licence":"work"}`},
{"module show plex", "mesh-delivery-view.indexer_module", `{"module":"plex"}`},
{"issues apostrophe bug --status open --limit 5", "issue-tracker.list", `{"limit":5,"search":"apostrophe bug","status":"open"}`},
{"issue 1126 --brief", "issue-tracker.get", `{"brief":true,"number":1126}`},
{"issue 294 --brief", "issue-tracker.get", `{"brief":true,"number":294}`},
{"kb ask what holds about the merge window", "knowledge-base.ask", `{"question":"what holds about the merge window"}`},
{"kb get 587 --reasoning", "knowledge-base.get", `{"number":587,"reasoning":true}`},
{"progress 47", "knowledge-base.progress", `{"of":"design 47"}`},
@@ -154,42 +154,43 @@ func TestEachLineCallsItsOwner(t *testing.T) {
}
}
// A line the controller ran that no seat owns says so and what to use, exits 1 and calls nothing; a line nox cannot
// read says how it is written, exits 2 and calls nothing.
func TestALineWithNoOwnerOrNotReadCallsNothingAndSaysWhy(t *testing.T) {
// 1126/AC4: a line nox cannot read says how it is written, exits 2 and calls nothing; the controller's retired lines are gone with
// it, not mapped to a refusal (the operator, 2026-11-22: "why are there still references to the controller?"), and
// nothing nox says names the controller.
func TestALineNotReadCallsNothingAndSaysWhy(t *testing.T) {
for _, c := range []struct {
line string
code int
err string
}{
{"push ace", 1, "mesh-delivery-assigner.assigner_put"},
{"migrate", 1, "no seat or module does this now"},
{"secret accept ace plex token", 1, "mesh-vault.secret-ask"},
{"node add new1", 1, "nox enrol issue"},
{"pause", 1, "node-build-go.pause"},
{"operator key make", 1, "operator key show"},
{"assign ace plex", 2, "needs --why"},
{"issue twelve", 2, "not an issue's number"},
{"conditions --bogus x", 2, "--bogus is not a flag"},
{"settings set zsh {\"execute\":\"withhold\"} --node g14 --why x", 2, "set each key"},
{"healers --days soon", 2, "takes a number"},
{"config propose --pull novox/x#1", 2, "--pull is not a flag"},
{"frobnicate", 2, "is not a command"},
{"push ace", "is not a command"},
{"migrate", "is not a command"},
{"secret accept ace plex token", "is not a command"},
{"node add new1", "is not a command"},
{"pause", "is not a command"},
{"operator key make", "is not a command"},
{"module forget plex", "is not a command"},
{"assign ace plex", "needs --why"},
{"issue twelve", "not an issue's number"},
{"conditions --bogus x", "--bogus is not a flag"},
{"settings set zsh {\"execute\":\"withhold\"} --node g14 --why x", "set each key"},
{"healers --days soon", "takes a number"},
{"config propose --pull novox/x#1", "--pull is not a flag"},
{"frobnicate", "is not a command"},
// The checker and the groups go whole (design 47 H §764): nox calls neither.
{"try novox/mesh-catalog abc123 --level unit", 2, "is not a command"},
{"groups", 2, "is not a command"},
{"checks novox/mesh-catalog --number 591", 2, "is not a command"},
{"try novox/mesh-catalog abc123 --level unit", "is not a command"},
{"groups", "is not a command"},
{"checks novox/mesh-catalog --number 591", "is not a command"},
} {
got := console(t, nil)
args := strings.Fields(c.line)
code, _, errOut := runLine(args...)
if code != c.code || len(*got) != 0 || !strings.Contains(errOut, c.err) {
t.Errorf("nox %s: exit %d, asked %+v, stderr %q; want exit %d saying %q", c.line, code, *got, errOut, c.code, c.err)
}
if c.code == 1 && !strings.Contains(errOut, "issue 1126") {
t.Errorf("nox %s does not say the controller is unassigned: %q", c.line, errOut)
if code != 2 || len(*got) != 0 || !strings.Contains(errOut, c.err) || strings.Contains(errOut, "controller") {
t.Errorf("nox %s: exit %d, asked %+v, stderr %q; want exit 2 saying %q", c.line, code, *got, errOut, c.err)
}
}
if strings.Contains(usage(), "controller") {
t.Errorf("the help still names the controller:\n%s", usage())
}
}
// What the console says is printed as said: an answer it marks an error on standard error with exit 1, a console that
@@ -279,16 +280,13 @@ func TestEveryLineIsInTheHelpOnce(t *testing.T) {
if c.build != nil && !strings.Contains(help, "nox "+w+" ") {
t.Errorf("nox %s is not in the help", w)
}
if c.build == nil && c.instead == "" {
t.Errorf("nox %s has neither an owner nor an instead", w)
}
if _, dup := unowned[c.words[0]]; dup && len(c.words) == 1 {
t.Errorf("nox %s is both owned and unowned", w)
if c.build == nil {
t.Errorf("nox %s has no owner", w)
}
}
}
// ADR 0590 §8 (issue 1126 review 1): each sensitive vault verb judges its own caller, and nox reaches the vault as its
// ADR 0590 §8: each sensitive vault verb judges its own caller, and nox reaches the vault as its
// machine's runtime, so nox first records the hand act that warrants the line through mesh-hand-acts (the vault verb as
// its verb, what it acts on as its what) and names it as `act`; a recording refused calls the vault not at all.
func TestASensitiveLineRecordsItsHandActAndNamesIt(t *testing.T) {
@@ -322,3 +320,82 @@ func TestASensitiveLineRecordsItsHandActAndNamesIt(t *testing.T) {
t.Errorf("a refused recording: exit %d, asked %+v, %q", code, *got, errOut)
}
}
// 1126/AC1, 1126/AC2, 1126/AC3: the operator's overview of the licences is one line (one-question-one-tool): `nox licence` and
// `nox licence list` call the licence manager's licences and bindings and print one table of each, every time local;
// `nox licence usage` prints the readings; --json prints the raw answers, the two as one object.
func TestTheLicencesAreOneTable(t *testing.T) {
local := time.Local
time.Local = time.FixedZone("CET", 3600)
t.Cleanup(func() { time.Local = local })
licences := `[{"name":"work","account":"a@example.org","kind":"subscription","bound":["ace","novox"],
"usage":{"readAt":"2026-11-22T19:32:27Z","weeklyPct":2,"weeklyResetsAt":"2026-11-25T01:59:59.5+00:00",
"sessionPct":7,"sessionResetsAt":"2026-11-23T00:29:59+00:00","sonnetPct":null},
"accessExpiresAt":"2026-11-23T01:56:57Z","refreshExpiresAt":"2026-12-14T01:48:16Z","room":98,
"failures":0,"conditions":[],"target":true},
{"name":"home","account":"b@example.org","kind":"subscription","bound":[],
"usage":{"weeklyPct":99,"weeklyResetsAt":"2026-11-25T10:59:59+00:00","sessionPct":null,"sonnetPct":40},
"accessExpiresAt":"2026-11-23T02:02:57Z","failures":2,"conditions":["licence.home.full"],"target":false}]`
bindings := `[{"consumer":"g14","licence":"home","kind":"subscription","generation":3,"since":"2026-11-22T19:32:28Z",
"why":"work reached 99 % of its weekly window","by":"usage"}]`
usage := `[{"at":1795376250078,"licence":"work","reading":{"weeklyPct":4,"weeklyResetsAt":"2026-11-29T17:59:59+00:00",
"sessionPct":null,"sonnetPct":null}}]`
answers := map[string]string{"anthropic-licence-manager.licences": licences,
"anthropic-licence-manager.bindings": bindings, "anthropic-licence-manager.usage": usage}
for _, words := range []string{"licence", "licence list"} {
got := console(t, answers)
code, out, errOut := runLine(strings.Fields(words)...)
if code != 0 || errOut != "" || len(*got) != 2 || (*got)[0].Address != "anthropic-licence-manager.licences" ||
(*got)[1].Address != "anthropic-licence-manager.bindings" || (*got)[1].Args != `{}` {
t.Fatalf("nox %s: exit %d, stderr %q, asked %+v", words, code, errOut, *got)
}
for _, want := range []string{
"LICENCE", "KIND", "BOUND", "WEEKLY", "SESSION", "SONNET", "TOKEN EXPIRES", "FAILURES", "CONDITIONS", "TARGET",
"work", "ace novox", "2 % (resets 2026-11-25 02:59)", "7 % (resets 2026-11-23 01:29)", "2026-11-23 02:56", "yes",
"home", "99 % (resets 2026-11-25 11:59)", "40 %", "licence.home.full",
"NODE", "SINCE", "WHY", "g14", "2026-11-22 20:32", "work reached 99 % of its weekly window",
} {
if !strings.Contains(out, want) {
t.Errorf("nox %s does not print %q:\n%s", words, want, out)
}
}
if strings.Contains(out, "2026-12-14") || strings.Contains(out, "98") {
t.Errorf("nox %s prints the refresh-token expiry or the room:\n%s", words, out)
}
}
// 1126/AC3: --json prints the raw answers, the two calls' as one object.
console(t, answers)
code, out, _ := runLine("licence", "--json")
var raw struct {
Licences []map[string]any `json:"licences"`
Bindings []map[string]any `json:"bindings"`
}
if err := json.Unmarshal([]byte(strings.SplitN(out, "\nanswered by", 2)[0]), &raw); code != 0 || err != nil ||
len(raw.Licences) != 2 || len(raw.Bindings) != 1 {
t.Errorf("nox licence --json: exit %d, %v:\n%s", code, err, out)
}
// 1126/AC3: on every rendered line, as on the nodes.
nodes := `{"keys":{"ace":{"assignments":{"decided":{"address":"10.0.0.1"},"modules":[]}}}}`
console(t, map[string]string{"mesh-module-assigner.assignments": nodes})
if code, out, _ := runLine("nodes", "--json"); code != 0 || !strings.HasPrefix(out, nodes) {
t.Errorf("nox nodes --json: exit %d, does not print the raw answer:\n%s", code, out)
}
// 1126/AC2: the usage readings as one table.
got := console(t, answers)
code, out, errOut := runLine("licence", "usage", "work")
if code != 0 || len(*got) != 1 || (*got)[0].Address != "anthropic-licence-manager.usage" || (*got)[0].Args != `{"licence":"work"}` {
t.Fatalf("nox licence usage work: exit %d, stderr %q, asked %+v", code, errOut, *got)
}
for _, want := range []string{"LICENCE", "READ AT", "WEEKLY", "SESSION", "RESETS", "work",
time.UnixMilli(1795376250078).Local().Format("2006-01-02 15:04"), "4 %", "weekly 2026-11-29 18:59"} {
if !strings.Contains(out, want) {
t.Errorf("nox licence usage does not print %q:\n%s", want, out)
}
}
if code, _, _ := runLine("licence", "usage", "--limit", "5"); code != 2 {
t.Errorf("nox licence usage --limit is read (exit %d); it takes no limit", code)
}
}
@@ -24,8 +24,8 @@ func TestTheArchivePlacesExactlyOneFileAndTheConsolesAddressOne(t *testing.T) {
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
// Beside the program, one directory and one file: the console's address, from the mcp-endpoint it requires
// (novox/hq issue 1126). Nothing else.
// Beside the program, one directory and one file: the console's address, from the mcp-endpoint it requires.
// Nothing else.
var r map[string]any
for _, res := range m.Resources {
switch {
@@ -43,7 +43,7 @@ func TestTheArchivePlacesExactlyOneFileAndTheConsolesAddressOne(t *testing.T) {
if len(m.Resources) != 3 || r == nil || r["path"] != "/usr/local/bin" {
t.Fatalf("its resources are %v", m.Resources)
}
// The build has a second artifact, the files archive the controller reads the templates back from; it
// The build has a second artifact, the files archive the templates are read back from; it
// places no file. The artifact the resource unpacks is the one that does.
var a map[string]any
for _, candidate := range m.Build.Artifacts {