geneseed 5.3.0 → 5.4.0

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 (198) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +23 -20
  3. package/SHIPPED.md +7 -7
  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/README.md +3 -2
  9. package/adapters/opencode/plugins/geneseed-activity.js +20 -21
  10. package/adapters/opencode/plugins/geneseed-context.js +175 -62
  11. package/adapters/opencode/plugins/geneseed-guard.js +419 -205
  12. package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
  13. package/adapters/opencode/workflows/_runtime.js +3 -2
  14. package/bin/geneseed-cli.mjs +7 -0
  15. package/bin/geneseed-hook.mjs +59 -11
  16. package/docs/PRD.md +1 -1
  17. package/docs/README.md +1 -0
  18. package/docs/concepts/agents.md +1 -1
  19. package/docs/concepts/collaboration.md +2 -2
  20. package/docs/concepts/enforcement-table.md +5 -2
  21. package/docs/concepts/exclusions.md +18 -4
  22. package/docs/concepts/footprint.md +11 -1
  23. package/docs/concepts/foreman-mode.md +1 -1
  24. package/docs/concepts/hook-gates.md +5 -5
  25. package/docs/concepts/hooks.md +4 -3
  26. package/docs/concepts/host-matrix.md +24 -6
  27. package/docs/concepts/kits.md +12 -2
  28. package/docs/concepts/loop-bricks.md +3 -3
  29. package/docs/concepts/loops.md +6 -4
  30. package/docs/concepts/ownership.md +1 -1
  31. package/docs/concepts/rules.md +2 -2
  32. package/docs/concepts/skills.md +1 -1
  33. package/docs/design-history.md +8 -0
  34. package/docs/extending.md +112 -35
  35. package/docs/guides/auto-merge.md +100 -0
  36. package/docs/guides/choose-your-setup.md +1 -1
  37. package/docs/guides/headless.md +1 -1
  38. package/docs/guides/install-bob.md +2 -2
  39. package/docs/guides/install-clone.md +1 -1
  40. package/docs/guides/install-openclaude.md +1 -1
  41. package/docs/guides/install.md +1 -1
  42. package/docs/guides/loop-finish.md +3 -3
  43. package/docs/guides/loop-running.md +4 -4
  44. package/docs/guides/project-context.md +1 -1
  45. package/docs/guides/run-a-factory.md +2 -2
  46. package/docs/guides/setup-doctrines.md +2 -2
  47. package/docs/guides/setup-footprint.md +1 -1
  48. package/docs/guides/uninstall.md +3 -3
  49. package/docs/guides/upgrade.md +1 -1
  50. package/docs/guides/verify.md +12 -0
  51. package/docs/guides/worktree.md +1 -1
  52. package/docs/reference/environment.md +5 -2
  53. package/docs/reference/plugin-activity.md +1 -1
  54. package/docs/reference/plugin-guard.md +1 -1
  55. package/docs/reference/plugin-learn.md +1 -1
  56. package/docs/reference/plugin-workflow.md +1 -1
  57. package/docs/reference/troubleshoot-doctor.md +2 -2
  58. package/docs/reference/troubleshoot-hooks.md +2 -2
  59. package/docs/reference/troubleshoot-install.md +3 -3
  60. package/docs/reference/troubleshoot-tools.md +1 -1
  61. package/docs/token-footprint.md +68 -4
  62. package/docs/understand/design-choices-hosts.md +1 -1
  63. package/docs/understand/design-choices-shape.md +1 -0
  64. package/docs/understand/enforced-vs-asked.md +2 -2
  65. package/docs/understand/machine-bob.md +1 -1
  66. package/docs/understand/machine-claude.md +2 -2
  67. package/docs/understand/on-your-machine.md +1 -1
  68. package/docs/web-ui.md +10 -5
  69. package/harness.config.json +1 -1
  70. package/js/README.md +5 -3
  71. package/js/build/args.mjs +13 -2
  72. package/js/build/driver.mjs +34 -7
  73. package/js/build/emit-claude.mjs +9 -5
  74. package/js/build/emit-opencode.mjs +13 -9
  75. package/js/build/generate.mjs +10 -165
  76. package/js/build/profile.mjs +318 -0
  77. package/js/build/render.mjs +81 -3
  78. package/js/build/retired-skills.mjs +60 -13
  79. package/js/build/source.mjs +15 -1
  80. package/js/build/stubs.mjs +4 -1
  81. package/js/cli-table.json +48 -3
  82. package/js/hosts/done-checks.mjs +6 -0
  83. package/js/hosts/geneseed-dir.mjs +3 -2
  84. package/js/hosts/gitref.mjs +5 -3
  85. package/js/hosts/hook-tap.mjs +104 -0
  86. package/js/hosts/hooks-context.mjs +4 -2
  87. package/js/hosts/hooks-done.mjs +345 -55
  88. package/js/hosts/hooks-learn.mjs +51 -19
  89. package/js/hosts/hooks-prims.mjs +5 -3
  90. package/js/hosts/hooks.mjs +172 -19
  91. package/js/hosts/hosts.mjs +80 -12
  92. package/js/hosts/installs.mjs +26 -1
  93. package/js/hosts/native.mjs +33 -7
  94. package/js/hosts/owned.mjs +7 -6
  95. package/js/hosts/ownership-gate.mjs +14 -1
  96. package/js/hosts/settings.mjs +273 -105
  97. package/js/hosts/shim.mjs +4 -4
  98. package/js/hosts/usage.mjs +9 -3
  99. package/js/inspect/checks-constitution.mjs +32 -0
  100. package/js/inspect/checks-probe.mjs +66 -5
  101. package/js/inspect/checks-repo.mjs +196 -2
  102. package/js/inspect/cost.mjs +34 -2
  103. package/js/inspect/diff.mjs +21 -3
  104. package/js/inspect/doctor.mjs +6 -1
  105. package/js/inspect/inventory.mjs +1 -1
  106. package/js/lib/machine-dir.mjs +1 -1
  107. package/js/lib/node-floor.mjs +46 -6
  108. package/js/maintain/setup.mjs +5 -1
  109. package/js/maintain/uninstall.mjs +42 -16
  110. package/js/maintain/update.mjs +4 -2
  111. package/js/web/actions.mjs +17 -12
  112. package/js/web/api.mjs +7 -2
  113. package/package.json +1 -1
  114. package/registry.json +14 -0
  115. package/src/AGENT.md.tmpl +15 -17
  116. package/src/bricks/pr-open.md +3 -2
  117. package/src/doctrines/ops.md +2 -2
  118. package/src/doctrines/process.md +40 -36
  119. package/src/factories/analysis-to-build.json +1 -1
  120. package/src/factories/bug-report-to-fix.json +1 -1
  121. package/src/factories/issue-to-pr.json +1 -1
  122. package/src/kits/terminal-tools/rules.md +10 -0
  123. package/src/kits/terminal-tools.json +13 -0
  124. package/src/licenses/herdr.txt +201 -0
  125. package/src/modes/foreman.md +6 -3
  126. package/src/skills/_self-improvement.md +9 -7
  127. package/src/skills/commit.md +17 -17
  128. package/src/skills/debug/ci.md +1 -1
  129. package/src/skills/dependencies.md +3 -3
  130. package/src/skills/document-project.md +3 -2
  131. package/src/skills/factory.md +13 -4
  132. package/src/skills/geneseed.md +4 -2
  133. package/src/skills/git-history.md +5 -7
  134. package/src/skills/herdr.md +135 -0
  135. package/src/skills/loop.md +3 -2
  136. package/src/skills/opencode-cli.md +84 -0
  137. package/src/skills/pipeline.md +1 -1
  138. package/src/skills/release.md +5 -8
  139. package/src/skills/review-response.md +4 -2
  140. package/src/skills/rule.md +27 -1
  141. package/src/skills/ship.md +54 -7
  142. package/src/skills/worktree.md +2 -2
  143. package/src/upstreams.json +7 -0
  144. package/themes/_TEMPLATE.json +2 -0
  145. package/themes/biker.json +2 -0
  146. package/themes/commentator.json +2 -0
  147. package/themes/cyberpunk.json +2 -0
  148. package/themes/gamer.json +2 -0
  149. package/themes/imperial.json +2 -0
  150. package/themes/joker.json +2 -0
  151. package/themes/marvin.json +2 -0
  152. package/themes/mean.json +2 -0
  153. package/themes/military.json +2 -0
  154. package/themes/neutral.json +2 -0
  155. package/themes/pirate.json +2 -0
  156. package/themes/sports.json +2 -0
  157. package/themes/verstappen.json +2 -0
  158. package/themes/wizard.json +2 -0
  159. package/web/dist/assets/Activity-D2kOc3yi.js +1 -0
  160. package/web/dist/assets/ActivityDetail-By3xOr21.js +1 -0
  161. package/web/dist/assets/{Bonsai-Bfpb6W-1.js → Bonsai-CBWDTBA4.js} +1 -1
  162. package/web/dist/assets/{CopyButton-ByIntFtB.js → CopyButton-BVbpriMB.js} +1 -1
  163. package/web/dist/assets/Dashboard-CIJLPHM9.js +2 -0
  164. package/web/dist/assets/{Docs-DvlMJhpu.js → Docs-CiRRIELs.js} +3 -3
  165. package/web/dist/assets/Factories-DhyK0O8d.js +1 -0
  166. package/web/dist/assets/GreenhouseView-DW3PgTPy.js +1 -0
  167. package/web/dist/assets/Installs-B6nlo-Ly.js +3 -0
  168. package/web/dist/assets/JournalView-O65qEWfp.js +1 -0
  169. package/web/dist/assets/Kits-C5U-yT6Z.js +1 -0
  170. package/web/dist/assets/Laws-CuTw_XNf.js +4 -0
  171. package/web/dist/assets/{LibRows-DEHjIoD-.js → LibRows-D6-CVa3K.js} +1 -1
  172. package/web/dist/assets/Library-CzPlerd6.js +3 -0
  173. package/web/dist/assets/Loops-CqNF_-nS.js +2 -0
  174. package/web/dist/assets/Markdown-CxkA7940.js +71 -0
  175. package/web/dist/assets/OperatorHudView-BNr8K5qj.js +1 -0
  176. package/web/dist/assets/Personal-DeDb9e8O.js +2 -0
  177. package/web/dist/assets/Settings-B8MPN_AD.js +1 -0
  178. package/web/dist/assets/{Tabs-CWeQTADL.js → Tabs-DJzAez4h.js} +1 -1
  179. package/web/dist/assets/index-BL3P-9Rg.js +6 -0
  180. package/web/dist/assets/{index-CsAZq0BQ.css → index-CRWqKxfY.css} +1 -1
  181. package/web/dist/index.html +2 -2
  182. package/adapters/claude-code/settings.json +0 -52
  183. package/web/dist/assets/Activity-CqJiquEq.js +0 -1
  184. package/web/dist/assets/ActivityDetail-BSzevynX.js +0 -1
  185. package/web/dist/assets/Dashboard-DBOEi9lQ.js +0 -2
  186. package/web/dist/assets/Factories-Bpvv7L2H.js +0 -1
  187. package/web/dist/assets/GreenhouseView-GpBsYn50.js +0 -1
  188. package/web/dist/assets/Installs-BlGmVrFK.js +0 -3
  189. package/web/dist/assets/JournalView-iLuLrOxE.js +0 -1
  190. package/web/dist/assets/Kits-DRwpxC-J.js +0 -1
  191. package/web/dist/assets/Laws-CZkiNOWQ.js +0 -4
  192. package/web/dist/assets/Library-B4K-1iNF.js +0 -3
  193. package/web/dist/assets/Loops-BWSzaW8E.js +0 -2
  194. package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
  195. package/web/dist/assets/OperatorHudView-BAXwCEvY.js +0 -1
  196. package/web/dist/assets/Personal-Bp9nV4GR.js +0 -2
  197. package/web/dist/assets/Settings-CWWuaIp-.js +0 -1
  198. package/web/dist/assets/index-How7SzDZ.js +0 -6
