@alexeiled/claude-router 1.10.0 → 1.10.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 +7 -0
- package/README.md +3 -3
- package/docs/activity-routing.md +18 -18
- package/docs/architecture.md +5 -7
- package/docs/configuration.md +20 -18
- package/docs/evaluation.md +8 -9
- package/docs/native-router.md +7 -8
- package/docs/router-band.svg +3 -21
- package/docs/user-guide.md +13 -14
- package/hooks/native-router.mjs +16 -49
- package/lib/activity-stats.mjs +21 -70
- package/lib/band.mjs +3 -6
- package/lib/config.mjs +11 -8
- package/lib/cost.mjs +3 -3
- package/lib/display.mjs +4 -16
- package/lib/panel.mjs +13 -47
- package/lib/route.mjs +4 -53
- package/lib/subagents.mjs +12 -17
- package/lib/view.mjs +1 -3
- package/package.json +1 -1
- package/types/index.d.ts +5 -35
package/lib/panel.mjs
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import { effortSharesCache, routeEffort } from './cost.mjs';
|
|
17
17
|
import {
|
|
18
18
|
activityReading,
|
|
19
|
-
activityRouteText,
|
|
20
19
|
activityVerb,
|
|
21
20
|
bar,
|
|
22
21
|
classifierLabel,
|
|
@@ -85,13 +84,11 @@ const ACTIVITY_STYLE = { color: '#d7875f', italic: true };
|
|
|
85
84
|
|
|
86
85
|
const ACTIVITY_MODE_HINT = {
|
|
87
86
|
off: 'not asked; every turn runs its tier’s model',
|
|
88
|
-
shadow: 'asked and shown; every turn still runs its tier’s model',
|
|
89
87
|
on: 'an activity can change its tier’s model',
|
|
90
88
|
};
|
|
91
89
|
// What `subagentRouting` does, under the router.json path: it is set in the file, not in the pane.
|
|
92
90
|
const SUBAGENT_LINE = {
|
|
93
91
|
off: 'Subagents keep their own model (subagentRouting off).',
|
|
94
|
-
shadow: 'Subagents: shadow. A model is chosen at spawn and recorded, not applied.',
|
|
95
92
|
on: 'Subagents: on. Agents that pin no model get one at spawn, kept for every step.',
|
|
96
93
|
};
|
|
97
94
|
const EFFORT_SHORT = { low: 'low', medium: 'med', high: 'high', xhigh: 'xh', max: 'max', [INHERIT]: 'inh' };
|
|
@@ -262,11 +259,10 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
262
259
|
const served = view.actualModel && current && !isSameModel(current, view.actualModel);
|
|
263
260
|
const mode = config.activityRouting;
|
|
264
261
|
const reading = mode === 'off' ? null : activityReading(view);
|
|
265
|
-
// In `on` an override names the tier's own model
|
|
262
|
+
// In `on` an override names the tier's own model.
|
|
266
263
|
const base = view.tier ? resolveRoute(config, view.tier) : null;
|
|
267
264
|
const override =
|
|
268
265
|
mode === 'on' && view.activity && base && !sameRoute(resolveRoute(config, view.tier, view.activity), base);
|
|
269
|
-
const route = mode === 'shadow' ? activityRouteText(config, view) : null;
|
|
270
266
|
const support = auto ? supportText(label, view.estimate) : null;
|
|
271
267
|
const out = [
|
|
272
268
|
ui.line(
|
|
@@ -288,7 +284,6 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
288
284
|
: null,
|
|
289
285
|
ui.line('Why ', whyText(config, view)),
|
|
290
286
|
support ? ui.dim(` ${support}`) : null,
|
|
291
|
-
route ? ui.line('Shadow ', ui.dim(route)) : null,
|
|
292
287
|
served
|
|
293
288
|
? ui.line(ui.text('Served ', { color: 'yellow' }), `${modelName(view.actualModel)} · native fallback`)
|
|
294
289
|
: null,
|
|
@@ -955,15 +950,6 @@ function statusBar(ui, config, view, tab, actions) {
|
|
|
955
950
|
return out;
|
|
956
951
|
}
|
|
957
952
|
|
|
958
|
-
// `on` would route N of M shadow turns differently, with the summed next-request range of the differing turns that had
|
|
959
|
-
// one, at configured list prices; `for K` says when only some had one.
|
|
960
|
-
function shadowLine(shadow) {
|
|
961
|
-
const counted = `Shadow on would route ${shadow.differs} of ${shadow.turns} turns differently`;
|
|
962
|
-
if (!(shadow.estimated > 0)) return counted;
|
|
963
|
-
const some = shadow.estimated < shadow.differs ? ` for ${shadow.estimated}` : '';
|
|
964
|
-
return `${counted} · est. ${difference(shadow.minUsd)} … ${difference(shadow.maxUsd)}${some} at list prices`;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
953
|
// The counts kept across sessions, read from the stores as last loaded: how often the tools a turn used fit the
|
|
968
954
|
// classifier's activity, and what the activity moves led to. Agreement uses the classifier's raw answer, so it can
|
|
969
955
|
// differ from the session's.
|
|
@@ -993,7 +979,6 @@ function storeUsage(ui, store, metrics) {
|
|
|
993
979
|
out.push(
|
|
994
980
|
ui.text(`Escalations after a cheaper activity move: ${escalations} in ${moves} move${moves === 1 ? '' : 's'}`),
|
|
995
981
|
);
|
|
996
|
-
if (summary.shadow.turns > 0) out.push(ui.text(shadowLine(summary.shadow)));
|
|
997
982
|
return out;
|
|
998
983
|
}
|
|
999
984
|
|
|
@@ -1002,7 +987,7 @@ const ACTIVITY_TABLE = 48;
|
|
|
1002
987
|
const ACTIVITY_COST = 11;
|
|
1003
988
|
|
|
1004
989
|
// Session counts by activity: turns, requests, share, the estimated list price of their replies and the route most of
|
|
1005
|
-
// them ran on; the switches by cause
|
|
990
|
+
// them ran on; the switches by cause and the tool agreement. The counts kept across sessions are on
|
|
1006
991
|
// the Classifier tab.
|
|
1007
992
|
function activityUsage(ui, config, view, columns) {
|
|
1008
993
|
const stats = view.activityStats ?? null;
|
|
@@ -1010,7 +995,7 @@ function activityUsage(ui, config, view, columns) {
|
|
|
1010
995
|
if (mode === 'off' && !stats)
|
|
1011
996
|
return [
|
|
1012
997
|
ui.head('BY ACTIVITY · activity routing off'),
|
|
1013
|
-
ui.dim(' Not asked. Set activity routing to
|
|
998
|
+
ui.dim(' Not asked. Set activity routing to on in the Routes tab.'),
|
|
1014
999
|
];
|
|
1015
1000
|
const out = [ui.line(ui.head('BY ACTIVITY · this session'), ui.dim(` activity routing ${mode}`))];
|
|
1016
1001
|
const rows = Object.entries(stats?.byActivity ?? {}).filter(([, counts]) => counts?.turns > 0);
|
|
@@ -1053,7 +1038,7 @@ function activityUsage(ui, config, view, columns) {
|
|
|
1053
1038
|
}
|
|
1054
1039
|
if (stats) {
|
|
1055
1040
|
const { tier, activity } = stats.switches;
|
|
1056
|
-
// Refused moves change no route.
|
|
1041
|
+
// Refused moves change no route.
|
|
1057
1042
|
const refused = stats.lateral?.refused ?? 0;
|
|
1058
1043
|
out.push(
|
|
1059
1044
|
ui.text(
|
|
@@ -1063,7 +1048,6 @@ function activityUsage(ui, config, view, columns) {
|
|
|
1063
1048
|
const { matched, total } = stats.agreement;
|
|
1064
1049
|
if (total > 0)
|
|
1065
1050
|
out.push(ui.text(`Agreement classifier vs tools: ${matched} of ${total} turns (${percent(matched / total)})`));
|
|
1066
|
-
if (mode === 'shadow' || stats.shadow.turns > 0) out.push(ui.text(shadowLine(stats.shadow)));
|
|
1067
1051
|
}
|
|
1068
1052
|
return out;
|
|
1069
1053
|
}
|
|
@@ -1141,8 +1125,8 @@ function moneyBar(ui, parts, scale) {
|
|
|
1141
1125
|
}
|
|
1142
1126
|
|
|
1143
1127
|
// The parts of a session readout past "too early": each part, the stronger replies, the two costs as bars (not in a
|
|
1144
|
-
// narrow pane), the replies by tier
|
|
1145
|
-
function savingsDetail(ui,
|
|
1128
|
+
// narrow pane), the replies by tier and why routing spent more.
|
|
1129
|
+
function savingsDetail(ui, view, { totals, session, across, row, tier, narrow, columns }) {
|
|
1146
1130
|
const out = [];
|
|
1147
1131
|
const savedPart = (key) => (across && !across.early ? partCell(ui, across[key]) : null);
|
|
1148
1132
|
const stronger = strongerReplies(totals);
|
|
@@ -1196,17 +1180,6 @@ function savingsDetail(ui, config, view, { totals, session, across, row, tier, n
|
|
|
1196
1180
|
...dimLines(ui, ' To spend less, pick cheaper models for those tiers in the Routes tab.', columns),
|
|
1197
1181
|
);
|
|
1198
1182
|
}
|
|
1199
|
-
const shadow = view.activityStats?.shadow;
|
|
1200
|
-
if (config.activityRouting === 'shadow' && shadow?.estimated > 0)
|
|
1201
|
-
out.push(
|
|
1202
|
-
ui.line(
|
|
1203
|
-
ui.dim(' if activity routing were on: '),
|
|
1204
|
-
ui.text(`est. ${signedUsd(shadow.minUsd)} … ${signedUsd(shadow.maxUsd)}`, {
|
|
1205
|
-
color: savingsColor((shadow.minUsd + shadow.maxUsd) / 2),
|
|
1206
|
-
}),
|
|
1207
|
-
ui.dim(' this session'),
|
|
1208
|
-
),
|
|
1209
|
-
);
|
|
1210
1183
|
return out;
|
|
1211
1184
|
}
|
|
1212
1185
|
|
|
@@ -1314,7 +1287,7 @@ function savingsSection(ui, config, view, columns) {
|
|
|
1314
1287
|
}
|
|
1315
1288
|
const others = otherModels(config, view);
|
|
1316
1289
|
if (others) out.push(...dimLines(ui, ` vs other models: ${others}`, columns));
|
|
1317
|
-
out.push(...savingsDetail(ui,
|
|
1290
|
+
out.push(...savingsDetail(ui, view, { totals, session, across, row, tier, narrow, columns }));
|
|
1318
1291
|
return [...out, ...notes()];
|
|
1319
1292
|
}
|
|
1320
1293
|
|
|
@@ -1347,27 +1320,20 @@ const pricedText = (text, counts) =>
|
|
|
1347
1320
|
|
|
1348
1321
|
// Subagent routing across sessions since the last reset. Per routed type: agents, how many the decision moved off
|
|
1349
1322
|
// core's model, requests per agent and respawns (the retry proxies), and core's cost against the routed one at list
|
|
1350
|
-
// prices
|
|
1351
|
-
// core's model. Then the spawns that passed through, by reason, priced on the model they ran on.
|
|
1323
|
+
// prices, with core's model estimated. Then the spawns that passed through, by reason, priced on the model they ran on.
|
|
1352
1324
|
function subagentUsage(ui, config, view, columns) {
|
|
1353
1325
|
const mode = config.subagentRouting;
|
|
1354
1326
|
const store = readSubagentStore(view.subagentStore);
|
|
1355
1327
|
const out = [ui.line(ui.head('SUBAGENTS · across sessions'), ui.dim(` subagent routing ${mode}`))];
|
|
1356
|
-
const
|
|
1357
|
-
.map((m) => ({ m, rows: Object.entries(store.routed[m]).filter(([, counts]) => counts.agents > 0) }))
|
|
1358
|
-
.filter(({ rows }) => rows.length);
|
|
1328
|
+
const rows = Object.entries(store.routed.on).filter(([, counts]) => counts.agents > 0);
|
|
1359
1329
|
const passed = PASS_REASONS.filter((reason) => store.passed[reason]?.agents > 0);
|
|
1360
|
-
if (!
|
|
1330
|
+
if (!rows.length && !passed.length)
|
|
1361
1331
|
return [
|
|
1362
1332
|
...out,
|
|
1363
|
-
ui.dim(
|
|
1364
|
-
mode === 'off' ? ' Not recorded. Set subagentRouting to shadow or on in router.json.' : ' no subagents yet',
|
|
1365
|
-
),
|
|
1333
|
+
ui.dim(mode === 'off' ? ' Not recorded. Set subagentRouting to on in router.json.' : ' no subagents yet'),
|
|
1366
1334
|
];
|
|
1367
|
-
|
|
1368
|
-
out.push(
|
|
1369
|
-
ui.dim(m === 'shadow' ? ' shadow: core’s model → the decided one' : ' on: core’s model (est.) → routed'),
|
|
1370
|
-
);
|
|
1335
|
+
if (rows.length) {
|
|
1336
|
+
out.push(ui.dim(' core’s model (est.) → routed'));
|
|
1371
1337
|
for (const [type, c] of rows.sort((a, b) => b[1].agents - a[1].agents)) {
|
|
1372
1338
|
const cost = pricedText(`${usd(c.coreUsd)} → ${usd(c.routedUsd)}`, c);
|
|
1373
1339
|
out.push(
|
package/lib/route.mjs
CHANGED
|
@@ -42,7 +42,6 @@ export function emptyLoop(config, model) {
|
|
|
42
42
|
return {
|
|
43
43
|
lastRoute: cell?.tier ?? config.baselineTier,
|
|
44
44
|
lastActivity: cell?.activity ?? null,
|
|
45
|
-
would: null,
|
|
46
45
|
state: initialState(),
|
|
47
46
|
models: {},
|
|
48
47
|
resolutions: {},
|
|
@@ -69,7 +68,6 @@ export function resetHistory(loop) {
|
|
|
69
68
|
resolutions: {},
|
|
70
69
|
historyMeasured: false,
|
|
71
70
|
state: freshState(loop.state),
|
|
72
|
-
would: loop.would ? { ...loop.would, state: freshState(loop.would.state) } : null,
|
|
73
71
|
// The active turn keeps its route, pin and fallback suspension; the next turn decides afresh.
|
|
74
72
|
ineligible: [],
|
|
75
73
|
yoursBy: {},
|
|
@@ -108,71 +106,24 @@ function economicConfig(config, loop) {
|
|
|
108
106
|
return { ...config, models };
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
// `activityRouting` decides which activity the
|
|
112
|
-
// decision a second time as `on` for `decision.wouldRoute` only, and the chosen one in `on`. Shadow keeps its own cell
|
|
113
|
-
// and policy state in `loop.would`, so each would-route continues from the previous one, as `on` would. Its limit: the
|
|
114
|
-
// would-route never runs, so its cache is never observed and an unobserved incumbent is priced as `inputBounds`
|
|
115
|
-
// prices any unknown cache.
|
|
109
|
+
// `activityRouting` decides which activity the route may use: none in `off`, the chosen one in `on`.
|
|
116
110
|
export function chooseRoute(config, loop, input) {
|
|
117
111
|
const { pin, facts } = input;
|
|
118
112
|
const applied = routeTurn(config, loop, input);
|
|
119
|
-
let wouldRoute = null;
|
|
120
|
-
let would = null;
|
|
121
|
-
if (config.activityRouting === 'shadow') {
|
|
122
|
-
const from = loop.would ?? {
|
|
123
|
-
lastRoute: loop.lastRoute,
|
|
124
|
-
lastActivity: loop.lastActivity ?? null,
|
|
125
|
-
state: loop.state,
|
|
126
|
-
};
|
|
127
|
-
const run = routeTurn(
|
|
128
|
-
{ ...config, activityRouting: 'on' },
|
|
129
|
-
{ ...loop, ...from },
|
|
130
|
-
{
|
|
131
|
-
...input,
|
|
132
|
-
facts: { ...facts, lastRoute: from.lastRoute },
|
|
133
|
-
},
|
|
134
|
-
);
|
|
135
|
-
const { activity, tier, model, effort, reason, lateral } = run;
|
|
136
|
-
// What the would-route's next request costs against the applied one's; a route priced against itself would
|
|
137
|
-
// still give a spread, so only a different request is priced.
|
|
138
|
-
const priced =
|
|
139
|
-
input.contextKnown &&
|
|
140
|
-
loop.lastRequest &&
|
|
141
|
-
run.tier &&
|
|
142
|
-
applied.tier &&
|
|
143
|
-
(run.model !== applied.model || run.effort !== applied.effort);
|
|
144
|
-
const difference = priced
|
|
145
|
-
? costs.nextTurnRange(
|
|
146
|
-
economicConfig(config, loop),
|
|
147
|
-
resolveRoute(config, run.tier, run.activity),
|
|
148
|
-
resolveRoute(config, applied.tier, applied.activity ?? null),
|
|
149
|
-
facts,
|
|
150
|
-
input.now,
|
|
151
|
-
)
|
|
152
|
-
: null;
|
|
153
|
-
wouldRoute = { activity, tier, model, effort, reason, lateral, difference };
|
|
154
|
-
const stays = pin || !run.tier;
|
|
155
|
-
would = {
|
|
156
|
-
lastRoute: stays ? from.lastRoute : run.tier,
|
|
157
|
-
lastActivity: stays ? from.lastActivity : run.activity,
|
|
158
|
-
state: run.state,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
113
|
const kept = pin || !applied.tier;
|
|
162
114
|
return {
|
|
163
115
|
...loop,
|
|
164
116
|
state: applied.state,
|
|
165
117
|
lastRoute: kept ? loop.lastRoute : applied.tier,
|
|
166
118
|
lastActivity: kept ? activityOf(config, loop) : applied.activity,
|
|
167
|
-
would,
|
|
168
119
|
turnId: facts.turnKey,
|
|
169
|
-
decision:
|
|
120
|
+
decision: applied,
|
|
170
121
|
suspended: false,
|
|
171
122
|
};
|
|
172
123
|
}
|
|
173
124
|
|
|
174
125
|
// The activity of the route running now. Outside `on` there is none, even one a turn in `on` left in the loop before
|
|
175
|
-
// the mode changed: `off`
|
|
126
|
+
// the mode changed: `off` is the 1.5 decision.
|
|
176
127
|
const activityOf = (config, loop) => (config.activityRouting === 'on' ? (loop.lastActivity ?? null) : null);
|
|
177
128
|
|
|
178
129
|
// One decision (plan §5.2) for the cell `{ tier, activity }` it lands on. Outside `on` the activity is null throughout.
|
|
@@ -231,7 +182,7 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
231
182
|
const candidate = pin ?? advice?.choice;
|
|
232
183
|
if (contextKnown && loop.lastRequest && TIERS.includes(candidate) && candidate !== loop.lastRoute) {
|
|
233
184
|
const [to, from] = [resolveRoute(config, candidate, activity), routeOf(last)];
|
|
234
|
-
const forecast = costs.
|
|
185
|
+
const forecast = costs.switchEconomics(projected, to, from, facts, now);
|
|
235
186
|
comparison = {
|
|
236
187
|
candidate,
|
|
237
188
|
incumbent: loop.lastRoute,
|
package/lib/subagents.mjs
CHANGED
|
@@ -117,12 +117,11 @@ export function coreModelOf(config, spawn, { envModel = null, force = false, def
|
|
|
117
117
|
|
|
118
118
|
// One spawn's record while its agent runs: what was decided and the priced replies since the last flush. `pass` is a
|
|
119
119
|
// PASS_REASONS entry or null. `choice` is the models key decided, or 'core' when the decision kept core's model.
|
|
120
|
-
// `actualUsd` prices each reply on the model it ran on; `otherUsd` the same tokens on
|
|
121
|
-
//
|
|
122
|
-
export function spawnRecord({ sessionId,
|
|
120
|
+
// `actualUsd` prices each reply on the model it ran on; `otherUsd` the same tokens on core's estimated model. Null for
|
|
121
|
+
// a pass-through.
|
|
122
|
+
export function spawnRecord({ sessionId, spawn, pass, choice, routedModel, coreModel, failed, respawn }) {
|
|
123
123
|
return {
|
|
124
124
|
sessionId,
|
|
125
|
-
mode,
|
|
126
125
|
type: spawn.subagentType,
|
|
127
126
|
pass,
|
|
128
127
|
choice,
|
|
@@ -151,7 +150,7 @@ export function addAgentReply(config, agent, usage, ttl) {
|
|
|
151
150
|
const next = { ...agent, requests: agent.requests + 1 };
|
|
152
151
|
const write = config.cache.writeMultiplier[ttl];
|
|
153
152
|
const actual = modelSpec(config, usage?.model);
|
|
154
|
-
const other = agent.pass ? null : modelSpec(config, agent.
|
|
153
|
+
const other = agent.pass ? null : modelSpec(config, agent.coreModel);
|
|
155
154
|
const priced = (spec) => spec && Number.isFinite(spec.output);
|
|
156
155
|
if (!Object.values(counts).every(isCount) || !Number.isFinite(write) || !priced(actual)) return next;
|
|
157
156
|
if (!agent.pass && !priced(other)) return next;
|
|
@@ -162,9 +161,10 @@ export function addAgentReply(config, agent, usage, ttl) {
|
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
// A record kept across sessions, one session's or their sum, since `since` (ms), the first agent after a reset.
|
|
165
|
-
// `routed[
|
|
164
|
+
// `routed.on[type]` counts the routed types; `passed[reason]` the pass-throughs, priced on the model they ran on. Records
|
|
165
|
+
// saved before 1.10.1 may also hold `routed.shadow`, which reads as dropped.
|
|
166
166
|
export function emptySubagentStore() {
|
|
167
|
-
return { version: 1, since: null, routed: {
|
|
167
|
+
return { version: 1, since: null, routed: { on: {} }, passed: {} };
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const ROUTED_SUMS = ['agents', 'differs', 'requests', 'pricedRequests', 'coreUsd', 'routedUsd', 'respawns', 'failures'];
|
|
@@ -189,9 +189,8 @@ export function recordAgent(store, agent, now) {
|
|
|
189
189
|
next.passed[agent.pass] = counts;
|
|
190
190
|
return next;
|
|
191
191
|
}
|
|
192
|
-
const byType = { ...next.routed
|
|
192
|
+
const byType = { ...next.routed.on };
|
|
193
193
|
const counts = { ...(byType[agent.type] ?? emptyRouted()), choices: { ...byType[agent.type]?.choices } };
|
|
194
|
-
const shadow = agent.mode === 'shadow';
|
|
195
194
|
counts.agents += first;
|
|
196
195
|
counts.differs += first && agent.routedModel !== agent.coreModel ? 1 : 0;
|
|
197
196
|
counts.respawns += first && agent.respawn ? 1 : 0;
|
|
@@ -199,10 +198,10 @@ export function recordAgent(store, agent, now) {
|
|
|
199
198
|
if (first) counts.choices[agent.choice] = (counts.choices[agent.choice] ?? 0) + 1;
|
|
200
199
|
counts.requests += agent.requests;
|
|
201
200
|
counts.pricedRequests += agent.pricedRequests;
|
|
202
|
-
counts.coreUsd +=
|
|
203
|
-
counts.routedUsd +=
|
|
201
|
+
counts.coreUsd += agent.otherUsd;
|
|
202
|
+
counts.routedUsd += agent.actualUsd;
|
|
204
203
|
byType[agent.type] = counts;
|
|
205
|
-
next.routed
|
|
204
|
+
next.routed = { on: byType };
|
|
206
205
|
return next;
|
|
207
206
|
}
|
|
208
207
|
|
|
@@ -243,10 +242,7 @@ export function readSubagentStore(value) {
|
|
|
243
242
|
return {
|
|
244
243
|
version: 1,
|
|
245
244
|
since: value.since,
|
|
246
|
-
routed: {
|
|
247
|
-
shadow: readMap(value.routed?.shadow, ROUTED_SUMS, true),
|
|
248
|
-
on: readMap(value.routed?.on, ROUTED_SUMS, true),
|
|
249
|
-
},
|
|
245
|
+
routed: { on: readMap(value.routed?.on, ROUTED_SUMS, true) },
|
|
250
246
|
passed: readMap(value.passed, PASSED_SUMS, false),
|
|
251
247
|
};
|
|
252
248
|
}
|
|
@@ -272,7 +268,6 @@ export function mergeSubagentStores(values, resetAt = null) {
|
|
|
272
268
|
for (const one of values.map((value) => subagentsAfterReset(readSubagentStore(value), resetAt))) {
|
|
273
269
|
const since = [merged.since, one.since].filter(Number.isFinite);
|
|
274
270
|
merged.since = since.length ? Math.min(...since) : null;
|
|
275
|
-
addInto(merged.routed.shadow, one.routed.shadow, ROUTED_SUMS, true);
|
|
276
271
|
addInto(merged.routed.on, one.routed.on, ROUTED_SUMS, true);
|
|
277
272
|
addInto(merged.passed, one.passed, PASSED_SUMS, false);
|
|
278
273
|
}
|
package/lib/view.mjs
CHANGED
|
@@ -35,7 +35,6 @@ export function initialView(model) {
|
|
|
35
35
|
activity: null,
|
|
36
36
|
activityChoice: null,
|
|
37
37
|
activityProbabilities: null,
|
|
38
|
-
wouldRoute: null,
|
|
39
38
|
history: [],
|
|
40
39
|
tiers: [],
|
|
41
40
|
activities: [],
|
|
@@ -71,11 +70,10 @@ export const CLEARED_READINGS = {
|
|
|
71
70
|
estimate: null,
|
|
72
71
|
activityChoice: null,
|
|
73
72
|
activityProbabilities: null,
|
|
74
|
-
wouldRoute: null,
|
|
75
73
|
};
|
|
76
74
|
|
|
77
75
|
// The view patch for a tool continuation's route. In `on` the activity label is the route's, which a fallback to the
|
|
78
|
-
// native model drops
|
|
76
|
+
// native model drops.
|
|
79
77
|
export function continuationView(config, decision, context) {
|
|
80
78
|
return {
|
|
81
79
|
selectedModel: decision.model,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Native Claude Code Mod: model and effort routing for the main conversation, advised by Jev, Clef, Clef Flash, OpenAI or Ollama.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare module 'claude-code' {
|
|
|
4
4
|
// What kind of work a turn does (ACTIVITIES in lib/config.mjs); 'uncertain' only as a classifier answer.
|
|
5
5
|
type RouterActivity = 'code' | 'debug' | 'explore' | 'plan' | 'review' | 'ops' | 'docs';
|
|
6
6
|
type RouterActivityAnswer = RouterActivity | 'uncertain';
|
|
7
|
-
type RouterActivityMode = 'off' | '
|
|
7
|
+
type RouterActivityMode = 'off' | 'on';
|
|
8
8
|
// A finished turn's bucket, read from its tool calls.
|
|
9
9
|
type RouterObserved = 'code' | 'docs' | 'ops' | 'read' | 'talk';
|
|
10
10
|
// A route change inside the incumbent's tier: taken, refused (does not pay back, a hold, the cash gate), or none.
|
|
@@ -20,28 +20,6 @@ declare module 'claude-code' {
|
|
|
20
20
|
probabilities: Record<RouterActivityAnswer, number>;
|
|
21
21
|
} | null;
|
|
22
22
|
}
|
|
23
|
-
// A next-request cost difference in USD at configured list prices; negative is cheaper.
|
|
24
|
-
interface RouterUsdRange {
|
|
25
|
-
minUsd: number;
|
|
26
|
-
maxUsd: number;
|
|
27
|
-
}
|
|
28
|
-
// What `on` would do, computed in `shadow`. `model` is a model id, as `decision.model`. `difference` prices its next
|
|
29
|
-
// request against the applied route's; null when the routes match or there is no measured request yet.
|
|
30
|
-
interface RouterWouldRoute {
|
|
31
|
-
activity: RouterActivity | null;
|
|
32
|
-
tier: RouterTier | null;
|
|
33
|
-
model: string;
|
|
34
|
-
effort: string | number | null;
|
|
35
|
-
reason: string;
|
|
36
|
-
lateral: RouterLateral;
|
|
37
|
-
difference: RouterUsdRange | null;
|
|
38
|
-
}
|
|
39
|
-
// Shadow turns, those `on` would route differently, and of those the ones with a `difference`, summed.
|
|
40
|
-
interface RouterActivityShadow extends RouterUsdRange {
|
|
41
|
-
differs: number;
|
|
42
|
-
turns: number;
|
|
43
|
-
estimated: number;
|
|
44
|
-
}
|
|
45
23
|
interface RouterActivityCounts {
|
|
46
24
|
turns: number;
|
|
47
25
|
requests: number;
|
|
@@ -57,11 +35,9 @@ declare module 'claude-code' {
|
|
|
57
35
|
interface RouterActivitySession {
|
|
58
36
|
byActivity: Partial<Record<RouterActivity | 'none', RouterActivityCounts>>;
|
|
59
37
|
switches: { tier: number; activity: number };
|
|
60
|
-
// Lateral moves taken and refused (by economics, a hold or the cash gate)
|
|
61
|
-
// by 1.7.0.
|
|
38
|
+
// Lateral moves taken and refused (by economics, a hold or the cash gate); absent in views saved by 1.7.0.
|
|
62
39
|
lateral?: { taken: number; refused: number };
|
|
63
40
|
agreement: { matched: number; total: number };
|
|
64
|
-
shadow: RouterActivityShadow;
|
|
65
41
|
}
|
|
66
42
|
// Cross-session counts under store key 'activity:stats:v1'. `runs` buckets run lengths 1, 2, 3, 4, 5+.
|
|
67
43
|
interface RouterActivityStore {
|
|
@@ -69,8 +45,6 @@ declare module 'claude-code' {
|
|
|
69
45
|
confusion: Partial<Record<RouterActivityAnswer | 'none', Partial<Record<RouterObserved, number>>>>;
|
|
70
46
|
runs: Partial<Record<RouterActivity, [number, number, number, number, number]>>;
|
|
71
47
|
lateral: { taken: number; refused: number };
|
|
72
|
-
// A 1.6.0 store has `differs` and `turns` only; readStore fills the rest with zeros.
|
|
73
|
-
shadow: RouterActivityShadow;
|
|
74
48
|
}
|
|
75
49
|
// Cross-session readings under store key 'activity:metrics:v1'. Classifier wait per turn by classifier id, in
|
|
76
50
|
// LATENCY_BOUNDS buckets plus one above; at most 8 ids. Cheaper activity moves taken in 'on' and the escalations that
|
|
@@ -165,7 +139,7 @@ declare module 'claude-code' {
|
|
|
165
139
|
interface RouterSubagentStore {
|
|
166
140
|
version: 1;
|
|
167
141
|
since: number | null;
|
|
168
|
-
routed: {
|
|
142
|
+
routed: { on: Record<string, RouterSubagentCounts> };
|
|
169
143
|
passed: Partial<Record<'fork' | 'explicit' | 'teammate' | 'workflow' | 'unlisted', RouterSubagentPassed>>;
|
|
170
144
|
}
|
|
171
145
|
interface RouterView {
|
|
@@ -196,11 +170,10 @@ declare module 'claude-code' {
|
|
|
196
170
|
estimate?: RouterEstimate | null;
|
|
197
171
|
comparison?: RouterComparison | null;
|
|
198
172
|
probabilities?: Partial<Record<RouterTier | 'uncertain', number>> | null;
|
|
199
|
-
// The turn's activity
|
|
173
|
+
// The turn's activity, applied in 'on'.
|
|
200
174
|
activity?: RouterActivity | null;
|
|
201
175
|
activityChoice?: RouterActivityAnswer | null;
|
|
202
176
|
activityProbabilities?: Partial<Record<RouterActivityAnswer, number>> | null;
|
|
203
|
-
wouldRoute?: RouterWouldRoute | null;
|
|
204
177
|
history?: number[];
|
|
205
178
|
tiers?: (RouterTier | null)[];
|
|
206
179
|
// Aligned with `history` and `tiers`.
|
|
@@ -239,8 +212,6 @@ declare module 'claude-code' {
|
|
|
239
212
|
lastRoute: RouterTier;
|
|
240
213
|
// The activity of the route running now; absent in loops saved before 1.6.
|
|
241
214
|
lastActivity?: RouterActivity | null;
|
|
242
|
-
// Shadow mode only: the cell and policy state `on` would run with, so each would-route continues the last one.
|
|
243
|
-
would?: { lastRoute: RouterTier; lastActivity: RouterActivity | null; state: RouterPolicyState } | null;
|
|
244
215
|
state: RouterPolicyState;
|
|
245
216
|
models: Record<string, { lastAt: number; prefixTokens: number }>;
|
|
246
217
|
resolutions: Record<string, string>;
|
|
@@ -264,12 +235,11 @@ declare module 'claude-code' {
|
|
|
264
235
|
effort: string | number | null;
|
|
265
236
|
estimate?: RouterEstimate | null;
|
|
266
237
|
comparison?: RouterComparison | null;
|
|
267
|
-
// The applied activity
|
|
238
|
+
// The applied activity.
|
|
268
239
|
activity?: RouterActivity | null;
|
|
269
240
|
lateral?: RouterLateral;
|
|
270
241
|
// A failure asked for an escalation this turn, also one the cash gate held or context-fit replaced.
|
|
271
242
|
escalated?: boolean;
|
|
272
|
-
wouldRoute?: RouterWouldRoute | null;
|
|
273
243
|
pinned: boolean;
|
|
274
244
|
requestedPin: RouterTier | null;
|
|
275
245
|
} | null;
|