notesoup 0.44.0 → 0.45.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 (78) hide show
  1. package/README.md +1 -0
  2. package/cordis.patch.yml +14 -0
  3. package/dist/src/boot/text.d.ts +7 -0
  4. package/dist/src/boot/text.js +7 -0
  5. package/dist/src/claude/helper.js +3 -8
  6. package/dist/src/dsh/budget.d.ts +20 -0
  7. package/dist/src/dsh/budget.js +34 -0
  8. package/dist/src/dsh/engine.d.ts +28 -0
  9. package/dist/src/dsh/engine.js +226 -0
  10. package/dist/src/dsh/history.d.ts +6 -0
  11. package/dist/src/dsh/history.js +73 -0
  12. package/dist/src/dsh/index.d.ts +22 -0
  13. package/dist/src/dsh/index.js +63 -0
  14. package/dist/src/dsh/tools.d.ts +3 -0
  15. package/dist/src/dsh/tools.js +111 -0
  16. package/dist/src/dsh/window.d.ts +46 -0
  17. package/dist/src/dsh/window.js +122 -0
  18. package/dist/src/notes/index.d.ts +4 -2
  19. package/dist/src/notes/index.js +4 -1
  20. package/dist/src/notes/paths.d.ts +0 -1
  21. package/dist/src/notes/paths.js +0 -1
  22. package/dist/src/pi/boot.d.ts +0 -5
  23. package/dist/src/pi/boot.js +4 -30
  24. package/dist/src/pi/budget.js +3 -3
  25. package/dist/src/pi/notes/adapter.d.ts +1 -1
  26. package/dist/src/pi/notes/adapter.js +1 -1
  27. package/dist/src/pi/runtime.js +28 -3
  28. package/dist/src/pi/tool-result.d.ts +9 -0
  29. package/dist/src/pi/tool-result.js +4 -0
  30. package/dist/src/tools/notes.d.ts +1 -1
  31. package/dist/src/tools/notes.js +1 -1
  32. package/dist/src/tools/output.d.ts +1 -14
  33. package/dist/src/tools/output.js +1 -9
  34. package/dist/test/dependencies.test.js +63 -1
  35. package/dist/test/dsh-cli.test.d.ts +1 -0
  36. package/dist/test/dsh-cli.test.js +44 -0
  37. package/dist/test/dsh-compaction-parity.test.d.ts +1 -0
  38. package/dist/test/dsh-compaction-parity.test.js +143 -0
  39. package/dist/test/dsh.test.d.ts +1 -0
  40. package/dist/test/dsh.test.js +323 -0
  41. package/dist/test/helpers/dependency-graph.d.ts +3 -3
  42. package/dist/test/helpers/dependency-graph.js +64 -14
  43. package/dist/test/helpers/dsh-messages.d.ts +29 -0
  44. package/dist/test/helpers/dsh-messages.js +33 -0
  45. package/dist/test/helpers/dsh.d.ts +17 -0
  46. package/dist/test/helpers/dsh.js +50 -0
  47. package/dist/test/helpers/extension.js +2 -2
  48. package/dist/test/host-neutral.test.js +5 -0
  49. package/dist/test/notes.integration.test.js +4 -4
  50. package/dist/test/notes.test.js +1 -1
  51. package/docs/architecture.md +4 -1
  52. package/docs/dsh.md +61 -0
  53. package/docs/dsh.profile.patch.yml +34 -0
  54. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  55. package/mods/notesoup/dist/claude/helper.js +649 -651
  56. package/package.json +63 -4
  57. package/src/boot/text.ts +8 -0
  58. package/src/claude/helper.ts +3 -10
  59. package/src/dsh/budget.ts +35 -0
  60. package/src/dsh/engine.ts +186 -0
  61. package/src/dsh/history.ts +57 -0
  62. package/src/dsh/index.ts +69 -0
  63. package/src/dsh/tools.ts +106 -0
  64. package/src/dsh/window.ts +124 -0
  65. package/src/notes/index.ts +4 -2
  66. package/src/notes/paths.ts +0 -1
  67. package/src/pi/boot.ts +4 -33
  68. package/src/pi/budget.ts +3 -3
  69. package/src/pi/notes/adapter.ts +1 -2
  70. package/src/pi/notes/tools.ts +1 -1
  71. package/src/pi/runtime.ts +31 -3
  72. package/src/pi/tool-result.ts +5 -0
  73. package/src/tools/notes.ts +1 -1
  74. package/src/tools/output.ts +1 -10
  75. package/dist/src/pi/tool-names.d.ts +0 -7
  76. package/dist/src/pi/tool-names.js +0 -7
  77. package/mods/pi-context/dist/claude/helper.js +0 -9324
  78. package/src/pi/tool-names.ts +0 -9
