@clagentic/console 1.11.0 → 1.12.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 (99) hide show
  1. package/README.md +1 -0
  2. package/bin/cli.js +14 -2
  3. package/lib/build-changes.js +8 -2
  4. package/lib/build-sha.json +2 -2
  5. package/lib/build-update-offer.js +31 -7
  6. package/lib/claude-settings-env.js +142 -0
  7. package/lib/cli/arg-validation.js +1 -1
  8. package/lib/cli/duration.js +27 -0
  9. package/lib/cli/ipc-subcommands.js +26 -0
  10. package/lib/cli/schedule-input-subcommands.js +1 -22
  11. package/lib/cli/session-subcommands.js +38 -7
  12. package/lib/daemon.js +26 -0
  13. package/lib/notification-prefs.js +257 -0
  14. package/lib/notify/core.js +175 -0
  15. package/lib/notify/index.js +31 -0
  16. package/lib/notify/live-prompts.js +36 -0
  17. package/lib/notify/payload.js +63 -0
  18. package/lib/notify/target.js +5 -0
  19. package/lib/notify/type-registry.js +64 -0
  20. package/lib/notify/types.js +20 -0
  21. package/lib/open-sockets.js +27 -0
  22. package/lib/outbound-access.js +74 -0
  23. package/lib/outbound-entry.js +109 -0
  24. package/lib/outbound-ledger.js +306 -0
  25. package/lib/outbound-query.js +153 -0
  26. package/lib/pending-prompts.js +31 -16
  27. package/lib/project-connection.js +40 -1
  28. package/lib/project-filesystem.js +20 -5
  29. package/lib/project-http.js +9 -1
  30. package/lib/project-loop.js +25 -13
  31. package/lib/project-notifications.js +206 -42
  32. package/lib/project-prompt-responses.js +1 -1
  33. package/lib/project-sessions.js +30 -1
  34. package/lib/project.js +15 -1
  35. package/lib/prompt-registry.js +92 -24
  36. package/lib/prompt-reminders.js +282 -0
  37. package/lib/prompt-source.js +43 -8
  38. package/lib/public/app.js +1 -0
  39. package/lib/public/css/diagnostics.css +28 -0
  40. package/lib/public/css/home-hub.css +12 -0
  41. package/lib/public/css/icon-strip.css +9 -0
  42. package/lib/public/css/input.css +93 -0
  43. package/lib/public/css/menus.css +22 -0
  44. package/lib/public/css/mobile-nav.css +11 -0
  45. package/lib/public/css/server-settings.css +24 -0
  46. package/lib/public/css/sidebar.css +24 -0
  47. package/lib/public/index.html +6 -0
  48. package/lib/public/modules/activity-state.js +20 -4
  49. package/lib/public/modules/app-connection.js +22 -5
  50. package/lib/public/modules/app-header.js +2 -0
  51. package/lib/public/modules/app-messages.js +6 -2
  52. package/lib/public/modules/app-notifications.js +65 -40
  53. package/lib/public/modules/app-projects.js +3 -1
  54. package/lib/public/modules/app-rate-limit.js +12 -6
  55. package/lib/public/modules/app-rendering.js +26 -3
  56. package/lib/public/modules/build-update-sessions.js +81 -0
  57. package/lib/public/modules/collapsible-text.js +77 -0
  58. package/lib/public/modules/diagnostics.js +9 -2
  59. package/lib/public/modules/env-shadow-notice.js +34 -0
  60. package/lib/public/modules/keep-alive.js +66 -0
  61. package/lib/public/modules/notification-prefs.js +151 -0
  62. package/lib/public/modules/notify-client.js +153 -0
  63. package/lib/public/modules/project-settings.js +5 -0
  64. package/lib/public/modules/prompt-reminders-setting.js +13 -0
  65. package/lib/public/modules/prompt-state.js +3 -3
  66. package/lib/public/modules/prompts.js +1 -1
  67. package/lib/public/modules/server-settings.js +3 -0
  68. package/lib/public/modules/sidebar-mobile.js +8 -0
  69. package/lib/public/modules/sidebar-sessions.js +27 -0
  70. package/lib/public/modules/terminal-links.js +175 -0
  71. package/lib/public/modules/terminal.js +19 -103
  72. package/lib/public/notify-sw-logic.js +300 -0
  73. package/lib/public/notify-target.js +97 -0
  74. package/lib/public/sw.js +15 -62
  75. package/lib/push-audience.js +84 -0
  76. package/lib/push.js +87 -20
  77. package/lib/runtime-env.js +1 -0
  78. package/lib/sdk-bridge.js +83 -36
  79. package/lib/sdk-message-processor.js +148 -49
  80. package/lib/sender-ref.js +3 -0
  81. package/lib/server.js +80 -4
  82. package/lib/session-directory.js +6 -4
  83. package/lib/session-input-ipc.js +11 -1
  84. package/lib/session-input.js +95 -14
  85. package/lib/session-liveness.js +53 -0
  86. package/lib/session-reclaim.js +37 -2
  87. package/lib/sessions.js +58 -4
  88. package/lib/usage-store.js +403 -0
  89. package/lib/vendor-auth.js +33 -2
  90. package/lib/ws-schema.js +13 -2
  91. package/lib/yoke/adapters/claude-vendor.js +11 -1
  92. package/lib/yoke/adapters/claude.js +17 -0
  93. package/lib/yoke/adapters/codex.js +5 -1
  94. package/lib/yoke/auth-checks.js +17 -2
  95. package/lib/yoke/index.js +21 -3
  96. package/lib/yoke/provider-credentials.js +24 -0
  97. package/lib/yoke/registry.js +8 -1
  98. package/package.json +2 -2
  99. package/scripts/check-test-count.js +14 -0
