opencode-model-router 1.8.0 → 1.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.
- package/CHANGELOG.md +65 -0
- package/README.md +7 -5
- package/package.json +2 -2
- package/src/commands/output.ts +3 -16
- package/src/index.ts +17 -25
- package/src/router/agent-options.ts +22 -2
- package/src/router/catalog.ts +55 -56
- package/src/router/config.ts +21 -13
- package/src/router/logger.ts +122 -0
- package/src/router/prompts.ts +36 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,71 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.9.0] - 2026-08-20
|
|
9
|
+
|
|
10
|
+
Minor release. One real bug — prompt-style resolution broke when a provider renamed a
|
|
11
|
+
model across separators — plus the diagnostics that were compensating for it, which are
|
|
12
|
+
gone now that the cause is fixed.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **`promptStyle: "auto"` survives a provider renaming a model across separators.**
|
|
17
|
+
`isStrongModel` matched patterns case-insensitively but not separator-insensitively, so
|
|
18
|
+
the moment a provider shipped `claude-opus-4.8` where the pattern said `opus-4-8`, the
|
|
19
|
+
tier silently stopped resolving as strong and dropped from `goal-oriented` to
|
|
20
|
+
`prescriptive` — a different system prompt, with nothing said. Matching now normalizes
|
|
21
|
+
case and `.`, `-`, `_` on both sides. The provider boundary is preserved: `/` is not
|
|
22
|
+
normalized, so a pattern cannot match across it. A pattern consisting only of
|
|
23
|
+
separators now matches nothing instead of everything.
|
|
24
|
+
|
|
25
|
+
This is not hypothetical drift. Our own `tiers.json` carries the same model as
|
|
26
|
+
`anthropic/claude-haiku-4-5` and `github-copilot/claude-haiku-4.5`, because each
|
|
27
|
+
provider spells it its own way.
|
|
28
|
+
|
|
29
|
+
- **Passive warnings go to opencode's log instead of the terminal.** `console.warn`
|
|
30
|
+
from a plugin lands on the server's stderr, which the TUI does not own, so a warning
|
|
31
|
+
painted over whatever the terminal was drawing. Stale-model, orphaned-pattern and
|
|
32
|
+
agent-option warnings now post to `POST /log` via `client.app.log` with a
|
|
33
|
+
`model-router` service tag and structured `extra`. Fire-and-forget and fail-soft: a
|
|
34
|
+
server without the endpoint, a rejected post, a post that resolves reporting an error,
|
|
35
|
+
and a synchronous throw all fall back to `console.warn`, so a diagnostic is never
|
|
36
|
+
silently dropped.
|
|
37
|
+
|
|
38
|
+
Config-parse warnings deliberately still use `console.warn`. They are emitted from
|
|
39
|
+
`loadConfig`, which runs before a client exists, and they only fire on a malformed
|
|
40
|
+
override file — a case where being loud is the point.
|
|
41
|
+
|
|
42
|
+
### Removed
|
|
43
|
+
|
|
44
|
+
- **`modelGenerations.claude5x`.** The field was declared, type-validated on load and
|
|
45
|
+
documented in three places, and never read by anything. `isStrongModel` reads
|
|
46
|
+
`strong`, and the default `strong` list was a module-level constant computed once
|
|
47
|
+
from the built-in array, so a user's `claude5x` could not reach it. Setting it did
|
|
48
|
+
nothing, and passing validation implied otherwise. An existing config carrying the key
|
|
49
|
+
still loads — unknown keys under `modelGenerations` are ignored, not rejected.
|
|
50
|
+
|
|
51
|
+
The note that `strong` was "a superset of `claude5x` by construction — every Claude 5.x
|
|
52
|
+
model is a strong model" is gone with it. It had stopped being true in both directions:
|
|
53
|
+
`claude-opus-5` was strong without being in `claude5x`, and `claude-sonnet-5` ships on
|
|
54
|
+
two tiers as a Claude 5 model that is deliberately not strong. `strong` is curated per
|
|
55
|
+
model, and the docs now say so.
|
|
56
|
+
|
|
57
|
+
- **Near-miss detection for orphaned strong-model patterns.** It existed to spot exactly
|
|
58
|
+
the rename the matcher now absorbs, so under the fixed matcher a near miss *is* a match
|
|
59
|
+
and can no longer be an orphan — the code was unreachable. The `/router models` output
|
|
60
|
+
and the passive warning both drop the "served under a different separator" hint. What
|
|
61
|
+
remains is narrower and honest: a pattern **you** wrote in `modelGenerations.strong`
|
|
62
|
+
that matches nothing your providers serve is still reported, because that is a claim
|
|
63
|
+
about your environment that turned out to be wrong. Shipped defaults are never
|
|
64
|
+
reported — most of a cross-provider union is unserved on any given install, and saying
|
|
65
|
+
so is noise you cannot act on.
|
|
66
|
+
|
|
67
|
+
### Changed
|
|
68
|
+
|
|
69
|
+
- **`@opencode-ai/plugin` peer range is now `>=1.0.0 <2.0.0`.** The open-ended `>=1.0.0`
|
|
70
|
+
claimed compatibility with a major version that does not exist yet and whose plugin API
|
|
71
|
+
is by definition unknown.
|
|
72
|
+
|
|
8
73
|
## [1.8.0] - 2026-08-19
|
|
9
74
|
|
|
10
75
|
Minor release: every vendor preset is refreshed to the current generation of models.
|
package/README.md
CHANGED
|
@@ -684,16 +684,18 @@ for that tier name only, and tiers you do not list keep theirs.
|
|
|
684
684
|
|
|
685
685
|
#### `modelGenerations`
|
|
686
686
|
|
|
687
|
-
`modelGenerations` holds
|
|
688
|
-
|
|
687
|
+
`modelGenerations` holds substring patterns matched against a tier's model ID, with case
|
|
688
|
+
and separators (`.`, `-`, `_`) normalized on both sides — so `opus-4-8` matches
|
|
689
|
+
`opus-4.8`, and a provider renaming a model across separators cannot silently change how
|
|
690
|
+
it resolves. One list exists:
|
|
689
691
|
|
|
690
692
|
| List | Default | What it drives |
|
|
691
693
|
|------|---------|----------------|
|
|
692
694
|
| `strong` | `["claude-fable-5", "claude-mythos-5", "opus-4-8", "claude-opus-5"]` | `promptStyle: "auto"` resolution — a match resolves to `goal-oriented`, everything else to `prescriptive` (`isStrongModel` in `src/router/prompts.ts`). |
|
|
693
|
-
| `claude5x` | `["claude-fable-5", "claude-mythos-5"]` | The Claude 5.x generation list. In code it seeds the default `strong` list (`DEFAULT_STRONG_MODEL_PATTERNS` in `src/router/config.ts`), so `strong` is a superset of it by construction. |
|
|
694
695
|
|
|
695
|
-
|
|
696
|
-
|
|
696
|
+
Setting `strong` replaces the default list outright rather than extending it — include the
|
|
697
|
+
built-in patterns you still want. The list is curated per model, not by generation:
|
|
698
|
+
`claude-sonnet-5` is a Claude 5 model that is deliberately not in it. Claude-specific
|
|
697
699
|
prompt prefixes and the anti-narration detector do **not** use these lists; they match the
|
|
698
700
|
model ID directly (`isClaudeModel` in `src/router/protocol.ts`).
|
|
699
701
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-model-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "OpenCode plugin that routes tasks to tiered subagents (fast/medium/heavy) based on complexity",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"CHANGELOG.md"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@opencode-ai/plugin": ">=1.0.0"
|
|
48
|
+
"@opencode-ai/plugin": ">=1.0.0 <2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^26.2.0",
|
package/src/commands/output.ts
CHANGED
|
@@ -232,7 +232,6 @@ export function buildModelsOutput(
|
|
|
232
232
|
catalog: Catalog | null,
|
|
233
233
|
filter: string,
|
|
234
234
|
orphanedStrongPatterns: string[] = [],
|
|
235
|
-
strongPatternNearMisses: Record<string, string[]> = {},
|
|
236
235
|
): string {
|
|
237
236
|
// Orphan patterns are pure config analysis, so they are appended to EVERY
|
|
238
237
|
// return path — including the catalog-unavailable ones, where the warning is
|
|
@@ -240,7 +239,7 @@ export function buildModelsOutput(
|
|
|
240
239
|
const suffix =
|
|
241
240
|
orphanedStrongPatterns.length > 0
|
|
242
241
|
? "\n\n" +
|
|
243
|
-
formatOrphanedStrongPatterns(orphanedStrongPatterns
|
|
242
|
+
formatOrphanedStrongPatterns(orphanedStrongPatterns)
|
|
244
243
|
: "";
|
|
245
244
|
if (!catalog) {
|
|
246
245
|
return (
|
|
@@ -289,22 +288,10 @@ export function buildModelsOutput(
|
|
|
289
288
|
* `findOrphanedStrongPatterns`). Report-only — the router never edits the
|
|
290
289
|
* user's pattern list.
|
|
291
290
|
*/
|
|
292
|
-
export function formatOrphanedStrongPatterns(
|
|
293
|
-
patterns: string[],
|
|
294
|
-
nearMisses: Record<string, string[]> = {},
|
|
295
|
-
): string {
|
|
291
|
+
export function formatOrphanedStrongPatterns(patterns: string[]): string {
|
|
296
292
|
return [
|
|
297
293
|
"⚠ **Strong-model patterns matching no model your providers serve:**",
|
|
298
|
-
...patterns.map((p) => {
|
|
299
|
-
const near = nearMisses[p] ?? [];
|
|
300
|
-
if (near.length === 0) return `- \`${p}\``;
|
|
301
|
-
// Named separately from the generic rename hint below: when we can point
|
|
302
|
-
// at the served id, the user can fix it without going to look.
|
|
303
|
-
return `- \`${p}\` — served under a different separator: ${near
|
|
304
|
-
.slice(0, 3)
|
|
305
|
-
.map((r) => `\`${r}\``)
|
|
306
|
-
.join(", ")}`;
|
|
307
|
-
}),
|
|
294
|
+
...patterns.map((p) => `- \`${p}\``),
|
|
308
295
|
"",
|
|
309
296
|
"This may silently change prompt-style resolution for tiers on `promptStyle: auto`. If a provider renamed a model, update `modelGenerations.strong` in your overrides file (`/router overrides`).",
|
|
310
297
|
].join("\n");
|
package/src/index.ts
CHANGED
|
@@ -46,9 +46,9 @@ import {
|
|
|
46
46
|
assembleSystemPrompt,
|
|
47
47
|
} from "./router/protocol";
|
|
48
48
|
import { resolveEnforcementMode } from "./router/enforcement";
|
|
49
|
+
import { createPluginLogger } from "./router/logger";
|
|
49
50
|
import {
|
|
50
51
|
findOrphanedStrongPatterns,
|
|
51
|
-
findStrongPatternNearMisses,
|
|
52
52
|
normalizeCatalog,
|
|
53
53
|
validateModels,
|
|
54
54
|
} from "./router/catalog";
|
|
@@ -271,6 +271,11 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
271
271
|
// current plugin lifetime (i.e., until OpenCode is restarted).
|
|
272
272
|
let bypassed = false;
|
|
273
273
|
|
|
274
|
+
// Passive warnings go to opencode's log rather than stderr: console output
|
|
275
|
+
// from a plugin paints over the TUI. Falls back to console when the server
|
|
276
|
+
// has no /log endpoint. See src/router/logger.ts.
|
|
277
|
+
const logger = createPluginLogger(ctx.client);
|
|
278
|
+
|
|
274
279
|
// Fetch and normalize opencode's live provider/model catalog. Best-effort:
|
|
275
280
|
// returns null when the client call fails, e.g. the server is not ready yet.
|
|
276
281
|
// The pure analysis (validateModels) lives in src/router/catalog.ts.
|
|
@@ -727,14 +732,9 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
727
732
|
// tiers on auto. Catalog-dependent, so it rides the same deferred
|
|
728
733
|
// path — it is NOT emitted on turn 1.
|
|
729
734
|
for (const p of findOrphanedStrongPatterns(cfg, catalog)) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
near.length > 0
|
|
734
|
-
? ` — served under a different separator: ${near.slice(0, 3).join(", ")}`
|
|
735
|
-
: "";
|
|
736
|
-
console.warn(
|
|
737
|
-
`[model-router] strong-model pattern '${p}' matches no model your providers serve — may silently change prompt-style resolution for tiers on auto${hint}`,
|
|
735
|
+
logger.warn(
|
|
736
|
+
`strong-model pattern '${p}' matches no model your providers serve — may silently change prompt-style resolution for tiers on auto`,
|
|
737
|
+
{ pattern: p },
|
|
738
738
|
);
|
|
739
739
|
}
|
|
740
740
|
for (const it of validateModels(cfg, catalog)) {
|
|
@@ -747,9 +747,12 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
747
747
|
it.scope === "fallback"
|
|
748
748
|
? `${it.tier}[${it.providerId}]`
|
|
749
749
|
: `@${it.tier}`;
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
750
|
+
logger.warn(`${where} ${it.ref}: ${it.kind}${hint}`, {
|
|
751
|
+
tier: it.tier,
|
|
752
|
+
ref: it.ref,
|
|
753
|
+
kind: it.kind,
|
|
754
|
+
suggestions: it.suggestions,
|
|
755
|
+
});
|
|
753
756
|
}
|
|
754
757
|
}
|
|
755
758
|
}
|
|
@@ -1025,7 +1028,7 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
1025
1028
|
}
|
|
1026
1029
|
|
|
1027
1030
|
// Apply provider-specific options
|
|
1028
|
-
const opts = buildAgentOptions(tier, name);
|
|
1031
|
+
const opts = buildAgentOptions(tier, name, logger);
|
|
1029
1032
|
if (Object.keys(opts).length > 0) {
|
|
1030
1033
|
agentDef.options = opts;
|
|
1031
1034
|
}
|
|
@@ -1210,18 +1213,7 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
1210
1213
|
if (sub === "models") {
|
|
1211
1214
|
const catalog = await fetchCatalog();
|
|
1212
1215
|
const orphans = catalog ? findOrphanedStrongPatterns(cfg, catalog) : [];
|
|
1213
|
-
|
|
1214
|
-
if (catalog) {
|
|
1215
|
-
for (const p of orphans) {
|
|
1216
|
-
nearMisses[p] = findStrongPatternNearMisses(p, catalog);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
text = buildModelsOutput(
|
|
1220
|
-
catalog,
|
|
1221
|
-
parts.slice(1).join(" "),
|
|
1222
|
-
orphans,
|
|
1223
|
-
nearMisses,
|
|
1224
|
-
);
|
|
1216
|
+
text = buildModelsOutput(catalog, parts.slice(1).join(" "), orphans);
|
|
1225
1217
|
} else {
|
|
1226
1218
|
text = buildRouterOutput(cfg, args);
|
|
1227
1219
|
// On the bare status view, surface stale or missing models inline.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PluginLogger } from "./logger";
|
|
1
2
|
/**
|
|
2
3
|
* Registration-path agent options.
|
|
3
4
|
*
|
|
@@ -25,9 +26,19 @@ import { isClaudeModel } from "./protocol";
|
|
|
25
26
|
// two different mistakes are still two different warnings.
|
|
26
27
|
const warnedAgentOptionsEffort = new Set<string>();
|
|
27
28
|
|
|
28
|
-
export function warnAgentOptionsEffortOnce(
|
|
29
|
+
export function warnAgentOptionsEffortOnce(
|
|
30
|
+
key: string,
|
|
31
|
+
message: string,
|
|
32
|
+
logger?: PluginLogger,
|
|
33
|
+
): void {
|
|
29
34
|
if (warnedAgentOptionsEffort.has(key)) return;
|
|
30
35
|
warnedAgentOptionsEffort.add(key);
|
|
36
|
+
// Optional so this module keeps working for callers that have no client
|
|
37
|
+
// (unit tests, and buildAgentOptions being called directly).
|
|
38
|
+
if (logger) {
|
|
39
|
+
logger.warn(message, { key });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
31
42
|
console.warn(`[model-router] ${message}`);
|
|
32
43
|
}
|
|
33
44
|
|
|
@@ -54,7 +65,11 @@ function isOpenAIModel(model: string): boolean {
|
|
|
54
65
|
* only ever present when something asked for it — an unset `effort` leaves no
|
|
55
66
|
* trace in the returned object.
|
|
56
67
|
*/
|
|
57
|
-
export function buildAgentOptions(
|
|
68
|
+
export function buildAgentOptions(
|
|
69
|
+
tier: TierConfig,
|
|
70
|
+
tierName = tier.model,
|
|
71
|
+
logger?: PluginLogger,
|
|
72
|
+
): Record<string, unknown> {
|
|
58
73
|
const opts: Record<string, unknown> = {};
|
|
59
74
|
|
|
60
75
|
// Anthropic thinking config. A zero budget asks for no extended thinking at
|
|
@@ -68,6 +83,7 @@ export function buildAgentOptions(tier: TierConfig, tierName = tier.model): Reco
|
|
|
68
83
|
warnAgentOptionsEffortOnce(
|
|
69
84
|
`thinking-zero:${tierName}`,
|
|
70
85
|
`tier ${tierName}: thinking.budgetTokens: 0 is ignored`,
|
|
86
|
+
logger,
|
|
71
87
|
);
|
|
72
88
|
}
|
|
73
89
|
|
|
@@ -96,6 +112,7 @@ export function buildAgentOptions(tier: TierConfig, tierName = tier.model): Reco
|
|
|
96
112
|
warnAgentOptionsEffortOnce(
|
|
97
113
|
`anthropic-conflict:${tierName}`,
|
|
98
114
|
`tier ${tierName}: both thinking and effort set; explicit thinking wins`,
|
|
115
|
+
logger,
|
|
99
116
|
);
|
|
100
117
|
} else {
|
|
101
118
|
opts.effort = effort;
|
|
@@ -105,11 +122,13 @@ export function buildAgentOptions(tier: TierConfig, tierName = tier.model): Reco
|
|
|
105
122
|
warnAgentOptionsEffortOnce(
|
|
106
123
|
`openai-conflict:${tierName}`,
|
|
107
124
|
`tier ${tierName}: both reasoning.effort and effort set; explicit reasoning wins`,
|
|
125
|
+
logger,
|
|
108
126
|
);
|
|
109
127
|
} else if (effort === "xhigh" || effort === "max") {
|
|
110
128
|
warnAgentOptionsEffortOnce(
|
|
111
129
|
`openai-downgrade:${tierName}:${effort}`,
|
|
112
130
|
`tier ${tierName}: downgrading effort '${effort}' to 'high' because OpenAI reasoning_effort only supports low, medium, or high`,
|
|
131
|
+
logger,
|
|
113
132
|
);
|
|
114
133
|
opts.reasoning_effort = "high";
|
|
115
134
|
} else {
|
|
@@ -119,6 +138,7 @@ export function buildAgentOptions(tier: TierConfig, tierName = tier.model): Reco
|
|
|
119
138
|
warnAgentOptionsEffortOnce(
|
|
120
139
|
`unknown-provider:${tierName}`,
|
|
121
140
|
`tier ${tierName}: effort ignored for unknown provider family '${tier.model}'`,
|
|
141
|
+
logger,
|
|
122
142
|
);
|
|
123
143
|
}
|
|
124
144
|
}
|
package/src/router/catalog.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_STRONG_MODEL_PATTERNS, type RouterConfig } from "./config";
|
|
9
|
+
import { flattenModelID } from "./prompts";
|
|
9
10
|
import { getActiveTiers } from "./protocol";
|
|
10
11
|
|
|
11
12
|
export interface CatalogModel {
|
|
@@ -145,19 +146,24 @@ export function suggestModels(
|
|
|
145
146
|
* {@link DEFAULT_STRONG_MODEL_PATTERNS}) that match NO model in the live
|
|
146
147
|
* catalog. Report-only: the router never rewrites the user's pattern list.
|
|
147
148
|
*
|
|
148
|
-
* Why this exists: prompt-style resolution
|
|
149
|
-
* (`isStrongModel` in ./prompts).
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
149
|
+
* Why this exists: prompt-style resolution matches patterns against tier model
|
|
150
|
+
* ids (`isStrongModel` in ./prompts). A pattern that matches nothing any
|
|
151
|
+
* configured provider serves decides nothing, so it is dead weight the user
|
|
152
|
+
* probably meant to be doing something.
|
|
153
|
+
*
|
|
154
|
+
* Matching is IDENTICAL to `isStrongModel`: case- and separator-insensitive via
|
|
155
|
+
* the shared {@link flattenModelID}. That equivalence is the contract of this
|
|
156
|
+
* function — "orphaned" means precisely "isStrongModel would never match this
|
|
157
|
+
* against anything served". Historically the two used different rules, which is
|
|
158
|
+
* what made the old near-miss machinery necessary; see the note on `reportable`
|
|
159
|
+
* below.
|
|
153
160
|
*
|
|
154
161
|
* Comparison base: the CATALOG, not the active preset. The default pattern list
|
|
155
162
|
* is a cross-preset union by construction (see DEFAULT_STRONG_MODEL_PATTERNS in
|
|
156
163
|
* ./config), so any single preset leaves most of it unmatched — checking against
|
|
157
|
-
* the active preset would warn on every clean install.
|
|
158
|
-
* model
|
|
159
|
-
*
|
|
160
|
-
* mirroring `isStrongModel`, which is fed the full provider-prefixed tier model.
|
|
164
|
+
* the active preset would warn on every clean install. Refs are compared as
|
|
165
|
+
* `provider/model`, mirroring `isStrongModel`, which is fed the full
|
|
166
|
+
* provider-prefixed tier model.
|
|
161
167
|
*
|
|
162
168
|
* Never cries wolf: an empty catalog (fetch failed) or a catalog with no models
|
|
163
169
|
* returns `[]`, like `validateModels`.
|
|
@@ -165,6 +171,15 @@ export function suggestModels(
|
|
|
165
171
|
* Gate: reported only when at least one active tier resolves its style by `auto`
|
|
166
172
|
* (`promptStyle` absent or `"auto"`). With every tier pinned to an explicit
|
|
167
173
|
* style the pattern list decides nothing, so an orphan there is harmless noise.
|
|
174
|
+
*
|
|
175
|
+
* SCOPE BOUNDARY, DELIBERATE: `usesAuto` reads the ACTIVE preset only
|
|
176
|
+
* (`getActiveTiers` in ./protocol returns `cfg.presets[cfg.activePreset]`). A
|
|
177
|
+
* preset reachable only by failing over through `cfg.fallback` is not consulted,
|
|
178
|
+
* so a pattern that matters solely to such a preset is out of scope here. This
|
|
179
|
+
* is a choice, not an oversight: fallback presets are conditional futures, and
|
|
180
|
+
* warning about prompt-style resolution in a preset the session may never enter
|
|
181
|
+
* trades a real signal for speculative noise. The tier the user is actually
|
|
182
|
+
* running is what this check speaks about.
|
|
168
183
|
*/
|
|
169
184
|
export function findOrphanedStrongPatterns(
|
|
170
185
|
cfg: RouterConfig,
|
|
@@ -180,7 +195,7 @@ export function findOrphanedStrongPatterns(
|
|
|
180
195
|
|
|
181
196
|
const refs: string[] = [];
|
|
182
197
|
for (const p of catalog.providers) {
|
|
183
|
-
for (const m of p.models) refs.push(`${p.id}/${m.id}
|
|
198
|
+
for (const m of p.models) refs.push(flattenModelID(`${p.id}/${m.id}`));
|
|
184
199
|
}
|
|
185
200
|
if (refs.length === 0) return [];
|
|
186
201
|
|
|
@@ -189,55 +204,39 @@ export function findOrphanedStrongPatterns(
|
|
|
189
204
|
const patterns = raw.filter(
|
|
190
205
|
(p): p is string => typeof p === "string" && p.length > 0,
|
|
191
206
|
);
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
// Exactly isStrongModel()'s rule, via the shared normalizer: case- and
|
|
208
|
+
// separator-insensitive substring match. A pattern that flattens to nothing
|
|
209
|
+
// (e.g. "---") matches nothing there, so it is an orphan here too.
|
|
210
|
+
const orphans = patterns.filter((p) => {
|
|
211
|
+
const needle = flattenModelID(p);
|
|
212
|
+
return needle.length === 0 || !refs.some((r) => r.includes(needle));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Defaults are never reported; user-authored patterns are reported when dead.
|
|
216
|
+
//
|
|
217
|
+
// This used to be an evidence gate: a default pattern was reported only if it
|
|
218
|
+
// had a separator "near miss" AND named a model the active preset used. That
|
|
219
|
+
// gate was correct for the matcher of the time — `isStrongModel` compared
|
|
220
|
+
// separators literally, so `opus-4-8` genuinely failed against a served
|
|
221
|
+
// `claude-opus-4.8`, and a provider re-spelling a model could silently
|
|
222
|
+
// downgrade a tier from `goal-oriented` to `prescriptive`. The gate existed to
|
|
223
|
+
// catch that silence without drowning every install in noise from a default
|
|
224
|
+
// list that is a cross-provider union.
|
|
225
|
+
//
|
|
226
|
+
// `isStrongModel` now normalizes separators itself, so that failure mode is
|
|
227
|
+
// gone at the source: a "near miss" IS a match, and a default pattern can no
|
|
228
|
+
// longer be simultaneously orphaned and about a real served model. The gate
|
|
229
|
+
// became unreachable rather than wrong, and carrying unreachable code that
|
|
230
|
+
// implies a live hazard is worse than deleting it.
|
|
231
|
+
//
|
|
232
|
+
// What remains actionable is narrow and genuine: a user wrote a
|
|
233
|
+
// `modelGenerations.strong` entry that matches nothing their providers serve.
|
|
234
|
+
// That is a claim about THIS environment which is false, so we say so. The
|
|
235
|
+
// shipped defaults make no such claim and stay silent.
|
|
236
|
+
const reportable = configured === undefined ? [] : orphans;
|
|
208
237
|
return [...new Set(reportable)];
|
|
209
238
|
}
|
|
210
239
|
|
|
211
|
-
/**
|
|
212
|
-
* For an orphaned pattern, the served refs it would match if separators were
|
|
213
|
-
* ignored.
|
|
214
|
-
*
|
|
215
|
-
* `findOrphanedStrongPatterns` says a pattern is dead; this says why. The
|
|
216
|
-
* failure this exists for is separator drift, not a wrong name: `anthropic`
|
|
217
|
-
* ships `claude-opus-4-8` while the copilot preset uses `claude-opus-4.6`, so a
|
|
218
|
-
* provider moving between the two un-matches a pattern that is otherwise still
|
|
219
|
-
* describing the right model. Normalizing `.`, `-` and `_` away turns "this
|
|
220
|
-
* matches nothing" into "this matches nothing, but here is the model it almost
|
|
221
|
-
* certainly means", which is the difference between a warning and a fix.
|
|
222
|
-
*
|
|
223
|
-
* Returns empty when nothing plausibly matches, i.e. the pattern is simply
|
|
224
|
-
* wrong or the model is genuinely gone.
|
|
225
|
-
*/
|
|
226
|
-
export function findStrongPatternNearMisses(
|
|
227
|
-
pattern: string,
|
|
228
|
-
catalog: Catalog,
|
|
229
|
-
): string[] {
|
|
230
|
-
const flatten = (v: string) => v.toLowerCase().replace(/[.\-_]/g, "");
|
|
231
|
-
const needle = flatten(pattern);
|
|
232
|
-
if (!needle) return [];
|
|
233
|
-
|
|
234
|
-
const refs: string[] = [];
|
|
235
|
-
for (const p of catalog.providers) {
|
|
236
|
-
for (const m of p.models) refs.push(`${p.id}/${m.id}`);
|
|
237
|
-
}
|
|
238
|
-
return refs.filter((r) => flatten(r).includes(needle));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
240
|
export type ModelIssueKind =
|
|
242
241
|
| "provider-unknown"
|
|
243
242
|
| "model-missing"
|
package/src/router/config.ts
CHANGED
|
@@ -55,18 +55,25 @@ export const PROMPT_STYLES = ["prescriptive", "goal-oriented", "auto"] as const;
|
|
|
55
55
|
export type PromptStyle = (typeof PROMPT_STYLES)[number];
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* Model-ID patterns, matched as substrings of a tier's model ID with case and
|
|
59
|
+
* separators normalized (see flattenModelID in ./prompts).
|
|
60
60
|
*/
|
|
61
61
|
export interface ModelGenerationsConfig {
|
|
62
|
-
claude5x?: string[];
|
|
63
62
|
strong?: string[];
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
//
|
|
65
|
+
// Curated per model, NOT by generation. There used to be a `claude5x` list that
|
|
66
|
+
// this one spread, with a note claiming "strong is a superset of claude5x by
|
|
67
|
+
// construction — every Claude 5.x model is a strong model". Both halves stopped
|
|
68
|
+
// being true: `claude-opus-5` was added here without being added there, and
|
|
69
|
+
// `claude-sonnet-5` ships on two tiers as a Claude 5.x model that is
|
|
70
|
+
// deliberately not strong. Worse, the `claude5x` config field was validated and
|
|
71
|
+
// documented but never read — the spread happened once at module load from the
|
|
72
|
+
// default array, so a user override could not reach it. Generation is not the
|
|
73
|
+
// criterion; whether goal-oriented prompting suits the model is.
|
|
68
74
|
export const DEFAULT_STRONG_MODEL_PATTERNS = [
|
|
69
|
-
|
|
75
|
+
"claude-fable-5",
|
|
76
|
+
"claude-mythos-5",
|
|
70
77
|
"opus-4-8",
|
|
71
78
|
"claude-opus-5",
|
|
72
79
|
];
|
|
@@ -525,13 +532,14 @@ function validateModelGenerations(obj: Record<string, unknown>): void {
|
|
|
525
532
|
throw new Error("tiers.json: modelGenerations must be an object");
|
|
526
533
|
}
|
|
527
534
|
const modelGenerations = obj.modelGenerations as Record<string, unknown>;
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
+
// Only `strong` is validated because only `strong` is read. Unknown keys —
|
|
536
|
+
// including the removed `claude5x` — are ignored rather than rejected, so an
|
|
537
|
+
// existing tiers.json carrying one still loads.
|
|
538
|
+
if (
|
|
539
|
+
modelGenerations.strong !== undefined &&
|
|
540
|
+
!Array.isArray(modelGenerations.strong)
|
|
541
|
+
) {
|
|
542
|
+
throw new Error("tiers.json: modelGenerations.strong must be an array");
|
|
535
543
|
}
|
|
536
544
|
}
|
|
537
545
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the plugin's passive warnings go.
|
|
3
|
+
*
|
|
4
|
+
* `console.warn` from a plugin lands on the server process's stderr, which the
|
|
5
|
+
* TUI does not own, so anything written there paints over whatever the terminal
|
|
6
|
+
* was drawing. A user reported exactly that: a preset switch smeared a
|
|
7
|
+
* ~230-character warning across two lines of UI.
|
|
8
|
+
*
|
|
9
|
+
* opencode exposes `POST /log` for this, reachable as `client.app.log`. Entries
|
|
10
|
+
* go to opencode's own log with a service tag instead of into the terminal.
|
|
11
|
+
*
|
|
12
|
+
* Fail-soft by contract. The call is fire-and-forget: a warning is never worth
|
|
13
|
+
* blocking a hook on, and a logging failure must never surface as a plugin
|
|
14
|
+
* error. When the endpoint is unavailable, when the post rejects, and when it
|
|
15
|
+
* resolves reporting an error, the message falls back to console.warn so a
|
|
16
|
+
* diagnostic is never silently dropped.
|
|
17
|
+
*
|
|
18
|
+
* Two properties of the real SDK client shape this file, and getting either
|
|
19
|
+
* wrong degrades the feature silently rather than loudly:
|
|
20
|
+
*
|
|
21
|
+
* 1. `client.app` is a class instance (`App extends _HeyApiClient`) whose
|
|
22
|
+
* methods read `this._client`. Detaching the method — `const log =
|
|
23
|
+
* client.app.log` — leaves `this` undefined under ESM strict mode, so every
|
|
24
|
+
* call throws and every warning quietly takes the console fallback. The
|
|
25
|
+
* method is therefore always invoked with its receiver bound.
|
|
26
|
+
* 2. `App.log` defaults to `ThrowOnError = false`, so an HTTP failure RESOLVES
|
|
27
|
+
* as `{ data: undefined, error }` instead of rejecting. A bare `.catch()`
|
|
28
|
+
* sees nothing on a 400, so the settled value is inspected as well.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export interface PluginLogger {
|
|
32
|
+
warn(message: string, extra?: Record<string, unknown>): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The service tag on every entry, so entries are greppable by origin. */
|
|
36
|
+
export const LOG_SERVICE = "model-router";
|
|
37
|
+
|
|
38
|
+
/** Prefix used only on the console fallback, where there is no service field. */
|
|
39
|
+
const CONSOLE_PREFIX = `[${LOG_SERVICE}]`;
|
|
40
|
+
|
|
41
|
+
type LogRequest = {
|
|
42
|
+
body: {
|
|
43
|
+
service: string;
|
|
44
|
+
level: "debug" | "info" | "error" | "warn";
|
|
45
|
+
message: string;
|
|
46
|
+
extra?: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Structural view of the one method we use. Deliberately narrow: the plugin
|
|
52
|
+
* must keep working against a bare stub (every unit test hands it one) and
|
|
53
|
+
* against an older server with no `/log` at all, so the capability is probed at
|
|
54
|
+
* runtime rather than demanded by the type.
|
|
55
|
+
*/
|
|
56
|
+
type LogCapableClient = {
|
|
57
|
+
app?: {
|
|
58
|
+
log?: (req: LogRequest) => unknown;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The SDK resolves rather than rejects on an HTTP failure, reporting it as a
|
|
64
|
+
* populated `error` field on the settled value. Treat that as a failed post.
|
|
65
|
+
*/
|
|
66
|
+
function isErrorResult(value: unknown): boolean {
|
|
67
|
+
return (
|
|
68
|
+
typeof value === "object" &&
|
|
69
|
+
value !== null &&
|
|
70
|
+
"error" in value &&
|
|
71
|
+
(value as { error?: unknown }).error !== undefined
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Build a logger over an opencode client. Falls back to the console when the
|
|
77
|
+
* client cannot log, which covers older servers and every unit test that hands
|
|
78
|
+
* the plugin a stub.
|
|
79
|
+
*/
|
|
80
|
+
export function createPluginLogger(client?: unknown): PluginLogger {
|
|
81
|
+
const app = (client as LogCapableClient | undefined)?.app;
|
|
82
|
+
const log = app?.log;
|
|
83
|
+
|
|
84
|
+
if (!app || typeof log !== "function") {
|
|
85
|
+
return {
|
|
86
|
+
warn(message) {
|
|
87
|
+
console.warn(`${CONSOLE_PREFIX} ${message}`);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
warn(message, extra) {
|
|
94
|
+
const toConsole = () => console.warn(`${CONSOLE_PREFIX} ${message}`);
|
|
95
|
+
let result: unknown;
|
|
96
|
+
try {
|
|
97
|
+
// Bound to `app` on purpose — see (1) in the module comment. Calling
|
|
98
|
+
// the detached reference would throw on every real client.
|
|
99
|
+
result = log.call(app, {
|
|
100
|
+
body: {
|
|
101
|
+
service: LOG_SERVICE,
|
|
102
|
+
level: "warn",
|
|
103
|
+
message,
|
|
104
|
+
...(extra ? { extra } : {}),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
// A synchronous throw means the transport is unusable; say it somewhere.
|
|
109
|
+
toConsole();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Fire-and-forget: never await, but never leave a rejection unhandled
|
|
113
|
+
// either, and do not lose the diagnostic when the post fails — whether it
|
|
114
|
+
// fails by rejecting or by resolving with an error. See (2) above.
|
|
115
|
+
void Promise.resolve(result)
|
|
116
|
+
.then((settled) => {
|
|
117
|
+
if (isErrorResult(settled)) toConsole();
|
|
118
|
+
})
|
|
119
|
+
.catch(toConsole);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
package/src/router/prompts.ts
CHANGED
|
@@ -47,13 +47,46 @@ Ground every claim in a tool result or the context you were given; flag anything
|
|
|
47
47
|
Begin your response with exactly one of \`DONE:\` (structured analysis), \`SCOPE GROWTH:\` (prefer @fast pre-exploration of [specific files/patterns/areas] before I continue), or \`ESCALATE:\`.`,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Fold away case and separator style (`.`, `-`, `_`) so two spellings of the
|
|
52
|
+
* same model id compare equal. `/` is deliberately preserved: it separates the
|
|
53
|
+
* provider prefix from the model id, and collapsing it would let a pattern
|
|
54
|
+
* match across that boundary.
|
|
55
|
+
*
|
|
56
|
+
* Exported because `findOrphanedStrongPatterns` in ./catalog must ask exactly
|
|
57
|
+
* the question `isStrongModel` answers — "would this pattern match anything?" —
|
|
58
|
+
* and a second, drifting copy of this rule would reintroduce the mismatch it
|
|
59
|
+
* exists to remove.
|
|
60
|
+
*/
|
|
61
|
+
export const flattenModelID = (v: string): string =>
|
|
62
|
+
v.toLowerCase().replace(/[.\-_]/g, "");
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Substring match against the strong-model pattern list, ignoring case AND
|
|
66
|
+
* separator style: `.`, `-` and `_` are normalized away on both sides, so the
|
|
67
|
+
* pattern `opus-4-8` matches the served id `claude-opus-4.8`, and
|
|
68
|
+
* `claude-haiku-4-5` matches `claude-haiku-4.5`.
|
|
69
|
+
*
|
|
70
|
+
* Why separator-insensitive: providers spell the same model differently and
|
|
71
|
+
* change their minds. Our own shipped tiers.json carries
|
|
72
|
+
* `anthropic/claude-haiku-4-5` and `github-copilot/claude-haiku-4.5` for one
|
|
73
|
+
* model. Under a plain substring match, that drift silently un-matched the
|
|
74
|
+
* pattern list and quietly downgraded a tier's prompt style from
|
|
75
|
+
* `goal-oriented` to `prescriptive` — no error, no log, just a weaker prompt.
|
|
76
|
+
* Normalizing separators here removes that failure mode at the source.
|
|
77
|
+
*
|
|
78
|
+
* The provider prefix still participates in the match (see
|
|
79
|
+
* {@link flattenModelID}), so a pattern may target `provider/model` refs.
|
|
80
|
+
*/
|
|
51
81
|
export function isStrongModel(modelID: string | undefined, cfg: RouterConfig): boolean {
|
|
52
82
|
if (typeof modelID !== "string" || modelID.length === 0) return false;
|
|
53
83
|
const raw = cfg.modelGenerations?.strong ?? DEFAULT_STRONG_MODEL_PATTERNS;
|
|
54
84
|
const patterns = raw.filter((p): p is string => typeof p === "string" && p.length > 0);
|
|
55
|
-
const id = modelID
|
|
56
|
-
return patterns.some((p) =>
|
|
85
|
+
const id = flattenModelID(modelID);
|
|
86
|
+
return patterns.some((p) => {
|
|
87
|
+
const needle = flattenModelID(p);
|
|
88
|
+
return needle.length > 0 && id.includes(needle);
|
|
89
|
+
});
|
|
57
90
|
}
|
|
58
91
|
|
|
59
92
|
/** Resolve "auto" (or absent) to a concrete style. Fail-safe: unknown/empty model -> prescriptive. */
|