opencode-model-router 1.5.0 → 1.7.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 +357 -0
- package/README.md +220 -19
- package/package.json +3 -2
- package/src/commands/output.ts +342 -0
- package/src/guard/enforce.ts +14 -1
- package/src/guard/guards.ts +26 -0
- package/src/guard/store.ts +46 -3
- package/src/index.ts +429 -347
- package/src/router/agent-options.ts +127 -0
- package/src/router/catalog.ts +457 -0
- package/src/router/config.ts +335 -48
- package/src/router/idle-sweep.ts +35 -0
- package/src/router/jsonc.ts +1 -0
- package/src/router/prompts.ts +72 -0
- package/src/router/protocol.ts +1 -1
- package/src/router/sessions.ts +299 -27
- package/src/router/subagents.ts +85 -0
- package/src/telemetry/trajectory.ts +48 -1
- package/src/verify/checker.ts +47 -1
- package/src/verify/deterministic.ts +13 -5
- package/src/verify/dispatch.ts +27 -2
- package/src/verify/gate.ts +25 -1
- package/src/verify/paths.ts +29 -0
- package/src/verify/timeout.ts +93 -0
- package/src/verify/wiring.ts +267 -0
- package/tiers.json +79 -6
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
|
|
5
|
+
An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,089–4,659 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
|
|
15
|
+
Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,089 characters; a Claude orchestrator receives 3,861 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.
|
|
@@ -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
|
|
68
|
+
All of this adds 3,089 characters for a non-Claude orchestrator or 3,861 characters for a Claude orchestrator (roughly 770–1,075 tokens at 3.6–4.0 characters per token).
|
|
69
69
|
|
|
70
70
|
## Cost simulation
|
|
71
71
|
|
|
@@ -114,7 +114,7 @@ Task distribution: 18 exploration (60%), 10 implementation (33%), 2 architecture
|
|
|
114
114
|
|
|
115
115
|
## How it works
|
|
116
116
|
|
|
117
|
-
On every message, the plugin injects a
|
|
117
|
+
On every message, the plugin injects a 3,089-character routing protocol. A Claude orchestrator receives 3,861 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.
|
|
118
118
|
|
|
119
119
|
What the orchestrator sees (Anthropic preset, normal mode):
|
|
120
120
|
|
|
@@ -166,7 +166,7 @@ With router → split:
|
|
|
166
166
|
| Cross-provider fallback | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
167
167
|
| Cost ratio awareness | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
168
168
|
| Plan annotation with tiers | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
169
|
-
| Measured prompt overhead:
|
|
169
|
+
| Measured prompt overhead: 3,089–4,659 chars | ✅ | — | ❌ | ❌ | ❌ |
|
|
170
170
|
|
|
171
171
|
**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.
|
|
172
172
|
|
|
@@ -298,6 +298,15 @@ Restart opencode after adding a new preset so its tier subagents get registered.
|
|
|
298
298
|
|
|
299
299
|
> **`activePreset` / `activeMode` / `enforcement.mode` in an override file are _defaults_.** Runtime selections — `/preset`, `/budget`, `/router enforce` — are persisted to the state file (`~/.config/opencode/opencode-model-router.state.json`), which is applied **after** the override files and therefore wins. So the override's `activePreset` takes effect until you switch at runtime; if it ever "isn't taking", it's because a past `/preset` left a value in the state file — run `/preset <name>` again or delete that file. (The state file is machine-written, so the plugin never rewrites your hand-authored, commented override file.)
|
|
300
300
|
|
|
301
|
+
### Keeping models current
|
|
302
|
+
|
|
303
|
+
You do not have to wait on a plugin release when providers ship new models. opencode already resolves a live model catalog (models.dev plus your configured and authenticated providers), and the plugin reads it directly. No external fetch, no hardcoded list.
|
|
304
|
+
|
|
305
|
+
- **`/router models [provider]`** lists the valid model ids for your configured providers, each annotated with the provider's default and any `deprecated`, `alpha` or `beta` status. Copy an id straight into an overrides file.
|
|
306
|
+
- **Validation.** Bare `/router` checks the active preset's tier models against the catalog and reports any that are missing or deprecated, with the closest valid suggestions. A stale id surfaces immediately instead of failing silently on every subagent dispatch. The same check is logged once per session to the plugin console.
|
|
307
|
+
|
|
308
|
+
This is report-only. The plugin never changes your models for you: it tells you what is available and what to change, and you set it in the overrides file.
|
|
309
|
+
|
|
301
310
|
### Advanced: edit the bundled `tiers.json` directly
|
|
302
311
|
|
|
303
312
|
For an npm install, `tiers.json` is **inside the cached package directory**, not your `~/.config/opencode/` folder — typically:
|
|
@@ -310,28 +319,28 @@ For an npm install, `tiers.json` is **inside the cached package directory**, not
|
|
|
310
319
|
|
|
311
320
|
### Presets
|
|
312
321
|
|
|
313
|
-
The plugin ships with
|
|
322
|
+
The plugin ships with six presets (switch with `/preset <name>`):
|
|
314
323
|
|
|
315
324
|
**anthropic** (default):
|
|
316
325
|
| Tier | Model | Cost ratio |
|
|
317
326
|
|------|-------|-----------|
|
|
318
327
|
| @fast | `anthropic/claude-haiku-4-5` | 1x |
|
|
319
|
-
| @medium | `anthropic/claude-sonnet-4-
|
|
320
|
-
| @heavy | `anthropic/claude-opus-4-
|
|
328
|
+
| @medium | `anthropic/claude-sonnet-4-6` (max) | 5x |
|
|
329
|
+
| @heavy | `anthropic/claude-opus-4-8` (max) | 20x |
|
|
321
330
|
|
|
322
331
|
**openai**:
|
|
323
332
|
| Tier | Model | Cost ratio |
|
|
324
333
|
|------|-------|-----------|
|
|
325
|
-
| @fast | `openai/gpt-5.
|
|
326
|
-
| @medium | `openai/gpt-5.
|
|
327
|
-
| @heavy | `openai/gpt-5.
|
|
334
|
+
| @fast | `openai/gpt-5.4-mini-fast` | 1x |
|
|
335
|
+
| @medium | `openai/gpt-5.5-fast` (high) | 5x |
|
|
336
|
+
| @heavy | `openai/gpt-5.5-fast` (xhigh) | 20x |
|
|
328
337
|
|
|
329
338
|
**github-copilot**:
|
|
330
339
|
| Tier | Model | Cost ratio |
|
|
331
340
|
|------|-------|-----------|
|
|
332
|
-
| @fast | `github-copilot/claude-haiku-4
|
|
333
|
-
| @medium | `github-copilot/claude-sonnet-4
|
|
334
|
-
| @heavy | `github-copilot/claude-opus-4
|
|
341
|
+
| @fast | `github-copilot/claude-haiku-4.5` | 1x |
|
|
342
|
+
| @medium | `github-copilot/claude-sonnet-4.6` | 5x |
|
|
343
|
+
| @heavy | `github-copilot/claude-opus-4.6` | 20x |
|
|
335
344
|
|
|
336
345
|
**google**:
|
|
337
346
|
| Tier | Model | Cost ratio |
|
|
@@ -340,6 +349,44 @@ The plugin ships with four presets (switch with `/preset <name>`):
|
|
|
340
349
|
| @medium | `google/gemini-2.5-pro` | 5x |
|
|
341
350
|
| @heavy | `google/gemini-3-pro-preview` | 20x |
|
|
342
351
|
|
|
352
|
+
**hybrid** — Anthropic for exploration and heavy analysis, OpenAI for implementation:
|
|
353
|
+
| Tier | Model | Cost ratio |
|
|
354
|
+
|------|-------|-----------|
|
|
355
|
+
| @fast | `anthropic/claude-haiku-4-5` | 1x |
|
|
356
|
+
| @medium | `openai/gpt-5.5-fast` (high) | 5x |
|
|
357
|
+
| @heavy | `anthropic/claude-opus-4-8` (max) | 20x |
|
|
358
|
+
|
|
359
|
+
**fable-effort** — one model, three reasoning depths (see [per-tier `effort`](#per-tier-effort)):
|
|
360
|
+
| Tier | Model | Effort | Cost ratio |
|
|
361
|
+
|------|-------|--------|-----------|
|
|
362
|
+
| @fast | `anthropic/claude-fable-5` | `low` | 1x |
|
|
363
|
+
| @medium | `anthropic/claude-fable-5` | `high` | 3x |
|
|
364
|
+
| @heavy | `anthropic/claude-fable-5` | `xhigh` | 6x |
|
|
365
|
+
|
|
366
|
+
Because the model string is identical across tiers, escalating a task keeps the prompt
|
|
367
|
+
cache warm. The cost ratios are estimated token-spend multipliers, not price differences.
|
|
368
|
+
|
|
369
|
+
### Per-tier `effort`
|
|
370
|
+
|
|
371
|
+
Any tier may set `effort`: `low`, `medium`, `high`, `xhigh`, or `max`. Precedence,
|
|
372
|
+
highest first:
|
|
373
|
+
|
|
374
|
+
1. `thinking.budgetTokens` (Anthropic) / `reasoning.effort` (OpenAI) — the explicit,
|
|
375
|
+
provider-specific setting always wins, and a one-time warning names the tier.
|
|
376
|
+
2. `effort`.
|
|
377
|
+
|
|
378
|
+
**Unset means unset**: no `effort` (and no `reasoning_effort`) key is registered at all.
|
|
379
|
+
|
|
380
|
+
| Model family | Registered as | Caveats |
|
|
381
|
+
|---|---|---|
|
|
382
|
+
| Anthropic | `options.effort`, incl. `xhigh`/`max` | 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. |
|
|
383
|
+
| OpenAI | `options.reasoning_effort` | Supports only `low`/`medium`/`high`; `xhigh` and `max` are downgraded to `high` with a warning. |
|
|
384
|
+
| Other (Google, …) | nothing | Dropped with a warning — no known mapping. Detection is by model family, not provider prefix, so Copilot-proxied ids (`github-copilot/gpt-4o`, `github-copilot/claude-sonnet-4`) take their family's knob above. |
|
|
385
|
+
|
|
386
|
+
An out-of-set value in `tiers.json` fails validation at load; one that arrives any other
|
|
387
|
+
way is ignored with a single warning. Full detail in
|
|
388
|
+
[docs/CONFIG_REFERENCE.md](docs/CONFIG_REFERENCE.md#per-tier-effort).
|
|
389
|
+
|
|
343
390
|
### Routing modes
|
|
344
391
|
|
|
345
392
|
Switch with `/budget <mode>`. Mode is persisted across restarts.
|
|
@@ -443,10 +490,36 @@ Subagents carry a cap on their own read-only tool calls (grep/read/glob/ls) per
|
|
|
443
490
|
The orchestrator can override any subagent's cap per dispatch by including a directive in the `Task` prompt:
|
|
444
491
|
|
|
445
492
|
- `CAP:N` — tighten or loosen to N calls (e.g., `CAP:3` for a focused lookup).
|
|
446
|
-
- `CAP:none` — disable the numeric cap entirely (used in `quality` mode and for `@heavy` in `deep` mode).
|
|
493
|
+
- `CAP:none` — disable the numeric cap entirely (used in `quality` mode and for `@heavy` in `deep` mode). **`CAP:none` is honored only when the dispatch prompt also contains a `reason:` line.** An unjustified `CAP:none` silently falls back to the tier baseline — uncapped work must be justified in the dispatch, not just requested. `CAP:N` is unaffected.
|
|
447
494
|
|
|
448
495
|
Omitting the directive falls back to the tier baseline. Subagents may **exceed** their cap with a 1-line `reason:` in the return (target, not hard block).
|
|
449
496
|
|
|
497
|
+
#### Resumed dispatches
|
|
498
|
+
|
|
499
|
+
A "resume" is a second `chat.message` to a session already tracked at the **same tier** — how an opencode `task_id` resume (re-prompting an existing subagent session instead of spawning a new one) reaches the plugin. On resume:
|
|
500
|
+
|
|
501
|
+
- the **per-dispatch cap resets** (`[cap: 1/8]` again) — the resumed round gets a full budget, and re-reads the `CAP:` directive from the new dispatch text, gate included;
|
|
502
|
+
- the **redundancy map persists** — re-reading a file you already read in the previous round still emits `[⚠ REDUNDANT: … call #1]`;
|
|
503
|
+
- **cumulative usage persists** and is bounded by a ceiling of `cap × 3` (the current dispatch's cap). Exceeding it appends:
|
|
504
|
+
|
|
505
|
+
```
|
|
506
|
+
[cap: 2/3]
|
|
507
|
+
[⚠ CUMULATIVE BUDGET EXCEEDED: 10/9 across 4 dispatches — return now]
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
The ceiling follows the *current* cap, so a tighter resumed cap tightens the ceiling. `CAP:none` has no per-dispatch budget to derive from and therefore no cumulative ceiling. A **retry** (new session, e.g. an escalation to another tier) is not a resume: it gets fresh counters and an empty redundancy map. A session evicted by the idle-TTL sweep also comes back fresh.
|
|
511
|
+
|
|
512
|
+
The sweep exists so per-session bookkeeping does not grow without bound in a long-running
|
|
513
|
+
opencode process. A session is evicted once it has been idle for **1 hour**; every mutating
|
|
514
|
+
entry point refreshes its stamp, and a tool call refreshes at *start* so a single long call
|
|
515
|
+
cannot age out mid-flight. There are no timers: the sweep runs opportunistically off chat
|
|
516
|
+
activity, throttled to at most once every **5 minutes**, and covers the four session-keyed
|
|
517
|
+
stores (subagent sessions, guard state, trajectory telemetry, and changed-file tracking).
|
|
518
|
+
|
|
519
|
+
The same accounting exists at the hard-guard layer: `guard.budget` resets per dispatch, with a cumulative ceiling of `guard.budget × 3` enforced as `cumulative_iteration_cap`.
|
|
520
|
+
|
|
521
|
+
**If you never resume a subagent session, nothing changes** — a first dispatch's cumulative count equals its per-dispatch count, so the ceiling is unreachable and every banner is byte-identical to before.
|
|
522
|
+
|
|
450
523
|
#### Runtime enforcement (subagents only)
|
|
451
524
|
|
|
452
525
|
Prompt-level rules alone are unreliable: many models (including strong ones like Opus 4.7) ignore "please stop at N reads" and loop on reconnaissance for tens of minutes. To address this, the plugin tracks read-only tool calls per subagent session and **appends a banner to every read-only tool result** via the `tool.execute.after` hook. The subagent sees this banner inside the tool's own response text — not as advisory system prompt noise — which makes it very hard to ignore.
|
|
@@ -539,9 +612,51 @@ Each tier (`@fast`, `@medium`, `@heavy`) has a system prompt that describes its
|
|
|
539
612
|
**Resolution order per tier:**
|
|
540
613
|
|
|
541
614
|
1. If the preset's tier defines `"prompt": "..."` inline → use it (per-tier override).
|
|
542
|
-
2. Otherwise → fall back to `tierPrompts[<tierName>]`.
|
|
615
|
+
2. Otherwise → fall back to the default for the tier's **prompt style**: `tierPromptsGoalOriented[<tierName>]` (or the built-in goal-oriented default) when the tier resolves to `goal-oriented`, else `tierPrompts[<tierName>]`.
|
|
543
616
|
3. If neither is set → the tier registers without a system prompt.
|
|
544
617
|
|
|
618
|
+
Two wordings of every default prompt ship: the enumerated `tierPrompts` above, and a shorter goal-oriented set. Which one a tier gets is decided by `promptStyle`, which defaults to `auto` (goal-oriented for strong models). See [Prompt styles](docs/CONFIG_REFERENCE.md#prompt-styles-promptstyle) in the config reference — including which shipped presets are affected.
|
|
619
|
+
|
|
620
|
+
To replace a built-in goal-oriented prompt, set `tierPromptsGoalOriented` in the overrides
|
|
621
|
+
file. It is the goal-oriented twin of `tierPrompts`: an entry replaces the built-in default
|
|
622
|
+
for that tier name only, and tiers you do not list keep theirs.
|
|
623
|
+
|
|
624
|
+
```jsonc
|
|
625
|
+
{
|
|
626
|
+
// Only affects tiers that resolve to the goal-oriented style.
|
|
627
|
+
"tierPromptsGoalOriented": {
|
|
628
|
+
"medium": "You are @medium. Ship the change described in the dispatch, match the surrounding code, and return the files you touched plus the verification you ran."
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### `modelGenerations`
|
|
634
|
+
|
|
635
|
+
`modelGenerations` holds shared, case-insensitive substring patterns matched against a
|
|
636
|
+
tier's model ID. Two lists exist:
|
|
637
|
+
|
|
638
|
+
| List | Default | What it drives |
|
|
639
|
+
|------|---------|----------------|
|
|
640
|
+
| `strong` | `["claude-fable-5", "claude-mythos-5", "opus-4-8"]` | `promptStyle: "auto"` resolution — a match resolves to `goal-oriented`, everything else to `prescriptive` (`isStrongModel` in `src/router/prompts.ts`). |
|
|
641
|
+
| `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. |
|
|
642
|
+
|
|
643
|
+
Only `strong` is read at match time, and setting it replaces the default list outright
|
|
644
|
+
rather than extending it — include the built-in patterns you still want. Claude-specific
|
|
645
|
+
prompt prefixes and the anti-narration detector do **not** use these lists; they match the
|
|
646
|
+
model ID directly (`isClaudeModel` in `src/router/protocol.ts`).
|
|
647
|
+
|
|
648
|
+
```jsonc
|
|
649
|
+
{
|
|
650
|
+
"modelGenerations": {
|
|
651
|
+
// Keep the shipped patterns and add a locally-hosted strong model.
|
|
652
|
+
"strong": ["claude-fable-5", "claude-mythos-5", "opus-4-8", "my-org/big-coder"]
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
See [Prompt styles](docs/CONFIG_REFERENCE.md#prompt-styles-promptstyle) in the config
|
|
658
|
+
reference for the full description.
|
|
659
|
+
|
|
545
660
|
**When to customize:** if a specific provider/model in a preset needs different instructions (e.g. Gemini-specific tool format, tighter/looser caps for a weaker local model), add `"prompt": "..."` on that tier only. All other presets keep using the global.
|
|
546
661
|
|
|
547
662
|
```json
|
|
@@ -636,11 +751,45 @@ When `antiNarration` is enabled, the detector runs for all models (not only Clau
|
|
|
636
751
|
| `costRatio` | number | Relative cost (1 = cheapest). Shown in prompt. |
|
|
637
752
|
| `thinking` | object | Anthropic thinking: `{ "budgetTokens": 10000 }` |
|
|
638
753
|
| `reasoning` | object | OpenAI reasoning: `{ "effort": "high", "summary": "detailed" }` |
|
|
754
|
+
| `effort` | string | Provider-agnostic reasoning effort: `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`. See [Per-tier `effort`](#per-tier-effort). |
|
|
755
|
+
| `color` | string | Optional agent colour passed through to the opencode agent registration. |
|
|
639
756
|
| `description` | string | Shown in `/tiers` output |
|
|
640
757
|
| `steps` | number | Max agent turns |
|
|
641
|
-
| `prompt` | string | Optional per-tier system prompt override. Falls back to
|
|
758
|
+
| `prompt` | string | Optional per-tier system prompt override. Falls back to the style-appropriate default when omitted. |
|
|
759
|
+
| `promptStyle` | string | `"prescriptive"`, `"goal-oriented"` or `"auto"` (default). Picks which default prompt the tier gets; ignored when `prompt` is set. |
|
|
642
760
|
| `whenToUse` | string[] | Use cases (shown in `/tiers`, not in system prompt) |
|
|
643
761
|
|
|
762
|
+
### Routing your own subagents (`subagentTiers`, opt-in)
|
|
763
|
+
|
|
764
|
+
If you already have custom subagents (`.opencode/agents/**`), they do **not** get routed by default. An agent that declares no `model` inherits the model of whoever invoked it, usually your orchestrator, so a cheap read-only helper quietly runs at orchestrator prices.
|
|
765
|
+
|
|
766
|
+
`subagentTiers` maps your agent names to tiers, and the plugin repoints them at the active preset's models:
|
|
767
|
+
|
|
768
|
+
```jsonc
|
|
769
|
+
{
|
|
770
|
+
"subagentTiers": {
|
|
771
|
+
"ContextScout": "fast",
|
|
772
|
+
"CodeReviewer": "medium",
|
|
773
|
+
"SecurityReviewer": "heavy"
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
The point of doing this here rather than in `opencode.json` is that these agents then **follow `/preset`**. Switch to `openai` and `ContextScout` moves to that preset's fast model along with `@fast`. No model IDs live in your agent files, and a committed project overrides file gives the whole team the same routing.
|
|
779
|
+
|
|
780
|
+
**Getting the names right.** The key is opencode's agent name: the frontmatter `name:` field when the agent declares one, otherwise the file's path-derived name (`agents/team/helper.md` becomes `team/helper`). Frontmatter wins, so an agent in `subagents/core/contextscout.md` with `name: ContextScout` is keyed `ContextScout`. Matching is case-sensitive.
|
|
781
|
+
|
|
782
|
+
**Rules, all deliberate:**
|
|
783
|
+
|
|
784
|
+
- **Opt-in.** No map, or an empty one, and nothing is touched.
|
|
785
|
+
- **The map wins over the agent's own `model`.** This is the point, and it is what lets you delete hardcoded model IDs from agent files. If you want an agent to keep its pinned model, leave it out of the map.
|
|
786
|
+
- **List subagents only.** Primary agents are the orchestrator, so pinning one to a tier defeats the routing. Agents already registered with a non-`subagent` mode are skipped, but a *markdown* agent's mode is not visible when the map is applied, so a primary agent listed there would still be repointed.
|
|
787
|
+
- **Unknown tier names are skipped**, not fatal. A map written for a preset that defines a tier this one does not must never break startup.
|
|
788
|
+
- **Tier names are never overwritten.** An entry keyed `fast`/`medium`/`heavy` is ignored so it cannot clobber the plugin's own agents.
|
|
789
|
+
- **Variants are set explicitly.** If the target tier has no `variant`, any variant already on the agent is removed rather than inherited. An inherited variant from another provider fails at dispatch, not at load.
|
|
790
|
+
|
|
791
|
+
Anything not listed is left exactly as opencode built it.
|
|
792
|
+
|
|
644
793
|
### Fallback
|
|
645
794
|
|
|
646
795
|
Defines provider fallback order when a delegated task fails:
|
|
@@ -683,6 +832,53 @@ Advisory is the default. To change the level:
|
|
|
683
832
|
|
|
684
833
|
> Enforcement applies to subagent/delegate sessions only. The orchestrator session is never hard-blocked.
|
|
685
834
|
|
|
835
|
+
**Per-tier override.** `enforcement.perTier` maps a tier name to `off`, `advisory` or
|
|
836
|
+
`enforced` and wins over the global `mode` for delegations to that tier — useful to keep
|
|
837
|
+
`@fast` advisory while `@medium` and `@heavy` are enforced:
|
|
838
|
+
|
|
839
|
+
```jsonc
|
|
840
|
+
{
|
|
841
|
+
"enforcement": {
|
|
842
|
+
"mode": "enforced",
|
|
843
|
+
"perTier": { "fast": "advisory" }
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
#### Time-boxes
|
|
849
|
+
|
|
850
|
+
Three ceilings bound the verification pipeline so a stuck model cannot hang a delegation
|
|
851
|
+
forever. All are integers in milliseconds, live under `enforcement.verify`, and ship
|
|
852
|
+
explicitly in `tiers.json`:
|
|
853
|
+
|
|
854
|
+
| Key | Bundled default | Bounds |
|
|
855
|
+
|-----|-----------------|--------|
|
|
856
|
+
| `delegateTimeoutMs` | `600000` (10 min) | One producer turn. |
|
|
857
|
+
| `graderTimeoutMs` | `60000` (1 min) | One grader turn. |
|
|
858
|
+
| `gateBudgetMs` | `90000` (90 s) | The whole acceptance gate. |
|
|
859
|
+
|
|
860
|
+
Each budget is per **ladder attempt**, not per delegation: a fast → medium → heavy
|
|
861
|
+
escalation gives every attempt its own fresh clock. On expiry the child session is
|
|
862
|
+
cancelled for real via `session.abort` rather than left running, and the attempt is
|
|
863
|
+
recorded as failed so the ladder advances — an expired budget never yields a fabricated
|
|
864
|
+
pass, only an honest `status: unmet`.
|
|
865
|
+
|
|
866
|
+
Raise a ceiling rather than removing it; `0` and negative values are rejected by
|
|
867
|
+
`validateConfig`, not read as "no timeout".
|
|
868
|
+
|
|
869
|
+
```jsonc
|
|
870
|
+
{
|
|
871
|
+
"enforcement": {
|
|
872
|
+
"verify": {
|
|
873
|
+
// A slow local model needs longer than the 10-minute default.
|
|
874
|
+
"delegateTimeoutMs": 1800000
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
Full field notes are in [docs/CONFIG_REFERENCE.md](docs/CONFIG_REFERENCE.md).
|
|
881
|
+
|
|
686
882
|
### Deep-dive documentation
|
|
687
883
|
|
|
688
884
|
- `docs/ENFORCEMENT.md` — architecture, hook wiring, session lifecycle
|
|
@@ -697,14 +893,16 @@ Advisory is the default. To change the level:
|
|
|
697
893
|
|
|
698
894
|
| Command | Description |
|
|
699
895
|
|---------|-------------|
|
|
700
|
-
| `/tiers` | Show active tier configuration, models, and
|
|
896
|
+
| `/tiers` | Show active tier configuration, models, rules, and each tier's resolved prompt style |
|
|
701
897
|
| `/preset` | List available presets |
|
|
702
898
|
| `/preset <name>` | Switch preset (e.g., `/preset openai`) |
|
|
703
899
|
| `/budget` | Show available modes and which is active |
|
|
704
900
|
| `/budget <mode>` | Switch routing mode (`normal`, `budget`, `quality`, `deep`) |
|
|
705
901
|
| `/annotate-plan [path]` | Annotate a plan file with `[tier:X]` tags for each step |
|
|
706
902
|
| `/router overrides` | Show the global + project override file paths and merge precedence |
|
|
903
|
+
| `/router models [provider]` | List valid model ids from your configured providers (with defaults and deprecated flags) |
|
|
707
904
|
| `/router enforce <off\|advisory\|enforced>` | Set delegation-enforcement mode (persisted) |
|
|
905
|
+
| `/router` | With no subcommand — or an unrecognized one — prints the `/router` help and the current enforcement mode |
|
|
708
906
|
| `/bypass [on\|off]` | Toggle the router off/on for the session |
|
|
709
907
|
|
|
710
908
|
## Plan annotation
|
|
@@ -731,12 +929,15 @@ After `/annotate-plan`:
|
|
|
731
929
|
|
|
732
930
|
## Token overhead
|
|
733
931
|
|
|
734
|
-
Measured with the bundled Anthropic preset in normal mode, the routing protocol is
|
|
932
|
+
Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,089 characters for a non-Claude orchestrator. A Claude orchestrator receives 3,861 characters after its authority prefix, or 4,659 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.
|
|
933
|
+
|
|
934
|
+
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.
|
|
735
935
|
|
|
736
936
|
| Version | Measured overhead | Features |
|
|
737
937
|
|---------|-------------------|----------|
|
|
738
938
|
| Before v1.4.0 | Earlier README token estimates were not measured and were inaccurate | Routing, caps, and enforcement evolved across releases |
|
|
739
939
|
| v1.4.0 | 2,970–4,540 chars (~740–1,260 tokens at 3.6–4.0 chars/token) | Trimmed protocol; path-dependent Claude and enforcement prefixes |
|
|
940
|
+
| v1.6.0 | 3,089–4,659 chars (~770–1,295 tokens at 3.6–4.0 chars/token) | +119 chars on every path: `CAP:none` now has to be justified by a `reason:` line, and the protocol says so twice (rule 7 and the per-dispatch paragraph) |
|
|
740
941
|
|
|
741
942
|
## Requirements
|
|
742
943
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-model-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"src/",
|
|
42
42
|
"tiers.json",
|
|
43
43
|
"LICENSE",
|
|
44
|
-
"README.md"
|
|
44
|
+
"README.md",
|
|
45
|
+
"CHANGELOG.md"
|
|
45
46
|
],
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@opencode-ai/plugin": ">=1.0.0"
|