@aeondave/pi-persona-mind 0.9.5 → 0.9.7

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.
@@ -7,8 +7,8 @@ import { MAX_SESSION_NOTES, SESSION_NOTE_ENTRY_TYPE, replaySessionNotes, session
7
7
 
8
8
  export type SessionStorage = "session" | "memory";
9
9
  export interface SessionFailure { ok: false; reason: string }
10
- export type SessionWriteResult = SessionFailure | { ok: true; storage: SessionStorage; entry: SessionNote };
11
- export type SessionReadResult = SessionWriteResult;
10
+ export type SessionReadResult = SessionFailure | { ok: true; storage: SessionStorage; entry: SessionNote };
11
+ export type SessionWriteResult = SessionFailure | { ok: true; storage: SessionStorage; entry: SessionNote; created: boolean };
12
12
  export type SessionForgetResult = SessionFailure | { ok: true; storage: SessionStorage; removed: number };
13
13
  export interface SessionSnapshot { ok: boolean; notes: SessionNote[]; storage: SessionStorage; reason?: string }
14
14
  export interface SessionRecallResult { ok: boolean; storage: SessionStorage; reason?: string; hits: SessionNote[]; total: number; withheld: number; max: number }
@@ -17,7 +17,7 @@ export interface SessionMemory {
17
17
  deactivate(): void;
18
18
  isCurrent(ctx: ExtensionContext): boolean;
19
19
  captureOwner(ctx: ExtensionContext): () => boolean;
20
- remember(ctx: ExtensionContext, input: SessionNoteInput): SessionWriteResult;
20
+ remember(ctx: ExtensionContext, input: SessionNoteInput, options?: { reuseIdentical?: boolean }): SessionWriteResult;
21
21
  recall(ctx: ExtensionContext, opts: { query?: string; max?: number }): SessionRecallResult;
22
22
  read(ctx: ExtensionContext, id: string): SessionReadResult;
23
23
  forget(ctx: ExtensionContext, id: string): SessionForgetResult;
@@ -42,12 +42,10 @@ export function createSessionMemory(pi: Pick<ExtensionAPI, "appendEntry">): Sess
42
42
  try { return { owner: selected, replay: replaySessionNotes(noteData(selected.manager.getBranch()), noteData(selected.manager.getEntries())) }; }
43
43
  catch { return undefined; }
44
44
  }
45
- function append(ctx: ExtensionContext, event: SessionNoteEvent): SessionFailure | { ok: true; storage: SessionStorage } {
46
- const selected = state(ctx);
47
- if (!selected) return failure("session note owner is unavailable");
48
- if (selected.replay.error) return failure(selected.replay.error);
45
+ function append(ctx: ExtensionContext, selected: NonNullable<ReturnType<typeof state>>, event: SessionNoteEvent): SessionFailure | { ok: true; storage: SessionStorage } {
49
46
  if (!sessionEventFits(selected.replay, event)) return failure("session note lifetime budget is full");
50
47
  // No await separates owner validation and host append. Failed appends never mutate a cache.
48
+ if (current(ctx) !== selected.owner) return failure("session note owner is unavailable");
51
49
  try { pi.appendEntry(SESSION_NOTE_ENTRY_TYPE, event); }
52
50
  catch { return failure("host rejected the session note append"); }
53
51
  return { ok: true, storage: selected.owner.file ? "session" : "memory" };
@@ -61,16 +59,21 @@ export function createSessionMemory(pi: Pick<ExtensionAPI, "appendEntry">): Sess
61
59
  deactivate() { owner = undefined; },
62
60
  isCurrent(ctx) { return current(ctx) !== undefined; },
63
61
  captureOwner(ctx) { const captured = current(ctx); return () => captured !== undefined && current(ctx) === captured; },
64
- remember(ctx, input) {
62
+ remember(ctx, input, options) {
65
63
  const invalid = sessionNoteError(input);
66
64
  if (invalid) return failure(invalid);
67
65
  const selected = state(ctx);
68
66
  if (!selected) return failure("session note owner is unavailable");
69
67
  if (selected.replay.error) return failure(selected.replay.error);
68
+ const text = input.text.trim();
69
+ if (options?.reuseIdentical) {
70
+ const entry = selected.replay.notes.find((note) => note.kind === input.kind && note.text === text && note.source === input.source);
71
+ if (entry) return { ok: true, storage: selected.owner.file ? "session" : "memory", entry, created: false };
72
+ }
70
73
  if (selected.replay.notes.length >= MAX_SESSION_NOTES) return failure(`session note limit reached (${MAX_SESSION_NOTES})`);
71
- const entry: SessionNote = { id: `session:${randomUUID()}`, kind: input.kind, text: input.text.trim(), recordedAt: new Date().toISOString(), originSessionId: selected.owner.id, ...(input.source === undefined ? {} : { source: input.source }) };
72
- const result = append(ctx, { version: 1, op: "save", note: entry });
73
- return result.ok ? { ...result, entry } : result;
74
+ const entry: SessionNote = { id: `session:${randomUUID()}`, kind: input.kind, text, recordedAt: new Date().toISOString(), originSessionId: selected.owner.id, ...(input.source === undefined ? {} : { source: input.source }) };
75
+ const result = append(ctx, selected, { version: 1, op: "save", note: entry });
76
+ return result.ok ? { ...result, entry, created: true } : result;
74
77
  },
75
78
  snapshot(ctx) {
76
79
  const selected = state(ctx);
@@ -99,9 +102,11 @@ export function createSessionMemory(pi: Pick<ExtensionAPI, "appendEntry">): Sess
99
102
  return entry ? { ok: true, entry, storage: snapshot.storage } : failure("session note not found on the active branch");
100
103
  },
101
104
  forget(ctx, id) {
102
- const existing = api.read(ctx, id);
103
- if (!existing.ok) return existing;
104
- const result = append(ctx, { version: 1, op: "forget", id });
105
+ const selected = state(ctx);
106
+ if (!selected) return failure("session note owner is unavailable");
107
+ if (selected.replay.error) return failure(selected.replay.error);
108
+ if (!selected.replay.notes.some((note) => note.id === id)) return failure("session note not found on the active branch");
109
+ const result = append(ctx, selected, { version: 1, op: "forget", id });
105
110
  return result.ok ? { ...result, removed: 1 } : result;
106
111
  },
107
112
  injection(ctx, opts = {}) {
@@ -6,6 +6,7 @@ import { cardFrameDetailHint, cardFramePresentation, type MindCardUI } from "./c
6
6
  interface SessionNoteCardModel {
7
7
  title: string;
8
8
  body: string;
9
+ summary?: string;
9
10
  }
10
11
 
11
12
  function record(value: unknown): Record<string, unknown> | undefined {
@@ -30,13 +31,14 @@ function sessionNoteCardModel(value: unknown): SessionNoteCardModel | undefined
30
31
  }
31
32
  return {
32
33
  title: `session note · ${note.kind}`,
34
+ summary: note.text,
33
35
  body: [
34
36
  `id: ${note.id}`,
35
37
  `recorded: ${note.recordedAt}`,
36
38
  `origin session: ${note.originSessionId} (provenance only; not auto-resolved)`,
37
39
  note.source === undefined ? "" : `source: ${note.source}`,
38
40
  "",
39
- note.text,
41
+ note.text,
40
42
  ].filter((line) => line !== "").join("\n"),
41
43
  };
42
44
  }
@@ -45,7 +47,7 @@ function sessionNoteCardModel(value: unknown): SessionNoteCardModel | undefined
45
47
  export function registerSessionNoteRenderer(pi: Pick<ExtensionAPI, "registerEntryRenderer">, cardUI: MindCardUI): void {
46
48
  pi.registerEntryRenderer<unknown>(SESSION_NOTE_ENTRY_TYPE, (entry, { expanded, keyHint }, theme) => {
47
49
  const model = sessionNoteCardModel(entry.data);
48
- return model ? cardUI.renderCard(cardFramePresentation(model.title, model.body), {
50
+ return model ? cardUI.renderCard(cardFramePresentation(model.title, model.body, model.summary), {
49
51
  expanded,
50
52
  theme,
51
53
  outputPad: cardUI.outputPad(),