@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,429 @@
1
+ // agent-picker.js — searchable picker for the SDK `agent` option (lr-7db0).
2
+ //
3
+ // Modeled on command-palette.js so the visual idiom is identical: backdrop +
4
+ // dialog + search input + grouped results + keyboard nav. Reuses the
5
+ // .cmd-palette-* CSS classes so we don't fork the styling; agent-specific
6
+ // affordances (star toggle, source badge) are layered on with .agent-*
7
+ // classes in agent-picker.css.
8
+ //
9
+ // Two tabs: Favorites (default) and All agents. Star toggle on each row
10
+ // flips chattable.json membership. Recents pinned above Favorites when not
11
+ // searching. Hidden caller-side (sidebar-sessions) when current project is
12
+ // a Mate; server also enforces.
13
+
14
+ import { escapeHtml } from './utils.js';
15
+ import { iconHtml, refreshIcons } from './icons.js';
16
+ import { store } from './store.js';
17
+ import { getWs } from './ws-ref.js';
18
+
19
+ var paletteEl = null;
20
+ var inputEl = null;
21
+ var resultsEl = null;
22
+ var tabsEl = null;
23
+ var activeIndex = -1;
24
+ var items = [];
25
+
26
+ // When set, activateItem() saves as preferred agent instead of starting a session.
27
+ var _preferredTargetSlug = null;
28
+
29
+ var allAgents = [];
30
+ var favorites = [];
31
+ var recents = [];
32
+ var activeTab = "favorites"; // "favorites" | "all"
33
+
34
+ // Agent-identity match. pluginName only meaningful for kind="plugin".
35
+ function sameAgent(a, b) {
36
+ if (!a || !b) return false;
37
+ if (a.name !== b.name) return false;
38
+ if (a.kind !== b.kind) return false;
39
+ if (a.kind === "plugin" && (a.pluginName || null) !== (b.pluginName || null)) return false;
40
+ return true;
41
+ }
42
+
43
+ function isFavorite(agent) {
44
+ for (var i = 0; i < favorites.length; i++) {
45
+ if (sameAgent(favorites[i], agent)) return true;
46
+ }
47
+ return false;
48
+ }
49
+
50
+ export function initAgentPicker() {
51
+ buildDOM();
52
+ }
53
+
54
+ export function isAgentPickerOpen() {
55
+ return paletteEl && !paletteEl.classList.contains("hidden");
56
+ }
57
+
58
+ export function openAgentPicker() {
59
+ if (!paletteEl) return;
60
+ // Refuse to open inside Mate DM mode (server also enforces; this just keeps
61
+ // the surface from flickering open).
62
+ if (store.get('dmMode')) return;
63
+ _preferredTargetSlug = null;
64
+ paletteEl.classList.remove("hidden");
65
+ inputEl.value = "";
66
+ activeIndex = -1;
67
+ items = [];
68
+ activeTab = "favorites";
69
+ resultsEl.innerHTML = '<div class="cmd-palette-loading">Loading agents…</div>';
70
+ inputEl.focus();
71
+ // Request fresh catalog every open — agents come and go as plugins
72
+ // install/uninstall, and discovery is cheap.
73
+ var ws = getWs();
74
+ if (ws && ws.readyState === 1) {
75
+ ws.send(JSON.stringify({ type: "list_agents" }));
76
+ }
77
+ }
78
+
79
+ // Open the picker in "set preferred agent" mode for the given project slug.
80
+ // On selection the agent is saved as that project's preferredAgent; no session
81
+ // is started.
82
+ export function openAgentPickerForPreferred(slug) {
83
+ if (!paletteEl || !slug) return;
84
+ _preferredTargetSlug = slug;
85
+ paletteEl.classList.remove("hidden");
86
+ inputEl.value = "";
87
+ activeIndex = -1;
88
+ items = [];
89
+ activeTab = "all";
90
+ syncTabUi();
91
+ resultsEl.innerHTML = '<div class="cmd-palette-loading">Loading agents…</div>';
92
+ // Update footer hint
93
+ var footerEl = paletteEl.querySelector(".cmd-palette-footer-shortcuts");
94
+ if (footerEl) {
95
+ footerEl.innerHTML =
96
+ '<span><kbd>&uarr;</kbd> <kbd>&darr;</kbd> navigate</span>' +
97
+ '<span><kbd>Enter</kbd> set as preferred</span>' +
98
+ '<span><kbd>Esc</kbd> cancel</span>';
99
+ }
100
+ inputEl.focus();
101
+ var ws = getWs();
102
+ if (ws && ws.readyState === 1) {
103
+ ws.send(JSON.stringify({ type: "list_agents" }));
104
+ }
105
+ }
106
+
107
+ export function closeAgentPicker() {
108
+ if (!paletteEl) return;
109
+ paletteEl.classList.add("hidden");
110
+ inputEl.value = "";
111
+ resultsEl.innerHTML = "";
112
+ items = [];
113
+ activeIndex = -1;
114
+ _preferredTargetSlug = null;
115
+ // Restore default footer
116
+ var footerEl = paletteEl.querySelector(".cmd-palette-footer-shortcuts");
117
+ if (footerEl) {
118
+ footerEl.innerHTML =
119
+ '<span><kbd>&uarr;</kbd> <kbd>&darr;</kbd> navigate</span>' +
120
+ '<span><kbd>Enter</kbd> start chat</span>' +
121
+ '<span><kbd>&#9733;</kbd> toggle favorite</span>';
122
+ }
123
+ }
124
+
125
+ // Server pushed an updated catalog — render if we're open.
126
+ export function handleAgentsList(msg) {
127
+ allAgents = Array.isArray(msg.agents) ? msg.agents : [];
128
+ favorites = Array.isArray(msg.favorites) ? msg.favorites : [];
129
+ recents = Array.isArray(msg.recents) ? msg.recents : [];
130
+ if (isAgentPickerOpen()) {
131
+ render();
132
+ }
133
+ }
134
+
135
+ // Server confirmed a favorite toggle — no-op visually because agents_list
136
+ // follows immediately and re-renders.
137
+ export function handleAgentFavoriteToggled(_msg) { /* re-render comes via agents_list */ }
138
+
139
+ function buildDOM() {
140
+ paletteEl = document.createElement("div");
141
+ paletteEl.className = "cmd-palette agent-picker hidden";
142
+ paletteEl.innerHTML =
143
+ '<div class="cmd-palette-backdrop"></div>' +
144
+ '<div class="cmd-palette-dialog">' +
145
+ '<div class="cmd-palette-input-row">' +
146
+ '<i data-lucide="bot"></i>' +
147
+ '<input class="cmd-palette-input" type="text" placeholder="Search agents…" autocomplete="off" spellcheck="false" />' +
148
+ '<span class="cmd-palette-kbd agent-picker-close"><i data-lucide="x"></i></span>' +
149
+ '</div>' +
150
+ '<div class="agent-picker-tabs">' +
151
+ '<button class="agent-picker-tab active" data-tab="favorites" type="button">Favorites</button>' +
152
+ '<button class="agent-picker-tab" data-tab="all" type="button">All agents</button>' +
153
+ '</div>' +
154
+ '<div class="cmd-palette-results"></div>' +
155
+ '<div class="cmd-palette-footer">' +
156
+ '<span class="cmd-palette-footer-shortcuts">' +
157
+ '<span><kbd>&uarr;</kbd> <kbd>&darr;</kbd> navigate</span>' +
158
+ '<span><kbd>Enter</kbd> start chat</span>' +
159
+ '<span><kbd>★</kbd> toggle favorite</span>' +
160
+ '</span>' +
161
+ '</div>' +
162
+ '</div>';
163
+
164
+ document.body.appendChild(paletteEl);
165
+ refreshIcons();
166
+
167
+ inputEl = paletteEl.querySelector(".cmd-palette-input");
168
+ resultsEl = paletteEl.querySelector(".cmd-palette-results");
169
+ tabsEl = paletteEl.querySelector(".agent-picker-tabs");
170
+
171
+ paletteEl.querySelector(".cmd-palette-backdrop").addEventListener("click", closeAgentPicker);
172
+ paletteEl.querySelector(".agent-picker-close").addEventListener("click", closeAgentPicker);
173
+
174
+ inputEl.addEventListener("input", render);
175
+
176
+ inputEl.addEventListener("keydown", function (e) {
177
+ if (e.key === "Escape") {
178
+ e.preventDefault();
179
+ closeAgentPicker();
180
+ return;
181
+ }
182
+ if (e.key === "ArrowDown") {
183
+ e.preventDefault();
184
+ setActive(activeIndex + 1);
185
+ return;
186
+ }
187
+ if (e.key === "ArrowUp") {
188
+ e.preventDefault();
189
+ setActive(activeIndex - 1);
190
+ return;
191
+ }
192
+ if (e.key === "Enter") {
193
+ e.preventDefault();
194
+ if (activeIndex >= 0 && activeIndex < items.length) activateItem(items[activeIndex]);
195
+ return;
196
+ }
197
+ if (e.key === "Tab") {
198
+ // Tab swaps tabs without leaving the input.
199
+ e.preventDefault();
200
+ activeTab = activeTab === "favorites" ? "all" : "favorites";
201
+ syncTabUi();
202
+ render();
203
+ return;
204
+ }
205
+ });
206
+
207
+ // Tab clicks
208
+ var tabButtons = tabsEl.querySelectorAll(".agent-picker-tab");
209
+ for (var ti = 0; ti < tabButtons.length; ti++) {
210
+ (function (btn) {
211
+ btn.addEventListener("click", function () {
212
+ activeTab = btn.getAttribute("data-tab");
213
+ syncTabUi();
214
+ render();
215
+ inputEl.focus();
216
+ });
217
+ })(tabButtons[ti]);
218
+ }
219
+
220
+ paletteEl.querySelector(".cmd-palette-dialog").addEventListener("click", function (e) {
221
+ e.stopPropagation();
222
+ });
223
+ }
224
+
225
+ function syncTabUi() {
226
+ var btns = tabsEl.querySelectorAll(".agent-picker-tab");
227
+ for (var i = 0; i < btns.length; i++) {
228
+ btns[i].classList.toggle("active", btns[i].getAttribute("data-tab") === activeTab);
229
+ }
230
+ }
231
+
232
+ function render() {
233
+ var f = (inputEl.value || "").toLowerCase().trim();
234
+ items = [];
235
+ var html = "";
236
+ var flatIndex = 0;
237
+
238
+ function matches(a) {
239
+ if (!f) return true;
240
+ return (a.name || "").toLowerCase().indexOf(f) !== -1
241
+ || (a.description || "").toLowerCase().indexOf(f) !== -1
242
+ || (a.pluginName || "").toLowerCase().indexOf(f) !== -1;
243
+ }
244
+
245
+ // Resolve recents/favorites against the catalog so we always render fresh
246
+ // metadata (description/model) rather than the stale snapshot the server
247
+ // stored in chattable.json.
248
+ function resolve(stub) {
249
+ for (var i = 0; i < allAgents.length; i++) {
250
+ if (sameAgent(allAgents[i], stub)) return allAgents[i];
251
+ }
252
+ return null;
253
+ }
254
+
255
+ if (activeTab === "favorites") {
256
+ // Recents (pinned, only when not searching).
257
+ if (!f) {
258
+ var recentResolved = recents.map(resolve).filter(Boolean);
259
+ if (recentResolved.length > 0) {
260
+ html += '<div class="cmd-palette-group-label">Recents</div>';
261
+ for (var ri = 0; ri < recentResolved.length; ri++) {
262
+ var ra = recentResolved[ri];
263
+ items.push({ type: "agent", data: ra });
264
+ html += renderRow(flatIndex, ra);
265
+ flatIndex++;
266
+ }
267
+ }
268
+ }
269
+
270
+ var favResolved = favorites.map(resolve).filter(Boolean).filter(matches);
271
+ if (favResolved.length > 0) {
272
+ html += '<div class="cmd-palette-group-label">Favorites</div>';
273
+ for (var fi = 0; fi < favResolved.length; fi++) {
274
+ var fa = favResolved[fi];
275
+ items.push({ type: "agent", data: fa });
276
+ html += renderRow(flatIndex, fa);
277
+ flatIndex++;
278
+ }
279
+ } else if (!f && favorites.length === 0) {
280
+ html += '<div class="agent-picker-empty">' +
281
+ 'No favorites yet. Switch to <strong>All agents</strong> and star the ones you want here.' +
282
+ '</div>';
283
+ }
284
+ } else {
285
+ // All agents — group by source.
286
+ var groups = { user: [], plugin: [], project: [] };
287
+ for (var ai = 0; ai < allAgents.length; ai++) {
288
+ var ag = allAgents[ai];
289
+ if (!matches(ag)) continue;
290
+ var bucket = ag.kind === "plugin" ? "plugin" : (ag.kind === "project" ? "project" : "user");
291
+ groups[bucket].push(ag);
292
+ }
293
+ var groupOrder = [
294
+ { key: "user", label: "User" },
295
+ { key: "project", label: "Project" },
296
+ { key: "plugin", label: "Plugins" },
297
+ ];
298
+ for (var gi = 0; gi < groupOrder.length; gi++) {
299
+ var g = groupOrder[gi];
300
+ if (groups[g.key].length === 0) continue;
301
+ html += '<div class="cmd-palette-group-label">' + g.label + '</div>';
302
+ for (var ii = 0; ii < groups[g.key].length; ii++) {
303
+ var aa = groups[g.key][ii];
304
+ items.push({ type: "agent", data: aa });
305
+ html += renderRow(flatIndex, aa);
306
+ flatIndex++;
307
+ }
308
+ }
309
+ }
310
+
311
+ if (items.length === 0 && !html) {
312
+ html = '<div class="agent-picker-empty">' +
313
+ (f ? 'No agents match "' + escapeHtml(f) + '".' : 'No agents discovered.') +
314
+ '</div>';
315
+ }
316
+
317
+ resultsEl.innerHTML = html;
318
+ refreshIcons();
319
+ bindItemEvents();
320
+ if (items.length > 0) setActive(0, true);
321
+ }
322
+
323
+ function renderRow(index, agent) {
324
+ var fav = isFavorite(agent);
325
+ var sourceLabel = agent.kind === "plugin"
326
+ ? (agent.pluginName ? "plugin · " + escapeHtml(agent.pluginName) : "plugin")
327
+ : (agent.kind === "project" ? "project" : "user");
328
+ var modelChip = agent.model
329
+ ? '<span class="agent-picker-model">' + escapeHtml(agent.model) + '</span>'
330
+ : '';
331
+ var description = agent.description ? escapeHtml(agent.description) : '';
332
+ var starIcon = fav ? "star" : "star-off";
333
+ var starClass = fav ? "agent-picker-star is-favorite" : "agent-picker-star";
334
+ return '<div class="cmd-palette-item agent-picker-item" data-index="' + index + '">' +
335
+ '<div class="cmd-palette-item-icon"><i data-lucide="bot"></i></div>' +
336
+ '<div class="cmd-palette-item-body">' +
337
+ '<div class="cmd-palette-item-title-row">' +
338
+ '<span class="cmd-palette-item-title">' + escapeHtml(agent.name) + '</span>' +
339
+ modelChip +
340
+ '<span class="agent-picker-source">' + sourceLabel + '</span>' +
341
+ '</div>' +
342
+ (description ? '<div class="cmd-palette-item-meta"><span class="cmd-palette-item-project">' + description + '</span></div>' : '') +
343
+ '</div>' +
344
+ '<button class="' + starClass + '" data-fav-index="' + index + '" type="button" title="Toggle favorite">' +
345
+ '<i data-lucide="' + starIcon + '"></i>' +
346
+ '</button>' +
347
+ '</div>';
348
+ }
349
+
350
+ function bindItemEvents() {
351
+ var itemEls = resultsEl.querySelectorAll(".agent-picker-item");
352
+ for (var k = 0; k < itemEls.length; k++) {
353
+ (function (el) {
354
+ el.addEventListener("click", function (e) {
355
+ if (e.target.closest(".agent-picker-star")) return; // star handler runs separately
356
+ var idx = parseInt(el.getAttribute("data-index"), 10);
357
+ if (idx >= 0 && idx < items.length) activateItem(items[idx]);
358
+ });
359
+ el.addEventListener("mouseenter", function () {
360
+ var idx = parseInt(el.getAttribute("data-index"), 10);
361
+ setActive(idx, true);
362
+ });
363
+ })(itemEls[k]);
364
+ }
365
+ var starEls = resultsEl.querySelectorAll(".agent-picker-star");
366
+ for (var s = 0; s < starEls.length; s++) {
367
+ (function (el) {
368
+ el.addEventListener("click", function (e) {
369
+ e.stopPropagation();
370
+ var idx = parseInt(el.getAttribute("data-fav-index"), 10);
371
+ if (idx >= 0 && idx < items.length) {
372
+ var it = items[idx];
373
+ if (it && it.type === "agent") toggleFavorite(it.data);
374
+ }
375
+ });
376
+ })(starEls[s]);
377
+ }
378
+ }
379
+
380
+ function setActive(idx, skipScroll) {
381
+ if (items.length === 0) return;
382
+ if (idx < 0) idx = items.length - 1;
383
+ if (idx >= items.length) idx = 0;
384
+ activeIndex = idx;
385
+ var els = resultsEl.querySelectorAll(".agent-picker-item");
386
+ for (var i = 0; i < els.length; i++) {
387
+ els[i].classList.toggle("active", i === idx);
388
+ }
389
+ if (!skipScroll && els[idx]) {
390
+ els[idx].scrollIntoView({ block: "nearest" });
391
+ }
392
+ }
393
+
394
+ function activateItem(entry) {
395
+ if (!entry || entry.type !== "agent") return;
396
+ var ws = getWs();
397
+ if (!ws || ws.readyState !== 1) return;
398
+ if (_preferredTargetSlug) {
399
+ // "Set preferred agent" mode — persist the choice, no new session.
400
+ ws.send(JSON.stringify({
401
+ type: "set_project_preferred_agent",
402
+ slug: _preferredTargetSlug,
403
+ agent: {
404
+ name: entry.data.name,
405
+ kind: entry.data.kind,
406
+ pluginName: entry.data.pluginName || null,
407
+ },
408
+ }));
409
+ } else {
410
+ ws.send(JSON.stringify({
411
+ type: "new_session",
412
+ agentName: entry.data.name,
413
+ agentKind: entry.data.kind,
414
+ agentPluginName: entry.data.pluginName || null,
415
+ }));
416
+ }
417
+ closeAgentPicker();
418
+ }
419
+
420
+ function toggleFavorite(agent) {
421
+ var ws = getWs();
422
+ if (!ws || ws.readyState !== 1) return;
423
+ ws.send(JSON.stringify({
424
+ type: "toggle_agent_favorite",
425
+ name: agent.name,
426
+ kind: agent.kind,
427
+ pluginName: agent.pluginName || null,
428
+ }));
429
+ }
@@ -0,0 +1,216 @@
1
+ // app-connection.js - WebSocket connection, reconnect, status
2
+ // Extracted from app.js (PR-22)
3
+
4
+ import { store } from './store.js';
5
+ import { getWs, setWs } from './ws-ref.js';
6
+ import { getStatusDot, getSendBtn } from './dom-refs.js';
7
+ import { setSendBtnMode, blinkIO, setActivity } from './app-favicon.js';
8
+ import { startLogoAnimation, stopLogoAnimation } from './console-logo.js';
9
+ import { hasSendableContent } from './input.js';
10
+ import { processMessage } from './app-messages.js';
11
+ import { flushPendingExtMessages } from './app-misc.js';
12
+ import { resetTerminals } from './terminal.js';
13
+ import { closeDmUserPicker } from './sidebar-users.js';
14
+ import { openDm } from './app-dm.js';
15
+
16
+ var reconnectTimer = null;
17
+ var reconnectDelay = 100;
18
+ var connectTimeoutId = null;
19
+ var connectOverlay = null;
20
+ var overlayGraceTimer = null;
21
+
22
+ // Message types that warrant a visible IO blink. Everything else is
23
+ // background infrastructure traffic (presence, rate-limit accounting,
24
+ // cursor relay, session list updates, input echo) that does not need
25
+ // to trigger the querySelector-heavy blinkIO() path on the main thread.
26
+ var _blinkTypes = {
27
+ delta: true,
28
+ thinking_delta: true,
29
+ message: true,
30
+ stop: true,
31
+ tool_start: true,
32
+ tool_result: true,
33
+ tool_progress: true,
34
+ permission_request: true,
35
+ elicitation_request: true,
36
+ ask_user_question: true,
37
+ subagent_activity: true,
38
+ thinking_start: true,
39
+ thinking_done: true,
40
+ done: true,
41
+ error: true,
42
+ rate_limit: true,
43
+ };
44
+
45
+ export function initConnection() {
46
+ connectOverlay = document.getElementById("connect-overlay");
47
+
48
+ // --- Reactive UI sync for connected/processing state ---
49
+ store.subscribe(function (state, prev) {
50
+ // Status dot (depends on both connected and processing)
51
+ if (state.connected !== prev.connected || state.processing !== prev.processing) {
52
+ var dot = getStatusDot();
53
+ if (dot) {
54
+ dot.className = "icon-strip-status";
55
+ if (state.connected) {
56
+ dot.classList.add("connected");
57
+ if (state.processing) dot.classList.add("processing");
58
+ }
59
+ }
60
+ }
61
+
62
+ // Connected state changed
63
+ if (state.connected !== prev.connected) {
64
+ var sendBtn = getSendBtn();
65
+ if (state.connected) {
66
+ // Cancel any pending grace timer — reconnected before overlay was needed
67
+ if (overlayGraceTimer) { clearTimeout(overlayGraceTimer); overlayGraceTimer = null; }
68
+ if (sendBtn) sendBtn.disabled = false;
69
+ if (connectOverlay) connectOverlay.classList.add("hidden");
70
+ var updPill = document.getElementById("update-pill-wrap");
71
+ if (updPill) updPill.classList.add("hidden");
72
+ stopLogoAnimation();
73
+ } else {
74
+ if (sendBtn) sendBtn.disabled = true;
75
+ // Delay showing the overlay by 600ms — absorbs brief AP switches and
76
+ // sub-second network hiccups without flashing the full-screen animation.
77
+ if (overlayGraceTimer) clearTimeout(overlayGraceTimer);
78
+ overlayGraceTimer = setTimeout(function () {
79
+ overlayGraceTimer = null;
80
+ if (!store.get('connected')) {
81
+ if (connectOverlay) connectOverlay.classList.remove("hidden");
82
+ startLogoAnimation();
83
+ }
84
+ }, 600);
85
+ }
86
+ }
87
+
88
+ // Processing state changed
89
+ if (state.processing !== prev.processing) {
90
+ if (state.processing) {
91
+ setSendBtnMode(hasSendableContent() ? "send" : "stop");
92
+ } else if (state.connected) {
93
+ setSendBtnMode("send");
94
+ }
95
+ }
96
+ });
97
+ }
98
+
99
+ // setStatus: now just sets state. UI sync is handled by the subscriber above.
100
+ export function setStatus(status) {
101
+ if (status === "connected") {
102
+ store.set({ connected: true, processing: false });
103
+ } else if (status === "processing") {
104
+ store.set({ processing: true });
105
+ } else {
106
+ store.set({ connected: false, processing: false });
107
+ }
108
+ }
109
+
110
+ function onConnected() {
111
+ // Flush any extension messages that arrived before WS was ready
112
+ flushPendingExtMessages();
113
+
114
+ // Reset terminal xterm instances (server will send fresh term_list)
115
+ resetTerminals();
116
+
117
+ // Re-send push subscription on reconnect
118
+ var ws = getWs();
119
+ if (window._pushSubscription) {
120
+ try {
121
+ ws.send(JSON.stringify({
122
+ type: "push_subscribe",
123
+ subscription: window._pushSubscription.toJSON(),
124
+ }));
125
+ } catch(e) {}
126
+ }
127
+
128
+ // Session restore is now server-driven (user-presence.json).
129
+ try { localStorage.removeItem("clagentic-active-dm"); localStorage.removeItem("clay-active-dm"); } catch (e) {}
130
+ }
131
+
132
+ export function connect() {
133
+ var ws = getWs();
134
+ if (ws) { ws.onclose = null; ws.close(); }
135
+ if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
136
+
137
+ var protocol = location.protocol === "https:" ? "wss:" : "ws:";
138
+ var newWs = new WebSocket(protocol + "//" + location.host + store.get('wsPath'));
139
+ setWs(newWs);
140
+
141
+ // If not connected within 3s, force retry
142
+ connectTimeoutId = setTimeout(function () {
143
+ if (!store.get('connected')) {
144
+ newWs.onclose = null;
145
+ newWs.onerror = null;
146
+ newWs.close();
147
+ connect();
148
+ }
149
+ }, 3000);
150
+
151
+ newWs.onopen = function () {
152
+ if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
153
+ setStatus("connected");
154
+ reconnectDelay = 100;
155
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
156
+
157
+ // Wrap ws.send to blink LED on outgoing traffic
158
+ var currentWs = getWs();
159
+ var _origSend = currentWs.send.bind(currentWs);
160
+ currentWs._sendRaw = _origSend;
161
+ currentWs.send = function (data) {
162
+ blinkIO();
163
+ return _origSend(data);
164
+ };
165
+
166
+ onConnected();
167
+ };
168
+
169
+ newWs.onclose = function (e) {
170
+ if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
171
+ closeDmUserPicker();
172
+ setStatus("disconnected");
173
+ setActivity(null);
174
+ scheduleReconnect();
175
+ };
176
+
177
+ newWs.onerror = function () {};
178
+
179
+ newWs.onmessage = function (event) {
180
+ // Backup: if we're receiving messages, we're connected
181
+ if (!store.get('connected')) {
182
+ setStatus("connected");
183
+ reconnectDelay = 100;
184
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
185
+ }
186
+
187
+ var msg;
188
+ try { msg = JSON.parse(event.data); } catch (e) { return; }
189
+ // Only blink the IO indicator for user-visible activity. Background
190
+ // infrastructure messages (rate_limit_usage, session_list, input_sync_broadcast,
191
+ // cursor_move, text_select, session_presence, session_io, etc.) are excluded
192
+ // so the querySelector storm inside blinkIO() doesn't fire on every
193
+ // server heartbeat or collab event during typing.
194
+ if (_blinkTypes[msg.type]) blinkIO();
195
+ processMessage(msg);
196
+ };
197
+ }
198
+
199
+ export function cancelReconnect() {
200
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
201
+ }
202
+
203
+ export function scheduleReconnect() {
204
+ if (reconnectTimer) return;
205
+ reconnectTimer = setTimeout(function () {
206
+ reconnectTimer = null;
207
+ // Attempt reconnect immediately — don't block on /info preflight.
208
+ // Check auth in parallel: if the server returns 401 while we're trying to
209
+ // connect, the WS handshake will fail anyway and we reload then.
210
+ fetch("/info").then(function (res) {
211
+ if (res.status === 401) { location.reload(); }
212
+ }).catch(function () {});
213
+ connect();
214
+ }, reconnectDelay);
215
+ reconnectDelay = Math.min(reconnectDelay * 1.5, 10000);
216
+ }