notesoup 0.51.8 → 0.51.9

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.
@@ -1,15 +1,16 @@
1
1
  import { generateDiffString } from "@earendil-works/pi-coding-agent";
2
2
  import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../../../src/tools/notes.js";
3
3
  import { notesIdentityFromPi } from "./adapter.js";
4
+ import { notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../render.js";
4
5
  import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
5
6
  function renderDiff(change) {
6
7
  return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
7
8
  }
8
9
  /** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */
9
10
  export function registerNotesTools(pi) {
10
- registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
11
- registerOperation(pi, notesUpdate, (params, ctx) => notesUpdate.execute(params, notesIdentityFromPi(ctx), renderDiff), NOTES_NAMESPACE);
12
- registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
11
+ registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
12
+ registerOperation(pi, notesUpdate, (params, ctx) => notesUpdate.execute(params, notesIdentityFromPi(ctx), renderDiff), NOTES_NAMESPACE, notesUpdateRenderers);
13
+ registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE, notesReadRenderers);
13
14
  registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
14
15
  registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
15
16
  }
@@ -0,0 +1,40 @@
1
+ /** Pi TUI renderers for notesoup's own tools: collapsed one-line slips, expandable bodies. */
2
+ import { type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
3
+ import { type Component } from "@earendil-works/pi-tui";
4
+ import type { Static } from "typebox";
5
+ import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
6
+ /** Only the render-context members these renderers read; the host's ToolRenderContext satisfies this. */
7
+ type CallContext<TArgs> = {
8
+ args: TArgs;
9
+ };
10
+ export type NotesWriteArgs = Static<typeof notesWriteParameters>;
11
+ export declare const notesWriteRenderers: {
12
+ renderCall: (args: NotesWriteArgs, theme: Theme) => Component;
13
+ renderResult(result: AgentToolResult<undefined>, options: {
14
+ expanded: boolean;
15
+ }, theme: Theme, context: CallContext<NotesWriteArgs>): Component;
16
+ };
17
+ export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
18
+ export declare const notesUpdateRenderers: {
19
+ renderCall(args: NotesUpdateArgs, theme: Theme): Component;
20
+ renderResult(result: AgentToolResult<undefined>, options: {
21
+ expanded: boolean;
22
+ }, theme: Theme, context: CallContext<NotesUpdateArgs>): Component;
23
+ };
24
+ export type NotesReadArgs = Static<typeof notesReadParameters>;
25
+ export declare const notesReadRenderers: {
26
+ renderCall: (args: NotesReadArgs, theme: Theme) => Component;
27
+ renderResult(result: AgentToolResult<undefined>, options: {
28
+ expanded: boolean;
29
+ }, theme: Theme): Component;
30
+ };
31
+ export type EmptyBrainArgs = {
32
+ last_word?: string;
33
+ };
34
+ export declare const emptyBrainRenderers: {
35
+ renderCall: (_args: EmptyBrainArgs, theme: Theme) => Component;
36
+ renderResult(result: AgentToolResult<unknown>, _options: {
37
+ expanded: boolean;
38
+ }, theme: Theme, context: CallContext<EmptyBrainArgs>): Component;
39
+ };
40
+ export {};
@@ -0,0 +1,168 @@
1
+ /** Pi TUI renderers for notesoup's own tools: collapsed one-line slips, expandable bodies. */
2
+ import { renderDiff } from "@earendil-works/pi-coding-agent";
3
+ import { Text, TruncatedText, visibleWidth } from "@earendil-works/pi-tui";
4
+ /** Expanded bodies show this many lines before a "more lines" marker; the full text is in the receipt. */
5
+ const EXPANDED_LINE_CAP = 80;
6
+ /** structuredContent is wireResult(outcome): the data itself, or {error, code}. Old sessions may lack it. */
7
+ function wireOf(result) {
8
+ const sc = result.structuredContent;
9
+ if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
10
+ const obj = sc;
11
+ if (typeof obj.error === "string")
12
+ return { error: { error: obj.error, code: typeof obj.code === "string" ? obj.code : "error" } };
13
+ return { data: obj };
14
+ }
15
+ return {};
16
+ }
17
+ /** Results without a structured payload (resumed old sessions) fall back to the receipt's first line. */
18
+ function receiptFallback(result, theme) {
19
+ const text = result.content.find((c) => c.type === "text")?.text ?? "";
20
+ return new TruncatedText(theme.fg("dim", text.split("\n")[0] ?? ""), 0, 0);
21
+ }
22
+ function errorComponent(theme, error, expanded) {
23
+ if (!expanded)
24
+ return new TruncatedText(theme.fg("error", `${error.code}: ${error.error.split("\n")[0]}`), 0, 0);
25
+ return new Text(theme.fg("error", `${error.code}: ${error.error}`), 0, 0);
26
+ }
27
+ function addressText(theme, address) {
28
+ return theme.fg("accent", address);
29
+ }
30
+ function callLine(theme, tool, target, suffix = "") {
31
+ let line = theme.fg("toolTitle", theme.bold(tool));
32
+ if (target !== undefined && target !== "")
33
+ line += " " + addressText(theme, target);
34
+ if (suffix !== "")
35
+ line += theme.fg("dim", suffix);
36
+ return new TruncatedText(line, 0, 0);
37
+ }
38
+ /** First `+` line of a generateDiffString diff, without its line-number prefix: the sentence just written down. */
39
+ function firstAddedLine(diff) {
40
+ for (const line of diff.split("\n")) {
41
+ const match = /^\+(\s*\d*)?\s?(.*)$/.exec(line);
42
+ if (match)
43
+ return match[2];
44
+ }
45
+ return undefined;
46
+ }
47
+ function boundedLines(text, theme) {
48
+ const lines = text.split("\n");
49
+ if (lines.length <= EXPANDED_LINE_CAP)
50
+ return text;
51
+ return `${lines.slice(0, EXPANDED_LINE_CAP).join("\n")}\n${theme.fg("dim", `… ${lines.length - EXPANDED_LINE_CAP} more lines`)}`;
52
+ }
53
+ export const notesWriteRenderers = {
54
+ renderCall: (args, theme) => callLine(theme, "notes_write", args.address),
55
+ renderResult(result, options, theme, context) {
56
+ const { data, error } = wireOf(result);
57
+ if (error)
58
+ return errorComponent(theme, error, options.expanded);
59
+ if (!data)
60
+ return receiptFallback(result, theme);
61
+ const content = typeof context.args?.content === "string" ? context.args.content : "";
62
+ const qualifier = data.outcome === "created" ? "" : theme.fg("dim", ` · ${data.outcome}`);
63
+ const head = `wrote ${addressText(theme, data.address)}${qualifier}${theme.fg("dim", ` · ${Array.from(content).length} chars`)}`;
64
+ if (!options.expanded)
65
+ return new TruncatedText(head, 0, 0);
66
+ return new Text(`${head}\n\n${boundedLines(content, theme)}`, 0, 0);
67
+ },
68
+ };
69
+ export const notesUpdateRenderers = {
70
+ renderCall(args, theme) {
71
+ let suffix = "";
72
+ if (args.crumpled === true)
73
+ suffix = " · crumple";
74
+ else if (args.crumpled === false)
75
+ suffix = " · restore";
76
+ if (typeof args.rename_to === "string" && args.rename_to !== "")
77
+ suffix += ` → ${args.rename_to}`;
78
+ return callLine(theme, "notes_update", args.address, suffix);
79
+ },
80
+ renderResult(result, options, theme, context) {
81
+ const { data, error } = wireOf(result);
82
+ if (error)
83
+ return errorComponent(theme, error, options.expanded);
84
+ if (!data)
85
+ return receiptFallback(result, theme);
86
+ let head;
87
+ if (context.args?.crumpled === true) {
88
+ head = `✂ crumpled ${theme.strikethrough(theme.fg("dim", data.address))}`;
89
+ }
90
+ else if (context.args?.crumpled === false) {
91
+ head = `restored ${addressText(theme, data.address)}`;
92
+ }
93
+ else if (data.change_kind === "moved") {
94
+ head = `renamed ${theme.fg("dim", data.rename_from ?? "?")}${theme.fg("dim", " → ")}${addressText(theme, data.address)}`;
95
+ }
96
+ else if (data.change_kind === "none") {
97
+ head = theme.fg("dim", "unchanged ") + addressText(theme, data.address);
98
+ }
99
+ else {
100
+ head = `edited ${addressText(theme, data.address)}`;
101
+ const peek = firstAddedLine(data.diff);
102
+ if (peek !== undefined && peek !== "")
103
+ head += theme.fg("dim", " · ") + theme.fg("toolDiffAdded", `+ ${peek}`);
104
+ }
105
+ if (!options.expanded)
106
+ return new TruncatedText(head, 0, 0);
107
+ const parts = [head];
108
+ if (data.diff !== "")
109
+ parts.push("", renderDiff(data.diff));
110
+ if (data.change_kind !== "moved" && data.rename_from !== undefined)
111
+ parts.push(theme.fg("dim", `renamed from ${data.rename_from}`));
112
+ return new Text(parts.join("\n"), 0, 0);
113
+ },
114
+ };
115
+ export const notesReadRenderers = {
116
+ renderCall: (args, theme) => callLine(theme, "notes_read", args.address, args.offset_chars !== undefined && args.offset_chars !== 0 ? ` · offset ${args.offset_chars}` : ""),
117
+ renderResult(result, options, theme) {
118
+ const { data, error } = wireOf(result);
119
+ if (error)
120
+ return errorComponent(theme, error, options.expanded);
121
+ if (!data)
122
+ return receiptFallback(result, theme);
123
+ const truncated = data.next_offset_chars !== null;
124
+ let head = `read ${addressText(theme, data.address)}${theme.fg("dim", ` · ${data.total_chars} chars${truncated ? " · truncated" : ""}`)}`;
125
+ const peek = data.text.split("\n").find((line) => line.trim() !== "");
126
+ if (peek !== undefined)
127
+ head += theme.fg("dim", ` — ${peek.trim()}`);
128
+ if (!options.expanded)
129
+ return new TruncatedText(head, 0, 0);
130
+ const tail = truncated ? `\n${theme.fg("dim", `… continue at offset_chars=${data.next_offset_chars}`)}` : "";
131
+ return new Text(`${head}\n\n${boundedLines(data.text, theme)}${tail}`, 0, 0);
132
+ },
133
+ };
134
+ /** The empty_brain result is the JSON receipt text; there is no structured payload. */
135
+ function emptyBrainPayload(result) {
136
+ try {
137
+ const text = result.content.find((c) => c.type === "text")?.text ?? "";
138
+ const parsed = JSON.parse(text);
139
+ if (parsed !== null && typeof parsed === "object")
140
+ return parsed;
141
+ }
142
+ catch { /* a non-JSON receipt renders as a plain line */ }
143
+ return {};
144
+ }
145
+ export const emptyBrainRenderers = {
146
+ renderCall: (_args, theme) => callLine(theme, "empty_brain"),
147
+ renderResult(result, _options, theme, context) {
148
+ const payload = emptyBrainPayload(result);
149
+ if (result.isError || payload.error !== undefined) {
150
+ return new TruncatedText(theme.fg("error", `✂ brain refused to empty — ${payload.error ?? "unknown error"}`), 0, 0);
151
+ }
152
+ if (payload.status === "rollover_already_pending")
153
+ return new TruncatedText(theme.fg("dim", "✂ brain already being emptied"), 0, 0);
154
+ const lastWord = typeof context.args?.last_word === "string" && context.args.last_word !== "" ? context.args.last_word : undefined;
155
+ return {
156
+ invalidate() { },
157
+ render(width) {
158
+ const label = "✂ brain emptied";
159
+ const prefix = "── ";
160
+ const fill = Math.max(2, width - visibleWidth(prefix) - visibleWidth(label) - 1);
161
+ const lines = [theme.fg("dim", `${prefix}${label} ${"─".repeat(fill)}`)];
162
+ if (lastWord !== undefined)
163
+ lines.push(theme.fg("warning", theme.italic(`“${lastWord}”`)));
164
+ return lines;
165
+ },
166
+ };
167
+ },
168
+ };
@@ -4,6 +4,7 @@ import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
4
4
  import { VERSION, defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { registerBudget } from "./budget.js";
6
6
  import { output } from "./tool-result.js";
7
+ import { emptyBrainRenderers } from "./render.js";
7
8
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
8
9
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
10
  import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
@@ -209,6 +210,8 @@ export function registerContext(pi, settingsManager) {
209
210
  label: "Empty Brain",
210
211
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
211
212
  parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
213
+ renderCall: emptyBrainRenderers.renderCall,
214
+ renderResult: emptyBrainRenderers.renderResult,
212
215
  async execute(_id, params, _signal, _update, ctx) {
213
216
  if (!enabled)
214
217
  return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
@@ -1,5 +1,5 @@
1
1
  /** Pi transport for host-neutral operations. */
2
- import { type ExtensionAPI, type ExtensionToolContext } from "@earendil-works/pi-coding-agent";
2
+ import { type ExtensionAPI, type ExtensionToolContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
3
3
  import type { Static, TSchema } from "typebox";
4
4
  import { type Operation, type Outcome } from "../../src/tools/result.js";
5
5
  /** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
@@ -18,5 +18,7 @@ export type ToolNamespace = {
18
18
  };
19
19
  export declare const NOTES_NAMESPACE: ToolNamespace;
20
20
  export declare const HISTORY_NAMESPACE: ToolNamespace;
21
+ /** Optional TUI renderers; without them the host draws its default call line and receipt text. */
22
+ export type OperationRenderers<TParams extends TSchema> = Pick<ToolDefinition<TParams, undefined>, "renderCall" | "renderResult">;
21
23
  /** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
22
- export declare function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[]>(pi: ExtensionAPI, operation: Operation<TParams, TData, TRest>, run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData>>, namespace?: ToolNamespace): void;
24
+ export declare function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[]>(pi: ExtensionAPI, operation: Operation<TParams, TData, TRest>, run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData>>, namespace?: ToolNamespace, renderers?: OperationRenderers<TParams>): void;
@@ -19,7 +19,7 @@ function piOperationResult(render, outcome) {
19
19
  export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
20
20
  export const HISTORY_NAMESPACE = { name: "history", description: "What happened in this session, read-only. See the memory skill." };
21
21
  /** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
22
- export function registerOperation(pi, operation, run, namespace) {
22
+ export function registerOperation(pi, operation, run, namespace, renderers) {
23
23
  pi.registerTool(defineTool({
24
24
  name: operation.name,
25
25
  label: operation.label,
@@ -28,6 +28,7 @@ export function registerOperation(pi, operation, run, namespace) {
28
28
  outputSchema: operation.outputSchema,
29
29
  executionMode: operation.executionMode,
30
30
  ...(namespace ? { namespace } : {}),
31
+ ...renderers,
31
32
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
32
33
  return piOperationResult(operation.render, await run(params, ctx));
33
34
  },
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,89 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { initTheme } from "@earendil-works/pi-coding-agent";
4
+ import { stripTerminalSequences } from "@earendil-works/pi-tui";
5
+ import { emptyBrainRenderers, notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../plugins/pi/render.js";
6
+ import { success, wireResult } from "../src/tools/result.js";
7
+ /** Flat theme for content assertions; strikethrough marks its text so crumple stays visible. */
8
+ const flatTheme = {
9
+ fg: (_color, text) => text,
10
+ bold: (text) => text,
11
+ italic: (text) => text,
12
+ strikethrough: (text) => `~~${text}~~`,
13
+ };
14
+ function toolResult(outcome) {
15
+ return { content: [{ type: "text", text: "receipt" }], structuredContent: wireResult(outcome), isError: !outcome.ok, details: undefined };
16
+ }
17
+ function jsonResult(value, isError = false) {
18
+ return { content: [{ type: "text", text: JSON.stringify(value) }], isError, details: undefined };
19
+ }
20
+ function lines(component, width = 80) {
21
+ return component.render(width).map((line) => stripTerminalSequences(line).trimEnd()).join("\n");
22
+ }
23
+ test("notes_write collapsed: outcome, address and content size", () => {
24
+ const result = toolResult(success({ address: "@self/grudge.md", outcome: "created" }));
25
+ const component = notesWriteRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "@self/grudge.md", content: "hello" } });
26
+ assert.equal(lines(component), "wrote @self/grudge.md · 5 chars");
27
+ });
28
+ test("notes_write expanded: the written content follows the header", () => {
29
+ const result = toolResult(success({ address: "plan.md", outcome: "overwrote" }));
30
+ const component = notesWriteRenderers.renderResult(result, { expanded: true }, flatTheme, { args: { address: "plan.md", content: "one\ntwo" } });
31
+ assert.equal(lines(component), "wrote plan.md · overwrote · 7 chars\n\none\ntwo");
32
+ });
33
+ test("notes_update edited: collapsed peeks at the first added line", () => {
34
+ const result = toolResult(success({ address: "a.md", change_kind: "body", diff: " 1 old\n-2 gone\n+2 here" }));
35
+ const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md" } });
36
+ assert.equal(lines(component), "edited a.md · + here");
37
+ });
38
+ test("notes_update crumple: the address is struck through", () => {
39
+ const result = toolResult(success({ address: "@self/stale.md", change_kind: "metadata", diff: "" }));
40
+ const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "@self/stale.md", crumpled: true } });
41
+ assert.equal(lines(component), "✂ crumpled ~~@self/stale.md~~");
42
+ });
43
+ test("notes_update moved: both addresses stay on the line", () => {
44
+ const result = toolResult(success({ address: "@self/new.md", change_kind: "moved", diff: "rename a.md -> @self/new.md", rename_from: "a.md" }));
45
+ const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md", rename_to: "@self/new.md" } });
46
+ assert.equal(lines(component), "renamed a.md → @self/new.md");
47
+ });
48
+ test("notes_update unchanged keeps quiet", () => {
49
+ const result = toolResult(success({ address: "a.md", change_kind: "none", diff: "" }));
50
+ const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md" } });
51
+ assert.equal(lines(component), "unchanged a.md");
52
+ });
53
+ test("notes_read collapsed: size and a peek at the first line", () => {
54
+ const result = toolResult(success({ address: "@project/MAP.md", metadata: { origin: "self", created_at: "x", updated_at: "y", extra: {} }, text: "# MAP\n\nbody", total_chars: 11, next_offset_chars: null }));
55
+ const component = notesReadRenderers.renderResult(result, { expanded: false }, flatTheme);
56
+ assert.equal(lines(component), "read @project/MAP.md · 11 chars — # MAP");
57
+ });
58
+ test("notes_read expanded: truncation points at the next offset", () => {
59
+ const result = toolResult(success({ address: "a.md", metadata: { origin: "self", created_at: "x", updated_at: "y", extra: {} }, text: "part", total_chars: 10, next_offset_chars: 4 }));
60
+ const component = notesReadRenderers.renderResult(result, { expanded: true }, flatTheme);
61
+ assert.equal(lines(component), "read a.md · 10 chars · truncated — part\n\npart\n… continue at offset_chars=4");
62
+ });
63
+ test("refusals render as one error line with the code", () => {
64
+ const result = toolResult({ ok: false, error: { code: "not_found", message: "No note at x.md." } });
65
+ const component = notesReadRenderers.renderResult(result, { expanded: false }, flatTheme);
66
+ assert.equal(lines(component), "not_found: No note at x.md.");
67
+ });
68
+ test("results without a structured payload fall back to the receipt line", () => {
69
+ const result = { content: [{ type: "text", text: "created a.md" }], isError: false, details: undefined };
70
+ const component = notesWriteRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md", content: "x" } });
71
+ assert.equal(lines(component), "created a.md");
72
+ });
73
+ test("empty_brain: divider with the last word, refusals in one line", () => {
74
+ initTheme();
75
+ const ok = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_requested" }), { expanded: false }, flatTheme, { args: { last_word: "cake was worth it" } });
76
+ const rendered = lines(ok, 40).split("\n");
77
+ assert.match(rendered[0] ?? "", /^── ✂ brain emptied ─+$/);
78
+ assert.equal(rendered[1], "“cake was worth it”");
79
+ const refused = emptyBrainRenderers.renderResult(jsonResult({ error: "notesoup is off" }, true), { expanded: false }, flatTheme, { args: {} });
80
+ assert.equal(lines(refused), "✂ brain refused to empty — notesoup is off");
81
+ const pending = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_already_pending" }), { expanded: false }, flatTheme, { args: {} });
82
+ assert.equal(lines(pending), "✂ brain already being emptied");
83
+ });
84
+ test("notes_update expanded diff goes through the host's diff renderer", () => {
85
+ initTheme();
86
+ const result = toolResult(success({ address: "a.md", change_kind: "body", diff: " 1 old\n-2 gone\n+2 here" }));
87
+ const component = notesUpdateRenderers.renderResult(result, { expanded: true }, flatTheme, { args: { address: "a.md" } });
88
+ assert.equal(lines(component), "edited a.md · + here\n\n 1 old\n-2 gone\n+2 here");
89
+ });
package/package.json CHANGED
@@ -1,151 +1,156 @@
1
1
  {
2
- "name": "notesoup",
3
- "version": "0.51.8",
4
- "type": "module",
5
- "main": "./dist/src/index.js",
6
- "types": "./dist/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/src/index.d.ts",
10
- "import": "./dist/src/index.js"
11
- },
12
- "./notes": {
13
- "types": "./dist/src/notes/index.d.ts",
14
- "import": "./dist/src/notes/index.js"
15
- },
16
- "./package.json": "./package.json",
17
- "./dsh": {
18
- "types": "./dist/plugins/dsh/index.d.ts",
19
- "import": "./dist/plugins/dsh/index.js"
20
- },
21
- "./dsh/engine": {
22
- "types": "./dist/plugins/dsh/engine.d.ts",
23
- "import": "./dist/plugins/dsh/engine.js"
24
- }
25
- },
26
- "description": "Host-neutral notes, history and context-window core, with plugins for Pi, Claude Code and the DeepSeek Harness.",
27
- "license": "MIT",
28
- "keywords": [
29
- "pi-package",
30
- "pi-extension",
31
- "agent-memory",
32
- "notes"
33
- ],
34
- "repository": {
35
- "type": "git",
36
- "url": "https://github.com/astrosheep-zero/notesoup.git"
37
- },
38
- "pi": {
39
- "extensions": [
40
- "./plugins/pi/index.ts"
41
- ],
42
- "skills": [
43
- "./skills"
44
- ]
45
- },
46
- "files": [
47
- "src",
48
- "plugins",
49
- "dist",
50
- "docs",
51
- "LICENSE",
52
- "README.md",
53
- "playbook.md",
54
- "skills",
55
- "!plugins/claude/types",
56
- "!plugins/claude/tsconfig.json",
57
- "cordis.patch.yml"
58
- ],
59
- "bin": {
60
- "dream": "dist/plugins/pi/dream/cli.js"
61
- },
62
- "scripts": {
63
- "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node scripts/build-extension.mjs && node -e \"require('node:fs').chmodSync('dist/plugins/pi/dream/cli.js', 0o755)\"",
64
- "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p plugins/claude/tsconfig.json",
65
- "test": "npm run build && node --test --test-concurrency=4 $(ls dist/test/*.test.js | grep -v dist/test/claude-validation.test.js) && node --test dist/test/claude-validation.test.js",
66
- "prepublishOnly": "npm run typecheck",
67
- "prepack": "npm run build"
68
- },
69
- "peerDependencies": {
70
- "@earendil-works/pi-agent-core": "*",
71
- "@earendil-works/pi-ai": "*",
72
- "@earendil-works/pi-coding-agent": "*",
73
- "typebox": "*",
74
- "@deepseek-ai/cordis": "*",
75
- "@deepseek-ai/cordis-plugin-loader": "*",
76
- "@deepseek-ai/dsh-agent": "*",
77
- "@deepseek-ai/dsh-compaction": "*",
78
- "@deepseek-ai/dsh-commands": "*",
79
- "@deepseek-ai/dsh-llm": "*",
80
- "@deepseek-ai/dsh-session": "*",
81
- "@deepseek-ai/dsh-session-query": "*",
82
- "@deepseek-ai/dsh-system-prompt": "*",
83
- "@deepseek-ai/dsh-token-meter": "*",
84
- "@deepseek-ai/dsh-tools": "*"
85
- },
86
- "peerDependenciesMeta": {
87
- "@earendil-works/pi-agent-core": {
88
- "optional": true
89
- },
90
- "@earendil-works/pi-ai": {
91
- "optional": true
92
- },
93
- "@earendil-works/pi-coding-agent": {
94
- "optional": true
95
- },
96
- "typebox": {
97
- "optional": true
98
- },
99
- "@deepseek-ai/cordis": {
100
- "optional": true
101
- },
102
- "@deepseek-ai/cordis-plugin-loader": {
103
- "optional": true
104
- },
105
- "@deepseek-ai/dsh-agent": {
106
- "optional": true
107
- },
108
- "@deepseek-ai/dsh-compaction": {
109
- "optional": true
110
- },
111
- "@deepseek-ai/dsh-commands": {
112
- "optional": true
113
- },
114
- "@deepseek-ai/dsh-llm": {
115
- "optional": true
116
- },
117
- "@deepseek-ai/dsh-session": {
118
- "optional": true
119
- },
120
- "@deepseek-ai/dsh-session-query": {
121
- "optional": true
122
- },
123
- "@deepseek-ai/dsh-system-prompt": {
124
- "optional": true
125
- },
126
- "@deepseek-ai/dsh-token-meter": {
127
- "optional": true
128
- },
129
- "@deepseek-ai/dsh-tools": {
130
- "optional": true
131
- }
132
- },
133
- "devDependencies": {
134
- "@deepseek-ai/dsh": "0.2.1-alpha.2",
135
- "@earendil-works/pi-agent-core": "^1.0.0",
136
- "@earendil-works/pi-ai": "^1.0.0",
137
- "@earendil-works/pi-coding-agent": "^1.0.0",
138
- "@types/node": "^22.19.19",
139
- "esbuild": "^0.28.2",
140
- "typebox": "1.3.27",
141
- "typescript": "^5.9.3"
142
- },
143
- "publishConfig": {
144
- "access": "public"
145
- },
146
- "dsh": {
147
- "bundle": {
148
- "patch": "./cordis.patch.yml"
149
- }
150
- }
2
+ "name": "notesoup",
3
+ "version": "0.51.9",
4
+ "type": "module",
5
+ "main": "./dist/src/index.js",
6
+ "types": "./dist/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/src/index.d.ts",
10
+ "import": "./dist/src/index.js"
11
+ },
12
+ "./notes": {
13
+ "types": "./dist/src/notes/index.d.ts",
14
+ "import": "./dist/src/notes/index.js"
15
+ },
16
+ "./package.json": "./package.json",
17
+ "./dsh": {
18
+ "types": "./dist/plugins/dsh/index.d.ts",
19
+ "import": "./dist/plugins/dsh/index.js"
20
+ },
21
+ "./dsh/engine": {
22
+ "types": "./dist/plugins/dsh/engine.d.ts",
23
+ "import": "./dist/plugins/dsh/engine.js"
24
+ }
25
+ },
26
+ "description": "Host-neutral notes, history and context-window core, with plugins for Pi, Claude Code and the DeepSeek Harness.",
27
+ "license": "MIT",
28
+ "keywords": [
29
+ "pi-package",
30
+ "pi-extension",
31
+ "agent-memory",
32
+ "notes"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/astrosheep-zero/notesoup.git"
37
+ },
38
+ "pi": {
39
+ "extensions": [
40
+ "./plugins/pi/index.ts"
41
+ ],
42
+ "skills": [
43
+ "./skills"
44
+ ]
45
+ },
46
+ "files": [
47
+ "src",
48
+ "plugins",
49
+ "dist",
50
+ "docs",
51
+ "LICENSE",
52
+ "README.md",
53
+ "playbook.md",
54
+ "skills",
55
+ "!plugins/claude/types",
56
+ "!plugins/claude/tsconfig.json",
57
+ "cordis.patch.yml"
58
+ ],
59
+ "bin": {
60
+ "dream": "dist/plugins/pi/dream/cli.js"
61
+ },
62
+ "scripts": {
63
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node scripts/build-extension.mjs && node -e \"require('node:fs').chmodSync('dist/plugins/pi/dream/cli.js', 0o755)\"",
64
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p plugins/claude/tsconfig.json",
65
+ "test": "npm run build && node --test --test-concurrency=4 $(ls dist/test/*.test.js | grep -v dist/test/claude-validation.test.js) && node --test dist/test/claude-validation.test.js",
66
+ "prepublishOnly": "npm run typecheck",
67
+ "prepack": "npm run build"
68
+ },
69
+ "peerDependencies": {
70
+ "@earendil-works/pi-agent-core": "*",
71
+ "@earendil-works/pi-ai": "*",
72
+ "@earendil-works/pi-coding-agent": "*",
73
+ "@earendil-works/pi-tui": "*",
74
+ "typebox": "*",
75
+ "@deepseek-ai/cordis": "*",
76
+ "@deepseek-ai/cordis-plugin-loader": "*",
77
+ "@deepseek-ai/dsh-agent": "*",
78
+ "@deepseek-ai/dsh-compaction": "*",
79
+ "@deepseek-ai/dsh-commands": "*",
80
+ "@deepseek-ai/dsh-llm": "*",
81
+ "@deepseek-ai/dsh-session": "*",
82
+ "@deepseek-ai/dsh-session-query": "*",
83
+ "@deepseek-ai/dsh-system-prompt": "*",
84
+ "@deepseek-ai/dsh-token-meter": "*",
85
+ "@deepseek-ai/dsh-tools": "*"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "@earendil-works/pi-agent-core": {
89
+ "optional": true
90
+ },
91
+ "@earendil-works/pi-ai": {
92
+ "optional": true
93
+ },
94
+ "@earendil-works/pi-coding-agent": {
95
+ "optional": true
96
+ },
97
+ "@earendil-works/pi-tui": {
98
+ "optional": true
99
+ },
100
+ "typebox": {
101
+ "optional": true
102
+ },
103
+ "@deepseek-ai/cordis": {
104
+ "optional": true
105
+ },
106
+ "@deepseek-ai/cordis-plugin-loader": {
107
+ "optional": true
108
+ },
109
+ "@deepseek-ai/dsh-agent": {
110
+ "optional": true
111
+ },
112
+ "@deepseek-ai/dsh-compaction": {
113
+ "optional": true
114
+ },
115
+ "@deepseek-ai/dsh-commands": {
116
+ "optional": true
117
+ },
118
+ "@deepseek-ai/dsh-llm": {
119
+ "optional": true
120
+ },
121
+ "@deepseek-ai/dsh-session": {
122
+ "optional": true
123
+ },
124
+ "@deepseek-ai/dsh-session-query": {
125
+ "optional": true
126
+ },
127
+ "@deepseek-ai/dsh-system-prompt": {
128
+ "optional": true
129
+ },
130
+ "@deepseek-ai/dsh-token-meter": {
131
+ "optional": true
132
+ },
133
+ "@deepseek-ai/dsh-tools": {
134
+ "optional": true
135
+ }
136
+ },
137
+ "devDependencies": {
138
+ "@deepseek-ai/dsh": "0.2.1-alpha.2",
139
+ "@earendil-works/pi-agent-core": "^1.0.0",
140
+ "@earendil-works/pi-ai": "^1.0.0",
141
+ "@earendil-works/pi-coding-agent": "^1.0.0",
142
+ "@earendil-works/pi-tui": "1.0.0",
143
+ "@types/node": "^22.19.19",
144
+ "esbuild": "^0.28.2",
145
+ "typebox": "1.3.27",
146
+ "typescript": "^5.9.3"
147
+ },
148
+ "publishConfig": {
149
+ "access": "public"
150
+ },
151
+ "dsh": {
152
+ "bundle": {
153
+ "patch": "./cordis.patch.yml"
154
+ }
155
+ }
151
156
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.51.8",
3
+ "version": "0.51.9",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"
@@ -1,6 +1,7 @@
1
1
  import { generateDiffString, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../../../src/tools/notes.js";
3
3
  import { notesIdentityFromPi } from "./adapter.js";
4
+ import { notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../render.js";
4
5
  import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
5
6
  import type { NoteChange } from "../../../src/notes/index.js";
6
7
 
@@ -10,9 +11,9 @@ function renderDiff(change: NoteChange): string {
10
11
 
11
12
  /** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */
12
13
  export function registerNotesTools(pi: ExtensionAPI) {
13
- registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
14
- registerOperation(pi, notesUpdate, (params, ctx) => notesUpdate.execute(params, notesIdentityFromPi(ctx), renderDiff), NOTES_NAMESPACE);
15
- registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
14
+ registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
15
+ registerOperation(pi, notesUpdate, (params, ctx) => notesUpdate.execute(params, notesIdentityFromPi(ctx), renderDiff), NOTES_NAMESPACE, notesUpdateRenderers);
16
+ registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE, notesReadRenderers);
16
17
  registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
17
18
  registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, notesIdentityFromPi(ctx)), NOTES_NAMESPACE);
18
19
  }
