@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
@@ -0,0 +1,159 @@
1
+ // activity-latch.js - Pure decision logic for the client-local 'processing'
2
+ // activity-indicator latch.
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.
12
+ //
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.
26
+
27
+ /**
28
+ * Should a session-scoped activity-latch edge (status:"processing",
29
+ * done, auth_required) be applied to the client's current local state?
30
+ *
31
+ * Mirrors the lr-0827ba pattern already used by scheduled_message_*
32
+ * handlers: a message with no localId (older server, or a message type
33
+ * that was never session-scoped) always applies, matching pre-fix
34
+ * behavior; a message WITH a localId only applies when it matches the
35
+ * session the client currently has focused.
36
+ *
37
+ * @param {number|string|null|undefined} msgLocalId - localId on the
38
+ * incoming message, or null/undefined if the server didn't stamp one.
39
+ * @param {number|string|null|undefined} activeSessionId - the client's
40
+ * currently-focused session id (store.get('activeSessionId')).
41
+ * @returns {boolean}
42
+ */
43
+ export function shouldApplyActivityEdge(msgLocalId, activeSessionId) {
44
+ return msgLocalId == null || msgLocalId === activeSessionId;
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
+ }
@@ -0,0 +1,157 @@
1
+ // activity-state.js - Single frontend derivation module for activity
2
+ // indicator state (dots) across every render surface.
3
+ //
4
+ // Replaces 21 previously-divergent render sites across sidebar-sessions.js,
5
+ // sidebar-projects.js, sidebar-mobile.js, app-home-hub.js, app-projects.js,
6
+ // and the 3 different state sources they used to read directly (the
7
+ // per-session processing flag, the client's own live connection processing
8
+ // flag, and setActivity) with ONE derivation:
9
+ //
10
+ // sessionActivity(sess, currentUserId, opts) -> { active, alert, tone, label }
11
+ // rollupActivity(list, currentUserId, opts) -> same shape, OR-reduced
12
+ // indicatorClass(state) -> the one place a CSS class is chosen
13
+ //
14
+ // Design notes:
15
+ //
16
+ // - Precedence (LOCKED, operator ruling lr-0aa7b6, promoted here from its
17
+ // former home-hub-only special case): alert > processing > live > idle.
18
+ // "live" and "processing" collapse to the same visual state today (no
19
+ // separate 'live' CSS class exists anywhere in the codebase — the
20
+ // home-hub.css comment claiming 4 states was aspirational, not real; see
21
+ // indicatorClass() below for the reconciliation). tone: 'alert' | 'self' |
22
+ // 'other' | 'idle'.
23
+ //
24
+ // - Multi-user tone (operator ruling, epic lr-a6a449): a session/project
25
+ // whose activity belongs to a DIFFERENT user renders in a third,
26
+ // non-red/non-green tone ('other'), never conflated with your own
27
+ // ('self'). Rollup rule: self wins over other when a folder/project
28
+ // contains both — your own work is the more actionable signal, same
29
+ // spirit as the locked alert-over-processing precedence.
30
+ //
31
+ // - This module is pure: no DOM, no store import, no WS. Callers own
32
+ // rendering (indicatorClass gives the CSS class; callers still build the
33
+ // element/title/etc.). This keeps activity-state.js testable as plain
34
+ // data transforms and reusable from any surface (sidebar, mobile sheet,
35
+ // home hub) without an import cycle back into store.js or a render module.
36
+
37
+ /**
38
+ * @typedef {Object} ActivityState
39
+ * @property {boolean} active - true if there is any live activity to show a dot for.
40
+ * @property {boolean} alert - true if this represents unread/alert state (wins over active).
41
+ * @property {"alert"|"self"|"other"|"idle"} tone - which color family to render.
42
+ * @property {string} label - short human label for a title/tooltip attribute.
43
+ */
44
+
45
+ /**
46
+ * Derive activity state for a single session-shaped object. Callers pass the
47
+ * RAW session/project object straight through — activity-state.js is the
48
+ * ONLY place in lib/public/modules/ allowed to read .isProcessing (CI
49
+ * assertion #2); render sites must never read it themselves, even to build
50
+ * a wrapper object for this function.
51
+ *
52
+ * Accepts any object carrying the fields already on the wire for a session
53
+ * list item (lib/sessions.js mapSessionForClient): isProcessing, unread,
54
+ * ownerId. Also accepts the project-shaped objects used by the icon strip /
55
+ * mobile sheets (isProcessing, unread) — ownerId is absent there, which
56
+ * correctly falls back to tone 'self' since a project has no single owner
57
+ * distinguishing "mine" from "someone else's" the way a session does.
58
+ *
59
+ * @param {object} sess - session or project object with isProcessing/unread/ownerId.
60
+ * @param {string|number|null} [currentUserId] - the viewing user's id, for
61
+ * self-vs-other tone. Omit (or pass null/undefined) in single-user mode —
62
+ * every session then renders as 'self'.
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.
70
+ * @returns {ActivityState}
71
+ */
72
+ export function sessionActivity(sess, currentUserId, opts) {
73
+ if (!sess) {
74
+ return { active: false, alert: false, tone: "idle", label: "Idle" };
75
+ }
76
+
77
+ var alert = !(opts && opts.ignoreUnread) && (sess.unread || 0) > 0;
78
+ var active = !!sess.isProcessing;
79
+
80
+ if (alert) {
81
+ return { active: true, alert: true, tone: "alert", label: "Unread activity" };
82
+ }
83
+
84
+ if (!active) {
85
+ return { active: false, alert: false, tone: "idle", label: "Idle" };
86
+ }
87
+
88
+ var isOther = !!(sess.ownerId != null && currentUserId != null && sess.ownerId !== currentUserId);
89
+ return isOther
90
+ ? { active: true, alert: false, tone: "other", label: "Active (another user)" }
91
+ : { active: true, alert: false, tone: "self", label: "Active" };
92
+ }
93
+
94
+ // Precedence used by both sessionActivity's tone choice above and
95
+ // rollupActivity's OR-reduce below. Higher wins. 'self' outranks 'other'
96
+ // per the locked rollup rule; 'alert' outranks everything.
97
+ var TONE_RANK = { idle: 0, other: 1, self: 2, alert: 3 };
98
+
99
+ /**
100
+ * Roll up a list of already-derived (or raw session/project) items into a
101
+ * single ActivityState, replacing the 8 open-coded `anyProcessing` OR-loops
102
+ * this module supersedes.
103
+ *
104
+ * Accepts either raw session/project objects (in which case sessionActivity
105
+ * is applied per-item using the given currentUserId) or an array of
106
+ * ActivityState objects already produced by sessionActivity — the latter is
107
+ * useful when a caller has already computed per-item tone for other reasons
108
+ * and wants to fold the results without re-deriving.
109
+ *
110
+ * @param {Array<object|ActivityState>} list
111
+ * @param {string|number|null} [currentUserId]
112
+ * @param {object} [opts] - forwarded to sessionActivity() for each raw item;
113
+ * see its ignoreUnread doc. Ignored for items that are already derived
114
+ * ActivityState objects.
115
+ * @returns {ActivityState}
116
+ */
117
+ export function rollupActivity(list, currentUserId, opts) {
118
+ if (!list || list.length === 0) {
119
+ return { active: false, alert: false, tone: "idle", label: "Idle" };
120
+ }
121
+
122
+ var best = { active: false, alert: false, tone: "idle", label: "Idle" };
123
+ for (var i = 0; i < list.length; i++) {
124
+ var item = list[i];
125
+ var state = (item && typeof item.tone === "string" && typeof item.active === "boolean")
126
+ ? item
127
+ : sessionActivity(item, currentUserId, opts);
128
+ if (TONE_RANK[state.tone] > TONE_RANK[best.tone]) {
129
+ best = state;
130
+ }
131
+ }
132
+ return best;
133
+ }
134
+
135
+ // The 5 CSS class families this reconciles all key their "on" state off a
136
+ // bare ".processing" (or ".alert" for the home-hub dot) suffix appended to a
137
+ // per-surface base class. indicatorClass() returns ONLY that suffix (or ""
138
+ // for idle) — callers still own their own base class name, since the base
139
+ // classes themselves are not being unified (that would be a DOM/CSS
140
+ // restructure, out of scope for a derivation module) — only the STATE ->
141
+ // CLASS decision is centralized.
142
+ /**
143
+ * The one place a CSS class suffix is chosen from an ActivityState.
144
+ * @param {ActivityState} state
145
+ * @returns {string} "" | "processing" | "alert" | "other"
146
+ */
147
+ export function indicatorClass(state) {
148
+ if (!state || !state.active) return "";
149
+ if (state.tone === "alert") return "alert";
150
+ if (state.tone === "other") return "other";
151
+ // tone === "self": the reconciled state. home-hub.css's stale comment
152
+ // claimed 4 states (alert/processing/live/idle) but only ever shipped 3
153
+ // classes (.alert, .processing, bare/idle) — there is no separate "live"
154
+ // class anywhere in the codebase. "self" activity renders as ".processing"
155
+ // everywhere, matching what every surface already shipped.
156
+ return "processing";
157
+ }
@@ -4,7 +4,7 @@
4
4
  import { store } from './store.js';
