@nandoblanco/opencode-local-memory 1.1.0 → 1.2.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 +31 -10
- package/dist/gui-experimental.cjs +1 -0
- package/gui.css +635 -0
- package/gui.tsx +1314 -0
- package/index.js +333 -6
- package/package.json +23 -3
- package/rpc.d.ts +140 -0
- package/rpc.js +221 -0
- package/tui.ts +970 -265
package/tui.ts
CHANGED
|
@@ -55,11 +55,13 @@ interface MemoryHit {
|
|
|
55
55
|
entry: MemoryEntry;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
type TypeFilter = "all" | "topics" | "sessions";
|
|
58
|
+
type TypeFilter = "all" | "core" | "topics" | "sessions";
|
|
59
59
|
type ModeFilter = "hybrid" | "keyword" | "regex";
|
|
60
|
+
type EditorField = "topic" | "tags" | "project" | "core" | "fact";
|
|
60
61
|
|
|
61
|
-
const TYPE_CYCLE: TypeFilter[] = ["all", "topics", "sessions"];
|
|
62
|
+
const TYPE_CYCLE: TypeFilter[] = ["all", "core", "topics", "sessions"];
|
|
62
63
|
const MODE_CYCLE: ModeFilter[] = ["hybrid", "keyword", "regex"];
|
|
64
|
+
const EDITOR_FIELDS: EditorField[] = ["topic", "tags", "project", "core", "fact"];
|
|
63
65
|
const CLI_SCRIPT_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "index.js");
|
|
64
66
|
|
|
65
67
|
function runCliSubprocess(args: string[]): Promise<string> {
|
|
@@ -98,6 +100,48 @@ async function safeImportMemory(rootDir: string, limit?: number) {
|
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
async function safeStoreMemory(
|
|
104
|
+
rootDir: string,
|
|
105
|
+
payload: {
|
|
106
|
+
id?: string;
|
|
107
|
+
topic: string;
|
|
108
|
+
tags: string;
|
|
109
|
+
fact: string;
|
|
110
|
+
project?: string;
|
|
111
|
+
core?: boolean;
|
|
112
|
+
}
|
|
113
|
+
) {
|
|
114
|
+
try {
|
|
115
|
+
return await storeMemoryFact(rootDir, payload);
|
|
116
|
+
} catch {
|
|
117
|
+
const stdout = await runCliSubprocess([
|
|
118
|
+
"store-json",
|
|
119
|
+
"--dir",
|
|
120
|
+
rootDir,
|
|
121
|
+
"--payload",
|
|
122
|
+
JSON.stringify(payload),
|
|
123
|
+
]);
|
|
124
|
+
const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
|
|
125
|
+
return JSON.parse(lines[lines.length - 1]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function safeDeleteMemory(rootDir: string, id: string) {
|
|
130
|
+
try {
|
|
131
|
+
return await deleteMemoryEntry(rootDir, id);
|
|
132
|
+
} catch {
|
|
133
|
+
const stdout = await runCliSubprocess([
|
|
134
|
+
"delete-json",
|
|
135
|
+
"--dir",
|
|
136
|
+
rootDir,
|
|
137
|
+
"--payload",
|
|
138
|
+
JSON.stringify({ id }),
|
|
139
|
+
]);
|
|
140
|
+
const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
|
|
141
|
+
return JSON.parse(lines[lines.length - 1]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
101
145
|
function splitHighlightedText(
|
|
102
146
|
text: string,
|
|
103
147
|
term: string
|
|
@@ -219,6 +263,15 @@ function createTuiRenderer() {
|
|
|
219
263
|
const [allEntries, setAllEntries] = createSignal<MemoryEntry[]>([]);
|
|
220
264
|
const [hits, setHits] = createSignal<MemoryHit[]>([]);
|
|
221
265
|
const [statusMsg, setStatusMsg] = createSignal("");
|
|
266
|
+
const [editorMode, setEditorMode] = createSignal<null | "add" | "edit">(null);
|
|
267
|
+
const [editorField, setEditorField] = createSignal<EditorField>("fact");
|
|
268
|
+
const [editId, setEditId] = createSignal("");
|
|
269
|
+
const [editTopic, setEditTopic] = createSignal("preferences");
|
|
270
|
+
const [editTags, setEditTags] = createSignal("");
|
|
271
|
+
const [editProject, setEditProject] = createSignal("global");
|
|
272
|
+
const [editCore, setEditCore] = createSignal(false);
|
|
273
|
+
const [editFact, setEditFact] = createSignal("");
|
|
274
|
+
const [confirmDeleteId, setConfirmDeleteId] = createSignal<string | null>(null);
|
|
222
275
|
|
|
223
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
277
|
let rootRef: any;
|
|
@@ -304,6 +357,9 @@ function createTuiRenderer() {
|
|
|
304
357
|
effType = "topics";
|
|
305
358
|
} else if (lower === "type:sessions" || lower === "in:sessions") {
|
|
306
359
|
effType = "sessions";
|
|
360
|
+
} else if (lower === "type:core" || lower === "in:core") {
|
|
361
|
+
effType = "core";
|
|
362
|
+
effCoreOnly = true;
|
|
307
363
|
} else if (lower === "type:all") {
|
|
308
364
|
effType = "all";
|
|
309
365
|
} else if (lower === "core:true" || lower === "is:core") {
|
|
@@ -322,6 +378,10 @@ function createTuiRenderer() {
|
|
|
322
378
|
}
|
|
323
379
|
}
|
|
324
380
|
|
|
381
|
+
if (effType === "core") {
|
|
382
|
+
effCoreOnly = true;
|
|
383
|
+
}
|
|
384
|
+
|
|
325
385
|
return {
|
|
326
386
|
cleanQ: cleanTokens.join(" ").trim(),
|
|
327
387
|
effType,
|
|
@@ -347,6 +407,7 @@ function createTuiRenderer() {
|
|
|
347
407
|
);
|
|
348
408
|
|
|
349
409
|
const subset = entries.filter((e) => {
|
|
410
|
+
if (effType === "core" && !e.core) return false;
|
|
350
411
|
if (effType === "topics" && !e.file.startsWith("topics/")) return false;
|
|
351
412
|
if (effType === "sessions" && !e.file.startsWith("sessions/")) return false;
|
|
352
413
|
if (effTopic !== "all" && e.file !== `topics/${effTopic}.md`) return false;
|
|
@@ -356,9 +417,10 @@ function createTuiRenderer() {
|
|
|
356
417
|
});
|
|
357
418
|
|
|
358
419
|
if (!q) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
420
|
+
const topicPart = subset.filter((e) => !e.file.startsWith("sessions/")).reverse();
|
|
421
|
+
const sessionPart = subset.filter((e) => e.file.startsWith("sessions/")).reverse();
|
|
422
|
+
return topicPart
|
|
423
|
+
.concat(sessionPart)
|
|
362
424
|
.map((e) => ({ score: 1, semanticScore: 0, entry: e }));
|
|
363
425
|
}
|
|
364
426
|
|
|
@@ -432,6 +494,7 @@ function createTuiRenderer() {
|
|
|
432
494
|
});
|
|
433
495
|
if (currentSeq !== searchSeq) return;
|
|
434
496
|
const filtered = semHits.filter((h) => {
|
|
497
|
+
if (effType === "core" && !h.entry.core) return false;
|
|
435
498
|
if (effType === "topics" && !h.entry.file.startsWith("topics/")) return false;
|
|
436
499
|
if (effType === "sessions" && !h.entry.file.startsWith("sessions/")) return false;
|
|
437
500
|
if (effTopic !== "all" && h.entry.file !== `topics/${effTopic}.md`) return false;
|
|
@@ -444,7 +507,7 @@ function createTuiRenderer() {
|
|
|
444
507
|
}
|
|
445
508
|
};
|
|
446
509
|
|
|
447
|
-
const reloadVectors = async (forceSync = false) => {
|
|
510
|
+
const reloadVectors = async (forceSync = false, selectId?: string) => {
|
|
448
511
|
if (forceSync) {
|
|
449
512
|
setStatusMsg("syncing markdown -> vectors.json...");
|
|
450
513
|
await safeSyncVectors(props.rootDir).catch(() => {});
|
|
@@ -453,6 +516,177 @@ function createTuiRenderer() {
|
|
|
453
516
|
const loaded = (loadCachedVectors(props.rootDir) || []) as MemoryEntry[];
|
|
454
517
|
setAllEntries(loaded);
|
|
455
518
|
await runSearch();
|
|
519
|
+
if (selectId) {
|
|
520
|
+
const idx = hits().findIndex((h) => h.entry.id === selectId);
|
|
521
|
+
if (idx >= 0) {
|
|
522
|
+
setSelectedIndex(idx);
|
|
523
|
+
queueMicrotask(() => listScrollRef?.scrollChildIntoView?.(`memory-row-${idx}`));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const startAdd = () => {
|
|
529
|
+
setConfirmDeleteId(null);
|
|
530
|
+
const currentTopic = topicFilter() !== "all" ? topicFilter() : "preferences";
|
|
531
|
+
setEditId("");
|
|
532
|
+
setEditTopic(currentTopic);
|
|
533
|
+
setEditTags(currentTopic);
|
|
534
|
+
setEditProject("global");
|
|
535
|
+
setEditCore(typeFilter() === "core");
|
|
536
|
+
setEditFact("");
|
|
537
|
+
setEditorField("fact");
|
|
538
|
+
setEditorMode("add");
|
|
539
|
+
setFocusPane("preview");
|
|
540
|
+
setStatusMsg("adding new memory fact (Tab fields · ^S/Enter save · Esc cancel)");
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const startEdit = () => {
|
|
544
|
+
setConfirmDeleteId(null);
|
|
545
|
+
const current = selectedHit();
|
|
546
|
+
if (!current) return;
|
|
547
|
+
if (!current.entry.file.startsWith("topics/")) {
|
|
548
|
+
props.context.ui.toast.show({
|
|
549
|
+
title: "Session Checkpoints are Read-Only",
|
|
550
|
+
message: "Select a topic fact (topics/*.md) to edit inline, or press ^N to add a new fact.",
|
|
551
|
+
variant: "warning",
|
|
552
|
+
});
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const topicSlug = current.entry.file.replace(/^topics\//, "").replace(/\.md$/, "");
|
|
556
|
+
setEditId(current.entry.id);
|
|
557
|
+
setEditTopic(topicSlug || "preferences");
|
|
558
|
+
setEditTags(current.entry.tags || "");
|
|
559
|
+
setEditProject(current.entry.project || "global");
|
|
560
|
+
setEditCore(Boolean(current.entry.core));
|
|
561
|
+
setEditFact(current.entry.fact || "");
|
|
562
|
+
setEditorField("fact");
|
|
563
|
+
setEditorMode("edit");
|
|
564
|
+
setFocusPane("preview");
|
|
565
|
+
setStatusMsg(`editing [${current.entry.id}] (Tab fields · ^S/Enter save · Esc cancel)`);
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const cancelEditor = () => {
|
|
569
|
+
setEditorMode(null);
|
|
570
|
+
setConfirmDeleteId(null);
|
|
571
|
+
setStatusMsg("");
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
const saveEditor = async () => {
|
|
575
|
+
const modeVal = editorMode();
|
|
576
|
+
if (!modeVal) return;
|
|
577
|
+
const topic = editTopic().trim() || "preferences";
|
|
578
|
+
const fact = editFact().trim();
|
|
579
|
+
if (!fact) {
|
|
580
|
+
props.context.ui.toast.show({
|
|
581
|
+
title: "Fact Required",
|
|
582
|
+
message: "Enter a non-empty memory fact before saving.",
|
|
583
|
+
variant: "warning",
|
|
584
|
+
});
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const tags = editTags().trim() || topic;
|
|
588
|
+
const project = editProject().trim() || "global";
|
|
589
|
+
const core = Boolean(editCore());
|
|
590
|
+
const id = modeVal === "edit" ? editId().trim() || undefined : undefined;
|
|
591
|
+
setStatusMsg(modeVal === "edit" ? `saving [${id}]...` : "storing new memory...");
|
|
592
|
+
try {
|
|
593
|
+
const saved = await safeStoreMemory(props.rootDir, {
|
|
594
|
+
id,
|
|
595
|
+
topic,
|
|
596
|
+
tags,
|
|
597
|
+
fact,
|
|
598
|
+
project,
|
|
599
|
+
core,
|
|
600
|
+
});
|
|
601
|
+
setEditorMode(null);
|
|
602
|
+
setStatusMsg("");
|
|
603
|
+
await reloadVectors(false, saved.id);
|
|
604
|
+
props.context.ui.toast.show({
|
|
605
|
+
title: modeVal === "edit" ? `Updated [${saved.id}] (0 tokens)` : `Stored [${saved.id}] (0 tokens)`,
|
|
606
|
+
message: `${saved.file}: ${saved.fact.slice(0, 90)}`,
|
|
607
|
+
variant: "success",
|
|
608
|
+
});
|
|
609
|
+
} catch (err) {
|
|
610
|
+
setStatusMsg("");
|
|
611
|
+
props.context.ui.toast.show({
|
|
612
|
+
title: "Memory Save Error",
|
|
613
|
+
message: err instanceof Error ? err.message : String(err),
|
|
614
|
+
variant: "error",
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const toggleSelectedCore = async () => {
|
|
620
|
+
setConfirmDeleteId(null);
|
|
621
|
+
const current = selectedHit();
|
|
622
|
+
if (!current) return;
|
|
623
|
+
if (!current.entry.file.startsWith("topics/")) {
|
|
624
|
+
props.context.ui.toast.show({
|
|
625
|
+
title: "Topic Facts Only",
|
|
626
|
+
message: "Only topic facts (topics/*.md) can be pinned as core memories.",
|
|
627
|
+
variant: "warning",
|
|
628
|
+
});
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const topic = current.entry.file.replace(/^topics\//, "").replace(/\.md$/, "");
|
|
632
|
+
const nextCore = !current.entry.core;
|
|
633
|
+
setStatusMsg(`${nextCore ? "pinning" : "unpinning"} [${current.entry.id}]...`);
|
|
634
|
+
try {
|
|
635
|
+
const saved = await safeStoreMemory(props.rootDir, {
|
|
636
|
+
id: current.entry.id,
|
|
637
|
+
topic,
|
|
638
|
+
tags: current.entry.tags,
|
|
639
|
+
fact: current.entry.fact,
|
|
640
|
+
project: current.entry.project || "global",
|
|
641
|
+
core: nextCore,
|
|
642
|
+
});
|
|
643
|
+
setStatusMsg("");
|
|
644
|
+
await reloadVectors(false, saved.id);
|
|
645
|
+
props.context.ui.toast.show({
|
|
646
|
+
title: nextCore ? `Pinned [${saved.id}] as Core` : `Unpinned [${saved.id}]`,
|
|
647
|
+
message: nextCore
|
|
648
|
+
? "Injected automatically on every turn."
|
|
649
|
+
: "Removed from pinned core memories.",
|
|
650
|
+
variant: "success",
|
|
651
|
+
});
|
|
652
|
+
} catch (err) {
|
|
653
|
+
setStatusMsg("");
|
|
654
|
+
props.context.ui.toast.show({
|
|
655
|
+
title: "Pin Toggle Error",
|
|
656
|
+
message: err instanceof Error ? err.message : String(err),
|
|
657
|
+
variant: "error",
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
const promptOrConfirmDelete = async () => {
|
|
663
|
+
const current = selectedHit();
|
|
664
|
+
if (!current) return;
|
|
665
|
+
const targetId = current.entry.id;
|
|
666
|
+
if (confirmDeleteId() !== targetId) {
|
|
667
|
+
setConfirmDeleteId(targetId);
|
|
668
|
+
setStatusMsg(`confirm delete [${targetId}]? press ^D or Enter again (Esc cancels)`);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
setConfirmDeleteId(null);
|
|
672
|
+
setStatusMsg(`deleting [${targetId}]...`);
|
|
673
|
+
try {
|
|
674
|
+
const res = await safeDeleteMemory(props.rootDir, targetId);
|
|
675
|
+
setStatusMsg("");
|
|
676
|
+
await reloadVectors(false);
|
|
677
|
+
props.context.ui.toast.show({
|
|
678
|
+
title: `Deleted [${targetId}] (0 tokens)`,
|
|
679
|
+
message: `${res.total} entries remaining in vectors.json`,
|
|
680
|
+
variant: "success",
|
|
681
|
+
});
|
|
682
|
+
} catch (err) {
|
|
683
|
+
setStatusMsg("");
|
|
684
|
+
props.context.ui.toast.show({
|
|
685
|
+
title: "Delete Error",
|
|
686
|
+
message: err instanceof Error ? err.message : String(err),
|
|
687
|
+
variant: "error",
|
|
688
|
+
});
|
|
689
|
+
}
|
|
456
690
|
};
|
|
457
691
|
|
|
458
692
|
const runImportInDialog = async () => {
|
|
@@ -532,10 +766,43 @@ function createTuiRenderer() {
|
|
|
532
766
|
if (name === "escape") {
|
|
533
767
|
event.preventDefault();
|
|
534
768
|
event.stopPropagation();
|
|
769
|
+
if (editorMode()) {
|
|
770
|
+
cancelEditor();
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (confirmDeleteId()) {
|
|
774
|
+
setConfirmDeleteId(null);
|
|
775
|
+
setStatusMsg("");
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
535
778
|
props.close();
|
|
536
779
|
return;
|
|
537
780
|
}
|
|
538
781
|
|
|
782
|
+
if (editorMode()) {
|
|
783
|
+
if (name === "tab") {
|
|
784
|
+
event.preventDefault();
|
|
785
|
+
event.stopPropagation();
|
|
786
|
+
const idx = EDITOR_FIELDS.indexOf(editorField());
|
|
787
|
+
const next = EDITOR_FIELDS[(idx + (event.shift ? -1 : 1) + EDITOR_FIELDS.length) % EDITOR_FIELDS.length];
|
|
788
|
+
setEditorField(next);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if ((event.ctrl && name === "s") || name === "return" || name === "enter" || name === "kpenter") {
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
event.stopPropagation();
|
|
794
|
+
void saveEditor();
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
if (editorField() === "core" && name === "space") {
|
|
798
|
+
event.preventDefault();
|
|
799
|
+
event.stopPropagation();
|
|
800
|
+
setEditCore((v) => !v);
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
539
806
|
if (name === "tab") {
|
|
540
807
|
event.preventDefault();
|
|
541
808
|
event.stopPropagation();
|
|
@@ -564,6 +831,30 @@ function createTuiRenderer() {
|
|
|
564
831
|
cycleMode();
|
|
565
832
|
return;
|
|
566
833
|
}
|
|
834
|
+
if (event.ctrl && name === "n") {
|
|
835
|
+
event.preventDefault();
|
|
836
|
+
event.stopPropagation();
|
|
837
|
+
startAdd();
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
if (event.ctrl && name === "e") {
|
|
841
|
+
event.preventDefault();
|
|
842
|
+
event.stopPropagation();
|
|
843
|
+
startEdit();
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (event.ctrl && name === "p") {
|
|
847
|
+
event.preventDefault();
|
|
848
|
+
event.stopPropagation();
|
|
849
|
+
void toggleSelectedCore();
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (event.ctrl && name === "d") {
|
|
853
|
+
event.preventDefault();
|
|
854
|
+
event.stopPropagation();
|
|
855
|
+
void promptOrConfirmDelete();
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
567
858
|
if (event.ctrl && name === "l") {
|
|
568
859
|
event.preventDefault();
|
|
569
860
|
event.stopPropagation();
|
|
@@ -577,7 +868,13 @@ function createTuiRenderer() {
|
|
|
577
868
|
return;
|
|
578
869
|
}
|
|
579
870
|
|
|
580
|
-
if (name === "return" || name === "enter") {
|
|
871
|
+
if (name === "return" || name === "enter" || name === "kpenter") {
|
|
872
|
+
if (confirmDeleteId()) {
|
|
873
|
+
event.preventDefault();
|
|
874
|
+
event.stopPropagation();
|
|
875
|
+
void promptOrConfirmDelete();
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
581
878
|
const current = selectedHit();
|
|
582
879
|
if (current) {
|
|
583
880
|
event.preventDefault();
|
|
@@ -606,11 +903,12 @@ function createTuiRenderer() {
|
|
|
606
903
|
|
|
607
904
|
if (
|
|
608
905
|
name === "down" ||
|
|
609
|
-
(event.ctrl &&
|
|
610
|
-
(focusPane() !== "
|
|
906
|
+
(event.ctrl && name === "j") ||
|
|
907
|
+
(focusPane() !== "search" && !event.ctrl && name === "j")
|
|
611
908
|
) {
|
|
612
909
|
event.preventDefault();
|
|
613
910
|
event.stopPropagation();
|
|
911
|
+
setConfirmDeleteId(null);
|
|
614
912
|
if (focusPane() === "preview" && !event.ctrl && name === "j") {
|
|
615
913
|
previewScrollRef?.scrollBy?.(2);
|
|
616
914
|
} else {
|
|
@@ -620,11 +918,12 @@ function createTuiRenderer() {
|
|
|
620
918
|
}
|
|
621
919
|
if (
|
|
622
920
|
name === "up" ||
|
|
623
|
-
(event.ctrl &&
|
|
624
|
-
(focusPane() !== "
|
|
921
|
+
(event.ctrl && name === "k") ||
|
|
922
|
+
(focusPane() !== "search" && !event.ctrl && name === "k")
|
|
625
923
|
) {
|
|
626
924
|
event.preventDefault();
|
|
627
925
|
event.stopPropagation();
|
|
926
|
+
setConfirmDeleteId(null);
|
|
628
927
|
if (focusPane() === "preview" && !event.ctrl && name === "k") {
|
|
629
928
|
previewScrollRef?.scrollBy?.(-2);
|
|
630
929
|
} else {
|
|
@@ -632,9 +931,10 @@ function createTuiRenderer() {
|
|
|
632
931
|
}
|
|
633
932
|
return;
|
|
634
933
|
}
|
|
635
|
-
if (name === "pagedown" || (event.ctrl && name === "
|
|
934
|
+
if (name === "pagedown" || (event.ctrl && name === "f")) {
|
|
636
935
|
event.preventDefault();
|
|
637
936
|
event.stopPropagation();
|
|
937
|
+
setConfirmDeleteId(null);
|
|
638
938
|
if (focusPane() === "preview") {
|
|
639
939
|
previewScrollRef?.scrollBy?.(8);
|
|
640
940
|
} else {
|
|
@@ -645,6 +945,7 @@ function createTuiRenderer() {
|
|
|
645
945
|
if (name === "pageup" || (event.ctrl && name === "u")) {
|
|
646
946
|
event.preventDefault();
|
|
647
947
|
event.stopPropagation();
|
|
948
|
+
setConfirmDeleteId(null);
|
|
648
949
|
if (focusPane() === "preview") {
|
|
649
950
|
previewScrollRef?.scrollBy?.(-8);
|
|
650
951
|
} else {
|
|
@@ -716,99 +1017,147 @@ function createTuiRenderer() {
|
|
|
716
1017
|
queueMicrotask(applyDialogWidth);
|
|
717
1018
|
},
|
|
718
1019
|
width: "100%",
|
|
719
|
-
height:
|
|
1020
|
+
height: 34,
|
|
720
1021
|
flexDirection: "column",
|
|
721
1022
|
backgroundColor: () => theme().background.base,
|
|
1023
|
+
paddingLeft: 2,
|
|
1024
|
+
paddingRight: 2,
|
|
1025
|
+
paddingTop: 1,
|
|
1026
|
+
paddingBottom: 1,
|
|
1027
|
+
gap: 1,
|
|
722
1028
|
},
|
|
723
|
-
// 1. Header Bar
|
|
1029
|
+
// 1. Header Bar (single-line, no wrapping)
|
|
724
1030
|
el(
|
|
725
1031
|
"box",
|
|
726
1032
|
{
|
|
727
1033
|
flexDirection: "row",
|
|
728
1034
|
justifyContent: "space-between",
|
|
729
1035
|
alignItems: "center",
|
|
730
|
-
|
|
731
|
-
|
|
1036
|
+
border: ["bottom"],
|
|
1037
|
+
borderColor: () => theme().border.base,
|
|
1038
|
+
paddingBottom: 0,
|
|
732
1039
|
flexShrink: 0,
|
|
1040
|
+
width: "100%",
|
|
733
1041
|
},
|
|
734
1042
|
el(
|
|
735
1043
|
"box",
|
|
736
|
-
{ flexDirection: "row", gap: 2, alignItems: "center" },
|
|
1044
|
+
{ flexDirection: "row", gap: 2, alignItems: "center", flexShrink: 0 },
|
|
737
1045
|
el(
|
|
738
1046
|
"text",
|
|
739
1047
|
{
|
|
740
|
-
|
|
1048
|
+
wrapMode: "none",
|
|
1049
|
+
flexShrink: 0,
|
|
1050
|
+
fg: () => theme().text.action.primary.base,
|
|
741
1051
|
attributes: TextAttributes.BOLD,
|
|
742
1052
|
},
|
|
743
|
-
"
|
|
1053
|
+
"opencode / memory"
|
|
744
1054
|
),
|
|
745
1055
|
el(
|
|
746
1056
|
"text",
|
|
747
|
-
{
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1057
|
+
{
|
|
1058
|
+
wrapMode: "none",
|
|
1059
|
+
flexShrink: 0,
|
|
1060
|
+
fg: () => theme().text.muted,
|
|
1061
|
+
},
|
|
1062
|
+
() => props.context.ui.format.path(props.rootDir)
|
|
751
1063
|
)
|
|
752
1064
|
),
|
|
753
1065
|
el(
|
|
754
|
-
"
|
|
755
|
-
{
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
el(
|
|
762
|
-
"box",
|
|
763
|
-
{ paddingX: 1, onMouseUp: () => props.close() },
|
|
764
|
-
el("text", { fg: () => theme().text.muted }, "esc")
|
|
765
|
-
)
|
|
1066
|
+
"text",
|
|
1067
|
+
{
|
|
1068
|
+
wrapMode: "none",
|
|
1069
|
+
flexShrink: 0,
|
|
1070
|
+
fg: () => theme().text.muted,
|
|
1071
|
+
},
|
|
1072
|
+
"[↑↓] select [^N] add [^E] edit [^P] pin [^D] delete [Esc] close"
|
|
766
1073
|
)
|
|
767
1074
|
),
|
|
768
1075
|
|
|
769
|
-
// 2.
|
|
1076
|
+
// 2. Boxed Filter + Pills Card
|
|
770
1077
|
el(
|
|
771
1078
|
"box",
|
|
772
1079
|
{
|
|
773
1080
|
flexDirection: "column",
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
1081
|
+
backgroundColor: () =>
|
|
1082
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1083
|
+
border: true,
|
|
1084
|
+
borderColor: () =>
|
|
1085
|
+
focusPane() === "search"
|
|
1086
|
+
? theme().text.action.primary.base
|
|
1087
|
+
: theme().border.base,
|
|
1088
|
+
paddingLeft: 2,
|
|
1089
|
+
paddingRight: 2,
|
|
1090
|
+
paddingTop: 0,
|
|
1091
|
+
paddingBottom: 0,
|
|
1092
|
+
gap: 0,
|
|
777
1093
|
flexShrink: 0,
|
|
778
|
-
|
|
779
|
-
borderColor: () => theme().border.base,
|
|
1094
|
+
width: "100%",
|
|
780
1095
|
},
|
|
781
1096
|
el(
|
|
782
1097
|
"box",
|
|
783
|
-
{
|
|
1098
|
+
{
|
|
1099
|
+
flexDirection: "row",
|
|
1100
|
+
justifyContent: "space-between",
|
|
1101
|
+
alignItems: "center",
|
|
1102
|
+
gap: 1,
|
|
1103
|
+
width: "100%",
|
|
1104
|
+
},
|
|
784
1105
|
el(
|
|
785
1106
|
"text",
|
|
786
1107
|
{
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
1108
|
+
width: 7,
|
|
1109
|
+
wrapMode: "none",
|
|
1110
|
+
flexShrink: 0,
|
|
1111
|
+
fg: () => theme().text.action.primary.base,
|
|
791
1112
|
attributes: TextAttributes.BOLD,
|
|
792
1113
|
},
|
|
793
|
-
"
|
|
1114
|
+
"Filter:"
|
|
794
1115
|
),
|
|
795
|
-
el(
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1116
|
+
el(
|
|
1117
|
+
"box",
|
|
1118
|
+
{
|
|
1119
|
+
flexGrow: 1,
|
|
1120
|
+
flexShrink: 1,
|
|
1121
|
+
minWidth: 0,
|
|
1122
|
+
},
|
|
1123
|
+
el("input", {
|
|
1124
|
+
id: "local-memory-search-input",
|
|
1125
|
+
width: "100%",
|
|
1126
|
+
value: () => query(),
|
|
1127
|
+
focused: () => !editorMode() && focusPane() === "search",
|
|
1128
|
+
maxLength: Number.POSITIVE_INFINITY,
|
|
1129
|
+
placeholder:
|
|
1130
|
+
"Search memories (semantic + keyword, topic:name, project:slug, /regex/i)...",
|
|
1131
|
+
placeholderColor: () => theme().text.muted,
|
|
1132
|
+
textColor: () => theme().text.base,
|
|
1133
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
1134
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
1135
|
+
backgroundColor: () =>
|
|
1136
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1137
|
+
focusedBackgroundColor: () =>
|
|
1138
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1139
|
+
onMouseDown: () => {
|
|
1140
|
+
setEditorMode(null);
|
|
1141
|
+
setFocusPane("search");
|
|
1142
|
+
},
|
|
1143
|
+
onInput: (val: string) => setQuery(val),
|
|
1144
|
+
})
|
|
1145
|
+
),
|
|
1146
|
+
el(
|
|
1147
|
+
"text",
|
|
1148
|
+
{
|
|
1149
|
+
wrapMode: "none",
|
|
1150
|
+
flexShrink: 0,
|
|
1151
|
+
fg: () =>
|
|
1152
|
+
confirmDeleteId()
|
|
1153
|
+
? theme().text.feedback?.warning?.base ?? theme().text.action.primary.base
|
|
1154
|
+
: theme().text.feedback?.success?.base ??
|
|
1155
|
+
theme().text.action.primary.base,
|
|
1156
|
+
},
|
|
1157
|
+
() =>
|
|
1158
|
+
statusMsg() ||
|
|
1159
|
+
`${hits().length} of ${allEntries().length} entries · 0 tokens`
|
|
1160
|
+
)
|
|
812
1161
|
),
|
|
813
1162
|
el(
|
|
814
1163
|
"box",
|
|
@@ -831,268 +1180,624 @@ function createTuiRenderer() {
|
|
|
831
1180
|
active: () => mode() !== "hybrid",
|
|
832
1181
|
onClick: cycleMode,
|
|
833
1182
|
}),
|
|
1183
|
+
Pill({
|
|
1184
|
+
label: () => "+ add",
|
|
1185
|
+
shortcut: "^n",
|
|
1186
|
+
active: () => editorMode() === "add",
|
|
1187
|
+
onClick: startAdd,
|
|
1188
|
+
}),
|
|
1189
|
+
Pill({
|
|
1190
|
+
label: () => "edit",
|
|
1191
|
+
shortcut: "^e",
|
|
1192
|
+
active: () => editorMode() === "edit",
|
|
1193
|
+
onClick: startEdit,
|
|
1194
|
+
}),
|
|
1195
|
+
Pill({
|
|
1196
|
+
label: () => (selectedHit()?.entry.core ? "unpin" : "pin core"),
|
|
1197
|
+
shortcut: "^p",
|
|
1198
|
+
active: () => Boolean(selectedHit()?.entry.core),
|
|
1199
|
+
onClick: () => void toggleSelectedCore(),
|
|
1200
|
+
}),
|
|
1201
|
+
Pill({
|
|
1202
|
+
label: () => (confirmDeleteId() ? "confirm del!" : "delete"),
|
|
1203
|
+
shortcut: "^d",
|
|
1204
|
+
active: () => Boolean(confirmDeleteId()),
|
|
1205
|
+
onClick: () => void promptOrConfirmDelete(),
|
|
1206
|
+
}),
|
|
834
1207
|
Pill({
|
|
835
1208
|
label: () => "import",
|
|
836
1209
|
shortcut: "^b",
|
|
837
1210
|
active: () => false,
|
|
838
1211
|
onClick: () => void runImportInDialog(),
|
|
1212
|
+
}),
|
|
1213
|
+
Pill({
|
|
1214
|
+
label: () => "resync",
|
|
1215
|
+
shortcut: "^l",
|
|
1216
|
+
active: () => false,
|
|
1217
|
+
onClick: () => void reloadVectors(true),
|
|
839
1218
|
})
|
|
840
1219
|
)
|
|
841
1220
|
),
|
|
842
1221
|
|
|
843
|
-
// 3. Split-Pane Body
|
|
1222
|
+
// 3. Split-Pane Body: Two Side-by-Side Bordered Cards
|
|
844
1223
|
el(
|
|
845
1224
|
"box",
|
|
846
|
-
{ flexDirection: "row", flexGrow: 1, minHeight: 0 },
|
|
847
|
-
// Left: Results List (44%)
|
|
1225
|
+
{ flexDirection: "row", gap: 2, flexGrow: 1, minHeight: 0, width: "100%" },
|
|
1226
|
+
// Left Card: Results List (44%)
|
|
848
1227
|
el(
|
|
849
|
-
"
|
|
1228
|
+
"box",
|
|
850
1229
|
{
|
|
851
|
-
id: "local-memory-list",
|
|
852
|
-
ref: (r: unknown) => {
|
|
853
|
-
listScrollRef = r;
|
|
854
|
-
},
|
|
855
1230
|
width: "44%",
|
|
856
1231
|
height: "100%",
|
|
1232
|
+
flexDirection: "column",
|
|
857
1233
|
flexShrink: 0,
|
|
858
|
-
|
|
1234
|
+
backgroundColor: () =>
|
|
1235
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1236
|
+
border: true,
|
|
859
1237
|
borderColor: () =>
|
|
860
|
-
focusPane() === "list"
|
|
861
|
-
|
|
1238
|
+
focusPane() === "list"
|
|
1239
|
+
? theme().text.action.primary.base
|
|
1240
|
+
: theme().border.base,
|
|
1241
|
+
paddingLeft: 1,
|
|
1242
|
+
paddingRight: 1,
|
|
1243
|
+
paddingTop: 0,
|
|
1244
|
+
paddingBottom: 0,
|
|
862
1245
|
onMouseDown: () => setFocusPane("list"),
|
|
863
1246
|
},
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1247
|
+
el(
|
|
1248
|
+
"box",
|
|
1249
|
+
{
|
|
1250
|
+
flexDirection: "row",
|
|
1251
|
+
justifyContent: "space-between",
|
|
1252
|
+
border: ["bottom"],
|
|
1253
|
+
borderColor: () => theme().border.base,
|
|
1254
|
+
paddingX: 1,
|
|
1255
|
+
flexShrink: 0,
|
|
867
1256
|
},
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1257
|
+
el(
|
|
1258
|
+
"text",
|
|
1259
|
+
{
|
|
1260
|
+
fg: () => theme().text.action.primary.base,
|
|
1261
|
+
attributes: TextAttributes.BOLD,
|
|
1262
|
+
},
|
|
1263
|
+
"◈ MEMORY ENTRIES"
|
|
1264
|
+
),
|
|
1265
|
+
el(
|
|
1266
|
+
"text",
|
|
1267
|
+
{ fg: () => theme().text.muted },
|
|
1268
|
+
() => `${mode()} · ${typeFilter()}`
|
|
1269
|
+
)
|
|
1270
|
+
),
|
|
1271
|
+
el(
|
|
1272
|
+
"scrollbox",
|
|
1273
|
+
{
|
|
1274
|
+
id: "local-memory-list",
|
|
1275
|
+
ref: (r: unknown) => {
|
|
1276
|
+
listScrollRef = r;
|
|
1277
|
+
},
|
|
1278
|
+
width: "100%",
|
|
1279
|
+
flexGrow: 1,
|
|
1280
|
+
minHeight: 0,
|
|
1281
|
+
scrollbarOptions: { visible: false },
|
|
878
1282
|
},
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
el(
|
|
1283
|
+
createComponent(Show, {
|
|
1284
|
+
get when() {
|
|
1285
|
+
return hits().length > 0;
|
|
1286
|
+
},
|
|
1287
|
+
get fallback() {
|
|
1288
|
+
return el(
|
|
1289
|
+
"box",
|
|
1290
|
+
{ paddingX: 1, paddingY: 1 },
|
|
1291
|
+
el(
|
|
1292
|
+
"text",
|
|
1293
|
+
{ fg: () => theme().text.muted },
|
|
1294
|
+
"No matching memory entries found."
|
|
1295
|
+
)
|
|
1296
|
+
);
|
|
1297
|
+
},
|
|
1298
|
+
get children() {
|
|
1299
|
+
return createComponent(For, {
|
|
1300
|
+
get each() {
|
|
1301
|
+
return hits();
|
|
1302
|
+
},
|
|
1303
|
+
children: (item: MemoryHit, idx: () => number) => {
|
|
1304
|
+
const isSelected = () => selectedIndex() === idx();
|
|
1305
|
+
return el(
|
|
903
1306
|
"box",
|
|
904
1307
|
{
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1308
|
+
id: () => `memory-row-${idx()}`,
|
|
1309
|
+
flexDirection: "column",
|
|
1310
|
+
paddingX: 1,
|
|
1311
|
+
paddingY: 0,
|
|
1312
|
+
marginBottom: 1,
|
|
1313
|
+
flexShrink: 0,
|
|
1314
|
+
backgroundColor: () =>
|
|
1315
|
+
isSelected()
|
|
1316
|
+
? theme().background.action.primary.focused
|
|
1317
|
+
: undefined,
|
|
1318
|
+
onMouseUp: () => setSelectedIndex(idx()),
|
|
1319
|
+
onMouseOver: () => setSelectedIndex(idx()),
|
|
908
1320
|
},
|
|
909
1321
|
el(
|
|
910
|
-
"
|
|
1322
|
+
"box",
|
|
911
1323
|
{
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
? theme().text.action.primary.focused
|
|
916
|
-
: theme().text.base,
|
|
917
|
-
attributes: () =>
|
|
918
|
-
isSelected() ? TextAttributes.BOLD : undefined,
|
|
1324
|
+
flexDirection: "row",
|
|
1325
|
+
justifyContent: "space-between",
|
|
1326
|
+
width: "100%",
|
|
919
1327
|
},
|
|
920
|
-
(
|
|
1328
|
+
el(
|
|
1329
|
+
"text",
|
|
1330
|
+
{
|
|
1331
|
+
wrapMode: "none",
|
|
1332
|
+
truncate: true,
|
|
1333
|
+
fg: () =>
|
|
1334
|
+
isSelected()
|
|
1335
|
+
? theme().text.action.primary.focused
|
|
1336
|
+
: theme().text.base,
|
|
1337
|
+
attributes: () =>
|
|
1338
|
+
isSelected() ? TextAttributes.BOLD : undefined,
|
|
1339
|
+
},
|
|
1340
|
+
() =>
|
|
1341
|
+
`${isSelected() ? "▸ " : " "}${item.entry.core ? "★ " : ""}[${item.entry.id}]`
|
|
1342
|
+
),
|
|
1343
|
+
el(
|
|
1344
|
+
"text",
|
|
1345
|
+
{
|
|
1346
|
+
wrapMode: "none",
|
|
1347
|
+
fg: () =>
|
|
1348
|
+
isSelected()
|
|
1349
|
+
? theme().text.action.primary.focused
|
|
1350
|
+
: theme().text.action.primary.base,
|
|
1351
|
+
},
|
|
1352
|
+
() =>
|
|
1353
|
+
query().trim()
|
|
1354
|
+
? `${item.score.toFixed(2)} · ${item.entry.file.replace(/\.md$/, "")}`
|
|
1355
|
+
: item.entry.file.replace(/\.md$/, "")
|
|
1356
|
+
)
|
|
921
1357
|
),
|
|
922
1358
|
el(
|
|
923
1359
|
"text",
|
|
924
1360
|
{
|
|
925
1361
|
wrapMode: "none",
|
|
1362
|
+
truncate: true,
|
|
926
1363
|
fg: () =>
|
|
927
1364
|
isSelected()
|
|
928
1365
|
? theme().text.action.primary.focused
|
|
929
1366
|
: theme().text.muted,
|
|
930
1367
|
},
|
|
931
|
-
() =>
|
|
932
|
-
query().trim()
|
|
933
|
-
? `${item.score.toFixed(2)} · ${item.entry.file.replace(/\.md$/, "")}`
|
|
934
|
-
: item.entry.file.replace(/\.md$/, "")
|
|
1368
|
+
() => ` ${item.entry.fact.slice(0, 56)}`
|
|
935
1369
|
)
|
|
936
|
-
)
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
isSelected()
|
|
943
|
-
? theme().text.action.primary.focused
|
|
944
|
-
: theme().text.muted,
|
|
945
|
-
},
|
|
946
|
-
() => ` ${item.entry.fact.slice(0, 56)}`
|
|
947
|
-
)
|
|
948
|
-
);
|
|
949
|
-
},
|
|
950
|
-
});
|
|
951
|
-
},
|
|
952
|
-
})
|
|
1370
|
+
);
|
|
1371
|
+
},
|
|
1372
|
+
});
|
|
1373
|
+
},
|
|
1374
|
+
})
|
|
1375
|
+
)
|
|
953
1376
|
),
|
|
954
1377
|
|
|
955
|
-
// Right: Full Memory Entry Preview (56%)
|
|
1378
|
+
// Right Card: Full Memory Entry Preview or Inline Editor (56%)
|
|
956
1379
|
el(
|
|
957
|
-
"
|
|
1380
|
+
"box",
|
|
958
1381
|
{
|
|
959
|
-
id: "local-memory-preview",
|
|
960
|
-
ref: (r: unknown) => {
|
|
961
|
-
previewScrollRef = r;
|
|
962
|
-
},
|
|
963
1382
|
flexGrow: 1,
|
|
1383
|
+
height: "100%",
|
|
964
1384
|
minWidth: 0,
|
|
965
1385
|
minHeight: 0,
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1386
|
+
flexDirection: "column",
|
|
1387
|
+
backgroundColor: () =>
|
|
1388
|
+
theme().background.raised?.base ?? theme().background.base,
|
|
1389
|
+
border: true,
|
|
1390
|
+
borderColor: () =>
|
|
1391
|
+
editorMode() || focusPane() === "preview"
|
|
1392
|
+
? theme().text.action.primary.base
|
|
1393
|
+
: theme().border.base,
|
|
1394
|
+
paddingLeft: 2,
|
|
1395
|
+
paddingRight: 2,
|
|
1396
|
+
paddingTop: 0,
|
|
1397
|
+
paddingBottom: 1,
|
|
969
1398
|
onMouseDown: () => setFocusPane("preview"),
|
|
970
1399
|
},
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1400
|
+
el(
|
|
1401
|
+
"box",
|
|
1402
|
+
{
|
|
1403
|
+
flexDirection: "row",
|
|
1404
|
+
justifyContent: "space-between",
|
|
1405
|
+
border: ["bottom"],
|
|
1406
|
+
borderColor: () => theme().border.base,
|
|
1407
|
+
marginBottom: 1,
|
|
1408
|
+
flexShrink: 0,
|
|
974
1409
|
},
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1410
|
+
el(
|
|
1411
|
+
"text",
|
|
1412
|
+
{
|
|
1413
|
+
fg: () => theme().text.action.primary.base,
|
|
1414
|
+
attributes: TextAttributes.BOLD,
|
|
1415
|
+
},
|
|
1416
|
+
() =>
|
|
1417
|
+
editorMode() === "add"
|
|
1418
|
+
? "◈ ADD NEW MEMORY FACT"
|
|
1419
|
+
: editorMode() === "edit"
|
|
1420
|
+
? `◈ EDIT MEMORY [${editId()}]`
|
|
1421
|
+
: "◈ ENTRY PREVIEW"
|
|
1422
|
+
),
|
|
1423
|
+
el(
|
|
1424
|
+
"text",
|
|
1425
|
+
{ fg: () => theme().text.muted },
|
|
1426
|
+
() =>
|
|
1427
|
+
editorMode()
|
|
1428
|
+
? "[Tab] next field · [^S/Enter] save · [Esc] cancel"
|
|
1429
|
+
: selectedHit()
|
|
1430
|
+
? `${selectedHit()?.entry.file ?? ""} · score ${selectedHit()?.score.toFixed(3) ?? ""}`
|
|
1431
|
+
: "no selection"
|
|
1432
|
+
)
|
|
1433
|
+
),
|
|
1434
|
+
el(
|
|
1435
|
+
"scrollbox",
|
|
1436
|
+
{
|
|
1437
|
+
id: "local-memory-preview",
|
|
1438
|
+
ref: (r: unknown) => {
|
|
1439
|
+
previewScrollRef = r;
|
|
1440
|
+
},
|
|
1441
|
+
flexGrow: 1,
|
|
1442
|
+
minWidth: 0,
|
|
1443
|
+
minHeight: 0,
|
|
1444
|
+
focused: () => !editorMode() && focusPane() === "preview",
|
|
981
1445
|
},
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
{
|
|
989
|
-
fg: () => theme().text.base,
|
|
990
|
-
attributes: TextAttributes.BOLD,
|
|
991
|
-
},
|
|
992
|
-
() => `[${selectedHit()?.entry.id ?? ""}]`
|
|
993
|
-
),
|
|
994
|
-
el(
|
|
995
|
-
"text",
|
|
996
|
-
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
997
|
-
() => {
|
|
998
|
-
const h = selectedHit();
|
|
999
|
-
if (!h) return "";
|
|
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)}`;
|
|
1003
|
-
}
|
|
1004
|
-
),
|
|
1005
|
-
el(
|
|
1006
|
-
"text",
|
|
1007
|
-
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1008
|
-
() => `Tags: [${selectedHit()?.entry.tags ?? ""}]`
|
|
1009
|
-
),
|
|
1010
|
-
el(
|
|
1011
|
-
"box",
|
|
1012
|
-
{
|
|
1013
|
-
flexDirection: "row",
|
|
1014
|
-
flexWrap: "wrap",
|
|
1015
|
-
marginTop: 1,
|
|
1016
|
-
},
|
|
1017
|
-
createComponent(For, {
|
|
1018
|
-
get each() {
|
|
1019
|
-
return splitHighlightedText(
|
|
1020
|
-
selectedHit()?.entry.fact ?? "",
|
|
1021
|
-
query()
|
|
1022
|
-
);
|
|
1023
|
-
},
|
|
1024
|
-
children: (seg: { text: string; match: boolean }) =>
|
|
1025
|
-
el(
|
|
1026
|
-
"text",
|
|
1027
|
-
{
|
|
1028
|
-
fg: () =>
|
|
1029
|
-
seg.match
|
|
1030
|
-
? theme().text.action.primary.base
|
|
1031
|
-
: theme().text.base,
|
|
1032
|
-
attributes: () =>
|
|
1033
|
-
seg.match ? TextAttributes.BOLD : undefined,
|
|
1034
|
-
},
|
|
1035
|
-
seg.text
|
|
1036
|
-
),
|
|
1037
|
-
})
|
|
1038
|
-
),
|
|
1039
|
-
createComponent(Show, {
|
|
1446
|
+
createComponent(Show, {
|
|
1447
|
+
get when() {
|
|
1448
|
+
return Boolean(editorMode());
|
|
1449
|
+
},
|
|
1450
|
+
get fallback() {
|
|
1451
|
+
return createComponent(Show, {
|
|
1040
1452
|
get when() {
|
|
1041
|
-
return
|
|
1453
|
+
return selectedHit();
|
|
1454
|
+
},
|
|
1455
|
+
get fallback() {
|
|
1456
|
+
return el(
|
|
1457
|
+
"text",
|
|
1458
|
+
{ fg: () => theme().text.muted },
|
|
1459
|
+
"Select a memory entry on the left to inspect it, or press ^N to add a new memory fact."
|
|
1460
|
+
);
|
|
1042
1461
|
},
|
|
1043
1462
|
get children() {
|
|
1044
1463
|
return el(
|
|
1045
1464
|
"box",
|
|
1046
|
-
{
|
|
1047
|
-
flexDirection: "column",
|
|
1048
|
-
marginTop: 1,
|
|
1049
|
-
paddingTop: 1,
|
|
1050
|
-
border: ["top"],
|
|
1051
|
-
borderColor: () => theme().border.base,
|
|
1052
|
-
},
|
|
1465
|
+
{ flexDirection: "column", gap: 1 },
|
|
1053
1466
|
el(
|
|
1054
|
-
"
|
|
1467
|
+
"box",
|
|
1055
1468
|
{
|
|
1056
|
-
|
|
1057
|
-
|
|
1469
|
+
flexDirection: "column",
|
|
1470
|
+
paddingLeft: 1,
|
|
1471
|
+
border: ["left"],
|
|
1472
|
+
borderColor: () => theme().text.action.primary.base,
|
|
1058
1473
|
},
|
|
1059
|
-
|
|
1474
|
+
el(
|
|
1475
|
+
"text",
|
|
1476
|
+
{
|
|
1477
|
+
fg: () => theme().text.base,
|
|
1478
|
+
attributes: TextAttributes.BOLD,
|
|
1479
|
+
},
|
|
1480
|
+
() =>
|
|
1481
|
+
`${selectedHit()?.entry.core ? "★ " : ""}[${selectedHit()?.entry.id ?? ""}]`
|
|
1482
|
+
),
|
|
1483
|
+
el(
|
|
1484
|
+
"text",
|
|
1485
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1486
|
+
() => {
|
|
1487
|
+
const h = selectedHit();
|
|
1488
|
+
if (!h) return "";
|
|
1489
|
+
const scope = h.entry.project || "global";
|
|
1490
|
+
const coreLabel = h.entry.core ? " · Core: pinned" : "";
|
|
1491
|
+
return `File: ${h.entry.file} · Date: ${h.entry.date || "N/A"} · Scope: ${scope}${coreLabel}`;
|
|
1492
|
+
}
|
|
1493
|
+
),
|
|
1494
|
+
el(
|
|
1495
|
+
"text",
|
|
1496
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1497
|
+
() => `Tags: [${selectedHit()?.entry.tags ?? ""}]`
|
|
1498
|
+
)
|
|
1060
1499
|
),
|
|
1061
1500
|
el(
|
|
1062
|
-
"
|
|
1063
|
-
{
|
|
1064
|
-
|
|
1065
|
-
|
|
1501
|
+
"box",
|
|
1502
|
+
{
|
|
1503
|
+
flexDirection: "row",
|
|
1504
|
+
flexWrap: "wrap",
|
|
1505
|
+
marginTop: 1,
|
|
1506
|
+
},
|
|
1507
|
+
createComponent(For, {
|
|
1508
|
+
get each() {
|
|
1509
|
+
return splitHighlightedText(
|
|
1510
|
+
selectedHit()?.entry.fact ?? "",
|
|
1511
|
+
query()
|
|
1512
|
+
);
|
|
1513
|
+
},
|
|
1514
|
+
children: (seg: { text: string; match: boolean }) =>
|
|
1515
|
+
el(
|
|
1516
|
+
"text",
|
|
1517
|
+
{
|
|
1518
|
+
fg: () =>
|
|
1519
|
+
seg.match
|
|
1520
|
+
? theme().text.action.primary.base
|
|
1521
|
+
: theme().text.base,
|
|
1522
|
+
attributes: () =>
|
|
1523
|
+
seg.match ? TextAttributes.BOLD : undefined,
|
|
1524
|
+
},
|
|
1525
|
+
seg.text
|
|
1526
|
+
),
|
|
1527
|
+
})
|
|
1528
|
+
),
|
|
1529
|
+
createComponent(Show, {
|
|
1530
|
+
get when() {
|
|
1531
|
+
return Boolean(selectedSessionBody());
|
|
1532
|
+
},
|
|
1533
|
+
get children() {
|
|
1534
|
+
return el(
|
|
1535
|
+
"box",
|
|
1536
|
+
{
|
|
1537
|
+
flexDirection: "column",
|
|
1538
|
+
marginTop: 1,
|
|
1539
|
+
paddingTop: 1,
|
|
1540
|
+
border: ["top"],
|
|
1541
|
+
borderColor: () => theme().border.base,
|
|
1542
|
+
},
|
|
1543
|
+
el(
|
|
1544
|
+
"text",
|
|
1545
|
+
{
|
|
1546
|
+
fg: () => theme().text.action.primary.base,
|
|
1547
|
+
attributes: TextAttributes.BOLD,
|
|
1548
|
+
},
|
|
1549
|
+
"◈ FULL SESSION CHECKPOINT MARKDOWN"
|
|
1550
|
+
),
|
|
1551
|
+
el(
|
|
1552
|
+
"text",
|
|
1553
|
+
{ fg: () => theme().text.muted, wrapMode: "word" },
|
|
1554
|
+
() => selectedSessionBody()
|
|
1555
|
+
)
|
|
1556
|
+
);
|
|
1557
|
+
},
|
|
1558
|
+
})
|
|
1066
1559
|
);
|
|
1067
1560
|
},
|
|
1068
|
-
})
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1561
|
+
});
|
|
1562
|
+
},
|
|
1563
|
+
get children() {
|
|
1564
|
+
return el(
|
|
1565
|
+
"box",
|
|
1566
|
+
{ flexDirection: "column", gap: 1, width: "100%" },
|
|
1567
|
+
// Topic field
|
|
1568
|
+
el(
|
|
1569
|
+
"box",
|
|
1570
|
+
{
|
|
1571
|
+
flexDirection: "row",
|
|
1572
|
+
alignItems: "center",
|
|
1573
|
+
gap: 1,
|
|
1574
|
+
width: "100%",
|
|
1575
|
+
onMouseDown: () => setEditorField("topic"),
|
|
1576
|
+
},
|
|
1577
|
+
el(
|
|
1578
|
+
"text",
|
|
1579
|
+
{
|
|
1580
|
+
width: 10,
|
|
1581
|
+
flexShrink: 0,
|
|
1582
|
+
fg: () =>
|
|
1583
|
+
editorField() === "topic"
|
|
1584
|
+
? theme().text.action.primary.base
|
|
1585
|
+
: theme().text.muted,
|
|
1586
|
+
attributes: () =>
|
|
1587
|
+
editorField() === "topic" ? TextAttributes.BOLD : undefined,
|
|
1588
|
+
},
|
|
1589
|
+
"Topic:"
|
|
1590
|
+
),
|
|
1591
|
+
el(
|
|
1592
|
+
"box",
|
|
1593
|
+
{ flexGrow: 1, minWidth: 0 },
|
|
1594
|
+
el("input", {
|
|
1595
|
+
id: "local-memory-edit-topic",
|
|
1596
|
+
width: "100%",
|
|
1597
|
+
value: () => editTopic(),
|
|
1598
|
+
focused: () => editorMode() !== null && editorField() === "topic",
|
|
1599
|
+
placeholder: "preferences, decisions, environment, tools...",
|
|
1600
|
+
placeholderColor: () => theme().text.muted,
|
|
1601
|
+
textColor: () => theme().text.base,
|
|
1602
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
1603
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
1604
|
+
onInput: (v: string) => setEditTopic(v),
|
|
1605
|
+
})
|
|
1606
|
+
)
|
|
1607
|
+
),
|
|
1608
|
+
// Tags field
|
|
1609
|
+
el(
|
|
1610
|
+
"box",
|
|
1611
|
+
{
|
|
1612
|
+
flexDirection: "row",
|
|
1613
|
+
alignItems: "center",
|
|
1614
|
+
gap: 1,
|
|
1615
|
+
width: "100%",
|
|
1616
|
+
onMouseDown: () => setEditorField("tags"),
|
|
1617
|
+
},
|
|
1618
|
+
el(
|
|
1619
|
+
"text",
|
|
1620
|
+
{
|
|
1621
|
+
width: 10,
|
|
1622
|
+
flexShrink: 0,
|
|
1623
|
+
fg: () =>
|
|
1624
|
+
editorField() === "tags"
|
|
1625
|
+
? theme().text.action.primary.base
|
|
1626
|
+
: theme().text.muted,
|
|
1627
|
+
attributes: () =>
|
|
1628
|
+
editorField() === "tags" ? TextAttributes.BOLD : undefined,
|
|
1629
|
+
},
|
|
1630
|
+
"Tags:"
|
|
1631
|
+
),
|
|
1632
|
+
el(
|
|
1633
|
+
"box",
|
|
1634
|
+
{ flexGrow: 1, minWidth: 0 },
|
|
1635
|
+
el("input", {
|
|
1636
|
+
id: "local-memory-edit-tags",
|
|
1637
|
+
width: "100%",
|
|
1638
|
+
value: () => editTags(),
|
|
1639
|
+
focused: () => editorMode() !== null && editorField() === "tags",
|
|
1640
|
+
placeholder: "comma-separated keywords...",
|
|
1641
|
+
placeholderColor: () => theme().text.muted,
|
|
1642
|
+
textColor: () => theme().text.base,
|
|
1643
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
1644
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
1645
|
+
onInput: (v: string) => setEditTags(v),
|
|
1646
|
+
})
|
|
1647
|
+
)
|
|
1648
|
+
),
|
|
1649
|
+
// Project field
|
|
1650
|
+
el(
|
|
1651
|
+
"box",
|
|
1652
|
+
{
|
|
1653
|
+
flexDirection: "row",
|
|
1654
|
+
alignItems: "center",
|
|
1655
|
+
gap: 1,
|
|
1656
|
+
width: "100%",
|
|
1657
|
+
onMouseDown: () => setEditorField("project"),
|
|
1658
|
+
},
|
|
1659
|
+
el(
|
|
1660
|
+
"text",
|
|
1661
|
+
{
|
|
1662
|
+
width: 10,
|
|
1663
|
+
flexShrink: 0,
|
|
1664
|
+
fg: () =>
|
|
1665
|
+
editorField() === "project"
|
|
1666
|
+
? theme().text.action.primary.base
|
|
1667
|
+
: theme().text.muted,
|
|
1668
|
+
attributes: () =>
|
|
1669
|
+
editorField() === "project" ? TextAttributes.BOLD : undefined,
|
|
1670
|
+
},
|
|
1671
|
+
"Project:"
|
|
1672
|
+
),
|
|
1673
|
+
el(
|
|
1674
|
+
"box",
|
|
1675
|
+
{ flexGrow: 1, minWidth: 0 },
|
|
1676
|
+
el("input", {
|
|
1677
|
+
id: "local-memory-edit-project",
|
|
1678
|
+
width: "100%",
|
|
1679
|
+
value: () => editProject(),
|
|
1680
|
+
focused: () => editorMode() !== null && editorField() === "project",
|
|
1681
|
+
placeholder: "global (or cms/<client>, git/<repo>)...",
|
|
1682
|
+
placeholderColor: () => theme().text.muted,
|
|
1683
|
+
textColor: () => theme().text.base,
|
|
1684
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
1685
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
1686
|
+
onInput: (v: string) => setEditProject(v),
|
|
1687
|
+
})
|
|
1688
|
+
)
|
|
1689
|
+
),
|
|
1690
|
+
// Core pin toggle
|
|
1691
|
+
el(
|
|
1692
|
+
"box",
|
|
1693
|
+
{
|
|
1694
|
+
flexDirection: "row",
|
|
1695
|
+
alignItems: "center",
|
|
1696
|
+
gap: 1,
|
|
1697
|
+
width: "100%",
|
|
1698
|
+
onMouseUp: () => {
|
|
1699
|
+
setEditorField("core");
|
|
1700
|
+
setEditCore((v) => !v);
|
|
1701
|
+
},
|
|
1702
|
+
},
|
|
1703
|
+
el(
|
|
1704
|
+
"text",
|
|
1705
|
+
{
|
|
1706
|
+
width: 10,
|
|
1707
|
+
flexShrink: 0,
|
|
1708
|
+
fg: () =>
|
|
1709
|
+
editorField() === "core"
|
|
1710
|
+
? theme().text.action.primary.base
|
|
1711
|
+
: theme().text.muted,
|
|
1712
|
+
attributes: () =>
|
|
1713
|
+
editorField() === "core" ? TextAttributes.BOLD : undefined,
|
|
1714
|
+
},
|
|
1715
|
+
"Core Pin:"
|
|
1716
|
+
),
|
|
1717
|
+
el(
|
|
1718
|
+
"text",
|
|
1719
|
+
{
|
|
1720
|
+
fg: () =>
|
|
1721
|
+
editCore()
|
|
1722
|
+
? theme().text.action.primary.base
|
|
1723
|
+
: theme().text.muted,
|
|
1724
|
+
attributes: () => (editCore() ? TextAttributes.BOLD : undefined),
|
|
1725
|
+
},
|
|
1726
|
+
() =>
|
|
1727
|
+
editCore()
|
|
1728
|
+
? "[★ Pinned — injected on every turn] (click or Space to toggle)"
|
|
1729
|
+
: "[ Unpinned — recalled by relevance] (click or Space to toggle)"
|
|
1730
|
+
)
|
|
1731
|
+
),
|
|
1732
|
+
// Fact field
|
|
1733
|
+
el(
|
|
1734
|
+
"box",
|
|
1735
|
+
{
|
|
1736
|
+
flexDirection: "column",
|
|
1737
|
+
gap: 0,
|
|
1738
|
+
width: "100%",
|
|
1739
|
+
marginTop: 1,
|
|
1740
|
+
onMouseDown: () => setEditorField("fact"),
|
|
1741
|
+
},
|
|
1742
|
+
el(
|
|
1743
|
+
"text",
|
|
1744
|
+
{
|
|
1745
|
+
fg: () =>
|
|
1746
|
+
editorField() === "fact"
|
|
1747
|
+
? theme().text.action.primary.base
|
|
1748
|
+
: theme().text.muted,
|
|
1749
|
+
attributes: () =>
|
|
1750
|
+
editorField() === "fact" ? TextAttributes.BOLD : undefined,
|
|
1751
|
+
},
|
|
1752
|
+
"Fact (one-line statement):"
|
|
1753
|
+
),
|
|
1754
|
+
el(
|
|
1755
|
+
"box",
|
|
1756
|
+
{
|
|
1757
|
+
width: "100%",
|
|
1758
|
+
border: true,
|
|
1759
|
+
borderColor: () =>
|
|
1760
|
+
editorField() === "fact"
|
|
1761
|
+
? theme().text.action.primary.base
|
|
1762
|
+
: theme().border.base,
|
|
1763
|
+
paddingX: 1,
|
|
1764
|
+
},
|
|
1765
|
+
el("input", {
|
|
1766
|
+
id: "local-memory-edit-fact",
|
|
1767
|
+
width: "100%",
|
|
1768
|
+
value: () => editFact(),
|
|
1769
|
+
focused: () => editorMode() !== null && editorField() === "fact",
|
|
1770
|
+
maxLength: Number.POSITIVE_INFINITY,
|
|
1771
|
+
placeholder: "Write the fact, rule, preference, or decision...",
|
|
1772
|
+
placeholderColor: () => theme().text.muted,
|
|
1773
|
+
textColor: () => theme().text.base,
|
|
1774
|
+
focusedTextColor: () => theme().text.formfield.focused,
|
|
1775
|
+
cursorColor: () => theme().text.formfield.focused,
|
|
1776
|
+
onInput: (v: string) => setEditFact(v),
|
|
1777
|
+
})
|
|
1778
|
+
)
|
|
1779
|
+
),
|
|
1780
|
+
// Action pills inside editor
|
|
1781
|
+
el(
|
|
1782
|
+
"box",
|
|
1783
|
+
{ flexDirection: "row", gap: 1, marginTop: 1 },
|
|
1784
|
+
Pill({
|
|
1785
|
+
label: () => (editorMode() === "edit" ? "save changes" : "store memory"),
|
|
1786
|
+
shortcut: "^s / Enter",
|
|
1787
|
+
active: () => true,
|
|
1788
|
+
onClick: () => void saveEditor(),
|
|
1789
|
+
}),
|
|
1790
|
+
Pill({
|
|
1791
|
+
label: () => "cancel",
|
|
1792
|
+
shortcut: "Esc",
|
|
1793
|
+
active: () => false,
|
|
1794
|
+
onClick: cancelEditor,
|
|
1795
|
+
})
|
|
1796
|
+
)
|
|
1797
|
+
);
|
|
1798
|
+
},
|
|
1799
|
+
})
|
|
1800
|
+
)
|
|
1096
1801
|
)
|
|
1097
1802
|
)
|
|
1098
1803
|
);
|