@useavalon/caelence-agent 0.2.3-canary.1 → 0.2.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/desktop/src/App.tsx +9 -2919
  2. package/desktop/src/BubbleClip.tsx +1 -1
  3. package/desktop/src/ComposerAttach.tsx +2 -2
  4. package/desktop/src/DeskBoot.tsx +28 -0
  5. package/desktop/src/DeskChrome.tsx +360 -0
  6. package/desktop/src/DeskComposer.tsx +311 -0
  7. package/desktop/src/DeskSidebar.tsx +191 -0
  8. package/desktop/src/FilesPanel.tsx +104 -36
  9. package/desktop/src/FloatNotice.test.ts +12 -0
  10. package/desktop/src/FloatNotice.tsx +5 -2
  11. package/desktop/src/IntegrationsPanel.tsx +273 -0
  12. package/desktop/src/McpPanel.tsx +8 -8
  13. package/desktop/src/MemoryPanel.tsx +138 -0
  14. package/desktop/src/QueuePanel.tsx +123 -0
  15. package/desktop/src/SessionsPanel.tsx +174 -0
  16. package/desktop/src/SettingsPanel.tsx +181 -0
  17. package/desktop/src/SkillsPanel.tsx +28 -12
  18. package/desktop/src/TranscriptViews.tsx +637 -0
  19. package/desktop/src/api.ts +36 -0
  20. package/desktop/src/app.css +159 -11
  21. package/desktop/src/composer-files.ts +2 -2
  22. package/desktop/src/desk-keys.ts +45 -0
  23. package/desktop/src/desk-prefs.ts +29 -0
  24. package/desktop/src/desk-types.ts +92 -0
  25. package/desktop/src/desktop-turn.ts +271 -0
  26. package/desktop/src/queue.ts +1 -1
  27. package/desktop/src/session-search.test.ts +20 -0
  28. package/desktop/src/session-search.ts +13 -0
  29. package/desktop/src/session-select.test.ts +23 -0
  30. package/desktop/src/session-select.ts +32 -0
  31. package/desktop/src/useDeskDictation.ts +123 -0
  32. package/desktop/src/useDeskFiles.ts +180 -0
  33. package/desktop/src/useDeskNotice.ts +20 -0
  34. package/desktop/src/useDeskPicker.ts +189 -0
  35. package/desktop/src/useDeskPrefs.ts +30 -0
  36. package/desktop/src/useDeskRuntime.ts +109 -0
  37. package/desktop/src/useDeskSessions.ts +195 -0
  38. package/desktop/src/useDeskSlash.ts +31 -0
  39. package/desktop/src/useDeskTurns.ts +264 -0
  40. package/desktop/src/useDesktopApp.ts +286 -0
  41. package/desktop/src/user-display.ts +2 -2
  42. package/package.json +2 -2
  43. package/src/desktop/bridge.test.ts +13 -0
  44. package/src/desktop/bridge.ts +45 -19
  45. package/src/desktop/uploads.test.ts +6 -0
  46. package/src/desktop/uploads.ts +178 -66
@@ -1,7 +1,15 @@
1
- import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ readdirSync,
5
+ readFileSync,
6
+ statSync,
7
+ unlinkSync,
8
+ writeFileSync,
9
+ } from "node:fs";
2
10
  import { homedir } from "node:os";
3
- import { isAbsolute, resolve } from "node:path";
4
- import { toProjectRel } from "../tools/paths.ts";
11
+ import { basename, isAbsolute, resolve } from "node:path";
12
+ import { resolveUnderCwd, toProjectRel } from "../tools/paths.ts";
5
13
  import { composeUploadMessage as buildUploadMessage } from "./upload-message.ts";
6
14
 
7
15
  export const MAX_UPLOADS = 8;
@@ -10,10 +18,51 @@ const TEXT_EXCERPT_BYTES = 100_000;
10
18
  const INDEX_NAME = "index.json";
11
19
  const MAX_LISTED = 40;
12
20
 
