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
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, join, resolve, sep } from "node:path";
4
4
  import { slugify } from "./paths.js";
5
5
  function errno(error) {
@@ -94,19 +94,19 @@ function readMarker(dir) {
94
94
  }
95
95
  try {
96
96
  const value = JSON.parse(raw);
97
- if (typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0)
98
- return undefined;
97
+ if (!value || typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0)
98
+ throw new Error("Expected non-empty id and path");
99
99
  return { name: basename(dir), dir, id: value.id, path: value.path };
100
100
  }
101
- catch {
102
- return undefined;
101
+ catch (cause) {
102
+ throw new Error(`Invalid project marker at ${join(dir, ".project")}`, { cause });
103
103
  }
104
104
  }
105
105
  function projectRoot(home) {
106
106
  return join(home, "project");
107
107
  }
108
- /** Read marked project homes. Unmarked legacy directories are deliberately omitted. */
109
- export function projectHomes(home) {
108
+ /** Read marked project notebooks. Unmarked legacy directories are deliberately omitted. */
109
+ export function projectNamespaces(home) {
110
110
  const root = projectRoot(home);
111
111
  let entries;
112
112
  try {
@@ -119,8 +119,8 @@ export function projectHomes(home) {
119
119
  }
120
120
  return entries.filter(entry => entry.isDirectory()).map(entry => readMarker(join(root, entry.name))).filter((entry) => entry !== undefined).sort((a, b) => a.name.localeCompare(b.name));
121
121
  }
122
- function updateMarker(home, marker) {
123
- const markerPath = join(home.dir, ".project");
122
+ function updateMarker(namespace, marker) {
123
+ const markerPath = join(namespace.dir, ".project");
124
124
  const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
125
125
  try {
126
126
  writeFileSync(temp, JSON.stringify(marker));
@@ -133,19 +133,55 @@ function updateMarker(home, marker) {
133
133
  catch { /* Preserve the marker update failure. */ }
134
134
  throw error;
135
135
  }
136
- return { ...home, ...marker };
136
+ return { ...namespace, ...marker };
137
+ }
138
+ const claimSleep = new Int32Array(new SharedArrayBuffer(4));
139
+ function awaitClaim(path, attempt) {
140
+ const deadline = performance.now() + 5_000;
141
+ for (;;) {
142
+ const result = attempt();
143
+ if (result !== undefined)
144
+ return result;
145
+ const remaining = deadline - performance.now();
146
+ if (remaining <= 0)
147
+ throw new Error(`Timed out waiting for project claim at ${path}`);
148
+ Atomics.wait(claimSleep, 0, 0, Math.min(10, remaining));
149
+ }
137
150
  }
138
- /** Resolve and claim the readable home for one repository identity. */
139
- export function resolveProjectHome(cwd, home) {
151
+ /** Resolve and claim the readable notebook for one repository identity. */
152
+ export function resolveProjectNamespace(cwd, home) {
153
+ mkdirSync(projectRoot(home), { recursive: true });
154
+ // Serialize the scan as well as publication: an unmarked directory seen under
155
+ // this lock is legacy, not another resolver between mkdir and marker write.
156
+ const lock = join(home, ".project-claim");
157
+ awaitClaim(lock, () => {
158
+ try {
159
+ mkdirSync(lock);
160
+ return true;
161
+ }
162
+ catch (error) {
163
+ if (errno(error) === "EEXIST")
164
+ return undefined;
165
+ throw error;
166
+ }
167
+ });
168
+ try {
169
+ return claimProjectNamespace(cwd, home);
170
+ }
171
+ finally {
172
+ rmdirSync(lock);
173
+ }
174
+ }
175
+ function claimProjectNamespace(cwd, home) {
140
176
  const root = canonicalRoot(cwd);
141
177
  const remote = originRemote(root);
142
178
  const id = remote ?? root;
143
179
  const markerRoot = projectRoot(home);
144
180
  mkdirSync(markerRoot, { recursive: true });
145
- const homes = projectHomes(home);
146
- let found = homes.find(candidate => candidate.id === id);
181
+ const namespaces = projectNamespaces(home);
182
+ let found = namespaces.find(candidate => candidate.id === id);
147
183
  if (!found && remote) {
148
- found = homes.find(candidate => candidate.id === root);
184
+ found = namespaces.find(candidate => candidate.id === root);
149
185
  if (found)
150
186
  found = updateMarker(found, { id: remote, path: root });
151
187
  }
@@ -155,7 +191,7 @@ export function resolveProjectHome(cwd, home) {
155
191
  return found;
156
192
  }
157
193
  const base = slugify(basename(root));
158
- // Existing unmarked homes are taken; only directories appearing after this scan can be raced.
194
+ // The claim lock makes this a stable snapshot of legacy, unmarked names.
159
195
  const taken = new Set(readdirSync(markerRoot));
160
196
  for (let suffix = 0;; suffix++) {
161
197
  const name = suffix === 0 ? base : `${base}-${suffix}`;
@@ -163,15 +199,21 @@ export function resolveProjectHome(cwd, home) {
163
199
  continue;
164
200
  const dir = join(markerRoot, name);
165
201
  try {
166
- mkdirSync(dir, { recursive: true });
167
- writeFileSync(join(dir, ".project"), JSON.stringify({ id, path: root }), { flag: "wx" });
168
- return { name, dir, id, path: root };
202
+ mkdirSync(dir);
169
203
  }
170
204
  catch (error) {
171
- if (errno(error) === "EEXIST")
205
+ if (errno(error) !== "EEXIST")
206
+ throw error;
207
+ // A writer outside this protocol may have won after the snapshot.
208
+ // Never mistake its incomplete publication for a different identity.
209
+ let winner = awaitClaim(join(dir, ".project"), () => readMarker(dir));
210
+ if (winner.id !== id && !(remote && winner.id === root))
172
211
  continue;
173
- throw error;
212
+ if (winner.id !== id || winner.path !== root)
213
+ winner = updateMarker(winner, { id, path: root });
214
+ return winner;
174
215
  }
216
+ return updateMarker({ name, dir, id, path: root }, { id, path: root });
175
217
  }
176
218
  }
177
219
  /** Existing root discovery, including linked worktrees, without invoking Git. */
@@ -213,19 +255,19 @@ function repositoryRoot(dir) {
213
255
  const common = parts.slice(0, worktrees).join(sep);
214
256
  return basename(common) === ".git" ? dirname(common) : dir;
215
257
  }
216
- /** Display-only context for an explicitly named project home. */
258
+ /** Display-only context for an explicitly named project notebook. */
217
259
  export function projectReceipt(home, name) {
218
260
  const project = readMarker(join(projectRoot(home), name));
219
261
  if (!project)
220
262
  return {};
221
263
  const base = slugify(basename(project.path));
222
- const siblings = projectHomes(home).filter(candidate => candidate.name !== name && slugify(basename(candidate.path)) === base);
264
+ const siblings = projectNamespaces(home).filter(candidate => candidate.name !== name && slugify(basename(candidate.path)) === base);
223
265
  return {
224
266
  project_root: project.path,
225
267
  ...(siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name, path }) => ({ name, path })) }),
226
268
  };
227
269
  }
228
- /** Names a project home, claiming it when the notes home has not seen this identity. */
270
+ /** Names a project notebook, claiming it when the notes store has not seen this identity. */
229
271
  export function projectKey(cwd, home) {
230
- return resolveProjectHome(cwd, home).name;
272
+ return resolveProjectNamespace(cwd, home).name;
231
273
  }
@@ -1,7 +1,7 @@
1
1
  import { type NotesIdentity } from "./identity.js";
2
2
  import { type NoteMeta, type Origin } from "./frontmatter.js";
3
3
  import { type Scope } from "./paths.js";
4
- import { type ProjectReceipt } from "./project-home.js";
4
+ import { type ProjectReceipt } from "./project-namespace.js";
5
5
  export type { NoteMeta, Origin, Scope };
6
6
  export type NoteRow = {
7
7
  address: string;
@@ -36,7 +36,7 @@ export type EditOptions = {
36
36
  replaceAll?: boolean;
37
37
  renameTo?: string;
38
38
  };
39
- /** Omitted/null/empty glob or bare @default selects current homes; explicit globs match full addresses.
39
+ /** Omitted/null/empty glob or bare @default selects current notebooks; explicit globs match full addresses.
40
40
  * Only the current session also matches its bare-path alias (e.g. *.md or deep/**).
41
41
  */
42
42
  export type NotesQuery = {
@@ -76,9 +76,9 @@ export type NoteRenameResult = {
76
76
  meta: NoteMeta;
77
77
  replacedCrumpledTarget: boolean;
78
78
  };
79
- /** A home, or one unreadable note inside it, that a status-reporting query could not read. */
79
+ /** A notebook, or one unreadable note inside it, that a status-reporting query could not read. */
80
80
  export type NoteQueryStatus = {
81
- homesUnavailable: string[];
81
+ namespacesUnavailable: string[];
82
82
  };
83
83
  export type NoteQueryResult<T> = {
84
84
  rows: T[];
@@ -2,14 +2,14 @@ import { randomUUID } from "node:crypto";
2
2
  import { mkdir, readdir, readFile, realpath, rename, rm, unlink, writeFile } from "node:fs/promises";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { earliestMatchOffsetChars } from "../text-match.js";
5
- import { assertAddress, assertGlobPattern, addressFor, canonicalAddressFor, globToRegExp, HOME_HEADS } from "./address.js";
5
+ import { assertAddress, assertGlobPattern, addressFor, canonicalAddressFor, globToRegExp, NAMESPACE_HEADS } from "./address.js";
6
6
  import { isFilesystemError } from "./fs-error.js";
7
7
  import { snapshotNotesIdentity } from "./identity.js";
8
8
  import { NoteError } from "./errors.js";
9
9
  import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
10
10
  import { isOrigin, localIso, parseNote, serializeNote, stripLeadingFrontmatter } from "./frontmatter.js";
11
11
  import { namespaceSlugs, noteFileName, physicalPath, scopeDir, isSessionId, SLUG_PATTERN } from "./paths.js";
12
- import { projectReceipt } from "./project-home.js";
12
+ import { projectReceipt } from "./project-namespace.js";
13
13
  // Recency sorts tie-break by address, so two writes sharing one Date.now() tick would silently invert the recent-first contract. Write stamps are strictly increasing per process.
14
14
  let lastWriteStamp = 0;
15
15
  function writeStamp() {
@@ -60,8 +60,8 @@ async function walkMarkdown(dir, base = dir) {
60
60
  entries = await readdir(dir, { withFileTypes: true });
61
61
  }
62
62
  catch (error) {
63
- // A home that has never been created is normal. Other failures must reach the
64
- // boot snapshot boundary instead of masquerading as an empty home.
63
+ // A notebook that has never been created is normal. Other failures must reach the
64
+ // boot snapshot boundary instead of masquerading as an empty notebook.
65
65
  if (errno(error) === "ENOENT")
66
66
  return [];
67
67
  throw error;
@@ -76,27 +76,27 @@ async function walkMarkdown(dir, base = dir) {
76
76
  }
77
77
  return paths;
78
78
  }
79
- async function homesForPattern(pattern, identity, status) {
79
+ async function namespacesForPattern(pattern, identity, status) {
80
80
  if (pattern === undefined)
81
81
  return SCOPE_ORDER.map((scope) => ({ scope }));
82
82
  const families = [
83
- { scope: "session", home: "sessions", current: identity.sessionId },
84
- { scope: "project", home: "project", current: identity.projectKey },
85
- { scope: "agent", home: "agents", current: identity.agent },
86
- { scope: "model", home: "models", current: identity.model },
83
+ { scope: "session", dir: "sessions", current: identity.sessionId },
84
+ { scope: "project", dir: "project", current: identity.projectKey },
85
+ { scope: "agent", dir: "agents", current: identity.agent },
86
+ { scope: "model", dir: "models", current: identity.model },
87
87
  ];
88
88
  async function enumerate(family, relative) {
89
89
  let names;
90
90
  try {
91
- names = await namespaceSlugs(family.home, identity.home);
91
+ names = await namespaceSlugs(family.dir, identity.home);
92
92
  }
93
93
  catch (error) {
94
94
  if (!status || !isFilesystemError(error))
95
95
  throw error;
96
- status.homesUnavailable.push(`@${family.home === "project" ? "projects" : family.home}`);
96
+ status.namespacesUnavailable.push(`@${family.dir === "project" ? "projects" : family.dir}`);
97
97
  return [];
98
98
  }
99
- // Include the current home even when missing or a non-directory, and only once.
99
+ // Include the current namespace even when missing or a non-directory, and only once.
100
100
  return [...new Set([family.current, ...names])].map((who) => ({
101
101
  scope: family.scope,
102
102
  who: relative && who === family.current ? undefined : who,
@@ -105,26 +105,26 @@ async function homesForPattern(pattern, identity, status) {
105
105
  if (pattern.startsWith("@")) {
106
106
  const [rawHead, ...tail] = pattern.slice(1).split("/");
107
107
  if (!/[*?]/.test(rawHead)) {
108
- const head = HOME_HEADS.get(rawHead);
108
+ const head = NAMESPACE_HEADS.get(rawHead);
109
109
  if (head === undefined || tail.length === 0)
110
110
  return [];
111
- if (head.home === undefined)
111
+ if (head.dir === undefined)
112
112
  return [{ scope: head.scope }];
113
113
  const name = tail[0];
114
114
  if (name && !/[*?]/.test(name))
115
115
  return [{ scope: head.scope, who: assertWho(name, head.scope) }];
116
- return enumerate(families.find((family) => family.home === head.home), false);
116
+ return enumerate(families.find((family) => family.dir === head.dir), false);
117
117
  }
118
118
  }
119
119
  // Unreserved patterns see the full universe, not just the current identities.
120
- const homes = [];
120
+ const namespaces = [];
121
121
  for (const scope of SCOPE_ORDER) {
122
122
  if (scope === "human")
123
- homes.push({ scope });
123
+ namespaces.push({ scope });
124
124
  else
125
- homes.push(...await enumerate(families.find((family) => family.scope === scope), true));
125
+ namespaces.push(...await enumerate(families.find((family) => family.scope === scope), true));
126
126
  }
127
- return homes;
127
+ return namespaces;
128
128
  }
129
129
  /** Relative pattern heads resolve to canonical names, so they match canonical addresses. */
130
130
  function normalizePattern(pattern, identity) {
@@ -218,11 +218,11 @@ function assertSerializedSize(content) {
218
218
  function frontmatterOf(meta) {
219
219
  return serializeNote(meta, "").slice(0, -2);
220
220
  }
221
- /** Explicit session/project homes are read-only unless dreamed over; agent/model homes allow their owner. */
222
- function assertWritableHome(scope, who, identity) {
221
+ /** Explicit session/project namespaces are read-only unless dreamed over; agent/model namespaces allow their owner. */
222
+ function assertWritableNamespace(scope, who, identity) {
223
223
  if (who === undefined)
224
224
  return;
225
- // A dreamed project is writable whole; its other sessions are checked per note by assertDreamSessionNote.
225
+ // A dreamed project is writable whole; project and session ownership is checked per note by assertDreamNote.
226
226
  if (identity.dreaming !== undefined && (scope === "session" || (scope === "project" && who === identity.dreaming)))
227
227
  return;
228
228
  if (scope === "session")
@@ -232,16 +232,19 @@ function assertWritableHome(scope, who, identity) {
232
232
  const current = scope === "agent" ? identity.agent : identity.model;
233
233
  if (who === current)
234
234
  return;
235
- const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
236
- throw new NoteError("invalid_scope", `${home} is someone else's home; you can write to this session, @project/, @human/, @self/, or @model/.`);
235
+ const address = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
236
+ throw new NoteError("invalid_scope", `${address} is someone else's notebook; you can write to this session, @project/, @human/, @self/, or @model/.`);
237
237
  }
238
- /** A dream reaches another session's note only when that note was born in the dreamed project. */
239
- function assertDreamSessionNote(scope, who, identity, raw, address) {
240
- if (scope !== "session" || who === undefined || identity.dreaming === undefined)
238
+ /** Resolve aliases before checking that a dreamed note belongs to the open project. */
239
+ function assertDreamNote(scope, who, identity, raw, address) {
240
+ if (identity.dreaming === undefined || (scope !== "session" && scope !== "project"))
241
241
  return;
242
- if (raw !== undefined && parseNote(raw).meta.project === identity.dreaming)
242
+ const project = scope === "project" ? who ?? identity.projectKey
243
+ : raw !== undefined ? parseNote(raw).meta.project
244
+ : who === undefined ? identity.projectKey : undefined;
245
+ if (project === identity.dreaming)
243
246
  return;
244
- throw new NoteError("invalid_scope", raw === undefined
247
+ throw new NoteError("invalid_scope", raw === undefined && scope === "session" && who !== undefined
245
248
  ? `${address}: a dream edits other sessions' existing notes, it doesn't create new ones there.`
246
249
  : `${address} belongs to another project, not the one being dreamed over (${identity.dreaming}).`);
247
250
  }
@@ -253,7 +256,7 @@ export function createNotesStore(input) {
253
256
  const destination = assertAddress(address);
254
257
  assertWritablePath(destination.path);
255
258
  const scope = destination.scope;
256
- assertWritableHome(scope, destination.who, identity);
259
+ assertWritableNamespace(scope, destination.who, identity);
257
260
  // Absent means "keep whatever the note already says": replacing a note must not silently
258
261
  // re-attribute a user-written note to the agent that happened to rewrite it.
259
262
  const origin = stableOptions.origin === undefined ? undefined : assertOrigin(stableOptions.origin);
@@ -262,7 +265,7 @@ export function createNotesStore(input) {
262
265
  const now = writeStamp();
263
266
  const cleanBody = stripLeadingFrontmatter(content);
264
267
  const existingRaw = await readFileIfExists(path);
265
- assertDreamSessionNote(scope, destination.who, identity, existingRaw, address);
268
+ assertDreamNote(scope, destination.who, identity, existingRaw, address);
266
269
  const existing = existingRaw === undefined ? undefined : parseNote(existingRaw, now).meta;
267
270
  const outcome = existing === undefined ? "created" : existing.crumpledAt === undefined ? "overwrote" : "uncrumpled";
268
271
  const meta = existing ?? {
@@ -295,7 +298,7 @@ export function createNotesStore(input) {
295
298
  return undefined;
296
299
  const now = Date.now();
297
300
  const parsed = parseNote(raw, now);
298
- // Named homes, and every read during a dream, leave no access stamp.
301
+ // Named notebooks, and every read during a dream, leave no access stamp.
299
302
  if (identity.dreaming !== undefined || ((scope === "project" || scope === "session") && destination.who !== undefined))
300
303
  return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope, accessedBefore: parsed.meta.lastAccessed };
301
304
  // A read records its own access, exactly as a write records an edit.
@@ -311,8 +314,8 @@ export function createNotesStore(input) {
311
314
  const destination = stableOptions.renameTo === undefined ? from : assertAddress(stableOptions.renameTo);
312
315
  assertWritablePath(destination.path);
313
316
  const scope = destination.scope;
314
- assertWritableHome(from.scope, from.who, identity);
315
- assertWritableHome(scope, destination.who, identity);
317
+ assertWritableNamespace(from.scope, from.who, identity);
318
+ assertWritableNamespace(scope, destination.who, identity);
316
319
  if (operations.length === 0 && stableOptions.origin === undefined && stableOptions.crumpled === undefined && stableOptions.renameTo === undefined) {
317
320
  throw new NoteError("nothing_to_do", "Nothing to change: provide edits, an origin, a crumpled state, or a new address.");
318
321
  }
@@ -324,9 +327,9 @@ export function createNotesStore(input) {
324
327
  if (raw === undefined)
325
328
  throw new NoteError("not_found", `No note at ${noteIdentity(identity, address).address}.`);
326
329
  const targetRaw = differentPaths ? await readFileIfExists(path) : undefined;
327
- assertDreamSessionNote(from.scope, from.who, identity, raw, address);
330
+ assertDreamNote(from.scope, from.who, identity, raw, address);
328
331
  if (differentPaths)
329
- assertDreamSessionNote(scope, destination.who, identity, targetRaw, stableOptions.renameTo);
332
+ assertDreamNote(scope, destination.who, identity, targetRaw, stableOptions.renameTo);
330
333
  // Case and symlink aliases must not turn write-then-remove into deleting the result.
331
334
  const sourceReal = targetRaw === undefined ? undefined : await realpath(fromPath);
332
335
  const sameFile = sourceReal !== undefined && sourceReal === await realpath(path);
@@ -410,13 +413,13 @@ export function createNotesStore(input) {
410
413
  if (identity.dreaming === undefined)
411
414
  throw new NoteError("invalid_scope", "Only a dream can delete notes; begin one first.");
412
415
  const target = assertAddress(address);
413
- assertWritableHome(target.scope, target.who, identity);
416
+ assertWritableNamespace(target.scope, target.who, identity);
414
417
  const path = physicalPath(target.scope, target.path, identity, target.who);
415
418
  return withPathQueue(path, async () => {
416
419
  const raw = await readFileIfExists(path);
417
420
  if (raw === undefined)
418
421
  throw new NoteError("not_found", `No note at ${noteIdentity(identity, address).address}.`);
419
- assertDreamSessionNote(target.scope, target.who, identity, raw, address);
422
+ assertDreamNote(target.scope, target.who, identity, raw, address);
420
423
  const { meta } = parseNote(raw);
421
424
  if (meta.crumpledAt === undefined)
422
425
  throw new NoteError("not_crumpled", `${noteIdentity(identity, address).address} isn't crumpled; crumple it before deleting.`);
@@ -429,10 +432,10 @@ export function createNotesStore(input) {
429
432
  const pattern = glob === "@default" ? undefined : glob;
430
433
  const normalized = normalizePattern(pattern, identity);
431
434
  const matcher = normalized === undefined ? undefined : globToRegExp(normalized);
432
- const homes = await homesForPattern(pattern, identity, status);
433
- for (const home of homes) {
434
- const scope = home.scope;
435
- const root = scopeDir(scope, identity, home.who);
435
+ const namespaces = await namespacesForPattern(pattern, identity, status);
436
+ for (const namespace of namespaces) {
437
+ const scope = namespace.scope;
438
+ const root = scopeDir(scope, identity, namespace.who);
436
439
  let paths;
437
440
  try {
438
441
  paths = await walkMarkdown(root);
@@ -440,24 +443,24 @@ export function createNotesStore(input) {
440
443
  catch (error) {
441
444
  if (!status || !isFilesystemError(error))
442
445
  throw error;
443
- status.homesUnavailable.push(addressFor(identity, scope, "", home.who).replace(/\/$/, "") || "session");
446
+ status.namespacesUnavailable.push(addressFor(identity, scope, "", namespace.who).replace(/\/$/, "") || "session");
444
447
  continue;
445
448
  }
446
449
  for (const path of paths) {
447
- if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who))
448
- && !(scope === "session" && home.who === undefined && !pattern.startsWith("@") && matcher.test(path)))
450
+ if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, namespace.who))
451
+ && !(scope === "session" && namespace.who === undefined && !pattern.startsWith("@") && matcher.test(path)))
449
452
  continue;
450
- const address = addressFor(identity, scope, path, home.who);
453
+ const address = addressFor(identity, scope, path, namespace.who);
451
454
  const fullPath = join(root, path);
452
455
  let raw;
453
456
  try {
454
457
  raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
455
458
  }
456
459
  catch (error) {
457
- // One unreadable note is named on its own; its home's readable notes still list.
460
+ // One unreadable note is named on its own; its notebook's readable notes still list.
458
461
  if (!status || !isFilesystemError(error))
459
462
  throw error;
460
- status.homesUnavailable.push(address);
463
+ status.namespacesUnavailable.push(address);
461
464
  continue;
462
465
  }
463
466
  const { meta, body } = parseNote(raw);
@@ -478,10 +481,10 @@ export function createNotesStore(input) {
478
481
  rows.push({ ...row, sizeBytes: Buffer.byteLength(row.body, "utf8") });
479
482
  }
480
483
  rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
481
- return { rows, status: status ?? { homesUnavailable: [] } };
484
+ return { rows, status: status ?? { namespacesUnavailable: [] } };
482
485
  }
483
486
  function listWithStatus(options = {}) {
484
- return listRows(options, { homesUnavailable: [] });
487
+ return listRows(options, { namespacesUnavailable: [] });
485
488
  }
486
489
  async function search(queries, options = {}) {
487
490
  return (await searchRows(queries, options)).rows;
@@ -511,10 +514,10 @@ export function createNotesStore(input) {
511
514
  rows.push({ address, path, scope, meta, matches });
512
515
  }
513
516
  rows.sort((a, b) => a.address.localeCompare(b.address));
514
- return { rows, status: status ?? { homesUnavailable: [] } };
517
+ return { rows, status: status ?? { namespacesUnavailable: [] } };
515
518
  }
516
519
  function searchWithStatus(queries, options = {}) {
517
- return searchRows(queries, options, { homesUnavailable: [] });
520
+ return searchRows(queries, options, { namespacesUnavailable: [] });
518
521
  }
519
522
  return { write, read, update, rename, forget, list, search, listWithStatus, searchWithStatus };
520
523
  }
@@ -4,9 +4,16 @@ import { type NotesIdentity } from "../notes/index.js";
4
4
  import { type DreamLock } from "../dream/lock.js";
5
5
  import { type Outcome } from "./result.js";
6
6
  /** The one open dream per session; the host owns where it lives. */
7
+ type DreamOpening = {
8
+ project: string;
9
+ lock: DreamLock;
10
+ generation: number;
11
+ };
7
12
  export type DreamState = {
8
13
  project?: string;
9
14
  lock?: DreamLock;
15
+ pending?: DreamOpening;
16
+ generation?: number;
10
17
  };
11
18
  /** Drop an open dream without an end commit, e.g. when its session shuts down. */
12
19
  export declare function abandonDream(state: DreamState): void;
@@ -17,7 +24,7 @@ export declare const dreamBeginParameters: Type.TObject<{
17
24
  }>;
18
25
  export declare const DreamBeginDataSchema: Type.TObject<{
19
26
  more: Type.TInteger;
20
- homes_unavailable: Type.TArray<Type.TString>;
27
+ namespaces_unavailable: Type.TArray<Type.TString>;
21
28
  files: Type.TArray<Type.TObject<{
22
29
  updated_at: Type.TString;
23
30
  last_accessed: Type.TString;
@@ -37,13 +44,13 @@ export type DreamBeginData = Static<typeof DreamBeginDataSchema>;
37
44
  export declare const dreamBegin: {
38
45
  readonly name: "dream_begin";
39
46
  readonly label: "Dream begin";
40
- readonly description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp. Takes the project's dream lock and commits a Git baseline of the notes home.";
47
+ readonly description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp. Holds the notes home's dream lock through dream_end so Git audits cannot interleave, and commits a baseline of the notes home.";
41
48
  readonly parameters: Type.TObject<{
42
49
  project: Type.TOptional<Type.TString>;
43
50
  }>;
44
51
  readonly outputSchema: Type.TUnion<[Type.TObject<{
45
52
  more: Type.TInteger;
46
- homes_unavailable: Type.TArray<Type.TString>;
53
+ namespaces_unavailable: Type.TArray<Type.TString>;
47
54
  files: Type.TArray<Type.TObject<{
48
55
  updated_at: Type.TString;
49
56
  last_accessed: Type.TString;
@@ -69,6 +76,11 @@ export declare const dreamForgetParameters: Type.TObject<{
69
76
  address: Type.TString;
70
77
  }>;
71
78
  export declare const DreamForgetDataSchema: Type.TObject<{
79
+ project_root: Type.TOptional<Type.TString>;
80
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
81
+ name: Type.TString;
82
+ path: Type.TString;
83
+ }>>>;
72
84
  address: Type.TString;
73
85
  project_key: Type.TOptional<Type.TString>;
74
86
  }>;
@@ -81,6 +93,11 @@ export declare const dreamForget: {
81
93
  address: Type.TString;
82
94
  }>;
83
95
  readonly outputSchema: Type.TUnion<[Type.TObject<{
96
+ project_root: Type.TOptional<Type.TString>;
97
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
98
+ name: Type.TString;
99
+ path: Type.TString;
100
+ }>>>;
84
101
  address: Type.TString;
85
102
  project_key: Type.TOptional<Type.TString>;
86
103
  }>, Type.TObject<{
@@ -113,3 +130,4 @@ export declare const dreamEnd: {
113
130
  readonly execute: (_params: Static<typeof dreamEndParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamEndData>>;
114
131
  readonly render: (result: Outcome<DreamEndData>) => string;
115
132
  };
133
+ export {};