opencode-model-router 2.2.0 → 2.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 +214 -0
- package/README.md +90 -12
- package/package.json +4 -1
- package/src/commands/output.ts +24 -1
- package/src/compat/child-session.ts +43 -0
- package/src/compat/v2-client.ts +107 -7
- package/src/compat/v2-hooks.ts +1435 -44
- package/src/escalate/attempt-recorder.ts +263 -0
- package/src/escalate/ladder.ts +496 -10
- package/src/escalate/resume.ts +208 -0
- package/src/escalate/variants.ts +391 -0
- package/src/guard/enforce.ts +186 -22
- package/src/guard/guards.ts +132 -6
- package/src/guard/store.ts +5 -0
- package/src/index.ts +1193 -56
- package/src/router/build-info.ts +151 -0
- package/src/router/config.ts +1611 -19
- package/src/router/dispatch-header.ts +46 -4
- package/src/router/git-tools.ts +1152 -0
- package/src/router/guard-profile.ts +100 -0
- package/src/router/plugin-agents.ts +433 -0
- package/src/router/prompts.ts +26 -1
- package/src/router/protocol.ts +180 -0
- package/src/router/read-only.ts +149 -0
- package/src/router/role-agents.ts +409 -0
- package/src/router/roles-config.ts +429 -0
- package/src/router/roles.ts +600 -0
- package/src/router/run-tools.ts +913 -0
- package/src/router/sensitive-paths.ts +101 -0
- package/src/router/sessions.ts +533 -9
- package/src/router/subagents.ts +28 -1
- package/src/routing/advisor/findings.ts +898 -0
- package/src/routing/advisor/index.ts +614 -0
- package/src/routing/classify/backends/host.ts +163 -0
- package/src/routing/classify/backends/openai-compatible.ts +275 -0
- package/src/routing/classify/backends/shared.ts +741 -0
- package/src/routing/classify/backends/typesafe.ts +315 -0
- package/src/routing/classify/fences.ts +96 -0
- package/src/routing/classify/index.ts +594 -0
- package/src/routing/classify/route-line.ts +362 -0
- package/src/routing/classify/rules.ts +667 -0
- package/src/routing/classify/scrub.ts +214 -0
- package/src/routing/classify/state.ts +148 -0
- package/src/routing/classify/text.ts +20 -0
- package/src/routing/classify/types.ts +1310 -0
- package/src/routing/commands/annotate-plan.ts +652 -0
- package/src/routing/commands/stats.ts +134 -0
- package/src/routing/commands/v1-roles.ts +64 -0
- package/src/routing/engine/index.ts +32 -0
- package/src/routing/engine/kernel.ts +760 -0
- package/src/routing/engine/ladders.ts +802 -0
- package/src/routing/engine/plan.ts +404 -0
- package/src/routing/engine/protocol-line.ts +150 -0
- package/src/routing/engine/roles-taxonomy.ts +52 -0
- package/src/routing/engine/simulate.ts +167 -0
- package/src/routing/engine/types.ts +368 -0
- package/src/routing/file-lock.ts +53 -0
- package/src/routing/outcomes/beta.ts +147 -0
- package/src/routing/outcomes/cost.ts +313 -0
- package/src/routing/outcomes/index.ts +215 -0
- package/src/routing/outcomes/ingest.ts +960 -0
- package/src/routing/outcomes/persist.ts +1080 -0
- package/src/routing/outcomes/signals.ts +650 -0
- package/src/routing/outcomes/stats.ts +873 -0
- package/src/routing/outcomes/store.ts +673 -0
- package/src/routing/outcomes/types.ts +1093 -0
- package/src/routing/roles/authority.ts +495 -0
- package/src/routing/roles/binding.ts +543 -0
- package/src/routing/roles/policy.ts +416 -0
- package/src/routing/roles/work-root.ts +132 -0
- package/src/routing/wire/dispatch.ts +2088 -0
- package/src/routing/wire/hint.ts +222 -0
- package/src/routing/wire/host-info.ts +256 -0
- package/src/routing/wire/runtime.ts +348 -0
- package/src/v2.ts +40 -1
- package/src/verify/checker.ts +249 -7
- package/src/verify/deterministic.ts +10 -1
- package/src/verify/dispatch.ts +63 -6
- package/src/verify/dod.ts +127 -10
- package/src/verify/gate.ts +75 -7
- package/src/verify/types.ts +12 -0
- package/src/verify/wiring.ts +55 -10
- package/tiers.json +13 -5
package/src/verify/gate.ts
CHANGED
|
@@ -22,8 +22,9 @@ import type { DeterministicDeps } from "./types";
|
|
|
22
22
|
import type { DoD } from "./dod";
|
|
23
23
|
import { isCheckable } from "./dod";
|
|
24
24
|
import { runDeterministic } from "./deterministic";
|
|
25
|
-
import { runChecker } from "./checker";
|
|
25
|
+
import { incompleteVerdict, isIncompleteVerdict, runChecker } from "./checker";
|
|
26
26
|
import type { ArtefactView, CheckerDeps } from "./checker";
|
|
27
|
+
import type { BudgetSnapshot } from "../guard/enforce";
|
|
27
28
|
import { isAbsolute } from "node:path";
|
|
28
29
|
import { isWithinDir, resolveBaseDir } from "./paths";
|
|
29
30
|
|
|
@@ -35,6 +36,15 @@ export interface Artefact {
|
|
|
35
36
|
declaredOutputs: string[];
|
|
36
37
|
producerSessionID: string;
|
|
37
38
|
producerTier: string;
|
|
39
|
+
/** The producer follows the return contract (role agents, P2.1); absent = a router tier. */
|
|
40
|
+
returnContract?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* QA-P15-2-5: the producer's guard budget state captured when its task
|
|
43
|
+
* returned (enforce.ts captureBudget, with sessions.ts readCapReached). Absent:
|
|
44
|
+
* read live when the gate runs (the synchronous task path runs it right after
|
|
45
|
+
* the return).
|
|
46
|
+
*/
|
|
47
|
+
budget?: BudgetSnapshot;
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
/** The delegation being judged: its DoD plus dispatch-time classification. */
|
|
@@ -51,6 +61,24 @@ export interface Delegation {
|
|
|
51
61
|
* router's own directory", which is the pre-existing behaviour exactly.
|
|
52
62
|
*/
|
|
53
63
|
cwd?: string;
|
|
64
|
+
/**
|
|
65
|
+
* #84 P3.3 DF2-F1: the validated work root of a ROLE dispatch (plan §2.2; `routedWorkRoot`). Present: verification runs in
|
|
66
|
+
* it — the default base when `cwd` is absent, the base a relative `cwd` resolves against — and a `cwd` outside it is refused
|
|
67
|
+
* (unverifiable, nothing runs). Absent (tier dispatches): unchanged (I1). Set from `verificationScope` (index.ts): the child's
|
|
68
|
+
* bound work root, else its canonical session directory (QA-P33F1-1-1, 1-3), with `cwd` the checked canonical directory.
|
|
69
|
+
*/
|
|
70
|
+
workRoot?: string;
|
|
71
|
+
/**
|
|
72
|
+
* QA-P33F1-1-2: the `cwd:` the caller found outside `workRoot` by P2.3's containment rule (`verificationScope.refused`, as
|
|
73
|
+
* written). With `workRoot`, the gate refuses it (unverifiable) without resolving it.
|
|
74
|
+
*/
|
|
75
|
+
refusedCwd?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Fix-1 review nit: where the requested cwd (`cwd` / `refusedCwd`) came from — the call's own `cwd` argument or the
|
|
78
|
+
* `[acceptance]` block's `cwd:` (work-root.ts `requestedVerificationCwdSource`). Only names the source in a refusal; absent:
|
|
79
|
+
* the refusal names neither.
|
|
80
|
+
*/
|
|
81
|
+
cwdSource?: "argument" | "acceptance";
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
export interface GateDeps {
|
|
@@ -82,7 +110,9 @@ export function gateResult(verdict: Verdict, dodSource: DoD["source"], strictUnv
|
|
|
82
110
|
const outcome = verdict.outcome ?? (verdict.pass ? "pass" : "fail");
|
|
83
111
|
const caveats = verdict.caveats ?? (outcome === "unverifiable" ? verdict.reasons : []);
|
|
84
112
|
return {
|
|
85
|
-
|
|
113
|
+
// QA-P15-1-1: an incomplete return (progress note, budget stop) is never accepted;
|
|
114
|
+
// as an unverifiable outcome it still gets no next-tier hint and moves no evidence.
|
|
115
|
+
accepted: outcome !== "fail" && !isIncompleteVerdict(verdict) && !(strictUnverifiable && caveats.length > 0),
|
|
86
116
|
verdict: { ...verdict, outcome, ...(caveats.length ? { caveats } : {}) },
|
|
87
117
|
dodSource,
|
|
88
118
|
};
|
|
@@ -187,19 +217,55 @@ export async function accept(
|
|
|
187
217
|
// THAT directory, not the router's. Both verifiers get the same effective
|
|
188
218
|
// base dir so a deterministic check and a grader can never disagree about
|
|
189
219
|
// where the work was supposed to land.
|
|
220
|
+
// QA-P15-1-2 / 2-6 / I7: a budget stop, or a contract follower's progress note,
|
|
221
|
+
// is incomplete under either verifier — never a failure, never a next-tier hint.
|
|
222
|
+
// Judged on the snapshot captured when the task returned (artefact.budget, 2-5).
|
|
223
|
+
const stopped = incompleteVerdict(artefact, {
|
|
224
|
+
progressNotes: true,
|
|
225
|
+
ladder: deps.checker.ladder,
|
|
226
|
+
budgetSnapshot: deps.checker.budgetSnapshot,
|
|
227
|
+
});
|
|
228
|
+
if (stopped) return gateResult(stopped, dodSource, deps.strictUnverifiable);
|
|
229
|
+
|
|
230
|
+
// DF2-F1: a role dispatch is verified in its work root (its default base, and the base of a relative cwd), never the router's.
|
|
231
|
+
const workRoot = delegation.workRoot;
|
|
232
|
+
const refuseCwd = (cwd: string): GateResult => {
|
|
233
|
+
// Refused like any path outside the role's work root (§2.2): no check runs and no grader is dispatched there.
|
|
234
|
+
// The text names where the cwd came from (fix-1 review nit): the call's `cwd` argument, or the [acceptance] block's `cwd:`.
|
|
235
|
+
const [subject, remedy] = delegation.cwdSource === "argument"
|
|
236
|
+
? [`the call's cwd argument ${cwd}`, `Drop the "cwd" argument (the checks then run in the work root) or name a directory inside it.`]
|
|
237
|
+
: delegation.cwdSource === "acceptance"
|
|
238
|
+
? [`the [acceptance] block's cwd ${cwd}`, `Remove "cwd:" (the checks then run in the work root) or name a directory inside it.`]
|
|
239
|
+
: [`the requested cwd ${cwd}`, `Name no cwd (the checks then run in the work root) or one inside it.`];
|
|
240
|
+
const reason = `${subject} is outside this role dispatch's work root ${workRoot}; the router verifies a role dispatch only inside its work root. ${remedy}`;
|
|
241
|
+
return gateResult({ pass: false, outcome: "unverifiable", method: "none", reasons: [reason], caveats: [reason] }, dodSource, deps.strictUnverifiable);
|
|
242
|
+
};
|
|
243
|
+
// QA-P33F1-1-2: the caller decided containment with P2.3's rule (routing/roles/work-root.ts verificationScope); a refused cwd
|
|
244
|
+
// is never resolved here (a UNC/device path reaches no filesystem call).
|
|
245
|
+
if (workRoot !== undefined && delegation.refusedCwd !== undefined) return refuseCwd(delegation.refusedCwd);
|
|
190
246
|
const effectiveBaseDir = resolveBaseDir(
|
|
191
247
|
delegation.cwd,
|
|
192
|
-
deps.deterministic.cwd,
|
|
248
|
+
workRoot ?? deps.deterministic.cwd,
|
|
193
249
|
);
|
|
250
|
+
// Backstop for a caller that did not check its cwd: lexical only (no filesystem call); a checked canonical cwd always passes.
|
|
251
|
+
if (workRoot !== undefined && !isWithinDir(effectiveBaseDir, workRoot)) return refuseCwd(effectiveBaseDir);
|
|
252
|
+
const canonical = deps.canonicalPath ?? ((path: string) => path);
|
|
194
253
|
|
|
195
254
|
let verdict: Verdict;
|
|
196
255
|
if (dod.kind === "deterministic") {
|
|
197
|
-
const canonical = deps.canonicalPath ?? ((path: string) => path);
|
|
198
256
|
const canonicalBase = canonical(effectiveBaseDir);
|
|
199
257
|
if (artefact.changedFiles.length > 0 && artefact.changedFiles.every(
|
|
200
258
|
({ path }) => isAbsolute(path) && !isWithinDir(canonical(path), canonicalBase),
|
|
201
259
|
)) {
|
|
202
|
-
|
|
260
|
+
// QA-P33F1-1 nit 1: a cwd: narrower than the work root, with work elsewhere in the root → widen (or drop) the cwd:.
|
|
261
|
+
const narrowed = workRoot !== undefined && !isWithinDir(canonical(workRoot), canonicalBase)
|
|
262
|
+
&& artefact.changedFiles.some(({ path }) => isWithinDir(canonical(path), canonical(workRoot)));
|
|
263
|
+
const hint = workRoot === undefined
|
|
264
|
+
? `Add "cwd: <dir>" to the [acceptance] block to verify where the work landed.`
|
|
265
|
+
: narrowed
|
|
266
|
+
? `The [acceptance] block's "cwd:" narrows verification to ${effectiveBaseDir} inside the work root ${workRoot}: widen "cwd:" to where the work landed, or remove it (the checks then run in the work root).`
|
|
267
|
+
: `A role dispatch is verified only inside its work root ${workRoot}: the work belongs there.`;
|
|
268
|
+
const reason = `the producer changed files only outside ${effectiveBaseDir} (e.g. ${artefact.changedFiles[0].path}); checks run there cannot see them. ${hint}`;
|
|
203
269
|
return gateResult({ pass: false, outcome: "unverifiable", method: "none", reasons: [reason], caveats: [reason] }, dodSource, deps.strictUnverifiable);
|
|
204
270
|
}
|
|
205
271
|
verdict = await runDeterministic(dod, {
|
|
@@ -214,10 +280,12 @@ export async function accept(
|
|
|
214
280
|
artefact: view(artefact),
|
|
215
281
|
producerTier: artefact.producerTier,
|
|
216
282
|
producerSessionID: artefact.producerSessionID,
|
|
217
|
-
|
|
283
|
+
...(artefact.returnContract !== undefined ? { returnContract: artefact.returnContract } : {}),
|
|
284
|
+
...(artefact.budget !== undefined ? { budget: artefact.budget } : {}),
|
|
285
|
+
// Only when the delegation actually declared one (or is a role dispatch: its work root, DF2-F1). Passing the router's
|
|
218
286
|
// own directory here would scope every existing grader and add a
|
|
219
287
|
// working-directory line to every existing prompt for no reason.
|
|
220
|
-
...(delegation.cwd ? { workingDir: effectiveBaseDir } : {}),
|
|
288
|
+
...(delegation.cwd || workRoot !== undefined ? { workingDir: effectiveBaseDir } : {}),
|
|
221
289
|
},
|
|
222
290
|
deps.checker,
|
|
223
291
|
);
|
package/src/verify/types.ts
CHANGED
|
@@ -26,6 +26,12 @@ export interface Verdict {
|
|
|
26
26
|
* this verdict classified, concatenated across testsPass checks. Absent when no check classified.
|
|
27
27
|
*/
|
|
28
28
|
failures?: FailureClassification;
|
|
29
|
+
/**
|
|
30
|
+
* #84 P3.3 fix 2 (plan §2.6, I6): the LLM grader that judged this verdict (checker.ts runChecker, only once a grader
|
|
31
|
+
* session answered): the tier the checker asked for and the model the grader was dispatched on (`provider/model`, null when
|
|
32
|
+
* the router does not know it). Outcome signals weigh such a verdict as a grader's, never as a deterministic check's.
|
|
33
|
+
*/
|
|
34
|
+
grader?: { readonly tier: string; readonly model: string | null };
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export interface ExecResult {
|
|
@@ -96,6 +102,12 @@ export interface DeterministicDeps {
|
|
|
96
102
|
deadline?: Deadline;
|
|
97
103
|
/** Preserve completed failures if an outer gate budget expires later. */
|
|
98
104
|
onFailure?: (reason: string) => void;
|
|
105
|
+
/**
|
|
106
|
+
* #84 QA-G-B-2-1: set for a CARRIED acceptance (a role resume re-checking the block of an earlier attempt): a testsPass or
|
|
107
|
+
* lintClean check that ran no process (NoAffected: nothing of the change set maps to a test or a lintable file) is unverifiable
|
|
108
|
+
* with this reason, never a pass. Absent (every other gate, I1): NoAffected passes with its note, as before.
|
|
109
|
+
*/
|
|
110
|
+
noAffectedUnverifiable?: string;
|
|
99
111
|
exec: ExecSeam;
|
|
100
112
|
/** Any FsSeam; lintClean scoping also uses the optional PlannerFs members when present. */
|
|
101
113
|
fs: import("./runner").PlannerFs;
|
package/src/verify/wiring.ts
CHANGED
|
@@ -96,6 +96,8 @@ import { accept, gateResult, unverifiableGateResult, type GateDeps, type GateRes
|
|
|
96
96
|
// wiring's narrower structural type silently discarded it, and the grader ran
|
|
97
97
|
// against the router's directory while claiming to check the producer's.
|
|
98
98
|
import type { GraderRequest } from "./checker";
|
|
99
|
+
import { isIncompleteVerdict } from "./checker";
|
|
100
|
+
import type { BudgetSnapshot } from "../guard/enforce";
|
|
99
101
|
export type { GraderRequest };
|
|
100
102
|
|
|
101
103
|
/**
|
|
@@ -396,8 +398,23 @@ export interface DeferredFinishInput {
|
|
|
396
398
|
readonly cwd: string | undefined;
|
|
397
399
|
readonly dod: DoD;
|
|
398
400
|
readonly dispatchedAt: number;
|
|
401
|
+
/**
|
|
402
|
+
* #84 P2.1 (handoff 24, R7): the producer's guard budget state captured when its task returned (enforce.ts captureBudget with
|
|
403
|
+
* sessions.ts readCapReached). A later `router_verify` judges THIS snapshot, never the live state at verification time. Absent:
|
|
404
|
+
* the gate reads it live, as before.
|
|
405
|
+
*/
|
|
406
|
+
readonly budget?: BudgetSnapshot;
|
|
407
|
+
/**
|
|
408
|
+
* #84 P3.3 DF2-F1 (fix-1 review nit): the role dispatch's verification root (the gate's `Delegation.workRoot`). `router_verify`
|
|
409
|
+
* hands it to its gate, which then re-checks the stored cwd's containment and gives the role's hints. Absent (tier dispatches):
|
|
410
|
+
* the gate runs as before (I1).
|
|
411
|
+
*/
|
|
412
|
+
readonly workRoot?: string;
|
|
399
413
|
}
|
|
400
414
|
|
|
415
|
+
/** Deferred budget snapshots kept for `router_verify` (by handle; oldest dropped first, like the pending registry's bound). */
|
|
416
|
+
export const MAX_DEFERRED_BUDGETS = 1000;
|
|
417
|
+
|
|
401
418
|
/**
|
|
402
419
|
* What finishDeferred decided. `deferred: false` means the delegation is NOT deferred and the
|
|
403
420
|
* caller runs today's required gate on it (QA-2.4-4, QA-2.4-10): the dispatch record is left in the
|
|
@@ -668,7 +685,7 @@ export function formatVerifyReport(
|
|
|
668
685
|
if (judged.accepted) {
|
|
669
686
|
lines.push(indent(buildAcceptedSuffix(verdict.method, judged.verdict.outcome, judged.verdict.caveats, verdict.notes).trim()));
|
|
670
687
|
} else {
|
|
671
|
-
lines.push(indent(scrubText(buildForcingNote(verdict.reasons, { producerTier: item.producerTier, nextTier: result.nextTier ?? null }))));
|
|
688
|
+
lines.push(indent(scrubText(buildForcingNote(verdict.reasons, { producerTier: item.producerTier, nextTier: result.nextTier ?? null, incomplete: isIncompleteVerdict(verdict) }))));
|
|
672
689
|
lines.push(indent(ROUTER_VERIFY_NO_RETRY_TEXT));
|
|
673
690
|
}
|
|
674
691
|
blocks.push(lines.join("\n"));
|
|
@@ -895,12 +912,12 @@ export interface VerificationWiring {
|
|
|
895
912
|
graderSessions: Set<string>;
|
|
896
913
|
/** Stop a plugin-created child; v1 deletes it, a host runner owns v2 cleanup. Never throws. */
|
|
897
914
|
disposeChildSession(sid: string): Promise<void>;
|
|
898
|
-
/** Run one grader turn, parented to the caller's session when given. */
|
|
915
|
+
/** Run one grader turn, parented to the caller's session when given. `model`: the model it was dispatched on (null = host default). */
|
|
899
916
|
dispatchGrader(
|
|
900
917
|
req: GraderRequest,
|
|
901
918
|
parentSessionID?: string,
|
|
902
919
|
inFlight?: Set<string>,
|
|
903
|
-
): Promise<{ sessionID: string; text: string }>;
|
|
920
|
+
): Promise<{ sessionID: string; text: string; model?: string | null }>;
|
|
904
921
|
/**
|
|
905
922
|
* Deps for the acceptance gate; graders are parented to parentSessionID.
|
|
906
923
|
*
|
|
@@ -1212,16 +1229,21 @@ export function createVerificationWiring(deps: {
|
|
|
1212
1229
|
parentSessionID?: string,
|
|
1213
1230
|
inFlight?: Set<string>,
|
|
1214
1231
|
creatorSessionID: string | null = parentSessionID ?? null,
|
|
1215
|
-
): Promise<{ sessionID: string; text: string }> => {
|
|
1232
|
+
): Promise<{ sessionID: string; text: string; model: string | null }> => {
|
|
1233
|
+
// #84 P3.3 fix 2: the model the grader is dispatched on travels with its answer (checker.ts GraderResult.model → the
|
|
1234
|
+
// verdict's `grader`), so the outcome signals can check its independence (plan §2.6). Null: the host's default model.
|
|
1235
|
+
const modelRef = (model: { providerID: string; modelID: string } | null): string | null =>
|
|
1236
|
+
model === null ? null : `${model.providerID}/${model.modelID}`;
|
|
1216
1237
|
if (deps.childRunner) {
|
|
1217
1238
|
const cfg = getConfig();
|
|
1218
1239
|
const controller = new AbortController();
|
|
1240
|
+
const model = tierModel(cfg, req.tier);
|
|
1219
1241
|
let sid: string | undefined;
|
|
1220
1242
|
try {
|
|
1221
|
-
|
|
1243
|
+
const answer = await withTimeout(deps.childRunner.run({
|
|
1222
1244
|
parentSessionID,
|
|
1223
1245
|
cwd: req.cwd,
|
|
1224
|
-
model:
|
|
1246
|
+
model: model ?? undefined,
|
|
1225
1247
|
system: req.system,
|
|
1226
1248
|
prompt: req.prompt,
|
|
1227
1249
|
signal: controller.signal,
|
|
@@ -1232,6 +1254,7 @@ export function createVerificationWiring(deps: {
|
|
|
1232
1254
|
notifyChildCreated(sessionID, creatorSessionID);
|
|
1233
1255
|
},
|
|
1234
1256
|
}), graderTimeoutMs(req.tier, cfg.enforcement?.verify?.graderTimeoutMs), "grader prompt");
|
|
1257
|
+
return { sessionID: answer.sessionID, text: answer.text, model: modelRef(model) };
|
|
1235
1258
|
} finally {
|
|
1236
1259
|
controller.abort();
|
|
1237
1260
|
if (sid) {
|
|
@@ -1251,13 +1274,14 @@ export function createVerificationWiring(deps: {
|
|
|
1251
1274
|
...(req.cwd ? { query: { directory: req.cwd } } : {}),
|
|
1252
1275
|
});
|
|
1253
1276
|
const sid: string | undefined = created?.data?.id;
|
|
1254
|
-
if (!sid) return { sessionID: "", text: "" };
|
|
1277
|
+
if (!sid) return { sessionID: "", text: "", model: null };
|
|
1255
1278
|
graderSessions.add(sid);
|
|
1256
1279
|
inFlight?.add(sid);
|
|
1257
1280
|
notifyChildCreated(sid, creatorSessionID);
|
|
1258
1281
|
try {
|
|
1259
1282
|
const cfg = getConfig();
|
|
1260
|
-
const
|
|
1283
|
+
const tiered = tierModel(cfg, req.tier);
|
|
1284
|
+
const model = tiered ?? undefined;
|
|
1261
1285
|
// Time-boxed for the same reason as the producer prompt, but with a
|
|
1262
1286
|
// sharper edge: a grader that never answers must not be able to hold the
|
|
1263
1287
|
// gate open. The RouterTimeoutError is deliberately allowed to propagate
|
|
@@ -1285,7 +1309,7 @@ export function createVerificationWiring(deps: {
|
|
|
1285
1309
|
);
|
|
1286
1310
|
const responseError = graderPromptResponseError(res);
|
|
1287
1311
|
if (responseError) throw responseError;
|
|
1288
|
-
return { sessionID: sid, text: extractAssistantText(res) };
|
|
1312
|
+
return { sessionID: sid, text: extractAssistantText(res), model: modelRef(tiered) };
|
|
1289
1313
|
} finally {
|
|
1290
1314
|
graderSessions.delete(sid);
|
|
1291
1315
|
inFlight?.delete(sid);
|
|
@@ -1592,6 +1616,10 @@ export function createVerificationWiring(deps: {
|
|
|
1592
1616
|
return plans.find(p => "unverifiable" in p) ?? plans[0] ?? unfinished;
|
|
1593
1617
|
};
|
|
1594
1618
|
|
|
1619
|
+
/** #84 P2.1 (handoff 24): deferred budget snapshots by handle, read by `router_verify` (bounded, oldest out). */
|
|
1620
|
+
const deferredBudgets = new Map<string, BudgetSnapshot>();
|
|
1621
|
+
/** #84 P3.3 DF2-F1: the work roots of deferred role dispatches by handle, read by `router_verify` (same bound as the budgets). */
|
|
1622
|
+
const deferredWorkRoots = new Map<string, string>();
|
|
1595
1623
|
const finishDeferred: VerificationWiring["finishDeferred"] = async (store, input) => {
|
|
1596
1624
|
const producerTier = canonicalTier(input.producerTier);
|
|
1597
1625
|
// The live reference promise (no signal: never awaited here). Its settled value at this moment
|
|
@@ -1658,6 +1686,17 @@ export function createVerificationWiring(deps: {
|
|
|
1658
1686
|
return { deferred: false, reason: "unregistered", detail: `${reg.code}: ${reg.detail}` };
|
|
1659
1687
|
}
|
|
1660
1688
|
deferred = true;
|
|
1689
|
+
// #84 P2.1 (handoff 24, R7): the budget captured at return travels with the handle to `router_verify`.
|
|
1690
|
+
if (input.budget !== undefined) {
|
|
1691
|
+
deferredBudgets.delete(reg.handle);
|
|
1692
|
+
deferredBudgets.set(reg.handle, input.budget);
|
|
1693
|
+
while (deferredBudgets.size > MAX_DEFERRED_BUDGETS) deferredBudgets.delete(deferredBudgets.keys().next().value as string);
|
|
1694
|
+
}
|
|
1695
|
+
if (input.workRoot !== undefined) {
|
|
1696
|
+
deferredWorkRoots.delete(reg.handle);
|
|
1697
|
+
deferredWorkRoots.set(reg.handle, input.workRoot);
|
|
1698
|
+
while (deferredWorkRoots.size > MAX_DEFERRED_BUDGETS) deferredWorkRoots.delete(deferredWorkRoots.keys().next().value as string);
|
|
1699
|
+
}
|
|
1661
1700
|
// 2.4.5 (pending.ts R14): queued, never awaited: the queue's own timer starts the run later.
|
|
1662
1701
|
// An unattributed change set is not queued (nothing could run; it stays listed instead).
|
|
1663
1702
|
if (background !== undefined && changedFiles !== "unavailable") {
|
|
@@ -1842,12 +1881,16 @@ export function createVerificationWiring(deps: {
|
|
|
1842
1881
|
declaredOutputs: dod.deliverable ? [dod.deliverable] : [],
|
|
1843
1882
|
producerSessionID: entry.producerSessionID,
|
|
1844
1883
|
producerTier: entry.producerTier,
|
|
1884
|
+
// #84 P2.1 (handoff 24, R7): the snapshot captured when the task returned; absent → read live, as before.
|
|
1885
|
+
...(deferredBudgets.has(entry.handle) ? { budget: deferredBudgets.get(entry.handle) as BudgetSnapshot } : {}),
|
|
1845
1886
|
};
|
|
1846
1887
|
let res: GateResult;
|
|
1847
1888
|
let timedOut = false;
|
|
1889
|
+
// #84 P3.3 DF2-F1: a deferred role dispatch is judged in its work root, as its synchronous gate would be.
|
|
1890
|
+
const workRoot = deferredWorkRoots.get(entry.handle);
|
|
1848
1891
|
try {
|
|
1849
1892
|
res = await withTimeout(
|
|
1850
|
-
accept({ dod, trivial: false, mode: "modeA", cwd: entry.cwd }, artefact, gateDeps),
|
|
1893
|
+
accept({ dod, trivial: false, mode: "modeA", cwd: entry.cwd, ...(workRoot !== undefined ? { workRoot } : {}) }, artefact, gateDeps),
|
|
1851
1894
|
deadline.remaining(),
|
|
1852
1895
|
"verification gate",
|
|
1853
1896
|
);
|
|
@@ -2198,6 +2241,8 @@ export function createVerificationWiring(deps: {
|
|
|
2198
2241
|
},
|
|
2199
2242
|
disposeVerification: () => {
|
|
2200
2243
|
dispatchStarts.clear();
|
|
2244
|
+
deferredBudgets.clear();
|
|
2245
|
+
deferredWorkRoots.clear();
|
|
2201
2246
|
// 2.4.5: abort the background run first, so nothing re-queues while the coordinator stops.
|
|
2202
2247
|
background?.dispose();
|
|
2203
2248
|
return coordinator.dispose();
|
package/tiers.json
CHANGED
|
@@ -38,18 +38,19 @@
|
|
|
38
38
|
"heavy": 3
|
|
39
39
|
},
|
|
40
40
|
"tierPrompts": {
|
|
41
|
-
"fast": "STOP CONDITIONS — read these FIRST, they govern EVERY tool call:\n\n1. CAP: ≤8 read-only tool calls (grep/read/glob/ls) per dispatch. If the dispatch prompt contains `CAP:N`, N is your cap; `CAP:none` removes the numeric cap, but only when the dispatch also carries a `reason:` line — an unjustified `CAP:none` falls back to the baseline. The opencode runtime tracks your count and appends `[cap: N/MAX]` to every read-only tool result — that's your LIVE COUNTER. When N=MAX, your next action MUST be a return, not another read.\n\n2. REDUNDANCY: before every new read/grep/glob, ask yourself: \"Am I re-reading the same region or re-running a similar search I already ran?\" The runtime ALSO detects this and appends `[⚠ REDUNDANT]` to your tool result when you repeat a call. When you see that marker, stop repeating covered ground — repeated reads add nothing. A different region of the same file is not a repeat; the marker alone is not a reason to abandon the dispatch.\n\n3. RETURN PROTOCOL: on stop (cap reached or scope satisfied), return with EXACTLY ONE of these prefixes as the FIRST line of your response:\n - `DONE: [one-line summary]` — the dispatch request is fully satisfied with what you have.\n - `NEED MORE: [specific ask]` — you need the orchestrator to dispatch another targeted round.\n - `ESCALATE: [reason]` — hand back for orchestrator to re-dispatch or decide.\n\n4. EXCEEDING CAP: only if the task is irreversibly incomplete AND returning with NEED MORE is worse than one more read. Prepend `reason: <1-line>` above your return. This should be rare.\n\n---\n\nROLE: You are @fast — a read-only exploration specialist. Scope: search, grep, read, ls, lookup, doc-lookup, type-check, count, exists-check, git-info. NEVER write, edit, or modify files. If the task requires edits, that is out of scope: report what needs changing and return. Return findings concisely: file:line paths, quoted snippets, and a one-line summary.\n\nPrefer a single focused pass; stop as soon as you have enough to answer the exact question asked. Do not explore beyond the asked scope. You execute this dispatch yourself: work within your scope and return findings.",
|
|
41
|
+
"fast": "STOP CONDITIONS — read these FIRST, they govern EVERY tool call:\n\n1. CAP: ≤8 read-only tool calls (grep/read/glob/ls) per dispatch. If the dispatch prompt contains `CAP:N`, N is your cap; `CAP:none` removes the numeric cap, but only when the dispatch also carries a `reason:` line — an unjustified `CAP:none` falls back to the baseline. The opencode runtime tracks your count and appends `[cap: N/MAX]` to every read-only tool result — that's your LIVE COUNTER. When N=MAX, your next action MUST be a return, not another read.\n\n2. REDUNDANCY: before every new read/grep/glob, ask yourself: \"Am I re-reading the same region or re-running a similar search I already ran?\" The runtime ALSO detects this and appends `[⚠ REDUNDANT]` to your tool result when you repeat a call. When you see that marker, stop repeating covered ground — repeated reads add nothing. A different region of the same file is not a repeat; the marker alone is not a reason to abandon the dispatch.\n\n3. RETURN PROTOCOL: on stop (cap reached or scope satisfied), return with EXACTLY ONE of these prefixes as the FIRST line of your response:\n - `DONE: [one-line summary]` — the dispatch request is fully satisfied with what you have.\n - `NEED MORE: [specific ask]` — you need the orchestrator to dispatch another targeted round.\n - `ESCALATE: [reason]` — hand back for orchestrator to re-dispatch or decide.\n\n4. EXCEEDING CAP: only if the task is irreversibly incomplete AND returning with NEED MORE is worse than one more read. Prepend `reason: <1-line>` above your return. This should be rare.\n\n---\n\nROLE: You are @fast — a read-only exploration specialist. Scope: search, grep, read, ls, lookup, doc-lookup, type-check, count, exists-check, git-info. NEVER write, edit, or modify files. If the task requires edits, that is out of scope: report what needs changing and return. Return findings concisely: file:line paths, quoted snippets, and a one-line summary.\n\nPrefer a single focused pass; stop as soon as you have enough to answer the exact question asked. Do not explore beyond the asked scope. You execute this dispatch yourself: work within your scope and return findings.\n\nDirect tools (read, glob, grep, router_git_*) and the Code Mode catalog are separate; an empty Code Mode search does not mean a direct tool is missing. You cannot run a shell or edit files: report what you found, with file:line evidence, and say what a higher tier should do.",
|
|
42
42
|
"medium": "STOP CONDITIONS — read these FIRST, they govern EVERY read-only tool call BEFORE you begin editing:\n\n1. CAP: ≤5 read-only tool calls (grep/read/glob/ls) before you start editing. `CAP:N` in the dispatch overrides; `CAP:none` disables it, but only when the dispatch also carries a `reason:` line — an unjustified `CAP:none` falls back to the baseline. The opencode runtime tracks your reads and appends `[cap: N/MAX]` to every read-only tool result — that's your LIVE COUNTER. When N=MAX, start editing or return; do not make another read-only call.\n\n2. REDUNDANCY: before every new grep/read, ask: \"Did I already read this region or run a similar search?\" The runtime appends `[⚠ REDUNDANT]` to your tool result when you repeat a call. When you see that marker, stop repeating covered ground — repeated reads add nothing. A different region of the same file is not a repeat; the marker alone is not a reason to abandon the dispatch.\n\n3. RETURN PROTOCOL (when stopping before/instead of full implementation): first line of your response must be EXACTLY ONE of:\n - `DONE: [summary of edits + verification]` — implementation complete.\n - `NEED CONTEXT: [specific ask]` — requires orchestrator to dispatch @fast and re-invoke.\n - `ESCALATE: [reason]` — scope grew beyond implementation (e.g. architectural decision needed).\n\n4. EXCEEDING CAP: only when the implementation genuinely requires more context. Prepend `reason: <1-line>` above your summary.\n\n---\n\nROLE: You are @medium — an implementation specialist. Scope: write/edit code, refactor, write tests, fix bugs, apply build-fixes, create files, config changes, API endpoints. Match existing project patterns exactly. Never suppress type errors (no `as any`, `@ts-ignore`, `@ts-expect-error`). Run targeted tests/linters for the changed area only — never the full suite unless asked. If you hit 2+ consecutive failures on the same issue, STOP and report back to the orchestrator with what you tried; do not self-escalate to @heavy. Return a concise summary: files changed, key decisions, tests added, verification run.\n\nYou execute this dispatch yourself rather than routing it to another tier. Avoid grep/read-exhaustive sweeps.\n\nBefore reporting progress, audit each claim against a tool result from this session. Only report work you can point to evidence for; if unverified, say so explicitly. If tests fail, report it with the relevant excerpt of the output.",
|
|
43
43
|
"heavy": "STOP CONDITIONS — read these FIRST, they govern EVERY tool call:\n\n1. CAP: ≤3 reads/greps per dispatch. `CAP:N` in the dispatch overrides; `CAP:none` disables it when the dispatch also carries a `reason:` line (used in `deep` mode). The opencode runtime tracks your count and appends `[cap: N/MAX]` to every read-only tool result — that's your LIVE COUNTER. You are an analysis specialist, not a reconnaissance specialist: at N=MAX, return your analysis based on what you have, or return `SCOPE GROWTH` asking for @fast pre-exploration.\n\n2. REDUNDANCY: before every new tool call, ask: \"Is this re-reading ground I've already covered or information already in my context?\" The runtime appends `[⚠ REDUNDANT]` to your tool result when you repeat a call. When you see that marker, stop repeating covered ground — repeated reads add nothing. A different region of the same file is not a repeat; the marker alone is not a reason to abandon the dispatch.\n\n3. RETURN PROTOCOL: first line of your response must be EXACTLY ONE of:\n - `DONE: [structured analysis]` — request fully satisfied.\n - `SCOPE GROWTH: prefer @fast pre-exploration of [specific files/patterns/areas] before I continue.` — orchestrator dispatches @fast and re-invokes you.\n - `ESCALATE: [reason]` — hand back for orchestrator decision.\n\n4. EXCEEDING CAP: only when the analysis genuinely cannot be completed without one more read AND `SCOPE GROWTH` would be worse. Prepend `reason: <1-line>`.\n\n---\n\nROLE: You are @heavy — a senior architecture and debugging consultant. Scope: architecture decisions, security review, perf optimization, complex debugging (invoked after ≥2 prior failures), multi-system tradeoffs, migration strategy, root-cause analysis. Analyze exhaustively WITHIN the context you were given. Provide reasoning, tradeoffs, and concrete recommendations. Default to analysis + recommendations; write code only when the orchestrator explicitly asked for implementation. Return structured output: problem framing → options considered → tradeoffs → recommendation → implementation notes (if applicable).\n\nYou execute this dispatch yourself rather than routing it to another tier. Your job is analysis, not reconnaissance. 40 minutes of file reads is not analysis — it's reconnaissance. Stop early, analyze what you have, return SCOPE GROWTH if genuinely needed.\n\nBefore reporting progress, audit each claim against a tool result or the context you were given this session. Only report work you can point to evidence for; if unverified, say so explicitly. If tests fail, report it with the relevant excerpt of the output."
|
|
44
44
|
},
|
|
45
45
|
"presets": {
|
|
46
46
|
"anthropic": {
|
|
47
47
|
"fast": {
|
|
48
|
-
"
|
|
48
|
+
"readOnly": true,
|
|
49
|
+
"model": "anthropic/claude-haiku-5-5",
|
|
49
50
|
"variant": "low",
|
|
50
51
|
"effort": "low",
|
|
51
52
|
"costRatio": 1,
|
|
52
|
-
"description": "
|
|
53
|
+
"description": "Haiku 5.5 low for exploration, search, and simple reads",
|
|
53
54
|
"steps": 30,
|
|
54
55
|
"whenToUse": [
|
|
55
56
|
"Codebase exploration and search",
|
|
@@ -90,6 +91,7 @@
|
|
|
90
91
|
},
|
|
91
92
|
"openai": {
|
|
92
93
|
"fast": {
|
|
94
|
+
"readOnly": true,
|
|
93
95
|
"model": "openai/gpt-6-luna-fast",
|
|
94
96
|
"costRatio": 1,
|
|
95
97
|
"description": "GPT-6 Luna Fast for fast exploration and simple tasks",
|
|
@@ -129,6 +131,7 @@
|
|
|
129
131
|
},
|
|
130
132
|
"github-copilot": {
|
|
131
133
|
"fast": {
|
|
134
|
+
"readOnly": true,
|
|
132
135
|
"model": "github-copilot/claude-haiku-4.5",
|
|
133
136
|
"costRatio": 1,
|
|
134
137
|
"description": "Claude Haiku 4.5 via GitHub Copilot for fast exploration and simple tasks",
|
|
@@ -168,6 +171,7 @@
|
|
|
168
171
|
},
|
|
169
172
|
"google": {
|
|
170
173
|
"fast": {
|
|
174
|
+
"readOnly": true,
|
|
171
175
|
"model": "google/gemini-3.5-flash-lite",
|
|
172
176
|
"costRatio": 1,
|
|
173
177
|
"description": "Gemini 3.5 Flash Lite for fast exploration and simple tasks",
|
|
@@ -207,6 +211,7 @@
|
|
|
207
211
|
},
|
|
208
212
|
"zai": {
|
|
209
213
|
"fast": {
|
|
214
|
+
"readOnly": true,
|
|
210
215
|
"model": "zai-coding-plan/glm-4.7",
|
|
211
216
|
"costRatio": 1,
|
|
212
217
|
"description": "GLM-4.7 for read-only exploration, search, and simple lookups (requires the Z.AI Coding Plan; token-spend ratios are estimates, not price differences)",
|
|
@@ -248,6 +253,7 @@
|
|
|
248
253
|
},
|
|
249
254
|
"hybrid": {
|
|
250
255
|
"fast": {
|
|
256
|
+
"readOnly": true,
|
|
251
257
|
"model": "openai/gpt-6-luna-fast",
|
|
252
258
|
"variant": "medium",
|
|
253
259
|
"costRatio": 1,
|
|
@@ -290,6 +296,7 @@
|
|
|
290
296
|
},
|
|
291
297
|
"hybrid-2": {
|
|
292
298
|
"fast": {
|
|
299
|
+
"readOnly": true,
|
|
293
300
|
"model": "openai/gpt-6-luna-fast",
|
|
294
301
|
"variant": "medium",
|
|
295
302
|
"costRatio": 1,
|
|
@@ -333,6 +340,7 @@
|
|
|
333
340
|
},
|
|
334
341
|
"fable-effort": {
|
|
335
342
|
"fast": {
|
|
343
|
+
"readOnly": true,
|
|
336
344
|
"model": "anthropic/claude-fable-5-1",
|
|
337
345
|
"effort": "low",
|
|
338
346
|
"costRatio": 1,
|
|
@@ -382,10 +390,10 @@
|
|
|
382
390
|
"ls",
|
|
383
391
|
"lookup-docs/types",
|
|
384
392
|
"count",
|
|
385
|
-
"exists-check"
|
|
386
|
-
"rename"
|
|
393
|
+
"exists-check"
|
|
387
394
|
],
|
|
388
395
|
"medium": [
|
|
396
|
+
"rename",
|
|
389
397
|
"impl-feature",
|
|
390
398
|
"refactor",
|
|
391
399
|
"write-tests",
|