geneseed 4.28.0 → 4.30.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.
- package/CHANGELOG.md +58 -0
- package/README.md +4 -2
- package/SHIPPED.md +2 -2
- package/adapters/bob/README.md +1 -1
- package/adapters/claude-code/README.md +4 -2
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +2 -2
- package/adapters/opencode/README.md +18 -2
- package/adapters/opencode/plugins/geneseed-activity.js +22 -20
- package/adapters/opencode/plugins/geneseed-context.js +155 -18
- package/adapters/opencode/plugins/geneseed-guard.js +59 -8
- package/adapters/opencode/plugins/geneseed-workflow.js +18 -1
- package/adapters/opencode/workflows/_runtime.js +14 -3
- package/docs/concepts/enforcement-table.md +5 -4
- package/docs/concepts/exclusions.md +3 -3
- package/docs/concepts/hooks.md +12 -4
- package/docs/concepts/ownership.md +9 -8
- package/docs/concepts/skills.md +1 -0
- package/docs/guides/set-up-ownership.md +22 -6
- package/docs/reference/environment.md +1 -0
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-context.md +3 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/understand/enforced-vs-asked.md +3 -3
- package/docs/understand/machine-bob.md +1 -1
- package/docs/understand/machine-claude.md +1 -1
- package/docs/understand/machine-opencode.md +1 -1
- package/harness.config.json +1 -1
- package/js/README.md +3 -1
- package/js/build/driver.mjs +29 -9
- package/js/build/emit-opencode.mjs +12 -10
- package/js/build/render.mjs +9 -0
- package/js/hosts/done-checks.mjs +134 -0
- package/js/hosts/geneseed-dir.mjs +116 -0
- package/js/hosts/hooks-context.mjs +19 -0
- package/js/hosts/hooks-done.mjs +82 -38
- package/js/hosts/hooks-learn.mjs +9 -2
- package/js/hosts/hooks-prims.mjs +4 -0
- package/js/hosts/hooks.mjs +139 -6
- package/js/hosts/hosts.mjs +6 -0
- package/js/hosts/native.mjs +1 -1
- package/js/hosts/owned.mjs +19 -0
- package/js/hosts/ownership-gate.mjs +64 -10
- package/js/hosts/settings.mjs +115 -74
- package/js/inspect/checks-constitution.mjs +5 -1
- package/js/inspect/cost.mjs +1 -1
- package/js/inspect/doctor.mjs +2 -1
- package/js/inspect/inventory.mjs +1 -1
- package/js/inspect/status.mjs +2 -1
- package/js/inspect/validate.mjs +2 -1
- package/js/lib/json.mjs +70 -0
- package/js/maintain/uninstall.mjs +18 -5
- package/js/web/gates-api.mjs +2 -2
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +2 -2
- package/src/licenses/i-have-adhd.txt +21 -0
- package/src/skills/_checkpoints.md +28 -5
- package/src/skills/adhd.md +40 -0
- package/src/skills/diagram-design/LICENSE +21 -0
- package/src/skills/diagram-design/SKILL.md +392 -0
- package/src/skills/diagram-design/THIRD_PARTY_LICENSES.md +134 -0
- package/src/skills/diagram-design/VENDOR.md +81 -0
- package/src/skills/diagram-design/assets/example-architecture.html +183 -0
- package/src/skills/diagram-design/assets/example-venn.html +110 -0
- package/src/skills/diagram-design/assets/template-dark.html +99 -0
- package/src/skills/diagram-design/assets/template-full.html +421 -0
- package/src/skills/diagram-design/assets/template-motion.html +448 -0
- package/src/skills/diagram-design/assets/template-terminal.html +188 -0
- package/src/skills/diagram-design/assets/template.html +100 -0
- package/src/skills/diagram-design/references/animation.md +135 -0
- package/src/skills/diagram-design/references/layout-budget.md +97 -0
- package/src/skills/diagram-design/references/onboarding.md +368 -0
- package/src/skills/diagram-design/references/output-spec.md +277 -0
- package/src/skills/diagram-design/references/primitive-annotation.md +36 -0
- package/src/skills/diagram-design/references/primitive-icons.md +782 -0
- package/src/skills/diagram-design/references/primitive-sketchy.md +43 -0
- package/src/skills/diagram-design/references/primitive-terminal.md +76 -0
- package/src/skills/diagram-design/references/primitives-core.md +144 -0
- package/src/skills/diagram-design/references/profiles.md +183 -0
- package/src/skills/diagram-design/references/semantic-patterns.md +154 -0
- package/src/skills/diagram-design/references/style-guide.md +232 -0
- package/src/skills/diagram-design/references/type-architecture-delta.md +143 -0
- package/src/skills/diagram-design/references/type-architecture.md +117 -0
- package/src/skills/diagram-design/references/type-axonometric-plan.md +83 -0
- package/src/skills/diagram-design/references/type-bar.md +108 -0
- package/src/skills/diagram-design/references/type-data-flow.md +371 -0
- package/src/skills/diagram-design/references/type-db-schema.md +48 -0
- package/src/skills/diagram-design/references/type-dependency.md +44 -0
- package/src/skills/diagram-design/references/type-deployment.md +45 -0
- package/src/skills/diagram-design/references/type-dp-integration.md +407 -0
- package/src/skills/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/src/skills/diagram-design/references/type-er.md +25 -0
- package/src/skills/diagram-design/references/type-exploded.md +115 -0
- package/src/skills/diagram-design/references/type-fishbone.md +75 -0
- package/src/skills/diagram-design/references/type-flowchart.md +23 -0
- package/src/skills/diagram-design/references/type-gantt.md +45 -0
- package/src/skills/diagram-design/references/type-heatmap.md +80 -0
- package/src/skills/diagram-design/references/type-high-level.md +470 -0
- package/src/skills/diagram-design/references/type-it-state.md +468 -0
- package/src/skills/diagram-design/references/type-journey.md +55 -0
- package/src/skills/diagram-design/references/type-kanban.md +49 -0
- package/src/skills/diagram-design/references/type-layers.md +26 -0
- package/src/skills/diagram-design/references/type-line.md +337 -0
- package/src/skills/diagram-design/references/type-loop.md +223 -0
- package/src/skills/diagram-design/references/type-medallion.md +356 -0
- package/src/skills/diagram-design/references/type-nested.md +22 -0
- package/src/skills/diagram-design/references/type-org-chart.md +44 -0
- package/src/skills/diagram-design/references/type-polar.md +136 -0
- package/src/skills/diagram-design/references/type-process.md +490 -0
- package/src/skills/diagram-design/references/type-pyramid.md +33 -0
- package/src/skills/diagram-design/references/type-quadrant.md +81 -0
- package/src/skills/diagram-design/references/type-radar.md +82 -0
- package/src/skills/diagram-design/references/type-sankey.md +75 -0
- package/src/skills/diagram-design/references/type-scatter.md +276 -0
- package/src/skills/diagram-design/references/type-sequence.md +130 -0
- package/src/skills/diagram-design/references/type-service-blueprint.md +103 -0
- package/src/skills/diagram-design/references/type-state.md +30 -0
- package/src/skills/diagram-design/references/type-story-map.md +46 -0
- package/src/skills/diagram-design/references/type-swimlane.md +22 -0
- package/src/skills/diagram-design/references/type-timeline.md +20 -0
- package/src/skills/diagram-design/references/type-tree.md +24 -0
- package/src/skills/diagram-design/references/type-treemap.md +137 -0
- package/src/skills/diagram-design/references/type-uml-class.md +65 -0
- package/src/skills/diagram-design/references/type-venn.md +26 -0
- package/src/skills/diagram-design/references/type-wardley.md +39 -0
- package/src/skills/diagram-design/references/type-waterfall.md +75 -0
- package/src/skills/document-project.md +4 -1
- package/src/skills/learn-mode.md +11 -11
- package/src/skills/ownership.md +41 -18
- package/src/upstreams.json +14 -0
- package/themes/_TEMPLATE.json +1 -0
- package/themes/biker.json +1 -0
- package/themes/commentator.json +1 -0
- package/themes/cyberpunk.json +1 -0
- package/themes/gamer.json +1 -0
- package/themes/imperial.json +1 -0
- package/themes/joker.json +1 -0
- package/themes/marvin.json +1 -0
- package/themes/mean.json +1 -0
- package/themes/military.json +1 -0
- package/themes/neutral.json +1 -0
- package/themes/pirate.json +1 -0
- package/themes/sports.json +1 -0
- package/themes/verstappen.json +1 -0
- package/themes/wizard.json +1 -0
package/js/hosts/hooks-done.mjs
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
* The done gate — Verify Before Asserting's boundary half, at the moment a turn ends (#289).
|
|
3
3
|
*
|
|
4
4
|
* Every other gate sits before an act. This one sits at Stop: a turn that edited files under a
|
|
5
|
-
* project
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* project's git root is judged against that project's proof — the checks that must have run AND
|
|
6
|
+
* passed after the last edit. The gate never runs a check itself — the hook path starts no
|
|
7
|
+
* process of its own (ADR 0002) — it reads the turn's own tool calls in the transcript.
|
|
8
|
+
*
|
|
9
|
+
* WHERE THE CHECKS COME FROM (`doneChecksOf`, user decision 2026-10-29: the harness maintains
|
|
10
|
+
* them, not the user). `.geneseed/done-checks.txt` at the git root, when present, is the override:
|
|
11
|
+
* one command per line, and it BLOCKS (a present file that lists nothing switches the gate off for
|
|
12
|
+
* that project). Absent, the checks are INFERRED from the root manifests (`inferDoneChecks`), and
|
|
13
|
+
* an inferred check is ADVISORY: an unproven turn still ends, with a `systemMessage` to the user,
|
|
14
|
+
* a ledger line and a stderr line — never `decision: block`. An inferred check is a GROUP of
|
|
15
|
+
* accepted command forms (`npm test` | `npm run test` | `npm t`), satisfied by any one.
|
|
8
16
|
*
|
|
9
17
|
* WHY IT RIDES `learn` AND NOT A VERB OR A FLAG OF ITS OWN (ADR 0010). The machine-wide shim is
|
|
10
18
|
* last-writer-wins: an older `geneseed-hook` would refuse a new verb or flag, and the Stop
|
|
@@ -17,14 +25,20 @@
|
|
|
17
25
|
*
|
|
18
26
|
* WHY STDOUT JSON AND NOT EXIT 2. The emitted Stop command ends in `|| exit 0`, which swallows
|
|
19
27
|
* a 2. `{"decision":"block"}` on exit 0 is the one signal that survives the existing wiring.
|
|
20
|
-
* Allowing prints NOTHING — on Stop a stray stdout byte is read as a verdict.
|
|
28
|
+
* Allowing prints NOTHING — on Stop a stray stdout byte is read as a verdict. The advisory prints
|
|
29
|
+
* `{"systemMessage":…}` alone: Claude Code shows it to the user as a warning and the stop goes
|
|
30
|
+
* ahead (code.claude.com/docs/en/hooks.md, "JSON output"; not seen live — no gate here runs a
|
|
31
|
+
* model turn). `hookSpecificOutput.additionalContext` would reach the model, but it continues the
|
|
32
|
+
* turn under the same loop guard as a block — a block in all but name — so the model learns of
|
|
33
|
+
* inferred checks from `doneLine`, in the SessionStart context, instead.
|
|
21
34
|
*
|
|
22
35
|
* WHAT COUNTS (shortcut: write tools only; a shell `sed -i` or redirect is not an edit here —
|
|
23
36
|
* seeing those would need `git status`, a spawn. Same limit as `protected-checks.txt`):
|
|
24
37
|
* - an edit is a Write/Edit/NotebookEdit/MultiEdit whose target is under the project root and
|
|
25
38
|
* whose result is not an error (a denied write changed nothing);
|
|
26
|
-
* - a pass is a Bash/PowerShell call whose command contains the
|
|
27
|
-
* takes the exit code of its last stage: `npm test | tail` exits 0 on a red suite)
|
|
39
|
+
* - a pass is a Bash/PowerShell call whose command contains one of the check's forms UNPIPED (a pipe
|
|
40
|
+
* takes the exit code of its last stage: `npm test | tail` exits 0 on a red suite), not MASKED
|
|
41
|
+
* after it (`|| true`, `; exit 0` — see `runsUnpiped`), and whose
|
|
28
42
|
* result is not `is_error` — every non-zero exit, denial and timeout carries it (checked on
|
|
29
43
|
* 14 000+ real Claude Code results, 2026-10-17).
|
|
30
44
|
*
|
|
@@ -36,38 +50,37 @@
|
|
|
36
50
|
* At most one block per turn: `stop_hook_active` is true when this Stop follows a block, and the
|
|
37
51
|
* gate then lets the turn end and leaves a ledger line, so a gate that cries wolf gets found.
|
|
38
52
|
*/
|
|
39
|
-
import { existsSync } from 'node:fs';
|
|
40
53
|
import path from 'node:path';
|
|
41
|
-
import {
|
|
54
|
+
import { printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
42
55
|
import { within } from '../lib/paths.mjs';
|
|
43
56
|
import { gitRootOf } from './gitref.mjs';
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
57
|
+
import { recordGate } from './hooks.mjs';
|
|
58
|
+
import { ADVISORY_VERB } from './hosts.mjs';
|
|
59
|
+
import { DONE_LIST, splitLines, tailReader } from './hooks-prims.mjs';
|
|
60
|
+
import { doneChecksOf } from './done-checks.mjs';
|
|
46
61
|
|
|
47
62
|
const EDIT_TOOLS = new Set(['Write', 'Edit', 'NotebookEdit', 'MultiEdit']);
|
|
48
63
|
const SHELL_TOOLS = new Set(['Bash', 'PowerShell']);
|
|
49
64
|
|
|
50
|
-
/** The declared checks, one per line, `#` comments; null when the project has no list. */
|
|
51
|
-
export function readDoneChecks(root) {
|
|
52
|
-
const file = path.join(root, DONE_LIST);
|
|
53
|
-
if (!existsSync(file)) return null;
|
|
54
|
-
try {
|
|
55
|
-
return splitLines(readText(file)).map((l) => l.trim().replace(/\s+/g, ' '))
|
|
56
|
-
.filter((l) => l && !l.startsWith('#'));
|
|
57
|
-
} catch {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
65
|
/**
|
|
63
66
|
* True when `command` runs `line` as a whole command with no pipe after it in the same segment.
|
|
64
67
|
* A segment ends at `&&`, `||`, `;` or a newline; a single `|` before that end is a pipe. The
|
|
65
68
|
* check must open a segment (the start, or right after one of those separators) and be followed
|
|
66
69
|
* by the end, whitespace or a separator, never by more of a word (`npm run lint:fix` does not
|
|
67
70
|
* prove `npm run lint`); a match inside a quoted string (`-m "ran npm test"`) is text, not a run.
|
|
71
|
+
* A run whose exit code is MASKED is not a run either: `npm test || true`, `npm test; true`,
|
|
72
|
+
* `npm test; exit 0` all exit 0 on a red suite, so `is_error` stays false. Masked means a `||`
|
|
73
|
+
* anywhere after the check (any right-hand side, even an honest `|| exit 1`), or a `;`/newline
|
|
74
|
+
* followed by `true`, `:`, `exit 0` or a bare `exit` (bash passes `$?` on, but PowerShell's bare
|
|
75
|
+
* `exit` is 0, so it must count). `&&` masks nothing (a red check stops the
|
|
76
|
+
* chain), so `npm test && echo ok` still passes.
|
|
68
77
|
* Whitespace is collapsed on both sides. shortcut: the shell is not parsed — a prefix such as
|
|
69
78
|
* `sudo`/`time`/`env X=1`, a subshell, or a `|` inside a quoted argument after the check all read
|
|
70
|
-
* as "not run"
|
|
79
|
+
* as "not run", and so does a `||` inside a quoted argument after the check. Every approximation
|
|
80
|
+
* above refuses a pass, so the gate errs toward a reminder — with ONE known opening the other way:
|
|
81
|
+
* `npm test; npm run lint` passes both, though `;` lets a green lint hide a red test (the line's
|
|
82
|
+
* exit code is the last command's). Kept so a chained proof line still counts; upgrade by
|
|
83
|
+
* requiring `&&` between checks if that opening is ever seen in a real transcript.
|
|
71
84
|
*/
|
|
72
85
|
export function runsUnpiped(command, line) {
|
|
73
86
|
const cmd = String(command).replace(/[ \t]+/g, ' ');
|
|
@@ -91,11 +104,26 @@ export function runsUnpiped(command, line) {
|
|
|
91
104
|
if (two === '&&' || two === '||' || rest[j] === ';' || rest[j] === '\n') break;
|
|
92
105
|
if (rest[j] === '|') { piped = true; break; }
|
|
93
106
|
}
|
|
94
|
-
if (!piped) return true;
|
|
107
|
+
if (!piped && !/\|\||[;\n] ?(?:true|:|exit(?: 0)?)(?= ?(?:$|[;&|\n]))/.test(rest)) return true;
|
|
95
108
|
}
|
|
96
109
|
return false;
|
|
97
110
|
}
|
|
98
111
|
|
|
112
|
+
/**
|
|
113
|
+
* True when `command` proves the check group `g`: one of its forms runs unpiped and unmasked
|
|
114
|
+
* (`runsUnpiped`), and — when the group names `refuse`, the flags that skip the tests
|
|
115
|
+
* (`mvn install -DskipTests`, `gradle build -x test`, `cargo test --no-run`) — some unpiped
|
|
116
|
+
* segment opening with a form carries none of them. shortcut: segments split on `&&`, `||`, `;`
|
|
117
|
+
* and newlines without reading quotes; a quoted separator only makes a refusal more likely.
|
|
118
|
+
*/
|
|
119
|
+
export function groupPasses(command, g) {
|
|
120
|
+
if (!g.forms.some((f) => runsUnpiped(command, f))) return false;
|
|
121
|
+
if (!g.refuse) return true;
|
|
122
|
+
return String(command).replace(/[ \t]+/g, ' ').split(/&&|\|\||;|\n/).map((s) => s.trim())
|
|
123
|
+
.some((s) => !s.includes('|') && !g.refuse.test(s)
|
|
124
|
+
&& g.forms.some((f) => s === f || s.startsWith(`${f} `)));
|
|
125
|
+
}
|
|
126
|
+
|
|
99
127
|
/** A user line that opens a turn: the user typed it, it is not a tool result or a meta note. */
|
|
100
128
|
function isPrompt(obj) {
|
|
101
129
|
if (obj.type !== 'user' || obj.isMeta || obj.isSidechain) return false;
|
|
@@ -110,8 +138,10 @@ function isPrompt(obj) {
|
|
|
110
138
|
* unit tier — a transcript is text no CLI cell can vary cheaply. `whole` false means the text
|
|
111
139
|
* is only the file's tail: with no prompt in it the turn may start earlier, so the answer is
|
|
112
140
|
* null ("read more") — a turn judged from its middle could miss its edit and wrongly pass.
|
|
141
|
+
* A check is a line (one form) or a `{ label, forms }` group; the answer lists labels.
|
|
113
142
|
*/
|
|
114
143
|
export function doneDecide(transcript, checks, root, cwd = root, whole = true) {
|
|
144
|
+
const groups = checks.map((c) => (typeof c === 'string' ? { label: c, forms: [c] } : c));
|
|
115
145
|
const entries = [];
|
|
116
146
|
for (const line of splitLines(transcript)) {
|
|
117
147
|
if (!line.trim()) continue;
|
|
@@ -149,14 +179,16 @@ export function doneDecide(transcript, checks, root, cwd = root, whole = true) {
|
|
|
149
179
|
const command = SHELL_TOOLS.has(c.name) && c.input && c.input.command;
|
|
150
180
|
// A call with no result yet (the host has not flushed it) is not a pass.
|
|
151
181
|
if (typeof command !== 'string' || results.get(c.id) !== false) return;
|
|
152
|
-
for (const
|
|
182
|
+
for (const g of groups) if (groupPasses(command, g)) passed.add(g.label);
|
|
153
183
|
});
|
|
154
|
-
return
|
|
184
|
+
return groups.map((g) => g.label).filter((l) => !passed.has(l));
|
|
155
185
|
}
|
|
156
186
|
|
|
157
187
|
/**
|
|
158
|
-
* The Stop-side wrapper `cmdLearn` calls first. Returns
|
|
159
|
-
* goes on, so `learn` must not distil yet);
|
|
188
|
+
* The Stop-side wrapper `cmdLearn` calls first. Returns 'block' when it printed a block (the
|
|
189
|
+
* turn goes on, so `learn` must not distil yet); 'advisory' when it printed the advisory
|
|
190
|
+
* `systemMessage` (the turn ends and learning runs, but `learn` must print nothing more on
|
|
191
|
+
* stdout, or the JSON stops parsing); null in every other case, with nothing on stdout.
|
|
160
192
|
* `install` is the root `cmdLearn` already derived from `--memory` (null without one), so the
|
|
161
193
|
* ledger lands in the same root its sovereignty check read. `read` is `cmdLearn`'s per-Stop
|
|
162
194
|
* transcript reader, so the distillation after an allow reuses the windows read here.
|
|
@@ -165,12 +197,14 @@ export function doneGate(meta, args, install, read = tailReader()) {
|
|
|
165
197
|
try {
|
|
166
198
|
const cwd = typeof meta.cwd === 'string' && meta.cwd ? meta.cwd : process.cwd();
|
|
167
199
|
const root = gitRootOf(cwd);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
200
|
+
if (!root) return null;
|
|
201
|
+
const { source, blocking, checks } = doneChecksOf(root);
|
|
202
|
+
if (!checks.length) return null;
|
|
203
|
+
// Bob's Stop payload carries no transcript (learn's I2): nothing to judge, and a listed gate
|
|
204
|
+
// says so. Inferred checks stay quiet there: every repo with a manifest would log it.
|
|
171
205
|
if (args.host === 'bob' || typeof meta.transcript_path !== 'string') {
|
|
172
|
-
err(`[done-gate] no transcript${args.host === 'bob' ? ' (bob)' : ''} — turn not judged.\n`);
|
|
173
|
-
return
|
|
206
|
+
if (blocking) err(`[done-gate] no transcript${args.host === 'bob' ? ' (bob)' : ''} — turn not judged.\n`);
|
|
207
|
+
return null;
|
|
174
208
|
}
|
|
175
209
|
let missing;
|
|
176
210
|
try {
|
|
@@ -179,13 +213,23 @@ export function doneGate(meta, args, install, read = tailReader()) {
|
|
|
179
213
|
} catch {
|
|
180
214
|
// No ask tier on Stop: blocking on an unreadable transcript would trap the user.
|
|
181
215
|
err('[done-gate] transcript unreadable — turn not judged.\n');
|
|
182
|
-
return
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
if (!missing.length) return null;
|
|
219
|
+
if (!blocking) {
|
|
220
|
+
recordGate(install, ADVISORY_VERB, 'law-3');
|
|
221
|
+
err(`[done-gate] advisory — unproven since the last edit: ${missing.join('; ')}\n`);
|
|
222
|
+
out(`${JSON.stringify({
|
|
223
|
+
systemMessage: 'Geneseed done gate (advisory) — this turn edited files, and these checks '
|
|
224
|
+
+ `inferred from ${source} have not passed since the last edit: ${missing.join('; ')}. `
|
|
225
|
+
+ `List your own in ${DONE_LIST} to make the gate block.`,
|
|
226
|
+
})}\n`);
|
|
227
|
+
return 'advisory';
|
|
183
228
|
}
|
|
184
|
-
if (!missing.length) return false;
|
|
185
229
|
if (meta.stop_hook_active === true) {
|
|
186
230
|
recordGate(install, 'done-gate-cap', 'law-3');
|
|
187
231
|
err(`[done-gate] cap reached — turn ends with unproven checks: ${missing.join('; ')}\n`);
|
|
188
|
-
return
|
|
232
|
+
return null;
|
|
189
233
|
}
|
|
190
234
|
recordGate(install, 'done-gate', 'law-3');
|
|
191
235
|
out(`${JSON.stringify({
|
|
@@ -194,9 +238,9 @@ export function doneGate(meta, args, install, read = tailReader()) {
|
|
|
194
238
|
+ `checks from ${DONE_LIST} have not passed since the last edit: ${missing.join('; ')}. `
|
|
195
239
|
+ 'Run them unpiped, or say plainly that they were not run and why.',
|
|
196
240
|
})}\n`);
|
|
197
|
-
return
|
|
241
|
+
return 'block';
|
|
198
242
|
} catch (e) {
|
|
199
243
|
err(`[done-gate] skipped: ${e && e.message}\n`);
|
|
200
|
-
return
|
|
244
|
+
return null;
|
|
201
245
|
}
|
|
202
246
|
}
|
package/js/hosts/hooks-learn.mjs
CHANGED
|
@@ -327,7 +327,10 @@ export function cmdLearn(args) {
|
|
|
327
327
|
// distillation below.
|
|
328
328
|
// One reader for this Stop: an allowed turn's distillation reuses the windows the gate read.
|
|
329
329
|
const read = tailReader();
|
|
330
|
-
|
|
330
|
+
// An advisory verdict already holds stdout: nothing below may print there after it.
|
|
331
|
+
const verdict = hookEvent === 'Stop' && !args.file && !args.noDoneGate
|
|
332
|
+
? doneGate(meta, args, install, read) : null;
|
|
333
|
+
if (verdict === 'block') return 0;
|
|
331
334
|
|
|
332
335
|
// I2 (Bob): its Stop payload never carries `transcript_path`, so there is never a transcript
|
|
333
336
|
// to distil — and the bare envelope itself is not notes text (that would waste a model call
|
|
@@ -394,9 +397,13 @@ export function cmdLearn(args) {
|
|
|
394
397
|
if (!created.length && !updated.length && !archived.length) {
|
|
395
398
|
err('[learn] nothing new to store (all duplicates).\n');
|
|
396
399
|
}
|
|
400
|
+
} else if (verdict === 'advisory') {
|
|
401
|
+
err(output);
|
|
397
402
|
} else {
|
|
398
403
|
out(output);
|
|
399
404
|
}
|
|
400
405
|
if (proc.returncode !== 0 && proc.stderr) err(proc.stderr);
|
|
401
|
-
|
|
406
|
+
// After an advisory, the model CLI's code is not this hook's: exit 2 on Stop would turn the
|
|
407
|
+
// advisory into a block, and any non-zero drops the JSON already on stdout.
|
|
408
|
+
return verdict === 'advisory' ? 0 : proc.returncode;
|
|
402
409
|
}
|
package/js/hosts/hooks-prims.mjs
CHANGED
|
@@ -123,6 +123,10 @@ export function readStdin() {
|
|
|
123
123
|
return stdinText;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// The done gate's own list (#289): `./done-checks.mjs` reads it, `./hooks.mjs`'s rule-gate
|
|
127
|
+
// protects it. Here because both need it and only this module is in both closures.
|
|
128
|
+
export const DONE_LIST = '.geneseed/done-checks.txt';
|
|
129
|
+
|
|
126
130
|
// Law I's boundary half — rule-gate's credential scan, and the activity writer's redaction of
|
|
127
131
|
// every snippet it puts on disk. Here, not in `./hooks.mjs`, so the writer reads the one copy
|
|
128
132
|
// without loading the gates. High-precision vendor prefixes only — a generic "looks like
|
package/js/hosts/hooks.mjs
CHANGED
|
@@ -56,16 +56,17 @@
|
|
|
56
56
|
*/
|
|
57
57
|
import { readFileSync, appendFileSync, writeFileSync } from 'node:fs';
|
|
58
58
|
import path from 'node:path';
|
|
59
|
-
import { printOut as out, printErr as err } from '../lib/fs.mjs';
|
|
59
|
+
import { printOut as out, printErr as err, withDiscardableStderr } from '../lib/fs.mjs';
|
|
60
60
|
import { normcase } from '../lib/paths.mjs';
|
|
61
|
+
import { isDict, isTruthy, parseJson, readJsonc } from '../lib/json.mjs';
|
|
61
62
|
import {
|
|
62
63
|
GATE_LEDGER, globalHookStandingDown, hookProjectDir, resolvePath, sovereignBypass,
|
|
63
64
|
} from './hosts.mjs';
|
|
64
65
|
import { currentBranch, gitRootOf, loopLaunched } from './gitref.mjs';
|
|
65
66
|
import { LOSS_CANDIDATE_RE, catastrophic, lossReason, stripStructure } from './loss.mjs';
|
|
66
|
-
import { selfAndParents, readStdin, SECRET_RE } from './hooks-prims.mjs';
|
|
67
|
+
import { selfAndParents, readStdin, SECRET_RE, DONE_LIST } from './hooks-prims.mjs';
|
|
67
68
|
import { recordUse } from './usage.mjs';
|
|
68
|
-
import { ownershipBlock } from './ownership-gate.mjs';
|
|
69
|
+
import { WRITE_NAME_RE, ownershipBlock } from './ownership-gate.mjs';
|
|
69
70
|
|
|
70
71
|
// ======================================================================================
|
|
71
72
|
// git-gate — Doctrine process 5's tool-boundary backstop
|
|
@@ -576,9 +577,8 @@ function ruleGateTarget(p, root) {
|
|
|
576
577
|
const DOTENV_RE = /(^|[\\/])\.env(\.[^\\/]*)?$/;
|
|
577
578
|
|
|
578
579
|
export const SENSOR_LIST = '.geneseed/protected-checks.txt';
|
|
579
|
-
// The done gate's list (`./hooks-
|
|
580
|
-
// protected-checks list: emptying it would disarm the gate it feeds.
|
|
581
|
-
export const DONE_LIST = '.geneseed/done-checks.txt';
|
|
580
|
+
// The done gate's list (`DONE_LIST`, `./hooks-prims.mjs`; #289) protects itself too, with or
|
|
581
|
+
// without a protected-checks list: emptying it would disarm the gate it feeds.
|
|
582
582
|
/**
|
|
583
583
|
* External Gate's boundary half: the checks an agent is judged by must sit outside what it can
|
|
584
584
|
* edit, or a failing check is one edit away from a passing one. A project opts in by listing
|
|
@@ -611,6 +611,126 @@ function protectedIn(target) {
|
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
+
/**
|
|
615
|
+
* External Gate's other half: the GATES' OWN configuration. A file the agent can edit that turns
|
|
616
|
+
* a gate off is a gate the agent can switch off, so a write to one asks like a protected check
|
|
617
|
+
* (audit 2026-10-28, R4/C5). Three anchors, each matched by exact name, never by folder prefix:
|
|
618
|
+
* * the install root (`--root`): the hook wiring (`settings.json`, `settings.local.json`, Bob
|
|
619
|
+
* global's `settings/settings.json` — `claudeWire`), `excludes.json` (`sovereignBypass`), the
|
|
620
|
+
* `AGENT.md` gate markers (`Done gate: off`, read by `cmdContext`; every marker is read back
|
|
621
|
+
* by a rebuild), and `.geneseed-manifest.json` / `.geneseed-emit` (`globalHookStandingDown`);
|
|
622
|
+
* * any host project dir the target sits in (`<dir>/.claude/settings.json` and kin, found by
|
|
623
|
+
* the parent's — or for `settings/settings.json` the grandparent's — folder name, so a
|
|
624
|
+
* monorepo subpackage or a dir with no `.git` is covered): Claude reads project settings
|
|
625
|
+
* from the session's own dir (`globalHookStandingDown`), the team file can set
|
|
626
|
+
* `disableAllHooks`, which Claude applies live, and a forged project manifest + settings makes
|
|
627
|
+
* a global gate stand down; and any `opencode.json(c)`, a name only OpenCode's config wears
|
|
628
|
+
* (OpenCode reads it from every dir up to the git root);
|
|
629
|
+
* * the machine-wide hook shim dir (`$GENESEED_HOME/bin`, `shimHome` in `./shim.mjs`, inlined
|
|
630
|
+
* because that module is not on this path) — every Claude/Bob hook command runs through it.
|
|
631
|
+
* Read twice like `protectedCheck`, so a link into one of these never loosens the gate. On Bob
|
|
632
|
+
* the ask is a block, except for a hook-settings file (`bobSettingsChange` below). The OpenCode
|
|
633
|
+
* guard holds these lists minus the hook settings and OpenCode's own files, which OpenCode asks about natively
|
|
634
|
+
* (`opencodeEditAsks` in ./settings.mjs; tests/plugins/guard.test.mjs pins the difference). The CLI
|
|
635
|
+
* (`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.
|
|
637
|
+
*/
|
|
638
|
+
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
|
+
const GATE_CONFIG_MARKERS = ['.claude', '.openclaude', '.bob', '.opencode'];
|
|
640
|
+
export const GATE_CONFIG_ASK = 'is a gate\'s own configuration (the hook wiring, the exclusion list, a gate switch or the hook shim). Editing it could switch a check off: fix the code, not the gate, unless the user asks for this edit. Stop and ask the user now; never write it another way (for example through a shell command).';
|
|
641
|
+
function gateConfig(p, root) {
|
|
642
|
+
let bin = null;
|
|
643
|
+
try {
|
|
644
|
+
bin = normcase(path.join(withDiscardableStderr(() => resolvePath(process.env.GENESEED_HOME || '~/.geneseed')), 'bin'));
|
|
645
|
+
} catch { /* a `~user` GENESEED_HOME: no shim dir to compare, the other anchors still run */ }
|
|
646
|
+
try {
|
|
647
|
+
const roots = root ? [path.resolve(root), resolvePath(root)] : [];
|
|
648
|
+
for (const target of [path.resolve(p), resolvePath(p)]) {
|
|
649
|
+
const t = normcase(target);
|
|
650
|
+
if (bin && t.startsWith(bin + path.sep)) return true;
|
|
651
|
+
if (/^opencode\.jsonc?$/.test(path.basename(t))) return true;
|
|
652
|
+
const up = [path.dirname(target), path.dirname(path.dirname(target))];
|
|
653
|
+
const homes = [...roots, ...up.filter((d) => GATE_CONFIG_MARKERS.some((m) => normcase(m) === normcase(path.basename(d))))];
|
|
654
|
+
if (homes.some((h) => GATE_CONFIG_FILES.some((f) => normcase(path.join(h, f)) === t))) return true;
|
|
655
|
+
}
|
|
656
|
+
} catch { /* an unresolvable path is no hit, like `protectedIn` */ }
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Bob's half of External Gate on its own settings (A2 L2). Bob has no ask tier and no native
|
|
662
|
+
* per-path approval (bob.ibm.com approval settings work per tool group), so an ask there is a
|
|
663
|
+
* block — and blocking every edit of the user's shared `settings.json` was rejected. So on Bob a
|
|
664
|
+
* hook-settings file passes unless the write CHANGES Geneseed's own wiring: the after-text is
|
|
665
|
+
* rebuilt from the tool call, both sides are parsed, and the write is blocked when the set of
|
|
666
|
+
* `event|matcher|hook` entries whose command names `geneseed-hook` differs, `disableAllHooks`
|
|
667
|
+
* turns on, or an env value the hook reads changes (`GENESEED_*`, `*_CONFIG_DIR`, `NODE_OPTIONS`).
|
|
668
|
+
* Fail closed: a tool we cannot replay (a regex, case-folded or line-ranged search, a diff of more
|
|
669
|
+
* than one block), a search not found exactly once, or an after-text Bob might not parse (JSONC
|
|
670
|
+
* where the file was strict JSON) returns a reason, never a pass.
|
|
671
|
+
* @returns {string | null} why the write is refused, or null when Geneseed's wiring is untouched
|
|
672
|
+
*/
|
|
673
|
+
const SETTINGS_RE = /(^|[\\/])(settings\.json|settings\.local\.json)$/i;
|
|
674
|
+
function settingsAfter(before, payload) {
|
|
675
|
+
const ti = payload.tool_input || {};
|
|
676
|
+
const tool = payload.tool_name;
|
|
677
|
+
if (tool === 'write_file' || tool === 'write_to_file' || tool === 'Write') {
|
|
678
|
+
return typeof ti.content === 'string' ? ti.content : null;
|
|
679
|
+
}
|
|
680
|
+
const line = Number(ti.line); // Roo-lineage tools may send it as a string
|
|
681
|
+
if (tool === 'insert_content' && typeof ti.content === 'string' && Number.isInteger(line) && line >= 0) {
|
|
682
|
+
const lines = before.split('\n');
|
|
683
|
+
lines.splice(line === 0 ? lines.length : line - 1, 0, ...ti.content.split('\n'));
|
|
684
|
+
return lines.join('\n');
|
|
685
|
+
}
|
|
686
|
+
const once = (text, search, replace) => (typeof search === 'string' && search && typeof replace === 'string'
|
|
687
|
+
&& text.split(search).length === 2 ? text.replace(search, () => replace) : null);
|
|
688
|
+
if (tool === 'search_and_replace') {
|
|
689
|
+
const ranged = ti.use_regex || ti.ignore_case || ti.start_line != null || ti.end_line != null;
|
|
690
|
+
return ranged ? null : once(before, ti.search, ti.replace);
|
|
691
|
+
}
|
|
692
|
+
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)];
|
|
694
|
+
let text = before;
|
|
695
|
+
for (const [, search, replace] of blocks) if ((text = once(text, search, replace)) === null) return null;
|
|
696
|
+
// One block only: with several, Bob may apply some and refuse others (its start-line window).
|
|
697
|
+
return blocks.length === 1 ? text : null;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
function geneseedWiring(data) {
|
|
702
|
+
const keys = [];
|
|
703
|
+
const hooks = isDict(data.hooks) ? data.hooks : {};
|
|
704
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
705
|
+
for (const g of Array.isArray(groups) ? groups : []) {
|
|
706
|
+
for (const h of (g && Array.isArray(g.hooks)) ? g.hooks : []) {
|
|
707
|
+
if (h && typeof h.command === 'string' && h.command.includes('geneseed-hook')) {
|
|
708
|
+
keys.push(JSON.stringify([event, g.matcher ?? null, h]));
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
const env = isDict(data.env) ? data.env : {};
|
|
714
|
+
for (const [k, v] of Object.entries(env)) {
|
|
715
|
+
if (/^GENESEED_|_CONFIG_DIR$|^NODE_OPTIONS$/i.test(k)) keys.push(JSON.stringify(['env', k, v]));
|
|
716
|
+
}
|
|
717
|
+
return keys.sort().join('\n');
|
|
718
|
+
}
|
|
719
|
+
function bobSettingsChange(p, payload) {
|
|
720
|
+
let before = '';
|
|
721
|
+
const file = path.resolve(typeof payload.cwd === 'string' ? payload.cwd : '.', p);
|
|
722
|
+
try { before = readFileSync(file, 'utf8'); } catch (e) { if (e.code !== 'ENOENT') return 'it could not be read'; }
|
|
723
|
+
const after = settingsAfter(before, payload);
|
|
724
|
+
if (after === null) return 'the edit could not be replayed to check it';
|
|
725
|
+
const [a] = readJsonc(before.trim() ? before : '{}');
|
|
726
|
+
const [b] = readJsonc(after.trim() ? after : '{}');
|
|
727
|
+
if (!isDict(a) || !isDict(b)) return 'a side of the edit is not a JSON object';
|
|
728
|
+
const strict = (t) => { try { parseJson(t.trim() ? t : '{}'); return true; } catch { return false; } };
|
|
729
|
+
if (strict(before) && !strict(after)) return 'it turns strict JSON into JSONC, which Bob may refuse to read';
|
|
730
|
+
if (isTruthy(b.disableAllHooks) && !isTruthy(a.disableAllHooks)) return 'it turns on disableAllHooks';
|
|
731
|
+
return geneseedWiring(a) === geneseedWiring(b) ? null : 'it changes Geneseed\'s own hook entries';
|
|
732
|
+
}
|
|
733
|
+
|
|
614
734
|
function ruleGate(args) {
|
|
615
735
|
if (sovereignBypass(args.root)) return 0;
|
|
616
736
|
return ruleDecide(args, readPayload());
|
|
@@ -656,6 +776,19 @@ function ruleDecide(args, payload) {
|
|
|
656
776
|
: `${sensor}, listed in ${SENSOR_LIST}`}). A check the agent can edit is not a `
|
|
657
777
|
+ 'check: fix the code, not the check, unless the user asks for this edit.');
|
|
658
778
|
}
|
|
779
|
+
// Bob routes reads here too (`read_file` carries a path): only a write is this gate's business.
|
|
780
|
+
// Bob never reads `opencode.json(c)`, OpenCode's whole host config: it is not gated from Bob.
|
|
781
|
+
const bobWrite = HOST !== 'bob' || (WRITE_NAME_RE.test(String((payload && payload.tool_name) || ''))
|
|
782
|
+
&& !/^opencode\.jsonc?$/i.test(path.basename(p)));
|
|
783
|
+
if (bobWrite && gateConfig(p, args.root)) {
|
|
784
|
+
// Bob: a hook-settings file is the user's shared host config — refused only when the write
|
|
785
|
+
// touches Geneseed's wiring (`bobSettingsChange`); a pass falls through to the checks below.
|
|
786
|
+
const why = HOST === 'bob' && SETTINGS_RE.test(p) ? bobSettingsChange(p, payload) : '';
|
|
787
|
+
if (why !== null) {
|
|
788
|
+
return ask(args, 'rule-gate', 'rigor-5', `Geneseed (External Gate) — ${p} ${GATE_CONFIG_ASK}`
|
|
789
|
+
+ (why ? ` On Bob this write is refused because ${why}.` : ''));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
659
792
|
const target = ruleGateTarget(p, args.root);
|
|
660
793
|
if (!target) {
|
|
661
794
|
// The ownership first-write gate (./ownership-gate.mjs), last: every rule above outranks it.
|
package/js/hosts/hosts.mjs
CHANGED
|
@@ -29,6 +29,12 @@ export const EXCLUDES_FILE = 'excludes.json';
|
|
|
29
29
|
|
|
30
30
|
/** The gate ledger inside an install: the hooks append to it, `status` counts it. */
|
|
31
31
|
export const GATE_LEDGER = path.join('notebook', 'gates.jsonl');
|
|
32
|
+
/**
|
|
33
|
+
* The ledger verb of the done gate's ADVISORY (inferred checks, `hooks-done.mjs`): recorded so
|
|
34
|
+
* it can be found, but it asked nothing of anyone, so the ask counts (`status`, `/api/gates`)
|
|
35
|
+
* skip it — an advisory fires on almost every editing turn and would drown the real asks.
|
|
36
|
+
*/
|
|
37
|
+
export const ADVISORY_VERB = 'done-gate-advisory';
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* `sovereign_bypass` — the user's own excludes.json, read on EVERY hook call so an edit
|
package/js/hosts/native.mjs
CHANGED
|
@@ -45,7 +45,7 @@ import { lstripNewlines } from './settings.mjs';
|
|
|
45
45
|
const SKILL_DIR_PLACEHOLDER = '<this-skill-directory>';
|
|
46
46
|
|
|
47
47
|
/** Mirrors `_build_core.VENDORED_SKILL_DIRS`. */
|
|
48
|
-
export const VENDORED_SKILL_DIRS = new Set(['react-view-transitions', 'daydream', 'token-report', 'explain-changes']);
|
|
48
|
+
export const VENDORED_SKILL_DIRS = new Set(['react-view-transitions', 'daydream', 'token-report', 'explain-changes', 'diagram-design']);
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* `PurePath(rel).parts` — split on EITHER separator, empties dropped.
|
package/js/hosts/owned.mjs
CHANGED
|
@@ -185,6 +185,25 @@ export function recordedDenies(doc) {
|
|
|
185
185
|
return Array.isArray(d) ? d.filter((n) => typeof n === 'string') : [];
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* An OpenCode manifest's `permission.edit` record — `edit_asks`, the gate-config ask keys
|
|
190
|
+
* Geneseed itself added, and `edit_shorthand`, the user's blanket `"allow"` it widened to an
|
|
191
|
+
* object — as `{ asks, shorthand }`. Absent or malformed reads as nothing owned, like
|
|
192
|
+
* `recordedDenies`, and for the same reason: rebuild and uninstall must agree on what is ours.
|
|
193
|
+
*/
|
|
194
|
+
export function recordedEdit(doc) {
|
|
195
|
+
const a = doc && doc.edit_asks;
|
|
196
|
+
return {
|
|
197
|
+
asks: Array.isArray(a) ? a.filter((k) => typeof k === 'string') : [],
|
|
198
|
+
shorthand: doc && doc.edit_shorthand === 'allow' ? 'allow' : null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The manifest keys for an edit record; none when Geneseed owns nothing there. */
|
|
203
|
+
export function editRecordKeys(rec) {
|
|
204
|
+
return rec.asks.length ? { edit_asks: rec.asks, ...(rec.shorthand ? { edit_shorthand: rec.shorthand } : {}) } : {};
|
|
205
|
+
}
|
|
206
|
+
|
|
188
207
|
/**
|
|
189
208
|
* Where one owned file stands against its recorded hash — the table rebuild, prune and
|
|
190
209
|
* uninstall branch on so none of them clobbers a user's edit to a Geneseed-owned file.
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* never sees the developer's answer, so "once" is a marker: the root is recorded per session
|
|
8
8
|
* BEFORE the refusal, and every later write in that (session, repo) passes. The `AGENT.md`
|
|
9
9
|
* pointer line carries the rest, shell writes included (this gate sees Write|Edit|NotebookEdit,
|
|
10
|
-
* and Bob's write tools, only).
|
|
10
|
+
* and Bob's write tools, only). A developer's personal `Setup: declined <date>` line in
|
|
11
|
+
* `.geneseed/ownership.md` defers it in that repo with no expiry (`DECLINED_RE`), and
|
|
12
|
+
* `ownershipLine` turns the same line into a SessionStart reminder.
|
|
11
13
|
*
|
|
12
14
|
* ON THE HOOK PATH, so builtins plus `gitRootOf` and `normcase` only — both already loaded by
|
|
13
15
|
* `./hooks.mjs`. `managedBlockWrite`'s delimiters are inlined, not imported: `settings.mjs` is a
|
|
@@ -21,7 +23,7 @@ import { appendFileSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
21
23
|
import os from 'node:os';
|
|
22
24
|
import path from 'node:path';
|
|
23
25
|
import { normcase } from '../lib/paths.mjs';
|
|
24
|
-
import { gitRootOf } from './gitref.mjs';
|
|
26
|
+
import { gitRootOf, mainWorktreeOf } from './gitref.mjs';
|
|
25
27
|
|
|
26
28
|
// D5: the build manifests that make a git root an "application". Exact names, plus two families.
|
|
27
29
|
const MANIFESTS = new Set(['package.json', 'pom.xml', 'pyproject.toml', 'go.mod', 'Cargo.toml',
|
|
@@ -35,7 +37,7 @@ const MANAGED_BLOCK_RE = /<!-- BEGIN GENESEED -->[\s\S]*?<!-- END GENESEED -->/g
|
|
|
35
37
|
const SECTION_RE = /^## Ownership[ \t]*\r?$/m;
|
|
36
38
|
|
|
37
39
|
// Write-shaped tool names (Bob's `tool-gate` also routes reads here: `read_file` carries a path).
|
|
38
|
-
const WRITE_NAME_RE = /write|edit|diff|replace|insert/i;
|
|
40
|
+
export const WRITE_NAME_RE = /write|edit|diff|replace|insert/i;
|
|
39
41
|
|
|
40
42
|
// js/hosts/activity.mjs `safeStem`, copied (that module is not on the gate path): a hostile
|
|
41
43
|
// session id can never steer the marker join out of its directory.
|
|
@@ -53,12 +55,65 @@ const TAIL = 'Opt out per repo: `## Ownership` with `mode: off` in the root `AGE
|
|
|
53
55
|
+ 'install: rebuild with `--no-ownership-gate`. Offer the full documentation '
|
|
54
56
|
+ '(`/document-project`) as yes / later. Stop and ask the developer now; re-issue the write only '
|
|
55
57
|
+ 'after they answer. This gate fires once per session and repo.';
|
|
58
|
+
// D5: three answers. Only the third writes anything — the durable, personal decline below.
|
|
59
|
+
const SKIP = 'skip this session; or skip in this repo until they ask — only on that third answer, '
|
|
60
|
+
+ 'write the line `Setup: declined <YYYY-MM-DD>` (today) into `.geneseed/ownership.md` at the '
|
|
61
|
+
+ 'MAIN worktree\'s root (in a linked git worktree, the main checkout\'s, so it outlives this '
|
|
62
|
+
+ 'worktree), which is personal and never committed (if `.geneseed/.gitignore` is absent there, '
|
|
63
|
+
+ 'create it first, as the ownership skill\'s checkpoint rules say)';
|
|
56
64
|
const REASON_NONE = 'Geneseed (Ownership) — this application has no `AGENTS.md` with '
|
|
57
|
-
+ '`## Ownership`. Before writing, propose to the developer: set it up
|
|
58
|
-
+ `
|
|
65
|
+
+ '`## Ownership`. Before writing, propose three answers to the developer: set it up now '
|
|
66
|
+
+ `(ownership skill); ${SKIP}. ${TAIL}`;
|
|
59
67
|
const REASON_NO_SECTION = 'Geneseed (Ownership) — this application\'s `AGENTS.md` has no '
|
|
60
|
-
+ '`## Ownership` section. Before writing, ask the developer: add the Ownership section '
|
|
61
|
-
+ `(ownership skill)
|
|
68
|
+
+ '`## Ownership` section. Before writing, ask the developer: add the Ownership section now '
|
|
69
|
+
+ `(ownership skill); ${SKIP}? ${TAIL}`;
|
|
70
|
+
|
|
71
|
+
// D2: the developer's durable, personal, per-repo decline, in `.geneseed/ownership.md`. It holds
|
|
72
|
+
// until the line is deleted or the setup runs (which removes it); a `## Ownership` section in
|
|
73
|
+
// `AGENTS.md`, on or off, outranks it. The OpenCode twins (geneseed-guard.js,
|
|
74
|
+
// geneseed-context.js) carry this same pattern, so the gate defers exactly where the reminder
|
|
75
|
+
// prints. A malformed line matches nothing, and the gate behaves as before.
|
|
76
|
+
//
|
|
77
|
+
// The line lives in the MAIN worktree (user ruling 2026-10-29): Claude Desktop opens a fresh
|
|
78
|
+
// linked worktree per session, so a decline kept in one would die with it. Only this lookup
|
|
79
|
+
// moves; the section, the manifest test and the session marker stay on the current git root.
|
|
80
|
+
// `mainWorktreeOf` is null for a main worktree, a bare common dir or a malformed link, and the
|
|
81
|
+
// lookup then falls back to the current root.
|
|
82
|
+
export const DECLINED_RE = /^Setup:[ \t]*declined[ \t]+(\d{4}-\d{2}-\d{2})[ \t]*\r?$/m;
|
|
83
|
+
|
|
84
|
+
/** The decline's date, or null (no file, no line, unreadable). Never throws. */
|
|
85
|
+
function declinedSince(root) {
|
|
86
|
+
try {
|
|
87
|
+
const home = mainWorktreeOf(root) ?? root;
|
|
88
|
+
// A leading BOM (some editors write one) would hide a first-line `Setup:` from `^`.
|
|
89
|
+
const text = readFileSync(path.join(home, '.geneseed', 'ownership.md'), 'utf8').replace(/^\uFEFF/, '');
|
|
90
|
+
return DECLINED_RE.exec(text)?.[1] ?? null;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The root `AGENTS.md` outside Geneseed's managed block; '' when there is none. */
|
|
97
|
+
function ownAgentsText(root) {
|
|
98
|
+
let text = null;
|
|
99
|
+
try { text = readFileSync(path.join(root, 'AGENTS.md'), 'utf8'); } catch { /* none */ }
|
|
100
|
+
return text === null ? '' : text.replace(MANAGED_BLOCK_RE, '');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* D4: the one SessionStart line for a declined repo (`./hooks-context.mjs` prints it beside
|
|
105
|
+
* `doneLine`), or null: not an application, a `## Ownership` section present, or no decline.
|
|
106
|
+
* Never throws.
|
|
107
|
+
*/
|
|
108
|
+
export function ownershipLine(root) {
|
|
109
|
+
try {
|
|
110
|
+
if (!root || !readdirSync(root).some(isManifest) || SECTION_RE.test(ownAgentsText(root))) return null;
|
|
111
|
+
const since = declinedSince(root);
|
|
112
|
+
return since ? `Ownership: setup declined since ${since} — not set up; say "set up ownership" to run it` : null;
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
62
117
|
|
|
63
118
|
/**
|
|
64
119
|
* The refusal reason for this write, or null to defer. `p` is the write target as the payload
|
|
@@ -82,10 +137,9 @@ export function ownershipBlock(p, payload, body, installRoot = null) {
|
|
|
82
137
|
const inInstall = path.relative(path.resolve(installRoot), target);
|
|
83
138
|
if (!inInstall.startsWith('..') && !path.isAbsolute(inInstall)) return null;
|
|
84
139
|
}
|
|
85
|
-
|
|
86
|
-
try { text = readFileSync(path.join(root, 'AGENTS.md'), 'utf8'); } catch { /* none: gate */ }
|
|
87
|
-
const own = text === null ? '' : text.replace(MANAGED_BLOCK_RE, '');
|
|
140
|
+
const own = ownAgentsText(root);
|
|
88
141
|
if (SECTION_RE.test(own)) return null; // on or off, the team has decided
|
|
142
|
+
if (declinedSince(root)) return null; // D2: the developer declined it in this repo
|
|
89
143
|
// shortcut: one small marker file per session, never pruned (the OS temp cleaner owns it);
|
|
90
144
|
// prune here if the folder is ever seen to grow past a few thousand files.
|
|
91
145
|
const dir = path.join(os.tmpdir(), `geneseed-ownership-${userTag()}`);
|