notesoup 0.53.1 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +2 -2
  2. package/dist/plugins/claude/src/helper.js +2 -1
  3. package/dist/plugins/claude/src/history.js +2 -3
  4. package/dist/plugins/claude/src/thresholds.js +4 -2
  5. package/dist/plugins/codex/src/hooks.js +1 -1
  6. package/dist/plugins/codex/src/identity.d.ts +1 -1
  7. package/dist/plugins/codex/src/identity.js +3 -3
  8. package/dist/plugins/codex/src/mcp.js +2 -1
  9. package/dist/plugins/codex/src/text.d.ts +1 -1
  10. package/dist/plugins/codex/src/text.js +2 -2
  11. package/dist/plugins/dsh/engine.js +2 -2
  12. package/dist/plugins/dsh/tools.js +8 -7
  13. package/dist/plugins/dsh/window.d.ts +1 -0
  14. package/dist/plugins/dsh/window.js +7 -3
  15. package/dist/plugins/pi/entries.d.ts +1 -0
  16. package/dist/plugins/pi/entries.js +1 -0
  17. package/dist/plugins/pi/history-tools.d.ts +1 -1
  18. package/dist/plugins/pi/history-tools.js +4 -4
  19. package/dist/plugins/pi/marker.d.ts +9 -0
  20. package/dist/plugins/pi/marker.js +36 -0
  21. package/dist/plugins/pi/notes/tools.js +8 -6
  22. package/dist/plugins/pi/render.js +7 -4
  23. package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
  24. package/dist/plugins/pi/reset/artifacts.js +2 -2
  25. package/dist/plugins/pi/runtime.js +11 -8
  26. package/dist/plugins/pi/text.d.ts +2 -0
  27. package/dist/plugins/pi/text.js +4 -0
  28. package/dist/plugins/pi/window.js +21 -7
  29. package/dist/src/boot/render.js +7 -7
  30. package/dist/src/boot/snapshot.d.ts +7 -7
  31. package/dist/src/boot/snapshot.js +17 -17
  32. package/dist/src/boot/text.d.ts +2 -2
  33. package/dist/src/boot/text.js +7 -5
  34. package/dist/src/dream/git.d.ts +2 -11
  35. package/dist/src/dream/git.js +6 -23
  36. package/dist/src/dream/lock.d.ts +2 -2
  37. package/dist/src/dream/lock.js +3 -3
  38. package/dist/src/index.d.ts +2 -1
  39. package/dist/src/index.js +3 -2
  40. package/dist/src/notes/address.d.ts +8 -8
  41. package/dist/src/notes/address.js +13 -13
  42. package/dist/src/notes/errors.d.ts +1 -1
  43. package/dist/src/notes/frontmatter.js +2 -2
  44. package/dist/src/notes/index.d.ts +1 -1
  45. package/dist/src/notes/index.js +1 -1
  46. package/dist/src/notes/paths.d.ts +6 -6
  47. package/dist/src/notes/paths.js +9 -9
  48. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  49. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  50. package/dist/src/notes/store.d.ts +4 -4
  51. package/dist/src/notes/store.js +55 -52
  52. package/dist/src/tools/dream.d.ts +21 -3
  53. package/dist/src/tools/dream.js +54 -16
  54. package/dist/src/tools/notes-context.d.ts +10 -0
  55. package/dist/src/tools/notes-context.js +27 -0
  56. package/dist/src/tools/notes.d.ts +69 -20
  57. package/dist/src/tools/notes.js +40 -31
  58. package/dist/test/agent-loop.test.js +8 -8
  59. package/dist/test/boot.integration.test.js +5 -5
  60. package/dist/test/claude-history.test.js +26 -0
  61. package/dist/test/claude-mod.test.js +257 -86
  62. package/dist/test/codex-plugin.test.js +18 -1
  63. package/dist/test/context-edit-budget.test.js +121 -0
  64. package/dist/test/dependencies.test.js +71 -4
  65. package/dist/test/dream-tools.test.js +153 -8
  66. package/dist/test/dsh.test.js +62 -15
  67. package/dist/test/helpers/dsh.d.ts +4 -1
  68. package/dist/test/helpers/dsh.js +20 -4
  69. package/dist/test/helpers/extension.d.ts +5 -0
  70. package/dist/test/helpers/extension.js +33 -2
  71. package/dist/test/host-neutral.test.js +17 -15
  72. package/dist/test/marker.test.js +78 -0
  73. package/dist/test/model-facing-text.test.js +12 -8
  74. package/dist/test/notes-cwd.test.d.ts +1 -0
  75. package/dist/test/notes-cwd.test.js +114 -0
  76. package/dist/test/notes-library.test.js +4 -4
  77. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  78. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  79. package/dist/test/notes.integration.test.js +72 -23
  80. package/dist/test/notes.test.js +50 -20
  81. package/dist/test/pi-render.test.js +33 -1
  82. package/dist/test/project-namespace.test.d.ts +1 -0
  83. package/dist/test/project-namespace.test.js +324 -0
  84. package/dist/test/reset-lifecycle.test.js +12 -0
  85. package/docs/architecture.md +13 -8
  86. package/docs/claude-code-mod.md +7 -7
  87. package/docs/codex.md +4 -4
  88. package/docs/dsh.md +8 -8
  89. package/docs/notes-library.md +9 -5
  90. package/docs/skills.md +3 -3
  91. package/docs/tool-results.md +6 -2
  92. package/package.json +4 -6
  93. package/playbook.md +6 -6
  94. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  95. package/plugins/claude/dist/claude/helper.js +681 -617
  96. package/plugins/claude/hooks/register.ts +61 -65
  97. package/plugins/claude/playbook.md +6 -6
  98. package/plugins/claude/skills/memory/SKILL.md +4 -4
  99. package/plugins/claude/src/helper.ts +3 -2
  100. package/plugins/claude/src/history.ts +2 -3
  101. package/plugins/claude/src/thresholds.ts +4 -2
  102. package/plugins/codex/README.md +1 -1
  103. package/plugins/codex/dist/codex/notesoup.js +877 -815
  104. package/plugins/codex/src/hooks.ts +1 -1
  105. package/plugins/codex/src/identity.ts +3 -3
  106. package/plugins/codex/src/mcp.ts +2 -1
  107. package/plugins/codex/src/text.ts +2 -2
  108. package/plugins/dsh/engine.ts +2 -2
  109. package/plugins/dsh/tools.ts +8 -7
  110. package/plugins/dsh/window.ts +8 -3
  111. package/plugins/paseo/OVERVIEW.md +4 -4
  112. package/plugins/paseo/README.md +1 -1
  113. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  114. package/plugins/paseo/client/markdown.tsx +179 -0
  115. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  116. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  117. package/plugins/paseo/client/paper-card.tsx +8 -19
  118. package/plugins/paseo/client/paper-palette.ts +40 -0
  119. package/plugins/paseo/client/sticky-card.tsx +6 -4
  120. package/plugins/paseo/package.json +3 -0
  121. package/plugins/paseo/paseo-plugin.json +2 -2
  122. package/plugins/paseo/shared/notes-op.ts +13 -9
  123. package/plugins/paseo/test/notes-op.test.ts +52 -73
  124. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  125. package/plugins/pi/entries.ts +1 -0
  126. package/plugins/pi/history-tools.ts +4 -4
  127. package/plugins/pi/marker.ts +39 -0
  128. package/plugins/pi/notes/tools.ts +8 -6
  129. package/plugins/pi/render.ts +6 -4
  130. package/plugins/pi/reset/artifacts.ts +2 -2
  131. package/plugins/pi/runtime.ts +9 -8
  132. package/plugins/pi/text.ts +5 -0
  133. package/plugins/pi/window.ts +22 -7
  134. package/skills/memory/SKILL.md +4 -4
  135. package/src/boot/render.ts +8 -8
  136. package/src/boot/snapshot.ts +20 -20
  137. package/src/boot/text.ts +7 -5
  138. package/src/dream/git.ts +7 -24
  139. package/src/dream/lock.ts +3 -3
  140. package/src/index.ts +4 -3
  141. package/src/notes/address.ts +13 -13
  142. package/src/notes/errors.ts +1 -1
  143. package/src/notes/frontmatter.ts +2 -2
  144. package/src/notes/index.ts +1 -1
  145. package/src/notes/paths.ts +9 -9
  146. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  147. package/src/notes/store.ts +61 -58
  148. package/src/tools/dream.ts +63 -16
  149. package/src/tools/notes-context.ts +29 -0
  150. package/src/tools/notes.ts +39 -29
  151. package/dist/test/project-home.test.js +0 -134
  152. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  153. /package/dist/test/{project-home.test.d.ts → marker.test.d.ts} +0 -0
@@ -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,7 +354,7 @@ 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
359
  for (const retired of ["history_windows", "history_list", "history_read"]) {
311
360
  assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
@@ -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");
@@ -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");
@@ -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 {};