@clagentic/console 1.6.0-beta.1 → 1.6.0-beta.3

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 (46) hide show
  1. package/README.md +18 -0
  2. package/lib/daemon.js +94 -0
  3. package/lib/history-visibility.js +113 -0
  4. package/lib/project-sessions.js +51 -2
  5. package/lib/public/css/base.css +18 -0
  6. package/lib/public/css/diagnostics.css +99 -11
  7. package/lib/public/css/icon-strip.css +201 -0
  8. package/lib/public/css/menus.css +2 -2
  9. package/lib/public/css/mobile-nav.css +24 -0
  10. package/lib/public/css/server-settings.css +100 -0
  11. package/lib/public/index.html +17 -1
  12. package/lib/public/modules/app-header.js +72 -17
  13. package/lib/public/modules/app-home-hub.js +31 -7
  14. package/lib/public/modules/app-messages.js +5 -0
  15. package/lib/public/modules/app-notifications.js +5 -1
  16. package/lib/public/modules/app-projects.js +10 -5
  17. package/lib/public/modules/command-palette.js +16 -5
  18. package/lib/public/modules/custom-icons-settings.js +399 -0
  19. package/lib/public/modules/custom-icons.js +114 -0
  20. package/lib/public/modules/diagnostic-format.js +18 -2
  21. package/lib/public/modules/diagnostics.js +159 -8
  22. package/lib/public/modules/emoji-picker.js +274 -6
  23. package/lib/public/modules/history-visibility.js +98 -0
  24. package/lib/public/modules/popover-position.js +192 -0
  25. package/lib/public/modules/project-icon.js +113 -0
  26. package/lib/public/modules/project-settings.js +2 -2
  27. package/lib/public/modules/project-switcher.js +2 -1
  28. package/lib/public/modules/scheduler-config.js +5 -8
  29. package/lib/public/modules/scheduler.js +5 -6
  30. package/lib/public/modules/server-settings.js +6 -0
  31. package/lib/public/modules/sidebar-mobile.js +4 -6
  32. package/lib/public/modules/sidebar-projects.js +35 -90
  33. package/lib/public/modules/sidebar-sessions.js +6 -20
  34. package/lib/public/modules/sticky-notes.js +4 -4
  35. package/lib/public/modules/terminal.js +5 -12
  36. package/lib/sdk-bridge.js +59 -19
  37. package/lib/sdk-message-processor.js +58 -3
  38. package/lib/sdk-permission-ownership.js +85 -0
  39. package/lib/server-settings.js +221 -1
  40. package/lib/server.js +2 -0
  41. package/lib/sessions.js +77 -10
  42. package/lib/settings-preflight.js +52 -16
  43. package/lib/utils.js +23 -0
  44. package/lib/ws-schema.js +2 -0
  45. package/lib/yoke/adapters/diagnostic-patterns.js +25 -0
  46. package/package.json +2 -1
@@ -12,20 +12,61 @@
12
12
  // initDiagnostics() — call once on page load (wires up panel button)
13
13
  // addDiagnostic(msg) — call from processMessage case 'diagnostic'
14
14
  // formatDiagnosticSource(source) — pure helper, exported for tests
15
+ //
16
+ // Dismiss / clear-all (parity with app-notifications.js banner dismiss +
17
+ // clear-all, see initAppNotifications/dismissNotif/clearAllBanners there):
18
+ // diagnostics are client-side-only session state — there is no backend
19
+ // message type or persistence for them (unlike notifications, which round-
20
+ // trip a notification_dismiss/_dismiss_all message over the websocket).
21
+ // Dismissing here only ever mutates the in-memory `diagnostics` array and
22
+ // the DOM; a dismissed diagnostic can legitimately reappear if the next
23
+ // settings-preflight run re-emits the same underlying condition — that is
24
+ // expected and not a bug in this module.
15
25
 
16
26
  import { iconHtml, refreshIcons } from './icons.js';
17
27
  import { formatDiagnosticSource as _formatSource } from './diagnostic-format.js';
18
28
 
19
29
  // --- Module state ---
20
- var diagnostics = []; // [{severity, source, message, actionable, ts}]
30
+ var diagnostics = []; // [{id, severity, source, message, actionable, ts}]
21
31
  var panelEl = null;
22
32
  var panelListEl = null;
23
33
  var panelToggleBtn = null;
24
34
  var panelBadgeEl = null;
