notesoup 0.53.2 → 0.54.1

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 (186) hide show
  1. package/README.md +6 -4
  2. package/dist/plugins/claude/src/helper.d.ts +2 -1
  3. package/dist/plugins/claude/src/helper.js +21 -24
  4. package/dist/plugins/claude/src/history.d.ts +3 -14
  5. package/dist/plugins/claude/src/history.js +2 -298
  6. package/dist/plugins/claude/src/text.d.ts +0 -1
  7. package/dist/plugins/claude/src/text.js +0 -1
  8. package/dist/plugins/codex/src/history.d.ts +3 -8
  9. package/dist/plugins/codex/src/history.js +2 -238
  10. package/dist/plugins/codex/src/hooks.js +1 -1
  11. package/dist/plugins/codex/src/identity.d.ts +1 -1
  12. package/dist/plugins/codex/src/identity.js +3 -3
  13. package/dist/plugins/codex/src/mcp.js +9 -8
  14. package/dist/plugins/codex/src/text.d.ts +1 -1
  15. package/dist/plugins/codex/src/text.js +2 -2
  16. package/dist/plugins/codex/src/transcript.d.ts +3 -39
  17. package/dist/plugins/codex/src/transcript.js +2 -313
  18. package/dist/plugins/dsh/engine.js +2 -2
  19. package/dist/plugins/dsh/history.d.ts +3 -0
  20. package/dist/plugins/dsh/history.js +15 -0
  21. package/dist/plugins/dsh/tools.js +12 -12
  22. package/dist/plugins/dsh/window.d.ts +1 -0
  23. package/dist/plugins/dsh/window.js +7 -3
  24. package/dist/plugins/pi/history-tools.d.ts +1 -1
  25. package/dist/plugins/pi/history-tools.js +9 -5
  26. package/dist/plugins/pi/history.d.ts +2 -3
  27. package/dist/plugins/pi/history.js +4 -147
  28. package/dist/plugins/pi/notes/tools.js +8 -6
  29. package/dist/plugins/pi/render.js +7 -4
  30. package/dist/plugins/pi/runtime.js +2 -2
  31. package/dist/plugins/pi/window.js +21 -7
  32. package/dist/src/boot/render.js +9 -11
  33. package/dist/src/boot/snapshot.d.ts +7 -7
  34. package/dist/src/boot/snapshot.js +17 -17
  35. package/dist/src/boot/text.d.ts +5 -3
  36. package/dist/src/boot/text.js +18 -10
  37. package/dist/src/dream/git.d.ts +2 -11
  38. package/dist/src/dream/git.js +6 -23
  39. package/dist/src/dream/lock.d.ts +2 -2
  40. package/dist/src/dream/lock.js +3 -3
  41. package/dist/src/history/claude.d.ts +16 -0
  42. package/dist/src/history/claude.js +336 -0
  43. package/dist/src/history/codex-transcript.d.ts +39 -0
  44. package/dist/src/history/codex-transcript.js +315 -0
  45. package/dist/src/history/codex.d.ts +8 -0
  46. package/dist/src/history/codex.js +238 -0
  47. package/dist/src/history/corpus.d.ts +35 -0
  48. package/dist/src/history/corpus.js +54 -0
  49. package/dist/src/history/history.d.ts +4 -8
  50. package/dist/src/history/history.js +3 -11
  51. package/dist/src/history/local.d.ts +17 -0
  52. package/dist/src/history/local.js +101 -0
  53. package/dist/src/history/pi.d.ts +36 -0
  54. package/dist/src/history/pi.js +202 -0
  55. package/dist/src/history/query.d.ts +15 -5
  56. package/dist/src/history/query.js +42 -13
  57. package/dist/src/index.d.ts +6 -3
  58. package/dist/src/index.js +6 -4
  59. package/dist/src/notes/address.d.ts +8 -8
  60. package/dist/src/notes/address.js +13 -13
  61. package/dist/src/notes/errors.d.ts +1 -1
  62. package/dist/src/notes/frontmatter.js +2 -2
  63. package/dist/src/notes/index.d.ts +1 -1
  64. package/dist/src/notes/index.js +1 -1
  65. package/dist/src/notes/paths.d.ts +6 -6
  66. package/dist/src/notes/paths.js +9 -9
  67. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  68. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  69. package/dist/src/notes/store.d.ts +4 -4
  70. package/dist/src/notes/store.js +55 -52
  71. package/dist/src/tools/dream.d.ts +21 -3
  72. package/dist/src/tools/dream.js +54 -16
  73. package/dist/src/tools/history.d.ts +7 -19
  74. package/dist/src/tools/history.js +80 -93
  75. package/dist/src/tools/notes-context.d.ts +10 -0
  76. package/dist/src/tools/notes-context.js +27 -0
  77. package/dist/src/tools/notes.d.ts +69 -20
  78. package/dist/src/tools/notes.js +40 -31
  79. package/dist/test/boot.integration.test.js +2 -3
  80. package/dist/test/claude-history.test.js +47 -34
  81. package/dist/test/claude-mod.test.js +96 -50
  82. package/dist/test/codex-history.test.js +4 -10
  83. package/dist/test/codex-plugin.test.js +50 -12
  84. package/dist/test/context-edit-budget.test.js +121 -0
  85. package/dist/test/dependencies.test.js +73 -6
  86. package/dist/test/dream-tools.test.js +153 -8
  87. package/dist/test/dsh.test.js +88 -19
  88. package/dist/test/helpers/dsh.d.ts +4 -1
  89. package/dist/test/helpers/dsh.js +20 -4
  90. package/dist/test/helpers/extension.d.ts +5 -1
  91. package/dist/test/helpers/extension.js +33 -2
  92. package/dist/test/helpers/history-corpus.d.ts +7 -0
  93. package/dist/test/helpers/history-corpus.js +26 -0
  94. package/dist/test/history-corpus.test.js +307 -0
  95. package/dist/test/history.integration.test.js +40 -48
  96. package/dist/test/host-neutral.test.js +20 -33
  97. package/dist/test/model-facing-text.test.js +14 -8
  98. package/dist/test/notes-cwd.test.d.ts +1 -0
  99. package/dist/test/notes-cwd.test.js +114 -0
  100. package/dist/test/notes-library.test.js +4 -4
  101. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  102. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  103. package/dist/test/notes.integration.test.js +73 -24
  104. package/dist/test/notes.test.js +51 -21
  105. package/dist/test/pi-render.test.js +33 -1
  106. package/dist/test/project-namespace.test.d.ts +1 -0
  107. package/dist/test/project-namespace.test.js +324 -0
  108. package/docs/architecture.md +19 -12
  109. package/docs/claude-code-mod.md +7 -5
  110. package/docs/codex.md +6 -6
  111. package/docs/dsh.md +9 -9
  112. package/docs/history-sessions.md +52 -0
  113. package/docs/notes-library.md +9 -5
  114. package/docs/skills.md +3 -3
  115. package/docs/tool-results.md +14 -8
  116. package/package.json +4 -6
  117. package/playbook.md +6 -6
  118. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  119. package/plugins/claude/dist/claude/helper.js +2164 -1341
  120. package/plugins/claude/hooks/register.ts +19 -11
  121. package/plugins/claude/playbook.md +6 -6
  122. package/plugins/claude/skills/memory/SKILL.md +9 -7
  123. package/plugins/claude/src/helper.ts +22 -25
  124. package/plugins/claude/src/history.ts +3 -257
  125. package/plugins/claude/src/text.ts +0 -1
  126. package/plugins/codex/README.md +1 -1
  127. package/plugins/codex/dist/codex/notesoup.js +1582 -969
  128. package/plugins/codex/src/history.ts +3 -193
  129. package/plugins/codex/src/hooks.ts +1 -1
  130. package/plugins/codex/src/identity.ts +3 -3
  131. package/plugins/codex/src/mcp.ts +9 -8
  132. package/plugins/codex/src/text.ts +2 -2
  133. package/plugins/codex/src/transcript.ts +3 -275
  134. package/plugins/dsh/engine.ts +2 -2
  135. package/plugins/dsh/history.ts +17 -0
  136. package/plugins/dsh/tools.ts +12 -12
  137. package/plugins/dsh/window.ts +8 -3
  138. package/plugins/paseo/OVERVIEW.md +4 -4
  139. package/plugins/paseo/README.md +1 -1
  140. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  141. package/plugins/paseo/client/markdown.tsx +159 -0
  142. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  143. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  144. package/plugins/paseo/client/paper-card.tsx +8 -19
  145. package/plugins/paseo/client/paper-palette.ts +40 -0
  146. package/plugins/paseo/client/sticky-card.tsx +6 -4
  147. package/plugins/paseo/package.json +3 -0
  148. package/plugins/paseo/paseo-plugin.json +2 -2
  149. package/plugins/paseo/shared/notes-op.ts +13 -9
  150. package/plugins/paseo/test/notes-op.test.ts +52 -73
  151. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  152. package/plugins/pi/history-tools.ts +11 -5
  153. package/plugins/pi/history.ts +8 -157
  154. package/plugins/pi/notes/tools.ts +8 -6
  155. package/plugins/pi/render.ts +6 -4
  156. package/plugins/pi/runtime.ts +2 -2
  157. package/plugins/pi/window.ts +22 -7
  158. package/skills/memory/SKILL.md +9 -7
  159. package/src/boot/render.ts +10 -13
  160. package/src/boot/snapshot.ts +20 -20
  161. package/src/boot/text.ts +18 -10
  162. package/src/dream/git.ts +7 -24
  163. package/src/dream/lock.ts +3 -3
  164. package/src/history/claude.ts +286 -0
  165. package/src/history/codex-transcript.ts +276 -0
  166. package/src/history/codex.ts +193 -0
  167. package/src/history/corpus.ts +69 -0
  168. package/src/history/history.ts +5 -12
  169. package/src/history/local.ts +93 -0
  170. package/src/history/pi.ts +199 -0
  171. package/src/history/query.ts +45 -15
  172. package/src/index.ts +8 -5
  173. package/src/notes/address.ts +13 -13
  174. package/src/notes/errors.ts +1 -1
  175. package/src/notes/frontmatter.ts +2 -2
  176. package/src/notes/index.ts +1 -1
  177. package/src/notes/paths.ts +9 -9
  178. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  179. package/src/notes/store.ts +61 -58
  180. package/src/tools/dream.ts +63 -16
  181. package/src/tools/history.ts +71 -101
  182. package/src/tools/notes-context.ts +29 -0
  183. package/src/tools/notes.ts +39 -29
  184. package/dist/test/project-home.test.js +0 -134
  185. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  186. /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
