opencode-model-router 1.10.0 → 1.11.1
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 +43 -0
- package/README.md +20 -8
- package/package.json +2 -2
- package/src/guard/guards.ts +9 -0
- package/src/verify/dispatch.ts +20 -3
- package/tiers.json +46 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,49 @@ 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.1] - 2026-08-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Community health files.** `CONTRIBUTING.md`, `SECURITY.md`, `CODE_OF_CONDUCT.md`, a
|
|
13
|
+
pull request template, and a bug report form. The contributing guide writes down the
|
|
14
|
+
parts that are easy to miss from outside: golden snapshots are parameterized over every
|
|
15
|
+
preset and must be regenerated, model refs are only format-validated so the provider id
|
|
16
|
+
has to be checked against the models.dev catalog, and a new preset also needs a
|
|
17
|
+
`fallback.global` chain plus the README and config-reference counts.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- **Two polynomial-ReDoS findings on LLM-influenced input.** CodeQL flagged the guard's
|
|
22
|
+
ad-hoc script detection (`isSelfScript`) and the subagent task-result parser. The guard
|
|
23
|
+
now caps the command it scans at 20k characters and fails closed above that: truncating
|
|
24
|
+
would let padding push a redirect past the scan window, and a shell command that long is
|
|
25
|
+
itself a signal. The task-result parser dropped its regex entirely for a linear `indexOf`
|
|
26
|
+
scan — even a lazy capture backtracks polynomially on repeated open tags with no close —
|
|
27
|
+
keeping the same semantics: first open tag, first close tag after it, case-insensitive,
|
|
28
|
+
trimmed at the use site, raw output as the fallback.
|
|
29
|
+
|
|
30
|
+
## [1.11.0] - 2026-08-24
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- **A `zai` preset, routing GLM models through the Z.AI Coding Plan.** `@fast` takes
|
|
35
|
+
`glm-4.7`, `@medium` and `@heavy` share `glm-5.3` at `high` and `max` effort. Contributed
|
|
36
|
+
by @MarCYK in
|
|
37
|
+
[#37](https://github.com/marco-jardim/opencode-model-router/pull/37), closing
|
|
38
|
+
[#18](https://github.com/marco-jardim/opencode-model-router/issues/18).
|
|
39
|
+
|
|
40
|
+
Landed with three fixes on top. The preset originally named the `zai` provider, but
|
|
41
|
+
`glm-5.3` is not published under it in the models.dev catalog opencode resolves against
|
|
42
|
+
— it exists only under `zai-coding-plan`, whose reasoning options (`low`/`high`/`max`)
|
|
43
|
+
are also what make the `high` and `max` variants valid. All three tiers now point at
|
|
44
|
+
`zai-coding-plan/*` and say so in their descriptions, since the plan is a prerequisite.
|
|
45
|
+
`fallback.global` gained a `zai-coding-plan` chain, so a Z.AI outage now fails over
|
|
46
|
+
instead of dead-ending. And `costRatio` follows the `fable-effort` precedent — `1`/`3`/`6`
|
|
47
|
+
as an estimated token-spend multiplier, not a price difference, because `@medium` and
|
|
48
|
+
`@heavy` are the same model on a flat-rate plan where the catalog prices every model at
|
|
49
|
+
zero.
|
|
50
|
+
|
|
8
51
|
## [1.10.0] - 2026-08-20
|
|
9
52
|
|
|
10
53
|
Minor release. Config errors are caught at load instead of drifting to a later turn,
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# opencode-model-router
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-model-router)
|
|
4
|
+
|
|
3
5
|
> **Use the cheapest model that can do the job. Automatically.**
|
|
4
6
|
|
|
5
|
-
An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,
|
|
7
|
+
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
8
|
|
|
7
9
|
## Why it's different
|
|
8
10
|
|
|
@@ -12,7 +14,7 @@ Most AI coding tools give you one model for everything. You pay Opus prices to r
|
|
|
12
14
|
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
15
|
|
|
14
16
|
**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,
|
|
17
|
+
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
18
|
|
|
17
19
|
**Match task to tier using a configurable taxonomy.**
|
|
18
20
|
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 +35,7 @@ Every tier carries its `costRatio` (fast=1x, medium=5x, heavy=20x) injected into
|
|
|
33
35
|
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
36
|
|
|
35
37
|
**Multi-provider support with automatic fallback.**
|
|
36
|
-
|
|
38
|
+
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
39
|
|
|
38
40
|
**Plan annotation for long tasks.**
|
|
39
41
|
`/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 +67,7 @@ opencode-model-router injects a **delegation protocol** into the system prompt t
|
|
|
65
67
|
4. **Never over-qualify** — use the cheapest tier that can reliably handle the task
|
|
66
68
|
5. **Fallback** across providers when one fails
|
|
67
69
|
|
|
68
|
-
All of this adds 3,
|
|
70
|
+
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
71
|
|
|
70
72
|
## Understanding how it works
|
|
71
73
|
|
|
@@ -166,7 +168,7 @@ Task distribution: 18 exploration (60%), 10 implementation (33%), 2 architecture
|
|
|
166
168
|
|
|
167
169
|
## How it works
|
|
168
170
|
|
|
169
|
-
On every message, the plugin injects a 3,
|
|
171
|
+
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
172
|
|
|
171
173
|
What the orchestrator sees (Anthropic preset, normal mode):
|
|
172
174
|
|
|
@@ -218,7 +220,7 @@ With router → split:
|
|
|
218
220
|
| Cross-provider fallback | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
219
221
|
| Cost ratio awareness | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
220
222
|
| Plan annotation with tiers | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
221
|
-
| Measured prompt overhead: 3,
|
|
223
|
+
| Measured prompt overhead: 3,116–4,686 chars | ✅ | — | ❌ | ❌ | ❌ |
|
|
222
224
|
|
|
223
225
|
**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
226
|
|
|
@@ -371,7 +373,7 @@ For an npm install, `tiers.json` is **inside the cached package directory**, not
|
|
|
371
373
|
|
|
372
374
|
### Presets
|
|
373
375
|
|
|
374
|
-
The plugin ships with
|
|
376
|
+
The plugin ships with seven presets (switch with `/preset <name>`):
|
|
375
377
|
|
|
376
378
|
**anthropic** (default):
|
|
377
379
|
| Tier | Model | Cost ratio |
|
|
@@ -418,6 +420,16 @@ The plugin ships with six presets (switch with `/preset <name>`):
|
|
|
418
420
|
Because the model string is identical across tiers, escalating a task keeps the prompt
|
|
419
421
|
cache warm. The cost ratios are estimated token-spend multipliers, not price differences.
|
|
420
422
|
|
|
423
|
+
**zai** — GLM through the Z.AI Coding Plan (the `zai-coding-plan` provider, which is where `glm-5.3` lives):
|
|
424
|
+
| Tier | Model | Variant | Cost ratio |
|
|
425
|
+
|------|-------|---------|-----------|
|
|
426
|
+
| @fast | `zai-coding-plan/glm-4.7` | — | 1x |
|
|
427
|
+
| @medium | `zai-coding-plan/glm-5.3` | `high` | 3x |
|
|
428
|
+
| @heavy | `zai-coding-plan/glm-5.3` | `max` | 6x |
|
|
429
|
+
|
|
430
|
+
@medium and @heavy share one model, so — as with `fable-effort` — the cost ratios are
|
|
431
|
+
estimated token-spend multipliers, not price differences.
|
|
432
|
+
|
|
421
433
|
### Per-tier `effort`
|
|
422
434
|
|
|
423
435
|
Any tier may set `effort`: `low`, `medium`, `high`, `xhigh`, or `max`. Precedence,
|
|
@@ -983,7 +995,7 @@ After `/annotate-plan`:
|
|
|
983
995
|
|
|
984
996
|
## Token overhead
|
|
985
997
|
|
|
986
|
-
Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,
|
|
998
|
+
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
999
|
|
|
988
1000
|
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
1001
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-model-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
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,7 +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",
|
|
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",
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"license": "GPL-3.0-only",
|
package/src/guard/guards.ts
CHANGED
|
@@ -64,6 +64,13 @@ const INLINE_SCRIPT_RE = /\b(node|python3?|deno|bun)\s+-(e|c)\b/i;
|
|
|
64
64
|
const CAT_WRITE_RE = /\bcat\s+>\s*\S/i;
|
|
65
65
|
const BASH_C_RE = /\bbash\s+-c\b/i;
|
|
66
66
|
|
|
67
|
+
// Upper bound on the command length we are willing to scan with the regexes
|
|
68
|
+
// above. Several of them are polynomial on adversarial input (CodeQL
|
|
69
|
+
// js/polynomial-redos), and a shell command this long is itself a signal.
|
|
70
|
+
// Truncating instead would let padding push a redirect past the scan window, so
|
|
71
|
+
// an over-length command is flagged, not waved through.
|
|
72
|
+
const MAX_GUARD_SCAN_CHARS = 20_000;
|
|
73
|
+
|
|
67
74
|
// ---------------------------------------------------------------------------
|
|
68
75
|
// Write tools set (module-level)
|
|
69
76
|
// ---------------------------------------------------------------------------
|
|
@@ -113,6 +120,8 @@ export function isSelfScript(call: GuardCall, policy: GuardPolicy): boolean {
|
|
|
113
120
|
if (call.tool === "bash" || call.tool === "shell") {
|
|
114
121
|
const cmd = String(args.command ?? args.cmd ?? "");
|
|
115
122
|
if (!cmd) return false;
|
|
123
|
+
// Fail closed: too long to scan safely, so treat it as suspicious.
|
|
124
|
+
if (cmd.length > MAX_GUARD_SCAN_CHARS) return true;
|
|
116
125
|
return (
|
|
117
126
|
HEREDOC_RE.test(cmd) ||
|
|
118
127
|
REDIRECT_SCRIPT_RE.test(cmd) ||
|
package/src/verify/dispatch.ts
CHANGED
|
@@ -90,7 +90,24 @@ export function createChangedFileStore(options: ChangedFileStoreOptions = {}) {
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const
|
|
93
|
+
const TASK_RESULT_OPEN = "<task_result>";
|
|
94
|
+
const TASK_RESULT_CLOSE = "</task_result>";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Linear-time extraction of the <task_result> body. Any regex scan here, even a
|
|
98
|
+
* lazy one, backtracks polynomially on repeated open tags with no close
|
|
99
|
+
* (CodeQL js/polynomial-redos), so this walks the string with indexOf instead.
|
|
100
|
+
* Case-insensitive, like the regex it replaced: first open tag, then the first
|
|
101
|
+
* close tag after it. Returns null when either tag is missing.
|
|
102
|
+
*/
|
|
103
|
+
function extractTaskResult(raw: string): string | null {
|
|
104
|
+
const lower = raw.toLowerCase();
|
|
105
|
+
const start = lower.indexOf(TASK_RESULT_OPEN);
|
|
106
|
+
if (start === -1) return null;
|
|
107
|
+
const end = lower.indexOf(TASK_RESULT_CLOSE, start + TASK_RESULT_OPEN.length);
|
|
108
|
+
if (end === -1) return null;
|
|
109
|
+
return raw.slice(start + TASK_RESULT_OPEN.length, end);
|
|
110
|
+
}
|
|
94
111
|
|
|
95
112
|
/**
|
|
96
113
|
* Parse the built-in `task` tool's after-hook output: the child's final return
|
|
@@ -103,8 +120,8 @@ export function parseTaskResult(output: unknown): {
|
|
|
103
120
|
} {
|
|
104
121
|
const o = (output ?? {}) as Record<string, unknown>;
|
|
105
122
|
const raw = typeof o.output === "string" ? o.output : "";
|
|
106
|
-
const
|
|
107
|
-
const finalReturnText = (
|
|
123
|
+
const inner = extractTaskResult(raw);
|
|
124
|
+
const finalReturnText = (inner ?? raw).trim();
|
|
108
125
|
const meta = (o.metadata ?? {}) as Record<string, unknown>;
|
|
109
126
|
const childSessionID =
|
|
110
127
|
typeof meta.sessionId === "string"
|
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
|
},
|