@@ -0,0 +1,124 @@
1
+ import type { Agent } from "@deepseek-ai/dsh-agent";
2
+ import { appendPluginRecord, pluginRecordOf, type Session, type SessionEvent } from "@deepseek-ai/dsh-session";
3
+ import { isCompactCheckpointSource } from "@deepseek-ai/dsh-compaction";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { createHash } from "node:crypto";
7
+ import { loadNotesSnapshot } from "../boot/snapshot.js";
8
+ import { renderBootBlock } from "../boot/render.js";
9
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
10
+ import { CONTINUATION } from "../budget/text.js";
11
+ import { contentText } from "../history/history.js";
12
+ import { projectKey, slugify, snapshotNotesIdentity, type NotesIdentity } from "../notes/index.js";
13
+
14
+ export const WINDOW_RECORD = "plugin:notesoup/window";
15
+ export const BOOT_SECTION = "notesoup:boot";
16
+ const BOOT_OPEN = "<notesoup-boot>\n";
17
+ const BOOT_CLOSE = "\n</notesoup-boot>";
18
+ const CHECKPOINT_END = "\n\n<notesoup-continuation>\n";
19
+ export type WindowSnapshot = Readonly<{ version: 1; window: number; windowId: string; openedAt: number; boot: string; notesDigest: string }>;
20
+ export type WindowState = { snapshot: WindowSnapshot; pendingReset: boolean; warned: boolean; reminded: boolean };
21
+ export type NotesConfig = { notesHome?: string; agentName?: string };
22
+
23
+ export function restoreWarnings(state: WindowState, events: readonly SessionEvent[]): void {
24
+ state.warned = false;
25
+ state.reminded = false;
26
+ for (const event of events) {
27
+ if (event.type === "user/message" && event.data.source.kind === "notesoup-budget" && event.data.source.windowId === state.snapshot.windowId) {
28
+ if (event.data.source.phase === "warning") state.warned = true;
29
+ else state.reminded = true;
30
+ }
31
+ }
32
+ }
33
+
34
+ declare module "@deepseek-ai/dsh-session/types" {
35
+ interface PluginRecordMap { "plugin:notesoup/window": WindowSnapshot }
36
+ }
37
+
38
+ export function windowId(sessionId: string, window: number): string { return `dsh:${sessionId}:${window}`; }
39
+ function digest(boot: string): string { return createHash("sha256").update(boot).digest("hex"); }
40
+ export function checkpointText(snapshot: WindowSnapshot): string { return snapshot.boot + CHECKPOINT_END + CONTINUATION + "\n</notesoup-continuation>"; }
41
+
42
+ export function recordSnapshot(event: SessionEvent): WindowSnapshot | undefined {
43
+ const record = pluginRecordOf(event);
44
+ if (record?.type !== WINDOW_RECORD || typeof record.data !== "object" || record.data === null) return undefined;
45
+ const value = record.data as Partial<WindowSnapshot>;
46
+ if (value.version !== 1 || !Number.isSafeInteger(value.window) || value.window! < 0 || typeof value.windowId !== "string" || typeof value.openedAt !== "number" || typeof value.boot !== "string" || value.notesDigest !== digest(value.boot)) return undefined;
47
+ return Object.freeze(value as WindowSnapshot);
48
+ }
49
+
50
+ /** The checkpoint is authoritative when an ignorable record was lost or the transaction's close failed. */
51
+ export function checkpointSnapshot(event: SessionEvent): WindowSnapshot | undefined {
52
+ if (event.type !== "user/message" || !isCompactCheckpointSource(event.data.source)) return undefined;
53
+ const text = contentText(event.data.content);
54
+ const end = text.lastIndexOf(CHECKPOINT_END);
55
+ if (end < 0 || !text.startsWith(BOOT_OPEN)) return undefined;
56
+ return snapshotFromBoot(text.slice(0, end), event.time);
57
+ }
58
+
59
+ function systemSnapshot(event: SessionEvent): WindowSnapshot | undefined {
60
+ if (event.type !== "system/message") return undefined;
61
+ const text = contentText(event.data.message.content);
62
+ const start = text.indexOf(BOOT_OPEN);
63
+ const end = text.lastIndexOf(BOOT_CLOSE);
64
+ if (start < 0 || end < 0) return undefined;
65
+ return snapshotFromBoot(text.slice(start, end + BOOT_CLOSE.length), event.time);
66
+ }
67
+
68
+ function snapshotFromBoot(boot: string, openedAt: number): WindowSnapshot | undefined {
69
+ const id = /^Current context window id: (dsh:.*:(\d+))$/m.exec(boot);
70
+ if (!id || !Number.isSafeInteger(Number(id[2]))) return undefined;
71
+ return Object.freeze({ version: 1, window: Number(id[2]), windowId: id[1]!, openedAt, boot, notesDigest: digest(boot) });
72
+ }
73
+
74
+ export function recoverSnapshot(events: readonly SessionEvent[]): WindowSnapshot | undefined {
75
+ let latest: WindowSnapshot | undefined;
76
+ for (const event of events) {
77
+ const candidate = checkpointSnapshot(event) ?? recordSnapshot(event) ?? systemSnapshot(event);
78
+ if (candidate && (!latest || candidate.window >= latest.window)) latest = candidate;
79
+ }
80
+ return latest;
81
+ }
82
+
83
+ /** Identity is extracted here, never in the filesystem domain. */
84
+ export function notesIdentity(agent: Pick<Agent, "session" | "options">, config: NotesConfig): NotesIdentity {
85
+ const home = config.notesHome ?? join(homedir(), ".agents", "notes");
86
+ return snapshotNotesIdentity({
87
+ home,
88
+ sessionId: agent.session.id,
89
+ projectKey: projectKey(agent.session.header.cwd ?? process.cwd(), home),
90
+ agent: slugify(config.agentName ?? "dsh"),
91
+ model: slugify(agent.session.requestHeader()?.config.model ?? agent.options.model ?? "unknown"),
92
+ });
93
+ }
94
+
95
+ /** Engine-owned, per-session state; prompt reads are synchronous and never read notes again. */
96
+ export class Windows {
97
+ private states = new WeakMap<Session, WindowState>();
98
+ constructor(readonly config: NotesConfig) {}
99
+ get(session: Session): WindowState {
100
+ const state = this.states.get(session);
101
+ if (!state) throw Object.assign(new Error("notesoup: window missing; initialize at agent/created before sending a request."), { code: "WINDOW_MISSING" });
102
+ return state;
103
+ }
104
+ async adopt(agent: Agent, signal?: AbortSignal): Promise<WindowState> {
105
+ const existing = this.states.get(agent.session);
106
+ if (existing) return existing;
107
+ const restored = recoverSnapshot(agent.session.snapshotEvents());
108
+ const snapshot = restored ?? await this.mint(agent, 0, agent.session.header.createdAt);
109
+ signal?.throwIfAborted();
110
+ if (!restored) appendPluginRecord(agent.session, WINDOW_RECORD, snapshot);
111
+ const state = { snapshot, pendingReset: false, warned: false, reminded: false };
112
+ restoreWarnings(state, agent.session.snapshotEvents());
113
+ this.states.set(agent.session, state);
114
+ return state;
115
+ }
116
+ async mint(agent: Pick<Agent, "session" | "options">, window: number, openedAt: number): Promise<WindowSnapshot> {
117
+ const identity = notesIdentity(agent, this.config);
118
+ const notes = await loadNotesSnapshot(identity, openedAt);
119
+ const previous = this.states.get(agent.session)?.snapshot;
120
+ const firstWindowId = previous?.boot.match(/^First context window id: (.+)$/m)?.[1] ?? windowId(agent.session.id, 0);
121
+ const boot = BOOT_OPEN + renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId, currentWindowId: windowId(agent.session.id, window), ...(window ? { previousWindowId: previous?.windowId ?? windowId(agent.session.id, window - 1) } : {}), notes, tools: DEFAULT_BOOT_TOOL_NAMES }) + BOOT_CLOSE;
122
+ return Object.freeze({ version: 1, window, windowId: windowId(agent.session.id, window), openedAt, boot, notesDigest: digest(boot) });
123
+ }
124
+ }
@@ -1,7 +1,9 @@
1
1
  export { createNotesStore, noteIdentity } from "./store.js";
