notesoup 0.49.0 → 0.51.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 (172) hide show
  1. package/README.md +13 -1
  2. package/dist/{src/claude → plugins/claude/src}/helper.js +7 -7
  3. package/dist/{src/claude → plugins/claude/src}/history.d.ts +1 -1
  4. package/dist/{src/claude → plugins/claude/src}/history.js +1 -1
  5. package/dist/plugins/claude/src/text.d.ts +6 -0
  6. package/dist/plugins/claude/src/text.js +7 -0
  7. package/dist/{src/claude → plugins/claude/src}/thresholds.js +3 -3
  8. package/dist/{src → plugins}/dsh/budget.js +1 -1
  9. package/dist/{src → plugins}/dsh/engine.d.ts +1 -1
  10. package/dist/{src → plugins}/dsh/engine.js +1 -1
  11. package/dist/{src → plugins}/dsh/history.d.ts +1 -1
  12. package/dist/{src → plugins}/dsh/history.js +1 -1
  13. package/dist/{src → plugins}/dsh/index.js +1 -1
  14. package/dist/{src → plugins}/dsh/tools.js +3 -3
  15. package/dist/{src → plugins}/dsh/window.d.ts +1 -1
  16. package/dist/{src → plugins}/dsh/window.js +5 -5
  17. package/dist/{src → plugins}/pi/boot.d.ts +1 -1
  18. package/dist/{src → plugins}/pi/boot.js +5 -4
  19. package/dist/{src → plugins}/pi/budget.js +4 -4
  20. package/dist/{src → plugins}/pi/dream/cli.d.ts +1 -1
  21. package/dist/{src → plugins}/pi/dream/cli.js +6 -6
  22. package/dist/{src → plugins}/pi/dream/runner.d.ts +1 -1
  23. package/dist/{src → plugins}/pi/dream/runner.js +3 -3
  24. package/dist/{src → plugins}/pi/dream/settings.d.ts +1 -1
  25. package/dist/{src → plugins}/pi/dream/settings.js +2 -2
  26. package/dist/{src → plugins}/pi/history-tools.js +1 -1
  27. package/dist/{src → plugins}/pi/history.d.ts +1 -1
  28. package/dist/{src → plugins}/pi/history.js +1 -1
  29. package/dist/plugins/pi/index.d.ts +1 -0
  30. package/dist/plugins/pi/index.js +1 -0
  31. package/dist/{src → plugins}/pi/notes/adapter.d.ts +1 -1
  32. package/dist/{src → plugins}/pi/notes/adapter.js +1 -1
  33. package/dist/{src → plugins}/pi/notes/tools.js +1 -1
  34. package/dist/{src → plugins}/pi/reset/artifacts.d.ts +1 -1
  35. package/dist/{src → plugins}/pi/reset/artifacts.js +1 -1
  36. package/dist/{src → plugins}/pi/reset/lifecycle.d.ts +1 -1
  37. package/dist/{src → plugins}/pi/reset/lifecycle.js +1 -1
  38. package/dist/{src → plugins}/pi/runtime.js +4 -4
  39. package/dist/plugins/pi/text.d.ts +23 -0
  40. package/dist/plugins/pi/text.js +30 -0
  41. package/dist/{src → plugins}/pi/thresholds.d.ts +1 -1
  42. package/dist/{src → plugins}/pi/thresholds.js +4 -4
  43. package/dist/{src → plugins}/pi/tool-result.d.ts +1 -1
  44. package/dist/{src → plugins}/pi/tool-result.js +1 -1
  45. package/dist/{src → plugins}/pi/window.d.ts +1 -1
  46. package/dist/src/boot/text.d.ts +4 -13
  47. package/dist/src/boot/text.js +1 -11
  48. package/dist/src/budget/policy.d.ts +2 -3
  49. package/dist/src/budget/policy.js +1 -1
  50. package/dist/src/budget/text.d.ts +1 -12
  51. package/dist/src/budget/text.js +2 -24
  52. package/dist/src/dream/settings.d.ts +1 -2
  53. package/dist/src/dream/settings.js +4 -2
  54. package/dist/src/index.d.ts +29 -1
  55. package/dist/src/index.js +26 -1
  56. package/dist/src/notes/address.d.ts +5 -4
  57. package/dist/src/notes/address.js +13 -7
  58. package/dist/src/notes/identity.js +3 -7
  59. package/dist/src/notes/paths.d.ts +4 -2
  60. package/dist/src/notes/paths.js +11 -6
  61. package/dist/src/notes/store.d.ts +4 -1
  62. package/dist/src/notes/store.js +66 -34
  63. package/dist/src/settings.d.ts +7 -16
  64. package/dist/src/settings.js +7 -10
  65. package/dist/src/tools/notes.d.ts +5 -5
  66. package/dist/src/tools/notes.js +5 -4
  67. package/dist/test/agent-loop.test.js +20 -19
  68. package/dist/test/boot.integration.test.js +9 -9
  69. package/dist/test/budget-settings.integration.test.js +1 -1
  70. package/dist/test/claude-history.test.js +2 -2
  71. package/dist/test/claude-mod.test.js +22 -16
  72. package/dist/test/claude-validation.test.js +3 -3
  73. package/dist/test/dependencies.test.js +53 -45
  74. package/dist/test/doctor.test.js +1 -1
  75. package/dist/test/dream-skill.test.js +4 -4
  76. package/dist/test/dream.test.js +2 -2
  77. package/dist/test/dsh-cli.test.js +2 -2
  78. package/dist/test/dsh-compaction-parity.test.js +1 -1
  79. package/dist/test/dsh.test.js +4 -4
  80. package/dist/test/helpers/dependency-graph.js +9 -7
  81. package/dist/test/helpers/dsh.d.ts +1 -1
  82. package/dist/test/helpers/dsh.js +2 -2
  83. package/dist/test/helpers/extension.js +6 -5
  84. package/dist/test/helpers/notes.js +1 -1
  85. package/dist/test/model-facing-text.test.js +6 -4
  86. package/dist/test/notes-query-homes.test.d.ts +1 -0
  87. package/dist/test/notes-query-homes.test.js +161 -0
  88. package/dist/test/notes.integration.test.js +3 -2
  89. package/dist/test/notes.test.js +1 -1
  90. package/dist/test/reset-lifecycle.test.js +16 -15
  91. package/docs/architecture.md +21 -18
  92. package/docs/claude-code-mod.md +3 -3
  93. package/docs/dsh.md +2 -2
  94. package/docs/dsh.profile.patch.yml +1 -1
  95. package/docs/notes-library.md +17 -10
  96. package/docs/reset-lifecycle.md +3 -3
  97. package/docs/sdk-integration.md +2 -2
  98. package/package.json +17 -13
  99. package/{mods/notesoup → plugins/claude}/.claude-plugin/plugin.json +1 -1
  100. package/{mods/notesoup → plugins/claude}/dist/claude/helper.js +565 -540
  101. package/{mods/notesoup → plugins/claude}/hooks/register.ts +2 -2
  102. package/{mods/notesoup → plugins/claude}/skills/memory/SKILL.md +3 -0
  103. package/{src/claude → plugins/claude/src}/helper.ts +10 -9
  104. package/{src/claude → plugins/claude/src}/history.ts +1 -1
  105. package/plugins/claude/src/text.ts +10 -0
  106. package/{src/claude → plugins/claude/src}/thresholds.ts +3 -3
  107. package/{src → plugins}/dsh/budget.ts +1 -1
  108. package/{src → plugins}/dsh/engine.ts +1 -1
  109. package/{src → plugins}/dsh/history.ts +1 -1
  110. package/{src → plugins}/dsh/index.ts +1 -1
  111. package/{src → plugins}/dsh/tools.ts +3 -3
  112. package/{src → plugins}/dsh/window.ts +5 -5
  113. package/{src → plugins}/pi/boot.ts +5 -4
  114. package/{src → plugins}/pi/budget.ts +4 -4
  115. package/{src → plugins}/pi/dream/cli.ts +8 -8
  116. package/{src → plugins}/pi/dream/runner.ts +4 -4
  117. package/{src → plugins}/pi/dream/settings.ts +2 -2
  118. package/{src → plugins}/pi/history-tools.ts +1 -1
  119. package/{src → plugins}/pi/history.ts +1 -1
  120. package/plugins/pi/index.ts +1 -0
  121. package/{src → plugins}/pi/notes/adapter.ts +1 -1
  122. package/{src → plugins}/pi/notes/tools.ts +2 -2
  123. package/{src → plugins}/pi/reset/artifacts.ts +1 -1
  124. package/{src → plugins}/pi/reset/lifecycle.ts +2 -2
  125. package/{src → plugins}/pi/runtime.ts +4 -4
  126. package/plugins/pi/text.ts +35 -0
  127. package/{src → plugins}/pi/thresholds.ts +4 -4
  128. package/{src → plugins}/pi/tool-result.ts +1 -1
  129. package/{src → plugins}/pi/window.ts +1 -1
  130. package/skills/memory/SKILL.md +3 -0
  131. package/src/boot/text.ts +5 -15
  132. package/src/budget/policy.ts +3 -3
  133. package/src/budget/text.ts +2 -30
  134. package/src/dream/settings.ts +6 -3
  135. package/src/index.ts +52 -1
  136. package/src/notes/address.ts +12 -8
  137. package/src/notes/identity.ts +2 -8
  138. package/src/notes/paths.ts +12 -6
  139. package/src/notes/store.ts +62 -29
  140. package/src/settings.ts +8 -24
  141. package/src/tools/notes.ts +5 -4
  142. /package/dist/{src/claude → plugins/claude/src}/helper.d.ts +0 -0
  143. /package/dist/{src/claude → plugins/claude/src}/thresholds.d.ts +0 -0
  144. /package/dist/{src → plugins}/dsh/budget.d.ts +0 -0
  145. /package/dist/{src → plugins}/dsh/index.d.ts +0 -0
  146. /package/dist/{src → plugins}/dsh/tools.d.ts +0 -0
  147. /package/dist/{src → plugins}/pi/anchored.d.ts +0 -0
  148. /package/dist/{src → plugins}/pi/anchored.js +0 -0
  149. /package/dist/{src → plugins}/pi/budget.d.ts +0 -0
  150. /package/dist/{src → plugins}/pi/entries.d.ts +0 -0
  151. /package/dist/{src → plugins}/pi/entries.js +0 -0
  152. /package/dist/{src → plugins}/pi/estimate.d.ts +0 -0
  153. /package/dist/{src → plugins}/pi/estimate.js +0 -0
  154. /package/dist/{src → plugins}/pi/extension.d.ts +0 -0
  155. /package/dist/{src → plugins}/pi/extension.js +0 -0
  156. /package/dist/{src → plugins}/pi/history-tools.d.ts +0 -0
  157. /package/dist/{src → plugins}/pi/notes/tools.d.ts +0 -0
  158. /package/dist/{src → plugins}/pi/reset/committed.d.ts +0 -0
  159. /package/dist/{src → plugins}/pi/reset/committed.js +0 -0
  160. /package/dist/{src → plugins}/pi/runtime.d.ts +0 -0
  161. /package/dist/{src → plugins}/pi/session-reader.d.ts +0 -0
  162. /package/dist/{src → plugins}/pi/session-reader.js +0 -0
  163. /package/dist/{src → plugins}/pi/window.js +0 -0
  164. /package/{mods/notesoup → plugins/claude}/hooks/hooks.json +0 -0
  165. /package/{mods/notesoup → plugins/claude}/playbook.md +0 -0
  166. /package/{mods/notesoup → plugins/claude}/skills/dream/SKILL.md +0 -0
  167. /package/{src → plugins}/pi/anchored.ts +0 -0
  168. /package/{src → plugins}/pi/entries.ts +0 -0
  169. /package/{src → plugins}/pi/estimate.ts +0 -0
  170. /package/{src → plugins}/pi/extension.ts +0 -0
  171. /package/{src → plugins}/pi/reset/committed.ts +0 -0
  172. /package/{src → plugins}/pi/session-reader.ts +0 -0
