aegiscode 7.0.9 → 7.0.11

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/README.md CHANGED
@@ -18,7 +18,7 @@ Routing, model tiers, memory and billing all stay behind aegiscloud.org.
18
18
  Four steps, in order. Everything past this section is the fuller reference for
19
19
  each one.
20
20
 
21
- **1. Install** — requires Node 18+.
21
+ **1. Install** — requires Node 22+.
22
22
 
23
23
  ```bash
24
24
  npm install -g aegiscode
@@ -74,7 +74,7 @@ npm install -g aegiscode
74
74
  node cli/bin/aegiscode.js
75
75
  ```
76
76
 
77
- Requires Node 18+. Save your key once — it goes to `~/.aegiscode/credentials.json`
77
+ Requires Node 22+. Save your key once — it goes to `~/.aegiscode/credentials.json`
78
78
  (mode `0600`) and is then picked up by every later launch, script and shell:
79
79
 
80
80
  ```bash
@@ -461,7 +461,7 @@ Copy-paste, in the order you actually need them.
461
461
  ### Install and sign in
462
462
 
463
463
  ```bash
464
- npm install -g aegiscode # requires Node 18+
464
+ npm install -g aegiscode # requires Node 22+
465
465
  aegiscode login # prompts for your AEGIS key, no echo
466
466
  aegiscode key status # verify: masked key + which source is in use
467
467
  aegiscode # start a session
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "7.0.9",
4
+ "version": "7.0.11",
5
5
  "description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
@@ -21,7 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "engines": {
24
- "node": ">=18.0.0"
24
+ "node": ">=22.0.0"
25
25
  },
26
26
  "scripts": {
27
27
  "start": "node bin/aegiscode.js",
package/src/app.js CHANGED
@@ -27,7 +27,7 @@ const readline = require('node:readline');
27
27
  const os = require('node:os');
28
28
  const { randomUUID } = require('node:crypto');
29
29
  const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, provisionFailureText, trialNote, hostEnv, autonomous, claudePro } = require('./deps.js');
30
- const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung } = require('./engine.js');
30
+ const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung, offeredClasses, proEnabled } = require('./engine.js');
31
31
  const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE, AUTO_THEME_INDEX, themeIsLight, reconcileThemeIndex } = require('./theme.js');
32
32
  const { probeTerminalBackground } = require('./caps.js');
33
33
  const { LiveRegion, termWidth, w } = require('./screen.js');
