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