@alexeiled/claude-router 1.24.0 → 1.25.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 +44 -0
- package/README.md +39 -7
- package/docs/architecture.md +27 -4
- package/docs/configuration.md +23 -14
- package/docs/evaluation.md +3 -3
- package/docs/native-router.md +11 -3
- package/docs/router-band.svg +124 -133
- package/docs/router-pane-classifier.svg +24 -23
- package/docs/router-pane-now.svg +9 -7
- package/docs/router-pane-policy.svg +4 -4
- package/docs/router-pane-routes.svg +8 -8
- package/docs/router-pane-usage-whatif.svg +14 -14
- package/docs/router-pane-usage.svg +20 -20
- package/docs/routing-modes.md +10 -8
- package/docs/user-guide.md +70 -17
- package/hooks/native-router.mjs +333 -80
- package/lib/activity-stats.mjs +23 -4
- package/lib/activity.mjs +7 -5
- package/lib/auto-engine.mjs +13 -6
- package/lib/auto-route.mjs +10 -4
- package/lib/band.mjs +35 -440
- package/lib/classifier-client.mjs +12 -8
- package/lib/config-file.mjs +7 -2
- package/lib/config.mjs +24 -9
- package/lib/cost.mjs +5 -1
- package/lib/costs.mjs +4 -2
- package/lib/decisions.mjs +13 -9
- package/lib/display.mjs +69 -20
- package/lib/facts.mjs +3 -0
- package/lib/modes.mjs +8 -4
- package/lib/panel.mjs +75 -2167
- package/lib/policy.mjs +7 -6
- package/lib/replay-trace.mjs +5 -2
- package/lib/replay.mjs +7 -1
- package/lib/route-line.mjs +46 -0
- package/lib/route.mjs +21 -16
- package/lib/savings.mjs +14 -3
- package/lib/subagents.mjs +41 -11
- package/lib/subcommands.mjs +60 -0
- package/lib/ui/fallback.mjs +22 -0
- package/lib/ui/graphical/band.mjs +256 -0
- package/lib/ui/graphical/charts.mjs +163 -0
- package/lib/ui/graphical/classifier.mjs +153 -0
- package/lib/ui/graphical/frame.mjs +227 -0
- package/lib/ui/graphical/kit.mjs +156 -0
- package/lib/ui/graphical/meter.mjs +25 -0
- package/lib/ui/graphical/now.mjs +353 -0
- package/lib/ui/graphical/policy.mjs +56 -0
- package/lib/ui/graphical/routes.mjs +264 -0
- package/lib/ui/graphical/squares.mjs +29 -0
- package/lib/ui/graphical/usage.mjs +376 -0
- package/lib/ui/model/band.mjs +439 -0
- package/lib/ui/model/classifier.mjs +308 -0
- package/lib/ui/model/draft.mjs +62 -0
- package/lib/ui/model/format.mjs +41 -0
- package/lib/ui/model/frame.mjs +359 -0
- package/lib/ui/model/now.mjs +390 -0
- package/lib/ui/model/policy.mjs +194 -0
- package/lib/ui/model/routes.mjs +392 -0
- package/lib/ui/model/usage-agents.mjs +311 -0
- package/lib/ui/model/usage-breakdown.mjs +237 -0
- package/lib/ui/model/usage-shared.mjs +58 -0
- package/lib/ui/model/usage.mjs +330 -0
- package/lib/ui/terminal/band.mjs +220 -0
- package/lib/ui/terminal/classifier.mjs +142 -0
- package/lib/ui/terminal/frame.mjs +169 -0
- package/lib/ui/terminal/kit.mjs +133 -0
- package/lib/ui/terminal/now.mjs +300 -0
- package/lib/ui/terminal/policy.mjs +52 -0
- package/lib/ui/terminal/routes.mjs +167 -0
- package/lib/ui/terminal/usage.mjs +363 -0
- package/lib/ui/terminal/wrap.mjs +37 -0
- package/lib/ui/tokens.mjs +106 -0
- package/lib/usage.mjs +5 -5
- package/lib/view.mjs +5 -2
- package/package.json +3 -2
- package/types/index.d.ts +15 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { activeClassifier, TIERS } from '../../config.mjs';
|
|
2
|
+
import { resetText } from '../../costs.mjs';
|
|
3
|
+
import {
|
|
4
|
+
API_ESTIMATE,
|
|
5
|
+
baselineName,
|
|
6
|
+
classifierLabel,
|
|
7
|
+
classifierStatus,
|
|
8
|
+
classifierWarns,
|
|
9
|
+
costText,
|
|
10
|
+
diffText,
|
|
11
|
+
modeLever,
|
|
12
|
+
modelName,
|
|
13
|
+
NOT_A_TIER_REASON,
|
|
14
|
+
percentPair,
|
|
15
|
+
pinCard,
|
|
16
|
+
pinShort,
|
|
17
|
+
reasonActivity,
|
|
18
|
+
reasonNamesActivity,
|
|
19
|
+
repliesText,
|
|
20
|
+
routingModeOf,
|
|
21
|
+
sessionCost,
|
|
22
|
+
sessionUsage,
|
|
23
|
+
shortReason,
|
|
24
|
+
tierBars,
|
|
25
|
+
unavailableReason,
|
|
26
|
+
usageMetrics,
|
|
27
|
+
usd,
|
|
28
|
+
} from '../../display.mjs';
|
|
29
|
+
import { isSameModel } from '../../route.mjs';
|
|
30
|
+
import { PASS_WHY } from '../../subagents.mjs';
|
|
31
|
+
import { isRouting } from '../../view.mjs';
|
|
32
|
+
import { limitTone, modelTone, savingTone } from '../tokens.mjs';
|
|
33
|
+
|
|
34
|
+
// Groups on a row sit apart by space alone: the meter, colours and glyphs already separate them.
|
|
35
|
+
export const SEPARATOR = ' ';
|
|
36
|
+
// Cells in the band's gauges: the context window and a plan window.
|
|
37
|
+
const CONTEXT_CELLS = 5;
|
|
38
|
+
const PLAN_CELLS = 8;
|
|
39
|
+
// The tier meter's bars, as many cells wide as it is drawn on the terminal.
|
|
40
|
+
const METER_CELLS = 4;
|
|
41
|
+
// The pin Select's "no pin" choice.
|
|
42
|
+
export const NO_PIN = 'none';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One piece of a band segment: what it says and what it means, never how a surface draws it. A terminal maps `tone` to
|
|
46
|
+
* a colour and `gauge` and `meter` to glyphs; a graphical surface draws the same as theme colours, a figure and an Svg.
|
|
47
|
+
* @typedef {object} Part
|
|
48
|
+
* @property {string} [text]
|
|
49
|
+
* @property {import('../tokens.mjs').Tone} [tone] what the text means
|
|
50
|
+
* @property {boolean} [dim] secondary text
|
|
51
|
+
* @property {'semibold'} [weight]
|
|
52
|
+
* @property {boolean} [italic]
|
|
53
|
+
* @property {boolean} [chip] drawn as a label on a ground
|
|
54
|
+
* @property {number} [gauge] a gauge at this percent, `cells` wide on the terminal
|
|
55
|
+
* @property {number} [cells]
|
|
56
|
+
* @property {import('../tokens.mjs').Tier | 'off' | 'pending'} [meter] the tier meter: lit to the tier, off, or working
|
|
57
|
+
* @property {object} [button] a Button's props
|
|
58
|
+
* @property {number} [priority] 0 never drops
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export const part = (text, props = {}) => ({ text, ...props });
|
|
62
|
+
export const dim = (text) => part(text, { dim: true });
|
|
63
|
+
export const button = (props) => ({ button: props });
|
|
64
|
+
const gauge = (percent, cells, tone) => ({ gauge: percent, cells, tone });
|
|
65
|
+
// `priority` 0 never drops; higher numbers drop first when the band is narrow. `right` segments sit at the row's end.
|
|
66
|
+
export const segment = (priority, ...parts) => ({ priority, parts: parts.flat().filter(Boolean) });
|
|
67
|
+
export const right = (seg) => ({ ...seg, right: true });
|
|
68
|
+
// The columns a part takes on the terminal, which both surfaces fit the band by. A Button is its label in `[ ` and ` ]`
|
|
69
|
+
// unless it is plain.
|
|
70
|
+
const partWidth = (p) =>
|
|
71
|
+
p.meter
|
|
72
|
+
? METER_CELLS
|
|
73
|
+
: p.gauge !== undefined
|
|
74
|
+
? p.cells
|
|
75
|
+
: p.button
|
|
76
|
+
? p.button.label.length + (p.button.plain ? 0 : 4)
|
|
77
|
+
: p.text.length;
|
|
78
|
+
export const partsWidth = (parts) => parts.reduce((n, p) => n + partWidth(p), 0);
|
|
79
|
+
export const lineWidth = (segments, separator) =>
|
|
80
|
+
segments.reduce((sum, s, i) => sum + (i ? separator.length : 0) + partsWidth(s.parts), 0);
|
|
81
|
+
|
|
82
|
+
// Drops the highest-priority segments and parts, later ones first on a tie, until the line fits `columns`. If the
|
|
83
|
+
// priority-0 segments alone are too wide, the later ones go too, and the first is cut with an ellipsis: Ink would
|
|
84
|
+
// otherwise shrink every Text in the row and garble it. A width that is not a finite number fits everything.
|
|
85
|
+
export function fitSegments(segments, columns, separator = SEPARATOR) {
|
|
86
|
+
if (!Number.isFinite(columns)) return segments;
|
|
87
|
+
const kept = [...segments];
|
|
88
|
+
while (lineWidth(kept, separator) > columns) {
|
|
89
|
+
/** @type {{ priority: number, i: number, j?: number } | null} */
|
|
90
|
+
let drop = null;
|
|
91
|
+
for (const [i, s] of kept.entries()) {
|
|
92
|
+
for (const [j, p] of s.parts.entries()) {
|
|
93
|
+
if (p.priority > 0 && (!drop || p.priority >= drop.priority)) drop = { priority: p.priority, i, j };
|
|
94
|
+
}
|
|
95
|
+
if (kept.length > 1 && s.priority > 0 && (!drop || s.priority >= drop.priority))
|
|
96
|
+
drop = { priority: s.priority, i };
|
|
97
|
+
}
|
|
98
|
+
const dropped = drop;
|
|
99
|
+
if (dropped?.j !== undefined)
|
|
100
|
+
kept[dropped.i] = { ...kept[dropped.i], parts: kept[dropped.i].parts.filter((_, j) => j !== dropped.j) };
|
|
101
|
+
else if (dropped) kept.splice(dropped.i, 1);
|
|
102
|
+
else if (kept.length > 1) kept.pop();
|
|
103
|
+
else break;
|
|
104
|
+
}
|
|
105
|
+
const overflow = lineWidth(kept, separator) - columns;
|
|
106
|
+
if (overflow > 0 && kept.length) {
|
|
107
|
+
const parts = [...kept[0].parts];
|
|
108
|
+
const last = parts.findLastIndex((p) => p.text?.length > overflow);
|
|
109
|
+
if (last >= 0) parts[last] = { ...parts[last], text: `${parts[last].text.slice(0, -overflow - 1)}…` };
|
|
110
|
+
kept[0] = { ...kept[0], parts };
|
|
111
|
+
}
|
|
112
|
+
return kept;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Signal-strength bars: lit up to the tier, dim above it, or all dim when off.
|
|
116
|
+
const meter = (tier) => ({ meter: tier ?? 'off' });
|
|
117
|
+
|
|
118
|
+
// The classifier is working: every bar in the accent tone.
|
|
119
|
+
const pendingMeter = () => ({ meter: 'pending' });
|
|
120
|
+
|
|
121
|
+
// "Haiku 5.5 · high", the model in bold so the eye finds it first.
|
|
122
|
+
const routeParts = (model, effort) => [
|
|
123
|
+
part(modelName(model), { weight: 'semibold' }),
|
|
124
|
+
effort === null || effort === undefined ? null : part(` · ${effort}`),
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
function served(view) {
|
|
128
|
+
const { actualModel: actual, selectedModel: selected } = view;
|
|
129
|
+
return Boolean(actual && selected && !isSameModel(selected, actual));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// "Jev 93% ≥ 90%": the classifier's support for the switch the policy weighed, against the bar it set.
|
|
133
|
+
export function supportText(config, estimate) {
|
|
134
|
+
if (!Number.isFinite(estimate?.threshold)) return null;
|
|
135
|
+
const mass = Number.isFinite(estimate.upgradeMass) ? estimate.upgradeMass : estimate.downgradeMass;
|
|
136
|
+
if (!Number.isFinite(mass)) return null;
|
|
137
|
+
const [shown, bar] = percentPair(mass, estimate.threshold);
|
|
138
|
+
return `${classifierLabel(config)} ${shown} ${mass >= estimate.threshold ? '≥' : '<'} ${bar}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// The routing mode as a chip, only when it is not balanced: "cost", or "cost effort only" when the mode kept the model.
|
|
142
|
+
function modeChip(config, view) {
|
|
143
|
+
const { mode } = routingModeOf(view);
|
|
144
|
+
if (mode === 'balanced') return null;
|
|
145
|
+
const lever = modeLever(config, view);
|
|
146
|
+
return segment(5, part(` ${mode} `, { chip: true, tone: 'muted' }), lever ? dim(` ${lever}`) : null);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Context fill and the last reply's cache reuse, kept at the row's end so they stay in one place turn after turn.
|
|
150
|
+
function gauges(config, view, usage) {
|
|
151
|
+
const metrics = usageMetrics(config, view, usage);
|
|
152
|
+
const out = [];
|
|
153
|
+
if (metrics.contextBar.percent !== null) {
|
|
154
|
+
const { percent, tone } = metrics.contextBar;
|
|
155
|
+
out.push(right(segment(3, dim('ctx '), gauge(percent, CONTEXT_CELLS, tone), part(` ${percent}%`, { tone }))));
|
|
156
|
+
}
|
|
157
|
+
if (metrics.cacheBar.percent !== null)
|
|
158
|
+
out.push(
|
|
159
|
+
right(
|
|
160
|
+
segment(4, dim('cache '), part(`${metrics.cacheBar.percent}%`, { tone: metrics.cacheBar.tone }), dim(' last')),
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function bandSegments(config, view, usage, actions) {
|
|
167
|
+
const native = () => routeParts(view.nativeModel, view.nativeEffort);
|
|
168
|
+
if (view.phase === 'unavailable')
|
|
169
|
+
return [
|
|
170
|
+
segment(
|
|
171
|
+
0,
|
|
172
|
+
part('✕ ', { tone: 'danger' }),
|
|
173
|
+
native(),
|
|
174
|
+
part(' '),
|
|
175
|
+
button({ key: 'band-fix', label: 'Fix', onPress: actions.open }),
|
|
176
|
+
),
|
|
177
|
+
segment(1, part('routing unavailable', { tone: 'danger' })),
|
|
178
|
+
segment(3, part(unavailableReason(view), { tone: 'danger', dim: true })),
|
|
179
|
+
];
|
|
180
|
+
// Turn on shares the first segment, which never drops and whose cut keeps buttons whole, so the band's one way back
|
|
181
|
+
// on survives any width.
|
|
182
|
+
if (view.mode === 'manual')
|
|
183
|
+
return [
|
|
184
|
+
segment(
|
|
185
|
+
0,
|
|
186
|
+
dim('○ '),
|
|
187
|
+
native(),
|
|
188
|
+
part(' '),
|
|
189
|
+
button({ key: 'band-auto', label: 'Turn on', variant: 'primary', onPress: () => actions.mode('auto') }),
|
|
190
|
+
),
|
|
191
|
+
segment(1, dim(`routing off${view.reason === 'model selected manually' ? ' · /model' : ''}`)),
|
|
192
|
+
view.reason === NOT_A_TIER_REASON ? segment(2, dim('not a routing tier')) : null,
|
|
193
|
+
].filter(Boolean);
|
|
194
|
+
if (view.phase === 'choosing')
|
|
195
|
+
return [
|
|
196
|
+
segment(0, pendingMeter(), dim(' choosing…')),
|
|
197
|
+
segment(3, dim(`${classifierLabel(config)} ≤ ${activeClassifier(config).timeoutMs / 1000} s`)),
|
|
198
|
+
];
|
|
199
|
+
const pin = view.pendingPin
|
|
200
|
+
? segment(
|
|
201
|
+
0,
|
|
202
|
+
part('⏵ next ', { tone: 'accent' }),
|
|
203
|
+
part(tierBars(view.pendingPin), { tone: `tier:${view.pendingPin}` }),
|
|
204
|
+
part(pinShort(config, view.pendingPin) && ` ${pinShort(config, view.pendingPin)}`, {
|
|
205
|
+
tone: `tier:${view.pendingPin}`,
|
|
206
|
+
}),
|
|
207
|
+
part(' '),
|
|
208
|
+
button({ key: 'band-unpin', label: '✕', plain: true, onPress: actions.unpin }),
|
|
209
|
+
)
|
|
210
|
+
: null;
|
|
211
|
+
if (!view.tier && view.phase === 'ready' && !view.actualModel)
|
|
212
|
+
return [segment(0, meter(null), part(' '), native()), segment(1, dim('ready')), pin, modeChip(config, view)].filter(
|
|
213
|
+
Boolean,
|
|
214
|
+
);
|
|
215
|
+
const main = segment(
|
|
216
|
+
0,
|
|
217
|
+
view.tier ? meter(view.tier) : dim('○'),
|
|
218
|
+
part(' '),
|
|
219
|
+
routeParts(view.actualModel ?? view.selectedModel ?? view.nativeModel, view.effort),
|
|
220
|
+
served(view) ? part(' fallback', { tone: 'warning' }) : null,
|
|
221
|
+
);
|
|
222
|
+
const activityText = view.goal
|
|
223
|
+
? `${view.goal}${view.taskPhase ? ` / ${view.taskPhase}` : ''}${view.activity && view.activity !== view.goal ? ` → ${view.activity}` : ''}`
|
|
224
|
+
: view.activity;
|
|
225
|
+
const activity =
|
|
226
|
+
activityText &&
|
|
227
|
+
config.activityRouting !== 'off' &&
|
|
228
|
+
((view.goal && (view.taskPhase || view.goal !== view.activity)) || !reasonNamesActivity(view.reason))
|
|
229
|
+
? segment(2, part(activityText, { tone: 'activity', italic: true }))
|
|
230
|
+
: null;
|
|
231
|
+
const reason = segment(1, dim(shortReason(view.reason, reasonActivity(config, view))));
|
|
232
|
+
// The warning leads and the route yields: when the band is narrow, what to fix matters more than the model kept.
|
|
233
|
+
if (classifierWarns(view.error))
|
|
234
|
+
return [
|
|
235
|
+
segment(0, part(`⚠ ${classifierStatus(config, view.error)}`, { tone: 'warning' })),
|
|
236
|
+
view.error === 'missing-key' || view.error === 'missing-account'
|
|
237
|
+
? segment(0, button({ key: 'band-key', label: 'Set up', variant: 'primary', onPress: actions.key }))
|
|
238
|
+
: segment(2, button({ key: 'band-fix', label: 'Details', onPress: actions.open })),
|
|
239
|
+
{ ...main, priority: 1 },
|
|
240
|
+
pin,
|
|
241
|
+
{ ...reason, priority: 3 },
|
|
242
|
+
].filter(Boolean);
|
|
243
|
+
const support = supportText(config, view.estimate);
|
|
244
|
+
// The policy's price for the switch it weighed: mostly the prompt cache the other model must write.
|
|
245
|
+
const switchUsd = view.estimate?.taxUsd;
|
|
246
|
+
return [
|
|
247
|
+
main,
|
|
248
|
+
activity,
|
|
249
|
+
pin,
|
|
250
|
+
reason,
|
|
251
|
+
modeChip(config, view),
|
|
252
|
+
support ? segment(6, dim(support)) : null,
|
|
253
|
+
Number.isFinite(switchUsd) && switchUsd >= 0.005 ? segment(6, dim(`switch ≈ ${usd(switchUsd)}`)) : null,
|
|
254
|
+
...gauges(config, view, usage),
|
|
255
|
+
].filter(Boolean);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// The second row: the plan windows on a Claude plan, then this session's cost with its subagents, and how it compares
|
|
259
|
+
// with your /model (or `unrouted` with subagents):
|
|
260
|
+
// "plan 5h ▰▰▰▱▱▱▱▱ 37% ↻17:00 7d 62% session ≈$7.60 API estimate −$1.76 (−19%) vs Sonnet 5.5 24 replies".
|
|
261
|
+
// An effort-only profile shows its effort mix instead of a saving. When the band is narrow the reset time, the
|
|
262
|
+
// counts and the words go first; the 5h window and the session total stay.
|
|
263
|
+
export function sessionSegments(config, view, usage, now = Date.now()) {
|
|
264
|
+
const cost = sessionCost(config, view, usage, now);
|
|
265
|
+
const out = [];
|
|
266
|
+
for (const limit of cost.limits) {
|
|
267
|
+
const tone = limitTone(limit.percent);
|
|
268
|
+
if (limit.kind === 'five_hour') {
|
|
269
|
+
const reset = resetText(limit.resetsAt, now);
|
|
270
|
+
out.push(
|
|
271
|
+
segment(
|
|
272
|
+
0,
|
|
273
|
+
dim('plan 5h '),
|
|
274
|
+
gauge(limit.percent, PLAN_CELLS, tone),
|
|
275
|
+
part(` ${limit.percent}%`, { tone }),
|
|
276
|
+
reset ? { ...dim(` ↻${reset}`), priority: 4 } : null,
|
|
277
|
+
),
|
|
278
|
+
);
|
|
279
|
+
} else out.push(segment(3, dim(`${limit.label} `), part(`${limit.percent}%`, { tone })));
|
|
280
|
+
}
|
|
281
|
+
if (!isRouting(view)) return out.filter(Boolean);
|
|
282
|
+
if (!cost.replies && !cost.agents) return [...out, segment(2, dim('session · no replies yet'))].filter(Boolean);
|
|
283
|
+
out.push(
|
|
284
|
+
segment(0, dim('session '), part(costText(cost.totalUsd, cost.billing), { weight: 'semibold' }), {
|
|
285
|
+
...dim(` ${API_ESTIMATE}`),
|
|
286
|
+
priority: 5,
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
if (cost.billing === 'mixed') out.push(segment(1, part(`credits ${costText(cost.creditsUsd, cost.billing)}`)));
|
|
290
|
+
if (cost.effortOnly && cost.effortMix.length)
|
|
291
|
+
out.push(segment(2, dim('effort '), part(cost.effortMix.map(([effort, n]) => `${effort} ${n}`).join(' · '))));
|
|
292
|
+
else if (cost.diffUsd !== null)
|
|
293
|
+
out.push(
|
|
294
|
+
segment(
|
|
295
|
+
1,
|
|
296
|
+
part(diffText(cost.diffUsd, cost.baseUsd), {
|
|
297
|
+
weight: 'semibold',
|
|
298
|
+
...(cost.diffUsd ? { tone: savingTone(cost.diffUsd) } : {}),
|
|
299
|
+
}),
|
|
300
|
+
dim(` vs ${baselineName(view, sessionUsage(view, now), cost)}`),
|
|
301
|
+
),
|
|
302
|
+
);
|
|
303
|
+
else if (cost.uncomparedReplies)
|
|
304
|
+
out.push(
|
|
305
|
+
segment(
|
|
306
|
+
2,
|
|
307
|
+
dim(
|
|
308
|
+
cost.uncomparedReplies === cost.replies
|
|
309
|
+
? 'not compared'
|
|
310
|
+
: `${cost.uncomparedReplies} of ${cost.replies} not compared`,
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
);
|
|
314
|
+
out.push(
|
|
315
|
+
segment(
|
|
316
|
+
6,
|
|
317
|
+
dim(`${repliesText(cost)}${cost.agents > 0 ? ` · ${cost.agents} agent${cost.agents === 1 ? '' : 's'}` : ''}`),
|
|
318
|
+
),
|
|
319
|
+
);
|
|
320
|
+
return out.filter(Boolean);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// The route line under a turn: "▂▄▆█ Sonnet 5.5 · high ↓ cheaper fits code Jev 93% ≥ 90%", the band's words for the
|
|
324
|
+
// route that ran. Narrow, the support goes first, then the activity, then the reason; the route stays.
|
|
325
|
+
export function routeLineSegments(config, line) {
|
|
326
|
+
const support = supportText(config, line.estimate);
|
|
327
|
+
const activity =
|
|
328
|
+
line.activity && config.activityRouting !== 'off' && !reasonNamesActivity(line.reason) ? line.activity : null;
|
|
329
|
+
return [
|
|
330
|
+
segment(0, line.tier ? meter(line.tier) : dim('○'), part(' '), routeParts(line.model, line.effort)),
|
|
331
|
+
segment(1, dim(shortReason(line.reason, line.reasonActivity))),
|
|
332
|
+
activity ? segment(2, part(activity, { tone: 'activity', italic: true })) : null,
|
|
333
|
+
support ? segment(3, dim(support)) : null,
|
|
334
|
+
].filter(Boolean);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// A subagent's model and how it was chosen: "agent ■ Haiku 5.5 ↓ from Sonnet 5.5 (Claude Code’s pick)". The square is
|
|
338
|
+
// filled when the router moved it off Claude Code's pick, as the Usage tab's squares show it. A band too narrow for the
|
|
339
|
+
// reason keeps the name. Without its record (routing off, or the router reloaded since the spawn) only the mode is
|
|
340
|
+
// known: a subagent's model is chosen once, at spawn, and never changes between its steps.
|
|
341
|
+
export function agentParts(config, agent, columns) {
|
|
342
|
+
if (!agent)
|
|
343
|
+
return [
|
|
344
|
+
dim(
|
|
345
|
+
config.subagentRouting === 'on'
|
|
346
|
+
? 'agent · model chosen at spawn'
|
|
347
|
+
: 'agent · keeps its own model (subagent routing off)',
|
|
348
|
+
),
|
|
349
|
+
];
|
|
350
|
+
const moved = !agent.pass && agent.move;
|
|
351
|
+
const name = part(`${moved ? '■' : '□'} ${modelName(agent.routedModel)}`, {
|
|
352
|
+
weight: 'semibold',
|
|
353
|
+
tone: modelTone(agent.routedModel),
|
|
354
|
+
});
|
|
355
|
+
const glyph = { up: '↑', down: '↓' }[agent.move] ?? '↕';
|
|
356
|
+
const why = agent.pass
|
|
357
|
+
? `= Claude Code’s pick: ${PASS_WHY[agent.pass]}`
|
|
358
|
+
: moved
|
|
359
|
+
? `${glyph} from ${modelName(agent.coreModel)} (Claude Code’s pick)`
|
|
360
|
+
: agent.choice === 'core'
|
|
361
|
+
? `= Claude Code’s pick: ${agent.failed ? 'classifier did not answer' : 'the router sent no model'}`
|
|
362
|
+
: '= Claude Code’s pick, kept by the router';
|
|
363
|
+
const parts = [dim('agent '), name, dim(` ${why}`)];
|
|
364
|
+
return Number.isFinite(columns) && partsWidth(parts) > columns ? parts.slice(0, 2) : parts;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Most agents the band lists before it says how many more.
|
|
368
|
+
export const MAX_AGENT_ROWS = 3;
|
|
369
|
+
// The longest task description a row carries; the rest is cut with an ellipsis.
|
|
370
|
+
const AGENT_TASK_CELLS = 24;
|
|
371
|
+
// The Back control of an agent's band, and the room it takes with the gap after it.
|
|
372
|
+
export const BACK_LABEL = '◂ main';
|
|
373
|
+
export const BACK_CELLS = BACK_LABEL.length + SEPARATOR.length;
|
|
374
|
+
|
|
375
|
+
const taskText = (text) => (text.length > AGENT_TASK_CELLS ? `${text.slice(0, AGENT_TASK_CELLS - 1)}…` : text);
|
|
376
|
+
|
|
377
|
+
// One running agent as a row's label: "▸ ■ Haiku 5.5 Explore · retry usages ●". The square is filled when the router
|
|
378
|
+
// moved the agent off Claude Code's pick, as the Usage tab's squares show it; the dot says it is running. `detail` is how
|
|
379
|
+
// much is said: the task and model, the model, or the type alone.
|
|
380
|
+
function agentLabel(row, detail) {
|
|
381
|
+
const { record } = row;
|
|
382
|
+
const moved = record && !record.pass && record.move;
|
|
383
|
+
const model =
|
|
384
|
+
record?.routedModel && detail !== 'type' ? `${moved ? '■' : '□'} ${modelName(record.routedModel)} ` : '';
|
|
385
|
+
const task = detail === 'full' && row.description ? ` · ${taskText(row.description)}` : '';
|
|
386
|
+
return `▸ ${model}${row.type}${task} ●`;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The band's agents row: "agents 2 ▸ ■ Haiku 5.5 Explore · retry usages ● ▸ □ Sonnet 5.5 general-purpose ●". One
|
|
391
|
+
* Button per agent, up to MAX_AGENT_ROWS, then "+N". A row too wide for `columns` says less (the model, then the type
|
|
392
|
+
* alone), then lists the first agent and the count, then only the count. No running agent, no row.
|
|
393
|
+
* @param {{ id: string, type: string, description?: string, record?: any }[]} rows the agents running, in order
|
|
394
|
+
*/
|
|
395
|
+
export function agentSegments(rows, columns, actions) {
|
|
396
|
+
if (!rows.length) return [];
|
|
397
|
+
const build = (detail, shown) =>
|
|
398
|
+
[
|
|
399
|
+
segment(0, dim(`agents ${rows.length}`)),
|
|
400
|
+
...rows.slice(0, shown).map((row) =>
|
|
401
|
+
segment(
|
|
402
|
+
0,
|
|
403
|
+
button({
|
|
404
|
+
key: `band-agent-${row.id}`,
|
|
405
|
+
label: agentLabel(row, detail),
|
|
406
|
+
plain: true,
|
|
407
|
+
onPress: () => actions.viewAgent(row.id),
|
|
408
|
+
}),
|
|
409
|
+
),
|
|
410
|
+
),
|
|
411
|
+
rows.length > shown ? segment(0, dim(`+${rows.length - shown}`)) : null,
|
|
412
|
+
].filter(Boolean);
|
|
413
|
+
const fits = (segments) => !Number.isFinite(columns) || lineWidth(segments, SEPARATOR) <= columns;
|
|
414
|
+
const details = ['full', 'model', 'type'];
|
|
415
|
+
const listed = [Math.min(rows.length, MAX_AGENT_ROWS), 1];
|
|
416
|
+
for (const shown of new Set(listed))
|
|
417
|
+
for (const detail of details) {
|
|
418
|
+
const segments = build(detail, shown);
|
|
419
|
+
if (fits(segments)) return segments;
|
|
420
|
+
}
|
|
421
|
+
return [segment(0, dim(`agents ${rows.length}`))];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* The pin Select's data, or null where no pin is offered: not while routing is off, unavailable or choosing, nor while
|
|
426
|
+
* the classifier needs a fix.
|
|
427
|
+
* @returns {{ value: string, options: { value: string, label: string }[] } | null}
|
|
428
|
+
*/
|
|
429
|
+
export function pinOf(config, view) {
|
|
430
|
+
if (!isRouting(view) || view.phase === 'choosing' || classifierWarns(view.error)) return null;
|
|
431
|
+
const pending = view.pendingPin;
|
|
432
|
+
return {
|
|
433
|
+
value: pending ?? NO_PIN,
|
|
434
|
+
options: [
|
|
435
|
+
{ value: NO_PIN, label: pending ? 'No pin' : 'Pin next turn' },
|
|
436
|
+
...TIERS.map((tier) => ({ value: tier, label: pinCard(config, tier) })),
|
|
437
|
+
],
|
|
438
|
+
};
|
|
439
|
+
}
|