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
@@ -0,0 +1,231 @@
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
+ function errno(error) {
6
+ return typeof error === "object" && error !== null ? error.code : undefined;
7
+ }
8
+ /** Normalize the small set of Git remote spellings used by ordinary repositories. */
9
+ export function normalizeRemote(value) {
10
+ let text = value.trim();
11
+ const scp = /^(?:[^/@]+)@([^:/]+):(.+)$/.exec(text);
12
+ if (scp)
13
+ text = `${scp[1].toLowerCase()}/${scp[2]}`;
14
+ else if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(text)) {
15
+ try {
16
+ const url = new URL(text);
17
+ const host = url.hostname.toLowerCase();
18
+ const port = url.port.length > 0 ? `:${url.port}` : "";
19
+ text = `${host}${port}${url.pathname}`;
20
+ }
21
+ catch {
22
+ text = text.replace(/^[A-Za-z][A-Za-z0-9+.-]*:\/\//, "").replace(/^[^/@]+@/, "");
23
+ }
24
+ }
25
+ else {
26
+ text = text.replace(/^[^/@]+@/, "");
27
+ const slash = text.indexOf("/");
28
+ if (slash > 0)
29
+ text = `${text.slice(0, slash).toLowerCase()}${text.slice(slash)}`;
30
+ }
31
+ text = text.replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
32
+ return text;
33
+ }
34
+ function canonicalRoot(cwd) {
35
+ const absolute = resolve(cwd);
36
+ const spelled = gitRoot(absolute) ?? absolute;
37
+ try {
38
+ return realpathSync(spelled);
39
+ }
40
+ catch {
41
+ return spelled;
42
+ }
43
+ }
44
+ function originRemote(root) {
45
+ let gitDir = join(root, ".git");
46
+ let raw;
47
+ try {
48
+ if (!statSync(gitDir).isDirectory()) {
49
+ const pointer = /^gitdir:\s*(.+)$/m.exec(readFileSync(gitDir, "utf8"));
50
+ if (!pointer)
51
+ return undefined;
52
+ gitDir = resolve(root, pointer[1].trim());
53
+ }
54
+ try {
55
+ gitDir = resolve(gitDir, readFileSync(join(gitDir, "commondir"), "utf8").trim());
56
+ }
57
+ catch (error) {
58
+ if (errno(error) !== "ENOENT")
59
+ throw error;
60
+ }
61
+ raw = readFileSync(join(gitDir, "config"), "utf8");
62
+ }
63
+ catch (error) {
64
+ if (errno(error) === "ENOENT")
65
+ return undefined;
66
+ throw error;
67
+ }
68
+ let origin = false;
69
+ for (const line of raw.split(/\r?\n/)) {
70
+ const section = /^\s*\[remote\s+"([^"]+)"\]\s*$/.exec(line);
71
+ if (section) {
72
+ origin = section[1] === "origin";
73
+ continue;
74
+ }
75
+ if (/^\s*\[/.test(line))
76
+ origin = false;
77
+ if (origin) {
78
+ const url = /^\s*url\s*=\s*(.*?)\s*$/.exec(line);
79
+ if (url)
80
+ return normalizeRemote(url[1].replace(/^"(.*)"$/, "$1")) || undefined;
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+ function readMarker(dir) {
86
+ let raw;
87
+ try {
88
+ raw = readFileSync(join(dir, ".project"), "utf8");
89
+ }
90
+ catch (error) {
91
+ if (errno(error) === "ENOENT")
92
+ return undefined;
93
+ throw error;
94
+ }
95
+ try {
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;
99
+ return { name: basename(dir), dir, id: value.id, path: value.path };
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ }
105
+ function projectRoot(home) {
106
+ return join(home, "project");
107
+ }
108
+ /** Read marked project homes. Unmarked legacy directories are deliberately omitted. */
109
+ export function projectHomes(home) {
110
+ const root = projectRoot(home);
111
+ let entries;
112
+ try {
113
+ entries = readdirSync(root, { withFileTypes: true });
114
+ }
115
+ catch (error) {
116
+ if (errno(error) === "ENOENT")
117
+ return [];
118
+ throw error;
119
+ }
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
+ }
122
+ function updateMarker(home, marker) {
123
+ const markerPath = join(home.dir, ".project");
124
+ const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
125
+ try {
126
+ writeFileSync(temp, JSON.stringify(marker));
127
+ renameSync(temp, markerPath);
128
+ }
129
+ catch (error) {
130
+ try {
131
+ rmSync(temp, { force: true });
132
+ }
133
+ catch { /* Preserve the marker update failure. */ }
134
+ throw error;
135
+ }
136
+ return { ...home, ...marker };
137
+ }
138
+ /** Resolve and claim the readable home for one repository identity. */
139
+ export function resolveProjectHome(cwd, home) {
140
+ const root = canonicalRoot(cwd);
141
+ const remote = originRemote(root);
142
+ const id = remote ?? root;
143
+ const markerRoot = projectRoot(home);
144
+ mkdirSync(markerRoot, { recursive: true });
145
+ const homes = projectHomes(home);
146
+ let found = homes.find(candidate => candidate.id === id);
147
+ if (!found && remote) {
148
+ found = homes.find(candidate => candidate.id === root);
149
+ if (found)
150
+ found = updateMarker(found, { id: remote, path: root });
151
+ }
152
+ if (found) {
153
+ if (found.path !== root)
154
+ found = updateMarker(found, { id: found.id, path: root });
155
+ return found;
156
+ }
157
+ const base = slugify(basename(root));
158
+ // Existing unmarked homes are taken; only directories appearing after this scan can be raced.
159
+ const taken = new Set(readdirSync(markerRoot));
160
+ for (let suffix = 0;; suffix++) {
161
+ const name = suffix === 0 ? base : `${base}-${suffix}`;
162
+ if (taken.has(name))
163
+ continue;
164
+ const dir = join(markerRoot, name);
165
+ 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 };
169
+ }
170
+ catch (error) {
171
+ if (errno(error) === "EEXIST")
172
+ continue;
173
+ throw error;
174
+ }
175
+ }
176
+ }
177
+ /** Existing root discovery, including linked worktrees, without invoking Git. */
178
+ function gitRoot(cwd) {
179
+ let dir = resolve(cwd);
180
+ for (;;) {
181
+ if (existsSync(join(dir, ".git")))
182
+ return repositoryRoot(dir);
183
+ const parent = dirname(dir);
184
+ if (parent === dir)
185
+ return undefined;
186
+ dir = parent;
187
+ }
188
+ }
189
+ function repositoryRoot(dir) {
190
+ let stats;
191
+ try {
192
+ stats = statSync(join(dir, ".git"));
193
+ }
194
+ catch {
195
+ return dir;
196
+ }
197
+ if (stats.isDirectory())
198
+ return dir;
199
+ let pointer;
200
+ try {
201
+ pointer = readFileSync(join(dir, ".git"), "utf8");
202
+ }
203
+ catch {
204
+ return dir;
205
+ }
206
+ const match = /^gitdir:\s*(.+)$/m.exec(pointer);
207
+ if (!match)
208
+ return dir;
209
+ const parts = resolve(dir, match[1].trim()).split(sep);
210
+ const worktrees = parts.lastIndexOf("worktrees");
211
+ if (worktrees <= 0 || worktrees !== parts.length - 2)
212
+ return dir;
213
+ const common = parts.slice(0, worktrees).join(sep);
214
+ return basename(common) === ".git" ? dirname(common) : dir;
215
+ }
216
+ /** Display-only context for an explicitly named project home. */
217
+ export function projectReceipt(home, name) {
218
+ const project = readMarker(join(projectRoot(home), name));
219
+ if (!project)
220
+ return {};
221
+ const base = slugify(basename(project.path));
222
+ const siblings = projectHomes(home).filter(candidate => candidate.name !== name && slugify(basename(candidate.path)) === base);
223
+ return {
224
+ project_root: project.path,
225
+ ...(siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name, path }) => ({ name, path })) }),
226
+ };
227
+ }
228
+ /** Names a project home, claiming it when the notes home has not seen this identity. */
229
+ export function projectKey(cwd, home) {
230
+ return resolveProjectHome(cwd, home).name;
231
+ }
@@ -1,6 +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
5
  export type { NoteMeta, Origin, Scope };
