opencode-model-router 2.8.0 → 2.9.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +364 -0
  2. package/README.md +20 -0
  3. package/package.json +5 -1
  4. package/src/commands/output.ts +23 -1
  5. package/src/compat/background.ts +2439 -0
  6. package/src/compat/child-session.ts +6 -0
  7. package/src/compat/turn-state.ts +215 -0
  8. package/src/compat/v2-client.ts +136 -17
  9. package/src/compat/v2-hooks.ts +2656 -114
  10. package/src/compat/v2-observations.ts +328 -0
  11. package/src/executor/capacity.ts +362 -0
  12. package/src/executor/child-guards.ts +40 -0
  13. package/src/executor/command.ts +265 -0
  14. package/src/executor/compile/edges.ts +809 -0
  15. package/src/executor/compile/estimate.ts +158 -0
  16. package/src/executor/compile/footprint.ts +829 -0
  17. package/src/executor/compile/index.ts +1080 -0
  18. package/src/executor/compile/parse.ts +1492 -0
  19. package/src/executor/compile/residue.ts +706 -0
  20. package/src/executor/compile/validate.ts +280 -0
  21. package/src/executor/create.ts +672 -0
  22. package/src/executor/expand.ts +551 -0
  23. package/src/executor/git.ts +1214 -0
  24. package/src/executor/host-preamble.ts +17 -0
  25. package/src/executor/instructions.ts +35 -0
  26. package/src/executor/integrate/bisect.ts +73 -0
  27. package/src/executor/integrate/checks.ts +1086 -0
  28. package/src/executor/integrate/land.ts +177 -0
  29. package/src/executor/integrate/phase-suite.ts +407 -0
  30. package/src/executor/integrate/queue.ts +3083 -0
  31. package/src/executor/integrate/run-resolver.ts +19 -0
  32. package/src/executor/launch.ts +652 -0
  33. package/src/executor/ledger.ts +2208 -0
  34. package/src/executor/observations.ts +212 -0
  35. package/src/executor/paths.ts +159 -0
  36. package/src/executor/platform.ts +39 -0
  37. package/src/executor/process-identity.ts +19 -0
  38. package/src/executor/qa-loop.ts +470 -0
  39. package/src/executor/recovery.ts +403 -0
  40. package/src/executor/runtime.ts +6233 -0
  41. package/src/executor/schedule.ts +246 -0
  42. package/src/executor/slots/env.ts +145 -0
  43. package/src/executor/slots/pool.ts +1564 -0
  44. package/src/executor/slots/provision.ts +853 -0
  45. package/src/executor/tool.ts +534 -0
  46. package/src/executor/types.ts +2064 -0
  47. package/src/executor/unattended.ts +488 -0
  48. package/src/guard/store.ts +3 -1
  49. package/src/index.ts +1498 -288
  50. package/src/router/config.ts +776 -25
  51. package/src/router/git-tools.ts +106 -15
  52. package/src/router/leases.ts +1469 -0
  53. package/src/router/logger.ts +44 -32
  54. package/src/router/protocol.ts +40 -10
  55. package/src/router/role-agents.ts +224 -17
  56. package/src/router/roles-config.ts +10 -1
  57. package/src/router/roles.ts +1 -1
  58. package/src/router/run-tools.ts +56 -4
  59. package/src/router/tool-paths.ts +308 -0
  60. package/src/router/work-roots.ts +86 -0
  61. package/src/routing/advisor/findings.ts +25 -5
  62. package/src/routing/classify/index.ts +7 -1
  63. package/src/routing/classify/rules.ts +11 -0
  64. package/src/routing/commands/stats.ts +2 -2
  65. package/src/routing/outcomes/durations.ts +225 -0
  66. package/src/routing/outcomes/index.ts +59 -2
  67. package/src/routing/outcomes/persist.ts +409 -0
  68. package/src/routing/outcomes/stats.ts +170 -11
  69. package/src/routing/outcomes/timings.ts +836 -0
  70. package/src/routing/outcomes/types.ts +98 -0
  71. package/src/routing/roles/approvals.ts +86 -5
  72. package/src/routing/roles/binding.ts +99 -9
  73. package/src/routing/roles/orphans.ts +68 -0
  74. package/src/routing/roles/policy.ts +21 -3
  75. package/src/routing/roles/work-root.ts +3 -1
  76. package/src/routing/wire/dispatch.ts +86 -12
  77. package/src/routing/wire/hint.ts +56 -8
  78. package/src/v2.ts +94 -49
  79. package/src/verify/branch.ts +8 -2
  80. package/src/verify/canonical-path.ts +35 -0
  81. package/src/verify/deterministic.ts +38 -9
  82. package/src/verify/dispatch.ts +64 -28
  83. package/src/verify/exec.ts +52 -9
  84. package/src/verify/pending.ts +1691 -10
  85. package/src/verify/perimeter.ts +12 -6
  86. package/src/verify/plan-task.ts +729 -0
  87. package/src/verify/reference.ts +216 -3
  88. package/src/verify/tree.ts +30 -13
  89. package/src/verify/types.ts +9 -2
  90. package/src/verify/wiring.ts +290 -31
