@alexeiled/claude-router 1.12.0 → 1.13.0
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 +16 -0
- package/docs/architecture.md +1 -1
- package/docs/native-router.md +1 -1
- package/docs/router-pane-now.svg +111 -77
- package/docs/router-pane-usage-whatif.svg +62 -67
- package/docs/router-pane-usage.svg +34 -34
- package/docs/user-guide.md +10 -6
- package/hooks/native-router.mjs +34 -18
- package/lib/display.mjs +0 -5
- package/lib/panel.mjs +227 -93
- package/lib/view.mjs +50 -11
- package/package.json +1 -1
- package/types/index.d.ts +11 -4
package/lib/panel.mjs
CHANGED
|
@@ -17,7 +17,6 @@ import { effortSharesCache, routeEffort } from './cost.mjs';
|
|
|
17
17
|
import {
|
|
18
18
|
activityReading,
|
|
19
19
|
activityVerb,
|
|
20
|
-
bar,
|
|
21
20
|
classifierLabel,
|
|
22
21
|
classifierStatus,
|
|
23
22
|
differenceShare,
|
|
@@ -35,7 +34,6 @@ import {
|
|
|
35
34
|
savingsColor,
|
|
36
35
|
signedUsd,
|
|
37
36
|
sparkline,
|
|
38
|
-
switchCount,
|
|
39
37
|
TIER_COLOR,
|
|
40
38
|
unavailableReason,
|
|
41
39
|
usageMetrics,
|
|
@@ -50,6 +48,7 @@ import {
|
|
|
50
48
|
allTime,
|
|
51
49
|
breakdown,
|
|
52
50
|
cellsWhere,
|
|
51
|
+
dayKey,
|
|
53
52
|
INSIGHT_REPLIES,
|
|
54
53
|
insights,
|
|
55
54
|
mostlyOn,
|
|
@@ -59,6 +58,7 @@ import {
|
|
|
59
58
|
summarize,
|
|
60
59
|
trend,
|
|
61
60
|
} from './usage.mjs';
|
|
61
|
+
import { mergePairs, STRIP_CELLS } from './view.mjs';
|
|
62
62
|
|
|
63
63
|
// Routes and Policy edit one draft and save together; Classifier saves each pick at once.
|
|
64
64
|
const TABS = [
|
|
@@ -259,9 +259,9 @@ function supportText(label, estimate) {
|
|
|
259
259
|
return `${label} gave ${direction} tiers ${Number.isFinite(mass) ? gave : '—'} (needs ${needs})${cost}`;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
// What runs next turn and why first
|
|
263
|
-
// context and cost readings.
|
|
264
|
-
function nowTab(ui, config, view, usage, actions) {
|
|
262
|
+
// What runs next turn and why first, with the one-turn pins; then this session and today as headlines, the finding
|
|
263
|
+
// worth a look, and Claude's context and cost readings.
|
|
264
|
+
function nowTab(ui, config, view, usage, actions, _modelOptions, columns, now) {
|
|
265
265
|
const metrics = usageMetrics(config, view, usage);
|
|
266
266
|
const unavailable = view.phase === 'unavailable';
|
|
267
267
|
const auto = view.mode === 'auto' && !unavailable;
|
|
@@ -314,30 +314,16 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
314
314
|
ui.Button({ key: 'key', label: 'Set up', hotkey: 'k', onPress: actions.key }),
|
|
315
315
|
)
|
|
316
316
|
: null,
|
|
317
|
-
ui
|
|
318
|
-
ui.line(
|
|
319
|
-
ui.head('TIERS'),
|
|
320
|
-
ui.dim(auto ? ` · ${label} support on the last turn · pin = next turn only` : ` · ${label} support`),
|
|
321
|
-
),
|
|
317
|
+
pinLine(ui, view, auto, unavailable, actions, columns),
|
|
322
318
|
];
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
ui.tier(tier, tier.padEnd(8)),
|
|
330
|
-
routeName(config, config.routes[tier]).padEnd(22),
|
|
331
|
-
meter ? ui.text(meter.text, { color: TIER_COLOR[tier] }) : ui.dim('—'.padEnd(10)),
|
|
332
|
-
meter ? ` ${percent(support).padStart(4)} ` : ' ',
|
|
333
|
-
auto ? ui.Button({ key: `pin-${tier}`, label: 'pin', onPress: () => actions.pin(tier) }) : null,
|
|
334
|
-
),
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
if (!auto)
|
|
338
|
-
out.push(ui.dim(unavailable ? ' Pins need routing, which is unavailable.' : ' Pins need routing on (o above).'));
|
|
339
|
-
out.push(ui.text(' '), ...replies(ui, view));
|
|
319
|
+
const session = summarize(readUsage(view.usageSession), periodRange('session', now));
|
|
320
|
+
const today = summarize(readUsage(view.usageStore), periodRange('today', now));
|
|
321
|
+
out.push(ui.text(' '), ...sessionLines(ui, view, session, actions, columns, now));
|
|
322
|
+
// Today repeats this session's part of it until another session adds to it.
|
|
323
|
+
const ownToday = summarize(readUsage(view.usageSession), periodRange('today', now));
|
|
324
|
+
if (today.replies > ownToday.replies) out.push(ui.text(' '), ...todayLines(ui, today, actions, columns));
|
|
340
325
|
out.push(
|
|
326
|
+
...worthLines(ui, today, actions, columns),
|
|
341
327
|
ui.text(' '),
|
|
342
328
|
ui.gauge('Context ', metrics.contextBar, contextSuffix(metrics)),
|
|
343
329
|
ui.line(
|
|
@@ -384,7 +370,7 @@ function readingDetail(ui, view, metrics) {
|
|
|
384
370
|
ui.dim(` cache read ${formatTokens(view.cacheRead)} · written ${formatTokens(view.cacheWrite)} tokens`),
|
|
385
371
|
ui.dim(` output ${formatTokens(view.outputTokens)} tokens on the last reply`),
|
|
386
372
|
ui.text(' '),
|
|
387
|
-
ui.head(
|
|
373
|
+
ui.head(`INPUT PER REPLY · last ${plural(history.length, 'reply', 'replies')} · lowest to highest`),
|
|
388
374
|
trend,
|
|
389
375
|
ui.text(' '),
|
|
390
376
|
ui.head('ESTIMATES · configured list prices'),
|
|
@@ -406,47 +392,183 @@ function readingDetail(ui, view, metrics) {
|
|
|
406
392
|
|
|
407
393
|
const verbShare = (text) => text.replace(/^(\S+)/, (name) => activityVerb(name));
|
|
408
394
|
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
function
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
395
|
+
// One button per tier with the classifier's support on the last turn, the current tier marked; a press pins the next
|
|
396
|
+
// turn only. Without routing there is nothing to pin.
|
|
397
|
+
function pinLine(ui, view, auto, unavailable, actions, columns) {
|
|
398
|
+
if (!auto)
|
|
399
|
+
return ui.line(
|
|
400
|
+
'Pin next ',
|
|
401
|
+
ui.dim(unavailable ? 'needs routing, which is unavailable' : 'needs routing on (o above)'),
|
|
402
|
+
);
|
|
403
|
+
return ui.line(
|
|
404
|
+
'Pin next ',
|
|
405
|
+
...LADDER.flatMap((tier) => {
|
|
406
|
+
const support = view.probabilities?.[tier];
|
|
407
|
+
return [
|
|
408
|
+
ui.Button({
|
|
409
|
+
key: `pin-${tier}`,
|
|
410
|
+
label: `${view.tier === tier ? '▶ ' : ''}${tier} ${Number.isFinite(support) ? percent(support) : '—'}`,
|
|
411
|
+
variant: view.pendingPin === tier ? 'primary' : 'secondary',
|
|
412
|
+
onPress: () => actions.pin(tier),
|
|
413
|
+
}),
|
|
414
|
+
' ',
|
|
415
|
+
];
|
|
416
|
+
}),
|
|
417
|
+
!Number.isFinite(columns) || columns >= PIN_HINT_COLUMNS ? ui.dim(' next turn only') : null,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const PIN_HINT_COLUMNS = 80;
|
|
421
|
+
|
|
422
|
+
// "13:41", or "Oct 12 13:41" for another day than `now`'s.
|
|
423
|
+
const clockText = (ms) => new Date(ms).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
|
|
424
|
+
const sinceText = (ms, now) =>
|
|
425
|
+
dayKey(ms) === dayKey(now) ? clockText(ms) : `${dayLabel(dayKey(ms))} ${clockText(ms)}`;
|
|
426
|
+
|
|
427
|
+
// The strip cell's tier: the one with most replies, the stronger on a tie; `none` where routing served none.
|
|
428
|
+
const STRIP_ORDER = [...LADDER, 'none'];
|
|
429
|
+
const cellTier = (cell) => STRIP_ORDER.reduce((top, key) => ((cell[key] ?? 0) > (cell[top] ?? 0) ? key : top));
|
|
430
|
+
|
|
431
|
+
// The session strip fitted to the pane beside its note: pairs of cells merge until both fit. The note says how many
|
|
432
|
+
// replies a cell holds, and since when the strip runs when Claude Code restarted after the session's first reply.
|
|
433
|
+
function fittedStrip(strip, columns, since, now) {
|
|
434
|
+
let { per, cells } = strip;
|
|
435
|
+
const restarted = Number.isFinite(strip.from) && Number.isFinite(since) && strip.from > since;
|
|
436
|
+
const note = () =>
|
|
437
|
+
[per > 1 ? `${per} replies per cell` : null, restarted ? `since ${sinceText(strip.from, now)}` : null]
|
|
438
|
+
.filter(Boolean)
|
|
439
|
+
.join(' · ');
|
|
440
|
+
const room = () => (Number.isFinite(columns) ? Math.max(8, columns - 4 - note().length) : STRIP_CELLS);
|
|
441
|
+
while (cells.length > room()) {
|
|
442
|
+
cells = mergePairs(cells);
|
|
443
|
+
per *= 2;
|
|
444
|
+
}
|
|
445
|
+
return { cells, note: note() };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// This session: since its first routed reply, its routed replies and route switches; its replies as a strip colored
|
|
449
|
+
// by tier, with the replies per tier, and the routed replies per activity; the last switch; and routing against your
|
|
450
|
+
// model, linked to Usage.
|
|
451
|
+
function sessionLines(ui, view, summary, actions, columns, now) {
|
|
452
|
+
const since = readUsage(view.usageSession).since;
|
|
453
|
+
const strip = view.strip?.cells?.length ? fittedStrip(view.strip, columns, since, now) : null;
|
|
454
|
+
const counts = {};
|
|
455
|
+
for (const cell of view.strip?.cells ?? [])
|
|
456
|
+
for (const [key, n] of Object.entries(cell)) counts[key] = (counts[key] ?? 0) + n;
|
|
457
|
+
const replies = Object.values(counts).reduce((sum, n) => sum + n, 0);
|
|
458
|
+
const switches = summary.switches.tier + summary.switches.activity;
|
|
459
|
+
const head = [
|
|
460
|
+
Number.isFinite(since) ? `since ${sinceText(since, now)}` : null,
|
|
461
|
+
summary.replies
|
|
462
|
+
? plural(summary.replies, 'routed reply', 'routed replies')
|
|
463
|
+
: replies
|
|
464
|
+
? plural(replies, 'reply', 'replies')
|
|
465
|
+
: null,
|
|
466
|
+
summary.turns ? plural(switches, 'route switch', 'route switches') : null,
|
|
467
|
+
].filter(Boolean);
|
|
468
|
+
if (!strip && !summary.replies) return [ui.line(ui.head('SESSION'), ui.dim(' · no replies yet'))];
|
|
469
|
+
const out = [ui.line(ui.head('SESSION'), head.length ? ui.dim(` · ${head.join(' · ')}`) : null)];
|
|
470
|
+
if (strip) {
|
|
471
|
+
out.push(
|
|
472
|
+
ui.line(
|
|
473
|
+
' ',
|
|
474
|
+
...strip.cells.map((cell) => {
|
|
475
|
+
const tier = cellTier(cell);
|
|
476
|
+
return tier === 'none' ? ui.dim('·') : ui.tier(tier, '█');
|
|
477
|
+
}),
|
|
478
|
+
strip.note ? ui.dim(` ${strip.note}`) : null,
|
|
479
|
+
),
|
|
480
|
+
ui.line(
|
|
481
|
+
' ',
|
|
482
|
+
...TIERS.filter((tier) => counts[tier]).flatMap((tier) => [ui.tier(tier, '■ '), `${tier} ${counts[tier]} `]),
|
|
483
|
+
counts.none ? ui.dim(`· not routed ${counts.none}`) : null,
|
|
484
|
+
),
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
const used = breakdown(summary.cells, 'activity')
|
|
488
|
+
.filter((group) => ACTIVITIES.includes(group.name))
|
|
489
|
+
.sort((a, b) => b.sums[0] - a.sums[0])
|
|
490
|
+
.map((group) => [group.name, `${activityVerb(group.name)} ${group.sums[0]}`]);
|
|
491
|
+
// The most used first, as many as fit the pane; the rest as a count.
|
|
492
|
+
const shown = [];
|
|
493
|
+
for (const [i, entry] of used.entries()) {
|
|
494
|
+
const rest = used.length - i - 1;
|
|
495
|
+
const width =
|
|
496
|
+
2 + [...shown, entry].map(([, text]) => text).join(' · ').length + (rest ? ` · +${rest} more`.length : 0);
|
|
497
|
+
if (Number.isFinite(columns) && width > columns && shown.length) break;
|
|
498
|
+
shown.push(entry);
|
|
499
|
+
}
|
|
500
|
+
if (shown.length)
|
|
501
|
+
out.push(
|
|
502
|
+
ui.line(
|
|
503
|
+
' ',
|
|
504
|
+
...shown.flatMap(([name, text], i) => [
|
|
505
|
+
ui.activity(name),
|
|
506
|
+
ui.dim(`${text.slice(activityVerb(name).length)}${i < shown.length - 1 ? ' · ' : ''}`),
|
|
507
|
+
]),
|
|
508
|
+
shown.length < used.length ? ui.dim(` · +${used.length - shown.length} more`) : null,
|
|
509
|
+
),
|
|
510
|
+
);
|
|
511
|
+
const last = view.lastSwitch;
|
|
512
|
+
if (Number.isFinite(last?.at) && last.from && last.to) out.push(lastSwitchLine(ui, last, now));
|
|
513
|
+
if (summary.replies)
|
|
514
|
+
out.push(verdictLine(ui, readout(summary), () => actions.usageFor('session'), 'session', columns));
|
|
515
|
+
return out;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// "last switch 13:41 medium → high · debugging"; routes by name when the switch kept the tier.
|
|
519
|
+
function lastSwitchLine(ui, last, now) {
|
|
520
|
+
const byTier = TIERS.includes(last.from.tier) && TIERS.includes(last.to.tier) && last.from.tier !== last.to.tier;
|
|
521
|
+
return ui.line(
|
|
522
|
+
' ',
|
|
523
|
+
ui.dim(`last switch ${sinceText(last.at, now)} `),
|
|
524
|
+
...(byTier
|
|
525
|
+
? [ui.tier(last.from.tier), ui.dim(' → '), ui.tier(last.to.tier)]
|
|
526
|
+
: [routeLabel(last.from.model, last.from.effort), ui.dim(' → '), routeLabel(last.to.model, last.to.effort)]),
|
|
527
|
+
...(ACTIVITIES.includes(last.activity) ? [ui.dim(' · '), ui.activity(last.activity)] : []),
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Routing against your model, with the Usage tab on the same period one press away. The switch writes in it and an
|
|
532
|
+
// early sample follow where the pane has room, the early sample dropping first.
|
|
533
|
+
function verdictLine(ui, r, open, period, columns) {
|
|
534
|
+
const notes = [
|
|
535
|
+
r.switchUsd > 0 ? ` · switch writes ${usd(r.switchUsd)}` : null,
|
|
536
|
+
r.early ? ' · early sample' : null,
|
|
537
|
+
].filter(Boolean);
|
|
538
|
+
const width = () => 2 + verdictText(r).join('').length + notes.join('').length + USAGE_LINK;
|
|
539
|
+
while (notes.length && Number.isFinite(columns) && width() > columns) notes.pop();
|
|
540
|
+
return ui.line(
|
|
541
|
+
' ',
|
|
542
|
+
...verdictParts(ui, r),
|
|
543
|
+
...notes.map((note) => ui.dim(note)),
|
|
544
|
+
' ',
|
|
545
|
+
ui.Button({ key: `usage-${period}`, label: 'Usage', onPress: open }),
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
// " [ Usage ]" after the verdict.
|
|
549
|
+
const USAGE_LINK = 11;
|
|
550
|
+
|
|
551
|
+
// Today across sessions, shown once another session added to it.
|
|
552
|
+
function todayLines(ui, summary, actions, columns) {
|
|
553
|
+
const switches = summary.switches.tier + summary.switches.activity;
|
|
422
554
|
return [
|
|
423
555
|
ui.line(
|
|
424
|
-
ui.head(
|
|
425
|
-
ui.dim(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
ui.line(
|
|
429
|
-
' ',
|
|
430
|
-
...TIERS.filter((tier) => tiers.includes(tier)).flatMap((tier) => [
|
|
431
|
-
ui.tier(tier, '■ '),
|
|
432
|
-
`${tier} ${count(tiers, tier)} `,
|
|
433
|
-
]),
|
|
434
|
-
notRouted ? ui.dim(`· not routed ${notRouted}`) : null,
|
|
556
|
+
ui.head('TODAY'),
|
|
557
|
+
ui.dim(
|
|
558
|
+
` · ${plural(summary.replies, 'routed reply', 'routed replies')} · ${plural(switches, 'route switch', 'route switches')}`,
|
|
559
|
+
),
|
|
435
560
|
),
|
|
436
|
-
|
|
437
|
-
? [
|
|
438
|
-
ui.line(
|
|
439
|
-
' ',
|
|
440
|
-
...used.flatMap(([activity, n], i) => [
|
|
441
|
-
ui.activity(activity),
|
|
442
|
-
ui.dim(` ${n}${i < used.length - 1 ? ' · ' : ''}`),
|
|
443
|
-
]),
|
|
444
|
-
),
|
|
445
|
-
]
|
|
446
|
-
: []),
|
|
561
|
+
verdictLine(ui, readout(summary), () => actions.usageFor('today'), 'today', columns),
|
|
447
562
|
];
|
|
448
563
|
}
|
|
449
564
|
|
|
565
|
+
// Today's first finding from Usage's WORTH A LOOK, with the tab that changes it; nothing when there is none.
|
|
566
|
+
function worthLines(ui, summary, actions, columns) {
|
|
567
|
+
const [first] = summary.replies >= INSIGHT_REPLIES ? insights(summary) : [];
|
|
568
|
+
if (!first) return [];
|
|
569
|
+
return [ui.text(' '), ui.line(ui.head('WORTH A LOOK'), ui.dim(' · today')), insightLine(ui, first, actions, columns)];
|
|
570
|
+
}
|
|
571
|
+
|
|
450
572
|
// Rows: [key, label, format, router.json field]. Typed as tuples so tsc keeps each position's type.
|
|
451
573
|
/** @type {[string, string, (value: number) => string, string][]} */
|
|
452
574
|
const POLICY_ROWS = [
|
|
@@ -1273,19 +1395,29 @@ function headline(ui, config, view, period, r) {
|
|
|
1273
1395
|
),
|
|
1274
1396
|
];
|
|
1275
1397
|
}
|
|
1276
|
-
const share = differenceShare(r)?.replace(/^[−+]/, '');
|
|
1277
|
-
const amount = `${usd(r.differenceUsd)}${share ? ` (${share})` : ''}`;
|
|
1278
|
-
const color = savingsColor(r.differenceUsd);
|
|
1279
1398
|
return [
|
|
1280
1399
|
ui.line(
|
|
1281
|
-
|
|
1282
|
-
r.differenceUsd === 0 ? '' : ui.text(amount, { bold: true, color }),
|
|
1283
|
-
r.differenceUsd < 0 ? ' vs your model' : r.differenceUsd > 0 ? ' more than your model' : ' your model',
|
|
1400
|
+
...verdictParts(ui, r),
|
|
1284
1401
|
r.early ? ui.text(` early sample · ${plural(r.replies, 'reply', 'replies')}`, { color: 'yellow' }) : null,
|
|
1285
1402
|
),
|
|
1286
1403
|
];
|
|
1287
1404
|
}
|
|
1288
1405
|
|
|
1406
|
+
// "Routing saved $1.84 (22%) vs your model", or what it cost more: the text before the amount, the amount, the rest.
|
|
1407
|
+
function verdictText(r) {
|
|
1408
|
+
const share = differenceShare(r)?.replace(/^[−+]/, '');
|
|
1409
|
+
return [
|
|
1410
|
+
r.differenceUsd < 0 ? 'Routing saved ' : r.differenceUsd > 0 ? 'Routing cost ' : 'Routing cost the same as',
|
|
1411
|
+
r.differenceUsd === 0 ? '' : `${usd(r.differenceUsd)}${share ? ` (${share})` : ''}`,
|
|
1412
|
+
r.differenceUsd < 0 ? ' vs your model' : r.differenceUsd > 0 ? ' more than your model' : ' your model',
|
|
1413
|
+
];
|
|
1414
|
+
}
|
|
1415
|
+
// The verdict as line parts, the amount bold in the savings color.
|
|
1416
|
+
function verdictParts(ui, r) {
|
|
1417
|
+
const [before, amount, after] = verdictText(r);
|
|
1418
|
+
return [before, amount ? ui.text(amount, { bold: true, color: savingsColor(r.differenceUsd) }) : '', after];
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1289
1421
|
// Your model − cheaper models + stronger models + switch cache writes = routed, in whole cents that add up (readout).
|
|
1290
1422
|
function ledger(ui, config, view, { period, r, summary, legacy, columns }) {
|
|
1291
1423
|
const tier = yourTier(config, view);
|
|
@@ -1508,6 +1640,15 @@ function insightLines(ui, summary, actions, columns) {
|
|
|
1508
1640
|
if (summary.replies < INSIGHT_REPLIES) return [];
|
|
1509
1641
|
const list = insights(summary);
|
|
1510
1642
|
if (!list.length) return [];
|
|
1643
|
+
return [
|
|
1644
|
+
ui.text(' '),
|
|
1645
|
+
ui.line(ui.head('WORTH A LOOK'), ui.dim(' · from the numbers; answer quality is not measured')),
|
|
1646
|
+
...list.map((insight) => insightLine(ui, insight, actions, columns)),
|
|
1647
|
+
];
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
// One finding with the tab that changes it.
|
|
1651
|
+
function insightLine(ui, insight, actions, columns) {
|
|
1511
1652
|
const where = ({ activity, tier }) => [
|
|
1512
1653
|
...(ACTIVITIES.includes(activity) ? [ui.activity(activity), ui.dim(' · ')] : []),
|
|
1513
1654
|
TIERS.includes(tier) ? ui.tier(tier) : ui.dim('not routed'),
|
|
@@ -1523,30 +1664,23 @@ function insightLines(ui, summary, actions, columns) {
|
|
|
1523
1664
|
),
|
|
1524
1665
|
})
|
|
1525
1666
|
: null;
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
insight.
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
),
|
|
1544
|
-
);
|
|
1545
|
-
return [
|
|
1546
|
-
ui.text(' '),
|
|
1547
|
-
ui.line(ui.head('WORTH A LOOK'), ui.dim(' · from the numbers; answer quality is not measured')),
|
|
1548
|
-
...lines,
|
|
1549
|
-
];
|
|
1667
|
+
return insight.kind === 'switch'
|
|
1668
|
+
? ui.line(
|
|
1669
|
+
` Switch cache writes used ${percent(insight.share)} of the cheaper-model saving `,
|
|
1670
|
+
ui.Button({ key: 'insight-switch', label: 'Policy', onPress: () => actions.tab('policy') }),
|
|
1671
|
+
)
|
|
1672
|
+
: ui.line(
|
|
1673
|
+
' ',
|
|
1674
|
+
...where(insight),
|
|
1675
|
+
insight.kind === 'cost'
|
|
1676
|
+
? ` carried ${percent(insight.share)} of the cost`
|
|
1677
|
+
: ` ran ${usd(insight.usd)} above your model`,
|
|
1678
|
+
insight.route && (!Number.isFinite(columns) || columns >= 90)
|
|
1679
|
+
? ui.dim(` · mostly ${routeText(insight.route)}`)
|
|
1680
|
+
: null,
|
|
1681
|
+
' ',
|
|
1682
|
+
link(insight),
|
|
1683
|
+
);
|
|
1550
1684
|
}
|
|
1551
1685
|
|
|
1552
1686
|
// Delete history waits for a second press, as nothing brings the records back.
|
package/lib/view.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// The view the band and pane draw from: its initial shape and the patches built from pure inputs. Pure: the hook
|
|
2
2
|
// writes the view to $.state.
|
|
3
3
|
|
|
4
|
-
// Replies kept for the
|
|
5
|
-
const HISTORY = 30;
|
|
4
|
+
// Replies kept for the input trend behind the Now tab's details.
|
|
5
|
+
export const HISTORY = 30;
|
|
6
|
+
// The session strip's most cells. Once it is full, neighbouring cells merge, so each covers twice the replies and the
|
|
7
|
+
// strip always spans the whole session in a bounded view.
|
|
8
|
+
export const STRIP_CELLS = 48;
|
|
6
9
|
|
|
7
10
|
export function initialView(model) {
|
|
8
11
|
return {
|
|
@@ -37,8 +40,10 @@ export function initialView(model) {
|
|
|
37
40
|
activityProbabilities: null,
|
|
38
41
|
history: [],
|
|
39
42
|
tiers: [],
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
// The session's replies by tier (addToStrip), and the last route switch: when, the tiers and routes it moved
|
|
44
|
+
// between, and the turn's activity.
|
|
45
|
+
strip: null,
|
|
46
|
+
lastSwitch: null,
|
|
42
47
|
activityStats: null,
|
|
43
48
|
activityStore: null,
|
|
44
49
|
activityMetrics: null,
|
|
@@ -97,10 +102,45 @@ export function continuationView(config, decision, context) {
|
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
// The view patch for a
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
// The view patch for a route switch at `at`: the routes it moved between with their tiers, and the activity the new
|
|
106
|
+
// route runs for (null outside activity routing `on`).
|
|
107
|
+
export const switchView = (from, to, activity, at) => ({
|
|
108
|
+
lastSwitch: { at, from: routeOf(from), to: routeOf(to), activity: activity ?? null },
|
|
109
|
+
});
|
|
110
|
+
const routeOf = (decision) => ({ tier: decision.tier ?? null, model: decision.model, effort: decision.effort ?? null });
|
|
111
|
+
|
|
112
|
+
// A reply that arrived `at` (ms) added to the session strip, `{ per, cells, from }`: each cell counts up to `per`
|
|
113
|
+
// replies by tier, `none` for one routing did not serve, and `from` is when the first reply arrived. A full strip
|
|
114
|
+
// merges each pair of cells first. The view lives as long as the Claude Code process, so after a restart the strip
|
|
115
|
+
// starts again while the session's usage record goes on: `from` tells the two apart.
|
|
116
|
+
export function addToStrip(strip, tier, at = null) {
|
|
117
|
+
const key = tier ?? 'none';
|
|
118
|
+
const from = strip?.from ?? at;
|
|
119
|
+
let per = strip?.per ?? 1;
|
|
120
|
+
let cells = strip?.cells ?? [];
|
|
121
|
+
const last = cells.at(-1);
|
|
122
|
+
if (last && Object.values(last).reduce((sum, n) => sum + n, 0) < per)
|
|
123
|
+
return { per, cells: [...cells.slice(0, -1), { ...last, [key]: (last[key] ?? 0) + 1 }], from };
|
|
124
|
+
if (cells.length >= STRIP_CELLS) {
|
|
125
|
+
cells = mergePairs(cells);
|
|
126
|
+
per *= 2;
|
|
127
|
+
}
|
|
128
|
+
return { per, cells: [...cells, { [key]: 1 }], from };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Each pair of cells as one, its counts added; an odd last cell stays as it is.
|
|
132
|
+
export function mergePairs(cells) {
|
|
133
|
+
const merged = [];
|
|
134
|
+
for (let i = 0; i < cells.length; i += 2) {
|
|
135
|
+
const cell = { ...cells[i] };
|
|
136
|
+
for (const [key, n] of Object.entries(cells[i + 1] ?? {})) cell[key] = (cell[key] ?? 0) + n;
|
|
137
|
+
merged.push(cell);
|
|
138
|
+
}
|
|
139
|
+
return merged;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// The view patch for a main reply's usage that arrived `at` (ms). `tier` is the routed tier that served it, else null.
|
|
143
|
+
export function responseMetrics(view, response, tier, at = null) {
|
|
104
144
|
const usage = response.usage;
|
|
105
145
|
const counters = usage ? [usage.input_tokens, usage.cache_read_input_tokens, usage.cache_creation_input_tokens] : [];
|
|
106
146
|
const inputTokens =
|
|
@@ -111,13 +151,12 @@ export function responseMetrics(view, response, tier, activity = null, route = n
|
|
|
111
151
|
cacheWrite: usage?.cache_creation_input_tokens ?? null,
|
|
112
152
|
inputTokens,
|
|
113
153
|
outputTokens: usage?.output_tokens ?? null,
|
|
114
|
-
// Appended together so the
|
|
154
|
+
// Appended together so the input trend can color each reading by its tier.
|
|
115
155
|
...(Number.isFinite(inputTokens)
|
|
116
156
|
? {
|
|
117
157
|
history: [...(view?.history ?? []), inputTokens].slice(-HISTORY),
|
|
118
158
|
tiers: [...(view?.tiers ?? []), tier ?? null].slice(-HISTORY),
|
|
119
|
-
|
|
120
|
-
routes: [...(view?.routes ?? []), route ?? null].slice(-HISTORY),
|
|
159
|
+
strip: addToStrip(view?.strip, tier, at),
|
|
121
160
|
}
|
|
122
161
|
: {}),
|
|
123
162
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Native Claude Code Mod: model and effort routing for the main conversation, advised by Jev, Clef, Clef Flash, Clef Omni, OpenAI or Ollama.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|
package/types/index.d.ts
CHANGED
|
@@ -196,10 +196,17 @@ declare module 'claude-code' {
|
|
|
196
196
|
activityProbabilities?: Partial<Record<RouterActivityAnswer, number>> | null;
|
|
197
197
|
history?: number[];
|
|
198
198
|
tiers?: (RouterTier | null)[];
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
routes
|
|
199
|
+
// Every reply since Claude Code started the session by tier: each cell counts up to `per` replies, `none` for one
|
|
200
|
+
// routing did not serve; `from` is when the first one arrived (ms).
|
|
201
|
+
strip?: { per: number; cells: Partial<Record<RouterTier | 'none', number>>[]; from?: number | null } | null;
|
|
202
|
+
// The last route switch, at turn start or inside a turn: when, the routes it moved between with their tiers, and
|
|
203
|
+
// the activity the new route runs for.
|
|
204
|
+
lastSwitch?: {
|
|
205
|
+
at: number;
|
|
206
|
+
from: { tier: RouterTier | null; model: string; effort: string | null };
|
|
207
|
+
to: { tier: RouterTier | null; model: string; effort: string | null };
|
|
208
|
+
activity: RouterActivity | null;
|
|
209
|
+
} | null;
|
|
203
210
|
activityStats?: RouterActivitySession | null;
|
|
204
211
|
// The counts kept across sessions as last read or written.
|
|
205
212
|
activityStore?: RouterActivityStore | null;
|