notesoup 0.61.0 → 0.62.0

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 (200) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -11
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +2 -1
  10. package/dist/plugins/codex/src/hooks.js +1 -0
  11. package/dist/plugins/codex/src/identity.d.ts +6 -1
  12. package/dist/plugins/codex/src/identity.js +13 -1
  13. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  14. package/dist/plugins/codex/src/mcp.js +26 -88
  15. package/dist/plugins/codex/src/text.js +3 -3
  16. package/dist/plugins/dsh/tools.js +8 -4
  17. package/dist/plugins/mcp/operations.d.ts +15 -0
  18. package/dist/plugins/mcp/operations.js +43 -0
  19. package/dist/plugins/mcp/server.d.ts +14 -0
  20. package/dist/plugins/mcp/server.js +13 -0
  21. package/dist/plugins/pi/budget.d.ts +1 -1
  22. package/dist/plugins/pi/budget.js +3 -2
  23. package/dist/plugins/pi/entries.d.ts +1 -0
  24. package/dist/plugins/pi/entries.js +1 -0
  25. package/dist/plugins/pi/history-tools.js +2 -1
  26. package/dist/plugins/pi/history.js +18 -1
  27. package/dist/plugins/pi/notes/tools.js +7 -3
  28. package/dist/plugins/pi/render.d.ts +7 -1
  29. package/dist/plugins/pi/render.js +2 -2
  30. package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
  31. package/dist/plugins/pi/reset/lifecycle.js +8 -9
  32. package/dist/plugins/pi/runtime.js +102 -61
  33. package/dist/plugins/pi/tool-result.js +7 -7
  34. package/dist/plugins/pi/window.d.ts +33 -3
  35. package/dist/plugins/pi/window.js +209 -9
  36. package/dist/src/boot/render.js +18 -15
  37. package/dist/src/boot/text.d.ts +3 -1
  38. package/dist/src/boot/text.js +22 -20
  39. package/dist/src/budget/text.d.ts +2 -2
  40. package/dist/src/budget/text.js +13 -13
  41. package/dist/src/history/claude.d.ts +2 -0
  42. package/dist/src/history/claude.js +46 -0
  43. package/dist/src/history/codex-transcript.js +7 -5
  44. package/dist/src/history/codex.js +3 -0
  45. package/dist/src/history/corpus.d.ts +28 -1
  46. package/dist/src/history/corpus.js +40 -0
  47. package/dist/src/history/history.d.ts +37 -46
  48. package/dist/src/history/history.js +21 -40
  49. package/dist/src/history/local.js +67 -32
  50. package/dist/src/history/pi.d.ts +2 -1
  51. package/dist/src/history/pi.js +122 -48
  52. package/dist/src/history/prefilter.js +76 -19
  53. package/dist/src/history/query.d.ts +28 -49
  54. package/dist/src/history/query.js +83 -68
  55. package/dist/src/history/summary-cache.d.ts +8 -1
  56. package/dist/src/history/summary-cache.js +138 -12
  57. package/dist/src/index.d.ts +1 -1
  58. package/dist/src/index.js +1 -1
  59. package/dist/src/notes/errors.d.ts +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +0 -2
  61. package/dist/src/notes/frontmatter.js +0 -2
  62. package/dist/src/notes/index.d.ts +1 -1
  63. package/dist/src/notes/index.js +1 -1
  64. package/dist/src/notes/policy.d.ts +15 -1
  65. package/dist/src/notes/policy.js +46 -5
  66. package/dist/src/notes/store.d.ts +12 -0
  67. package/dist/src/notes/store.js +16 -20
  68. package/dist/src/text-match.d.ts +10 -1
  69. package/dist/src/text-match.js +42 -3
  70. package/dist/src/tools/dream.d.ts +22 -93
  71. package/dist/src/tools/dream.js +30 -27
  72. package/dist/src/tools/history.d.ts +33 -26
  73. package/dist/src/tools/history.js +257 -163
  74. package/dist/src/tools/notes.d.ts +51 -163
  75. package/dist/src/tools/notes.js +146 -100
  76. package/dist/src/tools/output.d.ts +2 -1
  77. package/dist/src/tools/output.js +2 -1
  78. package/dist/src/tools/result.d.ts +4 -7
  79. package/dist/src/tools/result.js +8 -9
  80. package/dist/src/tools/schema.d.ts +4 -1
  81. package/dist/src/tools/schema.js +25 -1
  82. package/dist/test/agent-loop.test.js +198 -16
  83. package/dist/test/antigravity-live.test.d.ts +1 -0
  84. package/dist/test/antigravity-live.test.js +142 -0
  85. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  86. package/dist/test/antigravity-plugin.test.js +101 -0
  87. package/dist/test/boot.integration.test.js +133 -14
  88. package/dist/test/claude-history.test.js +14 -13
  89. package/dist/test/claude-mod.test.js +9 -6
  90. package/dist/test/codex-history.test.js +15 -3
  91. package/dist/test/codex-plugin.test.js +76 -38
  92. package/dist/test/dependencies.test.js +7 -3
  93. package/dist/test/dream-skill.test.js +3 -3
  94. package/dist/test/dream-tools.test.js +101 -56
  95. package/dist/test/dsh.test.js +34 -19
  96. package/dist/test/helpers/dependency-graph.js +2 -2
  97. package/dist/test/helpers/extension.d.ts +65 -2
  98. package/dist/test/helpers/extension.js +72 -3
  99. package/dist/test/history-corpus.test.js +79 -77
  100. package/dist/test/history-summary-cache.test.js +97 -9
  101. package/dist/test/history.integration.test.js +234 -168
  102. package/dist/test/host-neutral.test.js +69 -19
  103. package/dist/test/marker.test.js +1 -1
  104. package/dist/test/note-policy.test.js +96 -77
  105. package/dist/test/notes.integration.test.js +212 -94
  106. package/dist/test/notes.test.js +184 -113
  107. package/dist/test/pi-render.test.js +20 -12
  108. package/dist/test/project-namespace.test.js +3 -2
  109. package/dist/test/reset-lifecycle.test.js +2 -2
  110. package/docs/antigravity.md +44 -0
  111. package/docs/architecture.md +6 -4
  112. package/docs/claude-code-mod.md +2 -2
  113. package/docs/codex.md +36 -38
  114. package/docs/dsh.md +3 -3
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +4 -4
  117. package/docs/skills.md +3 -3
  118. package/docs/tool-results.md +47 -28
  119. package/package.json +3 -2
  120. package/playbook.md +1 -1
  121. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  122. package/plugins/antigravity/hooks.json +7 -0
  123. package/plugins/antigravity/mcp_config.json +8 -0
  124. package/plugins/antigravity/plugin.json +6 -0
  125. package/plugins/antigravity/src/cli.ts +22 -0
  126. package/plugins/antigravity/src/hooks.ts +51 -0
  127. package/plugins/antigravity/src/identity.ts +127 -0
  128. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  129. package/plugins/claude/dist/claude/helper.js +1059 -534
  130. package/plugins/claude/hooks/register.ts +2 -2
  131. package/plugins/claude/playbook.md +1 -1
  132. package/plugins/claude/skills/dream/SKILL.md +1 -1
  133. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  134. package/plugins/claude/src/helper.ts +2 -1
  135. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  136. package/plugins/codex/.mcp.json +11 -0
  137. package/plugins/codex/README.md +5 -21
  138. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  139. package/plugins/codex/src/hooks.ts +1 -0
  140. package/plugins/codex/src/identity.ts +14 -1
  141. package/plugins/codex/src/mcp.ts +28 -98
  142. package/plugins/codex/src/text.ts +3 -3
  143. package/plugins/dsh/tools.ts +8 -4
  144. package/plugins/mcp/operations.ts +50 -0
  145. package/plugins/mcp/server.ts +23 -0
  146. package/plugins/paseo/README.md +5 -10
  147. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  148. package/plugins/paseo/client/markdown.tsx +50 -38
  149. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  150. package/plugins/paseo/client/paper-card.tsx +6 -5
  151. package/plugins/paseo/client/paper-palette.ts +2 -9
  152. package/plugins/paseo/client/sticky-card.tsx +2 -2
  153. package/plugins/paseo/client/tool-result.ts +7 -14
  154. package/plugins/paseo/package-lock.json +3406 -0
  155. package/plugins/paseo/package.json +1 -0
  156. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  157. package/plugins/pi/budget.ts +3 -3
  158. package/plugins/pi/entries.ts +1 -0
  159. package/plugins/pi/history-tools.ts +2 -1
  160. package/plugins/pi/history.ts +30 -1
  161. package/plugins/pi/notes/tools.ts +7 -3
  162. package/plugins/pi/render.ts +6 -6
  163. package/plugins/pi/reset/lifecycle.ts +9 -10
  164. package/plugins/pi/runtime.ts +96 -60
  165. package/plugins/pi/tool-result.ts +8 -8
  166. package/plugins/pi/window.ts +198 -9
  167. package/skills/dream/SKILL.md +1 -1
  168. package/skills/notesoup/SKILL.md +92 -0
  169. package/src/boot/render.ts +18 -15
  170. package/src/boot/text.ts +23 -19
  171. package/src/budget/text.ts +13 -13
  172. package/src/history/claude.ts +41 -0
  173. package/src/history/codex-transcript.ts +6 -4
  174. package/src/history/codex.ts +2 -0
  175. package/src/history/corpus.ts +51 -2
  176. package/src/history/history.ts +35 -44
  177. package/src/history/local.ts +67 -27
  178. package/src/history/pi.ts +113 -35
  179. package/src/history/prefilter.ts +73 -15
  180. package/src/history/query.ts +93 -73
  181. package/src/history/summary-cache.ts +142 -17
  182. package/src/index.ts +1 -1
  183. package/src/notes/errors.ts +1 -1
  184. package/src/notes/frontmatter.ts +0 -3
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +44 -5
  187. package/src/notes/store.ts +17 -20
  188. package/src/text-match.ts +46 -4
  189. package/src/tools/dream.ts +29 -31
  190. package/src/tools/history.ts +249 -142
  191. package/src/tools/notes.ts +145 -113
  192. package/src/tools/output.ts +2 -1
  193. package/src/tools/result.ts +12 -11
  194. package/src/tools/schema.ts +24 -1
  195. package/plugins/claude/skills/memory/SKILL.md +0 -69
  196. package/plugins/codex/mcp.json +0 -10
  197. package/plugins/codex/plugin.json +0 -6
  198. package/plugins/paseo/client/markdown-core.tsx +0 -189
  199. package/plugins/paseo/client/typography.ts +0 -24
  200. package/skills/memory/SKILL.md +0 -69
