notesoup 0.59.2 → 0.60.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 (78) hide show
  1. package/README.md +3 -17
  2. package/dist/plugins/claude/src/helper.js +1 -2
  3. package/dist/plugins/codex/src/mcp.js +1 -2
  4. package/dist/plugins/dsh/tools.js +1 -2
  5. package/dist/plugins/pi/notes/tools.d.ts +1 -1
  6. package/dist/plugins/pi/notes/tools.js +2 -3
  7. package/dist/src/dream/git.js +12 -13
  8. package/dist/src/history/history.d.ts +10 -11
  9. package/dist/src/history/history.js +8 -19
  10. package/dist/src/history/query.d.ts +3 -14
  11. package/dist/src/history/query.js +73 -85
  12. package/dist/src/index.d.ts +1 -1
  13. package/dist/src/index.js +1 -1
  14. package/dist/src/notes/address.js +3 -3
  15. package/dist/src/notes/project-namespace.js +39 -73
  16. package/dist/src/notes/store.d.ts +2 -4
  17. package/dist/src/notes/store.js +1 -2
  18. package/dist/src/sqlite-lock.d.ts +2 -0
  19. package/dist/src/sqlite-lock.js +17 -0
  20. package/dist/src/tools/dream.d.ts +2 -4
  21. package/dist/src/tools/dream.js +15 -16
  22. package/dist/src/tools/history.d.ts +4 -6
  23. package/dist/src/tools/history.js +69 -29
  24. package/dist/src/tools/notes.d.ts +18 -78
  25. package/dist/src/tools/notes.js +39 -50
  26. package/dist/src/tools/schema.d.ts +0 -1
  27. package/dist/src/tools/schema.js +0 -1
  28. package/dist/test/claude-history.test.js +5 -6
  29. package/dist/test/claude-mod.test.js +6 -7
  30. package/dist/test/codex-history.test.js +1 -1
  31. package/dist/test/codex-plugin.test.js +1 -2
  32. package/dist/test/dependencies.test.js +2 -2
  33. package/dist/test/dream-tools.test.js +42 -14
  34. package/dist/test/dsh.test.js +2 -2
  35. package/dist/test/history-corpus.test.js +21 -36
  36. package/dist/test/history-summary-cache.test.js +3 -3
  37. package/dist/test/history.integration.test.js +53 -106
  38. package/dist/test/host-neutral.test.js +1 -1
  39. package/dist/test/note-policy.test.js +5 -5
  40. package/dist/test/notes-cwd.test.js +5 -5
  41. package/dist/test/notes-query-namespaces.test.js +2 -6
  42. package/dist/test/notes.integration.test.js +33 -42
  43. package/dist/test/notes.test.js +12 -14
  44. package/dist/test/project-namespace.test.js +36 -91
  45. package/docs/architecture.md +3 -3
  46. package/docs/claude-code-mod.md +2 -2
  47. package/docs/codex.md +1 -1
  48. package/docs/dsh.md +2 -2
  49. package/docs/history-sessions.md +8 -9
  50. package/docs/notes-library.md +9 -3
  51. package/docs/skills.md +2 -6
  52. package/docs/tool-results.md +12 -6
  53. package/package.json +1 -1
  54. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  55. package/plugins/claude/dist/claude/helper.js +212 -211
  56. package/plugins/claude/skills/memory/SKILL.md +6 -6
  57. package/plugins/claude/src/helper.ts +1 -2
  58. package/plugins/codex/README.md +1 -1
  59. package/plugins/codex/dist/codex/notesoup.js +211 -210
  60. package/plugins/codex/src/mcp.ts +1 -2
  61. package/plugins/dsh/tools.ts +1 -2
  62. package/plugins/pi/notes/tools.ts +2 -3
  63. package/skills/memory/SKILL.md +6 -6
  64. package/src/dream/git.ts +11 -11
  65. package/src/history/history.ts +11 -16
  66. package/src/history/query.ts +67 -99
  67. package/src/index.ts +1 -1
  68. package/src/notes/address.ts +2 -2
  69. package/src/notes/project-namespace.ts +37 -59
  70. package/src/notes/store.ts +3 -6
  71. package/src/sqlite-lock.ts +14 -0
  72. package/src/tools/dream.ts +15 -14
  73. package/src/tools/history.ts +60 -29
  74. package/src/tools/notes.ts +39 -54
  75. package/src/tools/schema.ts +0 -1
  76. package/dist/src/dream/lock.d.ts +0 -14
  77. package/dist/src/dream/lock.js +0 -29
  78. package/src/dream/lock.ts +0 -28
@@ -9,7 +9,7 @@ import { TOOL_OUTPUT_LIMIT } from "./output.js";
9
9
  import { failure, success } from "../result.js";
10
10
  import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
11
11
  import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
12
- import { nullableString, searchQuery } from "./schema.js";
12
+ import { searchQuery } from "./schema.js";
13
13
  import { notesIdentityForCall } from "./notes-context.js";
14
14
  const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
