@clagentic/console 1.8.0 → 1.9.0-beta.2

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 (64) hide show
  1. package/bin/cli.js +12 -1
  2. package/lib/agents.js +13 -3
  3. package/lib/build-sha.json +2 -2
  4. package/lib/cli/ipc-subcommands.js +40 -4
  5. package/lib/daemon.js +25 -1
  6. package/lib/generated/claude-model-catalog.json +180 -0
  7. package/lib/model-catalog.js +202 -0
  8. package/lib/model-families.js +243 -0
  9. package/lib/project-connection.js +30 -5
  10. package/lib/project-loop.js +46 -2
  11. package/lib/project-sessions.js +133 -21
  12. package/lib/project-user-message.js +70 -3
  13. package/lib/project.js +11 -1
  14. package/lib/public/app.js +14 -4
  15. package/lib/public/css/base.css +14 -0
  16. package/lib/public/css/home-hub.css +28 -8
  17. package/lib/public/css/icon-strip.css +17 -0
  18. package/lib/public/css/menus.css +67 -0
  19. package/lib/public/css/messages.css +11 -0
  20. package/lib/public/css/mobile-nav.css +22 -0
  21. package/lib/public/css/server-settings.css +72 -0
  22. package/lib/public/css/sidebar.css +15 -0
  23. package/lib/public/css/title-bar.css +10 -1
  24. package/lib/public/index.html +4 -0
  25. package/lib/public/modules/activity-latch.js +159 -0
  26. package/lib/public/modules/activity-state.js +157 -0
  27. package/lib/public/modules/app-connection.js +10 -4
  28. package/lib/public/modules/app-favicon.js +88 -1
  29. package/lib/public/modules/app-home-hub.js +14 -11
  30. package/lib/public/modules/app-loop-ui.js +90 -2
  31. package/lib/public/modules/app-messages.js +117 -28
  32. package/lib/public/modules/app-panels.js +184 -56
  33. package/lib/public/modules/app-projects.js +28 -8
  34. package/lib/public/modules/app-rate-limit.js +14 -2
  35. package/lib/public/modules/model-families.js +230 -0
  36. package/lib/public/modules/project-settings.js +1 -0
  37. package/lib/public/modules/scheduler.js +5 -0
  38. package/lib/public/modules/server-settings.js +14 -12
  39. package/lib/public/modules/settings-defaults.js +151 -41
  40. package/lib/public/modules/sidebar-mobile.js +32 -22
  41. package/lib/public/modules/sidebar-projects.js +42 -14
  42. package/lib/public/modules/sidebar-sessions.js +168 -48
  43. package/lib/public/modules/tools.js +22 -12
  44. package/lib/sdk-bridge.js +389 -35
  45. package/lib/sdk-message-processor.js +215 -7
  46. package/lib/sdk-skill-discovery.js +46 -6
  47. package/lib/sdk-slash-enrichment.js +5 -2
  48. package/lib/server-hub-sessions.js +70 -0
  49. package/lib/server.js +79 -22
  50. package/lib/session-activity.js +289 -0
  51. package/lib/sessions.js +104 -3
  52. package/lib/smtp.js +10 -1
  53. package/lib/terminal-manager.js +40 -0
  54. package/lib/utils.js +44 -0
  55. package/lib/ws-schema.js +17 -0
  56. package/lib/yoke/adapters/claude-worker.js +6 -2
  57. package/lib/yoke/adapters/claude.js +384 -88
  58. package/lib/yoke/adapters/codex.js +239 -31
  59. package/package.json +2 -2
  60. package/scripts/check-test-count.js +397 -0
  61. package/scripts/generate-model-catalog.js +337 -0
  62. package/scripts/test-file-completion-reporter.js +43 -0
  63. package/lib/model-context-windows.js +0 -65
  64. package/lib/public/modules/model-context-windows.js +0 -62
