@clagentic/console 1.0.0-beta.2 → 1.0.0-beta.4

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.
@@ -443,50 +443,52 @@ export function initCursors() {
443
443
  });
444
444
 
445
445
  // Track local text selection and send to server
446
- document.addEventListener("selectionchange", function () {
447
- if (!shouldBroadcastCollab()) return;
448
- var ws = getWs();
449
- if (!ws || ws.readyState !== 1) return;
450
- if (selectionThrottleTimer) return;
451
- selectionThrottleTimer = setTimeout(function () { selectionThrottleTimer = null; }, 100);
452
-
453
- var activeEl = document.activeElement;
454
- if (activeEl && activeEl.id === "input" && lastSelectionKey === "") return;
455
-
456
- var sel = window.getSelection();
457
- if (!sel || sel.rangeCount === 0 || sel.isCollapsed) {
458
- // Selection cleared
459
- if (lastSelectionKey !== "") {
460
- lastSelectionKey = "";
461
- sendWsQuiet({ type: "text_select", ranges: [] });
446
+ if (store.get('isMultiUserMode')) {
447
+ document.addEventListener("selectionchange", function () {
448
+ if (!shouldBroadcastCollab()) return;
449
+ var ws = getWs();
450
+ if (!ws || ws.readyState !== 1) return;
451
+ if (selectionThrottleTimer) return;
452
+ selectionThrottleTimer = setTimeout(function () { selectionThrottleTimer = null; }, 100);
453
+
454
+ var activeEl = document.activeElement;
455
+ if (activeEl && activeEl.id === "input" && lastSelectionKey === "") return;
456
+
457
+ var sel = window.getSelection();
458
+ if (!sel || sel.rangeCount === 0 || sel.isCollapsed) {
459
+ // Selection cleared
460
+ if (lastSelectionKey !== "") {
461
+ lastSelectionKey = "";
462
+ sendWsQuiet({ type: "text_select", ranges: [] });
463
+ }
464
+ return;
462
465
  }
463
- return;
464
- }
465
466
 
466
- var ranges = [];
467
- for (var i = 0; i < sel.rangeCount; i++) {
468
- var range = sel.getRangeAt(i);
469
- var startTurn = findParentTurn(range.startContainer);
470
- var endTurn = findParentTurn(range.endContainer);
471
- if (!startTurn || !endTurn) continue;
472
- // Both must be inside messagesEl
473
- if (!messagesEl.contains(startTurn)) continue;
474
-
475
- var startCh = getCharOffset(startTurn, range.startContainer, range.startOffset);
476
- var endCh = getCharOffset(endTurn, range.endContainer, range.endOffset);
477
-
478
- ranges.push({
479
- startTurn: parseInt(startTurn.dataset.turn, 10),
480
- startCh: startCh,
481
- endTurn: parseInt(endTurn.dataset.turn, 10),
482
- endCh: endCh
483
- });
484
- }
467
+ var ranges = [];
468
+ for (var i = 0; i < sel.rangeCount; i++) {
469
+ var range = sel.getRangeAt(i);
470
+ var startTurn = findParentTurn(range.startContainer);
471
+ var endTurn = findParentTurn(range.endContainer);
472
+ if (!startTurn || !endTurn) continue;
473
+ // Both must be inside messagesEl
474
+ if (!messagesEl.contains(startTurn)) continue;
475
+
476
+ var startCh = getCharOffset(startTurn, range.startContainer, range.startOffset);
477
+ var endCh = getCharOffset(endTurn, range.endContainer, range.endOffset);
478
+
479
+ ranges.push({
480
+ startTurn: parseInt(startTurn.dataset.turn, 10),
481
+ startCh: startCh,
482
+ endTurn: parseInt(endTurn.dataset.turn, 10),
483
+ endCh: endCh
484
+ });
485
+ }
485
486
 
486
- var key = JSON.stringify(ranges);
487
- if (key === lastSelectionKey) return;
488
- lastSelectionKey = key;
487
+ var key = JSON.stringify(ranges);
488
+ if (key === lastSelectionKey) return;
489
+ lastSelectionKey = key;
489
490
 
490
- sendWsQuiet({ type: "text_select", ranges: ranges });
491
- });
491
+ sendWsQuiet({ type: "text_select", ranges: ranges });
492
+ });
493
+ }
492
494
  }
