geneseed 5.3.0 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +2 -2
- package/SHIPPED.md +1 -1
- package/adapters/bob/README.md +31 -18
- package/adapters/claude-code/README.md +27 -22
- package/adapters/openclaude/README.md +18 -8
- package/adapters/opencode/HOW-OPENCODE-LOADS.md +8 -3
- package/adapters/opencode/plugins/geneseed-activity.js +20 -21
- package/adapters/opencode/plugins/geneseed-context.js +169 -62
- package/adapters/opencode/plugins/geneseed-guard.js +414 -202
- package/adapters/opencode/plugins/geneseed-workflow.js +3 -2
- package/adapters/opencode/workflows/_runtime.js +3 -2
- package/bin/geneseed-hook.mjs +57 -9
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +2 -2
- package/docs/concepts/footprint.md +10 -0
- package/docs/concepts/hook-gates.md +3 -3
- package/docs/concepts/host-matrix.md +22 -4
- package/docs/design-history.md +8 -0
- package/docs/extending.md +49 -7
- package/docs/guides/install-bob.md +2 -2
- package/docs/guides/install-openclaude.md +1 -1
- package/docs/guides/verify.md +12 -0
- package/docs/reference/environment.md +1 -0
- package/docs/reference/troubleshoot-doctor.md +1 -1
- package/docs/token-footprint.md +66 -2
- package/docs/understand/design-choices-hosts.md +1 -1
- package/docs/understand/design-choices-shape.md +1 -0
- package/docs/understand/enforced-vs-asked.md +1 -1
- package/docs/understand/machine-bob.md +1 -1
- package/docs/web-ui.md +5 -0
- package/harness.config.json +1 -1
- package/js/README.md +3 -2
- package/js/build/args.mjs +1 -1
- package/js/build/driver.mjs +1 -1
- package/js/build/emit-claude.mjs +1 -1
- package/js/build/generate.mjs +5 -14
- 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-learn.mjs +47 -16
- package/js/hosts/hooks.mjs +19 -13
- package/js/hosts/hosts.mjs +80 -12
- package/js/hosts/installs.mjs +7 -0
- package/js/hosts/native.mjs +14 -5
- package/js/hosts/owned.mjs +7 -6
- package/js/hosts/ownership-gate.mjs +14 -1
- package/js/hosts/settings.mjs +245 -103
- package/js/hosts/shim.mjs +4 -4
- package/js/hosts/usage.mjs +9 -3
- package/js/inspect/checks-probe.mjs +66 -5
- package/js/inspect/checks-repo.mjs +196 -2
- package/js/inspect/cost.mjs +34 -2
- package/js/inspect/doctor.mjs +6 -1
- package/js/lib/machine-dir.mjs +1 -1
- package/js/lib/node-floor.mjs +46 -6
- package/js/maintain/uninstall.mjs +42 -16
- package/js/web/actions.mjs +1 -9
- package/package.json +1 -1
- package/web/dist/assets/Activity-WQ3ykgxU.js +1 -0
- package/web/dist/assets/{ActivityDetail-BSzevynX.js → ActivityDetail-7rt04SkS.js} +1 -1
- package/web/dist/assets/{Bonsai-Bfpb6W-1.js → Bonsai-BBl4XXqs.js} +1 -1
- package/web/dist/assets/{CopyButton-ByIntFtB.js → CopyButton-Beven8yn.js} +1 -1
- package/web/dist/assets/Dashboard-BgLArtgu.js +2 -0
- package/web/dist/assets/{Docs-DvlMJhpu.js → Docs-B5aHp86J.js} +3 -3
- package/web/dist/assets/Factories-BjqzXAw8.js +1 -0
- package/web/dist/assets/GreenhouseView-Bce212qd.js +1 -0
- package/web/dist/assets/{Installs-BlGmVrFK.js → Installs-B1OsrHXF.js} +3 -3
- package/web/dist/assets/JournalView-CV4omyww.js +1 -0
- package/web/dist/assets/{Kits-DRwpxC-J.js → Kits-CW1e7xNa.js} +1 -1
- package/web/dist/assets/{Laws-CZkiNOWQ.js → Laws-1Ckf1lbs.js} +2 -2
- package/web/dist/assets/{LibRows-DEHjIoD-.js → LibRows-Dag1s0ZX.js} +1 -1
- package/web/dist/assets/Library-B3FuFLel.js +3 -0
- package/web/dist/assets/Loops-CwqgnLNw.js +2 -0
- package/web/dist/assets/Markdown-CxkA7940.js +71 -0
- package/web/dist/assets/OperatorHudView-JmYY1pBR.js +1 -0
- package/web/dist/assets/{Personal-Bp9nV4GR.js → Personal-DKLgLa7Z.js} +2 -2
- package/web/dist/assets/Settings-BwErnh-R.js +1 -0
- package/web/dist/assets/{Tabs-CWeQTADL.js → Tabs-8zsyEPSK.js} +1 -1
- package/web/dist/assets/{index-CsAZq0BQ.css → index-CRWqKxfY.css} +1 -1
- package/web/dist/assets/index-Ce6qF2nG.js +6 -0
- 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/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/JournalView-iLuLrOxE.js +0 -1
- 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/Settings-CWWuaIp-.js +0 -1
- package/web/dist/assets/index-How7SzDZ.js +0 -6
|
@@ -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
|
|
|
@@ -1416,6 +1493,19 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1416
1493
|
const blockCache = { text: null, at: 0 }
|
|
1417
1494
|
const bypassed = ttlMemo(sovereignBypass)
|
|
1418
1495
|
const doneChecks = ttlMemo(doneChecksOf)
|
|
1496
|
+
const modelPins = new Map()
|
|
1497
|
+
|
|
1498
|
+
// Did a model request really run in this session? An assistant message in its transcript
|
|
1499
|
+
// is the evidence; an unreadable transcript is not, and the next idle asks again.
|
|
1500
|
+
async function sawModelRequest(sid) {
|
|
1501
|
+
try {
|
|
1502
|
+
const msgs = await client.session.messages({ path: { id: sid } })
|
|
1503
|
+
const list = Array.isArray(msgs) ? msgs : (msgs?.data ?? [])
|
|
1504
|
+
return list.some((m) => m?.info?.role === "assistant")
|
|
1505
|
+
} catch {
|
|
1506
|
+
return false
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1419
1509
|
|
|
1420
1510
|
// Visible delivery — post the block as a noReply session message. Used when
|
|
1421
1511
|
// GENESEED_CONTEXT_VISIBLE forces it, and by the transform fallback below.
|
|
@@ -1473,21 +1563,26 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1473
1563
|
},
|
|
1474
1564
|
|
|
1475
1565
|
event: async ({ event }) => {
|
|
1476
|
-
if (!event
|
|
1477
|
-
if (await bypassed(root)) return
|
|
1566
|
+
if (!event) return
|
|
1478
1567
|
const sid =
|
|
1479
1568
|
event.properties?.sessionID ?? event.payload?.sessionID ??
|
|
1480
1569
|
event.properties?.info?.id ?? event.payload?.info?.id
|
|
1570
|
+
if (event.type === "session.deleted") { modelPins.delete(sid); return }
|
|
1571
|
+
if (INJECT_OFF) return
|
|
1572
|
+
if (await bypassed(root)) return
|
|
1481
1573
|
if (event.type === "session.created") {
|
|
1482
1574
|
if (TRANSFORM && !fallbackVisible) return // invisible delivery handles it
|
|
1483
1575
|
await injectVisible(sid)
|
|
1484
1576
|
return
|
|
1485
1577
|
}
|
|
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
|
|
1578
|
+
// Transform fallback: the session went idle after a model request (its transcript
|
|
1579
|
+
// holds an assistant message) yet the experimental hook never fired in this
|
|
1580
|
+
// process — this build lacks it. Engage the visible delivery so context still
|
|
1581
|
+
// arrives, injecting into THIS session right away (one turn late) rather than
|
|
1582
|
+
// waiting for the next session. An idle with no request behind it proves nothing
|
|
1583
|
+
// about the hook and latches nothing.
|
|
1490
1584
|
if (event.type === "session.idle" && TRANSFORM && !transformSeen && !fallbackVisible) {
|
|
1585
|
+
if (!(await sawModelRequest(sid)) || transformSeen) return
|
|
1491
1586
|
fallbackVisible = true
|
|
1492
1587
|
log("transform hook absent on this build — falling back to visible injection")
|
|
1493
1588
|
await injectVisible(sid)
|
|
@@ -1522,14 +1617,21 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1522
1617
|
// detects that and takes over with the visible delivery.
|
|
1523
1618
|
"experimental.chat.messages.transform": async (_input, output) => {
|
|
1524
1619
|
transformSeen = true // the hook exists on this build
|
|
1620
|
+
// …so a fallback latched before it first fired was a wrong guess: back to invisible.
|
|
1621
|
+
// A session that already got the visible block keeps it; the MARKER check below is
|
|
1622
|
+
// what stops a second one.
|
|
1623
|
+
fallbackVisible = false
|
|
1525
1624
|
// One scope decision per request, shared by the done gate and the context block:
|
|
1526
1625
|
// both end on an empty request, an excluded repo, or a skipped session.
|
|
1527
1626
|
if (!output || !Array.isArray(output.messages) || !output.messages.length) return
|
|
1528
1627
|
const sid = output.messages[0]?.info?.sessionID
|
|
1529
1628
|
if (await bypassed(root) || await skipSession(sid)) return
|
|
1530
|
-
// The done gate's reminder: FIRST, and independent of the context block:
|
|
1629
|
+
// The done gate's reminder: decided FIRST, and independent of the context block:
|
|
1531
1630
|
// INJECT_OFF and the visible delivery leave it on, and no early return below can skip it.
|
|
1532
1631
|
// Its own function, so its early returns end the reminder, never the context injection.
|
|
1632
|
+
// Both reminders are PUSHED — the last messages of the request — and the context block
|
|
1633
|
+
// alone is unshifted, so message 0 is the same on every request (see the done gate's
|
|
1634
|
+
// docblock for why).
|
|
1533
1635
|
await (async () => {
|
|
1534
1636
|
if (await doneGateOff()) return
|
|
1535
1637
|
const { root: gitRoot, source, blocking, checks } = await doneChecks(root)
|
|
@@ -1537,7 +1639,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1537
1639
|
const owed = doneOwed(output.messages, checks, gitRoot)
|
|
1538
1640
|
if (!owed.length) return
|
|
1539
1641
|
const stamp = Date.now()
|
|
1540
|
-
output.messages.
|
|
1642
|
+
output.messages.push({
|
|
1541
1643
|
info: { id: `geneseed-done-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
1542
1644
|
parts: [{ id: `geneseed-done-part-${stamp}`, type: "text", text:
|
|
1543
1645
|
`Geneseed (Verify Before Asserting) — files were edited, and these checks ${blocking ? "from" : "(advisory) inferred from"} `
|
|
@@ -1550,7 +1652,7 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1550
1652
|
const weakened = !(await doneGateOff()) && takeWeakened(sid)
|
|
1551
1653
|
if (weakened) {
|
|
1552
1654
|
const stamp = Date.now()
|
|
1553
|
-
output.messages.
|
|
1655
|
+
output.messages.push({
|
|
1554
1656
|
info: { id: `geneseed-weakened-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
1555
1657
|
parts: [{ id: `geneseed-weakened-part-${stamp}`, type: "text", text: weakened }],
|
|
1556
1658
|
})
|
|
@@ -1564,9 +1666,11 @@ export const GeneseedContext = async (ctx) => {
|
|
|
1564
1666
|
if (present) return
|
|
1565
1667
|
const cached = await cachedBlockText(root, blockCache)
|
|
1566
1668
|
if (!cached) return
|
|
1567
|
-
//
|
|
1568
|
-
// transcript
|
|
1569
|
-
|
|
1669
|
+
// The model line is kept out of the cache and decided ONCE per session — the live
|
|
1670
|
+
// transcript of the session's first request, else $GENESEED_MODEL, else no line —
|
|
1671
|
+
// so no later request rewrites the block.
|
|
1672
|
+
const text = withModel(cached,
|
|
1673
|
+
pinnedModel(modelPins, sid, () => modelFromMessages(output.messages) || envModelStr()))
|
|
1570
1674
|
const stamp = Date.now()
|
|
1571
1675
|
output.messages.unshift({
|
|
1572
1676
|
info: { id: `geneseed-context-${stamp}`, role: "user", sessionID: sid, time: { created: stamp } },
|
|
@@ -1608,6 +1712,7 @@ async function setupV2(ctx) {
|
|
|
1608
1712
|
const blockCache = { text: null, at: 0, judged: false }
|
|
1609
1713
|
const bypassed = ttlMemo(sovereignBypass)
|
|
1610
1714
|
const doneChecks = ttlMemo(doneChecksOf)
|
|
1715
|
+
const modelPins = new Map()
|
|
1611
1716
|
// Same scope rule as V1's skipSession. V2's info names the parent `parentID` only, so only
|
|
1612
1717
|
// that and the title are passed on.
|
|
1613
1718
|
const skipSession = sessionSkipper(async (sid) => {
|
|
@@ -1621,7 +1726,8 @@ async function setupV2(ctx) {
|
|
|
1621
1726
|
console.error(`[geneseed-context] done gate: ${DONE_LIST} found, but OpenCode 2 turns are not judged.`)
|
|
1622
1727
|
}
|
|
1623
1728
|
|
|
1624
|
-
// The weakened-test reminder, which INJECT_OFF and visible delivery leave on, as on V1
|
|
1729
|
+
// The weakened-test reminder, which INJECT_OFF and visible delivery leave on, as on V1 —
|
|
1730
|
+
// and, as on V1, the LAST message of the request, so the context block stays message 0. A V2
|
|
1625
1731
|
// callback that throws fails the agent step, so both swallow their errors.
|
|
1626
1732
|
await ctx.tool?.hook?.("execute.before", async (event) => {
|
|
1627
1733
|
await noteWeakened(root, event?.sessionID, event?.tool, event?.input)
|
|
@@ -1631,7 +1737,7 @@ async function setupV2(ctx) {
|
|
|
1631
1737
|
if (!Array.isArray(event?.messages) || await bypassed(root) || await doneGateOff()) return
|
|
1632
1738
|
if (await skipSession(event.sessionID)) return
|
|
1633
1739
|
const weakened = takeWeakened(event.sessionID)
|
|
1634
|
-
if (weakened) event.messages.
|
|
1740
|
+
if (weakened) event.messages.push(v2UserMessage(event.messages, weakened))
|
|
1635
1741
|
} catch (err) {
|
|
1636
1742
|
log(`test-weakening error: ${err?.message ?? err}`)
|
|
1637
1743
|
}
|
|
@@ -1649,7 +1755,8 @@ async function setupV2(ctx) {
|
|
|
1649
1755
|
if (await skipSession(event.sessionID)) return
|
|
1650
1756
|
const cached = await cachedBlockText(root, blockCache)
|
|
1651
1757
|
if (!cached) return
|
|
1652
|
-
|
|
1758
|
+
const model = pinnedModel(modelPins, event.sessionID, () => v2Model(event.model) || envModelStr())
|
|
1759
|
+
event.messages.unshift(v2UserMessage(event.messages, withModel(cached, model)))
|
|
1653
1760
|
log("context hook: injected context invisibly")
|
|
1654
1761
|
} catch (err) {
|
|
1655
1762
|
log(`context hook error: ${err?.message ?? err}`)
|