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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** One filename policy for read approval, grep filtering and Git exclusions.
|
|
2
|
+
* Patterns are relative suffixes, matched at any depth (not a content scanner). */
|
|
3
|
+
const SSH_KEY_NAMES = ["id_rsa", "id_ed25519", "id_ecdsa", "id_dsa"] as const;
|
|
4
|
+
export const SENSITIVE_PATH_PATTERNS = [
|
|
5
|
+
"*.env", "*.env.*", "*.pem", "*.key", "*.p12", "*.pfx", "*.kdbx",
|
|
6
|
+
...SSH_KEY_NAMES.flatMap(name => [name, `${name}.*`]),
|
|
7
|
+
".npmrc", ".netrc", ".pgpass", ".git-credentials", "credentials.json",
|
|
8
|
+
".aws/credentials", ".docker/config.json",
|
|
9
|
+
".envrc", "*.ppk", "*.jks", "*.keystore", ".kube/config", "*.tfvars", "*.tfstate",
|
|
10
|
+
".pypirc", ".vault-token", ".cargo/credentials*", ".config/gh/hosts.yml", "application_default_credentials.json",
|
|
11
|
+
] as const;
|
|
12
|
+
// Public SSH keys are intentionally readable; backups/extensions other than
|
|
13
|
+
// exactly .pub remain sensitive. Helpers like id_rsa_helpers are not key names.
|
|
14
|
+
export const SENSITIVE_PATH_EXCEPTIONS = ["*.env.example", ...SSH_KEY_NAMES.map(name => `${name}.pub`)] as const;
|
|
15
|
+
const escape = (text: string) => text.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*");
|
|
16
|
+
|
|
17
|
+
export function isSensitivePath(path: string, platform: NodeJS.Platform = process.platform): boolean {
|
|
18
|
+
const normalized = path.replaceAll("\\", "/").split("/").filter(part => part !== "." && part !== "").join("/");
|
|
19
|
+
const matches = (pattern: string) => new RegExp(`(?:^|/)${escape(pattern)}$`, platform === "win32" ? "i" : "").test(normalized);
|
|
20
|
+
return !SENSITIVE_PATH_EXCEPTIONS.some(matches) && SENSITIVE_PATH_PATTERNS.some(matches);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Host wildcard '*' spans separators; include basename, slash and backslash
|
|
24
|
+
// forms for v1 too. V2 normalizes separators and folds case on Windows itself.
|
|
25
|
+
const hostGlobs = (pattern: string) => [...new Set([pattern, pattern.replaceAll("/", "\\"), `*/${pattern}`, `*\\${pattern.replaceAll("/", "\\")}`])];
|
|
26
|
+
export const SENSITIVE_PERMISSION_GLOBS = SENSITIVE_PATH_PATTERNS.flatMap(hostGlobs);
|
|
27
|
+
export const SENSITIVE_PERMISSION_EXCEPTIONS = SENSITIVE_PATH_EXCEPTIONS.flatMap(hostGlobs);
|
|
28
|
+
|
|
29
|
+
/** Expand prefix* minus prefix+suffix: Git cannot re-include an excluded file. */
|
|
30
|
+
function exceptSuffix(prefix: string, suffix: string): string[] {
|
|
31
|
+
return [prefix, ...[...suffix].flatMap((char, i) => {
|
|
32
|
+
const start = `${prefix}${suffix.slice(0, i)}`;
|
|
33
|
+
return [`${start}[!${char}]*`, ...(i > 0 ? [start] : [])];
|
|
34
|
+
}), `${prefix}${suffix}?*`];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Preserve env examples and public SSH keys without re-including private files. */
|
|
38
|
+
export function sensitiveGitPathspecs(platform: NodeJS.Platform = process.platform): string[] {
|
|
39
|
+
return SENSITIVE_PATH_PATTERNS.flatMap(pattern => {
|
|
40
|
+
const exception = SENSITIVE_PATH_EXCEPTIONS.find(value => pattern.endsWith("*") && value.startsWith(pattern.slice(0, -1)));
|
|
41
|
+
return exception ? exceptSuffix(pattern.slice(0, -1), exception.slice(pattern.length - 1)) : [pattern];
|
|
42
|
+
})
|
|
43
|
+
.map(pattern => `:(exclude,glob${platform === "win32" ? ",icase" : ""})**/${pattern}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Native v1/v2 grep's grouped `path:\n Line N: text` format. Drop entire
|
|
47
|
+
* sensitive blocks, including continuations, rather than editing match text. */
|
|
48
|
+
export function filterSensitiveGrep(text: string): string {
|
|
49
|
+
let blocked = false;
|
|
50
|
+
let withheld = 0;
|
|
51
|
+
const kept: string[] = [];
|
|
52
|
+
for (const line of text.split(/\r?\n/)) {
|
|
53
|
+
if (line.startsWith("(Results are truncated")) { kept.push(line); continue; }
|
|
54
|
+
const header = /^(\S.*):$/.exec(line);
|
|
55
|
+
if (header) blocked = isSensitivePath(header[1]!);
|
|
56
|
+
if (blocked) {
|
|
57
|
+
if (/^\s+Line \d+:/.test(line)) withheld++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
kept.push(line);
|
|
61
|
+
}
|
|
62
|
+
if (!withheld) return text;
|
|
63
|
+
return `${kept.join("\n").trimEnd()}\n${withheld} matches in sensitive files withheld; use read (asks for approval)`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Decode Git's C-quoted UTF-8 filenames (including octal bytes). */
|
|
67
|
+
function gitPath(value: string): string {
|
|
68
|
+
if (!value.startsWith('"')) return value;
|
|
69
|
+
const bytes: number[] = [];
|
|
70
|
+
const body = value.slice(1, -1);
|
|
71
|
+
for (let i = 0; i < body.length;) {
|
|
72
|
+
const octal = /^\\([0-7]{1,3})/.exec(body.slice(i));
|
|
73
|
+
if (octal) { bytes.push(parseInt(octal[1]!, 8)); i += octal[0].length; continue; }
|
|
74
|
+
if (body[i] === "\\") {
|
|
75
|
+
const next = body[i + 1] ?? "";
|
|
76
|
+
const escaped: Record<string, string> = { t: "\t", n: "\n", r: "\r", b: "\b", f: "\f", v: "\v", a: "\x07" };
|
|
77
|
+
bytes.push(...Buffer.from(escaped[next] ?? next)); i += 2; continue;
|
|
78
|
+
}
|
|
79
|
+
const char = String.fromCodePoint(body.codePointAt(i)!);
|
|
80
|
+
bytes.push(...Buffer.from(char)); i += char.length;
|
|
81
|
+
}
|
|
82
|
+
return Buffer.from(bytes).toString("utf8");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Backstop for rename/quoted-path diffs, including sections cut by the output
|
|
86
|
+
* bound. Fixed a/b prefixes are imposed by the Git argv builder. */
|
|
87
|
+
export function filterSensitiveDiff(text: string): string {
|
|
88
|
+
return text.split(/(?=^diff --(?:git|cc|combined) |^commit [0-9a-f]{40,64}(?:\s|$))/m).map(section => {
|
|
89
|
+
if (!/^diff --(?:git|cc|combined) /.test(section)) return section;
|
|
90
|
+
const header = section.split("\n", 1)[0]!;
|
|
91
|
+
const paths: string[] = [];
|
|
92
|
+
if (header.startsWith("diff --git ")) {
|
|
93
|
+
const pair = /^("(?:\\.|[^"\\])*"|a\/.*?) ("(?:\\.|[^"\\])*"|b\/.*)$/.exec(header.slice(11));
|
|
94
|
+
if (!pair) return "[router_git] unparseable diff section withheld; use read (asks for approval)\n";
|
|
95
|
+
paths.push(gitPath(pair[1]!).slice(2), gitPath(pair[2]!).slice(2));
|
|
96
|
+
} else paths.push(gitPath(header.replace(/^diff --(?:cc|combined) /, "")));
|
|
97
|
+
for (const match of section.matchAll(/^(?:rename|copy) (?:from|to) (.*)$/gm)) paths.push(gitPath(match[1]!));
|
|
98
|
+
return paths.some(path => isSensitivePath(path))
|
|
99
|
+
? "[router_git] sensitive diff section withheld; use read (asks for approval)\n" : section;
|
|
100
|
+
}).join("");
|
|
101
|
+
}
|