@@ -19,7 +19,7 @@ import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
19
19
  import { notesList } from "../src/tools/notes.js";
20
20
  import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
21
21
  import { notesToolContext } from "../src/tools/notes-context.js";
22
- import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
22
+ import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead, resultText, resultTextError } from "./helpers/extension.js";
23
23
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
24
24
  const testEnvironment = installExtensionTestHooks("notesoup-notes");
25
25
  function freshRoot() {
@@ -37,11 +37,11 @@ test("tools register their namespaces and sequential note mutations", () => {
37
37
  for (const name of ["notes_write", "notes_update", "notes_read", "notes_list"]) {
38
38
  assert.equal(captured.tools.get(name)?.namespace?.name, "notes", `${name} is in notes`);
39
39
  }
40
- for (const name of ["history_list", "history_read"]) {
40
+ for (const name of ["history_list", "history_read", "history_search"]) {
41
41
  assert.equal(captured.tools.get(name)?.namespace?.name, "history", `${name} is in history`);
42
42
  }
43
43
  });
44
- test("every notes tool declares a result schema that accepts its own structured payload", async () => {
44
+ test("only notes_read declares a result schema and emits a structured payload", async () => {
45
45
  const session = manager();
46
46
  const captured = makeExtension(session);
47
47
  const ctx = context(session);
@@ -56,8 +56,19 @@ test("every notes tool declares a result schema that accepts its own structured
56
56
  ];
57
57
  for (const [name, result] of delivered) {
58
58
  const schema = captured.tools.get(name).outputSchema;
59
- assert.ok(schema, `${name} registers an outputSchema`);
60
- assert.equal(Check(schema, result.structuredContent), true, `${name} structured payload matches its declared schema`);
59
+ if (name === "notes_read") {
60
+ assert.ok(schema, "notes_read registers an outputSchema");
61
+ assert.equal(Check(schema, result.structuredContent), true);
62
+ }
63
+ else {
64
+ assert.equal(schema, undefined, `${name} has no outputSchema`);
65
+ resultText(result);
66
+ if (name === "notes_write" || name === "notes_update") {
67
+ const receipt = result.details.receipt;
68
+ assert.ok(receipt && typeof receipt === "object" && "address" in receipt);
69
+ assert.equal(receipt.address, "schema.md");
70
+ }
71
+ }
61
72
  }
62
73
  });
63
74
  test("note schemas accept their operations, reject unknown fields, and expose crumpled listing", () => {
@@ -84,8 +95,8 @@ test("Pi resolves a per-call relative cwd against the session cwd", async () =>
84
95
  mkdirSync(base);
85
96
  mkdirSync(other);
86
97
  const ctx = context(session, undefined, undefined, true, base);
87
- const result = resultData(await call(captured, "notes_write", { address: "@project/selected", content: "other project", cwd: "../other" }, ctx));
88
- assert.equal(result.project_key, projectKey(other, process.env.NOTESOUP_HOME));
98
+ const result = resultText(await call(captured, "notes_write", { address: "@project/selected", content: "other project", cwd: "../other" }, ctx));
99
+ assert.ok(result.includes(`project ${projectKey(other, process.env.NOTESOUP_HOME)}`));
89
100
  const read = resultData(await call(captured, "notes_read", { address: "@project/selected", cwd: other }, ctx));
90
101
  assert.equal(read.text, "other project");
91
102
  const missing = resultError(await call(captured, "notes_read", { address: "@project/selected" }, ctx));
@@ -97,8 +108,7 @@ test("write lands a real markdown file with harness frontmatter and a pure body"
97
108
  const captured = makeExtension(session);
98
109
  const ctx = context(session);
99
110
  const sessionId = session.getSessionId();
100
- const result = resultData(await call(captured, "notes_write", { address: "a/b.md", content: "hello" }, ctx));
101
- assert.deepEqual(Object.keys(result).sort(), ["address", "budget", "outcome", "pinned", "readonly", "warnings"]);
111
+ const result = resultText(await call(captured, "notes_write", { address: "a/b.md", content: "hello" }, ctx));
102
112
  const file = physicalPath("session", "a/b.md", ctx);
103
113
  assert.equal(file, join(root, "pi", "session", sessionId, "a", "b.md"));
104
114
  assert.ok(existsSync(file), "the note is a real file under the session scope dir");
@@ -114,8 +124,7 @@ test("write lands a real markdown file with harness frontmatter and a pure body"
114
124
  assert.match(raw, new RegExp(`^${key}: \\d{4}-\\d{2}-\\d{2}T`, "m"), `frontmatter renders ${key} via localIso`);
115
125
  }
116
126
  assert.equal(parseNote(raw).meta.project, projectKey(ctx.cwd, root), "a newly-created session note records its existing project key");
117
- assertReceiptIdentity(result, "a/b.md", "session", ctx);
118
- assert.equal(result.outcome, "created");
127
+ assert.equal(result, "created a/b.md", "path-default policy adds no receipt noise");
119
128
  assert.equal(existsSync(join(scopeDir("session", ctx), ".session.json")), false, "ownership is stored in note frontmatter, not a sidecar");
120
129
  // A leading YAML block in user content is stripped from the body.
121
130
  await call(captured, "notes_write", { address: "stripped.md", content: "---\nscope: human\nnonsense: true\n---\nreal body" }, ctx);
@@ -238,33 +247,53 @@ test("edit is body-scoped with named failures and a replace_all escape hatch", a
238
247
  const captured = makeExtension(session);
239
248
  const ctx = context(session);
240
249
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta\nbeta\ngamma" }, ctx);
241
- const ambiguous = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }] }, ctx));
250
+ const ambiguous = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }] }, ctx));
242
251
  assert.match(ambiguous.message, /2 times/);
