opencode-model-router 1.11.1 → 1.12.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 CHANGED
@@ -5,6 +5,164 @@ 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.12.1] - 2026-09-23
9
+
10
+ The delegate instruction filter introduced in 1.12.0 never removed anything in a live
11
+ session, and the change that makes it take effect would, on its own, have deleted
12
+ unrelated system-prompt text. Both are fixed together.
13
+
14
+ ### Fixed
15
+
16
+ - **`delegateInstructions` stripping now reaches the request.** The filter ended with
17
+ `output.system = output.system.flatMap(...)`, which rebinds the hook's output
18
+ property. opencode keeps its own reference to the array it passes to
19
+ `experimental.chat.system.transform` and reads that reference back after the hook
20
+ returns, so every removal was computed and then discarded. Protocol injection had
21
+ always worked only because it used `push`, which mutates the same array. The
22
+ filter now writes its result back with `splice` over the original array and never
23
+ rebinds `output.system`. The 1.12.0 tests passed because they asserted on the
24
+ rebound property rather than on the array the host still holds.
25
+
26
+ - **Removal is bounded to the instruction file's own text.** A block was defined as
27
+ running from its `Instructions from:` marker to the next marker or the end of the
28
+ entry, which was correct only while each instruction file arrived as its own array
29
+ element. The runtime joins the agent prompt, every instruction file and any
30
+ trailing system text into one string, so the last block extended to the end of
31
+ everything: a reproduction with a trailing `<mcp_instructions>` block lost the whole
32
+ MCP section along with `CLAUDE.md`, shrinking the prompt from 839 to 465 characters.
33
+ The filter now reads the file named by the marker (cached per path and revalidated
34
+ against its modification time) and removes exactly the marker line plus the longest
35
+ rendering of the file's contents — as read, LF-to-CRLF, CRLF-to-LF, or any of those
36
+ with trailing whitespace trimmed — that is an exact prefix of the block, keeping
37
+ whatever follows. If the file cannot be read or does not match, the block is kept
38
+ whole: leaving an instruction in place is unhelpful, deleting an unknown span of
39
+ the system prompt is not recoverable. The reader is an optional fourth parameter
40
+ (`InstructionFileReader`), so tests exercise the logic without touching disk; the
41
+ plugin's call site is unchanged.
42
+
43
+ ## [1.12.0] - 2026-09-23
44
+
45
+ A subagent was refusing dispatched work outright — returning `ESCALATE: The Task tool
46
+ is not available in this session` or `the available tools here are not the
47
+ Read/Grep/Glob/Bash tools described in the request` — without making a single tool
48
+ call. This release is about the several independent causes behind that, and about an
49
+ acceptance gate that was rejecting work for its own inability to check it.
50
+
51
+ ### Fixed
52
+
53
+ - **The orchestrator delegation protocol no longer leaks into subagent sessions.**
54
+ Classification was an allowlist of tier names: `if (!input.agent ||
55
+ !tierNames.includes(input.agent))`. So `general`, `explore`, every
56
+ markdown-defined agent and — by construction — every agent mapped through
57
+ `subagentTiers` was never recognised as a child, because
58
+ `resolveSubagentOverrides` deliberately skips any name that collides with a tier.
59
+ The two features were mutually exclusive. Unrecognised children were then told
60
+ `You are the orchestrator: route each task to the right tier and delegate it with
61
+ Task(...)`, which is a MANDATORY instruction they have no tool to satisfy, and a
62
+ literal-minded model refuses the dispatch rather than improvising. Children are now
63
+ classified by `parentID`, from the `session.created` event with a memoised
64
+ `session.get` fallback — the code comment had claimed this mechanism for some time,
65
+ but the only event handler began `if (event?.type !== "session.idle") return;` and
66
+ no `session.created` branch existed. Grader sessions are excluded too; they are
67
+ created synchronously and would otherwise stall until their budget expired. The
68
+ guard also now fails closed: a transform with no session id no longer injects.
69
+
70
+ - **Tier prompts no longer assert a missing capability.** All six shipped prompts
71
+ ended their opening paragraph with `You have no Task tool and cannot sub-delegate.`
72
+ The statement is true — the runtime denies `task` to children on its own — but
73
+ training a hand-back reflex next to orchestrator text demanding delegation is what
74
+ produced `I cannot invoke a medium subagent… dispatch it from the orchestrator`.
75
+ The sentence is replaced with `You execute this dispatch yourself and do not
76
+ re-delegate it`, and a provider-neutral tool-authority clause is appended once at
77
+ agent assembly: your own schema is authoritative, tool names in a dispatch are
78
+ descriptive and vary by provider, an empty search result is a result, and refusing
79
+ because a named tool looks unavailable is not an acceptable answer. This matters
80
+ most in a mixed-family setup, where a dispatch written in one vendor's tool
81
+ vocabulary reads to another vendor's model as a list of tools it does not have.
82
+
83
+ - **Reading a different region of an already-opened file is no longer flagged as
84
+ redundant.** The read fingerprint was the path alone, so lines 400–600 of a file
85
+ whose first 200 lines had been read collided with the earlier call and produced
86
+ `[⚠ REDUNDANT]`. Combined with prompts that said to stop immediately on that
87
+ marker, it halted legitimate work. The fingerprint now includes any range
88
+ arguments; a read with no range keeps its previous fingerprint exactly, so no
89
+ banner output moved. The prompts now say the marker means stop repeating ground you
90
+ already covered, and that a different region is not a repeat.
91
+
92
+ - **The announced read-only budget is the one actually charged.** The dispatch header
93
+ resolved the cap from `tierCaps`, while enforcement resolved it from the dispatch's
94
+ own `CAP:` directive and the `reason:` justification rule, so the header could
95
+ announce a budget the guard would not honour. Both sides now read the same
96
+ directive through the same parser, and a test pins their equality so neither can
97
+ drift alone.
98
+
99
+ - **Subagent-tier mappings now carry a tier.** An agent listed in `subagentTiers` was
100
+ correctly excluded from protocol injection but remained untiered, which silently
101
+ disabled its caps, verification and escalation. It now resolves to its mapped tier.
102
+ Alongside it: a non-2xx `session.get` is no longer cached as "root" (the generated
103
+ client resolves rather than throws, so the error object was read as an absent
104
+ `parentID`), failed lookups are retried after 30s instead of every step, and
105
+ `session.deleted` evicts the classification state.
106
+
107
+ - **A polynomial-ReDoS finding in delegate instruction filtering.** CodeQL flagged the
108
+ path normalizer behind `delegateInstructions`, the same class as the two 1.11.1
109
+ fixes. Its trailing-slash strip, `/\/+$/`, re-scanned a run of slashes from every
110
+ start offset, so a project directory or an `Instructions from:` marker path made of
111
+ many slashes cost O(n²). It is now a linear backwards scan with identical semantics:
112
+ trim, backslashes to slashes, lower-case, then drop trailing slashes.
113
+
114
+ ### Added
115
+
116
+ - **Orchestrator instruction files are stripped from delegate sessions**
117
+ (`delegateInstructions`, default `strip-global`). opencode injects instruction
118
+ files — `AGENTS.md`, a global `CLAUDE.md` — into every session, children included.
119
+ A global orchestrator persona therefore reached every delegate telling it to fire
120
+ a `fast` agent via `Task` for any read-only work, and to treat a dispatch's
121
+ `REQUIRED TOOLS` list as a whitelist. Project-local files are kept by default
122
+ because they usually carry conventions the delegate needs; `strip-all` removes
123
+ every instruction file, `keep` restores the previous behaviour.
124
+
125
+ - **A mechanical dispatch header on every tier dispatch** (`dispatchHeader`, default
126
+ on). Roughly 260 tokens stating the tier identity, that the delegate executes the
127
+ work itself, the working directory and that it is already there, that tool names
128
+ are descriptive rather than restrictive, that empty results are results and
129
+ `.gitignore` filtering is not a broken tool, and the resolved read budget with what
130
+ the runtime's banners mean. This is dispatch hygiene that previously had to be
131
+ retyped by hand into every prompt, which is exactly the kind of thing that stops
132
+ being done.
133
+
134
+ - **Hand-backs made without trying are detected** (`falseRefusalDetection`, default
135
+ on). A child that returns `ESCALATE:` / `NEED MORE:` / `SCOPE GROWTH:` with a
136
+ capability complaint and **zero recorded tool calls** gets its result annotated for
137
+ the orchestrator: no tool call was observed, so the capability claim is untested
138
+ rather than demonstrated, and a tier escalation on that result is suppressed. The
139
+ detector requires all three signals together, so a genuine scope hand-back after
140
+ real work is untouched.
141
+
142
+ - **A third verification outcome: `unverifiable`, distinct from a failed check**
143
+ (`enforcement.verify.strictUnverifiable`, default off). The gate was rejecting —
144
+ and the ladder escalating a tier on — its own inability to check: a command the
145
+ allowlist refused, `buildPasses` in a repo with no build script, a grader that
146
+ timed out, a path it could not resolve. None of those are evidence that the
147
+ producer failed. They are now reported as caveats on an accepted result, which
148
+ never claims the check passed; `strictUnverifiable` restores rejection, but
149
+ terminates the ladder instead of escalating. Grader timeouts also scale with tier
150
+ (60s / 180s / 600s) rather than a flat 60s a thinking model cannot meet.
151
+
152
+ - **`testsPass` is judged against a measured baseline** (`enforcement.verify.testBaseline`,
153
+ default on; `baselineTimeoutMs`, default 60s). A suite with pre-existing unrelated
154
+ failures made every delegation unacceptable. A dispatch-time baseline is now
155
+ captured out of band, keyed by working directory, `HEAD`, a working-tree
156
+ fingerprint and the exact test command, and cached across dispatches. It is
157
+ discarded the moment it could have been contaminated by the producer's own edits,
158
+ because a contaminated baseline errs in the dangerous direction: a newly introduced
159
+ failure would appear in both runs and be excused. Equal failure counts or equal
160
+ non-zero exit codes do not prove the identities are unchanged, so they yield
161
+ `unverifiable` rather than a pass. A green baseline followed by a failure still
162
+ rejects. The grader is also handed the producer's own change delta instead of an
163
+ unqualified dirty tree, so it stops reporting "no files were modified" against
164
+ changes that predate the dispatch.
165
+
8
166
  ## [1.11.1] - 2026-08-24
