opencode-model-router 1.1.7 → 1.1.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +23 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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
@@ -580,7 +580,24 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
580
580
  let cfg = loadConfig();
581
581
  const activeTiers = getActiveTiers(cfg);
582
582
 
583
+ // Track child (subagent) sessions so we can skip delegation protocol
584
+ // injection for them. Child sessions have a parentID — primary sessions don't.
585
+ const subagentSessionIDs = new Set<string>();
586
+
583
587
  return {
588
+ // -----------------------------------------------------------------------
589
+ // Track subagent sessions via session lifecycle events
590
+ // -----------------------------------------------------------------------
591
+ event: async (input: { event: any }) => {
592
+ const evt = input.event;
593
+ if (evt.type === "session.created" && evt.properties?.info?.parentID) {
594
+ subagentSessionIDs.add(evt.properties.info.id);
595
+ }
596
+ if (evt.type === "session.deleted") {
597
+ subagentSessionIDs.delete(evt.properties?.info?.id);
598
+ }
599
+ },
600
+
584
601
  // -----------------------------------------------------------------------
585
602
  // Register tier agents + commands at load time
586
603
  // -----------------------------------------------------------------------
@@ -659,8 +676,8 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
659
676
  // -----------------------------------------------------------------------
660
677
  // Inject delegation protocol — uses cached config (invalidated on /preset or /budget)
661
678
  // Only inject for the primary orchestrator, NOT for subagent calls.
662
- // Smaller models (e.g. Haiku) get confused by delegation instructions
663
- // when they're supposed to just execute a task.
679
+ // Subagents get confused by delegation instructions when they should
680
+ // just execute a task (especially smaller models like Haiku).
664
681
  // -----------------------------------------------------------------------
665
682
  "experimental.chat.system.transform": async (_input: any, output: any) => {
666
683
  try {
@@ -669,20 +686,10 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
669
686
  // Use last known config if file read fails
670
687
  }
671
688
 
672
- // Skip injection when the model matches a registered subagent tier.
673
- // This prevents subagents from seeing delegation instructions that
674
- // conflict with their task-executor role.
675
- const model = _input?.model;
676
- if (model) {
677
- const tiers = getActiveTiers(cfg);
678
- const isSubagentModel = Object.values(tiers).some((tier) => {
679
- const parts = tier.model.split("/");
680
- const providerID = parts[0];
681
- const modelID = parts.slice(1).join("/");
682
- return model.providerID === providerID && model.id === modelID;
683
- });
684
- if (isSubagentModel) return;
685
- }
689
+ // Skip injection for child (subagent) sessions.
690
+ // Child sessions are detected via session.created events with a parentID.
691
+ const sessionID = _input?.sessionID;
692
+ if (sessionID && subagentSessionIDs.has(sessionID)) return;
686
693
 
687
694
  output.system.push(buildDelegationProtocol(cfg));
688
695
  },