fix(cli): autonomy set takes the bus's 64-hex revision (#1873, P1-3)

The panel's revision is the bus's sha256 of the organization, so a
whole-number --revision could never match a real Console. The fake in
cli-parity now answers hex revisions, and a whole number is a usage error.
This commit is contained in:
jason.woltje committed 2026-11-11 20:47:35 -06:00
1 parent 550bd084d0
commit 226e28d1e6
6 files changed
+30 -26

No files matched your search

+2 -2
View File
@@ -317,7 +317,7 @@ scripts/mosaic org role-templates <org> [--json]
scripts/mosaic org hire|change <org> --name <name> --template <template> --harness <harness> --model <model> [--thinking <level>] [--level org|project|root] [--project <project>] --reason <text> [--json]
scripts/mosaic org fire <org> --name <name> [--level org|project|root] [--project <project>] --reason <text> [--json]
scripts/mosaic org autonomy <org> [--json]
scripts/mosaic org autonomy <org> set --revision <n> [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours <n>] [--authority-resolver <name>] [--json]
scripts/mosaic org autonomy <org> set --revision <rev> [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours <n>] [--authority-resolver <name>] [--json]
scripts/mosaic org autonomy <org> review cross-role|merge|policy|authority [--json]
scripts/mosaic tasks create --title <text> --requirement <REQ-X-N> [--project <name>] [--state <state>] [--assignees <role,...>] [--priority 0-5] [--due <iso>|none] [--business <id>] [--json]
scripts/mosaic tasks edit task:<n> --expect <digest> [--title ...] [--state ...] [--assignees ...] [--priority ...] [--due ...] [--business <id>] [--json]
@@ -344,7 +344,7 @@ For local development on a named instance only, `mosaic bus start BUSINESS --dev
`mosaic console restart` and `mosaic org reload ORG` are the Console's Settings controls (F3) from a terminal (U1, #1873). Each sends one request to the running Console named in the instance's console state, as the page sends it (the Console's own Host and Origin, `Sec-Fetch-Site: same-origin`, a JSON `{}` body), so the Console applies the same owner, `--send` and origin checks and writes the same action trail, `<dataRoot>/console/actions.jsonl`. Both refuse inside an agent run (exit 3) before reading anything, and refuse with exit 3 when no Console runs. `console restart` works only for a Console started in the foreground by `mosaic console start`, or by `mosaic console start --dev-local-owner --detach`, which leaves a detached supervisor (`packages/cli/src/console-supervisor.mjs`, its own session) running the Console as the foreground start does; its receipt adds the supervisor's `supervisor` pid, and its later warnings go to `console/supervisor-*.log` under the data root. `mosaic console stop` stops that Console, and its supervisor then exits. `mosaic console start` refuses inside an agent run (exit 3), with or without `--dev-local-owner` or `--detach`, checking the starting process's own environment as well as the one given for the Console (agent-guard, #1873). A detached start whose supervisor does not reply within 60 seconds signals the supervisor's process group, then kills it, and clears `console/start.lock` only when the lock names that supervisor (pid and start time) and it is gone. Any other Console answers `not-supervised`. `console restart` waits up to 30 seconds for the relaunched Console to answer and prints `{"outcome":"restarted","from":OLD,"boot":NEW}`. `org reload ORG` restarts a running bus or starts a stopped one and prints the Console's done receipt. A request that left but got no answer is reported as outcome unknown (exit 1) and is never retried; check `mosaic console status`, `mosaic bus status ORG` and the trail. `mosaic bus restart ORG` remains the trail-less host verb.
The hire form and the autonomy panel from a terminal (E2, #1873, P1-3). `mosaic org role-templates|hire|fire|change ORG` and `mosaic org autonomy ORG [set|review]` send the page's own request to the running Console's org route (`/api/orgs/ORG/decisions/hire/templates|start`, `/api/orgs/ORG/autonomy[/review]`), as `org reload` does, so the Console applies the same owner, `--send`, origin, body and live-session checks and the same bus verbs run (`hire.templates.console`, `hire.start.console`, `autonomy.get.console`, `autonomy.set.console`, `autonomy.review.console`). `hire` and `change` read the templates first and send the chosen template's name and sha256, as the form does. `autonomy set` needs `--revision` from `mosaic org autonomy ORG` and sends every setting the panel sends, with only the named ones changed; a stale revision is refused `revision-conflict`. A Console refusal exits 3 with the Console's code and message; `outcome-unknown` exits 1; an unknown template exits 2. Every one of these verbs, reads included, refuses inside an agent run. `mosaic tasks create|edit|archive` are the task board's three writes: the arguments pass the board's own check (`workspace-tasks.mjs parseTaskWrite`) and go to the bus as the person (`tasks.create|edit|archive`, human transport), so the bus runs its human, field, digest and archive checks. A stale `--expect` is refused `task-conflict`; read the digest with `mosaic tasks --json`.
The hire form and the autonomy panel from a terminal (E2, #1873, P1-3). `mosaic org role-templates|hire|fire|change ORG` and `mosaic org autonomy ORG [set|review]` send the page's own request to the running Console's org route (`/api/orgs/ORG/decisions/hire/templates|start`, `/api/orgs/ORG/autonomy[/review]`), as `org reload` does, so the Console applies the same owner, `--send`, origin, body and live-session checks and the same bus verbs run (`hire.templates.console`, `hire.start.console`, `autonomy.get.console`, `autonomy.set.console`, `autonomy.review.console`). `hire` and `change` read the templates first and send the chosen template's name and sha256, as the form does. `autonomy set` needs the 64-hex `--revision` from `mosaic org autonomy ORG` and sends every setting the panel sends, with only the named ones changed; a stale revision is refused `revision-conflict`. A Console refusal exits 3 with the Console's code and message; `outcome-unknown` exits 1; an unknown template exits 2. Every one of these verbs, reads included, refuses inside an agent run. `mosaic tasks create|edit|archive` are the task board's three writes: the arguments pass the board's own check (`workspace-tasks.mjs parseTaskWrite`) and go to the bus as the person (`tasks.create|edit|archive`, human transport), so the bus runs its human, field, digest and archive checks. A stale `--expect` is refused `task-conflict`; read the digest with `mosaic tasks --json`.
The bus and Console lifecycle verbs refuse inside an agent run (agent-guard, #1873): `mosaic bus start`, `bus stop`, `bus restart` and `bus recover`, and `mosaic console start`, `console stop` and `console restart`, and `mosaic org archive` and `org delete`, which stop the organization's bus, and `mosaic org restore`, which starts it (`org restore --no-bus` starts nothing and is not refused), and `mosaic org role-templates`, `hire`, `fire`, `change` and `autonomy` (E2). Each exits 3 with `refused: this runs only from a human shell, outside any agent run (found MARKER in the environment)` before it reads anything. It checks the environment it is given and its own process environment, so a sanitized environment does not hide a marker. A usage error (a missing or extra argument, `--pm` with `--no-launch`, or a bad `--dev-insecure-bind`/`--dev-allow-host`) still comes first (exit 4). `mosaic bus status` and `mosaic console status` stay open to agents. The Console's Restart bus and Restart Console controls keep working: the Console starts its bus host with its own environment, which carries no marker, and Restart Console relaunches the Console under its supervisor without going through the CLI. The markers are the ones `packages/cli/src/transport.mjs` lists. The check is cooperative: a process that drops the markers from its environment is not stopped by it.
+2 -2
View File
@@ -1323,7 +1323,7 @@ mosaic org role-templates ORG [--json]
mosaic org hire|change ORG --name NAME --template TEMPLATE --harness H --model M [--thinking T] [--level org|project|root] [--project P] --reason TEXT [--json]
mosaic org fire ORG --name NAME [--level org|project|root] [--project P] --reason TEXT [--json]
mosaic org autonomy ORG [--json]
mosaic org autonomy ORG set --revision N [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME] [--json]
mosaic org autonomy ORG set --revision REV [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME] [--json]
mosaic org autonomy ORG review cross-role|merge|policy|authority [--json]
```
@@ -1331,7 +1331,7 @@ Each sends the page's own request to the running Console's org route, as
`org reload` does, so the Console runs the same owner, `--send`, origin, body
and session checks and the same bus verbs. `hire` and `change` read the role
templates first and send the chosen template's name and sha256. `autonomy set`
needs the `--revision` that `mosaic org autonomy ORG` prints and sends every
needs the 64-hex `--revision` that `mosaic org autonomy ORG` prints and sends every
setting the panel sends, changing only the named ones; a stale revision is
refused `revision-conflict`. A Console refusal exits 3 with its code and
message, an answer that never came exits 1, an unknown template exits 2. All of
+4 -3
View File
@@ -19,7 +19,7 @@ import { consoleOrgRequest } from './org-console.mjs';
import { refuseInsideAgent } from './transport.mjs';
export const ORG_OWNER_VERBS = Object.freeze(['role-templates', 'hire', 'fire', 'change', 'autonomy']);
export const ORG_OWNER_USAGE = 'mosaic org role-templates ID [--json] | hire|change ID --name NAME --template TEMPLATE --harness HARNESS --model MODEL [--thinking LEVEL] [--level org|project|root] [--project PROJECT] --reason TEXT [--json] | fire ID --name NAME [--level org|project|root] [--project PROJECT] --reason TEXT [--json] | autonomy ID [--json] | autonomy ID set --revision N [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME] [--json] | autonomy ID review cross-role|merge|policy|authority [--json]';
export const ORG_OWNER_USAGE = 'mosaic org role-templates ID [--json] | hire|change ID --name NAME --template TEMPLATE --harness HARNESS --model MODEL [--thinking LEVEL] [--level org|project|root] [--project PROJECT] --reason TEXT [--json] | fire ID --name NAME [--level org|project|root] [--project PROJECT] --reason TEXT [--json] | autonomy ID [--json] | autonomy ID set --revision REV [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME] [--json] | autonomy ID review cross-role|merge|policy|authority [--json]';
const usage = why => new CliError(`${why}\nusage: ${ORG_OWNER_USAGE}`, 4);
const ORG_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
@@ -63,7 +63,8 @@ function hireBody(op, v) {
function autonomyChanges(v) {
const revision = v['--revision'];
if (revision === undefined) throw usage('autonomy set needs --revision, the revision mosaic org autonomy ID shows');
if (!/^(0|[1-9][0-9]{0,14})$/.test(revision)) throw usage('--revision takes a whole number');
// The panel's revision is the bus's 64-hex digest of the organization (autonomy.set.console).
if (!/^[a-f0-9]{64}$/.test(revision)) throw usage('--revision takes the 64-hex revision mosaic org autonomy ID shows');
const changes = {};
for (const c of CLASSES) {
const value = v[`--${c}`];
@@ -81,7 +82,7 @@ function autonomyChanges(v) {
}
if (v['--authority-resolver'] !== undefined) changes.authorityResolver = v['--authority-resolver'];
if (!Object.keys(changes).length) throw usage('autonomy set needs a setting to change');
return { revision: Number(revision), changes };
return { revision, changes };
}
// The panel's save sends every class with the level it shows, notices, the reverse window (24 when
+1 -1
View File
@@ -48,7 +48,7 @@ const GUARDED = [
['org', 'change', 'alpha', '--name', 'ada', '--template', 'worker', '--harness', 'pi', '--model', 'glm', '--reason', 'r'],
['org', 'fire', 'alpha', '--name', 'ada', '--reason', 'r'],
['org', 'autonomy', 'alpha'],
['org', 'autonomy', 'alpha', 'set', '--revision', '1', '--merge', 'near'],
['org', 'autonomy', 'alpha', 'set', '--revision', 'a'.repeat(64), '--merge', 'near'],
['org', 'autonomy', 'alpha', 'review', 'merge'],
];
+20 -17
View File
@@ -67,12 +67,14 @@ function page(port, method, path, body) {
}).on('error', reject).end(payload);
});
}
// The bus's revision is a 64-hex digest; REV(n) stands in for the nth.
const REV = n => n.toString(16).padStart(64, '0');
const LOOP = { 'cross-role': 'in the loop', merge: 'in the loop', policy: 'in the loop', authority: 'in the loop' };
// One organization, alpha, whose bus transports record each call. `send` false is a Console
// started without --send.
function organizations({ send = true } = {}) {
const calls = [];
let state = { revision: 3, levels: { ...LOOP }, autonomy: { notices: false } };
let state = { revision: REV(3), levels: { ...LOOP }, autonomy: { notices: false } };
const org = {
busHealthy: true,
send: send ? async () => ({}) : null,
@@ -88,8 +90,8 @@ function organizations({ send = true } = {}) {
if (verb === 'autonomy.review.console') return { reviewed: args.decisionClass };
if (args.revision !== state.revision) throw new BusReadError('revision-conflict');
const { notices, reverseWindowHours, authorityResolver, ...levels } = args.autonomy;
state = { revision: state.revision + 1, levels, autonomy: { notices, reverseWindowHours, ...(authorityResolver ? { authorityResolver } : {}) } };
return { revision: state.revision, transaction: `tx-${state.revision}` };
state = { revision: REV(parseInt(state.revision, 16) + 1), levels, autonomy: { notices, reverseWindowHours, ...(authorityResolver ? { authorityResolver } : {}) } };
return { revision: state.revision, transaction: `tx-${parseInt(state.revision, 16)}` };
},
};
return { calls, organizations: { list: async () => [{ id: 'alpha' }], resolve: async id => (id === 'alpha' ? org : null) } };
@@ -111,7 +113,7 @@ const GUARDED = [
['org', 'change', 'alpha', ...HIRE],
['org', 'fire', 'alpha', '--name', 'ada', '--reason', 'done'],
['org', 'autonomy', 'alpha'],
['org', 'autonomy', 'alpha', 'set', '--revision', '3', '--merge', 'near'],
['org', 'autonomy', 'alpha', 'set', '--revision', REV(3), '--merge', 'near'],
['org', 'autonomy', 'alpha', 'review', 'merge'],
];
@@ -129,7 +131,8 @@ test('hire and autonomy verbs: usage errors first (exit 4), then refused inside
['org', 'fire', 'alpha', '--name', 'ada', '--reason', 'done', '--model', 'glm'],
['org', 'hire', 'alpha', ...HIRE, '--level', 'project'],
['org', 'autonomy', 'alpha', 'set', '--merge', 'near'],
['org', 'autonomy', 'alpha', 'set', '--revision', '3', '--merge', 'sideways'],
['org', 'autonomy', 'alpha', 'set', '--revision', REV(3), '--merge', 'sideways'],
['org', 'autonomy', 'alpha', 'set', '--revision', '3', '--merge', 'near'],
['org', 'autonomy', 'alpha', 'review', 'everything'],
['org', 'role-templates', 'Not An Id'],
]) {
@@ -221,7 +224,7 @@ test('autonomy reads, saves with the panel\'s revision check and records a revie
assert.equal(r.status, 0, r.stderr);
assert.deepEqual(JSON.parse(r.stdout), (await page(c.port, 'GET', '/api/orgs/alpha/autonomy')).body);
r = await mosaic(env, ['org', 'autonomy', 'alpha']);
assert.equal(r.stdout, 'revision 3\ncross-role: in the loop\nmerge: in the loop\npolicy: in the loop\nauthority: in the loop\nnotices: off\nreverse window: not set (the page offers 24 hours)\nauthority resolver: none\n');
assert.equal(r.stdout, `revision ${REV(3)}\ncross-role: in the loop\nmerge: in the loop\npolicy: in the loop\nauthority: in the loop\nnotices: off\nreverse window: not set (the page offers 24 hours)\nauthority resolver: none\n`);
c.calls.splice(0);
// The panel's save for "merge near the loop" (autonomy.js): every class as shown, notices, the
@@ -229,23 +232,23 @@ test('autonomy reads, saves with the panel\'s revision check and records a revie
const panel = { ...LOOP, merge: 'near the loop', notices: false, reverseWindowHours: 24 };
// Imported here so that the other tests still run, and fail on their own, on a base without it.
const { autonomyDocument } = await import('../src/org-owner.mjs');
assert.deepEqual(autonomyDocument({ revision: 3, levels: LOOP, autonomy: { notices: false } }, { merge: 'near the loop' }), panel);
r = await mosaic(env, ['org', 'autonomy', 'alpha', 'set', '--revision', '3', '--merge', 'near', '--json']);
assert.deepEqual(autonomyDocument({ revision: REV(3), levels: LOOP, autonomy: { notices: false } }, { merge: 'near the loop' }), panel);
r = await mosaic(env, ['org', 'autonomy', 'alpha', 'set', '--revision', REV(3), '--merge', 'near', '--json']);
assert.equal(r.status, 0, r.stderr);
assert.deepEqual(JSON.parse(r.stdout), { revision: 4, transaction: 'tx-4', writable: true });
assert.deepEqual(c.calls.splice(0), [{ verb: 'autonomy.get.console', args: {}, opts }, { verb: 'autonomy.set.console', args: { revision: 3, autonomy: panel }, opts }]);
assert.deepEqual(JSON.parse(r.stdout), { revision: REV(4), transaction: 'tx-4', writable: true });
assert.deepEqual(c.calls.splice(0), [{ verb: 'autonomy.get.console', args: {}, opts }, { verb: 'autonomy.set.console', args: { revision: REV(3), autonomy: panel }, opts }]);
// The page's save of the same document at revision 4 lands the same way.
const pageSave = await page(c.port, 'POST', '/api/orgs/alpha/autonomy', { revision: 4, autonomy: panel });
assert.deepEqual(pageSave.body, { revision: 5, transaction: 'tx-5', writable: true });
assert.deepEqual(c.calls.splice(0), [{ verb: 'autonomy.set.console', args: { revision: 4, autonomy: panel }, opts }]);
const pageSave = await page(c.port, 'POST', '/api/orgs/alpha/autonomy', { revision: REV(4), autonomy: panel });
assert.deepEqual(pageSave.body, { revision: REV(5), transaction: 'tx-5', writable: true });
assert.deepEqual(c.calls.splice(0), [{ verb: 'autonomy.set.console', args: { revision: REV(4), autonomy: panel }, opts }]);
// A stale revision is the panel's revision-conflict, and nothing changes.
r = await mosaic(env, ['org', 'autonomy', 'alpha', 'set', '--revision', '3', '--policy', 'near']);
const pageStale = await page(c.port, 'POST', '/api/orgs/alpha/autonomy', { revision: 3, autonomy: panel });
r = await mosaic(env, ['org', 'autonomy', 'alpha', 'set', '--revision', REV(3), '--policy', 'near']);
const pageStale = await page(c.port, 'POST', '/api/orgs/alpha/autonomy', { revision: REV(3), autonomy: panel });
assert.deepEqual(pageStale, { status: 409, body: { error: 'revision-conflict' } });
assert.equal(r.status, 3, r.stderr);
assert.match(r.stderr, /autonomy set refused \(revision-conflict\): the organization changed; read it again with mosaic org autonomy ID/);
assert.equal((await page(c.port, 'GET', '/api/orgs/alpha/autonomy')).body.revision, 5);
assert.equal((await page(c.port, 'GET', '/api/orgs/alpha/autonomy')).body.revision, REV(5));
c.calls.splice(0);
r = await mosaic(env, ['org', 'autonomy', 'alpha', 'review', 'merge']);
@@ -262,7 +265,7 @@ test('autonomy reads, saves with the panel\'s revision check and records a revie
r = await mosaic(env, ['org', 'autonomy', 'alpha', '--json']);
assert.equal(r.status, 0, r.stderr);
assert.equal(JSON.parse(r.stdout).writable, false);
for (const args of [['set', '--revision', '3', '--merge', 'near'], ['review', 'merge']]) {
for (const args of [['set', '--revision', REV(3), '--merge', 'near'], ['review', 'merge']]) {
r = await mosaic(env, ['org', 'autonomy', 'alpha', ...args]);
assert.equal(r.status, 3, r.stderr);
assert.match(r.stderr, /refused \(read-only\): start the Console with --send/);
+1 -1
View File
@@ -22,7 +22,7 @@ baseline CLI.
| Start, stop or restart a bus | `mosaic bus start <id>` / `mosaic bus stop <id>` / `mosaic bus restart <id>` | S6 integration hook |
| Restart (or first start) an organization's bus | `mosaic bus restart <id>`, or `mosaic bus start <id>` for a bus never started | Enabled (F3): the owner's **Restart bus** control, offered where a page says the bus is down or a change needs a restart; trailed |
| Restart the Console | Stop and run `mosaic console start` again | Enabled (F3) when `mosaic console start` runs it in the foreground, or with `--dev-local-owner --detach` under a detached supervisor (D1): Settings > Console; the owner only; trailed. Other Consoles answer `not-supervised` |
| Save, review, confirm or reverse an organization's autonomy | Read, save and review: `mosaic org autonomy ORG`, `mosaic org autonomy ORG set --revision N [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME]`, `mosaic org autonomy ORG review CLASS` (E2, through this route and its revision check); confirm and reverse act on inbox decisions and have no verb yet | Enabled (D1) on a `--dev-local-owner` Console: the owner only, on the selected organization's bus, behind a fence that passes only the four console verbs `autonomy.set.console`, `autonomy.review.console`, `decision.confirm.console` and `decision.reverse.console` |
| Save, review, confirm or reverse an organization's autonomy | Read, save and review: `mosaic org autonomy ORG`, `mosaic org autonomy ORG set --revision REV [--cross-role|--merge|--policy|--authority in|near|out] [--notices on|off] [--reverse-window-hours N] [--authority-resolver NAME]`, `mosaic org autonomy ORG review CLASS` (E2, through this route and its revision check); confirm and reverse act on inbox decisions and have no verb yet | Enabled (D1) on a `--dev-local-owner` Console: the owner only, on the selected organization's bus, behind a fence that passes only the four console verbs `autonomy.set.console`, `autonomy.review.console`, `decision.confirm.console` and `decision.reverse.console` |
| Hire, fire or change an agent; read role templates | `mosaic org role-templates ORG`; `mosaic org hire|change ORG --name NAME --template TEMPLATE --harness H --model M [--thinking T] [--level org|project|root] [--project P] --reason TEXT`; `mosaic org fire ORG --name NAME [--level ...] --reason TEXT` (E2, through this route) | Enabled (D4) for the owner on a selected organization's bus: one decision raised and approved through `hire.start.console`, with the bus's hire checks |
| Create, edit or archive a board task | `mosaic tasks create --title T --requirement REQ [--project P] [--state S] [--assignees R,...] [--priority 0-5] [--due ISO|none]`; `mosaic tasks edit task:N --expect DIGEST ...`; `mosaic tasks archive task:N --expect DIGEST` (E2: the board's own check, then the person's `tasks.create|edit|archive` on the bus) | Enabled for the owner on an organization with the built-in task store |
| Create chat project linked to a configured repository | `mosaic project create <name> --repo <project> --org <id>` | Enabled |