aegiscode 7.0.8 → 7.0.10

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/src/commands.js CHANGED
@@ -531,6 +531,63 @@ async function offeredModelIds(c, provider, key) {
531
531
  return res && res.ok && Array.isArray(res.ids) && res.ids.length ? res.ids : undefined;
532
532
  }
533
533
 
534
+ /**
535
+ * One argument string, tokenized with the SAME quote rule the app's own parser
536
+ * uses (`app.js` tokenize): a quoted run is one token and the quotes are not
537
+ * part of it.
538
+ *
539
+ * `_rest` is the raw remainder of the line (app.js parseArgs keeps it
540
+ * verbatim), so the only unambiguous way to type a base URL — `/model-add
541
+ * custom "https://my-vllm.example/v1" sk-… llama-3-70b` — arrives here still
542
+ * wrapped in its quotes. Splitting on whitespace alone stores the quote
543
+ * characters as part of the URL: the row then looks saved while every call on
544
+ * it is refused upstream, which is the silent no-op this whole command exists
545
+ * to avoid. The app's tokenizer is not reachable from here (it is a closure in
546
+ * app.js), so the rule is restated once, beside the only command that needs it.
547
+ */
548
+ function splitCommandWords(rest) {
549
+ const out = [];
550
+ let cur = '';
551
+ let quote = null;
552
+ let has = false;
553
+ for (const ch of String(rest == null ? '' : rest)) {
554
+ if (quote) {
555
+ if (ch === quote) quote = null;
556
+ else cur += ch;
557
+ continue;
558
+ }
559
+ if (ch === '"' || ch === "'") { quote = ch; has = true; continue; }
560
+ if (/\s/.test(ch)) {
561
+ if (cur || has) { out.push(cur); cur = ''; has = false; }
562
+ continue;
563
+ }
564
+ cur += ch;
565
+ has = true;
566
+ }
567
+ if (cur || has) out.push(cur);
568
+ return out;
569
+ }
570
+
571
+ /**
572
+ * The base URL this machine already holds for a provider, or ''.
573
+ *
574
+ * Only `custom` needs it, and only to answer one question: `/model-add custom
575
+ * <word>` with a single leftover word is ambiguous on a machine with no
576
+ * endpoint configured — the word could be the base URL (key and model still to
577
+ * come) or a model id for an endpoint nobody has named — and unambiguous once
578
+ * one IS configured, because then the word can be nothing but a model id.
579
+ */
580
+ function savedByokBaseURL(c, provider) {
581
+ try {
582
+ const store = c && c.settings && c.settings();
583
+ if (!store || typeof store.get !== 'function' || typeof c.byokNamespace !== 'function') return '';
584
+ const row = store.get(c.byokNamespace(provider)) || {};
585
+ return String(row.baseURL || '').trim();
586
+ } catch {
587
+ return '';
588
+ }
589
+ }
590
+
534
591
  /**
535
592
  * Declare ids into the store, skipping the ones already there. Returns the
536
593
  * count added, plus what was skipped and WHY, so the caller can say
@@ -3000,6 +3057,7 @@ const COMMANDS = [
3000
3057
  return {
3001
3058
  note: `${p.id} already has a key${p.masked ? ` (${p.masked})` : ''} — pasting a new one replaces it.`,
3002
3059
  prompt: `new ${p.label || p.id} key: `,
3060
+ provider: p.id,
3003
3061
  };
3004
3062
  }
3005
3063
  const bits = [`${p.label || p.id}`];
@@ -3009,7 +3067,7 @@ const COMMANDS = [
3009
3067
  if (models.length) bits.push(`unlocks ${models.join(', ')}`);
3010
3068
  if (p.key_prefix) bits.push(`key starts with ${p.key_prefix}`);
3011
3069
  if (p.key_url) bits.push(`create one at ${p.key_url}`);
3012
- return { note: bits.join(' · '), prompt: `${p.id} key: ` };
3070
+ return { note: bits.join(' · '), prompt: `${p.id} key: `, provider: p.id };
3013
3071
  },
3014
3072
  },
3015
3073
  {
@@ -3032,30 +3090,12 @@ const COMMANDS = [
3032
3090
  // at all falls back to the two static rows below.
3033
3091
  const classes = await Promise.resolve(c.classes ? c.classes() : []).catch(() => []);
3034
3092
  const rows = classes.length ? classes : [{ class: 'aegis' }, { class: 'byok' }];
3035
- const lines = [
3036
- [span(C.gold + BOLD, 'Class'), span(BOLD_OFF, ' — which route the next turn takes')],
3037
- [span(C.gray, '─'.repeat(52))],
3038
- ];
3039
- for (const k of rows) {
3040
- const id = k.class;
3041
- const on = id === cur;
3042
- // The distinction that matters to a user: who pays, and with which
3043
- // credential. Stated per class rather than in a footnote.
3044
- const note =
3045
- id === 'byok'
3046
- ? k.configured
3047
- ? 'your key, relayed by AEGIS — billed a handling fee'
3048
- : 'needs a provider key: /byok-key <provider>'
3049
- : 'the pool — your AEGIS account key pays for it';
3050
- lines.push([
3051
- span(on ? C.green : C.gray, ` ${on ? '●' : '○'} ${String(id).padEnd(6)}`),
3052
- span(on ? C.green : C.gray, label(id)),
3053
- span(C.gray, ` ${note}`),
3054
- ]);
3055
- }
3056
- lines.push('', [span(C.gray, ' switch with /class byok or /class aegis')]);
3057
- panel(c, lines);
3058
- c.render();
3093
+ const sel = rows.findIndex((k) => k.class === cur);
3094
+ // An interactive picker, not a static panel — the same tab/arrow/enter
3095
+ // overlay machinery /model already uses (chatflow.js handleOverlayKey),
3096
+ // so a class is switched by moving the highlight and hitting enter
3097
+ // rather than retyping its name after reading it off this list.
3098
+ c.openOverlay({ type: 'class', items: rows, sel: sel < 0 ? 0 : sel, current: cur });
3059
3099
  return true;
3060
3100
  }
3061
3101
  const res = c.switchClass(want);
@@ -3106,45 +3146,33 @@ const COMMANDS = [
3106
3146
  },
3107
3147
  {
3108
3148
  name: 'models', aliases: ['model-list'], hint: '', category: 'model',
3109
- desc: 'List the model ids you can pin with /model, for the class you are on',
3149
+ desc: 'Pick a model to pin, for the class you are on — opens the same picker as /model',
3110
3150
  handler: async (c) => {
3111
3151
  const cls = (c.ctx && c.ctx.modelClass) || 'aegis';
3112
3152
  const models = (await c.listModelsFor(cls)) || [];
3113
- const lines = [
3114
- [span(C.gold + BOLD, 'Models'), span(BOLD_OFF, ` — ${c.classLabel ? c.classLabel(cls) : cls}`)],
3115
- [span(C.gray, '─'.repeat(52))],
3116
- ];
3117
3153
  if (!models.length) {
3118
- lines.push('', [
3119
- span(
3120
- C.gray,
3121
- cls === 'byok'
3122
- ? ' nothing to relay yet — save a provider key with /byok-key <provider>'
3123
- : ' no models advertised — check the account with /status, then retry'
3124
- ),
3125
- ]);
3126
- } else {
3127
- const pinned = c.ctx && c.ctx.model;
3128
- for (const m of models) {
3129
- const on = pinned === m.id;
3130
- // A row from the OTHER class rides on this list on purpose — the
3131
- // pooled Nexus row is what makes the byok list able to show a way
3132
- // back to the pooled lane (app.js classScopedModels). It is not
3133
- // pinnable here, so it says which class it runs on instead of
3134
- // looking like a byok id that would 400 at the relay.
3135
- const other = m.cls && m.cls !== cls;
3136
- lines.push([
3137
- span(on ? C.green : C.gray, ` ${on ? '●' : '○'} `),
3138
- span(on ? C.green : C.gray, String(m.id).padEnd(30)),
3139
- span(C.gray, other
3140
- ? `${m.note || m.label || ''} · pooled lane — /class ${m.cls}`
3141
- : m.note || m.label || ''),
3142
- ]);
3143
- }
3144
- lines.push('', [span(C.gray, ' pin one with /model <id> — /model alone opens the picker')]);
3154
+ note(c, cls === 'byok'
3155
+ ? 'nothing to relay yet — save a provider key with /byok-key <provider>'
3156
+ : 'no models advertised — check the account with /status, then retry');
3157
+ c.render();
3158
+ return true;
3145
3159
  }
3146
- panel(c, lines);
3147
- c.render();
3160
+ const pinned = c.ctx && c.ctx.model;
3161
+ // A row from the OTHER class rides on this list on purpose — the pooled
3162
+ // Nexus row is what makes the byok list able to show a way back to the
3163
+ // pooled lane (app.js classScopedModels). It is not a row of THIS
3164
+ // class's own ids, so its note says which class it actually runs on
3165
+ // instead of looking like a byok id that would 400 at the relay.
3166
+ const items = models.map((m) => (m.cls && m.cls !== cls
3167
+ ? { ...m, note: `${m.note || m.label || ''} · pooled lane — /class ${m.cls}` }
3168
+ : m));
3169
+ const sel = items.findIndex((m) => m.id === pinned);
3170
+ // Same overlay /model opens (tab/arrow to move, enter to pin — see
3171
+ // chatflow.js handleOverlayKey), just scoped to this class's own rows
3172
+ // rather than /model's merged cross-class catalog. Picking the other
3173
+ // class's row switches class first, the same cross-class pin
3174
+ // applyModelRow already does for /model's own rows.
3175
+ c.openOverlay({ type: 'model', items, sel: sel < 0 ? 0 : sel, current: pinned, cls });
3148
3176
  return true;
3149
3177
  },
3150
3178
  },
@@ -3172,6 +3200,24 @@ const COMMANDS = [
3172
3200
  c.push({ role: 'error', text: `"${typed}" matches ${match.ambiguous.join(', ')} — retype the exact id.` });
3173
3201
  return true;
3174
3202
  }
3203
+ // A key written under a provider the relay does not serve is unusable and
3204
+ // invisible: the catalog never lists the row it created, so the user sees
3205
+ // "saved" and then no models, with nothing naming the typo. `byok-set`
3206
+ // already refuses this; the command it redirects users TO must refuse it
3207
+ // too, or the redirect trades one silent failure for another.
3208
+ //
3209
+ // Only refused when the catalog actually answered. `byokCatalog` returns
3210
+ // null on an unreachable server, and refusing on null would turn a
3211
+ // network blip into "unknown provider" — a wrong reason for a right-looking
3212
+ // stop. With no catalog the typed id is trusted, as before.
3213
+ if (providers && !match?.provider) {
3214
+ const ids = providers.map((x) => x.id).join(', ');
3215
+ c.push({
3216
+ role: 'error',
3217
+ text: `unknown provider "${typed}". Known ids: ${ids} — nothing was saved.`,
3218
+ });
3219
+ return true;
3220
+ }
3175
3221
  const p = match && match.provider;
3176
3222
  const id = (p && p.id) || typed;
3177
3223
  // A second token is the scriptable path (`/byok-key openai sk-…`); with
@@ -3240,19 +3286,33 @@ const COMMANDS = [
3240
3286
  // the next refresh and the window shows it on ITS next refresh. The file is
3241
3287
  // printed on success, because a hand-edit is the bulk path and a store the
3242
3288
  // user cannot find is a store they will not use.
3243
- name: 'model-add', aliases: ['add-model'], args: ['provider'], hint: '<provider> [model-id|*]',
3289
+ name: 'model-add', aliases: ['add-model'], args: ['provider'],
3290
+ hint: '<provider> [api-key] [model-id|*] (custom: <base-url> <api-key> [model-id|*])',
3244
3291
  category: 'model',
3245
- desc: 'Offer a model id the AEGIS catalog does not name (asks the vendor when it can)',
3292
+ desc: 'Save a provider key and offer a model id in one step (asks the vendor when it can)',
3246
3293
  handler: async (c, a) => {
3247
3294
  const args = a || {};
3248
3295
  const typed = String(args.provider || '').trim();
3249
3296
  if (!typed) {
3250
- c.push({ role: 'error', text: 'Usage: /model-add <provider> <model-id> — /byok lists the providers.' });
3297
+ c.push({
3298
+ role: 'error',
3299
+ text: 'Usage: /model-add <provider> [api-key] <model-id> — /byok lists the providers. '
3300
+ + 'A vendor this catalog does not name yet: /model-add custom <https-base-url> <api-key> <model-id>. '
3301
+ + 'Example: /model-add deepseek sk-xxxxxxxx deepseek-v4.3-preview',
3302
+ });
3251
3303
  return true;
3252
3304
  }
3253
3305
  const rest = String(args._rest || '').trim();
3254
- const sp = rest.indexOf(' ');
3255
- let model = sp === -1 ? '' : rest.slice(sp + 1).trim();
3306
+ // Quote-aware, because the one word on this line that MAY need quoting is
3307
+ // the base URL — see splitCommandWords.
3308
+ const words = splitCommandWords(rest);
3309
+ // `words[0]` is the provider token itself, echoed into `_rest` the same
3310
+ // way `/byok-key` reads it — everything after it is ours to read. A
3311
+ // `_rest` without it (a caller that passes only the trailing words) is
3312
+ // tolerated rather than misread as the provider being the model id.
3313
+ let extra = words.length && words[0].toLowerCase() === typed.toLowerCase()
3314
+ ? words.slice(1)
3315
+ : words;
3256
3316
  // Resolve the provider against the relay's catalog first. A slug the
3257
3317
  // server does not list can never be attached to a key, so storing it
3258
3318
  // would produce a declaration that is invisible in every picker — the
@@ -3273,6 +3333,95 @@ const COMMANDS = [
3273
3333
  return true;
3274
3334
  }
3275
3335
  const id = (match && match.provider && match.provider.id) || typed.toLowerCase();
3336
+ // ── fold the key-save step in, so one command does both ──────────────
3337
+ //
3338
+ // Before this, a never-configured provider needed /byok-key THEN
3339
+ // /model-add — two commands for one outcome the user has in mind as
3340
+ // one. Two extra words can only mean key-then-model (the one-word shape
3341
+ // just below is already the model-id-alone case this command always
3342
+ // had, and guessing "key or model id" from a single token is the
3343
+ // ambiguity this rule avoids rather than resolves): `/model-add
3344
+ // deepseek sk-… deepseek-v4.3-preview` saves the key and declares the
3345
+ // model in the same breath, and shows up in the picker right after —
3346
+ // no separate /byok-key round trip.
3347
+ //
3348
+ // "custom" (a vendor this catalog does not name, or a self-hosted
3349
+ // OpenAI-compatible endpoint) reads one word EARLIER than every other
3350
+ // provider: the base URL aegis1 has no constant for and must be told
3351
+ // per call (`_byok_custom_base_url` there validates it — https, no
3352
+ // loopback/private/link-local target). It gets its own branch rather
3353
+ // than folding into the generic rule below, because with the base URL
3354
+ // in play a lone leftover word is still ambiguous between "no model"
3355
+ // and "no key" in a way the generic one-word-is-the-model-id rule
3356
+ // cannot resolve.
3357
+ let typedBaseURL = '';
3358
+ let typedKey = '';
3359
+ if (id === 'custom') {
3360
+ // ONE leftover word for `custom` is genuinely ambiguous, so it is
3361
+ // refused rather than guessed: with no endpoint on this machine the
3362
+ // word could be the base URL (key and model still to come) or a model
3363
+ // id for an endpoint nobody has named — and the guess that writes a
3364
+ // model row against no endpoint is a row that cannot be called. Once an
3365
+ // endpoint IS saved the ambiguity is gone, because a second endpoint
3366
+ // needs its key with it (the two-word branch below), so a lone word can
3367
+ // only be a model id. Named, not silently dropped.
3368
+ if (extra.length === 1 && !savedByokBaseURL(c, id)) {
3369
+ c.push({
3370
+ role: 'error',
3371
+ text: 'one word cannot say whether it is the URL or the model id — nothing was saved. '
3372
+ + 'Type the endpoint first: /model-add custom <https-base-url> <api-key> [model-id]',
3373
+ });
3374
+ return true;
3375
+ }
3376
+ if (extra.length >= 2) {
3377
+ typedBaseURL = extra.shift();
3378
+ typedKey = extra.shift();
3379
+ }
3380
+ } else if (extra.length >= 2) {
3381
+ typedKey = extra.shift();
3382
+ }
3383
+ let model = extra.join(' ').trim();
3384
+ if (typedKey) {
3385
+ const keyStore = c.settings && c.settings();
3386
+ if (!keyStore || typeof keyStore.set !== 'function') {
3387
+ c.push({ role: 'error', text: 'this client has no provider-key store.' });
3388
+ return true;
3389
+ }
3390
+ const p = match && match.provider;
3391
+ if (p && p.key_prefix && !typedKey.startsWith(p.key_prefix)) {
3392
+ c.push({ role: 'note', text: `heads up: ${id} keys normally start with "${p.key_prefix}" — saved anyway.` });
3393
+ }
3394
+ if (typedBaseURL && !/^https:\/\//i.test(typedBaseURL)) {
3395
+ c.push({ role: 'note', text: `heads up: aegis1 only dials an https:// base_url — saved anyway, but calls on it will be refused.` });
3396
+ }
3397
+ keyStore.set(c.byokNamespace(id), { key: typedKey, ...(typedBaseURL ? { baseURL: typedBaseURL } : {}) });
3398
+ // Mirror it into ~/.aegiscode/.env too — the same file the model picker
3399
+ // writes (models.js storeModelKey) and byokKeyForProvider() already
3400
+ // falls back to reading. Without this a key saved here was invisible to
3401
+ // anything that only reads process.env/.env (a shell, the other host
3402
+ // before its settings store syncs), even though the two files name the
3403
+ // same provider through the identical envVarFor() mapping. Best-effort:
3404
+ // the settings-store save above is the row of record, so a failure here
3405
+ // (e.g. an unwritable .env) is reported but never undoes it.
3406
+ try {
3407
+ const { envVarFor, setEnvValue } = require(resolveShared(path.join('client', 'env-file.js')));
3408
+ const envName = envVarFor(id);
3409
+ if (envName) {
3410
+ const res = setEnvValue(envName, typedKey);
3411
+ if (!res.ok) {
3412
+ c.push({ role: 'note', text: `heads up: could not mirror the key into ~/.aegiscode/.env (${res.error}).` });
3413
+ }
3414
+ }
3415
+ } catch {
3416
+ /* the settings-store save is the row of record; this mirror is best-effort */
3417
+ }
3418
+ c.push({
3419
+ role: 'done',
3420
+ text: typedBaseURL
3421
+ ? `saved a ${id} key and base URL (${typedBaseURL}) on this machine.`
3422
+ : `saved a ${id} key on this machine.`,
3423
+ });
3424
+ }
3276
3425
  // ── what the vendor says, before we ask the user to remember it ──────
