geneseed 5.1.1 → 5.3.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 (163) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -2
  3. package/SHIPPED.md +1 -1
  4. package/adapters/opencode/README.md +4 -3
  5. package/adapters/opencode/plugins/geneseed-context.js +82 -29
  6. package/adapters/opencode/plugins/geneseed-guard.js +118 -8
  7. package/bin/geneseed-cli.mjs +64 -16
  8. package/bin/geneseed-hook.mjs +37 -3
  9. package/docs/concepts/exclusions.md +1 -1
  10. package/docs/concepts/factories.md +40 -6
  11. package/docs/concepts/footprint.md +1 -1
  12. package/docs/concepts/foreman-mode.md +2 -2
  13. package/docs/concepts/host-matrix.md +1 -1
  14. package/docs/concepts/loop-gates.md +1 -1
  15. package/docs/concepts/loops.md +2 -2
  16. package/docs/concepts/shared-tier.md +1 -1
  17. package/docs/design-history.md +140 -0
  18. package/docs/extending.md +54 -162
  19. package/docs/guides/run-a-factory.md +15 -2
  20. package/docs/guides/setup-doctrines.md +1 -1
  21. package/docs/guides/upgrade.md +2 -2
  22. package/docs/reference/factory-actions.md +6 -5
  23. package/docs/reference/troubleshoot-update.md +1 -1
  24. package/docs/understand/enforced-vs-asked.md +1 -1
  25. package/docs/web-ui.md +16 -3
  26. package/harness.config.json +1 -1
  27. package/js/README.md +10 -7
  28. package/js/build/args.mjs +10 -4
  29. package/js/build/bundle.mjs +122 -23
  30. package/js/build/driver.mjs +32 -12
  31. package/js/build/emit-claude.mjs +2 -1
  32. package/js/build/emit-common.mjs +2 -2
  33. package/js/build/emit-opencode.mjs +22 -10
  34. package/js/build/export.mjs +431 -0
  35. package/js/build/generate.mjs +3 -0
  36. package/js/build/render.mjs +44 -24
  37. package/js/build/source.mjs +6 -1
  38. package/js/cli-table.json +232 -57
  39. package/js/factory/cli.mjs +24 -5
  40. package/js/factory/graph.mjs +13 -9
  41. package/js/factory/metrics.mjs +93 -0
  42. package/js/factory/registry.mjs +37 -12
  43. package/js/factory/state.mjs +25 -6
  44. package/js/hosts/hooks-context.mjs +26 -1
  45. package/js/hosts/hooks-done.mjs +8 -2
  46. package/js/hosts/hooks-prims.mjs +52 -3
  47. package/js/hosts/hooks.mjs +155 -33
  48. package/js/hosts/hosts.mjs +2 -4
  49. package/js/hosts/installs.mjs +28 -0
  50. package/js/hosts/loss.mjs +25 -3
  51. package/js/hosts/native.mjs +30 -2
  52. package/js/hosts/owned.mjs +55 -1
  53. package/js/hosts/ownership-gate.mjs +5 -5
  54. package/js/hosts/settings.mjs +83 -33
  55. package/js/inspect/diff.mjs +16 -1
  56. package/js/inspect/doctor.mjs +7 -3
  57. package/js/inspect/excludes.mjs +18 -6
  58. package/js/inspect/status.mjs +35 -7
  59. package/js/inspect/validate.mjs +44 -21
  60. package/js/lib/managed-block.mjs +74 -0
  61. package/js/maintain/uninstall.mjs +85 -15
  62. package/js/maintain/update.mjs +31 -7
  63. package/js/ui/cli.mjs +34 -4
  64. package/js/ui/menu.mjs +1 -1
  65. package/js/ui/tui.mjs +11 -14
  66. package/js/web/actions.mjs +5 -0
  67. package/js/web/api.mjs +32 -11
  68. package/js/web/daemon.mjs +0 -1
  69. package/js/web/server.mjs +1 -0
  70. package/js/web/state.mjs +37 -16
  71. package/package.json +1 -1
  72. package/src/AGENT.md.tmpl +23 -17
  73. package/src/agents/_template.md +1 -1
  74. package/src/agents/advocate.md +1 -1
  75. package/src/agents/developer.md +12 -3
  76. package/src/agents/empiricist.md +1 -1
  77. package/src/agents/framer.md +1 -1
  78. package/src/agents/historian.md +1 -1
  79. package/src/agents/operator.md +1 -1
  80. package/src/agents/pragmatist.md +1 -1
  81. package/src/agents/researcher.md +1 -1
  82. package/src/agents/skeptic.md +1 -1
  83. package/src/agents/steward.md +1 -1
  84. package/src/agents/user-advocate.md +1 -1
  85. package/src/agents/visionary.md +1 -1
  86. package/src/bricks/intake.md +10 -3
  87. package/src/bricks/retro.md +13 -3
  88. package/src/doctrines/comms.md +1 -1
  89. package/src/doctrines/ops.md +1 -1
  90. package/src/doctrines/process.md +7 -5
  91. package/src/factories/analysis-to-build.json +1 -0
  92. package/src/factories/bug-report-to-fix.json +1 -0
  93. package/src/factories/issue-to-pr.json +1 -0
  94. package/src/laws/universal.md +2 -2
  95. package/src/modes/foreman.md +8 -14
  96. package/src/skills/commit.md +7 -2
  97. package/src/skills/debug.md +1 -1
  98. package/src/skills/diagram-design/SKILL.md +1 -1
  99. package/src/skills/diagram-design/VENDOR.md +3 -1
  100. package/src/skills/factory-forge.md +5 -3
  101. package/src/skills/factory.md +22 -1
  102. package/src/skills/geneseed.md +1 -1
  103. package/src/skills/handoff.md +1 -1
  104. package/src/skills/parallel-agents.md +1 -1
  105. package/src/skills/pipeline.md +6 -6
  106. package/src/skills/plan.md +7 -3
  107. package/src/skills/spring-testing.md +1 -1
  108. package/themes/biker.json +78 -78
  109. package/themes/commentator.json +81 -81
  110. package/themes/cyberpunk.json +79 -79
  111. package/themes/gamer.json +77 -77
  112. package/themes/imperial.json +82 -82
  113. package/themes/joker.json +79 -79
  114. package/themes/marvin.json +82 -82
  115. package/themes/mean.json +82 -82
  116. package/themes/military.json +78 -78
  117. package/themes/neutral.json +78 -78
  118. package/themes/pirate.json +79 -79
  119. package/themes/sports.json +79 -79
  120. package/themes/verstappen.json +78 -78
  121. package/themes/wizard.json +79 -79
  122. package/web/dist/assets/ActiveLoops-BJJN3P-V.js +1 -0
  123. package/web/dist/assets/Activity-CqJiquEq.js +1 -0
  124. package/web/dist/assets/ActivityDetail-BSzevynX.js +1 -0
  125. package/web/dist/assets/{Bonsai-hiG_gGNU.js → Bonsai-Bfpb6W-1.js} +1 -1
  126. package/web/dist/assets/{CopyButton-DUIUfNp6.js → CopyButton-ByIntFtB.js} +1 -1
  127. package/web/dist/assets/Dashboard-DBOEi9lQ.js +2 -0
  128. package/web/dist/assets/Docs-DvlMJhpu.js +5 -0
  129. package/web/dist/assets/Factories-Bpvv7L2H.js +1 -0
  130. package/web/dist/assets/{GreenhouseView-BKxy5apE.js → GreenhouseView-GpBsYn50.js} +1 -1
  131. package/web/dist/assets/Installs-BlGmVrFK.js +3 -0
  132. package/web/dist/assets/{JournalView-ChFitHjo.js → JournalView-iLuLrOxE.js} +1 -1
  133. package/web/dist/assets/Kits-DRwpxC-J.js +1 -0
  134. package/web/dist/assets/Laws-CZkiNOWQ.js +4 -0
  135. package/web/dist/assets/LibRows-DEHjIoD-.js +1 -0
  136. package/web/dist/assets/Library-B4K-1iNF.js +3 -0
  137. package/web/dist/assets/Loops-BWSzaW8E.js +2 -0
  138. package/web/dist/assets/{OperatorHudView-BO0aIKPL.js → OperatorHudView-BAXwCEvY.js} +1 -1
  139. package/web/dist/assets/Personal-Bp9nV4GR.js +2 -0
  140. package/web/dist/assets/Settings-CWWuaIp-.js +1 -0
  141. package/web/dist/assets/Tabs-CWeQTADL.js +1 -0
  142. package/web/dist/assets/index-CsAZq0BQ.css +1 -0
  143. package/web/dist/assets/index-How7SzDZ.js +6 -0
  144. package/web/dist/assets/usePoll-D5c_qIFZ.js +1 -0
  145. package/web/dist/index.html +2 -2
  146. package/web/dist/assets/ActiveLoops-BTHIaRhn.js +0 -1
  147. package/web/dist/assets/Activity-CpkBwpu7.js +0 -1
  148. package/web/dist/assets/ActivityDetail-DTPziZWM.js +0 -1
  149. package/web/dist/assets/Dashboard-Dnw6EyX7.js +0 -2
  150. package/web/dist/assets/Docs-BEET_l16.js +0 -5
  151. package/web/dist/assets/Factories-D6KXkfWw.js +0 -1
  152. package/web/dist/assets/Installs-CnFVlVD0.js +0 -3
  153. package/web/dist/assets/Kits-CcR-OlwQ.js +0 -1
  154. package/web/dist/assets/Laws-B1s5idOg.js +0 -4
  155. package/web/dist/assets/LibRows-BZgdbI1l.js +0 -1
  156. package/web/dist/assets/Library-x6TkkEVF.js +0 -3
  157. package/web/dist/assets/Loops-BH93KKxn.js +0 -2
  158. package/web/dist/assets/Personal-CE_0Vhh0.js +0 -2
  159. package/web/dist/assets/Settings-CbpZvVN_.js +0 -1
  160. package/web/dist/assets/Tabs-C2oW7oEj.js +0 -1
  161. package/web/dist/assets/index-BQwOmbor.js +0 -6
  162. package/web/dist/assets/index-CuIop_pO.css +0 -1
  163. package/web/dist/assets/usePoll-o8ul-Sog.js +0 -1
