@alexeiled/claude-router 1.22.1 → 1.23.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.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +30 -0
- package/docs/activity-routing.md +31 -6
- package/docs/architecture.md +15 -4
- package/docs/configuration.md +10 -2
- package/docs/native-router.md +2 -2
- package/docs/providers.md +1 -1
- package/docs/router-band.svg +11 -11
- package/docs/router-pane-now.svg +4 -4
- package/docs/router-pane-usage-whatif.svg +10 -9
- package/docs/router-pane-usage.svg +10 -9
- package/docs/routing-modes.md +13 -11
- package/docs/user-guide.md +37 -19
- package/hooks/native-router.mjs +18 -6
- package/lib/activity.mjs +46 -29
- package/lib/band.mjs +4 -4
- package/lib/config.mjs +15 -2
- package/lib/cost.mjs +7 -0
- package/lib/costs.mjs +2 -2
- package/lib/display.mjs +5 -5
- package/lib/modes.mjs +17 -6
- package/lib/panel.mjs +17 -20
- package/lib/route.mjs +140 -31
- package/lib/subagents.mjs +3 -3
- package/lib/view.mjs +3 -0
- package/package.json +1 -1
- package/types/index.d.ts +5 -1
package/lib/panel.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { effortSharesCache, routeEffort } from './cost.mjs';
|
|
18
18
|
import { periodCost, resetText } from './costs.mjs';
|
|
19
19
|
import {
|
|
20
|
+
API_ESTIMATE,
|
|
20
21
|
activityReading,
|
|
21
22
|
baselineName,
|
|
22
23
|
classifierLabel,
|
|
@@ -434,11 +435,11 @@ function planLines(ui, cost, now) {
|
|
|
434
435
|
];
|
|
435
436
|
}
|
|
436
437
|
|
|
437
|
-
//
|
|
438
|
+
// The estimate's billing product is context, never evidence of an invoice or measured quota use.
|
|
438
439
|
function billingWords(cost) {
|
|
439
|
-
if (cost.billing === 'plan') return
|
|
440
|
-
if (cost.billing === 'mixed') return
|
|
441
|
-
return
|
|
440
|
+
if (cost.billing === 'plan') return `${API_ESTIMATE} · plan quota, not a charge`;
|
|
441
|
+
if (cost.billing === 'mixed') return `${API_ESTIMATE} · credits ${costText(cost.creditsUsd, cost.billing)}`;
|
|
442
|
+
return `${API_ESTIMATE} · configured rates, not an invoice`;
|
|
442
443
|
}
|
|
443
444
|
|
|
444
445
|
// SESSION: one total with the subagents, the difference against no routing, the main thread and the subagents as bars
|
|
@@ -632,7 +633,7 @@ function readingDetail(ui, view, metrics) {
|
|
|
632
633
|
ui.head(`INPUT PER REPLY · last ${plural(history.length, 'reply', 'replies')} · lowest to highest`),
|
|
633
634
|
trend,
|
|
634
635
|
ui.text(' '),
|
|
635
|
-
ui.head('ESTIMATES · configured
|
|
636
|
+
ui.head('ESTIMATES · configured API rates'),
|
|
636
637
|
ui.text(`Cache hits saved ${dollars(metrics.cacheBenefit)}`),
|
|
637
638
|
Number.isFinite(view.estimate?.taxUsd) ? ui.text(`Switch cost ${dollars(view.estimate.taxUsd)}`) : null,
|
|
638
639
|
...(view.comparison
|
|
@@ -1345,8 +1346,8 @@ function storeUsage(ui, store, metrics) {
|
|
|
1345
1346
|
// The footer as [text, joiner] pieces, packed to the pane: two lines at full width, more in a narrow pane, never a
|
|
1346
1347
|
// line that ends in a joiner.
|
|
1347
1348
|
const SAVINGS_FOOTER = [
|
|
1348
|
-
['
|
|
1349
|
-
['
|
|
1349
|
+
['≈$ = tokens × configured API rates (list/custom)', ' · '],
|
|
1350
|
+
['not invoices or measured quota savings', ' · '],
|
|
1350
1351
|
['answer quality not measured', ''],
|
|
1351
1352
|
];
|
|
1352
1353
|
const FULL_WIDTH = 68;
|
|
@@ -1665,7 +1666,9 @@ function subagentUsage(ui, config, view, actions, period, now, columns, billing)
|
|
|
1665
1666
|
out.push(
|
|
1666
1667
|
ui.text(' '),
|
|
1667
1668
|
...dimLines(ui, ' ■ moved by the router · □ Claude Code’s pick · color: the model', columns),
|
|
1668
|
-
...(routed.length
|
|
1669
|
+
...(routed.length
|
|
1670
|
+
? dimLines(ui, ' vs CC: the same tokens on Claude Code’s pick, at configured API rates', columns)
|
|
1671
|
+
: []),
|
|
1669
1672
|
);
|
|
1670
1673
|
return out;
|
|
1671
1674
|
}
|
|
@@ -2063,7 +2066,7 @@ function costHeadline(ui, cost) {
|
|
|
2063
2066
|
);
|
|
2064
2067
|
return ui.dim(
|
|
2065
2068
|
cost.effortOnly
|
|
2066
|
-
? 'Effort routing on one model: no saving is estimated;
|
|
2069
|
+
? 'Effort routing on one model: no saving is estimated; cost uses configured API rates.'
|
|
2067
2070
|
: `${uncomparedText(cost).replace(/^./, (c) => c.toUpperCase())}: no saving is shown.`,
|
|
2068
2071
|
);
|
|
2069
2072
|
}
|
|
@@ -2074,7 +2077,7 @@ function costTable(ui, config, view, period, cost, legacy, actions, columns) {
|
|
|
2074
2077
|
if (!cost.replies && !cost.agents) return emptyCost(ui, config, view, period);
|
|
2075
2078
|
const compared = cost.diffUsd !== null;
|
|
2076
2079
|
const r = cost.readout;
|
|
2077
|
-
//
|
|
2080
|
+
// All products use configured-rate estimates, including the credits subtotal.
|
|
2078
2081
|
const row = (label, amount, diff, base, style = {}, billing = cost.billing) =>
|
|
2079
2082
|
ui.line(
|
|
2080
2083
|
ui.cell(COST_LABEL, ui.text(label, style)),
|
|
@@ -2132,14 +2135,8 @@ function costTable(ui, config, view, period, cost, legacy, actions, columns) {
|
|
|
2132
2135
|
)
|
|
2133
2136
|
: null,
|
|
2134
2137
|
ui.dim('─'.repeat(COST_LABEL + COST_AMOUNT + (compared ? COST_DIFF + COST_BASE : 0))),
|
|
2135
|
-
row(
|
|
2136
|
-
|
|
2137
|
-
cost.totalUsd,
|
|
2138
|
-
cost.diffUsd,
|
|
2139
|
-
cost.baseUsd,
|
|
2140
|
-
{ bold: true },
|
|
2141
|
-
),
|
|
2142
|
-
cost.billing === 'mixed' ? row(' billed as credits', cost.creditsUsd, null, null, {}, 'billed') : null,
|
|
2138
|
+
row(`${total} · ${API_ESTIMATE}`, cost.totalUsd, cost.diffUsd, cost.baseUsd, { bold: true }),
|
|
2139
|
+
cost.billing === 'mixed' ? row(' credits estimate', cost.creditsUsd, null, null, {}, 'billed') : null,
|
|
2143
2140
|
].filter(Boolean);
|
|
2144
2141
|
if (legacy?.replies)
|
|
2145
2142
|
out.push(
|
|
@@ -2161,8 +2158,8 @@ const COST_BASE = 12;
|
|
|
2161
2158
|
function helpLines(ui) {
|
|
2162
2159
|
return [
|
|
2163
2160
|
ui.head('ABOUT THESE NUMBERS'),
|
|
2164
|
-
ui.dim('
|
|
2165
|
-
ui.dim('
|
|
2161
|
+
ui.dim('≈$ is tokens × configured API rates in router.json (list/custom).'),
|
|
2162
|
+
ui.dim('These are estimates, not invoices or measured plan-quota savings.'),
|
|
2166
2163
|
ui.dim('No routing: your model on the main thread, Claude Code’s pick per agent,'),
|
|
2167
2164
|
ui.dim('same tokens and output length. Answer quality is not measured.'),
|
|
2168
2165
|
ui.dim('For the whole session cost, with side calls such as titles and compaction'),
|
package/lib/route.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
chooseActivity,
|
|
5
5
|
compareRoutes,
|
|
6
6
|
lateralMove,
|
|
7
|
+
opsWorkActivity,
|
|
7
8
|
routingActivity,
|
|
8
9
|
sameRequest,
|
|
9
10
|
} from './activity.mjs';
|
|
@@ -101,6 +102,7 @@ export function resetHistory(loop) {
|
|
|
101
102
|
resolutions: {},
|
|
102
103
|
historyMeasured: false,
|
|
103
104
|
state: freshState(loop.state),
|
|
105
|
+
...(loop.decision ? { decision: { ...loop.decision, floorActivity: null } } : {}),
|
|
104
106
|
// The active turn keeps its route, pin and fallback suspension; the next turn decides afresh.
|
|
105
107
|
ineligible: [],
|
|
106
108
|
yoursBy: {},
|
|
@@ -172,6 +174,13 @@ function economicConfig(config, loop) {
|
|
|
172
174
|
export function chooseRoute(config, loop, input) {
|
|
173
175
|
const { pin, facts } = input;
|
|
174
176
|
const applied = routeTurn(config, loop, input);
|
|
177
|
+
const floor = opsFloor(config, applied.floorActivity);
|
|
178
|
+
if (
|
|
179
|
+
applied.activity === floor.activity &&
|
|
180
|
+
floor.retained.includes(applied.tier) &&
|
|
181
|
+
sameRoute(applied.route, resolveRoute(config, applied.tier, 'ops'))
|
|
182
|
+
)
|
|
183
|
+
applied.activity = 'ops';
|
|
175
184
|
const kept = pin || !applied.tier;
|
|
176
185
|
return {
|
|
177
186
|
...loop,
|
|
@@ -190,14 +199,41 @@ export function chooseRoute(config, loop, input) {
|
|
|
190
199
|
};
|
|
191
200
|
}
|
|
192
201
|
|
|
202
|
+
// An absent engineering cell inherits the generic row, which is not necessarily a floor for a custom ops row.
|
|
203
|
+
// Protect only a declared weaker inherited preference; explicit cells (even use-tier) and unknown strength stay
|
|
204
|
+
// authoritative. Project per tier before any price/fit/gate calculation, then report a retained ops cell as ops.
|
|
205
|
+
function opsFloor(config, activity) {
|
|
206
|
+
const retained = [];
|
|
207
|
+
if (config.activityRouting !== 'on' || !activity) return { config, activity, retained };
|
|
208
|
+
const declared = config.configuredActivities ?? config.activities;
|
|
209
|
+
const cells = { ...config.activities[activity] };
|
|
210
|
+
for (const tier of TIERS) {
|
|
211
|
+
if (declared[activity]?.[tier]) continue;
|
|
212
|
+
const ops = resolveRoute(config, tier, 'ops');
|
|
213
|
+
if (!(compareRoutes(config, resolveRoute(config, tier, activity), ops) < 0)) continue;
|
|
214
|
+
cells[tier] = ops;
|
|
215
|
+
retained.push(tier);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
config: retained.length
|
|
219
|
+
? { ...config, configuredActivities: declared, activities: { ...config.activities, [activity]: cells } }
|
|
220
|
+
: config,
|
|
221
|
+
activity,
|
|
222
|
+
retained,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
193
226
|
// The activity of the route running now. Outside `on` there is none, even one a turn in `on` left in the loop before
|
|
194
227
|
// the mode changed: `off` is the 1.5 decision.
|
|
195
228
|
const activityOf = (config, loop) => (config.activityRouting === 'on' ? (loop.lastActivity ?? null) : null);
|
|
196
229
|
|
|
197
230
|
// One decision (plan §5.2) for the cell `{ tier, activity }` it lands on. Outside `on` the activity is null throughout.
|
|
198
231
|
function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown, availableModels, now }) {
|
|
199
|
-
const
|
|
200
|
-
|
|
232
|
+
const last = {
|
|
233
|
+
tier: loop.lastRoute,
|
|
234
|
+
activity: activityOf(config, loop),
|
|
235
|
+
floorActivity: config.activityRouting === 'on' ? (loop.decision?.floorActivity ?? null) : null,
|
|
236
|
+
};
|
|
201
237
|
const tier0 = TIERS.includes(facts.lastRoute) ? facts.lastRoute : config.baselineTier;
|
|
202
238
|
// The incumbent runs the route in use, not the one config gives its cell now. It is rebuilt from config for a loop
|
|
203
239
|
// from before 1.15, a route whose model left the config or can no longer run, and a route kept for an activity that
|
|
@@ -212,8 +248,12 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
212
248
|
const incumbent = {
|
|
213
249
|
tier: tier0,
|
|
214
250
|
activity: last.activity,
|
|
251
|
+
floorActivity: last.floorActivity,
|
|
215
252
|
route: inUse ?? resolveRoute(config, tier0, last.activity),
|
|
216
253
|
};
|
|
254
|
+
let result = chooseCell(config, loop, { facts, advice, pin, now }, incumbent);
|
|
255
|
+
// Restoring last/native provenance can change the floor again, so each candidate resolves its own projection.
|
|
256
|
+
const preferredRoute = (cell) => resolveRoute(opsFloor(config, cell.floorActivity).config, cell.tier, cell.activity);
|
|
217
257
|
// A decision that stays on the incumbent's cell keeps running its route; only a taken lateral move or a pin runs the
|
|
218
258
|
// cell's route from config. So a mode change reaches the request only through the gates.
|
|
219
259
|
const stays = (cell) =>
|
|
@@ -221,21 +261,8 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
221
261
|
(cell.activity ?? null) === incumbent.activity &&
|
|
222
262
|
cell.lateral !== 'taken' &&
|
|
223
263
|
cell.reason !== 'pinned';
|
|
224
|
-
const routeOf = (cell) => (stays(cell) ? incumbent.route :
|
|
264
|
+
const routeOf = (cell) => (stays(cell) ? incumbent.route : preferredRoute(cell));
|
|
225
265
|
const specOf = (cell) => routeSpec(config, routeOf(cell));
|
|
226
|
-
const activity =
|
|
227
|
-
pin || config.activityRouting !== 'on' ? null : chooseActivity(config, advice, incumbent, facts.effort, facts);
|
|
228
|
-
let result =
|
|
229
|
-
pin && TIERS.includes(pin)
|
|
230
|
-
? {
|
|
231
|
-
tier: pin,
|
|
232
|
-
activity: null,
|
|
233
|
-
reason: 'pinned',
|
|
234
|
-
lateral: null,
|
|
235
|
-
escalated: false,
|
|
236
|
-
state: { ...loop.state, turn: loop.state.turn + 1 },
|
|
237
|
-
}
|
|
238
|
-
: decideCell({ config, projected, facts, advice, state: loop.state, now, incumbent, activity });
|
|
239
266
|
// Without a reliable reading of the context, a route with a smaller window than the last one might overflow. Before
|
|
240
267
|
// the first decision the session's own model ran, not the mode's route for its cell.
|
|
241
268
|
const lastSpec =
|
|
@@ -256,19 +283,27 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
256
283
|
const fits = (cell) => runs(cell) && roomFor(cell);
|
|
257
284
|
if (contextKnown) {
|
|
258
285
|
const cell = result;
|
|
259
|
-
const
|
|
286
|
+
const acceptedActivity = cell.floorActivity ?? cell.activity;
|
|
287
|
+
const routeFor = (tier) =>
|
|
288
|
+
tier === cell.tier ? routeOf(cell) : preferredRoute({ ...cell, tier, activity: acceptedActivity });
|
|
260
289
|
const fitted = fitTier(config, result.tier, costs.nextContextTokens(facts), routeFor);
|
|
261
|
-
if (fitted !== result.tier)
|
|
290
|
+
if (fitted !== result.tier)
|
|
291
|
+
result = { ...result, tier: fitted, activity: acceptedActivity, reason: 'context-fit', lateral: null };
|
|
262
292
|
}
|
|
263
293
|
// A lateral outcome describes the cell the lateral rule chose; a context or availability override replaces it.
|
|
264
294
|
if (shrinksUnmeasured(result)) result = { ...result, ...last, reason: 'context-unknown', lateral: null };
|
|
265
295
|
if (!fits(result)) {
|
|
266
296
|
// A cell labelled with another activity would run, and stick, a route this turn did not choose.
|
|
267
297
|
const native = cellForModel(config, nativeModel);
|
|
268
|
-
const
|
|
298
|
+
const acceptedActivity = result.floorActivity ?? result.activity;
|
|
299
|
+
const cells = [
|
|
300
|
+
last,
|
|
301
|
+
native && { ...native, floorActivity: null },
|
|
302
|
+
...TIERS.map((tier) => ({ tier, activity: acceptedActivity, floorActivity: result.floorActivity })),
|
|
303
|
+
];
|
|
269
304
|
const fallback = cells.find(
|
|
270
|
-
(cell) => cell && (cell.activity === null || cell.activity ===
|
|
271
|
-
) ?? { tier: null, activity: null };
|
|
305
|
+
(cell) => cell && (cell.activity === null || cell.activity === acceptedActivity) && fits(cell),
|
|
306
|
+
) ?? { tier: null, activity: null, floorActivity: null };
|
|
272
307
|
// Only the window failed: no route is withheld, the conversation is just too full for every one of them.
|
|
273
308
|
const reason = runs(result) ? 'context-full' : 'model-unavailable';
|
|
274
309
|
result = { ...result, ...fallback, reason, lateral: null };
|
|
@@ -279,7 +314,9 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
279
314
|
let comparison = null;
|
|
280
315
|
const candidate = pin ?? advice?.choice;
|
|
281
316
|
if (contextKnown && loop.lastRequest && TIERS.includes(candidate) && candidate !== loop.lastRoute) {
|
|
282
|
-
const
|
|
317
|
+
const to = preferredRoute({ ...result, tier: candidate, activity: result.floorActivity ?? result.activity });
|
|
318
|
+
const from = incumbent.route;
|
|
319
|
+
const projected = economicConfig(opsFloor(config, result.floorActivity).config, loop);
|
|
283
320
|
const forecast = costs.switchEconomics(projected, to, from, facts, now);
|
|
284
321
|
comparison = {
|
|
285
322
|
candidate,
|
|
@@ -292,10 +329,59 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
292
329
|
return { ...result, route, model, effort, comparison, pinned: Boolean(pin), requestedPin: pin ?? null };
|
|
293
330
|
}
|
|
294
331
|
|
|
332
|
+
// Nomination carries its source into the gates; only their accepted outcome owns future refit intent.
|
|
333
|
+
function chooseCell(config, loop, { facts, advice, pin, now }, incumbent) {
|
|
334
|
+
if (pin && TIERS.includes(pin))
|
|
335
|
+
return {
|
|
336
|
+
tier: pin,
|
|
337
|
+
activity: null,
|
|
338
|
+
floorActivity: null,
|
|
339
|
+
reason: 'pinned',
|
|
340
|
+
lateral: null,
|
|
341
|
+
escalated: false,
|
|
342
|
+
state: { ...loop.state, turn: loop.state.turn + 1 },
|
|
343
|
+
};
|
|
344
|
+
const work = !pin && config.activityRouting === 'on' ? opsWorkActivity(config, advice) : null;
|
|
345
|
+
const proposal = opsFloor(config, work);
|
|
346
|
+
const selection =
|
|
347
|
+
!pin && config.activityRouting === 'on'
|
|
348
|
+
? chooseActivity(proposal.config, advice, incumbent, facts.effort, facts)
|
|
349
|
+
: { activity: null, floorActivity: null };
|
|
350
|
+
const chosen = opsFloor(config, selection.floorActivity);
|
|
351
|
+
return decideCell({
|
|
352
|
+
config: chosen.config,
|
|
353
|
+
projected: economicConfig(chosen.config, loop),
|
|
354
|
+
facts,
|
|
355
|
+
advice,
|
|
356
|
+
state: loop.state,
|
|
357
|
+
now,
|
|
358
|
+
incumbent,
|
|
359
|
+
activity: selection.floorActivity ?? selection.activity,
|
|
360
|
+
floorActivity: selection.floorActivity,
|
|
361
|
+
phaseDerived: Boolean(
|
|
362
|
+
work &&
|
|
363
|
+
selection.floorActivity === work &&
|
|
364
|
+
incumbent.floorActivity !== work &&
|
|
365
|
+
chosen.retained.includes(incumbent.tier),
|
|
366
|
+
),
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
295
370
|
// Steps 3-6 of plan §5.2: the tier as `decide` picks it, every candidate priced at its route for `activity` and the
|
|
296
371
|
// incumbent at the route it runs; then, when the tier stays and the route would change, the lateral rule. Equal routes
|
|
297
372
|
// never switch: a label alone decides nothing.
|
|
298
|
-
function decideCell({
|
|
373
|
+
function decideCell({
|
|
374
|
+
config,
|
|
375
|
+
projected,
|
|
376
|
+
facts,
|
|
377
|
+
advice,
|
|
378
|
+
state,
|
|
379
|
+
now,
|
|
380
|
+
incumbent,
|
|
381
|
+
activity,
|
|
382
|
+
floorActivity,
|
|
383
|
+
phaseDerived,
|
|
384
|
+
}) {
|
|
299
385
|
const routeFor = (tier) => resolveRoute(config, tier, activity);
|
|
300
386
|
// Failures move to the lowest tier whose route is stronger than the one running, or another request that does not
|
|
301
387
|
// order against it: after a mode change the next tier's route can be the weaker one.
|
|
@@ -321,15 +407,23 @@ function decideCell({ config, projected, facts, advice, state, now, incumbent, a
|
|
|
321
407
|
const escalated = step.state.escalatedSignature !== state.escalatedSignature;
|
|
322
408
|
const route = routeFor(step.tier);
|
|
323
409
|
// Without a classifier answer the running route stays, whatever the mode's route for the cell, during a hold too.
|
|
324
|
-
if (!advice
|
|
325
|
-
|
|
410
|
+
if (!advice) return { ...step, activity: incumbent.activity, floorActivity, lateral: null, escalated };
|
|
411
|
+
if (step.tier !== incumbent.tier || sameRequest(config, route, incumbent.route, facts.effort))
|
|
412
|
+
return { ...step, activity, floorActivity, lateral: null, escalated };
|
|
326
413
|
const lateral = lateralMove({
|
|
327
414
|
config: projected,
|
|
328
415
|
from: incumbent.route,
|
|
329
416
|
to: route,
|
|
330
417
|
// Returning to the base route needs no evidence, nor does the incumbent's own cell whose configured route changed
|
|
331
|
-
// (a routing mode, a route edit)
|
|
332
|
-
|
|
418
|
+
// (a routing mode, a route edit). A new phase-derived physical projection is not an operator edit, even when
|
|
419
|
+
// its label is unchanged: that proposal still needs the lower of the actual goal/phase supports.
|
|
420
|
+
mass:
|
|
421
|
+
!phaseDerived &&
|
|
422
|
+
(activity === null ||
|
|
423
|
+
activity === incumbent.activity ||
|
|
424
|
+
(floorActivity && floorActivity === incumbent.floorActivity))
|
|
425
|
+
? 1
|
|
426
|
+
: (routingActivity(config, advice)?.mass ?? 0),
|
|
333
427
|
hold: step.reason === 'hold',
|
|
334
428
|
sameTask: sameTaskOf(config, advice, facts),
|
|
335
429
|
facts,
|
|
@@ -340,6 +434,7 @@ function decideCell({ config, projected, facts, advice, state, now, incumbent, a
|
|
|
340
434
|
return {
|
|
341
435
|
...step,
|
|
342
436
|
activity: activityOf,
|
|
437
|
+
floorActivity: lateral.move ? floorActivity : incumbent.floorActivity,
|
|
343
438
|
reason: lateral.reason,
|
|
344
439
|
estimate: lateral.estimate,
|
|
345
440
|
lateral: lateral.move ? 'taken' : 'refused',
|
|
@@ -391,6 +486,7 @@ export function observedMove(config, loop, { observed, facts, contextKnown, now
|
|
|
391
486
|
...decision,
|
|
392
487
|
tier,
|
|
393
488
|
activity: observed,
|
|
489
|
+
floorActivity: null,
|
|
394
490
|
route: to,
|
|
395
491
|
model: routeSpec(config, to).id,
|
|
396
492
|
effort: costs.routeEffort(config, to, facts.effort),
|
|
@@ -403,18 +499,27 @@ export function observedMove(config, loop, { observed, facts, contextKnown, now
|
|
|
403
499
|
// A tool continuation keeps the turn's route and activity; only the context, the model list, or the turn's own tool
|
|
404
500
|
// calls (observedMove) can move it.
|
|
405
501
|
export function continueRoute(
|
|
406
|
-
|
|
502
|
+
current,
|
|
407
503
|
loop,
|
|
408
504
|
{ nativeModel, contextTokens, contextKnown, availableModels, effort, hasImages = false },
|
|
409
505
|
) {
|
|
410
506
|
if (!loop.decision) return loop;
|
|
411
507
|
// A fit to another tier serves this turn only: `loop.route` stays the route of `lastRoute`, as the tier does.
|
|
412
508
|
let decision = loop.decision;
|
|
509
|
+
const work =
|
|
510
|
+
current.activityRouting === 'on' && !decision.pinned && ['debug', 'code'].includes(decision.floorActivity)
|
|
511
|
+
? decision.floorActivity
|
|
512
|
+
: null;
|
|
513
|
+
const floor = opsFloor(current, work);
|
|
514
|
+
const config = floor.config;
|
|
515
|
+
const activity = work ?? decision.activity ?? null;
|
|
516
|
+
const activityOf = (tier) => (floor.retained.includes(tier) ? 'ops' : activity);
|
|
517
|
+
if (!work && decision.floorActivity) decision = { ...decision, floorActivity: null };
|
|
413
518
|
if (contextKnown && decision.tier) {
|
|
414
519
|
// The route the turn runs, which a mode change or a held move can keep apart from config, stays while the context
|
|
415
520
|
// fits it; past that, the routes config gives each tier, its own tier's first.
|
|
416
521
|
const running = runningRoute(config, decision);
|
|
417
|
-
const routeOf = (tier) => resolveRoute(config, tier,
|
|
522
|
+
const routeOf = (tier) => resolveRoute(config, tier, activity);
|
|
418
523
|
const fits = contextTokens <= routeSpec(config, running).contextWindow * CONTEXT_FILL;
|
|
419
524
|
const fitted = fits ? decision.tier : fitTier(config, decision.tier, contextTokens, routeOf);
|
|
420
525
|
if (!fits && !sameRoute(routeOf(fitted), running)) {
|
|
@@ -422,6 +527,7 @@ export function continueRoute(
|
|
|
422
527
|
decision = {
|
|
423
528
|
...decision,
|
|
424
529
|
tier: fitted,
|
|
530
|
+
activity: activityOf(fitted),
|
|
425
531
|
route,
|
|
426
532
|
model: routeSpec(config, route).id,
|
|
427
533
|
effort: costs.routeEffort(config, route, effort),
|
|
@@ -432,7 +538,7 @@ export function continueRoute(
|
|
|
432
538
|
if (hasImages && decision.tier && routeSpec(config, runningRoute(config, decision))?.imageInput === false) {
|
|
433
539
|
const runningWindow = routeSpec(config, runningRoute(config, decision)).contextWindow;
|
|
434
540
|
const tier = [...TIERS].reverse().find((t) => {
|
|
435
|
-
const model = routeSpec(config, resolveRoute(config, t,
|
|
541
|
+
const model = routeSpec(config, resolveRoute(config, t, activity));
|
|
436
542
|
return (
|
|
437
543
|
model.imageInput !== false &&
|
|
438
544
|
isModelAllowed(model.id, availableModels, nativeModel) &&
|
|
@@ -440,10 +546,12 @@ export function continueRoute(
|
|
|
440
546
|
(contextKnown ? contextTokens <= model.contextWindow * CONTEXT_FILL : model.contextWindow >= runningWindow)
|
|
441
547
|
);
|
|
442
548
|
});
|
|
443
|
-
const route = tier ? resolveRoute(config, tier,
|
|
549
|
+
const route = tier ? resolveRoute(config, tier, activity) : null;
|
|
444
550
|
decision = {
|
|
445
551
|
...decision,
|
|
446
552
|
tier: tier ?? null,
|
|
553
|
+
activity: tier ? activityOf(tier) : null,
|
|
554
|
+
floorActivity: tier ? work : null,
|
|
447
555
|
route,
|
|
448
556
|
model: route ? routeSpec(config, route).id : nativeModel,
|
|
449
557
|
effort: route ? costs.routeEffort(config, route, effort) : effort,
|
|
@@ -455,6 +563,7 @@ export function continueRoute(
|
|
|
455
563
|
...decision,
|
|
456
564
|
tier: null,
|
|
457
565
|
activity: null,
|
|
566
|
+
floorActivity: null,
|
|
458
567
|
route: null,
|
|
459
568
|
model: nativeModel,
|
|
460
569
|
effort,
|
package/lib/subagents.mjs
CHANGED
|
@@ -137,11 +137,11 @@ export function coreModelOf(config, spawn, { envModel = null, force = false, def
|
|
|
137
137
|
return usesEnv ? idOf(envModel) : spawn.parentModel;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
// How the router's model compares with core's: null when they are the same, `up` or `down` by
|
|
141
|
-
// when either
|
|
140
|
+
// How the router's model compares with core's: null when they are the same, `up` or `down` by declared strength,
|
|
141
|
+
// `moved` when either rank is unknown or they are equal. Tariffs do not establish capability.
|
|
142
142
|
export function moveOf(config, routedModel, coreModel) {
|
|
143
143
|
if (!routedModel || !coreModel || routedModel === coreModel) return null;
|
|
144
|
-
const [routed, core] = [routedModel, coreModel].map((id) => modelSpec(config, id)?.
|
|
144
|
+
const [routed, core] = [routedModel, coreModel].map((id) => modelSpec(config, id)?.strength);
|
|
145
145
|
if (!Number.isFinite(routed) || !Number.isFinite(core) || routed === core) return 'moved';
|
|
146
146
|
return routed > core ? 'up' : 'down';
|
|
147
147
|
}
|
package/lib/view.mjs
CHANGED
|
@@ -16,6 +16,9 @@ export function initialView(model) {
|
|
|
16
16
|
// The effort Claude Code sent on the turn's first request, before routing: with nativeModel, "your model".
|
|
17
17
|
nativeEffort: null,
|
|
18
18
|
selectedModel: null,
|
|
19
|
+
// Last recorded completed request handed to the engine, not an attestation of its serialized API request.
|
|
20
|
+
delegatedModel: null,
|
|
21
|
+
delegatedEffort: null,
|
|
19
22
|
actualModel: null,
|
|
20
23
|
tier: null,
|
|
21
24
|
effort: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.1",
|
|
4
4
|
"description": "Native Claude Code model and effort routing with Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, and classifier advice.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|
package/types/index.d.ts
CHANGED
|
@@ -192,6 +192,9 @@ declare module 'claude-code' {
|
|
|
192
192
|
nativeEffort?: string | number | null;
|
|
193
193
|
activeTurnId?: string | null;
|
|
194
194
|
selectedModel?: string | null;
|
|
195
|
+
// Last recorded completed engine request, not verified API-transmitted settings.
|
|
196
|
+
delegatedModel?: string | null;
|
|
197
|
+
delegatedEffort?: string | number | null;
|
|
195
198
|
actualModel?: string | null;
|
|
196
199
|
tier?: RouterTier | null;
|
|
197
200
|
effort?: string | number | null;
|
|
@@ -298,8 +301,9 @@ declare module 'claude-code' {
|
|
|
298
301
|
effort: string | number | null;
|
|
299
302
|
estimate?: RouterEstimate | null;
|
|
300
303
|
comparison?: RouterComparison | null;
|
|
301
|
-
// The applied
|
|
304
|
+
// The applied physical cell; a protected ops cell may retain a separate accepted work preference.
|
|
302
305
|
activity?: RouterActivity | null;
|
|
306
|
+
floorActivity?: 'debug' | 'code' | null;
|
|
303
307
|
lateral?: RouterLateral;
|
|
304
308
|
// A failure asked for an escalation this turn, also one the cash gate held or context-fit replaced.
|
|
305
309
|
escalated?: boolean;
|