aegiscode 6.8.7 → 6.8.8

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "6.8.7",
4
+ "version": "6.8.8",
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",
@@ -55,6 +55,13 @@ const FILES = [
55
55
  // for the same account on the same machine.
56
56
  'client/auto-provision.js',
57
57
  'client/device-fingerprint.js',
58
+ // The pooled-brain selection rule: which single entry stands for the Aegis
59
+ // class. Required at load time by src/models.js (through src/sharedpaths.js),
60
+ // which the picker, /model and the OpenAI-compatible shim all build their
61
+ // model list from — and by the desktop engine, so the GUI and the terminal
62
+ // offer one account one list. Leaving it out stages a package whose every
63
+ // model listing throws MODULE_NOT_FOUND before it can print a prompt.
64
+ 'client/brain-catalog.js',
58
65
  'mcp/tools.js',
59
66
  // The stdio MCP server itself — the process every editor config written by
60
67
  // `aegiscode mcp install` points at. Staging the registry without it ships a
package/src/app.js CHANGED
@@ -220,6 +220,12 @@ function createApp(options = {}) {
220
220
  // /new genuinely reset context.
221
221
  const transcript = [];
222
222
  let wantExit = false;
223
+ // When non-null, `emit` appends here instead of writing to `out`. Used by the
224
+ // one-shot path to run a command and report its output as one JSON document
225
+ // (`--json`) rather than as loose human text on stdout. Every command's output
226
+ // funnels through `emit` (pushRow's panel/note/turn branches all call it), so
227
+ // one switch here covers the whole command surface.
228
+ let capture = null;
223
229
 
224
230
  const ctx = () => ({ light: commandCtx.light });
225
231
 
@@ -665,7 +671,10 @@ function createApp(options = {}) {
665
671
  */
666
672
  function emit(lines) {
667
673
  const block = typeof lines === 'string' ? [lines] : lines;
668
- for (const l of block) out.write(l + '\n');
674
+ for (const l of block) {
675
+ if (capture) capture.push(l);
676
+ else out.write(l + '\n');
677
+ }
669
678
  }
670
679
 
671
680
  // --- the ask path ---------------------------------------------------------
@@ -1432,9 +1441,20 @@ function createApp(options = {}) {
1432
1441
  async function runOnce(prompt, { json = false } = {}) {
1433
1442
  adoptLegacyKeyOnce();
1434
1443
  if (!client.apiKey) {
1435
- err.write(`aegiscode: no AEGIS account key. ${credentials.HOW_TO_SET}, or set $${credentials.KEY_ENV}.\n`);
1444
+ err.write(`aegiscode: no AEGIS account key. ${credentials.HOW_TO_SET}, or set ${credentials.KEY_ENV}.\n`);
1436
1445
  return 2;
1437
1446
  }
1447
+ // A leading `/` is a LOCAL command at every other entry point (the chatflow
1448
+ // dispatches it, the linear REPL dispatches it), so it must be one here too.
1449
+ // This path used to skip the dispatcher entirely and hand `"/cost"` to the
1450
+ // model as ordinary user text: the request went out as a chat completion, and
1451
+ // the pool — which has no answer for a bare slash command — opened an
1452
+ // event-stream and sent nothing, so the turn died on the client's 60s idle
1453
+ // watchdog with "stream stalled". Every documented non-interactive use of a
1454
+ // command (`aegiscode -p "/cost"`, `--json -p "/models"`) was affected, and
1455
+ // the failure was indistinguishable from a server outage.
1456
+ const parsed = parseLine(prompt);
1457
+ if (parsed.kind !== 'prompt') return runOnceCommand(prompt, parsed, { json });
1438
1458
  // Snapshot the account's existing ledger BEFORE the billed call. Without
1439
1459
  // this the refresh after the turn would treat every historical row as new,
1440
1460
  // and the reported charge would be whatever the account spent last rather
@@ -1473,6 +1493,64 @@ function createApp(options = {}) {
1473
1493
  return res.interrupted ? 130 : 0;
1474
1494
  }
1475
1495
 
1496
+ /**
1497
+ * The one-shot variant of `handleLine`: run a local command and print what it
1498
+ * produced. Returns the process exit code.
1499
+ *
1500
+ * The commands are dispatched through the SAME `handleLine` the interactive
1501
+ * loop uses — not a second implementation — so `/cost`, `/models` and friends
1502
+ * cannot answer differently depending on whether a human was watching. What
1503
+ * this adds over the interactive path is only the two things a non-interactive
1504
+ * caller has that the loop does not: an exit code, and, under `--json`, a
1505
+ * machine-readable envelope around the command's own output.
1506
+ *
1507
+ * Preferences are restored first. The interactive entry point calls
1508
+ * `restorePrefs()` on startup and this one never did, so a command run through
1509
+ * `-p` would have read a context that ignored the config on disk — `/model`
1510
+ * with no pin, for instance, would not have seen the model the user pinned.
1511
+ */
1512
+ async function runOnceCommand(line, parsed, { json }) {
1513
+ if (parsed.kind === 'empty') return 0;
1514
+ if (parsed.kind === 'unknown') {
1515
+ // Straight to stderr, and non-zero: an unknown command is a caller bug, and
1516
+ // `-p` is the entry point scripts use. Going through `emit` would put the
1517
+ // diagnostic on stdout where a `$(...)` capture would swallow it, and
1518
+ // exiting 0 would make a typo look like a success.
1519
+ const alt = nearest(parsed.name);
1520
+ err.write(`aegiscode: unknown command: /${parsed.name}${alt ? ` — did you mean /${alt}?` : ''}\n`);
1521
+ return 2;
1522
+ }
1523
+ restorePrefs();
1524
+ await refreshSpend();
1525
+ const lines = json ? [] : null;
1526
+ if (lines) capture = lines;
1527
+ let keep = true;
1528
+ try {
1529
+ keep = await handleLine(line);
1530
+ } finally {
1531
+ capture = null;
1532
+ }
1533
+ if (json) {
1534
+ out.write(
1535
+ JSON.stringify(
1536
+ {
1537
+ command: parsed.kind === 'command' ? '/' + parsed.command.name : line,
1538
+ arg: parsed.arg || '',
1539
+ // `handleLine` returns false when the command asked to end the
1540
+ // session (`/quit`, `/exit`); in one-shot that simply means the
1541
+ // command ran and there is nothing further to do.
1542
+ ended: keep === false,
1543
+ output: lines,
1544
+ balance_eur: session.balance,
1545
+ },
1546
+ null,
1547
+ 2
1548
+ ) + '\n'
1549
+ );
1550
+ }
1551
+ return 0;
1552
+ }
1553
+
1476
1554
  /** Fold one completed turn's usage into the session tallies.
1477
1555
  * @returns {number|null} the total token count for the turn, when known. */
1478
1556
  function recordTurn(res) {
package/src/art.js CHANGED
@@ -9,7 +9,10 @@ const { caps, detect, cells, padCells } = require('./caps.js');
9
9
  * A platform *name* is still accepted because it is the shape a test wants when
10
10
  * it is asking "what would the mark look like on that host?"; it is resolved
11
11
  * through the same `detect()` the live process uses, so a platform string is a
12
- * convenience alias for a capability probe, never a second decision path.
12
+ * convenience alias for a capability probe, never a second decision path. Under
13
+ * the uniform policy `detect()` ignores the platform it is handed, so
14
+ * `capsOf('win32')` and `capsOf('linux')` return the same axes — which is the
15
+ * point, and is asserted by `test/cli-terminal-caps.test.mjs`.
13
16
  */
14
17
  function capsOf(target) {
15
18
  if (!target) return caps();
@@ -81,27 +84,31 @@ const TAGLINE = 'Your intent, AI automated.';
81
84
  const TAGLINE_SHORT = 'Your intent, automated.';
82
85
 
83
86
  // ── Terminal portability ─────────────────────────────────────────────────────
84
- // The wordmark is drawn with U+2550 box-drawing runes. Those are single-width on
85
- // most terminals, but not everywhere: a legacy Windows console font has no
86
- // box-drawing block at all, Terminal.app's fallback font renders the quarters
87
- // (▐▛▜▌▝▘) wrong and ✦ through the two-cell emoji fallback. Each pass swaps
88
- // offending code points 1:1 (same character count per row) so the width maths
89
- // stays exact and the mark keeps its shape.
87
+ // The wordmark is drawn with U+2550 box-drawing runes, which are single-width on
88
+ // essentially every terminal in use. Each pass swaps offending code points 1:1
89
+ // (same character count per row) so the width maths stays exact and the mark
90
+ // keeps its shape.
90
91
  //
91
- // The pass is keyed on the terminal's CAPABILITIES (`caps.js`), never on
92
- // `process.platform`. That distinction is the whole point: PowerShell inside
93
- // Windows Terminal draws this mark exactly as zsh does, and it used to be
94
- // handed the hyphen-and-hash ASCII version purely because the *process* was
95
- // win32. The three passes below compose — a Windows VT host needs the star
96
- // narrow but keeps the native block palette, which no single platform-keyed
97
- // table could express.
92
+ // A pass is applied when the user ASKS for one — `AEGIS_ART=ascii` for a font
93
+ // with no box-drawing or block range, `AEGIS_STAR=narrow` for a font that
94
+ // renders ✦ through a two-cell emoji fallback. It is never triggered by the
95
+ // host: `process.platform`, `TERM`, `TERM_PROGRAM`, `WT_SESSION` and the
96
+ // locale's character set are probed and reported by `caps.js` and then
97
+ // deliberately ignored, because a font that lacks the runes is something only
98
+ // the person looking at the screen can settle. Previously PowerShell outside
99
+ // Windows Terminal, Terminal.app and any `LANG=C` shell each silently got a
100
+ // different mark from the same build.
101
+ //
102
+ // The passes still compose rather than being picked one-of-three, because the
103
+ // two overrides are independent: `AEGIS_STAR=narrow` alone gives a native block
104
+ // palette with a single-column star, which no single flat table could express.
98
105
  //
99
106
  // This table is the ONE stencil source of truth for the product. `theme.js`
100
107
  // resolves `GLYPH.star` through `stencilGlyph(STAR, caps)` rather than carrying
101
108
  // its own `'✦' → '*'` rule, and `render.js` builds the mark's tint map by
102
109
  // stencilling its runes — both had a private copy of the same decision, which
103
- // is how a stencil edit here could leave the star wide on macOS or the whale
104
- // untinted on Windows. `test/cli-terminal-caps.test.mjs` pins all of it.
110
+ // is how a stencil edit here could leave the star wide on one host and the mark
111
+ // untinted on another. `test/cli-terminal-caps.test.mjs` pins all of it.
105
112
  const STAR = '✦';
106
113
 
107
114
  /** The quartile/quadrant face edges. The wordmark no longer draws them, but the
@@ -145,9 +152,9 @@ const EDGE_STENCIL = new Map(EDGE_RUNES.map((c) => [c, '#']));
145
152
  const STAR_STENCIL = new Map([[STAR, '*']]);
146
153
 
147
154
  /**
148
- * The named passes. They compose rather than being picked one-of-three: a
149
- * Windows VT host takes `star` only (native palette, narrow star) and
150
- * Terminal.app takes `edges` + `star`.
155
+ * The named passes. They compose rather than being picked one-of-three:
156
+ * `AEGIS_STAR=narrow` takes `star` only — a native block palette with a
157
+ * single-column star — and `AEGIS_ART=ascii` takes the full pass.
151
158
  */
152
159
  const STENCILS = { ascii: ASCII_STENCIL, edges: EDGE_STENCIL, star: STAR_STENCIL };
153
160
 
package/src/caps.js CHANGED
@@ -3,35 +3,39 @@
3
3
  /**
4
4
  * Terminal capabilities — ONE probe, resolved once, consulted by everything.
5
5
  *
6
- * The UI used to decide how to draw itself from `process.platform`: Windows got
7
- * the ASCII stencil, macOS got a half-stencil, Linux got the native mark. That
8
- * is the wrong axis. The platform of the *process* says nothing about the
9
- * terminal it is talking to, and the two most common real-world runtimes prove
10
- * it:
6
+ * POLICY: aegiscode renders ONE way. `process.platform`, `TERM`, `TERM_PROGRAM`,
7
+ * the locale's character set and the Windows terminal markers are all still
8
+ * probed — because the support surface reports them — but not one of them may
9
+ * move a single byte of what is drawn. PowerShell in Windows Terminal,
10
+ * Terminal.app, a legacy Windows console, WSL and zsh over SSH all get the same
11
+ * palette, the same mark, the same colour depth, the same control sequences and
12
+ * the same `\n`. A screenshot of one is a screenshot of all of them.
11
13
  *
12
- * · PowerShell *inside Windows Terminal* (`WT_SESSION` set) draws
13
- * █▓▒░▐▛▜▌▝▘ and ✦ exactly like zsh does — but `process.platform` is still
14
- * `win32`, so it was being handed the hyphen-and-hash ASCII mark.
15
- * · `zsh` over SSH from a Windows box, inside `mintty`/`ConEmu`, is `linux`
16
- * on the far side and `win32` on the client — the mark must be chosen once,
17
- * from what the *terminal* can draw.
14
+ * What used to differ by platform or environment, and no longer does:
18
15
  *
19
- * So the decision is made from the environment the process is actually running
20
- * in — `TERM`, `COLORTERM`, `TERM_PROGRAM`, the Windows terminal markers
21
- * (`WT_SESSION`, `ConEmuANSI`, `ANSICON`, …), the locale's character set, and
22
- * whether stdout is a TTY. Every axis is overridable, because only the person
23
- * looking at the screen can settle the cases no environment variable can
24
- * (a Windows console with a font that lacks the block glyphs, a macOS terminal
25
- * that renders ✦ as a wide emoji).
16
+ * · Windows got the ASCII stencil because `process.platform` was `win32` —
17
+ * even *inside Windows Terminal*, which draws █▓▒░▐▛▜▌▝▘ and ✦ exactly like
18
+ * zsh does.
19
+ * · Terminal.app got a half-stencil (edges stencilled, star narrowed) because
20
+ * its font stack lacks ▐▛▜▌▝▘ and renders ✦ through the wide emoji fallback.
21
+ * · A non-UTF-8 locale, or `TERM=dumb`, dropped the whole UI to ASCII — so the
22
+ * same build looked like a different product in `LANG=C` CI.
23
+ * · `TERM=linux|vt100|ansi` and a legacy console flattened truecolor to the 16
24
+ * ANSI slots.
25
+ * · A redirected run on Windows wrote CRLF; the same run on Linux wrote LF.
26
+ *
27
+ * The probe is not gone, it is just no longer *implicit*. Every axis below is
28
+ * still overridable, and an override is now the ONLY thing that changes the
29
+ * rendering. All of them are environment variables and flags, so they are
30
+ * spelled and behave identically on every platform, and the resulting look is
31
+ * reproducible from a bug report without asking what OS it came from.
26
32
  *
27
33
  * The axes:
28
- * glyphs 'unicode' | 'ascii' — can the mark's palette be drawn at all?
29
- * face 'native' | 'edges' — do the quartile edges ▐▛▜▌▝▘ exist in the
30
- * terminal's font, or must they be stencilled?
31
- * star 'native' | 'narrow' — is ✦ a single-cell text glyph, or does the
32
- * terminal fall back to a wide emoji?
33
- * depth 24 | 8 | 4 | 0 — truecolor, 256, the 16 ANSI slots, none
34
- * vt boolean — are cursor/erase escapes honoured?
34
+ * glyphs 'unicode' | 'ascii' — the mark's palette (unicode by default)
35
+ * face 'native' | 'edges' — the quartile edges ▐▛▜▌▝▘
36
+ * star 'native' | 'narrow' — ✦ as a single-cell glyph, or stencilled to `*`
37
+ * depth 24 | 8 | 4 | 0 — truecolor by default
38
+ * vt boolean — cursor/erase escapes (on by default)
35
39
  * cols/rows — the frame, with `AEGIS_WIDTH`/`COLUMNS` over
36
40
  * the reported size and a stable 80 fallback,
37
41
  * wideRunes — runes the terminal draws two cells wide
@@ -43,6 +47,7 @@
43
47
  * AEGIS_ART=unicode|ascii AEGIS_ASCII=1 AEGIS_UNICODE=0|1
44
48
  * AEGIS_STAR=native|narrow AEGIS_COLOR=0|1|2|3
45
49
  * AEGIS_VT=0|1 AEGIS_WIDTH=<cols> AEGIS_WIDE_RUNES=<runes>
50
+ * AEGIS_FORCE_TRUECOLOR=0 NO_COLOR FORCE_COLOR=0|1|2|3
46
51
  *
47
52
  * `caps()` is cached; `setCaps()` re-resolves and notifies subscribers, which is
48
53
  * how `theme.js` re-materialises its palette and glyph table when the user runs
@@ -63,11 +68,15 @@ const RE_ZERO = /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uF
63
68
  const RE_WIDE = /[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA000-\uA4CF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6\u{1F1E6}-\u{1F1FF}\u{1F300}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}\u{1FA70}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u;
64
69
 
65
70
  /**
66
- * Windows terminals that draw the full mark. `WT_SESSION` is set by Windows
71
+ * Windows terminals that can draw the full mark. `WT_SESSION` is set by Windows
67
72
  * Terminal for every shell it hosts (pwsh, cmd, wsl, git-bash); `TERM_PROGRAM`
68
73
  * by VS Code and the other Electron/ConPTY hosts; the rest are the classic
69
- * ConPTY-era consoles. Presence of any of them means the console is VT-capable
70
- * and its default font carries the block-element range.
74
+ * ConPTY-era consoles.
75
+ *
76
+ * Reported, never consulted: the rendering is uniform whether one of these is
77
+ * set or not (see the policy at the top of this file). The list survives so
78
+ * `--terminal` can say "Windows VT host (WT_SESSION)" in a bug report, which is
79
+ * how a support thread knows the user's console can draw what we draw.
71
80
  */
72
81
  const MODERN_WINDOWS = [
73
82
  'WT_SESSION',
@@ -80,27 +89,6 @@ const MODERN_WINDOWS = [
80
89
  'KITTY_WINDOW_ID',
81
90
  ];
82
91
 
83
- /**
84
- * `TERM_PROGRAM` values whose font renders the whole palette natively, `✦`
85
- * included. `Apple_Terminal` is deliberately NOT here — see `resolveGlyphs`.
86
- */
87
- const NATIVE_TERM_PROGRAMS = new Set([
88
- 'vscode',
89
- 'vscode-insiders',
90
- 'iTerm.app',
91
- 'WezTerm',
92
- 'kitty',
93
- 'ghostty',
94
- 'Alacritty',
95
- 'Hyper',
96
- 'Tabby',
97
- 'WarpTerminal',
98
- 'Warp',
99
- 'rio',
100
- 'mintty',
101
- 'JetBrains-JediTerm',
102
- ]);
103
-
104
92
  const TRUTHY_RE = /^(1|true|yes|on)$/i;
105
93
 
106
94
  /** Is an env value "on"? (`WT_SESSION=` with no value still counts.) */
@@ -124,20 +112,16 @@ function modernWindows(env) {
124
112
 
125
113
  /**
126
114
  * The locale's character set. POSIX terminals signal UTF-8 support here and
127
- * nowhere else: a terminal launched with `LANG=C` cannot draw ░▒▓, and no
128
- * amount of TERM sniffing will tell you that.
115
+ * nowhere else. Recorded for the support surface only: a `LANG=C` shell renders
116
+ * the same Unicode mark as a UTF-8 one, so that the same build cannot look like
117
+ * a different product on a differently-configured host. A terminal whose font
118
+ * genuinely lacks the palette is a deliberate `AEGIS_ART=ascii`.
129
119
  */
130
120
  function localeOf(env) {
131
121
  const hit = firstEnv(env, ['LC_ALL', 'LC_CTYPE', 'LANG']);
132
122
  return hit ? hit.value : '';
133
123
  }
134
124
 
135
- function utf8Locale(env) {
136
- const loc = localeOf(env);
137
- if (!loc) return true; // unset: every shell we ship to defaults to UTF-8
138
- return /utf-?8/i.test(loc);
139
- }
140
-
141
125
  /** The explicit art mode, or 'auto'. */
142
126
  function artMode(env) {
143
127
  const raw = String(env.AEGIS_ART || '').trim().toLowerCase();
@@ -149,10 +133,24 @@ function artMode(env) {
149
133
  }
150
134
 
151
135
  /**
152
- * Resolve what the mark may be drawn with. Order matters: an explicit request
153
- * always wins, then the terminal's own declarations, then the two signals that
154
- * mean "this cannot work" (a dumb terminal, a non-UTF-8 locale), then the
155
- * legacy-Windows console.
136
+ * What the mark is drawn with — the same answer on every platform.
137
+ *
138
+ * Only an explicit request moves this: `AEGIS_ART` (the valued switch),
139
+ * `AEGIS_ASCII`/`AEGIS_UNICODE` (the booleans it supersedes), or `AEGIS_STAR`
140
+ * for a font that renders ✦ through a wide emoji fallback. Everything else —
141
+ * `process.platform`, `TERM`, `TERM_PROGRAM`, `WT_SESSION`, the locale's
142
+ * character set — is recorded in the resolved `reasons` for the support surface
143
+ * and then deliberately ignored.
144
+ *
145
+ * The old behaviour read those signals and silently downgraded: a `win32`
146
+ * process outside a ConPTY host, an Apple Terminal, `TERM=dumb` and any
147
+ * non-UTF-8 locale each got a different product. That made the same build look
148
+ * unlike itself from one machine to the next, and it made the *reason* for the
149
+ * difference invisible to the person looking at the screen. A terminal that
150
+ * genuinely cannot draw the palette now says so with the documented override,
151
+ * which is a decision the user makes once and the support surface can report.
152
+ *
153
+ * `platform` is accepted (and reported) but never branched on.
156
154
  */
157
155
  function resolveGlyphs(env, platform) {
158
156
  const starPref = String(env.AEGIS_STAR || '').trim().toLowerCase();
@@ -170,56 +168,11 @@ function resolveGlyphs(env, platform) {
170
168
  return { glyphs: 'unicode', face: 'native', star: star || 'native', reason: 'AEGIS_ART=unicode' };
171
169
  }
172
170
 
173
- if (String(env.TERM || '').toLowerCase() === 'dumb') {
174
- return { glyphs: 'ascii', face: 'edges', star: 'narrow', reason: 'TERM=dumb' };
175
- }
176
-
177
- if (platform === 'win32') {
178
- const modern = modernWindows(env);
179
- if (!modern) {
180
- return {
181
- glyphs: 'ascii',
182
- face: 'edges',
183
- star: 'narrow',
184
- reason: 'legacy Windows console (no WT_SESSION/ConEmu/TERM_PROGRAM) — Consolas has no block glyphs',
185
- };
186
- }
187
- // A ConPTY host (Windows Terminal, VS Code, ConEmu) renders the block
188
- // palette, and ConPTY does font fallback — Cascadia Mono lacks ✦ but the
189
- // system symbol fonts carry it single-width, so the star is drawn natively
190
- // and the welcome mark is byte-identical to the one zsh prints. That parity
191
- // is the point: `star: 'narrow'` here would swap all eleven ✦ in the mark
192
- // for '*', which is the difference a PowerShell user sees.
193
- //
194
- // The escape hatches are for the font that does *not* fall back cleanly:
195
- // AEGIS_STAR=narrow swaps ✦ for '*', AEGIS_WIDE_RUNES=✦ tells the width
196
- // maths the glyph is two cells wide (which is what a bad fallback actually
197
- // breaks — the row alignment, not the rune).
198
- return {
199
- glyphs: 'unicode',
200
- face: 'native',
201
- star: star || 'native',
202
- reason: `Windows VT host (${modern.name})`,
203
- };
204
- }
205
-
206
- if (!utf8Locale(env)) {
207
- return { glyphs: 'ascii', face: 'edges', star: 'narrow', reason: `locale is not UTF-8 (${localeOf(env)})` };
208
- }
209
-
210
- const program = String(env.TERM_PROGRAM || '');
211
- if (platform === 'darwin' && program === 'Apple_Terminal') {
212
- // Terminal.app's font stack has no ▐▛▜▌▝▘ and renders ✦ with the emoji
213
- // fallback (two cells), so it gets the edge pass and a narrow star — the
214
- // shipped behaviour on macOS, now expressed as a capability, not a platform.
215
- return { glyphs: 'unicode', face: 'edges', star: 'narrow', reason: 'Apple_Terminal font stack' };
216
- }
217
-
218
171
  return {
219
172
  glyphs: 'unicode',
220
173
  face: 'native',
221
174
  star: star || 'native',
222
- reason: program ? `${program} terminal` : `TERM=${env.TERM || 'unset'}`,
175
+ reason: `uniform default on every platform${star ? ` (AEGIS_STAR=${starPref})` : ''}`,
223
176
  };
224
177
  }
225
178
 
@@ -227,15 +180,19 @@ function resolveGlyphs(env, platform) {
227
180
  * Colour depth in bits per channel: 24 truecolor, 8 the 256-colour cube, 4 the
228
181
  * 16 ANSI slots, 0 no colour at all.
229
182
  *
230
- * The default is truecolor, because that is the honest answer for every
231
- * terminal we can name: the 256-colour terminals in use today all pass 24-bit
232
- * SGR through, and a terminal that cannot simply downsamples it itself — which
233
- * is the correct authority for the decision. Only a provably narrow terminal
234
- * (legacy Windows console, `TERM=linux|vt100|ansi`, `NO_COLOR`) is downgraded,
235
- * so the palette cannot be silently flattened on a machine that could have
236
- * shown it.
183
+ * Truecolor, always, unless the user says otherwise. That is the honest default
184
+ * for every terminal in use: the 256-colour terminals all pass 24-bit SGR
185
+ * through, and a terminal that cannot simply downsamples it itself — which is
186
+ * the correct authority for the decision. The old probe tried to guess the
187
+ * terminal's ceiling from `TERM`, from the platform and from the Windows console
188
+ * markers, and every wrong guess flattened the palette on a machine that could
189
+ * have shown it *and* made Windows differ from Linux on identical hardware.
190
+ *
191
+ * `NO_COLOR` (non-empty), `FORCE_COLOR=0` and `AEGIS_COLOR=0` are the only ways
192
+ * to get depth 0; `FORCE_COLOR`/`AEGIS_COLOR` pick 4, 8 or 24; the older
193
+ * `AEGIS_FORCE_TRUECOLOR=0` still selects the 256-colour cube.
237
194
  */
238
- function resolveDepth(env, platform, isTTY) {
195
+ function resolveDepth(env) {
239
196
  if (env.NO_COLOR != null && env.NO_COLOR !== '') return { depth: 0, reason: 'NO_COLOR' };
240
197
  const forced = String(env.FORCE_COLOR || '').trim();
241
198
  if (forced === '0') return { depth: 0, reason: 'FORCE_COLOR=0' };
@@ -246,47 +203,23 @@ function resolveDepth(env, platform, isTTY) {
246
203
  if (/^[0-3]$/.test(aegis)) {
247
204
  return { depth: aegis === '0' ? 0 : aegis === '1' ? 4 : aegis === '2' ? 8 : 24, reason: `AEGIS_COLOR=${aegis}` };
248
205
  }
249
- if (String(env.COLORTERM || '').trim() !== '' && /^(truecolor|24bit)$/i.test(env.COLORTERM)) {
250
- return { depth: 24, reason: `COLORTERM=${env.COLORTERM}` };
251
- }
252
- const term = String(env.TERM || '').toLowerCase();
253
- if (term === 'dumb') return { depth: 0, reason: 'TERM=dumb' };
254
- if (platform === 'win32') {
255
- const modern = modernWindows(env);
256
- if (modern) return { depth: 24, reason: `Windows VT host (${modern.name})` };
257
- // The classic console: 16 slots, and only when it is actually a console.
258
- if (isTTY) return { depth: 4, reason: 'legacy Windows console' };
259
- return { depth: 24, reason: 'redirected output' };
260
- }
261
- if (/^(linux|vt100|vt220|ansi|cons25|sun|dumb)$/.test(term) || /^xterm-color$/.test(term)) {
262
- return { depth: 4, reason: `TERM=${term}` };
263
- }
264
- if (env.AEGIS_FORCE_TRUECOLOR === '0' || env.TERM_PROGRAM === 'Apple_Terminal') {
265
- // Terminal.app advertises truecolor and honours 24-bit SGR on every release
266
- // that still runs, so it keeps its depth; the check exists for the older
267
- // builds that dithered. AEGIS_FORCE_TRUECOLOR=0 is the user's override.
268
- if (env.AEGIS_FORCE_TRUECOLOR === '0') return { depth: 8, reason: 'AEGIS_FORCE_TRUECOLOR=0' };
269
- }
270
- return { depth: 24, reason: term ? `TERM=${term}` : 'default' };
206
+ if (env.AEGIS_FORCE_TRUECOLOR === '0') return { depth: 8, reason: 'AEGIS_FORCE_TRUECOLOR=0' };
207
+ return { depth: 24, reason: 'uniform default: truecolor on every platform' };
271
208
  }
272
209
 
273
210
  /**
274
- * Cursor and erase control. Never claimed for a dumb terminal or redirected
275
- * output on Windows (where `\x1b[2K` would be printed as text), and always
276
- * assumed for a POSIX terminal — the live spinner line depends on it.
211
+ * Cursor and erase control — on everywhere, since every terminal we ship to
212
+ * honours it, and off only for an explicit `AEGIS_VT=0`. The old probe guessed
213
+ * from the platform and the console markers, which meant the live spinner line
214
+ * behaved differently in a Windows console than in a Linux one; a redirected
215
+ * Windows run is no longer treated as a terminal that would print `\x1b[2K` as
216
+ * text, because that is the same run everywhere and should render the same.
277
217
  */
278
- function resolveVt(env, platform, isTTY) {
218
+ function resolveVt(env) {
279
219
  const pref = String(env.AEGIS_VT == null ? '' : env.AEGIS_VT).trim();
280
220
  if (pref === '0') return { vt: false, reason: 'AEGIS_VT=0' };
281
221
  if (pref === '1' || /^(true|yes|on)$/i.test(pref)) return { vt: true, reason: 'AEGIS_VT=1' };
282
- if (String(env.TERM || '').toLowerCase() === 'dumb') return { vt: false, reason: 'TERM=dumb' };
283
- if (platform === 'win32') {
284
- const modern = modernWindows(env);
285
- if (modern) return { vt: true, reason: `Windows VT host (${modern.name})` };
286
- if (isTTY) return { vt: true, reason: 'console host (Node enables VT processing)' };
287
- return { vt: false, reason: 'redirected output' };
288
- }
289
- return { vt: true, reason: 'POSIX terminal' };
222
+ return { vt: true, reason: 'uniform default: ansi on every platform' };
290
223
  }
291
224
 
292
225
  /**
@@ -323,24 +256,33 @@ function resolveWideRunes(env) {
323
256
 
324
257
  /**
325
258
  * Resolve every axis, purely, from an environment and a stream. Exported so the
326
- * platform matrix is a plain function call in a test — no subprocess, no TTY.
259
+ * uniformity invariant is a plain function call in a test — no subprocess, no
260
+ * TTY.
261
+ *
262
+ * `platform` is recorded in the result and threaded into the *reasons*, so a
263
+ * support paste still says which host it came from; nothing else reads it. The
264
+ * line ending is `\n` on every platform, including a redirected run on Windows:
265
+ * the one divergence the previous probe allowed is exactly the kind of thing
266
+ * that makes two identical invocations produce different bytes.
327
267
  *
328
268
  * @param {object} [env] defaults to `process.env`
329
269
  * @param {object} [stdout] defaults to `process.stdout`
330
- * @param {string} [platform] defaults to `process.platform`
270
+ * @param {string} [platform] defaults to `process.platform` (reported, not consulted)
331
271
  */
332
272
  function detect(env = process.env, stdout = process.stdout, platform = process.platform) {
333
273
  const isTTY = !!(stdout && stdout.isTTY);
334
274
  const glyph = resolveGlyphs(env, platform);
335
- const color = resolveDepth(env, platform, isTTY);
336
- const vt = resolveVt(env, platform, isTTY);
275
+ const color = resolveDepth(env);
276
+ const vt = resolveVt(env);
337
277
  const size = resolveSize(env, stdout);
278
+ const host = platform === 'win32' ? modernWindows(env) : null;
338
279
  return {
339
280
  platform,
340
281
  isTTY,
341
282
  term: String(env.TERM || ''),
342
283
  termProgram: String(env.TERM_PROGRAM || ''),
343
284
  locale: localeOf(env),
285
+ windowsHost: host ? host.name : '',
344
286
  glyphs: glyph.glyphs,
345
287
  face: glyph.face,
346
288
  star: glyph.star,
@@ -349,7 +291,7 @@ function detect(env = process.env, stdout = process.stdout, platform = process.p
349
291
  vt: vt.vt,
350
292
  cols: size.cols,
351
293
  rows: size.rows,
352
- eol: platform === 'win32' && !isTTY ? '\r\n' : '\n',
294
+ eol: '\n',
353
295
  wideRunes: resolveWideRunes(env),
354
296
  reasons: {
355
297
  glyphs: glyph.reason,
@@ -556,11 +498,18 @@ function bg(r, g, b) {
556
498
  /**
557
499
  * The resolved capabilities as `[label, value]` rows — one shape, same on every
558
500
  * platform, so a support paste from PowerShell reads like one from zsh.
501
+ *
502
+ * The first three rows are the host as *reported*: they are the only place the
503
+ * platform, the terminal brand and the locale appear, and they cannot influence
504
+ * any row below them. That is the point of the layout — a reader can see at a
505
+ * glance that the mark, the colour, the control sequences and the line ending
506
+ * are the same on every machine, while still knowing which machine produced the
507
+ * paste.
559
508
  */
560
509
  function describe(c = caps()) {
561
- const eol = c.eol === '\r\n' ? '\\r\\n' : '\\n';
510
+ const host = [c.platform, c.isTTY ? '' : '(no tty)'].filter(Boolean).join(' ');
562
511
  return [
563
- ['platform', `${c.platform}${c.isTTY ? '' : ' (no tty)'}`],
512
+ ['platform', c.windowsHost ? `${host} — ${c.windowsHost}` : host],
564
513
  ['terminal', c.termProgram || c.term || 'unknown'],
565
514
  ['locale', c.locale || 'unset'],
566
515
  ['mark', c.glyphs === 'ascii' ? 'ascii' : c.face === 'edges' ? 'unicode (edges stencilled)' : 'unicode'],
@@ -568,7 +517,7 @@ function describe(c = caps()) {
568
517
  ['color', c.depth === 0 ? 'none' : c.depth >= 24 ? 'truecolor' : c.depth >= 8 ? '256' : '16'],
569
518
  ['control', c.vt ? 'ansi' : 'plain'],
570
519
  ['size', `${c.cols}x${c.rows} (${c.reasons.size})`],
571
- ['eol', eol],
520
+ ['eol', '\\n'],
572
521
  ['why', `${c.reasons.glyphs}; ${c.reasons.depth}`],
573
522
  ];
574
523
  }
@@ -593,5 +542,4 @@ module.exports = {
593
542
  resolveVt,
594
543
  resolveSize,
595
544
  MODERN_WINDOWS,
596
- NATIVE_TERM_PROGRAMS,
597
545
  };
package/src/models.js CHANGED
@@ -12,16 +12,38 @@
12
12
  * would silently route somewhere else.
13
13
  *
14
14
  * The platform lists per-provider ids (`deepseek`, `anthropic`, `groq`, …) plus
15
- * the pooled-brain tiers. The desktop host collapsed all of that to a single
16
- * "Nexus" entry because its dropdown *is* the model choice and surfacing
17
- * per-provider routing invites pinning a provider that happens to be dead right
18
- * now (see desktop/lib/local/engine.js selectBrainEntry). This host keeps every
19
- * distinct id — a CLI user pinning `deepseek` explicitly is a legitimate
20
- * request — but drops the pure-alias duplicates the server itself marks
21
- * `hidden: true, alias_of: "<id>"` (`aegis-brain`, `nexus-brain-smart`, …),
22
- * which are the same model advertised under another spelling.
15
+ * the pooled-brain tiers. What this host OFFERS for the pooled class is the
16
+ * same single collapsed "Nexus" entry the desktop offers, and it is now the
17
+ * same *code* that decides it: `client/brain-catalog.js`, required through
18
+ * `src/sharedpaths.js` so a checkout and an installed package resolve it the
19
+ * same way. Offering one entry is not accepting one entry — the server's ids
20
+ * stay pinnable (`/model deepseek` still validates against the full catalog
21
+ * through `findModel`/`catalogIds`), which is why the collapse lives here in
22
+ * what we *show* rather than in what we *normalise*.
23
+ *
24
+ * This host used to keep every distinct id, on the argument that a CLI user
25
+ * pinning `deepseek` explicitly is a legitimate request. It is — but that is
26
+ * an argument about accepting ids, and it was implemented as an argument about
27
+ * displaying them, so the same account saw seven models in the terminal and one
28
+ * in the GUI. The two hosts disagreeing about one account was the actual bug.
29
+ *
30
+ * A payload with no brain tier at all (the BYOK listing, which is per-provider
31
+ * models) is not collapsed: `filterAegisCatalog` returns `[]` for it, and this
32
+ * module then offers every distinct entry exactly as before.
23
33
  */
24
34
 
35
+ const path = require('node:path');
36
+
37
+ const { resolveShared } = require('./sharedpaths.js');
38
+
39
+ /**
40
+ * The shared selection rule — required at load time and by EXISTENCE, never
41
+ * with a fallback copy here: a silently divergent local implementation is the
42
+ * precise defect this file was changed to remove. A missing module is a loud
43
+ * error naming the file, which is what `resolveShared` throws.
44
+ */
45
+ const { filterAegisCatalog } = require(resolveShared(path.join('client', 'brain-catalog.js')));
46
+
25
47
  /** A pinned id of `null` means "no pin — let the pool choose" (the server's own default). */
26
48
  const NO_PIN = null;
27
49
 
@@ -88,13 +110,25 @@ function normalizeModelCatalog(raw) {
88
110
  }
89
111
 
90
112
  /**
91
- * The entries the picker and `/models` offer: every distinct advertised model,
92
- * minus the alias duplicates — unless the catalog is *only* aliases, in which
93
- * case the aliases are all the server advertises and are offered rather than
94
- * leaving the user with an empty list.
113
+ * The entries the picker and `/models` offer.
114
+ *
115
+ * Pooled class: exactly one entry, the collapsed brain, decided by the shared
116
+ * rule (`client/brain-catalog.js`) so the terminal and the GUI cannot offer the
117
+ * same account two different lists. The collapsed entry is re-normalised here
118
+ * so renderers keep the `label`/`note` columns they already expect, and so the
119
+ * brain's cost shape ("multi-call fan-out, sized by /effort") still reaches the
120
+ * picker's right-hand column.
121
+ *
122
+ * BYOK class: no brain tier is present, `filterAegisCatalog` reports that with
123
+ * `[]`, and every distinct advertised model is offered — minus the server's own
124
+ * alias duplicates, unless the catalog is *only* aliases, in which case the
125
+ * aliases are all the server advertises and are offered rather than leaving the
126
+ * user with an empty list.
95
127
  */
96
128
  function pickerEntries(catalog) {
97
129
  const all = Array.isArray(catalog) ? catalog.filter(Boolean) : [];
130
+ const collapsed = filterAegisCatalog(all).map(normalizeModel).filter(Boolean);
131
+ if (collapsed.length) return collapsed;
98
132
  const distinct = all.filter((m) => !m.aliasOf);
99
133
  return distinct.length ? distinct : all;
100
134
  }
package/src/theme.js CHANGED
@@ -15,14 +15,15 @@
15
15
  * What DOES change per terminal is how those triples reach the screen:
16
16
  *
17
17
  * · `RGB()`/`BG()` go through `caps.rgb()/caps.bg()`, which emit 24-bit SGR,
18
- * the 256-colour cube, the 16 ANSI slots, or nothing at all — decided by the
19
- * terminal, not by us. On a legacy Windows console or `TERM=linux` the UI
20
- * now paints in colours that console can actually show, instead of emitting
21
- * truecolor escapes it renders as literal text or dithers unpredictably.
22
- * · `glyphsFor()` is a function of the resolved capabilities, so PowerShell in
23
- * Windows Terminal gets the same ❯ ⎿ ✻ ✦ set as zsh, and only a terminal
24
- * that genuinely cannot draw them (legacy console, `TERM=dumb`, a non-UTF-8
25
- * locale, `AEGIS_ART=ascii`) gets the ASCII stand-ins.
18
+ * the 256-colour cube, the 16 ANSI slots, or nothing at all. Truecolor is
19
+ * the default on every platform, because the terminals we ship to all pass
20
+ * 24-bit SGR through and a terminal that cannot downsamples it itself —
21
+ * which is the correct authority for the decision. Narrowing the palette is
22
+ * an explicit request (`AEGIS_COLOR=1|2`, `FORCE_COLOR`, `NO_COLOR`,
23
+ * `AEGIS_FORCE_TRUECOLOR=0`), never an inference from `TERM` or the OS.
24
+ * · `glyphsFor()` is a function of the resolved capabilities, so every host
25
+ * gets the same ❯ ⎿ ✻ ✦ set; the ASCII stand-ins appear only when the user
26
+ * asks for them (`AEGIS_ART=ascii`, `--ascii`).
26
27
  *
27
28
  * Both are re-materialised when the capabilities change (`onCapsChange`), so
28
29
  * `aegiscode --ascii`, `--no-color` and the `/terminal` command take effect on
@@ -284,25 +285,26 @@ function diffOf(ctx) {
284
285
  * A few of the reference's glyphs are missing from some terminal fonts
285
286
  * (⎿ U+23BF, ⏸ U+23F8, ✔ U+2714, ▸ U+25B8) or render as double-width emoji
286
287
  * (✦ U+2726, ✻/✢/✽/✶), which breaks row alignment exactly like the welcome art.
287
- * The three capability classes in `caps.js` decide the set:
288
+ * The capability classes in `caps.js` decide the set, and the host is not one of
289
+ * them — see the policy at the top of that file:
288
290
  *
289
- * · `glyphs: 'ascii'` — no Unicode claim at all: legacy Windows console,
290
- * `TERM=dumb`, a non-UTF-8 locale, `AEGIS_ART=ascii`. Every mark becomes a
291
- * single-column ASCII stand-in, so the layout is identical but nothing is
292
- * mis-rendered by a font that lacks the glyph.
293
- * · `face: 'edges'` — the block palette survives but the quartile edges
294
- * and the typographic marks (⎿, ⏸, ✔) do not (Apple fonts, older Windows
295
- * fonts). Only those are swapped.
296
- * · native — the reference's own set, on any terminal that can
297
- * draw it: Windows Terminal, VS Code, iTerm2, WezTerm, kitty, Ghostty,
298
- * Alacritty, GNOME Terminal, xterm, zsh on Linux/macOS.
291
+ * · `glyphs: 'ascii'` — no Unicode claim at all, requested with
292
+ * `AEGIS_ART=ascii` / `--ascii`. Every mark becomes a single-column ASCII
293
+ * stand-in, so the layout is identical but nothing is mis-rendered by a font
294
+ * that lacks the glyph.
295
+ * · `face: 'edges'` — the quartile edges and the typographic marks (⎿, ⏸,
296
+ * ✔) are swapped; reachable today only through the ASCII pass, and kept
297
+ * because `AEGIS_ART=unicode` on a font without the edges must be
298
+ * expressible.
299
+ * · native — the default everywhere: the reference's own set.
299
300
  *
300
301
  * `star` is NOT restated here: it is resolved through `art.js`'s stencil, the
301
302
  * single source of truth for the mark's runes, so the glyph table and the art
302
303
  * can never disagree about the same character.
303
304
  *
304
- * @param {string|object} [target] a `process.platform` name, or a caps object,
305
- * or nothing at all for the live process's resolved capabilities.
305
+ * @param {string|object} [target] a `process.platform` name (accepted for
306
+ * tests, ignored by the policy), or a caps object, or nothing at all for the
307
+ * live process's resolved capabilities.
306
308
  */
307
309
  function glyphsFor(target = null) {
308
310
  const c = !target
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The pooled-brain entry, defined ONCE for every host.
5
+ *
6
+ * The platform's `/api/v1/models` payload lists the brain tier under five
7
+ * spellings (`nexus-brain` canonical; `aegis-brain`, `nexus-brain-smart`,
8
+ * `aegis-brain-smart`, `nexus-brain-neo` each sent as `hidden: true,
9
+ * alias_of: "nexus-brain"`). A host that showed all five painted five models
10
+ * where the server routes one, and a host that showed none (or a different one
11
+ * per release) left users comparing two clients that disagree about the same
12
+ * account.
13
+ *
14
+ * This module exists because that disagreement was real: the desktop collapsed
15
+ * the class to a single "Nexus" entry (desktop/lib/local/engine.js) while the
16
+ * CLI kept every distinct id, so the same account saw a different model list in
17
+ * each host. Two copies of the selection rule is the drift; one shared function
18
+ * is the fix, which is why both hosts require THIS file — the desktop from
19
+ * `desktop/lib/local/engine.js` (repo-relative `client/brain-catalog.js`, or
20
+ * `desktop/vendor/brain-catalog.js` in the packaged app) and the CLI from
21
+ * `cli/src/models.js` (through `src/sharedpaths.js`: repo-relative
22
+ * `client/brain-catalog.js`, or `vendor/client/brain-catalog.js` installed).
23
+ *
24
+ * The two hosts do NOT hand this module the same entry shape and must not have
25
+ * to: the desktop passes the relay's raw payload (`hidden`, `alias_of`), the
26
+ * CLI passes its own normalised entries (`hidden`, `aliasOf`). So the readers
27
+ * below accept either spelling — one rule, two shapes — instead of each host
28
+ * keeping a private copy of the rule to match its own shape, which is the drift
29
+ * this module exists to end.
30
+ *
31
+ * Pure: no I/O, no node builtins, no dependencies — safe to require from a
32
+ * renderer, a CLI start-up path, or an MCP host.
33
+ */
34
+
35
+ /** Every id the server uses for the pooled brain, canonical spelling first. */
36
+ const NEXUS_BRAIN_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
37
+
38
+ /** The name users see for the collapsed entry. */
39
+ const NEXUS_LABEL = 'Nexus';
40
+
41
+ /**
42
+ * The id this entry is an alias OF, or `null`. Reads the relay's `alias_of` and
43
+ * the CLI's normalised `aliasOf`, so callers may pass either shape.
44
+ */
45
+ function aliasOfEntry(m) {
46
+ if (!m || typeof m !== 'object') return null;
47
+ for (const value of [m.alias_of, m.aliasOf]) {
48
+ if (typeof value === 'string' && value.trim()) return value.trim();
49
+ }
50
+ return null;
51
+ }
52
+
53
+ /** Whether the entry is marked display-hidden, in either shape. */
54
+ function isHiddenEntry(m) {
55
+ return Boolean(m) && m.hidden === true;
56
+ }
57
+
58
+ /**
59
+ * Pick the one entry standing in for the pooled brain. The server serves
60
+ * `nexus-brain` as the canonical tier (`hidden: false`, no `alias_of`) and
61
+ * marks every other spelling — `aegis-brain` and the `-smart`/`-neo` tiers —
62
+ * as `hidden: true, alias_of: "nexus-brain"`. Prefer the canonical id so the
63
+ * request travels on the name the server owns; fall back to the alias, then to
64
+ * any tier whose `alias_of` names the brain, so a renamed or trimmed catalog
65
+ * still resolves to something selectable instead of silently emptying the
66
+ * dropdown (the previous fixed-id lookup returned [] if `aegis-brain` was ever
67
+ * retired, leaving the class with no model to choose).
68
+ *
69
+ * @param {Array<object>} models normalized or raw catalog entries.
70
+ * @returns {object|null}
71
+ */
72
+ function selectBrainEntry(models) {
73
+ const list = Array.isArray(models) ? models.filter(Boolean) : [];
74
+ return (
75
+ list.find((m) => NEXUS_BRAIN_IDS.includes(m.id) && !isHiddenEntry(m) && aliasOfEntry(m) === null)
76
+ || list.find((m) => NEXUS_BRAIN_IDS.includes(m.id))
77
+ || list.find((m) => NEXUS_BRAIN_IDS.includes(aliasOfEntry(m)))
78
+ || null
79
+ );
80
+ }
81
+
82
+ /**
83
+ * The Aegis-class catalog as a host must OFFER it: exactly one entry, the
84
+ * collapsed brain — never the raw provider list, and never the alias tiers.
85
+ *
86
+ * Offering this shape is not the same as accepting only this shape: the ids the
87
+ * server advertises still route (a pin on `deepseek` still runs), so callers
88
+ * keep the full catalog for validation and use this for what they show.
89
+ *
90
+ * Returns `[]` when the payload names no brain tier at all — which is the
91
+ * caller's signal that this is not a pooled-brain catalog (the BYOK listing is
92
+ * per-provider models and must be offered in full, not collapsed to nothing).
93
+ *
94
+ * @param {Array<object>} models the server's catalog (any shape).
95
+ * @returns {Array<object>} `[]` when the payload names no brain tier at all.
96
+ */
97
+ function filterAegisCatalog(models) {
98
+ const nexus = selectBrainEntry(models);
99
+ if (!nexus) return [];
100
+ // Drop the alias bookkeeping in BOTH spellings: this entry *is* the
101
+ // selection, so a renderer must never treat it as a hidden alias and filter
102
+ // it back out — which is exactly what happens if `aliasOf` survives here and
103
+ // the consumer re-runs its own "drop aliases" pass over the result.
104
+ const { hidden, alias_of, aliasOf, ...rest } = nexus;
105
+ return [{ ...rest, label: NEXUS_LABEL }];
106
+ }
107
+
108
+ module.exports = {
109
+ NEXUS_BRAIN_IDS,
110
+ NEXUS_LABEL,
111
+ selectBrainEntry,
112
+ filterAegisCatalog,
113
+ };
@@ -76,6 +76,34 @@ try {
76
76
  }
77
77
  }
78
78
 
79
+ /**
80
+ * The shared pooled-brain selection rule (`client/brain-catalog.js`), resolved
81
+ * the same two ways as every other shared module: repo-relative from a source
82
+ * checkout, and this app's own staged tree (`desktop/vendor/brain-catalog.js`,
83
+ * flattened by scripts/predist.mjs because a packaged app cannot reach outside
84
+ * its own directory). The CLI resolves the same file its own way, through
85
+ * `cli/src/sharedpaths.js`. Both hosts must agree on which entry stands for the
86
+ * pool, so there is deliberately no fallback implementation here — a silently
87
+ * divergent local copy is the exact bug this module removes. When neither
88
+ * layout has it, require() throws at load time naming the file, rather than the
89
+ * host quietly offering a different model list than its sibling.
90
+ */
91
+ function requireSharedBrain() {
92
+ const candidates = [
93
+ () => require('../../../client/brain-catalog.js'),
94
+ () => require('../../vendor/brain-catalog.js'),
95
+ ];
96
+ let last = null;
97
+ for (const load of candidates) {
98
+ try {
99
+ return load();
100
+ } catch (err) {
101
+ last = err;
102
+ }
103
+ }
104
+ throw last;
105
+ }
106
+
79
107
  /**
80
108
  * How long a turn waits for the working-tree lock before running anyway.
81
109
  *
@@ -254,38 +282,16 @@ function normalizeCatalog(models) {
254
282
  * The pool already auto-routes across whichever providers are live, so the
255
283
  * desktop dropdown offers exactly one entry for the "aegis" class: the
256
284
  * collapsed "Nexus" brain — never the raw provider list.
285
+ *
286
+ * The selection rule itself now lives in `client/brain-catalog.js`, shared with
287
+ * the CLI: this host and the terminal were offering the same account two
288
+ * different model lists (one collapsed entry vs. every distinct provider id),
289
+ * and two copies of the rule is precisely how that drift happened. Resolved the
290
+ * two ways this repo resolves every shared module — repo-relative in a
291
+ * checkout, and this app's staged vendor/ tree — with the selection itself
292
+ * unchanged.
257
293
  */
258
- const NEXUS_BRAIN_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
259
- const NEXUS_LABEL = 'Nexus';
260
-
261
- /**
262
- * Pick the one entry standing in for the pooled brain. The server serves
263
- * `nexus-brain` as the canonical tier (`hidden: false`, no `alias_of`) and
264
- * marks every other spelling — `aegis-brain` and the `-smart`/`-neo` tiers —
265
- * as `hidden: true, alias_of: "nexus-brain"`. Prefer the canonical id so the
266
- * request travels on the name the server owns; fall back to the alias, then to
267
- * any tier whose `alias_of` names the brain, so a renamed or trimmed catalog
268
- * still resolves to something selectable instead of silently emptying the
269
- * dropdown (the previous fixed-id lookup returned [] if `aegis-brain` was ever
270
- * retired, leaving the class with no model to choose).
271
- */
272
- function selectBrainEntry(models) {
273
- return (
274
- models.find((m) => NEXUS_BRAIN_IDS.includes(m.id) && !m.hidden && m.alias_of === undefined)
275
- || models.find((m) => NEXUS_BRAIN_IDS.includes(m.id))
276
- || models.find((m) => m.alias_of && NEXUS_BRAIN_IDS.includes(m.alias_of))
277
- || null
278
- );
279
- }
280
-
281
- function filterAegisCatalog(models) {
282
- const nexus = selectBrainEntry(models);
283
- if (!nexus) return [];
284
- // Drop the alias bookkeeping: this entry *is* the selection, so the renderer
285
- // must never treat it as a hidden alias and filter it back out.
286
- const { hidden, alias_of, ...rest } = nexus;
287
- return [{ ...rest, label: NEXUS_LABEL }];
288
- }
294
+ const { filterAegisCatalog } = requireSharedBrain();
289
295
 
290
296
  // ── Agent-loop helpers ──────────────────────────────────────────────────────
291
297