@clagentic/console 1.0.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 (221) hide show
  1. package/CREDITS.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +250 -0
  4. package/bin/cli.js +2812 -0
  5. package/lib/agents-favorites.js +164 -0
  6. package/lib/agents.js +282 -0
  7. package/lib/ask-user-mcp-server.js +120 -0
  8. package/lib/browser-mcp-server.js +484 -0
  9. package/lib/build-user-env.js +63 -0
  10. package/lib/certs/fullchain.pem +47 -0
  11. package/lib/certs/privkey.pem +5 -0
  12. package/lib/cli-sessions.js +265 -0
  13. package/lib/codex-defaults.js +18 -0
  14. package/lib/config.js +332 -0
  15. package/lib/crisis-safety.js +60 -0
  16. package/lib/daemon-projects.js +164 -0
  17. package/lib/daemon.js +1602 -0
  18. package/lib/dm.js +128 -0
  19. package/lib/ipc.js +125 -0
  20. package/lib/ipv4-only.js +39 -0
  21. package/lib/mcp-local.js +385 -0
  22. package/lib/notes.js +141 -0
  23. package/lib/os-users.js +529 -0
  24. package/lib/pages.js +1325 -0
  25. package/lib/project-connection.js +302 -0
  26. package/lib/project-external-trigger.js +236 -0
  27. package/lib/project-file-watch.js +120 -0
  28. package/lib/project-filesystem.js +528 -0
  29. package/lib/project-http.js +753 -0
  30. package/lib/project-image.js +95 -0
  31. package/lib/project-knowledge.js +88 -0
  32. package/lib/project-loop.js +1304 -0
  33. package/lib/project-mcp.js +374 -0
  34. package/lib/project-memory.js +39 -0
  35. package/lib/project-notifications.js +262 -0
  36. package/lib/project-sessions.js +1581 -0
  37. package/lib/project-user-mention.js +193 -0
  38. package/lib/project-user-message.js +628 -0
  39. package/lib/project.js +1303 -0
  40. package/lib/public/app.js +1031 -0
  41. package/lib/public/apple-touch-icon.png +0 -0
  42. package/lib/public/claude-code-avatar.png +0 -0
  43. package/lib/public/codex-avatar.png +0 -0
  44. package/lib/public/console-icon.png +0 -0
  45. package/lib/public/css/admin.css +736 -0
  46. package/lib/public/css/agent-picker.css +119 -0
  47. package/lib/public/css/base.css +235 -0
  48. package/lib/public/css/channel-layout.css +441 -0
  49. package/lib/public/css/command-palette.css +559 -0
  50. package/lib/public/css/debate.css +1609 -0
  51. package/lib/public/css/diff.css +139 -0
  52. package/lib/public/css/filebrowser.css +1976 -0
  53. package/lib/public/css/highlight.css +144 -0
  54. package/lib/public/css/home-hub.css +545 -0
  55. package/lib/public/css/icon-strip.css +1856 -0
  56. package/lib/public/css/input.css +1349 -0
  57. package/lib/public/css/loop.css +1248 -0
  58. package/lib/public/css/mention.css +317 -0
  59. package/lib/public/css/menus.css +857 -0
  60. package/lib/public/css/messages.css +1833 -0
  61. package/lib/public/css/mobile-nav.css +1332 -0
  62. package/lib/public/css/notifications-center.css +296 -0
  63. package/lib/public/css/overlays.css +1273 -0
  64. package/lib/public/css/playbook.css +264 -0
  65. package/lib/public/css/profile.css +397 -0
  66. package/lib/public/css/rewind.css +671 -0
  67. package/lib/public/css/scheduler-modal.css +1495 -0
  68. package/lib/public/css/scheduler.css +1420 -0
  69. package/lib/public/css/server-settings.css +909 -0
  70. package/lib/public/css/session-search.css +159 -0
  71. package/lib/public/css/sidebar.css +2012 -0
  72. package/lib/public/css/skills.css +789 -0
  73. package/lib/public/css/sticky-notes.css +854 -0
  74. package/lib/public/css/stt.css +155 -0
  75. package/lib/public/css/title-bar.css +674 -0
  76. package/lib/public/css/tooltip.css +67 -0
  77. package/lib/public/css/user-settings.css +702 -0
  78. package/lib/public/emoji-data.json +1 -0
  79. package/lib/public/favicon-banded-32.png +0 -0
  80. package/lib/public/favicon-banded.png +0 -0
  81. package/lib/public/favicon-dark.svg +32 -0
  82. package/lib/public/favicon.svg +32 -0
  83. package/lib/public/icon-192.png +0 -0
  84. package/lib/public/icon-512.png +0 -0
  85. package/lib/public/icon-banded-76.png +0 -0
  86. package/lib/public/icon-banded-96.png +0 -0
  87. package/lib/public/icon-mono.svg +25 -0
  88. package/lib/public/icons/email/gmail.svg +7 -0
  89. package/lib/public/icons/email/outlook.svg +35 -0
  90. package/lib/public/icons/email/yahoo.svg +1 -0
  91. package/lib/public/index.html +1946 -0
  92. package/lib/public/manifest.json +27 -0
  93. package/lib/public/markdown-worker.js +43 -0
  94. package/lib/public/marked.min.js +6 -0
  95. package/lib/public/modules/admin.js +954 -0
  96. package/lib/public/modules/agent-picker.js +429 -0
  97. package/lib/public/modules/app-connection.js +216 -0
  98. package/lib/public/modules/app-cursors.js +492 -0
  99. package/lib/public/modules/app-dm.js +265 -0
  100. package/lib/public/modules/app-favicon.js +231 -0
  101. package/lib/public/modules/app-header.js +242 -0
  102. package/lib/public/modules/app-home-hub.js +432 -0
  103. package/lib/public/modules/app-loop-ui.js +691 -0
  104. package/lib/public/modules/app-loop-wizard.js +439 -0
  105. package/lib/public/modules/app-messages.js +1415 -0
  106. package/lib/public/modules/app-misc.js +463 -0
  107. package/lib/public/modules/app-notifications.js +651 -0
  108. package/lib/public/modules/app-panels.js +1061 -0
  109. package/lib/public/modules/app-projects.js +875 -0
  110. package/lib/public/modules/app-rate-limit.js +529 -0
  111. package/lib/public/modules/app-rendering.js +739 -0
  112. package/lib/public/modules/app-skills-install.js +285 -0
  113. package/lib/public/modules/avatar.js +36 -0
  114. package/lib/public/modules/command-palette.js +491 -0
  115. package/lib/public/modules/console-logo.js +162 -0
  116. package/lib/public/modules/context-sources.js +365 -0
  117. package/lib/public/modules/diff.js +412 -0
  118. package/lib/public/modules/dom-refs.js +21 -0
  119. package/lib/public/modules/emoji-picker.js +222 -0
  120. package/lib/public/modules/events.js +21 -0
  121. package/lib/public/modules/filebrowser.js +1966 -0
  122. package/lib/public/modules/fileicons.js +172 -0
  123. package/lib/public/modules/icons.js +80 -0
  124. package/lib/public/modules/input.js +1102 -0
  125. package/lib/public/modules/longpress.js +74 -0
  126. package/lib/public/modules/markdown.js +486 -0
  127. package/lib/public/modules/mcp-ui.js +295 -0
  128. package/lib/public/modules/mention.js +1093 -0
  129. package/lib/public/modules/notifications.js +613 -0
  130. package/lib/public/modules/playbook.js +578 -0
  131. package/lib/public/modules/profile.js +594 -0
  132. package/lib/public/modules/project-settings.js +849 -0
  133. package/lib/public/modules/project-switcher.js +375 -0
  134. package/lib/public/modules/qrcode.js +87 -0
  135. package/lib/public/modules/rewind.js +381 -0
  136. package/lib/public/modules/scheduler-config.js +1611 -0
  137. package/lib/public/modules/scheduler-history.js +131 -0
  138. package/lib/public/modules/scheduler.js +1689 -0
  139. package/lib/public/modules/server-settings.js +842 -0
  140. package/lib/public/modules/session-search.js +456 -0
  141. package/lib/public/modules/settings-defaults.js +253 -0
  142. package/lib/public/modules/sidebar-mobile.js +1425 -0
  143. package/lib/public/modules/sidebar-projects.js +2022 -0
  144. package/lib/public/modules/sidebar-sessions.js +1548 -0
  145. package/lib/public/modules/sidebar-users.js +449 -0
  146. package/lib/public/modules/sidebar.js +348 -0
  147. package/lib/public/modules/skills.js +793 -0
  148. package/lib/public/modules/state.js +3 -0
  149. package/lib/public/modules/sticky-notes.js +1221 -0
  150. package/lib/public/modules/store.js +34 -0
  151. package/lib/public/modules/stt.js +266 -0
  152. package/lib/public/modules/terminal.js +987 -0
  153. package/lib/public/modules/theme.js +812 -0
  154. package/lib/public/modules/tool-palette.js +562 -0
  155. package/lib/public/modules/tools.js +2285 -0
  156. package/lib/public/modules/tooltip.js +150 -0
  157. package/lib/public/modules/user-settings.js +544 -0
  158. package/lib/public/modules/utils.js +56 -0
  159. package/lib/public/modules/ws-ref.js +26 -0
  160. package/lib/public/style.css +34 -0
  161. package/lib/public/sw.js +159 -0
  162. package/lib/push.js +149 -0
  163. package/lib/scheduler.js +471 -0
  164. package/lib/sdk-bridge.js +1792 -0
  165. package/lib/sdk-message-processor.js +740 -0
  166. package/lib/sdk-message-queue.js +42 -0
  167. package/lib/sdk-skill-discovery.js +131 -0
  168. package/lib/sdk-worker.js +677 -0
  169. package/lib/server-admin.js +712 -0
  170. package/lib/server-auth.js +737 -0
  171. package/lib/server-dm.js +170 -0
  172. package/lib/server-palette.js +104 -0
  173. package/lib/server-settings.js +553 -0
  174. package/lib/server-skills.js +280 -0
  175. package/lib/server.js +1390 -0
  176. package/lib/session-search.js +693 -0
  177. package/lib/sessions.js +946 -0
  178. package/lib/smtp.js +221 -0
  179. package/lib/terminal-manager.js +219 -0
  180. package/lib/terminal.js +39 -0
  181. package/lib/themes/ayu-light.json +9 -0
  182. package/lib/themes/catppuccin-latte.json +9 -0
  183. package/lib/themes/catppuccin-mocha.json +9 -0
  184. package/lib/themes/clagentic-dark.json +10 -0
  185. package/lib/themes/clagentic-light.json +10 -0
  186. package/lib/themes/dracula.json +9 -0
  187. package/lib/themes/everforest-light.json +9 -0
  188. package/lib/themes/everforest.json +9 -0
  189. package/lib/themes/github-light.json +9 -0
  190. package/lib/themes/gruvbox-dark.json +9 -0
  191. package/lib/themes/gruvbox-light.json +9 -0
  192. package/lib/themes/monokai.json +9 -0
  193. package/lib/themes/nord-light.json +9 -0
  194. package/lib/themes/nord.json +9 -0
  195. package/lib/themes/one-dark.json +9 -0
  196. package/lib/themes/one-light.json +9 -0
  197. package/lib/themes/rose-pine-dawn.json +9 -0
  198. package/lib/themes/rose-pine.json +9 -0
  199. package/lib/themes/solarized-dark.json +9 -0
  200. package/lib/themes/solarized-light.json +9 -0
  201. package/lib/themes/tokyo-night-light.json +9 -0
  202. package/lib/themes/tokyo-night.json +9 -0
  203. package/lib/updater.js +124 -0
  204. package/lib/user-presence.js +92 -0
  205. package/lib/users-auth.js +146 -0
  206. package/lib/users-permissions.js +118 -0
  207. package/lib/users-preferences.js +254 -0
  208. package/lib/users.js +465 -0
  209. package/lib/utils.js +64 -0
  210. package/lib/worktree.js +134 -0
  211. package/lib/ws-schema.js +464 -0
  212. package/lib/yoke/adapters/claude-worker.js +759 -0
  213. package/lib/yoke/adapters/claude.js +1599 -0
  214. package/lib/yoke/adapters/codex.js +1559 -0
  215. package/lib/yoke/codex-app-server.js +352 -0
  216. package/lib/yoke/index.js +319 -0
  217. package/lib/yoke/instructions.js +61 -0
  218. package/lib/yoke/interface.js +98 -0
  219. package/lib/yoke/mcp-bridge-server.js +302 -0
  220. package/lib/yoke/package.json +7 -0
  221. package/package.json +72 -0