@@ -56,6 +56,7 @@ import path from 'node:path';
56
56
  import { printOut as out, printErr as err, withDiscardableStderr } from '../lib/fs.mjs';
57
57
  import { normcase } from '../lib/paths.mjs';
58
58
  import { machineDir } from '../lib/machine-dir.mjs';
59
+ import { markerLines } from '../lib/managed-block.mjs';
59
60
  import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
60
61
  import {
61
62
  GATE_LEDGER, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
@@ -66,8 +67,8 @@ import {
66
67
  } from './gitref.mjs';
67
68
  import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
68
69
  import {
69
- readStdin, SECRET_RE, DONE_LIST, DIFF_BLOCK_RE, isTestPath, weakenedBy, editPairs,
70
- gateLoss, gateSafe,
70
+ readStdin, SECRET_RE, DONE_LIST, diffBlocks, isTestPath, weakenedBy, editPairs,
71
+ gateLoss, gateSafe, askDecision, decisionDoc, asciiJson,
71
72
  } from './hooks-prims.mjs';
72
73
  import { recordUse } from './usage.mjs';
73
74
  import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
@@ -80,7 +81,20 @@ import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
80
81
  // (`git add . && git commit … && git push`) and `-C <path>` forms, so a compound
81
82
  // one-liner can never slip a commit past the prompt. `[^\n]*` is the boundary: a `git` on
82
83
  // one line and a `commit` on the next are two commands, not one.
83
- const GIT_GATE_RE = /\bgit\b[^\n]*\b(?:commit|push)\b/;
84
+ //
85
+ // LINEAR, ON PURPOSE. The plain `\bgit\b[^\n]*\b(?:commit|push)\b` rescanned to the end of the
86
+ // line from EVERY `git`, so `git -C x ` repeated to 270 KB took 7.8 s here alone, and past the
87
+ // host's hook timeout the call ran unguarded. A match can start only at the input's start or at
88
+ // a `\n` (never `^` with `m`, whose `\r`/`U+2028` line starts would bring the rescan back), and
89
+ // it tries only the line's FIRST `git`: if any `git` on a line precedes a verb, the first one
90
+ // does too, so the truth set is unchanged and each line is read once.
91
+ const GIT_GATE_RE = /(?:^|\n)(?:(?!\bgit\b)[^\n])*\bgit\b[^\n]*\b(?:commit|push)\b/;
92
+
93
+ // Past this many characters a command is not read at all: it asks. Every reader on the path
94
+ // (`shellReading`, the splitters, `catastrophic`) is at least linear, some worse, and a gate
95
+ // that has not finished when the host's hook timeout fires lets the call through unjudged. No
96
+ // real command line comes near it; a generated one that does is worth a human look.
97
+ const MAX_COMMAND_CHARS = 64 * 1024;
84
98
 
85
99
  // Law IV's boundary half lives in `./loss.mjs`: it asks only when a command would really lose
86
100
  // data — a protected branch deleted or force-pushed, an unpushed unmerged branch deleted,
@@ -240,17 +254,8 @@ export function worktreeExempt(command, cwd, agentId) {
240
254
  }
241
255
  }
