@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.
- package/README.md +7 -0
- package/desktop/src/App.tsx +9 -2919
- package/desktop/src/BubbleClip.tsx +1 -1
- package/desktop/src/ComposerAttach.tsx +2 -2
- package/desktop/src/DeskBoot.tsx +28 -0
- package/desktop/src/DeskChrome.tsx +360 -0
- package/desktop/src/DeskComposer.tsx +311 -0
- package/desktop/src/DeskSidebar.tsx +191 -0
- package/desktop/src/FilesPanel.tsx +104 -36
- package/desktop/src/FloatNotice.test.ts +12 -0
- package/desktop/src/FloatNotice.tsx +5 -2
- package/desktop/src/IntegrationsPanel.tsx +273 -0
- package/desktop/src/McpPanel.tsx +8 -8
- package/desktop/src/MemoryPanel.tsx +138 -0
- package/desktop/src/QueuePanel.tsx +123 -0
- package/desktop/src/SessionsPanel.tsx +174 -0
- package/desktop/src/SettingsPanel.tsx +181 -0
- package/desktop/src/SkillsPanel.tsx +28 -12
- package/desktop/src/TranscriptViews.tsx +637 -0
- package/desktop/src/api.ts +36 -0
- package/desktop/src/app.css +159 -11
- package/desktop/src/composer-files.ts +2 -2
- package/desktop/src/desk-keys.ts +45 -0
- package/desktop/src/desk-prefs.ts +29 -0
- package/desktop/src/desk-types.ts +92 -0
- package/desktop/src/desktop-turn.ts +271 -0
- package/desktop/src/preview-render.ts +322 -36
- package/desktop/src/queue.ts +1 -1
- package/desktop/src/session-search.test.ts +20 -0
- package/desktop/src/session-search.ts +13 -0
- package/desktop/src/session-select.test.ts +23 -0
- package/desktop/src/session-select.ts +32 -0
- package/desktop/src/useDeskDictation.ts +123 -0
- package/desktop/src/useDeskFiles.ts +180 -0
- package/desktop/src/useDeskNotice.ts +20 -0
- package/desktop/src/useDeskPicker.ts +189 -0
- package/desktop/src/useDeskPrefs.ts +30 -0
- package/desktop/src/useDeskRuntime.ts +109 -0
- package/desktop/src/useDeskSessions.ts +195 -0
- package/desktop/src/useDeskSlash.ts +31 -0
- package/desktop/src/useDeskTurns.ts +264 -0
- package/desktop/src/useDesktopApp.ts +286 -0
- package/desktop/src/user-display.ts +2 -2
- package/package.json +2 -2
- package/src/cli/openrouter-live.ts +30 -21
- package/src/cli/slash-dispatch.test.ts +25 -0
- package/src/cli/slash-dispatch.ts +41 -0
- package/src/cli/slash.ts +1 -0
- package/src/config.ts +10 -1
- package/src/core/run-turn.test.ts +3 -0
- package/src/core/run-turn.ts +74 -41
- package/src/desktop/bridge.test.ts +43 -0
- package/src/desktop/bridge.ts +91 -19
- package/src/desktop/uploads.test.ts +6 -0
- package/src/desktop/uploads.ts +178 -66
- package/src/index.ts +13 -0
- package/src/integrations/remote-mcp.ts +51 -21
- package/src/memory/extract.test.ts +81 -0
- package/src/memory/extract.ts +88 -0
- package/src/memory/prefs.test.ts +53 -0
- package/src/memory/prefs.ts +47 -0
- package/src/memory/prompt.ts +24 -0
- package/src/memory/store.test.ts +191 -0
- package/src/memory/store.ts +382 -0
- package/src/runtime.test.ts +37 -0
- package/src/runtime.ts +29 -1
- package/src/tools/local.ts +86 -39
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { DesktopState } from "./api";
|
|
3
|
+
import { releaseAttachment } from "./composer-files";
|
|
4
|
+
import { applySlashComposerKey, composerEscapeAction, slashMenuKey } from "./desk-keys";
|
|
5
|
+
import { composerMediaModels } from "./desk-types";
|
|
6
|
+
import type { StreamLine } from "./stream";
|
|
7
|
+
import { useDeskDictation } from "./useDeskDictation";
|
|
8
|
+
import { useDeskFiles } from "./useDeskFiles";
|
|
9
|
+
import { useDeskNotice } from "./useDeskNotice";
|
|
10
|
+
import { useDeskPicker } from "./useDeskPicker";
|
|
11
|
+
import { useDeskPrefs } from "./useDeskPrefs";
|
|
12
|
+
import { useDeskRuntime } from "./useDeskRuntime";
|
|
13
|
+
import { useDeskSessions } from "./useDeskSessions";
|
|
14
|
+
import { useDeskSlash } from "./useDeskSlash";
|
|
15
|
+
import { useDeskTurns } from "./useDeskTurns";
|
|
16
|
+
|
|
17
|
+
export function useDesktopApp() {
|
|
18
|
+
const prefs = useDeskPrefs();
|
|
19
|
+
const notices = useDeskNotice();
|
|
20
|
+
const runtime = useDeskRuntime();
|
|
21
|
+
const viewRef = useRef(runtime.view);
|
|
22
|
+
viewRef.current = runtime.view;
|
|
23
|
+
const transcriptRef = useRef<HTMLDivElement>(null);
|
|
24
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
25
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
26
|
+
const sendingRef = useRef(false);
|
|
27
|
+
const [draft, setDraft] = useState("");
|
|
28
|
+
const [editingUser, setEditingUser] = useState<{
|
|
29
|
+
index: number;
|
|
30
|
+
text: string;
|
|
31
|
+
suffix?: string;
|
|
32
|
+
} | null>(null);
|
|
33
|
+
|
|
34
|
+
const files = useDeskFiles({
|
|
35
|
+
view: runtime.view,
|
|
36
|
+
viewRef,
|
|
37
|
+
showNotice: notices.showNotice,
|
|
38
|
+
noticeError: notices.noticeError,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const dictation = useDeskDictation({
|
|
42
|
+
bridge: runtime.bridge,
|
|
43
|
+
status: runtime.status,
|
|
44
|
+
showNotice: notices.showNotice,
|
|
45
|
+
noticeError: notices.noticeError,
|
|
46
|
+
setDraft,
|
|
47
|
+
inputRef,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const slashOpen =
|
|
51
|
+
runtime.view === "chat" &&
|
|
52
|
+
draft.startsWith("/") &&
|
|
53
|
+
!dictation.listening &&
|
|
54
|
+
runtime.status !== "picker";
|
|
55
|
+
const slash = useDeskSlash({
|
|
56
|
+
bridge: runtime.bridge,
|
|
57
|
+
draft,
|
|
58
|
+
slashOpen,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const pushSystem = useCallback(
|
|
62
|
+
(text: string) => {
|
|
63
|
+
runtime.setLines((prev) => [
|
|
64
|
+
...prev,
|
|
65
|
+
{ key: `sys-${prev.length}-${Date.now()}`, type: "system", text },
|
|
66
|
+
]);
|
|
67
|
+
},
|
|
68
|
+
[runtime.setLines],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const releaseLinePreviews = useCallback(
|
|
72
|
+
(next: StreamLine[]) => {
|
|
73
|
+
runtime.setLines((prev) => {
|
|
74
|
+
for (const line of prev) {
|
|
75
|
+
if (line.type !== "user") continue;
|
|
76
|
+
for (const item of line.attachments ?? []) releaseAttachment(item);
|
|
77
|
+
}
|
|
78
|
+
return next;
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
[runtime.setLines],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const picker = useDeskPicker({
|
|
85
|
+
bridge: runtime.bridge,
|
|
86
|
+
state: runtime.state,
|
|
87
|
+
listening: dictation.listening,
|
|
88
|
+
status: runtime.status,
|
|
89
|
+
sendingRef,
|
|
90
|
+
setState: runtime.setState,
|
|
91
|
+
setStatus: runtime.setStatus,
|
|
92
|
+
setLines: runtime.setLines,
|
|
93
|
+
setDraft,
|
|
94
|
+
pushSystem,
|
|
95
|
+
refreshSessions: runtime.refreshSessions,
|
|
96
|
+
noticeError: notices.noticeError,
|
|
97
|
+
inputRef,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const turns = useDeskTurns({
|
|
101
|
+
bridge: runtime.bridge,
|
|
102
|
+
status: runtime.status,
|
|
103
|
+
draft,
|
|
104
|
+
listening: dictation.listening,
|
|
105
|
+
slashOpen,
|
|
106
|
+
slashItems: slash.slashItems,
|
|
107
|
+
slashIndex: slash.slashIndex,
|
|
108
|
+
editingUser,
|
|
109
|
+
pending: runtime.pending,
|
|
110
|
+
setState: runtime.setState,
|
|
111
|
+
setStatus: runtime.setStatus,
|
|
112
|
+
setView: runtime.setView,
|
|
113
|
+
setSkillQuery: runtime.setSkillQuery,
|
|
114
|
+
setDraft,
|
|
115
|
+
setLines: runtime.setLines,
|
|
116
|
+
setPending: runtime.setPending,
|
|
117
|
+
setPicker: picker.setPicker,
|
|
118
|
+
setEditingUser,
|
|
119
|
+
pushSystem,
|
|
120
|
+
refreshSessions: runtime.refreshSessions,
|
|
121
|
+
showNotice: notices.showNotice,
|
|
122
|
+
noticeError: notices.noticeError,
|
|
123
|
+
takeAttachments: files.takeAttachments,
|
|
124
|
+
attachmentsRef: files.attachmentsRef,
|
|
125
|
+
sendingRef,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const sessions = useDeskSessions({
|
|
129
|
+
bridge: runtime.bridge,
|
|
130
|
+
status: runtime.status,
|
|
131
|
+
setState: runtime.setState,
|
|
132
|
+
setView: runtime.setView,
|
|
133
|
+
setEditingUser,
|
|
134
|
+
setQueueSync: turns.setQueueSync,
|
|
135
|
+
releaseLinePreviews,
|
|
136
|
+
noticeError: notices.noticeError,
|
|
137
|
+
refreshSessions: runtime.refreshSessions,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const node = transcriptRef.current;
|
|
142
|
+
if (node) node.scrollTop = node.scrollHeight;
|
|
143
|
+
}, [runtime.lines, runtime.pending]);
|
|
144
|
+
|
|
145
|
+
useEffect(() => () => dictation.stopRecorder(), [dictation.stopRecorder]);
|
|
146
|
+
|
|
147
|
+
const onKeyDown = useCallback(
|
|
148
|
+
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
149
|
+
if (picker.picker) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (event.key === "Escape") {
|
|
154
|
+
const action = composerEscapeAction(Boolean(editingUser), runtime.status);
|
|
155
|
+
if (action === "cancel-edit") {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
setEditingUser(null);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (action === "stop") {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
void turns.stop();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const slashKey = slashMenuKey(event.key, slashOpen, slash.slashItems.length);
|
|
167
|
+
if (
|
|
168
|
+
applySlashComposerKey(
|
|
169
|
+
slashKey,
|
|
170
|
+
slash.slashItems,
|
|
171
|
+
slash.slashIndex,
|
|
172
|
+
slash.setSlashIndex,
|
|
173
|
+
setDraft,
|
|
174
|
+
)
|
|
175
|
+
) {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
void turns.submit();
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
[
|
|
185
|
+
editingUser,
|
|
186
|
+
picker.picker,
|
|
187
|
+
runtime.status,
|
|
188
|
+
slash.slashIndex,
|
|
189
|
+
slash.slashItems,
|
|
190
|
+
slash.setSlashIndex,
|
|
191
|
+
slashOpen,
|
|
192
|
+
turns.stop,
|
|
193
|
+
turns.submit,
|
|
194
|
+
],
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
bootError: runtime.bootError,
|
|
199
|
+
state: runtime.state,
|
|
200
|
+
bridge: runtime.bridge,
|
|
201
|
+
sessions: runtime.sessions,
|
|
202
|
+
lines: runtime.lines,
|
|
203
|
+
draft,
|
|
204
|
+
status: runtime.status,
|
|
205
|
+
view: runtime.view,
|
|
206
|
+
skillQuery: runtime.skillQuery,
|
|
207
|
+
theme: prefs.theme,
|
|
208
|
+
sideOpen: prefs.sideOpen,
|
|
209
|
+
mediaOpen: prefs.mediaOpen,
|
|
210
|
+
slashItems: slash.slashItems,
|
|
211
|
+
slashIndex: slash.slashIndex,
|
|
212
|
+
picker: picker.picker,
|
|
213
|
+
sessionMenu: sessions.sessionMenu,
|
|
214
|
+
renamingId: sessions.renamingId,
|
|
215
|
+
renameDraft: sessions.renameDraft,
|
|
216
|
+
pending: runtime.pending,
|
|
217
|
+
listening: dictation.listening,
|
|
218
|
+
queue: turns.queue,
|
|
219
|
+
editingUser,
|
|
220
|
+
editingQueuedId: turns.editingQueuedId,
|
|
221
|
+
queueOpen: turns.queueOpen,
|
|
222
|
+
notice: notices.notice,
|
|
223
|
+
attachments: files.attachments,
|
|
224
|
+
integrations: runtime.integrations,
|
|
225
|
+
fileDrag: files.fileDrag,
|
|
226
|
+
slashOpen,
|
|
227
|
+
transcriptRef,
|
|
228
|
+
inputRef,
|
|
229
|
+
fileInputRef,
|
|
230
|
+
pickerListRef: picker.pickerListRef,
|
|
231
|
+
sessionMenuRef: sessions.sessionMenuRef,
|
|
232
|
+
renameInputRef: sessions.renameInputRef,
|
|
233
|
+
skipRenameBlurRef: sessions.skipRenameBlurRef,
|
|
234
|
+
mediaModels: runtime.state ? composerMediaModels(runtime.state) : [],
|
|
235
|
+
setState: runtime.setState,
|
|
236
|
+
setStatus: runtime.setStatus,
|
|
237
|
+
setView: runtime.setView,
|
|
238
|
+
setSkillQuery: runtime.setSkillQuery,
|
|
239
|
+
setTheme: prefs.setTheme,
|
|
240
|
+
setSideOpen: prefs.setSideOpen,
|
|
241
|
+
setMediaOpen: prefs.setMediaOpen,
|
|
242
|
+
setSlashIndex: slash.setSlashIndex,
|
|
243
|
+
setDraft,
|
|
244
|
+
setRenamingId: sessions.setRenamingId,
|
|
245
|
+
setRenameDraft: sessions.setRenameDraft,
|
|
246
|
+
setEditingUser,
|
|
247
|
+
setEditingQueuedId: turns.setEditingQueuedId,
|
|
248
|
+
setQueueOpen: turns.setQueueOpen,
|
|
249
|
+
setQueueSync: turns.setQueueSync,
|
|
250
|
+
queueRef: turns.queueRef,
|
|
251
|
+
setSessionMenu: sessions.setSessionMenu,
|
|
252
|
+
setPicker: picker.setPicker,
|
|
253
|
+
dismissNotice: notices.dismissNotice,
|
|
254
|
+
showNotice: notices.showNotice,
|
|
255
|
+
noticeError: notices.noticeError,
|
|
256
|
+
addFiles: files.addFiles,
|
|
257
|
+
removeAttachment: files.removeAttachment,
|
|
258
|
+
onFileDragEnter: files.onFileDragEnter,
|
|
259
|
+
onFileDragOver: files.onFileDragOver,
|
|
260
|
+
onFileDragLeave: files.onFileDragLeave,
|
|
261
|
+
onFileDrop: files.onFileDrop,
|
|
262
|
+
sendTurn: turns.sendTurn,
|
|
263
|
+
openComposerPicker: picker.openComposerPicker,
|
|
264
|
+
submit: turns.submit,
|
|
265
|
+
sendQueuedNow: turns.sendQueuedNow,
|
|
266
|
+
stop: turns.stop,
|
|
267
|
+
commitEdit: turns.commitEdit,
|
|
268
|
+
choosePicker: picker.choosePicker,
|
|
269
|
+
cancelPicker: picker.cancelPicker,
|
|
270
|
+
openSession: sessions.openSession,
|
|
271
|
+
newChat: sessions.newChat,
|
|
272
|
+
commitRename: sessions.commitRename,
|
|
273
|
+
removeChat: sessions.removeChat,
|
|
274
|
+
removeChats: sessions.removeChats,
|
|
275
|
+
decide: turns.decide,
|
|
276
|
+
onKeyDown,
|
|
277
|
+
startDictation: dictation.startDictation,
|
|
278
|
+
stopDictation: dictation.stopDictation,
|
|
279
|
+
applySpoken: dictation.applySpoken,
|
|
280
|
+
ingestDropped: files.ingestDropped,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type DeskReady = Exclude<ReturnType<typeof useDesktopApp>, { state: null }> & {
|
|
285
|
+
state: DesktopState;
|
|
286
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { joinUploadDisplay, parseUploadDisplay } from "../../src/desktop/upload-message
|
|
2
|
-
import { type AttachmentPreview, attachmentKind } from "./composer-files
|
|
1
|
+
import { joinUploadDisplay, parseUploadDisplay } from "../../src/desktop/upload-message";
|
|
2
|
+
import { type AttachmentPreview, attachmentKind } from "./composer-files";
|
|
3
3
|
|
|
4
4
|
export function userBubbleContent(
|
|
5
5
|
text: string,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useavalon/caelence-agent",
|
|
3
|
-
"version": "0.2.3-canary.
|
|
3
|
+
"version": "0.2.3-canary.2",
|
|
4
4
|
"description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
41
|
"start": "bun bin/harness.ts",
|
|
42
|
-
"test": "bun test src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts",
|
|
42
|
+
"test": "bun test src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/memory src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts desktop/src/session-search.test.ts desktop/src/session-select.test.ts",
|
|
43
43
|
"typecheck": "bunx tsc --noEmit -p tsconfig.json",
|
|
44
44
|
"lint": "biome ci .",
|
|
45
45
|
"format": "biome format --write .",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OPENROUTER_DEFAULT_BASE_URL } from "../config.ts";
|
|
1
|
+
import { OPENROUTER_DEFAULT_BASE_URL, stripTrailingSlashes } from "../config.ts";
|
|
2
2
|
|
|
3
3
|
const LIVE_TTL_MS = 10 * 60 * 1000;
|
|
4
4
|
const EMPTY = new Map<string, string>();
|
|
@@ -13,11 +13,34 @@ function displayName(id: string, rawName: string): string {
|
|
|
13
13
|
return prettyLiveModelName(name);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
function liveNameFromRow(item: unknown): { id: string; name: string } | undefined {
|
|
17
|
+
if (typeof item !== "object" || item === null) return undefined;
|
|
18
|
+
const row = item as Record<string, unknown>;
|
|
19
|
+
const id = typeof row.id === "string" ? row.id : "";
|
|
20
|
+
if (!id) return undefined;
|
|
21
|
+
const target = row.alias_target;
|
|
22
|
+
if (typeof target === "object" && target !== null) {
|
|
23
|
+
const name = (target as { name?: unknown }).name;
|
|
24
|
+
const slug = (target as { slug?: unknown }).slug;
|
|
25
|
+
if (typeof name === "string" && name.trim()) {
|
|
26
|
+
return { id, name: displayName(typeof slug === "string" ? slug : id, name) };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (typeof row.name === "string" && row.name.trim()) {
|
|
30
|
+
return { id, name: displayName(id, row.name) };
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function wordsOf(name: string): string[] {
|
|
36
|
+
return name.toLowerCase().replaceAll("_", " ").replaceAll("-", " ").split(" ").filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
/** OpenRouter calls Auto "Auto Router". Product copy is Auto / Auto beta. */
|
|
17
40
|
export function prettyLiveModelName(name: string): string {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
41
|
+
const words = wordsOf(name);
|
|
42
|
+
if (!words.includes("auto") || !words.includes("router")) return name;
|
|
43
|
+
return words.includes("beta") ? "Auto beta" : "Auto";
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
/** Human name of the concrete model a `~latest` alias currently resolves to. */
|
|
@@ -27,22 +50,8 @@ export function parseLiveTargetNames(json: unknown): Map<string, string> {
|
|
|
27
50
|
const data = (json as { data?: unknown }).data;
|
|
28
51
|
if (!Array.isArray(data)) return names;
|
|
29
52
|
for (const item of data) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const id = typeof row.id === "string" ? row.id : "";
|
|
33
|
-
if (!id) continue;
|
|
34
|
-
const target = row.alias_target;
|
|
35
|
-
if (typeof target === "object" && target !== null) {
|
|
36
|
-
const name = (target as { name?: unknown }).name;
|
|
37
|
-
const slug = (target as { slug?: unknown }).slug;
|
|
38
|
-
if (typeof name === "string" && name.trim()) {
|
|
39
|
-
names.set(id, displayName(typeof slug === "string" ? slug : id, name));
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (typeof row.name === "string" && row.name.trim()) {
|
|
44
|
-
names.set(id, displayName(id, row.name));
|
|
45
|
-
}
|
|
53
|
+
const mapped = liveNameFromRow(item);
|
|
54
|
+
if (mapped) names.set(mapped.id, mapped.name);
|
|
46
55
|
}
|
|
47
56
|
return names;
|
|
48
57
|
}
|
|
@@ -61,7 +70,7 @@ export async function loadLiveTargetNames(options: {
|
|
|
61
70
|
const useCache = fetchImpl === globalThis.fetch;
|
|
62
71
|
if (useCache && cache && cache.expires > Date.now()) return cache.names;
|
|
63
72
|
try {
|
|
64
|
-
const base = (options.baseUrl ?? OPENROUTER_DEFAULT_BASE_URL)
|
|
73
|
+
const base = stripTrailingSlashes(options.baseUrl ?? OPENROUTER_DEFAULT_BASE_URL);
|
|
65
74
|
const res = await fetchImpl(`${base}/models`, {
|
|
66
75
|
headers: {
|
|
67
76
|
Authorization: `Bearer ${options.apiKey}`,
|
|
@@ -250,6 +250,31 @@ describe("dispatchSlash", () => {
|
|
|
250
250
|
expect(await runSlashLine(fakeHarness(), "/asdf")).toEqual({ kind: "hold" });
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
+
test("memory lists facts and can turn on", async () => {
|
|
254
|
+
const home = await mkdtemp(join(tmpdir(), "harness-mem-slash-"));
|
|
255
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-mem-slash-cwd-"));
|
|
256
|
+
const prevHome = process.env.HARNESS_HOME;
|
|
257
|
+
process.env.HARNESS_HOME = home;
|
|
258
|
+
try {
|
|
259
|
+
const { addFacts } = await import("../memory/store.ts");
|
|
260
|
+
addFacts(cwd, [{ text: "Prefer bun over npm for installs", scope: "user" }]);
|
|
261
|
+
const off = await dispatchSlash(fakeHarness({ cwd }), "/memory");
|
|
262
|
+
expect(off.kind).toBe("text");
|
|
263
|
+
if (off.kind === "text") {
|
|
264
|
+
expect(off.text).toContain("off");
|
|
265
|
+
expect(off.text).toContain("Prefer bun");
|
|
266
|
+
}
|
|
267
|
+
const on = await dispatchSlash(fakeHarness({ cwd }), "/memory on");
|
|
268
|
+
expect(on.kind).toBe("text");
|
|
269
|
+
if (on.kind === "text") expect(on.text).toContain("Memory on");
|
|
270
|
+
} finally {
|
|
271
|
+
if (prevHome === undefined) delete process.env.HARNESS_HOME;
|
|
272
|
+
else process.env.HARNESS_HOME = prevHome;
|
|
273
|
+
await rm(home, { recursive: true, force: true });
|
|
274
|
+
await rm(cwd, { recursive: true, force: true });
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
253
278
|
test("settings reports a missing key without opening a picker", async () => {
|
|
254
279
|
const result = await dispatchSlash(fakeHarness({ hasApiKey: false }), "/settings");
|
|
255
280
|
expect(result.kind).toBe("text");
|
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
} from "../integrations/store.ts";
|
|
14
14
|
import { type GeneratedMedia, generateImage, generateVideo } from "../media/openrouter-generate.ts";
|
|
15
15
|
import { readMediaPrefs, writeMediaPrefs } from "../media/prefs.ts";
|
|
16
|
+
import { isMemoryEnabled, writeMemoryPrefs } from "../memory/prefs.ts";
|
|
17
|
+
import { formatMemoryList } from "../memory/prompt.ts";
|
|
18
|
+
import { deleteFact, listFacts, matchFact, pinFact, unpinFact } from "../memory/store.ts";
|
|
16
19
|
import type { HarnessRuntime } from "../runtime.ts";
|
|
17
20
|
import { browseSkillCatalog } from "../skills/catalog.ts";
|
|
18
21
|
import {
|
|
@@ -366,6 +369,43 @@ async function handleEval(harness: HarnessRuntime, arg: string): Promise<SlashOu
|
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
371
|
|
|
372
|
+
function memoryState(harness: HarnessRuntime) {
|
|
373
|
+
return {
|
|
374
|
+
enabled: isMemoryEnabled({ configEnabled: harness.config.memory?.enabled }),
|
|
375
|
+
facts: listFacts(harness.cwd),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function handleMemory(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
380
|
+
const body = arg.trim();
|
|
381
|
+
if (!body) return { kind: "text", text: formatMemoryList(memoryState(harness)) };
|
|
382
|
+
if (body === "on" || body === "off") {
|
|
383
|
+
writeMemoryPrefs({ enabled: body === "on" });
|
|
384
|
+
return { kind: "text", text: formatMemoryList(memoryState(harness)) };
|
|
385
|
+
}
|
|
386
|
+
const [action, ...rest] = body.split(/\s+/);
|
|
387
|
+
const target = rest.join(" ").trim();
|
|
388
|
+
if ((action === "delete" || action === "pin") && !target) {
|
|
389
|
+
return { kind: "text", text: `/memory ${action} <n>` };
|
|
390
|
+
}
|
|
391
|
+
if (action === "delete") {
|
|
392
|
+
const fact = matchFact(listFacts(harness.cwd), target);
|
|
393
|
+
if (!fact) return { kind: "text", text: `No memory matches ${target}.` };
|
|
394
|
+
deleteFact(harness.cwd, fact.id);
|
|
395
|
+
const unpinned = unpinFact(harness.cwd, fact, harness.config.instructionsFile);
|
|
396
|
+
if ("error" in unpinned) return { kind: "text", text: unpinned.error };
|
|
397
|
+
return { kind: "text", text: `Deleted ${fact.text}` };
|
|
398
|
+
}
|
|
399
|
+
if (action === "pin") {
|
|
400
|
+
const fact = matchFact(listFacts(harness.cwd), target);
|
|
401
|
+
if (!fact) return { kind: "text", text: `No memory matches ${target}.` };
|
|
402
|
+
const pinned = pinFact(harness.cwd, fact, harness.config.instructionsFile);
|
|
403
|
+
if ("error" in pinned) return { kind: "text", text: pinned.error };
|
|
404
|
+
return { kind: "text", text: `Pinned to ${pinned.path}` };
|
|
405
|
+
}
|
|
406
|
+
return { kind: "text", text: "/memory on · /memory off · /memory delete 1 · /memory pin 1" };
|
|
407
|
+
}
|
|
408
|
+
|
|
369
409
|
async function handleSettings(harness: HarnessRuntime, arg: string): Promise<SlashOutcome> {
|
|
370
410
|
const body = arg.trim();
|
|
371
411
|
if (!body || body === "key") {
|
|
@@ -406,6 +446,7 @@ const SLASH_HANDLERS: Record<string, SlashHandler> = {
|
|
|
406
446
|
transcribe: handleTranscribe,
|
|
407
447
|
resume: handleResume,
|
|
408
448
|
eval: handleEval,
|
|
449
|
+
memory: handleMemory,
|
|
409
450
|
settings: handleSettings,
|
|
410
451
|
exit: async () => ({ kind: "exit" }),
|
|
411
452
|
quit: async () => ({ kind: "exit" }),
|
package/src/cli/slash.ts
CHANGED
|
@@ -20,6 +20,7 @@ export const SLASH_COMMANDS: SlashCommand[] = [
|
|
|
20
20
|
{ name: "model", hint: "pick a model" },
|
|
21
21
|
{ name: "mode", hint: "ask, plan, or agent" },
|
|
22
22
|
{ name: "compact", hint: "summarize earlier turns" },
|
|
23
|
+
{ name: "memory", hint: "remember across chats", arg: true },
|
|
23
24
|
{ name: "image", hint: "generate an image", arg: true, slot: "[prompt]" },
|
|
24
25
|
{ name: "video", hint: "generate a clip", arg: true, slot: "[prompt]" },
|
|
25
26
|
{ name: "transcribe", hint: "speech to text model" },
|
package/src/config.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface HarnessConfig {
|
|
|
24
24
|
openrouterBaseUrl?: string;
|
|
25
25
|
subagents?: { enabled?: boolean };
|
|
26
26
|
observability?: { enabled?: boolean };
|
|
27
|
+
/** Cross-session memory. Off unless this is true or ~/.harness/memory.json enables it. */
|
|
28
|
+
memory?: { enabled?: boolean };
|
|
27
29
|
/** Default agent. ask = read only. plan = read + todos. */
|
|
28
30
|
mode?: AgentMode;
|
|
29
31
|
hooks?: HookConfig[];
|
|
@@ -66,11 +68,18 @@ export async function loadConfig(cwd: string): Promise<HarnessConfig> {
|
|
|
66
68
|
},
|
|
67
69
|
mcp: partial.mcp ?? [],
|
|
68
70
|
observability: partial.observability,
|
|
71
|
+
memory: partial.memory,
|
|
69
72
|
mode: partial.mode,
|
|
70
73
|
hooks: partial.hooks,
|
|
71
74
|
};
|
|
72
75
|
}
|
|
73
76
|
|
|
77
|
+
export function stripTrailingSlashes(value: string): string {
|
|
78
|
+
let trimmed = value;
|
|
79
|
+
while (trimmed.endsWith("/")) trimmed = trimmed.slice(0, -1);
|
|
80
|
+
return trimmed;
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
export function resolveOpenRouter(config: HarnessConfig): {
|
|
75
84
|
apiKey: string;
|
|
76
85
|
baseUrl: string;
|
|
@@ -82,5 +91,5 @@ export function resolveOpenRouter(config: HarnessConfig): {
|
|
|
82
91
|
config.openrouterBaseUrl ||
|
|
83
92
|
OPENROUTER_DEFAULT_BASE_URL;
|
|
84
93
|
const model = process.env.OPENROUTER_MODEL?.trim() || config.model;
|
|
85
|
-
return { apiKey, baseUrl: baseUrl
|
|
94
|
+
return { apiKey, baseUrl: stripTrailingSlashes(baseUrl), model };
|
|
86
95
|
}
|
|
@@ -202,12 +202,15 @@ describe("runTurn", () => {
|
|
|
202
202
|
cwd: "/tmp/proj",
|
|
203
203
|
userInstructions: "prefer bun",
|
|
204
204
|
projectInstructions: "no secrets",
|
|
205
|
+
memory: "Use these only when they are relevant.\n- Prefer bun",
|
|
205
206
|
mode: "ask",
|
|
206
207
|
});
|
|
207
208
|
expect(prompt).toContain("## User instructions");
|
|
208
209
|
expect(prompt).toContain("prefer bun");
|
|
209
210
|
expect(prompt).toContain("## Project instructions");
|
|
210
211
|
expect(prompt).toContain("no secrets");
|
|
212
|
+
expect(prompt).toContain("## Memory");
|
|
213
|
+
expect(prompt).toContain("Prefer bun");
|
|
211
214
|
expect(prompt).toContain("## Mode: ask");
|
|
212
215
|
expect(prompt).toContain("You are a coding agent in this project.");
|
|
213
216
|
expect(prompt).not.toContain("You are harness, a coding agent working in /tmp/proj");
|