15
15
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
@@ -36,7 +36,7 @@ function withWarnings(text, data) {
36
36
  const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
37
37
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
38
38
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
39
- const GLOB_PARAMETER = nullableString("Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf · `MAP.md` that page in every notebook · `**` everything · `@sessions/*/**` every session.");
39
+ const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf · `MAP.md` that page in every notebook · `**` everything · `@sessions/*/**` every session." }));
40
40
  const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
41
41
  const ADDRESS_PARAMETER = Type.String({ description: "Which drawer the page sits in. `plan.md` — this session's desk, cleared when it ends. `@project/` this project's shelf · `@human/` your human's file · `@self/` your own notebook · `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` — someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
42
42
  /**
@@ -148,10 +148,6 @@ const MatchSchema = Type.Object({
148
148
  text: Type.String(),
149
149
  offset_chars: Type.Integer(),
150
150
  }, { additionalProperties: false });
151
- const SearchedFileSchema = Type.Object({
152
- ...ListedFileSchema.properties,
153
- matches: Type.Array(MatchSchema), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
154
- }, { additionalProperties: false });
155
151
  export const SnapshotSchema = {
156
152
  more: Type.Integer({ description: "How many more were left out." }),
157
153
  namespaces_unavailable: Type.Array(Type.String(), { description: "Unreadable notebooks or notes." }),
@@ -176,11 +172,10 @@ export const NotesReadDataSchema = Type.Object({
176
172
  ...TextWindowSchema.properties,
177
173
  }, { additionalProperties: false });
178
174
  export const NotesListDataSchema = Type.Object({
179
- files: Type.Array(ListedFileSchema),
180
- ...SnapshotSchema,
181
- }, { additionalProperties: false });
182
- export const NotesSearchDataSchema = Type.Object({
183
- files: Type.Array(SearchedFileSchema),
175
+ files: Type.Array(Type.Object({
176
+ ...ListedFileSchema.properties,
177
+ matches: Type.Optional(Type.Array(MatchSchema)), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
178
+ }, { additionalProperties: false })),
184
179
  ...SnapshotSchema,
185
180
  }, { additionalProperties: false });
186
181
  /** Keep identities intact. Only search previews may shrink to make the first row fit. */
@@ -296,42 +291,27 @@ export const notesRead = {
296
291
  },
297
292
  render: (result) => renderOutcome(result, renderReadData),
298
293
  };
299
- export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
294
+ export const notesListParameters = Type.Object({
295
+ glob: GLOB_PARAMETER,
296
+ query: Type.Optional(searchQuery()),
297
+ max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "How many hit lines per note at most; requires a query." })),
298
+ crumpled: CRUMPLED_LIST_PARAMETER,
299
+ limit: FILE_LIMIT_PARAMETER,
300
+ cwd: CWD_PARAMETER,
301
+ }, { additionalProperties: false });
300
302
  export function renderListData(data) {
301
303
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
302
304
  for (const file of data.files) {
303
- lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at}${file.last_accessed === undefined ? "" : ` | accessed ${file.last_accessed}`}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
305
+ const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
306
+ if (file.last_accessed !== undefined)
307
+ fields.push(`accessed ${file.last_accessed}`);
308
+ if (file.crumpled_at !== undefined)
309
+ fields.push(`crumpled ${file.crumpled_at}`);
310
+ if (file.matches)
311
+ fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
312
+ lines.push(fields.join(" | "));
304
313
  lines.push(...file.warnings.map(warning => ` ${warning}`));
305
- }
306
- if (data.more > 0)
307
- lines.push(`${data.more} more matching notes omitted; narrow with glob`);
308
- for (const namespace of data.namespaces_unavailable)
309
- lines.push(`${namespace} could not be read`);
310
- return lines.join("\n");
311
- }
312
- export const notesList = {
313
- name: "notes_list", label: "Notes list",
314
- description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile — narrow `glob`.",
315
- parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
316
- async execute(params, context) {
317
- try {
318
- const identity = notesIdentityForCall(context, params.cwd);
319
- const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
320
- return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
321
- }
322
- catch (error) {
323
- return failureOf(error);
324
- }
325
- },
326
- render: (result) => renderOutcome(result, renderListData),
327
- };
328
- 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: "How many hit lines per page at most." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
329
- function renderSearchData(data) {
330
- const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
331
- for (const file of data.files) {
332
- lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
333
- lines.push(...file.warnings.map(warning => ` ${warning}`));
334
- for (const match of file.matches)
314
+ for (const match of file.matches ?? [])
335
315
  lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
336
316
  }
337
317
  if (data.more > 0)
@@ -363,23 +343,32 @@ function fitSearchFile(file, fits) {
363
343
  const withText = (text) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
364
344
  return withText(prefixFit(first.text, text => fits(withText(text))));
365
345
  }
366
- export const notesSearch = {
367
- name: "notes_search", label: "Notes search",
368
- description: "Run a finger down every page for some text, case doesn't matter. Returns the lines it hits and where they sit; no query just lists the pages. One pass; `more` counts pages left on the pile — narrow `glob`.",
369
- parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
346
+ export const notesList = {
347
+ name: "notes_list", label: "Notes list",
348
+ description: "List or search notes, newest pages on top. A query matches literal text (ignoring case) and returns hit lines and read offsets. One pass; `more` counts pages left on the pile — narrow `glob`.",
349
+ parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
370
350
  async execute(params, context) {
371
351
  try {
352
+ const queries = searchQueries(params.query);
353
+ const { glob, crumpled, limit } = params;
354
+ if (!queries.length && params.max_matches_per_file !== undefined)
355
+ return failure("invalid_params", "`max_matches_per_file` requires a non-empty `query`.");
372
356
  const identity = notesIdentityForCall(context, params.cwd);
373
- const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
357
+ const store = createNotesStore(identity);
358
+ if (!queries.length) {
359
+ const { rows, status } = await store.listWithStatus({ glob, crumpled });
360
+ return snapshot(rows.map(row => listedFile(row, identity)), limit, status, renderListData);
361
+ }
362
+ const { rows, status } = await store.searchWithStatus(queries, { glob, crumpled });
374
363
  const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => keepMatches({
375
364
  ...listedFile(row, identity),
376
365
  matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
377
366
  }, params.max_matches_per_file));
378
- return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
367
+ return snapshot(files, limit, status, renderListData, fitSearchFile);
379
368
  }
380
369
  catch (error) {
381
370
  return failureOf(error);
382
371
  }
383
372
  },
384
- render: (result) => renderOutcome(result, renderSearchData),
373
+ render: (result) => renderOutcome(result, renderListData),
385
374
  };
@@ -1,5 +1,4 @@
1
1
  import { Type, type TSchema } from "typebox";
2
- export declare const nullableString: (description?: string) => Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
3
2
  export declare const historyRoles: () => Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
4
3
  /** First parameter violation; skip false subschemas so additionalProperties can name the field. */
5
4
  export declare function paramProblem(schema: TSchema, params: unknown): string;
@@ -1,7 +1,6 @@
1
1
  import { Type } from "typebox";
2
2
  import { Errors } from "typebox/value";
3
3
  import { HistoryRoleSchema } from "../history/history.js";
4
- export const nullableString = (description) => Type.Optional(Type.Union([Type.String(), Type.Null()], description === undefined ? {} : { description }));
5
4
  export const historyRoles = () => Type.Optional(Type.Array(HistoryRoleSchema, { minItems: 1, description: "Only these voices: user, assistant, tool, context. Without roles or query, tool and context runs fold into one line." }));
6
5
  /** First parameter violation; skip false subschemas so additionalProperties can name the field. */
7
6
  export function paramProblem(schema, params) {
@@ -103,7 +103,7 @@ test("Claude dialogue paging skips tool/thinking envelopes without losing array
103
103
  compact("boundary", "last"), row("boot", "boundary", "user", bootText(1))];
104
104
  const projection = project(rows, "boot");
105
105
  assert.equal(projection.highestSeq, 10);
106
- const listed = await historyList.execute({ before_seq: 9, roles: ["user", "assistant"], limit: 3 }, projection);
106
+ const listed = await historyList.execute({ before: 9, roles: ["user", "assistant"], limit: 3 }, projection);
107
107
  assert.ok(listed.ok);
108
108
  assert.deepEqual(listed.data.items.map((item) => "seq" in item ? [item.seq, item.content] : []), [[1, "human question"], [2, "assistant answer"], [8, "human followup"]]);
109
109
  const read = await historyRead.execute({ seq: 2 }, projection);
@@ -196,7 +196,7 @@ test("Claude native compaction and reset keep pre-reset history, preserved rewri
196
196
  assert.equal(allItems(projection).find((event) => event.text === "before first reset")?.windowId, `claude:${sessionId}:0`);
197
197
  assert.equal(allItems(projection).find((event) => event.text === "after first reset")?.windowId, `claude:${sessionId}:1`);
198
198
  assert.equal(projection.highestSeq, 8);
199
- const earlier = await historyList.execute({ after_seq: 4, before_seq: 6, roles: ["assistant"] }, projection);
199
+ const earlier = await historyList.execute({ after: 4, before: 6, roles: ["assistant"] }, projection);
200
200
  assert.ok(earlier.ok);
201
201
  assert.deepEqual(earlier.data.items.map((item) => "content" in item ? item.content : ""), ["after first reset"]);
202
202
  assert.equal(projection.windows[0]?.items[0]?.seq, 1);
@@ -210,7 +210,7 @@ test("Claude reset crosses native turn_duration graph metadata with no message c
210
210
  assert.equal(projection.highestSeq, 5, "duration metadata does not allocate a message address");
211
211
  assert.equal(projection.windows.length, 2);
212
212
  assert.ok(allItems(projection).some((event) => event.text === "marker before reset"));
213
- assert.ok((await historyList.execute({ before_seq: 3 }, projection)).ok);
213
+ assert.ok((await historyList.execute({ before: 3 }, projection)).ok);
214
214
  assert.ok((await historyRead.execute({ seq: 2 }, projection)).ok);
215
215
  });
216
216
  test("Claude api_error retry metadata keeps compact ancestry without allocating seq or exposing internals", async () => {
@@ -228,7 +228,7 @@ test("Claude api_error retry metadata keeps compact ancestry without allocating
228
228
  assert.deepEqual(project([...prefix, { ...rows[3], logicalParentUuid: "old" }, ...rows.slice(4)], "after"), projection, "metadata leaves all addresses and windows unchanged");
229
229
  assert.doesNotMatch(allItems(projection).map(eventDocument).join("\n"), /PRIVATE_RETRY_PAYLOAD|ECONNRESET|request_retry/);
230
230
  assert.ok((await historyList.execute({}, projection)).ok);
231
- const earlier = await historyList.execute({ before_seq: 3 }, projection);
231
+ const earlier = await historyList.execute({ before: 3 }, projection);
232
232
  assert.ok(earlier.ok);
233
233
  assert.match(JSON.stringify(earlier), /before retry|finished turn/);
234
234
  assert.ok((await historyRead.execute({ seq: 2 }, projection)).ok);
@@ -324,7 +324,6 @@ test("Claude helper reports gaps on list/read and re-anchors reset state only wi
324
324
  assert.equal(excluded.ok, false);
325
325
  assert.match(excluded.text, /outside the confirmed selected history/);
326
326
  await assert.rejects(invoke("history_list", { window_id: "anything" }), /invalid history_list parameters:.*window_id/);
327
- await assert.rejects(invoke("history_list", { before_seq: "invalid" }), /invalid history_list parameters: before_seq/);
328
327
  await assert.rejects(invoke("history_read", { seq: "2" }), /invalid history_read parameters: seq/);
329
328
  await assert.rejects(dispatch({ op: "history_state", identity, history }), /cannot determine the current window ordinal/);
330
329
  // A native boundary alone cannot count the missing earlier resets. A quoted
@@ -346,7 +345,7 @@ test("Claude helper reports gaps on list/read and re-anchors reset state only wi
346
345
  rows.push(compact("next", "after"), row("next-boot", "next", "user", bootText(9)), user("latest", "next-boot", "latest"));
347
346
  writeFileSync(transcriptPath, jsonl(rows));
348
347
  history.headUuid = "latest";
349
- const earlier = await invoke("history_list", { after_seq: 5, before_seq: 7 });
348
+ const earlier = await invoke("history_list", { after: 5, before: 7 });
350
349
  assert.ok(earlier.ok);
351
350
  assert.match(earlier.text, /after anchored reset/);
352
351
  assert.doesNotMatch(earlier.text, /confirmed suffix/);
@@ -122,9 +122,9 @@ test("Claude notes survive removal of the session's worktree cwd", async (t) =>
122
122
  assert.match((await call("notes_read", { address })).result, /done/);
123
123
  }
124
124
  });
125
- test("Claude helper exposes the seven shared notes/history schemas", async () => {
125
+ test("Claude helper exposes the shared notes/history schemas", async () => {
126
126
  const schemas = await dispatch({ op: "schemas" });
127
- assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read"]);
127
+ assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "history_list", "history_read"]);
128
128
  assert.ok(schemas.every((schema) => schema.description.length > 20 && schema.inputSchema.type === "object"));
129
129
  });
130
130
  test("Claude helper delivers only shared rendered text and success", async () => {
@@ -328,7 +328,7 @@ test("Claude Mod helper runs from a standalone copied plugin directory", () => {
328
328
  }));
329
329
  const schemas = run('{"op":"schemas"}');
330
330
  assert.equal(schemas.ok, true);
331
- assert.equal(schemas.result?.length, 7);
331
+ assert.equal(schemas.result?.length, 6);
332
332
  assert.equal(run("not json").ok, false);
333
333
  }
334
334
  finally {
@@ -524,7 +524,7 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
524
524
  const handlers = new Map();
525
525
  hooks.register((event, handler) => handlers.set(event, handler));
526
526
  await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async (event) => event);
527
- assert.deepEqual(registered.map((spec) => spec.name), ["empty_brain", "notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read"]);
527
+ assert.deepEqual(registered.map((spec) => spec.name), ["empty_brain", "notes_write", "notes_update", "notes_read", "notes_list", "history_list", "history_read"]);
528
528
  for (const spec of registered) {
529
529
  assert.equal(spec.isDeferred, false, `${spec.name} is available from the start without tool search`);
530
530
  assert.ok(spec.description.length > 20);
@@ -586,7 +586,6 @@ test("Claude Mod clears at the shared hard point after successful settlement and
586
586
  return {};
587
587
  };
588
588
  await invoke("session.start", { cwd: home, isInteractive: true });
589
- assert.equal(registered.length, 8);
590
589
  const initial = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
591
590
  assert.equal(initial.blocks.length, 1, "below the warn point no warning joins the boot");
592
591
  assert.match(initial.blocks[0].text, /Current context window id: claude:hook-session:0/);
@@ -1732,7 +1731,7 @@ test("Claude serves every registered notes tool to subagents without leaking eve
1732
1731
  assert.match((await call("notes_read", { address: "child.md" })).result, /child body/);
1733
1732
  assert.equal((await call("notes_update", { address: "child.md", edits: [{ oldText: "child body", newText: "updated body" }] })).isError, undefined);
1734
1733
  assert.match((await call("notes_list", {})).result, /child\.md/);
1735
- assert.match((await call("notes_search", { query: "updated body" })).result, /child\.md/);
1734
+ assert.match((await call("notes_list", { query: "updated body" })).result, /child\.md/);
1736
1735
  assert.equal((await call("notes_read", { address: "absent.md" })).isError, true, "refusals retain the error discriminator in subagents");
1737
1736
  });
1738
1737
  test("Claude identity uses the documented current model and cwd, with a safe model fallback", async (t) => {
@@ -1841,7 +1840,7 @@ test("Claude history keeps classic transcript_path across startup, confirms appe
1841
1840
  // Real order: classic -> startup attachment appends -> typed session.start.
1842
1841
  await invoke("session.append", { uuid: "startup" }, { uuid: "startup", message: {} });
1843
1842
  await invoke("session.start", { cwd: home, isInteractive: true });
1844
- assert.equal(registered.length, 8);
1843
+ assert.ok(registered.some((tool) => tool.name === "history_list"));
1845
1844
  const listed = await call("history_list", { roles: ["user", "context"] });
1846
1845
  assert.equal(listed.isError, undefined, listed.result);
1847
1846
  assert.match(listed.result, /old request/);
@@ -209,7 +209,7 @@ test("two native checkpoints retain old raw history; replacement_history is not
209
209
  assert.deepEqual(second.projection.windows.map((w) => [w.windowId, w.items[0]?.seq, w.items.at(-1)?.seq]), [
210
210
  [`codex:${ROOT}:${W0}`, 2, 3], [`codex:${ROOT}:${W1}`, 4, 6], [`codex:${ROOT}:${W2}`, 7, 8],
211
211
  ]);
212
- const earlier = await historyList.execute({ after_seq: 3, before_seq: 7, roles: ["user"] }, second.projection);
212
+ const earlier = await historyList.execute({ after: 3, before: 7, roles: ["user"] }, second.projection);
213
213
  assert.ok(earlier.ok);
214
214
  assert.deepEqual(earlier.data.items.map((item) => [item.seq, item.role, item.content]), [[6, "user", "middle text"]]);
215
215
  const old = await historyRead.execute({ seq: 2 }, second.projection);
@@ -149,7 +149,7 @@ test("a copied plugin without src or node_modules still initializes and lists al
149
149
  const listed = await client.listTools();
150
150
  assert.deepEqual(listed.tools.map((tool) => tool.name).sort(), [
151
151
  "history_list", "history_read",
152
- "notes_list", "notes_read", "notes_search", "notes_update", "notes_write",
152
+ "notes_list", "notes_read", "notes_update", "notes_write",
153
153
  ]);
154
154
  for (const tool of listed.tools) {
155
155
  const schema = tool.outputSchema;
@@ -184,7 +184,6 @@ test("bundled Codex MCP reads another harness and wildcard results retain their
184
184
  const limited = await call(client, { name: "history_list", arguments: { session: "*", query: "needle", limit: 1 }, _meta: metaFor(ROOT, ROOT) });
185
185
  assert.equal(limited.structuredContent.has_older, true);
186
186
  assert.equal(limited.structuredContent.items.length, 1, "the limit bounds the page to one item");
187
- assert.doesNotMatch(textOf(limited), /before_seq|after_seq/);
188
187
  const invalid = await call(client, { name: "history_read", arguments: { session: "*", seq: 1 }, _meta: metaFor(ROOT, ROOT) });
189
188
  assert.equal(errorCode(invalid), "invalid_session");
190
189
  });
@@ -246,7 +246,7 @@ test("AST guard sees every literal module edge, not import-like prose or comment
246
246
  test("the core entry is host-neutral and the Pi plugin entry owns the extension", () => {
247
247
  assert.deepEqual(Object.keys(core).sort(), [
248
248
  "DEFAULT_BOOT_TOOL_NAMES", "NoteError", "createNotesStore", "deriveThresholds", "effectiveNotePolicy", "historyList", "historyRead",
249
- "loadNotesSnapshot", "noteIdentity", "notesIdentityForCall", "notesList", "notesRead", "notesSearch", "notesToolContext", "notesUpdate", "notesWrite", "projectHistory",
249
+ "loadNotesSnapshot", "noteIdentity", "notesIdentityForCall", "notesList", "notesRead", "notesToolContext", "notesUpdate", "notesWrite", "projectHistory",
250
250
  "projectKey", "remainingBudget", "renderBootBlock", "renderProtocolBlock", "selectContinuation", "slugify",
251
251
  "tokenBudgetGuidance", "unavailableNotesSnapshot", "warningPrompt", "WARNING_BODY",
252
252
  ].sort(), "the core exports a curated host-neutral surface and no extension");
@@ -269,7 +269,7 @@ test("the configured extension source is the executable current entry", async ()
269
269
  registerTool(tool) { tools.push(tool); },
270
270
  registerCommand(name) { commands.push(name); },
271
271
  });
272
- assert.deepEqual(tools.map((tool) => tool.name).sort(), ["dream_begin", "dream_end", "dream_forget", "empty_brain", "get_context_remaining", "history_list", "history_read", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
272
+ assert.deepEqual(tools.map((tool) => tool.name).sort(), ["dream_begin", "dream_end", "dream_forget", "empty_brain", "get_context_remaining", "history_list", "history_read", "notes_list", "notes_read", "notes_update", "notes_write"]);
273
273
  assert.deepEqual(tools.filter((tool) => tool.exposure === "deferred").map((tool) => tool.name).sort(), ["dream_begin", "dream_end", "dream_forget", "history_list", "history_read"], "dream and history tools stay hidden until searched");
274
274
  assert.deepEqual(commands.sort(), ["empty", "fresh-window", "notesoup"]);
275
275
  });
@@ -1,13 +1,14 @@
1
1
  import assert from "node:assert/strict";
2
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
3
  import fs from "node:fs/promises";
4
4
  import { syncBuiltinESMExports } from "node:module";
5
5
  import { tmpdir } from "node:os";
6
6
  import { join } from "node:path";
7
7
  import test from "node:test";
8
- import { execFileSync } from "node:child_process";
8
+ import { once } from "node:events";
9
+ import { execFileSync, spawn } from "node:child_process";
9
10
  import { Check } from "typebox/value";
10
- import { createNotesStore } from "../src/notes/index.js";
11
+ import { createNotesStore, projectKey } from "../src/notes/index.js";
11
12
  import { abandonDream, dreamBegin, dreamEnd, dreamForget, dreamingIdentity } from "../src/tools/dream.js";
12
13
  import { notesRead, notesUpdate, notesWrite } from "../src/tools/notes.js";
13
14
  import { notesToolContext } from "../src/tools/notes-context.js";
@@ -43,7 +44,6 @@ test("a dream opens one other project, writes its notes, deletes only crumpled o
43
44
  assert.ok(begun.data.files.every(f => typeof f.last_accessed === "string"), "the dream's list shows each note's last access");
44
45
  assert.match(dreamBegin.render(begun), /\| accessed /);
45
46
  assert.equal((await dreamBegin.execute({}, me, state)).ok, false, "only one dream at a time");
46
- assert.ok(existsSync(join(home, ".dream.lock")), "the notes-home lock is held");
47
47
  assert.equal((await dreamBegin.execute({ project: "beta" }, as("other", "alpha"), {})).ok, false, "another session can't dream the same project");
48
48
  assert.ok((await notesWrite.execute({ address: "@projects/beta/rule", content: "merged" }, ident())).ok);
49
49
  assert.ok((await notesUpdate.execute({ address: "@sessions/b1/checkpoint", edits: [{ oldText: "old", newText: "new" }] }, ident())).ok);
@@ -60,13 +60,12 @@ test("a dream opens one other project, writes its notes, deletes only crumpled o
60
60
  assert.equal(existsSync(join(home, "pi", "session", "b2", "trash.md")), false);
61
61
  const ended = await dreamEnd.execute({}, me, state);
62
62
  assert.ok(ended.ok && ended.data.commit && ended.data.commit !== begun.data.baseline, "dream_end commits the changes");
63
- assert.equal(existsSync(join(home, ".dream.lock")), false, "the lock is released");
64
63
  assert.equal(execFileSync("git", ["status", "--porcelain"], { cwd: home, encoding: "utf8" }), "", "the audit leaves a clean tree");
65
64
  assert.equal((await notesWrite.execute({ address: "@projects/beta/rule", content: "x" }, ident())).ok, false, "closed again");
66
65
  assert.equal((await dreamEnd.execute({}, me, state)).ok, false);
67
66
  });
68
67
  test("pending openings exclude concurrent begins and stale cleanup preserves a newer generation", async (t) => {
69
- const { home, as } = fixture(t);
68
+ const { as } = fixture(t);
70
69
  const me = as("s", "alpha");
71
70
  const state = {};
72
71
  const old = dreamBegin.execute({}, me, state);
@@ -78,20 +77,18 @@ test("pending openings exclude concurrent begins and stale cleanup preserves a n
78
77
  assert.ok(!concurrent.ok && concurrent.error.code === "already_dreaming");
79
78
  assert.equal(state.pending, pending);
80
79
  abandonDream(state);
81
- assert.equal(existsSync(join(home, ".dream.lock")), false);
82
80
  const newer = dreamBegin.execute({ project: "beta" }, me, state);
83
81
  const newerPending = state.pending;
84
82
  assert.ok(newerPending && newerPending.generation > pending.generation);
85
- const token = readFileSync(join(home, ".dream.lock"), "utf8");
86
83
  const cancelled = await old;
87
84
  assert.ok(!cancelled.ok && cancelled.error.code === "cancelled");
88
- assert.equal(readFileSync(join(home, ".dream.lock"), "utf8"), token);
85
+ const refused = await dreamBegin.execute({}, me, {});
86
+ assert.ok(!refused.ok && refused.error.code === "already_dreaming");
89
87
  const begun = await newer;
90
88
  assert.ok(begun.ok);
91
89
  assert.equal(state.project, "beta");
92
90
  assert.equal(state.pending, undefined);
93
91
  assert.ok((await dreamEnd.execute({}, me, state)).ok);
94
- assert.equal(existsSync(join(home, ".dream.lock")), false);
95
92
  });
96
93
  test("a thrown scan releases pending ownership before propagating the defect", async (t) => {
97
94
  const { home, as } = fixture(t);
@@ -106,10 +103,9 @@ test("a thrown scan releases pending ownership before propagating the defect", a
106
103
  syncBuiltinESMExports();
107
104
  t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
108
105
  await assert.rejects(dreamBegin.execute({}, as("s", "alpha"), state), error => error === sentinel);
109
- assert.equal(existsSync(join(home, ".dream.lock")), false);
110
106
  assert.equal(state.pending, undefined);
111
107
  assert.equal(state.project, undefined);
112
- assert.equal(state.lock, undefined);
108
+ assert.equal(state.release, undefined);
113
109
  t.mock.restoreAll();
114
110
  syncBuiltinESMExports();
115
111
  assert.ok((await dreamBegin.execute({}, as("s", "alpha"), state)).ok, "the same state can retry after a failed scan");
@@ -122,10 +118,9 @@ test("baseline failure releases pending ownership and permits a retry", async (t
122
118
  writeFileSync(join(home, ".git"), "not a Git repository");
123
119
  const failed = await dreamBegin.execute({}, me, state);
124
120
  assert.ok(!failed.ok && failed.error.code === "audit_failed");
125
- assert.equal(existsSync(join(home, ".dream.lock")), false);
126
121
  assert.equal(state.pending, undefined);
127
122
  assert.equal(state.project, undefined);
128
- assert.equal(state.lock, undefined);
123
+ assert.equal(state.release, undefined);
129
124
  const ended = await dreamEnd.execute({}, me, state);
130
125
  assert.ok(!ended.ok && ended.error.code === "not_dreaming");
131
126
  rmSync(join(home, ".git"));
@@ -220,11 +215,41 @@ test("named-project mutation receipts carry their project metadata and fit their
220
215
  assert.equal(Check(dreamForget.outputSchema, forgotten.data), true, "dream_forget accepts its own named-project receipt");
221
216
  assert.ok((await dreamEnd.execute({}, me, state)).ok);
222
217
  });
218
+ test("a killed dream releases its lock without blocking project claims or note writes", { timeout: 20_000 }, async (t) => {
219
+ const { as } = fixture(t);
220
+ const script = `
221
+ import { dreamBegin } from ${JSON.stringify(new URL("../src/tools/dream.js", import.meta.url).href)};
222
+ globalThis.dream = {};
223
+ const result = await dreamBegin.execute({}, JSON.parse(process.argv[1]), globalThis.dream);
224
+ if (!result.ok) throw new Error(result.error.message);
225
+ process.send("open");
226
+ setInterval(() => {}, 60000);
227
+ `;
228
+ const child = spawn(process.execPath, ["--input-type=module", "-e", script, JSON.stringify(as("child", "alpha"))], { stdio: ["ignore", "ignore", "inherit", "ipc"] });
229
+ t.after(() => { child.kill("SIGKILL"); });
230
+ const exit = once(child, "exit");
231
+ assert.equal(await Promise.race([once(child, "message").then(([message]) => message), exit]), "open");
232
+ const next = as("next", "beta");
233
+ const state = {};
234
+ const refused = await dreamBegin.execute({}, next, state);
235
+ assert.ok(!refused.ok && refused.error.code === "already_dreaming");
236
+ assert.equal(projectKey("/work/another", next.home), "another");
237
+ await createNotesStore(next).write("@project/live", "still writable");
238
+ assert.ok(child.kill("SIGKILL"));
239
+ assert.deepEqual(await exit, [null, "SIGKILL"]);
240
+ assert.ok((await dreamBegin.execute({}, next, state)).ok);
241
+ assert.equal((await createNotesStore(next).read("@project/live"))?.body, "still writable");
242
+ assert.ok((await dreamEnd.execute({}, next, state)).ok);
243
+ });
223
244
  test("a notes-home lock prevents interleaved dream Git audits", async (t) => {
224
245
  const { home, as } = fixture(t);
225
246
  const alpha = as("alpha-session", "alpha"), beta = as("beta-session", "beta");
226
247
  await createNotesStore(alpha).write("@project/note", "before alpha");
227
248
  await createNotesStore(beta).write("@project/note", "before beta");
249
+ // A crashed project claim may leave a staged marker. Neither it nor the lock DB belongs in Git.
250
+ const staged = mkdtempSync(join(home, ".project-pending-"));
251
+ writeFileSync(join(staged, ".project"), "{}");
252
+ projectKey("/work/another", home);
228
253
  const alphaState = {}, betaState = {};
229
254
  const begun = await dreamBegin.execute({ project: "alpha" }, alpha, alphaState);
230
255
  assert.ok(begun.ok);
@@ -237,6 +262,9 @@ test("a notes-home lock prevents interleaved dream Git audits", async (t) => {
237
262
  const ended = await dreamEnd.execute({}, alpha, alphaState);
238
263
  assert.ok(ended.ok && ended.data.commit !== undefined);
239
264
  assert.notEqual(ended.data.commit, begun.data.baseline);
265
+ for (const commit of [begun.data.baseline, ended.data.commit]) {
266
+ assert.equal(execFileSync("git", ["ls-tree", "--name-only", commit], { cwd: home, encoding: "utf8" }), "project\n");
267
+ }
240
268
  const changed = execFileSync("git", ["show", "--format=", "--name-only", ended.data.commit], { cwd: home, encoding: "utf8" });
241
269
  assert.match(changed, /project\/alpha\/note\.md/);
242
270
  assert.doesNotMatch(changed, /project\/beta\/note\.md/);
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
8
8
  import { join } from "node:path";
9
9
  import { resolveProjectNamespace } from "../src/notes/project-namespace.js";
10
10
  import { WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG } from "../src/boot/text.js";
11
- import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
11
+ import { notesList, notesRead, notesUpdate, notesWrite } from "../src/tools/notes.js";
12
12
  import { historyList, historyRead } from "../src/tools/history.js";
13
13
  import { notesToolContext } from "../src/tools/notes-context.js";
14
14
  import { success } from "../src/result.js";
@@ -27,7 +27,7 @@ function system(request) { return typeof request.system === "string" ? request.s
27
27
  function code(expected) { return (error) => error?.code === expected; }
28
28
  test("dsh preserves shared tool and parameter descriptions verbatim", async (t) => {
29
29
  const { ctx } = await dshFixture(t);
30
- for (const operation of [notesWrite, notesUpdate, notesRead, notesList, notesSearch, historyList, historyRead]) {
30
+ for (const operation of [notesWrite, notesUpdate, notesRead, notesList, historyList, historyRead]) {
31
31
  const registered = ctx.tools.get(operation.name);
32
32
  assert.equal(registered.description, operation.description);
33
33
  const properties = registered.parameters.properties;
@@ -112,18 +112,17 @@ test("all single-session recipes preserve the resolved identity, including folde
112
112
  { seq: 4, windowId: "w", role: "assistant", text: "last" },
113
113
  ] }], 4, new Set([1, 2, 3, 4]));
114
114
  const ctx = context([descriptor("claude", "target-session", p)]);
115
- const page = await historyList.execute({ session: "claude:target", limit: 1, after_seq: 1, before_seq: 5, from: "newest" }, ctx);
115
+ const page = await historyList.execute({ session: "claude:target", limit: 1, before: 5 }, ctx);
116
116
  assert.equal(data(page).has_older, true);
117
- assert.match(historyList.render(page), /→ older: \{"session":"claude:target-session","before_seq":4\}/);
118
- const first = await historyList.execute({ session: "target", from: "oldest", limit: 1 }, ctx);
117
+ assert.match(historyList.render(page), /→ older: \{"session":"claude:target-session","before":4\}/);
118
+ const first = await historyList.execute({ session: "target", after: 0, limit: 1 }, ctx);
119
119
  assert.equal(data(first).has_newer, true);
120
- assert.match(historyList.render(first), /→ newer: \{"session":"claude:target-session","after_seq":1\}/);
120
+ assert.match(historyList.render(first), /→ newer: \{"session":"claude:target-session","after":1\}/);
121
121
  const foldPage = await historyList.execute({ session: "target", limit: 3 }, ctx);
122
122
  const expand = /→ expand: (\{[^\n]+\})/.exec(historyList.render(foldPage));
123
123
  assert.ok(expand);
124
124
  const recipe = JSON.parse(expand[1]);
125
125
  assert.equal(recipe.session, "claude:target-session");
126
- assert.equal("from" in recipe, false);
127
126
  assert.deepEqual(data(await historyList.execute(recipe, ctx)).items.map((item) => item.seq), [2]);
128
127
  assert.match(historyList.render(foldPage), /session claude:target-session \| seq 1 \| user/);
129
128
  const read = await historyRead.execute({ session: "target", seq: 3 }, ctx);
@@ -144,30 +143,21 @@ test("recipes expand a fold at seq 1 and read its neighborhood from the start",
144
143
  const expand = /→ expand: (\{[^\n]+\})/.exec(historyList.render(folded));
145
144
  assert.ok(expand);
146
145
  const recipe = JSON.parse(expand[1]);
147
- assert.equal(recipe.after_seq, 0);
146
+ assert.equal(recipe.after, 0);
148
147
  assert.ok(Check(historyList.parameters, recipe));
149
148
  assert.deepEqual(data(await historyList.execute(recipe, ctx)).items.map((item) => item.seq), [1, 2]);
150
149
  const read = await historyRead.execute({ session: "first-fold", seq: 3 }, ctx);
151
150
  const neighborhood = /neighborhood → `history_list`\((\{[^\n]+\})\)/.exec(historyRead.render(read));
152
151
  assert.ok(neighborhood);
153
152
  const nearby = JSON.parse(neighborhood[1]);
154
- assert.equal(nearby.after_seq, 0);
153
+ assert.equal(nearby.after, 0);
155
154
  assert.ok(Check(historyList.parameters, nearby));
156
155
  assert.ok(data(await historyList.execute(nearby, ctx)).items.length > 0);
157
156
  });
158
157
  test("wildcard refusals precede discovery, and read accepts no wildcard selector", async () => {
159
158
  const ctx = { current: () => { throw new Error("must not load current"); }, corpus: { currentHarness: "pi", sessions: async () => { throw new Error("must not discover"); } } };
160
- for (const session of ["*", "pi:*", "pre*fix"]) {
161
- for (const query of [undefined, "", [], ["", ""], "needle"]) {
162
- for (const bounds of [{ before_seq: 10 }, { after_seq: 0 }, { after_seq: 1 }, { before_seq: 10, after_seq: 1 }]) {
163
- refusal(await historyList.execute({ session, query, ...bounds }, ctx), "invalid_bounds");
164
- }
165
- }
166
- }
167
- for (const session of ["*", "pi:*", "cl*", "dsh:pre*suffix"]) {
168
- refusal(await historyRead.execute({ session, seq: 1 }, ctx), "invalid_session");
169
- }
170
- refusal(await historyList.execute({ session: "*", query: "needle", since: "not-a-date" }, ctx), "invalid_time");
159
+ assert.match(refusal(await historyList.execute({ session: "pi:*", query: "needle", after: "3" }, ctx), "invalid_bounds"), /requires times/);
160
+ refusal(await historyRead.execute({ session: "*", seq: 1 }, ctx), "invalid_session");
171
161
  });
172
162
  test("native filesystem discovery decodes three harnesses, compressed Codex, and keeps source bytes/mtime unchanged", async (t) => {
173
163
  const f = await fixture(t);
@@ -205,14 +195,12 @@ test("wildcard query merges every role chronologically, limits from either end,
205
195
  assert.deepEqual(newest.items, page.items.slice(-2));
206
196
  assert.equal(newest.has_older, true);
207
197
  assert.equal(newest.has_newer, false);
208
- assert.doesNotMatch(historyList.render(newestResult), /before_seq|after_seq/);
209
- const oldestResult = await historyList.execute({ session: "*", query: "needle", limit: 2, from: "oldest" }, ctx);
198
+ const oldestResult = await historyList.execute({ session: "*", query: "needle", limit: 2, after: "2026-10-06" }, ctx);
210
199
  const oldest = data(oldestResult);
211
200
  assert.deepEqual(oldest.items, page.items.slice(0, 2));
212
201
  assert.equal(oldest.has_older, false);
213
202
  assert.equal(oldest.has_newer, true);
214
- assert.doesNotMatch(historyList.render(oldestResult), /before_seq|after_seq/);
215
- const filtered = data(await historyList.execute({ session: "*", query: "needle", roles: ["tool", "context"], since: "2026-10-06T01:02:05", until: "2026-10-06T01:02:07Z" }, ctx));
203
+ const filtered = data(await historyList.execute({ session: "*", query: "needle", roles: ["tool", "context"], after: "2026-10-06T01:02:04", before: "2026-10-06T01:02:07Z" }, ctx));
216
204
  assert.deepEqual(filtered.items.map((item) => item.role), ["tool"]);
217
205
  const harness = data(await historyList.execute({ session: "claude:*", query: "needle" }, ctx));
218
206
  assert.ok(harness.items.every((item) => "session" in item && item.session === "claude:claude-one"));
@@ -235,12 +223,11 @@ test("bounded wildcard search scans every session and orders untimed and tied ma
235
223
  }));
236
224
  const ctx = context(sessions);
237
225
  const ids = (page) => page.items.map((item) => "seq" in item ? [item.session, item.seq] : null);
238
- assert.deepEqual(ids(data(await historyList.execute({ session: "*", query: "needle", from: "oldest", limit: 3 }, ctx))), [["pi:a", 1], ["pi:a", 2], ["pi:m", 1]]);
226
+ assert.deepEqual(ids(data(await historyList.execute({ session: "*", query: "needle", after: "2026-10-06", limit: 3 }, ctx))), [["pi:a", 3], ["pi:a", 4], ["pi:a", 5]]);
239
227
  assert.deepEqual(seen, ["z", "a", "m"]);
240
228
  seen.length = 0;
241
229
  assert.deepEqual(ids(data(await historyList.execute({ session: "*", query: "needle", limit: 3 }, ctx))), [["pi:z", 198], ["pi:z", 199], ["pi:z", 200]]);
242
230
  assert.deepEqual(seen, ["z", "a", "m"]);
243
- assert.deepEqual(ids(data(await historyList.execute({ session: "*", query: "needle", from: "oldest", limit: 1, since: AT }, ctx))), [["pi:a", 3]]);
244
231
  });
245
232
  test("query-less wildcards browse recent sessions, normalize empty queries, and keep canonical IDs", async (t) => {
246
233
  const { ctx } = await fixture(t);
@@ -278,7 +265,7 @@ test("session overviews order discovery by mtime, stop at the session limit, the
278
265
  assert.deepEqual(loaded, Array.from({ length: 20 }, (_, index) => 24 - index));
279
266
  assert.deepEqual(recent.items.map((item) => item.session), loaded.map((index) => `pi:s-${index}`));
280
267
  loaded.length = 0;
281
- const oldest = data(await historyList.execute({ session: "*", from: "oldest", limit: 2 }, ctx));
268
+ const oldest = data(await historyList.execute({ session: "*", after: AT, limit: 2 }, ctx));
282
269
  assert.equal(oldest.has_older, false);
283
270
  assert.equal(oldest.has_newer, true);
284
271
  assert.deepEqual(loaded, [0, 1]);
@@ -308,12 +295,11 @@ test("session representatives respect visibility, role/time filters, opening use
308
295
  assert.deepEqual(await chosen({ roles: ["context", "tool"] }), [8]);
309
296
  assert.deepEqual(await chosen({ roles: ["tool"] }), [6]);
310
297
  assert.deepEqual(await chosen({ roles: [] }), []);
311
- assert.deepEqual(await chosen({ since: at(2), until: at(3) }), [4]);
312
- assert.deepEqual(await chosen({ since: at(3) }), [5]);
313
- assert.deepEqual(await chosen({ until: at(1) }), [1]);
314
- assert.deepEqual(await chosen({ since: at(4) }), [8]);
315
- assert.deepEqual(await chosen({ since: at(4), roles: ["user"] }), []);
316
- assert.deepEqual(await chosen({ since: at(7) }), []);
298
+ assert.deepEqual(await chosen({ after: at(1), before: at(3) }), [4]);
299
+ assert.deepEqual(await chosen({ after: at(2) }), [5]);
300
+ assert.deepEqual(await chosen({ before: at(1) }), [1]);
301
+ assert.deepEqual(await chosen({ after: at(4) }), [8]);
302
+ assert.deepEqual(await chosen({ after: at(4), roles: ["user"] }), []);
317
303
  const noUsers = { ...p, windows: p.windows.map((window) => ({ ...window, items: window.items.filter((item) => item.role !== "user") })) };
318
304
  const fallback = data(await historyList.execute({ session: "*" }, context([descriptor("pi", "assistant-topic", noUsers)])));
319
305
  assert.deepEqual(fallback.items.map((item) => "seq" in item ? item.seq : null), [4]);
@@ -418,13 +404,12 @@ test("oversized cross-session reads/searches obey both wire budgets and retain c
418
404
  });
419
405
  test("wildcard byte budgets report retained candidates beyond either end", async () => {
420
406
  const ctx = context([descriptor("pi", "large", projection("needle " + "x".repeat(20_000)))]);
421
- for (const from of ["newest", "oldest"]) {
422
- const result = await historyList.execute({ session: "*", query: "needle", from, limit: 5, max_chars_per_item: 50_000 }, ctx);
407
+ for (const after of [undefined, AT]) {
408
+ const result = await historyList.execute({ session: "*", query: "needle", after, limit: 5, max_chars_per_item: 50_000 }, ctx);
423
409
  const page = data(result);
424
410
  assert.ok(page.items.length < 5);
425
- assert.equal(page.has_older, from === "newest");
426
- assert.equal(page.has_newer, from === "oldest");
427
- assert.doesNotMatch(historyList.render(result), /before_seq|after_seq/);
411
+ assert.equal(page.has_older, after === undefined);
412
+ assert.equal(page.has_newer, after !== undefined);
428
413
  }
429
414
  });
430
415
  test("qualified lookup and current-harness matches do not inspect unrelated roots", async (t) => {