aegisone 1.0.6 → 1.0.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.
@@ -2639,7 +2639,27 @@ function hideWelcome() {
2639
2639
  // window.open (CSP `script-src 'self'` drops nothing here, but the
2640
2640
  // main process is what validates the URL).
2641
2641
 
2642
- /** Show the connect block only on an unconnected, un-dismissed install. */
2642
+ /** Show the connect block while EITHER connect route is still untaken, and
2643
+ * retire the individual routes that have been taken.
2644
+ *
2645
+ * This used to hide the whole block — "bring your own key" included — the
2646
+ * moment `keyConfigured` went true, on the reasoning that a panel still
2647
+ * advertising a route the user already took is a nag. It is a nag; but the
2648
+ * two routes are not alternatives, and the user who just redeemed an AEGIS
2649
+ * key is the one most likely to want a provider key of their own (a model the
2650
+ * pool does not carry, a turn that is not relayed). Hiding the BYOK path at
2651
+ * exactly that moment meant the app answered "you have a key" to a question
2652
+ * nobody had asked, and the two-key pop-up below was left to carry the whole
2653
+ * explanation. So the gates are now split, one per route, matching the CLI
2654
+ * welcome screen's `connectRows()`:
2655
+ *
2656
+ * cloud — retired by an AEGIS account key (that is the thing it pitches);
2657
+ * byok — retired by a provider route of the user's own (`providerConfigured`
2658
+ * — a BYOK key or a local base URL, which never touch aegis.apiKey).
2659
+ *
2660
+ * Both states are null/false until status is read, so an unknown state keeps
2661
+ * the block visible: on a cold boot the user has no key far more often than
2662
+ * not, and renderStatus() calls this again the moment the truth arrives. */
2643
2663
  function applyWelcomeConnect() {
2644
2664
  const box = document.getElementById('welcome-connect');
2645
2665
  if (!box) return;
@@ -2649,15 +2669,22 @@ function applyWelcomeConnect() {
2649
2669
  } catch {
2650
2670
  /* storage disabled — treat as not dismissed */
2651
2671
  }
2652
- // Both connect routes retire the block: the AEGIS Cloud key (keyConfigured)
2653
- // and a provider route of the user's own (providerConfigured — a BYOK key or
2654
- // a local base URL, which never touch aegis.apiKey). A panel that keeps
2655
- // advertising "Bring your own key" to someone who already did is a nag.
2656
- //
2657
- // keyConfigured is null until status is read, so an unknown state keeps the
2658
- // block visible: on a cold boot the user has no key far more often than not,
2659
- // and renderStatus() calls this again the moment the truth arrives.
2660
- box.hidden = dismissed || keyConfigured === true || providerConfigured === true;
2672
+ // `!== true`, not `=== false`: null is "not read yet" and must read as owed.
2673
+ const cloudOwed = keyConfigured !== true;
2674
+ const byokOwed = providerConfigured !== true;
2675
+ box.hidden = dismissed || (!cloudOwed && !byokOwed);
2676
+ // Each route retires on its own, button AND its note — a note left under a
2677
+ // gone button reads as a dangling fragment.
2678
+ setHidden('welcome-cloud', !cloudOwed);
2679
+ setHidden('welcome-cloud-note', !cloudOwed);
2680
+ setHidden('welcome-byok', !byokOwed);
2681
+ setHidden('welcome-byok-note', !byokOwed);
2682
+ }
2683
+
2684
+ /** Hide/show one cloned panel node by id when it exists. */
2685
+ function setHidden(id, hidden) {
2686
+ const el = document.getElementById(id);
2687
+ if (el) el.hidden = hidden;
2661
2688
  }
2662
2689
 
2663
2690
  /**
@@ -2786,7 +2813,8 @@ function dismissWelcomeConnect() {
2786
2813
  // ------------------------------------------- boot: the two-key pop-up
2787
2814
  //
2788
2815
  // The welcome block above pitches the ROUTES ("connect AEGIS Cloud", "bring
2789
- // your own key") and retires the moment either one is taken. This sheet is the
2816
+ // your own key") and retires each one as it is taken — keyConfigured for the
2817
+ // Cloud row, providerConfigured for the BYOK row. This sheet is the
2790
2818
  // other question, and the one nothing on screen used to answer: this app and
2791
2819
  // the `aegiscode` CLI on the command line are ONE engine over ONE store, so a
2792
2820
  // user who added only one of the two keys gets a surface that refuses turns
@@ -3580,6 +3608,119 @@ function renderApprovalCard(row, approval, beforeSelector) {
3580
3608
  return card;
3581
3609
  }
3582
3610
 
3611
+ /**
3612
+ * A turn-level note written by the APP, not by the model (`onDelta`'s
3613
+ * `{ note }` chunk). Rendered inside the assistant row it belongs to, above the
3614
+ * text stream, and kept out of `streamedText` for the reason the branch that
3615
+ * calls this states: the row's text is persisted as the assistant's own message
3616
+ * and pushed to the account's cloud memory, so app-authored prose placed there
3617
+ * would come back on the next turn as the model's previous answer.
3618
+ *
3619
+ * It exists because auto mode's silent round continuations have to be VISIBLE:
3620
+ * a turn whose budget quietly grew is the "why is it still running?" report
3621
+ * this app keeps getting, and the CLI announces the same continuation with the
3622
+ * same wording in its transcript.
3623
+ */
3624
+ function appendTurnNote(row, text, beforeSelector) {
3625
+ if (!row || !text) return null;
3626
+ const note = document.createElement('div');
3627
+ note.className = 'turn-note';
3628
+ note.textContent = text;
3629
+ const before = beforeSelector ? row.querySelector(beforeSelector) : null;
3630
+ if (before) row.insertBefore(note, before);
3631
+ else row.appendChild(note);
3632
+ return note;
3633
+ }
3634
+
3635
+ /**
3636
+ * Render the round-horizon card (`onDelta`'s `{ rounds: { id, spent,
3637
+ * extensions, max, size } }` chunk — see `requestRoundsAsk` in
3638
+ * desktop/lib/local/engine.js).
3639
+ *
3640
+ * This is the desktop half of what the CLI has handled since the ask landed
3641
+ * (`cli/src/app.js` `chunk.rounds` → `confirmRoundsExtension`). Without it the
3642
+ * desktop never opted in (`roundsAsk` was false, because nothing sent it), so a
3643
+ * turn that used its rounds ended with the engine's non-interactive note —
3644
+ * "…or raise AEGIS_CHAT_MAX_ROUNDS for a longer single turn" — naming an
3645
+ * environment variable a packaged Electron app gives its user no way to set.
3646
+ * The engine only says that where nobody could have been asked, so wiring the
3647
+ * ask is what deletes the obsolete line here: with the card on screen the note
3648
+ * drops the knob and keeps the part that is true (the work is held, the next
3649
+ * message resumes it).
3650
+ *
3651
+ * Answers through `models.respondRoundsAsk`; like the approval card it disables
3652
+ * itself on the first click so a double-click cannot send two decisions for one
3653
+ * id. Declining is NOT destructive: the engine falls through to the same
3654
+ * session-hold stop a non-interactive caller gets, so "Stop here" costs the user
3655
+ * nothing they cannot resume.
3656
+ */
3657
+ function renderRoundsCard(row, ask, beforeSelector) {
3658
+ if (!row || !ask || !ask.id) return null;
3659
+
3660
+ const spent = Number(ask.spent) || 0;
3661
+ const size = Number(ask.size) || spent;
3662
+ const extensions = Number(ask.extensions) || 1;
3663
+ const max = Number(ask.max) || 8;
3664
+
3665
+ const card = document.createElement('div');
3666
+ card.className = 'approval-card rounds-card';
3667
+ card.dataset.roundsAskId = ask.id;
3668
+
3669
+ const title = document.createElement('div');
3670
+ title.className = 'approval-title';
3671
+ title.textContent = `Round limit reached — keep going?`;
3672
+ card.appendChild(title);
3673
+
3674
+ const summary = document.createElement('div');
3675
+ summary.className = 'approval-summary';
3676
+ // Says the three things the user needs to decide: what the limit is, what
3677
+ // "keep going" buys, and that stopping is a pause rather than a loss. No
3678
+ // environment variable is named, because the card IS the lever now.
3679
+ summary.textContent =
3680
+ `This turn has used all ${spent} tool rounds allowed for it. ` +
3681
+ `${size} more continue the SAME turn — no restart, no repeated work. ` +
3682
+ `Stopping holds everything done so far: your next message resumes it automatically. ` +
3683
+ `(${extensions} of ${max} extensions.)`;
3684
+ card.appendChild(summary);
3685
+
3686
+ const actions = document.createElement('div');
3687
+ actions.className = 'approval-actions';
3688
+
3689
+ const decide = (decision) => {
3690
+ for (const btn of actions.querySelectorAll('button')) btn.disabled = true;
3691
+ card.classList.add('resolved');
3692
+ const tag = document.createElement('div');
3693
+ tag.className = 'approval-decision';
3694
+ tag.textContent = decision ? `Continuing — ${size} more rounds` : 'Stopped — the work is held';
3695
+ card.appendChild(tag);
3696
+ models.respondRoundsAsk(ask.id, decision);
3697
+ };
3698
+
3699
+ const mkButton = (label, cls, decision) => {
3700
+ const btn = document.createElement('button');
3701
+ btn.type = 'button';
3702
+ btn.className = `approval-btn ${cls}`;
3703
+ btn.textContent = label;
3704
+ btn.addEventListener('click', () => decide(decision));
3705
+ return btn;
3706
+ };
3707
+
3708
+ actions.appendChild(mkButton(`Keep going (${size} more rounds)`, 'allow', true));
3709
+ actions.appendChild(mkButton('Stop here', 'deny', false));
3710
+ card.appendChild(actions);
3711
+
3712
+ let slot = row.querySelector('.approval-slot');
3713
+ if (!slot) {
3714
+ slot = document.createElement('div');
3715
+ slot.className = 'approval-slot';
3716
+ const before = beforeSelector ? row.querySelector(beforeSelector) : null;
3717
+ if (before) row.insertBefore(slot, before);
3718
+ else row.appendChild(slot);
3719
+ }
3720
+ slot.appendChild(card);
3721
+ return card;
3722
+ }
3723
+
3583
3724
  function classLabel(cls) {
3584
3725
  const found = classOptions.find((c) => c.class === cls);
3585
3726
  return found ? found.label : cls;
@@ -4043,6 +4184,12 @@ async function saveLocalBase(baseURL) {
4043
4184
 
4044
4185
  async function loadSettings() {
4045
4186
  els.settingsList.innerHTML = '';
4187
+ // The provider ids the class offers, collected while the byok rows are built.
4188
+ // `/byok`'s own list IS the catalog, so the "add a model" field below can
4189
+ // offer it instead of asking the user to remember a slug — and it can still
4190
+ // accept a typed id, because the very case this row exists for is a provider
4191
+ // whose lineup moved ahead of our catalog.
4192
+ const byokProviderIds = [];
4046
4193
  let settings = [];
4047
4194
  try {
4048
4195
  settings = (await models.settings.get()) || [];
@@ -4081,6 +4228,7 @@ async function loadSettings() {
4081
4228
  const byokProviders = Array.isArray(byokData && byokData.providers) ? byokData.providers : [];
4082
4229
  for (const p of byokProviders) {
4083
4230
  if (!p || !p.id) continue;
4231
+ byokProviderIds.push({ id: p.id, label: p.label || p.id });
4084
4232
  const provider = `byok:${p.id}`;
4085
4233
  const local = settings.find((s) => s.provider === provider) || {
4086
4234
  provider, baseURL: '', configured: false, keyMask: null,
@@ -4117,6 +4265,195 @@ async function loadSettings() {
4117
4265
  } catch {
4118
4266
  /* catalog unreachable (offline, server down) — no rows, and the hint above says why */
4119
4267
  }
4268
+
4269
+ // The user's OWN model declarations (`client/user-models.js`, the file the
4270
+ // CLI's `/model-add` writes). Rendered outside the byok try above so it
4271
+ // survives an unreachable catalog, and it is the ONE way a desktop user can
4272
+ // pin a model the AEGIS catalog does not name — a newly shipped vendor id, a
4273
+ // fine-tune, a preview route — without waiting for a release or hand-editing
4274
+ // a JSON file the app never named. The relay is a pass-through, so anything
4275
+ // the vendor serves for a provider whose key is set is callable.
4276
+ try {
4277
+ await renderUserModelRows(byokProviderIds);
4278
+ } catch (err) {
4279
+ els.settingsHint.textContent =
4280
+ `your own models: ${err && err.message ? err.message : err}`;
4281
+ }
4282
+ }
4283
+
4284
+ /**
4285
+ * The "your own models" block: one add row plus a row per declaration.
4286
+ *
4287
+ * Everything here goes through the engine (`models.userModels.*`), never
4288
+ * through the settings store, because the engine's `listModels('byok')` is what
4289
+ * APPLIES the declarations — one implementation writes the file and one reads
4290
+ * it, so the row a user adds here is the row the picker offers on its next
4291
+ * refresh (loadModels is re-run by the callers below).
4292
+ *
4293
+ * A rejected value does not throw into the console: `add`/`remove` reject with
4294
+ * the validation message (an id the relay would forward to a vendor 404s on the
4295
+ * user's first turn, so refusing it here is the whole value of the check) and it
4296
+ * is printed in the hint line with the file path, which is also the documented
4297
+ * escape hatch for a bulk edit.
4298
+ */
4299
+ async function renderUserModelRows(byokProviderIds) {
4300
+ if (!els.settingsList || !models.userModels) return;
4301
+ const report = await models.userModels.get();
4302
+ if (!report) return;
4303
+ const map = (report && report.map) || {};
4304
+ const ids = (byokProviderIds || []).map((p) => (p && p.id) || '').filter(Boolean);
4305
+
4306
+ const block = document.createElement('div');
4307
+ block.id = 'user-models-block';
4308
+
4309
+ const title = document.createElement('div');
4310
+ title.className = 'setting-name';
4311
+ title.textContent = 'Your own models (BYOK)';
4312
+ block.appendChild(title);
4313
+
4314
+ // ── add: provider + model id + one button
4315
+ const addRow = document.createElement('div');
4316
+ addRow.className = 'setting-row';
4317
+ addRow.dataset.provider = 'byok:__user-model-add';
4318
+
4319
+ const providerInput = document.createElement('input');
4320
+ providerInput.type = 'text';
4321
+ providerInput.className = 'setting-input';
4322
+ providerInput.id = 'user-model-provider';
4323
+ providerInput.placeholder = 'provider (deepseek)';
4324
+ providerInput.autocomplete = 'off';
4325
+ providerInput.spellcheck = false;
4326
+ // A datalist rather than a select: the catalog's ids are a convenience for the
4327
+ // common case, and a typed slug is still allowed for the case this row exists
4328
+ // for (the catalog has not caught up). A select would have made the second one
4329
+ // impossible without a form of its own.
4330
+ if (ids.length) {
4331
+ const list = document.createElement('datalist');
4332
+ list.id = 'user-model-providers';
4333
+ for (const id of ids) {
4334
+ const opt = document.createElement('option');
4335
+ opt.value = id;
4336
+ list.appendChild(opt);
4337
+ }
4338
+ addRow.appendChild(list);
4339
+ providerInput.setAttribute('list', 'user-model-providers');
4340
+ }
4341
+ addRow.appendChild(providerInput);
4342
+
4343
+ const modelInput = document.createElement('input');
4344
+ modelInput.type = 'text';
4345
+ modelInput.className = 'setting-input';
4346
+ modelInput.id = 'user-model-id';
4347
+ modelInput.placeholder = 'model id (deepseek-v4.2-preview)';
4348
+ modelInput.autocomplete = 'off';
4349
+ modelInput.spellcheck = false;
4350
+ addRow.appendChild(modelInput);
4351
+
4352
+ const actions = document.createElement('div');
4353
+ actions.className = 'setting-actions';
4354
+ const addBtn = document.createElement('button');
4355
+ addBtn.type = 'button';
4356
+ addBtn.className = 'ghost-btn';
4357
+ addBtn.id = 'user-model-add';
4358
+ addBtn.textContent = 'Add model';
4359
+ addBtn.addEventListener('click', async () => {
4360
+ const provider = providerInput.value.trim();
4361
+ const model = modelInput.value.trim();
4362
+ els.settingsHint.textContent = 'adding…';
4363
+ try {
4364
+ const res = await models.userModels.add(provider, model);
4365
+ els.settingsHint.textContent = res && res.added === false
4366
+ ? `${res.provider}:${res.model} was already declared.`
4367
+ : `added ${res.provider}:${res.model} — /models and the picker now offer it.`;
4368
+ await loadSettings();
4369
+ await loadModels(els.classSelect.value);
4370
+ } catch (err) {
4371
+ els.settingsHint.textContent = `${err && err.message ? err.message : err}`;
4372
+ }
4373
+ });
4374
+ actions.appendChild(addBtn);
4375
+ addRow.appendChild(actions);
4376
+
4377
+ const hint = document.createElement('div');
4378
+ hint.className = 'setting-status';
4379
+ hint.id = 'user-model-hint';
4380
+ hint.textContent = report.file
4381
+ ? `saved in ${report.file} — the CLI reads the same file (/model-add)`
4382
+ : 'saved beside your AEGIS config — the CLI reads the same file (/model-add)';
4383
+ addRow.appendChild(hint);
4384
+ block.appendChild(addRow);
4385
+
4386
+ // ── one removal row per declaration, provider-major and sorted, so the list
4387
+ // is stable between renders (an order that shuffled would make the Remove
4388
+ // button beside a row a guess).
4389
+ const providers = Object.keys(map).sort();
4390
+ for (const provider of providers) {
4391
+ for (const model of map[provider]) {
4392
+ const row = document.createElement('div');
4393
+ row.className = 'setting-row';
4394
+ row.dataset.provider = `byok:${provider}`;
4395
+
4396
+ const name = document.createElement('div');
4397
+ name.className = 'setting-name';
4398
+ name.textContent = `${provider} — ${model}`;
4399
+ row.appendChild(name);
4400
+
4401
+ const status = document.createElement('div');
4402
+ status.className = 'setting-status';
4403
+ // Declared, but not offered: the server's BYOK catalog lists no row for
4404
+ // this provider, so no key could ever be attached to it and the engine
4405
+ // will not paint it. Saying so here is the difference between "my typo is
4406
+ // being ignored" and "this provider cannot take a key".
4407
+ status.textContent = ids.length && !ids.includes(provider)
4408
+ ? 'no provider row for this id — /byok lists the ones the relay takes'
4409
+ : 'offered in the picker on this machine';
4410
+ row.appendChild(status);
4411
+
4412
+ const rowActions = document.createElement('div');
4413
+ rowActions.className = 'setting-actions';
4414
+ const rmBtn = document.createElement('button');
4415
+ rmBtn.type = 'button';
4416
+ rmBtn.className = 'ghost-btn danger';
4417
+ rmBtn.textContent = 'Remove';
4418
+ rmBtn.addEventListener('click', async () => {
4419
+ els.settingsHint.textContent = 'removing…';
4420
+ try {
4421
+ const res = await models.userModels.remove(provider, model);
4422
+ els.settingsHint.textContent = res && res.removed === false
4423
+ ? `${provider}:${model} was not declared.`
4424
+ : `removed ${provider}:${model}.`;
4425
+ await loadSettings();
4426
+ await loadModels(els.classSelect.value);
4427
+ } catch (err) {
4428
+ els.settingsHint.textContent = `${err && err.message ? err.message : err}`;
4429
+ }
4430
+ });
4431
+ rowActions.appendChild(rmBtn);
4432
+ row.appendChild(rowActions);
4433
+
4434
+ block.appendChild(row);
4435
+ }
4436
+ }
4437
+
4438
+ // A hand-edited file can carry a row this module refuses (a typo, an id with a
4439
+ // space). It is named rather than dropped in silence: otherwise "my model is
4440
+ // nowhere in the picker" has no explanation anywhere in the UI.
4441
+ const invalid = (report && report.invalid) || [];
4442
+ for (const bad of invalid) {
4443
+ const row = document.createElement('div');
4444
+ row.className = 'setting-row';
4445
+ const name = document.createElement('div');
4446
+ name.className = 'setting-name';
4447
+ name.textContent = `${bad.provider || 'models.json'}: ${bad.model == null ? '' : String(bad.model)}`.trim();
4448
+ row.appendChild(name);
4449
+ const status = document.createElement('div');
4450
+ status.className = 'setting-status';
4451
+ status.textContent = `skipped — ${bad.reason}`;
4452
+ row.appendChild(status);
4453
+ block.appendChild(row);
4454
+ }
4455
+
4456
+ els.settingsList.appendChild(block);
4120
4457
  }
4121
4458
 
4122
4459
  async function saveSetting(provider, key) {
@@ -4546,6 +4883,19 @@ async function send() {
4546
4883
  paintStream();
4547
4884
  return;
4548
4885
  }
4886
+ if (chunk && typeof chunk.note === 'string' && chunk.note) {
4887
+ // A turn-level notice that is NOT the model's words — today the only one
4888
+ // is auto mode's "continuing automatically" line (desktop/main.js
4889
+ // chatWithAutoRounds). It is deliberately not folded into
4890
+ // `streamedText`: that string becomes the assistant's message and is
4891
+ // persisted and synced, so an app-authored sentence put there would
4892
+ // re-enter the model's context on the next turn as something it had said.
4893
+ const row = ensurePendingRow();
4894
+ row.classList.remove('pending');
4895
+ appendTurnNote(row, chunk.note, '.body');
4896
+ stickToBottom();
4897
+ return;
4898
+ }
4549
4899
  if (chunk && chunk.approval) {
4550
4900
  const row = ensurePendingRow();
4551
4901
  row.classList.remove('pending');
@@ -4555,6 +4905,17 @@ async function send() {
4555
4905
  stickToBottom({ force: true });
4556
4906
  return;
4557
4907
  }
4908
+ if (chunk && chunk.rounds) {
4909
+ const row = ensurePendingRow();
4910
+ row.classList.remove('pending');
4911
+ renderRoundsCard(row, chunk.rounds, '.body');
4912
+ // Same blocked-until-answered reason as the approval card above. The
4913
+ // engine holds the turn open on this promise, and an unanswered ask
4914
+ // resolves `false` — so a card the user never scrolled to would read as
4915
+ // the turn stopping for no reason.
4916
+ stickToBottom({ force: true });
4917
+ return;
4918
+ }
4558
4919
  if (chunk && chunk.tool) {
4559
4920
  // See the flow-stream handler above: the run frame is the CLI's live
4560
4921
  // row. Ignored here, and ignored *before* `toolLog.push` — a run frame
@@ -4579,7 +4940,29 @@ async function send() {
4579
4940
  // All four classes route through the model: surface (the main process
4580
4941
  // decides transport — cloud client, ollama, or a direct provider).
4581
4942
  const data = await models.chat(
4582
- { class: cls, prompt, model, maxTokens, sessionId, autonomous, effort, workers, messages: historyForModel },
4943
+ {
4944
+ class: cls,
4945
+ prompt,
4946
+ model,
4947
+ maxTokens,
4948
+ sessionId,
4949
+ autonomous,
4950
+ effort,
4951
+ workers,
4952
+ messages: historyForModel,
4953
+ // Opt in to the round-horizon dialog. A live renderer on the other end
4954
+ // of the delta stream is exactly what this flag asserts, and this call
4955
+ // has one (the `{ rounds }` branch of onDelta above answers it via
4956
+ // renderRoundsCard → models.respondRoundsAsk). It is also what retires
4957
+ // the engine's "raise AEGIS_CHAT_MAX_ROUNDS" advice: that line is
4958
+ // written only for callers nobody could ask (see the `knob` note in
4959
+ // lib/local/engine.js), and a packaged app user has no env to set.
4960
+ // The discovery lane (spawnPath) deliberately does NOT pass this: it is
4961
+ // single-shot with no tools, so it can never reach a round horizon, and
4962
+ // opting in would buy a dialog nobody could answer in a fire-and-forget
4963
+ // card.
4964
+ roundsAsk: true,
4965
+ },
4583
4966
  onDelta
4584
4967
  );
4585
4968
 
@@ -544,14 +544,14 @@
544
544
  <button type="button" class="wc-link" id="welcome-cloud">
545
545
  Connect AEGIS Cloud — I already have a key →
546
546
  </button>
547
- <span class="wc-note">
547
+ <span class="wc-note" id="welcome-cloud-note">
548
548
  Connect it here and the same queue runs on pooled models right
549
549
  away, free, while this window is open.
550
550
  </span>
551
551
  <button type="button" class="wc-link" id="welcome-byok">
552
552
  Bring your own key →
553
553
  </button>
554
- <span class="wc-note">
554
+ <span class="wc-note" id="welcome-byok-note">
555
555
  The free path, and it stays free: exec, write and edit run on
556
556
  your machine, your repos, sessions and keys live on this disk,
557
557
  and a local model server needs no account at all. A provider
@@ -1525,6 +1525,38 @@ label {
1525
1525
  background: rgba(255, 255, 255, 0.03);
1526
1526
  }
1527
1527
 
1528
+ /* The round-horizon card borrows the approval card wholesale — same slot, same
1529
+ buttons, same one-decision-then-disable behaviour — and only re-tints to the
1530
+ accent: it is a budget question about the turn, not a permission question
1531
+ about a tool, and the two can be on screen in the same conversation. Without
1532
+ the tint a user reading quickly would answer the wrong one. */
1533
+ .rounds-card {
1534
+ border-color: var(--accent);
1535
+ background: rgba(90, 160, 255, 0.08);
1536
+ }
1537
+
1538
+ .rounds-card .approval-title {
1539
+ color: var(--accent);
1540
+ }
1541
+
1542
+ .rounds-card.resolved .approval-title {
1543
+ color: var(--text2);
1544
+ }
1545
+
1546
+ /* An app-authored turn note ({ note } frames — today auto mode's "continuing
1547
+ automatically" line). Muted and unboxed on purpose: it is a statement about
1548
+ the turn's budget, not a question, and it must not read as either of the two
1549
+ cards that ARE questions (approval, round horizon). */
1550
+ .turn-note {
1551
+ font-family: var(--font-mono);
1552
+ font-size: 11px;
1553
+ color: var(--text2);
1554
+ border-left: 2px solid var(--accent);
1555
+ padding: 2px 0 2px 8px;
1556
+ margin: 4px 0;
1557
+ opacity: 0.9;
1558
+ }
1559
+
1528
1560
  .approval-title {
1529
1561
  font-family: var(--font-mono);
1530
1562
  font-size: 11px;
@@ -139,9 +139,36 @@ function estimatedBuckets(prompt, reply, reasoning) {
139
139
  // Keys are matched by exact id first, then by prefix (ratesFor below), so a
140
140
  // family row covers every dated variant of it.
141
141
  const RATES = {
142
+ // Sonnet, Opus, Fable, Haiku — the four FAMILY rows, matched by prefix, and
143
+ // deliberately NOT re-pointed at any one generation's price.
144
+ //
145
+ // The tempting change is to price this row as Claude Sonnet 5's published
146
+ // $2.00/$10.00, on the theory that `sonnet` names Sonnet 5. It does not: this
147
+ // repo's own alias tables carry no such id. `cli/src/models.js` lists pooled
148
+ // seats by name and `cli/src/config.js` records that the platform "does not
149
+ // advertise" `sonnet` at all — a pin on it was a phantom that made the pool
150
+ // answer from its own default with no error. So a bare `sonnet` is a LABEL,
151
+ // not a route: `cli/src/tokens.js` uses it as the default stand-in when no
152
+ // model is named, and the family row here is what a non-`claude-`-prefixed
153
+ // spelling resolves to by prefix.
154
+ //
155
+ // $3.00/$15.00 is therefore the honest figure for it, and it is the SAME
156
+ // figure as `RATES.default` below — which is the point: an id that names no
157
+ // real vendored route prices exactly like an unpriced one, never like a
158
+ // current-generation model. Every id that DOES name a real model has an exact
159
+ // row in the Claude 5 block below, and an exact id out-ranks a prefix match,
160
+ // so correcting those is what fixes the money — re-pointing this family row
161
+ // only moves the number an admitted placeholder reports, and silently
162
+ // re-prices every dated spelling that resolves here by prefix
163
+ // (`sonnet-4-5-20250929` is pinned at $3.00 in test/turn-accounting.test.mjs
164
+ // for exactly that reason).
142
165
  sonnet: { input: 3.00, output: 15.00, cacheRead: 0.30, cacheWrite: 3.75 },
143
166
  default: { input: 3.00, output: 15.00, cacheRead: 0.30, cacheWrite: 3.75 },
144
- fable: { input: 5.00, output: 25.00, cacheRead: 0.50, cacheWrite: 6.25 },
167
+ // Fable — the alias for **claude-fable-5**, at Fable's published
168
+ // $10.00/$50.00. The $5.00/$25.00 this row used to carry is the Opus-class
169
+ // figure; Fable has never been priced there, and the error ran in the
170
+ // under-reporting direction on the most expensive model in the lineup.
171
+ fable: { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
145
172
  opus: { input: 5.00, output: 25.00, cacheRead: 0.50, cacheWrite: 6.25 },
146
173
  // Haiku — the same class of hole as the DeepSeek row below, on the provider
147
174
  // whose prices we already thought we knew. The three rows above price Sonnet,
@@ -160,6 +187,46 @@ const RATES = {
160
187
  // match is EXACT and cannot be reordered away.
161
188
  'claude-haiku': { input: 1.00, output: 5.00, cacheRead: 0.10, cacheWrite: 1.25 },
162
189
 
190
+ // ── the Claude 5 line, one row per ID ────────────────────────────────────
191
+ //
192
+ // Every figure here is Anthropic's own published rate (docs.claude.com
193
+ // pricing table, fetched 2026-10-11), not a fraction derived from a sibling
194
+ // row. They are EXACT rows because the family fallback prices this
195
+ // generation wrong in both directions: `claude-sonnet-5-5` family-matched
196
+ // `sonnet` and `claude-fable-5-1` family-matched `fable`, so the very ids
197
+ // the picker offers and the BYOK relay forwards were billed at rates the
198
+ // vendor does not charge for them.
199
+ //
200
+ // cacheRead is NOT the 0.1x-input convention the 4.x rows above use.
201
+ // Anthropic changed the cache-hit multiplier on this generation and quotes
202
+ // it per model — 5% of input on Opus 5.5 and Sonnet 5.5 ($0.20 / $0.10),
203
+ // 2.5% on Fable 5.1 ($0.25), 10% on Fable 5 and Haiku 5.5 ($1.00 / $0.01)
204
+ // — so each row carries the published number rather than a multiplier this
205
+ // file computed. cacheWrite stays 1.25x input, which the same table
206
+ // confirms for all of them.
207
+ //
208
+ // Haiku 5.5 is priced by PROMPT LENGTH: the vendor charges 5x input and 5x
209
+ // output once a request's prompt passes 100k tokens ($0.50/$2.50). This
210
+ // schema has no prompt-size field — the only tiering it models is
211
+ // DeepSeek's time-of-day peak/offPeak — so the row carries the up-to-100k
212
+ // tier and a long-context Haiku turn UNDER-reports. Said out loud rather
213
+ // than left implicit: the alternative is 5x-ing every ordinary Haiku turn,
214
+ // which is the louder error.
215
+ 'claude-opus-5': { input: 5.00, output: 25.00, cacheRead: 0.50, cacheWrite: 6.25 },
216
+ 'claude-opus-5-5': { input: 4.00, output: 20.00, cacheRead: 0.20, cacheWrite: 5.00 },
217
+ 'claude-sonnet-5': { input: 2.00, output: 10.00, cacheRead: 0.20, cacheWrite: 2.50 },
218
+ 'claude-sonnet-5-5': { input: 2.00, output: 10.00, cacheRead: 0.10, cacheWrite: 2.50 },
219
+ 'claude-haiku-5-5': { input: 0.10, output: 0.50, cacheRead: 0.01, cacheWrite: 0.125 },
220
+ 'claude-fable-5': { input: 10.00, output: 50.00, cacheRead: 1.00, cacheWrite: 12.50 },
221
+ 'claude-fable-5-1': { input: 10.00, output: 50.00, cacheRead: 0.25, cacheWrite: 12.50 },
222
+ // The Sonnet 4.x spellings keep their own line items now that `sonnet`
223
+ // above carries the 5-line price: without these, a Claude Sonnet 4.x turn —
224
+ // the id a config saved before this change still holds, and the wire model
225
+ // the dated form names — would family-match the alias row and be billed
226
+ // $2.00/$10.00 against the vendor's $3.00/$15.00.
227
+ 'claude-sonnet-4-6': { input: 3.00, output: 15.00, cacheRead: 0.30, cacheWrite: 3.75 },
228
+ 'claude-sonnet-4-5': { input: 3.00, output: 15.00, cacheRead: 0.30, cacheWrite: 3.75 },
229
+
163
230
  // DeepSeek — read off the vendor's own pricing table
164
231
  // (api-docs.deepseek.com/quick_start/pricing), not from a secondary blog and
165
232
  // not from a mirror of our own catalog.
@@ -1440,7 +1440,29 @@ function createClient(opts = {}) {
1440
1440
  .sort((a, b) => a[0] - b[0])
1441
1441
  .map(([idx, c]) => ({ ...c, id: c.id || `call_${idx}` }));
1442
1442
 
1443
+ // The hidden chain-of-thought belongs on the RESULT, not only on the live
1444
+ // stream. `reasoningText` above is accumulated and forwarded to the caller's
1445
+ // `onReasoning`/`onStream` so the thinking can be shown while it happens —
1446
+ // but the resolved result carried only `content`, so every down-stream
1447
+ // diagnosis of "the model spent the whole budget thinking and never wrote a
1448
+ // word" read an empty reasoning channel on THIS lane and concluded there had
1449
+ // been no thinking at all.
1450
+ //
1451
+ // That is not a cosmetic loss. desktop/lib/local/engine.js decides its
1452
+ // reasoning-only recovery from exactly this field (`reasonedButSilent` →
1453
+ // `reasoningTextOf(res)`), so on byok the gate was dead code: DeepSeek
1454
+ // returns `finish_reason: 'stop'` with empty content and a full
1455
+ // `reasoning_content`, which matched neither `isTruncated` (the reason says
1456
+ // 'stop', not 'length') nor the reasoning retry (nothing to detect), and the
1457
+ // turn fell straight through to emptyTurnError — the "backend error: the
1458
+ // model returned no answer … max_tokens 16384" the user sees. Measured live
1459
+ // on byok/deepseek-v4-flash 2026-10-11.
1460
+ //
1461
+ // Kept out of `content` on purpose: deliberation is not an answer, and
1462
+ // folding it in would make a no-answer turn look answered to every caller's
1463
+ // empty-check (see the note at the `reasoningText` accumulation above).
1443
1464
  const message = { content: cleanText };
1465
+ if (reasoningText) message.reasoning_content = reasoningText;
1444
1466
  if (toolCalls.length) message.tool_calls = toolCalls;
1445
1467
  const result = {
1446
1468
  model: resultModel,