35
+ var clearAllBtn = null;
36
+
37
+ // Stable per-entry identity so a specific rendered item can be located and
38
+ // removed on dismiss. The array otherwise carries no unique key.
39
+ var _nextDiagnosticId = 1;
25
40
 
26
41
  // Severity priority (higher = more prominent).
27
42
  var SEVERITY_ORDER = { error: 2, warning: 1, info: 0 };
28
43
 
44
+ // lr-e901: dedup window for repeated/duplicate diagnostics. Two independent
45
+ // emitters (CLI-stderr capture + deterministic settings-preflight runPreflight())
46
+ // can legitimately produce a diagnostic for the same underlying condition -
47
+ // addDiagnostic() had no dedup, so both were pushed and both toasted. Identity
48
+ // is (source, scope, message): scope is included because runPreflight()
49
+ // intentionally emits one diagnostic per settings file (user vs project,
50
+ // lr-7e22) - those are distinct conditions and must NOT be deduped together.
51
+ var DEDUP_WINDOW_MS = 5000;
52
+ var _recentDiagnosticKeys = Object.create(null); // key -> last-seen timestamp (ms)
53
+
54
+ function _diagnosticKey(msg) {
55
+ return (msg.source || "") + "|" + (msg.scope || "") + "|" + (msg.message || "");
56
+ }
57
+
58
+ /**
59
+ * True when an equivalent diagnostic (same source+scope+message) was already
60
+ * recorded within DEDUP_WINDOW_MS. Also prunes the key's prior timestamp so
61
+ * the map does not grow unbounded across a long session.
62
+ */
63
+ function _isDuplicateDiagnostic(msg, now) {
64
+ var key = _diagnosticKey(msg);
65
+ var last = _recentDiagnosticKeys[key];
66
+ _recentDiagnosticKeys[key] = now;
67
+ return typeof last === "number" && (now - last) < DEDUP_WINDOW_MS;
68
+ }
69
+
29
70
  // ============================================================
30
71
  // Init
31
72
  // ============================================================
@@ -35,6 +76,7 @@ export function initDiagnostics() {
35
76
  panelListEl = document.getElementById("diagnostics-panel-list");
36
77
  panelToggleBtn = document.getElementById("diagnostics-panel-btn");
37
78
  panelBadgeEl = document.getElementById("diagnostics-panel-badge");
79
+ clearAllBtn = panelEl ? panelEl.querySelector(".diagnostics-panel-clear-all") : null;
38
80
 
39
81
  if (!panelEl || !panelListEl || !panelToggleBtn) return;
40
82
 
@@ -54,6 +96,14 @@ export function initDiagnostics() {
54
96
  });
55
97
  }
56
98
 
99
+ // Clear-all button (parity with app-notifications.js clearAllBanners()).
100
+ if (clearAllBtn) {
101
+ clearAllBtn.addEventListener("click", function () {
102
+ clearAllDiagnostics();
103
+ if (closeBtn) closeBtn.focus();
104
+ });
105
+ }
106
+
57
107
  // Toggle button in the topbar.
58
108
  panelToggleBtn.addEventListener("click", function () {
59
109
  if (panelEl.classList.contains("hidden")) {
@@ -69,6 +119,16 @@ export function initDiagnostics() {
69
119
  closePanelAndRefocus();
70
120
  }
71
121
  });
122
+
123
+ // Click-outside dismiss: the panel is a non-modal surface (no backdrop
124
+ // element), so listen on the document and close when a click lands
125
+ // outside the panel and outside its topbar toggle button (lr-b580).
126
+ document.addEventListener("click", function (e) {
127
+ if (panelEl.classList.contains("hidden")) return;
128
+ if (panelEl.contains(e.target)) return;
129
+ if (panelToggleBtn && panelToggleBtn.contains(e.target)) return;
130
+ closePanelAndRefocus();
131
+ });
72
132
  }
73
133
 
74
134
  // ============================================================