3277
3426
  //
3278
3427
  // The whole cost of this feature used to be "know the vendor's model id",
@@ -3336,8 +3485,13 @@ const COMMANDS = [
3336
3485
  // A bare number picks the row it is listed under. Only an in-range
3337
3486
  // integer is read that way, so an id that happens to start with a digit
3338
3487
  // is still stored verbatim unless it is exactly a listed position.
3339
- const n = /^\d+$/.test(typedId) ? Number(typedId) : 0;
3340
- model = n >= 1 && n <= offered.length ? offered[n - 1] : typedId;
3488
+ // `offered` is undefined whenever the vendor could not be asked (no
3489
+ // key, no endpoint, no network) — reading `.length` off it here threw a
3490
+ // TypeError out of the handler, which reads to the user as the command
3491
+ // crashing rather than as the id being stored, so the position rule is
3492
+ // applied only when there is a list to be a position IN.
3493
+ const n = offered && /^\d+$/.test(typedId) ? Number(typedId) : 0;
3494
+ model = offered && n >= 1 && n <= offered.length ? offered[n - 1] : typedId;
3341
3495
  }
3342
3496
  if (!model) {
3343
3497
  c.push({ role: 'note', text: 'nothing saved.' });
package/src/engine.js CHANGED
@@ -116,10 +116,36 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
116
116
  }
