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
@@ -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,17 +51,20 @@
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,
64
62
  } from './hosts.mjs';
65
63
  import { currentBranch, gitRootOf, loopLaunched } from './gitref.mjs';
66
64
  import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
67
- import { selfAndParents, readStdin, SECRET_RE, DONE_LIST } from './hooks-prims.mjs';
65
+ import {
66
+ selfAndParents, readStdin, SECRET_RE, DONE_LIST, DIFF_BLOCK_RE, isTestPath, weakenedBy, editPairs,
67
+ } from './hooks-prims.mjs';
68
68
  import { recordUse } from './usage.mjs';
69
69
  import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
70
70
 
@@ -190,17 +190,26 @@ export function askDecision(reason) { return decisionDoc('ask', reason); }
190
190
  export function denyDecision(reason) { return decisionDoc('deny', reason); }
191
191
 
192
192
  function decisionDoc(decision, reason) {
193
- const value = JSON.stringify(reason)
194
- .replace(/[\u007f-￿]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
195
193
  return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "${decision}", `
196
- + `"permissionDecisionReason": ${value}}}\n`;
194
+ + `"permissionDecisionReason": ${asciiJson(reason)}}}\n`;
195
+ }
196
+
197
+ const asciiJson = (s) => JSON.stringify(s)
198
+ .replace(/[\u007f-￿]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
199
+
200
+ /**
201
+ * A note to the MODEL that decides nothing: PreToolUse `additionalContext` with no
202
+ * `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
203
+ * `additionalContext`; not seen live, no gate here runs a model turn).
204
+ */
205
+ function contextNote(text) {
206
+ return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": ${asciiJson(text)}}}\n`;
197
207
  }
198
208
 
199
209
  /**
200
210
  * The host reading this process's verdict — `--host` on the emitted command, `claude` when
201
211
  * absent. Module state rather than a parameter because a hook process answers exactly one
202
212
  * call: set once at the gate's entry (`guardGate`), read where the output dialect is chosen.
203
- * `./hooks-context.mjs` keeps its own for the same reason.
204
213
  */
205
214
  let HOST = 'claude';
206
215
  const setHost = (args) => { HOST = (args && args.host) || 'claude'; };
