aegisone 1.0.17 → 1.0.20

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.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/package.json +3 -3
  3. package/scripts/bump.mjs +29 -4
  4. package/scripts/predist.mjs +2 -0
  5. package/src/dispatch.js +1 -0
  6. package/vendor/cli/README.md +3 -3
  7. package/vendor/cli/bin/aegiscode.js +29 -0
  8. package/vendor/cli/package.json +2 -2
  9. package/vendor/cli/src/app.js +370 -30
  10. package/vendor/cli/src/autonomous.js +30 -4
  11. package/vendor/cli/src/chatflow.js +132 -4
  12. package/vendor/cli/src/commands.js +223 -64
  13. package/vendor/cli/src/config.js +21 -0
  14. package/vendor/cli/src/connect.js +351 -0
  15. package/vendor/cli/src/deps.js +97 -1
  16. package/vendor/cli/src/engine.js +123 -7
  17. package/vendor/cli/src/fingerprint.js +46 -16
  18. package/vendor/cli/src/limits.js +1 -1
  19. package/vendor/cli/src/overlays.js +98 -0
  20. package/vendor/cli/src/provenance.lock.json +3 -3
  21. package/vendor/cli/src/screens.js +14 -1
  22. package/vendor/cli/vendor/client/credentials.js +9 -2
  23. package/vendor/cli/vendor/client/google-signin.js +127 -0
  24. package/vendor/cli/vendor/client/record-vault.js +431 -113
  25. package/vendor/cli/vendor/client/update.js +266 -0
  26. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +48 -8
  27. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +134 -11
  28. package/vendor/cli/vendor/desktop/lib/local/engine.js +47 -25
  29. package/vendor/cli/vendor/desktop/lib/settings.js +65 -24
  30. package/vendor/desktop/README.md +1 -1
  31. package/vendor/desktop/lib/auto.js +11 -7
  32. package/vendor/desktop/lib/fingerprint.js +76 -17
  33. package/vendor/desktop/lib/local/autonomous.js +48 -8
  34. package/vendor/desktop/lib/local/claude-pro.js +134 -11
  35. package/vendor/desktop/lib/local/engine.js +47 -25
  36. package/vendor/desktop/lib/settings.js +65 -24
  37. package/vendor/desktop/main.js +79 -24
  38. package/vendor/desktop/package.json +10 -5
  39. package/vendor/desktop/preload.js +31 -12
  40. package/vendor/desktop/renderer/app.js +676 -17
  41. package/vendor/desktop/renderer/budget.js +18 -9
  42. package/vendor/desktop/renderer/companion.js +225 -0
  43. package/vendor/desktop/renderer/fingerprint.css +16 -0
  44. package/vendor/desktop/renderer/fingerprint.js +62 -2
  45. package/vendor/desktop/renderer/index.html +285 -121
  46. package/vendor/desktop/renderer/provider-toolbar.js +136 -0
  47. package/vendor/desktop/renderer/providers.js +261 -0
  48. package/vendor/desktop/renderer/style.css +547 -171
  49. package/vendor/desktop/vendor/credentials.js +9 -2
  50. package/vendor/desktop/vendor/google-signin.js +127 -0
  51. package/vendor/desktop/vendor/record-vault.js +431 -113
  52. package/vendor/desktop/vendor/update.js +266 -0
@@ -284,6 +284,9 @@ const PRO_ALIAS_KEYWORDS = Object.freeze(['opus', 'haiku', 'sonnet']);
284
284
  * @param {boolean} o.hasStored the byok provider store already holds an
285
285
  * anthropic key (desktop Provider settings / `/byok-key anthropic`)
286
286
  * @param {boolean} o.proLoggedIn this machine is signed into Claude Code Pro
287
+ * @param {boolean} o.proEnabled the `pro` class is enabled for this install
288
+ * (`/class pro on`); anything but `true` leaves the byok row untouched, so a
289
+ * disabled subscription can never be reached by this reroute
287
290
  * @param {Array<{id:string,label:string,note:string}>} o.proModels
288
291
  * `claudePro.PRO_MODELS`, injected rather than required here
