opencode-model-router 1.14.0 → 2.0.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 CHANGED
@@ -5,6 +5,179 @@ 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
+ ## [Unreleased]
9
+
10
+ ## [2.0.0] - 2026-10-04
11
+
12
+ The router now runs on OpenCode v2 through a separate server entrypoint. **OpenCode v1
13
+ remains supported**: the callable v1 entrypoint and every config key are unchanged. The
14
+ major version marks the new host support and the updated bundled preset defaults. See
15
+ [the compatibility notes](docs/OPENCODE_V2.md).
16
+
17
+ ### Added
18
+
19
+ - OpenCode v2 compatibility through a separate server entrypoint, fixing the
20
+ `Expected object at ["default"]` plugin validation error while preserving the
21
+ callable v1 entrypoint. The adapter translates agent registration, commands,
22
+ prompts, tool guards and verification to v2's domain APIs, and uses native
23
+ subagents for producer/grader sessions. A subagent's `background` request is
24
+ kept unless the router verifies that dispatch. Only router-added instructions
25
+ are translated to v2 tool names. V2 tier options reach requests through the
26
+ context hook, not unused agent settings. V2 ≥2.0.21 removes temporary children
27
+ after use; 2.0.20 retains their history. Anti-narration warnings appear as
28
+ synthetic transcript entries. Includes an opt-in provider-backed v2 e2e smoke
29
+ adapted from @ChronosWS (Cliff Hudson). See
30
+ [the compatibility notes](docs/OPENCODE_V2.md).
31
+ - **Behavior note:** on v2, graders send no temperature (the provider default
32
+ applies, not `graderTemperature`) unless the exact `provider/model` is listed in
33
+ `enforcement.verify.graderTemperatureModels` (reported by @ChronosWS).
34
+
35
+ ### Changed
36
+
37
+ - Bundled presets updated: `anthropic` fast → Sonnet 5.5 low, medium → Sonnet
38
+ 5.5 medium (was Opus 5.5 low); `openai` medium → `gpt-6.1-sol-fast` xhigh;
39
+ `hybrid` fast → Luna medium, medium → Astra high, heavy → Opus 5.5 xhigh
40
+ (was Fable 5.1 max). The orchestrator prompt grows by 11 characters:
41
+ 3,249 / 4,021 / 6,221 for base / Claude / Claude with enforcement.
42
+ - `hybrid` heavy now also sets `effort: "xhigh"`, like the `anthropic` preset's
43
+ heavy tier, so Opus 5.5 receives the effort and not only the variant. The
44
+ `github-copilot` heavy description names Fable 5.1, the model it runs.
45
+ - V1 graders no longer send `graderTemperature` to models whose capabilities
46
+ report `temperature: false`.
47
+
48
+ ### Fixed
49
+
50
+ - Setting `enforcement.verify.graderTemperature` to `null` removes any grader temperature,
51
+ including pre-existing values and v2 allowlisted models. Numeric values still respect
52
+ v1 model capabilities and the v2 allowlist. Grader response/API failures are reported as
53
+ SDK errors with metadata-only details before verdict parsing, rather than as parse failures.
54
+ - Native `task` acceptance checks could run in the router directory instead of the producer's worktree: `[acceptance]` now supports `cwd:` (a supplied tool cwd wins), and the deterministic gate returns unverifiable without running checks when all changed paths are absolute and outside its base.
55
+ - Windows e2e self-check waits for sampler snapshots instead of a fixed 2.5 s window (#61).
56
+ - Parallel deferred finishes now share their gate-time tree snapshot, as dispatch
57
+ starts already did. A run only serves finishes that asked before it started.
58
+ Unshared, 20 parallel deferred delegations on a 4-core Windows host ran 20
59
+ snapshots and 19 hit the 2 s finish bound, leaving their changes unattributed
60
+ (risk high). Measured with that affinity: finish p50 2.11 s → 0.96 s, 19 → 0 capped.
61
+
62
+ ### Documentation
63
+
64
+ - README updated for OpenCode v2 support, presets and requirements.
65
+
66
+ ## [1.15.0] - 2026-09-28
67
+
68
+ The acceptance gate no longer runs a test suite per delegation. `testsPass` now runs only
69
+ the tests affected by the producer's changes, and the dispatch-time baseline is replaced
70
+ by a git reference captured in well under a second. **By default, delegations are no
71
+ longer verified unless the orchestrator asks for it**, either with `VERIFY:required` on
72
+ the dispatch or with a `router_verify` call on the returned handle, or unless
73
+ `enforcement.verify.background` is enabled. A deferred delegation is marked unverified,
74
+ carries a risk signal and stays in a pending list until it is checked. The full suite is
75
+ CI's job. See `docs/adr/0003-affected-test-verification.md`.
76
+
77
+ ### Added
78
+
79
+ - **New `enforcement.verify` keys.** These are `testScope` (`"affected"`, or `"full"`
80
+ as the explicit opt-in), `maxWorkers` (default 2), `lowPriority` (default `true`),
81
+ `maxConcurrentVerifications` (default `max(1, floor(cores / 8))`), `defaultVerify`
82
+ (default `"deferred"`), `captureWaitMs` (default 5 s, never more than
83
+ `baselineTimeoutMs`), `background` (default `false`), `pendingTtlMs` (default 1 h),
84
+ `slotWaitMs` (default 60 s), `batchWindowMs` (default 2 s), `failureRecheck` (default
85
+ `true`) and `recheckTimeoutMs` (default 60 s). See `docs/CONFIG_REFERENCE.md`.
86
+
87
+ - **`VERIFY:` and `VERIFY_WAIT:` dispatch directives.** `VERIFY:required` gates a
88
+ delegation synchronously and keeps the escalation ladder. `VERIFY:deferred`, the
89
+ default, returns at once. `VERIFY_WAIT:<n>s` sets how long the dispatch waits for the
90
+ reference capture before the producer starts. It never blocks beyond that.
91
+
92
+ - **`router_verify` tool.** A deferred delegation returns a `vrf_…` handle together with
93
+ an "unverified" disclaimer and a deterministic risk signal. `router_verify` runs the
94
+ verification for that handle on demand, within a deadline, and returns the verdict.
95
+
96
+ - **Pending list.** Unverified delegations are listed in the prompt until they are
97
+ verified or their handle expires (`pendingTtlMs`), so the orchestrator can see what it
98
+ is building on.
99
+
100
+ - **Opt-in background verification.** With `background: true`, deferred verifications
101
+ also run in the background through the verification slot at low priority, and failures
102
+ reach the orchestrator as late notices. It is off by default, so no CPU is spent on
103
+ verdicts nobody asked for.
104
+
105
+ - **pytest support.** `testsPass` scopes pytest runs by module mapping, and `pytest` and
106
+ `uv run pytest` are allowlisted. A green pytest scope passes. A failing one is always
107
+ `unverifiable`, because an editable install imports the live tree, which makes the
108
+ reference rerun impossible.
109
+
110
+ ### Changed
111
+
112
+ - **Gate labels say what was verified.** A result the gate let through without verifying it
113
+ (unverifiable: gate timeout, slot busy, budget exhausted, no reference; or a pass carrying a
114
+ caveat) is headed `[router ⚠ UNVERIFIED: <method>]` above its `Verification caveats — NOT
115
+ verified` list, instead of `[router ✓ accepted: …]` (plan G2, QA-3.1-21). A clean pass,
116
+ which used to add no text on a native `Task()`, now ends with `[router ✓ verified: <method>]`,
117
+ and a pass with notes uses the same label (QA-3.1-18). Accept/reject policy is unchanged.
118
+ - **`testsPass` runs only the affected tests.** The runner adapter builds the command
119
+ (`vitest related`, `jest --findRelatedTests`, pytest module mapping) and spawns it
120
+ without a shell. When scoped tests fail, only those test files are rerun in an
121
+ ephemeral worktree at the dispatch reference. Failures that also fail there were
122
+ already present, so they are excused with a note rather than blamed on the producer.
123
+ The router never falls back to a full suite: when scoping is impossible (an unknown
124
+ runner, a composite script, a config-file change) the result is `unverifiable` with a
125
+ caveat, which is accepted unless `strictUnverifiable` is set.
126
+
127
+ - **Deferred verification is the default.** A delegation with no `VERIFY:` directive
128
+ returns immediately as unverified. The synchronous cost is up to `VERIFY_WAIT`
129
+ (default `captureWaitMs`, 5 s) at dispatch for the reference capture, paid in either
130
+ mode, plus at most 2 s at return for the git-only snapshot of the producer's changes
131
+ (measured at about 0.4–0.5 s).
132
+
133
+ - **`enforcement.verify.baselineTimeoutMs` now bounds the git-only reference capture.**
134
+ It used to bound the dispatch-time baseline test run. Its default changed from 60 s to
135
+ 15 s.
136
+
137
+ - **The bundled `tiers.json` no longer sets `gateBudgetMs`.** The key is still supported;
138
+ its in-code default of 90 s (90000 ms) applies.
139
+
140
+ - **Verification runs at low priority, through a machine-wide slot, in batches.**
141
+ Commands run at below-normal OS priority with the runner's worker cap. A cross-process
142
+ semaphore in the OS temp directory limits concurrent verifications across every
143
+ opencode process on the machine. Requests for the same runner root that arrive within
144
+ `batchWindowMs` are merged into one scoped run, and failures are attributed back to
145
+ each request.
146
+
147
+ - **Deprecations.** `enforcement.verify.testBaseline` is deprecated in favour of
148
+ `failureRecheck`. Any value logs a once-per-process warning, and `testBaseline: false`
149
+ still turns the recheck off.
150
+
151
+ ### Fixed
152
+
153
+ - **A gate that runs out of budget now kills the verification process tree.** The gate
154
+ budget's abort signal reaches the running command instead of abandoning it.
155
+
156
+ - **The native `task` path's required gate has a budget.** `accept(…)` there was not
157
+ wrapped in a timeout, so a slow check could hold the `task` result indefinitely. It is
158
+ now bounded by `gateBudgetMs`, like the `delegate` path.
159
+
160
+ - **pytest: a changed module no longer passes as "no affected tests".** A changed module
161
+ used to map only to test files named after it (`test_<stem>.py`, `<stem>_test.py`), so
162
+ a test such as `tests/test_mod02_1.py` that imports it was never run. It now maps to
163
+ the test files that name its stem as a whole word (`git grep -F -w`, which matches
164
+ every import spelling), plus the name-matched tests. When no test maps, or a
165
+ `conftest.py` names the module, the check is `unverifiable` (`unmapped-module`), never
166
+ a pass. When `testpaths` decides the collection, only tests under it are inputs.
167
+ Residual: only direct importers run. A test that reaches the module through another
168
+ source module or a dynamic import is not run, and a change to non-`.py` files alone
169
+ (for example a data file a module reads) still gives "no affected tests".
170
+
171
+ - **An unknown tool during the dispatch capture no longer seeds the baseline.** Only
172
+ tools known not to write (read, glob, grep, list, ls, codesearch, webfetch, websearch,
173
+ lsp, todoread, todowrite, question, skill, plan_enter, plan_exit, invalid, task, the MCP
174
+ resource readers, delegate and router_verify) leave an in-flight snapshot or capture
175
+ alone. Any other tool, MCP and custom tools included, that runs in that window makes
176
+ the dispatch's change set unavailable and its reference none, so that dispatch is
177
+ `unverifiable` instead of a possible clean pass. Residual: a write with no tool event
178
+ (an external editor, an MCP server writing after its call returned), or a tool that
179
+ writes under a non-writing name, is not seen.
180
+
8
181
  ## [1.14.0] - 2026-09-26
9
182
 
10
183
  Test baselines could saturate every core on a machine running several delegations: a
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  > **Use the cheapest model that can do the job. Automatically.**
6
6
 
7
- An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,238–5,229 characters of system-prompt overhead depending on the orchestrator and enforcement mode.
7
+ An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,249–6,357 characters of system-prompt overhead depending on the orchestrator and enforcement mode.
8
8
 
9
9
  ## Why it's different
10
10
 
@@ -14,7 +14,7 @@ Most AI coding tools give you one model for everything. You pay Opus prices to r
14
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.
15
15
 
16
16
  **Inject a compressed, LLM-optimized routing protocol.**
17
- Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,238 characters; a Claude orchestrator receives 4,010 characters after its authority prefix (roughly 1,000–1,115 tokens at 3.6–4.0 characters per token). Every message, every session.
17
+ Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,249 characters; a Claude orchestrator receives 4,021 characters after its authority prefix (roughly 1,005–1,117 tokens at 3.6–4.0 characters per token). Every message, every session.
18
18
 
19
19
  **Match task to tier using a configurable taxonomy.**
20
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.
@@ -67,7 +67,7 @@ opencode-model-router injects a **delegation protocol** into the system prompt t
67
67
  4. **Never over-qualify** — use the cheapest tier that can reliably handle the task
68
68
  5. **Fallback** across providers when one fails
69
69
 
70
- All of this adds 3,238 characters for a non-Claude orchestrator or 4,010 characters for a Claude orchestrator (roughly 810–1,115 tokens at 3.6–4.0 characters per token).
70
+ All of this adds 3,249 characters for a non-Claude orchestrator or 4,021 characters for a Claude orchestrator (roughly 812–1,117 tokens at 3.6–4.0 characters per token).
71
71
 
72
72
  ## Understanding how it works
73
73
 
@@ -168,13 +168,13 @@ Task distribution: 18 exploration (60%), 10 implementation (33%), 2 architecture
168
168
 
169
169
  ## How it works
170
170
 
171
- On every message, the plugin injects a 3,238-character routing protocol. A Claude orchestrator receives 4,010 characters after its authority prefix (roughly 1,000–1,115 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.
171
+ On every message, the plugin injects a 3,249-character routing protocol. A Claude orchestrator receives 4,021 characters after its authority prefix (roughly 1,005–1,117 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.
172
172
 
173
173
  What the orchestrator sees (Anthropic preset, normal mode):
174
174
 
175
175
  ```
176
176
  ## Model Delegation Protocol
177
- Preset: anthropic. Tiers: @fast=claude-sonnet-5(1x) @medium=claude-opus-5/high(5x) @heavy=claude-fable-5/max(20x). mode:normal
177
+ Preset: anthropic. Tiers: @fast=claude-sonnet-5-5/low(1x) @medium=claude-sonnet-5-5/medium(5x) @heavy=claude-opus-5-5/xhigh(20x). mode:normal
178
178
  R: @fast→search/grep/read/git-info/ls/lookup-docs/types/count/exists-check/rename @medium→impl-feature/refactor/write-tests/bugfix(≤2)/edit-logic/code-review/build-fix/create-file/db-migrate/api-endpoint/config-update @heavy→arch-design/debug(≥3fail)/sec-audit/perf-opt/migrate-strategy/multi-system-integration/tradeoff-analysis/rca
179
179
  Multi-phase: prefer explore(@fast)→execute(@medium) when phases are separable. Cheapest-first when practical.
180
180
  1.[tier:X] tag in plan → delegate to X 2.plan:fast/cheap→@fast | plan:medium→@medium | plan:heavy→@heavy 3.default preference: read-only work → @fast; implementation → @medium 4.orchestrate=self, execute=subagent (info-gathering IS execution, not orchestration) 5.trivial (≤1 tool call, no expected follow-up) → direct, spent from the orchestrator read-only allowance 6.orchestrator read-only allowance (TARGET): dispatch is default; ≤2 direct read-only calls per turn; 3rd need → dispatch @fast (exceed only with 1-line reason) 7.dispatch caps baseline: @fast=CAP:8, @medium=CAP:5, @heavy=CAP:3 (omit directive = baseline; include CAP:N to override; CAP:none disables the cap only when the dispatch also carries a `reason:` line) 8.before dispatching @heavy: gather context first (usually via @fast); if context is already sufficient, dispatch directly 9.if self is opus: skip-@heavy (do locally); still prefer routing broader read-only exploration to @fast 10.min(cost, adequate-tier)
@@ -220,7 +220,7 @@ With router → split:
220
220
  | Cross-provider fallback | ✅ | ❌ | ❌ | ❌ | ❌ |
221
221
  | Cost ratio awareness | ✅ | ❌ | ❌ | ❌ | ❌ |
222
222
  | Plan annotation with tiers | ✅ | ❌ | ❌ | ❌ | ❌ |
223
- | Measured prompt overhead: 3,238–5,229 chars | ✅ | — | ❌ | ❌ | ❌ |
223
+ | Measured prompt overhead: 3,249–6,357 chars | ✅ | — | ❌ | ❌ | ❌ |
224
224
 
225
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.
226
226
 
@@ -250,6 +250,47 @@ Then install and configure model-router to handle the rest.
250
250
 
251
251
  ## Installation
252
252
 
253
+ ### OpenCode v2
254
+
255
+ The v2 adapter supports OpenCode hosts **2.0.20 or later** and typechecks against
256
+ `@opencode/plugin` **2.0.22**. Use the v2 `plugins` key:
257
+
258
+ ```json
259
+ {
260
+ "plugins": ["opencode-model-router"]
261
+ }
262
+ ```
263
+
264
+ For a local checkout, replace the package name with its absolute directory path.
265
+ V2 loads the package's `server.ts` definition; v1 continues to load the original
266
+ function from `src/index.ts`. Existing v1 configuration does not need to change.
267
+
268
+ Routing, tool guards and verification use the same engine on both versions. V2
269
+ uses its native `subagent` tool to create real child sessions, preserving the
270
+ host's permissions and cancellation. There are a few host differences:
271
+
272
+ - Delegations the router verifies run in the foreground so verification receives
273
+ a completed result; other `background` requests are kept. The router's own
274
+ deferred/background verification remains a separate setting.
275
+ - Temporary child sessions are removed after use on v2 ≥2.0.21; 2.0.20 can only
276
+ interrupt them, so their history is retained.
277
+ - Graders send no temperature unless the exact `provider/model` is listed in
278
+ `enforcement.verify.graderTemperatureModels`
279
+ ([details](docs/OPENCODE_V2.md#grader-temperature-on-v2)).
280
+ - Anti-narration warnings appear as separate synthetic transcript entries, because
281
+ completed v2 text events cannot be rewritten.
282
+ - Tier options (`effort`/`variant`/`reasoning_effort`, `budget_tokens`, etc.) are
283
+ applied per turn through the v2 `session` context hook, filling only keys not
284
+ already present, because v2 does not read `Agent.Info.request.settings`.
285
+
286
+ **Smoke tests:** Set `OPENCODE_V2_BIN` to the absolute path of an OpenCode v2
287
+ executable. `npm run smoke:v2` checks loading and registration without provider
288
+ credentials. `npm run smoke:v2:e2e` opts in to the end-to-end smoke (the script sets
289
+ `RUN_OC_SMOKE_V2_E2E=1`), driving `opencode run --standalone` against a local
290
+ deterministic OpenAI-compatible provider, also without provider credentials.
291
+
292
+ See [the v2 compatibility notes](docs/OPENCODE_V2.md) for the API mapping and validation.
293
+
253
294
  ### From npm (recommended)
254
295
  ```bash
255
296
  # In your opencode project or globally
@@ -378,23 +419,23 @@ The plugin ships with seven presets (switch with `/preset <name>`):
378
419
  **anthropic** (default):
379
420
  | Tier | Model | Cost ratio |
380
421
  |------|-------|-----------|
381
- | @fast | `anthropic/claude-sonnet-5` | 1x |
382
- | @medium | `anthropic/claude-opus-5` (high) | 5x |
383
- | @heavy | `anthropic/claude-fable-5` (max) | 20x |
422
+ | @fast | `anthropic/claude-sonnet-5-5` (variant/effort: low) | 1x |
423
+ | @medium | `anthropic/claude-sonnet-5-5` (variant/effort: medium) | 5x |
424
+ | @heavy | `anthropic/claude-opus-5-5` (variant/effort: xhigh) | 20x |
384
425
 
385
426
  **openai**:
386
427
  | Tier | Model | Cost ratio |
387
428
  |------|-------|-----------|
388
- | @fast | `openai/gpt-5.6-luna-fast` | 1x |
389
- | @medium | `openai/gpt-5.6-terra-fast` (high) | 5x |
390
- | @heavy | `openai/gpt-5.6-sol-fast` (xhigh) | 20x |
429
+ | @fast | `openai/gpt-6-luna-fast` | 1x |
430
+ | @medium | `openai/gpt-6.1-sol-fast` (xhigh) | 5x |
431
+ | @heavy | `openai/gpt-6-astra-fast` (max) | 20x |
391
432
 
392
433
  **github-copilot**:
393
434
  | Tier | Model | Cost ratio |
394
435
  |------|-------|-----------|
395
436
  | @fast | `github-copilot/claude-haiku-4.5` | 1x |
396
437
  | @medium | `github-copilot/claude-sonnet-5` | 5x |
397
- | @heavy | `github-copilot/claude-fable-5` | 20x |
438
+ | @heavy | `github-copilot/claude-fable-5-1` | 20x |
398
439
 
399
440
  **google**:
400
441
  | Tier | Model | Cost ratio |
@@ -403,19 +444,19 @@ The plugin ships with seven presets (switch with `/preset <name>`):
403
444
  | @medium | `google/gemini-3.7-flash` | 5x |
404
445
  | @heavy | `google/gemini-3.1-pro-preview` | 20x |
405
446
 
406
- **hybrid** — Anthropic for exploration and heavy analysis, OpenAI for implementation:
447
+ **hybrid** — OpenAI for exploration and implementation, Anthropic for heavy analysis:
407
448
  | Tier | Model | Cost ratio |
408
449
  |------|-------|-----------|
409
- | @fast | `anthropic/claude-haiku-4-5` | 1x |
410
- | @medium | `openai/gpt-5.6-terra-fast` (high) | 5x |
411
- | @heavy | `anthropic/claude-opus-5` (max) | 20x |
450
+ | @fast | `openai/gpt-6-luna-fast` (medium) | 1x |
451
+ | @medium | `openai/gpt-6-astra-fast` (high) | 5x |
452
+ | @heavy | `anthropic/claude-opus-5-5` (variant/effort: xhigh) | 20x |
412
453
 
413
454
  **fable-effort** — one model, three reasoning depths (see [per-tier `effort`](#per-tier-effort)):
414
455
  | Tier | Model | Effort | Cost ratio |
415
456
  |------|-------|--------|-----------|
416
- | @fast | `anthropic/claude-fable-5` | `low` | 1x |
417
- | @medium | `anthropic/claude-fable-5` | `high` | 3x |
418
- | @heavy | `anthropic/claude-fable-5` | `xhigh` | 6x |
457
+ | @fast | `anthropic/claude-fable-5-1` | `low` | 1x |
458
+ | @medium | `anthropic/claude-fable-5-1` | `high` | 3x |
459
+ | @heavy | `anthropic/claude-fable-5-1` | `xhigh` | 6x |
419
460
 
420
461
  Because the model string is identical across tiers, escalating a task keeps the prompt
421
462
  cache warm. The cost ratios are estimated token-spend multipliers, not price differences.
@@ -441,6 +482,9 @@ highest first:
441
482
 
442
483
  **Unset means unset**: no `effort` (and no `reasoning_effort`) key is registered at all.
443
484
 
485
+ Explicit fields are gated by model family: Claude drops `reasoning.effort`/`reasoning.summary`; adaptive-only Claude also ignores `thinking.budgetTokens`, leaving `effort` applicable.
486
+ Each drop warns once per tier; non-Claude explicit fields are unchanged. See the [provider gate](docs/CONFIG_REFERENCE.md#provider-gate-for-explicit-thinking-and-reasoning-fields).
487
+
444
488
  | Model family | Registered as | Caveats |
445
489
  |---|---|---|
446
490
  | 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. |
@@ -665,9 +709,9 @@ Each tier (`@fast`, `@medium`, `@heavy`) has a system prompt that describes its
665
709
  },
666
710
  "presets": {
667
711
  "anthropic": {
668
- "fast": { "model": "anthropic/claude-sonnet-5", ... },
669
- "medium": { "model": "anthropic/claude-opus-5", ... },
670
- "heavy": { "model": "anthropic/claude-fable-5", ... }
712
+ "fast": { "model": "anthropic/claude-sonnet-5-5", ... },
713
+ "medium": { "model": "anthropic/claude-sonnet-5-5", ... },
714
+ "heavy": { "model": "anthropic/claude-opus-5-5", ... }
671
715
  }
672
716
  }
673
717
  }
@@ -873,17 +917,19 @@ Defines provider fallback order when a delegated task fails:
873
917
 
874
918
  ## Delegation enforcement (advisory by default)
875
919
 
876
- The read-only cap banners described above are advisory: a well-behaved subagent will respect them, but nothing prevents a model from making one more read after the `[⚠ CAP REACHED]` banner. The **enforcement layer** turns delegation into a produce → verify → accept/escalate loop with independent acceptance and quality escalation. As of v1.3.0 it runs in **`advisory` mode by default**: every non-trivial delegation is verified and any genuine failure surfaces a forcing-note, but nothing is ever hard-blocked (the DoD/acceptance section adds 1,219 characters to the orchestrator system prompt, roughly 305–340 tokens at 3.6–4.0 characters per token, and subagents may receive non-blocking guard banners). Unavailable verification is accepted with explicit caveats by default; `enforcement.verify.strictUnverifiable: true` restores rejection without producer escalation. Set `"mode": "off"` — or run `/router enforce off` — to restore byte-for-byte-unchanged routing with zero added prompt tokens and zero new latency. Hard-blocks only activate in `"mode": "enforced"`.
920
+ The read-only cap banners described above are advisory: a well-behaved subagent will respect them, but nothing prevents a model from making one more read after the `[⚠ CAP REACHED]` banner. The **enforcement layer** turns delegation into a produce → verify → accept/escalate loop with independent acceptance and quality escalation. As of v1.3.0 it runs in **`advisory` mode by default**: non-trivial delegations are verified and any genuine failure surfaces a forcing-note, except that a DoD with `testsPass` is deferred by default and returns unverified with a `vrf_` handle until you call `router_verify`, use `VERIFY:required` or enable background verification; nothing is ever hard-blocked (the DoD/acceptance section adds 2,336 characters to the orchestrator system prompt, roughly 584–649 tokens at 3.6–4.0 characters per token, and subagents may receive non-blocking guard banners). Unavailable verification is accepted with explicit caveats by default; `enforcement.verify.strictUnverifiable: true` restores rejection without producer escalation. Set `"mode": "off"` — or run `/router enforce off` — to restore byte-for-byte-unchanged routing with zero added prompt tokens and zero new latency. Hard-blocks only activate in `"mode": "enforced"`.
921
+
922
+ That deferral is the v1.15.0 default (`enforcement.verify.defaultVerify: "deferred"`, `enforcement.verify.background: false`). It applies only to root-orchestrator dispatches whose DoD carries `testsPass`; see [deferred verification](docs/CONFIG_REFERENCE.md#deferred-verification) for the full conditions.
877
923
 
878
924
  ### The three enforcement layers
879
925
 
880
926
  - **Layer 1 — hard-block guard.** A `tool.execute.before` hook throws before a disallowed tool call executes, stopping budget overruns, redundant reads, and throwaway-script sidesteps in subagent sessions.
881
- - **Layer 2 — independent acceptance gate.** A non-trivial delegation carries a Definition-of-Done (DoD) that is checked — deterministically or by an independent grader at ≥ the producer's tier — before the result is trusted. The producer never grades its own output. Two cases are skipped rather than checked: a trivial dispatch carrying only an inferred DoD, and a dispatch whose inferred DoD has no deterministic checks and which changed no files. An explicit `[acceptance]` block is always verified. See [docs/VERIFICATION.md](docs/VERIFICATION.md).
927
+ - **Layer 2 — independent acceptance gate.** A non-trivial delegation carries a Definition-of-Done (DoD) that is checked — deterministically or by an independent grader at ≥ the producer's tier — before the result is trusted. The producer never grades its own output. Two cases are skipped rather than checked: a trivial dispatch carrying only an inferred DoD, and a dispatch whose inferred DoD has no deterministic checks and which changed no files. An explicit `[acceptance]` block is verified, but one with `testsPass` is deferred by default as a whole: its build, lint, `run` and criteria checks are deferred too, even when the producer changed nothing. A block without `testsPass` is gated before return (see [Deferred verification](docs/CONFIG_REFERENCE.md#deferred-verification)). See [docs/VERIFICATION.md](docs/VERIFICATION.md).
882
928
  - **Layer 3 — quality-escalation ladder.** On a failed check: retry once, then escalate fast → medium → heavy, bounded by attempt and cost ceilings. The loop ends in an honest `status: unmet` rather than a fabricated pass.
883
929
 
884
930
  ### Two operating modes
885
931
 
886
- - **Mode A — on-the-fly.** The orchestrator delegates through the native `Task()` tool — observed and verified automatically by the enforcement pipeline, and rendered inline in the TUI. (An optional, independently-verified `delegate` tool can be enabled via `experimental.verifiedDelegateTool` in `tiers.json` or `MODEL_ROUTER_VERIFIED_DELEGATE=1`; it is hidden by default so delegation stays visible.)
932
+ - **Mode A — on-the-fly.** The orchestrator delegates through the native `Task()` tool — observed by the enforcement pipeline, verified according to the settings above, and rendered inline in the TUI. (An optional, independently-verified `delegate` tool can be enabled via `experimental.verifiedDelegateTool` in `tiers.json` or `MODEL_ROUTER_VERIFIED_DELEGATE=1`; it is hidden by default so delegation stays visible.)
887
933
  - **Mode B — plan-annotated.** `/annotate-plan` emits `[tier:X]` plus an `[acceptance]` block per task; the enforcement loop is wired up at execution time based on those annotations.
888
934
 
889
935
  ### Tuning enforcement
@@ -894,6 +940,12 @@ Advisory is the default. To change the level:
894
940
  2. Set `MODEL_ROUTER_ENFORCE=1` to force `enforced` for a session, or `MODEL_ROUTER_ENFORCE=0` to force `off`.
895
941
  3. Run `/router enforce <off|advisory|enforced>` from the chat to toggle at runtime.
896
942
 
943
+ `taskPromptRepair` (top-level, default `true`) fills an absent, null or blank `task` prompt from a non-empty trimmed description, or refuses the call readably if none is usable.
944
+ Set `taskPromptRepair: false` to restore the previous behaviour; see [configuration details](docs/CONFIG_REFERENCE.md#taskpromptrepair).
945
+
946
+ For work outside the router directory (e.g. a git worktree), add `cwd: <dir>` inside the task's `[acceptance]` block; a non-empty tool `args.cwd` takes precedence.
947
+ If every changed file is absolute and outside the verification base, deterministic checks return unverifiable instead of running in the wrong directory.
948
+
897
949
  **Modes:** `off` — no-op, byte-for-byte-unchanged routing (must now be set explicitly, since `advisory` is the default); `advisory` (default) — evaluates and surfaces guidance, never blocks; `enforced` — hard-blocks active, full produce → verify → accept/escalate pipeline.
898
950
 
899
951
  > Enforcement applies to subagent/delegate sessions only. The orchestrator session is never hard-blocked.
@@ -995,7 +1047,7 @@ After `/annotate-plan`:
995
1047
 
996
1048
  ## Token overhead
997
1049
 
998
- Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,238 characters for a non-Claude orchestrator. A Claude orchestrator receives 4,010 characters after its authority prefix, or 5,229 characters when the 1,219-character DoD/enforcement section is enabled. That is roughly 810–1,450 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.
1050
+ Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,249 characters for a non-Claude orchestrator. A Claude orchestrator receives 4,021 characters after its authority prefix, or 6,357 characters when the 2,336-character DoD/enforcement section is enabled. That is roughly 812–1,766 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.
999
1051
 
1000
1052
  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.
1001
1053
 
@@ -1007,7 +1059,7 @@ These are character counts of the prompts the shipped config actually produces,
1007
1059
 
1008
1060
  ## Requirements
1009
1061
 
1010
- - [OpenCode](https://opencode.ai) v1.0 or later
1062
+ - [OpenCode](https://opencode.ai) v1 (`>=1.0.0 <2.0.0`) or v2 **2.0.20+**
1011
1063
  - Node.js 20+
1012
1064
  - Provider API keys configured in OpenCode
1013
1065
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "1.14.0",
3
+ "version": "2.0.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",
@@ -10,6 +10,8 @@
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
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
+ "smoke:v2": "cross-env RUN_OC_SMOKE_V2=1 vitest run --config vitest.smoke.config.ts test/smoke/v2-registration.smoke.test.ts",
14
+ "smoke:v2:e2e": "cross-env RUN_OC_SMOKE_V2_E2E=1 vitest run --config vitest.smoke.config.ts test/smoke/v2-provider-e2e.smoke.test.ts",
13
15
  "typecheck": "tsc --noEmit"
14
16
  },
15
17
  "license": "GPL-3.0-only",
@@ -39,6 +41,7 @@
39
41
  "orchestration"
40
42
  ],
41
43
  "files": [
44
+ "server.ts",
42
45
  "src/",
43
46
  "tiers.json",
44
47
  "LICENSE",
@@ -49,10 +52,12 @@
49
52
  "@opencode-ai/plugin": ">=1.0.0 <2.0.0"
50
53
  },
51
54
  "devDependencies": {
55
+ "@opencode/plugin": "2.0.22",
52
56
  "@types/node": "^26.2.0",
53
- "@vitest/coverage-v8": "^4.1.8",
57
+ "@vitest/coverage-v8": "^5.0.3",
54
58
  "cross-env": "^10.1.0",
59
+ "istanbul-lib-coverage": "^3.2.2",
55
60
  "typescript": "^7.0.2",
56
- "vitest": "^4.1.8"
61
+ "vitest": "^5.0.3"
57
62
  }
58
63
  }
package/server.ts ADDED
@@ -0,0 +1,3 @@
1
+ // OpenCode v2 resolves the /server entrypoint before the package main.
2
+ // Keep main callable for v1 loaders that invoke every module export.
3
+ export { default } from "./src/v2";
@@ -0,0 +1,27 @@
1
+ import type { PluginInput } from "@opencode-ai/plugin";
2
+
3
+ /** Marks the legacy tool.execute.before output bag when verification starts for
4
+ * that task call. V1 hosts read only output.args, so this symbol is invisible. */
5
+ export const TASK_VERIFICATION = Symbol.for("opencode-model-router.task-verification");
6
+
7
+ /** A host-owned child lifecycle, so v2 never fabricates REST sessions or IDs. */
8
+ export interface ChildSessionRequest {
9
+ parentSessionID?: string;
10
+ cwd?: string;
11
+ agent?: string;
12
+ model?: { providerID: string; modelID: string; variant?: string };
13
+ system?: string;
14
+ prompt: string;
15
+ signal?: AbortSignal;
16
+ /** Runs before the child can start its first model request. */
17
+ onCreated(sessionID: string): Promise<void>;
18
+ }
19
+
20
+ export interface ChildSessionRunner {
21
+ run(request: ChildSessionRequest): Promise<{ sessionID: string; text: string }>;
22
+ dispose(sessionID: string): Promise<void>;
23
+ }
24
+
25
+ export type RouterPluginInput = PluginInput & {
26
+ routerChildRunner?: ChildSessionRunner;
27
+ };