notesoup 0.53.2 → 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 (131) hide show
  1. package/README.md +2 -2
  2. package/dist/plugins/claude/src/helper.js +2 -1
  3. package/dist/plugins/codex/src/hooks.js +1 -1
  4. package/dist/plugins/codex/src/identity.d.ts +1 -1
  5. package/dist/plugins/codex/src/identity.js +3 -3
  6. package/dist/plugins/codex/src/mcp.js +2 -1
  7. package/dist/plugins/codex/src/text.d.ts +1 -1
  8. package/dist/plugins/codex/src/text.js +2 -2
  9. package/dist/plugins/dsh/engine.js +2 -2
  10. package/dist/plugins/dsh/tools.js +8 -7
  11. package/dist/plugins/dsh/window.d.ts +1 -0
  12. package/dist/plugins/dsh/window.js +7 -3
  13. package/dist/plugins/pi/history-tools.d.ts +1 -1
  14. package/dist/plugins/pi/history-tools.js +4 -4
  15. package/dist/plugins/pi/notes/tools.js +8 -6
  16. package/dist/plugins/pi/render.js +7 -4
  17. package/dist/plugins/pi/runtime.js +2 -2
  18. package/dist/plugins/pi/window.js +21 -7
  19. package/dist/src/boot/render.js +7 -7
  20. package/dist/src/boot/snapshot.d.ts +7 -7
  21. package/dist/src/boot/snapshot.js +17 -17
  22. package/dist/src/boot/text.d.ts +2 -2
  23. package/dist/src/boot/text.js +7 -5
  24. package/dist/src/dream/git.d.ts +2 -11
  25. package/dist/src/dream/git.js +6 -23
  26. package/dist/src/dream/lock.d.ts +2 -2
  27. package/dist/src/dream/lock.js +3 -3
  28. package/dist/src/index.d.ts +2 -1
  29. package/dist/src/index.js +3 -2
  30. package/dist/src/notes/address.d.ts +8 -8
  31. package/dist/src/notes/address.js +13 -13
  32. package/dist/src/notes/errors.d.ts +1 -1
  33. package/dist/src/notes/frontmatter.js +2 -2
  34. package/dist/src/notes/index.d.ts +1 -1
  35. package/dist/src/notes/index.js +1 -1
  36. package/dist/src/notes/paths.d.ts +6 -6
  37. package/dist/src/notes/paths.js +9 -9
  38. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  39. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  40. package/dist/src/notes/store.d.ts +4 -4
  41. package/dist/src/notes/store.js +55 -52
  42. package/dist/src/tools/dream.d.ts +21 -3
  43. package/dist/src/tools/dream.js +54 -16
  44. package/dist/src/tools/notes-context.d.ts +10 -0
  45. package/dist/src/tools/notes-context.js +27 -0
  46. package/dist/src/tools/notes.d.ts +69 -20
  47. package/dist/src/tools/notes.js +40 -31
  48. package/dist/test/boot.integration.test.js +1 -1
  49. package/dist/test/claude-mod.test.js +89 -43
  50. package/dist/test/codex-plugin.test.js +18 -1
  51. package/dist/test/context-edit-budget.test.js +121 -0
  52. package/dist/test/dependencies.test.js +71 -4
  53. package/dist/test/dream-tools.test.js +153 -8
  54. package/dist/test/dsh.test.js +62 -15
  55. package/dist/test/helpers/dsh.d.ts +4 -1
  56. package/dist/test/helpers/dsh.js +20 -4
  57. package/dist/test/helpers/extension.d.ts +5 -0
  58. package/dist/test/helpers/extension.js +33 -2
  59. package/dist/test/host-neutral.test.js +17 -15
  60. package/dist/test/model-facing-text.test.js +12 -8
  61. package/dist/test/notes-cwd.test.js +114 -0
  62. package/dist/test/notes-library.test.js +4 -4
  63. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  64. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  65. package/dist/test/notes.integration.test.js +72 -23
  66. package/dist/test/notes.test.js +50 -20
  67. package/dist/test/pi-render.test.js +33 -1
  68. package/dist/test/project-namespace.test.d.ts +1 -0
  69. package/dist/test/project-namespace.test.js +324 -0
  70. package/docs/architecture.md +12 -7
  71. package/docs/codex.md +4 -4
  72. package/docs/dsh.md +8 -8
  73. package/docs/notes-library.md +9 -5
  74. package/docs/skills.md +3 -3
  75. package/docs/tool-results.md +6 -2
  76. package/package.json +4 -6
  77. package/playbook.md +6 -6
  78. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  79. package/plugins/claude/dist/claude/helper.js +677 -615
  80. package/plugins/claude/hooks/register.ts +19 -11
  81. package/plugins/claude/playbook.md +6 -6
  82. package/plugins/claude/skills/memory/SKILL.md +4 -4
  83. package/plugins/claude/src/helper.ts +3 -2
  84. package/plugins/codex/README.md +1 -1
  85. package/plugins/codex/dist/codex/notesoup.js +877 -815
  86. package/plugins/codex/src/hooks.ts +1 -1
  87. package/plugins/codex/src/identity.ts +3 -3
  88. package/plugins/codex/src/mcp.ts +2 -1
  89. package/plugins/codex/src/text.ts +2 -2
  90. package/plugins/dsh/engine.ts +2 -2
  91. package/plugins/dsh/tools.ts +8 -7
  92. package/plugins/dsh/window.ts +8 -3
  93. package/plugins/paseo/OVERVIEW.md +4 -4
  94. package/plugins/paseo/README.md +1 -1
  95. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  96. package/plugins/paseo/client/markdown.tsx +179 -0
  97. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  98. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  99. package/plugins/paseo/client/paper-card.tsx +8 -19
  100. package/plugins/paseo/client/paper-palette.ts +40 -0
  101. package/plugins/paseo/client/sticky-card.tsx +6 -4
  102. package/plugins/paseo/package.json +3 -0
  103. package/plugins/paseo/paseo-plugin.json +2 -2
  104. package/plugins/paseo/shared/notes-op.ts +13 -9
  105. package/plugins/paseo/test/notes-op.test.ts +52 -73
  106. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  107. package/plugins/pi/history-tools.ts +4 -4
  108. package/plugins/pi/notes/tools.ts +8 -6
  109. package/plugins/pi/render.ts +6 -4
  110. package/plugins/pi/runtime.ts +2 -2
  111. package/plugins/pi/window.ts +22 -7
  112. package/skills/memory/SKILL.md +4 -4
  113. package/src/boot/render.ts +8 -8
  114. package/src/boot/snapshot.ts +20 -20
  115. package/src/boot/text.ts +7 -5
  116. package/src/dream/git.ts +7 -24
  117. package/src/dream/lock.ts +3 -3
  118. package/src/index.ts +4 -3
  119. package/src/notes/address.ts +13 -13
  120. package/src/notes/errors.ts +1 -1
  121. package/src/notes/frontmatter.ts +2 -2
  122. package/src/notes/index.ts +1 -1
  123. package/src/notes/paths.ts +9 -9
  124. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  125. package/src/notes/store.ts +61 -58
  126. package/src/tools/dream.ts +63 -16
  127. package/src/tools/notes-context.ts +29 -0
  128. package/src/tools/notes.ts +39 -29
  129. package/dist/test/project-home.test.js +0 -134
  130. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  131. /package/dist/test/{project-home.test.d.ts → notes-cwd.test.d.ts} +0 -0
