@clagentic/console 1.7.1-beta.1 → 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 (39) hide show
  1. package/bin/cli.js +198 -2542
  2. package/lib/build-sha.json +2 -2
  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/pages.js +13 -17
  9. package/lib/public/css/diagnostics.css +15 -0
  10. package/lib/public/css/overlays.css +19 -0
  11. package/lib/public/index.html +12 -11
  12. package/lib/public/manifest.json +1 -1
  13. package/lib/public/modules/app-connection.js +150 -4
  14. package/lib/public/modules/app-history-replay.js +155 -0
  15. package/lib/public/modules/app-home-hub.js +2 -16
  16. package/lib/public/modules/app-messages.js +1245 -1489
  17. package/lib/public/modules/app-notifications.js +4 -4
  18. package/lib/public/modules/command-palette.js +11 -22
  19. package/lib/public/modules/context-sources.js +1 -6
  20. package/lib/public/modules/filebrowser.js +25 -13
  21. package/lib/public/modules/mcp-ui.js +2 -2
  22. package/lib/public/modules/notifications.js +22 -1
  23. package/lib/public/modules/playbook.js +6 -6
  24. package/lib/public/modules/project-settings.js +5 -13
  25. package/lib/public/modules/qrcode.js +2 -2
  26. package/lib/public/modules/relative-time.js +27 -0
  27. package/lib/public/modules/scheduler-history.js +1 -5
  28. package/lib/public/modules/server-settings.js +28 -15
  29. package/lib/public/modules/sidebar-projects.js +1 -1
  30. package/lib/public/modules/sidebar-sessions.js +1 -15
  31. package/lib/public/modules/sidebar.js +3 -3
  32. package/lib/public/modules/utils.js +1 -0
  33. package/lib/public/sw.js +24 -4
  34. package/lib/server-auth.js +48 -2
  35. package/lib/server-settings.js +70 -4
  36. package/lib/server.js +200 -4
  37. package/lib/smtp.js +6 -6
  38. package/lib/yoke/adapters/codex.js +1 -1
  39. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ // app-history-replay.js - history_meta / history_prepend / history_done
