geneseed 5.3.0 → 5.4.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 +95 -0
- package/README.md +23 -20
- package/SHIPPED.md +7 -7
- package/adapters/bob/README.md +31 -18
- package/adapters/claude-code/README.md +27 -22
- package/adapters/openclaude/README.md +18 -8
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +8 -3
- package/adapters/opencode/README.md +3 -2
- package/adapters/opencode/plugins/geneseed-activity.js +20 -21
- package/adapters/opencode/plugins/geneseed-context.js +175 -62
- package/adapters/opencode/plugins/geneseed-guard.js +419 -205
- package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
- package/adapters/opencode/workflows/_runtime.js +3 -2
- package/bin/geneseed-cli.mjs +7 -0
- package/bin/geneseed-hook.mjs +59 -11
- package/docs/PRD.md +1 -1
- package/docs/README.md +1 -0
- package/docs/concepts/agents.md +1 -1
- package/docs/concepts/collaboration.md +2 -2
- package/docs/concepts/enforcement-table.md +5 -2
- package/docs/concepts/exclusions.md +18 -4
- package/docs/concepts/footprint.md +11 -1
- package/docs/concepts/foreman-mode.md +1 -1
- package/docs/concepts/hook-gates.md +5 -5
- package/docs/concepts/hooks.md +4 -3
- package/docs/concepts/host-matrix.md +24 -6
- package/docs/concepts/kits.md +12 -2
- package/docs/concepts/loop-bricks.md +3 -3
- package/docs/concepts/loops.md +6 -4
- package/docs/concepts/ownership.md +1 -1
- package/docs/concepts/rules.md +2 -2
- package/docs/concepts/skills.md +1 -1
- package/docs/design-history.md +8 -0
- package/docs/extending.md +112 -35
- package/docs/guides/auto-merge.md +100 -0
- package/docs/guides/choose-your-setup.md +1 -1
- package/docs/guides/headless.md +1 -1
- package/docs/guides/install-bob.md +2 -2
- package/docs/guides/install-clone.md +1 -1
- package/docs/guides/install-openclaude.md +1 -1
- package/docs/guides/install.md +1 -1
- package/docs/guides/loop-finish.md +3 -3
- package/docs/guides/loop-running.md +4 -4
- package/docs/guides/project-context.md +1 -1
- package/docs/guides/run-a-factory.md +2 -2
- package/docs/guides/setup-doctrines.md +2 -2
- package/docs/guides/setup-footprint.md +1 -1
- package/docs/guides/uninstall.md +3 -3
- package/docs/guides/upgrade.md +1 -1
- package/docs/guides/verify.md +12 -0
- package/docs/guides/worktree.md +1 -1
- package/docs/reference/environment.md +5 -2
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/reference/plugin-guard.md +1 -1
- package/docs/reference/plugin-learn.md +1 -1
- package/docs/reference/plugin-workflow.md +1 -1
- package/docs/reference/troubleshoot-doctor.md +2 -2
- package/docs/reference/troubleshoot-hooks.md +2 -2
- package/docs/reference/troubleshoot-install.md +3 -3
- package/docs/reference/troubleshoot-tools.md +1 -1
- package/docs/token-footprint.md +68 -4
- package/docs/understand/design-choices-hosts.md +1 -1
- package/docs/understand/design-choices-shape.md +1 -0
- package/docs/understand/enforced-vs-asked.md +2 -2
- package/docs/understand/machine-bob.md +1 -1
- package/docs/understand/machine-claude.md +2 -2
- package/docs/understand/on-your-machine.md +1 -1
- package/docs/web-ui.md +10 -5
- package/harness.config.json +1 -1
- package/js/README.md +5 -3
- package/js/build/args.mjs +13 -2
- package/js/build/driver.mjs +34 -7
- package/js/build/emit-claude.mjs +9 -5
- package/js/build/emit-opencode.mjs +13 -9
- package/js/build/generate.mjs +10 -165
- package/js/build/profile.mjs +318 -0
- package/js/build/render.mjs +81 -3
- package/js/build/retired-skills.mjs +60 -13
- package/js/build/source.mjs +15 -1
- package/js/build/stubs.mjs +4 -1
- package/js/cli-table.json +48 -3
- package/js/hosts/done-checks.mjs +6 -0
- package/js/hosts/geneseed-dir.mjs +3 -2
- package/js/hosts/gitref.mjs +5 -3
- package/js/hosts/hook-tap.mjs +104 -0
- package/js/hosts/hooks-context.mjs +4 -2
- package/js/hosts/hooks-done.mjs +345 -55
- package/js/hosts/hooks-learn.mjs +51 -19
- package/js/hosts/hooks-prims.mjs +5 -3
- package/js/hosts/hooks.mjs +172 -19
- package/js/hosts/hosts.mjs +80 -12
- package/js/hosts/installs.mjs +26 -1
- package/js/hosts/native.mjs +33 -7
- package/js/hosts/owned.mjs +7 -6
- package/js/hosts/ownership-gate.mjs +14 -1
- package/js/hosts/settings.mjs +273 -105
- package/js/hosts/shim.mjs +4 -4
- package/js/hosts/usage.mjs +9 -3
- package/js/inspect/checks-constitution.mjs +32 -0
- package/js/inspect/checks-probe.mjs +66 -5
- package/js/inspect/checks-repo.mjs +196 -2
- package/js/inspect/cost.mjs +34 -2
- package/js/inspect/diff.mjs +21 -3
- package/js/inspect/doctor.mjs +6 -1
- package/js/inspect/inventory.mjs +1 -1
- package/js/lib/machine-dir.mjs +1 -1
- package/js/lib/node-floor.mjs +46 -6
- package/js/maintain/setup.mjs +5 -1
- package/js/maintain/uninstall.mjs +42 -16
- package/js/maintain/update.mjs +4 -2
- package/js/web/actions.mjs +17 -12
- package/js/web/api.mjs +7 -2
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +15 -17
- package/src/bricks/pr-open.md +3 -2
- package/src/doctrines/ops.md +2 -2
- package/src/doctrines/process.md +40 -36
- package/src/factories/analysis-to-build.json +1 -1
- package/src/factories/bug-report-to-fix.json +1 -1
- package/src/factories/issue-to-pr.json +1 -1
- package/src/kits/terminal-tools/rules.md +10 -0
- package/src/kits/terminal-tools.json +13 -0
- package/src/licenses/herdr.txt +201 -0
- package/src/modes/foreman.md +6 -3
- package/src/skills/_self-improvement.md +9 -7
- package/src/skills/commit.md +17 -17
- package/src/skills/debug/ci.md +1 -1
- package/src/skills/dependencies.md +3 -3
- package/src/skills/document-project.md +3 -2
- package/src/skills/factory.md +13 -4
- package/src/skills/geneseed.md +4 -2
- package/src/skills/git-history.md +5 -7
- package/src/skills/herdr.md +135 -0
- package/src/skills/loop.md +3 -2
- package/src/skills/opencode-cli.md +84 -0
- package/src/skills/pipeline.md +1 -1
- package/src/skills/release.md +5 -8
- package/src/skills/review-response.md +4 -2
- package/src/skills/rule.md +27 -1
- package/src/skills/ship.md +54 -7
- package/src/skills/worktree.md +2 -2
- package/src/upstreams.json +7 -0
- package/themes/_TEMPLATE.json +2 -0
- package/themes/biker.json +2 -0
- package/themes/commentator.json +2 -0
- package/themes/cyberpunk.json +2 -0
- package/themes/gamer.json +2 -0
- package/themes/imperial.json +2 -0
- package/themes/joker.json +2 -0
- package/themes/marvin.json +2 -0
- package/themes/mean.json +2 -0
- package/themes/military.json +2 -0
- package/themes/neutral.json +2 -0
- package/themes/pirate.json +2 -0
- package/themes/sports.json +2 -0
- package/themes/verstappen.json +2 -0
- package/themes/wizard.json +2 -0
- package/web/dist/assets/Activity-D2kOc3yi.js +1 -0
- package/web/dist/assets/ActivityDetail-By3xOr21.js +1 -0
- package/web/dist/assets/{Bonsai-Bfpb6W-1.js → Bonsai-CBWDTBA4.js} +1 -1
- package/web/dist/assets/{CopyButton-ByIntFtB.js → CopyButton-BVbpriMB.js} +1 -1
- package/web/dist/assets/Dashboard-CIJLPHM9.js +2 -0
- package/web/dist/assets/{Docs-DvlMJhpu.js → Docs-CiRRIELs.js} +3 -3
- package/web/dist/assets/Factories-DhyK0O8d.js +1 -0
- package/web/dist/assets/GreenhouseView-DW3PgTPy.js +1 -0
- package/web/dist/assets/Installs-B6nlo-Ly.js +3 -0
- package/web/dist/assets/JournalView-O65qEWfp.js +1 -0
- package/web/dist/assets/Kits-C5U-yT6Z.js +1 -0
- package/web/dist/assets/Laws-CuTw_XNf.js +4 -0
- package/web/dist/assets/{LibRows-DEHjIoD-.js → LibRows-D6-CVa3K.js} +1 -1
- package/web/dist/assets/Library-CzPlerd6.js +3 -0
- package/web/dist/assets/Loops-CqNF_-nS.js +2 -0
- package/web/dist/assets/Markdown-CxkA7940.js +71 -0
- package/web/dist/assets/OperatorHudView-BNr8K5qj.js +1 -0
- package/web/dist/assets/Personal-DeDb9e8O.js +2 -0
- package/web/dist/assets/Settings-B8MPN_AD.js +1 -0
- package/web/dist/assets/{Tabs-CWeQTADL.js → Tabs-DJzAez4h.js} +1 -1
- package/web/dist/assets/index-BL3P-9Rg.js +6 -0
- package/web/dist/assets/{index-CsAZq0BQ.css → index-CRWqKxfY.css} +1 -1
- package/web/dist/index.html +2 -2
- package/adapters/claude-code/settings.json +0 -52
- package/web/dist/assets/Activity-CqJiquEq.js +0 -1
- package/web/dist/assets/ActivityDetail-BSzevynX.js +0 -1
- package/web/dist/assets/Dashboard-DBOEi9lQ.js +0 -2
- package/web/dist/assets/Factories-Bpvv7L2H.js +0 -1
- package/web/dist/assets/GreenhouseView-GpBsYn50.js +0 -1
- package/web/dist/assets/Installs-BlGmVrFK.js +0 -3
- package/web/dist/assets/JournalView-iLuLrOxE.js +0 -1
- package/web/dist/assets/Kits-DRwpxC-J.js +0 -1
- package/web/dist/assets/Laws-CZkiNOWQ.js +0 -4
- package/web/dist/assets/Library-B4K-1iNF.js +0 -3
- package/web/dist/assets/Loops-BWSzaW8E.js +0 -2
- package/web/dist/assets/Markdown-0ORz7tAc.js +0 -69
- package/web/dist/assets/OperatorHudView-BAXwCEvY.js +0 -1
- package/web/dist/assets/Personal-Bp9nV4GR.js +0 -2
- package/web/dist/assets/Settings-CWWuaIp-.js +0 -1
- package/web/dist/assets/index-How7SzDZ.js +0 -6
|
@@ -408,8 +408,9 @@ behaviour** — nothing changes the machine's current agent/model unless you opt
|
|
|
408
408
|
- **Default permissions.** A fresh `opencode.json` gets a minimal policy that **asks**
|
|
409
409
|
before `git reflog expire`, `git gc --prune` and a force-push or delete of `main`/`master` —
|
|
410
410
|
**Rule IV**'s territory, in every build; the guard plugin decides every other data loss — and, **on an install that built the `process` pack in**, before every
|
|
411
|
-
`git commit` and `git push` (the host-level backstop for **Consent Before Push
|
|
412
|
-
|
|
411
|
+
`git commit` and `git push` (the host-level backstop for **Consent Before Push**). The
|
|
412
|
+
rule asks only for a commit or push onto the main branch, but a permission glob cannot read
|
|
413
|
+
which branch is checked out, so OpenCode asks for every commit and push. Build with
|
|
413
414
|
`--doctrines` leaving `process` out and those two entries are simply not written.
|
|
414
415
|
The whole block is added only when you have no `permission` key; an existing policy is
|
|
415
416
|
reconciled key by key — Geneseed adds back what a returning pack wants and removes
|
|
@@ -199,41 +199,40 @@ function ownRowsDeduped(turns, launchedIn) {
|
|
|
199
199
|
d.by != null || !since.has(d.raw) || order(key) < since.get(d.raw)))
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
// The fs-only readers below are
|
|
203
|
-
//
|
|
204
|
-
// tests/
|
|
205
|
-
// layout aside; change one, change both.
|
|
202
|
+
// The fs-only readers below are js/hosts/gitref.mjs's (gitRootOf, gitDirOf, mainWorktreeOf),
|
|
203
|
+
// verbatim: a plugin is copied whole into an install and cannot import js/. Edit the original;
|
|
204
|
+
// `node tests/twins.mjs --write` copies it here, house style included.
|
|
206
205
|
function gitRootOf(cwd) {
|
|
207
206
|
try {
|
|
208
|
-
let dir = path.resolve(cwd)
|
|
207
|
+
let dir = path.resolve(cwd);
|
|
209
208
|
for (;;) {
|
|
210
|
-
if (existsSync(path.join(dir,
|
|
211
|
-
const up = path.dirname(dir)
|
|
212
|
-
if (up === dir) return null
|
|
213
|
-
dir = up
|
|
209
|
+
if (existsSync(path.join(dir, '.git'))) return dir;
|
|
210
|
+
const up = path.dirname(dir);
|
|
211
|
+
if (up === dir) return null;
|
|
212
|
+
dir = up;
|
|
214
213
|
}
|
|
215
214
|
} catch {
|
|
216
|
-
return null
|
|
215
|
+
return null;
|
|
217
216
|
}
|
|
218
217
|
}
|
|
219
218
|
function gitDirOf(root) {
|
|
220
|
-
const dotgit = path.join(root,
|
|
219
|
+
const dotgit = path.join(root, '.git');
|
|
221
220
|
if (statSync(dotgit).isFile()) {
|
|
222
|
-
const m = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync(dotgit,
|
|
223
|
-
if (!m) throw new Error(`${dotgit} does not name a gitdir`)
|
|
224
|
-
return path.resolve(root, m[1])
|
|
221
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync(dotgit, 'utf8'));
|
|
222
|
+
if (!m) throw new Error(`${dotgit} does not name a gitdir`);
|
|
223
|
+
return path.resolve(root, m[1]);
|
|
225
224
|
}
|
|
226
|
-
return dotgit
|
|
225
|
+
return dotgit;
|
|
227
226
|
}
|
|
228
227
|
function mainWorktreeOf(cwd) {
|
|
229
228
|
try {
|
|
230
|
-
const root = gitRootOf(cwd)
|
|
231
|
-
if (!root || !statSync(path.join(root,
|
|
232
|
-
const gitdir = gitDirOf(root)
|
|
233
|
-
const common = path.resolve(gitdir, readFileSync(path.join(gitdir,
|
|
234
|
-
return path.basename(common) ===
|
|
229
|
+
const root = gitRootOf(cwd);
|
|
230
|
+
if (!root || !statSync(path.join(root, '.git')).isFile()) return null;
|
|
231
|
+
const gitdir = gitDirOf(root);
|
|
232
|
+
const common = path.resolve(gitdir, readFileSync(path.join(gitdir, 'commondir'), 'utf8').trim());
|
|
233
|
+
return path.basename(common) === '.git' ? path.dirname(common) : null;
|
|
235
234
|
} catch {
|
|
236
|
-
return null
|
|
235
|
+
return null;
|
|
237
236
|
}
|
|
238
237
|
}
|
|
239
238
|
|
|
@@ -179,9 +179,13 @@ const VISIBLE =
|
|
|
179
179
|
(process.env.GENESEED_CONTEXT_TRANSFORM || "").toLowerCase())
|
|
180
180
|
const TRANSFORM = !VISIBLE
|
|
181
181
|
// Fallback state (module-level — OpenCode keeps ONE copy of the plugin loaded):
|
|
182
|
-
// `transformSeen` flips the first time the experimental hook fires; if a
|
|
183
|
-
// completes (session.idle
|
|
184
|
-
// `fallbackVisible` switches delivery to
|
|
182
|
+
// `transformSeen` flips the first time the experimental hook fires; if a MODEL REQUEST
|
|
183
|
+
// completes (session.idle, with an assistant message in that session's transcript) while
|
|
184
|
+
// it is still false, the build lacks the hook and `fallbackVisible` switches delivery to
|
|
185
|
+
// the classic visible injection. The latch is not for life: the hook firing later clears
|
|
186
|
+
// it, because that is the proof the build has the hook after all. It once latched on any
|
|
187
|
+
// idle seen before the first transform call — an idle with no request behind it was
|
|
188
|
+
// enough — and stayed latched for the whole process, visible delivery in every session.
|
|
185
189
|
let transformSeen = false
|
|
186
190
|
let fallbackVisible = false
|
|
187
191
|
function log(msg) { if (DEBUG) console.error(`[geneseed-context] ${msg}`) }
|
|
@@ -221,8 +225,8 @@ async function isDir(p) {
|
|
|
221
225
|
// context.json is not here: it is a manifest, honoured by resolveSource. geneseed-wiki.jsonc
|
|
222
226
|
// is not here either: the MACHINE WIKI block below already renders it in full.
|
|
223
227
|
const SESSION_FILES = ["user-rules.md", "PROFILE.md", "memory/MEMORY.md", "notebook/NOTEBOOK.md"]
|
|
224
|
-
// The wiki manifest's names, newest first:
|
|
225
|
-
const WIKI_NAMES = [
|
|
228
|
+
// The wiki manifest's names, newest first: js/lib/machine-dir.mjs's line (node tests/twins.mjs).
|
|
229
|
+
const WIKI_NAMES = ['geneseed-wiki.jsonc', 'wiki.jsonc', 'wiki.json'];
|
|
226
230
|
const SEED_SHA256 = new Set([
|
|
227
231
|
"5c2e92fb1acde041e02d9ebf158460d8ff7a07cbc2b447859631604610130721", // user-rules.md
|
|
228
232
|
"29e012c3c4349ea62a9082cbd04bb25599a0ec280d62c33f6e10742809471816", // PROFILE.md
|
|
@@ -456,23 +460,53 @@ function repoRoot(ctx) {
|
|
|
456
460
|
|
|
457
461
|
// ---- model self-awareness (best-effort) --------------------------------------
|
|
458
462
|
// Surface the model the session is actually using so the agent reasons within its
|
|
459
|
-
// real limits (awesome-opencode "Model Announcer"). Sources, first hit wins:
|
|
460
|
-
// assistant message's info.providerID/modelID
|
|
461
|
-
//
|
|
462
|
-
//
|
|
463
|
-
//
|
|
463
|
+
// real limits (awesome-opencode "Model Announcer"). Sources, first hit wins: the outgoing
|
|
464
|
+
// transcript — an assistant message's info.providerID/modelID (the fields the learn plugin
|
|
465
|
+
// reads) or a user message's info.model.{providerID,modelID} — then $GENESEED_MODEL
|
|
466
|
+
// ("provider/model"). Unknown -> no line. It is added per request, OUTSIDE the cached
|
|
467
|
+
// block, so one cache serves every model.
|
|
468
|
+
//
|
|
469
|
+
// THE DECISION IS PINNED PER SESSION (`pinnedModel`), "no line" included. The block is the
|
|
470
|
+
// first message of every request, so it is the head of the provider's prompt-cache prefix:
|
|
471
|
+
// a line that appears on request 2 — the first with an assistant message — rewrites message
|
|
472
|
+
// 0 and re-bills the whole transcript once per session. The user message is read so that
|
|
473
|
+
// request 1 can already answer; where it cannot, the session gets no line rather than a
|
|
474
|
+
// late one. A model switched mid-session is therefore not announced, by design.
|
|
475
|
+
// UNVERIFIED ON A REAL HOST: that OpenCode 1 fills `info.model` on the user message of the
|
|
476
|
+
// first request. No run here has shown it set; where it is absent, a session with no
|
|
477
|
+
// $GENESEED_MODEL simply has no model line.
|
|
464
478
|
function modelFromMessages(messages) {
|
|
465
479
|
if (!Array.isArray(messages)) return null
|
|
466
480
|
let found = null
|
|
467
481
|
for (const m of messages) {
|
|
468
482
|
const info = m?.info ?? {}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
483
|
+
let providerID, modelID
|
|
484
|
+
if (info.role === "assistant") {
|
|
485
|
+
providerID = info.providerID ?? info.provider
|
|
486
|
+
modelID = info.modelID ?? info.model
|
|
487
|
+
} else if (info.role === "user" && info.model && typeof info.model === "object") {
|
|
488
|
+
providerID = info.model.providerID
|
|
489
|
+
modelID = info.model.modelID
|
|
490
|
+
}
|
|
491
|
+
if (typeof providerID === "string" && providerID && typeof modelID === "string" && modelID) {
|
|
492
|
+
found = `${providerID}/${modelID}` // last wins (latest turn)
|
|
493
|
+
}
|
|
473
494
|
}
|
|
474
495
|
return found
|
|
475
496
|
}
|
|
497
|
+
// The model line for this session: decided once, then repeated. `pins` is the instance's own
|
|
498
|
+
// Map (session id -> "provider/model" or null); it drops a session on `session.deleted` and
|
|
499
|
+
// is capped, oldest first, so a long-lived process cannot grow it without bound — a session
|
|
500
|
+
// evicted and still running re-decides once, which costs one rewrite of the block.
|
|
501
|
+
const MODEL_PIN_CAP = 256
|
|
502
|
+
function pinnedModel(pins, sid, decide) {
|
|
503
|
+
if (!sid) return decide() || null
|
|
504
|
+
if (pins.has(sid)) return pins.get(sid)
|
|
505
|
+
const model = decide() || null
|
|
506
|
+
if (pins.size >= MODEL_PIN_CAP) pins.delete(pins.keys().next().value)
|
|
507
|
+
pins.set(sid, model)
|
|
508
|
+
return model
|
|
509
|
+
}
|
|
476
510
|
function envModelStr() {
|
|
477
511
|
const v = process.env.GENESEED_MODEL
|
|
478
512
|
return v && v.includes("/") ? v : null
|
|
@@ -1094,13 +1128,25 @@ function takeWeakened(sid) {
|
|
|
1094
1128
|
}
|
|
1095
1129
|
|
|
1096
1130
|
// ---- The done gate (#289): the OpenCode twin of js/hosts/hooks-done.mjs ----------------
|
|
1097
|
-
// OpenCode has no turn-end event a plugin can block on, so its ceiling is a reminder: on
|
|
1098
|
-
// request
|
|
1099
|
-
// (`.geneseed/done-checks.txt`)
|
|
1131
|
+
// OpenCode has no turn-end event a plugin can block on, so its ceiling is a reminder: on
|
|
1132
|
+
// EVERY request — mid-turn, between two tool calls, as much as at the next prompt — whose
|
|
1133
|
+
// transcript holds an edit with the project's declared checks (`.geneseed/done-checks.txt`)
|
|
1134
|
+
// not passed since, one invisible user message says which checks are owed. It is judged over
|
|
1135
|
+
// the previous turn and the current one (`doneOwed`), so it starts on the request right after
|
|
1136
|
+
// the edit and stops when the checks pass or a second prompt has gone by.
|
|
1137
|
+
//
|
|
1138
|
+
// It is the LAST message of the request, never the first. It comes and goes from one request
|
|
1139
|
+
// to the next, and a message put at the front shifts every message behind it: the provider's
|
|
1140
|
+
// prompt cache, which matches on the prefix, is thrown away each time the reminder toggles.
|
|
1141
|
+
// At the end it changes nothing before it, and it is also where a model weighs an instruction
|
|
1142
|
+
// most. The same holds for the weakened-test reminder below, on both majors.
|
|
1143
|
+
// UNVERIFIED ON A REAL HOST: that every provider accepts a synthetic user message after the
|
|
1144
|
+
// tool results of an unfinished tool loop (the mid-turn case). Only V1
|
|
1100
1145
|
// (`messages.transform`, whose tool parts carry `state.status` and the shell's
|
|
1101
1146
|
// `metadata.exit`); OpenCode 2's message shape for tool calls is unverified, so V2 is not
|
|
1102
1147
|
// judged and says so once. Fails open on every shape it does not recognise (ADR 0007).
|
|
1103
|
-
// `runsUnpiped` is
|
|
1148
|
+
// `runsUnpiped` is js/hosts/hooks-done.mjs's, copied by `node tests/twins.mjs --write`;
|
|
1149
|
+
// tests/plugins/context_done.test.mjs runs both on one table.
|
|
1104
1150
|
const DONE_LIST = ".geneseed/done-checks.txt"
|
|
1105
1151
|
const DONE_EDIT_TOOLS = new Set(["edit", "write", "patch", "apply_patch", "multiedit"])
|
|
1106
1152
|
const DONE_SHELL_TOOLS = new Set(["bash", "shell"])
|
|
@@ -1144,30 +1190,50 @@ async function readDoneChecks(root) {
|
|
|
1144
1190
|
// The inference twin of js/hosts/done-checks.mjs (user decision 2026-10-29): with no list, the
|
|
1145
1191
|
// root manifests imply the checks, each a GROUP of accepted forms. Here they only shape the
|
|
1146
1192
|
// reminder's wording ("advisory"); OpenCode never blocks either way.
|
|
1147
|
-
// tests/plugins/context_done.test.mjs runs both copies over the same fixtures.
|
|
1148
|
-
|
|
1149
|
-
|
|
1193
|
+
// tests/plugins/context_done.test.mjs runs both copies over the same fixtures. The tables are
|
|
1194
|
+
// the hook's own (the twin block); `inferDoneChecks` and `doneChecksOf` are by hand, because
|
|
1195
|
+
// they await where the hook reads synchronously.
|
|
1196
|
+
// ---- done-check tables twin: BEGIN — adapters/opencode/plugins/geneseed-context.js carries
|
|
1197
|
+
// everything down to the END marker verbatim, with `export ` dropped (node tests/twins.mjs --write
|
|
1198
|
+
// keeps it). Its `inferDoneChecks` is the async reading of the one below, kept by hand.
|
|
1199
|
+
|
|
1200
|
+
// The package manager a lockfile names; first hit wins, npm without one. Exported for the gate that
|
|
1201
|
+
// holds the factory `checks` brick's restatement of these rules to this list (factory_graph test).
|
|
1202
|
+
const PM_LOCKS = [['bun.lockb', 'bun'], ['bun.lock', 'bun'], ['pnpm-lock.yaml', 'pnpm'], ['yarn.lock', 'yarn']];
|
|
1203
|
+
const PM_SCRIPTS = ['test', 'lint', 'typecheck'];
|
|
1204
|
+
|
|
1205
|
+
/** One package.json script as a check: the lockfile's own spellings, plus npm's (npm runs any). */
|
|
1150
1206
|
function scriptCheck(pm, s) {
|
|
1151
|
-
const npm = s ===
|
|
1152
|
-
|
|
1153
|
-
|
|
1207
|
+
const npm = s === 'test' ? ['npm test', 'npm run test', 'npm t'] : [`npm run ${s}`];
|
|
1208
|
+
// `bun test` is bun's own runner, not the `test` script: only `bun run` runs the script.
|
|
1209
|
+
const own = pm === 'npm' ? [] : pm === 'bun' ? [`bun run ${s}`] : [`${pm} ${s}`, `${pm} run ${s}`];
|
|
1210
|
+
return { label: own[0] ?? npm[0], forms: [...own, ...npm] };
|
|
1154
1211
|
}
|
|
1212
|
+
|
|
1213
|
+
// Each wrapper spelling (POSIX and Windows) times each task that runs the tests, with and without
|
|
1214
|
+
// a leading `clean`. `refuse` names the flags that make the same command skip the tests: a
|
|
1215
|
+
// segment carrying one is no pass (`hooks-done.mjs`'s `groupPasses`).
|
|
1155
1216
|
const wrapped = (label, bins, tasks, refuse) => ({
|
|
1156
1217
|
label, refuse, forms: bins.flatMap((b) => tasks.flatMap((t) => [`${b} ${t}`, `${b} clean ${t}`])),
|
|
1157
|
-
})
|
|
1158
|
-
const MAVEN = wrapped(
|
|
1159
|
-
/(?:^|\s)-D(?:skipTests|maven\.test\.skip)(?=[=\s]|$)/)
|
|
1160
|
-
const GRADLE = wrapped(
|
|
1161
|
-
/(?:^|\s)(?:-x|--exclude-task)[ =](?:\S*:)?test(?=\s|$)/)
|
|
1162
|
-
|
|
1218
|
+
});
|
|
1219
|
+
const MAVEN = wrapped('mvn test', ['mvn', './mvnw', '.\\mvnw', 'mvnw', 'mvnw.cmd'], ['test', 'verify', 'install'],
|
|
1220
|
+
/(?:^|\s)-D(?:skipTests|maven\.test\.skip)(?=[=\s]|$)/);
|
|
1221
|
+
const GRADLE = wrapped('gradle test', ['gradle', './gradlew', '.\\gradlew', 'gradlew', 'gradlew.bat'], ['test', 'build', 'check'],
|
|
1222
|
+
/(?:^|\s)(?:-x|--exclude-task)[ =](?:\S*:)?test(?=\s|$)/);
|
|
1223
|
+
// shortcut: no `uv`-prefixed form — that spelling trips the no-Python gates in
|
|
1224
|
+
// tests/unit/package_manifest.test.mjs (user decision 2026-10-29: no exemption), so a uv user's
|
|
1225
|
+
// run reads as unproven, which is only an advisory.
|
|
1226
|
+
const PYTEST = { label: 'pytest', forms: ['pytest', 'python -m pytest', 'python3 -m pytest', 'py -m pytest', 'poetry run pytest'] };
|
|
1163
1227
|
const MANIFEST_CHECKS = [
|
|
1164
|
-
[
|
|
1165
|
-
[
|
|
1166
|
-
[
|
|
1167
|
-
[
|
|
1168
|
-
[
|
|
1169
|
-
[
|
|
1170
|
-
]
|
|
1228
|
+
['pom.xml', MAVEN],
|
|
1229
|
+
['build.gradle', GRADLE],
|
|
1230
|
+
['build.gradle.kts', GRADLE],
|
|
1231
|
+
['pyproject.toml', PYTEST],
|
|
1232
|
+
['Cargo.toml', { label: 'cargo test', forms: ['cargo test'], refuse: /(?:^|\s)--no-run(?=\s|$)/ }],
|
|
1233
|
+
['go.mod', { label: 'go test', forms: ['go test'] }],
|
|
1234
|
+
];
|
|
1235
|
+
|
|
1236
|
+
// ---- done-check tables twin: END
|
|
1171
1237
|
const exists = (p) => fs.access(p).then(() => true, () => false)
|
|
1172
1238
|
// The Node hook's `gitRootOf`: the nearest ancestor holding `.git` (a dir, or a worktree's file).
|
|
1173
1239
|
async function gitRootOf(dir) {
|
|
@@ -1229,15 +1295,26 @@ async function doneLine(dir, judged = true) {
|
|
|
1229
1295
|
// In an application repo (a git root holding a build manifest) whose root AGENTS.md has no
|
|
1230
1296
|
// `## Ownership` section outside the Geneseed block, the developer's `Setup: declined <date>`
|
|
1231
1297
|
// line in `.geneseed/ownership.md` gets one context line, so the decline stays visible. Same
|
|
1232
|
-
// manifests,
|
|
1233
|
-
//
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1298
|
+
// manifests, section and decline patterns as the hook (and geneseed-guard.js, whose gate defers
|
|
1299
|
+
// on that line): they are its own lines, kept by `node tests/twins.mjs --write`. `--no-ownership-gate` (`Ownership gate: off` in AGENT.md) prints nothing.
|
|
1300
|
+
// ---- ownership shape twin: BEGIN — adapters/opencode/plugins/geneseed-guard.js and
|
|
1301
|
+
// geneseed-context.js carry everything down to the END marker verbatim (node tests/twins.mjs
|
|
1302
|
+
// --write keeps it), and the one-line `WRITE_NAME_RE`, `safeStem` and `DECLINED_RE` below too.
|
|
1303
|
+
|
|
1304
|
+
// D5: the build manifests that make a git root an "application". Exact names, plus two families.
|
|
1305
|
+
const MANIFESTS = new Set(['package.json', 'pom.xml', 'pyproject.toml', 'go.mod', 'Cargo.toml',
|
|
1306
|
+
'composer.json', 'Gemfile']);
|
|
1307
|
+
const isManifest = (n) => MANIFESTS.has(n) || n.startsWith('build.gradle') || n.endsWith('.csproj');
|
|
1308
|
+
|
|
1309
|
+
// On a Bob project install the managed block holds the whole carrier, `#### Ownership` included —
|
|
1310
|
+
// hence the strip (`withoutBlocks`) and the exact `##` heading match. `\r?`: a CRLF file's `$`
|
|
1311
|
+
// sits after the `\r`.
|
|
1312
|
+
const SECTION_RE = /^## Ownership[ \t]*\r?$/m;
|
|
1313
|
+
|
|
1314
|
+
// ---- ownership shape twin: END
|
|
1237
1315
|
// Whole-line markers: js/lib/managed-block.mjs BLOCK_RE_SOURCE, by value (a plugin imports nothing).
|
|
1238
1316
|
const OWN_BLOCK_RE = /^<!-- BEGIN GENESEED -->[ \t]*\r?\n[\s\S]*?^<!-- END GENESEED -->[ \t]*\r?$/gm
|
|
1239
|
-
const
|
|
1240
|
-
const OWN_DECLINED_RE = /^Setup:[ \t]*declined[ \t]+(\d{4}-\d{2}-\d{2})[ \t]*\r?$/m
|
|
1317
|
+
const DECLINED_RE = /^Setup:[ \t]*declined[ \t]+(\d{4}-\d{2}-\d{2})[ \t]*\r?$/m;
|
|
1241
1318
|
let ownershipGateOffOnce = null
|
|
1242
1319
|
function ownershipGateOff() {
|
|
1243
1320
|
ownershipGateOffOnce ??= (async () => {
|
|
@@ -1250,13 +1327,13 @@ function ownershipGateOff() {
|
|
|
1250
1327
|
}
|
|
1251
1328
|
async function ownershipLine(dir) {
|
|
1252
1329
|
const root = await gitRootOf(dir)
|
|
1253
|
-
if (!root || !(await fs.readdir(root)).some(
|
|
1330
|
+
if (!root || !(await fs.readdir(root)).some(isManifest)) return null
|
|
1254
1331
|
const agents = await fs.readFile(path.join(root, "AGENTS.md"), "utf8").catch(() => "")
|
|
1255
|
-
if (
|
|
1332
|
+
if (SECTION_RE.test(agents.replace(OWN_BLOCK_RE, ""))) return null
|
|
1256
1333
|
// The decline lives in the MAIN worktree (a fresh linked worktree per session must not lose it).
|
|
1257
1334
|
const home = (await mainWorktreeOf(root)) ?? root
|
|
1258
1335
|
const personal = await fs.readFile(path.join(home, ".geneseed", "ownership.md"), "utf8").catch(() => "")
|
|
1259
|
-
const since =
|
|
1336
|
+
const since = DECLINED_RE.exec(personal.replace(/^\uFEFF/, ""))?.[1]
|
|
1260
1337
|
return since ? `Ownership: setup declined since ${since} — not set up; say "set up ownership" to run it` : null
|
|
1261
1338
|
}
|
|
1262
1339
|
|
|
@@ -1344,6 +1421,12 @@ function patchSections(patchText) {
|
|
|
1344
1421
|
|
|
1345
1422
|
// The checks still owed, judged over the previous turn and the current one: a reminder lasts
|
|
1346
1423
|
// one turn, not the whole session. Our own injected messages (`geneseed-*` ids) open no turn.
|
|
1424
|
+
// BACKGROUND RUNS: js/hosts/hooks-done.mjs holds a Claude Code `run_in_background` launch as
|
|
1425
|
+
// pending until its notification says exit 0. Nothing here does. OpenCode 2's bash tool takes
|
|
1426
|
+
// `background: true` ("Background commands return immediately", seen in the @opencode/cli 2.2.5
|
|
1427
|
+
// binary, 2026-11), but V2 is not judged. Whether V1's bash tool has a background mode is
|
|
1428
|
+
// UNVERIFIED (no V1 binary was inspected); if it has one, a launch would pass here, since only a
|
|
1429
|
+
// numeric non-zero `metadata.exit` refuses a completed call.
|
|
1347
1430
|
function doneOwed(messages, checks, root) {
|
|
1348
1431
|
const groups = checks.map((c) => (typeof c === "string" ? { label: c, forms: [c] } : c))
|
|
1349
1432
|
const prompts = []
|
|
@@ -1416,6 +1499,19 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1416
1499
|
const blockCache = { text: null, at: 0 }
|
|
1417
1500
|
const bypassed = ttlMemo(sovereignBypass)
|
|
1418
1501
|
const doneChecks = ttlMemo(doneChecksOf)
|
|
1502
|
+
const modelPins = new Map()
|
|
1503
|
+
|
|
1504
|
+
// Did a model request really run in this session? An assistant message in its transcript
|
|
1505
|
+
// is the evidence; an unreadable transcript is not, and the next idle asks again.
|
|
1506
|
+
async function sawModelRequest(sid) {
|
|
1507
|
+
try {
|
|
1508
|
+
const msgs = await client.session.messages({ path: { id: sid } })
|
|
1509
|
+
const list = Array.isArray(msgs) ? msgs : (msgs?.data ?? [])
|
|
1510
|
+
return list.some((m) => m?.info?.role === "assistant")
|
|
1511
|
+
} catch {
|
|
1512
|
+
return false
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1419
1515
|
|
|
1420
1516
|
// Visible delivery — post the block as a noReply session message. Used when
|
|
1421
1517
|
// GENESEED_CONTEXT_VISIBLE forces it, and by the transform fallback below.
|
|
@@ -1473,21 +1569,26 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1473
1569
|
},
|
|
1474
1570
|
|
|
1475
1571
|
event: async ({ event }) => {
|
|
1476
|
-
if (!event
|
|
1477
|
-
if (await bypassed(root)) return
|
|
1572
|
+
if (!event) return
|
|
1478
1573
|
const sid =
|
|
1479
1574
|
event.properties?.sessionID ?? event.payload?.sessionID ??
|
|
1480
1575
|
event.properties?.info?.id ?? event.payload?.info?.id
|
|
1576
|
+
if (event.type === "session.deleted") { modelPins.delete(sid); return }
|
|
1577
|
+
if (INJECT_OFF) return
|
|
1578
|
+
if (await bypassed(root)) return
|
|
1481
1579
|
if (event.type === "session.created") {
|
|
1482
1580
|
if (TRANSFORM && !fallbackVisible) return // invisible delivery handles it
|
|
1483
1581
|
await injectVisible(sid)
|
|
1484
1582
|
return
|
|
1485
1583
|
}
|
|
1486
|
-
// Transform fallback: the session went idle
|
|
1487
|
-
// experimental hook never fired in this
|
|
1488
|
-
// the visible delivery so context still
|
|
1489
|
-
// right away (one turn late) rather than
|
|
1584
|
+
// Transform fallback: the session went idle after a model request (its transcript
|
|
1585
|
+
// holds an assistant message) yet the experimental hook never fired in this
|
|
1586
|
+
// process — this build lacks it. Engage the visible delivery so context still
|
|
1587
|
+
// arrives, injecting into THIS session right away (one turn late) rather than
|
|
1588
|
+
// waiting for the next session. An idle with no request behind it proves nothing
|
|
1589
|
+
// about the hook and latches nothing.
|
|
1490
1590
|
if (event.type === "session.idle" && TRANSFORM && !transformSeen && !fallbackVisible) {
|
|
1591
|
+
if (!(await sawModelRequest(sid)) || transformSeen) return
|
|
1491
1592
|
fallbackVisible = true
|
|
1492
1593
|
log("transform hook absent on this build — falling back to visible injection")
|
|
1493
1594
|
await injectVisible(sid)
|
|
@@ -1522,14 +1623,21 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1522
1623
|
// detects that and takes over with the visible delivery.
|
|
1523
1624
|
"experimental.chat.messages.transform": async (_input, output) => {
|
|
1524
1625
|
transformSeen = true // the hook exists on this build
|
|
1626
|
+
// …so a fallback latched before it first fired was a wrong guess: back to invisible.
|
|
1627
|
+
// A session that already got the visible block keeps it; the MARKER check below is
|
|
1628
|
+
// what stops a second one.
|
|
1629
|
+
fallbackVisible = false
|
|
1525
1630
|
// One scope decision per request, shared by the done gate and the context block:
|
|
1526
1631
|
// both end on an empty request, an excluded repo, or a skipped session.
|
|
1527
1632
|
if (!output || !Array.isArray(output.messages) || !output.messages.length) return
|
|
1528
1633
|
const sid = output.messages[0]?.info?.sessionID
|
|
1529
1634
|
if (await bypassed(root) || await skipSession(sid)) return
|
|
1530
|
-
// The done gate's reminder: FIRST, and independent of the context block:
|
|
1635
|
+
// The done gate's reminder: decided FIRST, and independent of the context block:
|
|
1531
1636
|
// INJECT_OFF and the visible delivery leave it on, and no early return below can skip it.
|
|
1532
1637
|
// Its own function, so its early returns end the reminder, never the context injection.
|
|
1638
|
+
// Both reminders are PUSHED — the last messages of the request — and the context block
|
|
1639
|
+
// alone is unshifted, so message 0 is the same on every request (see the done gate's
|
|
1640
|
+
// docblock for why).
|
|
1533
1641
|
await (async () => {
|
|
1534
1642
|
if (await doneGateOff()) return
|
|
1535
1643
|
const { root: gitRoot, source, blocking, checks } = await doneChecks(root)
|
|
@@ -1537,7 +1645,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1537
1645
|
const owed = doneOwed(output.messages, checks, gitRoot)
|
|
1538
1646
|
if (!owed.length) return
|
|
1539
1647
|
const stamp = Date.now()
|
|
1540
|
-
output.messages.
|
|
1648
|
+
output.messages.push({
|
|
1541
1649
|
info: { id: `geneseed-done-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
1542
1650
|
parts: [{ id: `geneseed-done-part-${stamp}`, type: "text", text:
|
|
1543
1651
|
`Geneseed (Verify Before Asserting) — files were edited, and these checks ${blocking ? "from" : "(advisory) inferred from"} `
|
|
@@ -1550,7 +1658,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1550
1658
|
const weakened = !(await doneGateOff()) && takeWeakened(sid)
|
|
1551
1659
|
if (weakened) {
|
|
1552
1660
|
const stamp = Date.now()
|
|
1553
|
-
output.messages.
|
|
1661
|
+
output.messages.push({
|
|
1554
1662
|
info: { id: `geneseed-weakened-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
1555
1663
|
parts: [{ id: `geneseed-weakened-part-${stamp}`, type: "text", text: weakened }],
|
|
1556
1664
|
})
|
|
@@ -1564,9 +1672,11 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1564
1672
|
if (present) return
|
|
1565
1673
|
const cached = await cachedBlockText(root, blockCache)
|
|
1566
1674
|
if (!cached) return
|
|
1567
|
-
//
|
|
1568
|
-
// transcript
|
|
1569
|
-
|
|
1675
|
+
// The model line is kept out of the cache and decided ONCE per session — the live
|
|
1676
|
+
// transcript of the session's first request, else $GENESEED_MODEL, else no line —
|
|
1677
|
+
// so no later request rewrites the block.
|
|
1678
|
+
const text = withModel(cached,
|
|
1679
|
+
pinnedModel(modelPins, sid, () => modelFromMessages(output.messages) || envModelStr()))
|
|
1570
1680
|
const stamp = Date.now()
|
|
1571
1681
|
output.messages.unshift({
|
|
1572
1682
|
info: { id: `geneseed-context-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
@@ -1608,6 +1718,7 @@ async function setupV2(ctx) {
|
|
|
1608
1718
|
const blockCache = { text: null, at: 0, judged: false }
|
|
1609
1719
|
const bypassed = ttlMemo(sovereignBypass)
|
|
1610
1720
|
const doneChecks = ttlMemo(doneChecksOf)
|
|
1721
|
+
const modelPins = new Map()
|
|
1611
1722
|
// Same scope rule as V1's skipSession. V2's info names the parent `parentID` only, so only
|
|
1612
1723
|
// that and the title are passed on.
|
|
1613
1724
|
const skipSession = sessionSkipper(async (sid) => {
|
|
@@ -1621,7 +1732,8 @@ async function setupV2(ctx) {
|
|
|
1621
1732
|
console.error(`[geneseed-context] done gate: ${DONE_LIST} found, but OpenCode 2 turns are not judged.`)
|
|
1622
1733
|
}
|
|
1623
1734
|
|
|
1624
|
-
// The weakened-test reminder, which INJECT_OFF and visible delivery leave on, as on V1
|
|
1735
|
+
// The weakened-test reminder, which INJECT_OFF and visible delivery leave on, as on V1 —
|
|
1736
|
+
// and, as on V1, the LAST message of the request, so the context block stays message 0. A V2
|
|
1625
1737
|
// callback that throws fails the agent step, so both swallow their errors.
|
|
1626
1738
|
await ctx.tool?.hook?.("execute.before", async (event) => {
|
|
1627
1739
|
await noteWeakened(root, event?.sessionID, event?.tool, event?.input)
|
|
@@ -1631,7 +1743,7 @@ async function setupV2(ctx) {
|
|
|
1631
1743
|
if (!Array.isArray(event?.messages) || await bypassed(root) || await doneGateOff()) return
|
|
1632
1744
|
if (await skipSession(event.sessionID)) return
|
|
1633
1745
|
const weakened = takeWeakened(event.sessionID)
|
|
1634
|
-
if (weakened) event.messages.
|
|
1746
|
+
if (weakened) event.messages.push(v2UserMessage(event.messages, weakened))
|
|
1635
1747
|
} catch (err) {
|
|
1636
1748
|
log(`test-weakening error: ${err?.message ?? err}`)
|
|
1637
1749
|
}
|
|
@@ -1649,7 +1761,8 @@ async function setupV2(ctx) {
|
|
|
1649
1761
|
if (await skipSession(event.sessionID)) return
|
|
1650
1762
|
const cached = await cachedBlockText(root, blockCache)
|
|
1651
1763
|
if (!cached) return
|
|
1652
|
-
|
|
1764
|
+
const model = pinnedModel(modelPins, event.sessionID, () => v2Model(event.model) || envModelStr())
|
|
1765
|
+
event.messages.unshift(v2UserMessage(event.messages, withModel(cached, model)))
|
|
1653
1766
|
log("context hook: injected context invisibly")
|
|
1654
1767
|
} catch (err) {
|
|
1655
1768
|
log(`context hook error: ${err?.message ?? err}`)
|