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
@@ -6,14 +6,16 @@
6
6
  */
7
7
  import path from 'node:path';
8
8
  import { spawnSync } from 'node:child_process';
9
- import { readText, printOut as out, printErr as err } from '../lib/fs.mjs';
9
+ import { readText, isDir, printOut as out, printErr as err } from '../lib/fs.mjs';
10
10
  import { toPlatformPath } from '../lib/paths.mjs';
11
11
  import { NO_WINDOW } from '../lib/proc.mjs';
12
12
  import {
13
- globalHookStandingDown, hookProjectDir, resolveMemoryDir, sovereignBypass,
13
+ globalHookStandingDown, hookProjectDir, isGlobalInstall, resolveMemoryDir, sovereignBypass,
14
14
  } from './hosts.mjs';
15
+ import { sharedPaths } from '../lib/machine-dir.mjs';
15
16
  import { readStdin, splitLines, splitWords, tailReader } from './hooks-prims.mjs';
16
17
  import { doneGate } from './hooks-done.mjs';
18
+ import { recordOwnWrites, storeReport } from './store-watch.mjs';
17
19
  import {
18
20
  existingSlugs, readFacts, writeMemories, consolidateMemory, appendAgentLesson,
19
21
  } from './memory-files.mjs';
@@ -217,8 +219,7 @@ export function buildLearnPrompt(notes, facts) {
217
219
  */
218
220
  function runLlm(llm, prompt) {
219
221
  const argv = splitWords(llm);
220
- // `_harness_learn.py:85` runs this through the wrapped `run(..., capture_output=True)`,
221
- // which folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
222
+ // `NO_WINDOW` folds in `CREATE_NO_WINDOW`; a model CLI invoked from the windowless daemon
222
223
  // otherwise pops a console for as long as it takes to answer.
223
224
  //
224
225
  // `GENESEED_LEARN_CHILD=1` (Claude B2): `$GENESEED_LLM="claude -p"` with hooks not disabled
@@ -276,13 +277,24 @@ function learnAgentLesson(meta, notes, args) {
276
277
  const lesson = splitLines(text)[0].replace(/^[-*]+/, '').trim();
277
278
  const n = Array.from(lesson).length; // code points, as `len()` counts them
278
279
  if (n >= 10 && n <= 300) {
279
- err(`[learn] agent lesson -> ${appendAgentLesson(memDir, agent, lesson)}\n`);
280
+ const written = recordOwnWrites(path.dirname(memDir), () => appendAgentLesson(memDir, agent, lesson));
281
+ err(written ? `[learn] agent lesson -> ${written}\n`
282
+ : `[learn] ${agent}'s lesson file is not UTF-8 - left as it is, lesson dropped\n`);
280
283
  }
281
284
  }
282
285
  if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
283
286
  return proc.returncode;
284
287
  }
285
288
 
289
+ /** `--memory` of a global install's hook, swapped for the shared store when that exists. */
290
+ function sharedStoreFor(install, args) {
291
+ if (!install) return args.memory;
292
+ try {
293
+ const shared = sharedPaths().memory;
294
+ return isDir(shared) && isGlobalInstall(args.host ?? null, install) ? shared : args.memory;
295
+ } catch { return args.memory; }
296
+ }
297
+
286
298
  export function cmdLearn(args) {
287
299
  // B2: stand straight down inside a model-CLI child `runLlm` just spawned (see its comment).
288
300
  // Checked before anything else — a child never gets as far as reading its own stdin, let
@@ -295,7 +307,7 @@ export function cmdLearn(args) {
295
307
  err('[learn] no memory store found \u2014 nothing to consolidate.\n');
296
308
  return 0;
297
309
  }
298
- const report = consolidateMemory(memDir);
310
+ const report = recordOwnWrites(path.dirname(memDir), () => consolidateMemory(memDir));
299
311
  err(`[learn] consolidated ${memDir}: +${report.added.length} indexed, `
300
312
  + `-${report.pruned.length} pruned, `
301
313
  + `${report.duplicates.length} duplicate description(s)\n`);
@@ -321,6 +333,14 @@ export function cmdLearn(args) {
321
333
  const hookEvent = typeof meta.hook_event_name === 'string' ? meta.hook_event_name
322
334
  : (typeof meta.event === 'string' ? meta.event : null);
323
335
 
336
+ // A global install's hook passes its own host store; the shared store is where its facts live
337
+ // once it exists, or they land in the seeded host store and wait for the next fold. Only a hook
338
+ // call is redirected: it names its event or carries a transcript, and a person who typed
339
+ // `--memory` meant that store. Empty stdin is neither, and has no notes to write anywhere.
340
+ if (hookEvent || typeof meta.transcript_path === 'string') {
341
+ args = { ...args, memory: sharedStoreFor(install, args) };
342
+ }
343
+
324
344
  // The done gate (#289) judges the turn BEFORE anything here spawns, and only on Stop. A block
325
345
  // means the turn goes on, so there is nothing to distil yet: the next Stop will.
326
346
  // `--no-done-gate` (the install switched Law III's gate off) skips the check, never the
@@ -332,6 +352,17 @@ export function cmdLearn(args) {
332
352
  ? doneGate(meta, args, install, read) : null;
333
353
  if (verdict === 'block') return 0;
334
354
 
355
+ // The change report, at the turn's real end (./store-watch.mjs). One JSON document on stdout, so an
356
+ // advisory already there keeps it, and Bob reads no stdout here at all: those go to stderr.
357
+ if (hookEvent === 'Stop' && !args.file && install) {
358
+ const said = storeReport(install, meta.session_id, {
359
+ transcript: typeof meta.transcript_path === 'string' ? meta.transcript_path : null,
360
+ cwd: meta.cwd, host: args.host || 'claude',
361
+ });
362
+ if (said && (verdict === 'advisory' || args.host === 'bob')) err(`[geneseed] ${said}\n`);
363
+ else if (said) out(`${JSON.stringify({ systemMessage: said })}\n`);
364
+ }
365
+
335
366
  // I2 (Bob): its Stop payload never carries `transcript_path`, so there is never a transcript
336
367
  // to distil — and the bare envelope itself is not notes text (that would waste a model call
337
368
  // on `{"event":"Stop","session_id":"s"}`). Scoped to `--host bob`: every other host's Stop/
@@ -384,7 +415,7 @@ export function cmdLearn(args) {
384
415
  const proc = runLlm(llm, prompt);
385
416
  const output = proc.stdout;
386
417
  if (memDir && output.trim() && output.trim().toUpperCase() !== 'NOTHING') {
387
- const { created, updated, archived } = writeMemories(output, memDir, existing);
418
+ const { created, updated, archived } = recordOwnWrites(path.dirname(memDir), () => writeMemories(output, memDir, existing));
388
419
  if (created.length) {
389
420
  err(`[learn] wrote ${created.length} memory file(s) to `
390
421
  + `${memDir}: ${created.join(', ')}\n`);
@@ -70,15 +70,17 @@ export function selfAndParents(p) {
70
70
  * the other. The trailing empty is dropped the way Python drops it (`"a\n"` is one line,
71
71
  * `""` is none).
72
72
  */
73
+ export const LINE_BREAK = /\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/;
74
+
73
75
  export function splitLines(text) {
74
76
  if (!text) return [];
75
- const parts = text.split(/\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/);
77
+ const parts = text.split(LINE_BREAK);
76
78
  if (parts.length && parts[parts.length - 1] === '') parts.pop();
77
79
  return parts;
78
80
  }
79
81
 
80
82
  /** The first window a Stop reads from a transcript's end; real transcripts reach 50 MB. */
81
- export const TAIL_BYTES = 2 * 1024 * 1024;
83
+ const TAIL_BYTES = 2 * 1024 * 1024;
82
84
 
83
85
  /**
84
86
  * A transcript reader for ONE hook invocation: `read(file, judge)` hands `judge(text, whole)`
@@ -23,14 +23,11 @@
23
23
  * this driver emits has no Python in its hook path at all — which is what let the interpreter
24
24
  * discovery and its exit-4 refusal be deleted rather than merely bypassed.
25
25
  *
26
- * Ported from `rituals/_harness_context.py` and `rituals/_harness_learn.py`, whose shared
27
- * primitives live in `_harness_core.py`. `rituals/harness.py` links all fourteen
28
- * submodules into one namespace at import time, so a Python `harness context` loads
29
- * ~11,600 lines and the generator behind them. This module loads none of that, and that is
30
- * deliberate rather than incidental: the Python originals already refuse to import `build`
31
- * for the marker filenames they need ("literals keep the hook dependency-free"), and
26
+ * This module loads none of the generator behind `build`, and that is deliberate rather
27
+ * than incidental: it takes the marker filenames it needs as literals to stay
28
+ * dependency-free, and
32
29
  * `bin/build-driver.mjs` could not be imported anyway, since its last statement runs the
33
- * generator. What that rule does NOT license is a second copy of a shared resolver under a
30
+ * generator. What that does NOT license is a second copy of a shared resolver under a
34
31
  * different name — see `./hooks-prims.mjs`, where P5d found one that had silently diverged
35
32
  * from its twin.
36
33
  *
@@ -54,10 +51,11 @@
54
51
  * and every file left behind. Absolute rather than compared is what let it survive the deletion
55
52
  * of the implementation it was once compared against.
56
53
  */
57
- import { readFileSync, appendFileSync, writeFileSync } from 'node:fs';
54
+ import { readFileSync, readlinkSync, appendFileSync, writeFileSync } from 'node:fs';
58
55
  import path from 'node:path';
59
56
  import { printOut as out, printErr as err, withDiscardableStderr } from '../lib/fs.mjs';
60
57
  import { normcase } from '../lib/paths.mjs';
58
+ import { sharedPaths, machineDir } from '../lib/machine-dir.mjs';
61
59
  import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
62
60
  import {
63
61
  GATE_LEDGER, globalHookStandingDown, hookProjectDir, resolvePath, sovereignBypass,
@@ -204,7 +202,7 @@ const asciiJson = (s) => JSON.stringify(s)
204
202
  * `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
205
203
  * `additionalContext`; not seen live, no gate here runs a model turn).
206
204
  */
207
- export function contextNote(text) {
205
+ function contextNote(text) {
208
206
  return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": ${asciiJson(text)}}}\n`;
209
207
  }
210
208
 
@@ -212,7 +210,6 @@ export function contextNote(text) {
212
210
  * The host reading this process's verdict — `--host` on the emitted command, `claude` when
213
211
  * absent. Module state rather than a parameter because a hook process answers exactly one
214
212
  * call: set once at the gate's entry (`guardGate`), read where the output dialect is chosen.
215
- * `./hooks-context.mjs` keeps its own for the same reason.
216
213
  */
217
214
  let HOST = 'claude';
218
215
  const setHost = (args) => { HOST = (args && args.host) || 'claude'; };
@@ -243,14 +240,15 @@ const confirmTail = () => (HOST === 'bob' ? 'Leave the data in place.'
243
240
  * credential in a tracked file and a history-discarding git act are wrong in every context,
244
241
  * so refusing them costs nothing. rigor-5 (External Gate) joins them: a protected check the
245
242
  * agent can edit is not a check, so it is as unconditional as the two Laws — NOT "Laws I/IV
246
- * only", see bob-code.md B3. Process 1 and process 5 are the USER's calls — a hard
247
- * block would make Bob unable to commit at all — so they become a warning the host
248
- * logs. ops-2 (Commands Must Return, the root-scan check) is a block too: a warning would let a
243
+ * only", see bob-code.md B3. process-1 too (owner decision, 2026-11): with no prompt, a warning
244
+ * let the agent write the user's rules and memory on its own say. Process 5 is the USER's call
245
+ * as well, but a hard block would make Bob unable to commit at all, so it stays a warning the
246
+ * host logs. ops-2 (Commands Must Return, the root-scan check) is a block too: a warning would let a
249
247
  * scan of every drive run for hours, and the agent loses nothing by re-targeting a directory.
250
248
  * `gate-error` is a warning too: a crashed gate that blocked every tool call would be
251
249
  * a lockout, not a safeguard, and there is no prompt through which the user could clear it.
252
250
  */
253
- const BLOCK_RULES = new Set(['law-1', 'law-4', 'rigor-5', 'ops-2']);
251
+ const BLOCK_RULES = new Set(['law-1', 'law-4', 'rigor-5', 'ops-2', 'process-1']);
254
252
 
255
253
  /**
256
254
  * THE GATE LEDGER — one JSON line per ask, nothing per defer.
@@ -613,6 +611,27 @@ function shellWriteReason(args, command, payload) {
613
611
  return null;
614
612
  }
615
613
 
614
+ /**
615
+ * A parsed shell write that lands in a rule or memory store: the reason, or null. Asked on Claude
616
+ * and OpenClaude, and only a warning on Bob, whose one verdict is a hard block: shell is no boundary,
617
+ * and command text is no ground to refuse on. Fails open, like `shellWriteReason`.
618
+ */
619
+ function shellStoreReason(args, command, payload) {
620
+ try {
621
+ const base = (payload && typeof payload.cwd === 'string' && payload.cwd) || process.cwd();
622
+ const own = payload && payload.tool_input && payload.tool_input.cwd;
623
+ const cwd = typeof own === 'string' && own ? path.resolve(base, own) : base;
624
+ for (const t of shellWriteTargets(command, cwd)) {
625
+ const store = ruleGateTarget(t, args.root, cwd);
626
+ if (store) {
627
+ return `Geneseed (Persist Insight) \u2014 writing to ${store} through a shell command: a standing `
628
+ + 'rule, or a fact to remember? That choice is the user\'s.';
629
+ }
630
+ }
631
+ } catch { /* see above */ }
632
+ return null;
633
+ }
634
+
616
635
  function gitDecide(args, payload) {
617
636
  const command = ((payload && payload.tool_input) || {}).command;
618
637
  if (typeof command !== 'string') return 0;
@@ -650,6 +669,9 @@ function gitDecide(args, payload) {
650
669
  // target cannot be replayed from a command (`bobSettingsChange`), so it blocks.
651
670
  const shellWrite = shellWriteReason(args, command, payload);
652
671
  if (shellWrite) return ask(args, 'git-gate', 'rigor-5', shellWrite);
672
+ const shellStore = shellStoreReason(args, command, payload);
673
+ if (shellStore && HOST !== 'bob') return ask(args, 'git-gate', 'process-1', shellStore);
674
+ if (shellStore) err(`[geneseed] ${shellStore}\n`);
653
675
  // `--no-consent`: the process pack (or process 5 alone) is off, so the commit/push ask has
654
676
  // no rule behind it — but Law IV above is universal and has already run. Checked before
655
677
  // `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
@@ -670,32 +692,76 @@ export const cmdGitGate = guardGate(gitGate, 'git-gate');
670
692
  * `_rule_gate_target` — name the store a write would land in, or null for ordinary work.
671
693
  *
672
694
  * A deployed install's folder and file names are theme-INDEPENDENT by design, so this
673
- * matches literal names and needs no install lookup. `user-rules.md` and `MEMORY.md` are
674
- * Geneseed's own coinage and match anywhere; any other markdown matches only inside THIS
675
- * install's `<root>/memory/`.
695
+ * matches literal names and needs no install lookup. `user-rules.md`, `user-rules.draft.md` and
696
+ * `MEMORY.md` are Geneseed's own coinage and match anywhere; any other markdown matches only
697
+ * inside THIS install's `<root>/memory/` or the machine tier's `memory/`, or the store
698
+ * `$GENESEED_HARNESS` or `$GENESEED_MEMORY` names. Twin of the OpenCode guard's `ruleStoreTarget`.
699
+ *
700
+ * The test is on what the write LANDS on: as spelled, `..` and `//` folded, and with links followed,
701
+ * since a link from outside into a store and a store that links out are both real. On Windows a
702
+ * stream (`user-rules.md::$DATA`), trailing dots and spaces, a device path and this machine's admin
703
+ * share name the same file. A coined name matches by exact case outside a store: `docs/concepts/memory.md`
704
+ * is another file, on Windows too, and on Bob this is a hard block. A file that EXISTS under a coined
705
+ * name comes back in its true case through the link-followed form; a differently cased spelling
706
+ * of one that does not exist yet is not caught. `base` is the session's directory.
676
707
  */
677
- // The close of the process-1 text, word for word the OpenCode guard's PERSIST_ASK (tests pin
678
- // both). A weak model once took a refusal as leave to write the same file through a shell
679
- // command, so the text names the one way forward and never a switch that turns the gate off.
708
+ // The close of the process-1 text. On Claude this is a real prompt the host shows; the OpenCode
709
+ // guard has its own texts, because a re-issue releases nothing there. A weak model once took a
710
+ // refusal as leave to write the same file through a shell command, so the text names the one way
711
+ // forward and never a switch that turns the gate off.
680
712
  export const PERSIST_ASK = 'Stop and ask the user now (the rule skill). If this edit was refused, '
681
713
  + 're-issue the same edit only after they answer; never write it another way (for example '
682
714
  + 'through a shell command).';
715
+ /** Bob's close instead: nothing there lifts the block, so nothing here may speak of re-issuing. */
716
+ const PERSIST_BOB = 'Tell the user what you wanted to write (the rule skill).';
683
717
 
684
- function ruleGateTarget(p, root) {
718
+ function ruleGateTarget(p, root, base = null) {
685
719
  if (typeof p !== 'string') return null;
720
+ const win = process.platform === 'win32';
686
721
  // Split on BOTH separators rather than taking a basename: a payload carrying a Windows
687
722
  // path reaches a POSIX host with its backslashes intact, and `path.basename` there
688
- // returns the whole string — so the two coined names would go unrecognised exactly
723
+ // returns the whole string — so the coined names would go unrecognised exactly
689
724
  // where they are meant to match on whichever host reads them.
690
- const name = p.split(/[\\/]/).pop().toLowerCase();
691
- if (name === 'user-rules.md') return 'user-rules.md';
692
- if (name === 'memory.md') return 'the memory index';
693
- if (!root || !name.endsWith('.md')) return null;
725
+ const coined = (f) => {
726
+ const name = f.split(/[\\/]/).pop();
727
+ if (name === 'user-rules.md') return 'user-rules.md';
728
+ if (name === 'MEMORY.md') return 'the memory index';
729
+ if (name === 'user-rules.draft.md') return 'the rule draft';
730
+ return null;
731
+ };
732
+ const named = coined(p);
733
+ if (named) return named;
694
734
  try {
695
- const store = normcase(resolvePath(path.join(root, 'memory')));
696
- // `.parents`, so the store dir itself is not one of its own ancestors.
697
- return selfAndParents(resolvePath(p)).slice(1).some((d) => normcase(d) === store)
698
- ? 'memory' : null;
735
+ const forms = [];
736
+ if (p.startsWith('~')) forms.push(resolvePath(p));
737
+ else {
738
+ const spelled = !win ? p : p.replace(/^\/([a-zA-Z])(?=\/|$)/, '$1:').replace(/^[\\/]{2}[?.][\\/](?=[a-zA-Z]:)/, '')
739
+ .replace(/^[\\/]{2}(?:localhost|127\.0\.0\.1|\[?::1\]?)[\\/]([a-zA-Z])\$(?=[\\/]|$)/i, '$1:');
740
+ let abs = path.resolve(base || process.cwd(), spelled);
741
+ if (win) {
742
+ const drive = /^[a-zA-Z]:|^\\\\[^\\]+\\[^\\]+/.exec(abs)?.[0] ?? '';
743
+ abs = drive + abs.slice(drive.length).split('\\').map((s) => s.replace(/:.*$/, '').replace(/[. ]+$/, '')).join('\\');
744
+ }
745
+ forms.push(abs, resolvePath(abs));
746
+ // A dangling link has no realpath, and a write through it creates its target: follow it by
747
+ // hand, each hop through `resolvePath`, because a hop may pass a folder link. Links can loop.
748
+ for (let cur = forms[1], hop = 0; hop < 8; hop += 1) {
749
+ try { cur = resolvePath(path.resolve(path.dirname(cur), readlinkSync(cur))); forms.push(cur); } catch { break; }
750
+ }
751
+ }
752
+ const hit = forms.map(coined).find(Boolean);
753
+ if (hit) return hit;
754
+ // This install's store, the machine tier's (`~/.config/geneseed/memory`) and the two a variable
755
+ // points at: a path compare, each store as written and with its links followed.
756
+ const stores = [];
757
+ if (root) stores.push(path.join(root, 'memory'));
758
+ try { stores.push(sharedPaths().memory); } catch { /* no home dir: no shared store to match */ }
759
+ if (process.env.GENESEED_HARNESS) stores.push(path.join(process.env.GENESEED_HARNESS, 'memory'));
760
+ if (process.env.GENESEED_MEMORY) stores.push(process.env.GENESEED_MEMORY);
761
+ const homes = stores.flatMap((s) => [path.resolve(s), resolvePath(s)]).map(normcase);
762
+ // `.slice(1)`, so the store dir itself is not one of its own ancestors.
763
+ return forms.some((f) => (win ? f.toLowerCase() : f).endsWith('.md')
764
+ && selfAndParents(f).slice(1).some((a) => homes.includes(normcase(a)))) ? 'memory' : null;
699
765
  } catch {
700
766
  return null;
701
767
  }
@@ -779,7 +845,8 @@ function gateConfig(p, root) {
779
845
  if (bin && t.startsWith(bin + path.sep)) return true;
780
846
  if (/^opencode\.jsonc?$/.test(path.basename(t))) return true;
781
847
  const up = [path.dirname(target), path.dirname(path.dirname(target))];
782
- const homes = [...roots, ...up.filter((d) => GATE_CONFIG_MARKERS.some((m) => normcase(m) === normcase(path.basename(d))))];
848
+ // The machine tier is a home too, so the shared `excludes.json` is gated like a host's (a home, not a `.claude`-style marker).
849
+ const homes = [...roots, machineDir(), ...up.filter((d) => GATE_CONFIG_MARKERS.some((m) => normcase(m) === normcase(path.basename(d))))];
783
850
  if (homes.some((h) => GATE_CONFIG_FILES.some((f) => normcase(path.join(h, f)) === t))) return true;
784
851
  }
785
852
  } catch { /* an unresolvable path is no hit, like `protectedIn` */ }
@@ -918,11 +985,15 @@ function diffReplaced(diff) {
918
985
  return halves.length ? halves.join('\n') : diff;
919
986
  }
920
987
 
988
+ const RULE_PATH_KEYS = ['file_path', 'path', 'notebook_path', 'target_file', 'target', 'file', 'filename', 'destination', 'dest',
989
+ 'new_path', 'new_name', 'old_path', 'source', 'from', 'to'];
921
990
  function ruleDecide(args, payload) {
922
991
  const ti = (payload && payload.tool_input) || {};
923
- // NotebookEdit names its target `notebook_path`; the settings matcher routes it here too.
924
- const p = ti.file_path || ti.path || ti.notebook_path || '';
925
- if (typeof p !== 'string' || !p) return 0;
992
+ // NotebookEdit names its target `notebook_path`; the settings matcher routes it here too. Every
993
+ // key is read, never the first found: Bob's move and rename tools carry two, and a harmless
994
+ // `path` beside the real target must not hide it from any gate below.
995
+ const paths = [...new Set(RULE_PATH_KEYS.map((k) => ti[k]).filter((v) => typeof v === 'string' && v))];
996
+ if (!paths.length) return 0;
926
997
  // Write carries `content`, Edit `new_string`, NotebookEdit `new_source`, MultiEdit an
927
998
  // `edits[]` of `new_string`s — every one can plant a credential, so every one is scanned.
928
999
  // MultiEdit is no longer in Claude Code's own tool table (tools-reference.md) or the
@@ -938,8 +1009,9 @@ function ruleDecide(args, payload) {
938
1009
  .filter((v) => typeof v === 'string').join('\n');
939
1010
  // `--no-secrets-gate`: the install switched Law I's scan off (user decision 2026-10-18). Only
940
1011
  // this check stands down; the protected checks and process 1 below still run.
941
- if (!args.noSecretsGate && body && !DOTENV_RE.test(p) && SECRET_RE.test(body)) {
942
- return ask(args, 'rule-gate', 'law-1', `Geneseed (Sealed Secrets) — ${p} would carry a `
1012
+ const carrier = paths.find((p) => !DOTENV_RE.test(p));
1013
+ if (!args.noSecretsGate && body && carrier && SECRET_RE.test(body)) {
1014
+ return ask(args, 'rule-gate', 'law-1', `Geneseed (Sealed Secrets) — ${carrier} would carry a `
943
1015
  + 'credential-shaped string. Secrets live in .env or a secret manager, never in a '
944
1016
  + 'tracked file.');
945
1017
  }
@@ -947,9 +1019,11 @@ function ruleDecide(args, payload) {
947
1019
  // shortcut: a write is told by its tool name, so a Bob write tool named outside WRITE_NAME_RE
948
1020
  // passes both gates; switch to an allowlist of Bob's read tools if Bob adds or renames one.
949
1021
  const bobRead = HOST === 'bob' && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
950
- const external = !bobRead && externalGate(args, p, payload);
1022
+ const external = !bobRead && paths.map((p) => externalGate(args, p, payload)).find(Boolean);
951
1023
  if (external) return ask(args, 'rule-gate', 'rigor-5', external);
952
- const target = ruleGateTarget(p, args.root);
1024
+ // A read on Bob names the store too, and that is no write to refuse.
1025
+ const target = bobRead ? null : paths.map((p) => ruleGateTarget(p, args.root, payload && payload.cwd)).find(Boolean);
1026
+ const p = paths[0];
953
1027
  if (!target) {
954
1028
  // The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
955
1029
  // `--no-ownership-gate`: the install switched it off (D25).
@@ -960,7 +1034,8 @@ function ruleDecide(args, payload) {
960
1034
  return 0;
961
1035
  }
962
1036
  return ask(args, 'rule-gate', 'process-1', `Geneseed (Persist Insight) \u2014 writing to `
963
- + `${target}: a standing rule, or a fact to remember? That choice is the user's. ${PERSIST_ASK}`);
1037
+ + `${target}: a standing rule, or a fact to remember? That choice is the user's. `
1038
+ + (HOST === 'bob' ? PERSIST_BOB : PERSIST_ASK));
964
1039
  }
965
1040
  export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
966
1041