@@ -0,0 +1,456 @@
1
+ // --- In-session search (Cmd+F / Ctrl+F) ---
2
+ import { escapeHtml } from './utils.js';
3
+ import { iconHtml, refreshIcons } from './icons.js';
4
+
5
+ var ctx = null;
6
+ var searchBarEl = null;
7
+ var searchInputEl = null;
8
+ var matchCountEl = null;
9
+ var currentQuery = "";
10
+ var matches = []; // DOM highlight marks (for loaded messages)
11
+ var currentMatchIndex = -1;
12
+ var highlightClass = "session-search-highlight";
13
+ var activeHighlightClass = "session-search-highlight-active";
14
+
15
+ // Timeline state
16
+ var timelineEl = null;
17
+ var timelineScrollHandler = null;
18
+ var serverHits = []; // full history hits from server
19
+ var serverTotal = 0;
20
+ var pendingScrollTarget = null;
21
+
22
+ function initSessionSearch(context) {
23
+ ctx = context;
24
+ createSearchBar();
25
+ document.addEventListener("keydown", function (e) {
26
+ var isMod = e.metaKey || e.ctrlKey;
27
+ if (isMod && e.key === "f") {
28
+ e.preventDefault();
29
+ openSearch();
30
+ }
31
+ if (e.key === "Escape" && isSearchOpen()) {
32
+ e.preventDefault();
33
+ closeSearch();
34
+ }
35
+ });
36
+ }
37
+
38
+ function createSearchBar() {
39
+ searchBarEl = document.createElement("div");
40
+ searchBarEl.id = "session-search-bar";
41
+ searchBarEl.className = "session-search-bar hidden";
42
+ searchBarEl.innerHTML =
43
+ '<div class="session-search-inner">' +
44
+ '<input type="text" id="find-in-session-input" placeholder="Search in this session..." autocomplete="off" spellcheck="false">' +
45
+ '<span class="session-search-count" id="find-in-session-count"></span>' +
46
+ '<button class="session-search-btn" id="find-in-session-prev" title="Previous (Shift+Enter)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg></button>' +
47
+ '<button class="session-search-btn" id="find-in-session-next" title="Next (Enter)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></button>' +
48
+ '<button class="session-search-btn" id="find-in-session-close" title="Close (Esc)" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>' +
49
+ '</div>';
50
+
51
+ // Insert at top of #app
52
+ var appEl = ctx.messagesEl.parentElement;
53
+ appEl.insertBefore(searchBarEl, appEl.firstChild);
54
+
55
+ searchInputEl = document.getElementById("find-in-session-input");
56
+ matchCountEl = document.getElementById("find-in-session-count");
57
+
58
+ var debounceTimer = null;
59
+ searchInputEl.addEventListener("input", function () {
60
+ clearTimeout(debounceTimer);
61
+ debounceTimer = setTimeout(function () {
62
+ performSearch(searchInputEl.value);
63
+ }, 250);
64
+ });
65
+
66
+ searchInputEl.addEventListener("keydown", function (e) {
67
+ if (e.key === "Enter") {
68
+ e.preventDefault();
69
+ if (e.shiftKey) {
70
+ goToPrevMatch();
71
+ } else {
72
+ goToNextMatch();
73
+ }
74
+ }
75
+ if (e.key === "Escape") {
76
+ e.preventDefault();
77
+ closeSearch();
78
+ }
79
+ });
80
+
81
+ document.getElementById("find-in-session-prev").addEventListener("click", function () {
82
+ goToPrevMatch();
83
+ });
84
+ document.getElementById("find-in-session-next").addEventListener("click", function () {
85
+ goToNextMatch();
86
+ });
87
+ document.getElementById("find-in-session-close").addEventListener("click", function () {
88
+ closeSearch();
89
+ });
90
+ }
91
+
92
+ function isSearchOpen() {
93
+ return searchBarEl && !searchBarEl.classList.contains("hidden");
94
+ }
95
+
96
+ function openSearch(prefill) {
97
+ if (!searchBarEl) return;
98
+ searchBarEl.classList.remove("hidden");
99
+ var btn = document.getElementById("find-in-session-btn");
100
+ if (btn) btn.classList.add("active");
101
+ if (typeof prefill === "string" && prefill) {
102
+ searchInputEl.value = prefill;
103
+ performSearch(prefill);
104
+ }
105
+ searchInputEl.focus();
106
+ searchInputEl.select();
107
+ if (!prefill && searchInputEl.value) {
108
+ performSearch(searchInputEl.value);
109
+ }
110
+ }
111
+
112
+ function closeSearch() {
113
+ if (!searchBarEl) return;
114
+ searchBarEl.classList.add("hidden");
115
+ var btn = document.getElementById("find-in-session-btn");
116
+ if (btn) btn.classList.remove("active");
117
+ clearHighlights();
118
+ removeTimeline();
119
+ currentQuery = "";
120
+ matches = [];
121
+ currentMatchIndex = -1;
122
+ serverHits = [];
123
+ serverTotal = 0;
124
+ matchCountEl.textContent = "";
125
+ }
126
+
127
+ function toggleSearch() {
128
+ if (isSearchOpen()) {
129
+ closeSearch();
130
+ } else {
131
+ openSearch();
132
+ }
133
+ }
134
+
135
+ function performSearch(query) {
136
+ clearHighlights();
137
+ removeTimeline();
138
+ matches = [];
139
+ currentMatchIndex = -1;
140
+ serverHits = [];
141
+ serverTotal = 0;
142
+ currentQuery = query.trim();
143
+
144
+ if (!currentQuery) {
145
+ matchCountEl.textContent = "";
146
+ return;
147
+ }
148
+
149
+ // Highlight in currently loaded DOM
150
+ highlightLoadedMessages();
151
+
152
+ // Request full-history search from server
153
+ if (ctx.ws && ctx.ws.readyState === 1) {
154
+ ctx.ws.send(JSON.stringify({ type: "search_session_content", query: currentQuery, source: "find_in_session" }));
155
+ }
156
+ }
157
+
158
+ function highlightLoadedMessages() {
159
+ var messagesEl = ctx.messagesEl;
160
+ var msgEls = messagesEl.querySelectorAll(".msg-user, .msg-assistant");
161
+ var queryLower = currentQuery.toLowerCase();
162
+
163
+ for (var i = 0; i < msgEls.length; i++) {
164
+ var contentEl = msgEls[i].querySelector(".bubble") || msgEls[i].querySelector(".md-content");
165
+ if (!contentEl) continue;
166
+ highlightInElement(contentEl, queryLower);
167
+ }
168
+
169
+ matches = Array.from(messagesEl.querySelectorAll("." + highlightClass));
170
+
171
+ if (matches.length > 0) {
172
+ currentMatchIndex = 0;
173
+ setActiveMatch(0);
174
+ matchCountEl.textContent = "1 / " + matches.length;
175
+ } else {
176
+ matchCountEl.textContent = "Searching...";
177
+ }
178
+ }
179
+
180
+ // Handle server response with full-history search results
181
+ function handleFindInSessionResults(msg) {
182
+ if (!isSearchOpen()) return;
183
+ if (msg.query !== currentQuery) return; // stale
184
+
185
+ serverHits = msg.hits || [];
186
+ serverTotal = msg.total || 0;
187
+
188
+ // Update count to reflect total server hits
189
+ if (serverHits.length > 0) {
190
+ // Re-highlight loaded messages to get accurate DOM match count
191
+ clearHighlights();
192
+ highlightLoadedMessages();
193
+ if (matches.length > 0) {
194
+ matchCountEl.textContent = "1 / " + matches.length + " (" + serverHits.length + " total)";
195
+ } else {
196
+ matchCountEl.textContent = serverHits.length + " matches";
197
+ }
198
+ buildTimeline();
199
+ } else {
200
+ matchCountEl.textContent = "No results";
201
+ }
202
+ }
203
+
204
+ // Called after older history is prepended to DOM
205
+ function onHistoryPrepended() {
206
+ if (!pendingScrollTarget) return;
207
+ var target = pendingScrollTarget;
208
+ pendingScrollTarget = null;
209
+ // Re-highlight with current query
210
+ if (currentQuery && isSearchOpen()) {
211
+ clearHighlights();
212
+ highlightLoadedMessages();
213
+ }
214
+ requestAnimationFrame(function() {
215
+ findAndScrollToMatch(target.snippet, target.query);
216
+ });
217
+ }
218
+
219
+ // --- Timeline (scroll map) ---
220
+ function buildTimeline() {
221
+ removeTimeline();
222
+ if (serverHits.length === 0) return;
223
+
224
+ var messagesEl = ctx.messagesEl;
225
+ var appEl = messagesEl.parentElement;
226
+
227
+ timelineEl = document.createElement("div");
228
+ timelineEl.className = "find-in-session-timeline";
229
+ timelineEl.id = "find-in-session-timeline";
230
+
231
+ var track = document.createElement("div");
232
+ track.className = "rewind-timeline-track";
233
+ track.dataset.historyTotal = serverTotal;
234
+
235
+ var viewport = document.createElement("div");
236
+ viewport.className = "rewind-timeline-viewport";
237
+ track.appendChild(viewport);
238
+
239
+ for (var i = 0; i < serverHits.length; i++) {
240
+ var hit = serverHits[i];
241
+ var pct = serverTotal <= 1 ? 50 : 6 + (hit.historyIndex / (serverTotal - 1)) * 88;
242
+
243
+ var snippetText = hit.snippet;
244
+ if (snippetText.length > 24) snippetText = snippetText.substring(0, 24) + "\u2026";
245
+
246
+ var dateText = "";
247
+ if (hit.ts) {
248
+ var d = new Date(hit.ts);
249
+ var mon = d.getMonth() + 1;
250
+ var day = d.getDate();
251
+ var hr = d.getHours();
252
+ var min = d.getMinutes();
253
+ dateText = mon + "/" + day + " " + (hr < 10 ? "0" : "") + hr + ":" + (min < 10 ? "0" : "") + min;
254
+ }
255
+
256
+ var marker = document.createElement("div");
257
+ marker.className = "rewind-timeline-marker search-hit-marker";
258
+ marker.innerHTML = iconHtml("search") +
259
+ (dateText ? '<span class="marker-date">' + dateText + '</span>' : '') +
260
+ '<span class="marker-text">' + escapeHtml(snippetText) + '</span>';
261
+ marker.style.top = pct + "%";
262
+ marker.dataset.historyIndex = hit.historyIndex;
263
+
264
+ (function(hitData, markerEl) {
265
+ markerEl.addEventListener("click", function() {
266
+ scrollToSearchHit(hitData.historyIndex, hitData.snippet, currentQuery);
267
+ });
268
+ })(hit, marker);
269
+
270
+ track.appendChild(marker);
271
+ }
272
+
273
+ timelineEl.appendChild(track);
274
+
275
+ // Position timeline to align with messages area
276
+ var titleBarEl = document.querySelector(".title-bar-content");
277
+ var inputAreaEl = document.getElementById("input-area");
278
+ var appRect = appEl.getBoundingClientRect();
279
+ var titleBarRect = titleBarEl ? titleBarEl.getBoundingClientRect() : { bottom: appRect.top };
280
+ var inputRect = inputAreaEl.getBoundingClientRect();
281
+
282
+ timelineEl.style.top = (titleBarRect.bottom - appRect.top + 4) + "px";
283
+ timelineEl.style.bottom = (appRect.bottom - inputRect.top + 4) + "px";
284
+
285
+ appEl.appendChild(timelineEl);
286
+ refreshIcons();
287
+
288
+ timelineScrollHandler = function() { updateTimelineViewport(track, viewport); };
289
+ messagesEl.addEventListener("scroll", timelineScrollHandler);
290
+ updateTimelineViewport(track, viewport);
291
+ }
292
+
293
+ function removeTimeline() {
294
+ if (timelineEl) {
295
+ timelineEl.remove();
296
+ timelineEl = null;
297
+ }
298
+ if (timelineScrollHandler && ctx.messagesEl) {
299
+ ctx.messagesEl.removeEventListener("scroll", timelineScrollHandler);
300
+ timelineScrollHandler = null;
301
+ }
302
+ }
303
+
304
+ function updateTimelineViewport(track, viewport) {
305
+ if (!track) return;
306
+ var messagesEl = ctx.messagesEl;
307
+ var scrollH = messagesEl.scrollHeight;
308
+ var viewH = messagesEl.clientHeight;
309
+
310
+ var historyFrom = ctx.getHistoryFrom ? ctx.getHistoryFrom() : 0;
311
+ var total = parseInt(track.dataset.historyTotal || "0", 10) || 1;
312
+ var timelineStart = 6 + (historyFrom / (total - 1 || 1)) * 88;
313
+ var timelineEnd = 94;
314
+ var timelineRange = timelineEnd - timelineStart;
315
+
316
+ if (scrollH <= viewH) {
317
+ viewport.style.top = timelineStart + "%";
318
+ viewport.style.height = timelineRange + "%";
319
+ } else {
320
+ var scrollFrac = messagesEl.scrollTop / scrollH;
321
+ var viewFrac = viewH / scrollH;
322
+ viewport.style.top = (timelineStart + scrollFrac * timelineRange) + "%";
323
+ viewport.style.height = (viewFrac * timelineRange) + "%";
324
+ }
325
+ }
326
+
327
+ function scrollToSearchHit(historyIndex, snippet, query) {
328
+ var historyFrom = ctx.getHistoryFrom ? ctx.getHistoryFrom() : 0;
329
+ if (historyIndex < historyFrom) {
330
+ // Need to load older history first
331
+ pendingScrollTarget = { historyIndex: historyIndex, snippet: snippet, query: query };
332
+ if (ctx.ws && ctx.ws.readyState === 1) {
333
+ ctx.ws.send(JSON.stringify({ type: "load_more_history", before: historyFrom, target: historyIndex }));
334
+ }
335
+ return;
336
+ }
337
+ findAndScrollToMatch(snippet, query);
338
+ }
339
+
340
+ function findAndScrollToMatch(snippet, query) {
341
+ var messagesEl = ctx.messagesEl;
342
+ var q = query.toLowerCase();
343
+ var allMsgs = messagesEl.querySelectorAll(".msg-user, .msg-assistant");
344
+ var cleanSnippet = snippet.replace(/^\u2026/, "").replace(/\u2026$/, "");
345
+
346
+ for (var i = 0; i < allMsgs.length; i++) {
347
+ var msgEl = allMsgs[i];
348
+ var textEl = msgEl.querySelector(".bubble") || msgEl.querySelector(".md-content");
349
+ if (!textEl) continue;
350
+ var text = textEl.textContent || "";
351
+ if (text.indexOf(cleanSnippet) !== -1) {
352
+ msgEl.scrollIntoView({ behavior: "smooth", block: "center" });
353
+ msgEl.classList.remove("search-blink");
354
+ void msgEl.offsetWidth;
355
+ msgEl.classList.add("search-blink");
356
+ return;
357
+ }
358
+ }
359
+ // Fallback: any element containing the query
360
+ for (var j = 0; j < allMsgs.length; j++) {
361
+ var el = allMsgs[j];
362
+ var tEl = el.querySelector(".bubble") || el.querySelector(".md-content");
363
+ if (!tEl) continue;
364
+ if ((tEl.textContent || "").toLowerCase().indexOf(q) !== -1) {
365
+ el.scrollIntoView({ behavior: "smooth", block: "center" });
366
+ el.classList.remove("search-blink");
367
+ void el.offsetWidth;
368
+ el.classList.add("search-blink");
369
+ return;
370
+ }
371
+ }
372
+ }
373
+
374
+ // --- DOM highlighting ---
375
+ function highlightInElement(el, queryLower) {
376
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
377
+ var textNodes = [];
378
+ var node;
379
+ while ((node = walker.nextNode())) {
380
+ textNodes.push(node);
381
+ }
382
+
383
+ for (var i = 0; i < textNodes.length; i++) {
384
+ var textNode = textNodes[i];
385
+ var parent = textNode.parentNode;
386
+ if (!parent || parent.classList && parent.classList.contains(highlightClass)) continue;
387
+ if (parent.tagName === "BUTTON" || parent.tagName === "SCRIPT" || parent.tagName === "STYLE") continue;
388
+
389
+ var text = textNode.nodeValue;
390
+ var textLower = text.toLowerCase();
391
+ var idx = textLower.indexOf(queryLower);
392
+ if (idx === -1) continue;
393
+
394
+ var frag = document.createDocumentFragment();
395
+ var lastIdx = 0;
396
+
397
+ while (idx !== -1) {
398
+ if (idx > lastIdx) {
399
+ frag.appendChild(document.createTextNode(text.substring(lastIdx, idx)));
400
+ }
401
+ var mark = document.createElement("mark");
402
+ mark.className = highlightClass;
403
+ mark.textContent = text.substring(idx, idx + currentQuery.length);
404
+ frag.appendChild(mark);
405
+ lastIdx = idx + currentQuery.length;
406
+ idx = textLower.indexOf(queryLower, lastIdx);
407
+ }
408
+
409
+ if (lastIdx < text.length) {
410
+ frag.appendChild(document.createTextNode(text.substring(lastIdx)));
411
+ }
412
+
413
+ parent.replaceChild(frag, textNode);
414
+ }
415
+ }
416
+
417
+ function clearHighlights() {
418
+ var messagesEl = ctx.messagesEl;
419
+ var marks = messagesEl.querySelectorAll("mark." + highlightClass);
420
+ for (var i = 0; i < marks.length; i++) {
421
+ var mark = marks[i];
422
+ var parent = mark.parentNode;
423
+ parent.replaceChild(document.createTextNode(mark.textContent), mark);
424
+ parent.normalize();
425
+ }
426
+ matches = [];
427
+ currentMatchIndex = -1;
428
+ }
429
+
430
+ function setActiveMatch(index) {
431
+ var prev = ctx.messagesEl.querySelector("." + activeHighlightClass);
432
+ if (prev) prev.classList.remove(activeHighlightClass);
433
+
434
+ if (index >= 0 && index < matches.length) {
435
+ matches[index].classList.add(activeHighlightClass);
436
+ matches[index].scrollIntoView({ behavior: "smooth", block: "center" });
437
+ }
438
+ }
439
+
440
+ function goToNextMatch() {
441
+ if (matches.length === 0) return;
442
+ currentMatchIndex = (currentMatchIndex + 1) % matches.length;
443
+ setActiveMatch(currentMatchIndex);
444
+ matchCountEl.textContent = (currentMatchIndex + 1) + " / " + matches.length +
445
+ (serverHits.length > matches.length ? " (" + serverHits.length + " total)" : "");
446
+ }
447
+
448
+ function goToPrevMatch() {
449
+ if (matches.length === 0) return;
450
+ currentMatchIndex = (currentMatchIndex - 1 + matches.length) % matches.length;
451
+ setActiveMatch(currentMatchIndex);
452
+ matchCountEl.textContent = (currentMatchIndex + 1) + " / " + matches.length +
453
+ (serverHits.length > matches.length ? " (" + serverHits.length + " total)" : "");
454
+ }
455
+
456
+ export { initSessionSearch, openSearch, closeSearch, toggleSearch, isSearchOpen, handleFindInSessionResults, onHistoryPrepended };