@alexeiled/claude-router 1.1.1 → 1.3.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.
@@ -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
- CLASSIFIER,
5
- CLASSIFIER_ERRORS,
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,
@@ -13,8 +16,8 @@ import {
13
16
 
14
17
  export const TABS = [
15
18
  ['now', '1', 'Now'],
16
- ['tiers', '2', 'Tiers'],
17
- ['tuning', '3', 'Tuning'],
19
+ ['routing', '2', 'Routing'],
20
+ ['classifier', '3', 'Classifier'],
18
21
  ['usage', '4', 'Usage'],
19
22
  ];
20
23
  export const TUNING_CHOICES = {
@@ -41,7 +44,7 @@ export function routeName(config, route) {
41
44
  return `${modelName(model.id)}${model.efforts.length ? ` · ${route.effort ?? SESSION_EFFORT}` : ''}`;
42
45
  }
43
46
 
44
- // The draft the Tiers tab edits: the saved routes until the person changes one.
47
+ // The route draft the Routing tab edits: the saved routes until the person changes one.
45
48
  export function routeDraftOf(config, view) {
46
49
  if (view.routeDraft) return view.routeDraft;
47
50
  const base = structuredClone({ routes: config.routes, baselineTier: config.baselineTier });
@@ -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)
@@ -93,33 +97,33 @@ export function renderPanel(
93
97
  ) {
94
98
  const ui = kit(elements);
95
99
  const tab = TABS.some(([id]) => id === view.tab) ? view.tab : 'now';
96
- const body = { now: nowTab, tiers: tiersTab, tuning: tuningTab, usage: usageTab }[tab];
100
+ const body = { now: nowTab, routing: routingTab, classifier: classifierTab, usage: usageTab }[tab];
97
101
  return ui.Box({
98
102
  flexDirection: 'column',
99
103
  children: [
100
- ...header(ui, view, actions),
104
+ ...header(ui, config, view, tab, actions),
101
105
  ...body(ui, config, view, usage, actions, modelOptions),
102
106
  ...(view.help ? helpLines(ui) : []),
103
- view.notice ? ui.text(view.notice, { color: 'yellow' }) : null,
107
+ ...statusBar(ui, config, view, actions),
104
108
  ui.Button({ key: 'close', label: 'Close', hotkey: 'q', role: 'dismiss', onPress: actions.close }),
105
109
  ],
106
110
  });
107
111
  }
108
112
 
109
- function header(ui, view, actions) {
113
+ function header(ui, config, view, tab, actions) {
110
114
  const auto = view.mode === 'auto';
111
- const jev =
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
- : view.error
115
- ? ui.text(`${CLASSIFIER} ${CLASSIFIER_ERRORS[view.error] ?? view.error}`, { color: 'yellow' })
116
- : view.keySet
117
- ? ui.text(`${CLASSIFIER} ready${Number.isFinite(view.adviceMs) ? ` · ${view.adviceMs} ms` : ''}`, {
118
- color: 'green',
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'}`), ' ', jev),
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(
@@ -133,19 +137,20 @@ function header(ui, view, actions) {
133
137
  ' ',
134
138
  ui.Button({
135
139
  key: 'manual',
136
- label: 'Manual: keep /model',
140
+ label: 'Manual',
137
141
  hotkey: 'm',
138
142
  variant: auto ? 'secondary' : 'primary',
139
143
  onPress: () => actions.mode('manual'),
140
144
  }),
145
+ ui.dim(' Manual keeps the /model choice'),
141
146
  ),
142
147
  ui.line(
143
148
  ...TABS.flatMap(([id, hotkey, label]) => [
144
149
  ui.Button({
145
150
  key: `tab-${id}`,
146
- label,
151
+ label: id === 'routing' && routingChanges(config, view).count ? `${label} ●` : label,
147
152
  hotkey,
148
- variant: (view.tab ?? 'now') === id ? 'primary' : 'secondary',
153
+ variant: tab === id ? 'primary' : 'secondary',
149
154
  onPress: () => actions.tab(id),
150
155
  }),
151
156
  ' ',
@@ -160,6 +165,8 @@ function nowTab(ui, config, view, usage, actions) {
160
165
  const metrics = usageMetrics(config, view, usage);
161
166
  const auto = view.mode === 'auto';
162
167
  const current = view.selectedModel ?? view.nativeModel;
168
+ const label = classifierLabel(config);
169
+ const missing = missingCredentials(view, config.classifier);
163
170
  const served =
164
171
  view.actualModel && current && view.actualModel !== current && !view.actualModel.startsWith(`${current}-`);
165
172
  const out = [
@@ -181,15 +188,15 @@ function nowTab(ui, config, view, usage, actions) {
181
188
  ui.Button({ key: 'unpin', label: 'unpin', onPress: actions.unpin }),
182
189
  )
183
190
  : null,
184
- view.keySet
185
- ? null
186
- : ui.line(
187
- ui.text('Jev key not set: keeping the model ', { color: 'yellow' }),
188
- ui.Button({ key: 'key', label: 'Set Jev key', hotkey: 'k', onPress: actions.key }),
189
- ),
191
+ missing
192
+ ? ui.line(
193
+ ui.text(`${classifierStatus(config, missing)}, keeping the model `, { color: 'yellow' }),
194
+ ui.Button({ key: 'key', label: 'Set up', hotkey: 'k', onPress: actions.key }),
195
+ )
196
+ : null,
190
197
  ui.text(' '),
191
198
  ui.head('TIERS · next turn'),
192
- ui.dim(` ${'tier'.padEnd(8)}${'route'.padEnd(22)}Jev support`),
199
+ ui.dim(` ${'tier'.padEnd(8)}${'route'.padEnd(22)}${label} support`),
193
200
  ];
194
201
  for (const tier of LADDER) {
195
202
  const support = view.probabilities?.[tier];
@@ -201,12 +208,7 @@ function nowTab(ui, config, view, usage, actions) {
201
208
  routeName(config, config.routes[tier]).padEnd(22),
202
209
  meter ? ui.text(meter.text, { color: TIER_COLOR[tier] }) : ui.dim('—'.padEnd(10)),
203
210
  meter ? ` ${percent(support).padStart(4)} ` : ' ',
204
- ui.Button({
205
- key: `pin-${tier}`,
206
- label: 'pin',
207
- dimColor: !auto,
208
- onPress: () => actions.pin(tier),
209
- }),
211
+ auto ? ui.Button({ key: `pin-${tier}`, label: 'pin', onPress: () => actions.pin(tier) }) : null,
210
212
  ),
211
213
  );
212
214
  }
@@ -217,7 +219,7 @@ function nowTab(ui, config, view, usage, actions) {
217
219
  : ['down', estimate.downgradeMass];
218
220
  out.push(
219
221
  ui.dim(
220
- ` switch needs ${percent(estimate.threshold)} · Jev gave ${Number.isFinite(mass) ? percent(mass) : '—'} ${direction}` +
222
+ ` switch needs ${percent(estimate.threshold)} · ${label} gave ${Number.isFinite(mass) ? percent(mass) : '—'} ${direction}` +
221
223
  `${Number.isFinite(estimate.taxUsd) ? ` · tax ≈ $${estimate.taxUsd.toFixed(2)}` : ''}`,
222
224
  ),
223
225
  );
@@ -257,16 +259,40 @@ function replies(ui, view) {
257
259
  ];
258
260
  }
259
261
 
260
- function tiersTab(ui, config, view, _usage, actions, modelOptions) {
262
+ const POLICY_ROWS = [
263
+ ['downgradeVotes', 'Votes to go down', String, 'agreeing turns before cheaper', 'policy.downgradeVotes'],
264
+ ['horizon', 'Payback horizon', (v) => `${v} turns`, 'a switch repays its cache', 'policy.downgradeHorizonTurns'],
265
+ ['cashCapUsd', 'Credits cap', (v) => `$${v.toFixed(2)}`, 'max cold write on credits', 'policy.cashCapUsd'],
266
+ ];
267
+
268
+ // What the Routing tab changed and has not saved: tiers and baseline against the saved routes, policy values against
269
+ // the values the draft started from.
270
+ export function routingChanges(config, view) {
261
271
  const draft = effectiveRoutes(routeDraftOf(config, view), config);
272
+ const saved = tuningOf(config);
273
+ const base = view.tuningBase ?? saved;
274
+ const tuning = { ...saved, ...view.tuning };
275
+ const tiers = TIERS.filter((tier) => !sameRoute(draft.routes[tier], config.routes[tier]));
276
+ const baseline = draft.baselineTier !== config.baselineTier;
277
+ const policy = POLICY_ROWS.map(([key]) => key).filter(
278
+ (key) => Object.hasOwn(view.tuning ?? {}, key) && view.tuning[key] !== base[key],
279
+ );
280
+ return { draft, saved, tuning, tiers, baseline, policy, count: tiers.length + Number(baseline) + policy.length };
281
+ }
282
+
283
+ const marker = (ui, changed) => ui.cell(2, changed ? ui.text('●', { color: 'yellow' }) : '');
284
+
285
+ // Routes and policy are edited as one set: the switch-cost lines read the whole ladder, so nothing here is written
286
+ // until Save in the status bar.
287
+ function routingTab(ui, config, view, _usage, actions, modelOptions) {
288
+ const { draft, tuning, tiers, baseline, policy } = routingChanges(config, view);
262
289
  const out = [
263
- ui.head('ROUTES · future turns'),
264
- ui.dim(`${'tier'.padEnd(8)}${'model'.padEnd(14)}${'effort'.padEnd(12)}${'$/M in · out'.padEnd(14)}window`),
290
+ ui.line(ui.head('ROUTES'), ui.dim(' · applies next turn · edit, then Save')),
291
+ ui.dim(`${'tier'.padEnd(8)}${'model'.padEnd(14)}${'effort'.padEnd(14)}${'$/M in · out'.padEnd(14)}window`),
265
292
  ];
266
293
  for (const tier of LADDER) {
267
294
  const route = draft.routes[tier];
268
295
  const model = config.models[route.model];
269
- const changed = !sameRoute(route, config.routes[tier]);
270
296
  const aliases = modelOptions.includes(route.model) ? modelOptions : [route.model, ...modelOptions];
271
297
  out.push(
272
298
  ui.line(
@@ -295,24 +321,28 @@ function tiersTab(ui, config, view, _usage, actions, modelOptions) {
295
321
  })
296
322
  : (route.effort ?? SESSION_EFFORT),
297
323
  ),
324
+ marker(ui, tiers.includes(tier)),
298
325
  ui.cell(14, `${model.input} · ${model.output ?? '?'}`),
299
326
  windowSize(model.contextWindow),
300
- changed ? ui.text(' ●', { color: 'yellow' }) : null,
301
327
  ),
302
328
  );
303
329
  }
304
330
  out.push(
305
331
  ui.line(
306
- ui.Select
307
- ? ui.Select({
308
- key: 'baseline',
309
- label: 'Baseline tier',
310
- value: draft.baselineTier,
311
- options: TIERS.map((tier) => ({ value: tier, label: tier })),
312
- onSelect: (tier) => actions.baseline(tier),
313
- })
314
- : `Baseline tier: ${draft.baselineTier}`,
315
- ui.dim(' start here, fall back here'),
332
+ ui.cell(
333
+ 34,
334
+ ui.Select
335
+ ? ui.Select({
336
+ key: 'baseline',
337
+ label: 'Baseline tier',
338
+ value: draft.baselineTier,
339
+ options: TIERS.map((tier) => ({ value: tier, label: tier })),
340
+ onSelect: (tier) => actions.baseline(tier),
341
+ })
342
+ : `Baseline tier: ${draft.baselineTier}`,
343
+ ),
344
+ marker(ui, baseline),
345
+ ui.dim('start here, fall back here'),
316
346
  ),
317
347
  ui.text(' '),
318
348
  ui.head('SWITCH COST · from these routes'),
@@ -327,110 +357,148 @@ function tiersTab(ui, config, view, _usage, actions, modelOptions) {
327
357
  out.push(ui.line(ui.dim('· '), pair, 'same model, new effort: priced as a new cache'));
328
358
  else out.push(ui.line(ui.dim('· '), pair, 'model change: priced as a cold cache write'));
329
359
  }
330
- const changes = TIERS.filter((tier) => !sameRoute(draft.routes[tier], config.routes[tier]));
331
- const baselineChanged = draft.baselineTier !== config.baselineTier;
332
- const dirty = changes.length > 0 || baselineChanged;
333
- out.push(ui.text(' '));
334
- if (dirty) {
335
- out.push(ui.dim('router.json changes:'));
336
- for (const tier of changes) {
337
- out.push(ui.text(`- routes.${tier.padEnd(7)} ${routeName(config, config.routes[tier])}`, { color: 'red' }));
338
- out.push(ui.text(`+ routes.${tier.padEnd(7)} ${routeName(config, draft.routes[tier])}`, { color: 'green' }));
339
- }
340
- if (baselineChanged) {
341
- out.push(ui.text(`- baselineTier ${config.baselineTier}`, { color: 'red' }));
342
- out.push(ui.text(`+ baselineTier ${draft.baselineTier}`, { color: 'green' }));
343
- }
344
- } else out.push(ui.dim('No changes. Pick a model or an effort above.'));
345
360
  out.push(
361
+ ui.Button({ key: 'reset-routes', label: 'Reset routes to defaults', hotkey: 'r', onPress: actions.resetRoutes }),
362
+ ui.dim('A new model ID needs router.json → models: price, window, efforts.'),
363
+ ui.text(' '),
364
+ ui.line(ui.head('POLICY'), ui.dim(' · applies next turn · edit, then Save')),
365
+ ...POLICY_ROWS.map(([key, label, format, hint]) =>
366
+ ui.line(
367
+ ui.cell(20, label),
368
+ ui.cell(
369
+ 12,
370
+ choice(ui, key, tuning[key], format, (value) => actions.tune(key, value)),
371
+ ),
372
+ marker(ui, policy.includes(key)),
373
+ ui.dim(hint),
374
+ ),
375
+ ),
376
+ ui.Button({ key: 'reset-policy', label: 'Reset policy to defaults', onPress: actions.resetPolicy }),
377
+ ui.text(' '),
378
+ ui.head('CONFIG'),
346
379
  ui.line(
347
- ui.Button({
348
- key: 'save-routes',
349
- label: 'Save routes',
350
- hotkey: 's',
351
- variant: dirty ? 'primary' : 'secondary',
352
- dimColor: !dirty,
353
- onPress: actions.saveRoutes,
354
- }),
355
- ' ',
356
- ui.Button({ key: 'discard-routes', label: 'Discard', dimColor: !dirty, onPress: actions.discardRoutes }),
357
- ' ',
358
- ui.Button({ key: 'reset-routes', label: 'Reset to defaults', hotkey: 'r', onPress: actions.resetRoutes }),
380
+ `File ${view.configPath ?? 'profile router.json'} `,
381
+ view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
359
382
  ),
360
- ui.dim('A new model ID needs router.json → models: price, window, efforts.'),
383
+ ui.dim('Main conversation only. Subagents keep their own model.'),
361
384
  );
362
385
  return out;
363
386
  }
364
387
 
365
- function tuningTab(ui, config, view, _usage, actions) {
366
- const saved = tuningOf(config);
367
- const draft = { ...saved, ...view.tuning };
368
- const base = view.tuningBase ?? saved;
369
- const edited = (key) => Object.hasOwn(view.tuning ?? {}, key) && view.tuning[key] !== base[key];
370
- const rows = [
371
- ['timeoutMs', 'Jev deadline', (v) => `${v} ms`, 'then keep the model'],
372
- ['downgradeVotes', 'Votes to go down', String, 'agreeing turns before cheaper'],
373
- ['horizon', 'Payback horizon', (v) => `${v} turns`, 'a switch repays its cache'],
374
- ['cashCapUsd', 'Credits cap', (v) => `$${v.toFixed(2)}`, 'max cold write on credits'],
375
- ];
376
- const dirty = rows.some(([key]) => edited(key));
388
+ // A Select over TUNING_CHOICES[key], with a saved value outside them kept as the first option.
389
+ function choice(ui, key, value, format, pick) {
390
+ if (!ui.Select) return format(value);
391
+ const values = TUNING_CHOICES[key].includes(value) ? TUNING_CHOICES[key] : [value, ...TUNING_CHOICES[key]];
392
+ return ui.Select({
393
+ key,
394
+ value: String(value),
395
+ options: values.map((v) => ({ value: String(v), label: format(v) })),
396
+ onSelect: (picked) => (TUNING_CHOICES[key].includes(Number(picked)) ? pick(Number(picked)) : undefined),
397
+ });
398
+ }
399
+
400
+ // One row per configured classifier. A row press and the deadline are single values with nothing to review as a set,
401
+ // so each writes router.json at once; Undo in the status bar puts it back.
402
+ function classifierTab(ui, config, view, _usage, actions) {
403
+ const active = activeClassifier(config);
377
404
  const health = view.health ?? { failures: 0, pausedUntil: 0 };
378
- return [
379
- ui.head('POLICY · future turns'),
380
- ...rows.map(([key, label, format, hint]) => {
381
- const values = TUNING_CHOICES[key].includes(draft[key])
382
- ? TUNING_CHOICES[key]
383
- : [draft[key], ...TUNING_CHOICES[key]];
384
- return ui.line(
385
- ui.cell(18, label),
386
- ui.cell(
387
- 12,
388
- ui.Select
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]),
398
- ),
399
- ui.cell(2, edited(key) ? ui.text('●', { color: 'yellow' }) : ''),
400
- ui.dim(hint),
401
- );
402
- }),
403
- ui.line(
405
+ const rows = Object.entries(config.classifiers).map(([id, entry]) => {
406
+ const isActive = id === config.classifier;
407
+ const missing = missingCredentials(view, id);
408
+ return ui.line(
404
409
  ui.Button({
405
- key: 'save-tuning',
406
- label: 'Save tuning',
407
- variant: dirty ? 'primary' : 'secondary',
408
- dimColor: !dirty,
409
- onPress: actions.saveTuning,
410
+ key: `classifier-${id}`,
411
+ label: `${isActive ? '◉' : '○'} ${entry.label.padEnd(11)}`,
412
+ variant: isActive ? 'primary' : 'secondary',
413
+ onPress: () => actions.classifier(id),
410
414
  }),
411
415
  ' ',
412
- ui.Button({ key: 'reset-tuning', label: 'Discard', dimColor: !dirty, onPress: actions.resetTuning }),
413
- ),
414
- ui.text(' '),
415
- ui.head('JEV'),
416
+ ui.cell(20, ui.dim(hostOf(entry.endpoint))),
417
+ missing
418
+ ? ui.text(`○ ${missingText(config, id, missing)} `, { color: 'yellow' })
419
+ : ui.text('● ready', { color: 'green' }),
420
+ missing
421
+ ? ui.Button({ key: `key-${id}`, label: 'Set up', onPress: actions.key })
422
+ : isActive && Number.isFinite(view.adviceMs)
423
+ ? ui.dim(` ${view.adviceMs} ms`)
424
+ : null,
425
+ );
426
+ });
427
+ return [
428
+ ui.line(ui.head('CLASSIFIER'), ui.dim(' · applies next turn · saves at once')),
429
+ ui.dim('Asked once per new turn.'),
430
+ ...rows,
416
431
  ui.line(
417
- 'Key ',
418
- view.keySet ? ui.text('● configured ', { color: 'green' }) : ui.text('● not set ', { color: 'yellow' }),
419
- ui.Button({ key: 'key', label: view.keySet ? 'Edit key' : 'Set Jev key', hotkey: 'k', onPress: actions.key }),
432
+ ui.cell(9, 'Deadline'),
433
+ ui.cell(
434
+ 12,
435
+ choice(ui, 'timeoutMs', active.timeoutMs, (v) => `${v} ms`, actions.classifierTimeout),
436
+ ),
437
+ ui.dim('then keep the model'),
420
438
  ),
421
439
  ui.text(
422
440
  `Health ${health.pausedUntil > Date.now() ? `paused until ${new Date(health.pausedUntil).toLocaleTimeString()}` : 'active'} · ${health.failures} recent failure${health.failures === 1 ? '' : 's'}`,
423
441
  ),
424
- ui.text(' '),
425
- ui.head('CONFIG'),
442
+ ui.dim(`Sends prompt + ${config.context.recentTurns} recent turns → ${hostOf(active.endpoint)}`),
426
443
  ui.line(
427
- `File ${view.configPath ?? 'profile router.json'} `,
428
- view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
444
+ 'Credentials ',
445
+ ui.Button({ key: 'key', label: 'Edit', hotkey: 'k', onPress: actions.key }),
446
+ ui.dim(' opens /plugin configure'),
429
447
  ),
430
- ui.dim('Main conversation only. Subagents keep their own model.'),
448
+ ui.dim(` ${credentialsNeeded(config)}`),
431
449
  ];
432
450
  }
433
451
 
452
+ // Green for a write or its undo, red for a refused write, yellow for everything else that needs a look.
453
+ const noticeColor = (notice) =>
454
+ /^Not saved/.test(notice) ? 'red' : /^(Saved|Undid|Path copied)/.test(notice) ? 'green' : 'yellow';
455
+
456
+ // The one place for commit state on every tab: the unsaved routing diff with Save and Discard, the last notice, and
457
+ // Undo for the last write to router.json.
458
+ function statusBar(ui, config, view, actions) {
459
+ const changes = routingChanges(config, view);
460
+ const out = [];
461
+ if (changes.count) {
462
+ const diff = (key, before, after) => [
463
+ ui.text(`- ${key.padEnd(30)} ${before}`, { color: 'red' }),
464
+ ui.text(`+ ${key.padEnd(30)} ${after}`, { color: 'green' }),
465
+ ];
466
+ out.push(ui.text(' '), ui.dim('router.json changes:'));
467
+ for (const tier of changes.tiers)
468
+ out.push(
469
+ ...diff(
470
+ `routes.${tier}`,
471
+ routeName(config, config.routes[tier]),
472
+ routeName(config, changes.draft.routes[tier]),
473
+ ),
474
+ );
475
+ if (changes.baseline) out.push(...diff('baselineTier', config.baselineTier, changes.draft.baselineTier));
476
+ for (const [key, , format, , field] of POLICY_ROWS.filter(([key]) => changes.policy.includes(key)))
477
+ out.push(...diff(field, format(changes.saved[key]), format(changes.tuning[key])));
478
+ out.push(
479
+ ui.line(
480
+ ui.text(`● ${changes.count} unsaved routing change${changes.count === 1 ? '' : 's'} `, { color: 'yellow' }),
481
+ ui.Button({
482
+ key: 'save-routing',
483
+ label: 'Save',
484
+ hotkey: 's',
485
+ variant: 'primary',
486
+ onPress: actions.saveRouting,
487
+ }),
488
+ ' ',
489
+ ui.Button({ key: 'discard-routing', label: 'Discard', hotkey: 'd', onPress: actions.discardRouting }),
490
+ ),
491
+ );
492
+ }
493
+ const undo = view.lastWrite ? ui.Button({ key: 'undo', label: 'Undo', hotkey: 'u', onPress: actions.undo }) : null;
494
+ const confirmsWrite = Boolean(undo && view.notice?.startsWith('Saved'));
495
+ if (view.notice || undo) out.push(ui.text(' '));
496
+ if (view.notice)
497
+ out.push(ui.line(ui.text(`${view.notice} `, { color: noticeColor(view.notice) }), confirmsWrite ? undo : null));
498
+ if (undo && !confirmsWrite) out.push(ui.line(ui.dim(`Last change: ${view.lastWrite.label} `), undo));
499
+ return out;
500
+ }
501
+
434
502
  function usageTab(ui, config, view, usage) {
435
503
  const metrics = usageMetrics(config, view, usage);
436
504
  const history = view.history ?? [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alexeiled/claude-router",
3
- "version": "1.1.1",
4
- "description": "Native Claude Code Mod: Jev model and effort routing for the main conversation.",
3
+ "version": "1.3.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": {
@@ -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
- // Convert only retired gateway keys. All routing, pricing, cache and policy overrides survive unchanged.
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
- const backup = `${path}.v0.8.backup`;
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
- keySet?: boolean;
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,7 +60,9 @@ declare module 'claude-code' {
60
60
  tuning?: Partial<RouterTuning> | null;
61
61
  tuningBase?: RouterTuning | null;
62
62
  routeDraft?: (RouterRoutes & { base: RouterRoutes }) | null;
63
- tab?: 'now' | 'tiers' | 'tuning' | 'usage';
63
+ // The last pane write to router.json: each leaf it changed with the value the file had before, none if absent.
64
+ lastWrite?: { label: string; leaves: { path: string[]; value?: unknown }[] } | null;
65
+ tab?: 'now' | 'routing' | 'classifier' | 'usage';
64
66
  help?: boolean;
65
67
  bandDetail?: boolean;
66
68
  notice?: string | null;
@@ -1,62 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 594 477" role="img" aria-labelledby="title desc">
2
- <title id="title">Router pane, Tiers tab</title>
3
- <desc id="desc">Model and effort per tier with prices and windows, the baseline tier, how the policy prices each step up, and the router.json change Save routes will write.</desc>
4
- <style>
5
- text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; font-size: 13px; }
6
- .cap { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 12px; fill: #9a988f; }
7
- </style>
8
- <rect width="594" height="477" rx="8" fill="#1c1c1c"/>
9
- <rect x="10" y="10" width="574" height="457" rx="6" fill="none" stroke="#3f5f8f"/>
10
- <text x="24.0" y="34" fill="#5fafd7" font-weight="700" xml:space="preserve">ROUTER · Auto</text>
11
- <text x="148.8" y="34" fill="#87d787" xml:space="preserve">Jev ready · 347 ms</text>
12
- <text x="24.0" y="53" fill="#87afff" font-weight="700" xml:space="preserve">[ Auto ]</text>
13
- <text x="94.2" y="53" fill="#d0d0d0" xml:space="preserve">[ Manual: keep /model ]</text>
14
- <text x="24.0" y="72" fill="#d0d0d0" xml:space="preserve">[ Now ]</text>
15
- <text x="86.4" y="72" fill="#87afff" font-weight="700" xml:space="preserve">[ Tiers ]</text>
16
- <text x="164.4" y="72" fill="#d0d0d0" xml:space="preserve">[ Tuning ]</text>
17
- <text x="250.2" y="72" fill="#d0d0d0" xml:space="preserve">[ Usage ]</text>
18
- <text x="328.2" y="72" fill="#d0d0d0" xml:space="preserve">[ ? ]</text>
19
- <text x="24.0" y="110" fill="#5fafd7" font-weight="700" xml:space="preserve">ROUTES · future turns</text>
20
- <text x="24.0" y="129" fill="#7c7c7c" xml:space="preserve">tier model effort $/M in · out window</text>
21
- <text x="24.0" y="148" fill="#e0708a" font-weight="700" xml:space="preserve">high</text>
22
- <text x="86.4" y="148" fill="#d0d0d0" xml:space="preserve">Opus 5.5 ▾</text>
23
- <text x="195.6" y="148" fill="#d0d0d0" xml:space="preserve">xhigh ▾</text>
24
- <text x="289.2" y="148" fill="#d0d0d0" xml:space="preserve">4 · 20</text>
25
- <text x="398.4" y="148" fill="#d0d0d0" xml:space="preserve">1M</text>
26
- <text x="24.0" y="167" fill="#d7af5f" font-weight="700" xml:space="preserve">medium</text>
27
- <text x="86.4" y="167" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
28
- <text x="195.6" y="167" fill="#d0d0d0" xml:space="preserve">xhigh ▾</text>
29
- <text x="289.2" y="167" fill="#d0d0d0" xml:space="preserve">2 · 10</text>
30
- <text x="398.4" y="167" fill="#d0d0d0" xml:space="preserve">1M</text>
31
- <text x="414.0" y="167" fill="#d7af5f" xml:space="preserve"> ●</text>
32
- <text x="24.0" y="186" fill="#5f9fe0" font-weight="700" xml:space="preserve">low</text>
33
- <text x="86.4" y="186" fill="#d0d0d0" xml:space="preserve">Sonnet 5.5 ▾</text>
34
- <text x="195.6" y="186" fill="#d0d0d0" xml:space="preserve">session ▾</text>
35
- <text x="289.2" y="186" fill="#d0d0d0" xml:space="preserve">2 · 10</text>
36
- <text x="398.4" y="186" fill="#d0d0d0" xml:space="preserve">1M</text>
37
- <text x="24.0" y="205" fill="#5fd7af" font-weight="700" xml:space="preserve">micro</text>
38
- <text x="86.4" y="205" fill="#d0d0d0" xml:space="preserve">Haiku 4.5 ▾</text>
39
- <text x="195.6" y="205" fill="#7c7c7c" xml:space="preserve">none</text>
40
- <text x="289.2" y="205" fill="#d0d0d0" xml:space="preserve">1 · 5</text>
41
- <text x="398.4" y="205" fill="#d0d0d0" xml:space="preserve">200K</text>
42
- <text x="24.0" y="224" fill="#d0d0d0" xml:space="preserve">Baseline tier: low ▾</text>
43
- <text x="180.0" y="224" fill="#7c7c7c" xml:space="preserve"> start here, fall back here</text>
44
- <text x="24.0" y="262" fill="#5fafd7" font-weight="700" xml:space="preserve">SWITCH COST · from these routes</text>
45
- <text x="24.0" y="281" fill="#7c7c7c" xml:space="preserve">· </text>
46
- <text x="39.6" y="281" fill="#d0d0d0" xml:space="preserve">medium → high </text>
47
- <text x="164.4" y="281" fill="#d0d0d0" xml:space="preserve">model change: priced as a cold cache write</text>
48
- <text x="24.0" y="300" fill="#7c7c7c" xml:space="preserve">· </text>
49
- <text x="39.6" y="300" fill="#d0d0d0" xml:space="preserve">low → medium </text>
50
- <text x="164.4" y="300" fill="#d0d0d0" xml:space="preserve">same model, new effort: priced as a new cache</text>
51
- <text x="24.0" y="319" fill="#7c7c7c" xml:space="preserve">· </text>
52
- <text x="39.6" y="319" fill="#d0d0d0" xml:space="preserve">micro → low </text>
53
- <text x="164.4" y="319" fill="#d0d0d0" xml:space="preserve">model change: priced as a cold cache write</text>
54
- <text x="24.0" y="357" fill="#7c7c7c" xml:space="preserve">router.json changes:</text>
55
- <text x="24.0" y="376" fill="#e06c6c" xml:space="preserve">- routes.medium Opus 5.5 · medium</text>
56
- <text x="24.0" y="395" fill="#87d787" xml:space="preserve">+ routes.medium Sonnet 5.5 · xhigh</text>
57
- <text x="24.0" y="414" fill="#87afff" font-weight="700" xml:space="preserve">[ Save routes ]</text>
58
- <text x="148.8" y="414" fill="#d0d0d0" xml:space="preserve">[ Discard ]</text>
59
- <text x="242.4" y="414" fill="#d0d0d0" xml:space="preserve">[ Reset to defaults ]</text>
60
- <text x="24.0" y="433" fill="#7c7c7c" xml:space="preserve">A new model ID needs router.json → models: price, window, efforts.</text>
61
- <text x="24.0" y="452" fill="#d0d0d0" xml:space="preserve">[ Close ]</text>
62
- </svg>