@@ -6,6 +6,7 @@ import { createNotesStore, NoteError, noteIdentity, type NoteChange, type NoteMe
6
6
  import { prefixFit, TOOL_OUTPUT_LIMIT } from "./output.js";
7
7
  import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema, type Outcome } from "./result.js";
8
8
  import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
9
+ import { notesIdentityForCall, type NotesToolContext } from "./notes-context.js";
9
10
 
10
11
  const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")] as const;
11
12
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
@@ -14,9 +15,10 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
14
15
  const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
15
16
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
16
17
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
17
- const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current homes.");
18
- const QUERY_HOMES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared homes; `**` searches all homes, `@sessions/*/**` searches all sessions.";
19
- const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
18
+ const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current notebooks.");
19
+ const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "(optional) Select the current project for this call. A relative path resolves against the host session cwd; the path must be an existing directory." }));
20
+ const QUERY_NAMESPACES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions.";
21
+ const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
20
22
 
21
23
  /**
22
24
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
@@ -103,15 +105,21 @@ function renderIdentity(identity: { address: string; project_key?: string; proje
103
105
  return text;
104
106
  }
105
107
 
106
- const ProjectReceiptSchema = {
108
+ /** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
109
+ export const ProjectReceiptSchema = {
107
110
  project_root: Type.Optional(Type.String()),
108
111
  project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
109
112
  };
110
113
 
111
- const ListedFileSchema = Type.Object({
114
+ /** One note identity, shared by every receipt: read/list/search rows and all mutations alike. */
115
+ export const NoteIdentitySchema = {
112
116
  address: Type.String(),
113
117
  project_key: Type.Optional(Type.String()),
114
118
  ...ProjectReceiptSchema,
119
+ };
120
+
121
+ const ListedFileSchema = Type.Object({
122
+ ...NoteIdentitySchema,
115
123
  updated_at: Type.String(),
116
124
  last_accessed: Type.String(),
117
125
  crumpled_at: Type.Optional(Type.String()),
@@ -130,19 +138,17 @@ const SearchedFileSchema = Type.Object({
130
138
 
131
139
  const SnapshotSchema = {
132
140
  more: Type.Integer({ description: "How many more were left out." }),
133
- homes_unavailable: Type.Array(Type.String()),
141
+ namespaces_unavailable: Type.Array(Type.String()),
134
142
  };
135
143
 
136
144
  export const NotesWriteDataSchema = Type.Object({
137
- address: Type.String(),
138
- project_key: Type.Optional(Type.String()),
145
+ ...NoteIdentitySchema,
139
146
  outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
140
147
  }, { additionalProperties: false });
141
148
  export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
142
149
 
143
150
  export const NotesUpdateDataSchema = Type.Object({
144
- address: Type.String(),
145
- project_key: Type.Optional(Type.String()),
151
+ ...NoteIdentitySchema,
146
152
  change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
147
153
  diff: Type.String(),
148
154
  rename_from: Type.Optional(Type.String()),
@@ -150,9 +156,7 @@ export const NotesUpdateDataSchema = Type.Object({
150
156
  export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
151
157
 
152
158
  export const NotesReadDataSchema = Type.Object({
153
- address: Type.String(),
154
- project_key: Type.Optional(Type.String()),
155
- ...ProjectReceiptSchema,
159
+ ...NoteIdentitySchema,
156
160
  metadata: NoteMetadataSchema,
157
161
  ...TextWindowSchema.properties,
158
162
  }, { additionalProperties: false });
@@ -181,7 +185,7 @@ export function snapshot<T extends { address: string }>(
181
185
  shrink?: (item: T, fits: (candidate: T) => boolean) => T,
182
186
  ): Outcome<Snapshot<T>> {
183
187
  const files: T[] = [];
184
- const data = (selected: T[]): Snapshot<T> => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
188
+ const data = (selected: T[]): Snapshot<T> => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
185
189
  const render = (outcome: Outcome<Snapshot<T>>) => renderOutcome(outcome, renderData);
186
190
  const fits = (item: T) => fitsResult(success(data([...files, item])), render);
187
191
  for (const item of rows.slice(0, limit)) {
@@ -197,14 +201,14 @@ export function snapshot<T extends { address: string }>(
197
201
  break;
198
202
  }
199
203
  const outcome = success(data(files));
200
- 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.`);
204
+ return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable notebooks is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer notebooks.`);
201
205
  }
202
206
 
203
207
  export function listedFile(row: Pick<NoteRow, "address" | "meta">, identity: NotesIdentity): NotesListData["files"][number] {
204
208
  return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), last_accessed: localIso(row.meta.lastAccessed), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
205
209
  }
206
210
 
207
- export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
211
+ export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, cwd: CWD_PARAMETER }, { additionalProperties: false });
208
212
 
209
213
  function renderWriteData(data: NotesWriteData): string {
210
214
  return `${data.outcome} ${renderIdentity(data)}`;
@@ -214,8 +218,9 @@ export const notesWrite = {
214
218
  name: "notes_write", label: "Notes write",
215
219
  description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
216
220
  parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
217
- async execute(params: Static<typeof notesWriteParameters>, identity: NotesIdentity): Promise<Outcome<NotesWriteData>> {
221
+ async execute(params: Static<typeof notesWriteParameters>, context: NotesToolContext): Promise<Outcome<NotesWriteData>> {
218
222
  try {
223
+ const identity = notesIdentityForCall(context, params.cwd);
219
224
  const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin });
220
225
  return success({ ...noteIdentity(identity, params.address), outcome });
221
226
  } catch (error) { return failureOf(error); }
@@ -230,6 +235,7 @@ export const notesUpdateParameters = Type.Object({
230
235
  crumpled: CRUMPLED_PARAMETER,
231
236
  replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
232
237
  rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, optionally with edits or metadata changes. Won't overwrite a live note; references aren't updated." })),
238
+ cwd: CWD_PARAMETER,
233
239
  }, { additionalProperties: false });
234
240
 
235
241
  function renderUpdateData(data: NotesUpdateData): string {
@@ -261,10 +267,11 @@ function boundedUpdate(data: NotesUpdateData): Outcome<NotesUpdateData> {
261
267
 
262
268
  export const notesUpdate = {
263
269
  name: "notes_update", label: "Notes update",
264
- description: `Change part of a note's body, its origin or crumpled state, or its address. When a line goes stale, replace it; don't append the correction below it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
270
+ description: `Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
265
271
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
266
- async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
272
+ async execute(params: Static<typeof notesUpdateParameters>, context: NotesToolContext, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
267
273
  try {
274
+ const identity = notesIdentityForCall(context, params.cwd);
268
275
  const store = createNotesStore(identity);
269
276
  // Empty filler is not a request: models that pass every parameter get the edit path.
270
277
  const renameTo = params.rename_to === "" ? undefined : params.rename_to;
@@ -278,7 +285,7 @@ export const notesUpdate = {
278
285
  render: renderUpdate,
279
286
  } as const;
280
287
 
281
- export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
288
+ export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
282
289
 
283
290
  function renderReadData(data: NotesReadData): string {
284
291
  return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
@@ -288,8 +295,9 @@ export const notesRead = {
288
295
  name: "notes_read", label: "Notes read",
289
296
  description: `Read a note. ${ADDRESS_DESCRIPTION}`,
290
297
  parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
291
- async execute(params: Static<typeof notesReadParameters>, identity: NotesIdentity): Promise<Outcome<NotesReadData>> {
298
+ async execute(params: Static<typeof notesReadParameters>, context: NotesToolContext): Promise<Outcome<NotesReadData>> {
292
299
  try {
300
+ const identity = notesIdentityForCall(context, params.cwd);
293
301
  const note = await createNotesStore(identity).read(params.address);
294
302
  const resolved = noteIdentity(identity, params.address);
295
303
  if (!note) return failure("not_found", `No note at ${resolved.address}.`);
@@ -303,7 +311,7 @@ export const notesRead = {
303
311
  render: (result: Outcome<NotesReadData>): string => renderOutcome(result, renderReadData),
304
312
  } as const;
305
313
 
306
- export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
314
+ export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
307
315
 
308
316
  export function renderListData(data: NotesListData): string {
309
317
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
@@ -311,16 +319,17 @@ export function renderListData(data: NotesListData): string {
311
319
  lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | accessed ${file.last_accessed}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
312
320
  }
313
321
  if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
314
- for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
322
+ for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
315
323
  return lines.join("\n");
316
324
  }
317
325
 
318
326
  export const notesList = {
319
327
  name: "notes_list", label: "Notes list",
320
- description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_HOMES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
328
+ description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
321
329
  parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
322
- async execute(params: Static<typeof notesListParameters>, identity: NotesIdentity): Promise<Outcome<NotesListData>> {
330
+ async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
323
331
  try {
332
+ const identity = notesIdentityForCall(context, params.cwd);
324
333
  const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
325
334
  return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
326
335
  } catch (error) { return failureOf(error); }
@@ -328,7 +337,7 @@ export const notesList = {
328
337
  render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
329
338
  } as const;
330
339
 
331
- export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
340
+ export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
332
341
 
333
342
  function renderSearchData(data: NotesSearchData): string {
334
343
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
@@ -337,7 +346,7 @@ function renderSearchData(data: NotesSearchData): string {
337
346
  for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
338
347
  }
339
348
  if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
340
- for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
349
+ for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
341
350
  return lines.join("\n");
342
351
  }
343
352
 
@@ -364,10 +373,11 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
364
373
 
365
374
  export const notesSearch = {
366
375
  name: "notes_search", label: "Notes search",
367
- description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${QUERY_HOMES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
376
+ description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
368
377
  parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
369
- async execute(params: Static<typeof notesSearchParameters>, identity: NotesIdentity): Promise<Outcome<NotesSearchData>> {
378
+ async execute(params: Static<typeof notesSearchParameters>, context: NotesToolContext): Promise<Outcome<NotesSearchData>> {
370
379
  try {
380
+ const identity = notesIdentityForCall(context, params.cwd);
371
381
  const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
372
382
  const files: NotesSearchData["files"] = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => ({
373
383
  ...listedFile(row, identity),
@@ -1,134 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import test from "node:test";
6
- import { Check } from "typebox/value";
7
- import { createNotesStore } from "../src/notes/index.js";
8
- import { assertAddress } from "../src/notes/address.js";
9
- import { normalizeRemote, projectKey } from "../src/notes/project-home.js";
10
- import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
11
- import { success } from "../src/tools/result.js";
12
- function fixture(t) {
13
- const root = realpathSync(mkdtempSync(join(tmpdir(), "notesoup-project-home-")));
14
- t.after(() => rmSync(root, { recursive: true, force: true }));
15
- const home = join(root, "notes");
16
- const repo = (path, origin) => {
17
- const cwd = join(root, path);
18
- mkdirSync(join(cwd, ".git"), { recursive: true });
19
- writeFileSync(join(cwd, ".git/config"), origin ? `[remote "origin"]\n\turl = ${origin}\n` : "");
20
- return cwd;
21
- };
22
- const marker = (key) => JSON.parse(readFileSync(join(home, "project", key, ".project"), "utf8"));
23
- const identity = (cwd) => ({ home, projectKey: projectKey(cwd, home), sessionId: "session", agent: "test", model: "test" });
24
- return { root, home, repo, marker, identity };
25
- }
26
- function data(result) {
27
- if (!result.ok)
28
- assert.fail(result.error.message);
29
- return result.data;
30
- }
31
- function refused(result) {
32
- if (result.ok)
33
- assert.fail("expected refusal");
34
- return result.error.message;
35
- }
36
- test("origin identity normalizes https, scp and port-less ssh without invoking Git", t => {
37
- const { home, repo, marker } = fixture(t);
38
- for (const remote of ["https://user:secret@GitHub.COM/team/api.git/", "git@GitHub.COM:team/api.git", "ssh://git@GitHub.COM/team/api.git"]) {
39
- assert.equal(normalizeRemote(remote), "github.com/team/api");
40
- }
41
- assert.equal(normalizeRemote("ssh://git@EXAMPLE.com:2222/team/api.git"), "example.com:2222/team/api");
42
- const first = repo("one/api", "git@GitHub.COM:team/api.git");
43
- const second = repo("two/renamed", "https://github.com/team/api.git");
44
- assert.equal(projectKey(first, home), "api");
45
- assert.equal(projectKey(second, home), "api");
46
- assert.deepEqual(marker("api"), { id: "github.com/team/api", path: second });
47
- });
48
- test("same-basename repositories get readable suffixes and unmarked legacy names are taken", t => {
49
- const { home, repo } = fixture(t);
50
- const first = repo("one/x", "https://host/one/x");
51
- const second = repo("two/x", "https://host/two/x");
52
- assert.equal(projectKey(first, home), "x");
53
- assert.equal(projectKey(second, home), "x-1");
54
- mkdirSync(join(home, "project", "legacy"));
55
- writeFileSync(join(home, "project", "legacy", "keep.md"), "old notes");
56
- assert.equal(projectKey(repo("legacy"), home), "legacy-1");
57
- assert.equal(readFileSync(join(home, "project", "legacy", "keep.md"), "utf8"), "old notes");
58
- });
59
- test("linked worktrees and nested directories share the main checkout home and origin", t => {
60
- const { root, home, repo, marker } = fixture(t);
61
- const main = repo("api", "ssh://git@HOST/team/api.git");
62
- const worktree = join(root, "worktree");
63
- mkdirSync(worktree);
64
- mkdirSync(join(main, ".git/worktrees/wt"), { recursive: true });
65
- writeFileSync(join(worktree, ".git"), `gitdir: ${join(main, ".git/worktrees/wt")}\n`);
66
- writeFileSync(join(main, ".git/worktrees/wt/commondir"), "../..\n");
67
- assert.equal(projectKey(main, home), "api");
68
- assert.equal(projectKey(join(worktree, "missing/subdir"), home), "api");
69
- assert.deepEqual(marker("api"), { id: "host/team/api", path: main });
70
- });
71
- test("a moved checkout reuses its remote home and updates only the display root", async (t) => {
72
- const { root, home, repo, marker, identity } = fixture(t);
73
- const old = repo("api", "https://host/team/api.git");
74
- await createNotesStore(identity(old)).write("@project/decision", "keep me");
75
- const moved = join(root, "new-name");
76
- renameSync(old, moved);
77
- const current = identity(moved);
78
- assert.equal(current.projectKey, "api");
79
- assert.deepEqual(marker("api"), { id: "host/team/api", path: moved });
80
- assert.equal((await createNotesStore(current).read("@project/decision"))?.body, "keep me");
81
- assert.equal(projectKey(moved, home), "api");
82
- });
83
- test("adding origin adopts the canonical path identity without orphaning notes", async (t) => {
84
- const { home, repo, marker, identity } = fixture(t);
85
- const cwd = repo("api");
86
- await createNotesStore(identity(cwd)).write("@project/decision", "still here");
87
- assert.deepEqual(marker("api"), { id: cwd, path: cwd });
88
- writeFileSync(join(cwd, ".git/config"), '[remote "backup"]\nurl = https://host/wrong\n[remote "origin"]\nurl = git@HOST:team/api.git\n');
89
- assert.equal(projectKey(cwd, home), "api");
90
- assert.deepEqual(marker("api"), { id: "host/team/api", path: cwd });
91
- assert.equal((await createNotesStore(identity(cwd)).read("@project/decision"))?.body, "still here");
92
- });
93
- test("named projects read/list/search with root and sibling receipts, without touching stored bytes", async (t) => {
94
- const { home, repo, identity } = fixture(t);
95
- const first = repo("one/api", "https://host/one/backend");
96
- const second = repo("two/api", "https://host/two/service");
97
- const own = identity(first);
98
- const other = identity(second);
99
- await createNotesStore(own).write("@project/decision", "needle first");
100
- await createNotesStore(other).write("@project/decision", "needle second");
101
- const address = "@projects/api-1/decision.md";
102
- const file = join(home, "project/api-1/decision.md");
103
- const before = readFileSync(file, "utf8");
104
- const read = data(await notesRead.execute({ address }, own));
105
- assert.equal(read.text, "needle second");
106
- assert.equal(read.project_root, second);
107
- assert.deepEqual(read.project_siblings, [{ name: "api", path: first }]);
108
- assert.equal(Check(notesRead.outputSchema, read), true);
109
- assert.match(notesRead.render(success(read)), /Same-basename projects: api \(/);
110
- const listed = data(await notesList.execute({ glob: "@projects/*/**" }, own));
111
- assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
112
- assert.equal(Check(notesList.outputSchema, listed), true);
113
- const searched = data(await notesSearch.execute({ glob: "@projects/api-1/**", query: "needle" }, own));
114
- assert.equal(searched.files[0]?.project_root, second);
115
- assert.equal(Check(notesSearch.outputSchema, searched), true);
116
- assert.equal(readFileSync(file, "utf8"), before, "named-home reads never rewrite access metadata");
117
- });
118
- test("named project writes, edits, crumples and both move endpoints refuse, including the current home", async (t) => {
119
- const { repo, identity } = fixture(t);
120
- const own = identity(repo("api"));
121
- await createNotesStore(own).write("@project/decision", "body");
122
- const address = "@projects/api/decision";
123
- for (const result of [
124
- await notesWrite.execute({ address, content: "replacement" }, own),
125
- await notesUpdate.execute({ address, edits: [{ oldText: "body", newText: "changed" }] }, own, () => ""),
126
- await notesUpdate.execute({ address, crumpled: true }, own, () => ""),
127
- await notesUpdate.execute({ address, rename_to: "@project/moved" }, own, () => ""),
128
- await notesUpdate.execute({ address: "@project/decision", rename_to: "@projects/api/moved" }, own, () => ""),
129
- ])
130
- assert.match(refused(result), /read-only; use @project\//);
131
- assert.equal(data(await notesRead.execute({ address }, own)).text, "body");
132
- assert.throws(() => assertAddress("@projects/api/../decision"));
133
- assert.throws(() => assertAddress("@projects/api"));
134
- });