opencode-model-router 1.12.0 → 1.13.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 +103 -0
- package/README.md +12 -12
- package/package.json +1 -1
- package/src/index.ts +31 -0
- package/src/router/agent-options.ts +34 -7
- package/src/router/config.ts +15 -0
- package/src/router/instructions.ts +98 -11
- package/src/router/protocol.ts +28 -1
- package/tiers.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,109 @@ 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.13.0] - 2026-09-24
|
|
9
|
+
|
|
10
|
+
A forced delegation of a request that carries no task produced a `task` call with no
|
|
11
|
+
prompt, which the harness rejected with a terse schema error. The router now repairs
|
|
12
|
+
such calls or refuses them readably. This release also gives the orchestrator's
|
|
13
|
+
read-only allowance a single consistent statement, and stops explicit thinking and
|
|
14
|
+
reasoning fields from reaching Claude models that cannot use them.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **`taskPromptRepair` fills in or refuses prompt-less `task` calls.** A forced
|
|
19
|
+
delegation of a request that carries no task — a bare greeting sent through an
|
|
20
|
+
explicit tier mention, say — made the model emit a `task` call with a description
|
|
21
|
+
and a tier but no prompt, and the harness rejected it with a bare schema error
|
|
22
|
+
naming the missing key. The `task` before-hook now repairs the call ahead of the
|
|
23
|
+
dispatch header: when `prompt` is absent, `null` or blank and `description` is a
|
|
24
|
+
non-empty string, the trimmed description becomes the prompt and the call proceeds
|
|
25
|
+
with the dispatch header applied normally. When there is no usable description the
|
|
26
|
+
call is refused with a `[router]` error saying that `task` needs a non-empty
|
|
27
|
+
`prompt`, and that a request carrying no task (a greeting, an acknowledgement)
|
|
28
|
+
should be answered directly rather than delegated. A prompt of a non-string type
|
|
29
|
+
is left for the harness, and frozen args that cannot be repaired are left alone.
|
|
30
|
+
The flag defaults to `true`; set `taskPromptRepair: false` to restore the previous
|
|
31
|
+
behaviour. Non-boolean values are rejected by `validateConfig`. See
|
|
32
|
+
`docs/CONFIG_REFERENCE.md`.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **The orchestrator's read-only allowance is stated as one mechanism.** The injected
|
|
37
|
+
protocol gave the same rule three incompatible readings: the orchestrator line said
|
|
38
|
+
information-gathering should be dispatched to @fast rather than run directly, then
|
|
39
|
+
capped direct read-only calls at about two per turn, and the rules array added a
|
|
40
|
+
separate licence for trivial single-call work that acknowledged neither. Dispatch
|
|
41
|
+
is now the stated default, and direct calls are a named allowance for lookups that
|
|
42
|
+
settle a question outright; the trivial-work rules in the shipped `tiers.json` now
|
|
43
|
+
spend that allowance instead of competing with it, and the per-mode overrides are
|
|
44
|
+
reconciled the same way. No cap number moved: the base allowance is still two,
|
|
45
|
+
budget mode is still one, and the dispatch baselines are unchanged. Only the
|
|
46
|
+
protocol prose changed, so the injected prompt and the README's measured
|
|
47
|
+
prompt-size figures move by the length of the new wording. The README's sample
|
|
48
|
+
rules line is regenerated from the shipped configuration; it had shown eight rules
|
|
49
|
+
where the shipped array has ten.
|
|
50
|
+
|
|
51
|
+
### Fixed
|
|
52
|
+
|
|
53
|
+
- **The invalid-effort warning goes through the plugin logger.** Every other
|
|
54
|
+
`buildAgentOptions` warning passed the plugin logger, but an unrecognised `effort`
|
|
55
|
+
value always went to `console.warn`, even when a logger was supplied. It now uses
|
|
56
|
+
the logger like its siblings; without one the behaviour is unchanged.
|
|
57
|
+
|
|
58
|
+
- **Explicit `thinking` and `reasoning` fields are gated for Claude models.**
|
|
59
|
+
`buildAgentOptions` emitted `budget_tokens` and `reasoning_effort` /
|
|
60
|
+
`reasoning_summary` without consulting the model, so a tier on an adaptive-only
|
|
61
|
+
model — the bundled `anthropic` preset's `@medium` is `anthropic/claude-opus-5-5` —
|
|
62
|
+
that also set `thinking.budgetTokens` registered a manual thinking budget on a model
|
|
63
|
+
that only accepts adaptive thinking (the HTTP 400 this is said to cause is reported,
|
|
64
|
+
not reproduced here; see the provider gate in `docs/CONFIG_REFERENCE.md`), and the
|
|
65
|
+
budget outranked the `effort` that would have applied. A Claude tier now never
|
|
66
|
+
registers `reasoning_*` (OpenAI parameters), and a tier on a model whose wire-compat
|
|
67
|
+
catalogue entry carries `rejects_disabled_thinking` (`claude-opus-5-5`,
|
|
68
|
+
`claude-fable-5`, `claude-fable-5-1`, `claude-mythos-5-1`, matched by the new
|
|
69
|
+
`isAdaptiveOnlyClaudeModel`) never registers `budget_tokens`; the budget is then
|
|
70
|
+
treated as unset, so `effort` still applies. Each drop warns once per tier.
|
|
71
|
+
Non-Claude tiers are unchanged. Ids of the form
|
|
72
|
+
`<provider>/<namespace>.claude-…`, such as `bedrock/us.anthropic.claude-…`, are not
|
|
73
|
+
recognised as Claude, so they get no Claude prompt prefix, no Anthropic effort
|
|
74
|
+
routing and no gate; the README had claimed they were detected and now says so.
|
|
75
|
+
|
|
76
|
+
## [1.12.1] - 2026-09-23
|
|
77
|
+
|
|
78
|
+
The delegate instruction filter introduced in 1.12.0 never removed anything in a live
|
|
79
|
+
session, and the change that makes it take effect would, on its own, have deleted
|
|
80
|
+
unrelated system-prompt text. Both are fixed together.
|
|
81
|
+
|
|
82
|
+
### Fixed
|
|
83
|
+
|
|
84
|
+
- **`delegateInstructions` stripping now reaches the request.** The filter ended with
|
|
85
|
+
`output.system = output.system.flatMap(...)`, which rebinds the hook's output
|
|
86
|
+
property. opencode keeps its own reference to the array it passes to
|
|
87
|
+
`experimental.chat.system.transform` and reads that reference back after the hook
|
|
88
|
+
returns, so every removal was computed and then discarded. Protocol injection had
|
|
89
|
+
always worked only because it used `push`, which mutates the same array. The
|
|
90
|
+
filter now writes its result back with `splice` over the original array and never
|
|
91
|
+
rebinds `output.system`. The 1.12.0 tests passed because they asserted on the
|
|
92
|
+
rebound property rather than on the array the host still holds.
|
|
93
|
+
|
|
94
|
+
- **Removal is bounded to the instruction file's own text.** A block was defined as
|
|
95
|
+
running from its `Instructions from:` marker to the next marker or the end of the
|
|
96
|
+
entry, which was correct only while each instruction file arrived as its own array
|
|
97
|
+
element. The runtime joins the agent prompt, every instruction file and any
|
|
98
|
+
trailing system text into one string, so the last block extended to the end of
|
|
99
|
+
everything: a reproduction with a trailing `<mcp_instructions>` block lost the whole
|
|
100
|
+
MCP section along with `CLAUDE.md`, shrinking the prompt from 839 to 465 characters.
|
|
101
|
+
The filter now reads the file named by the marker (cached per path and revalidated
|
|
102
|
+
against its modification time) and removes exactly the marker line plus the longest
|
|
103
|
+
rendering of the file's contents — as read, LF-to-CRLF, CRLF-to-LF, or any of those
|
|
104
|
+
with trailing whitespace trimmed — that is an exact prefix of the block, keeping
|
|
105
|
+
whatever follows. If the file cannot be read or does not match, the block is kept
|
|
106
|
+
whole: leaving an instruction in place is unhelpful, deleting an unknown span of
|
|
107
|
+
the system prompt is not recoverable. The reader is an optional fourth parameter
|
|
108
|
+
(`InstructionFileReader`), so tests exercise the logic without touching disk; the
|
|
109
|
+
plugin's call site is unchanged.
|
|
110
|
+
|
|
8
111
|
## [1.12.0] - 2026-09-23
|
|
9
112
|
|
|
10
113
|
A subagent was refusing dispatched work outright — returning `ESCALATE: The Task tool
|
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,
|
|
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.
|
|
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,
|
|
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.
|
|
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,
|
|
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).
|
|
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,
|
|
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.
|
|
172
172
|
|
|
173
173
|
What the orchestrator sees (Anthropic preset, normal mode):
|
|
174
174
|
|
|
@@ -177,7 +177,7 @@ What the orchestrator sees (Anthropic preset, normal mode):
|
|
|
177
177
|
Preset: anthropic. Tiers: @fast=claude-sonnet-5(1x) @medium=claude-opus-5/high(5x) @heavy=claude-fable-5/max(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
|
-
1.[tier:X] tag in plan→delegate X 2.plan:fast/cheap→@fast | plan:medium→@medium | plan:heavy→@heavy 3.default preference: read-only
|
|
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)
|
|
181
181
|
Err→retry-alt-tier→fail→direct. Chain: anthropic→openai→google→github-copilot
|
|
182
182
|
Delegate with Task(subagent_type="fast|medium|heavy", prompt="...").
|
|
183
183
|
Keep orchestration and final synthesis in the primary agent.
|
|
@@ -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,
|
|
223
|
+
| Measured prompt overhead: 3,238–5,229 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
|
|
|
@@ -481,7 +481,7 @@ Switch with `/budget <mode>`. Mode is persisted across restarts.
|
|
|
481
481
|
"default→@medium for implementation and multi-file changes",
|
|
482
482
|
"@heavy for architecture/debug/security/tradeoff-analysis by default",
|
|
483
483
|
"allow long heavy runs before fallback; avoid premature downshift",
|
|
484
|
-
"trivial(grep/read/glob)→direct,
|
|
484
|
+
"trivial(grep/read/glob)→direct,spends orchestrator read-only allowance",
|
|
485
485
|
"if task is composite and phases are separable: prefer explore@fast then execute@heavy"
|
|
486
486
|
]
|
|
487
487
|
}
|
|
@@ -530,7 +530,7 @@ The `rules` array is injected verbatim (in compact form) into the system prompt.
|
|
|
530
530
|
"plan:fast/cheap→@fast | plan:medium→@medium | plan:heavy→@heavy",
|
|
531
531
|
"default preference: read-only work → @fast; implementation → @medium",
|
|
532
532
|
"orchestrate=self,delegate=exec",
|
|
533
|
-
"trivial (≤1 tool call, no expected follow-up) → direct,
|
|
533
|
+
"trivial (≤1 tool call, no expected follow-up) → direct, spent from the orchestrator read-only allowance",
|
|
534
534
|
"before dispatching @heavy: gather context first (usually via @fast); if context is already sufficient, dispatch directly",
|
|
535
535
|
"if self is opus: skip-@heavy (do locally); still prefer routing broader read-only exploration to @fast",
|
|
536
536
|
"min(cost,adequate-tier)"
|
|
@@ -544,7 +544,7 @@ Rules in `modes[x].overrideRules` replace this array entirely for that mode.
|
|
|
544
544
|
|
|
545
545
|
Subagents carry a cap on their own read-only tool calls (grep/read/glob/ls) per dispatch. Enforcement is **two-layered**: prompt-level stop rules + runtime banners injected into tool results. Baselines (configurable via `tierCaps` — see below):
|
|
546
546
|
|
|
547
|
-
| Tier | Baseline cap | Orchestrator
|
|
547
|
+
| Tier | Baseline cap | Orchestrator allowance |
|
|
548
548
|
|------|-------------:|----------------------:|
|
|
549
549
|
| `@fast` | 8 | — |
|
|
550
550
|
| `@medium` | 5 | — |
|
|
@@ -645,7 +645,7 @@ This keeps subagents from burning tokens on repeated lookups when they already h
|
|
|
645
645
|
|
|
646
646
|
**Mode interactions:**
|
|
647
647
|
|
|
648
|
-
| Mode | Dispatch directive | Orchestrator
|
|
648
|
+
| Mode | Dispatch directive | Orchestrator allowance |
|
|
649
649
|
|------|-------------------|-----------------------|
|
|
650
650
|
| `normal` | baselines (omit directive) | ≤2 direct reads |
|
|
651
651
|
| `budget` | `CAP:5` @fast, `CAP:2` @medium, `CAP:2` @heavy | ≤1 direct read |
|
|
@@ -765,7 +765,7 @@ Detection is by model string, not preset. A `hybrid` preset that mixes providers
|
|
|
765
765
|
|
|
766
766
|
- `anthropic/<anything>` → Claude
|
|
767
767
|
- `<provider>/claude-<anything>` (e.g. `github-copilot/claude-sonnet-4-6`) → Claude
|
|
768
|
-
- `<provider>/<namespace>.claude-<anything>` (e.g. `bedrock/us.anthropic.claude-3-5-sonnet-...`) → Claude
|
|
768
|
+
- `<provider>/<namespace>.claude-<anything>` (e.g. `bedrock/us.anthropic.claude-3-5-sonnet-...`) → **not** detected: the dot before `claude-` does not satisfy the rule, so such tiers are treated as non-Claude (no Claude prefix, no Anthropic `effort` routing, no provider gate)
|
|
769
769
|
- Everything else → untouched
|
|
770
770
|
|
|
771
771
|
No configuration is needed — the prefixes are always applied for Claude-backed tiers. If you want to disable them, override the tier's `prompt` field (per-tier overrides replace the whole prompt, including the prefix).
|
|
@@ -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,
|
|
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.
|
|
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
package/src/index.ts
CHANGED
|
@@ -899,6 +899,37 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
|
|
|
899
899
|
}));
|
|
900
900
|
}
|
|
901
901
|
}
|
|
902
|
+
// A task call with no prompt (typically a forced delegation of a bare
|
|
903
|
+
// greeting) is otherwise rejected by the harness with a terse schema
|
|
904
|
+
// error. Repair it from the description, or refuse it readably. The
|
|
905
|
+
// refusal is computed inside the best-effort try and thrown outside it,
|
|
906
|
+
// so the catch can never swallow it.
|
|
907
|
+
let promptRefusal: string | null = null;
|
|
908
|
+
try {
|
|
909
|
+
if (input?.tool === "task" && cfg.taskPromptRepair !== false) {
|
|
910
|
+
const rawArgs: unknown = output?.args;
|
|
911
|
+
if (rawArgs && typeof rawArgs === "object" && !Array.isArray(rawArgs)) {
|
|
912
|
+
const args = rawArgs as Record<string, unknown>;
|
|
913
|
+
// Only an absent or blank prompt is repaired; a non-string prompt of
|
|
914
|
+
// some other type is a different malformation left to the harness.
|
|
915
|
+
const rawPrompt = args.prompt;
|
|
916
|
+
if (rawPrompt === undefined || rawPrompt === null || (typeof rawPrompt === "string" && rawPrompt.trim() === "")) {
|
|
917
|
+
const description = typeof args.description === "string" ? args.description.trim() : "";
|
|
918
|
+
if (description) {
|
|
919
|
+
args.prompt = description;
|
|
920
|
+
} else {
|
|
921
|
+
promptRefusal = "[router] This task call carried no prompt, and the task tool needs a non-empty `prompt` " +
|
|
922
|
+
"stating the work for the delegate. Re-issue the call with the work restated as an instruction in " +
|
|
923
|
+
"`prompt`. If the request carries no task at all (a greeting, an acknowledgement), do not delegate: " +
|
|
924
|
+
"answer it directly instead.";
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
} catch {
|
|
930
|
+
// Best-effort: malformed or frozen args must never break a dispatch.
|
|
931
|
+
}
|
|
932
|
+
if (promptRefusal) throw new Error(promptRefusal);
|
|
902
933
|
// Dispatch hygiene is independent of subagent guard enforcement below.
|
|
903
934
|
// The plugin API declares generic args, not a task-specific argument shape.
|
|
904
935
|
try {
|
|
@@ -14,7 +14,7 @@ import type { PluginLogger } from "./logger";
|
|
|
14
14
|
*/
|
|
15
15
|
import type { TierConfig } from "./config";
|
|
16
16
|
import { EFFORT_LEVELS } from "./config";
|
|
17
|
-
import { isClaudeModel } from "./protocol";
|
|
17
|
+
import { isAdaptiveOnlyClaudeModel, isClaudeModel } from "./protocol";
|
|
18
18
|
|
|
19
19
|
// ---------------------------------------------------------------------------
|
|
20
20
|
// Warn-once
|
|
@@ -61,7 +61,13 @@ function isOpenAIModel(model: string): boolean {
|
|
|
61
61
|
* Precedence, highest first: explicit `thinking` with a truthy `budgetTokens`
|
|
62
62
|
* (Anthropic) or explicit `reasoning.effort` (OpenAI), then the
|
|
63
63
|
* provider-agnostic `effort`. A `budgetTokens` of 0 asks for nothing and so
|
|
64
|
-
* loses to `effort`, with a one-time notice per tier.
|
|
64
|
+
* loses to `effort`, with a one-time notice per tier.
|
|
65
|
+
*
|
|
66
|
+
* Explicit fields are gated by model: a Claude model never receives
|
|
67
|
+
* `reasoning_effort` / `reasoning_summary`, and an adaptive-only Claude model
|
|
68
|
+
* (`isAdaptiveOnlyClaudeModel`) never receives `budget_tokens` — the budget is
|
|
69
|
+
* then ignored as if unset, so `effort` still applies. Each drop warns once
|
|
70
|
+
* per tier. A key is
|
|
65
71
|
* only ever present when something asked for it — an unset `effort` leaves no
|
|
66
72
|
* trace in the returned object.
|
|
67
73
|
*/
|
|
@@ -76,8 +82,19 @@ export function buildAgentOptions(
|
|
|
76
82
|
// all, so it is neither emitted nor treated as an explicit thinking config
|
|
77
83
|
// below — `hasThinkingBudget` is the single notion of "thinking was asked
|
|
78
84
|
// for", shared by the emission and the effort precedence check.
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
// An adaptive-only Claude model rejects a manual budget outright, so the
|
|
86
|
+
// budget is dropped and — for the effort precedence below — treated as never
|
|
87
|
+
// having been set, which lets a sibling `effort` through.
|
|
88
|
+
const isClaude = isClaudeModel(tier.model);
|
|
89
|
+
let hasThinkingBudget = Boolean(tier.thinking?.budgetTokens);
|
|
90
|
+
if (hasThinkingBudget && isAdaptiveOnlyClaudeModel(tier.model)) {
|
|
91
|
+
hasThinkingBudget = false;
|
|
92
|
+
warnAgentOptionsEffortOnce(
|
|
93
|
+
`thinking-adaptive-only:${tierName}`,
|
|
94
|
+
`tier ${tierName}: model '${tier.model}' only accepts adaptive thinking and rejects a manual budget, so thinking.budgetTokens is ignored; use effort instead`,
|
|
95
|
+
logger,
|
|
96
|
+
);
|
|
97
|
+
} else if (hasThinkingBudget) {
|
|
81
98
|
opts.budget_tokens = tier.thinking?.budgetTokens;
|
|
82
99
|
} else if (tier.thinking?.budgetTokens === 0) {
|
|
83
100
|
warnAgentOptionsEffortOnce(
|
|
@@ -87,8 +104,17 @@ export function buildAgentOptions(
|
|
|
87
104
|
);
|
|
88
105
|
}
|
|
89
106
|
|
|
90
|
-
// OpenAI reasoning config
|
|
91
|
-
|
|
107
|
+
// OpenAI reasoning config. Claude models have no such parameters, so they
|
|
108
|
+
// are dropped there rather than sent to a provider that cannot read them.
|
|
109
|
+
if (tier.reasoning && isClaude) {
|
|
110
|
+
if (tier.reasoning.effort || tier.reasoning.summary) {
|
|
111
|
+
warnAgentOptionsEffortOnce(
|
|
112
|
+
`reasoning-claude:${tierName}`,
|
|
113
|
+
`tier ${tierName}: reasoning.effort and reasoning.summary are OpenAI parameters and are ignored for Claude model '${tier.model}'; use effort instead`,
|
|
114
|
+
logger,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
} else if (tier.reasoning) {
|
|
92
118
|
if (tier.reasoning.effort) {
|
|
93
119
|
opts.reasoning_effort = tier.reasoning.effort;
|
|
94
120
|
}
|
|
@@ -106,8 +132,9 @@ export function buildAgentOptions(
|
|
|
106
132
|
warnAgentOptionsEffortOnce(
|
|
107
133
|
`invalid:${tierName}:${String(effort)}`,
|
|
108
134
|
`tier ${tierName}: invalid effort '${String(effort)}' ignored`,
|
|
135
|
+
logger,
|
|
109
136
|
);
|
|
110
|
-
} else if (
|
|
137
|
+
} else if (isClaude) {
|
|
111
138
|
if (hasThinkingBudget) {
|
|
112
139
|
warnAgentOptionsEffortOnce(
|
|
113
140
|
`anthropic-conflict:${tierName}`,
|
package/src/router/config.ts
CHANGED
|
@@ -156,6 +156,14 @@ export interface RouterConfig {
|
|
|
156
156
|
* orchestrator remembered to write it.
|
|
157
157
|
*/
|
|
158
158
|
dispatchHeader?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Repair a task dispatch that arrives without a prompt: copy a non-empty
|
|
161
|
+
* description into the prompt, or refuse the call with a readable
|
|
162
|
+
* explanation when neither carries any work. Defaults to true. Set false to
|
|
163
|
+
* restore the pre-feature behaviour where the harness rejected such a call
|
|
164
|
+
* with a bare schema error.
|
|
165
|
+
*/
|
|
166
|
+
taskPromptRepair?: boolean;
|
|
159
167
|
/**
|
|
160
168
|
* DELEGATE sessions only, never the orchestrator. `strip-global` (default)
|
|
161
169
|
* removes instruction files outside the project, where orchestrator personas
|
|
@@ -512,6 +520,12 @@ function validateDispatchHeader(obj: Record<string, unknown>): void {
|
|
|
512
520
|
}
|
|
513
521
|
}
|
|
514
522
|
|
|
523
|
+
function validateTaskPromptRepair(obj: Record<string, unknown>): void {
|
|
524
|
+
if (obj.taskPromptRepair !== undefined && typeof obj.taskPromptRepair !== "boolean") {
|
|
525
|
+
throw new Error("tiers.json: 'taskPromptRepair' must be a boolean");
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
515
529
|
function validateFalseRefusalDetection(obj: Record<string, unknown>): void {
|
|
516
530
|
if (obj.falseRefusalDetection !== undefined && typeof obj.falseRefusalDetection !== "boolean") {
|
|
517
531
|
throw new Error("tiers.json: 'falseRefusalDetection' must be a boolean");
|
|
@@ -923,6 +937,7 @@ export function validateConfig(raw: unknown): RouterConfig {
|
|
|
923
937
|
validateEnforcement(obj);
|
|
924
938
|
validateDelegateInstructions(obj);
|
|
925
939
|
validateDispatchHeader(obj);
|
|
940
|
+
validateTaskPromptRepair(obj);
|
|
926
941
|
validateFalseRefusalDetection(obj);
|
|
927
942
|
|
|
928
943
|
return raw as RouterConfig;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
1
2
|
import type { RouterConfig } from "./config";
|
|
2
3
|
|
|
3
4
|
export type DelegateInstructionsPolicy = "strip-global" | "strip-all" | "keep";
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Returns an instruction file's contents, or `undefined` when the file cannot be
|
|
8
|
+
* read for any reason. Injectable so tests need not touch the filesystem.
|
|
9
|
+
*/
|
|
10
|
+
export type InstructionFileReader = (absolutePath: string) => string | undefined;
|
|
11
|
+
|
|
12
|
+
const MARKER = /^Instructions from:[^\S\r\n]*(\S[^\r\n]*)/;
|
|
13
|
+
|
|
5
14
|
/**
|
|
6
15
|
* Strip trailing forward slashes without a regex.
|
|
7
16
|
*
|
|
@@ -16,6 +25,74 @@ function stripTrailingSlashes(value: string): string {
|
|
|
16
25
|
return value.slice(0, end);
|
|
17
26
|
}
|
|
18
27
|
|
|
28
|
+
const fileCache = new Map<string, { mtimeMs: number; size: number; contents: string }>();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Real-filesystem reader. The system transform fires on every LLM step, so
|
|
32
|
+
* contents are cached per path and revalidated against mtime and size.
|
|
33
|
+
*/
|
|
34
|
+
export const readInstructionFile: InstructionFileReader = (absolutePath) => {
|
|
35
|
+
try {
|
|
36
|
+
const stat = statSync(absolutePath);
|
|
37
|
+
if (!stat.isFile()) return undefined;
|
|
38
|
+
const cached = fileCache.get(absolutePath);
|
|
39
|
+
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
40
|
+
return cached.contents;
|
|
41
|
+
}
|
|
42
|
+
const contents = readFileSync(absolutePath, "utf8");
|
|
43
|
+
fileCache.set(absolutePath, { mtimeMs: stat.mtimeMs, size: stat.size, contents });
|
|
44
|
+
return contents;
|
|
45
|
+
} catch {
|
|
46
|
+
// Missing, unreadable, or not a file: the caller keeps the section intact.
|
|
47
|
+
fileCache.delete(absolutePath);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Length of the longest candidate rendering of `contents` that is an exact
|
|
54
|
+
* prefix of `body`, or `undefined` when none is. Compared literally against the
|
|
55
|
+
* original body so the removal length needs no index mapping.
|
|
56
|
+
*/
|
|
57
|
+
function matchedSpan(body: string, contents: string): number | undefined {
|
|
58
|
+
const renderings = [
|
|
59
|
+
contents,
|
|
60
|
+
contents.replace(/\r?\n/g, "\r\n"),
|
|
61
|
+
contents.replace(/\r\n/g, "\n"),
|
|
62
|
+
];
|
|
63
|
+
let best: number | undefined;
|
|
64
|
+
for (const candidate of [...renderings, ...renderings.map((r) => r.trimEnd())]) {
|
|
65
|
+
if ((best === undefined || candidate.length > best) && body.startsWith(candidate)) {
|
|
66
|
+
best = candidate.length;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return best;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Remove the marker line and the named file's own text from `section`, keeping
|
|
74
|
+
* whatever follows. The host joins every instruction file and trailing system
|
|
75
|
+
* text into one string, so the last section's end is not the file's end. If
|
|
76
|
+
* the extent cannot be established from the file, the section is returned
|
|
77
|
+
* unchanged: keeping an instruction is harmless, deleting unknown text is not.
|
|
78
|
+
*/
|
|
79
|
+
function removeInstructionBlock(section: string, path: string, read: InstructionFileReader): string {
|
|
80
|
+
let contents: string | undefined;
|
|
81
|
+
try {
|
|
82
|
+
contents = read(path);
|
|
83
|
+
} catch {
|
|
84
|
+
// A throwing reader means the extent is unknown; keep the section.
|
|
85
|
+
contents = undefined;
|
|
86
|
+
}
|
|
87
|
+
if (typeof contents !== "string") return section;
|
|
88
|
+
const newline = section.indexOf("\n");
|
|
89
|
+
const body = newline === -1 ? "" : section.slice(newline + 1);
|
|
90
|
+
const span = matchedSpan(body, contents);
|
|
91
|
+
if (span === undefined) return section;
|
|
92
|
+
const rest = body.slice(span);
|
|
93
|
+
return rest.trim() ? rest : "";
|
|
94
|
+
}
|
|
95
|
+
|
|
19
96
|
/**
|
|
20
97
|
* opencode injects instruction files into every session, including children.
|
|
21
98
|
* A global orchestrator persona can tell delegates to "fire the fast agent via
|
|
@@ -23,40 +100,50 @@ function stripTrailingSlashes(value: string): string {
|
|
|
23
100
|
* though those delegates have no task tool and must do the dispatched work.
|
|
24
101
|
* Keep project-local files by default: they usually contain coding conventions
|
|
25
102
|
* delegates need. With no project directory, every instruction file is global.
|
|
26
|
-
*
|
|
103
|
+
*
|
|
104
|
+
* A section runs from its marker to the next marker or the end of the entry;
|
|
105
|
+
* only the marker line plus the named file's contents are removed from it.
|
|
106
|
+
* The host holds its own reference to `output.system` and reads it back after
|
|
107
|
+
* the hook, so the array is mutated in place and never rebound.
|
|
27
108
|
*/
|
|
28
109
|
export function stripDelegateInstructions(
|
|
29
110
|
output: { system: string[] },
|
|
30
111
|
cfg: RouterConfig,
|
|
31
112
|
projectDirectory: string | undefined,
|
|
113
|
+
readFile: InstructionFileReader = readInstructionFile,
|
|
32
114
|
): void {
|
|
33
115
|
try {
|
|
34
116
|
const policy = cfg.delegateInstructions ?? "strip-global";
|
|
35
117
|
if (policy === "keep") return;
|
|
118
|
+
const system = output.system;
|
|
119
|
+
if (!Array.isArray(system)) return;
|
|
36
120
|
|
|
37
121
|
const normalize = (path: string): string =>
|
|
38
122
|
stripTrailingSlashes(path.trim().replace(/\\/g, "/").toLowerCase());
|
|
39
123
|
const project = projectDirectory ? normalize(projectDirectory) : undefined;
|
|
40
|
-
|
|
124
|
+
let changed = false;
|
|
125
|
+
const next = system.flatMap((entry) => {
|
|
41
126
|
if (typeof entry !== "string") return [entry];
|
|
42
127
|
// Horizontal whitespace only: a pathless marker must not consume the
|
|
43
128
|
// following line as its path. Preserve original line endings verbatim.
|
|
44
129
|
const sections = entry.split(/(?=^Instructions from:[^\S\r\n]*\S[^\r\n]*$)/m);
|
|
45
130
|
let removed = false;
|
|
46
|
-
const kept = sections.
|
|
47
|
-
const marker =
|
|
48
|
-
if (!marker) return
|
|
131
|
+
const kept = sections.map((section) => {
|
|
132
|
+
const marker = MARKER.exec(section);
|
|
133
|
+
if (!marker) return section;
|
|
49
134
|
const path = normalize(marker[1]!);
|
|
50
135
|
const local = project !== undefined &&
|
|
51
136
|
(path === project || path.startsWith(`${project}/`));
|
|
52
|
-
if (policy
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return true;
|
|
137
|
+
if (policy !== "strip-all" && local) return section;
|
|
138
|
+
const rest = removeInstructionBlock(section, marker[1]!.trim(), readFile);
|
|
139
|
+
if (rest !== section) removed = true;
|
|
140
|
+
return rest;
|
|
57
141
|
}).join("");
|
|
58
|
-
|
|
142
|
+
if (!removed) return [entry];
|
|
143
|
+
changed = true;
|
|
144
|
+
return kept.trim() ? [kept] : [];
|
|
59
145
|
});
|
|
146
|
+
if (changed) system.splice(0, system.length, ...next);
|
|
60
147
|
} catch {
|
|
61
148
|
// Fail soft: retain the original array if malformed runtime input prevents
|
|
62
149
|
// computing the replacement. Instruction filtering must not break a turn.
|
package/src/router/protocol.ts
CHANGED
|
@@ -113,7 +113,7 @@ export function buildDelegationProtocol(cfg: RouterConfig): string {
|
|
|
113
113
|
return [
|
|
114
114
|
`## Model Delegation Protocol (MANDATORY)`,
|
|
115
115
|
``,
|
|
116
|
-
`You are the orchestrator: route each task to the right tier and delegate it with \`Task(subagent_type="fast"|"medium"|"heavy", prompt="...")\`. Information-gathering (grep, read, glob, ls) is execution
|
|
116
|
+
`You are the orchestrator: route each task to the right tier and delegate it with \`Task(subagent_type="fast"|"medium"|"heavy", prompt="...")\`. Information-gathering (grep, read, glob, ls) is execution and goes to @fast by default; your one exception is an allowance of about 2 direct read-only calls per turn for lookups that settle a question outright, so dispatch @fast once you would exceed it. Synthesize the subagents' results and answer the user yourself.`,
|
|
117
117
|
``,
|
|
118
118
|
`Preset: ${cfg.activePreset}. Tiers: ${tierLine}.${modeSuffix}`,
|
|
119
119
|
``,
|
|
@@ -153,6 +153,33 @@ export function isClaudeModel(modelID: string | undefined): boolean {
|
|
|
153
153
|
return /\/claude-/.test(s) || /(^|[\/\-])claude-/.test(s);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Claude models that only accept adaptive thinking: a manually supplied
|
|
158
|
+
* thinking budget (and `{"type": "disabled"}`) is rejected. The list mirrors
|
|
159
|
+
* the catalogue entries carrying `rejects_disabled_thinking` in
|
|
160
|
+
* claude-code-wire-compat's 2.1.280 profile. Neighbours are deliberately not
|
|
161
|
+
* covered: `claude-opus-5` and `claude-mythos-5` still accept a budget.
|
|
162
|
+
*/
|
|
163
|
+
const ADAPTIVE_ONLY_CLAUDE_MODELS = [
|
|
164
|
+
"claude-opus-5-5",
|
|
165
|
+
"claude-fable-5",
|
|
166
|
+
"claude-fable-5-1",
|
|
167
|
+
"claude-mythos-5-1",
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
export function isAdaptiveOnlyClaudeModel(modelID: string | undefined): boolean {
|
|
171
|
+
if (!modelID || !isClaudeModel(modelID)) return false;
|
|
172
|
+
// Same family matching as isClaudeModel, plus dots folded to dashes so a
|
|
173
|
+
// provider re-spelling (`claude-fable-5.1`) lands on the catalogue id. The
|
|
174
|
+
// id must end at the model name, optionally followed by a date stamp
|
|
175
|
+
// (`-YYYYMMDD`, or the Vertex `@YYYYMMDD` form) and a bracketed tag (`[1m]`),
|
|
176
|
+
// so `claude-opus-5` never matches `claude-opus-5-5` and vice versa.
|
|
177
|
+
const s = modelID.toLowerCase().replace(/\./g, "-");
|
|
178
|
+
return ADAPTIVE_ONLY_CLAUDE_MODELS.some((id) =>
|
|
179
|
+
new RegExp(`(^|[\\/\\-])${id}([-@]\\d{8})?(\\[[^\\]]*\\])?$`).test(s),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
156
183
|
/** Per-tier adversarial openers. @fast/@medium use Tom 2 (scoping); @heavy uses Tom 1 (override). */
|
|
157
184
|
export const CLAUDE_TIER_PREFIX: Record<string, string> = {
|
|
158
185
|
fast: [
|
package/tiers.json
CHANGED
|
@@ -375,11 +375,11 @@
|
|
|
375
375
|
"default→@fast unless edits/complex-reasoning needed",
|
|
376
376
|
"@medium ONLY: multi-file-edit/refactor/test-suite/build-fix",
|
|
377
377
|
"@heavy ONLY: user-requested OR ≥2 @medium failures",
|
|
378
|
-
"trivial(grep/read/glob)→direct,
|
|
378
|
+
"trivial(grep/read/glob)→direct,spends orchestrator read-only allowance",
|
|
379
379
|
"batch related searches→single @fast",
|
|
380
380
|
"uncertain @fast vs @medium→@fast,escalate on fail",
|
|
381
381
|
"dispatch caps (tighter): always include CAP:5 when dispatching @fast, CAP:2 for @medium, CAP:2 for @heavy",
|
|
382
|
-
"orchestrator
|
|
382
|
+
"orchestrator read-only allowance: dispatch is default; ≤1 direct read-only call per turn; 2nd need → dispatch @fast"
|
|
383
383
|
]
|
|
384
384
|
},
|
|
385
385
|
"quality": {
|
|
@@ -401,7 +401,7 @@
|
|
|
401
401
|
"default→@medium for implementation and multi-file changes",
|
|
402
402
|
"@heavy for architecture/debug/security/tradeoff-analysis by default",
|
|
403
403
|
"allow long heavy runs before fallback; avoid premature downshift",
|
|
404
|
-
"trivial(grep/read/glob)→direct
|
|
404
|
+
"trivial one-off lookup(grep/read/glob) that settles the question→direct; further reads→@fast",
|
|
405
405
|
"if task is composite: explore@fast then execute@heavy",
|
|
406
406
|
"dispatch caps: CAP:none (with a `reason:` line) for @heavy only; @fast=CAP:8 and @medium=CAP:5 baselines apply",
|
|
407
407
|
"subagents still run redundancy check; CAP:none only lifts the numeric cap"
|
|
@@ -442,8 +442,8 @@
|
|
|
442
442
|
"plan:fast/cheap→@fast | plan:medium→@medium | plan:heavy→@heavy",
|
|
443
443
|
"default preference: read-only work → @fast; implementation → @medium",
|
|
444
444
|
"orchestrate=self, execute=subagent (info-gathering IS execution, not orchestration)",
|
|
445
|
-
"trivial (≤1 tool call, no expected follow-up) → direct,
|
|
446
|
-
"orchestrator
|
|
445
|
+
"trivial (≤1 tool call, no expected follow-up) → direct, spent from the orchestrator read-only allowance",
|
|
446
|
+
"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)",
|
|
447
447
|
"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)",
|
|
448
448
|
"before dispatching @heavy: gather context first (usually via @fast); if context is already sufficient, dispatch directly",
|
|
449
449
|
"if self is opus: skip-@heavy (do locally); still prefer routing broader read-only exploration to @fast",
|