geneseed 5.3.1 → 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 (161) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +21 -18
  3. package/SHIPPED.md +7 -7
  4. package/adapters/opencode/README.md +3 -2
  5. package/adapters/opencode/plugins/geneseed-context.js +6 -0
  6. package/adapters/opencode/plugins/geneseed-guard.js +5 -3
  7. package/bin/geneseed-cli.mjs +7 -0
  8. package/bin/geneseed-hook.mjs +3 -3
  9. package/docs/PRD.md +1 -1
  10. package/docs/README.md +1 -0
  11. package/docs/concepts/agents.md +1 -1
  12. package/docs/concepts/collaboration.md +2 -2
  13. package/docs/concepts/enforcement-table.md +5 -2
  14. package/docs/concepts/exclusions.md +16 -2
  15. package/docs/concepts/footprint.md +1 -1
  16. package/docs/concepts/foreman-mode.md +1 -1
  17. package/docs/concepts/hook-gates.md +3 -3
  18. package/docs/concepts/hooks.md +4 -3
  19. package/docs/concepts/host-matrix.md +2 -2
  20. package/docs/concepts/kits.md +12 -2
  21. package/docs/concepts/loop-bricks.md +3 -3
  22. package/docs/concepts/loops.md +6 -4
  23. package/docs/concepts/ownership.md +1 -1
  24. package/docs/concepts/rules.md +2 -2
  25. package/docs/concepts/skills.md +1 -1
  26. package/docs/extending.md +63 -28
  27. package/docs/guides/auto-merge.md +100 -0
  28. package/docs/guides/choose-your-setup.md +1 -1
  29. package/docs/guides/headless.md +1 -1
  30. package/docs/guides/install-clone.md +1 -1
  31. package/docs/guides/install.md +1 -1
  32. package/docs/guides/loop-finish.md +3 -3
  33. package/docs/guides/loop-running.md +4 -4
  34. package/docs/guides/project-context.md +1 -1
  35. package/docs/guides/run-a-factory.md +2 -2
  36. package/docs/guides/setup-doctrines.md +2 -2
  37. package/docs/guides/setup-footprint.md +1 -1
  38. package/docs/guides/uninstall.md +3 -3
  39. package/docs/guides/upgrade.md +1 -1
  40. package/docs/guides/worktree.md +1 -1
  41. package/docs/reference/environment.md +4 -2
  42. package/docs/reference/plugin-activity.md +1 -1
  43. package/docs/reference/plugin-guard.md +1 -1
  44. package/docs/reference/plugin-learn.md +1 -1
  45. package/docs/reference/plugin-workflow.md +1 -1
  46. package/docs/reference/troubleshoot-doctor.md +1 -1
  47. package/docs/reference/troubleshoot-hooks.md +2 -2
  48. package/docs/reference/troubleshoot-install.md +3 -3
  49. package/docs/reference/troubleshoot-tools.md +1 -1
  50. package/docs/token-footprint.md +2 -2
  51. package/docs/understand/enforced-vs-asked.md +1 -1
  52. package/docs/understand/machine-claude.md +2 -2
  53. package/docs/understand/on-your-machine.md +1 -1
  54. package/docs/web-ui.md +5 -5
  55. package/harness.config.json +1 -1
  56. package/js/README.md +2 -1
  57. package/js/build/args.mjs +12 -1
  58. package/js/build/driver.mjs +33 -6
  59. package/js/build/emit-claude.mjs +8 -4
  60. package/js/build/emit-opencode.mjs +13 -9
  61. package/js/build/generate.mjs +10 -156
  62. package/js/build/profile.mjs +318 -0
  63. package/js/build/render.mjs +81 -3
  64. package/js/build/retired-skills.mjs +60 -13
  65. package/js/build/source.mjs +15 -1
  66. package/js/build/stubs.mjs +4 -1
  67. package/js/cli-table.json +48 -3
  68. package/js/hosts/hooks-done.mjs +345 -55
  69. package/js/hosts/hooks-learn.mjs +4 -3
  70. package/js/hosts/hooks-prims.mjs +5 -3
  71. package/js/hosts/hooks.mjs +153 -6
  72. package/js/hosts/installs.mjs +19 -1
  73. package/js/hosts/native.mjs +19 -2
  74. package/js/hosts/settings.mjs +29 -3
  75. package/js/inspect/checks-constitution.mjs +32 -0
  76. package/js/inspect/diff.mjs +21 -3
  77. package/js/inspect/inventory.mjs +1 -1
  78. package/js/maintain/setup.mjs +5 -1
  79. package/js/maintain/update.mjs +4 -2
  80. package/js/web/actions.mjs +16 -3
  81. package/js/web/api.mjs +7 -2
  82. package/package.json +1 -1
  83. package/registry.json +14 -0
  84. package/src/AGENT.md.tmpl +15 -17
  85. package/src/bricks/pr-open.md +3 -2
  86. package/src/doctrines/ops.md +2 -2
  87. package/src/doctrines/process.md +40 -36
  88. package/src/factories/analysis-to-build.json +1 -1
  89. package/src/factories/bug-report-to-fix.json +1 -1
  90. package/src/factories/issue-to-pr.json +1 -1
  91. package/src/kits/terminal-tools/rules.md +10 -0
  92. package/src/kits/terminal-tools.json +13 -0
  93. package/src/licenses/herdr.txt +201 -0
  94. package/src/modes/foreman.md +6 -3
  95. package/src/skills/_self-improvement.md +9 -7
  96. package/src/skills/commit.md +17 -17
  97. package/src/skills/debug/ci.md +1 -1
  98. package/src/skills/dependencies.md +3 -3
  99. package/src/skills/document-project.md +3 -2
  100. package/src/skills/factory.md +13 -4
  101. package/src/skills/geneseed.md +4 -2
  102. package/src/skills/git-history.md +5 -7
  103. package/src/skills/herdr.md +135 -0
  104. package/src/skills/loop.md +3 -2
  105. package/src/skills/opencode-cli.md +84 -0
  106. package/src/skills/pipeline.md +1 -1
  107. package/src/skills/release.md +5 -8
  108. package/src/skills/review-response.md +4 -2
  109. package/src/skills/rule.md +27 -1
  110. package/src/skills/ship.md +54 -7
  111. package/src/skills/worktree.md +2 -2
  112. package/src/upstreams.json +7 -0
  113. package/themes/_TEMPLATE.json +2 -0
  114. package/themes/biker.json +2 -0
  115. package/themes/commentator.json +2 -0
  116. package/themes/cyberpunk.json +2 -0
  117. package/themes/gamer.json +2 -0
  118. package/themes/imperial.json +2 -0
  119. package/themes/joker.json +2 -0
  120. package/themes/marvin.json +2 -0
  121. package/themes/mean.json +2 -0
  122. package/themes/military.json +2 -0
  123. package/themes/neutral.json +2 -0
  124. package/themes/pirate.json +2 -0
  125. package/themes/sports.json +2 -0
  126. package/themes/verstappen.json +2 -0
  127. package/themes/wizard.json +2 -0
  128. package/web/dist/assets/Activity-D2kOc3yi.js +1 -0
  129. package/web/dist/assets/ActivityDetail-By3xOr21.js +1 -0
  130. package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CBWDTBA4.js} +1 -1
  131. package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-BVbpriMB.js} +1 -1
  132. package/web/dist/assets/Dashboard-CIJLPHM9.js +2 -0
  133. package/web/dist/assets/Docs-CiRRIELs.js +5 -0
  134. package/web/dist/assets/Factories-DhyK0O8d.js +1 -0
  135. package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-DW3PgTPy.js} +1 -1
  136. package/web/dist/assets/Installs-B6nlo-Ly.js +3 -0
  137. package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-O65qEWfp.js} +1 -1
  138. package/web/dist/assets/Kits-C5U-yT6Z.js +1 -0
  139. package/web/dist/assets/Laws-CuTw_XNf.js +4 -0
  140. package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-D6-CVa3K.js} +1 -1
  141. package/web/dist/assets/Library-CzPlerd6.js +3 -0
  142. package/web/dist/assets/Loops-CqNF_-nS.js +2 -0
  143. package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-BNr8K5qj.js} +1 -1
  144. package/web/dist/assets/Personal-DeDb9e8O.js +2 -0
  145. package/web/dist/assets/Settings-B8MPN_AD.js +1 -0
  146. package/web/dist/assets/{Tabs-8zsyEPSK.js → Tabs-DJzAez4h.js} +1 -1
  147. package/web/dist/assets/index-BL3P-9Rg.js +6 -0
  148. package/web/dist/index.html +1 -1
  149. package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
  150. package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
  151. package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
  152. package/web/dist/assets/Docs-B5aHp86J.js +0 -5
  153. package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
  154. package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
  155. package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
  156. package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
  157. package/web/dist/assets/Library-B3FuFLel.js +0 -3
  158. package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
  159. package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
  160. package/web/dist/assets/Settings-BwErnh-R.js +0 -1
  161. package/web/dist/assets/index-Ce6qF2nG.js +0 -6