@@ -76,12 +136,20 @@ export function initDiagnostics() {
76
136
  // ============================================================
77
137
 
78
138
  export function addDiagnostic(msg) {
139
+ var now = Date.now();
140
+
141
+ // lr-e901: same condition can arrive via two independent emitters (CLI-stderr
142
+ // capture + deterministic preflight) - collapse to a single visible entry.
143
+ if (_isDuplicateDiagnostic(msg, now)) return;
144
+
79
145
  var entry = {
80
146
  severity: msg.severity || "info",
81
147
  source: msg.source || "",
148
+ scope: msg.scope || "",
82
149
  message: msg.message || "",
83
150
  actionable: msg.actionable || null,
84
- ts: Date.now(),
151
+ ts: now,
152
+ id: _nextDiagnosticId++,
85
153
  };
86
154
  diagnostics.push(entry);
87
155
 
@@ -106,6 +174,23 @@ export { formatDiagnosticSource } from './diagnostic-format.js';
106
174
  // Toast
107
175
  // ============================================================
108
176
 
177
+ // lr-e901: fixed top-right corner stack (see diagnostics.css
178
+ // #diagnostic-toast-container) so concurrent diagnostic toasts stack via
179
+ // normal flex flow instead of piling on top of each other at a single fixed
180
+ // position over the input box.
181
+ var toastContainerEl = null;
182
+
183
+ function _getToastContainer() {
184
+ if (toastContainerEl && toastContainerEl.isConnected) return toastContainerEl;
185
+ toastContainerEl = document.getElementById("diagnostic-toast-container");
186
+ if (!toastContainerEl) {
187
+ toastContainerEl = document.createElement("div");
188
+ toastContainerEl.id = "diagnostic-toast-container";
189
+ document.body.appendChild(toastContainerEl);
190
+ }
191
+ return toastContainerEl;
192
+ }
193
+
109
194
  function _showDiagnosticToast(entry) {
110
195
  var el = document.createElement("div");
111
196
  // Use a dedicated class so diagnostics are visually distinct from error messages.
@@ -122,7 +207,7 @@ function _showDiagnosticToast(entry) {
122
207
 
123
208
  var sourceEl = document.createElement("span");
124
209
  sourceEl.className = "toast-diagnostic-source";
125
- sourceEl.textContent = _formatSource(entry.source);
210
+ sourceEl.textContent = _formatSource(entry.source, entry.scope);
126
211
 
127
212
  var dismissBtn = document.createElement("button");
128
213
  dismissBtn.className = "toast-diagnostic-dismiss";
@@ -145,7 +230,7 @@ function _showDiagnosticToast(entry) {
145
230
  el.appendChild(msgEl);
146
231
  el.appendChild(hintEl);
147
232
 
148
- document.body.appendChild(el);
233
+ _getToastContainer().appendChild(el);
149
234
  refreshIcons();
150
235
 
151
236
  // Animate in.
@@ -206,11 +291,11 @@ function _appendEntry(entry) {
206
291
  if (!panelListEl) return;
207
292
 
208
293
  // Remove the empty-state placeholder if present.
209
- var emptyEl = panelListEl.querySelector(".diagnostics-empty");
210
- if (emptyEl) emptyEl.parentNode.removeChild(emptyEl);
294
+ _removeEmptyPlaceholder();
211
295
 
212
296
  var item = document.createElement("div");
213
297
  item.className = "diagnostics-item diagnostics-item-" + entry.severity;
298
+ item.setAttribute("data-diag-id", String(entry.id));
214
299
 
215
300
  // Icon strip: severity pill.
216
301
  var meta = document.createElement("div");
@@ -223,10 +308,19 @@ function _appendEntry(entry) {
223
308
 
224
309
  var srcEl = document.createElement("span");
225
310
  srcEl.className = "diagnostics-source";
226
- srcEl.textContent = _formatSource(entry.source);
311
+ srcEl.textContent = _formatSource(entry.source, entry.scope);
312
+
313
+ var dismissBtn = document.createElement("button");
314
+ dismissBtn.className = "diagnostics-item-dismiss";
315
+ dismissBtn.setAttribute("aria-label", "Dismiss this diagnostic");
316
+ dismissBtn.innerHTML = iconHtml("x");
317
+ dismissBtn.addEventListener("click", function () {
318
+ dismissDiagnostic(entry.id);
319
+ });
227
320
 
228
321
  meta.appendChild(sevEl);
229
322
  meta.appendChild(srcEl);
323
+ meta.appendChild(dismissBtn);
230
324
 
231
325
  var msgEl = document.createElement("div");
232
326
  msgEl.className = "diagnostics-message";
@@ -251,15 +345,72 @@ function _appendEntry(entry) {
251
345
  actionEl.appendChild(fixIcon);
252
346
  actionEl.appendChild(fixText);
253
347
  item.appendChild(actionEl);
254
- refreshIcons();
255
348
  }
256
349
 
257
350
  panelListEl.appendChild(item);
351
+ refreshIcons();
258
352
 
259
353
  // Scroll the panel to the newest entry.
260
354
  panelListEl.scrollTop = panelListEl.scrollHeight;
261
355
  }
262
356
 
357
+ // ============================================================
358
+ // Dismiss / clear-all (client-side only — see module header note)
359
+ // ============================================================
360
+
361
+ function _removeEmptyPlaceholder() {
362
+ if (!panelListEl) return;
363
+ var emptyEl = panelListEl.querySelector(".diagnostics-empty");
364
+ if (emptyEl) emptyEl.parentNode.removeChild(emptyEl);
365
+ }
366
+
367
+ // Restore the empty-state placeholder that _appendEntry removes on first
368
+ // append. Mirrors the markup baked into index.html so a fresh page load and
369
+ // a fully-cleared panel render identically.
370
+ function _restoreEmptyPlaceholder() {
371
+ if (!panelListEl) return;
372
+ if (panelListEl.querySelector(".diagnostics-empty")) return;
373
+ var emptyEl = document.createElement("div");
374
+ emptyEl.className = "diagnostics-empty";
375
+ emptyEl.textContent = "No diagnostics this session.";
376
+ panelListEl.appendChild(emptyEl);
377
+ }
378
+
379
+ /**
380
+ * Remove a single diagnostic by id from both the in-memory array and the
381
+ * rendered panel list, then refresh the badge. No-op if the id is unknown
382
+ * (e.g. a stale dismiss click racing a clear-all).
383
+ */
384
+ function dismissDiagnostic(id) {
385
+ var idx = -1;
386
+ for (var i = 0; i < diagnostics.length; i++) {
387
+ if (diagnostics[i].id === id) { idx = i; break; }
388
+ }
389
+ if (idx === -1) return;
390
+ diagnostics.splice(idx, 1);
391
+
392
+ if (panelListEl) {
393
+ var itemEl = panelListEl.querySelector('[data-diag-id="' + id + '"]');
394
+ if (itemEl && itemEl.parentNode) itemEl.parentNode.removeChild(itemEl);
395
+ }
396
+
397
+ if (diagnostics.length === 0) _restoreEmptyPlaceholder();
398
+ _updateBadge();
399
+ }
400
+
401
+ /**
402
+ * Empty the diagnostics array and panel list, restore the empty-state
403
+ * placeholder, and hide the badge. Parity with clearAllBanners() in
404
+ * app-notifications.js, minus the websocket round-trip — diagnostics have
405
+ * no server-side dismiss contract (see module header note).
406
+ */
407
+ function clearAllDiagnostics() {
408
+ diagnostics = [];
409
+ if (panelListEl) panelListEl.innerHTML = "";
410
+ _restoreEmptyPlaceholder();
411
+ _updateBadge();
412
+ }
413
+
263
414
  // ============================================================
264
415
  // Badge
265
416
  // ============================================================
@@ -2,8 +2,11 @@
2
2
  // Replaces hand-curated EMOJI_CATEGORIES in sidebar-projects.js / project-settings.js
3
3
 
4
4
  import { parseEmojis } from './markdown.js';
5
+ import { showToast } from './utils.js';
6
+ import { slugifyFilename, fetchCustomIconList, uploadCustomIcon, deleteCustomIcon, matchesCustomIconQuery } from './custom-icons.js';
5
7
 
6
- // Group metadata matching emojibase-data group numbers
8
+ // Group metadata matching emojibase-data group numbers.
9
+ // "custom" is a string key (not a numeric group) so it never collides with emojibase groups.
7
10
  var GROUP_META = [
8
11
  { g: 0, icon: "😀", label: "Smileys & Emotion" },
9
12
  { g: 1, icon: "🧑", label: "People & Body" },
@@ -14,6 +17,7 @@ var GROUP_META = [
14
17
  { g: 7, icon: "💡", label: "Objects" },
15
18
  { g: 8, icon: "❤️", label: "Symbols" },
16
19
  { g: 9, icon: "🏁", label: "Flags" },
20
+ { g: "custom", icon: "🖼", label: "Custom" },
17
21
  ];
18
22
 
19
23
  // Cached data promise — fetched once
@@ -137,10 +141,17 @@ export function buildEmojiPicker(opts) {
137
141
 
138
142
  var currentCatIdx = 0;
139
143
 
140
- function buildGrid(emojis) {
144
+ // customMatches (optional) — custom-icon {slug, url} entries to render as
145
+ // image tiles alongside plain-text emoji results (lr-0847: search previously
146
+ // never included custom icons at all, so "console" could never find
147
+ // ":clagentic-console:" regardless of query). Appended after the emoji
148
+ // results, reusing the same select-on-click behavior as the Custom tab.
149
+ function buildGrid(emojis, customMatches) {
141
150
  grid.innerHTML = "";
142
151
  noResults.style.display = "none";
143
- if (!emojis || emojis.length === 0) {
152
+ var hasEmojis = emojis && emojis.length > 0;
153
+ var hasCustom = customMatches && customMatches.length > 0;
154
+ if (!hasEmojis && !hasCustom) {
144
155
  noResults.style.display = "block";
145
156
  return;
146
157
  }
@@ -157,24 +168,281 @@ export function buildEmojiPicker(opts) {
157
168
  frag.appendChild(btn);
158
169
  })(emojis[i]);
159
170
  }
171
+ if (hasCustom) {
172
+ for (var ci = 0; ci < customMatches.length; ci++) {
173
+ (function (entry) {
174
+ var btn = document.createElement("button");
175
+ btn.className = "emoji-picker-item emoji-picker-item-custom";
176
+ btn.title = ":" + entry.slug + ":";
177
+ var img = document.createElement("img");
178
+ img.src = entry.url;
179
+ img.alt = ":" + entry.slug + ":";
180
+ img.className = "emoji-picker-custom-img";
181
+ btn.appendChild(img);
182
+ btn.addEventListener("click", function (e) {
183
+ e.stopPropagation();
184
+ onSelect(":" + entry.slug + ":");
185
+ });
186
+ frag.appendChild(btn);
187
+ })(customMatches[ci]);
188
+ }
189
+ }
160
190
  grid.appendChild(frag);
161
191
  parseEmojis(grid);
162
192
  scrollArea.scrollTop = 0;
163
193
  }
164
194
 
195
+ // --- Custom emoji panel ---
196
+
197
+ // Cached list of uploads from GET /api/custom-emoji
198
+ var customList = null; // null = not fetched yet
199
+
200
+ function fetchCustomList(cb) {
201
+ fetchCustomIconList().then(function (list) {
202
+ customList = list;
203
+ if (cb) cb(customList);
204
+ });
205
+ }
206
+
207
+ function buildCustomPanel() {
208
+ grid.innerHTML = "";
209
+ noResults.style.display = "none";
210
+
211
+ var panel = document.createElement("div");
212
+ panel.className = "emoji-picker-custom-panel";
213
+
214
+ // Hidden file input (opened by upload tile click)
215
+ var fileInput = document.createElement("input");
216
+ fileInput.type = "file";
217
+ fileInput.accept = "image/png,image/jpeg,image/gif,image/webp";
218
+ fileInput.style.display = "none";
219
+ panel.appendChild(fileInput);
220
+
221
+ // Slug confirm dialog (shown inline before upload)
222
+ var slugConfirm = document.createElement("div");
223
+ slugConfirm.className = "emoji-picker-slug-confirm hidden";
224
+ slugConfirm.innerHTML =
225
+ '<label class="emoji-picker-slug-label">Slug</label>' +
226
+ '<input type="text" class="emoji-picker-slug-input" maxlength="64" spellcheck="false" autocomplete="off">' +
227
+ '<div class="emoji-picker-slug-actions">' +
228
+ '<button class="emoji-picker-slug-cancel">Cancel</button>' +
229
+ '<button class="emoji-picker-slug-ok primary">Upload</button>' +
230
+ '</div>';
231
+ panel.appendChild(slugConfirm);
232
+
233
+ var slugInput = slugConfirm.querySelector(".emoji-picker-slug-input");
234
+ var slugOk = slugConfirm.querySelector(".emoji-picker-slug-ok");
235
+ var slugCancel = slugConfirm.querySelector(".emoji-picker-slug-cancel");
236
+ var pendingFile = null;
237
+
238
+ function showSlugConfirm(file) {
239
+ pendingFile = file;
240
+ slugInput.value = slugifyFilename(file.name);
241
+ slugConfirm.classList.remove("hidden");
242
+ slugInput.focus();
243
+ slugInput.select();
244
+ }
245
+
246
+ function hideSlugConfirm() {
247
+ slugConfirm.classList.add("hidden");
248
+ pendingFile = null;
249
+ }
250
+
251
+ function doUpload() {
252
+ // Both early returns below used to be silent — the control (rendered
253
+ // by showSlugConfirm) is only reachable once a file is already
254
+ // selected, but a defensive check that fires with zero user feedback
255
+ // is indistinguishable from the picker doing nothing at all. Surface
256
+ // both via the same toast used for server-side upload failures (line
257
+ // ~285) so "nothing happened" never happens silently again.
258
+ if (!pendingFile) {
259
+ showToast("Couldn't add custom emoji", "warn");
260
+ return;
261
+ }
262
+ var slug = slugInput.value.trim().toLowerCase()
263
+ .replace(/[^a-z0-9_-]+/g, "-")
264
+ .replace(/^-+|-+$/g, "")
265
+ .slice(0, 64);
266
+ if (!slug || !/^[a-z0-9_-]{1,64}$/.test(slug)) {
267
+ showToast("Enter a valid name", "warn");
268
+ return;
269
+ }
270
+
271
+ // Check for duplicate in the already-fetched list
272
+ var existing = customList || [];
273
+ var hasDup = existing.some(function (e) { return e.slug === slug; });
274
+
275
+ function proceed() {
276
+ hideSlugConfirm();
277
+ uploadCustomIcon(slug, pendingFile).then(function (result) {
278
+ if (!result.ok) {
279
+ // lr-0847: the picker previously swallowed upload failures here
280
+ // (bare `return`), so a failed upload looked identical to a
281
+ // successful one from the user's perspective — nothing happened,
282
+ // no icon appeared, no explanation. Settings surfaces the same
283
+ // uploadCustomIcon() failure via window.alert; use the app's
284
+ // shared toast here since the picker is a transient popover, not
285
+ // a modal dialog.
286
+ showToast(result.error || "Upload failed", "warn");
287
+ return;
288
+ }
289
+ // Refresh the custom grid after upload. buildCustomPanel() already
290
+ // repaints the grid it just (re)built via its own fresh
291
+ // renderCustomGrid closure (see below) — calling the outer
292
+ // renderCustomGrid here re-renders the ORPHANED grid captured by
293
+ // this closure at the time doUpload's panel was built, which is
294
+ // detached from the DOM the moment buildCustomPanel() runs again.
295
+ customList = null;
296
+ fetchCustomList(function () { buildCustomPanel(); });
297
+ });
298
+ }
299
+
300
+ if (hasDup) {
301
+ // Confirm overwrite
302
+ if (window.confirm(":" + slug + ": already exists — overwrite?")) {
303
+ proceed();
304
+ } else {
305
+ hideSlugConfirm();
306
+ }
307
+ } else {
308
+ proceed();
309
+ }
310
+ }
311
+
312
+ slugOk.addEventListener("click", function (e) { e.stopPropagation(); doUpload(); });
313
+ slugCancel.addEventListener("click", function (e) { e.stopPropagation(); hideSlugConfirm(); });
314
+ slugInput.addEventListener("keydown", function (e) {
315
+ e.stopPropagation();
316
+ if (e.key === "Enter") { e.preventDefault(); doUpload(); }
317
+ if (e.key === "Escape") { e.preventDefault(); hideSlugConfirm(); }
318
+ });
319
+ // Prevent slug input clicks from bubbling to the picker's document-click close handler
320
+ slugInput.addEventListener("click", function (e) { e.stopPropagation(); });
321
+
322
+ fileInput.addEventListener("change", function () {
323
+ var file = fileInput.files && fileInput.files[0];
324
+ fileInput.value = ""; // reset so same file can be re-selected
325
+ if (!file) return;
326
+ showSlugConfirm(file);
327
+ });
328
+
329
+ // Grid of existing uploads
330
+ var customGrid = document.createElement("div");
331
+ customGrid.className = "emoji-picker-grid";
332
+ panel.appendChild(customGrid);
333
+
334
+ function renderCustomGrid() {
335
+ customGrid.innerHTML = "";
336
+
337
+ // Upload tile (always first)
338
+ var uploadTile = document.createElement("button");
339
+ uploadTile.className = "emoji-picker-item emoji-picker-upload-tile";
340
+ uploadTile.title = "Upload image";
341
+ uploadTile.textContent = "+";
342
+ uploadTile.addEventListener("click", function (e) {
343
+ e.stopPropagation();
344
+ fileInput.click();
345
+ });
346
+ customGrid.appendChild(uploadTile);
347
+
348
+ var list = customList || [];
349
+ for (var ci = 0; ci < list.length; ci++) {
350
+ (function (entry) {
351
+ var tile = document.createElement("div");
352
+ tile.className = "emoji-picker-custom-tile";
353
+
354
+ var img = document.createElement("img");
355
+ img.src = entry.url;
356
+ img.alt = ":" + entry.slug + ":";
357
+ img.className = "emoji-picker-custom-img";
358
+ img.title = ":" + entry.slug + ":";
359
+ img.addEventListener("click", function (e) {
360
+ e.stopPropagation();
361
+ onSelect(":" + entry.slug + ":");
362
+ });
363
+ tile.appendChild(img);
364
+
365
+ var delBtn = document.createElement("button");
366
+ delBtn.className = "emoji-picker-custom-delete";
367
+ delBtn.title = "Delete";
368
+ delBtn.textContent = "×";
369
+ delBtn.addEventListener("click", function (e) {
370
+ e.stopPropagation();
371
+ deleteCustomIcon(entry.slug).then(function () {
372
+ // Same stale-closure hazard as the upload success path above:
373
+ // buildCustomPanel() already repaints via its own fresh
374
+ // renderCustomGrid; the closure captured here is orphaned
375
+ // once buildCustomPanel() rebuilds the panel.
376
+ customList = null;
377
+ fetchCustomList(function () { buildCustomPanel(); });
378
+ });
379
+ });
380
+ tile.appendChild(delBtn);
381
+
382
+ customGrid.appendChild(tile);
383
+ })(list[ci]);
384
+ }
385
+
386
+ if (list.length === 0) {
387
+ var emptyHint = document.createElement("div");
388
+ emptyHint.className = "emoji-picker-custom-empty";
389
+ emptyHint.textContent = "No custom icons yet — click + to upload";
390
+ emptyHint.style.gridColumn = "1 / -1";
391
+ customGrid.appendChild(emptyHint);
392
+ }
393
+ }
394
+
395
+ // Attach renderCustomGrid to the panel so switchCategory can re-invoke it
396
+ panel._renderCustomGrid = renderCustomGrid;
397
+
398
+ if (customList !== null) {
399
+ renderCustomGrid();
400
+ } else {
401
+ fetchCustomList(function () { renderCustomGrid(); });
402
+ }
403
+
404
+ grid.appendChild(panel);
405
+ scrollArea.scrollTop = 0;
406
+ }
407
+
165
408
  function switchCategory(idx) {
166
409
  currentCatIdx = idx;
167
410
  for (var j = 0; j < tabBtns.length; j++) {
168
411
  tabBtns[j].classList.toggle("active", j === idx);
169
412
  }
170
- if (_byGroup) {
171
- buildGrid(_byGroup[GROUP_META[idx].g] || []);
413
+ var meta = GROUP_META[idx];
414
+ if (meta.g === "custom") {
415
+ buildCustomPanel();
416
+ } else if (_byGroup) {
417
+ buildGrid(_byGroup[meta.g] || []);
418
+ }
419
+ }
420
+
421
+ function matchingCustomIcons(query) {
422
+ var list = customList || [];
423
+ var matches = [];
424
+ for (var i = 0; i < list.length; i++) {
425
+ if (matchesCustomIconQuery(list[i].slug, query)) matches.push(list[i]);
172
426
  }
427
+ return matches;
173
428
  }
174
429
 
175
430
  function showSearchResults(query) {
176
431
  tabBar.style.display = "none";
177
- buildGrid(searchEmojis(query));
432
+ var emojiMatches = searchEmojis(query);
433
+ if (customList === null) {
434
+ // Custom list not fetched yet (user hasn't opened the Custom tab this
435
+ // session) — show emoji matches immediately, then re-render with
436
+ // custom-icon matches once the list arrives so search never blocks on it.
437
+ buildGrid(emojiMatches, []);
438
+ fetchCustomList(function () {
439
+ if (searchInput.value.trim() === query.trim()) {
440
+ buildGrid(emojiMatches, matchingCustomIcons(query));
441
+ }
442
+ });
443
+ return;
444
+ }
445
+ buildGrid(emojiMatches, matchingCustomIcons(query));
178
446
  }
179
447
 
180
448
  function showCategory() {
@@ -0,0 +1,98 @@
1
+ /**
2
+ * history-visibility.js — shared source of truth for classifying a recorded
3
+ * history event as "renders a visible message" vs. an invisible-yield event.
4
+ * (lr-c24b)
5
+ *
6
+ * This is the ES module (browser) copy, used by app-header.js's
7
+ * prependOlderHistory / updateHistorySentinel to decide whether a prepended
8
+ * page surfaced any visible content. The CJS backend copy lives at
9
+ * lib/history-visibility.js. A test (test/history-visibility-parity.test.js)
10
+ * asserts both copies produce identical classifications so they cannot
11
+ * silently drift.
12
+ *
13
+ * When adding a new WS message type: check whether processMessage() in
14
+ * app-messages.js inserts a new visible element for it, then update BOTH
15
+ * this file and lib/history-visibility.js accordingly. The parity test will
16
+ * fail if they disagree.
17
+ */
18
+
19
+ // Tool names that render as hidden bookkeeping widgets (todo/task list state,
20
+ // plan-mode banners) — mirrors TODO_TOOLS / PLAN_MODE_TOOLS in tools.js and
21
+ // the tool_start branch in app-messages.js.
22
+ export var HIDDEN_TOOL_NAMES = {
23
+ TodoWrite: 1,
24
+ TaskCreate: 1,
25
+ TaskUpdate: 1,
26
+ TaskList: 1,
27
+ TaskGet: 1,
28
+ EnterPlanMode: 1,
29
+ ExitPlanMode: 1,
30
+ ask_user_questions: 1,
31
+ };
32
+
33
+ // Event types that never render a new visible message/bubble on their own —
34
+ // they update existing UI state (status text, badges, panels) or are pure
35
+ // internal bookkeeping. Matches the case branches in app-messages.js that
36
+ // call a state setter / no-op rather than a DOM-inserting render helper.
37
+ export var INVISIBLE_TYPES = {
38
+ message_uuid: 1,
39
+ session_id: 1,
40
+ status: 1,
41
+ compacting: 1,
42
+ thinking_start: 1,
43
+ thinking_delta: 1,
44
+ thinking_stop: 1,
45
+ ask_user_answered: 1,
46
+ permission_request: 1,
47
+ permission_request_pending: 1,
48
+ permission_cancel: 1,
49
+ permission_resolved: 1,
50
+ elicitation_request: 1,
51
+ elicitation_resolved: 1,
52
+ context_usage: 1,
53
+ fast_mode_state: 1,
54
+ rate_limit: 1,
55
+ rate_limit_usage: 1,
56
+ subagent_activity: 1,
57
+ subagent_tool: 1,
58
+ subagent_done: 1,
59
+ task_started: 1,
60
+ task_progress: 1,
61
+ task_updated: 1,
62
+ done: 1,
63
+ digest_checkpoint: 1,
64
+ };
65
+
66
+ // Event types whose visibility depends on the tool name carried in the event.
67
+ var TOOL_NAME_TYPES = {
68
+ tool_start: 1,
69
+ tool_executing: 1,
70
+ };
71
+
72
+ /**
73
+ * Returns true when `entry` (a single session.history[] item / WS message)
74
+ * causes app-messages.js's processMessage() to insert a new visible element
75
+ * into the message list. Returns false for state-only or hidden-bookkeeping
76
+ * events — the invisible-yield set that can dominate a raw-event-count page.
77
+ *
78
+ * entry is intentionally treated defensively: unknown/missing type defaults
79
+ * to visible (safe default — never under-counts and can't create a new
80
+ * zero-visible page shape that this module wasn't already guarding against).
81
+ */
82
+ export function isVisibleHistoryEvent(entry) {
83
+ if (!entry || typeof entry.type !== "string") return true;
84
+ var type = entry.type;
85
+
86
+ if (INVISIBLE_TYPES[type]) return false;
87
+
88
+ if (TOOL_NAME_TYPES[type]) {
89
+ return !HIDDEN_TOOL_NAMES[entry.name];
90
+ }
91
+
92
+ // tool_result carries only an id (no name) — it updates an existing tool
93
+ // card rather than inserting a new one, so it is never itself the reason
94
+ // a page becomes visible.
95
+ if (type === "tool_result") return false;
96
+
97
+ return true;
98
+ }