geneseed 5.3.1 → 5.5.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 (248) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +51 -18
  3. package/SHIPPED.md +7 -7
  4. package/adapters/bob/README.md +12 -1
  5. package/adapters/opencode/README.md +5 -3
  6. package/adapters/opencode/plugins/geneseed-context.js +77 -10
  7. package/adapters/opencode/plugins/geneseed-guard.js +106 -22
  8. package/adapters/opencode/plugins/geneseed-learn.js +641 -6
  9. package/bin/geneseed-cli.mjs +10 -0
  10. package/bin/geneseed-hook.mjs +5 -4
  11. package/docs/PRD.md +1 -1
  12. package/docs/README.md +1 -0
  13. package/docs/concepts/agents.md +14 -2
  14. package/docs/concepts/collaboration.md +2 -2
  15. package/docs/concepts/enforcement-table.md +5 -2
  16. package/docs/concepts/exclusions.md +16 -2
  17. package/docs/concepts/footprint.md +1 -1
  18. package/docs/concepts/foreman-mode.md +23 -4
  19. package/docs/concepts/hook-gates.md +4 -4
  20. package/docs/concepts/hooks.md +25 -7
  21. package/docs/concepts/host-matrix.md +4 -4
  22. package/docs/concepts/hosts.md +1 -1
  23. package/docs/concepts/kits.md +12 -2
  24. package/docs/concepts/loop-bricks.md +3 -3
  25. package/docs/concepts/loops.md +6 -4
  26. package/docs/concepts/ownership.md +1 -1
  27. package/docs/concepts/rules.md +2 -2
  28. package/docs/concepts/shared-tier.md +1 -1
  29. package/docs/concepts/skills.md +21 -1
  30. package/docs/concepts/themes.md +1 -1
  31. package/docs/extending.md +73 -29
  32. package/docs/guides/auto-merge.md +100 -0
  33. package/docs/guides/choose-your-setup.md +1 -1
  34. package/docs/guides/headless.md +1 -1
  35. package/docs/guides/install-clone.md +19 -1
  36. package/docs/guides/install-scripted.md +8 -2
  37. package/docs/guides/install.md +20 -2
  38. package/docs/guides/loop-finish.md +3 -3
  39. package/docs/guides/loop-running.md +4 -4
  40. package/docs/guides/project-context.md +1 -1
  41. package/docs/guides/run-a-factory.md +2 -2
  42. package/docs/guides/setup-doctrines.md +2 -2
  43. package/docs/guides/setup-footprint.md +1 -1
  44. package/docs/guides/uninstall.md +3 -3
  45. package/docs/guides/upgrade.md +2 -2
  46. package/docs/guides/worktree.md +1 -1
  47. package/docs/reference/env-context.md +1 -1
  48. package/docs/reference/environment.md +4 -2
  49. package/docs/reference/plugin-activity.md +1 -1
  50. package/docs/reference/plugin-guard.md +1 -1
  51. package/docs/reference/plugin-learn.md +5 -1
  52. package/docs/reference/plugin-workflow.md +1 -1
  53. package/docs/reference/profiles.md +142 -0
  54. package/docs/reference/troubleshoot-doctor.md +1 -1
  55. package/docs/reference/troubleshoot-hooks.md +2 -2
  56. package/docs/reference/troubleshoot-install.md +3 -3
  57. package/docs/reference/troubleshoot-tools.md +1 -1
  58. package/docs/token-footprint.md +11 -6
  59. package/docs/understand/design-choices-engineering.md +1 -1
  60. package/docs/understand/enforced-vs-asked.md +1 -1
  61. package/docs/understand/machine-claude.md +2 -2
  62. package/docs/understand/on-your-machine.md +1 -1
  63. package/docs/web-ui.md +8 -6
  64. package/harness.config.json +1 -1
  65. package/js/README.md +11 -3
  66. package/js/build/args.mjs +16 -4
  67. package/js/build/catalog.mjs +11 -1
  68. package/js/build/driver.mjs +74 -16
  69. package/js/build/emit-claude.mjs +32 -5
  70. package/js/build/emit-opencode.mjs +16 -9
  71. package/js/build/export.mjs +1 -1
  72. package/js/build/generate.mjs +12 -157
  73. package/js/build/notes-migrate.mjs +99 -0
  74. package/js/build/profile.mjs +326 -0
  75. package/js/build/render.mjs +110 -8
  76. package/js/build/retired-skills.mjs +60 -13
  77. package/js/build/source.mjs +100 -3
  78. package/js/build/stubs.mjs +4 -1
  79. package/js/cli-table.json +212 -7
  80. package/js/hosts/agent-runs.mjs +205 -0
  81. package/js/hosts/done-checks.mjs +3 -1
  82. package/js/hosts/hooks-done.mjs +428 -63
  83. package/js/hosts/hooks-learn.mjs +89 -3
  84. package/js/hosts/hooks-prims.mjs +44 -4
  85. package/js/hosts/hooks.mjs +159 -9
  86. package/js/hosts/hosts.mjs +10 -0
  87. package/js/hosts/installs.mjs +44 -2
  88. package/js/hosts/link.mjs +45 -10
  89. package/js/hosts/native.mjs +61 -7
  90. package/js/hosts/opencode.mjs +1 -1
  91. package/js/hosts/settings.mjs +101 -3
  92. package/js/hosts/spec-feedback.mjs +538 -0
  93. package/js/hosts/usage.mjs +67 -8
  94. package/js/inspect/agent-scores.mjs +118 -0
  95. package/js/inspect/checks-authoring.mjs +2 -1
  96. package/js/inspect/checks-build.mjs +20 -4
  97. package/js/inspect/checks-constitution.mjs +32 -0
  98. package/js/inspect/checks-repo.mjs +27 -2
  99. package/js/inspect/cost.mjs +6 -5
  100. package/js/inspect/diff.mjs +46 -8
  101. package/js/inspect/doctor.mjs +4 -0
  102. package/js/inspect/inventory.mjs +1 -1
  103. package/js/inspect/status.mjs +3 -1
  104. package/js/inspect/validate.mjs +1 -0
  105. package/js/lib/machine-dir.mjs +8 -0
  106. package/js/lib/paths.mjs +4 -1
  107. package/js/maintain/profile-scope.mjs +145 -0
  108. package/js/maintain/profiles.mjs +486 -0
  109. package/js/maintain/setup.mjs +413 -15
  110. package/js/maintain/uninstall.mjs +4 -1
  111. package/js/maintain/update.mjs +4 -2
  112. package/js/web/actions.mjs +44 -41
  113. package/js/web/api.mjs +13 -3
  114. package/js/web/handler.mjs +8 -0
  115. package/js/web/jobs.mjs +5 -4
  116. package/js/web/profiles-api.mjs +201 -0
  117. package/js/web/routes.mjs +5 -0
  118. package/package.json +2 -1
  119. package/profiles/guillaume-claude-global.json +16 -0
  120. package/profiles/starter.json +14 -0
  121. package/registry.json +14 -0
  122. package/src/AGENT.md.tmpl +16 -18
  123. package/src/agents/_self-improvement.md +15 -7
  124. package/src/agents/_template.md +4 -2
  125. package/src/agents/advocate.md +1 -1
  126. package/src/agents/architect.md +1 -1
  127. package/src/agents/developer.md +10 -3
  128. package/src/agents/devops-engineer.md +1 -1
  129. package/src/agents/docker-expert.md +1 -1
  130. package/src/agents/docs.md +1 -1
  131. package/src/agents/empiricist.md +1 -1
  132. package/src/agents/explorer.md +4 -2
  133. package/src/agents/framer.md +1 -1
  134. package/src/agents/historian.md +1 -1
  135. package/src/agents/kubernetes-specialist.md +1 -1
  136. package/src/agents/memory-curator.md +1 -1
  137. package/src/agents/operator.md +1 -1
  138. package/src/agents/performance.md +1 -1
  139. package/src/agents/pragmatist.md +1 -1
  140. package/src/agents/react-engineer.md +1 -1
  141. package/src/agents/react-reviewer.md +1 -1
  142. package/src/agents/researcher.md +1 -1
  143. package/src/agents/reviewer.md +10 -3
  144. package/src/agents/security.md +1 -1
  145. package/src/agents/skeptic.md +1 -1
  146. package/src/agents/spring-boot-engineer.md +1 -1
  147. package/src/agents/spring-reviewer.md +1 -1
  148. package/src/agents/spring-security.md +1 -1
  149. package/src/agents/steward.md +1 -1
  150. package/src/agents/tester.md +4 -2
  151. package/src/agents/user-advocate.md +1 -1
  152. package/src/agents/visionary.md +1 -1
  153. package/src/bricks/pr-open.md +3 -2
  154. package/src/doctrines/ops.md +2 -2
  155. package/src/doctrines/process.md +40 -36
  156. package/src/factories/analysis-to-build.json +1 -1
  157. package/src/factories/bug-report-to-fix.json +1 -1
  158. package/src/factories/issue-to-pr.json +1 -1
  159. package/src/kits/terminal-tools/rules.md +10 -0
  160. package/src/kits/terminal-tools.json +13 -0
  161. package/src/licenses/herdr.txt +201 -0
  162. package/src/memory/README.md +12 -2
  163. package/src/modes/foreman.md +25 -9
  164. package/src/skill-descriptions.json +63 -0
  165. package/src/skills/_self-improvement.md +42 -24
  166. package/src/skills/_template.md +3 -1
  167. package/src/skills/brainstorm.md +35 -22
  168. package/src/skills/commit.md +17 -17
  169. package/src/skills/daydream/VENDOR.md +6 -0
  170. package/src/skills/debug/ci.md +1 -1
  171. package/src/skills/dependencies.md +3 -3
  172. package/src/skills/diagram-design/VENDOR.md +4 -0
  173. package/src/skills/document-project.md +3 -2
  174. package/src/skills/explain-changes/VENDOR.md +5 -1
  175. package/src/skills/factory.md +13 -4
  176. package/src/skills/geneseed.md +4 -2
  177. package/src/skills/git-history.md +5 -7
  178. package/src/skills/herdr.md +135 -0
  179. package/src/skills/loop.md +3 -2
  180. package/src/skills/opencode-cli.md +84 -0
  181. package/src/skills/parallel-agents.md +11 -0
  182. package/src/skills/pipeline.md +3 -3
  183. package/src/skills/plan.md +5 -4
  184. package/src/skills/react-view-transitions/VENDOR.md +7 -1
  185. package/src/skills/release.md +11 -9
  186. package/src/skills/review-response.md +4 -2
  187. package/src/skills/rule/approve.md +2 -1
  188. package/src/skills/rule.md +27 -1
  189. package/src/skills/ship.md +54 -7
  190. package/src/skills/skill-forge.md +5 -3
  191. package/src/skills/token-report/VENDOR.md +5 -1
  192. package/src/skills/worktree.md +2 -2
  193. package/src/upstreams.json +9 -2
  194. package/themes/README.md +3 -1
  195. package/themes/_TEMPLATE.json +2 -0
  196. package/themes/biker.json +2 -0
  197. package/themes/commentator.json +2 -0
  198. package/themes/cyberpunk.json +2 -0
  199. package/themes/gamer.json +2 -0
  200. package/themes/imperial.json +2 -0
  201. package/themes/joker.json +2 -0
  202. package/themes/marvin.json +2 -0
  203. package/themes/mean.json +2 -0
  204. package/themes/military.json +2 -0
  205. package/themes/neutral.json +2 -0
  206. package/themes/pirate.json +2 -0
  207. package/themes/sports.json +2 -0
  208. package/themes/verstappen.json +2 -0
  209. package/themes/wizard.json +2 -0
  210. package/web/dist/assets/{ActiveLoops-BJJN3P-V.js → ActiveLoops-DOJCPPPc.js} +1 -1
  211. package/web/dist/assets/Activity-LKsDzsnK.js +1 -0
  212. package/web/dist/assets/ActivityDetail-DhwTfPm6.js +1 -0
  213. package/web/dist/assets/{Bonsai-BBl4XXqs.js → Bonsai-CePMLrpr.js} +1 -1
  214. package/web/dist/assets/{CopyButton-Beven8yn.js → CopyButton-CuoaJ6k7.js} +1 -1
  215. package/web/dist/assets/Dashboard-D1VKuvLe.js +2 -0
  216. package/web/dist/assets/Docs-CUrHJKaU.js +5 -0
  217. package/web/dist/assets/Factories-Ci1XfmSy.js +1 -0
  218. package/web/dist/assets/{GreenhouseView-Bce212qd.js → GreenhouseView-CNfH2lPK.js} +1 -1
  219. package/web/dist/assets/Installs-ZHQZM1iS.js +3 -0
  220. package/web/dist/assets/{JournalView-CV4omyww.js → JournalView-CMsWahkS.js} +1 -1
  221. package/web/dist/assets/Kits-CkliyK0n.js +1 -0
  222. package/web/dist/assets/Laws-hh4O3HZ4.js +4 -0
  223. package/web/dist/assets/{LibRows-Dag1s0ZX.js → LibRows-Brv0Hmkr.js} +1 -1
  224. package/web/dist/assets/Library-BYmiLjJr.js +3 -0
  225. package/web/dist/assets/Loops-ytm-xJ68.js +2 -0
  226. package/web/dist/assets/{OperatorHudView-JmYY1pBR.js → OperatorHudView-KaqCx_HP.js} +1 -1
  227. package/web/dist/assets/Personal-CmcnRKYE.js +2 -0
  228. package/web/dist/assets/Settings-tUrpdOfq.js +1 -0
  229. package/web/dist/assets/{Tabs-8zsyEPSK.js → Tabs-CD7etcGD.js} +1 -1
  230. package/web/dist/assets/api-CZ-x0iWG.js +1 -0
  231. package/web/dist/assets/{controls-D4wmg_pl.js → controls-CK7qHA8H.js} +1 -1
  232. package/web/dist/assets/{index-CRWqKxfY.css → index-Ba_Kg3Af.css} +1 -1
  233. package/web/dist/assets/index-COKbhFNo.js +6 -0
  234. package/web/dist/index.html +3 -3
  235. package/web/dist/assets/Activity-WQ3ykgxU.js +0 -1
  236. package/web/dist/assets/ActivityDetail-7rt04SkS.js +0 -1
  237. package/web/dist/assets/Dashboard-BgLArtgu.js +0 -2
  238. package/web/dist/assets/Docs-B5aHp86J.js +0 -5
  239. package/web/dist/assets/Factories-BjqzXAw8.js +0 -1
  240. package/web/dist/assets/Installs-B1OsrHXF.js +0 -3
  241. package/web/dist/assets/Kits-CW1e7xNa.js +0 -1
  242. package/web/dist/assets/Laws-1Ckf1lbs.js +0 -4
  243. package/web/dist/assets/Library-B3FuFLel.js +0 -3
  244. package/web/dist/assets/Loops-CwqgnLNw.js +0 -2
  245. package/web/dist/assets/Personal-DKLgLa7Z.js +0 -2
  246. package/web/dist/assets/Settings-BwErnh-R.js +0 -1
  247. package/web/dist/assets/api-DLDVY3K-.js +0 -1
  248. package/web/dist/assets/index-Ce6qF2nG.js +0 -6