@@ -0,0 +1,165 @@
1
+ /** Pi TUI renderers for notesoup's own tools: collapsed one-line slips, expandable bodies. */
2
+ import { renderDiff, type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
3
+ import { Text, TruncatedText, visibleWidth, type Component } from "@earendil-works/pi-tui";
4
+ import type { Static } from "typebox";
5
+ import type { NotesReadData, NotesUpdateData, NotesWriteData } from "../../src/tools/notes.js";
6
+ import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
7
+
8
+ /** Only the render-context members these renderers read; the host's ToolRenderContext satisfies this. */
9
+ type CallContext<TArgs> = { args: TArgs };
10
+
11
+ /** Expanded bodies show this many lines before a "more lines" marker; the full text is in the receipt. */
12
+ const EXPANDED_LINE_CAP = 80;
13
+
14
+ type WireError = { error: string; code: string };
15
+
16
+ /** structuredContent is wireResult(outcome): the data itself, or {error, code}. Old sessions may lack it. */
17
+ function wireOf<T>(result: AgentToolResult<undefined>): { data?: T; error?: WireError } {
18
+ const sc = result.structuredContent;
19
+ if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
20
+ const obj = sc as Record<string, unknown>;
21
+ if (typeof obj.error === "string") return { error: { error: obj.error, code: typeof obj.code === "string" ? obj.code : "error" } };
22
+ return { data: obj as T };
23
+ }
24
+ return {};
25
+ }
26
+
27
+ /** Results without a structured payload (resumed old sessions) fall back to the receipt's first line. */
28
+ function receiptFallback(result: AgentToolResult<undefined>, theme: Theme): Component {
29
+ const text = result.content.find((c) => c.type === "text")?.text ?? "";
30
+ return new TruncatedText(theme.fg("dim", text.split("\n")[0] ?? ""), 0, 0);
31
+ }
32
+
33
+ function errorComponent(theme: Theme, error: WireError, expanded: boolean): Component {
34
+ if (!expanded) return new TruncatedText(theme.fg("error", `${error.code}: ${error.error.split("\n")[0]}`), 0, 0);
35
+ return new Text(theme.fg("error", `${error.code}: ${error.error}`), 0, 0);
36
+ }
37
+
38
+ function addressText(theme: Theme, address: string): string {
39
+ return theme.fg("accent", address);
40
+ }
41
+
42
+ function callLine(theme: Theme, tool: string, target?: string, suffix = ""): Component {
43
+ let line = theme.fg("toolTitle", theme.bold(tool));
44
+ if (target !== undefined && target !== "") line += " " + addressText(theme, target);
45
+ if (suffix !== "") line += theme.fg("dim", suffix);
46
+ return new TruncatedText(line, 0, 0);
47
+ }
48
+
49
+ /** First `+` line of a generateDiffString diff, without its line-number prefix: the sentence just written down. */
50
+ function firstAddedLine(diff: string): string | undefined {
51
+ for (const line of diff.split("\n")) {
52
+ const match = /^\+(\s*\d*)?\s?(.*)$/.exec(line);
53
+ if (match) return match[2];
54
+ }
55
+ return undefined;
56
+ }
57
+
58
+ function boundedLines(text: string, theme: Theme): string {
59
+ const lines = text.split("\n");
60
+ if (lines.length <= EXPANDED_LINE_CAP) return text;
61
+ return `${lines.slice(0, EXPANDED_LINE_CAP).join("\n")}\n${theme.fg("dim", `… ${lines.length - EXPANDED_LINE_CAP} more lines`)}`;
62
+ }
63
+
64
+ export type NotesWriteArgs = Static<typeof notesWriteParameters>;
65
+ export const notesWriteRenderers = {
66
+ renderCall: (args: NotesWriteArgs, theme: Theme): Component => callLine(theme, "notes_write", args.address),
67
+ renderResult(result: AgentToolResult<undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesWriteArgs>): Component {
68
+ const { data, error } = wireOf<NotesWriteData>(result);
69
+ if (error) return errorComponent(theme, error, options.expanded);
70
+ if (!data) return receiptFallback(result, theme);
71
+ const content = typeof context.args?.content === "string" ? context.args.content : "";
72
+ const qualifier = data.outcome === "created" ? "" : theme.fg("dim", ` · ${data.outcome}`);
73
+ const head = `wrote ${addressText(theme, data.address)}${qualifier}${theme.fg("dim", ` · ${Array.from(content).length} chars`)}`;
74
+ if (!options.expanded) return new TruncatedText(head, 0, 0);
75
+ return new Text(`${head}\n\n${boundedLines(content, theme)}`, 0, 0);
76
+ },
77
+ };
78
+
79
+ export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
80
+ export const notesUpdateRenderers = {
81
+ renderCall(args: NotesUpdateArgs, theme: Theme): Component {
82
+ let suffix = "";
83
+ if (args.crumpled === true) suffix = " · crumple";
84
+ else if (args.crumpled === false) suffix = " · restore";
85
+ if (typeof args.rename_to === "string" && args.rename_to !== "") suffix += ` → ${args.rename_to}`;
86
+ return callLine(theme, "notes_update", args.address, suffix);
87
+ },
88
+ renderResult(result: AgentToolResult<undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesUpdateArgs>): Component {
89
+ const { data, error } = wireOf<NotesUpdateData>(result);
90
+ if (error) return errorComponent(theme, error, options.expanded);
91
+ if (!data) return receiptFallback(result, theme);
92
+ let head: string;
93
+ if (context.args?.crumpled === true) {
94
+ head = `✂ crumpled ${theme.strikethrough(theme.fg("dim", data.address))}`;
95
+ } else if (context.args?.crumpled === false) {
96
+ head = `restored ${addressText(theme, data.address)}`;
97
+ } else if (data.change_kind === "moved") {
98
+ head = `renamed ${theme.fg("dim", data.rename_from ?? "?")}${theme.fg("dim", " → ")}${addressText(theme, data.address)}`;
99
+ } else if (data.change_kind === "none") {
100
+ head = theme.fg("dim", "unchanged ") + addressText(theme, data.address);
101
+ } else {
102
+ head = `edited ${addressText(theme, data.address)}`;
103
+ const peek = firstAddedLine(data.diff);
104
+ if (peek !== undefined && peek !== "") head += theme.fg("dim", " · ") + theme.fg("toolDiffAdded", `+ ${peek}`);
105
+ }
106
+ if (!options.expanded) return new TruncatedText(head, 0, 0);
107
+ const parts = [head];
108
+ if (data.diff !== "") parts.push("", renderDiff(data.diff));
109
+ if (data.change_kind !== "moved" && data.rename_from !== undefined) parts.push(theme.fg("dim", `renamed from ${data.rename_from}`));
110
+ return new Text(parts.join("\n"), 0, 0);
111
+ },
112
+ };
113
+
114
+ export type NotesReadArgs = Static<typeof notesReadParameters>;
115
+ export const notesReadRenderers = {
116
+ renderCall: (args: NotesReadArgs, theme: Theme): Component =>
117
+ callLine(theme, "notes_read", args.address, args.offset_chars !== undefined && args.offset_chars !== 0 ? ` · offset ${args.offset_chars}` : ""),
118
+ renderResult(result: AgentToolResult<undefined>, options: { expanded: boolean }, theme: Theme): Component {
119
+ const { data, error } = wireOf<NotesReadData>(result);
120
+ if (error) return errorComponent(theme, error, options.expanded);
121
+ if (!data) return receiptFallback(result, theme);
122
+ const truncated = data.next_offset_chars !== null;
123
+ let head = `read ${addressText(theme, data.address)}${theme.fg("dim", ` · ${data.total_chars} chars${truncated ? " · truncated" : ""}`)}`;
124
+ const peek = data.text.split("\n").find((line) => line.trim() !== "");
125
+ if (peek !== undefined) head += theme.fg("dim", ` — ${peek.trim()}`);
126
+ if (!options.expanded) return new TruncatedText(head, 0, 0);
127
+ const tail = truncated ? `\n${theme.fg("dim", `… continue at offset_chars=${data.next_offset_chars}`)}` : "";
128
+ return new Text(`${head}\n\n${boundedLines(data.text, theme)}${tail}`, 0, 0);
129
+ },
130
+ };
131
+
132
+ export type EmptyBrainArgs = { last_word?: string };
133
+
134
+ /** The empty_brain result is the JSON receipt text; there is no structured payload. */
135
+ function emptyBrainPayload(result: AgentToolResult<unknown>): { status?: string; error?: string } {
136
+ try {
137
+ const text = result.content.find((c) => c.type === "text")?.text ?? "";
138
+ const parsed: unknown = JSON.parse(text);
139
+ if (parsed !== null && typeof parsed === "object") return parsed as { status?: string; error?: string };
140
+ } catch { /* a non-JSON receipt renders as a plain line */ }
141
+ return {};
142
+ }
143
+
144
+ export const emptyBrainRenderers = {
145
+ renderCall: (_args: EmptyBrainArgs, theme: Theme): Component => callLine(theme, "empty_brain"),
146
+ renderResult(result: AgentToolResult<unknown>, _options: { expanded: boolean }, theme: Theme, context: CallContext<EmptyBrainArgs>): Component {
147
+ const payload = emptyBrainPayload(result);
148
+ if (result.isError || payload.error !== undefined) {
149
+ return new TruncatedText(theme.fg("error", `✂ brain refused to empty — ${payload.error ?? "unknown error"}`), 0, 0);
150
+ }
151
+ if (payload.status === "rollover_already_pending") return new TruncatedText(theme.fg("dim", "✂ brain already being emptied"), 0, 0);
152
+ const lastWord = typeof context.args?.last_word === "string" && context.args.last_word !== "" ? context.args.last_word : undefined;
153
+ return {
154
+ invalidate() {},
155
+ render(width: number): string[] {
156
+ const label = "✂ brain emptied";
157
+ const prefix = "── ";
158
+ const fill = Math.max(2, width - visibleWidth(prefix) - visibleWidth(label) - 1);
159
+ const lines = [theme.fg("dim", `${prefix}${label} ${"─".repeat(fill)}`)];
160
+ if (lastWord !== undefined) lines.push(theme.fg("warning", theme.italic(`“${lastWord}”`)));
161
+ return lines;
162
+ },
163
+ };
164
+ },
165
+ };
@@ -4,6 +4,7 @@ import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
4
4
  import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type SettingsManager } from "@earendil-works/pi-coding-agent";