2
+ // Extracted from app-messages.js (lr-4e49 Part 2: 185-case switch -> handler
3
+ // registry). This block was called out in the split task as the sharpest
4
+ // ordering risk: history_meta arms sticky-bottom scroll BEFORE the replay
5
+ // batch runs, and history_done re-evaluates / finalizes it AFTER. Both
6
+ // handlers share no local module state with each other (all state lives in
7
+ // `store` or module-level refs in app-rendering.js / pending-navigate.js),
8
+ // so extracting them verbatim preserves the exact sequencing the client
9
+ // already depends on — nothing here changes call order relative to the
10
+ // original switch.
11
+
12
+ import { store } from './store.js';
13
+ import { renderMarkdown, highlightCodeBlocksBatched, renderMermaidBlocks } from './markdown.js';
14
+ import { getPendingNavigate, peekPendingNavigate } from './pending-navigate.js';
15
+ import { armStickyBottom, disarmStickyBottom, scrollToBottom, finalizeAssistantBlock } from './app-rendering.js';
16
+ import { applyDeadSessionTodoCompaction, markAllToolsDone } from './tools.js';
17
+ import { accumulateContext, updateContextPanel, updateUsagePanel, getSessionUsage } from './app-panels.js';
18
+ import { stopUrgentBlink } from './app-favicon.js';
19
+
20
+ var replayLoadingEl = document.getElementById("replay-loading");
21
+
22
+ // updateHistorySentinel is intentionally NOT imported here: app-header.js
23
+ // imports processMessage from app-messages.js, so an app-history-replay.js
24
+ // -> app-header.js import would close an import cycle back through
25
+ // app-messages.js. The caller (app-messages.js, which already imports
26
+ // app-header.js today) supplies it instead.
27
+ export function handleHistoryMeta(msg, updateHistorySentinelFn) {
28
+ store.set({ historyFrom: msg.from, historyTotal: msg.total, replayingHistory: true });
29
+ if (replayLoadingEl) replayLoadingEl.classList.remove("hidden");
30
+ updateHistorySentinelFn();
31
+ // Arm sticky-bottom at the START of replay so the scroll listener's
32
+ // "user scrolled up" detection is suppressed for the entire history
33
+ // append sequence. Without this, scroll events fired during DOM growth
34
+ // can set isUserScrolledUp=true before history_done's arm fires, leaving
35
+ // the user stranded mid-conversation on resume (especially on mobile).
36
+ // Peek without consuming — getPendingNavigate() is the single consumer
37
+ // in the history_done branch below. Calling getPendingNavigate() here
38
+ // would clear the value before history_done can use it.
39
+ var _metaNav = peekPendingNavigate();
40
+ if (!_metaNav || !(_metaNav.toolId || _metaNav.assistantUuid)) {
41
+ armStickyBottom(5000, true); // force: history replay must scroll to bottom
42
+ }
43
+ }
44
+
45
+ export function handleHistoryDone(msg) {
46
+ var messagesEl = document.getElementById("messages");
47
+ store.set({ replayingHistory: false });
48
+ if (replayLoadingEl) replayLoadingEl.classList.add("hidden");
49
+ // Arm sticky-bottom FIRST so the ResizeObserver is watching before the
50
+ // bulk DOM mutations below (syntax highlighting, mermaid, todo
51
+ // compaction) displace the scroll position. Arming after those writes
52
+ // races the browser's layout resolution and can leave the user stranded
53
+ // mid-conversation. The arm is later re-evaluated and potentially
54
+ // replaced by the nav-target branch below; that branch calls
55
+ // scrollToBottom() and does NOT re-arm, so this early arm is harmless.
56
+ var nav = getPendingNavigate();
57
+ var hasNavTarget = nav && (nav.toolId || nav.assistantUuid);
58
+ if (!hasNavTarget) {
59
+ // Scale the quiet window with history depth. A 20-item threshold
60
+ // (old code) gave identical 2000ms to sessions with 21 and 1000
61
+ // items. The scaled formula gives fast disarm for small sessions
62
+ // and up to 3000ms for very large ones (>=500 events), without
63
+ // a hard ceiling that cuts off still-settling content on mobile.
64
+ var historyLen = store.get('historyTotal') || 0;
65
+ var quietMs = Math.min(Math.max(500, Math.round(historyLen * 2.5)), 3000);
66
+ armStickyBottom(quietMs, true); // force: history replay must scroll to bottom
67
+ }
68
+ // Batched syntax highlight + mermaid pass for the entire replayed
69
+ // transcript. Per-message highlights are skipped during replay
70
+ // (see markdown.js). Uses requestIdleCallback batching to avoid
71
+ // blocking the main thread — the old synchronous highlightCodeBlocks()
72
+ // fired hljs on every code block at once, each triggering a
73
+ // ResizeObserver callback that reset the sticky-bottom quiet timer,
74
+ // keeping the scroll pinned and the UI unresponsive for several
75
+ // seconds on large sessions (especially on mobile). The completion
76
+ // callback re-arms once after all blocks are done.
77
+ if (messagesEl) {
78
+ highlightCodeBlocksBatched(messagesEl, function () {
79
+ if (!store.get('processing')) {
80
+ armStickyBottom(500, true); // force: re-pin after all blocks settle
81
+ }
82
+ });
83
+ renderMermaidBlocks(messagesEl);
84
+ // NOTE: The old 300ms setTimeout re-arm is removed. The batched
85
+ // highlight completion callback above replaces it. The 300ms timer
86
+ // was a workaround for Highlight.js deferred work that no longer
87
+ // applies with the idle-callback batching path.
88
+ }
89
+ // Compact dead-session todo widgets (unfinished items will never
90
+ // resolve — the agent isn't coming back) so they don't anchor
91
+ // visual position mid-page on resume.
92
+ if (!store.get('sessionIsProcessing')) {
93
+ applyDeadSessionTodoCompaction();
94
+ }
95
+ // Hide vendor toggle if session has history (vendor already locked)
96
+ var _hTotal = store.get('historyTotal') || 0;
97
+ var _vtw2 = document.getElementById("vendor-toggle-wrap");
98
+ if (_vtw2 && _hTotal > 0) { _vtw2.classList.remove("hidden"); _vtw2.classList.add("locked"); }
99
+ // Restore cached rich context usage BEFORE updateContextPanel runs
100
+ if (msg.contextUsage) {
101
+ store.set({ richContextUsage: msg.contextUsage });
102
+ }
103
+ // Restore accurate context data from the last result in full history.
104
+ // accumulateContext handles context bar fill; accumulateUsage restores the
105
+ // usage panel's context/cost values. Both assign (not sum) so replay
106
+ // accumulation during history messages is correctly overwritten here.
107
+ if (msg.lastUsage || msg.lastModelUsage) {
108
+ accumulateContext(msg.lastCost, msg.lastUsage, msg.lastModelUsage, msg.lastStreamInputTokens);
109
+ }
110
+ // Restore usage panel from the last result in history.
111
+ // output/cacheWrite are cumulative sums that were accumulated during replay above;
112
+ // we keep them. cost and context come from the last result directly.
113
+ if (msg.lastCost != null) {
114
+ var su = getSessionUsage();
115
+ su.cost = msg.lastCost;
116
+ if (msg.lastStreamInputTokens) su.context = msg.lastStreamInputTokens;
117
+ }
118
+ updateContextPanel();
119
+ updateUsagePanel();
120
+ // Render + finalize any incomplete turn from the replayed history
121
+ var _hs = store.snap();
122
+ if (_hs.currentMsgEl && _hs.currentFullText) {
123
+ var replayContentEl = _hs.currentMsgEl.querySelector(".md-content");
124
+ if (replayContentEl) {
125
+ replayContentEl.innerHTML = renderMarkdown(_hs.currentFullText);
126
+ }
127
+ }
128
+ markAllToolsDone();
129
+ finalizeAssistantBlock();
130
+ stopUrgentBlink();
131
+ // Scroll to tool element if navigating from file edit history.
132
+ // nav/hasNavTarget are declared above (early arm block).
133
+ if (hasNavTarget) {
134
+ // Nav target: discard the early sticky-bottom arm and scroll to element.
135
+ disarmStickyBottom();
136
+ scrollToBottom();
137
+ }
138
+ if (hasNavTarget) {
139
+ requestAnimationFrame(function() {
140
+ // Prefer scrolling to the exact tool element
141
+ var target = nav.toolId ? messagesEl.querySelector('[data-tool-id="' + nav.toolId + '"]') : null;
142
+ if (!target && nav.assistantUuid) {
143
+ target = messagesEl.querySelector('[data-uuid="' + nav.assistantUuid + '"]');
144
+ }
145
+ if (target) {
146
+ // Auto-expand parent tool group if collapsed
147
+ var parentGroup = target.closest(".tool-group");
148
+ if (parentGroup) parentGroup.classList.remove("collapsed");
149
+ target.scrollIntoView({ behavior: "smooth", block: "center" });
150
+ target.classList.add("message-blink");
151
+ setTimeout(function() { target.classList.remove("message-blink"); }, 2000);
152
+ }
153
+ });
154
+ }
155
+ }
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { store } from './store.js';
5
5
  import { getWs } from './ws-ref.js';
