geneseed 5.3.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +2 -2
  3. package/SHIPPED.md +1 -1
  4. package/adapters/bob/README.md +31 -18
  5. package/adapters/claude-code/README.md +27 -22
  6. package/adapters/openclaude/README.md +18 -8
  7. package/adapters/opencode/HOW-OPENCODE-LOADS.md +8 -3
  8. package/adapters/opencode/plugins/geneseed-activity.js +20 -21
  9. package/adapters/opencode/plugins/geneseed-context.js +169 -62
  10. package/adapters/opencode/plugins/geneseed-guard.js +414 -202
  11. package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
  12. package/adapters/opencode/workflows/_runtime.js +3 -2
  13. package/bin/geneseed-hook.mjs +57 -9
  14. package/docs/concepts/enforcement-table.md +1 -1
  15. package/docs/concepts/exclusions.md +2 -2
  16. package/docs/concepts/footprint.md +10 -0
  17. package/docs/concepts/hook-gates.md +3 -3
  18. package/docs/concepts/host-matrix.md +22 -4
  19. package/docs/design-history.md +8 -0
  20. package/docs/extending.md +49 -7
  21. package/docs/guides/install-bob.md +2 -2
  22. package/docs/guides/install-openclaude.md +1 -1
  23. package/docs/guides/verify.md +12 -0
  24. package/docs/reference/environment.md +1 -0
  25. package/docs/reference/troubleshoot-doctor.md +1 -1
  26. package/docs/token-footprint.md +66 -2
  27. package/docs/understand/design-choices-hosts.md +1 -1
  28. package/docs/understand/design-choices-shape.md +1 -0
  29. package/docs/understand/enforced-vs-asked.md +1 -1
  30. package/docs/understand/machine-bob.md +1 -1
  31. package/docs/web-ui.md +5 -0
  32. package/harness.config.json +1 -1
  33. package/js/README.md +3 -2
  34. package/js/build/args.mjs +1 -1
  35. package/js/build/driver.mjs +1 -1
  36. package/js/build/emit-claude.mjs +1 -1
  37. package/js/build/generate.mjs +5 -14
  38. package/js/hosts/done-checks.mjs +6 -0
  39. package/js/hosts/geneseed-dir.mjs +3 -2
  40. package/js/hosts/gitref.mjs +5 -3
  41. package/js/hosts/hook-tap.mjs +104 -0
  42. package/js/hosts/hooks-context.mjs +4 -2
  43. package/js/hosts/hooks-learn.mjs +47 -16
  44. package/js/hosts/hooks.mjs +19 -13
  45. package/js/hosts/hosts.mjs +80 -12
  46. package/js/hosts/installs.mjs +7 -0
  47. package/js/hosts/native.mjs +14 -5
  48. package/js/hosts/owned.mjs +7 -6
  49. package/js/hosts/ownership-gate.mjs +14 -1
  50. package/js/hosts/settings.mjs +245 -103
  51. package/js/hosts/shim.mjs +4 -4
  52. package/js/hosts/usage.mjs +9 -3
  53. package/js/inspect/checks-probe.mjs +66 -5
  54. package/js/inspect/checks-repo.mjs +196 -2
  55. package/js/inspect/cost.mjs +34 -2
  56. package/js/inspect/doctor.mjs +6 -1
  57. package/js/lib/machine-dir.mjs +1 -1
  58. package/js/lib/node-floor.mjs +46 -6
  59. package/js/maintain/uninstall.mjs +42 -16
  60. package/js/web/actions.mjs +1 -9
  61. package/package.json +1 -1
  62. package/web/dist/assets/Activity-WQ3ykgxU.js +1 -0
  63. package/web/dist/assets/{ActivityDetail-BSzevynX.js → ActivityDetail-7rt04SkS.js} +1 -1
  64. package/web/dist/assets/{Bonsai-Bfpb6W-1.js → Bonsai-BBl4XXqs.js} +1 -1
  65. package/web/dist/assets/{CopyButton-ByIntFtB.js → CopyButton-Beven8yn.js} +1 -1
  66. package/web/dist/assets/Dashboard-BgLArtgu.js +2 -0
  67. package/web/dist/assets/{Docs-DvlMJhpu.js → Docs-B5aHp86J.js} +3 -3
  68. package/web/dist/assets/Factories-BjqzXAw8.js +1 -0
  69. package/web/dist/assets/GreenhouseView-Bce212qd.js +1 -0
  70. package/web/dist/assets/{Installs-BlGmVrFK.js → Installs-B1OsrHXF.js} +3 -3
  71. package/web/dist/assets/JournalView-CV4omyww.js +1 -0
  72. package/web/dist/assets/{Kits-DRwpxC-J.js → Kits-CW1e7xNa.js} +1 -1
  73. package/web/dist/assets/{Laws-CZkiNOWQ.js → Laws-1Ckf1lbs.js} +2 -2
  74. package/web/dist/assets/{LibRows-DEHjIoD-.js → LibRows-Dag1s0ZX.js} +1 -1
  75. package/web/dist/assets/Library-B3FuFLel.js +3 -0
  76. package/web/dist/assets/Loops-CwqgnLNw.js +2 -0
  77. package/web/dist/assets/Markdown-CxkA7940.js +71 -0
  78. package/web/dist/assets/OperatorHudView-JmYY1pBR.js +1 -0
  79. package/web/dist/assets/{Personal-Bp9nV4GR.js → Personal-DKLgLa7Z.js} +2 -2
  80. package/web/dist/assets/Settings-BwErnh-R.js +1 -0
  81. package/web/dist/assets/{Tabs-CWeQTADL.js → Tabs-8zsyEPSK.js} +1 -1
  82. package/web/dist/assets/{index-CsAZq0BQ.css → index-CRWqKxfY.css} +1 -1
  83. package/web/dist/assets/index-Ce6qF2nG.js +6 -0
  84. package/web/dist/index.html +2 -2
  85. package/adapters/claude-code/settings.json +0 -52
  86. package/web/dist/assets/Activity-CqJiquEq.js +0 -1
  87. package/web/dist/assets/Dashboard-DBOEi9lQ.js +0 -2
  88. package/web/dist/assets/Factories-Bpvv7L2H.js +0 -1
  89. package/web/dist/assets/GreenhouseView-GpBsYn50.js +0 -1
  90. package/web/dist/assets/JournalView-iLuLrOxE.js +0 -1
  91. package/web/dist/assets/Library-B4K-1iNF.js +0 -3
  92. package/web/dist/assets/Loops-BWSzaW8E.js +0 -2
  93. package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
  94. package/web/dist/assets/OperatorHudView-BAXwCEvY.js +0 -1
  95. package/web/dist/assets/Settings-CWWuaIp-.js +0 -1
  96. package/web/dist/assets/index-How7SzDZ.js +0 -6
