@nandoblanco/opencode-local-memory 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
- return subset
360
- .slice()
361
- .reverse()
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 && (name === "n" || name === "j")) ||
610
- (focusPane() !== "input" && !event.ctrl && name === "j")
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 && (name === "p" || name === "k")) ||
624
- (focusPane() !== "input" && !event.ctrl && name === "k")
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 === "d")) {
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 {
@@ -768,7 +1069,7 @@ function createTuiRenderer() {
768
1069
  flexShrink: 0,
769
1070
  fg: () => theme().text.muted,
770
1071
  },
771
- "[↑↓] select [Tab] pane [^D] delete [Esc] close"
1072
+ "[↑↓] select [^N] add [^E] edit [^P] pin [^D] delete [Esc] close"
772
1073
  )
773
1074
  ),
774
1075
 
@@ -823,7 +1124,7 @@ function createTuiRenderer() {
823
1124
  id: "local-memory-search-input",
824
1125
  width: "100%",
825
1126
  value: () => query(),
826
- focused: () => focusPane() === "search",
1127
+ focused: () => !editorMode() && focusPane() === "search",
827
1128
  maxLength: Number.POSITIVE_INFINITY,
828
1129
  placeholder:
829
1130
  "Search memories (semantic + keyword, topic:name, project:slug, /regex/i)...",
@@ -835,7 +1136,10 @@ function createTuiRenderer() {
835
1136
  theme().background.raised?.base ?? theme().background.base,
836
1137
  focusedBackgroundColor: () =>
837
1138
  theme().background.raised?.base ?? theme().background.base,
838
- onMouseDown: () => setFocusPane("search"),
1139
+ onMouseDown: () => {
1140
+ setEditorMode(null);
1141
+ setFocusPane("search");
1142
+ },
839
1143
  onInput: (val: string) => setQuery(val),
840
1144
  })
841
1145
  ),
@@ -845,8 +1149,10 @@ function createTuiRenderer() {
845
1149
  wrapMode: "none",
846
1150
  flexShrink: 0,
847
1151
  fg: () =>
848
- theme().text.feedback?.success?.base ??
849
- theme().text.action.primary.base,
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,
850
1156
  },
851
1157
  () =>
852
1158
  statusMsg() ||
