notesoup 0.43.0 → 0.45.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 (76) hide show
  1. package/README.md +1 -0
  2. package/cordis.patch.yml +14 -0
  3. package/dist/src/boot/snapshot.d.ts +2 -0
  4. package/dist/src/boot/snapshot.js +4 -0
  5. package/dist/src/boot/text.js +3 -1
  6. package/dist/src/claude/helper.js +2 -2
  7. package/dist/src/dsh/budget.d.ts +20 -0
  8. package/dist/src/dsh/budget.js +34 -0
  9. package/dist/src/dsh/engine.d.ts +22 -0
  10. package/dist/src/dsh/engine.js +193 -0
  11. package/dist/src/dsh/history.d.ts +6 -0
  12. package/dist/src/dsh/history.js +73 -0
  13. package/dist/src/dsh/index.d.ts +22 -0
  14. package/dist/src/dsh/index.js +63 -0
  15. package/dist/src/dsh/preflight.d.ts +8 -0
  16. package/dist/src/dsh/preflight.js +35 -0
  17. package/dist/src/dsh/tools.d.ts +3 -0
  18. package/dist/src/dsh/tools.js +111 -0
  19. package/dist/src/dsh/window.d.ts +46 -0
  20. package/dist/src/dsh/window.js +124 -0
  21. package/dist/src/notes/address.d.ts +2 -2
  22. package/dist/src/notes/address.js +5 -5
  23. package/dist/src/notes/identity.js +2 -1
  24. package/dist/src/notes/paths.d.ts +1 -6
  25. package/dist/src/notes/paths.js +5 -68
  26. package/dist/src/notes/project-home.d.ts +25 -0
  27. package/dist/src/notes/project-home.js +231 -0
  28. package/dist/src/notes/store.d.ts +3 -2
  29. package/dist/src/notes/store.js +14 -8
  30. package/dist/src/pi/boot.js +17 -5
  31. package/dist/src/pi/notes/adapter.js +1 -1
  32. package/dist/src/tools/notes.d.ts +47 -17
  33. package/dist/src/tools/notes.js +15 -4
  34. package/dist/test/claude-mod.test.js +32 -1
  35. package/dist/test/dependencies.test.js +27 -1
  36. package/dist/test/dsh-cli.test.d.ts +1 -0
  37. package/dist/test/dsh-cli.test.js +44 -0
  38. package/dist/test/dsh-compaction-parity.test.d.ts +1 -0
  39. package/dist/test/dsh-compaction-parity.test.js +143 -0
  40. package/dist/test/dsh.test.d.ts +1 -0
  41. package/dist/test/dsh.test.js +323 -0
  42. package/dist/test/helpers/dependency-graph.js +3 -3
  43. package/dist/test/helpers/dsh-messages.d.ts +29 -0
  44. package/dist/test/helpers/dsh-messages.js +33 -0
  45. package/dist/test/helpers/dsh.d.ts +17 -0
  46. package/dist/test/helpers/dsh.js +50 -0
  47. package/dist/test/notes.test.js +22 -19
  48. package/dist/test/project-home.test.d.ts +1 -0
  49. package/dist/test/project-home.test.js +134 -0
  50. package/docs/architecture.md +4 -1
  51. package/docs/dsh.md +61 -0
  52. package/docs/dsh.profile.patch.yml +34 -0
  53. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  54. package/mods/notesoup/dist/claude/helper.js +223 -56
  55. package/mods/notesoup/skills/memory/SKILL.md +1 -0
  56. package/package.json +63 -4
  57. package/skills/memory/SKILL.md +1 -0
  58. package/src/boot/snapshot.ts +5 -0
  59. package/src/boot/text.ts +3 -1
  60. package/src/claude/helper.ts +2 -2
  61. package/src/dsh/budget.ts +35 -0
  62. package/src/dsh/engine.ts +160 -0
  63. package/src/dsh/history.ts +57 -0
  64. package/src/dsh/index.ts +69 -0
  65. package/src/dsh/preflight.ts +29 -0
  66. package/src/dsh/tools.ts +107 -0
  67. package/src/dsh/window.ts +126 -0
  68. package/src/notes/address.ts +5 -5
  69. package/src/notes/identity.ts +1 -1
  70. package/src/notes/paths.ts +4 -60
  71. package/src/notes/project-home.ts +197 -0
  72. package/src/notes/store.ts +13 -9
  73. package/src/pi/boot.ts +15 -5
  74. package/src/pi/notes/adapter.ts +1 -1
  75. package/src/tools/notes.ts +16 -6
  76. package/mods/pi-context/dist/claude/helper.js +0 -9324
