@useavalon/caelence-agent 0.2.3-canary.0 → 0.2.3-canary.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.
Files changed (67) hide show
  1. package/README.md +7 -0
  2. package/desktop/src/App.tsx +9 -2919
  3. package/desktop/src/BubbleClip.tsx +1 -1
  4. package/desktop/src/ComposerAttach.tsx +2 -2
  5. package/desktop/src/DeskBoot.tsx +28 -0
  6. package/desktop/src/DeskChrome.tsx +360 -0
  7. package/desktop/src/DeskComposer.tsx +311 -0
  8. package/desktop/src/DeskSidebar.tsx +191 -0
  9. package/desktop/src/FilesPanel.tsx +104 -36
  10. package/desktop/src/FloatNotice.test.ts +12 -0
  11. package/desktop/src/FloatNotice.tsx +5 -2
  12. package/desktop/src/IntegrationsPanel.tsx +273 -0
  13. package/desktop/src/McpPanel.tsx +8 -8
  14. package/desktop/src/MemoryPanel.tsx +138 -0
  15. package/desktop/src/QueuePanel.tsx +123 -0
  16. package/desktop/src/SessionsPanel.tsx +174 -0
  17. package/desktop/src/SettingsPanel.tsx +181 -0
  18. package/desktop/src/SkillsPanel.tsx +28 -12
  19. package/desktop/src/TranscriptViews.tsx +637 -0
  20. package/desktop/src/api.ts +36 -0
  21. package/desktop/src/app.css +159 -11
  22. package/desktop/src/composer-files.ts +2 -2
  23. package/desktop/src/desk-keys.ts +45 -0
  24. package/desktop/src/desk-prefs.ts +29 -0
  25. package/desktop/src/desk-types.ts +92 -0
  26. package/desktop/src/desktop-turn.ts +271 -0
  27. package/desktop/src/preview-render.ts +322 -36
  28. package/desktop/src/queue.ts +1 -1
  29. package/desktop/src/session-search.test.ts +20 -0
  30. package/desktop/src/session-search.ts +13 -0
  31. package/desktop/src/session-select.test.ts +23 -0
  32. package/desktop/src/session-select.ts +32 -0
  33. package/desktop/src/useDeskDictation.ts +123 -0
  34. package/desktop/src/useDeskFiles.ts +180 -0
  35. package/desktop/src/useDeskNotice.ts +20 -0
  36. package/desktop/src/useDeskPicker.ts +189 -0
  37. package/desktop/src/useDeskPrefs.ts +30 -0
  38. package/desktop/src/useDeskRuntime.ts +109 -0
  39. package/desktop/src/useDeskSessions.ts +195 -0
  40. package/desktop/src/useDeskSlash.ts +31 -0
  41. package/desktop/src/useDeskTurns.ts +264 -0
  42. package/desktop/src/useDesktopApp.ts +286 -0
  43. package/desktop/src/user-display.ts +2 -2
  44. package/package.json +2 -2
  45. package/src/cli/openrouter-live.ts +30 -21
  46. package/src/cli/slash-dispatch.test.ts +25 -0
  47. package/src/cli/slash-dispatch.ts +41 -0
  48. package/src/cli/slash.ts +1 -0
  49. package/src/config.ts +10 -1
  50. package/src/core/run-turn.test.ts +3 -0
  51. package/src/core/run-turn.ts +74 -41
  52. package/src/desktop/bridge.test.ts +43 -0
  53. package/src/desktop/bridge.ts +91 -19
  54. package/src/desktop/uploads.test.ts +6 -0
  55. package/src/desktop/uploads.ts +178 -66
  56. package/src/index.ts +13 -0
  57. package/src/integrations/remote-mcp.ts +51 -21
  58. package/src/memory/extract.test.ts +81 -0
  59. package/src/memory/extract.ts +88 -0
  60. package/src/memory/prefs.test.ts +53 -0
  61. package/src/memory/prefs.ts +47 -0
  62. package/src/memory/prompt.ts +24 -0
  63. package/src/memory/store.test.ts +191 -0
  64. package/src/memory/store.ts +382 -0
  65. package/src/runtime.test.ts +37 -0
  66. package/src/runtime.ts +29 -1
  67. package/src/tools/local.ts +86 -39
