@alexeiled/claude-router 1.13.0 → 1.14.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/lib/band.mjs CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  classifierStatus,
6
6
  classifierWarns,
7
7
  differenceShare,
8
+ modelColor,
8
9
  modelName,
9
10
  NOT_A_TIER_REASON,
10
11
  percentPair,
@@ -20,6 +21,7 @@ import {
20
21
  } from './display.mjs';
21
22
  import { isSameModel } from './route.mjs';
22
23
  import { emptyTotals, modelSpec, readout } from './savings.mjs';
24
+ import { PASS_WHY } from './subagents.mjs';
23
25
 
24
26
  const BARS = '▂▄▆█';
25
27
  const SEPARATOR = ' · ';
@@ -265,19 +267,43 @@ function hoverSegments(view, actions, routing) {
265
267
  ].filter(Boolean);
266
268
  }
267
269
 
268
- export function renderBand({ Box, Text, Button }, config, view, usage, { columns, agentId }, actions) {
270
+ // A subagent's model and who chose it, as the Usage tab's squares show it: filled when the router moved it off
271
+ // Claude Code's pick. Claude Code's model goes first in a narrow band.
272
+ function agentParts(agent, columns) {
273
+ const color = modelColor(agent.routedModel);
274
+ const moved = !agent.pass && agent.move;
275
+ const name = part(`${moved ? '■' : '□'} ${modelName(agent.routedModel)}`, color ? { color } : {});
276
+ const why = agent.pass
277
+ ? `Claude Code’s pick: ${PASS_WHY[agent.pass]}`
278
+ : moved
279
+ ? `moved ${agent.move === 'moved' ? '' : `${agent.move} `}by the router`
280
+ : agent.choice === 'core'
281
+ ? `Claude Code’s pick: ${agent.failed ? 'classifier did not answer' : 'the router sent no model'}`
282
+ : 'the router kept Claude Code’s pick';
283
+ const parts = [part('○ Router · ', { dimColor: true }), name, part(` · ${why}`, { dimColor: true })];
284
+ const pick = part(` · Claude Code: ${modelName(agent.coreModel)}`, { dimColor: true });
285
+ const width = parts.reduce((sum, p) => sum + p.text.length, 0) + pick.text.length;
286
+ return moved && agent.coreModel && !(Number.isFinite(columns) && width > columns) ? [...parts, pick] : parts;
287
+ }
288
+
289
+ export function renderBand({ Box, Text, Button }, config, view, usage, { columns, agentId, agent = null }, actions) {
269
290
  const draw = (p) => (p.button ? Button(p.button) : Text({ ...p.style, children: p.text }));
270
291
  const row = (parts) => Box({ children: parts.map(draw) });
271
- // A subagent's model is chosen once, at spawn, and never changes between its steps.
292
+ // A subagent's model is chosen once, at spawn, and never changes between its steps. Without its record (routing
293
+ // off, or the router reloaded since the spawn) only the mode is known.
272
294
  if (agentId)
273
- return row([
274
- part(
275
- config.subagentRouting === 'on'
276
- ? '○ Router · subagent model chosen at spawn'
277
- : '○ Router · subagents keep their own model',
278
- { dimColor: true },
279
- ),
280
- ]);
295
+ return row(
296
+ agent
297
+ ? agentParts(agent, columns)
298
+ : [
299
+ part(
300
+ config.subagentRouting === 'on'
301
+ ? '○ Router · subagent model chosen at spawn'
302
+ : '○ Router · subagents keep their own model',
303
+ { dimColor: true },
304
+ ),
305
+ ],
306
+ );
281
307
  const kept = fitSegments(bandSegments(config, view, usage, actions), Math.max(0, columns - ROUTER_BUTTON));
282
308
  const line = kept.flatMap((s, i) => (i ? [part(SEPARATOR, { dimColor: true }), ...s.parts] : s.parts));
283
309
  line.push(part(' '), button({ key: 'details', label: 'Router', plain: true, onPress: actions.open }));
package/lib/display.mjs CHANGED
@@ -16,6 +16,10 @@ import { allTime } from './usage.mjs';
16
16
 
17
17
  // Cost order, cheapest first, so the colors read as a scale. Hex values: every surface draws them.
18
18
  export const TIER_COLOR = { micro: '#5fd7af', low: '#5f9fe0', medium: '#d7af5f', high: '#e0708a' };
19
+ // A subagent's square by the model family it ran on, apart from the tier colors so a model never reads as a tier.
20
+ const MODEL_COLOR = { haiku: '#c3e88d', sonnet: '#f78c6c', opus: '#c792ea', fable: '#89ddff' };
21
+ export const modelColor = (id) =>
22
+ Object.entries(MODEL_COLOR).find(([family]) => String(id ?? '').includes(family))?.[1] ?? null;
19
23
 
20
24
  // Why routing starts off: the session's model is no tier's model. Set at session start, read by the band.
21
25
  export const NOT_A_TIER_REASON = 'not a routing tier';
package/lib/panel.mjs CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  GATEWAY_SETTINGS,
26
26
  missingCredentials,
27
27
  missingText,
28
+ modelColor,
28
29
  modelName,
29
30
  percent,
30
31
  percentPair,
@@ -43,7 +44,14 @@ import {
43
44
  } from './display.mjs';
44
45
  import { cellForModel, isSameModel } from './route.mjs';
45
46
  import { modelSpec, readout } from './savings.mjs';
46
- import { PASS_REASONS, readSubagentStore } from './subagents.mjs';
47
+ import {
48
+ modelTotals,
49
+ PASS_LABEL,
50
+ PASS_REASONS,
51
+ PASS_WHY,
52
+ readSubagentStore,
53
+ summarizeSubagents,
54
+ } from './subagents.mjs';
47
55
  import {
48
56
  allTime,
49
57
  breakdown,
@@ -323,6 +331,7 @@ function nowTab(ui, config, view, usage, actions, _modelOptions, columns, now) {
323
331
  const ownToday = summarize(readUsage(view.usageSession), periodRange('today', now));
324
332
  if (today.replies > ownToday.replies) out.push(ui.text(' '), ...todayLines(ui, today, actions, columns));
325
333
  out.push(
334
+ ...sessionAgentLines(ui, view, actions, columns),
326
335
  ...worthLines(ui, today, actions, columns),
327
336
  ui.text(' '),
328
337
  ui.gauge('Context ', metrics.contextBar, contextSuffix(metrics)),
@@ -1233,45 +1242,298 @@ function yourTier(config, view) {
1233
1242
  const pricedText = (text, counts) =>
1234
1243
  counts.pricedRequests < counts.requests ? `${text} (${counts.requests - counts.pricedRequests} unpriced)` : text;
1235
1244
 
1236
- // Subagent routing across sessions since the last reset. Per routed type: agents, how many the decision moved off
1237
- // core's model, requests per agent and respawns (the retry proxies), and core's cost against the routed one at list
1238
- // prices, with core's model estimated. Then the spawns that passed through, by reason, priced on the model they ran on.
1239
- function subagentUsage(ui, config, view, columns) {
1245
+ // "Oct 7 – Oct 13" for a period's span, or "since Oct 10", its `first` day, for one without a range; null without one.
1246
+ function spanText(period, now, first) {
1247
+ const { from, to } = periodRange(period, now);
1248
+ if (period === 'today') return `today, ${dayLabel(to)}`;
1249
+ if (from) return `${dayLabel(from)} – ${dayLabel(to)}`;
1250
+ return first ? `since ${dayLabel(first)}` : null;
1251
+ }
1252
+
1253
+ // The subagent rows: the open mark, the type, its squares, agents, cost, and against Claude Code's pick with its arrow.
1254
+ const AGENT_TYPE = 19;
1255
+ const AGENT_SQUARES = 12;
1256
+ const AGENT_ROW = 4 + AGENT_TYPE + AGENT_SQUARES + 3 + 9 + 11;
1257
+ // The summary strip's squares at most: past this each model gets its share of them, not one per agent.
1258
+ const AGENT_STRIP = 25;
1259
+ // The models in the order their squares go, by family; any other after them by name.
1260
+ const FAMILIES = ['haiku', 'sonnet', 'opus', 'fable'];
1261
+ const clipped = (text, width) => (text.length < width ? text : `${text.slice(0, width - 2)}…`);
1262
+ const familyRank = (id) => {
1263
+ const rank = FAMILIES.findIndex((family) => id.includes(family));
1264
+ return rank < 0 ? FAMILIES.length : rank;
1265
+ };
1266
+ const byFamily = (a, b) => familyRank(a[0]) - familyRank(b[0]) || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
1267
+ const colored = (ui, id, text) => {
1268
+ const color = modelColor(id);
1269
+ return ui.text(text, color ? { color } : {});
1270
+ };
1271
+
1272
+ // Each model's agents in a period and how many the router moved, across the routed types and the pass-throughs.
1273
+ function agentsByModel(s) {
1274
+ const models = new Map();
1275
+ for (const kind of ['routed', 'passed'])
1276
+ for (const counts of Object.values(s[kind]))
1277
+ for (const [id, m] of Object.entries(counts.models)) {
1278
+ const sum = models.get(id) ?? { agents: 0, moved: 0 };
1279
+ models.set(id, { agents: sum.agents + m.agents, moved: sum.moved + (m.moved ?? 0) });
1280
+ }
1281
+ return [...models].filter(([, m]) => m.agents > 0).sort(byFamily);
1282
+ }
1283
+
1284
+ // Squares for `models` ([id, { agents, moved }]), colored by model, filled for the agents the router moved. `scale`:
1285
+ // one per agent up to `max`, then each model's share of `max`, at least one. Else one per agent up to `max`, and
1286
+ // `rest` counts the agents past them.
1287
+ function squares(ui, models, max, scale) {
1288
+ const total = models.reduce((n, [, m]) => n + m.agents, 0);
1289
+ const shown = (n) => (!scale || total <= max || !n ? n : Math.max(1, Math.round((n / total) * max)));
1290
+ const parts = [];
1291
+ let left = max;
1292
+ for (const [id, m] of models) {
1293
+ const n = Math.min(shown(m.agents), left);
1294
+ const filled = Math.min(n, shown(m.moved));
1295
+ if (filled) parts.push(colored(ui, id, '■'.repeat(filled)));
1296
+ if (n > filled) parts.push(colored(ui, id, '□'.repeat(n - filled)));
1297
+ left -= n;
1298
+ }
1299
+ return { parts, width: max - left, rest: scale ? 0 : total - (max - left) };
1300
+ }
1301
+
1302
+ // "Routing saved $0.21 (5%) on 7 routed agents": the routed agents' cost against Claude Code's picks.
1303
+ function agentVerdict(ui, routed) {
1304
+ const agents = routed.reduce((n, [, c]) => n + c.agents, 0);
1305
+ const totals = routed.map(([, c]) => modelTotals(c));
1306
+ const cost = totals.reduce((n, t) => n + t.usd, 0);
1307
+ const core = totals.reduce((n, t) => n + t.coreUsd, 0);
1308
+ const counts = {
1309
+ requests: routed.reduce((n, [, c]) => n + c.requests, 0),
1310
+ pricedRequests: routed.reduce((n, [, c]) => n + c.pricedRequests, 0),
1311
+ };
1312
+ if (!counts.pricedRequests) return ui.dim(` ${plural(agents, 'routed agent')}, not priced`);
1313
+ const difference = cents(cost - core);
1314
+ const on = pricedText(` on ${plural(agents, 'routed agent')}`, counts);
1315
+ if (!difference) return ui.line(' Routing cost the same as Claude Code’s picks', ui.dim(on));
1316
+ return ui.line(
1317
+ ` Routing ${difference < 0 ? 'saved' : 'cost'} `,
1318
+ ui.text(usd(difference), { color: savingsColor(difference) }),
1319
+ difference < 0 ? '' : ' more',
1320
+ core > 0 ? ` (${percent(Math.abs(difference) / core)})` : '',
1321
+ ui.dim(on),
1322
+ );
1323
+ }
1324
+
1325
+ // The strip of every agent by model, what the router moved, and how routing paid off.
1326
+ function agentSummary(ui, s, columns) {
1327
+ const models = agentsByModel(s);
1328
+ const total = models.reduce((n, [, m]) => n + m.agents, 0);
1329
+ const moved = models.reduce((n, [, m]) => n + m.moved, 0);
1330
+ const strip = squares(ui, models, AGENT_STRIP, true);
1331
+ const labels = models.map(([id, m]) => [id, `${modelName(id)} ${m.agents}`]);
1332
+ const names = labels.flatMap(([id, text], i) => [i ? ui.dim(' · ') : null, colored(ui, id, text)]);
1333
+ const namesWidth = labels.reduce((n, [, text], i) => n + (i ? 3 : 0) + text.length, 0);
1334
+ const out =
1335
+ Number.isFinite(columns) && 2 + strip.width + 2 + namesWidth > columns
1336
+ ? [ui.line(' ', ...strip.parts), ui.line(' ', ...names)]
1337
+ : [ui.line(' ', ...strip.parts, ' ', ...names)];
1338
+ out.push(
1339
+ ui.line(
1340
+ ` ${plural(total, 'agent')}`,
1341
+ ui.dim(' · '),
1342
+ `■ ${moved} moved by the router`,
1343
+ ui.dim(' · '),
1344
+ `□ ${total - moved} on Claude Code’s pick`,
1345
+ ),
1346
+ );
1347
+ const routed = Object.entries(s.routed).filter(([, c]) => c.agents > 0);
1348
+ if (routed.length) out.push(agentVerdict(ui, routed));
1349
+ return out;
1350
+ }
1351
+
1352
+ // Agents per day from the period's first day, or the first recorded one, to today, with the busiest day.
1353
+ function agentTrend(ui, s, period, now) {
1354
+ if (period === 'session' || period === 'today' || !s.perDay.length) return [];
1355
+ const counts = new Map(s.perDay);
1356
+ const start = periodRange(period, now).from ?? s.perDay[0][0];
1357
+ const [y, m, d] = start.split('-').map(Number);
1358
+ const days = [];
1359
+ for (let i = 0; ; i += 1) {
1360
+ const key = dayKey(new Date(y, m - 1, d + i).getTime());
1361
+ if (key > dayKey(now)) break;
1362
+ days.push([key, counts.get(key) ?? 0]);
1363
+ }
1364
+ if (days.length < 2) return [];
1365
+ const [peakDay, peak] = days.reduce((top, day) => (day[1] > top[1] ? day : top));
1366
+ // A long All period keeps its last days, as many as the row has room for.
1367
+ const values = days.map(([, n]) => n).slice(-(AGENT_ROW - 30));
1368
+ return [
1369
+ ui.line(' per day ', ui.text(sparkline(values), { bold: true }), ui.dim(` peak ${peak} on ${dayLabel(peakDay)}`)),
1370
+ ];
1371
+ }
1372
+
1373
+ // "+$0.44 ▲" against Claude Code's pick, in the savings colors; a dim dash when it rounds to nothing.
1374
+ const pickDifference = (ui, value) =>
1375
+ value
1376
+ ? ui.text(`${signedUsd(value)} ${value > 0 ? '▲' : '▼'}`.padStart(11), { color: savingsColor(value) })
1377
+ : ui.dim('—'.padStart(9));
1378
+
1379
+ // What a routed model row holds: "2 moved up", or "1 kept, 2 down".
1380
+ function moveText(m) {
1381
+ const kept = m.agents - m.moved;
1382
+ const other = m.moved - m.up - m.down;
1383
+ const parts = [
1384
+ kept ? `${kept} kept` : null,
1385
+ m.up ? `${m.up} up` : null,
1386
+ m.down ? `${m.down} down` : null,
1387
+ other ? `${other} moved` : null,
1388
+ ].filter(Boolean);
1389
+ if (parts.length > 1 || kept) return parts.join(', ');
1390
+ return `${m.moved} moved${m.up ? ' up' : m.down ? ' down' : ''}`;
1391
+ }
1392
+
1393
+ // One row of the subagent table; open, the models it ran on with their cost, and its requests and retry proxies.
1394
+ function agentRow(ui, view, actions, { id, name, counts, routed, why, narrow, columns }) {
1395
+ const open = view.usageOpen === id;
1396
+ const models = Object.entries(counts.models)
1397
+ .filter(([, m]) => m.agents > 0)
1398
+ .sort(byFamily);
1399
+ const marks = squares(
1400
+ ui,
1401
+ models.map(([model, m]) => [model, { agents: m.agents, moved: m.moved ?? 0 }]),
1402
+ AGENT_SQUARES - 3,
1403
+ false,
1404
+ );
1405
+ const t = modelTotals(counts);
1406
+ // A row none of whose requests had a price says so rather than $0.00.
1407
+ const priced = counts.pricedRequests > 0;
1408
+ const costCell = (value) => (priced ? usd(value).padStart(9) : ui.dim('no price'.padStart(9)));
1409
+ const out = [
1410
+ ui.line(
1411
+ ' ',
1412
+ ui.Button({
1413
+ key: `row-${id}`,
1414
+ label: open ? '▾' : '▸',
1415
+ plain: true,
1416
+ onPress: () => actions.usageOpen(open ? null : id),
1417
+ }),
1418
+ ' ',
1419
+ ui.cell(AGENT_TYPE, clipped(name, AGENT_TYPE)),
1420
+ ui.cell(AGENT_SQUARES, ui.line(...marks.parts, marks.rest ? ui.dim(`+${marks.rest}`) : null)),
1421
+ String(counts.agents).padStart(3),
1422
+ narrow ? null : costCell(t.usd),
1423
+ routed && priced ? pickDifference(ui, cents(t.usd - t.coreUsd)) : null,
1424
+ !routed && why && !narrow ? ui.dim(` ${why}`) : null,
1425
+ ),
1426
+ ];
1427
+ if (!open) return out;
1428
+ for (const [model, m] of models)
1429
+ out.push(
1430
+ ui.line(
1431
+ ' ',
1432
+ ui.cell(17, colored(ui, model, `${m.moved ? '■' : '□'} ${modelName(model)}`)),
1433
+ ui.cell(15, ui.dim(routed ? moveText(m) : plural(m.agents, 'agent'))),
1434
+ narrow ? null : costCell(m.usd),
1435
+ routed && priced ? pickDifference(ui, cents(m.usd - m.coreUsd)) : null,
1436
+ ),
1437
+ );
1438
+ const notes = [
1439
+ `${(counts.requests / counts.agents).toFixed(1)} requests per agent`,
1440
+ routed ? `${counts.respawns || 'none'} respawned within 10 min` : null,
1441
+ counts.failures ? plural(counts.failures, 'classifier failure') : null,
1442
+ counts.pricedRequests < counts.requests ? `${counts.requests - counts.pricedRequests} requests not priced` : null,
1443
+ ].filter(Boolean);
1444
+ out.push(...dimLines(ui, ` ${notes.join(' · ')}`, columns));
1445
+ return out;
1446
+ }
1447
+
1448
+ // Subagents in the chosen period: this session's record, or every session's in every project (one $.store per
1449
+ // plugin install). A strip of every agent by the model it ran on, filled where the router moved it off Claude Code's
1450
+ // pick, and the routed agents' cost against those picks. Then the routed types and the pass-throughs, each with its
1451
+ // squares, agents and cost, opening to its models; a pass-through says why Claude Code picked.
1452
+ function subagentUsage(ui, config, view, actions, period, now, columns) {
1240
1453
  const mode = config.subagentRouting;
1241
- const store = readSubagentStore(view.subagentStore);
1242
- const out = [ui.line(ui.head('SUBAGENTS · across sessions'), ui.dim(` subagent routing ${mode}`))];
1243
- const rows = Object.entries(store.routed.on).filter(([, counts]) => counts.agents > 0);
1244
- const passed = PASS_REASONS.filter((reason) => store.passed[reason]?.agents > 0);
1245
- if (!rows.length && !passed.length)
1454
+ const record = readSubagentStore(period === 'session' ? view.subagentSession : view.subagentStore);
1455
+ const s = summarizeSubagents(record, periodRange(period, now));
1456
+ const first = Number.isFinite(record.since) ? dayKey(record.since) : null;
1457
+ const scope =
1458
+ period === 'session' ? 'this session' : `all projects · ${spanText(period, now, first) ?? 'nothing yet'}`;
1459
+ const out = [ui.line(ui.head('SUBAGENTS'), ui.dim(` · ${scope} subagent routing ${mode}`))];
1460
+ const routed = Object.entries(s.routed)
1461
+ .filter(([, c]) => c.agents > 0)
1462
+ .sort((a, b) => b[1].agents - a[1].agents || (a[0] < b[0] ? -1 : 1));
1463
+ const passed = PASS_REASONS.filter((reason) => s.passed[reason]?.agents > 0).sort(
1464
+ (a, b) => s.passed[b].agents - s.passed[a].agents,
1465
+ );
1466
+ const undated = s.undated
1467
+ ? [
1468
+ ui.dim(
1469
+ ` + ${plural(s.undated.agents, 'agent')} from before 1.14.0, not split by model · ${usd(s.undated.usd)}`,
1470
+ ),
1471
+ ]
1472
+ : [];
1473
+ if (!routed.length && !passed.length) {
1474
+ const older = !s.undated && periodRange(period, now).from !== null && readSubagentStore(view.subagentStore).undated;
1246
1475
  return [
1247
1476
  ...out,
1248
- ui.dim(mode === 'off' ? ' Not recorded. Set subagentRouting to on in router.json.' : ' no subagents yet'),
1477
+ ui.dim(
1478
+ mode === 'off'
1479
+ ? ' Not recorded: subagentRouting is off in router.json.'
1480
+ : ` No subagents ${PERIOD_PHRASE[period]}.`,
1481
+ ),
1482
+ ...undated,
1483
+ ...(older ? [ui.dim(' Agents from before 1.14.0 have no date: All shows them.')] : []),
1249
1484
  ];
1250
- if (rows.length) {
1251
- out.push(ui.dim(' core’s model (est.) → routed'));
1252
- for (const [type, c] of rows.sort((a, b) => b[1].agents - a[1].agents)) {
1253
- const cost = pricedText(`${usd(c.coreUsd)} → ${usd(c.routedUsd)}`, c);
1254
- out.push(
1255
- ui.text(
1256
- ` ${type} ${c.agents} agent${c.agents === 1 ? '' : 's'} · ${c.differs} moved · ${(c.requests / c.agents).toFixed(1)} req/agent · ${c.respawns} respawns · ${cost}`,
1257
- ),
1258
- );
1259
- const choices = Object.entries(c.choices).map(([choice, n]) => `${choice} ${n}`);
1260
- if (c.failures) choices.push(`${c.failures} classifier failures`);
1261
- out.push(...dimLines(ui, ` ${choices.join(' · ')}`, columns));
1262
- }
1263
1485
  }
1264
- if (passed.length) {
1265
- const sum = (field) => passed.reduce((total, reason) => total + store.passed[reason][field], 0);
1266
- const total = { requests: sum('requests'), pricedRequests: sum('pricedRequests') };
1486
+ const narrow = Number.isFinite(columns) && columns < AGENT_ROW;
1487
+ out.push(...agentSummary(ui, s, columns), ...agentTrend(ui, s, period, now), ...undated);
1488
+ const rowOf = (fields) => agentRow(ui, view, actions, { narrow, columns, ...fields });
1489
+ if (routed.length) {
1267
1490
  out.push(
1268
- ui.text(` Not routed ${passed.map((reason) => `${reason} ${store.passed[reason].agents}`).join(' · ')}`),
1269
- ui.dim(` ${pricedText(`${usd(sum('usd'))} on the model they ran on`, total)}`),
1491
+ ui.text(' '),
1492
+ ui.line(ui.text(' ROUTED', { bold: true }), ui.dim(' · the router picked the model at spawn')),
1493
+ ui.dim(
1494
+ ` ${'type'.padEnd(AGENT_TYPE)}${'agents'.padEnd(AGENT_SQUARES + 3)}${narrow ? '' : 'cost'.padStart(9)}${'vs CC'.padStart(9)}`,
1495
+ ),
1270
1496
  );
1497
+ for (const [type, counts] of routed)
1498
+ out.push(...rowOf({ id: `subagent:${type}`, name: type, counts, routed: true }));
1499
+ }
1500
+ if (passed.length) {
1501
+ out.push(ui.text(' '), ui.line(ui.text(' NOT ROUTED', { bold: true }), ui.dim(' · Claude Code picked the model')));
1502
+ for (const reason of passed)
1503
+ out.push(
1504
+ ...rowOf({
1505
+ id: `subagent-pass:${reason}`,
1506
+ name: PASS_LABEL[reason],
1507
+ counts: s.passed[reason],
1508
+ routed: false,
1509
+ why: PASS_WHY[reason],
1510
+ }),
1511
+ );
1271
1512
  }
1513
+ out.push(
1514
+ ui.text(' '),
1515
+ ...dimLines(ui, ' ■ moved by the router · □ Claude Code’s pick · color: the model', columns),
1516
+ ...(routed.length ? dimLines(ui, ' vs CC: the same tokens on Claude Code’s pick, at list prices', columns) : []),
1517
+ );
1272
1518
  return out;
1273
1519
  }
1274
1520
 
1521
+ // This session's subagents on the Now tab: how many run now, the strip, and how routing paid off. Nothing without any.
1522
+ function sessionAgentLines(ui, view, actions, columns) {
1523
+ const s = summarizeSubagents(readSubagentStore(view.subagentSession), { from: null, to: null });
1524
+ const running = view.subagentsRunning ?? 0;
1525
+ const any = [...Object.values(s.routed), ...Object.values(s.passed)].some((c) => c.agents > 0);
1526
+ if (!any && !running) return [];
1527
+ const head = ui.line(
1528
+ ui.head('SUBAGENTS'),
1529
+ ui.dim(' · this session'),
1530
+ running ? ui.text(` · ● ${running} running`, { color: 'yellow' }) : null,
1531
+ ' ',
1532
+ ui.Button({ key: 'usage-agents', label: 'Usage', onPress: () => actions.usageFor('session') }),
1533
+ );
1534
+ return [ui.text(' '), head, ...(any ? agentSummary(ui, s, columns) : [])];
1535
+ }
1536
+
1275
1537
  const PERIOD_LABEL = { session: 'Session', today: 'Today', '7d': '7d', '30d': '30d', month: 'Month', all: 'All' };
1276
1538
  // "No routed replies …" for each period.
1277
1539
  const PERIOD_PHRASE = {
@@ -1359,17 +1621,8 @@ function scopeLine(ui, config, view, period, summary, now) {
1359
1621
  tier ? ui.tier(tier, yourModel(view)) : ui.text(yourModel(view)),
1360
1622
  );
1361
1623
  }
1362
- const { from, to } = periodRange(period, now);
1363
- const first = summary.days[0]?.[0];
1364
- const span =
1365
- period === 'today'
1366
- ? `today, ${dayLabel(to)}`
1367
- : from
1368
- ? `${dayLabel(from)} – ${dayLabel(to)}`
1369
- : first
1370
- ? `since ${dayLabel(first)}`
1371
- : 'no dated replies yet';
1372
- return ui.dim(`all sessions · ${span} · each session vs its own model`);
1624
+ const span = spanText(period, now, summary.days[0]?.[0]) ?? 'no dated replies yet';
1625
+ return ui.dim(`all projects · ${span} · each session vs its own model`);
1373
1626
  }
1374
1627
 
1375
1628
  // The models a session's replies were priced against, when they are not the one `/model` selects now: after a
@@ -1701,7 +1954,7 @@ function deleteLine(ui, view, actions) {
1701
1954
  }
1702
1955
 
1703
1956
  // Answer first for the chosen period: routing against your model as a ledger that adds up, the tokens, the cost by
1704
- // activity, model or tier, the trend or What if, and what is worth a look. Subagents follow, across sessions.
1957
+ // activity, model or tier, the trend or What if, and what is worth a look. Subagents follow, for the same period.
1705
1958
  function usageTab(ui, config, view, _usage, actions, _modelOptions, columns, now) {
1706
1959
  const period = PERIODS.includes(view.usagePeriod) ? view.usagePeriod : 'session';
1707
1960
  const record = readUsage(period === 'session' ? view.usageSession : view.usageStore);
@@ -1732,7 +1985,12 @@ function usageTab(ui, config, view, _usage, actions, _modelOptions, columns, now
1732
1985
  ...insightLines(ui, summary, actions, columns),
1733
1986
  );
1734
1987
  }
1735
- out.push(ui.text(' '), ...subagentUsage(ui, config, view, columns), ui.text(' '), ...footer(ui, columns));
1988
+ out.push(
1989
+ ui.text(' '),
1990
+ ...subagentUsage(ui, config, view, actions, period, now, columns),
1991
+ ui.text(' '),
1992
+ ...footer(ui, columns),
1993
+ );
1736
1994
  out.push(ui.text(' '), deleteLine(ui, view, actions));
1737
1995
  return out;
1738
1996
  }