clay-server 2.5.0

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -0
  3. package/bin/cli.js +2385 -0
  4. package/lib/cli-sessions.js +270 -0
  5. package/lib/config.js +237 -0
  6. package/lib/daemon.js +489 -0
  7. package/lib/ipc.js +112 -0
  8. package/lib/notes.js +120 -0
  9. package/lib/pages.js +664 -0
  10. package/lib/project.js +1433 -0
  11. package/lib/public/app.js +2795 -0
  12. package/lib/public/apple-touch-icon-dark.png +0 -0
  13. package/lib/public/apple-touch-icon.png +0 -0
  14. package/lib/public/css/base.css +264 -0
  15. package/lib/public/css/diff.css +128 -0
  16. package/lib/public/css/filebrowser.css +1114 -0
  17. package/lib/public/css/highlight.css +144 -0
  18. package/lib/public/css/icon-strip.css +296 -0
  19. package/lib/public/css/input.css +573 -0
  20. package/lib/public/css/menus.css +856 -0
  21. package/lib/public/css/messages.css +1445 -0
  22. package/lib/public/css/mobile-nav.css +354 -0
  23. package/lib/public/css/overlays.css +697 -0
  24. package/lib/public/css/rewind.css +505 -0
  25. package/lib/public/css/server-settings.css +761 -0
  26. package/lib/public/css/sidebar.css +936 -0
  27. package/lib/public/css/sticky-notes.css +358 -0
  28. package/lib/public/css/title-bar.css +314 -0
  29. package/lib/public/favicon-dark.svg +1 -0
  30. package/lib/public/favicon.svg +1 -0
  31. package/lib/public/icon-192-dark.png +0 -0
  32. package/lib/public/icon-192.png +0 -0
  33. package/lib/public/icon-512-dark.png +0 -0
  34. package/lib/public/icon-512.png +0 -0
  35. package/lib/public/icon-mono.svg +1 -0
  36. package/lib/public/index.html +762 -0
  37. package/lib/public/manifest.json +27 -0
  38. package/lib/public/modules/diff.js +398 -0
  39. package/lib/public/modules/events.js +21 -0
  40. package/lib/public/modules/filebrowser.js +1411 -0
  41. package/lib/public/modules/fileicons.js +172 -0
  42. package/lib/public/modules/icons.js +54 -0
  43. package/lib/public/modules/input.js +584 -0
  44. package/lib/public/modules/markdown.js +356 -0
  45. package/lib/public/modules/notifications.js +649 -0
  46. package/lib/public/modules/qrcode.js +70 -0
  47. package/lib/public/modules/rewind.js +345 -0
  48. package/lib/public/modules/server-settings.js +510 -0
  49. package/lib/public/modules/sidebar.js +1083 -0
  50. package/lib/public/modules/state.js +3 -0
  51. package/lib/public/modules/sticky-notes.js +688 -0
  52. package/lib/public/modules/terminal.js +697 -0
  53. package/lib/public/modules/theme.js +738 -0
  54. package/lib/public/modules/tools.js +1608 -0
  55. package/lib/public/modules/utils.js +56 -0
  56. package/lib/public/style.css +15 -0
  57. package/lib/public/sw.js +75 -0
  58. package/lib/push.js +124 -0
  59. package/lib/sdk-bridge.js +989 -0
  60. package/lib/server.js +582 -0
  61. package/lib/sessions.js +424 -0
  62. package/lib/terminal-manager.js +187 -0
  63. package/lib/terminal.js +24 -0
  64. package/lib/themes/ayu-light.json +9 -0
  65. package/lib/themes/catppuccin-latte.json +9 -0
  66. package/lib/themes/catppuccin-mocha.json +9 -0
  67. package/lib/themes/clay-light.json +10 -0
  68. package/lib/themes/clay.json +10 -0
  69. package/lib/themes/dracula.json +9 -0
  70. package/lib/themes/everforest-light.json +9 -0
  71. package/lib/themes/everforest.json +9 -0
  72. package/lib/themes/github-light.json +9 -0
  73. package/lib/themes/gruvbox-dark.json +9 -0
  74. package/lib/themes/gruvbox-light.json +9 -0
  75. package/lib/themes/monokai.json +9 -0
  76. package/lib/themes/nord-light.json +9 -0
  77. package/lib/themes/nord.json +9 -0
  78. package/lib/themes/one-dark.json +9 -0
  79. package/lib/themes/one-light.json +9 -0
  80. package/lib/themes/rose-pine-dawn.json +9 -0
  81. package/lib/themes/rose-pine.json +9 -0
  82. package/lib/themes/solarized-dark.json +9 -0
  83. package/lib/themes/solarized-light.json +9 -0
  84. package/lib/themes/tokyo-night-light.json +9 -0
  85. package/lib/themes/tokyo-night.json +9 -0
  86. package/lib/updater.js +97 -0
  87. package/package.json +47 -0
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "Clay",
3
+ "short_name": "Clay",
4
+ "id": "/",
5
+ "start_url": "/",
6
+ "scope": "/",
7
+ "display": "standalone",
8
+ "background_color": "#2F2E2B",
9
+ "theme_color": "#2F2E2B",
10
+ "icons": [
11
+ {
12
+ "src": "icon-192.png",
13
+ "sizes": "192x192",
14
+ "type": "image/png"
15
+ },
16
+ {
17
+ "src": "icon-512.png",
18
+ "sizes": "512x512",
19
+ "type": "image/png"
20
+ },
21
+ {
22
+ "src": "icon-mono.svg",
23
+ "sizes": "any",
24
+ "type": "image/svg+xml"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,398 @@
1
+ // diff.js - Shared diff module with LCS-based line diffing
2
+ // Produces unified and split diff views similar to GitHub
3
+
4
+ /**
5
+ * Compute LCS (Longest Common Subsequence) table for two arrays of lines.
6
+ * Returns a 2D table where table[i][j] = length of LCS of a[0..i-1] and b[0..j-1].
7
+ */
8
+ function lcsTable(a, b) {
9
+ var m = a.length;
10
+ var n = b.length;
11
+ // Use flat array for performance
12
+ var t = new Array((m + 1) * (n + 1));
13
+ var w = n + 1;
14
+ for (var i = 0; i <= m; i++) t[i * w] = 0;
15
+ for (var j = 0; j <= n; j++) t[j] = 0;
16
+ for (var i2 = 1; i2 <= m; i2++) {
17
+ for (var j2 = 1; j2 <= n; j2++) {
18
+ if (a[i2 - 1] === b[j2 - 1]) {
19
+ t[i2 * w + j2] = t[(i2 - 1) * w + (j2 - 1)] + 1;
20
+ } else {
21
+ var up = t[(i2 - 1) * w + j2];
22
+ var left = t[i2 * w + (j2 - 1)];
23
+ t[i2 * w + j2] = up > left ? up : left;
24
+ }
25
+ }
26
+ }
27
+ return { data: t, width: w };
28
+ }
29
+
30
+ /**
31
+ * Backtrack LCS table to produce a list of diff operations.
32
+ * Each op: { type: "equal"|"remove"|"add", oldLine, newLine, text }
33
+ */
34
+ function backtrack(a, b, table) {
35
+ var ops = [];
36
+ var t = table.data;
37
+ var w = table.width;
38
+ var i = a.length;
39
+ var j = b.length;
40
+
41
+ while (i > 0 || j > 0) {
42
+ if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
43
+ ops.push({ type: "equal", oldLine: i, newLine: j, text: a[i - 1] });
44
+ i--;
45
+ j--;
46
+ } else if (j > 0 && (i === 0 || t[(i) * w + (j - 1)] >= t[(i - 1) * w + j])) {
47
+ ops.push({ type: "add", oldLine: null, newLine: j, text: b[j - 1] });
48
+ j--;
49
+ } else {
50
+ ops.push({ type: "remove", oldLine: i, newLine: null, text: a[i - 1] });
51
+ i--;
52
+ }
53
+ }
54
+
55
+ ops.reverse();
56
+ return ops;
57
+ }
58
+
59
+ /**
60
+ * Compute line-level diff between two strings.
61
+ * Returns array of { type: "equal"|"remove"|"add", oldLine, newLine, text }
62
+ */
63
+ export function diffLines(oldStr, newStr) {
64
+ var a = oldStr ? oldStr.split("\n") : [];
65
+ var b = newStr ? newStr.split("\n") : [];
66
+ var table = lcsTable(a, b);
67
+ return backtrack(a, b, table);
68
+ }
69
+
70
+ /**
71
+ * Highlight all lines of a source string via hljs.
72
+ * Returns an array of HTML strings, one per line.
73
+ * Falls back to escaped text if hljs is unavailable or fails.
74
+ */
75
+ function highlightLines(src, lang) {
76
+ if (!lang || typeof hljs === "undefined" || !src) return null;
77
+ try {
78
+ var result = hljs.highlight(src, { language: lang });
79
+ return result.value.split("\n");
80
+ } catch (e) {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Build a map from line number (1-based) to highlighted HTML.
87
+ * oldMap[lineNum] = html, newMap[lineNum] = html
88
+ */
89
+ function buildHighlightMaps(oldStr, newStr, lang) {
90
+ if (!lang) return null;
91
+ var oldHL = highlightLines(oldStr, lang);
92
+ var newHL = highlightLines(newStr, lang);
93
+ if (!oldHL && !newHL) return null;
94
+ return { oldLines: oldHL, newLines: newHL };
95
+ }
96
+
97
+ /**
98
+ * Set cell content: use highlighted HTML if available, otherwise plain text.
99
+ */
100
+ function setCellContent(td, text, hlLines, lineNum) {
101
+ if (hlLines && lineNum != null && lineNum > 0 && lineNum <= hlLines.length) {
102
+ td.innerHTML = hlLines[lineNum - 1];
103
+ } else {
104
+ td.textContent = text;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Render a unified diff view (single column, +/- markers).
110
+ * Optional lang parameter enables syntax highlighting.
111
+ * Returns a DOM element.
112
+ */
113
+ export function renderUnifiedDiff(oldStr, newStr, lang) {
114
+ var ops = diffLines(oldStr, newStr);
115
+ var hl = buildHighlightMaps(oldStr, newStr, lang);
116
+ var container = document.createElement("div");
117
+ container.className = "diff-unified";
118
+
119
+ var table = document.createElement("table");
120
+ table.className = "diff-table";
121
+
122
+ for (var i = 0; i < ops.length; i++) {
123
+ var op = ops[i];
124
+ var tr = document.createElement("tr");
125
+ tr.className = "diff-row diff-row-" + op.type;
126
+
127
+ // Old line number
128
+ var tdOldLn = document.createElement("td");
129
+ tdOldLn.className = "diff-ln diff-ln-old";
130
+ tdOldLn.textContent = op.oldLine != null ? op.oldLine : "";
131
+
132
+ // New line number
133
+ var tdNewLn = document.createElement("td");
134
+ tdNewLn.className = "diff-ln diff-ln-new";
135
+ tdNewLn.textContent = op.newLine != null ? op.newLine : "";
136
+
137
+ // Marker
138
+ var tdMarker = document.createElement("td");
139
+ tdMarker.className = "diff-marker";
140
+ if (op.type === "remove") tdMarker.textContent = "-";
141
+ else if (op.type === "add") tdMarker.textContent = "+";
142
+ else tdMarker.textContent = " ";
143
+
144
+ // Code (with optional highlighting)
145
+ var tdCode = document.createElement("td");
146
+ tdCode.className = "diff-code";
147
+ if (hl) {
148
+ var hlSrc = (op.type === "add") ? hl.newLines : hl.oldLines;
149
+ var ln = (op.type === "add") ? op.newLine : op.oldLine;
150
+ setCellContent(tdCode, op.text, hlSrc, ln);
151
+ } else {
152
+ tdCode.textContent = op.text;
153
+ }
154
+
155
+ tr.appendChild(tdOldLn);
156
+ tr.appendChild(tdNewLn);
157
+ tr.appendChild(tdMarker);
158
+ tr.appendChild(tdCode);
159
+ table.appendChild(tr);
160
+ }
161
+
162
+ container.appendChild(table);
163
+ return container;
164
+ }
165
+
166
+ /**
167
+ * Render a split (side-by-side) diff view like GitHub.
168
+ * Optional lang parameter enables syntax highlighting.
169
+ * Returns a DOM element.
170
+ */
171
+ export function renderSplitDiff(oldStr, newStr, lang) {
172
+ var ops = diffLines(oldStr, newStr);
173
+ var hl = buildHighlightMaps(oldStr, newStr, lang);
174
+ var container = document.createElement("div");
175
+ container.className = "diff-split-view";
176
+
177
+ var table = document.createElement("table");
178
+ table.className = "diff-table diff-table-split";
179
+
180
+ // Group consecutive removes and adds into change blocks
181
+ var i = 0;
182
+ while (i < ops.length) {
183
+ var op = ops[i];
184
+
185
+ if (op.type === "equal") {
186
+ var tr = document.createElement("tr");
187
+ tr.className = "diff-row diff-row-equal";
188
+ appendSplitCells(tr, op.oldLine, op.text, op.newLine, op.text, hl);
189
+ table.appendChild(tr);
190
+ i++;
191
+ } else {
192
+ // Collect consecutive removes and adds
193
+ var removes = [];
194
+ var adds = [];
195
+ while (i < ops.length && ops[i].type === "remove") {
196
+ removes.push(ops[i]);
197
+ i++;
198
+ }
199
+ while (i < ops.length && ops[i].type === "add") {
200
+ adds.push(ops[i]);
201
+ i++;
202
+ }
203
+
204
+ // Pair them up row by row
205
+ var maxLen = Math.max(removes.length, adds.length);
206
+ for (var k = 0; k < maxLen; k++) {
207
+ var tr2 = document.createElement("tr");
208
+ var rm = k < removes.length ? removes[k] : null;
209
+ var ad = k < adds.length ? adds[k] : null;
210
+
211
+ if (rm && ad) {
212
+ tr2.className = "diff-row diff-row-change";
213
+ } else if (rm) {
214
+ tr2.className = "diff-row diff-row-remove";
215
+ } else {
216
+ tr2.className = "diff-row diff-row-add";
217
+ }
218
+
219
+ appendSplitCells(
220
+ tr2,
221
+ rm ? rm.oldLine : null,
222
+ rm ? rm.text : "",
223
+ ad ? ad.newLine : null,
224
+ ad ? ad.text : "",
225
+ hl
226
+ );
227
+ table.appendChild(tr2);
228
+ }
229
+ }
230
+ }
231
+
232
+ container.appendChild(table);
233
+ return container;
234
+ }
235
+
236
+ /**
237
+ * Render a pre-formatted patch/diff text (with @@, +, - markers) using table layout.
238
+ * Parses hunk headers for line numbers. Optional lang for syntax highlighting.
239
+ * Returns a DOM element.
240
+ */
241
+ export function renderPatchDiff(text, lang) {
242
+ var lines = text.split("\n");
243
+
244
+ // Reconstruct old and new source for highlighting
245
+ var oldSrc = [];
246
+ var newSrc = [];
247
+ for (var p = 0; p < lines.length; p++) {
248
+ var pl = lines[p];
249
+ if (pl.startsWith("-") && !pl.startsWith("---")) {
250
+ oldSrc.push(pl.substring(1));
251
+ } else if (pl.startsWith("+") && !pl.startsWith("+++")) {
252
+ newSrc.push(pl.substring(1));
253
+ } else if (pl.startsWith(" ")) {
254
+ oldSrc.push(pl.substring(1));
255
+ newSrc.push(pl.substring(1));
256
+ }
257
+ }
258
+ var oldHL = highlightLines(oldSrc.join("\n"), lang);
259
+ var newHL = highlightLines(newSrc.join("\n"), lang);
260
+ var oldHLIdx = 0;
261
+ var newHLIdx = 0;
262
+
263
+ var container = document.createElement("div");
264
+ container.className = "diff-unified";
265
+
266
+ var table = document.createElement("table");
267
+ table.className = "diff-table";
268
+
269
+ var oldLn = 0;
270
+ var newLn = 0;
271
+
272
+ for (var i = 0; i < lines.length; i++) {
273
+ var line = lines[i];
274
+
275
+ // Skip file headers
276
+ if (line.startsWith("---") || line.startsWith("+++")) continue;
277
+ // Skip "diff --git" lines
278
+ if (line.startsWith("diff ")) continue;
279
+ // Skip index lines
280
+ if (line.startsWith("index ")) continue;
281
+
282
+ // Hunk header: @@ -oldStart,oldLen +newStart,newLen @@
283
+ var hunkMatch = line.match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);
284
+ if (hunkMatch) {
285
+ oldLn = parseInt(hunkMatch[1], 10);
286
+ newLn = parseInt(hunkMatch[2], 10);
287
+
288
+ // Render hunk separator row
289
+ var tr = document.createElement("tr");
290
+ tr.className = "diff-row diff-row-hunk";
291
+ var tdLn1 = document.createElement("td");
292
+ tdLn1.className = "diff-ln";
293
+ var tdLn2 = document.createElement("td");
294
+ tdLn2.className = "diff-ln";
295
+ var tdMarker = document.createElement("td");
296
+ tdMarker.className = "diff-marker";
297
+ var tdCode = document.createElement("td");
298
+ tdCode.className = "diff-code diff-hunk-text";
299
+ tdCode.textContent = line;
300
+ tr.appendChild(tdLn1);
301
+ tr.appendChild(tdLn2);
302
+ tr.appendChild(tdMarker);
303
+ tr.appendChild(tdCode);
304
+ table.appendChild(tr);
305
+ continue;
306
+ }
307
+
308
+ var tr2 = document.createElement("tr");
309
+ var tdOldLn = document.createElement("td");
310
+ tdOldLn.className = "diff-ln diff-ln-old";
311
+ var tdNewLn = document.createElement("td");
312
+ tdNewLn.className = "diff-ln diff-ln-new";
313
+ var tdMark = document.createElement("td");
314
+ tdMark.className = "diff-marker";
315
+ var tdText = document.createElement("td");
316
+ tdText.className = "diff-code";
317
+
318
+ if (line.startsWith("-")) {
319
+ tr2.className = "diff-row diff-row-remove";
320
+ tdOldLn.textContent = oldLn;
321
+ tdMark.textContent = "-";
322
+ if (oldHL && oldHLIdx < oldHL.length) {
323
+ tdText.innerHTML = oldHL[oldHLIdx];
324
+ } else {
325
+ tdText.textContent = line.substring(1);
326
+ }
327
+ oldHLIdx++;
328
+ oldLn++;
329
+ } else if (line.startsWith("+")) {
330
+ tr2.className = "diff-row diff-row-add";
331
+ tdNewLn.textContent = newLn;
332
+ tdMark.textContent = "+";
333
+ if (newHL && newHLIdx < newHL.length) {
334
+ tdText.innerHTML = newHL[newHLIdx];
335
+ } else {
336
+ tdText.textContent = line.substring(1);
337
+ }
338
+ newHLIdx++;
339
+ newLn++;
340
+ } else if (line.startsWith(" ") || line === "") {
341
+ tr2.className = "diff-row diff-row-equal";
342
+ tdOldLn.textContent = oldLn;
343
+ tdNewLn.textContent = newLn;
344
+ tdMark.textContent = " ";
345
+ if (oldHL && oldHLIdx < oldHL.length) {
346
+ tdText.innerHTML = oldHL[oldHLIdx];
347
+ } else {
348
+ tdText.textContent = line.startsWith(" ") ? line.substring(1) : line;
349
+ }
350
+ oldHLIdx++;
351
+ newHLIdx++;
352
+ oldLn++;
353
+ newLn++;
354
+ } else {
355
+ // Unknown line, just render as context
356
+ tr2.className = "diff-row diff-row-equal";
357
+ tdText.textContent = line;
358
+ }
359
+
360
+ tr2.appendChild(tdOldLn);
361
+ tr2.appendChild(tdNewLn);
362
+ tr2.appendChild(tdMark);
363
+ tr2.appendChild(tdText);
364
+ table.appendChild(tr2);
365
+ }
366
+
367
+ container.appendChild(table);
368
+ return container;
369
+ }
370
+
371
+ function appendSplitCells(tr, oldLn, oldText, newLn, newText, hl) {
372
+ // Left side
373
+ var tdOldLn = document.createElement("td");
374
+ tdOldLn.className = "diff-ln";
375
+ tdOldLn.textContent = oldLn != null ? oldLn : "";
376
+
377
+ var tdOldCode = document.createElement("td");
378
+ tdOldCode.className = "diff-code diff-code-old";
379
+ if (oldLn != null) {
380
+ setCellContent(tdOldCode, oldText, hl ? hl.oldLines : null, oldLn);
381
+ }
382
+
383
+ // Right side
384
+ var tdNewLn = document.createElement("td");
385
+ tdNewLn.className = "diff-ln";
386
+ tdNewLn.textContent = newLn != null ? newLn : "";
387
+
388
+ var tdNewCode = document.createElement("td");
389
+ tdNewCode.className = "diff-code diff-code-new";
390
+ if (newLn != null) {
391
+ setCellContent(tdNewCode, newText, hl ? hl.newLines : null, newLn);
392
+ }
393
+
394
+ tr.appendChild(tdOldLn);
395
+ tr.appendChild(tdOldCode);
396
+ tr.appendChild(tdNewLn);
397
+ tr.appendChild(tdNewCode);
398
+ }
@@ -0,0 +1,21 @@
1
+ // EventBus — lightweight pub/sub for module decoupling
2
+ export class EventBus {
3
+ constructor() {
4
+ this._listeners = {};
5
+ }
6
+
7
+ on(event, fn) {
8
+ (this._listeners[event] || (this._listeners[event] = [])).push(fn);
9
+ return () => this.off(event, fn);
10
+ }
11
+
12
+ off(event, fn) {
13
+ var list = this._listeners[event];
14
+ if (list) this._listeners[event] = list.filter(f => f !== fn);
15
+ }
16
+
17
+ emit(event, data) {
18
+ var list = this._listeners[event];
19
+ if (list) list.forEach(fn => fn(data));
20
+ }
21
+ }