package/js/README.md CHANGED
@@ -73,6 +73,7 @@ as a per-host install at project or global scope.
73
73
  | `driver.mjs` | The generator driver: the nine emit targets, per-host emit orchestration, the prune and the manifest. `bin/build-driver.mjs` is only its entry |
74
74
  | `args.mjs` | The generator's flag surface: `harness.config.json` defaults, the `--emit`/`--theme`/`--footprint` parse tables and choices, `-h`, and `die` (a throw, so `rebuild-all` survives one bad install) |
75
75
  | `generate.mjs` | CLI verbs `build`, `prompt`, `theme`, `rebuild-all` — the thin face over `driver.mjs` |
76
+ | `profile.mjs` | An install's profile (`installProfile`, `setupBuildArgs`, `rebuildCommand`: every setting read back, and the argv that re-emits it) and the preserve guard: a build over an existing install refuses to change a setting it was not given, unless `--reset`. A leaf the driver may import; `generate.mjs` re-exports the three |
76
77
  | `catalog.mjs` | `geneseed catalog` — prints the shipped roster. Classifies nothing itself |
77
78
  | `export.mjs` | `geneseed export` — skills, agents and the constitution as catalogue entities for a shared library (`SKILL.md`/`AGENT.md` + `metadata.yaml`), shaped by a profile kept outside the repo. One way, claim-on-create, not an install |