@@ -874,6 +1180,30 @@ function createTuiRenderer() {
874
1180
  active: () => mode() !== "hybrid",
875
1181
  onClick: cycleMode,
876
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
+ }),
877
1207
  Pill({
878
1208
  label: () => "import",
879
1209
  shortcut: "^b",
@@ -1007,7 +1337,8 @@ function createTuiRenderer() {
1007
1337
  attributes: () =>
1008
1338
  isSelected() ? TextAttributes.BOLD : undefined,
1009
1339
  },
1010
- () => `${isSelected() ? "▸ " : " "}[${item.entry.id}]`
1340
+ () =>
1341
+ `${isSelected() ? "▸ " : " "}${item.entry.core ? "★ " : ""}[${item.entry.id}]`
1011
1342
  ),
1012
1343
  el(
1013
1344
  "text",
@@ -1044,7 +1375,7 @@ function createTuiRenderer() {
1044
1375
  )
1045
1376
  ),
1046
1377
 
1047
- // Right Card: Full Memory Entry Preview (56%)
1378
+ // Right Card: Full Memory Entry Preview or Inline Editor (56%)
1048
1379
  el(
1049
1380
  "box",
1050
1381
  {
@@ -1057,7 +1388,7 @@ function createTuiRenderer() {
1057
1388
  theme().background.raised?.base ?? theme().background.base,
1058
1389
  border: true,
1059
1390
  borderColor: () =>
1060
- focusPane() === "preview"
1391
+ editorMode() || focusPane() === "preview"
1061
1392
  ? theme().text.action.primary.base
1062
1393
  : theme().border.base,
1063
1394
  paddingLeft: 2,
@@ -1082,15 +1413,22 @@ function createTuiRenderer() {
1082
1413
  fg: () => theme().text.action.primary.base,
1083
1414
  attributes: TextAttributes.BOLD,
1084
1415
  },
1085
- "◈ ENTRY PREVIEW"
1416
+ () =>
1417
+ editorMode() === "add"
1418
+ ? "◈ ADD NEW MEMORY FACT"
1419
+ : editorMode() === "edit"
1420
+ ? `◈ EDIT MEMORY [${editId()}]`
1421
+ : "◈ ENTRY PREVIEW"
1086
1422
  ),
1087
1423
  el(
1088
1424
  "text",
1089
1425
  { fg: () => theme().text.muted },
1090
1426
  () =>
1091
- selectedHit()
1092
- ? `${selectedHit()?.entry.file ?? ""} · score ${selectedHit()?.score.toFixed(3) ?? ""}`
1093
- : "no selection"
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"
1094
1432
  )
1095
1433
  ),
1096
1434
  el(
@@ -1103,115 +1441,359 @@ function createTuiRenderer() {
1103
1441
  flexGrow: 1,
1104
1442
  minWidth: 0,
1105
1443
  minHeight: 0,
1106
- focused: () => focusPane() === "preview",
1444
+ focused: () => !editorMode() && focusPane() === "preview",
1107
1445
  },
1108
1446
  createComponent(Show, {
1109
1447
  get when() {
1110
- return selectedHit();
1448
+ return Boolean(editorMode());
1111
1449
  },
1112
1450
  get fallback() {
1113
- return el(
1114
- "text",
1115
- { fg: () => theme().text.muted },
1116
- "Select a memory entry on the left to inspect it."
1117
- );
1451
+ return createComponent(Show, {
1452
+ get when() {
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
+ );
1461
+ },
1462
+ get children() {
1463
+ return el(
1464
+ "box",
1465
+ { flexDirection: "column", gap: 1 },
1466
+ el(
1467
+ "box",
1468
+ {
1469
+ flexDirection: "column",
1470
+ paddingLeft: 1,
1471
+ border: ["left"],
1472
+ borderColor: () => theme().text.action.primary.base,
1473
+ },
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
+ )
1499
+ ),
1500
+ el(
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
+ })
1559
+ );
1560
+ },
1561
+ });
1118
1562
  },
1119
1563
  get children() {
1120
1564
  return el(
1121
1565
  "box",
1122
- { flexDirection: "column", gap: 1 },
1566
+ { flexDirection: "column", gap: 1, width: "100%" },
1567
+ // Topic field
1123
1568
  el(
1124
1569
  "box",
1125
1570
  {
1126
- flexDirection: "column",
1127
- paddingLeft: 1,
1128
- border: ["left"],
1129
- borderColor: () => theme().text.action.primary.base,
1571
+ flexDirection: "row",
1572
+ alignItems: "center",
1573
+ gap: 1,
1574
+ width: "100%",
1575
+ onMouseDown: () => setEditorField("topic"),
1130
1576
  },
1131
1577
  el(
1132
1578
  "text",
1133
1579
  {
1134
- fg: () => theme().text.base,
1135
- attributes: TextAttributes.BOLD,
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,
1136
1588
  },
1137
- () => `[${selectedHit()?.entry.id ?? ""}]`
1589
+ "Topic:"
1138
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
+ },
1139
1618
  el(
1140
1619
  "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
- }
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:"
1149
1631
  ),
1150
1632
  el(
1151
- "text",
1152
- { fg: () => theme().text.muted, wrapMode: "word" },
1153
- () => `Tags: [${selectedHit()?.entry.tags ?? ""}]`
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
+ })
1154
1647
  )
1155
1648
  ),
1649
+ // Project field
1156
1650
  el(
1157
1651
  "box",
1158
1652
  {
1159
1653
  flexDirection: "row",
1160
- flexWrap: "wrap",
1161
- marginTop: 1,
1654
+ alignItems: "center",
1655
+ gap: 1,
1656
+ width: "100%",
1657
+ onMouseDown: () => setEditorField("project"),
1162
1658
  },
1163
- createComponent(For, {
1164
- get each() {
1165
- return splitHighlightedText(
1166
- selectedHit()?.entry.fact ?? "",
1167
- query()
1168
- );
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,
1169
1670
  },
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
- })
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
+ )
1184
1689
  ),
1185
- createComponent(Show, {
1186
- get when() {
1187
- return Boolean(selectedSessionBody());
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
+ },
1188
1702
  },
1189
- get children() {
1190
- return el(
1191
- "box",
1192
- {
1193
- flexDirection: "column",
1194
- marginTop: 1,
1195
- paddingTop: 1,
1196
- border: ["top"],
1197
- borderColor: () => theme().border.base,
1198
- },
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
- );
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"),
1213
1741
  },
1214
- })
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
+ )
1215
1797
  );
1216
1798
  },
1217
1799
  })