9
167
 
10
168
  ### Added
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,116–4,686 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,120–5,111 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,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.
17
+ Instead of duplicated prose, the plugin injects a dense, machine-readable routing protocol. The protocol itself is 3,120 characters; a Claude orchestrator receives 3,892 characters after its authority prefix (roughly 965–1,075 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,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).
70
+ All of this adds 3,120 characters for a non-Claude orchestrator or 3,892 characters for a Claude orchestrator (roughly 770–1,075 tokens at 3.6–4.0 characters per token).
71
71
 
72
72
  ## Understanding how it works
73
73
 
@@ -168,7 +168,7 @@ 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,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.
171
+ On every message, the plugin injects a 3,120-character routing protocol. A Claude orchestrator receives 3,892 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.
172
172
 
173
173
  What the orchestrator sees (Anthropic preset, normal mode):
174
174
 
@@ -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,116–4,686 chars | ✅ | — | ❌ | ❌ | ❌ |
223
+ | Measured prompt overhead: 3,120–5,111 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
 
@@ -873,7 +873,7 @@ Defines provider fallback order when a delegated task fails:
873
873
 
874
874
  ## Delegation enforcement (advisory by default)
875
875
 
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 miss surfaces a forcing-note, but nothing is ever hard-blocked (the DoD/acceptance section adds 798 characters to the orchestrator system prompt, roughly 200–220 tokens at 3.6–4.0 characters per token, and subagents may receive non-blocking guard banners). 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"`.
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"`.
877
877
 
878
878
  ### The three enforcement layers
879
879
 
@@ -920,7 +920,7 @@ explicitly in `tiers.json`:
920
920
  | Key | Bundled default | Bounds |
921
921
  |-----|-----------------|--------|
922
922
  | `delegateTimeoutMs` | `600000` (10 min) | One producer turn. |
923
- | `graderTimeoutMs` | `60000` (1 min) | One grader turn. |
923
+ | `graderTimeoutMs` | fast `60000` / medium `180000` / heavy `600000` | One grader turn; explicit override wins. |
924
924
  | `gateBudgetMs` | `90000` (90 s) | The whole acceptance gate. |
925
925
 
926
926
  Each budget is per **ladder attempt**, not per delegation: a fast → medium → heavy
@@ -995,7 +995,7 @@ After `/annotate-plan`:
995
995
 
996
996
  ## Token overhead
997
997
 
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.
998
+ Measured with the bundled Anthropic preset in normal mode (the shipped `activePreset`/`activeMode` defaults), the routing protocol is 3,120 characters for a non-Claude orchestrator. A Claude orchestrator receives 3,892 characters after its authority prefix, or 5,111 characters when the 1,219-character DoD/enforcement section is enabled. That is roughly 780–1,420 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
999
 
1000
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.
1001
1001
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "1.11.1",
3
+ "version": "1.12.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",
@@ -32,6 +32,7 @@ export interface LadderAction {
32
32
 
33
33
  export interface LadderVerdict {
34
34
  pass: boolean;
35
+ outcome?: "pass" | "fail" | "unverifiable";
35
36
  reasons?: string[];
36
37
  }
37
38
 
@@ -113,6 +114,11 @@ export function nextAction(
113
114
  if (verdict?.pass === true) {
114
115
  return { action: "accept" };
115
116
  }
117
+ // Strict policy may reject an unavailable check, but paying another producer
118
+ // cannot repair the verifier. Only actual failures enter the retry ladder.
119
+ if (verdict?.outcome === "unverifiable") {
120
+ return { action: "give_up", reason: "verification unavailable; no producer escalation" };
121
+ }
116
122
 
117
123
  // (2) cost check
118
124
  const costExceeded =
@@ -2,8 +2,17 @@
2
2
  export function fingerprintToolCall(tool: string, args: unknown): string {
3
3
  const a = (args ?? {}) as Record<string, unknown>;
4
4
  switch (tool) {
5
- case "read":
6
- return `read:${a.file_path ?? a.filePath ?? ""}`;
5
+ case "read": {
6
+ // Fixed field order preserves repeats regardless of argument insertion order.
7
+ // Keep path-only fingerprints unchanged when no range was supplied.
8
+ const range = Object.fromEntries(
9
+ ["offset", "limit", "start", "end", "line", "lines", "range"]
10
+ .filter((key) => a[key] != null)
11
+ .map((key) => [key, a[key]]),
12
+ );
13
+ const suffix = Object.keys(range).length ? `:${JSON.stringify(range)}` : "";
14
+ return `read:${a.file_path ?? a.filePath ?? ""}${suffix}`;
15
+ }
7
16
  case "grep":
8
17
  return `grep:${a.pattern ?? ""}:${a.path ?? a.glob ?? ""}`;
9
18
  case "glob":