117
117
 
118
118
  function chat(payload, onDelta) {
119
- const cls = currentClass();
120
119
  // `class` is stamped here rather than sent by every caller, so the class a
121
120
  // turn runs on has exactly one source of truth (the live session state) and
122
121
  // a caller cannot accidentally pin a stale one.
122
+ //
123
+ // …WHEN THERE IS A LIVE SESSION TO STAMP FROM. `getClass` is the
124
+ // interactive surface's `/class` state; a payload that NAMES a class is
125
+ // stating its own, and the only such caller is the autonomous queue, whose
126
+ // tasks each carry the class they were queued on (autonomous.js runTask).
127
+ // The drain builds this engine through buildEngine() below, which supplies
128
+ // no `getClass` at all — deliberately, because a drain has no interactive
129
+ // session to read.
130
+ //
131
+ // Reading `currentClass()` unconditionally was therefore not a clamp but an
132
+ // OVERWRITE: every queued task went out as `class: 'aegis'` regardless of
133
+ // what it was queued as, so a byok or local task (feature from 9eeef09) was
134
+ // billed to the pooled route it did not ask for, on a model id the pool
135
+ // does not serve. Verified against this tree: a payload `{class:'pro'}` was
136
+ // observed arriving at the shared engine as `{class:'aegis'}`.
137
+ //
138
+ // Precedence is unchanged for the interactive path, which always supplies
139
+ // `getClass`: a live class wins over anything a payload carries, so a stale
140
+ // value still cannot pin a turn. Only an ABSENT live class lets the
141
+ // payload's own class through, and then only one this host can run.
142
+ const live = typeof getClass === 'function' ? getClass() : null;
143
+ const stated = payload && payload.class;
144
+ const cls = HOST_CLASSES.includes(live)
145
+ ? live
146
+ : HOST_CLASSES.includes(stated)
147
+ ? stated
148
+ : DEFAULT_CLASS;
123
149
  return local.chat({ ...payload, class: cls }, onDelta);
124
150
  }
