opencode-model-router 1.1.13 → 1.1.14
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 +32 -0
- package/package.json +1 -1
- package/src/index.ts +94 -2
package/README.md
CHANGED
|
@@ -518,6 +518,38 @@ Detection is by model string, not preset. A `hybrid` preset that mixes providers
|
|
|
518
518
|
|
|
519
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
520
|
|
|
521
|
+
### Anti-narration guardrail (Claude models)
|
|
522
|
+
|
|
523
|
+
Thinking-enabled Claude models (especially Sonnet with the `max` variant) sometimes produce progress narration instead of actual work — phrasings like *"Still writing the X function..."*, *"Now I'll implement Y..."*, *"Let me add Z..."* — without the X/Y/Z ever appearing. This is a known thinking-mode failure pattern.
|
|
524
|
+
|
|
525
|
+
The router counters this on two layers:
|
|
526
|
+
|
|
527
|
+
**1. Prompt-level clause (prevention).** A dedicated `ANTI-NARRATION` block is appended to every Claude-backed tier prompt and to the Claude-backed orchestrator delegation protocol. It names the forbidden phrasings explicitly and requires concrete output to follow any such phrase. A carve-out preserves legitimate explanation/plan requests from the user.
|
|
528
|
+
|
|
529
|
+
**2. Post-hoc detector (telemetry).** An `experimental.text.complete` hook scans completed text for narration regex patterns. On match, it:
|
|
530
|
+
|
|
531
|
+
- Logs a warning to the plugin console:
|
|
532
|
+
```
|
|
533
|
+
[model-router] narration detected (session abc123): "Still writing the auth", "Now I'll add the tests"
|
|
534
|
+
```
|
|
535
|
+
- Appends a visible banner to the text as it's rendered to the user:
|
|
536
|
+
```
|
|
537
|
+
[⚠ narration detected: "Still writing the auth", "Now I'll add the tests"]
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
The detector is not blocking — plugin hooks cannot modify tokens mid-stream. It signals post-hoc so you can spot the pattern in the UI and in logs, and judge whether the prompt-level clause is holding up.
|
|
541
|
+
|
|
542
|
+
Detected patterns (conservative set to minimize false positives):
|
|
543
|
+
|
|
544
|
+
- `Still (writing|implementing|working on|...) the X`
|
|
545
|
+
- `Now (I'll)? (write|implement|add|...) the X`
|
|
546
|
+
- `Let me (write|implement|add|...) (the )? X`
|
|
547
|
+
- `I'll (now)? (write|implement|...) the X`
|
|
548
|
+
- `Going to (write|implement|...) the X`
|
|
549
|
+
- `Continuing (with|by ...ing) (the )? X`
|
|
550
|
+
|
|
551
|
+
Applies to all models, not only Claude — but the prompt-level clause is Claude-only, so non-Claude models get detector-only.
|
|
552
|
+
|
|
521
553
|
### Tier fields reference
|
|
522
554
|
|
|
523
555
|
| Field | Type | Description |
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -823,6 +823,73 @@ const CLAUDE_ORCHESTRATOR_PREFIX = [
|
|
|
823
823
|
"dispatching the right tier, not by you becoming the explorer.",
|
|
824
824
|
].join("\n");
|
|
825
825
|
|
|
826
|
+
/**
|
|
827
|
+
* Anti-narration clause appended to every Claude-model prefix (tier + orchestrator).
|
|
828
|
+
*
|
|
829
|
+
* Thinking-enabled Claude models (esp. Sonnet with `max` variant) sometimes
|
|
830
|
+
* produce progress narration in place of actual work — "Still writing X...",
|
|
831
|
+
* "Now I'll implement Y...", "Let me add Z..." — without the X/Y/Z ever
|
|
832
|
+
* appearing. This clause names the pattern, lists specific forbidden phrasings
|
|
833
|
+
* (A3 — exemplified), and carves out an escape valve for legitimate
|
|
834
|
+
* explanation/plan requests (A2 — with exception).
|
|
835
|
+
*/
|
|
836
|
+
const CLAUDE_ANTI_NARRATION = [
|
|
837
|
+
"ANTI-NARRATION — do NOT write progress commentary in your response or",
|
|
838
|
+
"thinking output. Forbidden phrasings include:",
|
|
839
|
+
" - \"Still writing the X function...\"",
|
|
840
|
+
" - \"Now I'll implement Y...\"",
|
|
841
|
+
" - \"Let me add Z...\"",
|
|
842
|
+
" - \"Continuing with W...\"",
|
|
843
|
+
" - \"Going to fix V...\"",
|
|
844
|
+
"",
|
|
845
|
+
"Each of these signals planning without production. If you write one, the",
|
|
846
|
+
"NEXT tokens MUST contain the actual artifact (the code, the edit, the",
|
|
847
|
+
"concrete output). Otherwise, stop and return with status.",
|
|
848
|
+
"",
|
|
849
|
+
"Exception: when the user explicitly asks for an explanation, plan, or",
|
|
850
|
+
"walkthrough, prose is welcome — this rule targets unsolicited progress",
|
|
851
|
+
"narration during code and implementation tasks.",
|
|
852
|
+
].join("\n");
|
|
853
|
+
|
|
854
|
+
// ---------------------------------------------------------------------------
|
|
855
|
+
// Narration detector (telemetry — logs + appends banner)
|
|
856
|
+
// ---------------------------------------------------------------------------
|
|
857
|
+
|
|
858
|
+
/** Regex patterns that flag progress narration without production. */
|
|
859
|
+
const NARRATION_PATTERNS: RegExp[] = [
|
|
860
|
+
// "Still writing the X", "Still implementing the Y"
|
|
861
|
+
/\bstill\s+(writing|implementing|working on|adding|creating|fixing|building|refactoring|handling)\s+(the\s+)?\w+/gi,
|
|
862
|
+
// "Now I'll write the X", "Now writing the Y"
|
|
863
|
+
/\bnow\s+(i['']ll\s+)?(writ|implement|add|creat|work|fix|build|handl|refactor|updat|mov)\w*\s+(the\s+)?\w+/gi,
|
|
864
|
+
// "Let me write X", "Let me implement Y"
|
|
865
|
+
/\blet\s+me\s+(write|implement|add|create|fix|build|handle|refactor|work on|move|update|set up)\s+(the\s+)?\w+/gi,
|
|
866
|
+
// "I'll write the X", "I'll now implement Y"
|
|
867
|
+
/\bi['']ll\s+(now\s+)?(write|implement|add|create|fix|build|handle|refactor|set up|work on|move|update)\s+(the\s+)?\w+/gi,
|
|
868
|
+
// "Going to fix the X"
|
|
869
|
+
/\bgoing\s+to\s+(write|implement|add|create|fix|build|handle|refactor|set up|work on|move|update)\s+(the\s+)?\w+/gi,
|
|
870
|
+
// "Continuing with X", "Continuing by adding Y"
|
|
871
|
+
/\bcontinuing\s+(with|by\s+\w+ing)\s+(the\s+)?\w+/gi,
|
|
872
|
+
];
|
|
873
|
+
|
|
874
|
+
/** Returns matched narration phrases, deduped and capped. Empty array = no narration detected. */
|
|
875
|
+
function detectNarration(text: string): string[] {
|
|
876
|
+
if (text.length < 20) return [];
|
|
877
|
+
const seen = new Set<string>();
|
|
878
|
+
const out: string[] = [];
|
|
879
|
+
for (const pattern of NARRATION_PATTERNS) {
|
|
880
|
+
const matches = text.match(pattern);
|
|
881
|
+
if (!matches) continue;
|
|
882
|
+
for (const m of matches) {
|
|
883
|
+
const trimmed = m.trim().toLowerCase();
|
|
884
|
+
if (seen.has(trimmed)) continue;
|
|
885
|
+
seen.add(trimmed);
|
|
886
|
+
out.push(m.trim());
|
|
887
|
+
if (out.length >= 5) return out;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return out;
|
|
891
|
+
}
|
|
892
|
+
|
|
826
893
|
// ---------------------------------------------------------------------------
|
|
827
894
|
// Plugin
|
|
828
895
|
// ---------------------------------------------------------------------------
|
|
@@ -913,6 +980,31 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
|
|
|
913
980
|
output.output = existing ? `${existing}\n\n${banner}` : banner;
|
|
914
981
|
},
|
|
915
982
|
|
|
983
|
+
// -----------------------------------------------------------------------
|
|
984
|
+
// Narration detector — flags progress-commentary-without-production.
|
|
985
|
+
//
|
|
986
|
+
// Fires per completed text part. Scans for narration patterns; if any
|
|
987
|
+
// match, logs a warning to the plugin console and appends a visible
|
|
988
|
+
// banner to the text so the user sees the detection in the UI. This is
|
|
989
|
+
// telemetry, not blocking — we cannot modify mid-stream generation, only
|
|
990
|
+
// post-hoc signal.
|
|
991
|
+
// -----------------------------------------------------------------------
|
|
992
|
+
"experimental.text.complete": async (input: any, output: any) => {
|
|
993
|
+
const text = output?.text;
|
|
994
|
+
if (typeof text !== "string" || text.length < 20) return;
|
|
995
|
+
|
|
996
|
+
const found = detectNarration(text);
|
|
997
|
+
if (found.length === 0) return;
|
|
998
|
+
|
|
999
|
+
const quoted = found
|
|
1000
|
+
.map((m) => `"${m.slice(0, 60)}${m.length > 60 ? "…" : ""}"`)
|
|
1001
|
+
.join(", ");
|
|
1002
|
+
console.warn(
|
|
1003
|
+
`[model-router] narration detected (session ${input?.sessionID ?? "?"}): ${quoted}`,
|
|
1004
|
+
);
|
|
1005
|
+
output.text = `${text}\n\n[⚠ narration detected: ${quoted}]`;
|
|
1006
|
+
},
|
|
1007
|
+
|
|
916
1008
|
// -----------------------------------------------------------------------
|
|
917
1009
|
// Register tier agents + commands at load time
|
|
918
1010
|
// -----------------------------------------------------------------------
|
|
@@ -928,7 +1020,7 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
|
|
|
928
1020
|
// Detection is by model string, so hybrid presets get the override
|
|
929
1021
|
// only on their Claude-backed tiers.
|
|
930
1022
|
const claudePrefix = isClaudeModel(tier.model)
|
|
931
|
-
? CLAUDE_TIER_PREFIX[name]
|
|
1023
|
+
? `${CLAUDE_TIER_PREFIX[name]}\n\n${CLAUDE_ANTI_NARRATION}`
|
|
932
1024
|
: undefined;
|
|
933
1025
|
const finalPrompt =
|
|
934
1026
|
claudePrefix && resolvedPrompt
|
|
@@ -1029,7 +1121,7 @@ const ModelRouterPlugin: Plugin = async (_ctx: PluginInput) => {
|
|
|
1029
1121
|
const orchestratorModel = providerID && modelID ? `${providerID}/${modelID}` : modelID;
|
|
1030
1122
|
const delegationProtocol = buildDelegationProtocol(cfg);
|
|
1031
1123
|
const finalProtocol = isClaudeModel(orchestratorModel)
|
|
1032
|
-
? `${CLAUDE_ORCHESTRATOR_PREFIX}\n\n---\n\n${delegationProtocol}`
|
|
1124
|
+
? `${CLAUDE_ORCHESTRATOR_PREFIX}\n\n${CLAUDE_ANTI_NARRATION}\n\n---\n\n${delegationProtocol}`
|
|
1033
1125
|
: delegationProtocol;
|
|
1034
1126
|
|
|
1035
1127
|
output.system.push(finalProtocol);
|