@alexeiled/claude-router 1.23.1 → 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 +62 -1
- package/README.md +39 -7
- package/docs/architecture.md +27 -4
- package/docs/auto-engine.md +152 -0
- package/docs/configuration.md +47 -3
- package/docs/evaluation.md +222 -3
- package/docs/native-router.md +11 -3
- package/docs/providers.md +28 -0
- 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 +13 -4
- package/docs/user-guide.md +79 -19
- package/hooks/native-router.mjs +1194 -215
- package/lib/activity-stats.mjs +23 -4
- package/lib/activity.mjs +7 -5
- package/lib/auto-engine.mjs +414 -0
- package/lib/auto-route.mjs +253 -0
- package/lib/band.mjs +35 -440
- package/lib/classifier-client.mjs +12 -8
- package/lib/config-file.mjs +7 -2
- package/lib/config.mjs +64 -15
- package/lib/cost.mjs +5 -1
- package/lib/costs.mjs +4 -2
- package/lib/decisions.mjs +80 -5
- package/lib/display.mjs +69 -20
- package/lib/facts.mjs +30 -0
- package/lib/modes.mjs +8 -4
- package/lib/panel.mjs +75 -2163
- package/lib/policy.mjs +7 -6
- package/lib/providers.mjs +7 -0
- package/lib/replay-trace.mjs +550 -0
- package/lib/replay.mjs +718 -0
- package/lib/route-line.mjs +46 -0
- package/lib/route.mjs +35 -21
- 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,353 @@
|
|
|
1
|
+
// The Now tab as cards for desktop, VS Code and mobile, drawn from the model in ui/model/now.mjs: Next turn; Plan usage
|
|
2
|
+
// and Context side by side when the pane is wide, stacked when narrow; This session; Recent decisions.
|
|
3
|
+
import { isFiniteNumber } from '../tokens.mjs';
|
|
4
|
+
|
|
5
|
+
// Two cards of label 10 + bar 10 + figure 7 + note + gaps, plus border and padding, need about 55 cells each.
|
|
6
|
+
const SIDE_BY_SIDE = 110;
|
|
7
|
+
|
|
8
|
+
// A reading's tone on a card: its own where it warns, else the card's ordinary one.
|
|
9
|
+
const alertOr = (name, ordinary) => (name === 'warning' || name === 'danger' ? name : ordinary);
|
|
10
|
+
|
|
11
|
+
// The routing mode as one label: "Cost mode from session · ... · /router mode default clears it".
|
|
12
|
+
const modeWords = (ui, mode) => (mode ? [ui.say(mode.from), mode.clear].filter(Boolean).join(' · ') : null);
|
|
13
|
+
|
|
14
|
+
const figure = (percent) => (Number.isFinite(percent) ? `${percent}%` : '—');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {any} ui the graphical kit
|
|
18
|
+
* @param {import('../model/now.mjs').NowModel} model
|
|
19
|
+
* @param {{ columns: number | null, now: number }} opts
|
|
20
|
+
*/
|
|
21
|
+
export function graphicalNow(ui, model, { columns, now }) {
|
|
22
|
+
const { Box } = ui;
|
|
23
|
+
const plan = planCard(ui, model.plan);
|
|
24
|
+
const context = contextCard(ui, model.context);
|
|
25
|
+
const half = (card) => Box({ width: '50%', flexGrow: 1, flexShrink: 1, flexDirection: 'column', children: [card] });
|
|
26
|
+
const pair = !plan
|
|
27
|
+
? context
|
|
28
|
+
: isFiniteNumber(columns) && columns >= SIDE_BY_SIDE
|
|
29
|
+
? Box({ flexDirection: 'row', gap: 'lg', alignItems: 'stretch', children: [half(plan), half(context)] })
|
|
30
|
+
: Box({ flexDirection: 'column', gap: 'lg', children: [plan, context] });
|
|
31
|
+
return [
|
|
32
|
+
Box({
|
|
33
|
+
flexDirection: 'column',
|
|
34
|
+
gap: 'lg',
|
|
35
|
+
children: [
|
|
36
|
+
nextCard(ui, model.next),
|
|
37
|
+
pair,
|
|
38
|
+
sessionCard(ui, model.session, columns, now),
|
|
39
|
+
model.decisions.length
|
|
40
|
+
? ui.section(
|
|
41
|
+
'Recent decisions',
|
|
42
|
+
{},
|
|
43
|
+
model.decisions.map((line) => ui.text(line, { size: 'footnote', mono: true, wrap: 'truncate-end' })),
|
|
44
|
+
)
|
|
45
|
+
: null,
|
|
46
|
+
].filter(Boolean),
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {any} ui
|
|
53
|
+
* @param {import('../model/now.mjs').NextModel} next
|
|
54
|
+
*/
|
|
55
|
+
// The tier meter and the route, the activity reading at the right, the why line, then the pins.
|
|
56
|
+
function nextCard(ui, next) {
|
|
57
|
+
const { Box } = ui;
|
|
58
|
+
const routed = next.state === 'routed';
|
|
59
|
+
const meter = ui.tierMeter(routed ? next.tier : null, routed && next.tier ? 'lit' : 'off');
|
|
60
|
+
const reading = routed ? next.reading : null;
|
|
61
|
+
const headline = Box({
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
flexWrap: 'nowrap',
|
|
64
|
+
alignItems: 'center',
|
|
65
|
+
justifyContent: 'space-between',
|
|
66
|
+
gap: 'md',
|
|
67
|
+
children: [
|
|
68
|
+
Box({
|
|
69
|
+
flexDirection: 'row',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
gap: 'sm',
|
|
72
|
+
flexShrink: 1,
|
|
73
|
+
overflow: 'hidden',
|
|
74
|
+
children: [
|
|
75
|
+
Box({ flexShrink: 0, children: [meter] }),
|
|
76
|
+
ui.text(next.label, { size: 'heading', weight: 'semibold', wrap: 'truncate-end' }),
|
|
77
|
+
],
|
|
78
|
+
}),
|
|
79
|
+
reading
|
|
80
|
+
? Box({
|
|
81
|
+
flexShrink: 0,
|
|
82
|
+
children: [
|
|
83
|
+
ui.text([reading.choice, reading.share].filter(Boolean).join(' '), {
|
|
84
|
+
size: 'footnote',
|
|
85
|
+
weight: 'medium',
|
|
86
|
+
tabular: true,
|
|
87
|
+
color: ui.color(reading.isActivity ? 'activity' : 'muted'),
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
})
|
|
91
|
+
: null,
|
|
92
|
+
].filter(Boolean),
|
|
93
|
+
});
|
|
94
|
+
if (!routed) {
|
|
95
|
+
const unavailable = next.state === 'unavailable';
|
|
96
|
+
return ui.section('Next turn', {}, [
|
|
97
|
+
Box({
|
|
98
|
+
flexDirection: 'column',
|
|
99
|
+
gap: 'xs',
|
|
100
|
+
children: [
|
|
101
|
+
headline,
|
|
102
|
+
unavailable
|
|
103
|
+
? ui.text(ui.say(next.note), { color: ui.color('warning'), wrap: 'truncate-end' })
|
|
104
|
+
: ui.muted(ui.say(next.note)),
|
|
105
|
+
ui.muted(ui.say(next.pin), { size: 'footnote' }),
|
|
106
|
+
],
|
|
107
|
+
}),
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
// The why, the classifier's support, an override and the routing mode fold into one wrapping line.
|
|
111
|
+
const why = [next.why, next.support, reading?.other, next.phase, next.override, modeWords(ui, next.mode)].filter(
|
|
112
|
+
Boolean,
|
|
113
|
+
);
|
|
114
|
+
return ui.section('Next turn', {}, [
|
|
115
|
+
Box({
|
|
116
|
+
flexDirection: 'column',
|
|
117
|
+
gap: 'xs',
|
|
118
|
+
children: [
|
|
119
|
+
headline,
|
|
120
|
+
next.tier
|
|
121
|
+
? why.length
|
|
122
|
+
? ui.muted(why.join(' · '), { tabular: true, wrap: 'wrap' })
|
|
123
|
+
: null
|
|
124
|
+
: ui.muted(next.firstTurn),
|
|
125
|
+
].filter(Boolean),
|
|
126
|
+
}),
|
|
127
|
+
Box({
|
|
128
|
+
flexDirection: 'column',
|
|
129
|
+
gap: 'sm',
|
|
130
|
+
children: [ui.muted('Pin next turn', { size: 'footnote' }), pinRow(ui, next)],
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {any} ui
|
|
137
|
+
* @param {import('../model/now.mjs').NextRoutedModel} next
|
|
138
|
+
*/
|
|
139
|
+
// The pins: per tier, its meter beside a Button named by its route, then its reading (`current` on the tier that runs
|
|
140
|
+
// now, the classifier's support). The meter stays outside the Button, which holds Text alone; only a pending pin is
|
|
141
|
+
// primary. A group may shrink, its label cut, so a long model name never makes it wider than the card.
|
|
142
|
+
function pinRow(ui, next) {
|
|
143
|
+
const { Box, Button } = ui;
|
|
144
|
+
return Box({
|
|
145
|
+
flexDirection: 'row',
|
|
146
|
+
flexWrap: 'wrap',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
justifyContent: 'flex-start',
|
|
149
|
+
gap: 'md',
|
|
150
|
+
children: next.pins.map((pin) =>
|
|
151
|
+
Box({
|
|
152
|
+
flexDirection: 'row',
|
|
153
|
+
alignItems: 'center',
|
|
154
|
+
gap: 'xs',
|
|
155
|
+
flexShrink: 1,
|
|
156
|
+
minWidth: 0,
|
|
157
|
+
children: [
|
|
158
|
+
Box({ flexShrink: 0, children: [ui.tierMeter(pin.tier, 'lit')] }),
|
|
159
|
+
Button({
|
|
160
|
+
key: `pin-${pin.tier}`,
|
|
161
|
+
label: ui.say(pin.route),
|
|
162
|
+
children: [ui.text(ui.say(pin.route), { wrap: 'truncate-end' })],
|
|
163
|
+
variant: next.pendingPin === pin.tier ? 'primary' : 'secondary',
|
|
164
|
+
onPress: () => next.pick(pin.tier),
|
|
165
|
+
}),
|
|
166
|
+
pin.reading ? ui.muted(pin.reading, { size: 'footnote', tabular: true }) : null,
|
|
167
|
+
].filter(Boolean),
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @param {any} ui
|
|
175
|
+
* @param {import('../model/now.mjs').NowModel['plan']} plan
|
|
176
|
+
*/
|
|
177
|
+
function planCard(ui, plan) {
|
|
178
|
+
if (!plan.length) return null;
|
|
179
|
+
return ui.section(
|
|
180
|
+
'Plan usage',
|
|
181
|
+
{},
|
|
182
|
+
plan.map((limit) =>
|
|
183
|
+
ui.meter({
|
|
184
|
+
label: limit.label,
|
|
185
|
+
value: limit.percent / 100,
|
|
186
|
+
tone: limit.tone,
|
|
187
|
+
text: figure(limit.percent),
|
|
188
|
+
caption: limit.reset ? `resets ${limit.reset}` : undefined,
|
|
189
|
+
}),
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {any} ui
|
|
196
|
+
* @param {import('../model/now.mjs').ContextModel} context
|
|
197
|
+
*/
|
|
198
|
+
function contextCard(ui, context) {
|
|
199
|
+
const { Box } = ui;
|
|
200
|
+
const toggle = ui.Button({
|
|
201
|
+
key: 'usage-detail',
|
|
202
|
+
label: context.detail.open ? 'Less' : 'Details',
|
|
203
|
+
variant: context.detail.open ? 'primary' : 'secondary',
|
|
204
|
+
onPress: context.detail.toggle,
|
|
205
|
+
});
|
|
206
|
+
const { cache } = context;
|
|
207
|
+
// The last reply's figure in the cache's tone, then its words; the session's after a muted dot.
|
|
208
|
+
const reuse = cache.last
|
|
209
|
+
? [
|
|
210
|
+
ui.text(cache.last.figure, { tabular: true, color: ui.color(alertOr(cache.tone, 'primary')) }),
|
|
211
|
+
ui.text(cache.last.words),
|
|
212
|
+
...(cache.session
|
|
213
|
+
? [ui.muted('·'), ui.text(cache.session.figure, { tabular: true }), ui.text(cache.session.words)]
|
|
214
|
+
: []),
|
|
215
|
+
]
|
|
216
|
+
: [ui.text(ui.say(cache.empty))];
|
|
217
|
+
return ui.section('Context', { action: toggle }, [
|
|
218
|
+
context.fill === null
|
|
219
|
+
? ui.muted(ui.say(context.empty))
|
|
220
|
+
: ui.meter({
|
|
221
|
+
label: 'Window',
|
|
222
|
+
value: context.fill / 100,
|
|
223
|
+
tone: alertOr(context.fillTone, 'accent'),
|
|
224
|
+
text: figure(context.fill),
|
|
225
|
+
caption: context.suffix,
|
|
226
|
+
}),
|
|
227
|
+
Box({
|
|
228
|
+
flexDirection: 'row',
|
|
229
|
+
flexWrap: 'nowrap',
|
|
230
|
+
alignItems: 'center',
|
|
231
|
+
gap: 'md',
|
|
232
|
+
children: [
|
|
233
|
+
Box({ width: 10, flexShrink: 0, children: [ui.muted('Cache')] }),
|
|
234
|
+
Box({
|
|
235
|
+
flexDirection: 'row',
|
|
236
|
+
alignItems: 'center',
|
|
237
|
+
gap: 'xs',
|
|
238
|
+
flexShrink: 1,
|
|
239
|
+
overflow: 'hidden',
|
|
240
|
+
children: reuse,
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
...(context.detail.open ? readingDetail(ui, context.detail) : []),
|
|
245
|
+
]);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param {any} ui
|
|
250
|
+
* @param {import('../model/now.mjs').ContextModel['detail']} detail
|
|
251
|
+
*/
|
|
252
|
+
// Behind Details: Claude's readings of the last reply, the input per reply as a trend, and the estimates the last
|
|
253
|
+
// decision weighed.
|
|
254
|
+
function readingDetail(ui, detail) {
|
|
255
|
+
const heading = (words) => ui.muted(words, { size: 'footnote', weight: 'semibold' });
|
|
256
|
+
return [
|
|
257
|
+
ui.muted(ui.say(detail.readings), { tabular: true, wrap: 'wrap' }),
|
|
258
|
+
heading(ui.say(detail.input)),
|
|
259
|
+
...(detail.chart
|
|
260
|
+
? [ui.trend(detail.chart), ui.muted(ui.say(detail.range), { tabular: true })]
|
|
261
|
+
: [ui.muted(ui.say(detail.empty))]),
|
|
262
|
+
heading(ui.say(detail.estimatesHead)),
|
|
263
|
+
...detail.estimates.map(([label, value]) => ui.field(label, [value])),
|
|
264
|
+
];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @param {any} ui
|
|
269
|
+
* @param {import('../model/now.mjs').SessionModel} session
|
|
270
|
+
* @param {number | null} columns
|
|
271
|
+
* @param {number} now
|
|
272
|
+
*/
|
|
273
|
+
// The total and how it is paid, the difference against no routing, the main thread and the subagents on one scale,
|
|
274
|
+
// then the replies by tier.
|
|
275
|
+
function sessionCard(ui, session, columns, now) {
|
|
276
|
+
const toggle = ui.Button({
|
|
277
|
+
key: 'band-detail-toggle',
|
|
278
|
+
label: ui.say(session.detailToggle),
|
|
279
|
+
onPress: session.toggleDetail,
|
|
280
|
+
});
|
|
281
|
+
const running = session.running
|
|
282
|
+
? ui.text(`● ${session.running} running`, { color: ui.color('warning'), size: 'footnote', tabular: true })
|
|
283
|
+
: null;
|
|
284
|
+
const strip = ui.strip(session.strip, { columns, now, since: session.since });
|
|
285
|
+
if (!session.priced)
|
|
286
|
+
return ui.section(
|
|
287
|
+
'This session',
|
|
288
|
+
{ hint: session.head || undefined, action: toggle },
|
|
289
|
+
[running, ui.muted(ui.say(session.empty)), strip].filter(Boolean),
|
|
290
|
+
);
|
|
291
|
+
const { Box } = ui;
|
|
292
|
+
const { diff, scale } = session;
|
|
293
|
+
return ui.section(
|
|
294
|
+
'This session',
|
|
295
|
+
{ hint: session.head || undefined, action: toggle },
|
|
296
|
+
[
|
|
297
|
+
Box({
|
|
298
|
+
flexDirection: 'row',
|
|
299
|
+
alignItems: 'flex-start',
|
|
300
|
+
justifyContent: 'space-between',
|
|
301
|
+
gap: 'md',
|
|
302
|
+
children: [
|
|
303
|
+
ui.stat({ value: session.total, caption: session.billing }),
|
|
304
|
+
Box({
|
|
305
|
+
flexDirection: 'row',
|
|
306
|
+
gap: 'sm',
|
|
307
|
+
alignItems: 'center',
|
|
308
|
+
flexShrink: 0,
|
|
309
|
+
children: [running, ui.Button({ key: 'usage-session', label: 'Usage', onPress: session.usage })].filter(
|
|
310
|
+
Boolean,
|
|
311
|
+
),
|
|
312
|
+
}),
|
|
313
|
+
],
|
|
314
|
+
}),
|
|
315
|
+
diff
|
|
316
|
+
? Box({
|
|
317
|
+
flexDirection: 'row',
|
|
318
|
+
flexWrap: 'wrap',
|
|
319
|
+
gap: 'xs',
|
|
320
|
+
children: [
|
|
321
|
+
ui.text(diff.text, { tabular: true, color: ui.color(diff.tone) }),
|
|
322
|
+
ui.muted(`vs ${diff.versus} ${diff.of}`, { tabular: true }),
|
|
323
|
+
],
|
|
324
|
+
})
|
|
325
|
+
: null,
|
|
326
|
+
session.note ? ui.muted(session.note, { size: 'footnote', wrap: 'wrap' }) : null,
|
|
327
|
+
Box({
|
|
328
|
+
flexDirection: 'column',
|
|
329
|
+
gap: 'sm',
|
|
330
|
+
children: session.parts.map((part) =>
|
|
331
|
+
ui.meter({
|
|
332
|
+
label: part.name === 'main' ? 'Main' : 'Agents',
|
|
333
|
+
value: scale > 0 ? part.usd / scale : 0,
|
|
334
|
+
tone: 'accent',
|
|
335
|
+
text: part.amount,
|
|
336
|
+
caption: part.against ? `${part.against.text} vs ${part.against.versus}` : undefined,
|
|
337
|
+
}),
|
|
338
|
+
),
|
|
339
|
+
}),
|
|
340
|
+
session.effortMix.length
|
|
341
|
+
? ui.muted(`Effort ${session.effortMix.map(([effort, n]) => `${effort} ${n}`).join(' · ')}`, { tabular: true })
|
|
342
|
+
: null,
|
|
343
|
+
session.lost
|
|
344
|
+
? ui.notice(
|
|
345
|
+
'warning',
|
|
346
|
+
'Switches cost more than they saved',
|
|
347
|
+
ui.Button({ key: 'session-policy', label: 'Policy', onPress: session.policy }),
|
|
348
|
+
)
|
|
349
|
+
: null,
|
|
350
|
+
strip,
|
|
351
|
+
].filter(Boolean),
|
|
352
|
+
);
|
|
353
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The Policy tab as a form for desktop, VS Code and mobile, drawn from the model in ui/model/policy.mjs: one card per
|
|
2
|
+
// group (Routing mode, Switching down, Switching up, Activities, Credits), each field its label, its Select and one
|
|
3
|
+
// muted help line; then Reset on its own row, the settings file in its own card, and the subagent line.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {any} ui the graphical kit
|
|
7
|
+
* @param {import('../model/policy.mjs').PolicyModel} model
|
|
8
|
+
*/
|
|
9
|
+
export function graphicalPolicy(ui, model) {
|
|
10
|
+
const { Box } = ui;
|
|
11
|
+
const field = (one) =>
|
|
12
|
+
ui.field(
|
|
13
|
+
one.label,
|
|
14
|
+
[
|
|
15
|
+
ui.select(one.control),
|
|
16
|
+
one.changed ? ui.text(model.unsaved.glyph, { color: ui.color(model.unsaved.tone) }) : null,
|
|
17
|
+
one.default ? ui.muted(ui.say(one.default), { tabular: true }) : null,
|
|
18
|
+
],
|
|
19
|
+
{ help: one.hint ? ui.say(one.hint) : one.help },
|
|
20
|
+
);
|
|
21
|
+
const { file } = model;
|
|
22
|
+
return [
|
|
23
|
+
Box({
|
|
24
|
+
flexDirection: 'column',
|
|
25
|
+
gap: 'lg',
|
|
26
|
+
children: [
|
|
27
|
+
...model.groups.map((group) =>
|
|
28
|
+
ui.section(group.title, {}, [
|
|
29
|
+
...group.fields.map(field),
|
|
30
|
+
...group.warnings.map((warning) => ui.notice('warning', warning)),
|
|
31
|
+
...group.notes.map((note) => ui.muted(note, { wrap: 'wrap' })),
|
|
32
|
+
]),
|
|
33
|
+
),
|
|
34
|
+
Box({
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
children: [ui.Button({ key: 'reset-policy', label: model.reset.label, onPress: model.reset.press })],
|
|
37
|
+
}),
|
|
38
|
+
ui.section(file.title, {}, [
|
|
39
|
+
Box({
|
|
40
|
+
flexDirection: 'row',
|
|
41
|
+
flexWrap: 'wrap',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
gap: 'sm',
|
|
44
|
+
children: [
|
|
45
|
+
ui.muted(file.path, { wrap: 'wrap' }),
|
|
46
|
+
file.copy
|
|
47
|
+
? ui.Button({ key: 'copy-path', label: ui.say(file.copy.label), onPress: file.copy.press })
|
|
48
|
+
: null,
|
|
49
|
+
].filter(Boolean),
|
|
50
|
+
}),
|
|
51
|
+
ui.muted(ui.say(model.subagents), { size: 'footnote', wrap: 'wrap' }),
|
|
52
|
+
]),
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// The Routes tab as cards for desktop, VS Code and mobile, drawn from the model in ui/model/routes.mjs: Routes (the
|
|
2
|
+
// activity-routing mode in its header, the tier × activity grid, its warnings and Reset), the selected cell's editor
|
|
3
|
+
// directly under it, and Prompt caches.
|
|
4
|
+
import { isFiniteNumber } from '../tokens.mjs';
|
|
5
|
+
|
|
6
|
+
// The row-label column: "Default" and the longest activity name.
|
|
7
|
+
const ROW_LABEL = 12;
|
|
8
|
+
// The grid needs this many columns; a narrower pane, or one that reports no width, lists each row's tiers instead.
|
|
9
|
+
const WIDE = 80;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {any} ui the graphical kit
|
|
13
|
+
* @param {import('../model/routes.mjs').RoutesModel} model
|
|
14
|
+
* @param {{ columns: number | null }} opts
|
|
15
|
+
*/
|
|
16
|
+
export function graphicalRoutes(ui, model, { columns }) {
|
|
17
|
+
return [
|
|
18
|
+
ui.Box({
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
gap: 'lg',
|
|
21
|
+
children: [
|
|
22
|
+
routesCard(ui, model, columns),
|
|
23
|
+
model.editor ? editorCard(ui, model.editor, model.unsaved) : null,
|
|
24
|
+
ui.section('Prompt caches', {}, [ui.muted(ui.say(model.cache.text), { wrap: 'wrap' })]),
|
|
25
|
+
].filter(Boolean),
|
|
26
|
+
}),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {any} ui
|
|
32
|
+
* @param {import('../model/routes.mjs').RouteMark} mark
|
|
33
|
+
*/
|
|
34
|
+
const markText = (ui, mark) => ui.text(mark.card ?? mark.glyph, { color: ui.color(mark.tone) });
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {any} ui
|
|
38
|
+
* @param {import('../model/routes.mjs').RoutesModel} model
|
|
39
|
+
* @param {number | null} columns
|
|
40
|
+
*/
|
|
41
|
+
function routesCard(ui, model, columns) {
|
|
42
|
+
const wide = isFiniteNumber(columns) && columns >= WIDE;
|
|
43
|
+
const { Box } = ui;
|
|
44
|
+
const { mode, overrides } = model;
|
|
45
|
+
const control = Box({
|
|
46
|
+
flexDirection: 'row',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
gap: 'xs',
|
|
49
|
+
flexShrink: 0,
|
|
50
|
+
children: [
|
|
51
|
+
ui.Select({
|
|
52
|
+
key: 'activity-mode',
|
|
53
|
+
label: mode.label,
|
|
54
|
+
value: mode.value,
|
|
55
|
+
options: mode.options.map((option) => ({ value: option.value, label: ui.say(option.label) })),
|
|
56
|
+
onSelect: mode.pick,
|
|
57
|
+
}),
|
|
58
|
+
mode.changed ? markText(ui, model.unsaved) : null,
|
|
59
|
+
].filter(Boolean),
|
|
60
|
+
});
|
|
61
|
+
return ui.section('Routes', { hint: ui.say(mode.hint), action: control }, [
|
|
62
|
+
overrides
|
|
63
|
+
? Box({
|
|
64
|
+
flexDirection: 'row',
|
|
65
|
+
flexWrap: 'wrap',
|
|
66
|
+
gap: 'xs',
|
|
67
|
+
children: [
|
|
68
|
+
ui.text(overrides.text, { color: ui.color(overrides.warning ? 'warning' : 'muted') }),
|
|
69
|
+
overrides.after ? ui.muted(`· ${overrides.after}`) : null,
|
|
70
|
+
].filter(Boolean),
|
|
71
|
+
})
|
|
72
|
+
: null,
|
|
73
|
+
Box({
|
|
74
|
+
key: 'routes-grid',
|
|
75
|
+
flexDirection: 'column',
|
|
76
|
+
gap: wide ? 'xs' : 'sm',
|
|
77
|
+
children: wide ? gridRows(ui, model) : listRows(ui, model),
|
|
78
|
+
}),
|
|
79
|
+
...model.steps.map((step) => ui.notice('warning', ui.say(step))),
|
|
80
|
+
Box({
|
|
81
|
+
flexDirection: 'row',
|
|
82
|
+
alignItems: 'flex-start',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
gap: 'md',
|
|
85
|
+
children: [
|
|
86
|
+
Box({
|
|
87
|
+
flexDirection: 'column',
|
|
88
|
+
gap: 'xs',
|
|
89
|
+
flexShrink: 1,
|
|
90
|
+
children: [
|
|
91
|
+
ui.muted(model.legend.map((mark) => `${mark.card ?? mark.glyph} ${mark.text}`).join(' · '), {
|
|
92
|
+
size: 'footnote',
|
|
93
|
+
wrap: 'wrap',
|
|
94
|
+
}),
|
|
95
|
+
model.hint ? ui.muted(model.hint, { size: 'footnote', wrap: 'wrap' }) : null,
|
|
96
|
+
ui.muted(model.note, { size: 'footnote', wrap: 'wrap' }),
|
|
97
|
+
].filter(Boolean),
|
|
98
|
+
}),
|
|
99
|
+
Box({
|
|
100
|
+
flexShrink: 0,
|
|
101
|
+
children: [
|
|
102
|
+
ui.Button({ key: 'reset-routes', label: model.reset.label, hotkey: 'r', onPress: model.reset.press }),
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
}),
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {any} ui
|
|
112
|
+
* @param {import('../model/routes.mjs').GridCell} cell
|
|
113
|
+
* @param {object | null} icon
|
|
114
|
+
*/
|
|
115
|
+
// A cell's Button: its route (a muted dash where it runs the tier's model), then its marks; the selected cell is
|
|
116
|
+
// primary. `icon` leads it where no header names the tier.
|
|
117
|
+
const cellButton = (ui, cell, icon = null) =>
|
|
118
|
+
ui.Button({
|
|
119
|
+
key: cell.key,
|
|
120
|
+
variant: cell.selected ? 'primary' : 'secondary',
|
|
121
|
+
onPress: cell.press,
|
|
122
|
+
children: [
|
|
123
|
+
icon,
|
|
124
|
+
ui.text(cell.label, {
|
|
125
|
+
wrap: 'truncate-end',
|
|
126
|
+
tabular: true,
|
|
127
|
+
...(cell.muted ? { color: ui.color('muted') } : {}),
|
|
128
|
+
}),
|
|
129
|
+
...cell.marks.map((mark) => markText(ui, mark)),
|
|
130
|
+
].filter(Boolean),
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {any} ui
|
|
135
|
+
* @param {import('../model/routes.mjs').GridRow} row
|
|
136
|
+
*/
|
|
137
|
+
// The tier routes' row in the heavier weight, an activity in its colour; wrapped, never cut.
|
|
138
|
+
const rowLabel = (ui, row) =>
|
|
139
|
+
row.kind === 'tier'
|
|
140
|
+
? ui.text(ui.say(row.label), { weight: 'semibold', wrap: 'wrap' })
|
|
141
|
+
: ui.text(row.label, { color: ui.color('activity'), wrap: 'wrap' });
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {any} ui
|
|
145
|
+
* @param {import('../model/routes.mjs').RoutesModel} model
|
|
146
|
+
*/
|
|
147
|
+
// The grid: a header of the tiers, then a row per tier route and activity, each a fixed label column and one equal
|
|
148
|
+
// column per tier.
|
|
149
|
+
function gridRows(ui, model) {
|
|
150
|
+
const { Box } = ui;
|
|
151
|
+
const share = `${100 / model.tiers.length}%`;
|
|
152
|
+
const row = (key, label, columns) =>
|
|
153
|
+
Box({
|
|
154
|
+
key,
|
|
155
|
+
flexDirection: 'row',
|
|
156
|
+
flexWrap: 'nowrap',
|
|
157
|
+
alignItems: 'center',
|
|
158
|
+
children: [
|
|
159
|
+
Box({ width: ROW_LABEL, flexShrink: 0, children: label ? [label] : [] }),
|
|
160
|
+
Box({
|
|
161
|
+
flexDirection: 'row',
|
|
162
|
+
flexWrap: 'nowrap',
|
|
163
|
+
flexGrow: 1,
|
|
164
|
+
flexShrink: 1,
|
|
165
|
+
children: columns.map((children) =>
|
|
166
|
+
Box({ width: share, flexShrink: 1, overflow: 'hidden', paddingRight: 'xs', children }),
|
|
167
|
+
),
|
|
168
|
+
}),
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
return [
|
|
172
|
+
row(
|
|
173
|
+
'grid-head',
|
|
174
|
+
null,
|
|
175
|
+
model.tiers.map(({ id: tier, label }) => [
|
|
176
|
+
Box({
|
|
177
|
+
flexDirection: 'row',
|
|
178
|
+
alignItems: 'center',
|
|
179
|
+
gap: 'xs',
|
|
180
|
+
children: [
|
|
181
|
+
Box({ flexShrink: 0, children: [ui.tierMeter(tier, 'lit')] }),
|
|
182
|
+
ui.text(ui.say(label), {
|
|
183
|
+
size: 'footnote',
|
|
184
|
+
weight: 'semibold',
|
|
185
|
+
color: ui.color(`tier:${tier}`),
|
|
186
|
+
wrap: 'truncate-end',
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
}),
|
|
190
|
+
]),
|
|
191
|
+
),
|
|
192
|
+
...model.rows.map((one) =>
|
|
193
|
+
row(
|
|
194
|
+
`grid-${one.id}`,
|
|
195
|
+
rowLabel(ui, one),
|
|
196
|
+
one.cells.map((cell) => [cellButton(ui, cell)]),
|
|
197
|
+
),
|
|
198
|
+
),
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {any} ui
|
|
204
|
+
* @param {import('../model/routes.mjs').RoutesModel} model
|
|
205
|
+
*/
|
|
206
|
+
// A narrow pane: each row is its label over its tiers' Buttons, wrapped, each Button led by its tier's bars.
|
|
207
|
+
function listRows(ui, model) {
|
|
208
|
+
const { Box } = ui;
|
|
209
|
+
return model.rows.map((one) =>
|
|
210
|
+
Box({
|
|
211
|
+
key: `grid-${one.id}`,
|
|
212
|
+
flexDirection: 'column',
|
|
213
|
+
gap: 'xs',
|
|
214
|
+
children: [
|
|
215
|
+
rowLabel(ui, one),
|
|
216
|
+
Box({
|
|
217
|
+
flexDirection: 'row',
|
|
218
|
+
flexWrap: 'wrap',
|
|
219
|
+
gap: 'xs',
|
|
220
|
+
children: one.cells.map((cell) => cellButton(ui, cell, ui.tierMeter(cell.tier, 'lit', { inButton: true }))),
|
|
221
|
+
}),
|
|
222
|
+
],
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @param {any} ui
|
|
229
|
+
* @param {import('../model/routes.mjs').RouteEditor} editor
|
|
230
|
+
* @param {import('../model/routes.mjs').RouteMark} unsaved
|
|
231
|
+
*/
|
|
232
|
+
// The selected cell's editor: its model and effort, then its prices or its state and the ways back, then its warnings.
|
|
233
|
+
function editorCard(ui, editor, unsaved) {
|
|
234
|
+
const { Box } = ui;
|
|
235
|
+
const { key, model, effort } = editor.choices;
|
|
236
|
+
const select = (id, choice) =>
|
|
237
|
+
ui.Select({ key: `${key}-${id}`, value: choice.value, options: choice.options, onSelect: choice.pick });
|
|
238
|
+
const children = [
|
|
239
|
+
ui.field('Model', [select('model', model), editor.changed ? markText(ui, unsaved) : null]),
|
|
240
|
+
ui.field('Effort', [effort ? select('effort', effort) : ui.muted('none')]),
|
|
241
|
+
];
|
|
242
|
+
if (editor.kind === 'tier') {
|
|
243
|
+
children.push(ui.muted(editor.rates.graphical, { tabular: true, wrap: 'wrap' }));
|
|
244
|
+
} else {
|
|
245
|
+
const { remove, restore } = editor;
|
|
246
|
+
children.push(ui.muted(ui.say(editor.state)));
|
|
247
|
+
if (remove || restore)
|
|
248
|
+
children.push(
|
|
249
|
+
Box({
|
|
250
|
+
flexDirection: 'row',
|
|
251
|
+
flexWrap: 'wrap',
|
|
252
|
+
alignItems: 'center',
|
|
253
|
+
gap: 'sm',
|
|
254
|
+
children: [
|
|
255
|
+
remove ? ui.Button({ key: remove.key, label: remove.label.graphical, onPress: remove.press }) : null,
|
|
256
|
+
remove ? ui.muted(remove.note, { size: 'footnote' }) : null,
|
|
257
|
+
restore ? ui.Button({ key: restore.key, label: restore.label, onPress: restore.press }) : null,
|
|
258
|
+
].filter(Boolean),
|
|
259
|
+
}),
|
|
260
|
+
);
|
|
261
|
+
children.push(...editor.warnings.map((warning) => ui.notice('warning', ui.say(warning))));
|
|
262
|
+
}
|
|
263
|
+
return ui.section(editor.title, {}, children);
|
|
264
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Subagent squares for desktop, VS Code and mobile: one Svg per run of agents, filled for an agent the router moved,
|
|
2
|
+
// outlined for one on Claude Code's pick, each in its model's colour, so moved and kept differ without colour.
|
|
3
|
+
import { svgColor } from '../tokens.mjs';
|
|
4
|
+
|
|
5
|
+
// A square in pixels, and the gap after it.
|
|
6
|
+
const SQUARE = 9;
|
|
7
|
+
const SQUARE_GAP = 3;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The model's squares (`runs` of `{ tone, filled, n, text }`) as one Svg with its alt.
|
|
11
|
+
* @param {any} ui the graphical kit
|
|
12
|
+
* @param {{ runs: { tone: import('../tokens.mjs').Tone, filled: boolean, n: number, text: string }[] }} strip
|
|
13
|
+
* @param {string} alt
|
|
14
|
+
*/
|
|
15
|
+
export function squares(ui, strip, alt) {
|
|
16
|
+
const cells = strip.runs.flatMap((run) => Array.from({ length: run.n }, () => run));
|
|
17
|
+
const step = SQUARE + SQUARE_GAP;
|
|
18
|
+
const width = Math.max(1, cells.length * step - SQUARE_GAP);
|
|
19
|
+
const rects = cells
|
|
20
|
+
.map((run, i) => {
|
|
21
|
+
const color = svgColor(run.tone);
|
|
22
|
+
return run.filled
|
|
23
|
+
? `<rect x="${i * step}" y="0" width="${SQUARE}" height="${SQUARE}" rx="1.5" fill="${color}"/>`
|
|
24
|
+
: `<rect x="${i * step + 0.75}" y="0.75" width="${SQUARE - 1.5}" height="${SQUARE - 1.5}" rx="1.5" fill="none" stroke="${color}" stroke-width="1.5"/>`;
|
|
25
|
+
})
|
|
26
|
+
.join('');
|
|
27
|
+
const source = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${SQUARE}" viewBox="0 0 ${width} ${SQUARE}">${rects}</svg>`;
|
|
28
|
+
return ui.Svg({ source, alt, width, height: SQUARE });
|
|
29
|
+
}
|