@aeondave/pi-persona-mind 0.8.7 → 0.9.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/AGENTS.md +58 -14
- package/CHANGELOG.md +95 -0
- package/README.md +123 -67
- package/docs/DESIGN.md +224 -35
- package/docs/MEMORY-RESEARCH.md +135 -112
- package/package.json +7 -12
- package/src/core/auto-optimize.ts +12 -10
- package/src/core/capture.ts +14 -6
- package/src/core/host-compat.ts +9 -6
- package/src/core/knowledge-review.ts +107 -0
- package/src/core/memory-inspector.ts +149 -0
- package/src/core/memory-read.ts +3 -3
- package/src/core/memory.ts +6 -0
- package/src/core/optimize-history.ts +3 -3
- package/src/core/optimize-service.ts +10 -6
- package/src/core/optimize.ts +5 -11
- package/src/core/retrieval.ts +5 -4
- package/src/core/service.ts +24 -13
- package/src/core/store.ts +8 -2
- package/src/extension/auto-optimize-session.ts +26 -6
- package/src/extension/auto-optimize.ts +134 -25
- package/src/extension/inspector-data.ts +69 -0
- package/src/extension/knowledge-review.ts +215 -0
- package/src/extension/memory-inspector.ts +82 -0
- package/src/extension/mind-actions.ts +38 -0
- package/src/extension/mind-command.ts +42 -1
- package/src/extension/review-evidence.ts +222 -0
- package/src/index.ts +90 -43
- package/src/session-memory.ts +6 -2
- package/src/tools/backlog.ts +2 -2
- package/src/tools/memory.ts +51 -24
- package/src/ui/card-frame.ts +161 -0
- package/src/ui/inspector-frame.ts +44 -0
- package/src/ui/memory-inspector.ts +460 -0
- package/src/ui/mind-result-card.ts +37 -4
- package/src/ui/presentation.ts +13 -23
- package/src/ui/session-note-card.ts +12 -6
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { cardFrameDetailHint, cardFramePresentation, type MindCardUI } from "./card-frame.ts";
|
|
3
3
|
|
|
4
4
|
export const MIND_RESULT_ENTRY_TYPE = "pi-persona-mind-result";
|
|
5
5
|
const MAX_TITLE_CHARS = 160;
|
|
6
6
|
const MAX_BODY_CHARS = 1_000_000;
|
|
7
|
+
const AUTOMATIC_NO_OP_PREFIX = "Bounded coverage: one selected record window; bounded review found no safe consolidation in this record set.\nWorker ";
|
|
8
|
+
interface AutomaticResultContext {
|
|
9
|
+
automatic: true;
|
|
10
|
+
target: "project" | "project-long" | "persona";
|
|
11
|
+
phase: "result";
|
|
12
|
+
summary: string;
|
|
13
|
+
attention: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function automaticContext(value: unknown): AutomaticResultContext | undefined {
|
|
17
|
+
if (!value || typeof value !== "object") return undefined;
|
|
18
|
+
const context = value as Record<string, unknown>;
|
|
19
|
+
if (context.automatic !== true || context.phase !== "result" || (context.target !== "project" && context.target !== "project-long" && context.target !== "persona") || typeof context.summary !== "string" || typeof context.attention !== "boolean") return undefined;
|
|
20
|
+
return context as unknown as AutomaticResultContext;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function cardTitle(title: string): string {
|
|
24
|
+
const automatic = /^Mind automatic (?:optimization|result|proposal)( — .+)?$/.exec(title);
|
|
25
|
+
if (automatic) return `mind · automatic review${automatic[1] ?? ""}`;
|
|
26
|
+
return title.replace(/^(Mind|Memory|Automatic memory|Staged memory)\b/, (prefix) => prefix[0]!.toLowerCase() + prefix.slice(1));
|
|
27
|
+
}
|
|
7
28
|
|
|
8
29
|
/** Register once per factory; command output stays display-only and can be expanded without loss. */
|
|
9
|
-
export function registerMindResultRenderer(pi: ExtensionAPI): void {
|
|
10
|
-
pi.registerEntryRenderer<{ title: string; content: string }>(MIND_RESULT_ENTRY_TYPE, (entry, { expanded }, theme) => {
|
|
30
|
+
export function registerMindResultRenderer(pi: Pick<ExtensionAPI, "registerEntryRenderer">, cardUI: MindCardUI): void {
|
|
31
|
+
pi.registerEntryRenderer<{ title: string; content: string; reportContext?: unknown }>(MIND_RESULT_ENTRY_TYPE, (entry, { expanded, keyHint }, theme) => {
|
|
11
32
|
const data = entry.data;
|
|
12
33
|
if (!data || typeof data.title !== "string" || data.title.length < 1 || data.title.length > MAX_TITLE_CHARS || typeof data.content !== "string" || data.content.length > MAX_BODY_CHARS) return undefined;
|
|
13
|
-
|
|
34
|
+
const report = automaticContext(data.reportContext);
|
|
35
|
+
const legacyAutomatic = /^Mind automatic (?:optimization|result|proposal)(?: — .+)?$/.test(data.title);
|
|
36
|
+
const manualNoOp = /^Mind optimization result(?: — .+)?$/.test(data.title) && data.content.startsWith(AUTOMATIC_NO_OP_PREFIX);
|
|
37
|
+
const presentation = report || legacyAutomatic
|
|
38
|
+
? { title: report ? `mind · ${report.target} · ${report.summary}` : cardTitle(data.title), state: report?.attention ? "attention" as const : "neutral" as const, full: data.content, preview: () => ({ text: "", truncated: true }) }
|
|
39
|
+
: cardFramePresentation(cardTitle(data.title), data.content, manualNoOp ? "One selected window reviewed; no consolidation proposed" : undefined);
|
|
40
|
+
return cardUI.renderCard(presentation, {
|
|
41
|
+
expanded,
|
|
42
|
+
theme,
|
|
43
|
+
outputPad: cardUI.outputPad(),
|
|
44
|
+
detailHint: cardFrameDetailHint(keyHint),
|
|
45
|
+
expansionKey: entry,
|
|
46
|
+
});
|
|
14
47
|
});
|
|
15
48
|
}
|
package/src/ui/presentation.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* they only bound what a collapsed Pi card paints.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { keyHint } from "@earendil-works/pi-coding-agent";
|
|
7
6
|
import { sliceByColumn, stripTerminalSequences, Text, visibleWidth } from "@earendil-works/pi-tui";
|
|
8
7
|
|
|
9
8
|
export const MAX_COLLAPSED_CARD_LINES = 3;
|
|
@@ -27,14 +26,15 @@ export interface CardTheme {
|
|
|
27
26
|
bold: (text: string) => string;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function sanitizeCardText(text: string): string {
|
|
29
|
+
export function sanitizeCardText(text: string): string {
|
|
31
30
|
return stripTerminalSequences(text.replace(/\r\n?/g, "\n")).replace(C0_AND_DEL, "");
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/** Bound a collapsed card: a few semantic lines, each clipped by column, then a drill-down marker. */
|
|
35
34
|
export function compactVisibleText(input: string, opts: CompactVisibleTextOptions = {}): CompactVisibleTextResult {
|
|
36
35
|
const maxLines = Math.max(1, Math.floor(opts.maxLines ?? MAX_COLLAPSED_CARD_LINES));
|
|
37
|
-
const
|
|
36
|
+
const requestedColumns = opts.maxLineChars ?? MAX_COLLAPSED_CARD_CHARS;
|
|
37
|
+
const maxLineColumns = Number.isFinite(requestedColumns) ? Math.max(1, Math.floor(requestedColumns)) : MAX_COLLAPSED_CARD_CHARS;
|
|
38
38
|
const source = sanitizeCardText(input)
|
|
39
39
|
.split("\n")
|
|
40
40
|
.map((line) => line.trim())
|
|
@@ -63,32 +63,22 @@ export function compactVisibleText(input: string, opts: CompactVisibleTextOption
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
export
|
|
68
|
-
try {
|
|
69
|
-
return keyHint("app.tools.expand", "to expand");
|
|
70
|
-
} catch {
|
|
71
|
-
return "ctrl+o to expand";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
66
|
+
/** Optional expansion hint supplied by Pi's active renderer context. */
|
|
67
|
+
export type DetailHint = () => string;
|
|
74
68
|
|
|
75
|
-
function formatExpandableBody(body: string, expanded: boolean, theme: CardTheme): string {
|
|
69
|
+
function formatExpandableBody(body: string, expanded: boolean, theme: CardTheme, detailHint?: DetailHint, summary?: string): string {
|
|
76
70
|
const full = sanitizeCardText(body).trim() || "(no output)";
|
|
77
71
|
if (expanded) return theme.fg("toolOutput", full);
|
|
78
|
-
const
|
|
79
|
-
const
|
|
72
|
+
const compact = summary === undefined ? full : sanitizeCardText(summary).trim();
|
|
73
|
+
const preview = compactVisibleText(compact);
|
|
74
|
+
const hidden = preview.truncated || compact !== full;
|
|
75
|
+
const hint = hidden && detailHint ? `\n${theme.fg("dim", sanitizeCardText(detailHint()))}` : "";
|
|
80
76
|
return `${theme.fg("toolOutput", preview.text)}${hint}`;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
/** Result body only: Pi
|
|
84
|
-
export function renderExpandableResult(body: string, expanded: boolean, theme: CardTheme): Text {
|
|
85
|
-
return new Text(formatExpandableBody(body, expanded, theme), 0, 0);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Standalone entries such as backlog wakes have no Pi tool title and still need their own. */
|
|
89
|
-
export function renderExpandableCard(label: string, body: string, expanded: boolean, theme: CardTheme): Text {
|
|
90
|
-
const title = theme.fg("accent", theme.bold(label));
|
|
91
|
-
return new Text(`${title}\n${formatExpandableBody(body, expanded, theme)}`, 0, 0);
|
|
79
|
+
/** Result body only: Pi owns the title/shell. An optional compact summary never replaces expanded evidence. */
|
|
80
|
+
export function renderExpandableResult(body: string, expanded: boolean, theme: CardTheme, detailHint?: DetailHint, summary?: string): Text {
|
|
81
|
+
return new Text(formatExpandableBody(body, expanded, theme, detailHint, summary), 0, 0);
|
|
92
82
|
}
|
|
93
83
|
|
|
94
84
|
export function toolResultText(result: { content?: ReadonlyArray<{ type: string; text?: string }> }): string {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
3
|
import { MAX_SESSION_NOTE_CHARS, SESSION_MEMORY_KINDS, SESSION_NOTE_ENTRY_TYPE, MAX_SESSION_SOURCE_CHARS } from "../core/session-memory.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { cardFrameDetailHint, cardFramePresentation, type MindCardUI } from "./card-frame.ts";
|
|
5
5
|
|
|
6
6
|
interface SessionNoteCardModel {
|
|
7
7
|
title: string;
|
|
@@ -16,7 +16,7 @@ function sessionNoteCardModel(value: unknown): SessionNoteCardModel | undefined
|
|
|
16
16
|
const event = record(value);
|
|
17
17
|
if (event?.version !== 1) return undefined;
|
|
18
18
|
if (event.op === "forget" && typeof event.id === "string" && event.id.startsWith("session:")) {
|
|
19
|
-
return { title: "
|
|
19
|
+
return { title: "session note retired", body: `${event.id}\nNo longer active on this branch.` };
|
|
20
20
|
}
|
|
21
21
|
if (event.op !== "save") return undefined;
|
|
22
22
|
const note = record(event.note);
|
|
@@ -29,7 +29,7 @@ function sessionNoteCardModel(value: unknown): SessionNoteCardModel | undefined
|
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
31
|
return {
|
|
32
|
-
title: `
|
|
32
|
+
title: `session note · ${note.kind}`,
|
|
33
33
|
body: [
|
|
34
34
|
`id: ${note.id}`,
|
|
35
35
|
`recorded: ${note.recordedAt}`,
|
|
@@ -42,9 +42,15 @@ function sessionNoteCardModel(value: unknown): SessionNoteCardModel | undefined
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** Register a semantic standalone card for session-note save and forget events. */
|
|
45
|
-
export function registerSessionNoteRenderer(pi: Pick<ExtensionAPI, "registerEntryRenderer"
|
|
46
|
-
pi.registerEntryRenderer<unknown>(SESSION_NOTE_ENTRY_TYPE, (entry, { expanded }, theme) => {
|
|
45
|
+
export function registerSessionNoteRenderer(pi: Pick<ExtensionAPI, "registerEntryRenderer">, cardUI: MindCardUI): void {
|
|
46
|
+
pi.registerEntryRenderer<unknown>(SESSION_NOTE_ENTRY_TYPE, (entry, { expanded, keyHint }, theme) => {
|
|
47
47
|
const model = sessionNoteCardModel(entry.data);
|
|
48
|
-
return model ?
|
|
48
|
+
return model ? cardUI.renderCard(cardFramePresentation(model.title, model.body), {
|
|
49
|
+
expanded,
|
|
50
|
+
theme,
|
|
51
|
+
outputPad: cardUI.outputPad(),
|
|
52
|
+
detailHint: cardFrameDetailHint(keyHint),
|
|
53
|
+
expansionKey: entry,
|
|
54
|
+
}) : undefined;
|
|
49
55
|
});
|
|
50
56
|
}
|