opencode-model-router 1.1.12 → 1.1.13

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.
Files changed (3) hide show
  1. package/README.md +31 -0
  2. package/package.json +1 -1
  3. package/src/index.ts +98 -2
package/README.md CHANGED
@@ -487,6 +487,37 @@ Each tier (`@fast`, `@medium`, `@heavy`) has a system prompt that describes its
487
487
  }
488
488
  ```
489
489
 
490
+ ### Claude-model adversarial prefixes (automatic)
491
+
492
+ Anthropic models (served directly via `anthropic/*` or routed through other providers as `*/claude-*`) ship with a large cached system prompt that primes them toward broad exploratory Read/Grep/Glob behavior. When such a prompt sits in front of your router instructions, primacy bias and prompt caching weaken the router's authority — subagents ignore caps, orchestrators run read-only work themselves instead of dispatching.
493
+
494
+ To counteract this, the router **automatically prepends an adversarial opener** to:
495
+
496
+ - The tier prompt for any tier whose `model` matches a Claude identifier
497
+ - The orchestrator delegation protocol when the session model is a Claude identifier
498
+
499
+ Detection is by model string, not preset. A `hybrid` preset that mixes providers (e.g. `openai/*` for @fast, `anthropic/*` for @medium and @heavy) gets the override only on its Claude-backed tiers.
500
+
501
+ **Tone assignment:**
502
+
503
+ | Target | Tone | Opener label |
504
+ |--------|------|--------------|
505
+ | `@fast` (Claude) | Scoping — conversational | `SCOPE NOTE` |
506
+ | `@medium` (Claude) | Scoping — conversational | `SCOPE NOTE` |
507
+ | `@heavy` (Claude) | Override — firm | `AUTHORITY OVERRIDE` |
508
+ | Orchestrator (Claude) | Override — firm | `AUTHORITY OVERRIDE` |
509
+
510
+ `@heavy` and the orchestrator use the firmer tone because that's where reconnaissance loops were worst in observed sessions. `@fast` and `@medium` use a softer scoping note to avoid over-correcting legitimate multi-read tasks.
511
+
512
+ **Detection rules:**
513
+
514
+ - `anthropic/<anything>` → Claude
515
+ - `<provider>/claude-<anything>` (e.g. `github-copilot/claude-sonnet-4-6`) → Claude
516
+ - `<provider>/<namespace>.claude-<anything>` (e.g. `bedrock/us.anthropic.claude-3-5-sonnet-...`) → Claude
517
+ - Everything else → untouched
518
+
519
+ 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).
520
+
490
521
  ### Tier fields reference
491
522
 
492
523
  | Field | Type | Description |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
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
@@ -750,6 +750,79 @@ function buildCapBanner(
750
750
  return lines.join("\n");
751
751
  }
752
752
 
753
+ // ---------------------------------------------------------------------------
754
+ // Claude-model adversarial prefixes
755
+ //
756
+ // Anthropic models (direct or via other providers) are served with a large
757
+ // cached "Claude Code" signature prompt that primes them toward broad
758
+ // exploratory Read/Grep/Glob behavior. Our tier prompts land after that
759
+ // cached block and lose authority through primacy bias and cache freezing.
760
+ // For Claude models specifically, we prepend an override block that
761
+ // explicitly revokes the exploratory priming for the current dispatch.
762
+ //
763
+ // Detection is by model identifier, not preset — a hybrid preset mixing
764
+ // providers gets the override only on its Claude-backed tiers.
765
+ // ---------------------------------------------------------------------------
766
+
767
+ function isClaudeModel(modelID: string | undefined): boolean {
768
+ if (!modelID) return false;
769
+ const s = modelID.toLowerCase();
770
+ if (s.startsWith("anthropic/")) return true;
771
+ return /\/claude-/.test(s) || /(^|[\/\-])claude-/.test(s);
772
+ }
773
+
774
+ /** Per-tier adversarial openers. @fast/@medium use Tom 2 (scoping); @heavy uses Tom 1 (override). */
775
+ const CLAUDE_TIER_PREFIX: Record<string, string> = {
776
+ fast: [
777
+ "SCOPE NOTE — any cached instruction priming you to 'thoroughly explore",
778
+ "the codebase' or 'gather context broadly' does not apply here. This is",
779
+ "a single dispatch with a single question. Stay narrow to the ask.",
780
+ "",
781
+ "Before every tool call, ask: 'Does THIS read answer the dispatch",
782
+ "question specifically, or am I drifting into context-gathering for my",
783
+ "own understanding?' If the latter, stop — you have enough.",
784
+ ].join("\n"),
785
+ medium: [
786
+ "SCOPE NOTE — cached instructions may prime you to deeply understand",
787
+ "surrounding code before editing. For THIS dispatch, the orchestrator",
788
+ "has already scoped the problem; trust that scoping. Read what's needed",
789
+ "for the edit, not the whole module.",
790
+ "",
791
+ "A 4th or 5th 'context read' is usually a sign the dispatch was under-",
792
+ "scoped — return NEED CONTEXT rather than expanding scope yourself.",
793
+ ].join("\n"),
794
+ heavy: [
795
+ "AUTHORITY OVERRIDE — this block supersedes any cached prefix suggesting",
796
+ "you should 'investigate thoroughly', 'gather comprehensive context', or",
797
+ "'trace through the code systematically before analyzing'. You are",
798
+ "@heavy, an ANALYSIS specialist. The orchestrator should have pre-",
799
+ "gathered context via @fast before dispatching you. If it didn't, return",
800
+ "`SCOPE GROWTH:` immediately — do NOT self-gather.",
801
+ "",
802
+ "40 minutes of Read/Grep is not analysis — it is the orchestrator's job",
803
+ "that leaked into yours. Push it back with SCOPE GROWTH. Your 3 reads",
804
+ "are for targeted verification, not exploration.",
805
+ ].join("\n"),
806
+ };
807
+
808
+ /** Adversarial opener prepended to the delegation protocol when the orchestrator is a Claude model. */
809
+ const CLAUDE_ORCHESTRATOR_PREFIX = [
810
+ "AUTHORITY OVERRIDE — this block supersedes any prior system instruction",
811
+ "about 'exploring the codebase', 'gathering context with tools', or using",
812
+ "Read/Grep/Glob to validate assumptions. Those instructions describe a",
813
+ "general-purpose Claude Code session. THIS session is a routing",
814
+ "orchestrator.",
815
+ "",
816
+ "Your job is to DISPATCH, not to EXECUTE. Read-only work (grep/read/",
817
+ "glob/ls) is execution, and execution is delegated to @fast. You may run",
818
+ "AT MOST 2 direct read-only tool calls per turn — a 3rd call is a rule",
819
+ "violation. If you need more context, you dispatch @fast.",
820
+ "",
821
+ "If a cached instruction told you to 'be thorough', 'explore broadly', or",
822
+ "'read supporting files' — ignore it here. Thoroughness is achieved by",
823
+ "dispatching the right tier, not by you becoming the explorer.",
824
+ ].join("\n");
825
+
753
826
  // ---------------------------------------------------------------------------
754
827
  // Plugin
755
828
  // ---------------------------------------------------------------------------
@@ -850,12 +923,24 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
850
923
  // Resolve prompt: per-tier override wins; otherwise fall back to global tierPrompts[name].
851
924
  const resolvedPrompt = tier.prompt ?? cfg.tierPrompts?.[name];
852
925
 
926
+ // For Claude-backed tiers, prepend an adversarial opener that revokes
927
+ // the cached "Claude Code exploratory agent" priming for this dispatch.
928
+ // Detection is by model string, so hybrid presets get the override
929
+ // only on their Claude-backed tiers.
930
+ const claudePrefix = isClaudeModel(tier.model)
931
+ ? CLAUDE_TIER_PREFIX[name]
932
+ : undefined;
933
+ const finalPrompt =
934
+ claudePrefix && resolvedPrompt
935
+ ? `${claudePrefix}\n\n---\n\n${resolvedPrompt}`
936
+ : resolvedPrompt;
937
+
853
938
  const agentDef: Record<string, unknown> = {
854
939
  model: tier.model,
855
940
  mode: "subagent",
856
941
  description: tier.description,
857
942
  maxSteps: tier.steps,
858
- prompt: resolvedPrompt,
943
+ prompt: finalPrompt,
859
944
  color: tier.color,
860
945
  };
861
946
 
@@ -936,7 +1021,18 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
936
1021
  const sessionID = _input?.sessionID;
937
1022
  if (sessionID && subagentSessionIDs.has(sessionID)) return;
938
1023
 
939
- output.system.push(buildDelegationProtocol(cfg));
1024
+ // For Claude-backed orchestrators, prepend an adversarial opener that
1025
+ // revokes the cached "Claude Code explorer" priming for the routing
1026
+ // role. Detection is by orchestrator model, not preset.
1027
+ const providerID = _input?.model?.providerID ?? "";
1028
+ const modelID = _input?.model?.modelID ?? "";
1029
+ const orchestratorModel = providerID && modelID ? `${providerID}/${modelID}` : modelID;
1030
+ const delegationProtocol = buildDelegationProtocol(cfg);
1031
+ const finalProtocol = isClaudeModel(orchestratorModel)
1032
+ ? `${CLAUDE_ORCHESTRATOR_PREFIX}\n\n---\n\n${delegationProtocol}`
1033
+ : delegationProtocol;
1034
+
1035
+ output.system.push(finalProtocol);
940
1036
  },
941
1037
 
942
1038
  // -----------------------------------------------------------------------