13
- const TEXT_MIME =
14
- /^(text\/|application\/(json|xml|javascript|sql|yaml|x-yaml|toml|x-sh|x-httpd-php))/i;
15
- const TEXT_EXT =
16
- /\.(txt|md|markdown|json|csv|tsv|ts|tsx|js|jsx|mjs|cjs|css|scss|html|htm|xml|yml|yaml|toml|py|rs|go|sh|bash|zsh|env|svg|log|ini|cfg)$/i;
21
+ const TEXT_MIME_PREFIXES = [
22
+ "text/",
23
+ "application/json",
24
+ "application/xml",
25
+ "application/javascript",
26
+ "application/sql",
27
+ "application/yaml",
28
+ "application/x-yaml",
29
+ "application/toml",
30
+ "application/x-sh",
31
+ "application/x-httpd-php",
32
+ ];
33
+ const TEXT_EXTS = new Set([
34
+ "txt",
35
+ "md",
36
+ "markdown",
37
+ "json",
38
+ "csv",
39
+ "tsv",
40
+ "ts",
41
+ "tsx",
42
+ "js",
43
+ "jsx",
44
+ "mjs",
45
+ "cjs",
46
+ "css",
47
+ "scss",
48
+ "html",
49
+ "htm",
50
+ "xml",
51
+ "yml",
52
+ "yaml",
53
+ "toml",
54
+ "py",
55
+ "rs",
56
+ "go",
57
+ "sh",
58
+ "bash",
59
+ "zsh",
60
+ "env",
61
+ "svg",
62
+ "log",
63
+ "ini",
64
+ "cfg",
65
+ ]);
17
66
 
