@clagentic/console 1.9.0-beta.1 → 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 (50) 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/project-connection.js +15 -2
  7. package/lib/project-loop.js +46 -2
  8. package/lib/project-sessions.js +31 -3
  9. package/lib/project-user-message.js +70 -3
  10. package/lib/project.js +7 -1
  11. package/lib/public/app.js +14 -4
  12. package/lib/public/css/base.css +14 -0
  13. package/lib/public/css/home-hub.css +28 -8
  14. package/lib/public/css/icon-strip.css +17 -0
  15. package/lib/public/css/messages.css +11 -0
  16. package/lib/public/css/mobile-nav.css +22 -0
  17. package/lib/public/css/sidebar.css +15 -0
  18. package/lib/public/css/title-bar.css +10 -1
  19. package/lib/public/index.html +1 -0
  20. package/lib/public/modules/activity-latch.js +159 -0
  21. package/lib/public/modules/activity-state.js +157 -0
  22. package/lib/public/modules/app-connection.js +10 -4
  23. package/lib/public/modules/app-favicon.js +88 -1
  24. package/lib/public/modules/app-home-hub.js +14 -11
  25. package/lib/public/modules/app-loop-ui.js +86 -2
  26. package/lib/public/modules/app-messages.js +118 -54
  27. package/lib/public/modules/app-panels.js +91 -32
  28. package/lib/public/modules/app-projects.js +28 -8
  29. package/lib/public/modules/app-rate-limit.js +13 -1
  30. package/lib/public/modules/sidebar-mobile.js +32 -22
  31. package/lib/public/modules/sidebar-projects.js +42 -14
  32. package/lib/public/modules/sidebar-sessions.js +168 -48
  33. package/lib/public/modules/tools.js +11 -39
  34. package/lib/sdk-bridge.js +301 -22
  35. package/lib/sdk-message-processor.js +98 -15
  36. package/lib/sdk-skill-discovery.js +46 -6
  37. package/lib/sdk-slash-enrichment.js +5 -2
  38. package/lib/server-hub-sessions.js +70 -0
  39. package/lib/server.js +24 -22
  40. package/lib/session-activity.js +8 -1
  41. package/lib/sessions.js +47 -1
  42. package/lib/smtp.js +10 -1
  43. package/lib/ws-schema.js +16 -0
  44. package/lib/yoke/adapters/claude.js +7 -1
  45. package/lib/yoke/adapters/codex.js +219 -31
  46. package/package.json +2 -2
  47. package/scripts/check-test-count.js +397 -0
  48. package/scripts/test-file-completion-reporter.js +43 -0
  49. package/lib/model-context-windows.js +0 -74
  50. package/lib/public/modules/model-context-windows.js +0 -71
@@ -6,7 +6,6 @@ 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';
10
9
  import { splitModelsByTier } from './settings-defaults.js';
11
10
  import { isSonnetModel } from './model-families.js';
12
11
 
@@ -14,7 +13,7 @@ import { isSonnetModel } from './model-families.js';
14
13
  // sessionUsage.context = last-turn context fill (lastStreamInputTokens) — not cumulative,
15
14
  // just the most recent value. Correct for display without any accumulation issues.
16
15
  var sessionUsage = { cost: 0, context: 0, output: 0, cacheWrite: 0, turns: 0 };
17
- 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 };
18
17
  var ctxPopoverEl = null;
19
18
  var ctxHoverTimer = null;
20
19
  var statusRefreshTimer = null;
@@ -77,6 +76,7 @@ var contextCacheWriteEl = null;
77
76
  var contextModelEl = null;
78
77
  var contextCostEl = null;
79
78
  var contextTurnsEl = null;
79
+ var contextReasoningEl = null;
80
80
  var contextMini = null;
81
81
  var contextMiniFill = null;
82
82
  var contextMiniLabel = null;
@@ -109,7 +109,6 @@ var CODEX_WEBSEARCH_OPTIONS = [
109
109
  { value: "cached", label: "Cached" },
110
110
  { value: "live", label: "Live" },
111
111
  ];
112
- // KNOWN_CONTEXT_WINDOWS imported from ./model-context-windows.js (lr-336f shared source of truth)
113
112
  // Categories to hide from the legend (noise, not actionable)
114
113
  var CTX_HIDDEN_CATS = { "Free space": 1, "Autocompact buffer": 1 };