@@ -303,6 +303,13 @@
303
303
  border: 1.5px solid var(--activity-other, #B77BF3);
304
304
  box-shadow: 0 0 4px rgba(183, 123, 243, 0.4);
305
305
  }
306
+ /* Waiting on a prompt: dashed ring in the warning hue, so it is
307
+ told from running (filled) and another user's activity (solid ring) by
308
+ shape as well as color. */
309
+ .hub-project-dot.waiting {
310
+ background: transparent;
311
+ border: 1.5px dashed var(--warning);
312
+ }
306
313
  .hub-project-icon {
307
314
  font-size: 14px;
308
315
  width: 20px;
@@ -523,6 +530,11 @@
523
530
  border: 1.5px solid var(--activity-other, #B77BF3);
524
531
  box-shadow: 0 0 4px rgba(183, 123, 243, 0.4);
525
532
  }
533
+ .hub-recent-dot.waiting {
534
+ background: transparent;
535
+ opacity: 1;
536
+ border: 1.5px dashed var(--warning);
537
+ }
526
538
  .hub-recent-project-icon {
527
539
  font-size: 14px;
528
540
  width: 20px;
@@ -248,6 +248,15 @@
248
248
  border-color: var(--activity-other, #B77BF3);
249
249
  }
250
250
 
251
+ /* Waiting on a prompt: dashed ring, warning hue. */
252
+ .icon-strip-status.waiting {
253
+ opacity: 1;
254
+ background: transparent;
255
+ border-width: 2px;
256
+ border-style: dashed;
257
+ border-color: var(--warning);
258
+ }
259
+
251
260
  /* Alert tone (lr-66c118): unread activity wins over processing green. */
252
261
  .icon-strip-status.alert {
253
262
  opacity: 1;
@@ -1388,3 +1388,96 @@ body.wide-view .scheduled-msg-wrap .scheduled-msg-countdown {
1388
1388
  font-size: inherit;
1389
1389
  color: inherit;
1390
1390
  }
1391
+
1392
+ /* Collapsible text: a pending scheduled input and a long fired one. Collapsed
1393
+ shows the first line only, cut by CSS so the text itself stays whole. */
1394
+ .collapsible-text.is-collapsed .collapsible-full { display: none; }
1395
+ .collapsible-text:not(.is-collapsed):not(.collapsible-single) .collapsible-preview { display: none; }
1396
+ .collapsible-text.is-collapsed .collapsible-preview {
1397
+ display: block;
1398
+ white-space: nowrap;
1399
+ overflow: hidden;
1400
+ text-overflow: ellipsis;
1401
+ }
1402
+ .collapsible-toggle {
1403
+ padding: 0;
1404
+ border: none;
1405
+ background: none;
1406
+ color: var(--accent);
1407
+ font-size: 12px;
1408
+ font-weight: 500;
1409
+ font-family: inherit;
1410
+ cursor: pointer;
1411
+ white-space: nowrap;
1412
+ }
1413
+ .collapsible-toggle:hover { text-decoration: underline; }
1414
+ .collapsible-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
1415
+ .collapsible-toggle-fired { align-self: flex-start; margin-top: 2px; }
1416
+
1417
+ /* A collapsed pending card is one row: send time and actions, then the first
1418
+ line taking the rest of the width. Bubble view and channel view. */
1419
+ .scheduled-msg-wrap.is-collapsed:not(.dm-bubble-content) {
1420
+ flex-direction: row;
1421
+ align-items: center;
1422
+ gap: 8px;
1423
+ }
1424
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-meta { order: -1; flex: 0 1 auto; min-width: 0; padding-right: 0; }
1425
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-countdown {
1426
+ flex: 0 1 auto;
1427
+ min-width: 0;
1428
+ overflow: hidden;
1429
+ text-overflow: ellipsis;
1430
+ white-space: nowrap;
1431
+ }
1432
+ .scheduled-msg-wrap.is-collapsed .bubble {
1433
+ flex: 1 1 0;
1434
+ min-width: 0;
1435
+ max-width: none;
1436
+ padding: 4px 12px;
1437
+ }
1438
+ .scheduled-msg-wrap.is-collapsed .dm-bubble-content {
1439
+ flex-direction: row;
1440
+ align-items: center;
1441
+ gap: 8px;
1442
+ min-width: 0;
1443
+ flex: 1 1 0;
1444
+ }
1445
+ .scheduled-msg-wrap.is-collapsed .dm-bubble-header { flex: 0 1 auto; min-width: 0; }
1446
+
1447
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-send-now,
1448
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-cancel,
1449
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-sep { white-space: nowrap; flex: none; }
1450
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-actions { flex: none; margin-left: 0; }
1451
+ .scheduled-msg-wrap.is-collapsed .scheduled-msg-badge { min-width: 0; flex: 0 1 auto; padding: 3px 8px; }
1452
+ .scheduled-msg-wrap.is-collapsed .collapsible-toggle { flex: none; }
1453
+
1454
+ /* Phone widths: index.html pins the narrow-screen column layout of user rows
1455
+ with !important, so the collapsed card overrides it the same way, scoped to
1456
+ itself. A 390px row cannot hold the send time, three actions and a readable
1457
+ prompt, so the card is two compact rows: send time and actions, then the
1458
+ prompt's first line across the full width. */
1459
+ @media (max-width: 768px) {
1460
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed {
1461
+ gap: 0 !important;
1462
+ align-items: stretch !important;
1463
+ }
1464
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed > .dm-bubble-avatar { display: none !important; }
1465
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed .dm-bubble-content {
1466
+ flex-direction: column !important;
1467
+ align-items: stretch !important;
1468
+ gap: 2px !important;
1469
+ min-width: 0 !important;
1470
+ width: 100% !important;
1471
+ }
1472
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed .dm-bubble-name { display: none; }
1473
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed .dm-bubble-header { flex-wrap: nowrap; }
1474
+ body.wide-view .msg-user.scheduled-msg-wrap.is-collapsed .bubble {
1475
+ flex: none !important;
1476
+ max-width: 100% !important;
1477
+ width: auto !important;
1478
+ padding: 0 !important;
1479
+ background: none !important;
1480
+ border: none !important;
1481
+ border-radius: 0 !important;
1482
+ }
1483
+ }
@@ -43,6 +43,28 @@
43
43
  #header-rename-btn:hover { color: var(--text-secondary); background: rgba(var(--overlay-rgb),0.04); border-color: var(--border); }
44
44
  #header-rename-btn .lucide { width: 13px; height: 13px; }
45
45
 
46
+ #header-keepalive-btn {
47
+ display: flex;
48
+ align-items: center;
49
+ justify-content: center;
50
+ width: 24px;
51
+ height: 24px;
52
+ border: 1px solid transparent;
53
+ background: none;
54
+ color: var(--text-dimmer);
55
+ cursor: pointer;
56
+ border-radius: 8px;
57
+ flex-shrink: 0;
58
+ padding: 0;
59
+ margin-left: 4px;
60
+ transition: color 0.15s, background 0.15s, border-color 0.15s;
61
+ }
62
+
63
+ #header-keepalive-btn.hidden { display: none; }
64
+ #header-keepalive-btn:hover { color: var(--text-secondary); background: rgba(var(--overlay-rgb),0.04); border-color: var(--border); }
65
+ #header-keepalive-btn.active { color: var(--accent, #63b3ed); }
66
+ #header-keepalive-btn .lucide { width: 13px; height: 13px; }
67
+
46
68
  #header-info-btn {
47
69
  display: flex;
48
70
  align-items: center;
@@ -223,6 +223,12 @@
223
223
  border: 1.5px solid var(--activity-other, #B77BF3);
224
224
  box-sizing: border-box;
225
225
  }
226
+ /* Waiting on a prompt: dashed ring, warning hue. */
227
+ .mobile-project-processing.waiting {
228
+ background: transparent;
229
+ border: 1.5px dashed var(--warning);
230
+ box-sizing: border-box;
231
+ }
226
232
  /* Alert tone (lr-66c118): unread wins over processing green. */
227
233
  .mobile-project-processing.alert {
228
234
  background: var(--danger, #e74c3c);
@@ -882,6 +888,11 @@
882
888
  border: 1.5px solid var(--activity-other, #B77BF3);
883
889
  box-sizing: border-box;
884
890
  }
891
+ .mobile-session-processing.waiting {
892
+ background: transparent;
893
+ border: 1.5px dashed var(--warning);
894
+ box-sizing: border-box;
895
+ }
885
896
  /* Alert tone (lr-66c118): unread wins over processing green. */
886
897
  .mobile-session-processing.alert {
887
898
  background: var(--danger, #e74c3c);
@@ -1253,3 +1253,27 @@
1253
1253
  margin-top: 4px;
1254
1254
  }
1255
1255
 
1256
+
1257
+ /* Per-type notification preferences (modules/notification-prefs.js) */
1258
+ .settings-subheading {
1259
+ margin: 16px 0 8px;
1260
+ font-size: 14px;
1261
+ font-weight: 600;
1262
+ }
1263
+
1264
+ .notif-prefs-grid {
1265
+ width: 100%;
1266
+ border-collapse: collapse;
1267
+ margin-top: 8px;
1268
+ }
1269
+
1270
+ .notif-prefs-grid th,
1271
+ .notif-prefs-grid td {
1272
+ padding: 6px 8px;
1273
+ text-align: center;
1274
+ }
1275
+
1276
+ .notif-prefs-grid th:first-child,
1277
+ .notif-prefs-grid td:first-child {
1278
+ text-align: left;
1279
+ }
@@ -901,6 +901,13 @@
901
901
  border: 1.5px solid var(--activity-other, #B77BF3);
902
902
  box-sizing: border-box;
903
903
  }
904
+ /* Waiting on a prompt: dashed ring, warning hue. */
905
+ .session-item .session-processing.waiting,
906
+ .mate-session-item .session-processing.waiting {
907
+ background: transparent;
908
+ border: 1.5px dashed var(--warning);
909
+ box-sizing: border-box;
910
+ }
904
911
  /* Alert tone (lr-66c118): unread activity wins over processing green. */
905
912
  .session-item .session-processing.alert,
906
913
  .mate-session-item .session-processing.alert {
@@ -2025,3 +2032,20 @@
2025
2032
  50% { opacity: 0.18; }
2026
2033
  100% { opacity: 0.1; }
2027
2034
  }
2035
+
2036
+ /* Pin shown on a session the operator has kept alive past the idle reaper. */
2037
+ .session-item .session-keepalive-badge,
2038
+ .mobile-session-item .session-keepalive-badge {
2039
+ display: inline-flex;
2040
+ align-items: center;
2041
+ justify-content: center;
2042
+ color: var(--accent, #63b3ed);
2043
+ margin-right: 4px;
2044
+ vertical-align: middle;
2045
+ }
2046
+
2047
+ .session-item .session-keepalive-badge i,
2048
+ .mobile-session-item .session-keepalive-badge i {
2049
+ width: 12px;
2050
+ height: 12px;
2051
+ }
@@ -268,6 +268,7 @@
268
268
  <span class="header-title" id="header-title">Connecting...</span>
269
269
  <button id="header-info-btn" type="button" title="Session info"><i data-lucide="info"></i></button>
270
270
  <button id="header-rename-btn" type="button" title="Rename session"><i data-lucide="pencil"></i></button>
271
+ <button id="header-keepalive-btn" type="button" class="hidden" aria-pressed="false" title="Keep this session alive"><i data-lucide="pin"></i></button>
271
272
  </div>
272
273
  <div id="todo-sticky" class="hidden"></div>
273
274
  <div id="ralph-sticky" class="hidden"></div>
@@ -743,6 +744,7 @@
743
744
  </div>
744
745
  <div class="ps-env-tab-content active" data-tab="project">
745
746
  <p class="settings-hint" id="ps-env-scope-hint" style="margin-bottom: 12px;"></p>
747
+ <div class="settings-hint ps-env-notice hidden" id="ps-env-shadow-notice"></div>
746
748
  <div class="ps-env-header">
747
749
  <button class="settings-btn-sm" id="ps-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
748
750
  <span class="ps-save-status" id="ps-env-save-status"></span>
@@ -753,6 +755,7 @@
753
755
  </div>
754
756
  <div class="ps-env-tab-content" data-tab="shared">
755
757
  <p class="settings-hint" style="margin-bottom: 12px;">Shared variables apply to every session in every project. Only administrators can change them. Project-level variables take precedence where they apply. Applies to sessions started after saving.</p>
758
+ <div class="settings-hint ps-env-notice hidden" id="ps-shared-env-shadow-notice"></div>
756
759
  <div class="ps-env-header">
757
760
  <button class="settings-btn-sm" id="ps-shared-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
758
761
  <span class="ps-save-status" id="ps-shared-env-save-status"></span>
@@ -1300,6 +1303,8 @@
1300
1303
  <span class="toggle-track"><span class="toggle-thumb"></span></span>
1301
1304
  </label>
1302
1305
  </div>
1306
+ <h3 class="settings-subheading">What to notify you about</h3>
1307
+ <div class="settings-card" id="notif-prefs-card"></div>
1303
1308
  </div>
1304
1309
  <div class="server-settings-section" data-section="claudemd">
1305
1310
  <h2>CLAUDE.md</h2>
@@ -1322,6 +1327,7 @@
1322
1327
  <div class="server-settings-section" data-section="environment">
1323
1328
  <h2>Environment</h2>
1324
1329
  <p class="settings-hint" style="margin-bottom: 16px;">Define environment variables shared across all projects. Project-level variables take precedence over shared ones. Applies to sessions started after saving.</p>
1330
+ <div class="settings-hint ps-env-notice hidden" id="ss-env-shadow-notice"></div>
1325
1331
  <div class="ps-env-header">
1326
1332
  <button class="settings-btn-sm" id="ss-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
1327
1333
  <span class="ps-save-status" id="ss-env-save-status"></span>
@@ -13,6 +13,14 @@
13
13
  //
14
14
  // Design notes:
15
15
  //
16
+ // - Waiting: a session the daemon reports as blocked on an
17
+ // operator prompt (the `waiting` wire field, derived once in
18
+ // lib/session-liveness.js from the same pending-prompt data list-sessions
19
+ // serves) is its own tone, "waiting", and outranks alert: a blocked
20
+ // session is the one the operator must act on, and an unread badge on it
21
+ // must not hide that. It has its own class, "waiting", distinct from
22
+ // running and idle.
23
+ //
16
24
  // - Precedence (LOCKED, operator ruling lr-0aa7b6, promoted here from its
17
25
  // former home-hub-only special case): alert > processing > live > idle.
18
26
  // "live" and "processing" collapse to the same visual state today (no
@@ -38,7 +46,7 @@
38
46
  * @typedef {Object} ActivityState
39
47
  * @property {boolean} active - true if there is any live activity to show a dot for.
40
48
  * @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.
49
+ * @property {"waiting"|"alert"|"self"|"other"|"idle"} tone - which color family to render.
42
50
  * @property {string} label - short human label for a title/tooltip attribute.
43
51
  */
44
52
 
@@ -61,6 +69,9 @@
61
69
  * self-vs-other tone. Omit (or pass null/undefined) in single-user mode —
62
70
  * every session then renders as 'self'.
63
71
  * @param {object} [opts]
72
+ * @param {boolean} [opts.ignoreWaiting] - read only the turn flag, for the
73
+ * transcript footer, which says whether a turn is running and must not be
74
+ * pinned on by a session that is merely waiting on a prompt.
64
75
  * @param {boolean} [opts.ignoreUnread] - suppress alert/unread from flipping
65
76
  * `.active`/tone, for a consumer that has no unread-alert affordance of
66
77
  * its own. Project-level dots (icon strip, mobile project rows, folder
@@ -81,6 +92,10 @@ export function sessionActivity(sess, currentUserId, opts) {
81
92
  return { active: false, alert: false, tone: "idle", label: "Idle" };
82
93
  }
83
94
 
95
+ if (sess.waiting && !(opts && opts.ignoreWaiting)) {
96
+ return { active: true, alert: false, tone: "waiting", label: "Waiting on a prompt" };
97
+ }
98
+
84
99
  var alert = !(opts && opts.ignoreUnread) && (sess.unread || 0) > 0;
85
100
  var active = !!sess.isProcessing;
86
101
 
@@ -123,7 +138,7 @@ export function deriveSessionListProcessing(sessions, activeSessionId) {
123
138
  if (activeSessionId == null || !sessions) return { found: false, active: false };
124
139
  for (var i = 0; i < sessions.length; i++) {
125
140
  if (sessions[i].id === activeSessionId) {
126
- return { found: true, active: sessionActivity(sessions[i], null, { ignoreUnread: true }).active };
141
+ return { found: true, active: sessionActivity(sessions[i], null, { ignoreUnread: true, ignoreWaiting: true }).active };
127
142
  }
128
143
  }
129
144
  return { found: false, active: false };
@@ -132,7 +147,7 @@ export function deriveSessionListProcessing(sessions, activeSessionId) {
132
147
  // Precedence used by both sessionActivity's tone choice above and
133
148
  // rollupActivity's OR-reduce below. Higher wins. 'self' outranks 'other'
134
149
  // per the locked rollup rule; 'alert' outranks everything.
135
- var TONE_RANK = { idle: 0, other: 1, self: 2, alert: 3 };
150
+ var TONE_RANK = { idle: 0, other: 1, self: 2, alert: 3, waiting: 4 };
136
151
 
137
152
  /**
138
153
  * Roll up a list of already-derived (or raw session/project) items into a
@@ -180,10 +195,11 @@ export function rollupActivity(list, currentUserId, opts) {
180
195
  /**
181
196
  * The one place a CSS class suffix is chosen from an ActivityState.
182
197
  * @param {ActivityState} state
183
- * @returns {string} "" | "processing" | "alert" | "other"
198
+ * @returns {string} "" | "processing" | "alert" | "other" | "waiting"
184
199
  */
185
200
  export function indicatorClass(state) {
186
201
  if (!state || !state.active) return "";
202
+ if (state.tone === "waiting") return "waiting";
187
203
  if (state.tone === "alert") return "alert";
188
204
  if (state.tone === "other") return "other";
189
205
  // tone === "self": the reconciled state. home-hub.css's stale comment
@@ -277,6 +277,10 @@ function fetchWsTicket() {
277
277
  .catch(function () { return { ticket: null }; });
278
278
  }
279
279
 
280
+ // Bumped by every connect() call; an attempt whose generation is no longer
281
+ // current is superseded and must not touch the socket or the UI.
282
+ var connectGeneration = 0;
283
+
280
284
  // Milliseconds to wait before re-verifying a single ws-ticket 401 (lr-e5c1fe).
281
285
  var UNAUTH_RETRY_BACKOFF_MS = 400;
282
286
 
@@ -291,21 +295,27 @@ var UNAUTH_RETRY_BACKOFF_MS = 400;
291
295
  // re-run) then proved was still good. Re-verify once, after a short backoff,
292
296
  // before declaring the session gone — only two consecutive 401s (auth
293
297
  // actually confirmed absent) route to handleUnauthenticated().
298
+ //
299
+ // Single-flight: each call takes a new generation. An earlier attempt still
300
+ // awaiting its ticket sees the bump and neither opens nor registers a socket,
301
+ // so no orphan socket can keep feeding processMessage.
294
302
  export function connect() {
303
+ var gen = ++connectGeneration;
304
+ cancelReconnect();
295
305
  var ws = getWs();
296
306
  if (ws) { ws.onclose = null; ws.onmessage = null; ws.onerror = null; ws.close(); }
297
307
  if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
298
308
 
299
309
  fetchWsTicket().then(function (result) {
310
+ if (gen !== connectGeneration) return;
300
311
  if (result.unauthenticated) {
301
312
  setTimeout(function () {
313
+ if (gen !== connectGeneration) return;
302
314
  fetchWsTicket().then(function (retryResult) {
315
+ if (gen !== connectGeneration) return;
303
316
  if (retryResult.unauthenticated) {
304
317
  // Two consecutive 401s: auth is confirmed gone, not a transient
305
- // wake-from-background cookie-attachment gap. Route to sign-in
306
- // instead of opening a socket that would only 401 on the
307
- // upgrade too — ties into the Surface-1 unauth-vs-unreachable
308
- // split below.
318
+ // wake-from-background cookie gap. Route to sign-in.
309
319
  handleUnauthenticated();
310
320
  return;
311
321
  }
@@ -333,9 +343,13 @@ function openSocket(ticket) {
333
343
  var newWs = ticket ? new WebSocket(url, ["clagentic.auth." + ticket]) : new WebSocket(url);
334
344
  setWs(newWs);
335
345
 
346
+ // Handlers fire only while this socket is still the tracked one; a socket
347
+ // that was replaced must not mutate connection state or feed messages.
348
+ function isCurrent() { return getWs() === newWs; }
349
+
336
350
  // If not connected within 3s, force retry
337
351
  connectTimeoutId = setTimeout(function () {
338
- if (!store.get('connected')) {
352
+ if (isCurrent() && !store.get('connected')) {
339
353
  newWs.onclose = null;
340
354
  newWs.onerror = null;
341
355
  newWs.onmessage = null;
@@ -353,6 +367,7 @@ function openSocket(ticket) {
353
367
  var everOpened = false;
354
368
 
355
369
  newWs.onopen = function () {
370
+ if (!isCurrent()) return;
356
371
  everOpened = true;
357
372
  if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
358
373
  setStatus("connected");
@@ -373,6 +388,7 @@ function openSocket(ticket) {
373
388
  };
374
389
 
375
390
  newWs.onclose = function (e) {
391
+ if (!isCurrent()) return;
376
392
  if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
377
393
  closeDmUserPicker();
378
394
  setStatus("disconnected");
@@ -399,6 +415,7 @@ function openSocket(ticket) {
399
415
  newWs.onerror = function () {};
400
416
 
401
417
  newWs.onmessage = function (event) {
418
+ if (!isCurrent()) return;
402
419
  // Backup: if we're receiving messages, we're connected
403
420
  if (!store.get('connected')) {
404
421
  setStatus("connected");
@@ -12,6 +12,7 @@ import { saveToolState, resetToolState, restoreToolState } from './tools.js';
12
12
  import { getSessionUsage, setSessionUsage, getContextData, setContextData, updateContextPanel, updateUsagePanel } from './app-panels.js';
13
13
  import { onHistoryPrepended as onSessionSearchHistoryPrepended } from './session-search.js';
14
14
  import { positionPopover } from './popover-position.js';
15
+ import { initKeepAliveButton } from './keep-alive.js';
15
16
 
16
17
  // --- Module-owned state ---
17
18
  var sessionInfoPopover = null;
@@ -21,6 +22,7 @@ export function initHeader() {
21
22
  var headerRenameBtn = document.getElementById("header-rename-btn");
22
23
  var headerTitleEl = document.getElementById("header-title");
23
24
  var headerInfoBtn = document.getElementById("header-info-btn");
25
+ initKeepAliveButton();
24
26
 
25
27
  // --- Header session rename ---
26
28
  if (headerRenameBtn) {
@@ -27,6 +27,7 @@ import { getWs } from './ws-ref.js';
27
27
  import { showToast } from './utils.js';
28
28
  import { refreshIcons, iconHtml } from './icons.js';
29
29
  import { updatePageTitle } from './sidebar.js';
30
+ import { syncKeepAliveButton } from './keep-alive.js';
30
31
  import { renderSessionList, updateSessionPresence, populateCliSessionList, handleSearchResults, updateSessionBadge } from './sidebar-sessions.js';
31
32
  import { updateDmBadge, renderSidebarPresence, setMentionActive } from './sidebar-users.js';
32
33
  import { refreshMobileChatSheet } from './sidebar-mobile.js';
@@ -37,6 +38,7 @@ import { handleFindInSessionResults } from './session-search.js';
37
38
  import { handleInputSync, autoResize, resetAutoResize, builtinCommands } from './input.js';
38
39
  import { startThinking, appendThinking, stopThinking, resetThinkingGroup, createToolItem, updateToolExecuting, updateToolResult, markAllToolsDone, closeToolGroup, removeToolFromGroup, resetToolState, getTools, getPlanContent, setPlanContent, renderPlanBanner, renderPlanCard, getTodoTools, handleTodoWrite, handleTaskCreate, handleTaskUpdate, applyDeadSessionTodoCompaction, isPlanFilePath, enableMainInput, addTurnMeta, updateSubagentActivity, addSubagentToolEntry, markSubagentDone, initSubagentStop, updateSubagentProgress, updateSubagentTaskStatus, applyPromptMessage, hasPendingPrompts } from './tools.js';
39
40
  import { showDoneNotification, playDoneSound, isNotifAlertEnabled, isNotifSoundEnabled } from './notifications.js';
41
+ import { handleNotificationPrefs, isSurfaceWanted } from './notification-prefs.js';
40
42
  import { handleFsRead, refreshIfOpen } from './filebrowser.js';
41
43
  import { isProjectSettingsOpen, refreshProjectSettingsModels, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged, updateLiteVisibility, handleLiteProjectStatus, handleLiteEnrollResult, handleLiteUnenrollResult } from './project-settings.js';
42
44
  import { updateSettingsModels, updateSettingsStats, updateDaemonConfig, handleSharedEnv, handleSharedEnvSaved, updateSsLiteVisibility } from './server-settings.js';
@@ -393,6 +395,7 @@ registerHandlers({
393
395
 
394
396
  session_list: function (msg) {
395
397
  renderSessionList(msg.sessions || []);
398
+ syncKeepAliveButton(msg.sessions || []);
396
399
  handlePaletteSessionSwitch();
397
400
  // lr-5edd64: 'processing' (the transcript footer's field) is now a pure
398
401
  // PROJECTION of server-authoritative per-session state — nothing writes
@@ -959,8 +962,8 @@ registerHandlers({
959
962
  resetToolState();
960
963
  syncUrgentBlink();
961
964
  if (document.hidden) {
962
- if (isNotifAlertEnabled() && !window._pushSubscription) showDoneNotification();
963
- if (isNotifSoundEnabled()) playDoneSound();
965
+ if (isNotifAlertEnabled() && !window._pushSubscription && isSurfaceWanted("banner", "turn_done")) showDoneNotification();
966
+ if (isNotifSoundEnabled() && isSurfaceWanted("sound", "turn_done")) playDoneSound();
964
967
  }
965
968
  },
966
969
 
@@ -1476,6 +1479,7 @@ registerHandlers({
1476
1479
  // --- Notifications ---
1477
1480
  notifications_state: handleNotificationsState,
1478
1481
  notification_created: handleNotificationCreated,
1482
+ notification_prefs: handleNotificationPrefs,
1479
1483
  notification_dismissed: handleNotificationDismissed,
1480
1484
 
1481
1485
  notification_dismissed_all: function (msg) {