ultimate-pi 0.4.0 → 0.4.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.
Files changed (76) hide show
  1. package/.pi/PACKAGING.md +3 -2
  2. package/.pi/extensions/lib/harness-vcc-settings.ts +50 -0
  3. package/.pi/extensions/ultimate-pi-vcc.ts +17 -0
  4. package/.pi/harness/docs/adrs/0030-inhouse-vcc-compaction.md +40 -0
  5. package/.pi/harness/docs/adrs/README.md +1 -0
  6. package/.pi/prompts/harness-setup.md +2 -2
  7. package/.pi/scripts/vendor-pi-vcc-settings.stub.ts +8 -0
  8. package/.pi/scripts/vendor-sync-pi-vcc.sh +40 -0
  9. package/.pi/settings.example.json +1 -6
  10. package/CHANGELOG.md +9 -7
  11. package/THIRD_PARTY_NOTICES.md +8 -22
  12. package/package.json +7 -6
  13. package/vendor/pi-vcc/README.md +215 -0
  14. package/vendor/pi-vcc/UPSTREAM_PIN.md +12 -0
  15. package/vendor/pi-vcc/demo.gif +0 -0
  16. package/vendor/pi-vcc/index.ts +12 -0
  17. package/vendor/pi-vcc/package.json +26 -0
  18. package/vendor/pi-vcc/scripts/audit-sessions.ts +88 -0
  19. package/vendor/pi-vcc/scripts/benchmark-real-sessions.ts +25 -0
  20. package/vendor/pi-vcc/scripts/compare-before-after.ts +36 -0
  21. package/vendor/pi-vcc/scripts/dump-branch-output.ts +20 -0
  22. package/vendor/pi-vcc/src/commands/pi-vcc.ts +36 -0
  23. package/vendor/pi-vcc/src/commands/vcc-recall.ts +65 -0
  24. package/vendor/pi-vcc/src/core/brief.ts +381 -0
  25. package/vendor/pi-vcc/src/core/build-sections.ts +79 -0
  26. package/vendor/pi-vcc/src/core/content.ts +60 -0
  27. package/vendor/pi-vcc/src/core/filter-noise.ts +42 -0
  28. package/vendor/pi-vcc/src/core/format-recall.ts +27 -0
  29. package/vendor/pi-vcc/src/core/format.ts +49 -0
  30. package/vendor/pi-vcc/src/core/lineage.ts +26 -0
  31. package/vendor/pi-vcc/src/core/load-messages.ts +41 -0
  32. package/vendor/pi-vcc/src/core/normalize.ts +66 -0
  33. package/vendor/pi-vcc/src/core/recall-scope.ts +14 -0
  34. package/vendor/pi-vcc/src/core/render-entries.ts +55 -0
  35. package/vendor/pi-vcc/src/core/report.ts +237 -0
  36. package/vendor/pi-vcc/src/core/sanitize.ts +5 -0
  37. package/vendor/pi-vcc/src/core/search-entries.ts +221 -0
  38. package/vendor/pi-vcc/src/core/settings.ts +8 -0
  39. package/vendor/pi-vcc/src/core/skill-collapse.ts +35 -0
  40. package/vendor/pi-vcc/src/core/summarize.ts +157 -0
  41. package/vendor/pi-vcc/src/core/tool-args.ts +14 -0
  42. package/vendor/pi-vcc/src/details.ts +7 -0
  43. package/vendor/pi-vcc/src/extract/commits.ts +69 -0
  44. package/vendor/pi-vcc/src/extract/files.ts +80 -0
  45. package/vendor/pi-vcc/src/extract/goals.ts +79 -0
  46. package/vendor/pi-vcc/src/extract/preferences.ts +55 -0
  47. package/vendor/pi-vcc/src/hooks/before-compact.ts +314 -0
  48. package/vendor/pi-vcc/src/sections.ts +12 -0
  49. package/vendor/pi-vcc/src/tools/recall.ts +109 -0
  50. package/vendor/pi-vcc/src/types.ts +14 -0
  51. package/vendor/pi-vcc/tests/before-compact-hook.test.ts +204 -0
  52. package/vendor/pi-vcc/tests/before-compact.test.ts +145 -0
  53. package/vendor/pi-vcc/tests/brief.test.ts +206 -0
  54. package/vendor/pi-vcc/tests/build-sections.test.ts +59 -0
  55. package/vendor/pi-vcc/tests/compile.test.ts +80 -0
  56. package/vendor/pi-vcc/tests/content.test.ts +31 -0
  57. package/vendor/pi-vcc/tests/extract-goals.test.ts +86 -0
  58. package/vendor/pi-vcc/tests/extract-preferences.test.ts +30 -0
  59. package/vendor/pi-vcc/tests/filter-noise.test.ts +61 -0
  60. package/vendor/pi-vcc/tests/fixtures.ts +61 -0
  61. package/vendor/pi-vcc/tests/format-recall.test.ts +30 -0
  62. package/vendor/pi-vcc/tests/format.test.ts +62 -0
  63. package/vendor/pi-vcc/tests/lineage.test.ts +33 -0
  64. package/vendor/pi-vcc/tests/load-messages.test.ts +51 -0
  65. package/vendor/pi-vcc/tests/normalize.test.ts +97 -0
  66. package/vendor/pi-vcc/tests/real-sessions.test.ts +38 -0
  67. package/vendor/pi-vcc/tests/recall-expand.test.ts +15 -0
  68. package/vendor/pi-vcc/tests/recall-scope.test.ts +32 -0
  69. package/vendor/pi-vcc/tests/recall-tool-scope.test.ts +67 -0
  70. package/vendor/pi-vcc/tests/render-entries.test.ts +62 -0
  71. package/vendor/pi-vcc/tests/report.test.ts +44 -0
  72. package/vendor/pi-vcc/tests/sanitize.test.ts +24 -0
  73. package/vendor/pi-vcc/tests/search-entries.test.ts +144 -0
  74. package/vendor/pi-vcc/tests/support/load-session.ts +23 -0
  75. package/vendor/pi-vcc/tests/support/real-sessions.ts +51 -0
  76. package/.pi/pi-vcc-config.json +0 -4
