@nandoblanco/opencode-local-memory 1.0.0 → 1.1.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/README.md +42 -22
- package/index.js +1637 -101
- package/package.json +1 -1
- package/tui.ts +285 -67
package/package.json
CHANGED
package/tui.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
5
7
|
import type { TuiPluginContext } from "@opencode-ai/plugin/tui";
|
|
6
8
|
import { TextAttributes } from "@opentui/core";
|
|
7
9
|
import {
|
|
@@ -24,8 +26,11 @@ import {
|
|
|
24
26
|
Show,
|
|
25
27
|
} from "solid-js";
|
|
26
28
|
import {
|
|
29
|
+
deleteMemoryEntry,
|
|
27
30
|
getTopicSlugs,
|
|
31
|
+
importExistingMemory,
|
|
28
32
|
loadCachedVectors,
|
|
33
|
+
matchesProjectScope,
|
|
29
34
|
resolveMemoryDir,
|
|
30
35
|
searchMemory,
|
|
31
36
|
storeMemoryFact,
|
|
@@ -38,6 +43,8 @@ interface MemoryEntry {
|
|
|
38
43
|
file: string;
|
|
39
44
|
tags: string;
|
|
40
45
|
fact: string;
|
|
46
|
+
project?: string;
|
|
47
|
+
core?: boolean;
|
|
41
48
|
vector?: number[];
|
|
42
49
|
_haystack?: string;
|
|
43
50
|
}
|
|
@@ -53,6 +60,43 @@ type ModeFilter = "hybrid" | "keyword" | "regex";
|
|
|
53
60
|
|
|
54
61
|
const TYPE_CYCLE: TypeFilter[] = ["all", "topics", "sessions"];
|
|
55
62
|
const MODE_CYCLE: ModeFilter[] = ["hybrid", "keyword", "regex"];
|
|
63
|
+
const CLI_SCRIPT_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "index.js");
|
|
64
|
+
|
|
65
|
+
function runCliSubprocess(args: string[]): Promise<string> {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const baseEnv = { ...process.env, OPENCODE_MEMORY_SUBPROCESS: "1" };
|
|
68
|
+
execFile("node", [CLI_SCRIPT_PATH, ...args], { env: baseEnv, windowsHide: true, timeout: 120000 }, (err, stdout) => {
|
|
69
|
+
if (!err) return resolve(String(stdout || ""));
|
|
70
|
+
const bunEnv = { ...baseEnv, BUN_BE_BUN: "1" };
|
|
71
|
+
execFile(process.execPath, [CLI_SCRIPT_PATH, ...args], { env: bunEnv, windowsHide: true, timeout: 120000 }, (err2, stdout2) => {
|
|
72
|
+
if (err2) return reject(err);
|
|
73
|
+
resolve(String(stdout2 || ""));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function safeSyncVectors(rootDir: string) {
|
|
80
|
+
try {
|
|
81
|
+
return await syncVectors(rootDir);
|
|
82
|
+
} catch {
|
|
83
|
+
await runCliSubprocess(["sync", "--dir", rootDir]);
|
|
84
|
+
const loaded = (loadCachedVectors(rootDir) || []) as MemoryEntry[];
|
|
85
|
+
return { total: loaded.length, embedded: 0, reused: loaded.length, vecFile: path.join(rootDir, "vectors.json") };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function safeImportMemory(rootDir: string, limit?: number) {
|
|
90
|
+
try {
|
|
91
|
+
return await importExistingMemory(rootDir, { limit });
|
|
92
|
+
} catch {
|
|
93
|
+
const args = ["import", "--dir", rootDir, "--json"];
|
|
94
|
+
if (limit) args.push("--limit", String(limit));
|
|
95
|
+
const stdout = await runCliSubprocess(args);
|
|
96
|
+
const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
|
|
97
|
+
return JSON.parse(lines[lines.length - 1]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
56
100
|
|
|
57
101
|
function splitHighlightedText(
|
|
58
102
|
text: string,
|
|
@@ -61,36 +105,60 @@ function splitHighlightedText(
|
|
|
61
105
|
if (!term || !term.trim()) {
|
|
62
106
|
return [{ text, match: false }];
|
|
63
107
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
const words = term
|
|
109
|
+
.trim()
|
|
110
|
+
.toLowerCase()
|
|
111
|
+
.split(/\s+/)
|
|
112
|
+
.filter((w) => w.length >= 2 && !w.includes(":"));
|
|
113
|
+
if (!words.length) {
|
|
114
|
+
const fallback = term.trim().toLowerCase();
|
|
115
|
+
if (fallback && !fallback.includes(":")) words.push(fallback);
|
|
116
|
+
}
|
|
117
|
+
if (!words.length) return [{ text, match: false }];
|
|
71
118
|
|
|
72
119
|
const parts: Array<{ text: string; match: boolean }> = [];
|
|
73
120
|
const lower = text.toLowerCase();
|
|
74
121
|
let cursor = 0;
|
|
75
122
|
|
|
76
123
|
while (cursor < text.length) {
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
let bestIdx = -1;
|
|
125
|
+
let bestLen = 0;
|
|
126
|
+
for (const w of words) {
|
|
127
|
+
const idx = lower.indexOf(w, cursor);
|
|
128
|
+
if (idx !== -1 && (bestIdx === -1 || idx < bestIdx || (idx === bestIdx && w.length > bestLen))) {
|
|
129
|
+
bestIdx = idx;
|
|
130
|
+
bestLen = w.length;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (bestIdx === -1) {
|
|
79
134
|
parts.push({ text: text.slice(cursor), match: false });
|
|
80
135
|
break;
|
|
81
136
|
}
|
|
82
|
-
if (
|
|
83
|
-
parts.push({ text: text.slice(cursor,
|
|
137
|
+
if (bestIdx > cursor) {
|
|
138
|
+
parts.push({ text: text.slice(cursor, bestIdx), match: false });
|
|
84
139
|
}
|
|
85
|
-
parts.push({ text: text.slice(
|
|
86
|
-
cursor =
|
|
140
|
+
parts.push({ text: text.slice(bestIdx, bestIdx + bestLen), match: true });
|
|
141
|
+
cursor = bestIdx + bestLen;
|
|
87
142
|
}
|
|
88
143
|
return parts.length ? parts : [{ text, match: false }];
|
|
89
144
|
}
|
|
90
145
|
|
|
146
|
+
function isSafeSubPath(parentDir: string, targetPath: string): boolean {
|
|
147
|
+
const rel = path.relative(path.resolve(parentDir), path.resolve(targetPath));
|
|
148
|
+
return Boolean(rel && !rel.startsWith("..") && !path.isAbsolute(rel));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function isSafeRegexPattern(pattern: string): boolean {
|
|
152
|
+
if (!pattern || pattern.length > 256) return false;
|
|
153
|
+
// Reject nested quantifiers such as (a+)+, (.*)*, ([a-z]+){2,} that cause catastrophic backtracking
|
|
154
|
+
if (/(\([^()]*[+*?][^()]*\))\s*[+*?{]/.test(pattern)) return false;
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
91
158
|
function readFullSessionMarkdown(rootDir: string, relFile: string): string {
|
|
92
159
|
try {
|
|
93
|
-
const fullPath = path.
|
|
160
|
+
const fullPath = path.resolve(rootDir, relFile);
|
|
161
|
+
if (!isSafeSubPath(rootDir, fullPath)) return "";
|
|
94
162
|
if (fs.existsSync(fullPath)) {
|
|
95
163
|
return fs.readFileSync(fullPath, "utf8").replace(/\r\n/g, "\n").trim();
|
|
96
164
|
}
|
|
@@ -107,7 +175,7 @@ interface DialogProps {
|
|
|
107
175
|
close: () => void;
|
|
108
176
|
}
|
|
109
177
|
|
|
110
|
-
|
|
178
|
+
function createTuiRenderer() {
|
|
111
179
|
function el(
|
|
112
180
|
tag: string,
|
|
113
181
|
props?: Record<string, unknown> | null,
|
|
@@ -225,6 +293,8 @@ async function loadTuiRenderer() {
|
|
|
225
293
|
let effType = tFilter;
|
|
226
294
|
let effTopic = topFilter;
|
|
227
295
|
let effMode = mFilter;
|
|
296
|
+
let effProject = "all";
|
|
297
|
+
let effCoreOnly = false;
|
|
228
298
|
const tokens = rawQ.trim().split(/\s+/).filter(Boolean);
|
|
229
299
|
const cleanTokens: string[] = [];
|
|
230
300
|
|
|
@@ -236,6 +306,11 @@ async function loadTuiRenderer() {
|
|
|
236
306
|
effType = "sessions";
|
|
237
307
|
} else if (lower === "type:all") {
|
|
238
308
|
effType = "all";
|
|
309
|
+
} else if (lower === "core:true" || lower === "is:core") {
|
|
310
|
+
effCoreOnly = true;
|
|
311
|
+
} else if (lower.startsWith("project:")) {
|
|
312
|
+
const val = lower.slice(8).trim();
|
|
313
|
+
if (val) effProject = val;
|
|
239
314
|
} else if (lower.startsWith("topic:")) {
|
|
240
315
|
const val = lower.slice(6).trim();
|
|
241
316
|
if (val) effTopic = val;
|
|
@@ -252,6 +327,8 @@ async function loadTuiRenderer() {
|
|
|
252
327
|
effType,
|
|
253
328
|
effTopic,
|
|
254
329
|
effMode,
|
|
330
|
+
effProject,
|
|
331
|
+
effCoreOnly,
|
|
255
332
|
};
|
|
256
333
|
};
|
|
257
334
|
|
|
@@ -262,7 +339,7 @@ async function loadTuiRenderer() {
|
|
|
262
339
|
topFilter: string,
|
|
263
340
|
mFilter: ModeFilter
|
|
264
341
|
): MemoryHit[] => {
|
|
265
|
-
const { cleanQ: q, effType, effTopic, effMode } = parseInlineFilters(
|
|
342
|
+
const { cleanQ: q, effType, effTopic, effMode, effProject, effCoreOnly } = parseInlineFilters(
|
|
266
343
|
rawQ,
|
|
267
344
|
tFilter,
|
|
268
345
|
topFilter,
|
|
@@ -273,6 +350,8 @@ async function loadTuiRenderer() {
|
|
|
273
350
|
if (effType === "topics" && !e.file.startsWith("topics/")) return false;
|
|
274
351
|
if (effType === "sessions" && !e.file.startsWith("sessions/")) return false;
|
|
275
352
|
if (effTopic !== "all" && e.file !== `topics/${effTopic}.md`) return false;
|
|
353
|
+
if (effCoreOnly && !e.core) return false;
|
|
354
|
+
if (effProject !== "all" && !matchesProjectScope(e.project, effProject, false)) return false;
|
|
276
355
|
return true;
|
|
277
356
|
});
|
|
278
357
|
|
|
@@ -287,10 +366,11 @@ async function loadTuiRenderer() {
|
|
|
287
366
|
try {
|
|
288
367
|
const lastSlash = q.startsWith("/") ? q.lastIndexOf("/") : -1;
|
|
289
368
|
const pattern = lastSlash > 0 ? q.slice(1, lastSlash) : q;
|
|
369
|
+
if (!isSafeRegexPattern(pattern)) return [];
|
|
290
370
|
const flags = lastSlash > 0 ? q.slice(lastSlash + 1) || "i" : "i";
|
|
291
371
|
const re = new RegExp(pattern, flags);
|
|
292
372
|
return subset
|
|
293
|
-
.filter((e) => re.test(`${e.id} ${e.tags} ${e.fact} ${e.file}`))
|
|
373
|
+
.filter((e) => re.test(e._haystack || `${e.id} ${e.tags} ${e.fact} ${e.file}`))
|
|
294
374
|
.map((e) => ({ score: 1, semanticScore: 0, entry: e }));
|
|
295
375
|
} catch {
|
|
296
376
|
return [];
|
|
@@ -331,7 +411,7 @@ async function loadTuiRenderer() {
|
|
|
331
411
|
const tFilter = typeFilter();
|
|
332
412
|
const topFilter = topicFilter();
|
|
333
413
|
const mFilter = mode();
|
|
334
|
-
const { cleanQ: q, effType, effTopic, effMode } = parseInlineFilters(
|
|
414
|
+
const { cleanQ: q, effType, effTopic, effMode, effProject, effCoreOnly } = parseInlineFilters(
|
|
335
415
|
rawQ,
|
|
336
416
|
tFilter,
|
|
337
417
|
topFilter,
|
|
@@ -345,7 +425,11 @@ async function loadTuiRenderer() {
|
|
|
345
425
|
// If hybrid mode and non-empty query, refine with local vector similarity (0 LLM tokens)
|
|
346
426
|
if (effMode === "hybrid" && q.length >= 2) {
|
|
347
427
|
try {
|
|
348
|
-
const semHits: MemoryHit[] = await searchMemory(props.rootDir, q, "hybrid", 50
|
|
428
|
+
const semHits: MemoryHit[] = await searchMemory(props.rootDir, q, "hybrid", 50, {
|
|
429
|
+
project: effProject,
|
|
430
|
+
includeGlobal: effProject === "all",
|
|
431
|
+
coreOnly: effCoreOnly,
|
|
432
|
+
});
|
|
349
433
|
if (currentSeq !== searchSeq) return;
|
|
350
434
|
const filtered = semHits.filter((h) => {
|
|
351
435
|
if (effType === "topics" && !h.entry.file.startsWith("topics/")) return false;
|
|
@@ -363,7 +447,7 @@ async function loadTuiRenderer() {
|
|
|
363
447
|
const reloadVectors = async (forceSync = false) => {
|
|
364
448
|
if (forceSync) {
|
|
365
449
|
setStatusMsg("syncing markdown -> vectors.json...");
|
|
366
|
-
await
|
|
450
|
+
await safeSyncVectors(props.rootDir).catch(() => {});
|
|
367
451
|
setStatusMsg("");
|
|
368
452
|
}
|
|
369
453
|
const loaded = (loadCachedVectors(props.rootDir) || []) as MemoryEntry[];
|
|
@@ -371,6 +455,29 @@ async function loadTuiRenderer() {
|
|
|
371
455
|
await runSearch();
|
|
372
456
|
};
|
|
373
457
|
|
|
458
|
+
const runImportInDialog = async () => {
|
|
459
|
+
setStatusMsg("importing AGENTS.md & opencode.db...");
|
|
460
|
+
try {
|
|
461
|
+
const res = await safeImportMemory(props.rootDir);
|
|
462
|
+
setStatusMsg("");
|
|
463
|
+
const loaded = (loadCachedVectors(props.rootDir) || []) as MemoryEntry[];
|
|
464
|
+
setAllEntries(loaded);
|
|
465
|
+
await runSearch();
|
|
466
|
+
props.context.ui.toast.show({
|
|
467
|
+
title: "Memory Import Complete (0 tokens)",
|
|
468
|
+
message: `Imported ${res.importedFacts.length} rules & ${res.importedSessions.length} sessions (${res.syncResult.total} total)`,
|
|
469
|
+
variant: "success",
|
|
470
|
+
});
|
|
471
|
+
} catch (err) {
|
|
472
|
+
setStatusMsg("");
|
|
473
|
+
props.context.ui.toast.show({
|
|
474
|
+
title: "Memory Import Error",
|
|
475
|
+
message: err instanceof Error ? err.message : String(err),
|
|
476
|
+
variant: "error",
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
374
481
|
createEffect(() => {
|
|
375
482
|
query();
|
|
376
483
|
typeFilter();
|
|
@@ -463,6 +570,12 @@ async function loadTuiRenderer() {
|
|
|
463
570
|
void reloadVectors(true);
|
|
464
571
|
return;
|
|
465
572
|
}
|
|
573
|
+
if (event.ctrl && name === "b") {
|
|
574
|
+
event.preventDefault();
|
|
575
|
+
event.stopPropagation();
|
|
576
|
+
void runImportInDialog();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
466
579
|
|
|
467
580
|
if (name === "return" || name === "enter") {
|
|
468
581
|
const current = selectedHit();
|
|
@@ -493,22 +606,30 @@ async function loadTuiRenderer() {
|
|
|
493
606
|
|
|
494
607
|
if (
|
|
495
608
|
name === "down" ||
|
|
496
|
-
(event.ctrl && name === "n") ||
|
|
497
|
-
(focusPane()
|
|
609
|
+
(event.ctrl && (name === "n" || name === "j")) ||
|
|
610
|
+
(focusPane() !== "input" && !event.ctrl && name === "j")
|
|
498
611
|
) {
|
|
499
612
|
event.preventDefault();
|
|
500
613
|
event.stopPropagation();
|
|
501
|
-
|
|
614
|
+
if (focusPane() === "preview" && !event.ctrl && name === "j") {
|
|
615
|
+
previewScrollRef?.scrollBy?.(2);
|
|
616
|
+
} else {
|
|
617
|
+
moveSelection(1);
|
|
618
|
+
}
|
|
502
619
|
return;
|
|
503
620
|
}
|
|
504
621
|
if (
|
|
505
622
|
name === "up" ||
|
|
506
|
-
(event.ctrl && name === "k") ||
|
|
507
|
-
(focusPane()
|
|
623
|
+
(event.ctrl && (name === "p" || name === "k")) ||
|
|
624
|
+
(focusPane() !== "input" && !event.ctrl && name === "k")
|
|
508
625
|
) {
|
|
509
626
|
event.preventDefault();
|
|
510
627
|
event.stopPropagation();
|
|
511
|
-
|
|
628
|
+
if (focusPane() === "preview" && !event.ctrl && name === "k") {
|
|
629
|
+
previewScrollRef?.scrollBy?.(-2);
|
|
630
|
+
} else {
|
|
631
|
+
moveSelection(-1);
|
|
632
|
+
}
|
|
512
633
|
return;
|
|
513
634
|
}
|
|
514
635
|
if (name === "pagedown" || (event.ctrl && name === "d")) {
|
|
@@ -709,6 +830,12 @@ async function loadTuiRenderer() {
|
|
|
709
830
|
shortcut: "^r",
|
|
710
831
|
active: () => mode() !== "hybrid",
|
|
711
832
|
onClick: cycleMode,
|
|
833
|
+
}),
|
|
834
|
+
Pill({
|
|
835
|
+
label: () => "import",
|
|
836
|
+
shortcut: "^b",
|
|
837
|
+
active: () => false,
|
|
838
|
+
onClick: () => void runImportInDialog(),
|
|
712
839
|
})
|
|
713
840
|
)
|
|
714
841
|
),
|
|
@@ -870,7 +997,9 @@ async function loadTuiRenderer() {
|
|
|
870
997
|
() => {
|
|
871
998
|
const h = selectedHit();
|
|
872
999
|
if (!h) return "";
|
|
873
|
-
|
|
1000
|
+
const scope = h.entry.project || "global";
|
|
1001
|
+
const coreLabel = h.entry.core ? " · Core: pinned" : "";
|
|
1002
|
+
return `File: ${h.entry.file} · Date: ${h.entry.date || "N/A"} · Scope: ${scope}${coreLabel} · Score: ${h.score.toFixed(3)}`;
|
|
874
1003
|
}
|
|
875
1004
|
),
|
|
876
1005
|
el(
|
|
@@ -958,7 +1087,7 @@ async function loadTuiRenderer() {
|
|
|
958
1087
|
el(
|
|
959
1088
|
"text",
|
|
960
1089
|
{ fg: () => theme().text.muted },
|
|
961
|
-
"enter select · ↑/↓ or ^n/^k move · ^t type · ^g topic · ^r mode · ^l resync · tab pane · esc"
|
|
1090
|
+
"enter select · ↑/↓ or ^n/^k move · ^t type · ^g topic · ^r mode · ^b import · ^l resync · tab pane · esc"
|
|
962
1091
|
),
|
|
963
1092
|
el(
|
|
964
1093
|
"text",
|
|
@@ -1016,15 +1145,10 @@ export default {
|
|
|
1016
1145
|
return;
|
|
1017
1146
|
}
|
|
1018
1147
|
const rootDir = resolveMemoryDir((context as any)?.options?.directory);
|
|
1019
|
-
const
|
|
1148
|
+
const renderDialog = createTuiRenderer();
|
|
1020
1149
|
|
|
1021
1150
|
const openMemoryPopup = async (rawArgs?: string) => {
|
|
1022
1151
|
const initialQuery = typeof rawArgs === "string" ? rawArgs.trim() : "";
|
|
1023
|
-
const renderDialog = await renderDialogPromise;
|
|
1024
|
-
if (!renderDialog) {
|
|
1025
|
-
await openFallbackSelectDialog(context, rootDir, initialQuery);
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
1152
|
|
|
1029
1153
|
try {
|
|
1030
1154
|
context.ui.dialog.show(() =>
|
|
@@ -1074,46 +1198,140 @@ export default {
|
|
|
1074
1198
|
}
|
|
1075
1199
|
};
|
|
1076
1200
|
|
|
1201
|
+
const quickDeleteFromSlash = async (rawArgs?: string) => {
|
|
1202
|
+
const id = typeof rawArgs === "string" ? rawArgs.trim() : "";
|
|
1203
|
+
if (!id) {
|
|
1204
|
+
context.ui.toast.show({
|
|
1205
|
+
title: "Local Memory Delete (0 tokens)",
|
|
1206
|
+
message: "Usage: /memory-delete <id>",
|
|
1207
|
+
variant: "warning",
|
|
1208
|
+
});
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
try {
|
|
1212
|
+
const res = await deleteMemoryEntry(rootDir, id);
|
|
1213
|
+
if (res.deleted.length === 0) {
|
|
1214
|
+
context.ui.toast.show({
|
|
1215
|
+
title: "Not Found",
|
|
1216
|
+
message: `No memory entry matched ID: ${id}`,
|
|
1217
|
+
variant: "warning",
|
|
1218
|
+
});
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
context.ui.toast.show({
|
|
1222
|
+
title: `Deleted ${res.deleted.map((d: { id: string }) => `[${d.id}]`).join(", ")} (0 tokens)`,
|
|
1223
|
+
message: `${res.total} entries remaining in vectors.json`,
|
|
1224
|
+
variant: "success",
|
|
1225
|
+
});
|
|
1226
|
+
} catch (err) {
|
|
1227
|
+
context.ui.toast.show({
|
|
1228
|
+
title: "Local Memory Error",
|
|
1229
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1230
|
+
variant: "error",
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
const quickImportFromSlash = async (rawArgs?: string) => {
|
|
1236
|
+
const arg = typeof rawArgs === "string" ? rawArgs.trim() : "";
|
|
1237
|
+
const limit = arg && /^\d+$/.test(arg) ? parseInt(arg, 10) : undefined;
|
|
1238
|
+
context.ui.toast.show({
|
|
1239
|
+
title: "Importing Local Memory (0 tokens)...",
|
|
1240
|
+
message: "Scanning AGENTS.md rules and opencode.db session history...",
|
|
1241
|
+
variant: "info",
|
|
1242
|
+
});
|
|
1243
|
+
try {
|
|
1244
|
+
const res = await safeImportMemory(rootDir, limit);
|
|
1245
|
+
context.ui.toast.show({
|
|
1246
|
+
title: "Local Memory Import Complete (0 tokens)",
|
|
1247
|
+
message: `Added ${res.importedFacts.length} rules & ${res.importedSessions.length} sessions (${res.syncResult.total} total indexed)`,
|
|
1248
|
+
variant: "success",
|
|
1249
|
+
});
|
|
1250
|
+
} catch (err) {
|
|
1251
|
+
context.ui.toast.show({
|
|
1252
|
+
title: "Local Memory Import Error",
|
|
1253
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1254
|
+
variant: "error",
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
let layerRegistered = false;
|
|
1077
1260
|
context.ui.slot({
|
|
1078
1261
|
append: "app",
|
|
1079
1262
|
render() {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
"
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1263
|
+
if (!layerRegistered) {
|
|
1264
|
+
layerRegistered = true;
|
|
1265
|
+
context.keymap.layer(() => ({
|
|
1266
|
+
mode: "global",
|
|
1267
|
+
commands: [
|
|
1268
|
+
{
|
|
1269
|
+
id: "local.memory.search",
|
|
1270
|
+
title: "Search local memory (0 tokens)...",
|
|
1271
|
+
description:
|
|
1272
|
+
"Interactive zero-token popup to search local memories (topics/*.md + sessions/*.md) with semantic + keyword + regex matching",
|
|
1273
|
+
category: "Memory",
|
|
1274
|
+
palette: true,
|
|
1275
|
+
slash: {
|
|
1276
|
+
name: "memory",
|
|
1277
|
+
arguments: true,
|
|
1278
|
+
},
|
|
1279
|
+
run: (input) => {
|
|
1280
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1281
|
+
void openMemoryPopup(rawArgs);
|
|
1282
|
+
},
|
|
1093
1283
|
},
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1284
|
+
{
|
|
1285
|
+
id: "local.memory.add",
|
|
1286
|
+
title: "Store local memory fact (0 tokens)...",
|
|
1287
|
+
description:
|
|
1288
|
+
"Zero-token slash command to store a memory fact directly: /memory-add <topic> | <tags> | <fact>",
|
|
1289
|
+
category: "Memory",
|
|
1290
|
+
palette: false,
|
|
1291
|
+
slash: {
|
|
1292
|
+
name: "memory-add",
|
|
1293
|
+
arguments: true,
|
|
1294
|
+
},
|
|
1295
|
+
run: (input) => {
|
|
1296
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1297
|
+
void quickStoreFromSlash(rawArgs);
|
|
1298
|
+
},
|
|
1097
1299
|
},
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1300
|
+
{
|
|
1301
|
+
id: "local.memory.delete",
|
|
1302
|
+
title: "Delete local memory entry by ID (0 tokens)...",
|
|
1303
|
+
description:
|
|
1304
|
+
"Zero-token slash command to delete a memory entry by ID: /memory-delete <id>",
|
|
1305
|
+
category: "Memory",
|
|
1306
|
+
palette: false,
|
|
1307
|
+
slash: {
|
|
1308
|
+
name: "memory-delete",
|
|
1309
|
+
arguments: true,
|
|
1310
|
+
},
|
|
1311
|
+
run: (input) => {
|
|
1312
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1313
|
+
void quickDeleteFromSlash(rawArgs);
|
|
1314
|
+
},
|
|
1109
1315
|
},
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1316
|
+
{
|
|
1317
|
+
id: "local.memory.import",
|
|
1318
|
+
title: "Import existing AGENTS.md & session history (0 tokens)...",
|
|
1319
|
+
description:
|
|
1320
|
+
"Zero-token command to import existing AGENTS.md/CLAUDE.md rules and compacted session summaries from opencode.db: /memory-import [limit]",
|
|
1321
|
+
category: "Memory",
|
|
1322
|
+
palette: true,
|
|
1323
|
+
slash: {
|
|
1324
|
+
name: "memory-import",
|
|
1325
|
+
arguments: true,
|
|
1326
|
+
},
|
|
1327
|
+
run: (input) => {
|
|
1328
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1329
|
+
void quickImportFromSlash(rawArgs);
|
|
1330
|
+
},
|
|
1113
1331
|
},
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1332
|
+
],
|
|
1333
|
+
}));
|
|
1334
|
+
}
|
|
1117
1335
|
return null;
|
|
1118
1336
|
},
|
|
1119
1337
|
});
|