package/js/README.md CHANGED
@@ -103,6 +103,7 @@ user co-owns, and the hook verbs those emitted configs then run.
103
103
  | `hooks-prims.mjs` | The Python path/text primitives the hook verbs share (`splitLines`, `readStdin`, a never-throwing `isFile`), plus the activity off switch (`activityOn`) and the do-nothing `activity` verb |
104
104
  | `store-watch.mjs` | The change report: a session's baseline of the rule and memory files (`writeBaseline`, from the hook entry after `context`), the compare at Stop (`storeReport`, from `learn`), and `recordOwnWrites`, around Geneseed's own writers. It detects; it prevents nothing. The OpenCode guard holds the twin |
105
105
  | `activity.mjs` | The hook-side activity writer and the owner of snapshot liveness: `recordActivity` (one payload into `<root>/activity/`), `readTranscriptDelta`, `sweepActivity` (archive, newest 50, 7 days). Loaded only when tracking is on; never prints |
106
+ | `hook-tap.mjs` | The opt-in tap: with `GENESEED_HOOK_TAP=<dir>` set, one file per hook call recording the payload's SHAPE (keys kept, every string replaced by its type and length), for fixtures from a host the canary cannot run. Refuses a directory inside a git worktree. Imported only when the variable is set; never prints, never throws |
106
107
  | `usage.mjs` | The usage counter `tool-gate` runs: one `{day, kind, name}` line per Skill or subagent call into `notebook/usage.jsonl`. Hook path: builtins only, silent, never throws |
107
108
  | `memory-files.mjs` | The memory store's file format — `frontmatter`, `MEMORY.md` index writes, agent lessons, consolidate — the `user-rules.md` parser, the draft's format and the fold's ledger reader. No spawn: the CLI, web console and fold import it |
108
109
  | `geneseed-dir.mjs` | The Node writers into a project's `<git root>/.geneseed/`: the personal-by-default `.gitignore` (`GENESEED_GITIGNORE`, pinned to the two OpenCode copies), and the protected-checks seed every project emit runs (`seedProtectedChecks`: seed once when absent, then the user's — never recorded, rewritten or uninstalled). Never throws, never writes through a link. Spawn-free |