@@ -1,6 +1,6 @@
1
1
  import { CaretDownIcon } from "@phosphor-icons/react/dist/csr/CaretDown";
2
2
  import { type ReactElement, type ReactNode, useLayoutEffect, useRef, useState } from "react";
3
- import { clipLineHeight, clipNeedsExpand, collapsedClipLimit } from "./clip.ts";
3
+ import { clipLineHeight, clipNeedsExpand, collapsedClipLimit } from "./clip";
4
4
 
5
5
  export function BubbleClip(
6
6
  props: Readonly<{
@@ -1,7 +1,7 @@
1
1
  import { FileIcon as FileGlyph } from "@phosphor-icons/react/dist/csr/File";
2
2
  import { XIcon } from "@phosphor-icons/react/dist/csr/X";
3
- import type { AttachmentPreview, ComposerFileKind } from "./composer-files.ts";
4
- import { fileExtension } from "./composer-files.ts";
3
+ import type { AttachmentPreview, ComposerFileKind } from "./composer-files";
4
+ import { fileExtension } from "./composer-files";
5
5
 
6
6
  export function AttachmentThumbs(
7
7
  props: Readonly<{
@@ -0,0 +1,28 @@
1
+ import { LogoMark } from "./LogoMark";
2
+
3
+ export function DeskBoot(props: Readonly<{ error?: string }>): React.ReactElement {
4
+ return (
5
+ <div className="desk desk--boot">
6
+ <header className="desk-bar">
7
+ <LogoMark size={20} />
8
+ <h1>Caelence</h1>
9
+ {props.error ? null : (
10
+ <span className="cel-chip cel-chip--run">
11
+ <span className="cel-chip__spin" aria-hidden="true" />
12
+ {"Starting"}
13
+ </span>
14
+ )}
15
+ </header>
16
+ <main className="desk-empty">
17
+ {props.error ? (
18
+ <>
19
+ <p>{props.error}</p>
20
+ <p>Open this UI from the Caelence agent window, not a browser tab.</p>
21
+ </>
22
+ ) : (
23
+ <p>Starting the local runtime</p>
24
+ )}
25
+ </main>
26
+ </div>
27
+ );
28
+ }
@@ -0,0 +1,360 @@
1
+ import { PencilSimpleIcon } from "@phosphor-icons/react/dist/csr/PencilSimple";
2
+ import { TrashIcon } from "@phosphor-icons/react/dist/csr/Trash";
3
+ import {
4
+ type BridgeClient,
5
+ type DesktopState,
6
+ deleteUploads,
7
+ openLocalFile,
8
+ type PickerItem,
9
+ } from "./api";
10
+ import { DeskComposer } from "./DeskComposer";
11
+ import { DeskSidebar } from "./DeskSidebar";
12
+ import {
13
+ isUploadEditPending,
14
+ type MainView,
15
+ mainViewTitle,
16
+ type PendingApproval,
17
+ type ShowNotice,
18
+ type ThemeChoice,
19
+ } from "./desk-types";
20
+ import { FilesPanel, homePath } from "./FilesPanel";
21
+ import { FloatNotice } from "./FloatNotice";
22
+ import { IntegrationsPanel } from "./IntegrationsPanel";
23
+ import { MemoryPanel } from "./MemoryPanel";
24
+ import { SessionsPanel } from "./SessionsPanel";
25
+ import { SettingsPanel } from "./SettingsPanel";
26
+ import { SkillsPanel } from "./SkillsPanel";
27
+ import { previewInput } from "./stream";
28
+ import { DeskTranscript } from "./TranscriptViews";
29
+ import { groupTranscriptLines, type TranscriptBlock } from "./thought";
30
+ import type { DeskReady } from "./useDesktopApp";
31
+
32
+ export function DeskSidePanel(
33
+ props: Readonly<{
34
+ view: MainView;
35
+ bridge: BridgeClient | null;
36
+ theme: ThemeChoice;
37
+ skillQuery: string;
38
+ uploads: Array<{ name: string; rel: string; sourcePath?: string }>;
39
+ onTheme: (theme: ThemeChoice) => void;
40
+ onSaved: (state: DesktopState) => void;
41
+ onNotice: ShowNotice;
42
+ onSkillQuery: (value: string) => void;
43
+ onOpenFile: (path: string, reveal: boolean) => void;
44
+ onDeleteFiles: (rels: readonly string[]) => void | Promise<void>;
45
+ sessions: PickerItem[];
46
+ sessionBusy: boolean;
47
+ onOpenSession: (id: string) => void;
48
+ onDeleteSessions: (ids: readonly string[]) => void | Promise<void>;
49
+ }>,
50
+ ): React.ReactElement | null {
51
+ if (!props.bridge) return null;
52
+ if (props.view === "settings") {
53
+ return (
54
+ <SettingsPanel
55
+ bridge={props.bridge}
56
+ theme={props.theme}
57
+ onTheme={props.onTheme}
58
+ onSaved={props.onSaved}
59
+ onNotice={props.onNotice}
60
+ />
61
+ );
62
+ }
63
+ if (props.view === "integrations") {
64
+ return <IntegrationsPanel bridge={props.bridge} onNotice={props.onNotice} />;
65
+ }
66
+ if (props.view === "skills") {
67
+ return (
68
+ <SkillsPanel
69
+ bridge={props.bridge}
70
+ query={props.skillQuery}
71
+ onQuery={props.onSkillQuery}
72
+ onNotice={props.onNotice}
73
+ />
74
+ );
75
+ }
76
+ if (props.view === "files") {
77
+ return (
78
+ <FilesPanel items={props.uploads} onOpen={props.onOpenFile} onDelete={props.onDeleteFiles} />
79
+ );
80
+ }
81
+ if (props.view === "memory") {
82
+ return <MemoryPanel bridge={props.bridge} onNotice={props.onNotice} />;
83
+ }
84
+ if (props.view === "sessions") {
85
+ return (
86
+ <SessionsPanel
87
+ sessions={props.sessions}
88
+ busy={props.sessionBusy}
89
+ onOpen={props.onOpenSession}
90
+ onDelete={props.onDeleteSessions}
91
+ />
92
+ );
93
+ }
94
+ return null;
95
+ }
96
+
97
+ export function DesktopChrome(props: Readonly<{ desk: DeskReady }>): React.ReactElement {
98
+ const desk = props.desk;
99
+ const { lines, status, sideOpen, pending } = desk;
100
+ const approvalPreview = pending ? previewInput(pending.input) : "";
101
+ const turnRunning = status === "running" || status === "approval";
102
+ const transcriptBlocks = groupTranscriptLines(lines);
103
+ const lastLine = lines.at(-1);
104
+ const thoughtPending = turnRunning && (!lastLine || lastLine.type === "user");
105
+ const warmupSeed = lastLine?.type === "user" ? lastLine.userTurnIndex : 0;
106
+
107
+ return (
108
+ <div className={`desk${sideOpen ? "" : " is-side-off"}`}>
109
+ <DeskSidebar desk={desk} />
110
+ <DeskMain
111
+ desk={desk}
112
+ approvalPreview={approvalPreview}
113
+ turnRunning={turnRunning}
114
+ transcriptBlocks={transcriptBlocks}
115
+ thoughtPending={thoughtPending}
116
+ warmupSeed={warmupSeed}
117
+ />
118
+ </div>
119
+ );
120
+ }
121
+
122
+ export function DeskApproval(
123
+ props: Readonly<{ desk: DeskReady; approvalPreview: string }>,
124
+ ): React.ReactElement | null {
125
+ const pending = props.desk.pending;
126
+ if (!pending) return null;
127
+ if (isUploadEditPending(pending)) {
128
+ return (
129
+ <DeskUploadApproval
130
+ pending={pending}
131
+ approvalPreview={props.approvalPreview}
132
+ onDecide={props.desk.decide}
133
+ />
134
+ );
135
+ }
136
+ return (
137
+ <DeskToolApproval
138
+ pending={pending}
139
+ approvalPreview={props.approvalPreview}
140
+ onDecide={props.desk.decide}
141
+ />
142
+ );
143
+ }
144
+
145
+ export function DeskUploadApproval(
146
+ props: Readonly<{
147
+ pending: PendingApproval;
148
+ approvalPreview: string;
149
+ onDecide: DeskReady["decide"];
150
+ }>,
151
+ ): React.ReactElement {
152
+ const fileName =
153
+ typeof props.pending.input.fileName === "string" ? props.pending.input.fileName : "File";
154
+ const copyPath =
155
+ typeof props.pending.input.copyPath === "string"
156
+ ? props.pending.input.copyPath
157
+ : props.approvalPreview;
158
+ const originalPath =
159
+ typeof props.pending.input.originalPath === "string"
160
+ ? homePath(props.pending.input.originalPath)
161
+ : "";
162
+ return (
163
+ <section className="desk-approve" aria-label="Approval needed">
164
+ <p>Edit this file where?</p>
165
+ <pre className="cel-code">
166
+ {fileName}
167
+ {"\n"}Copy: {copyPath}
168
+ {originalPath ? `\nOriginal: ${originalPath}` : ""}
169
+ </pre>
170
+ <div className="desk-approve-actions">
171
+ <button
172
+ type="button"
173
+ className="cel-btn cel-btn--secondary cel-btn--compact"
174
+ onClick={() => void props.onDecide("copy")}
175
+ >
176
+ Copy
177
+ </button>
178
+ <button
179
+ type="button"
180
+ className="cel-btn cel-btn--secondary cel-btn--compact"
181
+ onClick={() => void props.onDecide("original")}
182
+ >
183
+ Original
184
+ </button>
185
+ <button
186
+ type="button"
187
+ className="cel-btn cel-btn--tertiary cel-btn--compact"
188
+ onClick={() => void props.onDecide("no")}
189
+ >
190
+ Cancel
191
+ </button>
192
+ </div>
193
+ </section>
194
+ );
195
+ }
196
+
197
+ export function DeskToolApproval(
198
+ props: Readonly<{
199
+ pending: PendingApproval;
200
+ approvalPreview: string;
201
+ onDecide: DeskReady["decide"];
202
+ }>,
203
+ ): React.ReactElement {
204
+ return (
205
+ <section className="desk-approve" aria-label="Approval needed">
206
+ <p>Approval needed · {props.pending.toolName}</p>
207
+ <pre className="cel-code">{props.approvalPreview}</pre>
208
+ <div className="desk-approve-actions">
209
+ <button
210
+ type="button"
211
+ className="cel-btn cel-btn--secondary cel-btn--compact"
212
+ onClick={() => void props.onDecide("yes")}
213
+ >
214
+ Approve
215
+ </button>
216
+ <button
217
+ type="button"
218
+ className="cel-btn cel-btn--secondary cel-btn--compact"
219
+ onClick={() => void props.onDecide("no")}
220
+ >
221
+ Deny
222
+ </button>
223
+ <button
224
+ type="button"
225
+ className="cel-btn cel-btn--tertiary cel-btn--compact"
226
+ onClick={() => void props.onDecide("always")}
227
+ >
228
+ Always this session
229
+ </button>
230
+ </div>
231
+ </section>
232
+ );
233
+ }
234
+
235
+ export function DeskSessionMenu(props: Readonly<{ desk: DeskReady }>): React.ReactElement | null {
236
+ const menu = props.desk.sessionMenu;
237
+ if (!menu) return null;
238
+ return (
239
+ <div
240
+ ref={props.desk.sessionMenuRef}
241
+ className="desk-menu cel-float"
242
+ role="menu"
243
+ aria-label="Chat"
244
+ style={{ left: menu.x, top: menu.y }}
245
+ >
246
+ <button
247
+ type="button"
248
+ role="menuitem"
249
+ onClick={() => {
250
+ props.desk.setRenameDraft(menu.label);
251
+ props.desk.setRenamingId(menu.id);
252
+ props.desk.setSessionMenu(null);
253
+ }}
254
+ >
255
+ <PencilSimpleIcon size={16} weight="regular" />
256
+ Rename
257
+ </button>
258
+ <button
259
+ type="button"
260
+ role="menuitem"
261
+ className="is-danger"
262
+ onClick={() => void props.desk.removeChat(menu.id)}
263
+ >
264
+ <TrashIcon size={16} weight="regular" />
265
+ Delete
266
+ </button>
267
+ </div>
268
+ );
269
+ }
270
+
271
+ export function DeskMain(
272
+ props: Readonly<{
273
+ desk: DeskReady;
274
+ approvalPreview: string;
275
+ turnRunning: boolean;
276
+ transcriptBlocks: TranscriptBlock[];
277
+ thoughtPending: boolean;
278
+ warmupSeed: number;
279
+ }>,
280
+ ): React.ReactElement {
281
+ const { desk } = props;
282
+ const { view, fileDrag, pending, notice, sessionMenu, dismissNotice } = desk;
283
+ return (
284
+ <>
285
+ <section
286
+ className={`desk-main${fileDrag && view === "chat" ? " is-file-drag" : ""}`}
287
+ aria-label="Chat"
288
+ onDragEnter={desk.onFileDragEnter}
289
+ onDragOver={desk.onFileDragOver}
290
+ onDragLeave={desk.onFileDragLeave}
291
+ onDrop={desk.onFileDrop}
292
+ >
293
+ <header className="desk-bar">
294
+ <div className="desk-id">
295
+ <h1>{mainViewTitle(view)}</h1>
296
+ {view === "chat" && desk.state.spend ? <p>{desk.state.spend}</p> : null}
297
+ </div>
298
+ </header>
299
+ <div className="desk-stage">
300
+ {view !== "chat" ? (
301
+ <DeskSidePanel
302
+ view={view}
303
+ bridge={desk.bridge}
304
+ theme={desk.theme}
305
+ skillQuery={desk.skillQuery}
306
+ uploads={desk.state.uploads ?? []}
307
+ onTheme={desk.setTheme}
308
+ onSaved={(next) => desk.setState(next)}
309
+ onNotice={desk.showNotice}
310
+ onSkillQuery={desk.setSkillQuery}
311
+ onOpenFile={(path, reveal) => {
312
+ void openLocalFile(path, reveal, desk.bridge).catch((err: unknown) => {
313
+ desk.noticeError(err);
314
+ });
315
+ }}
316
+ onDeleteFiles={(rels) => {
317
+ if (!desk.bridge) return;
318
+ return deleteUploads(desk.bridge, rels)
319
+ .then((result) => {
320
+ desk.setState(result.state);
321
+ desk.showNotice(rels.length > 1 ? `Deleted ${rels.length}` : "Deleted");
322
+ })
323
+ .catch((err: unknown) => {
324
+ desk.noticeError(err);
325
+ });
326
+ }}
327
+ sessions={desk.sessions}
328
+ sessionBusy={desk.status !== "idle"}
329
+ onOpenSession={(id) => void desk.openSession(id)}
330
+ onDeleteSessions={(ids) => desk.removeChats(ids)}
331
+ />
332
+ ) : (
333
+ <DeskTranscript
334
+ desk={desk}
335
+ turnRunning={props.turnRunning}
336
+ transcriptBlocks={props.transcriptBlocks}
337
+ thoughtPending={props.thoughtPending}
338
+ warmupSeed={props.warmupSeed}
339
+ />
340
+ )}
341
+ {view === "chat" && pending ? (
342
+ <DeskApproval desk={desk} approvalPreview={props.approvalPreview} />
343
+ ) : null}
344
+ {view === "chat" ? <DeskComposer desk={desk} /> : null}
345
+ </div>
346
+ {notice ? (
347
+ <div className="desk-notice-host">
348
+ <FloatNotice
349
+ key={notice.id}
350
+ text={notice.text}
351
+ kind={notice.kind}
352
+ onDismiss={dismissNotice}
353
+ />
354
+ </div>
355
+ ) : null}
356
+ </section>
357
+ {sessionMenu ? <DeskSessionMenu desk={desk} /> : null}
358
+ </>
359
+ );
360
+ }