@clagentic/console 1.5.0 → 1.6.0-beta.2
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.
- package/README.md +23 -4
- package/bin/cli.js +15 -82
- package/lib/agents-favorites.js +21 -6
- package/lib/config.js +1 -1
- package/lib/daemon.js +153 -22
- package/lib/drain.js +213 -0
- package/lib/lite-detect.js +6 -5
- package/lib/loop-handoff.js +282 -0
- package/lib/mcp-local.js +18 -2
- package/lib/memory-limits.js +436 -0
- package/lib/model-context-windows.js +65 -0
- package/lib/project-loop.js +31 -3
- package/lib/project-sessions.js +26 -0
- package/lib/project-team.js +4 -1
- package/lib/project.js +8 -0
- package/lib/public/app.js +4 -0
- package/lib/public/css/base.css +18 -0
- package/lib/public/css/diagnostics.css +279 -0
- package/lib/public/css/icon-strip.css +201 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +24 -0
- package/lib/public/css/server-settings.css +100 -0
- package/lib/public/index.html +26 -0
- package/lib/public/modules/app-header.js +4 -7
- package/lib/public/modules/app-home-hub.js +31 -7
- package/lib/public/modules/app-messages.js +13 -0
- package/lib/public/modules/app-notifications.js +5 -1
- package/lib/public/modules/app-panels.js +11 -21
- package/lib/public/modules/app-projects.js +10 -5
- package/lib/public/modules/command-palette.js +16 -5
- package/lib/public/modules/custom-icons-settings.js +399 -0
- package/lib/public/modules/custom-icons.js +114 -0
- package/lib/public/modules/diagnostic-format.js +34 -0
- package/lib/public/modules/diagnostics.js +297 -0
- package/lib/public/modules/emoji-picker.js +253 -6
- package/lib/public/modules/model-context-windows.js +62 -0
- package/lib/public/modules/popover-position.js +192 -0
- package/lib/public/modules/project-icon.js +113 -0
- package/lib/public/modules/project-settings.js +2 -2
- package/lib/public/modules/project-switcher.js +2 -1
- package/lib/public/modules/scheduler-config.js +5 -8
- package/lib/public/modules/scheduler.js +5 -6
- package/lib/public/modules/server-settings.js +6 -0
- package/lib/public/modules/sidebar-mobile.js +4 -6
- package/lib/public/modules/sidebar-projects.js +35 -90
- package/lib/public/modules/sidebar-sessions.js +6 -20
- package/lib/public/modules/sticky-notes.js +4 -4
- package/lib/public/modules/terminal.js +5 -12
- package/lib/public/style.css +1 -0
- package/lib/sdk-bridge.js +75 -10
- package/lib/sdk-message-processor.js +12 -0
- package/lib/sdk-worker.js +4 -1
- package/lib/server-settings.js +221 -1
- package/lib/server.js +30 -1
- package/lib/sessions.js +27 -11
- package/lib/settings-preflight.js +212 -0
- package/lib/ws-schema.js +2 -0
- package/lib/yoke/adapters/claude-worker.js +14 -2
- package/lib/yoke/adapters/claude.js +16 -0
- package/lib/yoke/adapters/diagnostic-patterns.js +120 -0
- package/lib/yoke/index.js +4 -0
- package/lib/yoke/interface.js +99 -0
- package/package.json +2 -1
- package/scripts/postinstall.js +41 -0
- package/lib/certs/fullchain.pem +0 -47
- package/lib/certs/privkey.pem +0 -5
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// custom-icons-settings.js — Server Settings > Custom Icons management surface (lr-d1d9).
|
|
2
|
+
//
|
|
3
|
+
// Global-scope list/upload/rename/delete UI for the shared custom-icon
|
|
4
|
+
// namespace (lr-a68f). Reuses the shared upload/list/delete helpers from
|
|
5
|
+
// custom-icons.js (also used by emoji-picker.js) so the two surfaces never
|
|
6
|
+
// diverge, and renders thumbnails via renderProjectIcon() (DOM API, not
|
|
7
|
+
// innerHTML) for XSS parity with every other custom-icon render site.
|
|
8
|
+
//
|
|
9
|
+
// Usage ("Used by N") is computed entirely client-side from the already-cached
|
|
10
|
+
// project list + folder metadata — no server usage route exists or is needed.
|
|
11
|
+
//
|
|
12
|
+
// Rename is a daemon WS op (rename_custom_icon), not a bare HTTP route: file
|
|
13
|
+
// rename + config reference rewrite + projects_updated broadcast must be one
|
|
14
|
+
// atomic operation (see lib/daemon.js onRenameCustomIcon).
|
|
15
|
+
|
|
16
|
+
import { escapeHtml } from './utils.js';
|
|
17
|
+
import { refreshIcons, iconHtml } from './icons.js';
|
|
18
|
+
import { renderProjectIcon } from './project-icon.js';
|
|
19
|
+
import { fetchCustomIconList, uploadCustomIcon, deleteCustomIcon, slugifyFilename, matchesCustomIconQuery } from './custom-icons.js';
|
|
20
|
+
import { getCachedProjects, getCachedFolderMeta } from './app-projects.js';
|
|
21
|
+
|
|
22
|
+
var ctx = null;
|
|
23
|
+
var containerEl = null;
|
|
24
|
+
var cachedList = [];
|
|
25
|
+
var pendingRenameSlug = null; // slug currently being renamed inline, or null
|
|
26
|
+
var filterQuery = ""; // lr-0847: current text in #custom-icons-filter-input
|
|
27
|
+
|
|
28
|
+
export function initCustomIconsSettings(appCtx) {
|
|
29
|
+
ctx = appCtx;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Compute usage references for every custom-icon slug from the already-cached
|
|
34
|
+
* project list and folder metadata (client-side only — no server round trip).
|
|
35
|
+
*
|
|
36
|
+
* @returns {Object<string, {projects: string[], folders: string[]}>} keyed by slug
|
|
37
|
+
*/
|
|
38
|
+
function computeUsage() {
|
|
39
|
+
var usage = {};
|
|
40
|
+
function ensure(slug) {
|
|
41
|
+
if (!usage[slug]) usage[slug] = { projects: [], folders: [] };
|
|
42
|
+
return usage[slug];
|
|
43
|
+
}
|
|
44
|
+
function slugOf(iconStr) {
|
|
45
|
+
if (!iconStr || typeof iconStr !== "string") return null;
|
|
46
|
+
var m = /^:([a-z0-9_-]{1,64}):$/.exec(iconStr);
|
|
47
|
+
return m ? m[1] : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var projects = getCachedProjects() || [];
|
|
51
|
+
for (var i = 0; i < projects.length; i++) {
|
|
52
|
+
var slug = slugOf(projects[i].icon);
|
|
53
|
+
if (slug) ensure(slug).projects.push(projects[i].title || projects[i].project || projects[i].slug);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var folderMeta = getCachedFolderMeta() || {};
|
|
57
|
+
var folderNames = Object.keys(folderMeta);
|
|
58
|
+
for (var j = 0; j < folderNames.length; j++) {
|
|
59
|
+
var fSlug = slugOf(folderMeta[folderNames[j]] && folderMeta[folderNames[j]].icon);
|
|
60
|
+
if (fSlug) ensure(fSlug).folders.push(folderNames[j]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return usage;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function usageCount(usage, slug) {
|
|
67
|
+
var u = usage[slug];
|
|
68
|
+
if (!u) return 0;
|
|
69
|
+
return u.projects.length + u.folders.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function usageLabel(usage, slug) {
|
|
73
|
+
var u = usage[slug];
|
|
74
|
+
if (!u || (u.projects.length === 0 && u.folders.length === 0)) return null;
|
|
75
|
+
var names = u.projects.concat(u.folders.map(function (f) { return f + " (folder)"; }));
|
|
76
|
+
return names.join(", ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Load (or reload) the custom icons list and render it into the settings section.
|
|
81
|
+
*/
|
|
82
|
+
export function loadCustomIcons() {
|
|
83
|
+
var body = document.getElementById("custom-icons-list");
|
|
84
|
+
if (!body) return;
|
|
85
|
+
body.innerHTML = '<div class="admin-loading">Loading...</div>';
|
|
86
|
+
fetchCustomIconList().then(function (list) {
|
|
87
|
+
cachedList = list;
|
|
88
|
+
renderList();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatSize(bytes) {
|
|
93
|
+
if (typeof bytes !== "number") return "";
|
|
94
|
+
if (bytes >= 1048576) return (bytes / 1048576).toFixed(1) + " MB";
|
|
95
|
+
if (bytes >= 1024) return (bytes / 1024).toFixed(1) + " KB";
|
|
96
|
+
return bytes + " B";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function renderList() {
|
|
100
|
+
var body = document.getElementById("custom-icons-list");
|
|
101
|
+
if (!body) return;
|
|
102
|
+
containerEl = body;
|
|
103
|
+
var usage = computeUsage();
|
|
104
|
+
|
|
105
|
+
body.innerHTML = "";
|
|
106
|
+
|
|
107
|
+
if (cachedList.length === 0) {
|
|
108
|
+
var empty = document.createElement("div");
|
|
109
|
+
empty.className = "settings-hint";
|
|
110
|
+
empty.textContent = "No custom icons uploaded yet.";
|
|
111
|
+
body.appendChild(empty);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// lr-0847: filter by hyphen/underscore-segment match (shared with the
|
|
116
|
+
// emoji-picker Custom tab search via matchesCustomIconQuery) so this list
|
|
117
|
+
// and the picker never drift on tokenization the way upload error
|
|
118
|
+
// handling drifted between the two surfaces.
|
|
119
|
+
var visible = [];
|
|
120
|
+
for (var fi = 0; fi < cachedList.length; fi++) {
|
|
121
|
+
if (matchesCustomIconQuery(cachedList[fi].slug, filterQuery)) visible.push(cachedList[fi]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (visible.length === 0) {
|
|
125
|
+
var noMatch = document.createElement("div");
|
|
126
|
+
noMatch.className = "settings-hint";
|
|
127
|
+
noMatch.textContent = "No custom icons match \"" + filterQuery + "\".";
|
|
128
|
+
body.appendChild(noMatch);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var list = document.createElement("div");
|
|
133
|
+
list.className = "custom-icons-list";
|
|
134
|
+
|
|
135
|
+
for (var i = 0; i < visible.length; i++) {
|
|
136
|
+
list.appendChild(buildRow(visible[i], usage));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
body.appendChild(list);
|
|
140
|
+
refreshIcons(body);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function buildRow(entry, usage) {
|
|
144
|
+
var row = document.createElement("div");
|
|
145
|
+
row.className = "custom-icons-row";
|
|
146
|
+
row.dataset.slug = entry.slug;
|
|
147
|
+
|
|
148
|
+
// Thumbnail — rendered via renderProjectIcon (DOM <img>, not innerHTML).
|
|
149
|
+
var thumbWrap = document.createElement("span");
|
|
150
|
+
thumbWrap.className = "custom-icons-thumb";
|
|
151
|
+
// Cache-bust: the server serves custom-emoji bytes with an immutable
|
|
152
|
+
// Cache-Control header (server-settings.js), so a browser that already
|
|
153
|
+
// cached the old bytes for this slug (e.g. after an overwrite-upload) would
|
|
154
|
+
// otherwise keep showing stale pixels here. The query param busts that
|
|
155
|
+
// cache without touching the immutable-cache header itself.
|
|
156
|
+
renderProjectIcon(":" + entry.slug + ":", thumbWrap, null);
|
|
157
|
+
var img = thumbWrap.querySelector("img");
|
|
158
|
+
if (img) img.src = img.src + "?v=" + (entry.size || 0);
|
|
159
|
+
row.appendChild(thumbWrap);
|
|
160
|
+
|
|
161
|
+
// Meta: slug, size/type, usage badge
|
|
162
|
+
var meta = document.createElement("div");
|
|
163
|
+
meta.className = "custom-icons-meta";
|
|
164
|
+
|
|
165
|
+
var slugEl = document.createElement("div");
|
|
166
|
+
slugEl.className = "custom-icons-slug";
|
|
167
|
+
slugEl.textContent = ":" + entry.slug + ":";
|
|
168
|
+
meta.appendChild(slugEl);
|
|
169
|
+
|
|
170
|
+
var detailEl = document.createElement("div");
|
|
171
|
+
detailEl.className = "custom-icons-detail settings-hint";
|
|
172
|
+
var detailParts = [];
|
|
173
|
+
if (entry.ext) detailParts.push(entry.ext.toUpperCase());
|
|
174
|
+
if (typeof entry.size === "number") detailParts.push(formatSize(entry.size));
|
|
175
|
+
var count = usageCount(usage, entry.slug);
|
|
176
|
+
var label = usageLabel(usage, entry.slug);
|
|
177
|
+
detailParts.push("Used by " + count);
|
|
178
|
+
detailEl.textContent = detailParts.join(" · ");
|
|
179
|
+
if (label) detailEl.title = label;
|
|
180
|
+
meta.appendChild(detailEl);
|
|
181
|
+
|
|
182
|
+
row.appendChild(meta);
|
|
183
|
+
|
|
184
|
+
// Actions
|
|
185
|
+
var actions = document.createElement("div");
|
|
186
|
+
actions.className = "custom-icons-actions";
|
|
187
|
+
|
|
188
|
+
var renameBtn = document.createElement("button");
|
|
189
|
+
renameBtn.className = "settings-btn-sm";
|
|
190
|
+
renameBtn.innerHTML = iconHtml("pencil");
|
|
191
|
+
renameBtn.title = "Rename";
|
|
192
|
+
renameBtn.addEventListener("click", function () { startRename(entry.slug, row, usage); });
|
|
193
|
+
actions.appendChild(renameBtn);
|
|
194
|
+
|
|
195
|
+
var deleteBtn = document.createElement("button");
|
|
196
|
+
deleteBtn.className = "settings-btn-sm settings-btn-danger";
|
|
197
|
+
deleteBtn.innerHTML = iconHtml("trash-2");
|
|
198
|
+
deleteBtn.title = "Delete";
|
|
199
|
+
deleteBtn.addEventListener("click", function () { confirmDelete(entry.slug, usage); });
|
|
200
|
+
actions.appendChild(deleteBtn);
|
|
201
|
+
|
|
202
|
+
row.appendChild(actions);
|
|
203
|
+
return row;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function startRename(oldSlug, row, usage) {
|
|
207
|
+
if (pendingRenameSlug) return; // one inline rename at a time
|
|
208
|
+
pendingRenameSlug = oldSlug;
|
|
209
|
+
|
|
210
|
+
var slugEl = row.querySelector(".custom-icons-slug");
|
|
211
|
+
if (!slugEl) return;
|
|
212
|
+
var originalText = slugEl.textContent;
|
|
213
|
+
|
|
214
|
+
var form = document.createElement("div");
|
|
215
|
+
form.className = "custom-icons-rename-form";
|
|
216
|
+
var input = document.createElement("input");
|
|
217
|
+
input.type = "text";
|
|
218
|
+
input.maxLength = 64;
|
|
219
|
+
input.spellcheck = false;
|
|
220
|
+
input.autocomplete = "off";
|
|
221
|
+
input.value = oldSlug;
|
|
222
|
+
input.className = "custom-icons-rename-input";
|
|
223
|
+
var okBtn = document.createElement("button");
|
|
224
|
+
okBtn.className = "settings-btn-sm primary";
|
|
225
|
+
okBtn.textContent = "Save";
|
|
226
|
+
var cancelBtn = document.createElement("button");
|
|
227
|
+
cancelBtn.className = "settings-btn-sm settings-btn-ghost";
|
|
228
|
+
cancelBtn.textContent = "Cancel";
|
|
229
|
+
var errorEl = document.createElement("div");
|
|
230
|
+
errorEl.className = "settings-hint custom-icons-rename-error hidden";
|
|
231
|
+
|
|
232
|
+
form.appendChild(input);
|
|
233
|
+
form.appendChild(okBtn);
|
|
234
|
+
form.appendChild(cancelBtn);
|
|
235
|
+
|
|
236
|
+
slugEl.replaceWith(form);
|
|
237
|
+
row.appendChild(errorEl);
|
|
238
|
+
input.focus();
|
|
239
|
+
input.select();
|
|
240
|
+
|
|
241
|
+
function endRename() {
|
|
242
|
+
pendingRenameSlug = null;
|
|
243
|
+
form.replaceWith(slugEl);
|
|
244
|
+
slugEl.textContent = originalText;
|
|
245
|
+
errorEl.remove();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function submitRename() {
|
|
249
|
+
var newSlug = input.value.trim().toLowerCase()
|
|
250
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
251
|
+
.replace(/^-+|-+$/g, "")
|
|
252
|
+
.slice(0, 64);
|
|
253
|
+
if (!newSlug || !/^[a-z0-9_-]{1,64}$/.test(newSlug)) {
|
|
254
|
+
errorEl.textContent = "Invalid slug — use lowercase letters, numbers, dashes, underscores.";
|
|
255
|
+
errorEl.classList.remove("hidden");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (newSlug === oldSlug) { endRename(); return; }
|
|
259
|
+
|
|
260
|
+
var label = usageLabel(usage, oldSlug);
|
|
261
|
+
var count = usageCount(usage, oldSlug);
|
|
262
|
+
if (count > 0) {
|
|
263
|
+
var proceed = window.confirm(
|
|
264
|
+
":" + oldSlug + ": is used by " + count + " item" + (count === 1 ? "" : "s") +
|
|
265
|
+
(label ? " (" + label + ")" : "") +
|
|
266
|
+
". Renaming will update all references to :" + newSlug + ":. Continue?"
|
|
267
|
+
);
|
|
268
|
+
if (!proceed) return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
okBtn.disabled = true;
|
|
272
|
+
sendRename(oldSlug, newSlug).then(function (result) {
|
|
273
|
+
okBtn.disabled = false;
|
|
274
|
+
if (!result.ok) {
|
|
275
|
+
errorEl.textContent = result.error || "Rename failed";
|
|
276
|
+
errorEl.classList.remove("hidden");
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
pendingRenameSlug = null;
|
|
280
|
+
loadCustomIcons();
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
okBtn.addEventListener("click", function (e) { e.stopPropagation(); submitRename(); });
|
|
285
|
+
cancelBtn.addEventListener("click", function (e) { e.stopPropagation(); endRename(); });
|
|
286
|
+
input.addEventListener("keydown", function (e) {
|
|
287
|
+
e.stopPropagation();
|
|
288
|
+
if (e.key === "Enter") { e.preventDefault(); submitRename(); }
|
|
289
|
+
if (e.key === "Escape") { e.preventDefault(); endRename(); }
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// In-flight rename WS round-trip, keyed so a stray late reply can't resolve
|
|
294
|
+
// a newer request's promise.
|
|
295
|
+
var _pendingRenameResolvers = {};
|
|
296
|
+
var _renameReqSeq = 0;
|
|
297
|
+
|
|
298
|
+
function sendRename(oldSlug, newSlug) {
|
|
299
|
+
return new Promise(function (resolve) {
|
|
300
|
+
var ws = ctx && ctx.ws;
|
|
301
|
+
if (!ws || ws.readyState !== 1) {
|
|
302
|
+
resolve({ ok: false, error: "Not connected" });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
var reqId = ++_renameReqSeq;
|
|
306
|
+
_pendingRenameResolvers[reqId] = resolve;
|
|
307
|
+
ws.send(JSON.stringify({ type: "rename_custom_icon", oldSlug: oldSlug, newSlug: newSlug, _reqId: reqId }));
|
|
308
|
+
// Safety timeout — don't leave the UI spinner stuck if the daemon never replies.
|
|
309
|
+
setTimeout(function () {
|
|
310
|
+
if (_pendingRenameResolvers[reqId]) {
|
|
311
|
+
delete _pendingRenameResolvers[reqId];
|
|
312
|
+
resolve({ ok: false, error: "Rename timed out" });
|
|
313
|
+
}
|
|
314
|
+
}, 10000);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Handle the rename_custom_icon_result WS message (wired from app-messages.js).
|
|
320
|
+
*/
|
|
321
|
+
export function handleRenameCustomIconResult(msg) {
|
|
322
|
+
var reqId = msg._reqId;
|
|
323
|
+
if (reqId && _pendingRenameResolvers[reqId]) {
|
|
324
|
+
var resolve = _pendingRenameResolvers[reqId];
|
|
325
|
+
delete _pendingRenameResolvers[reqId];
|
|
326
|
+
resolve(msg);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
// No matching in-flight request (e.g. reload happened) — still refresh the
|
|
330
|
+
// list so the UI doesn't show stale data if the rename succeeded elsewhere.
|
|
331
|
+
if (msg.ok) loadCustomIcons();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function confirmDelete(slug, usage) {
|
|
335
|
+
var count = usageCount(usage, slug);
|
|
336
|
+
var label = usageLabel(usage, slug);
|
|
337
|
+
var message = "Delete :" + slug + ":?";
|
|
338
|
+
if (count > 0) {
|
|
339
|
+
message += " It is used by " + count + " item" + (count === 1 ? "" : "s") +
|
|
340
|
+
(label ? " (" + label + ")" : "") +
|
|
341
|
+
". Those references will show a fallback icon after deletion — this cannot be undone.";
|
|
342
|
+
}
|
|
343
|
+
if (!window.confirm(message)) return;
|
|
344
|
+
deleteCustomIcon(slug).then(function () { loadCustomIcons(); });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// --- Upload ---
|
|
348
|
+
|
|
349
|
+
function handleUploadFile(file) {
|
|
350
|
+
if (!file) return;
|
|
351
|
+
var suggested = slugifyFilename(file.name);
|
|
352
|
+
var slug = window.prompt("Slug for this icon (letters, numbers, dashes, underscores):", suggested);
|
|
353
|
+
if (slug === null) return; // cancelled
|
|
354
|
+
slug = slug.trim().toLowerCase()
|
|
355
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
356
|
+
.replace(/^-+|-+$/g, "")
|
|
357
|
+
.slice(0, 64);
|
|
358
|
+
if (!slug || !/^[a-z0-9_-]{1,64}$/.test(slug)) {
|
|
359
|
+
window.alert("Invalid slug.");
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
var hasDup = cachedList.some(function (e) { return e.slug === slug; });
|
|
363
|
+
if (hasDup && !window.confirm(":" + slug + ": already exists — overwrite?")) return;
|
|
364
|
+
|
|
365
|
+
uploadCustomIcon(slug, file).then(function (result) {
|
|
366
|
+
if (!result.ok) {
|
|
367
|
+
window.alert(result.error || "Upload failed");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
loadCustomIcons();
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Wire the Upload button + hidden file input, and the slug filter box
|
|
376
|
+
* (lr-0847). Called once from server-settings.js's initServerSettings
|
|
377
|
+
* (idempotent — safe if elements are absent, e.g. in tests without the full
|
|
378
|
+
* DOM).
|
|
379
|
+
*/
|
|
380
|
+
export function initCustomIconsUpload() {
|
|
381
|
+
var uploadBtn = document.getElementById("custom-icons-upload-btn");
|
|
382
|
+
var fileInput = document.getElementById("custom-icons-file-input");
|
|
383
|
+
if (uploadBtn && fileInput) {
|
|
384
|
+
uploadBtn.addEventListener("click", function () { fileInput.click(); });
|
|
385
|
+
fileInput.addEventListener("change", function () {
|
|
386
|
+
var file = fileInput.files && fileInput.files[0];
|
|
387
|
+
fileInput.value = "";
|
|
388
|
+
handleUploadFile(file);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
var filterInput = document.getElementById("custom-icons-filter-input");
|
|
393
|
+
if (filterInput) {
|
|
394
|
+
filterInput.addEventListener("input", function () {
|
|
395
|
+
filterQuery = filterInput.value;
|
|
396
|
+
renderList();
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// custom-icons.js — Shared client-side helper for the global custom-icon
|
|
2
|
+
// namespace (lr-a68f). Extracted from emoji-picker.js (lr-d1d9) so the emoji
|
|
3
|
+
// picker's "Custom" panel and the Server Settings > Custom Icons management
|
|
4
|
+
// surface share one implementation of slugify/list-fetch/upload/delete
|
|
5
|
+
// instead of maintaining two copies that can drift.
|
|
6
|
+
//
|
|
7
|
+
// DOM-free: safe to import from both browser modules and Node test files.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Derive a slug candidate from an uploaded filename: strip extension,
|
|
11
|
+
* lowercase, collapse anything outside [a-z0-9_-] into a single dash,
|
|
12
|
+
* trim leading/trailing dashes, cap at 64 chars. Falls back to "custom"
|
|
13
|
+
* if the result would be empty (e.g. an all-symbol filename).
|
|
14
|
+
*
|
|
15
|
+
* Mirrors the server's SLUG_RE (^[a-z0-9_-]{1,64}$) — the caller must still
|
|
16
|
+
* validate the final (possibly user-edited) slug against that pattern
|
|
17
|
+
* before uploading, since this is only a best-effort starting suggestion.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} filename
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
export function slugifyFilename(filename) {
|
|
23
|
+
var base = String(filename || "").replace(/\.[^.]+$/, "").toLowerCase()
|
|
24
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
25
|
+
.replace(/^-+|-+$/g, "")
|
|
26
|
+
.slice(0, 64);
|
|
27
|
+
return base || "custom";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the full list of custom-icon uploads.
|
|
32
|
+
* Resolves to [] on any network/parse error rather than rejecting, so
|
|
33
|
+
* callers can render an empty state without a try/catch at every call site.
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<Array<{slug: string, url: string, size?: number, ext?: string}>>}
|
|
36
|
+
*/
|
|
37
|
+
export function fetchCustomIconList() {
|
|
38
|
+
return fetch("/api/custom-emoji")
|
|
39
|
+
.then(function (r) { return r.json(); })
|
|
40
|
+
.then(function (data) { return Array.isArray(data) ? data : []; })
|
|
41
|
+
.catch(function () { return []; });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Upload a File/Blob as a new (or replacement) custom icon under the given
|
|
46
|
+
* slug. Caller is responsible for slug validation/confirmation UX (e.g. the
|
|
47
|
+
* duplicate-overwrite confirm dialog in emoji-picker.js) before calling this.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} slug
|
|
50
|
+
* @param {File|Blob} file
|
|
51
|
+
* @returns {Promise<{ok: boolean, slug?: string, url?: string, error?: string}>}
|
|
52
|
+
*/
|
|
53
|
+
export function uploadCustomIcon(slug, file) {
|
|
54
|
+
return new Promise(function (resolve) {
|
|
55
|
+
var reader = new FileReader();
|
|
56
|
+
reader.onload = function (ev) {
|
|
57
|
+
fetch("/api/custom-emoji/" + encodeURIComponent(slug), {
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: ev.target.result,
|
|
60
|
+
}).then(function (r) {
|
|
61
|
+
if (!r.ok) {
|
|
62
|
+
return r.json().catch(function () { return {}; }).then(function (body) {
|
|
63
|
+
resolve({ ok: false, error: (body && body.error) || "Upload failed" });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return r.json().then(function (body) { resolve(Object.assign({ ok: true }, body)); });
|
|
67
|
+
}).catch(function () {
|
|
68
|
+
resolve({ ok: false, error: "Upload failed" });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
reader.onerror = function () { resolve({ ok: false, error: "Failed to read file" }); };
|
|
72
|
+
reader.readAsArrayBuffer(file);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Delete a custom icon by slug.
|
|
78
|
+
* @param {string} slug
|
|
79
|
+
* @returns {Promise<{ok: boolean}>}
|
|
80
|
+
*/
|
|
81
|
+
export function deleteCustomIcon(slug) {
|
|
82
|
+
return fetch("/api/custom-emoji/" + encodeURIComponent(slug), { method: "DELETE" })
|
|
83
|
+
.then(function () { return { ok: true }; })
|
|
84
|
+
.catch(function () { return { ok: false }; });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Test whether a custom-icon slug matches a search query (lr-0847).
|
|
89
|
+
*
|
|
90
|
+
* Matches if the query is a substring of the whole slug OR a substring of
|
|
91
|
+
* any hyphen/underscore-delimited segment. Whole-slug substring match alone
|
|
92
|
+
* already covers segment prefixes (e.g. "clage" -> "clagentic-console"),
|
|
93
|
+
* but NOT a later segment on its own (e.g. "console" was previously unable
|
|
94
|
+
* to match "clagentic-console" since custom icons had no search wiring at
|
|
95
|
+
* all — this is the shared match rule for both the emoji-picker Custom tab
|
|
96
|
+
* search and the Server Settings > Custom Icons list filter, so the two
|
|
97
|
+
* surfaces can't drift on tokenization the way they drifted on upload
|
|
98
|
+
* error handling).
|
|
99
|
+
*
|
|
100
|
+
* @param {string} slug
|
|
101
|
+
* @param {string} query
|
|
102
|
+
* @returns {boolean}
|
|
103
|
+
*/
|
|
104
|
+
export function matchesCustomIconQuery(slug, query) {
|
|
105
|
+
var q = String(query || "").toLowerCase().trim();
|
|
106
|
+
if (!q) return true;
|
|
107
|
+
var s = String(slug || "").toLowerCase();
|
|
108
|
+
if (s.indexOf(q) !== -1) return true;
|
|
109
|
+
var segments = s.split(/[-_]+/);
|
|
110
|
+
for (var i = 0; i < segments.length; i++) {
|
|
111
|
+
if (segments[i].indexOf(q) !== -1) return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// diagnostic-format.js — Pure formatting helpers for diagnostic messages.
|
|
2
|
+
// No DOM dependencies; importable in unit tests directly.
|
|
3
|
+
// Part of epic lr-1a52 stage 4/5 (lr-8294).
|
|
4
|
+
|
|
5
|
+
// Human-readable labels for known diagnostic source identifiers.
|
|
6
|
+
// Sources from stage 5/5 (lr-1a26) preflight may add new entries here;
|
|
7
|
+
// the default falls back to the raw source string.
|
|
8
|
+
var SOURCE_LABELS = {
|
|
9
|
+
hook: "Hook",
|
|
10
|
+
cli: "CLI",
|
|
11
|
+
settings: "Settings",
|
|
12
|
+
stderr: "CLI",
|
|
13
|
+
preflight: "Preflight",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Format a raw diagnostic source identifier for display.
|
|
18
|
+
* @param {string} source - The source field from the diagnostic message.
|
|
19
|
+
* @returns {string} Human-readable source label.
|
|
20
|
+
*/
|
|
21
|
+
export function formatDiagnosticSource(source) {
|
|
22
|
+
if (!source) return "Diagnostic";
|
|
23
|
+
return SOURCE_LABELS[source] || source;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Map severity to a short display label.
|
|
28
|
+
* @param {string} severity - 'info' | 'warning' | 'error'
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function formatDiagnosticSeverity(severity) {
|
|
32
|
+
if (!severity) return "INFO";
|
|
33
|
+
return severity.toUpperCase();
|
|
34
|
+
}
|