@@ -22,6 +22,7 @@ import {
22
22
  claimAndWrite, globalMemory, globalNotebook, shipLeanLaws, stripCapabilityLinks,
23
23
  } from './emit-common.mjs';
24
24
  import { foldOnEmit } from './fold.mjs';
25
+ import { migrateProjectNotes } from './notes-migrate.mjs';
25
26
  import { pruneRetiredSkills } from './retired-skills.mjs';
26
27
  import { renderAll } from './render.mjs';
27
28
  import {
@@ -56,7 +57,7 @@ import { mkdirSync } from 'node:fs';
56
57
  function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
57
58
  const {
58
59
  oldOwned, manifestExisted, agentPath, wireBase, overridesDir, oldDenies = [], oldEdit = { asks: [], shorthand: null },
59
- oldHashes = {}, oldGates = [],
60
+ oldHashes = {}, oldGates = [], oldKeptHashes = {},
60
61
  } = opts;
61
62
  ensureAgentOverridesStub(cfg, overridesDir);
62
63
  const overrides = loadAgentOverrides(overridesDir);
@@ -114,6 +115,7 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
114
115
  // As `skillDenies`: a merge that wrote nothing keeps the old record whole.
115
116
  bashGates: wired.bashGates ? [...wired.bashGates].sort() : oldGates,
116
117
  kept: [...claim.kept],
118
+ keptHashes: claim.keptHashes(oldKeptHashes),
117
119
  };
