geneseed 4.31.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 (272) hide show
  1. package/CHANGELOG.md +107 -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 +220 -18
  14. package/adapters/opencode/plugins/geneseed-guard.js +578 -74
  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 +6 -6
  26. package/docs/concepts/footprint.md +1 -1
  27. package/docs/concepts/foreman-mode.md +2 -2
  28. package/docs/concepts/hook-gates.md +1 -1
  29. package/docs/concepts/hooks.md +27 -11
  30. package/docs/concepts/host-matrix.md +3 -3
  31. package/docs/concepts/hosts.md +1 -1
  32. package/docs/concepts/kits.md +3 -1
  33. package/docs/concepts/loop-bricks.md +1 -1
  34. package/docs/concepts/loop-notes.md +4 -2
  35. package/docs/concepts/loop-templates.md +7 -4
  36. package/docs/concepts/loops.md +3 -0
  37. package/docs/concepts/ownership.md +2 -2
  38. package/docs/concepts/rules.md +15 -2
  39. package/docs/concepts/shared-tier.md +73 -0
  40. package/docs/concepts/skills.md +2 -2
  41. package/docs/concepts/themes.md +1 -1
  42. package/docs/extending.md +13 -12
  43. package/docs/guides/install-claude-code.md +1 -1
  44. package/docs/guides/install-opencode.md +1 -1
  45. package/docs/guides/migrate.md +4 -2
  46. package/docs/guides/project-context.md +2 -2
  47. package/docs/guides/run-a-loop.md +1 -1
  48. package/docs/guides/set-up-ownership.md +1 -1
  49. package/docs/guides/setup-footprint.md +1 -1
  50. package/docs/guides/uninstall.md +2 -1
  51. package/docs/guides/upgrade-to-5.md +116 -0
  52. package/docs/guides/upgrade.md +21 -9
  53. package/docs/guides/wiki.md +3 -3
  54. package/docs/reference/env-context.md +5 -3
  55. package/docs/reference/environment.md +1 -1
  56. package/docs/reference/glossary.md +2 -0
  57. package/docs/reference/loop-actions.md +1 -1
  58. package/docs/reference/opencode-plugins.md +3 -3
  59. package/docs/reference/plugin-activity.md +1 -1
  60. package/docs/reference/plugin-context.md +5 -0
  61. package/docs/reference/plugin-guard.md +14 -6
  62. package/docs/reference/plugin-learn.md +13 -6
  63. package/docs/reference/troubleshoot-hooks.md +3 -3
  64. package/docs/reference/troubleshoot-update.md +14 -0
  65. package/docs/token-footprint.md +4 -3
  66. package/docs/understand/a-day.md +2 -2
  67. package/docs/understand/design-choices-install.md +2 -1
  68. package/docs/understand/enforced-vs-asked.md +4 -3
  69. package/docs/understand/machine-bob.md +3 -1
  70. package/docs/understand/machine-claude.md +7 -5
  71. package/docs/understand/machine-opencode.md +7 -5
  72. package/docs/understand/on-your-machine.md +4 -0
  73. package/docs/understand/take-it-out.md +1 -1
  74. package/docs/web-ui.md +141 -73
  75. package/harness.config.json +1 -1
  76. package/js/README.md +10 -6
  77. package/js/build/args.mjs +10 -8
  78. package/js/build/bundle.mjs +11 -13
  79. package/js/build/driver.mjs +66 -65
  80. package/js/build/emit-claude.mjs +22 -16
  81. package/js/build/emit-common.mjs +4 -5
  82. package/js/build/emit-opencode.mjs +22 -22
  83. package/js/build/fold.mjs +515 -0
  84. package/js/build/generate.mjs +41 -52
  85. package/js/build/render.mjs +115 -29
  86. package/js/build/source.mjs +4 -1
  87. package/js/build/stubs.mjs +70 -9
  88. package/js/build/version.mjs +10 -10
  89. package/js/cli-table.json +23 -83
  90. package/js/hosts/activity.mjs +2 -2
  91. package/js/hosts/geneseed-dir.mjs +1 -1
  92. package/js/hosts/hooks-context.mjs +410 -99
  93. package/js/hosts/hooks-done.mjs +97 -31
  94. package/js/hosts/hooks-learn.mjs +38 -7
  95. package/js/hosts/hooks-prims.mjs +69 -2
  96. package/js/hosts/hooks.mjs +300 -64
  97. package/js/hosts/hosts.mjs +150 -51
  98. package/js/hosts/installs.mjs +55 -167
  99. package/js/hosts/link.mjs +3 -5
  100. package/js/hosts/mcp.mjs +1 -1
  101. package/js/hosts/memory-files.mjs +219 -17
  102. package/js/hosts/ownership-gate.mjs +1 -1
  103. package/js/hosts/settings.mjs +18 -13
  104. package/js/hosts/shim.mjs +4 -33
  105. package/js/hosts/store-watch.mjs +189 -0
  106. package/js/inspect/checks-authoring.mjs +3 -3
  107. package/js/inspect/checks-build.mjs +45 -18
  108. package/js/inspect/checks-counts.mjs +4 -4
  109. package/js/inspect/checks-repo.mjs +13 -14
  110. package/js/inspect/cost.mjs +24 -2
  111. package/js/inspect/diff.mjs +123 -123
  112. package/js/inspect/doctor.mjs +22 -27
  113. package/js/inspect/excludes.mjs +181 -62
  114. package/js/inspect/inventory.mjs +22 -27
  115. package/js/inspect/registry.mjs +106 -30
  116. package/js/inspect/scan.mjs +5 -5
  117. package/js/inspect/status.mjs +141 -119
  118. package/js/inspect/validate.mjs +22 -24
  119. package/js/lib/fs.mjs +47 -50
  120. package/js/lib/json.mjs +10 -17
  121. package/js/lib/machine-dir.mjs +73 -0
  122. package/js/lib/paths.mjs +22 -33
  123. package/js/lib/proc.mjs +1 -1
  124. package/js/lib/prompt.mjs +19 -27
  125. package/js/lib/text.mjs +8 -12
  126. package/js/lib/udiff.mjs +11 -15
  127. package/js/loop/catalog.mjs +2 -3
  128. package/js/loop/state.mjs +15 -5
  129. package/js/maintain/memory.mjs +17 -17
  130. package/js/maintain/migrate.mjs +79 -89
  131. package/js/maintain/setup.mjs +43 -32
  132. package/js/maintain/uninstall.mjs +43 -61
  133. package/js/maintain/update.mjs +200 -93
  134. package/js/ui/anim.mjs +21 -35
  135. package/js/ui/cli.mjs +36 -58
  136. package/js/ui/menu.mjs +22 -45
  137. package/js/ui/tui.mjs +27 -67
  138. package/js/web/actions.mjs +38 -38
  139. package/js/web/api.mjs +132 -76
  140. package/js/web/catalog.mjs +175 -46
  141. package/js/web/docs.mjs +33 -12
  142. package/js/web/doctor-worker.mjs +14 -0
  143. package/js/web/handler.mjs +14 -5
  144. package/js/web/routes.mjs +17 -19
  145. package/js/web/state.mjs +78 -19
  146. package/js/web/update-check.mjs +25 -10
  147. package/js/web/user-files.mjs +50 -105
  148. package/package.json +7 -4
  149. package/registry.json +48 -55
  150. package/src/AGENT.md.tmpl +13 -14
  151. package/src/agents/_self-improvement.md +1 -1
  152. package/src/agents/_template.md +4 -1
  153. package/src/agents/advocate.md +1 -1
  154. package/src/agents/architect.md +1 -1
  155. package/src/agents/developer.md +6 -3
  156. package/src/agents/devops-engineer.md +1 -1
  157. package/src/agents/docker-expert.md +1 -1
  158. package/src/agents/docs.md +1 -1
  159. package/src/agents/empiricist.md +1 -1
  160. package/src/agents/explorer.md +1 -1
  161. package/src/agents/framer.md +1 -1
  162. package/src/agents/historian.md +1 -1
  163. package/src/agents/kubernetes-specialist.md +1 -1
  164. package/src/agents/memory-curator.md +2 -2
  165. package/src/agents/operator.md +1 -1
  166. package/src/agents/performance.md +1 -1
  167. package/src/agents/pragmatist.md +1 -1
  168. package/src/agents/react-engineer.md +1 -1
  169. package/src/agents/react-reviewer.md +1 -1
  170. package/src/agents/researcher.md +1 -1
  171. package/src/agents/reviewer.md +1 -1
  172. package/src/agents/security.md +1 -1
  173. package/src/agents/skeptic.md +1 -1
  174. package/src/agents/spring-boot-engineer.md +1 -1
  175. package/src/agents/spring-reviewer.md +1 -1
  176. package/src/agents/spring-security.md +1 -1
  177. package/src/agents/steward.md +1 -1
  178. package/src/agents/tester.md +5 -2
  179. package/src/agents/user-advocate.md +1 -1
  180. package/src/agents/visionary.md +1 -1
  181. package/src/bricks/apply.md +3 -0
  182. package/src/bricks/test.md +6 -4
  183. package/src/loops/bugfix.json +11 -5
  184. package/src/loops/feature.json +7 -4
  185. package/src/memory/README.md +1 -1
  186. package/src/skills/_self-improvement.md +2 -2
  187. package/src/skills/daydream/SKILL.md +2 -2
  188. package/src/skills/daydream/instructions.md +1 -1
  189. package/src/skills/geneseed.md +1 -1
  190. package/src/skills/learn-mode.md +1 -2
  191. package/src/skills/loop.md +1 -0
  192. package/src/skills/profile.md +2 -2
  193. package/src/skills/rule/approve.md +69 -0
  194. package/src/skills/rule/consolidate.md +3 -3
  195. package/src/skills/rule.md +13 -5
  196. package/src/skills/ship.md +9 -1
  197. package/src/skills/skill-forge.md +1 -1
  198. package/src/skills/teach.md +29 -12
  199. package/src/skills/wiki.md +1 -1
  200. package/themes/_TEMPLATE.json +1 -2
  201. package/themes/biker.json +1 -2
  202. package/themes/commentator.json +1 -2
  203. package/themes/cyberpunk.json +1 -2
  204. package/themes/gamer.json +1 -2
  205. package/themes/imperial.json +1 -2
  206. package/themes/joker.json +1 -2
  207. package/themes/marvin.json +1 -2
  208. package/themes/mean.json +1 -2
  209. package/themes/military.json +1 -2
  210. package/themes/neutral.json +1 -2
  211. package/themes/pirate.json +1 -2
  212. package/themes/sports.json +1 -2
  213. package/themes/verstappen.json +1 -2
  214. package/themes/wizard.json +1 -2
  215. package/web/dist/assets/Activity-D8G4eClY.js +1 -0
  216. package/web/dist/assets/ActivityDetail-BtOBYk3M.js +1 -0
  217. package/web/dist/assets/AgentGlyph-k6o3gCM1.js +1 -0
  218. package/web/dist/assets/Bonsai-B_y20b3i.js +1 -0
  219. package/web/dist/assets/{CopyButton-IXnXzH4Y.js → CopyButton-CHQte7Ap.js} +1 -1
  220. package/web/dist/assets/Dashboard-B8uXeJZ_.js +2 -0
  221. package/web/dist/assets/{DataTable-BWbUx4bY.js → DataTable-b9zTShqJ.js} +1 -1
  222. package/web/dist/assets/Docs-Dgv_MWfT.js +5 -0
  223. package/web/dist/assets/{EmptyState-1sPNleqv.js → EmptyState-CY5Pm2xy.js} +1 -1
  224. package/web/dist/assets/FilterInput-qGKNSlxv.js +1 -0
  225. package/web/dist/assets/GreenhouseView-CSzTMSl_.js +1 -0
  226. package/web/dist/assets/Installs-BDk9lqBI.js +3 -0
  227. package/web/dist/assets/JournalView-CvRk1-m5.js +1 -0
  228. package/web/dist/assets/Kits-CoITzxWM.js +1 -0
  229. package/web/dist/assets/Laws-Ctf5r9rE.js +3 -0
  230. package/web/dist/assets/Library-DNwHYVXt.js +3 -0
  231. package/web/dist/assets/{Loops-C5u7fQOR.js → Loops-S85PMQ8m.js} +2 -2
  232. package/web/dist/assets/Markdown-0ORz7tAc.js +69 -0
  233. package/web/dist/assets/OperatorHudView-DuGz_sTk.js +1 -0
  234. package/web/dist/assets/Personal-afJNwvRS.js +2 -0
  235. package/web/dist/assets/RailCats-AW92uhsX.js +1 -0
  236. package/web/dist/assets/Settings-CGDFz-6j.js +1 -0
  237. package/web/dist/assets/Tabs-1qLrnqmn.js +1 -0
  238. package/web/dist/assets/api-C46vAuqp.js +1 -0
  239. package/web/dist/assets/controls-D4wmg_pl.js +1 -0
  240. package/web/dist/assets/index-COTd4TRZ.js +3 -0
  241. package/web/dist/assets/index-CtorA7uK.css +1 -0
  242. package/web/dist/assets/motion-RlUl1osO.js +1 -0
  243. package/web/dist/assets/react-C1iE8mnY.js +9 -0
  244. package/web/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  245. package/web/dist/assets/{sections-ChwaobfW.js → sections-CtFz7HFH.js} +1 -1
  246. package/web/dist/assets/{usePoll-bDFN-Hr6.js → usePoll-o8ul-Sog.js} +1 -1
  247. package/web/dist/index.html +7 -7
  248. package/src/skills/quiz.md +0 -44
  249. package/web/dist/assets/Activity-B7cFtS00.js +0 -1
  250. package/web/dist/assets/ActivityDetail-C-GbMmuW.js +0 -1
  251. package/web/dist/assets/Bonsai-_YyexVC5.js +0 -1
  252. package/web/dist/assets/Dashboard-sCfEjowQ.js +0 -2
  253. package/web/dist/assets/Docs-w3Y7M5Ts.js +0 -5
  254. package/web/dist/assets/FilterInput-CZREvrjX.js +0 -1
  255. package/web/dist/assets/GreenhouseView-BWWbMKmg.js +0 -1
  256. package/web/dist/assets/Installs-CnkdJ-VA.js +0 -3
  257. package/web/dist/assets/JournalView-C7bPD3fZ.js +0 -1
  258. package/web/dist/assets/KitApply-CQQbnThf.js +0 -1
  259. package/web/dist/assets/Kits-aj07N7mT.js +0 -1
  260. package/web/dist/assets/Laws-DZ38nl_H.js +0 -3
  261. package/web/dist/assets/Library-QCGXPV5h.js +0 -2
  262. package/web/dist/assets/Markdown-DpmmtW2Y.js +0 -65
  263. package/web/dist/assets/OperatorHudView-Blu1lqiZ.js +0 -1
  264. package/web/dist/assets/Personal-ox_MktWO.js +0 -2
  265. package/web/dist/assets/RailCats-BuJD4Jou.js +0 -1
  266. package/web/dist/assets/Tabs-CIPyMAX-.js +0 -1
  267. package/web/dist/assets/api-BxjLd7Qd.js +0 -1
  268. package/web/dist/assets/index-0GCxkY7m.css +0 -1
  269. package/web/dist/assets/index-CzDi9JpF.js +0 -3
  270. package/web/dist/assets/motion-CXaUMNkg.js +0 -1
  271. package/web/dist/assets/react-DlYQp10C.js +0 -9
  272. package/web/dist/assets/rolldown-runtime-hePW80VL.js +0 -1
