opencode-model-router 1.2.0 → 1.3.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/README.md CHANGED
@@ -205,12 +205,15 @@ npm install -g opencode-model-router
205
205
  Add to `~/.config/opencode/opencode.json`:
206
206
  ```json
207
207
  {
208
- "plugin": {
209
- "opencode-model-router": {
210
- "type": "npm",
211
- "package": "opencode-model-router"
212
- }
213
- }
208
+ "plugin": [
209
+ [
210
+ "opencode-model-router",
211
+ {
212
+ "type": "npm",
213
+ "package": "opencode-model-router"
214
+ }
215
+ ]
216
+ ]
214
217
  }
215
218
  ```
216
219
 
@@ -224,18 +227,23 @@ npm install
224
227
  In `~/.config/opencode/opencode.json`:
225
228
  ```json
226
229
  {
227
- "plugin": {
228
- "opencode-model-router": {
229
- "type": "local",
230
- "path": "/absolute/path/to/opencode-model-router"
231
- }
232
- }
230
+ "plugin": [
231
+ [
232
+ "opencode-model-router",
233
+ {
234
+ "type": "local",
235
+ "package": "/absolute/path/to/opencode-model-router"
236
+ }
237
+ ]
238
+ ]
233
239
  }
234
240
  ```
235
241
 
236
242
  ## Configuration
237
243
 
238
- All configuration lives in `tiers.json` at the plugin root.
244
+ All configuration lives in `tiers.json` at the plugin root, which is located inside the cached package directory in your home folder (e.g. `~/.cache/opencode/packages/opencode-model-router@latest/node_modules/opencode-model-router/tiers.json`).
245
+
246
+ > ⚠️ **IMPORTANT**: You **must** edit this cached version of `tiers.json` for opencode to respect your changes and custom model configurations.
239
247
 
240
248
  ### Presets
241
249
 
@@ -579,9 +587,9 @@ Defines provider fallback order when a delegated task fails:
579
587
  }
580
588
  ```
581
589
 
582
- ## Enforced delegation (opt-in)
590
+ ## Delegation enforcement (advisory by default)
583
591
 
584
- 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 optional **enforcement layer** turns delegation into a produce → verify → accept/escalate loop with real hard-blocks, independent acceptance, and quality escalation. It is **opt-in and off by default** — with `enforcement` absent from `tiers.json` or `"mode": "off"` set explicitly, routing behaviour is byte-for-byte unchanged: zero added prompt tokens, zero new latency.
592
+ 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 orchestrator system prompt grows by ~200 tokens for the DoD/acceptance section, 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"`.
585
593
 
586
594
  ### The three enforcement layers
587
595
 
@@ -591,18 +599,18 @@ The read-only cap banners described above are advisory: a well-behaved subagent
591
599
 
592
600
  ### Two operating modes
593
601
 
594
- - **Mode A — on-the-fly.** The orchestrator calls the plugin's `delegate` tool (or a raw `Task()` call is observed and annotated) and the full enforcement pipeline runs automatically.
602
+ - **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.)
595
603
  - **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.
596
604
 
597
- ### Enabling enforcement
605
+ ### Tuning enforcement
598
606
 
599
- Three equivalent ways to turn it on:
607
+ Advisory is the default. To change the level:
600
608
 
601
- 1. Add an `enforcement` block to `tiers.json` with `"mode": "advisory"` or `"mode": "enforced"` (see `docs/CONFIG_REFERENCE.md`).
602
- 2. Set `MODEL_ROUTER_ENFORCE=1` in your environment to try it for a session (equivalent to `mode: "enforced"`).
609
+ 1. Add or edit the `enforcement` block in `tiers.json` — `"mode": "off"`, `"advisory"`, or `"enforced"` (see `docs/CONFIG_REFERENCE.md`).
610
+ 2. Set `MODEL_ROUTER_ENFORCE=1` to force `enforced` for a session, or `MODEL_ROUTER_ENFORCE=0` to force `off`.
603
611
  3. Run `/router enforce <off|advisory|enforced>` from the chat to toggle at runtime.
604
612
 
605
- **Modes:** `off` — no-op, identical to having no `enforcement` key; `advisory` — evaluates and surfaces guidance, never blocks (safe adoption step); `enforced` — hard-blocks active, full produce → verify → accept/escalate pipeline.
613
+ **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.
606
614
 
607
615
  > Enforcement applies to subagent/delegate sessions only. The orchestrator session is never hard-blocked.
608
616
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^25.2.3",
48
- "@vitest/coverage-v8": "^3.2.4",
48
+ "@vitest/coverage-v8": "^4.1.8",
49
49
  "cross-env": "^7.0.3",
50
50
  "typescript": "^5.9.3",
51
- "vitest": "^3.2.4"
51
+ "vitest": "^4.1.8"
52
52
  }
53
53
  }
package/src/index.ts CHANGED
@@ -422,9 +422,13 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
422
422
  // current plugin lifetime (i.e., until OpenCode is restarted).
423
423
  let bypassed = false;
424
424
 
425
+ const enableDelegateTool =
426
+ cfg.experimental?.verifiedDelegateTool === true ||
427
+ process.env.MODEL_ROUTER_VERIFIED_DELEGATE === "1";
428
+
425
429
  return {
426
430
  tool: {
427
- delegate: tool({
431
+ ...(enableDelegateTool ? { delegate: tool({
428
432
  description:
429
433
  "Delegate a task to a tier subagent (fast | medium | heavy). The subagent's result is INDEPENDENTLY VERIFIED (deterministic checks, or an independent grader at >= the producer tier in a fresh session) before it is returned. Returns an accepted result on PASS, or an honest 'unmet' status on FAIL — never a self-reported completion. Optionally pass an [acceptance]...[/acceptance] block to define the Definition of Done.",
430
434
  args: {
@@ -613,7 +617,7 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
613
617
  return "[router] delegate failed (fail-closed): the delegation or verification could not complete.";
614
618
  }
615
619
  },
616
- }),
620
+ }) } : {}),
617
621
  },
