geneseed 4.28.0 → 4.29.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 +41 -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-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 +11 -3
- package/docs/concepts/ownership.md +7 -6
- 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-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 +15 -2
- 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/ownership.md +26 -4
- 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
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
copyPlugins, copyWorkflows, ensureAgentOverridesStub, writeColorThemes, writeCommandLayer,
|
|
14
14
|
writeAliasCommands, writePonytailCommand, writePrimaryAgent, writeTheme,
|
|
15
15
|
} from '../hosts/opencode.mjs';
|
|
16
|
-
import { mergeOpencodeJson, opencodeSentinelWrite } from '../hosts/settings.mjs';
|
|
16
|
+
import { mergeOpencodeJson, opencodeEditAsks, opencodeSentinelWrite } from '../hosts/settings.mjs';
|
|
17
17
|
import { isFile, readText, writeText } from '../lib/fs.mjs';
|
|
18
18
|
import { relPosix } from '../lib/text.mjs';
|
|
19
19
|
import { assertSourceComplete, build, phaseLog, ensureMemoryStore } from './bundle.mjs';
|
|
@@ -53,7 +53,7 @@ import { mkdirSync } from 'node:fs';
|
|
|
53
53
|
*/
|
|
54
54
|
function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
|
|
55
55
|
const {
|
|
56
|
-
oldOwned, manifestExisted, agentPath, wireBase, overridesDir, oldDenies = [],
|
|
56
|
+
oldOwned, manifestExisted, agentPath, wireBase, overridesDir, oldDenies = [], oldEdit = { asks: [], shorthand: null },
|
|
57
57
|
oldHashes = {},
|
|
58
58
|
} = opts;
|
|
59
59
|
ensureAgentOverridesStub(cfg, overridesDir);
|
|
@@ -98,7 +98,7 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
|
|
|
98
98
|
const wired = {};
|
|
99
99
|
const cfgName = path.basename(mergeOpencodeJson(path.join(wireBase, 'opencode.json'),
|
|
100
100
|
agentPath, cfg.doctrines, cfg.excludeRules, userOnlySkills, staleSkillNames, wired,
|
|
101
|
-
cfg.deletionGate));
|
|
101
|
+
cfg.deletionGate, opencodeEditAsks(dir, wireBase === dir, wireBase === dir ? null : agentPath), oldEdit));
|
|
102
102
|
// The next record: Geneseed's earlier denies still wanted, plus the ones it added now. A merge
|
|
103
103
|
// that wrote nothing (`skillsAdded` unset) keeps the old record whole.
|
|
104
104
|
const skillDenies = wired.skillsAdded
|
|
@@ -107,7 +107,7 @@ function opencodeLayer(cfg, items, themeName, theme, dir, owned, opts) {
|
|
|
107
107
|
|
|
108
108
|
return {
|
|
109
109
|
nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands: commands.length, cfgName,
|
|
110
|
-
skillDenies, editRefused: [...claim.editRefused],
|
|
110
|
+
skillDenies, editRecord: wired.editRecord ?? oldEdit, editRefused: [...claim.editRefused],
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -131,7 +131,7 @@ export function emitOpencodeRender(cfg, job) {
|
|
|
131
131
|
phaseLog('RENDER');
|
|
132
132
|
const {
|
|
133
133
|
theme: _theme, out, root, footprint, nativeCatalog, oldOwned, manifestExisted, agentPath,
|
|
134
|
-
oldDenies, oldHashes = {},
|
|
134
|
+
oldDenies, oldEdit, oldHashes = {},
|
|
135
135
|
} = job;
|
|
136
136
|
const oc = path.join(root, '.opencode');
|
|
137
137
|
|
|
@@ -146,9 +146,9 @@ export function emitOpencodeRender(cfg, job) {
|
|
|
146
146
|
const { theme, items } = renderAll(cfg, _theme, { footprint, nativeCatalog });
|
|
147
147
|
|
|
148
148
|
const {
|
|
149
|
-
nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRefused,
|
|
149
|
+
nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused,
|
|
150
150
|
} = opencodeLayer(cfg, items, _theme, theme, oc, owned, {
|
|
151
|
-
oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldHashes,
|
|
151
|
+
oldOwned, manifestExisted, agentPath, wireBase: root, overridesDir: out, oldDenies, oldEdit, oldHashes,
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
return {
|
|
@@ -158,6 +158,7 @@ export function emitOpencodeRender(cfg, job) {
|
|
|
158
158
|
},
|
|
159
159
|
cfgName,
|
|
160
160
|
skillDenies,
|
|
161
|
+
editRecord,
|
|
161
162
|
editRefused,
|
|
162
163
|
};
|
|
163
164
|
}
|
|
@@ -197,7 +198,7 @@ export function emitOpencodeRender(cfg, job) {
|
|
|
197
198
|
export function emitOpencodeGlobalRender(cfg, job) {
|
|
198
199
|
phaseLog('RENDER');
|
|
199
200
|
const {
|
|
200
|
-
theme: themeName, cfgDir, out, footprint, nativeCatalog, oldOwned, agentPath, oldDenies,
|
|
201
|
+
theme: themeName, cfgDir, out, footprint, nativeCatalog, oldOwned, agentPath, oldDenies, oldEdit,
|
|
201
202
|
oldHashes = {},
|
|
202
203
|
} = job;
|
|
203
204
|
|
|
@@ -223,9 +224,9 @@ export function emitOpencodeGlobalRender(cfg, job) {
|
|
|
223
224
|
// `manifestExisted` is deliberately not passed — the Python does not pass it either, so
|
|
224
225
|
// the pre-manifest header line is unreachable from this emit on both sides.
|
|
225
226
|
const {
|
|
226
|
-
nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRefused,
|
|
227
|
+
nAgents, nSkills, nPlugins, nWorkflows, primary, nCommands, cfgName, skillDenies, editRecord, editRefused,
|
|
227
228
|
} = opencodeLayer(cfg, items, themeName, theme, cfgDir, owned, {
|
|
228
|
-
oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldHashes,
|
|
229
|
+
oldOwned, agentPath, wireBase: cfgDir, overridesDir: cfgDir, oldDenies, oldEdit, oldHashes,
|
|
229
230
|
});
|
|
230
231
|
|
|
231
232
|
const memStatus = globalMemory(cfgDir, items, out, cfg.src);
|
|
@@ -250,6 +251,7 @@ export function emitOpencodeGlobalRender(cfg, job) {
|
|
|
250
251
|
nbStatus,
|
|
251
252
|
cfgName,
|
|
252
253
|
skillDenies,
|
|
254
|
+
editRecord,
|
|
253
255
|
editRefused,
|
|
254
256
|
};
|
|
255
257
|
}
|
package/js/build/render.mjs
CHANGED
|
@@ -510,6 +510,15 @@ export function effectiveTheme(cfg, themeName, { footprint = 'full', lawsPrefix
|
|
|
510
510
|
// their wording is a parsed contract.
|
|
511
511
|
theme.GATE_LINES = GATE_SWITCHES.filter((g) => cfg[g.key] === false)
|
|
512
512
|
.map((g) => `\n${g.marker}: off`).join('');
|
|
513
|
+
// The carrier's ownership proposal (ruling D6): an install built `--no-ownership-gate` has
|
|
514
|
+
// chosen silence, so it renders no proposal at all — the hook alone standing down left the
|
|
515
|
+
// model still proposing the setup from this prose. Outside any LEAN block: both footprints.
|
|
516
|
+
// Paid on every session, so the three answers are named and the skill carries the how.
|
|
517
|
+
theme.OWNERSHIP_PROPOSAL = cfg.ownershipGate === false ? '' : ' With no section at all, propose it '
|
|
518
|
+
+ 'once before the first\nwrite, shell writes included: set it up now, skip this session, or '
|
|
519
|
+
+ 'skip in this repo until\nasked (ownership skill). A context line `Ownership: setup declined '
|
|
520
|
+
+ '…` means propose nothing:\nrepeat it once, verbatim, in your first reply, after the '
|
|
521
|
+
+ 'readiness line. In read-only work,\nsuggest `/document-project` once at most.';
|
|
513
522
|
return theme;
|
|
514
523
|
}
|
|
515
524
|
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the done gate's checks come from (`./hooks-done.mjs` judges them): the project's
|
|
3
|
+
* `.geneseed/done-checks.txt`, else what its root manifests imply.
|
|
4
|
+
*
|
|
5
|
+
* Its own module because two verbs read it — `learn` on Stop and `context` at SessionStart — and
|
|
6
|
+
* `context` is in the CLI's closure (`js/inspect/cost.mjs`), which may not reach a spawn:
|
|
7
|
+
* `./hooks-done.mjs` imports `./hooks.mjs`, which does. Nothing here may spawn either.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { readText } from '../lib/fs.mjs';
|
|
12
|
+
import { DONE_LIST, splitLines } from './hooks-prims.mjs';
|
|
13
|
+
|
|
14
|
+
/** The declared checks, one per line, `#` comments; null when the project has no list. */
|
|
15
|
+
export function readDoneChecks(root) {
|
|
16
|
+
const file = path.join(root, DONE_LIST);
|
|
17
|
+
if (!existsSync(file)) return null;
|
|
18
|
+
try {
|
|
19
|
+
return splitLines(readText(file)).map((l) => l.trim().replace(/\s+/g, ' '))
|
|
20
|
+
.filter((l) => l && !l.startsWith('#'));
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The package manager a lockfile names; first hit wins, npm without one.
|
|
27
|
+
const PM_LOCKS = [['bun.lockb', 'bun'], ['bun.lock', 'bun'], ['pnpm-lock.yaml', 'pnpm'], ['yarn.lock', 'yarn']];
|
|
28
|
+
const PM_SCRIPTS = ['test', 'lint', 'typecheck'];
|
|
29
|
+
|
|
30
|
+
/** One package.json script as a check: the lockfile's own spellings, plus npm's (npm runs any). */
|
|
31
|
+
function scriptCheck(pm, s) {
|
|
32
|
+
const npm = s === 'test' ? ['npm test', 'npm run test', 'npm t'] : [`npm run ${s}`];
|
|
33
|
+
// `bun test` is bun's own runner, not the `test` script: only `bun run` runs the script.
|
|
34
|
+
const own = pm === 'npm' ? [] : pm === 'bun' ? [`bun run ${s}`] : [`${pm} ${s}`, `${pm} run ${s}`];
|
|
35
|
+
return { label: own[0] ?? npm[0], forms: [...own, ...npm] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Each wrapper spelling (POSIX and Windows) times each task that runs the tests, with and without
|
|
39
|
+
// a leading `clean`. `refuse` names the flags that make the same command skip the tests: a
|
|
40
|
+
// segment carrying one is no pass (`hooks-done.mjs`'s `groupPasses`).
|
|
41
|
+
const wrapped = (label, bins, tasks, refuse) => ({
|
|
42
|
+
label, refuse, forms: bins.flatMap((b) => tasks.flatMap((t) => [`${b} ${t}`, `${b} clean ${t}`])),
|
|
43
|
+
});
|
|
44
|
+
const MAVEN = wrapped('mvn test', ['mvn', './mvnw', '.\\mvnw', 'mvnw', 'mvnw.cmd'], ['test', 'verify', 'install'],
|
|
45
|
+
/(?:^|\s)-D(?:skipTests|maven\.test\.skip)(?=[=\s]|$)/);
|
|
46
|
+
const GRADLE = wrapped('gradle test', ['gradle', './gradlew', '.\\gradlew', 'gradlew', 'gradlew.bat'], ['test', 'build', 'check'],
|
|
47
|
+
/(?:^|\s)(?:-x|--exclude-task)[ =](?:\S*:)?test(?=\s|$)/);
|
|
48
|
+
// shortcut: no `uv`-prefixed form — that spelling trips the no-Python gates in
|
|
49
|
+
// tests/unit/package_manifest.test.mjs (user decision 2026-10-29: no exemption), so a uv user's
|
|
50
|
+
// run reads as unproven, which is only an advisory.
|
|
51
|
+
const PYTEST = { label: 'pytest', forms: ['pytest', 'python -m pytest', 'python3 -m pytest', 'py -m pytest', 'poetry run pytest'] };
|
|
52
|
+
const MANIFEST_CHECKS = [
|
|
53
|
+
['pom.xml', MAVEN],
|
|
54
|
+
['build.gradle', GRADLE],
|
|
55
|
+
['build.gradle.kts', GRADLE],
|
|
56
|
+
['pyproject.toml', PYTEST],
|
|
57
|
+
['Cargo.toml', { label: 'cargo test', forms: ['cargo test'], refuse: /(?:^|\s)--no-run(?=\s|$)/ }],
|
|
58
|
+
['go.mod', { label: 'go test', forms: ['go test'] }],
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* Every root manifest the checks are inferred from — what an emit seeds into the protected list.
|
|
62
|
+
* @type {string[]}
|
|
63
|
+
*/
|
|
64
|
+
export const INFERRED_FROM = ['package.json', ...MANIFEST_CHECKS.map(([f]) => /** @type {string} */ (f))];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The checks the root's manifests imply, and which manifests implied them. npm's default `test`
|
|
68
|
+
* script (`echo "Error: no test specified" && exit 1`) is no check: it fails by design. A
|
|
69
|
+
* pyproject.toml implies `pytest` only where pytest shows: `[tool.pytest` in it, or a
|
|
70
|
+
* `pytest.ini`, `conftest.py` or `tests/` at the root — else a unittest-only or test-less repo
|
|
71
|
+
* would owe an advisory it can never clear.
|
|
72
|
+
*
|
|
73
|
+
* shortcut: KNOWN UNSEEN FORMS. Every one reads as "not run", so it costs a stray advisory, never
|
|
74
|
+
* a false pass; add a form here when a real transcript shows one:
|
|
75
|
+
* - the git root's manifests only — a monorepo's subprojects (`pnpm -r test`,
|
|
76
|
+
* `./gradlew :app:test`, `mvn -pl core test`) are neither inferred nor matched;
|
|
77
|
+
* - a sibling script (`npm run test:unit`) or a runner called directly (`npx vitest`);
|
|
78
|
+
* - a prefix before the command (`CI=1 npm test`, `mvn -q test`): forms match verbatim.
|
|
79
|
+
*/
|
|
80
|
+
export function inferDoneChecks(root) {
|
|
81
|
+
const has = (f) => existsSync(path.join(root, f));
|
|
82
|
+
const sources = [];
|
|
83
|
+
const checks = [];
|
|
84
|
+
const add = (source, list) => {
|
|
85
|
+
if (!list.length) return;
|
|
86
|
+
sources.push(source);
|
|
87
|
+
for (const c of list) if (!checks.some((k) => k.label === c.label)) checks.push(c);
|
|
88
|
+
};
|
|
89
|
+
if (has('package.json')) {
|
|
90
|
+
let scripts = null;
|
|
91
|
+
try { scripts = JSON.parse(readText(path.join(root, 'package.json'))).scripts; } catch { /* unreadable: none */ }
|
|
92
|
+
if (!scripts || typeof scripts !== 'object') scripts = {};
|
|
93
|
+
const pm = (PM_LOCKS.find(([f]) => has(f)) ?? [null, 'npm'])[1];
|
|
94
|
+
add('package.json', PM_SCRIPTS.filter((s) => typeof scripts[s] === 'string'
|
|
95
|
+
&& !(s === 'test' && /no test specified/.test(scripts[s]))).map((s) => scriptCheck(pm, s)));
|
|
96
|
+
}
|
|
97
|
+
const pytestShows = () => {
|
|
98
|
+
let toml = '';
|
|
99
|
+
try { toml = readText(path.join(root, 'pyproject.toml')); } catch { /* unreadable: no section */ }
|
|
100
|
+
return toml.includes('[tool.pytest') || ['pytest.ini', 'conftest.py', 'tests'].some(has);
|
|
101
|
+
};
|
|
102
|
+
for (const [file, check] of MANIFEST_CHECKS) {
|
|
103
|
+
if (has(file) && (check !== PYTEST || pytestShows())) add(file, [check]);
|
|
104
|
+
}
|
|
105
|
+
return { sources, checks };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The project's checks: `{ source, blocking, checks: [{ label, forms, refuse? }] }`. The file, when
|
|
110
|
+
* present, wins and blocks; else the inference, advisory. `source` names where they came from.
|
|
111
|
+
*/
|
|
112
|
+
export function doneChecksOf(root) {
|
|
113
|
+
const listed = readDoneChecks(root);
|
|
114
|
+
if (listed) return { source: DONE_LIST, blocking: true, checks: listed.map((l) => ({ label: l, forms: [l] })) };
|
|
115
|
+
const { sources, checks } = inferDoneChecks(root);
|
|
116
|
+
return { source: sources.join(', '), blocking: false, checks };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The one SessionStart line naming the done gate's checks for the repo at `root`. `judged` false
|
|
121
|
+
* is a host that never judges a turn (Bob: its Stop carries no transcript): the line names the
|
|
122
|
+
* checks but claims no verdict.
|
|
123
|
+
*/
|
|
124
|
+
export function doneLine(root, judged = true) {
|
|
125
|
+
const { source, blocking, checks } = doneChecksOf(root);
|
|
126
|
+
const names = checks.map((c) => c.label).join(', ');
|
|
127
|
+
const how = (verdict) => (judged ? verdict : 'not judged on this host');
|
|
128
|
+
if (blocking) {
|
|
129
|
+
return checks.length ? `Done gate: from ${source} — ${names} (${how('blocking')})`
|
|
130
|
+
: `Done gate: off — ${source} lists no checks`;
|
|
131
|
+
}
|
|
132
|
+
return checks.length ? `Done gate: inferred from ${source} — ${names} (${how('advisory')})`
|
|
133
|
+
: 'Done gate: no checks could be inferred';
|
|
134
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Node-side writers into a project's `<git root>/.geneseed/`: its personal-by-default
|
|
3
|
+
* `.gitignore`, and the protected-checks list a PROJECT emit seeds (A3, audit 2026-10-28).
|
|
4
|
+
*
|
|
5
|
+
* Why seed at all: the done gate infers its checks from the manifest (`done-checks.mjs`), so an
|
|
6
|
+
* agent that edits `package.json` lowers its own bar — and the protected-checks gate
|
|
7
|
+
* (`protectedIn`, `js/hosts/hooks.mjs`) asks only when the list exists. A fresh install armed
|
|
8
|
+
* nothing. The seed lists only paths that exist at that root, so no line is stale.
|
|
9
|
+
*
|
|
10
|
+
* SEED ONCE, then the file is the user's: created only when absent, never rewritten, never
|
|
11
|
+
* pruned, never deleted on uninstall, and recorded in no manifest. Owning it broke two ways
|
|
12
|
+
* (review 2026-10-29): two hosts in one repo, where one uninstall deleted the other's seed, and a
|
|
13
|
+
* committed seed plus a committed manifest, where every teammate's rebuild rewrote the team's
|
|
14
|
+
* list. To opt out, the user empties it; an existing file, even comment-only, is never re-seeded.
|
|
15
|
+
*
|
|
16
|
+
* Never throws: a `.geneseed` that is a file, a link or read-only must not cost the emit its
|
|
17
|
+
* manifest (the next emit would then read the whole install as the user's). Spawn-free.
|
|
18
|
+
*/
|
|
19
|
+
import { lstatSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { INFERRED_FROM } from './done-checks.mjs';
|
|
22
|
+
import { gitRootOf } from './gitref.mjs';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The `.geneseed/.gitignore` every writer creates: personal by default, the team paths allowed
|
|
26
|
+
* back. Anchored `/*`: a bare `*` matches at every depth and would hide `bricks/x.md` even under
|
|
27
|
+
* `!bricks/`. The same string lives in `adapters/opencode/plugins/geneseed-workflow.js`,
|
|
28
|
+
* `adapters/opencode/workflows/_runtime.js` and `src/skills/_checkpoints.md`; tests pin them.
|
|
29
|
+
*/
|
|
30
|
+
export const GENESEED_GITIGNORE = '/*\n!/.gitignore\n!/bricks/\n!/loops/\n!/protected-checks.txt\n!/done-checks.txt\n';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create-if-absent; a file holding only `*` is Geneseed's former output (it hid team bricks),
|
|
34
|
+
* never a user edit, so it is upgraded. Any other content, or a link, is the user's. Never
|
|
35
|
+
* throws: hygiene must not fail an emit. Same content rules as `writeGitignore` in the two
|
|
36
|
+
* OpenCode copies, but NOT the same link handling: those still write through a symlinked
|
|
37
|
+
* `.gitignore` (a known follow-up); this one refuses to.
|
|
38
|
+
*/
|
|
39
|
+
export function writeGeneseedGitignore(file) {
|
|
40
|
+
try { writeFileSync(file, GENESEED_GITIGNORE, { flag: 'wx' }); } catch {
|
|
41
|
+
try {
|
|
42
|
+
if (!lstatSync(file).isSymbolicLink() && /^\*(\r?\n)?$/.test(readFileSync(file, 'utf8'))) {
|
|
43
|
+
writeFileSync(file, GENESEED_GITIGNORE);
|
|
44
|
+
}
|
|
45
|
+
} catch { /* contained */ }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The seeded list, relative to the git root. */
|
|
50
|
+
export const SEED_REL = '.geneseed/protected-checks.txt';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* What a project's checks live in. A string ending `/` is a folder, any other string a file; a
|
|
54
|
+
* regex matches file names at the root. Lockfiles are not listed: they move on every install.
|
|
55
|
+
*/
|
|
56
|
+
const CANDIDATES = [
|
|
57
|
+
'.github/workflows/', '.gitlab-ci.yml', 'Jenkinsfile', 'azure-pipelines.yml', '.circleci/',
|
|
58
|
+
/^eslint\.config\./, /^\.eslintrc/, 'biome.json', 'biome.jsonc', 'tsconfig.json',
|
|
59
|
+
/^jest\.config\./, /^vitest\.config\./, 'pytest.ini', 'ruff.toml', '.golangci.yml', 'checkstyle.xml',
|
|
60
|
+
...INFERRED_FROM,
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const SEED_HEADER = '# Seeded once by Geneseed with the checks found in this project; it is yours now.\n'
|
|
64
|
+
+ '# A write tool aimed at a listed path asks you first (on Bob, it is blocked): External Gate.\n'
|
|
65
|
+
+ '# One repo-relative file or folder per line; `#` starts a comment. A shell command is not\n'
|
|
66
|
+
+ '# seen: CI holds that. To opt out, delete the listed paths (the comments may stay) but keep\n'
|
|
67
|
+
+ '# the file: a missing file is seeded again.\n';
|
|
68
|
+
|
|
69
|
+
/** The seed for git root `root`, or null when none of the candidates exists there. */
|
|
70
|
+
export function protectedChecksSeed(root) {
|
|
71
|
+
const kind = (rel) => { try { return statSync(path.join(root, rel)); } catch { return null; } };
|
|
72
|
+
let names = [];
|
|
73
|
+
try { names = readdirSync(root).sort(); } catch { /* unreadable: no regex matches */ }
|
|
74
|
+
const found = [];
|
|
75
|
+
for (const c of CANDIDATES) {
|
|
76
|
+
if (typeof c !== 'string') {
|
|
77
|
+
for (const n of names) if (c.test(n) && kind(n)?.isFile() && !found.includes(n)) found.push(n);
|
|
78
|
+
} else if (c.endsWith('/') ? kind(c.slice(0, -1))?.isDirectory() : kind(c)?.isFile()) {
|
|
79
|
+
found.push(c);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return found.length ? `${SEED_HEADER}${found.join('\n')}\n` : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Seed `<git root of projectRoot>/.geneseed/protected-checks.txt` when it is absent and a
|
|
87
|
+
* candidate exists; then, whenever `.geneseed/` is a real directory, make sure its `.gitignore`
|
|
88
|
+
* exists (`writeGeneseedGitignore`). No git root: nothing. Nothing is written through a link: a
|
|
89
|
+
* `.geneseed` that is a symlink, or a leaf that is one (dangling included — `lstat`, not
|
|
90
|
+
* `exists`), is left alone. A failure is one stderr warning; the emit goes on.
|
|
91
|
+
*/
|
|
92
|
+
export function seedProtectedChecks(projectRoot) {
|
|
93
|
+
const root = gitRootOf(projectRoot);
|
|
94
|
+
if (!root) return;
|
|
95
|
+
const dir = path.join(root, '.geneseed');
|
|
96
|
+
const at = (p) => lstatSync(p, { throwIfNoEntry: false });
|
|
97
|
+
try {
|
|
98
|
+
const d = at(dir);
|
|
99
|
+
if (d && !d.isDirectory()) {
|
|
100
|
+
process.stderr.write(`[geneseed] WARN: ${dir} is not a directory — `
|
|
101
|
+
+ 'the protected-checks list was not seeded\n');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!at(path.join(dir, 'protected-checks.txt'))) {
|
|
105
|
+
const text = protectedChecksSeed(root);
|
|
106
|
+
if (text !== null) {
|
|
107
|
+
mkdirSync(dir, { recursive: true });
|
|
108
|
+
writeFileSync(path.join(dir, 'protected-checks.txt'), text, { flag: 'wx' });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (at(dir)?.isDirectory()) writeGeneseedGitignore(path.join(dir, '.gitignore'));
|
|
112
|
+
} catch (e) {
|
|
113
|
+
process.stderr.write(`[geneseed] WARN: could not seed ${SEED_REL} at ${root}: `
|
|
114
|
+
+ `${e && e.message ? e.message : e}\n`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -11,6 +11,9 @@ import { normcase, toPlatformPath } from '../lib/paths.mjs';
|
|
|
11
11
|
import { relPosix } from '../lib/text.mjs';
|
|
12
12
|
import { globalHookStandingDown, hookProjectDir, resolvePath, sovereignBypass } from './hosts.mjs';
|
|
13
13
|
import { isFile, isDir, sortPaths, listDir } from './hooks-prims.mjs';
|
|
14
|
+
import { gitRootOf } from './gitref.mjs';
|
|
15
|
+
import { doneLine } from './done-checks.mjs';
|
|
16
|
+
import { ownershipLine } from './ownership-gate.mjs';
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* `str(OSError)` — `[Errno N] strerror: 'filename'`, with the filename REPR'd.
|
|
@@ -443,9 +446,24 @@ export function cmdContext(args) {
|
|
|
443
446
|
let [eager, lazy, source] = resolveContextSets(root, hookRoot);
|
|
444
447
|
eager = eager.filter(fresh);
|
|
445
448
|
lazy = lazy.filter(fresh);
|
|
449
|
+
// The done gate's checks for this repo, and where they come from (`./hooks-done.mjs`). No git
|
|
450
|
+
// root, no gate, no line. Printed even when there is nothing else to load. An install built
|
|
451
|
+
// `--no-done-gate` carries `Done gate: off` in its AGENT.md and gets no line — the OpenCode
|
|
452
|
+
// context plugin's `doneGateOff` reads the same marker with the same pattern.
|
|
453
|
+
const gitRoot = gitRootOf(root);
|
|
454
|
+
let carrier = '';
|
|
455
|
+
try { carrier = hookRoot ? readFileSync(path.join(hookRoot, 'AGENT.md'), 'utf8') : ''; } catch { /* no carrier: armed */ }
|
|
456
|
+
const gateOff = (marker) => new RegExp(`^${marker}:[ \\t]*off[ \\t]*\\r?$`, 'm').test(carrier);
|
|
457
|
+
// Bob's Stop carries no transcript, so the gate never judges a turn there (`hooks-done.mjs`).
|
|
458
|
+
const done = gitRoot && !gateOff('Done gate') ? doneLine(gitRoot, HOST !== 'bob') : null;
|
|
459
|
+
// The ownership decline reminder (`./ownership-gate.mjs`), under the same contract: an install
|
|
460
|
+
// built `--no-ownership-gate` carries `Ownership gate: off` and gets no line.
|
|
461
|
+
const owned = gitRoot && !gateOff('Ownership gate') ? ownershipLine(gitRoot) : null;
|
|
462
|
+
const heads = [done, owned].filter(Boolean);
|
|
446
463
|
if (!session.length && !eager.length && !lazy.length) {
|
|
447
464
|
err(`[context] nothing to load for ${root} `
|
|
448
465
|
+ '(no docs discovered, no manifest entries).\n');
|
|
466
|
+
if (heads.length) out(`${heads.join('\n')}\n`);
|
|
449
467
|
return 0;
|
|
450
468
|
}
|
|
451
469
|
|
|
@@ -454,6 +472,7 @@ export function cmdContext(args) {
|
|
|
454
472
|
// the whole payload, not on the file bodies alone.
|
|
455
473
|
let spent = 0;
|
|
456
474
|
const push = (...ls) => { for (const l of ls) { lines.push(l); spent += cost(l); } };
|
|
475
|
+
if (heads.length) push(...heads, '');
|
|
457
476
|
if (session.length) {
|
|
458
477
|
push('=== SESSION FILES \u2014 your harness files, injected at session start '
|
|
459
478
|
+ '(untouched seeds skipped) ===', '');
|
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
|
}
|