@nandoblanco/opencode-local-memory 1.0.1 → 1.1.1
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 +1437 -75
- package/package.json +1 -1
- package/tui.ts +569 -260
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,
|
|
@@ -249,6 +293,8 @@ function createTuiRenderer() {
|
|
|
249
293
|
let effType = tFilter;
|
|
250
294
|
let effTopic = topFilter;
|
|
251
295
|
let effMode = mFilter;
|
|
296
|
+
let effProject = "all";
|
|
297
|
+
let effCoreOnly = false;
|
|
252
298
|
const tokens = rawQ.trim().split(/\s+/).filter(Boolean);
|
|
253
299
|
const cleanTokens: string[] = [];
|
|
254
300
|
|
|
@@ -260,6 +306,11 @@ function createTuiRenderer() {
|
|
|
260
306
|
effType = "sessions";
|
|
261
307
|
} else if (lower === "type:all") {
|
|
262
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;
|
|
263
314
|
} else if (lower.startsWith("topic:")) {
|
|
264
315
|
const val = lower.slice(6).trim();
|
|
265
316
|
if (val) effTopic = val;
|
|
@@ -276,6 +327,8 @@ function createTuiRenderer() {
|
|
|
276
327
|
effType,
|
|
277
328
|
effTopic,
|
|
278
329
|
effMode,
|
|
330
|
+
effProject,
|
|
331
|
+
effCoreOnly,
|
|
279
332
|
};
|
|
280
333
|
};
|
|
281
334
|
|
|
@@ -286,7 +339,7 @@ function createTuiRenderer() {
|
|
|
286
339
|
topFilter: string,
|
|
287
340
|
mFilter: ModeFilter
|
|
288
341
|
): MemoryHit[] => {
|
|
289
|
-
const { cleanQ: q, effType, effTopic, effMode } = parseInlineFilters(
|
|
342
|
+
const { cleanQ: q, effType, effTopic, effMode, effProject, effCoreOnly } = parseInlineFilters(
|
|
290
343
|
rawQ,
|
|
291
344
|
tFilter,
|
|
292
345
|
topFilter,
|
|
@@ -297,6 +350,8 @@ function createTuiRenderer() {
|
|
|
297
350
|
if (effType === "topics" && !e.file.startsWith("topics/")) return false;
|
|
298
351
|
if (effType === "sessions" && !e.file.startsWith("sessions/")) return false;
|
|
299
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;
|
|
300
355
|
return true;
|
|
301
356
|
});
|
|
302
357
|
|
|
@@ -356,7 +411,7 @@ function createTuiRenderer() {
|
|
|
356
411
|
const tFilter = typeFilter();
|
|
357
412
|
const topFilter = topicFilter();
|
|
358
413
|
const mFilter = mode();
|
|
359
|
-
const { cleanQ: q, effType, effTopic, effMode } = parseInlineFilters(
|
|
414
|
+
const { cleanQ: q, effType, effTopic, effMode, effProject, effCoreOnly } = parseInlineFilters(
|
|
360
415
|
rawQ,
|
|
361
416
|
tFilter,
|
|
362
417
|
topFilter,
|
|
@@ -370,7 +425,11 @@ function createTuiRenderer() {
|
|
|
370
425
|
// If hybrid mode and non-empty query, refine with local vector similarity (0 LLM tokens)
|
|
371
426
|
if (effMode === "hybrid" && q.length >= 2) {
|
|
372
427
|
try {
|
|
373
|
-
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
|
+
});
|
|
374
433
|
if (currentSeq !== searchSeq) return;
|
|
375
434
|
const filtered = semHits.filter((h) => {
|
|
376
435
|
if (effType === "topics" && !h.entry.file.startsWith("topics/")) return false;
|
|
@@ -388,7 +447,7 @@ function createTuiRenderer() {
|
|
|
388
447
|
const reloadVectors = async (forceSync = false) => {
|
|
389
448
|
if (forceSync) {
|
|
390
449
|
setStatusMsg("syncing markdown -> vectors.json...");
|
|
391
|
-
await
|
|
450
|
+
await safeSyncVectors(props.rootDir).catch(() => {});
|
|
392
451
|
setStatusMsg("");
|
|
393
452
|
}
|
|
394
453
|
const loaded = (loadCachedVectors(props.rootDir) || []) as MemoryEntry[];
|
|
@@ -396,6 +455,29 @@ function createTuiRenderer() {
|
|
|
396
455
|
await runSearch();
|
|
397
456
|
};
|
|
398
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
|
+
|
|
399
481
|
createEffect(() => {
|
|
400
482
|
query();
|
|
401
483
|
typeFilter();
|
|
@@ -488,6 +570,12 @@ function createTuiRenderer() {
|
|
|
488
570
|
void reloadVectors(true);
|
|
489
571
|
return;
|
|
490
572
|
}
|
|
573
|
+
if (event.ctrl && name === "b") {
|
|
574
|
+
event.preventDefault();
|
|
575
|
+
event.stopPropagation();
|
|
576
|
+
void runImportInDialog();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
491
579
|
|
|
492
580
|
if (name === "return" || name === "enter") {
|
|
493
581
|
const current = selectedHit();
|
|
@@ -628,99 +716,142 @@ function createTuiRenderer() {
|
|
|
628
716
|
queueMicrotask(applyDialogWidth);
|
|
629
717
|
},
|
|
630
718
|
width: "100%",
|
|
631
|
-
height:
|
|
719
|
+
height: 34,
|
|
632
720
|
flexDirection: "column",
|
|
633
721
|
backgroundColor: () => theme().background.base,
|
|
722
|
+
paddingLeft: 2,
|
|
723
|
+
paddingRight: 2,
|
|
724
|
+
paddingTop: 1,
|
|
725
|
+
paddingBottom: 1,
|
|
726
|
+
gap: 1,
|
|
634
727
|
},
|
|
635
|
-
// 1. Header Bar
|
|
728
|
+
// 1. Header Bar (single-line, no wrapping)
|
|
636
729
|
el(
|
|
637
730
|
"box",
|
|
638
731
|
{
|
|
639
732
|
flexDirection: "row",
|
|
640
733
|
justifyContent: "space-between",
|
|
641
734
|
alignItems: "center",
|
|
642
|
-
|
|
643
|
-
|
|
735
|
+
border: ["bottom"],
|
|
736
|
+
borderColor: () => theme().border.base,
|
|
737
|
+
paddingBottom: 0,
|
|
644
738
|
flexShrink: 0,
|
|
739
|
+
width: "100%",
|
|
645
740
|
},
|
|
646
741
|
el(
|
|
647
742
|
"box",
|
|
648
|
-
{ flexDirection: "row", gap: 2, alignItems: "center" },
|
|
743
|
+
{ flexDirection: "row", gap: 2, alignItems: "center", flexShrink: 0 },
|
|
649
744
|
el(
|
|
650
745
|
"text",
|
|
651
746
|
{
|
|
652
|
-
|
|
747
|
+
wrapMode: "none",
|
|
748
|
+
flexShrink: 0,
|
|
749
|
+
fg: () => theme().text.action.primary.base,
|
|
653
750
|
attributes: TextAttributes.BOLD,
|
|
654
751
|
},
|
|
655
|
-
"
|
|
752
|
+
"opencode / memory"
|
|
656
753
|
),
|
|
657
754
|
el(
|
|
658
755
|
"text",
|
|
659
|
-
{
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
756
|
+
{
|
|
757
|
+
wrapMode: "none",
|
|
758
|
+
flexShrink: 0,
|
|
759
|
+
fg: () => theme().text.muted,
|
|
760
|
+
},
|
|
761
|
+
() => props.context.ui.format.path(props.rootDir)
|
|
663
762
|
)
|
|
664
763
|
),
|
|
665
764
|
el(
|
|
666
|
-
"
|
|
667
|
-
{
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
el(
|
|
674
|
-
"box",
|
|
675
|
-
{ paddingX: 1, onMouseUp: () => props.close() },
|
|
676
|
-
el("text", { fg: () => theme().text.muted }, "esc")
|
|
677
|
-
)
|
|
765
|
+
"text",
|
|
766
|
+
{
|
|
767
|
+
wrapMode: "none",
|
|
768
|
+
flexShrink: 0,
|
|
769
|
+
fg: () => theme().text.muted,
|
|
770
|
+
},
|
|
771
|
+
"[↑↓] select [Tab] pane [^D] delete [Esc] close"
|
|
678
772
|
)
|
|
679
773
|
),
|
|
680
774
|
|
|
681
|
-
// 2.
|
|
775
|
+
// 2. Boxed Filter + Pills Card
|
|
682
776
|
el(
|
|
683
777
|
"box",
|
|
684
778
|
{
|
|
685
779
|
flexDirection: "column",
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
780
|
+
backgroundColor: () =>
|
|
781
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
782
|
+
border: true,
|
|
783
|
+
borderColor: () =>
|
|
784
|
+
focusPane() === "search"
|
|
785
|
+
? theme().text.action.primary.base
|
|
786
|
+
: theme().border.base,
|
|
787
|
+
paddingLeft: 2,
|
|
788
|
+
paddingRight: 2,
|
|
789
|
+
paddingTop: 0,
|
|
790
|
+
paddingBottom: 0,
|
|
791
|
+
gap: 0,
|
|
689
792
|
flexShrink: 0,
|
|
690
|
-
|
|
691
|
-
borderColor: () => theme().border.base,
|
|
793
|
+
width: "100%",
|
|
692
794
|
},
|
|
693
795
|
el(
|
|
694
796
|
"box",
|
|
695
|
-
{
|
|
797
|
+
{
|
|
798
|
+
flexDirection: "row",
|
|
799
|
+
justifyContent: "space-between",
|
|
800
|
+
alignItems: "center",
|
|
801
|
+
gap: 1,
|
|
802
|
+
width: "100%",
|
|
803
|
+
},
|
|
696
804
|
el(
|
|
697
805
|
"text",
|
|
698
806
|
{
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
807
|
+
width: 7,
|
|
808
|
+
wrapMode: "none",
|
|
809
|
+
flexShrink: 0,
|
|
810
|
+
fg: () => theme().text.action.primary.base,
|
|
703
811
|
attributes: TextAttributes.BOLD,
|
|
704
812
|
},
|
|
705
|
-
"
|
|
813
|
+
"Filter:"
|
|
706
814
|
),
|
|
707
|
-
el(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
815
|
+
el(
|
|
816
|
+
"box",
|
|
817
|
+
{
|
|
818
|
+
flexGrow: 1,
|
|
819
|
+
flexShrink: 1,
|
|
820
|
+
minWidth: 0,
|
|
821
|
+
},
|
|
822
|
+
el("input", {
|
|
823
|
+
id: "local-memory-search-input",
|
|
824
|
+
width: "100%",
|
|
825
|
+
value: () => query(),
|
|
826
|
+
focused: () => focusPane() === "search",
|
|
827
|
+
maxLength: Number.POSITIVE_INFINITY,
|
|
828
|
+
placeholder:
|
|
829
|
+
"Search memories (semantic + keyword, topic:name, project:slug, /regex/i)...",
|
|
830
|
+
placeholderColor: () => theme().text.muted,
|
|
831
|
+
textColor: () => theme().text.base,
|
|
832
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
833
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
834
|
+
backgroundColor: () =>
|
|
835
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
836
|
+
focusedBackgroundColor: () =>
|
|
837
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
838
|
+
onMouseDown: () => setFocusPane("search"),
|
|
839
|
+
onInput: (val: string) => setQuery(val),
|
|
840
|
+
})
|
|
841
|
+
),
|
|
842
|
+
el(
|
|
843
|
+
"text",
|
|
844
|
+
{
|
|
845
|
+
wrapMode: "none",
|
|
846
|
+
flexShrink: 0,
|
|
847
|
+
fg: () =>
|
|
848
|
+
theme().text.feedback?.success?.base ??
|
|
849
|
+
theme().text.action.primary.base,
|
|
850
|
+
},
|
|
851
|
+
() =>
|
|
852
|
+
statusMsg() ||
|
|
853
|
+
`${hits().length} of ${allEntries().length} entries · 0 tokens`
|
|
854
|
+
)
|
|
724
855
|
),
|
|
725
856
|
el(
|
|
726
857
|
"box",
|
|
@@ -742,261 +873,349 @@ function createTuiRenderer() {
|
|
|
742
873
|
shortcut: "^r",
|
|
743
874
|
active: () => mode() !== "hybrid",
|
|
744
875
|
onClick: cycleMode,
|
|
876
|
+
}),
|
|
877
|
+
Pill({
|
|
878
|
+
label: () => "import",
|
|
879
|
+
shortcut: "^b",
|
|
880
|
+
active: () => false,
|
|
881
|
+
onClick: () => void runImportInDialog(),
|
|
882
|
+
}),
|
|
883
|
+
Pill({
|
|
884
|
+
label: () => "resync",
|
|
885
|
+
shortcut: "^l",
|
|
886
|
+
active: () => false,
|
|
887
|
+
onClick: () => void reloadVectors(true),
|
|
745
888
|
})
|
|
746
889
|
)
|
|
747
890
|
),
|
|
748
891
|
|
|
749
|
-
// 3. Split-Pane Body
|
|
892
|
+
// 3. Split-Pane Body: Two Side-by-Side Bordered Cards
|
|
750
893
|
el(
|
|
751
894
|
"box",
|
|
752
|
-
{ flexDirection: "row", flexGrow: 1, minHeight: 0 },
|
|
753
|
-
// Left: Results List (44%)
|
|
895
|
+
{ flexDirection: "row", gap: 2, flexGrow: 1, minHeight: 0, width: "100%" },
|
|
896
|
+
// Left Card: Results List (44%)
|
|
754
897
|
el(
|
|
755
|
-
"
|
|
898
|
+
"box",
|
|
756
899
|
{
|
|
757
|
-
id: "local-memory-list",
|
|
758
|
-
ref: (r: unknown) => {
|
|
759
|
-
listScrollRef = r;
|
|
760
|
-
},
|
|
761
900
|
width: "44%",
|
|
762
901
|
height: "100%",
|
|
902
|
+
flexDirection: "column",
|
|
763
903
|
flexShrink: 0,
|
|
764
|
-
|
|
904
|
+
backgroundColor: () =>
|
|
905
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
906
|
+
border: true,
|
|
765
907
|
borderColor: () =>
|
|
766
|
-
focusPane() === "list"
|
|
767
|
-
|
|
908
|
+
focusPane() === "list"
|
|
909
|
+
? theme().text.action.primary.base
|
|
910
|
+
: theme().border.base,
|
|
911
|
+
paddingLeft: 1,
|
|
912
|
+
paddingRight: 1,
|
|
913
|
+
paddingTop: 0,
|
|
914
|
+
paddingBottom: 0,
|
|
768
915
|
onMouseDown: () => setFocusPane("list"),
|
|
769
916
|
},
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
917
|
+
el(
|
|
918
|
+
"box",
|
|
919
|
+
{
|
|
920
|
+
flexDirection: "row",
|
|
921
|
+
justifyContent: "space-between",
|
|
922
|
+
border: ["bottom"],
|
|
923
|
+
borderColor: () => theme().border.base,
|
|
924
|
+
paddingX: 1,
|
|
925
|
+
flexShrink: 0,
|
|
773
926
|
},
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
927
|
+
el(
|
|
928
|
+
"text",
|
|
929
|
+
{
|
|
930
|
+
fg: () => theme().text.action.primary.base,
|
|
931
|
+
attributes: TextAttributes.BOLD,
|
|
932
|
+
},
|
|
933
|
+
"◈ MEMORY ENTRIES"
|
|
934
|
+
),
|
|
935
|
+
el(
|
|
936
|
+
"text",
|
|
937
|
+
{ fg: () => theme().text.muted },
|
|
938
|
+
() => `${mode()} · ${typeFilter()}`
|
|
939
|
+
)
|
|
940
|
+
),
|
|
941
|
+
el(
|
|
942
|
+
"scrollbox",
|
|
943
|
+
{
|
|
944
|
+
id: "local-memory-list",
|
|
945
|
+
ref: (r: unknown) => {
|
|
946
|
+
listScrollRef = r;
|
|
947
|
+
},
|
|
948
|
+
width: "100%",
|
|
949
|
+
flexGrow: 1,
|
|
950
|
+
minHeight: 0,
|
|
951
|
+
scrollbarOptions: { visible: false },
|
|
784
952
|
},
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
el(
|
|
953
|
+
createComponent(Show, {
|
|
954
|
+
get when() {
|
|
955
|
+
return hits().length > 0;
|
|
956
|
+
},
|
|
957
|
+
get fallback() {
|
|
958
|
+
return el(
|
|
959
|
+
"box",
|
|
960
|
+
{ paddingX: 1, paddingY: 1 },
|
|
961
|
+
el(
|
|
962
|
+
"text",
|
|
963
|
+
{ fg: () => theme().text.muted },
|
|
964
|
+
"No matching memory entries found."
|
|
965
|
+
)
|
|
966
|
+
);
|
|
967
|
+
},
|
|
968
|
+
get children() {
|
|
969
|
+
return createComponent(For, {
|
|
970
|
+
get each() {
|
|
971
|
+
return hits();
|
|
972
|
+
},
|
|
973
|
+
children: (item: MemoryHit, idx: () => number) => {
|
|
974
|
+
const isSelected = () => selectedIndex() === idx();
|
|
975
|
+
return el(
|
|
809
976
|
"box",
|
|
810
977
|
{
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
978
|
+
id: () => `memory-row-${idx()}`,
|
|
979
|
+
flexDirection: "column",
|
|
980
|
+
paddingX: 1,
|
|
981
|
+
paddingY: 0,
|
|
982
|
+
marginBottom: 1,
|
|
983
|
+
flexShrink: 0,
|
|
984
|
+
backgroundColor: () =>
|
|
985
|
+
isSelected()
|
|
986
|
+
? theme().background.action.primary.focused
|
|
987
|
+
: undefined,
|
|
988
|
+
onMouseUp: () => setSelectedIndex(idx()),
|
|
989
|
+
onMouseOver: () => setSelectedIndex(idx()),
|
|
814
990
|
},
|
|
815
991
|
el(
|
|
816
|
-
"
|
|
992
|
+
"box",
|
|
817
993
|
{
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
? theme().text.action.primary.focused
|
|
822
|
-
: theme().text.base,
|
|
823
|
-
attributes: () =>
|
|
824
|
-
isSelected() ? TextAttributes.BOLD : undefined,
|
|
994
|
+
flexDirection: "row",
|
|
995
|
+
justifyContent: "space-between",
|
|
996
|
+
width: "100%",
|
|
825
997
|
},
|
|
826
|
-
(
|
|
998
|
+
el(
|
|
999
|
+
"text",
|
|
1000
|
+
{
|
|
1001
|
+
wrapMode: "none",
|
|
1002
|
+
truncate: true,
|
|
1003
|
+
fg: () =>
|
|
1004
|
+
isSelected()
|
|
1005
|
+
? theme().text.action.primary.focused
|
|
1006
|
+
: theme().text.base,
|
|
1007
|
+
attributes: () =>
|
|
1008
|
+
isSelected() ? TextAttributes.BOLD : undefined,
|
|
1009
|
+
},
|
|
1010
|
+
() => `${isSelected() ? "▸ " : " "}[${item.entry.id}]`
|
|
1011
|
+
),
|
|
1012
|
+
el(
|
|
1013
|
+
"text",
|
|
1014
|
+
{
|
|
1015
|
+
wrapMode: "none",
|
|
1016
|
+
fg: () =>
|
|
1017
|
+
isSelected()
|
|
1018
|
+
? theme().text.action.primary.focused
|
|
1019
|
+
: theme().text.action.primary.base,
|
|
1020
|
+
},
|
|
1021
|
+
() =>
|
|
1022
|
+
query().trim()
|
|
1023
|
+
? `${item.score.toFixed(2)} · ${item.entry.file.replace(/\.md$/, "")}`
|
|
1024
|
+
: item.entry.file.replace(/\.md$/, "")
|
|
1025
|
+
)
|
|
827
1026
|
),
|
|
828
1027
|
el(
|
|
829
1028
|
"text",
|
|
830
1029
|
{
|
|
831
1030
|
wrapMode: "none",
|
|
1031
|
+
truncate: true,
|
|
832
1032
|
fg: () =>
|
|
833
1033
|
isSelected()
|
|
834
1034
|
? theme().text.action.primary.focused
|
|
835
1035
|
: theme().text.muted,
|
|
836
1036
|
},
|
|
837
|
-
() =>
|
|
838
|
-
query().trim()
|
|
839
|
-
? `${item.score.toFixed(2)} · ${item.entry.file.replace(/\.md$/, "")}`
|
|
840
|
-
: item.entry.file.replace(/\.md$/, "")
|
|
1037
|
+
() => ` ${item.entry.fact.slice(0, 56)}`
|
|
841
1038
|
)
|
|
842
|
-
)
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
isSelected()
|
|
849
|
-
? theme().text.action.primary.focused
|
|
850
|
-
: theme().text.muted,
|
|
851
|
-
},
|
|
852
|
-
() => ` ${item.entry.fact.slice(0, 56)}`
|
|
853
|
-
)
|
|
854
|
-
);
|
|
855
|
-
},
|
|
856
|
-
});
|
|
857
|
-
},
|
|
858
|
-
})
|
|
1039
|
+
);
|
|
1040
|
+
},
|
|
1041
|
+
});
|
|
1042
|
+
},
|
|
1043
|
+
})
|
|
1044
|
+
)
|
|
859
1045
|
),
|
|
860
1046
|
|
|
861
|
-
// Right: Full Memory Entry Preview (56%)
|
|
1047
|
+
// Right Card: Full Memory Entry Preview (56%)
|
|
862
1048
|
el(
|
|
863
|
-
"
|
|
1049
|
+
"box",
|
|
864
1050
|
{
|
|
865
|
-
id: "local-memory-preview",
|
|
866
|
-
ref: (r: unknown) => {
|
|
867
|
-
previewScrollRef = r;
|
|
868
|
-
},
|
|
869
1051
|
flexGrow: 1,
|
|
1052
|
+
height: "100%",
|
|
870
1053
|
minWidth: 0,
|
|
871
1054
|
minHeight: 0,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1055
|
+
flexDirection: "column",
|
|
1056
|
+
backgroundColor: () =>
|
|
1057
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1058
|
+
border: true,
|
|
1059
|
+
borderColor: () =>
|
|
1060
|
+
focusPane() === "preview"
|
|
1061
|
+
? theme().text.action.primary.base
|
|
1062
|
+
: theme().border.base,
|
|
1063
|
+
paddingLeft: 2,
|
|
1064
|
+
paddingRight: 2,
|
|
1065
|
+
paddingTop: 0,
|
|
1066
|
+
paddingBottom: 1,
|
|
875
1067
|
onMouseDown: () => setFocusPane("preview"),
|
|
876
1068
|
},
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1069
|
+
el(
|
|
1070
|
+
"box",
|
|
1071
|
+
{
|
|
1072
|
+
flexDirection: "row",
|
|
1073
|
+
justifyContent: "space-between",
|
|
1074
|
+
border: ["bottom"],
|
|
1075
|
+
borderColor: () => theme().border.base,
|
|
1076
|
+
marginBottom: 1,
|
|
1077
|
+
flexShrink: 0,
|
|
880
1078
|
},
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1079
|
+
el(
|
|
1080
|
+
"text",
|
|
1081
|
+
{
|
|
1082
|
+
fg: () => theme().text.action.primary.base,
|
|
1083
|
+
attributes: TextAttributes.BOLD,
|
|
1084
|
+
},
|
|
1085
|
+
"◈ ENTRY PREVIEW"
|
|
1086
|
+
),
|
|
1087
|
+
el(
|
|
1088
|
+
"text",
|
|
1089
|
+
{ fg: () => theme().text.muted },
|
|
1090
|
+
() =>
|
|
1091
|
+
selectedHit()
|
|
1092
|
+
? `${selectedHit()?.entry.file ?? ""} · score ${selectedHit()?.score.toFixed(3) ?? ""}`
|
|
1093
|
+
: "no selection"
|
|
1094
|
+
)
|
|
1095
|
+
),
|
|
1096
|
+
el(
|
|
1097
|
+
"scrollbox",
|
|
1098
|
+
{
|
|
1099
|
+
id: "local-memory-preview",
|
|
1100
|
+
ref: (r: unknown) => {
|
|
1101
|
+
previewScrollRef = r;
|
|
1102
|
+
},
|
|
1103
|
+
flexGrow: 1,
|
|
1104
|
+
minWidth: 0,
|
|
1105
|
+
minHeight: 0,
|
|
1106
|
+
focused: () => focusPane() === "preview",
|
|
887
1107
|
},
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
{
|
|
895
|
-
fg: () => theme().text.base,
|
|
896
|
-
attributes: TextAttributes.BOLD,
|
|
897
|
-
},
|
|
898
|
-
() => `[${selectedHit()?.entry.id ?? ""}]`
|
|
899
|
-
),
|
|
900
|
-
el(
|
|
901
|
-
"text",
|
|
902
|
-
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
903
|
-
() => {
|
|
904
|
-
const h = selectedHit();
|
|
905
|
-
if (!h) return "";
|
|
906
|
-
return `File: ${h.entry.file} · Date: ${h.entry.date || "N/A"} · Score: ${h.score.toFixed(3)}`;
|
|
907
|
-
}
|
|
908
|
-
),
|
|
909
|
-
el(
|
|
1108
|
+
createComponent(Show, {
|
|
1109
|
+
get when() {
|
|
1110
|
+
return selectedHit();
|
|
1111
|
+
},
|
|
1112
|
+
get fallback() {
|
|
1113
|
+
return el(
|
|
910
1114
|
"text",
|
|
911
|
-
{ fg: () => theme().text.muted
|
|
912
|
-
|
|
913
|
-
)
|
|
914
|
-
|
|
1115
|
+
{ fg: () => theme().text.muted },
|
|
1116
|
+
"Select a memory entry on the left to inspect it."
|
|
1117
|
+
);
|
|
1118
|
+
},
|
|
1119
|
+
get children() {
|
|
1120
|
+
return el(
|
|
915
1121
|
"box",
|
|
916
|
-
{
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
selectedHit()?.entry.fact ?? "",
|
|
925
|
-
query()
|
|
926
|
-
);
|
|
1122
|
+
{ flexDirection: "column", gap: 1 },
|
|
1123
|
+
el(
|
|
1124
|
+
"box",
|
|
1125
|
+
{
|
|
1126
|
+
flexDirection: "column",
|
|
1127
|
+
paddingLeft: 1,
|
|
1128
|
+
border: ["left"],
|
|
1129
|
+
borderColor: () => theme().text.action.primary.base,
|
|
927
1130
|
},
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
"text",
|
|
931
|
-
{
|
|
932
|
-
fg: () =>
|
|
933
|
-
seg.match
|
|
934
|
-
? theme().text.action.primary.base
|
|
935
|
-
: theme().text.base,
|
|
936
|
-
attributes: () =>
|
|
937
|
-
seg.match ? TextAttributes.BOLD : undefined,
|
|
938
|
-
},
|
|
939
|
-
seg.text
|
|
940
|
-
),
|
|
941
|
-
})
|
|
942
|
-
),
|
|
943
|
-
createComponent(Show, {
|
|
944
|
-
get when() {
|
|
945
|
-
return Boolean(selectedSessionBody());
|
|
946
|
-
},
|
|
947
|
-
get children() {
|
|
948
|
-
return el(
|
|
949
|
-
"box",
|
|
1131
|
+
el(
|
|
1132
|
+
"text",
|
|
950
1133
|
{
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
paddingTop: 1,
|
|
954
|
-
border: ["top"],
|
|
955
|
-
borderColor: () => theme().border.base,
|
|
1134
|
+
fg: () => theme().text.base,
|
|
1135
|
+
attributes: TextAttributes.BOLD,
|
|
956
1136
|
},
|
|
957
|
-
|
|
958
|
-
|
|
1137
|
+
() => `[${selectedHit()?.entry.id ?? ""}]`
|
|
1138
|
+
),
|
|
1139
|
+
el(
|
|
1140
|
+
"text",
|
|
1141
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1142
|
+
() => {
|
|
1143
|
+
const h = selectedHit();
|
|
1144
|
+
if (!h) return "";
|
|
1145
|
+
const scope = h.entry.project || "global";
|
|
1146
|
+
const coreLabel = h.entry.core ? " · Core: pinned" : "";
|
|
1147
|
+
return `File: ${h.entry.file} · Date: ${h.entry.date || "N/A"} · Scope: ${scope}${coreLabel}`;
|
|
1148
|
+
}
|
|
1149
|
+
),
|
|
1150
|
+
el(
|
|
1151
|
+
"text",
|
|
1152
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1153
|
+
() => `Tags: [${selectedHit()?.entry.tags ?? ""}]`
|
|
1154
|
+
)
|
|
1155
|
+
),
|
|
1156
|
+
el(
|
|
1157
|
+
"box",
|
|
1158
|
+
{
|
|
1159
|
+
flexDirection: "row",
|
|
1160
|
+
flexWrap: "wrap",
|
|
1161
|
+
marginTop: 1,
|
|
1162
|
+
},
|
|
1163
|
+
createComponent(For, {
|
|
1164
|
+
get each() {
|
|
1165
|
+
return splitHighlightedText(
|
|
1166
|
+
selectedHit()?.entry.fact ?? "",
|
|
1167
|
+
query()
|
|
1168
|
+
);
|
|
1169
|
+
},
|
|
1170
|
+
children: (seg: { text: string; match: boolean }) =>
|
|
1171
|
+
el(
|
|
1172
|
+
"text",
|
|
1173
|
+
{
|
|
1174
|
+
fg: () =>
|
|
1175
|
+
seg.match
|
|
1176
|
+
? theme().text.action.primary.base
|
|
1177
|
+
: theme().text.base,
|
|
1178
|
+
attributes: () =>
|
|
1179
|
+
seg.match ? TextAttributes.BOLD : undefined,
|
|
1180
|
+
},
|
|
1181
|
+
seg.text
|
|
1182
|
+
),
|
|
1183
|
+
})
|
|
1184
|
+
),
|
|
1185
|
+
createComponent(Show, {
|
|
1186
|
+
get when() {
|
|
1187
|
+
return Boolean(selectedSessionBody());
|
|
1188
|
+
},
|
|
1189
|
+
get children() {
|
|
1190
|
+
return el(
|
|
1191
|
+
"box",
|
|
959
1192
|
{
|
|
960
|
-
|
|
961
|
-
|
|
1193
|
+
flexDirection: "column",
|
|
1194
|
+
marginTop: 1,
|
|
1195
|
+
paddingTop: 1,
|
|
1196
|
+
border: ["top"],
|
|
1197
|
+
borderColor: () => theme().border.base,
|
|
962
1198
|
},
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
flexDirection: "row",
|
|
984
|
-
justifyContent: "space-between",
|
|
985
|
-
paddingX: 2,
|
|
986
|
-
paddingY: 1,
|
|
987
|
-
flexShrink: 0,
|
|
988
|
-
border: ["top"],
|
|
989
|
-
borderColor: () => theme().border.base,
|
|
990
|
-
},
|
|
991
|
-
el(
|
|
992
|
-
"text",
|
|
993
|
-
{ fg: () => theme().text.muted },
|
|
994
|
-
"enter select · ↑/↓ or ^n/^k move · ^t type · ^g topic · ^r mode · ^l resync · tab pane · esc"
|
|
995
|
-
),
|
|
996
|
-
el(
|
|
997
|
-
"text",
|
|
998
|
-
{ fg: () => theme().text.muted },
|
|
999
|
-
"0 tokens (100% local)"
|
|
1199
|
+
el(
|
|
1200
|
+
"text",
|
|
1201
|
+
{
|
|
1202
|
+
fg: () => theme().text.action.primary.base,
|
|
1203
|
+
attributes: TextAttributes.BOLD,
|
|
1204
|
+
},
|
|
1205
|
+
"◈ FULL SESSION CHECKPOINT MARKDOWN"
|
|
1206
|
+
),
|
|
1207
|
+
el(
|
|
1208
|
+
"text",
|
|
1209
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1210
|
+
() => selectedSessionBody()
|
|
1211
|
+
)
|
|
1212
|
+
);
|
|
1213
|
+
},
|
|
1214
|
+
})
|
|
1215
|
+
);
|
|
1216
|
+
},
|
|
1217
|
+
})
|
|
1218
|
+
)
|
|
1000
1219
|
)
|
|
1001
1220
|
)
|
|
1002
1221
|
);
|
|
@@ -1102,6 +1321,64 @@ export default {
|
|
|
1102
1321
|
}
|
|
1103
1322
|
};
|
|
1104
1323
|
|
|
1324
|
+
const quickDeleteFromSlash = async (rawArgs?: string) => {
|
|
1325
|
+
const id = typeof rawArgs === "string" ? rawArgs.trim() : "";
|
|
1326
|
+
if (!id) {
|
|
1327
|
+
context.ui.toast.show({
|
|
1328
|
+
title: "Local Memory Delete (0 tokens)",
|
|
1329
|
+
message: "Usage: /memory-delete <id>",
|
|
1330
|
+
variant: "warning",
|
|
1331
|
+
});
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
try {
|
|
1335
|
+
const res = await deleteMemoryEntry(rootDir, id);
|
|
1336
|
+
if (res.deleted.length === 0) {
|
|
1337
|
+
context.ui.toast.show({
|
|
1338
|
+
title: "Not Found",
|
|
1339
|
+
message: `No memory entry matched ID: ${id}`,
|
|
1340
|
+
variant: "warning",
|
|
1341
|
+
});
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
context.ui.toast.show({
|
|
1345
|
+
title: `Deleted ${res.deleted.map((d: { id: string }) => `[${d.id}]`).join(", ")} (0 tokens)`,
|
|
1346
|
+
message: `${res.total} entries remaining in vectors.json`,
|
|
1347
|
+
variant: "success",
|
|
1348
|
+
});
|
|
1349
|
+
} catch (err) {
|
|
1350
|
+
context.ui.toast.show({
|
|
1351
|
+
title: "Local Memory Error",
|
|
1352
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1353
|
+
variant: "error",
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
const quickImportFromSlash = async (rawArgs?: string) => {
|
|
1359
|
+
const arg = typeof rawArgs === "string" ? rawArgs.trim() : "";
|
|
1360
|
+
const limit = arg && /^\d+$/.test(arg) ? parseInt(arg, 10) : undefined;
|
|
1361
|
+
context.ui.toast.show({
|
|
1362
|
+
title: "Importing Local Memory (0 tokens)...",
|
|
1363
|
+
message: "Scanning AGENTS.md rules and opencode.db session history...",
|
|
1364
|
+
variant: "info",
|
|
1365
|
+
});
|
|
1366
|
+
try {
|
|
1367
|
+
const res = await safeImportMemory(rootDir, limit);
|
|
1368
|
+
context.ui.toast.show({
|
|
1369
|
+
title: "Local Memory Import Complete (0 tokens)",
|
|
1370
|
+
message: `Added ${res.importedFacts.length} rules & ${res.importedSessions.length} sessions (${res.syncResult.total} total indexed)`,
|
|
1371
|
+
variant: "success",
|
|
1372
|
+
});
|
|
1373
|
+
} catch (err) {
|
|
1374
|
+
context.ui.toast.show({
|
|
1375
|
+
title: "Local Memory Import Error",
|
|
1376
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1377
|
+
variant: "error",
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1105
1382
|
let layerRegistered = false;
|
|
1106
1383
|
context.ui.slot({
|
|
1107
1384
|
append: "app",
|
|
@@ -1143,6 +1420,38 @@ export default {
|
|
|
1143
1420
|
void quickStoreFromSlash(rawArgs);
|
|
1144
1421
|
},
|
|
1145
1422
|
},
|
|
1423
|
+
{
|
|
1424
|
+
id: "local.memory.delete",
|
|
1425
|
+
title: "Delete local memory entry by ID (0 tokens)...",
|
|
1426
|
+
description:
|
|
1427
|
+
"Zero-token slash command to delete a memory entry by ID: /memory-delete <id>",
|
|
1428
|
+
category: "Memory",
|
|
1429
|
+
palette: false,
|
|
1430
|
+
slash: {
|
|
1431
|
+
name: "memory-delete",
|
|
1432
|
+
arguments: true,
|
|
1433
|
+
},
|
|
1434
|
+
run: (input) => {
|
|
1435
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1436
|
+
void quickDeleteFromSlash(rawArgs);
|
|
1437
|
+
},
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
id: "local.memory.import",
|
|
1441
|
+
title: "Import existing AGENTS.md & session history (0 tokens)...",
|
|
1442
|
+
description:
|
|
1443
|
+
"Zero-token command to import existing AGENTS.md/CLAUDE.md rules and compacted session summaries from opencode.db: /memory-import [limit]",
|
|
1444
|
+
category: "Memory",
|
|
1445
|
+
palette: true,
|
|
1446
|
+
slash: {
|
|
1447
|
+
name: "memory-import",
|
|
1448
|
+
arguments: true,
|
|
1449
|
+
},
|
|
1450
|
+
run: (input) => {
|
|
1451
|
+
const rawArgs = typeof input === "string" ? input : (input as any)?.arguments;
|
|
1452
|
+
void quickImportFromSlash(rawArgs);
|
|
1453
|
+
},
|
|
1454
|
+
},
|
|
1146
1455
|
],
|
|
1147
1456
|
}));
|
|
1148
1457
|
}
|