aegisone 1.0.5 → 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.
Files changed (45) hide show
  1. package/README.md +2 -2
  2. package/bin/aegis.js +28 -3
  3. package/package.json +1 -1
  4. package/scripts/predist.mjs +230 -0
  5. package/src/permissions.js +134 -7
  6. package/src/release.js +14 -5
  7. package/vendor/cli/README.md +42 -3
  8. package/vendor/cli/bin/aegiscode.js +15 -3
  9. package/vendor/cli/package.json +1 -1
  10. package/vendor/cli/src/app.js +167 -37
  11. package/vendor/cli/src/chatflow.js +285 -39
  12. package/vendor/cli/src/commands.js +251 -30
  13. package/vendor/cli/src/config.js +41 -11
  14. package/vendor/cli/src/engine.js +33 -4
  15. package/vendor/cli/src/entitlement.js +30 -1
  16. package/vendor/cli/src/format.js +175 -3
  17. package/vendor/cli/src/overlays.js +13 -9
  18. package/vendor/cli/src/panels.js +19 -6
  19. package/vendor/cli/src/render.js +49 -14
  20. package/vendor/cli/src/screen.js +12 -1
  21. package/vendor/cli/src/screens.js +118 -25
  22. package/vendor/cli/src/todos.js +7 -4
  23. package/vendor/cli/src/tokens.js +31 -1
  24. package/vendor/cli/vendor/client/aegis.js +22 -0
  25. package/vendor/cli/vendor/client/byok-catalog.js +43 -8
  26. package/vendor/cli/vendor/client/user-models.js +378 -0
  27. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +81 -0
  28. package/vendor/cli/vendor/desktop/lib/local/engine.js +447 -14
  29. package/vendor/cli/vendor/desktop/renderer/usage.js +274 -21
  30. package/vendor/cli/vendor/mcp/tools.js +1 -1
  31. package/vendor/desktop/README.md +11 -0
  32. package/vendor/desktop/lib/deep-link.js +35 -1
  33. package/vendor/desktop/lib/local/autonomous.js +81 -0
  34. package/vendor/desktop/lib/local/engine.js +447 -14
  35. package/vendor/desktop/main.js +271 -6
  36. package/vendor/desktop/package.json +1 -1
  37. package/vendor/desktop/preload.js +18 -0
  38. package/vendor/desktop/renderer/app.js +631 -43
  39. package/vendor/desktop/renderer/index.html +4 -5
  40. package/vendor/desktop/renderer/stream-policy.js +24 -2
  41. package/vendor/desktop/renderer/style.css +81 -7
  42. package/vendor/desktop/renderer/usage.js +274 -21
  43. package/vendor/desktop/vendor/aegis.js +22 -0
  44. package/vendor/desktop/vendor/byok-catalog.js +43 -8
  45. package/vendor/desktop/vendor/user-models.js +378 -0
@@ -25,7 +25,7 @@
25
25
  <!-- The rolling session token total, counted the way the CLI counts it:
26
26
  every finished turn folded into one running number rather than a
27
27
  per-turn count that resets. Hidden until a turn has been accounted
28
- for, so an untouched thread never shows a `0 tok` it never measured. -->
28
+ for, so an untouched thread never shows a `0 tokens` it never measured. -->
29
29
  <div class="session-meter" id="session-meter" hidden></div>
30
30
  <div class="spacer"></div>
31
31
  <button type="button" id="new-chat" class="ghost-btn">New chat</button>
@@ -138,8 +138,7 @@
138
138
  <select id="effort-select">
139
139
  <option value="low">low</option>
140
140
  <option value="medium">medium</option>
141
- <option value="high">high</option>
142
- <option value="auto" selected>auto</option>
141
+ <option value="high" selected>high</option>
143
142
  </select>
144
143
  </div>
145
144
 
@@ -545,14 +544,14 @@
545
544
  <button type="button" class="wc-link" id="welcome-cloud">
546
545
  Connect AEGIS Cloud — I already have a key →
547
546
  </button>
548
- <span class="wc-note">
547
+ <span class="wc-note" id="welcome-cloud-note">
549
548
  Connect it here and the same queue runs on pooled models right
550
549
  away, free, while this window is open.
551
550
  </span>
552
551
  <button type="button" class="wc-link" id="welcome-byok">
553
552
  Bring your own key →
