@clagentic/console 1.7.0 → 1.8.0-beta.1

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 (58) hide show
  1. package/bin/cli.js +198 -2542
  2. package/lib/build-sha.json +4 -0
  3. package/lib/cli/daemon-launch.js +797 -0
  4. package/lib/cli/ipc-subcommands.js +186 -0
  5. package/lib/cli/menus.js +849 -0
  6. package/lib/cli/net-detect.js +209 -0
  7. package/lib/cli/tui.js +589 -0
  8. package/lib/daemon.js +15 -6
  9. package/lib/memory-shed.js +81 -2
  10. package/lib/pages.js +13 -17
  11. package/lib/project-connection.js +13 -0
  12. package/lib/project-loop.js +4 -0
  13. package/lib/project-sessions.js +9 -3
  14. package/lib/project.js +3 -2
  15. package/lib/public/css/diagnostics.css +29 -1
  16. package/lib/public/css/home-hub.css +10 -0
  17. package/lib/public/css/overlays.css +19 -0
  18. package/lib/public/index.html +12 -11
  19. package/lib/public/manifest.json +1 -1
  20. package/lib/public/modules/app-connection.js +150 -4
  21. package/lib/public/modules/app-history-replay.js +155 -0
  22. package/lib/public/modules/app-home-hub.js +24 -14
  23. package/lib/public/modules/app-messages.js +1246 -1469
  24. package/lib/public/modules/app-notifications.js +4 -4
  25. package/lib/public/modules/app-rate-limit.js +128 -27
  26. package/lib/public/modules/command-palette.js +11 -22
  27. package/lib/public/modules/context-sources.js +1 -6
  28. package/lib/public/modules/filebrowser.js +25 -13
  29. package/lib/public/modules/input.js +47 -12
  30. package/lib/public/modules/mcp-ui.js +2 -2
  31. package/lib/public/modules/notifications.js +22 -1
  32. package/lib/public/modules/playbook.js +6 -6
  33. package/lib/public/modules/project-settings.js +5 -13
  34. package/lib/public/modules/qrcode.js +2 -2
  35. package/lib/public/modules/rate-limit-state.js +133 -0
  36. package/lib/public/modules/relative-time.js +27 -0
  37. package/lib/public/modules/scheduler-history.js +1 -5
  38. package/lib/public/modules/server-settings.js +28 -15
  39. package/lib/public/modules/sidebar-mobile.js +8 -3
  40. package/lib/public/modules/sidebar-projects.js +1 -1
  41. package/lib/public/modules/sidebar-sessions.js +1 -15
  42. package/lib/public/modules/sidebar.js +3 -3
  43. package/lib/public/modules/utils.js +1 -0
  44. package/lib/public/sw.js +24 -4
  45. package/lib/sdk-bridge.js +22 -0
  46. package/lib/sdk-message-processor.js +27 -1
  47. package/lib/server-auth.js +48 -2
  48. package/lib/server-palette.js +17 -1
  49. package/lib/server-settings.js +70 -4
  50. package/lib/server.js +200 -4
  51. package/lib/session-search.js +20 -5
  52. package/lib/sessions.js +84 -3
  53. package/lib/smtp.js +6 -6
  54. package/lib/yoke/adapters/codex.js +1 -1
  55. package/package.json +4 -2
  56. package/scripts/install-local-test.js +97 -0
  57. package/scripts/verify-installed-build.js +80 -0
  58. package/scripts/write-build-sha.js +53 -0