@@ -7,8 +7,9 @@ import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import test from "node:test";
8
8
  import ts from "typescript";
9
9
  import { dependencyViolations, moduleReferences } from "./helpers/dependency-graph.js";
10
- import * as entry from "../src/index.js";
11
- import notesoup, { createNotesoup } from "../src/pi/extension.js";
10
+ import * as core from "../src/index.js";
11
+ import * as pi from "../plugins/pi/index.js";
12
+ import notesoup, { createNotesoup } from "../plugins/pi/index.js";
12
13
  function repository() {
13
14
  let root = dirname(fileURLToPath(import.meta.url));
14
15
  while (!existsSync(join(root, "tsconfig.json")))
@@ -19,14 +20,14 @@ function sources(directory) {
19
20
  return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? sources(join(directory, entry.name)) : entry.name.endsWith(".ts") ? [join(directory, entry.name)] : []);
20
21
  }
21
22
  const options = { module: ts.ModuleKind.NodeNext, moduleResolution: ts.ModuleResolutionKind.NodeNext, target: ts.ScriptTarget.ES2022 };
22
- test("all shared domains resolve without any direct or transitive SDK, Pi adapter or root entry dependency", () => {
23
+ test("the host-neutral core resolves without any SDK or plugin dependency", () => {
23
24
  const root = repository();
24
25
  const config = ts.readConfigFile(join(root, "tsconfig.json"), ts.sys.readFile);
25
26
  assert.equal(config.error, undefined);
26
27
  const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, root);
27
28
  assert.deepEqual(parsed.errors, []);
28
29
  const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
29
- const shared = sources(join(root, "src")).filter((file) => !["pi", "claude", "dsh"].some((adapter) => file.startsWith(join(root, "src", adapter) + "/")) && file !== join(root, "src/index.ts"));
30
+ const shared = sources(join(root, "src"));
30
31
  for (const domain of ["notes", "boot", "history", "budget", "tools", "dream"])
31
32
  assert.ok(shared.some((file) => file.startsWith(join(root, "src", domain) + "/")), `${domain} is included`);
32
33
  assert.deepEqual(dependencyViolations(root, shared, parsed.options, new Set(["typebox"])), []);
@@ -35,49 +36,48 @@ test("all shared domains resolve without any direct or transitive SDK, Pi adapte
35
36
  assert.equal(manifest.peerDependencies[name], "*", `${name} follows Pi's host dependency contract`);
36
37
  }
37
38
  });
38
- test("each adapter resolves only its own host, shared domains and the public notes entry", () => {
39
+ test("each plugin resolves only its own host, the core, and the public notes entry", () => {
39
40
  const root = repository();
40
- for (const adapter of ["pi", "claude", "dsh"]) {
41
- const entries = sources(join(root, "src", adapter));
42
- if (adapter === "claude")
43
- entries.push(...sources(join(root, "mods/notesoup/hooks")));
44
- assert.deepEqual(dependencyViolations(root, entries, options, new Set(["typebox"])), [], adapter);
41
+ for (const plugin of ["pi", "claude", "dsh"]) {
42
+ const entries = sources(join(root, "plugins", plugin));
43
+ if (plugin === "claude")
44
+ entries.push(...sources(join(root, "plugins/claude/hooks")));
45
+ assert.deepEqual(dependencyViolations(root, entries, options, new Set(["typebox"])), [], plugin);
45
46
  }
46
47
  });
47
48
  test("dependency guard follows indirect types, re-exports, dynamic imports and import-type edges through resolved aliases", (t) => {
48
- const root = mkdtempSync(join(tmpdir(), "context-dependencies-"));
49
+ const root = mkdtempSync(join(tmpdir(), "notesoup-dependencies-"));
49
50
  t.after(() => rmSync(root, { recursive: true, force: true }));
50
51
  const put = (path, text) => { mkdirSync(dirname(join(root, path)), { recursive: true }); writeFileSync(join(root, path), text); };
51
52
  put("package.json", '{"type":"module"}');
52
- put("src/pi/native.ts", "export type Native = string;");
53
- put("src/index.ts", 'export * from "./pi/native.js";');
53
+ put("plugins/pi/native.ts", "export type Native = string;");
54
54
  put("src/notes/bridge.ts", 'export type { Native } from "@native";');
55
55
  put("src/notes/identity.ts", 'import type { Native } from "./bridge.js"; export type Identity = Native;');
56
- put("src/dream/jail.ts", 'export const backend = () => import("../index.js");');
57
- put("src/boot/snapshot.ts", 'export type Snapshot = import("../pi/native.js").Native;');
56
+ put("src/dream/jail.ts", 'export const backend = () => import("../../plugins/pi/native.js");');
57
+ put("src/boot/snapshot.ts", 'export type Snapshot = import("../../plugins/pi/native.js").Native;');
58
58
  put("src/history/decoder.ts", 'import type { SessionEntry } from "@earendil-works/pi-coding-agent"; export type Entry = SessionEntry;');
59
59
  put("src/history/query.ts", 'export type { Entry } from "./decoder.js";');
60
- const fixtureOptions = { ...options, baseUrl: root, paths: { "@native": ["src/pi/native.ts"] } };
60
+ const fixtureOptions = { ...options, baseUrl: root, paths: { "@native": ["plugins/pi/native.ts"] } };
61
61
  const violations = dependencyViolations(root, ["src/notes/identity.ts", "src/dream/jail.ts", "src/boot/snapshot.ts", "src/history/query.ts"], fixtureOptions, new Set());
62
62
  assert.deepEqual(violations, [
63
- "src/notes/identity.ts -> src/notes/bridge.ts -> src/pi/native.ts",
64
- "src/dream/jail.ts -> src/index.ts",
65
- "src/boot/snapshot.ts -> src/pi/native.ts",
63
+ "src/notes/identity.ts -> src/notes/bridge.ts -> plugins/pi/native.ts",
64
+ "src/dream/jail.ts -> plugins/pi/native.ts",
65
+ "src/boot/snapshot.ts -> plugins/pi/native.ts",
66
66
  "src/history/query.ts -> src/history/decoder.ts -> @earendil-works/pi-coding-agent",
67
67
  ]);
68
- put("src/boot/snapshot.ts", 'export type Snapshot = import("../dsh/native.js").Native;');
69
- put("src/dsh/native.ts", "export type Native = string;");
68
+ put("src/boot/snapshot.ts", 'export type Snapshot = import("../../plugins/dsh/native.js").Native;');
69
+ put("plugins/dsh/native.ts", "export type Native = string;");
70
70
  put("src/history/query.ts", 'export type { Session } from "@deepseek-ai/dsh-session";');
71
71
  assert.deepEqual(dependencyViolations(root, ["src/boot/snapshot.ts", "src/history/query.ts"], fixtureOptions, new Set()), [
72
- "src/boot/snapshot.ts -> src/dsh/native.ts",
72
+ "src/boot/snapshot.ts -> plugins/dsh/native.ts",
73
73
  "src/history/query.ts -> @deepseek-ai/dsh-session",
74
74
  ]);
75
75
  put("src/notes/bridge.ts", 'export type { Value as Native } from "./safe.js";');
76
76
  put("src/notes/safe.ts", "export type Value = string;");
77
77
  assert.deepEqual(dependencyViolations(root, ["src/notes/identity.ts"], fixtureOptions, new Set()), [], "a host-neutral type/re-export chain is allowed");
78
78
  });
79
- test("adapter policies reject foreign hosts and notes internals, including reachable Claude hooks", (t) => {
80
- const root = mkdtempSync(join(tmpdir(), "context-adapters-"));
79
+ test("plugin policies reject foreign hosts and notes internals, including reachable Claude hooks", (t) => {
80
+ const root = mkdtempSync(join(tmpdir(), "notesoup-plugins-"));
81
81
  t.after(() => rmSync(root, { recursive: true, force: true }));
82
82
  const put = (path, text) => { mkdirSync(dirname(join(root, path)), { recursive: true }); writeFileSync(join(root, path), text); };
83
83
  put("package.json", '{"type":"module"}');
@@ -86,30 +86,31 @@ test("adapter policies reject foreign hosts and notes internals, including reach
86
86
  const hosts = ["pi", "claude", "dsh"];
87
87
  const sdks = ["@earendil-works/pi-coding-agent", "claude-code", "@deepseek-ai/cordis"];
88
88
  for (const host of hosts)
89
- put(`src/${host}/native.ts`, "export const value = 1;");
89
+ put(`plugins/${host}/native.ts`, "export const value = 1;");
90
90
  for (const [index, host] of hosts.entries()) {
91
- const entry = `src/${host}/entry.ts`;
91
+ const entry = `plugins/${host}/entry.ts`;
92
92
  const check = () => dependencyViolations(root, [entry], options, new Set());
93
- put(entry, `export type { Note } from "../notes/index.js"; import type { Native } from "${sdks[index]}";`);
93
+ put(entry, `export type { Note } from "../../src/notes/index.js"; import type { Native } from "${sdks[index]}";`);
94
94
  assert.deepEqual(check(), [], `${host} may use its SDK and the notes entry`);
95
- put(entry, 'export type { Note } from "../notes/store.js";');
95
+ put(entry, 'export type { Note } from "../../src/notes/store.js";');
96
96
  assert.deepEqual(check(), [`${entry} -> src/notes/store.ts`]);
97
97
  const other = (index + 1) % hosts.length;
98
98
  put(entry, `export { value } from "../${hosts[other]}/native.js";`);
99
- assert.deepEqual(check(), [`${entry} -> src/${hosts[other]}/native.ts`]);
99
+ assert.deepEqual(check(), [`${entry} -> plugins/${hosts[other]}/native.ts`]);
100
100
  put(entry, `export type { Native } from "${sdks[other]}";`);
101
101
  assert.deepEqual(check(), [`${entry} -> ${sdks[other]}`]);
102
102
  }
103
- put("src/claude/entry.ts", 'export { value } from "../../mods/notesoup/hooks/register.js";');
104
- put("mods/notesoup/hooks/register.ts", 'export { value } from "../../../src/pi/native.js";');
105
- assert.deepEqual(dependencyViolations(root, ["src/claude/entry.ts"], options, new Set()), ["src/claude/entry.ts -> mods/notesoup/hooks/register.ts -> src/pi/native.ts"]);
106
- put("mods/notesoup/hooks/register.ts", 'export type { Note } from "../../../src/notes/index.js";');
107
- assert.deepEqual(dependencyViolations(root, ["src/claude/entry.ts"], options, new Set()), []);
108
- put("src/pi/entry.ts", 'export type { Note } from "@notes-internal";');
109
- assert.deepEqual(dependencyViolations(root, ["src/pi/entry.ts"], { ...options, baseUrl: root, paths: { "@notes-internal": ["src/notes/store.ts"] } }, new Set()), ["src/pi/entry.ts -> src/notes/store.ts"]);
103
+ // The Claude hook module is reachable from the Claude plugin and must obey the same rules.
104
+ put("plugins/claude/src/entry.ts", 'export { value } from "../hooks/register.js";');
105
+ put("plugins/claude/hooks/register.ts", 'export { value } from "../../pi/native.js";');
106
+ assert.deepEqual(dependencyViolations(root, ["plugins/claude/src/entry.ts"], options, new Set()), ["plugins/claude/src/entry.ts -> plugins/claude/hooks/register.ts -> plugins/pi/native.ts"]);
107
+ put("plugins/claude/hooks/register.ts", 'export type { Note } from "../../../src/notes/index.js";');
108
+ assert.deepEqual(dependencyViolations(root, ["plugins/claude/src/entry.ts"], options, new Set()), []);
109
+ put("plugins/pi/entry.ts", 'export type { Note } from "@notes-internal";');
110
+ assert.deepEqual(dependencyViolations(root, ["plugins/pi/entry.ts"], { ...options, baseUrl: root, paths: { "@notes-internal": ["src/notes/store.ts"] } }, new Set()), ["plugins/pi/entry.ts -> src/notes/store.ts"]);
110
111
  });
111
112
  test("runtime cycles are rejected but explicit and implicitly erased type edges are allowed", (t) => {
112
- const root = mkdtempSync(join(tmpdir(), "context-cycles-"));
113
+ const root = mkdtempSync(join(tmpdir(), "notesoup-cycles-"));
113
114
  t.after(() => rmSync(root, { recursive: true, force: true }));
114
115
  mkdirSync(join(root, "src/boot"), { recursive: true });
115
116
  writeFileSync(join(root, "package.json"), '{"type":"module"}');
@@ -136,18 +137,25 @@ test("AST guard sees every literal module edge, not import-like prose or comment
136
137
  `, ts.ScriptTarget.Latest, true);
137
138
  assert.deepEqual(moduleReferences(source), ["type-import", "type-reexport", "reexport", "import-type", "dynamic-import", "import-equals", "require-call"]);
138
139
  });
139
- test("the intentional root exports only the Pi extension and its settings-bound factory", () => {
140
- assert.deepEqual(Object.keys(entry).sort(), ["createNotesoup", "default"]);
141
- assert.equal(entry.default, notesoup);
142
- assert.equal(entry.createNotesoup, createNotesoup);
143
- assert.equal(typeof entry.createNotesoup(), "function");
140
+ test("the core entry is host-neutral and the Pi plugin entry owns the extension", () => {
141
+ assert.deepEqual(Object.keys(core).sort(), [
142
+ "DEFAULT_BOOT_TOOL_NAMES", "NoteError", "createNotesStore", "deriveThresholds", "historyList", "historyRead", "historyWindows",
143
+ "loadNotesSnapshot", "noteIdentity", "notesList", "notesRead", "notesSearch", "notesUpdate", "notesWrite", "projectHistory",
144
+ "projectKey", "remainingBudget", "renderBootBlock", "renderProtocolBlock", "selectContinuation", "slugify",
145
+ "tokenBudgetGuidance", "unavailableNotesSnapshot", "warningPrompt", "WARNING_BODY",
146
+ ].sort(), "the core exports a curated host-neutral surface and no extension");
147
+ assert.deepEqual(Object.keys(pi).sort(), ["createNotesoup", "default"], "the Pi plugin entry owns the extension");
148
+ assert.equal(pi.default, notesoup);
149
+ assert.equal(pi.createNotesoup, createNotesoup);
150
+ assert.equal(typeof createNotesoup(), "function");
144
151
  });
145
- test("configured extension source and moved dream CLI are executable current entries", async () => {
152
+ test("the configured extension source and the moved dream CLI are executable current entries", async () => {
146
153
  const root = repository();
147
154
  const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
155
+ assert.deepEqual(manifest.pi.extensions, ["./plugins/pi/index.ts"], "Pi loads the plugin entry from TypeScript source");
148
156
  const entrySource = resolve(root, manifest.pi.extensions[0]);
149
157
  assert.ok(existsSync(entrySource), "the manifest entry exists as TypeScript source (Pi loads it directly; plain Node cannot)");
150
- const built = await import(pathToFileURL(resolve(root, "dist/src/index.js")).href);
158
+ const built = await import(pathToFileURL(resolve(root, "dist/plugins/pi/index.js")).href);
151
159
  const tools = [];
152
160
  const commands = [];
153
161
  built.default({
@@ -156,7 +164,7 @@ test("configured extension source and moved dream CLI are executable current ent
156
164
  registerCommand(name) { commands.push(name); },
157
165
  });
158
166
  assert.deepEqual(tools.map((tool) => tool.name).sort(), ["empty_brain", "get_context_remaining", "history_list", "history_read", "history_windows", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
159
- assert.deepEqual(commands.sort(), ["empty-brain", "fresh-window", "notesoup"]);
167
+ assert.deepEqual(commands.sort(), ["empty", "fresh-window", "notesoup"]);
160
168
  const help = execFileSync(process.execPath, [resolve(root, manifest.bin.dream), "--help"], { cwd: root, encoding: "utf8" });
161
169
  assert.ok(help.startsWith("dream doctor [--notes-home <dir>]"));
162
170
  assert.ok(help.includes("Default playbook: <installed package root>/playbook.md"));
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { main } from "../src/pi/dream/cli.js";
2
+ import { main } from "../plugins/pi/dream/cli.js";
3
3
  import { doctor } from "../src/dream/doctor.js";
4
4
  import { existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
5
5
  import test from "node:test";
@@ -28,8 +28,8 @@ test("dream skill is publicly discoverable and resolves the CLI's shared playboo
28
28
  const root = packageRoot();
29
29
  const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
30
30
  assert.deepEqual(manifest.pi.skills, ["./skills"]);
31
- assert.deepEqual(manifest.pi.extensions, ["./src/index.ts"]);
32
- assert.equal(manifest.bin.dream, "dist/src/pi/dream/cli.js");
31
+ assert.deepEqual(manifest.pi.extensions, ["./plugins/pi/index.ts"]);
32
+ assert.equal(manifest.bin.dream, "dist/plugins/pi/dream/cli.js");
33
33
  assert.ok(manifest.files.includes("skills"));
34
34
  discoverSkill(join(root, "skills"), "memory");
35
35
  const skill = discoverSkill(join(root, "skills"), "dream");
@@ -52,8 +52,8 @@ test("npm tarball keeps the skill's relative playbook path portable after extrac
52
52
  assert.ok(packedPaths.includes("skills/dream/SKILL.md"));
53
53
  assert.ok(packedPaths.includes("skills/memory/SKILL.md"));
54
54
  assert.ok(packedPaths.includes("playbook.md"));
55
- assert.ok(packedPaths.includes("src/index.ts"));
56
- assert.ok(packedPaths.includes("dist/src/pi/dream/cli.js"));
55
+ assert.ok(packedPaths.includes("plugins/pi/index.ts"));
56
+ assert.ok(packedPaths.includes("dist/plugins/pi/dream/cli.js"));
57
57
  const extracted = join(fixture, "extracted");
58
58
  execFileSync("mkdir", ["-p", extracted]);
59
59
  execFileSync("tar", ["-xzf", join(fixture, packed.filename), "-C", extracted]);
@@ -5,8 +5,8 @@ import test from "node:test";
5
5
  import { tmpdir } from "node:os";
6
6
  import { basename, join } from "node:path";
7
7
  import { acquireLock, releaseLock } from "../src/dream/lock.js";
8
- import { dreamerDeleteToolDefinition, dreamerWriteToolDefinitions } from "../src/pi/dream/runner.js";
9
- import { main } from "../src/pi/dream/cli.js";
8
+ import { dreamerDeleteToolDefinition, dreamerWriteToolDefinitions } from "../plugins/pi/dream/runner.js";
9
+ import { main } from "../plugins/pi/dream/cli.js";
10
10
  const fixture = () => mkdtempSync(join(tmpdir(), "dream-test-"));
11
11
  function scriptedSession(run) {
12
12
  return async ({ cwd }) => {
@@ -22,8 +22,8 @@ test("dsh profile loads our rows and a second process restores the on-disk windo
22
22
  await writeFile(join(profile, "package.json"), JSON.stringify({ name: "notesoup-test", private: true, version: "0.0.0", dsh: { profile: { bundles: ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-headless"] } } }));
23
23
  const example = await readFile(join(repository, "docs/dsh.profile.patch.yml"), "utf8");
24
24
  const patch = example
25
- .replace("'notesoup/dsh/engine'", `'${pathToFileURL(join(repository, "dist/src/dsh/engine.js")).href}'`)
26
- .replace("'notesoup/dsh'", `'${pathToFileURL(join(repository, "dist/src/dsh/index.js")).href}'`)
25
+ .replace("'notesoup/dsh/engine'", `'${pathToFileURL(join(repository, "dist/plugins/dsh/engine.js")).href}'`)
26
+ .replace("'notesoup/dsh'", `'${pathToFileURL(join(repository, "dist/plugins/dsh/index.js")).href}'`)
27
27
  .replace("# notesHome: /absolute/path/to/notes", `notesHome: ${join(directory, "notes")}`);
28
28
  await writeFile(join(profile, "cordis.patch.yml"), patch + "\n- id: session-title-llm\n disabled: true\n");
29
29
  const env = { ...process.env, DSH_HOME: home, DEEPSEEK_API_KEY: "mock-key", DEEPSEEK_BASE_URL: mock.url, DSH_TOOLS_MODE: "native" };
@@ -4,7 +4,7 @@ import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
4
4
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
5
5
  import { pluginRecordOf } from "@deepseek-ai/dsh-session";
6
6
  import { dshFixture } from "./helpers/dsh.js";
7
- import { WINDOW_RECORD } from "../src/dsh/window.js";
7
+ import { WINDOW_RECORD } from "../plugins/dsh/window.js";
8
8
  /** Pin the shared host contract while naming our intentional template-vs-LLM differences. */
9
9
  function transactionShape(session, from, head, result) {
10
10
  const events = session.snapshotEvents().slice(from);
@@ -14,11 +14,11 @@ import { notesRead } from "../src/tools/notes.js";
14
14
  import { success } from "../src/tools/result.js";
15
15
  import { createNotesStore } from "../src/notes/index.js";
16
16
  import { dshFixture } from "./helpers/dsh.js";
17
- import { decodeHistory } from "../src/dsh/history.js";
18
- import { checkpointSnapshot, notesIdentity, recoverSnapshot, WINDOW_RECORD } from "../src/dsh/window.js";
19
- import { measureBudget } from "../src/dsh/budget.js";
17
+ import { decodeHistory } from "../plugins/dsh/history.js";
18
+ import { checkpointSnapshot, notesIdentity, recoverSnapshot, WINDOW_RECORD } from "../plugins/dsh/window.js";
19
+ import { measureBudget } from "../plugins/dsh/budget.js";
20
20
  import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, NORMAL_CONTINUATIONS } from "../src/budget/text.js";
21
- import { preflight } from "../src/dsh/engine.js";
21
+ import { preflight } from "../plugins/dsh/engine.js";
22
22
  import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
23
23
  function prompt(text) { return createUserMessage({ content: [{ type: "text", text }], source: { kind: "user" } }); }
24
24
  async function run(agent, text) { agent.followup(prompt(text)); await agent.whenIdle(); }
@@ -50,14 +50,15 @@ export function dependencyViolations(root, entries, options, runtimeDependencies
50
50
  const runtime = new Map();
51
51
  const cache = ts.createModuleResolutionCache(root, (path) => path, options);
52
52
  const sourceRoot = resolve(root, "src");
53
- const rootEntry = resolve(sourceRoot, "index.ts");
53
+ const pluginRoot = resolve(root, "plugins");
54
+ const notesRoot = resolve(sourceRoot, "notes");
54
55
  const notesEntry = resolve(sourceRoot, "notes/index.ts");
55
56
  const display = (path) => relative(root, path).split(sep).join("/");
56
- const local = (file) => file.startsWith(sourceRoot + sep) || file.startsWith(resolve(root, "mods/notesoup") + sep);
57
+ const local = (file) => file.startsWith(sourceRoot + sep) || file.startsWith(pluginRoot + sep);
57
58
  const adapter = (file) => {
58
59
  const path = display(file);
59
- return file === rootEntry ? "pi" : /^src\/(pi|claude|dsh)\//.exec(path)?.[1]
60
- ?? (path.startsWith("mods/notesoup/") ? "claude" : packageAdapter(file.split(sep).join("/").split("/node_modules/").at(-1)));
60
+ return /^plugins\/(pi|claude|dsh)\//.exec(path)?.[1]
61
+ ?? packageAdapter(file.split(sep).join("/").split("/node_modules/").at(-1));
61
62
  };
62
63
  const walk = (file, chain) => {
63
64
  file = realpathSync(file);
@@ -86,9 +87,10 @@ export function dependencyViolations(root, entries, options, runtimeDependencies
86
87
  }
87
88
  const target = realpathSync(resolution.resolvedFileName);
88
89
  const targetOwner = adapter(target);
89
- if (target === rootEntry || (targetOwner && targetOwner !== owner) ||
90
- (owner && target.startsWith(resolve(sourceRoot, "notes") + sep) && target !== notesEntry) ||
91
- (owner === "dsh" && target.startsWith(resolve(sourceRoot, "dream") + sep))) {
90
+ if ((targetOwner && targetOwner !== owner) ||
91
+ (owner && target.startsWith(notesRoot + sep) && target !== notesEntry) ||
92
+ (owner === "dsh" && target.startsWith(resolve(sourceRoot, "dream") + sep)) ||
93
+ (!owner && target.startsWith(pluginRoot + sep))) {
92
94
  violations.push([...here, display(target)].join(" -> "));
93
95
  continue;
94
96
  }
@@ -1,7 +1,7 @@
1
1
  import type { TestContext } from "node:test";
2
2
  import { Context } from "@deepseek-ai/cordis";
3
3
  import { type SessionEvent } from "@deepseek-ai/dsh-session";
4
- import NotesoupEngine, { type EngineConfig } from "../../src/dsh/engine.js";
4
+ import NotesoupEngine, { type EngineConfig } from "../../plugins/dsh/engine.js";
5
5
  export declare function dshFixture(t: TestContext, config?: EngineConfig): Promise<{
6
6
  ctx: Context;
7
7
  engine: NotesoupEngine;
@@ -14,8 +14,8 @@ import Tools from "@deepseek-ai/dsh-tools";
14
14
  import Meter from "@deepseek-ai/dsh-token-meter";
15
15
  import Query from "@deepseek-ai/dsh-session-query-sqlite";
16
16
  import { createLaunchEnvironmentSnapshot } from "@deepseek-ai/dsh-launch-environment";
17
- import NotesoupEngine from "../../src/dsh/engine.js";
18
- import notesoup from "../../src/dsh/index.js";
17
+ import NotesoupEngine from "../../plugins/dsh/engine.js";
18
+ import notesoup from "../../plugins/dsh/index.js";
19
19
  import { messagesServer } from "./dsh-messages.js";
20
20
  export async function dshFixture(t, config = {}) {
21
21
  const directory = await mkdtemp(join(tmpdir(), "ns-dsh-test-"));
@@ -1,15 +1,16 @@
1
- import { notesIdentityFromPi } from "../../src/pi/notes/adapter.js";
2
- import { DEFAULT_BOOT_TOOL_NAMES, PI_PRE_RESET_HINTS, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
1
+ import { notesIdentityFromPi } from "../../plugins/pi/notes/adapter.js";
2
+ import { DEFAULT_BOOT_TOOL_NAMES, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
3
+ import { PI_PRE_RESET_HINTS } from "../../plugins/pi/text.js";
3
4
  import assert from "node:assert/strict";
4
5
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
5
6
  import { tmpdir } from "node:os";
6
7
  import { dirname, join } from "node:path";
7
8
  import { SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
8
- import notesoup, { createNotesoup } from "../../src/pi/extension.js";
9
+ import notesoup, { createNotesoup } from "../../plugins/pi/extension.js";
9
10
  import { loadNotesSnapshot } from "../../src/boot/snapshot.js";
10
11
  import { renderBootBlock } from "../../src/boot/render.js";
11
- import { agentSlug, modelSlug } from "../../src/pi/notes/adapter.js";
12
- import { rootWindowId } from "../../src/pi/window.js";
12
+ import { agentSlug, modelSlug } from "../../plugins/pi/notes/adapter.js";
13
+ import { rootWindowId } from "../../plugins/pi/window.js";
13
14
  import { TOOL_OUTPUT_MAX_BYTES } from "../../src/tools/output.js";
14
15
  import { structuredBytes } from "../../src/tools/result.js";
15
16
  let defaultCwd = "/private/tmp/notesoup-test-cwd";
@@ -1,5 +1,5 @@
1
1
  import { createNotesStore } from "../../src/notes/index.js";
2
- import { notesIdentityFromPi } from "../../src/pi/notes/adapter.js";
2
+ import { notesIdentityFromPi } from "../../plugins/pi/notes/adapter.js";
3
3
  import { physicalPath as corePhysicalPath, scopeDir as coreScopeDir } from "../../src/notes/paths.js";
4
4
  /** Test-only conveniences for fixtures that still model notes through a live Pi context. */
5
5
  export function physicalPath(scope, path, ctx, who) {
@@ -4,8 +4,10 @@ import { join } from "node:path";
4
4
  import { tmpdir } from "node:os";
5
5
  import { renderBootBlock } from "../src/boot/render.js";
6
6
  import { loadNotesSnapshot } from "../src/boot/snapshot.js";
7
- import { CLAUDE_WIPE_SENTENCE, DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, PI_PRE_RESET_HINTS, WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
8
- import { CLAUDE_WARNING_PROMPT, COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, LAST_WORD_HINT, NORMAL_CONTINUATIONS, WARNING_BODY, selectContinuation, tokenBudgetGuidance, warningContent } from "../src/budget/text.js";
7
+ import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
8
+ import { CLAUDE_WARNING_PROMPT, CLAUDE_WIPE_SENTENCE } from "../plugins/claude/src/text.js";
9
+ import { PI_PRE_RESET_HINTS, LAST_WORD_HINT, warningContent } from "../plugins/pi/text.js";
10
+ import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, WARNING_BODY, selectContinuation, tokenBudgetGuidance } from "../src/budget/text.js";
9
11
  /**
10
12
  * The reviewed Design text is what the model actually reads, so the golden copies below pin it
11
13
  * character for character: an edit that drifts the wording has to change them too.
@@ -103,8 +105,8 @@ test("the countdown closes the second-tier notice only, in both hosts", () => {
103
105
  assert.ok(pi.endsWith(`\n${GUIDANCE_CLOSE_TAG}`));
104
106
  assert.ok(pi.includes(`\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n`), "the countdown comes after the Pi-only last-word hint");
105
107
  assert.equal(pi.split(COUNTDOWN_LINE).length - 1, 1, "the second tier carries the countdown exactly once");
106
- const prompted = warningContent("/empty-brain keep going");
107
- assert.ok(prompted.includes("<notesoup:next_window_prompt>\n/empty-brain keep going\n</notesoup:next_window_prompt>"));
108
+ const prompted = warningContent("/empty keep going");
109
+ assert.ok(prompted.includes("<notesoup:next_window_prompt>\n/empty keep going\n</notesoup:next_window_prompt>"));
108
110
  assert.ok(prompted.endsWith(`\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`), "the prompt block does not displace the countdown");
109
111
  assert.equal(CLAUDE_WARNING_PROMPT.endsWith(`\n${COUNTDOWN_LINE}`), true, "Claude's variant ends the same way");
110
112
  assert.equal(tokenBudgetGuidance(100, "empty_brain").includes(COUNTDOWN_LINE), false, "the first tier never counts down");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,161 @@
1
+ import assert from "node:assert/strict";
2
+ import { chmodSync, 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 { createNotesStore, noteIdentity, NoteError } from "../src/notes/index.js";
7
+ import { scopeDir } from "../src/notes/paths.js";
8
+ function fixture(t) {
9
+ const home = mkdtempSync(join(tmpdir(), "notes-query-homes-"));
10
+ t.after(() => rmSync(home, { recursive: true, force: true }));
11
+ const identity = { home, sessionId: "DSH.Run_1+local", projectKey: "current-project", agent: "current-agent", model: "current-model" };
12
+ const foreignIdentity = { ...identity, sessionId: "DSH.Run_2+@remote", projectKey: "other-project", agent: "other-agent", model: "other-model" };
13
+ return { home, identity, foreignIdentity, notes: createNotesStore(identity), foreign: createNotesStore(foreignIdentity) };
14
+ }
15
+ function addresses(rows) {
16
+ return rows.map(row => row.address).sort();
17
+ }
18
+ async function populate(t) {
19
+ const fixtureData = fixture(t);
20
+ const { notes, foreign, foreignIdentity } = fixtureData;
21
+ const current = ["shared.md", "@project/shared.md", "@human/shared.md", "@self/shared.md", "@model/shared.md"].sort();
22
+ for (const address of current)
23
+ await notes.write(address, "needle in current home");
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");
26
+ const all = [...current,
27
+ `@sessions/${foreignIdentity.sessionId}/shared.md`,
28
+ "@projects/other-project/shared.md", "@agents/other-agent/shared.md", "@models/other-model/shared.md",
29
+ ].sort();
30
+ return { ...fixtureData, current, all };
31
+ }
32
+ test("default spellings stay local while explicit ** lists and searches each home once", async (t) => {
33
+ const { notes, current, all, identity } = await populate(t);
34
+ assert.deepEqual(addresses(await notes.list()), current);
35
+ for (const glob of [null, "", "@default"]) {
36
+ assert.deepEqual(addresses(await notes.list({ glob })), current);
37
+ assert.deepEqual(addresses(await notes.search(["needle"], { glob })), current);
38
+ }
39
+ const rows = await notes.list({ glob: "**" });
40
+ assert.deepEqual(addresses(rows), all);
41
+ assert.deepEqual(addresses(await notes.search(["needle"], { glob: "**" })), all);
42
+ assert.equal(new Set(rows.map(row => row.address)).size, rows.length);
43
+ for (const row of rows)
44
+ assert.equal((await notes.read(row.address))?.body.startsWith("needle"), true, "every result is a real readable address");
45
+ assert.deepEqual(await notes.list({ glob: "@default/**" }), [], "@default is a bare selector, not an address prefix");
46
+ assert.deepEqual(addresses(await notes.list({ glob: "@project/**" })), ["@project/shared.md"]);
47
+ assert.deepEqual(addresses(await notes.list({ glob: "@self/**" })), ["@self/shared.md"]);
48
+ assert.deepEqual(addresses(await notes.list({ glob: "@model/**" })), ["@model/shared.md"]);
49
+ assert.deepEqual(addresses(await notes.list({ glob: `@projects/${identity.projectKey}/**` })), [`@projects/${identity.projectKey}/shared.md`], "explicit current project stays a named read-only address");
50
+ });
51
+ test("explicit patterns use canonical addresses, with bare-path matching only for the current session", async (t) => {
52
+ const { notes, identity, foreignIdentity, foreign, all } = await populate(t);
53
+ await notes.write("deep/nested.md", "needle nested");
54
+ await foreign.write("deep/nested.md", "needle elsewhere");
55
+ await foreign.write("only-foreign.md", "needle foreign only");
56
+ assert.deepEqual(addresses(await notes.list({ glob: "*.md" })), ["shared.md"]);
57
+ assert.deepEqual(addresses(await notes.list({ glob: "deep/**" })), ["deep/nested.md"]);
58
+ assert.deepEqual(await notes.search(["needle"], { glob: "only-foreign.md" }), [], "foreign sessions get no implicit basename alias");
59
+ assert.deepEqual(addresses(await notes.list({ glob: "**/shared.md" })), all);
60
+ assert.deepEqual(addresses(await notes.list({ glob: "@*/**/shared.md" })), all, "a wildcard head is not mistaken for an unknown reserved head");
61
+ assert.deepEqual(addresses(await notes.list({ glob: `@sessions/${identity.sessionId}/**` })), [
62
+ `@sessions/${identity.sessionId}/deep/nested.md`, `@sessions/${identity.sessionId}/shared.md`,
63
+ ].sort(), "explicit session patterns return canonical addresses even for the current session");
64
+ assert.deepEqual(addresses(await notes.list({ glob: "@sessions/*/shared.md" })), [
65
+ `@sessions/${identity.sessionId}/shared.md`, `@sessions/${foreignIdentity.sessionId}/shared.md`,
66
+ ].sort());
67
+ });
68
+ test("named session reads leave bytes untouched and explicit session mutations refuse both endpoints", async (t) => {
69
+ const { identity, foreignIdentity, notes, foreign } = fixture(t);
70
+ await notes.write("local.md", "local body");
71
+ await foreign.write("foreign.md", "foreign body", { origin: "user" });
72
+ const foreignAddress = `@sessions/${foreignIdentity.sessionId}/foreign.md`;
73
+ const currentAddress = `@sessions/${identity.sessionId}/local.md`;
74
+ const foreignFile = join(scopeDir("session", foreignIdentity), "foreign.md");
75
+ const currentFile = join(scopeDir("session", identity), "local.md");
76
+ const beforeForeign = readFileSync(foreignFile, "utf8");
77
+ const beforeCurrent = readFileSync(currentFile, "utf8");
78
+ const read = (await notes.read(foreignAddress));
79
+ assert.equal(read.body, "foreign body");
80
+ assert.equal(read.meta.accessCount, 0);
81
+ assert.equal(read.meta.project, foreignIdentity.projectKey);
82
+ assert.equal(read.resolvedScope, "session");
83
+ assert.equal((await notes.read(currentAddress))?.body, "local body");
84
+ assert.deepEqual(noteIdentity(identity, foreignAddress), { address: foreignAddress });
85
+ assert.equal(await notes.read(`@sessions/${foreignIdentity.sessionId}/missing.md`), undefined);
86
+ const readOnly = (error) => error instanceof NoteError && error.code === "invalid_scope";
87
+ await assert.rejects(() => notes.write(foreignAddress, "overwritten"), readOnly);
88
+ await assert.rejects(() => notes.write(currentAddress, "overwritten"), readOnly);
89
+ await assert.rejects(() => notes.update(foreignAddress, undefined, { crumpled: true }), readOnly);
90
+ await assert.rejects(() => notes.rename(foreignAddress, "stolen.md"), readOnly);
91
+ await assert.rejects(() => notes.rename("local.md", currentAddress), readOnly);
92
+ await assert.rejects(() => notes.update("local.md", [{ oldText: "local", newText: "changed" }], { renameTo: foreignAddress }), readOnly);
93
+ assert.equal(readFileSync(foreignFile, "utf8"), beforeForeign);
94
+ assert.equal(readFileSync(currentFile, "utf8"), beforeCurrent);
95
+ assert.equal((await notes.read("local.md"))?.meta.accessCount, 1, "the bare current-session alias retains ordinary access accounting");
96
+ await assert.rejects(() => notes.read("@sessions/../escape.md"), (error) => error instanceof NoteError && error.code === "invalid_address");
97
+ await assert.rejects(() => notes.list({ glob: "@sessions/bad:id/**" }), readOnly);
98
+ assert.equal(readFileSync(foreignFile, "utf8"), beforeForeign);
99
+ });
100
+ test("named project reads and relative identity rendering survive global enumeration of unmarked homes", async (t) => {
101
+ const { home, identity, notes } = fixture(t);
102
+ const project = join(home, "project", "another-project");
103
+ mkdirSync(project, { recursive: true });
104
+ writeFileSync(join(project, ".project"), JSON.stringify({ id: "remote/project", path: "/workspace/another" }));
105
+ writeFileSync(join(project, "decision.md"), "needle project");
106
+ const legacy = join(home, "project", "legacy-project");
107
+ mkdirSync(legacy, { recursive: true });
108
+ writeFileSync(join(legacy, "legacy.md"), "needle legacy");
109
+ await notes.write("@self/agent.md", "needle agent");
110
+ await notes.write("@model/model.md", "needle model");
111
+ assert.deepEqual(addresses(await notes.list({ glob: "**" })), [
112
+ "@projects/another-project/decision.md", "@projects/legacy-project/legacy.md", "@self/agent.md", "@model/model.md",
113
+ ].sort());
114
+ const address = "@projects/another-project/decision.md";
115
+ const before = readFileSync(join(project, "decision.md"), "utf8");
116
+ assert.equal((await notes.read(address))?.body, "needle project");
117
+ assert.equal(readFileSync(join(project, "decision.md"), "utf8"), before);
118
+ assert.deepEqual(noteIdentity(identity, address), { address, project_root: "/workspace/another" });
119
+ assert.equal(noteIdentity(identity, `@agents/${identity.agent}/agent.md`).address, "@self/agent.md");
120
+ assert.equal(noteIdentity(identity, `@models/${identity.model}/model.md`).address, "@model/model.md");
121
+ await assert.rejects(() => notes.write(address, "no"), (error) => error instanceof NoteError && error.code === "invalid_scope");
122
+ });
123
+ test("global status isolates every failed namespace and reserved heads do not scan unrelated homes", async (t) => {
124
+ const { home, notes } = fixture(t);
125
+ await notes.write("@human/available.md", "needle");
126
+ mkdirSync(join(home, "pi"), { recursive: true });
127
+ for (const root of ["pi/session", "project", "agents", "models"])
128
+ writeFileSync(join(home, root), "not a directory");
129
+ const expected = { homesUnavailable: ["@sessions", "@projects", "@agents", "@models"] };
130
+ const listed = await notes.listWithStatus({ glob: "**" });
131
+ assert.deepEqual(addresses(listed.rows), ["@human/available.md"]);
132
+ assert.deepEqual(listed.status, expected);
133
+ assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status, expected);
134
+ assert.deepEqual((await notes.listWithStatus({ glob: "@human/**" })).status.homesUnavailable, []);
135
+ await assert.rejects(() => notes.list({ glob: "**" }), (error) => error.code === "ENOTDIR");
136
+ });
137
+ test("global status reports failed enumerated homes individually and keeps readable siblings", async (t) => {
138
+ if (process.getuid?.() === 0 || process.platform === "win32")
139
+ return t.skip("chmod 000 does not refuse this user's reads");
140
+ const { notes, foreignIdentity, current, home, all } = await populate(t);
141
+ const failed = [scopeDir("session", foreignIdentity), scopeDir("project", foreignIdentity)];
142
+ for (const dir of failed)
143
+ chmodSync(dir, 0o000);
144
+ try {
145
+ const result = await notes.listWithStatus({ glob: "**" });
146
+ const unavailable = [`@sessions/${foreignIdentity.sessionId}`, "@projects/other-project"];
147
+ assert.deepEqual(result.status.homesUnavailable, unavailable);
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");
151
+ // A namespace scan must not read project marker files or let one bad marker abort its siblings.
152
+ chmodSync(failed[1], 0o755);
153
+ writeFileSync(join(home, "project/other-project/.project"), "{}");
154
+ chmodSync(join(home, "project/other-project/.project"), 0o000);
155
+ assert.deepEqual((await notes.listWithStatus({ glob: "@projects/*/**" })).status.homesUnavailable, []);
156
+ }
157
+ finally {
158
+ for (const dir of failed)
159
+ chmodSync(dir, 0o755);
160
+ }
161
+ });
@@ -1,4 +1,4 @@
1
- import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
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
4
  import { mkdirSync, rmSync, writeFileSync } from "node:fs";
@@ -6,7 +6,8 @@ import { dirname } from "node:path";
6
6
  import test from "node:test";
7
7
  import { loadNotesSnapshot } from "../src/boot/snapshot.js";
8
8
  import { renderBootBlock } from "../src/boot/render.js";
9
- import { MAP_BOOT_MAX_CHARS, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, PI_PRE_RESET_HINTS } from "../src/boot/text.js";
9
+ import { MAP_BOOT_MAX_CHARS, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG } from "../src/boot/text.js";
10
+ import { PI_PRE_RESET_HINTS } from "../plugins/pi/text.js";
10
11
  import { localIso } from "../src/notes/frontmatter.js";
11
12
  import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
12
13
  import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
@@ -17,7 +17,7 @@ import { createNotesStore, projectKey } from "../src/notes/index.js";
17
17
  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
- import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
20
+ import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
21
21
  import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
22
22
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
23
23
  const testEnvironment = installExtensionTestHooks("notesoup-notes");