5
6
  export type NoteRow = {
6
7
  address: string;
@@ -84,11 +85,11 @@ export type NoteQueryResult<T> = {
84
85
  rows: T[];
85
86
  status: NoteQueryStatus;
86
87
  };
87
- /** Public identity resolved for an operation, never a filesystem path. */
88
+ /** Public note identity; named projects also carry their display root and sibling hints. */
88
89
  export declare function noteIdentity(identity: NotesIdentity, address: string): {
89
90
  address: string;
90
91
  project_key?: string;
91
- };
92
+ } & ProjectReceipt;
92
93
  /** Host-neutral, filesystem-backed notes API. */
93
94
  export interface NotesStore {
94
95
  write(address: string, content: string, options?: WriteOptions): Promise<NoteWriteResult>;
@@ -9,6 +9,7 @@ import { NoteError } from "./errors.js";
9
9
  import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
10
10
  import { isOrigin, isScope, localIso, parseNote, serializeNote, stripLeadingFrontmatter } from "./frontmatter.js";
11
11
  import { namespaceSlugs, noteFileName, physicalPath, scopeDir, SLUG_PATTERN } from "./paths.js";
12
+ import { projectHomes, projectReceipt } from "./project-home.js";
12
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.
13
14
  let lastWriteStamp = 0;
14
15
  function writeStamp() {
@@ -16,12 +17,12 @@ function writeStamp() {
16
17
  lastWriteStamp = now > lastWriteStamp ? now : lastWriteStamp + 1;
17
18
  return lastWriteStamp;
18
19
  }
19
- /** Public identity resolved for an operation, never a filesystem path. */
20
+ /** Public note identity; named projects also carry their display root and sibling hints. */
20
21
  export function noteIdentity(identity, address) {
21
22
  const resolved = assertAddress(address);
22
23
  return {
23
24
  address: addressFor(identity, resolved.scope, noteFileName(resolved.path), resolved.who),
24
- ...(resolved.scope === "project" ? { project_key: identity.projectKey } : {}),
25
+ ...(resolved.scope !== "project" ? {} : resolved.who === undefined ? { project_key: identity.projectKey } : projectReceipt(identity.home, resolved.who)),
25
26
  };
26
27
  }
27
28
  const SCOPE_ORDER = ["session", "project", "human", "agent", "model"];
@@ -87,12 +88,13 @@ async function homesForPattern(pattern, identity) {
87
88
  return [{ scope: "agent" }];
88
89
  if (head === "model")
89
90
  return [{ scope: "model" }];
90
- if (head === "agents" || head === "models") {
91
- const scope = head === "agents" ? "agent" : "model";
91
+ if (head === "projects" || head === "agents" || head === "models") {
92
+ const scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
92
93
  const name = pattern.slice(head.length + 2).split("/")[0] ?? "";
93
94
  if (name.length > 0 && !/[*?]/.test(name))
94
95
  return [{ scope, who: assertWho(name) }];
95
- return (await namespaceSlugs(head, identity.home)).map((who) => ({ scope, who }));
96
+ const names = head === "projects" ? projectHomes(identity.home).map(home => home.name) : await namespaceSlugs(head, identity.home);
97
+ return names.map((who) => ({ scope, who }));
96
98
  }
97
99
  return [];
98
100
  }
@@ -203,10 +205,12 @@ function assertSerializedSize(content) {
203
205
  function frontmatterOf(meta) {
204
206
  return serializeNote(meta, "").slice(0, -2);
205
207
  }
206
- /** Named agent/model homes are read-only to whoever is not running there. */
208
+ /** Explicit project homes are always read-only; agent/model homes allow their owner. */
207
209
  function assertWritableHome(scope, who, identity) {
208
210
  if (who === undefined)
209
211
  return;
212
+ if (scope === "project")
213
+ throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
210
214
  const current = scope === "agent" ? identity.agent : identity.model;
211
215
  if (who === current)
212
216
  return;
@@ -262,6 +266,8 @@ export function createNotesStore(input) {
262
266
  return undefined;
263
267
  const now = Date.now();
264
268
  const parsed = parseNote(raw, now);
269
+ if (scope === "project" && destination.who !== undefined)
270
+ return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
265
271
  // A read records its own access, exactly as a write records an edit.
266
272
  const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
267
273
  await atomicWrite(path, serializeNote(meta, parsed.body));
@@ -389,9 +395,9 @@ export function createNotesStore(input) {
389
395
  homes = await homesFor(identity, options);
390
396
  }
391
397
  catch (error) {
392
- if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? ""))
398
+ if (!status || !isFilesystemError(error) || !/^@(projects|agents|models)\//.test(options.glob ?? ""))
393
399
  throw error;
394
- status.homesUnavailable.push(options.glob.startsWith("@agents/") ? "@agents" : "@models");
400
+ status.homesUnavailable.push(options.glob.split("/")[0]);
395
401
  return;
396
402
  }
397
403
  for (const home of homes) {
@@ -1,6 +1,7 @@
1
1
  import { PI_TOOL_NAMES } from "./tool-names.js";
2
- import { notesIdentityFromPi } from "./notes/adapter.js";
3
- import { loadNotesSnapshot } from "../boot/snapshot.js";
2
+ import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
3
+ import { loadNotesSnapshot, unavailableNotesSnapshot } from "../boot/snapshot.js";
4
+ import { isFilesystemError } from "../notes/fs-error.js";
4
5
  import { BOOT_TYPE } from "./entries.js";
5
6
  import { renderBootBlock } from "../boot/render.js";
6
7
  import { currentReset, currentWindowId, isWindowBoot, rootWindowId } from "./window.js";
@@ -10,13 +11,24 @@ import { repairResetTail } from "./reset/artifacts.js";
10
11
  * fields are captured synchronously before the first filesystem await.
11
12
  */
12
13
  export async function buildBootMessage(ctx, windowId, previousId, notifyIncompleteNotes, isCurrent = () => true) {
13
- const identity = notesIdentityFromPi(ctx);
14
- const notes = await loadNotesSnapshot(identity, Date.now());
14
+ const agentName = agentSlug();
15
+ const modelName = modelSlug(ctx);
16
+ const sessionId = ctx.sessionManager.getSessionId();
17
+ const openedAt = Date.now();
18
+ let notes;
19
+ try {
20
+ notes = await loadNotesSnapshot(notesIdentityFromPi(ctx), openedAt);
21
+ }
22
+ catch (error) {
23
+ if (!isFilesystemError(error))
24
+ throw error;
25
+ notes = unavailableNotesSnapshot(openedAt);
26
+ }
15
27
  if (isCurrent())
16
28
  notifyIncompleteNotes?.(ctx, windowId, notes);
17
29
  return {
18
30
  customType: BOOT_TYPE,
19
- content: renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId: rootWindowId(identity.sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
31
+ content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
20
32
  display: false,
21
33
  details: { windowId },
22
34
  };
@@ -20,7 +20,7 @@ export function notesIdentityFromPi(ctx, home = notesRoot()) {
20
20
  return {
21
21
  home,
22
22
  sessionId: ctx.sessionManager.getSessionId(),
23
- projectKey: projectKey(ctx.cwd),
23
+ projectKey: projectKey(ctx.cwd, home),
24
24
  agent: agentSlug(),
25
25
  model: modelSlug(ctx),
26
26
  };
@@ -29,8 +29,6 @@ export declare const NotesReadDataSchema: Type.TObject<{
29
29
  text: Type.TString;
30
30
  total_chars: Type.TInteger;
31
31
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
32
- address: Type.TString;
33
- project_key: Type.TOptional<Type.TString>;
34
32
  metadata: Type.TObject<{
35
33
  origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
36
34
  created_at: Type.TString;
@@ -39,16 +37,28 @@ export declare const NotesReadDataSchema: Type.TObject<{
39
37
  project: Type.TOptional<Type.TString>;
40
38
  extra: Type.TRecord<"^.*$", Type.TUnknown>;
41
39
  }>;
40
+ project_root: Type.TOptional<Type.TString>;
41
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
42
+ name: Type.TString;
43
+ path: Type.TString;
44
+ }>>>;
45
+ address: Type.TString;
46
+ project_key: Type.TOptional<Type.TString>;
42
47
  }>;
43
48
  export type NotesReadData = Static<typeof NotesReadDataSchema>;
44
49
  export declare const NotesListDataSchema: Type.TObject<{
45
50
  more: Type.TInteger;
46
51
  homes_unavailable: Type.TArray<Type.TString>;
47
52
  files: Type.TArray<Type.TObject<{
48
- address: Type.TString;
49
- project_key: Type.TOptional<Type.TString>;
50
53
  updated_at: Type.TString;
51
54
  crumpled_at: Type.TOptional<Type.TString>;
55
+ project_root: Type.TOptional<Type.TString>;
56
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
57
+ name: Type.TString;
58
+ path: Type.TString;
59
+ }>>>;
60
+ address: Type.TString;
61
+ project_key: Type.TOptional<Type.TString>;
52
62
  }>>;
53
63
  }>;
54
64
  export type NotesListData = Static<typeof NotesListDataSchema>;
@@ -61,10 +71,15 @@ export declare const NotesSearchDataSchema: Type.TObject<{
61
71
  text: Type.TString;
62
72
  offset_chars: Type.TInteger;
63
73
  }>>;
64
- address: Type.TString;
65
- project_key: Type.TOptional<Type.TString>;
66
74
  updated_at: Type.TString;
67
75
  crumpled_at: Type.TOptional<Type.TString>;
76
+ project_root: Type.TOptional<Type.TString>;
77
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
78
+ name: Type.TString;
79
+ path: Type.TString;
80
+ }>>>;
81
+ address: Type.TString;
82
+ project_key: Type.TOptional<Type.TString>;
68
83
  }>>;
69
84
  }>;
70
85
  export type NotesSearchData = Static<typeof NotesSearchDataSchema>;
@@ -76,7 +91,7 @@ export declare const notesWriteParameters: Type.TObject<{
76
91
  export declare const notesWrite: {
77
92
  readonly name: "notes_write";
78
93
  readonly label: "Notes write";
79
- readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. 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.";
94
+ readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. 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.";
80
95
  readonly parameters: Type.TObject<{
81
96
  address: Type.TString;
82
97
  content: Type.TString;
@@ -111,7 +126,7 @@ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
111
126
  export declare const notesUpdate: {
112
127
  readonly name: "notes_update";
113
128
  readonly label: "Notes update";
114
- readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. 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.";
129
+ readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. 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.";
115
130
  readonly parameters: Type.TObject<{
116
131
  address: Type.TString;
117
132
  edits: Type.TOptional<Type.TArray<Type.TObject<{
@@ -145,7 +160,7 @@ export declare const notesReadParameters: Type.TObject<{
145
160
  export declare const notesRead: {
146
161
  readonly name: "notes_read";
147
162
  readonly label: "Notes read";
148
- readonly description: "Read a note. 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.";
163
+ readonly description: "Read a note. 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.";
149
164
  readonly parameters: Type.TObject<{
150
165
  offset_chars: Type.TOptional<Type.TInteger>;
151
166
  max_chars: Type.TOptional<Type.TInteger>;
@@ -155,8 +170,6 @@ export declare const notesRead: {
155
170
  text: Type.TString;
156
171
  total_chars: Type.TInteger;
157
172
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
158
- address: Type.TString;
159
- project_key: Type.TOptional<Type.TString>;
160
173
  metadata: Type.TObject<{
161
174
  origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
162
175
  created_at: Type.TString;
@@ -165,6 +178,13 @@ export declare const notesRead: {
165
178
  project: Type.TOptional<Type.TString>;
166
179
  extra: Type.TRecord<"^.*$", Type.TUnknown>;
167
180
  }>;
181
+ project_root: Type.TOptional<Type.TString>;
182
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
183
+ name: Type.TString;
184
+ path: Type.TString;
185
+ }>>>;
186
+ address: Type.TString;
187
+ project_key: Type.TOptional<Type.TString>;
168
188
  }>, Type.TObject<{
169
189
  error: Type.TString;
170
190
  code: Type.TString;
@@ -180,7 +200,7 @@ export declare const notesListParameters: Type.TObject<{
180
200
  export declare const notesList: {
181
201
  readonly name: "notes_list";
182
202
  readonly label: "Notes list";
183
- readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. 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.";
203
+ readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. 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.";
184
204
  readonly parameters: Type.TObject<{
185
205
  glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
186
206
  limit: Type.TOptional<Type.TInteger>;
@@ -190,10 +210,15 @@ export declare const notesList: {
190
210
  more: Type.TInteger;
191
211
  homes_unavailable: Type.TArray<Type.TString>;
192
212
  files: Type.TArray<Type.TObject<{
193
- address: Type.TString;
194
- project_key: Type.TOptional<Type.TString>;
195
213
  updated_at: Type.TString;
196
214
  crumpled_at: Type.TOptional<Type.TString>;
215
+ project_root: Type.TOptional<Type.TString>;
216
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
217
+ name: Type.TString;
218
+ path: Type.TString;
219
+ }>>>;
220
+ address: Type.TString;
221
+ project_key: Type.TOptional<Type.TString>;
197
222
  }>>;
198
223
  }>, Type.TObject<{
199
224
  error: Type.TString;
@@ -214,7 +239,7 @@ export declare const MATCH_SHORTENED_MARKER = " [truncated]";
214
239
  export declare const notesSearch: {
215
240
  readonly name: "notes_search";
216
241
  readonly label: "Notes search";
217
- readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. 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.";
242
+ readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. 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.";
218
243
  readonly parameters: Type.TObject<{
219
244
  query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
220
245
  glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
@@ -231,10 +256,15 @@ export declare const notesSearch: {
231
256
  text: Type.TString;
232
257
  offset_chars: Type.TInteger;
233
258
  }>>;
234
- address: Type.TString;
235
- project_key: Type.TOptional<Type.TString>;
236
259
  updated_at: Type.TString;
237
260
  crumpled_at: Type.TOptional<Type.TString>;
261
+ project_root: Type.TOptional<Type.TString>;
262
+ project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
263
+ name: Type.TString;
264
+ path: Type.TString;
265
+ }>>>;
266
+ address: Type.TString;
267
+ project_key: Type.TOptional<Type.TString>;
238
268
  }>>;
239
269
  }>, Type.TObject<{
240
270
  error: Type.TString;
@@ -13,7 +13,7 @@ const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional)
13
13
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
14
14
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
15
15
  const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
16
- 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.";
16
+ 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.";
17
17
  /**
18
18
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
19
19
  * Convert expected refusals; unexpected errors propagate unchanged.
@@ -88,13 +88,23 @@ function renderMetadata(metadata) {
88
88
  fields.push(`extra ${JSON.stringify(metadata.extra)}`);
89
89
  return fields.join(" | ");
90
90
  }
91
- /** Address plus project key in one line; the project key never replaces the address. */
91
+ /** Keep the address visible, with project context and at most one sibling hint line. */
92
92
  function renderIdentity(identity) {
93
- return identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
93
+ let text = identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
94
+ if (identity.project_root !== undefined)
95
+ text += ` (project_root ${identity.project_root})`;
96
+ if (identity.project_siblings !== undefined)
97
+ text += `\n Same-basename projects: ${identity.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
98
+ return text;
94
99
  }
100
+ const ProjectReceiptSchema = {
101
+ project_root: Type.Optional(Type.String()),
102
+ project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
103
+ };
95
104
  const ListedFileSchema = Type.Object({
96
105
  address: Type.String(),
97
106
  project_key: Type.Optional(Type.String()),
107
+ ...ProjectReceiptSchema,
98
108
  updated_at: Type.String(),
99
109
  crumpled_at: Type.Optional(Type.String()),
100
110
  }, { additionalProperties: false });
@@ -126,6 +136,7 @@ export const NotesUpdateDataSchema = Type.Object({
126
136
  export const NotesReadDataSchema = Type.Object({
127
137
  address: Type.String(),
128
138
  project_key: Type.Optional(Type.String()),
139
+ ...ProjectReceiptSchema,
129
140
  metadata: NoteMetadataSchema,
130
141
  ...TextWindowSchema.properties,
131
142
  }, { additionalProperties: false });
@@ -161,7 +172,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
161
172
  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.`);
162
173
  }
163
174
  function listedFile(row, identity) {
164
- 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 }) };
175
+ return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
165
176
  }
166
177
  export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
167
178
  function renderWriteData(data) {
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { execFileSync } from "node:child_process";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
@@ -11,6 +11,10 @@ import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../src/
11
11
  import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
12
12
  import { PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
13
13
  import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../src/budget/text.js";
14
+ import { createNotesStore } from "../src/notes/index.js";
15
+ import { resolveProjectHome } from "../src/notes/project-home.js";
16
+ import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
17
+ import { context, manager } from "./helpers/extension.js";
14
18
  const identity = { home: mkdtempSync(join(tmpdir(), "claude-mod-")), sessionId: "session", cwd: process.cwd(), agent: "claude", model: "claude" };
15
19
  async function callTool(tool, params) {
16
20
  return await dispatch({ op: "tool", tool, identity, params });
@@ -779,6 +783,33 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
779
783
  await write("@model/model.md", "fallback");
780
784
  assert.equal(seen.at(-1).identity.model, "claude");
781
785
  });
786
+ test("Claude current-cwd project resolution shares Pi's remote home across checkout spellings", async (t) => {
787
+ const { host, home, invoke } = await retainedFixture(t);
788
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "claude-project-home-")));
789
+ t.after(() => rmSync(root, { recursive: true, force: true }));
790
+ const first = join(root, "api");
791
+ const second = join(root, "renamed");
792
+ for (const [cwd, remote] of [[first, "git@HOST:team/backend.git"], [second, "https://host/team/backend.git"]]) {
793
+ mkdirSync(join(cwd, ".git"), { recursive: true });
794
+ writeFileSync(join(cwd, ".git/config"), `[remote "origin"]\nurl = ${remote}\n`);
795
+ }
796
+ let cwd = first;
797
+ host.session.cwd = async () => cwd;
798
+ const piIdentity = notesIdentityFromPi(context(manager(), undefined, undefined, true, first), home);
799
+ assert.equal(piIdentity.projectKey, "api");
800
+ await createNotesStore(piIdentity).write("@project/shared", "Pi body");
801
+ const call = (tool, params) => invoke("tool.call", {
802
+ tool: `mcp__notesoup__${tool}`, tool_use_id: "project-call", ...params,
803
+ });
804
+ assert.match((await call("notes_read", { address: "@project/shared" })).result, /Pi body/);
805
+ cwd = second;
806
+ const written = await call("notes_write", { address: "@project/shared", content: "Claude body" });
807
+ assert.equal(written.isError, undefined);
808
+ assert.equal(written.result, "overwrote @project/shared.md (project api)");
809
+ assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
810
+ assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
811
+ assert.equal(resolveProjectHome(second, home).name, piIdentity.projectKey);
812
+ });
782
813
  test("Claude session.end cannot be undone by an in-flight old reset", async (t) => {
783
814
  const { host, invoke, context } = await retainedFixture(t);
784
815
  let prepared;