554
553
  </button>
555
- <span class="wc-note">
554
+ <span class="wc-note" id="welcome-byok-note">
556
555
  The free path, and it stays free: exec, write and edit run on
557
556
  your machine, your repos, sessions and keys live on this disk,
558
557
  and a local model server needs no account at all. A provider
@@ -207,8 +207,23 @@ function isPlaceholderContent(content) {
207
207
  );
208
208
  }
209
209
 
210
- /** The smallest stream growth, in characters, that earns a live-meter recompute. */
211
- const LIVE_METER_MIN_GROWTH = 256;
210
+ /** The smallest stream growth, in characters, that earns a live-meter recompute.
211
+ *
212
+ * It was 256, and that number was the start-of-turn lag this rule exists to
213
+ * avoid: the counter's first paint required a quarter kilobyte of text — ~64
214
+ * tokens, several seconds into a slow turn — so the bubble opened with no
215
+ * figure at all and then jumped to it, while the CLI's own tail
216
+ * (`cli/src/chatflow.js`'s spinner, `↓${fmtTokens(state.streamed)}`) and the
217
+ * reference engine both have a count climbing from the first frame. 32 chars
218
+ * (~8 tokens) is a step the eye reads as continuous at the start of a reply,
219
+ * which is the whole point of a live count.
220
+ *
221
+ * The cost bound is NOT this number — it is the proportional term below. At
222
+ * 100k chars the step is 1/32 of the stream (3125), so lowering this floor
223
+ * leaves the long-reply recompute count unchanged; it only buys paints in the
224
+ * first ~1k characters, where each estimate is over a string too short to
225
+ * matter. */
226
+ const LIVE_METER_MIN_GROWTH = 32;
212
227
 
213
228
  /** …and the fraction of the whole stream that must have arrived since the last
214
229
  * one: a recompute comes due once the stream has grown by 1/this. */
@@ -241,6 +256,13 @@ const LIVE_METER_GROWTH_FRACTION = 32;
241
256
  */
