@alexeiled/claude-router 1.20.1 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +41 -0
- package/README.md +3 -3
- package/docs/activity-routing.md +1 -1
- package/docs/architecture.md +6 -4
- package/docs/configuration.md +9 -8
- package/docs/evaluation.md +4 -4
- package/docs/native-router.md +11 -11
- package/docs/providers.md +5 -6
- package/docs/router-band.svg +158 -137
- package/docs/router-pane-classifier.svg +21 -23
- package/docs/router-pane-now.svg +138 -173
- package/docs/router-pane-policy.svg +21 -23
- package/docs/router-pane-routes.svg +32 -34
- package/docs/router-pane-usage-whatif.svg +139 -157
- package/docs/router-pane-usage.svg +165 -165
- package/docs/routing-modes.md +22 -20
- package/docs/user-guide.md +130 -71
- package/hooks/native-router.mjs +9 -5
- package/lib/band.mjs +254 -171
- package/lib/config.mjs +33 -18
- package/lib/cost.mjs +26 -10
- package/lib/costs.mjs +156 -0
- package/lib/display.mjs +115 -92
- package/lib/modes.mjs +8 -7
- package/lib/panel.mjs +487 -445
- package/lib/policy.mjs +1 -1
- package/lib/prices.mjs +113 -0
- package/lib/providers.mjs +9 -21
- package/lib/route.mjs +1 -1
- package/lib/savings.mjs +14 -8
- package/lib/subagents.mjs +3 -3
- package/package.json +2 -1
package/lib/band.mjs
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
|
-
import { activeClassifier, TIERS } from './config.mjs';
|
|
1
|
+
import { activeClassifier, resolveRoute, TIERS } from './config.mjs';
|
|
2
|
+
import { resetText } from './costs.mjs';
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
+
BILLING_WORDS,
|
|
5
|
+
baselineName,
|
|
4
6
|
classifierLabel,
|
|
5
7
|
classifierStatus,
|
|
6
8
|
classifierWarns,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
costText,
|
|
10
|
+
diffText,
|
|
11
|
+
gaugeCells,
|
|
12
|
+
limitColor,
|
|
9
13
|
modeLever,
|
|
10
14
|
modelColor,
|
|
11
15
|
modelName,
|
|
12
16
|
NOT_A_TIER_REASON,
|
|
13
|
-
observedUsageText,
|
|
14
17
|
percentPair,
|
|
15
18
|
reasonActivity,
|
|
19
|
+
reasonNamesActivity,
|
|
20
|
+
repliesText,
|
|
16
21
|
routeLabel,
|
|
17
|
-
|
|
18
|
-
routingModeText,
|
|
22
|
+
routingModeOf,
|
|
19
23
|
savingsColor,
|
|
24
|
+
sessionCost,
|
|
20
25
|
sessionUsage,
|
|
21
26
|
shortReason,
|
|
22
|
-
|
|
27
|
+
shortRoute,
|
|
28
|
+
shownConfig,
|
|
23
29
|
TIER_COLOR,
|
|
30
|
+
tierBars,
|
|
24
31
|
unavailableReason,
|
|
25
32
|
usageMetrics,
|
|
26
33
|
usd,
|
|
27
34
|
} from './display.mjs';
|
|
28
35
|
import { isSameModel } from './route.mjs';
|
|
29
|
-
import { modelSpec, readout } from './savings.mjs';
|
|
30
36
|
import { PASS_WHY } from './subagents.mjs';
|
|
31
37
|
|
|
32
38
|
const BARS = '▂▄▆█';
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
// Groups on a row sit apart by space alone: the meter, colours and glyphs already separate them.
|
|
40
|
+
const SEPARATOR = ' ';
|
|
41
|
+
// The hover row's controls sit closer: they are buttons, not readings.
|
|
35
42
|
const GAP = ' ';
|
|
36
43
|
// Space the band keeps for the trailing Router button.
|
|
37
44
|
const ROUTER_BUTTON = 8;
|
|
45
|
+
// Cells in the band's gauges: the context window and a plan window.
|
|
46
|
+
const CONTEXT_CELLS = 5;
|
|
47
|
+
const PLAN_CELLS = 8;
|
|
38
48
|
|
|
39
49
|
// Hex, like TIER_COLOR, so every surface draws the same shades. Yellow stays out: it marks a fault that needs action.
|
|
40
50
|
// Activity is Claude Code's orange for a turn's action; italic sets it apart from the high and medium tier colors.
|
|
@@ -43,20 +53,20 @@ const COLOR = {
|
|
|
43
53
|
off: '#2a3040',
|
|
44
54
|
muted: '#8b93a7',
|
|
45
55
|
warn: '#f0b429',
|
|
46
|
-
ink: '#0d1016',
|
|
47
56
|
activity: '#d77757',
|
|
57
|
+
gauge: '#87d787',
|
|
48
58
|
};
|
|
49
59
|
|
|
50
60
|
const part = (text, style = {}) => ({ text, style });
|
|
51
|
-
|
|
52
|
-
const pill = (text, background) => part(` ${text} `, { backgroundColor: background, color: COLOR.ink, bold: true });
|
|
61
|
+
const dim = (text) => part(text, { dimColor: true });
|
|
53
62
|
const button = (props) => ({ button: props });
|
|
54
|
-
// `priority` 0 never drops; higher numbers drop first when the band is narrow.
|
|
55
|
-
// drop from inside a segment it shares no separator with.
|
|
63
|
+
// `priority` 0 never drops; higher numbers drop first when the band is narrow. `right` segments sit at the row's end.
|
|
56
64
|
const segment = (priority, ...parts) => ({ priority, parts: parts.flat().filter(Boolean) });
|
|
65
|
+
const right = (seg) => ({ ...seg, right: true });
|
|
57
66
|
const partWidth = (p) => (p.button ? p.button.label.length + (p.button.plain ? 0 : 4) : p.text.length);
|
|
67
|
+
const partsWidth = (parts) => parts.reduce((n, p) => n + partWidth(p), 0);
|
|
58
68
|
const lineWidth = (segments, separator) =>
|
|
59
|
-
segments.reduce((sum, s, i) => sum + (i ? separator.length : 0) + s.parts
|
|
69
|
+
segments.reduce((sum, s, i) => sum + (i ? separator.length : 0) + partsWidth(s.parts), 0);
|
|
60
70
|
|
|
61
71
|
// Drops the highest-priority segments and parts, later ones first on a tie, until the line fits `columns`. If the
|
|
62
72
|
// priority-0 segments alone are too wide, the later ones go too, and the first is cut with an ellipsis: Ink would
|
|
@@ -89,28 +99,26 @@ export function fitSegments(segments, columns, separator = SEPARATOR) {
|
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
// Signal-strength bars: lit up to the tier in its color, dim above it or when `dim`.
|
|
92
|
-
function meter(tier,
|
|
93
|
-
const lit =
|
|
102
|
+
function meter(tier, off = false) {
|
|
103
|
+
const lit = off ? -1 : TIERS.indexOf(tier);
|
|
94
104
|
return [...BARS].map((bar, i) => part(bar, i <= lit ? { color: TIER_COLOR[tier] } : { dimColor: true }));
|
|
95
105
|
}
|
|
96
106
|
|
|
97
107
|
// The classifier is working: every bar in the accent colour.
|
|
98
108
|
const pendingMeter = () => [...BARS].map((bar) => part(bar, { color: COLOR.accent }));
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (!view.activity || config.activityRouting === 'off') return null;
|
|
106
|
-
return { ...part(`${activityVerb(view.activity)} → `, { color: COLOR.activity, italic: true }), priority: 2 };
|
|
107
|
-
}
|
|
110
|
+
// "Haiku 5.5 · high", the model in bold so the eye finds it first.
|
|
111
|
+
const routeParts = (model, effort) => [
|
|
112
|
+
part(modelName(model), { bold: true }),
|
|
113
|
+
effort === null || effort === undefined ? null : part(` · ${effort}`),
|
|
114
|
+
];
|
|
108
115
|
|
|
109
116
|
function served(view) {
|
|
110
117
|
const { actualModel: actual, selectedModel: selected } = view;
|
|
111
118
|
return Boolean(actual && selected && !isSameModel(selected, actual));
|
|
112
119
|
}
|
|
113
120
|
|
|
121
|
+
// "Jev 93% ≥ 90%": the classifier's support for the switch the policy weighed, against the bar it set.
|
|
114
122
|
function supportText(config, estimate) {
|
|
115
123
|
if (!Number.isFinite(estimate?.threshold)) return null;
|
|
116
124
|
const mass = Number.isFinite(estimate.upgradeMass) ? estimate.upgradeMass : estimate.downgradeMass;
|
|
@@ -119,70 +127,115 @@ function supportText(config, estimate) {
|
|
|
119
127
|
return `${classifierLabel(config)} ${shown} ${mass >= estimate.threshold ? '≥' : '<'} ${bar}`;
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
// The routing mode as a chip, only when it is not balanced: "cost", or "cost effort only" when the mode kept the model.
|
|
131
|
+
function modeChip(config, view) {
|
|
132
|
+
const { mode } = routingModeOf(view);
|
|
133
|
+
if (mode === 'balanced') return null;
|
|
134
|
+
const lever = modeLever(config, view);
|
|
135
|
+
return segment(
|
|
136
|
+
5,
|
|
137
|
+
part(` ${mode} `, { backgroundColor: COLOR.off, color: COLOR.muted }),
|
|
138
|
+
lever ? dim(` ${lever}`) : null,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Context fill and the last reply's cache reuse, kept at the row's end so they stay in one place turn after turn.
|
|
143
|
+
function gauges(config, view, usage) {
|
|
144
|
+
const metrics = usageMetrics(config, view, usage);
|
|
145
|
+
const out = [];
|
|
146
|
+
if (metrics.contextBar.percent !== null) {
|
|
147
|
+
const [filled, empty] = gaugeCells(metrics.contextBar.percent / 100, CONTEXT_CELLS);
|
|
148
|
+
out.push(
|
|
149
|
+
right(
|
|
150
|
+
segment(
|
|
151
|
+
3,
|
|
152
|
+
dim('ctx '),
|
|
153
|
+
part(filled, { color: metrics.contextBar.color }),
|
|
154
|
+
dim(empty),
|
|
155
|
+
part(` ${metrics.contextBar.percent}%`, { color: metrics.contextBar.color }),
|
|
156
|
+
),
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (metrics.cacheBar.percent !== null)
|
|
161
|
+
out.push(
|
|
162
|
+
right(
|
|
163
|
+
segment(
|
|
164
|
+
4,
|
|
165
|
+
dim('cache '),
|
|
166
|
+
part(`${metrics.cacheBar.percent}%`, { color: metrics.cacheBar.color }),
|
|
167
|
+
dim(' last'),
|
|
168
|
+
),
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
|
|
122
174
|
export function bandSegments(config, view, usage, actions) {
|
|
175
|
+
const native = () => routeParts(view.nativeModel, view.nativeEffort);
|
|
123
176
|
if (view.phase === 'unavailable')
|
|
124
177
|
return [
|
|
125
|
-
segment(
|
|
126
|
-
|
|
127
|
-
|
|
178
|
+
segment(
|
|
179
|
+
0,
|
|
180
|
+
part('✕ ', { color: 'red' }),
|
|
181
|
+
native(),
|
|
182
|
+
part(' '),
|
|
183
|
+
button({ key: 'band-fix', label: 'Fix', onPress: actions.open }),
|
|
184
|
+
),
|
|
185
|
+
segment(1, part('routing unavailable', { color: 'red' })),
|
|
186
|
+
segment(3, part(unavailableReason(view), { color: 'red', dimColor: true })),
|
|
128
187
|
];
|
|
129
|
-
//
|
|
130
|
-
//
|
|
188
|
+
// Turn on shares the first segment, which never drops and whose cut keeps buttons whole, so the band's one way back
|
|
189
|
+
// on survives any width.
|
|
131
190
|
if (view.mode === 'manual')
|
|
132
191
|
return [
|
|
133
192
|
segment(
|
|
134
193
|
0,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
part('off', { backgroundColor: COLOR.off, color: COLOR.muted }),
|
|
194
|
+
dim('○ '),
|
|
195
|
+
native(),
|
|
138
196
|
part(' '),
|
|
139
197
|
button({ key: 'band-auto', label: 'Turn on', variant: 'primary', onPress: () => actions.mode('auto') }),
|
|
140
198
|
),
|
|
141
|
-
segment(
|
|
142
|
-
|
|
143
|
-
{ ...part('every turn uses '), priority: 3 },
|
|
144
|
-
part(modelName(view.nativeModel)),
|
|
145
|
-
view.reason === 'model selected manually' ? { ...part(' (/model)', { dimColor: true }), priority: 2 } : null,
|
|
146
|
-
),
|
|
147
|
-
view.reason === NOT_A_TIER_REASON
|
|
148
|
-
? segment(2, part(`${modelName(view.nativeModel)} is not a routing tier`, { dimColor: true }))
|
|
149
|
-
: null,
|
|
199
|
+
segment(1, dim(`routing off${view.reason === 'model selected manually' ? ' · /model' : ''}`)),
|
|
200
|
+
view.reason === NOT_A_TIER_REASON ? segment(2, dim('not a routing tier')) : null,
|
|
150
201
|
].filter(Boolean);
|
|
151
202
|
if (view.phase === 'choosing')
|
|
152
203
|
return [
|
|
153
|
-
segment(0, pendingMeter(),
|
|
154
|
-
segment(
|
|
155
|
-
3,
|
|
156
|
-
part(`${classifierLabel(config)} · ${activeClassifier(config).timeoutMs / 1000} s deadline`, {
|
|
157
|
-
dimColor: true,
|
|
158
|
-
}),
|
|
159
|
-
),
|
|
204
|
+
segment(0, pendingMeter(), dim(' choosing…')),
|
|
205
|
+
segment(3, dim(`${classifierLabel(config)} ≤ ${activeClassifier(config).timeoutMs / 1000} s`)),
|
|
160
206
|
];
|
|
161
207
|
const pin = view.pendingPin
|
|
162
208
|
? segment(
|
|
163
209
|
0,
|
|
164
|
-
part('⏵ next
|
|
165
|
-
part(view.pendingPin, {
|
|
210
|
+
part('⏵ next ', { color: COLOR.accent }),
|
|
211
|
+
part(tierBars(view.pendingPin), { color: TIER_COLOR[view.pendingPin] }),
|
|
212
|
+
part(` ${shortRoute(config, resolveRoute(shownConfig(config, view), view.pendingPin))}`, {
|
|
213
|
+
color: TIER_COLOR[view.pendingPin],
|
|
214
|
+
}),
|
|
166
215
|
part(' '),
|
|
167
216
|
button({ key: 'band-unpin', label: '✕', plain: true, onPress: actions.unpin }),
|
|
168
217
|
)
|
|
169
218
|
: null;
|
|
170
219
|
if (!view.tier && view.phase === 'ready' && !view.actualModel)
|
|
171
220
|
return [
|
|
172
|
-
segment(0, meter(null, true), part('
|
|
221
|
+
segment(0, meter(null, true), part(' '), native()),
|
|
222
|
+
segment(1, dim('ready')),
|
|
173
223
|
pin,
|
|
174
|
-
|
|
224
|
+
modeChip(config, view),
|
|
175
225
|
].filter(Boolean);
|
|
176
226
|
const main = segment(
|
|
177
227
|
0,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
part(route(view)),
|
|
228
|
+
view.tier ? meter(view.tier) : dim('○'),
|
|
229
|
+
part(' '),
|
|
230
|
+
routeParts(view.actualModel ?? view.selectedModel ?? view.nativeModel, view.effort),
|
|
182
231
|
served(view) ? part(' fallback', { color: 'yellow' }) : null,
|
|
183
232
|
);
|
|
184
|
-
|
|
185
|
-
|
|
233
|
+
const activity =
|
|
234
|
+
view.activity && config.activityRouting !== 'off' && !reasonNamesActivity(view.reason)
|
|
235
|
+
? segment(2, part(view.activity, { color: COLOR.activity, italic: true }))
|
|
236
|
+
: null;
|
|
237
|
+
const reason = segment(1, dim(shortReason(view.reason, reasonActivity(config, view))));
|
|
238
|
+
// The warning leads and the route yields: when the band is narrow, what to fix matters more than the model kept.
|
|
186
239
|
if (classifierWarns(view.error))
|
|
187
240
|
return [
|
|
188
241
|
segment(0, part(`⚠ ${classifierStatus(config, view.error)}`, { color: COLOR.warn })),
|
|
@@ -191,134 +244,155 @@ export function bandSegments(config, view, usage, actions) {
|
|
|
191
244
|
: segment(2, button({ key: 'band-fix', label: 'Details', onPress: actions.open })),
|
|
192
245
|
{ ...main, priority: 1 },
|
|
193
246
|
pin,
|
|
194
|
-
|
|
247
|
+
{ ...reason, priority: 3 },
|
|
195
248
|
].filter(Boolean);
|
|
196
|
-
const metrics = usageMetrics(config, view, usage);
|
|
197
|
-
const reading = (bar) => part(bar.percent === null ? '?' : `${bar.percent}%`, { color: bar.color });
|
|
198
249
|
const support = supportText(config, view.estimate);
|
|
199
|
-
// The policy's price for the switch it weighed: mostly the prompt cache the other model must write.
|
|
200
|
-
// cheaper model it is net of what that model saves over the downgrade horizon.
|
|
250
|
+
// The policy's price for the switch it weighed: mostly the prompt cache the other model must write.
|
|
201
251
|
const switchUsd = view.estimate?.taxUsd;
|
|
202
252
|
return [
|
|
203
253
|
main,
|
|
254
|
+
activity,
|
|
204
255
|
pin,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
support ? segment(
|
|
208
|
-
Number.isFinite(switchUsd) && switchUsd >= 0.005
|
|
209
|
-
|
|
210
|
-
: null,
|
|
211
|
-
metrics.contextBar.percent === null && metrics.cacheBar.percent === null
|
|
212
|
-
? null
|
|
213
|
-
: segment(3, part('ctx '), reading(metrics.contextBar), part(' · cache hit '), reading(metrics.cacheBar)),
|
|
256
|
+
reason,
|
|
257
|
+
modeChip(config, view),
|
|
258
|
+
support ? segment(6, dim(support)) : null,
|
|
259
|
+
Number.isFinite(switchUsd) && switchUsd >= 0.005 ? segment(6, dim(`switch ≈ ${usd(switchUsd)}`)) : null,
|
|
260
|
+
...gauges(config, view, usage),
|
|
214
261
|
].filter(Boolean);
|
|
215
262
|
}
|
|
216
263
|
|
|
217
|
-
// The second row
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
264
|
+
// The second row: the plan windows on a Claude plan, then this session's cost with its subagents, and how it compares
|
|
265
|
+
// with your /model (or `unrouted` with subagents):
|
|
266
|
+
// "plan 5h ▰▰▰▱▱▱▱▱ 37% ↻17:00 7d 62% session ≈$7.60 API value −$1.76 (−19%) vs Sonnet 5.5 24 replies".
|
|
267
|
+
// An effort-only profile shows its effort mix instead of a saving. When the band is narrow the reset time, the
|
|
268
|
+
// counts and the words go first; the 5h window and the session total stay.
|
|
269
|
+
export function sessionSegments(config, view, usage, now = Date.now()) {
|
|
270
|
+
const cost = sessionCost(config, view, usage, now);
|
|
271
|
+
const out = [];
|
|
272
|
+
for (const limit of cost.limits) {
|
|
273
|
+
const color = limitColor(limit.percent);
|
|
274
|
+
if (limit.kind === 'five_hour') {
|
|
275
|
+
const [filled, empty] = gaugeCells(limit.percent / 100, PLAN_CELLS);
|
|
276
|
+
const reset = resetText(limit.resetsAt, now);
|
|
277
|
+
out.push(
|
|
278
|
+
segment(
|
|
279
|
+
0,
|
|
280
|
+
dim('plan 5h '),
|
|
281
|
+
part(filled, { color }),
|
|
282
|
+
dim(empty),
|
|
283
|
+
part(` ${limit.percent}%`, { color }),
|
|
284
|
+
reset ? { ...dim(` ↻${reset}`), priority: 4 } : null,
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
} else out.push(segment(3, dim(`${limit.label} `), part(`${limit.percent}%`, { color })));
|
|
288
|
+
}
|
|
289
|
+
const routing = view.mode === 'auto' && view.phase !== 'unavailable';
|
|
290
|
+
if (!routing) return out.filter(Boolean);
|
|
291
|
+
if (!cost.replies && !cost.agents) return [...out, segment(2, dim('session · no replies yet'))].filter(Boolean);
|
|
292
|
+
out.push(
|
|
293
|
+
segment(0, dim('session '), part(costText(cost.totalUsd, cost.billing), { bold: true }), {
|
|
294
|
+
...dim(` ${BILLING_WORDS[cost.billing]}`),
|
|
295
|
+
priority: 5,
|
|
296
|
+
}),
|
|
297
|
+
);
|
|
298
|
+
if (cost.billing === 'mixed') out.push(segment(1, part(`billed ${usd(cost.creditsUsd)}`)));
|
|
299
|
+
if (cost.effortOnly && cost.effortMix.length)
|
|
300
|
+
out.push(segment(2, dim('effort '), part(cost.effortMix.map(([effort, n]) => `${effort} ${n}`).join(' · '))));
|
|
301
|
+
else if (cost.diffUsd !== null)
|
|
302
|
+
out.push(
|
|
303
|
+
segment(
|
|
304
|
+
1,
|
|
305
|
+
part(diffText(cost.diffUsd, cost.baseUsd), { bold: true, color: savingsColor(cost.diffUsd) }),
|
|
306
|
+
dim(` vs ${baselineName(view, sessionUsage(view, now), cost)}`),
|
|
307
|
+
),
|
|
308
|
+
);
|
|
309
|
+
else if (cost.uncomparedReplies)
|
|
310
|
+
out.push(
|
|
311
|
+
segment(
|
|
312
|
+
2,
|
|
313
|
+
dim(
|
|
314
|
+
cost.uncomparedReplies === cost.replies
|
|
315
|
+
? 'not compared'
|
|
316
|
+
: `${cost.uncomparedReplies} of ${cost.replies} not compared`,
|
|
317
|
+
),
|
|
318
|
+
),
|
|
319
|
+
);
|
|
320
|
+
out.push(
|
|
321
|
+
segment(
|
|
322
|
+
6,
|
|
323
|
+
dim(`${repliesText(cost)}${cost.agents ? ` · ${cost.agents} agent${cost.agents === 1 ? '' : 's'}` : ''}`),
|
|
324
|
+
),
|
|
325
|
+
);
|
|
326
|
+
return out.filter(Boolean);
|
|
274
327
|
}
|
|
275
328
|
|
|
276
|
-
// The row
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
329
|
+
// The second row's parts at `columns`.
|
|
330
|
+
export const sessionRow = (config, view, usage, columns, now = Date.now()) =>
|
|
331
|
+
fitSegments(sessionSegments(config, view, usage, now), columns).flatMap((s, i) =>
|
|
332
|
+
i ? [part(SEPARATOR), ...s.parts] : s.parts,
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
// The row revealed under the pointer: a pin per tier, low to high, each named by what it runs ("▂▄ Haiku·high"), then
|
|
336
|
+
// Turn off and the one- or two-row choice. No digit hotkeys, since a bare digit in an empty prompt would press them.
|
|
337
|
+
// When the row is narrow the pins lose their model names first; Turn off and the row choice stay.
|
|
338
|
+
function hoverSegments(config, view, actions, routing, columns) {
|
|
339
|
+
const shown = shownConfig(config, view);
|
|
340
|
+
const pins = (named) =>
|
|
341
|
+
segment(
|
|
342
|
+
1,
|
|
343
|
+
dim('pin '),
|
|
344
|
+
TIERS.flatMap((tier, i) => [
|
|
345
|
+
i ? part(' ') : null,
|
|
346
|
+
button({
|
|
347
|
+
key: `band-pin-${tier}`,
|
|
348
|
+
label: `${tierBars(tier)}${named ? ` ${shortRoute(config, resolveRoute(shown, tier))}` : ''}`,
|
|
349
|
+
onPress: () => actions.pin(tier),
|
|
350
|
+
}),
|
|
351
|
+
]),
|
|
352
|
+
);
|
|
353
|
+
const rest = [
|
|
288
354
|
routing
|
|
289
|
-
? segment(
|
|
290
|
-
0,
|
|
291
|
-
{ ...part('routing on ', { dimColor: true }), priority: 4 },
|
|
292
|
-
button({ key: 'band-manual', label: 'Turn off', onPress: () => actions.mode('manual') }),
|
|
293
|
-
)
|
|
355
|
+
? segment(0, button({ key: 'band-manual', label: 'Turn off', onPress: () => actions.mode('manual') }))
|
|
294
356
|
: null,
|
|
295
357
|
segment(
|
|
296
358
|
view.bandDetail ? 0 : 3,
|
|
297
359
|
button({ key: 'band-detail', label: view.bandDetail ? '1 row' : '2 rows', onPress: actions.toggleDetail }),
|
|
298
360
|
),
|
|
299
361
|
].filter(Boolean);
|
|
362
|
+
if (!routing) return rest;
|
|
363
|
+
const named = [pins(true), ...rest];
|
|
364
|
+
return Number.isFinite(columns) && lineWidth(named, GAP) > columns ? [pins(false), ...rest] : named;
|
|
300
365
|
}
|
|
301
366
|
|
|
302
|
-
// A subagent's model and
|
|
303
|
-
//
|
|
367
|
+
// A subagent's model and how it was chosen: "agent ■ Haiku 5.5 ↓ from Sonnet 5.5 (Claude Code’s pick)". The square is
|
|
368
|
+
// filled when the router moved it off Claude Code's pick, as the Usage tab's squares show it.
|
|
304
369
|
function agentParts(agent, columns) {
|
|
305
370
|
const color = modelColor(agent.routedModel);
|
|
306
371
|
const moved = !agent.pass && agent.move;
|
|
307
|
-
const name = part(`${moved ? '■' : '□'} ${modelName(agent.routedModel)}`,
|
|
372
|
+
const name = part(`${moved ? '■' : '□'} ${modelName(agent.routedModel)}`, {
|
|
373
|
+
bold: true,
|
|
374
|
+
...(color ? { color } : {}),
|
|
375
|
+
});
|
|
376
|
+
const glyph = { up: '↑', down: '↓' }[agent.move] ?? '↕';
|
|
308
377
|
const why = agent.pass
|
|
309
|
-
?
|
|
378
|
+
? `= Claude Code’s pick: ${PASS_WHY[agent.pass]}`
|
|
310
379
|
: moved
|
|
311
|
-
?
|
|
380
|
+
? `${glyph} from ${modelName(agent.coreModel)} (Claude Code’s pick)`
|
|
312
381
|
: agent.choice === 'core'
|
|
313
|
-
?
|
|
314
|
-
: '
|
|
315
|
-
const parts = [
|
|
316
|
-
|
|
317
|
-
const width = parts.reduce((sum, p) => sum + p.text.length, 0) + pick.text.length;
|
|
318
|
-
return moved && agent.coreModel && !(Number.isFinite(columns) && width > columns) ? [...parts, pick] : parts;
|
|
382
|
+
? `= Claude Code’s pick: ${agent.failed ? 'classifier did not answer' : 'the router sent no model'}`
|
|
383
|
+
: '= Claude Code’s pick, kept by the router';
|
|
384
|
+
const parts = [dim('agent '), name, dim(` ${why}`)];
|
|
385
|
+
return Number.isFinite(columns) && partsWidth(parts) > columns ? parts.slice(0, 2) : parts;
|
|
319
386
|
}
|
|
320
387
|
|
|
321
|
-
export function renderBand(
|
|
388
|
+
export function renderBand(
|
|
389
|
+
{ Box, Text, Button },
|
|
390
|
+
config,
|
|
391
|
+
view,
|
|
392
|
+
usage,
|
|
393
|
+
{ columns, agentId, agent = null, now = Date.now() },
|
|
394
|
+
actions,
|
|
395
|
+
) {
|
|
322
396
|
const draw = (p) => (p.button ? Button(p.button) : Text({ ...p.style, children: p.text }));
|
|
323
397
|
const row = (parts) => Box({ children: parts.map(draw) });
|
|
324
398
|
// A subagent's model is chosen once, at spawn, and never changes between its steps. Without its record (routing
|
|
@@ -328,25 +402,34 @@ export function renderBand({ Box, Text, Button }, config, view, usage, { columns
|
|
|
328
402
|
agent
|
|
329
403
|
? agentParts(agent, columns)
|
|
330
404
|
: [
|
|
331
|
-
|
|
405
|
+
dim(
|
|
332
406
|
config.subagentRouting === 'on'
|
|
333
|
-
? '
|
|
334
|
-
: '
|
|
335
|
-
{ dimColor: true },
|
|
407
|
+
? 'agent · model chosen at spawn'
|
|
408
|
+
: 'agent · keeps its own model (subagent routing off)',
|
|
336
409
|
),
|
|
337
410
|
],
|
|
338
411
|
);
|
|
339
|
-
const
|
|
340
|
-
const
|
|
412
|
+
const width = Number.isFinite(columns) ? Math.max(0, columns - ROUTER_BUTTON) : columns;
|
|
413
|
+
const kept = fitSegments(bandSegments(config, view, usage, actions), width);
|
|
414
|
+
const join = (segs) => segs.flatMap((s, i) => (i ? [part(SEPARATOR), ...s.parts] : s.parts));
|
|
415
|
+
const left = join(kept.filter((s) => !s.right));
|
|
416
|
+
const end = join(kept.filter((s) => s.right));
|
|
417
|
+
const pad = end.length
|
|
418
|
+
? Number.isFinite(width)
|
|
419
|
+
? Math.max(SEPARATOR.length, width - partsWidth(left) - partsWidth(end))
|
|
420
|
+
: SEPARATOR.length
|
|
421
|
+
: 0;
|
|
422
|
+
const line = [...left, ...(pad ? [part(' '.repeat(pad))] : []), ...end];
|
|
341
423
|
line.push(part(' '), button({ key: 'details', label: 'Router', plain: true, onPress: actions.open }));
|
|
342
424
|
const routing = view.mode === 'auto' && view.phase !== 'unavailable';
|
|
343
|
-
const
|
|
425
|
+
const second = view.bandDetail ? sessionRow(config, view, usage, columns, now) : [];
|
|
426
|
+
const hover = fitSegments(hoverSegments(config, view, actions, routing, columns), columns, GAP);
|
|
344
427
|
return Box({
|
|
345
428
|
key: 'router-band',
|
|
346
429
|
flexDirection: 'column',
|
|
347
430
|
children: [
|
|
348
431
|
row(line),
|
|
349
|
-
|
|
432
|
+
second.length ? row(second) : null,
|
|
350
433
|
Box({
|
|
351
434
|
display: 'none',
|
|
352
435
|
hover: { display: 'flex' },
|
|
@@ -359,7 +442,7 @@ export function renderBand({ Box, Text, Button }, config, view, usage, { columns
|
|
|
359
442
|
export function switchToast(config, previous, next, estimate) {
|
|
360
443
|
const label = (decision) => routeLabel(decision.model, decision.effort);
|
|
361
444
|
const support = supportText(config, estimate);
|
|
362
|
-
//
|
|
363
|
-
const why = shortReason(next.reason, next.activity)
|
|
445
|
+
// "Model changed: Sonnet 5.5 · medium → Haiku 5.5 · high · ↓ ops"
|
|
446
|
+
const why = shortReason(next.reason, next.activity);
|
|
364
447
|
return `Model changed: ${label(previous)} → ${label(next)} · ${why}${support ? ` (${support})` : ''}`;
|
|
365
448
|
}
|