@nandoblanco/opencode-local-memory 1.1.1 → 1.3.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.
- package/CHANGELOG.md +35 -0
- package/README.md +34 -10
- package/dist/gui-experimental.cjs +1 -0
- package/gui.css +635 -0
- package/gui.tsx +1313 -0
- package/index.js +524 -51
- package/package.json +24 -3
- package/rpc.d.ts +140 -0
- package/rpc.js +221 -0
- package/tui.ts +682 -100
package/gui.tsx
ADDED
|
@@ -0,0 +1,1313 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Command,
|
|
3
|
+
MenuItem,
|
|
4
|
+
Panel,
|
|
5
|
+
Plugin,
|
|
6
|
+
Slot,
|
|
7
|
+
Style,
|
|
8
|
+
type PanelTab,
|
|
9
|
+
type PluginContext,
|
|
10
|
+
type UiMenuEntry,
|
|
11
|
+
} from "@opencode/plugin/gui";
|
|
12
|
+
import { For, Show, createEffect, createMemo, createSignal, onCleanup } from "solid-js";
|
|
13
|
+
import css from "./gui.css?inline";
|
|
14
|
+
import {
|
|
15
|
+
MemoryRpc,
|
|
16
|
+
type MemoryModeFilter,
|
|
17
|
+
type MemoryRpcEntry,
|
|
18
|
+
type MemoryRpcHit,
|
|
19
|
+
type MemoryRpcQueryOutput,
|
|
20
|
+
type MemoryTypeFilter,
|
|
21
|
+
} from "./rpc.js";
|
|
22
|
+
|
|
23
|
+
const TYPE_LABELS: Record<MemoryTypeFilter, string> = {
|
|
24
|
+
all: "All",
|
|
25
|
+
core: "Core",
|
|
26
|
+
topics: "Topics",
|
|
27
|
+
sessions: "Sessions",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const MODE_LABELS: Record<MemoryModeFilter, string> = {
|
|
31
|
+
hybrid: "Hybrid (Semantic + BM25)",
|
|
32
|
+
keyword: "Keyword",
|
|
33
|
+
regex: "Regex",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const TYPE_CYCLE: MemoryTypeFilter[] = ["all", "core", "topics", "sessions"];
|
|
37
|
+
const MODE_CYCLE: MemoryModeFilter[] = ["hybrid", "keyword", "regex"];
|
|
38
|
+
|
|
39
|
+
function cycleValue<T>(list: readonly T[], current: T): T {
|
|
40
|
+
const idx = list.indexOf(current);
|
|
41
|
+
return list[(idx + 1) % list.length] ?? list[0];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isSessionEntry(entry: MemoryRpcEntry): boolean {
|
|
45
|
+
return String(entry.file || "").startsWith("sessions/") || String(entry.id || "").startsWith("session:");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function entryTopicSlug(entry: MemoryRpcEntry): string {
|
|
49
|
+
const f = String(entry.file || "");
|
|
50
|
+
if (f.startsWith("topics/") && f.endsWith(".md")) {
|
|
51
|
+
return f.slice(7, -3);
|
|
52
|
+
}
|
|
53
|
+
if (isSessionEntry(entry)) return "session";
|
|
54
|
+
return "general";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function entryTagsList(entry: MemoryRpcEntry): string[] {
|
|
58
|
+
return String(entry.tags || "")
|
|
59
|
+
.split(",")
|
|
60
|
+
.map((t) => t.trim())
|
|
61
|
+
.filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function splitHighlightedParts(text: string, rawQuery: string): Array<{ text: string; match: boolean }> {
|
|
65
|
+
const cleanTerms = String(rawQuery || "")
|
|
66
|
+
.replace(/\b(?:type|topic|mode|project|in|core|is|re):[^\s]+/gi, " ")
|
|
67
|
+
.trim()
|
|
68
|
+
.split(/\s+/)
|
|
69
|
+
.filter((t) => t.length >= 2);
|
|
70
|
+
if (!text || cleanTerms.length === 0) return [{ text, match: false }];
|
|
71
|
+
|
|
72
|
+
const escaped = cleanTerms.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
73
|
+
let re: RegExp;
|
|
74
|
+
try {
|
|
75
|
+
re = new RegExp(`(${escaped.join("|")})`, "gi");
|
|
76
|
+
} catch {
|
|
77
|
+
return [{ text, match: false }];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const out: Array<{ text: string; match: boolean }> = [];
|
|
81
|
+
let lastIndex = 0;
|
|
82
|
+
for (const m of text.matchAll(re)) {
|
|
83
|
+
const idx = m.index ?? 0;
|
|
84
|
+
const hit = m[0] ?? "";
|
|
85
|
+
if (!hit) continue;
|
|
86
|
+
if (idx > lastIndex) {
|
|
87
|
+
out.push({ text: text.slice(lastIndex, idx), match: false });
|
|
88
|
+
}
|
|
89
|
+
out.push({ text: hit, match: true });
|
|
90
|
+
lastIndex = idx + hit.length;
|
|
91
|
+
}
|
|
92
|
+
if (lastIndex < text.length) {
|
|
93
|
+
out.push({ text: text.slice(lastIndex), match: false });
|
|
94
|
+
}
|
|
95
|
+
return out.length > 0 ? out : [{ text, match: false }];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getRpcClient(ctx: PluginContext) {
|
|
99
|
+
const activeSession = ctx.sessions.current();
|
|
100
|
+
if (activeSession?.server?.client) {
|
|
101
|
+
return activeSession.server.client.rpc(MemoryRpc);
|
|
102
|
+
}
|
|
103
|
+
const serverIds = ctx.servers?.list?.() ?? [];
|
|
104
|
+
const server =
|
|
105
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s?.builtin) ??
|
|
106
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s?.local) ??
|
|
107
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s !== undefined);
|
|
108
|
+
const client = server?.client ?? ctx.client;
|
|
109
|
+
return client.rpc(MemoryRpc);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface MemorySurfaceProps {
|
|
113
|
+
ctx: PluginContext;
|
|
114
|
+
initialQuery?: string;
|
|
115
|
+
initialEditorMode?: "none" | "add";
|
|
116
|
+
initialDraftFact?: string;
|
|
117
|
+
variant: "panel" | "modal";
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function MemorySurface(props: MemorySurfaceProps) {
|
|
122
|
+
const ui = props.ctx.ui;
|
|
123
|
+
|
|
124
|
+
const [query, setQuery] = createSignal(props.initialQuery ?? "");
|
|
125
|
+
const [typeFilter, setTypeFilter] = createSignal<MemoryTypeFilter>("all");
|
|
126
|
+
const [topicFilter, setTopicFilter] = createSignal<string>("all");
|
|
127
|
+
const [mode, setMode] = createSignal<MemoryModeFilter>("hybrid");
|
|
128
|
+
const [selectedIndex, setSelectedIndex] = createSignal(0);
|
|
129
|
+
|
|
130
|
+
const [loading, setLoading] = createSignal(true);
|
|
131
|
+
const [busyAction, setBusyAction] = createSignal(false);
|
|
132
|
+
const [errorMsg, setErrorMsg] = createSignal<string | undefined>(undefined);
|
|
133
|
+
const [data, setData] = createSignal<MemoryRpcQueryOutput | undefined>(undefined);
|
|
134
|
+
const [sessionMarkdown, setSessionMarkdown] = createSignal<string>("");
|
|
135
|
+
const [confirmDeleteId, setConfirmDeleteId] = createSignal<string>("");
|
|
136
|
+
|
|
137
|
+
const [editorMode, setEditorMode] = createSignal<"none" | "add" | "edit">(
|
|
138
|
+
props.initialEditorMode ?? "none",
|
|
139
|
+
);
|
|
140
|
+
const [editId, setEditId] = createSignal("");
|
|
141
|
+
const [draftTopic, setDraftTopic] = createSignal("preferences");
|
|
142
|
+
const [draftTags, setDraftTags] = createSignal("");
|
|
143
|
+
const [draftProject, setDraftProject] = createSignal("global");
|
|
144
|
+
const [draftCore, setDraftCore] = createSignal(false);
|
|
145
|
+
const [draftFact, setDraftFact] = createSignal(props.initialDraftFact ?? "");
|
|
146
|
+
|
|
147
|
+
// External openers (commands, intercepted clicks) push state here.
|
|
148
|
+
createEffect(() => {
|
|
149
|
+
const q = olmPanelQuery();
|
|
150
|
+
if (q) setQuery(q);
|
|
151
|
+
});
|
|
152
|
+
createEffect(() => {
|
|
153
|
+
const ed = olmPanelEditor();
|
|
154
|
+
if (ed) {
|
|
155
|
+
setEditorMode(ed.mode);
|
|
156
|
+
setDraftFact(ed.draftFact);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
let requestCounter = 0;
|
|
161
|
+
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
162
|
+
|
|
163
|
+
const hits = createMemo<MemoryRpcHit[]>(() => data()?.hits ?? []);
|
|
164
|
+
const topics = createMemo<string[]>(() => data()?.topics ?? []);
|
|
165
|
+
const selectedHit = createMemo<MemoryRpcHit | undefined>(() => {
|
|
166
|
+
const list = hits();
|
|
167
|
+
const idx = Math.max(0, Math.min(selectedIndex(), Math.max(0, list.length - 1)));
|
|
168
|
+
return list[idx];
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
async function executeQuery(preferEntryId?: string) {
|
|
172
|
+
const seq = ++requestCounter;
|
|
173
|
+
setLoading(true);
|
|
174
|
+
setErrorMsg(undefined);
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const rpc = getRpcClient(props.ctx);
|
|
178
|
+
const res = await rpc.query({
|
|
179
|
+
query: query(),
|
|
180
|
+
typeFilter: typeFilter(),
|
|
181
|
+
topicFilter: topicFilter(),
|
|
182
|
+
mode: mode(),
|
|
183
|
+
limit: 80,
|
|
184
|
+
});
|
|
185
|
+
if (seq !== requestCounter) return;
|
|
186
|
+
setData(res);
|
|
187
|
+
if (preferEntryId) {
|
|
188
|
+
const idx = res.hits.findIndex((h) => h.entry.id === preferEntryId);
|
|
189
|
+
setSelectedIndex(idx >= 0 ? idx : 0);
|
|
190
|
+
} else {
|
|
191
|
+
setSelectedIndex((prev) => Math.max(0, Math.min(prev, Math.max(0, res.hits.length - 1))));
|
|
192
|
+
}
|
|
193
|
+
} catch (err) {
|
|
194
|
+
if (seq !== requestCounter) return;
|
|
195
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
196
|
+
} finally {
|
|
197
|
+
if (seq === requestCounter) {
|
|
198
|
+
setLoading(false);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function scheduleQuery() {
|
|
204
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
205
|
+
debounceTimer = setTimeout(() => {
|
|
206
|
+
void executeQuery();
|
|
207
|
+
}, 65);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
createEffect(() => {
|
|
211
|
+
void query();
|
|
212
|
+
void typeFilter();
|
|
213
|
+
void topicFilter();
|
|
214
|
+
void mode();
|
|
215
|
+
scheduleQuery();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
createEffect(() => {
|
|
219
|
+
const hit = selectedHit();
|
|
220
|
+
setConfirmDeleteId("");
|
|
221
|
+
if (!hit || !isSessionEntry(hit.entry)) {
|
|
222
|
+
setSessionMarkdown("");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let cancelled = false;
|
|
226
|
+
void (async () => {
|
|
227
|
+
try {
|
|
228
|
+
const res = await getRpcClient(props.ctx).getSessionMarkdown({ file: hit.entry.file });
|
|
229
|
+
if (!cancelled) setSessionMarkdown(res.markdown || hit.entry.fact);
|
|
230
|
+
} catch {
|
|
231
|
+
if (!cancelled) setSessionMarkdown(hit.entry.fact);
|
|
232
|
+
}
|
|
233
|
+
})();
|
|
234
|
+
onCleanup(() => {
|
|
235
|
+
cancelled = true;
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
onCleanup(() => {
|
|
240
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
function openAddEditor() {
|
|
244
|
+
const currentTopic = topicFilter() !== "all" ? topicFilter() : (topics()[0] || "preferences");
|
|
245
|
+
setEditorMode("add");
|
|
246
|
+
setEditId("");
|
|
247
|
+
setDraftTopic(currentTopic);
|
|
248
|
+
setDraftTags("");
|
|
249
|
+
setDraftProject("global");
|
|
250
|
+
setDraftCore(typeFilter() === "core");
|
|
251
|
+
setDraftFact("");
|
|
252
|
+
setConfirmDeleteId("");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function openEditEditor(hit?: MemoryRpcHit) {
|
|
256
|
+
const target = hit ?? selectedHit();
|
|
257
|
+
if (!target || isSessionEntry(target.entry)) {
|
|
258
|
+
props.ctx.toast.show({ title: "Only topic facts can be edited in-place", variant: "error" });
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
setEditId(target.entry.id);
|
|
262
|
+
setDraftTopic(entryTopicSlug(target.entry));
|
|
263
|
+
setDraftTags(target.entry.tags || "");
|
|
264
|
+
setDraftProject(target.entry.project || "global");
|
|
265
|
+
setDraftCore(Boolean(target.entry.core));
|
|
266
|
+
setDraftFact(target.entry.fact || "");
|
|
267
|
+
setConfirmDeleteId("");
|
|
268
|
+
setEditorMode("edit");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function saveDraft() {
|
|
272
|
+
const topicVal = draftTopic().trim();
|
|
273
|
+
const factVal = draftFact().trim();
|
|
274
|
+
if (!topicVal) {
|
|
275
|
+
props.ctx.toast.show({ title: "Topic slug is required", variant: "error" });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!factVal) {
|
|
279
|
+
props.ctx.toast.show({ title: "Memory fact cannot be empty", variant: "error" });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
setBusyAction(true);
|
|
283
|
+
try {
|
|
284
|
+
const res = await getRpcClient(props.ctx).store({
|
|
285
|
+
id: editorMode() === "edit" && editId() ? editId() : undefined,
|
|
286
|
+
topic: topicVal,
|
|
287
|
+
tags: draftTags().trim() || topicVal,
|
|
288
|
+
fact: factVal,
|
|
289
|
+
project: draftProject().trim() || "global",
|
|
290
|
+
core: draftCore(),
|
|
291
|
+
});
|
|
292
|
+
setEditorMode("none");
|
|
293
|
+
props.ctx.toast.show({
|
|
294
|
+
title: `${res.entry.updated ? "Updated" : "Stored"} [${res.entry.id}] (${res.entry.file})`,
|
|
295
|
+
variant: "success",
|
|
296
|
+
});
|
|
297
|
+
await executeQuery(res.entry.id);
|
|
298
|
+
} catch (err) {
|
|
299
|
+
props.ctx.toast.show({
|
|
300
|
+
title: err instanceof Error ? err.message : "Failed to save memory",
|
|
301
|
+
variant: "error",
|
|
302
|
+
});
|
|
303
|
+
} finally {
|
|
304
|
+
setBusyAction(false);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function toggleCorePin(hit?: MemoryRpcHit) {
|
|
309
|
+
const target = hit ?? selectedHit();
|
|
310
|
+
if (!target || isSessionEntry(target.entry)) return;
|
|
311
|
+
const nextCore = !target.entry.core;
|
|
312
|
+
setBusyAction(true);
|
|
313
|
+
try {
|
|
314
|
+
const res = await getRpcClient(props.ctx).store({
|
|
315
|
+
id: target.entry.id,
|
|
316
|
+
topic: entryTopicSlug(target.entry),
|
|
317
|
+
tags: target.entry.tags || entryTopicSlug(target.entry),
|
|
318
|
+
fact: target.entry.fact,
|
|
319
|
+
project: target.entry.project || "global",
|
|
320
|
+
core: nextCore,
|
|
321
|
+
});
|
|
322
|
+
props.ctx.toast.show({
|
|
323
|
+
title: `${nextCore ? "Pinned" : "Unpinned"} [${res.entry.id}]`,
|
|
324
|
+
variant: "success",
|
|
325
|
+
});
|
|
326
|
+
await executeQuery(res.entry.id);
|
|
327
|
+
} catch (err) {
|
|
328
|
+
props.ctx.toast.show({
|
|
329
|
+
title: err instanceof Error ? err.message : "Failed to update core pin",
|
|
330
|
+
variant: "error",
|
|
331
|
+
});
|
|
332
|
+
} finally {
|
|
333
|
+
setBusyAction(false);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async function handleDelete(hit?: MemoryRpcHit) {
|
|
338
|
+
const target = hit ?? selectedHit();
|
|
339
|
+
if (!target) return;
|
|
340
|
+
if (confirmDeleteId() !== target.entry.id) {
|
|
341
|
+
setConfirmDeleteId(target.entry.id);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
setBusyAction(true);
|
|
345
|
+
try {
|
|
346
|
+
const res = await getRpcClient(props.ctx).remove({ id: target.entry.id });
|
|
347
|
+
setConfirmDeleteId("");
|
|
348
|
+
if (res.deleted.length > 0) {
|
|
349
|
+
props.ctx.toast.show({
|
|
350
|
+
title: `Deleted ${res.deleted.map((d) => d.id).join(", ")}`,
|
|
351
|
+
variant: "success",
|
|
352
|
+
});
|
|
353
|
+
await executeQuery();
|
|
354
|
+
} else {
|
|
355
|
+
props.ctx.toast.show({
|
|
356
|
+
title: `Not found: ${target.entry.id}`,
|
|
357
|
+
variant: "error",
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
} catch (err) {
|
|
361
|
+
props.ctx.toast.show({
|
|
362
|
+
title: err instanceof Error ? err.message : "Delete failed",
|
|
363
|
+
variant: "error",
|
|
364
|
+
});
|
|
365
|
+
} finally {
|
|
366
|
+
setBusyAction(false);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function handleResync() {
|
|
371
|
+
setBusyAction(true);
|
|
372
|
+
try {
|
|
373
|
+
const res = await getRpcClient(props.ctx).sync({});
|
|
374
|
+
props.ctx.toast.show({
|
|
375
|
+
title: `Synced ${res.total} memories (${res.embedded} newly embedded)`,
|
|
376
|
+
variant: "success",
|
|
377
|
+
});
|
|
378
|
+
await executeQuery(selectedHit()?.entry.id);
|
|
379
|
+
} catch (err) {
|
|
380
|
+
props.ctx.toast.show({
|
|
381
|
+
title: err instanceof Error ? err.message : "Sync failed",
|
|
382
|
+
variant: "error",
|
|
383
|
+
});
|
|
384
|
+
} finally {
|
|
385
|
+
setBusyAction(false);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function handleImport() {
|
|
390
|
+
setBusyAction(true);
|
|
391
|
+
try {
|
|
392
|
+
const res = await getRpcClient(props.ctx).importMemory({ limit: 30 });
|
|
393
|
+
props.ctx.toast.show({
|
|
394
|
+
title: `Imported ${res.importedFactsCount} rules, ${res.importedSessionsCount} sessions (${res.total} total)`,
|
|
395
|
+
variant: "success",
|
|
396
|
+
});
|
|
397
|
+
await executeQuery(selectedHit()?.entry.id);
|
|
398
|
+
} catch (err) {
|
|
399
|
+
props.ctx.toast.show({
|
|
400
|
+
title: err instanceof Error ? err.message : "Import failed",
|
|
401
|
+
variant: "error",
|
|
402
|
+
});
|
|
403
|
+
} finally {
|
|
404
|
+
setBusyAction(false);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async function copyEntry(hit?: MemoryRpcHit) {
|
|
409
|
+
const target = hit ?? selectedHit();
|
|
410
|
+
if (!target) return;
|
|
411
|
+
const text = `[${target.entry.id}] (${target.entry.file}): ${target.entry.fact}`;
|
|
412
|
+
try {
|
|
413
|
+
await props.ctx.system.copy(text);
|
|
414
|
+
props.ctx.toast.show({ title: `Copied [${target.entry.id}]`, variant: "success" });
|
|
415
|
+
} catch {
|
|
416
|
+
// ignore
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
421
|
+
if (editorMode() !== "none") {
|
|
422
|
+
if (e.key === "Escape") {
|
|
423
|
+
e.preventDefault();
|
|
424
|
+
setEditorMode("none");
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") {
|
|
428
|
+
e.preventDefault();
|
|
429
|
+
void saveDraft();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (e.ctrlKey || e.metaKey) {
|
|
436
|
+
const k = e.key.toLowerCase();
|
|
437
|
+
if (k === "t") {
|
|
438
|
+
e.preventDefault();
|
|
439
|
+
setTypeFilter((c) => cycleValue(TYPE_CYCLE, c));
|
|
440
|
+
setSelectedIndex(0);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (k === "g") {
|
|
444
|
+
e.preventDefault();
|
|
445
|
+
const cycle = ["all", ...topics()];
|
|
446
|
+
setTopicFilter((c) => cycleValue(cycle, c));
|
|
447
|
+
setSelectedIndex(0);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (k === "r") {
|
|
451
|
+
e.preventDefault();
|
|
452
|
+
setMode((c) => cycleValue(MODE_CYCLE, c));
|
|
453
|
+
setSelectedIndex(0);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (k === "n") {
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
openAddEditor();
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (k === "e") {
|
|
462
|
+
e.preventDefault();
|
|
463
|
+
openEditEditor();
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (k === "p") {
|
|
467
|
+
e.preventDefault();
|
|
468
|
+
void toggleCorePin();
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (k === "d") {
|
|
472
|
+
e.preventDefault();
|
|
473
|
+
void handleDelete();
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (k === "l") {
|
|
477
|
+
e.preventDefault();
|
|
478
|
+
void handleResync();
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (e.key === "ArrowDown") {
|
|
484
|
+
e.preventDefault();
|
|
485
|
+
const maxIdx = Math.max(0, hits().length - 1);
|
|
486
|
+
setSelectedIndex((i) => Math.min(maxIdx, i + 1));
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (e.key === "ArrowUp") {
|
|
490
|
+
e.preventDefault();
|
|
491
|
+
setSelectedIndex((i) => Math.max(0, i - 1));
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const filterMenuItems = createMemo<UiMenuEntry[]>(() => {
|
|
497
|
+
const topicItems: UiMenuEntry[] = [
|
|
498
|
+
{
|
|
499
|
+
label: "All topics",
|
|
500
|
+
icon: topicFilter() === "all" ? "check-small" : undefined,
|
|
501
|
+
onSelect: () => {
|
|
502
|
+
setTopicFilter("all");
|
|
503
|
+
setSelectedIndex(0);
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
...topics().map((slug) => ({
|
|
507
|
+
label: slug,
|
|
508
|
+
icon: topicFilter() === slug ? ("check-small" as const) : undefined,
|
|
509
|
+
onSelect: () => {
|
|
510
|
+
setTopicFilter(slug);
|
|
511
|
+
setSelectedIndex(0);
|
|
512
|
+
},
|
|
513
|
+
})),
|
|
514
|
+
];
|
|
515
|
+
|
|
516
|
+
return [
|
|
517
|
+
{
|
|
518
|
+
type: "group",
|
|
519
|
+
label: "Search Mode",
|
|
520
|
+
items: (["hybrid", "keyword", "regex"] as MemoryModeFilter[]).map((m) => ({
|
|
521
|
+
label: MODE_LABELS[m],
|
|
522
|
+
icon: mode() === m ? "check-small" : undefined,
|
|
523
|
+
onSelect: () => {
|
|
524
|
+
setMode(m);
|
|
525
|
+
setSelectedIndex(0);
|
|
526
|
+
},
|
|
527
|
+
})),
|
|
528
|
+
},
|
|
529
|
+
{ type: "separator" },
|
|
530
|
+
{
|
|
531
|
+
type: "group",
|
|
532
|
+
label: "Topic Filter",
|
|
533
|
+
items: topicItems,
|
|
534
|
+
},
|
|
535
|
+
{ type: "separator" },
|
|
536
|
+
{
|
|
537
|
+
label: "Import rules & sessions",
|
|
538
|
+
icon: "download",
|
|
539
|
+
onSelect: () => {
|
|
540
|
+
void handleImport();
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
label: "Reset filters",
|
|
545
|
+
icon: "refresh",
|
|
546
|
+
disabled: typeFilter() === "all" && topicFilter() === "all" && mode() === "hybrid",
|
|
547
|
+
onSelect: () => {
|
|
548
|
+
setTypeFilter("all");
|
|
549
|
+
setTopicFilter("all");
|
|
550
|
+
setMode("hybrid");
|
|
551
|
+
setSelectedIndex(0);
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
];
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
const hasNonDefaultFilters = createMemo(
|
|
558
|
+
() => topicFilter() !== "all" || mode() !== "hybrid" || Boolean(errorMsg()),
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
return (
|
|
562
|
+
<div
|
|
563
|
+
class={`olm-root olm-root--${props.variant}`}
|
|
564
|
+
onKeyDown={handleKeyDown}
|
|
565
|
+
>
|
|
566
|
+
<div class="olm-header">
|
|
567
|
+
<div class="olm-toolbar">
|
|
568
|
+
<div class="olm-search-field">
|
|
569
|
+
<ui.TextInput
|
|
570
|
+
value={query()}
|
|
571
|
+
onInput={(val) => {
|
|
572
|
+
setQuery(val);
|
|
573
|
+
setSelectedIndex(0);
|
|
574
|
+
}}
|
|
575
|
+
label="Search memories"
|
|
576
|
+
placeholder="Search facts & session checkpoints, or filter with topic:preferences type:core..."
|
|
577
|
+
type="search"
|
|
578
|
+
size="large"
|
|
579
|
+
invalid={Boolean(errorMsg())}
|
|
580
|
+
autofocus={editorMode() === "none"}
|
|
581
|
+
/>
|
|
582
|
+
</div>
|
|
583
|
+
|
|
584
|
+
<div class="olm-toolbar-controls">
|
|
585
|
+
<div class="olm-segmented" role="group" aria-label="Memory type filter">
|
|
586
|
+
<For each={TYPE_CYCLE}>
|
|
587
|
+
{(t) => (
|
|
588
|
+
<button
|
|
589
|
+
type="button"
|
|
590
|
+
class={`olm-segment ${typeFilter() === t ? "olm-segment--active" : ""}`}
|
|
591
|
+
onClick={() => {
|
|
592
|
+
setTypeFilter(t);
|
|
593
|
+
setSelectedIndex(0);
|
|
594
|
+
}}
|
|
595
|
+
>
|
|
596
|
+
{TYPE_LABELS[t]}
|
|
597
|
+
</button>
|
|
598
|
+
)}
|
|
599
|
+
</For>
|
|
600
|
+
</div>
|
|
601
|
+
|
|
602
|
+
<ui.Menu
|
|
603
|
+
label="Filters"
|
|
604
|
+
icon="sliders"
|
|
605
|
+
trigger="button"
|
|
606
|
+
placement="bottom-end"
|
|
607
|
+
items={filterMenuItems()}
|
|
608
|
+
/>
|
|
609
|
+
|
|
610
|
+
<Show when={loading() || busyAction()}>
|
|
611
|
+
<ui.Loader size="small" />
|
|
612
|
+
</Show>
|
|
613
|
+
|
|
614
|
+
<ui.Tooltip value="Resync vector index" keys={["Ctrl", "L"]}>
|
|
615
|
+
<ui.IconButton
|
|
616
|
+
icon="refresh"
|
|
617
|
+
label="Resync vector index"
|
|
618
|
+
variant="ghost"
|
|
619
|
+
size="normal"
|
|
620
|
+
busy={busyAction()}
|
|
621
|
+
onClick={() => void handleResync()}
|
|
622
|
+
/>
|
|
623
|
+
</ui.Tooltip>
|
|
624
|
+
|
|
625
|
+
<ui.Button
|
|
626
|
+
variant="contrast"
|
|
627
|
+
size="small"
|
|
628
|
+
icon="plus-small"
|
|
629
|
+
onClick={() => openAddEditor()}
|
|
630
|
+
>
|
|
631
|
+
Add Memory
|
|
632
|
+
</ui.Button>
|
|
633
|
+
</div>
|
|
634
|
+
</div>
|
|
635
|
+
|
|
636
|
+
<Show when={hasNonDefaultFilters() || data()}>
|
|
637
|
+
<div class="olm-active-filters">
|
|
638
|
+
<div class="olm-chip-group">
|
|
639
|
+
<Show when={mode() !== "hybrid"}>
|
|
640
|
+
<button
|
|
641
|
+
type="button"
|
|
642
|
+
class="olm-chip"
|
|
643
|
+
onClick={() => setMode("hybrid")}
|
|
644
|
+
title="Reset search mode to Hybrid"
|
|
645
|
+
>
|
|
646
|
+
<span class="olm-chip-key">Mode:</span>
|
|
647
|
+
<span>{MODE_LABELS[mode()]}</span>
|
|
648
|
+
<ui.Icon name="close-small" size="small" />
|
|
649
|
+
</button>
|
|
650
|
+
</Show>
|
|
651
|
+
|
|
652
|
+
<Show when={topicFilter() !== "all"}>
|
|
653
|
+
<button
|
|
654
|
+
type="button"
|
|
655
|
+
class="olm-chip"
|
|
656
|
+
onClick={() => setTopicFilter("all")}
|
|
657
|
+
title="Clear topic filter"
|
|
658
|
+
>
|
|
659
|
+
<span class="olm-chip-key">Topic:</span>
|
|
660
|
+
<span>{topicFilter()}</span>
|
|
661
|
+
<ui.Icon name="close-small" size="small" />
|
|
662
|
+
</button>
|
|
663
|
+
</Show>
|
|
664
|
+
|
|
665
|
+
<Show when={errorMsg()}>
|
|
666
|
+
{(err) => (
|
|
667
|
+
<span style={{ "font-size": "11px", color: "var(--v2-state-fg-danger)" }}>
|
|
668
|
+
{err()}
|
|
669
|
+
</span>
|
|
670
|
+
)}
|
|
671
|
+
</Show>
|
|
672
|
+
</div>
|
|
673
|
+
|
|
674
|
+
<span class="olm-meta-summary">
|
|
675
|
+
{hits().length} of {data()?.totalEntries ?? 0} memories ({data()?.coreCount ?? 0} core)
|
|
676
|
+
</span>
|
|
677
|
+
</div>
|
|
678
|
+
</Show>
|
|
679
|
+
</div>
|
|
680
|
+
|
|
681
|
+
<div class="olm-split">
|
|
682
|
+
<div class="olm-column olm-column--list">
|
|
683
|
+
<div class="olm-scroll">
|
|
684
|
+
<Show
|
|
685
|
+
when={hits().length > 0}
|
|
686
|
+
fallback={
|
|
687
|
+
<div class="olm-empty">
|
|
688
|
+
<ui.Icon name="magnifying-glass" size="large" />
|
|
689
|
+
<div class="olm-empty-title">
|
|
690
|
+
{loading() ? "Loading persistent memories..." : "No matching memories"}
|
|
691
|
+
</div>
|
|
692
|
+
<div class="olm-empty-desc">
|
|
693
|
+
Try switching to All types, clearing topic filters, or click Add Memory to store a new fact.
|
|
694
|
+
</div>
|
|
695
|
+
</div>
|
|
696
|
+
}
|
|
697
|
+
>
|
|
698
|
+
<div class="olm-list" role="listbox" aria-label="Memory entries">
|
|
699
|
+
<For each={hits()}>
|
|
700
|
+
{(hit, idx) => {
|
|
701
|
+
const isSelected = () => idx() === selectedIndex() && editorMode() === "none";
|
|
702
|
+
return (
|
|
703
|
+
<button
|
|
704
|
+
type="button"
|
|
705
|
+
role="option"
|
|
706
|
+
aria-selected={isSelected()}
|
|
707
|
+
class={`olm-row ${isSelected() ? "olm-row--selected" : ""}`}
|
|
708
|
+
onClick={() => {
|
|
709
|
+
setEditorMode("none");
|
|
710
|
+
setSelectedIndex(idx());
|
|
711
|
+
}}
|
|
712
|
+
>
|
|
713
|
+
<div class="olm-row-top">
|
|
714
|
+
<span class="olm-row-id-wrap">
|
|
715
|
+
<Show when={hit.entry.core}>
|
|
716
|
+
<span class="olm-row-pin" title="Pinned Core Memory">
|
|
717
|
+
★
|
|
718
|
+
</span>
|
|
719
|
+
</Show>
|
|
720
|
+
<span class="olm-row-id">{hit.entry.id}</span>
|
|
721
|
+
</span>
|
|
722
|
+
<span class="olm-row-meta">
|
|
723
|
+
<Show when={hit.entry.core}>
|
|
724
|
+
<span class="olm-badge olm-badge--core">core</span>
|
|
725
|
+
</Show>
|
|
726
|
+
<span class="olm-badge">
|
|
727
|
+
{entryTopicSlug(hit.entry)}
|
|
728
|
+
</span>
|
|
729
|
+
<Show when={query().trim().length > 0 && hit.score > 0}>
|
|
730
|
+
<span class="olm-row-score">{hit.score.toFixed(2)}</span>
|
|
731
|
+
</Show>
|
|
732
|
+
</span>
|
|
733
|
+
</div>
|
|
734
|
+
|
|
735
|
+
<div class="olm-row-fact">
|
|
736
|
+
<For each={splitHighlightedParts(hit.entry.fact, query())}>
|
|
737
|
+
{(part) => (
|
|
738
|
+
<Show when={part.match} fallback={<span>{part.text}</span>}>
|
|
739
|
+
<mark class="olm-mark">{part.text}</mark>
|
|
740
|
+
</Show>
|
|
741
|
+
)}
|
|
742
|
+
</For>
|
|
743
|
+
</div>
|
|
744
|
+
</button>
|
|
745
|
+
);
|
|
746
|
+
}}
|
|
747
|
+
</For>
|
|
748
|
+
</div>
|
|
749
|
+
</Show>
|
|
750
|
+
</div>
|
|
751
|
+
</div>
|
|
752
|
+
|
|
753
|
+
<div class="olm-column olm-column--detail">
|
|
754
|
+
<Show
|
|
755
|
+
when={editorMode() === "none"}
|
|
756
|
+
fallback={
|
|
757
|
+
<>
|
|
758
|
+
<div class="olm-detail-bar">
|
|
759
|
+
<div class="olm-detail-heading">
|
|
760
|
+
<h3 class="olm-detail-title">
|
|
761
|
+
{editorMode() === "add" ? "Add New Memory Fact" : `Edit Memory [${editId()}]`}
|
|
762
|
+
</h3>
|
|
763
|
+
<div class="olm-detail-subtitle">
|
|
764
|
+
<span>Saves to topics/{draftTopic() || "preferences"}.md and updates semantic vectors immediately</span>
|
|
765
|
+
</div>
|
|
766
|
+
</div>
|
|
767
|
+
<div class="olm-detail-actions">
|
|
768
|
+
<ui.Button
|
|
769
|
+
variant="ghost"
|
|
770
|
+
size="small"
|
|
771
|
+
onClick={() => setEditorMode("none")}
|
|
772
|
+
>
|
|
773
|
+
Cancel
|
|
774
|
+
</ui.Button>
|
|
775
|
+
<ui.Button
|
|
776
|
+
variant="contrast"
|
|
777
|
+
size="small"
|
|
778
|
+
icon="check-small"
|
|
779
|
+
busy={busyAction()}
|
|
780
|
+
onClick={() => void saveDraft()}
|
|
781
|
+
>
|
|
782
|
+
{editorMode() === "add" ? "Save Memory" : "Save Changes"}
|
|
783
|
+
</ui.Button>
|
|
784
|
+
</div>
|
|
785
|
+
</div>
|
|
786
|
+
|
|
787
|
+
<div class="olm-scroll">
|
|
788
|
+
<div class="olm-form">
|
|
789
|
+
<div class="olm-form-row">
|
|
790
|
+
<div class="olm-form-group">
|
|
791
|
+
<label class="olm-form-label">Topic Slug</label>
|
|
792
|
+
<input
|
|
793
|
+
type="text"
|
|
794
|
+
class="olm-input"
|
|
795
|
+
value={draftTopic()}
|
|
796
|
+
placeholder="e.g. preferences, decisions, environment"
|
|
797
|
+
onInput={(e) => setDraftTopic(e.currentTarget.value)}
|
|
798
|
+
/>
|
|
799
|
+
<Show when={topics().length > 0}>
|
|
800
|
+
<div class="olm-topic-suggestions">
|
|
801
|
+
<For each={topics().slice(0, 8)}>
|
|
802
|
+
{(slug) => (
|
|
803
|
+
<button
|
|
804
|
+
type="button"
|
|
805
|
+
class={`olm-topic-pill ${draftTopic() === slug ? "olm-topic-pill--active" : ""}`}
|
|
806
|
+
onClick={() => setDraftTopic(slug)}
|
|
807
|
+
>
|
|
808
|
+
{slug}
|
|
809
|
+
</button>
|
|
810
|
+
)}
|
|
811
|
+
</For>
|
|
812
|
+
</div>
|
|
813
|
+
</Show>
|
|
814
|
+
</div>
|
|
815
|
+
|
|
816
|
+
<div class="olm-form-group">
|
|
817
|
+
<label class="olm-form-label">Project Scope</label>
|
|
818
|
+
<input
|
|
819
|
+
type="text"
|
|
820
|
+
class="olm-input"
|
|
821
|
+
value={draftProject()}
|
|
822
|
+
placeholder="global or project slug (e.g. git/opencode-plugins)"
|
|
823
|
+
onInput={(e) => setDraftProject(e.currentTarget.value)}
|
|
824
|
+
/>
|
|
825
|
+
</div>
|
|
826
|
+
</div>
|
|
827
|
+
|
|
828
|
+
<div class="olm-form-group">
|
|
829
|
+
<label class="olm-form-label">Tags (comma-separated keywords)</label>
|
|
830
|
+
<input
|
|
831
|
+
type="text"
|
|
832
|
+
class="olm-input"
|
|
833
|
+
value={draftTags()}
|
|
834
|
+
placeholder="e.g. opencode, desktop, gui, preferences"
|
|
835
|
+
onInput={(e) => setDraftTags(e.currentTarget.value)}
|
|
836
|
+
/>
|
|
837
|
+
</div>
|
|
838
|
+
|
|
839
|
+
<div class="olm-form-group">
|
|
840
|
+
<ui.Switch
|
|
841
|
+
checked={draftCore()}
|
|
842
|
+
onChange={(checked) => setDraftCore(checked)}
|
|
843
|
+
label="Pin as Core Memory"
|
|
844
|
+
description="Core memories are always injected on every turn regardless of prompt query."
|
|
845
|
+
/>
|
|
846
|
+
</div>
|
|
847
|
+
|
|
848
|
+
<div class="olm-form-group">
|
|
849
|
+
<label class="olm-form-label">Memory Fact</label>
|
|
850
|
+
<textarea
|
|
851
|
+
class="olm-textarea"
|
|
852
|
+
value={draftFact()}
|
|
853
|
+
placeholder="Write a concise, authoritative statement of the rule, decision, preference, or environment fact..."
|
|
854
|
+
onInput={(e) => setDraftFact(e.currentTarget.value)}
|
|
855
|
+
autofocus
|
|
856
|
+
/>
|
|
857
|
+
</div>
|
|
858
|
+
</div>
|
|
859
|
+
</div>
|
|
860
|
+
</>
|
|
861
|
+
}
|
|
862
|
+
>
|
|
863
|
+
<Show
|
|
864
|
+
when={selectedHit()}
|
|
865
|
+
fallback={
|
|
866
|
+
<div class="olm-empty">
|
|
867
|
+
<ui.Icon name="bubble-5" size="large" />
|
|
868
|
+
<div class="olm-empty-title">Select a memory to inspect or manage</div>
|
|
869
|
+
<div class="olm-empty-desc">
|
|
870
|
+
View full details, pin/unpin core memories, edit topic facts in-place, or delete outdated entries.
|
|
871
|
+
</div>
|
|
872
|
+
</div>
|
|
873
|
+
}
|
|
874
|
+
>
|
|
875
|
+
{(hit) => (
|
|
876
|
+
<>
|
|
877
|
+
<div class="olm-detail-bar">
|
|
878
|
+
<div class="olm-detail-heading">
|
|
879
|
+
<h3 class="olm-detail-title">
|
|
880
|
+
<Show when={hit().entry.core}>
|
|
881
|
+
<span class="olm-row-pin" title="Pinned Core Memory">
|
|
882
|
+
★
|
|
883
|
+
</span>
|
|
884
|
+
</Show>
|
|
885
|
+
<span>{hit().entry.id}</span>
|
|
886
|
+
</h3>
|
|
887
|
+
<div class="olm-detail-subtitle">
|
|
888
|
+
<span>{hit().entry.file}</span>
|
|
889
|
+
<Show when={hit().entry.date}>
|
|
890
|
+
<span>·</span>
|
|
891
|
+
<span>Updated {hit().entry.date}</span>
|
|
892
|
+
</Show>
|
|
893
|
+
</div>
|
|
894
|
+
</div>
|
|
895
|
+
|
|
896
|
+
<div class="olm-detail-actions">
|
|
897
|
+
<Show when={!isSessionEntry(hit().entry)}>
|
|
898
|
+
<ui.Button
|
|
899
|
+
variant="neutral"
|
|
900
|
+
size="small"
|
|
901
|
+
busy={busyAction()}
|
|
902
|
+
onClick={() => void toggleCorePin(hit())}
|
|
903
|
+
>
|
|
904
|
+
{hit().entry.core ? "Unpin Core" : "Pin Core"}
|
|
905
|
+
</ui.Button>
|
|
906
|
+
<ui.Button
|
|
907
|
+
variant="neutral"
|
|
908
|
+
size="small"
|
|
909
|
+
icon="edit"
|
|
910
|
+
onClick={() => openEditEditor(hit())}
|
|
911
|
+
>
|
|
912
|
+
Edit
|
|
913
|
+
</ui.Button>
|
|
914
|
+
</Show>
|
|
915
|
+
|
|
916
|
+
<ui.Tooltip value="Copy memory entry">
|
|
917
|
+
<ui.IconButton
|
|
918
|
+
icon="copy"
|
|
919
|
+
label="Copy memory entry"
|
|
920
|
+
variant="ghost"
|
|
921
|
+
size="small"
|
|
922
|
+
onClick={() => void copyEntry(hit())}
|
|
923
|
+
/>
|
|
924
|
+
</ui.Tooltip>
|
|
925
|
+
|
|
926
|
+
<ui.Button
|
|
927
|
+
variant="danger"
|
|
928
|
+
size="small"
|
|
929
|
+
icon="trash"
|
|
930
|
+
busy={busyAction()}
|
|
931
|
+
onClick={() => void handleDelete(hit())}
|
|
932
|
+
>
|
|
933
|
+
{confirmDeleteId() === hit().entry.id ? "Confirm Delete" : "Delete"}
|
|
934
|
+
</ui.Button>
|
|
935
|
+
</div>
|
|
936
|
+
</div>
|
|
937
|
+
|
|
938
|
+
<div class="olm-scroll">
|
|
939
|
+
<div class="olm-detail-body">
|
|
940
|
+
<div class="olm-field-grid">
|
|
941
|
+
<div class="olm-field-card">
|
|
942
|
+
<span class="olm-field-label">Type</span>
|
|
943
|
+
<span class="olm-field-value">
|
|
944
|
+
{isSessionEntry(hit().entry) ? "Session Checkpoint" : "Topic Fact"}
|
|
945
|
+
</span>
|
|
946
|
+
</div>
|
|
947
|
+
<div class="olm-field-card">
|
|
948
|
+
<span class="olm-field-label">Topic</span>
|
|
949
|
+
<span class="olm-field-value">{entryTopicSlug(hit().entry)}</span>
|
|
950
|
+
</div>
|
|
951
|
+
<div class="olm-field-card">
|
|
952
|
+
<span class="olm-field-label">Project Scope</span>
|
|
953
|
+
<span class="olm-field-value">{hit().entry.project || "global"}</span>
|
|
954
|
+
</div>
|
|
955
|
+
<div class="olm-field-card">
|
|
956
|
+
<span class="olm-field-label">Core Status</span>
|
|
957
|
+
<span class="olm-field-value">
|
|
958
|
+
{hit().entry.core ? "★ Pinned (Always recalled)" : "Contextual recall"}
|
|
959
|
+
</span>
|
|
960
|
+
</div>
|
|
961
|
+
</div>
|
|
962
|
+
|
|
963
|
+
<Show when={entryTagsList(hit().entry).length > 0}>
|
|
964
|
+
<div class="olm-tags-list">
|
|
965
|
+
<For each={entryTagsList(hit().entry)}>
|
|
966
|
+
{(tag) => <span class="olm-tag">#{tag}</span>}
|
|
967
|
+
</For>
|
|
968
|
+
</div>
|
|
969
|
+
</Show>
|
|
970
|
+
|
|
971
|
+
<Show
|
|
972
|
+
when={isSessionEntry(hit().entry) && sessionMarkdown()}
|
|
973
|
+
fallback={
|
|
974
|
+
<div class="olm-fact-box">
|
|
975
|
+
<For each={splitHighlightedParts(hit().entry.fact, query())}>
|
|
976
|
+
{(part) => (
|
|
977
|
+
<Show when={part.match} fallback={<span>{part.text}</span>}>
|
|
978
|
+
<mark class="olm-mark">{part.text}</mark>
|
|
979
|
+
</Show>
|
|
980
|
+
)}
|
|
981
|
+
</For>
|
|
982
|
+
</div>
|
|
983
|
+
}
|
|
984
|
+
>
|
|
985
|
+
<div class="olm-fact-box">
|
|
986
|
+
<ui.Markdown text={sessionMarkdown()} />
|
|
987
|
+
</div>
|
|
988
|
+
</Show>
|
|
989
|
+
</div>
|
|
990
|
+
</div>
|
|
991
|
+
</>
|
|
992
|
+
)}
|
|
993
|
+
</Show>
|
|
994
|
+
</Show>
|
|
995
|
+
</div>
|
|
996
|
+
</div>
|
|
997
|
+
</div>
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// Module-level signals so commands/slots can drive the shared panel's state
|
|
1002
|
+
// without re-mounting MemorySurface (one persistent side panel, no modals).
|
|
1003
|
+
const [olmPanelQuery, setOlmPanelQuery] = createSignal("");
|
|
1004
|
+
const [olmPanelEditor, setOlmPanelEditor] = createSignal<{
|
|
1005
|
+
mode: "none" | "add";
|
|
1006
|
+
draftFact: string;
|
|
1007
|
+
} | null>(null);
|
|
1008
|
+
|
|
1009
|
+
let memoryFallbackDialog: { close(): void } | undefined;
|
|
1010
|
+
|
|
1011
|
+
function openMemoryPanel(
|
|
1012
|
+
ctx: PluginContext,
|
|
1013
|
+
initialQuery = "",
|
|
1014
|
+
initialEditorMode: "none" | "add" = "none",
|
|
1015
|
+
initialDraftFact = "",
|
|
1016
|
+
) {
|
|
1017
|
+
if (initialQuery) setOlmPanelQuery(initialQuery);
|
|
1018
|
+
if (initialEditorMode !== "none" || initialDraftFact) {
|
|
1019
|
+
setOlmPanelEditor({ mode: initialEditorMode, draftFact: initialDraftFact });
|
|
1020
|
+
}
|
|
1021
|
+
const session = ctx.sessions.current();
|
|
1022
|
+
if (!session) {
|
|
1023
|
+
if (memoryFallbackDialog) return;
|
|
1024
|
+
const ui = ctx.ui;
|
|
1025
|
+
memoryFallbackDialog = ctx.dialogs.open((dialog) => {
|
|
1026
|
+
onCleanup(() => { memoryFallbackDialog = undefined; });
|
|
1027
|
+
return (
|
|
1028
|
+
<ui.Dialog title="Memory Manager" size="x-large">
|
|
1029
|
+
<MemorySurface ctx={ctx} variant="modal" initialQuery={initialQuery} initialEditorMode={initialEditorMode} initialDraftFact={initialDraftFact} onClose={dialog.close} />
|
|
1030
|
+
</ui.Dialog>
|
|
1031
|
+
);
|
|
1032
|
+
});
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
memoryFallbackDialog?.close();
|
|
1036
|
+
try {
|
|
1037
|
+
// Always select the tab so it becomes the focused panel even if another
|
|
1038
|
+
// panel (usage, search, backups) is already open.
|
|
1039
|
+
ctx.layout.open(`${ctx.id}:memory`, session);
|
|
1040
|
+
} catch {
|
|
1041
|
+
// Layout not ready; retry on next interaction.
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
export default Plugin.define({
|
|
1046
|
+
i18n: {
|
|
1047
|
+
en: {
|
|
1048
|
+
"memory.command.title": "Memory Manager...",
|
|
1049
|
+
"memory.command.description": "Search, add, edit, pin, and delete persistent local memories",
|
|
1050
|
+
"memory.panel": "Memory",
|
|
1051
|
+
"memory.panel.toggle": "Toggle Memory Panel",
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
setup(ctx) {
|
|
1055
|
+
ctx.add(Style, css);
|
|
1056
|
+
|
|
1057
|
+
ctx.add(Command, () => ({
|
|
1058
|
+
id: "memory",
|
|
1059
|
+
title: ctx.t("memory.command.title"),
|
|
1060
|
+
description: ctx.t("memory.command.description"),
|
|
1061
|
+
keywords: "memory facts recall core topics sessions vectors embeddings",
|
|
1062
|
+
group: "Session",
|
|
1063
|
+
section: "session",
|
|
1064
|
+
bind: "mod+shift+m",
|
|
1065
|
+
slash: {
|
|
1066
|
+
name: "memory",
|
|
1067
|
+
arguments: true,
|
|
1068
|
+
},
|
|
1069
|
+
featured: true,
|
|
1070
|
+
run(input) {
|
|
1071
|
+
openMemoryPanel(ctx, input ?? "");
|
|
1072
|
+
},
|
|
1073
|
+
}));
|
|
1074
|
+
|
|
1075
|
+
ctx.add(Command, () => ({
|
|
1076
|
+
id: "memory-add",
|
|
1077
|
+
title: "Add Memory Fact...",
|
|
1078
|
+
description: "Add a new persistent memory fact (<topic> | <tags> | <fact> or interactive form)",
|
|
1079
|
+
keywords: "memory store add fact rule preference",
|
|
1080
|
+
group: "Session",
|
|
1081
|
+
section: "session",
|
|
1082
|
+
slash: {
|
|
1083
|
+
name: "memory-add",
|
|
1084
|
+
arguments: true,
|
|
1085
|
+
},
|
|
1086
|
+
run(input) {
|
|
1087
|
+
const raw = (input ?? "").trim();
|
|
1088
|
+
if (raw.includes("|")) {
|
|
1089
|
+
const parts = raw
|
|
1090
|
+
.split("|")
|
|
1091
|
+
.map((s) => s.trim())
|
|
1092
|
+
.filter(Boolean);
|
|
1093
|
+
if (parts.length >= 3) {
|
|
1094
|
+
const topic = parts[0];
|
|
1095
|
+
const tags = parts[1];
|
|
1096
|
+
const fact = parts.slice(2).join(" | ");
|
|
1097
|
+
void getRpcClient(ctx)
|
|
1098
|
+
.store({ topic, tags, fact })
|
|
1099
|
+
.then((res) => {
|
|
1100
|
+
ctx.toast.show({
|
|
1101
|
+
title: `Stored [${res.entry.id}] in ${res.entry.file}`,
|
|
1102
|
+
variant: "success",
|
|
1103
|
+
});
|
|
1104
|
+
})
|
|
1105
|
+
.catch((err) => {
|
|
1106
|
+
ctx.toast.show({
|
|
1107
|
+
title: err instanceof Error ? err.message : "Failed to store memory",
|
|
1108
|
+
variant: "error",
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
openMemoryPanel(ctx, "", "add", raw);
|
|
1115
|
+
},
|
|
1116
|
+
}));
|
|
1117
|
+
|
|
1118
|
+
ctx.add(Command, () => ({
|
|
1119
|
+
id: "memory-delete",
|
|
1120
|
+
title: "Delete Memory Entry...",
|
|
1121
|
+
description: "Delete a persistent memory entry by ID",
|
|
1122
|
+
keywords: "memory delete remove prune",
|
|
1123
|
+
group: "Session",
|
|
1124
|
+
section: "session",
|
|
1125
|
+
slash: {
|
|
1126
|
+
name: "memory-delete",
|
|
1127
|
+
arguments: true,
|
|
1128
|
+
},
|
|
1129
|
+
run(input) {
|
|
1130
|
+
const raw = (input ?? "").trim();
|
|
1131
|
+
if (!raw) {
|
|
1132
|
+
openMemoryPanel(ctx, "");
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
void getRpcClient(ctx)
|
|
1136
|
+
.remove({ id: raw })
|
|
1137
|
+
.then((res) => {
|
|
1138
|
+
if (res.deleted.length > 0) {
|
|
1139
|
+
ctx.toast.show({
|
|
1140
|
+
title: `Deleted ${res.deleted.map((d) => d.id).join(", ")}`,
|
|
1141
|
+
variant: "success",
|
|
1142
|
+
});
|
|
1143
|
+
} else {
|
|
1144
|
+
ctx.toast.show({
|
|
1145
|
+
title: `Not found: ${raw}`,
|
|
1146
|
+
variant: "error",
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
})
|
|
1150
|
+
.catch((err) => {
|
|
1151
|
+
ctx.toast.show({
|
|
1152
|
+
title: err instanceof Error ? err.message : "Delete failed",
|
|
1153
|
+
variant: "error",
|
|
1154
|
+
});
|
|
1155
|
+
});
|
|
1156
|
+
},
|
|
1157
|
+
}));
|
|
1158
|
+
|
|
1159
|
+
ctx.add(Command, () => ({
|
|
1160
|
+
id: "memory-import",
|
|
1161
|
+
title: "Import Existing Memories",
|
|
1162
|
+
description: "Import rules from AGENTS.md/CLAUDE.md and compacted sessions from opencode.db",
|
|
1163
|
+
keywords: "memory import rules sessions bootstrap",
|
|
1164
|
+
group: "Session",
|
|
1165
|
+
section: "session",
|
|
1166
|
+
slash: {
|
|
1167
|
+
name: "memory-import",
|
|
1168
|
+
arguments: true,
|
|
1169
|
+
},
|
|
1170
|
+
run(input) {
|
|
1171
|
+
const limitNum = Number.parseInt((input ?? "").trim(), 10);
|
|
1172
|
+
const limit = Number.isFinite(limitNum) && limitNum > 0 ? limitNum : 30;
|
|
1173
|
+
void getRpcClient(ctx)
|
|
1174
|
+
.importMemory({ limit })
|
|
1175
|
+
.then((res) => {
|
|
1176
|
+
ctx.toast.show({
|
|
1177
|
+
title: `Imported ${res.importedFactsCount} rules, ${res.importedSessionsCount} sessions (${res.total} total)`,
|
|
1178
|
+
variant: "success",
|
|
1179
|
+
});
|
|
1180
|
+
})
|
|
1181
|
+
.catch((err) => {
|
|
1182
|
+
ctx.toast.show({
|
|
1183
|
+
title: err instanceof Error ? err.message : "Import failed",
|
|
1184
|
+
variant: "error",
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
},
|
|
1188
|
+
}));
|
|
1189
|
+
|
|
1190
|
+
const panelTabKey = `${ctx.id}:memory`;
|
|
1191
|
+
const memoryTab: PanelTab = {
|
|
1192
|
+
id: "memory",
|
|
1193
|
+
get title() {
|
|
1194
|
+
return ctx.t("memory.panel");
|
|
1195
|
+
},
|
|
1196
|
+
closable: "compact",
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
ctx.add(Command, () => ({
|
|
1200
|
+
id: "memory-panel",
|
|
1201
|
+
title: ctx.t("memory.panel.toggle"),
|
|
1202
|
+
description: "Toggle the persistent Memory Manager side panel",
|
|
1203
|
+
keywords: "memory panel sidebar facts core",
|
|
1204
|
+
group: "Session",
|
|
1205
|
+
section: "session",
|
|
1206
|
+
bind: "mod+alt+m",
|
|
1207
|
+
run() {
|
|
1208
|
+
const session = ctx.sessions.current();
|
|
1209
|
+
if (session) {
|
|
1210
|
+
ctx.layout.toggle(panelTabKey, session);
|
|
1211
|
+
} else {
|
|
1212
|
+
openMemoryPanel(ctx, "");
|
|
1213
|
+
}
|
|
1214
|
+
},
|
|
1215
|
+
}));
|
|
1216
|
+
|
|
1217
|
+
ctx.add(MenuItem, () => {
|
|
1218
|
+
const session = ctx.sessions.current();
|
|
1219
|
+
return {
|
|
1220
|
+
menu: "session.panel",
|
|
1221
|
+
id: "memory",
|
|
1222
|
+
title: ctx.t("memory.panel"),
|
|
1223
|
+
description: ctx.t("memory.command.description"),
|
|
1224
|
+
icon: "outline-brain",
|
|
1225
|
+
keybind: `${ctx.id}.memory-panel`,
|
|
1226
|
+
opened: !!session && ctx.layout.state(panelTabKey, session) !== "closed",
|
|
1227
|
+
run() {
|
|
1228
|
+
const current = ctx.sessions.current();
|
|
1229
|
+
if (current) {
|
|
1230
|
+
ctx.layout.toggle(panelTabKey, current);
|
|
1231
|
+
} else {
|
|
1232
|
+
openMemoryPanel(ctx, "");
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
};
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
if (typeof document !== "undefined") {
|
|
1239
|
+
const ensureTopLeftMemoriesButton = () => {
|
|
1240
|
+
const searchBtn = document.querySelector<HTMLButtonElement>(
|
|
1241
|
+
'header[data-slot="titlebar-v2"] button[aria-label*="Search"]',
|
|
1242
|
+
);
|
|
1243
|
+
if (searchBtn && searchBtn.parentElement) {
|
|
1244
|
+
const container = searchBtn.parentElement;
|
|
1245
|
+
if (!container.querySelector('[data-action="titlebar-memories"]')) {
|
|
1246
|
+
const btn = document.createElement("button");
|
|
1247
|
+
btn.type = "button";
|
|
1248
|
+
btn.setAttribute("data-action", "titlebar-memories");
|
|
1249
|
+
btn.setAttribute("aria-label", "Memory Manager (Ctrl+Shift+M)");
|
|
1250
|
+
btn.setAttribute("title", "Memory Manager (Ctrl+Shift+M)");
|
|
1251
|
+
btn.className = "olm-titlebar-quick-btn";
|
|
1252
|
+
btn.innerHTML =
|
|
1253
|
+
'<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><use href="#opencode-v2-icon-outline-brain"></use></svg>';
|
|
1254
|
+
btn.addEventListener("click", (e) => {
|
|
1255
|
+
e.preventDefault();
|
|
1256
|
+
e.stopPropagation();
|
|
1257
|
+
openMemoryPanel(ctx, "");
|
|
1258
|
+
});
|
|
1259
|
+
container.appendChild(btn);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const vertSearchBtn = document.querySelector<HTMLButtonElement>(
|
|
1264
|
+
'button[data-action="vertical-tabs-search"]',
|
|
1265
|
+
);
|
|
1266
|
+
if (vertSearchBtn && vertSearchBtn.parentElement) {
|
|
1267
|
+
const vertContainer = vertSearchBtn.parentElement;
|
|
1268
|
+
if (!vertContainer.querySelector('[data-action="vertical-tabs-memories"]')) {
|
|
1269
|
+
const vBtn = document.createElement("button");
|
|
1270
|
+
vBtn.type = "button";
|
|
1271
|
+
vBtn.setAttribute("data-titlebar-tab-action", "");
|
|
1272
|
+
vBtn.setAttribute("data-action", "vertical-tabs-memories");
|
|
1273
|
+
vBtn.setAttribute("aria-label", "Memories (Ctrl+Shift+M)");
|
|
1274
|
+
vBtn.className =
|
|
1275
|
+
"group flex h-7 w-full shrink-0 items-center gap-1.5 rounded-[6px] ps-1.5 pe-2 text-[13px] leading-4 text-v2-text-text-faint hover:text-v2-text-text-base";
|
|
1276
|
+
vBtn.innerHTML =
|
|
1277
|
+
'<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" class="shrink-0" aria-hidden="true"><use href="#opencode-v2-icon-outline-brain"></use></svg>' +
|
|
1278
|
+
'<span class="min-w-0 truncate whitespace-nowrap">Memories</span>';
|
|
1279
|
+
vBtn.addEventListener("click", (e) => {
|
|
1280
|
+
e.preventDefault();
|
|
1281
|
+
e.stopPropagation();
|
|
1282
|
+
openMemoryPanel(ctx, "");
|
|
1283
|
+
});
|
|
1284
|
+
vertSearchBtn.insertAdjacentElement("afterend", vBtn);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
ensureTopLeftMemoriesButton();
|
|
1290
|
+
const observer = new MutationObserver(() => {
|
|
1291
|
+
ensureTopLeftMemoriesButton();
|
|
1292
|
+
});
|
|
1293
|
+
if (document.body) {
|
|
1294
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
1295
|
+
}
|
|
1296
|
+
onCleanup(() => {
|
|
1297
|
+
observer.disconnect();
|
|
1298
|
+
document
|
|
1299
|
+
.querySelectorAll(
|
|
1300
|
+
'[data-action="titlebar-memories"], [data-action="vertical-tabs-memories"]',
|
|
1301
|
+
)
|
|
1302
|
+
.forEach((el) => el.remove());
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
ctx.add(Panel, {
|
|
1307
|
+
id: "memory",
|
|
1308
|
+
region: "side",
|
|
1309
|
+
list: (input) => (input.open.includes("memory") ? [memoryTab] : []),
|
|
1310
|
+
render: () => <MemorySurface ctx={ctx} variant="panel" />,
|
|
1311
|
+
});
|
|
1312
|
+
},
|
|
1313
|
+
});
|