125
151
 
package/src/limits.js CHANGED
@@ -101,7 +101,7 @@ const UNITS = Object.freeze([
101
101
  * The masked digest of the sealed set. Rewritten ONLY by
102
102
  * `node tools/provenance.mjs seal --write`, never by hand.
103
103
  */
104
- const SEALED = '400c9a8d7deb897b43ba3d993b4fff04d8d11e9426fef06141898b320ecff365';
104
+ const SEALED = '32ce3ebb806e116aefc6be2e3a8e6fbc04503cedf85e4460c78baf761c3b92c6';
105
105
 
106
106
  /** Subcommands that a build failing this check does not get to run. */
107
107
  const PRIVILEGED = Object.freeze(['gate', 'provenance', 'mcp']);
package/src/overlays.js CHANGED
@@ -285,6 +285,49 @@ function renderEffortPicker(sel = 0, width = 80, current = null, levels = EFFORT
285
285
  return fit(lines, width);
286
286
  }
287
287
 
288
+ // ── Class picker overlay (/class) ────────────────────────────────────────────
289
+
290
+ /**
291
+ * @param {Array} classes entries ({class, configured?})
292
+ * @param {number} sel selected index
293
+ * @param {number} width
294
+ * @param {string|null} current the live class id
295
+ * @param {(cls: string) => string} [classLabel] the caller's label table, so
296
+ * the class is named one way in every surface rather than re-spelled here.
297
+ */
298
+ function renderClassPicker(classes, sel = 0, width = 80, current = null, classLabel = null) {
299
+ const list = Array.isArray(classes) ? classes : [];
300
+ const label = (id) => (typeof classLabel === 'function' ? classLabel(id) : id) || id;
301
+ const lines = [];
302
+ lines.push(blank(width));
303
+ lines.push([span('', ' '), span(C.white + BOLD, 'Select class'), span(BOLD_OFF, '')]);
304
+ lines.push([span('', ' '), span(C.gray, 'Which route the next turn takes — who pays, and with which credential.')]);
305
+ lines.push(blank(width));
306
+ for (let i = 0; i < list.length; i++) {
307
+ const k = list[i] || {};
308
+ const id = k.class;
309
+ const active = i === sel;
310
+ const cur = current != null && id === current;
311
+ const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
312
+ const name = label(id);
313
+ const nameSpan = active ? span(C.lavender, name) : span(C.white, name);
314
+ const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
315
+ const pad = ' '.repeat(Math.max(1, 14 - [...name].length));
316
+ // Same distinction /class's static panel used to draw: who pays, and with
317
+ // which credential, so the picker says exactly what the printed table did.
318
+ const note =
319
+ id === 'byok'
320
+ ? k.configured
321
+ ? 'your key, relayed by AEGIS — billed a handling fee'
322
+ : 'needs a provider key: /byok-key <provider>'
323
+ : 'the pool — your AEGIS account key pays for it';
324
+ lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + note)]);
325
+ }
326
+ lines.push(blank(width));
327
+ lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
328
+ return fit(lines, width);
329
+ }
330
+
288
331
  // ── Resume-list overlay (/resume) ────────────────────────────────────────────