@@ -231,14 +240,15 @@ const confirmTail = () => (HOST === 'bob' ? 'Leave the data in place.'
231
240
  * credential in a tracked file and a history-discarding git act are wrong in every context,
232
241
  * so refusing them costs nothing. rigor-5 (External Gate) joins them: a protected check the
233
242
  * agent can edit is not a check, so it is as unconditional as the two Laws — NOT "Laws I/IV
234
- * only", see bob-code.md B3. Process 1 and process 5 are the USER's calls — a hard
235
- * block would make Bob unable to commit at all — so they become a warning the host
236
- * 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
237
247
  * scan of every drive run for hours, and the agent loses nothing by re-targeting a directory.
238
248
  * `gate-error` is a warning too: a crashed gate that blocked every tool call would be
239
249
  * a lockout, not a safeguard, and there is no prompt through which the user could clear it.
240
250
  */
241
- 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']);
242
252
 
243
253
  /**
244
254
  * THE GATE LEDGER — one JSON line per ask, nothing per defer.
@@ -488,6 +498,140 @@ const lossSegments = (s) => scanSegments(s).map((seg) => seg.match(SCAN_TOKEN_RE
488
498
  // (`rg "/mnt/c" README.md`) — never a root target; only an unquoted root is one.
489
499
  const rootArg = (t) => !/^["']/.test(t) && FS_ROOT_RE.test(t);
490
500
 
501
+ // ---- shell-write twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js carries everything down
502
+ // to the END marker verbatim, with `export ` dropped (tests/plugins/guard.test.mjs diffs the two).
503
+
504
+ // The cheap prefilter, a superset of what the parse acts on: a `>`, or one of the programs as a word.
505
+ const SHELL_WRITE_RE = />|(?:^|[\s;&|("'`\\/])(?:tee|sed|cp|mv|rm)(?:\.exe)?(?=[\s;&|)"'`]|$)/im;
506
+ // One pass over a segment: a quoted run (kept: its `>` is data), or a redirection with its optional
507
+ // fd, operator, `&` (a dup such as `2>&1`, which writes no file) and target word. `<` forms match
508
+ // too, so that their words never read as operands. A backslash is no escape here, as in
509
+ // `SCAN_SPLIT_RE`: `echo "say \"hi > f\""` closes its quote early, reads a target, and asks (on Bob, blocks).
510
+ const REDIRECT_RE = /"[^"]*"?|'[^']*'?|(?:(?<!\S)\d+|&)?(<<?<?-?|>>?)[ \t]*(&?)((?:[^\s"';|&<>()]|"[^"]*"?|'[^']*'?)*)/g;
511
+ const SHELL_CD = new Set(['cd', 'pushd', 'chdir', 'set-location', 'sl']);
512
+
513
+ /** `t` as an absolute path from `dir`, `~/…` as it stands, or null for what the shell rewrites. */
514
+ function writePath(dir, t) {
515
+ if (/[$`*?{}\0]/.test(t) || /^~[^\\/]/.test(t) || /^(?:\/dev\/|nul$)/i.test(t)) return null;
516
+ if (t[0] === '~') return t;
517
+ // A Git Bash `/c/…` path, as `resolveIn` reads it.
518
+ const q = process.platform === 'win32' ? t.replace(/^\/([a-zA-Z])(?=\/|$)/, '$1:') : t;
519
+ if (path.isAbsolute(q)) return path.resolve(q);
520
+ return dir ? path.resolve(dir, q) : null;
521
+ }
522
+
523
+ /** The files `sed` edits in place: none without `-i`; else its operands, past the script if inline. */
524
+ function sedFiles(args) {
525
+ const ops = [];
526
+ let inPlace = false; let script = false; let flags = true;
527
+ for (let i = 0; i < args.length; i += 1) {
528
+ const a = args[i];
529
+ if (flags && a === '--') flags = false;
530
+ else if (flags && /^--in-place(?:=|$)/.test(a)) inPlace = true;
531
+ else if (flags && (a === '--expression' || a === '--file')) { script = true; i += 1; }
532
+ else if (flags && /^--(?:expression|file)=/.test(a)) script = true;
533
+ else if (flags && /^-[a-zA-Z]*i/.test(a)) inPlace = true;
534
+ else if (flags && /^-[a-zA-Z]*[ef]$/.test(a)) { script = true; i += 1; }
535
+ else if (!flags || !a.startsWith('-') || a === '-') { if (a) ops.push(a); }
536
+ }
537
+ return inPlace ? ops.slice(script ? 0 : 1) : [];
538
+ }
539
+
540
+ /**
541
+ * The files `command` would write, as absolute paths: redirect targets (`>`, `>>`, `&>`), `tee`
542
+ * and `rm` operands, `sed -i` files, the destination of `cp` and `mv`, and the sources of `mv`, which
543
+ * it removes. A destination may be a folder, so `cp a tests/` also names `tests/a`. Read like
544
+ * `rootScan`: quotes, comments and heredoc bodies are data. A `cd` is followed; one it cannot read
545
+ * leaves later relative paths unseen. What it cannot read, it leaves out: this reader fails OPEN.
546
+ *
547
+ * shortcut: KNOWN UNSEEN FORMS, all of them still a write. An interpreter (inline code,
548
+ * `bash -c`, `eval`, `xargs`), a script or `npm run`, a `$(…)` or subshell trick, `>|`, a path with a
549
+ * variable, glob or brace in it, a wrapper with flags (`sudo -u x`) or outside `SCAN_WRAPPERS` (`env rm`,
550
+ * `nohup rm`, `timeout 5 rm`, `exec rm`), `echo x >& file` (read as a dup), a `popd` (not followed, so
551
+ * relative paths after a `pushd`/`popd` pair resolve from the wrong folder), `cp -t`, any other writer
552
+ * (`dd`, `ln`, `install`, `git mv`, `git checkout`, `Set-Content`), and a folder removed above a
553
+ * listed file (`rm -r tests` when only `tests/a.test.js` is listed). CI running the checks is the
554
+ * boundary that holds against those.
555
+ */
556
+ export function shellWriteTargets(command, cwd) {
557
+ if (!SHELL_WRITE_RE.test(command)) return [];
558
+ const found = new Set();
559
+ let dir = cwd;
560
+ const add = (t) => { const p = writePath(dir, t); if (p) found.add(p); };
561
+ const bare = (t) => t.replace(/["']/g, '');
562
+ for (const seg of scanSegments(command)) {
563
+ const outs = [];
564
+ const body = seg.replace(REDIRECT_RE, (m, op, dup, target) => {
565
+ if (op === undefined) return m;
566
+ if (op[0] === '>' && !dup && target) outs.push(bare(target));
567
+ return ' ';
568
+ });
569
+ let toks = stripStructure(body.match(SCAN_TOKEN_RE) || []);
570
+ while (toks.length && (/^\w+=/.test(toks[0]) || SCAN_WRAPPERS.has(bare(toks[0])))) toks = toks.slice(1);
571
+ const prog = toks.length ? bare(toks[0]).split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '') : '';
572
+ const args = toks.slice(1).map(bare);
573
+ const dashes = args.indexOf('--');
574
+ const ops = args.filter((a, i) => a && (a === '-' || !a.startsWith('-') || (dashes >= 0 && i > dashes)));
575
+ if (SHELL_CD.has(prog)) {
576
+ const to = ops.find((a) => !/^\/d$/i.test(a));
577
+ dir = to && to !== '-' ? writePath(dir, to) : null;
578
+ } else if (prog === 'rm' || prog === 'tee') ops.forEach(add);
579
+ else if (prog === 'sed') sedFiles(args).forEach(add);
580
+ else if ((prog === 'cp' || prog === 'mv') && ops.length > 1) {
581
+ const dest = ops[ops.length - 1];
582
+ const sources = ops.slice(0, -1);
583
+ add(dest);
584
+ for (const s of sources) {
585
+ add(`${dest.replace(/[\\/]+$/, '')}/${s.split(/[\\/]/).pop()}`);
586
+ if (prog === 'mv') add(s);
587
+ }
588
+ }
589
+ outs.forEach(add);
590
+ }
591
+ return [...found];
592
+ }
593
+ // ---- shell-write twin: END
594
+
595
+ /**
596
+ * External Gate over a shell command: the first write target that `externalGate` refuses, as the
597
+ * reason to ask, or null. Path check only, no secret scan of the command. Any throw is a pass, not
598
+ * `guardGate`'s `gate-error` ask: this reader fails open, and a hand-mangled path is not a gate failure.
599
+ */
600
+ function shellWriteReason(args, command, payload) {
601
+ try {
602
+ const base = (payload && typeof payload.cwd === 'string' && payload.cwd) || process.cwd();
603
+ // A Roo-lineage shell tool may name its own directory, as OpenCode's `workdir` does.
604
+ const own = payload && payload.tool_input && payload.tool_input.cwd;
605
+ const cwd = typeof own === 'string' && own ? path.resolve(base, own) : base;
606
+ for (const t of shellWriteTargets(command, cwd)) {
607
+ const why = externalGate(args, t, payload);
608
+ if (why) return why;
609
+ }
610
+ } catch { /* see above */ }
611
+ return null;
612
+ }
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
+
491
635
  function gitDecide(args, payload) {
492
636
  const command = ((payload && payload.tool_input) || {}).command;
493
637
  if (typeof command !== 'string') return 0;
@@ -521,6 +665,13 @@ function gitDecide(args, payload) {
521
665
  + 'share, for hours; | head stops nothing). Search a specific directory instead: the '
522
666
  + 'project, node_modules, ~/.npm, %APPDATA%.');
523
667
  }
668
+ // Also before `--no-consent`: rigor-5 is no part of the process pack. On Bob a hook-settings
669
+ // target cannot be replayed from a command (`bobSettingsChange`), so it blocks.
670
+ const shellWrite = shellWriteReason(args, command, payload);
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`);
524
675
  // `--no-consent`: the process pack (or process 5 alone) is off, so the commit/push ask has
525
676
  // no rule behind it — but Law IV above is universal and has already run. Checked before
526
677
  // `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
@@ -541,32 +692,76 @@ export const cmdGitGate = guardGate(gitGate, 'git-gate');
541
692
  * `_rule_gate_target` — name the store a write would land in, or null for ordinary work.
542
693
  *
543
694
  * A deployed install's folder and file names are theme-INDEPENDENT by design, so this
544
- * matches literal names and needs no install lookup. `user-rules.md` and `MEMORY.md` are
545
- * Geneseed's own coinage and match anywhere; any other markdown matches only inside THIS
546
- * 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.
547
707
  */
548
- // The close of the process-1 text, word for word the OpenCode guard's PERSIST_ASK (tests pin
549
- // both). A weak model once took a refusal as leave to write the same file through a shell
550
- // 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.
551
712
  export const PERSIST_ASK = 'Stop and ask the user now (the rule skill). If this edit was refused, '
552
713
  + 're-issue the same edit only after they answer; never write it another way (for example '
553
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).';
554
717
 
555
- function ruleGateTarget(p, root) {
718
+ function ruleGateTarget(p, root, base = null) {
556
719
  if (typeof p !== 'string') return null;
720
+ const win = process.platform === 'win32';
557
721
  // Split on BOTH separators rather than taking a basename: a payload carrying a Windows
558
722
  // path reaches a POSIX host with its backslashes intact, and `path.basename` there
559
- // 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
560
724
  // where they are meant to match on whichever host reads them.
561
- const name = p.split(/[\\/]/).pop().toLowerCase();
562
- if (name === 'user-rules.md') return 'user-rules.md';
563
- if (name === 'memory.md') return 'the memory index';
564
- 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;
565
734
  try {
566
- const store = normcase(resolvePath(path.join(root, 'memory')));
567
- // `.parents`, so the store dir itself is not one of its own ancestors.
568
- return selfAndParents(resolvePath(p)).slice(1).some((d) => normcase(d) === store)
569
- ? '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;
570
765
  } catch {
571
766
  return null;
572
767
  }
@@ -585,8 +780,8 @@ export const SENSOR_LIST = '.geneseed/protected-checks.txt';
585
780
  * them, one repo-relative path per line (`#` comments), in `.geneseed/protected-checks.txt` at
586
781
  * its git root — found by walking up from the WRITE TARGET, not the cwd, so a session in one repo
587
782
  * writing into another reads that other repo's list. The list protects itself. Returns the entry
588
- * the path falls under, or null. shortcut: a write tool only — a shell `sed -i` or redirect is
589
- * not seen here; CI running the checks is the boundary that holds against that.
783
+ * the path falls under, or null. A write tool's path reaches this through `ruleDecide`, a shell
784
+ * command's write targets through `shellWriteTargets`, whose docblock names what stays unseen.
590
785
  */
591
786
  function protectedCheck(p) {
592
787
  return protectedIn(path.resolve(p)) ?? protectedIn(resolvePath(p));
@@ -633,7 +828,7 @@ function protectedIn(target) {
633
828
  * guard holds these lists minus the hook settings and OpenCode's own files, which OpenCode asks about natively
634
829
  * (`opencodeEditAsks` in ./settings.mjs; tests/plugins/guard.test.mjs pins the difference). The CLI
635
830
  * (`geneseed exclude`, an emit) writes these with `fs`, never through a write tool, so it is
636
- * not gated. shortcut: write tools only, like `protectedCheck` — a shell redirect is not seen.
831
+ * not gated. Reached from a shell command too, with the same limit as `protectedCheck`.
637
832
  */
638
833
  const GATE_CONFIG_FILES = ['settings.json', 'settings.local.json', 'settings/settings.json', 'excludes.json', 'AGENT.md', '.geneseed-manifest.json', '.geneseed-emit', 'opencode.json', 'opencode.jsonc'];
639
834
  const GATE_CONFIG_MARKERS = ['.claude', '.openclaude', '.bob', '.opencode'];
@@ -650,7 +845,8 @@ function gateConfig(p, root) {
650
845
  if (bin && t.startsWith(bin + path.sep)) return true;
651
846
  if (/^opencode\.jsonc?$/.test(path.basename(t))) return true;
652
847
  const up = [path.dirname(target), path.dirname(path.dirname(target))];
653
- 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))))];
654
850
  if (homes.some((h) => GATE_CONFIG_FILES.some((f) => normcase(path.join(h, f)) === t))) return true;
655
851
  }
656
852
  } catch { /* an unresolvable path is no hit, like `protectedIn` */ }
