@clagentic/console 1.9.0-beta.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/project.js CHANGED
@@ -233,8 +233,8 @@ function createProjectContext(opts) {
233
233
 
234
234
  function getLinuxUserForWs(ws) {
235
235
  if (!osUsers) return null;
236
- if (!ws._clayUser || !ws._clayUser.linuxUser) return null;
237
- return ws._clayUser.linuxUser;
236
+ if (!ws._clagenticUser || !ws._clagenticUser.linuxUser) return null;
237
+ return ws._clagenticUser.linuxUser;
238
238
  }
239
239
 
240
240
  // Cache resolved OS user info to avoid repeated getent calls
@@ -255,8 +255,8 @@ function createProjectContext(opts) {
255
255
 
256
256
  function getOsUserInfoForReq(req) {
257
257
  if (!osUsers) return null;
258
- if (!req._clayUser || !req._clayUser.linuxUser) return null;
259
- var linuxUser = req._clayUser.linuxUser;
258
+ if (!req._clagenticUser || !req._clagenticUser.linuxUser) return null;
259
+ var linuxUser = req._clagenticUser.linuxUser;
260
260
  if (osUserInfoCache[linuxUser]) return osUserInfoCache[linuxUser];
261
261
  try {
262
262
  var info = resolveOsUserInfo(linuxUser);
@@ -345,7 +345,7 @@ function createProjectContext(opts) {
345
345
  function sendToAdmins(obj) {
346
346
  var data = JSON.stringify(obj);
347
347
  for (var ws of clients) {
348
- if (ws.readyState === 1 && ws._clayUser && ws._clayUser.role === "admin") ws.send(data);
348
+ if (ws.readyState === 1 && ws._clagenticUser && ws._clagenticUser.role === "admin") ws.send(data);
349
349
  }
350
350
  }
351
351
 
@@ -354,8 +354,8 @@ function createProjectContext(opts) {
354
354
  var seen = {};
355
355
  var userList = [];
356
356
  for (var c of clients) {
357
- if (!c._clayUser) continue;
358
- var u = c._clayUser;
357
+ if (!c._clagenticUser) continue;
358
+ var u = c._clagenticUser;
359
359
  if (seen[u.id]) continue;
360
360
  seen[u.id] = true;
361
361
  var p = u.profile || {};
@@ -388,7 +388,7 @@ function createProjectContext(opts) {
388
388
  stampActivityLocalId(sessionId, obj);
389
389
  var data = JSON.stringify(obj);
390
390
  for (var ws of clients) {
391
- if (ws.readyState === 1 && ws._clayActiveSession === sessionId) {
391
+ if (ws.readyState === 1 && ws._clagenticActiveSession === sessionId) {
392
392
  ws.send(data);
393
393
  }
394
394
  }
@@ -398,7 +398,7 @@ function createProjectContext(opts) {
398
398
  stampActivityLocalId(sessionId, obj);
399
399
  var data = JSON.stringify(obj);
400
400
  for (var ws of clients) {
401
- if (ws !== sender && ws.readyState === 1 && ws._clayActiveSession === sessionId) {
401
+ if (ws !== sender && ws.readyState === 1 && ws._clagenticActiveSession === sessionId) {
402
402
  ws.send(data);
403
403
  }
404
404
  }
@@ -433,7 +433,7 @@ function createProjectContext(opts) {
433
433
  sendTo: sendTo,
434
434
  sendEach: function (fn) {
435
435
  for (var ws of clients) {
436
- var user = ws._clayUser;
436
+ var user = ws._clagenticUser;
437
437
  var filterFn = null;
438
438
  if (user) {
439
439
  filterFn = (function (u) {
@@ -512,7 +512,7 @@ function createProjectContext(opts) {
512
512
  // Apply to all connected clients' active sessions
513
513
  for (var c of clients) {
514
514
  if (c.readyState !== 1) continue;
515
- var sid = c._clayActiveSession || null;
515
+ var sid = c._clagenticActiveSession || null;
516
516
  var active = loadContextSources(slug, sid);
517
517
  if (active.indexOf(key) === -1) {
518
518
  active.push(key);
@@ -526,7 +526,7 @@ function createProjectContext(opts) {
526
526
  var key = "tab:" + tabId;
527
527
  for (var c of clients) {
528
528
  if (c.readyState !== 1) continue;
529
- var sid = c._clayActiveSession || null;
529
+ var sid = c._clagenticActiveSession || null;
530
530
  var active = loadContextSources(slug, sid);
531
531
  var idx = active.indexOf(key);
532
532
  if (idx !== -1) {
@@ -677,7 +677,7 @@ function createProjectContext(opts) {
677
677
  _connection.handleConnection(ws, wsUser, handleMessage, handleDisconnection);
678
678
 
679
679
  // Initialize local MCP when a localhost client connects
680
- if (ws._clayLocal && _localMcp && !_localMcp.isReady()) {
680
+ if (ws._clagenticLocal && _localMcp && !_localMcp.isReady()) {
681
681
  _localMcp.initialize(function () {
682
682
  // Rebuild proxy servers and broadcast state when local servers are ready
683
683
  _mcp.rebuildAndBroadcast();
@@ -687,7 +687,7 @@ function createProjectContext(opts) {
687
687
 
688
688
  // --- WS message handler ---
689
689
  function getSessionForWs(ws) {
690
- return sm.sessions.get(ws._clayActiveSession) || null;
690
+ return sm.sessions.get(ws._clagenticActiveSession) || null;
691
691
  }
692
692
 
693
693
  // --- Schedule / cancel a message (used by WS handler and auto-continue) ---
@@ -872,10 +872,10 @@ function createProjectContext(opts) {
872
872
  function broadcastPresence() {
873
873
  var presence = {};
874
874
  for (var c of clients) {
875
- if (!c._clayUser || !c._clayActiveSession) continue;
876
- var sid = c._clayActiveSession;
875
+ if (!c._clagenticUser || !c._clagenticActiveSession) continue;
876
+ var sid = c._clagenticActiveSession;
877
877
  if (!presence[sid]) presence[sid] = [];
878
- var u = c._clayUser;
878
+ var u = c._clagenticUser;
879
879
  var p = u.profile || {};
880
880
  // Deduplicate: skip if this user is already listed for this session
881
881
  var dominated = false;
@@ -1285,8 +1285,8 @@ function createProjectContext(opts) {
1285
1285
  var seen = {};
1286
1286
  var onlineUsers = [];
1287
1287
  for (var c of clients) {
1288
- if (!c._clayUser) continue;
1289
- var u = c._clayUser;
1288
+ if (!c._clagenticUser) continue;
1289
+ var u = c._clagenticUser;
1290
1290
  if (seen[u.id]) continue;
1291
1291
  seen[u.id] = true;
1292
1292
  var p = u.profile || {};
@@ -1355,8 +1355,8 @@ function createProjectContext(opts) {
1355
1355
  var user = usersModule.findUserById(userId);
1356
1356
  if (!user) return;
1357
1357
  for (var ws of clients) {
1358
- if (ws._clayUser && ws._clayUser.id === userId) {
1359
- ws._clayUser = user;
1358
+ if (ws._clagenticUser && ws._clagenticUser.id === userId) {
1359
+ ws._clagenticUser = user;
1360
1360
  }
1361
1361
  }
1362
1362
  broadcastClientCount();
package/lib/public/app.js CHANGED
@@ -67,7 +67,6 @@ import { initDm, openDm as _dmOpenDm, enterDmMode as _dmEnterDmMode, exitDmMode
67
67
  import { initMention, handleMentionStart, handleMentionStream, handleMentionDone, handleMentionError, handleMentionActivity, renderMentionUser, renderMentionResponse } from './modules/mention.js';
68
68
  import { initTeamPanel } from './modules/team-panel.js';
69
69
  import { initDiagnostics } from './modules/diagnostics.js';
70
- import { getActivityEdgeLedger } from './modules/activity-latch.js';
71
70
 
72
71
  // --- Base path for multi-project routing ---
73
72
  var slugMatch = location.pathname.match(/^\/p\/([a-z0-9_-]+)/);
@@ -1035,11 +1034,16 @@ import { getActivityEdgeLedger } from './modules/activity-latch.js';
1035
1034
  // --- Diagnostics panel (lr-8294, epic lr-1a52) ---
1036
1035
  initDiagnostics();
1037
1036
 
1038
- // lr-58c813: expose the client-side activity-edge accept/reject ledger for
1039
- // production retrieval without a debugger — open devtools console and run
1040
- // `window.__clagenticActivityLedger()`. Read-only accessor over a plain
1041
- // counter object (activity-latch.js); does not affect rendering.
1042
- window.__clagenticActivityLedger = getActivityEdgeLedger;
1037
+ // lr-5edd64: the lr-58c813 client-side activity-edge accept/reject ledger
1038
+ // (window.__clagenticActivityLedger(), activity-latch.js) is removed along
1039
+ // with the client-local 'processing' latch it existed to observe —
1040
+ // 'processing' is a pure projection of server-authoritative per-session
1041
+ // state now (see app-messages.js's session_list/session_switched
1042
+ // handlers), so there is no edge-accept/reject decision left to ledger.
1043
+ // The SEPARATE server-side lr-58c813 divergence probe (lib/sdk-bridge.js,
1044
+ // session.isProcessing vs the token registry) is untouched by this
1045
+ // removal — it is reachable via `clagentic-console --activity-diagnostics`
1046
+ // (lr-8b476f), not this devtools hook.
1043
1047
 
1044
1048
  // --- Messages module (uses direct imports, no ctx injection needed) ---
1045
1049
 
@@ -745,6 +745,12 @@
745
745
  color: var(--text-dimmer);
746
746
  }
747
747
 
748
+ /* lr-93e3c8: visible error state for save-status spans (e.g. Advanced >
749
+ Memory), matching the same class other save-status spans already use. */
750
+ .ps-save-status-error {
751
+ color: var(--error, #f38ba8);
752
+ }
753
+
748
754
  /* Environment notice */
749
755
  .ps-env-notice {
750
756
  display: flex;
@@ -696,6 +696,15 @@
696
696
  color: #3fb950;
697
697
  }
698
698
 
699
+ /* --- Badge variant: proxy-terminated HTTPS (lr-20e71c) ---
700
+ Distinct from settings-badge-green: TLS is genuinely active, but a
701
+ reverse proxy terminates it rather than the daemon itself. Reuses the
702
+ existing --warning semantic token rather than introducing a new color. */
703
+ .settings-badge.settings-badge-proxy {
704
+ background: var(--warning-bg);
705
+ color: var(--warning);
706
+ }
707
+
699
708
  /* --- Nav danger item (Shutdown) --- */
700
709
  .settings-nav-item.settings-nav-danger {
701
710
  color: var(--error);
@@ -1421,11 +1421,17 @@
1421
1421
  <label class="settings-label" for="settings-mem-available-min">Min available memory (MB)</label>
1422
1422
  <div class="settings-hint">Minimum system memory required to start a new session. Increase if you experience OOM restarts.</div>
1423
1423
  <input type="number" id="settings-mem-available-min" class="settings-budget-input" min="0" max="65536" step="128" value="1024" style="margin-top: 8px; width: 120px;">
1424
+ <div class="settings-hint" id="settings-mem-available-min-default-note" style="margin-top: 4px;"></div>
1424
1425
  </div>
1425
1426
  <div class="settings-field" style="margin-top: 16px;">
1426
1427
  <label class="settings-label" for="settings-tokens-per-mb-headroom">Context tokens per MB headroom</label>
1427
- <div class="settings-hint">Controls how large a session's context can grow relative to available cgroup memory. Lower = more conservative. Default (67) is calibrated for claude-opus-4 at 1M context.</div>
1428
- <input type="number" id="settings-tokens-per-mb-headroom" class="settings-budget-input" min="10" max="500" step="1" value="67" style="margin-top: 8px; width: 120px;">
1428
+ <div class="settings-hint">Controls how large a session's context can grow relative to available cgroup memory. Lower = more conservative. Default (240) is derived from this daemon's own observed cgroup memory.peak against a confirmed large-session token count (lr-93e3c8) -- not a fixed model assumption.</div>
1429
+ <input type="number" id="settings-tokens-per-mb-headroom" class="settings-budget-input" min="10" max="500" step="1" value="240" style="margin-top: 8px; width: 120px;">
1430
+ <div class="settings-hint" id="settings-tokens-per-mb-headroom-default-note" style="margin-top: 4px;"></div>
1431
+ </div>
1432
+ <div class="ps-textarea-actions" style="margin-top: 8px;">
1433
+ <button class="settings-btn-sm" id="ss-memory-save-btn">Save</button>
1434
+ <span class="ps-save-status" id="ss-memory-save-status"></span>
1429
1435
  </div>
1430
1436
  </div>
1431
1437
  </div>
@@ -1,32 +1,32 @@
1
- // activity-latch.js - Pure decision logic for the client-local 'processing'
2
- // activity-indicator latch.
1
+ // activity-latch.js - Pure decision logic for session-scoping a
2
+ // session-addressed WS edge to the client's currently-focused session.
3
3
  //
4
- // 'processing' (the field app-favicon.js's initActivityFooter subscribes
5
- // to) is a client-local edge latch with no server reconciliation —
6
- // app-messages.js's status/done/auth_required handlers wrote it
7
- // unconditionally, with no knowledge of which session a message actually
8
- // belongs to. A background session's status:"processing" could raise the
9
- // FOCUSED session's latch with no done ever routed back to clear it
10
- // (stuck-ON) — the inverse of the historical stuck-OFF symptom this
11
- // codebase has previously fixed for the transcript footer.
4
+ // lr-5edd64: this module used to also own the client-local 'processing'
5
+ // activity-indicator latch's staleness backstop (createActivityStaleBackstop)
6
+ // and an accept/reject ledger built to observe that latch
7
+ // (recordActivityEdgeDecision/getActivityEdgeLedger, lr-58c813). Both are
8
+ // deleted here: 'processing' (the field app-favicon.js's initActivityFooter
9
+ // subscribes to) is no longer an independently-written client-local latch —
10
+ // it is a pure PROJECTION of server-authoritative per-session state
11
+ // (app-messages.js's session_list/session_switched handlers, deriving via
12
+ // activity-state.js's sessionActivity()). A staleness backstop and a ledger
13
+ // both existed solely to defend that latch against a missed edge; with
14
+ // nothing left to defend, keeping them would make them load-bearing again
15
+ // for no real behavior (MILLER lr-5edd64 comment #2, Q6).
12
16
  //
13
- // This module extracts the two DECISION functions those handlers need —
14
- // "should this session-scoped edge apply to the currently-focused session?"
15
- // and "when should the staleness backstop timer arm/fire/clear?" — as pure,
16
- // DOM-free logic. app-messages.js and app-favicon.js are both DOM-heavy
17
- // (app-favicon.js's import graph reaches theme.js <-> markdown.js, which
18
- // has a circular-import ordering hazard around mermaid theme init that
19
- // makes them unimportable in a plain Node test process without a much
20
- // heavier harness than this repo carries — see the test file for this
21
- // module's header comment). Carving the pure decision logic out here —
22
- // mirroring how activity-state.js was carved out of the sidebar/hub render
23
- // sites for the same reason — is what makes this fix's core logic
24
- // behaviorally testable at all, rather than only provable by source-text
25
- // inspection.
17
+ // shouldApplyActivityEdge itself remains: app-messages.js's status handler
18
+ // still uses it to session-scope a DIFFERENT, non-render concern —
19
+ // sessionIsProcessing (dead-session-todo-compaction) and the pre-thinking-
20
+ // dots clear — both of which target whatever session this client is
21
+ // currently viewing, so a background session's status:"processing" must
22
+ // still not touch them. That guard was never specific to the 'processing'
23
+ // latch; it is a general "does this session-addressed edge belong to the
24
+ // session I'm currently looking at?" predicate, reused here for its second,
25
+ // still-live purpose.
26
26
 
27
27
  /**
28
- * Should a session-scoped activity-latch edge (status:"processing",
29
- * done, auth_required) be applied to the client's current local state?
28
+ * Should a session-scoped edge (e.g. status:"processing") be applied to
29
+ * state the client currently associates with its focused session?
30
30
  *
31
31
  * Mirrors the lr-0827ba pattern already used by scheduled_message_*
32
32
  * handlers: a message with no localId (older server, or a message type
@@ -43,117 +43,3 @@
43
43
  export function shouldApplyActivityEdge(msgLocalId, activeSessionId) {
44
44
  return msgLocalId == null || msgLocalId === activeSessionId;
45
45
  }
46
-
47
- // ---------------------------------------------------------------------------
48
- // lr-58c813: accept/reject ledger — instrumentation only, no decision logic.
49
- //
50
- // MILLER (lr-96e7da) hypothesized cross-session crosstalk on this latch at
51
- // 0.5 confidence and flagged it never instrumented to proof; the symptom
52
- // recurred (lr-5edd64) in code that already has this guard. This ledger
53
- // records what shouldApplyActivityEdge actually decided at runtime, at the
54
- // three call sites in app-messages.js (status/done/auth_required), WITHOUT
55
- // changing which branch any of them take — recordActivityEdgeDecision is
56
- // called for its side effect (counting) only, after the real decision has
57
- // already been made by shouldApplyActivityEdge, never in place of it.
58
- //
59
- // The fail-open branch (msgLocalId == null) is counted SEPARATELY per the
60
- // task spec: it is a deliberate back-compat path, but a live send site that
61
- // still fails to stamp localId would silently re-enable the pre-fix
62
- // unguarded write through this exact branch, and no existing test would
63
- // notice. A nonzero count here in production is the actionable signal.
64
- //
65
- // Bounded: this is a plain in-memory counter object, reset on page
66
- // load/reload (no persistence, no growth — four integers total, no per-
67
- // event array). It does not log to the console on every message (that would
68
- // flood devtools on a chatty session); callers read the totals on demand via
69
- // getActivityEdgeLedger(), e.g. from devtools or a future diagnostics-panel
70
- // hook — never a per-event stream.
71
-
72
- var _activityEdgeLedger = {
73
- accepted: 0,
74
- rejected: 0,
75
- acceptedFailOpen: 0, // subset of `accepted`: msgLocalId == null specifically
76
- };
77
-
78
- /**
79
- * Record the outcome of a shouldApplyActivityEdge call for the ledger.
80
- * Pure bookkeeping — does not itself decide anything and must be called
81
- * with the SAME inputs the real decision already used, after the fact.
82
- *
83
- * @param {string} msgType - "status" | "done" | "auth_required"
84
- * @param {number|string|null|undefined} msgLocalId
85
- * @param {number|string|null|undefined} activeSessionId
86
- * @param {boolean} accepted - the shouldApplyActivityEdge result already computed by the caller
87
- */
88
- export function recordActivityEdgeDecision(msgType, msgLocalId, activeSessionId, accepted) {
89
- if (accepted) {
90
- _activityEdgeLedger.accepted++;
91
- if (msgLocalId == null) _activityEdgeLedger.acceptedFailOpen++;
92
- } else {
93
- _activityEdgeLedger.rejected++;
94
- }
95
- }
96
-
97
- /** Read-only snapshot of the ledger totals (does not reset). */
98
- export function getActivityEdgeLedger() {
99
- return {
100
- accepted: _activityEdgeLedger.accepted,
101
- rejected: _activityEdgeLedger.rejected,
102
- acceptedFailOpen: _activityEdgeLedger.acceptedFailOpen,
103
- };
104
- }
105
-
106
- /** Test-only reset so ledger tests don't leak counts across cases. */
107
- export function _resetActivityEdgeLedgerForTest() {
108
- _activityEdgeLedger = { accepted: 0, rejected: 0, acceptedFailOpen: 0 };
109
- }
110
-
111
- /**
112
- * Staleness-backstop timer state machine. A single timer is
113
- * armed on a genuine 0->1 'processing' transition and disarmed on every
114
- * 1->0 transition — never a recurring poll, never more than one in-flight
115
- * timer regardless of how many turns/sessions run. Kept here as pure state
116
- * transitions (arm/clear/shouldFire) so the bound (one timer, one-shot,
117
- * re-armed only by a fresh transition) is asserted directly rather than
118
- * only described in a comment.
119
- */
120
- export function createActivityStaleBackstop(opts) {
121
- var delayMs = (opts && opts.delayMs) || 5 * 60 * 1000; // mirrors sdk-bridge.js ACTIVITY_STALE_MS
122
- var setTimeoutFn = (opts && opts.setTimeout) || setTimeout;
123
- var clearTimeoutFn = (opts && opts.clearTimeout) || clearTimeout;
124
- var onFire = (opts && opts.onFire) || function () {};
125
- var timer = null;
126
- var armCount = 0; // exposed for the "never polls / never stacks" test assertion
127
-
128
- function clear() {
129
- if (timer) {
130
- clearTimeoutFn(timer);
131
- timer = null;
132
- }
133
- }
134
-
135
- function arm() {
136
- clear(); // at most one in-flight timer, ever — re-arming replaces, never stacks
137
- armCount++;
138
- timer = setTimeoutFn(function () {
139
- timer = null;
140
- onFire();
141
- }, delayMs);
142
- }
143
-
144
- /** Called on every store 'processing' transition (state !== prev only). */
145
- function onTransition(nowProcessing) {
146
- if (nowProcessing) {
147
- arm();
148
- } else {
149
- clear();
150
- }
151
- }
152
-
153
- return {
154
- onTransition: onTransition,
155
- isArmed: function () { return timer !== null; },
156
- armCount: function () { return armCount; },
157
- _clearForTest: clear,
158
- };
159
- }
@@ -61,12 +61,19 @@
61
61
  * self-vs-other tone. Omit (or pass null/undefined) in single-user mode —
62
62
  * every session then renders as 'self'.
63
63
  * @param {object} [opts]
64
- * @param {boolean} [opts.ignoreUnread] - project-level dots (icon strip,
65
- * mobile project rows, folder headers, home-hub project summary) have
66
- * their OWN separate unread badge affordance and have never shown alert
67
- * red on the dot itself — set true there so passing the raw project
68
- * object (which does carry .unread, for the badge) doesn't also flip the
69
- * dot to alert tone. Session-level dots never set this.
64
+ * @param {boolean} [opts.ignoreUnread] - suppress alert/unread from flipping
65
+ * `.active`/tone, for a consumer that has no unread-alert affordance of
66
+ * its own. Project-level dots (icon strip, mobile project rows, folder
67
+ * headers, home-hub project summary) are the original case: they have
68
+ * their OWN separate unread badge and have never shown alert red on the
69
+ * dot itself, so passing the raw project object (which does carry
70
+ * .unread, for the badge) must not also flip the dot to alert tone.
71
+ * lr-5edd64: the transcript footer's "is a turn running" projection
72
+ * (app-messages.js's session_list handler) is a second, SESSION-level
73
+ * caller of this — it is a processing indicator, not a dot with its own
74
+ * alert affordance, so unread must not pin it on. Most other
75
+ * session-level dots (sidebar rows, hub recent-session rows) still want
76
+ * full alert precedence and must NOT set this.
70
77
  * @returns {ActivityState}
71
78
  */
72
79
  export function sessionActivity(sess, currentUserId, opts) {
@@ -91,6 +98,37 @@ export function sessionActivity(sess, currentUserId, opts) {
91
98
  : { active: true, alert: false, tone: "self", label: "Active" };
92
99
  }
93
100
 
101
+ /**
102
+ * lr-5edd64: the exact derivation app-messages.js's session_list handler
103
+ * performs to project the transcript footer's 'processing' field from a
104
+ * session_list broadcast — extracted here (a pure, DOM-free module) rather
105
+ * than left inline, specifically so a test can import and exercise the
106
+ * REAL production logic directly. app-messages.js is not importable under
107
+ * plain Node (its import graph reaches the theme.js<->markdown.js circular
108
+ * boot hazard — see activity-latch-lr-96e7da.test.js's header), so without
109
+ * this extraction a behavioral test of this projection would necessarily
110
+ * be testing a hand-copied reimplementation, not the code that actually
111
+ * ships. Bounded to the entry matching activeSessionId; { ignoreUnread:
112
+ * true } is REQUIRED here — see sessionActivity's ignoreUnread doc above
113
+ * for why (PEACHES finding 2, this task's 8th recurrence): the footer is a
114
+ * turn-running indicator, not an unread-alert surface.
115
+ *
116
+ * @param {Array<object>} sessions - msg.sessions from a session_list broadcast.
117
+ * @param {string|number|null} activeSessionId
118
+ * @returns {{found: boolean, active: boolean}} found=false means no entry
119
+ * matched activeSessionId (or activeSessionId is null) — caller must not
120
+ * apply a projection in that case.
121
+ */
122
+ export function deriveSessionListProcessing(sessions, activeSessionId) {
123
+ if (activeSessionId == null || !sessions) return { found: false, active: false };
124
+ for (var i = 0; i < sessions.length; i++) {
125
+ if (sessions[i].id === activeSessionId) {
126
+ return { found: true, active: sessionActivity(sessions[i], null, { ignoreUnread: true }).active };
127
+ }
128
+ }
129
+ return { found: false, active: false };
130
+ }
131
+
94
132
  // Precedence used by both sessionActivity's tone choice above and
95
133
  // rollupActivity's OR-reduce below. Higher wins. 'self' outranks 'other'
96
134
  // per the locked rollup rule; 'alert' outranks everything.
@@ -76,9 +76,12 @@ export function initConnection() {
76
76
  // --- Reactive UI sync for connected/processing state ---
77
77
  store.subscribe(['connected', 'processing'], function (state, prev) {
78
78
  // Status dot (depends on both connected and processing). lr-66c118:
79
- // state.processing is this client's own live turn-in-flight signal —
80
- // always tone 'self' — routed through the same derivation every other
81
- // dot uses rather than writing '.processing' independently.
79
+ // routed through the same derivation every other dot uses rather than
80
+ // writing '.processing' independently. lr-5edd64: state.processing is
81
+ // now a projection of the focused session's server-authoritative
82
+ // isProcessing (app-messages.js's session_list/session_switched
83
+ // handlers) rather than a client-local edge latch — always tone 'self'
84
+ // here since this dot represents the viewing user's own connection.
82
85
  if (state.connected !== prev.connected || state.processing !== prev.processing) {
83
86
  var dot = getStatusDot();
84
87
  if (dot) {
@@ -145,10 +148,26 @@ export function initConnection() {
145
148
  });
146
149
  }
147
150
 
148
- // setStatus: now just sets state. UI sync is handled by the subscriber above.
151
+ // setStatus: connection lifecycle, plus the two remaining legitimate
152
+ // session-scoped PUSH raises of 'processing' (lr-5edd64). The status/done/
153
+ // auth_required handlers no longer call this with "processing"/"connected"
154
+ // to drive it — that was the client-local latch with no reconciliation
155
+ // MILLER's lr-5edd64 diagnosis identified. 'processing' is now primarily a
156
+ // PROJECTION: re-derived from the session_list entry for the active session
157
+ // and the session_switched snapshot (app-messages.js) on every broadcast,
158
+ // regardless of whether anything pushed it in between — so even if one of
159
+ // the two remaining pushes below is ever missed or mis-scoped, the next
160
+ // session_list/session_switched self-corrects it (comment #2 Q5's push+
161
+ // query requirement). scheduled_message_sent and auto_continue_fired keep
162
+ // calling setStatus("processing") here because they are genuine "a turn
163
+ // just started for the focused session" server pushes, same shape as the
164
+ // deleted status:"processing" push, just for two different message types —
165
+ // deleting the push entirely (rather than just the previously-redundant
166
+ // status/done/auth_required copies of it) would leave a real WS event with
167
+ // no immediate raise until the next session_list tick.
149
168
  export function setStatus(status) {
150
169
  if (status === "connected") {
151
- store.set({ connected: true, processing: false });
170
+ store.set({ connected: true });
152
171
  } else if (status === "processing") {
153
172
  store.set({ processing: true });
154
173
  } else {