289
332
 
290
333
  /**
@@ -358,6 +401,7 @@ module.exports = {
358
401
  renderPalette,
359
402
  renderModelPicker,
360
403
  renderEffortPicker,
404
+ renderClassPicker,
361
405
  renderResumeList,
362
406
  EFFORT_LEVELS,
363
407
  EFFORT_VALUES,
@@ -29,8 +29,8 @@
29
29
  "p3": "ff962ac8dbf42cecb2477e2f77bf5ec61f88aa1751b0d4e506bf030fbc5fc6c6",
30
30
  "p4": "2e8385c3a653a2af324050b4b92aeb9d142fc6765c91a13ccc928c5d4a2dbedb",
31
31
  "p5": "408d67f78f31f6d637a26d2852e0c809a260544e613afdc64b731401c0ba3801",
32
- "p6": "2a934a1b76e1321457d0a2e7ebf91dcc9520097d6b62f7d5a99af0bd69c2cf97",
33
- "p7": "904efedb3101cca9d7b81009dfe72216ce773e7ab8f5bc603327b2f76da356be",
32
+ "p6": "50da0fa70ab4210f5fd6358c174009e91f481870136075f623a8592b1f19bd90",
33
+ "p7": "227117377da48ae003c4b971d242d579bfc8156c61d7719a2d3b331022a9b570",
34
34
  "p8": "3cc054d06715e065fe635b37b7d1bb98bf7989d64453a572ddbb77cec5b830e7"
35
35
  }
36
36
  }
package/src/render.js CHANGED
@@ -406,7 +406,15 @@ function renderWorking(ctx, state = {}) {
406
406
  const verb = state.verb || VERBS[0];
407
407
  const tail = [];
408
408
  if (state.elapsedMs != null) tail.push(fmtElapsed(state.elapsedMs));
409
- if (state.streamed != null) tail.push(`↓${fmtTokens(state.streamed)} tokens`);
409
+ // `streamedFloor` marks a figure that has folded in Anthropic's own
410
+ // `thinking_delta.estimated_tokens` (desktop/lib/local/claude-pro.js) — a
411
+ // running count that measurement showed landing under the real billed
412
+ // thinking-token total (1900 vs 1943, 1800 vs 1832, 250 vs 339). Flagged
413
+ // with `≥` rather than shown as an exact figure, because the true number
414
+ // only arrives with the turn's final `usage`.
415
+ if (state.streamed != null) {
416
+ tail.push(`↓${state.streamedFloor ? '≥' : ''}${fmtTokens(state.streamed)} tokens`);
417
+ }
410
418
  const tailStr = tail.length ? ` ${t.gray}(${tail.join(` ${GLYPH.bullet} `)})${RESET}` : '';
411
419
  return (
412
420
  `${t.coral}${frame}${RESET} ${t.white}${verb}${RESET}${t.white}…${RESET}${tailStr}` +
@@ -1133,6 +1133,7 @@ function createClient(opts = {}) {
1133
1133
  onStream,
1134
1134
  signal,
1135
1135
  providerKey,
1136
+ baseURL,
1136
1137
  } = {}) {
1137
1138
  const key = providerKey !== undefined ? providerKey : opts.providerKey;
1138
1139
  // Same rule as the pooled path above: omit `max_tokens` entirely when the
@@ -1169,6 +1170,11 @@ function createClient(opts = {}) {
1169
1170
  // `tools: []` differently from the field's plain absence.
1170
1171
  ...(Array.isArray(tools) && tools.length ? { tools } : {}),
1171
1172
  ...(toolChoice ? { tool_choice: toolChoice } : {}),
1173
+ // Read server-side ONLY for provider "custom" (aegis1 app.py
1174
+ // byok_chat_completions) — every other provider's upstream host is a
1175
+ // constant the server already knows, so sending this for them is a
1176
+ // no-op rather than a behaviour change.
1177
+ ...(baseURL ? { base_url: baseURL } : {}),
1172
1178
  };
1173
1179
  if (model) body.model = model;
1174
1180
  const headers = {
@@ -27,7 +27,7 @@
27
27
  *
28
28
  * ── what a user does now ───────────────────────────────────────────────────
29
29
  *
30
- * CLI `/model-add <provider> <model-id>` (and `/model-rm …`)
30
+ * CLI `/model-add <provider> [api-key] <model-id>` (and `/model-rm …`)
31
31
  * Desktop Settings → "Add a model" → provider + id
32
32
  * Either hand-edit `$AEGISCODE_HOME/models.json` (default `~/.aegiscode`)
33
33
  *
@@ -209,8 +209,15 @@ const DEFAULT_MODEL = 'nexus-brain';
209
209
  * depends on what the user's own daemon happens to have. Both REQUIRE an
210
210
  * explicit model, refused by name instead of silently resolving to
211
211
  * something nobody chose.
212
+ * - 'pro' DOES have a default, but not one this app chooses: a blank model
213
+ * means "the `claude` CLI picks for the subscription", which is what
214
+ * `--model` omitted says (engine.js sends no flag for `default`). Once a
215
+ * model IS stated it must be one of claude-pro.js's PRO_MODELS aliases —
216
+ * the same list the model picker offers — because the child accepts only
217
+ * those four spellings, and a `provider:model` id copied from a byok task
218
+ * would otherwise be handed to `claude --model` and fail there.
212
219
  */
