@alexeiled/claude-router 1.9.0 → 1.10.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/panel.mjs CHANGED
@@ -15,13 +15,12 @@ import {
15
15
  } from './config.mjs';
16
16
  import { effortSharesCache, routeEffort } from './cost.mjs';
17
17
  import {
18
- ACTIVITY_LETTER,
19
18
  activityReading,
20
19
  activityRouteText,
20
+ activityVerb,
21
21
  bar,
22
22
  classifierLabel,
23
23
  classifierStatus,
24
- credentialsNeeded,
25
24
  differenceShare,
26
25
  formatTokens,
27
26
  GATEWAY_CLEANUP,
@@ -31,7 +30,7 @@ import {
31
30
  modelName,
32
31
  percent,
33
32
  percentPair,
34
- probeText,
33
+ probeOf,
35
34
  routeLabel,
36
35
  routeName,
37
36
  savingsColor,
@@ -59,12 +58,15 @@ import {
59
58
  } from './savings.mjs';
60
59
  import { PASS_REASONS, readSubagentStore } from './subagents.mjs';
61
60
 
61
+ // Routes and Policy edit one draft and save together; Classifier saves each pick at once.
62
62
  const TABS = [
63
63
  ['now', '1', 'Now'],
64
- ['routing', '2', 'Routing'],
65
- ['classifier', '3', 'Classifier'],
66
- ['usage', '4', 'Usage'],
64
+ ['routes', '2', 'Routes'],
65
+ ['policy', '3', 'Policy'],
66
+ ['classifier', '4', 'Classifier'],
67
+ ['usage', '5', 'Usage'],
67
68
  ];
69
+ const DRAFT_TABS = ['routes', 'policy'];
68
70
  const TUNING_CHOICES = {
69
71
  timeoutMs: [500, 1000, 1500, 3000, 5000],
70
72
  downgradeVotes: [1, 2, 3],
@@ -73,12 +75,18 @@ const TUNING_CHOICES = {
73
75
  activityMass: [0.5, 0.6, 0.7, 0.8],
74
76
  };
75
77
  const LADDER = [...TIERS].reverse();
78
+ // The effort option that sends no effort of its own: the request keeps the one Claude Code sends.
76
79
  const SESSION_EFFORT = 'session';
80
+ const INHERIT = 'inherit';
81
+ // The Routes grid's row of the tiers' own routes; every other row is an activity.
82
+ const TIER_ROW = 'tier';
83
+ // Activity verbs are orange italic, as on the band.
84
+ const ACTIVITY_STYLE = { color: '#d7875f', italic: true };
77
85
 
78
86
  const ACTIVITY_MODE_HINT = {
79
- off: 'the activity is not asked; base routes run',
80
- shadow: 'shows what on would do; base routes run',
81
- on: 'an override runs when the activity has one',
87
+ off: 'not asked; every turn runs its tier’s model',
88
+ shadow: 'asked and shown; every turn still runs its tier’s model',
89
+ on: 'an activity can change its tier’s model',
82
90
  };
83
91
  // What `subagentRouting` does, under the router.json path: it is set in the file, not in the pane.
84
92
  const SUBAGENT_LINE = {
@@ -86,9 +94,10 @@ const SUBAGENT_LINE = {
86
94
  shadow: 'Subagents: shadow. A model is chosen at spawn and recorded, not applied.',
87
95
  on: 'Subagents: on. Agents that pin no model get one at spawn, kept for every step.',
88
96
  };
89
- const EFFORT_SHORT = { low: 'low', medium: 'med', high: 'high', xhigh: 'xh', max: 'max' };
97
+ const EFFORT_SHORT = { low: 'low', medium: 'med', high: 'high', xhigh: 'xh', max: 'max', [INHERIT]: 'inh' };
90
98
 
91
- // The route draft the Routing tab edits: the saved routes, activity overrides and mode until the person changes one.
99
+ // The route draft the Routes and Policy tabs edit: the saved routes, activity overrides and mode until the person
100
+ // changes one.
92
101
  export function routeDraftOf(config, view) {
93
102
  if (view.routeDraft) return view.routeDraft;
94
103
  const base = structuredClone({
@@ -103,7 +112,10 @@ export function routeDraftOf(config, view) {
103
112
  const dollars = (value) => (Number.isFinite(value) ? `$${value.toFixed(3)}` : 'not reported');
104
113
  const difference = (value) => `${value < 0 ? '−' : '+'}$${Math.abs(value).toFixed(3)}`;
105
114
  const hostOf = (endpoint) => endpoint.replace(/^https?:\/\//, '').split('/')[0];
115
+ const isLocal = (endpoint) => /^(127\.0\.0\.1|localhost)(:|$)/.test(hostOf(endpoint));
106
116
  const windowSize = (tokens) => (tokens >= 1e6 ? `${tokens / 1e6}M` : `${Math.round(tokens / 1e3)}K`);
117
+ const share = (value) => (value === null ? '—' : `${value}%`);
118
+ const plural = (n, word, many = `${word}s`) => `${n} ${n === 1 ? word : many}`;
107
119
  const contextSuffix = (metrics) =>
108
120
  Number.isFinite(metrics.nextContext)
109
121
  ? `~${formatTokens(metrics.nextContext)} / ${formatTokens(metrics.window)}`
@@ -119,6 +131,7 @@ function kit({ Box, Text, Button, Select }) {
119
131
  dim: (children) => text(children, { dimColor: true }),
120
132
  head: (children) => text(children, { bold: true, color: 'cyan' }),
121
133
  tier: (tier, children = tier) => text(children, { bold: true, color: TIER_COLOR[tier] }),
134
+ activity: (activity) => text(activityVerb(activity), ACTIVITY_STYLE),
122
135
  // One row of mixed parts; strings become plain Text, nulls are dropped.
123
136
  line: (...parts) =>
124
137
  Box({
@@ -126,8 +139,8 @@ function kit({ Box, Text, Button, Select }) {
126
139
  .filter((part) => part !== null && part !== '')
127
140
  .map((p) => (typeof p === 'string' ? text(p) : p)),
128
141
  }),
129
- // A fixed-width column, so controls of different widths still line up.
130
- cell: (width, part) => Box({ width, children: [typeof part === 'string' ? text(part) : part] }),
142
+ // A fixed-width column, so controls of different widths still line up; it never shrinks in a narrow pane.
143
+ cell: (width, part) => Box({ width, flexShrink: 0, children: [typeof part === 'string' ? text(part) : part] }),
131
144
  gauge: (name, value, suffix) =>
132
145
  text(`${name}${value.text}${value.percent === null ? '' : ` ${String(value.percent).padStart(3)}%`} ${suffix}`, {
133
146
  color: value.color,
@@ -145,21 +158,21 @@ export function renderPanel(
145
158
  ) {
146
159
  const ui = kit(elements);
147
160
  const tab = TABS.some(([id]) => id === view.tab) ? view.tab : 'now';
148
- const body = { now: nowTab, routing: routingTab, classifier: classifierTab, usage: usageTab }[tab];
161
+ const body = { now: nowTab, routes: routesTab, policy: policyTab, classifier: classifierTab, usage: usageTab }[tab];
149
162
  return ui.Box({
150
163
  flexDirection: 'column',
151
164
  children: [
152
165
  ...header(ui, config, view, tab, actions),
153
166
  ...body(ui, config, view, usage, actions, modelOptions, columns),
154
167
  ...(view.help ? helpLines(ui) : []),
155
- ...statusBar(ui, config, view, actions),
168
+ ...statusBar(ui, config, view, tab, actions),
156
169
  ui.Button({ key: 'close', label: 'Close', hotkey: 'q', role: 'dismiss', onPress: actions.close }),
157
170
  ],
158
171
  });
159
172
  }
160
173
 
161
- // Routing's state and its one mode control. While routing is unavailable, on and off would change nothing, so the
162
- // header says why instead of offering them.
174
+ // Routing's state, its one mode control and the classifier's state on one line. While routing is unavailable, on and
175
+ // off would change nothing, so the line says why instead of offering them.
163
176
  function routingState(ui, config, view, actions) {
164
177
  if (view.phase === 'unavailable')
165
178
  return [
@@ -190,22 +203,29 @@ function routingState(ui, config, view, actions) {
190
203
  option('auto', 'on', 'o'),
191
204
  ' ',
192
205
  option('manual', 'off', 'f'),
193
- ui.dim(' off keeps the /model choice'),
206
+ ' ',
207
+ error
208
+ ? ui.text(classifierStatus(config, error), { color: 'yellow' })
209
+ : ui.text(`${label} ready${Number.isFinite(view.adviceMs) ? ` · ${view.adviceMs} ms` : ''}`, {
210
+ color: 'green',
211
+ }),
194
212
  ),
195
- error
196
- ? ui.text(classifierStatus(config, error), { color: 'yellow' })
197
- : ui.text(`${label} ready${Number.isFinite(view.adviceMs) ? ` · ${view.adviceMs} ms` : ''}`, { color: 'green' }),
198
213
  ];
199
214
  }
200
215
 
201
216
  function header(ui, config, view, tab, actions) {
217
+ const changes = routingChanges(config, view);
218
+ const unsaved = {
219
+ routes: changes.tiers.length + changes.cells.length + Number(changes.mode) > 0,
220
+ policy: changes.policy.length + Number(changes.baseline) > 0,
221
+ };
202
222
  return [
203
223
  ...routingState(ui, config, view, actions),
204
224
  ui.line(
205
225
  ...TABS.flatMap(([id, hotkey, label]) => [
206
226
  ui.Button({
207
227
  key: `tab-${id}`,
208
- label: id === 'routing' && routingChanges(config, view).count ? `${label} ●` : label,
228
+ label: unsaved[id] ? `${label} ●` : label,
209
229
  hotkey,
210
230
  variant: tab === id ? 'primary' : 'secondary',
211
231
  onPress: () => actions.tab(id),
@@ -218,6 +238,20 @@ function header(ui, config, view, tab, actions) {
218
238
  ];
219
239
  }
220
240
 
241
+ // "Jev gave stronger tiers 88% (needs 82%) · switch ≈ $0.48": the support for the switch the policy weighed against
242
+ // the bar it set, and the switch cost. Null without a reading.
243
+ function supportText(label, estimate) {
244
+ if (!Number.isFinite(estimate?.threshold)) return null;
245
+ const [direction, mass] = Number.isFinite(estimate.upgradeMass)
246
+ ? ['stronger', estimate.upgradeMass]
247
+ : ['cheaper', estimate.downgradeMass];
248
+ const [needs, gave] = percentPair(estimate.threshold, Number.isFinite(mass) ? mass : estimate.threshold);
249
+ const cost = Number.isFinite(estimate.taxUsd) ? ` · switch ≈ ${usd(estimate.taxUsd)}` : '';
250
+ return `${label} gave ${direction} tiers ${Number.isFinite(mass) ? gave : '—'} (needs ${needs})${cost}`;
251
+ }
252
+
253
+ // What runs next turn and why first; then the classifier's support per tier with pins, the recent replies, and the
254
+ // context and cost readings.
221
255
  function nowTab(ui, config, view, usage, actions) {
222
256
  const metrics = usageMetrics(config, view, usage);
223
257
  const unavailable = view.phase === 'unavailable';
@@ -226,25 +260,41 @@ function nowTab(ui, config, view, usage, actions) {
226
260
  const label = classifierLabel(config);
227
261
  const missing = unavailable ? null : missingCredentials(config, view, config.classifier);
228
262
  const served = view.actualModel && current && !isSameModel(current, view.actualModel);
229
- const reading = config.activityRouting === 'off' ? null : activityReading(view);
230
- const route = activityRouteText(config, view);
263
+ const mode = config.activityRouting;
264
+ const reading = mode === 'off' ? null : activityReading(view);
265
+ // In `on` an override names the tier's own model; in `shadow` the line says what `on` would run.
266
+ const base = view.tier ? resolveRoute(config, view.tier) : null;
267
+ const override =
268
+ mode === 'on' && view.activity && base && !sameRoute(resolveRoute(config, view.tier, view.activity), base);
269
+ const route = mode === 'shadow' ? activityRouteText(config, view) : null;
270
+ const support = auto ? supportText(label, view.estimate) : null;
231
271
  const out = [
232
- ui.line('Now ', view.tier ? ui.tier(view.tier, `▌${view.tier} `) : null, routeLabel(current, view.effort)),
272
+ ui.line(
273
+ 'Next turn ',
274
+ view.tier ? ui.tier(view.tier, `▌${view.tier} `) : null,
275
+ ui.text(routeLabel(current, view.effort), { bold: true }),
276
+ auto ? null : ui.dim(unavailable ? ' Claude’s model' : ' your /model choice, routing off'),
277
+ override ? ui.dim(` override · ${view.tier} runs ${routeName(config, base)}`) : null,
278
+ ),
233
279
  reading
234
280
  ? ui.line(
235
- 'Activity ',
236
- `${reading.choice}${reading.share ? ` ${reading.share}` : ''}`,
237
- reading.others.length ? ui.dim(` ${reading.others.join(' · ')}`) : null,
281
+ 'Activity ',
282
+ // `uncertain` is an answer, not an activity: it applies none.
283
+ ACTIVITIES.includes(reading.choice) ? ui.activity(reading.choice) : ui.dim(reading.choice),
284
+ reading.share ? ` ${reading.share}` : '',
285
+ reading.others.length ? ui.dim(` ${reading.others.map(verbShare).join(' · ')}`) : null,
286
+ ui.dim(` applies at ${percent(config.policy.activityMass)}+`),
238
287
  )
239
288
  : null,
240
- ui.line('Why ', whyText(config, view)),
241
- route ? ui.line('Route ', route) : null,
289
+ ui.line('Why ', whyText(config, view)),
290
+ support ? ui.dim(` ${support}`) : null,
291
+ route ? ui.line('Shadow ', ui.dim(route)) : null,
242
292
  served
243
- ? ui.line(ui.text('Served ', { color: 'yellow' }), `${modelName(view.actualModel)} · native fallback`)
293
+ ? ui.line(ui.text('Served ', { color: 'yellow' }), `${modelName(view.actualModel)} · native fallback`)
244
294
  : null,
245
295
  view.pendingPin
246
296
  ? ui.line(
247
- ui.text('Pinned ', { color: 'yellow' }),
297
+ ui.text('Pinned ', { color: 'yellow' }),
248
298
  'next turn → ',
249
299
  ui.tier(view.pendingPin),
250
300
  ' ',
@@ -258,8 +308,10 @@ function nowTab(ui, config, view, usage, actions) {
258
308
  )
259
309
  : null,
260
310
  ui.text(' '),
261
- ui.head('TIERS · next turn'),
262
- ui.dim(` ${'tier'.padEnd(8)}${'route'.padEnd(22)}${label} support`),
311
+ ui.line(
312
+ ui.head('TIERS'),
313
+ ui.dim(auto ? ` · ${label} support on the last turn · pin = next turn only` : ` · ${label} support`),
314
+ ),
263
315
  ];
264
316
  for (const tier of LADDER) {
265
317
  const support = view.probabilities?.[tier];
@@ -275,87 +327,79 @@ function nowTab(ui, config, view, usage, actions) {
275
327
  ),
276
328
  );
277
329
  }
278
- const estimate = view.estimate;
279
- if (Number.isFinite(estimate?.threshold)) {
280
- const [direction, mass] = Number.isFinite(estimate.upgradeMass)
281
- ? ['up', estimate.upgradeMass]
282
- : ['down', estimate.downgradeMass];
283
- const [bar, gave] = percentPair(estimate.threshold, Number.isFinite(mass) ? mass : estimate.threshold);
284
- out.push(
285
- ui.dim(
286
- ` switch needs ${bar} · ${label} gave ${Number.isFinite(mass) ? gave : '—'} ${direction}` +
287
- `${Number.isFinite(estimate.taxUsd) ? ` · switch cost ≈ ${usd(estimate.taxUsd)}` : ''}`,
288
- ),
289
- );
290
- }
291
- out.push(
292
- ui.dim(
293
- unavailable
294
- ? ' Pins need routing, which is unavailable.'
295
- : auto
296
- ? ' Pins serve the next turn only.'
297
- : ' Pins need routing on. Routing off keeps the /model choice.',
298
- ),
299
- );
330
+ if (!auto)
331
+ out.push(ui.dim(unavailable ? ' Pins need routing, which is unavailable.' : ' Pins need routing on (o above).'));
300
332
  out.push(ui.text(' '), ...replies(ui, view));
301
333
  out.push(
302
334
  ui.text(' '),
303
335
  ui.gauge('Context ', metrics.contextBar, contextSuffix(metrics)),
304
- ui.gauge(
305
- 'Cache ',
306
- metrics.cacheBar,
307
- metrics.cacheBar.percent === null ? 'no reply yet' : 'reused on the last reply',
308
- ),
309
336
  ui.line(
310
- `Cost ${dollars(metrics.cost)} `,
337
+ ui.text('Cache ', { color: metrics.cacheBar.color }),
338
+ metrics.cacheBar.percent === null
339
+ ? ui.dim('no reply yet')
340
+ : ui.text(`${metrics.cacheBar.percent}% reused on the last reply`, { color: metrics.cacheBar.color }),
341
+ ui.dim(' · '),
342
+ `cost ${dollars(metrics.cost)} `,
311
343
  ui.dim('by Claude'),
312
- Number.isFinite(metrics.cacheBenefit) ? ` · cache hits saved ≈ ${usd(metrics.cacheBenefit)}` : '',
313
344
  ),
314
345
  );
315
346
  return out;
316
347
  }
317
348
 
318
- // One cell per reply, colored by the tier that served it; a dot where routing did not choose (routing off, fallback).
319
- // Under it, the reply's activity letter, aligned from the end: a view from before 1.6 has fewer activities.
349
+ const verbShare = (text) => text.replace(/^(\S+)/, (name) => activityVerb(name));
350
+
351
+ // The last replies, one cell each colored by the tier that served it, a dot where routing did not choose; the switch
352
+ // count; the replies per tier, which is also the color key; and the replies per activity.
320
353
  function replies(ui, view) {
321
354
  const tiers = view.tiers ?? [];
322
- if (!tiers.length) return [ui.head('REPLIES'), ui.dim(' no replies yet')];
323
- const activities = view.activities ?? [];
355
+ if (!tiers.length) return [ui.head('LAST REPLIES'), ui.dim(' no replies yet')];
324
356
  const switches = switchCount((view.routes ?? []).slice(-tiers.length));
325
- const letters = tiers.map((_, i) => activities[activities.length - tiers.length + i] ?? null);
357
+ const count = (list, value) => list.filter((item) => item === value).length;
358
+ const notRouted = count(tiers, null);
359
+ // A view from before 1.6 has fewer activities: they align from the newest.
360
+ const activities = (view.activities ?? []).slice(-tiers.length);
361
+ const used = ACTIVITIES.map((activity) => [activity, count(activities, activity)])
362
+ .filter(([, n]) => n > 0)
363
+ .sort((a, b) => b[1] - a[1]);
326
364
  return [
327
- ui.head(`REPLIES · last ${tiers.length}`),
365
+ ui.line(
366
+ ui.head(tiers.length === 1 ? 'LAST REPLY' : `LAST ${tiers.length} REPLIES`),
367
+ ui.dim(` · ${plural(switches, 'model switch', 'model switches')}`),
368
+ ),
369
+ ui.line(' ', ...tiers.map((tier) => (tier ? ui.tier(tier, '█') : ui.dim('·')))),
328
370
  ui.line(
329
371
  ' ',
330
- ...tiers.map((tier) => (tier ? ui.tier(tier, '█') : ui.dim('·'))),
331
- ui.dim(` ${switches} switch${switches === 1 ? '' : 'es'}`),
372
+ ...TIERS.filter((tier) => tiers.includes(tier)).flatMap((tier) => [
373
+ ui.tier(tier, '■ '),
374
+ `${tier} ${count(tiers, tier)} `,
375
+ ]),
376
+ notRouted ? ui.dim(`· not routed ${notRouted}`) : null,
332
377
  ),
333
- ...(letters.some(Boolean)
334
- ? [ui.line(' ', ...letters.map((activity) => (activity ? ui.text(ACTIVITY_LETTER[activity]) : ui.dim('·'))))]
335
- : []),
336
- ui.line(' ', ...TIERS.flatMap((tier) => [ui.tier(tier, '■ '), `${tier} `])),
337
- ...(letters.some(Boolean)
338
- ? [ui.dim(` ${ACTIVITIES.map((activity) => `${ACTIVITY_LETTER[activity]} ${activity}`).join(' ')}`)]
378
+ ...(used.length
379
+ ? [
380
+ ui.line(
381
+ ' ',
382
+ ...used.flatMap(([activity, n], i) => [
383
+ ui.activity(activity),
384
+ ui.dim(` ${n}${i < used.length - 1 ? ' · ' : ''}`),
385
+ ]),
386
+ ),
387
+ ]
339
388
  : []),
340
389
  ];
341
390
  }
342
391
 
343
- // Rows: [key, label, format, hint, router.json field]. Typed as tuples so tsc keeps each position's type.
344
- /** @type {[string, string, (value: number) => string, string, string][]} */
392
+ // Rows: [key, label, format, router.json field]. Typed as tuples so tsc keeps each position's type.
393
+ /** @type {[string, string, (value: number) => string, string][]} */
345
394
  const POLICY_ROWS = [
346
- ['downgradeVotes', 'Votes to go down', String, 'agreeing turns before cheaper', 'policy.downgradeVotes'],
347
- ['horizon', 'Payback horizon', (v) => `${v} turns`, 'a switch repays its cache', 'policy.downgradeHorizonTurns'],
348
- ['cashCapUsd', 'Credits cap', (v) => `$${v.toFixed(2)}`, 'max cold write on credits', 'policy.cashCapUsd'],
349
- [
350
- 'activityMass',
351
- 'Activity threshold',
352
- percent,
353
- 'a weaker reading keeps the running activity or uses the base route',
354
- 'policy.activityMass',
355
- ],
395
+ ['downgradeVotes', 'Votes to go down', String, 'policy.downgradeVotes'],
396
+ ['horizon', 'Payback horizon', (v) => plural(v, 'turn'), 'policy.downgradeHorizonTurns'],
397
+ ['cashCapUsd', 'Credits cap', (v) => `$${v.toFixed(2)}`, 'policy.cashCapUsd'],
398
+ ['activityMass', 'Activity threshold', percent, 'policy.activityMass'],
356
399
  ];
400
+ const POLICY_FORMAT = Object.fromEntries(POLICY_ROWS.map(([key, , format]) => [key, format]));
357
401
 
358
- // What the Routing tab changed and has not saved: tiers, baseline, activity cells and mode against the saved config,
402
+ // What Routes and Policy changed and have not saved: tiers, baseline, activity cells and mode against the saved config,
359
403
  // policy values against the values the draft started from. `cells` lists [activity, tier] pairs.
360
404
  export function routingChanges(config, view) {
361
405
  const raw = routeDraftOf(config, view);
@@ -380,171 +424,112 @@ export function routingChanges(config, view) {
380
424
 
381
425
  const marker = (ui, changed) => ui.cell(2, changed ? ui.text('●', { color: 'yellow' }) : '');
382
426
 
383
- // Routes and policy are edited as one set: the switch-cost lines read the whole ladder, so nothing here is written
384
- // until Save in the status bar.
385
- function routingTab(ui, config, view, _usage, actions, modelOptions) {
386
- const changes = routingChanges(config, view);
387
- const { draft, tuning, tiers, baseline, policy } = changes;
388
- const out = [
389
- ui.line(ui.head('ROUTES'), ui.dim(' · applies next turn · edit, then Save')),
390
- ui.dim(`${'tier'.padEnd(8)}${'model'.padEnd(14)}${'effort'.padEnd(14)}${'$/M in · out'.padEnd(14)}window`),
391
- ];
392
- for (const tier of LADDER) {
393
- const route = draft.routes[tier];
394
- const model = config.models[route.model];
395
- const aliases = modelOptions.includes(route.model) ? modelOptions : [route.model, ...modelOptions];
396
- out.push(
397
- ui.line(
398
- ui.cell(8, ui.tier(tier)),
399
- ui.cell(
400
- 14,
401
- ui.Select
402
- ? ui.Select({
403
- key: `route-model-${tier}`,
404
- value: route.model,
405
- options: aliases.map((alias) => ({ value: alias, label: modelName(config.models[alias].id) })),
406
- onSelect: (alias) => actions.routeModel(tier, alias),
407
- })
408
- : modelName(model.id),
409
- ),
410
- ui.cell(
411
- 12,
412
- !model.efforts.length
413
- ? ui.dim('none')
414
- : ui.Select
415
- ? ui.Select({
416
- key: `route-effort-${tier}`,
417
- value: route.effort ?? SESSION_EFFORT,
418
- options: [SESSION_EFFORT, ...model.efforts].map((effort) => ({ value: effort, label: effort })),
419
- onSelect: (effort) => actions.routeEffort(tier, effort === SESSION_EFFORT ? null : effort),
420
- })
421
- : (route.effort ?? SESSION_EFFORT),
422
- ),
423
- marker(ui, tiers.includes(tier)),
424
- ui.cell(14, `${model.input} · ${model.output ?? '?'}`),
425
- windowSize(model.contextWindow),
426
- ),
427
- );
428
- }
429
- out.push(
430
- ui.line(
431
- ui.cell(
432
- 34,
433
- ui.Select
434
- ? ui.Select({
435
- key: 'baseline',
436
- label: 'Baseline tier',
437
- value: draft.baselineTier,
438
- options: TIERS.map((tier) => ({ value: tier, label: tier })),
439
- onSelect: (tier) => actions.baseline(tier),
440
- })
441
- : `Baseline tier: ${draft.baselineTier}`,
442
- ),
443
- marker(ui, baseline),
444
- ui.dim('start here, fall back here'),
445
- ),
446
- ui.text(' '),
447
- ui.head('SWITCH COST · from these routes'),
448
- ...switchCost(ui, config, draft.routes),
449
- ui.Button({ key: 'reset-routes', label: 'Reset routes to defaults', hotkey: 'r', onPress: actions.resetRoutes }),
450
- ui.dim('A new model ID needs router.json → models: price, window, efforts.'),
451
- ui.text(' '),
452
- ...activitySections(ui, config, view, changes, actions, modelOptions),
453
- ui.text(' '),
454
- ui.line(ui.head('POLICY'), ui.dim(' · applies next turn · edit, then Save')),
455
- ...POLICY_ROWS.map(([key, label, format, hint]) =>
456
- ui.line(
457
- ui.cell(20, label),
458
- ui.cell(
459
- 12,
460
- choice(ui, key, tuning[key], format, (value) => actions.tune(key, value)),
461
- ),
462
- marker(ui, policy.includes(key)),
463
- ui.dim(hint),
464
- ),
465
- ),
466
- ui.Button({ key: 'reset-policy', label: 'Reset policy to defaults', onPress: actions.resetPolicy }),
467
- ui.text(' '),
468
- ui.head('CONFIG'),
469
- ui.line(
470
- `File ${view.configPath ?? 'profile router.json'} `,
471
- view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
472
- ),
473
- ui.dim(SUBAGENT_LINE[config.subagentRouting]),
474
- );
475
- return out;
476
- }
477
-
478
- function switchCost(ui, config, routes) {
479
- return LADDER.slice(0, -1).map((upperTier, i) => {
480
- const upper = routes[upperTier];
481
- const lower = routes[LADDER[i + 1]];
482
- const pair = `${LADDER[i + 1]} → ${upperTier}`.padEnd(16);
483
- if (sameRoute(upper, lower))
484
- return ui.line(ui.text('! ', { color: 'yellow' }), pair, 'identical: this step changes nothing');
485
- if (upper.model === lower.model)
486
- return ui.line(
487
- ui.dim('· '),
488
- pair,
489
- sharesEffort(config, upper)
490
- ? 'same model, new effort: keeps its cache'
491
- : 'same model, new effort: priced as a new cache',
492
- );
493
- return ui.line(ui.dim('· '), pair, 'model change: priced as a cold cache write');
494
- });
495
- }
496
-
497
- // "S·med": the model's initial and a short effort, for the matrix.
498
- function shortRoute(config, route) {
499
- const model = config.models[route.model];
500
- const effort = model.efforts.length ? `·${EFFORT_SHORT[route.effort] ?? 'ses'}` : '';
501
- return `${modelName(model.id)[0]}${effort}`;
427
+ // "sonnet·high": the route's models key and its effort, short enough for the grid; `inherit` for a route that leaves
428
+ // the effort to the session, and no effort for a model without efforts. The key, not the model name: two Haiku versions
429
+ // in router.json still read apart.
430
+ function shortRoute(config, route, narrow) {
431
+ if (!config.models[route.model].efforts.length) return route.model;
432
+ const effort = route.effort ?? INHERIT;
433
+ return `${route.model}·${narrow ? (EFFORT_SHORT[effort] ?? effort) : effort}`;
502
434
  }
503
435
  const routeKey = (route) => `${route.model}@${route.effort ?? ''}`;
436
+ const builtIn = (activity, tier) => DEFAULTS.activities[activity]?.[tier] ?? null;
504
437
  const sharesEffort = (config, route) => effortSharesCache(config, config.models[route.model]?.id);
505
438
  // The cache a route runs on: one per model on a model that keeps one cache across efforts, else one per route.
506
439
  const cacheOf = (config, route) => (sharesEffort(config, route) ? route.model : routeKey(route));
507
440
 
508
- // Why an override may be a mistake: no effect, a route above the next tier's, or a pair no other cell runs.
441
+ // Why an override may be a mistake: no effect, a route above the next tier's, or a cache no other cell runs on.
509
442
  function overrideWarnings(config, uses, activity, tier) {
510
443
  const route = resolveRoute(config, tier, activity);
511
- if (sameRoute(route, config.routes[tier])) return ['same as base: no effect'];
444
+ if (sameRoute(route, config.routes[tier])) return [];
512
445
  const above = config.routes[TIERS[TIERS.indexOf(tier) + 1]];
513
446
  return [
514
447
  above && compareRoutes(config, route, above) > 0 ? 'stronger than the tier above' : null,
515
448
  uses.get(cacheOf(config, route)) === 1
516
- ? `${sharesEffort(config, route) ? 'new model' : 'new (model, effort) pair'}: one more cache`
449
+ ? `${sharesEffort(config, route) ? 'a model' : 'a model + effort'} only this cell uses: one more cache`
517
450
  : null,
518
451
  ].filter(Boolean);
519
452
  }
520
453
 
521
- // ACTIVITIES, the effective matrix of the draft, and OVERRIDES, its editable cells. Both join the routing draft.
522
- function activitySections(ui, config, view, changes, actions, modelOptions) {
523
- const draft = { ...config, ...changes.draft };
524
- const mode = draft.activityRouting;
525
- const cellRoutes = ACTIVITIES.flatMap((activity) => TIERS.map((tier) => resolveRoute(draft, tier, activity)));
526
- // Uses per cache, for the one-more-cache warning, and the distinct routes.
454
+ // A model Select and an effort Select for one route; `session` is offered as `inherit`.
455
+ function routeSelects(ui, config, key, route, modelOptions, onModel, onEffort) {
456
+ const model = config.models[route.model];
457
+ const aliases = modelOptions.includes(route.model) ? modelOptions : [route.model, ...modelOptions];
458
+ return [
459
+ ui.cell(
460
+ 14,
461
+ ui.Select
462
+ ? ui.Select({
463
+ key: `${key}-model`,
464
+ value: route.model,
465
+ options: aliases.map((alias) => ({ value: alias, label: modelName(config.models[alias].id) })),
466
+ onSelect: onModel,
467
+ })
468
+ : modelName(model.id),
469
+ ),
470
+ ui.cell(
471
+ 12,
472
+ !model.efforts.length
473
+ ? ui.dim('none')
474
+ : ui.Select
475
+ ? ui.Select({
476
+ key: `${key}-effort`,
477
+ value: route.effort ?? SESSION_EFFORT,
478
+ options: [
479
+ { value: SESSION_EFFORT, label: INHERIT },
480
+ ...model.efforts.map((effort) => ({ value: effort, label: effort })),
481
+ ],
482
+ onSelect: (effort) => onEffort(effort === SESSION_EFFORT ? null : effort),
483
+ })
484
+ : (route.effort ?? INHERIT),
485
+ ),
486
+ ];
487
+ }
488
+
489
+ // Routes per cache: the tiers' routes, and the overrides when `overrides` is set. The count shows the overrides once
490
+ // activity routing is on; the one-more-cache warning always counts them, so it reads the same in every mode. `shared`
491
+ // says, per counted route, whether its model keeps one cache across efforts.
492
+ function cacheUses(draft, overrides) {
527
493
  const uses = new Map();
528
- const routeKeys = new Set();
529
- for (const route of [...TIERS.map((tier) => draft.routes[tier]), ...cellRoutes]) {
494
+ const shared = [];
495
+ const count = (route) => {
496
+ shared.push(sharesEffort(draft, route));
530
497
  uses.set(cacheOf(draft, route), (uses.get(cacheOf(draft, route)) ?? 0) + 1);
531
- routeKeys.add(routeKey(route));
532
- }
533
- // Activities with the same row share it, so the matrix stays as short as the overrides are few.
534
- const rows = new Map();
535
- for (const activity of ACTIVITIES) {
536
- const cells = TIERS.map((tier) => {
537
- const route = resolveRoute(draft, tier, activity);
538
- return sameRoute(route, draft.routes[tier]) ? '·' : shortRoute(draft, route);
539
- });
540
- const row = rows.get(cells.join()) ?? { names: [], cells };
541
- rows.set(cells.join(), { ...row, names: [...row.names, activity] });
542
- }
543
- const [distinct, caches] = [routeKeys.size, uses.size];
544
- const matrixRow = (name, cells) => ui.text(` ${name.padEnd(30)}${cells.map((c) => c.padEnd(9)).join('')}`);
545
- // The mode leads the section: it decides whether the matrix below runs or is only shown.
498
+ };
499
+ for (const tier of TIERS) count(draft.routes[tier]);
500
+ if (overrides)
501
+ for (const activity of ACTIVITIES)
502
+ for (const tier of TIERS) {
503
+ const route = resolveRoute(draft, tier, activity);
504
+ if (!sameRoute(route, draft.routes[tier])) count(route);
505
+ }
506
+ return { uses, shared };
507
+ }
508
+
509
+ // The Routes tab: one grid of tier (columns) by activity (rows), the tiers' own routes on top. A cell press opens its
510
+ // editor under the grid. Nothing is written until Save; the cache count reads the whole draft.
511
+ function routesTab(ui, config, view, _usage, actions, modelOptions, columns) {
512
+ const changes = routingChanges(config, view);
513
+ const draft = { ...config, ...changes.draft };
514
+ const mode = draft.activityRouting;
515
+ const narrow = Number.isFinite(columns) && columns < 80;
516
+ const width = narrow ? 14 : 16;
517
+ const { uses, shared } = cacheUses(draft, mode === 'on');
518
+ const selected = view.routeCell ?? null;
519
+ const cellButton = (row, tier, text, dim) =>
520
+ ui.cell(
521
+ width,
522
+ ui.Button({
523
+ key: `cell-${row}-${tier}`,
524
+ label: `${selected === `${row}.${tier}` ? '▸' : ' '}${text}`,
525
+ plain: true,
526
+ ...(dim ? { dimColor: true } : {}),
527
+ onPress: () => actions.selectCell(`${row}.${tier}`),
528
+ }),
529
+ );
530
+ const gridRow = (name, cells) => ui.line(ui.cell(13, name), ...cells);
546
531
  const out = [
547
- ui.line(ui.head('ACTIVITIES'), ui.dim(' · applies next turn · edit, then Save')),
532
+ ui.line(ui.head('ROUTES'), ui.dim(' · which model runs, by tier and activity · edit, then Save')),
548
533
  ui.line(
549
534
  ui.cell(
550
535
  26,
@@ -561,55 +546,163 @@ function activitySections(ui, config, view, changes, actions, modelOptions) {
561
546
  marker(ui, changes.mode),
562
547
  ui.dim(ACTIVITY_MODE_HINT[mode]),
563
548
  ),
564
- ui.line(ui.cell(32, ''), ui.dim(TIERS.map((t) => t.padEnd(9)).join(''))),
565
- matrixRow(
566
- 'base',
567
- TIERS.map((tier) => shortRoute(draft, draft.routes[tier])),
568
- ),
569
- ...[...rows.values()].map(({ names, cells }) => matrixRow(names.join(' '), cells)),
570
- ui.dim(
571
- ` ${distinct} distinct route${distinct === 1 ? '' : 's'} · ${caches} cache${caches === 1 ? '' : 's'}` +
572
- `${mode === 'on' ? '' : ' once activity routing is on'}`,
573
- ),
549
+ ...overridesState(ui, view, config.activityRouting, mode),
574
550
  ui.text(' '),
575
- ui.line(ui.head('OVERRIDES'), ...overridesState(ui, view, config.activityRouting, mode)),
551
+ ui.line(ui.cell(13, ''), ...TIERS.map((tier) => ui.cell(width, ui.tier(tier, ` ${tier}`)))),
552
+ gridRow(
553
+ ui.text('every turn', { bold: true }),
554
+ TIERS.map((tier) =>
555
+ cellButton(
556
+ TIER_ROW,
557
+ tier,
558
+ `${shortRoute(draft, draft.routes[tier], narrow)}${changes.tiers.includes(tier) ? '●' : ''}`,
559
+ false,
560
+ ),
561
+ ),
562
+ ),
576
563
  ];
577
- const free = [];
578
- for (const activity of ACTIVITIES) {
579
- for (const tier of TIERS) {
580
- const edited = changes.cells.some(([a, t]) => a === activity && t === tier);
581
- const route = resolveRoute(draft, tier, activity);
582
- // A built-in override set to the tier's route is how a removal is saved: it lists as free, not as no effect.
583
- const removed =
584
- sameRoute(route, draft.routes[tier]) && DEFAULTS.activities[activity]?.[tier] !== undefined && !edited;
585
- if (!draft.activities[activity]?.[tier] || removed) {
586
- free.push([activity, tier]);
587
- continue;
588
- }
589
- out.push(overrideRow(ui, draft, route, activity, tier, edited, actions, modelOptions, uses));
590
- }
591
- }
592
- if (ui.Select && free.length)
564
+ for (const activity of ACTIVITIES)
593
565
  out.push(
594
- ui.Select({
595
- key: 'activity-add',
596
- value: '',
597
- options: [
598
- { value: '', label: 'add an override…' },
599
- ...free.map(([activity, tier]) => ({ value: `${activity}.${tier}`, label: `${activity} at ${tier}` })),
600
- ],
601
- onSelect: (picked) => {
602
- const [activity, tier] = picked.split('.');
603
- return tier ? actions.addActivity(activity, tier) : undefined;
604
- },
605
- }),
566
+ gridRow(
567
+ ui.activity(activity),
568
+ TIERS.map((tier) => {
569
+ const route = resolveRoute(draft, tier, activity);
570
+ const edited = changes.cells.some(([a, t]) => a === activity && t === tier) ? '●' : '';
571
+ if (sameRoute(route, draft.routes[tier])) return cellButton(activity, tier, `·${edited}`, true);
572
+ const preset = builtIn(activity, tier);
573
+ const mark = preset && sameRoute(route, { model: preset.model, effort: preset.effort ?? null }) ? '°' : '';
574
+ return cellButton(activity, tier, `${shortRoute(draft, route, narrow)}${mark}${edited}`, mode !== 'on');
575
+ }),
576
+ ),
606
577
  );
578
+ out.push(
579
+ ui.dim(' · runs the tier’s model ° built-in default ● unsaved'),
580
+ ui.text(' '),
581
+ ...cellEditor(ui, draft, changes, selected, cacheUses(draft, true).uses, actions, modelOptions),
582
+ ui.text(' '),
583
+ ...cacheLines(ui, uses.size, shared, mode, columns),
584
+ ...LADDER.slice(0, -1)
585
+ .filter((upper, i) => sameRoute(draft.routes[upper], draft.routes[LADDER[i + 1]]))
586
+ .map((upper) =>
587
+ ui.text(
588
+ `! ${LADDER[LADDER.indexOf(upper) + 1]} and ${upper} run the same model and effort: that step changes nothing`,
589
+ { color: 'yellow' },
590
+ ),
591
+ ),
592
+ ui.Button({ key: 'reset-routes', label: 'Reset routes to defaults', hotkey: 'r', onPress: actions.resetRoutes }),
593
+ ui.dim('A new model ID needs router.json → models: price, window, efforts.'),
594
+ );
607
595
  return out;
608
596
  }
609
597
 
610
- // Whether the overrides run now: activity routing on is not enough while routing itself is off or unavailable.
611
- // Whether overrides run now: the saved mode decides, since a draft runs nothing until Save. A different draft mode
612
- // says what Save will change.
598
+ // Why the cache count matters, in one or two lines: a model keeps one cache across efforts (the 5.5 models on an API key
599
+ // or a subscription) or one per effort (other providers).
600
+ function cacheLines(ui, n, shared, mode, columns) {
601
+ const scope = mode === 'on' ? '' : ' (tiers only: activity routing is not on)';
602
+ const per = shared.every(Boolean)
603
+ ? 'one per model; effort changes keep it'
604
+ : shared.some(Boolean)
605
+ ? 'one per model, or per model + effort where efforts cache apart'
606
+ : 'one per model + effort';
607
+ return dimLines(
608
+ ui,
609
+ `${plural(n, 'prompt cache')} in use${scope}: ${per}. A switch to a cold cache writes the whole context again, the switch cost on Now.`,
610
+ Math.min(columns ?? 78, 78),
611
+ );
612
+ }
613
+
614
+ // The editor of the selected grid cell: a tier's own route, or an activity's cell with what it runs, its built-in
615
+ // default, and the two ways back.
616
+ function cellEditor(ui, draft, changes, selected, uses, actions, modelOptions) {
617
+ const [row, tier] = selected?.split('.') ?? [];
618
+ if (!TIERS.includes(tier) || (row !== TIER_ROW && !ACTIVITIES.includes(row)))
619
+ return [ui.dim('Select a cell to change its model and effort.')];
620
+ if (row === TIER_ROW) {
621
+ const route = draft.routes[tier];
622
+ const model = draft.models[route.model];
623
+ return [
624
+ ui.line(
625
+ ui.cell(22, ui.line(ui.tier(tier), ui.dim(' · every turn'))),
626
+ ...routeSelects(
627
+ ui,
628
+ draft,
629
+ `route-${tier}`,
630
+ route,
631
+ modelOptions,
632
+ (alias) => actions.routeModel(tier, alias),
633
+ (effort) => actions.routeEffort(tier, effort),
634
+ ),
635
+ marker(ui, changes.tiers.includes(tier)),
636
+ ),
637
+ ui.dim(
638
+ `${''.padEnd(22)}$${model.input} in · $${model.output ?? '?'} out per M tokens · ${windowSize(model.contextWindow)} window`,
639
+ ),
640
+ ];
641
+ }
642
+ const activity = row;
643
+ const route = resolveRoute(draft, tier, activity);
644
+ const base = draft.routes[tier];
645
+ const preset = builtIn(activity, tier);
646
+ const presetRoute = preset ? { model: preset.model, effort: preset.effort ?? null } : null;
647
+ const edited = changes.cells.some(([a, t]) => a === activity && t === tier);
648
+ const own = !sameRoute(route, base);
649
+ // A saved cell that resolves to the tier's route and is no built-in one changes nothing; 1.6 wrote such cells.
650
+ const noEffect = !own && !presetRoute && Boolean(draft.activities[activity]?.[tier]);
651
+ const drop = own || noEffect;
652
+ const state = !own
653
+ ? presetRoute && !sameRoute(route, presetRoute)
654
+ ? 'runs the tier’s model; the built-in default is removed'
655
+ : noEffect
656
+ ? 'same as the tier’s model: no effect'
657
+ : 'runs the tier’s model'
658
+ : presetRoute && sameRoute(route, presetRoute)
659
+ ? 'built-in default'
660
+ : 'your override';
661
+ const warnings = overrideWarnings(draft, uses, activity, tier);
662
+ const back = Boolean(presetRoute) && !sameRoute(route, presetRoute);
663
+ return [
664
+ ui.line(
665
+ ui.cell(22, ui.line(ui.activity(activity), ' at ', ui.tier(tier))),
666
+ ...routeSelects(
667
+ ui,
668
+ draft,
669
+ `activity-${activity}-${tier}`,
670
+ route,
671
+ modelOptions,
672
+ (alias) => actions.activityModel(activity, tier, alias),
673
+ (effort) => actions.activityEffort(activity, tier, effort),
674
+ ),
675
+ marker(ui, edited),
676
+ ),
677
+ ui.line(ui.cell(22, ''), ui.dim(state)),
678
+ ...(drop || back
679
+ ? [
680
+ ui.line(
681
+ ui.cell(22, ''),
682
+ drop
683
+ ? ui.Button({
684
+ key: `activity-tier-${activity}-${tier}`,
685
+ label: `Use tier model: ${routeName(draft, base)}`,
686
+ onPress: () => actions.removeActivity(activity, tier),
687
+ })
688
+ : null,
689
+ drop && back ? ' ' : null,
690
+ back
691
+ ? ui.Button({
692
+ key: `activity-default-${activity}-${tier}`,
693
+ label: `Restore default: ${routeName(draft, presetRoute)}`,
694
+ onPress: () => actions.restoreActivity(activity, tier),
695
+ })
696
+ : null,
697
+ ),
698
+ ]
699
+ : []),
700
+ ...warnings.map((warning) => ui.text(`${''.padEnd(22)}! ${warning}`, { color: 'yellow' })),
701
+ ];
702
+ }
703
+
704
+ // Whether the overrides run now: the saved mode decides, since a draft runs nothing until Save. A different draft mode
705
+ // says what Save will change. Nothing while they run.
613
706
  function overridesState(ui, view, saved, drafted) {
614
707
  const why = (mode) =>
615
708
  view.phase === 'unavailable'
@@ -620,50 +713,14 @@ function overridesState(ui, view, saved, drafted) {
620
713
  ? null
621
714
  : `activity routing is ${mode}`;
622
715
  const now = why(saved);
623
- const state = now ? ui.text(` · not in use: ${now}`, { color: 'yellow' }) : ui.dim(' · in use');
624
- if (drafted === saved || Boolean(why(drafted)) === Boolean(now)) return [state];
625
- return [state, ui.dim(why(drafted) ? ' · not in use after Save' : ' · in use after Save')];
626
- }
627
-
628
- function overrideRow(ui, draft, route, activity, tier, edited, actions, modelOptions, uses) {
629
- const model = draft.models[route.model];
630
- const aliases = modelOptions.includes(route.model) ? modelOptions : [route.model, ...modelOptions];
631
- const warnings = overrideWarnings(draft, uses, activity, tier);
632
- return ui.line(
633
- ui.cell(10, activity),
634
- ui.cell(8, ui.tier(tier)),
635
- ui.cell(
636
- 14,
637
- ui.Select
638
- ? ui.Select({
639
- key: `activity-model-${activity}-${tier}`,
640
- value: route.model,
641
- options: aliases.map((alias) => ({ value: alias, label: modelName(draft.models[alias].id) })),
642
- onSelect: (alias) => actions.activityModel(activity, tier, alias),
643
- })
644
- : modelName(model.id),
645
- ),
646
- ui.cell(
647
- 12,
648
- !model.efforts.length
649
- ? ui.dim('none')
650
- : ui.Select
651
- ? ui.Select({
652
- key: `activity-effort-${activity}-${tier}`,
653
- value: route.effort ?? SESSION_EFFORT,
654
- options: [SESSION_EFFORT, ...model.efforts].map((effort) => ({ value: effort, label: effort })),
655
- onSelect: (effort) => actions.activityEffort(activity, tier, effort === SESSION_EFFORT ? null : effort),
656
- })
657
- : (route.effort ?? SESSION_EFFORT),
716
+ const after = drafted === saved || Boolean(why(drafted)) === Boolean(now) ? null : why(drafted) ? 'not' : 'in';
717
+ if (!now && !after) return [];
718
+ return [
719
+ ui.line(
720
+ now ? ui.text(`Activity overrides not in use: ${now}`, { color: 'yellow' }) : ui.dim('Activity overrides in use'),
721
+ after ? ui.dim(` · ${after === 'not' ? 'not in use' : 'in use'} after Save`) : null,
658
722
  ),
659
- marker(ui, edited),
660
- ui.Button({
661
- key: `activity-remove-${activity}-${tier}`,
662
- label: 'remove',
663
- onPress: () => actions.removeActivity(activity, tier),
664
- }),
665
- warnings.length ? ui.text(` ${warnings.join(' · ')}`, { color: 'yellow' }) : null,
666
- );
723
+ ];
667
724
  }
668
725
 
669
726
  // A Select over TUNING_CHOICES[key], with a saved value outside them kept as the first option.
@@ -678,57 +735,161 @@ function choice(ui, key, value, format, pick) {
678
735
  });
679
736
  }
680
737
 
681
- // One row per configured classifier. A row press and the deadline are single values with nothing to review as a set,
682
- // so each writes router.json at once; Undo in the status bar puts it back.
683
- function classifierTab(ui, config, view, _usage, actions) {
738
+ // The Policy tab: each control inside the sentence it completes, its default named when the value differs. One Save
739
+ // writes it with the Routes draft.
740
+ function policyTab(ui, config, view, _usage, actions) {
741
+ const changes = routingChanges(config, view);
742
+ const { draft, tuning, policy } = changes;
743
+ const defaults = tuningOf(DEFAULTS);
744
+ const label = classifierLabel(config);
745
+ const pad = ''.padEnd(13);
746
+ const tune = (key) => choice(ui, key, tuning[key], POLICY_FORMAT[key], (value) => actions.tune(key, value));
747
+ const note = (key) => [
748
+ marker(ui, policy.includes(key)),
749
+ tuning[key] === defaults[key] ? null : ui.dim(`default ${POLICY_FORMAT[key](defaults[key])}`),
750
+ ];
751
+ const { upgradeBase, upgradeSlope } = config.policy;
752
+ const credits = Object.values(config.models).some((model) => model.billing === 'credits');
753
+ return [
754
+ ui.line(ui.head('POLICY'), ui.dim(' · how readily the router changes models · edit, then Save')),
755
+ ui.text(' '),
756
+ ui.line(
757
+ ui.cell(13, ui.text('Start', { bold: true })),
758
+ 'at ',
759
+ ui.Select
760
+ ? ui.Select({
761
+ key: 'baseline',
762
+ value: draft.baselineTier,
763
+ options: TIERS.map((tier) => ({ value: tier, label: tier })),
764
+ onSelect: (tier) => actions.baseline(tier),
765
+ })
766
+ : draft.baselineTier,
767
+ ' ',
768
+ marker(ui, changes.baseline),
769
+ draft.baselineTier === DEFAULTS.baselineTier ? null : ui.dim(`default ${DEFAULTS.baselineTier}`),
770
+ ),
771
+ ui.dim(`${pad}when the session’s model is no tier’s model`),
772
+ ui.line(
773
+ ui.cell(13, ui.text('Going down', { bold: true })),
774
+ 'after ',
775
+ tune('downgradeVotes'),
776
+ ' agreeing turns ',
777
+ ...note('downgradeVotes'),
778
+ ),
779
+ ui.line(pad, 'if a cache write pays back within ', tune('horizon'), ' ', ...note('horizon')),
780
+ ui.line(
781
+ ui.cell(13, ui.text('Going up', { bold: true })),
782
+ ui.dim(
783
+ `needs ${label} support of ${percent(upgradeBase)}, up to ${percent(upgradeBase + upgradeSlope)} as the switch costs more`,
784
+ ),
785
+ ),
786
+ ui.line(
787
+ ui.cell(13, ui.text('Activities', { bold: true })),
788
+ 'apply at ',
789
+ tune('activityMass'),
790
+ ' certainty or more ',
791
+ ...note('activityMass'),
792
+ ),
793
+ ui.dim(`${pad}else a new task runs its tier’s model; a continuation keeps it`),
794
+ ui.line(
795
+ ui.cell(13, ui.text('Credits', { bold: true })),
796
+ 'cap one cold cache write at ',
797
+ tune('cashCapUsd'),
798
+ ' ',
799
+ ...note('cashCapUsd'),
800
+ ),
801
+ ui.dim(
802
+ credits
803
+ ? `${pad}on a model that bills credits`
804
+ : `${pad}no model in router.json bills credits, so this has no effect`,
805
+ ),
806
+ ui.text(' '),
807
+ ui.Button({ key: 'reset-policy', label: 'Reset policy to defaults', onPress: actions.resetPolicy }),
808
+ ui.text(' '),
809
+ ui.line(
810
+ ui.head('FILE'),
811
+ ` ${view.configPath ?? 'profile router.json'} `,
812
+ view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
813
+ ),
814
+ ui.dim(SUBAGENT_LINE[config.subagentRouting]),
815
+ ];
816
+ }
817
+
818
+ // One row per configured classifier, as columns to compare: where the prompt goes, its activity probe and p95 wait,
819
+ // and whether its credentials are complete. A row press and the deadline are single values with nothing to review as
820
+ // a set, so each writes router.json at once; Undo in the status bar puts it back. Under the rows, the active
821
+ // classifier's own settings and readings, and its accuracy across sessions.
822
+ function classifierTab(ui, config, view, _usage, actions, _modelOptions, columns) {
684
823
  const active = activeClassifier(config);
685
824
  const health = view.health ?? { failures: 0, pausedUntil: 0 };
686
- const rows = Object.entries(config.classifiers).flatMap(([id, entry]) => {
825
+ const where = (entry) => (isLocal(entry.endpoint) ? 'this machine' : hostOf(entry.endpoint));
826
+ const rows = Object.entries(config.classifiers).map(([id, entry]) => {
687
827
  const isActive = id === config.classifier;
688
828
  const missing = missingCredentials(config, view, id);
689
- const probe = probeText(config, id);
690
- const row = ui.line(
691
- ui.Button({
692
- key: `classifier-${id}`,
693
- label: `${isActive ? '◉' : '○'} ${entry.label.padEnd(11)}`,
694
- variant: isActive ? 'primary' : 'secondary',
695
- onPress: () => actions.classifier(id),
696
- }),
697
- ' ',
698
- ui.cell(20, ui.dim(hostOf(entry.endpoint))),
829
+ const probe = probeOf(config, id);
830
+ return ui.line(
831
+ ui.cell(
832
+ 17,
833
+ ui.Button({
834
+ key: `classifier-${id}`,
835
+ label: `${isActive ? '◉' : '○'} ${entry.label.padEnd(10)}`,
836
+ variant: isActive ? 'primary' : 'secondary',
837
+ onPress: () => actions.classifier(id),
838
+ }),
839
+ ),
840
+ ui.cell(21, isLocal(entry.endpoint) ? ui.text(where(entry), { color: 'green' }) : ui.dim(where(entry))),
841
+ ui.cell(8, probe ? `${probe.correct}/${probe.probes}` : ui.dim('—')),
842
+ ui.cell(10, probe ? `${probe.p95Ms} ms` : ui.dim('—')),
699
843
  missing
700
844
  ? ui.text(`○ ${missingText(config, id, missing)} `, { color: 'yellow' })
701
845
  : ui.text('● ready', { color: 'green' }),
702
- missing
703
- ? ui.Button({ key: `key-${id}`, label: 'Set up', onPress: actions.key })
704
- : isActive && Number.isFinite(view.adviceMs)
705
- ? ui.dim(` ${view.adviceMs} ms`)
706
- : null,
846
+ missing ? ui.Button({ key: `key-${id}`, label: 'Set up', onPress: actions.key }) : null,
707
847
  );
708
- return probe ? [row, ui.dim(` ${probe}`)] : [row];
709
848
  });
849
+ const { latency } = readMetrics(view.activityMetrics);
850
+ const live = latencyP95(Object.hasOwn(latency, config.classifier) ? latency[config.classifier] : null);
851
+ const probe = probeOf(config, config.classifier);
852
+ const p95 = live ? live.ms : probe?.p95Ms;
853
+ const wait = live
854
+ ? `p95 ${live.over ? '>' : '≤'} ${live.ms} ms over ${plural(live.turns, 'turn')}`
855
+ : probe
856
+ ? `p95 ${probe.p95Ms} ms in its probe`
857
+ : 'no wait measured yet';
858
+ const slow = Number.isFinite(p95) && (p95 > active.timeoutMs || live?.over);
859
+ const paused = health.pausedUntil > Date.now();
710
860
  return [
711
- ui.line(ui.head('CLASSIFIER'), ui.dim(' · applies next turn · saves at once')),
712
- ui.dim('Asked once per new turn.'),
861
+ ui.line(ui.head('CLASSIFIER'), ui.dim(' · asked once per new turn · a pick saves at once')),
862
+ ui.dim(`${''.padEnd(17)}${'prompt goes to'.padEnd(21)}${'probe'.padEnd(8)}${'p95'.padEnd(10)}status`),
713
863
  ...rows,
864
+ ...dimLines(ui, ' probe: test prompts with a known activity it answered right, and its p95 wait', columns),
865
+ ui.text(' '),
866
+ ui.line(ui.head(active.label.toUpperCase()), ui.dim(' · active')),
714
867
  ui.line(
715
- ui.cell(9, 'Deadline'),
868
+ ui.cell(12, 'Deadline'),
716
869
  ui.cell(
717
870
  12,
718
871
  choice(ui, 'timeoutMs', active.timeoutMs, (v) => `${v} ms`, actions.classifierTimeout),
719
872
  ),
720
- ui.dim('then keep the model'),
873
+ slow ? ui.text(`${wait}: slower than the deadline`, { color: 'yellow' }) : ui.dim(wait),
721
874
  ),
722
- ui.text(
723
- `Health ${health.pausedUntil > Date.now() ? `paused until ${new Date(health.pausedUntil).toLocaleTimeString()}` : 'active'} · ${health.failures} recent failure${health.failures === 1 ? '' : 's'}`,
875
+ ui.dim(`${''.padEnd(12)}past the deadline the turn keeps its model`),
876
+ ui.line(ui.cell(12, 'Sends'), `prompt + ${config.context.recentTurns} recent turns → ${where(active)}`),
877
+ ui.line(
878
+ ui.cell(12, 'Health'),
879
+ paused
880
+ ? ui.text(`paused until ${new Date(health.pausedUntil).toLocaleTimeString()}`, { color: 'yellow' })
881
+ : 'not paused',
882
+ ` · ${plural(health.failures, 'recent failure')}`,
883
+ Number.isFinite(view.adviceMs) ? ui.dim(` · last ${view.adviceMs} ms`) : null,
724
884
  ),
725
- ui.dim(`Sends prompt + ${config.context.recentTurns} recent turns → ${hostOf(active.endpoint)}`),
726
885
  ui.line(
727
- 'Credentials ',
886
+ ui.cell(12, 'Credentials'),
728
887
  ui.Button({ key: 'key', label: 'Edit', hotkey: 'k', onPress: actions.key }),
729
888
  ui.dim(' opens /plugin configure'),
730
889
  ),
731
- ui.dim(` ${credentialsNeeded(config)}`),
890
+ ...(storeSummary(readStore(view.activityStore)).labelled > 0
891
+ ? [ui.text(' '), ...storeUsage(ui, view.activityStore, view.activityMetrics)]
892
+ : []),
732
893
  ];
733
894
  }
734
895
 
@@ -736,36 +897,39 @@ function classifierTab(ui, config, view, _usage, actions) {
736
897
  const noticeColor = (notice) =>
737
898
  /^Not saved/.test(notice) ? 'red' : /^(Saved|Undid|Path copied)/.test(notice) ? 'green' : 'yellow';
738
899
 
739
- // The one place for commit state on every tab: the unsaved routing diff with Save and Discard, the last notice, and
740
- // Undo for the last write to router.json.
741
- function statusBar(ui, config, view, actions) {
900
+ // The one place for commit state on every tab: the unsaved Routes and Policy draft with Save and Discard (the
901
+ // router.json lines it writes on those two tabs, a count elsewhere), the last notice, and Undo for the last write.
902
+ function statusBar(ui, config, view, tab, actions) {
742
903
  const changes = routingChanges(config, view);
743
904
  const out = [];
744
905
  if (changes.count) {
745
- const diff = (key, before, after) => [
746
- ui.text(`- ${key.padEnd(30)} ${before}`, { color: 'red' }),
747
- ui.text(`+ ${key.padEnd(30)} ${after}`, { color: 'green' }),
748
- ];
749
- out.push(ui.text(' '), ui.dim('router.json changes:'));
750
- for (const tier of changes.tiers)
751
- out.push(
752
- ...diff(
753
- `routes.${tier}`,
754
- routeName(config, config.routes[tier]),
755
- routeName(config, changes.draft.routes[tier]),
756
- ),
757
- );
758
- if (changes.baseline) out.push(...diff('baselineTier', config.baselineTier, changes.draft.baselineTier));
759
- const draft = { ...config, ...changes.draft };
760
- const cellName = (c, activity, tier) =>
761
- c.activities[activity]?.[tier] ? routeName(c, resolveRoute(c, tier, activity)) : 'no override';
762
- for (const [activity, tier] of changes.cells)
763
- out.push(
764
- ...diff(`activities.${activity}.${tier}`, cellName(config, activity, tier), cellName(draft, activity, tier)),
765
- );
766
- if (changes.mode) out.push(...diff('activityRouting', config.activityRouting, changes.draft.activityRouting));
767
- for (const [key, , format, , field] of POLICY_ROWS.filter(([key]) => changes.policy.includes(key)))
768
- out.push(...diff(field, format(changes.saved[key]), format(changes.tuning[key])));
906
+ out.push(ui.text(' '));
907
+ if (DRAFT_TABS.includes(tab)) {
908
+ const diff = (key, before, after) => [
909
+ ui.text(`- ${key.padEnd(30)} ${before}`, { color: 'red' }),
910
+ ui.text(`+ ${key.padEnd(30)} ${after}`, { color: 'green' }),
911
+ ];
912
+ out.push(ui.dim('router.json changes:'));
913
+ for (const tier of changes.tiers)
914
+ out.push(
915
+ ...diff(
916
+ `routes.${tier}`,
917
+ routeName(config, config.routes[tier]),
918
+ routeName(config, changes.draft.routes[tier]),
919
+ ),
920
+ );
921
+ if (changes.baseline) out.push(...diff('baselineTier', config.baselineTier, changes.draft.baselineTier));
922
+ const draft = { ...config, ...changes.draft };
923
+ const cellName = (c, activity, tier) =>
924
+ c.activities[activity]?.[tier] ? routeName(c, resolveRoute(c, tier, activity)) : 'no override';
925
+ for (const [activity, tier] of changes.cells)
926
+ out.push(
927
+ ...diff(`activities.${activity}.${tier}`, cellName(config, activity, tier), cellName(draft, activity, tier)),
928
+ );
929
+ if (changes.mode) out.push(...diff('activityRouting', config.activityRouting, changes.draft.activityRouting));
930
+ for (const [key, , format, field] of POLICY_ROWS.filter(([key]) => changes.policy.includes(key)))
931
+ out.push(...diff(field, format(changes.saved[key]), format(changes.tuning[key])));
932
+ }
769
933
  out.push(
770
934
  ui.line(
771
935
  ui.text(`● ${changes.count} unsaved routing change${changes.count === 1 ? '' : 's'} `, { color: 'yellow' }),
@@ -778,6 +942,7 @@ function statusBar(ui, config, view, actions) {
778
942
  }),
779
943
  ' ',
780
944
  ui.Button({ key: 'discard-routing', label: 'Discard', hotkey: 'd', onPress: actions.discardRouting }),
945
+ DRAFT_TABS.includes(tab) ? null : ui.dim(' listed on Routes and Policy'),
781
946
  ),
782
947
  );
783
948
  }
@@ -799,13 +964,13 @@ function shadowLine(shadow) {
799
964
  return `${counted} · est. ${difference(shadow.minUsd)} … ${difference(shadow.maxUsd)}${some} at list prices`;
800
965
  }
801
966
 
802
- // The counts kept across sessions, read from the stores as last loaded. Agreement uses the classifier's raw answer, so
803
- // it can differ from the session's.
804
- function storeUsage(ui, config, store, metrics) {
967
+ // The counts kept across sessions, read from the stores as last loaded: how often the tools a turn used fit the
968
+ // classifier's activity, and what the activity moves led to. Agreement uses the classifier's raw answer, so it can
969
+ // differ from the session's.
970
+ function storeUsage(ui, store, metrics) {
805
971
  const summary = storeSummary(readStore(store));
806
- const { latency, downMoves } = readMetrics(metrics);
972
+ const { downMoves } = readMetrics(metrics);
807
973
  const out = [ui.head('ACROSS SESSIONS · since the last reset')];
808
- if (summary.labelled === 0) return [...out, ui.dim(' no turns recorded yet')];
809
974
  out.push(ui.text(`Labelled ${summary.labelled} turns`));
810
975
  const { matched, total } = summary.agreement;
811
976
  if (total > 0)
@@ -828,40 +993,26 @@ function storeUsage(ui, config, store, metrics) {
828
993
  out.push(
829
994
  ui.text(`Escalations after a cheaper activity move: ${escalations} in ${moves} move${moves === 1 ? '' : 's'}`),
830
995
  );
831
- const p95 = latencyP95(Object.hasOwn(latency, config.classifier) ? latency[config.classifier] : null);
832
- if (p95)
833
- out.push(
834
- ui.text(
835
- `Latency ${classifierLabel(config)} p95 ${p95.over ? '>' : '≤'} ${p95.ms} ms · ${p95.turns} turn${p95.turns === 1 ? '' : 's'}`,
836
- ),
837
- );
838
996
  if (summary.shadow.turns > 0) out.push(ui.text(shadowLine(summary.shadow)));
839
997
  return out;
840
998
  }
841
999
 
842
1000
  // The ACTIVITY table's columns before the cost, and the cost column.
843
- const ACTIVITY_TABLE = 45;
1001
+ const ACTIVITY_TABLE = 48;
844
1002
  const ACTIVITY_COST = 11;
845
1003
 
846
1004
  // Session counts by activity: turns, requests, share, the estimated list price of their replies and the route most of
847
- // them ran on; the switches by cause, the tool agreement and the shadow readout, then the counts kept
848
- // across sessions. Reset is always offered: the counts kept across sessions may exist before this session has any.
849
- function activityUsage(ui, config, view, actions, columns) {
1005
+ // them ran on; the switches by cause, the tool agreement and the shadow readout. The counts kept across sessions are on
1006
+ // the Classifier tab.
1007
+ function activityUsage(ui, config, view, columns) {
850
1008
  const stats = view.activityStats ?? null;
851
1009
  const mode = config.activityRouting;
852
- const reset = ui.line(
853
- ui.Button({ key: 'reset-stats', label: 'Reset stats', onPress: actions.resetStats }),
854
- ui.dim(' clears activity stats and routing vs your model, all sessions'),
855
- );
856
- const across = [ui.text(' '), ...storeUsage(ui, config, view.activityStore, view.activityMetrics)];
857
1010
  if (mode === 'off' && !stats)
858
1011
  return [
859
- ui.head('ACTIVITY · activity routing off'),
860
- ui.dim(' Not asked. Set activity routing to shadow or on in the Routing tab.'),
861
- ...(storeSummary(readStore(view.activityStore)).labelled > 0 ? across : []),
862
- reset,
1012
+ ui.head('BY ACTIVITY · activity routing off'),
1013
+ ui.dim(' Not asked. Set activity routing to shadow or on in the Routes tab.'),
863
1014
  ];
864
- const out = [ui.line(ui.head('ACTIVITY · this session'), ui.dim(` activity routing ${mode}`))];
1015
+ const out = [ui.line(ui.head('BY ACTIVITY · this session'), ui.dim(` activity routing ${mode}`))];
865
1016
  const rows = Object.entries(stats?.byActivity ?? {}).filter(([, counts]) => counts?.turns > 0);
866
1017
  if (!rows.length) out.push(ui.dim(' no activity readings yet'));
867
1018
  else {
@@ -883,7 +1034,7 @@ function activityUsage(ui, config, view, actions, columns) {
883
1034
  const showRoute = showCost && fits(ACTIVITY_TABLE + ACTIVITY_COST + 3 + widest);
884
1035
  out.push(
885
1036
  ui.dim(
886
- ` ${''.padEnd(9)}${''.padEnd(10)}${'turns'.padStart(7)}${'requests'.padStart(10)}${'share'.padStart(7)}` +
1037
+ ` ${''.padEnd(12)}${''.padEnd(10)}${'turns'.padStart(7)}${'requests'.padStart(10)}${'share'.padStart(7)}` +
887
1038
  `${showCost ? 'est. cost'.padStart(ACTIVITY_COST) : ''}${showRoute ? ' mostly on' : ''}`,
888
1039
  ),
889
1040
  );
@@ -891,7 +1042,8 @@ function activityUsage(ui, config, view, actions, columns) {
891
1042
  const share = counts.turns / total;
892
1043
  out.push(
893
1044
  ui.line(
894
- ` ${name.padEnd(9)}`,
1045
+ ' ',
1046
+ ui.cell(12, ui.activity(name)),
895
1047
  ui.text(bar(share, 1, 10).text, { color: 'cyan' }),
896
1048
  `${String(counts.turns).padStart(7)}${String(counts.requests).padStart(10)}${percent(share).padStart(7)}` +
897
1049
  `${showCost ? cost(counts).padStart(ACTIVITY_COST) : ''}${showRoute ? ` ${route(counts)}` : ''}`,
@@ -913,7 +1065,7 @@ function activityUsage(ui, config, view, actions, columns) {
913
1065
  out.push(ui.text(`Agreement classifier vs tools: ${matched} of ${total} turns (${percent(matched / total)})`));
914
1066
  if (mode === 'shadow' || stats.shadow.turns > 0) out.push(ui.text(shadowLine(stats.shadow)));
915
1067
  }
916
- return [...out, ...across, reset];
1068
+ return out;
917
1069
  }
918
1070
 
919
1071
  // Bars are this wide at the larger of routed and your model; the section drops them before any number when the pane is
@@ -1041,7 +1193,7 @@ function savingsDetail(ui, config, view, { totals, session, across, row, tier, n
1041
1193
  ` Routing spent more than ${modelName(view.nativeModel)} alone because upper tiers ran on ${models}.`,
1042
1194
  columns,
1043
1195
  ),
1044
- ...dimLines(ui, ' To spend less, pick cheaper models for those tiers in the Routing tab.', columns),
1196
+ ...dimLines(ui, ' To spend less, pick cheaper models for those tiers in the Routes tab.', columns),
1045
1197
  );
1046
1198
  }
1047
1199
  const shadow = view.activityStats?.shadow;
@@ -1166,6 +1318,29 @@ function savingsSection(ui, config, view, columns) {
1166
1318
  return [...out, ...notes()];
1167
1319
  }
1168
1320
 
1321
+ // The answer before the table: "Routing saved $1.84 (22%) this session vs Opus 5.5 · xhigh", or what it cost more.
1322
+ // None before EARLY_REPLIES routed replies, or while the section says every reply used your model.
1323
+ function savingsHeadline(ui, config, view) {
1324
+ if (!modelSpec(config, view.nativeModel)) return [];
1325
+ const session = readout(view.savings ?? emptyTotals());
1326
+ if (session.early || !session.replies) return [];
1327
+ const tier = yourTier(config, view);
1328
+ const name = yourModel(view);
1329
+ const share = differenceShare(session)?.replace(/^[−+]/, '');
1330
+ const amount = `${usd(session.differenceUsd)}${share ? ` (${share})` : ''}`;
1331
+ const verb = session.differenceUsd < 0 ? 'saved' : session.differenceUsd > 0 ? 'cost' : 'cost the same';
1332
+ return [
1333
+ ui.line(
1334
+ `Routing ${verb} `,
1335
+ session.differenceUsd === 0 ? '' : ui.text(amount, { bold: true, color: savingsColor(session.differenceUsd) }),
1336
+ session.differenceUsd > 0 ? ' more' : '',
1337
+ session.differenceUsd > 0 ? ' this session than ' : ' this session vs ',
1338
+ tier ? ui.tier(tier, name) : ui.text(name),
1339
+ ),
1340
+ ui.text(' '),
1341
+ ];
1342
+ }
1343
+
1169
1344
  // Prices summed over the priced requests, and how many were not priced (a model without a price in router.json).
1170
1345
  const pricedText = (text, counts) =>
1171
1346
  counts.pricedRequests < counts.requests ? `${text} (${counts.requests - counts.pricedRequests} unpriced)` : text;
@@ -1216,11 +1391,14 @@ function subagentUsage(ui, config, view, columns) {
1216
1391
  return out;
1217
1392
  }
1218
1393
 
1394
+ // Answer first: routing vs your model, then plan quota, then this session by activity. Claude's own readings fold to
1395
+ // one line, with the detail and the estimates behind `details`.
1219
1396
  function usageTab(ui, config, view, usage, actions, _modelOptions, columns) {
1220
1397
  const metrics = usageMetrics(config, view, usage);
1221
1398
  const history = view.history ?? [];
1222
1399
  const tiers = view.tiers ?? [];
1223
1400
  const glyphs = sparkline(history);
1401
+ const quota = (usage?.rateLimits ?? []).filter((limit) => Number.isFinite(limit.percentUsed));
1224
1402
  const trend = history.length
1225
1403
  ? ui.line(
1226
1404
  ' ',
@@ -1231,41 +1409,71 @@ function usageTab(ui, config, view, usage, actions, _modelOptions, columns) {
1231
1409
  ui.dim(` ${formatTokens(Math.min(...history))} … ${formatTokens(Math.max(...history))}`),
1232
1410
  )
1233
1411
  : ui.dim(' no replies yet');
1412
+ const detail = view.usageDetail
1413
+ ? [
1414
+ ui.dim(` context observed ${formatTokens(metrics.observed)} · estimated ${formatTokens(view.contextTokens)}`),
1415
+ ui.dim(` cache read ${formatTokens(view.cacheRead)} · written ${formatTokens(view.cacheWrite)} tokens`),
1416
+ ui.dim(` output ${formatTokens(view.outputTokens)} tokens on the last reply`),
1417
+ ui.text(' '),
1418
+ ui.head('INPUT PER REPLY · lowest to highest'),
1419
+ trend,
1420
+ ui.text(' '),
1421
+ ui.head('ESTIMATES · configured list prices'),
1422
+ ui.text(`Cache hits saved ${dollars(metrics.cacheBenefit)}`),
1423
+ Number.isFinite(view.estimate?.taxUsd)
1424
+ ? ui.text(`Switch cost ${dollars(view.estimate.taxUsd)}`)
1425
+ : null,
1426
+ ...(view.comparison
1427
+ ? [
1428
+ ui.text(`Compared tiers ${view.comparison.incumbent} → ${view.comparison.candidate}`),
1429
+ ui.text(
1430
+ `Next-turn difference ${difference(view.comparison.minUsd)} to ${difference(view.comparison.maxUsd)}`,
1431
+ ),
1432
+ ui.text(
1433
+ `Payback ${view.comparison.paybackTurns === null ? 'none projected' : `${view.comparison.paybackTurns} later turns`}`,
1434
+ ),
1435
+ ]
1436
+ : []),
1437
+ ]
1438
+ : [];
1234
1439
  return [
1440
+ ...savingsHeadline(ui, config, view),
1235
1441
  ...savingsSection(ui, config, view, columns),
1236
- ui.text(' '),
1237
- ui.head('USAGE · Claude readings'),
1238
- ui.line(`Cost ${dollars(metrics.cost)} `, ui.dim('reported by Claude')),
1239
- ui.gauge('Context ', metrics.contextBar, contextSuffix(metrics)),
1240
- ui.dim(` observed ${formatTokens(metrics.observed)} · estimated ${formatTokens(view.contextTokens)}`),
1241
- ui.gauge('Cache ', metrics.cacheBar, metrics.cacheBar.percent === null ? 'no reply yet' : 'last reply'),
1242
- ui.dim(` read ${formatTokens(view.cacheRead)} · written ${formatTokens(view.cacheWrite)} tokens`),
1243
- ui.text(`Output ${formatTokens(view.outputTokens)} tokens on the last reply`),
1244
- ui.text(' '),
1245
- ui.head('INPUT PER REPLY · lowest to highest'),
1246
- trend,
1247
- ...(usage?.rateLimits ?? [])
1248
- .filter((limit) => Number.isFinite(limit.percentUsed))
1249
- .map((limit) => ui.gauge(`${limit.kind.replaceAll('_', ' ').padEnd(11)}`, bar(limit.percentUsed, 100), 'used')),
1250
- ui.text(' '),
1251
- ...activityUsage(ui, config, view, actions, columns),
1252
- ui.text(' '),
1253
- ...subagentUsage(ui, config, view, columns),
1254
- ui.text(' '),
1255
- ui.head('ESTIMATES · configured list prices'),
1256
- ui.text(`Cache hits saved ${dollars(metrics.cacheBenefit)}`),
1257
- Number.isFinite(view.estimate?.taxUsd) ? ui.text(`Switch cost ${dollars(view.estimate.taxUsd)}`) : null,
1258
- ...(view.comparison
1442
+ ...(quota.length
1259
1443
  ? [
1260
- ui.text(`Compared tiers ${view.comparison.incumbent} → ${view.comparison.candidate}`),
1261
- ui.text(
1262
- `Next-turn difference ${difference(view.comparison.minUsd)} to ${difference(view.comparison.maxUsd)}`,
1263
- ),
1264
- ui.text(
1265
- `Payback ${view.comparison.paybackTurns === null ? 'none projected' : `${view.comparison.paybackTurns} later turns`}`,
1444
+ ui.text(' '),
1445
+ ui.head('PLAN QUOTA'),
1446
+ ...quota.map((limit) =>
1447
+ ui.gauge(`${limit.kind.replaceAll('_', ' ').padEnd(11)}`, bar(limit.percentUsed, 100), 'used'),
1266
1448
  ),
1267
1449
  ]
1268
1450
  : []),
1451
+ ui.text(' '),
1452
+ ...activityUsage(ui, config, view, columns),
1453
+ ui.text(' '),
1454
+ ...subagentUsage(ui, config, view, columns),
1455
+ ui.text(' '),
1456
+ ui.line(
1457
+ ui.head('CLAUDE READINGS'),
1458
+ ` cost ${dollars(metrics.cost)}`,
1459
+ ui.dim(' · '),
1460
+ ui.text(`context ${share(metrics.contextBar.percent)}`, { color: metrics.contextBar.color }),
1461
+ ui.dim(' · '),
1462
+ ui.text(`cache ${share(metrics.cacheBar.percent)}`, { color: metrics.cacheBar.color }),
1463
+ ' ',
1464
+ ui.Button({
1465
+ key: 'usage-detail',
1466
+ label: view.usageDetail ? 'less' : 'details',
1467
+ variant: view.usageDetail ? 'primary' : 'secondary',
1468
+ onPress: actions.usageDetail,
1469
+ }),
1470
+ ),
1471
+ ...detail,
1472
+ ui.text(' '),
1473
+ ui.line(
1474
+ ui.Button({ key: 'reset-stats', label: 'Reset stats', onPress: actions.resetStats }),
1475
+ ui.dim(' clears activity stats and routing vs your model, all sessions'),
1476
+ ),
1269
1477
  ui.dim('Press ? for what these estimates leave out.'),
1270
1478
  ];
1271
1479
  }