@alexeiled/claude-router 1.1.1 → 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.
@@ -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,
@@ -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 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(
@@ -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
- 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
- ),
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)}Jev support`),
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)} · Jev gave ${Number.isFinite(mass) ? percent(mass) : '—'} ${direction}` +
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
- 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
+ ...rows.map(([key, label, format, hint]) =>
387
+ ui.line(
388
+ ui.cell(20, label),
386
389
  ui.cell(
387
390
  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]),
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('JEV'),
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
- '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 }),
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.text(' '),
425
- ui.head('CONFIG'),
480
+ ui.dim(`Sends prompt + ${config.context.recentTurns} recent turns → ${hostOf(active.endpoint)}`),
426
481
  ui.line(
427
- `File ${view.configPath ?? 'profile router.json'} `,
428
- view.configPath ? ui.Button({ key: 'copy-path', label: 'copy', onPress: actions.copyPath }) : null,
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('Main conversation only. Subagents keep their own model.'),
486
+ ui.dim(` ${credentialsNeeded(config)}`),
431
487
  ];
432
488
  }
433
489
 
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.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": {
@@ -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,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;