@@ -225,6 +225,18 @@ function createApp(options = {}) {
225
225
  // reason confirmMode is a callback: a captured value made `/class`
226
226
  // cosmetic, changing the panel and not what the next turn ran on.
227
227
  getClass: () => commandCtx.modelClass,
228
+ // Whether the `pro` class is enabled (config.js `proEnabled`, off by
229
+ // default). Read per call for the same reason getClass is: `/class pro
230
+ // off` must remove it from the picker and stop the very next turn, not
231
+ // the next launch. A read failure answers "off" — fail closed, because
232
+ // the alternative spends a subscription nobody opted into.
233
+ getProEnabled: () => {
234
+ try {
235
+ return proEnabled(loadConfig());
236
+ } catch {
237
+ return false;
238
+ }
239
+ },
228
240
  getConfirmMode: () => {
229
241
  if (options.confirmMode !== undefined) return confirmMode;
230
242
  // AEGISONE D8 rule 5 — the skip posture, resolved by the SAME function
@@ -652,7 +664,14 @@ function createApp(options = {}) {
652
664
  * able to chat on the server's own default.
653
665
  */
654
666
  async function listModelsFor(cls) {
655
- const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
667
+ // The OFFERED set, not HOST_CLASSES: a class that is not selectable (a
668
+ // disabled `pro`) yields NOTHING rather than the live class's rows. The
669
+ // merged picker tags whatever comes back as belonging to the class it
670
+ // asked about, so substituting pooled rows here would paint pooled ids as
671
+ // Pro rows — and pinning one would move the session onto the subscription.
672
+ const allowed = selectableClasses();
673
+ if (cls && !allowed.includes(cls) && HOST_CLASSES.includes(cls)) return [];
674
+ const want = allowed.includes(cls) ? cls : commandCtx.modelClass;
656
675
  try {
657
676
  if (want === 'byok') {
658
677
  const byok = await loadByokModels();
@@ -777,7 +796,13 @@ function createApp(options = {}) {
777
796
  * not on; only an absent/unknown `cls` may fall back to the live one.
778
797
  */
779
798
  function classScopedModels(byokOverride, cls) {
780
- const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
799
+ const allowed = selectableClasses();
800
+ const want = allowed.includes(cls) ? cls : commandCtx.modelClass;
801
+ // A disabled `pro` yields no rows at all — not the pooled ones either,
802
+ // because the caller asked for pro's id space and answering with pooled ids
803
+ // is the cross-class mix-up this branch exists to prevent (the merged
804
+ // picker would tag them `pro`).
805
+ if (cls === 'pro' && !allowed.includes('pro')) return [];
781
806
  // The Pro class' list is its own alias set, never the pooled catalog: a
782
807
  // pooled id pinned under pro would be sent to `claude --model`, which
783
808
  // resolves aliases and real model names, not AEGIS ids — the same
@@ -820,9 +845,25 @@ function createApp(options = {}) {
820
845
  return !s.includes(':');
821
846
  }
822
847
 
848
+ /**
849
+ * The classes selectable right now. `pro` is behind the `proEnabled` gate
850
+ * (config.js, default off): HOST_CLASSES says this host CAN run it, this says
851
+ * whether it has been opted into. Every surface that lists or validates a
852
+ * class reads this, so the gate cannot be honoured in one place and ignored
853
+ * in another. A config read failure answers "pro is off" (fail closed).
854
+ */
855
+ function selectableClasses() {
856
+ try {
857
+ return offeredClasses(proEnabled(loadConfig()));
858
+ } catch {
859
+ return offeredClasses(false);
860
+ }
861
+ }
862
+
823
863
  /**
824
864
  * Switch the live class. Refuses anything this host cannot run (engine.js's
825
- * HOST_CLASSES is the authority).
865
+ * HOST_CLASSES is the authority) and anything it does not offer — `pro` needs
866
+ * a one-time `/class pro on` first.
826
867
  *
827
868
  * A pin is cleared when it does not belong to the class being entered: a
828
869
  * pooled id pinned under byok would be parsed as provider `<pooled id>` and
@@ -833,8 +874,17 @@ function createApp(options = {}) {
833
874
  */
834
875
  function switchClass(next) {
835
876
  const want = String(next == null ? '' : next).trim().toLowerCase();
836
- if (!HOST_CLASSES.includes(want)) {
837
- return { ok: false, error: `unknown class "${next}" — classes: ${HOST_CLASSES.join(', ')}` };
877
+ const allowed = selectableClasses();
878
+ if (!allowed.includes(want)) {
879
+ if (want === 'pro') {
880
+ return {
881
+ ok: false,
882
+ error:
883
+ 'the pro class (your Claude Code subscription) is off by default — ' +
884
+ 'enable it once with `/class pro on`',
885
+ };
886
+ }
887
+ return { ok: false, error: `unknown class "${next}" — classes: ${allowed.join(', ')}` };
838
888
  }
839
889
  const prev = commandCtx.modelClass;
840
890
  commandCtx.modelClass = want;
@@ -1517,6 +1567,8 @@ function createApp(options = {}) {
1517
1567
  else if (o.type === 'palette') lines = overlays.renderPalette(visibleCommands(), { query: o.query || '', sel: o.sel || 0 }, W, rows);
1518
1568
  else if (o.type === 'model') lines = overlays.renderModelPicker(o.items || [], o.sel || 0, W, rows, o.current != null ? o.current : commandCtx.model, o.cls || commandCtx.modelClass, classLabelOf);
1519
1569
  else if (o.type === 'effort') lines = overlays.renderEffortPicker(o.sel || 0, W, commandCtx.effort);
1570
+ else if (o.type === 'class') lines = overlays.renderClassPicker(o.items || [], o.sel || 0, W, o.current || commandCtx.modelClass, classLabelOf);
1571
+ else if (o.type === 'provider') lines = overlays.renderProviderPicker(o.items || [], o.sel || 0, W, o.current, o.hint);
1520
1572
  else if (o.type === 'resume') lines = overlays.renderResumeList(o.items || [], o.sel || 0, W, rows);
1521
1573
  else if (o.type === 'confirm') lines = render.renderApproval(ctx(), o.info || {}, W).map((s) => [spanRow(s)]);
1522
1574
  if (!lines) return;
@@ -1742,6 +1794,17 @@ function createApp(options = {}) {
1742
1794
  // leave a working prompt rather than aborting the command.
1743
1795
  const spec = await describeSecret(cmd, args);
1744
1796
  if (spec && spec.note) emit(render.renderNotice(ctx(), 'info', spec.note));
1797
+ // An explicit `prompt: null` is a refusal, not a missing description.
1798
+ // Reading it as "no description" and falling through to the generic
1799
+ // prompt is how `/byok-set <typo>` printed "unknown provider … Nothing
1800
+ // was sent" and then asked for the key anyway and sent it: the command
1801
+ // had decided this must not be stored, and the dispatcher overrode it.
1802
+ if (spec && spec.prompt === null) return true;
1803
+ // The command may have resolved the typed word to a canonical id
1804
+ // (`together-ai` → `together`). Send that. Otherwise the prompt names
1805
+ // the real provider while the request carries the alias the server does
1806
+ // not know, and the save fails after the user has already pasted a key.
1807
+ if (spec && spec.provider) args = { ...args, provider: spec.provider };
1745
1808
  const key = await askSecret((spec && spec.prompt) || `provider key for ${args.provider}: `);
1746
1809
  if (!key) {
1747
1810
  emit(render.renderNotice(ctx(), 'warn', 'empty key — nothing sent'));
@@ -1826,8 +1889,54 @@ function createApp(options = {}) {
1826
1889
 
1827
1890
  // --- entry points ---------------------------------------------------------
1828
1891
 
1892
+ /**
1893
+ * Give the local lane back its hardware, on the way out.
1894
+ *
1895
+ * The desktop has done this from its quit path since the class shipped
1896
+ * (`main.js` before-quit -> `engine.unloadLocalModels` -> local.js
1897
+ * `unloadAll`): "closing the app closes the model". The CLI had no equivalent
1898
+ * at all, so exiting a session after a `local` turn left the weights resident
1899
+ * for the remainder of the pin the turn itself set — `DEFAULT_WARM_SECS` is
1900
+ * 1800 (local.js), i.e. up to thirty minutes of a loaded model on hardware
1901
+ * nobody was using anymore, which is the one cost this lane exists to not
1902
+ * have.
1903
+ *
1904
+ * Best-effort by construction: `unloadAll` never throws and each request is
1905
+ * bounded by `UNLOAD_TIMEOUT_MS` (4s) inside the transport, so a daemon that
1906
+ * is slow, wedged or already gone cannot turn a clean exit into a hang or a
1907
+ * crash. Called from every exit path of every entry point below — INCLUDING
1908
+ * `-p`, whose whole life may be one local turn.
1909
+ *
1910
+ * Deliberately not a `process.on('exit')` handler: that callback cannot
1911
+ * await, so the request would be issued into a process that is already
1912
+ * tearing the socket down. Awaiting at the end of the session is what makes
1913
+ * the eviction actually reach the daemon.
1914
+ */
1915
+ async function releaseLocalModel() {
1916
+ if (!engine || typeof engine.unloadLocalModels !== 'function') return;
1917
+ try {
1918
+ await engine.unloadLocalModels();
1919
+ } catch {
1920
+ /* the model's own keep-alive lapses; never fail an exit over cleanup */
1921
+ }
1922
+ }
1923
+
1924
+ /**
1925
+ * One-shot run: the turn itself (`runOnceTurn`), then the local lane handed
1926
+ * back even if that turn threw. A `-p` run can BE a whole local session, so
1927
+ * it needs the same closing the interactive loop gets — see
1928
+ * `releaseLocalModel`.
1929
+ */
1930
+ async function runOnce(prompt, opts = {}) {
1931
+ try {
1932
+ return await runOnceTurn(prompt, opts);
1933
+ } finally {
1934
+ await releaseLocalModel();
1935
+ }
1936
+ }
1937
+
1829
1938
  /** Non-interactive: one prompt, plain output, exit code. */
1830
- async function runOnce(prompt, { json = false } = {}) {
1939
+ async function runOnceTurn(prompt, { json = false } = {}) {
1831
1940
  adoptLegacyKeyOnce();
1832
1941
  // Same self-service a fresh `aegiscode -p ...` deserves as a fresh
1833
1942
  // interactive session (runInteractive) or a fresh `/ask` (runPrompt):
@@ -2158,11 +2267,21 @@ function createApp(options = {}) {
2158
2267
  // Without these two the picker would re-prompt for a key the machine
2159
2268
  // demonstrably holds, which is how the same key got saved twice.
2160
2269
  accountConfigured: () => !!(credentials.keyStatus() || {}).configured,
2270
+ // `get()` is the MASKED read — it returns {provider, baseURL, configured,
2271
+ // keyMask} and never carries a `.key` field. Reading `row.key` here made
2272
+ // this predicate permanently false, so the picker re-prompted for a key
2273
+ // the machine demonstrably held: the exact bug the comment above says it
2274
+ // exists to prevent. `rawKey()` is the reader that returns the plaintext;
2275
+ // `configured` is the fallback for a store that offers only `get()`.
2161
2276
  hasProviderKey: (provider) => {
2162
2277
  const store = engine.settings;
2163
- if (!store || typeof store.get !== 'function' || !provider) return false;
2164
- const row = (store.get(byokNamespace(provider)) || {});
2165
- return !!String(row.key || '').trim();
2278
+ if (!store || !provider) return false;
2279
+ const row = byokNamespace(provider);
2280
+ if (typeof store.rawKey === 'function') {
2281
+ return !!String(store.rawKey(row) || '').trim();
2282
+ }
2283
+ if (typeof store.get !== 'function') return false;
2284
+ return !!((store.get(row) || {}).configured);
2166
2285
  },
2167
2286
  loadModels: (o) => loadModels(o),
2168
2287
  buildState: () => buildState(),
@@ -2274,7 +2393,12 @@ function createApp(options = {}) {
2274
2393
  }
2275
2394
  // The class first: a stored BYOK pin is only meaningful under byok, and the
2276
2395
  // pin check right after this reads whichever class won.
2277
- if (HOST_CLASSES.includes(cfg.modelClass)) commandCtx.modelClass = cfg.modelClass;
2396
+ //
2397
+ // Gated on the OFFERED set, not HOST_CLASSES: a config written while `pro`
2398
+ // was enabled must not restore a subscription session onto a machine where
2399
+ // it has been turned off, or where this install never opted in. Such a
2400
+ // stored value falls back to the live default rather than being trusted.
2401
+ if (selectableClasses().includes(cfg.modelClass)) commandCtx.modelClass = cfg.modelClass;
2278
2402
  if (!opts.model && cfg.model) commandCtx.model = cfg.model;
2279
2403
  // Restored through effortRung(), so a config written by an older build is
2280
2404
  // never a value this one does not send: `null`, `''` and the retired
@@ -2344,7 +2468,22 @@ function createApp(options = {}) {
2344
2468
  * injected readline, `--print` — it stays the linear loop, so output remains
2345
2469
  * pipeable and scriptable.
2346
2470
  */
2471
+ /**
2472
+ * Interactive session: the loop itself (`runInteractiveSession`), then the
2473
+ * local lane handed back. Wrapped for the same reason `runOnce` is: the loop
2474
+ * has several exits (a declined onboarding, `/quit`, a reset key stream, the
2475
+ * linear REPL), and "closing the session closes the model" must hold on all
2476
+ * of them rather than on the one path a `return` happens to reach.
2477
+ */
2347
2478
  async function runInteractive() {
2479
+ try {
2480
+ return await runInteractiveSession();
2481
+ } finally {
2482
+ await releaseLocalModel();
2483
+ }
2484
+ }
2485
+
2486
+ async function runInteractiveSession() {
2348
2487
  const tty =
2349
2488
  !options.readline &&
2350
2489
  options.chatflow !== false &&
@@ -2473,11 +2612,18 @@ function createApp(options = {}) {
2473
2612
  cloudsync,
2474
2613
  keyStatus: () => credentials.keyStatus(),
2475
2614
  accountConfigured: () => !!(credentials.keyStatus() || {}).configured,
2615
+ // Same masked-read defect as the host binding above — see the comment
2616
+ // there. Kept identical so the two hosts cannot disagree about whether a
2617
+ // key is stored.
2476
2618
  hasProviderKey: (provider) => {
2477
2619
  const store = engine.settings;
2478
- if (!store || typeof store.get !== 'function' || !provider) return false;
2479
- const row = (store.get(byokNamespace(provider)) || {});
2480
- return !!String(row.key || '').trim();
2620
+ if (!store || !provider) return false;
2621
+ const row = byokNamespace(provider);
2622
+ if (typeof store.rawKey === 'function') {
2623
+ return !!String(store.rawKey(row) || '').trim();
2624
+ }
2625
+ if (typeof store.get !== 'function') return false;
2626
+ return !!((store.get(row) || {}).configured);
2481
2627
  },
2482
2628
  sessionId: () => commandCtx.sessionId,
2483
2629
  tokenSummary,
package/src/autonomous.js CHANGED
@@ -33,7 +33,8 @@
33
33
  const path = require('node:path');
34
34
 
35
35
  const { queue, autonomous } = require('./deps.js');
36
- const { createEngine } = require('./engine.js');
36
+ const { createEngine, proEnabled } = require('./engine.js');
37
+ const { loadConfig } = require('./config.js');
37
38
  const { fmtElapsed } = require('./format.js');
38
39
  const limits = require('./limits.js');
39
40
 
@@ -57,7 +58,7 @@ const EXECUTES = new Set(['run', 'proceed', 'retry', 'reconcile']);
57
58
  */
58
59
  function parseFlags(argv) {
59
60
  const opts = { terms: [], json: false, flags: {} };
60
- const takesValue = new Set(['cwd', 'model', 'effort', 'workers', 'max', 'max-rounds', 'source']);
61
+ const takesValue = new Set(['cwd', 'model', 'effort', 'workers', 'max', 'max-rounds', 'source', 'class']);
61
62
  for (let i = 0; i < argv.length; i++) {
62
63
  const a = argv[i];
63
64
  if (a === '--json') {
@@ -154,7 +155,23 @@ function buildEngine({ io, quiet = false }) {
154
155
  if (!client.apiKey) {
155
156
  return { error: `no AEGIS account key — ${credentials.HOW_TO_SET}, or set ${credentials.KEY_ENV}` };
156
157
  }
157
- const engine = createEngine({ client, getConfirmMode: () => false });
158
+ // No `getClass` — deliberate (see engine.js chat()'s comment): a drain has
159
+ // no interactive session to read, so a queued task's own stated class is
160
+ // what runs. `getProEnabled` IS required even so, because liveClasses()
161
+ // treats a missing one as "off" and would strip `pro` out of the allowed
162
+ // set before the stated class is ever checked against it — leaving a
163
+ // `--class pro` task silently downgraded to DEFAULT_CLASS on every drain.
164
+ const engine = createEngine({
165
+ client,
166
+ getConfirmMode: () => false,
167
+ getProEnabled: () => {
168
+ try {
169
+ return proEnabled(loadConfig());
170
+ } catch {
171
+ return false;
172
+ }
173
+ },
174
+ });
158
175
  // The Pro gate (Phase 7). Built from the SAME shared decision the desktop
159
176
  // uses, bound to this host's channel so a refusal links `?s=cli` and not
160
177
  // `?s=desktop` — see cli/src/entitlement.js. Passed to the worker below as
@@ -264,6 +281,13 @@ async function runQueueCommand(command, argv, io = {}) {
264
281
  item = queue.addTask(process.env, {
265
282
  task,
266
283
  cwd,
284
+ // WHICH TRANSPORT THIS TASK RUNS ON. Omitted means 'aegis' (queue.js
285
+ // normalizes a blank class, and every pre-existing task means the
286
+ // pooled brain). The flag exists so a Pro subscription — the class the
287
+ // desktop has had since claude-pro.js and the queue never did — can be
288
+ // queued from a timer: `--class pro` with no --model lets the claude
289
+ // CLI pick, `--class pro --model opus` pins one of its aliases.
290
+ class: args.flags.class || null,
267
291
  model: args.flags.model || null,
268
292
  effort: args.flags.effort || null,
269
293
  workers: intFlag(args.flags, 'workers'),
@@ -471,8 +495,10 @@ function usageText() {
471
495
  'aegiscode autonomous <command> — the unattended work queue',
472
496
  '',
473
497
  'Commands:',
474
- ' add "<task>" queue a task (--cwd, --model, --effort, --commit,',
498
+ ' add "<task>" queue a task (--cwd, --class, --model, --effort, --commit,',
475
499
  ' --single-pass, --workers N, --max-rounds N)',
500
+ ' --class aegis|byok|local|pro (default aegis); --model must',
501
+ ' match the class (pro takes a claude alias, or none at all)',
476
502
  ' list show queued tasks and the tail of the runs log',
477
503
  ' run drain ONE task, then stop',
478
504
  ' proceed drain every pending task (--max N, --stop-on-error, --commit)',
package/src/chatflow.js CHANGED
@@ -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