2
2
  export { NoteError, type NoteErrorCode } from "./errors.js";
3
- export { projectKey, slugify } from "./paths.js";
4
- export type { NotesIdentity } from "./identity.js";
3
+ export { projectKey } from "./project-home.js";
4
+ export { slugify } from "./paths.js";
5
+ export { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
6
+ export { isFilesystemError } from "./fs-error.js";
5
7
  export type {
6
8
  EditOperation,
7
9
  EditOptions,
@@ -1,6 +1,5 @@
1
1
  import { readdir } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
- export { projectKey } from "./project-home.js";
4
3
  import { NoteError, shown } from "./errors.js";
5
4
  import type { NotesIdentity } from "./identity.js";
6
5
 
package/src/pi/boot.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { PI_TOOL_NAMES } from "./tool-names.js";
1
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
2
2
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
4
4
  import { loadNotesSnapshot, unavailableNotesSnapshot, type NotesSnapshot } from "../boot/snapshot.js";
5
- import { isFilesystemError } from "../notes/fs-error.js";
5
+ import { isFilesystemError } from "../notes/index.js";
6
6
  import { BOOT_TYPE } from "./entries.js";
7
7
  import { renderBootBlock } from "../boot/render.js";
8
- import { currentReset, currentWindowId, isWindowBoot, rootWindowId } from "./window.js";
9
- import { repairResetTail } from "./reset/artifacts.js";
8
+ import { rootWindowId } from "./window.js";
10
9
 
11
10
  export type IncompleteNotesNotifier = (ctx: ExtensionContext, windowId: string, snapshot: NotesSnapshot) => void;
12
11
 
@@ -43,7 +42,7 @@ export async function buildBootMessage(
43
42
  if (isCurrent()) notifyIncompleteNotes?.(ctx, windowId, notes);
44
43
  return {
45
44
  customType: BOOT_TYPE,
46
- content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
45
+ content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: DEFAULT_BOOT_TOOL_NAMES }),
47
46
  display: false,
48
47
  details: { windowId },
49
48
  };
@@ -56,31 +55,3 @@ export function sendBoot(pi: ExtensionAPI, boot: BootMessage): void {
56
55
  { triggerTurn: false },
57
56
  );
58
57
  }