5
5
  import { registerBudget } from "./budget.js";
6
6
  import { output } from "./tool-result.js";
7
+ import { emptyBrainRenderers } from "./render.js";
7
8
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
8
9
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
10
  import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
@@ -205,6 +206,8 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
205
206
  label: "Empty Brain",
206
207
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
207
208
  parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
209
+ renderCall: emptyBrainRenderers.renderCall,
210
+ renderResult: emptyBrainRenderers.renderResult,
208
211
  async execute(_id, params, _signal, _update, ctx) {
209
212
  if (!enabled) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
210
213
  const lastWord = sanitizeLastWord(params.last_word);
@@ -1,5 +1,5 @@
1
1
  /** Pi transport for host-neutral operations. */
2
- import { defineTool, type ExtensionAPI, type ExtensionToolContext } from "@earendil-works/pi-coding-agent";
2
+ import { defineTool, type ExtensionAPI, type ExtensionToolContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
3
3
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
4
4
  import type { JsonValue } from "@earendil-works/pi-ai";
5
5
  import type { Static, TSchema } from "typebox";
@@ -26,12 +26,16 @@ export type ToolNamespace = { name: string; description: string };
26
26
  export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
27
27
  export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "What happened in this session, read-only. See the memory skill." };
28
28
 
29
+ /** Optional TUI renderers; without them the host draws its default call line and receipt text. */
30
+ export type OperationRenderers<TParams extends TSchema> = Pick<ToolDefinition<TParams, undefined>, "renderCall" | "renderResult">;
31
+
29
32
  /** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
30
33
  export function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[]>(
31
34
  pi: ExtensionAPI,
32
35
  operation: Operation<TParams, TData, TRest>,
33
36
  run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData>>,
34
37
  namespace?: ToolNamespace,
38
+ renderers?: OperationRenderers<TParams>,
35
39
  ): void {
36
40
  pi.registerTool(defineTool<TParams, undefined>({
37
41
  name: operation.name,
@@ -41,6 +45,7 @@ export function registerOperation<TParams extends TSchema, TData, TRest extends
41
45
  outputSchema: operation.outputSchema,
42
46
  executionMode: operation.executionMode,
43
47
  ...(namespace ? { namespace } : {}),
48
+ ...renderers,
44
49
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
45
50
  return piOperationResult(operation.render, await run(params, ctx));
46
51
  },