@@ -53,7 +53,7 @@ import { handleLoopRegistryUpdated, handleScheduleRunStarted, handleScheduleRunF
53
53
 
54
54
  // --- App module imports ---
55
55
  import { scrollToBottom, addToMessages, addUserMessage, addSystemMessage, appendDelta, finalizeAssistantBlock, addConflictMessage, addContextOverflowMessage, showSuggestionChips, removePreThinking } from './app-rendering.js';
56
- import { setActivity, startUrgentBlink, stopUrgentBlink, blinkSessionDot, updateCrossProjectBlink } from './app-favicon.js';
56
+ import { startUrgentBlink, stopUrgentBlink, blinkSessionDot, updateCrossProjectBlink } from './app-favicon.js';
57
57
  import { setStatus } from './app-connection.js';
58
58
  import { getModelEffortLevels, accumulateUsage, setSessionUsage, updateUsagePanel, accumulateContext, updateContextPanel, renderCtxPopover, updateStatusPanel } from './app-panels.js';
59
59
  import { updateProjectList, resetClientState, showUpdateAvailable, handleRemoveProjectCheckResult, handleRemoveProjectResult, handleBrowseDirResult, handleAddProjectResult, handleCloneProgress } from './app-projects.js';
@@ -69,6 +69,7 @@ import { handleMentionStart, handleMentionActivity, handleMentionStream, handleM
69
69
  import { handleTeamState, handleTeamMemberUpdate, handleTeamTaskUpdate, handleTeamMessage as handleTeamMsg, handleTeamGone } from './team-panel.js';
70
70
  import { addDiagnostic } from './diagnostics.js';
71
71
  import { handleHistoryMeta, handleHistoryDone } from './app-history-replay.js';
72
+ import { shouldApplyActivityEdge, recordActivityEdgeDecision } from './activity-latch.js';
72
73
 
73
74
  // --- DOM refs (cached once, stable for page lifetime) ---
74
75
  var messagesEl = document.getElementById("messages");
@@ -442,7 +443,25 @@ registerHandlers({
442
443
  } else if (_prevSid) {
443
444
  delete store.get('sessionDrafts')[_prevSid];
444
445
  }
446
+ // Reconcile the footer's edge-latch field from the server-authoritative
447
+ // snapshot on every session switch/hydration, not only
448
+ // sessionIsProcessing. 'processing' (the field app-favicon.js's
449
+ // initActivityFooter subscribes to) was a pure client-local edge latch
450
+ // with no reconciliation path — missing a single 1->0 done edge (e.g. a
451
+ // cross-session race, see the session-scoping fix in the status/done/
452
+ // auth_required handlers below) left it stuck true forever.
453
+ // session_switched now always carries msg.isProcessing
454
+ // (project-connection.js's hydration path previously omitted it —
455
+ // sessions.js's own switchSession() send already had it).
445
456
  store.set({ activeSessionId: msg.id, cliSessionId: msg.cliSessionId || null, vendorCapabilities: msg.capabilities || {}, sessionIsProcessing: !!msg.isProcessing });
457
+ // Re-derive 'processing' from the store field just set above
458
+ // (sessionIsProcessing), NOT from a second raw msg.isProcessing read —
459
+ // this file's CI invariant test locks .isProcessing reads to exactly
460
+ // the one documented site immediately above, so every switch/reconnect/
461
+ // hydration re-derives 'processing' from that already-read,
462
+ // already-reconciled value instead of trusting whatever the
463
+ // client-local latch happened to be left at.
464
+ store.set({ processing: store.get('sessionIsProcessing') });
446
465
  if (msg.vendor) {
447
466
  if (!store.get('vendorSelectionLocked') || msg.hasHistory) {
448
467
  store.set({ currentVendor: msg.vendor });
@@ -605,26 +624,48 @@ registerHandlers({
605
624
  },
606
625
 
607
626
  status: function (msg) {
627
+ // Session-scope this edge write, mirroring the lr-0827ba pattern
628
+ // already used by scheduled_message_*/other handlers (msg.localId ==
629
+ // null || msg.localId === activeSessionId). This handler previously
630
+ // raised the global 'processing' latch for ANY session's
631
+ // status:"processing", including one the client is not currently
632
+ // focused on — a background session's edge could raise the FOCUSED
633
+ // session's dot with no done ever routed back to clear it. msg.localId
634
+ // is now always populated server-side (see sessions.js
635
+ // stampActivityLocalId / project.js sendToSession); a missing localId
636
+ // (e.g. an older server) falls back to applying the edge
637
+ // unconditionally, same as before this fix.
608
638
  if (msg.status === "processing") {
609
- setStatus("processing");
610
- // Session became live — undo any dead-session todo compaction
611
- // applied at history_done time.
612
- store.set({ sessionIsProcessing: true });
613
- applyDeadSessionTodoCompaction();
614
- if (!store.get('dmMode')) {
615
- removePreThinking(); // drop pre-thinking dots before showing activity indicator
616
- setActivity("thinking");
639
+ var _statusActiveSid = store.get('activeSessionId');
640
+ var _statusEdgeAccepted = shouldApplyActivityEdge(msg.localId, _statusActiveSid);
641
+ // lr-58c813: ledger this edge's outcome for observability only — the
642
+ // decision below (same _statusEdgeAccepted value) is unchanged.
643
+ recordActivityEdgeDecision("status", msg.localId, _statusActiveSid, _statusEdgeAccepted);
644
+ if (_statusEdgeAccepted) {
645
+ setStatus("processing");
646
+ // Session became live — undo any dead-session todo compaction
647
+ // applied at history_done time.
648
+ store.set({ sessionIsProcessing: true });
649
+ applyDeadSessionTodoCompaction();
650
+ if (!store.get('dmMode')) {
651
+ removePreThinking(); // drop pre-thinking dots before showing activity indicator
652
+ }
617
653
  }
618
654
  }
619
655
  },
620
656
 
621
- compacting: function (msg) {
622
- if (msg.active) {
623
- setActivity("compacting");
624
- } else if (!store.get('dmMode')) {
625
- setActivity("thinking");
626
- }
627
- },
657
+ // lr-66c118: setActivity("thinking"/"compacting") re-raise removed here.
658
+ // setActivity collapses to ONE optimistic raise (input.js, on send) — the
659
+ // widget's job is to bridge the gap before the FIRST real server signal
660
+ // arrives; once real streaming UI exists (thinking block, tool items,
661
+ // delta text) that IS the activity indicator, so re-raising the bubble
662
+ // widget mid-turn only risked stacking it on top of the real UI.
663
+ // lr-3af675: the context meter itself no longer needs anything here either
664
+ // — the server re-reads vendor usage on the compacting -> not-compacting
665
+ // transition and pushes a fresh 'context_usage' message (see the 'status'
666
+ // handler in sdk-message-processor.js), which the context_usage handler
667
+ // below already applies to the meter.
668
+ compacting: function (msg) {},
628
669
 
629
670
  thinking_start: function (msg) {
630
671
  removePreThinking();
@@ -637,9 +678,6 @@ registerHandlers({
637
678
 
638
679
  thinking_stop: function (msg) {
639
680
  stopThinking(msg.duration);
640
- if (!store.get('dmMode')) {
641
- setActivity("thinking");
642
- }
643
681
  },
644
682
 
645
683
  delta: function (msg) {
@@ -647,7 +685,12 @@ registerHandlers({
647
685
  removePreThinking();
648
686
  stopThinking();
649
687
  resetThinkingGroup();
650
- setActivity(null);
688
+ // lr-66c118: the setActivity clear-call removed here (was gated on
689
+ // hasActiveSubagents() per lr-1317b8 Defect 2 — that gate is now moot,
690
+ // there is nothing left to clear here). setActivity collapses to ONE
691
+ // optimistic raise (input.js); real streaming text arriving is itself
692
+ // the strongest possible "not idle" signal, so there is no risk of a
693
+ // stuck indicator from removing this clear.
651
694
  appendDelta(msg.text);
652
695
  },
653
696
 
@@ -799,7 +842,11 @@ registerHandlers({
799
842
  },
800
843
 
801
844
  result: function (msg) {
802
- setActivity(null);
845
+ // lr-66c118: the lr-255e hasActiveSubagents()-gated setActivity clear
846
+ // call is removed — setActivity collapses to ONE optimistic raise
847
+ // (input.js) with no manual clears anywhere. The subagent-liveness
848
+ // tracking itself (activeSubagentToolIds, markSubagentDone) is untouched
849
+ // and still governs the real per-tool subagent UI.
803
850
  stopThinking();
804
851
  markAllToolsDone();
805
852
  closeToolGroup();
@@ -816,14 +863,30 @@ registerHandlers({
816
863
  }
817
864
  },
818
865
 
866
+ // Only setStatus("connected") below is session-scoped — a done for a
867
+ // BACKGROUND session must not clear the FOCUSED session's 'processing'
868
+ // latch (see activity-latch.js's header comment for the full rationale).
869
+ // Every other cleanup call in this handler stays unconditional: it
870
+ // targets DOM/tool state for whatever session this client's own WS
871
+ // connection is bound to server-side (ws._clayActiveSession), so it is
872
+ // never cross-session — only the store-wide latch write needs the guard.
819
873
  done: function (msg) {
820
874
  removePreThinking();
821
- setActivity(null);
875
+ // lr-66c118: the setActivity clear call is removed here too — see the
876
+ // 'result' handler above. resetToolState() below still clears all
877
+ // per-turn tool tracking (including subagent liveness) unconditionally.
822
878
  stopThinking();
823
879
  markAllToolsDone();
824
880
  closeToolGroup();
825
881
  finalizeAssistantBlock();
826
- setStatus("connected");
882
+ var _doneActiveSid = store.get('activeSessionId');
883
+ var _doneEdgeAccepted = shouldApplyActivityEdge(msg.localId, _doneActiveSid);
884
+ // lr-58c813: ledger this edge's outcome for observability only — the
885
+ // decision below (same _doneEdgeAccepted value) is unchanged.
886
+ recordActivityEdgeDecision("done", msg.localId, _doneActiveSid, _doneEdgeAccepted);
887
+ if (_doneEdgeAccepted) {
888
+ setStatus("connected");
889
+ }
827
890
  // Re-enable input unless this is one of the loop's own sessions (coder/judge).
828
891
  // A loop running in a separate session must not suppress input here.
829
892
  var _doneLoopSid = store.get('loopCurrentSessionId');
@@ -842,9 +905,11 @@ registerHandlers({
842
905
  addSystemMessage(msg.text, false);
843
906
  },
844
907
 
908
+ // lr-66c118: setActivity clear calls removed below (error,
909
+ // process_conflict, context_overflow, auth_required) — setActivity
910
+ // collapses to ONE optimistic raise (input.js) with no manual clears.
845
911
  error: function (msg) {
846
912
  removePreThinking();
847
- setActivity(null);
848
913
  addSystemMessage(msg.text, true);
849
914
  },
850
915
 
@@ -858,24 +923,31 @@ registerHandlers({
858
923
 
859
924
  process_conflict: function (msg) {
860
925
  removePreThinking();
861
- setActivity(null);
862
926
  addConflictMessage(msg);
863
927
  },
864
928
 
865
929
  context_overflow: function (msg) {
866
930
  removePreThinking();
867
- setActivity(null);
868
931
  addContextOverflowMessage(msg);
869
932
  },
870
933
 
871
934
  auth_required: function (msg) {
872
935
  removePreThinking();
873
- setActivity(null);
874
936
  stopThinking();
875
937
  markAllToolsDone();
876
938
  closeToolGroup();
877
939
  appendDelta((msg.text || "Authentication required.") + "\n");
878
- setStatus("connected");
940
+ // Same session-scoping as the done handler above — a background
941
+ // session's auth_required must not clear the focused session's
942
+ // 'processing' latch.
943
+ var _authActiveSid = store.get('activeSessionId');
944
+ var _authEdgeAccepted = shouldApplyActivityEdge(msg.localId, _authActiveSid);
945
+ // lr-58c813: ledger this edge's outcome for observability only — the
946
+ // decision below (same _authEdgeAccepted value) is unchanged.
947
+ recordActivityEdgeDecision("auth_required", msg.localId, _authActiveSid, _authEdgeAccepted);
948
+ if (_authEdgeAccepted) {
949
+ setStatus("connected");
950
+ }
879
951
  var _authLoopSid = store.get('loopCurrentSessionId');
880
952
  if (!store.get('loopActive') || !_authLoopSid || store.get('activeSessionId') !== _authLoopSid) {
881
953
  enableMainInput();
@@ -1215,6 +1287,20 @@ registerHandlers({
1215
1287
  // loop's own session — updateLoopInputVisibility() already switched
1216
1288
  // it into queue mode so a human message is queued for the next
1217
1289
  // iteration boundary rather than dropped or blocked outright.
1290
+ //
1291
+ // lr-fd38ac follow-up: loopCurrentSessionId (set just above) is what
1292
+ // makes updateLoopInputVisibility()'s gate condition
1293
+ // (loopCurrentSessionId === activeSessionId) newly true when a
1294
+ // client is already viewing the loop's new session — the
1295
+ // session_switched broadcast that forced every client onto this
1296
+ // session fired earlier with loop: null (session.loop is assigned
1297
+ // server-side only after createSession() returns; see
1298
+ // project-loop.js runNextIteration()), so that call armed nothing.
1299
+ // The re-invocation itself lives in app-loop-ui.js's reactive
1300
+ // store.subscribe(), keyed on loopActive/loopCurrentSessionId, so
1301
+ // every writer of those two fields (this handler, loop_judging,
1302
+ // loop_finished) gets the re-check for free instead of each call
1303
+ // site having to remember to do it.
1218
1304
  },
1219
1305
 
1220
1306
  loop_judging: function (msg) {
@@ -1223,6 +1309,9 @@ registerHandlers({
1223
1309
  updateLoopBanner(_ljs.loopIteration, _ljs.loopMaxIterations, "judging");
1224
1310
  addSystemMessage("Judging iteration #" + msg.iteration + "...", false);
1225
1311
  // lr-e31b: composer stays enabled in queue mode (see loop_iteration above).
1312
+ // lr-fd38ac follow-up: same re-arm requirement as loop_iteration —
1313
+ // loopCurrentSessionId changes to the judge session here, and the
1314
+ // reactive subscriber in app-loop-ui.js re-checks the gate.
1226
1315
  },
1227
1316
 
1228
1317
  loop_verdict: function (msg) {
@@ -6,13 +6,14 @@ import { escapeHtml, showToast } from "./utils.js";
6
6
  import { store } from './store.js';
7
7
  import { getWs } from './ws-ref.js';
8
8
  import { VENDOR_NAMES } from './app-rendering.js';
9
- import { KNOWN_CONTEXT_WINDOWS, resolveModelContextWindow as _resolveModelContextWindowCore } from './model-context-windows.js';
9
+ import { splitModelsByTier } from './settings-defaults.js';
10
+ import { isSonnetModel } from './model-families.js';
10
11
 
11
12
  // --- Module-owned state (not in store) ---
12
13
  // sessionUsage.context = last-turn context fill (lastStreamInputTokens) — not cumulative,
13
14
  // just the most recent value. Correct for display without any accumulation issues.
14
15
  var sessionUsage = { cost: 0, context: 0, output: 0, cacheWrite: 0, turns: 0 };
15
- var contextData = { contextWindow: 0, maxOutputTokens: 0, model: "-", cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, turns: 0 };
16
+ var contextData = { contextWindow: 0, maxOutputTokens: 0, model: "-", cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoningOutput: 0, turns: 0 };
16
17
  var ctxPopoverEl = null;
17
18
  var ctxHoverTimer = null;
18
19
  var statusRefreshTimer = null;
@@ -75,6 +76,7 @@ var contextCacheWriteEl = null;
75
76
  var contextModelEl = null;
76
77
  var contextCostEl = null;
77
78
  var contextTurnsEl = null;
79
+ var contextReasoningEl = null;
78
80
  var contextMini = null;
79
81
  var contextMiniFill = null;
80
82
  var contextMiniLabel = null;
@@ -107,7 +109,6 @@ var CODEX_WEBSEARCH_OPTIONS = [
107
109
  { value: "cached", label: "Cached" },
108
110
  { value: "live", label: "Live" },
109
111
  ];
110
- // KNOWN_CONTEXT_WINDOWS imported from ./model-context-windows.js (lr-336f shared source of truth)
111
112
  // Categories to hide from the legend (noise, not actionable)
112
113
  var CTX_HIDDEN_CATS = { "Free space": 1, "Autocompact buffer": 1 };
113
114
 
@@ -153,11 +154,9 @@ function thinkingDisplayName(value) {
153
154
  return value || "Adaptive";
154
155
  }
155
156
 
156
- function isSonnetModel(model) {
157
- if (!model) return false;
158
- var lower = model.toLowerCase();
159
- return lower.indexOf("sonnet") !== -1;
160
- }
157
+ // isSonnetModel imported from ./model-families.js (lr-d91ecf) — the single
158
+ // shared family-detection module; this file used to carry its own private
159
+ // copy of the same substring check.
161
160
 
162
161
  function hasBeta(name) {
163
162
  var betas = store.get('currentBetas');
@@ -167,32 +166,101 @@ function hasBeta(name) {
167
166
  return false;
168
167
  }
169
168
 
169
+ // Build one .config-radio-item button for a model entry (string or rich object).
170
+ function buildConfigModelItem(item, currentModel) {
171
+ // Support both object { value, displayName } and plain string formats
172
+ var value = typeof item === "string" ? item : (item.value || "");
173
+ var label = typeof item === "string" ? item : (item.displayName || value);
174
+ // lr-d3817f: retired entries are filtered out upstream (model-catalog.js's
175
+ // filterSelectableCatalogModels) and never reach this function — no
176
+ // disabled/retired-badge rendering here anymore. Deprecated (still-
177
+ // runnable) entries still get a marker.
178
+ var isDeprecated = !!(item && typeof item === "object" && item.isDeprecated);
179
+ var btn = document.createElement("button");
180
+ btn.className = "config-radio-item";
181
+ if (value === currentModel) btn.classList.add("active");
182
+ btn.dataset.model = value;
183
+ btn.textContent = label;
184
+ // lr-f22787: same non-blocking "Catalog" marker as the settings picker
185
+ // (settings-defaults.js buildModelItem) for entries sourced from the
186
+ // release-time-generated catalog rather than the vendor's live list.
187
+ if (item && typeof item === "object" && item.fromCatalog) {
188
+ var catalogBadge = document.createElement("span");
189
+ catalogBadge.className = "config-model-catalog-badge";
190
+ catalogBadge.textContent = " (Catalog)";
191
+ btn.appendChild(catalogBadge);
192
+ }
193
+ if (isDeprecated) {
194
+ var deprecatedBadge = document.createElement("span");
195
+ deprecatedBadge.className = "config-model-deprecated-badge";
196
+ deprecatedBadge.textContent = " (Deprecated)";
197
+ btn.appendChild(deprecatedBadge);
198
+ }
199
+ btn.addEventListener("click", function () {
200
+ var model = this.dataset.model;
201
+ sendSetModel(model);
202
+ });
203
+ return btn;
204
+ }
205
+
206
+ function sendSetModel(model) {
207
+ var ws = getWs();
208
+ if (ws && ws.readyState === 1) {
209
+ ws.send(JSON.stringify({ type: "set_model", model: model }));
210
+ }
211
+ configPopover.classList.add("hidden");
212
+ configChip.classList.remove("active");
213
+ }
214
+
170
215
  function rebuildModelList() {
171
216
  if (!configModelList) return;
172
217
  configModelList.innerHTML = "";
173
218
  var s = store.snap();
174
219
  var list = s.currentModels.length > 0 ? s.currentModels : (s.currentModel ? [{ value: s.currentModel, displayName: s.currentModel }] : []);
175
- for (var i = 0; i < list.length; i++) {
176
- var item = list[i];
177
- // Support both object { value, displayName } and plain string formats
178
- var value = typeof item === "string" ? item : (item.value || "");
179
- var label = typeof item === "string" ? item : (item.displayName || value);
180
- var btn = document.createElement("button");
181
- btn.className = "config-radio-item";
182
- if (value === s.currentModel) btn.classList.add("active");
183
- btn.dataset.model = value;
184
- btn.textContent = label;
185
- btn.addEventListener("click", function () {
186
- var model = this.dataset.model;
187
- var ws = getWs();
188
- if (ws && ws.readyState === 1) {
189
- ws.send(JSON.stringify({ type: "set_model", model: model }));
190
- }
191
- configPopover.classList.add("hidden");
192
- configChip.classList.remove("active");
220
+
221
+ // lr-e03635: same latest/older tiering as every other picker surface
222
+ // (renderModelList in settings-defaults.js) — default to latest models,
223
+ // with a collapsible "Older models" disclosure for the rest.
224
+ var tiers = splitModelsByTier(list);
225
+
226
+ for (var i = 0; i < tiers.latest.length; i++) {
227
+ configModelList.appendChild(buildConfigModelItem(tiers.latest[i], s.currentModel));
228
+ }
229
+
230
+ // Empty-disclosure rule: absent, not present-and-empty.
231
+ if (tiers.older.length > 0) {
232
+ var toggle = document.createElement("button");
233
+ toggle.type = "button";
234
+ toggle.className = "config-older-models-toggle";
235
+ toggle.setAttribute("aria-expanded", "false");
236
+
237
+ var toggleLabel = document.createElement("span");
238
+ toggleLabel.textContent = "Older models";
239
+ toggle.appendChild(toggleLabel);
240
+
241
+ var chevron = document.createElement("i");
242
+ chevron.setAttribute("data-lucide", "chevron-right");
243
+ chevron.className = "settings-adv-chevron";
244
+ toggle.appendChild(chevron);
245
+
246
+ var body = document.createElement("div");
247
+ body.className = "config-older-models-body hidden";
248
+ for (var k = 0; k < tiers.older.length; k++) {
249
+ body.appendChild(buildConfigModelItem(tiers.older[k], s.currentModel));
250
+ }
251
+
252
+ toggle.addEventListener("click", function () {
253
+ var isOpen = !body.classList.contains("hidden");
254
+ body.classList.toggle("hidden", isOpen);
255
+ toggle.setAttribute("aria-expanded", String(!isOpen));
256
+ chevron.style.transform = isOpen ? "" : "rotate(90deg)";
193
257
  });
194
- configModelList.appendChild(btn);
258
+
259
+ configModelList.appendChild(toggle);
260
+ configModelList.appendChild(body);
195
261
  }
262
+
263
+ refreshIcons(configModelList);
196
264
  }
197
265
 
198
266
  function rebuildModeList() {
@@ -496,6 +564,7 @@ export function initPanels() {
496
564
  contextModelEl = $("context-model");
497
565
  contextCostEl = $("context-cost");
498
566
  contextTurnsEl = $("context-turns");
567
+ contextReasoningEl = $("context-reasoning");
499
568
  contextMini = $("context-mini");
500
569
  contextMiniFill = $("context-mini-fill");
501
570
  contextMiniLabel = $("context-mini-label");
@@ -704,13 +773,15 @@ export function accumulateUsage(cost, usage, lastStreamInputTokens) {
704
773
  // context: current context window fill from the last message_start event.
705
774
  // This is the same value used by the context bar. Assign (not sum) — it represents
706
775
  // the current state of the context window, not a cumulative total.
707
- // Prefer lastStreamInputTokens (accurate per-call); fall back to input+cache_read.
776
+ // Prefer lastStreamInputTokens (accurate per-call); fall back to input+cache_read+cache_creation
777
+ // (lr-3af675: the three usage fields are disjoint and all occupy the window).
708
778
  if (lastStreamInputTokens) {
709
779
  sessionUsage.context = lastStreamInputTokens;
710
780
  } else if (usage) {
711
781
  var directIn = usage.input_tokens || usage.inputTokens || 0;
712
782
  var cacheIn = usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0;
713
- if (directIn + cacheIn > 0) sessionUsage.context = directIn + cacheIn;
783
+ var cacheCreate = usage.cache_creation_input_tokens || usage.cacheCreationInputTokens || 0;
784
+ if (directIn + cacheIn + cacheCreate > 0) sessionUsage.context = directIn + cacheIn + cacheCreate;
714
785
  }
715
786
  sessionUsage.turns++;
716
787
  if (!store.get('replayingHistory')) updateUsagePanel();
@@ -786,44 +857,73 @@ export function toggleStatusPanel() {
786
857
 
787
858
  // --- Context panel ---
788
859
 
789
- export function resolveContextWindow(model, sdkValue) {
790
- // Build the active betas array from store so we can delegate to the shared
791
- // core (lr-336f) which is store-agnostic and usable on both backend and frontend.
792
- var activeBetas = store.get('currentBetas') || [];
793
- // Delegate to shared core: beta-first, then [1m] suffix, then map lookup.
794
- // Core returns 0 for unknown models; apply frontend-specific fallbacks here.
795
- var coreResult = _resolveModelContextWindowCore(model, activeBetas);
796
- if (coreResult > 0) return coreResult;
797
- // sdkValue fallback: prefer the SDK-reported window when the model is not in the
798
- // shared map (new models, vendor-specific entries). Returns 200000 as last resort.
799
- if (sdkValue) return sdkValue;
800
- return 200000;
860
+ /**
861
+ * lr-3af675: vendor-first context-window resolution. The hardcoded
862
+ * model-name -> window table (lib/model-context-windows.js) is gone — both
863
+ * providers report their own context window, and that report is the only
864
+ * value this function ever returns.
865
+ *
866
+ * vendorWindow: the window size as reported by the vendor for the CURRENT
867
+ * turn/session (Claude: modelUsage.contextWindow or getContextUsage()'s
868
+ * maxTokens; Codex: modelUsage.contextWindow, sourced from
869
+ * ThreadTokenUsage.modelContextWindow on thread/tokenUsage/updated —
870
+ * lr-872f94 — absent until the app-server reports one for the session).
871
+ *
872
+ * Returns the vendor-reported window, or 0 when none is available (no
873
+ * completed turn yet, a resumed session before its first result, a daemon
874
+ * restart, or a vendor that hasn't reported one). Callers MUST treat 0 as
875
+ * "unknown" and render an indeterminate state — never substitute a guess.
876
+ */
877
+ export function resolveContextWindow(vendorWindow) {
878
+ return (typeof vendorWindow === "number" && vendorWindow > 0) ? vendorWindow : 0;
801
879
  }
802
880
 
803
881
  export function contextPctClass(pct) {
804
882
  return pct >= 85 ? " danger" : pct >= 60 ? " warn" : "";
805
883
  }
806
884
 
885
+ /**
886
+ * lr-3af675: the effective (used, window) pair the meter renders from.
887
+ * Prefers the rich context-usage breakdown (store.richContextUsage) when
888
+ * present — it is the freshest vendor read, including immediately after a
889
+ * compaction re-read (see the 'status' handler re-fetch in
890
+ * sdk-message-processor.js) — and falls back to the per-turn contextData
891
+ * accumulated from 'result' events. Both sources are vendor-first; neither
892
+ * ever substitutes a guessed window.
893
+ *
894
+ * Exported so every consumer of the meter (header bar, popover, panel, and
895
+ * the tools.js clear-context label) reads the exact same (used, win) pair
896
+ * instead of each recomputing its own view and risking disagreement.
897
+ */
898
+ export function getEffectiveContextFill() {
899
+ var rich = store.get('richContextUsage');
900
+ if (rich && typeof rich.totalTokens === "number") {
901
+ var richWin = resolveContextWindow(rich.maxTokens);
902
+ if (richWin > 0) return { used: rich.totalTokens, win: richWin };
903
+ }
904
+ return { used: contextData.input, win: resolveContextWindow(contextData.contextWindow) };
905
+ }
906
+
807
907
  export function updateContextPanel() {
808
908
  if (!contextUsedEl) return;
809
- // Context window usage = input tokens only (includes cache read/write)
810
- var used = contextData.input;
811
- // Re-resolve each paint so beta changes (e.g. context-1m toggle) are
812
- // reflected immediately without waiting for the next turn's result event.
813
- var win = resolveContextWindow(contextData.model, contextData.contextWindow);
909
+ var fill = getEffectiveContextFill();
910
+ var used = fill.used;
911
+ var win = fill.win;
814
912
  var pct = win > 0 ? Math.min(100, (used / win) * 100) : 0;
815
913
  var cls = contextPctClass(pct);
816
914
  // Panel bar
817
915
  contextBarFill.style.width = pct.toFixed(1) + "%";
818
916
  contextBarFill.className = "context-bar-fill" + cls;
819
- contextBarPct.textContent = pct.toFixed(0) + "%";
917
+ // lr-3af675: unknown window -> "-", never a fabricated "0%".
918
+ contextBarPct.textContent = win > 0 ? pct.toFixed(0) + "%" : "-";
820
919
  // Mini bar
821
920
  if (contextMiniFill) {
822
921
  contextMiniFill.style.width = pct.toFixed(1) + "%";
823
922
  contextMiniFill.className = "context-mini-fill" + cls;
824
923
  }
825
924
  if (contextMiniLabel) {
826
- contextMiniLabel.textContent = (win > 0 ? formatTokens(used) + "/" + formatTokens(win) : "0%");
925
+ // lr-3af675: unknown window -> "-", never a fabricated "0%".
926
+ contextMiniLabel.textContent = (win > 0 ? formatTokens(used) + "/" + formatTokens(win) : "-");
827
927
  }
828
928
  // Header bar
829
929
  if (pct > 0) {
@@ -865,6 +965,19 @@ export function updateContextPanel() {
865
965
  if (contextOutputEl) contextOutputEl.textContent = formatTokens(contextData.output);
866
966
  if (contextCacheReadEl) contextCacheReadEl.textContent = formatTokens(contextData.cacheRead);
867
967
  if (contextCacheWriteEl) contextCacheWriteEl.textContent = formatTokens(contextData.cacheWrite);
968
+ // lr-872f94: reasoning tokens are a real Codex-specific spend category
969
+ // (thread/tokenUsage/updated's reasoningOutputTokens) that was previously
970
+ // invisible to users. Row is hidden (not just "-") when a vendor hasn't
971
+ // reported any, so Claude sessions don't show a permanently-zero row.
972
+ if (contextReasoningEl) {
973
+ var reasoningRow = contextReasoningEl.closest(".usage-row");
974
+ if (contextData.reasoningOutput > 0) {
975
+ contextReasoningEl.textContent = formatTokens(contextData.reasoningOutput);
976
+ if (reasoningRow) reasoningRow.classList.remove("hidden");
977
+ } else if (reasoningRow) {
978
+ reasoningRow.classList.add("hidden");
979
+ }
980
+ }
868
981
  contextModelEl.textContent = contextData.model;
869
982
  var vendor = store.get('currentVendor');
870
983
  contextCostEl.textContent = (vendor === 'codex' || contextData.cost == null)
@@ -886,12 +999,20 @@ export function accumulateContext(cost, usage, modelUsage, lastStreamInputTokens
886
999
  if (lastStreamInputTokens) {
887
1000
  contextData.input = lastStreamInputTokens;
888
1001
  } else {
1002
+ // lr-3af675: input_tokens, cache_read_input_tokens, and
1003
+ // cache_creation_input_tokens are disjoint and all three occupy the
1004
+ // context window -- cache_creation_input_tokens was previously
1005
+ // omitted here, under-reporting fill on cache-write-heavy turns.
889
1006
  contextData.input = (usage.input_tokens || usage.inputTokens || 0)
890
- + (usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0);
1007
+ + (usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0)
1008
+ + (usage.cache_creation_input_tokens || usage.cacheCreationInputTokens || 0);
891
1009
  }
892
1010
  contextData.output = usage.output_tokens || usage.outputTokens || 0;
893
1011
  contextData.cacheRead = usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0;
894
1012
  contextData.cacheWrite = usage.cache_creation_input_tokens || usage.cacheCreationInputTokens || 0;
1013
+ // lr-872f94: Codex-specific reasoning token spend (previously discarded).
1014
+ // No cumulative concept here, matching the other per-turn fields above.
1015
+ contextData.reasoningOutput = usage.reasoning_output_tokens || usage.reasoningOutputTokens || 0;
895
1016
  }
896
1017
  contextData.turns++;
897
1018
  if (modelUsage) {
@@ -903,7 +1024,12 @@ export function accumulateContext(cost, usage, modelUsage, lastStreamInputTokens
903
1024
  // (e.g. CLI reports "claude-sonnet-4-6" even when running as opus[1m])
904
1025
  var displayModel = store.get('currentModel') || m;
905
1026
  contextData.model = displayModel;
906
- contextData.contextWindow = resolveContextWindow(displayModel, mu.contextWindow);
1027
+ // lr-3af675: vendor-first, no hardcoded table. mu.contextWindow is the
1028
+ // vendor's own reported window for this model; resolveContextWindow no
1029
+ // longer does anything but validate it's a positive number. Absent a
1030
+ // vendor value, contextWindow stays 0 ("unknown") -- render blank, not
1031
+ // a guess.
1032
+ contextData.contextWindow = resolveContextWindow(mu.contextWindow);
907
1033
  if (mu.maxOutputTokens) contextData.maxOutputTokens = mu.maxOutputTokens;
908
1034
  }
909
1035
  }
@@ -926,7 +1052,7 @@ export function applyContextView(view) {
926
1052
  }
927
1053
 
928
1054
  export function resetContextData() {
929
- contextData = { contextWindow: 0, maxOutputTokens: 0, model: "-", cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, turns: 0 };
1055
+ contextData = { contextWindow: 0, maxOutputTokens: 0, model: "-", cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoningOutput: 0, turns: 0 };
930
1056
  store.set({ richContextUsage: null });
931
1057
  // hideCtxPopover + updateContextPanel handled by store subscriber
932
1058
  }
@@ -997,9 +1123,10 @@ export function renderCtxPopover() {
997
1123
  var d = richContextUsage;
998
1124
  var cats = d.categories || [];
999
1125
  var total = d.totalTokens || 0;
1000
- // SDK reports the model's base window in maxTokens; override with the
1001
- // beta-aware resolved window so 1M sessions show the correct denominator.
1002
- var max = resolveContextWindow(d.model || contextData.model, d.maxTokens || 0);
1126
+ // lr-3af675: vendor-first -- d.maxTokens is the SDK's own reported window
1127
+ // (already reflects any active beta, e.g. context-1m) and needs no local
1128
+ // override. resolveContextWindow now only validates it's a positive number.
1129
+ var max = resolveContextWindow(d.maxTokens);
1003
1130
  var pct = max > 0 ? Math.min(100, (total / max) * 100) : (d.percentage != null ? d.percentage : 0);
1004
1131
 
1005
1132
  var html = "";
@@ -1007,8 +1134,9 @@ export function renderCtxPopover() {
1007
1134
  // Header
1008
1135
  html += '<div class="ctx-pop-header">';
1009
1136
  html += '<span class="ctx-pop-model">' + escHtml(d.model || contextData.model || "-") + '</span>';
1010
- html += '<span class="ctx-pop-pct">' + pct.toFixed(0) + '%';
1011
- html += '<span class="ctx-pop-tokens">' + formatTokens(total) + ' / ' + formatTokens(max) + '</span>';
1137
+ // lr-3af675: unknown window -> "-", never a fabricated "0%"/0 denominator.
1138
+ html += '<span class="ctx-pop-pct">' + (max > 0 ? pct.toFixed(0) + '%' : '-');
1139
+ html += '<span class="ctx-pop-tokens">' + formatTokens(total) + ' / ' + (max > 0 ? formatTokens(max) : '-') + '</span>';
1012
1140
  html += '</span>';
1013
1141
  html += '</div>';
1014
1142