@@ -5,6 +5,7 @@ import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
5
5
  import { prefixFit, TOOL_OUTPUT_LIMIT } from "./output.js";
6
6
  import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
7
7
  import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
8
+ import { notesIdentityForCall } from "./notes-context.js";
8
9
  const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
9
10
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
10
11
  description: "(optional) Who wrote it: user, self, or external. Omit to keep the existing origin; new notes default to self.",
@@ -12,9 +13,10 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
12
13
  const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
13
14
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
14
15
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
15
- const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current homes.");
16
- const QUERY_HOMES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared homes; `**` searches all homes, `@sessions/*/**` searches all sessions.";
17
- 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.";
16
+ const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current notebooks.");
17
+ 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." }));
18
+ const QUERY_NAMESPACES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions.";
19
+ 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.";
18
20
  /**
19
21
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
20
22
  * Convert expected refusals; unexpected errors propagate unchanged.
@@ -101,14 +103,19 @@ function renderIdentity(identity) {
101
103
  text += `\n Same-basename projects: ${identity.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
102
104
  return text;
103
105
  }
104
- const ProjectReceiptSchema = {
106
+ /** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
107
+ export const ProjectReceiptSchema = {
105
108
  project_root: Type.Optional(Type.String()),
106
109
  project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
107
110
  };
108
- const ListedFileSchema = Type.Object({
111
+ /** One note identity, shared by every receipt: read/list/search rows and all mutations alike. */
112
+ export const NoteIdentitySchema = {
109
113
  address: Type.String(),
110
114
  project_key: Type.Optional(Type.String()),
111
115
  ...ProjectReceiptSchema,
116
+ };
117
+ const ListedFileSchema = Type.Object({
118
+ ...NoteIdentitySchema,
112
119
  updated_at: Type.String(),
113
120
  last_accessed: Type.String(),
114
121
  crumpled_at: Type.Optional(Type.String()),
@@ -124,24 +131,20 @@ const SearchedFileSchema = Type.Object({
124
131
  }, { additionalProperties: false });
125
132
  const SnapshotSchema = {
126
133
  more: Type.Integer({ description: "How many more were left out." }),
127
- homes_unavailable: Type.Array(Type.String()),
134
+ namespaces_unavailable: Type.Array(Type.String()),
128
135
  };
129
136
  export const NotesWriteDataSchema = Type.Object({
130
- address: Type.String(),
131
- project_key: Type.Optional(Type.String()),
137
+ ...NoteIdentitySchema,
132
138
  outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
133
139
  }, { additionalProperties: false });
134
140
  export const NotesUpdateDataSchema = Type.Object({
135
- address: Type.String(),
136
- project_key: Type.Optional(Type.String()),
141
+ ...NoteIdentitySchema,
137
142
  change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
138
143
  diff: Type.String(),
139
144
  rename_from: Type.Optional(Type.String()),
140
145
  }, { additionalProperties: false });
141
146
  export const NotesReadDataSchema = Type.Object({
142
- address: Type.String(),
143
- project_key: Type.Optional(Type.String()),
144
- ...ProjectReceiptSchema,
147
+ ...NoteIdentitySchema,
145
148
  metadata: NoteMetadataSchema,
146
149
  ...TextWindowSchema.properties,
147
150
  }, { additionalProperties: false });
@@ -156,7 +159,7 @@ export const NotesSearchDataSchema = Type.Object({
156
159
  /** Keep identities intact. Only search previews may shrink to make the first row fit. */
157
160
  export function snapshot(rows, limit, status, renderData, shrink) {
158
161
  const files = [];
159
- const data = (selected) => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
162
+ const data = (selected) => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
160
163
  const render = (outcome) => renderOutcome(outcome, renderData);
161
164
  const fits = (item) => fitsResult(success(data([...files, item])), render);
162
165
  for (const item of rows.slice(0, limit)) {
@@ -174,12 +177,12 @@ export function snapshot(rows, limit, status, renderData, shrink) {
174
177
  break;
175
178
  }
176
179
  const outcome = success(data(files));
177
- 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.`);
180
+ 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.`);
178
181
  }
179
182
  export function listedFile(row, identity) {
180
183
  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 }) };
181
184
  }
182
- export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
185
+ export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, cwd: CWD_PARAMETER }, { additionalProperties: false });
183
186
  function renderWriteData(data) {
184
187
  return `${data.outcome} ${renderIdentity(data)}`;
185
188
  }