@@ -0,0 +1,158 @@
1
+ import type { DurationModel } from "../../routing/outcomes/durations";
2
+ import type { RouteLine } from "../../routing/classify/types";
3
+ import type { CompileSummary, Edge, LedgerV1, TaskKind, TaskNode, TaskState, Tier } from "../types";
4
+
5
+ /** Prior for one integration until 3.2 records integration timings (memo §8). */
6
+ export const INTEGRATION_ESTIMATE_MS = 60_000;
7
+
8
+ const NOT_LAUNCHABLE_KINDS: ReadonlySet<TaskKind> = new Set<TaskKind>(["manual", "preflight"]);
9
+ const FINISHED_STATES: ReadonlySet<TaskState> = new Set<TaskState>(["done", "cancelled", "integrated"]);
10
+
11
+ export interface TaskEstimateInput {
12
+ kind: TaskKind;
13
+ state: TaskState;
14
+ role: string;
15
+ tier: Tier | null;
16
+ route: RouteLine | null;
17
+ }
18
+
19
+ /** Per-task estimate (memo §8): manual/preflight and finished tasks cost 0, the rest come from the duration model. */
20
+ export function taskEstimate(m: DurationModel, t: TaskEstimateInput): TaskNode["estimate"] {
21
+ if (NOT_LAUNCHABLE_KINDS.has(t.kind)) return { p50: 0, p90: 0, source: "manual" };
22
+ if (t.state === "done") return { p50: 0, p90: 0, source: "done: merged before the run" };
23
+ const e = m.estimate({
24
+ role: t.role !== "" ? t.role : (t.tier ?? "unknown"),
25
+ class: t.route?.class ?? "other",
26
+ scope: t.route?.scope ?? "single",
27
+ });
28
+ const p50 = Math.max(0, e.p50);
29
+ const p90 = Math.max(p50, e.p90);
30
+ const source = e.p90Source === e.source ? e.source : `${e.source}/p90:${e.p90Source}`;
31
+ return { p50, p90, source };
32
+ }
33
+
34
+ function isLaunchable(t: TaskNode): boolean {
35
+ return !NOT_LAUNCHABLE_KINDS.has(t.kind) && !FINISHED_STATES.has(t.state);
36
+ }
37
+
38
+ /** W, CP, width and expected makespan over the ledger graph (tasks plus phase gates, memo §8). */
39
+ export function planEstimate(
40
+ l: Pick<LedgerV1, "tasks" | "edges" | "phases">,
41
+ maxParallel: number,
42
+ ): Pick<CompileSummary, "workMs" | "criticalPathMs" | "width" | "expectedMakespanMs"> {
43
+ const ids: string[] = [];
44
+ const index = new Map<string, number>();
45
+ const cost: number[] = [];
46
+ const launchable: boolean[] = [];
47
+ const addNode = (id: string, c: number, lau: boolean): void => {
48
+ index.set(id, ids.length);
49
+ ids.push(id);
50
+ cost.push(c);
51
+ launchable.push(lau);
52
+ };
53
+ for (const t of Object.values(l.tasks)) {
54
+ const lau = isLaunchable(t);
55
+ addNode(t.id, lau ? t.estimate.p50 : 0, lau);
56
+ }
57
+ for (const p of l.phases) addNode(`gate:${p.id}`, 0, false);
58
+
59
+ const n = ids.length;
60
+ const succ: number[][] = Array.from({ length: n }, () => []);
61
+ const indeg: number[] = new Array<number>(n).fill(0);
62
+ const seen = new Set<string>();
63
+ const link = (from: string, to: string): void => {
64
+ const a = index.get(from);
65
+ const b = index.get(to);
66
+ if (a === undefined || b === undefined || a === b) return;
67
+ const key = `${a}>${b}`;
68
+ if (seen.has(key)) return;
69
+ seen.add(key);
70
+ succ[a]?.push(b);
71
+ indeg[b] = (indeg[b] ?? 0) + 1;
72
+ };
73
+ for (const e of l.edges as readonly Edge[]) link(e.from, e.to);
74
+ for (const t of Object.values(l.tasks)) {
75
+ if (t.phase !== null) link(t.id, `gate:${t.phase}`);
76
+ }
77
+
78
+ // Kahn order; nodes left over by a cycle keep es = 0 (validate reports cycles, the estimate stays total).
79
+ const order: number[] = [];
80
+ const queue: number[] = [];
81
+ for (let i = 0; i < n; i += 1) if ((indeg[i] ?? 0) === 0) queue.push(i);
82
+ for (let h = 0; h < queue.length; h += 1) {
83
+ const v = queue[h] as number;
84
+ order.push(v);
85
+ for (const w of succ[v] ?? []) {
86
+ indeg[w] = (indeg[w] ?? 0) - 1;
87
+ if (indeg[w] === 0) queue.push(w);
88
+ }
89
+ }
90
+ const es: number[] = new Array<number>(n).fill(0);
91
+ for (const v of order) {
92
+ const end = (es[v] ?? 0) + (cost[v] ?? 0);
93
+ for (const w of succ[v] ?? []) if (end > (es[w] ?? 0)) es[w] = end;
94
+ }
95
+ const bl: number[] = new Array<number>(n).fill(0);
96
+ let cp = 0;
97
+ for (let k = order.length - 1; k >= 0; k -= 1) {
98
+ const v = order[k] as number;
99
+ let best = 0;
100
+ for (const w of succ[v] ?? []) best = Math.max(best, bl[w] ?? 0);
101
+ bl[v] = (cost[v] ?? 0) + best;
102
+ cp = Math.max(cp, bl[v] ?? 0);
103
+ }
104
+
105
+ let work = 0;
106
+ let count = 0;
107
+ const events: Array<[number, number]> = [];
108
+ for (let i = 0; i < n; i += 1) {
109
+ if (launchable[i] !== true) continue;
110
+ count += 1;
111
+ const c = cost[i] ?? 0;
112
+ work += c;
113
+ if (c > 0) {
114
+ events.push([es[i] ?? 0, 1]);
115
+ events.push([(es[i] ?? 0) + c, -1]);
116
+ }
117
+ }
118
+ events.sort((a, b) => (a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1]));
119
+ let cur = 0;
120
+ let width = 0;
121
+ for (const [, d] of events) {
122
+ cur += d;
123
+ if (cur > width) width = cur;
124
+ }
125
+ if (count > 0 && width === 0) width = 1;
126
+
127
+ const pEff = Math.min(Math.max(1, maxParallel), Math.max(1, width));
128
+ const integration = INTEGRATION_ESTIMATE_MS * count;
129
+ return {
130
+ workMs: Math.round(work),
131
+ criticalPathMs: Math.round(cp),
132
+ width,
133
+ expectedMakespanMs: Math.round(Math.max(cp, work / pEff, integration)),
134
+ };
135
+ }
136
+
137
+ function hours(ms: number): string {
138
+ return `${(ms / 3_600_000).toFixed(1)}h`;
139
+ }
140
+
141
+ /**
142
+ * One-line summary (memo §8). `CompileSummary` carries no plan id or parallelism, so the caller may pass them;
143
+ * `ctx.maxParallel` is the effective p used for the makespan.
144
+ */
145
+ export function formatSummary(s: CompileSummary, ctx: { planId?: string; maxParallel?: number } = {}): string {
146
+ const p = Math.min(Math.max(1, ctx.maxParallel ?? s.width), Math.max(1, s.width));
147
+ return [
148
+ `plan ${ctx.planId ?? "?"}: ${s.tasks} tasks`,
149
+ `${s.phases} phases`,
150
+ `${s.edges} edges`,
151
+ `W ${hours(s.workMs)}`,
152
+ `CP ${hours(s.criticalPathMs)}`,
153
+ `width ${s.width}`,
154
+ `≈${hours(s.expectedMakespanMs)} (p=${p})`,
155
+ `manual ${s.manual.length}`,
156
+ `${s.warnings.length} warnings`,
157
+ ].join(" · ");
158
+ }