59
-
60
- /**
61
- * Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
62
- * boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
63
- */
64
- export async function ensureBoot(
65
- pi: ExtensionAPI,
66
- ctx: ExtensionContext,
67
- notifyIncompleteNotes?: IncompleteNotesNotifier,
68
- isCurrent: () => boolean = () => true,
69
- ): Promise<void> {
70
- const sessionId = ctx.sessionManager.getSessionId();
71
- const reset = currentReset(ctx);
72
- const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
73
- const stillCurrent = () => isCurrent() &&
74
- ctx.signal?.aborted !== true &&
75
- ctx.sessionManager.getSessionId() === sessionId &&
76
- currentWindowId(ctx) === windowId;
77
- if (reset) {
78
- await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
79
- return;
80
- }
81
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
82
- const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
83
- if (!stillCurrent()) return;
84
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
85
- sendBoot(pi, boot);
86
- }
package/src/pi/budget.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PI_TOOL_NAMES } from "./tool-names.js";
1
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
2
2
  import { remainingBudget, type ResolvedThresholds } from "../budget/policy.js";
3
3
  import { Type } from "@earendil-works/pi-ai";
4
4
  import { defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
@@ -8,7 +8,7 @@ import { readThresholdSettings, type ThresholdSettingsResolution } from "./thres
8
8
  import { currentWindowId, hasWindowMessage, isWindowMarker, rootWindowId, windowUsage } from "./window.js";
9
9
  import { tokenBudgetGuidance } from "../budget/text.js";
10
10
  import { arrangeAnchoredReminders, type AnchorDetails } from "./anchored.js";
11
- import { output } from "../tools/output.js";
11
+ import { output } from "./tool-result.js";
12
12
 
13
13
  /** Remaining tokens in the provider's active window, or null without a usable estimate. */
14
14
  function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">): number | null {
@@ -147,7 +147,7 @@ export function registerBudget(
147
147
  if (hasWindowMessage(ctx, GUIDANCE_TYPE)) return result();
148
148
  if (pendingGuidance?.windowId !== windowId) {
149
149
  if (remaining > reminder) return result();
150
- pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, PI_TOOL_NAMES.wipe) };
150
+ pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
151
151
  }