@@ -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
  });
@@ -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
 
@@ -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_FOR, 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,162 +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
- // 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.
191
-
192
- /**
193
- * Everything `rebuild-all` reads back off one install, and the argv that re-emits it unchanged.
194
- *
195
- * EXTRACTED SO `status` SHOWS WHAT A REBUILD WOULD USE, not a second reading of the same
196
- * markers that could drift from this one. An agent changing one setting takes `argv`, edits one
197
- * flag and runs it; every flag it did not touch has to be the install's own, or the "one
198
- * change" silently resets the rest — which is exactly the failure the seven read-backs below
199
- * exist to prevent.
200
- *
201
- * THE MARKER IS TRUSTED ONLY FOR ITS OWN HOST. There is one `.geneseed-emit` per root and the
202
- * last deploy wins, so in a dual-host repo (`.opencode/` and `.claude/` in one cwd) the other
203
- * host's row would otherwise rebuild with the WRONG emit — turning a Claude install into an
204
- * OpenCode one. `rebuild-all/a-dual-host-repo-rebuilds-each-row-in-its-own-emit` is the cell.
205
- */
206
- export function installProfile(host, scope, root, notify = null) {
207
- const raw = readMaybe(path.join(root, '.geneseed-emit'));
208
- let marker = raw === null ? '' : raw.trim();
209
- if (marker && (EMIT_HOST_SCOPE.get(marker) ?? ['', ''])[0] !== host) marker = '';
210
- const emit = marker || EMIT_FOR.get(`${host} ${scope}`) || 'opencode-global';
211
- // Every read-back below is narrowed to `host`'s OWN carrier (host-compat B1): in a repo
212
- // shared with another Claude-style host, an un-narrowed scan answers with WHICHEVER host's
213
- // carrier the shared `CARRIERS` order favours — the wrong carrier for every host but one.
214
- const theme = themeOfDir(root, host) || defaultTheme();
215
- const footprint = footprintOfDir(root);
216
- const posture = postureOfDir(root, host) || defaultPosture();
217
- const mode = modeOfDir(root, host) || defaultMode();
218
- // Read off the deployed loop skill; no config fallback — `DEFAULT_PRESET` is the engine's.
219
- const trust = trustOfDir(root, host) || DEFAULT_PRESET;
220
- // A rebuild that defaulted the pack selection would re-emit an install into a constitution
221
- // its owner did not choose — and in one direction that is not merely surprising: dropping
222
- // the process pack takes the commit/push consent RULES out of AGENT.md while
223
- // `claudeHookGroups` keeps the gate wired, or the reverse. ⚠ AND THE FALLBACK IS NOT
224
- // `harness.config.json`: a pre-migration carrier has no marker, and resolving that silence
225
- // out of a machine-wide config narrows every such install on its first upgrade.
226
- // `doctrinesForBuild` resolves unknown to ALL packs — see its docblock.
227
- const doctrines = doctrinesForBuild(root, host);
228
- // The per-rule axis is preserved for the same reason and with sharper teeth: an upgrade that
229
- // dropped it would quietly hand back every rule its owner switched off, and `process 5` is
230
- // one of them. `null` (no marker) stays `null` so the argv omits the flag, as it always did.
231
- const excludeRules = excludedRulesOfDir(root, host);
232
- // Skills left out stay left out: an upgrade that forgot them would put them all back.
233
- const excludeSkills = excludedSkillsOfDir(root, host, notify);
234
- // The gate switches: a rebuild that forgot one would silently re-arm (or, read wrong, disarm)
235
- // the install. A missing marker reads as armed.
236
- const gates = gatesOfDir(root, host);
237
- // Kits on stay on (spec A3); one this checkout no longer ships drops with a notice (R2).
238
- const kits = kitsOfDir(root, host, notify);
239
- // A project install's `Shared tier: on` stays on across a rebuild; a global install never has it.
240
- const sharedTier = sharedTierOfDir(root, host);
241
- const out = scope === 'global' ? null : root;
242
- const argv = setupBuildArgs(theme, emit, out, out, footprint, posture, mode, doctrines,
243
- PACK_ORDER, excludeRules, trust, excludeSkills, gates, kits, sharedTier);
244
- // A GLOBAL ROW NAMES ITS OWN DIR. `root` came from the host's config-dir resolver, which
245
- // honours env overrides (`OPENCODE_CONFIG_DIR`, `CLAUDE_CONFIG_DIR`…); without the flag the
246
- // same argv run from a shell lacking that variable re-emits into the DEFAULT dir — a second
247
- // install beside the one it was meant to rebuild. Appended, so the argv's head is unchanged.
248
- if (scope === 'global') argv.push('--config-dir', root);
249
- return {
250
- host, scope, root, state: installState(root, host, scope),
251
- emit, theme, footprint, posture, mode, trust, doctrines, excludeRules, excludeSkills,
252
- kits, sharedTier, ...gates, argv,
253
- };
254
- }
255
-
256
- /**
257
- * `argv` as one pasteable command, using the `geneseed build` launcher rather than the raw
258
- * generator: `geneseed-build` is only on PATH for an npm global install, while a git-clone
259
- * install has only the `geneseed` launcher, and `geneseed build` now forwards every flag
260
- * `setupBuildArgs` produces. Only whitespace is quoted — a path holding shell metacharacters
261
- * (`$`, `&`) would need quoting by hand.
262
- */
263
- export function rebuildCommand(argv) {
264
- return ['geneseed', 'build', ...argv.map((a) => (/\s/.test(a) ? `"${a}"` : a))].join(' ');
265
- }
266
-
267
121
  /**
268
122
  * `_harness_build.cmd_rebuild_all` — re-emit every ACTIVE install in place, best-effort.
269
123
  *