@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,613 @@
1
+ import { copyToClipboard, showToast } from './utils.js';
2
+ import { iconHtml, refreshIcons } from './icons.js';
3
+
4
+ var ctx;
5
+ var basePath = "/";
6
+ var onboardingPill, onboardingText, onboardingClose, onboardingDismissed;
7
+ var notifAlertEnabled, notifSoundEnabled, notifPermission;
8
+ var audioCtx = null;
9
+
10
+ export function isNotifAlertEnabled() { return notifAlertEnabled; }
11
+ export function isNotifSoundEnabled() { return notifSoundEnabled; }
12
+ export function getNotifPermission() { return notifPermission; }
13
+
14
+ export function showOnboarding(html) {
15
+ onboardingText.innerHTML = html;
16
+ onboardingPill.classList.remove("hidden");
17
+ refreshIcons();
18
+ }
19
+
20
+ export function hideOnboarding() {
21
+ onboardingPill.classList.add("hidden");
22
+ }
23
+
24
+ export function playDoneSound() {
25
+ try {
26
+ if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
27
+ if (audioCtx.state === "suspended") audioCtx.resume();
28
+ var osc = audioCtx.createOscillator();
29
+ var gain = audioCtx.createGain();
30
+ osc.type = "sine";
31
+ osc.frequency.value = 880;
32
+ gain.gain.value = 0.1;
33
+ osc.connect(gain);
34
+ gain.connect(audioCtx.destination);
35
+ osc.start();
36
+ gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 0.3);
37
+ osc.stop(audioCtx.currentTime + 0.3);
38
+ } catch(e) {}
39
+ }
40
+
41
+ export function showDoneNotification() {
42
+ var lastAssistant = ctx.messagesEl.querySelector(".msg-assistant:last-of-type .md-content");
43
+ var preview = lastAssistant ? lastAssistant.textContent.substring(0, 100) : "Response ready";
44
+
45
+ var sessionTitle = "Claude";
46
+ var activeItem = ctx.sessionListEl.querySelector(".session-item.active");
47
+ if (activeItem) {
48
+ var textEl = activeItem.querySelector(".session-item-text");
49
+ if (textEl) sessionTitle = textEl.textContent || "Claude";
50
+ else sessionTitle = activeItem.textContent || "Claude";
51
+ }
52
+
53
+ var n = new Notification(sessionTitle, {
54
+ body: preview,
55
+ tag: "claude-done",
56
+ });
57
+
58
+ n.onclick = function() {
59
+ window.focus();
60
+ n.close();
61
+ };
62
+
63
+ setTimeout(function() { n.close(); }, 5000);
64
+ }
65
+
66
+ export function initNotifications(_ctx) {
67
+ ctx = _ctx;
68
+ basePath = ctx.basePath || "/";
69
+ var $ = ctx.$;
70
+
71
+ // --- Mobile viewport (iOS keyboard handling) ---
72
+ if (window.visualViewport) {
73
+ var layout = $("layout");
74
+ var mobileTabBar = document.getElementById("mobile-tab-bar");
75
+ // Capture initial viewport height before any keyboard interaction.
76
+ // In iOS PWA standalone mode, window.innerHeight shrinks when the
77
+ // keyboard opens, so we need a stable baseline for comparison.
78
+ var stableViewportHeight = window.innerHeight;
79
+ function onViewportChange() {
80
+ var vv = window.visualViewport;
81
+ // Shrink layout to visual viewport height so input area sits above keyboard
82
+ layout.style.height = vv.height + "px";
83
+ // Compensate for any vertical offset (iOS can shift the visual viewport)
84
+ layout.style.top = vv.offsetTop + "px";
85
+ document.documentElement.scrollTop = 0;
86
+ // Toggle class so CSS can remove the tab-bar bottom padding while keyboard is up
87
+ var keyboardOpen = vv.height < stableViewportHeight - 100;
88
+ document.body.classList.toggle("keyboard-open", keyboardOpen);
89
+ if (!keyboardOpen) ctx.scrollToBottom();
90
+ // Hide tab bar when software keyboard is open
91
+ if (mobileTabBar) {
92
+ if (keyboardOpen) {
93
+ mobileTabBar.classList.add("keyboard-hidden");
94
+ } else {
95
+ mobileTabBar.classList.remove("keyboard-hidden");
96
+ }
97
+ }
98
+ }
99
+ window.visualViewport.addEventListener("resize", onViewportChange);
100
+ window.visualViewport.addEventListener("scroll", onViewportChange);
101
+ }
102
+
103
+ // --- Update pill badge ---
104
+ (function () {
105
+ var pillWrap = $("update-pill-wrap");
106
+ var pillBtn = $("update-pill");
107
+ var popover = $("update-popover");
108
+ var updateNowBtn = $("update-now");
109
+ if (!pillWrap) return;
110
+
111
+ var copyBtn = popover.querySelector(".popover-copy");
112
+ if (copyBtn) {
113
+ copyBtn.addEventListener("click", function (e) {
114
+ e.stopPropagation();
115
+ var cmdEl = document.getElementById("update-manual-cmd");
116
+ var cmdText = cmdEl ? cmdEl.textContent : "npx clay-server@latest";
117
+ copyToClipboard(cmdText).then(function () {
118
+ copyBtn.classList.add("copied");
119
+ copyBtn.innerHTML = iconHtml("check");
120
+ refreshIcons();
121
+ setTimeout(function () {
122
+ copyBtn.classList.remove("copied");
123
+ copyBtn.innerHTML = iconHtml("copy");
124
+ refreshIcons();
125
+ }, 1500);
126
+ });
127
+ });
128
+ }
129
+
130
+ // "Update now" button — trigger server-side update + restart
131
+ if (updateNowBtn) {
132
+ updateNowBtn.addEventListener("click", function (e) {
133
+ e.stopPropagation();
134
+ if (ctx.ws && ctx.connected) {
135
+ ctx.ws.send(JSON.stringify({ type: "update_now" }));
136
+ var textNode = updateNowBtn.lastChild;
137
+ if (textNode) textNode.textContent = " Updating...";
138
+ updateNowBtn.disabled = true;
139
+ }
140
+ });
141
+ }
142
+
143
+ // Toggle popover on pill click
144
+ if (pillBtn) {
145
+ pillBtn.addEventListener("click", function (e) {
146
+ e.stopPropagation();
147
+ popover.classList.toggle("visible");
148
+ });
149
+ }
150
+
151
+ document.addEventListener("click", function (e) {
152
+ if (!popover.contains(e.target) && e.target !== pillBtn && !pillBtn.contains(e.target)) {
153
+ popover.classList.remove("visible");
154
+ }
155
+ });
156
+ })();
157
+
158
+ // --- Extension pill popover ---
159
+ (function () {
160
+ var extPillWrap = $("ext-pill-wrap");
161
+ var extPillBtn = $("ext-pill");
162
+ var extPopover = $("ext-popover");
163
+ var extDownloadBtn = $("ext-download-btn");
164
+ var extDownloadStatus = $("ext-download-status");
165
+ var extCopyUrl = $("ext-copy-url");
166
+ if (!extPillWrap || !extPillBtn || !extPopover) return;
167
+
168
+ // Detect extension connection via postMessage from content.js
169
+ var extConnected = false;
170
+ var connectedBanner = $("ext-connected-banner");
171
+ var extDesc = $("ext-popover-desc");
172
+ var extDivider = $("ext-popover-divider");
173
+ var extGuideTitle = $("ext-popover-guide-title");
174
+ var extSteps = extPopover.querySelector(".ext-popover-steps");
175
+
176
+ function setExtConnected() {
177
+ if (extConnected) return;
178
+ extConnected = true;
179
+ extPillBtn.classList.add("ext-connected");
180
+ extPillBtn.innerHTML = '<i data-lucide="check"></i> Extension';
181
+ refreshIcons(extPillBtn);
182
+ if (connectedBanner) connectedBanner.classList.remove("hidden");
183
+ if (extDownloadBtn) extDownloadBtn.style.display = "none";
184
+ if (extDownloadStatus) extDownloadStatus.classList.add("hidden");
185
+ if (extDesc) extDesc.style.display = "none";
186
+ if (extDivider) extDivider.style.display = "none";
187
+ if (extGuideTitle) extGuideTitle.style.display = "none";
188
+ if (extSteps) extSteps.style.display = "none";
189
+ }
190
+
191
+ window.addEventListener("message", function (event) {
192
+ if (event.source !== window) return;
193
+ if (!event.data || event.data.source !== "clay-chrome-extension") return;
194
+ setExtConnected();
195
+ });
196
+
197
+ // Toggle popover
198
+ extPillBtn.addEventListener("click", function (e) {
199
+ e.stopPropagation();
200
+ extPopover.classList.toggle("visible");
201
+ refreshIcons(extPopover);
202
+ });
203
+
204
+ document.addEventListener("click", function (e) {
205
+ if (!extPopover.contains(e.target) && e.target !== extPillBtn && !extPillBtn.contains(e.target)) {
206
+ extPopover.classList.remove("visible");
207
+ }
208
+ });
209
+
210
+ // Download button
211
+ if (extDownloadBtn) {
212
+ extDownloadBtn.addEventListener("click", function (e) {
213
+ e.stopPropagation();
214
+ extDownloadBtn.disabled = true;
215
+ extDownloadBtn.innerHTML = iconHtml("loader") + " Downloading...";
216
+ refreshIcons(extDownloadBtn);
217
+ var loaderIcon = extDownloadBtn.querySelector(".lucide");
218
+ if (loaderIcon) loaderIcon.style.animation = "spin 1s linear infinite";
219
+ if (extDownloadStatus) {
220
+ extDownloadStatus.classList.remove("hidden");
221
+ extDownloadStatus.textContent = "Fetching from GitHub...";
222
+ extDownloadStatus.style.color = "";
223
+ }
224
+ fetch("/api/extension/download").then(function (resp) {
225
+ if (!resp.ok) throw new Error("Download failed (" + resp.status + ")");
226
+ return resp.blob();
227
+ }).then(function (blob) {
228
+ var url = URL.createObjectURL(blob);
229
+ var a = document.createElement("a");
230
+ a.href = url;
231
+ a.download = "clay-chrome-extension.zip";
232
+ document.body.appendChild(a);
233
+ a.click();
234
+ document.body.removeChild(a);
235
+ URL.revokeObjectURL(url);
236
+ if (extDownloadStatus) {
237
+ extDownloadStatus.textContent = "Download complete!";
238
+ extDownloadStatus.style.color = "var(--accent)";
239
+ }
240
+ showToast("Extension downloaded");
241
+ }).catch(function (err) {
242
+ if (extDownloadStatus) {
243
+ extDownloadStatus.textContent = "Failed: " + err.message;
244
+ extDownloadStatus.style.color = "var(--danger, #e53935)";
245
+ }
246
+ showToast("Download failed");
247
+ }).finally(function () {
248
+ extDownloadBtn.disabled = false;
249
+ extDownloadBtn.innerHTML = iconHtml("download") + " Download Extension (.zip)";
250
+ refreshIcons(extDownloadBtn);
251
+ });
252
+ });
253
+ }
254
+
255
+ // Copy chrome://extensions URL
256
+ if (extCopyUrl) {
257
+ extCopyUrl.addEventListener("click", function (e) {
258
+ e.stopPropagation();
259
+ copyToClipboard("chrome://extensions").then(function () {
260
+ showToast("Copied chrome://extensions");
261
+ });
262
+ });
263
+ }
264
+ })();
265
+
266
+ // --- Settings: Check for updates ---
267
+ (function () {
268
+ var settingsUpdateCheck = $("settings-update-check");
269
+
270
+ function setUpdateBtn(label, spin, disabled) {
271
+ if (!settingsUpdateCheck) return;
272
+ var icon = settingsUpdateCheck.querySelector(".lucide, [data-lucide]");
273
+ if (icon) {
274
+ icon.setAttribute("data-lucide", spin ? "loader" : "refresh-cw");
275
+ if (spin) icon.classList.add("icon-spin-inline");
276
+ else icon.classList.remove("icon-spin-inline");
277
+ }
278
+ // Update text node
279
+ settingsUpdateCheck.innerHTML = "";
280
+ var i = document.createElement("i");
281
+ i.setAttribute("data-lucide", spin ? "loader" : (disabled ? "check" : "refresh-cw"));
282
+ settingsUpdateCheck.appendChild(i);
283
+ settingsUpdateCheck.appendChild(document.createTextNode(" " + label));
284
+ settingsUpdateCheck.disabled = disabled;
285
+ refreshIcons();
286
+ if (spin) {
287
+ var newIcon = settingsUpdateCheck.querySelector(".lucide");
288
+ if (newIcon) newIcon.classList.add("icon-spin-inline");
289
+ }
290
+ }
291
+
292
+ if (settingsUpdateCheck) {
293
+ settingsUpdateCheck.addEventListener("click", function (e) {
294
+ e.stopPropagation();
295
+ if (ctx.ws && ctx.connected) {
296
+ ctx.ws.send(JSON.stringify({ type: "check_update" }));
297
+ }
298
+ setUpdateBtn("Checking…", true, true);
299
+ });
300
+ }
301
+
302
+ // --- Footer status (title bar) ---
303
+ var footerStatus = $("footer-status");
304
+ if (footerStatus) {
305
+ footerStatus.addEventListener("click", function (e) {
306
+ e.stopPropagation();
307
+ if (ctx.toggleStatusPanel) ctx.toggleStatusPanel();
308
+ });
309
+ }
310
+ })();
311
+
312
+ // Onboarding pill removed — install flow handled by PWA install button
313
+ // Tooltip system moved to modules/tooltip.js
314
+
315
+ // --- iOS Safari detection ---
316
+ var isIOSSafari = (function () {
317
+ var ua = navigator.userAgent;
318
+ var isIOS = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
319
+ var isSafari = isIOS && /Safari/.test(ua) && !/CriOS|FxiOS|OPiOS|EdgiOS/.test(ua);
320
+ return isSafari;
321
+ })();
322
+ var isStandalone = window.matchMedia("(display-mode:standalone)").matches || navigator.standalone;
323
+
324
+ // --- Browser notifications ---
325
+ notifPermission = ("Notification" in window) ? Notification.permission : "denied";
326
+ notifAlertEnabled = localStorage.getItem("notif-alert") !== "0";
327
+ notifSoundEnabled = localStorage.getItem("notif-sound") !== "0";
328
+
329
+ var notifBtn = $("notif-btn");
330
+ var notifMenu = $("notif-menu");
331
+ var notifToggleAlert = $("notif-toggle-alert");
332
+ var notifToggleSound = $("notif-toggle-sound");
333
+
334
+ if (notifAlertEnabled && "Notification" in window && Notification.permission === "denied") {
335
+ notifAlertEnabled = false;
336
+ localStorage.setItem("notif-alert", "0");
337
+ }
338
+ notifToggleAlert.checked = notifAlertEnabled;
339
+ notifToggleSound.checked = notifSoundEnabled;
340
+
341
+ notifBtn.addEventListener("click", function (e) {
342
+ e.stopPropagation();
343
+ var open = notifMenu.classList.toggle("hidden");
344
+ notifBtn.classList.toggle("active", !open);
345
+ });
346
+
347
+ document.addEventListener("click", function (e) {
348
+ if (!notifMenu.contains(e.target) && e.target !== notifBtn) {
349
+ notifMenu.classList.add("hidden");
350
+ notifBtn.classList.remove("active");
351
+ }
352
+ });
353
+
354
+ var notifBlockedHint = $("notif-blocked-hint");
355
+
356
+ notifToggleAlert.addEventListener("change", function () {
357
+ notifAlertEnabled = notifToggleAlert.checked;
358
+ localStorage.setItem("notif-alert", notifAlertEnabled ? "1" : "0");
359
+ notifBlockedHint.classList.add("hidden");
360
+ if (notifAlertEnabled && notifPermission !== "granted") {
361
+ if ("Notification" in window && Notification.permission === "denied") {
362
+ notifAlertEnabled = false;
363
+ notifToggleAlert.checked = false;
364
+ localStorage.setItem("notif-alert", "0");
365
+ notifBlockedHint.classList.remove("hidden");
366
+ refreshIcons();
367
+ return;
368
+ }
369
+ Notification.requestPermission().then(function (p) {
370
+ notifPermission = p;
371
+ if (p !== "granted") {
372
+ notifAlertEnabled = false;
373
+ notifToggleAlert.checked = false;
374
+ localStorage.setItem("notif-alert", "0");
375
+ notifBlockedHint.classList.remove("hidden");
376
+ refreshIcons();
377
+ }
378
+ });
379
+ }
380
+ });
381
+
382
+ // --- Notification help modal ---
383
+ var notifHelpModal = $("notif-help-modal");
384
+ var notifHelpClose = $("notif-help-close");
385
+ var notifLearnMore = $("notif-learn-more");
386
+ var notifUrlCopy = $("notif-url-copy");
387
+ var notifSettingsUrl = $("notif-settings-url");
388
+
389
+ // Detect browser and set correct settings URL
390
+ (function () {
391
+ var url = "chrome://settings/content/notifications";
392
+ var ua = navigator.userAgent;
393
+ if (ua.indexOf("Firefox") !== -1) url = "about:preferences#privacy";
394
+ else if (ua.indexOf("Edg/") !== -1) url = "edge://settings/content/notifications";
395
+ else if (ua.indexOf("Arc") !== -1) url = "arc://settings/content/notifications";
396
+ else if (isIOSSafari) url = "Settings > Safari > Notifications";
397
+ notifSettingsUrl.textContent = url;
398
+ })();
399
+
400
+ notifLearnMore.addEventListener("click", function (e) {
401
+ e.preventDefault();
402
+ notifHelpModal.classList.remove("hidden");
403
+ refreshIcons();
404
+ });
405
+
406
+ notifHelpClose.addEventListener("click", function () {
407
+ notifHelpModal.classList.add("hidden");
408
+ });
409
+
410
+ notifHelpModal.querySelector(".confirm-backdrop").addEventListener("click", function () {
411
+ notifHelpModal.classList.add("hidden");
412
+ });
413
+
414
+ notifUrlCopy.addEventListener("click", function () {
415
+ copyToClipboard(notifSettingsUrl.textContent).then(function () {
416
+ notifUrlCopy.classList.add("copied");
417
+ notifUrlCopy.innerHTML = iconHtml("check");
418
+ refreshIcons();
419
+ setTimeout(function () {
420
+ notifUrlCopy.classList.remove("copied");
421
+ notifUrlCopy.innerHTML = iconHtml("copy");
422
+ refreshIcons();
423
+ }, 1500);
424
+ });
425
+ });
426
+
427
+ notifToggleSound.addEventListener("change", function () {
428
+ notifSoundEnabled = notifToggleSound.checked;
429
+ localStorage.setItem("notif-sound", notifSoundEnabled ? "1" : "0");
430
+ });
431
+
432
+ // --- Push notifications toggle ---
433
+ var notifPushRow = $("notif-push-row");
434
+ var notifTogglePush = $("notif-toggle-push");
435
+ var pushAvailable = ("serviceWorker" in navigator) &&
436
+ (location.protocol === "https:" || location.hostname === "localhost");
437
+
438
+ // On iOS Safari (not in PWA mode), replace the push toggle with an info hint
439
+ if (isIOSSafari && !isStandalone) {
440
+ var infoRow = document.createElement("div");
441
+ infoRow.className = "notif-option notif-ios-info";
442
+ infoRow.style.display = "flex";
443
+ infoRow.innerHTML =
444
+ '<span><i data-lucide="smartphone" style="width:14px;height:14px"></i> Push notifications</span>' +
445
+ '<button class="notif-ios-info-btn" title="Info"><i data-lucide="info" style="width:14px;height:14px"></i></button>';
446
+ notifPushRow.parentNode.replaceChild(infoRow, notifPushRow);
447
+
448
+ var iosHint = document.createElement("div");
449
+ iosHint.id = "notif-ios-hint";
450
+ iosHint.className = "hidden";
451
+ iosHint.innerHTML =
452
+ 'To enable push notifications on iOS, tap <strong>Share</strong> ' +
453
+ '<i data-lucide="share" style="width:12px;height:12px;vertical-align:-2px"></i> ' +
454
+ 'then <strong>Add to Home Screen</strong>. ' +
455
+ 'Push notifications work inside the installed app.';
456
+ infoRow.parentNode.insertBefore(iosHint, infoRow.nextSibling);
457
+
458
+ infoRow.querySelector(".notif-ios-info-btn").addEventListener("click", function (e) {
459
+ e.preventDefault();
460
+ e.stopPropagation();
461
+ iosHint.classList.toggle("hidden");
462
+ refreshIcons();
463
+ });
464
+ refreshIcons();
465
+ } else if (pushAvailable) {
466
+ notifPushRow.style.display = "flex";
467
+ }
468
+
469
+ function sendPushSubscription(sub) {
470
+ var prevEndpoint = localStorage.getItem("push-endpoint");
471
+ window._pushSubscription = sub;
472
+ localStorage.setItem("push-endpoint", sub.endpoint);
473
+ var json = sub.toJSON();
474
+ var payload = { subscription: json };
475
+ if (prevEndpoint && prevEndpoint !== sub.endpoint) {
476
+ payload.replaceEndpoint = prevEndpoint;
477
+ }
478
+ if (ctx.ws && ctx.ws.readyState === 1) {
479
+ ctx.ws.send(JSON.stringify({ type: "push_subscribe", subscription: json, replaceEndpoint: payload.replaceEndpoint || null }));
480
+ } else {
481
+ fetch(basePath + "api/push-subscribe", {
482
+ method: "POST", headers: { "Content-Type": "application/json" },
483
+ credentials: "same-origin", body: JSON.stringify(payload),
484
+ });
485
+ }
486
+ }
487
+
488
+ function subscribePush() {
489
+ navigator.serviceWorker.ready.then(function (reg) {
490
+ return fetch(basePath + "api/vapid-public-key", { cache: "no-store" })
491
+ .then(function (r) { return r.json(); })
492
+ .then(function (data) {
493
+ if (!data.publicKey) throw new Error("No VAPID key");
494
+ var raw = atob(data.publicKey.replace(/-/g, "+").replace(/_/g, "/"));
495
+ var key = new Uint8Array(raw.length);
496
+ for (var i = 0; i < raw.length; i++) key[i] = raw.charCodeAt(i);
497
+ return reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key });
498
+ });
499
+ }).then(function (sub) {
500
+ sendPushSubscription(sub);
501
+ localStorage.setItem("notif-push", "1");
502
+ hideOnboarding();
503
+ localStorage.setItem("onboarding-dismissed", "1");
504
+ // Show a welcome notification so the user knows it works
505
+ navigator.serviceWorker.ready.then(function (reg) {
506
+ reg.showNotification("\ud83c\udf89 Welcome to Clagentic:Console!", {
507
+ body: "\ud83d\udd14 You\u2019ll be notified when Claude responds.",
508
+ tag: "claude-welcome",
509
+ });
510
+ }).catch(function () {});
511
+ }).catch(function () {
512
+ notifTogglePush.checked = false;
513
+ localStorage.setItem("notif-push", "0");
514
+ notifBlockedHint.classList.remove("hidden");
515
+ refreshIcons();
516
+ });
517
+ }
518
+
519
+ function unsubscribePush() {
520
+ if (window._pushSubscription) {
521
+ window._pushSubscription.unsubscribe().catch(function () {});
522
+ window._pushSubscription = null;
523
+ }
524
+ localStorage.setItem("notif-push", "0");
525
+ }
526
+
527
+ notifTogglePush.addEventListener("change", function () {
528
+ if (notifTogglePush.checked) {
529
+ notifBlockedHint.classList.add("hidden");
530
+ subscribePush();
531
+ } else {
532
+ unsubscribePush();
533
+ }
534
+ });
535
+
536
+ // --- Service Worker registration & push state sync ---
537
+ (function initServiceWorker() {
538
+ if (!("serviceWorker" in navigator)) return;
539
+ if (location.protocol !== "https:" && location.hostname !== "localhost") return;
540
+
541
+ // iOS Safari (non-standalone): unregister existing SW and skip registration
542
+ // to prevent iOS from treating the app as a modern PWA (which shows a floating toolbar).
543
+ // SW will be registered once the app is launched in standalone mode from the home screen.
544
+ var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) ||
545
+ (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
546
+ var isStandalone = window.navigator.standalone ||
547
+ window.matchMedia("(display-mode:standalone)").matches;
548
+ if (isIOS && !isStandalone) {
549
+ navigator.serviceWorker.getRegistrations().then(function (regs) {
550
+ regs.forEach(function (r) { r.unregister(); });
551
+ });
552
+ return;
553
+ }
554
+
555
+ navigator.serviceWorker.register("/sw.js")
556
+ .then(function () { return navigator.serviceWorker.ready; })
557
+ .then(function (reg) {
558
+ // Fetch current VAPID key to detect key changes
559
+ var vapidPromise = fetch(basePath + "api/vapid-public-key", { cache: "no-store" })
560
+ .then(function (r) { return r.json(); })
561
+ .then(function (d) { return d.publicKey || null; })
562
+ .catch(function () { return null; });
563
+
564
+ return Promise.all([reg.pushManager.getSubscription(), vapidPromise]).then(function (results) {
565
+ var sub = results[0];
566
+ var serverKey = results[1];
567
+
568
+ // If subscription exists but VAPID key changed, unsubscribe and re-subscribe
569
+ if (sub && serverKey) {
570
+ var savedKey = localStorage.getItem("vapid-key");
571
+ if (savedKey && savedKey !== serverKey) {
572
+ sub.unsubscribe().catch(function () {});
573
+ sub = null;
574
+ }
575
+ }
576
+ if (serverKey) localStorage.setItem("vapid-key", serverKey);
577
+
578
+ if (sub) {
579
+ window._pushSubscription = sub;
580
+ notifTogglePush.checked = true;
581
+ sendPushSubscription(sub);
582
+ hideOnboarding();
583
+ } else if (serverKey && localStorage.getItem("notif-push") === "1") {
584
+ // Had push enabled but subscription is gone (VAPID key change), re-subscribe
585
+ var raw = atob(serverKey.replace(/-/g, "+").replace(/_/g, "/"));
586
+ var key = new Uint8Array(raw.length);
587
+ for (var i = 0; i < raw.length; i++) key[i] = raw.charCodeAt(i);
588
+ reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key })
589
+ .then(function (newSub) {
590
+ sendPushSubscription(newSub);
591
+ notifTogglePush.checked = true;
592
+ }).catch(function () {
593
+ notifTogglePush.checked = false;
594
+ localStorage.setItem("notif-push", "0");
595
+ });
596
+ } else {
597
+ notifTogglePush.checked = false;
598
+ localStorage.setItem("notif-push", "0");
599
+ // Standalone (PWA) without push: redirect to setup for push onboarding
600
+ // Skip if setup was just completed (setup-done flag)
601
+ var isStandalone = window.matchMedia("(display-mode:standalone)").matches || navigator.standalone;
602
+ if (isStandalone && !localStorage.getItem("setup-done")) {
603
+ var isTailscale = /^100\./.test(location.hostname);
604
+ location.href = "/setup" + (isTailscale ? "" : "?mode=lan");
605
+ return;
606
+ }
607
+ }
608
+ });
609
+ })
610
+ .catch(function () {});
611
+ })();
612
+
613
+ }