242
256
 
243
- /**
244
- * The `permissionDecision: "ask"` document, in Python's compact `json.dumps` spelling: `, ` and
245
- * `: ` separators, and `ensure_ascii` — every code unit past `~` as a lowercase `\uXXXX`, which is
246
- * why a reason's em dash reaches stdout as `—`.
247
- *
248
- * A TEMPLATE, NOT `js/lib/json.mjs`'s `jsonDumpsCompact`. The keys are fixed and the one value
249
- * is a string, so the general serializer bought nothing here — and it cost every tool call a
250
- * 378-line module parse, being the only thing on the gate path that needed it.
251
- * `tests/unit/hook_gates.test.mjs` holds the two byte-identical over non-ASCII reasons.
252
- */
253
- export function askDecision(reason) { return decisionDoc('ask', reason); }
257
+ // `askDecision` lives in `./hooks-prims.mjs`, so the entry can ask when THIS module fails to load.
258
+ export { askDecision };
254
259
 
255
260
  /**
256
261
  * The `permissionDecision: "deny"` twin of `askDecision`, same spelling. Claude Code shows an
@@ -260,14 +265,6 @@ export function askDecision(reason) { return decisionDoc('ask', reason); }
260
265
  */
261
266
  export function denyDecision(reason) { return decisionDoc('deny', reason); }
262
267
 
263
- function decisionDoc(decision, reason) {
264
- return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "${decision}", `
265
- + `"permissionDecisionReason": ${asciiJson(reason)}}}\n`;
266
- }
267
-
268
- const asciiJson = (s) => JSON.stringify(s)
269
- .replace(/[\u007f-￿]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
270
-
271
268
  /**
272
269
  * A note to the MODEL that decides nothing: PreToolUse `additionalContext` with no
273
270
  * `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
@@ -763,6 +760,68 @@ export function shellWriteTargets(command, cwd, ps = false) {
763
760
  }
764
761
  return [...found];
765
762
  }
763
+ /**
764
+ * THE ONE READING OF A COMMAND every gate below is handed. The lexers here are non-POSIX on
765
+ * purpose (`SCAN_TOKEN_RE`: a backslash is never an escape, so PowerShell's `"C:\"` closes), and
766
+ * that is wrong for the shell most commands run in. In bash:
767
+ * - a backslash-newline joins two lines, so `rm -rf \⏎ /` is one command. Read as two, the
768
+ * operand landed in a segment with no program and every gate passed it;
769
+ * - `\'` and `\"` outside single quotes are a literal quote, not a delimiter. Read as one, the
770
+ * everyday `'it'\''s'` left the quote state inverted and hid the rest of the line as data,
771
+ * `&& rm -rf /` included.
772
+ * So for a bash-like shell the continuation is joined and an escaped quote or separator is
773
+ * replaced by `_`, which is inert to every lexer and keeps every other character where it was.
774
+ * For PowerShell only its own continuation, a backtick-newline, is joined, and nothing else
775
+ * changes: there the backslash is a path separator.
776
+ *
777
+ * `shell` is what the caller knows: `'bash'` (Claude's `Bash` tool, Git Bash on Windows too),
778
+ * `'powershell'`, or null. Unknown is read as bash unless the platform is Windows or a
779
+ * `Verb-Noun` word says PowerShell.
780
+ */
781
+ export function shellReading(command, shell = null) {
782
+ const bashLike = shell === 'bash'
783
+ || (shell !== 'powershell' && process.platform !== 'win32' && !PS_CUE_RE.test(command));
784
+ if (!bashLike) return command.replace(/`\r?\n/g, '');
785
+ if (!command.includes('\\')) return command;
786
+ let out = '';
787
+ let quote = '';
788
+ const tags = []; // heredocs opened on this line: `[stripTabs, tag]`
789
+ for (let i = 0; i < command.length; i += 1) {
790
+ const ch = command[i];
791
+ const next = command[i + 1];
792
+ // A heredoc body is copied as it is: under a quoted tag a backslash is literal, and the
793
+ // gates read a body as data or, for `bash <<EOF`, as the command it is.
794
+ if (!quote && ch === '<' && next === '<' && command[i + 2] !== '<' && command[i - 1] !== '<') {
795
+ const m = /^<<(-?)[ \t]*(["']?)([A-Za-z_]\w*)\2/.exec(command.slice(i));
796
+ if (m) { tags.push([m[1], m[3]]); out += m[0]; i += m[0].length - 1; continue; }
797
+ }
798
+ if (!quote && ch === '\n' && tags.length) {
799
+ out += ch;
800
+ while (tags.length) {
801
+ const end = command.indexOf('\n', i + 1);
802
+ const line = command.slice(i + 1, end < 0 ? command.length : end);
803
+ out += line + (end < 0 ? '' : '\n');
804
+ i = end < 0 ? command.length : end;
805
+ const bare = line.replace(/\r$/, '');
806
+ if ((tags[0][0] ? bare.replace(/^\t+/, '') : bare) === tags[0][1]) tags.shift();
807
+ if (end < 0) break;
808
+ }
809
+ continue;
810
+ }
811
+ if (ch === '\\' && quote !== "'" && next !== undefined) {
812
+ const eol = next === '\n' ? 1 : (next === '\r' && command[i + 2] === '\n' ? 2 : 0);
813
+ if (eol) { i += eol; continue; }
814
+ // In double quotes only `\"` matters to a lexer; outside, a quote or a separator does.
815
+ out += ch + ((quote ? next === '"' : /["';|&]/.test(next)) ? '_' : next);
816
+ i += 1;
817
+ continue;
818
+ }
819
+ if (quote) { if (ch === quote) quote = ''; } else if (ch === '"' || ch === "'") quote = ch;
820
+ out += ch;
821
+ }
822
+ return out;
823
+ }
824
+
766
825
  // ---- shell-write twin: END
767
826
 
768
827
  /**
@@ -802,10 +861,54 @@ function shellStoreReason(args, command, payload) {
802
861
  return null;
803
862
  }
804
863
 
805
- function gitDecide(args, payload) {
864
+ // The git verbs that neither commit nor push nor run a command of the caller's choosing, and the
865
+ // programs that only read. `consentBenign` is the only reader.
866
+ const GIT_READ_VERBS = new Set(['log', 'diff', 'show', 'status', 'stash', 'blame', 'grep', 'ls-files',
867
+ 'rev-parse', 'reflog', 'shortlog', 'describe', 'branch', 'fetch', 'help', 'ls-remote', 'cat-file']);
868
+ const READ_PROGS = new Set(['cat', 'head', 'tail', 'less', 'more', 'grep', 'egrep', 'rg', 'ls', 'wc',
869
+ 'sort', 'uniq', 'cut', 'file', 'stat', 'true', 'cd']);
870
+
871
+ /**
872
+ * True when a command that trips `GIT_GATE_RE` provably neither commits nor pushes: the regex
873
+ * reads words, so `git log | grep push`, `cat .git/hooks/pre-commit.sample`, `git stash push`
874
+ * and `git diff -- docs/commit-style.md` all asked, and a gate that asks when nothing is at
875
+ * stake trains the click-through it exists to prevent.
876
+ *
877
+ * FAIL-CLOSED: the ask stands unless EVERY segment is one of two known shapes, a program that
878
+ * only reads, or `git` with a read verb reached past `-C <dir>`/`--no-pager` alone. Anything
879
+ * else keeps the ask: another program (`sh`, `xargs`, `sudo`: it may run the words), another
880
+ * git option (`-c alias.x=…`), a verb outside the list (an alias may be a commit), a
881
+ * substitution, or a redirection into a file.
882
+ */
883
+ function consentBenign(command) {
884
+ if (/\$\(|`|[<>]/.test(command)) return false;
885
+ for (const seg of scanSegments(command)) {
886
+ const toks = stripStructure(seg.match(SCAN_TOKEN_RE) || []).map(unquote);
887
+ if (!toks.length) continue;
888
+ const prog = toks[0].toLowerCase();
889
+ if (READ_PROGS.has(prog)) continue;
890
+ if (prog !== 'git') return false;
891
+ let i = 1;
892
+ while (i < toks.length && (toks[i] === '--no-pager' || toks[i] === '-C')) i += toks[i] === '-C' ? 2 : 1;
893
+ if (!GIT_READ_VERBS.has(toks[i])) return false;
894
+ // `git stash push` and `git branch` take no option that runs a command; `--exec`/`-c` do.
895
+ if (toks.slice(i + 1).some((t) => /^(?:--exec|--upload-pack|--receive-pack|-c$|--ext)/.test(t))) return false;
896
+ }
897
+ return true;
898
+ }
899
+
900
+ // Exported for the in-process timing rows (tests/unit/hook_gates.test.mjs): a spawn's own start-up
901
+ // on a loaded Windows host is noise next to a 200 ms bound.
902
+ export function gitDecide(args, payload) {
806
903
  const ti = (payload && payload.tool_input) || {};
807
- const { command } = ti;
808
- if (typeof command !== 'string') return 0;
904
+ if (typeof ti.command !== 'string') return 0;
905
+ // Before any switch: the catastrophic class below runs whatever the install turned off, so
906
+ // every gate verb reads the command. `unverified` under law-4, so Bob refuses it as well.
907
+ if (ti.command.length > MAX_COMMAND_CHARS) {
908
+ return ask(args, 'git-gate', 'law-4', 'unverified', {});
909
+ }
910
+ const tool = payload && payload.tool_name;
911
+ const command = shellReading(ti.command, tool === 'Bash' ? 'bash' : tool === 'PowerShell' ? 'powershell' : null);
809
912
  // The agent's own words, for the asks where they are no conflict of interest (`gateText`'s `quote`).
810
913
  const says = typeof ti.description === 'string' ? ti.description : '';
811
914
  // Law IV's catastrophic class (a root, a drive, the home dir, a disk): no state makes it safe,
@@ -842,7 +945,7 @@ function gitDecide(args, payload) {
842
945
  // `--no-consent`: the process pack (or process 5 alone) is off, so the commit/push ask has
843
946
  // no rule behind it — but Law IV above is universal and has already run. Checked before
844
947
  // `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
845
- if (args.noConsent || !GIT_GATE_RE.test(command)) return 0;
948
+ if (args.noConsent || !GIT_GATE_RE.test(command) || consentBenign(command)) return 0;
846
949
  // Consent Before Push: a loop launched on its own `loop/*` branch is a named batch for a
847
950
  // fixed set of commit/push forms on that branch only — never a merge into anything shared.
848
951
  if (loopExempt(command, (payload && payload.cwd) || process.cwd())) return 0;
@@ -1073,9 +1176,9 @@ function settingsAfter(before, payload) {
1073
1176
  return ranged ? null : replaceOnce(before, ti.search, ti.replace);
1074
1177
  }
1075
1178
  if (tool === 'apply_diff' && typeof ti.diff === 'string') {
1076
- const blocks = [...ti.diff.matchAll(DIFF_BLOCK_RE)];
1179
+ const blocks = diffBlocks(ti.diff);
1077
1180
  let text = before;
1078
- for (const [, search, replace] of blocks) if ((text = replaceOnce(text, search, replace)) === null) return null;
1181
+ for (const [search, replace] of blocks) if ((text = replaceOnce(text, search, replace)) === null) return null;
1079
1182
  // One block only: with several, Bob may apply some and refuse others (its start-line window).
1080
1183
  return blocks.length === 1 ? text : null;
1081
1184
  }
@@ -1130,8 +1233,8 @@ const ASK_COUNT_MAX = 1024 * 1024;
1130
1233
  * The `editPairs` of a write the gate will ask about, for the line count, or undefined for none. Run
1131
1234
  * only then, because `Write`'s old text is a file read. A pair says nothing of how often it applies,
1132
1235
  * so a `replace_all` and a `search_and_replace` count nothing, and a notebook cell names no old text.
1133
- * A `diff` counts nothing either: the agent writes it, and `DIFF_BLOCK_RE` took 20 s on 80 KB of
1134
- * opened blocks. A count must cost no verdict, so whatever is not a small regular file, or cannot be
1236
+ * A `diff` counts nothing either: the agent writes it, and the regex `diffBlocks` replaced took 20 s
1237
+ * on 80 KB of opened blocks. A count must cost no verdict, so whatever is not a small regular file, or cannot be
1135
1238
  * read, counts nothing. Only a file that is truly absent is a new file.
1136
1239
  */
1137
1240
  function askPairs(payload, p) {
@@ -1182,7 +1285,8 @@ function carrierBlockChange(p, payload) {
1182
1285
  if (e?.code !== 'ENOENT') return true;
1183
1286
  }
1184
1287
  const after = carrierAfter(before, payload);
1185
- return after === null || after.length > CARRIER_REPLAY_CAP || carrierBlock(after) !== carrierBlock(before);
1288
+ return after === null || after.length > CARRIER_REPLAY_CAP || carrierBlock(after) !== carrierBlock(before)
1289
+ || markerLines(after) !== markerLines(before);
1186
1290
  }
1187
1291
 
1188
1292
  /**
@@ -1235,21 +1339,39 @@ function ruleGate(args) {
1235
1339
 
1236
1340
  // The REPLACE halves of a Roo-style `apply_diff` (`<<<<<<< SEARCH … ======= <new> >>>>>>> REPLACE`).
1237
1341
  // A diff without those markers is a shape we do not know, so it is returned whole: fail closed.
1342
+ // One pass: each half runs from a separator line to the FIRST closing line after it, as the lazy
1343
+ // `/^=======\r?\n([\s\S]*?)^>>>>>>> REPLACE/gm` did, and a separator with no closing after it ends
1344
+ // the scan, where that regex rescanned the rest of the diff once per separator.
1238
1345
  function diffReplaced(diff) {
1239
1346
  if (typeof diff !== 'string') return diff;
1240
- const halves = [...diff.matchAll(/^=======\r?\n([\s\S]*?)^>>>>>>> REPLACE/gm)].map((m) => m[1]);
1347
+ const SEP = /^=======\r?\n/gm;
1348
+ const CLOSE = /^>>>>>>> REPLACE/gm;
1349
+ const halves = [];
1350
+ for (let sep; (sep = SEP.exec(diff));) {
1351
+ CLOSE.lastIndex = sep.index + sep[0].length;
1352
+ const close = CLOSE.exec(diff);
1353
+ if (!close) break;
1354
+ halves.push(diff.slice(sep.index + sep[0].length, close.index));
1355
+ SEP.lastIndex = CLOSE.lastIndex;
1356
+ }
1241
1357
  return halves.length ? halves.join('\n') : diff;
1242
1358
  }
1243
1359
 
1244
1360
  const RULE_PATH_KEYS = ['file_path', 'path', 'notebook_path', 'target_file', 'target', 'file', 'filename', 'destination', 'dest',
1245
1361
  'new_path', 'new_name', 'old_path', 'source', 'from', 'to'];
1246
- function ruleDecide(args, payload) {
1362
+ // Exported for the in-process timing rows, as `gitDecide` is.
1363
+ export function ruleDecide(args, payload) {
1247
1364
  const ti = (payload && payload.tool_input) || {};
1248
1365
  // NotebookEdit names its target `notebook_path`; the settings matcher routes it here too. Every
1249
1366
  // key is read, never the first found: Bob's move and rename tools carry two, and a harmless
1250
1367
  // `path` beside the real target must not hide it from any gate below.
1251
1368
  const paths = [...new Set(RULE_PATH_KEYS.map((k) => ti[k]).filter((v) => typeof v === 'string' && v))];
1252
1369
  if (!paths.length) return 0;
1370
+ // A diff past the command bound is not read, for `MAX_COMMAND_CHARS`' reason: on Bob a scan past
1371
+ // the hook timeout lets the write through with no secrets check. Same `unverified` ask, law-4.
1372
+ if (typeof ti.diff === 'string' && ti.diff.length > MAX_COMMAND_CHARS) {
1373
+ return ask(args, 'rule-gate', 'law-4', 'unverified', {});
1374
+ }
1253
1375
  // Write carries `content`, Edit `new_string`, NotebookEdit `new_source`, MultiEdit an
1254
1376
  // `edits[]` of `new_string`s — every one can plant a credential, so every one is scanned.
1255
1377
  // MultiEdit is no longer in Claude Code's own tool table (tools-reference.md) or the
@@ -20,6 +20,7 @@ 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
22
  import { sharedPaths, machineDir } from '../lib/machine-dir.mjs';
23
+ import { blockOf } from '../lib/managed-block.mjs';
23
24
  import { mainWorktreeOf } from './gitref.mjs';
24
25
 
25
26
  /** The marker a project built `--shared-tier on` carries, and its one reader. The OpenCode context plugin holds a copy. */
@@ -517,12 +518,9 @@ export const CARRIERS = [
517
518
  path.join('rules', 'geneseed.md'), 'AGENTS.md',
518
519
  ];
519
520
 
520
- // `managedBlockWrite`'s delimiters (./settings.mjs, which this module may not import). First block
521
- // only, as that writer reads it.
522
- const CARRIER_BLOCK_RE = /<!-- BEGIN GENESEED -->[\s\S]*?<!-- END GENESEED -->/;
523
521
  const SHARED_CARRIER_RE = /(?:^|[\\/])(?:CLAUDE|AGENTS)\.md$/i;
524
522
  /** The managed block as a reader sees it, `''` with none. */
525
- export const carrierBlock = (text) => CARRIER_BLOCK_RE.exec(text)?.[0] ?? '';
523
+ export const carrierBlock = (text) => blockOf(text);
526
524
  /** The file a Windows write lands on: `CLAUDE.md::$DATA` and `CLAUDE.md.` both write `CLAUDE.md`. */
527
525
  export function carrierName(file) {
528
526
  const s = String(file);
@@ -45,6 +45,7 @@ import { registryRoots } from '../inspect/registry.mjs';
45
45
  import { printErr, readText, isFile, isDir } from '../lib/fs.mjs';
46
46
  import { formatRepr, isDict } from '../lib/json.mjs';
47
47
  import { comparePaths } from '../lib/paths.mjs';
48
+ import { bundleLeftovers, ownedWithin } from './owned.mjs';
48
49
  import { claudeHookShell, hookShimPath } from './shim.mjs';
49
50
 
50
51
  export { carriersFor };
@@ -586,6 +587,33 @@ export function installKind(root) {
586
587
  return null;
587
588
  }
588
589
 
590
+ /**
591
+ * What the last emit left at `root` that is not Geneseed's copy, for the console: `kept`, the
592
+ * files that are the user's at a path Geneseed ships (an edit to a shipped skill, or a file of
593
+ * theirs under a shipped name), and `stale`, the retired skills an older build left in a bundle.
594
+ * Rels are spelled from `root`, the way the user would find them.
595
+ *
596
+ * Read off what the emit recorded (the manifest's `kept`, and for an OpenCode project the
597
+ * bundle marker at the root), never by rendering, so a page poll can afford it. Each entry
598
+ * only while its file still exists: a file the user removed since is no leftover. A build
599
+ * with `--force` replaces the first kind and removes the second.
600
+ */
601
+ export function leftoversOf(root, host = 'opencode', scope = 'global') {
602
+ const cfg = scope === 'project' ? claudeCfg(root, 'project', host) : root;
603
+ const prefix = scope === 'project' ? `${path.basename(cfg)}/` : '';
604
+ const man = claudeReadManifest(cfg);
605
+ const recorded = isDict(man) && Array.isArray(man.kept) ? man.kept : [];
606
+ const kept = ownedWithin(cfg, recorded.filter((r) => typeof r === 'string'))
607
+ .filter((r) => isFile(path.join(cfg, r))).map((r) => `${prefix}${r}`);
608
+ let stale = [];
609
+ if (host === 'opencode' && scope === 'project') {
610
+ const bundle = bundleLeftovers(root);
611
+ kept.push(...bundle.kept);
612
+ stale = bundle.stale;
613
+ }
614
+ return { kept: kept.sort(), stale };
615
+ }
616
+
589
617
  /** 'active' | 'disabled' | 'absent'. */
590
618
  export function installState(root, host = 'opencode', scope = 'global') {
591
619
  if (CLAUDE_STYLE.includes(host)) return claudeState(root, scope, host);
package/js/hosts/loss.mjs CHANGED
@@ -64,9 +64,14 @@ import { currentBranch, gitRootOf, protectedBranches, stashExists } from './gitr
64
64
  * a spawn. A git destructive VERB anywhere after `git` on the same line, or a removal program
65
65
  * as a word at a command boundary. Deliberately loose — the parse decides; this only has to be
66
66
  * a superset of what the parse acts on.
67
+ *
68
+ * The git half is LINEAR: it starts only at the input's start or a `\n` and tries the line's
69
+ * first `git` alone, which matches whenever any later `git` would. `\bgit\b[^\n]*\b(?:…)` from
70
+ * every `git` was quadratic: a 270 KB `git -C x …` took seconds, and a hook past its timeout
71
+ * lets the call through. `(?<![\s\S])`, not `^`: under `m`, `^` also starts after `\r`.
67
72
  */
68
73
  export const LOSS_CANDIDATE_RE =
69
- /\bgit\b[^\n]*\b(?:reset|clean|branch|checkout|switch|restore|stash|reflog|gc|push)\b|(?:^|[\s;&|("'`])(?:rm|rmdir|unlink|del|erase|remove-item|ri|rd)(?:\.exe)?(?=[\s;&|)"'`]|$)|(?:^|\s)-delete(?=\s|$)/im;
74
+ /(?:(?<![\s\S])|\n)(?:(?!\bgit\b)[^\n])*\bgit\b[^\n]*\b(?:reset|clean|branch|checkout|switch|restore|stash|reflog|gc|push)\b|(?:^|[\s;&|("'`])(?:rm|rmdir|unlink|del|erase|remove-item|ri|rd)(?:\.exe)?(?=[\s;&|)"'`]|$)|(?:^|\s)-delete(?=\s|$)/im;
70
75
 
71
76
  class Unverified extends Error {}
72
77
  const unverified = (why) => { throw new Unverified(why); };
@@ -600,7 +605,16 @@ export function lossReason(segments, cwd, { always = true, split } = {}) {
600
605
  /** The first loss among `segs`, run from `start`; a substitution body is judged as a command. */
601
606
  const judge = (segs, start, depth = 0) => {
602
607
  let dir = start;
603
- for (const raw of segs.map(stripStructure)) {
608
+ // A `cd` inside `( … )` ends with the subshell, and `popd` goes back somewhere this reader
609
+ // never recorded. Both used to leave `dir` where the `cd` put it, so a removal after them
610
+ // was looked for in the wrong folder, found absent, and passed. Now the directory is
611
+ // unknown from there on, which asks for a relative path.
612
+ let nest = 0;
613
+ let cdInside = false;
614
+ for (const [n, raw] of segs.map(stripStructure).entries()) {
615
+ const bare = segs[n].filter((t) => !/^["']/.test(t));
616
+ const opens = bare.filter((t) => /^\(/.test(t)).length;
617
+ const closes = bare.filter((t) => /\)$/.test(t) && !/\$\(/.test(t)).length;
604
618
  const text = raw.join(' ');
605
619
  const named = LOSS_CANDIDATE_RE.test(text);
606
620
  for (const body of named ? substitutions(text) : []) {
@@ -616,12 +630,19 @@ export function lossReason(segments, cwd, { always = true, split } = {}) {
616
630
  w = /^\w+=/.test(w[0]) ? w.slice(1) : pastWrapper(wrapper, w.slice(1));
617
631
  if (!w && named) unverified(`\`${wrapper}\` takes a flag the gate does not know`);
618
632
  }
619
- if (!w || !w.length) continue;
633
+ const leave = () => {
634
+ nest = Math.max(0, nest + opens - closes);
635
+ if (nest === 0 && cdInside) { dir = null; cdInside = false; }
636
+ };
637
+ if (!w || !w.length) { leave(); continue; }
620
638
  const prog = progOf(w[0]);
621
639
  const args = w.slice(1);
640
+ if (prog === 'popd' || prog === 'pop-location') { dir = null; leave(); continue; }
622
641
  if (CD_PROGS.has(prog)) {
623
642
  const target = args.find((a) => !a.startsWith('-') && !/^\/d$/i.test(a));
624
643
  try { dir = target && target !== '-' ? resolveIn(dir, target) : null; } catch { dir = null; }
644
+ if (nest + opens > 0) cdInside = true;
645
+ leave();
625
646
  continue;
626
647
  }
627
648
  let verdict = null;
@@ -636,6 +657,7 @@ export function lossReason(segments, cwd, { always = true, split } = {}) {
636
657
  unverified(`\`${w[0].replace(OPAQUE, '')}\` is not a program the gate reads, and a removal follows it`);
637
658
  }
638
659
  if (verdict) return verdict;
660
+ leave();
639
661
  }
640
662
  return null;
641
663
  };
@@ -524,11 +524,21 @@ function warnBobIgnored(overrides) {
524
524
  * Geneseed's copy back" — two warnings about one rel that is in fact still shipped. The caller
525
525
  * reads this set back off the closure and hands it to `pruneOwned` so that rel is excluded from
526
526
  * the stale set entirely, silently, rather than re-evaluated.
527
+ *
528
+ * `claim.kept`: every rel this closure refused, edited or pre-existing. The emit writes it into
529
+ * the manifest (`kept`), which is how the console knows an install holds files that are the
530
+ * user's where Geneseed ships one, without rendering anything.
531
+ *
532
+ * `force` (`--force`): both refusals become overwrites, each named on stderr. It reaches only
533
+ * what `claim` is asked about, and `claim` is asked only about a path Geneseed ships, so a
534
+ * skill or agent under the user's own name is never in question. The leaf guard still runs: a
535
+ * forced write goes through a link no more than an ordinary one does.
527
536
  */
528
- export function claimer(oldOwned, cfg, manifestExisted = true, oldHashes = {}) {
537
+ export function claimer(oldOwned, cfg, manifestExisted = true, oldHashes = {}, force = false) {
529
538
  const oldSet = oldOwned !== null && oldOwned !== undefined ? new Set(oldOwned) : null;
530
539
  let headerPrinted = false;
531
540
  const editRefused = new Set();
541
+ const kept = new Set();
532
542
  const rroot = cfg != null ? resolvePath(cfg) : undefined; // once per emit, not per leaf
533
543
  const claim = (dest) => {
534
544
  if (cfg != null && !claimLeaf(cfg, dest, relPosix(cfg, dest), rroot)) return false;
@@ -540,12 +550,21 @@ export function claimer(oldOwned, cfg, manifestExisted = true, oldHashes = {}) {
540
550
  // constraint that a manifest without `hashes` keeps today's behaviour exactly is this
541
551
  // branch doing nothing extra, not a special case.
542
552
  if (ownedState(cfg, rel, oldHashes) === 'modified') {
553
+ if (force) {
554
+ warn(`[geneseed] --force: replaced your edited ${rel}`);
555
+ return true;
556
+ }
543
557
  warn(`[geneseed] kept your edited ${rel} — delete it to get Geneseed's copy back`);
544
558
  editRefused.add(rel);
559
+ kept.add(rel);
545
560
  return false;
546
561
  }
547
562
  return true;
548
563
  }
564
+ if (force) {
565
+ warn(`[geneseed] --force: replaced your existing ${rel}`);
566
+ return true;
567
+ }
549
568
  if (!manifestExisted && !headerPrinted) {
550
569
  warn('[geneseed] first emit over a pre-manifest install — existing files '
551
570
  + 'are treated as yours');
@@ -553,9 +572,13 @@ export function claimer(oldOwned, cfg, manifestExisted = true, oldHashes = {}) {
553
572
  }
554
573
  warn(`[geneseed] kept your existing ${rel} — skipped Geneseed's copy to avoid `
555
574
  + 'clobbering it');
575
+ kept.add(rel);
556
576
  return false;
557
577
  };
558
578
  claim.editRefused = editRefused;
579
+ claim.kept = kept;
580
+ // Did the previous emit write `dest`? Read by `writeNativeLayer` for a skill's side files.
581
+ claim.owned = (dest) => oldSet !== null && cfg != null && oldSet.has(relPosix(cfg, dest));
559
582
  return claim;
560
583
  }
561
584
 
@@ -745,8 +768,13 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
745
768
  if (kind === 'agent') nAgents += 1;
746
769
  else nSkills += 1;
747
770
  }
771
+ // A side file follows its skill's claim, with one exception: a side file the previous emit
772
+ // wrote stays maintained when the claim on SKILL.md no longer holds. That is a shipped skill
773
+ // whose SKILL.md the user edited. The edit takes SKILL.md out of `owned` for good, and
774
+ // skipping its side files here dropped them out too, so the prune deleted them: the kept
775
+ // SKILL.md pointed at a file that was gone, and credited text lost its licence.
748
776
  for (const [stem, dest, text, source] of sideFiles) {
749
- if (!claimedSkills.has(stem) || !claim(dest)) continue;
777
+ if (!(claimedSkills.has(stem) || claim.owned?.(dest)) || !claim(dest)) continue;
750
778
  if (text !== null) { write(dest, stripSkillBodyLinks(text)); continue; }
751
779
  mkdirSync(path.dirname(dest), { recursive: true });
752
780
  copyFile(source, dest);
@@ -27,6 +27,7 @@ import path from 'node:path';
27
27
  import { resolvePath } from './hosts.mjs';
28
28
  import { within } from '../lib/paths.mjs';
29
29
  import { isFile, statOrNull, textWrites } from '../lib/fs.mjs';
30
+ import { isDict, parseJson } from '../lib/json.mjs';
30
31
 
31
32
  /**
32
33
  * The manifest rels that resolve INSIDE `base` — the one security boundary every walk over
@@ -175,7 +176,7 @@ export function hashesOf(doc) {
175
176
  * An OpenCode manifest's `skill_denies` — the `permission.skill` denies Geneseed itself added
176
177
  * (`opencodeLayer` records them; a deny the user wrote, even on a Geneseed skill, is never in
177
178
  * it) — or `[]` when the manifest, or the key, is absent or malformed, which sweeps nothing.
178
- * Unlike the Law IV `permission.bash` gates (permanent, never taken back — see
179
+ * Unlike the `permission.bash` gates (left in place at uninstall, which fails closed — see
179
180
  * `reconcileOpencodePermission`), a skill-visibility deny is reversible: once uninstalled there
180
181
  * is no skill left to hide, and the name is the user's to reuse. One home because rebuild's
181
182
  * deny sweep and uninstall must agree on what Geneseed owns.
@@ -199,6 +200,17 @@ export function recordedEdit(doc) {
199
200
  };
200
201
  }
201
202
 
203
+ /**
204
+ * An OpenCode manifest's `bash_gates` — the `permission.bash` keys Geneseed itself added, which
205
+ * a later build may take back once their rule is off (`reconcileOpencodePermission`). Absent or
206
+ * malformed reads as nothing owned, like `recordedDenies`: a manifest from before 5.2.0 has no
207
+ * such key, so its gates stay until `--prune-gates` or a hand edit.
208
+ */
209
+ export function recordedGates(doc) {
210
+ const g = doc && doc.bash_gates;
211
+ return Array.isArray(g) ? g.filter((k) => typeof k === 'string') : [];
212
+ }
213
+
202
214
  /** The manifest keys for an edit record; none when Geneseed owns nothing there. */
203
215
  export function editRecordKeys(rec) {
204
216
  return rec.asks.length ? { edit_asks: rec.asks, ...(rec.shorthand ? { edit_shorthand: rec.shorthand } : {}) } : {};
@@ -218,3 +230,45 @@ export function ownedState(root, rel, hashes) {
218
230
  if (!isFile(p)) return 'missing';
219
231
  return fileHash(p) === expected ? 'unmodified' : 'modified';
220
232
  }
233
+
234
+ /**
235
+ * THE BUNDLE'S OWN FILE LIST, and why it exists. A bundle is rendered straight into `out`, and
236
+ * for the OpenCode project emit `out` is the user's repository root, where `agents/`, `skills/`
237
+ * and `laws/` are ordinary names for the user's own folders. The build used to decide ownership
238
+ * by DIRECTORY: the first render merged into such a folder and overwrote any file of the same
239
+ * name, and wrote the markers; from the second render on, those markers made it delete the
240
+ * folders whole before writing, and uninstall deleted them whole too. A user's
241
+ * `agents/support_bot.py` did not survive two emits, or one emit and an uninstall.
242
+ *
243
+ * Ownership is now per FILE, claim-on-create, the rule `claimer` (`js/hosts/native.mjs`) holds
244
+ * for a host's config dir: a file this build finds at its destination and did not write before
245
+ * is the user's and is kept; a recorded file this build no longer ships is removed; nothing
246
+ * else under `out` is touched. `bundleFiles` is the reader, here rather than in
247
+ * `js/build/bundle.mjs` because the uninstall shares it and imports nothing from the generator.
248
+ * The list rides in the bundle's `.geneseed-srcdirs.json` marker, which the build already wrote.
249
+ *
250
+ * null when the marker carries no list: a bundle an older build rendered. `build` then
251
+ * overwrites what it ships, as that build did, and removes nothing, and its own marker starts
252
+ * the record.
253
+ */
254
+ export const SRC_DIRS_MARKER = '.geneseed-srcdirs.json';
255
+ export const BUNDLE_FILES_KEY = 'files';
256
+ export function bundleFiles(out) {
257
+ let data;
258
+ try { data = parseJson(readFileSync(path.join(out, SRC_DIRS_MARKER), 'utf8')); } catch { return null; }
259
+ const files = isDict(data) ? data[BUNDLE_FILES_KEY] : null;
260
+ return Array.isArray(files) ? files.filter((f) => typeof f === 'string') : null;
261
+ }
262
+
263
+ /**
264
+ * What the last build left in a bundle that is not Geneseed's copy: `kept`, the files that are
265
+ * the user's at a path the bundle ships, and `stale`, the retired skills an older build left
266
+ * behind. Each only while the file still exists. `--force` on the next build clears both.
267
+ */
268
+ export function bundleLeftovers(out) {
269
+ let data;
270
+ try { data = parseJson(readFileSync(path.join(out, SRC_DIRS_MARKER), 'utf8')); } catch { data = null; }
271
+ const list = (key) => (isDict(data) && Array.isArray(data[key]) ? data[key] : [])
272
+ .filter((r) => typeof r === 'string' && isFile(path.join(out, r)));
273
+ return { kept: ownedWithin(out, list('kept')), stale: ownedWithin(out, list('stale')) };
274
+ }
@@ -22,6 +22,7 @@
22
22
  import { appendFileSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
23
23
  import os from 'node:os';
24
24
  import path from 'node:path';
25
+ import { withoutBlocks } from '../lib/managed-block.mjs';
25
26
  import { normcase } from '../lib/paths.mjs';
26
27
  import { gitRootOf, mainWorktreeOf } from './gitref.mjs';
27
28
 
@@ -30,10 +31,9 @@ const MANIFESTS = new Set(['package.json', 'pom.xml', 'pyproject.toml', 'go.mod'
30
31
  'composer.json', 'Gemfile']);
31
32
  const isManifest = (n) => MANIFESTS.has(n) || n.startsWith('build.gradle') || n.endsWith('.csproj');
32
33
 
33
- // `managedBlockWrite`'s delimiters (js/hosts/settings.mjs `delimiters('GENESEED')`). On a Bob
34
- // project install the block holds the whole carrier, `#### Ownership` included — hence the strip
35
- // and the exact `##` heading match. `\r?`: a CRLF file's `$` sits after the `\r`.
36
- const MANAGED_BLOCK_RE = /<!-- BEGIN GENESEED -->[\s\S]*?<!-- END GENESEED -->/g;
34
+ // On a Bob project install the managed block holds the whole carrier, `#### Ownership` included —
35
+ // hence the strip (`withoutBlocks`) and the exact `##` heading match. `\r?`: a CRLF file's `$`
36
+ // sits after the `\r`.
37
37
  const SECTION_RE = /^## Ownership[ \t]*\r?$/m;
38
38
 
39
39
  // Write-shaped tool names (Bob's `tool-gate` also routes reads here: `read_file` carries a path).
@@ -97,7 +97,7 @@ function declinedSince(root) {
97
97
  function ownAgentsText(root) {
98
98
  let text = null;
99
99
  try { text = readFileSync(path.join(root, 'AGENTS.md'), 'utf8'); } catch { /* none */ }
100
- return text === null ? '' : text.replace(MANAGED_BLOCK_RE, '');
100
+ return text === null ? '' : withoutBlocks(text);
101
101
  }
102
102
 
103
103
  /**