243
252
  assert.equal(ambiguous.code, "ambiguous_edit");
244
253
  assert.match(ambiguous.message, /edits\[0\]\.oldText appears 2 times \(lines 2, 3\)/, "the message names the failing edit index and every match line");
245
- const missing = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
254
+ const missing = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
246
255
  assert.equal(missing.code, "no_match");
247
256
  assert.match(missing.message, /edits\[0\]/, "a zero-match anchor names the failing edit index");
248
- const all = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
249
- assert.equal(all.address, "edit.md");
250
- assertReceiptIdentity(all, "edit.md", "session", ctx);
251
- assert.equal(all.change_kind, "body");
257
+ const all = resultText(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
258
+ assert.equal(all, "updated edit.md");
252
259
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "alpha\nB\nB\ngamma", "replace_all replaces every occurrence");
253
260
  // An anchor that occurs only in frontmatter is not matched: edits are body-only.
254
- const frontmatterOnly = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "origin", newText: "x" }] }, ctx));
261
+ const frontmatterOnly = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "origin", newText: "x" }] }, ctx));
255
262
  assert.match(frontmatterOnly.message, /edits\[0\]/, "a frontmatter-only anchor is not a body match");
256
263
  });
264
+ test("per-edit replace_all overrides the call default in one atomic batch", async () => {
265
+ freshRoot();
266
+ const session = manager();
267
+ const captured = makeExtension(session);
268
+ const ctx = context(session);
269
+ await call(captured, "notes_write", { address: "mixed.md", content: "alpha\nbeta\nbeta\ngamma\ndelta" }, ctx);
270
+ const mixed = resultText(await call(captured, "notes_update", { address: "mixed.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "beta", newText: "B", replace_all: true }] }, ctx));
271
+ assert.equal(mixed, "updated mixed.md");
272
+ assert.equal(resultRead(await call(captured, "notes_read", { address: "mixed.md" }, ctx)).content, "A\nB\nB\ngamma\ndelta", "a unique edit and a per-edit replace_all edit run in the same call");
273
+ const file = physicalPath("session", "mixed.md", ctx);
274
+ const before = readFileSync(file, "utf8");
275
+ const override = resultTextError(await call(captured, "notes_update", { address: "mixed.md", replace_all: true, edits: [{ oldText: "delta", newText: "D" }, { oldText: "B", newText: "Z", replace_all: false }] }, ctx));
276
+ assert.equal(override.code, "ambiguous_edit", "edits[].replace_all: false overrides a true call default");
277
+ assert.match(override.message, /edits\[1\]/, "the refusing edit is the one that opted out");
278
+ assert.equal(readFileSync(file, "utf8"), before, "the refused batch saves nothing, not even the earlier edit");
279
+ const zero = resultTextError(await call(captured, "notes_update", { address: "mixed.md", edits: [{ oldText: "zzz", newText: "y", replace_all: true }] }, ctx));
280
+ assert.equal(zero.code, "no_match", "a per-edit replace_all with zero matches still refuses as no_match");
281
+ assert.equal(resultRead(await call(captured, "notes_read", { address: "mixed.md" }, ctx)).content, "A\nB\nB\ngamma\ndelta", "a zero-match per-edit replace_all leaves the note untouched");
282
+ // The store validates the field itself, so a non-boolean cannot slip through a direct caller.
283
+ const store = createNotesStore(notesIdentityFromPi(ctx));
284
+ await assert.rejects(() => store.update("mixed.md", [{ oldText: "A", newText: "x", replaceAll: "yes" }]), (error) => error.code === "invalid_edit" && /edits\[0\]\.replaceAll must be a boolean/.test(error.message ?? ""));
285
+ });
257
286
  test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are named", async () => {
258
287
  freshRoot();
259
288
  const session = manager();
260
289
  const captured = makeExtension(session);
261
290
  const ctx = context(session);
262
- const nameOnly = resultError(await call(captured, "notes_update", { address: "edit.md" }, ctx));
291
+ const nameOnly = resultTextError(await call(captured, "notes_update", { address: "edit.md" }, ctx));
263
292
  assert.equal(nameOnly.code, "nothing_to_do", "neither edits nor setters is a named error");
264
293
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta" }, ctx);
265
- const empty = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [] }, ctx));
294
+ const empty = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [] }, ctx));
266
295
  assert.equal(empty.code, "nothing_to_do", "an empty edits list with no setters is also nothing to do");
267
- const editMissing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
296
+ const editMissing = resultTextError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
268
297
  assert.equal(editMissing.code, "not_found");
269
298
  const readMissing = resultError(await call(captured, "notes_read", { address: "missing.md" }, ctx));
270
299
  assert.equal(readMissing.code, "not_found");
@@ -272,13 +301,13 @@ test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are n
272
301
  assert.deepEqual(Object.keys(readMissing).sort(), ["code", "message"], "a plain refusal carries only a code and message");
273
302
  const file = physicalPath("session", "edit.md", ctx);
274
303
  const before = readFileSync(file, "utf8");
275
- const failed = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "absent", newText: "x" }] }, ctx));
304
+ const failed = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "absent", newText: "x" }] }, ctx));
276
305
  assert.match(failed.message, /edits\[1\]/, "the failing edit is named");
277
306
  assert.equal(readFileSync(file, "utf8"), before, "a failing batch leaves the file byte-identical, frontmatter included");
278
- const applied = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "beta", newText: "B" }] }, ctx));
279
- assert.equal(applied.change_kind, "body");
307
+ const applied = resultText(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "beta", newText: "B" }] }, ctx));
308
+ assert.equal(applied, "updated edit.md");
280
309
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "A\nB");
281
- const zero = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "zzz", newText: "y" }], replace_all: true }, ctx));
310
+ const zero = resultTextError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "zzz", newText: "y" }], replace_all: true }, ctx));
282
311
  assert.match(zero.message, /edits\[0\]/, "replace_all with zero matches is the same zero-match error, not a silent no-op");
283
312
  });
284
313
  test("notes_update combines rename_to with edits and metadata but protects live targets", async () => {
@@ -287,16 +316,13 @@ test("notes_update combines rename_to with edits and metadata but protects live
287
316
  const captured = makeExtension(session);
288
317
  const ctx = context(session);
289
318
  await call(captured, "notes_write", { address: "move-me.md", content: "body" }, ctx);
290
- const failed = resultError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
319
+ const failed = resultTextError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
291
320
  assert.equal(failed.code, "no_match", "a failed edit does not move the note");
292
321
  await call(captured, "notes_write", { address: "occupied.md", content: "live target" }, ctx);
293
- const conflict = resultError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "occupied.md" }, ctx));
322
+ const conflict = resultTextError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "occupied.md" }, ctx));
294
323
  assert.match(conflict.message, /occupied\.md/, "a live target refuses the move");
295
- const renamed = resultData(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "body", newText: "x" }], origin: "external", crumpled: true }, ctx));
296
- assertReceiptIdentity(renamed, "moved.md", "session", ctx);
297
- assert.equal(renamed.rename_from, "move-me.md");
298
- assert.equal(renamed.change_kind, "moved");
299
- assert.equal(renamed.address, "moved.md");
324
+ const renamed = resultText(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "body", newText: "x" }], origin: "external", crumpled: true }, ctx));
325
+ assert.equal(renamed, "moved move-me.md -> moved.md");
300
326
  const gone = resultError(await call(captured, "notes_read", { address: "move-me.md" }, ctx));
301
327
  assert.equal(gone.code, "not_found", "the old address is gone");
302
328
  assert.equal(resultRead(await call(captured, "notes_read", { address: "moved.md" }, ctx)).content, "x");
@@ -304,36 +330,33 @@ test("notes_update combines rename_to with edits and metadata but protects live
304
330
  assert.equal(movedMeta.origin, "external");
305
331
  assert.ok(movedMeta.crumpledAt);
306
332
  // Empty filler values are not a combination: a model passing every parameter still gets its crumple.
307
- const crumpled = resultData(await call(captured, "notes_update", { address: "moved.md", crumpled: true, edits: [], origin: "self", rename_to: "", replace_all: false }, ctx));
308
- assert.equal(crumpled.address, "moved.md", "an empty rename_to is ignored as if omitted");
309
- const listedCrumpled = resultData(await call(captured, "notes_list", { crumpled: true }, ctx));
310
- assert.equal(listedCrumpled.files.some((file) => file.address === "moved.md"), true, "the note was crumpled");
311
- const fillerRename = resultData(await call(captured, "notes_update", { address: "moved.md", rename_to: "moved-again.md", edits: [], replace_all: false }, ctx));
312
- assert.equal(fillerRename.address, "moved-again.md", "empty edits and replace_all: false ride along with a rename");
313
- const realCombo = resultData(await call(captured, "notes_update", { address: "moved-again.md", rename_to: "final.md", replace_all: true, crumpled: false }, ctx));
314
- assert.equal(realCombo.address, "final.md", "replace_all is harmless without edits, and restoration can accompany the move");
333
+ const crumpled = resultText(await call(captured, "notes_update", { address: "moved.md", crumpled: true, edits: [], origin: "self", rename_to: "", replace_all: false }, ctx));
334
+ assert.equal(crumpled, "updated moved.md", "an empty rename_to is ignored as if omitted");
335
+ const listedCrumpled = resultText(await call(captured, "notes_list", { crumpled: true }, ctx));
336
+ assert.match(listedCrumpled, /- moved\.md \|/, "the note was crumpled");
337
+ const fillerRename = resultText(await call(captured, "notes_update", { address: "moved.md", rename_to: "moved-again.md", edits: [], replace_all: false }, ctx));
338
+ assert.match(fillerRename, /^moved moved\.md -> moved-again\.md/, "empty edits and replace_all: false ride along with a rename");
339
+ const realCombo = resultText(await call(captured, "notes_update", { address: "moved-again.md", rename_to: "final.md", replace_all: true, crumpled: false }, ctx));
340
+ assert.match(realCombo, /^moved moved-again\.md -> final\.md/, "replace_all is harmless without edits, and restoration can accompany the move");
315
341
  });
316
342
  test("write and update receipts distinguish outcomes and no-op edits", async () => {
317
343
  freshRoot();
318
344
  const session = manager();
319
345
  const captured = makeExtension(session);
320
346
  const ctx = context(session);
321
- const alias = resultData(await call(captured, "notes_write", { address: "@self/alias", content: "body" }, ctx));
322
- assertReceiptIdentity(alias, "@self/alias.md", "agent", ctx);
323
- assert.equal(alias.outcome, "created");
324
- assert.equal(resultData(await call(captured, "notes_write", { address: "@agents/anonymous/alias.md", content: "new body" }, ctx)).outcome, "overwrote");
347
+ const alias = resultText(await call(captured, "notes_write", { address: "@self/alias", content: "body" }, ctx));
348
+ assert.match(alias, /^created @self\/alias\.md/);
349
+ assert.match(resultText(await call(captured, "notes_write", { address: "@agents/anonymous/alias.md", content: "new body" }, ctx)), /^overwrote /);
325
350
  await call(captured, "notes_update", { address: "@self/alias", crumpled: true }, ctx);
326
- assert.equal(resultData(await call(captured, "notes_write", { address: "@self/alias", content: "restored" }, ctx)).outcome, "uncrumpled");
351
+ assert.match(resultText(await call(captured, "notes_write", { address: "@self/alias", content: "restored" }, ctx)), /^uncrumpled /);
327
352
  const noChangeRaw = await call(captured, "notes_update", { address: "@self/alias", edits: [{ oldText: "restored", newText: "restored" }], crumpled: false }, ctx);
328
- const noChange = resultData(noChangeRaw);
329
- assert.equal(noChange.change_kind, "none");
330
- assert.equal(noChangeRaw.details, undefined);
331
- const mixed = resultData(await call(captured, "notes_update", { address: "@self/alias", edits: [{ oldText: "restored", newText: "restored" }, { oldText: "restored", newText: "changed" }] }, ctx));
332
- assert.equal(mixed.change_kind, "body");
353
+ assert.match(resultText(noChangeRaw), /^unchanged /);
354
+ assert.equal(noChangeRaw.details.diff, undefined);
355
+ const mixed = resultText(await call(captured, "notes_update", { address: "@self/alias", edits: [{ oldText: "restored", newText: "restored" }, { oldText: "restored", newText: "changed" }] }, ctx));
356
+ assert.match(mixed, /^updated /);
333
357
  // A body edit that also rewrites frontmatter is still a body change; details.diff carries the rest.
334
358
  const combinedRaw = await call(captured, "notes_update", { address: "@self/alias", edits: [{ oldText: "changed", newText: "changed once more" }], origin: "user" }, ctx);
335
- const combined = resultData(combinedRaw);
336
- assert.equal(combined.change_kind, "body", "an edit that also rewrites frontmatter is a body change, not a whole file");
359
+ assert.match(resultText(combinedRaw), /^updated /);
337
360
  assert.match(combinedRaw.details?.diff ?? "", /origin/, "details.diff still carries the frontmatter part");
338
361
  });