@@ -1,7 +1,6 @@
1
- import { createHash } from "node:crypto";
2
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
3
1
  import { readdir } from "node:fs/promises";
4
- import { basename, dirname, join, resolve, sep } from "node:path";
2
+ import { join } from "node:path";
3
+ export { projectKey } from "./project-home.js";
5
4
  import { NoteError, shown } from "./errors.js";
6
5
  import type { NotesIdentity } from "./identity.js";
7
6
 
@@ -29,61 +28,6 @@ export function assertVirtualPath(value: unknown): string {
29
28
  return value;
30
29
  }
31
30
 
32
- /**
33
- * `<basename(canonical git root)-sha1(canonical git root)[:8]>`, or the same formula over cwd
34
- * with no git root. Git writes the canonical spelling into a linked worktree's `.git` pointer,
35
- * so canonicalizing here is what keeps one repository — and its worktrees — on one home.
36
- */
37
- export function projectKey(cwd: string): string {
38
- const absolute = resolve(cwd);
39
- const spelled = gitRoot(absolute) ?? absolute;
40
- let root = spelled;
41
- try { root = realpathSync(spelled); } catch { /* An unresolvable path keeps its spelling. */ }
42
- const digest = createHash("sha1").update(root).digest("hex").slice(0, 8);
43
- return `${basename(root)}-${digest}`;
44
- }
45
-
46
- /**
47
- * Repository root behind one `.git` entry. A `.git` directory is the main checkout
48
- * itself. A `.git` file is a worktree or submodule pointer: a linked worktree names
49
- * `<main>/.git/worktrees/<name>` and resolves to `<main>`, so every worktree of one
50
- * repository shares one project identity. Submodules, bare repositories, and separate
51
- * git dirs keep the current directory.
52
- */
53
- function repositoryRoot(dir: string): string {
54
- let stats;
55
- try {
56
- stats = statSync(join(dir, ".git"));
57
- } catch {
58
- return dir;
59
- }
60
- if (stats.isDirectory()) return dir;
61
- let pointer: string;
62
- try {
63
- pointer = readFileSync(join(dir, ".git"), "utf8");
64
- } catch {
65
- return dir;
66
- }
67
- const match = /^gitdir:\s*(.+)$/m.exec(pointer);
68
- if (!match) return dir;
69
- const parts = resolve(dir, match[1]!.trim()).split(sep);
70
- const worktrees = parts.lastIndexOf("worktrees");
71
- if (worktrees <= 0 || worktrees !== parts.length - 2) return dir;
72
- const common = parts.slice(0, worktrees).join(sep);
73
- return basename(common) === ".git" ? dirname(common) : dir;
74
- }
75
-
76
- /** Absolute repository root for cwd, walking upward until a directory holds a `.git` entry. */
77
- function gitRoot(cwd: string): string | undefined {
78
- let dir = resolve(cwd);
79
- for (;;) {
80
- if (existsSync(join(dir, ".git"))) return repositoryRoot(dir);
81
- const parent = dirname(dir);
82
- if (parent === dir) return undefined;
83
- dir = parent;
84
- }
85
- }
86
-
87
31
  /** Absolute directory holding the per-session note homes. */
