geneseed 4.32.0 → 5.0.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 (245) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/DESIGN.md +2 -2
  3. package/README.md +6 -5
  4. package/SHIPPED.md +4 -3
  5. package/adapters/bob/README.md +6 -5
  6. package/adapters/claude-code/README.md +4 -3
  7. package/adapters/claude-code/skills/geneseed/SKILL.md +1 -1
  8. package/adapters/openclaude/README.md +4 -3
  9. package/adapters/opencode/GLOBAL-HARNESS-SPEC.md +3 -1
  10. package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -1
  11. package/adapters/opencode/README.md +18 -18
  12. package/adapters/opencode/plugins/geneseed-activity.js +57 -1
  13. package/adapters/opencode/plugins/geneseed-context.js +85 -18
  14. package/adapters/opencode/plugins/geneseed-guard.js +437 -76
  15. package/adapters/opencode/plugins/geneseed-learn.js +97 -23
  16. package/bin/geneseed-cli.mjs +17 -25
  17. package/bin/geneseed-hook.mjs +23 -8
  18. package/docs/DESIGN.md +175 -0
  19. package/docs/PRD.md +111 -0
  20. package/docs/README.md +3 -2
  21. package/docs/architecture.md +145 -0
  22. package/docs/concepts/agents.md +1 -1
  23. package/docs/concepts/collaboration.md +1 -1
  24. package/docs/concepts/enforcement-table.md +1 -1
  25. package/docs/concepts/exclusions.md +5 -5
  26. package/docs/concepts/footprint.md +1 -1
  27. package/docs/concepts/foreman-mode.md +2 -2
  28. package/docs/concepts/hooks.md +22 -8
  29. package/docs/concepts/host-matrix.md +2 -2
  30. package/docs/concepts/hosts.md +1 -1
  31. package/docs/concepts/kits.md +3 -1
  32. package/docs/concepts/ownership.md +1 -1
  33. package/docs/concepts/rules.md +15 -2
  34. package/docs/concepts/shared-tier.md +73 -0
  35. package/docs/concepts/skills.md +2 -2
  36. package/docs/concepts/themes.md +1 -1
  37. package/docs/extending.md +13 -12
  38. package/docs/guides/install-claude-code.md +1 -1
  39. package/docs/guides/install-opencode.md +1 -1
  40. package/docs/guides/migrate.md +4 -2
  41. package/docs/guides/project-context.md +2 -2
  42. package/docs/guides/setup-footprint.md +1 -1
  43. package/docs/guides/uninstall.md +2 -1
  44. package/docs/guides/upgrade-to-5.md +116 -0
  45. package/docs/guides/upgrade.md +21 -9
  46. package/docs/guides/wiki.md +3 -3
  47. package/docs/reference/env-context.md +5 -3
  48. package/docs/reference/environment.md +1 -1
  49. package/docs/reference/glossary.md +2 -0
  50. package/docs/reference/opencode-plugins.md +3 -3
  51. package/docs/reference/plugin-activity.md +1 -1
  52. package/docs/reference/plugin-context.md +1 -0
  53. package/docs/reference/plugin-guard.md +14 -6
  54. package/docs/reference/plugin-learn.md +13 -6
  55. package/docs/reference/troubleshoot-hooks.md +3 -3
  56. package/docs/reference/troubleshoot-update.md +14 -0
  57. package/docs/token-footprint.md +4 -3
  58. package/docs/understand/a-day.md +2 -2
  59. package/docs/understand/design-choices-install.md +2 -1
  60. package/docs/understand/enforced-vs-asked.md +1 -1
  61. package/docs/understand/machine-bob.md +2 -0
  62. package/docs/understand/machine-claude.md +7 -5
  63. package/docs/understand/machine-opencode.md +7 -5
  64. package/docs/understand/on-your-machine.md +4 -0
  65. package/docs/understand/take-it-out.md +1 -1
  66. package/docs/web-ui.md +126 -68
  67. package/harness.config.json +1 -1
  68. package/js/README.md +10 -6
  69. package/js/build/args.mjs +10 -8
  70. package/js/build/bundle.mjs +11 -13
  71. package/js/build/driver.mjs +66 -65
  72. package/js/build/emit-claude.mjs +22 -16
  73. package/js/build/emit-common.mjs +4 -5
  74. package/js/build/emit-opencode.mjs +22 -22
  75. package/js/build/fold.mjs +515 -0
  76. package/js/build/generate.mjs +41 -52
  77. package/js/build/render.mjs +115 -29
  78. package/js/build/source.mjs +4 -1
  79. package/js/build/stubs.mjs +70 -9
  80. package/js/build/version.mjs +10 -10
  81. package/js/cli-table.json +23 -83
  82. package/js/hosts/activity.mjs +2 -2
  83. package/js/hosts/geneseed-dir.mjs +1 -1
  84. package/js/hosts/hooks-context.mjs +389 -99
  85. package/js/hosts/hooks-learn.mjs +38 -7
  86. package/js/hosts/hooks-prims.mjs +4 -2
  87. package/js/hosts/hooks.mjs +114 -39
  88. package/js/hosts/hosts.mjs +150 -51
  89. package/js/hosts/installs.mjs +55 -167
  90. package/js/hosts/link.mjs +3 -5
  91. package/js/hosts/mcp.mjs +1 -1
  92. package/js/hosts/memory-files.mjs +219 -17
  93. package/js/hosts/ownership-gate.mjs +1 -1
  94. package/js/hosts/settings.mjs +18 -13
  95. package/js/hosts/shim.mjs +4 -33
  96. package/js/hosts/store-watch.mjs +189 -0
  97. package/js/inspect/checks-authoring.mjs +3 -3
  98. package/js/inspect/checks-build.mjs +45 -18
  99. package/js/inspect/checks-counts.mjs +4 -4
  100. package/js/inspect/checks-repo.mjs +13 -14
  101. package/js/inspect/cost.mjs +24 -2
  102. package/js/inspect/diff.mjs +123 -123
  103. package/js/inspect/doctor.mjs +22 -27
  104. package/js/inspect/excludes.mjs +181 -62
  105. package/js/inspect/inventory.mjs +22 -27
  106. package/js/inspect/registry.mjs +106 -30
  107. package/js/inspect/scan.mjs +5 -5
  108. package/js/inspect/status.mjs +141 -119
  109. package/js/inspect/validate.mjs +22 -24
  110. package/js/lib/fs.mjs +47 -50
  111. package/js/lib/json.mjs +10 -17
  112. package/js/lib/machine-dir.mjs +73 -0
  113. package/js/lib/paths.mjs +22 -33
  114. package/js/lib/proc.mjs +1 -1
  115. package/js/lib/prompt.mjs +19 -27
  116. package/js/lib/text.mjs +8 -12
  117. package/js/lib/udiff.mjs +11 -15
  118. package/js/loop/catalog.mjs +2 -3
  119. package/js/maintain/memory.mjs +17 -17
  120. package/js/maintain/migrate.mjs +79 -89
  121. package/js/maintain/setup.mjs +43 -32
  122. package/js/maintain/uninstall.mjs +43 -61
  123. package/js/maintain/update.mjs +200 -93
  124. package/js/ui/anim.mjs +21 -35
  125. package/js/ui/cli.mjs +36 -58
  126. package/js/ui/menu.mjs +22 -45
  127. package/js/ui/tui.mjs +27 -67
  128. package/js/web/actions.mjs +34 -34
  129. package/js/web/api.mjs +130 -74
  130. package/js/web/catalog.mjs +175 -46
  131. package/js/web/docs.mjs +33 -12
  132. package/js/web/doctor-worker.mjs +14 -0
  133. package/js/web/handler.mjs +14 -5
  134. package/js/web/routes.mjs +17 -19
  135. package/js/web/state.mjs +78 -19
  136. package/js/web/update-check.mjs +25 -10
  137. package/js/web/user-files.mjs +50 -105
  138. package/package.json +7 -4
  139. package/registry.json +48 -55
  140. package/src/AGENT.md.tmpl +13 -14
  141. package/src/agents/_self-improvement.md +1 -1
  142. package/src/agents/_template.md +1 -1
  143. package/src/agents/advocate.md +1 -1
  144. package/src/agents/architect.md +1 -1
  145. package/src/agents/developer.md +1 -1
  146. package/src/agents/devops-engineer.md +1 -1
  147. package/src/agents/docker-expert.md +1 -1
  148. package/src/agents/docs.md +1 -1
  149. package/src/agents/empiricist.md +1 -1
  150. package/src/agents/explorer.md +1 -1
  151. package/src/agents/framer.md +1 -1
  152. package/src/agents/historian.md +1 -1
  153. package/src/agents/kubernetes-specialist.md +1 -1
  154. package/src/agents/memory-curator.md +2 -2
  155. package/src/agents/operator.md +1 -1
  156. package/src/agents/performance.md +1 -1
  157. package/src/agents/pragmatist.md +1 -1
  158. package/src/agents/react-engineer.md +1 -1
  159. package/src/agents/react-reviewer.md +1 -1
  160. package/src/agents/researcher.md +1 -1
  161. package/src/agents/reviewer.md +1 -1
  162. package/src/agents/security.md +1 -1
  163. package/src/agents/skeptic.md +1 -1
  164. package/src/agents/spring-boot-engineer.md +1 -1
  165. package/src/agents/spring-reviewer.md +1 -1
  166. package/src/agents/spring-security.md +1 -1
  167. package/src/agents/steward.md +1 -1
  168. package/src/agents/tester.md +1 -1
  169. package/src/agents/user-advocate.md +1 -1
  170. package/src/agents/visionary.md +1 -1
  171. package/src/memory/README.md +1 -1
  172. package/src/skills/_self-improvement.md +2 -2
  173. package/src/skills/daydream/SKILL.md +2 -2
  174. package/src/skills/daydream/instructions.md +1 -1
  175. package/src/skills/geneseed.md +1 -1
  176. package/src/skills/learn-mode.md +1 -2
  177. package/src/skills/profile.md +2 -2
  178. package/src/skills/rule/approve.md +69 -0
  179. package/src/skills/rule/consolidate.md +3 -3
  180. package/src/skills/rule.md +13 -5
  181. package/src/skills/skill-forge.md +1 -1
  182. package/src/skills/teach.md +29 -12
  183. package/src/skills/wiki.md +1 -1
  184. package/themes/_TEMPLATE.json +1 -2
  185. package/themes/biker.json +1 -2
  186. package/themes/commentator.json +1 -2
  187. package/themes/cyberpunk.json +1 -2
  188. package/themes/gamer.json +1 -2
  189. package/themes/imperial.json +1 -2
  190. package/themes/joker.json +1 -2
  191. package/themes/marvin.json +1 -2
  192. package/themes/mean.json +1 -2
  193. package/themes/military.json +1 -2
  194. package/themes/neutral.json +1 -2
  195. package/themes/pirate.json +1 -2
  196. package/themes/sports.json +1 -2
  197. package/themes/verstappen.json +1 -2
  198. package/themes/wizard.json +1 -2
  199. package/web/dist/assets/Activity-D8G4eClY.js +1 -0
  200. package/web/dist/assets/ActivityDetail-BtOBYk3M.js +1 -0
  201. package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
  202. package/web/dist/assets/Bonsai-B_y20b3i.js +1 -0
  203. package/web/dist/assets/{CopyButton-C5Li6awl.js → CopyButton-CHQte7Ap.js} +1 -1
  204. package/web/dist/assets/Dashboard-B8uXeJZ_.js +2 -0
  205. package/web/dist/assets/Docs-Dgv_MWfT.js +5 -0
  206. package/web/dist/assets/GreenhouseView-CSzTMSl_.js +1 -0
  207. package/web/dist/assets/Installs-BDk9lqBI.js +3 -0
  208. package/web/dist/assets/JournalView-CvRk1-m5.js +1 -0
  209. package/web/dist/assets/Kits-CoITzxWM.js +1 -0
  210. package/web/dist/assets/Laws-Ctf5r9rE.js +3 -0
  211. package/web/dist/assets/Library-DNwHYVXt.js +3 -0
  212. package/web/dist/assets/{Loops-CzitjxGV.js → Loops-S85PMQ8m.js} +2 -2
  213. package/web/dist/assets/{Markdown-C4S4tTA7.js → Markdown-0ORz7tAc.js} +21 -21
  214. package/web/dist/assets/OperatorHudView-DuGz_sTk.js +1 -0
  215. package/web/dist/assets/Personal-afJNwvRS.js +2 -0
  216. package/web/dist/assets/{RailCats-D5weYPCS.js → RailCats-AW92uhsX.js} +1 -1
  217. package/web/dist/assets/Settings-CGDFz-6j.js +1 -0
  218. package/web/dist/assets/Tabs-1qLrnqmn.js +1 -0
  219. package/web/dist/assets/api-C46vAuqp.js +1 -0
  220. package/web/dist/assets/controls-D4wmg_pl.js +1 -0
  221. package/web/dist/assets/index-COTd4TRZ.js +3 -0
  222. package/web/dist/assets/index-CtorA7uK.css +1 -0
  223. package/web/dist/assets/motion-RlUl1osO.js +1 -0
  224. package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
  225. package/web/dist/index.html +5 -5
  226. package/src/skills/quiz.md +0 -44
  227. package/web/dist/assets/Activity-Bjy64wHC.js +0 -1
  228. package/web/dist/assets/ActivityDetail-B0AaipP8.js +0 -1
  229. package/web/dist/assets/Bonsai-CJniRqaH.js +0 -1
  230. package/web/dist/assets/Dashboard-B-6DTmae.js +0 -2
  231. package/web/dist/assets/Docs-LRc30XL9.js +0 -5
  232. package/web/dist/assets/GreenhouseView-CcoYlaWo.js +0 -1
  233. package/web/dist/assets/Installs-dp1epTcE.js +0 -3
  234. package/web/dist/assets/JournalView-nFP4poCf.js +0 -1
  235. package/web/dist/assets/KitApply-DwyZUj57.js +0 -1
  236. package/web/dist/assets/Kits-C0IEdZXe.js +0 -1
  237. package/web/dist/assets/Laws-CkykmQWu.js +0 -3
  238. package/web/dist/assets/Library-Guh9HBZU.js +0 -2
  239. package/web/dist/assets/OperatorHudView-DLGNulIY.js +0 -1
  240. package/web/dist/assets/Personal-BMtberL8.js +0 -2
  241. package/web/dist/assets/Tabs-uYJqfuQt.js +0 -1
  242. package/web/dist/assets/api-BxjLd7Qd.js +0 -1
  243. package/web/dist/assets/index-DA7BiaE5.js +0 -3
  244. package/web/dist/assets/index-dbbDGFDq.css +0 -1
  245. package/web/dist/assets/motion-Bccx3zE8.js +0 -1
@@ -15,9 +15,9 @@
15
15
  * script's own location, not from an inherited `cfg`.
16
16
  *
17
17
  * A KEY IS DELIBERATELY ABSENT FROM `cfg`, and its absence is load-bearing.
18
- * `js_cfg()` (_build_core.py:199) always sent `structure` and `capabilityLinkRe`, because
19
- * the Python originals were module-level names that TESTS MUTATE — `_OWNED` membership
20
- * asked one level out. This driver has no Python module to mutate, so it sends neither;
18
+ * The former Python driver always sent `structure` and `capabilityLinkRe`, because
19
+ * those were module-level names that TESTS MUTATE. This driver has no such module to
20
+ * mutate, so it sends neither;
21
21
  * `js/build/render.mjs:215`'s `cfg.structure ?? STRUCTURE` takes its right-hand branch for
22
22
  * that reason — a fallback that was dead code until P4, always overridden by the driver
23
23
  * that always supplies it. `capabilityLinkRe`'s equivalent fallback in
@@ -26,7 +26,7 @@
26
26
  * supplied one, so there was no longer a `cfg` left to be absent from.
27
27
  *
28
28
  * THE FOOTPRINT DEFAULT IS THE FLAG'S, NOT THE FUNCTION'S. `--footprint` defaults to
29
- * `lean` (build.py:354); every `emit_*`/`build` SIGNATURE defaults to `full`. A driver
29
+ * `lean`; every `emit_*`/`build` SIGNATURE defaults to `full`. A driver
30
30
  * that reproduced the signature default would emit a different harness in every cell while
31
31
  * every gate that calls the functions directly stayed green.
32
32
  */
@@ -45,7 +45,7 @@ import { parseJson, jsonDumpsIndent } from '../lib/json.mjs';
45
45
  import { relPosix } from '../lib/text.mjs';
46
46
  // P5c moved these out of this file: `bin/geneseed-cli.mjs` needs the same four resolvers to
47
47
  // find a global install, and a resolver that decides WHERE a driver writes is the last thing
48
- // that should exist twice. golden.py's 259 cells are what made the move safe to attempt.
48
+ // that should exist twice.
49
49
  import {
50
50
  GLOBAL_MANIFEST, HOSTS, resolvePath, opencodeConfigDir, claudeConfigDir, bobConfigDir,
51
51
  openclaudeConfigDir, hostCatalogsNatively,
@@ -57,7 +57,7 @@ import { seedProtectedChecks } from '../hosts/geneseed-dir.mjs';
57
57
 
58
58
  // P5d moved these out of this file for the reason P5c moved the host resolvers: `harness
59
59
  // status` renders to count, so `bin/geneseed-cli.mjs` needs the same checkout paths and the
60
- // same cfg. golden.py's 259 cells all build one, which is what made the move safe.
60
+ // same cfg.
61
61
  import {
62
62
  GATE_SWITCHES, ROOT, makeCfg,
63
63
  } from './source.mjs';
@@ -99,7 +99,7 @@ export const PRIMARY_AGENT_SRC = path.join(ROOT, 'adapters', 'opencode', 'agents
99
99
  * It is invisible on a machine whose paths are already canonical, which is every machine
100
100
  * this ran on until GitHub's Windows runner handed it a `C:\\Users\\RUNNER~1\\...` and the
101
101
  * two CLIs printed the same directory under two different names — a 70-byte difference in a
102
- * line the former Python suite compared BYTE for byte; `tests/unit/resolve_out.test.mjs` pins
102
+ * line that was once compared BYTE for byte; `tests/unit/resolve_out.test.mjs` pins
103
103
  * it now. The
104
104
  * argument to `resolvePath` is made absolute first so its `expanduser` cannot fire: the
105
105
  * reference does not expand `~` here, and a bare `~` is a legal directory name. */
@@ -116,10 +116,9 @@ export function resolveOut(raw) {
116
116
  * key" no longer describes what resolves the directory; the carrier-name rule still holds.
117
117
  *
118
118
  * Computed HERE and not in the render child, and that is the inverted boundary rule doing
119
- * real work rather than being restated. P3b's note on the Python original: it resolves
120
- * through `_build_core._claude_config_dir`, an `_OWNED` name precisely because the suite
121
- * redirects it at a sandbox, and a redirect that stops at a subprocess half-works in
122
- * silence. The child must therefore never derive it — but this file is the PARENT, so
119
+ * real work rather than being restated. A redirect that stops at a subprocess half-works
120
+ * in silence, and the suite redirects the config dir at a sandbox. The child must
121
+ * therefore never derive it — but this file is the PARENT, so
123
122
  * deriving it is exactly this file's job, and `the host emit` receives the answer.
124
123
  *
125
124
  * POSIX spelling, per the original: `claudeMdExcludes` entries are glob patterns, where a
@@ -128,7 +127,10 @@ export function resolveOut(raw) {
128
127
  function preambleExclude(claudeMd, host) {
129
128
  if (path.basename(claudeMd) !== 'CLAUDE.md') return null;
130
129
  // OpenClaude inherited `claudeMdExcludes` from Claude Code; its global preamble is its own.
131
- const globalDir = host === 'openclaude' ? openclaudeConfigDir() : claudeConfigDir();
130
+ let globalDir;
131
+ try {
132
+ globalDir = host === 'openclaude' ? openclaudeConfigDir() : claudeConfigDir();
133
+ } catch { return null; } // no home: no global preamble to exclude, and a prior claim is kept
132
134
  return resolvePath(path.join(globalDir, 'CLAUDE.md')).split(path.sep).join('/');
133
135
  }
134
136
 
@@ -170,8 +172,7 @@ function relUnder(out, root) {
170
172
  * `_build_global._write_manifest_atomic` — temp + rename, so a torn manifest can never make
171
173
  * the next emit treat every owned file as the user's own.
172
174
  *
173
- * `writeText`, not `writeFileSync`: Python writes this through `Path.write_text`, so the
174
- * whole document is CRLF on Windows.
175
+ * `writeText`, not `writeFileSync`: the whole document is CRLF on Windows, as it always was.
175
176
  *
176
177
  * `jsonDumpsIndent`, not `JSON.stringify`: `json.dumps` defaults to `ensure_ascii=True` and
177
178
  * escapes every non-ASCII character, where `JSON.stringify` emits it raw. This was
@@ -297,12 +298,12 @@ function projectSurvivors(emitName) {
297
298
  }
298
299
 
299
300
  /**
300
- * `_build_emit.emit_opencode` — the driver body, which is what this phase actually ports.
301
+ * `_build_emit.emit_opencode` — the driver body.
301
302
  *
302
- * RENDER and WIRE already ran in Node before P4; what lived only in Python was the stage
303
- * either side of them: reading the previous manifest (PRE), pruning what this layer no
304
- * longer owns, writing the manifest atomically, and the summary line. All five stages now
305
- * run in one process, in the order `tests/unit/emit_phase_order.test.mjs` pins:
303
+ * The stage either side of RENDER and WIRE: reading the previous manifest (PRE),
304
+ * pruning what this layer no longer owns, writing the manifest atomically, and the
305
+ * summary line. All five stages run in one process, in the order
306
+ * `tests/unit/emit_phase_order.test.mjs` pins:
306
307
  * RENDER -> WIRE -> PRUNE -> MANIFEST -> VERIFY (opencode has no VERIFY; it writes no
307
308
  * settings file of its own).
308
309
  */
@@ -390,7 +391,7 @@ function emitOpencodeGlobal(cfg, args, out) {
390
391
  const rendered = emitOpencodeGlobalRender(
391
392
  { ...cfg, primaryAgentSrc: PRIMARY_AGENT_SRC },
392
393
  {
393
- theme: args.theme, cfgDir, out,
394
+ theme: args.theme, cfgDir, out, sharedRoot: args.sharedRoot,
394
395
  footprint: args.footprint, nativeCatalog: hostCatalogsNatively('opencode'),
395
396
  oldOwned, agentPath, oldDenies, oldEdit, oldHashes,
396
397
  });
@@ -415,8 +416,7 @@ function emitOpencodeGlobal(cfg, args, out) {
415
416
  + `${stats.nSkills} skills, ${stats.nPlugins} plugin(s), `
416
417
  + `${stats.nWorkflows} workflow file(s), AGENT.md, ${memStatus}, ${nbStatus}, `
417
418
  + `${cfgName} (no context.json)${extra}. `
418
- + 'The learn plugin now finds <cfg>/memory automatically; set GENESEED_HARNESS only to '
419
- + 'override.\n');
419
+ + 'Facts live in the shared tier, and the learn plugin finds it by itself.\n');
420
420
  return cfgDir;
421
421
  }
422
422
 
@@ -444,7 +444,7 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
444
444
  // `preambleExclude`'s own docblock). Spelling it as a call rather than a literal is what
445
445
  // makes that a measured `null` instead of an assumed one.
446
446
  const rendered = emitClaudeRender(cfg, {
447
- theme: args.theme, cfgDir, claudeMd, scope, host,
447
+ theme: args.theme, cfgDir, claudeMd, scope, host, sharedRoot: args.sharedRoot,
448
448
  out,
449
449
  footprint: args.footprint, nativeCatalog: hostCatalogsNatively(host),
450
450
  oldOwned, oldManaged, preambleExclude: preambleExclude(claudeMd, host),
@@ -475,11 +475,9 @@ function emitClaudeCore(cfg, args, { cfgDir, claudeMd, scope, host, out, hookOpt
475
475
  // external edit, a bug in the merge) is loud now instead of surfacing as hooks that
476
476
  // quietly never fire.
477
477
  //
478
- // On the Python driver this stage runs in Python AFTER a Node child did the wiring, which
479
- // makes it a live cross-implementation check on every build. Here both halves are Node, so
480
- // that particular property is gone and only the self-check remains — worth stating,
481
- // because it is a real reduction in what a Claude emit proves about itself, and the thing
482
- // that replaces it is the acceptance matrix rather than anything at runtime.
478
+ // Both halves are Node, so this proves only the emit against itself — worth stating,
479
+ // because it is a limit on what a Claude emit proves about itself; the acceptance matrix
480
+ // covers the rest, not anything at runtime.
483
481
  //
484
482
  // SILENT ON SUCCESS, which is its own coverage hazard: a clean emit prints nothing, so
485
483
  // deleting this call is byte-identical in all 259 cells. `test_verify_reports_an_orphaned
@@ -520,8 +518,8 @@ const CLAUDE_SHAPED = {
520
518
  summary: (at, r) => `[geneseed] claude-global -> ${at}: ${r.nAgents} subagents, `
521
519
  + `${r.nSkills} skills, CLAUDE.md, ${r.nHooks} hook group(s), settings.json, `
522
520
  + `${r.memStatus}, ${r.nbStatus}. No plugins/workflows/themes (no Claude analogue); `
523
- + '~/.claude/plugins is never touched. Hooks call the harness by absolute path; set '
524
- + 'GENESEED_HARNESS only to relocate memory.\n',
521
+ + '~/.claude/plugins is never touched. Hooks call the harness by absolute path. '
522
+ + 'Facts live in the shared tier.\n',
525
523
  },
526
524
  // Per-repo: CLAUDE.md at the root + a `.claude/` layer.
527
525
  claude: {
@@ -585,23 +583,22 @@ const claudeShaped = (name) => (cfg, args, out) => {
585
583
  };
586
584
 
587
585
  /**
588
- * build.py:437-466 — the POST stage, which writes markers and records the install and
586
+ * The POST stage, which writes markers and records the install and
589
587
  * wires NOTHING. `tests/unit/emit_phase_order.test.mjs`'s 'the post-emit marker stage wires
590
588
  * nothing' classifies it, and that is why it stays after the dispatch.
591
589
  *
592
- * `writeText`, never `writeFileSync`: Python's `Path.write_text` opens in text mode with
593
- * `newline=None` and translates the trailing `\n` to CRLF on Windows. A marker written
594
- * with a bare LF differs from Python's in every cell on this platform.
590
+ * `writeText`, never `writeFileSync`: it translates the trailing newline to CRLF on Windows,
591
+ * and a marker written with a bare LF differs from every other emitted file there.
595
592
  */
596
593
  function writeMarkers(markerDir, emit, footprint) {
597
594
  try {
598
595
  mkdirSync(markerDir, { recursive: true });
599
596
  writeText(path.join(markerDir, '.geneseed-emit'), `${emit}\n`);
600
- // Written for EVERY emit (build.py:443, unconditional), unlike the theme marker:
597
+ // Written for EVERY emit (unconditional), unlike the theme marker:
601
598
  // the claude/bob/openclaude PROJECT installs never call build(), so this is their only
602
599
  // footprint record. Read by harness._footprint_of_dir, which defaults to 'full'.
603
600
  writeText(path.join(markerDir, '.geneseed-footprint'), `${footprint}\n`);
604
- } catch { /* best-effort, exactly as build.py:444-445 — a marker hiccup never fails a build */ }
601
+ } catch { /* best-effort: a marker hiccup never fails a build */ }
605
602
  }
606
603
 
607
604
  /**
@@ -609,9 +606,8 @@ function writeMarkers(markerDir, emit, footprint) {
609
606
  * needs, and the reason it is a named export rather than a fifth branch in `main`.
610
607
  *
611
608
  * `harness diff` renders an 'expected' copy of a deployed install into a temp dir and
612
- * compares it file by file. The Python spells that `HOSTS[host]["emit_global"](theme,
613
- * out=..., cfg=<tmp>, footprint=...)`, where `cfg` overrides the target the emit would
614
- * otherwise resolve. This is that call, and the override is threaded as `args.cfgDir` through
609
+ * compares it file by file. `cfg` overrides the target the emit would otherwise resolve;
610
+ * the override is threaded as `args.cfgDir` through
615
611
  * the `emit*Global` bodies. The same key is also `--config-dir` on the command line: a global
616
612
  * emit never writes to `--out` (there `out` is the legacy bundle a memory store migrates FROM,
617
613
  * and `update` passes it for exactly that), so without the flag there was no way to preview a
@@ -642,12 +638,12 @@ const GLOBAL_EMITS = {
642
638
  *
643
639
  * IT CALLS THE EMIT, NOT `main`, AND THAT IS THE WHOLE POINT OF THE EXPORT. Routing this
644
640
  * through `driverMain(['--emit', 'claude', …])` would look like less code and would run two
645
- * stages the Python's direct call never reaches: `writeMarkers` drops `.geneseed-emit` and
641
+ * stages a direct call never reaches: `writeMarkers` drops `.geneseed-emit` and
646
642
  * `.geneseed-footprint` into the sandbox, and `registryRecord` writes a row into the USER'S
647
643
  * install registry for a temp directory that is deleted a millisecond later. A validation
648
644
  * pass must not register an install.
649
645
  *
650
- * `footprint: 'full'` is the Python signature default that `_claude_bob_emit_problems`'s
646
+ * `footprint: 'full'` is the signature default that `_claude_bob_emit_problems`'s
651
647
  * three-positional call leaves in place, inherited here rather than re-decided.
652
648
  */
653
649
  const PROJECT_EMITS = {
@@ -670,12 +666,12 @@ const PROJECT_EMITS = {
670
666
  * carry straight past the parameter default.
671
667
  */
672
668
  function axesCfg({
673
- posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, ...gates
669
+ posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, sharedTier, ...gates
674
670
  }) {
675
671
  return makeCfg({
676
672
  ...(posture ? { posture } : {}), ...(mode ? { mode } : {}), ...(trust ? { trust } : {}),
677
673
  ...(doctrines ? { doctrines } : {}), ...(excludeRules ? { excludeRules } : {}),
678
- ...(excludeSkills ? { excludeSkills } : {}), ...(kits ? { kits } : {}),
674
+ ...(excludeSkills ? { excludeSkills } : {}), ...(kits ? { kits } : {}), ...(sharedTier ? { sharedTier } : {}),
679
675
  // The gate switches (`GATE_SWITCHES` keys): only an explicit `false` disarms; `null` (no
680
676
  // opinion) keeps the gate.
681
677
  ...Object.fromEntries(GATE_SWITCHES.filter((g) => gates[g.key] === false).map((g) => [g.arg, true])),
@@ -684,7 +680,7 @@ function axesCfg({
684
680
 
685
681
  export function emitProjectInto(host, {
686
682
  theme, out, root, footprint = 'full', posture = null, mode = null, trust = null,
687
- doctrines = null, excludeRules = null, excludeSkills = null, kits = null, seed = true, ...gates
683
+ doctrines = null, excludeRules = null, excludeSkills = null, kits = null, sharedTier = false, seed = true, ...gates
688
684
  }) {
689
685
  const emit = PROJECT_EMITS[host];
690
686
  // The axes ride the same rail into every `*Into`, and for the same reason: a drift reader
@@ -695,7 +691,7 @@ export function emitProjectInto(host, {
695
691
  // the git root, which for a temp dir inside a repo is that repo, outside the sandbox.
696
692
  return withPlatformNewlines(() => emit(
697
693
  axesCfg({
698
- posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, ...gates }),
694
+ posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, sharedTier, ...gates }),
699
695
  { theme, footprint, root, seed }, out,
700
696
  ));
701
697
  }
@@ -710,24 +706,24 @@ export function emitProjectInto(host, {
710
706
  */
711
707
  export function buildInto({
712
708
  theme, out, footprint = 'lean', posture = null, mode = null, trust = null, doctrines = null,
713
- excludeRules = null, excludeSkills = null, kits = null, ...gates
709
+ excludeRules = null, excludeSkills = null, kits = null, sharedTier = false, ...gates
714
710
  }) {
715
711
  return withPlatformNewlines(() => build(axesCfg({
716
- posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, ...gates }),
712
+ posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, sharedTier, ...gates }),
717
713
  theme, out, { footprint, nativeCatalog: false }));
718
714
  }
719
715
 
720
716
  export function emitGlobalInto(host, {
721
717
  theme, out, cfgDir, footprint, posture = null, mode = null, doctrines = null, trust = null,
722
- excludeRules = null, excludeSkills = null, kits = null, ...gates
718
+ excludeRules = null, excludeSkills = null, kits = null, sharedTier = false, sharedRoot = undefined, ...gates
723
719
  }) {
724
720
  // `build.HOSTS.get(host, build.HOSTS["opencode"])` — an unknown host falls back rather than
725
721
  // raising, because the host comes from a marker file a user can edit.
726
722
  const emit = GLOBAL_EMITS[host] ?? GLOBAL_EMITS.opencode;
727
723
  // The same funnel `main` installs, for the same reason and not because `diff` asked: this
728
724
  // runs the whole render tree, whose ~25 print sites write raw `\n`. `diff` swallows the
729
- // emit's STDOUT and lets its stderr through (the Python's `redirect_stdout` does exactly
730
- // that), so an untranslated WARN from `warnBobGlobalOverProject` would reach the user's
725
+ // emit's STDOUT and lets its stderr through, so an untranslated WARN from
726
+ // `warnBobGlobalOverProject` would reach the user's
731
727
  // terminal with the wrong bytes on the one stream the caller deliberately does not hide.
732
728
  // ALL FIVE AXES TRAVEL WITH THE RENDER (see `axesCfg`). Callers that pass nothing keep the
733
729
  // reference's behaviour of rendering at `peer`/`direct`; the drift readers pass what the
@@ -736,23 +732,23 @@ export function emitGlobalInto(host, {
736
732
  // the same scar the footprint left in `diffCollect`, one axis over each time.
737
733
  return withPlatformNewlines(() => emit(
738
734
  axesCfg({
739
- posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, ...gates }),
740
- { theme, footprint, root: null, cfgDir }, out,
735
+ posture, mode, trust, doctrines, excludeRules, excludeSkills, kits, sharedTier, ...gates }),
736
+ { theme, footprint, root: null, cfgDir, sharedRoot }, out,
741
737
  ));
742
738
  }
743
739
 
744
740
  /**
745
741
  * EXPORTED because `harness build` is a passthrough to this program.
746
742
  *
747
- * `_harness_build.cmd_build` is `run([sys.executable, BUILD, *extra]).returncode` — Python
748
- * needs a second process because `build.py` is a different PROGRAM. Here it is a module in
749
- * the same one, and `bin/geneseed-cli.mjs` is under a transitive `child_process` ban, so
743
+ * The generator is a module in the same process, and `bin/geneseed-cli.mjs` is under a
744
+ * transitive `child_process` ban, so
750
745
  * `js/build/generate.mjs` calls this directly. The export is what makes the auto-run below need a
751
746
  * guard: without one, importing this file to reach `main` would RUN the generator with the
752
747
  * CLI's argv.
753
748
  */
754
749
  export function main(argv) {
755
- // `withPlatformNewlines` is what makes this driver's bytes Python's bytes on Windows, for every
750
+ // `withPlatformNewlines` makes this driver's bytes match the platform's text mode on
751
+ // Windows, for every
756
752
  // print site in the whole render tree at once — see its docblock for why a funnel and not
757
753
  // 25 calls to `printOut`. It wraps the `catch` as well as `run`, because `die` writes its
758
754
  // line on the way out.
@@ -763,7 +759,7 @@ export function main(argv) {
763
759
  // Every DELIBERATE refusal becomes this process's exit code — `die`'s, and equally
764
760
  // `assertSourceComplete`'s and `effectiveTheme`'s, which have already explained
765
761
  // themselves on stderr. An unmarked throw is a crash and keeps its stack, because
766
- // Python prints a traceback for one and dressing it as a tidy refusal would hide a bug.
762
+ // dressing it as a tidy refusal would hide a bug.
767
763
  if (e && e.exitCode !== undefined) return e.exitCode;
768
764
  throw e;
769
765
  }
@@ -798,7 +794,7 @@ function run(argv) {
798
794
  // `--sync-themes` is HERE, because it needs nothing this driver may not have: it reads
799
795
  // `themes/`, rewrites the files textually, and prints. `js/build/themes.mjs` carries it.
800
796
  // Non-zero when files were CHANGED (0 == already in sync), so CI can run it as a drift
801
- // check — build.py:393-397's mapping, and a refusal (exit 2) if the template is unreadable.
797
+ // check — and a refusal (exit 2) if the template is unreadable.
802
798
  if (args.syncThemes) return syncThemes() ? 1 : 0;
803
799
  // `--validate-only` is NOT, and cannot be: its source-tree half is the doctor, and
804
800
  // `js/inspect/checks-authoring.mjs` starts a process (`node --check` over the OpenCode plugins). This driver
@@ -822,12 +818,18 @@ function run(argv) {
822
818
  }
823
819
  args.cfgDir = resolveOut(args.cfgDir);
824
820
  }
821
+ // D11: the option belongs to a project install. A global install owns the tier, and a plain
822
+ // bundle has no host to read it with, so either would write a marker nothing honours.
823
+ if (args.sharedTier === 'on' && (args.emit === 'files' || args.emit.endsWith('-global'))) {
824
+ die(2, `argument --shared-tier: only applies to a per-repo host emit (got --emit ${args.emit}); `
825
+ + 'a global install already owns the shared tier');
826
+ }
825
827
  const cfg = makeCfg(args);
826
828
  warnDroppedKits(args, out);
827
829
 
828
830
  // The marker directory is the emit's TARGET, which for a global emit is the config dir it
829
831
  // just rendered into and not `--out` at all — so the emit returns it rather than the
830
- // caller guessing (build.py:427-436 re-resolves; returning it keeps one resolution).
832
+ // caller guessing (returning it keeps one resolution).
831
833
  //
832
834
  // NINE ARMS, TWO TABLES ALREADY ON FILE: `GLOBAL_EMITS` and `PROJECT_EMITS` above are
833
835
  // exactly this dispatch's `-global` and per-repo halves, keyed by host rather than by
@@ -837,13 +839,12 @@ function run(argv) {
837
839
  markerDir = GLOBAL_EMITS[args.emit.slice(0, -'-global'.length)](cfg, args, out);
838
840
  } else if (args.emit !== 'files') {
839
841
  // The PROJECT emits keep their markers in `out`, not in the host config dir the emit
840
- // wrote to (build.py:435-436) — `.claude/` is the layer, `out` is the install.
842
+ // wrote to — `.claude/` is the layer, `out` is the install.
841
843
  PROJECT_EMITS[args.emit](cfg, args, out);
842
844
  } else {
843
- // The ninth choice, a plain bundle: `nativeCatalog: false` is build.py:421's
844
- // three-positional-argument call reproduced — `build(args.theme, out, args.footprint)`
845
- // leaves `native_catalog` at its signature default. It is the one signature default
846
- // this driver DOES inherit, and it is inherited because the Python CLI inherits it too.
845
+ // The ninth choice, a plain bundle: `nativeCatalog: false` leaves
846
+ // `native_catalog` at its signature default, as `build(args.theme, out, args.footprint)`
847
+ // does. It is the one signature default this driver DOES inherit.
847
848
  build(cfg, args.theme, out, { footprint: args.footprint, nativeCatalog: false });
848
849
  }
849
850
 
@@ -858,7 +859,7 @@ function run(argv) {
858
859
  if (args.emit.endsWith('-global')) {
859
860
  try {
860
861
  writeText(path.join(markerDir, '.geneseed-theme'), `${args.theme}\n`);
861
- } catch { /* best-effort, as build.py:449-452 */ }
862
+ } catch { /* best-effort */ }
862
863
  }
863
864
  // An ALLOW-LIST, not "everything that is not global": a plain `--emit files` dev build —
864
865
  // the default — must never pollute the registry, and only the four per-repo host emits
@@ -16,14 +16,15 @@ import {
16
16
  import { get, isDict, isTruthy } from '../lib/json.mjs';
17
17
  import { relPosix } from '../lib/text.mjs';
18
18
  import { assertSourceComplete, phaseLog, ensureMemoryStore } from './bundle.mjs';
19
+ import { foldOnEmit } from './fold.mjs';
19
20
  import {
20
21
  claimAndWrite, globalMemory, globalNotebook, shipLeanLaws, stripCapabilityLinks,
21
22
  } from './emit-common.mjs';
22
- import { kitsBody, renderAll, renderFile } from './render.mjs';
23
+ import { kitsBody, pathTokens, renderAll, renderFile } from './render.mjs';
23
24
  import {
24
25
  BOB_RULES_STUB, bobFirstReply, ensureContextStub, ensureExcludesStub, ensureNotebookIndex,
25
26
  ensureProfileStub,
26
- ensureRulesStub, ensureWikiStub, WIKI_FILE,
27
+ ensureRulesStub, ensureWikiStub, sharedRootFor, WIKI_FILE,
27
28
  } from './stubs.mjs';
28
29
  import { writeVersion } from './version.mjs';
29
30
  import { existsSync, mkdirSync } from 'node:fs';
@@ -53,11 +54,13 @@ export function emitClaudeRender(cfg, job) {
53
54
  oldOwned, oldHashes = {},
54
55
  } = job;
55
56
 
56
- // `os.path.relpath(cfg, claude_md.parent)` — note the reversed argument order, and
57
- // that Python answers '.' for an identical pair where `path.relative` answers ''.
57
+ // Relative to the CLAUDE.md directory, so the argument order is cfg-from-claude_md; an
58
+ // identical pair is '.' where `path.relative` answers ''.
58
59
  const relCfg = relPosix(path.dirname(claudeMd), cfgDir) || '.';
59
60
  const lawsPrefix = relCfg === '.' ? '' : `${relCfg}/`;
60
- const { theme, items } = renderAll(cfg, themeName, { footprint, lawsPrefix, nativeCatalog });
61
+ // A re-render of a deployed install sends that install's root, null included.
62
+ const { sharedRoot = scope === 'global' ? sharedRootFor(cfgDir, host) : null } = job;
63
+ const { theme, items } = renderAll(cfg, themeName, { footprint, lawsPrefix, nativeCatalog, sharedRoot });
61
64
  assertSourceComplete(cfg, `claude-${scope}`);
62
65
  mkdirSync(cfgDir, { recursive: true });
63
66
 
@@ -68,7 +71,7 @@ export function emitClaudeRender(cfg, job) {
68
71
  // Deliberately NOT the same lookup as `agentText` below: that one skips an
69
72
  // AGENT.md whose text is null, this one does not. Unreachable today (`.md` is a
70
73
  // text suffix, so the render is never null) and reproduced anyway, because the two
71
- // spellings sit four lines apart in the Python and only one of them filters.
74
+ // spellings sit four lines apart and only one of them filters.
72
75
  //
73
76
  // The fast path itself is byte-inert, measured: removing it re-renders with a theme
74
77
  // whose DIR_* tokens gained an EMPTY prefix and with the same lawsPrefix, so it
@@ -82,6 +85,9 @@ export function emitClaudeRender(cfg, job) {
82
85
  ptheme[tok] = prefix + (ptheme[tok] ?? tok.split('_').slice(1).join('_').toLowerCase());
83
86
  }
84
87
  ptheme.AT_HARNESS = prefix;
88
+ // The PATH_* tokens are not in the loop: absolute ones take no prefix, and relative ones
89
+ // follow the tokens just prefixed.
90
+ Object.assign(ptheme, pathTokens(ptheme, sharedRoot));
85
91
  // The Kits block was substituted with the unprefixed DIR_* tokens; rebuild it, or its links dangle.
86
92
  ptheme.KITS_BODY = kitsBody(cfg, ptheme, '');
87
93
  // Same catalogue decision as the renderAll above — a re-render that forgot it would
@@ -113,8 +119,8 @@ export function emitClaudeRender(cfg, job) {
113
119
  : scope === 'project' ? (name) => relPosix(path.dirname(cfgDir), path.join(cfgDir, 'skills', name))
114
120
  : (name) => path.join(cfgDir, 'skills', name).split(path.sep).join('/');
115
121
  // Bob's and OpenClaude's agents/skills use the Claude dialect verbatim.
116
- // `manifestExisted` is deliberately not passed: the Python does not pass it either, so
117
- // the pre-manifest header line is unreachable from this emit on both sides.
122
+ // `manifestExisted` is deliberately not passed, so
123
+ // the pre-manifest header line is unreachable from this emit.
118
124
  // One shared `claim` (see `claimer`): the skills/agents writer and the Bob command writer
119
125
  // below both push into the same `owned` list, so a pre-manifest-install warning still
120
126
  // prints once across the whole emit rather than once per writer.
@@ -148,6 +154,8 @@ export function emitClaudeRender(cfg, job) {
148
154
  ensureRulesStub(cfgDir);
149
155
  ensureProfileStub(cfgDir);
150
156
  ensureExcludesStub(cfgDir);
157
+ // After the seeds, so what the fold sets aside is all it re-seeds. A project emit has no root.
158
+ if (sharedRoot !== null) foldOnEmit(host, cfgDir);
151
159
 
152
160
  // Project hygiene, claim-on-create: an existing (possibly user-authored) .gitignore is
153
161
  // never rewritten, but one we created stays owned across re-emits. The hook file is
@@ -216,8 +224,7 @@ export function emitClaudeRender(cfg, job) {
216
224
  *
217
225
  * `GENESEED_STACK_GLOBAL` is read from the environment on BOTH sides — the child inherits
218
226
  * `process.env`, so the opt-out reaches here without travelling in the job. `isTruthy` is
219
- * not needed for it: Python tests `os.environ.get(...)` for truthiness and an env var is
220
- * always a string, so `''` is the only falsy value either language sees.
227
+ * not needed for it: an env var is always a string, so `''` is the only falsy value.
221
228
  */
222
229
  function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRules = [],
223
230
  gates = {}) {
@@ -240,8 +247,8 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
240
247
  // when nothing else remains — a whole-file delete would eat prose the user added AFTER
241
248
  // Geneseed created the file.
242
249
  //
243
- // `os.path.relpath(claude_md, cfg).replace(os.sep, '/')`. Python answers '.' where
244
- // `path.relative` answers '' for an identical pair, the same guard `lawsPrefix` needs
250
+ // Relative path with '/' separators. An identical pair is '.' where
251
+ // `path.relative` answers '', the same guard `lawsPrefix` needs
245
252
  // above — unreachable here (CLAUDE.md is a file, cfgDir a directory, so the pair is
246
253
  // never identical) and spelled anyway, because the two call sites are 400 lines apart
247
254
  // and only one of them is obviously safe.
@@ -249,8 +256,7 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
249
256
  managed.claude_md = { rel };
250
257
  } else if (isBob && scope === 'global' && isTruthy(get(old, 'claude_md'))) {
251
258
  const oldCm = isDict(get(old, 'claude_md')) ? get(old, 'claude_md') : {};
252
- // `.resolve()` on the Python side; `path.resolve` is its counterpart and both are
253
- // applied to a path already built from an absolute cfgDir.
259
+ // `path.resolve` is applied to a path already built from an absolute cfgDir.
254
260
  const victim = path.resolve(cfgDir, get(oldCm, 'rel') || path.basename(claudeMd));
255
261
  managedBlockRemove(victim);
256
262
  }
@@ -306,8 +312,8 @@ function claudeWire(job, claudeMdText, hasAgentText, doctrines = null, excludeRu
306
312
  const addedExcl = wireClaudeExcludes(settingsPath, wantExcl);
307
313
  // Claim only what Geneseed itself wired (prior + newly added) — folding `wantExcl`
308
314
  // in unconditionally would claim a user's own pre-existing exclude, and uninstall
309
- // would then strip it. `sorted(set(a) | set(b))` — Python sorts strings by code
310
- // point and so does the default `Array.sort`, which is why no comparator is passed.
315
+ // would then strip it. The default `Array.sort` orders strings by code
316
+ // unit, which is the order wanted, so no comparator is passed.
311
317
  managed.settings_excludes = [...new Set([...priorExcl, ...addedExcl])].sort();
312
318
  }
313
319
  } else if (priorExcl.length && isBob) {
@@ -45,9 +45,8 @@ const LEAN_FULL_TEXT_DIRS = ['laws', 'ontology', 'doctrines'];
45
45
  /**
46
46
  * `_build_core.CAPABILITY_LINK_RE`.
47
47
  *
48
- * NOT OVERRIDABLE. Python's `cfg.capabilityLinkRe` was the driver's seam for tests that
49
- * monkeypatch `_build_core.CAPABILITY_LINK_RE`; `bin/build-driver.mjs` deliberately never
50
- * sends one (see its docblock), so the override branch that used to sit in
48
+ * NOT OVERRIDABLE. A `cfg.capabilityLinkRe` seam once let tests swap the pattern;
49
+ * `bin/build-driver.mjs` deliberately never sends one (see its docblock), so the override branch that used to sit in
51
50
  * `stripCapabilityLinks` never took its left-hand side and was deleted as dead code in the
52
51
  * over-engineering cleanup. `tests/unit/harness.test.mjs`'s planted-fault test drives this
53
52
  * exact constant by rewriting the module's source text instead, which is what "no injection
@@ -60,7 +59,7 @@ const CAPABILITY_LINK_RE =
60
59
  export const TMPL_SPEC_RE = /\{\{DIR_(AGENTS|SKILLS)\}\}\/([A-Za-z0-9_-]+)\.md/g;
61
60
 
62
61
  /**
63
- * `Path.rglob("*")` restricted to files, skipping `__pycache__` as Python's callers do.
62
+ * Every file under a directory, recursively, skipping `__pycache__`.
64
63
  *
65
64
  * `recursive: true, withFileTypes: true` (Node >= 20.1, `parentPath` >= 21.4 — this repo
66
65
  * requires >= 22.7) replaces a hand-rolled walk; the order it yields is NOT the walk's
@@ -94,7 +93,7 @@ export function stripCapabilityLinks(text) {
94
93
  * ever touching a store that already holds something.
95
94
  *
96
95
  * The three outcomes are the returned status string, which the emit prints, so they are
97
- * compared through stdout as well as through the tree. Python's `theme` parameter is
96
+ * compared through stdout as well as through the tree. A `theme` parameter is
98
97
  * dropped for both: the store dir is ALWAYS the classic English name, never themed (the
99
98
  * OpenCode config dir uses fixed names), so the argument was never read.
100
99
  *
@@ -20,10 +20,11 @@ import { assertSourceComplete, build, phaseLog, ensureMemoryStore } from './bund
20
20
  import {
21
21
  claimAndWrite, globalMemory, globalNotebook, shipLeanLaws, stripCapabilityLinks,
22
22
  } from './emit-common.mjs';
23
+ import { foldOnEmit } from './fold.mjs';
23
24
  import { renderAll } from './render.mjs';
24
25
  import {
25
26
  ensureExcludesStub, ensureNotebookIndex, ensureProfileStub, ensureRulesStub,
26
- ensureWikiStub,
27
+ ensureWikiStub, sharedRootFor,
27
28
  } from './stubs.mjs';
28
29
  import { writeVersion } from './version.mjs';
29
30
  import { mkdirSync } from 'node:fs';
@@ -42,8 +43,7 @@ import { mkdirSync } from 'node:fs';
42
43
  * earlier than RENDER, which still holds since nothing after this logs a phase at all.
43
44
  *
44
45
  * `manifestExisted` only ever arrives from the per-repo caller; the global emit does not pass
45
- * it, matching the Python side, so the pre-manifest header line stays unreachable from there on
46
- * both sides.
46
+ * it, so the pre-manifest header line stays unreachable from there.
47
47
  *
48
48
  * `overridesDir` is a THIRD directory, and it is not `dir` for the per-repo emit: the
49
49
  * per-repo `agent-overrides.json` lives beside the portable bundle in `out`, while every other
@@ -172,19 +172,14 @@ export function emitOpencodeRender(cfg, job) {
172
172
  * per-repo" OpenCode deployment. PRUNE and MANIFEST are the driver's; there is no VERIFY,
173
173
  * because this emit writes no settings file.
174
174
  *
175
- * ASSEMBLY, NOT TRANSLATION. Every unit it needs was already here — 58 of the 65 functions
176
- * in its Python closure, counted with `ast` rather than by name-mapping, which is how the
177
- * scout that produced this list first reported `_posture_body` and `_mode_body` as missing
178
- * when both are `registerBody` in `js/build/render.mjs`. What is new is the assembly and the
179
- * three values that had to be decided on the Python side.
175
+ * ASSEMBLY, NOT TRANSLATION. Every unit it needs already exists elsewhere (`_posture_body`
176
+ * and `_mode_body`, for one, are `registerBody` in `js/build/render.mjs`); what is here is the
177
+ * assembly and the values the caller must decide.
180
178
  *
181
- * `cfgDir` IS THE FIRST OF THEM AND THE REASON THE OTHERS WERE ASKED ABOUT.
182
- * `_build_core._opencode_config_dir` is an `_OWNED` name — the suite and `harness diff`
183
- * both redirect it at a sandbox — so resolving it here would render 135 files into the
184
- * developer's real `~/.config/opencode`. Python's entry point resolves it once, before
185
- * anything else, and sends the answer. Fourth phase running (`STRUCTURE` at P2d,
186
- * `capabilityLinkRe` at P2e, `_PREAMBLE_CONFIG_DIR` at P3b): send the decision, never the
187
- * resolver.
179
+ * `cfgDir` IS THE FIRST OF THEM. The suite and `harness diff` both redirect the OpenCode
180
+ * config dir at a sandbox, so resolving it here would render 135 files into the
181
+ * developer's real `~/.config/opencode`. The entry point resolves it once, before
182
+ * anything else, and sends the answer: send the decision, never the resolver.
188
183
  *
189
184
  * `out` IS NOT THE TARGET, and with the default nobody can tell. `emit_opencode_global`
190
185
  * writes into `<cfg>` and takes `out` ONLY as the legacy bundle to migrate a memory or
@@ -193,7 +188,7 @@ export function emitOpencodeRender(cfg, job) {
193
188
  * leaves them coincident — the `claude/bundle-in-subfolder` finding at a third call site.
194
189
  *
195
190
  * `agentPath` travels for the same reason `emitOpencodeRender`'s does: it is WIRE's one
196
- * input, and `Path.as_posix()` is the Python side's spelling of it.
191
+ * input, and it is a POSIX-style path.
197
192
  */
198
193
  export function emitOpencodeGlobalRender(cfg, job) {
199
194
  phaseLog('RENDER');
@@ -204,7 +199,9 @@ export function emitOpencodeGlobalRender(cfg, job) {
204
199
 
205
200
  // No `lawsPrefix`: the standalone laws dir sits beside AGENT.md in <cfg>, so the lean
206
201
  // pointer's relative `laws/universal.md` resolves with no prefix.
207
- const { theme, items } = renderAll(cfg, themeName, { footprint, nativeCatalog });
202
+ // A re-render of a deployed install sends that install's root, null included.
203
+ const { sharedRoot = sharedRootFor(cfgDir, 'opencode') } = job;
204
+ const { theme, items } = renderAll(cfg, themeName, { footprint, nativeCatalog, sharedRoot });
208
205
  assertSourceComplete(cfg, 'opencode-global');
209
206
  mkdirSync(cfgDir, { recursive: true });
210
207
 
@@ -212,17 +209,18 @@ export function emitOpencodeGlobalRender(cfg, job) {
212
209
  const agentText = items.find((i) => i.rel === 'AGENT.md' && i.text !== null)?.text ?? null;
213
210
  if (agentText !== null) {
214
211
  // OpenCode loads agents/skills natively, so drop AGENT.md's per-row spec links to
215
- // plain names. Memory links stay RELATIVE: in the global layout AGENT.md and the
216
- // store are siblings, so `memory/` resolves from AGENT.md's own location and stays
217
- // hermetic — no absolute path a doctor check would flag as an escape.
212
+ // plain names. Memory LINKS stay relative: in the global layout AGENT.md and the host
213
+ // store are siblings, so `memory/README.md` resolves from AGENT.md's own location and stays
214
+ // hermetic. The shared store is named in code spans only (`pathTokens`), never as a link
215
+ // target, which a doctor check would flag as an escape.
218
216
  const agentDest = path.join(cfgDir, 'AGENT.md');
219
217
  claimAndWrite(cfgDir, agentDest, 'AGENT.md', stripCapabilityLinks(agentText), owned);
220
218
  }
221
219
  // Co-owned, so never in `owned` — see `opencodeSentinelWrite`.
222
220
  opencodeSentinelWrite(cfgDir);
223
221
 
224
- // `manifestExisted` is deliberately not passed — the Python does not pass it either, so
225
- // the pre-manifest header line is unreachable from this emit on both sides.
222
+ // `manifestExisted` is deliberately not passed, so
223
+ // the pre-manifest header line is unreachable from this emit.
226
224
  const {
227
225
  nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused,
228
226
  } = opencodeLayer(cfg, items, themeName, theme, cfgDir, owned, {
@@ -237,6 +235,8 @@ export function emitOpencodeGlobalRender(cfg, job) {
237
235
  ensureRulesStub(cfgDir);
238
236
  ensureProfileStub(cfgDir);
239
237
  ensureExcludesStub(cfgDir);
238
+ // As in `emitClaudeRender`: after the seeds.
239
+ if (sharedRoot !== null) foldOnEmit('opencode', cfgDir);
240
240
 
241
241
  if (writeVersion(cfg, cfgDir) !== null) owned.push(VERSION_MARKER);
242
242