geneseed 4.30.1 → 4.32.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 (97) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/SHIPPED.md +1 -1
  3. package/adapters/opencode/plugins/geneseed-context.js +136 -1
  4. package/adapters/opencode/plugins/geneseed-guard.js +145 -2
  5. package/docs/concepts/exclusions.md +1 -1
  6. package/docs/concepts/footprint.md +1 -1
  7. package/docs/concepts/hook-gates.md +1 -1
  8. package/docs/concepts/hooks.md +6 -4
  9. package/docs/concepts/host-matrix.md +1 -1
  10. package/docs/concepts/loop-bricks.md +1 -1
  11. package/docs/concepts/loop-notes.md +4 -2
  12. package/docs/concepts/loop-templates.md +7 -4
  13. package/docs/concepts/loops.md +3 -0
  14. package/docs/concepts/ownership.md +1 -1
  15. package/docs/guides/run-a-loop.md +1 -1
  16. package/docs/guides/set-up-ownership.md +1 -1
  17. package/docs/reference/loop-actions.md +1 -1
  18. package/docs/reference/plugin-activity.md +1 -1
  19. package/docs/reference/plugin-context.md +4 -0
  20. package/docs/reference/plugin-guard.md +1 -1
  21. package/docs/understand/enforced-vs-asked.md +3 -2
  22. package/docs/understand/machine-bob.md +1 -1
  23. package/docs/web-ui.md +85 -26
  24. package/harness.config.json +1 -1
  25. package/js/README.md +3 -3
  26. package/js/hosts/hooks-context.mjs +22 -1
  27. package/js/hosts/hooks-done.mjs +97 -31
  28. package/js/hosts/hooks-prims.mjs +65 -0
  29. package/js/hosts/hooks.mjs +188 -27
  30. package/js/loop/state.mjs +15 -5
  31. package/js/web/actions.mjs +17 -27
  32. package/js/web/activity.mjs +139 -23
  33. package/js/web/api.mjs +31 -13
  34. package/js/web/catalog.mjs +108 -23
  35. package/js/web/handler.mjs +4 -3
  36. package/js/web/routes.mjs +47 -14
  37. package/js/web/server.mjs +14 -13
  38. package/js/web/state.mjs +36 -15
  39. package/js/web/usage-api.mjs +7 -3
  40. package/package.json +1 -1
  41. package/src/agents/_template.md +3 -0
  42. package/src/agents/developer.md +5 -2
  43. package/src/agents/tester.md +4 -1
  44. package/src/bricks/apply.md +3 -0
  45. package/src/bricks/test.md +6 -4
  46. package/src/loops/bugfix.json +11 -5
  47. package/src/loops/feature.json +7 -4
  48. package/src/skills/loop.md +1 -0
  49. package/src/skills/ship.md +9 -1
  50. package/web/dist/assets/Activity-Bjy64wHC.js +1 -0
  51. package/web/dist/assets/ActivityDetail-B0AaipP8.js +1 -0
  52. package/web/dist/assets/{Bonsai-CN4rRAHc.js → Bonsai-CJniRqaH.js} +1 -1
  53. package/web/dist/assets/{CopyButton-CYljsnLo.js → CopyButton-C5Li6awl.js} +1 -1
  54. package/web/dist/assets/Dashboard-B-6DTmae.js +2 -0
  55. package/web/dist/assets/{DataTable-BWbUx4bY.js → DataTable-b9zTShqJ.js} +1 -1
  56. package/web/dist/assets/{Docs-DE04qOKj.js → Docs-LRc30XL9.js} +2 -2
  57. package/web/dist/assets/{EmptyState-1sPNleqv.js → EmptyState-CY5Pm2xy.js} +1 -1
  58. package/web/dist/assets/FilterInput-qGKNSlxv.js +1 -0
  59. package/web/dist/assets/{GreenhouseView-DPwhFO_j.js → GreenhouseView-CcoYlaWo.js} +1 -1
  60. package/web/dist/assets/Installs-dp1epTcE.js +3 -0
  61. package/web/dist/assets/JournalView-nFP4poCf.js +1 -0
  62. package/web/dist/assets/{KitApply-BN2Az7dc.js → KitApply-DwyZUj57.js} +1 -1
  63. package/web/dist/assets/{Kits-C9qVd466.js → Kits-C0IEdZXe.js} +1 -1
  64. package/web/dist/assets/Laws-CkykmQWu.js +3 -0
  65. package/web/dist/assets/Library-Guh9HBZU.js +2 -0
  66. package/web/dist/assets/Loops-CzitjxGV.js +2 -0
  67. package/web/dist/assets/Markdown-C4S4tTA7.js +69 -0
  68. package/web/dist/assets/{OperatorHudView-CLN6Qn25.js → OperatorHudView-DLGNulIY.js} +1 -1
  69. package/web/dist/assets/Personal-BMtberL8.js +2 -0
  70. package/web/dist/assets/RailCats-D5weYPCS.js +1 -0
  71. package/web/dist/assets/Tabs-uYJqfuQt.js +1 -0
  72. package/web/dist/assets/api-BxjLd7Qd.js +1 -0
  73. package/web/dist/assets/index-DA7BiaE5.js +3 -0
  74. package/web/dist/assets/index-dbbDGFDq.css +1 -0
  75. package/web/dist/assets/{motion-CXaUMNkg.js → motion-Bccx3zE8.js} +1 -1
  76. package/web/dist/assets/react-C1iE8mnY.js +9 -0
  77. package/web/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  78. package/web/dist/assets/{usePoll-bDFN-Hr6.js → usePoll-o8ul-Sog.js} +1 -1
  79. package/web/dist/index.html +6 -6
  80. package/web/dist/assets/Activity-C8pQvnos.js +0 -1
  81. package/web/dist/assets/ActivityDetail-D_8Bx-QO.js +0 -1
  82. package/web/dist/assets/Dashboard-DkUm4XMu.js +0 -2
  83. package/web/dist/assets/FilterInput-CZREvrjX.js +0 -1
  84. package/web/dist/assets/Installs-DmPzD4BW.js +0 -3
  85. package/web/dist/assets/JournalView-DQlDC-7i.js +0 -1
  86. package/web/dist/assets/Laws-T2wbwMmB.js +0 -3
  87. package/web/dist/assets/Library-t3KocV0-.js +0 -2
  88. package/web/dist/assets/Loops-6lNY-9uR.js +0 -2
  89. package/web/dist/assets/Markdown-DpmmtW2Y.js +0 -65
  90. package/web/dist/assets/Personal-xjoSqCzr.js +0 -2
  91. package/web/dist/assets/RailCats-BuJD4Jou.js +0 -1
  92. package/web/dist/assets/Tabs-DaExAgql.js +0 -1
  93. package/web/dist/assets/api-LvBC0CnK.js +0 -1
  94. package/web/dist/assets/index-DhNNxhfg.js +0 -3
  95. package/web/dist/assets/index-XTGBLKQr.css +0 -1
  96. package/web/dist/assets/react-DlYQp10C.js +0 -9
  97. package/web/dist/assets/rolldown-runtime-hePW80VL.js +0 -1