339
362
  test("empty results distinguish hidden notes and unavailable notebooks", async () => {
@@ -341,12 +364,12 @@ test("empty results distinguish hidden notes and unavailable notebooks", async (
341
364
  const session = manager();
342
365
  const captured = makeExtension(session);
343
366
  const ctx = context(session);
344
- const empty = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
345
- assert.deepEqual(empty, { files: [], more: 0, namespaces_unavailable: [] });
367
+ const empty = resultText(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
368
+ assert.equal(empty, "0 notes");
346
369
  await call(captured, "notes_write", { address: "@human/hidden.md", content: "needle" }, ctx);
347
370
  await call(captured, "notes_update", { address: "@human/hidden.md", crumpled: true }, ctx);
348
- const hidden = resultData(await call(captured, "notes_list", { query: "needle", glob: "@human/**" }, ctx));
349
- assert.deepEqual(hidden.files, [], "a crumpled note is hidden from search");
371
+ const hidden = resultText(await call(captured, "notes_list", { query: "needle", glob: "@human/**" }, ctx));
372
+ assert.equal(hidden, "0 notes", "a crumpled note is hidden from search");
350
373
  const identity = notesIdentityFromPi(ctx);
351
374
  const broken = scopeDir("project", ctx);
352
375
  mkdirSync(join(broken, ".."), { recursive: true });
@@ -361,8 +384,56 @@ test("empty results distinguish hidden notes and unavailable notebooks", async (
361
384
  assert.ok(searchResult.ok);
362
385
  assert.deepEqual(searchResult.data.namespaces_unavailable, ["@project"]);
363
386
  writeFileSync(join(process.env.NOTESOUP_HOME, "agents"), "not a directory");
364
- const namespace = resultData(await call(captured, "notes_list", { glob: "@agents/*/note.md" }, ctx));
365
- assert.deepEqual(namespace.namespaces_unavailable, ["@agents"]);
387
+ const namespace = resultText(await call(captured, "notes_list", { glob: "@agents/*/note.md" }, ctx));
388
+ assert.match(namespace, /@agents could not be read/);
389
+ });
390
+ test("notes_list refuses malformed cursors and treats an empty cursor as absent", async () => {
391
+ const session = manager();
392
+ const captured = makeExtension(session);
393
+ const ctx = context(session);
394
+ await call(captured, "notes_write", { address: "a.md", content: "needle" }, ctx);
395
+ await call(captured, "notes_write", { address: "b.md", content: "needle" }, ctx);
396
+ const baseline = resultText(await call(captured, "notes_list", { limit: 1 }, ctx));
397
+ assert.equal(resultText(await call(captured, "notes_list", { limit: 1, cursor: "" }, ctx)), baseline);
398
+ for (const cursor of ["nospace", "not-a-date a.md", "2026-01-01T00:00:00+08:00", "2026-01-01T00:00:00+08:00 ../escape.md"]) {
399
+ const refusal = resultTextError(await call(captured, "notes_list", { cursor }, ctx));
400
+ assert.equal(refusal.code, "invalid_params");
401
+ assert.match(refusal.message, /`cursor`/);
402
+ }
403
+ assert.equal(resultTextError(await call(captured, "notes_list", { cursor: "not-a-date a.md" }, ctx)).message, "`cursor` starts with an invalid ISO 8601 timestamp.");
404
+ assert.equal(resultTextError(await call(captured, "notes_list", { cursor: "2026-01-01T00:00:00+08:00 ../escape.md" }, ctx)).message, "`cursor` ends with an invalid note address.");
405
+ });
406
+ test("notes_list names the cursor and match cap and refuses their legacy spellings", () => {
407
+ const schema = makeExtension(manager()).tools.get("notes_list").parameters;
408
+ assert.equal(Check(schema, { cursor: "2026-01-01T00:00:00+08:00 a.md", max_matches_per_note: 2 }), true);
409
+ assert.equal(Check(schema, { before: "2026-01-01T00:00:00+08:00 a.md" }), false, "`before` is not an alias");
410
+ assert.equal(Check(schema, { max_matches_per_file: 2 }), false, "`max_matches_per_file` is not an alias");
411
+ });
412
+ test("receipts and list rows show only policy that differs from the path defaults", async () => {
413
+ const session = manager();
414
+ const captured = makeExtension(session);
415
+ const ctx = context(session);
416
+ assert.equal(resultText(await call(captured, "notes_write", { address: "plain.md", content: "body" }, ctx)), "created plain.md");
417
+ assert.equal(resultText(await call(captured, "notes_write", { address: "pinned.md", content: "body", pinned: true }, ctx)), "created pinned.md | pinned");
418
+ await createNotesStore(notesIdentityFromPi(ctx)).write("budgeted.md", "seed", { budget: 10 });
419
+ assert.equal(resultText(await call(captured, "notes_write", { address: "budgeted.md", content: "body" }, ctx)), "overwrote budgeted.md | budget 10");
420
+ assert.equal(resultText(await call(captured, "notes_write", { address: "locked.md", content: "body", readonly: true }, ctx)), "created locked.md | readonly");
421
+ assert.equal(resultText(await call(captured, "notes_write", { address: "CHEATSHEET.md", content: "body" }, ctx)), "created CHEATSHEET.md | pinned", "the default pin is announced once, without the default budget");
422
+ assert.equal(resultText(await call(captured, "notes_write", { address: "CHEATSHEET.md", content: "body", pinned: false }, ctx)), "overwrote CHEATSHEET.md | pinned false");
423
+ assert.equal(resultText(await call(captured, "notes_update", { address: "plain.md", edits: [{ oldText: "body", newText: "text" }] }, ctx)), "updated plain.md");
424
+ const listed = resultText(await call(captured, "notes_list", {}, ctx));
425
+ assert.match(listed, /^- plain\.md \| updated /m);
426
+ assert.match(listed, /^- pinned\.md \| pinned \| updated /m);
427
+ assert.match(listed, /^- budgeted\.md \| budget 10 \| updated /m);
428
+ assert.match(listed, /^- locked\.md \| readonly \| updated /m);
429
+ assert.match(listed, /^- CHEATSHEET\.md \| pinned false \| updated /m, "the one pin default that was explicitly turned off is named");
430
+ assert.doesNotMatch(listed, /budget 8192|readonly false|budget 4096/);
431
+ const readPlain = resultData(await call(captured, "notes_read", { address: "plain.md" }, ctx)).metadata;
432
+ assert.deepEqual({ pinned: readPlain.pinned, budget: readPlain.budget, readonly: readPlain.readonly }, { pinned: false, budget: 8192, readonly: false }, "read metadata keeps the full effective policy");
433
+ await call(captured, "notes_write", { address: "@project/decision.md", content: "body" }, ctx);
434
+ const scoped = resultText(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
435
+ assert.match(scoped, /^- @project\/decision\.md \| updated /m, "the current project needs no label on its own rows");
436
+ assert.doesNotMatch(scoped, /\(project /);
366
437
  });
367
438
  test("notes receipts report resolved identity across scopes", async () => {
368
439
  freshRoot();
@@ -375,10 +446,10 @@ test("notes receipts report resolved identity across scopes", async () => {
375
446
  { address: "@human/human.md", body: "human needle", scope: "human" },
376
447
  ];
377
448
  for (const note of notes) {
378
- const written = resultData(await call(captured, "notes_write", { address: note.address, content: note.body }, ctx));
379
- assertReceiptIdentity(written, note.address, note.scope, ctx);
380
- const edited = resultData(await call(captured, "notes_update", { address: note.address, edits: [{ oldText: "needle", newText: "match" }] }, ctx));
381
- assertReceiptIdentity(edited, note.address, note.scope, ctx);
449
+ const written = resultText(await call(captured, "notes_write", { address: note.address, content: note.body }, ctx));
450
+ assert.ok(written.startsWith(`created ${note.address}`));
451
+ const edited = resultText(await call(captured, "notes_update", { address: note.address, edits: [{ oldText: "needle", newText: "match" }] }, ctx));
452
+ assert.ok(edited.startsWith(`updated ${note.address}`));
382
453
  const rawRead = await call(captured, "notes_read", { address: note.address }, ctx);
383
454
  const read = resultRead(rawRead);
384
455
  assertReceiptIdentity(resultData(rawRead), note.address, note.scope, ctx);
@@ -387,14 +458,14 @@ test("notes receipts report resolved identity across scopes", async () => {
387
458
  assert.equal(read.metadata.project !== undefined, note.scope === "session", "stored project ownership is exposed as metadata");
388
459
  assert.equal(rawRead.content[0].type === "text" && rawRead.content[0].text.includes("---"), false, "the rendered read carries no frontmatter block");
389
460
  }
390
- const listed = resultData(await call(captured, "notes_list", { glob: "**" }, ctx));
391
- assert.deepEqual(listed.files.map((file) => file.address).sort(), notes.map((note) => note.address).sort(), "notes_list returns each full address");
392
- for (const row of listed.files)
393
- assertReceiptIdentity(row, row.address, notes.find((note) => note.address === row.address).scope, ctx);
394
- const searched = resultData(await call(captured, "notes_list", { query: "match", glob: "**" }, ctx));
395
- assert.deepEqual(searched.files.map((file) => file.address), notes.map((note) => note.address).sort(), "search returns each full address");
396
- for (const row of searched.files)
397
- assertReceiptIdentity(row, row.address, notes.find((note) => note.address === row.address).scope, ctx);
461
+ const listed = resultText(await call(captured, "notes_list", { glob: "**" }, ctx));
462
+ const searched = resultText(await call(captured, "notes_list", { query: "match", glob: "**" }, ctx));
463
+ assert.match(listed, /^3 notes\n/);
464
+ assert.match(searched, /^3 notes\n/);
465
+ for (const note of notes) {
466
+ assert.ok(listed.includes(`- ${note.address}`));
467
+ assert.ok(searched.includes(`- ${note.address}`));
468
+ }
398
469
  });
399
470
  test("list and search merge scopes and carry addresses; the path jail rejects escapes", async () => {
400
471
  freshRoot();
@@ -404,31 +475,27 @@ test("list and search merge scopes and carry addresses; the path jail rejects es
404
475
  await call(captured, "notes_write", { address: "one.md", content: "needle one" }, ctx);
405
476
  await call(captured, "notes_write", { address: "@project/two.md", content: "needle two" }, ctx);
406
477
  await call(captured, "notes_write", { address: "@human/three.md", content: "needle three" }, ctx);
407
- const listed = resultData(await call(captured, "notes_list", {}, ctx));
408
- assert.deepEqual([...listed.files].map((file) => file.address).sort(), ["@human/three.md", "@project/two.md", "one.md"], "every merged row carries its full address");
409
- for (const row of listed.files)
410
- assert.equal(typeof row.updated_at, "string");
411
- const scoped = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
412
- assert.deepEqual(scoped.files.map((file) => file.address), ["@human/three.md"], "an address glob filter narrows the set");
413
- const searched = resultData(await call(captured, "notes_list", { query: "needle" }, ctx));
414
- assert.equal(searched.files.length, 3, "literal search finds matches in every scope");
415
- assert.deepEqual([...searched.files].map((file) => file.address).sort(), ["@human/three.md", "@project/two.md", "one.md"]);
416
- for (const row of [...listed.files, ...searched.files])
417
- assert.equal("scope" in row, false, "scope is derivable from the address and never echoed");
418
- assert.equal(searched.files.every((file) => file.matches?.length === 1), true);
419
- const hit = searched.files[0].matches[0];
420
- assert.equal(hit.line, 1);
421
- assert.equal(hit.offset_chars, 0, "the offset counts into the note body, so it does not include serialized frontmatter");
422
- assert.deepEqual(Object.keys(hit).sort(), ["line", "offset_chars", "text"]);
423
- assert.equal(resultRead(await call(captured, "notes_read", { address: searched.files[0].address, offset_chars: hit.offset_chars }, ctx)).content.startsWith("needle"), true, "the search offset starts a read at the match");
478
+ const listed = resultText(await call(captured, "notes_list", {}, ctx));
479
+ assert.match(listed, /^3 notes\n/);
480
+ for (const address of ["@human/three.md", "@project/two.md", "one.md"])
481
+ assert.ok(listed.includes(`- ${address}`));
482
+ const scoped = resultText(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
483
+ assert.match(scoped, /^1 note\n- @human\/three\.md/, "an address glob filter narrows the set");
484
+ const searched = resultText(await call(captured, "notes_list", { query: "needle" }, ctx));
485
+ assert.match(searched, /^3 notes\n/);
486
+ for (const address of ["@human/three.md", "@project/two.md", "one.md"])
487
+ assert.ok(searched.includes(`- ${address}`));
488
+ assert.equal((searched.match(/line 1 at offset_chars 0: needle/g) ?? []).length, 3);
489
+ assert.equal(resultRead(await call(captured, "notes_read", { address: "one.md", offset_chars: 0 }, ctx)).content.startsWith("needle"), true, "the search offset starts a read at the match");
424
490
  const escaped = ["../evil", "/abs", "a\\b"];
425
491
  for (const tool of ["notes_write", "notes_update", "notes_read"]) {
426
492
  for (const path of escaped) {
427
- assert.equal(resultError(await call(captured, tool, { address: path, content: "x", edits: [{ oldText: "a", newText: "b" }] }, ctx)).code, "invalid_address");
493
+ const result = await call(captured, tool, { address: path, content: "x", edits: [{ oldText: "a", newText: "b" }] }, ctx);
494
+ assert.equal((tool === "notes_read" ? resultError(result) : resultTextError(result)).code, "invalid_address");
428
495
  }
429
496
  }
430
497
  assert.equal(resultError(await call(captured, "notes_read", { address: "one.md", offset_chars: 99999 }, ctx)).code, "invalid_offset");
431
- assert.equal(resultError(await call(captured, "notes_list", { glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
498
+ assert.equal(resultTextError(await call(captured, "notes_list", { glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
432
499
  });
433
500
  test("a read offsets the body in code points, not bytes or frontmatter", async () => {
434
501
  freshRoot();
@@ -436,11 +503,9 @@ test("a read offsets the body in code points, not bytes or frontmatter", async (
436
503
  const captured = makeExtension(session);
437
504
  const ctx = context(session);
438
505
  await call(captured, "notes_write", { address: "emoji.md", content: "🐑字\nneedle tail" }, ctx);
439
- const search = resultData(await call(captured, "notes_list", { query: "needle", glob: "emoji.md" }, ctx));
440
- const match = search.files[0].matches[0];
441
- assert.equal(match.line, 2);
442
- assert.equal(match.offset_chars, 3, "the emoji and CJK line above contribute two code points plus the newline, not their bytes");
443
- const atMatch = resultRead(await call(captured, "notes_read", { address: "emoji.md", offset_chars: match.offset_chars }, ctx));
506
+ const search = resultText(await call(captured, "notes_list", { query: "needle", glob: "emoji.md" }, ctx));
507
+ assert.match(search, /line 2 at offset_chars 3: needle tail/, "the emoji and CJK line contribute two code points plus the newline");
508
+ const atMatch = resultRead(await call(captured, "notes_read", { address: "emoji.md", offset_chars: 3 }, ctx));
444
509
  assert.equal(atMatch.text.startsWith("needle"), true, "the offset lands on the match even with multi-byte characters above it");
445
510
  assert.equal(atMatch.total_chars, Array.from("🐑字\nneedle tail").length);
446
511
  const negative = resultRead(await call(captured, "notes_read", { address: "emoji.md", offset_chars: -4 }, ctx));
@@ -464,8 +529,8 @@ test("@ addresses select one notebook, keep boundaries, and never fall back", as
464
529
  assert.match(resultRead(await call(captured, "notes_read", { address: "same.md" }, ctx)).content, /session$/);
465
530
  assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).code, "not_found");
466
531
  assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /isn't a note address.*@project\/.*@human\//);
467
- assert.equal(resultError(await call(captured, "notes_write", { address: "@glboal/same.md", content: "no" }, ctx)).code, "invalid_address", "an unknown leading head is still not a note address");
468
- assert.equal(resultError(await call(captured, "notes_write", { address: "@project/../escape.md", content: "no" }, ctx)).code, "invalid_address", "traversal never hides behind a known head");
532
+ assert.equal(resultTextError(await call(captured, "notes_write", { address: "@glboal/same.md", content: "no" }, ctx)).code, "invalid_address", "an unknown leading head is still not a note address");
533
+ assert.equal(resultTextError(await call(captured, "notes_write", { address: "@project/../escape.md", content: "no" }, ctx)).code, "invalid_address", "traversal never hides behind a known head");
469
534
  assert.equal(existsSync(join(root, "human", "escape.md")), false, "a refused address creates nothing anywhere");
470
535
  });
471
536
  test("interior @ in a note path round-trips through write, list, search, read, update and rename", async () => {
@@ -473,16 +538,20 @@ test("interior @ in a note path round-trips through write, list, search, read, u
473
538
  const session = manager();
474
539
  const captured = makeExtension(session);
475
540
  const ctx = context(session);
476
- assertReceiptIdentity(resultData(await call(captured, "notes_write", { address: "release@v1.md", content: "release needle" }, ctx)), "release@v1.md", "session", ctx);
477
- assertReceiptIdentity(resultData(await call(captured, "notes_write", { address: "@project/mail/alice@example.com.md", content: "mail needle" }, ctx)), "@project/mail/alice@example.com.md", "project", ctx);
541
+ assert.match(resultText(await call(captured, "notes_write", { address: "release@v1.md", content: "release needle" }, ctx)), /^created release@v1\.md/);
542
+ assert.match(resultText(await call(captured, "notes_write", { address: "@project/mail/alice@example.com.md", content: "mail needle" }, ctx)), /^created @project\/mail\/alice@example\.com\.md/);
478
543
  assert.ok(existsSync(join(root, "pi", "session", session.getSessionId(), "release@v1.md")), "the session file keeps its interior @");
479
544
  assert.ok(existsSync(physicalPath("project", "mail/alice@example.com.md", ctx)), "the project file keeps its interior @ inside a folder");
480
- const listed = resultData(await call(captured, "notes_list", {}, ctx));
481
- assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "both addresses list in canonical form");
482
- const globbed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
483
- assert.deepEqual(globbed.files.map((row) => row.address), ["@project/mail/alice@example.com.md"], "a notebook glob still narrows to that notebook");
484
- const searched = resultData(await call(captured, "notes_list", { query: "needle" }, ctx));
485
- assert.deepEqual(searched.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "searched addresses carry the interior @ back out");
545
+ const listed = resultText(await call(captured, "notes_list", {}, ctx));
546
+ assert.match(listed, /^2 notes\n/);
547
+ for (const address of ["@project/mail/alice@example.com.md", "release@v1.md"])
548
+ assert.ok(listed.includes(`- ${address}`));
549
+ const globbed = resultText(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
550
+ assert.match(globbed, /^1 note\n- @project\/mail\/alice@example\.com\.md/, "a notebook glob still narrows to that notebook");
551
+ const searched = resultText(await call(captured, "notes_list", { query: "needle" }, ctx));
552
+ assert.match(searched, /^2 notes\n/);
553
+ for (const address of ["@project/mail/alice@example.com.md", "release@v1.md"])
554
+ assert.ok(searched.includes(`- ${address}`));
486
555
  assert.match(resultRead(await call(captured, "notes_read", { address: "@project/mail/alice@example.com.md" }, ctx)).content, /mail needle$/);
487
556
  await call(captured, "notes_update", { address: "release@v1.md", edits: [{ oldText: "release", newText: "shipped" }] }, ctx);
488
557
  assert.match(resultRead(await call(captured, "notes_read", { address: "release@v1.md" }, ctx)).content, /shipped needle$/);
@@ -493,8 +562,8 @@ test("interior @ in a note path round-trips through write, list, search, read, u
493
562
  // A file dropped on disk (before any address change) still lists and reads under its full address.
494
563
  mkdirSync(join(root, "human"), { recursive: true });
495
564
  writeFileSync(join(root, "human", "pre@existing.md"), "---\norigin: user\n---\n\nlegacy needle\n");
496
- const legacy = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
497
- assert.deepEqual(legacy.files.map((row) => row.address), ["@human/pre@existing.md"]);
565
+ const legacy = resultText(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
566
+ assert.match(legacy, /^1 note\n- @human\/pre@existing\.md/);
498
567
  assert.match(resultRead(await call(captured, "notes_read", { address: "@human/pre@existing.md" }, ctx)).content, /legacy needle/);
499
568
  });
500
569
  test("Pi adapter defaults to anonymous agent identity", async () => {
@@ -504,10 +573,10 @@ test("Pi adapter defaults to anonymous agent identity", async () => {
504
573
  const ctx = context(session);
505
574
  await withAgent(undefined, async () => {
506
575
  await call(captured, "notes_write", { address: "@self/private.md", content: "anonymous agent note" }, ctx);
507
- const listed = resultData(await call(captured, "notes_list", {}, ctx));
508
- assert.deepEqual(listed.files.map((row) => row.address), ["@self/private.md"]);
509
- const explicit = resultData(await call(captured, "notes_list", { glob: "@agents/*/private.md" }, ctx));
510
- assert.deepEqual(explicit.files.map((row) => row.address), ["@self/private.md"], "explicit-id globs still match the current notebook");
576
+ const listed = resultText(await call(captured, "notes_list", {}, ctx));
577
+ assert.match(listed, /^1 note\n- @self\/private\.md/);
578
+ const explicit = resultText(await call(captured, "notes_list", { glob: "@agents/*/private.md" }, ctx));
579
+ assert.match(explicit, /^1 note\n- @self\/private\.md/, "explicit-id globs still match the current notebook");
511
580
  assert.equal(existsSync(join(root, "agents", "anonymous", "private.md")), true);
512
581
  });
513
582
  });
@@ -522,13 +591,15 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
522
591
  ctx.model = context(session, undefined, undefined, true, testEnvironment.cwd, true, "other/Second.Model").model;
523
592
  assert.equal(resultError(await call(captured, "notes_read", { address: "@model/private.md" }, ctx)).code, "not_found", "switched model does not fall back to previous notebook");
524
593
  await call(captured, "notes_write", { address: "@model/private.md", content: "second model note" }, ctx);
525
- const listed = resultData(await call(captured, "notes_list", {}, ctx));
526
- assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@model/private.md", "@self/private.md"]);
594
+ const listed = resultText(await call(captured, "notes_list", {}, ctx));
595
+ assert.match(listed, /^2 notes\n/);
596
+ assert.ok(listed.includes("- @model/private.md"));
597
+ assert.ok(listed.includes("- @self/private.md"));
527
598
  const boot = await explicitBoot(ctx, "test-window", undefined);
528
599
  assert.ok(boot.includes("@model/private.md"));
529
600
  assert.equal(boot.includes("@models/first-model/private.md"), false);
530
601
  assert.match(resultRead(await call(captured, "notes_read", { address: "@models/first-model/private.md" }, ctx)).content, /first model note$/);
531
- const refused = resultError(await call(captured, "notes_update", { address: "@models/first-model/private.md", crumpled: true }, ctx));
602
+ const refused = resultTextError(await call(captured, "notes_update", { address: "@models/first-model/private.md", crumpled: true }, ctx));
532
603
  assert.match(refused.message, /someone else's notebook/);
533
604
  assert.match(readFileSync(join(root, "models/first-model/private.md"), "utf8"), /first model note$/);
534
605
  });
@@ -3,7 +3,7 @@ import test from "node:test";
3
3
  import { mkdtempSync, rmSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
- import { notesRead, notesToolContext, notesUpdate, notesWrite } from "../src/index.js";
6
+ import { createNotesStore, notesRead, notesToolContext, notesUpdate, notesWrite } from "../src/index.js";
7
7
  import { initTheme } from "@earendil-works/pi-coding-agent";
8
8
  import { Box, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
9
9
  import { emptyBrainRenderers, notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../plugins/pi/render.js";
@@ -19,6 +19,9 @@ const flatTheme = {
19
19
  function toolResult(outcome, details) {
20
20
  return { content: [{ type: "text", text: "receipt" }], structuredContent: wireResult(outcome), isError: !outcome.ok, details: details };
21
21
  }
22
+ function receiptResult(outcome, diff) {
23
+ return { content: [{ type: "text", text: "receipt" }], isError: !outcome.ok, details: { receipt: wireResult(outcome), ...(diff ? { diff } : {}) } };
24
+ }
22
25
  function jsonResult(value, isError = false) {
23
26
  return { content: [{ type: "text", text: JSON.stringify(value) }], isError, details: undefined };
24
27
  }
@@ -80,28 +83,33 @@ test("empty_brain keeps the divider and handoff within very narrow widths", () =
80
83
  test("real policy receipts keep policy and budget warnings visible in collapsed and expanded Pi views", async (t) => {
81
84
  const home = mkdtempSync(join(tmpdir(), "policy-render-"));
82
85
  t.after(() => rmSync(home, { recursive: true, force: true }));
83
- const context = notesToolContext({ home, sessionId: "render", projectKey: "render", agent: "root", model: "test" }, home);
84
- const writeArgs = { address: "custom", content: "😀".repeat(3), budget: 2, pinned: true, readonly: false };
85
- const written = toolResult(await notesWrite.execute(writeArgs, context));
86
+ const identity = { home, sessionId: "render", projectKey: "render", agent: "root", model: "test" };
87
+ const context = notesToolContext(identity, home);
88
+ await createNotesStore(identity).write("custom", "seed", { budget: 8, pinned: true });
89
+ const writeArgs = { address: "custom", content: "😀".repeat(3), pinned: true, readonly: false };
90
+ const written = receiptResult(await notesWrite.execute(writeArgs, context));
86
91
  const updateArgs = { address: "custom", readonly: true, edits: [{ oldText: "😀".repeat(3), newText: "😀".repeat(4) }] };
87
- const updated = toolResult(await notesUpdate.execute(updateArgs, context));
92
+ const updated = receiptResult(await notesUpdate.execute(updateArgs, context));
88
93
  const read = toolResult(await notesRead.execute({ address: "custom", max_chars: 10 }, context));
94
+ assert.equal(written.structuredContent, undefined);
95
+ assert.equal(updated.structuredContent, undefined);
96
+ assert.ok(read.structuredContent);
89
97
  for (const expanded of [false, true]) {
90
98
  const views = [
91
- { component: notesWriteRenderers.renderResult(written, { expanded }, flatTheme, { args: writeArgs }), locked: false, count: 3 },
92
- { component: notesUpdateRenderers.renderResult(updated, { expanded }, flatTheme, { args: updateArgs }), locked: true, count: 4 },
93
- { component: notesReadRenderers.renderResult(read, { expanded }, flatTheme), locked: true, count: 4 },
99
+ { component: notesWriteRenderers.renderResult(written, { expanded }, flatTheme, { args: writeArgs }), locked: false, bytes: 12 },
100
+ { component: notesUpdateRenderers.renderResult(updated, { expanded }, flatTheme, { args: updateArgs }), locked: true, bytes: 16 },
101
+ { component: notesReadRenderers.renderResult(read, { expanded }, flatTheme), locked: true, bytes: 16 },
94
102
  ];
95
- for (const { component, locked, count } of views) {
103
+ for (const { component, locked, bytes } of views) {
96
104
  const text = lines(component, 48).replace(/\s+/g, " ");
97
- assert.ok(text.includes(`pinned true | budget 2 | readonly ${locked}`));
98
- assert.ok(text.includes(`Warning: note body is ${count} Unicode code points, over budget 2`), `warning must not be clipped or hidden when expanded=${expanded}`);
105
+ assert.ok(text.includes(`pinned true | budget 8 | readonly ${locked}`));
106
+ assert.ok(text.includes(`note body is ${bytes} bytes (budget 8)`), `warning must not be clipped or hidden when expanded=${expanded}`);
99
107
  }
100
108
  }
101
109
  });
102
110
  test("notes_update expanded diff goes through the host's diff renderer", () => {
103
111
  initTheme();
104
- const result = toolResult(success({ address: "a.md", change_kind: "body" }), { diff: " 1 old\n-2 gone\n+2 here" });
112
+ const result = receiptResult(success({ address: "a.md", change_kind: "body", pinned: false, budget: 100, readonly: false, warnings: [] }), " 1 old\n-2 gone\n+2 here");
105
113
  const component = notesUpdateRenderers.renderResult(result, { expanded: true }, flatTheme, { args: { address: "a.md" } });
106
114
  const text = lines(component);
107
115
  assert.ok(text.includes("a.md"));
@@ -244,10 +244,11 @@ test("named projects read/list/search with root and sibling receipts, without to
244
244
  assert.match(notesRead.render(success(read)), /Same-basename projects: api \(/);
245
245
  const listed = data(await notesList.execute({ glob: "@projects/*/**" }, toolContext(own)));
246
246
  assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
247
- assert.equal(Check(notesList.outputSchema, listed), true);
247
+ assert.equal("outputSchema" in notesList, false);
248
+ assert.match(notesList.render(success(listed)), /@projects\/api-1\/decision\.md/);
248
249
  const searched = data(await notesList.execute({ glob: "@projects/api-1/**", query: "needle" }, toolContext(own)));
249
250
  assert.equal(searched.files[0]?.project_root, second);
250
- assert.equal(Check(notesList.outputSchema, searched), true);
251
+ assert.match(notesList.render(success(searched)), /line 1 at offset_chars 0: needle second/);
251
252
  assert.equal(readFileSync(file, "utf8"), before, "named-notebook reads never rewrite access metadata");
252
253
  });
253
254
  test("named project writes, edits, crumples and both move endpoints refuse, including the current notebook", async (t) => {