@@ -141,7 +142,7 @@ Everything that inspects an already-built or already-deployed harness and report
141
142
  | `validate.mjs` | The `validate` verb (the generator's old `--validate-only`): renders a sandbox, scans it for tokens and dead links, own exit contract |
142
143
  | `inventory.mjs` | The one catalog walk and its taxonomy tables, read by status, the TUI and the web console |
143
144
  | `status.mjs` | `geneseed status` and `version` — the panel data, counts, accent colour, version verdict |
144
- | `cost.mjs` | What one install injects every session, by part (root file, skill and agent lists, session files), in characters; owns `CARRIER_CEILING`, which the smoke test gates and the console draws |
145
+ | `cost.mjs` | What one install injects every session, by part (root file, skill and agent lists, session files), in characters; owns `CARRIER_CEILING`, which the smoke test gates and the console draws, and `SKILL_LISTING_CEILING`, which the smoke test gates and the console draws on a Claude Code install |
145
146
  | `diff.mjs` | `geneseed diff` — what a deployed install has that a fresh render of `src/` does not |
146
147
  | `excludes.mjs` | `geneseed exclude add|remove|list` — the WRITER for `excludes.json` and the shared list in the machine tier; `hosts.mjs` `sovereignBypass` reads both |
147
148
  | `registry.mjs` | `installs.json` under XDG — the persistent deploy-root list `rebuild-all` re-emits into |
@@ -172,7 +173,7 @@ into files users have committed, so change the test that states it in the same c
172
173
  | `prompt.mjs` | The line-mode stdin readers — `ask`, `promptLine`, `confirm`, `askChoice` — read a byte at a time so they stop where Enter stops. Shared by `setup`, `uninstall` and `web` without dragging in the wizard |
173
174
  | `managed-block.mjs` | Where the `<!-- BEGIN/END GENESEED -->` block is in a co-owned file: whole-line markers, the first END with the last BEGIN above it. One definition for the writer (`settings.mjs`) and the hook-side readers; no imports, so the hook path may load it. The OpenCode plugins carry `BLOCK_RE_SOURCE` by value |
174
175
  | `machine-dir.mjs` | `machineDir()`, `sharedPaths()`, `readDefaultInstall()` and `WIKI_NAMES`: the one home of `$XDG_CONFIG_HOME/geneseed`, the names beneath it, the reader of the chosen default install, and the wiki manifest's names. Spawn-free, so the hook and driver may import it |
175
- | `node-floor.mjs` | The first import of all three binaries: below Node 22.7, one sentence on stderr and exit 1 (0 in the hook) instead of a stack trace |
176
+ | `node-floor.mjs` | The first import of all three binaries: below Node 22.7, one sentence on stderr and exit 1 (0 in the hook, where a gate verb also asks) instead of a stack trace |
176
177
 
177
178
  **Before editing:** parse with `parseJson`, never `JSON.parse` — the latter collapses int `1` and
178
179
  float `1.0` into one double, and that value gets written into a user's file. Do not swap in a diff
package/js/build/args.mjs CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  import { DEFAULT_PRESET, PRESETS } from '../loop/score.mjs';
20
20
 
21
21
  /** The nine `--emit` choices: a plain bundle, then a project and a global emit per host. */
22
- const EMITS = ['files', 'opencode', 'opencode-global', 'claude', 'claude-global',
22
+ export const EMITS = ['files', 'opencode', 'opencode-global', 'claude', 'claude-global',
23
23
  'bob', 'bob-global', 'openclaude', 'openclaude-global'];
24
24
 
25
25
  /**
@@ -576,7 +576,7 @@ const CLAUDE_SHAPED = {
576
576
  summary: (at, r) => `[geneseed] bob-global -> ${at}: ${r.nAgents} subagents, `
577
577
  + `${r.nSkills} skills, rules/geneseed.md (Bob's always-injected channel; a global `
578
578
  + 'AGENTS.md is not auto-loaded, so none is written), '
579
- + `${r.nHooks} hook group(s), settings.json, ${r.memStatus}, ${r.nbStatus}.\n`,
579
+ + `${r.nHooks} hook group(s), settings/settings.json, ${r.memStatus}, ${r.nbStatus}.\n`,
580
580
  },
581
581
  // Per-repo: AGENTS.md at the root + a `.bob/` layer.
582
582
  bob: {
@@ -283,7 +283,7 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
283
283
  // recorded claims there, or they linger (and run) forever.
284
284
  const oldSf = get(old, 'settings_file') || 'settings.json';
285
285
  if (oldSf !== settingsName) {
286
- unwireClaudeSettings(path.join(cfgDir, oldSf), get(old, 'settings_hooks') || []);
286
+ unwireClaudeSettings(path.join(cfgDir, oldSf), get(old, 'settings_hooks') || [], cfgDir);
287
287
  unwireClaudeExcludes(path.join(cfgDir, oldSf), get(old, 'settings_excludes') || []);
288
288
  unwireClaudeEnv(path.join(cfgDir, oldSf), get(old, 'settings_env'));
289
289
  }
@@ -37,7 +37,7 @@ import { GATE_SWITCHES, makeCfg, PACK_ORDER } from './source.mjs';
37
37
  import { DEFAULT_PRESET } from '../loop/score.mjs';
38
38
  import { opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
39
39
  import {
40
- EMIT_HOST_SCOPE, defaultMode, defaultPosture, defaultTheme, doctrinesForBuild,
40
+ EMIT_FOR, EMIT_HOST_SCOPE, defaultMode, defaultPosture, defaultTheme, doctrinesForBuild,
41
41
  excludedRulesOfDir, excludedSkillsOfDir, footprintOfDir, kitsOfDir, sharedTierOfDir, gatesOfDir, installState, installTargets,
42
42
  modeOfDir, postureOfDir, readMaybe, themeOfDir, trustOfDir,
43
43
  } from '../hosts/installs.mjs';
@@ -185,18 +185,9 @@ export function setupBuildArgs(theme, emit, out = null, root = null, footprint =
185
185
  return argv;
186
186
  }
187
187
 
188
- /**
189
- * `_harness_build._DEFAULT_EMIT` — the emit to use for an install carrying NO marker.
190
- *
191
- * A pre-marker install still has a (host, scope), which is what the walk found it by, so it
192
- * is rebuilt in its own mode rather than defaulted to OpenCode.
193
- */
194
- const DEFAULT_EMIT = new Map([
195
- ['opencode global', 'opencode-global'], ['opencode project', 'opencode'],
196
- ['claude global', 'claude-global'], ['claude project', 'claude'],
197
- ['bob global', 'bob-global'], ['bob project', 'bob'],
198
- ['openclaude global', 'openclaude-global'], ['openclaude project', 'openclaude'],
199
- ]);
188
+ // The emit for an install carrying NO marker is `EMIT_FOR` (`js/hosts/installs.mjs`): a
189
+ // pre-marker install still has a (host, scope), which is what the walk found it by, so it is
190
+ // rebuilt in its own mode rather than defaulted to OpenCode.
200
191
 
201
192
  /**
202
193
  * Everything `rebuild-all` reads back off one install, and the argv that re-emits it unchanged.
@@ -216,7 +207,7 @@ export function installProfile(host, scope, root, notify = null) {
216
207
  const raw = readMaybe(path.join(root, '.geneseed-emit'));
217
208
  let marker = raw === null ? '' : raw.trim();
218
209
  if (marker && (EMIT_HOST_SCOPE.get(marker) ?? ['', ''])[0] !== host) marker = '';
219
- const emit = marker || DEFAULT_EMIT.get(`${host} ${scope}`) || 'opencode-global';
210
+ const emit = marker || EMIT_FOR.get(`${host} ${scope}`) || 'opencode-global';
220
211
  // Every read-back below is narrowed to `host`'s OWN carrier (host-compat B1): in a repo
221
212
  // shared with another Claude-style host, an un-narrowed scan answers with WHICHEVER host's
222
213
  // carrier the shared `CARRIERS` order favours — the wrong carrier for every host but one.
@@ -23,6 +23,10 @@ export function readDoneChecks(root) {
23
23
  }
24
24
  }
25
25
 
26
+ // ---- done-check tables twin: BEGIN — adapters/opencode/plugins/geneseed-context.js carries
27
+ // everything down to the END marker verbatim, with `export ` dropped (node tests/twins.mjs --write
28
+ // keeps it). Its `inferDoneChecks` is the async reading of the one below, kept by hand.
29
+
26
30
  // The package manager a lockfile names; first hit wins, npm without one. Exported for the gate that
27
31
  // holds the factory `checks` brick's restatement of these rules to this list (factory_graph test).
28
32
  export const PM_LOCKS = [['bun.lockb', 'bun'], ['bun.lock', 'bun'], ['pnpm-lock.yaml', 'pnpm'], ['yarn.lock', 'yarn']];
@@ -58,6 +62,8 @@ const MANIFEST_CHECKS = [
58
62
  ['Cargo.toml', { label: 'cargo test', forms: ['cargo test'], refuse: /(?:^|\s)--no-run(?=\s|$)/ }],
59
63
  ['go.mod', { label: 'go test', forms: ['go test'] }],
60
64
  ];
65
+
66
+ // ---- done-check tables twin: END
61
67
  /**
62
68
  * Every root manifest the checks are inferred from — what an emit seeds into the protected list.
63
69
  * @type {string[]}
@@ -24,8 +24,9 @@ import { gitRootOf } from './gitref.mjs';
24
24
  /**
25
25
  * The `.geneseed/.gitignore` every writer creates: personal by default, the team paths allowed
26
26
  * back. Anchored `/*`: a bare `*` matches at every depth and would hide `bricks/x.md` even under
27
- * `!bricks/`. The same string lives in `adapters/opencode/plugins/geneseed-workflow.js`,
28
- * `adapters/opencode/workflows/_runtime.js` and `src/skills/_checkpoints.md`; tests pin them.
27
+ * `!bricks/`. `adapters/opencode/plugins/geneseed-workflow.js` and
28
+ * `adapters/opencode/workflows/_runtime.js` carry this line (`node tests/twins.mjs --write`
29
+ * after changing it); `src/skills/_checkpoints.md` restates it by hand, and a test pins that.
29
30
  */
30
31
  export const GENESEED_GITIGNORE = '/*\n!/.gitignore\n!/bricks/\n!/loops/\n!/factories/\n!/protected-checks.txt\n!/done-checks.txt\n';
31
32
 
@@ -13,10 +13,12 @@
13
13
  * import. A module that is fs/path only is importable from anywhere.
14
14
  *
15
15
  * The OpenCode guard plugin (`adapters/opencode/plugins/geneseed-guard.js`) is copied whole
16
- * into an install and cannot import this, so it carries twins of `gitRootOf`, `gitDirOf`,
16
+ * into an install and cannot import this, so it carries copies of `gitRootOf`, `gitDirOf`,
17
17
  * `gitCommonDirOf`, `currentBranch`, `protectedBranches` and `stashExists` for its Law IV and
18
- * protected-checks gates. `tests/plugins/guard.test.mjs` compares each with the original here;
19
- * change one, change both.
18
+ * protected-checks gates, and the activity plugin of `gitRootOf`, `gitDirOf` and
19
+ * `mainWorktreeOf`. After changing one here, `node tests/twins.mjs --write` — so those
20
+ * functions may use nothing the plugins do not import (`existsSync`, `statSync`,
21
+ * `readFileSync`, `readdirSync`, `path`).
20
22
  */
21
23
  import { existsSync, statSync, lstatSync, readFileSync, readdirSync, openSync, readSync, closeSync } from 'node:fs';
22
24
  import path from 'node:path';
@@ -0,0 +1,104 @@
1
+ /**
2
+ * THE HOOK TAP: an opt-in record of what a host really sends a hook, as a fixture.
3
+ *
4
+ * `GENESEED_HOOK_TAP=<dir>` in the environment the HOST runs under, and every hook call writes
5
+ * one file, `<dir>/<host>-<event>-<n>.json`, after the verb has decided and printed.
6
+ *
7
+ * WHY IT EXISTS. What a host puts on a hook's stdin is the one input this repo cannot derive:
8
+ * Bob's payload was first read off its docs (`{event, tool, input}`), then off its shipped
9
+ * bundle (Claude's keys plus `cwd`), and neither is a recording. Bob is not on npm, so the
10
+ * canary cannot ask it (docs/concepts/host-matrix.md, "What is verified"). A person with the
11
+ * host can: set the variable, do one thing per event, send the files. Each is then a row in a
12
+ * test instead of a sentence in a docblock.
13
+ *
14
+ * WHAT IT WRITES IS THE SHAPE, NOT THE VALUES. A payload carries the user's prompt, file
15
+ * contents, commands and paths, and a tap file is made to be sent to someone else. So every
16
+ * string becomes `{ type: 'string', length: n }`, at any depth. The exceptions are the few
17
+ * top-level strings that say which event and which tool this is (`KEPT`); they come from the
18
+ * host's own vocabulary, and still pass through Law I's pattern (`SECRET_RE`, the activity
19
+ * writer's redaction). Numbers, booleans and null are kept: they are flags and counts. Keys
20
+ * are kept: they are the whole point.
21
+ *
22
+ * WHAT IT REFUSES, silently, like everything on the hook path:
23
+ * - a tap directory inside a git worktree (`gitRootOf`): a capture must not be one `git add`
24
+ * away from a commit;
25
+ * - a relative directory: a hook's cwd is the session's project;
26
+ * - a model-CLI child `learn` spawned (`GENESEED_LEARN_CHILD`), whose hooks are not the host's.
27
+ *
28
+ * IT NEVER PRINTS AND NEVER THROWS. A hook's stdout is its verdict and its exit code is the
29
+ * block; the caller wraps this too. The variable is read from the environment only and no emit
30
+ * ever writes it into a settings file (`tests/unit/hook_tap.test.mjs` holds both).
31
+ *
32
+ * Loaded by `bin/geneseed-hook.mjs` through a dynamic import, and only when the variable is
33
+ * set, so a hook that is not tapped pays one `process.env` read.
34
+ */
35
+ import { mkdirSync, writeFileSync } from 'node:fs';
36
+ import path from 'node:path';
37
+
38
+ import { gitRootOf } from './gitref.mjs';
39
+ import { SECRET_RE } from './hooks-prims.mjs';
40
+
41
+ /** The top-level strings kept as written: which event, which tool, and how it was triggered. */
42
+ const KEPT = new Set(['hook_event_name', 'event', 'tool_name', 'tool', 'source', 'trigger',
43
+ 'permission_mode', 'agent_type', 'matcher']);
44
+
45
+ const SECRET_ALL = new RegExp(SECRET_RE.source, 'g');
46
+ /** A kept string, cut and with anything credential-shaped replaced. */
47
+ const kept = (s) => s.slice(0, 80).replace(SECRET_ALL, '[redacted]');
48
+
49
+ /** How deep a payload is followed. Deeper values become `{ type: 'depth' }`. */
50
+ const MAX_DEPTH = 12;
51
+ /** The most files one event name may fill; the tap then stops rather than fill a disk. */
52
+ const MAX_FILES = 1000;
53
+
54
+ /**
55
+ * `value` with every string replaced by its type and length, keys and structure kept.
56
+ * `top` is true for the payload's own keys, the only place `KEPT` applies.
57
+ */
58
+ export function shapeOf(value, top = true, depth = 0) {
59
+ if (typeof value === 'string') return { type: 'string', length: value.length };
60
+ if (value === null || typeof value !== 'object') return value;
61
+ if (depth >= MAX_DEPTH) return { type: 'depth' };
62
+ if (Array.isArray(value)) return value.map((v) => shapeOf(v, false, depth + 1));
63
+ const out = {};
64
+ for (const [k, v] of Object.entries(value)) {
65
+ out[k] = top && KEPT.has(k) && typeof v === 'string' ? kept(v) : shapeOf(v, false, depth + 1);
66
+ }
67
+ return out;
68
+ }
69
+
70
+ /** A file-name part: letters, digits, `_` and `-` only, never empty. */
71
+ const part = (s, fallback) => (typeof s === 'string' && s.replace(/[^A-Za-z0-9_-]/g, '').slice(0, 40)) || fallback;
72
+
73
+ /**
74
+ * Write one tap file for `raw`, the hook's stdin. Returns the file's path, or null when
75
+ * nothing was written (refused, or the directory is full). Never throws.
76
+ */
77
+ export function tapPayload(dir, raw, { verb, host }) {
78
+ try {
79
+ if (process.env.GENESEED_LEARN_CHILD) return null;
80
+ if (typeof dir !== 'string' || !path.isAbsolute(dir) || gitRootOf(dir)) return null;
81
+ let payload = null;
82
+ try { payload = JSON.parse(raw); } catch { /* not JSON: recorded as such, by length */ }
83
+ const isObject = payload !== null && typeof payload === 'object' && !Array.isArray(payload);
84
+ const event = part(isObject ? (payload.hook_event_name ?? payload.event) : null, verb);
85
+ const body = `${JSON.stringify({
86
+ tap: { host, verb, json: payload !== null || raw.trim() === 'null', bytes: raw.length },
87
+ payload: shapeOf(payload),
88
+ }, null, 2)}\n`;
89
+ mkdirSync(dir, { recursive: true });
90
+ for (let n = 1; n <= MAX_FILES; n += 1) {
91
+ const file = path.join(dir, `${part(host, 'host')}-${event}-${n}.json`);
92
+ try {
93
+ // `wx`: two hooks of one turn run at once, and neither may take the other's number.
94
+ writeFileSync(file, body, { flag: 'wx' });
95
+ return file;
96
+ } catch (e) {
97
+ if (e.code !== 'EEXIST') return null;
98
+ }
99
+ }
100
+ return null;
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
@@ -97,7 +97,7 @@ const EXCLUDE_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'vendor',
97
97
  // The OpenCode context plugin carries the same rule for AGENT.md/AGENTS.md/CLAUDE.md.
98
98
  // OpenClaude's root file is AGENTS.md, or CLAUDE.md when AGENTS.md is absent — resolved
99
99
  // per repo in `discoverContext`, since which one it loads depends on what is on disk.
100
- const NATIVE_ROOT = {
100
+ export const NATIVE_ROOT = {
101
101
  claude: ['CLAUDE.md'], bob: ['AGENTS.md'],
102
102
  openclaude: ['AGENTS.md', 'CLAUDE.md'],
103
103
  };
@@ -848,6 +848,8 @@ export function cmdContext(args) {
848
848
  // Discovery (and the stand-down) runs against the SESSION's project root, not the harness
849
849
  // package dir: `$CLAUDE_PROJECT_DIR` when the host sets it (`hookProjectDir`), because
850
850
  // SessionStart also fires on resume/compact/clear, after the agent may have `cd`'d away.
851
+ // `args.cwd` is the payload's `cwd`, which the hook entry already parsed: Bob sets no such
852
+ // variable, and its payload names the root workspace.
851
853
  // The only two `resolvePath` calls in this file whose argument can be a `~user` path the
852
854
  // user typed — `$GENESEED_ROOT` and `--root` — and `resolvePath` expands, so both can now
853
855
  // throw. Every other caller either builds its argument by `path.join` from an absolute
@@ -857,7 +859,7 @@ export function cmdContext(args) {
857
859
  let hookRoot;
858
860
  try {
859
861
  ({ root, hookRoot } = withDiscardableStderr(() => ({
860
- root: resolvePath(process.env.GENESEED_ROOT || hookProjectDir()),
862
+ root: resolvePath(process.env.GENESEED_ROOT || hookProjectDir(args && args.cwd)),
861
863
  hookRoot: args.root ? resolvePath(args.root) : null,
862
864
  })));
863
865
  } catch {
@@ -24,9 +24,9 @@ const ROOT = path.resolve(import.meta.dirname, '../..');
24
24
 
25
25
  const AGENT_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
26
26
  const MAX_NOTES_CHARS = 16000;
27
- // Host payloads name the finished subagent inconsistently; try each.
28
- const SUBAGENT_NAME_FIELDS = ['agent_name', 'agent_type', 'subagent_type', 'agent',
29
- 'agent_id'];
27
+ // Host payloads name the finished subagent inconsistently. Never `agent_id`: it is one dispatch's
28
+ // id, so a lesson keyed on it is a file per dispatch that no later dispatch ever reads.
29
+ const SUBAGENT_NAME_FIELDS = ['agent_name', 'agent_type', 'subagent_type', 'agent'];
30
30
 
31
31
  const PLUGIN_LEARN = path.join(ROOT, 'adapters', 'opencode', 'plugins', 'geneseed-learn.js');
32
32
 
@@ -74,6 +74,17 @@ export function resolveAgentName(raw) {
74
74
  return name && AGENT_NAME_RE.test(name) ? name : null;
75
75
  }
76
76
 
77
+ /**
78
+ * The agent a SubagentStop payload names, as a safe slug, or null. The FIRST field present
79
+ * decides, and a value that is no slug yields no lesson: a plugin's agent arrives namespaced
80
+ * (`plug:rev`), and falling through to a later field would file its lesson under another name.
81
+ * Exported for the unit tier, like `readNotes` below.
82
+ */
83
+ export function subagentNameOf(meta) {
84
+ const field = SUBAGENT_NAME_FIELDS.find((f) => meta[f] !== undefined && meta[f] !== null && meta[f] !== '');
85
+ return field ? resolveAgentName(meta[field]) : null;
86
+ }
87
+
77
88
  /** The lifecycle-hook payload if stdin is one, else `{}`. */
78
89
  function hookMeta(raw) {
79
90
  const s = raw.trim();
@@ -216,9 +227,22 @@ export function buildLearnPrompt(notes, facts) {
216
227
  * distilled memory carrying an accent or an em dash is WRITTEN to the store, so a
217
228
  * mis-decode outlives the process. `maxBuffer` is lifted off Node's 1 MB default, which
218
229
  * would truncate a long reply into a silently-half-parsed set of memory files.
230
+ *
231
+ * BOUNDED: a model CLI that hangs (a login prompt, a dead network) used to hold Stop until the
232
+ * host's own hook timeout killed the hook, and that kill loses whatever the hook had still to
233
+ * say. `$GENESEED_LLM_TIMEOUT` is the limit in seconds, 120 unless it names a positive number.
234
+ * A CLI stopped at the limit has said nothing usable, so its partial reply is dropped, never
235
+ * parsed into half a memory file: one stderr line, and the run ends as if it answered nothing.
219
236
  */
237
+ const LLM_TIMEOUT_S = 120;
238
+ function llmTimeoutSeconds() {
239
+ const n = Number(process.env.GENESEED_LLM_TIMEOUT);
240
+ return Number.isFinite(n) && n > 0 ? n : LLM_TIMEOUT_S;
241
+ }
242
+
220
243
  function runLlm(llm, prompt) {
221
244
  const argv = splitWords(llm);
245
+ const seconds = llmTimeoutSeconds();
222
246
  // `NO_WINDOW` folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
223
247
  // otherwise pops a console for as long as it takes to answer.
224
248
  //
@@ -228,8 +252,12 @@ function runLlm(llm, prompt) {
228
252
  // killing the outermost call. The marker rides in the child's own environment (inherited by
229
253
  // every grandchild too), and `cmdLearn`'s first line stands down the instant it sees it.
230
254
  const proc = spawnSync(argv[0], [...argv.slice(1), prompt],
231
- { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024,
255
+ { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, timeout: seconds * 1000, killSignal: 'SIGKILL',
232
256
  env: { ...process.env, GENESEED_LEARN_CHILD: '1' }, ...NO_WINDOW });
257
+ if (proc.error && /** @type {NodeJS.ErrnoException} */ (proc.error).code === 'ETIMEDOUT') {
258
+ err(`[learn] ${argv[0]} gave no answer in ${seconds} s and was stopped - nothing learned.\n`);
259
+ return { stdout: '', stderr: '', returncode: 0, error: null };
260
+ }
233
261
  // Universal newlines, because Python reads the pipe in TEXT mode: a model CLI that is
234
262
  // itself a Python script emits CRLF on Windows, `subprocess` folds it to `\n`, and
235
263
  // `write_text` expands it again on the way into the memory file. Node hands back the raw
@@ -253,11 +281,7 @@ function runLlm(llm, prompt) {
253
281
  * parity of mechanism, degrading to a no-op, never a crash.
254
282
  */
255
283
  function learnAgentLesson(meta, notes, args) {
256
- let agent = null;
257
- for (const field of SUBAGENT_NAME_FIELDS) {
258
- agent = resolveAgentName(meta[field]);
259
- if (agent) break;
260
- }
284
+ const agent = subagentNameOf(meta);
261
285
  if (!agent) return 0;
262
286
  const memDir = resolveMemoryDir(args.memory);
263
287
  if (!memDir) return 0;
@@ -283,7 +307,9 @@ function learnAgentLesson(meta, notes, args) {
283
307
  }
284
308
  }
285
309
  if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
286
- return proc.returncode;
310
+ // Only a SubagentStop hook reaches this, and the model CLI's code is not the hook's: exit 2
311
+ // there sends the subagent back to work. The failure is on stderr above.
312
+ return 0;
287
313
  }
288
314
 
289
315
  /** `--memory` of a global install's hook, swapped for the shared store when that exists. */
@@ -428,13 +454,18 @@ export function cmdLearn(args) {
428
454
  if (!created.length && !updated.length && !archived.length) {
429
455
  err('[learn] nothing new to store (all duplicates).\n');
430
456
  }
431
- } else if (verdict === 'advisory') {
432
- err(output);
433
- } else {
457
+ } else if (!hookEvent) {
458
+ // A person running `learn` by hand with no store: the reply is what they asked to see.
434
459
  out(output);
460
+ } else if (output.trim() && output.trim().toUpperCase() !== 'NOTHING') {
461
+ // On a hook call stdout is the host's: it holds at most ONE JSON document (the change report
462
+ // or an advisory above), and the model's raw words after it made two, which no host parses,
463
+ // so the report was lost. A bare NOTHING says nothing and is dropped.
464
+ err(output);
435
465
  }
436
466
  if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
437
- // After an advisory, the model CLI's code is not this hook's: exit 2 on Stop would turn the
438
- // advisory into a block, and any non-zero drops the JSON already on stdout.
439
- return verdict === 'advisory' ? 0 : proc.returncode;
467
+ // On a hook call the model CLI's code is not this hook's: exit 2 on Stop or PreCompact blocks
468
+ // the turn's end or the compaction, and any non-zero drops the JSON already on stdout. The
469
+ // failure is on stderr above. A manual run keeps the code, so a script can test it.
470
+ return hookEvent ? 0 : proc.returncode;
440
471
  }
@@ -12,7 +12,7 @@
12
12
  * (the default) reads `hookSpecificOutput.permissionDecision: "ask"` and shows the user a
13
13
  * prompt; the one `"deny"` (the ownership first-write gate, `./ownership-gate.mjs`) carries
14
14
  * its reason to the MODEL instead. `--host bob` is Bob's own protocol: PreToolUse ignores stdout and refuses only on
15
- * EXIT CODE 2, so `BLOCK_RULES` (Laws I and IV, plus rigor-5 and ops-2) exit 2 with the reason on stderr,
15
+ * EXIT CODE 2, so the rules in `BLOCK_RULES` (below) exit 2 with the reason on stderr,
16
16
  * as does the ownership gate (through `deny`, with a one-time tail in place of `BOB_FINAL`),
17
17
  * and the rest is a stderr line with exit 0; SessionStart context is plain stdout, as on
18
18
  * Claude. `--host openclaude` speaks Claude's dialect verbatim (OpenClaude is a Claude Code
@@ -42,9 +42,9 @@
42
42
  * THE CONTRACT EVERY VERB HOLDS. Exit 0 on every path, and signal through stdout. A hook
43
43
  * that fails is a tool call that fails, so an unreadable payload, a missing file, a
44
44
  * malformed user config and a bypass all end the same way: quietly, with 0. The single
45
- * exception is `learn`, which returns the model CLI's own exit code — an auth or quota
46
- * failure has to be diagnosable, and its hook command carries `|| exit 0` for exactly that
47
- * reason.
45
+ * exception is `learn` run BY HAND, which returns the model CLI's own exit code so a script can
46
+ * test it. On a hook call `learn` returns 0 like every other verb — exit 2 on Stop or PreCompact
47
+ * would block the turn's end — and an auth or quota failure is diagnosable from its stderr.
48
48
  *
49
49
  * The gate is `tests/helpers/cli_golden.mjs` replaying `tests/helpers/matrix/cli.{posix,win32}.json`:
50
50
  * each verb run in a seeded sandbox, with ABSOLUTE assertions on stdout, stderr, the exit code
@@ -59,7 +59,7 @@ import { machineDir } from '../lib/machine-dir.mjs';
59
59
  import { markerLines } from '../lib/managed-block.mjs';
60
60
  import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
61
61
  import {
62
- GATE_LEDGER, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
62
+ GATE_LEDGER, HOSTS, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
63
63
  resolvePath, sovereignBypass,
64
64
  } from './hosts.mjs';
65
65
  import {
@@ -304,7 +304,7 @@ const BOB_FINAL = ' Bob has no approval step for this gate: neither a confirmati
304
304
  * credential in a tracked file and a history-discarding git act are wrong in every context,
305
305
  * so refusing them costs nothing. rigor-5 (External Gate) joins them: a protected check the
306
306
  * agent can edit is not a check, so it is as unconditional as the two Laws — NOT "Laws I/IV
307
- * only", see bob-code.md B3. process-1 too (owner decision, 2026-11): with no prompt, a warning
307
+ * only". process-1 too (owner decision, 2026-11): with no prompt, a warning
308
308
  * let the agent write the user's rules on its own say. Memory is written freely (owner decision,
309
309
  * 2026-11-08), so a memory write reaches no rule here. Process 5 is the USER's call
310
310
  * as well, but a hard block would make Bob unable to commit at all, so it stays a warning the
@@ -1122,7 +1122,9 @@ function protectedIn(target) {
1122
1122
  * not gated. Reached from a shell command too, with the same limit as `protectedCheck`.
1123
1123
  */
1124
1124
  const GATE_CONFIG_FILES = ['settings.json', 'settings.local.json', 'settings/settings.json', 'rules/geneseed.md', 'excludes.json', 'AGENT.md', '.geneseed-manifest.json', '.geneseed-emit', 'opencode.json', 'opencode.jsonc'];
1125
- const GATE_CONFIG_MARKERS = ['.claude', '.openclaude', '.bob', '.opencode'];
1125
+ // Every host's project dir, read from the host table so a new host's settings are gate
1126
+ // configuration the day it gets a row. Exported for the tests that write the list out.
1127
+ export const GATE_CONFIG_MARKERS = HOSTS.map((h) => h.projectMarker);
1126
1128
  function gateConfig(p, root) {
1127
1129
  let bin = null;
1128
1130
  try {
@@ -1378,7 +1380,7 @@ export function ruleDecide(args, payload) {
1378
1380
  // settings matcher that routes here (Claude verdict R2); the `edits[]` read stays as a
1379
1381
  // cheap, harmless guard in case that ever changes.
1380
1382
  // `diff` (Bob's `apply_diff`) and `replace`/`search` (`search_and_replace`) are Roo-lineage
1381
- // field names the Bob docs never confirm (bob-verdict.md I1) — accepted when present, never
1383
+ // field names the Bob docs never confirm — accepted when present, never
1382
1384
  // required, same as every field above. Only WRITTEN text is scanned: `search` and a diff's
1383
1385
  // SEARCH halves are text leaving the file (like Claude's `old_string`), so a secret there is
1384
1386
  // being removed — blocking it would stop the agent cleaning up a leak.
@@ -1392,9 +1394,12 @@ export function ruleDecide(args, payload) {
1392
1394
  return ask(args, 'rule-gate', 'law-1', 'secret', { name: repoRel(carrier, payload) });
1393
1395
  }
1394
1396
  // Bob routes reads here too (`read_file` carries a path): only a write is External Gate's business.
1395
- // shortcut: a write is told by its tool name, so a Bob write tool named outside WRITE_NAME_RE
1396
- // passes both gates; switch to an allowlist of Bob's read tools if Bob adds or renames one.
1397
- const bobRead = HOST === 'bob' && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
1397
+ // A call that carries text to write is a write whatever its tool is called (`create_file`,
1398
+ // `append_to_file`, `apply_patch`, `save_file`): Bob's tool names are undocumented, so the name
1399
+ // alone let those past the store and gate-config checks. `ownershipBlock` reads a write the same way.
1400
+ // shortcut: a write that carries no text under a name outside WRITE_NAME_RE still reads as a
1401
+ // read; switch to an allowlist of Bob's read tools if Bob adds one.
1402
+ const bobRead = HOST === 'bob' && !body && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
1398
1403
  for (const q of bobRead ? [] : paths) {
1399
1404
  // The carrier rule is a write tool's alone: a shell call reaches `externalGate` with nothing to replay.
1400
1405
  const hit = externalGate(args, q, payload)
@@ -1424,8 +1429,9 @@ export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
1424
1429
  // ======================================================================================
1425
1430
 
1426
1431
  /**
1427
- * Bob's documented PreToolUse payload (bob-verdict.md I1) is `{event, session_id, tool,
1428
- * input:{...}}` — none of `tool_input`, `tool_name` or `hook_event_name` exist. Normalised
1432
+ * The LEGACY Bob PreToolUse payload is `{event, session_id, tool, input:{...}}`, with none of
1433
+ * `tool_input`, `tool_name` or `hook_event_name`; Bob 2.2.3 sends Claude's keys (bundle read
1434
+ * 2026-10, docs/concepts/host-matrix.md "What is verified"), and both are read. Normalised
1429
1435
  * HERE, once, at Bob's one entry point (`toolGate` is the only verb its settings.json invokes
1430
1436
  * for PreToolUse), so `gitDecide`/`ruleDecide` keep reading the Claude shape unchanged and
1431
1437
  * never learn Bob exists. A no-op for an already-Claude-shaped payload: every field it sets
@@ -197,6 +197,50 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
197
197
  }
198
198
  }
199
199
 
200
+ // The marker lives in the shim's FILENAME, not its directory: GENESEED_HOME relocates the dir,
201
+ // and a relocated install's hooks must stay recognisable to `GENESEED_HOOK_SNIFF`. Declared here
202
+ // rather than in ./shim.mjs because `ownHookVerb` below reads it, and shim.mjs imports this module.
203
+ export const SHIM_MARK = 'geneseed-hook';
204
+
205
+ /** The verbs `bin/geneseed-hook.mjs` answers (its `VERBS` table). */
206
+ const HOOK_VERBS = 'context|git-gate|rule-gate|tool-gate|learn|activity';
207
+ /** A command that runs one of them: every emitted form is `<runner> <verb> --root|--memory …`. */
208
+ const RUNS_HOOK_VERB = new RegExp(` (?:${HOOK_VERBS}) --`);
209
+ /** The verb token after the shim's name: the rest of its path, a closing quote, then the verb. */
210
+ const VERB_AFTER_SHIM = new RegExp(`^[^"]*"? (${HOOK_VERBS})(?= |$)`);
211
+
212
+ /**
213
+ * The hook verb `command` runs FOR THE INSTALL AT `cfg`, or null when the handler is not that
214
+ * install's. The one test of "is this handler Geneseed's", shared by the settings merge, the
215
+ * unwire and the integrity check (`js/hosts/settings.mjs`).
216
+ *
217
+ * A SIGNATURE, not deep equality with what this build would emit. Equality broke four ways: a
218
+ * re-emit with other gate flags and no manifest stacked a second group beside the first; a group
219
+ * already on file was never claimed, so uninstall left it running; a user's own `"timeout": 30`
220
+ * on our handler made it a stranger; and the integrity check then reported that handler missing.
221
+ * So a handler is ours when its command names the shim (`SHIM_MARK`), then a hook verb, and
222
+ * carries exactly `--root "<cfg>"` or `--memory "<cfg>/memory"`. Flags, `--host` and every other
223
+ * field are free to differ. The closing quote makes the root exact: `<cfg>-old` is another
224
+ * install, and a global and a project install differ by root, so neither claims the other's.
225
+ *
226
+ * A hand-written hook that runs our binary with our root therefore counts as ours (the maintainer
227
+ * accepted that, 2026-11): a re-emit replaces it and uninstall removes it.
228
+ *
229
+ * The PowerShell form backtick-escapes `$` and a backtick inside the path (`powershellForm`), so
230
+ * the command is read both as written and with those undone; Windows compares paths case-folded.
231
+ */
232
+ export function ownHookVerb(command, cfg) {
233
+ if (typeof command !== 'string' || typeof cfg !== 'string' || !cfg) return null;
234
+ const at = command.indexOf(SHIM_MARK);
235
+ if (at < 0) return null;
236
+ const verb = VERB_AFTER_SHIM.exec(command.slice(at + SHIM_MARK.length))?.[1];
237
+ if (!verb) return null;
238
+ const fold = (s) => (process.platform === 'win32' ? s.toLowerCase() : s);
239
+ const wanted = [` --root "${cfg}"`, ` --memory "${path.join(cfg, 'memory')}"`].map(fold);
240
+ const readings = [command, command.replace(/`([`$])/g, '$1')].map(fold);
241
+ return readings.some((c) => wanted.some((w) => c.includes(w))) ? verb : null;
242
+ }
243
+
200
244
  /**
201
245
  * The hook handlers the install at `cfg` both RECORDS and still RUNS: `[event, handler]` pairs
202
246
  * from its manifest's `managed.settings_hooks` whose command the settings file that manifest
@@ -204,13 +248,20 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
204
248
  * the host runs. A user who deletes `hooks` by hand keeps the manifest (re-review, Important).
205
249
  * Absent, unparseable or COMMENTED settings fail `JSON.parse` and answer `[]`. Shared by
206
250
  * `projectWiresVerb` and the hook-shell drift check (`hookShellProblems`).
251
+ *
252
+ * Only a recorded handler that runs a hook verb: a claim is the whole group as it sat on file,
253
+ * so it can hold a hook the user added to our group, and that one is not this install's. The
254
+ * shim is NOT required here, unlike `ownHookVerb`: doctor's probe must still be handed a
255
+ * recorded gate that names another binary, to report it. Liveness compares the command alone,
256
+ * so a field the user set on our handler (`timeout`) does not make it read as gone.
207
257
  */
208
258
  export function liveRecordedHooks(cfg) {
209
259
  const readJson = (p) => { try { return JSON.parse(readText(p)); } catch { return null; } };
210
260
  const managed = readJson(path.join(cfg, GLOBAL_MANIFEST))?.managed;
211
261
  const recorded = Array.isArray(managed?.settings_hooks) ? managed.settings_hooks : [];
212
262
  const wanted = recorded.flatMap((r) => (Array.isArray(r?.group?.hooks) ? r.group.hooks : [])
213
- .filter((h) => typeof h?.command === 'string').map((h) => [r.event, h]));
263
+ .filter((h) => typeof h?.command === 'string' && RUNS_HOOK_VERB.test(h.command))
264
+ .map((h) => [r.event, h]));
214
265
  if (!wanted.length) return [];
215
266
  const hooks = readJson(settingsFile(cfg, managed))?.hooks;
216
267
  const live = (event, command) => Array.isArray(hooks?.[event]) && hooks[event]
@@ -304,10 +355,20 @@ export function isCanonical(cfgDir, host) {
304
355
  /**
305
356
  * The project root a hook judges against: `$CLAUDE_PROJECT_DIR` (Claude Code and OpenClaude set
306
357
  * it for every hook — the session's root, where its project hooks were loaded from), else the
307
- * cwd. Bob documents no such variable, so under Bob this is the cwd.
358
+ * payload's `cwd` when the caller has one, else the process cwd.
359
+ *
360
+ * Bob documents no such variable, but its payload carries `cwd`, the root workspace (2.2.3
361
+ * bundle read; docs/concepts/host-matrix.md, "What is verified"). `payloadCwd` is optional and
362
+ * only a caller that ALREADY holds the parsed payload passes it: `context` does, through the
363
+ * hook entry. The gate verbs do not, because their stand-down runs before they read stdin, and
364
+ * a second read on every tool call is not worth a fallback. A value that is not an absolute
365
+ * path is ignored: the payload is the host's text, and a relative one would resolve against
366
+ * the very cwd it was meant to replace.
308
367
  */
309
- export function hookProjectDir() {
310
- return process.env.CLAUDE_PROJECT_DIR || process.cwd();
368
+ export function hookProjectDir(payloadCwd) {
369
+ if (process.env.CLAUDE_PROJECT_DIR) return process.env.CLAUDE_PROJECT_DIR;
370
+ if (typeof payloadCwd === 'string' && path.isAbsolute(payloadCwd)) return payloadCwd;
371
+ return process.cwd();
311
372
  }
312
373
 
313
374
  /**
@@ -449,8 +510,10 @@ export function openclaudeConfigDir() {
449
510
 
450
511
  /**
451
512
  * `_build_global.HOSTS` — one row per host, IN ITS ORDER: opencode, claude, bob, openclaude.
452
- * A new host is one row here; `EMIT_HOST_SCOPE` (`js/hosts/installs.mjs`) and `CLAUDE_STYLE`
453
- * below are derived from it.
513
+ * `EMIT_HOST_SCOPE` and `EMIT_FOR` (`js/hosts/installs.mjs`) and `CLAUDE_STYLE` below are
514
+ * derived from it, but A NEW HOST IS NOT ONE ROW HERE: a dozen hand tables name the hosts
515
+ * too. `docs/extending.md` §4d is the checklist, and `tests/unit/host_tables.test.mjs` fails
516
+ * for each table that falls behind this one.
454
517
  *
455
518
  * An array rather than an object because the order is observable output, not an
456
519
  * implementation detail: `harness exclude add` walks it and prints one message per host, so
@@ -580,12 +643,17 @@ export const CLAUDE_STYLE = HOSTS.filter((h) => h.family === 'claude').map((h) =
580
643
  * user-editable `.geneseed-emit` marker, so an unrecognised one must degrade to the portable
581
644
  * bundle rather than raise.
582
645
  *
583
- * SPLIT PER KIND (2026-09): Bob reads `.bob/skills/<name>/SKILL.md` natively — verified
584
- * against its docs in the Bob injection review — but has no markdown agents directory, so a
585
- * single boolean was wrong both ways: `false` shipped the §4 Skills table on top of a
586
- * catalogue Bob already had (~1.7k tokens twice), `true` would have stripped the §3 Agents
587
- * table that is Bob's ONLY agent catalogue. Each CATALOG block in AGENT.md names its kind and
588
- * resolves against its own flag.
646
+ * SPLIT PER KIND (2026-09): Bob reads `.bob/skills/<name>/SKILL.md` natively (its skills
647
+ * docs), so a single boolean was wrong both ways: `false` shipped the §4 Skills table on top
648
+ * of a catalogue Bob already had (~1.7k tokens twice), `true` would have stripped the §3
649
+ * Agents table. Each CATALOG block in AGENT.md names its kind and resolves against its own flag.
650
+ *
651
+ * BOB'S `agents: false` IS NOT "Bob has no agents directory". The emit writes native
652
+ * `agents/<name>.md` in Bob's dialect (`bobAgentFrontmatter`, `js/hosts/native.mjs`), and Bob
653
+ * 2.2.3 reads them. What is NOT verified is whether Bob lists those agents to the model by
654
+ * itself, so the §3 Agents table stays in Bob's carrier and the flag stays false until someone
655
+ * sees Bob's own listing. Flipping it on a guess would remove the only agent catalogue the
656
+ * model is known to get.
589
657
  *
590
658
  * Returns `{ skills, agents }` for a known host, `false` for an unknown one.
591
659
  */