88
32
  export function sessionHomesRoot(home: string): string {
89
33
  return join(home, "pi", "session");
@@ -92,9 +36,9 @@ export function sessionHomesRoot(home: string): string {
92
36
  /** Absolute directory holding one scope's notes. The identity's home is already resolved. */
93
37
  export function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): string {
94
38
  if (!["session", "project", "human", "agent", "model"].includes(scope)) throw new TypeError("invalid notes scope");
95
- if (who !== undefined && (scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical agent/model slug");
39
+ if (who !== undefined && (scope !== "project" && scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical project/agent/model slug");
96
40
  if (scope === "human") return join(identity.home, "human");
97
- if (scope === "project") return join(identity.home, "project", identity.projectKey);
41
+ if (scope === "project") return join(identity.home, "project", who ?? identity.projectKey);
98
42
  if (scope === "agent") return join(identity.home, "agents", who ?? identity.agent);
99
43
  if (scope === "model") return join(identity.home, "models", who ?? identity.model);
100
44
  return join(sessionHomesRoot(identity.home), identity.sessionId);
@@ -0,0 +1,197 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, join, resolve, sep } from "node:path";
4
+ import { slugify } from "./paths.js";
5
+
6
+ export type ProjectMarker = { id: string; path: string };
7
+ export type ProjectHome = ProjectMarker & { name: string; dir: string };
8
+
9
+ function errno(error: unknown): string | undefined {
10
+ return typeof error === "object" && error !== null ? (error as NodeJS.ErrnoException).code : undefined;
11
+ }
12
+
13
+ /** Normalize the small set of Git remote spellings used by ordinary repositories. */
14
+ export function normalizeRemote(value: string): string {
15
+ let text = value.trim();
16
+ const scp = /^(?:[^/@]+)@([^:/]+):(.+)$/.exec(text);
17
+ if (scp) text = `${scp[1]!.toLowerCase()}/${scp[2]}`;
18
+ else if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(text)) {
19
+ try {
20
+ const url = new URL(text);
21
+ const host = url.hostname.toLowerCase();
22
+ const port = url.port.length > 0 ? `:${url.port}` : "";
23
+ text = `${host}${port}${url.pathname}`;
24
+ } catch {
25
+ text = text.replace(/^[A-Za-z][A-Za-z0-9+.-]*:\/\//, "").replace(/^[^/@]+@/, "");
26
+ }
27
+ } else {
28
+ text = text.replace(/^[^/@]+@/, "");
29
+ const slash = text.indexOf("/");
30
+ if (slash > 0) text = `${text.slice(0, slash).toLowerCase()}${text.slice(slash)}`;
31
+ }
32
+ text = text.replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
33
+ return text;
34
+ }
35
+
36
+ function canonicalRoot(cwd: string): string {
37
+ const absolute = resolve(cwd);
38
+ const spelled = gitRoot(absolute) ?? absolute;
39
+ try { return realpathSync(spelled); } catch { return spelled; }
40
+ }
41
+
42
+ function originRemote(root: string): string | undefined {
43
+ let gitDir = join(root, ".git");
44
+ let raw: string;
45
+ try {
46
+ if (!statSync(gitDir).isDirectory()) {
47
+ const pointer = /^gitdir:\s*(.+)$/m.exec(readFileSync(gitDir, "utf8"));
48
+ if (!pointer) return undefined;
49
+ gitDir = resolve(root, pointer[1]!.trim());
50
+ }
51
+ try { gitDir = resolve(gitDir, readFileSync(join(gitDir, "commondir"), "utf8").trim()); } catch (error) {
52
+ if (errno(error) !== "ENOENT") throw error;
53
+ }
54
+ raw = readFileSync(join(gitDir, "config"), "utf8");
55
+ } catch (error) {
56
+ if (errno(error) === "ENOENT") return undefined;
57
+ throw error;
58
+ }
59
+ let origin = false;
60
+ for (const line of raw.split(/\r?\n/)) {
61
+ const section = /^\s*\[remote\s+"([^"]+)"\]\s*$/.exec(line);
62
+ if (section) {
63
+ origin = section[1] === "origin";
64
+ continue;
65
+ }
66
+ if (/^\s*\[/.test(line)) origin = false;
67
+ if (origin) {
68
+ const url = /^\s*url\s*=\s*(.*?)\s*$/.exec(line);
69
+ if (url) return normalizeRemote(url[1]!.replace(/^"(.*)"$/, "$1")) || undefined;
70
+ }
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ function readMarker(dir: string): ProjectHome | undefined {
76
+ let raw: string;
77
+ try { raw = readFileSync(join(dir, ".project"), "utf8"); } catch (error) {
78
+ if (errno(error) === "ENOENT") return undefined;
79
+ throw error;
80
+ }
81
+ try {
82
+ const value = JSON.parse(raw) as Partial<ProjectMarker>;
83
+ if (typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0) return undefined;
84
+ return { name: basename(dir), dir, id: value.id, path: value.path };
85
+ } catch {
86
+ return undefined;
87
+ }
88
+ }
89
+
90
+ function projectRoot(home: string): string {
91
+ return join(home, "project");
92
+ }
93
+
94
+ /** Read marked project homes. Unmarked legacy directories are deliberately omitted. */
95
+ export function projectHomes(home: string): ProjectHome[] {
96
+ const root = projectRoot(home);
97
+ let entries;
98
+ try { entries = readdirSync(root, { withFileTypes: true }); } catch (error) {
99
+ if (errno(error) === "ENOENT") return [];
100
+ throw error;
101
+ }
102
+ return entries.filter(entry => entry.isDirectory()).map(entry => readMarker(join(root, entry.name))).filter((entry): entry is ProjectHome => entry !== undefined).sort((a, b) => a.name.localeCompare(b.name));
103
+ }
104
+
105
+ function updateMarker(home: ProjectHome, marker: ProjectMarker): ProjectHome {
106
+ const markerPath = join(home.dir, ".project");
107
+ const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
108
+ try {
109
+ writeFileSync(temp, JSON.stringify(marker));
110
+ renameSync(temp, markerPath);
111
+ } catch (error) {
112
+ try { rmSync(temp, { force: true }); } catch { /* Preserve the marker update failure. */ }
113
+ throw error;
114
+ }
115
+ return { ...home, ...marker };
116
+ }
117
+
118
+ /** Resolve and claim the readable home for one repository identity. */
119
+ export function resolveProjectHome(cwd: string, home: string): ProjectHome {
120
+ const root = canonicalRoot(cwd);
121
+ const remote = originRemote(root);
122
+ const id = remote ?? root;
123
+ const markerRoot = projectRoot(home);
124
+ mkdirSync(markerRoot, { recursive: true });
125
+ const homes = projectHomes(home);
126
+ let found = homes.find(candidate => candidate.id === id);
127
+ if (!found && remote) {
128
+ found = homes.find(candidate => candidate.id === root);
129
+ if (found) found = updateMarker(found, { id: remote, path: root });
130
+ }
131
+ if (found) {
132
+ if (found.path !== root) found = updateMarker(found, { id: found.id, path: root });
133
+ return found;
134
+ }
135
+
136
+ const base = slugify(basename(root));
137
+ // Existing unmarked homes are taken; only directories appearing after this scan can be raced.
138
+ const taken = new Set(readdirSync(markerRoot));
139
+ for (let suffix = 0; ; suffix++) {
140
+ const name = suffix === 0 ? base : `${base}-${suffix}`;
141
+ if (taken.has(name)) continue;
142
+ const dir = join(markerRoot, name);
143
+ try {
144
+ mkdirSync(dir, { recursive: true });
145
+ writeFileSync(join(dir, ".project"), JSON.stringify({ id, path: root }), { flag: "wx" });
146
+ return { name, dir, id, path: root };
147
+ } catch (error) {
148
+ if (errno(error) === "EEXIST") continue;
149
+ throw error;
150
+ }
151
+ }
152
+ }
153
+
154
+ /** Existing root discovery, including linked worktrees, without invoking Git. */
155
+ function gitRoot(cwd: string): string | undefined {
156
+ let dir = resolve(cwd);
157
+ for (;;) {
158
+ if (existsSync(join(dir, ".git"))) return repositoryRoot(dir);
159
+ const parent = dirname(dir);
160
+ if (parent === dir) return undefined;
161
+ dir = parent;
162
+ }
163
+ }
164
+
165
+ function repositoryRoot(dir: string): string {
166
+ let stats;
167
+ try { stats = statSync(join(dir, ".git")); } catch { return dir; }
168
+ if (stats.isDirectory()) return dir;
169
+ let pointer: string;
170
+ try { pointer = readFileSync(join(dir, ".git"), "utf8"); } catch { return dir; }
171
+ const match = /^gitdir:\s*(.+)$/m.exec(pointer);
172
+ if (!match) return dir;
173
+ const parts = resolve(dir, match[1]!.trim()).split(sep);
174
+ const worktrees = parts.lastIndexOf("worktrees");
175
+ if (worktrees <= 0 || worktrees !== parts.length - 2) return dir;
176
+ const common = parts.slice(0, worktrees).join(sep);
177
+ return basename(common) === ".git" ? dirname(common) : dir;
178
+ }
179
+
180
+ export type ProjectReceipt = { project_root?: string; project_siblings?: Array<{ name: string; path: string }> };
181
+
182
+ /** Display-only context for an explicitly named project home. */
183
+ export function projectReceipt(home: string, name: string): ProjectReceipt {
184
+ const project = readMarker(join(projectRoot(home), name));
185
+ if (!project) return {};
186
+ const base = slugify(basename(project.path));
187
+ const siblings = projectHomes(home).filter(candidate => candidate.name !== name && slugify(basename(candidate.path)) === base);
188
+ return {
189
+ project_root: project.path,
190
+ ...(siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name, path }) => ({ name, path })) }),
191
+ };
192
+ }
193
+
194
+ /** Names a project home, claiming it when the notes home has not seen this identity. */
195
+ export function projectKey(cwd: string, home: string): string {
196
+ return resolveProjectHome(cwd, home).name;
197
+ }
@@ -10,6 +10,7 @@ import { NoteError } from "./errors.js";
10
10
  import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
11
11
  import { isOrigin, isScope, localIso, parseNote, serializeNote, stripLeadingFrontmatter, type NoteMeta, type Origin } from "./frontmatter.js";
12
12
  import { namespaceSlugs, noteFileName, physicalPath, scopeDir, SLUG_PATTERN, type Scope } from "./paths.js";
13
+ import { projectHomes, projectReceipt, type ProjectReceipt } from "./project-home.js";
13
14
 
14
15
  export type { NoteMeta, Origin, Scope };
15
16
 
@@ -44,12 +45,12 @@ export type NoteRenameResult = { meta: NoteMeta; replacedCrumpledTarget: boolean
44
45
  export type NoteQueryStatus = { homesUnavailable: string[] };
45
46
  export type NoteQueryResult<T> = { rows: T[]; status: NoteQueryStatus };
46
47
 
47
- /** Public identity resolved for an operation, never a filesystem path. */
48
- export function noteIdentity(identity: NotesIdentity, address: string): { address: string; project_key?: string } {
48
+ /** Public note identity; named projects also carry their display root and sibling hints. */
49
+ export function noteIdentity(identity: NotesIdentity, address: string): { address: string; project_key?: string } & ProjectReceipt {
49
50
  const resolved = assertAddress(address);
50
51
  return {
51
52
  address: addressFor(identity, resolved.scope, noteFileName(resolved.path), resolved.who),
52
- ...(resolved.scope === "project" ? { project_key: identity.projectKey } : {}),
53
+ ...(resolved.scope !== "project" ? {} : resolved.who === undefined ? { project_key: identity.projectKey } : projectReceipt(identity.home, resolved.who)),
53
54
  };
54
55
  }
55
56
 
@@ -125,11 +126,12 @@ async function homesForPattern(pattern: string | undefined, identity: NotesIdent
125
126
  if (head === "human") return [{ scope: "human" }];
126
127
  if (head === "self") return [{ scope: "agent" }];
127
128
  if (head === "model") return [{ scope: "model" }];
128
- if (head === "agents" || head === "models") {
129
- const scope: Scope = head === "agents" ? "agent" : "model";
129
+ if (head === "projects" || head === "agents" || head === "models") {
130
+ const scope: Scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
130
131
  const name = pattern.slice(head.length + 2).split("/")[0] ?? "";
131
132
  if (name.length > 0 && !/[*?]/.test(name)) return [{ scope, who: assertWho(name) }];
132
- return (await namespaceSlugs(head, identity.home)).map((who) => ({ scope, who }));
133
+ const names = head === "projects" ? projectHomes(identity.home).map(home => home.name) : await namespaceSlugs(head, identity.home);
134
+ return names.map((who) => ({ scope, who }));
133
135
  }
134
136
  return [];
135
137
  }
@@ -238,9 +240,10 @@ function frontmatterOf(meta: NoteMeta): string {
238
240
  return serializeNote(meta, "").slice(0, -2);
239
241
  }
240
242
 
241
- /** Named agent/model homes are read-only to whoever is not running there. */
243
+ /** Explicit project homes are always read-only; agent/model homes allow their owner. */
242
244
  function assertWritableHome(scope: Scope, who: string | undefined, identity: NotesIdentity): void {
243
245
  if (who === undefined) return;
246
+ if (scope === "project") throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
244
247
  const current = scope === "agent" ? identity.agent : identity.model;
245
248
  if (who === current) return;
246
249
  const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
@@ -296,6 +299,7 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
296
299
  if (raw === undefined) return undefined;
297
300
  const now = Date.now();
298
301
  const parsed = parseNote(raw, now);
302
+ if (scope === "project" && destination.who !== undefined) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
299
303
  // A read records its own access, exactly as a write records an edit.
300
304
  const meta: NoteMeta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
301
305
  await atomicWrite(path, serializeNote(meta, parsed.body));
@@ -407,8 +411,8 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
407
411
  try {
408
412
  homes = await homesFor(identity, options);
409
413
  } catch (error) {
410
- if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? "")) throw error;
411
- status.homesUnavailable.push(options.glob!.startsWith("@agents/") ? "@agents" : "@models");
414
+ if (!status || !isFilesystemError(error) || !/^@(projects|agents|models)\//.test(options.glob ?? "")) throw error;
415
+ status.homesUnavailable.push(options.glob!.split("/")[0]!);
412
416
  return;
413
417
  }
414
418
  for (const home of homes) {
package/src/pi/boot.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { PI_TOOL_NAMES } from "./tool-names.js";
2
2
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
3
- import { notesIdentityFromPi } from "./notes/adapter.js";
4
- import { loadNotesSnapshot, type NotesSnapshot } from "../boot/snapshot.js";
3
+ import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
4
+ import { loadNotesSnapshot, unavailableNotesSnapshot, type NotesSnapshot } from "../boot/snapshot.js";
5
+ import { isFilesystemError } from "../notes/fs-error.js";
5
6
  import { BOOT_TYPE } from "./entries.js";
6
7
  import { renderBootBlock } from "../boot/render.js";
7
8
  import { currentReset, currentWindowId, isWindowBoot, rootWindowId } from "./window.js";
@@ -28,12 +29,21 @@ export async function buildBootMessage(
28
29
  notifyIncompleteNotes?: IncompleteNotesNotifier,
29
30
  isCurrent: () => boolean = () => true,
30
31
  ): Promise<BootMessage> {
31
- const identity = notesIdentityFromPi(ctx);
32
- const notes = await loadNotesSnapshot(identity, Date.now());
32
+ const agentName = agentSlug();
33
+ const modelName = modelSlug(ctx);
34
+ const sessionId = ctx.sessionManager.getSessionId();
35
+ const openedAt = Date.now();
36
+ let notes: NotesSnapshot;
37
+ try {
38
+ notes = await loadNotesSnapshot(notesIdentityFromPi(ctx), openedAt);
39
+ } catch (error) {
40
+ if (!isFilesystemError(error)) throw error;
41
+ notes = unavailableNotesSnapshot(openedAt);
42
+ }
33
43
  if (isCurrent()) notifyIncompleteNotes?.(ctx, windowId, notes);
34
44
  return {
35
45
  customType: BOOT_TYPE,
36
- content: renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId: rootWindowId(identity.sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
46
+ content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
37
47
  display: false,
38
48
  details: { windowId },
39
49
  };
@@ -26,7 +26,7 @@ export function notesIdentityFromPi(ctx: ExtensionContext, home = notesRoot()):
26
26
  return {
27
27
  home,
28
28
  sessionId: ctx.sessionManager.getSessionId(),
29
- projectKey: projectKey(ctx.cwd),
29
+ projectKey: projectKey(ctx.cwd, home),
30
30
  agent: agentSlug(),
31
31
  model: modelSlug(ctx),
32
32
  };
@@ -15,7 +15,7 @@ const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional)
15
15
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
16
16
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
17
17
  const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
18
- const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
18
+ const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
19
19
 
20
20
  /**
21
21
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
@@ -91,14 +91,23 @@ function renderMetadata(metadata: NoteMetadata): string {
91
91
  return fields.join(" | ");
92
92
  }
93
93
 
94
- /** Address plus project key in one line; the project key never replaces the address. */
95
- function renderIdentity(identity: { address: string; project_key?: string }): string {
96
- return identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
94
+ /** Keep the address visible, with project context and at most one sibling hint line. */
95
+ function renderIdentity(identity: { address: string; project_key?: string; project_root?: string; project_siblings?: Array<{ name: string; path: string }> }): string {
96
+ let text = identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
97
+ if (identity.project_root !== undefined) text += ` (project_root ${identity.project_root})`;
98
+ if (identity.project_siblings !== undefined) text += `\n Same-basename projects: ${identity.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
99
+ return text;
97
100
  }
98
101
 
102
+ const ProjectReceiptSchema = {
103
+ project_root: Type.Optional(Type.String()),
104
+ project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
105
+ };
106
+
99
107
  const ListedFileSchema = Type.Object({
100
108
  address: Type.String(),
101
109
  project_key: Type.Optional(Type.String()),
110
+ ...ProjectReceiptSchema,
102
111
  updated_at: Type.String(),
103
112
  crumpled_at: Type.Optional(Type.String()),
104
113
  }, { additionalProperties: false });
@@ -138,6 +147,7 @@ export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
138
147
  export const NotesReadDataSchema = Type.Object({
139
148
  address: Type.String(),
140
149
  project_key: Type.Optional(Type.String()),
150
+ ...ProjectReceiptSchema,
141
151
  metadata: NoteMetadataSchema,
142
152
  ...TextWindowSchema.properties,
143
153
  }, { additionalProperties: false });
@@ -185,8 +195,8 @@ function snapshot<T extends { address: string }>(
185
195
  return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
186
196
  }
187
197
 
188
- function listedFile(row: Pick<NoteRow, "address" | "scope" | "meta">, identity: NotesIdentity): NotesListData["files"][number] {
189
- return { address: row.address, ...(row.scope === "project" ? { project_key: identity.projectKey } : {}), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
198
+ function listedFile(row: Pick<NoteRow, "address" | "meta">, identity: NotesIdentity): NotesListData["files"][number] {
199
+ return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
190
200
  }
191
201
 
192
202
  export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });