@alexeiled/claude-router 1.23.1 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +62 -1
- package/README.md +39 -7
- package/docs/architecture.md +27 -4
- package/docs/auto-engine.md +152 -0
- package/docs/configuration.md +47 -3
- package/docs/evaluation.md +222 -3
- package/docs/native-router.md +11 -3
- package/docs/providers.md +28 -0
- package/docs/router-band.svg +124 -133
- package/docs/router-pane-classifier.svg +24 -23
- package/docs/router-pane-now.svg +9 -7
- package/docs/router-pane-policy.svg +4 -4
- package/docs/router-pane-routes.svg +8 -8
- package/docs/router-pane-usage-whatif.svg +14 -14
- package/docs/router-pane-usage.svg +20 -20
- package/docs/routing-modes.md +13 -4
- package/docs/user-guide.md +79 -19
- package/hooks/native-router.mjs +1194 -215
- package/lib/activity-stats.mjs +23 -4
- package/lib/activity.mjs +7 -5
- package/lib/auto-engine.mjs +414 -0
- package/lib/auto-route.mjs +253 -0
- package/lib/band.mjs +35 -440
- package/lib/classifier-client.mjs +12 -8
- package/lib/config-file.mjs +7 -2
- package/lib/config.mjs +64 -15
- package/lib/cost.mjs +5 -1
- package/lib/costs.mjs +4 -2
- package/lib/decisions.mjs +80 -5
- package/lib/display.mjs +69 -20
- package/lib/facts.mjs +30 -0
- package/lib/modes.mjs +8 -4
- package/lib/panel.mjs +75 -2163
- package/lib/policy.mjs +7 -6
- package/lib/providers.mjs +7 -0
- package/lib/replay-trace.mjs +550 -0
- package/lib/replay.mjs +718 -0
- package/lib/route-line.mjs +46 -0
- package/lib/route.mjs +35 -21
- package/lib/savings.mjs +14 -3
- package/lib/subagents.mjs +41 -11
- package/lib/subcommands.mjs +60 -0
- package/lib/ui/fallback.mjs +22 -0
- package/lib/ui/graphical/band.mjs +256 -0
- package/lib/ui/graphical/charts.mjs +163 -0
- package/lib/ui/graphical/classifier.mjs +153 -0
- package/lib/ui/graphical/frame.mjs +227 -0
- package/lib/ui/graphical/kit.mjs +156 -0
- package/lib/ui/graphical/meter.mjs +25 -0
- package/lib/ui/graphical/now.mjs +353 -0
- package/lib/ui/graphical/policy.mjs +56 -0
- package/lib/ui/graphical/routes.mjs +264 -0
- package/lib/ui/graphical/squares.mjs +29 -0
- package/lib/ui/graphical/usage.mjs +376 -0
- package/lib/ui/model/band.mjs +439 -0
- package/lib/ui/model/classifier.mjs +308 -0
- package/lib/ui/model/draft.mjs +62 -0
- package/lib/ui/model/format.mjs +41 -0
- package/lib/ui/model/frame.mjs +359 -0
- package/lib/ui/model/now.mjs +390 -0
- package/lib/ui/model/policy.mjs +194 -0
- package/lib/ui/model/routes.mjs +392 -0
- package/lib/ui/model/usage-agents.mjs +311 -0
- package/lib/ui/model/usage-breakdown.mjs +237 -0
- package/lib/ui/model/usage-shared.mjs +58 -0
- package/lib/ui/model/usage.mjs +330 -0
- package/lib/ui/terminal/band.mjs +220 -0
- package/lib/ui/terminal/classifier.mjs +142 -0
- package/lib/ui/terminal/frame.mjs +169 -0
- package/lib/ui/terminal/kit.mjs +133 -0
- package/lib/ui/terminal/now.mjs +300 -0
- package/lib/ui/terminal/policy.mjs +52 -0
- package/lib/ui/terminal/routes.mjs +167 -0
- package/lib/ui/terminal/usage.mjs +363 -0
- package/lib/ui/terminal/wrap.mjs +37 -0
- package/lib/ui/tokens.mjs +106 -0
- package/lib/usage.mjs +5 -5
- package/lib/view.mjs +5 -2
- package/package.json +3 -2
- package/types/index.d.ts +15 -0
package/lib/config.mjs
CHANGED
|
@@ -21,10 +21,12 @@ const withoutShadow = (file) =>
|
|
|
21
21
|
export const CLASSIFY = 'classify';
|
|
22
22
|
// The routing mode trades cost against answer quality (lib/modes.mjs). Not the session's auto|manual mode.
|
|
23
23
|
export const ROUTING_MODES = ['cost', 'balanced', 'quality'];
|
|
24
|
+
export const ROUTING_ENGINES = ['table', 'shadow', 'auto'];
|
|
24
25
|
// The modes that patch the policy; `balanced` is the base policy itself.
|
|
25
26
|
const PATCHED_MODES = ['cost', 'quality'];
|
|
26
27
|
const SONNET_HIGH = { model: 'sonnet', effort: 'high' };
|
|
27
28
|
export const DEFAULTS = {
|
|
29
|
+
routingEngine: 'table',
|
|
28
30
|
baselineTier: 'low',
|
|
29
31
|
// Haiku 5.5 is the worker at `low` and `micro`: at high effort it scored above Sonnet 5.5 at low, and at xhigh near
|
|
30
32
|
// Sonnet at medium, for a fraction of the cost per attempt (Anthropic's OSWorld 2.1 effort chart: computer use, not
|
|
@@ -58,10 +60,11 @@ export const DEFAULTS = {
|
|
|
58
60
|
// `inherit`, or sets `modelRouting: auto` gets `light`, `standard` or `heavy` from the classifier; a pinned one keeps
|
|
59
61
|
// its model. `types` overrides by agent type: a models key, `classify`, or null to never route it. A key without a
|
|
60
62
|
// colon matches only the built-in of that name, whose definition is not readable, so only the listed built-ins route.
|
|
63
|
+
// A workflow `agent()` is always `workflow-subagent`, whatever its own type says; its own `agent({ model })` stands.
|
|
61
64
|
// A listed type is routed even if it pins a model. docs/plans/2026-10-10-subagent-routing-plan.md.
|
|
62
65
|
subagentRouting: 'on',
|
|
63
66
|
subagents: {
|
|
64
|
-
types: { Explore: 'haiku', Plan: CLASSIFY, 'general-purpose': CLASSIFY },
|
|
67
|
+
types: { Explore: 'haiku', Plan: CLASSIFY, 'general-purpose': CLASSIFY, 'workflow-subagent': CLASSIFY },
|
|
65
68
|
light: 'haiku',
|
|
66
69
|
standard: 'sonnet',
|
|
67
70
|
heavy: 'opus',
|
|
@@ -82,6 +85,7 @@ export const DEFAULTS = {
|
|
|
82
85
|
models: {
|
|
83
86
|
fable: {
|
|
84
87
|
id: 'claude-fable-5-2',
|
|
88
|
+
capability: {},
|
|
85
89
|
strength: 4,
|
|
86
90
|
...listPrice('claude-fable-5-2'),
|
|
87
91
|
contextWindow: 1_000_000,
|
|
@@ -90,6 +94,11 @@ export const DEFAULTS = {
|
|
|
90
94
|
},
|
|
91
95
|
opus: {
|
|
92
96
|
id: 'claude-opus-5-5',
|
|
97
|
+
// Lead-approved user-derived policy from DEFAULTS balanced base routes and PR #79 methodology, not benchmark or quality.
|
|
98
|
+
capability: {
|
|
99
|
+
medium: 2, // built-in base route medium
|
|
100
|
+
xhigh: 3, // built-in base route high
|
|
101
|
+
},
|
|
93
102
|
strength: 3,
|
|
94
103
|
...listPrice('claude-opus-5-5'),
|
|
95
104
|
contextWindow: 1_000_000,
|
|
@@ -98,6 +107,7 @@ export const DEFAULTS = {
|
|
|
98
107
|
},
|
|
99
108
|
sonnet: {
|
|
100
109
|
id: 'claude-sonnet-5-5',
|
|
110
|
+
capability: {},
|
|
101
111
|
strength: 2,
|
|
102
112
|
...listPrice('claude-sonnet-5-5'),
|
|
103
113
|
contextWindow: 1_000_000,
|
|
@@ -106,6 +116,11 @@ export const DEFAULTS = {
|
|
|
106
116
|
},
|
|
107
117
|
haiku: {
|
|
108
118
|
id: 'claude-haiku-5-5',
|
|
119
|
+
// Lead-approved user-derived policy from DEFAULTS balanced base routes and PR #79 methodology, not benchmark or quality.
|
|
120
|
+
capability: {
|
|
121
|
+
medium: 0, // built-in base route micro
|
|
122
|
+
high: 1, // built-in base route low
|
|
123
|
+
},
|
|
109
124
|
strength: 1,
|
|
110
125
|
...listPrice('claude-haiku-5-5'),
|
|
111
126
|
contextWindow: 1_000_000,
|
|
@@ -256,6 +271,7 @@ const MODEL_KEYS = [
|
|
|
256
271
|
'billing',
|
|
257
272
|
'efforts',
|
|
258
273
|
'strength',
|
|
274
|
+
'capability',
|
|
259
275
|
'imageInput',
|
|
260
276
|
];
|
|
261
277
|
const CLASSIFIER_KEYS = ['label', 'api', 'endpoint', 'model', 'keyOption', 'timeoutMs'];
|
|
@@ -278,19 +294,28 @@ export const MIGRATION_HINT =
|
|
|
278
294
|
|
|
279
295
|
export const defaultsFor = (provider = 'anthropic') => executionDefaults(providerName(provider), DEFAULTS);
|
|
280
296
|
|
|
297
|
+
/** @param {{ userFile?: { models?: Record<string, { id?: string, capability?: object, efforts?: string[] }> } | null, provider?: string }} [options] */
|
|
281
298
|
export function loadConfig({ userFile = null, provider = 'anthropic' } = {}) {
|
|
282
299
|
provider = providerName(provider);
|
|
283
300
|
if (userFile !== null) checkShape(userFile);
|
|
284
301
|
const defaults = defaultsFor(provider);
|
|
285
302
|
const merged = merge(structuredClone(defaults), withoutShadow(userFile ?? {}));
|
|
286
|
-
//
|
|
287
|
-
for (const [alias, patch] of Object.entries(userFile?.models ?? {}))
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
)
|
|
293
|
-
|
|
303
|
+
// Model-specific judgments must not follow a different model under the same alias.
|
|
304
|
+
for (const [alias, patch] of Object.entries(userFile?.models ?? {})) {
|
|
305
|
+
const model = merged.models[alias];
|
|
306
|
+
const changed = patch.id && canonicalModel(patch.id) !== canonicalModel(defaults.models[alias]?.id);
|
|
307
|
+
if (changed && !Object.hasOwn(patch, 'strength')) delete model.strength;
|
|
308
|
+
if (Object.hasOwn(patch, 'capability')) model.capability = { ...patch.capability };
|
|
309
|
+
else if (changed) delete model.capability;
|
|
310
|
+
else if (patch.efforts && model.capability && Array.isArray(patch.efforts)) {
|
|
311
|
+
const { efforts } = patch;
|
|
312
|
+
model.capability = Object.fromEntries(
|
|
313
|
+
Object.entries(model.capability).filter(([effort]) =>
|
|
314
|
+
efforts.length ? efforts.includes(effort) : effort === 'default',
|
|
315
|
+
),
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
294
319
|
// A user entry without `api` speaks the System One protocol that every entry spoke before 1.5.
|
|
295
320
|
const config = {
|
|
296
321
|
...merged,
|
|
@@ -371,7 +396,7 @@ export function withRoutes(file, draft) {
|
|
|
371
396
|
// Activity cells are sparse: a missing field inherits the tier's route, so `effort: undefined` and `effort: null`
|
|
372
397
|
// differ. A null or missing cell is no override.
|
|
373
398
|
export const sameCell = (a, b) => (a && b ? a.model === b.model && a.effort === b.effort : !a === !b);
|
|
374
|
-
const cellOf = (activities, activity, tier) => activities?.[activity]?.[tier];
|
|
399
|
+
const cellOf = (activities, activity, tier) => (activity ? activities?.[activity]?.[tier] : undefined);
|
|
375
400
|
|
|
376
401
|
// The activity side of a route draft, with the effectiveRoutes rule: a cell or the mode counts as edited when it
|
|
377
402
|
// differs from the draft's `base`; everything else follows `current`. A draft built without `activities` or
|
|
@@ -401,11 +426,15 @@ export function effectiveActivities(draft, current) {
|
|
|
401
426
|
// An added cell starts from the built-in override, so re-adding a removed default restores it, else from the base
|
|
402
427
|
// route, which the pane flags as having no effect until edited. An edit that lands on the route the saved cell
|
|
403
428
|
// already resolves to is the saved cell, so a partial cell is not rewritten with the fields it inherits.
|
|
429
|
+
/** @param {string | null} [value] */
|
|
404
430
|
export function editActivity(draft, current, activity, tier, kind, value = null) {
|
|
405
431
|
const config = { ...current, ...effectiveRoutes(draft, current), ...effectiveActivities(draft, current) };
|
|
406
432
|
const route = resolveRoute(config, tier, activity);
|
|
407
433
|
let cell = {
|
|
408
|
-
model: () => ({
|
|
434
|
+
model: () => ({
|
|
435
|
+
model: value,
|
|
436
|
+
effort: value !== null && config.models[value]?.efforts.includes(route.effort) ? route.effort : null,
|
|
437
|
+
}),
|
|
409
438
|
effort: () => ({ model: route.model, effort: value }),
|
|
410
439
|
add: () => ({
|
|
411
440
|
...(cellOf(defaultsFor(current.provider).activities, activity, tier) ?? resolveRoute(config, tier)),
|
|
@@ -462,6 +491,7 @@ export function withMode(file, mode) {
|
|
|
462
491
|
}
|
|
463
492
|
|
|
464
493
|
// The pane's policy controls and the router.json fields they stand for. The classifier deadline saves on its own.
|
|
494
|
+
/** @type {Record<string, [string, string]>} */
|
|
465
495
|
const TUNING_FIELDS = {
|
|
466
496
|
downgradeVotes: ['policy', 'downgradeVotes'],
|
|
467
497
|
horizon: ['policy', 'downgradeHorizonTurns'],
|
|
@@ -507,20 +537,25 @@ export function rank(tier) {
|
|
|
507
537
|
|
|
508
538
|
// The (model, effort) a tier runs on for an activity: the tier's route with that activity's sparse override on top.
|
|
509
539
|
// A null activity (off, uncertain, failed) resolves to the tier's route.
|
|
540
|
+
/** @param {string | null} [activity] */
|
|
510
541
|
export function resolveRoute(config, tier, activity = null) {
|
|
511
|
-
const route = { ...config.routes[tier], ...config.activities
|
|
542
|
+
const route = { ...config.routes[tier], ...cellOf(config.activities, activity, tier) };
|
|
512
543
|
return { model: route.model, effort: route.effort ?? null };
|
|
513
544
|
}
|
|
514
545
|
|
|
515
546
|
// The model entry a route runs on.
|
|
516
547
|
export const routeSpec = (config, route) => config.models[route.model];
|
|
517
548
|
|
|
518
|
-
//
|
|
549
|
+
// The oldest Claude Code the router runs on: the first build whose engine takes the graphical surfaces' spacing steps.
|
|
550
|
+
export const MIN_CLAUDE_CODE = '2.1.321';
|
|
551
|
+
const MIN_PATCH = Number(MIN_CLAUDE_CODE.split('.')[2]);
|
|
552
|
+
|
|
553
|
+
// Whether a Claude Code version, such as 2.1.321 or a 2.1.322-beta build, runs the router.
|
|
519
554
|
export function supportedVersion(version) {
|
|
520
555
|
const parts = /^(\d+)\.(\d+)\.(\d+)(?:$|-)/.exec(version ?? '');
|
|
521
556
|
if (!parts) return false;
|
|
522
|
-
const [major, minor, patch] = parts.slice(1).map(Number);
|
|
523
|
-
return major > 2 || (major === 2 && (minor > 1 || (minor === 1 && patch >=
|
|
557
|
+
const [major = 0, minor = 0, patch = 0] = parts.slice(1).map(Number);
|
|
558
|
+
return major > 2 || (major === 2 && (minor > 1 || (minor === 1 && patch >= MIN_PATCH)));
|
|
524
559
|
}
|
|
525
560
|
|
|
526
561
|
function merge(base, override) {
|
|
@@ -568,6 +603,8 @@ function checkShape(file) {
|
|
|
568
603
|
checkObject(models, 'models');
|
|
569
604
|
for (const [alias, model] of Object.entries(models)) {
|
|
570
605
|
checkObject(model, `models.${alias}`, MODEL_KEYS);
|
|
606
|
+
if (model.capability !== undefined)
|
|
607
|
+
checkObject(model.capability, `models.${alias}.capability`, [...EFFORTS, 'default']);
|
|
571
608
|
// null removes a built-in surcharge.
|
|
572
609
|
if (model.longContext != null)
|
|
573
610
|
checkObject(model.longContext, `models.${alias}.longContext`, ['above', 'multiplier']);
|
|
@@ -600,6 +637,7 @@ function checkShape(file) {
|
|
|
600
637
|
}
|
|
601
638
|
|
|
602
639
|
// `allowed` null: an open map.
|
|
640
|
+
/** @param {string[] | null} [allowed] */
|
|
603
641
|
function checkObject(value, path, allowed = null) {
|
|
604
642
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new Error(`${path} must be an object`);
|
|
605
643
|
for (const key of Object.keys(value)) {
|
|
@@ -613,6 +651,8 @@ const isNumber = (value, min, { above = false, integer = false } = {}) =>
|
|
|
613
651
|
Number.isFinite(value) && (above ? value > min : value >= min) && (!integer || Number.isInteger(value));
|
|
614
652
|
|
|
615
653
|
function validate(config) {
|
|
654
|
+
if (!ROUTING_ENGINES.includes(config.routingEngine))
|
|
655
|
+
throw new Error(`routingEngine must be one of ${ROUTING_ENGINES.join(', ')}`);
|
|
616
656
|
for (const tier of TIERS) {
|
|
617
657
|
const route = config.routes[tier];
|
|
618
658
|
if (!route || typeof route.model !== 'string') throw new Error(`routes.${tier}.model is required`);
|
|
@@ -740,6 +780,15 @@ function validateModel(at, model) {
|
|
|
740
780
|
if (!['plan', 'credits'].includes(model.billing)) throw new Error(`${at}.billing must be plan or credits`);
|
|
741
781
|
if (!Array.isArray(model.efforts) || model.efforts.some((e) => !EFFORTS.includes(e)))
|
|
742
782
|
throw new Error(`${at}.efforts must list valid effort levels`);
|
|
783
|
+
if (model.capability !== undefined) {
|
|
784
|
+
checkObject(model.capability, `${at}.capability`, [...EFFORTS, 'default']);
|
|
785
|
+
for (const [effort, value] of Object.entries(model.capability)) {
|
|
786
|
+
if (!(model.efforts.length ? model.efforts.includes(effort) : effort === 'default'))
|
|
787
|
+
throw new Error(`${at}.capability.${effort} is not supported by its model`);
|
|
788
|
+
if (!Number.isFinite(value) || value < 0 || value > 3 || !Number.isInteger(value * 2))
|
|
789
|
+
throw new Error(`${at}.capability.${effort} must be a half-step from 0 to 3`);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
743
792
|
}
|
|
744
793
|
|
|
745
794
|
function validateClassifier(at, entry) {
|
package/lib/cost.mjs
CHANGED
|
@@ -143,7 +143,10 @@ export function nextTurnRange(config, candidate, incumbent, facts, now) {
|
|
|
143
143
|
ratesAt(routeSpec(config, incumbent), tokens, now),
|
|
144
144
|
];
|
|
145
145
|
const outputTokens = facts.lastRequest?.outputTokens ?? 0;
|
|
146
|
-
const output =
|
|
146
|
+
const output =
|
|
147
|
+
to.output !== undefined && from.output !== undefined && to.output > 0 && from.output > 0
|
|
148
|
+
? ((to.output - from.output) * outputTokens) / 1e6
|
|
149
|
+
: 0;
|
|
147
150
|
return { minUsd: proposed.min - current.max + output, maxUsd: proposed.max - current.min + output };
|
|
148
151
|
}
|
|
149
152
|
|
|
@@ -152,6 +155,7 @@ export function switchEconomics(config, candidate, incumbent, facts, now) {
|
|
|
152
155
|
const tokens = nextContextTokens(facts);
|
|
153
156
|
const proposed = ratesAt(routeSpec(config, candidate), tokens, now);
|
|
154
157
|
const current = ratesAt(routeSpec(config, incumbent), tokens, now);
|
|
158
|
+
if (proposed.output === undefined || current.output === undefined) return null;
|
|
155
159
|
if (!(proposed.output > 0) || !(current.output > 0)) return null;
|
|
156
160
|
const outputTokens = facts.lastRequest?.outputTokens ?? 0;
|
|
157
161
|
const output = ((proposed.output - current.output) * outputTokens) / 1e6;
|
package/lib/costs.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { dayKey } from './usage.mjs';
|
|
|
12
12
|
|
|
13
13
|
// The plan windows Claude Code reports, in the order shown. `spend_limit` is a gateway's cap on billed spend, not a
|
|
14
14
|
// plan's quota.
|
|
15
|
+
/** @type {[string, string][]} */
|
|
15
16
|
const WINDOWS = [
|
|
16
17
|
['five_hour', '5h'],
|
|
17
18
|
['seven_day', '7d'],
|
|
@@ -112,8 +113,9 @@ export function periodCost(config, { summary, agents, usage = null }) {
|
|
|
112
113
|
const mainDiff = comparable ? r.differenceUsd : null;
|
|
113
114
|
const agentDiff = cents(agentUsd - agentBaseUsd);
|
|
114
115
|
const baseUsd = comparable ? cents(r.yoursUsd + agentBaseUsd) : null;
|
|
115
|
-
const diffUsd =
|
|
116
|
+
const diffUsd = mainDiff === null ? null : cents(mainDiff + agentDiff);
|
|
116
117
|
const billing = billingOf(config, usage);
|
|
118
|
+
/** @type {number | null} */
|
|
117
119
|
let creditsUsd = null;
|
|
118
120
|
if (billing === 'mixed') {
|
|
119
121
|
let main = 0;
|
|
@@ -134,7 +136,7 @@ export function periodCost(config, { summary, agents, usage = null }) {
|
|
|
134
136
|
agentDiff: agentUsd || agentBaseUsd ? agentDiff : null,
|
|
135
137
|
baseUsd,
|
|
136
138
|
diffUsd,
|
|
137
|
-
share: baseUsd > 0 ? diffUsd / baseUsd : null,
|
|
139
|
+
share: baseUsd !== null && diffUsd !== null && baseUsd > 0 ? diffUsd / baseUsd : null,
|
|
138
140
|
// A sample of main replies: agents alone are each priced against their own pick, not sampled.
|
|
139
141
|
early: r.early && summary.replies > 0,
|
|
140
142
|
readout: r,
|
package/lib/decisions.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// whether its replies were priced. Counts, labels and routes only, never text. Pure: the hook collects a turn's rows and
|
|
4
4
|
// writes them at turn.complete to the session's own $.store key under DECISIONS_PREFIX.
|
|
5
5
|
|
|
6
|
+
import { ROUTING_ENGINES } from './config.mjs';
|
|
6
7
|
import { afterResetOf, isRecord } from './records.mjs';
|
|
7
8
|
|
|
8
9
|
export const DECISIONS_PREFIX = 'decisions:v1:';
|
|
@@ -63,6 +64,53 @@ const round = (n, digits = 2) => (Number.isFinite(n) ? Math.round(n * 10 ** digi
|
|
|
63
64
|
const label = (value) => (typeof value === 'string' && value.length > 0 && value.length <= 80 ? value : null);
|
|
64
65
|
const count = (n) => (Number.isSafeInteger(n) && n > 0 ? n : 0);
|
|
65
66
|
|
|
67
|
+
// Shadow retains a narrow projection, not the engine result or any of the transcript facts.
|
|
68
|
+
const ALT_REASONS = [
|
|
69
|
+
'classifier',
|
|
70
|
+
'jump',
|
|
71
|
+
'pin',
|
|
72
|
+
'escalation',
|
|
73
|
+
'hold',
|
|
74
|
+
'no-advice',
|
|
75
|
+
'uncertain',
|
|
76
|
+
'same-demand',
|
|
77
|
+
'upgrade',
|
|
78
|
+
'upgrade-pending',
|
|
79
|
+
'downgrade',
|
|
80
|
+
'downgrade-pending',
|
|
81
|
+
'error',
|
|
82
|
+
'pinned',
|
|
83
|
+
];
|
|
84
|
+
const ALT_OUTCOMES = ['meets-demand', 'declared-below-demand', 'unknown-only', 'no-route', 'incumbent'];
|
|
85
|
+
const altLevel = (n) => (Number.isFinite(n) && n >= 0 && n <= 3 && Number.isInteger(n * 2) ? n : null);
|
|
86
|
+
const altCost = (n) => (Number.isFinite(n) && n >= 0 ? Number(n.toFixed(6)) : null);
|
|
87
|
+
const ALT_ROUTE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}@(low|medium|high|xhigh|max|session)$/;
|
|
88
|
+
const AUTO_ROUTE = /^([^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+)@(low|medium|high|xhigh|max|session)$/u;
|
|
89
|
+
function validAutoRoute(value) {
|
|
90
|
+
if (typeof value !== 'string' || value.length > 72) return false;
|
|
91
|
+
const match = AUTO_ROUTE.exec(value);
|
|
92
|
+
return Boolean(match?.[1] && match[1].length <= 64);
|
|
93
|
+
}
|
|
94
|
+
function readAlt(alt, auto = false) {
|
|
95
|
+
if (!isRecord(alt)) return null;
|
|
96
|
+
return {
|
|
97
|
+
demand: altLevel(alt.demand),
|
|
98
|
+
reason: ALT_REASONS.includes(alt.reason) ? alt.reason : null,
|
|
99
|
+
headroom: alt.headroom === true,
|
|
100
|
+
targetReason: ['escalation', 'escalation-unknown', 'escalation-exhausted'].includes(alt.targetReason)
|
|
101
|
+
? alt.targetReason
|
|
102
|
+
: null,
|
|
103
|
+
requirement: altLevel(alt.requirement),
|
|
104
|
+
outcome: ALT_OUTCOMES.includes(alt.outcome) ? alt.outcome : null,
|
|
105
|
+
route: (auto ? validAutoRoute(alt.route) : typeof alt.route === 'string' && ALT_ROUTE.test(alt.route))
|
|
106
|
+
? alt.route
|
|
107
|
+
: null,
|
|
108
|
+
capability: altLevel(alt.capability),
|
|
109
|
+
minUsd: altCost(alt.minUsd),
|
|
110
|
+
maxUsd: altCost(alt.maxUsd),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
66
114
|
// The reasons whose estimate holds a mass the policy compared with its threshold. Any other reason can carry an
|
|
67
115
|
// estimate that is not its own: a context or availability override keeps the one of the decision it replaced, and a
|
|
68
116
|
// jump compared its mass with jumpConfidence, not the threshold.
|
|
@@ -89,6 +137,8 @@ function compared(kind, decision) {
|
|
|
89
137
|
return mass === null || bar === null ? {} : { mass, bar };
|
|
90
138
|
}
|
|
91
139
|
|
|
140
|
+
/** @typedef {{ choice: string, probabilities?: Record<string, number> }} AdviceChoice */
|
|
141
|
+
|
|
92
142
|
// One routing decision as a row: `kind` start (the turn's first step), review (a classifier review applied inside the
|
|
93
143
|
// turn) or observed (a move on the turn's own tool calls). `advice` is the classifier's answer or null, `error` why
|
|
94
144
|
// there is none, `decision` the route chosen (chooseRoute's), `facts` what it was chosen on, `sameTask` sameTaskOf.
|
|
@@ -97,11 +147,15 @@ export function decisionRow({
|
|
|
97
147
|
kind,
|
|
98
148
|
origin = null,
|
|
99
149
|
mode = null,
|
|
100
|
-
advice = null,
|
|
150
|
+
advice = /** @type {(AdviceChoice & { continuation?: number, activity?: AdviceChoice | null, phase?: AdviceChoice }) | null} */ (
|
|
151
|
+
null
|
|
152
|
+
),
|
|
101
153
|
error = null,
|
|
102
154
|
decision,
|
|
103
155
|
facts = {},
|
|
104
|
-
sameTask = null,
|
|
156
|
+
sameTask = /** @type {boolean | null} */ (null),
|
|
157
|
+
engine = /** @type {string | null} */ (null),
|
|
158
|
+
alt = /** @type {object | null} */ (null),
|
|
105
159
|
}) {
|
|
106
160
|
const activity = advice?.activity ?? null;
|
|
107
161
|
const { downAllowed, contextTokens } = /** @type {{ downAllowed?: boolean, contextTokens?: number }} */ (facts);
|
|
@@ -111,10 +165,10 @@ export function decisionRow({
|
|
|
111
165
|
origin: label(origin),
|
|
112
166
|
mode: label(mode),
|
|
113
167
|
cls: label(advice?.choice),
|
|
114
|
-
p: round(advice?.probabilities?.[advice
|
|
168
|
+
p: round(advice?.probabilities?.[advice.choice]),
|
|
115
169
|
cont: round(advice?.continuation),
|
|
116
170
|
act: label(activity?.choice),
|
|
117
|
-
actP: round(activity?.probabilities?.[activity
|
|
171
|
+
actP: round(activity?.probabilities?.[activity.choice]),
|
|
118
172
|
...(advice?.phase
|
|
119
173
|
? { phase: label(advice.phase.choice), phaseP: round(advice.phase.probabilities?.[advice.phase.choice]) }
|
|
120
174
|
: {}),
|
|
@@ -127,8 +181,13 @@ export function decisionRow({
|
|
|
127
181
|
pinned: Boolean(decision?.pinned),
|
|
128
182
|
same: typeof sameTask === 'boolean' ? sameTask : null,
|
|
129
183
|
down: typeof downAllowed === 'boolean' ? downAllowed : null,
|
|
130
|
-
ctx: Number.isFinite(contextTokens) ? Math.round(contextTokens / 1000) : null,
|
|
184
|
+
ctx: typeof contextTokens === 'number' && Number.isFinite(contextTokens) ? Math.round(contextTokens / 1000) : null,
|
|
131
185
|
...compared(kind, decision),
|
|
186
|
+
...(engine !== null && engine !== 'table' && ROUTING_ENGINES.includes(engine) ? { engine } : {}),
|
|
187
|
+
...(engine === 'shadow' && readAlt(alt) ? { alt: readAlt(alt) } : {}),
|
|
188
|
+
...(engine === 'auto' && readAlt(decision?.auto, true)
|
|
189
|
+
? { auto: { ...readAlt(decision.auto, true), move: label(decision.auto.move) } }
|
|
190
|
+
: {}),
|
|
132
191
|
};
|
|
133
192
|
}
|
|
134
193
|
|
|
@@ -201,6 +260,7 @@ const ROW_FIELDS = {
|
|
|
201
260
|
ctx: nullable(Number.isFinite),
|
|
202
261
|
mass: Number.isFinite,
|
|
203
262
|
bar: Number.isFinite,
|
|
263
|
+
engine: (v) => ROUTING_ENGINES.includes(v),
|
|
204
264
|
observed: nullable(label),
|
|
205
265
|
requests: Number.isSafeInteger,
|
|
206
266
|
priced: Number.isSafeInteger,
|
|
@@ -214,6 +274,9 @@ function readRow(row) {
|
|
|
214
274
|
const out = {};
|
|
215
275
|
for (const [field, check] of Object.entries(ROW_FIELDS))
|
|
216
276
|
if (Object.hasOwn(row, field) && check(row[field])) out[field] = row[field];
|
|
277
|
+
if (out.engine === 'shadow' && readAlt(row.alt)) out.alt = readAlt(row.alt);
|
|
278
|
+
if (out.engine === 'auto' && readAlt(row.auto, true))
|
|
279
|
+
out.auto = { ...readAlt(row.auto, true), move: label(row.auto.move) };
|
|
217
280
|
return out;
|
|
218
281
|
}
|
|
219
282
|
|
|
@@ -259,6 +322,14 @@ const share = (p) => (Number.isFinite(p) ? ` ${Math.round(p * 100)}%` : '');
|
|
|
259
322
|
const weighed = (row) =>
|
|
260
323
|
Number.isFinite(row.mass) && Number.isFinite(row.bar) ? `${share(row.mass)} vs bar${share(row.bar)}` : '';
|
|
261
324
|
|
|
325
|
+
export function shadowLine(row) {
|
|
326
|
+
const alt = readAlt(row.alt);
|
|
327
|
+
if (row.engine !== 'shadow' || !alt) return null;
|
|
328
|
+
const cost =
|
|
329
|
+
alt.minUsd === null || alt.maxUsd === null ? 'unknown' : `$${alt.minUsd.toFixed(4)}–$${alt.maxUsd.toFixed(4)}`;
|
|
330
|
+
return `shadow demand ${alt.demand ?? '?'} (${alt.reason ?? '?'}${alt.headroom ? ', headroom' : ''}) → target ${alt.route ?? 'none'} cap ${alt.capability ?? 'unknown'}; ${alt.outcome ?? '?'}${alt.targetReason ? ` (${alt.targetReason})` : ''}; required ${alt.requirement ?? '?'}; next-turn estimate ${cost} (proposal only)`;
|
|
331
|
+
}
|
|
332
|
+
|
|
262
333
|
function endLine(row) {
|
|
263
334
|
const unpriced = Object.entries(row.unpriced ?? {})
|
|
264
335
|
.filter(([cause]) => cause !== 'comparison')
|
|
@@ -295,6 +366,10 @@ export function decisionLines(rows, n = 20) {
|
|
|
295
366
|
`-> ${row.tier ?? '-'}${row.activity ? ` ${row.activity}` : ''} ${row.route ?? ''}`.trimEnd(),
|
|
296
367
|
`(${row.reason ?? '?'}${weighed(row)})`,
|
|
297
368
|
row.pinned ? 'pinned' : null,
|
|
369
|
+
shadowLine(row),
|
|
370
|
+
row.engine === 'auto' && row.auto
|
|
371
|
+
? `demand ${row.auto.demand ?? '?'} → target ${row.auto.route ?? 'none'} cap ${row.auto.capability ?? 'unknown'}; ${row.auto.outcome}; move ${row.auto.move}; next-turn estimate ${row.auto.maxUsd === null ? 'unknown' : `$${row.auto.minUsd.toFixed(4)}–$${row.auto.maxUsd.toFixed(4)}`}`
|
|
372
|
+
: null,
|
|
298
373
|
]
|
|
299
374
|
.filter(Boolean)
|
|
300
375
|
.join(' ');
|
package/lib/display.mjs
CHANGED
|
@@ -18,13 +18,6 @@ import { modelSpec } from './savings.mjs';
|
|
|
18
18
|
import { readSubagentStore, summarizeSubagents } from './subagents.mjs';
|
|
19
19
|
import { periodRange, readUsage, summarize, withReplies } from './usage.mjs';
|
|
20
20
|
|
|
21
|
-
// Cost order, cheapest first, so the colors read as a scale. Hex values: every surface draws them.
|
|
22
|
-
export const TIER_COLOR = { micro: '#5fd7af', low: '#5f9fe0', medium: '#d7af5f', high: '#e0708a' };
|
|
23
|
-
// A subagent's square by the model family it ran on, apart from the tier colors so a model never reads as a tier.
|
|
24
|
-
const MODEL_COLOR = { haiku: '#c3e88d', sonnet: '#f78c6c', opus: '#c792ea', fable: '#89ddff' };
|
|
25
|
-
export const modelColor = (id) =>
|
|
26
|
-
Object.entries(MODEL_COLOR).find(([family]) => String(id ?? '').includes(family))?.[1] ?? null;
|
|
27
|
-
|
|
28
21
|
// The config as the view's routing mode routes it: the route texts name what runs, not the configured route. A view
|
|
29
22
|
// from before 1.15 has no mode and reads as balanced.
|
|
30
23
|
export const DEFAULT_ROUTING_MODE = { mode: 'balanced', source: 'default' };
|
|
@@ -146,6 +139,34 @@ export const missingCredentials = (config, view, id) => {
|
|
|
146
139
|
if (view.credentials && Object.hasOwn(view.credentials, id)) return view.credentials[id];
|
|
147
140
|
return config.classifiers[id].keyOption === null ? null : 'missing-key';
|
|
148
141
|
};
|
|
142
|
+
// The plugin's id as `claude plugin configure` takes it: `<name>@<marketplace>`, read from where an installed plugin's
|
|
143
|
+
// files are kept (…/plugins/cache/<marketplace>/<name>/<version>). A plugin loaded from elsewhere (`--plugin-dir`)
|
|
144
|
+
// has only its name.
|
|
145
|
+
//
|
|
146
|
+
// Where the path names no marketplace (a folder install), the one enabled `<name>@…` key of settings' `enabledPlugins`
|
|
147
|
+
// other than `@inline` names it: a disabled earlier install (`false`) is not a candidate. An id with anything but word
|
|
148
|
+
// characters, dots, `@` and `-` falls back to the name, so the command it goes into stays plain.
|
|
149
|
+
export function pluginIdOf({ name, root }, enabledPlugins = null) {
|
|
150
|
+
const parts = String(root ?? '').split(/[\\/]/);
|
|
151
|
+
const at = parts.lastIndexOf('cache');
|
|
152
|
+
const found = at > 0 && parts[at - 1] === 'plugins' && parts[at + 1] && parts[at + 2] === name;
|
|
153
|
+
const listed =
|
|
154
|
+
enabledPlugins && typeof enabledPlugins === 'object'
|
|
155
|
+
? Object.entries(enabledPlugins)
|
|
156
|
+
.filter(
|
|
157
|
+
([key, value]) =>
|
|
158
|
+
key.startsWith(`${name}@`) &&
|
|
159
|
+
key !== `${name}@inline` &&
|
|
160
|
+
value !== false &&
|
|
161
|
+
value !== null &&
|
|
162
|
+
value !== undefined,
|
|
163
|
+
)
|
|
164
|
+
.map(([key]) => key)
|
|
165
|
+
: [];
|
|
166
|
+
const id = found ? `${name}@${parts[at + 1]}` : listed.length === 1 ? listed[0] : name;
|
|
167
|
+
return /^[\w.@-]+$/.test(id) ? id : name;
|
|
168
|
+
}
|
|
169
|
+
|
|
149
170
|
// What classifier `id` lacks, named by the setting the person enters: "no API token", "no account ID".
|
|
150
171
|
export function missingText(config, id, missing) {
|
|
151
172
|
const entry = config.classifiers[id];
|
|
@@ -225,7 +246,7 @@ export function reasonActivity(config, view) {
|
|
|
225
246
|
activity: { choice: view.activityChoice, probabilities: view.activityProbabilities },
|
|
226
247
|
phase: { choice: view.phaseChoice, probabilities: view.phaseProbabilities },
|
|
227
248
|
});
|
|
228
|
-
return signal
|
|
249
|
+
return signal && signal.mass >= config.policy.activityMass ? signal.choice : null;
|
|
229
250
|
}
|
|
230
251
|
|
|
231
252
|
// The classifier's activity answer: its choice with the share it got and the two runners-up, or null when there is
|
|
@@ -298,7 +319,7 @@ export function storeAgreementLine(view) {
|
|
|
298
319
|
const share = ({ matched, total }) => `${matched} of ${total}`;
|
|
299
320
|
if (!agreement.total) return 'Tool compatibility across sessions: no labelled turns yet';
|
|
300
321
|
const all = `${share(agreement)} turns (${percent(agreement.matched / agreement.total)})`;
|
|
301
|
-
const code = focus.total ? ` · code/ops/explore ${share(focus)} (${percent(focus.matched / focus.total)})` : '';
|
|
322
|
+
const code = focus.total > 0 ? ` · code/ops/explore ${share(focus)} (${percent(focus.matched / focus.total)})` : '';
|
|
302
323
|
return `Tool compatibility across sessions (not accuracy): ${all}${code}`;
|
|
303
324
|
}
|
|
304
325
|
|
|
@@ -321,13 +342,9 @@ export function probeText(config, id) {
|
|
|
321
342
|
return `activity probe ${probe.correct}/${probe.probes} · p95 ${probe.p95Ms} ms · ${day}`;
|
|
322
343
|
}
|
|
323
344
|
|
|
324
|
-
// Routing vs no routing: less is green, more is amber, not red: a stronger model is a purchase, not a fault.
|
|
325
|
-
export const SAVINGS_COLOR = { less: '#6fcf97', more: '#f0b429' };
|
|
326
|
-
|
|
327
345
|
// "$6.40"; signed for a difference or a part: "−$1.84", "+$0.47", "$0.00".
|
|
328
346
|
export const usd = (value) => `$${Math.abs(value).toFixed(2)}`;
|
|
329
347
|
export const signedUsd = (value) => (value === 0 ? '$0.00' : `${value < 0 ? '−' : '+'}${usd(value)}`);
|
|
330
|
-
export const savingsColor = (value) => (value < 0 ? SAVINGS_COLOR.less : value > 0 ? SAVINGS_COLOR.more : undefined);
|
|
331
348
|
|
|
332
349
|
export const yourModel = (view) => routeLabel(view.nativeModel, view.nativeEffort);
|
|
333
350
|
const replyCount = (n, what = 'replies') => `${n} ${n === 1 ? what.replace(/ies$/, 'y') : what}`;
|
|
@@ -379,7 +396,7 @@ export function savingsLine(config, view, usage, now) {
|
|
|
379
396
|
const plan = cost.limits.map((l) => `${l.label} ${l.percent}%`).join(' · ');
|
|
380
397
|
const lines = plan ? [`Plan: ${plan}`] : [];
|
|
381
398
|
if (!cost.replies && !cost.agents) return [...lines, 'Session: no routed replies yet'].join('\n');
|
|
382
|
-
const split = cost.agents ? ` (main ${usd(cost.mainUsd)} + agents ${usd(cost.agentUsd)})` : '';
|
|
399
|
+
const split = cost.agents > 0 ? ` (main ${usd(cost.mainUsd)} + agents ${usd(cost.agentUsd)})` : '';
|
|
383
400
|
const credits = cost.creditsUsd ? ` · credits ${costText(cost.creditsUsd, cost.billing)}` : '';
|
|
384
401
|
const versus =
|
|
385
402
|
cost.diffUsd !== null
|
|
@@ -411,13 +428,16 @@ export function formatTokens(value) {
|
|
|
411
428
|
}
|
|
412
429
|
|
|
413
430
|
export function bar(value, maximum, width = 16) {
|
|
414
|
-
if (!Number.isFinite(value) || !(maximum > 0))
|
|
431
|
+
if (!Number.isFinite(value) || !(maximum > 0))
|
|
432
|
+
return { text: 'unknown', percent: null, tone: /** @type {import('./ui/tokens.mjs').Tone} */ ('muted') };
|
|
415
433
|
const fraction = Math.max(0, value / maximum);
|
|
416
434
|
const filled = Math.min(width, Math.round(fraction * width));
|
|
417
435
|
return {
|
|
418
436
|
text: `${'█'.repeat(filled)}${'░'.repeat(width - filled)}`,
|
|
419
437
|
percent: Math.round(fraction * 100),
|
|
420
|
-
|
|
438
|
+
tone: /** @type {import('./ui/tokens.mjs').Tone} */ (
|
|
439
|
+
fraction > 0.8 ? 'danger' : fraction > 0.6 ? 'warning' : 'success'
|
|
440
|
+
),
|
|
421
441
|
};
|
|
422
442
|
}
|
|
423
443
|
|
|
@@ -444,7 +464,9 @@ export function usageMetrics(config, view, usage) {
|
|
|
444
464
|
contextBar: bar(nextContext, window),
|
|
445
465
|
cacheBar: {
|
|
446
466
|
...bar(reuse, 1),
|
|
447
|
-
|
|
467
|
+
tone: /** @type {import('./ui/tokens.mjs').Tone} */ (
|
|
468
|
+
reuse === null ? 'muted' : reuse >= 0.6 ? 'success' : reuse >= 0.2 ? 'warning' : 'muted'
|
|
469
|
+
),
|
|
448
470
|
},
|
|
449
471
|
};
|
|
450
472
|
}
|
|
@@ -474,11 +496,32 @@ export function shortRoute(config, route) {
|
|
|
474
496
|
return `${shortModelName(model.id)}${effort ? `·${effort}` : ''}`;
|
|
475
497
|
}
|
|
476
498
|
|
|
499
|
+
// "Opus 5.5 · medium": a route as a card names it, in the words the editor's Selects show; "inherit" where it leaves
|
|
500
|
+
// the effort to the session, and no effort on a model without efforts. `short` names the family alone, "Opus ·
|
|
501
|
+
// medium", as a graphical pin and the band's pin Select do.
|
|
502
|
+
export function cardRoute(config, route, { short = false } = {}) {
|
|
503
|
+
const model = config.models[route.model];
|
|
504
|
+
if (!model) return route.model;
|
|
505
|
+
// A name that is all version, with nothing left once the numbers go, keeps them.
|
|
506
|
+
const name = (short && shortModelName(model.id)) || modelName(model.id);
|
|
507
|
+
return `${name}${model.efforts.length ? ` · ${route.effort ?? 'inherit'}` : ''}`;
|
|
508
|
+
}
|
|
509
|
+
|
|
477
510
|
// A tier as signal-strength bars, "▂▄▆" for medium: the band and pane draw the tier this way, never as a word, so the
|
|
478
511
|
// only "low" or "high" beside a model is its effort.
|
|
479
512
|
const METER = '▂▄▆█';
|
|
480
513
|
export const tierBars = (tier) => METER.slice(0, TIERS.indexOf(tier) + 1);
|
|
481
514
|
|
|
515
|
+
// What a pin button says it runs. The table engine runs the tier's configured route in every routing mode, so the label
|
|
516
|
+
// names it. Auto reads no route table: a pin sets only the demand and the cheapest capable model is chosen when the turn
|
|
517
|
+
// runs, so no label can name one in advance. There the terminal shows the bars alone and a card names the tier.
|
|
518
|
+
export const pinShort = (config, tier) =>
|
|
519
|
+
config.routingEngine === 'auto' ? '' : shortRoute(config, resolveRoute(config, tier));
|
|
520
|
+
export const pinCard = (config, tier) =>
|
|
521
|
+
config.routingEngine === 'auto'
|
|
522
|
+
? `${tier[0]?.toUpperCase()}${tier.slice(1)} tier`
|
|
523
|
+
: cardRoute(config, resolveRoute(config, tier), { short: true });
|
|
524
|
+
|
|
482
525
|
// All amounts price observed tokens at configured rates, irrespective of the billing product.
|
|
483
526
|
export const costText = (value, _billing) => `≈${usd(value)}`;
|
|
484
527
|
export const API_ESTIMATE = 'API estimate';
|
|
@@ -496,9 +539,6 @@ export function gaugeCells(fraction, cells) {
|
|
|
496
539
|
const filled = Math.min(cells, lit);
|
|
497
540
|
return ['▰'.repeat(filled), '▱'.repeat(cells - filled)];
|
|
498
541
|
}
|
|
499
|
-
// A plan window's colour by how much is used: green, then the warning colour past 75%, red past 90%.
|
|
500
|
-
export const limitColor = (percent) => (percent >= 90 ? 'red' : percent >= 75 ? SAVINGS_COLOR.more : 'green');
|
|
501
|
-
|
|
502
542
|
// This session's cost with its subagents and plan windows (costs.mjs periodCost).
|
|
503
543
|
export function sessionCost(config, view, usage, now) {
|
|
504
544
|
return periodCost(config, {
|
|
@@ -507,3 +547,12 @@ export function sessionCost(config, view, usage, now) {
|
|
|
507
547
|
usage,
|
|
508
548
|
});
|
|
509
549
|
}
|
|
550
|
+
|
|
551
|
+
// The classifier's state as the pane's title line says it: a warning with the error or the missing credential, or the
|
|
552
|
+
// classifier ready with its last latency. Null latency (NaN included) is left out.
|
|
553
|
+
export function classifierState(config, view) {
|
|
554
|
+
const error = view.error ?? missingCredentials(config, view, config.classifier);
|
|
555
|
+
if (error) return { tone: /** @type {const} */ ('warning'), text: classifierStatus(config, error) };
|
|
556
|
+
const latency = Number.isFinite(view.adviceMs) ? ` · ${view.adviceMs} ms` : '';
|
|
557
|
+
return { tone: /** @type {const} */ ('success'), text: `${classifierLabel(config)} ready${latency}` };
|
|
558
|
+
}
|
package/lib/facts.mjs
CHANGED
|
@@ -308,6 +308,7 @@ function runsCheck(words) {
|
|
|
308
308
|
// cheaper route on the same task waits for. False when none ran since, or the last one failed (an unresolved failure),
|
|
309
309
|
// or it went to the background, by request or after a timeout: its result reports the launch, not the check.
|
|
310
310
|
export function verifiedSince(messages, fromIndex) {
|
|
311
|
+
/** @type {{ id: string, index: number, background: boolean } | null} */
|
|
311
312
|
let last = null;
|
|
312
313
|
for (let i = Math.max(0, fromIndex); i < messages.length; i += 1)
|
|
313
314
|
if (messages[i]?.role === 'assistant')
|
|
@@ -366,6 +367,34 @@ export function completedSince(messages, fromIndex, activity) {
|
|
|
366
367
|
return false;
|
|
367
368
|
}
|
|
368
369
|
|
|
370
|
+
// Text-free checkpoint evidence for a replay's own switch cursor, not the recorded router's dwell.
|
|
371
|
+
export function progressEvidence(messages) {
|
|
372
|
+
const calls = callsSince(messages, 0);
|
|
373
|
+
const last = (predicate) => calls.findLast(({ block }) => predicate(block));
|
|
374
|
+
const check = last((block) => block.name === 'Bash' && verifies(block.input?.command));
|
|
375
|
+
const edit = last((block) => FILE_EDIT_TOOLS.has(block.name));
|
|
376
|
+
const run = last((block) => block.name === 'Bash' && ['ops', 'shell'].includes(commandKind(block.input?.command)));
|
|
377
|
+
const outcome = (call) => (call ? { index: call.index, ok: succeeded(messages, call) } : null);
|
|
378
|
+
/** @type {{ index: number, error: boolean } | null} */
|
|
379
|
+
let result = null;
|
|
380
|
+
messages.forEach((message, index) => {
|
|
381
|
+
if (message?.role === 'user')
|
|
382
|
+
for (const block of blocks(message.content))
|
|
383
|
+
if (block.type === 'tool_result') result = { index, error: block.is_error === true };
|
|
384
|
+
});
|
|
385
|
+
return {
|
|
386
|
+
check: outcome(check),
|
|
387
|
+
lastTool: calls.at(-1)?.index ?? -1,
|
|
388
|
+
delegate: last((block) => DELEGATING.has(block.name))?.index ?? -1,
|
|
389
|
+
anyCheck: last((block) => block.name === 'Bash' && runsAnyCheck(block.input?.command))?.index ?? -1,
|
|
390
|
+
edit: outcome(edit),
|
|
391
|
+
nonDocEdit: last((block) => FILE_EDIT_TOOLS.has(block.name) && !DOC_PATH.test(editPath(block)))?.index ?? -1,
|
|
392
|
+
run: outcome(run),
|
|
393
|
+
prompt: promptIndex(messages),
|
|
394
|
+
result,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
369
398
|
function callsSince(messages, fromIndex) {
|
|
370
399
|
const calls = [];
|
|
371
400
|
for (let i = Math.max(0, fromIndex); i < messages.length; i += 1)
|
|
@@ -375,6 +404,7 @@ function callsSince(messages, fromIndex) {
|
|
|
375
404
|
}
|
|
376
405
|
|
|
377
406
|
function lastResultSince(messages, fromIndex) {
|
|
407
|
+
/** @type {{ is_error?: boolean } | null} */
|
|
378
408
|
let last = null;
|
|
379
409
|
for (let i = Math.max(0, fromIndex); i < messages.length; i += 1)
|
|
380
410
|
if (messages[i]?.role === 'user')
|