618
622
 
619
623
  // -----------------------------------------------------------------------
@@ -778,7 +782,10 @@ const ModelRouterPlugin: Plugin = async (ctx: PluginInput) => {
778
782
  buildGateDeps(),
779
783
  );
780
784
  if (!res.accepted && !res.verdict.skipped) {
781
- const note = scrubText(buildForcingNote(res.verdict.reasons));
785
+ const ladder = cfg.enforcement?.escalate?.ladder ?? ["fast", "medium", "heavy"];
786
+ const li = ladder.indexOf(producerTier);
787
+ const nextTier = li >= 0 && li < ladder.length - 1 ? ladder[li + 1] : null;
788
+ const note = scrubText(buildForcingNote(res.verdict.reasons, { producerTier, nextTier }));
782
789
  output.output =
783
790
  typeof output.output === "string"
784
791
  ? output.output + "\n\n" + note
@@ -66,6 +66,8 @@ export interface RouterConfig {
66
66
  /** Read-only tool-call caps per tier, enforced at runtime via tool.execute.after banner injection. */
67
67
  tierCaps?: Record<string, number>;
68
68
  enforcement?: EnforcementConfig;
69
+ /** Experimental, opt-in features. Off by default. */
70
+ experimental?: { verifiedDelegateTool?: boolean };
69
71
  }
70
72
 
71
73
  export interface RouterState {
@@ -470,9 +472,9 @@ export function writeState(patch: Partial<RouterState>): void {
470
472
  // Enforcement helpers
471
473
  // ---------------------------------------------------------------------------
472
474
 
473
- /** Returns the effective enforcement mode. Missing enforcement ⇒ mode:"off". */
475
+ /** Returns the effective enforcement mode. Missing enforcement ⇒ mode:"advisory". */
474
476
  export function normalizeEnforcement(
475
477
  e: EnforcementConfig | undefined,
476
478
  ): { mode: "off" | "advisory" | "enforced" } {
477
- return { mode: e?.mode ?? "off" };
479
+ return { mode: e?.mode ?? "advisory" };
478
480
  }
@@ -33,7 +33,7 @@ export function resolveEnforcementMode(args: {
33
33
  }
34
34
 
35
35
  // Config resolution
36
- const base: EnforcementMode = enf?.mode ?? "off";
36
+ const base: EnforcementMode = enf?.mode ?? "advisory";
37
37
  let mode: EnforcementMode;
38
38
 
39
39
  if (
@@ -135,15 +135,24 @@ export function shouldVerifyTask(
135
135
  }
136
136
 
137
137
  /** Build the advisory forcing note appended to a task result the gate did not accept. */
138
- export function buildForcingNote(reasons: string[]): string {
138
+ export function buildForcingNote(
139
+ reasons: string[],
140
+ escalation?: { producerTier?: string; nextTier?: string | null },
141
+ ): string {
139
142
  const body =
140
143
  reasons.length > 0
141
144
  ? reasons.map((r) => `- ${r}`).join("\n")
142
145
  : "- (no reasons provided)";
146
+ const next =
147
+ escalation?.nextTier
148
+ ? `NEXT: address the above, then re-run via \`Task(subagent_type="${escalation.nextTier}")\`` +
149
+ `${escalation.producerTier ? ` (escalated from ${escalation.producerTier})` : ""}; ` +
150
+ `do not treat the prior result as complete.`
151
+ : `NEXT: address the above and re-run the delegation; do not treat the prior result as complete.`;
143
152
  return (
144
153
  `[router \u26a0 NOT ACCEPTED] The delegated result was not accepted by independent verification:\n` +
145
154
  `${body}\n` +
146
- `NEXT: address the above and re-run the delegation; do not treat the prior result as complete.`
155
+ next
147
156
  );
148
157
  }
149
158
 
package/tiers.json CHANGED
@@ -94,7 +94,7 @@
94
94
  },
95
95
  "github-copilot": {
96
96
  "fast": {
97
- "model": "github-copilot/claude-haiku-4-5",
97
+ "model": "github-copilot/claude-haiku-4.5",
98
98
  "costRatio": 1,
99
99
  "description": "Claude Haiku 4.5 via GitHub Copilot for fast exploration and simple tasks",
100
100
  "steps": 30,
@@ -106,9 +106,9 @@
106
106
  ]
107
107
  },
108
108
  "medium": {
109
- "model": "github-copilot/claude-sonnet-4-6",
109
+ "model": "github-copilot/claude-sonnet-4.6",
110
110
  "costRatio": 5,
111
- "description": "Claude Sonnet 4.5 via GitHub Copilot for implementation, refactoring, and tests",
111
+ "description": "Claude Sonnet 4.6 via GitHub Copilot for implementation, refactoring, and tests",
112
112
  "steps": 50,
113
113
  "whenToUse": [
114
114
  "Feature implementation",
@@ -119,8 +119,7 @@
119
119
  ]
120
120
  },
121
121
  "heavy": {
122
- "model": "github-copilot/claude-opus-4-6",
123
- "variant": "thinking",
122
+ "model": "github-copilot/claude-opus-4.6",
124
123
  "costRatio": 20,
125
124
  "description": "Claude Opus 4.6 via GitHub Copilot for architecture, complex debugging, and security",
126
125
  "steps": 120,