@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,242 @@
1
+ // app-header.js - Session rename, session info popover, progressive history loading
2
+ // Extracted from app.js (PR-34)
3
+
4
+ import { refreshIcons, iconHtml } from './icons.js';
5
+ import { escapeHtml, copyToClipboard } from './utils.js';
6
+ import { store } from './store.js';
7
+ import { getWs } from './ws-ref.js';
8
+ import { getMessagesEl } from './dom-refs.js';
9
+ import { getActivityEl, setActivityEl, getTurnCounter, setTurnCounter, getPrependAnchor, setPrependAnchor, finalizeAssistantBlock, resetCurrentFullText } from './app-rendering.js';
10
+ import { processMessage } from './app-messages.js';
11
+ import { saveToolState, resetToolState, restoreToolState } from './tools.js';
12
+ import { getSessionUsage, setSessionUsage, getContextData, setContextData, updateContextPanel, updateUsagePanel } from './app-panels.js';
13
+ import { onHistoryPrepended as onSessionSearchHistoryPrepended } from './session-search.js';
14
+
15
+ // --- Module-owned state ---
16
+ var sessionInfoPopover = null;
17
+ var historySentinelObserver = null;
18
+
19
+ export function initHeader() {
20
+ var headerRenameBtn = document.getElementById("header-rename-btn");
21
+ var headerTitleEl = document.getElementById("header-title");
22
+ var headerInfoBtn = document.getElementById("header-info-btn");
23
+
24
+ // --- Header session rename ---
25
+ if (headerRenameBtn) {
26
+ headerRenameBtn.addEventListener("click", function () {
27
+ if (!store.get('activeSessionId')) return;
28
+ var currentText = headerTitleEl.textContent;
29
+ var input = document.createElement("input");
30
+ input.type = "text";
31
+ input.className = "header-rename-input";
32
+ input.value = currentText;
33
+ headerTitleEl.style.display = "none";
34
+ headerRenameBtn.style.display = "none";
35
+ headerTitleEl.parentNode.insertBefore(input, headerTitleEl.nextSibling);
36
+ input.focus();
37
+ input.select();
38
+
39
+ function commit() {
40
+ var newTitle = input.value.trim();
41
+ var ws = getWs();
42
+ if (newTitle && newTitle !== currentText && ws && ws.readyState === 1) {
43
+ ws.send(JSON.stringify({ type: "rename_session", id: store.get('activeSessionId'), title: newTitle }));
44
+ headerTitleEl.textContent = newTitle;
45
+ }
46
+ input.remove();
47
+ headerTitleEl.style.display = "";
48
+ headerRenameBtn.style.display = "";
49
+ }
50
+
51
+ input.addEventListener("keydown", function (e) {
52
+ if (e.key === "Enter") { e.preventDefault(); commit(); }
53
+ if (e.key === "Escape") {
54
+ e.preventDefault();
55
+ input.remove();
56
+ headerTitleEl.style.display = "";
57
+ headerRenameBtn.style.display = "";
58
+ }
59
+ });
60
+ input.addEventListener("blur", commit);
61
+ });
62
+ }
63
+
64
+ // --- Session info popover ---
65
+ if (headerInfoBtn) {
66
+ headerInfoBtn.addEventListener("click", function (e) {
67
+ e.stopPropagation();
68
+ if (sessionInfoPopover) { closeSessionInfoPopover(); return; }
69
+
70
+ var pop = document.createElement("div");
71
+ pop.className = "session-info-popover";
72
+
73
+ function addRow(label, value) {
74
+ var val = value == null ? "-" : String(value);
75
+ var row = document.createElement("div");
76
+ row.className = "info-row";
77
+ row.innerHTML =
78
+ '<span class="info-label">' + label + '</span>' +
79
+ '<span class="info-value">' + escapeHtml(val) + '</span>' +
80
+ '<button class="info-copy-btn" title="Copy">' + iconHtml("copy") + '</button>';
81
+ var btn = row.querySelector(".info-copy-btn");
82
+ btn.addEventListener("click", function () {
83
+ copyToClipboard(value || "").then(function () {
84
+ btn.innerHTML = iconHtml("check");
85
+ refreshIcons();
86
+ setTimeout(function () { btn.innerHTML = iconHtml("copy"); refreshIcons(); }, 1200);
87
+ });
88
+ });
89
+ pop.appendChild(row);
90
+ }
91
+
92
+ var s = store.snap();
93
+ if (s.cliSessionId) addRow("Session ID", s.cliSessionId);
94
+ if (s.activeSessionId) addRow("Local ID", s.activeSessionId);
95
+ if (s.cliSessionId) addRow("Resume", "claude --resume " + s.cliSessionId);
96
+
97
+ document.body.appendChild(pop);
98
+ sessionInfoPopover = pop;
99
+ refreshIcons();
100
+
101
+ var btnRect = headerInfoBtn.getBoundingClientRect();
102
+ pop.style.top = (btnRect.bottom + 6) + "px";
103
+ pop.style.left = btnRect.left + "px";
104
+ var popRect = pop.getBoundingClientRect();
105
+ if (popRect.right > window.innerWidth - 8) {
106
+ pop.style.left = (window.innerWidth - popRect.width - 8) + "px";
107
+ }
108
+ });
109
+
110
+ document.addEventListener("click", function (e) {
111
+ if (sessionInfoPopover && !sessionInfoPopover.contains(e.target) && !e.target.closest("#header-info-btn")) {
112
+ closeSessionInfoPopover();
113
+ }
114
+ });
115
+ }
116
+ }
117
+
118
+ export function closeSessionInfoPopover() {
119
+ if (sessionInfoPopover) {
120
+ sessionInfoPopover.remove();
121
+ sessionInfoPopover = null;
122
+ }
123
+ }
124
+
125
+ export function updateHistorySentinel() {
126
+ var messagesEl = getMessagesEl();
127
+ var existing = messagesEl.querySelector(".history-sentinel");
128
+ if (store.get('historyFrom') > 0) {
129
+ if (!existing) {
130
+ var sentinel = document.createElement("div");
131
+ sentinel.className = "history-sentinel";
132
+ sentinel.innerHTML = '<button class="load-more-btn">Load earlier messages</button>';
133
+ sentinel.querySelector(".load-more-btn").addEventListener("click", function () {
134
+ requestMoreHistory();
135
+ });
136
+ messagesEl.insertBefore(sentinel, messagesEl.firstChild);
137
+
138
+ // Auto-load when sentinel scrolls into view
139
+ if (historySentinelObserver) historySentinelObserver.disconnect();
140
+ historySentinelObserver = new IntersectionObserver(function (entries) {
141
+ if (entries[0].isIntersecting && !store.get('loadingMore') && store.get('historyFrom') > 0) {
142
+ requestMoreHistory();
143
+ }
144
+ }, { root: messagesEl, rootMargin: "200px 0px 0px 0px" });
145
+ historySentinelObserver.observe(sentinel);
146
+ }
147
+ } else {
148
+ if (existing) existing.remove();
149
+ if (historySentinelObserver) { historySentinelObserver.disconnect(); historySentinelObserver = null; }
150
+ }
151
+ }
152
+
153
+ export function requestMoreHistory() {
154
+ var ws = getWs();
155
+ var s = store.snap();
156
+ if (s.loadingMore || s.historyFrom <= 0 || !ws || !s.connected) return;
157
+ store.set({ loadingMore: true });
158
+ var messagesEl = getMessagesEl();
159
+ var btn = messagesEl.querySelector(".load-more-btn");
160
+ if (btn) btn.classList.add("loading");
161
+ ws.send(JSON.stringify({ type: "load_more_history", before: s.historyFrom }));
162
+ }
163
+
164
+ export function prependOlderHistory(items, meta) {
165
+ var messagesEl = getMessagesEl();
166
+
167
+ // Save current rendering state
168
+ var savedMsgEl = store.get('currentMsgEl');
169
+ var savedActivity = getActivityEl();
170
+ var savedFullText = store.get('currentFullText');
171
+ var savedTurnCounter = getTurnCounter();
172
+ var savedToolsState = saveToolState();
173
+ // Save context & usage so old result messages don't overwrite current values
174
+ var savedContext = JSON.parse(JSON.stringify(getContextData()));
175
+ var savedUsage = JSON.parse(JSON.stringify(getSessionUsage()));
176
+
177
+ // Reset to initial values for clean rendering
178
+ store.set({ currentMsgEl: null, currentFullText: "" });
179
+ resetCurrentFullText("");
180
+ setActivityEl(null);
181
+ setTurnCounter(0);
182
+ resetToolState();
183
+
184
+ // Set prepend anchor to insert before existing content
185
+ // Skip the sentinel itself when setting anchor
186
+ var firstReal = messagesEl.querySelector(".history-sentinel");
187
+ setPrependAnchor(firstReal ? firstReal.nextSibling : messagesEl.firstChild);
188
+
189
+ // Remember the first existing content element and its position
190
+ var anchorEl = getPrependAnchor();
191
+ var anchorOffset = anchorEl ? anchorEl.getBoundingClientRect().top : 0;
192
+
193
+ // Process each item through the rendering pipeline
194
+ for (var i = 0; i < items.length; i++) {
195
+ processMessage(items[i]);
196
+ }
197
+
198
+ // Finalize any open assistant block from the batch
199
+ finalizeAssistantBlock();
200
+
201
+ // Clear prepend mode
202
+ setPrependAnchor(null);
203
+
204
+ // Restore saved state
205
+ store.set({ currentMsgEl: savedMsgEl, currentFullText: savedFullText });
206
+ resetCurrentFullText(savedFullText);
207
+ setActivityEl(savedActivity);
208
+ setTurnCounter(savedTurnCounter);
209
+ restoreToolState(savedToolsState);
210
+ // Restore context & usage (old result messages must not overwrite current values)
211
+ setContextData(savedContext);
212
+ setSessionUsage(savedUsage);
213
+ updateContextPanel();
214
+ updateUsagePanel();
215
+
216
+ // Fix scroll: restore anchor element to same visual position
217
+ if (anchorEl) {
218
+ var newTop = anchorEl.getBoundingClientRect().top;
219
+ messagesEl.scrollTop += (newTop - anchorOffset);
220
+ }
221
+
222
+ // Update state
223
+ store.set({ historyFrom: meta.from, loadingMore: false });
224
+
225
+ // Renumber data-turn attributes in DOM order
226
+ var turnEls = messagesEl.querySelectorAll("[data-turn]");
227
+ for (var t = 0; t < turnEls.length; t++) {
228
+ turnEls[t].dataset.turn = t + 1;
229
+ }
230
+ setTurnCounter(turnEls.length);
231
+
232
+ // Update sentinel
233
+ if (meta.hasMore) {
234
+ var btn = messagesEl.querySelector(".load-more-btn");
235
+ if (btn) btn.classList.remove("loading");
236
+ } else {
237
+ updateHistorySentinel();
238
+ }
239
+
240
+ // Notify in-session search that history was prepended (for pending scroll targets)
241
+ onSessionSearchHistoryPrepended();
242
+ }
@@ -0,0 +1,432 @@
1
+ // app-home-hub.js - Home hub rendering, weather, tips
2
+ // Extracted from app.js (PR-25)
3
+
4
+ import { store } from './store.js';
5
+ import { getWs } from './ws-ref.js';
6
+ import { escapeHtml } from './utils.js';
7
+ import { switchProject, getCachedProjects, renderProjectList } from './app-projects.js';
8
+ import { openSchedulerToTab } from './scheduler.js';
9
+ // playbook imports removed (Quick Start section removed from hub)
10
+ import { exitDmMode } from './app-dm.js';
11
+
12
+ function $hub(id) { return document.getElementById(id); }
13
+
14
+ var homeHub = null;
15
+ var homeHubVisible = false;
16
+ var hubSchedules = [];
17
+
18
+ // tip data removed (Did You Know section no longer shown in hub)
19
+
20
+ var DAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
21
+ var MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
22
+ var WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
23
+
24
+ // --- Weather (hidden detail) ---
25
+ var weatherEmoji = null; // null = not yet fetched, "" = failed
26
+ var weatherCondition = ""; // e.g. "Light rain, Auckland"
27
+ var weatherFetchedAt = 0;
28
+ var WEATHER_CACHE_MS = 60 * 60 * 1000; // 1 hour
29
+ // WMO weather code -> emoji + description
30
+ var WMO_MAP = {
31
+ 0: ["☀️", "Clear sky"], 1: ["🌤", "Mainly clear"], 2: ["⛅", "Partly cloudy"], 3: ["☁️", "Overcast"],
32
+ 45: ["🌫", "Fog"], 48: ["🌫", "Depositing rime fog"],
33
+ 51: ["🌦", "Light drizzle"], 53: ["🌦", "Moderate drizzle"], 55: ["🌧", "Dense drizzle"],
34
+ 56: ["🌧", "Light freezing drizzle"], 57: ["🌧", "Dense freezing drizzle"],
35
+ 61: ["🌧", "Slight rain"], 63: ["🌧", "Moderate rain"], 65: ["🌧", "Heavy rain"],
36
+ 66: ["🌧", "Light freezing rain"], 67: ["🌧", "Heavy freezing rain"],
37
+ 71: ["🌨", "Slight snow"], 73: ["🌨", "Moderate snow"], 75: ["❄️", "Heavy snow"],
38
+ 77: ["🌨", "Snow grains"],
39
+ 80: ["🌦", "Slight rain showers"], 81: ["🌧", "Moderate rain showers"], 82: ["🌧", "Violent rain showers"],
40
+ 85: ["🌨", "Slight snow showers"], 86: ["❄️", "Heavy snow showers"],
41
+ 95: ["⛈", "Thunderstorm"], 96: ["⛈", "Thunderstorm with slight hail"], 99: ["⛈", "Thunderstorm with heavy hail"],
42
+ };
43
+
44
+ var SLOT_EMOJIS = ["☀️", "🌤", "⛅", "☁️", "🌧", "🌦", "⛈", "🌨", "❄️", "🌫", "🌙", "✨"];
45
+ var weatherSlotPlayed = false;
46
+
47
+ var hubCloseBtn = null;
48
+
49
+ export function initHomeHub() {
50
+ homeHub = document.getElementById("home-hub");
51
+ hubCloseBtn = document.getElementById("home-hub-close");
52
+
53
+ if (hubCloseBtn) {
54
+ hubCloseBtn.addEventListener("click", function () {
55
+ hideHomeHub();
56
+ if (store.get('currentSlug')) {
57
+ if (document.documentElement.classList.contains("pwa-standalone")) {
58
+ history.replaceState(null, "", "/p/" + store.get('currentSlug') + "/");
59
+ } else {
60
+ history.pushState(null, "", "/p/" + store.get('currentSlug') + "/");
61
+ }
62
+ // Restore icon strip active state
63
+ var homeIcon = document.querySelector(".icon-strip-home");
64
+ if (homeIcon) homeIcon.classList.remove("active");
65
+ renderProjectList();
66
+ }
67
+ });
68
+ }
69
+ }
70
+
71
+ export function isHomeHubVisible() { return homeHubVisible; }
72
+
73
+ function fetchWeather() {
74
+ // Use cache if we have a successful result within the last hour
75
+ if (weatherEmoji && weatherFetchedAt && (Date.now() - weatherFetchedAt < WEATHER_CACHE_MS)) return;
76
+ // Try localStorage cache
77
+ if (!weatherEmoji) {
78
+ try {
79
+ var cached = JSON.parse(localStorage.getItem("clagentic-weather") || localStorage.getItem("clay-weather") || "null");
80
+ if (cached && cached.emoji && (Date.now() - cached.ts < WEATHER_CACHE_MS)) {
81
+ weatherEmoji = cached.emoji;
82
+ weatherCondition = cached.condition || "";
83
+ weatherFetchedAt = cached.ts;
84
+ if (homeHubVisible) updateGreetingWeather();
85
+ return;
86
+ }
87
+ } catch (e) {}
88
+ }
89
+ if (weatherFetchedAt && (Date.now() - weatherFetchedAt < 30000)) return; // don't retry within 30s
90
+ weatherFetchedAt = Date.now();
91
+ // Step 1: IP geolocation -> lat/lon + city
92
+ fetch("https://ipapi.co/json/", { signal: AbortSignal.timeout(4000) })
93
+ .then(function (res) { return res.ok ? res.json() : Promise.reject(); })
94
+ .then(function (geo) {
95
+ var lat = geo.latitude;
96
+ var lon = geo.longitude;
97
+ var city = geo.city || geo.region || "";
98
+ var country = geo.country_name || "";
99
+ var locationStr = city + (country ? ", " + country : "");
100
+ // Step 2: Open-Meteo -> current weather
101
+ var meteoUrl = "https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "&current=weather_code&timezone=auto";
102
+ return fetch(meteoUrl, { signal: AbortSignal.timeout(4000) })
103
+ .then(function (res) { return res.ok ? res.json() : Promise.reject(); })
104
+ .then(function (data) {
105
+ var code = data && data.current && data.current.weather_code;
106
+ if (code === undefined || code === null) return;
107
+ var mapped = WMO_MAP[code] || WMO_MAP[0];
108
+ weatherEmoji = mapped[0];
109
+ weatherCondition = mapped[1] + (locationStr ? " in " + locationStr : "");
110
+ weatherFetchedAt = Date.now();
111
+ try {
112
+ localStorage.setItem("clagentic-weather", JSON.stringify({
113
+ emoji: weatherEmoji, condition: weatherCondition, ts: weatherFetchedAt
114
+ }));
115
+ } catch (e) {}
116
+ if (homeHubVisible) updateGreetingWeather();
117
+ });
118
+ })
119
+ .catch(function () {
120
+ if (!weatherEmoji) weatherEmoji = "";
121
+ });
122
+ }
123
+
124
+ function updateGreetingWeather() {
125
+ var greetEl = $hub("hub-greeting-text");
126
+ if (!greetEl) return;
127
+ // If we have real weather and haven't played the slot yet, do the reel
128
+ if (weatherEmoji && !weatherSlotPlayed && homeHubVisible) {
129
+ weatherSlotPlayed = true;
130
+ playWeatherSlot(greetEl);
131
+ return;
132
+ }
133
+ // Normal update (no animation)
134
+ greetEl.textContent = getGreeting();
135
+
136
+ applyWeatherTooltip(greetEl);
137
+ }
138
+
139
+ function applyWeatherTooltip(greetEl) {
140
+ if (!weatherCondition) return;
141
+ var emojis = greetEl.querySelectorAll("img.emoji");
142
+ var lastEmoji = emojis.length > 0 ? emojis[emojis.length - 1] : null;
143
+ if (lastEmoji) {
144
+ lastEmoji.title = weatherCondition;
145
+ lastEmoji.style.cursor = "default";
146
+ }
147
+ }
148
+
149
+ function playWeatherSlot(greetEl) {
150
+ var h = new Date().getHours();
151
+ var prefix;
152
+ if (h < 6) prefix = "Good night";
153
+ else if (h < 12) prefix = "Good morning";
154
+ else if (h < 18) prefix = "Good afternoon";
155
+ else prefix = "Good evening";
156
+
157
+ // Build schedule: fast ticks -> slow ticks -> land (~3s total)
158
+ var intervals = [50, 50, 50, 60, 70, 80, 100, 120, 150, 190, 240, 300, 370, 450, 530, 640];
159
+ var totalSteps = intervals.length;
160
+ var step = 0;
161
+ var startIdx = Math.floor(Math.random() * SLOT_EMOJIS.length);
162
+
163
+ function tick() {
164
+ if (step < totalSteps) {
165
+ var idx = (startIdx + step) % SLOT_EMOJIS.length;
166
+ greetEl.textContent = prefix + " " + SLOT_EMOJIS[idx];
167
+
168
+ step++;
169
+ setTimeout(tick, intervals[step - 1]);
170
+ } else {
171
+ // Final: land on actual weather
172
+ greetEl.textContent = prefix + " " + weatherEmoji;
173
+
174
+ applyWeatherTooltip(greetEl);
175
+ }
176
+ }
177
+ tick();
178
+ }
179
+
180
+ function getGreeting() {
181
+ var h = new Date().getHours();
182
+ var emoji = weatherEmoji || "";
183
+ // Fallback to time-based emoji if weather not available
184
+ if (!emoji) {
185
+ if (h < 6) emoji = "✨";
186
+ else if (h < 12) emoji = "☀️";
187
+ else if (h < 18) emoji = "🌤";
188
+ else emoji = "🌙";
189
+ }
190
+ var prefix;
191
+ if (h < 6) prefix = "Good night";
192
+ else if (h < 12) prefix = "Good morning";
193
+ else if (h < 18) prefix = "Good afternoon";
194
+ else prefix = "Good evening";
195
+ return prefix + " " + emoji;
196
+ }
197
+
198
+ function getFormattedDate() {
199
+ var now = new Date();
200
+ return WEEKDAY_NAMES[now.getDay()] + ", " + MONTH_NAMES[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear();
201
+ }
202
+
203
+ function formatScheduleTime(ts) {
204
+ var d = new Date(ts);
205
+ var now = new Date();
206
+ var todayStr = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0") + "-" + String(now.getDate()).padStart(2, "0");
207
+ var schedStr = d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
208
+ var h = d.getHours();
209
+ var m = String(d.getMinutes()).padStart(2, "0");
210
+ var ampm = h >= 12 ? "PM" : "AM";
211
+ var h12 = h % 12 || 12;
212
+ var timeStr = h12 + ":" + m + " " + ampm;
213
+ if (schedStr === todayStr) return timeStr;
214
+ // Tomorrow check
215
+ var tomorrow = new Date(now);
216
+ tomorrow.setDate(tomorrow.getDate() + 1);
217
+ var tomStr = tomorrow.getFullYear() + "-" + String(tomorrow.getMonth() + 1).padStart(2, "0") + "-" + String(tomorrow.getDate()).padStart(2, "0");
218
+ if (schedStr === tomStr) return "Tomorrow";
219
+ return DAY_NAMES[d.getDay()] + " " + timeStr;
220
+ }
221
+
222
+ export function renderHomeHub(projects) {
223
+ // Greeting + weather tooltip
224
+ updateGreetingWeather();
225
+
226
+ // Date
227
+ var dateEl = $hub("hub-greeting-date");
228
+ if (dateEl) dateEl.textContent = getFormattedDate();
229
+
230
+ // --- Upcoming tasks ---
231
+ var upcomingList = $hub("hub-upcoming-list");
232
+ var upcomingCount = $hub("hub-upcoming-count");
233
+ if (upcomingList) {
234
+ var now = Date.now();
235
+ var upcoming = hubSchedules.filter(function (s) {
236
+ return s.enabled && s.nextRunAt && s.nextRunAt > now;
237
+ }).sort(function (a, b) {
238
+ return a.nextRunAt - b.nextRunAt;
239
+ });
240
+ // Show up to next 48 hours
241
+ var cutoff = now + 48 * 60 * 60 * 1000;
242
+ var filtered = upcoming.filter(function (s) { return s.nextRunAt <= cutoff; });
243
+
244
+ if (upcomingCount) {
245
+ upcomingCount.textContent = filtered.length > 0 ? filtered.length : "";
246
+ }
247
+
248
+ upcomingList.innerHTML = "";
249
+ if (filtered.length === 0) {
250
+ // Empty state with CTA
251
+ var emptyDiv = document.createElement("div");
252
+ emptyDiv.className = "hub-upcoming-empty";
253
+ emptyDiv.innerHTML = '<div class="hub-upcoming-empty-icon">📋</div>' +
254
+ '<div class="hub-upcoming-empty-text">No upcoming tasks</div>' +
255
+ '<button class="hub-upcoming-cta" id="hub-upcoming-cta">' +
256
+ '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/></svg>' +
257
+ 'Create a schedule</button>';
258
+ upcomingList.appendChild(emptyDiv);
259
+ var ctaBtn = emptyDiv.querySelector("#hub-upcoming-cta");
260
+ if (ctaBtn) {
261
+ ctaBtn.addEventListener("click", function () {
262
+ hideHomeHub();
263
+ openSchedulerToTab("calendar");
264
+ });
265
+ }
266
+ } else {
267
+ var maxShow = 5;
268
+ var shown = filtered.slice(0, maxShow);
269
+ for (var i = 0; i < shown.length; i++) {
270
+ (function (sched) {
271
+ var item = document.createElement("div");
272
+ item.className = "hub-upcoming-item";
273
+ var dotColor = sched.color || "";
274
+ item.innerHTML = '<span class="hub-upcoming-dot"' + (dotColor ? ' style="background:' + dotColor + '"' : '') + '></span>' +
275
+ '<span class="hub-upcoming-time">' + formatScheduleTime(sched.nextRunAt) + '</span>' +
276
+ '<span class="hub-upcoming-name">' + escapeHtml(sched.name || "Untitled") + '</span>' +
277
+ '<span class="hub-upcoming-project">' + escapeHtml(sched.projectTitle || "") + '</span>';
278
+ item.addEventListener("click", function () {
279
+ if (sched.projectSlug) {
280
+ switchProject(sched.projectSlug);
281
+ setTimeout(function () {
282
+ openSchedulerToTab("library");
283
+ }, 300);
284
+ }
285
+ });
286
+ upcomingList.appendChild(item);
287
+ })(shown[i]);
288
+ }
289
+ if (filtered.length > maxShow) {
290
+ var moreEl = document.createElement("div");
291
+ moreEl.className = "hub-upcoming-more";
292
+ moreEl.textContent = "+" + (filtered.length - maxShow) + " more";
293
+ upcomingList.appendChild(moreEl);
294
+ }
295
+ }
296
+ }
297
+
298
+ // --- Projects summary ---
299
+ var projectsList = $hub("hub-projects-list");
300
+ if (projectsList && projects) {
301
+ projectsList.innerHTML = "";
302
+ var hubProjects = projects.filter(function (p) { return !p.isWorktree; });
303
+ for (var p = 0; p < hubProjects.length; p++) {
304
+ (function (proj) {
305
+ var item = document.createElement("div");
306
+ item.className = "hub-project-item";
307
+ var dotClass = "hub-project-dot" + (proj.isProcessing ? " processing" : "");
308
+ var iconHtml = proj.icon ? '<span class="hub-project-icon">' + proj.icon + '</span>' : '';
309
+ var sessionsLabel = typeof proj.sessions === "number" ? proj.sessions : "";
310
+ item.innerHTML = '<span class="' + dotClass + '"></span>' +
311
+ iconHtml +
312
+ '<span class="hub-project-name">' + escapeHtml(proj.title || proj.project || proj.slug) + '</span>' +
313
+ (sessionsLabel !== "" ? '<span class="hub-project-sessions">' + sessionsLabel + '</span>' : '');
314
+ item.addEventListener("click", function () {
315
+ switchProject(proj.slug);
316
+ });
317
+ projectsList.appendChild(item);
318
+ })(hubProjects[p]);
319
+ }
320
+ // Render emoji icons
321
+
322
+ }
323
+
324
+ // --- Week strip ---
325
+ var weekStrip = $hub("hub-week-strip");
326
+ if (weekStrip) {
327
+ weekStrip.innerHTML = "";
328
+ var today = new Date();
329
+ var todayDate = today.getDate();
330
+ var todayMonth = today.getMonth();
331
+ var todayYear = today.getFullYear();
332
+ // Find Monday of current week
333
+ var dayOfWeek = today.getDay();
334
+ var mondayOffset = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
335
+ var monday = new Date(today);
336
+ monday.setDate(today.getDate() + mondayOffset);
337
+
338
+ // Build set of dates that have events
339
+ var eventDates = {};
340
+ for (var si = 0; si < hubSchedules.length; si++) {
341
+ var sched = hubSchedules[si];
342
+ if (!sched.enabled) continue;
343
+ if (sched.nextRunAt) {
344
+ var sd = new Date(sched.nextRunAt);
345
+ var key = sd.getFullYear() + "-" + sd.getMonth() + "-" + sd.getDate();
346
+ eventDates[key] = (eventDates[key] || 0) + 1;
347
+ }
348
+ if (sched.date) {
349
+ var parts = sched.date.split("-");
350
+ var dateKey = parseInt(parts[0], 10) + "-" + (parseInt(parts[1], 10) - 1) + "-" + parseInt(parts[2], 10);
351
+ eventDates[dateKey] = (eventDates[dateKey] || 0) + 1;
352
+ }
353
+ }
354
+
355
+ for (var d = 0; d < 7; d++) {
356
+ var dayDate = new Date(monday);
357
+ dayDate.setDate(monday.getDate() + d);
358
+ var isToday = dayDate.getDate() === todayDate && dayDate.getMonth() === todayMonth && dayDate.getFullYear() === todayYear;
359
+ var dateKey = dayDate.getFullYear() + "-" + dayDate.getMonth() + "-" + dayDate.getDate();
360
+ var eventCount = eventDates[dateKey] || 0;
361
+
362
+ var cell = document.createElement("div");
363
+ cell.className = "hub-week-day" + (isToday ? " today" : "");
364
+ var dotsHtml = '<div class="hub-week-dots">';
365
+ var dotCount = Math.min(eventCount, 3);
366
+ for (var di = 0; di < dotCount; di++) {
367
+ dotsHtml += '<span class="hub-week-dot"></span>';
368
+ }
369
+ dotsHtml += '</div>';
370
+ cell.innerHTML = '<span class="hub-week-label">' + DAY_NAMES[(dayDate.getDay())] + '</span>' +
371
+ '<span class="hub-week-num">' + dayDate.getDate() + '</span>' +
372
+ dotsHtml;
373
+ weekStrip.appendChild(cell);
374
+ }
375
+ }
376
+
377
+ // Quick Start playbooks and Did You Know tip sections have been removed from the hub.
378
+
379
+ // Render twemoji for all emoji in the hub
380
+
381
+ }
382
+
383
+ export function handleHubSchedules(msg) {
384
+ if (msg.schedules) {
385
+ hubSchedules = msg.schedules;
386
+ if (homeHubVisible) renderHomeHub(getCachedProjects());
387
+ }
388
+ }
389
+
390
+ function startTipRotation() {} // removed: tip section no longer shown
391
+ function stopTipRotation() {}
392
+
393
+ export function showHomeHub() {
394
+ if (store.get('dmMode')) exitDmMode();
395
+ homeHubVisible = true;
396
+ homeHub.classList.remove("hidden");
397
+ // Show close button only if there's a project to return to
398
+ if (hubCloseBtn) {
399
+ if (store.get('currentSlug')) hubCloseBtn.classList.remove("hidden");
400
+ else hubCloseBtn.classList.add("hidden");
401
+ }
402
+ // Fetch weather silently (once)
403
+ fetchWeather();
404
+ // Request cross-project schedules
405
+ if (getWs() && getWs().readyState === 1) {
406
+ getWs().send(JSON.stringify({ type: "hub_schedules_list" }));
407
+ }
408
+ renderHomeHub(getCachedProjects());
409
+ startTipRotation();
410
+ if (document.documentElement.classList.contains("pwa-standalone")) {
411
+ history.replaceState(null, "", "/");
412
+ } else {
413
+ history.pushState(null, "", "/");
414
+ }
415
+ // Update icon strip active state
416
+ var homeIcon = document.querySelector(".icon-strip-home");
417
+ if (homeIcon) homeIcon.classList.add("active");
418
+ var activeProj = document.querySelector("#icon-strip-projects .icon-strip-item.active");
419
+ if (activeProj) activeProj.classList.remove("active");
420
+ // Mobile home button active
421
+ var mobileHome = document.getElementById("mobile-home-btn");
422
+ if (mobileHome) mobileHome.classList.add("active");
423
+ }
424
+
425
+ export function hideHomeHub() {
426
+ if (!homeHubVisible) return;
427
+ homeHubVisible = false;
428
+ homeHub.classList.add("hidden");
429
+ stopTipRotation();
430
+ var mobileHome = document.getElementById("mobile-home-btn");
431
+ if (mobileHome) mobileHome.classList.remove("active");
432
+ }