289
292
  * @returns {{row:object, message:string|null}} the row to actually pin (the
@@ -299,6 +302,14 @@ function overrideAnthropicByokWithPro(chosen, o = {}) {
299
302
  }
300
303
  if (!o.needsKey) return { row: chosen, message: null }; // a real console key is already usable
301
304
  if (!o.proLoggedIn) return { row: chosen, message: null }; // no subscription either — the normal prompt stands
305
+ // The `pro` class ships disabled (config.js `proEnabled`, `/class pro on`).
306
+ // This override silently MOVES a byok pick onto the subscription, so it must
307
+ // obey the same gate the picker and `/class` do — otherwise the one path a
308
+ // user never asked for is the path that still routes turns onto a
309
+ // subscription whose Claude Code access may be revoked, failing the turn with
310
+ // `oauth_org_not_allowed` after the pick already looked successful. Absent
311
+ // means "not stated" and is treated as disabled: fail closed.
312
+ if (o.proEnabled !== true) return { row: chosen, message: null };
302
313
  const modelPart = id.slice(colon + 1).toLowerCase();
303
314
  const proModels = Array.isArray(o.proModels) && o.proModels.length ? o.proModels : [{ id: 'default', label: 'Default', note: '' }];
304
315
  const aliasId = PRO_ALIAS_KEYWORDS.find((kw) => modelPart.includes(kw)) || 'default';
@@ -1266,6 +1277,19 @@ async function runSession(host) {
1266
1277
  );
1267
1278
  } else if (overlay.type === 'effort') {
1268
1279
  ol = overlays.renderEffortPicker(overlay.sel || 0, cols, ctx.effort);
1280
+ } else if (overlay.type === 'class') {
1281
+ ol = overlays.renderClassPicker(
1282
+ overlay.items || [], overlay.sel || 0, cols, overlay.current || ctx.modelClass,
1283
+ typeof host.classLabel === 'function' ? host.classLabel : null
1284
+ );
1285
+ } else if (overlay.type === 'provider') {
1286
+ // The BYOK provider picker (/byok-set with no argument, /byok-key with
1287
+ // no argument). Same overlay machinery as /model and /class — arrow or
1288
+ // Tab to move, Enter to pick — so choosing WHICH vendor a key belongs to
1289
+ // is a highlight rather than a provider id retyped from memory.
1290
+ ol = overlays.renderProviderPicker(
1291
+ overlay.items || [], overlay.sel || 0, cols, overlay.current, overlay.hint
1292
+ );
1269
1293
  } else if (overlay.type === 'resume') {
1270
1294
  ol = overlays.renderResumeList(overlay.items || [], overlay.sel || 0, cols, termRows);
1271
1295
  } else if (overlay.type === 'shortcuts') {
@@ -1518,6 +1542,12 @@ async function runSession(host) {
1518
1542
  if (tool.phase === 'run') {
1519
1543
  const n = ++toolSeq;
1520
1544
  const prefix = tool.agent ? `${tool.agent} ▸ ` : '';
1545
+ // Built on the `run` frame, before the executor writes — a writeFile
1546
+ // preview built any later would diff the file against itself. The
1547
+ // row this lands on persists through resolveToolDone (same object,
1548
+ // found by id), so the diff set here is still there once the tool
1549
+ // reports `done` and the row repaints.
1550
+ const diff = editPreview(tool.name, tool.args, { cwd: tool.cwd });
1521
1551
  pushToolRow(
1522
1552
  {
1523
1553
  role: 'tool',
@@ -1528,6 +1558,8 @@ async function runSession(host) {
1528
1558
  id: tool.id,
1529
1559
  label: `Running ${n} ${prefix}${toolLabel(tool.name, n)}…`,
1530
1560
  start: Date.now(),
1561
+ diff,
1562
+ diffOpen: defaultOpen(diff),
1531
1563
  },
1532
1564
  msg
1533
1565
  );
@@ -1538,7 +1570,12 @@ async function runSession(host) {
1538
1570
  // post-execution). Falling through left the row unwritten, so the
1539
1571
  // turn silently showed no tool activity at all. Record the finished
1540
1572
  // tool directly instead.
1573
+ // No `run` frame means no pre-write read either, so a writeFile's
1574
+ // diff here can only compare the file against its own post-write
1575
+ // content (reads clean) — a limitation of this fallback, not of the
1576
+ // normal run→done path above.
1541
1577
  const n = ++toolSeq;
1578
+ const diff = editPreview(tool.name, tool.args, { cwd: tool.cwd });
1542
1579
  pushToolRow(
1543
1580
  {
1544
1581
  role: 'tool',
@@ -1549,6 +1586,8 @@ async function runSession(host) {
1549
1586
  id: tool.id,
1550
1587
  ok: tool.ok,
1551
1588
  label: `Ran ${n} ${tool.agent ? `${tool.agent} ▸ ` : ''}${toolLabel(tool.name, n)}`,
1589
+ diff,
1590
+ diffOpen: defaultOpen(diff),
1552
1591
  },
1553
1592
  msg
1554
1593
  );
@@ -2008,7 +2047,7 @@ async function runSession(host) {
2008
2047
  (c) => c.aliases || []
2009
2048
  ).length;
2010
2049
  }
2011
- if (overlay.type === 'model' || overlay.type === 'resume') return (overlay.items || []).length;
2050
+ if (overlay.type === 'model' || overlay.type === 'resume' || overlay.type === 'class' || overlay.type === 'provider') return (overlay.items || []).length;
2012
2051
  if (overlay.type === 'effort') return overlays.EFFORT_VALUES.length;
2013
2052
  return 0;
2014
2053
  };
@@ -2143,6 +2182,15 @@ async function runSession(host) {
2143
2182
  const { row, message } = overrideAnthropicByokWithPro(chosen, {
2144
2183
  needsKey: !!(plan && plan.needed),
2145
2184
  proLoggedIn: models.claudeProLoggedIn(),
2185
+ // The same gate `/class pro on` writes: a disabled subscription is not
2186
+ // reachable by this reroute either.
2187
+ proEnabled: (() => {
2188
+ try {
2189
+ return loadConfig().proEnabled === true;
2190
+ } catch {
2191
+ return false;
2192
+ }
2193
+ })(),
2146
2194
  proModels: claudePro.PRO_MODELS,
2147
2195
  });
2148
2196
  chosen = row;
@@ -2163,6 +2211,17 @@ async function runSession(host) {
2163
2211
  await collectKeyFor(chosen);
2164
2212
  };
2165
2213
 
2214
+ /**
2215
+ * Switch class from a /class picker row — routed through the `/class`
2216
+ * command itself (not a second copy of switchClass + the byok auto-pin
2217
+ * fallback) so the picker and `/class <id>` typed by hand can never
2218
+ * disagree about what picking a class does.
2219
+ */
2220
+ const applyClassRow = async (chosen) => {
2221
+ if (!chosen || !chosen.class) return;
2222
+ await dispatch(`/class ${chosen.class}`);
2223
+ };
2224
+
2166
2225
  /**
2167
2226
  * Pin an effort rung — the ONE path a rung is applied through, shared by
2168
2227
  * Enter, shift+enter and the shift+arrow chords.
@@ -2208,14 +2267,14 @@ async function runSession(host) {
2208
2267
  }
2209
2268
  return;
2210
2269
  }
2211
- if (key.name === KEY.TAB && (type === 'model' || type === 'effort')) {
2270
+ if (key.name === KEY.TAB && (type === 'model' || type === 'effort' || type === 'class' || type === 'provider')) {
2212
2271
  // Reference parity (aegiscodex-dev/src/main.js's model overlay cycles on
2213
2272
  // Tab). It is also the one way to walk either picker that survives a link
2214
2273
  // where arrow escapes are eaten, since Tab is a single control byte.
2215
2274
  // Both lists are addressed the one way each of them can be: the catalogue
2216
2275
  // lives in `overlay.items`, while the rungs are the picker's own table —
2217
2276
  // the same table Enter and shift+enter resolve through.
2218
- const n = type === 'model'
2277
+ const n = type === 'model' || type === 'class' || type === 'provider'
2219
2278
  ? (overlay.items || []).length
2220
2279
  : overlays.EFFORT_VALUES.length;
2221
2280
  if (n) {
@@ -2253,6 +2312,29 @@ async function runSession(host) {
2253
2312
  applyEffortRow(overlay.sel || 0);
2254
2313
  return;
2255
2314
  }
2315
+ if (type === 'class') {
2316
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2317
+ overlay = null;
2318
+ render();
2319
+ await applyClassRow(chosen);
2320
+ render();
2321
+ return;
2322
+ }
2323
+ if (type === 'provider') {
2324
+ // The BYOK provider pick: run the command that opened this picker with
2325
+ // the highlighted provider's own catalog id, so the id that reaches the
2326
+ // store is the id the relay is asked for — never a hand-retyped alias
2327
+ // (the `findByokProvider` loose match this replaces could land on the
2328
+ // wrong vendor, which is the failure the whole path exists to prevent).
2329
+ // `overlay.command` names the command to re-enter: /byok-key stores on
2330
+ // this machine, /byok-set stores on the account.
2331
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2332
+ const cmd = overlay.command || 'byok-key';
2333
+ overlay = null;
2334
+ render();
2335
+ if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
2336
+ return;
2337
+ }
2256
2338
  if (type === 'resume') {
2257
2339
  const chosen = (overlay.items || [])[overlay.sel || 0];
2258
2340
  overlay = null;
@@ -2283,6 +2365,29 @@ async function runSession(host) {
2283
2365
  render();
2284
2366
  return;
2285
2367
  }
2368
+ if (type === 'class') {
2369
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2370
+ overlay = null;
2371
+ render();
2372
+ await applyClassRow(chosen);
2373
+ render();
2374
+ return;
2375
+ }
2376
+ if (type === 'provider') {
2377
+ // The BYOK provider pick: run the command that opened this picker with
2378
+ // the highlighted provider's own catalog id, so the id that reaches the
2379
+ // store is the id the relay is asked for — never a hand-retyped alias
2380
+ // (the `findByokProvider` loose match this replaces could land on the
2381
+ // wrong vendor, which is the failure the whole path exists to prevent).
2382
+ // `overlay.command` names the command to re-enter: /byok-key stores on
2383
+ // this machine, /byok-set stores on the account.
2384
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2385
+ const cmd = overlay.command || 'byok-key';
2386
+ overlay = null;
2387
+ render();
2388
+ if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
2389
+ return;
2390
+ }
2286
2391
  if (type === 'effort') {
2287
2392
  applyEffortRow(overlay.sel || 0);
2288
2393
  return;
@@ -2311,6 +2416,29 @@ async function runSession(host) {
2311
2416
  render();
2312
2417
  return;
2313
2418
  }
2419
+ if (type === 'class') {
2420
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2421
+ overlay = null;
2422
+ render();
2423
+ await applyClassRow(chosen);
2424
+ render();
2425
+ return;
2426
+ }
2427
+ if (type === 'provider') {
2428
+ // The BYOK provider pick: run the command that opened this picker with
2429
+ // the highlighted provider's own catalog id, so the id that reaches the
2430
+ // store is the id the relay is asked for — never a hand-retyped alias
2431
+ // (the `findByokProvider` loose match this replaces could land on the
2432
+ // wrong vendor, which is the failure the whole path exists to prevent).
2433
+ // `overlay.command` names the command to re-enter: /byok-key stores on
2434
+ // this machine, /byok-set stores on the account.
2435
+ const chosen = (overlay.items || [])[overlay.sel || 0];
2436
+ const cmd = overlay.command || 'byok-key';
2437
+ overlay = null;
2438
+ render();
2439
+ if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
2440
+ return;
2441
+ }
2314
2442
  if (type === 'effort') {
2315
2443
  applyEffortRow(overlay.sel || 0);
2316
2444
  return;
@@ -2359,7 +2487,7 @@ async function runSession(host) {
2359
2487
  }
2360
2488
  return;
2361
2489
  }
2362
- if (type === 'effort' || type === 'resume') {
2490
+ if (type === 'effort' || type === 'resume' || type === 'class' || type === 'provider') {
2363
2491
  // Bounded by the same row count every other mover is bounded by. A row
2364
2492
  // number past the end used to be accepted unseen (`sel = idx - 1` with
2365
2493
  // no upper clamp), so '9' in /effort parked the highlight off the list
@@ -3004,7 +3004,11 @@ const COMMANDS = [
3004
3004
  [span(C.gray, '─'.repeat(34))],
3005
3005
  [
3006
3006
  span(set ? C.green : C.gray, ` ${set} of ${providers.length} providers set`),
3007
- span(C.gray, ' — /byok-key <provider>'),
3007
+ // Name the PICKER first: the id is the one thing this screen was
3008
+ // asking the reader to copy by eye, and `/byok-list` removes that
3009
+ // step. The typed form stays beside it for scripts and for anyone who
3010
+ // already knows the id.
3011
+ span(C.gray, ' — /byok-list picks one, or /byok-key <provider>'),
3008
3012
  ],
3009
3013
  '',
3010
3014
  ...byokProviderLines(providers),
@@ -3057,6 +3061,7 @@ const COMMANDS = [
3057
3061
  return {
3058
3062
  note: `${p.id} already has a key${p.masked ? ` (${p.masked})` : ''} — pasting a new one replaces it.`,
3059
3063
  prompt: `new ${p.label || p.id} key: `,
3064
+ provider: p.id,
3060
3065
  };
3061
3066
  }
3062
3067
  const bits = [`${p.label || p.id}`];
@@ -3066,7 +3071,7 @@ const COMMANDS = [
3066
3071
  if (models.length) bits.push(`unlocks ${models.join(', ')}`);
3067
3072
  if (p.key_prefix) bits.push(`key starts with ${p.key_prefix}`);
3068
3073
  if (p.key_url) bits.push(`create one at ${p.key_url}`);
3069
- return { note: bits.join(' · '), prompt: `${p.id} key: ` };
3074
+ return { note: bits.join(' · '), prompt: `${p.id} key: `, provider: p.id };
3070
3075
  },
3071
3076
  },
3072
3077
  {
@@ -3076,43 +3081,60 @@ const COMMANDS = [
3076
3081
  build: (arg) => ({ provider: String(arg || '').trim() }),
3077
3082
  },
3078
3083
  {
3079
- name: 'class', args: ['class'], hint: '[aegis|byok]', category: 'model',
3080
- desc: 'Show or switch which class turns run on: pooled AEGIS Cloud, or your own key',
3084
+ name: 'class', args: ['class', 'mode'], hint: '[aegis|byok|local|pro [on|off]]', category: 'model',
3085
+ desc: 'Show or switch which class turns run on; pro (your Claude subscription) needs a one-time "on"',
3081
3086
  handler: async (c, a) => {
3082
3087
  const args = a || {};
3083
3088
  const cur = (c.ctx && c.ctx.modelClass) || 'aegis';
3084
3089
  const label = (id) => (c.classLabel ? c.classLabel(id) : id);
3085
3090
  const want = String(args.class || '').trim().toLowerCase();
3091
+ // `/class pro on|off` — the one-time opt-in for the subscription class.
3092
+ //
3093
+ // `pro` spends a real Claude Code Pro/Max subscription by spawning the
3094
+ // `claude` CLI, and an account whose organization has disabled Claude
3095
+ // Code answers every such turn with `oauth_org_not_allowed`, which this
3096
+ // repo cannot fix. So `pro` ships DISABLED (config.js `proEnabled: false`)
3097
+ // and this is the only way in: an explicit, deliberate word from the
3098
+ // user. Written through saveConfig so it survives a restart — an opt-in
3099
+ // that reverted on the next launch would put the class back out of reach
3100
+ // with no way to tell why.
3101
+ if (want === 'pro' && args.mode) {
3102
+ const mode = String(args.mode).trim().toLowerCase();
3103
+ if (mode !== 'on' && mode !== 'off') {
3104
+ c.push({ role: 'error', text: `usage: /class pro [on|off] — got "${args.mode}"` });
3105
+ return true;
3106
+ }
3107
+ const on = mode === 'on';
3108
+ c.saveConfig({ proEnabled: on });
3109
+ c.push({
3110
+ role: on ? 'done' : 'note',
3111
+ text: on
3112
+ ? 'pro class enabled — /class pro switches to your Claude Code subscription. ' +
3113
+ 'It runs only if that subscription has Claude Code access.'
3114
+ : 'pro class disabled — it is no longer offered by /class or the model picker.',
3115
+ });
3116
+ // Turning it off while sitting on it would leave the session pointing
3117
+ // at a class that can no longer run: fall back to the default class
3118
+ // through the same path `/class aegis` takes, so the pin rules and the
3119
+ // stored config are updated rather than only the panel.
3120
+ if (!on && cur === 'pro') {
3121
+ const back = c.switchClass('aegis');
3122
+ if (back.ok) c.push({ role: 'note', text: `class: ${back.class} — ${label(back.class)}` });
3123
+ }
3124
+ return true;
3125
+ }
3086
3126
  if (!want) {
3087
3127
  // Awaited: the engine's listClasses() is async (it probes for a local
3088
3128
  // Ollama before answering), and a context that offers no class surface
3089
3129
  // at all falls back to the two static rows below.
3090
3130
  const classes = await Promise.resolve(c.classes ? c.classes() : []).catch(() => []);
3091
3131
  const rows = classes.length ? classes : [{ class: 'aegis' }, { class: 'byok' }];
3092
- const lines = [
3093
- [span(C.gold + BOLD, 'Class'), span(BOLD_OFF, ' — which route the next turn takes')],
3094
- [span(C.gray, '─'.repeat(52))],
3095
- ];
3096
- for (const k of rows) {
3097
- const id = k.class;
3098
- const on = id === cur;
3099
- // The distinction that matters to a user: who pays, and with which
3100
- // credential. Stated per class rather than in a footnote.
3101
- const note =
3102
- id === 'byok'
3103
- ? k.configured
3104
- ? 'your key, relayed by AEGIS — billed a handling fee'
3105
- : 'needs a provider key: /byok-key <provider>'
3106
- : 'the pool — your AEGIS account key pays for it';
3107
- lines.push([
3108
- span(on ? C.green : C.gray, ` ${on ? '●' : '○'} ${String(id).padEnd(6)}`),
3109
- span(on ? C.green : C.gray, label(id)),
3110
- span(C.gray, ` ${note}`),
3111
- ]);
3112
- }
3113
- lines.push('', [span(C.gray, ' switch with /class byok or /class aegis')]);
3114
- panel(c, lines);
3115
- c.render();
3132
+ const sel = rows.findIndex((k) => k.class === cur);
3133
+ // An interactive picker, not a static panel — the same tab/arrow/enter
3134
+ // overlay machinery /model already uses (chatflow.js handleOverlayKey),
3135
+ // so a class is switched by moving the highlight and hitting enter
3136
+ // rather than retyping its name after reading it off this list.
3137
+ c.openOverlay({ type: 'class', items: rows, sel: sel < 0 ? 0 : sel, current: cur });
3116
3138
  return true;
3117
3139
  }
3118
3140
  const res = c.switchClass(want);
@@ -3163,45 +3185,72 @@ const COMMANDS = [
3163
3185
  },
3164
3186
  {
3165
3187
  name: 'models', aliases: ['model-list'], hint: '', category: 'model',
3166
- desc: 'List the model ids you can pin with /model, for the class you are on',
3188
+ desc: 'Pick a model to pin, for the class you are on — opens the same picker as /model',
3167
3189
  handler: async (c) => {
3168
3190
  const cls = (c.ctx && c.ctx.modelClass) || 'aegis';
3169
3191
  const models = (await c.listModelsFor(cls)) || [];
3170
- const lines = [
3171
- [span(C.gold + BOLD, 'Models'), span(BOLD_OFF, ` — ${c.classLabel ? c.classLabel(cls) : cls}`)],
3172
- [span(C.gray, '─'.repeat(52))],
3173
- ];
3174
3192
  if (!models.length) {
3175
- lines.push('', [
3176
- span(
3177
- C.gray,
3178
- cls === 'byok'
3179
- ? ' nothing to relay yet — save a provider key with /byok-key <provider>'
3180
- : ' no models advertised — check the account with /status, then retry'
3181
- ),
3182
- ]);
3183
- } else {
3184
- const pinned = c.ctx && c.ctx.model;
3185
- for (const m of models) {
3186
- const on = pinned === m.id;
3187
- // A row from the OTHER class rides on this list on purpose — the
3188
- // pooled Nexus row is what makes the byok list able to show a way
3189
- // back to the pooled lane (app.js classScopedModels). It is not
3190
- // pinnable here, so it says which class it runs on instead of
3191
- // looking like a byok id that would 400 at the relay.
3192
- const other = m.cls && m.cls !== cls;
3193
- lines.push([
3194
- span(on ? C.green : C.gray, ` ${on ? '●' : '○'} `),
3195
- span(on ? C.green : C.gray, String(m.id).padEnd(30)),
3196
- span(C.gray, other
3197
- ? `${m.note || m.label || ''} · pooled lane — /class ${m.cls}`
3198
- : m.note || m.label || ''),
3199
- ]);
3200
- }
3201
- lines.push('', [span(C.gray, ' pin one with /model <id> — /model alone opens the picker')]);
3193
+ note(c, cls === 'byok'
3194
+ ? 'nothing to relay yet — save a provider key with /byok-key <provider>'
3195
+ : 'no models advertised — check the account with /status, then retry');
3196
+ c.render();
3197
+ return true;
3202
3198
  }
3203
- panel(c, lines);
3204
- c.render();
3199
+ const pinned = c.ctx && c.ctx.model;
3200
+ // A row from the OTHER class rides on this list on purpose — the pooled
3201
+ // Nexus row is what makes the byok list able to show a way back to the
3202
+ // pooled lane (app.js classScopedModels). It is not a row of THIS
3203
+ // class's own ids, so its note says which class it actually runs on
3204
+ // instead of looking like a byok id that would 400 at the relay.
3205
+ const items = models.map((m) => (m.cls && m.cls !== cls
3206
+ ? { ...m, note: `${m.note || m.label || ''} · pooled lane — /class ${m.cls}` }
3207
+ : m));
3208
+ const sel = items.findIndex((m) => m.id === pinned);
3209
+ // Same overlay /model opens (tab/arrow to move, enter to pin — see
3210
+ // chatflow.js handleOverlayKey), just scoped to this class's own rows
3211
+ // rather than /model's merged cross-class catalog. Picking the other
3212
+ // class's row switches class first, the same cross-class pin
3213
+ // applyModelRow already does for /model's own rows.
3214
+ c.openOverlay({ type: 'model', items, sel: sel < 0 ? 0 : sel, current: pinned, cls });
3215
+ return true;
3216
+ },
3217
+ },
3218
+ {
3219
+ // `/byok-list` — pick a provider from the catalog and store its key on THIS
3220
+ // machine, the same route `/byok-key` takes once a provider is named. The
3221
+ // picker is the point: the provider id was the one thing this flow asked
3222
+ // the user to recall and retype, and a retyped or alias-matched id either
3223
+ // matched nothing or matched another vendor. Arrow or Tab moves the
3224
+ // highlight, Enter picks, and the id dispatched is the catalog's own — so
3225
+ // the key lands under the id the relay will be asked for, and that
3226
+ // provider's models then show up in `/model`.
3227
+ name: 'byok-list', aliases: ['byok-pick'], hint: '', category: 'auth',
3228
+ desc: 'Pick a provider to set a key for, then its models appear in /model',
3229
+ handler: async (c) => {
3230
+ const providers = await byokCatalog(c.client);
3231
+ if (!providers || !providers.length) {
3232
+ c.push({
3233
+ role: 'error',
3234
+ text: 'Could not read the provider catalog (offline, or no AEGIS key) — /byok lists what is known.',
3235
+ });
3236
+ return true;
3237
+ }
3238
+ if (typeof c.openOverlay !== 'function') {
3239
+ // No interactive host: fall back to the printable list rather than a
3240
+ // picker nothing can draw.
3241
+ c.push({ role: 'note', text: '/byok-key <provider> — /byok lists the providers.' });
3242
+ return true;
3243
+ }
3244
+ const cur = (providers.find((p) => p.configured) || {}).id || null;
3245
+ const sel = Math.max(0, providers.findIndex((p) => p.configured));
3246
+ c.openOverlay({
3247
+ type: 'provider',
3248
+ command: 'byok-key',
3249
+ items: providers,
3250
+ sel,
3251
+ current: cur,
3252
+ hint: '↑↓ or tab move · enter picks · the key is stored on this machine',
3253
+ });
3205
3254
  return true;
3206
3255
  },
3207
3256
  },
@@ -3212,7 +3261,33 @@ const COMMANDS = [
3212
3261
  const args = a || {};
3213
3262
  const typed = String(args.provider || '').trim().toLowerCase();
3214
3263
  if (!typed) {
3215
- c.push({ role: 'error', text: 'Usage: /byok-key <provider> — /byok lists the providers.' });
3264
+ // No provider typed: open the picker instead of printing a usage line.
3265
+ // The id was the one thing this flow asked the user to RECALL, and a
3266
+ // mistyped or alias-matched id either matched nothing or — worse —
3267
+ // matched another vendor's row. Arrow or Tab moves, Enter picks, and
3268
+ // the id Enter dispatches is the catalog's own, so the key lands under
3269
+ // the id the relay will actually be asked for.
3270
+ const providers = await byokCatalog(c.client);
3271
+ if (!providers || !providers.length) {
3272
+ c.push({ role: 'error', text: 'Usage: /byok-key <provider> — /byok lists the providers.' });
3273
+ return true;
3274
+ }
3275
+ if (typeof c.openOverlay !== 'function') {
3276
+ // No interactive host (a piped run): the old usage line, which at
3277
+ // least names the command that lists the ids.
3278
+ c.push({ role: 'error', text: 'Usage: /byok-key <provider> — /byok lists the providers.' });
3279
+ return true;
3280
+ }
3281
+ const cur = (providers.find((p) => p.configured) || {}).id || null;
3282
+ const sel = Math.max(0, providers.findIndex((p) => p.configured));
3283
+ c.openOverlay({
3284
+ type: 'provider',
3285
+ command: 'byok-key',
3286
+ items: providers,
3287
+ sel,
3288
+ current: cur,
3289
+ hint: '↑↓ or tab move · enter picks · the key is stored on this machine',
3290
+ });
3216
3291
  return true;
3217
3292
  }
3218
3293
  const store = c.settings && c.settings();
@@ -3229,6 +3304,24 @@ const COMMANDS = [
3229
3304
  c.push({ role: 'error', text: `"${typed}" matches ${match.ambiguous.join(', ')} — retype the exact id.` });
3230
3305
  return true;
3231
3306
  }
3307
+ // A key written under a provider the relay does not serve is unusable and
3308
+ // invisible: the catalog never lists the row it created, so the user sees
3309
+ // "saved" and then no models, with nothing naming the typo. `byok-set`
3310
+ // already refuses this; the command it redirects users TO must refuse it
3311
+ // too, or the redirect trades one silent failure for another.
3312
+ //
3313
+ // Only refused when the catalog actually answered. `byokCatalog` returns
3314
+ // null on an unreachable server, and refusing on null would turn a
3315
+ // network blip into "unknown provider" — a wrong reason for a right-looking
3316
+ // stop. With no catalog the typed id is trusted, as before.
3317
+ if (providers && !match?.provider) {
3318
+ const ids = providers.map((x) => x.id).join(', ');
3319
+ c.push({
3320
+ role: 'error',
3321
+ text: `unknown provider "${typed}". Known ids: ${ids} — nothing was saved.`,
3322
+ });
3323
+ return true;
3324
+ }
3232
3325
  const p = match && match.provider;
3233
3326
  const id = (p && p.id) || typed;
3234
3327
  // A second token is the scriptable path (`/byok-key openai sk-…`); with
@@ -3248,9 +3341,75 @@ const COMMANDS = [
3248
3341
  c.push({ role: 'note', text: `heads up: ${id} keys normally start with "${p.key_prefix}" — saved anyway.` });
3249
3342
  }
3250
3343
  store.set(c.byokNamespace(id), { key });
3344
+
3345
+ // MIRROR IT INTO ~/.aegiscode/.env — the file every host (this CLI, the
3346
+ // desktop, the MCP plugin) loads at start-up, and the one the shared
3347
+ // engine's `providerKeyFromEnv` reads. The settings store alone made the
3348
+ // key a private fact of this process's data dir: the next launch of the
3349
+ // SAME host found it, but nothing else did, and the byok model list is
3350
+ // built from a key the engine resolves through both. `/model-add` writes
3351
+ // both stores for this exact reason (see its `setEnvValue` call), and a
3352
+ // key entered here must not be the one row that behaves differently.
3353
+ // Best-effort: the store row above is the row of record, so a failure to
3354
+ // write the file is reported and never undoes the save.
3355
+ let envWritten = '';
3356
+ try {
3357
+ const { envVarFor, setEnvValue } = require(resolveShared(path.join('client', 'env-file.js')));
3358
+ const name = envVarFor(id);
3359
+ if (name) {
3360
+ const res = setEnvValue(name, key);
3361
+ if (res.ok) envWritten = name;
3362
+ else c.push({ role: 'note', text: `heads up: could not write ${name} to ~/.aegiscode/.env (${res.error}).` });
3363
+ }
3364
+ } catch {
3365
+ /* the settings-store save is the row of record; this mirror is best-effort */
3366
+ }
3367
+
3368
+ // Then make the models it unlocks VISIBLE where the user asked for them:
3369
+ // the byok model list is cached for five minutes (app.js MODEL_CACHE_MS),
3370
+ // so without this the key is saved and `/model` keeps offering the list
3371
+ // computed before it existed — the "I set a key and nothing new appeared"
3372
+ // report. The refresh is forced, and its rows are what get pinned below.
3373
+ let rows = [];
3374
+ if (typeof c.refreshByokModels === 'function') {
3375
+ try { rows = (await c.refreshByokModels()) || []; } catch { rows = []; }
3376
+ }
3377
+ if (!rows.length && typeof c.listModelsFor === 'function') {
3378
+ // Hosts that expose the class surface but not the cache invalidation
3379
+ // (an embedding) still get an answer: ask for the byok class directly.
3380
+ try {
3381
+ rows = ((await c.listModelsFor('byok')) || []).filter((m) => !m.cls || m.cls === 'byok');
3382
+ } catch { rows = []; }
3383
+ }
3384
+ const mine = rows.filter((m) => m && (m.provider === id || String(m.id || '').startsWith(`${id}:`)));
3385
+
3386
+ // Move onto the byok class — the key just saved can only be spent there,
3387
+ // and a session sitting on `aegis` would show these rows in /model and
3388
+ // then send the pinned `provider:model` id to the pool. Before the pin,
3389
+ // so switchClass's own pin rules run on the id we are about to store.
3390
+ let onByok = ((c.ctx && c.ctx.modelClass) || '') === 'byok';
3391
+ if (!onByok && typeof c.switchClass === 'function') {
3392
+ const sw = c.switchClass('byok');
3393
+ if (sw && sw.ok) {
3394
+ onByok = true;
3395
+ c.push({ role: 'note', text: `class: byok — ${c.classLabel ? c.classLabel('byok') : 'your own key'}` });
3396
+ }
3397
+ }
3398
+
3399
+ // Pin it and PERSIST it, which is what makes the pick survive a restart:
3400
+ // app.js's restorePrefs() reads config.model/modelClass back. Only on
3401
+ // success — this whole block is the success path, after the key landed.
3402
+ const pickId = mine.length ? String(mine[0].id) : '';
3403
+ if (pickId && c.ctx) {
3404
+ c.ctx.model = pickId;
3405
+ c.saveConfig({ model: pickId, currentModelId: pickId, ...(onByok ? { modelClass: 'byok' } : {}) });
3406
+ }
3407
+
3251
3408
  c.push({
3252
3409
  role: 'done',
3253
- text: `saved a ${id} key on this machine — /models lists its models, /class byok runs on it.`,
3410
+ text: pickId
3411
+ ? `saved a ${id} key on this machine${envWritten ? ` (${envWritten} in ~/.aegiscode/.env, so it is there next time)` : ''} — model ${pickId} pinned, /model lists the rest.`
3412
+ : `saved a ${id} key on this machine${envWritten ? ` (${envWritten} in ~/.aegiscode/.env, so it is there next time)` : ''} — /models lists its models, /class byok runs on it.`,
3254
3413
  });
3255
3414
  return true;
3256
3415
  },
@@ -70,6 +70,13 @@ const DEFAULT_CONFIG = {
70
70
  // src/update.js). Persisted so a launch reports what the LAST run learned
71
71
  // and never waits on the network to draw its own welcome box.
72
72
  updateCheck: null,
73
+ // Cached `{ checkedAt, behind, required, latest, downloadUrl }` from the
74
+ // once-a-day SERVER check (/api/v1/version, see src/update.js). Separate
75
+ // from `updateCheck` because it answers a different question: the registry
76
+ // says what was published, the server says what it will still serve. A
77
+ // build can be merely superseded (a suggestion) or refused (an outage), and
78
+ // collapsing the two would report the wrong urgency.
79
+ updateCheckServer: null,
73
80
  // No pinned model. This host runs on AEGIS Cloud, whose pinnable ids are the
74
81
  // server's (`/models`) — a client-side default here would have to name one,
75
82
  // and the one it named (`sonnet`) is not advertised by the platform at all:
@@ -89,6 +96,20 @@ const DEFAULT_CONFIG = {
89
96
  // back to. Defaulted to the pooled class, which is the only one an account
90
97
  // key alone can run.
91
98
  modelClass: 'aegis',
99
+ // Whether the `pro` class may be selected at all. OFF by default, and it
100
+ // takes a deliberate `/class pro on` to turn it on — this is a one-time
101
+ // opt-in, not a preference that drifts back.
102
+ //
103
+ // The reason is the failure this flag exists to prevent: `pro` spends a real
104
+ // Claude Code Pro/Max subscription by spawning the `claude` CLI, and an
105
+ // account whose organization has disabled Claude Code access answers every
106
+ // such turn with `oauth_org_not_allowed` ("Your organization has disabled
107
+ // Claude subscription access"). Nothing in this repo can re-enable that, so
108
+ // a default of "offered" meant the Class picker, the `/model` list and the
109
+ // anthropic→pro override all steered users into turns that could only fail.
110
+ // Off by default means a machine that never asked for the subscription route
111
+ // never lands on it; `/class pro on` is the single, explicit way in.
112
+ proEnabled: false,
92
113
  // The full model table (seeded from src/models.js MODELS on first
93
114
  // read by pickerModels()). 'currentModelId' mirrors `model` under the
94
115
  // aegiscode- name so /model add/remove/switch stay compatible both ways.