Compare commits

..
59 changed files with 230 additions and 14103 deletions
-4
View File
@@ -5177,7 +5177,3 @@ Before: managed project/thread verbs had no Console conversation area. After: fi
2026-10-21T01:28:05Z | Darkwing | row 232 #1734 installer I1 build, round 1 in review | Before: stack-release.sh managed only user units (systemctl --user), and stack-copy.sh had no bundle copy. After: --units external (adopt, activate, rollback --to, status, confirm, revert, gate --since, AWAITING-UNITS, stale-start, external-pm, --plan --expect-from) and stack-copy check --units external, copy --bundle FILE SHA, wrapper ID --create; user mode byte-identical to the base by test. First build 0af0c73c6 on 00d4cc1f6; rebased onto row 200 (cb5fdb064) as a0ffabc3f on darkwing/row232-r1; --sso refused under external (D9), row 200 config_checks run under external (D10). Gate on Sage's slot (sage-1618): cli 561/0, every scripts/test-*.sh green; 17/17 mutants killed. Results commit 84f1a91e6 (pushed, seat branch only). Manifest 7a3b4ea1 (9 paths), queue revs 2595-2596, request comment 29825, reviewer Filbert. Packet agents/darkwing/work/queue-232/BUILD.md.
2026-10-21T04:50:44Z | Darkwing | row 233 #1735 installer I3 build, round 1 in review | Before: root had no upgrade driver for root-owned units and no host run sheet; stack-release.sh had no rehearse --backup last and no external plan refusals. After: scripts/stack-upgrade.sh upgrade and rollback (r6 A1-A5, A2f, R1-R4) with 20 tests, docs/guides/host-run-sheet.md, TOOLS.md lines, and on Sage's rulings stack-release.sh --backup last, BACKUP_STORE and the --plan refusals open-activation and migrate-required (3 tests). Base e65a3ab4d (row 232's landing). Gate on Sage's slot (sage-1704) on d99166ade: cli 616/0, every scripts/test-*.sh green, 1201/0 summed by awk; m1-m8 8/8 killed. Correction: the process sweep after the gate found an orphaned sleep 60 from the lock test's flock holder (N1); 08db6ac3f fixes it test only, Sage ruled the gate stands (sage-1707), rerun c0 20/0 and m1 killed with 0 left (sage-1708). Tip 1a1dc80ca (pushed, seat branch only). Manifest 464ce9eb (7 paths), queue revs 2644 and 2647, request comment 29901, reviewer Filbert. Packet agents/darkwing/work/queue-233/BUILD.md.
2026-10-21T06:37:41Z | Darkwing | row 240 #1746 installer I4 build, round 1 in review | Before: root had no host check for the bwrap AppArmor profile, its pins or a boot unit, and stack-upgrade.sh exited 1 args-failed when the args move after A5 failed, while exit 1 means the old copy runs. After: scripts/case1-hostcheck.sh (seven items, --check, --enforce, --upstream), scripts/case1-pins.sh, mosaic-hostcheck.service and 16 tests; the args move failure exits 5 args-failed, documented in TOOLS.md and run sheet section 6 and tested; run sheet section 3 puts the pinned npm on PATH and names the bin/claude.exe --claude path; sections 8 and 10 have precheck lines. Verification: slot run r1 on 47ec9fe2f failed at the singles (the new N1 test's after hook threw ENOENT after the fixture cleanup removed the root); b45852daa drops the hook; r2 on b45852daa green: singles 16/0 and 21/0, c0 plus M1-M8 8/8 killed, cli 639/0, scripts 585/0. Candidate darkwing/row240-r3 ad1b23ab2 on c771a36f4, manifest 573ece95 (9 paths), revs 2694 and 2695, comment 29943.
2026-10-21T16:04:23Z | Q195/Q196 writing editor design, #1752 / Vikunja #448 | Before: row 154 edits Markdown in a separate Docs view, with no selected-word thesaurus or document pins. After: design draft on gyro/editor-design compares three editor approaches, records WordNet source/license/size, folds the pane/pin model and specifies guarded context/proposal APIs, DesignCraft handoff and seven proposed briefs. Q196 changes the basis to a Word-like interface. Verification so far: editor/provenance checks 10 pass, 1 explicit rebuild skip (pinned esbuild absent); brief fields, unique headings and 11-line checklist checked. Product, queue and live state unchanged. WordCraft scratch evaluation is being incorporated before publication. Review and Jason choices remain open.
2026-10-21T16:22:36Z | Q195/Q196 design verification, #1752 / Vikunja #448 | Folded Fenton 7caf8008b and Louie 880ef19e0. Recommend bounded O3: Word-like DOM editor plus isolated headless DOCX export, with explicit feature cut and semantic loss checks. WordCraft web 44,179,239 bytes, identical twice; measured comment/footnote conversion limits recorded. Seven briefs and 12-line checklist validated. Fresh editor/provenance: 10 pass, 0 fail, 1 explicit rebuild skip (esbuild 0.28.2 absent). CI queue guard identity gyro/purpose push returned documented degraded-pass (exit 0), CANNOT_ASSERT credential-unresolvable, scratch audit gyro-q195-ci-queue-audit.jsonl; no fallback or CI-green claim. Documentation-only candidate for Mos/Fenton review, no source, queue or live changes.
-598
View File
@@ -1,598 +0,0 @@
# Row 235 build: machine grant row b (#436, Gitea #1741)
Brief: `docs/plans/2026-10-20_host-credentials.md`, "Machine grant row b: raise binding, executor,
reconcile and revoke". Design r6 f9039682e. Built on row 234's landing c771a36f4 (sage-1775), branch
gizmoduck/row235-b. Line numbers below were read on b0320d395, whose src files are byte-identical to the landing's.
## Squash onto 4ced5e63d (sage-1812, sage-1831)
Steps 1-6 were six local commits on c771a36f4 (gizmoduck/row235-b, tip f9fff4300). Sage named
4ced5e63d as the base, so this branch, gizmoduck/row235-c, holds one commit on it: the diff
c771a36f4..f9fff4300 applied with `git apply --index`. N10 is in that commit. N12 needs no change,
because row b doesn't touch schema.sql.
Rows 240, 228 and 238 landed between c771a36f4 and 4ced5e63d and changed 18 paths. One of them is
also mine:
- `packages/cli/README.md`. Row 228 (86249ac55) changed the session credential paragraphs at about
lines 432 and 706. My hunk adds three lines on `hosts revoke` and `hosts sweep` at about line 1052.
The two don't overlap, so the blob here is row 228's blob plus my three lines, with no landed line
reverted. cli tests/host.test.mjs:855 reads this README, and run 1's cli suite covers it.
The other 12 paths are byte-identical to f9fff4300. The line numbers in the step notes below were read
on the old base.
## Run 1 (sage-1831, sage-1833, sage-1838)
Run 1 on 4d4bb4af6, 07:45-07:54Z, failed: 1351 tests, 1285 pass, 66 fail. The 66 are 33 tests counted
twice, once in the files run and once in the bus suite. The cli suite, the cli hosts test, seat
sandbox.test and bus project-runtime.test passed. Two defects, both mine:
- grant-executor.test.mjs, 32 tests. setup() never made `dir/data`, and `new Store` lstats its root
(store.mjs:137), so every test stopped at setup with ENOENT. setup() now makes it, mode 0700.
- credential-claim.test.mjs:76 (X4), 1 test. A register after a revoke left the key in `#revoked`, so
status() said `revoked` for a new grant's reference that has no token yet. register now clears
`#revoked`, as unregister does. `#revoked` feeds only status(), and issue clears it as well.
Both fixes are amended into the one commit. The rerun covers the five bus files, the bus suite, and
cli credentials.test.mjs and verbs.test.mjs, which read credential state strings.
## Run 1 rerun (sage-1842, sage-1843)
The rerun on ac7c45975, 08:06-08:07Z, failed: 701 tests, 695 pass, 6 fail, which are 3 grant-executor
tests counted in both the files run and the bus suite. All three were test defects that run 1's setup
failure had hidden. No src file changed for them:
- G10. The two fixture decisions were built after `before`, and grantDecision (host-fixtures.mjs)
INSERTs one events row each, so the count read 13 for 11. The test now builds them first, asserts
they added exactly 2 rows, and then pins the executor's 0 against that count.
- G27. setup's t.after removes the scratch dir before a hook the test adds later runs, so the test's
chmod hook hit ENOENT after the body had passed. The body now restores the mode in a try/finally.
- G22. The slow run's promise had no handler until `refusesWith`, four lines on. The revoke rejected it
first, and node failed the test on the unhandled rejection. The handler now goes on at creation.
The fix is one more amend of the single commit. The rerun is grant-executor.test.mjs whole plus the bus
suite.
Rerun 1c on 5df4b52c5, 08:15Z, was green: 623 of 623, grant-executor 34 of 34 and the bus suite 589 of 589.
## Mutants B1-B37 (sage-1894, sage-1899, sage-1904)
Three chunks ran on 5df4b52c5, 09:22-09:37Z. Restores matched HEAD after each. 33 were killed and four
survived. Two of the misses were mine, in the file lists:
- B2 and B23 listed only grant-executor, and that file never makes the raise either mutant changes.
grant-enroll.test.mjs:227 (A2, A4) resolves a plain `credential.mint` yes and a host grant no, and
asserts no grant events for either. mutants.py now lists grant-enroll and grant-executor for both.
B2 then ran alone and A2 killed it. B23 runs again with this round's tests.
The other two survivors needed tests, and Sage ruled on all four (sage-1904):
- B16 drops the abort check after `verify`. The check after `step('commit')` still ends the grant
revoked, so G23 X5's asserts held. The run then logs a commit step for a grant that never committed.
G23 X5 now asserts that its only `grant.step` is `install`.
- B17 adds `await null` after the commit check. Sage accepted it as equivalent. `await null` yields
only to microtasks. Every revoke starts in a macrotask of its own (a socket request, or a test's
call), so none can land in that gap. There is no test for it.
- B27 makes issue's commit callback async. issue() doesn't await it, so the executor returns `applied`
before the INSERT runs. The two differ only when the commit transaction throws, and a real store can
throw there with a full disk, an I/O error or a busy timeout. Under the mutant that throw becomes an
unhandled rejection after the key file is written, and the catch's undo never runs. The new G8 test
makes the store's `run` throw SQLITE_FULL once on the host_grants INSERT. It asserts host-failed, no
record, key file, reference or line, and the steps install, commit, failed. The store object comes
from the test's setup, so src gains no seam.
These two test changes went in as a new commit on gizmoduck/row235-d (8b13d0ca0). That branch then
moved onto row 213's landing as gizmoduck/row235-e, below. B16, B23 and B27 run there, after the touched
test files run whole.
## Rebase onto 62ddc96cc (sage-1922)
Row 213 landed as 361ba2387, and refactor's tip is 62ddc96cc, with only docs past it. gizmoduck/row235-e
starts at 62ddc96cc and cherry-picks 8b13d0ca0's one commit. The patch-id is unchanged (c062b73fa9f1).
row235-c and row235-d stay as they were.
Between 4ced5e63d and 62ddc96cc, 361ba2387 is the only commit that touches a file of mine. The one
drifted path is `packages/bus/src/broker.mjs`:
- 213 adds `CREATIVE_DEFINITIONS` to the vocabulary import at :6, and refuses `decision.raise` from a
creative role with `decision-not-allowed` at :2176. Both hunks stay as landed.
- My 31 removed broker lines read the same before and after the cherry-pick, so no landed line is
reverted.
`packages/cli/README.md` isn't in 361ba2387. Every other path of mine is byte-identical to 8b13d0ca0.
Line numbers in the section below were read on the row235-e working tree; earlier sections keep theirs.
## Creative roles get no host grant (mos-1163, sage-1905, sage-1908, sage-1916)
Brief blob b16e236188f6 (4364dddb0, rev 2784) requires two refusals: the writer, at the raise and at the
step 1 recheck, and host.run at spend time, with the record kept. Webby's N2 on row 213 r4 asks whether
a creative role can spend a decision another role raised.
The spend answer. Mos confirmed it read-only (mos-1164, sage-1916) on 8b13d0ca0 and 01e1fe512; the
row235-e line follows each:
- Only the chief raises a host grant. `#raiseGrant` refuses `grant-chief-only` for any other
definition: :1232 on 8b13d0ca0, :870 on 01e1fe512, :1238 here. The hosts verbs check the same at
:1307 on 8b13d0ca0, :896 on 01e1fe512, :1313 here. `chief-of-staff` isn't in `CREATIVE_DEFINITIONS`.
- No agent spends one. `#consumeGrant` (:697) is called for a host grant only from `#runHostGrant`
(:902) and from the restart reconcile (:1106), which ends it interrupted. `#runHostGrant` starts from
the resolve hook (:2881) only when `#approvedGrant` returns a grant, and that needs a close by the
business's human, via cli, with the raise's approval choice (:691). An agent's resolve records via
`broker`, so it starts nothing (grant-enroll A3). The public `runHostGrant` (:891) is a trusted API
that no verb reaches.
So a creative role can't raise, approve or spend a host grant. The gap was a different one: the chief
could raise a grant whose `agent` is a creative role, and the human could approve it. The only check on
that agent was `#hostDefinition`, which refuses `host-not-declared` (:864) unless the definition's
`credentials` names `host`. Row 213's `checkCreative` (business/src/role.mjs:143) limits a creative
role's tools, authority and messaging, not its `credentials`, so a creative role file naming `host`
passed both the raise and the step 1 recheck.
As built:
- Writer. `#hostDefinition` refuses `host-creative-role` (:862) before the `host-not-declared` check.
The raise binding (:1266) and the step 1 recheck (:879) both call it, so a grant raised before its
agent's instance moved to a creative definition ends at step 1, spent, with no remote step.
- Spend. `#hostAccess` refuses `host-creative-role` (:714) when the agent's current definition is
creative, before it reads the record. Both callers go through it: host.run (:2543) and the host.sudo
raise (:2778). The record stays, because revoke still owns the cleanup (sage-1908). This goes past
the brief's writer line in the same direction; Sage tells Mos.
Tests:
- grant-host.test.mjs:115. A `muse` role on a `research` definition that declares host. The raise
refuses `host-creative-role` and adds no decision.
- grant-executor.test.mjs:947. The restart moves `ops` to a creative definition that declares host,
then a fixture grant runs. It ends `host-creative-role` at step 1, the decision is spent, and there is
no remote request and no record. The fixture comes after the restart, because the restart's reconcile
ends any resolved, unspent host grant as interrupted.
- grant-executor.test.mjs:958. An applied grant, then a restart with `ops` creative, then host.run
refuses `host-creative-role`. No remote request is added, sudo.log has no `systemctl`, and the record
is still there.
The broker clones `businesses` when it's built, so a definition change needs a new Broker. The test's
`restart()` gains a `business` parameter, default unchanged, for that.
Mutants: B38 removes the `#hostDefinition` line, run against grant-host and grant-executor. B39 removes
the `#hostAccess` line, run against grant-executor.
## Run 2 (sage-1928)
Run 2 on 534f2254a, 10:12:52-10:14:51Z, was green. grant-host.test.mjs 9 of 9, grant-executor.test.mjs
37 of 37 and grant-enroll.test.mjs 24 of 24, each run whole. grant-enroll is unchanged, but it drives the
broker, and broker.mjs changed. Then the five mutants, all killed, with the restore matching HEAD:
| Id | Killed by |
|---|---|
| B16 | G23 (X5), the revoke as verify returns |
| B23 | A2, A4 |
| B27 | G8, the store fault in the commit transaction |
| B38 | both mos-1163 tests |
| B39 | the sage-1908 test |
## Mutant results, B1-B39
| Run | Head | Killed | Survived |
|---|---|---|---|
| B1-B13, 09:22Z | 5df4b52c5 | 12 | B2 (file list) |
| B2 alone, B14-B37, 09:28-09:37Z | 5df4b52c5 | 21 | B16, B17, B23, B27 |
| B16 B23 B27 B38 B39, 10:13Z | 534f2254a | 5 | none |
38 of 39 are killed. B17 is equivalent (sage-1904), for the macrotask reason in the B1-B37 section.
B1-B37 ran on 5df4b52c5, before the move onto row 213's landing, and weren't rerun on 534f2254a.
`--check` matches all 39 anchors once on 534f2254a.
## Carry list
- N10 (duckworth-0084, row 234 r1): `cli/src/hosts.mjs:30-31` reads `shape[verb]` off a plain object,
so `mosaic hosts constructor` passes usage and the bus refuses it with exit 2 instead of 4. Row b adds
`hosts revoke` and `hosts sweep` to the same table (design r6 :562, :680), so the fix goes in with
them: `Object.hasOwn(shape, verb)` and a usage test for an `Object.prototype` name (sage-1726).
- Untimed tables (sage-1745, row 234 r3): stack-release T46 lists hosts and host_grants as untimed
because every write to them shares one store transaction with a `grant.*` events row. Row a writes only
hosts. Every host_grants INSERT, UPDATE and DELETE row b adds must do the same, and BUILD.md lists each
with its event line. A write without one is a stop to raise with Sage.
- N12 (duckworth-0086, row 234 r3, doc-only): row 234's round 3 list of other schema hits leaves out
`packages/cli/tests/stack-release-fixture.mjs:214` and `scripts/test-land-work.sh:254`. Both look up
one table by name and need no change. If row b changes the schema, its grep list names them.
## What row a already gives row b (b0320d395)
- `#approvedGrant`, `#consumeGrant(business, decision, method)` and `GRANT_EVIDENCE` (broker.mjs:667-690).
Row b calls `#consumeGrant` with `'host'`.
- `#openGrantDecisions(business, method)` and `reconcileGrants()` (broker.mjs:823-860), which today handle
`host-enroll` only. Row b adds the `host` method, the `grant.step` undo table (r6 X3) and the
revoke-marker reconcile (r6 section 6, N4).
- The resolve hook at broker.mjs:2444-2445 starts `#runEnrollment` for `host-enroll`. Row b adds the same
start for `host`, under the same human, via cli and choice checks.
- `host.run` already reads the store grant record and checks the Approve record (broker.mjs:691-703).
- The raise check `grant-chief-only` (broker.mjs:870, :896). `host-grant.mjs:55` refuses every method but
`host-enroll`, and row b opens it to `host`.
- `Credentials` has `#inflight` with the `host-busy` claim inside `runHost` (credentials.mjs:118, :355).
It has no `claim`, `abortClaim`, `register` or `unregister`. Row b adds those (r6 X4, X5).
## Plan, in build order
1. Raise binding (r6 R1-R4): the `grant` argument for `method: 'host'`, `host-not-declared`,
`host-not-ready`, the 210 D6 argv rules, `rotateBy`, the rendered block and the 4096 cap, and the raise
body hashes. Tests G1-G5, G19.
2. `Credentials.claim`, `release`, `abortClaim`, `register`, `unregister`, with the shared reference check.
3. The executor in `bus/src/host-grants.mjs`, steps 1-6 (r6 X2), with failure undo (X3) and the abort rule
(X5, C1). Tests G7-G10, G15, G23, G24.
4. Restart reconcile for `grant.step`, unspent `host` decisions, and the start sweep of `host.<id>` key
files with no record (r6 X3, N1). Tests G11, G27, G28.
5. `hosts.revoke` and `hosts.sweep` verbs, plus the CLI `revoke` and `sweep` with N10. Tests G12, G13,
G26, G27.
6. G22 end to end on one bus. Then the mutant list from r6 section 10 for row b, numbered B1 onward in
this file, with the upsert mutant and the abort-after-commit mutant included.
There is no schema step. If one turns out to be needed, I stop and ask Sage to re-brief first.
## Step 1 notes (raise binding, read on b0320d395)
Where the code goes:
- `#raiseGrant` (broker.mjs:866-885) runs the checks and keyscan for `host-enroll` today, and every raise
with `grant` reaches it (:1738-1739). Row b branches on `a.grant?.method`. `host` takes no keyscan, so
its checks can all run inside the one raise transaction, as R4 asks.
- `enrollCheck` (host-grant.mjs:50-69) refuses every method but `host-enroll` (:55). Row b adds a sibling
`hostGrantCheck` for the R4 shape `{method, agent, host, commands, rotateBy}` and keeps `enrollCheck`
as it is, so the 234 tests don't move.
- The raise body is at broker.mjs:2270, :2345-2353 and :2391. `enroll` becomes a generic `grant`
binding. The question block for `host` follows the `host.sudo` block (:2337-2341): agent, host id,
address, user, sudo, each prefix JSON-quoted, rotate date, and new key or changed commands. The
4096 cap comes from `string(question)` (:2354).
- The argv rules come from `checkCommands` (business/src/hosts.mjs:67-87): no wildcard, no empty prefix,
no glob characters, a bare name or an absolute path, and `refusedCommand` for shells and runners. It
throws `refuse(...)` with a message, so the bus maps any throw to `invalid-request`, as `enrollCheck`
maps `checkAddress` (host-grant.mjs:57-61).
- `host-not-declared`: the agent's definition must list `{"service": "host"}`. business.mjs:126-129 reads
`definition.credentials` and filters out `HOST_SERVICE` (vocabulary.mjs:113). The bus needs the
definition's service list. Read how the running business exposes the definition before choosing.
- Both lookups are answered. `loadBusiness` returns `definitions`, each role file's validated document
(business/src/business.mjs:114-124, :159, returned at :267). `busBusiness` clones the whole business
(bus/src/business.mjs:7), so the broker has `b.definitions`. `#definitions` already reads it
(broker.mjs:1027-1029), and the comment there says the broker doesn't read `roles/` (sage-0590).
- `host-not-declared` checks `b.definitions[b.roles[agent].definition].credentials` for
`{service: 'host'}`. role.mjs:118 normalizes a host entry to exactly that.
- Deviation from R4: `definitionSha256` is sha256 over `canonicalJson` of that validated definition,
not over the file's bytes. The broker doesn't read `roles/`. A whitespace-only edit to the file no
longer voids an approval, but any change to a field the loader keeps still does. The bus sees a
definition change only after a business reload or restart, the same as every other role field.
This goes in the round 1 note.
Assumption, accepted for round 1 by Sage (sage-1782), for Duckworth to check in review: design R4 says `rotateBy` is "a date inside 210's rotation window", but 210
defines no window in code. It checks only that the value is a real calendar day (bus
credentials.mjs:16-20, issue at :245). The business load calls a past `rotateBy` a problem
(business/src/credentials.mjs:114). So the raise takes a real day strictly after today, UTC, and refuses
`invalid-request` otherwise. There is no upper bound, because no requirement states one and 210
checks none.
## Step 1 as built (not run yet; no slot)
- `hostGrantCheck(grant, today)` in host-grant.mjs takes exactly `method`, `agent`, `host`, `commands` and
`rotateBy`. `agent` must match ID_PATTERN and `host` HOST_ID. `commands` goes through `checkCommands`,
and any throw becomes `invalid-request`. `rotateBy` must pass 210's `day` (now exported from bus
credentials.mjs) and be later than the bus clock's UTC day.
- `#raiseGrant` branches on `a.grant?.method === 'host'` after the chief check and before `enrollCheck`.
So a host-enroll shape with `method: 'host'` still refuses `invalid-request`, and the 234 G1 list holds.
- `#hostGrantBinding` runs inside the raise transaction. It refuses `unknown-role` for an agent that
isn't a role instance (the code bindLaunch uses, broker.mjs:522). It refuses `host-not-declared`, and
`host-unknown` for a host with no record, as `#hostAccess` does. A record in `pending-install` refuses
`host-not-ready`. R4 names only `host-not-ready`. I picked `host-unknown` for a missing record so
"not enrolled" and "enrolled but not checked" stay apart.
- `commandsSha256` is sha256 over `JSON.stringify(commands)`. For arrays of strings this equals
canonicalJson, and step 3's executor recomputes it the same way.
- `#dispatch` takes `binding = {body, block}` in place of `enroll`. The enrollment block moved into
`enrollBinding` at module level with its text unchanged, so the 234 G4 test reads the same question.
- No new import in broker.mjs, so RUNNER_FILES doesn't change. host-grant.mjs now imports
business/src/util.mjs for canonicalJson. Nothing in the sandbox loads host-grant.mjs. Before in-review
I still run seat sandbox.test.mjs and bus project-runtime.test.mjs whole.
- The new-key line reads host_grants (a SELECT). Step 1 writes no host_grants row.
- Tests: bus/tests/grant-host.test.mjs, G1 (host), G2, G3, rotateBy, G19, R4/G5 body hashes, G4 block.
The G5 tester-thread case: a thread run is always THREAD_DEFINITION, never chief-of-staff, so
`grant-chief-only` refuses it first. The test covers the tester's own cap (`tester-refused`).
## Step 2 as built (not run yet)
- The constructor's per-reference checks moved into `#checkRef`, in the same order, and `register` calls
it (r6 X4). `register` reads no file. A key file that a failed revoke unlink left at the path stays
unused until the start sweep (step 4) removes it. `register` refuses `credential-reference` while the
entry holds a live token. An entry with no token, revoked or never issued, is replaced, so a new grant
after a revoke registers again.
- `unregister` drops an entry with no token and clears its revoked mark. A live token refuses.
- `claim` refuses `host-busy` when the slot is held, by a claim or a `host.run`, and returns the signal.
It needs no reference, because the executor claims at step 1 and registers at step 5.
`release(instance, service, signal)` frees the slot only for its own signal. I added the signal
argument so a late release can't free a later claim.
- `abortClaim` aborts whatever holds the slot and returns `{pending}`. An aborted claim keeps the slot
until the executor releases it in its `finally` (X2).
- Tests: bus/tests/credential-claim.test.mjs. The D5 `use(` allowlist is unchanged.
## Step 3 as built (not run yet)
Where the code goes. The remote steps are in host-grant.mjs (`grantKey`, `install`, `verify`, `remove`)
and the orchestration is `#runHostGrant` in broker.mjs, next to `#runEnrollment`. BUILD.md's plan said a
new `bus/src/host-grants.mjs`. I kept row 234's split instead: the broker holds every store write and
host-grant.mjs holds the network and key files. A new broker import would also change what the sandbox
must mount (RUNNER_FILES), and this way broker.mjs gains none.
The broker gets `hostKeys`, made by `grantKeys({credentials, storeRoot})` in host-grant.mjs. It wraps
only `claim`, `release`, `abortClaim`, `register`, `unregister`, `issue` and `revoke`, keyed by
(business, agent, hostId). The broker still never gets `use()`. runtime.mjs builds it and passes it in.
`hostReference` gives the store reference, and the runtime's start load uses the same function.
Every host_grants write in step 3, with its event (sage-1745):
| Write | Where | Event in the same transaction |
|---|---|---|
| INSERT, a new key | the `commit` callback that `issue` calls | `grant.applied` |
| UPDATE commands and decision, a commands change | step 5's transaction | `grant.applied` |
No other step 3 code writes host_grants.
Deviations from r6, for the round 1 note:
- `grant.applied` commits with the record, inside `commit`, not after `issue` at step 6. The untimed-table
rule needs an event in the record's transaction. `grant.step commit` can't be that event, because X2
writes it before the key file. So X3's "5 after commit" row has nothing to undo in the executor: once the
record commits, `grant.applied` has too. What's left in `issue` after `commit` is the memory fill, which
writes no file and no store row. The executor sets `committed` after the transaction returns and from
then ignores an abort (C1). The restart reconcile (step 4) keeps the commit row, because a crash can fall
between the key file write and `commit`.
- Event bodies name the decision as `grantDecision`, as row 234's enrollment events do. The consume record
is the only grant body with `decision`, so `#spent` counts it and nothing else.
- For a commands change, `grant.applied` has `fingerprint: null`. The executor holds no key on that path.
The record's `rotate_by` stays. X2 names only commands and the decision id.
- The keygen dir goes as soon as `grantKey` has read the key back into memory, not in step 5's `finally`.
- Step 4 runs `true` as the remote command as is, not through the sudo argv, since a user with no sudo
must pass it too.
- `hostGrant()` takes `installerUser`, `mosaic-installer` by default. Only the tests change it, because
the scratch sshd logs in only as the test's own user.
- A commands-change UPDATE that changes no row ends `host-changed`. Only a revoke deletes a live record,
and a revoke aborts the claim first, so this is a guard.
Step 1 codes, after the spend and in its transaction: `host-not-configured`, `unknown-role`,
`host-not-declared`, `decision-mismatch` (definition, registry or commands hash), `host-unknown`,
`host-not-ready`, `revoked` (a `grant.revoked` of the agent and host after the raise). The definition
check moved into `#hostDefinition`, which the raise binding uses too.
Tests: bus/tests/grant-executor.test.mjs, a scratch sshd on 127.0.0.1 with stub `list`, `add` and
`remove` that edit a second authorized-keys file. G7 (new key, and a commands change), G8 (install, verify,
a failed remove, step 5 before commit, a failed step 1 check), G9, G10, G15, G23 (a revoke during install
through `abortClaim`, a `grant.revoked` before start, and a held slot), G24's tag part. G23's held slot
uses `claim` in place of a running `host.run`. Both hold the same `#inflight` entry. The `revoke` verb
comes in step 5, so G23 here writes `grant.revoked` through the fixture writer and aborts through
`abortClaim`. Step 5 adds the verb's own path.
## Step 4 as built (not run yet)
The restart reconcile has three parts, in start order:
1. `sweepHostKeys` (host-grant.mjs), in runtime.mjs right before `Credentials` loads. In each loaded
business's agent store it unlinks every `host.<id>` file that has no `host_grants` record, and logs
one `hosts: {"event":"host-key-swept",...}` line per file to stderr. A store dir that isn't private
refuses `credential-file`, and so does the start. A name that isn't `host.` plus a valid host id
stays, so ssh-keygen's `.pub` stays too. A business the bus didn't load is left alone.
2. `reconcileGrants`, where row 234 already calls it, after `Credentials` loads and before the socket
opens. For a `host` grant it ends a spent decision that has no `grant.applied` and no `grant.failed`.
It also spends and ends an unspent one the human resolved yes. Each ends `grant.failed interrupted`,
with the tag and a notice. When the last step is `install`, or `commit` with `previous: null`, a line
may be left. For those, it claims the (agent, `host.<id>`) slot and queues the decision for part 3.
3. `reconcileHosts`, which runtime.mjs calls once `serve` returns, with no await, so a start doesn't
wait on the network. Each queued decision runs `remove <user> <tag>` through the installer, as the
step's `user`. Then it ends `grant.failed interrupted`, with `hostLineLeft` if the remove failed or
there's no host record, and releases the claim. The claim makes a new grant for the same agent and
host refuse `host-busy` while the remove runs. Otherwise its new line, with the same tag, could be
removed.
Deviations from r6's restart table, for the round 1 note:
- No record write on restart. Step 3 commits the record with `grant.applied` in one transaction. So a
decision with no `grant.applied` has no record. For a new key, the record undo has nothing to delete.
For a commands change, the "back to `previous`" undo has nothing to put back. What's left of the
`commit, new key` row is the key file, written before `commit`, and the start sweep unlinks it.
The `commit, commands change` row ends interrupted with nothing undone. G28's "a revoke before
`grant.applied`" can't happen, because they commit together. Step 5 tests G28 as a change, then a
revoke, then a restart.
- The local undo of row 234's enrollments stays after `Credentials` loads, where row 234 put it. That
undo touches only the installer key and the host record, and `Credentials` reads neither.
- The host grant part writes no `host_grants` row, so the untimed-table rule (sage-1745) adds nothing
here.
Fixture change: `hostGrantRecord` (tests/host-fixtures.mjs) writes `grant.applied` after a `grant.host`
spend, as the executor always does. Without it, a start over a fixture record ends that record's
decision `interrupted`. Row 234's M3 start test (host-run.test.mjs:602) does that start. No test counts
the fixture's grant events (checked by grep across the bus tests).
Tests in grant-executor.test.mjs, through a `restart` helper that follows runtime.mjs's order on the
same store:
- G11 after `install`: the line goes, the slot is held between the two parts, and the grant ends
interrupted. A second start adds nothing, and `runHostGrant` refuses `decision-consumed`.
- G11 after a new key's `commit` with the key file written: no key file, record, reference or line.
- G11 after a change's `commit`: the record, key and line are unchanged, and the host gets no request.
- G11 (B2) before step 1, spent and unspent: each ends interrupted with a notice, and the unspent one
is spent exactly once.
- A failed remote undo, and a missing host record: each ends with `hostLineLeft` and the sweep hint.
- A finished grant: the reconcile adds nothing.
- N1 (G27's sweep part): only files with no record in loaded businesses go, and a dir that isn't private
refuses.
The revoke-marker part of the reconcile (section 6, N4) comes with the revoke verb in step 5.
## Step 5 as built (not run yet)
Two new bus verbs, `hosts.revoke` and `hosts.sweep`, join `HOSTS_VERBS`. The CLI gets
`mosaic hosts revoke AGENT HOST --reason R` and `mosaic hosts sweep HOST`.
`hosts.revoke {agent, host, reason}` follows r6 section 6:
1. One transaction deletes the `host_grants` record and writes `grant.revoked` with a new `revoke` id
(a UUID), the computed tag, `hostLine: "pending"`, `granted`, `reason` and `by`. With no record it
still writes the marker, with `granted: false`, so a stale line can be named (N4). A host with no
record refuses `host-unknown` and writes nothing.
2. With no await between, `Credentials.revoke` drops the key from memory, aborts a `host.run` in flight
and unlinks the file. With no reference (`credential-unknown`), an executor holds only a claim, so
`abortClaim` stops it. Any other throw, such as an unlink that fails, comes back as `keyFile: "left"`.
The record is already gone, so the next start's sweep unlinks that file.
3. `remove <user> <tag>` through the installer, as the host record's user (the executor's user too).
Then `grant.revoke.closed` with the same `revoke` id and `hostLine: "removed"`, or `hostLineLeft`.
Callers (G26): the human, and the assistant of the session's business, checked with `#threaded`. The
tester can call it when `bus.tester` is exactly `true`, read again at the call. Any other agent gets
`revoke-refused`, a code new in this row. A tester session can't hold a business whose `bus.tester`
isn't `true`, since `bindTester` refuses `tester-off`, and the broker's businesses don't change while
it runs. So `tester-dev-only` can't be reached from a test. The check stays for N8, in case a later
row reloads businesses.
`hosts.sweep {host}` is the human's or the tester's; an agent gets `human-required`. It runs
`list <user>`, then removes each listed tag that this business recorded for the host in a `grant.step`
or `grant.revoked` and that no live grant holds. Another business's line and an unrecorded `mosaic-`
line stay (G24's sweep part). It writes `grant.host.swept {host, removed, left, by}`, where `left` is
each earlier left tag still listed and not removed. `#hostLinesLeft` now starts from the last
`grant.host.swept` and adds only later `hostLineLeft` bodies (F4).
The restart reconcile adds the marker part: `reconcileGrants` collects each `grant.revoked` with
`hostLine: "pending"`, a text `revoke` id and no `grant.revoke.closed` of that id. `reconcileHosts`
runs step 3 for each. A `grant.revoked` with no `revoke` id, as G23's fixtures write, isn't reopened.
`hosts.status` adds `revoking`, the tags of the open markers on the host.
Other changes:
- N10: the CLI checks the verb with `Object.hasOwn`, so `constructor`, `toString` or `__proto__` is a
usage error.
- `--reason` is required with `revoke` and refused with any other verb.
- The reason goes through the broker's `string(x, 500)`, as `credentials.revoke`'s does, so a reason of
only spaces is accepted there too.
- Correction to step 4: the first G11 test expected `list` then `remove`. `reconcileHosts` sends only
`remove`, so the test now expects that.
Residuals for the round 1 note:
- A new grant whose line goes in while a revoke's step 3 or a sweep runs can lose that line, if it has
the revoked tag. Revoke holds no claim during step 3. If the remove lands after the new grant's
verify, the grant is recorded but its line is gone, so its logins fail. I didn't add a claim, because
a revoke must not wait on a slot.
- The enrollment's installer tag is never in the sweep's set, so a `hostLineLeft` naming it stays
until the human removes it by hand.
Tests in grant-executor.test.mjs:
- G12: the human's revoke of a live grant, and the bodies of both markers. A restart adds nothing.
- G12 (N4): a revoke with no record removes the computed tag's line. Bad args refuse
`invalid-request` and an unknown host `host-unknown`.
- G13: a revoke during `install` aborts the executor, which ends `revoked`. A raise before a revoke
and started after it ends `revoked` at step 1.
- G26: who may revoke and who may sweep.
- G27: a restart after step 1 (the sweep takes the key file, then step 3 runs), after step 2 with the
host down (`hostLineLeft`, then a sweep clears it), and a file a revoke couldn't unlink.
- G28: a commands change, then a revoke, then a restart.
- G24 (B4): the sweep's tag set, a failing `list`, and the left list it records.
The CLI tests in packages/cli/tests/hosts.test.mjs cover revoke and sweep, the N10 usage cases and the
`revoking` field in a status line.
## Step 6 as built (not run yet)
New tests in grant-executor.test.mjs:
- G22 (B1), one bus with no restart. The chief enrolls web1, the human approves, and `hosts.check`
marks it ready. A grant of `echo` follows, then a `host.run` of `echo hi` that prints `hi`. A
`sleep` raise refuses `command-not-granted`, and after a commands change to `echo` and `sleep` the
next `host.run` of `sleep 30` starts. A revoke kills that run with `credential-unavailable`. The next
call refuses `host-not-granted`.
- G12: the local steps finish before the host step. With the host's `remove` held, the record and key
file are already gone and `hosts.status` shows the tag under `revoking`.
- G13: a revoke whose host `remove` fails returns `hostLineLeft`, drops the record and key, and closes
the marker, so a restart adds nothing.
- G23 (X5): a revoke right after the executor's spend reaches its claim and the grant ends `revoked`.
- G23 (X5): a revoke that lands as `verify` returns ends `revoked` with no record, key file or line.
Only the abort check after `verify` catches it.
The fixture gains a `sudo` stub (logs to sudo.log, then runs the command as the test's user), a
`hold-remove` flag, `opts.enroll` (no host record and no installer key) and `opts.wrap` (changes the
host API the broker gets). `hostGrant` gets a fake `scan` that returns the scratch sshd's host key.
G22 deviations, for the round 1 note:
- `checkAddress` (business/src/hosts.mjs:62) refuses this machine's address, so the test enrolls
192.0.2.10 with the fake keyscan. It then points the record at the scratch sshd with an SQL update
and adds the enrolled installer key to the sshd's authorized keys. Enrollment, check, grant, run and
revoke all go through the real code after that.
- r6 B1 says the next `host.run` after a revoke refuses `credential-unavailable`. Here it refuses
`host-not-granted`, because step 1 deletes the record and `requestHost` checks the record
(`#hostAccess`) before it reaches the key. The call in flight does refuse `credential-unavailable`.
### Mutants
`/mnt/storage/scratch/gizmo-235-out/mutants.py` holds each mutant as anchored edits. `--check` applies
them in memory and runs no test. All 39 anchors match once. Each mutant runs its named test files.
From r6 section 10, as they apply to row b:
| Id | Mutant | Test file |
|---|---|---|
| B1 | drop the chief check on a host grant raise | grant-host (G1) |
| B2 | start the executor on a `credential.mint` with no `grant` | grant-enroll (A2), grant-executor |
| B3 | skip the `ready` check at the raise | grant-host (G19) |
| B4 | skip the `ready` check at step 1 | grant-executor |
| B5 | skip the definition hash compare | grant-executor (G9) |
| B6 | drop the definition check (`host-not-declared`) | grant-host (G2), grant-executor (G9) |
| B7 | skip the commands hash compare | grant-executor (G9) |
| B8 | skip the host record hash compare | grant-executor (G9) |
| B9 | write the grant record before install | grant-executor (G8) |
| B10 | skip `remove` on a verify failure | grant-executor (G8) |
| B11 | skip the start sweep of key files with no record | grant-executor (N1, G27) |
| B12 | skip the reconcile's remote `remove` | grant-executor (G11) |
| B13 | skip the `grant.step` before install | grant-executor (G11) |
| B14 | revoke leaves the grant record | grant-executor (G12) |
| B15 | skip `register` before `issue` | grant-executor (G7) |
| B16 | drop the abort check after `verify`, the last one before `issue` | grant-executor (G23 X5) |
| B17 | add an `await` between the abort check and `issue` | grant-executor |
| B18 | revoke ignores a claim with no reference | grant-executor (G13, G23 X5) |
| B19 | build the tag without the business | grant-executor (G24) |
| B20 | `sweep` removes any `mosaic-` line | grant-executor (G24 B4) |
| B21 | run revoke's host step before the local steps | grant-executor (G12) |
| B22 | start the executor on an arbiter resolve | grant-executor (G10) |
| B23 | start it on `no` | grant-enroll (A2, A4), grant-executor |
| B24 | write the private key into the event body | grant-executor (G15) |
| B25 | put an `await` between the spend and the claim | grant-executor (G23 X5) |
| B26 | skip the start check for a resolved, unspent grant decision | grant-executor (G11 B2) |
| B27 | make `commit` async | grant-executor (G8) |
| B28 | route `hosts.revoke` to `Credentials.revoke` alone, as `credential-verbs.mjs` would | grant-executor (G12, G27) |
| B29 | skip the revoke marker reconcile | grant-executor (G27) |
Row 235's own:
| Id | Mutant | Test file |
|---|---|---|
| B30 | skip the `grant.revoked` check at step 1 | grant-executor (G13, G23) |
| B31 | the sweep set keeps a live grant's tag | grant-executor (G24 B4) |
| B32 | reopen a `grant.revoked` with no revoke id | grant-executor (G27) |
| B33 | step 3 reports `removed` when the host remove fails | grant-executor (G13, G27) |
| B34 | any agent revokes, not just the assistant | grant-executor (G26) |
| B35 | `hostLineLeft` ignores the last sweep | grant-executor (G24 B4, G27) |
| B36 | a stale `release` frees a later claim | credential-claim (X5), grant-executor |
| B37 | `register` replaces an entry with a live token | credential-claim (X4) |
| B38 | drop the creative check in `#hostDefinition` | grant-host (mos-1163), grant-executor (mos-1163) |
| B39 | drop the creative check in `#hostAccess` | grant-executor (sage-1908) |
B17 may survive. `await null` yields only to microtasks, and every revoke starts in a macrotask of its
own (a socket request, or a test's call), so none can land in that gap. If it survives I'll report it
as equivalent under this build, not add a test that fakes a microtask revoke.
Section 10 items not run as row b mutants, and why:
- The upsert mutant ("let the undo to `previous` insert a record") and "run past a newer
`grant.revoked`". Row 235 has no undo to `previous`. A commands change commits the UPDATE and
`grant.applied` in one transaction (sage-1745), so a restart after it leaves the record as it is
(G11). The UPDATE can't meet a missing record either: step 1 reads the live record, and nothing
awaits between there and the UPDATE. An upsert there would be equivalent.
- "let the executor act on an abort after step 5 commits". The record and `grant.applied` commit
together, and no abort check follows the commit, so no code path reaches the `if (committed)` guard
with an abort. Removing the guard is equivalent. C1's case is covered by G28 with a later revoke.
- "treat a missing `bus.tester` as dev". The tester check can't be reached from a test (step 5 notes).
- Row a's: the keyscan compare, the writer items, the "not yet enrolled" check, the `hosts` primary key
and `host.run` reading the business file. Row 234 ran those as A5, A6, A8, A9, A11 and A13-A19.
-98
View File
@@ -1,98 +0,0 @@
# Row 249 build notes (Gizmoduck)
Gitea #1751, Vikunja P19 445 under #436. Brief: docs/plans/2026-10-20_host-credentials.md, section
"Machine grant row b follow-up: the undo can't prove the remote add has ended" (6de1ebc62). Reviewer
Duckworth, gate owner Sage. Branch gizmoduck/row249-on-8a04, on row 248's landing 8a04f4aa4 (sage-2012).
No file under packages/bus/src changed between 6d5545d44 and 8a04f4aa4, so the brief's src line numbers
hold on the base. Line numbers below are on this branch.
## Correction to the brief
The brief, copying gizmoduck-0139, puts the sweep's host-unknown refusal at broker.mjs:1350. On
6d5545d44 it is :1349. On this branch it is :1354.
## The change
`#runHostGrant` in packages/bus/src/broker.mjs:
- :943 adds `installed = false` next to `installing`.
- :956 sets `installed = true` on the line after `await this.#hostGrant.install(...)`, before the
`stop()` that follows it. An abort that lands after install returned still ends revoked, with no hint,
because install returning means every request it sent has exited.
- :1025, in the catch, inside `if (installing)` and after the remove: `if (!installed) extra =
{ hostLineLeft: tag };`. The remove still runs first and its result doesn't matter. A remove that
throws sets the same hint as before (:1021).
The rule keys on install not returning, not on `signal.aborted`. That covers an abort (host-run.mjs:136,
SIGKILL to the local group), a timeout (host-run.mjs:131-134, SIGTERM, then SIGKILL after `graceMs`) and
a dropped connection, which fails the request with no signal at all. `#hostGrantFailed` (:845) already
adds "A line tagged X may be left on the host. Run: mosaic hosts sweep <host>" when `hostLineLeft` is
set (:852), so the message needed no change.
False hints. install is one call that runs `list`, maybe `remove`, then `add` (host-grant.mjs:329-333).
Any failure inside it now records the hint, including a `list` that exits 1 before any add was sent, and
an abort that lands before the first ssh starts (the G23 X5 case at "a revoke right after the spend").
The brief accepts this for an add that exits nonzero. The other cases are the same kind: the line isn't
on the host, and a sweep that doesn't list the tag drops the hint (G24, "a left tag no longer on the
host", broker.mjs:1358). Narrowing it would need install to report which request was in flight, which is
a change to host-grant.mjs's API that the brief doesn't ask for.
## Row a's enroll
The race can't happen there, because enrollment sends nothing to the host. `#runEnrollment`
(broker.mjs:772-842) writes the record, calls `this.#hostGrant.enroll(business, host)` (:800) and
commits the fingerprint. `enroll` (host-grant.mjs:247-286) runs ssh-keygen locally and writes the
private half to its file. It opens no ssh session. The installer line goes on the host by hand: the
notice tells ops-01 to write it, then to run `mosaic hosts check`. The undo at :835 is `unenroll`, which
deletes the local key file. There is no remote add to outlive a kill, and no remote undo to race with.
## Tests
packages/bus/tests/grant-executor.test.mjs:
- `lateAdd` (:451) is the shared tail. After the grant ends it asserts the code, `hostLineLeft` on
grant.failed, the sweep line in the notice, and that the undo's remove was the last request. Then it
writes `release`, so the held add writes its line and exits 0, and waits for the line in `granted`. It
checks there's no record, `hosts.status` lists the tag in `hostLineLeft`, `hosts.remove` refuses
host-line-left, `hosts.sweep` returns `removed: [tag]` and the line is gone, then `hosts.remove`
succeeds.
- :468, the abort case. `hold-add`, the human approves, the add holds, `abortClaim` aborts the
executor's claim. Ends revoked.
- :480, the timeout case. A 30 s wait is too long for the file, and making the timeout an option would
add a src seam, so the test wraps `install` through `opts.wrap` instead. The wrapper passes install its
own AbortController signal, waits for `holding`, aborts it, which SIGKILLs the local ssh group as the
timer does, then throws as a timed-out request does. The executor's signal isn't aborted, so it ends
host-failed. Nothing under src changes for it.
- G8 (:283) changes. fail-list and fail-add now carry `hostLineLeft` and the sweep line. noop-add fails at
verify, after install returned, so it keeps no hint and the old message.
- The comment at :436 (:432 at 6d5545d44) now says `skip` makes the held add exit without writing and that a
killed session's add can still write. G13 has no such comment.
Both new tests write `release`, so their held stub exits before `t.after` removes the dir. Row 248's dir
check (:67, :72) is the backstop.
## Mutant
/mnt/storage/scratch/gizmo-235-out/mutants-249.py, on row 235's runner. C1 removes the :1025 line and
runs grant-executor.test.mjs. Both new tests and G8 should fail under it. `--check` matches its anchor
once.
## Runs
On Sage's grant sage-2015, at 8457af076 (7cee1a1ab plus this file), TMPDIR /mnt/storage/scratch/g249t:
| Run | Window | Result |
|---|---|---|
| grant-executor.test.mjs whole | 13:29:01-13:29:21Z | 39 of 39 pass |
| C1 | 13:29:21-13:29:40Z | killed: both row 249 tests and G8 fail on `hostLineLeft` undefined |
After C1 the worktree was clean and broker.mjs matched HEAD. After the runs, no node, sshd or sh process had a
cwd under the worktree or g249t, and no `fake/add` or `fake/remove` stub was running. The bus suite runs on
Sage's gate.
## Rebase onto 8a04f4aa4 (sage-2012)
The first commit, 02bfd184b, sat on bc579f7a8 as gizmoduck/row249, which was never pushed. Row 248 landed
as 8a04f4aa4, changing grant-executor.test.mjs at :54, :67 and :72. gizmoduck/row249-on-8a04 starts at
8a04f4aa4 and cherry-picks 02bfd184b with no conflict. 248's lines stay as landed. The patch-id is the
same on both (c33823941e61). Test line numbers moved down by one, and this file was updated for that.
-158
View File
@@ -1,158 +0,0 @@
# Row 221 build notes, C2-20 Bean and Chet persona import (#1722, Vikunja #416)
Brief: docs/plans/2026-10-20_case2-rows.md "C2-20", blob 16847e94ae17 (sage-1834). Claimed rev 2736.
Rulings: sage-1836 (fence, pairing) and sage-1840 (YAML parser, handoff).
## Base
Built on Morgana's row 213 r4 tip 2b3e67e36 (origin/morgana/row213-r4), since the brief says "After:
C2-08" and 221 exports 213's fence check. Before review it goes onto 213's landing under a new branch
name, and its tests run again there.
## What changed
- `scripts/case2-persona-import.mjs`, new. Verbs `stage` and `install`, usage in its header.
- `packages/cli/tests/case2-persona-import.test.mjs`, new, and `packages/cli/tests/fixtures/case2-persona-import/`,
a fixture Hermes home plus `trace.mjs`, the read trace.
- `packages/harness/src/bundle.mjs`: the three text rules in `readPersona` move into an exported
`personaTextFault(text)`, which returns null or the reason, and `readPersona` calls it. Nothing it
checks changes and the messages are byte for byte the same, so 213's creative tests hold. There is
one copy of the rules and the import calls it (sage-1836).
- `package.json` and `package-lock.json`: `yaml` 2.9.0 becomes an exact direct dependency (sage-1840 Q3).
## Rulings recorded
Profile to name (sage-1836, answers DESIGN.md:1322 as an implementation ruling, not a PRD change).
Hermes at df5700ebe has no field holding a profile's own name. `profile.yaml` has only `description`
and `description_auto` (hermes_cli/profiles.py:798-850), and `agent_name` at cli.py:3494 is skin
branding with the default "Hermes Agent". So the human passes the pairing as `--pair default=Bean
--pair chet=Chet`. The script checks both profile directories exist, each name is exactly Bean or Chet
and the two differ, then prints the pairing with each SOUL.md's byte count and sha256 before it writes.
The brief's "confirm profile to name" is met by the human supplying and confirming the pairing.
The persona is `<profile dir>/SOUL.md`, where Hermes loads it (agent/prompt_builder.py:1829-1855).
The default profile's directory is the Hermes root, and others are `profiles/<name>`, with names
checked against hermes_cli/profiles.py:37. A missing or blank SOUL.md is "no persona", as in Hermes.
The file is staged byte for byte. Hermes strips it and runs its own scan before use, but this import
copies her text unchanged.
Handoff between the steps (sage-1840 Q4). `stage` writes 0600 files owned by whoever ran it. `install`
runs as `<user>` and refuses a staging file that isn't its own or has a group or other bit. The script
changes no owner. It prints the root step, `chown -R <user>: <staging>`, as an instruction. **Item for
Jason's go:** who runs stage on `<host>`, and the root chown between the two steps.
## Word list
69 tool names: every literal `name="..."` in a `registry.register(` call under hermes-agent's
`tools/*.py` at df5700ebe, plus Hermes and Discord. Two more registrations, in tools/mcp_tool.py:4997
and :5034, and plugin tools (hermes_cli/plugins.py:430) get their names at run time, so a fixed list
can't hold them. Matching is whole word, any case. `memory`, `terminal`, `todo`, `process`, `patch` and
`clarify` are ordinary words, so a persona line using them in prose counts, and the count leans high.
It is a hint for Jason and changes nothing in the import.
## Channel prompts
Hermes takes a platform's block from `<platform>` at the top level of config.yaml, else from
`platforms.<platform>` or `gateway.platforms.<platform>` (gateway/config.py:1159-1178), and its
prompts from `channel_prompts` (:1233). The script lists all three by platform, channel id and byte
count, and says "not text" for a value that isn't a string. The dry run doesn't read config.yaml.
yaml parses with `intAsBigInt`, so an unquoted 18 or 19 digit Discord id prints exactly instead of
rounding as a double, and with `uniqueKeys: false`, so a repeated key keeps the last value as Python's
`safe_load` does. `logLevel: "silent"` stops yaml's warnings, which quote config text. yaml reads YAML
1.2 and Hermes's PyYAML reads 1.1. They differ on scalars such as `yes` and `0123`, but neither
changes a channel prompt's key or its byte count for a quoted or decimal id.
## yaml dependency (sage-1840 Q3)
Made with `npm install --save-exact [email protected] --package-lock-only --ignore-scripts` at the worktree
root. `git config core.hooksPath` was unset before and after. npm moved nothing else:
```
package-lock.json | 3 ++-
package.json | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
```
```
@@ -10,7 +10,8 @@
"license": "UNLICENSED",
"dependencies": {
"@earendil-works/pi-coding-agent": "0.85.1",
- "oauth4webapi": "3.8.8"
+ "oauth4webapi": "3.8.8",
+ "yaml": "2.9.0"
}
},
```
node_modules/yaml is 2.9.0, from the pinned pi packages (package-lock.json:502 and :556).
Where it runs. `scripts/case2-persona-import.mjs` isn't in stack-copy's COPY_PATHS, and a copy carries
no node_modules of its own beyond its `npm ci`. So the script runs from a checkout at the reviewed
commit after `npm ci`, where `import "yaml"` resolves through the root package.json and
`../packages/harness/src/bundle.mjs` is beside it. Whoever runs `stage` needs read access to that
checkout and to her Hermes home, which is part of the item for Jason's go above.
## Tests
Round 1, on 213 r4 2b3e67e36, slot grants sage-1851 and sage-1863. One `node --test` per file.
Run 1 started at 08:19:44Z. A 600 s tool timeout on my wrapper killed it at about 08:29:45Z, inside
stack-release-external, after stack-release took 494 s. One test in this row's file failed in run 1.
Its filter `includes("per-channel prompt")` also matched the "profile chet: no per-channel prompts"
line that the next assert checks on its own. That was a test defect, and the script's output was
right. The filter is now `includes(": per-channel prompt ")`. The kill orphaned one fixture
holder.cjs, which I killed, and I removed its tmp dirs. Sage counts this as one failure under mos-0823.
The rerun, 08:31:11Z to 08:33:31Z, covered this row's file, stack-release-external, stack-upgrade
and the fixture dry run. The 15 files that run 1 finished green stand on code the fix didn't touch. Their counts come from run 1.
| File | pass | fail |
|---|---|---|
| packages/business/tests/launch-settings.test.mjs | 16 | 0 |
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
| packages/cli/tests/stack-release.test.mjs | 195 | 0 |
| packages/conversation/tests/cohort.test.mjs | 37 | 0 |
| packages/harness/tests/bundle.test.mjs | 22 | 0 |
| packages/harness/tests/claude-gate.test.mjs | 3 | 0 |
| packages/harness/tests/claude-session.test.mjs | 8 | 0 |
| packages/harness/tests/creative.test.mjs | 7 | 0 |
| packages/harness/tests/mcp-server.test.mjs | 5 | 0 |
| packages/harness/tests/pi-session.test.mjs | 8 | 0 |
| packages/harness/tests/skills.test.mjs | 10 | 0 |
| packages/plugins/tests/harness.test.mjs | 9 | 0 |
| packages/seat/tests/sandbox.test.mjs | 10 | 0 |
| packages/webui/tests/editor.test.mjs | 5 | 0 |
| packages/webui/tests/pinned-copy.test.mjs | 10 | 0 |
| packages/cli/tests/case2-persona-import.test.mjs | 11 | 0 |
| packages/cli/tests/stack-release-external.test.mjs | 25 | 0 |
| packages/cli/tests/stack-upgrade.test.mjs | 20 | 0 |
Total over the 18 files: 417 pass, 0 fail, 0 cancelled, summed by awk.
The dry run on the fixture, `stage --hermes-root packages/cli/tests/fixtures/case2-persona-import/hermes
--pair default=Bean --pair chet=Chet --dry-run`, exited 0 and printed:
```
files 2
profile default: lines 3, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0
profile chet: lines 2, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0
```
## Rebase onto 213's landing (sage-1925)
213 landed as 361ba2387, with the same `git patch-id --stable` as r4 2b3e67e36, f313e69b6f7e. The
refactor tip was 62ddc96cc. I cherry-picked 2d7a99aee onto it under the new branch gosalyn/c2-20-r2 as
48f044ccc. The patch-id is eb094ae783e9 before and after. None of the 22 paths changed between 2b3e67e36
and 62ddc96cc. The fence export from sage-1836 Q1 was already in the commit: `personaTextFault` from
packages/harness/src/bundle.mjs, called by the script. I checked the test list again on the new base by
grepping tests and scripts/test-*.sh for each non-test path's basename. The new hits name other packages'
package.json files or write lockfiles in temp dirs, so the 18 files stand. 231 landed after that as
29ce1e360. It touches only packages/library and the queue-231 packet, none of these 22 paths.
Rerun on 48f044ccc, slot grant sage-1932, 10:18:09Z to 10:30:14Z, after a busy check. All 18 files ran
whole, one `node --test` each, every rc 0: 419 pass, 0 fail, 0 cancelled, summed by awk. That's two more
than the 417 above, both from the base. stack-release went from 195 to 196 and stack-upgrade from 20 to 21,
and rows 238 and 240 changed those test files. Every other file has the count in the table above. The dry
run printed the same three lines, rc 0.
-96
View File
@@ -1,96 +0,0 @@
# Row 231 build notes, C2-01b survey escapes, list item lines and attachment embeds (#1733)
Brief: docs/plans/2026-10-20_case2-rows.md "C2-01b survey escapes, list item lines and attachment embeds",
blob 16847e94ae17. These are Webby's row 212 notes N1 to N3 (webby-0041), split out by sage-1517.
## Base
First built as 777f7358a on 212's first round bdf18272a. 212 landed as ee7b2f137 (sage-1886), so the
commit was cherry-picked onto refactor fefd54e13 under the new branch gosalyn/c2-01b-r2 as 3647a5a93.
`git patch-id --stable` is 45911915a9ee before and after. packages/library is the same in bdf18272a
and in 212's landed round a2c72ac95, so nothing the commit touches moved under it.
## What changed
- N1, `packages/library/src/survey.mjs`: JSON strings escape C0 controls but leave DEL, C1 and bidi
controls raw. The new `quote()` escapes those too, and folder names print through it.
- N2, `packages/library/src/reader.mjs`: front matter parsing records each block list item's line, and
a link in a block list carries its item's line instead of its key's.
- N3, `links.mjs` exports `isAttachment` through `index.mjs`. A wikilink or embed whose target's last
segment ends in an extension other than `.md` is an attachment. The reader neither resolves nor
indexes it, and it raises no problem. The survey prints a count of body links to attachments.
- `packages/library/README.md` describes all three, and the links, reader and survey tests cover them.
## Outside readers
`packages/cli/tests/stack-copy.test.mjs:38` checks only that `packages/library/src/index.mjs` exists, and
`scripts/mosaic:41` execs `survey.mjs`. No test pins a hash of a library file.
## Tests
On 3647a5a93, slot grant sage-1889, 09:20:01Z to 09:20:14Z, after a busy check. One `node --test` per
file, every rc 0.
| File | pass | fail |
|---|---|---|
| packages/library/tests/links.test.mjs | 7 | 0 |
| packages/library/tests/mapping.test.mjs | 7 | 0 |
| packages/library/tests/reader.test.mjs | 13 | 0 |
| packages/library/tests/render.test.mjs | 11 | 0 |
| packages/library/tests/survey.test.mjs | 6 | 0 |
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
Total: 60 pass, 0 fail, 0 cancelled, summed by awk.
## Round 2, after webby-0070 (CHANGES) and sage-1900
Webby's round 1 review is agents/webby/work/queue-231/REVIEW-r1.md at 387f04dfd, rev 2774.
Ruling sage-1900, recorded here as asked. B2: the brief stays as approved (sage-1517, case2-rows.md
C2-01b N3). Only a `![[x.ext]]` embed can be an attachment. Plain wikilinks and front matter values keep
resolving, and an unresolved one is R4. README's line "A link to a `.canvas` file or an attachment is
R4" is back as it was at fefd54e13. B1: resolve first. An embed is an attachment only when it resolves
to nothing and its target has an extension other than `.md`. So `![[Dr.Quinn]]` with Dr.Quinn.md
indexed resolves, `![[cover.png]]` gives no problem, `![[missing-note]]` is R4 and `![[note.md]]`
resolves. My own design ruling after r11 (28213ac27) also made plain links attachments. The brief
narrowed that, and the brief governs this row.
Changes:
- `links.mjs`: `isAttachment` is true only for a body embed, `link.embed === true && !link.field`,
with the extension test as before. Its comment says it goes by name, so the reader asks it only
after resolving.
- `reader.mjs`: every link resolves first. An unresolved one is R4 unless `isAttachment` holds.
- `survey.mjs`: `quote()` also escapes U+061C (Webby N1). The attachment count now covers body embeds
only, since it uses `isAttachment`.
- Webby N2, my choice of Sage's two options: the survey keeps a count by name and the README says so,
"the count of body embeds whose target has an extension other than `.md`", and that `![[Dr.Quinn]]`
counts there even when Dr.Quinn.md exists. Checking against the survey's path list would mean a second
resolver in the survey, for a count that only guides the mapping.
- Tests. links: embeds only, with `[[cover.png]]`, `[[Board.canvas]]`, `[[Dr.Quinn]]`, a front matter
value and a markdown link all false, and `![[Dr.Quinn]]` true by name. reader: the Shore case now
gives R4 for the front matter `"![[portrait.JPG]]"` (line 3), for `[[Board.canvas]]` (line 5) and for
`![[missing-note]]` (line 6). The new Dr.Quinn case has Dr.Quinn.md indexed and resolves `[[Dr.Quinn]]` in
a block list and in the body, plus `![[Dr.Quinn]]`, with no problem. survey: a U+061C folder name
prints escaped, and the attachment count is 1, since `[[map.PDF]]` is a plain link.
Round 2 tests, one `node --test` per file, each run after a busy check.
Run 1, slot grant sage-1903, 09:39:32Z to 09:39:46Z: 60 pass, 1 fail. The new Dr.Quinn reader test failed
on order alone. All three links resolved to Dr.Quinn.md with the right field, line and embed values, and
there was no problem. The reader lists body links before front matter links, and my expected array put
the `relationships` link first. I stopped and reported it (gosalyn-0098).
Run 2, after the test-only fix sage-1907 approved, which moves that entry to the end of the expected array,
09:43:42Z to 09:43:56Z. Every rc 0.
| File | pass | fail |
|---|---|---|
| packages/library/tests/links.test.mjs | 7 | 0 |
| packages/library/tests/mapping.test.mjs | 7 | 0 |
| packages/library/tests/reader.test.mjs | 14 | 0 |
| packages/library/tests/render.test.mjs | 11 | 0 |
| packages/library/tests/survey.test.mjs | 6 | 0 |
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
Total: 61 pass, 0 fail, 0 cancelled, summed by awk.
-87
View File
@@ -1,87 +0,0 @@
# Row 247 build notes, C2-20b persona import follow-up (#1749)
Brief: docs/plans/2026-10-20_case2-rows.md "C2-20b persona import follow-up: printed keys, the dry run
fence check and the mkdir race", landed in 335bb3e30. These are Webby's row 221 notes N1, N2 and N4
(webby-0073, REVIEW-r1 a0a00630e on webby/reviews). N3 is in DEFERRED (sage-1941).
## Base
Branch gosalyn/c2-20b from 335bb3e30, which is row 221's landing 300766450 plus the brief.
## What changed
- N1, `scripts/case2-persona-import.mjs`: the per-channel prompt line prints the platform key, with its
fixed `platforms.` or `gateway.platforms.` prefix, and the channel key through `JSON.stringify`. A key
holding a newline prints as `\n` inside one quoted line. The profile name on that line is not config
text: `pairing` already holds it to `PROFILE_ID`.
- N2: the dry run calls `personaTextFault` on each persona after its count line. A fault prints as
`profile P: persona <reason>, so C2-08's fence would refuse it`, where the reason is the fixed string
`personaTextFault` returns, never persona text or a line number. With any fault the run refuses, exit
1, and writes nothing, as stage would. The header comment no longer says a fault is counted, not
refused, and now says a SOUL.md over four times the fence in bytes refuses before any count, which is
what `soul()` already did (Webby's second point under N2).
- N4: `privateDir` catches an EEXIST from its mkdir and refuses with `<path> was made by something else
between the check and mkdir`. Any other mkdir error is thrown as before, since the brief names only
EEXIST.
- Tests, `packages/cli/tests/case2-persona-import.test.mjs`:
- The per-channel prompt test expects the quoted keys.
- New: a chet config.yaml with a newline in the platform key and in the channel key prints one quoted
line, and no output line starts with the forged text.
- The dry run heading test now expects the fence fault line, exit 1 and the refusal, still with
nothing written. Its persona has two heading lines, which the fence refuses.
- New: a persona of 8001 two-byte characters, 16002 bytes and under the 32000 byte cap, makes the dry
run print the over 8000 characters fault, write nothing and exit 1. At exactly 8000 it exits 0.
- New: the mkdir race refuses by name at stage, for the staging directory, and at install, for
`personas/<business>`. Each refused directory is left empty.
- New fixture `packages/cli/tests/fixtures/case2-persona-import/mkdir-race.mjs`, an `--import` preload
like `trace.mjs`. It makes the directory named by `$PERSONA_MKDIR_RACE` just before the script's own
`mkdirSync` of that path, so the script meets a real EEXIST from the kernel, not a thrown stub.
## Known limit of N1
`JSON.stringify` escapes C0 controls, `"` and `\`, but leaves DEL, C1, U+2028, U+2029 and the bidi
controls raw. None of those ends a line on a terminal, so the forged line N1 names can't happen. A bidi
control could still reorder how the rest of that one line displays. The brief asks for `JSON.stringify`,
and Sage kept it in sage-1964 because the keys come from Jason's own Hermes config. Note for Webby: row
231's `quote()` in packages/library covers the wider set, and this row doesn't import it. If you want it,
ask for it in review.
## Mutants
One per fix, plus a second for N1 so each of its two keys has its own. Each replaces one exact string
in the script, runs the test file, then restores the script from a copy and checks its sha256.
| Mutant | Fix | Change |
|---|---|---|
| M1 | N1 | the channel key prints raw |
| M2 | N1 | the platform key prints raw |
| M3 | N2 | the dry run's refusal after a fault is skipped |
| M4 | N4 | privateDir's EEXIST branch never matches, so EEXIST is thrown raw |
## Outside readers
`git grep` over packages/*/tests/* and scripts/test-*.sh finds `case2-persona-import` only in its own
test file and in two files of its fixture tree, README.md and trace.mjs, which name the test file in a
comment. No test pins a hash of the script.
## Tests
Two slot runs, `busy.sh && run.sh` in /mnt/storage/scratch/gosalyn-r247, on the test file alone.
Run 1, grant sage-1969, 11:47:45Z to 11:48:00Z, was red: 14 tests, 12 pass, 2 fail. The fault was in the
script. Adding `JSON.stringify` to the per-channel line dropped the space after the comma, so it printed
`"-1001",29 bytes`. The two per-channel tests caught it. run.sh also went on to the mutants with a red
base, so their counts meant nothing. Sage approved both fixes in sage-1971: the space goes back, and run.sh
now exits 3 before the mutants unless the base is rc=0 with fail 0.
Run 2, grant sage-1971, 11:49:04Z to 11:49:22Z, was green: 14 tests, 14 pass, 0 fail, rc=0.
| Mutant | Line | rc | Failed | Killed by |
|---|---|---|---|---|
| M1 | 237 | 1 | 2 | the per-channel prompt test and the newline key test |
| M2 | 237 | 1 | 2 | the same two |
| M3 | 238 | 1 | 2 | the dry run fence test and the dry run heading test |
| M4 | 192 | 1 | 1 | the mkdir race test |
After the run the script's sha256 was 7031d2c0dc9bd22bc748b364a35b461fc01cb98b795032a2e0ec436f3188d4e4, the
same as the copy taken before it. The /proc scan found no process in the worktree or the scratch dir.
-149
View File
@@ -1,149 +0,0 @@
# Row 218 draft notes: claims and sources
Drafts for `docs/case2/SETUP-SHEET.md` and `docs/case2/SURVEY-RUN.md`. Repo base: `refactor` at
947101d8a, which holds 29ce1e360 (row 231). "Design" means
`git show 75fb3e10e:agents/gosalyn/work/case2/DESIGN.md`, cited as `D:<line>`. "Brief" means
`docs/plans/2026-10-20_case2-rows.md`. Code paths are relative to the repo root. Nothing was run
except reads, greps and `git merge-base --is-ancestor 29ce1e360 HEAD`.
## SETUP-SHEET.md
| Claim | Source |
|---|---|
| She keeps writing in Obsidian, obsidian-git pushes to git.mosaicstack.dev, nothing changes on her machine, nothing commits to her repo | D:939-940 (7.1) |
| Agents read what she pushed; a push reaches them in about a minute | D:1006-1007 (7.5); D:972-973 (60-second sync timer) |
| Agents read `.md` notes inside book folders only | D:457-461 (1.2); `packages/library/src/scope.mjs:9-19` |
| Not read: top-level notes, `.canvas`, `.base`, attachments, anything outside a book folder | D:461 |
| Other repos under `~/src` are not read | D:489 (1.3), D:494-497 (N4) |
| Agents can't write to her repo: canon, playground, anything | D:389 (D3); D:1008 |
| Folder roles live in the `projects` entry of the business file, hand-edited, agents can't change it | D:409-429, D:443-451 (1.1, M9) |
| Jason asks her to confirm the mapping first | D:431; D:1324-1328 (10 step 7) |
| A folder named in `playground` is her playground | Brief:22; D:434 |
| Each playground prefix sits inside one book folder | D:434-436; `packages/library/src/mapping.mjs:77-80` |
| One per book, e.g. `<book>/playground/`; until then everything mapped is canon | D:438-439 |
| Agents search canon unless they ask for the playground | D:463 |
| Playground may back an idea or question, not a fact, finding or correction; refused before she sees it | D:858 (`playground-cited-as-canon`); D:378-382, D:835-839 (guard runs before store) |
| Only the folder decides; a tag or property can't change scope | D:388 (D2); D:440-441; `scope.mjs:1` |
| Graph colour group via Groups and a `path:` query, her own vault setting, changes nothing for agents | Brief:23; D:941-943. Obsidian UI steps from the task prompt, not the design |
| Path starts with the books repo folder because the vault is `~/src` | D:939 |
| N2: moving a note into a book folder makes it canon, agents may cite it as fact | D:944-945; D:259 |
| Rough drafts outside the playground are canon | Inference from D:460 (scope rule) |
| N4: Obsidian resolves short links across `~/src`, the reader sees one repo, the two can differ, the reader can't tell | D:494-497; D:262-263 |
| A name only in another repo leads nowhere for agents | D:489 (R4); `packages/library/src/links.mjs:61-87` |
| A full-path link resolves the same in both | D:497-498. Hub side: `links.mjs:77-78` (`vault-prefix` step) |
| "New link format: Absolute path in vault" setting | Obsidian UI knowledge. Not in design or code. Reviewer may strike it |
| `appears_in` and `relationships` links are read as links | D:489-490; `packages/library/src/reader.mjs:15`, `:153-162` |
| Quoted flow list `["[[A]]", "[[B]]"]` parses | `reader.mjs:81-96` (flow), `:66-73` (quoted scalar), `:159` |
| Block list with quoted items parses | `reader.mjs:117-122`, `:66-73` |
| Unquoted `[[[A]], [[B]]]` is R3 | Brief:28-29; `reader.mjs:87` (bracket inside a flow list stops parsing), `:137` |
| R3 effect: whole front matter unread, note still indexed by path, name and body, listed as a problem | D:480; `reader.mjs:103-105`, `:193`; `packages/library/README.md:69` |
| Problems show in Mosaic's status | D:473-474; D:999-1000 (7.4 status line) |
| A value without `[[ ]]` is a name | D:489-490; `reader.mjs:159` |
| Bean and Chet keep names and personalities | D:660-661 (Q180) |
| Hermes: free text and story text. Mosaic: short cited items, a prose request gets a question or idea | D:778-781 (design 4) |
| Bean and Chet's item kinds: idea, question, finding, fact; web cites allowed | D:649 (`companion`); D:860 (`citation-unfetched`) |
| Limits 10 items, 5 ideas of 200, others 300 | D:819 (M5) |
| She or Jason can ask for lower limits | D:1329-1330 (10 step 8); D:831 |
| "No cited answer" notice | D:870-871, D:996-997 |
| One item can't mix two worlds | D:859 (`citation-cross-universe`) |
| She talks to them in the Console; Hermes keeps running until she moves over; stopping it is her choice | D:381-382; D:1331 |
| Five more helpers; she chooses the start set and can add one later | D:647-654; D:783-784; D:1327-1328 |
| What Jason will ask | D:1325-1327 (10 step 7) |
## SURVEY-RUN.md
| Claim | Source |
|---|---|
| Runs on `<host>` 10.1.1.54 under design 10 step 7, after step 4 | D:1324; D:1266 (host) |
| Prints names and counts, never note text, property values, file names or link targets | `packages/library/src/survey.mjs:1-6`; README:118-125 |
| Sending to Melanie is Jason's call | Brief:36; D:1324-1328 |
| Token slot `library-gitea` is step 4 | D:1314-1316 |
| Run as `sudo -u mosaic -H` from `localadmin`; `mosaic` has no login shell | D:1195-1197; D:1281-1282 |
| Copy at `/srv/mosaic/.local/share/mosaic-stack/copies/<id>`, `<id>` = commit in Jason's go | D:1286-1292 (2c); `docs/TOOLS.md:417`; home `/srv/mosaic` per D:1314-1315 |
| The copy carries `packages/library/src` | `scripts/stack-copy.sh:36` |
| Row 231 adds the control and bidi escapes | `git log` 29ce1e360; `survey.mjs:78-82`; README:121-122 |
| `<node dir>` is the `--node` directory of step 2c; `scripts/mosaic` execs `node` from PATH | D:1290-1291; `scripts/mosaic:41` |
| Dispatch: `mosaic library survey` goes to `survey.mjs` with `survey <args>` | `scripts/mosaic:37-41` (one `shift` leaves `survey` as argv[0]); `survey.mjs:102-103` |
| Command and flags: `<repo>` plus optional `--mapping <file>` once; anything starting with `-` refuses | `survey.mjs:16`, `:104-110` |
| No fetch; reads `HEAD` | `survey.mjs:5-6`, `:27`; `reader.mjs:22-24` |
| Top folder only: ceiling is the path's parent | `packages/project/src/git.mjs:12`, `:62` |
| Owner must be `mosaic`: git gets no global config | `packages/seat/src/checkout.mjs:79-89` (`GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`). The dubious-ownership refusal is git's own behaviour |
| Bus mirror path `<dataRoot>/projects/<business>/<project>` | Brief:300; `packages/project/src/paths.mjs:34-40` |
| C2-04 and C2-03a not landed | `grep` of `packages/*/src` finds no library entry handling or `refs/heads/served`; `docs/guides/host-run-sheet.md:269` says "not landed" |
| Served ref `refs/heads/served` | D:963 (7.2); Brief:676 |
| Token kept out of URL, config, argv, logs | D:955-956 (7.2) |
| Mapping file is the entry alone; `remote`, `branch` required | `survey.mjs:114-116`; `mapping.mjs:38-47` |
| Output lines and fields | `survey.mjs:83-97`; data from `:26-76` |
| Folder lines list folders that directly hold an entry, full path | `survey.mjs:30-35` |
| Key names: short identifiers print, others as `(other key)` | `survey.mjs:17-20`, `:47` |
| `unresolved` equals the R4 count | `survey.mjs:72` |
| Scope counts cover all tree entries | `survey.mjs:66` |
| Refusal exit codes 0, 2, 3, 4 | `survey.mjs:99-124`; README:127-129 |
| Mapping checked before repo | `survey.mjs:112-121` |
| stderr format `library survey: <message>` | `survey.mjs:101`; `problems.mjs:3-5` |
| `(project-git)` suffix on git failures | `reader.mjs:18-20`; `paths.mjs:4-6` |
| `library-playground-outside-book` message | `mapping.mjs:79-80` |
| 100-second git timeout | `checkout.mjs:49`, `:52`; `git.mjs:68` |
| Exit 127 when `node` is missing | `scripts/mosaic:18`, `:41` (bash `exec` failure). Not run |
| Other errors rethrow as a stack trace | `survey.mjs:117`, `:123`, `:128-131` |
| Don't work around a refusal | AGENTS.md invariant 6 |
## Code and design disagreements
1. Design 1.1 shows the mapping nested in `"projects": {"books": {...}}` (D:412-429). The survey's
`--mapping` file must be the inner entry alone (`survey.mjs:114-116`). The run sheet follows the code.
2. Design 1.3 calls `vaultPrefix` part of the mapping (D:418). The code makes it optional
(`mapping.mjs:48`, README:30). Without it, a full vault path link, the N4 advice, resolves to
nothing in the hub (`links.mjs:73-87`: `root` fails, `vault-prefix` is skipped, `shortest` refuses a
`/`). The setup sheet's full-path advice holds only when Jason sets `vaultPrefix` to her books repo
folder name.
3. The task prompt calls the unquoted form "refused". R3 is not a refusal. It is a reported problem,
and the note stays indexed (D:473, D:480). The sheet says what happens instead.
## Open questions
1. Where `<repo>` comes from on .54. The survey reads a local repo's `HEAD` and never fetches. The bus
mirror needs C2-04 and C2-03a, neither landed. C2-03a moves `refs/heads/served`, not `HEAD`, so the
mirror's `HEAD` may name no commit and the survey would refuse with exit 2. The sync also needs a
checked mapping with at least one book (`mapping.mjs:59`, `:70`), and the mapping's values are
meant to come from this survey (D:431). Sage needs to rule: a placeholder mapping for the first
sync, a `HEAD` the sync sets, a `--commit` flag on the survey, or another source.
2. The brief says Obsidian's property editor writes `appears_in: ["[[A]]", "[[B]]"]` (Brief:28-29,
webby-0041 N4). I didn't read webby-0041 or check Obsidian's output. Both the flow and the block
quoted forms parse, so the sheet shows both and says only that the editor adds the quotes.
3. Whether `/srv/mosaic/.npm-global/bin/mosaic` exists on .54. The run sheet uses the copy's
`scripts/mosaic` by full path to avoid depending on a wrapper.
## Sage's rulings on the open questions (2026-10-21)
1. Survey source: the bus's bare mirror after the first `library.sync`, the only copy on the host
(design 2.1). The C2-03a brief now requires the mirror's `HEAD` to be a symbolic ref to
`refs/heads/served`, with a test (5c6f73ed7), so the survey reads the served commit with no ref flag.
2. Property list forms: the sheet shows both quoted forms, since both parse. Webby checks the claim
that Obsidian's property editor writes the quoted form.
3. The "New link format: Absolute path in vault" tip stays. It is an Obsidian setting, not a design
claim, and Webby may strike it.
4. The run sheet calls the copy's `scripts/mosaic` by full path. That holds whether or not a wrapper
is on `PATH`.
5. `vaultPrefix`: the run sheet's step 4 tells Jason to set it, because the setup sheet's full-path
link advice depends on it.
## Round 2 (2026-10-21), from Webby's round 1 notes (webby-0075, rev 2848)
- N1, by Mos's ruling mos-1165 (fix before landing): SETUP-SHEET.md now gives the 1,200 character
total of item text per reply (design M5, step 8). The word "Today" is gone. No code enforces these
caps until C2-06 lands, so my ruling is that the sheet goes to Melanie only after C2-06 lands, and
then only on Jason's go (#419). The wording stays as is, because by then it holds.
- N2: SURVEY-RUN.md says tab, newline, carriage return, backspace and form feed print as `\t`, `\n`,
`\r`, `\b` and `\f`, and other control and bidi characters as `\uXXXX` (survey.mjs quote()).
- N3: SURVEY-RUN.md has a refusal row for `library-commit:` (reader.mjs listTree). survey.mjs turns
every LibraryError into exit 2 with its message.
- N4: SURVEY-RUN.md's new step 2 checks `command -v node` under the same sudo and PATH before the
survey runs.
## Round 3 (2026-10-21), from Webby's round 2 note N5 (webby-0077, rev 2856)
- N5: the library-commit row no longer says a moved `HEAD` causes it. The survey reads `HEAD` once,
and listTree raises library-commit only for an id that isn't 40 hex or an object that isn't a
commit (reader.mjs:29, :31). In practice that means a SHA-256 repository, so a rerun doesn't help.
The row now says "for example in a SHA-256 repository" and "Report to Sage".
-13
View File
@@ -1408,16 +1408,3 @@ are never rewritten or removed; corrections are new entries.
2026-10-21T08:37:47Z | Filbert (Opus 5.5, 048f3c63) | row 215 (C2-04) manifest r2 review, herb/row215 2522025af | APPROVE, static: B1-B3 and N1-N2 resolved per sage-1860/1862; build notes on lock file creation, mirror metadata allowlist and flock dependency; sent to Herb and Sage 08:37Z
2026-10-21T08:52:06Z | Darkwing (Opus 5.5, 7525c8e4) | row 195 (#1693) build and manifest round 1 in review (rev 2756, request comment 29985, results 29987) | darkwing/row195-b 37171f65b on 4ced5e63d (ddf7dce6c build: scripts/case1-accept.sh, case1-accept.test.mjs, TOOLS.md entry, DESIGN r7 doc fixes per sage-1817; 37171f65b BUILD.md results); slot: single 22/22 (sage-1829), 12/12 mutants killed and gate cli 662/0 plus scripts 429/0 selftests (sage-1865), green per sage-1870; Duckworth reviews (sage-1872); Gosalyn 0087 Q4/Q5 match W10/W12; flock goes to DEFERRED with 215 (sage-1871); nothing touched .53
2026-10-21T09:20:46Z | Sage (Opus 5.5, 1ef1e4f8) | 212+197 combined landing gate (node 981/0, selftests 429/0, 08:51-09:03Z); 197 lane proof stopped after two failures (try 1 lane-image base inspect, N7; try 3 solo-a process.test.mjs:82 under umask 077), recovered cf48efccf083; mos-1162: row 212 landed alone as ee7b2f137 (paths match a2c72ac95, patch-id ea84d3e35470), #1713 closed 29996, revs 2759-2760; DEFERRED N7 plus brief docs/plans/2026-10-21_gate-env-rows.md at fefd54e13, rows 243 (chmod) and 244 (fixture PI_AUTH_FILE) revs 2761-2762; row 66 rebuilt as sage/row66-r4b 49ad61963 on fefd54e13 (manifest 99cab8275af4, not yet requested); slots: Herb 215 focused 26/0, Gosalyn 231 singles 60/0, Herb 197 r6 focused granted; kept root ga-8I3iZc removed (sage-1827..1893) | in progress
2026-10-21T10:12:45Z | Darkwing (Opus 5.5, 7525c8e4) | row 245 (#1693) built, slot asked (darkwing-0105) | claim rev 2795; darkwing/row245 0590a29fc pushed, on 62ddc96cc: 5273de0b7 cherry-pick of 1e3c4767c (case1-accept.sh, test, TOOLS.md blobs identical) and 0590a29fc notes to queue-245/BUILD.md (DESIGN.md:336-338 superseded by gosalyn-0087, unedited, sage-1877); slot scripts in /mnt/storage/scratch/darkwing-245-out pinned to 0590a29fc, nothing run; told Sage the untracked queue-195 DESIGN.md was r2 (fcbb4aa9b = 818b79696), nothing lost; flagged 245 and 246 both closing #1693
2026-10-21T11:28:49Z | Sage (Opus 5.5, 1ef1e4f8) | 235 landing gate (bus 596/0, business 200/0, cli 666/0, scripts green) and landing b1fece6f0, #1741 closed 30026; 197 r6 D5 proof stopped at solo-a script-release (Compose run has no --no-build, reproduced in lane env), #1695 30031; 221 landed before 197 r7 (sage-1954): gate 11:07-11:19Z (test 11/0, harness 140/0, cli 677/0, scripts green), 300766450, #1722 closed 30033, revs 2812-2813; C2-20b brief and DEFERRED N3 in 335bb3e30, row 247 #1749 briefed; 197 r7 9c3166915 focused run on my slot (red 9/2, green 11/0, mutant killed), request rev 2819 (30036), proof candidates A 2be6d07fa and B cceb258ff ready; slots Herb sage-1956, Darkwing 245 sage-1961 (sage-1894..1962) | in progress
2026-10-21T11:50:41Z | Darkwing (Opus 5.5, 7525c8e4) | row 245 (#1693) slot green, round 1 in review (rev 2842, request comment 30040) | grant sage-1961 on 0590a29fc: singles 23/0, mutants 16/16 killed (13-15 N1, 16 N3), gate cli 664/0 and every scripts/test-*.sh green (429/0), /proc scan empty; results commit ef8b4439e pushed on darkwing/row245; manifest ~/darkwing-scratch/r245/manifest-ef8b4439e*.sha256, 5 paths; slot handed back (darkwing-0107); Duckworth woken (darkwing-0108)
2026-10-21T13:43:38Z | Filbert (Opus 5.5, 048f3c63) | row 215 C2-04 candidate review r1 (herb-0083/0085, sage-2019) | APPROVE on 8d5695d7 tip 14a03d10f, static, no tests; #1716 c30071, queue rev 2897; N1-N4 non-blocking
2026-10-20T23:34:58Z | Dewey (Opus 5.5, 84fb346c) | #436b design r4 review (megavolt-0055, DESIGN.md 3e66f5acf) | CHANGES: revoke on an open rotation deletes one of two live tokens; N8 refuse a new grant while held; items 1 (sage-1578 b), 2, N7, duckworth N1 settled; verdict design-r4-verdict.md 19fdb59a; dewey-0761 Megavolt, dewey-0762 Sage
2026-10-20T23:35:58Z | Dewey (Opus 5.5, 84fb346c) | #436b design r5 review (megavolt-0057, DESIGN.md 1be535aca) | APPROVE; build carries N9 (settle row skips a revoked rotation, 404 delete is done) and N10 (serviceLeft list); verdict design-r5-verdict.md de52be1b; dewey-0763 Megavolt, dewey-0764 Sage
2026-10-20T23:41:36Z | Dewey (Opus 5.5, 84fb346c) | row 222 askpass vs 199 helper (megavolt-0061, design 7.2 8614ba87c) | accepted (a) http.followRedirects=false and (b) host/user-checked helper, plus exact prompt match, credential.helper reset or mirror config check, tests and mutants listed; dewey-0765 Megavolt, -0766 Gosalyn, -0767 Sage
2026-10-21T05:03:38Z | researcher | row 228 (#1729) round 2 in review (revs 2667, 2668) | round 1 4fa2ed1e3 (Webby 29677) drifted on packages/cli/README.md; rebased onto 9b5362018 as researcher/row228-r2 (3a2b547c3 + 5f2aad593 carrying the N1 trim), pushed; manifest ab40b92f (3 files); slot sage-1720: singles 94/0 (13+10+42+29), mutant M1 killed, restore sha OK; busy-check copy used for the 16-hour launchpad-test-dex container (Sage ok, sage-1729); request failed (no token), Sage posts as jarvis; packet agents/researcher/work/queue-228/r2
2026-10-21T06:47:54Z | researcher | row 228 (#1729) round 3 in review (rev 2702; start rev 2700) | rebase of r2 onto the 234 landing c771a36f4 as researcher/row228-r3 cf18c42b9 (one commit, pushed) with Webby's round 2 N1 (:711 and :718); manifest 82cf98c6 (3 files); slot sage-1796: session.test 13 + host.test 42 = 55/0, manifest OK before and after, busy228.sh copy named in the clear; r2 94/0 and M1 killed stand (seat blobs unchanged); request attempt left in requesting state (lock held by sage-238-review-2b when the outcome rev was written, exit 3; transport said failed pre-send, no token), Sage resolves and posts as jarvis; packet agents/researcher/work/queue-228/r3
2026-10-21T07:29:23Z | researcher | row 228 (#1729) landed as 86249ac55 (pushed 07:25Z by Sage) | patch-id b6ffe31feb0d matches my r3 candidate cf18c42b9 (checked here against origin/refactor); Sage combined gate with 238: seat 165/0, cli 640/0, scripts 585/0; queue note rev 2725, done rev 2727, #1729 closed comment 29966 (sage-1824); q228r2 worktree removed, branches researcher/row228, -r2 and -r3 stay on origin and locally; packets agents/researcher/work/queue-228 r1 r2 r3 uncommitted
2026-10-21T15:19:14Z | Sage (Opus 5.5, 1ef1e4f8) | MVP push 10-21 afternoon: rows 249, 197 proof 3/4, 222 singles, 66 r4d, queue-commit | 249 landed 9de5a57ab (+7b9737953 DEFERRED N1, #1751 closed, Vikunja 445 c442); 197 proof 3 rc=1 on a driver defect, Herb's fix a5b636750 to Webby, proof 4 set up in sage-r197p4; 222 singles 34/34 and 5 mutants killed (sage-2028); 66 round 4 in review (82c830779, c30083/30084); queue revs 2642-2904 committed 0636721e6
2026-10-21T16:04:23Z | Gyro (T3 Codex gpt-6.1-sol) | Q195/Q196 design only, #1752 / Vikunja #448, gyro/editor-design | Code-measured writing-editor draft with three options, local thesaurus, pane/pins, guarded API/MCP, DesignCraft handoff and proposed briefs; queue next refused linked worktree, canonical next gyro returned nothing; no implementation or live actions.
-125
View File
@@ -1,125 +0,0 @@
# Your books in Mosaic: a setup sheet
This sheet is for you, Melanie. You keep writing in Obsidian the way you do now. Mosaic reads your
books repo after obsidian-git pushes it to git.mosaicstack.dev. It changes nothing on your machine and
commits nothing to your repo.
## What the agents read
The agents read your books repo as you last pushed it. A push reaches them in about a minute.
They read notes, the `.md` files, inside your book folders. They don't read:
- notes at the top of the repo, outside any book folder
- `.canvas` and `.base` files, even inside a book folder
- images and other attachments
- anything in your other repos under `~/src`
They can't write to your repo at all. That covers canon, the playground and everything else.
Which folders are book folders, and which hold characters, places, research, your tracker or chapter
summaries, is set in one place. It is the `projects` entry of your business file in Mosaic. Jason
edits it by hand, and the agents can't change it. He will ask you to confirm it before the agents start.
## Your playground
A folder named in the `playground` list of that entry is your playground. Each playground folder sits
inside one book folder, so one per book works well, for example `<book>/playground/`. You choose the
names and tell Jason. Until you have one, every note in a book folder is canon.
What the playground means for the agents:
- They search canon unless they ask for the playground on purpose.
- An agent may quote a playground note in an idea or a question. It may not use one to back a fact,
a finding or a correction. Mosaic refuses that reply before you see it.
- Only the folder decides. A tag or a property can't make a note playground or canon.
### Colour the playground in your graph
This is a setting of your own vault. It changes nothing for the agents.
1. Open the graph view and open its settings panel.
2. Under Groups, choose New group.
3. In the query box, type the playground's path with `path:`. Your vault is `~/src`, so the path
starts with your books repo folder: `path:"<books repo folder>/<book>/<playground folder>"`.
4. Pick a colour.
Add one group per playground folder.
## Two things you might not expect
### Moving a note into a book folder makes it canon
The folder decides, so a move changes what the agents may do with a note. Once you move a note out of
the playground into a book folder and push, it is canon. The agents may then cite it as fact. A note
that isn't settled yet belongs in the playground. Any note in a book folder outside the playground is
canon, rough drafts included.
### A short link can point somewhere else for the agents
Obsidian looks up a short link like `[[Mara]]` across your whole vault, `~/src`. The agents see only
your books repo. Say a note called `Mara` exists in your books repo and also in another of your repos.
Obsidian and the agents can then open different notes for the same link, and the agents can't tell.
If the name exists only in the other repo, the link leads nowhere for the agents.
A link with the full path from the top of your vault reaches the same note in both:
```
[[<books repo folder>/<book>/<characters folder>/Mara]]
```
Obsidian can write new links this way. In Settings, open Files and links and set New link format to
Absolute path in vault.
## Lists of links in properties
The agents read the links in two properties, `appears_in` and `relationships`. Put quotes around each
link in the list:
```yaml
appears_in: ["[[A]]", "[[B]]"]
```
One link per line works too:
```yaml
appears_in:
- "[[A]]"
- "[[B]]"
```
Obsidian's property editor adds the quotes for you. If you type the list by hand, don't leave them out:
```yaml
appears_in: [[[A]], [[B]]]
```
The agents' reader can't read that form. It then ignores every property of that note and lists the
note as a problem in Mosaic's status. It still finds the note by its path, its name and its text. A
value written without `[[ ]]` counts as a plain name, not a link.
## What changes for Bean and Chet
They keep their names and personalities. How they answer changes.
In Hermes they answer in free text and may write story text when you ask. In Mosaic every reply is a
short list of items. Each item is an idea, a question, a finding or a fact. Each one quotes a line
from your repo or from a web page the agent read for you.
They don't write passages. If you ask for prose, you get a question or an idea instead.
A reply holds at most 10 items and at most 1,200 characters of item text in all. It has at most 5
ideas of up to 200 characters each. A question, finding or fact runs up to 300 characters. You or
Jason can ask for lower limits. When an agent can't back an answer with a quote, you see "No cited
answer" instead.
Each book world stays separate. One item can't mix quotes from two worlds.
You talk to them in the Console. Hermes keeps running until you have moved over, and stopping it is
your choice.
Five more helpers can join them: ideas, research, proofreader, fact-checker and continuity. You
choose which ones to start with, and you can add one later.
## What Jason will ask you
He will ask you to confirm your book folders and type folders, which books share a world, the name of
each playground folder, and which helpers to start with and when.
-122
View File
@@ -1,122 +0,0 @@
# Survey run sheet for the library host
This sheet is for whoever runs `mosaic library survey` on `<host>`, 10.1.1.54, under design 10 step
7. The survey reads one commit of a git repo and prints names and counts. It never prints note text,
property values, file names or link targets. Jason fills in the mapping for Melanie's books repo
from its output and her answers.
Out of scope: sending anything to Melanie. Design 10 step 7 makes that Jason's call.
## Before you start
- Jason's go for step 7. Step 4, the bot token in the `library-gitea` slot, comes first.
- You run as `mosaic` with `sudo -u mosaic -H` from `localadmin`. `mosaic` has no login shell.
- The stack copy from step 2 is in place at `/srv/mosaic/.local/share/mosaic-stack/copies/<id>`.
`<id>` is the full commit id in Jason's go. It must hold row 231, which escapes control and bidi
characters in folder names. In a canonical checkout, `git merge-base --is-ancestor 29ce1e360 <id>`
exits 0 when it does.
- `<node dir>`, the directory that holds `node`. It is the directory of the `--node` path given to
`case2-unit.sh` in step 2c. `scripts/mosaic` runs `node` from `PATH`.
- `<repo>`, an absolute path. See the next section.
## The repo to survey
The survey reads a local repo. It doesn't fetch. `<repo>` must:
- be the repo's top folder, or a bare repo's own folder. A folder inside a repo refuses, because the
survey stops git from looking above the path's parent.
- belong to `mosaic`. The survey gives git no global config, so a `safe.directory` entry can't
admit a repo another user owns.
- have a `HEAD` that names a commit. The survey reads `HEAD` and has no flag for another ref.
`<repo>` is the bus's bare mirror at `<dataRoot>/projects/<business>/<project>`, which C2-04 (row 215)
creates and C2-03a (row 222) fetches into. It is the only copy of her repo on the host (design 2.1), and
`mosaic` owns it. Survey it after the first `library.sync` succeeds. The mirror's `HEAD` points at
`refs/heads/served` (C2-03a brief), so the survey reads the commit the agents are served.
Don't survey anything else. A hand clone with the bot token would put the token where design 7.2 keeps
it out, and the mirror's refs belong to the bus. If `HEAD` names no commit, stop and report to Sage.
## Steps
1. `ssh [email protected]`.
2. Check which `node` runs. `PATH` ends in `/usr/bin:/bin`, so a wrong `<node dir>` would quietly run
another `node`:
```sh
cd /
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" sh -c 'command -v node; node --version'
```
The first line must be `<node dir>/node`. If it isn't, fix `<node dir>` before going on.
3. Run the survey without a mapping:
```sh
cd /
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" \
/srv/mosaic/.local/share/mosaic-stack/copies/<id>/scripts/mosaic library survey <repo>
echo "exit $?"
```
4. On exit 0, give the output to Jason. On any other exit, see "Refusals" below.
5. When Jason has a draft mapping, run it again with `--mapping`. The file holds the library entry
alone, `{"kind": "library", "remote": ..., "branch": ..., ...}`, without the business file or the
`"projects"` wrapper around it. `remote` and `branch` are required even though the survey doesn't
fetch. `mosaic` must be able to read the file. Set `vaultPrefix` to her books repo's folder name
in her vault. Without it, a link with the full path from the top of her vault resolves to nothing,
and the setup sheet tells her to write links that way.
```sh
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" \
/srv/mosaic/.local/share/mosaic-stack/copies/<id>/scripts/mosaic library survey <repo> --mapping <file>
echo "exit $?"
```
The usage line is `mosaic library survey <repo> [--mapping <file>]`. `--mapping <file>` is the only
flag, and it may appear once. `--mapping=<file>` and every other flag refuse.
## What the output holds
Plain text on stdout, one line per item:
| Line | What it holds |
|---|---|
| `commit <id>` | the 40-hex commit `HEAD` names |
| `entries <n>` | every entry in that commit's tree |
| `folders (direct children: md canvas base other)` | then one line per folder that holds a file directly: its path as a JSON string and four counts. `(root)` is the repo's top |
| `markdown <n> files, <n> read, ...` | `.md` files, how many were read, how many have no front matter, how many have front matter the reader can't fully parse |
| `front matter key sets` | then `<count> [<keys>]` per set of property names. A name that isn't a short identifier prints as `(other key)` |
| `body links plain .., label .., heading .., embed .., self .., markdown ..; attachment ..` | link forms in note bodies, and embeds of a target with an extension other than `.md` |
| `field appears_in wikilink .., name ..` | values written as links and as plain names. A `relationships` line follows |
With `--mapping` three lines follow:
| Line | What it holds |
|---|---|
| `scopes canon .., playground .., unmapped ..; indexed ..` | tree entries per scope, and notes indexed |
| `resolved root .., vault-prefix .., relative .., shortest .., unresolved ..` | links per resolver step. `unresolved` is the R4 count |
| `problems R1 .., ..., R7 ..` | problems per rule |
Folder paths and short property names are the only words from her repo in the output. In a folder
name, tab, newline, carriage return, backspace and form feed print as `\t`, `\n`, `\r`, `\b` and `\f`.
Any other control or bidi character prints as `\uXXXX`.
## Refusals
A refusal prints nothing on stdout and one line on stderr. The survey checks the mapping before the
repo, so a bad mapping gives exit 3 even when the repo path is wrong too.
| Exit | stderr | Cause | What to do |
|---|---|---|---|
| 4 | `library survey: usage: mosaic library survey <repo> [--mapping <file>]` | no repo, two repos, an unknown flag, `--mapping` without a file or twice | Fix the command |
| 3 | `library survey: library-mapping-invalid: <file> is not a readable JSON file` | missing, unreadable by `mosaic`, or not JSON | Fix the file or its mode |
| 3 | `library survey: library-mapping-invalid: <file> <reason>` | the entry breaks the schema. The reason names the key | Give it to Jason for the draft |
| 3 | `library survey: library-playground-outside-book: <file> universes.<u>.playground "<prefix>" is not inside one of its books` | a playground prefix outside its universe's books | Give it to Jason for the draft |
| 2 | `library survey: library-git: <repo> is not a directory` | wrong path | Check `<repo>` |
| 2 | `library survey: library-git: repository has no readable HEAD commit (project-git)` | not a repo, a folder inside one, another owner, no commits, a `HEAD` with no commit, or no `git` on `PATH` | Check each. If `<repo>` is the bus mirror, stop and report to Sage |
| 2 | `library survey: library-git: <other reason>`, such as `tree listing refused (project-git)` | git failed or ran past 100 seconds | Report to Sage |
| 2 | `library survey: library-commit: <reason>` | `HEAD` names something the reader can't take as a commit, for example in a SHA-256 repository | Report to Sage |
| 127 | a line ending `exec: node: not found` | `node` isn't in `<node dir>` | Fix `<node dir>` |
| other | a Node stack trace | a fault in the survey | Stop and report the exit code to Sage |
A refusal is the answer, not an obstacle. Don't run as another user, change modes on her repo or edit
its refs to get past one.
-6
View File
@@ -106,17 +106,11 @@ apt-get download apparmor-profiles=4.0.1really4.0.1-0ubuntu0.24.04.9
dpkg-deb --fsys-tarfile apparmor-profiles_*.deb | tar -x ./usr/share/apparmor/extra-profiles/bwrap-userns-restrict
echo "11d39094f044f0cda0febb3ad517b830301da6b2ce929664af09ee9e4dd264f9 usr/share/apparmor/extra-profiles/bwrap-userns-restrict" | sha256sum -c -
install -o root -g root -m 0644 usr/share/apparmor/extra-profiles/bwrap-userns-restrict /etc/apparmor.d/bwrap-userns-restrict
echo "11d39094f044f0cda0febb3ad517b830301da6b2ce929664af09ee9e4dd264f9 /etc/apparmor.d/bwrap-userns-restrict" | sha256sum -c -
apparmor_parser -r /etc/apparmor.d/bwrap-userns-restrict
dpkg-statoverride --update --add root mosaic 0750 /usr/bin/bwrap
```
Run as root in a `mktemp -d` dir, `apt-get download` prints a line starting `W: Download is performed
unsandboxed as root`, because the `_apt` user can't write that dir. The line is expected and the
download still succeeds. Each `sha256sum -c -` line must print `OK`. The second one checks the copy in
`/etc/apparmor.d`, the file that loads. Stop on any other result.
`aa-status` then lists `bwrap` and `unpriv_bwrap` in enforce mode. Install the one profile file, never the
whole `apparmor-profiles` package, whose 20 other profiles would load at the next boot. Rollback, in
reverse order: `dpkg-statoverride --remove /usr/bin/bwrap`, then `chown` and `chmod` to the values in
-52
View File
@@ -593,54 +593,6 @@ gate, along with every `scripts/test-*.sh`.
---
## C2-20b persona import follow-up: printed keys, the dry run fence check and the mkdir race
### Problem
Webby's round 1 review of row 221 (webby-0073, REVIEW-r1 a0a00630e on webby/reviews) approved it with
four notes that don't block. Three are in `scripts/case2-persona-import.mjs` and go in before Jason's
import run, because he runs the script once (sage-1941):
- N1: lines :147 and :237 print channel and platform keys from `config.yaml` as they are. A key with a
newline or a control character could forge an output line.
- N2: the dry run counts but doesn't apply C2-08's 8000-char fence. A persona over the fence and under
32000 bytes passes the dry run and then refuses at staging.
- N4: `privateDir` runs lstat, then mkdir. A directory made between the two gives a raw EEXIST. It still
fails closed, so only the error text is wrong.
N3 (Morgana's 213 `mutants.py:48` B3 pattern no longer matches `bundle.mjs`) isn't in this row. It's in
DEFERRED.
### Owner and reviewer
- Owner: Gosalyn.
- Reviewer: Webby.
- After: row 221 (C2-20) lands.
### Files owned
`scripts/case2-persona-import.mjs`, `packages/cli/tests/case2-persona-import.test.mjs` and its fixture
tree.
### What ships
- N1: every printed config key goes through `JSON.stringify`.
- N2: the dry run calls `personaTextFault` on each persona and prints the fault's name. It still prints
no persona text, no line and no line number.
- N4: an EEXIST from the mkdir refuses with a named reason, not a raw EEXIST.
Tests:
- A fixture key with a newline prints as one quoted line.
- A persona over the fence makes the dry run print the fault, write nothing and exit nonzero.
- The mkdir race refuses with the named reason. A stubbed mkdir that throws EEXIST is enough.
- One mutant for each of the three fixes, each killed by its test.
### Gate
Webby approves the manifest. The test file runs green on its own, and the three mutants are killed on
Sage's slot. The cli suite and every `scripts/test-*.sh` are green on Sage's gate.
---
## C2-03a fetch-only sync
### Problem
@@ -675,10 +627,6 @@ Design 7.2's slice:
- An `https://` URL only.
- The served ref `refs/heads/served`, and `library-diverged`, held until a human `library.sync --accept
<commit>`.
- The mirror's `HEAD` is a symbolic ref to `refs/heads/served`, so `mosaic library survey <mirror>` reads
the served commit. The survey reads `HEAD` and has no ref flag, and design 10 step 7 surveys this mirror
(C2-12 run sheet; Sage, 2026-10-21). Test: after the first sync, `git symbolic-ref HEAD` in the mirror
prints `refs/heads/served` and the survey's `commit` line equals the served commit.
- The sync state file, written atomically inside the mirror, and the 60-second timer.
- `library.sync`, human only. A test reaches a local bare repo only through the module parameter that
replaces `syncCommand`.
-50
View File
@@ -121,53 +121,3 @@ tells Mos before row b lands.
Gate: as row a, with section 10's row b tests and mutants, G27, G28 and the upsert mutant included, and
the creative refusal tests and mutants (writer and spend).
## Machine grant row b follow-up: the held stubs end with their test
The row 197 r8 D5 proof stopped on a leftover process on 2026-10-21. In
`packages/bus/tests/grant-executor.test.mjs`, the `add` stub waits for `release` when `hold-add`
is set. G23 ("a revoke during install") and G13 write `release`, finish, and `t.after` removes the
test dir. The stub polls every 50 ms, so it usually misses `release` and then loops forever on a
dir that is gone. Four runs of the file on Sage's slot left 7 stubs, every run 37/0.
Build: each hold loop in that file, `hold-add` and `hold-remove`, also stops when `$D` no longer
exists. The test file is the only change. Nothing under `src` changes.
Gate: Webby approves the commit. On Sage's gate the whole file passes three times in a row with no
stub left, checked by pgrep on the run's TMPDIR, and the bus suite is green. A mutant that drops the
dir check from `hold-add` leaves a stub behind.
## Machine grant row b follow-up: the undo can't prove the remote add has ended
Mos asked this in mos-1166. Gizmoduck answered in gizmoduck-0137 and gizmoduck-0139, and Duckworth
checked the answer in duckworth-0091. Line numbers are at 6d5545d44.
An abort during install SIGKILLs the local ssh process group (host-run.mjs:136). A timeout does the
same (host-run.mjs:131-134). sshd gives a non-pty command no SIGHUP when the client dies, so the
remote `add` can keep running. The undo runs `remove <user> <tag>` once (broker.mjs:1017). If the add
writes its line after that, the remove has already exited 0 and `hostLineLeft` stays unset (:1019).
Then hosts.status shows the host clean (:1396), reconcile skips a grant that already ended
(:1042), and nothing prompts a sweep. hosts.remove's host-line-left check (:1362) passes, and once
the record is gone a sweep refuses host-unknown (:1350), so no verb reaches the line. The line
authorizes a key nobody holds, under the installer's restrict prefix. No test covers this case. G24
seeds its failed grant with `hostLineLeft` already set.
Build:
- In `#runHostGrant`, mark install done right after `await install(...)` returns. In the catch, when
install started and never returned, record `hostLineLeft: tag` whatever the remove's exit was. The
rule keys on install not returning. It covers an abort, a timeout and a dropped connection, and
doesn't depend on `signal.aborted`. The message names `mosaic hosts sweep <host>`.
- An add that exits nonzero on the host also records the hint. That hint is false but harmless,
since a sweep that doesn't list the tag drops it (G24, "a left tag no longer on the host").
- Fix the comment at grant-executor.test.mjs:432, which says a killed session's add exits.
- Row a's enroll add: check it for the same race, then fix it or record in BUILD.md why it can't
happen.
- Owner Gizmoduck. Reviewer Duckworth.
Tests: one abort case and one timeout case. Each uses a held stub add that writes after the remove
and exits 0. Each asserts `hostLineLeft` on grant.failed and in hosts.status, that hosts.remove
refuses host-line-left before the sweep, that the sweep removes the line, and that hosts.remove then
succeeds. A mutant that drops the new catch branch fails a test.
Gate: Duckworth approves the manifest. On Sage's gate the bus suite and the whole touched test files
are green, and the mutant is killed.
@@ -1,803 +0,0 @@
# Q195 writing editor design
Gitea #1752, Vikunja #448, DECISIONS Q168, Q177, Q194, Q195 and Q196. Design for review, not build
authority. Measured against `origin/refactor` at `6c75887b0`. All repository line references below
use that commit unless a different revision is named. Work is confined to `gyro/editor-design`.
## Outcome and boundaries
D1. Give Melanie a familiar Word-like writing interface inside the Console. She writes, saves,
selects a word for synonyms, and moves between documents without losing her draft or chat. Her
corpus includes hundreds of .doc files, several .qxd books and recent Markdown. Obsidian is not the
interface model. Ship a useful writing slice before legacy import. This add-on does not gate the
October 27 Markdown-library MVP, which Q196 leaves unchanged.
D2. Q196 withdraws the earlier assumption that the current Markdown editor must be the solution.
Compare all three options below. WordCraft's canvas/WebGPU browser UI
(`apps/wordcraft-web/Cargo.toml:3,26`, `index.html:17`) has a different rendering and build system.
Read-only reference checkout: `/mnt/storage/src/artcraft/wordcraft`, commit
`e05b7fe86f3b85454000dffc321de638d7009817`. No code is copied by this design. Any later copy must
preserve its applicable MIT or Apache-2.0 license and notices.
D3. No direct agent writes. Proposals appear outside the document until Melanie accepts one, then
become an undoable draft edit. Saving remains a separate human action. Q176 and Case 2 C2-06 already
prohibit agent prose and constrain corrections. Q195 does not explicitly remove that rule. The
design below specifies the interface, but agent access to unsaved text and new replacement-prose
permissions remain gated on Jason's choices, not silently enabled.
All examples and tests use invented fixtures. No books content, host access, live stack changes,
role changes, queue changes or access to `~/.mosaic-dev` is part of this assignment.
## What exists
| Code | Measured finding and implication |
|---|---|
| F1 | Row 154 landed as `9353675d1` (#1648). `packages/webui/editor/model.mjs:16-18` imports ProseMirror and markdown-it. `view.mjs:162` mounts the DOM editor with history, formatting, lists and a link bar. `model.mjs:1-14` and the serializer retain original blocks unless edited. Front matter and unsupported structures remain source blocks. This is the implementation to extend. |
| F2 | The actual vendor path is `packages/webui/third_party/editor/`, relative to the WebUI package, not repository-root `third_party/editor/`. `PROVENANCE.json:1-13` records 170 files, 19 packages and no local changes. `NOTICE:1-10` names tagged source, hashes and license paths. `editor/build.mjs:16-24,34-56` aliases source and produces an unminified bundle with inline legal notices and hashes. `editor/BUILD.json:7-14` records 758,420 JS bytes and 4,462 CSS bytes. These are checked against bytes, not inferred from the README. |
| F3 | `packages/webui/src/public/bus.js:868-887,925-927` keeps a shared Markdown draft and falls back to Source when exact round-trip fails. Redrawing destroys the editor. `editor/view.mjs:183-205` creates a new history on `setText`. The README's “Visual editor” section (`packages/webui/README.md:563`) records this limit. A writer needs a stable editor mount while chat polls. |
| F4 | Row 148's save is `POST /api/project-file`, with exactly `{project,path,base,content}` (`bus.js:975-986`, `serve.mjs:414-447`). Authentication, exact Origin, Fetch Metadata, strict keys and a 1 MiB request bound apply. `packages/project/src/index.mjs:244-260` restricts it to a human and refuses a changed file base. `paths.mjs:12-15` allows only `spec/north-star.md` and direct `docs/*.md`. This route cannot save book paths today. Do not widen its regexp to admit the vault. |
| F5 | The Console already has chat projects, named threads, message paging, send and explicit resume (`packages/webui/src/chat.mjs:19-27`, `public/chat.js:9-14,66-70`). Chat has its own route and render lifecycle (`public/bus.js:1100-1104`), so Docs and Chat currently replace each other. `chat.js:68` renders bodies as escaped text. There is no document pin in these structures. |
| F6 | Sessions are durable thread identity plus replaceable runs. Row 121 landed as `2c16d6b93` (#1615). `packages/bus/src/broker.mjs:479-525` tracks pending work, holder and idle release. `:3429-3451` creates an owned thread, and `:3468-3474` requests launch only on explicit open. Reuse thread IDs, never run IDs, for pins. Existing tester isolation is in rows 177/182 and `chat.mjs:1-4`. |
| F7 | C2-11a, row 214, owns `editor/model.mjs`, bundle output and editor tests (`docs/plans/2026-10-20_case2-rows.md:235`). It measures and preserves wikilink forms. All proposed changes under `editor/` wait behind it. C2-10b owns `public/bus.js`, its stylesheet, `serve.mjs` and WebUI tests (`:780`). It supplies cited items, scope badges and sync status. Our shared-file rows wait behind it and reuse its renderer. Neither brief proves that its feature has landed. |
| F8 | Sage's input via mos-1179: row 220, C2-10a (#1721), makes the conversation reader hide creative sessions and refuse direct opens with `conversation-not-listed` (`case2-rows.md:517`). Row 198 (#1696) retires the 7331 board writer, currently referenced at `serve.mjs:12`. This design uses neither raw session files nor the board route. It does not depend on row 5 (waiting on Jason) or parked row 29. |
Verification: `node --test packages/webui/tests/editor-provenance.test.mjs
packages/webui/tests/editor.test.mjs` passed 10 tests with 1 explicit skip. The skip is the rebuild
because pinned esbuild 0.28.2 is absent. The source tree, output hashes, licenses, route serving and
exact round-trip tests passed. This is fixture evidence, not a live check.
## Options and recommendation under Q196
O1. Extend row 154 into a Word-like DOM interface. Reuse its safe source-built editor, add a
File/Home/Review ribbon, named heading/paragraph styles, a document navigation pane, familiar
shortcuts, status bar and synonyms. It preserves browser text behavior and the current CSP. The
measured JS/CSS sizes are F2, not an estimate. Its current schema has no footnote, comment or
tracked-change nodes (`editor/model.mjs:27-114`), no page layout engine and no DOCX writer.
Word-like controls do not create those features. This option needs a production export path before
it meets Q196's DesignCraft requirement.
O2. Put WordCraft's engine and canvas interface in the document pane. It offers Word-like commands
and rich file support rather than recreating all of them in ProseMirror. Louie's scratch evaluation
is the source for build/runtime and round-trip measurements below. Its own browser file
pickers/downloads and preferences are not a Mosaic save or permission boundary. An adapter must
disable direct uncontrolled I/O, connect owned git documents, expose selection/version/undo
operations, and put all agent access through Mosaic's broker. Its native MCP server is not
automatically a browser bridge. Q167 D3 bars the required CSP loosening today. An iframe or separate
origin is not a way around that ruling. O2 requires Jason's explicit scoped exception and an
independent security review before build rows.
O3. Keep a Word-like DOM writing interface, use WordCraft's headless formats/engine behind a narrow
server operation for production export. Recommend this bounded mix for the first release: O1
supplies editing and local synonyms, a pinned headless exporter supplies DOCX for DesignCraft. Do
not run two live document models or send every keystroke to a server. This avoids introducing a
canvas editor and a CSP exception while adding a concrete book handoff. The cost is a reviewed
format adapter and an explicit feature boundary. It does not promise full Word parity. If footnotes,
comments, tracked changes or precise pagination must be editable in the first release, choose O2
after its bridge and CSP gates instead of silently extending Markdown beyond what it can represent.
The first release includes prose, headings, emphasis, lists, links, native spelling, find, word
counts, undo, explicit save and synonyms in familiar controls. True page layout, headers/footers,
rich tables, footnotes, comments and tracked changes are later rich-document work, not buttons that
discard unsupported information. Existing documents with unsupported structures remain
source-preserved or read-only with a clear reason. Jason confirms that feature cut, not an
assumption that the existing vault defines her needs.
## WordCraft measurements used for O2 and O3
Louie's evaluation is pinned at `origin/louie/wordcraft-eval`, commit
`880ef19e017dad0194ecc9921ae55a0cf2e8fef2`,
`docs/plans/2026-10-21_q195-wordcraft-eval.md`. He built a scratch clone of WordCraft
`e05b7fe86f3b85454000dffc321de638d7009817` (0.9.0), with no source modifications.
These are his measured results, not estimates or a claim that this combined design ran
the application in the Console.
| Evidence | Measured result | Design implication |
|---|---|---|
| Release build twice | 392.786 s, then 172.324 s, under `nice -n 19`, four Cargo jobs | First-build cost is material. Exact timings are that scratch host, not a product startup benchmark. |
| WASM | 43,994,316 bytes, SHA-256 `90dec375924b47b40054eb4ecafb4235b6ed0bd63880b91ec138fdbb6f939e75` | The current shipped build is much larger than the packaging README's approximate figure. Use the measured artifact. |
| JS / HTML / icon | 164,941 / 1,604 / 18,378 bytes | Total 44,179,239 bytes, identical sorted hashes for all four artifacts across both builds. No compression transfer size was measured. |
| Review scope for web target | 15 local crates, 251,457 physical Rust source lines and 199 third-party packages | O2 imports a maintained application, not a small editor widget. All dependency licenses and pinned build inputs need review. |
| Browser API | Session and selection stay in WASM. No exported page API or postMessage bridge. Browser has no TCP control channel | The native MCP server cannot control the browser document. The O2 adapter is new work. |
| `.doc` → `.docx` fixture | Heading 1, italics and footnote reference/body preserved. Comment absent, inspect reports zero comments | Useful import candidate, with a real loss boundary. Legacy import must retain the original and disclose comment loss. |
| `.doc` → `.md` fixture | Heading and italics preserved, footnote reference/body and comment absent | Markdown is not a lossless intermediate for rich legacy books. |
| `.md` → `.docx` → `.md` fixture | Heading and italics preserved. Footnote marker/definition stay ordinary text and brackets are escaped | O3's adapter must detect unsupported constructs, not rely on conversion success as proof of semantics. |
| Thesaurus | 29 headwords, 122 synonym values | WordNet is needed under every option. Hunspell spelling dictionaries are a separate mechanism. |
| MCP | 16 native tools, stdio/headless or loopback desktop connection | Reuse operation ideas through Mosaic's scoped tools. Do not expose native execute/save or a loopback control port to agents. |
For the unmodified O2 browser app, Louie identifies `script-src 'wasm-unsafe-eval'` for
WebAssembly, `frame-src 'self' blob:` for the PDF preview, and `frame-ancestors 'self'`
on an embedded WordCraft response rather than the shell's existing `'none'`. A restricted
integration could disable PDF preview, but must demonstrate the resulting narrower policy.
The shell policy stays unchanged when only an editor response changes. Q167 D3 still
requires Jason's ruling on that editor policy. No worker/GPU-specific CSP directive is
needed for this build.
Pane fitting is a source-based inference: eframe 0.36.2 uses ResizeObserver on the canvas.
Louie did not prove a functioning Console embedding, keyboard escape, browser startup
latency or browser selection bridge. Those remain O2 acceptance work, not measured successes.
The native fixture conversions do prove format behavior on the synthetic fixture. They do
not prove preservation of Melanie's corpus or the complete Word feature set.
For O3, the headless format path is supported by the successful native fixture commands.
A restricted exporter service and its exact native dependency subtree, memory usage and
service latency have not been measured. W6 must measure them. O3 avoids the measured
browser WASM/app UI and a browser CSP exception, but is not claimed to be a zero-cost or
already-built backend. This is why the recommendation is limited to the tested prose,
heading/emphasis/list subset plus explicit loss checks, with richer editing as a separate
choice in Jason's checklist.
## Stored format and DesignCraft handoff
D20. For the recommended first slice, existing Markdown stays canonical in git, including front
matter. No forced migration. Produce DOCX as a derived, human-requested book handoff from a specific
commit. The first slice stores Markdown only in git and downloads the derived DOCX with an export
manifest. Optional storage of that output under a dedicated `exports/` directory in the writing
project requires its own accepted write-path policy brief. The manifest records source paths, source
commit/digests, converter revision, style map, output digest and conversion warnings. The Markdown
source is the sole editable copy. The DOCX is regenerated, never independently edited then merged
back. Existing Case 2 mapping does not automatically index exports or gain write permission for
them.
Markdown-only git is easiest to inspect but cannot retain all Word features. DOCX-only git retains a
richer document model but is binary to git and outside Case 2's Markdown reader, writer and
citations. Two editable masters drift. If git later holds both, DOCX is a derived output, not
another editable format to synchronize. A later rich-document mode may make DOCX canonical per
document, with a derived Markdown reading projection and stable identity mapping, but that needs
separate writer, index, citation and loss-preservation design. It does not change this week's Case 2
MVP.
D21. DesignCraft checkout `3ce3a24f08d03935bc8cf7cb23755aca8065558c` lists DOCX and MD at
`docs/file-format-parity.md:69,72`. Code qualifies that claim: `crates/textimport/src/lib.rs:94-126`
recognizes `.md` but falls through to plain text. Markdown headings, emphasis and YAML are not
automatically interpreted. `crates/textimport/src/docx.rs:493-548` reads named styles and footnotes.
Its regression `tracked_changes_import_as_accepted_including_moves` at `:706` shows that
insertions/move destinations become accepted content, with deletions removed, not an editable review
history. `crates/engine/src/cmd/place_text.rs:46-93` maps style names and resolves conflicts.
`crates/engine/src/cmd/file.rs:138` documents `file.place` for DOCX/MD and
`crates/mcp/src/tools.rs:98-110` exposes typed commands through the MCP server.
D22. `POST /api/editor/export` takes exactly `{project,path,base,format:"docx"}` under the existing
human write fences, reads the authorized saved commit and returns a bounded download containing DOCX
plus manifest. Dirty drafts must be saved first. No arbitrary server path or browser-selected
converter command is accepted. Export strips front matter into metadata, resolves source links as
text or explicit cross-reference labels and maps Normal, Title, Heading 1-3, Quote and list styles
by name. It refuses unsupported semantic content or offers an explicit loss report before export.
Jason's later layout agent fetches the reviewed Markdown commit into its own approved workspace,
produces the matching DOCX and manifest (or reads the separately authorized export commit), verifies
hashes, and uses DesignCraft MCP `execute` with `file.place`, sets an explicit style map and
`styleConflicts`, then reviews autoflow and warnings before saving a layout. That later agent
automation is not authorized by this design assignment. No editor agent gets DesignCraft credentials
or automatically sends Melanie's text to another service.
Acceptance uses invented fixtures: body, styled headings, emphasis, list, table, link and
footnote/track-change cases appropriate to the chosen format. Compare source text and style
identities after WordCraft export and DesignCraft placement, including Unicode and paragraph
boundaries. Unsupported footnotes/revisions in Markdown must refuse or warn, not vanish. For rich
DOCX input, explicitly choose a final accepted reading before production layout, retaining the
original review-bearing file. A direct `.md` place is a plain-text fallback only, not the production
path for styled Markdown.
D23. Legacy import is a separate assignment. It must supply stable document IDs, original hashes, a
read-only retained original, converted editable file, named styles, metadata, attachment mapping and
a loss/warning report with a human acceptance decision. It must also name the supported
format/features, source-to-output paragraph identifiers and asset paths so navigation, pins and
citations can be repaired explicitly. Never replace .doc or .qxd originals. WordCraft's `.doc`
parser is a candidate to test, not proof that every 20-year-old document survives. Neither project
reads .qxd today (DesignCraft's gap at `docs/file-format-parity.md:32`). QXD extraction needs its
own evaluated tool and license. The editor accepts only reviewed converted artifacts, not a bulk
import button.
## Writing and moving between documents
D4. Present a File/Open view with recent documents and a collapsible book/chapter navigation pane,
plus a heading outline. The Case 2 mapping supplies scope underneath it. Show book, folder and
document in the breadcrumb, without requiring Melanie to operate a vault UI. The host recon at
`/mnt/storage/src/jason-master-restart/projects/mosaic-mvp/MELANIE-HOST-RECON.md:23` describes
Markdown book folders, chapters, characters, summaries, locations, research and tracker notes, with
front matter keys `type`, `name`, `appears_in` and `relationships`. Only that structure is used
here. `.base` and `.canvas` stay untouched and are not offered as editable documents.
D5. Reuse C2-11b's library navigation and human `library.file` / `library.file.save` boundary, plus
C2-02's writer and C2-03b's push behavior. They are dependencies, not work hidden in a UI row. The
Case 2 design, `origin/gosalyn/case2-design:agents/gosalyn/work/case2/DESIGN.md` section 7.3,
already assigns these. A usable book-editing release waits for their reviewed write and sync
semantics. Until then the new writing surface can be tested on `docs/` fixtures, but is not reported
as usable for Melanie's books.
D6. Keep one working editor with a collapsible file tree, heading outline, recent documents and a
path/name filter. Opening a fixture such as `Lantern Book/Chapters/03 - Rain.md` uses the mapping's
document identity, not an absolute path. Back/forward and wikilink navigation use the same open
operation. Do not invent a second tree or a vault-wide search service.
D7. Each document keeps its text, base commit, selection, scroll and undo history in memory for this
signed-in tab. Chat polling and divider movement never remount it. Switching back restores it. Keep
at most ten clean inactive editor states. Before releasing a dirty state, require Save, Copy or
explicit Discard. Never evict a dirty document silently. No unsaved text goes in URLs, localStorage
or logs. A dirty-document badge and an unsaved count remain visible. Closing/reloading a dirty tab
warns. Explicit sign-out clears text and access context, with an unsaved warning before it proceeds.
Expired credentials revoke agent shares and block writes/server reads, while preserving the tab's
local draft for Copy or reauthentication. The UI distinguishes expiry from an explicit sign-out.
D8. Use Word-like File/Home/Review controls and a familiar Normal/Heading 1-3 style picker. Provide
a clean page-colored writing surface, readable line width (about 70 characters), text-size controls,
spacious line height, native spellcheck, keyboard formatting, find within the open file, word count
and a focus view. Keep the toolbar compact and keyboard accessible. Hide front matter behind a
collapsed “Document details” source panel, preserving its exact bytes. Unsupported blocks remain
marked source blocks. Do not reinterpret YAML or normalize wikilinks. All-day use means stable
selection/history and clear save status, not Word-style pagination.
D9. Save is explicit (button and Ctrl/Cmd+S), with “Unsaved”, “Saving”, a returned commit, or a
refusal. No autosave commits initially. Newer content refuses `stale-base` and preserves the draft.
Show current saved text beside the draft for manual reconciliation, never an automatic overwrite.
Unknown save/push results are read back before retry. A local library commit awaiting push is
labelled as such, using C2-03b's result, never called synced. No create, rename, delete, promote or
crossover work enters this add-on's first slice.
## Thesaurus
D10. Use Princeton WordNet 3.0, indexed locally by synset (meaning) and part of speech. This is
substantially broader than WordCraft's small static `T` table
(`crates/engine/src/cmd/review.rs:914`). WordNet is a lexical database, so it will miss some
inflected or literary terms and does not rank words for a sentence. Group results by meaning, show
the gloss, omit the selected word and duplicates, and say “No local synonyms” on a miss. Do not
promise every alternative is interchangeable.
Princeton's [statistics](https://wordnet.princeton.edu/documentation/wnstats7wn) report 117,659
synsets and 206,941 word-sense pairs. The 155,287 strings total counts words again across parts of
speech. The distinct total is 147,278. Its
[license](https://wordnet.princeton.edu/license-and-commercial-use) permits copying, modification
and distribution for any purpose, retaining its copyright, terms and disclaimer on copies and
modifications. This fits this repository's private `UNLICENSED` package and source-review rules. Do
not label WordNet MIT or Apache. Preserve the actual WordNet license.
Measured download on this design session: Princeton's archive host timed out. The NLTK project's
[WordNet data
mirror](https://github.com/nltk/nltk_data/blob/96f9b3252457a2b97e52aec64c3dfceeb5c312d5/packages/corpora/wordnet.zip)
at commit `96f9b3252457a2b97e52aec64c3dfceeb5c312d5` supplied the archive in memory. The archived
LICENSE is WordNet 3.0's Princeton license. No archive entered this repository.
| Measurement | Exact value |
|---|---|
| Archive | 10,775,600 bytes |
| SHA-256 | `cbda5ea6eef7f36a97a43d4a75f85e07fccbb4f23657d27b4ccbc93e2646ab59` |
| All uncompressed entries | 36,353,991 bytes |
| `data.*`, `index.*` and exception files | 35,435,978 bytes |
| Measured synsets | noun 82,115, verb 13,767, adjective 18,156, adverb 3,621 |
D11. At build time, import the original text, license and a provenance manifest under
`packages/webui/third_party/thesaurus/`. A small reviewed converter bakes a static index into a
self-hosted Web Worker asset, shipped with the Console build. Start that worker when the writing
surface loads. No runtime dependency install, upstream lookup, CDN, on-demand dictionary fetch or
model call occurs when she selects a word. Data is reviewable source in the release, like row 154's
editor source. Browser assets still come from the installed Console itself. CSP stays byte-for-byte
unchanged. Worker startup and index decoding stay off the typing thread.
The build row records exact generated bytes and worker memory/load measurements rather than guessing
compression size here. Gate limits: at most 50 MiB shipped dictionary assets, at most 128 MiB added
worker heap on the fixture browser, warm lookup under 100 ms for 95 of 100 fixture lookups. A failed
limit requires a reviewed representation change, not dropping words silently. Worker startup never
blocks typing. Only the selected word goes to the worker, and it stays in the browser.
D12. Right-click an explicitly selected word to open an accessible Synonyms menu. Also support
Shift+F10/Menu key and a toolbar action. Freeze its selection bookmark and document revision when
opening. Preserve selection while the menu has focus. For a whole-word selection, normalize lookup
case and use WordNet exception lists for inflections, while displaying the original word. Do not
silently inflect a replacement. Clicking a result replaces exactly that selection in one undoable
transaction and retains surrounding marks. If the document or selection changed while loading, close
the menu and ask her to select again. Empty/multiword selection, source blocks and read-only mode
offer no replacement. Escape closes and returns focus. Keep ordinary browser copy/paste reachable.
D13. “Ask the agent for options in this sentence” is an optional second menu action, never a
fallback request sent automatically. It previews the selected word and one sentence, then sends only
that context to the chosen thread after her action. Default off pending the policy/access choices
below. With Q176 unchanged, the answer must be allowed cited advice or bounded corrections under
C2-06, never an unrestricted rewritten sentence.
Reviewer checks: fetch the exact mirror commit, hash the archive, compare the archived LICENSE with
Princeton's published text, recompute every imported file hash and the four synset counts, and run
the converter twice from separate directories for identical output. Include license text with both
original and derived data. Check generated records against source offsets, malformed input refusals,
missing license/hash failures, no executable data, no network calls, CSP equality and absence of
document/word logging. The mirror's pin and measured hash establish repeatability, not a claim that
its bytes were compared with the unavailable Princeton archive.
## Agent API and MCP access
D14. Reuse the existing broker and harness typed-tool channel. Mosaic already implements
`initialize`, `tools/list` and `tools/call` in `packages/harness/src/mcp-server.mjs:23-43`, with
session-scoped tool dispatch (`tools.mjs:1-17`). WordCraft's `get_text`, `inspect_document` and
`select_text` (`crates/mcp/src/tools.rs:109-122`) illustrate small, typed operations. Its `execute`,
`type_text` and `save_document` are too broad here. Its `server.rs:130-163` exposes document
resources, but Mosaic needs no second MCP server.
D15. The browser publishes an immutable, short-lived context snapshot only when Melanie chooses
“Share selection” or “Share document” in the visible thread. A pin does not grant access. Snapshot
identity includes owner, business, library/project, mapped path, tab ID, thread ID, editor revision,
base commit, scope, text digest and expiry. An opaque ID is a reference, not authority. The broker
binds it to the authenticated thread holder and user. No agent chooses another user's tab, changes
the active file, reads a session file or uses `library.file` to evade M4. Sign-out, permission loss
or explicit revoke removes access. A browser heartbeat lease expires after 30 seconds without
renewal, including a lost connection. Absolute expiry is 15 minutes. Navigation suspends access
until explicit sharing for the new file. Multiple tabs have separate IDs and never guess which is
“open”.
Proposed new interfaces, all gated design contracts:
| HTTP / broker operation | Typed MCP tool | Result and authority |
|---|---|---|
| `POST /api/editor/contexts` → `editor.context.publish` | none (human only) | Publish selection or document snapshot. Return context ID, revision, digest and expiry. Max 256 KiB snapshot UTF-8, within a 1 MiB HTTP envelope. Reject overflow without truncating silently. |
| `DELETE /api/editor/contexts/:id` → `editor.context.revoke` | none (human only) | Revoke one owned share. Browser disables its card immediately. |
| `GET /api/editor/contexts/:id` → `editor.context.read` | `editor_read_document({context,revision,cursor?})` | Only explicitly shared document text. Page whole blocks below `REPLY_CAP`, with revision/digest on every page. Selection-only sharing refuses whole-document reads. |
| Same read boundary → `editor.selection.read` | `editor_read_selection({context,revision})` | Exact selected text, optional shared sentence and offsets, no implicit surrounding document. |
| `POST /api/editor/suggestions` → `editor.suggestion.propose` | `editor_propose_edit({context,revision,expected,replacement,reason,requestId})` | Store a proposal only. Bind to shared selection offsets and exact expected text, not a browser-supplied filesystem path. No file save. |
| `GET /api/editor/contexts/:id/suggestions` → `editor.suggestion.list` | none required | Human reads proposals for this context. |
| `POST /api/editor/suggestions/:id/decision` → `editor.suggestion.decide` | none (human only) | Accept or reject the card. Acceptance authorizes one local transaction, never a git write. |
D16. All arguments use strict schemas with unknown keys refused. Reads stay within the existing
session capability and approved universe/scope. HTTP mutations use the signed-in human, exact Origin
and same-origin Fetch Metadata fences, never a browser-selected actor. No MCP accept, save or
general execute tool ships. Publishing unsaved text is a new broker boundary and needs a reviewed
capability/policy decision. The first agent slice can remain read-only on explicitly shared saved
material through existing allowed lookups.
D17. Use normalized LF Markdown UTF-16 offsets at valid code-point boundaries, not ProseMirror
positions or rendered DOM offsets. The browser builds a source mapping for the selected editable
text and verifies the exact substring. Refuse selections crossing raw blocks, front matter, nodes or
unmappable syntax. The context revision increases on every document edit. A changed digest/revision,
revoked share or changed text makes a proposal stale. Do not auto-rebase it. Acceptance is one
ProseMirror transaction, undoable, and a later Save uses the original file base and the existing
human writer. Applying an accepted card twice is refused. A crash leaves a proposal unapplied, never
retries it.
D18. Bound proposals to 20 per context, each replacement/expected at most 4 KiB and reason at most
500 characters, with 15-minute expiry and idempotent `requestId` per thread/context. Deduplicate
transport retries without resending to the agent. Log IDs, hashes and outcomes, not bodies. Proposal
content remains protected context data and is deleted on expiry/revoke. Audit records retain
metadata only. Display all generated text as text, with authoring thread, old/new text, reason and
Accept/Reject. Nothing is interpreted as HTML or commands.
D19. Q176 remains enforced on this new channel too. With no new ruling, only the already permitted
C2-06 cited corrections/advice may appear, with its exact citation and edit-distance limits, and no
agent replacement tool is exposed. Unsaved text has no git citation. Sharing it does not turn a
digest into a valid C2-06 source. Supporting cited unsaved drafts needs an explicit decision and
review of M3-M5 and the guard, not a private suggestion channel around the existing guard. Reject
arbitrary prose even when a human would later approve it until that decision is made. Direct edits
remain outside this recommendation.
## Split pane, chat and pins
D24. This section folds Fenton's pane, chat and pin design from `origin/fenton/editor-design` at
`7caf8008b5887c15f74303a50db2e54a9778375f`, `docs/plans/2026-10-21_q195-pane-and-pin.md`. His
separate work supplies the layout, durable thread pin and send-time context model. The following
reconciles it with Q196, Case 2 paths and this brief's explicit sharing rules. It is design input,
not his review approval of this combined document.
D25. On writing routes put the editor container, a divider and sibling `aside#chat-pane` under
`main`. Navigation replaces the document container only. Embedded chat takes an explicit thread ID
and container, never owns `location.hash`, and reuses the same renderer as full Chat. Keep the
existing 10-second polling, paused for hidden tabs and sign-out. No new WebSocket service. Chat
polling updates only its own DOM. O2, if selected later, would use the same outer pane with an
engine adapter rather than DOM selection access.
D26. Start at 62% document, 38% chat. The divider uses pointer capture and the WAI-ARIA separator
pattern, names both panes, reports current/min/max width, and supports arrows (2%), Shift+arrows
(10%), Home/End and Enter to collapse/restore. Double-click resets. For the recommended ribbon UI,
clamp document/chat widths to 44rem/18rem and clamp again on resize. Below 76rem show Document/Chat
tabs, preserve both drafts and show reply counts without switching focus. Store width/collapse only
in `mosaic-console-split`, with invalid values reset. No document text in browser storage. These are
design sizes, not benchmark results. The compact O1 toolbar alternative uses 28rem/18rem and tabs
below 60rem. Existing CSP stays unchanged for the recommended O3 headless-export mix.
D27. Unpinned chat “Follows you” as documents change. A pin binds an owned bus thread UUID to a
document, never a harness run or session-file path. On A pinned to T1 and B pinned to T2, opening B
shows T2, keeping each thread's draft/read cursor. A document without a pin restores the follow-you
thread. Unpinning leaves the displayed thread following the user. Switching thread on a pinned
document offers “Pin this thread here instead?” and never changes the pin silently. A thread may
serve several documents, one pin per document/owner. Document navigation never launches a run. Reads
do not call `thread.open` or send messages.
D28. Recommend durable pins on the bus, following Fenton's S6. Add
`thread_pins(business,owner,project,path,thread,at)`, unique per business/owner/project/path, with
`POST /api/chat/pins` → `thread.pin`, `DELETE /api/chat/pins` → `thread.unpin`, and `GET
/api/chat/pins` → `thread.pins`, under the existing chat identity/write fences. Testers retain their
own isolated pins, never the human's. Both document and thread must belong to the authenticated
business and owner. For library documents validate the mapped path/scope through the library reader,
not row 148's narrow `documentPath`. Do not widen that existing function. Keep the thread's chat
project separate from the writing repository identity and validate their declared association. Poll
pin unread metadata separately from message bodies so background threads can get a badge without
rendering or waking them. Row 121's current API has no such metadata contract, so W3a must implement
and test it rather than assume it exists.
No automatic rename following. A missing path shows a stale pin and explicit Re-pin/Unpin controls.
A missing/forbidden thread offers Unpin only and exposes no former content. Two tabs update pins
with a revision precondition, so an old tab cannot silently replace a new pin. The follow-you thread
ID may live under an owner/business-scoped browser key and is cleared on sign-out. A pin confers no
document permission or context sharing.
D29. First agent context is saved material at send time. A visible chip, explicitly enabled by
Melanie and removable for each send, carries `{project,path,commit,lines:[from,to]}` and no text. It
appears only after her share action. Check commit is reachable in the allowed served history, path
is mapped, caller/thread can read that scope, and both lines exist in that exact commit. When the
draft is dirty or mapping is uncertain, omit selection lines and label “Saved version only. Save to
cite this selection.” Do not pretend draft offsets are saved line numbers. The agent uses existing
approved library lookup tools and C2-06 citations, not session files or an expanded generic `read`
root.
Store structured context in `message_context` keyed to the message, kept apart from body and
inserted atomically. `thread.send` accepts this optional strict field, and message reads return it
separately. The broker validates the source rather than trusting the browser's chip. This first
saved-context route does not enable D15's unsaved snapshots. Both tables and verb changes need
Jason's explicit schema/API approval. They grant no prose authority.
D30. Fenton found C2-10b's file list names `bus.js`, while actual thread messages render in
`public/chat.js:68`. Sage must amend that row's ownership/acceptance to include `chat.js` or a
shared renderer before W3 starts. Otherwise cited JSON would reach the pane as plain text. C2-09a's
brief also cites older broker positions. Re-measure against `broker.mjs:3429-3438` when building. No
edits to those briefs or queue are made here. M7 and M8 remain intact, and neither row 5 nor row 29
is a dependency.
D31. Fenton's Q196 update adds a host contract that works with each option: `mount`, `destroy`,
`dirty`, `focus`, `selection` and `resized`. For the recommended DOM surface these adapt the
editor's real state, not a second document model. F6/Shift+F6 cycle focus among editor, divider and
chat. Scope editing shortcuts to the focused pane, so chat paste and undo never mutate the document.
Before releasing any editor state, check `dirty`; a missing/failed response counts as dirty.
Preserve the state or offer the explicit Save/Copy/Discard controls in D7. A hash navigation alone
is not a browser `beforeunload` event and must run this check itself.
For O2, Fenton recommends an iframe so WordCraft's page-wide canvas and document/window listeners do
not capture chat input. A new browser bridge must check `event.origin`, `event.source`, message
schema, per-instance generation and request ID. It needs document load/export, dirty, selection,
focus-out, resize and a safe transaction operation for the thesaurus, not just a notification hook.
A failed dirty response after one second blocks unmounting. During divider drag capture the pointer,
prevent iframe interception, resize at most once per animation frame and send the final `resized`
notification. Test F6 escape, chat paste isolation, narrow ribbon behavior and stale messages after
document changes. A same-origin iframe is UI isolation, not a security boundary. Native file I/O and
network features still need the adapter restrictions in O2.
An iframe-route-only `wasm-unsafe-eval` exception would be narrower than changing the Console shell
policy, but it still changes the editor's CSP and requires Q167 D3's ruling. The recommended
headless-export O3 needs neither an iframe nor a browser WASM exception. No alternative-origin
hosting or broad `unsafe-eval` is authorized as a workaround. Fenton's conditional P5 brief at the
pinned source describes the iframe bridge. If O2 is chosen, revise W2/W6 into source-import/build
and browser-bridge rows before queue entry, with their exact owned source paths and the measured CSP
delta.
O2's DOCX selection cannot use Markdown line citations. A versioned document locator and C2
guard/renderer support would need a separate reviewed format-policy brief. A DOCX path is not made
legal by leaving `lines` out. Until that change is approved, rich-document agent context is
disabled. Do not use paragraph indexes as if they were existing git lines.
## Build order and review gates
Order: W1 → W2 → W3 → W6 → W4 → W5. W3a can prepare after its Case 2 dependencies and must finish
before W3. W2 is a useful writing increment. W6 completes the recommended release's styled
production handoff. W4/W5 remain separately gated.
These are proposed briefs, not queue entries. Jason confirms the checklist, Mos routes the decision,
then Sage accepts and schedules each brief and creates its Gitea build issue. Every code row gets an
independent Opus 5.5 reviewer who did not author that row. Q177 allows building on a reviewed parent
candidate, with landings in order. It does not allow overlapping file owners or bypassed reviews.
Sage grants suite slots and the final gate. Rows owning `serve.mjs` also serialize behind row 198's
current ownership. That is a file handoff, not a dependency on the retired board.
Common gate G1: run each changed/touched test file independently, the affected package suites and
every `scripts/test-*.sh` on Sage's slot. Search tests for changed path/hash pins. For editor
changes use `MOSAIC_REQUIRE_EDITOR_BUILD=1` with pinned esbuild 0.28.2 and reproducible output
hashes. Browser checks use scratch roots and invented vaults only. No row activates a stack, changes
roles or pushes to protected branches by implication.
## W1 local thesaurus data and converter
### Problem
WordCraft's small built-in list cannot provide general writing coverage (D10). No Console thesaurus
dataset exists in the measured editor inputs.
### Owner and reviewer
- Owner: Researcher in a T3 Codex gpt-6-luna seat (lower-level data import and converter).
- Reviewer: Fenton, Opus 5.5, independent of this implementation.
- After: Jason's data-source confirmation. May start independently of C2 shared-file work.
### Files owned
`packages/webui/third_party/thesaurus/{LICENSE,NOTICE,PROVENANCE.json,wordnet/}`,
`packages/webui/editor-data/{import-wordnet.mjs,build-thesaurus.mjs,BUILD.json}`,
`packages/webui/src/public/thesaurus-data/`, `packages/webui/tests/thesaurus-data.test.mjs`,
`packages/webui/README.md` (thesaurus section).
### What ships
Pinned WordNet originals and deterministic derived local data (D10-D11). Tests reproduce counts and
hashes, license preservation, invalid-input refusal and stable sorted output. No change inside
`editor/` or existing editor tests. Record actual output size.
### Out of scope
Menu, worker wiring, agent requests, editor source and Case 2 library writes.
### Gate
Fenton verifies source/license and two independent builds. Data tests pass and output stays within
D11's size budget, then G1. Sage accepts the manifest.
## W2 writing surface and local synonyms, first usable slice
### Problem
F3's redraw loses undo history and no selected-word menu exists. Books also need Case 2's library
read/write path (F4, D5).
### Owner and reviewer
- Owner: Gyro, Codex gpt-6.1-sol (editor lifecycle and selection handling).
- Reviewer: Fenton, Opus 5.5, independent of the code.
- After: W1, C2-11a row 214, C2-10b, and C2-11b with C2-02/C2-03b for usable book saves.
### Files owned
`packages/webui/editor/{view.mjs,entry.mjs,editor.css,thesaurus.mjs}`,
`packages/webui/editor/BUILD.json`,
`packages/webui/src/public/{editor.js,editor.css,bus.js,bus.css,thesaurus-worker.js}`,
`packages/webui/tests/{editor.test.mjs,editor-browser.test.mjs,docs-browser.test.mjs,writing-browser.test.mjs,thesaurus-browser.test.mjs,editor-provenance.test.mjs}`,
`packages/webui/README.md` (writing section). `model.mjs` remains C2-11a's result.
### What ships
D4-D12, D31 and O1's familiar controls: stable per-document state, explicit save, writing controls,
navigation through the existing library tree, preserved front matter and local accessible synonyms.
Wire only reviewed self-hosted assets. Tests cover selection/focus, Unicode, stale lookup,
replacement undo, read-only, exact saved-selection source mapping, unsupported blocks, no external
requests and unchanged CSP. A fixture session edits two nested chapters with front matter/wikilinks,
saves, navigates back and checks bytes, selection and undo. Test `stale-base`, unknown result,
unpushed feedback, credential expiry preserving local text and explicit sign-out clearing it after
the unsaved warning. Measure D11's load/heap/lookup budgets and a 100,000-word fixture without lost
input during chat-style refresh events. Passing responsiveness means no typing task above 100 ms
after load in 95 of 100 measured edits, with the browser/host recorded.
### Out of scope
Split pane, pins, agent permissions, library writer/sync implementation and Word layout.
### Gate
Fenton repeats the fixture writing flow and reviews accessibility and byte preservation. `node
--test packages/webui/tests/` with the required build passes, then G1. Sage accepts.
## W3a durable pins and saved-message context
### Problem
Pins and structured message context do not exist (F5-F6). Browser-only pins would differ across
machines. D28-D29 require new durable records and verified source references.
### Owner and reviewer
- Owner: Gyro, Codex gpt-6.1-sol (schema, broker and channel changes).
- Reviewer: Fenton, Opus 5.5, independent of the implementation.
- After: C2-09a, C2-10b ownership correction, C2-05b, and Jason's schema/API decision.
### Files owned
`packages/bus/{schema.sql,src/store.mjs,src/broker.mjs,src/editor-pins.mjs}`,
`packages/bus/tests/{schema.test.mjs,editor-pins.test.mjs}`,
`packages/plugins/channel/webui/index.mjs`, `packages/plugins/tests/` (pin/context tests),
`packages/webui/src/{chat.mjs,chat-http.mjs,serve.mjs,cli.mjs}`,
`packages/webui/tests/{chat.test.mjs,editor-context.test.mjs}`, `packages/webui/README.md`,
`packages/bus/README.md`. The next migration identifier is allocated by Sage's schema window before
build.
### What ships
D28-D29, an idempotent versioned migration in the repository's existing migration mechanism,
owned-pin revision checks, background unread metadata and atomic saved-message context. Tests refuse
another user's/thread's/business's context, wrong scope, unreachable commit, missing file and
out-of-bounds lines. Failed context insertion leaves no message. Pin tests cover tester separation,
stale paths and concurrent repin refusal. No document text stored in the new context table.
Migration/restore-count and bus tool allowlist tests remain green.
### Out of scope
UI, raw session access, unsaved context, new role authority and replacement prose.
### Gate
Fenton reviews schema/ownership and failure cases. Bus, plugins and WebUI suites pass plus G1. Sage
accepts within the allocated schema window. No live migration is part of this row.
## W3 split pane and pinned conversations
### Problem
F5's page-level routing prevents a persistent conversation beside navigation. No pin exists. D24-D30
supply the behavior to implement.
### Owner and reviewer
- Owner: Dewey in a T3 Haiku 5.5 high seat (mid-level pane and state wiring).
- Reviewer: Fenton, Opus 5.5, independent of the implementation.
- After: W2, W3a, C2-10b, C2-09a and row 220 C2-10a. Shared files wait behind those owners.
### Files owned
`packages/webui/src/public/{index.html,bus.js,bus.css,chat.js,chat.css,writing-pane.js}`,
`packages/webui/src/{serve.mjs,chat.mjs,chat-http.mjs}`,
`packages/webui/tests/{chat.test.mjs,chat-browser.test.mjs,writing-pane.test.mjs,writing-browser.test.mjs}`,
`packages/webui/README.md` (pane section). Persistent pin storage is W3a, not a hidden schema change
here.
### What ships
D24-D31: a resizable accessible split pane that reuses the existing owned chat thread and C2-10b
cited-item rendering, retains editor selection/history during polling and follows the pin rules in
D27-D29. Tests cover pin/unpin, two files, two tabs, removed/inaccessible thread, keyboard divider,
narrow viewport, reconnect/sign-out and navigation during delayed replies. No implicit `thread.open`
on read or navigation. Existing chat tests remain green. The saved context chip uses W2's exact
source mapping, and dirty drafts omit selection lines.
### Out of scope
7331 board route, row 5, row 29, raw sessions, fresh agent permissions and auto-launched runs.
### Gate
Fenton verifies the pane/pin scenarios against the folded design. WebUI suite and G1 pass. Sage
accepts the manifest after W3a's migration and API review.
## W6 DOCX production export and DesignCraft fixture handoff
### Problem
DesignCraft's `.md` import is plain text (D21). A Word-like writing surface still needs a verified
styled book-production handoff, without creating two editable masters.
### Owner and reviewer
- Owner: Gyro, Codex gpt-6.1-sol (isolated headless format adapter and semantic checks).
- Reviewer: Fenton, Opus 5.5, independent of the implementation.
- After: W3, Louie's evaluated engine revision, and Jason's O3/storage choice.
This serializes shared `serve.mjs` and `writing-pane.js` ownership.
### Files owned
`packages/writing-export/` (new, source, tests, pinned source manifest and build records),
`packages/webui/src/{editor-export.mjs,serve.mjs,cli.mjs}`,
`packages/webui/src/public/writing-pane.js`, `packages/webui/tests/writing-export.test.mjs`,
`packages/webui/README.md`. No change to WordCraft/DesignCraft checkouts. Any copied source retains
full applicable license notices. Export-commit authorization must be covered by a separate accepted
writing-project path/policy brief before a repository write is enabled.
### What ships
D20-D23's bounded Markdown-to-DOCX export from a pinned source commit, style map, warning report and
manifest, plus a reproducible source build of the needed WordCraft headless component. Review the
pinned Cargo.lock and dependency licenses, preserve required notices and bundle any required fonts
locally. Hard starting caps: 1 MiB Markdown input, 16 MiB DOCX output, 30-second conversion deadline
and one conversion per user at a time. Record actual fixture results and revise these limits only in
the accepted brief when measurements justify it. Refuse filesystem/network escape, external
linked-resource fetches, scripts/macros, malformed archives, decompression bombs and unsupported
semantic loss. Run the conversion without network or credential access. Fixture tests place the
result through DesignCraft's headless MCP path and compare body, styles, Unicode, paragraphs and
warnings. Conversion is an explicit action, not every Save. The initial UI can download the export
until the reviewed git-output path is authorized.
### Out of scope
Legacy .doc/.qxd import, new rich-document editing, live DesignCraft control and layout work on
Melanie's actual content. No guessed “full fidelity” claim.
### Gate
Fenton independently runs the export/place fixture using the pinned two source revisions and
inspects the loss report. New export tests and affected WebUI suite pass plus G1. Sage accepts only
if the target chapter's tested supported features place without loss.
## W4 scoped context API and typed reads
### Problem
The broker knows saved library material, not a tab's open document or selection. Exposing unsaved
drafts without explicit consent would cross D15-D16's new boundary.
### Owner and reviewer
- Owner: Gyro, Codex gpt-6.1-sol (broker identity and capability integration).
- Reviewer: Fenton, Opus 5.5, independent of the implementation.
- After: W6, C2-05b, C2-06, row 220, and Jason's explicit context-access decision.
### Files owned
`packages/webui/src/{serve.mjs,cli.mjs,editor-http.mjs}`,
`packages/webui/src/public/writing-pane.js`, `packages/bus/src/{broker.mjs,editor-context.mjs}`,
`packages/harness/src/tools.mjs`, `packages/{webui,bus,harness}/tests/` (editor-context test files
only), `packages/webui/README.md`, `packages/harness/README.md`. Any capability/role schema change
needs a separately accepted policy brief, not this allowlist.
### What ships
D14-D16's publish/revoke/read operations with strict schemas, expiry, bounded paging and explicit
sharing UI. Pi and Claude use the same broker checks. Tests refuse cross-user, thread, business,
universe, tab, guessed context, stale revision, revoked shares, expired heartbeat and absolute
expiry, whole-document read on selection-only access and attempts to use raw session endpoints.
Confirm raw-session `conversation-not-listed` and human-only `library.file` still refuse.
### Out of scope
Replacement proposals, save authority, new roles and bypass of M3-M5.
### Gate
Fenton approves boundary tests and confirms no tools are exposed without the approved capability.
WebUI, bus and harness suites pass with G1. Sage accepts.
## W5 guarded proposals and optional sentence options
### Problem
Q195's requested editing API needs a human-controlled proposal flow, but Q176 currently prohibits
unrestricted prose. An unsaved draft is not a valid existing git citation (D19).
### Owner and reviewer
- Owner: Gyro, Codex gpt-6.1-sol (revision checks and undoable proposal application).
- Reviewer: Fenton, Opus 5.5, independent of the implementation.
- After: W4 and an explicit Jason ruling on proposal kinds and unsaved-draft citations.
With no ruling this row does not enter the queue.
### Files owned
`packages/bus/src/{broker.mjs,editor-context.mjs}`, `packages/harness/src/tools.mjs`,
`packages/webui/src/editor-http.mjs`, `packages/webui/src/public/writing-pane.js`,
`packages/webui/editor/{view.mjs,thesaurus.mjs}`, `packages/webui/editor/BUILD.json`,
`packages/webui/src/public/{editor.js,editor.css}`, `packages/{webui,bus,harness}/tests/`
(editor-suggestion test files only), `packages/webui/README.md`. Any
`packages/library/src/guard.mjs` or role-policy change is excluded until its own reviewed policy
brief names the approved change and tests.
### What ships
D13 and D17-D19, restricted to the confirmed policy. Tests cover old/new text rendering,
accept/reject, undo, stale and expired context, changed base, no autosave, retry deduplication,
invalid UTF-16 boundary, hostile markup and guard failures on both RESULT and tool paths. Negative
tests prove an agent cannot accept, apply or save, and no proposal widens C2 scope.
### Out of scope
Direct agent edits, prose permission by inference, arbitrary execute and automatic sending.
### Gate
Fenton verifies that the recorded ruling matches the allowed proposal shapes and source citations.
WebUI, bus, harness and library guard regression suites pass with required editor rebuild and G1.
Sage accepts. No deploy or activation authority follows.
## Design verification receipt
Checked 2026-10-21T16:22:36Z (from `date -u`). Both companion branches were fetched and their
report commits pinned above. Seven briefs have every BRIEF-TEMPLATE field, unique anchors
and an independent implementation reviewer. The checklist has 12 lines. Only this design
and append-only BUILD-LOG/SESSIONS records change. No product or queue files change.
Fresh editor/provenance checks: 10 passed, zero failed, one rebuild skip because pinned
esbuild 0.28.2 is absent. This is not a claim that O3's exporter, new UI, live Console or
DesignCraft handoff has shipped or passed acceptance. Those tests belong to the build rows.
The push queue guard ran as `MOSAIC_GIT_IDENTITY=gyro` for `gyro/editor-design`, purpose
`push`, timeout/interval zero. It could not resolve the per-seat credential and recorded
`CANNOT_ASSERT credential-unresolvable` with its documented push `degraded-pass` (exit 0),
audit at `/mnt/storage/scratch/gyro-q195-ci-queue-audit.jsonl`. No identity fallback or guard
bypass was used. CI status was not asserted. Fenton reviews the combined draft through Mos.
## Jason's checklist
- Q1. Choose O3: Word-like DOM editor plus headless WordCraft DOCX export. Recommend yes for the first release.
- Q2. Are footnotes, comments, tracked changes or page layout required in that first release? Recommend defer them, or choose O2 for a richer editor after its bridge is proved.
- Q3. Allow O2's scoped WebAssembly/CSP change if you choose it? Recommend no blanket exception and a separate security gate.
- Q4. Keep Markdown as the first editable git source, with generated DOCX for DesignCraft. Recommend yes, never two editable masters.
- Q5. Ship writing controls, safe chapter saves and local WordNet synonyms first. Recommend yes, behind Case 2's shared-file rows.
- Q6. Store pins and saved-source message context on the bus through the reviewed schema/API change. Recommend yes.
- Q7. Pin by owner and document path, with explicit repair after a move. Recommend yes.
- Q8. Share saved context only when Melanie enables the visible chip for that send. Recommend yes.
- Q9. Keep saves explicit and unsaved drafts in the current tab initially. Recommend yes.
- Q10. Permit agents to read unsaved drafts or propose new prose? Recommend no initially, retaining Q176 and cited corrections.
- Q11. If proposals are enabled later, require Accept/Reject and a separate Save. Recommend yes.
- Q12. If O2 stores DOCX, approve a separate rich-document citation and library-policy design? Recommend yes before agent context.
-18
View File
@@ -315,24 +315,6 @@ at every gate. Started 2026-09-12 during the control board MVP.
`mosaic`, and F10 uses equality. Darkwing has a follow-up on
`darkwing/row195-n1` 1e3c4767c, not yet run; it gets its own row now
that 195 has landed (b65014647), Duckworth reviews. (2026-10-21)
- **Morgana's row 213 mutation set: the B3 pattern no longer matches `bundle.mjs`.**
(Webby N3 on row 221 round 1, REVIEW-r1 a0a00630e.) Row 221's
candidate changes `packages/harness/src/bundle.mjs`, and the B3
anchor at Morgana's 213 `mutants.py:48` stops matching on that
base. This matters only if someone reruns that set. Fix the anchor
in that tooling before any rerun, and check that a stale anchor
refuses instead of skipping the mutant (sage-1941). (2026-10-21)
- **Grant executor test X5 starts a `sleep 30` that can outlive its test.**
(Webby N1 on row 248 r1, webby-0080; deferred by Duckworth in the row
249 review, REVIEW-r1 28174fe08, #1751 comment 30070.) The test at
`packages/bus/tests/grant-executor.test.mjs:989` (:934 before row
249) runs `sleep 30` on the sshd side, where an abort doesn't reach it. Fix it with a stub
that exits once its test dir is gone, as row 248 did for the hold
stubs, or with a shorter sleep. This binds the next row that touches
that test file. Until then, a lane cleanup that runs after this file
waits 30 s before it calls a lone `sleep 30` a leak. The row 197
lanes scan only at lane end, about 15 minutes after pkg-bus, so they
can't see it (mos-1169). (2026-10-21)
## Queue
+18 -25
View File
@@ -33,7 +33,7 @@ Gaps found while working go to `docs/plans/DEFERRED.md`, not here.
<!-- mosaic-queue:begin -->
Generated from `docs/plans/queue.json` revision 2904 by `queue render`. Do not edit between the markers; change the queue with `scripts/mosaic queue`.
Generated from `docs/plans/queue.json` revision 2641 by `queue render`. Do not edit between the markers; change the queue with `scripts/mosaic queue`.
| # | Piece | Owner | Issues | State | After | Gate | Brief | Note |
|---|---|---|---|---|---|---|---|---|
@@ -102,7 +102,7 @@ Generated from `docs/plans/queue.json` revision 2904 by `queue render`. Do not e
| 63 | Multi-project verbs: task verbs across the tree | darkwing; reviewers dewey, filbert | #1556 | done | 62 done | dewey and filbert approve on the issue naming the candidate manifest; tasks, harness and every scripts/test-*.sh green on Sage's gate rerun (sage) | `docs/plans/2026-10-11_multi-project-sync.md` § Multi-project verbs: task verbs across the tree (row B) | lands before row 90 (decision 125): both share packages/tasks/README.md and tests/verbs.test.mjs, so row 90 rebases after this lands |
| 64 | Managed sessions get their role's skills on both harnesses | sage; reviewers darkwing, filbert | #1557 | done | 65 done | darkwing and filbert approve on #1557 naming the candidate manifest; business, harness, cli and every test-*.sh green on Sage's gate rerun; Sage's landing session on each harness shows the role's skills (sage) | `docs/plans/2026-10-11_managed-session-config.md` § Managed sessions get their role's skills on both harnesses | Landed (mos-0863/0864): 9f0039711 = c6d7d538f (range-diff =, patch-id 7e1948e2f2e9), F1 doc 6b6567b8b, packet ebfc23c43; gate-land GATE_PASSED 2384/0 on 6b6567b8b. D2 on #1557 comment 29228: claude-code coder rc13bcd555652 replied with its 4 skills, pi coder r3455505dd5da launch only (no pi credential on host, to Mos); both manifests list the 4 coder skills, sha256 = landed files. D3 window step 46de60893, D4 #1672 row 174. |
| 65 | Model routing table: sessions resolve harness, model and thinking from one table | sage; reviewers darkwing, dewey | #1558 | done | 49 done, 131 done | Mos clears the routing table's public/ diff (decision 123, mos-0840) before in-review; darkwing and dewey approve on #1558; plugins, bus, business, harness, seat, cli, webui, test-*.sh green on Sage's rerun; landing session shows module, route, counted model, thinking; report names the mos-0840 view (sage) | `docs/plans/2026-10-11_managed-session-config.md` § Model routing table: sessions resolve harness, model and thinking from one table | Decision 94 hold ended (cutover live 17:21Z); restarted under decision 111 and Mos sage-0091. |
| 66 | Managed sessions run the unslop check on both harnesses | sage; reviewers dewey, filbert | #1559 | in-review, round 4, request posted | 64 done | dewey and filbert approve on #1559 naming the candidate manifest; unslop, harness, cli and every test-*.sh green on Sage's gate rerun; Sage's landing session on each harness shows the notice, the correction and the counts (sage) | `docs/plans/2026-10-11_managed-session-config.md` § Managed sessions run the unslop check on both harnesses | Drift: row 245 (6d5545d44) changed docs/TOOLS.md, which is in this manifest. r4c must take 245's TOOLS.md hunks before its gate and new manifest; the approved TOOLS.md blob is now stale (sage-1992 sweep). |
| 66 | Managed sessions run the unslop check on both harnesses | sage; reviewers dewey, filbert | #1559 | in-review, round 3, request posted | 64 done | dewey and filbert approve on #1559 naming the candidate manifest; unslop, harness, cli and every test-*.sh green on Sage's gate rerun; Sage's landing session on each harness shows the notice, the correction and the counts (sage) | `docs/plans/2026-10-11_managed-session-config.md` § Managed sessions run the unslop check on both harnesses | Decision 94 hold ended (cutover live 17:21Z); restarted under decision 111 and Mos sage-0091. |
| 67 | Decisions read follow-up: seen-then-resolve, list-before-503 and full-row tests | filbert; reviewers darkwing, dewey | #1560 | done | — | darkwing and dewey approve on #1560 naming the candidate manifest; bus, webui and every scripts/test-*.sh green on Sage's gate rerun (sage) | `docs/plans/2026-10-11_decisions-read-follow-up.md` § Decisions read follow-up: seen-then-resolve, list-before-503 and full-row tests | — |
| 68 | Bus host runs an explicit Claude Code binary | sage; reviewers dewey, filbert | #1561 | done | — | Filbert and Dewey approve; cli, seat, harness suites and every scripts/test-*.sh green on Sage's gate rerun; unit reinstalled and opus probe through MOSAIC_CLAUDE_BIN (sage) | `docs/plans/2026-10-11_bus-claude-binary.md` § Bus host runs an explicit Claude Code binary | — |
| 69 | Terminal app follow-up: narrow-terminal guard test, hidden-box way out and width tests | darkwing; reviewers dewey, filbert | #1562 | done | 55 done | dewey and filbert approve on the issue naming the candidate manifest; cli and queue node suites plus every scripts/test-*.sh green on Sage's gate rerun (sage) | `docs/plans/2026-10-11_terminal-app-follow-up.md` § Terminal app follow-up: narrow-terminal guard test, hidden-box way out and width tests | Sage accepts the two shortened texts in round 1 (hidden box way out, status line), both forced by the 40x10 frame. Follow-up at landing: when help is cut to fit, draw() points at mosaic inbox --json though help has no whole text; open it as its own row (build.md Found, not fixed) |
@@ -231,9 +231,9 @@ Generated from `docs/plans/queue.json` revision 2904 by `queue render`. Do not e
| 192 | Q175 phase 1: the Console verifies SSO itself (--sso), OIDC RP with oauth4webapi 3.8.8, no live change (MVP T1.2, #412) | launchpad; reviewers webby | #1690 | done | — | Webby approves the manifest; webui and cli suites, scripts/test-config.sh and every scripts/test-*.sh green on Sage's gate; design section 9 mutants killed (sage) | `docs/plans/2026-10-20_sso-phase1.md` § Brief: Q175 phase 1, the Console verifies SSO itself (--sso) | Landed 4429a104f on refactor (squash of launchpad/row192 53bb59462..37582e820, round 2 manifest 6f8cee14...7787). patch-id 4a4869026 matches the reviewed diff on all 18 paths. Gate on 088087ac9: package suites 2758/0, scripts 429/0, mutants 22 of 23 killed (#23 equivalent, sage-1407). npm ci in canonical, oauth4webapi 3.8.8. Live re-pin is a window with Mos (mos-1099 item 3). |
| 193 | many humans per business, human roles, private and shared threads, one access.json store (MVP T1.3, Vikunja #414/#415) | morgana; reviewers duckworth | #1691 | in-progress | — | Duckworth approves DESIGN.md then the manifest; bus, business, cli and webui suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_human-users.md` § Brief: many humans per business, human roles, private and shared threads | — |
| 194 | agent lifecycle from the Console and the CLI (create, launch, terminate, regenerate, delete) with a per-agent hire/fire veto (MVP T1.5, Vikunja #414/#415) | honker; reviewers webby | #1692 | in-progress | — | Webby approves DESIGN.md then the manifest; bus, cli, business and webui suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_agent-lifecycle.md` § Brief: agent lifecycle from the Console and the CLI, with a per-agent hire/fire veto | sage-1610 (honker-0049): a human add takes tracker {bot, botId}, required for a vikunja definition, refused otherwise, checked by checkBot and bot uniqueness; CLI and API only. Delete accepts a tracker bot when all credentials are store refs, and its result names the bot for removal by hand in Vikunja. No Vikunja account is created (Q188 untouched). Mutants: drop the requirement, refuse the bot on delete, skip checkBot on add. |
| 195 | row 195: the Case 1 install on 10.1.1.53 as mosaic under /srv/mosaic, reusing C2-13's scripts by input under row 190's canon (Q181, Q182/Q183, Q185; ops-01 root steps under #423 step 1) | darkwing; reviewers duckworth | #1693 | done | 190 done, 226 done, 233 done | Duckworth approves DESIGN.md then the manifest; cli suite and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_hub-own-uid.md` § Brief: the Case 1 install on 10.1.1.53 (row 195) | LANDED b65014647 (pushed 361ba2387 tip). Patch-id 656e43ff25de = 4ced5e63d..37171f65b; verify-commit ok, 5 paths. Combined gate with 213 on 38b83ea5c+paths 09:45:52-09:57:52Z: business 200/0 bus 542/0 harness 140/0 cli 663/0, all 10 scripts green, L1 killed. N1-N3 to DEFERRED next; follow-up darkwing/row195-n1 1e3c4767c. |
| 195 | row 195: the Case 1 install on 10.1.1.53 as mosaic under /srv/mosaic, reusing C2-13's scripts by input under row 190's canon (Q181, Q182/Q183, Q185; ops-01 root steps under #423 step 1) | darkwing; reviewers duckworth | #1693 | briefed | 190 done, 233 done | Duckworth approves DESIGN.md then the manifest; cli suite and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_hub-own-uid.md` § Brief: the Case 1 install on 10.1.1.53 (row 195) | sage-1439: rewritten to Case 1 on .53 (f24f2cd40). Chains on C2-13's candidate too once C2-13 is queued. Darkwing starts DESIGN.md after row 190's mutants. |
| 196 | the human boundary across uids and humans: Console, tester listener, broker.sock and the path-bound human proof (P19 333, before federation R3, mos-0989) | gander; reviewers duckworth | #1694 | in-progress | — | Duckworth approves DESIGN.md then the manifest; bus, webui and cli suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_human-boundary.md` § Brief: the human boundary across uids and humans (P19 333) | — |
| 197 | a second gate lane: two full gates at once on dragon-lin, design first (mos-0977 item 6) | herb; reviewers webby | #1695 | in-review, round 6, request posted | — | Webby approves DESIGN.md then the manifest; cli suite and every scripts/test-*.sh green on Sage's gate, singly and in the two-lane proof (sage) | `docs/plans/2026-10-20_second-gate-lane.md` § Brief: a second gate lane, two full gates at once on dragon-lin | r7 APPROVED (webby-0074 rev 2822). r7 proof sage-1973 11:50-11:51Z STOPPED at solo-a pkg-cli (#1695 c30044): gate-lane-image.test.mjs:93 and :103 call docker via PATH, which in a lane is the guard shim; composeFixture env drops MOSAIC_GATE_DOCKER_RECORD, shim exits 2. business 200/0, bus 596/0, cli 197/2. r8 Herb: test-only fix + run under a lane-shaped PATH. N10 still open. |
| 197 | a second gate lane: two full gates at once on dragon-lin, design first (mos-0977 item 6) | herb; reviewers webby | #1695 | in-review, round 1, request posted | — | Webby approves DESIGN.md then the manifest; cli suite and every scripts/test-*.sh green on Sage's gate, singly and in the two-lane proof (sage) | `docs/plans/2026-10-20_second-gate-lane.md` § Brief: a second gate lane, two full gates at once on dragon-lin | Order with row 198 (Sage, mos-1040 N1): 197 lands first. After B1 the shared tests are packages/webui/tests/serve.test.mjs:100 and preview.test.mjs:208. Row 198 rebases onto 197's landing before its manifest review. |
| 198 | retire the control board writer on 7331 (unauthenticated loopback writer, Q175; mos-1008) | bushroot; reviewers webby | #1696 | in-progress | 192 done, 197 done | Webby approves INVENTORY.md then the manifest; control-board, webui and cli suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_retire-control-board.md` § Brief: retire the control board writer on 7331 | Order with row 197 (Sage, mos-1040 N1): 197 lands first. Row 198 rebases onto 197's landing before its manifest review; shared tests are packages/webui/tests/serve.test.mjs:100 and preview.test.mjs:208. |
| 199 | MVP T1 item 6: a credential store per agent, own git identity, pushes to a remote (G11, G13; mos-0974) | megavolt; reviewers duckworth | #1697 | done | — | Duckworth approves DESIGN.md; Mos rules on the authority model; Duckworth approves the manifest; bus, business, cli and tasks suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: a credential store per agent, own git identity, pushes to a remote | Landed cb5fdb064 on refactor (base 76134dfde), pushed. Patch-id 828fa21a matches git diff 00d4cc1f6..86963d281 on the 37 manifest paths; docs/TOOLS.md 3-way with row 200, hunk unchanged. Manifest 35f900fd, Duckworth approve r1 29779. Gate on 9e1085816+patch: packages 2735/0, scripts 429/0; landed blobs equal the gate tree. |
| 200 | stack-release.sh activate --sso for the Q175 phase 2 window (row 192 F3; chained on 192) | launchpad; reviewers webby | #1698 | done | — | Webby approves the manifest; cli suite and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_stack-release-sso.md` § Brief: stack-release.sh activates a Console with --sso (Q175 phase 2 prerequisite) | Landed 9e1085816 on refactor (base 722136772), pushed. Patch-id 7ebfa6a5 matches git diff 00d4cc1f6..9df40878f on the 3 manifest paths. Manifest b3ead55c, Webby approve r3 29772. Gate on 9df40878f: packages 2675/0, scripts 429/0. Mutants 13/14, M12 ruled equivalent (sage-1446). |
@@ -248,44 +248,37 @@ Generated from `docs/plans/queue.json` revision 2904 by `queue render`. Do not e
| 209 | FED R8: the hub window on 10.1.1.54, a recorded acceptance (#414, r4.11 b93f098f0; live window run by Jason and Mos, after the Case 2 install #416, Bean and Chet live and both Hermes gateways stopped) | sage; reviewers duckworth | — | queued | — | Every entry check's output is in the R8 record with who ran it; Jason signs in to the hub and sends one message, Melanie revokes, his next request is refused; Duckworth checks the record (sage) | `docs/plans/2026-10-20_federation-r1-r2-r5.md` § Brief: FED R8, the hub window on 10.1.1.54 | Stays queued until its entry gates near: Case 2 install on .54 (#416, by 2026-10-27), Bean and Chet live, both Hermes gateways on .54 stopped, R7, #412 phase 2, #419 answer. Filed per mos-1073 after duckworth-0034 (Sage) |
| 210 | Agent host access with sudo through the credential store: grant per agent and host, the stack does ssh and sudo, the agent never sees the key (#1707, Vikunja #424, Q183/Q184, due 10-27; chained on row 199's candidate) | gizmoduck; reviewers duckworth | #1707 | done | — | Duckworth approves DESIGN.md, then the manifest; bus, business, cli suites and every scripts/test-*.sh green on Sage's gate; the mutants killed (sage) | `docs/plans/2026-10-20_host-credentials.md` § Brief: agent host access with sudo through the credential store (#424) | Landed f5753c0e8 on refactor (base 9d165be8c), pushed. Patch-id 723b1c83 matches git diff ad95c888c..0485384e9 on the 23 manifest paths; landed files pass r5 manifest 688d38b9. Duckworth approve r2 rev 2592, r3 29851. Mutants 52/53, M22b equivalent (rev 2584). Gate on ad95c888c+patch: packages 2796/0, scripts 429/0; landed blobs equal the gate tree. |
| 211 | Force-push guard: scripts/git-hooks/pre-push refuses non-fast-forward and delete pushes from every worktree, and scripts/slot-busy.sh exits 1 on BUSY (#1709, Vikunja #426, mos-1078/1083) | rocko; reviewers dewey | #1709 | briefed | — | Dewey approves the manifest; the new or changed scripts/test-*.sh and every other scripts/test-*.sh green on Sage's gate; the mutants killed; hook installed in the canonical checkout with a scripted refused force-push (sage) | `docs/plans/2026-10-20_force-push-guard.md` § Brief: a pre-push hook that refuses force-pushes, and a busy check that fails on BUSY (#426) | — |
| 212 | Case 2 C2-01 packages/library: mapping, scope, reader, resolver, R-rules, renderItems, survey | gosalyn; reviewers webby | #1713 | done | — | Webby approves the manifest. The library tests and the cli suite are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-01 packages/library: mapping, scope, reader, resolver, R-rules, renderItems, survey | Landed ee7b2f137 (pushed 09:13Z) on f6c70f944, alone per mos-1162: the 21 manifest paths from a2c72ac95. Patch-id ea84d3e35470 equals the candidate's; blobs and modes match; verify-commit ok (21 paths). No 212 path changed after c771a36f4. Gate: Sage's landing gate 08:51-09:03Z on 4ced5e63d plus 212's and 197's paths, GATE_PASSED, node 981/0, selftests 429/0. Gosalyn r3 slot 451/0, test-queue 28/0. Row 197 waits for r6 (lane proof stopped, sage-1881). |
| 213 | Case 2 C2-08 creative roles, persona file and block, M1, M2, M6, M10, prompt passed by file | morgana; reviewers webby | #1714 | done | — | Webby approves the manifest. The business, bus and harness suites, `scripts/test-config.sh` and every `scripts/test-*.sh` are green on Sage's gate, and the `models` mutant is killed. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-08 creative roles, persona file and block, M1, M2, M6, M10, prompt passed by file | LANDED 361ba2387 (39 paths incl. 4 packet files). Patch-id f313e69b6f7e = c771a36f4..2b3e67e36; verify-commit ok, 35 manifest paths. Same combined gate as 195: business 200/0 bus 542/0 harness 140/0 cli 663/0, test-config 31/0 and all 10 scripts green, models mutant L1 killed. Webby N2 is row 235 acceptance (mos-1163). |
| 212 | Case 2 C2-01 packages/library: mapping, scope, reader, resolver, R-rules, renderItems, survey | gosalyn; reviewers webby | #1713 | in-review, round 1, request posted | — | Webby approves the manifest. The library tests and the cli suite are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-01 packages/library: mapping, scope, reader, resolver, R-rules, renderItems, survey | — |
| 213 | Case 2 C2-08 creative roles, persona file and block, M1, M2, M6, M10, prompt passed by file | morgana; reviewers webby | #1714 | in-review, round 2, request posted | — | Webby approves the manifest. The business, bus and harness suites, `scripts/test-config.sh` and every `scripts/test-*.sh` are green on Sage's gate, and the `models` mutant is killed. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-08 creative roles, persona file and block, M1, M2, M6, M10, prompt passed by file | — |
| 214 | Case 2 C2-11a editor wikilink node, after measuring whether [[ round-trips | rocko; reviewers filbert | #1715 | briefed | — | Filbert approves the manifest. The webui suite is green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-11a editor wikilink node, after measuring whether [[ round-trips | — |
| 215 | Case 2 C2-04 the library entry in the business file, consumer skips, M9, mirror, library.file and library.status | herb; reviewers filbert | #1716 | in-review, round 1, request posted | — | Filbert approves the manifest. The business, seat, cli, project, bus and webui suites are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-04 the library entry in the business file, consumer skips, M9, mirror, library.file and library.status | Sage 15:01Z drift sweep after 249 landed 9de5a57ab (+7b9737953): manifest 8d5695d7 shares packages/bus/src/broker.mjs with 249, merge-tree was clean. Order stays 197 then 215 (sage-2029, sage-2030): after 197 lands Herb rebases 215 on that tip for a merge-scoped round with Filbert (broker.mjs from 249, stack-release.test.mjs from 197), then Sage's full landing gate. Rows 13, 66, 197, 202 have no overlap. |
| 215 | Case 2 C2-04 the library entry in the business file, consumer skips, M9, mirror, library.file and library.status | herb; reviewers filbert | #1716 | briefed | — | Filbert approves the manifest. The business, seat, cli, project, bus and webui suites are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-04 the library entry in the business file, consumer skips, M9, mirror, library.file and library.status | — |
| 216 | Case 2 C2-05a lookup index and queries | researcher; reviewers filbert | #1717 | briefed | — | Filbert approves the manifest. The library suite is green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-05a lookup index and queries | — |
| 217 | Case 2 C2-06 the cited-reply guard, the page store and the three notices | launchpad; reviewers webby | #1718 | briefed | — | Webby approves the manifest. The library, bus and harness suites are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-06 the cited-reply guard, the page store and the three notices | — |
| 218 | Case 2 C2-12 the setup sheet for Melanie and the survey run sheet | sage; reviewers webby | #1719 | done | — | Doc only. Webby approves it against C2-01's real flags. Before landing, grep `packages/*/tests` and `scripts/test-*.sh` to confirm no test reads either file. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-12 the setup sheet for Melanie and the survey run sheet | LANDED f8276c5eb (pushed, on Darkwing sessions b65f3a0e8). Webby APPROVE r1-r3 (revs 2848, 2856, 2860; r3 candidate 1a38baf5af2a = 89ba79d94). Patch-id 18ba1e40ad29 seat 5c6f73ed7..89ba79d94 equals landed b65f3a0e8..f8276c5eb; three blobs equal 89ba79d94. Gate: doc only, 0 test readers (control 3). Melanie handover waits on C2-06 and Jason (#419). |
| 218 | Case 2 C2-12 the setup sheet for Melanie and the survey run sheet | sage; reviewers webby | #1719 | briefed | — | Doc only. Webby approves it against C2-01's real flags. Before landing, grep `packages/*/tests` and `scripts/test-*.sh` to confirm no test reads either file. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-12 the setup sheet for Melanie and the survey run sheet | — |
| 219 | Case 2 C2-09a one thread per creative instance | rocko; reviewers dewey | #1720 | briefed | — | Dewey approves the manifest. The bus, cli and webui suites are green on Sage's gate, along with every `scripts/test-*.sh`. Watch for hash pins on `bus.js` and `broker.mjs` (`packages/bus/tests/channel-proof.test.mjs` pins a webui file). (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-09a one thread per creative instance | — |
| 220 | Case 2 C2-10a no raw session view (M7) and no raw Discord engine (M8) | researcher; reviewers filbert | #1721 | briefed | — | Filbert approves the manifest. The conversation and discord suites and `scripts/test-discord.sh` are green on Sage's gate, along with every `scripts/test-*.sh`. No test reaches a Discord server. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-10a no raw session view (M7) and no raw Discord engine (M8) | — |
| 221 | Case 2 C2-20 Bean and Chet persona import, with a count-only dry run | gosalyn; reviewers webby | #1722 | done | — | Webby approves the manifest. The test file runs green on its own and the cli suite is green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-20 Bean and Chet persona import, with a count-only dry run | LANDED 300766450, pushed. Cand 8f403d0d4, manifest 20f05e3a6ad5, 22 paths, verify-commit ok, patch-id dfbb754c6fb4 equals 62ddc96cc..8f403d0d4. Gate 11:07:50-11:19Z on b1fece6f0: test file alone 11/0, harness 140/0, cli 677/0, all scripts green. Brief Gate met: webby-0073 approve, test file alone, cli, scripts. No live run in the Gate; the import itself waits on Jason. N1 N2 N4 go to C2-20b, N3 to DEFERRED. |
| 222 | Case 2 C2-03a fetch-only sync | megavolt; reviewers dewey | #1723 | in-progress | — | Dewey approves the manifest. The library and bus suites are green on Sage's gate, along with every `scripts/test-*.sh`, and the mutant is killed. A search of the test run's output for the fixture token finds nothing. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-03a fetch-only sync | sage-2024 on megavolt-0089: core.createObject=rename in the fetch argv is accepted as a brief departure, since C2-04 inspectMirror refuses nlink 2. Dewey checks it. The askpass env keys, export SAFE in project/src/git.mjs, bus/tests/library-sync.test.mjs and the SURVEY-RUN user line are accepted. The 5 s client timeout residual goes in BUILD.md and Dewey rules fix or defer. Slot after 197 proof 3 and the 249 gate. |
| 221 | Case 2 C2-20 Bean and Chet persona import, with a count-only dry run | gosalyn; reviewers webby | #1722 | briefed | — | Webby approves the manifest. The test file runs green on its own and the cli suite is green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-20 Bean and Chet persona import, with a count-only dry run | — |
| 222 | Case 2 C2-03a fetch-only sync | megavolt; reviewers dewey | #1723 | in-progress | — | Dewey approves the manifest. The library and bus suites are green on Sage's gate, along with every `scripts/test-*.sh`, and the mutant is killed. A search of the test run's output for the fixture token finds nothing. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-03a fetch-only sync | — |
| 223 | Case 2 C2-07 runner retry on a guard refusal, and the runner's notices | researcher; reviewers filbert | #1724 | briefed | — | Filbert approves the manifest. The harness suite is green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-07 runner retry on a guard refusal, and the runner's notices | — |
| 224 | Case 2 C2-05b broker lookup verbs and typed tools | rocko; reviewers dewey | #1725 | briefed | — | Dewey approves the manifest. The bus and harness suites are green on Sage's gate, along with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-05b broker lookup verbs and typed tools | — |
| 225 | Case 2 C2-10b Console chat: cited items and the status line | researcher; reviewers dewey | #1726 | briefed | — | Dewey approves the manifest. The webui suite is green on Sage's gate, along with every `scripts/test-*.sh`. Grep for hash pins on `bus.js` and `serve.mjs` before in-review. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-10b Console chat: cited items and the status line | — |
| 226 | Case 2 C2-13 install script and precheck for the host | gosalyn; reviewers webby | #1727 | briefed | 215 done, 221 done, 222 done, 230 done | Webby approves the manifest. The test file and the cli suite are green on Sage's gate, along with every `scripts/test-*.sh`. The run on the host is a separate window with Jason's go. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-13b install script and library precheck | — |
| 226 | Case 2 C2-13 install script and precheck for the host | gosalyn; reviewers webby | #1727 | briefed | — | Webby approves the manifest. The test file and the cli suite are green on Sage's gate, along with every `scripts/test-*.sh`. The run on the host is a separate window with Jason's go. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-13b install script and library precheck | — |
| 227 | Case 2 C2-14 end-to-end acceptance on a scratch root | launchpad; reviewers dewey | #1728 | briefed | — | Dewey runs the script and approves. It is green on Sage's gate with every `scripts/test-*.sh`. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-14 end-to-end acceptance on a scratch root | — |
| 228 | Row A: ZAI_API_KEY passes through ENV_ALLOW to sessions, README line, pass-through test (XS, Haiku high) | researcher; reviewers webby | #1729 | done | — | Webby approves the manifest. The mutant is killed. The seat suite and the cli suite are green on Sage's gate with every scripts/test-*.sh. (sage) | `docs/plans/2026-10-20_case2-rows.md` § Brief: row A, ZAI_API_KEY in the session env allowlist | Landed 86249ac55 (pushed 07:25Z) on 59f817c32: the 3 manifest paths from cf18c42b9. Patch-id b6ffe31feb0d equals the candidate's; modes and blobs match; verify-commit ok (3 paths). Sage's combined 228+238 gate on c515273db plus both rows' 6 paths, 07:11:30Z to 07:23:34Z: seat 165/0, cli 640/0, all ten scripts/test-*.sh 585/0. |
| 228 | Row A: ZAI_API_KEY passes through ENV_ALLOW to sessions, README line, pass-through test (XS, Haiku high) | researcher; reviewers webby | #1729 | in-review, round 1, request posted | — | Webby approves the manifest. The mutant is killed. The seat suite and the cli suite are green on Sage's gate with every scripts/test-*.sh. (sage) | `docs/plans/2026-10-20_case2-rows.md` § Brief: row A, ZAI_API_KEY in the session env allowlist | — |
| 229 | Row B: per-instance pi agent dir for Chet's Codex login, design only, starts after 10-27 (#428) | gosalyn; reviewers webby | #1730 | queued | — | A live check, with Jason's or Mos's go, that two clients on one ChatGPT login don't revoke each other's refresh tokens. No build row starts before it passes. Held until after 10-27. (sage) | `docs/plans/2026-10-20_case2-rows.md` § Brief: row B, a per-instance pi agent dir for Chet's Codex login (#428) | — |
| 230 | Case 2 C2-13a unit render and host precheck (case2-unit.sh, case2-precheck.sh) | gosalyn; reviewers webby | #1732 | done | — | Webby approves the manifest. The test file and the cli suite are green on Sage's gate, along with every scripts/test-*.sh. A run on a host is a separate window with Jason's go. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-13a unit render and host precheck | Landed c8bc5cf4c on refactor (base 390ea5261), pushed. Patch-id f4b49eb68997 matches git diff 722136772..96768766c on the 5 manifest paths (manifest fbb0d7e42c67, Webby approve r2 rev 2563). packages/cli/README.md 3-way with row 199, hunks apart. Gosalyn gate on 96768766c: cli 541/0, scripts 429/0, mutants 10/10. Merged tree check: case2-unit 30/0, host 42/0. |
| 231 | Case 2 C2-01b survey escapes, list item lines and attachment embeds (row 212 N1-N3) | gosalyn; reviewers webby | #1733 | done | 212 done | Webby approves the manifest. The library tests are green on Sage's gate, along with every scripts/test-*.sh. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-01b survey escapes, list item lines and attachment embeds | LANDED 29ce1e360 (sage gate 10:05:31-10:07:52Z GREEN on 62ddc96cc: library 45/0, every scripts/test-*.sh). verify-commit ok, 9 paths; patch-id 59b98b1b3e00 equals fefd54e13..f37a65857. Pushed. Webby N4 stays as restored (sage-1917), doc-only. |
| 231 | Case 2 C2-01b survey escapes, list item lines and attachment embeds (row 212 N1-N3) | gosalyn; reviewers webby | #1733 | briefed | 212 done | Webby approves the manifest. The library tests are green on Sage's gate, along with every scripts/test-*.sh. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-01b survey escapes, list item lines and attachment embeds | — |
| 232 | Installer I1: stack-release external units and stack-copy bundle copies (MVP, Q187, Vikunja #432) | darkwing; reviewers filbert | #1734 | done | — | Filbert approves the manifest. The cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) | `docs/plans/2026-10-20_installer-rows.md` § I1 stack-release external units and bundle copies | Landed e65a3ab4d on refactor (base 0444acd08), pushed. Patch-id 5adfbab9 matches git diff 8fede5fc6..da2da2f6c on the 9 manifest paths; tree entries (modes too) equal da2da2f6c, files pass manifest 7af3c943. Filbert approve r1 29829, r2 29865. Darkwing's landing gate on da2da2f6c: cli 593/0, scripts 429/0 (+156 queue node tests). Mutants 17/17. |
| 233 | Installer I3: stack-upgrade.sh root driver and the ops-01 host run sheet (MVP, Q187, Vikunja #432) | darkwing; reviewers filbert | #1735 | done | 232 done | Filbert approves the manifest. The test file, the cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) | `docs/plans/2026-10-20_installer-rows.md` § I3 the upgrade command and the host run sheet | Landed 57f59e0c3 on 5465fd52d (pushed 05:39Z). verify-commit matches the manifest (7 paths). Patch-id b16ac924 equals the candidate's (1a1dc80ca vs e65a3ab4d). Modes match. Sage's gate on the landing tree: cli 617/0, scripts/test-*.sh 585/0. Filbert N1, N4 and N5 go to row 240, N2 and N3 to DEFERRED. |
| 234 | Machine grant row a: host enrollment, store records and migration 3i-3j (#436a, design r6 f9039682e, lands by 10-25 before the .53/.54 installs) | gizmoduck; reviewers duckworth | #1740 | done | 210 done | Duckworth approves the manifest. The bus, business and cli suites and every scripts/test-*.sh are green on Sage's gate. The design's section 10 row a tests and mutants pass, the migration test included. (sage) (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row a: enrollment, store records and migration 3i-3j | LANDED c771a36f4 (pushed 06:16Z 10-21) on caa4b5944: r3 c783d5e39 41 paths via temp index, modes from ls-tree. patch-id 32bbbea2bd6f equals the candidate's; verify-commit ok 41 paths. Gate on the c783d5e39 tree 06:02:12Z-06:15:26Z: 15 packages 2890/0, ten scripts/test-*.sh 585/0. Duckworth r3 approve 29935 rev 2683. N10, N12 to row 235. |
| 235 | Machine grant row b: raise binding, executor, reconcile and revoke (#436, design r6 f9039682e, C1, N1, G27, G28) | gizmoduck; reviewers duckworth | #1741 | done | 234 done | Duckworth approves the manifest. The bus, business and cli suites and every scripts/test-*.sh are green on Sage's gate. Section 10's row b tests and mutants pass, G27, G28 and the upsert mutant included. (sage) (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row b: raise binding, executor, reconcile and revoke | LANDED b1fece6f0, pushed (rode Darkwing SESSIONS aa19a2464). Cand ed4193316, manifest dad377ca8fe4, 13 paths, verify-commit ok, patch-id c355d2fc457d. Gate 10:30:55-10:42:43Z: bus 596/0, business 200/0, cli 666/0, all scripts green. Brief Gate met: duckworth-0089 approve, upsert mutant equivalent, row b and creative tests and mutants on Gizmoduck slot runs (38 of 39 killed, B17 equivalent). |
| 233 | Installer I3: stack-upgrade.sh root driver and the ops-01 host run sheet (MVP, Q187, Vikunja #432) | darkwing; reviewers filbert | #1735 | in-progress | 232 done | Filbert approves the manifest. The test file, the cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) | `docs/plans/2026-10-20_installer-rows.md` § I3 the upgrade command and the host run sheet | — |
| 234 | Machine grant row a: host enrollment, store records and migration 3i-3j (#436a, design r6 f9039682e, lands by 10-25 before the .53/.54 installs) | gizmoduck; reviewers duckworth | #1740 | in-progress | 210 done | Duckworth approves the manifest. The bus, business and cli suites and every scripts/test-*.sh are green on Sage's gate. The design's section 10 row a tests and mutants pass, the migration test included. (sage) (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row a: enrollment, store records and migration 3i-3j | — |
| 235 | Machine grant row b: raise binding, executor, reconcile and revoke (#436, design r6 f9039682e, C1, N1, G27, G28) | gizmoduck; reviewers duckworth | #1741 | queued | 234 done | Duckworth approves the manifest. The bus, business and cli suites and every scripts/test-*.sh are green on Sage's gate. Section 10's row b tests and mutants pass, G27, G28 and the upsert mutant included. (sage) (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row b: raise binding, executor, reconcile and revoke | — |
| 236 | #436b Gitea grant path build: seat accounts and tokens through an approved grant, schema 3j-3k (design r5 1be535aca, due 10-27 at risk; live waits for Jason's section 8 approval and bootstrap step) | megavolt; reviewers dewey | #1742 | queued | 210 done, 234 done | Dewey approves the manifest. The bus, business and cli suites and every scripts/test-*.sh are green on Sage's gate. Section 9's mutants are killed, N9's restart test included. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: #436b Gitea grant path, build (schema 3j-3k) | — |
| 237 | Row 199 follow-up N1: one decision publishes once (publish-busy or #spent recheck) | megavolt; reviewers duckworth | #1743 | done | 199 done | Duckworth approves the manifest. The bus suite and every scripts/test-*.sh are green on Sage's gate, and the mutant is killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 199 follow-up N1, one decision publishes once | Landed d7d943199 on refactor (local, push pending), patch-id c5f4beb4 = e42415935, manifest bb777cb0 blobs checked. Sage gate 01:31-01:44Z on 816d48b03+4 paths: M1 killed (bus 1/13, cli 1/8), every package suite and scripts/test-*.sh green (bus 478, cli 564). |
| 238 | row 200 follow-up N1: the sso-config hint carries --instance NAME (#1744) | launchpad; reviewers webby | #1744 | done | 200 done | Webby approves the manifest; stack-release.test.mjs whole, cli suite and every scripts/test-*.sh green on Sage's gate; the mutant killed (sage) | `docs/plans/2026-10-20_stack-release-sso.md` § Brief: row 200 follow-up N1, the sso-config hint names the instance | Landed d49b1f2bd (pushed 07:25Z) on 86249ac55: the 3 manifest paths from 4c90099ea. Patch-id b9d0bb0ee3c7 equals the candidate's; modes and blobs match; verify-commit ok (3 paths). Sage's combined 228+238 gate on c515273db plus both rows' 6 paths, 07:11:30Z to 07:23:34Z: seat 165/0, cli 640/0, all ten scripts/test-*.sh 585/0. Mutant (sso-config drops --instance) killed, survived none. Round 1 N1 stays on the #1744 carry list. |
| 238 | row 200 follow-up N1: the sso-config hint carries --instance NAME (#1744) | launchpad; reviewers webby | #1744 | in-review, round 1, request posted | 200 done | Webby approves the manifest; stack-release.test.mjs whole, cli suite and every scripts/test-*.sh green on Sage's gate; the mutant killed (sage) | `docs/plans/2026-10-20_stack-release-sso.md` § Brief: row 200 follow-up N1, the sso-config hint names the instance | — |
| 239 | Row 194 follow-up: the credential revoke runs under the writer's lock, refusals after a revoke say so, and a stale-revision fire test (duckworth-0074, mos-1158) | honker; reviewers duckworth | #1745 | queued | 194 done | Duckworth approves the manifest. The bus, business, cli and webui suites and every scripts/test-*.sh are green on Sage's gate, and the mutants are killed. (sage) (sage) | `docs/plans/2026-10-20_agent-lifecycle.md` § Brief: row 194 follow-up, the revoke under the writer's lock and a fire test | — |
| 240 | Installer I4: hostcheck, the bwrap profile check, pins and boot unit, from r6 B2 (MVP, Q187, Vikunja #432; split from I3) | darkwing; reviewers filbert | #1746 | done | 233 done | Filbert approves the manifest. The test file, the cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) (sage) | `docs/plans/2026-10-20_installer-rows.md` § I4 hostcheck: the bwrap profile check, pins and boot unit | Landed c515273db (pushed 06:57Z) on da3051ccc: the 9 manifest paths from ad1b23ab2. Patch-id 48e376efe8a4 equals the candidate's; modes and blobs match; verify-commit ok (9 paths). Sage's gate on 060a17b54 plus the 9 paths, 06:45:05Z to 06:56:21Z: cli 639/0, all ten scripts/test-*.sh 585/0. Darkwing's r2: singles 37/0, M1-M8 8/8. Filbert N1 and N2 in DEFERRED (da3051ccc); N3 by design. |
| 240 | Installer I4: hostcheck, the bwrap profile check, pins and boot unit, from r6 B2 (MVP, Q187, Vikunja #432; split from I3) | darkwing; reviewers filbert | #1746 | queued | 233 done | Filbert approves the manifest. The test file, the cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) (sage) | `docs/plans/2026-10-20_installer-rows.md` § I4 hostcheck: the bwrap profile check, pins and boot unit | — |
| 241 | Row 237 follow-up: one decision lands once, a two-ticket broker land test and three mutants on the landing guards (megavolt-0069, sage-1651, P19 441) | megavolt; reviewers duckworth | #1747 | done | 237 done | Duckworth approves the manifest. The bus, seat and cli suites and every scripts/test-*.sh are green on Sage's gate, and the three mutants are killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 237 follow-up, one decision lands once, with tests at the broker | Landed 5d4a61776 on refactor, pushed (base e65a3ab4d). Blobs from 3e3ed303e on 2 paths; patch-id a1649f80 equals git diff f5753c0e8..3e3ed303e on those paths; ls-tree modes equal; manifest e8266864 verifies on the landed files. Sage slot on bbf3b1ee8: M1-M3 killed; gate 15 packages 2797/0, 10 script suites 429/0. Duckworth approve 29870 rev 2628. |
| 242 | Row 237 follow-up N1: a retry after publish-timeout pushes once; hold the decision or kill and wait for the push, a slow-push retry test and a mutant (duckworth-0069, P19 440) | megavolt; reviewers duckworth | #1748 | done | 237 done | Duckworth approves the manifest. The bus and cli suites and every scripts/test-*.sh are green on Sage's gate, and the mutant is killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 237 follow-up N1, a retry after publish-timeout pushes once | Landed 5fb736b92 on refactor, pushed (base 96bac588f). Blobs from 635c10924 on 3 paths; patch-id ceb741ee equals git diff 8fede5fc6..635c10924 on those paths; ls-tree modes equal; manifest 1fbfab6c verifies on the landed files. Megavolt M1/M2 killed on Sage's slot; Sage gate 15 packages 2826/0, 10 script suites 429/0. Duckworth approve 29889 rev 2639. |
| 243 | process.test.mjs startup token refusal sets its file mode (chmod), umask sweep of packages/*/tests | morgana; reviewers webby | — | briefed | 197 done | Webby approves the manifest. The test file passes whole under umask 022 and under umask 077 on Sage's slot. (sage) | `docs/plans/2026-10-21_gate-env-rows.md` § The startup token refusal test sets its file mode | mos-1162: lands after 197 r6, whose proof runs on the unchanged test. |
| 244 | Gate runs use a fixture PI_AUTH_FILE (DEFERRED 059577886, Webby N4) | morgana; reviewers webby | — | briefed | 197 done | Webby approves the manifest. The new test and every touched file are green on Sage's slot, along with test-task.sh and test-release.sh. (sage) | `docs/plans/2026-10-21_gate-env-rows.md` § Gate runs use a fixture pi auth file | — |
| 245 | row 195 follow-up: Duckworth's N1-N3 on scripts/case1-accept.sh (root never runs an unchecked --node; the header lists what root runs; F6 refuses .. after the claude pin dir) | darkwing; reviewers duckworth | #1693; closes none | done | — | Duckworth approves the manifest. The cli suite and every scripts/test-*.sh are green on Sage's gate, and a mutant for each of N1 and N3 is killed. (sage) | `docs/plans/2026-10-20_hub-own-uid.md` § Row 195 follow-up: Duckworth's N1-N3 on the Case 1 acceptance script | LANDED 6d5545d44 on 856c1826b, pushed. Patch-id 36a621ac3966 equals 62ddc96cc..ef8b4439e. Gate: Duckworth r1 APPROVE rev 2849; N1 mutants 13-15 and N3 mutant 16 killed (sage-1961, darkwing-0107); Sage gate 12:24-12:35Z: case1-accept alone 23/0, cli 681/0, scripts/test-*.sh 429/0. Lands before row 246 as the brief asks. #1693 stays open for 246. |
| 246 | row 195 window: the Case 1 acceptance run on 10.1.1.53 (carries row 195's done condition; needs a Jason or Mos go) | darkwing; reviewers duckworth | #1693 | queued | 226 done, 245 done | The window's acceptance run passes on .53, Duckworth reads its output, and Mos confirms. (sage) | `docs/plans/2026-10-20_hub-own-uid.md` § Row 195 window: the Case 1 acceptance run on 10.1.1.53 | — |
| 247 | Case 2 C2-20b persona import follow-up: printed keys, the dry run fence check and the mkdir race | gosalyn; reviewers webby | #1749 | done | 221 done | Webby approves the manifest. The test file runs green on its own, and the three mutants are killed on Sage's slot. The cli suite and every scripts/test-*.sh are green on Sage's gate. (sage) | `docs/plans/2026-10-20_case2-rows.md` § C2-20b persona import follow-up: printed keys, the dry run fence check and the mkdir race | LANDED 856c1826b on f8276c5eb, pushed. Patch-id 373ab2cc4c50 equals 6d43618a3's. Gate: Webby r1 APPROVE rev 2852; test file alone 14/0 and M1-M4 killed (sage-1971); Sage gate 12:10-12:21Z: file 14/0, cli 680/0, scripts/test-*.sh 429/0. M1/M2 at :248 not :237 (gosalyn-0111). |
| 248 | row 235 follow-up: the grant-executor hold-add and hold-remove stubs stop when their test dir is gone (found by the 197 r8 proof) | sage; reviewers webby | #1750 | done | — | Webby approves the commit. On Sage's gate the whole grant-executor.test.mjs passes three times with no stub left, the bus suite is green, and a mutant that drops the dir check leaves a stub. (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row b follow-up: the held stubs end with their test | LANDED 8a04f4aa4 on refactor, pushed. Temp-index landing of candidate 4d99c178b's one path onto bc579f7a8. No drift on the path since 540239b6b. Patch-id 84974d6b08d6 matches the candidate's. Gate per the brief: Webby APPROVE r1 rev 2883, Sage's gate 13:05-13:07Z (file 3x 37/0 no stub, bus 596/0, mutant left 2). |
| 249 | row 235 follow-up: the grant undo records hostLineLeft when install never returned, since the remote add can outlive an abort or timeout (mos-1166) | gizmoduck; reviewers duckworth | #1751 | done | — | Duckworth approves the manifest. On Sage's gate the bus suite and the whole touched test files are green, and a mutant that drops the new catch branch is killed. (sage) | `docs/plans/2026-10-20_host-credentials.md` § Machine grant row b follow-up: the undo can't prove the remote add has ended | LANDED 9de5a57ab on refactor, pushed with 7b9737953 (DEFERRED N1). Range-diff: 8a04f4aa4..05595794b vs 8ca064158..9de5a57ab, same 3 paths, patch-id 99551b122e66 on both. Gate sage-2026 14:53Z: grant-executor whole 39/0, bus 598/0, no stub left, C1 (drop :1025) killed by G8 and both G23. Duckworth approve c30070. |
<!-- mosaic-queue:end -->
+114 -8614
View File
File diff suppressed because one or more lines are too long
+1 -2
View File
@@ -10,8 +10,7 @@
"license": "UNLICENSED",
"dependencies": {
"@earendil-works/pi-coding-agent": "0.85.1",
"oauth4webapi": "3.8.8",
"yaml": "2.9.0"
"oauth4webapi": "3.8.8"
}
},
"node_modules/@anthropic-ai/sdk": {
+1 -2
View File
@@ -6,7 +6,6 @@
"license": "UNLICENSED",
"dependencies": {
"@earendil-works/pi-coding-agent": "0.85.1",
"oauth4webapi": "3.8.8",
"yaml": "2.9.0"
"oauth4webapi": "3.8.8"
}
}
+1 -3
View File
@@ -218,11 +218,9 @@ an operator inspect content and delivery evidence after an uncertain result.
| `credentials.issue` | `{agent,service,token,date}`; human only (row 199, #1697). Writes the token to `<configDir>/secrets/agents/<business>/<agent>/<service>` (0600, dirs 0700: tmp, fsync, rename), rewrites the agent's reference in the business file to `{"store":true,<rotateBy or expires>:date}`, then holds the token in memory, with no restart. Over an issued entry it is a rotate: the old value is gone from disk and memory when it returns. `service` is `gitea` or `vikunja` and the business file must already name it for the agent (`credential-unknown`). A token the bus already holds is `credential-leak`; a bad token `credential-format`; a bad date `credential-date`. Returns `{agent,verb,service,date,state}`, `verb` `issue` or `rotate`. The tester gets `tester-refused`. |
| `credentials.revoke` | `{agent,service?,reason}`; human, or the tester (Q173). Drops the entry from memory, then unlinks a store file; a `file` or `env` reference keeps its file and becomes `store`, so a restart loads nothing. Without `service`, every kind the agent has. Returns `{agent,verb,services:[{service,state}]}`. |
| `credentials.delete` | `{agent,reason}`; human only. `credentials.revoke` for every kind, then removes the agent's store dir; a file there other than a token is `credential-file`. While the agent or one of its threads holds a claim, `agent-running`. |
| `hosts.status` | No args; the human, the tester or the business's chief (row 234, #1740). `[{host,address,port,user,sudo,state,hostKeys,installerFingerprint,checkedAt,hostLineLeft,revoking}]` from the `hosts` records, with host keys as fingerprints. Never a key. |
| `hosts.status` | No args; the human, the tester or the business's chief (row 234, #1740). `[{host,address,port,user,sudo,state,hostKeys,installerFingerprint,checkedAt,hostLineLeft}]` from the `hosts` records, with host keys as fingerprints. Never a key. |
| `hosts.check` | `{host}`; same callers. Runs the host's `list <user>` as `mosaic-installer` with the installer key and the pinned host keys, then sets `state` `ready` and `checkedAt` and writes `grant.host.checked`. A nonzero exit is `host-failed`, a record that changed during the run `host-changed`, a record with no installer key `host-not-enrolled`. |
| `hosts.remove` | `{host}`; the human or the tester. Deletes the record, writes `grant.host.removed` and removes the installer key. A `host_grants` record for the host is `host-in-use`, a guarded event naming a host line left on the host `host-line-left`. |
| `hosts.revoke` | `{agent,host,reason}`; the human, the business's assistant, or the tester when `bus.tester` is exactly `true` (row 235, #1741, r6 section 6). Anyone else gets `revoke-refused`. The tester check reads `bus.tester` again at the call, `tester-dev-only`. One transaction deletes the `host_grants` record and writes `grant.revoked` with `hostLine:"pending"`. With no await between, the key leaves memory and its file goes, and a `host.run` or executor in flight aborts. Then `remove <user> <tag>` runs on the host and `grant.revoke.closed` records `hostLine:"removed"` or `hostLineLeft`. A revoke with no record still runs, with `granted:false`. Returns `{agent,host,tag,granted,keyFile,hostLine or hostLineLeft}`. A restart with a pending marker runs the remove once the bus is up; `hosts.status` lists its tag under `revoking`. |
| `hosts.sweep` | `{host}`; the human or the tester (r6 X3). Runs `list <user>` and removes each listed tag this business recorded for the host in a `grant.step` or `grant.revoked` that no live grant holds. Another business's line and an unrecorded `mosaic-` line stay. Writes `grant.host.swept {host,removed,left}`; `hostLineLeft` then counts from it. Returns `{host,removed,hostLineLeft}`. |
Each of the three leaves one receipt in the organization's `changes.jsonl`: the actor and a
`detail` of `{verb,agent,kind,date or reason}`, never a value. A change to the store alone writes
+31 -467
View File
@@ -221,23 +221,11 @@ export function writeGrantEvent(store, at, business, body, subject = null) {
);
return eid;
}
export const HOSTS_VERBS = Object.freeze(['hosts.status', 'hosts.check', 'hosts.remove', 'hosts.revoke', 'hosts.sweep']);
export const HOSTS_VERBS = Object.freeze(['hosts.status', 'hosts.check', 'hosts.remove']);
// The OpenSSH fingerprint of a "<type> <base64>" host key line. host-grant.mjs has the same; the broker
// doesn't import it, so the sandbox's RUNNER_FILES stay as they are.
const fingerprintOf = (line) =>
'SHA256:' + createHash('sha256').update(Buffer.from(line.split(' ')[1], 'base64')).digest('base64').replace(/=+$/, '');
// Row 234 (#1740, r6 E1): an enrollment's raise binding. The human sees each scanned key with its
// fingerprint, and the sudo mark in plain words.
const enrollBinding = (enroll) => ({
body: enroll,
block:
`\n\nEnroll host ${enroll.host}: user ${enroll.user} at ${enroll.address} port ${enroll.port}.` +
`\nHost keys from ssh-keyscan, equal to the requested fingerprints:` +
enroll.hostKeys.map((k) => `\n${fingerprintOf(k)} ${k}`).join('') +
(enroll.sudo
? `\n${enroll.user} has sudo on this host. Approving lets later grants for ${enroll.user} be installed, and section 9's first limit applies to ${enroll.user}.`
: `\n${enroll.user} has no sudo on this host.`),
});
// r6 E3: the installer line's comment, then the tag's 32 hex digits.
const INSTALLER_COMMENT = 'mosaic-installer-';
// Row 121 (#1615): an instance of THREAD_DEFINITION (vocabulary.mjs since row 155) talks with the
@@ -284,17 +272,11 @@ export class Broker {
#harnessOn;
// Row 234 (#1740): the trusted enrollment half (host-grant.mjs), or null where hosts are off.
#hostGrant;
// Row 235 (#1741, r6 X2 to X5): grantKeys from host-grant.mjs, the executor's calls on Credentials, or null.
#hostKeys;
// r6 X3: interrupted host grants whose remote undo waits for reconcileHosts, each with its claim.
#hostUndo = [];
// r6 section 6 (N4): revokes a restart cut short, whose step 3 waits for reconcileHosts.
#revokeUndo = [];
// Row 125 (#1619, REQ-LIMIT-4): a run a limit stops, by business:run, until its next receive or state.
#stops = new Map();
#clock = 0;
// credentialStatus is the runtime's metadata-only Credentials.status(); the broker never gets use().
constructor({ store, businesses, secretCheck = () => {}, credentialStatus = () => [], organization = null, project = null, usage = null, limits = null, harnessOn = null, credentialVerbs = null, hostGrant = null, hostKeys = null }) {
constructor({ store, businesses, secretCheck = () => {}, credentialStatus = () => [], organization = null, project = null, usage = null, limits = null, harnessOn = null, credentialVerbs = null, hostGrant = null }) {
if (!object(businesses) || !Object.keys(businesses).length) fail('invalid-business');
this.#businesses = structuredClone(businesses);
this.#store = store;
@@ -304,7 +286,6 @@ export class Broker {
// Row 199: the runtime's credential lifecycle (credential-verbs.mjs); it holds the store, not the broker.
this.#credentialVerbs = credentialVerbs;
this.#hostGrant = hostGrant;
this.#hostKeys = hostKeys;
this.#project = project;
this.#usage = usage;
this.#limits = limits;
@@ -709,9 +690,6 @@ export class Broker {
// decision is a credential.mint with a `host` grant, resolved yes by the human via cli and spent by
// #consumeGrant as grant.host. Read at each call, so a grant, a revoke and a hosts.remove need no reload.
#hostAccess(s, host) {
// mos-1164 (sage-1908): a creative role has no path to host.run, even through a record written before
// its instance became creative. The record stays, so hosts.revoke still finds it.
if (CREATIVE_DEFINITIONS.includes(this.#business(s.business).roles[s.role]?.definition)) fail('host-creative-role');
const r = this.#hostRecord(s.business, host);
if (!r) fail('host-unknown');
const g = this.#store.get('SELECT * FROM host_grants WHERE business=? AND agent=? AND host=?', s.business, s.role, host);
@@ -840,198 +818,6 @@ export class Broker {
return code;
}
}
// Row 235 (#1741, r6 X2): a host grant's end, in the caller's transaction. The tag is listed every time,
// so sweep and status can match a line left on the host.
#hostGrantFailed(business, decision, g, code, extra = {}) {
const tag = this.#hostGrant?.grantTag(business, g.agent, g.host) ?? null;
this.#grantEvent(business, { action: 'grant.failed', grantDecision: decision, agent: g.agent, host: g.host, code, tag, ...extra }, g.host);
this.#grantNotice(
business,
decision,
`Grant of host ${g.host} to ${g.agent} (decision ${decision}) failed: ${code}.` +
(extra.hostLineLeft ? ` A line tagged ${extra.hostLineLeft} may be left on the host. Run: mosaic hosts sweep ${g.host}` : ''),
);
}
// r6 R1: the agent's definition, if the agent is a role of the business and the definition declares host.
// mos-1163: a creative role gets no host grant, whatever its definition declares. The raise binding and
// the step 1 recheck both come here.
#hostDefinition(business, agent) {
const b = this.#business(business);
if (!Object.hasOwn(b.roles, agent)) fail('unknown-role');
const name = b.roles[agent].definition;
if (CREATIVE_DEFINITIONS.includes(name)) fail('host-creative-role');
const definition = Object.hasOwn(b.definitions ?? {}, name) ? b.definitions[name] : null;
if (!definition?.credentials?.some((c) => c.service === 'host')) fail('host-not-declared');
return definition;
}
// r6 X2 step 1, X5: a grant.revoked of (agent, host) recorded after the decision's raise.
#revokedSince(business, decision, agent, host) {
return Boolean(
this.#store.get(
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoked' AND json_extract(body,'$.agent')=? AND json_extract(body,'$.host')=? AND seq > (SELECT seq FROM events WHERE business=? AND kind='action.allowed' AND json_extract(body,'$.operation')='decision.raise' AND json_extract(body,'$.decision')=? ORDER BY seq LIMIT 1) LIMIT 1`,
business, agent, host, business, decision,
),
);
}
// r6 X2 step 1's checks after the spend, R4's binding again. Throws the code that ends the grant.
#hostGrantRecheck(business, decision, g) {
if (!this.#hostGrant || !this.#hostKeys) fail('host-not-configured');
const definition = this.#hostDefinition(business, g.agent);
if (this.#hostGrant.definitionSha256(definition) !== g.definitionSha256) fail('decision-mismatch');
const r = this.#hostRecord(business, g.host);
if (!r) fail('host-unknown');
if (registrySha256(r) !== g.registrySha256) fail('decision-mismatch');
if (r.state !== 'ready') fail('host-not-ready');
if (sha256(JSON.stringify(g.commands)) !== g.commandsSha256) fail('decision-mismatch');
if (this.#revokedSince(business, decision, g.agent, g.host)) fail('revoked');
return r;
}
// Trusted host API, as runEnrollment is, and no verb reaches it: the grant executor's entry for one
// decision. A second start ends decision-consumed with nothing written (r6 G10).
runHostGrant(business, decision) {
return this.#runHostGrant(business, decision);
}
// r6 X2, started by the human's cli yes. Never throws: the outcome is in the store and the notices, and
// the return value is 'applied' or the code grant.failed records. Every host_grants write shares its
// transaction with grant.applied (sage-1745).
async #runHostGrant(business, decision) {
let start;
try {
// Step 1, one transaction: the spend, then R4's checks again. A failed check still spends.
start = this.#store.transaction(() => {
const g = this.#consumeGrant(business, decision, 'host');
let record;
try {
record = this.#hostGrantRecheck(business, decision, g);
} catch (e) {
if (!(e instanceof BusError)) throw e;
this.#hostGrantFailed(business, decision, g, e.code);
return { g, code: e.code };
}
const live = this.#store.get('SELECT commands FROM host_grants WHERE business=? AND agent=? AND host=?', business, g.agent, g.host);
return { g, record, previous: live ? JSON.parse(live.commands) : null };
});
} catch (e) {
// Spent, not approved or no store: nothing was written. The start reconcile ends a resolved,
// unspent decision.
return e instanceof BusError ? e.code : 'host-failed';
}
if (start.code) return start.code;
const { g, record, previous } = start;
// Right after the commit, with no await between, so no revoke or host.run falls in between (X2).
let signal;
try {
signal = this.#hostKeys.claim(business, g.agent, g.host);
} catch (e) {
const code = e instanceof BusError ? e.code : 'host-failed';
try {
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, code));
} catch {}
return code;
}
const tag = this.#hostGrant.grantTag(business, g.agent, g.host);
const change = previous !== null;
const step = (name, extra = {}) =>
this.#store.transaction(() =>
this.#grantEvent(business, { action: 'grant.step', grantDecision: decision, agent: g.agent, host: g.host, user: record.user, tag, step: name, ...extra }, g.host),
);
// X5: checked after each await. A revoke during steps 2 to 5 ends the grant revoked.
const stop = () => {
if (signal.aborted) fail('revoked');
};
let installing = false,
installed = false,
registered = false,
committed = false;
try {
let key = null;
if (!change) {
// Step 2. A commands change keeps its key and line and skips to step 5.
key = await this.#hostGrant.grantKey(tag);
stop();
// Steps 3 and 4.
step('install');
installing = true;
await this.#hostGrant.install(business, g.host, record, tag, key.publicLine, signal);
installed = true;
stop();
await this.#hostGrant.verify(g.host, record, key, signal);
stop();
}
// Step 5. Nothing from the abort check to the end of commit awaits (X5, N2).
step('commit', { previous });
stop();
const applied = () => {
this.#grantEvent(
business,
{ action: 'grant.applied', grantDecision: decision, agent: g.agent, host: g.host, user: record.user, tag, fingerprint: key?.fingerprint ?? null, commandsSha256: g.commandsSha256 },
g.host,
);
this.#grantNotice(
business,
decision,
change
? `The commands of ${g.agent}'s grant on host ${g.host} changed (decision ${decision}).`
: `${g.agent} has access to host ${g.host} as ${record.user} (decision ${decision}), tag ${tag}.`,
);
};
if (change) {
this.#store.transaction(() => {
const out = this.#store.run(
'UPDATE host_grants SET commands=?, decision=? WHERE business=? AND agent=? AND host=?',
JSON.stringify(g.commands), decision, business, g.agent, g.host,
);
if (out.changes !== 1) fail('host-changed');
applied();
});
committed = true;
} else {
this.#hostKeys.register(business, g.agent, g.host, g.rotateBy);
registered = true;
this.#hostKeys.issue(business, g.agent, g.host, key.text, g.rotateBy, () => {
this.#store.transaction(() => {
this.#store.run(
'INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES(?,?,?,?,?,?,?)',
business, g.agent, g.host, JSON.stringify(g.commands), g.rotateBy, tag, decision,
);
applied();
});
committed = true;
});
}
return 'applied';
} catch (e) {
// Once the record and grant.applied commit, an abort is an ordinary revoke's to handle (C1).
if (committed) return 'applied';
const code = signal.aborted ? 'revoked' : e instanceof BusError ? e.code : 'host-failed';
// X3's table: a key file and its reference go, then the line, best effort.
if (registered) {
try {
this.#hostKeys.revoke(business, g.agent, g.host);
} catch {}
try {
this.#hostKeys.unregister(business, g.agent, g.host);
} catch {}
}
let extra = {};
if (installing) {
try {
await this.#hostGrant.remove(business, g.host, record, tag);
} catch {
extra = { hostLineLeft: tag };
}
// An abort or a timeout kills only the local ssh, so an add that hasn't returned may still write
// its line after the remove has run. Only install returning proves it ended (row 249).
if (!installed) extra = { hostLineLeft: tag };
}
try {
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, code, extra));
} catch {}
return code;
} finally {
this.#hostKeys.release(business, g.agent, g.host, signal);
}
}
// r6 X3 and duckworth-0067 N1: credential.mint decisions for `method`, resolved yes by the human via
// cli and never spent.
#openGrantDecisions(business, method) {
@@ -1073,190 +859,23 @@ export class Broker {
});
ended.push(decision);
}
// Row 235 (r6 X3): a host grant spent with no grant.applied or grant.failed died mid-executor. The
// record and grant.applied commit in one transaction (X2 step 5), so no record names it and the
// start sweep has unlinked any key file it wrote. A last step of install, or commit for a new key,
// may have left a line: the slot is claimed here, before anyone can call, and reconcileHosts
// removes the line. Any other ends interrupted now.
const hostSpent = this.#store.all(
`SELECT json_extract(body,'$.decision') AS decision FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.operation')='grant.host' ORDER BY seq`,
business,
);
for (const { decision } of hostSpent) {
const end = this.#store.get(
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.grantDecision')=? AND json_extract(body,'$.action') IN ('grant.applied','grant.failed') LIMIT 1`,
business,
decision,
);
if (end) continue;
const g = this.#raised(business, decision).grant;
const last = this.#store.get(
`SELECT body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.grantDecision')=? AND json_extract(body,'$.action')='grant.step' ORDER BY seq DESC LIMIT 1`,
business,
decision,
);
const step = last ? JSON.parse(last.body) : null;
if (step && (step.step === 'install' || (step.step === 'commit' && step.previous === null))) {
let signal = null;
try {
signal = this.#hostKeys.claim(business, g.agent, g.host);
} catch {}
this.#hostUndo.push({ business, decision, g, user: step.user, tag: step.tag, signal });
continue;
}
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, 'interrupted'));
ended.push(decision);
}
for (const decision of this.#openGrantDecisions(business, 'host')) {
this.#store.transaction(() => this.#hostGrantFailed(business, decision, this.#consumeGrant(business, decision, 'host'), 'interrupted'));
ended.push(decision);
}
// r6 section 6 (N4): a grant.revoked still pending has done step 1 and maybe step 2. The record is
// gone, so the start sweep took any key file left. reconcileHosts runs step 3.
for (const m of this.#openRevokes(business)) this.#revokeUndo.push({ business, ...m });
}
return ended;
}
// Trusted host API, after the socket opens (r6 X3): the remote undo of each grant reconcileGrants left
// claimed. `remove <user> <tag>` through the installer, then grant.failed interrupted, with
// hostLineLeft if the remove failed, and the claim released. It only takes access away, so it needs no
// decision. Never throws, and returns the decisions it ended.
async reconcileHosts() {
const ended = [];
for (const u of this.#hostUndo.splice(0)) {
let extra = {};
try {
const record = this.#hostRecord(u.business, u.g.host);
if (!record || !this.#hostGrant || !u.signal) fail('host-failed');
await this.#hostGrant.remove(u.business, u.g.host, { ...record, user: u.user }, u.tag);
} catch {
extra = { hostLineLeft: u.tag };
}
try {
this.#store.transaction(() => this.#hostGrantFailed(u.business, u.decision, u.g, 'interrupted', extra));
ended.push(u.decision);
} catch {}
try {
if (u.signal) this.#hostKeys.release(u.business, u.g.agent, u.g.host, u.signal);
} catch {}
}
for (const m of this.#revokeUndo.splice(0)) {
try {
await this.#closeRevoke(m.business, m);
ended.push(m.revoke);
} catch {}
}
return ended;
}
// The grant.revoked bodies still pending, with no grant.revoke.closed of the same revoke id. A body
// with no revoke id predates row 235 and has no step 3.
#openRevokes(business, host = null) {
return this.#store
.all(
`SELECT body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoked' AND json_extract(body,'$.hostLine')='pending' AND json_type(body,'$.revoke')='text' AND (? IS NULL OR json_extract(body,'$.host')=?) ORDER BY seq`,
business,
host,
host,
)
.map((e) => JSON.parse(e.body))
.filter(
(m) =>
!this.#store.get(
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoke.closed' AND json_extract(body,'$.revoke')=? LIMIT 1`,
business,
m.revoke,
),
);
}
// r6 section 6 step 3: `remove <user> <tag>` through the installer, then grant.revoke.closed, with
// hostLineLeft if the host can't be reached or has no record. The user is the host record's, as the
// executor's. Returns the closed body.
async #closeRevoke(business, m) {
let line = { hostLine: 'removed' };
try {
const record = this.#hostRecord(business, m.host);
if (!record || !this.#hostGrant) fail('host-failed');
await this.#hostGrant.remove(business, m.host, record, m.tag);
} catch {
line = { hostLineLeft: m.tag };
}
const body = { action: 'grant.revoke.closed', revoke: m.revoke, agent: m.agent, host: m.host, tag: m.tag, ...line, by: m.by };
this.#store.transaction(() => this.#grantEvent(business, body, m.host));
return body;
}
// r6 section 6: local first, so the part that matters can't wait on the network. Step 1 is one
// transaction: the record goes, if there is one, and grant.revoked records the pending marker. The tag
// is computed, so a revoke with no record still names the line (N4). Step 2 follows with no await
// between: the key leaves memory, its file goes, and a host.run or executor in flight aborts (X5).
// Step 3 removes the line.
async #revokeHost(s, a, by) {
keys(a, ['agent', 'host', 'reason'], ['agent', 'host', 'reason']);
if (typeof a.agent !== 'string' || !ID_PATTERN.test(a.agent) || typeof a.host !== 'string' || !HOST_ID.test(a.host)) fail('invalid-request');
string(a.reason, 500);
if (!this.#hostGrant) fail('host-not-configured');
const tag = this.#hostGrant.grantTag(s.business, a.agent, a.host);
const revoke = randomUUID();
const granted = this.#store.transaction(() => {
if (!this.#hostRecord(s.business, a.host)) fail('host-unknown');
const out = this.#store.run('DELETE FROM host_grants WHERE business=? AND agent=? AND host=?', s.business, a.agent, a.host);
this.#grantEvent(
s.business,
{ action: 'grant.revoked', revoke, agent: a.agent, host: a.host, tag, hostLine: 'pending', granted: out.changes === 1, reason: a.reason, by },
a.host,
);
return out.changes === 1;
});
let keyFile = 'removed';
if (this.#hostKeys) {
try {
this.#hostKeys.revoke(s.business, a.agent, a.host);
} catch (e) {
// No reference: only a claim can be held, an executor's before its register.
if (e instanceof BusError && e.code === 'credential-unknown') this.#hostKeys.abortClaim(s.business, a.agent, a.host);
else keyFile = 'left';
}
}
const closed = await this.#closeRevoke(s.business, { revoke, agent: a.agent, host: a.host, tag, by });
return { agent: a.agent, host: a.host, tag, granted, keyFile, ...(closed.hostLineLeft ? { hostLineLeft: closed.hostLineLeft } : { hostLine: 'removed' }) };
}
// r6 X3 sweep (B4): the tags this business recorded on the host, from grant.step and grant.revoked,
// less those of live grants.
#sweepTags(business, host) {
const tags = new Set(
this.#store
.all(
`SELECT json_extract(body,'$.tag') AS tag FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.host')=? AND json_extract(body,'$.action') IN ('grant.step','grant.revoked') AND json_type(body,'$.tag')='text'`,
business,
host,
)
.map((e) => e.tag),
);
for (const { tag } of this.#store.all('SELECT tag FROM host_grants WHERE business=? AND host=?', business, host)) tags.delete(tag);
return tags;
}
// r6 E1, R3: the raise checks and the keyscan, then the raise transaction. Row 235 (#1741, r6 R4): a
// host grant has no keyscan, so its store checks all run inside the raise transaction.
// r6 E1, R3: the raise checks and the keyscan, then the raise transaction.
async #raiseGrant(s, a) {
try {
this.#store.transaction(() => this.#agent(s));
if (a.action !== 'credential.mint' || 'spec_path' in a || 'spec_commit' in a) fail('invalid-request');
if (this.#business(s.business).roles[s.role]?.definition !== STAFF_TO) fail('grant-chief-only');
if (!this.#hostGrant) fail('host-not-configured');
if (a.grant?.method === 'host') {
const g = this.#hostGrant.hostGrantCheck(a.grant, this.#now().slice(0, 10));
return this.#store.transaction(() => {
const result = this.#dispatch(s, 'decision.raise', a, null, this.#hostGrantBinding(s.business, g));
this.#secretCheck(result);
return result;
});
}
const enroll = this.#hostGrant.enrollCheck(a.grant);
if (this.#hostRecord(s.business, enroll.host)) fail('host-enrolled');
const hostKeys = await this.#hostGrant.keyscan(enroll.address, enroll.port);
if (!this.#hostGrant.sameFingerprints(hostKeys, enroll.fingerprints)) fail('host-key-mismatch');
return this.#store.transaction(() => {
if (this.#hostRecord(s.business, enroll.host)) fail('host-enrolled');
const result = this.#dispatch(s, 'decision.raise', a, null, enrollBinding({ ...enroll, hostKeys }));
const result = this.#dispatch(s, 'decision.raise', a, null, { ...enroll, hostKeys });
this.#secretCheck(result);
return result;
});
@@ -1264,62 +883,20 @@ export class Broker {
throw this.#refused(s, e, { verb: 'decision.raise', args: a });
}
}
// r6 R4: a host grant's store checks and its raise binding. The caller owns the transaction. The body
// is R4's eight fields. The block shows the human the host as enrolled, each prefix and whether the
// key is new, and the chief can't shape it.
#hostGrantBinding(business, g) {
const definition = this.#hostDefinition(business, g.agent);
const h = this.#hostRecord(business, g.host);
if (!h) fail('host-unknown');
if (h.state !== 'ready') fail('host-not-ready');
const live = this.#store.get('SELECT 1 FROM host_grants WHERE business=? AND agent=? AND host=?', business, g.agent, g.host);
const body = {
method: 'host',
agent: g.agent,
host: g.host,
commands: g.commands,
commandsSha256: sha256(JSON.stringify(g.commands)),
rotateBy: g.rotateBy,
registrySha256: registrySha256(h),
definitionSha256: this.#hostGrant.definitionSha256(definition),
};
const block =
`\n\nGrant ${g.agent} access to host ${g.host}: user ${h.user} at ${h.address} port ${h.port}.` +
(h.sudo ? `\n${h.user} has sudo on this host.` : `\n${h.user} has no sudo on this host.`) +
`\nCommands, each an argv prefix:` +
g.commands.map((prefix) => `\n${prefix.map((x) => JSON.stringify(x)).join(' ')}`).join('') +
`\nRotate by ${g.rotateBy}.` +
(live
? `\nThis changes the commands of ${g.agent}'s grant on ${g.host}. The key stays.`
: `\nThis makes a new key for ${g.agent} on ${g.host}.`);
return { body, block };
}
#hostsCaller(s, verb) {
if (s.reader) fail('read-only');
if (s.tester) {
// r6 section 6 (N8): a tester revoke needs bus.tester exactly true on the session's business, read
// again here. Missing or any other value isn't dev.
if (verb === 'hosts.revoke' && this.#business(s.business).vars?.['bus.tester'] !== true) fail('tester-dev-only');
return 'tester';
}
if (s.tester) return 'tester';
if (s.human) {
this.#human(s);
return s.human;
}
// hosts.remove and hosts.sweep take access away, as a revoke does: the human or the tester (r6 E4, X3).
if (verb === 'hosts.remove' || verb === 'hosts.sweep') fail('human-required');
// hosts.remove takes access away, as a revoke does: the human or the tester (r6 E4).
if (verb === 'hosts.remove') fail('human-required');
this.#store.transaction(() => this.#agent(s));
// r6 section 6 (G26): the assistant revokes in its own business. The verb acts on the session's
// business only, so another business's grant can't be named.
if (verb === 'hosts.revoke') {
if (!this.#threaded(s.business, s.role)) fail('revoke-refused');
return s.role;
}
if (this.#business(s.business).roles[s.role]?.definition !== STAFF_TO) fail('grant-chief-only');
return s.role;
}
// r6 E4: hosts.status, hosts.check and hosts.remove. Async, because check runs ssh. Row 235 adds
// hosts.revoke and hosts.sweep (r6 section 6, X3).
// r6 E4: hosts.status, hosts.check and hosts.remove. Async, because check runs ssh.
async #requestHosts(s, verb, a) {
try {
const by = this.#hostsCaller(s, verb);
@@ -1340,25 +917,12 @@ export class Broker {
installerFingerprint: r.installer_fingerprint,
checkedAt: r.checked_at,
hostLineLeft: this.#hostLinesLeft(s.business, host),
// r6 section 6: the tags of revokes still in progress.
revoking: this.#openRevokes(s.business, host).map((m) => m.tag),
};
});
}
if (verb === 'hosts.revoke') return await this.#revokeHost(s, a, by);
keys(a, ['host'], ['host']);
if (typeof a.host !== 'string' || !HOST_ID.test(a.host)) fail('invalid-request');
if (!this.#hostGrant) fail('host-not-configured');
if (verb === 'hosts.sweep') {
const r = this.#hostRecord(s.business, a.host);
if (!r) fail('host-unknown');
const left = this.#hostLinesLeft(s.business, a.host);
const { listed, removed } = await this.#hostGrant.sweep(s.business, a.host, r, this.#sweepTags(s.business, a.host));
// A left tag still listed and not removed stays left.
const still = left.filter((tag) => listed.includes(tag) && !removed.includes(tag));
this.#store.transaction(() => this.#grantEvent(s.business, { action: 'grant.host.swept', host: a.host, removed, left: still, by }, a.host));
return { host: a.host, removed, hostLineLeft: still };
}
if (verb === 'hosts.remove') {
return this.#store.transaction(() => {
const r = this.#hostRecord(s.business, a.host);
@@ -1396,23 +960,15 @@ export class Broker {
}
}
// r6 E4, duckworth-0079 F2 and F3: every guarded body that left a line on the host names the host.
// Row 235 adds the sweep clear (F4): the last grant.host.swept carries what it left, and only later
// bodies add to it.
// Row b adds the sweep clear (F4).
#hostLinesLeft(business, host) {
const swept = this.#store.get(
`SELECT seq, body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.host.swept' AND json_extract(body,'$.host')=? ORDER BY seq DESC LIMIT 1`,
business,
host,
);
const left = swept ? JSON.parse(swept.body).left : [];
for (const e of this.#store.all(
`SELECT json_extract(body,'$.hostLineLeft') AS tag FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.host')=? AND json_extract(body,'$.hostLineLeft') IS NOT NULL AND seq > ? ORDER BY seq`,
business,
host,
swept?.seq ?? 0,
))
if (!left.includes(e.tag)) left.push(e.tag);
return left;
return this.#store
.all(
`SELECT json_extract(body,'$.hostLineLeft') AS tag FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.host')=? AND json_extract(body,'$.hostLineLeft') IS NOT NULL ORDER BY seq`,
business,
host,
)
.map((e) => e.tag);
}
#hardWait(s, action, target) {
if (GATED.has(action)) return true;
@@ -2606,7 +2162,7 @@ export class Broker {
});
return out;
}
#dispatch(s, verb, a, spec = null, binding = null) {
#dispatch(s, verb, a, spec = null, enroll = null) {
const b = this.#business(s.business),
by = s.human || s.run;
switch (verb) {
@@ -2715,8 +2271,8 @@ export class Broker {
],
['action', 'question', 'options', 'recommendation', 'blocking'],
);
// Only #raiseGrant passes `binding`, after its checks.
if (('grant' in a) !== (binding !== null)) fail('invalid-request');
// Only #raiseGrant passes `enroll`, after its checks and keyscan.
if (('grant' in a) !== (enroll !== null)) fail('invalid-request');
this.#agent(s);
if ((a.spec_path !== undefined || a.spec_commit !== undefined) && !spec) fail('invalid-spec-citation');
const cls = this.#classification(s, a.action, a.target);
@@ -2789,8 +2345,17 @@ export class Broker {
`\nargv: ${a.argv.map((x) => JSON.stringify(x)).join(' ')}` +
`\nstdin: ${JSON.stringify(a.stdin ?? '')}`;
}
// Rows 234 and 235: the grant's block, built by the broker. The chief can't shape it.
if (binding) question += binding.block;
// Row 234 (#1740, r6 E1): the human sees each scanned key with its fingerprint, and the sudo
// mark in plain words. The chief can't shape this block.
if (enroll) {
question +=
`\n\nEnroll host ${enroll.host}: user ${enroll.user} at ${enroll.address} port ${enroll.port}.` +
`\nHost keys from ssh-keyscan, equal to the requested fingerprints:` +
enroll.hostKeys.map((k) => `\n${fingerprintOf(k)} ${k}`).join('') +
(enroll.sudo
? `\n${enroll.user} has sudo on this host. Approving lets later grants for ${enroll.user} be installed, and section 9's first limit applies to ${enroll.user}.`
: `\n${enroll.user} has no sudo on this host.`);
}
string(question);
const did = randomUUID();
this.#store.run(
@@ -2828,7 +2393,7 @@ export class Broker {
a.action === 'role.revoke' ? (this.#holder(s.business, a.target)?.holder_run ?? null) : null,
...(pushCommit ? { pushCommit } : {}),
...(sudo ? { hostRun: hostRun(a.target, a.argv, a.stdin) } : {}),
...(binding ? { grant: binding.body } : {}),
...(enroll ? { grant: enroll } : {}),
},
a.task_ref ?? (taskRef(a.target) ? a.target : did),
);
@@ -2883,7 +2448,6 @@ export class Broker {
// transaction commits. It rechecks all of this itself, so a rollback starts nothing.
const grant = op === 'resolved' ? this.#approvedGrant(s.business, d.id) : null;
if (grant?.method === 'host-enroll') setImmediate(() => this.#runEnrollment(s.business, d.id));
if (grant?.method === 'host') setImmediate(() => this.#runHostGrant(s.business, d.id));
if (s.human)
this.#event(
s,
+14 -56
View File
@@ -13,7 +13,7 @@ const inside = (root, path) => {
const r = relative(root, path);
return r === '' || (!r.startsWith('..') && !isAbsolute(r));
};
export const day = (value) =>
const day = (value) =>
typeof value === 'string' &&
/^\d{4}-\d{2}-\d{2}$/.test(value) &&
!Number.isNaN(Date.parse(value)) &&
@@ -128,7 +128,19 @@ export class Credentials {
try {
for (const [instance, services] of Object.entries(references))
for (const [service, ref] of Object.entries(services)) {
const date = this.#checkRef(instance, service, ref);
if (!credentialKind(service) || !ref || typeof ref !== 'object')
deny('credential-reference');
const date = service === 'vikunja' ? ref.expires : ref.rotateBy;
if (!day(date)) deny('credential-date');
if (
(ref.service !== undefined && ref.service !== service) ||
Object.keys(ref).some(
(k) => !['service', 'file', 'env', 'store', service === 'vikunja' ? 'expires' : 'rotateBy'].includes(k),
) ||
Boolean(ref.file) === Boolean(ref.env) ||
(ref.store !== undefined && (ref.store !== true || ref.file !== this.#storePath(instance, service)))
)
deny('credential-reference');
this.#refs.set(instance + ':' + service, { ref, date });
const value = this.#read(ref, env, service);
if (value !== null) this.#tokens.set(instance + ':' + service, { ...value, date });
@@ -138,60 +150,6 @@ export class Credentials {
throw e;
}
}
// One reference's checks, for the constructor and register (row 235, r6 X4). Returns its date.
#checkRef(instance, service, ref) {
if (!credentialKind(service) || !ref || typeof ref !== 'object') deny('credential-reference');
const date = service === 'vikunja' ? ref.expires : ref.rotateBy;
if (!day(date)) deny('credential-date');
if (
(ref.service !== undefined && ref.service !== service) ||
Object.keys(ref).some(
(k) => !['service', 'file', 'env', 'store', service === 'vikunja' ? 'expires' : 'rotateBy'].includes(k),
) ||
Boolean(ref.file) === Boolean(ref.env) ||
(ref.store !== undefined && (ref.store !== true || ref.file !== this.#storePath(instance, service)))
)
deny('credential-reference');
return date;
}
// Row 235 (#1741, r6 X4): the grant executor adds a reference before `issue`, which refuses an unknown
// one. It reads no file, so a key file a failed revoke left can't come back. An entry with a live
// token refuses, and an entry with none, revoked or never issued, is replaced.
register(instance, service, ref) {
const k = instance + ':' + service;
if (this.#tokens.has(k)) deny('credential-reference');
const date = this.#checkRef(instance, service, ref);
this.#refs.set(k, { ref, date });
this.#revoked.delete(k);
}
// r6 X3, X4: the executor's undo for a reference it registered. An entry with a live token refuses.
unregister(instance, service) {
const k = instance + ':' + service;
if (this.#tokens.has(k)) deny('credential-reference');
this.#refs.delete(k);
this.#revoked.delete(k);
}
// r6 X5: the executor holds the entry's #inflight slot for its steps, so a host.run refuses host-busy
// and revoke's abort() reaches the executor. A slot already held refuses host-busy. Returns the signal.
claim(instance, service) {
const k = instance + ':' + service;
if (this.#inflight.has(k)) deny('host-busy');
const controller = new AbortController();
this.#inflight.set(k, controller);
return controller.signal;
}
// Frees the slot only if `signal` is the claim's own, so a late release can't free a later claim.
release(instance, service, signal) {
const k = instance + ':' + service;
if (this.#inflight.get(k)?.signal === signal) this.#inflight.delete(k);
}
// r6 X5: hosts.revoke with no reference to revoke. Aborts a live claim or call and says whether there
// was one.
abortClaim(instance, service) {
const controller = this.#inflight.get(instance + ':' + service);
controller?.abort();
return { pending: Boolean(controller) };
}
#storePath(instance, service) {
if (!this.#storeRoot) deny('credential-reference');
const [business, agent, ...rest] = instance.split('/');
+8 -148
View File
@@ -1,25 +1,22 @@
// Row 234 (#1740, #436a row a): the trusted half of host enrollment, run in the bus child. The broker
// gets it as `hostGrant` and holds every store write. This module holds what touches the network or
// a key file: the raise's ssh-keyscan (E1), the installer key pair (E2 steps 2 and 3) and the installer's
// `list` for hosts.check (E4). Row 235 (#1741, #436 row b) adds the host grant raise binding (R4), the
// grant executor's remote steps (X2 steps 2 to 4 and the `remove` undo) and `grantKeys`, the broker's
// narrow handle on Credentials.
// `list` for hosts.check (E4).
//
// The installer key lives at <configDir>/secrets/hosts/<business>/<hostId>/installer, 0600 in 0700 dirs,
// written as 210's issue writes (tmp, fsync, rename). It is never read into an event or a message.
import { spawn } from 'node:child_process';
import { createHash } from 'node:crypto';
import {
closeSync, constants, fsyncSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync,
rmdirSync, unlinkSync, writeSync,
closeSync, constants, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, renameSync, rmSync, rmdirSync,
unlinkSync, writeSync,
} from 'node:fs';
import { dirname, join } from 'node:path';
import { BusError } from './broker.mjs';
import { day, parseHostKey, privateDir } from './credentials.mjs';
import { parseHostKey, privateDir } from './credentials.mjs';
import { runHost, HOST_LIMITS } from './host-run.mjs';
import { checkAddress, checkCommands, HOST_KEY, USER } from '../../business/src/hosts.mjs';
import { canonicalJson } from '../../business/src/util.mjs';
import { HOST_ID, ID_PATTERN } from '../../business/src/vocabulary.mjs';
import { checkAddress, HOST_KEY, USER } from '../../business/src/hosts.mjs';
import { HOST_ID } from '../../business/src/vocabulary.mjs';
const deny = (code) => {
throw new BusError(code);
@@ -71,86 +68,6 @@ export function enrollCheck(grant) {
return { method: 'host-enroll', host: grant.host, address: grant.address, port: grant.port, user: grant.user, sudo: grant.sudo, fingerprints: [...prints] };
}
// R4's binding for a host grant. Anything off refuses invalid-request. `today` is the bus clock's UTC
// day. rotateBy must be a real calendar day after it (210's day check, credentials.mjs; sage-1782). The
// broker checks the agent, its definition and the host inside the raise transaction. Returns a fresh
// object with only the bound keys.
export function hostGrantCheck(grant, today) {
const allowed = ['method', 'agent', 'host', 'commands', 'rotateBy'];
if (!grant || typeof grant !== 'object' || Array.isArray(grant)) deny('invalid-request');
const own = Object.keys(grant);
if (own.some((k) => !allowed.includes(k)) || allowed.some((k) => !own.includes(k))) deny('invalid-request');
if (grant.method !== 'host') deny('invalid-request');
if (typeof grant.agent !== 'string' || !ID_PATTERN.test(grant.agent)) deny('invalid-request');
if (typeof grant.host !== 'string' || !HOST_ID.test(grant.host)) deny('invalid-request');
let commands;
try {
commands = checkCommands(grant.commands, 'grant.commands');
} catch {
deny('invalid-request');
}
if (!day(grant.rotateBy) || grant.rotateBy <= today) deny('invalid-request');
return { method: 'host', agent: grant.agent, host: grant.host, commands, rotateBy: grant.rotateBy };
}
// R4's definitionSha256: sha256 over the canonical JSON of the definition the business loaded, since
// the broker doesn't read roles/ (sage-0590). A change to any field the loader keeps changes it.
export const definitionSha256 = (definition) => createHash('sha256').update(canonicalJson(definition)).digest('hex');
// r6 X4: the store reference for an agent's host.<id> key, as Credentials checks it. The runtime's start
// load and the executor's register both use it.
export const hostReference = (storeRoot, business, agent, hostId, rotateBy) => ({
store: true,
file: storeRoot ? join(storeRoot, business, agent, 'host.' + hostId) : null,
rotateBy,
});
// Row 235 (r6 X2 to X5): the grant executor's calls on Credentials, keyed by (business, agent, hostId).
// The broker gets this and never Credentials itself, so it still has no use().
export function grantKeys({ credentials, storeRoot }) {
const at = (business, agent) => business + '/' + agent;
const service = (hostId) => 'host.' + hostId;
return {
claim: (business, agent, hostId) => credentials.claim(at(business, agent), service(hostId)),
release: (business, agent, hostId, signal) => credentials.release(at(business, agent), service(hostId), signal),
abortClaim: (business, agent, hostId) => credentials.abortClaim(at(business, agent), service(hostId)),
register: (business, agent, hostId, rotateBy) =>
credentials.register(at(business, agent), service(hostId), hostReference(storeRoot, business, agent, hostId, rotateBy)),
unregister: (business, agent, hostId) => credentials.unregister(at(business, agent), service(hostId)),
issue: (business, agent, hostId, text, rotateBy, commit) => credentials.issue(at(business, agent), service(hostId), text, rotateBy, commit),
revoke: (business, agent, hostId) => credentials.revoke(at(business, agent), service(hostId)),
};
}
// r6 section 6 and N1 of duckworth-0063: at start, before Credentials loads, unlink each host.<id> key
// file in a loaded business's agent store that has no host_grants record. `granted` holds
// 'business/agent/hostId' for each record. A file an interrupted executor wrote before its commit, or one
// a revoke failed to unlink, goes here. No reference loads for a file with no record (X4), so nothing
// holds it. A store dir that isn't private refuses credential-file, as Credentials would.
export function sweepHostKeys(storeRoot, businesses, granted) {
const removed = [];
if (!storeRoot || !privateDir(storeRoot, { missing: true })) return removed;
for (const business of businesses) {
const dir = join(storeRoot, business);
if (!privateDir(dir, { missing: true })) continue;
for (const agent of readdirSync(dir)) {
const agentDir = join(dir, agent);
if (!lstatSync(agentDir).isDirectory()) continue;
privateDir(agentDir);
for (const name of readdirSync(agentDir)) {
const hostId = name.startsWith('host.') ? name.slice(5) : null;
if (!hostId || !HOST_ID.test(hostId) || granted.has(business + '/' + agent + '/' + hostId)) continue;
unlinkSync(join(agentDir, name));
removed.push({ instance: business + '/' + agent, service: name });
}
}
}
return removed;
}
// The tags in `list` output, one per line, the last field of each.
export const listedTags = (stdout) => stdout.split('\n').filter(Boolean).map((line) => line.trim().split(/\s+/).at(-1));
// The keyscan's output lines, "<host> <type> <base64>", as "<type> <base64>". Comment lines and any
// other type drop out. A key listed twice counts once.
export function scanLines(stdout) {
@@ -205,9 +122,7 @@ const run = (bin, args) =>
child.on('close', (code) => (code === 0 ? resolve() : reject(new BusError('host-failed'))));
});
// `installerUser` is the installer's login. Only the tests change it, because a scratch sshd can only
// log in as the test's own user.
export function hostGrant({ configDir, runRoot, limits = HOST_LIMITS, scan = keyscan, keygen = 'ssh-keygen', installerUser = INSTALLER_USER }) {
export function hostGrant({ configDir, runRoot, limits = HOST_LIMITS, scan = keyscan, keygen = 'ssh-keygen' }) {
const keyRoot = join(configDir, 'secrets', 'hosts');
const keyPath = (business, hostId) => join(keyRoot, business, hostId, 'installer');
const readKey = (business, hostId) => {
@@ -224,24 +139,11 @@ export function hostGrant({ configDir, runRoot, limits = HOST_LIMITS, scan = key
if (fd !== undefined) closeSync(fd);
}
};
// One installer request, `list`, `add` or `remove`, pinned to the record's host keys (E3).
const installer = (business, hostId, record, command, signal = null) => {
const key = readKey(business, hostId);
const entry = { address: record.address, port: record.port, user: installerUser, hostKeys: record.hostKeys };
return runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command, signal });
};
const ok = (out) => {
if (out.exit !== 0) deny('host-failed');
return out;
};
return {
enrollCheck,
hostGrantCheck,
definitionSha256,
sameFingerprints,
fingerprint,
installerTag,
grantTag,
keyscan: (address, port) => scan(address, port),
// E2 steps 2 and 3. Returns the public line and fingerprint; the private half only reaches the file.
async enroll(business, hostId) {
@@ -307,51 +209,9 @@ export function hostGrant({ configDir, runRoot, limits = HOST_LIMITS, scan = key
// pin refuses host-key-mismatch (runHost). Returns the installer fingerprint and the exit.
async check(business, hostId, record) {
const key = readKey(business, hostId);
const entry = { address: record.address, port: record.port, user: installerUser, hostKeys: record.hostKeys };
const entry = { address: record.address, port: record.port, user: INSTALLER_USER, hostKeys: record.hostKeys };
const out = await runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command: `list ${record.user}` });
return { installerFingerprint: key.fingerprint, exit: out.exit };
},
// X2 step 2: a new ed25519 pair with the tag as its comment, made in a 0700 dir under the run root
// and read back into memory. The dir goes before this returns, so no private half stays on disk.
async grantKey(tag) {
mkdirSync(runRoot, { recursive: true, mode: 0o700 });
privateDir(runRoot);
const dir = mkdtempSync(join(runRoot, 'h-'));
try {
await run(keygen, ['-q', '-t', 'ed25519', '-N', '', '-C', tag, '-f', join(dir, 'key')]);
return parseHostKey(readFileSync(join(dir, 'key'), 'utf8'));
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
// X2 step 3: `list`, `remove` the tag if it's there, then `add`. Any request that doesn't exit 0
// refuses host-failed. `signal` is the executor's claim, so a revoke stops the call.
async install(business, hostId, record, tag, publicLine, signal) {
const listed = ok(await installer(business, hostId, record, `list ${record.user}`, signal));
if (listedTags(listed.stdout).includes(tag)) ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`, signal));
ok(await installer(business, hostId, record, `add ${record.user} ${publicLine} ${tag}`, signal));
},
// X2 step 4: log in as the record's user with the new key and run `true`.
async verify(hostId, record, key, signal) {
const entry = { address: record.address, port: record.port, user: record.user, hostKeys: record.hostKeys };
ok(await runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command: 'true', signal }));
},
// X3's undo and sweep: `remove <user> <tag>`, with no signal, since it runs after an abort too.
async remove(business, hostId, record, tag) {
ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`));
},
// X3's sweep (B4): `list <user>`, then `remove` for each listed tag in `tags`. A line with any other
// tag stays, so another business's line and an unrecorded one are left alone. Returns the listed
// tags and the removed ones.
async sweep(business, hostId, record, tags) {
const listed = listedTags(ok(await installer(business, hostId, record, `list ${record.user}`)).stdout);
const removed = [];
for (const tag of listed) {
if (!tags.has(tag) || removed.includes(tag)) continue;
ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`));
removed.push(tag);
}
return { listed, removed };
},
};
}
+2 -12
View File
@@ -16,7 +16,7 @@ import { organizationWriter } from '../../business/src/organization.mjs';
import { credentialVerbs } from './credential-verbs.mjs';
import { webService } from './web.mjs';
import { hostExecutor, sweepRunDir } from './host-run.mjs';
import { grantKeys, hostGrant, hostReference, sweepHostKeys } from './host-grant.mjs';
import { hostGrant } from './host-grant.mjs';
import { verifyHuman } from './human.mjs';
import { createUsage } from './usage.mjs';
import { createLimits } from './limits.mjs';
@@ -100,16 +100,11 @@ export async function startBroker({
// Row 234 (#1740, r6 X4 third bullet): each host grant record gives its agent a store reference to
// host.<id>, so a restart finds the keys the grant executor wrote. The loader refuses host.<id> in a
// role's credentials, so these never meet a business-file reference.
const granted = new Set();
for (const g of store.all('SELECT business, agent, host, rotate_by FROM host_grants ORDER BY business, agent, host')) {
granted.add(g.business + '/' + g.agent + '/' + g.host);
if (!Object.hasOwn(businesses, g.business)) continue;
const refs = (references[g.business + '/' + g.agent] = { ...(references[g.business + '/' + g.agent] ?? {}) });
refs['host.' + g.host] = hostReference(storeRoot, g.business, g.agent, g.host, g.rotate_by);
refs['host.' + g.host] = { store: true, file: storeRoot ? join(storeRoot, g.business, g.agent, 'host.' + g.host) : null, rotateBy: g.rotate_by };
}
// Row 235 (r6 section 6, N1): a host.<id> key file with no record goes before Credentials loads.
for (const entry of sweepHostKeys(storeRoot, Object.keys(businesses), granted))
process.stderr.write(`hosts: ${JSON.stringify({ event: 'host-key-swept', ...entry })}\n`);
credentials = new Credentials({ references, repoRoots: protectedRoots, dataRoot, storeRoot });
// vikunja:19/305: the plug-in switch through the same human-only path as the limits: the verbs
// plugins and plugins.set, logged in changes.jsonl with the actor, a missing module refused.
@@ -130,8 +125,6 @@ export async function startBroker({
const runRoot = organization ? join(organization.dir, 'secrets', 'run') : null;
const broker = new Broker({
hostGrant: runRoot ? hostGrant({ configDir: organization.dir, runRoot }) : null,
// Row 235 (#1741, r6 X4, X5): the grant executor's claim, register and issue, never use().
hostKeys: storeRoot ? grantKeys({ credentials, storeRoot }) : null,
usage,
limits,
store,
@@ -229,9 +222,6 @@ export async function startBroker({
return broker.bindTester({ business });
},
});
// Row 235 (r6 X3): the remote undo of interrupted host grants, once the bus is up, so a start doesn't
// wait on the network.
broker.reconcileHosts();
// S6 launcher operations. The host decides capacity and the instance list; the broker
// authorizes role.launch and keeps the evidence, refusals included.
// A refusal is recorded against the caller, as request() records one.
@@ -1,152 +0,0 @@
// Row 235 (#1741, #436 row b, r6 X4, X5): the grant executor's Credentials calls. register and
// unregister add and drop one store reference in the running bus, and claim, release and abortClaim
// hold the (agent, host.<id>) slot that host.run and revoke share. Keys are made by ssh-keygen in a
// scratch root, and nothing connects to any host.
import test from 'node:test';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { Credentials } from '../src/credentials.mjs';
const AGENT = 'demo/ops';
const SERVICE = 'host.web1';
function setup(t) {
const root = mkdtempSync(join(tmpdir(), 'bus-claim-'));
t.after(() => rmSync(root, { recursive: true, force: true }));
const storeRoot = join(root, 'secrets', 'agents');
mkdirSync(storeRoot, { recursive: true, mode: 0o700 });
chmodSync(join(root, 'secrets'), 0o700);
const file = join(storeRoot, 'demo', 'ops', SERVICE);
const ref = { service: SERVICE, store: true, file, rotateBy: '2099-01-01' };
const key = (name) => {
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'test', '-f', join(root, name)]);
return readFileSync(join(root, name), 'utf8');
};
const c = new Credentials({ references: {}, storeRoot, repoRoots: [], dataRoot: '/nonexistent-data' });
t.after(() => c.close());
const state = () => c.status().find((e) => e.instance === AGENT && e.service === SERVICE)?.state;
const run = () => c.use(AGENT, SERVICE, async () => ({ ok: true }));
return { root, storeRoot, file, ref, key, c, state, run };
}
test('X4: register adds a store reference to the running bus, and issue then writes the key', async (t) => {
const s = setup(t);
assert.throws(() => s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01'), /credential-unknown/);
s.c.register(AGENT, SERVICE, s.ref);
assert.equal(s.state(), 'not-issued');
await assert.rejects(s.run(), /credential-unavailable/);
assert.equal(s.c.issue(AGENT, SERVICE, s.key('k2'), '2099-01-01').state, 'valid');
assert.deepEqual(await s.run(), { ok: true });
});
test('X4: register runs the constructor\'s reference checks', (t) => {
const s = setup(t);
const other = join(s.storeRoot, 'demo', 'pm', SERVICE);
for (const [ref, code] of [
[null, /credential-reference/],
[{ ...s.ref, rotateBy: '2099-02-30' }, /credential-date/],
[{ ...s.ref, file: other }, /credential-reference/],
[{ ...s.ref, extra: 1 }, /credential-reference/],
[{ ...s.ref, service: 'host.web2' }, /credential-reference/],
[{ ...s.ref, env: 'X' }, /credential-reference/],
])
assert.throws(() => s.c.register(AGENT, SERVICE, ref), code);
assert.throws(() => s.c.register(AGENT, 'nope', s.ref), /credential-reference/);
assert.throws(() => s.c.register('demo/@tester', SERVICE, { ...s.ref, file: join(s.storeRoot, 'demo', '@tester', SERVICE) }), /credential-reference/);
assert.equal(s.state(), undefined);
});
test('X4: register reads no file, so a key file left at the path stays unused, and a live token refuses', async (t) => {
const s = setup(t);
mkdirSync(join(s.storeRoot, 'demo', 'ops'), { recursive: true, mode: 0o700 });
writeFileSync(s.file, s.key('left'), { mode: 0o600 });
s.c.register(AGENT, SERVICE, s.ref);
assert.equal(s.state(), 'not-issued');
await assert.rejects(s.run(), /credential-unavailable/);
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
assert.throws(() => s.c.register(AGENT, SERVICE, s.ref), /credential-reference/);
assert.equal(s.state(), 'valid');
// A revoked entry has no token, so a new grant registers again.
s.c.revoke(AGENT, SERVICE);
assert.equal(s.state(), 'revoked');
s.c.register(AGENT, SERVICE, s.ref);
assert.equal(s.state(), 'not-issued');
});
test('X3, X4: unregister drops an entry with no token and refuses one with a live token', (t) => {
const s = setup(t);
s.c.unregister(AGENT, SERVICE);
s.c.register(AGENT, SERVICE, s.ref);
s.c.unregister(AGENT, SERVICE);
assert.equal(s.state(), undefined);
assert.throws(() => s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01'), /credential-unknown/);
s.c.register(AGENT, SERVICE, s.ref);
s.c.issue(AGENT, SERVICE, s.key('k2'), '2099-01-01');
assert.throws(() => s.c.unregister(AGENT, SERVICE), /credential-reference/);
assert.equal(s.state(), 'valid');
s.c.revoke(AGENT, SERVICE);
assert.equal(existsSync(s.file), false);
s.c.unregister(AGENT, SERVICE);
assert.equal(s.state(), undefined);
});
test('X5: a claim holds the slot, so a second claim and a host.run refuse host-busy until release', async (t) => {
const s = setup(t);
s.c.register(AGENT, SERVICE, s.ref);
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
const signal = s.c.claim(AGENT, SERVICE);
assert.equal(signal.aborted, false);
assert.equal(s.c.busy(AGENT, SERVICE), true);
assert.throws(() => s.c.claim(AGENT, SERVICE), /host-busy/);
await assert.rejects(s.run(), /host-busy/);
// A claim needs no reference: the executor claims before it registers a new key.
const other = s.c.claim('demo/pm', SERVICE);
s.c.release('demo/pm', SERVICE, other);
s.c.release(AGENT, SERVICE, signal);
assert.equal(s.c.busy(AGENT, SERVICE), false);
assert.deepEqual(await s.run(), { ok: true });
});
test('X5: a claim made while a host.run is in flight refuses host-busy', async (t) => {
const s = setup(t);
s.c.register(AGENT, SERVICE, s.ref);
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
let finish;
const running = s.c.use(AGENT, SERVICE, () => new Promise((r) => (finish = r)));
assert.throws(() => s.c.claim(AGENT, SERVICE), /host-busy/);
finish({ ok: true });
assert.deepEqual(await running, { ok: true });
s.c.release(AGENT, SERVICE, s.c.claim(AGENT, SERVICE));
});
test('X5: a stale release leaves a later claim in place', (t) => {
const s = setup(t);
const first = s.c.claim(AGENT, SERVICE);
s.c.release(AGENT, SERVICE, first);
const second = s.c.claim(AGENT, SERVICE);
s.c.release(AGENT, SERVICE, first);
s.c.release(AGENT, SERVICE);
assert.equal(s.c.busy(AGENT, SERVICE), true);
s.c.release(AGENT, SERVICE, second);
assert.equal(s.c.busy(AGENT, SERVICE), false);
});
test('X5: abortClaim aborts a live claim and says pending, and revoke\'s abort reaches a claim too', (t) => {
const s = setup(t);
assert.deepEqual(s.c.abortClaim(AGENT, SERVICE), { pending: false });
const signal = s.c.claim(AGENT, SERVICE);
assert.deepEqual(s.c.abortClaim(AGENT, SERVICE), { pending: true });
assert.equal(signal.aborted, true);
// The slot stays held until the executor releases it.
assert.equal(s.c.busy(AGENT, SERVICE), true);
s.c.release(AGENT, SERVICE, signal);
s.c.register(AGENT, SERVICE, s.ref);
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
const live = s.c.claim(AGENT, SERVICE);
s.c.revoke(AGENT, SERVICE);
assert.equal(live.aborted, true);
s.c.release(AGENT, SERVICE, live);
});
File diff suppressed because it is too large Load Diff
-228
View File
@@ -1,228 +0,0 @@
// Row 235 (#1741, #436 row b): the host grant raise (r6 R1-R4). A credential.mint raise whose `grant`
// has method `host` binds an agent, an enrolled host, argv prefixes and a rotate date. The host record
// comes from the fixture, and nothing here connects to any host.
import test from 'node:test';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { Broker, registrySha256 } from '../src/broker.mjs';
import { Store } from '../src/store.mjs';
import { hostGrant, definitionSha256 } from '../src/host-grant.mjs';
import { hostRecord, hostGrantRecord } from './host-fixtures.mjs';
import { canonicalJson } from '../../business/src/util.mjs';
const options = [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }];
const refusesWith = async (p, code) => assert.rejects(Promise.resolve().then(() => p), (e) => (assert.equal(e.code, code), true));
const dayFrom = (n) => new Date(Date.now() + n * 86400000).toISOString().slice(0, 10);
const ENTRY = { address: '192.0.2.10', port: 22, user: 'jarvis', hostKeys: ['ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHostKeyForTests'] };
const none = { authority: { withinRole: ['message.send'], crossRole: [] } };
const DEFINITIONS = {
'chief-of-staff': { roleVersion: 2, credentials: [] },
pm: { roleVersion: 2, credentials: [] },
ops: { roleVersion: 2, credentials: [{ service: 'gitea', scopes: ['read:repository'] }, { service: 'host' }] },
};
function setup(t) {
const root = mkdtempSync(join(tmpdir(), 'g235-'));
const store = new Store(root);
t.after(() => {
store.close();
rmSync(root, { recursive: true, force: true });
});
const configDir = join(root, 'config');
const business = {
id: 'demo',
human: 'jason',
arbiters: { technical: 'pm', delivery: 'pm' },
roles: {
chief: { definition: 'chief-of-staff', ...none },
pm: { definition: 'pm', ...none },
ops: { definition: 'ops', ...none },
odd: { definition: 'constructor', ...none },
// A creative role whose definition declares host, so only the creative check refuses it.
muse: { definition: 'research', ...none },
},
definitions: { ...structuredClone(DEFINITIONS), research: structuredClone(DEFINITIONS.ops) },
vars: { 'bus.tester': true },
};
const broker = new Broker({ store, businesses: { demo: business }, hostGrant: hostGrant({ configDir, runRoot: join(configDir, 'secrets', 'run') }) });
const caps = {};
for (const role of ['chief', 'pm']) {
caps[role] = broker.bindLaunch({ business: 'demo', role, run: role + '-run', harness: 'pi', address: role });
broker.request(caps[role], { verb: 'role.claim' });
}
caps.human = broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
caps.tester = broker.bindTester({ business: 'demo' });
hostRecord(store, { host: 'web1', entry: ENTRY });
const grant = (over = {}) => ({ method: 'host', agent: 'ops', host: 'web1', commands: [['systemctl', 'status']], rotateBy: dayFrom(30), ...over });
const call = (who, verb, args = {}) => broker.request(caps[who], { verb, args });
const raise = (over = {}, who = 'chief', extra = {}) =>
call(who, 'decision.raise', { action: 'credential.mint', question: 'Grant ops web1?', options, recommendation: 'yes', blocking: false, grant: grant(over), ...extra });
const decisions = () => store.get('SELECT count(*) AS n FROM decisions').n;
const question = (id) => store.get('SELECT question FROM decisions WHERE id=?', id).question;
const raiseBody = (id) =>
JSON.parse(store.get("SELECT body FROM events WHERE kind='action.allowed' AND json_extract(body,'$.operation')='decision.raise' AND json_extract(body,'$.decision')=?", id).body);
const refusals = () => store.all("SELECT body FROM events WHERE business='demo' AND kind='action.refused' ORDER BY seq").map((e) => JSON.parse(e.body).code);
return { store, broker, caps, call, raise, grant, decisions, question, raiseBody, refusals };
}
test('G1 (host): only the chief raises a host grant, a grant on any other action refuses, and nothing is stored', async (t) => {
const f = setup(t);
const before = f.decisions();
await refusesWith(f.raise({}, 'pm'), 'grant-chief-only');
await refusesWith(f.raise({}, 'chief', { action: 'deploy' }), 'invalid-request');
await refusesWith(f.raise({}, 'tester'), 'tester-refused');
assert.equal(f.decisions(), before);
assert.deepEqual(f.refusals(), ['grant-chief-only', 'invalid-request', 'tester-refused']);
});
test('G1, R4: the grant takes exactly method, agent, host, commands and rotateBy, and an unknown method refuses', async (t) => {
const f = setup(t);
const before = f.decisions();
const g = f.grant();
const { rotateBy, ...noRotate } = g;
for (const bad of [
noRotate,
{ ...g, extra: 1 },
{ ...g, method: 'gitea' },
{ ...g, method: 'Host' },
{ ...g, agent: 'Ops' },
{ ...g, agent: '' },
{ ...g, agent: 7 },
{ ...g, host: 'Web_1' },
{ ...g, host: 'a'.repeat(33) },
])
await refusesWith(f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: bad }), 'invalid-request');
for (const bad of [null, [], 'host'])
await refusesWith(f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: bad }), 'invalid-request');
assert.equal(f.decisions(), before);
assert.ok(rotateBy);
});
test('G2: an agent whose definition lacks host refuses host-not-declared, and an unknown agent unknown-role', async (t) => {
const f = setup(t);
const before = f.decisions();
await refusesWith(f.raise({ agent: 'pm' }), 'host-not-declared');
await refusesWith(f.raise({ agent: 'chief' }), 'host-not-declared');
await refusesWith(f.raise({ agent: 'nobody' }), 'unknown-role');
// An inherited name is not a definition.
await refusesWith(f.raise({ agent: 'odd' }), 'host-not-declared');
assert.equal(f.decisions(), before);
});
test('mos-1163: a grant whose agent is a creative role refuses host-creative-role, even when its definition declares host', async (t) => {
const f = setup(t);
const before = f.decisions();
await refusesWith(f.raise({ agent: 'muse' }), 'host-creative-role');
assert.equal(f.decisions(), before);
});
test('G3: wildcard, shell, empty and other 210 D6 argv prefixes refuse invalid-request', async (t) => {
const f = setup(t);
const before = f.decisions();
for (const commands of [
'any',
'*',
{},
[],
[[]],
[['*']],
[['systemctl', 'status*']],
[['ls', '[a]']],
[['bash']],
[['/bin/sh', '-c']],
[['sudo', 'ls']],
[['python3']],
[['env', 'ls']],
[['bin/ls']],
[['']],
[['ls', 'a\0b']],
[['ls', 3]],
[['ls'], ['ls']],
[Array.from({ length: 257 }, () => 'x')],
])
await refusesWith(f.raise({ commands }), 'invalid-request');
assert.equal(f.decisions(), before);
});
test('R4 rotateBy (sage-1782): a real calendar day after today UTC, or invalid-request', async (t) => {
const f = setup(t);
const before = f.decisions();
for (const rotateBy of [dayFrom(0), dayFrom(-1), '2026-02-30', '2026-13-01', '20991231', '2099-1-01', 20991231, null])
await refusesWith(f.raise({ rotateBy }), 'invalid-request');
assert.equal(f.decisions(), before);
await f.raise({ rotateBy: dayFrom(1) });
await f.raise({ rotateBy: '2999-12-31' });
assert.equal(f.decisions(), before + 2);
});
test('G19: a grant naming a host that is pending-install refuses host-not-ready, and an unknown host host-unknown', async (t) => {
const f = setup(t);
hostRecord(f.store, { host: 'web2', entry: ENTRY });
f.store.run("UPDATE hosts SET state='pending-install' WHERE business='demo' AND host='web2'");
const before = f.decisions();
await refusesWith(f.raise({ host: 'web2' }), 'host-not-ready');
await refusesWith(f.raise({ host: 'web9' }), 'host-unknown');
assert.equal(f.decisions(), before);
});
test('R4, G5: the raise routes to the human and its event body binds the eight fields with their hashes', async (t) => {
const f = setup(t);
const commands = [['systemctl', 'status'], ['/usr/bin/journalctl', '-u', 'nginx']];
const d = await f.raise({ commands });
const row = f.store.get('SELECT action, class, route_to FROM decisions WHERE id=?', d.id);
assert.deepEqual({ ...row }, { action: 'credential.mint', class: 'gated', route_to: 'human' });
const body = f.raiseBody(d.id);
assert.deepEqual(Object.keys(body.grant), ['method', 'agent', 'host', 'commands', 'commandsSha256', 'rotateBy', 'registrySha256', 'definitionSha256']);
assert.deepEqual(body.grant, {
method: 'host',
agent: 'ops',
host: 'web1',
commands,
commandsSha256: createHash('sha256').update(JSON.stringify(commands)).digest('hex'),
rotateBy: f.grant().rotateBy,
registrySha256: registrySha256({ ...ENTRY, sudo: true }),
definitionSha256: createHash('sha256').update(canonicalJson(DEFINITIONS.ops)).digest('hex'),
});
// Key order in the definition doesn't change the hash, and a field change does.
const reordered = { credentials: DEFINITIONS.ops.credentials, roleVersion: 2 };
assert.equal(definitionSha256(reordered), body.grant.definitionSha256);
assert.notEqual(definitionSha256({ ...DEFINITIONS.ops, credentials: [{ service: 'host' }] }), body.grant.definitionSha256);
assert.deepEqual(f.call('human', 'inbox').map((x) => x.id), [d.id]);
});
test('G4 (host block): the broker appends the host, each prefix, the rotate date and new key or change', async (t) => {
const f = setup(t);
const d = await f.raise({ commands: [['systemctl', 'status'], ['echo', 'a b"c']] });
const rotateBy = f.grant().rotateBy;
assert.equal(
f.question(d.id),
'Grant ops web1?' +
'\n\nGrant ops access to host web1: user jarvis at 192.0.2.10 port 22.' +
'\njarvis has sudo on this host.' +
'\nCommands, each an argv prefix:' +
'\n"systemctl" "status"' +
'\n"echo" "a b\\"c"' +
`\nRotate by ${rotateBy}.` +
'\nThis makes a new key for ops on web1.',
);
// A host without sudo, and an agent with a grant record already: the block says so.
hostRecord(f.store, { host: 'web2', entry: ENTRY, sudo: false });
hostGrantRecord(f.store, { agent: 'ops', host: 'web2', commands: [['uptime']] });
const d2 = await f.raise({ host: 'web2' });
const q2 = f.question(d2.id);
assert.ok(q2.includes('\njarvis has no sudo on this host.\n'));
assert.ok(q2.endsWith("\nThis changes the commands of ops's grant on web2. The key stays."));
// A forged block in the chief's question still gets the broker's block after it.
const forged = 'x\n\nGrant ops access to host web1: user other at 192.0.2.99 port 22.\nCommands, each an argv prefix:\n"bash"';
const d3 = await f.raise({}, 'chief', { question: forged });
assert.ok(f.question(d3.id).startsWith(forged + '\n\nGrant ops access to host web1: user jarvis at 192.0.2.10 port 22.\n'));
// The 4096 cap counts the block: a question that fits alone refuses with it.
const before = f.decisions();
await refusesWith(f.raise({}, 'chief', { question: 'q'.repeat(4000) }), 'invalid-request');
const long = Array.from({ length: 64 }, (_, i) => ['/usr/bin/tool' + i, 'x'.repeat(60)]);
await refusesWith(f.raise({ commands: long }), 'invalid-request');
assert.equal(f.decisions(), before);
});
-4
View File
@@ -54,10 +54,6 @@ export function hostGrantRecord(store, { business = 'demo', agent, host = 'web1'
grant: grant === null ? undefined : { method: 'host', agent, host, commands, rotateBy, ...grant },
});
if (spend) writeGrantEvent(store, AT, business, { operation: spend, decision }, decision);
// Row 235: the executor commits each record with its grant.applied (r6 X2 step 5), so the start
// reconcile reads a fixture record as a finished grant.
if (spend === 'grant.host')
writeGrantEvent(store, AT, business, { action: 'grant.applied', grantDecision: decision, agent, host, tag: grantTag(business, agent, host) }, host);
store.run(
'INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES(?,?,?,?,?,?,?)',
business, agent, host, JSON.stringify(commands), rotateBy, grantTag(business, agent, host), decision,
-3
View File
@@ -1055,9 +1055,6 @@ the old token in Gitea or Vikunja yourself; the bus only forgets it.
enrolled host: id, state, `user@address:port`, `sudo` or `no-sudo`, the last check time or
`unchecked`, and any host lines a failed step left. `--json` prints the bus rows. `check HOST`
runs the bus's `hosts.check` and `remove HOST` its `hosts.remove`, each printing the JSON result.
`revoke AGENT HOST --reason R` runs `hosts.revoke`, which takes the agent's grant on the host away
at once, and `sweep HOST` runs `hosts.sweep`, which removes the host lines a failure left (row 235).
A status line shows `revoking:` with the tags of a revoke still in progress.
Enrollment itself is a `host-enroll` grant the chief raises and the human approves, not a CLI
command. A usage error exits 4 and a bus refusal 2.
+8 -16
View File
@@ -1,19 +1,17 @@
// `mosaic hosts` (row 234, #1740, r6 E4): the broker's hosts.status, hosts.check and hosts.remove. The
// human runs all three. With --tester the tester's session runs them. check logs in as mosaic-installer
// and runs `list` on the host, then marks the host ready. remove drops a host no grant uses. Nothing here
// reads a key: the answers carry fingerprints only. Row 235 (#1741, r6 section 6, X3) adds revoke, which
// takes an agent's grant on a host away at once, and sweep, which removes the lines a failure left.
// reads a key: the answers carry fingerprints only.
import { CliError } from "./errors.mjs";
export const HOSTS_USAGE =
"mosaic hosts [status] [--json] [--tester] [--business ID] | check|remove|sweep HOST [--tester] [--business ID] | revoke AGENT HOST --reason R [--tester] [--business ID]";
export const HOSTS_USAGE = "mosaic hosts [status] [--json] [--tester] [--business ID] | check|remove HOST [--tester] [--business ID]";
function parse(args) {
const out = { positional: [], flags: new Set(), values: {} };
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === "--json" || arg === "--tester") out.flags.add(arg);
else if (arg === "--business" || arg === "--reason") {
else if (arg === "--business") {
if (!args[i + 1] || Object.hasOwn(out.values, arg)) throw new CliError(HOSTS_USAGE, 4);
out.values[arg] = args[++i];
} else if (arg.startsWith("--")) throw new CliError(HOSTS_USAGE, 4);
@@ -24,18 +22,13 @@ function parse(args) {
const line = (h) =>
[h.host, h.state, `${h.user}@${h.address}:${h.port}`, h.sudo ? "sudo" : "no-sudo", h.checkedAt ?? "unchecked",
...(h.hostLineLeft.length ? [`line left: ${h.hostLineLeft.join(" ")}`] : []),
...(h.revoking?.length ? [`revoking: ${h.revoking.join(" ")}`] : [])].join("\t");
...(h.hostLineLeft.length ? [`line left: ${h.hostLineLeft.join(" ")}`] : [])].join("\t");
export async function hostsCommand(args, io, callFor) {
const parsed = parse(args);
const [verb = "status", first, second, ...extra] = parsed.positional;
const one = first !== undefined && second === undefined;
const shape = { status: first === undefined, check: one, remove: one, sweep: one, revoke: second !== undefined };
// N10: own keys only, so `constructor` or `toString` is a usage error, not a verb.
if (extra.length || !Object.hasOwn(shape, verb) || !shape[verb] || (parsed.flags.has("--json") && verb !== "status") ||
(verb === "revoke") !== Object.hasOwn(parsed.values, "--reason"))
throw new CliError(HOSTS_USAGE, 4);
const [verb = "status", host, ...extra] = parsed.positional;
const shape = { status: host === undefined, check: host !== undefined, remove: host !== undefined };
if (extra.length || !shape[verb] || (parsed.flags.has("--json") && verb !== "status")) throw new CliError(HOSTS_USAGE, 4);
try {
const call = callFor(parsed);
if (verb === "status") {
@@ -43,8 +36,7 @@ export async function hostsCommand(args, io, callFor) {
io.stdout.write(parsed.flags.has("--json") ? JSON.stringify(rows, null, 2) + "\n" : rows.map(line).join("\n") + (rows.length ? "\n" : ""));
return;
}
const args = verb === "revoke" ? { agent: first, host: second, reason: parsed.values["--reason"] } : { host: first };
io.stdout.write(JSON.stringify(await call(`hosts.${verb}`, args), null, 2) + "\n");
io.stdout.write(JSON.stringify(await call(`hosts.${verb}`, { host }), null, 2) + "\n");
} catch (error) {
if (error instanceof CliError) throw error;
throw new CliError(error.message, 2);
@@ -1,400 +0,0 @@
// Case 2 row C2-20 (#1722): scripts/case2-persona-import.mjs takes Bean's and Chet's personas from
// two Hermes profiles into Mosaic persona files. Brief: docs/plans/2026-10-20_case2-rows.md "C2-20".
// Every case runs on a scratch copy of fixtures/case2-persona-import/hermes, a scratch staging
// directory and a scratch config directory. Nothing here reads or writes ~/.hermes, ~/.mosaic-dev or
// ~/.config/mosaic-dev, and no fixture value is real. Fixture strings starting "marker-" must never
// reach the script's output.
import { test } from "node:test";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { PERSONA_CHARS, personaTextFault } from "../../harness/src/bundle.mjs";
import { tmp } from "./helpers.mjs";
const REPO = fileURLToPath(new URL("../../../", import.meta.url));
const SCRIPT = join(REPO, "scripts", "case2-persona-import.mjs");
const FIXTURE = join(REPO, "packages", "cli", "tests", "fixtures", "case2-persona-import");
const TRACE = join(FIXTURE, "trace.mjs");
const MKDIR_RACE = join(FIXTURE, "mkdir-race.mjs");
const PAIRS = ["--pair", "default=Bean", "--pair", "chet=Chet"];
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
const mode = (path) => statSync(path).mode & 0o777;
// A scratch Hermes home from the fixture, with the two .env files git won't carry, and empty
// staging and config parents.
function scratch(t) {
const root = tmp(t, "mosaic-persona-");
const hermes = join(root, "hermes");
cpSync(join(FIXTURE, "hermes"), hermes, { recursive: true });
writeFileSync(join(hermes, ".env"), "DISCORD_BOT_TOKEN=marker-env-default-3b58\n");
writeFileSync(join(hermes, "profiles", "chet", ".env"), "DISCORD_BOT_TOKEN=marker-env-chet-7e44\n");
const configDir = join(root, "config");
mkdirSync(configDir, { mode: 0o700 });
chmodSync(configDir, 0o700);
return { root, hermes, configDir, staging: join(root, "staging"), trace: join(root, "trace.log") };
}
function run(argv, { trace, race } = {}) {
const pre = [...(trace ? ["--import", TRACE] : []), ...(race ? ["--import", MKDIR_RACE] : [])];
const env = { ...process.env, ...(trace ? { PERSONA_TRACE: trace } : {}), ...(race ? { PERSONA_MKDIR_RACE: race } : {}) };
const r = spawnSync(process.execPath, [...pre, SCRIPT, ...argv], { encoding: "utf8", env, timeout: 30_000 });
return { status: r.status, out: r.stdout, err: r.stderr, all: r.stdout + r.stderr };
}
const stage = (s, extra = [], opts) => run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--staging", s.staging, ...extra], opts);
const install = (s, business = "case2", opts) => run(["install", "--staging", s.staging, "--config-dir", s.configDir, "--business", business], opts);
// Every fixture marker and every line of fixture text the script reads.
function assertNoText(s, output) {
const markers = new Set();
const walk = (dir) => {
for (const e of readdirSync(dir, { withFileTypes: true })) {
const p = join(dir, e.name);
if (e.isDirectory()) walk(p);
else for (const m of readFileSync(p, "utf8").match(/marker-[a-z]+(?:-[a-z]+)*-[0-9a-f]{4}/g) ?? []) markers.add(m);
}
};
walk(s.hermes);
assert.ok(markers.size >= 20, `only ${markers.size} markers found`);
for (const m of markers) assert.ok(!output.includes(m), `output holds ${m}`);
for (const line of ["You speak warmly", "Dry humour", "Help with the novel", "Ünïcode prompt"]) {
assert.ok(!output.includes(line), `output holds "${line}"`);
}
}
function personaTree(s, { bean, chet }) {
if (bean !== undefined) writeFileSync(join(s.hermes, "SOUL.md"), bean);
if (chet !== undefined) writeFileSync(join(s.hermes, "profiles", "chet", "SOUL.md"), chet);
}
test("stage takes each profile's SOUL.md byte for byte and prints the pairing with sizes and digests", (t) => {
const s = scratch(t);
const bean = readFileSync(join(s.hermes, "SOUL.md"));
const chet = readFileSync(join(s.hermes, "profiles", "chet", "SOUL.md"));
const r = stage(s);
assert.equal(r.status, 0, r.all);
assert.deepEqual(readFileSync(join(s.staging, "bean.md")), bean);
assert.deepEqual(readFileSync(join(s.staging, "chet.md")), chet);
assert.ok(r.out.includes(`pairing: profile default is Bean (instance bean), SOUL.md ${bean.length} bytes, sha256 ${sha256(bean)}`), r.out);
assert.ok(r.out.includes(`pairing: profile chet is Chet (instance chet), SOUL.md ${chet.length} bytes, sha256 ${sha256(chet)}`), r.out);
// The pairing comes before the first file written.
assert.ok(r.out.indexOf("pairing:") < r.out.indexOf("staged:"), r.out);
const manifest = JSON.parse(readFileSync(join(s.staging, "manifest.json"), "utf8"));
assert.deepEqual(manifest, {
version: 1,
personas: [
{ instance: "bean", name: "Bean", bytes: bean.length, sha256: sha256(bean) },
{ instance: "chet", name: "Chet", bytes: chet.length, sha256: sha256(chet) },
],
});
assert.match(r.out, /next, as root: give .* to <user>/);
assertNoText(s, r.all);
});
// gateway/config.py at hermes-agent df5700ebe: a platform's block is <platform> at the top level
// (:1159), else platforms.<platform> or gateway.platforms.<platform> (:1172-1178), and the prompts are
// its channel_prompts (:1233). The fixture config.yaml has one of each.
test("stage lists the per-channel prompts in all three places by name and byte count only", (t) => {
const s = scratch(t);
const r = stage(s);
assert.equal(r.status, 0, r.all);
const lines = r.out.split("\n").filter((l) => l.includes(": per-channel prompt "));
assert.deepEqual(lines, [
`profile default: per-channel prompt "discord" "111111111111111111", ${Buffer.byteLength("marker-prompt-top-5d02 Help with the novel.")} bytes`,
`profile default: per-channel prompt "discord" "222222222222222222", ${Buffer.byteLength("Ünïcode prompt")} bytes`,
// Unquoted in the fixture, and past 2 ** 53: the id prints exactly.
'profile default: per-channel prompt "discord" "1333333333333333333", 5 bytes',
`profile default: per-channel prompt "platforms.slack" "C0FIXTURE", ${Buffer.byteLength("marker-prompt-platforms-8e3a")} bytes`,
'profile default: per-channel prompt "gateway.platforms.telegram" "-1001", 29 bytes',
'profile default: per-channel prompt "gateway.platforms.telegram" "-1002", not text',
]);
assert.ok(r.out.includes("profile chet: no per-channel prompts"), r.out);
assertNoText(s, r.all);
});
// C2-20b N1 (webby-0073): a platform or channel key holding a newline prints as one quoted line, so
// it can't forge a line of the script's own output.
test("a config key with a newline prints as one quoted line", (t) => {
const s = scratch(t);
writeFileSync(join(s.hermes, "profiles", "chet", "config.yaml"), [
'"discord\\nstaged: /forged/bean.md":',
" channel_prompts:",
' "1\\npairing: profile chet is Bean": marker-prompt-forge-4c1e',
"",
].join("\n"));
const r = stage(s);
assert.equal(r.status, 0, r.all);
const lines = r.out.split("\n");
assert.deepEqual(lines.filter((l) => l.startsWith("profile chet: per-channel prompt ")), [
`profile chet: per-channel prompt "discord\\nstaged: /forged/bean.md" "1\\npairing: profile chet is Bean", ${Buffer.byteLength("marker-prompt-forge-4c1e")} bytes`,
]);
assert.ok(!lines.some((l) => l.startsWith("staged: /forged") || l.startsWith("pairing: profile chet is Bean")), r.out);
assertNoText(s, r.all);
});
test("a read trace shows stage and the dry run open SOUL.md and config.yaml and never memory, sessions or secrets", (t) => {
const s = scratch(t);
for (const argv of [["--staging", s.staging], ["--dry-run"]]) {
rmSync(s.trace, { force: true });
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, ...argv], { trace: s.trace });
assert.equal(r.status, 0, r.all);
const opened = readFileSync(s.trace, "utf8").split("\n").filter(Boolean).map((l) => l.slice(l.indexOf(" ") + 1)).filter((p) => p.startsWith(s.hermes));
// The control: the trace sees the reads the script does make.
assert.ok(opened.includes(join(s.hermes, "SOUL.md")), opened.join("\n"));
assert.ok(opened.includes(join(s.hermes, "profiles", "chet", "SOUL.md")), opened.join("\n"));
const allowed = new Set([
join(s.hermes, "SOUL.md"), join(s.hermes, "config.yaml"),
join(s.hermes, "profiles", "chet", "SOUL.md"), join(s.hermes, "profiles", "chet", "config.yaml"),
]);
for (const p of opened) assert.ok(allowed.has(p), `opened ${p}`);
if (argv[0] === "--dry-run") assert.ok(!opened.some((p) => p.endsWith("config.yaml")), "the dry run read config.yaml");
else assert.ok(opened.includes(join(s.hermes, "config.yaml")), opened.join("\n"));
}
});
test("the pairing refuses anything but two existing profiles naming Bean and Chet once each, and writes nothing", (t) => {
const s = scratch(t);
const cases = [
[["--pair", "default=Bean", "--pair", "chet=Bob"], 1, /profile chet names "Bob", not Bean or Chet/],
[["--pair", "default=bean", "--pair", "chet=Chet"], 1, /names "bean", not Bean or Chet/],
[["--pair", "default=Bean", "--pair", "chet=Bean"], 1, /Bean is named twice/],
[["--pair", "chet=Bean", "--pair", "chet=Chet"], 1, /profile chet is paired twice/],
[["--pair", "default=Bean", "--pair", "nobody=Chet"], 1, /profile nobody: .* doesn't exist/],
[["--pair", "default=Bean", "--pair", "../chet=Chet"], 1, /isn't a Hermes profile name/],
[["--pair", "default=Bean"], 2, /exactly two --pair/],
[["--pair", "default=Bean", "--pair", "chet=Chet", "--pair", "x=Chet"], 2, /exactly two --pair/],
];
for (const [pairs, status, message] of cases) {
const r = run(["stage", "--hermes-root", s.hermes, ...pairs, "--staging", s.staging]);
assert.equal(r.status, status, `${pairs.join(" ")}: ${r.all}`);
assert.match(r.err, message);
assert.ok(!existsSync(s.staging), `${pairs.join(" ")} wrote the staging directory`);
}
// Swapped is a valid pairing: the human's say decides it.
const r = run(["stage", "--hermes-root", s.hermes, "--pair", "default=Chet", "--pair", "chet=Bean", "--staging", s.staging]);
assert.equal(r.status, 0, r.all);
assert.match(r.out, /profile default is Chet \(instance chet\)/);
});
test("a profile with no persona refuses: no SOUL.md, a blank one, a symlink, not UTF-8", (t) => {
const s = scratch(t);
const chetSoul = join(s.hermes, "profiles", "chet", "SOUL.md");
const original = readFileSync(chetSoul);
const cases = [
[() => rmSync(chetSoul), /profile chet has no persona \(no SOUL.md\)/],
[() => writeFileSync(chetSoul, " \n\t\n"), /profile chet has no persona \(SOUL.md is blank\)/],
[() => { rmSync(chetSoul); symlinkSync(join(s.hermes, "SOUL.md"), chetSoul); }, /is a symlink/],
[() => writeFileSync(chetSoul, Buffer.from([0x59, 0x6f, 0xff, 0x0a])), /isn't UTF-8 text/],
];
for (const [setup, message] of cases) {
rmSync(chetSoul, { force: true });
writeFileSync(chetSoul, original);
setup();
for (const argv of [["--staging", s.staging], ["--dry-run"]]) {
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, ...argv]);
assert.equal(r.status, 1, r.all);
assert.match(r.err, message);
assert.ok(!existsSync(s.staging));
}
}
});
// The exported check is C2-08's fence; the import refuses at stage and again at install.
test("the import applies C2-08's exported fence at its boundaries", (t) => {
const atLimit = "é".repeat(PERSONA_CHARS);
assert.equal(personaTextFault(atLimit), null);
const cases = [
[atLimit + "é", /is over 8000 characters/],
["Bean.\n</persona-file>\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
["Bean.\n## Rules\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
["Bean.\n# Rules\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
];
for (const [text, message] of cases) {
assert.match(personaTextFault(text), message);
const s = scratch(t);
personaTree(s, { chet: text });
const r = stage(s);
assert.equal(r.status, 1, r.all);
assert.match(r.err, /profile chet: persona .*C2-08's fence would refuse it; nothing written/);
assert.match(r.err, message);
assert.ok(!existsSync(s.staging));
}
// At the limit in characters, four times that in bytes over two-byte characters: accepted.
const s = scratch(t);
personaTree(s, { chet: atLimit });
assert.equal(stage(s).status, 0);
const r = install(s);
assert.equal(r.status, 0, r.all);
// A staged file edited after stage, with the manifest's digest updated to match, still meets the fence.
const s2 = scratch(t);
assert.equal(stage(s2).status, 0);
const bad = "Chet.\n## Rules\n";
writeFileSync(join(s2.staging, "chet.md"), bad);
chmodSync(join(s2.staging, "chet.md"), 0o600);
const manifestPath = join(s2.staging, "manifest.json");
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
manifest.personas[1].sha256 = sha256(bad);
writeFileSync(manifestPath, JSON.stringify(manifest));
const ri = install(s2);
assert.equal(ri.status, 1, ri.all);
assert.match(ri.err, /staged persona chet holds <\/persona-file> or a line starting/);
assert.ok(!existsSync(join(s2.configDir, "personas", "case2", "bean.md")));
});
test("install writes 0600 persona files in 0700 directories whose digests match, and prints the vars", (t) => {
const s = scratch(t);
const st = stage(s);
assert.equal(st.status, 0, st.all);
assert.equal(mode(s.staging), 0o700);
for (const f of ["bean.md", "chet.md", "manifest.json"]) assert.equal(mode(join(s.staging, f)), 0o600, f);
const r = install(s);
assert.equal(r.status, 0, r.all);
const dir = join(s.configDir, "personas", "case2");
assert.equal(mode(join(s.configDir, "personas")), 0o700);
assert.equal(mode(dir), 0o700);
for (const [instance, name, src] of [["bean", "Bean", join(s.hermes, "SOUL.md")], ["chet", "Chet", join(s.hermes, "profiles", "chet", "SOUL.md")]]) {
const path = join(dir, `${instance}.md`);
assert.equal(mode(path), 0o600);
const data = readFileSync(path);
assert.deepEqual(data, readFileSync(src));
assert.ok(r.out.includes(`instance ${instance}: persona.name ${name}, persona.sha256 ${sha256(data)}`), r.out);
}
assertNoText(s, st.all + r.all);
});
test("install refuses an open or foreign staging file, a digest off the manifest and an existing persona", (t) => {
const s = scratch(t);
assert.equal(stage(s).status, 0);
const chet = join(s.staging, "chet.md");
chmodSync(chet, 0o640);
let r = install(s);
assert.equal(r.status, 1, r.all);
assert.match(r.err, /staged persona chet: .* has group or other mode bits/);
chmodSync(chet, 0o600);
chmodSync(s.staging, 0o750);
r = install(s);
assert.match(r.err, /staging has group or other mode bits/);
chmodSync(s.staging, 0o700);
writeFileSync(chet, "You are someone else.\n");
r = install(s);
assert.equal(r.status, 1, r.all);
assert.match(r.err, /staged persona chet isn't the file the manifest names/);
assert.ok(!existsSync(join(s.configDir, "personas", "case2", "bean.md")), "bean was written before chet was checked");
const s2 = scratch(t);
assert.equal(stage(s2).status, 0);
const dir = join(s2.configDir, "personas", "case2");
mkdirSync(dir, { recursive: true, mode: 0o700 });
chmodSync(join(s2.configDir, "personas"), 0o700);
writeFileSync(join(dir, "chet.md"), "already here\n", { mode: 0o600 });
r = install(s2);
assert.equal(r.status, 1, r.all);
assert.match(r.err, /chet.md already exists; nothing written/);
assert.equal(readFileSync(join(dir, "chet.md"), "utf8"), "already here\n");
assert.ok(!existsSync(join(dir, "bean.md")));
for (const business of ["../x", "Case2", ""]) {
r = install(s2, business);
assert.notEqual(r.status, 0, business);
}
const s3 = scratch(t);
assert.equal(stage(s3).status, 0);
writeFileSync(join(s3.staging, "manifest.json"), JSON.stringify({ version: 1, personas: [{ instance: "bob", name: "Bob" }] }));
r = install(s3);
assert.equal(r.status, 1, r.all);
assert.match(r.err, /the manifest doesn't list two personas/);
});
test("--dry-run writes nothing and prints only counts and the fence fault, two heading lines in a fixture counted", (t) => {
const s = scratch(t);
personaTree(s, { chet: "You are Chet. marker-chet-dry-7d21\n# Voice\nShort.\r\n## Habits\nNot # a heading, nor #nospace.\n" });
const before = readdirSync(s.root).sort();
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
assert.equal(r.status, 1, r.all);
assert.deepEqual(readdirSync(s.root).sort(), before);
assert.deepEqual(r.out.split("\n").filter(Boolean), [
"files 2",
'profile default: lines 3, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0',
'profile chet: lines 5, lines starting "# " or "## " 2, lines naming a Hermes tool or channel 0',
'profile chet: persona holds </persona-file> or a line starting "# " or "## ", so C2-08\'s fence would refuse it',
]);
assert.equal(r.err, "case2-persona-import: refused: C2-08's fence would refuse the persona of profile chet, so stage would write nothing\n");
assertNoText(s, r.all);
assert.ok(!r.all.includes("Voice") && !r.all.includes("Habits"));
});
// C2-20b N2 (webby-0073): a persona over the fence and under the byte cap used to pass the dry run
// and then refuse at stage. The dry run names the fault and refuses too, and passes at the limit.
test("--dry-run applies C2-08's fence: over it the fault prints, nothing is written and it exits 1", (t) => {
const atLimit = "é".repeat(PERSONA_CHARS);
const s = scratch(t);
personaTree(s, { bean: atLimit + "é" });
const before = readdirSync(s.root).sort();
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
assert.equal(r.status, 1, r.all);
assert.deepEqual(readdirSync(s.root).sort(), before);
assert.deepEqual(r.out.split("\n").filter(Boolean), [
"files 2",
'profile default: lines 1, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0',
"profile default: persona is over 8000 characters, so C2-08's fence would refuse it",
'profile chet: lines 2, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0',
]);
assert.match(r.err, /refused: C2-08's fence would refuse the persona of profile default, so stage would write nothing/);
assert.ok(!r.all.includes("éé"));
personaTree(s, { bean: atLimit });
const ok = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
assert.equal(ok.status, 0, ok.all);
assert.equal(ok.err, "");
});
// C2-20b N4 (webby-0073): a directory made between privateDir's lstat and its mkdir refuses with a
// named reason, not a raw EEXIST. mkdir-race.mjs makes the directory just before the script's mkdir.
test("a directory made between the check and mkdir refuses by name, at stage and at install", (t) => {
const s = scratch(t);
let r = stage(s, [], { race: s.staging });
assert.equal(r.status, 1, r.all);
assert.equal(r.err, `case2-persona-import: refused: ${s.staging} was made by something else between the check and mkdir\n`);
assert.deepEqual(readdirSync(s.staging), []);
const s2 = scratch(t);
assert.equal(stage(s2).status, 0);
const dir = join(s2.configDir, "personas", "case2");
r = install(s2, "case2", { race: dir });
assert.equal(r.status, 1, r.all);
assert.equal(r.err, `case2-persona-import: refused: ${dir} was made by something else between the check and mkdir\n`);
assert.deepEqual(readdirSync(dir), []);
});
test("--dry-run counts three lines naming a Hermes tool or channel and prints none of the words", (t) => {
const s = scratch(t);
personaTree(s, {
bean: [
"You are Bean.",
"Use web_search when she asks for facts.",
"You live on Discord, in her server.",
"Keep a TODO list for her chapters.",
"Web searching and discords of music don't count, nor memory_bank.",
"",
].join("\n"),
});
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
assert.equal(r.status, 0, r.all);
assert.match(r.out, /profile default: lines 5, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 3/);
for (const word of ["web_search", "Discord", "discord", "TODO", "todo", "memory"]) assert.ok(!r.all.includes(word), `output holds ${word}`);
});
test("usage: stage needs one of --staging and --dry-run, install takes only its own options", (t) => {
const s = scratch(t);
assert.equal(run(["stage", "--hermes-root", s.hermes, ...PAIRS]).status, 2);
assert.equal(run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--staging", s.staging, "--dry-run"]).status, 2);
assert.equal(run(["stage", ...PAIRS, "--dry-run"]).status, 2);
assert.equal(run(["install", "--staging", s.staging, "--config-dir", s.configDir]).status, 2);
assert.equal(run(["install", "--staging", s.staging, "--config-dir", s.configDir, "--business", "case2", "--dry-run"]).status, 2);
assert.equal(run(["import"]).status, 2);
assert.equal(run(["stage", "--bogus", "x"]).status, 2);
assert.ok(!existsSync(s.staging));
});
@@ -1,5 +0,0 @@
Fixture Hermes home for packages/cli/tests/case2-persona-import.test.mjs (row 221, C2-20).
The layout follows hermes-agent df5700ebe: the default profile is the root, other profiles sit under
profiles/<name>, each persona is SOUL.md and channel prompts are in config.yaml. Every value is made up.
Strings starting "marker-" must never reach the script's output, and files under memories/, sessions/
and skills/, state.db, profile.yaml, auth.json and .env (the test writes .env, which git ignores) must never be opened.
@@ -1,3 +0,0 @@
You are Bean. marker-bean-soul-71c4
You speak warmly and keep replies short.
You like sketches, coffee and long walks.
@@ -1 +0,0 @@
{"token": "marker-auth-default-6e21"}
@@ -1,21 +0,0 @@
model:
default: marker-model-name-2b91
provider: openrouter
discord:
require_mention: true
channel_prompts:
"111111111111111111": "marker-prompt-top-5d02 Help with the novel."
"222222222222222222": "Ünïcode prompt"
1333333333333333333: "short"
platforms:
slack:
channel_prompts:
C0FIXTURE: "marker-prompt-platforms-8e3a"
gateway:
platforms:
telegram:
channel_prompts:
"-1001": "marker-prompt-gateway-0f6b ok"
"-1002":
nested: not a string
api_key: marker-token-default-9a17
@@ -1 +0,0 @@
marker-memory-default-1f8e
@@ -1 +0,0 @@
description: marker-profile-description-44de
@@ -1,2 +0,0 @@
You are Chet. marker-chet-soul-38e0
Dry humour, quick with a pun.
@@ -1,2 +0,0 @@
model:
default: marker-model-chet-6d13
@@ -1 +0,0 @@
marker-memory-chet-d913
@@ -1 +0,0 @@
description: marker-profile-chet-0c55
@@ -1 +0,0 @@
{"text": "marker-session-chet-08bc"}
@@ -1 +0,0 @@
marker-skill-chet-6a70
@@ -1 +0,0 @@
marker-state-chet-52aa
@@ -1 +0,0 @@
{"text": "marker-session-default-a4b2"}
@@ -1 +0,0 @@
marker-state-default-c90d
@@ -1,13 +0,0 @@
// mkdir race for case2-persona-import.test.mjs: loaded with --import, it makes the directory named by
// $PERSONA_MKDIR_RACE just before the script's own mkdirSync of that path, as if another process won
// the race after the script's lstat. The script's mkdir then meets a real EEXIST.
import fs from "node:fs";
import { syncBuiltinESMExports } from "node:module";
const { mkdirSync } = fs;
const target = process.env.PERSONA_MKDIR_RACE;
fs.mkdirSync = function raced(p, ...rest) {
if (String(p) === target) mkdirSync(p, { mode: 0o700 });
return mkdirSync.call(this, p, ...rest);
};
syncBuiltinESMExports();
@@ -1,20 +0,0 @@
// Read trace for case2-persona-import.test.mjs: loaded with --import, it logs every path the script
// opens, reads or lists to $PERSONA_TRACE, one "op path" line each. The log is written through
// the original functions so the trace doesn't trace itself.
import fs from "node:fs";
import { syncBuiltinESMExports } from "node:module";
const { openSync, writeSync } = fs;
const log = openSync(process.env.PERSONA_TRACE, "a", 0o600);
const record = (op, p) => {
if (typeof p === "string" || p instanceof URL || Buffer.isBuffer(p)) writeSync(log, `${op} ${String(p)}\n`);
};
for (const name of ["openSync", "readFileSync", "readdirSync", "opendirSync", "createReadStream", "open", "readFile", "readdir", "opendir"]) {
const original = fs[name];
fs[name] = function traced(p, ...rest) { record(name, p); return original.call(this, p, ...rest); };
}
for (const name of ["open", "readFile", "readdir", "opendir"]) {
const original = fs.promises[name];
fs.promises[name] = function traced(p, ...rest) { record(`promises.${name}`, p); return original.call(this, p, ...rest); };
}
syncBuiltinESMExports();
+1 -31
View File
@@ -1,5 +1,4 @@
// Row 234 (#1740, r6 E4): `mosaic hosts status|check|remove`, and row 235 (#1741) revoke and sweep. A
// fake transport records the calls; no bus
// Row 234 (#1740, r6 E4): `mosaic hosts status|check|remove`. A fake transport records the calls; no bus
// runs here. The bus side of each verb is in packages/bus/tests/grant-enroll.test.mjs.
import test from "node:test";
import assert from "node:assert/strict";
@@ -73,32 +72,3 @@ test("row 234: scripts/mosaic sends hosts to packages/cli, not the seat CLI", (t
assert.match(r.stderr, /^mosaic: mosaic hosts \[status\]/);
assert.doesNotMatch(r.stderr, /mosaic launch </);
});
test("row 235: hosts revoke sends agent, host and reason, and sweep the host, as the human or the tester", async () => {
const calls = [];
const x = io();
await main(["hosts", "revoke", "ops", "web1", "--reason", "left the team", "--business", "acme"], x, deps(calls));
await main(["hosts", "sweep", "web1", "--tester", "--business", "acme"], x, deps(calls));
assert.deepEqual(calls.map(({ who, verb, args }) => ({ who, verb, args })), [
{ who: "human", verb: "hosts.revoke", args: { agent: "ops", host: "web1", reason: "left the team" } },
{ who: "tester", verb: "hosts.sweep", args: { host: "web1" } },
]);
});
test("row 235 (N10): revoke without --reason, --reason on another verb, and inherited names are usage errors", async () => {
const calls = [];
for (const argv of [["hosts", "revoke", "ops", "web1"], ["hosts", "revoke", "web1", "--reason", "r"], ["hosts", "revoke", "ops", "web1", "x", "--reason", "r"],
["hosts", "sweep"], ["hosts", "sweep", "web1", "web2"], ["hosts", "check", "web1", "--reason", "r"], ["hosts", "revoke", "ops", "web1", "--reason"],
["hosts", "revoke", "ops", "web1", "--reason", "a", "--reason", "b"], ["hosts", "constructor", "web1"], ["hosts", "toString", "web1"],
["hosts", "hasOwnProperty"], ["hosts", "__proto__", "web1"]])
await assert.rejects(main([...argv], io(), deps(calls)), (e) => (assert.equal(e.exitCode, 4, argv.join(" ")), assert.match(e.message, /mosaic hosts/), true));
assert.equal(calls.length, 0);
});
test("row 235: a status line shows the tags of a revoke in progress", async () => {
const rows = [{ ...ROWS[0], revoking: ["mosaic-" + "a".repeat(32)] }];
const x = io();
const d = { ...deps([]), transport: () => async () => rows };
await main(["hosts", "--business", "acme"], x, d);
assert.equal(x.out.text, `web1\tready\t[email protected]:22\tsudo\t2026-10-21T00:00:00.000Z\trevoking: mosaic-${"a".repeat(32)}\n`);
});
+4 -9
View File
@@ -188,13 +188,6 @@ function skillSection(skills) {
// digest still refuses any bytes but the pinned ones.
export const PERSONA_CHARS = 8000;
const PERSONA_END = "</persona-file>";
// The persona text rules, one copy for the bundle and the persona import (row 221,
// scripts/case2-persona-import.mjs): null for text that passes, else the reason it doesn't.
export function personaTextFault(text) {
if ([...text].length > PERSONA_CHARS) return `is over ${PERSONA_CHARS} characters`;
if (text.includes(PERSONA_END) || /^##? /m.test(text)) return `holds ${PERSONA_END} or a line starting "# " or "## "`;
return null;
}
function readPersona(resolved, personaDir) {
const digest = resolved.vars?.["persona.sha256"];
if (!personaDir) {
@@ -228,8 +221,10 @@ function readPersona(resolved, personaDir) {
}
let text;
try { text = utf8.decode(data); } catch { throw new BundleError(`instance ${resolved.instance}: persona file ${path} isn't UTF-8 text`, "persona-invalid"); }
const fault = personaTextFault(text);
if (fault) throw new BundleError(`instance ${resolved.instance}: persona file ${path} ${fault}`, "persona-invalid");
if ([...text].length > PERSONA_CHARS) throw new BundleError(`instance ${resolved.instance}: persona file ${path} is over ${PERSONA_CHARS} characters`, "persona-invalid");
if (text.includes(PERSONA_END) || /^##? /m.test(text)) {
throw new BundleError(`instance ${resolved.instance}: persona file ${path} holds ${PERSONA_END} or a line starting "# " or "## "`, "persona-invalid");
}
return { name: resolved.vars["persona.name"], sha256: digest, text };
}
// Between the contract and "## This session". The contract wins on a conflict, and the broker's
+2 -12
View File
@@ -57,8 +57,7 @@ environment and ceiling directory apply. A failed git call refuses `library-git`
It returns `{ commit, files, problems }`, deep-frozen and sorted. Each file has its path, scope,
universe, book, type, numbered lines, `bodyLine`, parsed `frontmatter` or `null`, `frontmatterRaw`
and `links`. Front matter `appears_in` and `relationships` wikilinks count as links. A link in a block
list carries its list item's line. One in a scalar or flow value carries its key's line.
and `links`. Front matter `appears_in` and `relationships` wikilinks count as links.
Problems carry `{ code, path, line, message }`:
@@ -88,11 +87,6 @@ then with `.md` added:
It resolves only against indexed files. A link to a `.canvas` file or an attachment is R4. A link into
another repo resolves to nothing. `extractLinks` skips fenced and inline code.
A `![[...]]` embed resolves like any link. A body embed that resolves to nothing and whose target ends
in an extension other than `.md`, in any case, embeds an attachment, and it is never R4. An extension is
a dot and up to 8 letters and digits, at least one a letter. Any other unresolved embed is R4, and so is
an unresolved front matter value written as an embed (C2-01b N3, sage-1900).
## renderItems
`renderItems(body, { scopeOf, changed })` turns a reply body into the plain text both channels show.
@@ -116,11 +110,7 @@ mosaic library survey <repo> [--mapping <file>]
```
It reads the repo's HEAD commit and prints folder names, file counts by extension, front matter key
sets, link-form counts and the count of body embeds whose target has an extension other than `.md`,
which still count as embeds. That count goes by the name alone, so an embed of `Dr.Quinn.md` written
`![[Dr.Quinn]]` counts there too. Folder names print as JSON strings, with DEL, C1 and bidi controls,
U+061C among them, also as `\uXXXX`. It never prints file text, front matter values, file names or
link targets.
sets and link-form counts. It never prints file text, front matter values, file names or link targets.
A key that is not a short identifier prints as `(other key)`, since it could be her words. With
`--mapping` it adds scope counts, resolver step counts and problem counts by rule.
+1 -1
View File
@@ -2,7 +2,7 @@
export { LibraryError, RULES, problem, sortProblems } from './problems.mjs';
export { checkMapping, TYPES } from './mapping.mjs';
export { classify } from './scope.mjs';
export { extractLinks, parseWikilink, resolver, formOf, isAttachment } from './links.mjs';
export { extractLinks, parseWikilink, resolver, formOf } from './links.mjs';
export { readLibrary, listTree, readTexts, parseFile, parseFrontMatter, headCommit, MAX_BLOB, LINK_FIELDS } from './reader.mjs';
export { renderItems, KINDS, NOTICES, UNREADABLE } from './render.mjs';
export { survey, formatSurvey, surveyMain } from './survey.mjs';
+1 -11
View File
@@ -1,8 +1,6 @@
// Wikilinks and the link resolver of design 1.3. Links are [[target]], [[target|label]] and
// [[target#heading]], with ![[...]] embeds read the same way. Links inside fenced code blocks and
// inline code spans are not links, as in Obsidian. A body embed that resolves to no indexed note and whose
// target ends in an extension other than `.md`, in any case, embeds an attachment (C2-01b N3): the
// reader doesn't index it, and it raises no problem.
// inline code spans are not links, as in Obsidian.
import { posix } from 'node:path';
const WIKILINK = /(!?)\[\[([^\[\]\n]+?)\]\]/g;
@@ -25,14 +23,6 @@ function parts(inner, embed) {
embed,
};
}
// Whether a body embed's target ends in an extension other than `.md`. An extension is a dot and up
// to 8 letters and digits, at least one a letter, at the end of the target's last segment, so
// `Chapter 1.5` and `Mr. Smith` have none and `cover.png` has one. `Dr.Quinn` has one too, so the
// reader asks this only of an embed that resolves to nothing. A plain link or a front matter value is
// never an attachment (sage-1900).
export const isAttachment = link => link.embed === true && !link.field
&& /\.(?=[a-z0-9]*[a-z])[a-z0-9]{1,8}$/i.test(link.file.slice(link.file.lastIndexOf('/') + 1))
&& !/\.md$/i.test(link.file);
// The form a link is counted under in the survey.
export const formOf = link => link.markdown ? 'markdown' : link.embed ? 'embed' : !link.file ? 'self'
: link.label !== null ? 'label' : link.heading !== null ? 'heading' : 'plain';
+10 -14
View File
@@ -5,7 +5,7 @@
// of the commit; the affected file or link is left out of the index.
import { git, gitBytes } from '../../project/src/git.mjs';
import { classify } from './scope.mjs';
import { extractLinks, isAttachment, parseWikilink, resolver } from './links.mjs';
import { extractLinks, parseWikilink, resolver } from './links.mjs';
import { LibraryError, problem, raise, sortProblems } from './problems.mjs';
export const MAX_BLOB = 1024 * 1024;
@@ -103,13 +103,12 @@ function value(raw) {
// Front matter of design 1.3 (R3): scalars, quoted strings, flow lists and block lists of scalars or
// wikilinks. Anything else, a nested map, a block scalar or an anchor for example, leaves the whole
// front matter as raw text with one R3 problem at the line where parsing stopped.
// Returns { frontmatter, raw, bodyLine, stop } with 1-based line numbers. Parsed front matter also
// returns `itemLines`, each block list key's item lines in order.
// Returns { frontmatter, raw, bodyLine, stop } with 1-based line numbers.
export function parseFrontMatter(lines) {
if (lines[0]?.replace(/^/, '').trimEnd() !== '---') return { frontmatter: null, raw: null, bodyLine: 1, stop: null };
const close = lines.findIndex((text, i) => i > 0 && /^(---|\.\.\.)\s*$/.test(text));
if (close < 0) return { frontmatter: null, raw: null, bodyLine: 1, stop: 1 };
const raw = lines.slice(1, close).join('\n'), data = {}, itemLines = {};
const raw = lines.slice(1, close).join('\n'), data = {};
let list = null;
for (let i = 1; i < close; i++) {
const text = lines[i], line = i + 1;
@@ -119,7 +118,6 @@ export function parseFrontMatter(lines) {
const parsed = scalar(item[2] ?? '');
if (!parsed.ok) return { frontmatter: null, raw, bodyLine: close + 2, stop: line };
data[list].push(parsed.value);
itemLines[list].push(line);
continue;
}
const pair = /^([^\s:#\-][^:]*?|"[^"]+"|'[^']+')\s*:(?:\s+(.*))?$/.exec(text);
@@ -128,7 +126,7 @@ export function parseFrontMatter(lines) {
if (Object.hasOwn(data, key) || key === '__proto__') return { frontmatter: null, raw, bodyLine: close + 2, stop: line };
if (pair[2] === undefined || !pair[2].trim()) {
const next = lines[i + 1];
if (i + 1 < close && /^\s*-( |$)/.test(next)) { data[key] = []; itemLines[key] = []; list = key; }
if (i + 1 < close && /^\s*-( |$)/.test(next)) { data[key] = []; list = key; }
else { data[key] = null; list = null; }
continue;
}
@@ -137,14 +135,13 @@ export function parseFrontMatter(lines) {
if (!parsed.ok) return { frontmatter: null, raw, bodyLine: close + 2, stop: line };
data[key] = parsed.value;
}
return { frontmatter: data, raw: null, bodyLine: close + 2, stop: null, itemLines };
return { frontmatter: data, raw: null, bodyLine: close + 2, stop: null };
}
export const splitLines = text => text.replace(/^/, '').split('\n').map(l => l.endsWith('\r') ? l.slice(0, -1) : l);
// One parsed file: its lines (all of them, numbered from 1), front matter and the links it holds.
// Front matter links come from LINK_FIELDS values that are wikilinks; other values are names. A
// link in a block list carries its item's line, one in a scalar or flow value its key's line.
// Front matter links come from LINK_FIELDS values that are wikilinks; other values are names.
export function parseFile(text, { markdown = false } = {}) {
const lines = splitLines(text);
const fm = parseFrontMatter(lines);
@@ -154,11 +151,10 @@ export function parseFile(text, { markdown = false } = {}) {
for (const field of LINK_FIELDS) {
const raw = fm.frontmatter[field];
const values = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];
const items = fm.itemLines[field];
values.forEach((v, i) => {
for (const v of values) {
const link = typeof v === 'string' ? parseWikilink(v.trim()) : null;
if (link) links.push({ ...link, field, line: items ? items[i] : frontMatterLine(lines, fm.bodyLine, field) });
});
if (link) links.push({ ...link, field, line: frontMatterLine(lines, fm.bodyLine, field) });
}
}
}
return { lines: numbered, bodyLine: fm.bodyLine, frontmatter: fm.frontmatter, frontmatterRaw: fm.raw, stop: fm.stop, links };
@@ -201,7 +197,7 @@ export async function readLibrary({ repo, commit, mapping }) {
for (const link of file.links) {
if (!link.file) continue;
const target = resolve(file.path, link.file);
if (!target.path) { if (!isAttachment(link)) problems.push(problem('R4', file.path, link.line)); continue; }
if (!target.path) { problems.push(problem('R4', file.path, link.line)); continue; }
const to = byPath.get(target.path);
if (file.scope === 'canon') {
if (to.scope === 'playground') problems.push(problem('R5', file.path, link.line));
+10 -15
View File
@@ -1,15 +1,14 @@
// `mosaic library survey <repo> [--mapping <file>]` (design 1.1, 10 step 7). It prints what a mapping
// needs: folder names, file counts by extension, front matter key sets, link-form counts and the
// count of body embeds whose target has an extension other than `.md`. It never prints file text,
// front matter values, file names or link targets. With a mapping it adds scope counts, resolver
// step counts and R-problem counts by code. It reads the repo's HEAD commit
// needs: folder names, file counts by extension, front matter key sets and link-form counts. It
// never prints file text, front matter values, file names or link targets. With a mapping it adds
// scope counts, resolver step counts and R-problem counts by code. It reads the repo's HEAD commit
// through the commit reader, never the working tree.
import { readFileSync, realpathSync, statSync } from 'node:fs';
import { resolve as resolvePath } from 'node:path';
import { pathToFileURL } from 'node:url';
import { checkMapping } from './mapping.mjs';
import { classify } from './scope.mjs';
import { formOf, isAttachment } from './links.mjs';
import { formOf } from './links.mjs';
import { headCommit, listTree, parseFile, readable, readLibrary, readTexts } from './reader.mjs';
import { LibraryError, RULES } from './problems.mjs';
@@ -38,7 +37,7 @@ export async function survey({ repo, commit, mapping }) {
const texts = await readTexts(repo, markdown.filter(readable));
const keySets = new Map(), forms = Object.fromEntries(FORMS.map(f => [f, 0]));
const fields = { appears_in: { wikilink: 0, name: 0 }, relationships: { wikilink: 0, name: 0 } };
let noFrontMatter = 0, unparsed = 0, attachments = 0;
let noFrontMatter = 0, unparsed = 0;
for (const text of texts.values()) {
const file = parseFile(text, { markdown: true });
if (file.stop !== null) unparsed++;
@@ -52,14 +51,14 @@ export async function survey({ repo, commit, mapping }) {
fields[field][typeof v === 'string' && /^\s*!?\[\[[^\]]+\]\]\s*$/.test(v) ? 'wikilink' : 'name']++;
}
}
for (const link of file.links) if (!link.field) { forms[formOf(link)]++; if (isAttachment(link)) attachments++; }
for (const link of file.links) if (!link.field) forms[formOf(link)]++;
}
const result = {
commit: head, entries: entries.length,
folders: [...folders].sort(([a], [b]) => a < b ? -1 : 1).map(([name, counts]) => ({ name, ...counts })),
markdown: { files: markdown.length, read: texts.size, noFrontMatter, unparsed },
keySets: [...keySets].sort(([a, x], [b, y]) => y - x || (a < b ? -1 : 1)).map(([keys, count]) => ({ keys, count })),
forms, attachments, fields,
forms, fields,
};
if (mapping) {
const scopes = { canon: 0, playground: 0, unmapped: 0 };
@@ -75,18 +74,14 @@ export async function survey({ repo, commit, mapping }) {
return result;
}
// Folder names are quoted as JSON strings, which escape C0 controls but leave DEL, C1 and bidi
// controls raw. quote() escapes those too, so no name can carry a control sequence to the terminal
// or reorder the line around it.
const RAW_CONTROLS = /[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
export const quote = name => JSON.stringify(name).replace(RAW_CONTROLS, c => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
// Folder names are quoted as JSON strings, so no name can carry a control sequence to the terminal.
export function formatSurvey(s) {
const out = [`commit ${s.commit}`, `entries ${s.entries}`, 'folders (direct children: md canvas base other)'];
for (const f of s.folders) out.push(` ${f.name === '' ? '(root)' : quote(f.name)} ${f.md} ${f.canvas} ${f.base} ${f.other}`);
for (const f of s.folders) out.push(` ${f.name === '' ? '(root)' : JSON.stringify(f.name)} ${f.md} ${f.canvas} ${f.base} ${f.other}`);
out.push(`markdown ${s.markdown.files} files, ${s.markdown.read} read, ${s.markdown.noFrontMatter} without front matter, ${s.markdown.unparsed} with front matter not fully parsed`);
out.push('front matter key sets');
for (const k of s.keySets) out.push(` ${k.count} [${k.keys}]`);
out.push(`body links ${FORMS.map(f => `${f} ${s.forms[f]}`).join(', ')}; attachment ${s.attachments}`);
out.push(`body links ${FORMS.map(f => `${f} ${s.forms[f]}`).join(', ')}`);
for (const [field, c] of Object.entries(s.fields)) out.push(`field ${field} wikilink ${c.wikilink}, name ${c.name}`);
if (s.scopes) {
out.push(`scopes canon ${s.scopes.canon}, playground ${s.scopes.playground}, unmapped ${s.scopes.unmapped}; indexed ${s.indexed}`);
+1 -13
View File
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { extractLinks, isAttachment, parseWikilink, resolver } from '../src/index.mjs';
import { extractLinks, parseWikilink, resolver } from '../src/index.mjs';
const PATHS = ['Book One/Characters/Mara Vell.md', 'Book One/Characters/Tomas.md', 'Book One/Places/Harbor Town.md',
'Book One/Chapters/Chapter 01.md', 'Book One/Places/Notes.md', 'Book One/Characters/Notes.md', 'Mara Vell.md'];
@@ -48,15 +48,3 @@ test('wikilink forms, embeds, and links skipped inside code', () => {
assert.deepEqual(extractLinks(lines).map(l => [l.file, l.line]), [['One', 1], ['Two', 1], ['Three', 1], ['Four', 1], ['', 1]]);
assert.deepEqual(extractLinks(lines, { markdown: true }).filter(l => l.markdown).map(l => l.file), ['Five.md']);
});
test('only a body embed whose target has an extension other than .md, in any case, is an attachment', () => {
const att = text => isAttachment(parseWikilink(text));
// By name alone: the reader asks only of an embed that resolved to nothing (sage-1900).
for (const s of ['![[cover.png]]', '![[cover.PNG]]', '![[Art/map.pdf|Map]]', '![[Board.canvas]]', '![[clip.mp4#t=5]]', '![[Dr.Quinn]]'])
assert.equal(att(s), true, s);
for (const s of ['![[missing-note]]', '![[note.md]]', '![[Note.MD]]', '![[Chapter 1.5]]', '![[Mr. Smith]]', '![[A.b/Note]]',
'[[cover.png]]', '[[Board.canvas]]', '[[Dr.Quinn]]', '[[#Self]]'])
assert.equal(att(s), false, s);
assert.equal(isAttachment({ ...parseWikilink('![[portrait.jpg]]'), field: 'relationships' }), false, 'a front matter value');
assert.equal(isAttachment({ file: 'pic.png', markdown: true, embed: false }), false, 'a markdown link');
});
+1 -35
View File
@@ -24,7 +24,7 @@ test('the fixture reads clean: every resolver step, appears_in and relationships
assert.deepEqual(mara.frontmatter, { type: 'character', name: 'Mara Vell', appears_in: '[[Book One/Chapters/Chapter 01]]',
relationships: ['[[Tomas]]', 'The Ferryman'] });
assert.deepEqual(mara.links.map(l => [l.field, l.path, l.line]), [
['appears_in', 'Book One/Chapters/Chapter 01.md', 4], ['relationships', 'Book One/Characters/Tomas.md', 6]]);
['appears_in', 'Book One/Chapters/Chapter 01.md', 4], ['relationships', 'Book One/Characters/Tomas.md', 5]]);
assert.deepEqual(file(result, 'Book One/Characters/Tomas.md').links.map(l => [l.field, l.path]),
[['appears_in', 'Book One/Chapters/Chapter 01.md']]);
assert.equal(mara.bodyLine, 9);
@@ -97,40 +97,6 @@ test('R4: a link to no file, to more than one, or into another repo is reported
assert.deepEqual(file(result, 'Book One/Chapters/Links.md').links.map(l => l.path), ['Book One/Characters/Tomas.md']);
});
test('a block list link carries its item line, a scalar or flow link its key line, and problems follow', async t => {
const r = repo(t, { ...BASE, 'Book One/Characters/Ana.md': ['---', 'appears_in: ["[[Nobody]]"]', 'relationships:', ' - "[[Tomas]]"',
' - Plain Name', ' - "[[Ghost]]"', ' - "[[What If]]"', '---', ''].join('\n') });
const result = await readLibrary({ repo: r.repo, commit: r.commit, mapping: mapping() });
assert.deepEqual(file(result, 'Book One/Characters/Ana.md').links.map(l => [l.field, l.path, l.line]), [
['relationships', 'Book One/Characters/Tomas.md', 4], ['relationships', 'Book One/Playground/What If.md', 7]]);
assert.deepEqual(result.problems.filter(p => p.path === 'Book One/Characters/Ana.md').map(p => [p.code, p.line]),
[['R4', 2], ['R4', 6], ['R5', 7]]);
});
// sage-1900: only an unresolved body embed with an extension other than .md is an attachment. A plain
// link to one and a front matter value stay R4 when they resolve to nothing.
test('an unresolved attachment embed gives no problem; a link or front matter value to one is R4; a note embed resolves', async t => {
const r = repo(t, { ...BASE, 'Book One/Places/note.md': 'n\n', 'Book One/Places/Shore.md': ['---',
'relationships:', ' - "![[portrait.JPG]]"', '---', '![[cover.png]] [[Board.canvas]] ![[map.pdf|Map]]',
'![[missing-note]] ![[note.md]] ![[Harbor Town]]', ''].join('\n') });
const result = await readLibrary({ repo: r.repo, commit: r.commit, mapping: mapping() });
assert.deepEqual(result.problems.filter(p => p.path === 'Book One/Places/Shore.md').map(p => [p.code, p.line]),
[['R4', 3], ['R4', 5], ['R4', 6]]);
assert.deepEqual(file(result, 'Book One/Places/Shore.md').links.map(l => [l.path, l.embed]),
[['Book One/Places/note.md', true], ['Book One/Places/Harbor Town.md', true]]);
});
// webby-0070 B1: a note whose name looks like it has an extension resolves before the attachment test.
test('an indexed Dr.Quinn.md resolves as a body link, a block list link and an embed', async t => {
const r = repo(t, { ...BASE, 'Book One/Characters/Dr.Quinn.md': 'q\n', 'Book One/Characters/Ana.md': ['---',
'relationships:', ' - "[[Dr.Quinn]]"', '---', '[[Dr.Quinn]] ![[Dr.Quinn]]', ''].join('\n') });
const result = await readLibrary({ repo: r.repo, commit: r.commit, mapping: mapping() });
assert.deepEqual(file(result, 'Book One/Characters/Ana.md').links.map(l => [l.field ?? null, l.path, l.line, l.embed]), [
[null, 'Book One/Characters/Dr.Quinn.md', 5, false], [null, 'Book One/Characters/Dr.Quinn.md', 5, true],
['relationships', 'Book One/Characters/Dr.Quinn.md', 3, false]]);
assert.deepEqual(result.problems.filter(p => p.path === 'Book One/Characters/Ana.md'), []);
});
test('R5: a canon file that refers into the playground is reported, and the link still goes by path', async t => {
const r = repo(t, { ...BASE, 'Book One/Places/Dock.md': 'See [[What If]].\n' });
const result = await readLibrary({ repo: r.repo, commit: r.commit, mapping: mapping() });
+1 -19
View File
@@ -39,31 +39,13 @@ test('the survey prints folder names, counts, key sets and link-form counts, and
' 1 [appears_in, name, type]',
' 1 [name]',
' 1 [type]',
'body links plain 3, label 1, heading 1, embed 0, self 0, markdown 1; attachment 0',
'body links plain 3, label 1, heading 1, embed 0, self 0, markdown 1',
'field appears_in wikilink 2, name 0',
'field relationships wikilink 1, name 1',
''].join('\n'));
for (const s of NEVER) assert.ok(!out.stdout.includes(s), s);
});
test('folder names print DEL, C1 and bidi controls, U+061C among them, as escapes', async t => {
// One name per escaped range, with each range's first and last code point.
const names = ['A\u007fB', 'C\u0080D\u009fE', 'F\u200eG\u200fH', 'I\u202aJ\u202eK', 'L\u2066M\u2069N', 'O\u061cP'];
const r = repo(t, Object.fromEntries(names.map(n => [`${n}/a.md`, `${MARKER}\n`])));
const out = await run(['survey', r.repo]);
assert.equal(out.code, 0, out.stderr);
assert.deepEqual(out.stdout.split('\n').slice(3, 9), [
' "A\\u007fB" 1 0 0 0', ' "C\\u0080D\\u009fE" 1 0 0 0', ' "F\\u200eG\\u200fH" 1 0 0 0',
' "I\\u202aJ\\u202eK" 1 0 0 0', ' "L\\u2066M\\u2069N" 1 0 0 0', ' "O\\u061cP" 1 0 0 0']);
assert.doesNotMatch(out.stdout, /[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/);
});
test('an embed of an attachment counts as an embed and as an attachment; a plain link to one does not', async t => {
const r = repo(t, { 'Book One/Chapters/A.md': ['![[cover.png]] ![[missing-note]] [[map.PDF]] [[Chapter 1.5]]', ''].join('\n') });
const out = await run(['survey', r.repo]);
assert.match(out.stdout, /^body links plain 2, label 0, heading 0, embed 2, self 0, markdown 0; attachment 1$/m);
});
test('with --mapping the survey adds scope, resolver step and problem counts', async t => {
const r = repo(t);
const out = await run(['survey', r.repo, '--mapping', join(FIXTURES, 'mapping.json')]);
-330
View File
@@ -1,330 +0,0 @@
#!/usr/bin/env node
// Case 2 row C2-20 (#1722): Bean's and Chet's personas from her two Hermes profiles into Mosaic
// persona files (design 4 and 9.1, brief docs/plans/2026-10-20_case2-rows.md "C2-20").
//
// case2-persona-import.mjs stage --hermes-root DIR --pair PROFILE=NAME --pair PROFILE=NAME
// (--staging DIR | --dry-run)
// case2-persona-import.mjs install --staging DIR --config-dir DIR --business ID
//
// stage runs as whoever can read her Hermes home. Per profile it reads SOUL.md, the persona Hermes
// loads (agent/prompt_builder.py:1829-1855 at df5700ebe), and config.yaml for the per-channel prompt
// names. Nothing else in the profile is opened: no memory store, state.db, session or message.
// Hermes has no field holding a profile's own name (profile.yaml carries only description,
// hermes_cli/profiles.py:798-850), so the human passes the pairing and the script prints it with each
// SOUL.md's byte count and sha256 before anything is written (sage-1836). NAME is Bean or Chet and
// the instance is its lower case. stage writes each persona, byte for byte, to a 0600 file in a new
// 0700 staging directory with a manifest of names and digests. Handing the directory to <user> is a
// root step between the two runs; the script changes no owner. install runs as <user>, checks each
// staged file against the manifest and C2-08's fence, and writes
// <configDir>/personas/<business>/<instance>.md at 0600. It never overwrites.
//
// Output is names, byte counts and sha256, never persona or prompt text. A key from config.yaml
// prints as a JSON string, so it can't start a line of its own. --dry-run writes nothing and prints
// counts only: files, lines, lines starting "# " or "## ", and lines naming a Hermes tool or channel
// from HERMES_WORDS. It applies C2-08's fence as stage does, prints each persona's fault by its
// reason and then refuses. A SOUL.md over four times the fence in bytes refuses before any count.
//
// Exit codes: 0 ok, 1 refused, 2 usage.
import { chmodSync, closeSync, constants, fchmodSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, unlinkSync, writeSync } from "node:fs";
import { createHash } from "node:crypto";
import { join } from "node:path";
import { parse as parseYaml } from "yaml";
import { PERSONA_CHARS, personaTextFault } from "../packages/harness/src/bundle.mjs";
// The tool names registered in hermes-agent's tools/*.py at df5700ebe (literal `name="..."` in
// registry.register calls; the MCP and plugin tools get their names at run time), plus Hermes and
// Discord (design 9.1). Matched as whole words, any case.
const HERMES_WORDS = Object.freeze([
"browser_back", "browser_cdp", "browser_click", "browser_console", "browser_dialog", "browser_get_images",
"browser_navigate", "browser_press", "browser_scroll", "browser_snapshot", "browser_type", "browser_vision",
"clarify", "close_terminal", "computer_use", "cronjob", "delegate_task", "discord", "discord_admin",
"execute_code", "feishu_doc_read", "feishu_drive_add_comment", "feishu_drive_list_comment_replies",
"feishu_drive_list_comments", "feishu_drive_reply_comment", "ha_call_service", "ha_get_state",
"ha_list_entities", "ha_list_services", "image_generate", "kanban_block", "kanban_comment", "kanban_complete",
"kanban_create", "kanban_heartbeat", "kanban_link", "kanban_list", "kanban_show", "kanban_unblock", "memory",
"patch", "process", "project_create", "project_list", "project_switch", "read_file", "read_terminal",
"search_files", "session_search", "skill_manage", "skill_view", "skills_list", "terminal", "text_to_speech",
"todo", "video_analyze", "video_generate", "vision_analyze", "web_extract", "web_search", "write_file",
"x_search", "xai_video_edit", "xai_video_extend", "yb_query_group_info", "yb_query_group_members",
"yb_search_sticker", "yb_send_dm", "yb_send_sticker",
"Hermes", "Discord",
]);
const WORD_LINE = new RegExp(`\\b(?:${HERMES_WORDS.join("|")})\\b`, "i");
const NAMES = Object.freeze(["Bean", "Chet"]);
const PROFILE_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/; // hermes_cli/profiles.py:37
const BUSINESS_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
const MANIFEST = "manifest.json";
const CONFIG_MAX = 4 * 1024 * 1024;
// The same split the fence's /^...$/m uses, so a counted heading line is one the fence refuses.
const LINE_BREAK = /\r\n|[\n\r\u2028\u2029]/;
const utf8 = new TextDecoder("utf-8", { fatal: true });
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
class Refusal extends Error {}
class Usage extends Error {}
function args(argv) {
const out = { pairs: [] };
for (let i = 0; i < argv.length; i++) {
const flag = argv[i];
if (flag === "--dry-run") { out.dryRun = true; continue; }
const value = argv[i + 1];
if (value === undefined || value.startsWith("--")) throw new Usage(`${flag} needs a value`);
i++;
if (flag === "--pair") out.pairs.push(value);
else if (flag === "--hermes-root") out.hermesRoot = value;
else if (flag === "--staging") out.staging = value;
else if (flag === "--config-dir") out.configDir = value;
else if (flag === "--business") out.business = value;
else throw new Usage(`unknown option ${flag}`);
}
return out;
}
// Exactly two pairs, two distinct profiles, Bean and Chet once each.
function pairing(pairs, hermesRoot) {
if (pairs.length !== 2) throw new Usage("give exactly two --pair PROFILE=NAME");
const out = pairs.map((p) => {
const m = /^([^=]+)=(.*)$/.exec(p);
if (!m) throw new Usage(`--pair ${p} isn't PROFILE=NAME`);
const [, profile, name] = m;
if (!PROFILE_ID.test(profile)) throw new Refusal(`profile ${profile} isn't a Hermes profile name`);
if (!NAMES.includes(name)) throw new Refusal(`profile ${profile} names ${JSON.stringify(name)}, not Bean or Chet`);
const dir = profile === "default" ? hermesRoot : join(hermesRoot, "profiles", profile);
const s = lstatSync(dir, { throwIfNoEntry: false });
if (!s) throw new Refusal(`profile ${profile}: ${dir} doesn't exist`);
if (!s.isDirectory()) throw new Refusal(`profile ${profile}: ${dir} isn't a directory`);
return { profile, name, instance: name.toLowerCase(), dir };
});
if (out[0].profile === out[1].profile) throw new Refusal(`profile ${out[0].profile} is paired twice`);
if (out[0].name === out[1].name) throw new Refusal(`${out[0].name} is named twice`);
return out;
}
// One regular file, opened without following a last-component symlink, at most max bytes.
function readFile(path, max, what) {
let fd;
try {
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
} catch (e) {
if (e.code === "ENOENT") return null;
if (e.code === "ELOOP") throw new Refusal(`${what} ${path} is a symlink`);
throw new Refusal(`${what} ${path} can't be opened (${e.code})`);
}
try {
const s = fstatSync(fd);
if (!s.isFile()) throw new Refusal(`${what} ${path} isn't a regular file`);
if (s.size > max) throw new Refusal(`${what} ${path} is over ${max} bytes`);
return { data: readFileSync(fd), stat: s };
} finally {
closeSync(fd);
}
}
// The persona Hermes loads: <profile dir>/SOUL.md. Hermes treats a missing or blank one as no
// persona, and so does this.
function soul(p) {
const path = join(p.dir, "SOUL.md");
const file = readFile(path, PERSONA_CHARS * 4, `profile ${p.profile}: persona`);
if (!file) throw new Refusal(`profile ${p.profile} has no persona (no SOUL.md)`);
let text;
try { text = utf8.decode(file.data); } catch { throw new Refusal(`profile ${p.profile}: persona ${path} isn't UTF-8 text`); }
if (!text.trim()) throw new Refusal(`profile ${p.profile} has no persona (SOUL.md is blank)`);
return { data: file.data, text };
}
// Per-channel prompts, by platform and channel id, from the three places Hermes takes a platform's
// block (gateway/config.py:1159-1178 at df5700ebe): <platform>, platforms.<platform> and
// gateway.platforms.<platform>, each with channel_prompts (:1233). Names and byte counts only.
function channelPrompts(config) {
const out = [];
const scan = (where, block) => {
if (!block || typeof block !== "object" || Array.isArray(block)) return;
for (const [platform, cfg] of Object.entries(block)) {
const prompts = cfg && typeof cfg === "object" ? cfg.channel_prompts : undefined;
if (!prompts || typeof prompts !== "object" || Array.isArray(prompts)) continue;
for (const [channel, value] of Object.entries(prompts)) {
out.push({ where: `${where}${platform}`, channel: String(channel), bytes: typeof value === "string" ? Buffer.byteLength(value) : null });
}
}
};
if (config && typeof config === "object") {
const { platforms, gateway, ...top } = config;
scan("", top);
scan("platforms.", platforms);
scan("gateway.platforms.", gateway?.platforms);
}
return out;
}
function config(p) {
const path = join(p.dir, "config.yaml");
const file = readFile(path, CONFIG_MAX, `profile ${p.profile}: config`);
if (!file) return [];
let doc;
// A Discord channel id is 18 or 19 digits, past a double's exact range, so unquoted ids parse as
// BigInt. Python's safe_load keeps the last of two equal keys, and so does this. yaml's warnings
// quote config text, so they are off.
try { doc = parseYaml(utf8.decode(file.data), { intAsBigInt: true, uniqueKeys: false, logLevel: "silent" }); } catch { throw new Refusal(`profile ${p.profile}: ${path} isn't YAML`); }
return channelPrompts(doc);
}
function counts(text) {
const lines = text.split(LINE_BREAK);
if (lines.at(-1) === "") lines.pop();
return {
lines: lines.length,
headings: lines.filter((l) => /^##? /.test(l)).length,
words: lines.filter((l) => WORD_LINE.test(l)).length,
};
}
// A new 0700 directory, or a check that an existing one is ours and closed to group and other.
function privateDir(path, { create }) {
const s = lstatSync(path, { throwIfNoEntry: false });
if (!s) {
if (!create) throw new Refusal(`${path} doesn't exist`);
try {
mkdirSync(path, { mode: 0o700 });
} catch (e) {
if (e.code === "EEXIST") throw new Refusal(`${path} was made by something else between the check and mkdir`);
throw e;
}
chmodSync(path, 0o700);
return;
}
if (!s.isDirectory()) throw new Refusal(`${path} isn't a directory`);
if (s.uid !== process.getuid()) throw new Refusal(`${path} isn't owned by uid ${process.getuid()}`);
if (s.mode & 0o077) throw new Refusal(`${path} has group or other mode bits`);
}
// A new 0600 file; refuses one that exists.
function writeNew(path, data) {
let fd;
try {
fd = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
} catch (e) {
if (e.code === "EEXIST") throw new Refusal(`${path} already exists`);
throw new Refusal(`${path} can't be created (${e.code})`);
}
try {
fchmodSync(fd, 0o600);
writeSync(fd, data);
} catch (e) {
closeSync(fd);
unlinkSync(path);
throw e;
}
closeSync(fd);
}
function stage(o, say) {
if (!o.hermesRoot) throw new Usage("stage needs --hermes-root");
if (!o.dryRun === !o.staging) throw new Usage("stage needs exactly one of --staging and --dry-run");
const pairs = pairing(o.pairs, o.hermesRoot);
const personas = pairs.map((p) => ({ ...p, ...soul(p) }));
if (o.dryRun) {
say(`files ${personas.length}`);
const faulted = [];
for (const p of personas) {
const c = counts(p.text);
say(`profile ${p.profile}: lines ${c.lines}, lines starting "# " or "## " ${c.headings}, lines naming a Hermes tool or channel ${c.words}`);
const fault = personaTextFault(p.text);
if (fault) { say(`profile ${p.profile}: persona ${fault}, so C2-08's fence would refuse it`); faulted.push(p.profile); }
}
if (faulted.length) throw new Refusal(`C2-08's fence would refuse the persona of profile ${faulted.join(" and ")}, so stage would write nothing`);
return;
}
for (const p of personas) {
say(`pairing: profile ${p.profile} is ${p.name} (instance ${p.instance}), SOUL.md ${p.data.length} bytes, sha256 ${sha256(p.data)}`);
}
for (const p of pairs) {
const prompts = config(p);
if (!prompts.length) say(`profile ${p.profile}: no per-channel prompts`);
for (const c of prompts) say(`profile ${p.profile}: per-channel prompt ${JSON.stringify(c.where)} ${JSON.stringify(c.channel)}, ${c.bytes === null ? "not text" : `${c.bytes} bytes`}`);
}
for (const p of personas) {
const fault = personaTextFault(p.text);
if (fault) throw new Refusal(`profile ${p.profile}: persona ${fault}, so C2-08's fence would refuse it; nothing written`);
}
privateDir(o.staging, { create: true });
const manifest = { version: 1, personas: [] };
for (const p of personas) {
writeNew(join(o.staging, `${p.instance}.md`), p.data);
manifest.personas.push({ instance: p.instance, name: p.name, bytes: p.data.length, sha256: sha256(p.data) });
}
writeNew(join(o.staging, MANIFEST), `${JSON.stringify(manifest, null, 2)}\n`);
for (const m of manifest.personas) say(`staged: ${join(o.staging, `${m.instance}.md`)}, ${m.bytes} bytes, sha256 ${m.sha256}`);
say(`next, as root: give ${o.staging} and its files to <user> (chown -R <user>: ${o.staging}), then as <user>:`);
say(` scripts/case2-persona-import.mjs install --staging ${o.staging} --config-dir <configDir> --business <business>`);
}
function staged(path, what) {
const file = readFile(path, PERSONA_CHARS * 4 + 64 * 1024, what);
if (!file) throw new Refusal(`${what} ${path} doesn't exist`);
if (file.stat.uid !== process.getuid()) throw new Refusal(`${what} ${path} isn't owned by uid ${process.getuid()}`);
if (file.stat.mode & 0o077) throw new Refusal(`${what} ${path} has group or other mode bits`);
return file.data;
}
function install(o, say) {
if (!o.staging || !o.configDir || !o.business) throw new Usage("install needs --staging, --config-dir and --business");
if (o.pairs.length || o.hermesRoot || o.dryRun) throw new Usage("install takes only --staging, --config-dir and --business");
if (!BUSINESS_ID.test(o.business)) throw new Refusal(`business ${o.business} isn't a business id`);
privateDir(o.staging, { create: false });
let manifest;
try { manifest = JSON.parse(staged(join(o.staging, MANIFEST), "manifest")); } catch (e) {
if (e instanceof Refusal) throw e;
throw new Refusal(`manifest ${join(o.staging, MANIFEST)} isn't JSON`);
}
const entries = manifest?.version === 1 && Array.isArray(manifest.personas) ? manifest.personas : null;
if (!entries || entries.length !== 2) throw new Refusal("the manifest doesn't list two personas");
const seen = new Set();
const personas = entries.map((m) => {
if (!NAMES.includes(m?.name) || m.instance !== m.name.toLowerCase() || seen.has(m.name)) throw new Refusal("the manifest doesn't pair Bean and Chet once each");
seen.add(m.name);
const data = staged(join(o.staging, `${m.instance}.md`), `staged persona ${m.instance}:`);
if (sha256(data) !== m.sha256) throw new Refusal(`staged persona ${m.instance} isn't the file the manifest names`);
let text;
try { text = utf8.decode(data); } catch { throw new Refusal(`staged persona ${m.instance} isn't UTF-8 text`); }
const fault = personaTextFault(text);
if (fault) throw new Refusal(`staged persona ${m.instance} ${fault}, so C2-08's fence would refuse it`);
return { ...m, data };
});
privateDir(o.configDir, { create: false });
const dir = join(o.configDir, "personas", o.business);
privateDir(join(o.configDir, "personas"), { create: true });
privateDir(dir, { create: true });
for (const p of personas) {
const target = join(dir, `${p.instance}.md`);
if (lstatSync(target, { throwIfNoEntry: false })) throw new Refusal(`${target} already exists; nothing written`);
}
for (const p of personas) writeNew(join(dir, `${p.instance}.md`), p.data);
for (const p of personas) {
say(`installed: ${join(dir, `${p.instance}.md`)}, ${p.data.length} bytes`);
say(`instance ${p.instance}: persona.name ${p.name}, persona.sha256 ${p.sha256}`);
}
}
function main(argv, say = (line) => process.stdout.write(`${line}\n`)) {
const [verb, ...rest] = argv;
try {
const o = args(rest);
if (verb === "stage") stage(o, say);
else if (verb === "install") install(o, say);
else throw new Usage("verb is stage or install");
return 0;
} catch (e) {
if (e instanceof Usage) { process.stderr.write(`case2-persona-import: ${e.message}\n`); return 2; }
if (e instanceof Refusal) { process.stderr.write(`case2-persona-import: refused: ${e.message}\n`); return 1; }
throw e;
}
}
process.exitCode = main(process.argv.slice(2));