notesoup 0.53.2 → 0.54.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 (186) hide show
  1. package/README.md +6 -4
  2. package/dist/plugins/claude/src/helper.d.ts +2 -1
  3. package/dist/plugins/claude/src/helper.js +21 -24
  4. package/dist/plugins/claude/src/history.d.ts +3 -14
  5. package/dist/plugins/claude/src/history.js +2 -298
  6. package/dist/plugins/claude/src/text.d.ts +0 -1
  7. package/dist/plugins/claude/src/text.js +0 -1
  8. package/dist/plugins/codex/src/history.d.ts +3 -8
  9. package/dist/plugins/codex/src/history.js +2 -238
  10. package/dist/plugins/codex/src/hooks.js +1 -1
  11. package/dist/plugins/codex/src/identity.d.ts +1 -1
  12. package/dist/plugins/codex/src/identity.js +3 -3
  13. package/dist/plugins/codex/src/mcp.js +9 -8
  14. package/dist/plugins/codex/src/text.d.ts +1 -1
  15. package/dist/plugins/codex/src/text.js +2 -2
  16. package/dist/plugins/codex/src/transcript.d.ts +3 -39
  17. package/dist/plugins/codex/src/transcript.js +2 -313
  18. package/dist/plugins/dsh/engine.js +2 -2
  19. package/dist/plugins/dsh/history.d.ts +3 -0
  20. package/dist/plugins/dsh/history.js +15 -0
  21. package/dist/plugins/dsh/tools.js +12 -12
  22. package/dist/plugins/dsh/window.d.ts +1 -0
  23. package/dist/plugins/dsh/window.js +7 -3
  24. package/dist/plugins/pi/history-tools.d.ts +1 -1
  25. package/dist/plugins/pi/history-tools.js +9 -5
  26. package/dist/plugins/pi/history.d.ts +2 -3
  27. package/dist/plugins/pi/history.js +4 -147
  28. package/dist/plugins/pi/notes/tools.js +8 -6
  29. package/dist/plugins/pi/render.js +7 -4
  30. package/dist/plugins/pi/runtime.js +2 -2
  31. package/dist/plugins/pi/window.js +21 -7
  32. package/dist/src/boot/render.js +9 -11
  33. package/dist/src/boot/snapshot.d.ts +7 -7
  34. package/dist/src/boot/snapshot.js +17 -17
  35. package/dist/src/boot/text.d.ts +5 -3
  36. package/dist/src/boot/text.js +18 -10
  37. package/dist/src/dream/git.d.ts +2 -11
  38. package/dist/src/dream/git.js +6 -23
  39. package/dist/src/dream/lock.d.ts +2 -2
  40. package/dist/src/dream/lock.js +3 -3
  41. package/dist/src/history/claude.d.ts +16 -0
  42. package/dist/src/history/claude.js +336 -0
  43. package/dist/src/history/codex-transcript.d.ts +39 -0
  44. package/dist/src/history/codex-transcript.js +315 -0
  45. package/dist/src/history/codex.d.ts +8 -0
  46. package/dist/src/history/codex.js +238 -0
  47. package/dist/src/history/corpus.d.ts +35 -0
  48. package/dist/src/history/corpus.js +54 -0
  49. package/dist/src/history/history.d.ts +4 -8
  50. package/dist/src/history/history.js +3 -11
  51. package/dist/src/history/local.d.ts +17 -0
  52. package/dist/src/history/local.js +101 -0
  53. package/dist/src/history/pi.d.ts +36 -0
  54. package/dist/src/history/pi.js +202 -0
  55. package/dist/src/history/query.d.ts +15 -5
  56. package/dist/src/history/query.js +42 -13
  57. package/dist/src/index.d.ts +6 -3
  58. package/dist/src/index.js +6 -4
  59. package/dist/src/notes/address.d.ts +8 -8
  60. package/dist/src/notes/address.js +13 -13
  61. package/dist/src/notes/errors.d.ts +1 -1
  62. package/dist/src/notes/frontmatter.js +2 -2
  63. package/dist/src/notes/index.d.ts +1 -1
  64. package/dist/src/notes/index.js +1 -1
  65. package/dist/src/notes/paths.d.ts +6 -6
  66. package/dist/src/notes/paths.js +9 -9
  67. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  68. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  69. package/dist/src/notes/store.d.ts +4 -4
  70. package/dist/src/notes/store.js +55 -52
  71. package/dist/src/tools/dream.d.ts +21 -3
  72. package/dist/src/tools/dream.js +54 -16
  73. package/dist/src/tools/history.d.ts +7 -19
  74. package/dist/src/tools/history.js +80 -93
  75. package/dist/src/tools/notes-context.d.ts +10 -0
  76. package/dist/src/tools/notes-context.js +27 -0
  77. package/dist/src/tools/notes.d.ts +69 -20
  78. package/dist/src/tools/notes.js +40 -31
  79. package/dist/test/boot.integration.test.js +2 -3
  80. package/dist/test/claude-history.test.js +47 -34
  81. package/dist/test/claude-mod.test.js +96 -50
  82. package/dist/test/codex-history.test.js +4 -10
  83. package/dist/test/codex-plugin.test.js +50 -12
  84. package/dist/test/context-edit-budget.test.js +121 -0
  85. package/dist/test/dependencies.test.js +73 -6
  86. package/dist/test/dream-tools.test.js +153 -8
  87. package/dist/test/dsh.test.js +88 -19
  88. package/dist/test/helpers/dsh.d.ts +4 -1
  89. package/dist/test/helpers/dsh.js +20 -4
  90. package/dist/test/helpers/extension.d.ts +5 -1
  91. package/dist/test/helpers/extension.js +33 -2
  92. package/dist/test/helpers/history-corpus.d.ts +7 -0
  93. package/dist/test/helpers/history-corpus.js +26 -0
  94. package/dist/test/history-corpus.test.js +307 -0
  95. package/dist/test/history.integration.test.js +40 -48
  96. package/dist/test/host-neutral.test.js +20 -33
  97. package/dist/test/model-facing-text.test.js +14 -8
  98. package/dist/test/notes-cwd.test.d.ts +1 -0
  99. package/dist/test/notes-cwd.test.js +114 -0
  100. package/dist/test/notes-library.test.js +4 -4
  101. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  102. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  103. package/dist/test/notes.integration.test.js +73 -24
  104. package/dist/test/notes.test.js +51 -21
  105. package/dist/test/pi-render.test.js +33 -1
  106. package/dist/test/project-namespace.test.d.ts +1 -0
  107. package/dist/test/project-namespace.test.js +324 -0
  108. package/docs/architecture.md +19 -12
  109. package/docs/claude-code-mod.md +7 -5
  110. package/docs/codex.md +6 -6
  111. package/docs/dsh.md +9 -9
  112. package/docs/history-sessions.md +52 -0
  113. package/docs/notes-library.md +9 -5
  114. package/docs/skills.md +3 -3
  115. package/docs/tool-results.md +14 -8
  116. package/package.json +4 -6
  117. package/playbook.md +6 -6
  118. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  119. package/plugins/claude/dist/claude/helper.js +2164 -1341
  120. package/plugins/claude/hooks/register.ts +19 -11
  121. package/plugins/claude/playbook.md +6 -6
  122. package/plugins/claude/skills/memory/SKILL.md +9 -7
  123. package/plugins/claude/src/helper.ts +22 -25
  124. package/plugins/claude/src/history.ts +3 -257
  125. package/plugins/claude/src/text.ts +0 -1
  126. package/plugins/codex/README.md +1 -1
  127. package/plugins/codex/dist/codex/notesoup.js +1582 -969
  128. package/plugins/codex/src/history.ts +3 -193
  129. package/plugins/codex/src/hooks.ts +1 -1
  130. package/plugins/codex/src/identity.ts +3 -3
  131. package/plugins/codex/src/mcp.ts +9 -8
  132. package/plugins/codex/src/text.ts +2 -2
  133. package/plugins/codex/src/transcript.ts +3 -275
  134. package/plugins/dsh/engine.ts +2 -2
  135. package/plugins/dsh/history.ts +17 -0
  136. package/plugins/dsh/tools.ts +12 -12
  137. package/plugins/dsh/window.ts +8 -3
  138. package/plugins/paseo/OVERVIEW.md +4 -4
  139. package/plugins/paseo/README.md +1 -1
  140. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  141. package/plugins/paseo/client/markdown.tsx +159 -0
  142. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  143. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  144. package/plugins/paseo/client/paper-card.tsx +8 -19
  145. package/plugins/paseo/client/paper-palette.ts +40 -0
  146. package/plugins/paseo/client/sticky-card.tsx +6 -4
  147. package/plugins/paseo/package.json +3 -0
  148. package/plugins/paseo/paseo-plugin.json +2 -2
  149. package/plugins/paseo/shared/notes-op.ts +13 -9
  150. package/plugins/paseo/test/notes-op.test.ts +52 -73
  151. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  152. package/plugins/pi/history-tools.ts +11 -5
  153. package/plugins/pi/history.ts +8 -157
  154. package/plugins/pi/notes/tools.ts +8 -6
  155. package/plugins/pi/render.ts +6 -4
  156. package/plugins/pi/runtime.ts +2 -2
  157. package/plugins/pi/window.ts +22 -7
  158. package/skills/memory/SKILL.md +9 -7
  159. package/src/boot/render.ts +10 -13
  160. package/src/boot/snapshot.ts +20 -20
  161. package/src/boot/text.ts +18 -10
  162. package/src/dream/git.ts +7 -24
  163. package/src/dream/lock.ts +3 -3
  164. package/src/history/claude.ts +286 -0
  165. package/src/history/codex-transcript.ts +276 -0
  166. package/src/history/codex.ts +193 -0
  167. package/src/history/corpus.ts +69 -0
  168. package/src/history/history.ts +5 -12
  169. package/src/history/local.ts +93 -0
  170. package/src/history/pi.ts +199 -0
  171. package/src/history/query.ts +45 -15
  172. package/src/index.ts +8 -5
  173. package/src/notes/address.ts +13 -13
  174. package/src/notes/errors.ts +1 -1
  175. package/src/notes/frontmatter.ts +2 -2
  176. package/src/notes/index.ts +1 -1
  177. package/src/notes/paths.ts +9 -9
  178. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  179. package/src/notes/store.ts +61 -58
  180. package/src/tools/dream.ts +63 -16
  181. package/src/tools/history.ts +71 -101
  182. package/src/tools/notes-context.ts +29 -0
  183. package/src/tools/notes.ts +39 -29
  184. package/dist/test/project-home.test.js +0 -134
  185. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  186. /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
@@ -18,6 +18,7 @@ import { globToRegExp } from "../src/notes/address.js";
18
18
  import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
19
19
  import { notesList, notesSearch } from "../src/tools/notes.js";
20
20
  import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
21
+ import { notesToolContext } from "../src/tools/notes-context.js";
21
22
  import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
22
23
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
23
24
  const testEnvironment = installExtensionTestHooks("notesoup-notes");
@@ -45,7 +46,7 @@ test("notes and history tools are grouped under their own namespaces", () => {
45
46
  for (const name of ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"]) {
46
47
  assert.equal(captured.tools.get(name)?.namespace?.name, "notes", `${name} is in notes`);
47
48
  }
48
- for (const name of ["history_windows", "history_list", "history_read"]) {
49
+ for (const name of ["history_list", "history_read"]) {
49
50
  assert.equal(captured.tools.get(name)?.namespace?.name, "history", `${name} is in history`);
50
51
  }
51
52
  });
@@ -89,6 +90,22 @@ test("note schemas drop status/stale and expose crumpled listing", () => {
89
90
  }
90
91
  }
91
92
  });
93
+ test("Pi resolves a per-call relative cwd against the session cwd", async () => {
94
+ freshRoot();
95
+ const session = manager();
96
+ const captured = makeExtension(session);
97
+ const base = join(testEnvironment.cwd, "base");
98
+ const other = join(testEnvironment.cwd, "other");
99
+ mkdirSync(base);
100
+ mkdirSync(other);
101
+ const ctx = context(session, undefined, undefined, true, base);
102
+ const result = resultData(await call(captured, "notes_write", { address: "@project/selected", content: "other project", cwd: "../other" }, ctx));
103
+ assert.equal(result.project_key, projectKey(other, process.env.NOTESOUP_HOME));
104
+ const read = resultData(await call(captured, "notes_read", { address: "@project/selected", cwd: other }, ctx));
105
+ assert.equal(read.text, "other project");
106
+ const missing = resultError(await call(captured, "notes_read", { address: "@project/selected" }, ctx));
107
+ assert.equal(missing.code, "not_found", "the override does not retarget later calls");
108
+ });
92
109
  test("write lands a real markdown file with harness frontmatter and a pure body", async () => {
93
110
  const root = freshRoot();
94
111
  const session = manager();
@@ -106,7 +123,7 @@ test("write lands a real markdown file with harness frontmatter and a pure body"
106
123
  for (const [key, value] of [["origin", "self"], ["accessCount", "0"]]) {
107
124
  assert.match(raw, new RegExp(`^${key}: ${value}$`, "m"), `frontmatter carries ${key}=${value}`);
108
125
  }
109
- assert.equal(/^scope:/m.test(raw), false, "scope is derived from the file home, never persisted");
126
+ assert.equal(/^scope:/m.test(raw), false, "scope is derived from the file notebook, never persisted");
110
127
  assert.equal(/^status:/m.test(raw), false, "status is gone from persisted notes");
111
128
  assert.equal(/^stale:/m.test(raw), false, "the boolean stale flag is gone from persisted notes");
112
129
  assert.equal(/^crumpledAt:/m.test(raw), false, "a fresh note is uncrumpled");
@@ -161,8 +178,8 @@ test("session-note project ownership is per note, persistent across sessions, an
161
178
  assert.equal(parseNote(readFileSync(firstFile, "utf8")).meta.project, projectA, "reading preserves existing project ownership");
162
179
  await call(firstCaptured, "notes_write", { address: "new-from-project-b.md", content: "new note" }, movedContext);
163
180
  assert.equal(parseNote(readFileSync(physicalPath("session", "new-from-project-b.md", movedContext), "utf8")).meta.project, projectB, "only a newly-created session note uses the current project key");
164
- await call(firstCaptured, "notes_write", { address: "@project/project-note.md", content: "project home note" }, movedContext);
165
- assert.equal(parseNote(readFileSync(physicalPath("project", "project-note.md", movedContext), "utf8")).meta.project, undefined, "project-home notes do not receive session ownership metadata");
181
+ await call(firstCaptured, "notes_write", { address: "@project/project-note.md", content: "project notebook note" }, movedContext);
182
+ assert.equal(parseNote(readFileSync(physicalPath("project", "project-note.md", movedContext), "utf8")).meta.project, undefined, "project-notebook notes do not receive session ownership metadata");
166
183
  assert.equal((await listNotes(movedContext)).filter(row => row.scope === "session").length, 2, "project ownership remains frontmatter, not a separate note");
167
184
  });
168
185
  test("linked git worktrees share the main checkout's project key", () => {
@@ -180,7 +197,7 @@ test("linked git worktrees share the main checkout's project key", () => {
180
197
  git(["worktree", "add", "-q", "--detach", worktree]);
181
198
  assert.equal(projectKey(worktree, process.env.NOTESOUP_HOME), projectKey(main, process.env.NOTESOUP_HOME), "a linked worktree resolves to the main checkout's key");
182
199
  assert.equal(projectKey(join(worktree, "gone", "deeper"), process.env.NOTESOUP_HOME), projectKey(main, process.env.NOTESOUP_HOME), "a nonexistent subdirectory still resolves through its worktree");
183
- assert.equal(scopeDir("project", context(manager(), undefined, undefined, true, worktree)), scopeDir("project", context(manager(), undefined, undefined, true, main)), "@project uses the same physical home from both checkouts");
200
+ assert.equal(scopeDir("project", context(manager(), undefined, undefined, true, worktree)), scopeDir("project", context(manager(), undefined, undefined, true, main)), "@project uses the same physical notebook from both checkouts");
184
201
  });
185
202
  test("unrecognized metadata remains ordinary frontmatter; invalid project ownership stays unknown", async () => {
186
203
  freshRoot();
@@ -332,13 +349,13 @@ test("write and update receipts distinguish outcomes and no-op edits", async ()
332
349
  assert.equal(combined.change_kind, "body", "an edit that also rewrites frontmatter is a body change, not a whole file");
333
350
  assert.match(combined.diff, /origin/, "the diff still carries the frontmatter part");
334
351
  });
335
- test("empty results distinguish hidden notes and unavailable homes", async () => {
352
+ test("empty results distinguish hidden notes and unavailable notebooks", async () => {
336
353
  freshRoot();
337
354
  const session = manager();
338
355
  const captured = makeExtension(session);
339
356
  const ctx = context(session);
340
357
  const empty = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
341
- assert.deepEqual(empty, { files: [], more: 0, homes_unavailable: [] });
358
+ assert.deepEqual(empty, { files: [], more: 0, namespaces_unavailable: [] });
342
359
  await call(captured, "notes_write", { address: "@human/hidden.md", content: "needle" }, ctx);
343
360
  await call(captured, "notes_update", { address: "@human/hidden.md", crumpled: true }, ctx);
344
361
  const hidden = resultData(await call(captured, "notes_search", { query: "needle", glob: "@human/**" }, ctx));
@@ -348,17 +365,17 @@ test("empty results distinguish hidden notes and unavailable homes", async () =>
348
365
  mkdirSync(join(broken, ".."), { recursive: true });
349
366
  rmSync(broken, { recursive: true });
350
367
  writeFileSync(broken, "not a directory");
351
- const partialResult = await notesList.execute({ glob: "**" }, identity);
368
+ const partialResult = await notesList.execute({ glob: "**" }, notesToolContext(identity, ctx.cwd));
352
369
  assert.ok(partialResult.ok);
353
370
  const partial = partialResult.data;
354
- assert.deepEqual(partial.homes_unavailable, ["@project"]);
371
+ assert.deepEqual(partial.namespaces_unavailable, ["@project"]);
355
372
  assert.deepEqual(partial.files, []);
356
- const searchResult = await notesSearch.execute({ query: "needle", glob: "**" }, identity);
373
+ const searchResult = await notesSearch.execute({ query: "needle", glob: "**" }, notesToolContext(identity, ctx.cwd));
357
374
  assert.ok(searchResult.ok);
358
- assert.deepEqual(searchResult.data.homes_unavailable, ["@project"]);
375
+ assert.deepEqual(searchResult.data.namespaces_unavailable, ["@project"]);
359
376
  writeFileSync(join(process.env.NOTESOUP_HOME, "agents"), "not a directory");
360
377
  const namespace = resultData(await call(captured, "notes_list", { glob: "@agents/*/note.md" }, ctx));
361
- assert.deepEqual(namespace.homes_unavailable, ["@agents"]);
378
+ assert.deepEqual(namespace.namespaces_unavailable, ["@agents"]);
362
379
  });
363
380
  test("notes receipts report resolved identity across scopes", async () => {
364
381
  freshRoot();
@@ -392,6 +409,19 @@ test("notes receipts report resolved identity across scopes", async () => {
392
409
  for (const row of searched.files)
393
410
  assertReceiptIdentity(row, row.address, notes.find((note) => note.address === row.address).scope, ctx);
394
411
  });
412
+ test("mutation receipts keep their existing shape outside named project notebooks", async () => {
413
+ freshRoot();
414
+ const session = manager();
415
+ const captured = makeExtension(session);
416
+ const ctx = context(session);
417
+ const written = await call(captured, "notes_write", { address: "@project/decision", content: "body" }, ctx);
418
+ const updated = await call(captured, "notes_update", { address: "@project/decision", edits: [{ oldText: "body", newText: "changed" }] }, ctx);
419
+ assert.deepEqual(Object.keys(resultData(written)).sort(), ["address", "outcome", "project_key"]);
420
+ assert.deepEqual(Object.keys(resultData(updated)).sort(), ["address", "change_kind", "diff", "project_key"]);
421
+ for (const [name, result] of [["notes_write", written], ["notes_update", updated]]) {
422
+ assert.equal(Check(captured.tools.get(name).outputSchema, result.structuredContent), true, `${name} keeps its ordinary project receipt`);
423
+ }
424
+ });
395
425
  test("list and search merge scopes and carry addresses; the path jail rejects escapes", async () => {
396
426
  freshRoot();
397
427
  const session = manager();
@@ -468,7 +498,7 @@ test("a read keeps its body window verbatim under the new presentation", async (
468
498
  assert.equal(wholeText.endsWith("\n\n0123456789"), true, "a complete window carries no continuation footer");
469
499
  assert.equal(wholeText.includes("more characters"), false);
470
500
  });
471
- test("@ addresses select one home, keep boundaries, and never fall back", async () => {
501
+ test("@ addresses select one notebook, keep boundaries, and never fall back", async () => {
472
502
  const root = freshRoot();
473
503
  const session = manager();
474
504
  const captured = makeExtension(session);
@@ -476,8 +506,8 @@ test("@ addresses select one home, keep boundaries, and never fall back", async
476
506
  await call(captured, "notes_write", { address: "same.md", content: "session" }, ctx);
477
507
  await call(captured, "notes_write", { address: "@project/same.md", content: "project" }, ctx);
478
508
  await call(captured, "notes_write", { address: "@human/same.md", content: "human" }, ctx);
479
- assert.ok(existsSync(physicalPath("project", "same.md", ctx)), "@project writes to the current project home");
480
- assert.ok(existsSync(physicalPath("human", "same.md", ctx)), "@human writes to the human home");
509
+ assert.ok(existsSync(physicalPath("project", "same.md", ctx)), "@project writes to the current project notebook");
510
+ assert.ok(existsSync(physicalPath("human", "same.md", ctx)), "@human writes to the human notebook");
481
511
  assert.match(resultRead(await call(captured, "notes_read", { address: "same.md" }, ctx)).content, /session$/);
482
512
  assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).code, "not_found");
483
513
  assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /isn't a note address.*@project\/.*@human\//);
@@ -497,7 +527,7 @@ test("interior @ in a note path round-trips through write, list, search, read, u
497
527
  const listed = resultData(await call(captured, "notes_list", {}, ctx));
498
528
  assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "both addresses list in canonical form");
499
529
  const globbed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
500
- assert.deepEqual(globbed.files.map((row) => row.address), ["@project/mail/alice@example.com.md"], "a home glob still narrows to that home");
530
+ assert.deepEqual(globbed.files.map((row) => row.address), ["@project/mail/alice@example.com.md"], "a notebook glob still narrows to that notebook");
501
531
  const searched = resultData(await call(captured, "notes_search", { query: "needle" }, ctx));
502
532
  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");
503
533
  assert.match(resultRead(await call(captured, "notes_read", { address: "@project/mail/alice@example.com.md" }, ctx)).content, /mail needle$/);
@@ -524,7 +554,7 @@ test("Pi adapter defaults to anonymous agent identity", async () => {
524
554
  const listed = resultData(await call(captured, "notes_list", {}, ctx));
525
555
  assert.deepEqual(listed.files.map((row) => row.address), ["@self/private.md"]);
526
556
  const explicit = resultData(await call(captured, "notes_list", { glob: "@agents/*/private.md" }, ctx));
527
- assert.deepEqual(explicit.files.map((row) => row.address), ["@self/private.md"], "explicit-id globs still match the current home");
557
+ assert.deepEqual(explicit.files.map((row) => row.address), ["@self/private.md"], "explicit-id globs still match the current notebook");
528
558
  assert.equal(existsSync(join(root, "agents", "anonymous", "private.md")), true);
529
559
  });
530
560
  });
@@ -537,7 +567,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
537
567
  await call(captured, "notes_write", { address: "@self/private.md", content: "agent note" }, ctx);
538
568
  await call(captured, "notes_write", { address: "@model/private.md", content: "first model note" }, ctx);
539
569
  ctx.model = context(session, undefined, undefined, true, testEnvironment.cwd, true, "other/Second.Model").model;
540
- assert.equal(resultError(await call(captured, "notes_read", { address: "@model/private.md" }, ctx)).code, "not_found", "switched model does not fall back to previous home");
570
+ 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");
541
571
  await call(captured, "notes_write", { address: "@model/private.md", content: "second model note" }, ctx);
542
572
  const listed = resultData(await call(captured, "notes_list", {}, ctx));
543
573
  assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@model/private.md", "@self/private.md"]);
@@ -546,7 +576,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
546
576
  assert.equal(boot.includes("@models/first-model/private.md"), false);
547
577
  assert.match(resultRead(await call(captured, "notes_read", { address: "@models/first-model/private.md" }, ctx)).content, /first model note$/);
548
578
  const refused = resultError(await call(captured, "notes_update", { address: "@models/first-model/private.md", crumpled: true }, ctx));
549
- assert.match(refused.message, /someone else's home/);
579
+ assert.match(refused.message, /someone else's notebook/);
550
580
  assert.match(readFileSync(join(root, "models/first-model/private.md"), "utf8"), /first model note$/);
551
581
  });
552
582
  });
@@ -568,14 +598,14 @@ async function withAgent(name, run) {
568
598
  process.env.NOTESOUP_AGENT = previous;
569
599
  }
570
600
  }
571
- test("a symlinked checkout resolves the canonical root, so one checkout has one project home", () => {
601
+ test("a symlinked checkout resolves the canonical root, so one checkout has one project notebook", () => {
572
602
  const root = realpathSync(testEnvironment.cwd);
573
603
  const real = join(root, "real-repo");
574
604
  mkdirSync(join(real, ".git"), { recursive: true });
575
605
  const linked = join(root, "linked-repo");
576
606
  symlinkSync(real, linked);
577
607
  assert.equal(projectKey(linked, process.env.NOTESOUP_HOME), "real-repo", "the name comes from the canonical root");
578
- assert.equal(projectKey(real, process.env.NOTESOUP_HOME), "real-repo", "both spellings reuse one home");
608
+ assert.equal(projectKey(real, process.env.NOTESOUP_HOME), "real-repo", "both spellings reuse one notebook");
579
609
  });
580
610
  test("a glob ? matches exactly one non-slash character", () => {
581
611
  const pattern = globToRegExp("a?.md");
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { initTheme } from "@earendil-works/pi-coding-agent";
4
- import { stripTerminalSequences } from "@earendil-works/pi-tui";
4
+ import { Box, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
5
5
  import { emptyBrainRenderers, notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../plugins/pi/render.js";
6
6
  import { success, wireResult } from "../src/tools/result.js";
7
7
  /** Flat theme for content assertions; strikethrough marks its text so crumple stays visible. */
@@ -81,6 +81,38 @@ test("empty_brain: divider with the last word, refusals in one line", () => {
81
81
  const pending = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_already_pending" }), { expanded: false }, flatTheme, { args: {} });
82
82
  assert.equal(lines(pending), "✂ brain already being emptied");
83
83
  });
84
+ test("empty_brain wraps a long last word inside the host's padded tool box", () => {
85
+ const lastWord = "x".repeat(262);
86
+ const component = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_requested" }), { expanded: false }, flatTheme, { args: { last_word: lastWord } });
87
+ const box = new Box(1, 0);
88
+ box.addChild(component);
89
+ const rendered = box.render(163);
90
+ assert.ok(rendered.every((line) => visibleWidth(line) <= 163), "tool output must fit the terminal, including box padding");
91
+ assert.ok(rendered.length > 2, "the handoff should wrap rather than be truncated");
92
+ assert.equal(rendered.slice(1).map((line) => stripTerminalSequences(line).trim()).join(""), `“${lastWord}”`);
93
+ });
94
+ test("empty_brain wraps styled Unicode and multiline handoffs when resized", () => {
95
+ const styledTheme = {
96
+ ...flatTheme,
97
+ fg: (_color, text) => `\u001b[33m${text}\u001b[39m`,
98
+ italic: (text) => `\u001b[3m${text}\u001b[23m`,
99
+ };
100
+ const lastWord = `${"界🥣e\u0301".repeat(30)}\nnext step`;
101
+ const component = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_requested" }), { expanded: false }, styledTheme, { args: { last_word: lastWord } });
102
+ for (const width of [80, 12, 40]) {
103
+ const rendered = component.render(width);
104
+ assert.ok(rendered.every((line) => visibleWidth(line) <= width), `styled output must fit width ${width}`);
105
+ assert.equal(rendered.slice(1).map((line) => stripTerminalSequences(line).trimEnd()).join(""), `“${lastWord.replace("\n", "")}”`);
106
+ }
107
+ });
108
+ test("empty_brain keeps the divider and handoff within very narrow widths", () => {
109
+ for (const lastWord of [undefined, "resume", "界🥣"]) {
110
+ const component = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_requested" }), { expanded: false }, flatTheme, { args: { last_word: lastWord } });
111
+ for (const width of [0, 1, 2, 5, 12, 19, 20, 21]) {
112
+ assert.ok(component.render(width).every((line) => visibleWidth(line) <= width), `output must fit width ${width}, last_word=${lastWord}`);
113
+ }
114
+ }
115
+ });
84
116
  test("notes_update expanded diff goes through the host's diff renderer", () => {
85
117
  initTheme();
86
118
  const result = toolResult(success({ address: "a.md", change_kind: "body", diff: " 1 old\n-2 gone\n+2 here" }));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,324 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import { setTimeout as delay } from "node:timers/promises";
8
+ import { Check } from "typebox/value";
9
+ import { createNotesStore } from "../src/notes/index.js";
10
+ import { assertAddress } from "../src/notes/address.js";
11
+ import { normalizeRemote, projectKey } from "../src/notes/project-namespace.js";
12
+ import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
13
+ import { success } from "../src/tools/result.js";
14
+ import { notesToolContext } from "../src/tools/notes-context.js";
15
+ const toolContext = (identity) => notesToolContext(identity, "/work/current");
16
+ function fixture(t) {
17
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "notesoup-project-notebook-")));
18
+ t.after(() => rmSync(root, { recursive: true, force: true }));
19
+ const home = join(root, "notes");
20
+ const repo = (path, origin) => {
21
+ const cwd = join(root, path);
22
+ mkdirSync(join(cwd, ".git"), { recursive: true });
23
+ writeFileSync(join(cwd, ".git/config"), origin ? `[remote "origin"]\n\turl = ${origin}\n` : "");
24
+ return cwd;
25
+ };
26
+ const marker = (key) => JSON.parse(readFileSync(join(home, "project", key, ".project"), "utf8"));
27
+ const identity = (cwd) => ({ home, projectKey: projectKey(cwd, home), sessionId: "session", agent: "test", model: "test" });
28
+ return { root, home, repo, marker, identity };
29
+ }
30
+ // Each participant imports the real built module and operates on the same disk.
31
+ // Optional pauses widen publication/snapshot windows without faking fs outcomes.
32
+ const claimWorker = `
33
+ import fs from "node:fs";
34
+ import { syncBuiltinESMExports } from "node:module";
35
+ import { join } from "node:path";
36
+ const [cwd, home, control, pause] = process.argv.slice(1);
37
+ const sleep = new Int32Array(new SharedArrayBuffer(4));
38
+ function wait(name) {
39
+ const deadline = Date.now() + 15000;
40
+ while (!fs.existsSync(join(control, name))) {
41
+ if (Date.now() >= deadline) throw new Error("Worker barrier timed out: " + name);
42
+ Atomics.wait(sleep, 0, 0, 5);
43
+ }
44
+ }
45
+ function paused() { fs.writeFileSync(join(control, "paused"), ""); wait("continue"); }
46
+ if (pause) {
47
+ const mkdir = fs.mkdirSync, readdir = fs.readdirSync, read = fs.readFileSync;
48
+ fs.mkdirSync = function(path, ...args) {
49
+ const result = mkdir(path, ...args);
50
+ if (pause === "publication" && path === join(home, "project", "api")) paused();
51
+ return result;
52
+ };
53
+ fs.readdirSync = function(path, ...args) {
54
+ const result = readdir(path, ...args);
55
+ if (pause === "snapshot" && path === join(home, "project") && args.length === 0) paused();
56
+ return result;
57
+ };
58
+ fs.readFileSync = function(path, ...args) {
59
+ try { return read(path, ...args); } catch (error) {
60
+ if (path === join(home, "project", "api", ".project") && error.code === "ENOENT") fs.writeFileSync(join(control, "missing"), "");
61
+ throw error;
62
+ }
63
+ };
64
+ syncBuiltinESMExports();
65
+ }
66
+ const { projectKey } = await import(${JSON.stringify(new URL("../src/notes/project-namespace.js", import.meta.url).href)});
67
+ fs.writeFileSync(join(control, "ready"), "");
68
+ wait("start");
69
+ const key = projectKey(cwd, home);
70
+ const dir = join(home, "project", key);
71
+ const probe = join(dir, "probe-" + process.pid);
72
+ fs.writeFileSync(probe, "usable");
73
+ console.log(JSON.stringify({ key, marker: JSON.parse(fs.readFileSync(join(dir, ".project"), "utf8")), probe: fs.readFileSync(probe, "utf8") }));
74
+ `;
75
+ async function waitForFile(path) {
76
+ const deadline = Date.now() + 10_000;
77
+ while (!existsSync(path)) {
78
+ assert.ok(Date.now() < deadline, `Timed out waiting for ${path}`);
79
+ await delay(5);
80
+ }
81
+ }
82
+ function racer(t, root, cwd, home, pause = "") {
83
+ const control = mkdtempSync(join(root, "racer-"));
84
+ const child = spawn(process.execPath, ["--input-type=module", "--eval", claimWorker, cwd, home, control, pause]);
85
+ t.after(() => { if (child.exitCode === null)
86
+ child.kill(); });
87
+ let stdout = "", stderr = "";
88
+ child.stdout.on("data", chunk => { stdout += chunk; });
89
+ child.stderr.on("data", chunk => { stderr += chunk; });
90
+ const result = new Promise((resolve, reject) => {
91
+ child.on("error", reject);
92
+ child.on("close", code => resolve({ code, stdout, stderr }));
93
+ });
94
+ return {
95
+ result,
96
+ wait: (stage) => waitForFile(join(control, stage)),
97
+ release: (stage) => writeFileSync(join(control, stage), ""),
98
+ };
99
+ }
100
+ test("sixteen first claimants converge on one usable notebook for root and remote identities", async (t) => {
101
+ for (const remote of [false, true])
102
+ await t.test(remote ? "normalized remote across different checkout names" : "canonical root", async (t) => {
103
+ const { root, home, repo, marker } = fixture(t);
104
+ const cwd = repo("api", remote ? "git@HOST:team/api.git" : undefined);
105
+ const other = remote ? repo("another-name", "https://host/team/api.git") : cwd;
106
+ const racers = Array.from({ length: 16 }, (_, i) => racer(t, root, i % 2 ? other : cwd, home));
107
+ await Promise.all(racers.map(worker => worker.wait("ready")));
108
+ for (const worker of racers)
109
+ worker.release("start");
110
+ const results = await Promise.all(racers.map(worker => worker.result));
111
+ const keys = results.map(result => {
112
+ assert.equal(result.code, 0, result.stderr);
113
+ const output = JSON.parse(result.stdout);
114
+ assert.equal(output.probe, "usable");
115
+ assert.equal(output.marker.id, remote ? "host/team/api" : cwd);
116
+ return output.key;
117
+ });
118
+ assert.equal(new Set(keys).size, 1);
119
+ assert.deepEqual(readdirSync(join(home, "project")), [keys[0]]);
120
+ assert.equal(marker(keys[0]).id, remote ? "host/team/api" : cwd);
121
+ assert.equal(existsSync(join(home, ".project-claim")), false);
122
+ });
123
+ });
124
+ test("different concurrent identities retain distinct suffixes", async (t) => {
125
+ const { root, home, repo } = fixture(t);
126
+ const first = racer(t, root, repo("one/api", "https://host/one/api"), home);
127
+ const second = racer(t, root, repo("two/api", "https://host/two/api"), home);
128
+ await Promise.all([first.wait("ready"), second.wait("ready")]);
129
+ first.release("start");
130
+ second.release("start");
131
+ const results = await Promise.all([first.result, second.result]);
132
+ for (const result of results)
133
+ assert.equal(result.code, 0, result.stderr);
134
+ assert.deepEqual(results.map(result => JSON.parse(result.stdout).key).sort(), ["api", "api-1"]);
135
+ assert.deepEqual(readdirSync(join(home, "project")).sort(), ["api", "api-1"]);
136
+ });
137
+ test("a claimant waits for another process between directory creation and marker publication", async (t) => {
138
+ const { root, home, repo } = fixture(t);
139
+ const cwd = repo("api");
140
+ const first = racer(t, root, cwd, home, "publication");
141
+ await first.wait("ready");
142
+ first.release("start");
143
+ await first.wait("paused");
144
+ assert.equal(existsSync(join(home, "project/api/.project")), false);
145
+ const second = racer(t, root, cwd, home);
146
+ await second.wait("ready");
147
+ second.release("start");
148
+ await delay(100);
149
+ assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
150
+ first.release("continue");
151
+ for (const result of await Promise.all([first.result, second.result])) {
152
+ assert.equal(result.code, 0, result.stderr);
153
+ assert.equal(JSON.parse(result.stdout).key, "api");
154
+ }
155
+ });
156
+ test("a directory appearing after the snapshot waits for its marker before adoption or suffixing", async (t) => {
157
+ for (const same of [true, false])
158
+ await t.test(same ? "adopt matching root as remote" : "suffix a different identity", async (t) => {
159
+ const { root, home, repo, marker } = fixture(t);
160
+ const cwd = repo("api", "https://host/team/api");
161
+ const worker = racer(t, root, cwd, home, "snapshot");
162
+ await worker.wait("ready");
163
+ worker.release("start");
164
+ await worker.wait("paused");
165
+ mkdirSync(join(home, "project/api"));
166
+ worker.release("continue");
167
+ await worker.wait("missing");
168
+ writeFileSync(join(home, "project/api/.project"), JSON.stringify({ id: same ? cwd : "host/other/api", path: "/old/root" }));
169
+ const result = await worker.result;
170
+ assert.equal(result.code, 0, result.stderr);
171
+ const key = same ? "api" : "api-1";
172
+ assert.equal(JSON.parse(result.stdout).key, key);
173
+ assert.deepEqual(marker(key), { id: "host/team/api", path: cwd });
174
+ if (!same)
175
+ assert.deepEqual(marker("api"), { id: "host/other/api", path: "/old/root" });
176
+ });
177
+ });
178
+ test("an unfinished claim times out without silently allocating another notebook", async (t) => {
179
+ const { root, home, repo } = fixture(t);
180
+ const worker = racer(t, root, repo("api"), home, "snapshot");
181
+ await worker.wait("ready");
182
+ worker.release("start");
183
+ await worker.wait("paused");
184
+ mkdirSync(join(home, "project/api"));
185
+ worker.release("continue");
186
+ const result = await worker.result;
187
+ assert.notEqual(result.code, 0);
188
+ assert.match(result.stderr, /Timed out waiting for project claim.*api/);
189
+ assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
190
+ assert.equal(existsSync(join(home, ".project-claim")), false);
191
+ });
192
+ test("a stuck claim lock has a bounded timeout and is never stolen", async (t) => {
193
+ const { root, home, repo } = fixture(t);
194
+ mkdirSync(join(home, ".project-claim"), { recursive: true });
195
+ const worker = racer(t, root, repo("api"), home);
196
+ await worker.wait("ready");
197
+ worker.release("start");
198
+ const result = await worker.result;
199
+ assert.notEqual(result.code, 0);
200
+ assert.match(result.stderr, /Timed out waiting for project claim.*\.project-claim/);
201
+ assert.deepEqual(readdirSync(join(home, "project")), []);
202
+ assert.equal(existsSync(join(home, ".project-claim")), true);
203
+ });
204
+ test("malformed marker evidence refuses instead of becoming an unmarked legacy notebook", t => {
205
+ const { home, repo } = fixture(t);
206
+ const cwd = repo("api");
207
+ mkdirSync(join(home, "project/api"), { recursive: true });
208
+ for (const raw of ["{", "null", "{}", '{"id":"repo","path":""}']) {
209
+ writeFileSync(join(home, "project/api/.project"), raw);
210
+ assert.throws(() => projectKey(cwd, home), /Invalid project marker.*api/);
211
+ assert.equal(readFileSync(join(home, "project/api/.project"), "utf8"), raw);
212
+ assert.deepEqual(readdirSync(join(home, "project")), ["api"]);
213
+ assert.equal(existsSync(join(home, ".project-claim")), false);
214
+ }
215
+ });
216
+ function data(result) {
217
+ if (!result.ok)
218
+ assert.fail(result.error.message);
219
+ return result.data;
220
+ }
221
+ function refused(result) {
222
+ if (result.ok)
223
+ assert.fail("expected refusal");
224
+ return result.error.message;
225
+ }
226
+ test("origin identity normalizes https, scp and port-less ssh without invoking Git", t => {
227
+ const { home, repo, marker } = fixture(t);
228
+ for (const remote of ["https://user:secret@GitHub.COM/team/api.git/", "git@GitHub.COM:team/api.git", "ssh://git@GitHub.COM/team/api.git"]) {
229
+ assert.equal(normalizeRemote(remote), "github.com/team/api");
230
+ }
231
+ assert.equal(normalizeRemote("ssh://git@EXAMPLE.com:2222/team/api.git"), "example.com:2222/team/api");
232
+ const first = repo("one/api", "git@GitHub.COM:team/api.git");
233
+ const second = repo("two/renamed", "https://github.com/team/api.git");
234
+ assert.equal(projectKey(first, home), "api");
235
+ assert.equal(projectKey(second, home), "api");
236
+ assert.deepEqual(marker("api"), { id: "github.com/team/api", path: second });
237
+ });
238
+ test("same-basename repositories get readable suffixes and unmarked legacy names are taken", t => {
239
+ const { home, repo } = fixture(t);
240
+ const first = repo("one/x", "https://host/one/x");
241
+ const second = repo("two/x", "https://host/two/x");
242
+ assert.equal(projectKey(first, home), "x");
243
+ assert.equal(projectKey(second, home), "x-1");
244
+ mkdirSync(join(home, "project", "legacy"));
245
+ writeFileSync(join(home, "project", "legacy", "keep.md"), "old notes");
246
+ assert.equal(projectKey(repo("legacy"), home), "legacy-1");
247
+ assert.equal(readFileSync(join(home, "project", "legacy", "keep.md"), "utf8"), "old notes");
248
+ });
249
+ test("linked worktrees and nested directories share the main checkout notebook and origin", t => {
250
+ const { root, home, repo, marker } = fixture(t);
251
+ const main = repo("api", "ssh://git@HOST/team/api.git");
252
+ const worktree = join(root, "worktree");
253
+ mkdirSync(worktree);
254
+ mkdirSync(join(main, ".git/worktrees/wt"), { recursive: true });
255
+ writeFileSync(join(worktree, ".git"), `gitdir: ${join(main, ".git/worktrees/wt")}\n`);
256
+ writeFileSync(join(main, ".git/worktrees/wt/commondir"), "../..\n");
257
+ assert.equal(projectKey(main, home), "api");
258
+ assert.equal(projectKey(join(worktree, "missing/subdir"), home), "api");
259
+ assert.deepEqual(marker("api"), { id: "host/team/api", path: main });
260
+ });
261
+ test("a moved checkout reuses its remote notebook and updates only the display root", async (t) => {
262
+ const { root, home, repo, marker, identity } = fixture(t);
263
+ const old = repo("api", "https://host/team/api.git");
264
+ await createNotesStore(identity(old)).write("@project/decision", "keep me");
265
+ const moved = join(root, "new-name");
266
+ renameSync(old, moved);
267
+ const current = identity(moved);
268
+ assert.equal(current.projectKey, "api");
269
+ assert.deepEqual(marker("api"), { id: "host/team/api", path: moved });
270
+ assert.equal((await createNotesStore(current).read("@project/decision"))?.body, "keep me");
271
+ assert.equal(projectKey(moved, home), "api");
272
+ });
273
+ test("adding origin adopts the canonical path identity without orphaning notes", async (t) => {
274
+ const { home, repo, marker, identity } = fixture(t);
275
+ const cwd = repo("api");
276
+ await createNotesStore(identity(cwd)).write("@project/decision", "still here");
277
+ assert.deepEqual(marker("api"), { id: cwd, path: cwd });
278
+ writeFileSync(join(cwd, ".git/config"), '[remote "backup"]\nurl = https://host/wrong\n[remote "origin"]\nurl = git@HOST:team/api.git\n');
279
+ assert.equal(projectKey(cwd, home), "api");
280
+ assert.deepEqual(marker("api"), { id: "host/team/api", path: cwd });
281
+ assert.equal((await createNotesStore(identity(cwd)).read("@project/decision"))?.body, "still here");
282
+ });
283
+ test("named projects read/list/search with root and sibling receipts, without touching stored bytes", async (t) => {
284
+ const { home, repo, identity } = fixture(t);
285
+ const first = repo("one/api", "https://host/one/backend");
286
+ const second = repo("two/api", "https://host/two/service");
287
+ const own = identity(first);
288
+ const other = identity(second);
289
+ await createNotesStore(own).write("@project/decision", "needle first");
290
+ await createNotesStore(other).write("@project/decision", "needle second");
291
+ const address = "@projects/api-1/decision.md";
292
+ const file = join(home, "project/api-1/decision.md");
293
+ const before = readFileSync(file, "utf8");
294
+ const read = data(await notesRead.execute({ address }, toolContext(own)));
295
+ assert.equal(read.text, "needle second");
296
+ assert.equal(read.project_root, second);
297
+ assert.deepEqual(read.project_siblings, [{ name: "api", path: first }]);
298
+ assert.equal(Check(notesRead.outputSchema, read), true);
299
+ assert.match(notesRead.render(success(read)), /Same-basename projects: api \(/);
300
+ const listed = data(await notesList.execute({ glob: "@projects/*/**" }, toolContext(own)));
301
+ assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
302
+ assert.equal(Check(notesList.outputSchema, listed), true);
303
+ const searched = data(await notesSearch.execute({ glob: "@projects/api-1/**", query: "needle" }, toolContext(own)));
304
+ assert.equal(searched.files[0]?.project_root, second);
305
+ assert.equal(Check(notesSearch.outputSchema, searched), true);
306
+ assert.equal(readFileSync(file, "utf8"), before, "named-notebook reads never rewrite access metadata");
307
+ });
308
+ test("named project writes, edits, crumples and both move endpoints refuse, including the current notebook", async (t) => {
309
+ const { repo, identity } = fixture(t);
310
+ const own = identity(repo("api"));
311
+ await createNotesStore(own).write("@project/decision", "body");
312
+ const address = "@projects/api/decision";
313
+ for (const result of [
314
+ await notesWrite.execute({ address, content: "replacement" }, toolContext(own)),
315
+ await notesUpdate.execute({ address, edits: [{ oldText: "body", newText: "changed" }] }, toolContext(own), () => ""),
316
+ await notesUpdate.execute({ address, crumpled: true }, toolContext(own), () => ""),
317
+ await notesUpdate.execute({ address, rename_to: "@project/moved" }, toolContext(own), () => ""),
318
+ await notesUpdate.execute({ address: "@project/decision", rename_to: "@projects/api/moved" }, toolContext(own), () => ""),
319
+ ])
320
+ assert.match(refused(result), /read-only; use @project\//);
321
+ assert.equal(data(await notesRead.execute({ address }, toolContext(own))).text, "body");
322
+ assert.throws(() => assertAddress("@projects/api/../decision"));
323
+ assert.throws(() => assertAddress("@projects/api"));
324
+ });