@alexeiled/claude-router 1.1.0 → 1.1.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "router",
3
3
  "displayName": "Router",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "Model and effort routing for the main conversation, advised by a prompt classifier (Jev). Preserves subagent model choices.",
6
6
  "author": {
7
7
  "name": "Alexei Ledenev",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.1 (2026-10-05)
4
+
5
+ ### Fixed
6
+
7
+ - The credits cap now also guards downgrades and failure escalations. It checked only upgrades, so a downgrade or an escalation could start with a cold cache write above `policy.cashCapUsd` on a `credits` model. A blocked switch now stays on the current tier, or moves to the strongest `plan` tier above it. Default routes use `plan` models and are not affected.
8
+
3
9
  ## 1.1.0 (2026-10-05)
4
10
 
5
11
  ### Added
package/README.md CHANGED
@@ -74,6 +74,12 @@ In Claude Code, run `/plugin configure router` and save your Jev API key in the
74
74
 
75
75
  Run `/router` to open the pane: route status, per-tier controls, tuning, and usage. Run `/model` to select a model and enter Manual mode, and `/router auto` to resume. For controls, metrics, tuning, and troubleshooting, see the [user guide](docs/user-guide.md).
76
76
 
77
+ Before a push, run the same checks as CI. `npm run validate` and `npm run test:plugin` need the `claude` CLI: they load the Mod in the Claude Code engine, which refuses some faults that lint and unit tests miss.
78
+
79
+ ```sh
80
+ npm run check && npm test && npm run validate && npm run test:plugin
81
+ ```
82
+
77
83
  ## Documentation
78
84
 
79
85
  - [User guide](docs/user-guide.md): install, use the controls, read the panel, and troubleshoot.
@@ -44,7 +44,8 @@ Claude Code builds each request for the model the Mod selects, so no request rew
44
44
  | [Router controller](../lib/native-router.mjs) | Context fit, model identity, cache observations, and one-turn pins. |
45
45
  | [Policy](../lib/policy.mjs) | Tier votes, escalation, and switching gates. |
46
46
  | [Native costs](../lib/native-cost.mjs) | Cache uncertainty bounds and switching estimates. |
47
- | [Native panel](../lib/native-panel.mjs) | Route status, usage metrics, controls, and validated tuning. |
47
+ | [Native panel](../lib/native-panel.mjs) | Tabbed pane: route status, tier pins, the route editor, tuning, and usage. |
48
+ | [Router band](../lib/native-band.mjs) | Status band segments fitted to the band's width, and route-change toasts. |
48
49
  | Claude Code | API requests, tools, authentication, stream output, and usage ledger. |
49
50
 
50
51
  Node.js is not part of routing. It is used for development and the optional v0.8 configuration migration.
package/lib/policy.mjs CHANGED
@@ -16,7 +16,9 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
16
16
  next.escalatedSignature = facts.failure.signature;
17
17
  next.holdUntilTurn = next.turn + config.policy.escalationHoldTurns;
18
18
  next.votes = [];
19
- return result(TIERS[rank(incumbent) + 1], 'escalation', next);
19
+ const target = TIERS[rank(incumbent) + 1];
20
+ const gated = cashGate(config, target, facts, now, costs);
21
+ return gated.blocked ? gatedResult(gated, incumbent, next) : result(target, 'escalation', next);
20
22
  }
21
23
  if (next.turn <= next.holdUntilTurn) return stay('hold');
22
24
  if (!advice) return stay('no-advice');
@@ -30,10 +32,7 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
30
32
  if (rank(choice) > rank(incumbent)) {
31
33
  const upgrade = massAbove(advice.probabilities, incumbent);
32
34
  const gated = cashGate(config, choice, facts, now, costs);
33
- if (gated.blocked) {
34
- if (!gated.fallback || rank(gated.fallback) <= rank(incumbent)) return stay('cash-gate', gated.estimate);
35
- return result(gated.fallback, 'cash-gate', next, gated.estimate);
36
- }
35
+ if (gated.blocked) return gatedResult(gated, incumbent, next);
37
36
  const tax = Math.max(0, costs.switchingTaxUsd(config, choice, incumbent, facts, now));
38
37
  const threshold =
39
38
  config.policy.upgradeBase + config.policy.upgradeSlope * (tax / (tax + config.policy.upgradePivotUsd));
@@ -57,8 +56,10 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
57
56
  const threshold =
58
57
  config.policy.downgradeMass + config.policy.downgradeSlope * (tax / (tax + config.policy.downgradePivotUsd));
59
58
  const estimate = { downgradeMass: support, streak, taxUsd: tax, threshold };
60
- if (support >= threshold && streak >= config.policy.downgradeVotes)
61
- return result(choice, 'downgrade', next, estimate);
59
+ if (support >= threshold && streak >= config.policy.downgradeVotes) {
60
+ const gated = cashGate(config, choice, facts, now, costs);
61
+ return gated.blocked ? gatedResult(gated, incumbent, next) : result(choice, 'downgrade', next, estimate);
62
+ }
62
63
  return stay('downgrade-pending', estimate);
63
64
  }
64
65
 
@@ -79,7 +80,7 @@ export function fitTier(config, tier, tokens) {
79
80
  );
80
81
  }
81
82
 
82
- // Cold-write guard: an automatic route to a credits-billed model whose cache is not warm must not start with a cache
83
+ // Cold-write guard: an automatic route (upgrade, downgrade or escalation) to a credits-billed model whose cache is not warm must not start with a cache
83
84
  // write above `cashCapUsd`. It bounds that one estimated write, not the spend of the turn: a warm cache passes, and
84
85
  // output is not counted.
85
86
  function cashGate(config, tier, facts, now, costs) {
@@ -94,6 +95,12 @@ function cashGate(config, tier, facts, now, costs) {
94
95
  return { blocked: true, fallback, estimate };
95
96
  }
96
97
 
98
+ // A blocked switch lands on the strongest plan tier when that is above the incumbent, else stays.
99
+ function gatedResult(gated, incumbent, state) {
100
+ const tier = gated.fallback && rank(gated.fallback) > rank(incumbent) ? gated.fallback : incumbent;
101
+ return result(tier, 'cash-gate', state, gated.estimate);
102
+ }
103
+
97
104
  function cacheOf(config, tier, facts, now, costs) {
98
105
  return costs.cacheState(facts.models[costs.routeCacheKey(config, tier, facts.effort)], now, config.cache);
99
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexeiled/claude-router",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Native Claude Code Mod: Jev model and effort routing for the main conversation.",
5
5
  "license": "MIT",
6
6
  "author": "Alexei Ledenev",
@@ -31,6 +31,7 @@
31
31
  "test": "node --test --test-timeout=8000 test/*.test.mjs",
32
32
  "check": "biome check lib scripts test hooks types .claude-plugin package.json package-lock.json biome.json experiments/mod-router",
33
33
  "validate": "claude plugin validate .claude-plugin/plugin.json && claude plugin validate .claude-plugin/marketplace.json",
34
+ "test:plugin": "bash scripts/plugin-test.sh",
34
35
  "format": "biome format --write .",
35
36
  "docs:images": "node scripts/render-doc-images.mjs",
36
37
  "pack:dry": "npm pack --dry-run",