geneseed 5.2.0 → 5.3.1
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.
- package/CHANGELOG.md +54 -0
- package/README.md +4 -4
- package/SHIPPED.md +1 -1
- package/adapters/bob/README.md +31 -18
- package/adapters/claude-code/README.md +27 -22
- package/adapters/openclaude/README.md +18 -8
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +8 -3
- package/adapters/opencode/plugins/geneseed-activity.js +20 -21
- package/adapters/opencode/plugins/geneseed-context.js +224 -71
- package/adapters/opencode/plugins/geneseed-guard.js +420 -203
- package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
- package/adapters/opencode/workflows/_runtime.js +3 -2
- package/bin/geneseed-cli.mjs +61 -16
- package/bin/geneseed-hook.mjs +94 -12
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +2 -2
- package/docs/concepts/factories.md +40 -6
- package/docs/concepts/footprint.md +11 -1
- package/docs/concepts/foreman-mode.md +2 -2
- package/docs/concepts/hook-gates.md +3 -3
- package/docs/concepts/host-matrix.md +22 -4
- package/docs/concepts/loop-gates.md +1 -1
- package/docs/concepts/loops.md +2 -2
- package/docs/concepts/shared-tier.md +1 -1
- package/docs/design-history.md +148 -0
- package/docs/extending.md +97 -163
- package/docs/guides/install-bob.md +2 -2
- package/docs/guides/install-openclaude.md +1 -1
- package/docs/guides/run-a-factory.md +15 -2
- package/docs/guides/upgrade.md +2 -2
- package/docs/guides/verify.md +12 -0
- package/docs/reference/environment.md +1 -0
- package/docs/reference/factory-actions.md +6 -5
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/reference/troubleshoot-update.md +1 -1
- package/docs/token-footprint.md +66 -2
- package/docs/understand/design-choices-hosts.md +1 -1
- package/docs/understand/design-choices-shape.md +1 -0
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-bob.md +1 -1
- package/docs/web-ui.md +21 -3
- package/harness.config.json +1 -1
- package/js/README.md +7 -5
- package/js/build/args.mjs +4 -4
- package/js/build/driver.mjs +1 -1
- package/js/build/emit-claude.mjs +1 -1
- package/js/build/generate.mjs +5 -14
- package/js/build/render.mjs +44 -24
- package/js/cli-table.json +135 -59
- package/js/factory/cli.mjs +24 -5
- package/js/factory/graph.mjs +13 -9
- package/js/factory/metrics.mjs +93 -0
- package/js/factory/registry.mjs +37 -12
- package/js/factory/state.mjs +25 -6
- package/js/hosts/done-checks.mjs +6 -0
- package/js/hosts/geneseed-dir.mjs +3 -2
- package/js/hosts/gitref.mjs +5 -3
- package/js/hosts/hook-tap.mjs +104 -0
- package/js/hosts/hooks-context.mjs +30 -3
- package/js/hosts/hooks-learn.mjs +47 -16
- package/js/hosts/hooks-prims.mjs +52 -3
- package/js/hosts/hooks.mjs +69 -42
- package/js/hosts/hosts.mjs +80 -12
- package/js/hosts/installs.mjs +7 -0
- package/js/hosts/loss.mjs +6 -1
- package/js/hosts/native.mjs +14 -5
- package/js/hosts/owned.mjs +7 -6
- package/js/hosts/ownership-gate.mjs +14 -1
- package/js/hosts/settings.mjs +245 -103
- package/js/hosts/shim.mjs +4 -4
- package/js/hosts/usage.mjs +9 -3
- package/js/inspect/checks-probe.mjs +66 -5
- package/js/inspect/checks-repo.mjs +196 -2
- package/js/inspect/cost.mjs +34 -2
- package/js/inspect/diff.mjs +16 -1
- package/js/inspect/doctor.mjs +13 -4
- package/js/inspect/excludes.mjs +18 -6
- package/js/inspect/status.mjs +35 -7
- package/js/inspect/validate.mjs +44 -21
- package/js/lib/machine-dir.mjs +1 -1
- package/js/lib/node-floor.mjs +46 -6
- package/js/maintain/uninstall.mjs +70 -17
- package/js/maintain/update.mjs +31 -7
- package/js/ui/cli.mjs +34 -4
- package/js/ui/menu.mjs +1 -1
- package/js/ui/tui.mjs +11 -14
- package/js/web/actions.mjs +3 -9
- package/js/web/api.mjs +28 -10
- package/js/web/daemon.mjs +0 -1
- package/js/web/server.mjs +1 -0
- package/js/web/state.mjs +37 -16
- package/package.json +1 -1
- package/src/AGENT.md.tmpl +23 -17
- package/src/agents/_template.md +1 -1
- package/src/agents/advocate.md +1 -1
- package/src/agents/developer.md +12 -3
- package/src/agents/empiricist.md +1 -1
- package/src/agents/framer.md +1 -1
- package/src/agents/historian.md +1 -1
- package/src/agents/operator.md +1 -1
- package/src/agents/pragmatist.md +1 -1
- package/src/agents/researcher.md +1 -1
- package/src/agents/skeptic.md +1 -1
- package/src/agents/steward.md +1 -1
- package/src/agents/user-advocate.md +1 -1
- package/src/agents/visionary.md +1 -1
- package/src/bricks/intake.md +10 -3
- package/src/bricks/retro.md +13 -3
- package/src/doctrines/comms.md +1 -1
- package/src/doctrines/ops.md +1 -1
- package/src/doctrines/process.md +7 -5
- package/src/factories/analysis-to-build.json +1 -0
- package/src/factories/bug-report-to-fix.json +1 -0
- package/src/factories/issue-to-pr.json +1 -0
- package/src/laws/universal.md +2 -2
- package/src/modes/foreman.md +8 -14
- package/src/skills/commit.md +7 -2
- package/src/skills/debug.md +1 -1
- package/src/skills/diagram-design/SKILL.md +1 -1
- package/src/skills/diagram-design/VENDOR.md +3 -1
- package/src/skills/factory-forge.md +5 -3
- package/src/skills/factory.md +22 -1
- package/src/skills/geneseed.md +1 -1
- package/src/skills/handoff.md +1 -1
- package/src/skills/parallel-agents.md +1 -1
- package/src/skills/pipeline.md +6 -6
- package/src/skills/plan.md +7 -3
- package/src/skills/spring-testing.md +1 -1
- package/themes/biker.json +78 -78
- package/themes/commentator.json +81 -81
- package/themes/cyberpunk.json +79 -79
- package/themes/gamer.json +77 -77
- package/themes/imperial.json +82 -82
- package/themes/joker.json +79 -79
- package/themes/marvin.json +82 -82
- package/themes/mean.json +82 -82
- package/themes/military.json +78 -78
- package/themes/neutral.json +78 -78
- package/themes/pirate.json +79 -79
- package/themes/sports.json +79 -79
- package/themes/verstappen.json +78 -78
- package/themes/wizard.json +79 -79
- package/web/dist/assets/ActiveLoops-BJJN3P-V.js +1 -0
- package/web/dist/assets/Activity-WQ3ykgxU.js +1 -0
- package/web/dist/assets/ActivityDetail-7rt04SkS.js +1 -0
- package/web/dist/assets/{Bonsai-DSwUbavu.js → Bonsai-BBl4XXqs.js} +1 -1
- package/web/dist/assets/{CopyButton-BzRQz7k2.js → CopyButton-Beven8yn.js} +1 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +2 -0
- package/web/dist/assets/Docs-B5aHp86J.js +5 -0
- package/web/dist/assets/Factories-BjqzXAw8.js +1 -0
- package/web/dist/assets/GreenhouseView-Bce212qd.js +1 -0
- package/web/dist/assets/Installs-B1OsrHXF.js +3 -0
- package/web/dist/assets/JournalView-CV4omyww.js +1 -0
- package/web/dist/assets/Kits-CW1e7xNa.js +1 -0
- package/web/dist/assets/Laws-1Ckf1lbs.js +4 -0
- package/web/dist/assets/LibRows-Dag1s0ZX.js +1 -0
- package/web/dist/assets/Library-B3FuFLel.js +3 -0
- package/web/dist/assets/Loops-CwqgnLNw.js +2 -0
- package/web/dist/assets/Markdown-CxkA7940.js +71 -0
- package/web/dist/assets/OperatorHudView-JmYY1pBR.js +1 -0
- package/web/dist/assets/Personal-DKLgLa7Z.js +2 -0
- package/web/dist/assets/Settings-BwErnh-R.js +1 -0
- package/web/dist/assets/Tabs-8zsyEPSK.js +1 -0
- package/web/dist/assets/index-CRWqKxfY.css +1 -0
- package/web/dist/assets/index-Ce6qF2nG.js +6 -0
- package/web/dist/assets/usePoll-D5c_qIFZ.js +1 -0
- package/web/dist/index.html +2 -2
- package/adapters/claude-code/settings.json +0 -52
- package/web/dist/assets/ActiveLoops-BTHIaRhn.js +0 -1
- package/web/dist/assets/Activity-DlQ30znB.js +0 -1
- package/web/dist/assets/ActivityDetail-CG0mn5fW.js +0 -1
- package/web/dist/assets/Dashboard-Ce3UOsxJ.js +0 -2
- package/web/dist/assets/Docs-CisVnYqv.js +0 -5
- package/web/dist/assets/Factories-Dq5oW4CU.js +0 -1
- package/web/dist/assets/GreenhouseView-y9WAfcc_.js +0 -1
- package/web/dist/assets/Installs-m4GElwFW.js +0 -3
- package/web/dist/assets/JournalView-DeBLRNGc.js +0 -1
- package/web/dist/assets/Kits-DJYVAnyE.js +0 -1
- package/web/dist/assets/Laws-CNpc_8ZV.js +0 -4
- package/web/dist/assets/LibRows-RO5bvXth.js +0 -1
- package/web/dist/assets/Library-Dg0ScciC.js +0 -3
- package/web/dist/assets/Loops-CjEdo-NG.js +0 -2
- package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
- package/web/dist/assets/OperatorHudView-2ujVMjq1.js +0 -1
- package/web/dist/assets/Personal-D0yS7ahT.js +0 -2
- package/web/dist/assets/Settings-DEN0U8QI.js +0 -1
- package/web/dist/assets/Tabs-But5R6_r.js +0 -1
- package/web/dist/assets/index-Ck42AbRX.js +0 -6
- package/web/dist/assets/index-PG_ukkh6.css +0 -1
- package/web/dist/assets/usePoll-o8ul-Sog.js +0 -1
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -182,8 +182,37 @@ export function weakenedBy(pairs) {
|
|
|
182
182
|
}
|
|
183
183
|
// ---- test-weakening twin: END
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
/**
|
|
186
|
+
* The Roo-style `apply_diff` blocks of `diff` as `[search, replace]` pairs: what
|
|
187
|
+
* `/<<<<<<< SEARCH\r?\n(?::start_line:\s*\d+\r?\n)?(?:-------\r?\n)?([\s\S]*?)\r?\n?=======\r?\n([\s\S]*?)\r?\n?>>>>>>> REPLACE/g`
|
|
188
|
+
* matched, read in one pass. That regex, on blocks opened and never closed, retried every later
|
|
189
|
+
* separator from every opening: 32 KB took 4.7 s and 256 KB ran past 120 s, past Bob's hook
|
|
190
|
+
* timeout, so the secrets gate never judged the call. Each half ends at the FIRST separator after
|
|
191
|
+
* it, as the lazy groups did; a block with no closing after its first separator has none after any
|
|
192
|
+
* later one either, so the scan stops there, where the regex would have found nothing more.
|
|
193
|
+
*/
|
|
194
|
+
export function diffBlocks(diff) {
|
|
195
|
+
const at = (re, from) => { re.lastIndex = from; return re.exec(diff); };
|
|
196
|
+
const OPEN = /<<<<<<< SEARCH\r?\n/g;
|
|
197
|
+
const LINE = /:start_line:\s*\d+\r?\n/y;
|
|
198
|
+
const DASH = /-------\r?\n/y;
|
|
199
|
+
const SEP = /\r?\n?=======\r?\n/g;
|
|
200
|
+
const CLOSE = /\r?\n?>>>>>>> REPLACE/g;
|
|
201
|
+
const pairs = [];
|
|
202
|
+
for (let pos = 0, open; (open = at(OPEN, pos));) {
|
|
203
|
+
let start = open.index + open[0].length;
|
|
204
|
+
const line = at(LINE, start);
|
|
205
|
+
if (line) start += line[0].length;
|
|
206
|
+
const dash = at(DASH, start);
|
|
207
|
+
if (dash) start += dash[0].length;
|
|
208
|
+
const sep = at(SEP, start);
|
|
209
|
+
const close = sep && at(CLOSE, sep.index + sep[0].length);
|
|
210
|
+
if (!close) break;
|
|
211
|
+
pairs.push([diff.slice(start, sep.index), diff.slice(sep.index + sep[0].length, close.index)]);
|
|
212
|
+
pos = close.index + close[0].length;
|
|
213
|
+
}
|
|
214
|
+
return pairs;
|
|
215
|
+
}
|
|
187
216
|
|
|
188
217
|
/**
|
|
189
218
|
* A write tool's input as `[old, new]` pairs for `weakenedBy`. `whole` is the file before a
|
|
@@ -200,7 +229,7 @@ export function editPairs(ti, whole = '') {
|
|
|
200
229
|
for (const e of Array.isArray(ti.edits) ? ti.edits : []) {
|
|
201
230
|
if (e && typeof e.new_string === 'string') pairs.push([text(e.old_string), e.new_string]);
|
|
202
231
|
}
|
|
203
|
-
if (typeof ti.diff === 'string')
|
|
232
|
+
if (typeof ti.diff === 'string') pairs.push(...diffBlocks(ti.diff));
|
|
204
233
|
return pairs;
|
|
205
234
|
}
|
|
206
235
|
|
|
@@ -474,6 +503,26 @@ export function gateLoss(reason) {
|
|
|
474
503
|
}
|
|
475
504
|
// ---- gate text twin: END
|
|
476
505
|
|
|
506
|
+
/**
|
|
507
|
+
* The `permissionDecision: "ask"` document, in Python's compact `json.dumps` spelling: `, ` and
|
|
508
|
+
* `: ` separators, and `ensure_ascii` — every code unit past `~` as a lowercase `\uXXXX`, which is
|
|
509
|
+
* why a reason's em dash reaches stdout as `—`.
|
|
510
|
+
*
|
|
511
|
+
* A TEMPLATE, NOT `js/lib/json.mjs`'s `jsonDumpsCompact`. The keys are fixed and the one value
|
|
512
|
+
* is a string, so the general serializer bought nothing here — and it cost every tool call a
|
|
513
|
+
* 378-line module parse, being the only thing on the gate path that needed it.
|
|
514
|
+
* `tests/unit/hook_gates.test.mjs` holds the two byte-identical over non-ASCII reasons.
|
|
515
|
+
*/
|
|
516
|
+
export function askDecision(reason) { return decisionDoc('ask', reason); }
|
|
517
|
+
|
|
518
|
+
export function decisionDoc(decision, reason) {
|
|
519
|
+
return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "${decision}", `
|
|
520
|
+
+ `"permissionDecisionReason": ${asciiJson(reason)}}}\n`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export const asciiJson = (s) => JSON.stringify(s)
|
|
524
|
+
.replace(/[\u007f-]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
525
|
+
|
|
477
526
|
const OFF = ['off', '0', 'false', 'no'];
|
|
478
527
|
|
|
479
528
|
/**
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* (the default) reads `hookSpecificOutput.permissionDecision: "ask"` and shows the user a
|
|
13
13
|
* prompt; the one `"deny"` (the ownership first-write gate, `./ownership-gate.mjs`) carries
|
|
14
14
|
* its reason to the MODEL instead. `--host bob` is Bob's own protocol: PreToolUse ignores stdout and refuses only on
|
|
15
|
-
* EXIT CODE 2, so `BLOCK_RULES` (
|
|
15
|
+
* EXIT CODE 2, so the rules in `BLOCK_RULES` (below) exit 2 with the reason on stderr,
|
|
16
16
|
* as does the ownership gate (through `deny`, with a one-time tail in place of `BOB_FINAL`),
|
|
17
17
|
* and the rest is a stderr line with exit 0; SessionStart context is plain stdout, as on
|
|
18
18
|
* Claude. `--host openclaude` speaks Claude's dialect verbatim (OpenClaude is a Claude Code
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
* THE CONTRACT EVERY VERB HOLDS. Exit 0 on every path, and signal through stdout. A hook
|
|
43
43
|
* that fails is a tool call that fails, so an unreadable payload, a missing file, a
|
|
44
44
|
* malformed user config and a bypass all end the same way: quietly, with 0. The single
|
|
45
|
-
* exception is `learn
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* exception is `learn` run BY HAND, which returns the model CLI's own exit code so a script can
|
|
46
|
+
* test it. On a hook call `learn` returns 0 like every other verb — exit 2 on Stop or PreCompact
|
|
47
|
+
* would block the turn's end — and an auth or quota failure is diagnosable from its stderr.
|
|
48
48
|
*
|
|
49
49
|
* The gate is `tests/helpers/cli_golden.mjs` replaying `tests/helpers/matrix/cli.{posix,win32}.json`:
|
|
50
50
|
* each verb run in a seeded sandbox, with ABSOLUTE assertions on stdout, stderr, the exit code
|
|
@@ -59,7 +59,7 @@ import { machineDir } from '../lib/machine-dir.mjs';
|
|
|
59
59
|
import { markerLines } from '../lib/managed-block.mjs';
|
|
60
60
|
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
61
61
|
import {
|
|
62
|
-
GATE_LEDGER, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
|
|
62
|
+
GATE_LEDGER, HOSTS, carrierBlock, carrierName, globalHookStandingDown, hookProjectDir, isSharedCarrier,
|
|
63
63
|
resolvePath, sovereignBypass,
|
|
64
64
|
} from './hosts.mjs';
|
|
65
65
|
import {
|
|
@@ -67,8 +67,8 @@ import {
|
|
|
67
67
|
} from './gitref.mjs';
|
|
68
68
|
import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
|
|
69
69
|
import {
|
|
70
|
-
readStdin, SECRET_RE, DONE_LIST,
|
|
71
|
-
gateLoss, gateSafe,
|
|
70
|
+
readStdin, SECRET_RE, DONE_LIST, diffBlocks, isTestPath, weakenedBy, editPairs,
|
|
71
|
+
gateLoss, gateSafe, askDecision, decisionDoc, asciiJson,
|
|
72
72
|
} from './hooks-prims.mjs';
|
|
73
73
|
import { recordUse } from './usage.mjs';
|
|
74
74
|
import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
|
|
@@ -81,7 +81,20 @@ import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
|
|
|
81
81
|
// (`git add . && git commit … && git push`) and `-C <path>` forms, so a compound
|
|
82
82
|
// one-liner can never slip a commit past the prompt. `[^\n]*` is the boundary: a `git` on
|
|
83
83
|
// one line and a `commit` on the next are two commands, not one.
|
|
84
|
-
|
|
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;
|
|
85
98
|
|
|
86
99
|
// Law IV's boundary half lives in `./loss.mjs`: it asks only when a command would really lose
|
|
87
100
|
// data — a protected branch deleted or force-pushed, an unpushed unmerged branch deleted,
|
|
@@ -241,17 +254,8 @@ export function worktreeExempt(command, cwd, agentId) {
|
|
|
241
254
|
}
|
|
242
255
|
}
|
|
243
256
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
* `: ` separators, and `ensure_ascii` — every code unit past `~` as a lowercase `\uXXXX`, which is
|
|
247
|
-
* why a reason's em dash reaches stdout as `—`.
|
|
248
|
-
*
|
|
249
|
-
* A TEMPLATE, NOT `js/lib/json.mjs`'s `jsonDumpsCompact`. The keys are fixed and the one value
|
|
250
|
-
* is a string, so the general serializer bought nothing here — and it cost every tool call a
|
|
251
|
-
* 378-line module parse, being the only thing on the gate path that needed it.
|
|
252
|
-
* `tests/unit/hook_gates.test.mjs` holds the two byte-identical over non-ASCII reasons.
|
|
253
|
-
*/
|
|
254
|
-
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 };
|
|
255
259
|
|
|
256
260
|
/**
|
|
257
261
|
* The `permissionDecision: "deny"` twin of `askDecision`, same spelling. Claude Code shows an
|
|
@@ -261,14 +265,6 @@ export function askDecision(reason) { return decisionDoc('ask', reason); }
|
|
|
261
265
|
*/
|
|
262
266
|
export function denyDecision(reason) { return decisionDoc('deny', reason); }
|
|
263
267
|
|
|
264
|
-
function decisionDoc(decision, reason) {
|
|
265
|
-
return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "${decision}", `
|
|
266
|
-
+ `"permissionDecisionReason": ${asciiJson(reason)}}}\n`;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const asciiJson = (s) => JSON.stringify(s)
|
|
270
|
-
.replace(/[\u007f-]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
271
|
-
|
|
272
268
|
/**
|
|
273
269
|
* A note to the MODEL that decides nothing: PreToolUse `additionalContext` with no
|
|
274
270
|
* `permissionDecision` defers, and the host puts the text next to the tool result (hooks.md,
|
|
@@ -308,7 +304,7 @@ const BOB_FINAL = ' Bob has no approval step for this gate: neither a confirmati
|
|
|
308
304
|
* credential in a tracked file and a history-discarding git act are wrong in every context,
|
|
309
305
|
* so refusing them costs nothing. rigor-5 (External Gate) joins them: a protected check the
|
|
310
306
|
* agent can edit is not a check, so it is as unconditional as the two Laws — NOT "Laws I/IV
|
|
311
|
-
* only"
|
|
307
|
+
* only". process-1 too (owner decision, 2026-11): with no prompt, a warning
|
|
312
308
|
* let the agent write the user's rules on its own say. Memory is written freely (owner decision,
|
|
313
309
|
* 2026-11-08), so a memory write reaches no rule here. Process 5 is the USER's call
|
|
314
310
|
* as well, but a hard block would make Bob unable to commit at all, so it stays a warning the
|
|
@@ -901,9 +897,16 @@ function consentBenign(command) {
|
|
|
901
897
|
return true;
|
|
902
898
|
}
|
|
903
899
|
|
|
904
|
-
|
|
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) {
|
|
905
903
|
const ti = (payload && payload.tool_input) || {};
|
|
906
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
|
+
}
|
|
907
910
|
const tool = payload && payload.tool_name;
|
|
908
911
|
const command = shellReading(ti.command, tool === 'Bash' ? 'bash' : tool === 'PowerShell' ? 'powershell' : null);
|
|
909
912
|
// The agent's own words, for the asks where they are no conflict of interest (`gateText`'s `quote`).
|
|
@@ -1119,7 +1122,9 @@ function protectedIn(target) {
|
|
|
1119
1122
|
* not gated. Reached from a shell command too, with the same limit as `protectedCheck`.
|
|
1120
1123
|
*/
|
|
1121
1124
|
const GATE_CONFIG_FILES = ['settings.json', 'settings.local.json', 'settings/settings.json', 'rules/geneseed.md', 'excludes.json', 'AGENT.md', '.geneseed-manifest.json', '.geneseed-emit', 'opencode.json', 'opencode.jsonc'];
|
|
1122
|
-
|
|
1125
|
+
// Every host's project dir, read from the host table so a new host's settings are gate
|
|
1126
|
+
// configuration the day it gets a row. Exported for the tests that write the list out.
|
|
1127
|
+
export const GATE_CONFIG_MARKERS = HOSTS.map((h) => h.projectMarker);
|
|
1123
1128
|
function gateConfig(p, root) {
|
|
1124
1129
|
let bin = null;
|
|
1125
1130
|
try {
|
|
@@ -1173,9 +1178,9 @@ function settingsAfter(before, payload) {
|
|
|
1173
1178
|
return ranged ? null : replaceOnce(before, ti.search, ti.replace);
|
|
1174
1179
|
}
|
|
1175
1180
|
if (tool === 'apply_diff' && typeof ti.diff === 'string') {
|
|
1176
|
-
const blocks =
|
|
1181
|
+
const blocks = diffBlocks(ti.diff);
|
|
1177
1182
|
let text = before;
|
|
1178
|
-
for (const [
|
|
1183
|
+
for (const [search, replace] of blocks) if ((text = replaceOnce(text, search, replace)) === null) return null;
|
|
1179
1184
|
// One block only: with several, Bob may apply some and refuse others (its start-line window).
|
|
1180
1185
|
return blocks.length === 1 ? text : null;
|
|
1181
1186
|
}
|
|
@@ -1230,8 +1235,8 @@ const ASK_COUNT_MAX = 1024 * 1024;
|
|
|
1230
1235
|
* The `editPairs` of a write the gate will ask about, for the line count, or undefined for none. Run
|
|
1231
1236
|
* only then, because `Write`'s old text is a file read. A pair says nothing of how often it applies,
|
|
1232
1237
|
* so a `replace_all` and a `search_and_replace` count nothing, and a notebook cell names no old text.
|
|
1233
|
-
* A `diff` counts nothing either: the agent writes it, and `
|
|
1234
|
-
* opened blocks. A count must cost no verdict, so whatever is not a small regular file, or cannot be
|
|
1238
|
+
* A `diff` counts nothing either: the agent writes it, and the regex `diffBlocks` replaced took 20 s
|
|
1239
|
+
* on 80 KB of opened blocks. A count must cost no verdict, so whatever is not a small regular file, or cannot be
|
|
1235
1240
|
* read, counts nothing. Only a file that is truly absent is a new file.
|
|
1236
1241
|
*/
|
|
1237
1242
|
function askPairs(payload, p) {
|
|
@@ -1336,28 +1341,46 @@ function ruleGate(args) {
|
|
|
1336
1341
|
|
|
1337
1342
|
// The REPLACE halves of a Roo-style `apply_diff` (`<<<<<<< SEARCH … ======= <new> >>>>>>> REPLACE`).
|
|
1338
1343
|
// A diff without those markers is a shape we do not know, so it is returned whole: fail closed.
|
|
1344
|
+
// One pass: each half runs from a separator line to the FIRST closing line after it, as the lazy
|
|
1345
|
+
// `/^=======\r?\n([\s\S]*?)^>>>>>>> REPLACE/gm` did, and a separator with no closing after it ends
|
|
1346
|
+
// the scan, where that regex rescanned the rest of the diff once per separator.
|
|
1339
1347
|
function diffReplaced(diff) {
|
|
1340
1348
|
if (typeof diff !== 'string') return diff;
|
|
1341
|
-
const
|
|
1349
|
+
const SEP = /^=======\r?\n/gm;
|
|
1350
|
+
const CLOSE = /^>>>>>>> REPLACE/gm;
|
|
1351
|
+
const halves = [];
|
|
1352
|
+
for (let sep; (sep = SEP.exec(diff));) {
|
|
1353
|
+
CLOSE.lastIndex = sep.index + sep[0].length;
|
|
1354
|
+
const close = CLOSE.exec(diff);
|
|
1355
|
+
if (!close) break;
|
|
1356
|
+
halves.push(diff.slice(sep.index + sep[0].length, close.index));
|
|
1357
|
+
SEP.lastIndex = CLOSE.lastIndex;
|
|
1358
|
+
}
|
|
1342
1359
|
return halves.length ? halves.join('\n') : diff;
|
|
1343
1360
|
}
|
|
1344
1361
|
|
|
1345
1362
|
const RULE_PATH_KEYS = ['file_path', 'path', 'notebook_path', 'target_file', 'target', 'file', 'filename', 'destination', 'dest',
|
|
1346
1363
|
'new_path', 'new_name', 'old_path', 'source', 'from', 'to'];
|
|
1347
|
-
|
|
1364
|
+
// Exported for the in-process timing rows, as `gitDecide` is.
|
|
1365
|
+
export function ruleDecide(args, payload) {
|
|
1348
1366
|
const ti = (payload && payload.tool_input) || {};
|
|
1349
1367
|
// NotebookEdit names its target `notebook_path`; the settings matcher routes it here too. Every
|
|
1350
1368
|
// key is read, never the first found: Bob's move and rename tools carry two, and a harmless
|
|
1351
1369
|
// `path` beside the real target must not hide it from any gate below.
|
|
1352
1370
|
const paths = [...new Set(RULE_PATH_KEYS.map((k) => ti[k]).filter((v) => typeof v === 'string' && v))];
|
|
1353
1371
|
if (!paths.length) return 0;
|
|
1372
|
+
// A diff past the command bound is not read, for `MAX_COMMAND_CHARS`' reason: on Bob a scan past
|
|
1373
|
+
// the hook timeout lets the write through with no secrets check. Same `unverified` ask, law-4.
|
|
1374
|
+
if (typeof ti.diff === 'string' && ti.diff.length > MAX_COMMAND_CHARS) {
|
|
1375
|
+
return ask(args, 'rule-gate', 'law-4', 'unverified', {});
|
|
1376
|
+
}
|
|
1354
1377
|
// Write carries `content`, Edit `new_string`, NotebookEdit `new_source`, MultiEdit an
|
|
1355
1378
|
// `edits[]` of `new_string`s — every one can plant a credential, so every one is scanned.
|
|
1356
1379
|
// MultiEdit is no longer in Claude Code's own tool table (tools-reference.md) or the
|
|
1357
1380
|
// settings matcher that routes here (Claude verdict R2); the `edits[]` read stays as a
|
|
1358
1381
|
// cheap, harmless guard in case that ever changes.
|
|
1359
1382
|
// `diff` (Bob's `apply_diff`) and `replace`/`search` (`search_and_replace`) are Roo-lineage
|
|
1360
|
-
// field names the Bob docs never confirm
|
|
1383
|
+
// field names the Bob docs never confirm — accepted when present, never
|
|
1361
1384
|
// required, same as every field above. Only WRITTEN text is scanned: `search` and a diff's
|
|
1362
1385
|
// SEARCH halves are text leaving the file (like Claude's `old_string`), so a secret there is
|
|
1363
1386
|
// being removed — blocking it would stop the agent cleaning up a leak.
|
|
@@ -1371,9 +1394,12 @@ function ruleDecide(args, payload) {
|
|
|
1371
1394
|
return ask(args, 'rule-gate', 'law-1', 'secret', { name: repoRel(carrier, payload) });
|
|
1372
1395
|
}
|
|
1373
1396
|
// Bob routes reads here too (`read_file` carries a path): only a write is External Gate's business.
|
|
1374
|
-
//
|
|
1375
|
-
//
|
|
1376
|
-
|
|
1397
|
+
// A call that carries text to write is a write whatever its tool is called (`create_file`,
|
|
1398
|
+
// `append_to_file`, `apply_patch`, `save_file`): Bob's tool names are undocumented, so the name
|
|
1399
|
+
// alone let those past the store and gate-config checks. `ownershipBlock` reads a write the same way.
|
|
1400
|
+
// shortcut: a write that carries no text under a name outside WRITE_NAME_RE still reads as a
|
|
1401
|
+
// read; switch to an allowlist of Bob's read tools if Bob adds one.
|
|
1402
|
+
const bobRead = HOST === 'bob' && !body && !WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''));
|
|
1377
1403
|
for (const q of bobRead ? [] : paths) {
|
|
1378
1404
|
// The carrier rule is a write tool's alone: a shell call reaches `externalGate` with nothing to replay.
|
|
1379
1405
|
const hit = externalGate(args, q, payload)
|
|
@@ -1403,8 +1429,9 @@ export const cmdRuleGate = guardGate(ruleGate, 'rule-gate');
|
|
|
1403
1429
|
// ======================================================================================
|
|
1404
1430
|
|
|
1405
1431
|
/**
|
|
1406
|
-
* Bob
|
|
1407
|
-
*
|
|
1432
|
+
* The LEGACY Bob PreToolUse payload is `{event, session_id, tool, input:{...}}`, with none of
|
|
1433
|
+
* `tool_input`, `tool_name` or `hook_event_name`; Bob 2.2.3 sends Claude's keys (bundle read
|
|
1434
|
+
* 2026-10, docs/concepts/host-matrix.md "What is verified"), and both are read. Normalised
|
|
1408
1435
|
* HERE, once, at Bob's one entry point (`toolGate` is the only verb its settings.json invokes
|
|
1409
1436
|
* for PreToolUse), so `gitDecide`/`ruleDecide` keep reading the Claude shape unchanged and
|
|
1410
1437
|
* never learn Bob exists. A no-op for an already-Claude-shaped payload: every field it sets
|
package/js/hosts/hosts.mjs
CHANGED
|
@@ -197,6 +197,50 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
// The marker lives in the shim's FILENAME, not its directory: GENESEED_HOME relocates the dir,
|
|
201
|
+
// and a relocated install's hooks must stay recognisable to `GENESEED_HOOK_SNIFF`. Declared here
|
|
202
|
+
// rather than in ./shim.mjs because `ownHookVerb` below reads it, and shim.mjs imports this module.
|
|
203
|
+
export const SHIM_MARK = 'geneseed-hook';
|
|
204
|
+
|
|
205
|
+
/** The verbs `bin/geneseed-hook.mjs` answers (its `VERBS` table). */
|
|
206
|
+
const HOOK_VERBS = 'context|git-gate|rule-gate|tool-gate|learn|activity';
|
|
207
|
+
/** A command that runs one of them: every emitted form is `<runner> <verb> --root|--memory …`. */
|
|
208
|
+
const RUNS_HOOK_VERB = new RegExp(` (?:${HOOK_VERBS}) --`);
|
|
209
|
+
/** The verb token after the shim's name: the rest of its path, a closing quote, then the verb. */
|
|
210
|
+
const VERB_AFTER_SHIM = new RegExp(`^[^"]*"? (${HOOK_VERBS})(?= |$)`);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The hook verb `command` runs FOR THE INSTALL AT `cfg`, or null when the handler is not that
|
|
214
|
+
* install's. The one test of "is this handler Geneseed's", shared by the settings merge, the
|
|
215
|
+
* unwire and the integrity check (`js/hosts/settings.mjs`).
|
|
216
|
+
*
|
|
217
|
+
* A SIGNATURE, not deep equality with what this build would emit. Equality broke four ways: a
|
|
218
|
+
* re-emit with other gate flags and no manifest stacked a second group beside the first; a group
|
|
219
|
+
* already on file was never claimed, so uninstall left it running; a user's own `"timeout": 30`
|
|
220
|
+
* on our handler made it a stranger; and the integrity check then reported that handler missing.
|
|
221
|
+
* So a handler is ours when its command names the shim (`SHIM_MARK`), then a hook verb, and
|
|
222
|
+
* carries exactly `--root "<cfg>"` or `--memory "<cfg>/memory"`. Flags, `--host` and every other
|
|
223
|
+
* field are free to differ. The closing quote makes the root exact: `<cfg>-old` is another
|
|
224
|
+
* install, and a global and a project install differ by root, so neither claims the other's.
|
|
225
|
+
*
|
|
226
|
+
* A hand-written hook that runs our binary with our root therefore counts as ours (the maintainer
|
|
227
|
+
* accepted that, 2026-11): a re-emit replaces it and uninstall removes it.
|
|
228
|
+
*
|
|
229
|
+
* The PowerShell form backtick-escapes `$` and a backtick inside the path (`powershellForm`), so
|
|
230
|
+
* the command is read both as written and with those undone; Windows compares paths case-folded.
|
|
231
|
+
*/
|
|
232
|
+
export function ownHookVerb(command, cfg) {
|
|
233
|
+
if (typeof command !== 'string' || typeof cfg !== 'string' || !cfg) return null;
|
|
234
|
+
const at = command.indexOf(SHIM_MARK);
|
|
235
|
+
if (at < 0) return null;
|
|
236
|
+
const verb = VERB_AFTER_SHIM.exec(command.slice(at + SHIM_MARK.length))?.[1];
|
|
237
|
+
if (!verb) return null;
|
|
238
|
+
const fold = (s) => (process.platform === 'win32' ? s.toLowerCase() : s);
|
|
239
|
+
const wanted = [` --root "${cfg}"`, ` --memory "${path.join(cfg, 'memory')}"`].map(fold);
|
|
240
|
+
const readings = [command, command.replace(/`([`$])/g, '$1')].map(fold);
|
|
241
|
+
return readings.some((c) => wanted.some((w) => c.includes(w))) ? verb : null;
|
|
242
|
+
}
|
|
243
|
+
|
|
200
244
|
/**
|
|
201
245
|
* The hook handlers the install at `cfg` both RECORDS and still RUNS: `[event, handler]` pairs
|
|
202
246
|
* from its manifest's `managed.settings_hooks` whose command the settings file that manifest
|
|
@@ -204,13 +248,20 @@ export function globalHookStandingDown(hookRoot, projectDir, host, verb) {
|
|
|
204
248
|
* the host runs. A user who deletes `hooks` by hand keeps the manifest (re-review, Important).
|
|
205
249
|
* Absent, unparseable or COMMENTED settings fail `JSON.parse` and answer `[]`. Shared by
|
|
206
250
|
* `projectWiresVerb` and the hook-shell drift check (`hookShellProblems`).
|
|
251
|
+
*
|
|
252
|
+
* Only a recorded handler that runs a hook verb: a claim is the whole group as it sat on file,
|
|
253
|
+
* so it can hold a hook the user added to our group, and that one is not this install's. The
|
|
254
|
+
* shim is NOT required here, unlike `ownHookVerb`: doctor's probe must still be handed a
|
|
255
|
+
* recorded gate that names another binary, to report it. Liveness compares the command alone,
|
|
256
|
+
* so a field the user set on our handler (`timeout`) does not make it read as gone.
|
|
207
257
|
*/
|
|
208
258
|
export function liveRecordedHooks(cfg) {
|
|
209
259
|
const readJson = (p) => { try { return JSON.parse(readText(p)); } catch { return null; } };
|
|
210
260
|
const managed = readJson(path.join(cfg, GLOBAL_MANIFEST))?.managed;
|
|
211
261
|
const recorded = Array.isArray(managed?.settings_hooks) ? managed.settings_hooks : [];
|
|
212
262
|
const wanted = recorded.flatMap((r) => (Array.isArray(r?.group?.hooks) ? r.group.hooks : [])
|
|
213
|
-
.filter((h) => typeof h?.command === 'string'
|
|
263
|
+
.filter((h) => typeof h?.command === 'string' && RUNS_HOOK_VERB.test(h.command))
|
|
264
|
+
.map((h) => [r.event, h]));
|
|
214
265
|
if (!wanted.length) return [];
|
|
215
266
|
const hooks = readJson(settingsFile(cfg, managed))?.hooks;
|
|
216
267
|
const live = (event, command) => Array.isArray(hooks?.[event]) && hooks[event]
|
|
@@ -304,10 +355,20 @@ export function isCanonical(cfgDir, host) {
|
|
|
304
355
|
/**
|
|
305
356
|
* The project root a hook judges against: `$CLAUDE_PROJECT_DIR` (Claude Code and OpenClaude set
|
|
306
357
|
* it for every hook — the session's root, where its project hooks were loaded from), else the
|
|
307
|
-
* cwd
|
|
358
|
+
* payload's `cwd` when the caller has one, else the process cwd.
|
|
359
|
+
*
|
|
360
|
+
* Bob documents no such variable, but its payload carries `cwd`, the root workspace (2.2.3
|
|
361
|
+
* bundle read; docs/concepts/host-matrix.md, "What is verified"). `payloadCwd` is optional and
|
|
362
|
+
* only a caller that ALREADY holds the parsed payload passes it: `context` does, through the
|
|
363
|
+
* hook entry. The gate verbs do not, because their stand-down runs before they read stdin, and
|
|
364
|
+
* a second read on every tool call is not worth a fallback. A value that is not an absolute
|
|
365
|
+
* path is ignored: the payload is the host's text, and a relative one would resolve against
|
|
366
|
+
* the very cwd it was meant to replace.
|
|
308
367
|
*/
|
|
309
|
-
export function hookProjectDir() {
|
|
310
|
-
|
|
368
|
+
export function hookProjectDir(payloadCwd) {
|
|
369
|
+
if (process.env.CLAUDE_PROJECT_DIR) return process.env.CLAUDE_PROJECT_DIR;
|
|
370
|
+
if (typeof payloadCwd === 'string' && path.isAbsolute(payloadCwd)) return payloadCwd;
|
|
371
|
+
return process.cwd();
|
|
311
372
|
}
|
|
312
373
|
|
|
313
374
|
/**
|
|
@@ -449,8 +510,10 @@ export function openclaudeConfigDir() {
|
|
|
449
510
|
|
|
450
511
|
/**
|
|
451
512
|
* `_build_global.HOSTS` — one row per host, IN ITS ORDER: opencode, claude, bob, openclaude.
|
|
452
|
-
*
|
|
453
|
-
*
|
|
513
|
+
* `EMIT_HOST_SCOPE` and `EMIT_FOR` (`js/hosts/installs.mjs`) and `CLAUDE_STYLE` below are
|
|
514
|
+
* derived from it, but A NEW HOST IS NOT ONE ROW HERE: a dozen hand tables name the hosts
|
|
515
|
+
* too. `docs/extending.md` §4d is the checklist, and `tests/unit/host_tables.test.mjs` fails
|
|
516
|
+
* for each table that falls behind this one.
|
|
454
517
|
*
|
|
455
518
|
* An array rather than an object because the order is observable output, not an
|
|
456
519
|
* implementation detail: `harness exclude add` walks it and prints one message per host, so
|
|
@@ -580,12 +643,17 @@ export const CLAUDE_STYLE = HOSTS.filter((h) => h.family === 'claude').map((h) =
|
|
|
580
643
|
* user-editable `.geneseed-emit` marker, so an unrecognised one must degrade to the portable
|
|
581
644
|
* bundle rather than raise.
|
|
582
645
|
*
|
|
583
|
-
* SPLIT PER KIND (2026-09): Bob reads `.bob/skills/<name>/SKILL.md` natively
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
646
|
+
* SPLIT PER KIND (2026-09): Bob reads `.bob/skills/<name>/SKILL.md` natively (its skills
|
|
647
|
+
* docs), so a single boolean was wrong both ways: `false` shipped the §4 Skills table on top
|
|
648
|
+
* of a catalogue Bob already had (~1.7k tokens twice), `true` would have stripped the §3
|
|
649
|
+
* Agents table. Each CATALOG block in AGENT.md names its kind and resolves against its own flag.
|
|
650
|
+
*
|
|
651
|
+
* BOB'S `agents: false` IS NOT "Bob has no agents directory". The emit writes native
|
|
652
|
+
* `agents/<name>.md` in Bob's dialect (`bobAgentFrontmatter`, `js/hosts/native.mjs`), and Bob
|
|
653
|
+
* 2.2.3 reads them. What is NOT verified is whether Bob lists those agents to the model by
|
|
654
|
+
* itself, so the §3 Agents table stays in Bob's carrier and the flag stays false until someone
|
|
655
|
+
* sees Bob's own listing. Flipping it on a guess would remove the only agent catalogue the
|
|
656
|
+
* model is known to get.
|
|
589
657
|
*
|
|
590
658
|
* Returns `{ skills, agents }` for a known host, `false` for an unknown one.
|
|
591
659
|
*/
|
package/js/hosts/installs.mjs
CHANGED
|
@@ -554,6 +554,13 @@ export const EMIT_HOST_SCOPE = new Map(HOSTS.flatMap(({ host }) => [
|
|
|
554
554
|
[host, [host, 'project']], [`${host}-global`, [host, 'global']],
|
|
555
555
|
]));
|
|
556
556
|
|
|
557
|
+
/**
|
|
558
|
+
* The inverse: `'<host> <scope>'` -> the emit name that installs it. One map for the two
|
|
559
|
+
* readers that had a hand copy each: `rebuild-all`'s default for an install with no marker
|
|
560
|
+
* (`js/build/generate.mjs`) and the console's install command (`js/web/actions.mjs`).
|
|
561
|
+
*/
|
|
562
|
+
export const EMIT_FOR = new Map([...EMIT_HOST_SCOPE].map(([emit, [host, scope]]) => [`${host} ${scope}`, emit]));
|
|
563
|
+
|
|
557
564
|
/** `root`'s own marker, resolved, or null. */
|
|
558
565
|
export function emitHostScopeOf(root) {
|
|
559
566
|
const emit = readMaybe(path.join(root, '.geneseed-emit'));
|
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
|
-
|
|
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); };
|
package/js/hosts/native.mjs
CHANGED
|
@@ -356,21 +356,30 @@ const WEBFETCH_MARKER = '<!-- webfetch: allow -->';
|
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
358
|
* `_build_emit._claude_agent_frontmatter`. A read-only spec gets a `disallowedTools` DENYLIST;
|
|
359
|
-
* each opt-in marker takes its
|
|
360
|
-
*
|
|
359
|
+
* each opt-in marker takes its tools back off the list. Order is emit order.
|
|
360
|
+
*
|
|
361
|
+
* `Agent` and `Task` (the same tool, new name and old) are denied to EVERY read-only agent and
|
|
362
|
+
* no marker lifts them: a read-only agent that can dispatch can spawn a writer, and the denylist
|
|
363
|
+
* of the child, not the parent's, is what that writer runs under. The specs already say a seat
|
|
364
|
+
* dispatches no sub-agents; this is the boundary under the sentence.
|
|
365
|
+
*
|
|
366
|
+
* STILL OPEN: an MCP tool that writes (`mcp__github__push_files`, a database server). A denylist
|
|
367
|
+
* cannot name tools it has never seen, so a read-only agent in a session with such a server can
|
|
368
|
+
* still write through it, until this becomes an allowlist (`tools:`).
|
|
361
369
|
*/
|
|
362
370
|
function claudeAgentFrontmatter(stem, text, overrides) {
|
|
363
371
|
const fm = [`name: ${stem}`, `description: ${jsonDumps(agentDescription(text))}`];
|
|
364
372
|
const ov = agentOverride(overrides, stem);
|
|
365
373
|
if (isTruthy(ov.model)) fm.push(`model: ${formatValue(ov.model)}`);
|
|
366
374
|
if (isReadonly(text)) {
|
|
367
|
-
const list = ['Write', 'Edit', 'NotebookEdit'];
|
|
375
|
+
const list = ['Write', 'Edit', 'NotebookEdit', 'Agent', 'Task'];
|
|
368
376
|
if (!text.includes(WEBFETCH_MARKER)) list.push('WebFetch');
|
|
369
377
|
// Bash AND PowerShell: docs `tools-reference.md` says denying Bash turns PowerShell off
|
|
370
378
|
// only for settings rules and `--disallowedTools` — agent frontmatter is not named there,
|
|
371
379
|
// so a "read-only" agent on Windows could still run shell commands via PowerShell
|
|
372
|
-
// (Claude verdict R1).
|
|
373
|
-
|
|
380
|
+
// (Claude verdict R1). Monitor is the third shell: it runs a `command` in the background.
|
|
381
|
+
// The one opt-in marker lifts all three together.
|
|
382
|
+
if (!text.includes(BASH_MARKER)) list.push('Bash', 'PowerShell', 'Monitor');
|
|
374
383
|
fm.push(`disallowedTools: ${list.join(', ')}`);
|
|
375
384
|
}
|
|
376
385
|
return fm;
|
package/js/hosts/owned.mjs
CHANGED
|
@@ -176,9 +176,9 @@ export function hashesOf(doc) {
|
|
|
176
176
|
* An OpenCode manifest's `skill_denies` — the `permission.skill` denies Geneseed itself added
|
|
177
177
|
* (`opencodeLayer` records them; a deny the user wrote, even on a Geneseed skill, is never in
|
|
178
178
|
* it) — or `[]` when the manifest, or the key, is absent or malformed, which sweeps nothing.
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
179
|
+
* A skill-visibility deny is reversible: once uninstalled there is no skill left to hide, and
|
|
180
|
+
* the name is the user's to reuse — uninstall takes the recorded ones back, as it does the
|
|
181
|
+
* recorded `permission.bash` gates (`recordedGates`). One home because rebuild's
|
|
182
182
|
* deny sweep and uninstall must agree on what Geneseed owns.
|
|
183
183
|
*/
|
|
184
184
|
export function recordedDenies(doc) {
|
|
@@ -202,9 +202,10 @@ export function recordedEdit(doc) {
|
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
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`)
|
|
206
|
-
*
|
|
207
|
-
* such key, so its gates stay
|
|
205
|
+
* a later build may take back once their rule is off (`reconcileOpencodePermission`) and an
|
|
206
|
+
* uninstall takes back outright (`unmergeOpencodeJson`). Absent or malformed reads as nothing
|
|
207
|
+
* owned, like `recordedDenies`: a manifest from before 5.2.0 has no such key, so its gates stay
|
|
208
|
+
* until `--prune-gates` or a hand edit.
|
|
208
209
|
*/
|
|
209
210
|
export function recordedGates(doc) {
|
|
210
211
|
const g = doc && doc.bash_gates;
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* and become a gate-error ask on every write in every repo; any surprise is a defer.
|
|
18
18
|
*
|
|
19
19
|
* The OpenCode guard (`adapters/opencode/plugins/geneseed-guard.js`, `ownershipBlock`) is this
|
|
20
|
-
* file's twin and cannot import it
|
|
20
|
+
* file's twin and cannot import it. Its constants are copied from here by `tests/twins.mjs`
|
|
21
|
+
* (the two marked blocks and three one-line constants); the function reads another payload
|
|
22
|
+
* and is kept in step by hand.
|
|
21
23
|
*/
|
|
22
24
|
import { appendFileSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
|
|
23
25
|
import os from 'node:os';
|
|
@@ -26,6 +28,10 @@ import { withoutBlocks } from '../lib/managed-block.mjs';
|
|
|
26
28
|
import { normcase } from '../lib/paths.mjs';
|
|
27
29
|
import { gitRootOf, mainWorktreeOf } from './gitref.mjs';
|
|
28
30
|
|
|
31
|
+
// ---- ownership shape twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js and
|
|
32
|
+
// geneseed-context.js carry everything down to the END marker verbatim (node tests/twins.mjs
|
|
33
|
+
// --write keeps it), and the one-line `WRITE_NAME_RE`, `safeStem` and `DECLINED_RE` below too.
|
|
34
|
+
|
|
29
35
|
// D5: the build manifests that make a git root an "application". Exact names, plus two families.
|
|
30
36
|
const MANIFESTS = new Set(['package.json', 'pom.xml', 'pyproject.toml', 'go.mod', 'Cargo.toml',
|
|
31
37
|
'composer.json', 'Gemfile']);
|
|
@@ -36,6 +42,8 @@ const isManifest = (n) => MANIFESTS.has(n) || n.startsWith('build.gradle') || n.
|
|
|
36
42
|
// sits after the `\r`.
|
|
37
43
|
const SECTION_RE = /^## Ownership[ \t]*\r?$/m;
|
|
38
44
|
|
|
45
|
+
// ---- ownership shape twin: END
|
|
46
|
+
|
|
39
47
|
// Write-shaped tool names (Bob's `tool-gate` also routes reads here: `read_file` carries a path).
|
|
40
48
|
export const WRITE_NAME_RE = /write|edit|diff|replace|insert|move|rename|delete|remove|trash|copy/i;
|
|
41
49
|
|
|
@@ -51,6 +59,9 @@ function userTag() {
|
|
|
51
59
|
try { return safeStem(os.userInfo().username); } catch { return 'user'; }
|
|
52
60
|
}
|
|
53
61
|
|
|
62
|
+
// ---- ownership text twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js carries everything
|
|
63
|
+
// down to the END marker verbatim (node tests/twins.mjs --write keeps it).
|
|
64
|
+
|
|
54
65
|
const TAIL = 'Opt out per repo: `## Ownership` with `mode: off` in the root `AGENTS.md`; per '
|
|
55
66
|
+ 'install: rebuild with `--no-ownership-gate`. Offer the full documentation '
|
|
56
67
|
+ '(`/document-project`) as yes / later. Stop and ask the developer now; re-issue the write only '
|
|
@@ -68,6 +79,8 @@ const REASON_NO_SECTION = 'Geneseed (Ownership) — this application\'s `AGENTS.
|
|
|
68
79
|
+ '`## Ownership` section. Before writing, ask the developer: add the Ownership section now '
|
|
69
80
|
+ `(ownership skill); ${SKIP}? ${TAIL}`;
|
|
70
81
|
|
|
82
|
+
// ---- ownership text twin: END
|
|
83
|
+
|
|
71
84
|
// D2: the developer's durable, personal, per-repo decline, in `.geneseed/ownership.md`. It holds
|
|
72
85
|
// until the line is deleted or the setup runs (which removes it); a `## Ownership` section in
|
|
73
86
|
// `AGENTS.md`, on or off, outranks it. The OpenCode twins (geneseed-guard.js,
|