@@ -62,6 +62,14 @@ export function processMessage(msg) {
62
62
  case "history_meta":
63
63
  store.set({ historyFrom: msg.from, historyTotal: msg.total, replayingHistory: true });
64
64
  updateHistorySentinel();
65
+ // Arm sticky-bottom at the START of replay so the scroll listener's
66
+ // "user scrolled up" detection is suppressed for the entire history
67
+ // append sequence. Without this, scroll events fired during DOM growth
68
+ // can set isUserScrolledUp=true before history_done's arm fires, leaving
69
+ // the user stranded mid-conversation on resume (especially on mobile).
70
+ if (!getPendingNavigate() || !(getPendingNavigate().toolId || getPendingNavigate().assistantUuid)) {
71
+ armStickyBottom(5000);
72
+ }
65
73
  break;
66
74
 
67
75
  case "history_prepend":
@@ -80,7 +88,12 @@ export function processMessage(msg) {
80
88
  var nav = getPendingNavigate();
81
89
  var hasNavTarget = nav && (nav.toolId || nav.assistantUuid);
82
90
  if (!hasNavTarget) {
83
- armStickyBottom(750);
91
+ // Use a longer quiet window when replaying long history — deferred
92
+ // content (lazy images, async markdown, todo compaction) can keep
93
+ // arriving for several seconds on mobile with a large transcript.
94
+ var historyLen = store.get('historyTotal') || 0;
95
+ var quietMs = historyLen > 20 ? 2000 : 750;
96
+ armStickyBottom(quietMs);
84
97
  }
85
98
  // Batched syntax highlight + mermaid pass for the entire replayed
86
99
  // transcript. Per-message highlights are skipped during replay
@@ -89,6 +102,15 @@ export function processMessage(msg) {
89
102
  if (messagesEl) {
90
103
  highlightCodeBlocks(messagesEl);
91
104
  renderMermaidBlocks(messagesEl);
105
+ // Re-arm after highlight batch completes — Highlight.js defers work
106
+ // via requestAnimationFrame, so the actual DOM updates may happen
107
+ // after the synchronous call returns. This re-arm catches the deferred
108
+ // work on slow browsers.
109
+ setTimeout(function () {
110
+ if (!store.get('processing')) {
111
+ armStickyBottom(500);
112
+ }
113
+ }, 300);
92
114
  }
93
115
  // Compact dead-session todo widgets (unfinished items will never
94
116
  // resolve — the agent isn't coming back) so they don't anchor
@@ -555,7 +555,7 @@ export function showUpdateBanner(msg) {
555
555
  '<div class="notif-banner-project">CLAY</div>' +
556
556
  '<div class="notif-banner-title">v' + escapeHtml(msg.version) + ' is available</div>' +
557
557
  (isHeadless
558
- ? '<div class="notif-banner-text">Run: npx clay-server@' + escapeHtml(updTag) + '</div>'
558
+ ? '<div class="notif-banner-text">Run: npx @clagentic/console@' + escapeHtml(updTag) + '</div>'
559
559
  : '') +
560
560
  actionsHtml +
561
561
  '</div>' +
@@ -132,13 +132,16 @@ export function armStickyBottom(durationMs) {
132
132
  stickyBottomQuietMs = durationMs || 750;
133
133
  if (stickyBottomQuietTimer) clearTimeout(stickyBottomQuietTimer);
134
134
  stickyBottomQuietTimer = setTimeout(disarmStickyBottom, stickyBottomQuietMs);
135
- // Hard ceiling so we never lock the scroller indefinitely if some
136
- // animation/observer keeps firing forever.
135
+ // Hard ceiling: use at least the quiet window + 5s headroom so a long
136
+ // history replay arm (durationMs=5000) can't be cut short by a stale
137
+ // ceiling set from a prior shorter arm.
138
+ var ceiling = Math.max(stickyBottomCeilingMs, (durationMs || 750) + 5000);
137
139
  if (stickyBottomCeilingTimer) clearTimeout(stickyBottomCeilingTimer);
138
- stickyBottomCeilingTimer = setTimeout(disarmStickyBottom, stickyBottomCeilingMs);
140
+ stickyBottomCeilingTimer = setTimeout(disarmStickyBottom, ceiling);
139
141
  }
140
142
 
141
143
  export function disarmStickyBottom() {
144
+ if (!stickyBottom) return; // already disarmed — skip timer ops
142
145
  stickyBottom = false;
143
146
  if (stickyBottomQuietTimer) { clearTimeout(stickyBottomQuietTimer); stickyBottomQuietTimer = null; }
144
147
  if (stickyBottomCeilingTimer) { clearTimeout(stickyBottomCeilingTimer); stickyBottomCeilingTimer = null; }
@@ -192,13 +195,13 @@ export function scrollToBottom() {
192
195
  });
193
196
  }
194
197
 
195
- export function forceScrollToBottom() {
198
+ export function forceScrollToBottom(quietMs) {
196
199
  if (prependAnchor) return;
197
200
  // Arm sticky-bottom mode so deferred layout (tool widgets, code highlighting,
198
201
  // image loads) can't strand the user partway down — single-rAF pin captures
199
202
  // a stale scrollHeight, then growth below pushes the bottom further away.
200
203
  // The quiet detector extends the window automatically while layout shifts.
201
- armStickyBottom(750);
204
+ armStickyBottom(quietMs || 750);
202
205
  }
203
206
 
204
207
  export function getMsgTime() {
@@ -433,6 +436,9 @@ export function finalizeAssistantBlock() {
433
436
  contentEl.innerHTML = html;
434
437
  highlightCodeBlocks(contentEl);
435
438
  renderMermaidBlocks(contentEl);
439
+ // Re-pin after the last-message expansion — this fires after the
440
+ // initial history_done arm may have already expired on mobile.
441
+ armStickyBottom(500);
436
442
  }
437
443
  }, 0);
438
444
  });
@@ -604,6 +604,8 @@ function getAllCommands() {
604
604
  return builtinCommands.concat(ctx.slashCommands());
605
605
  }
606
606
 
607
+ var _lastSlashRenderKey = "";
608
+
607
609
  function showSlashMenu(filter) {
608
610
  var query = filter.toLowerCase();
609
611
  slashFiltered = getAllCommands().filter(function (c) {
@@ -611,6 +613,16 @@ function showSlashMenu(filter) {
611
613
  });
612
614
  if (slashFiltered.length === 0) { hideSlashMenu(); return; }
613
615
 
616
+ // Compute a cheap key to detect if the filtered set has changed
617
+ var renderKey = slashFiltered.map(function (c) { return c.name; }).join(",");
618
+ if (ctx.slashMenu.classList.contains("visible") && renderKey === _lastSlashRenderKey) {
619
+ // Same candidates — just update highlight
620
+ slashActiveIdx = 0;
621
+ updateSlashHighlight();
622
+ return;
623
+ }
624
+ _lastSlashRenderKey = renderKey;
625
+
614
626
  slashActiveIdx = 0;
615
627
  ctx.slashMenu.innerHTML = slashFiltered.map(function (c, i) {
616
628
  return '<div class="slash-item' + (i === 0 ? ' active' : '') + '" data-idx="' + i + '">' +
@@ -623,6 +635,7 @@ function showSlashMenu(filter) {
623
635
 
624
636
  export function hideSlashMenu() {
625
637
  if (slashFiltered.length === 0 && slashActiveIdx === -1) return; // already hidden
638
+ _lastSlashRenderKey = "";
626
639
  ctx.slashMenu.classList.remove("visible");
627
640
  ctx.slashMenu.innerHTML = "";
628
641
  slashActiveIdx = -1;
@@ -200,6 +200,39 @@ export function renderMermaidBlocks(el) {
200
200
  }
201
201
  });
202
202
  }
203
+ export function highlightCodeBlocksBatched(container, onDone) {
204
+ var blocks = Array.prototype.slice.call(container.querySelectorAll("pre > code:not(.hljs)"));
205
+ if (blocks.length === 0) { if (onDone) onDone(); return; }
206
+
207
+ var BATCH = 5; // blocks per idle callback
208
+ var idx = 0;
209
+
210
+ function processBatch(deadline) {
211
+ while (idx < blocks.length) {
212
+ // In rAF fallback mode, deadline is null — process one per frame
213
+ if (deadline && deadline.timeRemaining() < 2) break;
214
+ try { hljs.highlightElement(blocks[idx]); } catch (e) {}
215
+ idx++;
216
+ if (!deadline) break; // rAF mode: one per frame
217
+ }
218
+ if (idx < blocks.length) {
219
+ if (typeof requestIdleCallback !== "undefined") {
220
+ requestIdleCallback(processBatch, { timeout: 2000 });
221
+ } else {
222
+ requestAnimationFrame(function () { processBatch(null); });
223
+ }
224
+ } else {
225
+ if (onDone) onDone();
226
+ }
227
+ }
228
+
229
+ if (typeof requestIdleCallback !== "undefined") {
230
+ requestIdleCallback(processBatch, { timeout: 2000 });
231
+ } else {
232
+ requestAnimationFrame(function () { processBatch(null); });
233
+ }
234
+ }
235
+
203
236
 
204
237
  export function showMermaidModal(svgHtml) {
205
238
  var modal = document.getElementById("mermaid-modal");
@@ -177,6 +177,8 @@ function buildMentionCandidates() {
177
177
  return candidates;
178
178
  }
179
179
 
180
+ var _lastMentionRenderKey = "";
181
+
180
182
  export function showMentionMenu(query) {
181
183
  var candidates = buildMentionCandidates();
182
184
  if (candidates.length === 0) {
@@ -197,6 +199,16 @@ export function showMentionMenu(query) {
197
199
  return;
198
200
  }
199
201
 
202
+ // Compute a cheap key to detect if the filtered set has changed
203
+ var renderKey = mentionFiltered.map(function (c) { return c.id || c.name; }).join(",");
204
+ if (mentionActive && renderKey === _lastMentionRenderKey) {
205
+ // Same candidates — just update highlight
206
+ mentionActiveIdx = 0;
207
+ updateMentionHighlight();
208
+ return;
209
+ }
210
+ _lastMentionRenderKey = renderKey;
211
+
200
212
  mentionActive = true;
201
213
  mentionActiveIdx = 0;
202
214
 
@@ -225,6 +237,7 @@ export function showMentionMenu(query) {
225
237
 
226
238
  export function hideMentionMenu() {
227
239
  if (!mentionActive && mentionFiltered.length === 0) return; // already hidden
240
+ _lastMentionRenderKey = "";
228
241
  mentionActive = false;
229
242
  mentionActiveIdx = -1;
230
243
  mentionFiltered = [];
@@ -113,7 +113,7 @@ export function initNotifications(_ctx) {
113
113
  copyBtn.addEventListener("click", function (e) {
114
114
  e.stopPropagation();
115
115
  var cmdEl = document.getElementById("update-manual-cmd");
116
- var cmdText = cmdEl ? cmdEl.textContent : "npx clay-server@latest";
116
+ var cmdText = cmdEl ? cmdEl.textContent : "npx @clagentic/console@latest";
117
117
  copyToClipboard(cmdText).then(function () {
118
118
  copyBtn.classList.add("copied");
119
119
  copyBtn.innerHTML = iconHtml("check");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.0-beta.2",
6
+ "version": "1.0.0-beta.4",
7
7
  "description": "Self-hosted console for Claude Code and Codex. Multi-user, browser-based, persistent AI sessions.",
8
8
  "bin": {
9
9
  "clagentic": "./bin/cli.js",