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