opencode-model-router 1.2.0 → 1.3.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/README.md CHANGED
@@ -579,9 +579,9 @@ Defines provider fallback order when a delegated task fails:
579
579
  }
580
580
  ```
581
581
 
582
- ## Enforced delegation (opt-in)
582
+ ## Delegation enforcement (advisory by default)
583
583
 
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.
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 **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
585
 
586
586
  ### The three enforcement layers
587
587
 
@@ -591,18 +591,18 @@ The read-only cap banners described above are advisory: a well-behaved subagent
591
591
 
592
592
  ### Two operating modes
593
593
 
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.
594
+ - **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
595
  - **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
596
 
597
- ### Enabling enforcement
597
+ ### Tuning enforcement
598
598
 
599
- Three equivalent ways to turn it on:
599
+ Advisory is the default. To change the level:
600
600
 
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"`).
601
+ 1. Add or edit the `enforcement` block in `tiers.json` — `"mode": "off"`, `"advisory"`, or `"enforced"` (see `docs/CONFIG_REFERENCE.md`).
602
+ 2. Set `MODEL_ROUTER_ENFORCE=1` to force `enforced` for a session, or `MODEL_ROUTER_ENFORCE=0` to force `off`.
603
603
  3. Run `/router enforce <off|advisory|enforced>` from the chat to toggle at runtime.
604
604
 
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.
605
+ **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
606
 
607
607
  > Enforcement applies to subagent/delegate sessions only. The orchestrator session is never hard-blocked.
608
608
 
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.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",
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