213
- const MODEL_CLASSES = Object.freeze(['aegis', 'byok', 'local']);
220
+ const MODEL_CLASSES = Object.freeze(['aegis', 'byok', 'local', 'pro']);
214
221
 
215
222
  const AEGIS_MODEL_RE = /^(?:nexus|aegis)-brain(?:-(?:smart|neo))?$/;
216
223
  const AEGIS_MODEL_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
@@ -270,6 +277,34 @@ function modelRefusal(id, cls) {
270
277
  }
271
278
  return '';
272
279
  }
280
+ if (normalized === 'pro') {
281
+ // The subscription route. A blank model is legal and meaningful: engine.js
282
+ // sends no `--model` at all for 'default', so the child resolves the pick
283
+ // itself. Anything STATED must be a PRO_MODELS alias, because those four
284
+ // spellings are exactly what `claude --model` accepts — a byok-style
285
+ // "provider:model" copied between tasks would be handed to the child and
286
+ // fail there, three stages into a drain, with the queue's own file naming
287
+ // something the queue never validated.
288
+ if (!stated) return '';
289
+ // Required lazily: claude-pro.js is a heavy sibling (child spawn, session
290
+ // files) and this module is loaded by queue.js at every CLI start. The
291
+ // require is a plain sibling path with no back-require, so there is no
292
+ // cycle to guard — this is about load cost, not correctness.
293
+ let aliases;
294
+ try {
295
+ aliases = require('./claude-pro.js').PRO_MODELS;
296
+ } catch {
297
+ // If the alias list cannot be read we cannot validate a stated model, and
298
+ // accepting it unvalidated is the exact failure this arm exists to stop.
299
+ return `a pro task's model cannot be checked right now — queue it with no --model to let the claude CLI pick`;
300
+ }
301
+ const ids = (Array.isArray(aliases) ? aliases : []).map((m) => String(m && m.id).trim());
302
+ if (ids.includes(stated.toLowerCase())) return '';
303
+ return (
304
+ `the autonomous queue's Pro class runs the subscription through the claude CLI, ` +
305
+ `which accepts only its own model aliases (${ids.join('/')}); "${stated}" is not one`
306
+ );
307
+ }
273
308
  // normalized === 'local'