@@ -0,0 +1,79 @@
1
+ import type { NormalizedBlock } from "../types";
2
+ import { clip, clipSentence, firstLine, nonEmptyLines } from "./content";
3
+ import type { SectionData } from "../sections";
4
+ import { extractGoals } from "../extract/goals";
5
+ import { extractFiles } from "../extract/files";
6
+ import { extractPreferences, dedupPreferencesAgainstGoals } from "../extract/preferences";
7
+ import { extractCommits, formatCommits } from "../extract/commits";
8
+ import { buildBriefSections, sectionsToTranscript, stringifyBrief } from "./brief";
9
+
10
+ export interface BuildSectionsInput {
11
+ blocks: NormalizedBlock[];
12
+ }
13
+
14
+ const BLOCKER_RE =
15
+ /\b(fail(ed|s|ure|ing)?|broken|cannot|can't|won't work|does not work|doesn't work|still (broken|failing|wrong)|blocked|blocker|not (fixed|resolved|working)|crash(es|ed|ing)?)\b/i;
16
+
17
+ const extractOutstandingContext = (blocks: NormalizedBlock[]): string[] => {
18
+ const items: string[] = [];
19
+ const tail = blocks.slice(-20);
20
+
21
+ for (const b of tail) {
22
+ if (b.kind === "tool_result" && b.isError) {
23
+ items.push(`[${b.name}] ${firstLine(b.text, 150)}`);
24
+ continue;
25
+ }
26
+
27
+ if (b.kind === "assistant" || b.kind === "user") {
28
+ for (const line of nonEmptyLines(b.text)) {
29
+ if (!BLOCKER_RE.test(line)) continue;
30
+ if (line.length < 15) continue;
31
+ // Skip continuation fragments (sub-bullets, parentheticals, dangling clauses)
32
+ if (/^\s*[-*+>]\s/.test(line)) continue;
33
+ if (/^\s*\(/.test(line)) continue;
34
+ // Require sentence-like start: capital letter, code identifier, or quote
35
+ if (!/^\s*["'`*_]?[A-Z`]/.test(line)) continue;
36
+ const clipped = b.kind === "user" ? `[user] ${clipSentence(line, 150)}` : clipSentence(line, 150);
37
+ if (!items.includes(clipped)) items.push(clipped);
38
+ break;
39
+ }
40
+ }
41
+ }
42
+
43
+ return items.slice(0, 5);
44
+ };
45
+
46
+ const formatFileActivity = (blocks: NormalizedBlock[]): string[] => {
47
+ const act = extractFiles(blocks);
48
+ // Dedup: if already Modified, drop from Created (file existed before)
49
+ for (const p of act.modified) act.created.delete(p);
50
+ const lines: string[] = [];
51
+ const cap = (set: Set<string>, limit: number) => {
52
+ const arr = [...set];
53
+ if (arr.length <= limit) return arr.join(", ");
54
+ return arr.slice(0, limit).join(", ") + ` (+${arr.length - limit} more)`;
55
+ };
56
+ if (act.modified.size > 0) lines.push(`Modified: ${cap(act.modified, 10)}`);
57
+ if (act.created.size > 0) lines.push(`Created: ${cap(act.created, 10)}`);
58
+ if (act.read.size > 0) lines.push(`Read: ${cap(act.read, 10)}`);
59
+ return lines;
60
+ };
61
+
62
+ export const buildSections = (input: BuildSectionsInput): SectionData => {
63
+ const { blocks } = input;
64
+ const briefSections = buildBriefSections(blocks);
65
+ const sessionGoal = extractGoals(blocks);
66
+ const userPreferences = dedupPreferencesAgainstGoals(
67
+ extractPreferences(blocks),
68
+ sessionGoal,
69
+ );
70
+ return {
71
+ sessionGoal,
72
+ outstandingContext: extractOutstandingContext(blocks),
73
+ filesAndChanges: formatFileActivity(blocks),
74
+ commits: formatCommits(extractCommits(blocks)),
75
+ userPreferences,
76
+ briefTranscript: stringifyBrief(briefSections),
77
+ transcriptEntries: sectionsToTranscript(briefSections),
78
+ };
79
+ };
@@ -0,0 +1,60 @@
1
+ import type { Message } from "@mariozechner/pi-ai";
2
+
3
+ export const clip = (text: string, max = 200): string => {
4
+ if (text.length <= max) return text;
5
+ // Try to cut at a word boundary
6
+ const cut = text.lastIndexOf(" ", max);
7
+ let end = cut > max * 0.6 ? cut : max;
8
+ // Avoid splitting a surrogate pair
9
+ if (end > 0 && end < text.length) {
10
+ const code = text.charCodeAt(end - 1);
11
+ if (code >= 0xd800 && code <= 0xdbff) end--;
12
+ }
13
+ return text.slice(0, end);
14
+ };
15
+
16
+ /**
17
+ * Clip text to last sentence boundary at or before `max` chars.
18
+ * Falls back to word boundary (clip()) if no sentence end is found in the
19
+ * acceptable range. Trailing whitespace stripped.
20
+ */
21
+ export const clipSentence = (text: string, max = 200): string => {
22
+ if (text.length <= max) return text;
23
+ // Look for sentence terminators followed by space/newline within [max*0.5, max]
24
+ const window = text.slice(0, max);
25
+ const matches = [...window.matchAll(/[.!?](?:\s|$)/g)];
26
+ if (matches.length > 0) {
27
+ const last = matches[matches.length - 1];
28
+ const end = (last.index ?? 0) + 1; // include the punctuation
29
+ if (end >= max * 0.5) return text.slice(0, end);
30
+ }
31
+ return clip(text, max);
32
+ };
33
+
34
+ export const nonEmptyLines = (text: string): string[] =>
35
+ text.split("\n").map((line) => line.trim()).filter(Boolean);
36
+
37
+ export const firstLine = (text: string, max = 200): string =>
38
+ clip(text.split("\n")[0] ?? "", max);
39
+
40
+ export const textParts = (content: Message["content"]): string[] => {
41
+ if (!content) return [];
42
+ if (typeof content === "string") return [content];
43
+ return content
44
+ .filter((part) => part.type === "text")
45
+ .map((part) => part.text);
46
+ };
47
+
48
+ export const textOf = (content: Message["content"]): string =>
49
+ textParts(content).join("\n");
50
+
51
+ /** Extract a snippet of ~`radius` chars around the first match of `term` in `text`. */
52
+ export const snippet = (text: string, term: string, radius = 60): string | null => {
53
+ const idx = text.toLowerCase().indexOf(term.toLowerCase());
54
+ if (idx === -1) return null;
55
+ const start = Math.max(0, idx - radius);
56
+ const end = Math.min(text.length, idx + term.length + radius);
57
+ const prefix = start > 0 ? "..." : "";
58
+ const suffix = end < text.length ? "..." : "";
59
+ return `${prefix}${text.slice(start, end)}${suffix}`;
60
+ };
@@ -0,0 +1,42 @@
1
+ import type { NormalizedBlock } from "../types";
2
+
3
+ const NOISE_TOOLS = new Set([
4
+ "TodoWrite", "TodoRead", "ToolSearch", "WebSearch",
5
+ "AskUser", "ExitSpecMode", "GenerateDroid",
6
+ ]);
7
+
8
+ const NOISE_STRINGS = [
9
+ "Continue from where you left off.",
10
+ "No response requested.",
11
+ "IMPORTANT: TodoWrite was not called yet.",
12
+ ];
13
+
14
+ const XML_WRAPPER_RE = /<(system-reminder|ide_opened_file|command-message|context-window-usage)[^>]*>[\s\S]*?<\/\1>/g;
15
+
16
+ const isNoiseUserBlock = (text: string): boolean => {
17
+ const trimmed = text.trim();
18
+ if (NOISE_STRINGS.some((s) => trimmed.includes(s))) return true;
19
+ const stripped = trimmed.replace(XML_WRAPPER_RE, "").trim();
20
+ return stripped.length === 0;
21
+ };
22
+
23
+ const cleanUserText = (text: string): string =>
24
+ text.replace(XML_WRAPPER_RE, "").trim();
25
+
26
+ export const filterNoise = (blocks: NormalizedBlock[]): NormalizedBlock[] => {
27
+ const out: NormalizedBlock[] = [];
28
+ for (const b of blocks) {
29
+ if (b.kind === "thinking") continue;
30
+ if (b.kind === "tool_call" && NOISE_TOOLS.has(b.name)) continue;
31
+ if (b.kind === "tool_result" && NOISE_TOOLS.has(b.name)) continue;
32
+ if (b.kind === "user") {
33
+ if (isNoiseUserBlock(b.text)) continue;
34
+ const cleaned = cleanUserText(b.text);
35
+ if (!cleaned) continue;
36
+ out.push({ kind: "user", text: cleaned });
37
+ continue;
38
+ }
39
+ out.push(b);
40
+ }
41
+ return out;
42
+ };
@@ -0,0 +1,27 @@
1
+ import type { SearchHit } from "./search-entries";
2
+
3
+ export const formatRecallOutput = (
4
+ entries: SearchHit[],
5
+ query?: string,
6
+ headerOverride?: string,
7
+ ): string => {
8
+ if (entries.length === 0) {
9
+ return query
10
+ ? `No matches for "${query}" in session history.`
11
+ : "No entries in session history.";
12
+ }
13
+
14
+ const header = headerOverride
15
+ ? `${headerOverride} for "${query}":`
16
+ : query
17
+ ? `Found ${entries.length} matches for "${query}":`
18
+ : `Session history (${entries.length} entries):`;
19
+
20
+ const lines = entries.map((e) => {
21
+ const fileSuffix = e.files?.length ? ` files:[${e.files.join(", ")}]` : "";
22
+ const body = query && e.snippet ? e.snippet : e.summary;
23
+ return `#${e.index} [${e.role}]${fileSuffix} ${body}`;
24
+ });
25
+
26
+ return `${header}\n\n${lines.join("\n\n")}`;
27
+ };
@@ -0,0 +1,49 @@
1
+ import type { SectionData } from "../sections";
2
+
3
+ const section = (title: string, items: string[]): string => {
4
+ if (items.length === 0) return "";
5
+ const body = items.map((i) => `- ${i}`).join("\n");
6
+ return `[${title}]\n${body}`;
7
+ };
8
+
9
+ const BRIEF_MAX_LINES = 120;
10
+
11
+ export const capBrief = (text: string): string => {
12
+ const lines = text.split("\n");
13
+ if (lines.length <= BRIEF_MAX_LINES) return text;
14
+ const omitted = lines.length - BRIEF_MAX_LINES;
15
+ const kept = lines.slice(-BRIEF_MAX_LINES);
16
+ // Find first section header to avoid cutting mid-section
17
+ const firstHeader = kept.findIndex((l) => /^\[.+\]/.test(l));
18
+ const clean = firstHeader > 0 ? kept.slice(firstHeader) : kept;
19
+ return `...(${omitted} earlier lines omitted)\n\n${clean.join("\n")}`;
20
+ };
21
+
22
+ export const RECALL_NOTE =
23
+ "Use `vcc_recall` to search for prior work, decisions, and context from before this summary. " +
24
+ "Do not redo work already completed.";
25
+
26
+ export const formatSummary = (data: SectionData): string => {
27
+ const headerParts = [
28
+ section("Session Goal", data.sessionGoal),
29
+ section("Files And Changes", data.filesAndChanges),
30
+ section("Commits", data.commits),
31
+ section("Outstanding Context", data.outstandingContext),
32
+ section("User Preferences", data.userPreferences),
33
+ ].filter(Boolean);
34
+
35
+ const parts: string[] = [];
36
+ if (headerParts.length > 0) {
37
+ parts.push(headerParts.join("\n\n"));
38
+ }
39
+ if (data.briefTranscript) {
40
+ parts.push(capBrief(data.briefTranscript));
41
+ }
42
+
43
+ if (parts.length === 0) return "";
44
+
45
+ // NOTE: RECALL_NOTE is intentionally NOT appended here.
46
+ // It is appended once by `compile()` at the very end, after merge-with-previous,
47
+ // to avoid the note compounding inside the brief transcript across compactions.
48
+ return parts.join("\n\n---\n\n");
49
+ };
@@ -0,0 +1,26 @@
1
+ export interface LineageEntryLike {
2
+ id?: string;
3
+ }
4
+
5
+ export interface LineageSessionManagerLike {
6
+ getBranch: () => LineageEntryLike[];
7
+ getEntries?: () => LineageEntryLike[];
8
+ }
9
+
10
+ export const getActiveLineageEntryIds = (sessionManager: LineageSessionManagerLike): Set<string> => {
11
+ try {
12
+ const branch = sessionManager.getBranch() ?? [];
13
+ if (branch.length > 0) {
14
+ return new Set(branch.map((e) => e.id).filter((id): id is string => Boolean(id)));
15
+ }
16
+ } catch {
17
+ // fall through to defensive fallback
18
+ }
19
+
20
+ try {
21
+ const all = sessionManager.getEntries?.() ?? [];
22
+ return new Set(all.map((e) => e.id).filter((id): id is string => Boolean(id)));
23
+ } catch {
24
+ return new Set();
25
+ }
26
+ };
@@ -0,0 +1,41 @@
1
+ import { readFileSync } from "fs";
2
+ import type { Message } from "@mariozechner/pi-ai";
3
+ import { renderMessage, type RenderedEntry } from "./render-entries";
4
+
5
+ export interface LoadedMessages {
6
+ rendered: RenderedEntry[];
7
+ rawMessages: Message[];
8
+ entryIds: string[];
9
+ }
10
+
11
+ export const loadAllMessages = (
12
+ sessionFile: string,
13
+ full: boolean,
14
+ allowedEntryIds?: Set<string>,
15
+ ): LoadedMessages => {
16
+ const content = readFileSync(sessionFile, "utf-8");
17
+ const entries: any[] = [];
18
+ for (const line of content.split("\n")) {
19
+ if (!line.trim()) continue;
20
+ try { entries.push(JSON.parse(line)); } catch {}
21
+ }
22
+ const rendered: RenderedEntry[] = [];
23
+ const rawMessages: Message[] = [];
24
+ const entryIds: string[] = [];
25
+
26
+ let messageIndex = 0;
27
+ for (const e of entries) {
28
+ const isMessage = e.type === "message" && e.message;
29
+ if (!isMessage) continue;
30
+
31
+ const allowed = !allowedEntryIds || allowedEntryIds.has(e.id);
32
+ if (allowed) {
33
+ rendered.push(renderMessage(e.message, messageIndex, full));
34
+ rawMessages.push(e.message);
35
+ entryIds.push(String(e.id));
36
+ }
37
+ messageIndex++;
38
+ }
39
+
40
+ return { rendered, rawMessages, entryIds };
41
+ };
@@ -0,0 +1,66 @@
1
+ import type { Message } from "@mariozechner/pi-ai";
2
+ import type { NormalizedBlock } from "../types";
3
+ import { textOf } from "./content";
4
+ import { sanitize } from "./sanitize";
5
+
6
+ const normalizeOne = (msg: Message, msgIndex: number): NormalizedBlock[] => {
7
+ if (msg.role === "user") {
8
+ const blocks: NormalizedBlock[] = [];
9
+ const text = sanitize(textOf(msg.content));
10
+ if (text) blocks.push({ kind: "user", text, sourceIndex: msgIndex });
11
+ if (msg.content && typeof msg.content !== "string") {
12
+ for (const part of msg.content) {
13
+ if (part.type === "image") {
14
+ blocks.push({ kind: "user", text: `[image: ${part.mimeType}]`, sourceIndex: msgIndex });
15
+ }
16
+ }
17
+ }
18
+ return blocks.length > 0 ? blocks : [{ kind: "user", text: "", sourceIndex: msgIndex }];
19
+ }
20
+
21
+ if (msg.role === "toolResult") {
22
+ return [{
23
+ kind: "tool_result",
24
+ name: msg.toolName,
25
+ text: sanitize(textOf(msg.content)),
26
+ isError: msg.isError,
27
+ sourceIndex: msgIndex,
28
+ }];
29
+ }
30
+
31
+ if (msg.role === "assistant") {
32
+ if (!msg.content) return [];
33
+ if (typeof msg.content === "string") {
34
+ return [{ kind: "assistant", text: sanitize(msg.content), sourceIndex: msgIndex }];
35
+ }
36
+
37
+ const blocks: NormalizedBlock[] = [];
38
+ for (const part of msg.content) {
39
+ if (part.type === "text") {
40
+ blocks.push({ kind: "assistant", text: sanitize(part.text), sourceIndex: msgIndex });
41
+ } else if (part.type === "thinking") {
42
+ blocks.push({
43
+ kind: "thinking",
44
+ text: sanitize(part.thinking),
45
+ redacted: part.redacted ?? false,
46
+ sourceIndex: msgIndex,
47
+ });
48
+ } else if (part.type === "toolCall") {
49
+ blocks.push({
50
+ kind: "tool_call",
51
+ name: part.name,
52
+ args: part.arguments,
53
+ sourceIndex: msgIndex,
54
+ });
55
+ }
56
+ }
57
+ return blocks;
58
+ }
59
+
60
+ return [];
61
+ };
62
+
63
+ export const normalize = (messages: Message[]): NormalizedBlock[] =>
64
+ messages.flatMap((msg, i) => normalizeOne(msg, i));
65
+
66
+
@@ -0,0 +1,14 @@
1
+ export type RecallScope = "lineage" | "all";
2
+
3
+ const SCOPE_RE = /\bscope:(lineage|all)\b/i;
4
+
5
+ export const normalizeRecallScope = (scope?: unknown): RecallScope =>
6
+ typeof scope === "string" && scope.toLowerCase() === "all" ? "all" : "lineage";
7
+
8
+ export const parseRecallScope = (text: string): { scope: RecallScope; text: string } => {
9
+ const match = text.match(SCOPE_RE);
10
+ return {
11
+ scope: normalizeRecallScope(match?.[1]),
12
+ text: text.replace(SCOPE_RE, "").replace(/\s+/g, " ").trim(),
13
+ };
14
+ };
@@ -0,0 +1,55 @@
1
+ import type { Message } from "@mariozechner/pi-ai";
2
+ import { clip, textOf } from "./content";
3
+ import { summarizeToolArgs } from "./tool-args";
4
+ import { extractPath } from "./tool-args";
5
+
6
+ export interface RenderedEntry {
7
+ index: number;
8
+ role: string;
9
+ summary: string;
10
+ files?: string[];
11
+ }
12
+
13
+ const toolCalls = (content: Message["content"]): string => {
14
+ if (!content || typeof content === "string") return "";
15
+ return content
16
+ .filter((c) => c.type === "toolCall")
17
+ .map((c) => `${c.name}(${summarizeToolArgs(c.arguments)})`)
18
+ .join(", ");
19
+ };
20
+
21
+ const extractFilesFromContent = (content: Message["content"]): string[] => {
22
+ if (!content || typeof content === "string") return [];
23
+ return content
24
+ .filter((c) => c.type === "toolCall")
25
+ .map((c) => extractPath(c.arguments))
26
+ .filter((p): p is string => p !== null);
27
+ };
28
+
29
+ export const renderMessage = (msg: Message, index: number, full = false): RenderedEntry => {
30
+ if (msg.role === "user") {
31
+ return { index, role: "user", summary: full ? textOf(msg.content) : clip(textOf(msg.content), 300) };
32
+ }
33
+ if (msg.role === "toolResult") {
34
+ const prefix = msg.isError ? "ERROR " : "";
35
+ const text = full ? textOf(msg.content) : clip(textOf(msg.content), 200);
36
+ return {
37
+ index, role: "tool_result",
38
+ summary: `${prefix}[${msg.toolName}] ${text}`,
39
+ };
40
+ }
41
+ // bashExecution has command+output instead of content
42
+ if ((msg as any).role === "bashExecution") {
43
+ const cmd = (msg as any).command ?? "";
44
+ const out = (msg as any).output ?? "";
45
+ const text = full ? `$ ${cmd}\n${out}` : clip(`$ ${cmd}\n${out}`, 300);
46
+ return { index, role: "bash", summary: text };
47
+ }
48
+ const text = full ? textOf(msg.content) : clip(textOf(msg.content), 300);
49
+ const tools = toolCalls(msg.content);
50
+ const files = extractFilesFromContent(msg.content);
51
+ const summary = tools ? `${tools}\n${text}` : text;
52
+ return { index, role: "assistant", summary, ...(files.length > 0 && { files }) };
53
+ };
54
+
55
+