6
- import { escapeHtml } from './utils.js';
6
+ import { escapeHtml, relativeTime } from './utils.js';
7
7
  import { switchProject, getCachedProjects, renderProjectList } from './app-projects.js';
8
8
  import { renderProjectIcon, projectIconHtml } from './project-icon.js';
9
9
  import { openSchedulerToTab } from './scheduler.js';
@@ -248,20 +248,6 @@ function projectHasAlert(projectSlug) {
248
248
  return false;
249
249
  }
250
250
 
251
- function formatRelativeTime(ts) {
252
- if (!ts) return "";
253
- var diff = Date.now() - ts;
254
- var m = Math.floor(diff / 60000);
255
- if (m < 1) return "just now";
256
- if (m < 60) return m + "m ago";
257
- var h = Math.floor(m / 60);
258
- if (h < 24) return h + "h ago";
259
- var d = Math.floor(h / 24);
260
- if (d === 1) return "yesterday";
261
- if (d < 7) return d + "d ago";
262
- return Math.floor(d / 7) + "w ago";
263
- }
264
-
265
251
  export function renderHomeHub(projects) {
266
252
  // Greeting + weather tooltip
267
253
  updateGreetingWeather();
@@ -471,7 +457,7 @@ export function handleHubRecentSessions(msg) {
471
457
  var iconHtml = sess.projectIcon
472
458
  ? '<span class="hub-recent-project-icon">' + projectIconHtml(sess.projectIcon) + '</span>'
473
459
  : '<span class="hub-recent-project-icon hub-recent-project-icon--blank"></span>';
474
- var timeStr = formatRelativeTime(sess.lastActivity);
460
+ var timeStr = relativeTime(sess.lastActivity);
475
461
  var agentBadge = sess.agentName
476
462
  ? '<span class="hub-recent-agent">' + escapeHtml(sess.agentName) + '</span>'
477
463
  : '';