@@ -187,8 +190,9 @@ export const notesWrite = {
187
190
  name: "notes_write", label: "Notes write",
188
191
  description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
189
192
  parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
190
- async execute(params, identity) {
193
+ async execute(params, context) {
191
194
  try {
195
+ const identity = notesIdentityForCall(context, params.cwd);
192
196
  const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin });
193
197
  return success({ ...noteIdentity(identity, params.address), outcome });
194
198
  }
@@ -205,6 +209,7 @@ export const notesUpdateParameters = Type.Object({
205
209
  crumpled: CRUMPLED_PARAMETER,
206
210
  replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
207
211
  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." })),
212
+ cwd: CWD_PARAMETER,
208
213
  }, { additionalProperties: false });
209
214
  function renderUpdateData(data) {
210
215
  const head = data.rename_from === undefined
@@ -233,10 +238,11 @@ function boundedUpdate(data) {
233
238
  }
234
239
  export const notesUpdate = {
235
240
  name: "notes_update", label: "Notes update",
236
- 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}`,
241
+ 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}`,
237
242
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
238
- async execute(params, identity, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
243
+ async execute(params, context, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
239
244
  try {
245
+ const identity = notesIdentityForCall(context, params.cwd);
240
246
  const store = createNotesStore(identity);
241
247
  // Empty filler is not a request: models that pass every parameter get the edit path.
242
248
  const renameTo = params.rename_to === "" ? undefined : params.rename_to;
@@ -252,7 +258,7 @@ export const notesUpdate = {
252
258
  },
253
259
  render: renderUpdate,
254
260
  };
255
- export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
261
+ export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
256
262
  function renderReadData(data) {
257
263
  return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
258
264
  }
@@ -260,8 +266,9 @@ export const notesRead = {
260
266
  name: "notes_read", label: "Notes read",
261
267
  description: `Read a note. ${ADDRESS_DESCRIPTION}`,
262
268
  parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
263
- async execute(params, identity) {
269
+ async execute(params, context) {
264
270
  try {
271
+ const identity = notesIdentityForCall(context, params.cwd);
265
272
  const note = await createNotesStore(identity).read(params.address);
266
273
  const resolved = noteIdentity(identity, params.address);
267
274
  if (!note)
@@ -279,7 +286,7 @@ export const notesRead = {
279
286
  },
280
287
  render: (result) => renderOutcome(result, renderReadData),
281
288
  };
282
- export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
289
+ export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
283
290
  export function renderListData(data) {
284
291
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
285
292
  for (const file of data.files) {
@@ -287,16 +294,17 @@ export function renderListData(data) {
287
294
  }
288
295
  if (data.more > 0)
289
296
  lines.push(`${data.more} more matching notes omitted; narrow with glob`);
290
- for (const home of data.homes_unavailable)
291
- lines.push(`${home} could not be read`);
297
+ for (const namespace of data.namespaces_unavailable)
298
+ lines.push(`${namespace} could not be read`);
292
299
  return lines.join("\n");
293
300
  }
294
301
  export const notesList = {
295
302
  name: "notes_list", label: "Notes list",
296
- description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_HOMES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
303
+ description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
297
304
  parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
298
- async execute(params, identity) {
305
+ async execute(params, context) {
299
306
  try {
307
+ const identity = notesIdentityForCall(context, params.cwd);
300
308
  const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
301
309
  return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
302
310
  }
@@ -306,7 +314,7 @@ export const notesList = {
306
314
  },
307
315
  render: (result) => renderOutcome(result, renderListData),
308
316
  };
309
- 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 });
317
+ 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 });
310
318
  function renderSearchData(data) {
311
319
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
312
320
  for (const file of data.files) {
@@ -316,8 +324,8 @@ function renderSearchData(data) {
316
324
  }
317
325
  if (data.more > 0)
318
326
  lines.push(`${data.more} more matching notes omitted; narrow with glob`);
319
- for (const home of data.homes_unavailable)
320
- lines.push(`${home} could not be read`);
327
+ for (const namespace of data.namespaces_unavailable)
328
+ lines.push(`${namespace} could not be read`);
321
329
  return lines.join("\n");
322
330
  }
323
331
  /** A shortened match line still ends with a marker, so its own text says it was cut. */
@@ -343,10 +351,11 @@ function fitSearchFile(file, fits) {
343
351
  }
344
352
  export const notesSearch = {
345
353
  name: "notes_search", label: "Notes search",
346
- 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}`,
354
+ 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}`,
347
355
  parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
348
- async execute(params, identity) {
356
+ async execute(params, context) {
349
357
  try {
358
+ const identity = notesIdentityForCall(context, params.cwd);
350
359
  const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
351
360
  const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => ({
352
361
  ...listedFile(row, identity),
@@ -181,7 +181,7 @@ test("an aborted async boot repair emits no boot, continuation, or incomplete-no
181
181
  controller.abort();
182
182
  await pending;
183
183
  assert.equal(captured.sent.length, 0, "aborted snapshot work cannot append the reset boot or continuation");
184
- assert.equal(noticesOf(ctx).some((notice) => notice.message.includes("went missing")), false, "aborted snapshot work cannot notify about missing homes");
184
+ assert.equal(noticesOf(ctx).some((notice) => notice.message.includes("went missing")), false, "aborted snapshot work cannot notify about missing notebooks");
185
185
  assert.equal(sessionManager.getBranch().some((entry) => entry.type === "custom_message" && [BOOT_TYPE, CONTINUATION_TYPE].includes(entry.customType)), false);
186
186
  });
187
187
  test("a marker tail with only metadata repairs its missing boot and continuation without moving the boundary", async () => {
@@ -301,8 +301,7 @@ test("off preserves an existing marker window and still cancels native compactio
301
301
  assert.deepEqual(before, { cancel: true });
302
302
  const projected = await runContextWithSystemHook(captured, ctx, sessionManager.buildSessionContext().messages);
303
303
  assert.equal(JSON.stringify(projected?.messages ?? []).includes("old context must stay hidden"), false);
304
- const windows = resultData(await call(captured, "history_windows", {}, ctx));
305
- assert.equal(windows.windows.at(-1)?.window_id, windowId);
304
+ assert.equal(historyFromSession(ctx).windows.at(-1)?.windowId, windowId);
306
305
  });
307
306
  test("empty_brain uses one turn boundary and never calls ctx.compact", async () => {
308
307
  const sessionManager = manager();
@@ -8,9 +8,10 @@ import { renderBootBlock } from "../src/boot/render.js";
8
8
  import { unavailableNotesSnapshot } from "../src/boot/snapshot.js";
9
9
  import { DEFAULT_BOOT_TOOL_NAMES } from "../src/boot/text.js";
10
10
  import { allItems, eventDocument } from "../src/history/history.js";
11
- import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
11
+ import { historyList, historyRead } from "../src/tools/history.js";
12
12
  import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
13
13
  import { dispatch } from "../plugins/claude/src/helper.js";
14
+ import { writePiTranscript } from "./helpers/history-corpus.js";
14
15
  const sessionId = "synthetic-session";
15
16
  function row(uuid, parentUuid, type, content, extra = {}) {
16
17
  return { uuid, parentUuid, type, sessionId, timestamp: "2026-01-01T00:00:00Z", isSidechain: false,
@@ -30,6 +31,25 @@ const bootText = (ordinal, spelling = "legacy") => spelling === "legacy"
30
31
  function compact(uuid, logical, metadata = {}) {
31
32
  return row(uuid, null, "system", "Conversation compacted", { subtype: "compact_boundary", logicalParentUuid: logical, compactMetadata: metadata });
32
33
  }
34
+ test("Claude helper resolves foreign history without requiring a current append head/path", async (t) => {
35
+ const home = mkdtempSync(join(tmpdir(), "claude-cross-harness-"));
36
+ t.after(() => rmSync(home, { recursive: true, force: true }));
37
+ const pi = join(home, "sessions");
38
+ await writePiTranscript(pi, "foreign-pi");
39
+ const identity = { home: join(home, "notes"), sessionId, cwd: home, agent: "claude", model: "claude" };
40
+ const options = { roots: { pi, claude: null, codex: null }, env: {} };
41
+ const invoke = (tool, params) => dispatch({ op: "tool", tool, params, identity }, options);
42
+ const read = await invoke("history_read", { session: "pi:foreign", seq: 1 });
43
+ assert.ok(read.ok);
44
+ assert.match(read.text, /^session pi:foreign-pi \| seq 1 \| user/);
45
+ assert.match(read.text, /foreign needle/);
46
+ const list = await invoke("history_list", { session: "pi:*", query: "needle" });
47
+ assert.ok(list.ok);
48
+ assert.match(list.text, /session pi:foreign-pi/);
49
+ const invalid = await invoke("history_read", { session: "*", seq: 1 });
50
+ assert.equal(invalid.ok, false);
51
+ assert.match(invalid.text, /invalid_session/);
52
+ });
33
53
  test("Claude append and result arrival preserve call addresses and use the shared paired read", async () => {
34
54
  const rows = [user("u", null, "run tools"), assistant("a", "u", [{ type: "thinking", thinking: "private thought" }, { type: "text", text: "working" }, call("one"), call("two")])];
35
55
  const pending = project(rows, "a");
@@ -62,7 +82,7 @@ test("Claude dialogue paging skips tool/thinking envelopes without losing array
62
82
  compact("boundary", "last"), row("boot", "boundary", "user", bootText(1))];
63
83
  const projection = project(rows, "boot");
64
84
  assert.equal(projection.highestSeq, 10);
65
- const listed = await historyList.execute({ window_id: "@previous", roles: ["user", "assistant"], limit: 3 }, projection);
85
+ const listed = await historyList.execute({ before_seq: 9, roles: ["user", "assistant"], limit: 3 }, projection);
66
86
  assert.ok(listed.ok);
67
87
  assert.deepEqual(listed.data.items.map((item) => "seq" in item ? [item.seq, item.content] : []), [[1, "human question"], [2, "assistant answer"], [8, "human followup"]]);
68
88
  const read = await historyRead.execute({ seq: 2 }, projection);
@@ -156,12 +176,10 @@ test("Claude native compaction and reset keep pre-reset history, preserved rewri
156
176
  assert.equal(allItems(projection).find((event) => event.text === "before first reset")?.windowId, `claude:${sessionId}:0`);
157
177
  assert.equal(allItems(projection).find((event) => event.text === "after first reset")?.windowId, `claude:${sessionId}:1`);
158
178
  assert.equal(projection.highestSeq, 8);
159
- const previous = await historyList.execute({ window_id: "@previous", roles: ["assistant"] }, projection);
160
- assert.ok(previous.ok);
161
- assert.deepEqual(previous.data.items.map((item) => "content" in item ? item.content : ""), ["after first reset"]);
162
- const windows = await historyWindows.execute({}, projection, sessionId);
163
- assert.ok(windows.ok);
164
- assert.equal(windows.data.windows[0]?.first_seq, 1);
179
+ const earlier = await historyList.execute({ after_seq: 4, before_seq: 6, roles: ["assistant"] }, projection);
180
+ assert.ok(earlier.ok);
181
+ assert.deepEqual(earlier.data.items.map((item) => "content" in item ? item.content : ""), ["after first reset"]);
182
+ assert.equal(projection.windows[0]?.items[0]?.seq, 1);
165
183
  assert.deepEqual(project(rows, "latest"), projection, "reload does not need an in-memory seq cache");
166
184
  });
167
185
  test("Claude reset crosses native turn_duration graph metadata with no message content", async () => {
@@ -172,9 +190,8 @@ test("Claude reset crosses native turn_duration graph metadata with no message c
172
190
  assert.equal(projection.highestSeq, 5, "duration metadata does not allocate a message address");
173
191
  assert.equal(projection.windows.length, 2);
174
192
  assert.ok(allItems(projection).some((event) => event.text === "marker before reset"));
175
- assert.ok((await historyList.execute({ window_id: "@previous" }, projection)).ok);
193
+ assert.ok((await historyList.execute({ before_seq: 3 }, projection)).ok);
176
194
  assert.ok((await historyRead.execute({ seq: 2 }, projection)).ok);
177
- assert.ok((await historyWindows.execute({}, projection, sessionId)).ok);
178
195
  });
179
196
  test("Claude api_error retry metadata keeps compact ancestry without allocating seq or exposing internals", async () => {
180
197
  const retry = { type: "system", subtype: "api_error", uuid: "retry", parentUuid: "old", sessionId, isSidechain: false,
@@ -191,11 +208,10 @@ test("Claude api_error retry metadata keeps compact ancestry without allocating
191
208
  assert.deepEqual(project([...prefix, { ...rows[3], logicalParentUuid: "old" }, ...rows.slice(4)], "after"), projection, "metadata leaves all addresses and windows unchanged");
192
209
  assert.doesNotMatch(allItems(projection).map(eventDocument).join("\n"), /PRIVATE_RETRY_PAYLOAD|ECONNRESET|request_retry/);
193
210
  assert.ok((await historyList.execute({}, projection)).ok);
194
- const previous = await historyList.execute({ window_id: "@previous" }, projection);
195
- assert.ok(previous.ok);
196
- assert.match(JSON.stringify(previous), /before retry|finished turn/);
211
+ const earlier = await historyList.execute({ before_seq: 3 }, projection);
212
+ assert.ok(earlier.ok);
213
+ assert.match(JSON.stringify(earlier), /before retry|finished turn/);
197
214
  assert.ok((await historyRead.execute({ seq: 2 }, projection)).ok);
198
- assert.ok((await historyWindows.execute({}, projection, sessionId)).ok);
199
215
  assert.deepEqual(project(rows, "after"), projection, "reload preserves seq");
200
216
  assert.deepEqual(project([...prefix, { ...retry, subtype: "future_metadata" }, ...rows.slice(3)], "after"), projection, "metadata does not depend on a subtype whitelist");
201
217
  const withBody = project([...prefix, { ...retry, content: "visible system notice" }], "retry");
@@ -266,7 +282,7 @@ test("Claude gaps retain only confirmed suffixes, keep pairing/seqs, and disappe
266
282
  assert.equal(recovered.pairedResults.get(6), 4);
267
283
  assert.ok(!recovered.branchSeqs.has(2) && !recovered.branchSeqs.has(7), "recovery never selects either sibling");
268
284
  });
269
- test("Claude helper reports gaps on list/read/windows and re-anchors reset state only with a retained boot", async (t) => {
285
+ test("Claude helper reports gaps on list/read and re-anchors reset state only with a retained boot", async (t) => {
270
286
  const root = mkdtempSync(join(tmpdir(), "claude-history-gap-"));
271
287
  t.after(() => rmSync(root, { recursive: true, force: true }));
272
288
  const transcriptPath = join(root, "transcript.jsonl");
@@ -277,7 +293,7 @@ test("Claude helper reports gaps on list/read/windows and re-anchors reset state
277
293
  const history = { sessionId, transcriptPath, headUuid: "suffix" };
278
294
  const invoke = (tool, params = {}) => dispatch({ op: "tool", tool, params, identity, history });
279
295
  writeFileSync(transcriptPath, jsonl(rows));
280
- for (const [tool, params] of [["history_list", {}], ["history_read", { seq: 2 }], ["history_windows", {}],
296
+ for (const [tool, params] of [["history_list", {}], ["history_read", { seq: 2 }],
281
297
  ["history_list", { query: "no matches" }], ["history_read", { seq: 99 }]]) {
282
298
  const response = await invoke(tool, params);
283
299
  assert.match(response.text, /history is incomplete: missing ancestor UUID\(s\): "missing"/);
@@ -287,8 +303,8 @@ test("Claude helper reports gaps on list/read/windows and re-anchors reset state
287
303
  const excluded = await invoke("history_read", { seq: 1 });
288
304
  assert.equal(excluded.ok, false);
289
305
  assert.match(excluded.text, /outside the confirmed selected history/);
290
- assert.match((await invoke("history_list", { window_id: "@previous" })).text, /Cannot resolve "@previous"/);
291
- await assert.rejects(invoke("history_list", { window_id: "@previous", before_seq: "invalid" }), /invalid history_list parameters: before_seq/);
306
+ await assert.rejects(invoke("history_list", { window_id: "anything" }), /invalid history_list parameters:.*window_id/);
307
+ await assert.rejects(invoke("history_list", { before_seq: "invalid" }), /invalid history_list parameters: before_seq/);
292
308
  await assert.rejects(invoke("history_read", { seq: "2" }), /invalid history_read parameters: seq/);
293
309
  await assert.rejects(dispatch({ op: "history_state", identity, history }), /cannot determine the current window ordinal/);
294
310
  // A native boundary alone cannot count the missing earlier resets. A quoted
@@ -304,21 +320,21 @@ test("Claude helper reports gaps on list/read/windows and re-anchors reset state
304
320
  assert.equal(anchored.currentWindowOrdinal, 8);
305
321
  assert.deepEqual(anchored.windows.map((window) => window.windowId), [`claude:${sessionId}:8`, `claude:${sessionId}:unknown:missing`], "unknown segments are listed separately, not inserted into the numbered timeline");
306
322
  assert.deepEqual(await dispatch({ op: "history_state", identity, history }), { window: 8 }, "never windows.length - 1");
307
- assert.match((await invoke("history_read", { seq: 6 })).text, /window claude:synthetic-session:8/);
308
- assert.match((await invoke("history_windows")).text, /history is incomplete/);
309
- assert.match((await invoke("history_list", { window_id: "@previous" })).text, /Cannot resolve "@previous"/);
323
+ const anchoredRead = await invoke("history_read", { seq: 6 });
324
+ assert.match(anchoredRead.text, /history is incomplete/);
325
+ assert.match(anchoredRead.text, /seq 6 \| user\n/);
310
326
  rows.push(compact("next", "after"), row("next-boot", "next", "user", bootText(9)), user("latest", "next-boot", "latest"));
311
327
  writeFileSync(transcriptPath, jsonl(rows));
312
328
  history.headUuid = "latest";
313
- const previous = await invoke("history_list", { window_id: "@previous" });
314
- assert.ok(previous.ok);
315
- assert.match(previous.text, /after anchored reset/);
316
- assert.doesNotMatch(previous.text, /confirmed suffix/);
329
+ const earlier = await invoke("history_list", { after_seq: 5, before_seq: 7 });
330
+ assert.ok(earlier.ok);
331
+ assert.match(earlier.text, /after anchored reset/);
332
+ assert.doesNotMatch(earlier.text, /confirmed suffix/);
317
333
  // Restore the record as a supported message: warning disappears on the next
318
334
  // read, without any in-memory repair state or changed existing addresses.
319
335
  rows.push(user("missing", "prefix", "recovered ancestor"));
320
336
  writeFileSync(transcriptPath, jsonl(rows));
321
- assert.doesNotMatch((await invoke("history_windows")).text, /history is incomplete|:unknown:/);
337
+ assert.doesNotMatch((await invoke("history_list")).text, /history is incomplete/);
322
338
  assert.deepEqual(await dispatch({ op: "history_state", identity, history }), { window: 9 });
323
339
  });
324
340
  test("Claude gap windows sort by confirmed ordinal despite forward references, without duplicating paired output", async () => {
@@ -327,9 +343,7 @@ test("Claude gap windows sort by confirmed ordinal despite forward references, w
327
343
  assistant("call", "boot8", [call("t")]), compact("boundary9", "call"),
328
344
  row("boot9", "boundary9", "user", bootText(9)), row("result", "notice", "user", [result("t", "output")])];
329
345
  const projection = project(rows, "result");
330
- const windows = await historyWindows.execute({}, projection, sessionId);
331
- assert.ok(windows.ok);
332
- assert.deepEqual(windows.data.windows.map((window) => window.window_id), [8, 9].map((ordinal) => `claude:${sessionId}:${ordinal}`));
346
+ assert.deepEqual(projection.windows.map((window) => window.windowId), [8, 9].map((ordinal) => `claude:${sessionId}:${ordinal}`));
333
347
  assert.equal(projection.currentWindowOrdinal, 9);
334
348
  assert.equal(projection.highestSeq, 8);
335
349
  assert.deepEqual(allItems(projection).filter((event) => event.role === "tool").map((event) => [event.seq, event.text]), [[4, "output"]]);
@@ -374,16 +388,15 @@ test("Claude helper history tools reuse shared schemas, outcomes and text render
374
388
  const identity = { home: join(root, "notes"), sessionId, cwd: root, agent: "claude", model: "claude" };
375
389
  const history = { sessionId, transcriptPath, headUuid: "r" };
376
390
  const projection = await readClaudeHistory(history);
377
- const operations = [historyList, historyRead, historyWindows];
391
+ const operations = [historyList, historyRead];
378
392
  for (const operation of operations) {
379
393
  const params = operation.name === "history_read" ? { seq: 3 } : {};
380
394
  const actual = await dispatch({ op: "tool", tool: operation.name, params, identity, history });
381
395
  const expected = operation.name === "history_read" ? { text: historyRead.render(await historyRead.execute({ seq: 3 }, projection)), ok: true }
382
- : operation.name === "history_list" ? { text: historyList.render(await historyList.execute({}, projection)), ok: true }
383
- : { text: historyWindows.render(await historyWindows.execute({}, projection, sessionId)), ok: true };
396
+ : { text: historyList.render(await historyList.execute({}, projection)), ok: true };
384
397
  assert.deepEqual(actual, expected);
385
398
  }
386
399
  assert.deepEqual(await dispatch({ op: "history_state", identity, history }), { window: 0 });
387
- await assert.rejects(dispatch({ op: "tool", tool: "history_windows", params: {}, identity }), /transcript_path is unavailable/);
388
- await assert.rejects(dispatch({ op: "tool", tool: "history_windows", params: {}, identity, history: { ...history, sessionId: "other" } }), /different session/);
400
+ await assert.rejects(dispatch({ op: "tool", tool: "history_list", params: {}, identity }), /transcript_path is unavailable/);
401
+ await assert.rejects(dispatch({ op: "tool", tool: "history_list", params: {}, identity, history: { ...history, sessionId: "other" } }), /different session/);
389
402
  });