18
67
  export interface IncomingUpload {
19
68
  name: string;
@@ -38,21 +87,25 @@ export interface UploadRecord {
38
87
  addedAt: string;
39
88
  }
40
89
 
90
+ function incomingFromUnknown(item: unknown): IncomingUpload | undefined {
91
+ if (!item || typeof item !== "object") return undefined;
92
+ const rec = item as Record<string, unknown>;
93
+ const name = typeof rec.name === "string" ? rec.name.trim() : "";
94
+ const data = typeof rec.data === "string" ? rec.data.trim() : "";
95
+ if (!name || !data) return undefined;
96
+ const mime =
97
+ typeof rec.mime === "string" && rec.mime.trim() ? rec.mime.trim() : "application/octet-stream";
98
+ const sourcePath = parseSourcePath(rec.sourcePath);
99
+ return { name, mime, data, ...(sourcePath ? { sourcePath } : {}) };
100
+ }
101
+
41
102
  export function parseIncomingUploads(raw: unknown): IncomingUpload[] {
42
103
  if (!Array.isArray(raw)) return [];
43
104
  const out: IncomingUpload[] = [];
44
105
  for (const item of raw) {
45
- if (!item || typeof item !== "object") continue;
46
- const rec = item as Record<string, unknown>;
47
- const name = typeof rec.name === "string" ? rec.name.trim() : "";
48
- const data = typeof rec.data === "string" ? rec.data.trim() : "";
49
- const mime =
50
- typeof rec.mime === "string" && rec.mime.trim()
51
- ? rec.mime.trim()
52
- : "application/octet-stream";
53
- if (!name || !data) continue;
54
- const sourcePath = parseSourcePath(rec.sourcePath);
55
- out.push({ name, mime, data, ...(sourcePath ? { sourcePath } : {}) });
106
+ const parsed = incomingFromUnknown(item);
107
+ if (!parsed) continue;
108
+ out.push(parsed);
56
109
  if (out.length >= MAX_UPLOADS) break;
57
110
  }
58
111
  return out;
@@ -61,7 +114,13 @@ export function parseIncomingUploads(raw: unknown): IncomingUpload[] {
61
114
  export function parseSourcePath(raw: unknown): string | undefined {
62
115
  if (typeof raw !== "string") return undefined;
63
116
  const trimmed = raw.trim();
64
- if (!trimmed || trimmed.includes("\0") || /\n|\r/.test(trimmed) || trimmed.length > 1024) {
117
+ if (
118
+ !trimmed ||
119
+ trimmed.includes("\0") ||
120
+ trimmed.includes("\n") ||
121
+ trimmed.includes("\r") ||
122
+ trimmed.length > 1024
123
+ ) {
65
124
  return undefined;
66
125
  }
67
126
  if (trimmed.startsWith("file://")) return undefined;
@@ -84,7 +143,11 @@ export function displaySourcePath(abs: string): string {
84
143
  }
85
144
 
86
145
  export function isTextUpload(name: string, mime: string): boolean {
87
- return TEXT_MIME.test(mime) || TEXT_EXT.test(name);
146
+ const lowerMime = mime.toLowerCase();
147
+ if (TEXT_MIME_PREFIXES.some((prefix) => lowerMime.startsWith(prefix))) return true;
148
+ const dot = name.lastIndexOf(".");
149
+ if (dot < 0) return false;
150
+ return TEXT_EXTS.has(name.slice(dot + 1).toLowerCase());
88
151
  }
89
152
 
90
153
  export function safeUploadName(name: string): string {
@@ -101,31 +164,28 @@ function storedDisplayName(filename: string): string {
101
164
  return filename.replace(/^\d+-\d+-/, "") || filename;
102
165
  }
103
166
 
167
+ function recordFromUnknown(item: unknown): UploadRecord | undefined {
168
+ if (!item || typeof item !== "object") return undefined;
169
+ const rec = item as Record<string, unknown>;
170
+ const name = typeof rec.name === "string" ? rec.name : "";
171
+ const rel = typeof rec.rel === "string" ? rec.rel : "";
172
+ if (!name || !rel) return undefined;
173
+ const mime = typeof rec.mime === "string" ? rec.mime : "application/octet-stream";
174
+ const addedAt = typeof rec.addedAt === "string" ? rec.addedAt : "";
175
+ const sourcePath = parseSourcePath(rec.sourcePath);
176
+ return { name, rel, mime, addedAt, ...(sourcePath ? { sourcePath } : {}) };
177
+ }
178
+
104
179
  function readIndex(dir: string): UploadRecord[] {
105
180
  try {
106
181
  const parsed: unknown = JSON.parse(readFileSync(resolve(dir, INDEX_NAME), "utf8"));
107
182
  if (!parsed || typeof parsed !== "object") return [];
108
183
  const files = (parsed as { files?: unknown }).files;
109
184
  if (!Array.isArray(files)) return [];
110
- const out: UploadRecord[] = [];
111
- for (const item of files) {
112
- if (!item || typeof item !== "object") continue;
113
- const rec = item as Record<string, unknown>;
114
- const name = typeof rec.name === "string" ? rec.name : "";
115
- const rel = typeof rec.rel === "string" ? rec.rel : "";
116
- if (!name || !rel) continue;
117
- const mime = typeof rec.mime === "string" ? rec.mime : "application/octet-stream";
118
- const addedAt = typeof rec.addedAt === "string" ? rec.addedAt : "";
119
- const sourcePath = parseSourcePath(rec.sourcePath);
120
- out.push({
121
- name,
122
- rel,
123
- mime,
124
- addedAt,
125
- ...(sourcePath ? { sourcePath } : {}),
126
- });
127
- }
128
- return out;
185
+ return files.flatMap((item) => {
186
+ const rec = recordFromUnknown(item);
187
+ return rec ? [rec] : [];
188
+ });
129
189
  } catch {
130
190
  return [];
131
191
  }
@@ -157,7 +217,7 @@ export function listUploads(cwd: string): UploadRecord[] {
157
217
  // no uploads folder yet
158
218
  }
159
219
  return [...byRel.values()]
160
- .sort((a, b) => (a.addedAt < b.addedAt ? 1 : a.addedAt > b.addedAt ? -1 : 0))
220
+ .sort((left, right) => right.addedAt.localeCompare(left.addedAt))
161
221
  .slice(0, MAX_LISTED);
162
222
  }
163
223
 
@@ -202,6 +262,41 @@ export function matchUploadEdit(
202
262
  return undefined;
203
263
  }
204
264
 
265
+ function existingSourcePath(raw: string | undefined): string | undefined {
266
+ if (!raw) return undefined;
267
+ const abs = expandSourcePath(raw);
268
+ return existsSync(abs) ? abs : undefined;
269
+ }
270
+
271
+ function excerptForUpload(item: IncomingUpload, bytes: Buffer): string | undefined {
272
+ if (!isTextUpload(item.name, item.mime) || bytes.byteLength > TEXT_EXCERPT_BYTES) {
273
+ return undefined;
274
+ }
275
+ return bytes.toString("utf8");
276
+ }
277
+
278
+ function writeOneUpload(
279
+ cwd: string,
280
+ dir: string,
281
+ item: IncomingUpload,
282
+ index: number,
283
+ ): SavedUpload | undefined {
284
+ const bytes = Buffer.from(item.data, "base64");
285
+ if (bytes.byteLength === 0 || bytes.byteLength > MAX_UPLOAD_BYTES) return undefined;
286
+ const unique = `${Date.now()}-${index}-${safeUploadName(item.name)}`;
287
+ const abs = resolve(dir, unique);
288
+ writeFileSync(abs, bytes);
289
+ const excerpt = excerptForUpload(item, bytes);
290
+ const sourcePath = existingSourcePath(item.sourcePath);
291
+ return {
292
+ name: item.name,
293
+ rel: toProjectRel(cwd, abs),
294
+ mime: item.mime,
295
+ ...(excerpt !== undefined ? { excerpt } : {}),
296
+ ...(sourcePath ? { sourcePath } : {}),
297
+ };
298
+ }
299
+
205
300
  export function saveUploads(cwd: string, items: IncomingUpload[]): SavedUpload[] {
206
301
  if (items.length === 0) return [];
207
302
  const dir = uploadsDir(cwd);
@@ -209,40 +304,57 @@ export function saveUploads(cwd: string, items: IncomingUpload[]): SavedUpload[]
209
304
  const saved: SavedUpload[] = [];
210
305
  const records = listUploads(cwd);
211
306
  for (const item of items) {
212
- const bytes = Buffer.from(item.data, "base64");
213
- if (bytes.byteLength === 0 || bytes.byteLength > MAX_UPLOAD_BYTES) continue;
214
- const unique = `${Date.now()}-${saved.length}-${safeUploadName(item.name)}`;
215
- const abs = resolve(dir, unique);
216
- writeFileSync(abs, bytes);
217
- const rel = toProjectRel(cwd, abs);
218
- const excerpt =
219
- isTextUpload(item.name, item.mime) && bytes.byteLength <= TEXT_EXCERPT_BYTES
220
- ? bytes.toString("utf8")
221
- : undefined;
222
- const sourcePath = item.sourcePath
223
- ? existsSync(expandSourcePath(item.sourcePath))
224
- ? expandSourcePath(item.sourcePath)
225
- : undefined
226
- : undefined;
227
- saved.push({
228
- name: item.name,
229
- rel,
230
- mime: item.mime,
231
- ...(excerpt !== undefined ? { excerpt } : {}),
232
- ...(sourcePath ? { sourcePath } : {}),
233
- });
307
+ const next = writeOneUpload(cwd, dir, item, saved.length);
308
+ if (!next) continue;
309
+ saved.push(next);
234
310
  records.unshift({
235
- name: item.name,
236
- rel,
237
- mime: item.mime,
311
+ name: next.name,
312
+ rel: next.rel,
313
+ mime: next.mime,
238
314
  addedAt: new Date().toISOString(),
239
- ...(sourcePath ? { sourcePath } : {}),
315
+ ...(next.sourcePath ? { sourcePath: next.sourcePath } : {}),
240
316
  });
241
317
  }
242
318
  writeIndex(dir, records.slice(0, MAX_LISTED));
243
319
  return saved;
244
320
  }
245
321
 
322
+ export function deleteUploads(cwd: string, rels: readonly string[]): UploadRecord[] {
323
+ const wanted = new Set(rels.filter((rel) => rel.trim().length > 0));
324
+ if (wanted.size === 0) return listUploads(cwd);
325
+ const dir = uploadsDir(cwd);
326
+ const keep: UploadRecord[] = [];
327
+ for (const item of listUploads(cwd)) {
328
+ if (!wanted.has(item.rel) || !isListedUploadRel(cwd, dir, item.rel)) {
329
+ keep.push(item);
330
+ continue;
331
+ }
332
+ try {
333
+ const abs = resolveUnderCwd(cwd, item.rel);
334
+ if (existsSync(abs) && statSync(abs).isFile()) unlinkSync(abs);
335
+ } catch {
336
+ keep.push(item);
337
+ }
338
+ }
339
+ try {
340
+ writeIndex(dir, keep);
341
+ } catch {
342
+ // no uploads folder
343
+ }
344
+ return keep;
345
+ }
346
+
347
+ function isListedUploadRel(cwd: string, dir: string, rel: string): boolean {
348
+ if (basename(rel) === INDEX_NAME) return false;
349
+ if (!rel.startsWith(".harness/uploads/") || rel.includes("\0")) return false;
350
+ try {
351
+ const abs = resolveUnderCwd(cwd, rel);
352
+ return abs.startsWith(`${dir}/`) && abs !== dir;
353
+ } catch {
354
+ return false;
355
+ }
356
+ }
357
+
246
358
  export function composeUploadMessage(text: string, files: SavedUpload[]): string {
247
359
  return buildUploadMessage(
248
360
  text,