274
309
  if (!stated) return 'a local task needs a model — the tag of whatever is pulled into the local daemon';
275
310
  return '';
@@ -594,13 +629,18 @@ function createQueueWorker({
594
629
  */
595
630
  async function runTask(item, { carry = '', commit } = {}) {
596
631
  const cwd = item.cwd || process.cwd();
597
- // Aegis Cloud or nothing — checked BEFORE the turn, not at the server. An
598
- // item whose model is not a pooled tier (a hand-edited queue file, a
599
- // `--model` the CLI accepted before this rule existed, another host's
600
- // older build) would otherwise go out as `class: 'aegis'` with an id the
601
- // pool does not serve: billed work if it happens to be a per-provider
602
- // spelling, an opaque server error otherwise. Failing here names the model
603
- // and the allowed ones, and costs nothing.
632
+ // The task's own (model, class) pair checked BEFORE the turn, not at the
633
+ // server. An item whose model does not belong to its class (a hand-edited
634
+ // queue file, a `--model` the CLI accepted before this rule existed,
635
+ // another host's older build) would otherwise go out under a transport
636
+ // that does not serve it: billed work if it happens to be a per-provider
637
+ // spelling, an opaque server error otherwise, and for 'pro' a `claude
638
+ // --model` that the child rejects. Failing here names the model and the
639
+ // spellings that class accepts, and costs nothing.
640
+ //
641
+ // "Aegis Cloud or nothing" was this comment's old claim, and it stopped
642
+ // being true when byok/local were added (9eeef09) — modelRefusal is what
643
+ // actually enforces the rule now, per class, and it runs for all four.
604
644
  const cls = normalizeClass(item.class);
605
645
  const refusal = modelRefusal(item.model, cls);
606
646
  if (refusal) {