5
5
  import { getWs, setWs } from './ws-ref.js';
6
6
  import { getStatusDot, getSendBtn } from './dom-refs.js';
7
- import { setSendBtnMode, blinkIO, setActivity } from './app-favicon.js';
7
+ import { setSendBtnMode, blinkIO } from './app-favicon.js';
8
8
  import { startLogoAnimation, stopLogoAnimation } from './console-logo.js';
9
9
  import { hasSendableContent } from './input.js';
10
10
  import { processMessage } from './app-messages.js';
@@ -14,6 +14,7 @@ import { resetTerminals } from './terminal.js';
14
14
  import { closeDmUserPicker } from './sidebar-users.js';
15
15
  import { openDm } from './app-dm.js';
16
16
  import { getPaletteVersion } from './command-palette.js';
17
+ import { sessionActivity, indicatorClass } from './activity-state.js';
17
18
 
18
19
  var reconnectTimer = null;
19
20
  var reconnectDelay = 100;
@@ -74,14 +75,18 @@ export function initConnection() {
74
75
 
75
76
  // --- Reactive UI sync for connected/processing state ---
76
77
  store.subscribe(['connected', 'processing'], function (state, prev) {
77
- // Status dot (depends on both connected and processing)
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.
78
82
  if (state.connected !== prev.connected || state.processing !== prev.processing) {
79
83
  var dot = getStatusDot();
80
84
  if (dot) {
81
85
  dot.className = "icon-strip-status";
82
86
  if (state.connected) {
83
87
  dot.classList.add("connected");
84
- if (state.processing) dot.classList.add("processing");
88
+ var connActivityCls = indicatorClass(sessionActivity({ isProcessing: state.processing }));
89
+ if (connActivityCls) dot.classList.add(connActivityCls);
85
90
  }
86
91
  }
87
92
  }
@@ -331,7 +336,8 @@ function openSocket(ticket) {
331
336
  if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
332
337
  closeDmUserPicker();
333
338
  setStatus("disconnected");
334
- setActivity(null);
339
+ // lr-66c118: the setActivity(null) clear formerly here is gone —
340
+ // setActivity collapsed to one optimistic raise (input.js), no manual clears.
335
341
  // lr-0446: Discard any pending cross-project session switch. If the WS
336
342
  // closed before the target project's session_list fired, the key is now
337
343
  // stale — leaving it would cause the *next* successful session_list (on
@@ -4,8 +4,10 @@
4
4
  import { refreshIcons } from './icons.js';
5
5
  import { store } from './store.js';
6
6
  import { getSendBtn, getStatusDot } from './dom-refs.js';
7
- import { onThemeChange } from './theme.js';
7
+ import { onThemeChange, getChatLayout } from './theme.js';
8
8
  import { getActivityEl, setActivityEl, addToMessages, scrollToBottom } from './app-rendering.js';
9
+ import { getWs } from './ws-ref.js';
10
+ import { createActivityStaleBackstop } from './activity-latch.js';
9
11
 
10
12
  // --- Module-owned state ---
11
13
  var faviconLink, faviconOrigHref, faviconCanvas, faviconCtx, faviconImg, faviconImgReady;
@@ -230,3 +232,88 @@ export function setActivity(text) {
230
232
  }
231
233
  }
232
234
 
235
+ // lr-6e20f7: the reactive clear setActivity's own removal branch (above) was
236
+ // designed for but never wired up — lr-66c118 deleted all 15 manual clear
237
+ // call sites (including every clear of this widget) on the assumption that
238
+ // "the widget's own reactive clear" would replace them, but no such
239
+ // subscriber was ever added. The widget was raised once at input.js's
240
+ // optimistic call and then never cleared again short of a full DOM wipe
241
+ // (resetClientState / prependOlderHistory), so it visibly stranded on-screen
242
+ // and was indistinguishable from the .thinking-item's own presence spinner —
243
+ // two indicators live at once (this task's SYMPTOM B).
244
+ //
245
+ // This subscriber makes the footer a DERIVED render of the same boolean the
246
+ // bottom bar/icon-strip status dot already uses (store.processing —
247
+ // app-connection.js's setStatus(), flipped true by the server's
248
+ // {type:"status", status:"processing"} at turn-start and false at
249
+ // done/auth_required/disconnect). That boolean already covers "literally
250
+ // anything" for THIS client's own turn: Claude has turn-wide isProcessing
251
+ // coverage for ordinary tools (sdk-message-processor.js module header), and
252
+ // status:"processing" is sent once at turn-start and stays true for the
253
+ // whole turn including any backgrounded Task/subagent activity — it only
254
+ // flips false at genuine turn-end (done) or auth_required/disconnect, all of
255
+ // which are real "nothing is happening" states. Subscribing here — rather
256
+ // than re-deriving from scratch — reuses the exact boolean already proven
257
+ // correct for the icon-strip dot instead of inventing a second one that
258
+ // could disagree with it.
259
+ //
260
+ // Gated to bubble layout only (mirrors input.js's optimistic-raise gate and
261
+ // showClaudePreThinking's channel-only gate in app-rendering.js) — the two
262
+ // footer renderers are mutually exclusive by design (wide-view <=> channel,
263
+ // theme.js getChatLayout/setChatLayout), so this must not fight
264
+ // .channel-pre-thinking for the same bottom-of-transcript slot in channel
265
+ // layout.
266
+ // Client-side staleness backstop, mirroring sdk-bridge.js's server-side
267
+ // ACTIVITY_STALE_MS (5 min) sweep for the registry. That server sweep can
268
+ // never repair THIS client-local latch — it sweeps the (already-correct)
269
+ // server registry, not any client state. Session-scoping the status/done/
270
+ // auth_required writers and reconciling on every session_switched snapshot
271
+ // (both elsewhere in this fix) close the known trigger paths; this is the
272
+ // backstop for an edge this fix's authors did not anticipate — a single
273
+ // timer, armed only on the 0->1 transition and disarmed on every 1->0
274
+ // transition, so it never polls per-tick and never accumulates more than
275
+ // one in-flight timer regardless of how many turns a session runs. On
276
+ // fire, it re-sends the EXISTING switch_session request for the
277
+ // currently-focused session (same message every sidebar click already
278
+ // sends) rather than inventing a new wire message — the server always
279
+ // answers with a fresh session_switched carrying the authoritative
280
+ // isProcessing (lib/sessions.js switchSession), which the reconciliation in
281
+ // app-messages.js's session_switched handler then applies. Bound: at most
282
+ // one re-request per ACTIVITY_STALE_BACKSTOP_MS per session-focus-duration,
283
+ // never a recurring poll — the timer is one-shot and only re-arms on a
284
+ // fresh 0->1 transition (a genuinely new turn), not on a fixed interval.
285
+ // Decision logic (arm/clear/one-shot-never-stacks) lives in the pure,
286
+ // directly-unit-tested activity-latch.js module — see its header comment
287
+ // for why (app-favicon.js's own import graph is not importable in a plain
288
+ // Node test process, so the behavioral proof lives against the pure
289
+ // module instead of this DOM-driving glue).
290
+ var _activityStaleBackstop = createActivityStaleBackstop({
291
+ onFire: function () {
292
+ // Only re-request if the latch is STILL true when the timer fires —
293
+ // a legitimate long-running turn re-arms nothing extra here (the
294
+ // request is one-shot, not a recurring poll); if the turn already
295
+ // ended, the 1->0 transition already cleared this timer, so reaching
296
+ // this callback at all means 'processing' has been true, unbroken,
297
+ // for the full backstop window.
298
+ if (!store.get('processing')) return;
299
+ var sid = store.get('activeSessionId');
300
+ var ws = getWs();
301
+ if (sid == null || !ws || ws.readyState !== 1) return;
302
+ ws.send(JSON.stringify({ type: "switch_session", id: sid }));
303
+ },
304
+ });
305
+
306
+ export function initActivityFooter() {
307
+ store.subscribe(['processing'], function (state, prev) {
308
+ if (state.processing === prev.processing) return;
309
+ _activityStaleBackstop.onTransition(state.processing);
310
+ if (getChatLayout() !== "channel") {
311
+ if (state.processing) {
312
+ setActivity("thinking");
313
+ } else {
314
+ setActivity(null);
315
+ }
316
+ }
317
+ });
318
+ }
319
+
@@ -11,6 +11,7 @@ import { openSchedulerToTab } from './scheduler.js';
11
11
  // playbook imports removed (Quick Start section removed from hub)
12
12
  import { exitDmMode } from './app-dm.js';
13
13
  import { openCommandPalette } from './command-palette.js';
14
+ import { sessionActivity, indicatorClass } from './activity-state.js';
14
15
 
15
16
  function $hub(id) { return document.getElementById(id); }
16
17
 
@@ -342,7 +343,10 @@ export function renderHomeHub(projects) {
342
343
  item.className = "hub-project-item";
343
344
 
344
345
  var dot = document.createElement("span");
345
- dot.className = "hub-project-dot" + (proj.isProcessing ? " processing" : "");
346
+ // lr-66c118: project-level dot — isProcessing-only, no alert tone
347
+ // (the Projects-list unread badge owns that affordance).
348
+ var projActivityCls = indicatorClass(sessionActivity(proj, null, { ignoreUnread: true }));
349
+ dot.className = "hub-project-dot" + (projActivityCls ? " " + projActivityCls : "");
346
350
  item.appendChild(dot);
347
351
 
348
352
  if (proj.icon) {
@@ -469,12 +473,11 @@ export function handleHubRecentSessions(msg) {
469
473
  var agentBadge = sess.agentName
470
474
  ? '<span class="hub-recent-agent">' + escapeHtml(sess.agentName) + '</span>'
471
475
  : '';
472
- // Single left status dot — color precedence LOCKED (andy, lr-0aa7b6):
473
- // alert(red) > processing(green, pulsing) > live(green) > idle(grey).
474
- // Alert wins over an active/processing session so the notification is
475
- // always visible. Previously alert rendered as a SEPARATE right-side dot
476
- // (.hub-recent-alert-dot); that's removed — alert is now just another
477
- // color state of the one left dot.
476
+ // Single left status dot — color precedence LOCKED (andy, lr-0aa7b6),
477
+ // now the CANONICAL derivation for every render surface via
478
+ // activity-state.js's sessionActivity/indicatorClass (lr-66c118): this
479
+ // was the only surface with a real precedence chain before, so it is
480
+ // promoted here rather than left a local special case.
478
481
  //
479
482
  // Alert state is keyed on THIS session's own unread count (sess.unread,
480
483
  // populated server-side per-session — see hub_recent_sessions_list in
@@ -483,10 +486,10 @@ export function handleHubRecentSessions(msg) {
483
486
  // project's session list even when only one of them is actually
484
487
  // notifying — that was the bug lr-0aa7b6 required fixing, not just
485
488
  // documenting.
486
- var hasAlert = (sess.unread || 0) > 0;
487
- var dotClass = "hub-recent-dot" +
488
- (hasAlert ? " alert" : (sess.isProcessing ? " processing" : ""));
489
- var dotTitle = hasAlert ? "Unread activity" : (sess.isProcessing ? "Active" : "Idle");
489
+ var recentActivityState = sessionActivity(sess, store.get('myUserId'));
490
+ var recentActivityCls = indicatorClass(recentActivityState);
491
+ var dotClass = "hub-recent-dot" + (recentActivityCls ? " " + recentActivityCls : "");
492
+ var dotTitle = recentActivityState.label;
490
493
  item.innerHTML =
491
494
  '<span class="' + dotClass + '" title="' + dotTitle + '"></span>' +
492
495
  iconHtml +
@@ -16,6 +16,27 @@ var pendingIterations = 20;
16
16
  // ========================================================
17
17
  // Init
18
18
  // ========================================================
19
+
20
+ // lr-fd38ac follow-up: re-check the queue-mode gate whenever the fields it
21
+ // depends on change, not only when a handler happens to remember to call
22
+ // updateLoopInputVisibility() itself. loop_iteration/loop_judging
23
+ // (app-messages.js) write loopCurrentSessionId without re-invoking the
24
+ // gate — that used to leave loopQueueMode stale-false for a client already
25
+ // viewing the loop's own session (queued messages silently dropped instead
26
+ // of queued, the inverse of the original lr-fd38ac bug). See
27
+ // recheckLoopQueueModeFromState() for why this branch does not need the
28
+ // raw per-session `loop` object that updateLoopInputVisibility()'s direct
29
+ // callers (session_switched et al.) pass in.
30
+ //
31
+ // Split out from initLoopUi() so it can be installed on its own — the rest
32
+ // of initLoopUi() renders DOM (banners, buttons) that a unit test covering
33
+ // only this reactive gate has no reason to depend on.
34
+ export function initLoopQueueModeSync() {
35
+ store.subscribe(['loopActive', 'loopCurrentSessionId', 'activeSessionId'], function () {
36
+ recheckLoopQueueModeFromState();
37
+ });
38
+ }
39
+
19
40
  export function initLoopUi() {
20
41
 
21
42
  // --- Reactive UI sync for loop state ---
@@ -34,6 +55,8 @@ export function initLoopUi() {
34
55
  }
35
56
  });
36
57
 
58
+ initLoopQueueModeSync();
59
+
37
60
  // --- Preview modal listeners ---
38
61
  // Backdrop click intentionally does NOT close the modal (no way to reopen it)
39
62
 
@@ -156,6 +179,32 @@ function sendLoopStart() {
156
179
  // Loop UI (exported)
157
180
  // ========================================================
158
181
 
182
+ // lr-6fe5fc: single derivation of "should THIS session's composer present
183
+ // queue-mode UI", used by both call sites below. Takes the three server-
184
+ // pushed inputs directly (never a per-session `loop` object) — see the
185
+ // invariant note on recheckLoopQueueModeFromState() for why the per-session
186
+ // `loop.active`/`loop.role` fields the pre-lr-6fe5fc code additionally
187
+ // checked here are provably redundant with this three-input check and are
188
+ // no longer consulted: project-loop.js only ever sets loopCurrentSessionId
189
+ // to a session whose own loop.active is true and role is coder/judge, and
190
+ // finishLoop() atomically nulls loopCurrentSessionId in the same pass that
191
+ // clears every affected session's loop.active. So loopCurrentSessionId ===
192
+ // activeSessionId already implies everything the per-session object could
193
+ // have told us; carrying it as a second, separately-checked condition is
194
+ // exactly the shape of the bug this task is fixing (two things that are
195
+ // supposed to always agree, checked independently, able to drift).
196
+ //
197
+ // This is a client-side UX gate only — which WS message type the composer
198
+ // sends (`loop_message` vs `message`). It is not a permission check: the
199
+ // server's handleLoopMessage() gate independently and authoritatively
200
+ // decides whether to accept a queued `loop_message` off loopState.active,
201
+ // which is a coarser, correctly-project-scoped question (see that
202
+ // function's comment for why the two predicates are intentionally not the
203
+ // same one).
204
+ export function isLoopQueueSession(loopActive, loopCurrentSessionId, activeSessionId) {
205
+ return !!(loopActive && loopCurrentSessionId != null && loopCurrentSessionId === activeSessionId);
206
+ }
207
+
159
208
  // lr-e31b: An active (non-crafting) loop iteration session used to hide the
160
209
  // composer outright, leaving no way for a human to get a message into a
161
210
  // running loop. Loop iterations are single-turn SDK sessions whose input
@@ -164,12 +213,30 @@ function sendLoopStart() {
164
213
  // into the in-flight turn — it is queued and delivered at the next
165
214
  // iteration boundary instead. The composer stays visible and enabled;
166
215
  // input.js routes the send through `loop_message` while loopQueueMode is set.
216
+ //
217
+ // lr-fd38ac / lr-6fe5fc: the per-session `loop.active` marker (persisted on
218
+ // the session itself, see sessions.js:109/711) is not a reliable input to
219
+ // this gate — see isLoopQueueSession()'s comment for why the three
220
+ // server-pushed store values are sufficient on their own. The `loop`
221
+ // parameter is accepted for backward compatibility with callers that pass
222
+ // the per-session object from a WS message (session_switched et al.) but is
223
+ // intentionally unused in the derivation itself.
167
224
  export function updateLoopInputVisibility(loop) {
168
225
  var inputArea = document.getElementById("input-area");
169
226
  if (!inputArea) return;
170
227
  inputArea.style.display = "";
171
- var queueMode = !!(loop && loop.active && loop.role !== "crafting");
172
- store.set({ loopQueueMode: queueMode });
228
+ var s = store.snap();
229
+ var queueMode = isLoopQueueSession(s.loopActive, s.loopCurrentSessionId, s.activeSessionId);
230
+ applyLoopQueueMode(queueMode);
231
+ }
232
+
233
+ // lr-fd38ac follow-up: shared by updateLoopInputVisibility() (per-session
234
+ // `loop` object supplied by the caller — session_switched, loop_available,
235
+ // loop_finished) and recheckLoopQueueModeFromState() (no `loop` object
236
+ // available; see that function's comment for why store state alone is
237
+ // sufficient there). Applies the derived boolean to the store and syncs
238
+ // the composer placeholder.
239
+ function applyLoopQueueMode(queueMode) {
173
240
  var inputEl = document.getElementById("input");
174
241
  if (inputEl) {
175
242
  if (queueMode) {
@@ -178,6 +245,23 @@ export function updateLoopInputVisibility(loop) {
178
245
  inputEl.placeholder = "Message Claude Code...";
179
246
  }
180
247
  }
248
+ store.set({ loopQueueMode: queueMode });
249
+ }
250
+
251
+ // lr-fd38ac follow-up / lr-6fe5fc: re-derive queue mode from store state
252
+ // alone, for the reactive subscriber in initLoopUi() — it fires on
253
+ // loopActive/loopCurrentSessionId/activeSessionId changes, none of which
254
+ // carry a per-session `loop` object the way session_switched's msg.loop
255
+ // does. Uses the same isLoopQueueSession() predicate as
256
+ // updateLoopInputVisibility() — see that function's comment for the
257
+ // server-side invariant that makes the three store values sufficient on
258
+ // their own, without a per-session `loop` object.
259
+ function recheckLoopQueueModeFromState() {
260
+ var inputArea = document.getElementById("input-area");
261
+ if (!inputArea) return;
262
+ var s = store.snap();
263
+ var queueMode = isLoopQueueSession(s.loopActive, s.loopCurrentSessionId, s.activeSessionId);
264
+ applyLoopQueueMode(queueMode);
181
265
  }
182
266
 
183
267
  export function updateLoopButton() {
@@ -772,6 +856,7 @@ function renderPreviewModelTab(bodyEl) {
772
856
  '<div class="settings-card"><div class="settings-field">' +
773
857
  '<label class="settings-label">Model</label>' +
774
858
  '<div class="settings-hint">Choose the Claude model for this loop.</div>' +
859
+ '<div id="rp-model-scope" class="config-scope-label"></div>' +
775
860
  '<div id="rp-model-list" class="settings-model-list"></div>' +
776
861
  '</div></div>' +
777
862
  '<div class="settings-card"><div class="settings-field">' +
@@ -818,6 +903,9 @@ function renderPreviewModelTab(bodyEl) {
818
903
  modelMsgType: "rp_set_model",
819
904
  modeMsgType: "rp_set_mode",
820
905
  effortMsgType: "rp_set_effort",
906
+ // lr-db0437: loop-scoped — this picker configures the Ralph-loop being
907
+ // created, not the current session or any project/server default.
908
+ scopeLabel: "Loop default (this Ralph-loop only)",
821
909
  };
822
910
 
823
911
  renderModelList("rp", opts);