opencode-model-router 1.13.0 → 1.15.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 +154 -0
- package/README.md +3 -3
- package/package.json +2 -1
- package/src/index.ts +377 -58
- package/src/router/config.ts +211 -12
- package/src/router/protocol.ts +11 -2
- package/src/verify/baseline.ts +143 -25
- package/src/verify/batch.ts +2226 -0
- package/src/verify/deterministic.ts +1378 -20
- package/src/verify/directives.ts +207 -0
- package/src/verify/dispatch.ts +387 -86
- package/src/verify/exec.ts +711 -0
- package/src/verify/pending.ts +1834 -0
- package/src/verify/reference.ts +2117 -0
- package/src/verify/risk.ts +271 -0
- package/src/verify/runner.ts +5315 -0
- package/src/verify/slot.ts +1603 -0
- package/src/verify/tree.ts +215 -11
- package/src/verify/types.ts +301 -4
- package/src/verify/wiring.ts +1884 -73
- package/tiers.json +8 -8
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic risk signal for deferred delegations (plan §1.5-17, Phase 1.6.2).
|
|
3
|
+
*
|
|
4
|
+
* Pure and synchronous: no process, no fs, no network. The caller runs the static planner
|
|
5
|
+
* (`planStaticScoping`) and passes its result in as `scopingPlan`.
|
|
6
|
+
*
|
|
7
|
+
* Paths: classification is done on repo-relative paths (QA-1.6-9). Pass the git root as `root`;
|
|
8
|
+
* absolute paths under it are made relative (after `\` → `/`, case-insensitively for drive-letter
|
|
9
|
+
* roots). CONTRACT (QA-1.6-22): `root` must be the git top-level the paths were resolved against
|
|
10
|
+
* (`git rev-parse --show-toplevel`, real path, as tree.ts uses) — never the delegation cwd: a
|
|
11
|
+
* subdirectory root strips inner segments such as `tests/` and can under-rate. Exposing the
|
|
12
|
+
* top-level on `TreeSnapshot` and passing it here is deferred to 2.1/2.4. An absolute path that cannot be made relative is classified conservatively: it never
|
|
13
|
+
* counts as documentation. Paths are deduplicated (normalised, case-folded for drive-letter paths)
|
|
14
|
+
* before counting (QA-1.6-15).
|
|
15
|
+
*
|
|
16
|
+
* Status: two-character porcelain XY codes count as deleted/renamed when D/R appears in EITHER
|
|
17
|
+
* column (`MD`, `AD`, ` D`, `RM`); other forms (`D`, `deleted`, `R100`) match on the first letter.
|
|
18
|
+
*
|
|
19
|
+
* Callers must not pass `[]` when attribution failed (e.g. `snapshotTree` returned undefined):
|
|
20
|
+
* `[]` means "nothing changed" and is rated low (QA-1.6-14; the unknown case is 2.4's).
|
|
21
|
+
*
|
|
22
|
+
* Fixed table (evaluated in this order; the level is the maximum of every matching row, then the
|
|
23
|
+
* adjustment rows apply once):
|
|
24
|
+
*
|
|
25
|
+
* | # | Condition | Level / effect |
|
|
26
|
+
* |----|-------------------------------------------------------------------|------------------------|
|
|
27
|
+
* | 1 | no changed files | low, stop |
|
|
28
|
+
* | 2 | every changed file is documentation (see isDocPath) | low, stop |
|
|
29
|
+
* | 3 | 1–5 changed files | low |
|
|
30
|
+
* | 4 | 6–15 changed files | medium |
|
|
31
|
+
* | 5 | 16 or more changed files | high |
|
|
32
|
+
* | 6 | a test file was deleted, or renamed to a non-test path | high |
|
|
33
|
+
* | 7 | a test file (incl. snapshots) was modified (added, changed, renamed) | medium |
|
|
34
|
+
* | 8 | a non-test file was deleted or any file was renamed | medium |
|
|
35
|
+
* | 9 | config / lock / CI / test-setup file changed (see isConfigPath) | medium |
|
|
36
|
+
* | 10 | scoping impossible (Unverifiable, S6) | medium |
|
|
37
|
+
* | 11 | producer tier "fast" | medium |
|
|
38
|
+
* | 12 | no reference captured | +1 step (max high) |
|
|
39
|
+
*
|
|
40
|
+
* Documentation (row 2): not a test or config path, and either a `.md/.mdx/.rst/.adoc` file
|
|
41
|
+
* anywhere, `LICENSE.txt`/`CHANGELOG.txt`, or a doc/asset file type
|
|
42
|
+
* (`md mdx rst txt adoc png jpg jpeg gif svg webp`) under a `docs/` directory.
|
|
43
|
+
*
|
|
44
|
+
* Rows 1–2 short-circuit: nothing else is evaluated. A `NoAffected` scoping plan adds the
|
|
45
|
+
* informational reason REASONS.noAffected without changing the level. Reasons are stable strings
|
|
46
|
+
* (they are shown to the orchestrator) and appear in table order.
|
|
47
|
+
*/
|
|
48
|
+
import type { ChangedPath, StaticScoping } from "./runner";
|
|
49
|
+
|
|
50
|
+
export type RiskLevel = "low" | "medium" | "high";
|
|
51
|
+
export type ProducerTier = "fast" | "medium" | "heavy" | (string & {});
|
|
52
|
+
|
|
53
|
+
export interface RiskInput {
|
|
54
|
+
readonly changedFiles: readonly ChangedPath[];
|
|
55
|
+
/** Whether a reference (baseline) exists for this delegation. Only presence matters. */
|
|
56
|
+
readonly reference: boolean;
|
|
57
|
+
readonly producerTier: ProducerTier;
|
|
58
|
+
readonly scopingPlan: StaticScoping;
|
|
59
|
+
/** Git root; absolute changed paths are made relative to it before classification. */
|
|
60
|
+
readonly root?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RiskAssessment {
|
|
64
|
+
readonly level: RiskLevel;
|
|
65
|
+
readonly reasons: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const SMALL_CHANGE_MAX = 5;
|
|
69
|
+
export const MEDIUM_CHANGE_MAX = 15;
|
|
70
|
+
|
|
71
|
+
export const REASONS = {
|
|
72
|
+
empty: "no changes attributed",
|
|
73
|
+
docsOnly: "documentation-only change",
|
|
74
|
+
small: "1-5 files changed",
|
|
75
|
+
mediumCount: "6-15 files changed",
|
|
76
|
+
largeCount: "16 or more files changed",
|
|
77
|
+
testDeleted: "a test file was deleted",
|
|
78
|
+
testModified: "a test file was modified",
|
|
79
|
+
deletedOrRenamed: "files were deleted or renamed",
|
|
80
|
+
configChanged: "config, lock or CI files changed",
|
|
81
|
+
unverifiable: "scoping impossible (S6): the change cannot be verified by scoped tests",
|
|
82
|
+
noAffected: "no affected tests found by static scoping",
|
|
83
|
+
fastTier: "produced by the fast tier",
|
|
84
|
+
noReference: "no reference captured: risk raised one step",
|
|
85
|
+
} as const;
|
|
86
|
+
|
|
87
|
+
const ORDER: readonly RiskLevel[] = ["low", "medium", "high"];
|
|
88
|
+
|
|
89
|
+
function norm(p: string): string {
|
|
90
|
+
return p.replace(/\\/g, "/");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function base(p: string): string {
|
|
94
|
+
const n = norm(p);
|
|
95
|
+
return n.slice(n.lastIndexOf("/") + 1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const DRIVE = /^[a-z]:\//i;
|
|
99
|
+
|
|
100
|
+
function isAbsolute(n: string): boolean {
|
|
101
|
+
return n.startsWith("/") || DRIVE.test(n);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Repo-relative form, or null when the path is absolute and not under `root`. */
|
|
105
|
+
function relativize(p: string, root: string | undefined): string | null {
|
|
106
|
+
const n = norm(p).replace(/^(\.\/)+/, "");
|
|
107
|
+
if (!isAbsolute(n)) return n;
|
|
108
|
+
if (root === undefined) return null;
|
|
109
|
+
let r = norm(root);
|
|
110
|
+
while (r.endsWith("/")) r = r.slice(0, -1); // linear trim (QA-1.6-32)
|
|
111
|
+
const fold = DRIVE.test(r);
|
|
112
|
+
const nc = fold ? n.toLowerCase() : n;
|
|
113
|
+
const rc = fold ? r.toLowerCase() : r;
|
|
114
|
+
return nc.startsWith(`${rc}/`) ? n.slice(r.length + 1) : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const DOC_ANYWHERE = /\.(md|mdx|rst|adoc)$/i;
|
|
118
|
+
const DOC_UNDER_DOCS = /\.(md|mdx|rst|txt|adoc|png|jpe?g|gif|svg|webp)$/i;
|
|
119
|
+
|
|
120
|
+
export function isDocPath(p: string): boolean {
|
|
121
|
+
const n = norm(p);
|
|
122
|
+
if (isTestPath(n) || isConfigPath(n)) return false;
|
|
123
|
+
const b = base(n);
|
|
124
|
+
return (
|
|
125
|
+
DOC_ANYWHERE.test(b) ||
|
|
126
|
+
/^(LICENSE|CHANGELOG)\.txt$/i.test(b) ||
|
|
127
|
+
(/(^|\/)docs\//i.test(n) && DOC_UNDER_DOCS.test(b))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function isTestPath(p: string): boolean {
|
|
132
|
+
const n = norm(p);
|
|
133
|
+
const b = base(n);
|
|
134
|
+
return (
|
|
135
|
+
/(^|\/)(test|tests|__tests__|__snapshots__)\//.test(n) ||
|
|
136
|
+
/\.snap$/.test(b) ||
|
|
137
|
+
/\.(test|spec)\.[cm]?[jt]sx?$/.test(b) ||
|
|
138
|
+
/^test_.*\.py$/.test(b) ||
|
|
139
|
+
/_test\.py$/.test(b)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Test-setup files (QA-1.6-21, adjustment to the §1.5-17 extension): `*.setup.<js/ts>` or the
|
|
145
|
+
* conventional basenames below. Both alternatives are anchored and linear-time; generic
|
|
146
|
+
* `*setup*` names (`src/setup.ts`, `SetupWizard.tsx`) are application code, not config.
|
|
147
|
+
*/
|
|
148
|
+
const SETUP_FILE =
|
|
149
|
+
/\.setup\.[cm]?[jt]sx?$|^(setupTests|setup-tests|test-setup|global-setup|globalSetup|vitest\.setup|jest\.setup|setup-jest|jest-setup|vitest-setup|global-teardown|globalTeardown|setupVitest|setup-vitest|testSetup)\.[cm]?[jt]sx?$/i; // QA-1.6-36
|
|
150
|
+
|
|
151
|
+
export function isConfigPath(p: string): boolean {
|
|
152
|
+
const n = norm(p);
|
|
153
|
+
const b = base(n);
|
|
154
|
+
return (
|
|
155
|
+
/(^|\/)\.github\//.test(n) ||
|
|
156
|
+
b === "package.json" ||
|
|
157
|
+
b === "package-lock.json" ||
|
|
158
|
+
b === "npm-shrinkwrap.json" ||
|
|
159
|
+
b === "yarn.lock" ||
|
|
160
|
+
b === "pnpm-lock.yaml" ||
|
|
161
|
+
b === "bun.lockb" ||
|
|
162
|
+
b === "bun.lock" ||
|
|
163
|
+
b === "poetry.lock" ||
|
|
164
|
+
b === "uv.lock" ||
|
|
165
|
+
b === "Pipfile.lock" ||
|
|
166
|
+
b === "Pipfile" ||
|
|
167
|
+
/^tsconfig.*\.json$/.test(b) ||
|
|
168
|
+
/^(vite|vitest|jest)\.config\./.test(b) ||
|
|
169
|
+
/^playwright\.config\./.test(b) ||
|
|
170
|
+
/^vitest\.workspace\./.test(b) ||
|
|
171
|
+
SETUP_FILE.test(b) ||
|
|
172
|
+
b === "conftest.py" ||
|
|
173
|
+
b === "pyproject.toml" ||
|
|
174
|
+
b === "pytest.ini" ||
|
|
175
|
+
b === "tox.ini" ||
|
|
176
|
+
b === "setup.cfg" ||
|
|
177
|
+
b === "setup.py" ||
|
|
178
|
+
b === ".gitlab-ci.yml" ||
|
|
179
|
+
b === "Makefile" ||
|
|
180
|
+
b === "CMakeLists.txt" ||
|
|
181
|
+
/^(requirements|constraints).*\.txt$/.test(b) ||
|
|
182
|
+
/^requirements.*\.in$/.test(b) || // pip-tools sources (QA-1.6-31)
|
|
183
|
+
/(^|\/)requirements\/[^/]*\.(txt|in)$/i.test(n) // any-case folder, .in sources (QA-1.6-36)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const PORCELAIN = /^[ .MTADRCU?!]{2}$/;
|
|
188
|
+
|
|
189
|
+
function statusHas(status: string | undefined, letter: "D" | "R"): boolean {
|
|
190
|
+
if (status === undefined) return false;
|
|
191
|
+
if (PORCELAIN.test(status)) return status.includes(letter);
|
|
192
|
+
return status.trim().charAt(0).toUpperCase() === letter;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface Classified {
|
|
196
|
+
readonly path: string | null;
|
|
197
|
+
readonly previousPath: string | null | undefined;
|
|
198
|
+
readonly deleted: boolean;
|
|
199
|
+
readonly renamed: boolean;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function assessRisk(input: RiskInput): RiskAssessment {
|
|
203
|
+
const { changedFiles, reference, producerTier, scopingPlan, root } = input;
|
|
204
|
+
|
|
205
|
+
if (changedFiles.length === 0) return { level: "low", reasons: [REASONS.empty] };
|
|
206
|
+
|
|
207
|
+
const files: Classified[] = changedFiles.map((f) => ({
|
|
208
|
+
path: relativize(f.path, root),
|
|
209
|
+
previousPath: f.previousPath === undefined ? undefined : relativize(f.previousPath, root),
|
|
210
|
+
deleted: statusHas(f.status, "D"),
|
|
211
|
+
renamed: f.previousPath !== undefined || statusHas(f.status, "R"),
|
|
212
|
+
}));
|
|
213
|
+
// Unresolvable absolute paths fall back to their full normalised form (conservative: may
|
|
214
|
+
// over-match test/config patterns, never counts as documentation).
|
|
215
|
+
const cls = (rel: string | null, raw: string): string => rel ?? norm(raw);
|
|
216
|
+
const doc = (rel: string | null | undefined): boolean => rel === undefined || (rel !== null && isDocPath(rel));
|
|
217
|
+
|
|
218
|
+
if (files.every((f) => doc(f.path) && doc(f.previousPath))) {
|
|
219
|
+
return { level: "low", reasons: [REASONS.docsOnly] };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let idx = 0;
|
|
223
|
+
const reasons: string[] = [];
|
|
224
|
+
const hit = (level: RiskLevel, reason: string): void => {
|
|
225
|
+
idx = Math.max(idx, ORDER.indexOf(level));
|
|
226
|
+
reasons.push(reason);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const keys = new Set(
|
|
230
|
+
changedFiles.map((f, i) => {
|
|
231
|
+
const k = cls(files[i]!.path, f.path);
|
|
232
|
+
return DRIVE.test(norm(f.path)) || (root !== undefined && DRIVE.test(norm(root))) ? k.toLowerCase() : k;
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
const n = keys.size;
|
|
236
|
+
if (n <= SMALL_CHANGE_MAX) hit("low", REASONS.small);
|
|
237
|
+
else if (n <= MEDIUM_CHANGE_MAX) hit("medium", REASONS.mediumCount);
|
|
238
|
+
else hit("high", REASONS.largeCount);
|
|
239
|
+
|
|
240
|
+
const paths = changedFiles.map((f, i) => {
|
|
241
|
+
const c = files[i]!;
|
|
242
|
+
const prev = f.previousPath === undefined ? undefined : cls(c.previousPath ?? null, f.previousPath);
|
|
243
|
+
return { ...c, cur: cls(c.path, f.path), prev };
|
|
244
|
+
});
|
|
245
|
+
const touchesTest = (f: (typeof paths)[number]): boolean =>
|
|
246
|
+
isTestPath(f.cur) || (f.prev !== undefined && isTestPath(f.prev));
|
|
247
|
+
const testGone = (f: (typeof paths)[number]): boolean =>
|
|
248
|
+
(f.deleted && touchesTest(f)) || (f.prev !== undefined && isTestPath(f.prev) && !isTestPath(f.cur));
|
|
249
|
+
|
|
250
|
+
if (paths.some(testGone)) hit("high", REASONS.testDeleted);
|
|
251
|
+
else if (paths.some(touchesTest)) hit("medium", REASONS.testModified);
|
|
252
|
+
|
|
253
|
+
if (paths.some((f) => (f.deleted && !touchesTest(f)) || f.renamed)) {
|
|
254
|
+
hit("medium", REASONS.deletedOrRenamed);
|
|
255
|
+
}
|
|
256
|
+
if (paths.some((f) => isConfigPath(f.cur) || (f.prev !== undefined && isConfigPath(f.prev)))) {
|
|
257
|
+
hit("medium", REASONS.configChanged);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if ("unverifiable" in scopingPlan && scopingPlan.unverifiable === true) hit("medium", REASONS.unverifiable);
|
|
261
|
+
else if ("noAffected" in scopingPlan && scopingPlan.noAffected === true) reasons.push(REASONS.noAffected);
|
|
262
|
+
|
|
263
|
+
if (producerTier === "fast") hit("medium", REASONS.fastTier);
|
|
264
|
+
|
|
265
|
+
if (!reference) {
|
|
266
|
+
idx = Math.min(idx + 1, ORDER.length - 1);
|
|
267
|
+
reasons.push(REASONS.noReference);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return { level: ORDER[idx] ?? "high", reasons };
|
|
271
|
+
}
|