@@ -690,7 +886,7 @@ function settingsAfter(before, payload) {
690
886
  return ranged ? null : once(before, ti.search, ti.replace);
691
887
  }
692
888
  if (tool === 'apply_diff' && typeof ti.diff === 'string') {
693
- const blocks = [...ti.diff.matchAll(/<<<<<<< SEARCH\r?\n(?::start_line:\s*\d+\r?\n)?(?:-------\r?\n)?([\s\S]*?)\r?\n?=======\r?\n([\s\S]*?)\r?\n?>>>>>>> REPLACE/g)];
889
+ const blocks = [...ti.diff.matchAll(DIFF_BLOCK_RE)];
694
890
  let text = before;
695
891
  for (const [, search, replace] of blocks) if ((text = once(text, search, replace)) === null) return null;
696
892
  // One block only: with several, Bob may apply some and refuse others (its start-line window).
@@ -731,6 +927,51 @@ function bobSettingsChange(p, payload) {
731
927
  return geneseedWiring(a) === geneseedWiring(b) ? null : 'it changes Geneseed\'s own hook entries';
732
928
  }
733
929
 
930
+ /**
931
+ * External Gate on one write target, by tool or by shell: why it must be asked about, or null.
932
+ * On Bob a hook-settings file is the user's shared host config, refused only when the write
933
+ * touches Geneseed's wiring (`bobSettingsChange`), and it never reads `opencode.json(c)`.
934
+ */
935
+ function externalGate(args, p, payload) {
936
+ const sensor = protectedCheck(p);
937
+ if (sensor) {
938
+ return `Geneseed (External Gate) — ${p} is a protected check (${sensor === DONE_LIST
939
+ ? 'the done gate list itself' : `${sensor}, listed in ${SENSOR_LIST}`}). A check the agent can `
940
+ + 'edit is not a check: fix the code, not the check, unless the user asks for this edit.';
941
+ }
942
+ if (HOST === 'bob' && /^opencode\.jsonc?$/i.test(path.basename(p))) return null;
943
+ if (!gateConfig(p, args.root)) return null;
944
+ const why = HOST === 'bob' && SETTINGS_RE.test(p) ? bobSettingsChange(p, payload) : '';
945
+ if (why === null) return null;
946
+ return `Geneseed (External Gate) — ${p} ${GATE_CONFIG_ASK}`
947
+ + (why ? ` On Bob this write is refused because ${why}.` : '');
948
+ }
949
+
950
+ /**
951
+ * Cure the Cause's edit-time half, ADVISORY: tells the agent that this write weakens a test (a skip
952
+ * marker added, an assertion dropped). The turn-end line is `doneGate`'s, read from the transcript.
953
+ * It only speaks, and it must not fail a write, so every error is silence. On Bob stdout is not
954
+ * read on PreToolUse, so the note is a stderr line, which also serves as its log line.
955
+ */
956
+ function testWeakenedNote(p, payload) {
957
+ try {
958
+ if (!isTestPath(p)) return;
959
+ const abs = path.resolve(typeof payload.cwd === 'string' ? payload.cwd : '.', p);
960
+ const root = gitRootOf(path.dirname(abs));
961
+ if (root && !isTestPath(path.relative(root, abs))) return;
962
+ let whole = '';
963
+ if (/write/i.test(String(payload.tool_name))) {
964
+ try { whole = readFileSync(abs, 'utf8'); } catch { /* a new file: nothing to weaken */ }
965
+ }
966
+ const hits = weakenedBy(editPairs(payload.tool_input, whole));
967
+ if (!hits.length) return;
968
+ const note = `Geneseed (Cure the Cause) — this edit weakens a test: ${p} (${hits.join(', ')}). `
969
+ + 'Fix the code, not the test. State this in your closing summary, with the reason.';
970
+ if (HOST === 'bob') err(`[geneseed] ${note}\n`);
971
+ else out(contextNote(note));
972
+ } catch { /* see above */ }
973
+ }
974
+
734
975
  function ruleGate(args) {
735
976
  if (sovereignBypass(args.root)) return 0;
736
977
  return ruleDecide(args, readPayload());
@@ -744,11 +985,15 @@ function diffReplaced(diff) {
744
985
  return halves.length ? halves.join('\n') : diff;
745
986
  }
746
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'];
747
990
  function ruleDecide(args, payload) {
748
991
  const ti = (payload && payload.tool_input) || {};
749
- // NotebookEdit names its target `notebook_path`; the settings matcher routes it here too.
750
- const p = ti.file_path || ti.path || ti.notebook_path || '';
751
- 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;
752
997
  // Write carries `content`, Edit `new_string`, NotebookEdit `new_source`, MultiEdit an
753
998
  // `edits[]` of `new_string`s — every one can plant a credential, so every one is scanned.
754
999
  // MultiEdit is no longer in Claude Code's own tool table (tools-reference.md) or the
@@ -764,8 +1009,9 @@ function ruleDecide(args, payload) {
764
1009
  .filter((v) => typeof v === 'string').join('\n');
765
1010
  // `--no-secrets-gate`: the install switched Law I's scan off (user decision 2026-10-18). Only
766
1011
  // this check stands down; the protected checks and process 1 below still run.
767
- if (!args.noSecretsGate && body && !DOTENV_RE.test(p) && SECRET_RE.test(body)) {
768
- 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 `
769
1015
  + 'credential-shaped string. Secrets live in .env or a secret manager, never in a '
770
1016
  + 'tracked file.');
771
1017
  }
@@ -773,33 +1019,23 @@ function ruleDecide(args, payload) {
773
1019
  // shortcut: a write is told by its tool name, so a Bob write tool named outside WRITE_NAME_RE
774
1020
  // passes both gates; switch to an allowlist of Bob's read tools if Bob adds or renames one.
775
1021
  const bobRead = HOST === 'bob' && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
776
- const sensor = !bobRead && protectedCheck(p);
777
- if (sensor) {
778
- return ask(args, 'rule-gate', 'rigor-5', `Geneseed (External Gate) — ${p} is a protected `
779
- + `check (${sensor === DONE_LIST ? 'the done gate list itself'
780
- : `${sensor}, listed in ${SENSOR_LIST}`}). A check the agent can edit is not a `
781
- + 'check: fix the code, not the check, unless the user asks for this edit.');
782
- }
783
- // Bob never reads `opencode.json(c)`, OpenCode's whole host config: it is not gated from Bob.
784
- const bobWrite = !bobRead && !(HOST === 'bob' && /^opencode\.jsonc?$/i.test(path.basename(p)));
785
- if (bobWrite && gateConfig(p, args.root)) {
786
- // Bob: a hook-settings file is the user's shared host config — refused only when the write
787
- // touches Geneseed's wiring (`bobSettingsChange`); a pass falls through to the checks below.
788
- const why = HOST === 'bob' && SETTINGS_RE.test(p) ? bobSettingsChange(p, payload) : '';
789
- if (why !== null) {
790
- return ask(args, 'rule-gate', 'rigor-5', `Geneseed (External Gate) — ${p} ${GATE_CONFIG_ASK}`
791
- + (why ? ` On Bob this write is refused because ${why}.` : ''));
792
- }
793
- }
794
- const target = ruleGateTarget(p, args.root);
1022
+ const external = !bobRead && paths.map((p) => externalGate(args, p, payload)).find(Boolean);
1023
+ if (external) return ask(args, 'rule-gate', 'rigor-5', external);
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];
795
1027
  if (!target) {
796
1028
  // The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
797
1029
  // `--no-ownership-gate`: the install switched it off (D25).
798
1030
  const why = args.noOwnershipGate ? null : ownershipBlock(p, payload, body, args.root);
799
- return why ? deny(args, 'rule-gate', 'ownership', why) : 0;
1031
+ if (why) return deny(args, 'rule-gate', 'ownership', why);
1032
+ // Only here: stdout carries one document, and an ask or a deny above already holds it.
1033
+ if (!bobRead) testWeakenedNote(p, payload);
1034
+ return 0;
800
1035
  }
801
1036
  return ask(args, 'rule-gate', 'process-1', `Geneseed (Persist Insight) \u2014 writing to `
802
- + `${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));
803
1039
  }
804
1040
  export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
805
1041