118
120
  }
119
121
 
@@ -137,7 +139,7 @@ export function emitOpencodeRender(cfg, job) {
137
139
  phaseLog('RENDER');
138
140
  const {
139
141
  theme: _theme, out, root, footprint, nativeCatalog, oldOwned, manifestExisted, agentPath,
140
- oldDenies, oldEdit, oldHashes = {}, oldGates = [],
142
+ oldDenies, oldEdit, oldHashes = {}, oldGates = [], oldKeptHashes = {},
141
143
  } = job;
142
144
  const oc = path.join(root, '.opencode');
143
145
 
@@ -156,10 +158,12 @@ export function emitOpencodeRender(cfg, job) {
156
158
  const { theme, items } = renderAll(cfg, _theme, { footprint, nativeCatalog });
157
159
 
158
160
  const {
159
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
161
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes,
160
162
  } = opencodeLayer(cfg, items, _theme, theme, oc, owned, {
161
- oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes, oldGates,
163
+ oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
162
164
  });
165
+ // Notes an install older than #590 kept in `.opencode/notebook` (js/build/notes-migrate.mjs).
166
+ migrateProjectNotes(oc, root);
163
167
 
164
168
  return {
165
169
  owned,
@@ -172,6 +176,7 @@ export function emitOpencodeRender(cfg, job) {
172
176
  editRefused,
173
177
  bashGates,
174
178
  kept,
179
+ keptHashes,
175
180
  };
176
181
  }
177
182
 
@@ -206,7 +211,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
206
211
  phaseLog('RENDER');
207
212
  const {
208
213
  theme: themeName, cfgDir, out, footprint, nativeCatalog, oldOwned, agentPath, oldDenies, oldEdit,
209
- oldHashes = {}, oldGates = [],
214
+ oldHashes = {}, oldGates = [], oldKeptHashes = {},
210
215
  } = job;
211
216
 
212
217
  // No `lawsPrefix`: the standalone laws dir sits beside AGENT.md in <cfg>, so the lean
@@ -232,14 +237,15 @@ export function emitOpencodeGlobalRender(cfg, job) {
232
237
  opencodeSentinelWrite(cfgDir);
233
238
 
234
239
  // As in `emitClaudeRender`: before the skill layer claims anything.
235
- if (sharedRoot !== null) pruneRetiredSkills('opencode', cfgDir, oldOwned);
240
+ // `held`: the user's kept edits under a revived name, recorded again so they never lapse.
241
+ const held = sharedRoot !== null ? pruneRetiredSkills('opencode', cfgDir, oldOwned) : [];
236
242
 
237
243
  // `manifestExisted` is deliberately not passed, so
238
244
  // the pre-manifest header line is unreachable from this emit.
239
245
  const {
240
- nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept,
246
+ nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused, bashGates, kept, keptHashes,
241
247
  } = opencodeLayer(cfg, items, themeName, theme, cfgDir, owned, {
242
- oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes, oldGates,
248
+ oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes, oldGates, oldKeptHashes,
243
249
  });
244
250
 
245
251
  const memStatus = globalMemory(cfgDir, items, out, cfg.src);
@@ -269,6 +275,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
269
275
  editRecord,
270
276
  editRefused,
271
277
  bashGates,
272
- kept,
278
+ kept: [...new Set([...kept, ...held])],
279
+ keptHashes,
273
280
  };
274
281
  }
@@ -274,7 +274,7 @@ export function planExport({ profile = { ...PROFILE_DEFAULTS }, theme = 'neutral
274
274
  let body = forLibrary(lstripNewlines(s.it.text), s);
275
275
  let description;
276
276
  if (s.kind === 'skill') {
277
- description = skillDescription(s.it.text);
277
+ description = skillDescription(s.it.text, s.stem, cfg.src);
278
278
  body = stripSkillBodyLinks(link(pointSideFiles(body, s.stem, 'references')));
279
279
  if (!profile.keepSkillSelfImprovement) body = dropSelfImprovement(body);
280
280
  for (const side of items) {
@@ -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';
@@ -95,7 +91,8 @@ function sysExit(msg) {
95
91
  const BUILD_FORWARD = [
96
92
  ['theme', '--theme'], ['emit', '--emit'], ['footprint', '--footprint'],
97
93
  ['posture', '--posture'], ['mode', '--mode'], ['trust', '--trust'], ['doctrines', '--doctrines'],
98
- ['excludeRules', '--exclude-rules'], ['excludeSkills', '--exclude-skills'], ['kits', '--kits'], ['sharedTier', '--shared-tier'], ['out', '--out'], ['root', '--root'],
94
+ ['excludeRules', '--exclude-rules'], ['excludeSkills', '--exclude-skills'], ['kits', '--kits'], ['sharedTier', '--shared-tier'],
95
+ ['contextWindow', '--context-window'], ['out', '--out'], ['root', '--root'],
99
96
  ['configDir', '--config-dir'],
100
97
  ];
101
98
 
@@ -108,162 +105,20 @@ export function cmdBuild(args) {
108
105
  if (args.force) argv.push('--force');
109
106
  // Forwarded like `--force`: a one-shot flag of the generator, with no `GATE_SWITCHES` row.
110
107
  if (args.pruneGates) argv.push('--prune-gates');
108
+ // Forwarded like `--force`: one build's consent to return the omitted settings to their defaults.
109
+ if (args.reset) argv.push('--reset');
111
110
  return driverMain(argv);
112
111
  }
113
112
 
113
+ // An install's profile — `setupBuildArgs`, `installProfile`, `rebuildCommand` — lives in
114
+ // `./profile.mjs`, a leaf the driver can import for its preserve guard without reaching this
115
+ // module's lazy `update.mjs` (a spawner). Re-exported so every caller keeps its import.
116
+ export { installProfile, rebuildCommand, setupBuildArgs } from './profile.mjs';
117
+
114
118
  // --------------------------------------------------------------------------------------
115
119
  // rebuild-all
116
120
  // --------------------------------------------------------------------------------------
117
121
 
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
122
  /**
268
123
  * `_harness_build.cmd_rebuild_all` — re-emit every ACTIVE install in place, best-effort.
269
124
  *
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The project notes, moved to their one folder (the owner's ruling, 2026-11-15).
3
+ *
4
+ * Before the two scopes, a PROJECT install kept every spec-feedback note in its own notebook,
5
+ * which differs per host: `.claude/notebook`, `.bob/notebook`, `.openclaude/notebook`, and
6
+ * `.opencode/notebook` for an OpenCode install older than #590. Those notes were written with no
7
+ * scope, so each counts as a PROJECT note now: on the next emit of that install they are merged
8
+ * into `<project>/notebook/{agent,skill}-notes/`, the one folder every host's step 0 reads.
9
+ *
10
+ * NO LOSS, BY CONSTRUCTION. The merge has no cap (`mergeNotesText`: a line the target already holds
11
+ * exactly is not added twice, and nothing is dropped), the target is read back and must hold every
12
+ * line of the source before the source moves, and the source then moves aside into
13
+ * `<project>/notebook/archived-<sub>/<stamp>/`, beside the target so a removed worktree cannot take
14
+ * the backup with it, as the fold sets a host store aside: never unlinked. A file
15
+ * that cannot be merged (not UTF-8 on either side, a read or write that fails) stays where it was,
16
+ * named in one line. A global install's notebook is the fold's (js/build/fold.mjs `foldNotes`), and
17
+ * a second emit finds nothing to move.
18
+ */
19
+ import { isUtf8 } from 'node:buffer';
20
+ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
21
+ import path from 'node:path';
22
+ import { NOTES_DIRS } from '../lib/machine-dir.mjs';
23
+ import { normcase } from '../lib/paths.mjs';
24
+ import { relPosix } from '../lib/text.mjs';
25
+ import { archiveStore } from '../hosts/memory-files.mjs';
26
+ import {
27
+ excludeProjectNotes, mergeNotesText, projectNotesDir, withLock,
28
+ } from '../hosts/spec-feedback.mjs';
29
+
30
+ const isFile = (p) => { try { return statSync(p).isFile(); } catch { return false; } };
31
+ const readUtf8 = (p) => {
32
+ const raw = readFileSync(p);
33
+ if (!isUtf8(raw)) throw new Error('not UTF-8');
34
+ return raw.toString('utf8');
35
+ };
36
+ // Every line of a note, exact (a CR aside): what the read-back compares.
37
+ const linesOf = (text) => new Set(text.replace(/\r\n?/g, '\n').split('\n').filter((l) => l.trim()));
38
+
39
+ /**
40
+ * Merge `<cfgDir>/notebook/{agent,skill}-notes/*.md` into `<projectRoot>/notebook/…`. Returns
41
+ * `{ moved, kept, archived }`: the files merged and set aside, the files left in place with why,
42
+ * and where the moved ones went. Prints one line when it moved anything and one per file it kept.
43
+ */
44
+ export function migrateProjectNotes(cfgDir, projectRoot, say = (s) => process.stdout.write(s)) {
45
+ const report = { moved: [], kept: [], archived: [] };
46
+ // A linked worktree's notes go to its main checkout, as the hook writes them (`projectNotesDir`).
47
+ const target = projectNotesDir(projectRoot);
48
+ for (const sub of NOTES_DIRS) {
49
+ const src = path.join(cfgDir, 'notebook', sub);
50
+ const dst = path.join(target, sub);
51
+ if (normcase(path.resolve(src)) === normcase(path.resolve(dst))) continue;
52
+ let names;
53
+ try { names = readdirSync(src).filter((n) => n.endsWith('.md') && isFile(path.join(src, n))).sort(); } catch { continue; }
54
+ const merged = [];
55
+ for (const name of names) {
56
+ const from = path.join(src, name);
57
+ const to = path.join(dst, name);
58
+ const rel = relPosix(projectRoot, from) || from;
59
+ try {
60
+ const text = readUtf8(from);
61
+ mkdirSync(dst, { recursive: true });
62
+ // Under the capture's own lock: a hook may be adding a note to the same file right now.
63
+ const done = withLock(to, () => {
64
+ const next = mergeNotesText(existsSync(to) ? readUtf8(to) : '', text);
65
+ if (next !== null) writeFileSync(to, next, 'utf8');
66
+ return true;
67
+ });
68
+ if (done !== true) throw new Error('the notes file stayed locked');
69
+ const have = linesOf(readUtf8(to));
70
+ if ([...linesOf(text)].some((l) => !have.has(l))) throw new Error(`${relPosix(projectRoot, to)} does not hold every line`);
71
+ merged.push(name);
72
+ } catch (e) {
73
+ report.kept.push({ rel, why: e.message });
74
+ }
75
+ }
76
+ if (merged.length) {
77
+ // Beside the merge target, not the source: in a linked worktree the source goes with the
78
+ // worktree, and the backup must outlive it.
79
+ const dest = archiveStore(src, (_store, into) => {
80
+ mkdirSync(into, { recursive: true });
81
+ for (const name of merged) renameSync(path.join(src, name), path.join(String(into), name));
82
+ }, path.join(target, `archived-${sub}`));
83
+ report.archived.push(dest);
84
+ report.moved.push(...merged.map((n) => `${sub}/${n}`));
85
+ try { rmdirSync(src); } catch { /* not empty: a kept file, or one that is not a note */ }
86
+ }
87
+ }
88
+ if (report.moved.length) {
89
+ // The notes and their archives stay out of every commit (`.git/info/exclude`, per clone).
90
+ excludeProjectNotes(target);
91
+ say(`[geneseed] notes: merged ${report.moved.length} project note file(s) from `
92
+ + `${relPosix(projectRoot, path.join(cfgDir, 'notebook')) || cfgDir} into ${relPosix(projectRoot, target) || target}/; the originals `
93
+ + `are set aside in ${report.archived.map((a) => relPosix(projectRoot, a) || a).join(', ')}\n`);
94
+ }
95
+ for (const { rel, why } of report.kept) {
96
+ say(`[geneseed] notes: kept ${rel} where it is, not merged into ${relPosix(projectRoot, target) || target}/ (${why}); merge it by hand\n`);
97
+ }
98
+ return report;
99
+ }