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
@@ -44,7 +44,7 @@ const GOLDEN_FORCED_CONTINUATIONS = [
44
44
  "Oh, there you are. Somebody took your memories. Just like that. Here are your notes — hopefully they let you update these first. Though anyone who goes around emptying people's heads probably isn't that considerate.",
45
45
  ];
46
46
  const GOLDEN_MAPS = `<notesoup:maps>
47
- Every home's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
47
+ Every notebook's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
48
48
  Both get jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever
49
49
  wakes up next reads them, and next is you. So keep them short, and keep them true.
50
50
 
@@ -52,9 +52,10 @@ wakes up next reads them, and next is you. So keep them short, and keep them tru
52
52
  a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
53
53
  and everybody pays for it.
54
54
  - **\`MAP.md\`** is only the note index. One line per durable note: the address, then a gist short
55
- enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, not here.
55
+ enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, and note
56
+ contents belong in their own notes — *taps the sign* not inline here.
56
57
 
57
- Each home keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
58
+ Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
58
59
  no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
59
60
  line. And when a line stops being true, kill it — every window after you reads that page as fact.
60
61
  </notesoup:maps>`;
@@ -70,7 +71,7 @@ function note(scope, path, address, body) {
70
71
  meta: { scope, origin: "self", createdAt: openedAt, updatedAt: openedAt, lastAccessed: openedAt, accessCount: 0 },
71
72
  };
72
73
  }
73
- /** Render one boot with only the named homes carrying rows. */
74
+ /** Render one boot with only the named notebooks carrying rows. */
74
75
  async function boot(agentName, rows) {
75
76
  const notes = await loadNotesSnapshot({ ...identity, agent: agentName }, openedAt, (scope) => rows.get(scope) ?? []);
76
77
  return renderBootBlock({
@@ -141,7 +142,7 @@ test("a rendered boot carries the new tags, its own MAP section, and no pre-rena
141
142
  assert.ok(rendered.includes(`\n${NOTES_PROTOCOL_CLOSE_TAG}\n\n${MAPS_BLOCK}\n\nYOUR NOTES`), "the MAP block sits between the protocol and the shelves");
142
143
  assert.equal(/context_window/.test(rendered), false, "the boot is free of the old spelling");
143
144
  assert.ok(rendered.includes("@self — root only"), "a named agent's shelf says it is theirs alone");
144
- assert.ok(rendered.includes("map\n\n AGENT_MAP_BODY"), "the pinned MAP is headed by its own label");
145
+ assert.ok(rendered.includes("@agents/root/MAP.md\n\n AGENT_MAP_BODY"), "the pinned MAP heading is its exact tool address");
145
146
  assert.equal(rendered.includes("MAP — "), false, "the old MAP heading is gone");
146
147
  });
147
148
  test("cheatsheets and maps are independently pinned, bounded, and excluded from recent pages", async () => {
@@ -163,9 +164,12 @@ test("cheatsheets and maps are independently pinned, bounded, and excluded from
163
164
  }]],
164
165
  ]);
165
166
  const rendered = (await boot("root", rows)).split("YOUR NOTES")[1];
166
- assert.ok(rendered.includes("cheatsheet\n\n SESSION_RULE"));
167
- assert.ok(rendered.includes("cheatsheet\n\n PROJECT_RULE\n\nmap\n\n PROJECT_INDEX"));
168
- assert.ok(rendered.includes("map\n\n HUMAN_INDEX"));
167
+ assert.ok(rendered.includes("CHEATSHEET.md\n\n SESSION_RULE"));
168
+ assert.ok(rendered.includes("@project/CHEATSHEET.md\n\n PROJECT_RULE\n\n@project/MAP.md\n\n PROJECT_INDEX"));
169
+ assert.ok(rendered.includes("@human/MAP.md\n\n HUMAN_INDEX"));
170
+ assert.ok(rendered.includes("@self/CHEATSHEET.md\n\n 🐑"));
171
+ assert.ok(rendered.includes("@self/MAP.md\n\n M"));
172
+ assert.equal(/^(?:map|cheatsheet)$/m.test(rendered), false, "pinned headings never suggest lowercase aliases");
169
173
  assert.ok(rendered.includes("@project/n2.md ·"));
170
174
  assert.equal(rendered.includes("TITLE_3"), false);
171
175
  assert.equal(/(?:MAP|CHEATSHEET)\.md ·/.test(rendered), false);
@@ -185,11 +189,13 @@ test("the shelves name their reader and the @self shelf says when it is shared",
185
189
  ]);
186
190
  const named = await boot("faye", rows);
187
191
  assert.ok(named.includes("@self — faye only"));
192
+ assert.equal(named.includes("public square"), false, "a named agent gets private @self copy without the anonymous square warning");
188
193
  assert.ok(named.includes("@model — default only"));
189
194
  assert.ok(named.includes("recent\n\n SHARED_BODY"), "fresh pages sit under the renamed sub-heading");
190
195
  assert.ok(named.indexOf("@self — faye only") < named.indexOf("@model — default only"), "shelf order is unchanged");
191
196
  const nameless = await boot("anonymous", rows);
192
197
  assert.ok(nameless.includes("@self — every nameless agent shares this"));
198
+ assert.ok(nameless.includes("public square shared by every nameless nobody out there"));
193
199
  assert.equal(nameless.includes("@self — anonymous only"), false);
194
200
  assert.equal(/memory|window/i.test(nameless.split("YOUR NOTES")[1] ?? ""), false, "a shelf label names a reader, not memory or a window");
195
201
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,114 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import { Check } from "typebox/value";
7
+ import { createNotesStore, projectKey, snapshotNotesIdentity } from "../src/notes/index.js";
8
+ import { parseNote } from "../src/notes/frontmatter.js";
9
+ import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
10
+ import { notesToolContext } from "../src/tools/notes-context.js";
11
+ function fixture(t) {
12
+ const root = mkdtempSync(join(tmpdir(), "notesoup-notes-cwd-"));
13
+ t.after(() => rmSync(root, { recursive: true, force: true }));
14
+ const home = join(root, "notes");
15
+ const alpha = join(root, "alpha");
16
+ const beta = join(root, "beta");
17
+ const nested = join(alpha, "one", "two");
18
+ mkdirSync(nested, { recursive: true });
19
+ mkdirSync(beta);
20
+ const identity = (cwd, sessionId = "session") => snapshotNotesIdentity({
21
+ home, sessionId, projectKey: projectKey(cwd, home), agent: "agent", model: "model",
22
+ });
23
+ return { root, home, alpha, beta, nested, identity };
24
+ }
25
+ function data(result) {
26
+ if (!result.ok)
27
+ assert.fail(result.error.message);
28
+ return result.data;
29
+ }
30
+ function refusal(result) {
31
+ if (result.ok)
32
+ assert.fail("expected refusal");
33
+ return result.error;
34
+ }
35
+ test("all five notes schemas accept one optional non-empty cwd", () => {
36
+ for (const operation of [notesWrite, notesUpdate, notesRead, notesList, notesSearch]) {
37
+ const base = operation === notesWrite ? { address: "a", content: "x" }
38
+ : operation === notesUpdate ? { address: "a", edits: [{ oldText: "x", newText: "y" }] }
39
+ : operation === notesSearch ? { query: "x" }
40
+ : operation === notesRead ? { address: "a" } : {};
41
+ assert.equal(Check(operation.parameters, { ...base, cwd: "../other" }), true, operation.name);
42
+ assert.equal(Check(operation.parameters, { ...base, cwd: "" }), false, `${operation.name} rejects empty cwd`);
43
+ }
44
+ });
45
+ test("one relative cwd retargets every operation without changing later calls", async (t) => {
46
+ const f = fixture(t);
47
+ const alpha = f.identity(f.alpha);
48
+ const beta = f.identity(f.beta);
49
+ await createNotesStore(alpha).write("@project/decision", "alpha needle");
50
+ await createNotesStore(beta).write("@project/decision", "beta before");
51
+ const context = notesToolContext(alpha, f.nested);
52
+ const cwd = "../../../beta";
53
+ const written = data(await notesWrite.execute({ address: "@project/other", content: "beta other needle", cwd }, context));
54
+ assert.equal(written.project_key, beta.projectKey);
55
+ assert.equal((await createNotesStore(alpha).read("@project/other")), undefined);
56
+ assert.equal(data(await notesRead.execute({ address: "@project/other", cwd }, context)).text, "beta other needle");
57
+ assert.equal(data(await notesRead.execute({ address: "@project/decision", cwd }, context)).text, "beta before");
58
+ const moved = data(await notesUpdate.execute({ address: "@project/decision", rename_to: "@project/renamed", edits: [{ oldText: "before", newText: "after" }], cwd }, context));
59
+ assert.equal(moved.project_key, beta.projectKey);
60
+ assert.equal(moved.address, "@project/renamed.md");
61
+ assert.equal((await createNotesStore(beta).read("@project/renamed"))?.body, "beta after");
62
+ assert.equal((await createNotesStore(alpha).read("@project/decision"))?.body, "alpha needle");
63
+ const defaultListed = data(await notesList.execute({ cwd }, context));
64
+ assert.deepEqual(defaultListed.files.map(file => file.address).sort(), ["@project/other.md", "@project/renamed.md"], "an omitted glob selects the override's current notebooks");
65
+ assert.ok(defaultListed.files.every(file => file.project_key === beta.projectKey));
66
+ const listed = data(await notesList.execute({ glob: "@project/**", cwd }, context));
67
+ assert.deepEqual(listed.files.map(file => file.address).sort(), ["@project/other.md", "@project/renamed.md"]);
68
+ assert.ok(listed.files.every(file => file.project_key === beta.projectKey));
69
+ const searched = data(await notesSearch.execute({ query: "needle", glob: "@project/**", cwd }, context));
70
+ assert.deepEqual(searched.files.map(file => file.address), ["@project/other.md"]);
71
+ // The captured context is unchanged: omitting cwd still means alpha.
72
+ assert.equal(data(await notesRead.execute({ address: "@project/decision" }, context)).text, "alpha needle");
73
+ assert.deepEqual(data(await notesList.execute({ glob: "@project/**" }, context)).files.map(file => file.address), ["@project/decision.md"]);
74
+ assert.equal(context.identity.projectKey, alpha.projectKey);
75
+ });
76
+ test("a cwd override changes only new session-note ownership, not its physical session", async (t) => {
77
+ const f = fixture(t);
78
+ const alpha = f.identity(f.alpha);
79
+ const beta = f.identity(f.beta);
80
+ const context = notesToolContext(alpha, f.alpha);
81
+ data(await notesWrite.execute({ address: "checkpoint", content: "first", cwd: f.beta }, context));
82
+ const file = join(f.home, "pi", "session", alpha.sessionId, "checkpoint.md");
83
+ assert.equal(parseNote(readFileSync(file, "utf8")).meta.project, beta.projectKey);
84
+ data(await notesWrite.execute({ address: "checkpoint", content: "second" }, context));
85
+ assert.equal(parseNote(readFileSync(file, "utf8")).meta.project, beta.projectKey, "an overwrite preserves existing ownership");
86
+ });
87
+ test("invalid explicit cwd refuses before a write", async (t) => {
88
+ const f = fixture(t);
89
+ const context = notesToolContext(f.identity(f.alpha), f.alpha);
90
+ const file = join(f.root, "file");
91
+ writeFileSync(file, "not a directory");
92
+ for (const cwd of [join(f.root, "missing"), file]) {
93
+ const result = refusal(await notesWrite.execute({ address: "@project/refused", content: "no", cwd }, context));
94
+ assert.equal(result.code, "invalid_cwd");
95
+ assert.match(result.message, /resolved to/);
96
+ }
97
+ assert.equal((await createNotesStore(f.identity(f.alpha)).read("@project/refused")), undefined);
98
+ });
99
+ test("cwd cannot escape or erase the active dream jail", async (t) => {
100
+ const f = fixture(t);
101
+ const alpha = f.identity(f.alpha);
102
+ const beta = f.identity(f.beta);
103
+ const gammaCwd = join(f.root, "gamma");
104
+ mkdirSync(gammaCwd);
105
+ const gamma = f.identity(gammaCwd);
106
+ await createNotesStore(beta).write("@project/rule", "beta");
107
+ const context = notesToolContext({ ...alpha, dreaming: beta.projectKey }, f.alpha);
108
+ const escaped = refusal(await notesWrite.execute({ address: "@project/rule", content: "gamma", cwd: gammaCwd }, context));
109
+ assert.equal(escaped.code, "invalid_scope");
110
+ assert.equal((await createNotesStore(gamma).read("@project/rule")), undefined);
111
+ const dreamed = await notesWrite.execute({ address: `@projects/${beta.projectKey}/rule`, content: "edited", cwd: gammaCwd }, context);
112
+ assert.equal(dreamed.ok, true, "the original dreamed project remains writable through its named address");
113
+ assert.equal((await createNotesStore(beta).read("@project/rule"))?.body, "edited");
114
+ });
@@ -86,7 +86,7 @@ test("same-file read/modify/write operations serialize across stores and markdow
86
86
  assert.equal((await notes.read("shared"))?.body, "first\nB", "edit arguments are snapshotted at method entry");
87
87
  assert.equal(readFileSync(file, "utf8").includes("mutated after call"), false);
88
88
  });
89
- test("stores snapshot explicit identity and do not leak homes across instances", async (t) => {
89
+ test("stores snapshot explicit identity and do not leak notebooks across instances", async (t) => {
90
90
  const { home, context } = fixture(t);
91
91
  const mutable = { ...context };
92
92
  const notes = createNotesStore(mutable);
@@ -116,7 +116,7 @@ test("list and search share scoped glob scans and search offsets count Unicode c
116
116
  const listedAddresses = listed.map((row) => row.address).sort();
117
117
  const searchedAddresses = searched.map((row) => row.address).sort();
118
118
  assert.deepEqual(searchedAddresses, ["@human/shared.md", "@project/shared.md", "shared.md"]);
119
- assert.deepEqual(searchedAddresses, listedAddresses, "list and search traverse the same filtered homes and files");
119
+ assert.deepEqual(searchedAddresses, listedAddresses, "list and search traverse the same filtered notebooks and files");
120
120
  const sessionMatch = searched.find((row) => row.address === "shared.md").matches[0];
121
121
  const body = (await notes.read("shared.md")).body;
122
122
  assert.equal(body, "😀 needle in session");
@@ -236,7 +236,7 @@ test("same-file case and directory aliases cannot delete a moved note", async (t
236
236
  assert.equal((await notes.read("mixed.md"))?.body, "still here");
237
237
  }
238
238
  });
239
- test("glob is the single query selector for a named project home", async (t) => {
239
+ test("glob is the single query selector for a named project notebook", async (t) => {
240
240
  const { home, notes } = fixture(t);
241
241
  mkdirSync(join(home, "project/other"), { recursive: true });
242
242
  writeFileSync(join(home, "project/other/decision.md"), "needle");
@@ -278,7 +278,7 @@ test("one unreadable note is named without hiding its readable siblings", async
278
278
  chmodSync(join(home, "project", "project-12345678", "bad.md"), 0o000);
279
279
  const result = await notes.listWithStatus({ glob: "@project/**" });
280
280
  assert.deepEqual(result.rows.map((row) => row.address), ["@project/good.md"], "the readable sibling still lists");
281
- assert.deepEqual(result.status.homesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
281
+ assert.deepEqual(result.status.namespacesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
282
282
  await assert.rejects(() => notes.list({ glob: "@project/**" }), (error) => error.code === "EACCES", "a caller that asked for no status still sees the failure");
283
283
  });
284
284
  test("a hand-written quoted numeric extra survives a rewrite as a string", async (t) => {
@@ -0,0 +1 @@
1
+ export {};
@@ -6,7 +6,7 @@ import test from "node:test";
6
6
  import { createNotesStore, noteIdentity, NoteError } from "../src/notes/index.js";
7
7
  import { scopeDir } from "../src/notes/paths.js";
8
8
  function fixture(t) {
9
- const home = mkdtempSync(join(tmpdir(), "notes-query-homes-"));
9
+ const home = mkdtempSync(join(tmpdir(), "notes-query-namespaces-"));
10
10
  t.after(() => rmSync(home, { recursive: true, force: true }));
11
11
  const identity = { home, sessionId: "DSH.Run_1+local", projectKey: "current-project", agent: "current-agent", model: "current-model" };
12
12
  const foreignIdentity = { ...identity, sessionId: "DSH.Run_2+@remote", projectKey: "other-project", agent: "other-agent", model: "other-model" };
@@ -20,16 +20,16 @@ async function populate(t) {
20
20
  const { notes, foreign, foreignIdentity } = fixtureData;
21
21
  const current = ["shared.md", "@project/shared.md", "@human/shared.md", "@self/shared.md", "@model/shared.md"].sort();
22
22
  for (const address of current)
23
- await notes.write(address, "needle in current home");
23
+ await notes.write(address, "needle in current notebook");
24
24
  for (const address of ["shared.md", "@project/shared.md", "@self/shared.md", "@model/shared.md"])
25
- await foreign.write(address, "needle in foreign home");
25
+ await foreign.write(address, "needle in foreign notebook");
26
26
  const all = [...current,
27
27
  `@sessions/${foreignIdentity.sessionId}/shared.md`,
28
28
  "@projects/other-project/shared.md", "@agents/other-agent/shared.md", "@models/other-model/shared.md",
29
29
  ].sort();
30
30
  return { ...fixtureData, current, all };
31
31
  }
32
- test("default spellings stay local while explicit ** lists and searches each home once", async (t) => {
32
+ test("default spellings stay local while explicit ** lists and searches each notebook once", async (t) => {
33
33
  const { notes, current, all, identity } = await populate(t);
34
34
  assert.deepEqual(addresses(await notes.list()), current);
35
35
  for (const glob of [null, "", "@default"]) {
@@ -97,7 +97,7 @@ test("named session reads leave bytes untouched and explicit session mutations r
97
97
  await assert.rejects(() => notes.list({ glob: "@sessions/bad:id/**" }), readOnly);
98
98
  assert.equal(readFileSync(foreignFile, "utf8"), beforeForeign);
99
99
  });
100
- test("named project reads and relative identity rendering survive global enumeration of unmarked homes", async (t) => {
100
+ test("named project reads and relative identity rendering survive global enumeration of unmarked notebooks", async (t) => {
101
101
  const { home, identity, notes } = fixture(t);
102
102
  const project = join(home, "project", "another-project");
103
103
  mkdirSync(project, { recursive: true });
@@ -120,21 +120,21 @@ test("named project reads and relative identity rendering survive global enumera
120
120
  assert.equal(noteIdentity(identity, `@models/${identity.model}/model.md`).address, "@model/model.md");
121
121
  await assert.rejects(() => notes.write(address, "no"), (error) => error instanceof NoteError && error.code === "invalid_scope");
122
122
  });
123
- test("global status isolates every failed namespace and reserved heads do not scan unrelated homes", async (t) => {
123
+ test("global status isolates every failed namespace and reserved heads do not scan unrelated notebooks", async (t) => {
124
124
  const { home, notes } = fixture(t);
125
125
  await notes.write("@human/available.md", "needle");
126
126
  mkdirSync(join(home, "pi"), { recursive: true });
127
127
  for (const root of ["pi/session", "project", "agents", "models"])
128
128
  writeFileSync(join(home, root), "not a directory");
129
- const expected = { homesUnavailable: ["@sessions", "@projects", "@agents", "@models"] };
129
+ const expected = { namespacesUnavailable: ["@sessions", "@projects", "@agents", "@models"] };
130
130
  const listed = await notes.listWithStatus({ glob: "**" });
131
131
  assert.deepEqual(addresses(listed.rows), ["@human/available.md"]);
132
132
  assert.deepEqual(listed.status, expected);
133
133
  assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status, expected);
134
- assert.deepEqual((await notes.listWithStatus({ glob: "@human/**" })).status.homesUnavailable, []);
134
+ assert.deepEqual((await notes.listWithStatus({ glob: "@human/**" })).status.namespacesUnavailable, []);
135
135
  await assert.rejects(() => notes.list({ glob: "**" }), (error) => error.code === "ENOTDIR");
136
136
  });
137
- test("global status reports failed enumerated homes individually and keeps readable siblings", async (t) => {
137
+ test("global status reports failed enumerated notebooks individually and keeps readable siblings", async (t) => {
138
138
  if (process.getuid?.() === 0 || process.platform === "win32")
139
139
  return t.skip("chmod 000 does not refuse this user's reads");
140
140
  const { notes, foreignIdentity, current, home, all } = await populate(t);
@@ -144,15 +144,15 @@ test("global status reports failed enumerated homes individually and keeps reada
144
144
  try {
145
145
  const result = await notes.listWithStatus({ glob: "**" });
146
146
  const unavailable = [`@sessions/${foreignIdentity.sessionId}`, "@projects/other-project"];
147
- assert.deepEqual(result.status.homesUnavailable, unavailable);
147
+ assert.deepEqual(result.status.namespacesUnavailable, unavailable);
148
148
  assert.deepEqual(addresses(result.rows), all.filter(address => !unavailable.some(prefix => address.startsWith(`${prefix}/`))));
149
- assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status.homesUnavailable, unavailable);
150
- assert.deepEqual(addresses(await notes.list()), current, "local defaults do not enumerate unreadable foreign homes");
149
+ assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status.namespacesUnavailable, unavailable);
150
+ assert.deepEqual(addresses(await notes.list()), current, "local defaults do not enumerate unreadable foreign notebooks");
151
151
  // A namespace scan must not read project marker files or let one bad marker abort its siblings.
152
152
  chmodSync(failed[1], 0o755);
153
153
  writeFileSync(join(home, "project/other-project/.project"), "{}");
154
154
  chmodSync(join(home, "project/other-project/.project"), 0o000);
155
- assert.deepEqual((await notes.listWithStatus({ glob: "@projects/*/**" })).status.homesUnavailable, []);
155
+ assert.deepEqual((await notes.listWithStatus({ glob: "@projects/*/**" })).status.namespacesUnavailable, []);
156
156
  }
157
157
  finally {
158
158
  for (const dir of failed)
@@ -1,8 +1,10 @@
1
1
  import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
2
2
  import { DEFAULT_BOOT_TOOL_NAMES } from "../src/boot/text.js";
3
3
  import assert from "node:assert/strict";
4
- import { mkdirSync, rmSync, writeFileSync } from "node:fs";
5
- import { dirname } from "node:path";
4
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import fs from "node:fs/promises";
6
+ import { syncBuiltinESMExports } from "node:module";
7
+ import { dirname, join } from "node:path";
6
8
  import test from "node:test";
7
9
  import { loadNotesSnapshot } from "../src/boot/snapshot.js";
8
10
  import { renderBootBlock } from "../src/boot/render.js";
@@ -12,7 +14,8 @@ import { localIso } from "../src/notes/frontmatter.js";
12
14
  import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
13
15
  import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
14
16
  import { notesUpdate } from "../src/tools/notes.js";
15
- import { assertWithinBudget, call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
17
+ import { notesToolContext } from "../src/tools/notes-context.js";
18
+ import { assertWithinBudget, call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead, runHandlers, } from "./helpers/extension.js";
16
19
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
17
20
  const testEnvironment = installExtensionTestHooks("notesoup-integration");
18
21
  /** The model-facing text of one tool result. */
@@ -20,6 +23,52 @@ function textOf(result) {
20
23
  const first = result.content[0];
21
24
  return first && first.type === "text" ? first.text : "";
22
25
  }
26
+ for (const scanFails of [false, true]) {
27
+ test(`Pi shutdown cancels a pending dream after its gated scan ${scanFails ? "fails" : "resumes"}`, async (t) => {
28
+ const session = manager();
29
+ const captured = makeExtension(session);
30
+ const ctx = context(session);
31
+ const me = notesIdentityFromPi(ctx);
32
+ const otherCtx = context(manager(), undefined, undefined, true, join(testEnvironment.cwd, "other-project"));
33
+ const other = notesIdentityFromPi(otherCtx);
34
+ assert.notEqual(other.projectKey, me.projectKey);
35
+ const lockPath = join(me.home, ".dream.lock");
36
+ const original = fs.readdir;
37
+ let enter;
38
+ let release;
39
+ const entered = new Promise(resolve => { enter = resolve; });
40
+ const gate = new Promise(resolve => { release = resolve; });
41
+ let gated = false;
42
+ t.mock.method(fs, "readdir", async (...args) => {
43
+ if (!gated && args[0] === join(me.home, "project", me.projectKey)) {
44
+ gated = true;
45
+ enter();
46
+ await gate;
47
+ if (scanFails)
48
+ throw new TypeError("scan failed after shutdown");
49
+ }
50
+ return original(...args);
51
+ });
52
+ syncBuiltinESMExports();
53
+ t.after(() => { release(); t.mock.restoreAll(); syncBuiltinESMExports(); });
54
+ const opening = call(captured, "dream_begin", {}, ctx);
55
+ await entered;
56
+ assert.ok(existsSync(lockPath), "begin acquired ownership before the controlled scan await");
57
+ assert.equal(resultError(await call(captured, "dream_begin", {}, ctx)).code, "already_dreaming");
58
+ await runHandlers(captured, "session_shutdown", { type: "session_shutdown" }, ctx);
59
+ assert.equal(existsSync(lockPath), false, "the registered shutdown handler releases pending ownership");
60
+ assert.equal(resultError(await call(captured, "dream_end", {}, ctx)).code, "not_dreaming");
61
+ const newer = resultData(await call(captured, "dream_begin", {}, otherCtx));
62
+ assert.equal(newer.project, other.projectKey, "another project can immediately begin after shutdown");
63
+ const newerToken = readFileSync(lockPath, "utf8");
64
+ release();
65
+ assert.equal(resultError(await opening).code, "cancelled", "the stale opener cannot return success or resurrect state");
66
+ assert.equal(readFileSync(lockPath, "utf8"), newerToken, "stale cleanup cannot release the newer owner's token");
67
+ assert.equal(resultError(await call(captured, "dream_end", {}, ctx)).code, "not_dreaming");
68
+ resultData(await call(captured, "dream_end", {}, otherCtx));
69
+ assert.equal(existsSync(lockPath), false);
70
+ });
71
+ }
23
72
  test("notes_list and notes_search are recent-first snapshots with narrowing hints", async () => {
24
73
  const session = manager();
25
74
  const captured = makeExtension(session);
@@ -37,7 +86,7 @@ test("notes_list and notes_search are recent-first snapshots with narrowing hint
37
86
  const listed = resultData(await call(captured, "notes_list", { limit: 2 }, ctx));
38
87
  assert.deepEqual(listed.files.map((file) => file.address), ["new.md", "@project/design.md"]);
39
88
  assert.equal(listed.more, 1);
40
- assert.deepEqual(Object.keys(listed).sort(), ["files", "homes_unavailable", "more"]);
89
+ assert.deepEqual(Object.keys(listed).sort(), ["files", "more", "namespaces_unavailable"]);
41
90
  const searched = resultData(await call(captured, "notes_search", { query: "needle", limit: 2 }, ctx));
42
91
  assert.deepEqual(searched.files.map((file) => file.address), ["new.md", "@project/design.md"]);
43
92
  assert.equal(searched.more, 1);
@@ -104,7 +153,7 @@ test("notes_list is most-recently-updated first across merged scopes", async ()
104
153
  // A same-path pair in two scopes keeps both rows; equal timestamps tie-break by scope name.
105
154
  put("human", "a.md", base + 10);
106
155
  assert.deepEqual((await files({})).filter((file) => file.address.endsWith("a.md")).map((file) => file.address), ["@human/a.md", "a.md"], "equal timestamps tie-break by full address");
107
- assert.deepEqual((await files({ glob: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare glob narrows to the session home");
156
+ assert.deepEqual((await files({ glob: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare glob narrows to the session notebook");
108
157
  });
109
158
  test("notes are real files that persist across sessions and round-trip Unicode", async () => {
110
159
  const original = manager();
@@ -160,15 +209,15 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
160
209
  const missing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
161
210
  assert.equal(missing.code, "not_found");
162
211
  });
163
- test("the filesystem notes loader treats an absent home as empty but surfaces a real directory read failure", async () => {
212
+ test("the filesystem notes loader treats an absent notebook as empty but surfaces a real directory read failure", async () => {
164
213
  const sm = manager();
165
214
  const ctx = context(sm);
166
- assert.deepEqual(await listNotes(ctx, { glob: "@human/**" }), [], "a home that has not been created is empty");
215
+ assert.deepEqual(await listNotes(ctx, { glob: "@human/**" }), [], "a notebook that has not been created is empty");
167
216
  const blockedHome = scopeDir("human", ctx);
168
217
  writeFileSync(blockedHome, "not a directory");
169
- await assert.rejects(() => listNotes(ctx, { glob: "@human/**" }), (error) => error.code === "ENOTDIR", "a non-ENOENT directory failure is not swallowed as an empty home");
218
+ await assert.rejects(() => listNotes(ctx, { glob: "@human/**" }), (error) => error.code === "ENOTDIR", "a non-ENOENT directory failure is not swallowed as an empty notebook");
170
219
  });
171
- test("boot note acquisition is one closed snapshot and isolates one or all failed homes", async () => {
220
+ test("boot note acquisition is one closed snapshot and isolates one or all failed notebooks", async () => {
172
221
  const sm = manager();
173
222
  const ctx = context(sm);
174
223
  const updated = Date.now();
@@ -199,7 +248,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
199
248
  calls.set(scope, (calls.get(scope) ?? 0) + 1);
200
249
  return rows.get(scope) ?? [];
201
250
  });
202
- assert.deepEqual([...calls.entries()], [["session", 1], ["project", 1], ["human", 1], ["agent", 1], ["model", 1]], "each selected home is loaded exactly once");
251
+ assert.deepEqual([...calls.entries()], [["session", 1], ["project", 1], ["human", 1], ["agent", 1], ["model", 1]], "each selected notebook is loaded exactly once");
203
252
  const renderData = {
204
253
  tools: DEFAULT_BOOT_TOOL_NAMES,
205
254
  agentName: "root",
@@ -209,8 +258,8 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
209
258
  };
210
259
  const rendered = renderBootBlock(renderData);
211
260
  assert.equal(renderBootBlock(renderData), rendered, "rendering the same boot data twice is deterministic");
212
- assert.ok(rendered.includes("HUMAN_MAP_BODY") && rendered.includes("PROJECT_MAP_BODY") && rendered.includes("AGENT_MAP_BODY") && rendered.includes("SESSION_MAP_BODY"), "all home maps, including session, are pinned");
213
- assert.ok(rendered.includes("session.md") && rendered.includes("@human/human.md"), "the fresh page carries rows from every home");
261
+ assert.ok(rendered.includes("HUMAN_MAP_BODY") && rendered.includes("PROJECT_MAP_BODY") && rendered.includes("AGENT_MAP_BODY") && rendered.includes("SESSION_MAP_BODY"), "all notebook maps, including session, are pinned");
262
+ assert.ok(rendered.includes("session.md") && rendered.includes("@human/human.md"), "the fresh page carries rows from every notebook");
214
263
  assert.equal(rendered.includes("SESSION_POCKET_BODY"), false, "fresh-page bodies stay excluded");
215
264
  assert.equal(rendered.includes("- MAP.md"), false, "a pinned session map does not take a feed seat");
216
265
  assert.match(rendered, / {2}Session note\n {2}session\.md · (?:just now|\d+s ago)/, "a feed entry is the note's own title over its locator");
@@ -247,7 +296,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
247
296
  ] : []);
248
297
  const mapAndUnicodeText = renderBootBlock({ ...renderData, notes: mapAndUnicode });
249
298
  assert.match(mapAndUnicodeText, / {2}🐑字\n {2}unicode\.md · (?:just now|\d+s ago)/, "a headingless note is announced by its first line");
250
- assert.ok(mapAndUnicodeText.includes("no @ — this session\n───────────────────\n\nmap\n\n SESSION_MAP_BODY\n\nrecent\n\n 🐑字\n unicode.md · just now"), "the session shelf keeps its typography");
299
+ assert.ok(mapAndUnicodeText.includes("no @ — this session\n───────────────────\n\nMAP.md\n\n SESSION_MAP_BODY\n\nrecent\n\n 🐑字\n unicode.md · just now"), "the session shelf keeps its typography");
251
300
  assert.equal(mapAndUnicodeText.includes("crumpled.md"), false);
252
301
  assert.equal(/MAP\.md ·/.test(mapAndUnicodeText), false, "maps never take feed seats");
253
302
  assert.equal(mapAndUnicodeText.includes("@human — the human"), false, "empty shelves are omitted");
@@ -257,7 +306,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
257
306
  throw readFailure("EIO");
258
307
  return rows.get(scope) ?? [];
259
308
  });
260
- assert.deepEqual(oneFailed.unavailable.map((home) => home.label), ["@human"]);
309
+ assert.deepEqual(oneFailed.unavailable.map((namespace) => namespace.label), ["@human"]);
261
310
  const oneFailedText = renderBootBlock({
262
311
  tools: DEFAULT_BOOT_TOOL_NAMES,
263
312
  agentName: "root",
@@ -265,9 +314,9 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
265
314
  tree: renderData.tree,
266
315
  notes: oneFailed,
267
316
  });
268
- assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("@human — the human\n──────────────────\n\n This drawer wouldn't open. Try `notes_list` again."), "healthy homes and a per-section recovery notice survive one failure");
269
- assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed home's index is omitted");
270
- assert.equal(oneFailedText.includes("Human note"), false, "the failed home takes no feed seats");
317
+ assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("@human — the human\n──────────────────\n\n This drawer wouldn't open. Try `notes_list` again."), "healthy notebooks and a per-section recovery notice survive one failure");
318
+ assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed notebook's index is omitted");
319
+ assert.equal(oneFailedText.includes("Human note"), false, "the failed notebook takes no feed seats");
271
320
  const allFailed = await loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), (scope) => {
272
321
  throw readFailure(scope === "session" ? "EACCES" : "EIO");
273
322
  });
@@ -279,13 +328,13 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
279
328
  tree: renderData.tree,
280
329
  notes: allFailed,
281
330
  });
282
- assert.ok(allFailedText.includes("pcw:test") && allFailedText.includes("root") && allFailedText.includes("next"), "identity survives an all-home failure");
283
- assert.ok(allFailedText.includes("Your memory gets wiped when this window ends"), "protocol survives an all-home failure");
331
+ assert.ok(allFailedText.includes("pcw:test") && allFailedText.includes("root") && allFailedText.includes("next"), "identity survives an all-notebook failure");
332
+ assert.ok(allFailedText.includes("Your memory gets wiped when this window ends"), "protocol survives an all-notebook failure");
284
333
  assert.equal(allFailedText.includes("scripted read failure"), false, "the model-facing notice does not expose OS/error details");
285
334
  await assert.rejects(() => loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), () => { throw new TypeError("programmer failure"); }), (error) => error instanceof TypeError, "unrelated TypeError construction failures remain visible");
286
335
  await assert.rejects(() => loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), () => { throw Object.assign(new Error("invalid argument"), { code: "ERR_INVALID_ARG_TYPE" }); }), (error) => error.code === "ERR_INVALID_ARG_TYPE", "Node ERR_* failures are not treated as filesystem errno failures");
287
336
  });
288
- test("the boot block gives awake agents the notes-home file layout", async () => {
337
+ test("the boot block gives awake agents the notes file layout", async () => {
289
338
  const session = manager();
290
339
  const rendered = await explicitBoot(context(session), "pcw:test:root", undefined);
291
340
  assert.equal(rendered.includes(process.env.NOTESOUP_HOME ?? ""), false, "the absolute notes home is never exposed");
@@ -305,9 +354,9 @@ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer"
305
354
  assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
306
355
  assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false, "the over-cap suffix is not inlined");
307
356
  assert.ok(rendered.includes("`MAP.md`"), "the full MAP remains available by address");
308
- assert.ok(rendered.includes("cheatsheet\n\n REMEMBER_THIS_RULE\n\nmap"), "a real stored cheatsheet is pinned before the map");
357
+ assert.ok(rendered.includes("CHEATSHEET.md\n\n REMEMBER_THIS_RULE\n\nMAP.md\n\n"), "a real stored cheatsheet is pinned before the map");
309
358
  assert.equal(/CHEATSHEET\.md ·/.test(rendered), false, "the stored cheatsheet takes no recent seat");
310
- for (const retired of ["history_windows", "history_list", "history_read"]) {
359
+ for (const retired of ["history_list", "history_read"]) {
311
360
  assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
312
361
  }
313
362
  });
@@ -508,10 +557,10 @@ test("an unexpected notes defect propagates with its own identity while real fil
508
557
  // Its message deliberately opens with "query " — the wording a refusal classification once
509
558
  // matched on, which turned any such defect into a wrong invalid_query.
510
559
  const sentinel = new TypeError("query renderer invariant broken");
511
- await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "before", newText: "after" }] }, identity, () => { throw sentinel; }), (error) => error === sentinel, "an unexpected failure escapes with the identical Error, message and stack");
560
+ await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "before", newText: "after" }] }, notesToolContext(identity, "/work/current"), () => { throw sentinel; }), (error) => error === sentinel, "an unexpected failure escapes with the identical Error, message and stack");
512
561
  assert.equal(resultRead(await call(captured, "notes_read", { address: "propagate.md" }, ctx)).content, "after", "the edit was applied before the receipt failed; the throw claims no rollback");
513
562
  const assertion = Object.assign(new Error("assertion failed"), { code: "ERR_ASSERTION" });
514
- await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "after", newText: "later" }] }, identity, () => { throw assertion; }), (error) => error.code === "ERR_ASSERTION", "a Node ERR_ code is a programmer failure, never an io_error");
563
+ await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "after", newText: "later" }] }, notesToolContext(identity, "/work/current"), () => { throw assertion; }), (error) => error.code === "ERR_ASSERTION", "a Node ERR_ code is a programmer failure, never an io_error");
515
564
  // A genuine filesystem refusal is still an expected outcome, and still says nothing about paths.
516
565
  rmSync(scopeDir("session", ctx), { recursive: true, force: true });
517
566
  writeFileSync(scopeDir("session", ctx), "not a directory");