78
79
  | `themes.mjs` | Maintainer-only `--sync-themes`: inserts `_TEMPLATE.json`'s missing keys into the committed themes |
@@ -97,12 +98,13 @@ user co-owns, and the hook verbs those emitted configs then run.
97
98
  | `hooks.mjs` | The gate verbs, run on every tool call: `git-gate`, `rule-gate`, `tool-gate` (the two gates fused, for Bob), plus `ask`/the gate ledger/`guardGate`. `--host` picks the verdict dialect |
98
99
  | `hooks-context.mjs` | The `context` verb — SessionStart: session files (shared tier first on a global install, wiki rendered) plus the repo's context docs; `sessionStartSize`, the console's read of the same payload |
99
100
  | `ownership-gate.mjs` | The ownership first-write gate, last in `rule-gate`: in an application repo (git root + build manifest) whose root `AGENTS.md` has no `## Ownership` section, denies the session's first write once (a tmpdir marker per session). Builtins + `gitRootOf` only. Twin: the OpenCode guard plugin |
100
- | `hooks-done.mjs` | The done gate (#289): on Stop, inside `learn` and before its spawn, judges a turn that edited files against the project's checks — blocks until `.geneseed/done-checks.txt`'s checks passed after the last edit; without that file, the inferred checks are advisory (a `systemMessage`, never a block) |
101
+ | `hooks-done.mjs` | The done gate (#289): on Stop and SubagentStop, inside `learn` and before its spawn, judges a turn (a sub-agent's own, at SubagentStop, against each git root it wrote under) that edited files against the project's checks — blocks until `.geneseed/done-checks.txt`'s checks passed after the last edit; without that file, the inferred checks are advisory (a `systemMessage`, never a block) |
101
102
  | `done-checks.mjs` | Where the done gate's checks come from: `.geneseed/done-checks.txt`, else inferred from the git root's manifests (package.json scripts, pom.xml, Gradle, pyproject.toml, Cargo.toml, go.mod), each a group of accepted command forms; plus `doneLine`, the SessionStart line `context` prints. Spawn-free: `context` is in the CLI's closure. Twin: the OpenCode context plugin |
102
103
  | `hooks-learn.mjs` | The `learn` verb — Stop/SubagentStop/PreCompact distiller; the hook path's ONE spawn (`$GENESEED_LLM`) |
103
104
  | `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
105
  | `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
106
  | `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 |
107
+ | `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
108
  | `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
109
  | `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
110
  | `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 +143,7 @@ Everything that inspects an already-built or already-deployed harness and report
141
143
  | `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
144
  | `inventory.mjs` | The one catalog walk and its taxonomy tables, read by status, the TUI and the web console |
143
145
  | `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 |
146
+ | `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
147
  | `diff.mjs` | `geneseed diff` — what a deployed install has that a fresh render of `src/` does not |
146
148
  | `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
149
  | `registry.mjs` | `installs.json` under XDG — the persistent deploy-root list `rebuild-all` re-emits into |
@@ -172,7 +174,7 @@ into files users have committed, so change the test that states it in the same c
172
174
  | `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
175
  | `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
176
  | `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 |
177
+ | `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
178
 
177
179
  **Before editing:** parse with `parseJson`, never `JSON.parse` — the latter collapses int `1` and
178
180
  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
  /**
@@ -118,6 +118,10 @@ export const FLAGS = {
118
118
  // One build's instruction, never recorded: Geneseed's copy replaces a file the user edited
119
119
  // or put at a name Geneseed ships. `claimer` (js/hosts/native.mjs) holds the rule.
120
120
  '--force': 'force',
121
+ // One build's consent: the settings this build does not pass return to their defaults on the
122
+ // install it targets. Without it the preserve guard (js/build/profile.mjs) refuses such a
123
+ // build. Never recorded, never replayed.
124
+ '--reset': 'reset',
121
125
  '-v': 'verbose', '--verbose': 'verbose',
122
126
  };
123
127
 
@@ -374,9 +378,14 @@ export function parseArgs(argv, defaults) {
374
378
  kits: defaults.kits ?? [],
375
379
  sharedTier: 'off',
376
380
  out: 'Harness', emit: 'files', footprint: 'lean', root: null,
377
- syncThemes: false, validateOnly: false, verbose: false, pruneGates: false, force: false,
381
+ syncThemes: false, validateOnly: false, verbose: false, pruneGates: false, force: false, reset: false,
378
382
  ...Object.fromEntries(GATE_SWITCHES.map((g) => [g.arg, false])),
379
383
  };
384
+ // The keys the caller PASSED, for the preserve guard: after this walk a default and a value
385
+ // typed equal to it look the same, and only the second is intent. Non-enumerable, so
386
+ // `makeCfg(args)`'s rest spread never sees it.
387
+ const given = new Set();
388
+ Object.defineProperty(args, 'given', { value: given, enumerable: false });
380
389
  const { tokens } = nodeParseArgs({
381
390
  args: argv, options: PARSE_OPTIONS, allowPositionals: true, strict: false, tokens: true,
382
391
  });
@@ -393,6 +402,7 @@ export function parseArgs(argv, defaults) {
393
402
  if (tok.kind === 'option' && VALUED_BY_NAME[tok.name] !== undefined) {
394
403
  if (tok.value === undefined) die(2, `argument ${tok.rawName}: expected one argument`);
395
404
  args[VALUED_BY_NAME[tok.name]] = tok.value;
405
+ given.add(VALUED_BY_NAME[tok.name]);
396
406
  continue;
397
407
  }
398
408
  // `tok.value === undefined` excludes `--sync-themes=x` from matching here — a store_true
@@ -402,6 +412,7 @@ export function parseArgs(argv, defaults) {
402
412
  // given), so this must compare the VALUE, not `'value' in tok` — the key is always there.
403
413
  if (tok.kind === 'option' && tok.value === undefined && FLAG_BY_NAME[tok.name] !== undefined) {
404
414
  args[FLAG_BY_NAME[tok.name]] = true;
415
+ given.add(FLAG_BY_NAME[tok.name]);
405
416
  continue;
406
417
  }
407
418
  // Every other shape — an unrecognized option, a bare positional, or `--` (which `parseArgs`
@@ -73,6 +73,7 @@ import { kitsOfDir } from '../hosts/installs.mjs';
73
73
  // maintainer pair that needs nothing this driver is banned from having.
74
74
  import { syncThemes } from './themes.mjs';
75
75
  import { configDefaults, die, parseArgs } from './args.mjs';
76
+ import { preserveRefusal, preserveRefusalText } from './profile.mjs';
76
77
 
77
78
  export { parseDriverArgs } from './args.mjs';
78
79
 
@@ -259,6 +260,18 @@ function pruneOwned(oc, oldOwned, owned, oldHashes = {}, editRefused = [], force
259
260
  */
260
261
  const keptKey = (kept) => (kept && kept.length ? { kept: [...kept].sort() } : {});
261
262
 
263
+ /**
264
+ * The manifest's `kept_hashes` (spec 2026-11-13 §1): for each rel an emit left to the user after
265
+ * an edit, the hash the last emit that WROTE it recorded — the base `diffCollect` needs to tell a
266
+ * kept edit from a diverged one after the rel has left `owned`. Read with `hashesOf`, so a
267
+ * malformed map empties as `hashes` does; written only when non-empty, so a clean manifest is
268
+ * byte-identical (`golden.mjs --idempotent`). Keys sorted, like `hashes`.
269
+ */
270
+ const keptHashesOf = (doc) => hashesOf({ hashes: doc && doc.kept_hashes });
271
+ const keptHashesKey = (h) => (h && Object.keys(h).length
272
+ ? { kept_hashes: Object.fromEntries(Object.entries(h).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) }
273
+ : {});
274
+
262
275
  /**
263
276
  * Whether this PROJECT emit seeds `<git root>/.geneseed/protected-checks.txt`. A real emit does;
264
277
  * a sandbox emit must not, because the seed walks UP to the git root and a sandbox under a temp
@@ -334,6 +347,7 @@ function emitOpencode(cfg, args, out) {
334
347
  const oldEdit = recordedEdit(doc);
335
348
  const oldGates = recordedGates(doc);
336
349
  const oldHashes = hashesOf(doc);
350
+ const oldKeptHashes = keptHashesOf(doc);
337
351
 
338
352
  const agentPathRel = relUnder(out, root);
339
353
  const agentPath = agentPathRel ? `${agentPathRel}/AGENT.md` : 'AGENT.md';
@@ -345,9 +359,9 @@ function emitOpencode(cfg, args, out) {
345
359
  {
346
360
  theme: args.theme, out, root, footprint: args.footprint,
347
361
  nativeCatalog: hostCatalogsNatively('opencode'), oldOwned, manifestExisted, agentPath,
348
- oldDenies, oldEdit, oldHashes, oldGates,
362
+ oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
349
363
  });
350
- const { owned, stats, cfgName, skillDenies, editRecord, editRefused, bashGates, kept } = rendered;
364
+ const { owned, stats, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes } = rendered;
351
365
  // Seed once: absent -> created, then the user's (never recorded, rewritten or removed).
352
366
  if (seeds(args)) seedProtectedChecks(root);
353
367
 
@@ -362,6 +376,7 @@ function emitOpencode(cfg, args, out) {
362
376
  owned: [...owned].sort(),
363
377
  hashes: ownedHashes(oc, owned),
364
378
  ...keptKey(kept),
379
+ ...keptHashesKey(keptHashes),
365
380
  scope: 'project',
366
381
  ...(skillDenies.length ? { skill_denies: skillDenies } : {}),
367
382
  ...editRecordKeys(editRecord),
@@ -402,6 +417,7 @@ function emitOpencodeGlobal(cfg, args, out) {
402
417
  const oldEdit = recordedEdit(doc);
403
418
  const oldGates = recordedGates(doc);
404
419
  const oldHashes = hashesOf(doc);
420
+ const oldKeptHashes = keptHashesOf(doc);
405
421
 
406
422
  const agentPath = path.join(cfgDir, 'AGENT.md').split(path.sep).join('/');
407
423
 
@@ -410,9 +426,9 @@ function emitOpencodeGlobal(cfg, args, out) {
410
426
  {
411
427
  theme: args.theme, cfgDir, out, sharedRoot: args.sharedRoot,
412
428
  footprint: args.footprint, nativeCatalog: hostCatalogsNatively('opencode'),
413
- oldOwned, agentPath, oldDenies, oldEdit, oldHashes, oldGates,
429
+ oldOwned, agentPath, oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
414
430
  });
415
- const { owned, stats, memStatus, nbStatus, cfgName, skillDenies, editRecord, editRefused, bashGates, kept } = rendered;
431
+ const { owned, stats, memStatus, nbStatus, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes } = rendered;
416
432
 
417
433
  phaseLog('PRUNE');
418
434
  pruneOwned(cfgDir, oldOwned, owned, oldHashes, editRefused, cfg.force);
@@ -425,6 +441,7 @@ function emitOpencodeGlobal(cfg, args, out) {
425
441
  owned: [...owned].sort(),
426
442
  hashes: ownedHashes(cfgDir, owned),
427
443
  ...keptKey(kept),
444
+ ...keptHashesKey(keptHashes),
428
445
  ...(skillDenies.length ? { skill_denies: skillDenies } : {}),
429
446
  ...editRecordKeys(editRecord),
430
447
  ...(bashGates.length ? { bash_gates: bashGates } : {}),
@@ -456,6 +473,7 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
456
473
  const oldManaged = (doc && doc.managed && typeof doc.managed === 'object'
457
474
  && !Array.isArray(doc.managed)) ? doc.managed : {};
458
475
  const oldHashes = hashesOf(doc);
476
+ const oldKeptHashes = keptHashesOf(doc);
459
477
 
460
478
  // RENDER + WIRE in one child's worth of work. `preambleExclude` is null for every
461
479
  // carrier but `CLAUDE.md`, so Bob's `AGENTS.md` does not resolve to one; for a `CLAUDE.md`
@@ -467,9 +485,9 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
467
485
  out,
468
486
  footprint: args.footprint, nativeCatalog: hostCatalogsNatively(host),
469
487
  oldOwned, oldManaged, preambleExclude: preambleExclude(claudeMd, host),
470
- hookOpts, oldHashes,
488
+ hookOpts, oldHashes, oldKeptHashes,
471
489
  });
472
- const { owned, stats, memStatus, nbStatus, managed, editRefused, kept } = rendered;
490
+ const { owned, stats, memStatus, nbStatus, managed, editRefused, kept, keptHashes } = rendered;
473
491
  // `root` is null on a global emit: it has no project to seed.
474
492
  if (root && seeds(args)) seedProtectedChecks(root);
475
493
 
@@ -486,6 +504,7 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
486
504
  owned: [...owned].sort(),
487
505
  hashes: ownedHashes(cfgDir, owned),
488
506
  ...keptKey(kept),
507
+ ...keptHashesKey(keptHashes),
489
508
  managed,
490
509
  scope,
491
510
  });
@@ -576,7 +595,7 @@ const CLAUDE_SHAPED = {
576
595
  summary: (at, r) => `[geneseed] bob-global -> ${at}: ${r.nAgents} subagents, `
577
596
  + `${r.nSkills} skills, rules/geneseed.md (Bob's always-injected channel; a global `
578
597
  + 'AGENTS.md is not auto-loaded, so none is written), '
579
- + `${r.nHooks} hook group(s), settings.json, ${r.memStatus}, ${r.nbStatus}.\n`,
598
+ + `${r.nHooks} hook group(s), settings/settings.json, ${r.memStatus}, ${r.nbStatus}.\n`,
580
599
  },
581
600
  // Per-repo: AGENTS.md at the root + a `.bob/` layer.
582
601
  bob: {
@@ -844,6 +863,14 @@ function run(argv) {
844
863
  die(2, `argument --shared-tier: only applies to a per-repo host emit (got --emit ${args.emit}); `
845
864
  + 'a global install already owns the shared tier');
846
865
  }
866
+ // The preserve guard, before anything is written: a build over an existing install that would
867
+ // change a setting it was not given refuses, naming each change and the command that keeps
868
+ // them. `--reset` is the caller's consent. See `preserveRefusal` (js/build/profile.mjs).
869
+ const refusal = preserveRefusal(args, args.given, out, args.root ? resolveOut(args.root) : null);
870
+ if (refusal) {
871
+ process.stderr.write(preserveRefusalText(refusal));
872
+ throw Object.assign(new Error('preserve guard'), { exitCode: 1 });
873
+ }
847
874
  const cfg = makeCfg(args);
848
875
  warnDroppedKits(args, out);
849
876
 
@@ -21,7 +21,7 @@ import { pruneRetiredSkills } from './retired-skills.mjs';
21
21
  import {
22
22
  claimAndWrite, globalMemory, globalNotebook, shipLeanLaws, stripCapabilityLinks,
23
23
  } from './emit-common.mjs';
24
- import { kitsBody, pathTokens, renderAll, renderFile } from './render.mjs';
24
+ import { kitsBody, modeBody, pathTokens, renderAll, renderFile } from './render.mjs';
25
25
  import {
26
26
  BOB_RULES_STUB, bobFirstReply, ensureContextStub, ensureExcludesStub, ensureNotebookIndex,
27
27
  ensureProfileStub,
@@ -52,7 +52,7 @@ export function emitClaudeRender(cfg, job) {
52
52
  phaseLog('RENDER');
53
53
  const {
54
54
  theme: themeName, cfgDir, claudeMd, scope, out, footprint, host, nativeCatalog,
55
- oldOwned, oldHashes = {},
55
+ oldOwned, oldHashes = {}, oldKeptHashes = {},
56
56
  } = job;
57
57
 
58
58
  // Relative to the CLAUDE.md directory, so the argument order is cfg-from-claude_md; an
@@ -91,6 +91,8 @@ export function emitClaudeRender(cfg, job) {
91
91
  Object.assign(ptheme, pathTokens(ptheme, sharedRoot));
92
92
  // The Kits block was substituted with the unprefixed DIR_* tokens; rebuild it, or its links dangle.
93
93
  ptheme.KITS_BODY = kitsBody(cfg, ptheme, '');
94
+ // The Foreman mode names its ledger under DIR_NOTEBOOK: rebuilt for the same reason.
95
+ ptheme.MODE_BODY = modeBody(cfg, ptheme);
94
96
  // Same catalogue decision as the renderAll above — a re-render that forgot it would
95
97
  // quietly put the stripped tables back.
96
98
  return renderFile(cfg, tmplItem.src, ptheme, footprint, '', new Set(), nativeCatalog);
@@ -126,7 +128,8 @@ export function emitClaudeRender(cfg, job) {
126
128
  // below both push into the same `owned` list, so a pre-manifest-install warning still
127
129
  // prints once across the whole emit rather than once per writer.
128
130
  // Before the claim: a retired folder freed here lets this emit write the alias that replaces it.
129
- if (sharedRoot !== null) pruneRetiredSkills(host, cfgDir, oldOwned);
131
+ // `held`: the user's kept edits under a revived name, recorded again so they never lapse.
132
+ const held = sharedRoot !== null ? pruneRetiredSkills(host, cfgDir, oldOwned) : [];
130
133
  const claim = claimer(oldOwned, cfgDir, true, oldHashes, cfg.force);
131
134
  const { nAgents, nSkills, written } = writeNativeLayer(
132
135
  items, path.join(cfgDir, 'agents'), path.join(cfgDir, 'skills'),
@@ -206,7 +209,8 @@ export function emitClaudeRender(cfg, job) {
206
209
  nbStatus,
207
210
  managed,
208
211
  editRefused: [...claim.editRefused],
209
- kept: [...claim.kept],
212
+ kept: [...new Set([...claim.kept, ...held])],
213
+ keptHashes: claim.keptHashes(oldKeptHashes),
210
214
  };
211
215
  }
212
216
 
@@ -283,7 +287,7 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
283
287
  // recorded claims there, or they linger (and run) forever.
284
288
  const oldSf = get(old, 'settings_file') || 'settings.json';
285
289
  if (oldSf !== settingsName) {
286
- unwireClaudeSettings(path.join(cfgDir, oldSf), get(old, 'settings_hooks') || []);
290
+ unwireClaudeSettings(path.join(cfgDir, oldSf), get(old, 'settings_hooks') || [], cfgDir);
287
291
  unwireClaudeExcludes(path.join(cfgDir, oldSf), get(old, 'settings_excludes') || []);
288
292
  unwireClaudeEnv(path.join(cfgDir, oldSf), get(old, 'settings_env'));
289
293
  }
@@ -56,7 +56,7 @@ import { mkdirSync } from 'node:fs';
56
56
  function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
57
57
  const {
58
58
  oldOwned, manifestExisted, agentPath, wireBase, overridesDir, oldDenies = [], oldEdit = { asks: [], shorthand: null },
59
- oldHashes = {}, oldGates = [],
59
+ oldHashes = {}, oldGates = [], oldKeptHashes = {},
60
60
  } = opts;
61
61
  ensureAgentOverridesStub(cfg, overridesDir);
62
62
  const overrides = loadAgentOverrides(overridesDir);
@@ -114,6 +114,7 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
114
114
  // As `skillDenies`: a merge that wrote nothing keeps the old record whole.
115
115
  bashGates: wired.bashGates ? [...wired.bashGates].sort() : oldGates,
116
116
  kept: [...claim.kept],
117
+ keptHashes: claim.keptHashes(oldKeptHashes),
117
118
  };
118
119
  }
119
120
 
@@ -137,7 +138,7 @@ export function emitOpencodeRender(cfg, job) {
137
138
  phaseLog('RENDER');
138
139
  const {
139
140
  theme: _theme, out, root, footprint, nativeCatalog, oldOwned, manifestExisted, agentPath,
140
- oldDenies, oldEdit, oldHashes = {}, oldGates = [],
141
+ oldDenies, oldEdit, oldHashes = {}, oldGates = [], oldKeptHashes = {},
141
142
  } = job;
142
143
  const oc = path.join(root, '.opencode');
143
144
 
@@ -156,9 +157,9 @@ export function emitOpencodeRender(cfg, job) {
156
157
  const { theme, items } = renderAll(cfg, _theme, { footprint, nativeCatalog });
157
158
 
158
159
  const {
159
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
160
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes,
160
161
  } = opencodeLayer(cfg, items, _theme, theme, oc, owned, {
161
- oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes, oldGates,
162
+ oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
162
163
  });
163
164
 
164
165
  return {
@@ -172,6 +173,7 @@ export function emitOpencodeRender(cfg, job) {
172
173
  editRefused,
173
174
  bashGates,
174
175
  kept,
176
+ keptHashes,
175
177
  };
176
178
  }
177
179
 
@@ -206,7 +208,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
206
208
  phaseLog('RENDER');
207
209
  const {
208
210
  theme: themeName, cfgDir, out, footprint, nativeCatalog, oldOwned, agentPath, oldDenies, oldEdit,
209
- oldHashes = {}, oldGates = [],
211
+ oldHashes = {}, oldGates = [], oldKeptHashes = {},
210
212
  } = job;
211
213
 
212
214
  // No `lawsPrefix`: the standalone laws dir sits beside AGENT.md in <cfg>, so the lean
@@ -232,14 +234,15 @@ export function emitOpencodeGlobalRender(cfg, job) {
232
234
  opencodeSentinelWrite(cfgDir);
233
235
 
234
236
  // As in `emitClaudeRender`: before the skill layer claims anything.
235
- if (sharedRoot !== null) pruneRetiredSkills('opencode', cfgDir, oldOwned);
237
+ // `held`: the user's kept edits under a revived name, recorded again so they never lapse.
238
+ const held = sharedRoot !== null ? pruneRetiredSkills('opencode', cfgDir, oldOwned) : [];
236
239
 
237
240
  // `manifestExisted` is deliberately not passed, so
238
241
  // the pre-manifest header line is unreachable from this emit.
239
242
  const {
240
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
243
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes,
241
244
  } = opencodeLayer(cfg, items, themeName, theme, cfgDir, owned, {
242
- oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes, oldGates,
245
+ oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
243
246
  });
244
247
 
245
248
  const memStatus = globalMemory(cfgDir, items, out, cfg.src);
@@ -269,6 +272,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
269
272
  editRecord,
270
273
  editRefused,
271
274
  bashGates,
272
- kept,
275
+ kept: [...new Set([...kept, ...held])],
276
+ keptHashes,
273
277
  };
274
278
  }
@@ -33,14 +33,10 @@ import { existsSync, mkdirSync, statSync } from 'node:fs';
33
33
  import path from 'node:path';
34
34
 
35
35
  import { main as driverMain } from './driver.mjs';
36
- import { GATE_SWITCHES, makeCfg, PACK_ORDER } from './source.mjs';
37
- import { DEFAULT_PRESET } from '../loop/score.mjs';
36
+ import { GATE_SWITCHES, makeCfg } from './source.mjs';
38
37
  import { opencodeConfigDir, resolvePath } from '../hosts/hosts.mjs';
39
- import {
40
- EMIT_HOST_SCOPE, defaultMode, defaultPosture, defaultTheme, doctrinesForBuild,
41
- excludedRulesOfDir, excludedSkillsOfDir, footprintOfDir, kitsOfDir, sharedTierOfDir, gatesOfDir, installState, installTargets,
42
- modeOfDir, postureOfDir, readMaybe, themeOfDir, trustOfDir,
43
- } from '../hosts/installs.mjs';
38
+ import { installState, installTargets } from '../hosts/installs.mjs';
39
+ import { installProfile } from './profile.mjs';
44
40
  import { colorThemeFiles, colorThemeJson, PALETTE_ROLES } from '../hosts/opencode.mjs';
45
41
  import { renderAll } from './render.mjs';
46
42
  import { renamedFilesIn } from './stubs.mjs';
@@ -108,171 +104,20 @@ export function cmdBuild(args) {
108
104
  if (args.force) argv.push('--force');
109
105
  // Forwarded like `--force`: a one-shot flag of the generator, with no `GATE_SWITCHES` row.
110
106
  if (args.pruneGates) argv.push('--prune-gates');
107
+ // Forwarded like `--force`: one build's consent to return the omitted settings to their defaults.
108
+ if (args.reset) argv.push('--reset');
111
109
  return driverMain(argv);
112
110
  }
113
111
 
112
+ // An install's profile — `setupBuildArgs`, `installProfile`, `rebuildCommand` — lives in
113
+ // `./profile.mjs`, a leaf the driver can import for its preserve guard without reaching this
114
+ // module's lazy `update.mjs` (a spawner). Re-exported so every caller keeps its import.
115
+ export { installProfile, rebuildCommand, setupBuildArgs } from './profile.mjs';
116
+
114
117
  // --------------------------------------------------------------------------------------
115
118
  // rebuild-all
116
119
  // --------------------------------------------------------------------------------------
117
120
 
118
- /**
119
- * `_harness_setup._setup_build_args` — the generator argv for one selection. Pure.
120
- *
121
- * The elision rules are not symmetric: `footprint` is ALWAYS passed,
122
- * because omitting it when it matched the generator's default silently coupled the answer to
123
- * whatever that default happened to be — the moment the default moved, picking the old one
124
- * produced the new one. `posture`, `mode` and `trust` still elide at theirs, and none has moved.
125
- *
126
- * ⚠ `doctrines` DOES NOT ELIDE, AND THAT IS THE SAFETY DECISION, NOT A STYLE ONE. It used to
127
- * elide on the full set, by analogy with posture and mode — but those two compare against a
128
- * FROZEN LITERAL (`'peer'`, `'direct'`), while the default a missing `--doctrines` actually
129
- * lands on is `configDefaults()`, which reads `harness.config.json`. With `{"doctrines":
130
- * ["craft"]}` in that file, an install carrying all four packs re-emitted by `upgrade` was
131
- * silently narrowed to one — and the narrowing takes the commit/push consent gate off an
132
- * install whose owner never asked for that. Same trap as `footprint`, one axis over, with a
133
- * boundary behind it. A caller that knows the selection now always says so.
134
- *
135
- * `allPacks` survives the elision's removal because it is still what CANONICALISES the value:
136
- * the flag is emitted in the checkout's pack order, not the order handed in, and this function
137
- * is pure and has no discovery of its own.
138
- *
139
- * Two states: `null` means "the caller expressed no opinion" and emits no flag at all, so the
140
- * generator falls back to `harness.config.json` — the only route left to that fallback, and it
141
- * is reached only where nothing was read back off an install; `[]` is a deliberate empty
142
- * selection and emits `--doctrines none`, which is the spelling the driver's `parseDoctrines`
143
- * accepts (an empty `--doctrines ` is a usage error there, so it can never be produced here).
144
- */
145
- export function setupBuildArgs(theme, emit, out = null, root = null, footprint = 'lean',
146
- posture = 'peer', mode = 'direct', doctrines = null, allPacks = PACK_ORDER,
147
- excludeRules = null, trust = DEFAULT_PRESET, excludeSkills = null, gates = {}, kits = null, sharedTier = false) {
148
- const argv = ['--theme', theme, '--emit', emit];
149
- if (!emit.endsWith('-global')) {
150
- if (out) argv.push('--out', out);
151
- if (root) argv.push('--root', root);
152
- }
153
- if (footprint) argv.push('--footprint', footprint);
154
- if (posture && posture !== 'peer') argv.push('--posture', posture);
155
- if (mode && mode !== 'direct') argv.push('--mode', mode);
156
- if (trust && trust !== DEFAULT_PRESET) argv.push('--trust', trust);
157
- if (Array.isArray(doctrines)) {
158
- // Emitted in `allPacks` order, not the order handed in: a caller may legitimately pass an
159
- // unsorted list, and the flag has to be canonical for the same reason the driver
160
- // re-normalises on parse — the `Active packs:` marker is compared against itself.
161
- const picked = allPacks.filter((p) => doctrines.includes(p));
162
- argv.push('--doctrines', picked.length ? picked.join(',') : 'none');
163
- }
164
- // The second axis, emitted the same way and for the same reason — but ALWAYS when the
165
- // caller passed a list, empty included. An omitted flag reads as "no opinion" and the
166
- // driver's config fallback fills it in; `none` is the caller saying "exclude nothing",
167
- // which is exactly what a rebuild that just re-enabled the last rule has to say.
168
- if (Array.isArray(excludeRules)) {
169
- argv.push('--exclude-rules', excludeRules.length ? excludeRules.join(',') : 'none');
170
- }
171
- // Skills elide when nothing is excluded: the driver's default IS nothing (no config key
172
- // feeds it), so the flag's absence and `none` are the same answer, and every argv that
173
- // excludes nothing stays the bytes it was before the flag existed.
174
- if (excludeSkills?.length) argv.push('--exclude-skills', excludeSkills.join(','));
175
- // The gate switches elide when armed: the driver's default IS armed (no config key feeds
176
- // them), so only an explicit `false` speaks, and every armed argv stays the bytes it was.
177
- // `gates` is one object keyed as `GATE_SWITCHES` keys it (`gatesOfDir`, a profile, a body).
178
- // Law order, so a Law IV-only install still ends on `--no-deletion-gate` as it did.
179
- for (const g of GATE_SWITCHES) if (gates?.[g.key] === false) argv.push(g.flag);
180
- // Kits elide when none is on, as skills do: no config key feeds them, so absence and `none`
181
- // are the same answer. Last, so an argv naming no kit is the bytes it always was.
182
- if (kits?.length) argv.push('--kits', [...kits].sort().join(','));
183
- // The shared tier elides when off, like the kits: the default is off, so only `on` speaks.
184
- if (sharedTier) argv.push('--shared-tier', 'on');
185
- return argv;
186
- }
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
- ]);
200
-
201
- /**
202
- * Everything `rebuild-all` reads back off one install, and the argv that re-emits it unchanged.
203
- *
204
- * EXTRACTED SO `status` SHOWS WHAT A REBUILD WOULD USE, not a second reading of the same
205
- * markers that could drift from this one. An agent changing one setting takes `argv`, edits one
206
- * flag and runs it; every flag it did not touch has to be the install's own, or the "one
207
- * change" silently resets the rest — which is exactly the failure the seven read-backs below
208
- * exist to prevent.
209
- *
210
- * THE MARKER IS TRUSTED ONLY FOR ITS OWN HOST. There is one `.geneseed-emit` per root and the
211
- * last deploy wins, so in a dual-host repo (`.opencode/` and `.claude/` in one cwd) the other
212
- * host's row would otherwise rebuild with the WRONG emit — turning a Claude install into an
213
- * OpenCode one. `rebuild-all/a-dual-host-repo-rebuilds-each-row-in-its-own-emit` is the cell.
214
- */
215
- export function installProfile(host, scope, root, notify = null) {
216
- const raw = readMaybe(path.join(root, '.geneseed-emit'));
217
- let marker = raw === null ? '' : raw.trim();
218
- if (marker && (EMIT_HOST_SCOPE.get(marker) ?? ['', ''])[0] !== host) marker = '';
219
- const emit = marker || DEFAULT_EMIT.get(`${host} ${scope}`) || 'opencode-global';
220
- // Every read-back below is narrowed to `host`'s OWN carrier (host-compat B1): in a repo
221
- // shared with another Claude-style host, an un-narrowed scan answers with WHICHEVER host's
222
- // carrier the shared `CARRIERS` order favours — the wrong carrier for every host but one.
223
- const theme = themeOfDir(root, host) || defaultTheme();
224
- const footprint = footprintOfDir(root);
225
- const posture = postureOfDir(root, host) || defaultPosture();
226
- const mode = modeOfDir(root, host) || defaultMode();
227
- // Read off the deployed loop skill; no config fallback — `DEFAULT_PRESET` is the engine's.
228
- const trust = trustOfDir(root, host) || DEFAULT_PRESET;
229
- // A rebuild that defaulted the pack selection would re-emit an install into a constitution
230
- // its owner did not choose — and in one direction that is not merely surprising: dropping
231
- // the process pack takes the commit/push consent RULES out of AGENT.md while
232
- // `claudeHookGroups` keeps the gate wired, or the reverse. ⚠ AND THE FALLBACK IS NOT
233
- // `harness.config.json`: a pre-migration carrier has no marker, and resolving that silence
234
- // out of a machine-wide config narrows every such install on its first upgrade.
235
- // `doctrinesForBuild` resolves unknown to ALL packs — see its docblock.
236
- const doctrines = doctrinesForBuild(root, host);
237
- // The per-rule axis is preserved for the same reason and with sharper teeth: an upgrade that
238
- // dropped it would quietly hand back every rule its owner switched off, and `process 5` is
239
- // one of them. `null` (no marker) stays `null` so the argv omits the flag, as it always did.
240
- const excludeRules = excludedRulesOfDir(root, host);
241
- // Skills left out stay left out: an upgrade that forgot them would put them all back.
242
- const excludeSkills = excludedSkillsOfDir(root, host, notify);
243
- // The gate switches: a rebuild that forgot one would silently re-arm (or, read wrong, disarm)
244
- // the install. A missing marker reads as armed.
245
- const gates = gatesOfDir(root, host);
246
- // Kits on stay on (spec A3); one this checkout no longer ships drops with a notice (R2).
247
- const kits = kitsOfDir(root, host, notify);
248
- // A project install's `Shared tier: on` stays on across a rebuild; a global install never has it.
249
- const sharedTier = sharedTierOfDir(root, host);
250
- const out = scope === 'global' ? null : root;
251
- const argv = setupBuildArgs(theme, emit, out, out, footprint, posture, mode, doctrines,
252
- PACK_ORDER, excludeRules, trust, excludeSkills, gates, kits, sharedTier);
253
- // A GLOBAL ROW NAMES ITS OWN DIR. `root` came from the host's config-dir resolver, which
254
- // honours env overrides (`OPENCODE_CONFIG_DIR`, `CLAUDE_CONFIG_DIR`…); without the flag the
255
- // same argv run from a shell lacking that variable re-emits into the DEFAULT dir — a second
256
- // install beside the one it was meant to rebuild. Appended, so the argv's head is unchanged.
257
- if (scope === 'global') argv.push('--config-dir', root);
258
- return {
259
- host, scope, root, state: installState(root, host, scope),
260
- emit, theme, footprint, posture, mode, trust, doctrines, excludeRules, excludeSkills,
261
- kits, sharedTier, ...gates, argv,
262
- };
263
- }
264
-
265
- /**
266
- * `argv` as one pasteable command, using the `geneseed build` launcher rather than the raw
267
- * generator: `geneseed-build` is only on PATH for an npm global install, while a git-clone
268
- * install has only the `geneseed` launcher, and `geneseed build` now forwards every flag
269
- * `setupBuildArgs` produces. Only whitespace is quoted — a path holding shell metacharacters
270
- * (`$`, `&`) would need quoting by hand.
271
- */
272
- export function rebuildCommand(argv) {
273
- return ['geneseed', 'build', ...argv.map((a) => (/\s/.test(a) ? `"${a}"` : a))].join(' ');
274
- }
275
-
276
121
  /**
277
122
  * `_harness_build.cmd_rebuild_all` — re-emit every ACTIVE install in place, best-effort.
278
123
  *