@@ -19,8 +19,13 @@ import path from 'node:path';
19
19
  import os from 'node:os';
20
20
  import { printErr, withDiscardableStderr, isDir, isFile, readText } from '../lib/fs.mjs';
21
21
  import { toPlatformPath, normcase } from '../lib/paths.mjs';
22
+ import { sharedPaths, machineDir } from '../lib/machine-dir.mjs';
22
23
  import { mainWorktreeOf } from './gitref.mjs';
23
24
 
25
+ /** The marker a project built `--shared-tier on` carries, and its one reader. The OpenCode context plugin holds a copy. */
26
+ export const SHARED_TIER_LINE = 'Shared tier: on';
27
+ export const SHARED_TIER_RE = /^Shared tier:[ \t]*on[ \t]*\r?$/m;
28
+
24
29
  /** `_build_global.GLOBAL_MANIFEST` — the file whose presence means "a global install". */
25
30
  export const GLOBAL_MANIFEST = '.geneseed-manifest.json';
26
31
 
@@ -47,6 +52,9 @@ export const ADVISORY_VERB = 'done-gate-advisory';
47
52
  * second copy in `js/inspect/` was the alternative, and a copy is what let the `~user`
48
53
  * refusal diverge between the two CLIs once already (see `hooks.mjs`'s header).
49
54
  *
55
+ * SHARED LIST: a global install also honours `excludes.json` in the machine tier (B8: the lists
56
+ * drifted across hosts). The OpenCode plugins carry the same union in their twins.
57
+ *
50
58
  * A LINKED GIT WORKTREE OF AN EXCLUDED REPO IS EXCLUDED TOO, wherever it sits on disk: the
51
59
  * cwd matches, or the main worktree `mainWorktreeOf` reads off the `.git` file does. An
52
60
  * exclusion names a repository the user keeps sovereign, not a folder; a worktree elsewhere
@@ -54,13 +62,22 @@ export const ADVISORY_VERB = 'done-gate-advisory';
54
62
  */
55
63
  export function sovereignBypass(root) {
56
64
  if (!root) return false;
57
- let entries;
65
+ const listOf = (file) => {
66
+ try {
67
+ const data = JSON.parse(readText(file));
68
+ return Array.isArray(data && data.excludes) ? data.excludes : [];
69
+ } catch {
70
+ return [];
71
+ }
72
+ };
73
+ const entries = listOf(path.join(root, EXCLUDES_FILE));
74
+ // The shared list (`<machineDir>/excludes.json`) adds to a GLOBAL install's own, never to a
75
+ // project install's: a folder excluded for the global harness must not silence a project
76
+ // install that lives inside it. The tier test runs only when the shared list has entries.
58
77
  try {
59
- const data = JSON.parse(readText(path.join(root, EXCLUDES_FILE)));
60
- entries = Array.isArray(data && data.excludes) ? data.excludes : [];
61
- } catch {
62
- return false;
63
- }
78
+ const shared = listOf(path.join(machineDir(), EXCLUDES_FILE));
79
+ if (shared.length && isGlobalInstall(null, root)) entries.push(...shared);
80
+ } catch { /* no home dir, or an unresolvable config dir: the host list alone */ }
64
81
  // Nothing to match, so no reason to pay for the cwd and `.git` reads below on every hook call.
65
82
  if (!entries.length) return false;
66
83
  let heres;
@@ -78,11 +95,11 @@ export function sovereignBypass(root) {
78
95
  if (typeof raw !== 'string' || !raw.trim()) continue;
79
96
  let base;
80
97
  try {
81
- // `.rstrip("\\/")` AFTER normcase, exactly as the Python orders it, so the separator
98
+ // `.rstrip("\\/")` AFTER normcase, so the separator
82
99
  // test below cannot be fooled by a trailing slash in the user's file.
83
100
  //
84
101
  // `withDiscardableStderr` because `expanduser` writes its refusal at the RAISE SITE
85
- // and this caller catches: the reference prints nothing here, so replaying the
102
+ // and this caller catches: nothing should print here, so replaying the
86
103
  // message would be a stderr divergence on every hook call for one bad entry.
87
104
  //
88
105
  // `resolvePath`, the same resolution as `heres` above: symlinks and junctions are followed on
@@ -211,7 +228,7 @@ function projectWiresVerb(cand, verb) {
211
228
  }
212
229
 
213
230
  /**
214
- * `_harness_mcp._settings_file` — the file this install's hooks were actually wired into.
231
+ * The file this install's hooks were actually wired into.
215
232
  *
216
233
  * `settings.local.json` for a Claude or OpenClaude PROJECT install (personal, untracked),
217
234
  * `settings.json` everywhere else (including Bob's, which documents no local variant), and
@@ -236,7 +253,7 @@ function emitMarkerOf(dir) {
236
253
  try { return readText(path.join(dir, '.geneseed-emit')).trim(); } catch { return ''; }
237
254
  }
238
255
 
239
- /** `_harness_mcp.DISABLED_STASH` — a sibling dir whose presence means "disabled". */
256
+ /** A sibling dir whose presence means "disabled". */
240
257
  export const DISABLED_STASH = '.geneseed-disabled';
241
258
 
242
259
  /**
@@ -250,7 +267,7 @@ export const DISABLED_STASH = '.geneseed-disabled';
250
267
  * only against `configDir()` made `rebuild-all` re-emit it as a PROJECT rooted at `$HOME`;
251
268
  * * its own `.geneseed-emit` names a `-global` emit (`<host>-global` when `host` is given).
252
269
  * Case-folded on Windows. A `configDir()` that throws propagates: each caller already has the
253
- * catch that says what "cannot tell" means for it (the hook stays loud).
270
+ * catch that says what "cannot tell" means for it (`isGlobalInstall` is the one most share).
254
271
  */
255
272
  export function isHostGlobalDir(host, dir) {
256
273
  const emit = emitMarkerOf(dir);
@@ -261,6 +278,28 @@ export function isHostGlobalDir(host, dir) {
261
278
  && normcase(resolvePath(path.join(os.homedir(), h.projectMarker))) === c)));
262
279
  }
263
280
 
281
+ /**
282
+ * `isHostGlobalDir` for the callers that read "cannot tell" as "not global": whatever reads the
283
+ * machine tier stays on its own layer then, and no refusal printed on the way reaches stderr. A
284
+ * caller whose "cannot tell" must fail the other way (`holdsInstall`'s) keeps its own catch.
285
+ */
286
+ export function isGlobalInstall(host, dir) {
287
+ try { return withDiscardableStderr(() => isHostGlobalDir(host, dir)); } catch { return false; }
288
+ }
289
+
290
+ /**
291
+ * Is `cfgDir` the one directory `host`'s `configDir()` resolves to? Only such an install creates
292
+ * and folds the shared tier. Stricter than `isHostGlobalDir` on purpose: `diff` renders a global
293
+ * emit into a temp dir and `rebuild-all` passes `--config-dir` for every row, so neither a
294
+ * `-global` marker, the flag nor a default `~/.claude` proves this is the live install.
295
+ */
296
+ export function isCanonical(cfgDir, host) {
297
+ const row = HOSTS.find((h) => h.host === host);
298
+ try {
299
+ return !!row && normcase(resolvePath(cfgDir)) === normcase(resolvePath(row.configDir()));
300
+ } catch { return false; }
301
+ }
302
+
264
303
  /**
265
304
  * The project root a hook judges against: `$CLAUDE_PROJECT_DIR` (Claude Code and OpenClaude set
266
305
  * it for every hook — the session's root, where its project hooks were loaded from), else the
@@ -281,23 +320,11 @@ export const VERSION_MARKER = '.geneseed-version';
281
320
  /**
282
321
  * `Path.expanduser()` — a LEADING `~` only, and `~` alone counts.
283
322
  *
284
- * The docblock here used to claim "Python does not expand `~user` on Windows the way a
285
- * shell would". That claim was FALSE, and `921384f`'s widened probe corpus caught it:
286
- * `ntpath.expanduser('~someuser/x')` swaps the last component of `%USERPROFILE%` and
287
- * returns `C:\Users\someuser\x` — it happily expands a name that may not even be a real
288
- * account.
289
- *
290
- * AND THE POSIX HALF OF THAT SENTENCE WAS WRONG IN ITS TURN, corrected here while the
291
- * reference is still on the machine to ask. `posixpath.expanduser` does the analogous thing
292
- * through the password database and returns the path unchanged when the account is unknown
293
- * — but the reference does not call it. It calls `Path.expanduser`, which re-checks the
294
- * result and RAISES `RuntimeError: Could not determine home directory.` So the divergence
295
- * below is WINDOWS-ONLY: on POSIX the reference and this port already agree in kind — both
296
- * refuse — and differ only in which exception says so.
297
- *
298
- * This port deliberately does NEITHER. Reproducing `ntpath`'s swap faithfully needs its own
299
- * corpus, and the Python reference is being deleted, so byte-parity on this one input stops
300
- * mattering the moment it is. What matters instead is that a `~user` form never resolves
323
+ * `ntpath.expanduser('~someuser/x')` swaps the last component of `%USERPROFILE%`, expanding a
324
+ * name that may not be a real account. `Path.expanduser` on POSIX raises when the account is
325
+ * unknown. The two disagree, so the divergence is WINDOWS-ONLY.
326
+ *
327
+ * This port deliberately does NEITHER. What matters is that a `~user` form never resolves
301
328
  * SILENTLY to the wrong place: the old code below returned it untouched, so
302
329
  * `--target ~someone/x` created a literal `~someone` directory in whatever cwd the user ran
303
330
  * from. It now REFUSES the form outright. This is the single primitive every config-dir env
@@ -430,8 +457,8 @@ export function openclaudeConfigDir() {
430
457
  *
431
458
  * `projectMarker` joined in P5f. `_install_targets` asks "does this cwd carry a project
432
459
  * install of host H", and `_claude_cfg` asks "which subdir holds a project install's
433
- * manifest" — both are the same `.opencode`/`.claude`/`.bob`/`.openclaude` value the Python reads
434
- * out of `build.HOSTS[host]["project_marker"]`, so it belongs beside the config dir rather
460
+ * manifest" — both are the same `.opencode`/`.claude`/`.bob`/`.openclaude` value as
461
+ * `build.HOSTS[host]["project_marker"]`, so it belongs beside the config dir rather
435
462
  * than in a second table in `js/hosts/installs.mjs`.
436
463
  *
437
464
  * `agentFile` joined in P5h, and for one caller: `cmd_uninstall` names the managed block's
@@ -463,6 +490,55 @@ export const HOSTS = [
463
490
  { host: 'openclaude', family: 'claude', configDir: openclaudeConfigDir, projectMarker: '.openclaude', agentFile: 'CLAUDE.md', catalog: { skills: true, agents: true }, carrierInLayer: true },
464
491
  ];
465
492
 
493
+ /**
494
+ * The four root-level carriers, plus one more.
495
+ *
496
+ * A shared table rather than three copies of the same list: `_theme_of_dir`,
497
+ * `_posture_of_dir` and `_mode_of_dir` each walk it, and the order is observable (the first
498
+ * carrier that answers wins). `rules/geneseed.md` is spelled with `path.join` at each use.
499
+ *
500
+ * `.openclaude/CLAUDE.md` is half
501
+ * of the fix for host-compat verdict B1 (the other half is `carriersFor`, below).
502
+ * OpenClaude's own per-repo carrier is `carrierInLayer` (see `CLAUDE_SHAPED.openclaude` in
503
+ * `js/build/driver.mjs`, and the `HOSTS` column of the same name): it sits at
504
+ * `<repo>/.openclaude/CLAUDE.md`, and the root `CLAUDE.md` is deliberately left untouched so a
505
+ * Claude Code install can share the repo.
506
+ *
507
+ * ⚠ THIS LIST STAYS HOST-AGNOSTIC ON PURPOSE — it is only `firstCarrier`'s FALLBACK for a
508
+ * caller with no host to narrow by (none of this module's exported `*OfDir` readers is one;
509
+ * see `carriersFor`). A caller that DOES have a host must pass it, or in a repo sharing two
510
+ * carriers that answer the same probe — only root `CLAUDE.md` today, between `claude` and
511
+ * `openclaude`'s global scope — this host-agnostic order decides for both of them, which was
512
+ * exactly B1's failure mode reversed: reading `.openclaude/CLAUDE.md` unconditionally made
513
+ * `claude`'s OWN read-back answer OpenClaude's settings in a shared repo.
514
+ */
515
+ export const CARRIERS = [
516
+ 'AGENT.md', path.join('.openclaude', 'CLAUDE.md'), 'CLAUDE.md',
517
+ path.join('rules', 'geneseed.md'), 'AGENTS.md',
518
+ ];
519
+
520
+ /**
521
+ * `host`'s own carrier path(s), narrowed off the single `HOSTS` table — `carrierInLayer` and
522
+ * `projectMarker`/`agentFile` — rather than a second hand-rolled host→carrier map.
523
+ *
524
+ * ONE HOST, ONE ANSWER, EXCEPT BOB. `carrierInLayer` true (OpenClaude only) tries the nested
525
+ * per-repo path FIRST and the bare `agentFile` SECOND, because the same column name means two
526
+ * different locations depending on scope: `<repo>/.openclaude/CLAUDE.md` for a project
527
+ * install, `<cfgDir>/CLAUDE.md` for a global one (see `CLAUDE_SHAPED.openclaude-global`,
528
+ * which has no `carrierInLayer`). Bob is the one host with a second, differently-NAMED
529
+ * carrier — `rules/geneseed.md` at global scope, because Bob never auto-loads a global
530
+ * `AGENTS.md` (`CLAUDE_SHAPED['bob-global']`'s summary says so) — which `HOSTS` has no column
531
+ * for and this hard-codes, same as the un-narrowed `CARRIERS` above always did.
532
+ */
533
+ export function carriersFor(host) {
534
+ const row = HOSTS.find((h) => h.host === host);
535
+ if (!row) return CARRIERS;
536
+ if (host === 'bob') return [path.join('rules', 'geneseed.md'), row.agentFile];
537
+ return row.carrierInLayer
538
+ ? [path.join(row.projectMarker, row.agentFile), row.agentFile]
539
+ : [row.agentFile];
540
+ }
541
+
466
542
  /** Each Claude-family host's project marker, keyed by host — `globalHookStandingDown`'s table. */
467
543
  const STAND_DOWN_MARKERS = Object.fromEntries(HOSTS.filter((h) => h.family === 'claude')
468
544
  .map((h) => [h.host, h.projectMarker]));
@@ -478,7 +554,7 @@ export const CLAUDE_STYLE = HOSTS.filter((h) => h.family === 'claude').map((h) =
478
554
  * that catalogues natively gets AGENT.md's tables collapsed to a pointer and comparing the
479
555
  * portable shape against its bundle reports AGENT.md stale on every run forever. It is a
480
556
  * column and not a set literal so that the capability is declared in exactly one place
481
- * — the Python's own reason for the helper. The driver reads it through this function too.
557
+ * The driver reads it through this function too.
482
558
  *
483
559
  * Unknown host -> false, which is the shape that KEEPS the tables. The value arrives from a
484
560
  * user-editable `.geneseed-emit` marker, so an unrecognised one must degrade to the portable
@@ -497,17 +573,44 @@ export function hostCatalogsNatively(host) {
497
573
  return HOSTS.find((h) => h.host === host)?.catalog || false;
498
574
  }
499
575
 
500
- /** `_harness_learn.MEMORY_DIR_NAMES` — the neutral name and the imperial theme's. */
501
- const MEMORY_DIR_NAMES = ['memory', 'anamnesis'];
576
+ /** Did an emit make `base`? Every one leaves the version marker there and the index in `memory/`. */
577
+ function holdsInstall(base) {
578
+ if (!isFile(path.join(base, VERSION_MARKER)) || !isFile(path.join(base, 'memory', 'MEMORY.md'))) return false;
579
+ try { return !withDiscardableStderr(() => isHostGlobalDir(null, base)); } catch { return false; /* no home: cannot tell, so a destructive path fails closed */ }
580
+ }
581
+
582
+ /**
583
+ * The stores of the project install or bundle rooted at `root`, the marker's own first, so a repo
584
+ * that two hosts share answers with the host that emitted last. A Claude-family project keeps its
585
+ * data under its layer; OpenCode and the bundle at the root. A marker is only a claim: a stale or
586
+ * hand-written one over a repo's own folder must not make that folder deletable (I4).
587
+ */
588
+ function projectStores(root) {
589
+ const emit = emitMarkerOf(root);
590
+ if (emit !== 'files' && !HOSTS.some((h) => h.host === emit)) return [];
591
+ const layers = HOSTS.filter((h) => h.family === 'claude').map((h) => h.projectMarker);
592
+ const own = HOSTS.find((h) => h.host === emit && h.family === 'claude')?.projectMarker ?? '';
593
+ return [...new Set([own, ...layers, ''])].map((l) => path.join(root, l)).filter(holdsInstall)
594
+ .map((base) => path.join(base, 'memory'));
595
+ }
502
596
 
503
597
  /**
504
- * `_harness_learn._resolve_memory_dir` — where `learn` dedups and indexes, and what
598
+ * Where `learn` dedups and indexes, and what
505
599
  * `status` reports on its memory row.
506
600
  *
507
- * Precedence: `--memory` > `$GENESEED_MEMORY` > a `memory/` (or `anamnesis/`) beside cwd or
508
- * under `./Harness` > `$GENESEED_HARNESS/memory` > the OpenCode GLOBAL config dir's store.
509
- * The last two matter for the recommended opencode-global install, whose store lives in
510
- * `~/.config/opencode` rather than beside any repo. null => stdout-only.
601
+ * Precedence: `--memory` > `$GENESEED_MEMORY` > `$GENESEED_HARNESS/memory` > the store of a project
602
+ * install in the cwd or `./Harness` > the shared store (`<machine dir>/memory`) > the OpenCode
603
+ * GLOBAL config dir's store. Each counts only when it exists, so a machine without the shared
604
+ * tier falls through. null => stdout-only. The learn plugin knows its own install and ends in a
605
+ * bare `./memory`: it only ever writes. This resolver also serves `memory rm --purge`.
606
+ *
607
+ * A FOLDER NAMED `memory` IS NOT A STORE (I4). `memory rm --purge` deleted a repo's own
608
+ * `memory/design-notes.md` when the mere name was enough, so only an install makes the folder
609
+ * count (`projectStores`). Without one it is reached through `--memory`.
610
+ *
611
+ * ONLY `memory` NAMES A STORE. The imperial theme's `anamnesis` alias matched Terra's
612
+ * `Anamnesis/` vault by Windows case folding (B3) and `learn` wrote facts into it. The alias is
613
+ * read only where it is copied forward (`globalMemory`, `migrateStrayBundle`).
511
614
  *
512
615
  * HERE rather than in `js/hosts/hooks.mjs`, where it was written, because P5d gave it a second
513
616
  * caller that cannot import that file: `bin/geneseed-cli.mjs` is under a transitive
@@ -522,8 +625,7 @@ export function resolveMemoryDir(explicit) {
522
625
  }
523
626
  const env = process.env.GENESEED_MEMORY;
524
627
  if (env && isDir(env)) return toPlatformPath(env);
525
- const cwd = process.cwd();
526
- const bases = [cwd, path.join(cwd, 'Harness')];
628
+ const stores = [];
527
629
  const gh = process.env.GENESEED_HARNESS;
528
630
  if (gh) {
529
631
  // PER BASE, and the walk continues. `$GENESEED_HARNESS` is the FOURTH user-controlled
@@ -534,16 +636,13 @@ export function resolveMemoryDir(explicit) {
534
636
  // trace on a hook path and a non-zero exit, the exact failure the other three guards
535
637
  // exist to prevent. Skipping the base degrades to "no memory store from $GENESEED_HARNESS",
536
638
  // which is what an unset variable already does. `withDiscardableStderr` because the
537
- // refusal prints at the RAISE SITE and both callers byte-compare stderr; the reference
538
- // (`rituals/_harness_learn.py`, same guard) prints nothing here.
539
- try { bases.push(withDiscardableStderr(() => expanduser(gh))); } catch { /* skip it */ }
540
- }
541
- try { bases.push(opencodeConfigDir()); } catch { /* best-effort, as the Python */ }
542
- for (const base of bases) {
543
- for (const name of MEMORY_DIR_NAMES) {
544
- const cand = path.join(base, name);
545
- if (isDir(cand)) return cand;
546
- }
639
+ // refusal prints at the RAISE SITE and both callers byte-compare stderr, and nothing
640
+ // may print here.
641
+ try { stores.push(path.join(withDiscardableStderr(() => expanduser(gh)), 'memory')); } catch { /* skip it */ }
547
642
  }
548
- return null;
643
+ const cwd = process.cwd();
644
+ stores.push(...[cwd, path.join(cwd, 'Harness')].flatMap(projectStores));
645
+ try { stores.push(sharedPaths().memory); } catch { /* no home dir: no shared store */ }
646
+ try { stores.push(path.join(opencodeConfigDir(), 'memory')); } catch { /* best-effort */ }
647
+ return stores.find(isDir) ?? null;
549
648
  }