opencode-model-router 2.8.0 → 2.9.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 +372 -0
- package/README.md +22 -2
- package/package.json +5 -1
- package/src/commands/output.ts +23 -1
- package/src/compat/background.ts +2439 -0
- package/src/compat/child-session.ts +6 -0
- package/src/compat/turn-state.ts +215 -0
- package/src/compat/v2-client.ts +136 -17
- package/src/compat/v2-hooks.ts +2656 -114
- package/src/compat/v2-observations.ts +328 -0
- package/src/executor/capacity.ts +362 -0
- package/src/executor/child-guards.ts +40 -0
- package/src/executor/command.ts +265 -0
- package/src/executor/compile/edges.ts +809 -0
- package/src/executor/compile/estimate.ts +158 -0
- package/src/executor/compile/footprint.ts +829 -0
- package/src/executor/compile/index.ts +1080 -0
- package/src/executor/compile/parse.ts +1492 -0
- package/src/executor/compile/residue.ts +706 -0
- package/src/executor/compile/validate.ts +280 -0
- package/src/executor/create.ts +672 -0
- package/src/executor/expand.ts +551 -0
- package/src/executor/git.ts +1214 -0
- package/src/executor/host-preamble.ts +17 -0
- package/src/executor/instructions.ts +35 -0
- package/src/executor/integrate/bisect.ts +73 -0
- package/src/executor/integrate/checks.ts +1086 -0
- package/src/executor/integrate/land.ts +177 -0
- package/src/executor/integrate/phase-suite.ts +407 -0
- package/src/executor/integrate/queue.ts +3083 -0
- package/src/executor/integrate/run-resolver.ts +19 -0
- package/src/executor/launch.ts +652 -0
- package/src/executor/ledger.ts +2208 -0
- package/src/executor/observations.ts +212 -0
- package/src/executor/paths.ts +159 -0
- package/src/executor/platform.ts +39 -0
- package/src/executor/process-identity.ts +19 -0
- package/src/executor/qa-loop.ts +470 -0
- package/src/executor/recovery.ts +403 -0
- package/src/executor/runtime.ts +6233 -0
- package/src/executor/schedule.ts +246 -0
- package/src/executor/slots/env.ts +145 -0
- package/src/executor/slots/pool.ts +1564 -0
- package/src/executor/slots/provision.ts +853 -0
- package/src/executor/tool.ts +534 -0
- package/src/executor/types.ts +2064 -0
- package/src/executor/unattended.ts +488 -0
- package/src/guard/store.ts +3 -1
- package/src/index.ts +1498 -288
- package/src/router/config.ts +776 -25
- package/src/router/git-tools.ts +106 -15
- package/src/router/leases.ts +1469 -0
- package/src/router/logger.ts +44 -32
- package/src/router/protocol.ts +40 -10
- package/src/router/role-agents.ts +224 -17
- package/src/router/roles-config.ts +10 -1
- package/src/router/roles.ts +1 -1
- package/src/router/run-tools.ts +56 -4
- package/src/router/tool-paths.ts +308 -0
- package/src/router/work-roots.ts +86 -0
- package/src/routing/advisor/findings.ts +25 -5
- package/src/routing/classify/index.ts +7 -1
- package/src/routing/classify/rules.ts +11 -0
- package/src/routing/commands/stats.ts +2 -2
- package/src/routing/outcomes/durations.ts +225 -0
- package/src/routing/outcomes/index.ts +59 -2
- package/src/routing/outcomes/persist.ts +409 -0
- package/src/routing/outcomes/stats.ts +170 -11
- package/src/routing/outcomes/timings.ts +836 -0
- package/src/routing/outcomes/types.ts +98 -0
- package/src/routing/roles/approvals.ts +86 -5
- package/src/routing/roles/binding.ts +99 -9
- package/src/routing/roles/orphans.ts +68 -0
- package/src/routing/roles/policy.ts +21 -3
- package/src/routing/roles/work-root.ts +3 -1
- package/src/routing/wire/dispatch.ts +86 -12
- package/src/routing/wire/hint.ts +56 -8
- package/src/v2.ts +94 -49
- package/src/verify/branch.ts +8 -2
- package/src/verify/canonical-path.ts +35 -0
- package/src/verify/deterministic.ts +38 -9
- package/src/verify/dispatch.ts +64 -28
- package/src/verify/exec.ts +52 -9
- package/src/verify/pending.ts +1691 -10
- package/src/verify/perimeter.ts +12 -6
- package/src/verify/plan-task.ts +729 -0
- package/src/verify/reference.ts +216 -3
- package/src/verify/tree.ts +30 -13
- package/src/verify/types.ts +9 -2
- package/src/verify/wiring.ts +290 -31
- package/tiers.json +5 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// QA-4.2-1: the v2 host's native-subagent preamble, shared by the v2 adapter (M41 launch-header matching) and recovery
|
|
2
|
+
// (R1 launch-header evidence). A leaf module with no imports, so both can use it without an import cycle.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* QA-3.1-16: the v2 host puts this exact line (ending in "\n", or "\r\n") before the first user message of every native-subagent
|
|
6
|
+
* child (recorded in docs/qa/role-tier/evidence/roots-handoffs.json, ladder.json), so a launcher prompt reaches the child either
|
|
7
|
+
* at offset 0 or right after this one line; no other leading text counts.
|
|
8
|
+
*/
|
|
9
|
+
export const HOST_SUBAGENT_PREAMBLE = "You are a subagent spawned by another session.";
|
|
10
|
+
|
|
11
|
+
/** The text after the host's one preamble line when it starts with exactly that line, else the text unchanged (QA-3.1-16). */
|
|
12
|
+
export function withoutHostPreamble(text: string): string {
|
|
13
|
+
for (const eol of ["\n", "\r\n"]) {
|
|
14
|
+
if (text.startsWith(HOST_SUBAGENT_PREAMBLE + eol)) return text.slice(HOST_SUBAGENT_PREAMBLE.length + eol.length);
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PLAN_PROVIDER_ORDER, type TurnStateProvider } from "../compat/turn-state";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Executor instructions (plan task 4.1.6, v2 only): a turn-state provider section, never system-prompt text. It renders
|
|
5
|
+
* only while a plan runs in the session (`planLine` is non-null) and is byte-stable for the same state, so the cached
|
|
6
|
+
* prefix is untouched. Registration is a handoff to 5.1.2; nothing here registers itself.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Provider name; sorts right after the "plan" provider (`PLAN_PROVIDER_NAME`). */
|
|
10
|
+
export const EXECUTOR_INSTRUCTIONS_PROVIDER_NAME = "plan-instructions";
|
|
11
|
+
|
|
12
|
+
/** Right after the plan section, which the v2 adapter registers at `PLAN_PROVIDER_ORDER` (turn-state.ts). */
|
|
13
|
+
export const EXECUTOR_INSTRUCTIONS_ORDER = PLAN_PROVIDER_ORDER + 1;
|
|
14
|
+
|
|
15
|
+
/** The exact text rendered while a plan runs. */
|
|
16
|
+
export const EXECUTOR_INSTRUCTIONS_TEXT = [
|
|
17
|
+
"Plan executor rules:",
|
|
18
|
+
"- Run the `manual` tasks listed in the router state yourself and report each with `router_plan action=done`.",
|
|
19
|
+
"- Never edit a slot or the plan file.",
|
|
20
|
+
"- Never report the plan done while `router_plan action=status` says running.",
|
|
21
|
+
"- Answer inbox items only with the human's answer or with text this plan already states.",
|
|
22
|
+
].join("\n");
|
|
23
|
+
|
|
24
|
+
export interface ExecutorInstructionsRuntime {
|
|
25
|
+
planLine(sessionID: string): string | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createExecutorInstructionsProvider(runtime: ExecutorInstructionsRuntime): TurnStateProvider {
|
|
29
|
+
return {
|
|
30
|
+
name: EXECUTOR_INSTRUCTIONS_PROVIDER_NAME,
|
|
31
|
+
order: EXECUTOR_INSTRUCTIONS_ORDER,
|
|
32
|
+
render: (sid) => (runtime.planLine(sid) === null ? undefined : EXECUTOR_INSTRUCTIONS_TEXT),
|
|
33
|
+
active: (sid) => runtime.planLine(sid) !== null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Range bisect (plan 3.2.4, memo 3.2.1 M24): pure search over a phase's integrated task ranges.
|
|
3
|
+
*
|
|
4
|
+
* Verdicts are monotone along the integration chain: once the failing ids fail at a commit they keep failing
|
|
5
|
+
* at every later commit of the phase. The search finds the first range whose `to` fails, then confirms the
|
|
6
|
+
* boundary (the culprit's `from` must pass). It never touches git: the caller supplies the probe.
|
|
7
|
+
*/
|
|
8
|
+
import type { TaskRange } from "./queue";
|
|
9
|
+
|
|
10
|
+
export type { TaskRange };
|
|
11
|
+
|
|
12
|
+
export type ProbeVerdict = "pass" | "fail";
|
|
13
|
+
export type RangeBisectResult = { kind: "culprit"; index: number; range: TaskRange; probes: number }
|
|
14
|
+
| { kind: "outside"; reason: "from-fails" | "last-passes"; probes: number };
|
|
15
|
+
|
|
16
|
+
/** Orders by the position of `to` in `chain` (revList(base, suiteCommit), oldest first); throws on a `to` not in chain. */
|
|
17
|
+
export function orderRanges(ranges: readonly TaskRange[], chain: readonly string[]): TaskRange[] {
|
|
18
|
+
const position = new Map<string, number>();
|
|
19
|
+
chain.forEach((sha, i) => {
|
|
20
|
+
if (!position.has(sha)) position.set(sha, i);
|
|
21
|
+
});
|
|
22
|
+
const keyed = ranges.map((range, order) => {
|
|
23
|
+
const at = position.get(range.to);
|
|
24
|
+
if (at === undefined) throw new Error(`range ${range.taskId}: commit ${range.to} is not in the phase chain`);
|
|
25
|
+
return { range, at, order };
|
|
26
|
+
});
|
|
27
|
+
keyed.sort((a, b) => a.at - b.at || a.order - b.order);
|
|
28
|
+
return keyed.map(k => ({ taskId: k.range.taskId, from: k.range.from, to: k.range.to }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Upper bound of real probes `bisectRanges` runs for `n` ranges: ceil(log2 n) + 2. */
|
|
32
|
+
export function maxRangeProbes(n: number): number {
|
|
33
|
+
return (n <= 1 ? 0 : Math.ceil(Math.log2(n))) + 2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `ordered` is oldest first (see `orderRanges`). `suiteCommit` is the commit the suite failed at, so it is
|
|
38
|
+
* known to fail; `known` holds verdicts already observed (they cost no probe). `probe(commit)` runs only the
|
|
39
|
+
* failing ids at `commit`.
|
|
40
|
+
*/
|
|
41
|
+
export async function bisectRanges(ordered: readonly TaskRange[], suiteCommit: string,
|
|
42
|
+
probe: (commit: string) => Promise<ProbeVerdict>, known?: ReadonlyMap<string, ProbeVerdict>): Promise<RangeBisectResult> {
|
|
43
|
+
const seen = new Map<string, ProbeVerdict>(known ?? []);
|
|
44
|
+
if (!seen.has(suiteCommit)) seen.set(suiteCommit, "fail");
|
|
45
|
+
let probes = 0;
|
|
46
|
+
const verdictAt = async (commit: string): Promise<ProbeVerdict> => {
|
|
47
|
+
const cached = seen.get(commit);
|
|
48
|
+
if (cached !== undefined) return cached;
|
|
49
|
+
probes++;
|
|
50
|
+
const v = await probe(commit);
|
|
51
|
+
seen.set(commit, v);
|
|
52
|
+
return v;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const n = ordered.length;
|
|
56
|
+
if (n === 0) return { kind: "outside", reason: "last-passes", probes };
|
|
57
|
+
|
|
58
|
+
if (await verdictAt(ordered[n - 1]!.to) === "pass") return { kind: "outside", reason: "last-passes", probes };
|
|
59
|
+
|
|
60
|
+
// Lower bound: the first index whose `to` fails. `hi` always fails.
|
|
61
|
+
let lo = 0;
|
|
62
|
+
let hi = n - 1;
|
|
63
|
+
while (lo < hi) {
|
|
64
|
+
const mid = (lo + hi) >> 1;
|
|
65
|
+
if (await verdictAt(ordered[mid]!.to) === "fail") hi = mid;
|
|
66
|
+
else lo = mid + 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const range = ordered[lo]!;
|
|
70
|
+
// Boundary: the culprit's `from` must pass. When it is the previous observed `to` the cache answers.
|
|
71
|
+
if (await verdictAt(range.from) === "fail") return { kind: "outside", reason: "from-fails", probes };
|
|
72
|
+
return { kind: "culprit", index: lo, range: { taskId: range.taskId, from: range.from, to: range.to }, probes };
|
|
73
|
+
}
|