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