152
152
  return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
153
153
  });
@@ -1,8 +1,7 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { homedir } from "node:os";
3
3
  import { join, resolve } from "node:path";
4
- import type { NotesIdentity } from "../../notes/identity.js";
5
- import { projectKey, slugify } from "../../notes/paths.js";
4
+ import { projectKey, slugify, type NotesIdentity } from "../../notes/index.js";
6
5
 
7
6
  /** Pi's default notes root; environment access stays on the host side of the library boundary. */
8
7
  export function notesRoot(): string {
@@ -2,7 +2,7 @@ import { generateDiffString, type ExtensionAPI } from "@earendil-works/pi-coding
2
2
  import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../../tools/notes.js";
3
3
  import { notesIdentityFromPi } from "./adapter.js";
4
4
  import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
5
- import type { NoteChange } from "../../notes/store.js";
5
+ import type { NoteChange } from "../../notes/index.js";
6
6
 
7
7
  function renderDiff(change: NoteChange): string {
8
8
  return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
package/src/pi/runtime.ts CHANGED
@@ -3,13 +3,13 @@ import { resetBoundaryCommitted } from "./reset/committed.js";
3
3
  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
- import { output } from "../tools/output.js";
6
+ import { output } from "./tool-result.js";
7
7
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
8
8
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
- import { buildResetDrafts } from "./reset/artifacts.js";
9
+ import { buildResetDrafts, repairResetTail } from "./reset/artifacts.js";
10
10
  import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
11
11
  import { WARNING_CONTENT } from "../budget/text.js";
12
- import { ensureBoot, type IncompleteNotesNotifier } from "./boot.js";
12
+ import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
13
13
  import { errorMessage } from "../error-message.js";
14
14
 
15
15
  function readPackageVersion(): string {
@@ -26,6 +26,34 @@ function branchHasWindowMarker(ctx: ExtensionContext, fromId?: string): boolean
26
26
  return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
27
27
  }
28
28
 
29
+ /**
30
+ * Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
31
+ * boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
32
+ */
33
+ async function ensureBoot(
34
+ pi: ExtensionAPI,
35
+ ctx: ExtensionContext,
36
+ notifyIncompleteNotes?: IncompleteNotesNotifier,
37
+ isCurrent: () => boolean = () => true,
38
+ ): Promise<void> {
39
+ const sessionId = ctx.sessionManager.getSessionId();
40
+ const reset = currentReset(ctx);
41
+ const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
42
+ const stillCurrent = () => isCurrent() &&
43
+ ctx.signal?.aborted !== true &&
44
+ ctx.sessionManager.getSessionId() === sessionId &&
45
+ currentWindowId(ctx) === windowId;
46
+ if (reset) {
47
+ await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
48
+ return;
49
+ }
50
+ if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
51
+ const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
52
+ if (!stillCurrent()) return;
53
+ if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
54
+ sendBoot(pi, boot);
55
+ }
56
+
29
57
  /** Register the context-window runtime and its context-owned commands/tools. */
30
58
  export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
31
59
  let enabled = true;
@@ -5,6 +5,11 @@ import type { JsonValue } from "@earendil-works/pi-ai";
5
5
  import type { Static, TSchema } from "typebox";
6
6
  import { wireResult, type Operation, type Outcome, type Renderer } from "../tools/result.js";
7
7
 
8
+ /** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
9
+ export function output(value: unknown, details?: unknown, terminate = false) {
10
+ return { content: [{ type: "text" as const, text: JSON.stringify(value) }], details, terminate };
11
+ }
12
+
8
13
  /** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
9
14
  function piOperationResult<TData>(render: Renderer<TData>, outcome: Outcome<TData>): AgentToolResult<undefined> {
10
15
  return {
@@ -258,7 +258,7 @@ export const notesUpdate = {
258
258
  name: "notes_update", label: "Notes update",
259
259
  description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
260
260
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
261
- async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string): Promise<Outcome<NotesUpdateData>> {
261
+ async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
262
262
  try {
263
263
  const store = createNotesStore(identity);
264
264
  // Empty filler is not a request: models that pass every parameter get the edit path.
@@ -1,4 +1,4 @@
1
- /** Budget primitives. Notes/history use result.ts; reset/budget tools retain output(). */
1
+ /** Shared output budget primitives. */
2
2
  export const TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
3
3
  /** The per-call limit as the model reads it in refusals. */
4
4
  export const TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
@@ -21,12 +21,3 @@ export function prefixFit(text: string, fits: (content: string) => boolean): str
21
21
  }
22
22
  return chars.slice(0, low).join("");
23
23
  }
24
-
25
- /**
26
- * Encode a structured result through the common tool result boundary. `details` is slim
27
- * metadata for logs/UI (pi convention: never a second copy of the payload) and stays
28
- * undefined unless the tool has metadata worth persisting.
29
- */
30
- export function output(value: unknown, details?: unknown, terminate = false) {
31
- return { content: [{ type: "text" as const, text: JSON.stringify(value) }], details, terminate };
32
- }
@@ -1,7 +0,0 @@
1
- export declare const PI_TOOL_NAMES: {
2
- readonly notes: "notes_*";
3
- readonly notesList: "notes_list";
4
- readonly history: "history_*";
5
- readonly remaining: "get_context_remaining";
6
- readonly wipe: "clear_memory";
7
- };
@@ -1,7 +0,0 @@
1
- export const PI_TOOL_NAMES = {
2
- notes: "notes_*",
3
- notesList: "notes_list",
4
- history: "history_*",
5
- remaining: "get_context_remaining",
6
- wipe: "clear_memory",
7
- };