242
257
  function liveMeterDue(measured, streamChars) {
243
258
  const now = Number(streamChars) || 0;
259
+ // Nothing has been painted yet this turn. The cursor is per-turn and starts
260
+ // UNSET (see app.js `let meterChars = null`), and an unset cursor must not be
261
+ // read as "measured an empty stream" — that made the first paint wait out the
262
+ // whole step below, which is the start-of-turn dead zone. The first text to
263
+ // arrive paints, so the figure is on screen from the first chunk rather than
264
+ // from the first 32nd of the reply.
265
+ if (measured === null || measured === undefined) return now > 0;
244
266
  const grown = now - (Number(measured) || 0);
245
267
  if (grown <= 0) return false;
246
268
  const step = Math.max(LIVE_METER_MIN_GROWTH, Math.floor(now / LIVE_METER_GROWTH_FRACTION));
@@ -148,6 +148,15 @@ body {
148
148
  display: none;
149
149
  }
150
150
 
151
+ /* A total that is still climbing has to look different from one that has
152
+ stopped, or "is it still working?" is answered by watching for the absence
153
+ of change. Set by `renderRollMeter` from the same `live` flag that makes the
154
+ figure an estimate in the first place. */
155
+ .session-meter.live {
156
+ color: var(--accent);
157
+ border-color: var(--accent);
158
+ }
159
+
151
160
  .spacer {
152
161
  flex: 1;
153
162
  }
@@ -876,21 +885,31 @@ body.memory-open {
876
885
  text-align: center;
877
886
  }
878
887
 
888
+ /* Dimmed by COLOR, not by `opacity`. The working indicator lives inside this
889
+ bubble, and `opacity` is inherited by everything painted under it — so the
890
+ 0.6 that was meant to fade placeholder prose also faded the dots, which
891
+ already sat on `--text3` (#3a4a60). Two dims multiplied on the one element
892
+ whose entire job is to be seen: the composite was about #232c3a on a dark
893
+ surface, i.e. the spinner was effectively invisible (reported as "too
894
+ transparent"). A color dim cannot compound like that. */
879
895
  .msg.pending {
880
- opacity: 0.6;
896
+ color: var(--text2);
881
897
  }
882
898
 
883
899
  .typing-dots {
884
900
  display: inline-flex;
885
901
  align-items: center;
886
- gap: 5px;
902
+ gap: 6px;
887
903
  }
888
904
 
905
+ /* 8px and `--text2` at rest, not 6px and `--text3`: the pulse should read as
906
+ motion on top of a visible indicator, not as the indicator briefly
907
+ appearing out of nothing twice a second. */
889
908
  .typing-dots span {
890
- width: 6px;
891
- height: 6px;
909
+ width: 8px;
910
+ height: 8px;
892
911
  border-radius: 50%;
893
- background: var(--text3);
912
+ background: var(--text2);
894
913
  animation: typing-glow 1.2s ease-in-out infinite;
895
914
  }
896
915
 
@@ -910,15 +929,38 @@ body.memory-open {
910
929
  0%,
911
930
  60%,
912
931
  100% {
913
- background: var(--text3);
932
+ background: var(--text2);
914
933
  box-shadow: none;
934
+ transform: scale(1);
915
935
  }
916
936
  30% {
917
937
  background: var(--accent);
918
- box-shadow: 0 0 6px 1px var(--accent);
938
+ box-shadow: 0 0 9px 2px var(--accent);
939
+ transform: scale(1.25);
919
940
  }
920
941
  }
921
942
 
943
+ /* The live token figure, beside the spinner rather than only in the topbar.
944
+ Reported as "I don't see the tokens when AI is working": the rolling total
945
+ was already live, but it was 40ch away in the topbar and muted to `--text2`,
946
+ so it read as a settled readout. Here it is where the reader is already
947
+ looking, in the accent the pulse uses. */
948
+ .typing-tokens {
949
+ display: block;
950
+ margin-top: 8px;
951
+ font-family: var(--font-mono);
952
+ font-size: 11px;
953
+ color: var(--accent);
954
+ white-space: nowrap;
955
+ }
956
+
957
+ /* Same reason `.session-meter[hidden]` exists: the rule above sets a display,
958
+ which would otherwise win over the `hidden` attribute and leave an empty
959
+ accent line under every fresh turn. */
960
+ .typing-tokens[hidden] {
961
+ display: none;
962
+ }
963
+
922
964
  .who {
923
965
  font-size: 11px;
924
966
  font-weight: 600;
@@ -1483,6 +1525,38 @@ label {
1483
1525
  background: rgba(255, 255, 255, 0.03);
1484
1526
  }
1485
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
+
1486
1560
  .approval-title {
1487
1561
  font-family: var(--font-mono);
1488
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.
@@ -609,14 +676,23 @@ function usageCost(usage, model, opts = {}) {
609
676
  * @param {object|null|undefined} usage the response's `usage` object
610
677
  * @param {string} model the model id that answered
611
678
  * @param {{costUsd?: number}} [opts] the server-settled charge, if any
612
- * @returns {{tokens: number|null, cost: number|null, real: boolean, estimated: boolean}}
679
+ * @returns {{tokens: number|null, output: number|null, cost: number|null,
680
+ * real: boolean, estimated: boolean}}
613
681
  * `real` is true only when `cost` is the settled charge. `cost` is
614
682
  * `null` when nothing was reported and no model was named — an
615
683
  * unpriced turn must render as nothing, never as $0.0000.
684
+ * `tokens` is the wire's TOTAL (input + output) and is what the ledger
685
+ * and the rolling fold need; `output` is the half a person reads, and
686
+ * it is what every per-turn surface shows (see `displayTokens`).
616
687
  */
617
688
  function turnAccounting(usage, model, opts = {}) {
618
689
  const tokens = usageTokens(usage);
619
690
  const u = usage && typeof usage === 'object' ? usage : {};
691
+ // The half the turn PRODUCED. Kept beside the total rather than replacing it:
692
+ // `tokens` still has to fold the ledger, and a rebuild from stored buckets
693
+ // must agree with the live fold to the unit.
694
+ const output =
695
+ usage && typeof usage === 'object' ? usageBuckets(usage).output : null;
620
696
  // The settled charge can arrive either on the response or folded into the
621
697
  // usage object — the upstream engine does the latter
622
698
  // (`{ ...result.usage, costUsd: result.costUsd }`), so both are accepted.
@@ -628,15 +704,23 @@ function turnAccounting(usage, model, opts = {}) {
628
704
  // because a settled charge is a fact and a table match is a guess — and the
629
705
  // pool's bill carries a margin and a prompt-cache discount this table
630
706
  // cannot see, so the two must never be averaged or confused.
631
- return { tokens, cost: settled, real: true, estimated: false, basis: 'settled', priced: true };
707
+ return {
708
+ tokens, output, cost: settled, real: true, estimated: false, basis: 'settled', priced: true,
709
+ };
710
+ }
711
+ if (tokens == null) {
712
+ return {
713
+ tokens, output, cost: null, real: false, estimated: false, basis: null, priced: false,
714
+ };
632
715
  }
633
- if (tokens == null) return { tokens, cost: null, real: false, estimated: false, basis: null, priced: false };
634
716
  const b = costBreakdown(u, model, opts);
635
717
  // A model the table cannot place still yields a number (ratesFor never
636
718
  // returns nothing), so this is always an estimate — but `priced: false` says
637
719
  // the figure is a placeholder rather than this model's rate, so the caller
638
720
  // can label it instead of printing it as though it had been measured.
639
- return { tokens, cost: b.cost, real: false, estimated: true, basis: b.basis, priced: b.priced };
721
+ return {
722
+ tokens, output, cost: b.cost, real: false, estimated: true, basis: b.basis, priced: b.priced,
723
+ };
640
724
  }
641
725
 
642
726
  /**
@@ -648,7 +732,7 @@ function turnAccounting(usage, model, opts = {}) {
648
732
  * — `tokens`, `inputTokens`, `outputTokens`, `calls` — and what the user reads
649
733
  * back is that RUNNING TOTAL. The status bar prints `state.tokens`
650
734
  * (renderStatus), and `ctrl+t` prints the tallies in one line
651
- * (`tokenSummary`: `12,400 tok (10,100 in / 2,300 out) · 4 calls · €0.03`).
735
+ * (`tokenSummary`: `12,400 tokens (10,100 in / 2,300 out) · 4 calls · €0.03`).
652
736
  * The tallies are reproduced; that one abbreviation is not — `fmtRoll` explains
653
737
  * why it drops the parenthetical rather than carrying the CLI's line verbatim.
654
738
  *
@@ -869,36 +953,104 @@ function fmtTokens(n) {
869
953
  .replace(/\B(?=(\d{3})+(?!\d))/g, ',');
870
954
  }
871
955
 
956
+ /**
957
+ * The token figure a person is SHOWN for a finished turn or a session roll.
958
+ *
959
+ * One authority, because there are two shapes that reach it and they had
960
+ * drifted apart: `turnAccounting` (a single dispatch, `{tokens, output}`) and
961
+ * `emptyRoll`/`rollTurn` (a session tally, same two fields). Every per-turn row
962
+ * and the topbar both route through here, so no surface can print a different
963
+ * quantity than another.
964
+ *
965
+ * What it returns is the OUTPUT — what the turn produced. The wire's total is
966
+ * input + output, and on any cached or long-context turn the input half
967
+ * dominates it: a 3,145-token call whose prompt was 3,000 tokens is a turn that
968
+ * wrote 145. Showing 3,145 beside a `session:` line that also reads 3,145 told
969
+ * the reader the model had emitted ten times what it did, and there is no way
970
+ * to tell from the row which of the two numbers is the prompt restated. The
971
+ * CLI settled this the same way (`fmtUsageSplit`, cli/src/format.js): the figure
972
+ * is the output, and the input half is not shown unlabelled beside it.
973
+ *
974
+ * It does NOT fall back to the total. Fall back to `tokens` and the input half
975
+ * is back on the screen with no label: a wire that priced a turn but did not
976
+ * itemise it would print `3,145` for a turn that wrote 145. Returns `null`
977
+ * rather than `0` in that case — `0 tokens` is a figure no provider sent,
978
+ * and this file refuses that fabrication everywhere else (`fmtRoll`).
979
+ *
980
+ * @param {{tokens?: number|null, output?: number|null}} [source]
981
+ * @returns {number|null}
982
+ */
983
+ function displayTokens(source) {
984
+ if (!source || typeof source !== 'object') return null;
985
+ // The half the turn PRODUCED, from either shape this file is handed: an
986
+ // accounting or roll record (`output`), or a stored token bucket
987
+ // (`tokens: {output}` — what `rollMessages` reads back out of the shared
988
+ // store, and what a rebuilt session presents).
989
+ const nested = source.tokens;
990
+ const candidates = [source.output];
991
+ if (nested && typeof nested === 'object') {
992
+ candidates.push(nested.output, nested.output_tokens, nested.completion_tokens);
993
+ } else {
994
+ candidates.push(source.output_tokens, source.completion_tokens);
995
+ }
996
+ for (const c of candidates) {
997
+ if (typeof c === 'number' && isFinite(c) && c > 0) return c;
998
+ }
999
+ // The wire's TOTAL is deliberately NOT a fallback here. `tokens` is
1000
+ // input + output, and on a cached turn the input half is the larger one, so
1001
+ // falling back to it put back the exact reading this rule exists to remove:
1002
+ // `tokens: 3,145` on a turn that wrote 145. This was the last surviving
1003
+ // place the input half reached the screen — the split had been dropped, and
1004
+ // the total it fell back to still carried it.
1005
+ //
1006
+ // Stated once more, because it is the whole point: a turn the wire priced but
1007
+ // did not itemise has NO output figure, and inventing one from the total
1008
+ // would be a number no provider sent. That turn's row states its own text
1009
+ // estimate instead (`~N tokens`), which is at least a figure about what was
1010
+ // written.
1011
+ return null;
1012
+ }
1013
+
872
1014
  /**
873
1015
  * The rolling session total as one line — the desktop's counterpart of the
874
1016
  * CLI's `tokenSummary`. Empty string when nothing has been accounted for, so
875
1017
  * an untouched session adds no noise to a turn's meta line.
876
1018
  *
877
1019
  * @param {object} [roll]
878
- * @returns {string} e.g. `12,400 tok · 4 calls · $0.0310` — the CLI's fields in
879
- * the CLI's order, minus the input/output parenthetical (see below).
1020
+ * @returns {string} e.g. `2,300 tokens · 4 calls · $0.0310` — the CLI's fields in
1021
+ * the CLI's order, minus the input/output parenthetical (see below). The
1022
+ * figure is the OUTPUT (see `displayTokens`).
880
1023
  */
881
- function fmtRoll(roll) {
1024
+ function fmtRoll(roll, opts = {}) {
882
1025
  const r = roll || emptyRoll();
883
1026
  if (!r.turns && !r.calls) return '';
884
1027
  // The fields are `tokenSummary`'s (cli/src/app.js:1413) in its order — tokens,
885
1028
  // calls, money — with one dropped: the `(10,100 in / 2,300 out)` split. `in`
886
1029
  // and `out` are a terminal status-line shorthand, legible to someone already
887
1030
  // reading that status line and to nobody else, which is what an unlabelled
888
- // abbreviation in a GUI topbar turns into. The total is the figure a reader
889
- // wants; `r.input`/`r.output` are still folded onto the roll (see `rollTurn`)
890
- // for any surface that wants to show the split with real labels. The call
891
- // count stays unconditional, because it is the number that reveals a
892
- // fan-out, and it is not hidden at 1.
1031
+ // abbreviation in a GUI topbar turns into.
1032
+ //
1033
+ // …and the figure that remains is the OUTPUT, not the wire's total. This line
1034
+ // used to print `r.tokens`, which is input + output: on a cached turn the
1035
+ // prompt restated is the larger half, so a session that wrote 2,300 tokens on
1036
+ // a 10,100-token prompt read `12,400 tokens` and looked like a model emitting
1037
+ // five times what it did. The parenthetical was not the only place the input
1038
+ // half showed up — it was in the total too, and dropping the split alone left
1039
+ // the reader comparing two numbers that were both mostly their own prompt.
1040
+ // `displayTokens` holds the rule, the same one the CLI's `fmtUsageSplit` uses.
1041
+ // `r.input` is still folded onto the roll (see `rollTurn`) for any surface
1042
+ // that wants to show the split with real labels.
893
1043
  const bits = [];
894
1044
  // The token half only when something was actually counted. `rollTurn` counts
895
1045
  // turns and calls BEFORE it looks at the token count, so a dispatch that
896
- // reported nothing still reaches here — and printing its empty tally would
897
- // put `0 tok` on the topbar, a figure the meter never took, which reads as a
898
- // counter that does not move. The turn count is still stated, because that
899
- // much is true.
900
- if (r.tokens > 0) {
901
- bits.push(`${fmtTokens(r.tokens)} tok`);
1046
+ // reported nothing still reaches here — and printing an empty tally would put
1047
+ // `0 tokens` on the topbar, a figure the meter never took, which reads as a
1048
+ // counter that does not move. `displayTokens` returns null rather than 0 for
1049
+ // exactly that case, and falls back to the total only when no split arrived.
1050
+ // The turn count is still stated, because that much is true.
1051
+ const produced = displayTokens(r);
1052
+ if (produced != null) {
1053
+ bits.push(`${fmtTokens(produced)} tokens`);
902
1054
  }
903
1055
  bits.push(`${r.calls} call${r.calls === 1 ? '' : 's'}`);
904
1056
  // Money is where this line departs from `tokenSummary`, deliberately: that
@@ -906,7 +1058,10 @@ function fmtRoll(roll) {
906
1058
  // a settled charge and a local estimate apart so a `~`-estimate can never be
907
1059
  // read as part of the bill. Desktop's pre-existing fmtCost renders both, and
908
1060
  // its `$` convention is left exactly as it was.
909
- if (r.cost > 0 || r.estimate > 0) {
1061
+ // Money is omitted entirely on a tier AEGIS does not bill a fee to
1062
+ // (`opts.omitMoney` — see `feeWaived`). Not zeroed, not marked `~`: a `$0.0000`
1063
+ // states a price, and this account has no price on this turn.
1064
+ if (!opts.omitMoney && (r.cost > 0 || r.estimate > 0)) {
910
1065
  const money = [];
911
1066
  if (r.cost > 0) money.push(fmtCost(r.cost, true));
912
1067
  if (r.estimate > 0) money.push(fmtCost(r.estimate, false));
@@ -935,11 +1090,108 @@ function fmtRoll(roll) {
935
1090
  */
936
1091
  function fmtCost(cost, real) {
937
1092
  if (typeof cost !== 'number' || !isFinite(cost)) return '';
1093
+ // The `$` is not decoration: its loss was a regression, not a decision.
1094
+ // `4d5d1e9` introduced this function with it (`~$18.0000`); `6d48470` — a
1095
+ // commit about the token TOTAL, unrelated to money — dropped it as a stray
1096
+ // hunk. Every desktop turn row then painted a bare `18.0000`, a number with no
1097
+ // currency on it, where the CLI paints `€0.03` for the same figure.
938
1098
  return `${real ? '' : '~'}$${cost.toFixed(4)}`;
939
1099
  }
940
1100
 
1101
+ /**
1102
+ * True when this account's tier means AEGIS bills no per-turn fee, so no money
1103
+ * figure belongs on a turn row or a session roll.
1104
+ *
1105
+ * The fee in question is the BYOK handling fee — the only charge AEGIS adds on
1106
+ * top of a caller's own provider bill — and aegis1 waives it on Unlimited:
1107
+ * `lib/local/entitlement.js` states the rule in as many words ("the throughput
1108
+ * allowance and the BYOK fee waiver are `is_unlimited()`-gated"), and the tier
1109
+ * a welcome trial grants IS Unlimited (a 30-day `unlimited` row in
1110
+ * `subscriptions`, which `register_device` writes in the same request that mints
1111
+ * the key). So a trial account resolves here exactly like a paying one, which is
1112
+ * what "trial unlimited" means — the trial is not a separate tier with its own
1113
+ * money rule, it is Unlimited for 30 days.
1114
+ *
1115
+ * Matching is on the resolved tier rather than `pro`: `pro` is "the PLAN is paid
1116
+ * for" and is also true of the €9 tier's aliases, while the waiver is gated on
1117
+ * `unlimited` specifically. A funded bank on a free plan is not a tier at all
1118
+ * (`entitlement.js` refuses to name one) and is therefore NOT waived — that
1119
+ * account pays the fee from the bank, and hiding the number would leave it with
1120
+ * no meter for the only money it spends.
1121
+ *
1122
+ * @param {{tier?: string|null, plan?: string|null, planRaw?: string|null}} [entitlement]
1123
+ * @returns {boolean}
1124
+ */
1125
+ function feeWaived(entitlement) {
1126
+ if (!entitlement || typeof entitlement !== 'object') return false;
1127
+ const named = [
1128
+ entitlement.tier,
1129
+ entitlement.plan,
1130
+ entitlement.planRaw,
1131
+ entitlement.subscription,
1132
+ entitlement.subscriptionTier,
1133
+ entitlement.product,
1134
+ // The server's own two fields, as `register_device` writes them: a welcome
1135
+ // trial is a 30-day `unlimited` row in `subscriptions`, and `item`/`sku` is
1136
+ // that row's product name. Naming them here is what keeps a trial account
1137
+ // from resolving to "no tier" and being billed a fee it does not owe.
1138
+ entitlement.item,
1139
+ entitlement.sku,
1140
+ ]
1141
+ .filter((v) => typeof v === 'string')
1142
+ .map((v) => v.trim().toLowerCase());
1143
+ // An explicit boolean outranks every spelling below: aegis1's `is_unlimited()`
1144
+ // verdict is the fact, and the strings are only what it is written as on the
1145
+ // wire. A probe that answers with the bit and not the tier is still an answer.
1146
+ if (entitlement.unlimited === true) return true;
1147
+ if (named.some((v) => v === 'unlimited' || v === 'trial')) return true;
1148
+ // A tier string that merely CONTAINS the word — `unlimited_trial`,
1149
+ // `plan.unlimited`, `Unlimited (trial)` — so a server that decorates the name
1150
+ // cannot put the fee back on an account whose tier is Unlimited.
1151
+ return named.some((v) => /(^|[^a-z])unlimited([^a-z]|$)/.test(v));
1152
+ }
1153
+
1154
+ /**
1155
+ * Whether a money figure belongs on this account's turn row or session roll.
1156
+ *
1157
+ * The CLI's exact rule (`cli/src/format.js` → `feeBillable`), and it is the same
1158
+ * rule on purpose — the two hosts render the same turn from the same engine, so
1159
+ * a row that shows a fee on one and waives it on the other is a disagreement
1160
+ * about what the user owes.
1161
+ *
1162
+ * A price is printed UNLESS AEGIS either waives it or has not proven it owed:
1163
+ *
1164
+ * - a tier AEGIS waives (`feeWaived`) → no price. Unlimited, paid or on the
1165
+ * 30-day welcome trial, has no per-turn charge and no bank draw;
1166
+ * - a snapshot asserting a plan it cannot prove (`degraded`) → no price. The
1167
+ * entitlement module STARTS at exactly that: `makeFreeSnapshot()` reads
1168
+ * `plan: 'free'`, `tier: null`, `source: 'unresolved'`, `degraded: true`,
1169
+ * which says "no verdict yet", not "this account is free". Reading the
1170
+ * placeholder as a verdict is what put `~$0.0005` and an "AEGIS handling fee"
1171
+ * line on the turns of trial accounts whose probe had not answered — a fee
1172
+ * charged in writing to the one account that does not pay it;
1173
+ * - everything else → the price stands, including when no snapshot exists at
1174
+ * all. A cost figure is a measurement of the turn, and dropping a real number
1175
+ * because no tier was published would leave a self-hosted or BYO-key run with
1176
+ * no meter for money it actually spent.
1177
+ *
1178
+ * The token figure is never gated by this, on any branch: what a turn produced
1179
+ * is not a price, and hiding it would leave an Unlimited account with no meter.
1180
+ *
1181
+ * @param {{tier?: string|null, plan?: string|null, planRaw?: string|null,
1182
+ * degraded?: boolean, source?: string|null, unlimited?: boolean}} [entitlement]
1183
+ * @returns {boolean}
1184
+ */
1185
+ function feeBillable(entitlement) {
1186
+ if (!entitlement || typeof entitlement !== 'object') return true;
1187
+ if (feeWaived(entitlement)) return false;
1188
+ return entitlement.degraded !== true;
1189
+ }
1190
+
941
1191
  if (typeof module !== 'undefined' && module.exports) {
942
1192
  module.exports = {
1193
+ feeWaived,
1194
+ feeBillable,
943
1195
  RATES,
944
1196
  RATE_BASIS,
945
1197
  UNPRICED_BY_DESIGN,
@@ -951,6 +1203,7 @@ if (typeof module !== 'undefined' && module.exports) {
951
1203
  usageCost,
952
1204
  costBreakdown,
953
1205
  turnAccounting,
1206
+ displayTokens,
954
1207
  estimateTokens,
955
1208
  estimatedBuckets,
956
1209
  emptyRoll,
@@ -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,