@@ -137,6 +137,71 @@ export const DONE_LIST = '.geneseed/done-checks.txt';
137
137
  export const SECRET_RE =
138
138
  /\b(?:AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{30,}|sk-ant-[A-Za-z0-9_-]{20,}|xox[abprs]-[0-9A-Za-z-]{10,})\b|-----BEGIN [A-Z ]*PRIVATE KEY-----/;
139
139
 
140
+ // ---- test-weakening twin: BEGIN — adapters/opencode/plugins/geneseed-context.js carries everything
141
+ // down to the END marker verbatim, with `export ` dropped (tests/plugins/context_done.test.mjs diffs the two).
142
+
143
+ /**
144
+ * A test file: a path segment `test`, `tests`, `__tests__` or `spec`, or a name `*.test.*`,
145
+ * `*.spec.*`, `*_test.*` or `test_*`. Give it a path relative to the repo, or an ancestor
146
+ * folder named `test` makes every file a test.
147
+ */
148
+ const TEST_PATH_RE = /(?:^|[\\/])(?:tests?|__tests__|spec)[\\/]|(?:^|[\\/])test_[^\\/]*$|\.(?:test|spec)\.[^\\/]*$|_test\.[^\\/]*$/;
149
+ export const isTestPath = (p) => TEST_PATH_RE.test(p);
150
+ // `\bxit`, or `process.exit(` reads as one; `(?<!mark)`, or `pytest.mark.skip(` counts twice.
151
+ const SKIP_MARKERS = [['.skip', /(?<!mark)\.skip\(/g], ['xit', /\bxit\(/g], ['xfail', /\bxfail\b/g],
152
+ ['@Disabled', /@Disabled\b/g], ['@Ignore', /@Ignore\b/g], ['pytest.mark.skip', /\bpytest\.mark\.skip/g],
153
+ ['t.Skip', /\bt\.Skip\(/g]];
154
+ const ASSERT_LINE_RE = /\bassert\w*!?\s*[.(]|\bexpect\s*\(|^assert\s/;
155
+ const COMMENT_LINE_RE = /^(?:\/\/|\/\*|\*|#)/;
156
+ // shortcut: only whole comment lines are dropped, so a marker in a string or a trailing comment, and
157
+ // any other `.skip(` (`stream().skip(1)`), still count. Upgrade by parsing the language; it is an advisory.
158
+ const code = (text) => text.split(/\r?\n/).filter((l) => !COMMENT_LINE_RE.test(l.trim())).join('\n');
159
+ // shortcut: a Set hides the loss of one of two identical lines, and `require.Equal`, `t.Errorf` and
160
+ // `.should` are not read as assertions. Upgrade by counting lines and widening `ASSERT_LINE_RE`.
161
+ const assertLines = (text) => new Set(text.split(/\r?\n/).map((l) => l.trim())
162
+ .filter((l) => ASSERT_LINE_RE.test(l) && !COMMENT_LINE_RE.test(l)));
163
+
164
+ /**
165
+ * What `pairs` of `[old, new]` text do to a test, as labels: a skip marker the new text has more
166
+ * of (`.skip added`), or an assertion line gone with none new in its place (`assertion removed`).
167
+ * A comment is no assertion, so commenting one out removes it. Cure the Cause's advisory half.
168
+ */
169
+ export function weakenedBy(pairs) {
170
+ const found = new Set();
171
+ for (const [before, after] of pairs) {
172
+ for (const [label, re] of SKIP_MARKERS) {
173
+ if ((code(after).match(re) || []).length > (code(before).match(re) || []).length) found.add(`${label} added`);
174
+ }
175
+ const was = assertLines(before);
176
+ const now = assertLines(after);
177
+ if ([...was].some((l) => !now.has(l)) && [...now].every((l) => was.has(l))) found.add('assertion removed');
178
+ }
179
+ return [...found];
180
+ }
181
+ // ---- test-weakening twin: END
182
+
183
+ // One Roo-style `apply_diff` block: its SEARCH half, then its REPLACE half.
184
+ export const DIFF_BLOCK_RE = /<<<<<<< SEARCH\r?\n(?::start_line:\s*\d+\r?\n)?(?:-------\r?\n)?([\s\S]*?)\r?\n?=======\r?\n([\s\S]*?)\r?\n?>>>>>>> REPLACE/g;
185
+
186
+ /**
187
+ * A write tool's input as `[old, new]` pairs for `weakenedBy`. `whole` is the file before a
188
+ * whole-file write, which the input does not carry. NotebookEdit's input names no old text either,
189
+ * so a cell that already held a marker reads as adding it.
190
+ */
191
+ export function editPairs(ti, whole = '') {
192
+ const text = (v) => (typeof v === 'string' ? v : '');
193
+ const pairs = [];
194
+ if (typeof ti.content === 'string') pairs.push([whole, ti.content]);
195
+ if (typeof ti.new_string === 'string') pairs.push([text(ti.old_string), ti.new_string]);
196
+ if (typeof ti.new_source === 'string') pairs.push(['', ti.new_source]);
197
+ if (typeof ti.replace === 'string') pairs.push([text(ti.search), ti.replace]);
198
+ for (const e of Array.isArray(ti.edits) ? ti.edits : []) {
199
+ if (e && typeof e.new_string === 'string') pairs.push([text(e.old_string), e.new_string]);
200
+ }
201
+ if (typeof ti.diff === 'string') for (const m of ti.diff.matchAll(DIFF_BLOCK_RE)) pairs.push([m[1], m[2]]);
202
+ return pairs;
203
+ }
204
+
140
205
  const OFF = ['off', '0', 'false', 'no'];
141
206
 
142
207
  /**
@@ -64,7 +64,9 @@ import {
64
64
  } from './hosts.mjs';
65
65
  import { currentBranch, gitRootOf, loopLaunched } from './gitref.mjs';
66
66
  import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
67
- import { selfAndParents, readStdin, SECRET_RE, DONE_LIST } from './hooks-prims.mjs';
67
+ import {
68
+ selfAndParents, readStdin, SECRET_RE, DONE_LIST, DIFF_BLOCK_RE, isTestPath, weakenedBy, editPairs,
69
+ } from './hooks-prims.mjs';
68
70
  import { recordUse } from './usage.mjs';
69
71
  import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
70
72
 
@@ -190,10 +192,20 @@ export function askDecision(reason) { return decisionDoc('ask', reason); }
190
192
  export function denyDecision(reason) { return decisionDoc('deny', reason); }
191
193
 
192
194
  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
195
  return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "${decision}", `
196
- + `"permissionDecisionReason": ${value}}}\n`;
196
+ + `"permissionDecisionReason": ${asciiJson(reason)}}}\n`;
197
+ }
198
+
199
+ const asciiJson = (s) => JSON.stringify(s)
200
+ .replace(/[\u007f-￿]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
201
+
202
+ /**
203
+ * A note to the MODEL that decides nothing: PreToolUse `additionalContext` with no
204
+ * `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
205
+ * `additionalContext`; not seen live, no gate here runs a model turn).
206
+ */
207
+ export function contextNote(text) {
208
+ return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": ${asciiJson(text)}}}\n`;
197
209
  }
198
210
 
199
211
  /**
@@ -488,6 +500,119 @@ const lossSegments = (s) => scanSegments(s).map((seg) => seg.match(SCAN_TOKEN_RE
488
500
  // (`rg "/mnt/c" README.md`) — never a root target; only an unquoted root is one.
489
501
  const rootArg = (t) => !/^["']/.test(t) && FS_ROOT_RE.test(t);
490
502
 
503
+ // ---- shell-write twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js carries everything down
504
+ // to the END marker verbatim, with `export ` dropped (tests/plugins/guard.test.mjs diffs the two).
505
+
506
+ // The cheap prefilter, a superset of what the parse acts on: a `>`, or one of the programs as a word.
507
+ const SHELL_WRITE_RE = />|(?:^|[\s;&|("'`\\/])(?:tee|sed|cp|mv|rm)(?:\.exe)?(?=[\s;&|)"'`]|$)/im;
508
+ // One pass over a segment: a quoted run (kept: its `>` is data), or a redirection with its optional
509
+ // fd, operator, `&` (a dup such as `2>&1`, which writes no file) and target word. `<` forms match
510
+ // too, so that their words never read as operands. A backslash is no escape here, as in
511
+ // `SCAN_SPLIT_RE`: `echo "say \"hi > f\""` closes its quote early, reads a target, and asks (on Bob, blocks).
512
+ const REDIRECT_RE = /"[^"]*"?|'[^']*'?|(?:(?<!\S)\d+|&)?(<<?<?-?|>>?)[ \t]*(&?)((?:[^\s"';|&<>()]|"[^"]*"?|'[^']*'?)*)/g;
513
+ const SHELL_CD = new Set(['cd', 'pushd', 'chdir', 'set-location', 'sl']);
514
+
515
+ /** `t` as an absolute path from `dir`, `~/…` as it stands, or null for what the shell rewrites. */
516
+ function writePath(dir, t) {
517
+ if (/[$`*?{}\0]/.test(t) || /^~[^\\/]/.test(t) || /^(?:\/dev\/|nul$)/i.test(t)) return null;
518
+ if (t[0] === '~') return t;
519
+ // A Git Bash `/c/…` path, as `resolveIn` reads it.
520
+ const q = process.platform === 'win32' ? t.replace(/^\/([a-zA-Z])(?=\/|$)/, '$1:') : t;
521
+ if (path.isAbsolute(q)) return path.resolve(q);
522
+ return dir ? path.resolve(dir, q) : null;
523
+ }
524
+
525
+ /** The files `sed` edits in place: none without `-i`; else its operands, past the script if inline. */
526
+ function sedFiles(args) {
527
+ const ops = [];
528
+ let inPlace = false; let script = false; let flags = true;
529
+ for (let i = 0; i < args.length; i += 1) {
530
+ const a = args[i];
531
+ if (flags && a === '--') flags = false;
532
+ else if (flags && /^--in-place(?:=|$)/.test(a)) inPlace = true;
533
+ else if (flags && (a === '--expression' || a === '--file')) { script = true; i += 1; }
534
+ else if (flags && /^--(?:expression|file)=/.test(a)) script = true;
535
+ else if (flags && /^-[a-zA-Z]*i/.test(a)) inPlace = true;
536
+ else if (flags && /^-[a-zA-Z]*[ef]$/.test(a)) { script = true; i += 1; }
537
+ else if (!flags || !a.startsWith('-') || a === '-') { if (a) ops.push(a); }
538
+ }
539
+ return inPlace ? ops.slice(script ? 0 : 1) : [];
540
+ }
541
+
542
+ /**
543
+ * The files `command` would write, as absolute paths: redirect targets (`>`, `>>`, `&>`), `tee`
544
+ * and `rm` operands, `sed -i` files, the destination of `cp` and `mv`, and the sources of `mv`, which
545
+ * it removes. A destination may be a folder, so `cp a tests/` also names `tests/a`. Read like
546
+ * `rootScan`: quotes, comments and heredoc bodies are data. A `cd` is followed; one it cannot read
547
+ * leaves later relative paths unseen. What it cannot read, it leaves out: this reader fails OPEN.
548
+ *
549
+ * shortcut: KNOWN UNSEEN FORMS, all of them still a write. An interpreter (inline code,
550
+ * `bash -c`, `eval`, `xargs`), a script or `npm run`, a `$(…)` or subshell trick, `>|`, a path with a
551
+ * variable, glob or brace in it, a wrapper with flags (`sudo -u x`) or outside `SCAN_WRAPPERS` (`env rm`,
552
+ * `nohup rm`, `timeout 5 rm`, `exec rm`), `echo x >& file` (read as a dup), a `popd` (not followed, so
553
+ * relative paths after a `pushd`/`popd` pair resolve from the wrong folder), `cp -t`, any other writer
554
+ * (`dd`, `ln`, `install`, `git mv`, `git checkout`, `Set-Content`), and a folder removed above a
555
+ * listed file (`rm -r tests` when only `tests/a.test.js` is listed). CI running the checks is the
556
+ * boundary that holds against those.
557
+ */
558
+ export function shellWriteTargets(command, cwd) {
559
+ if (!SHELL_WRITE_RE.test(command)) return [];
560
+ const found = new Set();
561
+ let dir = cwd;
562
+ const add = (t) => { const p = writePath(dir, t); if (p) found.add(p); };
563
+ const bare = (t) => t.replace(/["']/g, '');
564
+ for (const seg of scanSegments(command)) {
565
+ const outs = [];
566
+ const body = seg.replace(REDIRECT_RE, (m, op, dup, target) => {
567
+ if (op === undefined) return m;
568
+ if (op[0] === '>' && !dup && target) outs.push(bare(target));
569
+ return ' ';
570
+ });
571
+ let toks = stripStructure(body.match(SCAN_TOKEN_RE) || []);
572
+ while (toks.length && (/^\w+=/.test(toks[0]) || SCAN_WRAPPERS.has(bare(toks[0])))) toks = toks.slice(1);
573
+ const prog = toks.length ? bare(toks[0]).split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '') : '';
574
+ const args = toks.slice(1).map(bare);
575
+ const dashes = args.indexOf('--');
576
+ const ops = args.filter((a, i) => a && (a === '-' || !a.startsWith('-') || (dashes >= 0 && i > dashes)));
577
+ if (SHELL_CD.has(prog)) {
578
+ const to = ops.find((a) => !/^\/d$/i.test(a));
579
+ dir = to && to !== '-' ? writePath(dir, to) : null;
580
+ } else if (prog === 'rm' || prog === 'tee') ops.forEach(add);
581
+ else if (prog === 'sed') sedFiles(args).forEach(add);
582
+ else if ((prog === 'cp' || prog === 'mv') && ops.length > 1) {
583
+ const dest = ops[ops.length - 1];
584
+ const sources = ops.slice(0, -1);
585
+ add(dest);
586
+ for (const s of sources) {
587
+ add(`${dest.replace(/[\\/]+$/, '')}/${s.split(/[\\/]/).pop()}`);
588
+ if (prog === 'mv') add(s);
589
+ }
590
+ }
591
+ outs.forEach(add);
592
+ }
593
+ return [...found];
594
+ }
595
+ // ---- shell-write twin: END
596
+
597
+ /**
598
+ * External Gate over a shell command: the first write target that `externalGate` refuses, as the
599
+ * reason to ask, or null. Path check only, no secret scan of the command. Any throw is a pass, not
600
+ * `guardGate`'s `gate-error` ask: this reader fails open, and a hand-mangled path is not a gate failure.
601
+ */
602
+ function shellWriteReason(args, command, payload) {
603
+ try {
604
+ const base = (payload && typeof payload.cwd === 'string' && payload.cwd) || process.cwd();
605
+ // A Roo-lineage shell tool may name its own directory, as OpenCode's `workdir` does.
606
+ const own = payload && payload.tool_input && payload.tool_input.cwd;
607
+ const cwd = typeof own === 'string' && own ? path.resolve(base, own) : base;
608
+ for (const t of shellWriteTargets(command, cwd)) {
609
+ const why = externalGate(args, t, payload);
610
+ if (why) return why;
611
+ }
612
+ } catch { /* see above */ }
613
+ return null;
614
+ }
615
+
491
616
  function gitDecide(args, payload) {
492
617
  const command = ((payload && payload.tool_input) || {}).command;
493
618
  if (typeof command !== 'string') return 0;
@@ -521,6 +646,10 @@ function gitDecide(args, payload) {
521
646
  + 'share, for hours; | head stops nothing). Search a specific directory instead: the '
522
647
  + 'project, node_modules, ~/.npm, %APPDATA%.');
523
648
  }
649
+ // Also before `--no-consent`: rigor-5 is no part of the process pack. On Bob a hook-settings
650
+ // target cannot be replayed from a command (`bobSettingsChange`), so it blocks.
651
+ const shellWrite = shellWriteReason(args, command, payload);
652
+ if (shellWrite) return ask(args, 'git-gate', 'rigor-5', shellWrite);
524
653
  // `--no-consent`: the process pack (or process 5 alone) is off, so the commit/push ask has
525
654
  // no rule behind it — but Law IV above is universal and has already run. Checked before
526
655
  // `loopExempt` so a non-git command, or one with consent off, never pays for the whitelist.
@@ -585,8 +714,8 @@ export const SENSOR_LIST = '.geneseed/protected-checks.txt';
585
714
  * them, one repo-relative path per line (`#` comments), in `.geneseed/protected-checks.txt` at
586
715
  * its git root — found by walking up from the WRITE TARGET, not the cwd, so a session in one repo
587
716
  * 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.
717
+ * the path falls under, or null. A write tool's path reaches this through `ruleDecide`, a shell
718
+ * command's write targets through `shellWriteTargets`, whose docblock names what stays unseen.
590
719
  */
591
720
  function protectedCheck(p) {
592
721
  return protectedIn(path.resolve(p)) ?? protectedIn(resolvePath(p));
@@ -633,7 +762,7 @@ function protectedIn(target) {
633
762
  * guard holds these lists minus the hook settings and OpenCode's own files, which OpenCode asks about natively
634
763
  * (`opencodeEditAsks` in ./settings.mjs; tests/plugins/guard.test.mjs pins the difference). The CLI
635
764
  * (`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.
765
+ * not gated. Reached from a shell command too, with the same limit as `protectedCheck`.
637
766
  */
638
767
  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
768
  const GATE_CONFIG_MARKERS = ['.claude', '.openclaude', '.bob', '.opencode'];
@@ -690,7 +819,7 @@ function settingsAfter(before, payload) {
690
819
  return ranged ? null : once(before, ti.search, ti.replace);
691
820
  }
692
821
  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)];
822
+ const blocks = [...ti.diff.matchAll(DIFF_BLOCK_RE)];
694
823
  let text = before;
695
824
  for (const [, search, replace] of blocks) if ((text = once(text, search, replace)) === null) return null;
696
825
  // One block only: with several, Bob may apply some and refuse others (its start-line window).
@@ -731,6 +860,51 @@ function bobSettingsChange(p, payload) {
731
860
  return geneseedWiring(a) === geneseedWiring(b) ? null : 'it changes Geneseed\'s own hook entries';
732
861
  }
733
862
 
863
+ /**
864
+ * External Gate on one write target, by tool or by shell: why it must be asked about, or null.
865
+ * On Bob a hook-settings file is the user's shared host config, refused only when the write
866
+ * touches Geneseed's wiring (`bobSettingsChange`), and it never reads `opencode.json(c)`.
867
+ */
868
+ function externalGate(args, p, payload) {
869
+ const sensor = protectedCheck(p);
870
+ if (sensor) {
871
+ return `Geneseed (External Gate) — ${p} is a protected check (${sensor === DONE_LIST
872
+ ? 'the done gate list itself' : `${sensor}, listed in ${SENSOR_LIST}`}). A check the agent can `
873
+ + 'edit is not a check: fix the code, not the check, unless the user asks for this edit.';
874
+ }
875
+ if (HOST === 'bob' && /^opencode\.jsonc?$/i.test(path.basename(p))) return null;
876
+ if (!gateConfig(p, args.root)) return null;
877
+ const why = HOST === 'bob' && SETTINGS_RE.test(p) ? bobSettingsChange(p, payload) : '';
878
+ if (why === null) return null;
879
+ return `Geneseed (External Gate) — ${p} ${GATE_CONFIG_ASK}`
880
+ + (why ? ` On Bob this write is refused because ${why}.` : '');
881
+ }
882
+
883
+ /**
884
+ * Cure the Cause's edit-time half, ADVISORY: tells the agent that this write weakens a test (a skip
885
+ * marker added, an assertion dropped). The turn-end line is `doneGate`'s, read from the transcript.
886
+ * It only speaks, and it must not fail a write, so every error is silence. On Bob stdout is not
887
+ * read on PreToolUse, so the note is a stderr line, which also serves as its log line.
888
+ */
889
+ function testWeakenedNote(p, payload) {
890
+ try {
891
+ if (!isTestPath(p)) return;
892
+ const abs = path.resolve(typeof payload.cwd === 'string' ? payload.cwd : '.', p);
893
+ const root = gitRootOf(path.dirname(abs));
894
+ if (root && !isTestPath(path.relative(root, abs))) return;
895
+ let whole = '';
896
+ if (/write/i.test(String(payload.tool_name))) {
897
+ try { whole = readFileSync(abs, 'utf8'); } catch { /* a new file: nothing to weaken */ }
898
+ }
899
+ const hits = weakenedBy(editPairs(payload.tool_input, whole));
900
+ if (!hits.length) return;
901
+ const note = `Geneseed (Cure the Cause) — this edit weakens a test: ${p} (${hits.join(', ')}). `
902
+ + 'Fix the code, not the test. State this in your closing summary, with the reason.';
903
+ if (HOST === 'bob') err(`[geneseed] ${note}\n`);
904
+ else out(contextNote(note));
905
+ } catch { /* see above */ }
906
+ }
907
+
734
908
  function ruleGate(args) {
735
909
  if (sovereignBypass(args.root)) return 0;
736
910
  return ruleDecide(args, readPayload());
@@ -773,30 +947,17 @@ function ruleDecide(args, payload) {
773
947
  // shortcut: a write is told by its tool name, so a Bob write tool named outside WRITE_NAME_RE
774
948
  // passes both gates; switch to an allowlist of Bob's read tools if Bob adds or renames one.
775
949
  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
- }
950
+ const external = !bobRead && externalGate(args, p, payload);
951
+ if (external) return ask(args, 'rule-gate', 'rigor-5', external);
794
952
  const target = ruleGateTarget(p, args.root);
795
953
  if (!target) {
796
954
  // The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
797
955
  // `--no-ownership-gate`: the install switched it off (D25).
798
956
  const why = args.noOwnershipGate ? null : ownershipBlock(p, payload, body, args.root);
799
- return why ? deny(args, 'rule-gate', 'ownership', why) : 0;
957
+ if (why) return deny(args, 'rule-gate', 'ownership', why);
958
+ // Only here: stdout carries one document, and an ask or a deny above already holds it.
959
+ if (!bobRead) testWeakenedNote(p, payload);
960
+ return 0;
800
961
  }
801
962
  return ask(args, 'rule-gate', 'process-1', `Geneseed (Persist Insight) \u2014 writing to `
802
963
  + `${target}: a standing rule, or a fact to remember? That choice is the user's. ${PERSIST_ASK}`);
package/js/loop/state.mjs CHANGED
@@ -352,6 +352,12 @@ export function recordOutcome(state, bricks, outcome, { card = null, porcelain =
352
352
  if (brick.effect === 'mutate' && !state.validated) {
353
353
  throw new Error(`${from} modifies code: run \`geneseed loop score --declared\` before it, then record`);
354
354
  }
355
+ // `pass` is mechanical: a check that did not run is not a check that passed, whatever the model
356
+ // concluded. Only `test` writes this list, as `<check>: <status>`, so the word counts only where
357
+ // the status sits: right after a colon, markdown marks allowed, and not as a runner's count
358
+ // (`skipped: 0`, `: skipped 0`).
359
+ const skipped = from === 'test' && outcome === 'pass' ? note.split('\n').find((l) => /:[\s*`_]*skipped\b(?!\s*\d)/i.test(l)) : null;
360
+ if (skipped) throw new Error(`test cannot report pass with a skipped check (${skipped.trim()}): run it, or report fail or error`);
355
361
  const filteredPorcelain = porcelain === null ? null : filterPorcelain(porcelain);
356
362
  if (brick.effect === 'read' && filteredPorcelain !== null && filteredPorcelain !== state.snapshot) {
357
363
  return stop(state, `read-brick-wrote: ${from} changed the working tree`);
@@ -359,15 +365,19 @@ export function recordOutcome(state, bricks, outcome, { card = null, porcelain =
359
365
  if (filteredPorcelain !== null) state.snapshot = filteredPorcelain;
360
366
  if (card) state.card = card;
361
367
  if (from === 'test') state.tests = outcome;
362
- // A finding a brick needs to survive the unit (the ordered plan `plan` produced, `review`'s
363
- // `fail` findings) — pushed before the transition below, so it lands in `notes` even when
364
- // this call closes the unit, re-splits, or stops the loop. `notes` is never reset mid-run
365
- // (only `exhaust`'s own push and `decideAwaiting` add to it otherwise), so it survives
368
+ // A finding a brick needs to survive the unit (the ordered plan `plan` produced) — pushed before
369
+ // the transition below, so it lands in `notes` even when this call closes the unit, re-splits,
370
+ // or stops the loop. `notes` is never reset with the unit (only the two filters below trim it,
371
+ // and only `exhaust`'s own push and `decideAwaiting` add to it otherwise), so it survives
366
372
  // `resetUnit`/`finishUnit` — which a card does not: `resetUnit` clears it.
367
373
  // A fresh verdict: `test`'s latest report supersedes its earlier ones, so a repair never reads
368
374
  // findings about code that has since changed (stale traces broke 34 of 135 correct attempts
369
- // in arXiv 2607.24604, fresh ones 4). Every other brick's notes are a record and are kept.
375
+ // in arXiv 2607.24604, fresh ones 4). `review`'s and `mutation-check`'s findings go once `apply`
376
+ // has acted on them: it reads them through `next`, so they leave when it records, never when it
377
+ // is entered.
378
+ // Every other brick's notes are a record and are kept.
370
379
  if (from === 'test') state.notes = state.notes.filter((n) => !/^iteration \d+ \(test\): /.test(n));
380
+ if (from === 'apply') state.notes = state.notes.filter((n) => !/^iteration \d+ \((review|mutation-check)\): /.test(n));
371
381
  if (note) state.notes.push(`iteration ${state.iteration} (${from}): ${note}`);
372
382
  state.visited.push(from);
373
383
 
@@ -145,10 +145,10 @@ function bodyKits(body) {
145
145
  }
146
146
 
147
147
  /**
148
- * The gate switches across the trust boundary (`deletionGate`, `secretsGate`, `doneGate`), each
149
- * on its own: only a real JSON boolean counts. Anything else — a string `"false"`, a number,
150
- * absence — falls back to the install's own answer for THAT gate, so a malformed or partial body
151
- * can never disarm (or re-arm) a gate it did not name.
148
+ * The gate switches across the trust boundary (`deletionGate`, `secretsGate`, `doneGate`,
149
+ * `ownershipGate`), each on its own: only a real JSON boolean counts. Anything else — a string
150
+ * `"false"`, a number, absence — falls back to the install's own answer for THAT gate, so a
151
+ * malformed or partial body can never disarm (or re-arm) a gate it did not name.
152
152
  */
153
153
  function bodyGates(body, root, host) {
154
154
  const own = gatesOfDir(root, host);
@@ -177,7 +177,8 @@ function bodyAxes(body, dflt) {
177
177
 
178
178
  /**
179
179
  * The DETECTED install a body's (host, path) pair names — `[host, scope, root]` — or a
180
- * `NotFound`. THE ALLOWLIST three endpoints share (view select, rebuild, deactivate/remove), and
180
+ * `NotFound`. THE ALLOWLIST every install-naming endpoint shares (a per-request install, rebuild,
181
+ * deactivate/remove), and
181
182
  * one copy of it: two copies of a security check drift, and the copy that drifts is the one
182
183
  * nobody re-read.
183
184
  *
@@ -195,8 +196,7 @@ function detectedInstall(body) {
195
196
 
196
197
  /**
197
198
  * The state a request reads: the install its `{host, path}` names, or `base` (the daemon's
198
- * own, the topbar selector's view) when it names neither — so a client that sends no install
199
- * keeps today's answers.
199
+ * own, on the default install, `defaultView`) when it names neither.
200
200
  *
201
201
  * NAMING ONE IS AN ALLOWLIST LOOKUP, EVERY TIME: `detectedInstall` runs on a cache hit too, so
202
202
  * a half pair, an unknown pair or an install removed since is a `NotFound` (404), never a fall
@@ -207,7 +207,15 @@ function detectedInstall(body) {
207
207
  */
208
208
  export function installView(base, sel) {
209
209
  if (bget(sel, 'host') == null && bget(sel, 'path') == null) return base;
210
- const [host, scope, root] = detectedInstall(sel);
210
+ return targetView(base, detectedInstall(sel));
211
+ }
212
+
213
+ /**
214
+ * The cached view of one `[host, scope, root]` that `installTargets()` yielded — the allowlist
215
+ * already passed, so a caller holding a whole scan (the Library's fleet, `routes.mjs`) makes no
216
+ * second scan per install. Never call it with a pair a request supplied: that is `installView`.
217
+ */
218
+ export function targetView(base, [host, scope, root]) {
211
219
  const key = JSON.stringify([host, String(root)]);
212
220
  let v = base._views.get(key);
213
221
  if (v === undefined) {
@@ -472,24 +480,6 @@ export function mcpTargetPaths() {
472
480
  return known;
473
481
  }
474
482
 
475
- // ---- the harness selector ------------------------------------------------------------------
476
-
477
- /**
478
- * Re-point the whole console at a detected install.
479
- *
480
- * The (host, path) PAIR must be one of the detected targets, and the ROOT is threaded through
481
- * beside the data dir: markers and sigils live at the install root, not in the data dir, and
482
- * without it a claude/bob PROJECT view mis-detects as opencode/neutral.
483
- *
484
- * The pair is SERIALISED into the key rather than concatenated with a separator: the path
485
- * comes straight out of a request body, and any separator it could contain would let one
486
- * pair impersonate another in a lookup whose whole job is to be an allowlist.
487
- */
488
- export function apiSelectView(state, body) {
489
- const [host, scope, root] = detectedInstall(body);
490
- state.selectView(viewCfg(host, scope, root), root);
491
- return { ok: true, target: state.target, theme: state.theme, emit: state.emit };
492
- }
493
483
 
494
484
  // ---- restore, and the two build-command resolvers ---------------------------------------
495
485
 
@@ -706,7 +696,7 @@ const EMIT_FOR = new Map([
706
696
  * already-active one (an in-place re-emit, the same command either way).
707
697
  *
708
698
  * The (host, path) pair MUST be one of the detected targets — the same allowlist
709
- * `apiSelectView` uses, and the reason the target is never built from raw body input — and
699
+ * `installView` uses, and the reason the target is never built from raw body input — and
710
700
  * it must not be `disabled` (reactivate first). Every other field follows the same rule: a
711
701
  * VALID picked value wins, else the install's own, so a re-theme never silently flips the
712
702
  * footprint, the register or the mode, and a bogus body value cannot reach the argv.