@@ -100,14 +100,14 @@ function showBanner(notif, autoDismissMs) {
100
100
  var iconHtmlStr = userMentionAvatarSrc
101
101
  ? '<img class="notif-banner-avatar" src="' + escapeHtml(userMentionAvatarSrc) + '" alt="' + escapeHtml((notif.meta && notif.meta.fromName) || "User") + '">'
102
102
  : isAuthRequired
103
- ? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic:Console" style="border-radius:8px">'
103
+ ? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic: Console" style="border-radius:8px">'
104
104
  : projectIcon
105
105
  // projectIconHtml() routes custom (:slug:) icons to a safe <img> tag and
106
106
  // emoji to escaped text — the raw `projectIcon` interpolation previously
107
107
  // showed ':slug:' as literal text (lr-a6da).
108
108
  ? '<span class="notif-banner-emoji">' + projectIconHtml(projectIcon) + '</span>'
109
109
  : isEmpty
110
- ? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic:Console" style="border-radius:8px">'
110
+ ? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic: Console" style="border-radius:8px">'
111
111
  : iconHtml("folder");
112
112
 
113
113
  // Format permission title as "Can I ..." style
@@ -262,7 +262,7 @@ function showLoginReminderBanner() {
262
262
  '<div class="notif-banner-body">' +
263
263
  '<div class="notif-banner-project">CONSOLE</div>' +
264
264
  '<div class="notif-banner-title">Login started</div>' +
265
- '<div class="notif-banner-text">After the login completes, open a new session so Clagentic:Console picks up the fresh auth state.</div>' +
265
+ '<div class="notif-banner-text">After the login completes, open a new session so Clagentic: Console picks up the fresh auth state.</div>' +
266
266
  '<div class="notif-banner-actions">' +
267
267
  '<button class="notif-banner-new-session notif-banner-update-now">Open new session</button>' +
268
268
  '</div>' +
@@ -554,7 +554,7 @@ export function showUpdateBanner(msg) {
554
554
  }
555
555
 
556
556
  banner.innerHTML =
557
- '<div class="notif-banner-icon"><img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic:Console" style="border-radius:8px"></div>' +
557
+ '<div class="notif-banner-icon"><img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic: Console" style="border-radius:8px"></div>' +
558
558
  '<div class="notif-banner-body">' +
559
559
  '<div class="notif-banner-project">CLAGENTIC</div>' +
560
560
  '<div class="notif-banner-title">v' + escapeHtml(msg.version) + ' is available</div>' +
@@ -6,22 +6,37 @@ import { store } from './store.js';
6
6
  import { getWs } from './ws-ref.js';
7
7
  import { addToMessages, scrollToBottom } from './app-rendering.js';
8
8
  import { userAvatarUrl } from './avatar.js';
9
- import { setScheduleDelayMs, clearScheduleDelay } from './input.js';
9
+ import { clearScheduleDelay, setScheduleDelayForSession, clearScheduleDelayForSession, restoreScheduleDelayUi } from './input.js';
10
10
  import { isSonnetModel, isOpusModel } from './settings-defaults.js';
11
+ import {
12
+ getRateLimitResetsAt, setRateLimitResetsAt,
13
+ getRateLimitResetTimer, setRateLimitResetTimer,
14
+ getRateLimitResetState,
15
+ setScheduledMsg, clearScheduledMsg, getScheduledMsg,
16
+ clearSession as clearSessionRateLimitState,
17
+ } from './rate-limit-state.js';
11
18
 
12
19
  // --- Module-owned state ---
20
+ // lr-0827ba: rateLimitResetsAt / rateLimitResetTimer / rateLimitResetState /
21
+ // the scheduled-message bubble text are now owned per-session by
22
+ // rate-limit-state.js (see imports above) — arming one project's rate-limit
23
+ // auto-schedule no longer clobbers another project's armed state. The
24
+ // variables below remain module-scoped because they are references to the
25
+ // single visible DOM element/timer for whichever session is currently
26
+ // focused; they get rebuilt/rebound whenever the focused session changes.
13
27
  var rateLimitCountdownTimer = null;
14
28
  var rateLimitIndicatorEl = null;
15
- var rateLimitResetsAt = null;
16
- var rateLimitResetTimer = null;
17
29
  var rateLimitUsageEl = null;
18
- var rateLimitResetState = {};
19
30
  var rateLimitTickTimer = null;
20
31
  var _rateLimitUsageLastHtml = null; // guard against redundant innerHTML + refreshIcons()
21
32
  var scheduledMsgEl = null;
22
33
  var scheduledCountdownTimer = null;
23
34
  var fastModeIndicatorEl = null;
24
35
 
36
+ function currentSessionId() {
37
+ return store.get('activeSessionId');
38
+ }
39
+
25
40
  // --- Internal helpers ---
26
41
 
27
42
  function getVendorUsageMeta(vendor) {
@@ -158,11 +173,12 @@ function tickRateLimitUsage() {
158
173
  if (!rateLimitUsageEl) return;
159
174
  var parts = [];
160
175
  var types = ["five_hour", "seven_day", "seven_day_opus", "seven_day_sonnet"];
176
+ var resetState = getRateLimitResetState(currentSessionId());
161
177
  for (var i = 0; i < types.length; i++) {
162
- var entry = rateLimitResetState[types[i]];
178
+ var entry = resetState[types[i]];
163
179
  if (!entry || !entry.resetsAt) continue;
164
180
  var timeStr = formatResetTime(entry.resetsAt);
165
- if (!timeStr) { delete rateLimitResetState[types[i]]; continue; }
181
+ if (!timeStr) { delete resetState[types[i]]; continue; }
166
182
  parts.push(rateLimitTypeShortLabel(types[i]) + " resets " + timeStr);
167
183
  }
168
184
  var newHtml;
@@ -201,18 +217,31 @@ export function handleRateLimitEvent(msg) {
201
217
  var typeLabel = rateLimitTypeLabel(msg.rateLimitType);
202
218
  var popoverText = "";
203
219
 
220
+ // lr-0827ba: the event's own session (server-stamped localId) is the one
221
+ // that gets its schedule armed, NOT necessarily the currently-focused
222
+ // session — a rate limit hit in a background session must still arm that
223
+ // session's auto-schedule and keep its reset timer running, exactly like
224
+ // server-side session.scheduledMessage already does. Fall back to the
225
+ // active session for events from servers/replays that predate the localId
226
+ // stamp (older recorded history entries).
227
+ var eventSessionId = msg.localId != null ? msg.localId : currentSessionId();
228
+ var isActiveSession = eventSessionId === currentSessionId();
229
+
204
230
  if (isRejected && msg.resetsAt) {
205
231
  // Check if already expired (history replay) — skip popover
206
232
  if (msg.resetsAt < Date.now()) {
207
- updateRateLimitIndicator(msg);
233
+ if (isActiveSession) updateRateLimitIndicator(msg);
208
234
  return;
209
235
  }
210
- popoverText = typeLabel + " limit exceeded";
211
- updateRateLimitIndicator(msg);
212
- startRateLimitCountdown(null, msg.resetsAt, null);
213
- // Track rate limit reset time
214
- rateLimitResetsAt = msg.resetsAt;
215
- if (rateLimitResetTimer) clearTimeout(rateLimitResetTimer);
236
+ if (isActiveSession) {
237
+ popoverText = typeLabel + " limit exceeded";
238
+ updateRateLimitIndicator(msg);
239
+ startRateLimitCountdown(null, msg.resetsAt, null);
240
+ }
241
+ // Track rate limit reset time for the event's own session.
242
+ setRateLimitResetsAt(eventSessionId, msg.resetsAt);
243
+ var existingTimer = getRateLimitResetTimer(eventSessionId);
244
+ if (existingTimer) clearTimeout(existingTimer);
216
245
  // Auto-switch input to schedule mode: any message typed will be queued for after reset.
217
246
  // Model-aware: a seven_day_sonnet rejection should not schedule when the user is on Opus
218
247
  // (and vice-versa), since those messages would send fine against the other model's quota.
@@ -235,20 +264,21 @@ export function handleRateLimitEvent(msg) {
235
264
  }
236
265
  }
237
266
  if (shouldSchedule) {
238
- setScheduleDelayMs(delayUntilReset + 60000); // +1min buffer after reset
267
+ setScheduleDelayForSession(eventSessionId, delayUntilReset + 60000); // +1min buffer after reset
239
268
  }
240
269
  }
241
270
  // Only arm the reset timer when we actually entered schedule mode; otherwise we'd
242
271
  // clear unrelated scheduled state on reset.
243
272
  if (shouldSchedule) {
244
- rateLimitResetTimer = setTimeout(function () {
245
- rateLimitResetsAt = null;
246
- rateLimitResetTimer = null;
247
- // Clear schedule mode when rate limit resets
248
- clearScheduleDelay();
249
- }, msg.resetsAt - Date.now() + 1000);
273
+ setRateLimitResetTimer(eventSessionId, setTimeout(function () {
274
+ setRateLimitResetsAt(eventSessionId, null);
275
+ setRateLimitResetTimer(eventSessionId, null);
276
+ // Clear schedule mode when rate limit resets — for the event's own
277
+ // session, whether or not it's the one currently focused.
278
+ clearScheduleDelayForSession(eventSessionId);
279
+ }, msg.resetsAt - Date.now() + 1000));
250
280
  }
251
- } else {
281
+ } else if (isActiveSession) {
252
282
  var pct = msg.utilization ? Math.round(msg.utilization * 100) : null;
253
283
  popoverText = typeLabel + " warning" + (pct ? " (" + pct + "% used)" : "");
254
284
  updateRateLimitIndicator(msg);
@@ -258,9 +288,19 @@ export function handleRateLimitEvent(msg) {
258
288
  }
259
289
 
260
290
  export function updateRateLimitUsage(msg) {
291
+ // lr-0827ba: rate_limit_usage is a project-wide broadcast (account-wide
292
+ // usage, not session content), but only repaint the top-bar widget when
293
+ // the event belongs to the session currently in view, so a background
294
+ // session's usage tick doesn't visibly flicker the widget for whatever
295
+ // session the user is actually looking at. Reset-time bookkeeping itself
296
+ // is still tracked per-session (via rate-limit-state.js) so switching back
297
+ // into that session redraws with its own latest data.
298
+ var eventSessionId = msg.localId != null ? msg.localId : currentSessionId();
299
+ var resetState = getRateLimitResetState(eventSessionId);
261
300
  if (msg.rateLimitType && msg.resetsAt) {
262
- rateLimitResetState[msg.rateLimitType] = { resetsAt: msg.resetsAt, status: msg.status };
301
+ resetState[msg.rateLimitType] = { resetsAt: msg.resetsAt, status: msg.status };
263
302
  }
303
+ if (eventSessionId !== currentSessionId()) return;
264
304
 
265
305
  var topBarActions = document.querySelector("#top-bar .top-bar-actions");
266
306
  if (!topBarActions) return;
@@ -279,7 +319,7 @@ export function updateRateLimitUsage(msg) {
279
319
  var parts = [];
280
320
  var types = ["five_hour", "seven_day", "seven_day_opus", "seven_day_sonnet"];
281
321
  for (var i = 0; i < types.length; i++) {
282
- var entry = rateLimitResetState[types[i]];
322
+ var entry = resetState[types[i]];
283
323
  if (!entry || !entry.resetsAt) continue;
284
324
  var timeStr = formatResetTime(entry.resetsAt);
285
325
  if (!timeStr) continue;
@@ -313,7 +353,17 @@ export function updateRateLimitUsage(msg) {
313
353
  }
314
354
  }
315
355
 
316
- export function addScheduledMessageBubble(text, resetsAt) {
356
+ // lr-0827ba: msg carries the server-stamped localId of the session the
357
+ // scheduled message actually belongs to. Persist the queued text/resetsAt
358
+ // for that session regardless of focus (so switching back in later can
359
+ // redraw it), but only render the visible bubble into the DOM when the
360
+ // event's session is the one currently in view — otherwise a background
361
+ // project's scheduled message would render into whatever session's message
362
+ // list happens to be on screen.
363
+ export function addScheduledMessageBubble(text, resetsAt, sessionId) {
364
+ var targetSessionId = sessionId != null ? sessionId : currentSessionId();
365
+ setScheduledMsg(targetSessionId, text, resetsAt);
366
+ if (targetSessionId !== currentSessionId()) return;
317
367
  removeScheduledMessageBubble();
318
368
  var isChannel = document.body.classList.contains("wide-view");
319
369
  var wrap = document.createElement("div");
@@ -475,6 +525,10 @@ export function addScheduledMessageBubble(text, resetsAt) {
475
525
  scheduledCountdownTimer = setInterval(updateCountdown, 1000);
476
526
  }
477
527
 
528
+ // Clears the visible DOM bubble/countdown only — does not touch the
529
+ // per-session persisted state. Used internally when re-rendering the bubble
530
+ // for the same session (addScheduledMessageBubble) and by
531
+ // clearScheduledMessage() below.
478
532
  export function removeScheduledMessageBubble() {
479
533
  if (scheduledMsgEl) {
480
534
  scheduledMsgEl.remove();
@@ -486,6 +540,16 @@ export function removeScheduledMessageBubble() {
486
540
  }
487
541
  }
488
542
 
543
+ // lr-0827ba: clears both the persisted per-session scheduled-message state
544
+ // and (if that session is currently focused) the visible bubble. sessionId
545
+ // defaults to the currently active session for existing call sites that
546
+ // don't yet carry a server-stamped localId (older history entries).
547
+ export function clearScheduledMessage(sessionId) {
548
+ var targetSessionId = sessionId != null ? sessionId : currentSessionId();
549
+ clearScheduledMsg(targetSessionId);
550
+ if (targetSessionId === currentSessionId()) removeScheduledMessageBubble();
551
+ }
552
+
489
553
  export function handleFastModeState(state) {
490
554
  var statusArea = document.querySelector(".title-bar-content .status");
491
555
  if (!statusArea) return;
@@ -515,15 +579,52 @@ export function handleFastModeState(state) {
515
579
 
516
580
  export function getScheduledMsgEl() { return scheduledMsgEl; }
517
581
 
582
+ // lr-0827ba: this used to also null out the bare module-scoped
583
+ // rateLimitResetsAt/rateLimitResetTimer/rateLimitResetState variables —
584
+ // which meant switching projects silently canceled the OUTGOING session's
585
+ // rate-limit reset timer and armed schedule, exactly the bug this task
586
+ // fixes. Reset timers and armed state are per-session now (rate-limit-state.js)
587
+ // and must keep running in the background regardless of focus, mirroring
588
+ // server-side session.scheduledMessage. This function now only tears down
589
+ // the visible DOM/UI-timer for whichever session was previously focused —
590
+ // it does not touch any session's persisted arming state. Callers switching
591
+ // into a different session must call restoreRateLimitStateForSession() for
592
+ // the new session afterward to redraw its own state (see app-messages.js
593
+ // session_switched handler).
518
594
  export function resetRateLimitState() {
519
595
  clearRateLimitIndicator();
520
596
  if (rateLimitCountdownTimer) { clearInterval(rateLimitCountdownTimer); rateLimitCountdownTimer = null; }
521
597
  if (rateLimitTickTimer) { clearInterval(rateLimitTickTimer); rateLimitTickTimer = null; }
522
- if (rateLimitResetTimer) { clearTimeout(rateLimitResetTimer); rateLimitResetTimer = null; }
523
- rateLimitResetsAt = null;
524
- rateLimitResetState = {};
525
598
  // Remove the usage link element entirely so it is rebuilt fresh for the new
526
599
  // project (correct vendor href, correct reset times).
527
600
  if (rateLimitUsageEl) { rateLimitUsageEl.remove(); rateLimitUsageEl = null; }
528
601
  if (fastModeIndicatorEl) { fastModeIndicatorEl.remove(); fastModeIndicatorEl = null; }
602
+ removeScheduledMessageBubble();
603
+ }
604
+
605
+ // Called when a session is actually destroyed/removed (not merely
606
+ // unfocused) so its background reset timer is canceled and its entry is
607
+ // dropped instead of leaking forever. Wired from app-messages.js's
608
+ // session_deleted handler (server-stamped ids from lib/sessions.js'
609
+ // broadcastSessionDeleted, lr-0827ba PEACHES follow-up).
610
+ export function forgetSessionRateLimitState(sessionId) {
611
+ clearSessionRateLimitState(sessionId);
612
+ }
613
+
614
+ // lr-0827ba: "redraw on switch-in" — restores the newly-focused session's
615
+ // already-armed indicator/schedule-button/scheduled-message-bubble state
616
+ // instead of relying on the unreliable chat-history-replay side effect that
617
+ // happened to repaint these before. Call after resetRateLimitState() once
618
+ // the new session is focused (store.activeSessionId already updated).
619
+ export function restoreRateLimitStateForSession(sessionId) {
620
+ restoreScheduleDelayUi();
621
+ var resetsAt = getRateLimitResetsAt(sessionId);
622
+ if (resetsAt && resetsAt > Date.now()) {
623
+ updateRateLimitIndicator({ status: "rejected", resetsAt: resetsAt });
624
+ startRateLimitCountdown(null, resetsAt, null);
625
+ }
626
+ var queued = getScheduledMsg(sessionId);
627
+ if (queued && queued.resetsAt > Date.now()) {
628
+ addScheduledMessageBubble(queued.text, queued.resetsAt, sessionId);
629
+ }
529
630
  }
@@ -1,29 +1,10 @@
1
1
  import { userAvatarUrl } from './avatar.js';
2
- import { escapeHtml } from './utils.js';
2
+ import { escapeHtml, relativeTime } from './utils.js';
3
3
  import { refreshIcons } from './icons.js';
4
4
  import { openSearch as openSessionSearch } from './session-search.js';
5
5
  import { pushOverlayState, popOverlayState } from './overlay-history.js';
6
6
  import { projectIconHtml } from './project-icon.js';
7
7
 
8
- function formatRelativeDate(ts) {
9
- if (!ts) return "";
10
- var now = Date.now();
11
- var diff = now - ts;
12
- if (diff < 0) diff = 0;
13
- var sec = Math.floor(diff / 1000);
14
- if (sec < 60) return "just now";
15
- var min = Math.floor(sec / 60);
16
- if (min < 60) return min + "m ago";
17
- var hr = Math.floor(min / 60);
18
- if (hr < 24) return hr + "h ago";
19
- var days = Math.floor(hr / 24);
20
- if (days < 7) return days + "d ago";
21
- if (days < 30) return Math.floor(days / 7) + "w ago";
22
- var d = new Date(ts);
23
- var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
24
- return months[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
25
- }
26
-
27
8
  var ctx;
28
9
  var paletteEl = null;
29
10
  var inputEl = null;
@@ -109,6 +90,14 @@ export function setPaletteVersion(version) {
109
90
  cachedVersion = version;
110
91
  }
111
92
 
93
+ // Read-only accessor for the version this client's WS connection last
94
+ // reported as running (set from the "info" handshake message). Used by the
95
+ // stale-bundle watchdog in app-connection.js to detect a version mismatch
96
+ // against the server's currently served build (lr-e0ec47).
97
+ export function getPaletteVersion() {
98
+ return cachedVersion;
99
+ }
100
+
112
101
  export function handlePaletteSessionSwitch() {
113
102
  if (!pendingNav) return;
114
103
  var nav = pendingNav;
@@ -198,7 +187,7 @@ function updateFooter() {
198
187
  '<span><kbd>Enter</kbd> select</span>';
199
188
  var versionText = cachedVersion ? "v" + cachedVersion : "";
200
189
  footerEl.innerHTML =
201
- '<a href="https://github.com/clagentic/clagentic-console" target="_blank" rel="noopener" class="cmd-palette-brand"><img src="favicon-banded.png" width="13" height="13" alt="">Clagentic:Console ' + versionText + '</a>' +
190
+ '<a href="https://github.com/clagentic/clagentic-console" target="_blank" rel="noopener" class="cmd-palette-brand"><img src="favicon-banded.png" width="13" height="13" alt="">Clagentic: Console ' + versionText + '</a>' +
202
191
  '<span class="cmd-palette-footer-shortcuts">' + shortcuts + '</span>';
203
192
  }
204
193
 
@@ -415,7 +404,7 @@ function appendHomeSearchResults(results, query) {
415
404
  // ==========================================
416
405
 
417
406
  function renderItem(index, iconContent, title, desc, snippet, timestamp) {
418
- var dateStr = formatRelativeDate(timestamp);
407
+ var dateStr = relativeTime(timestamp);
419
408
  return '<div class="cmd-palette-item" data-index="' + index + '">' +
420
409
  '<div class="cmd-palette-item-icon">' + iconContent + '</div>' +
421
410
  '<div class="cmd-palette-item-body">' +
@@ -1,6 +1,7 @@
1
1
  // Context Sources — attach terminal output and browser tabs as context for Claude
2
2
 
3
3
  import { refreshIcons } from './icons.js';
4
+ import { escapeHtml } from './utils.js';
4
5
 
5
6
  var ctx = null;
6
7
  var activeSourceIds = new Set();
@@ -357,9 +358,3 @@ export function getActiveSources() {
357
358
  export function hasActiveSources() {
358
359
  return activeSourceIds.size > 0;
359
360
  }
360
-
361
- function escapeHtml(str) {
362
- var div = document.createElement("div");
363
- div.textContent = str;
364
- return div.innerHTML;
365
- }
@@ -1,5 +1,5 @@
1
1
  import { iconHtml, refreshIcons } from './icons.js';
2
- import { escapeHtml, copyToClipboard } from './utils.js';
2
+ import { escapeHtml, copyToClipboard, relativeTime } from './utils.js';
3
3
  import { renderMarkdown, highlightCodeBlocks, renderMermaidBlocks, exportMarkdownAsPdf } from './markdown.js';
4
4
  import { closeSidebar } from './sidebar.js';
5
5
  import { closeTerminal } from './terminal.js';
@@ -11,6 +11,7 @@ import {
11
11
  peekPendingNavigate,
12
12
  getPendingNavigate,
13
13
  } from './pending-navigate.js';
14
+ import { registerHandlers } from './app-messages.js';
14
15
 
15
16
  var ctx;
16
17
  var showDropHint = function () {};
@@ -1457,7 +1458,7 @@ function renderHistoryPanel() {
1457
1458
  if (item.source === "git") {
1458
1459
  var sub = document.createElement("div");
1459
1460
  sub.className = "file-history-meta";
1460
- sub.textContent = item.hash.substring(0, 7) + " by " + (item.author || "unknown") + formatTimeAgo(item.timestamp);
1461
+ sub.textContent = item.hash.substring(0, 7) + " by " + (item.author || "unknown") + (item.timestamp ? ", " + relativeTime(item.timestamp) : "");
1461
1462
  entry.appendChild(sub);
1462
1463
  } else {
1463
1464
  var sessionMeta = document.createElement("div");
@@ -1770,17 +1771,6 @@ function shortEntryLabel(entry) {
1770
1771
  return (entry.assistantSnippet || entry.toolName || "Edit").substring(0, 30);
1771
1772
  }
1772
1773
 
1773
- function formatTimeAgo(ts) {
1774
- if (!ts) return "";
1775
- var diff = Date.now() - ts;
1776
- if (diff < 60000) return ", just now";
1777
- if (diff < 3600000) return ", " + Math.floor(diff / 60000) + "m ago";
1778
- if (diff < 86400000) return ", " + Math.floor(diff / 3600000) + "h ago";
1779
- var d = new Date(ts);
1780
- return ", " + d.toLocaleDateString();
1781
- }
1782
-
1783
-
1784
1774
  function viewEntryFile(entry) {
1785
1775
  var viewerEl = ctx.fileViewerEl;
1786
1776
  var bodyEl = document.getElementById("file-viewer-body");
@@ -1991,3 +1981,25 @@ function scrollToToolElement(toolId, assistantUuid) {
1991
1981
 
1992
1982
  // peekPendingNavigate and getPendingNavigate are imported from
1993
1983
  // ./pending-navigate.js and re-exported from the import statement at the top.
1984
+
1985
+ // --- WS message registry (lr-4e49 Part 2) ---
1986
+ // Registers this module's own result/event handlers directly with the
1987
+ // app-messages.js registry instead of app-messages.js importing and
1988
+ // switch-casing them itself. Runs once at module load — app.js imports
1989
+ // every domain module (including this one) before connect() opens the
1990
+ // WebSocket, so registration always completes before any message can
1991
+ // arrive (see lib/public/app.js).
1992
+ // fs_read_result is NOT registered here even though handleFsRead lives in
1993
+ // this module: the wire message is shared with the CLAUDE.md instructions
1994
+ // editor in project-settings.js (msg.path === "CLAUDE.md" &&
1995
+ // isProjectSettingsOpen() routes there instead). That routing decision
1996
+ // needs both modules and stays a core case in app-messages.js.
1997
+ registerHandlers({
1998
+ fs_list_result: handleFsList,
1999
+ fs_search_result: handleFsSearch,
2000
+ fs_file_changed: handleFileChanged,
2001
+ fs_dir_changed: handleDirChanged,
2002
+ fs_file_history_result: handleFileHistory,
2003
+ fs_git_diff_result: handleGitDiff,
2004
+ fs_file_at_result: handleFileAt,
2005
+ });
@@ -5,6 +5,7 @@ import { checkForMention, showMentionMenu, hideMentionMenu, isMentionMenuVisible
5
5
  import { initAtAgents, showAgentMenu, hideAgentMenu, isAgentMenuActive, agentMenuKeydown, requestProjectAgents } from './at-agents.js';
6
6
  import { store } from './store.js';
7
7
  import { sendWsQuiet } from './ws-ref.js';
8
+ import { getScheduleDelayMs, setScheduleDelayMs as setSessionScheduleDelayMs } from './rate-limit-state.js';
8
9
 
9
10
  var ctx;
10
11
 
@@ -17,10 +18,18 @@ var slashActiveIdx = -1;
17
18
  var slashFiltered = [];
18
19
  var isComposing = false;
19
20
  var isRemoteInput = false;
20
- var scheduleDelayMs = 0; // 0 = no schedule, >0 = delay in ms
21
+ // lr-0827ba: schedule-delay arming is per-session state, owned by
22
+ // rate-limit-state.js and keyed by the currently active session (not a bare
23
+ // module-scoped variable — that was the root cause of arming in one project
24
+ // silently overwriting another project's armed state, since the SPA never
25
+ // reloads the page on project switch).
21
26
  var _setScheduleDelayFn = null; // set by initInput
22
27
  var slashMenuBound = false;
23
28
 
29
+ function currentSessionId() {
30
+ return store.get('activeSessionId');
31
+ }
32
+
24
33
  export function hasSendableContent() {
25
34
  return !!(
26
35
  (ctx && ctx.inputEl && ctx.inputEl.value.trim()) ||
@@ -30,18 +39,39 @@ export function hasSendableContent() {
30
39
  );
31
40
  }
32
41
 
33
- export function getScheduleDelay() {
34
- return scheduleDelayMs;
42
+ // Returns the armed schedule delay for the currently active session (0 = no
43
+ // schedule armed). Pass an explicit sessionId to check a session other than
44
+ // the active one (e.g. redrawing on switch-in).
45
+ export function getScheduleDelay(sessionId) {
46
+ return getScheduleDelayMs(sessionId === undefined ? currentSessionId() : sessionId);
35
47
  }
36
48
 
49
+ // Arms (or disarms, with ms=0) the schedule delay for a specific session.
50
+ // Only touches the visible schedule button when sessionId is the currently
51
+ // focused session — arming a background session (e.g. a rate-limit hit in a
52
+ // project the user isn't looking at) must not repaint the UI for whatever
53
+ // session IS focused (lr-0827ba).
54
+ export function setScheduleDelayForSession(sessionId, ms) {
55
+ setSessionScheduleDelayMs(sessionId, ms);
56
+ if (sessionId === currentSessionId() && _setScheduleDelayFn) _setScheduleDelayFn(ms);
57
+ }
58
+
59
+ // Arms (or disarms, with ms=0) the schedule delay for the currently active
60
+ // session and updates the visible button state.
37
61
  export function setScheduleDelayMs(ms) {
38
- scheduleDelayMs = ms;
39
- // Trigger visual update if initInput has been called
40
- if (_setScheduleDelayFn) _setScheduleDelayFn(ms);
62
+ setScheduleDelayForSession(currentSessionId(), ms);
41
63
  }
42
64
 
43
- export function clearScheduleDelay() {
44
- scheduleDelayMs = 0;
65
+ // Redraws the schedule button to reflect a session's already-armed delay
66
+ // without re-triggering any arm/disarm side effects — used when switching
67
+ // back into a session that has a background-armed schedule (lr-0827ba).
68
+ export function restoreScheduleDelayUi() {
69
+ if (_setScheduleDelayFn) _setScheduleDelayFn(getScheduleDelay());
70
+ }
71
+
72
+ export function clearScheduleDelayForSession(sessionId) {
73
+ setSessionScheduleDelayMs(sessionId, 0);
74
+ if (sessionId !== currentSessionId()) return;
45
75
  var btn = document.getElementById("schedule-btn");
46
76
  if (btn) {
47
77
  btn.classList.remove("schedule-active", "schedule-expanded");
@@ -53,6 +83,10 @@ export function clearScheduleDelay() {
53
83
  }
54
84
  }
55
85
 
86
+ export function clearScheduleDelay() {
87
+ clearScheduleDelayForSession(currentSessionId());
88
+ }
89
+
56
90
  export function setScheduleBtnDisabled(disabled) {
57
91
  var btn = document.getElementById("schedule-btn");
58
92
  if (!btn) return;
@@ -224,8 +258,9 @@ export function sendMessage() {
224
258
  }
225
259
 
226
260
  // Scheduled message: queue message with timer delay
227
- if (scheduleDelayMs > 0) {
228
- var resetsAt = Date.now() + scheduleDelayMs;
261
+ var _armedDelayMs = getScheduleDelay();
262
+ if (_armedDelayMs > 0) {
263
+ var resetsAt = Date.now() + _armedDelayMs;
229
264
  ctx.ws.send(JSON.stringify({ type: "schedule_message", text: text || "", resetsAt: resetsAt }));
230
265
  clearScheduleDelay();
231
266
  ctx.inputEl.value = "";
@@ -870,7 +905,7 @@ export function initInput(_ctx) {
870
905
  }
871
906
 
872
907
  function setScheduleDelay(ms) {
873
- scheduleDelayMs = ms;
908
+ setSessionScheduleDelayMs(currentSessionId(), ms);
874
909
  if (!scheduleBtn) return;
875
910
  collapseScheduleBtn();
876
911
  if (ms > 0) {
@@ -938,7 +973,7 @@ export function initInput(_ctx) {
938
973
  if (scheduleBtn) {
939
974
  scheduleBtn.addEventListener("click", function (e) {
940
975
  e.stopPropagation();
941
- if (scheduleDelayMs > 0) {
976
+ if (getScheduleDelayMs(currentSessionId()) > 0) {
942
977
  setScheduleDelay(0);
943
978
  return;
944
979
  }
@@ -155,7 +155,7 @@ function renderMcpServerList() {
155
155
  title: "Install Chrome Extension",
156
156
  desc: step1Done
157
157
  ? "Connected"
158
- : "Required to bridge your browser with Clagentic:Console.",
158
+ : "Required to bridge your browser with Clagentic: Console.",
159
159
  action: step1Done ? null : {
160
160
  label: "Setup Extension",
161
161
  icon: "puzzle",
@@ -191,7 +191,7 @@ function renderMcpServerList() {
191
191
  if (step3Done) {
192
192
  step3Desc = available.length + " server" + (available.length === 1 ? "" : "s") + " enabled";
193
193
  } else if (step2Done) {
194
- step3Desc = "Add servers from the Clagentic:Console Chrome Extension popup using the + button, or import an existing config file.";
194
+ step3Desc = "Add servers from the Clagentic: Console Chrome Extension popup using the + button, or import an existing config file.";
195
195
  } else {
196
196
  step3Desc = "Configure after installing the bridge.";
197
197
  }
@@ -503,7 +503,7 @@ export function initNotifications(_ctx) {
503
503
  localStorage.setItem("onboarding-dismissed", "1");
504
504
  // Show a welcome notification so the user knows it works
505
505
  navigator.serviceWorker.ready.then(function (reg) {
506
- reg.showNotification("\ud83c\udf89 Welcome to Clagentic:Console!", {
506
+ reg.showNotification("\ud83c\udf89 Welcome to Clagentic: Console!", {
507
507
  body: "\ud83d\udd14 You\u2019ll be notified when Claude responds.",
508
508
  tag: "claude-welcome",
509
509
  });
@@ -553,6 +553,27 @@ export function initNotifications(_ctx) {
553
553
  }
554
554
 
555
555
  navigator.serviceWorker.register("/sw.js")
556
+ .then(function (reg) {
557
+ // sw.js is served no-cache (server.js serveStatic), so reg.update()
558
+ // always re-fetches it from the network and picks up a post-deploy
559
+ // change. Without an explicit update() call the browser only
560
+ // re-checks sw.js on its own heuristic schedule (typically once per
561
+ // navigation, ~24h max) — a foregrounded mobile PWA that never
562
+ // navigates can hold a pre-deploy SW+cache indefinitely (lr-e0ec47).
563
+ reg.update().catch(function () {});
564
+
565
+ // Re-check for a newer sw.js whenever the PWA is foregrounded, so a
566
+ // backgrounded-then-resumed mobile client re-validates promptly
567
+ // instead of waiting for the browser's own update heuristic.
568
+ document.addEventListener("visibilitychange", function () {
569
+ if (document.visibilityState === "visible") reg.update().catch(function () {});
570
+ });
571
+ window.addEventListener("pageshow", function () {
572
+ reg.update().catch(function () {});
573
+ });
574
+
575
+ return reg;
576
+ })
556
577
  .then(function () { return navigator.serviceWorker.ready; })
557
578
  .then(function (reg) {
558
579
  // Fetch current VAPID key to detect key changes