@alexeiled/claude-router 1.1.0 → 1.2.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 +15 -4
- package/CHANGELOG.md +25 -0
- package/README.md +15 -9
- package/docs/architecture.md +25 -22
- package/docs/configuration.md +76 -22
- package/docs/native-router.md +20 -15
- package/docs/router-band.svg +14 -14
- package/docs/router-pane-tuning.svg +58 -0
- package/docs/user-guide.md +55 -27
- package/hooks/native-router.mjs +135 -31
- package/lib/config.mjs +107 -27
- package/lib/jev-contract.mjs +25 -6
- package/lib/native-band.mjs +31 -14
- package/lib/native-display.mjs +34 -3
- package/lib/native-jev.mjs +7 -5
- package/lib/native-panel.mjs +107 -51
- package/lib/policy.mjs +15 -8
- package/package.json +3 -2
- package/scripts/migrate-config.mjs +14 -3
- package/types/index.d.ts +5 -3
package/lib/native-panel.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { effectiveRoutes, sameRoute, TIERS, tuningOf } from './config.mjs';
|
|
1
|
+
import { activeClassifier, effectiveRoutes, sameRoute, TIERS, tuningOf } from './config.mjs';
|
|
2
2
|
import {
|
|
3
3
|
bar,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
classifierLabel,
|
|
5
|
+
classifierStatus,
|
|
6
|
+
credentialsNeeded,
|
|
6
7
|
formatTokens,
|
|
7
8
|
GATEWAY_CLEANUP,
|
|
8
9
|
GATEWAY_SETTINGS,
|
|
10
|
+
missingCredentials,
|
|
11
|
+
missingText,
|
|
9
12
|
REASONS,
|
|
10
13
|
sparkline,
|
|
11
14
|
usageMetrics,
|
|
@@ -51,6 +54,7 @@ export function routeDraftOf(config, view) {
|
|
|
51
54
|
const dollars = (value) => (Number.isFinite(value) ? `$${value.toFixed(3)}` : 'not reported');
|
|
52
55
|
const difference = (value) => `${value < 0 ? '−' : '+'}$${Math.abs(value).toFixed(3)}`;
|
|
53
56
|
const percent = (value) => `${Math.round(value * 100)}%`;
|
|
57
|
+
const hostOf = (endpoint) => endpoint.replace(/^https?:\/\//, '').split('/')[0];
|
|
54
58
|
const windowSize = (tokens) => (tokens >= 1e6 ? `${tokens / 1e6}M` : `${Math.round(tokens / 1e3)}K`);
|
|
55
59
|
const contextSuffix = (metrics) =>
|
|
56
60
|
Number.isFinite(metrics.nextContext)
|
|
@@ -97,7 +101,7 @@ export function renderPanel(
|
|
|
97
101
|
return ui.Box({
|
|
98
102
|
flexDirection: 'column',
|
|
99
103
|
children: [
|
|
100
|
-
...header(ui, view, actions),
|
|
104
|
+
...header(ui, config, view, actions),
|
|
101
105
|
...body(ui, config, view, usage, actions, modelOptions),
|
|
102
106
|
...(view.help ? helpLines(ui) : []),
|
|
103
107
|
view.notice ? ui.text(view.notice, { color: 'yellow' }) : null,
|
|
@@ -106,20 +110,20 @@ export function renderPanel(
|
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
function header(ui, view, actions) {
|
|
113
|
+
function header(ui, config, view, actions) {
|
|
110
114
|
const auto = view.mode === 'auto';
|
|
111
|
-
const
|
|
115
|
+
const label = classifierLabel(config);
|
|
116
|
+
const error = view.error ?? missingCredentials(view, config.classifier);
|
|
117
|
+
const status =
|
|
112
118
|
view.phase === 'unavailable'
|
|
113
119
|
? ui.text('Routing unavailable', { color: 'yellow' })
|
|
114
|
-
:
|
|
115
|
-
? ui.text(
|
|
116
|
-
: view.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
120
|
-
: ui.text(`${CLASSIFIER} key not set`, { color: 'yellow' });
|
|
120
|
+
: error
|
|
121
|
+
? ui.text(classifierStatus(config, error), { color: 'yellow' })
|
|
122
|
+
: ui.text(`${label} ready${Number.isFinite(view.adviceMs) ? ` · ${view.adviceMs} ms` : ''}`, {
|
|
123
|
+
color: 'green',
|
|
124
|
+
});
|
|
121
125
|
return [
|
|
122
|
-
ui.line(ui.head(`ROUTER · ${auto ? 'Auto' : 'Manual'}`), ' ',
|
|
126
|
+
ui.line(ui.head(`ROUTER · ${auto ? 'Auto' : 'Manual'}`), ' ', status),
|
|
123
127
|
view.phase === 'unavailable' && view.error ? ui.text(view.error, { color: 'yellow' }) : null,
|
|
124
128
|
...(view.error === GATEWAY_SETTINGS ? GATEWAY_CLEANUP.map((line) => ui.text(line, { color: 'yellow' })) : []),
|
|
125
129
|
ui.line(
|
|
@@ -160,6 +164,8 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
160
164
|
const metrics = usageMetrics(config, view, usage);
|
|
161
165
|
const auto = view.mode === 'auto';
|
|
162
166
|
const current = view.selectedModel ?? view.nativeModel;
|
|
167
|
+
const label = classifierLabel(config);
|
|
168
|
+
const missing = missingCredentials(view, config.classifier);
|
|
163
169
|
const served =
|
|
164
170
|
view.actualModel && current && view.actualModel !== current && !view.actualModel.startsWith(`${current}-`);
|
|
165
171
|
const out = [
|
|
@@ -181,15 +187,15 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
181
187
|
ui.Button({ key: 'unpin', label: 'unpin', onPress: actions.unpin }),
|
|
182
188
|
)
|
|
183
189
|
: null,
|
|
184
|
-
|
|
185
|
-
?
|
|
186
|
-
|
|
187
|
-
ui.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
missing
|
|
191
|
+
? ui.line(
|
|
192
|
+
ui.text(`${classifierStatus(config, missing)}, keeping the model `, { color: 'yellow' }),
|
|
193
|
+
ui.Button({ key: 'key', label: 'Set up', hotkey: 'k', onPress: actions.key }),
|
|
194
|
+
)
|
|
195
|
+
: null,
|
|
190
196
|
ui.text(' '),
|
|
191
197
|
ui.head('TIERS · next turn'),
|
|
192
|
-
ui.dim(` ${'tier'.padEnd(8)}${'route'.padEnd(22)}
|
|
198
|
+
ui.dim(` ${'tier'.padEnd(8)}${'route'.padEnd(22)}${label} support`),
|
|
193
199
|
];
|
|
194
200
|
for (const tier of LADDER) {
|
|
195
201
|
const support = view.probabilities?.[tier];
|
|
@@ -217,7 +223,7 @@ function nowTab(ui, config, view, usage, actions) {
|
|
|
217
223
|
: ['down', estimate.downgradeMass];
|
|
218
224
|
out.push(
|
|
219
225
|
ui.dim(
|
|
220
|
-
` switch needs ${percent(estimate.threshold)} ·
|
|
226
|
+
` switch needs ${percent(estimate.threshold)} · ${label} gave ${Number.isFinite(mass) ? percent(mass) : '—'} ${direction}` +
|
|
221
227
|
`${Number.isFinite(estimate.taxUsd) ? ` · tax ≈ $${estimate.taxUsd.toFixed(2)}` : ''}`,
|
|
222
228
|
),
|
|
223
229
|
);
|
|
@@ -368,38 +374,26 @@ function tuningTab(ui, config, view, _usage, actions) {
|
|
|
368
374
|
const base = view.tuningBase ?? saved;
|
|
369
375
|
const edited = (key) => Object.hasOwn(view.tuning ?? {}, key) && view.tuning[key] !== base[key];
|
|
370
376
|
const rows = [
|
|
371
|
-
['timeoutMs', 'Jev deadline', (v) => `${v} ms`, 'then keep the model'],
|
|
372
377
|
['downgradeVotes', 'Votes to go down', String, 'agreeing turns before cheaper'],
|
|
373
378
|
['horizon', 'Payback horizon', (v) => `${v} turns`, 'a switch repays its cache'],
|
|
374
379
|
['cashCapUsd', 'Credits cap', (v) => `$${v.toFixed(2)}`, 'max cold write on credits'],
|
|
375
380
|
];
|
|
376
381
|
const dirty = rows.some(([key]) => edited(key));
|
|
377
|
-
const health = view.health ?? { failures: 0, pausedUntil: 0 };
|
|
378
382
|
return [
|
|
383
|
+
...classifierSection(ui, config, view, actions),
|
|
384
|
+
ui.text(' '),
|
|
379
385
|
ui.head('POLICY · future turns'),
|
|
380
|
-
...rows.map(([key, label, format, hint]) =>
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
: [draft[key], ...TUNING_CHOICES[key]];
|
|
384
|
-
return ui.line(
|
|
385
|
-
ui.cell(18, label),
|
|
386
|
+
...rows.map(([key, label, format, hint]) =>
|
|
387
|
+
ui.line(
|
|
388
|
+
ui.cell(20, label),
|
|
386
389
|
ui.cell(
|
|
387
390
|
12,
|
|
388
|
-
ui.
|
|
389
|
-
? ui.Select({
|
|
390
|
-
key,
|
|
391
|
-
value: String(draft[key]),
|
|
392
|
-
options: values.map((value) => ({ value: String(value), label: format(value) })),
|
|
393
|
-
onSelect: (picked) => {
|
|
394
|
-
if (TUNING_CHOICES[key].includes(Number(picked))) actions.tune(key, Number(picked));
|
|
395
|
-
},
|
|
396
|
-
})
|
|
397
|
-
: format(draft[key]),
|
|
391
|
+
choice(ui, key, draft[key], format, (value) => actions.tune(key, value)),
|
|
398
392
|
),
|
|
399
393
|
ui.cell(2, edited(key) ? ui.text('●', { color: 'yellow' }) : ''),
|
|
400
394
|
ui.dim(hint),
|
|
401
|
-
)
|
|
402
|
-
|
|
395
|
+
),
|
|
396
|
+
),
|
|
403
397
|
ui.line(
|
|
404
398
|
ui.Button({
|
|
405
399
|
key: 'save-tuning',
|
|
@@ -412,22 +406,84 @@ function tuningTab(ui, config, view, _usage, actions) {
|
|
|
412
406
|
ui.Button({ key: 'reset-tuning', label: 'Discard', dimColor: !dirty, onPress: actions.resetTuning }),
|
|
413
407
|
),
|
|
414
408
|
ui.text(' '),
|
|
415
|
-
ui.head('
|
|
409
|
+
ui.head('CONFIG'),
|
|
410
|
+
ui.line(
|
|
411
|
+
`File ${view.configPath ?? 'profile router.json'} `,
|
|
412
|
+
view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
|
|
413
|
+
),
|
|
414
|
+
ui.dim('Main conversation only. Subagents keep their own model.'),
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// A Select over TUNING_CHOICES[key], with a saved value outside them kept as the first option.
|
|
419
|
+
function choice(ui, key, value, format, pick) {
|
|
420
|
+
if (!ui.Select) return format(value);
|
|
421
|
+
const values = TUNING_CHOICES[key].includes(value) ? TUNING_CHOICES[key] : [value, ...TUNING_CHOICES[key]];
|
|
422
|
+
return ui.Select({
|
|
423
|
+
key,
|
|
424
|
+
value: String(value),
|
|
425
|
+
options: values.map((v) => ({ value: String(v), label: format(v) })),
|
|
426
|
+
onSelect: (picked) => (TUNING_CHOICES[key].includes(Number(picked)) ? pick(Number(picked)) : undefined),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// One row per configured classifier: pressing a row makes it active at once, written to router.json, with Undo. The
|
|
431
|
+
// deadline belongs to the active classifier and saves at once too; the policy below keeps its draft and Save.
|
|
432
|
+
function classifierSection(ui, config, view, actions) {
|
|
433
|
+
const active = activeClassifier(config);
|
|
434
|
+
const health = view.health ?? { failures: 0, pausedUntil: 0 };
|
|
435
|
+
const undo = view.classifierUndo;
|
|
436
|
+
const rows = Object.entries(config.classifiers).map(([id, entry]) => {
|
|
437
|
+
const isActive = id === config.classifier;
|
|
438
|
+
const missing = missingCredentials(view, id);
|
|
439
|
+
return ui.line(
|
|
440
|
+
ui.Button({
|
|
441
|
+
key: `classifier-${id}`,
|
|
442
|
+
label: `${isActive ? '◉' : '○'} ${entry.label.padEnd(11)}`,
|
|
443
|
+
variant: isActive ? 'primary' : 'secondary',
|
|
444
|
+
onPress: () => actions.classifier(id),
|
|
445
|
+
}),
|
|
446
|
+
' ',
|
|
447
|
+
ui.cell(20, ui.dim(hostOf(entry.endpoint))),
|
|
448
|
+
missing
|
|
449
|
+
? ui.text(`○ ${missingText(config, id, missing)} `, { color: 'yellow' })
|
|
450
|
+
: ui.text('● ready', { color: 'green' }),
|
|
451
|
+
missing
|
|
452
|
+
? ui.Button({ key: `key-${id}`, label: 'Set up', onPress: actions.key })
|
|
453
|
+
: isActive && Number.isFinite(view.adviceMs)
|
|
454
|
+
? ui.dim(` ${view.adviceMs} ms`)
|
|
455
|
+
: null,
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
return [
|
|
459
|
+
ui.head('CLASSIFIER · asked once per new turn'),
|
|
460
|
+
...rows,
|
|
461
|
+
undo && undo !== config.classifier && Object.hasOwn(config.classifiers, undo)
|
|
462
|
+
? ui.line(
|
|
463
|
+
ui.text(`Switched from ${config.classifiers[undo].label}: ${active.label} from the next turn `, {
|
|
464
|
+
color: 'yellow',
|
|
465
|
+
}),
|
|
466
|
+
ui.Button({ key: 'undo-classifier', label: 'Undo', onPress: actions.undoClassifier }),
|
|
467
|
+
)
|
|
468
|
+
: null,
|
|
416
469
|
ui.line(
|
|
417
|
-
'
|
|
418
|
-
|
|
419
|
-
|
|
470
|
+
ui.cell(9, 'Deadline'),
|
|
471
|
+
ui.cell(
|
|
472
|
+
12,
|
|
473
|
+
choice(ui, 'timeoutMs', active.timeoutMs, (v) => `${v} ms`, actions.classifierTimeout),
|
|
474
|
+
),
|
|
475
|
+
ui.dim('then keep the model'),
|
|
420
476
|
),
|
|
421
477
|
ui.text(
|
|
422
478
|
`Health ${health.pausedUntil > Date.now() ? `paused until ${new Date(health.pausedUntil).toLocaleTimeString()}` : 'active'} · ${health.failures} recent failure${health.failures === 1 ? '' : 's'}`,
|
|
423
479
|
),
|
|
424
|
-
ui.
|
|
425
|
-
ui.head('CONFIG'),
|
|
480
|
+
ui.dim(`Sends prompt + ${config.context.recentTurns} recent turns → ${hostOf(active.endpoint)}`),
|
|
426
481
|
ui.line(
|
|
427
|
-
|
|
428
|
-
|
|
482
|
+
'Credentials ',
|
|
483
|
+
ui.Button({ key: 'key', label: 'Edit', hotkey: 'k', onPress: actions.key }),
|
|
484
|
+
ui.dim(' opens /plugin configure'),
|
|
429
485
|
),
|
|
430
|
-
ui.dim(
|
|
486
|
+
ui.dim(` ${credentialsNeeded(config)}`),
|
|
431
487
|
];
|
|
432
488
|
}
|
|
433
489
|
|
package/lib/policy.mjs
CHANGED
|
@@ -16,7 +16,9 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
|
|
|
16
16
|
next.escalatedSignature = facts.failure.signature;
|
|
17
17
|
next.holdUntilTurn = next.turn + config.policy.escalationHoldTurns;
|
|
18
18
|
next.votes = [];
|
|
19
|
-
|
|
19
|
+
const target = TIERS[rank(incumbent) + 1];
|
|
20
|
+
const gated = cashGate(config, target, facts, now, costs);
|
|
21
|
+
return gated.blocked ? gatedResult(gated, incumbent, next) : result(target, 'escalation', next);
|
|
20
22
|
}
|
|
21
23
|
if (next.turn <= next.holdUntilTurn) return stay('hold');
|
|
22
24
|
if (!advice) return stay('no-advice');
|
|
@@ -30,10 +32,7 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
|
|
|
30
32
|
if (rank(choice) > rank(incumbent)) {
|
|
31
33
|
const upgrade = massAbove(advice.probabilities, incumbent);
|
|
32
34
|
const gated = cashGate(config, choice, facts, now, costs);
|
|
33
|
-
if (gated.blocked)
|
|
34
|
-
if (!gated.fallback || rank(gated.fallback) <= rank(incumbent)) return stay('cash-gate', gated.estimate);
|
|
35
|
-
return result(gated.fallback, 'cash-gate', next, gated.estimate);
|
|
36
|
-
}
|
|
35
|
+
if (gated.blocked) return gatedResult(gated, incumbent, next);
|
|
37
36
|
const tax = Math.max(0, costs.switchingTaxUsd(config, choice, incumbent, facts, now));
|
|
38
37
|
const threshold =
|
|
39
38
|
config.policy.upgradeBase + config.policy.upgradeSlope * (tax / (tax + config.policy.upgradePivotUsd));
|
|
@@ -57,8 +56,10 @@ export function decide({ config, facts, advice, state, baseline, now, costs = na
|
|
|
57
56
|
const threshold =
|
|
58
57
|
config.policy.downgradeMass + config.policy.downgradeSlope * (tax / (tax + config.policy.downgradePivotUsd));
|
|
59
58
|
const estimate = { downgradeMass: support, streak, taxUsd: tax, threshold };
|
|
60
|
-
if (support >= threshold && streak >= config.policy.downgradeVotes)
|
|
61
|
-
|
|
59
|
+
if (support >= threshold && streak >= config.policy.downgradeVotes) {
|
|
60
|
+
const gated = cashGate(config, choice, facts, now, costs);
|
|
61
|
+
return gated.blocked ? gatedResult(gated, incumbent, next) : result(choice, 'downgrade', next, estimate);
|
|
62
|
+
}
|
|
62
63
|
return stay('downgrade-pending', estimate);
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -79,7 +80,7 @@ export function fitTier(config, tier, tokens) {
|
|
|
79
80
|
);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
// Cold-write guard: an automatic route to a credits-billed model whose cache is not warm must not start with a cache
|
|
83
|
+
// Cold-write guard: an automatic route (upgrade, downgrade or escalation) to a credits-billed model whose cache is not warm must not start with a cache
|
|
83
84
|
// write above `cashCapUsd`. It bounds that one estimated write, not the spend of the turn: a warm cache passes, and
|
|
84
85
|
// output is not counted.
|
|
85
86
|
function cashGate(config, tier, facts, now, costs) {
|
|
@@ -94,6 +95,12 @@ function cashGate(config, tier, facts, now, costs) {
|
|
|
94
95
|
return { blocked: true, fallback, estimate };
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
// A blocked switch lands on the strongest plan tier when that is above the incumbent, else stays.
|
|
99
|
+
function gatedResult(gated, incumbent, state) {
|
|
100
|
+
const tier = gated.fallback && rank(gated.fallback) > rank(incumbent) ? gated.fallback : incumbent;
|
|
101
|
+
return result(tier, 'cash-gate', state, gated.estimate);
|
|
102
|
+
}
|
|
103
|
+
|
|
97
104
|
function cacheOf(config, tier, facts, now, costs) {
|
|
98
105
|
return costs.cacheState(facts.models[costs.routeCacheKey(config, tier, facts.effort)], now, config.cache);
|
|
99
106
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Native Claude Code Mod:
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Native Claude Code Mod: model and effort routing for the main conversation, advised by Jev, Clef or Clef Flash.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|
|
7
7
|
"repository": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"test": "node --test --test-timeout=8000 test/*.test.mjs",
|
|
32
32
|
"check": "biome check lib scripts test hooks types .claude-plugin package.json package-lock.json biome.json experiments/mod-router",
|
|
33
33
|
"validate": "claude plugin validate .claude-plugin/plugin.json && claude plugin validate .claude-plugin/marketplace.json",
|
|
34
|
+
"test:plugin": "bash scripts/plugin-test.sh",
|
|
34
35
|
"format": "biome format --write .",
|
|
35
36
|
"docs:images": "node scripts/render-doc-images.mjs",
|
|
36
37
|
"pack:dry": "npm pack --dry-run",
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { loadConfig } from '../lib/config.mjs';
|
|
4
|
+
import { isGatewayLayout, loadConfig } from '../lib/config.mjs';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const JEV_KEYS = ['endpoint', 'model', 'timeoutMs'];
|
|
7
|
+
|
|
8
|
+
// Convert only retired keys: the 0.8 gateway settings and the 1.1 `jev` section, which becomes `classifiers.jev`.
|
|
9
|
+
// All routing, pricing, cache and policy overrides survive unchanged.
|
|
7
10
|
export function migrateConfig(file) {
|
|
8
11
|
if (!file || typeof file !== 'object' || Array.isArray(file)) throw new Error('router.json must be an object');
|
|
9
12
|
const next = structuredClone(file);
|
|
@@ -21,6 +24,13 @@ export function migrateConfig(file) {
|
|
|
21
24
|
delete next.gateway;
|
|
22
25
|
}
|
|
23
26
|
delete next.log;
|
|
27
|
+
if (Object.hasOwn(next, 'jev')) {
|
|
28
|
+
const jev = next.jev;
|
|
29
|
+
if (!jev || typeof jev !== 'object' || Array.isArray(jev)) throw new Error('jev must be an object');
|
|
30
|
+
for (const key of Object.keys(jev)) if (!JEV_KEYS.includes(key)) throw new Error(`jev.${key} is not a known key`);
|
|
31
|
+
if (Object.keys(jev).length) next.classifiers = { ...next.classifiers, jev: { ...next.classifiers?.jev, ...jev } };
|
|
32
|
+
delete next.jev;
|
|
33
|
+
}
|
|
24
34
|
if (next.models && typeof next.models === 'object' && !Array.isArray(next.models)) {
|
|
25
35
|
for (const model of Object.values(next.models)) {
|
|
26
36
|
if (model && typeof model === 'object' && !Array.isArray(model)) {
|
|
@@ -38,7 +48,8 @@ export async function migrateFile(path) {
|
|
|
38
48
|
const file = JSON.parse(original);
|
|
39
49
|
const next = migrateConfig(file);
|
|
40
50
|
if (JSON.stringify(file) === JSON.stringify(next)) return null;
|
|
41
|
-
|
|
51
|
+
// Named for the layout it keeps, so a 1.1 migration never collides with a 0.8 backup already on disk.
|
|
52
|
+
const backup = `${path}.${isGatewayLayout(file) ? 'v0.8' : 'v1.1'}.backup`;
|
|
42
53
|
await writeFile(backup, original, { flag: 'wx', mode: 0o600 });
|
|
43
54
|
await writeFile(path, `${JSON.stringify(next, null, 2)}\n`);
|
|
44
55
|
return backup;
|
package/types/index.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ declare module 'claude-code' {
|
|
|
20
20
|
cache?: RouterCacheState | { candidate: RouterCacheState; incumbent: RouterCacheState };
|
|
21
21
|
}
|
|
22
22
|
interface RouterTuning {
|
|
23
|
-
timeoutMs: number;
|
|
24
23
|
downgradeVotes: number;
|
|
25
24
|
horizon: number;
|
|
26
25
|
cashCapUsd: number;
|
|
@@ -41,14 +40,15 @@ declare module 'claude-code' {
|
|
|
41
40
|
reason?: string;
|
|
42
41
|
error?: string | null;
|
|
43
42
|
pendingPin?: RouterTier | null;
|
|
44
|
-
|
|
43
|
+
// Per classifier id: what its credentials lack, or null when complete.
|
|
44
|
+
credentials?: Record<string, 'missing-key' | 'missing-account' | null> | null;
|
|
45
45
|
contextTokens?: number | null;
|
|
46
46
|
contextKnown?: boolean;
|
|
47
47
|
cacheRead?: number | null;
|
|
48
48
|
cacheWrite?: number | null;
|
|
49
49
|
inputTokens?: number | null;
|
|
50
50
|
outputTokens?: number | null;
|
|
51
|
-
health?: { failures: number; pausedUntil: number };
|
|
51
|
+
health?: { failures: number; pausedUntil: number; classifier?: string };
|
|
52
52
|
adviceMs?: number | null;
|
|
53
53
|
adviceChoice?: RouterTier | 'uncertain' | null;
|
|
54
54
|
estimate?: RouterEstimate | null;
|
|
@@ -60,6 +60,8 @@ declare module 'claude-code' {
|
|
|
60
60
|
tuning?: Partial<RouterTuning> | null;
|
|
61
61
|
tuningBase?: RouterTuning | null;
|
|
62
62
|
routeDraft?: (RouterRoutes & { base: RouterRoutes }) | null;
|
|
63
|
+
// The classifier Undo returns to after a switch in the pane.
|
|
64
|
+
classifierUndo?: string | null;
|
|
63
65
|
tab?: 'now' | 'tiers' | 'tuning' | 'usage';
|
|
64
66
|
help?: boolean;
|
|
65
67
|
bandDetail?: boolean;
|