aegiscode 7.0.13 → 7.0.14

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": "7.0.13",
4
+ "version": "7.0.14",
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",
package/src/chatflow.js CHANGED
@@ -810,8 +810,20 @@ function transcriptLines(rows, view, ctx, now = Date.now(), cache = null) {
810
810
  const owners = [];
811
811
  for (const msg of rows) {
812
812
  const key = cache || null;
813
- const isGrower = msg.role === 'assistant' && msg.streaming;
814
- if (key && !isGrower) {
813
+ // Rows whose rendering depends on the CLOCK cannot be cached on their text.
814
+ // A streaming assistant row grows (`isGrower`), and a running tool row
815
+ // carries `${label} · ${secs}s` — its text is fixed while `now - start`
816
+ // climbs, so caching it froze the row at the second it first painted and a
817
+ // long-running tool read `· 1s` for as long as it ran. The same entry then
818
+ // survived the run → done collapse (resolveToolDone mutates the row in
819
+ // place and leaves `text` undefined, so the cache key still matched) and the
820
+ // finished row kept saying "Running 1 shell command… · 1s" for a command
821
+ // that had already returned. Neither row is cached; both are cheap to
822
+ // re-render, and the expensive rows (markdown answers) still are.
823
+ const isLive =
824
+ (msg.role === 'assistant' && msg.streaming) ||
825
+ (msg.role === 'tool' && msg.phase === 'run');
826
+ if (key && !isLive) {
815
827
  const hit = key.get(msg);
816
828
  // diffOpen is part of the cache key: a toggled edit block must re-render.
817
829
  if (hit && hit.text === msg.text && hit.cols === cols && hit.diffOpen === msg.diffOpen) {
package/src/commands.js CHANGED
@@ -3380,6 +3380,22 @@ const COMMANDS = [
3380
3380
  if (p && p.key_prefix && !key.startsWith(p.key_prefix)) {
3381
3381
  c.push({ role: 'note', text: `heads up: ${id} keys normally start with "${p.key_prefix}" — saved anyway.` });
3382
3382
  }
3383
+ // Saving a KEY with no ADDRESS is the one way to build a `custom` row that
3384
+ // looks configured and cannot be spent: the catalog descriptor pins no
3385
+ // base URL for that id, so nothing can be guessed, and the turn is
3386
+ // refused later with a 400 that never mentions what is missing. Refuse it
3387
+ // here instead — where the user is typing, and where the fix can be named.
3388
+ // If an endpoint is already saved, a re-key is legitimate and proceeds.
3389
+ if (id === 'custom' && !savedByokBaseURL(c, id)) {
3390
+ c.push({
3391
+ role: 'error',
3392
+ text:
3393
+ `the "custom" provider needs an endpoint as well as a key — a key alone dials nothing. ` +
3394
+ `Use: /model-add custom <https-base-url> ${key} <model-id> (saves endpoint, key and ` +
3395
+ `model together) — nothing was saved.`,
3396
+ });
3397
+ return true;
3398
+ }
3383
3399
  store.set(c.byokNamespace(id), { key });
3384
3400
 
3385
3401
  // MIRROR IT INTO ~/.aegiscode/.env — the file every host (this CLI, the
@@ -489,6 +489,47 @@ const TRANSIENT_STREAM_ERROR_PATTERN =
489
489
  const TRANSIENT_STREAM_RETRIES = 2;
490
490
  const TRANSIENT_STREAM_BASE_WAIT_MS = 500;
491
491
 
492
+ /**
493
+ * The sentence aegis1 puts in a mid-stream error frame when the UPSTREAM
494
+ * provider call it was relaying hit its own deadline. Deliberately kept out of
495
+ * TRANSIENT_STREAM_ERROR_PATTERN: a socket reset is worth re-issuing at once,
496
+ * but a provider timeout has already spent a full deadline, so the same retry
497
+ * would make a stuck upstream cost three of them before anything was said.
498
+ *
499
+ * It still has to be CLASSIFIED, not passed through raw. The frame arrives
500
+ * after the stream's own 200 OK, so `res.status` is 200 — the throw used to be
501
+ * stamped with that and reached the desktop host as `{ status: 200 }`, which
502
+ * reads as a success to every downstream branch (engine.js keys its recovery
503
+ * on `status === 402`/`400`; the renderer keys "waited too long" on status 0).
504
+ */
505
+ const SSE_UPSTREAM_TIMEOUT_PATTERN = /request timed out|timed out waiting|upstream timeout/i;
506
+
507
+ /**
508
+ * The message for a provider timeout, stating whose deadline expired.
509
+ *
510
+ * This used to read "the provider returned no answer within the 60s stream
511
+ * budget (raise AEGIS_SSE_IDLE_TIMEOUT_MS for a slower provider)". Measured
512
+ * live, that sentence was false in the one case it fired: the provider gave up
513
+ * in ~11-13s and aegis1 relayed it, so the client's own watchdog never fired at
514
+ * all — `sseError` is only ever set from a `json.error` frame, and our stall
515
+ * raises its own `stream stalled - …` error from `readWithIdleTimeout` instead.
516
+ * The advice pointed at an env var that provably cannot help, which is worse
517
+ * than saying nothing: a user follows it, restarts, and the turn still fails.
518
+ *
519
+ * So the message separates the two deadlines and names elapsed time, which is
520
+ * the fact that tells a reader which one it was without trusting the prose.
521
+ * `elapsedMs` is omitted when the caller has no measured start (the
522
+ * non-streaming path), rather than inventing one.
523
+ */
524
+ function upstreamTimeoutMessage(base, elapsedMs) {
525
+ const took = Number(elapsedMs) > 0 ? ` after ${(Number(elapsedMs) / 1000).toFixed(1)}s` : '';
526
+ return (
527
+ `${base} — the upstream provider gave up before answering${took}. ` +
528
+ "That is the provider's own deadline, not this client's stream budget, so " +
529
+ 'raising AEGIS_SSE_IDLE_TIMEOUT_MS cannot help'
530
+ );
531
+ }
532
+
492
533
  /**
493
534
  * .mcp.json / Electron pass config as "${VAR}" template refs. When the var is
494
535
  * unset, hosts have been observed to leave the template literally unexpanded
@@ -982,7 +1023,32 @@ function createClient(opts = {}) {
982
1023
  (data && (data.error?.message || data.error || data.message)) ||
983
1024
  `HTTP ${res.status}`;
984
1025
  const err = new Error(redact(typeof msg === 'string' ? msg : JSON.stringify(msg)));
985
- err.status = res.status;
1026
+ // The buffered twin of postStream's upstream-timeout classification.
1027
+ //
1028
+ // Aegis1 answers a NON-streaming request by draining the same generator
1029
+ // itself, so the provider's deadline arrives here as a plain 503 carrying
1030
+ // the same sentence a streaming caller gets as an error frame. Without
1031
+ // this the one failure had two shapes depending on wire form: the stream
1032
+ // path said `status 0 / code timeout` with an explanation, while the
1033
+ // buffered path said `status 503 / code undefined` and nothing else —
1034
+ // measured live, same provider, same 10s wall, ~10.8s either way. A host
1035
+ // gating on `code === 'timeout'` therefore saw it on one path only.
1036
+ //
1037
+ // Status becomes 0 for the same reason as the stream path: this is
1038
+ // "waited too long", which every downstream branch already reads as
1039
+ // status 0 + code, and a 5xx would instead be taken as a server fault.
1040
+ // The server's own number is preserved on `serverStatus`, because 5xx is
1041
+ // worth knowing even when it means the same thing to the caller.
1042
+ const upstreamTimeout =
1043
+ res.status >= 500 && res.status < 600 && SSE_UPSTREAM_TIMEOUT_PATTERN.test(err.message);
1044
+ if (upstreamTimeout) {
1045
+ err.serverStatus = res.status;
1046
+ err.status = 0;
1047
+ err.code = 'timeout';
1048
+ err.message = upstreamTimeoutMessage(err.message);
1049
+ } else {
1050
+ err.status = res.status;
1051
+ }
986
1052
  err.data = data;
987
1053
  throw err;
988
1054
  }
@@ -1262,6 +1328,29 @@ function createClient(opts = {}) {
1262
1328
  baseURL,
1263
1329
  } = {}) {
1264
1330
  const key = providerKey !== undefined ? providerKey : opts.providerKey;
1331
+ // `custom` is the one catalog provider whose address the server does NOT
1332
+ // know: every other id maps to a host aegis1 has baked in, and `custom`
1333
+ // travels as `base_url` on each request instead. So a custom call that
1334
+ // names no endpoint is not "a provider we can guess a default for" — there
1335
+ // is no default to guess, and aegis1 answers 400 (`_byok_custom_base_url`
1336
+ // refuses it). Refusing HERE turns that server-side 400 into a client-side
1337
+ // sentence naming the missing half, which is the difference between "custom
1338
+ // is broken" and "you saved a key but never saved the endpoint".
1339
+ //
1340
+ // Reachable without the card: `/byok-key custom <key>` saves a key alone,
1341
+ // and a hand-edited row can hold a key with no address. Guarded on the
1342
+ // value actually being absent (`!baseURL`), never on the provider alone, so
1343
+ // a correctly-saved custom row is untouched.
1344
+ if (provider === 'custom' && !baseURL) {
1345
+ const err = new Error(
1346
+ 'the "custom" provider dials the endpoint you name, and this call names none — ' +
1347
+ 'save the address first: /model-add custom <https-base-url> <api-key> <model-id>, ' +
1348
+ 'or the endpoint field in Settings › Provider (custom).'
1349
+ );
1350
+ err.status = 400;
1351
+ err.code = 'custom_endpoint_missing';
1352
+ throw err;
1353
+ }
1265
1354
  // Same rule as the pooled path above: omit `max_tokens` entirely when the
1266
1355
  // caller states none, rather than inventing a default. The server treats a
1267
1356
  // body max_tokens as a ceiling *over* its own ladder, so a defaulted 4096
@@ -1506,6 +1595,11 @@ function createClient(opts = {}) {
1506
1595
  // moves `lastPayloadAt` below.
1507
1596
  const idleMs = idleBudgetFor(res, idleTimeoutMs);
1508
1597
  let lastPayloadAt = Date.now();
1598
+ // When this response began, for the one place that needs to tell the two
1599
+ // deadlines apart: a provider timeout frame carries no duration, and the
1600
+ // elapsed time is what separates "the upstream gave up" (seconds, well
1601
+ // inside our budget) from "our own watchdog fired" (the full budget).
1602
+ const streamStartedAt = lastPayloadAt;
1509
1603
  let keepAlives = 0;
1510
1604
  async function readWithIdleTimeout() {
1511
1605
  let timer;
@@ -1684,8 +1778,39 @@ function createClient(opts = {}) {
1684
1778
  _transientStreamAttempt: transientStreamAttempt + 1,
1685
1779
  });
1686
1780
  }
1687
- const err = new Error(sseError);
1688
- err.status = res.status;
1781
+ // Deliberately NOT retried: this sentence is aegis1 relaying an upstream
1782
+ // abort ("Provider request timed out") as a mid-stream error frame with
1783
+ // the headers already 200 OK — the same frame shape as the reset above,
1784
+ // but the stall has already cost the caller a full provider deadline, and
1785
+ // re-issuing would make a stuck upstream cost three of them before the
1786
+ // host could say anything. One attempt, classified, and out.
1787
+ //
1788
+ // What must NOT happen is the shape this used to be thrown in: `res.status`
1789
+ // here is the SSE response's own 200 (the headers landed long before the
1790
+ // error frame did), so the rejection carried "success" as its status and
1791
+ // nothing downstream could classify it — the desktop host printed the raw
1792
+ // stack with `{ status: 200 }` for a turn that never produced a byte. A
1793
+ // timeout is stated in the shape every other "waited too long" on this
1794
+ // lane uses (status 0 + a code), which is what engine.js's `status === 402`
1795
+ // / `status === 400` branches already key off and what local.js translates
1796
+ // its own two clocks into — so "waited too long" stays one branch for
1797
+ // every class.
1798
+ //
1799
+ // Message: the budget is NOT named as the cause any more, because this
1800
+ // branch cannot be our own watchdog. `sseError` comes only from a
1801
+ // `json.error` frame the server sent; our watchdog raises `stream
1802
+ // stalled - …` out of readWithIdleTimeout and never reaches this code.
1803
+ // So every error here is the provider's deadline, already expired, and
1804
+ // the elapsed time says so as a fact rather than as prose — see
1805
+ // upstreamTimeoutMessage().
1806
+ const timedOut = SSE_UPSTREAM_TIMEOUT_PATTERN.test(sseError);
1807
+ const err = new Error(
1808
+ timedOut
1809
+ ? upstreamTimeoutMessage(sseError, Date.now() - streamStartedAt)
1810
+ : sseError
1811
+ );
1812
+ err.status = timedOut ? 0 : res.status;
1813
+ if (timedOut) err.code = 'timeout';
1689
1814
  throw err;
1690
1815
  }
1691
1816
 
@@ -40,14 +40,39 @@ function driveConnectUrl(apiBase) {
40
40
  }
41
41
 
42
42
  /**
43
- * One status check: is a Drive token on file for this account?
43
+ * One status check: is a Drive token on file for this account, and is the
44
+ * account tied to a Google identity at all?
44
45
  *
45
- * @param {{driveToken: () => Promise<{connected:boolean, email?:string}>}} aegis
46
+ * `googleLinked` comes from the server (`/api/drive/token`'s `google_linked`,
47
+ * derived from `users.google_id`) and is NOT the same question as "does this
48
+ * machine have an API key". Every install auto-provisions an anonymous device
49
+ * key, so a key always exists while the account behind it may never have
50
+ * touched Google. Connecting Drive in that state attaches the tokens to
51
+ * whatever Google account the browser happens to hold — a different account
52
+ * than the one this machine polls — and the poll just times out. Callers need
53
+ * this flag to refuse that ordering.
54
+ *
55
+ * Older servers answer `google_linked` not at all; a connected account is
56
+ * proof enough (only a Google round-trip can store those tokens), so a
57
+ * missing flag next to a live token reads as linked rather than as a
58
+ * regression that would disable the button for everyone.
59
+ *
60
+ * @param {{driveToken: () => Promise<{connected:boolean, email?:string, google_linked?:boolean}>}} aegis
46
61
  */
47
62
  async function driveStatus(aegis) {
48
63
  const data = await aegis.driveToken();
64
+ const connected = Boolean(data && data.connected);
65
+ const raw = data && data.google_linked;
66
+ // Did the server actually answer the question? A server that predates the
67
+ // field omits it entirely, and an account with no Drive token answers 404
68
+ // with no flag — both look exactly like an explicit `false` once collapsed
69
+ // to a boolean. Callers that must not block a real sign-in need to tell
70
+ // "not linked" apart from "nobody asked the server".
71
+ const known = typeof raw === 'boolean';
49
72
  return {
50
- connected: Boolean(data && data.connected),
73
+ connected,
74
+ googleLinked: connected || raw === true,
75
+ googleLinkedKnown: known || connected,
51
76
  email: (data && data.email) || null,
52
77
  };
53
78
  }
@@ -37,10 +37,14 @@ function escapeHtml(s) {
37
37
  }[c]));
38
38
  }
39
39
 
40
- function page({ ok, error, username }) {
40
+ function page({ ok, error, username, surface }) {
41
41
  const title = ok ? 'Signed in' : 'Sign-in failed';
42
+ // This page is shared by the CLI and the desktop, and only one of them is
43
+ // a terminal. The desktop passes `surface: 'app'`; the default keeps the
44
+ // CLI's existing wording.
45
+ const where = surface === 'app' ? 'the app' : 'the terminal';
42
46
  const body = ok
43
- ? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to the terminal.`
47
+ ? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to ${where}.`
44
48
  : `Sign-in failed: ${escapeHtml(error || 'no token was returned')}. You can close this tab and try again.`;
45
49
  return `<!doctype html><html><head><meta charset="utf-8"><title>${title} — AEGIS</title></head>` +
46
50
  `<body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;">` +
@@ -62,9 +66,13 @@ function buildAuthUrl(apiBase, callbackUrl) {
62
66
  * else (a browser pre-connect, `/favicon.ico`) gets a plain 404 and the
63
67
  * server keeps listening for the real one.
64
68
  *
69
+ * `surface` only changes the wording of the page the browser lands on after
70
+ * signing in ('terminal' for the CLI, 'app' for the desktop) — it changes
71
+ * nothing about the flow itself.
72
+ *
65
73
  * @returns {Promise<{url: string, wait: () => Promise<{apiKey:string, username:?string, memoryToken:?string}>}>}
66
74
  */
67
- async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000 } = {}) {
75
+ async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000, surface = 'terminal' } = {}) {
68
76
  if (!apiBase) throw new Error('startGoogleSignIn requires apiBase');
69
77
 
70
78
  let settled = false;
@@ -93,7 +101,7 @@ async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 *
93
101
  return;
94
102
  }
95
103
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
96
- res.end(page({ ok: Boolean(token), error, username }));
104
+ res.end(page({ ok: Boolean(token), error, username, surface }));
97
105
 
98
106
  if (settled) return;
99
107
  settled = true;
@@ -101,6 +101,36 @@ const ENDPOINTS = Object.freeze({
101
101
  headers: bearer,
102
102
  note: 'OpenAI-compatible',
103
103
  }),
104
+ // The remaining providers in aegis1's catalog that speak `openai_chat` and
105
+ // answer a standard OpenAI-shaped list on `<base_url>/models`.
106
+ //
107
+ // Probed live rather than assumed, because "OpenAI-compatible chat" does not
108
+ // imply "has a list endpoint": cerebras, fireworks and sakana answer 401/403
109
+ // without a key (the endpoint exists and is gated) and NVIDIA's list answers
110
+ // 200 unauthenticated with 84 rows, which is why it is the one endpoint here
111
+ // whose list is public. Ollama is deliberately absent: it is keyless and
112
+ // local, so it has nothing to put in the API key this module requires, and
113
+ // `canDiscover` would be reporting a capability the caller cannot use.
114
+ cerebras: Object.freeze({
115
+ url: 'https://api.cerebras.ai/v1/models',
116
+ headers: bearer,
117
+ note: 'OpenAI-compatible under /v1',
118
+ }),
119
+ fireworks: Object.freeze({
120
+ url: 'https://api.fireworks.ai/inference/v1/models',
121
+ headers: bearer,
122
+ note: 'OpenAI-compatible under /inference/v1; ids are "accounts/fireworks/models/<id>"',
123
+ }),
124
+ nvidia_nim: Object.freeze({
125
+ url: 'https://integrate.api.nvidia.com/v1/models',
126
+ headers: bearer,
127
+ note: 'OpenAI-compatible; ids are "<vendor>/<model>"',
128
+ }),
129
+ sakana: Object.freeze({
130
+ url: 'https://api.sakana.ai/v1/models',
131
+ headers: bearer,
132
+ note: 'OpenAI-compatible under /v1',
133
+ }),
104
134
  });
105
135
 
106
136
  /** Other spellings a user types for a provider this module knows. */
@@ -112,6 +142,19 @@ const ALIASES = Object.freeze({
112
142
  'googleai': 'gemini',
113
143
  'open-ai': 'openai',
114
144
  'deep-seek': 'deepseek',
145
+ // Two catalog rows that are the SAME VENDOR under a second provider id: both
146
+ // `openai-gpt4o-mini` and `anthropic-haiku` share their sibling's credential
147
+ // and base_url, and differ only in the default model they pin (see
148
+ // `client/byok-catalog.js`, which notes the two OpenAI ids "share one
149
+ // credential and one model"). Discovery asks a vendor, so both spellings must
150
+ // reach the one list its key can already answer — otherwise a user holding a
151
+ // key filed under the `-haiku` / `-gpt4o-mini` row is told this client has no
152
+ // endpoint for their provider while the identical key under the sibling row
153
+ // is accepted. `custom` and `ollama` are deliberately NOT aliased: the first
154
+ // has no fixed base_url (it is supplied per request), and the second is
155
+ // keyless, so neither has a vendor list this module could ask.
156
+ 'openai-gpt4o-mini': 'openai',
157
+ 'anthropic-haiku': 'anthropic',
115
158
  });
116
159
 
117
160
  /**
@@ -745,6 +745,7 @@ const { offerableCatalog } = requireSharedBrain();
745
745
  const { withByokAdditions } = requireSharedByokCatalog();
746
746
  const {
747
747
  withUserModels,
748
+ unmatchedUserProviders,
748
749
  load: loadUserModels,
749
750
  addUserModel,
750
751
  removeUserModel,
@@ -1671,6 +1672,16 @@ function createLocalEngine({
1671
1672
  // it via `fee.require_balance` below.
1672
1673
  let providers = [];
1673
1674
  let fee = null;
1675
+ // Did the CATALOG itself fail to arrive, as opposed to arriving empty?
1676
+ // The two are different states and the picker must not confuse them: a
1677
+ // 5xx / offline relay used to fall into the bare `catch` below and hand
1678
+ // back `providers: []`, which reads on screen exactly like an account
1679
+ // with nothing configured — while the user's provider row and their
1680
+ // `models.json` declaration sat intact on disk. Reported instead, the
1681
+ // same way the 'local' branch reports `listed: false` for a tag list
1682
+ // that did not arrive.
1683
+ let providersFailed = false;
1684
+ let providersError = null;
1674
1685
  try {
1675
1686
  const data = await aegis.byokProviders();
1676
1687
  // The server's catalog, plus the ids it does not name but the vendor
@@ -1688,8 +1699,16 @@ function createLocalEngine({
1688
1699
  // Absent until the server publishes one, and the UI must then say
1689
1700
  // nothing rather than show a guess.
1690
1701
  fee = (data && data.fee) || null;
1691
- } catch {
1702
+ } catch (err) {
1703
+ // Keep the empty list (nothing to offer) but SAY why, so the renderer
1704
+ // can distinguish "catalog unreachable" from "catalog said none". The
1705
+ // message is carried rather than a boolean alone because the two cases
1706
+ // need different copy: offline wants a retry, a server error wants the
1707
+ // status. `err.message` is the transport's own text, already shaped
1708
+ // elsewhere in this file.
1692
1709
  providers = [];
1710
+ providersFailed = true;
1711
+ providersError = (err && err.message) || String(err);
1693
1712
  }
1694
1713
  const models = [];
1695
1714
  for (const p of providers) {
@@ -1725,6 +1744,18 @@ function createLocalEngine({
1725
1744
  needsProviderKey: models.length > 0 && !models.some((m) => m.configured),
1726
1745
  needsAegisKey: !aegis.apiKey,
1727
1746
  fee,
1747
+ // True only when the catalog did not arrive — never merely because it
1748
+ // arrived with no providers. `withUserModels` never fabricates a
1749
+ // provider, so this list is the same either side of the fold above.
1750
+ providersFailed,
1751
+ providersError,
1752
+ // Declarations in `models.json` naming a provider the catalog does not
1753
+ // list — a typo, or a provider renamed/dropped server-side. `withUserModels`
1754
+ // deliberately does NOT invent a row for them (it would 401 on its first
1755
+ // turn), but silence is the other wrong answer: the model stays in the
1756
+ // file and the user is entitled to know the picker cannot show it.
1757
+ // Carried as the ids alone; the renderer names them.
1758
+ unmatchedProviders: unmatchedUserProviders(providers),
1728
1759
  };
1729
1760
  }
1730
1761
  if (cls === 'local') {
@@ -2444,6 +2475,32 @@ function createLocalEngine({
2444
2475
  const refusal = localT.remoteRefusal(cfg.baseURL || localT.DEFAULT_BASE);
2445
2476
  if (refusal) throw refusal;
2446
2477
  }
2478
+ // `custom` is the mirror of `local`: both are rows whose payload is an
2479
+ // ADDRESS rather than a credential, and both are unusable without it.
2480
+ // They differ in what absence MEANS. A blank `local` row falls back to
2481
+ // DEFAULT_BASE (the stock Ollama port) because there is exactly one
2482
+ // sensible address to guess. A blank `custom` row has no default at all —
2483
+ // the catalog descriptor pins none, so the server refuses the call with a
2484
+ // bare 400 that says nothing about which half of the setup is missing.
2485
+ //
2486
+ // Caught here, before any byte goes out, so the message can name the
2487
+ // command that fixes it. Reachable in practice: `/byok-key custom <key>`
2488
+ // stores a key with no address, and the CLI explicitly trusts an
2489
+ // unreachable catalog rather than refusing the id — so a user who typed
2490
+ // the key first and the endpoint never has a row that looks configured.
2491
+ // Keyed on the provider, not the class: every other byok provider's host
2492
+ // is a server-side constant and needs no address from us.
2493
+ if (cls === 'byok' && byokParts.provider === 'custom' && !(cfg.baseURL || '').trim()) {
2494
+ const err = new Error(
2495
+ 'No endpoint saved for the "custom" provider — its key is on this machine but the address ' +
2496
+ 'it dials is not, and no default exists for a vendor AEGIS does not know. Fix: ' +
2497
+ '/model-add custom <https-base-url> <api-key> <model-id> (writes both halves), or the ' +
2498
+ 'endpoint field in Settings › Provider (custom).'
2499
+ );
2500
+ err.status = 400;
2501
+ err.code = 'custom_endpoint_missing';
2502
+ throw err;
2503
+ }
2447
2504
  const base = {
2448
2505
  cls, model, mode: payload && payload.mode, maxTokens, statedMaxTokens, autonomous, sessionId, signal, onDelta, cfg, apiKey, toolChoice,
2449
2506
  // The turn's working directory, computed above as `turnCwd` — `dispatch`
@@ -3024,6 +3081,22 @@ function createLocalEngine({
3024
3081
  });
3025
3082
  }
3026
3083
  }
3084
+ } catch (e) {
3085
+ // Stamp the stop at the one place it is known for certain.
3086
+ //
3087
+ // `cancel(sessionId)` aborts THIS turn's controller, and the in-flight
3088
+ // transport unwinds as a rejection. The host has to tell that rejection
3089
+ // apart from a genuine provider/transport failure before it can stop
3090
+ // printing Ctrl-X as an application crash — and it used to guess from the
3091
+ // message text, which is exactly how a real failure ("connection aborted
3092
+ // by peer", "upstream aborted the connection") gets relabelled as a
3093
+ // deliberate stop and leaves the user with a silently empty answer. The
3094
+ // message is not evidence. This is: the signal reads aborted only because
3095
+ // the user asked for it, so it cannot be confused with anything upstream
3096
+ // did. Attached to the error object itself so it survives any rethrow,
3097
+ // and read by `isAbortShapedError` in desktop/main.js.
3098
+ if (signal.aborted && e && typeof e === 'object') e.aegisCancelled = true;
3099
+ throw e;
3027
3100
  } finally {
3028
3101
  if (shell) shell.dispose();
3029
3102
  controllers.delete(sessionId);
@@ -203,9 +203,15 @@ function byokFeeLine(fee) {
203
203
  // default-off gate after it. Joined with ' — ' only when there IS a second
204
204
  // clause: a sentence-ending dash with nothing after it ("…provider's bill —.")
205
205
  // is what the first live run of this line actually printed.
206
+ //
207
+ // This rate is the deployment's published RATE, not a quote for the reader
208
+ // specifically — an Unlimited subscriber is waived from this fee entirely
209
+ // (billing_service.is_unlimited on aegis1), so the number above is what a
210
+ // Free-tier BYOK caller pays, not what everyone pays.
206
211
  const price = `Bring your own key: relayed through AEGIS, handled at `
207
212
  + `${ratePerMillion(inRate)} in / ${ratePerMillion(outRate)} out, `
208
- + `on top of your provider's bill`;
213
+ + `on top of your provider's bill — no fee at all on Unlimited, `
214
+ + `and no fee at all during the free 1-month Unlimited trial`;
209
215
  let clause = '';
210
216
  if (f.require_account === true) {
211
217
  clause = 'and needs an AEGIS account key (X-AEGIS-Key) for the fee to be billed';