notesoup 0.51.3 → 0.51.4

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.
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+
3
+ export const NOTES_OP_KIND = "notes-op";
4
+ export const NOTES_OP_TOOLS = ["notes_read", "notes_write", "notes_update"] as const;
5
+ export type NotesOpTool = (typeof NOTES_OP_TOOLS)[number];
6
+
7
+ /** Card data stays small: the plugin timeline refuses payloads over 64 KB. */
8
+ export const READ_TEXT_MAX_CHARS = 4000;
9
+ export const DIFF_MAX_CHARS = 8000;
10
+ export const PREVIEW_MAX_CHARS = 4000;
11
+
12
+ export const notesOpSchema = z.object({
13
+ op: z.enum(["read", "write", "update"]),
14
+ address: z.string(),
15
+ status: z.enum(["running", "completed", "failed"]),
16
+ error: z.string().optional(),
17
+ // read
18
+ text: z.string().optional(),
19
+ totalChars: z.number().optional(),
20
+ // write
21
+ outcome: z.string().optional(),
22
+ preview: z.string().optional(),
23
+ // update
24
+ changeKind: z.string().optional(),
25
+ diff: z.string().optional(),
26
+ renamedFrom: z.string().optional(),
27
+ truncated: z.boolean().optional(),
28
+ });
29
+ export type NotesOp = z.infer<typeof notesOpSchema>;
@@ -0,0 +1,129 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { notesOpTransformer } from "../client/notes-op-transformer.ts";
4
+ import { DIFF_MAX_CHARS, PREVIEW_MAX_CHARS, READ_TEXT_MAX_CHARS, notesOpSchema } from "../shared/notes-op.ts";
5
+
6
+ function toolCall(overrides: Record<string, unknown>) {
7
+ return {
8
+ type: "tool_call" as const,
9
+ callId: "call-1",
10
+ name: "notes_read",
11
+ status: "completed" as const,
12
+ error: null,
13
+ detail: { type: "unknown" as const, input: { address: "@self/foo.md" }, output: {} },
14
+ ...overrides,
15
+ };
16
+ }
17
+
18
+ const transform = (overrides: Record<string, unknown>) => notesOpTransformer.transform({ item: toolCall(overrides) as never });
19
+
20
+ test("notes_read renders the structured window, marks continuation as truncated", () => {
21
+ const result = transform({
22
+ detail: {
23
+ type: "unknown",
24
+ input: { address: "@self/foo.md" },
25
+ output: { structuredContent: { address: "@self/foo.md", text: "hello note", total_chars: 9999, next_offset_chars: 4000 } },
26
+ },
27
+ });
28
+ const data = notesOpSchema.parse(result!.items[0]!.data);
29
+ assert.deepEqual(data, { op: "read", address: "@self/foo.md", status: "completed", text: "hello note", totalChars: 9999, truncated: true });
30
+ });
31
+
32
+ test("notes_write carries outcome and a clipped content preview", () => {
33
+ const result = transform({
34
+ name: "notes_write",
35
+ detail: {
36
+ type: "unknown",
37
+ input: { address: "session.md", content: "x".repeat(PREVIEW_MAX_CHARS + 10) },
38
+ output: { structuredContent: { address: "session.md", outcome: "created" } },
39
+ },
40
+ });
41
+ const data = notesOpSchema.parse(result!.items[0]!.data);
42
+ assert.equal(data.op, "write");
43
+ assert.equal(data.outcome, "created");
44
+ assert.equal(data.preview!.length, PREVIEW_MAX_CHARS);
45
+ assert.equal(data.truncated, true);
46
+ });
47
+
48
+ test("notes_update carries change kind, rename, and clipped diff", () => {
49
+ const result = transform({
50
+ name: "notes_update",
51
+ detail: {
52
+ type: "unknown",
53
+ input: { address: "@project/a.md" },
54
+ output: { structuredContent: { address: "@project/b.md", change_kind: "moved", rename_from: "@project/a.md", diff: "y".repeat(DIFF_MAX_CHARS + 10) } },
55
+ },
56
+ });
57
+ const data = notesOpSchema.parse(result!.items[0]!.data);
58
+ assert.equal(data.changeKind, "moved");
59
+ assert.equal(data.renamedFrom, "@project/a.md");
60
+ assert.equal(data.diff!.length, DIFF_MAX_CHARS);
61
+ assert.equal(data.truncated, true);
62
+ });
63
+
64
+ test("wire errors and failed calls surface the refusal text", () => {
65
+ const refused = transform({
66
+ detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { structuredContent: { error: "No note at @self/foo.md.", code: "not_found" } } },
67
+ });
68
+ assert.equal(notesOpSchema.parse(refused!.items[0]!.data).error, "No note at @self/foo.md.");
69
+
70
+ const failed = transform({
71
+ status: "failed",
72
+ error: { message: "boom" },
73
+ detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { content: [{ type: "text", text: "io failed" }] } },
74
+ });
75
+ assert.equal(notesOpSchema.parse(failed!.items[0]!.data).error, "io failed");
76
+ });
77
+
78
+ test("running calls render from input alone; long reads clip to the card budget", () => {
79
+ const running = transform({ status: "running", detail: { type: "unknown", input: { address: "@human/map.md" }, output: null } });
80
+ assert.deepEqual(notesOpSchema.parse(running!.items[0]!.data), { op: "read", address: "@human/map.md", status: "running" });
81
+
82
+ const long = transform({
83
+ detail: { type: "unknown", input: { address: "big.md" }, output: { structuredContent: { address: "big.md", text: "z".repeat(READ_TEXT_MAX_CHARS + 500), total_chars: 50000, next_offset_chars: null } } },
84
+ });
85
+ const data = notesOpSchema.parse(long!.items[0]!.data);
86
+ assert.equal(data.text!.length, READ_TEXT_MAX_CHARS);
87
+ assert.equal(data.truncated, true);
88
+ assert.ok(JSON.stringify(result_items(long)).length < 64 * 1024, "plugin payload stays under the timeline limit");
89
+ });
90
+
91
+ test("history replay has no structured payload: the rendered text is parsed instead", () => {
92
+ const read = transform({
93
+ detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { content: [{ type: "text", text: "@self/foo.md\norigin self | created 2026-10-15 | updated 2026-10-15\n\nbody line one\nbody line two" }] } },
94
+ });
95
+ assert.equal(notesOpSchema.parse(read!.items[0]!.data).text, "body line one\nbody line two");
96
+
97
+ const write = transform({
98
+ name: "notes_write",
99
+ detail: { type: "unknown", input: { address: "a.md", content: "ignored" }, output: { content: [{ type: "text", text: "overwrote a.md (project pi-context)" }] } },
100
+ });
101
+ const writeData = notesOpSchema.parse(write!.items[0]!.data);
102
+ assert.equal(writeData.outcome, "overwrote");
103
+ assert.equal(writeData.preview, undefined, "replay has no input preview authority beyond the address");
104
+
105
+ const update = transform({
106
+ name: "notes_update",
107
+ detail: { type: "unknown", input: { address: "a.md" }, output: { content: [{ type: "text", text: "updated a.md\ndiff:\n- 1 - old\n+ 1 + new" }] } },
108
+ });
109
+ const updateData = notesOpSchema.parse(update!.items[0]!.data);
110
+ assert.equal(updateData.changeKind, "body");
111
+ assert.equal(updateData.diff, "- 1 - old\n+ 1 + new");
112
+
113
+ const moved = transform({
114
+ name: "notes_update",
115
+ detail: { type: "unknown", input: { address: "a.md" }, output: { content: [{ type: "text", text: "moved a.md -> b.md" }] } },
116
+ });
117
+ assert.equal(notesOpSchema.parse(moved!.items[0]!.data).changeKind, "moved");
118
+ });
119
+
120
+ test("non-notes tools, unknown shapes and missing addresses stay untouched", () => {
121
+ assert.equal(notesOpTransformer.transform({ item: toolCall({ name: "bash" }) as never }), undefined);
122
+ assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "plain_text", text: "hi" } }) as never }), undefined);
123
+ assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "unknown", input: {}, output: {} } }) as never }), undefined);
124
+ assert.equal(notesOpTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
125
+ });
126
+
127
+ function result_items(result: { items: Array<{ data: unknown }> } | undefined) {
128
+ return result!.items.map((item) => item.data);
129
+ }
@@ -5,7 +5,7 @@ import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
5
5
  import type { NoteChange } from "../../../src/notes/index.js";
6
6
 
7
7
  function renderDiff(change: NoteChange): string {
8
- return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
8
+ return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
9
9
  }
10
10
 
11
11
  /** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */