opencode-model-router 1.9.0 → 1.11.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 +81 -0
- package/README.md +18 -8
- package/package.json +2 -1
- package/src/commands/output.ts +4 -3
- package/src/index.ts +15 -5
- package/src/router/catalog.ts +10 -11
- package/src/router/config.ts +31 -0
- package/src/router/logger.ts +37 -3
- package/tiers.json +46 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,87 @@ 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.11.0] - 2026-08-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A `zai` preset, routing GLM models through the Z.AI Coding Plan.** `@fast` takes
|
|
13
|
+
`glm-4.7`, `@medium` and `@heavy` share `glm-5.3` at `high` and `max` effort. Contributed
|
|
14
|
+
by @MarCYK in
|
|
15
|
+
[#37](https://github.com/marco-jardim/opencode-model-router/pull/37), closing
|
|
16
|
+
[#18](https://github.com/marco-jardim/opencode-model-router/issues/18).
|
|
17
|
+
|
|
18
|
+
Landed with three fixes on top. The preset originally named the `zai` provider, but
|
|
19
|
+
`glm-5.3` is not published under it in the models.dev catalog opencode resolves against
|
|
20
|
+
— it exists only under `zai-coding-plan`, whose reasoning options (`low`/`high`/`max`)
|
|
21
|
+
are also what make the `high` and `max` variants valid. All three tiers now point at
|
|
22
|
+
`zai-coding-plan/*` and say so in their descriptions, since the plan is a prerequisite.
|
|
23
|
+
`fallback.global` gained a `zai-coding-plan` chain, so a Z.AI outage now fails over
|
|
24
|
+
instead of dead-ending. And `costRatio` follows the `fable-effort` precedent — `1`/`3`/`6`
|
|
25
|
+
as an estimated token-spend multiplier, not a price difference, because `@medium` and
|
|
26
|
+
`@heavy` are the same model on a flat-rate plan where the catalog prices every model at
|
|
27
|
+
zero.
|
|
28
|
+
|
|
29
|
+
## [1.10.0] - 2026-08-20
|
|
30
|
+
|
|
31
|
+
Minor release. Config errors are caught at load instead of drifting to a later turn,
|
|
32
|
+
the logging path 1.9.0 introduced is finished — it was losing messages entirely in
|
|
33
|
+
short-lived processes, and one warning had never been routed through it at all — and
|
|
34
|
+
there is now a smoke lane that needs no credential and therefore actually runs.
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- **A credential-free smoke lane, running on every push.** `opencode debug agent`
|
|
39
|
+
loads the plugin, runs the `config` hook, resolves overrides and registers agents
|
|
40
|
+
with no API key and no model call, so an end-to-end check of registration costs
|
|
41
|
+
~20s. The existing smoke lane is gated on secrets, which made it a green no-op on
|
|
42
|
+
forks — and meant the only test covering the `config` hook had been asserting the
|
|
43
|
+
pre-1.8.0 anthropic preset for a whole release without anyone finding out. Those
|
|
44
|
+
pins are repaired, and the new lane asserts that **stderr is empty**, which is
|
|
45
|
+
coverage unit tests structurally cannot provide: they hand the plugin a stub client,
|
|
46
|
+
so they have neither a real SDK receiver nor a real process's stderr to check.
|
|
47
|
+
|
|
48
|
+
- **A malformed tier `model` is rejected when the config loads, not on some later
|
|
49
|
+
turn.** `"model": "claude-sonnet-5"` — a ref missing its provider — used to validate
|
|
50
|
+
clean and only surface as a catalog issue on a turn that happened to have the catalog
|
|
51
|
+
in hand, or never, if the fetch failed. The `provider/model` shape needs no network,
|
|
52
|
+
so it is now decided at load, alongside the existing `effort` and `promptStyle`
|
|
53
|
+
checks. `parseModelRef` moved to `config.ts` (re-exported from `catalog.ts`) so load
|
|
54
|
+
validation and catalog lookup share one definition of well-formed: passing the first
|
|
55
|
+
now guarantees parsing in the second. Observed by @MetalbolicX in
|
|
56
|
+
[#17](https://github.com/marco-jardim/opencode-model-router/issues/17); implementation
|
|
57
|
+
is independent of the fork's.
|
|
58
|
+
|
|
59
|
+
Behaviour change for an existing malformed config: an overrides file carrying a bad
|
|
60
|
+
ref is now dropped with a warning naming the offending value, and the bundled
|
|
61
|
+
defaults stand. Startup is never blocked — the layer-drop path already guaranteed
|
|
62
|
+
that, and there is now a test pinning it for this case specifically.
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- **The orphaned-pattern warning no longer suggests a fix that cannot apply.** It still
|
|
67
|
+
told the user a provider rename was the likely cause and to update
|
|
68
|
+
`modelGenerations.strong` to match. Since 1.9.0 normalizes separators, a rename is
|
|
69
|
+
matched rather than orphaned, so the only way to reach the warning is a user-authored
|
|
70
|
+
pattern naming something genuinely absent. The copy now says that and forecloses the
|
|
71
|
+
separator fix explicitly.
|
|
72
|
+
|
|
73
|
+
- **Passive warnings are no longer lost in short-lived processes.** 1.9.0 sent them to
|
|
74
|
+
opencode's log fire-and-forget, which is right for a hook — a warning must never
|
|
75
|
+
block one — but in `opencode run` or `opencode debug` the post never settled before
|
|
76
|
+
the process exited, and the console fallback never fired because nothing had failed.
|
|
77
|
+
The warning reached neither the log nor the terminal. The plugin API has
|
|
78
|
+
`dispose?: () => Promise<void>`, and opencode calls *and awaits* it even on a
|
|
79
|
+
two-second run, so the logger now tracks in-flight posts and `dispose` drains them.
|
|
80
|
+
The tracked promise is the already-`catch`-wrapped one, so a failing post can never
|
|
81
|
+
reject out of teardown. ([#36](https://github.com/marco-jardim/opencode-model-router/issues/36))
|
|
82
|
+
|
|
83
|
+
- **The `opencode-anthropic-fix` dependency notice reaches the log instead of the
|
|
84
|
+
terminal.** 1.9.0 routed five of the six `warnAgentOptionsEffortOnce` call sites
|
|
85
|
+
through the logger and missed the one in `index.ts`, so that warning kept writing to
|
|
86
|
+
stderr — the exact symptom the change existed to remove. Found by running a real
|
|
87
|
+
process, not by a test; there is now a test.
|
|
88
|
+
|
|
8
89
|
## [1.9.0] - 2026-08-20
|
|
9
90
|
|
|
10
91
|
Minor release. One real bug — prompt-style resolution broke when a provider renamed a
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **Use the cheapest model that can do the job. Automatically.**
|
|
4
4
|
|
|
5
|
-
An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,
|
|
5
|
+
An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,116–4,686 characters of system-prompt overhead depending on the orchestrator and enforcement mode.
|
|
6
6
|
|
|
7
7
|
## Why it's different
|
|
8
8
|
|
|
@@ -12,7 +12,7 @@ Most AI coding tools give you one model for everything. You pay Opus prices to r
|
|
|
12
12
|
The orchestrator runs on *every* message. Put Sonnet there, not Opus. Sonnet reads a routing protocol and delegates just as well as Opus — at 4x lower cost. Reserve Opus for when it genuinely matters.
|
|
13
13
|
|
|
14
14
|
**Inject a compressed, LLM-optimized routing protocol.**
|
|
15
|
-
Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,
|
|
15
|
+
Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,116 characters; a Claude orchestrator receives 3,888 characters after its authority prefix (roughly 965–1,075 tokens at 3.6–4.0 characters per token). Every message, every session.
|
|
16
16
|
|
|
17
17
|
**Match task to tier using a configurable taxonomy.**
|
|
18
18
|
A keyword routing guide (`@fast→search/grep/read`, `@medium→impl/refactor/test`, `@heavy→arch/debug/security`) tells the orchestrator exactly which tier fits each task type. Fully customizable. No ambiguity.
|
|
@@ -33,7 +33,7 @@ Every tier carries its `costRatio` (fast=1x, medium=5x, heavy=20x) injected into
|
|
|
33
33
|
If the orchestrator is already running on Opus, the rule `self∈opus→never→@heavy` fires — it does the heavy work itself rather than delegating to another Opus instance.
|
|
34
34
|
|
|
35
35
|
**Multi-provider support with automatic fallback.**
|
|
36
|
-
|
|
36
|
+
Seven presets out of the box: Anthropic, OpenAI, GitHub Copilot, Google, hybrid, fable-effort, and Zai (GLM). Switch with `/preset`. If a provider fails, the fallback chain tries the next one automatically.
|
|
37
37
|
|
|
38
38
|
**Plan annotation for long tasks.**
|
|
39
39
|
`/annotate-plan` reads a markdown plan and tags each step with `[tier:fast]`, `[tier:medium]`, or `[tier:heavy]` — removing all routing ambiguity from multi-step workflows.
|
|
@@ -65,7 +65,7 @@ opencode-model-router injects a **delegation protocol** into the system prompt t
|
|
|
65
65
|
4. **Never over-qualify** — use the cheapest tier that can reliably handle the task
|
|
66
66
|
5. **Fallback** across providers when one fails
|
|
67
67
|
|
|
68
|
-
All of this adds 3,
|
|
68
|
+
All of this adds 3,116 characters for a non-Claude orchestrator or 3,888 characters for a Claude orchestrator (roughly 770–1,075 tokens at 3.6–4.0 characters per token).
|
|
69
69
|
|
|
70
70
|
## Understanding how it works
|
|
71
71
|
|
|
@@ -166,7 +166,7 @@ Task distribution: 18 exploration (60%), 10 implementation (33%), 2 architecture
|
|
|
166
166
|
|
|
167
167
|
## How it works
|
|
168
168
|
|
|
169
|
-
On every message, the plugin injects a 3,
|
|
169
|
+
On every message, the plugin injects a 3,116-character routing protocol. A Claude orchestrator receives 3,888 characters after its authority prefix (roughly 965–1,075 tokens at 3.6–4.0 characters per token). The notation is intentionally dense and compressed — it's **optimized for LLM comprehension, not human readability**. An agent reads it as a precise routing grammar; a human might squint at it.
|
|
170
170
|
|
|
171
171
|
What the orchestrator sees (Anthropic preset, normal mode):
|
|
172
172
|
|
|
@@ -218,7 +218,7 @@ With router → split:
|
|
|
218
218
|
| Cross-provider fallback | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
219
219
|
| Cost ratio awareness | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
220
220
|
| Plan annotation with tiers | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
221
|
-
| Measured prompt overhead: 3,
|
|
221
|
+
| Measured prompt overhead: 3,116–4,686 chars | ✅ | — | ❌ | ❌ | ❌ |
|
|
222
222
|
|
|
223
223
|
**Claude native**: single model for everything, no cost routing. If you're using claude.ai or OpenCode without plugins, you're paying the same price for `grep` as for architecture design.
|
|
224
224
|
|
|
@@ -371,7 +371,7 @@ For an npm install, `tiers.json` is **inside the cached package directory**, not
|
|
|
371
371
|
|
|
372
372
|
### Presets
|
|
373
373
|
|
|
374
|
-
The plugin ships with
|
|
374
|
+
The plugin ships with seven presets (switch with `/preset <name>`):
|
|
375
375
|
|
|
376
376
|
**anthropic** (default):
|
|
377
377
|
| Tier | Model | Cost ratio |
|
|
@@ -418,6 +418,16 @@ The plugin ships with six presets (switch with `/preset <name>`):
|
|
|
418
418
|
Because the model string is identical across tiers, escalating a task keeps the prompt
|
|
419
419
|
cache warm. The cost ratios are estimated token-spend multipliers, not price differences.
|
|
420
420
|
|
|
421
|
+
**zai** — GLM through the Z.AI Coding Plan (the `zai-coding-plan` provider, which is where `glm-5.3` lives):
|
|
422
|
+
| Tier | Model | Variant | Cost ratio |
|
|
423
|
+
|------|-------|---------|-----------|
|
|
424
|
+
| @fast | `zai-coding-plan/glm-4.7` | — | 1x |
|
|
425
|
+
| @medium | `zai-coding-plan/glm-5.3` | `high` | 3x |
|
|
426
|
+
| @heavy | `zai-coding-plan/glm-5.3` | `max` | 6x |
|
|
427
|
+
|
|
428
|
+
@medium and @heavy share one model, so — as with `fable-effort` — the cost ratios are
|
|
429
|
+
estimated token-spend multipliers, not price differences.
|
|
430
|
+
|
|
421
431
|
### Per-tier `effort`
|
|
422
432
|
|
|
423
433
|
Any tier may set `effort`: `low`, `medium`, `high`, `xhigh`, or `max`. Precedence,
|
|
@@ -983,7 +993,7 @@ After `/annotate-plan`:
|
|
|
983
993
|
|
|
984
994
|
## Token overhead
|
|
985
995
|
|
|
986
|
-
Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,
|
|
996
|
+
Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,116 characters for a non-Claude orchestrator. A Claude orchestrator receives 3,888 characters after its authority prefix, or 4,686 characters when the 798-character DoD/enforcement section is enabled. That is roughly 770–1,295 tokens across the three paths at 3.6–4.0 characters per token. The optional anti-narration clause adds another 650 characters to the Claude path.
|
|
987
997
|
|
|
988
998
|
These are character counts of the prompts the shipped config actually produces, so they move whenever the protocol text does. `test/unit/docs-drift.test.ts` recomputes all three from `tiers.json` on every run and fails unless this section still quotes them, so a change that grows the protocol cannot land without updating these numbers.
|
|
989
999
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-model-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"test:watch": "vitest",
|
|
10
10
|
"test:coverage": "vitest run --coverage",
|
|
11
11
|
"smoke": "cross-env RUN_OC_SMOKE=1 vitest run --config vitest.smoke.config.ts test/smoke",
|
|
12
|
+
"smoke:keyless": "cross-env RUN_OC_SMOKE_KEYLESS=1 vitest run --config vitest.smoke.config.ts test/smoke/registration.smoke.test.ts test/smoke/subagent-tiers.smoke.test.ts test/smoke/deferred-catalog.smoke.test.ts",
|
|
12
13
|
"typecheck": "tsc --noEmit"
|
|
13
14
|
},
|
|
14
15
|
"license": "GPL-3.0-only",
|
package/src/commands/output.ts
CHANGED
|
@@ -284,8 +284,9 @@ export function buildModelsOutput(
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
|
-
* Render strong-model patterns that match no model
|
|
288
|
-
* `findOrphanedStrongPatterns`).
|
|
287
|
+
* Render strong-model patterns that match no model the configured providers
|
|
288
|
+
* serve (see `findOrphanedStrongPatterns`). Only ever user-authored patterns:
|
|
289
|
+
* shipped defaults are not reported. Report-only — the router never edits the
|
|
289
290
|
* user's pattern list.
|
|
290
291
|
*/
|
|
291
292
|
export function formatOrphanedStrongPatterns(patterns: string[]): string {
|
|
@@ -293,7 +294,7 @@ export function formatOrphanedStrongPatterns(patterns: string[]): string {
|
|
|
293
294
|
"⚠ **Strong-model patterns matching no model your providers serve:**",
|
|
294
295
|
...patterns.map((p) => `- \`${p}\``),
|
|
295
296
|
"",
|
|
296
|
-
"
|
|
297
|
+
"You set these in `modelGenerations.strong`, so they decide nothing here and tiers on `promptStyle: auto` resolve without them. Matching already ignores case and separator style, so `opus-4-8` finds `opus-4.8` — a pattern listed above is absent, not merely spelled differently. Fix or drop it in your overrides file (`/router overrides`).",
|
|
297
298
|
].join("\n");
|
|
298
299
|
}
|
|
299
300
|
|
package/src/index.ts
CHANGED
|
@@ -326,6 +326,13 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
326
326
|
process.env.MODEL_ROUTER_VERIFIED_DELEGATE === "1";
|
|
327
327
|
|
|
328
328
|
return {
|
|
329
|
+
// Warnings post to /log fire-and-forget, which loses the message when the
|
|
330
|
+
// process is about to exit — `opencode run` and `opencode debug` are short
|
|
331
|
+
// enough for that to be the normal case. Verified against opencode 1.18.16
|
|
332
|
+
// that dispose is both called and awaited, so flushing here is enough.
|
|
333
|
+
dispose: async () => {
|
|
334
|
+
await logger.flush();
|
|
335
|
+
},
|
|
329
336
|
tool: {
|
|
330
337
|
...(enableDelegateTool ? { delegate: tool({
|
|
331
338
|
description:
|
|
@@ -727,13 +734,15 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
727
734
|
catalogWarned = true;
|
|
728
735
|
const catalog = deferredCatalog;
|
|
729
736
|
if (catalog) {
|
|
730
|
-
//
|
|
731
|
-
//
|
|
732
|
-
//
|
|
733
|
-
//
|
|
737
|
+
// User-authored strong-model patterns matching nothing any
|
|
738
|
+
// configured provider serves. Shipped defaults are never reported
|
|
739
|
+
// (see findOrphanedStrongPatterns), so reaching here means the
|
|
740
|
+
// user wrote a claim about this environment that is false.
|
|
741
|
+
// Catalog-dependent, so it rides the same deferred path — it is
|
|
742
|
+
// NOT emitted on turn 1.
|
|
734
743
|
for (const p of findOrphanedStrongPatterns(cfg, catalog)) {
|
|
735
744
|
logger.warn(
|
|
736
|
-
`strong-model pattern '${p}' matches no model your providers serve
|
|
745
|
+
`strong-model pattern '${p}' from your modelGenerations.strong matches no model your providers serve, so it decides nothing — separator style is already ignored when matching`,
|
|
737
746
|
{ pattern: p },
|
|
738
747
|
);
|
|
739
748
|
}
|
|
@@ -1036,6 +1045,7 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
1036
1045
|
warnAgentOptionsEffortOnce(
|
|
1037
1046
|
"anthropic-effort-dependency",
|
|
1038
1047
|
"effort on Anthropic models requires the opencode-anthropic-fix plugin (commit 307aea9+ for fable/mythos); non-adaptive Claude models (e.g. haiku) silently strip effort at the API layer, and without the plugin a top-level effort can break Claude-Code billing fingerprinting",
|
|
1048
|
+
logger,
|
|
1039
1049
|
);
|
|
1040
1050
|
}
|
|
1041
1051
|
|
package/src/router/catalog.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
// raw payload is handed here for normalization and analysis.
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_STRONG_MODEL_PATTERNS,
|
|
10
|
+
parseModelRef,
|
|
11
|
+
type RouterConfig,
|
|
12
|
+
} from "./config";
|
|
9
13
|
import { flattenModelID } from "./prompts";
|
|
10
14
|
import { getActiveTiers } from "./protocol";
|
|
11
15
|
|
|
@@ -80,17 +84,12 @@ export function isCatalogEmpty(catalog: Catalog): boolean {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
|
-
*
|
|
84
|
-
* the
|
|
85
|
-
*
|
|
87
|
+
* Re-exported from config.ts, where it lives because the `provider/model` shape
|
|
88
|
+
* is a property of the config format rather than of the catalog. Config load
|
|
89
|
+
* rejects a ref this cannot parse, so by the time a ref reaches the lookups
|
|
90
|
+
* below it has already been through the same function.
|
|
86
91
|
*/
|
|
87
|
-
export
|
|
88
|
-
ref: string,
|
|
89
|
-
): { providerId: string; modelId: string } | undefined {
|
|
90
|
-
const i = ref.indexOf("/");
|
|
91
|
-
if (i <= 0 || i === ref.length - 1) return undefined;
|
|
92
|
-
return { providerId: ref.slice(0, i), modelId: ref.slice(i + 1) };
|
|
93
|
-
}
|
|
92
|
+
export { parseModelRef };
|
|
94
93
|
|
|
95
94
|
function findProvider(
|
|
96
95
|
catalog: Catalog,
|
package/src/router/config.ts
CHANGED
|
@@ -338,6 +338,25 @@ function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
|
338
338
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
+
/**
|
|
342
|
+
* Split a tier model reference (`"provider/model"`) into its parts. Splits on
|
|
343
|
+
* the FIRST slash only, so multi-segment model ids (e.g.
|
|
344
|
+
* `openrouter/deepseek/deepseek-v3.2`) keep their full model id.
|
|
345
|
+
*
|
|
346
|
+
* Lives here rather than in catalog.ts because the `provider/model` shape is a
|
|
347
|
+
* property of the config format, not of the catalog. Config load and catalog
|
|
348
|
+
* lookup have to agree on what a well-formed ref is; sharing one function is
|
|
349
|
+
* what makes "it validated at load" mean "it will parse later". catalog.ts
|
|
350
|
+
* re-exports it so the reference is still reachable from where it is used.
|
|
351
|
+
*/
|
|
352
|
+
export function parseModelRef(
|
|
353
|
+
ref: string,
|
|
354
|
+
): { providerId: string; modelId: string } | undefined {
|
|
355
|
+
const i = ref.indexOf("/");
|
|
356
|
+
if (i <= 0 || i === ref.length - 1) return undefined;
|
|
357
|
+
return { providerId: ref.slice(0, i), modelId: ref.slice(i + 1) };
|
|
358
|
+
}
|
|
359
|
+
|
|
341
360
|
/**
|
|
342
361
|
* Shape of every preset and every tier within it. Returns the presets map so
|
|
343
362
|
* the caller can hand it to validateActivePreset without re-narrowing.
|
|
@@ -372,6 +391,18 @@ function validatePresets(obj: Record<string, unknown>): Record<string, unknown>
|
|
|
372
391
|
`tiers.json: '${presetName}.${tierName}.model' must be a non-empty string`,
|
|
373
392
|
);
|
|
374
393
|
}
|
|
394
|
+
// Same reasoning as effort and promptStyle below, one step earlier: a ref
|
|
395
|
+
// missing its provider (`claude-sonnet-5`) or missing its model
|
|
396
|
+
// (`anthropic/`) used to load clean and only surface much later, as a
|
|
397
|
+
// catalog issue on a turn that happened to fetch the catalog — or never,
|
|
398
|
+
// if the fetch failed. The shape is knowable without the network, so it
|
|
399
|
+
// is decided here. parseModelRef is the same function the catalog lookup
|
|
400
|
+
// uses, so passing this guarantees the ref parses there too.
|
|
401
|
+
if (!parseModelRef(t.model)) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`tiers.json: '${presetName}.${tierName}.model' must be 'provider/model' (got '${t.model}')`,
|
|
404
|
+
);
|
|
405
|
+
}
|
|
375
406
|
if (t.description !== undefined && typeof t.description !== "string") {
|
|
376
407
|
throw new Error(
|
|
377
408
|
`tiers.json: '${presetName}.${tierName}.description' must be a string`,
|
package/src/router/logger.ts
CHANGED
|
@@ -26,10 +26,29 @@
|
|
|
26
26
|
* 2. `App.log` defaults to `ThrowOnError = false`, so an HTTP failure RESOLVES
|
|
27
27
|
* as `{ data: undefined, error }` instead of rejecting. A bare `.catch()`
|
|
28
28
|
* sees nothing on a 400, so the settled value is inspected as well.
|
|
29
|
+
* 3. Fire-and-forget loses the message outright when the process is about to
|
|
30
|
+
* exit: the post never settles, and the fallback never runs because nothing
|
|
31
|
+
* failed. A long-lived server never notices; `opencode run` and `opencode
|
|
32
|
+
* debug` are short-lived and would go silent, which is strictly worse than
|
|
33
|
+
* the stderr write this file exists to avoid. Hence `flush()`, awaited from
|
|
34
|
+
* the plugin's `dispose` hook. Verified against a live opencode 1.18.16:
|
|
35
|
+
* `dispose` is both called and awaited on `opencode debug agent`.
|
|
36
|
+
*
|
|
37
|
+
* One thing to know before debugging this: the `service` tag is a namespace,
|
|
38
|
+
* not a rendered field. Entries land as
|
|
39
|
+
* `timestamp=... level=WARN run=... message="..." <extra keys>` with no
|
|
40
|
+
* `service=` anywhere, so grepping opencode's log for `service=model-router`
|
|
41
|
+
* finds nothing even when the entry is there. Match on the message text.
|
|
29
42
|
*/
|
|
30
43
|
|
|
31
44
|
export interface PluginLogger {
|
|
32
45
|
warn(message: string, extra?: Record<string, unknown>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Await every post still in flight, so a shutting-down process does not drop
|
|
48
|
+
* warnings it already decided to emit. Never rejects: a failing flush must
|
|
49
|
+
* not be the thing that breaks teardown.
|
|
50
|
+
*/
|
|
51
|
+
flush(): Promise<void>;
|
|
33
52
|
}
|
|
34
53
|
|
|
35
54
|
/** The service tag on every entry, so entries are greppable by origin. */
|
|
@@ -86,9 +105,15 @@ export function createPluginLogger(client?: unknown): PluginLogger {
|
|
|
86
105
|
warn(message) {
|
|
87
106
|
console.warn(`${CONSOLE_PREFIX} ${message}`);
|
|
88
107
|
},
|
|
108
|
+
// console.warn is synchronous, so there is never anything to wait for.
|
|
109
|
+
flush: () => Promise.resolve(),
|
|
89
110
|
};
|
|
90
111
|
}
|
|
91
112
|
|
|
113
|
+
// Posts still in flight. Entries remove themselves once settled, so this
|
|
114
|
+
// stays bounded on a long-lived server rather than growing for its lifetime.
|
|
115
|
+
const inFlight = new Set<Promise<void>>();
|
|
116
|
+
|
|
92
117
|
return {
|
|
93
118
|
warn(message, extra) {
|
|
94
119
|
const toConsole = () => console.warn(`${CONSOLE_PREFIX} ${message}`);
|
|
@@ -112,11 +137,20 @@ export function createPluginLogger(client?: unknown): PluginLogger {
|
|
|
112
137
|
// Fire-and-forget: never await, but never leave a rejection unhandled
|
|
113
138
|
// either, and do not lose the diagnostic when the post fails — whether it
|
|
114
139
|
// fails by rejecting or by resolving with an error. See (2) above.
|
|
115
|
-
void Promise.resolve(result)
|
|
116
|
-
.then((
|
|
117
|
-
if (isErrorResult(
|
|
140
|
+
const settled: Promise<void> = Promise.resolve(result)
|
|
141
|
+
.then((value) => {
|
|
142
|
+
if (isErrorResult(value)) toConsole();
|
|
118
143
|
})
|
|
119
144
|
.catch(toConsole);
|
|
145
|
+
// Tracked so `flush` can wait for it. `settled` already absorbs its own
|
|
146
|
+
// failures, so nothing here can reject. See (3) above.
|
|
147
|
+
inFlight.add(settled);
|
|
148
|
+
void settled.finally(() => {
|
|
149
|
+
inFlight.delete(settled);
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
async flush() {
|
|
153
|
+
await Promise.allSettled([...inFlight]);
|
|
120
154
|
},
|
|
121
155
|
};
|
|
122
156
|
}
|
package/tiers.json
CHANGED
|
@@ -203,6 +203,47 @@
|
|
|
203
203
|
]
|
|
204
204
|
}
|
|
205
205
|
},
|
|
206
|
+
"zai": {
|
|
207
|
+
"fast": {
|
|
208
|
+
"model": "zai-coding-plan/glm-4.7",
|
|
209
|
+
"costRatio": 1,
|
|
210
|
+
"description": "GLM-4.7 for read-only exploration, search, and simple lookups (requires the Z.AI Coding Plan; token-spend ratios are estimates, not price differences)",
|
|
211
|
+
"steps": 30,
|
|
212
|
+
"whenToUse": [
|
|
213
|
+
"Codebase exploration and search",
|
|
214
|
+
"Simple file reads and listing",
|
|
215
|
+
"Grep/glob operations",
|
|
216
|
+
"Quick lookups and research"
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
"medium": {
|
|
220
|
+
"model": "zai-coding-plan/glm-5.3",
|
|
221
|
+
"variant": "high",
|
|
222
|
+
"costRatio": 3,
|
|
223
|
+
"description": "GLM-5.3 at high effort for implementation, refactoring, and tests (requires the Z.AI Coding Plan; costRatio is an estimated token-spend multiplier, not a price difference)",
|
|
224
|
+
"steps": 50,
|
|
225
|
+
"whenToUse": [
|
|
226
|
+
"Feature implementation",
|
|
227
|
+
"Refactoring",
|
|
228
|
+
"Writing tests",
|
|
229
|
+
"Code review",
|
|
230
|
+
"Bug fixes"
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"heavy": {
|
|
234
|
+
"model": "zai-coding-plan/glm-5.3",
|
|
235
|
+
"variant": "max",
|
|
236
|
+
"costRatio": 6,
|
|
237
|
+
"description": "GLM-5.3 at max effort for architecture, complex debugging, and security (requires the Z.AI Coding Plan; costRatio is an estimated token-spend multiplier, not a price difference)",
|
|
238
|
+
"steps": 120,
|
|
239
|
+
"whenToUse": [
|
|
240
|
+
"Architecture decisions",
|
|
241
|
+
"Complex debugging (after 2+ failures)",
|
|
242
|
+
"Security review",
|
|
243
|
+
"Performance optimization"
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
},
|
|
206
247
|
"hybrid": {
|
|
207
248
|
"fast": {
|
|
208
249
|
"model": "anthropic/claude-haiku-4-5",
|
|
@@ -387,6 +428,11 @@
|
|
|
387
428
|
"openai",
|
|
388
429
|
"anthropic",
|
|
389
430
|
"github-copilot"
|
|
431
|
+
],
|
|
432
|
+
"zai-coding-plan": [
|
|
433
|
+
"anthropic",
|
|
434
|
+
"openai",
|
|
435
|
+
"google"
|
|
390
436
|
]
|
|
391
437
|
}
|
|
392
438
|
},
|