115
114
 
@@ -565,6 +564,7 @@ export function initPanels() {
565
564
  contextModelEl = $("context-model");
566
565
  contextCostEl = $("context-cost");
567
566
  contextTurnsEl = $("context-turns");
567
+ contextReasoningEl = $("context-reasoning");
568
568
  contextMini = $("context-mini");
569
569
  contextMiniFill = $("context-mini-fill");
570
570
  contextMiniLabel = $("context-mini-label");
@@ -773,13 +773,15 @@ export function accumulateUsage(cost, usage, lastStreamInputTokens) {
773
773
  // context: current context window fill from the last message_start event.
774
774
  // This is the same value used by the context bar. Assign (not sum) — it represents
775
775
  // the current state of the context window, not a cumulative total.
776
- // 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).
777
778
  if (lastStreamInputTokens) {
778
779
  sessionUsage.context = lastStreamInputTokens;
779
780
  } else if (usage) {
780
781
  var directIn = usage.input_tokens || usage.inputTokens || 0;
781
782
  var cacheIn = usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0;
782
- 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;
783
785
  }
784
786
  sessionUsage.turns++;
785
787
  if (!store.get('replayingHistory')) updateUsagePanel();
@@ -855,44 +857,73 @@ export function toggleStatusPanel() {
855
857
 
856
858
  // --- Context panel ---
857
859
 
858
- export function resolveContextWindow(model, sdkValue) {
859
- // Build the active betas array from store so we can delegate to the shared
860
- // core (lr-336f) which is store-agnostic and usable on both backend and frontend.
861
- var activeBetas = store.get('currentBetas') || [];
862
- // Delegate to shared core: beta-first, then [1m] suffix, then map lookup.
863
- // Core returns 0 for unknown models; apply frontend-specific fallbacks here.
864
- var coreResult = _resolveModelContextWindowCore(model, activeBetas);
865
- if (coreResult > 0) return coreResult;
866
- // sdkValue fallback: prefer the SDK-reported window when the model is not in the
867
- // shared map (new models, vendor-specific entries). Returns 200000 as last resort.
868
- if (sdkValue) return sdkValue;
869
- 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;
870
879
  }
871
880
 
872
881
  export function contextPctClass(pct) {
873
882
  return pct >= 85 ? " danger" : pct >= 60 ? " warn" : "";
874
883
  }
875
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
+
876
907
  export function updateContextPanel() {
877
908
  if (!contextUsedEl) return;
878
- // Context window usage = input tokens only (includes cache read/write)
879
- var used = contextData.input;
880
- // Re-resolve each paint so beta changes (e.g. context-1m toggle) are
881
- // reflected immediately without waiting for the next turn's result event.
882
- var win = resolveContextWindow(contextData.model, contextData.contextWindow);
909
+ var fill = getEffectiveContextFill();
910
+ var used = fill.used;
911
+ var win = fill.win;
883
912
  var pct = win > 0 ? Math.min(100, (used / win) * 100) : 0;
884
913
  var cls = contextPctClass(pct);
885
914
  // Panel bar
886
915
  contextBarFill.style.width = pct.toFixed(1) + "%";
887
916
  contextBarFill.className = "context-bar-fill" + cls;
888
- contextBarPct.textContent = pct.toFixed(0) + "%";
917
+ // lr-3af675: unknown window -> "-", never a fabricated "0%".
918
+ contextBarPct.textContent = win > 0 ? pct.toFixed(0) + "%" : "-";
889
919
  // Mini bar
890
920
  if (contextMiniFill) {
891
921
  contextMiniFill.style.width = pct.toFixed(1) + "%";
892
922
  contextMiniFill.className = "context-mini-fill" + cls;
893
923
  }
894
924
  if (contextMiniLabel) {
895
- 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) : "-");
896
927
  }
897
928
  // Header bar
898
929
  if (pct > 0) {
@@ -934,6 +965,19 @@ export function updateContextPanel() {
934
965
  if (contextOutputEl) contextOutputEl.textContent = formatTokens(contextData.output);
935
966
  if (contextCacheReadEl) contextCacheReadEl.textContent = formatTokens(contextData.cacheRead);
936
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
+ }
937
981
  contextModelEl.textContent = contextData.model;
938
982
  var vendor = store.get('currentVendor');
939
983
  contextCostEl.textContent = (vendor === 'codex' || contextData.cost == null)
@@ -955,12 +999,20 @@ export function accumulateContext(cost, usage, modelUsage, lastStreamInputTokens
955
999
  if (lastStreamInputTokens) {
956
1000
  contextData.input = lastStreamInputTokens;
957
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.
958
1006
  contextData.input = (usage.input_tokens || usage.inputTokens || 0)
959
- + (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);
960
1009
  }
961
1010
  contextData.output = usage.output_tokens || usage.outputTokens || 0;
962
1011
  contextData.cacheRead = usage.cache_read_input_tokens || usage.cacheReadInputTokens || 0;
963
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;
964
1016
  }
965
1017
  contextData.turns++;
966
1018
  if (modelUsage) {
@@ -972,7 +1024,12 @@ export function accumulateContext(cost, usage, modelUsage, lastStreamInputTokens
972
1024
  // (e.g. CLI reports "claude-sonnet-4-6" even when running as opus[1m])
973
1025
  var displayModel = store.get('currentModel') || m;
974
1026
  contextData.model = displayModel;
975
- 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);
976
1033
  if (mu.maxOutputTokens) contextData.maxOutputTokens = mu.maxOutputTokens;
977
1034
  }
978
1035
  }
@@ -995,7 +1052,7 @@ export function applyContextView(view) {
995
1052
  }
996
1053
 
997
1054
  export function resetContextData() {
998
- 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 };
999
1056
  store.set({ richContextUsage: null });
1000
1057
  // hideCtxPopover + updateContextPanel handled by store subscriber
1001
1058
  }
@@ -1066,9 +1123,10 @@ export function renderCtxPopover() {
1066
1123
  var d = richContextUsage;
1067
1124
  var cats = d.categories || [];
1068
1125
  var total = d.totalTokens || 0;
1069
- // SDK reports the model's base window in maxTokens; override with the
1070
- // beta-aware resolved window so 1M sessions show the correct denominator.
1071
- 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);
1072
1130
  var pct = max > 0 ? Math.min(100, (total / max) * 100) : (d.percentage != null ? d.percentage : 0);
1073
1131
 
1074
1132
  var html = "";
@@ -1076,8 +1134,9 @@ export function renderCtxPopover() {
1076
1134
  // Header
1077
1135
  html += '<div class="ctx-pop-header">';
1078
1136
  html += '<span class="ctx-pop-model">' + escHtml(d.model || contextData.model || "-") + '</span>';
1079
- html += '<span class="ctx-pop-pct">' + pct.toFixed(0) + '%';
1080
- 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>';
1081
1140
  html += '</span>';
1082
1141
  html += '</div>';
1083
1142
 
@@ -8,11 +8,12 @@ import { renderProjectIcon } from './project-icon.js';
8
8
  import { store } from './store.js';
9
9
  import { getWs, setWs } from './ws-ref.js';
10
10
  import { getMessagesEl, getStatusDot } from './dom-refs.js';
11
+ import { sessionActivity, indicatorClass } from './activity-state.js';
11
12
  import { userAvatarUrl } from './avatar.js';
12
13
  import { showConfirm } from './app-misc.js';
13
14
  // renderUserStrip is now reactive via store subscriber in sidebar-users.js
14
15
  import { renderIconStrip } from './sidebar-projects.js';
15
- import { updateCrossProjectBlink, stopUrgentBlink, setActivity } from './app-favicon.js';
16
+ import { updateCrossProjectBlink, stopUrgentBlink } from './app-favicon.js';
16
17
  import { spawnDustParticles } from './sidebar.js';
17
18
  import { isSearchOpen, closeSearch } from './session-search.js';
18
19
  import { exitDmMode } from './app-dm.js';
@@ -313,13 +314,15 @@ export function renderTopbarPresence(serverUsers) {
313
314
  }
314
315
 
315
316
  export function renderProjectList() {
317
+ // lr-66c118: activity-state.js is the sole reader of the processing flag
318
+ // (CI-enforced) — Object.assign carries it through untouched rather than
319
+ // this mapper naming/reading the property itself.
316
320
  var iconStripProjects = cachedProjects.map(function (p) {
317
- return {
321
+ return Object.assign({}, p, {
318
322
  slug: p.slug,
319
323
  name: p.title || p.project,
320
324
  icon: p.icon || null,
321
325
  folderName: p.folderName || null,
322
- isProcessing: p.isProcessing,
323
326
  onlineUsers: p.onlineUsers || [],
324
327
  unread: p.unread || 0,
325
328
  pendingPermissions: p.pendingPermissions || 0,
@@ -327,7 +330,7 @@ export function renderProjectList() {
327
330
  parentSlug: p.parentSlug || null,
328
331
  branch: p.branch || null,
329
332
  worktreeAccessible: p.worktreeAccessible !== undefined ? p.worktreeAccessible : true,
330
- };
333
+ });
331
334
  });
332
335
  var st = store.snap();
333
336
  var iconStripActiveSlug = st.currentSlug;
@@ -377,11 +380,20 @@ export function renderProjectList() {
377
380
  }
378
381
  }
379
382
  }
380
- // Re-apply current socket status to the active icon's dot
383
+ // Re-apply current socket status to the active icon's dot. st.processing
384
+ // is THIS client's own live turn-in-flight signal (set by setStatus() in
385
+ // app-connection.js) — always tone 'self', it can only ever be about the
386
+ // viewing user's own connection. lr-66c118: routed through the same
387
+ // derivation as every other dot rather than writing '.processing' as an
388
+ // independent 3rd state source (alongside the session-level processing
389
+ // flag and setActivity).
381
390
  var dot = getStatusDot();
382
391
  if (dot) {
383
- if (st.connected && st.processing) { dot.classList.add("connected"); dot.classList.add("processing"); }
384
- else if (st.connected) { dot.classList.add("connected"); }
392
+ if (st.connected) {
393
+ dot.classList.add("connected");
394
+ var localActivityCls = indicatorClass(sessionActivity({ isProcessing: st.processing }));
395
+ if (localActivityCls) dot.classList.add(localActivityCls);
396
+ }
385
397
  }
386
398
  updateCrossProjectBlink();
387
399
  }
@@ -406,7 +418,15 @@ export function resetClientState() {
406
418
  setIsUserScrolledUp(false);
407
419
  document.getElementById("new-msg-btn").classList.add("hidden");
408
420
  setRewindMode(false);
409
- setActivity(null);
421
+ // lr-66c118 / lr-6e20f7: the setActivity clear call is removed here —
422
+ // setActivityEl(null) above already nulls the activity-widget ref, and
423
+ // getMessagesEl().innerHTML = "" already wiped the DOM element itself, so
424
+ // an explicit setActivity(null) call here would be redundant. The widget's
425
+ // OWN reactive clear (app-favicon.js's initActivityFooter, subscribed to
426
+ // store.processing) additionally still needs the DOM ref nulled out here —
427
+ // setActivityEl(null) above is exactly what makes that safe, since a
428
+ // reactive clear firing after this reset would otherwise find a stale ref
429
+ // pointing at an element already removed from the DOM by innerHTML="".
410
430
  setStatus("connected");
411
431
  // Always re-enable input on session switch. A loop running in another session
412
432
  // has its own dedicated session and must not lock unrelated sessions.
@@ -113,11 +113,23 @@ function updateRateLimitIndicator(msg) {
113
113
  var isRejected = msg.status === "rejected";
114
114
  var pillClass = "header-rate-limit" + (isRejected ? " rejected" : " warning");
115
115
  var label = isRejected ? "Rate limited" : "Rate warning";
116
+ // lr-872f94: render the vendor-reported usedPercent in the pill itself
117
+ // (previously only surfaced in the transient warning popover text).
118
+ // Applies to both providers -- Codex's account/rateLimits/updated and
119
+ // Claude's rate_limit_info both carry `utilization` (0-1 fraction) through
120
+ // the same yokeType: "rate_limit" event shape (lib/sdk-message-processor.js).
121
+ var pct = typeof msg.utilization === "number" ? Math.round(msg.utilization * 100) : null;
122
+ var pctHtml = pct != null ? '<span class="header-pill-pct">' + pct + "%</span>" : "";
123
+ // lr-872f94 fold-in: this link was hardcoded to Claude's usage page even
124
+ // for Codex-triggered warnings/rejections. getVendorUsageMeta already
125
+ // exists for exactly this (used by the rate_limit_usage widget below).
126
+ var vendorMeta = getVendorUsageMeta(store.get('currentVendor') || "claude");
116
127
  rateLimitIndicatorEl.innerHTML =
117
128
  '<span class="' + pillClass + '">' +
118
129
  iconHtml("alert-triangle") +
119
130
  '<span class="header-pill-text">' + label + "</span>" +
120
- '<a href="https://claude.ai/settings/usage" target="_blank" rel="noopener" class="rate-limit-link">' +
131
+ pctHtml +
132
+ '<a href="' + vendorMeta.href + '" target="_blank" rel="noopener" class="rate-limit-link">' +
121
133
  iconHtml("external-link") +
122
134
  "</a>" +
123
135
  "</span>";
@@ -34,6 +34,7 @@ import {
34
34
  getCachedDmUnread,
35
35
  getCachedDmRemovedUsers
36
36
  } from './sidebar-users.js';
37
+ import { sessionActivity, rollupActivity, indicatorClass } from './activity-state.js';
37
38
 
38
39
  import { store } from './store.js';
39
40
  import { getWs } from './ws-ref.js';
@@ -182,9 +183,10 @@ function renderSheetProjects(listEl) {
182
183
  nameSpan.textContent = p.name;
183
184
  el.appendChild(nameSpan);
184
185
 
185
- if (p.isProcessing) {
186
+ var rowActivityCls = indicatorClass(sessionActivity(p, null, { ignoreUnread: true }));
187
+ if (rowActivityCls) {
186
188
  var dot = document.createElement("span");
187
- dot.className = "mobile-project-processing";
189
+ dot.className = "mobile-project-processing " + rowActivityCls;
188
190
  el.appendChild(dot);
189
191
  }
190
192
  if (p.unread > 0 && p.slug !== currentSlug) {
@@ -231,13 +233,13 @@ function renderSheetProjects(listEl) {
231
233
  // Exclude the currently-active project from unread so switching into a
232
234
  // project inside a folder clears its contribution to the folder badge.
233
235
  var totalUnread = 0;
234
- var anyProcessing = false;
235
236
  for (var fai = 0; fai < folderProjects.length; fai++) {
236
237
  if (folderProjects[fai].slug !== currentSlug) {
237
238
  totalUnread += (folderProjects[fai].unread || 0);
238
239
  }
239
- if (folderProjects[fai].isProcessing) anyProcessing = true;
240
240
  }
241
+ // lr-66c118: replaces the open-coded anyProcessing OR-loop above.
242
+ var folderRowActivityCls = indicatorClass(rollupActivity(folderProjects, null, { ignoreUnread: true }));
241
243
 
242
244
  // Folder header row
243
245
  var headerEl = document.createElement("button");
@@ -264,9 +266,9 @@ function renderSheetProjects(listEl) {
264
266
  chevron.innerHTML = '<i data-lucide="chevron-right"></i>';
265
267
  headerEl.appendChild(chevron);
266
268
 
267
- if (anyProcessing) {
269
+ if (folderRowActivityCls) {
268
270
  var fdot = document.createElement("span");
269
- fdot.className = "mobile-project-processing";
271
+ fdot.className = "mobile-project-processing " + folderRowActivityCls;
270
272
  headerEl.appendChild(fdot);
271
273
  }
272
274
  if (totalUnread > 0) {
@@ -474,9 +476,12 @@ function createMobileSessionItem(s) {
474
476
  el.className = "mobile-session-item" + (s.active ? " active" : "");
475
477
 
476
478
  // Processing dot (left side, before title)
477
- if (s.isProcessing) {
479
+ var msiActivityState = sessionActivity(s, store.get('myUserId'));
480
+ var msiActivityCls = indicatorClass(msiActivityState);
481
+ if (msiActivityCls) {
478
482
  var dot = document.createElement("span");
479
- dot.className = "mobile-session-processing";
483
+ dot.className = "mobile-session-processing " + msiActivityCls;
484
+ dot.title = msiActivityState.label;
480
485
  el.appendChild(dot);
481
486
  }
482
487
 
@@ -525,9 +530,10 @@ function createMobileLoopChild(s) {
525
530
  var el = document.createElement("button");
526
531
  el.className = "mobile-loop-child" + (s.active ? " active" : "");
527
532
 
528
- if (s.isProcessing) {
533
+ var mlcActivityCls = indicatorClass(sessionActivity(s, store.get('myUserId')));
534
+ if (mlcActivityCls) {
529
535
  var dot = document.createElement("span");
530
- dot.className = "mobile-session-processing";
536
+ dot.className = "mobile-session-processing " + mlcActivityCls;
531
537
  el.appendChild(dot);
532
538
  }
533
539
 
@@ -567,15 +573,15 @@ function createMobileLoopRun(parentGk, startedAtKey, sessions, isRalph) {
567
573
  var timeLabel = startedAt ? new Date(startedAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : "Unknown";
568
574
 
569
575
  var hasActive = false;
570
- var anyProcessing = false;
571
576
  var latestSession = sessions[0];
572
577
  for (var i = 0; i < sessions.length; i++) {
573
578
  if (sessions[i].active) hasActive = true;
574
- if (sessions[i].isProcessing) anyProcessing = true;
575
579
  if ((sessions[i].lastActivity || 0) > (latestSession.lastActivity || 0)) {
576
580
  latestSession = sessions[i];
577
581
  }
578
582
  }
583
+ // lr-66c118: replaces the open-coded anyProcessing OR-loop above.
584
+ var runRowActivityCls = indicatorClass(rollupActivity(sessions, store.get('myUserId')));
579
585
 
580
586
  var wrapper = document.createElement("div");
581
587
  wrapper.className = "mobile-loop-run-wrapper";
@@ -591,8 +597,8 @@ function createMobileLoopRun(parentGk, startedAtKey, sessions, isRalph) {
591
597
  var label = document.createElement("span");
592
598
  label.className = "mobile-loop-run-time";
593
599
  var labelHtml = "";
594
- if (anyProcessing) {
595
- labelHtml += '<span class="mobile-session-processing"></span> ';
600
+ if (runRowActivityCls) {
601
+ labelHtml += '<span class="mobile-session-processing ' + runRowActivityCls + '"></span> ';
596
602
  }
597
603
  labelHtml += escapeHtml(timeLabel);
598
604
  label.innerHTML = labelHtml;
@@ -659,15 +665,15 @@ function createMobileLoopGroup(loopId, children, groupKey) {
659
665
 
660
666
  var expanded = expandedMobileLoopGroups.has(gk);
661
667
  var hasActive = false;
662
- var anyProcessing = false;
663
668
  var latestSession = children[0];
664
669
  for (var ci = 0; ci < children.length; ci++) {
665
670
  if (children[ci].active) hasActive = true;
666
- if (children[ci].isProcessing) anyProcessing = true;
667
671
  if ((children[ci].lastActivity || 0) > (latestSession.lastActivity || 0)) {
668
672
  latestSession = children[ci];
669
673
  }
670
674
  }
675
+ // lr-66c118: replaces the open-coded anyProcessing OR-loop above.
676
+ var groupRowActivityCls = indicatorClass(rollupActivity(children, store.get('myUserId')));
671
677
 
672
678
  var loopName = (children[0].loop && children[0].loop.name) || "Loop";
673
679
  var isRalph = children[0].loop && children[0].loop.source === "ralph";
@@ -695,9 +701,9 @@ function createMobileLoopGroup(loopId, children, groupKey) {
695
701
  iconSpan.innerHTML = iconHtml(groupIcon);
696
702
  header.appendChild(iconSpan);
697
703
 
698
- if (anyProcessing) {
704
+ if (groupRowActivityCls) {
699
705
  var dot = document.createElement("span");
700
- dot.className = "mobile-session-processing";
706
+ dot.className = "mobile-session-processing " + groupRowActivityCls;
701
707
  header.appendChild(dot);
702
708
  }
703
709
 
@@ -968,16 +974,20 @@ export function refreshMobileChatSheet() {
968
974
  // Update processing dot: same class as icon strip
969
975
  var statusDot = chip.querySelector(".icon-strip-status");
970
976
  if (statusDot) {
971
- var isProcessing = false;
977
+ var chipProject = null;
972
978
  var allProjects = getCachedProjects() || [];
973
979
  var lookupSlug = chip.dataset.type === "mate" ? ("mate-" + chip.dataset.mateId) : chip.dataset.slug;
974
980
  for (var pi = 0; pi < allProjects.length; pi++) {
975
- if (allProjects[pi].slug === lookupSlug && allProjects[pi].isProcessing) {
976
- isProcessing = true;
981
+ if (allProjects[pi].slug === lookupSlug) {
982
+ chipProject = allProjects[pi];
977
983
  break;
978
984
  }
979
985
  }
980
- statusDot.classList.toggle("processing", isProcessing);
986
+ // lr-66c118: chip dot is project-level — isProcessing-only (no alert
987
+ // tone here, matching every other project-level dot in this module).
988
+ statusDot.classList.remove("processing", "alert", "other");
989
+ var chipActivityCls = indicatorClass(sessionActivity(chipProject, null, { ignoreUnread: true }));
990
+ if (chipActivityCls) statusDot.classList.add(chipActivityCls);
981
991
  }
982
992
  }
983
993
 
@@ -16,6 +16,7 @@ import { showIconTooltip, hideIconTooltip, closeUserCtxMenu, getCurrentDmUserId
16
16
  import { switchProject, openAddProjectModal, getCachedProjects } from './app-projects.js';
17
17
  import { openAgentPickerForPreferred } from './agent-picker.js';
18
18
  import { showHomeHub } from './app-home-hub.js';
19
+ import { sessionActivity, rollupActivity, indicatorClass } from './activity-state.js';
19
20
 
20
21
  // --- Project state ---
21
22
  var cachedProjectList = [];
@@ -1316,7 +1317,14 @@ function generateFolderName(existingFolderNames) {
1316
1317
 
1317
1318
  // --- Icon item creation ---
1318
1319
 
1319
- function createIconItem(p, currentSlug) {
1320
+ // activityOverride (optional): a raw project/rollup-shaped object to derive
1321
+ // the dot from INSTEAD of p itself, without mutating p — see
1322
+ // renderWorktreeGroup, which used to fold worktree processing state directly
1323
+ // onto the shared project object in place (lr-66c118; same disease as the
1324
+ // July phantom-badge bug, engram 7574673: a later read of p could no longer
1325
+ // distinguish "this project is processing" from "some worktree was
1326
+ // processing at last render").
1327
+ function createIconItem(p, currentSlug, activityOverride) {
1320
1328
  var currentDmUserId = getCurrentDmUserId ? getCurrentDmUserId() : null;
1321
1329
  var el = document.createElement("a");
1322
1330
  var isActive = p.slug === currentSlug && !currentDmUserId;
@@ -1339,7 +1347,12 @@ function createIconItem(p, currentSlug) {
1339
1347
 
1340
1348
  var statusDot = document.createElement("span");
1341
1349
  statusDot.className = "icon-strip-status";
1342
- if (p.isProcessing) statusDot.classList.add("processing");
1350
+ // lr-66c118: project-level dot — only ever a processing/idle signal, never
1351
+ // alert (the project unread badge below owns that affordance) — ignoreUnread
1352
+ // so sessionActivity never derives an 'alert' tone here even though p (or
1353
+ // activityOverride) carries .unread for the badge above/below.
1354
+ var pActivityCls = indicatorClass(sessionActivity(activityOverride || p, null, { ignoreUnread: true }));
1355
+ if (pActivityCls) statusDot.classList.add(pActivityCls);
1343
1356
  el.appendChild(statusDot);
1344
1357
 
1345
1358
  var projectBadge = document.createElement("span");
@@ -1616,21 +1629,26 @@ function renderUserFolder(unit, wtByParent, currentSlug, currentDmUserId) {
1616
1629
 
1617
1630
  // Aggregate state: unread sum, processing, active
1618
1631
  var totalUnread = 0;
1619
- var anyProcessing = false;
1632
+ var folderActivityItems = [];
1620
1633
  var containsActive = false;
1621
1634
  for (var fi = 0; fi < folderProjects.length; fi++) {
1622
1635
  var fp = folderProjects[fi];
1623
1636
  totalUnread += fp.unread || 0;
1624
- if (fp.isProcessing) anyProcessing = true;
1637
+ folderActivityItems.push(fp);
1625
1638
  if (fp.slug === currentSlug) containsActive = true;
1626
1639
  // Also check worktrees
1627
1640
  var fwt = wtByParent[fp.slug] || [];
1628
1641
  for (var fwi = 0; fwi < fwt.length; fwi++) {
1629
1642
  totalUnread += fwt[fwi].unread || 0;
1630
- if (fwt[fwi].isProcessing) anyProcessing = true;
1643
+ folderActivityItems.push(fwt[fwi]);
1631
1644
  if (fwt[fwi].slug === currentSlug) containsActive = true;
1632
1645
  }
1633
1646
  }
1647
+ // lr-66c118: replaces the open-coded anyProcessing OR-loop above. Project
1648
+ // dots never carry alert tone (see createIconItem) — ignoreUnread so this
1649
+ // stays isProcessing-only, matching, even though the raw items carry
1650
+ // .unread for totalUnread above.
1651
+ var folderActivityCls = indicatorClass(rollupActivity(folderActivityItems, null, { ignoreUnread: true }));
1634
1652
 
1635
1653
  var folderEl = document.createElement("div");
1636
1654
  folderEl.className = "icon-strip-folder" + (isCollapsed ? " collapsed" : "") + (containsActive && isCollapsed ? " contains-active" : "");
@@ -1668,7 +1686,7 @@ function renderUserFolder(unit, wtByParent, currentSlug, currentDmUserId) {
1668
1686
  // Processing dot
1669
1687
  var fStatusDot = document.createElement("span");
1670
1688
  fStatusDot.className = "icon-strip-status";
1671
- if (anyProcessing) fStatusDot.classList.add("processing");
1689
+ if (folderActivityCls) fStatusDot.classList.add(folderActivityCls);
1672
1690
  headerEl.appendChild(fStatusDot);
1673
1691
 
1674
1692
  // Unread badge
@@ -1822,13 +1840,21 @@ function renderWorktreeGroup(p, worktrees, currentSlug, currentDmUserId) {
1822
1840
  folder.dataset.parentSlug = p.slug;
1823
1841
  if (wtCollapsed[p.slug]) folder.classList.add("collapsed");
1824
1842
 
1825
- if (!p.isProcessing) {
1826
- for (var wpi = 0; wpi < worktrees.length; wpi++) {
1827
- if (worktrees[wpi].isProcessing) { p.isProcessing = true; break; }
1843
+ // lr-66c118: replaces the prior in-place mutation of the shared project
1844
+ // object's processing flag (see createIconItem's activityOverride doc
1845
+ // comment for why that was wrong). activityOverride carries whichever raw
1846
+ // item (parent or a worktree) is the rollup's own winner, so
1847
+ // createIconItem's own sessionActivity() call still does the real
1848
+ // derivation — no double-derivation, no raw property read here.
1849
+ var worktreeGroupItems = [p].concat(worktrees);
1850
+ var worktreeWinner = worktreeGroupItems[0];
1851
+ for (var wpi = 1; wpi < worktreeGroupItems.length; wpi++) {
1852
+ if (sessionActivity(worktreeGroupItems[wpi], null, { ignoreUnread: true }).active) {
1853
+ worktreeWinner = worktreeGroupItems[wpi];
1854
+ break;
1828
1855
  }
1829
1856
  }
1830
-
1831
- var header = createIconItem(p, currentSlug);
1857
+ var header = createIconItem(p, currentSlug, worktreeWinner);
1832
1858
  header.classList.add("folder-header");
1833
1859
  (function (slug, name, elem) {
1834
1860
  elem.addEventListener("contextmenu", function (e) {
@@ -1884,7 +1910,8 @@ function renderWorktreeGroup(p, worktrees, currentSlug, currentDmUserId) {
1884
1910
 
1885
1911
  var wtStatus = document.createElement("span");
1886
1912
  wtStatus.className = "icon-strip-status";
1887
- if (wt.isProcessing) wtStatus.classList.add("processing");
1913
+ var wtActivityCls = indicatorClass(sessionActivity(wt, null, { ignoreUnread: true }));
1914
+ if (wtActivityCls) wtStatus.classList.add(wtActivityCls);
1888
1915
  wtEl.appendChild(wtStatus);
1889
1916
 
1890
1917
  var tooltipText = wt.name;
@@ -2020,9 +2047,10 @@ function createMobileProjectItem(p, currentSlug, isWorktree) {
2020
2047
  name.textContent = p.name;
2021
2048
  el.appendChild(name);
2022
2049
 
2023
- if (p.isProcessing) {
2050
+ var mProjActivityCls = indicatorClass(sessionActivity(p, null, { ignoreUnread: true }));
2051
+ if (mProjActivityCls) {
2024
2052
  var dot = document.createElement("span");
2025
- dot.className = "mobile-project-processing";
2053
+ dot.className = "mobile-project-processing " + mProjActivityCls;
2026
2054
  el.appendChild(dot);
2027
2055
  }
2028
2056