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
@@ -24947,6 +24947,7 @@ var HistoryFoldedRowSchema = typebox_exports.Object({
24947
24947
  var HistoryPageItemSchema = typebox_exports.Object({
24948
24948
  session: typebox_exports.Optional(typebox_exports.String()),
24949
24949
  folded_before: typebox_exports.Optional(HistoryFoldedRowSchema),
24950
+ context: typebox_exports.Optional(typebox_exports.Literal(true, { description: "A neighbor of a search hit, not a hit in this page." })),
24950
24951
  seq: typebox_exports.Integer({ minimum: 1 }),
24951
24952
  role: HistoryRoleSchema,
24952
24953
  created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
@@ -24976,20 +24977,17 @@ function visibleItem(event, maxChars, matchOffset) {
24976
24977
  function allItems(projection) {
24977
24978
  return projection.windows.flatMap((current) => current.items);
24978
24979
  }
24979
- function inSelection(event, params) {
24980
- if (params.after_seq !== void 0 && event.seq <= params.after_seq) return false;
24981
- if (params.before_seq !== void 0 && event.seq >= params.before_seq) return false;
24982
- if (params.sinceMs === void 0 && params.untilMs === void 0) return true;
24983
- if (event.createdAt === void 0) return false;
24984
- const at = Date.parse(event.createdAt);
24985
- return !Number.isNaN(at) && (params.sinceMs === void 0 || at >= params.sinceMs) && (params.untilMs === void 0 || at < params.untilMs);
24980
+ function compareBound(event, bound) {
24981
+ return "seq" in bound ? event.seq - bound.seq : Date.parse(event.createdAt ?? "") - bound.at;
24982
+ }
24983
+ function matchesFilter(event, { after, before, roles }) {
24984
+ return (!after || compareBound(event, after) > 0) && (!before || compareBound(event, before) < 0) && (!roles || roles.includes(event.role));
24986
24985
  }
24987
24986
  function filteredItems(projection, params) {
24988
- return allItems(projection).filter((item) => inSelection(item, params) && (!params.roles || params.roles.includes(item.role))).sort((a, b) => a.seq - b.seq);
24987
+ return allItems(projection).filter((event) => matchesFilter(event, params)).sort((a, b) => a.seq - b.seq);
24989
24988
  }
24990
24989
 
24991
24990
  // src/tools/schema.ts
24992
- var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
24993
24991
  var historyRoles = () => typebox_exports.Optional(typebox_exports.Array(HistoryRoleSchema, { minItems: 1, description: "Only these voices: user, assistant, tool, context. Without roles or query, tool and context runs fold into one line." }));
24994
24992
  function paramProblem(schema, params) {
24995
24993
  const first = Errors2(schema, params).find((error2) => error2.keyword !== "boolean");
@@ -25097,8 +25095,8 @@ function globToRegExp(pattern) {
25097
25095
  return new RegExp(`${source}$`);
25098
25096
  }
25099
25097
  function assertGlobPattern(value) {
25100
- if (value === void 0 || value === null || value === "") return void 0;
25101
- if (typeof value !== "string") throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
25098
+ if (value === void 0) return void 0;
25099
+ if (typeof value !== "string" || !value) throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a non-empty string; omit it for the current notebooks.`);
25102
25100
  if (value.includes("\0") || value.includes("\\")) throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
25103
25101
  return value;
25104
25102
  }
@@ -25372,8 +25370,25 @@ var MAX_NOTE_PATH_BYTES = 512;
25372
25370
 
25373
25371
  // src/notes/project-namespace.ts
25374
25372
  import { randomUUID } from "node:crypto";
25375
- import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync } from "node:fs";
25373
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
25376
25374
  import { basename, dirname, join as join2, resolve as resolve2, sep } from "node:path";
25375
+
25376
+ // src/sqlite-lock.ts
25377
+ function trySqliteLock(path, waitMs) {
25378
+ const sqlite = process.getBuiltinModule?.("node:sqlite");
25379
+ if (!sqlite?.DatabaseSync) throw new Error("Notesoup locks require built-in node:sqlite (Node 22.13+).");
25380
+ const db = new sqlite.DatabaseSync(path);
25381
+ try {
25382
+ db.exec(`PRAGMA busy_timeout = ${waitMs}; BEGIN IMMEDIATE`);
25383
+ } catch (error2) {
25384
+ db.close();
25385
+ if (error2 instanceof Error && "errcode" in error2 && error2.errcode === 5) return void 0;
25386
+ throw error2;
25387
+ }
25388
+ return () => db.close();
25389
+ }
25390
+
25391
+ // src/notes/project-namespace.ts
25377
25392
  function errno(error2) {
25378
25393
  return typeof error2 === "object" && error2 !== null ? error2.code : void 0;
25379
25394
  }
@@ -25486,67 +25501,42 @@ function updateMarker(namespace, marker) {
25486
25501
  }
25487
25502
  return { ...namespace, ...marker };
25488
25503
  }
25489
- var claimSleep = new Int32Array(new SharedArrayBuffer(4));
25490
- function awaitClaim(path, attempt) {
25491
- const deadline = performance.now() + 5e3;
25492
- for (; ; ) {
25493
- const result = attempt();
25494
- if (result !== void 0) return result;
25495
- const remaining = deadline - performance.now();
25496
- if (remaining <= 0) throw new Error(`Timed out waiting for project claim at ${path}`);
25497
- Atomics.wait(claimSleep, 0, 0, Math.min(10, remaining));
25498
- }
25504
+ function checkoutMarker(cwd) {
25505
+ const path = canonicalRoot(cwd);
25506
+ return { id: originRemote(path) ?? path, path };
25499
25507
  }
25500
25508
  function resolveProjectNamespace(cwd, home) {
25501
- mkdirSync(projectRoot(home), { recursive: true });
25502
- const lock = join2(home, ".project-claim");
25503
- awaitClaim(lock, () => {
25504
- try {
25505
- mkdirSync(lock);
25506
- return true;
25507
- } catch (error2) {
25508
- if (errno(error2) === "EEXIST") return void 0;
25509
- throw error2;
25510
- }
25511
- });
25509
+ const expected = checkoutMarker(cwd);
25510
+ const current = projectNamespaces(home).find((candidate) => candidate.id === expected.id);
25511
+ if (current?.path === expected.path) return current;
25512
+ const root = projectRoot(home);
25513
+ mkdirSync(root, { recursive: true });
25514
+ const lockPath = join2(home, ".project-claim.sqlite");
25515
+ const release = trySqliteLock(lockPath, 5e3);
25516
+ if (!release) throw new Error(`Timed out waiting for project claim at ${lockPath}`);
25512
25517
  try {
25513
- return claimProjectNamespace(cwd, home);
25514
- } finally {
25515
- rmdirSync(lock);
25516
- }
25517
- }
25518
- function claimProjectNamespace(cwd, home) {
25519
- const root = canonicalRoot(cwd);
25520
- const remote = originRemote(root);
25521
- const id2 = remote ?? root;
25522
- const markerRoot = projectRoot(home);
25523
- mkdirSync(markerRoot, { recursive: true });
25524
- const namespaces = projectNamespaces(home);
25525
- let found = namespaces.find((candidate) => candidate.id === id2);
25526
- if (!found && remote) {
25527
- found = namespaces.find((candidate) => candidate.id === root);
25528
- if (found) found = updateMarker(found, { id: remote, path: root });
25529
- }
25530
- if (found) {
25531
- if (found.path !== root) found = updateMarker(found, { id: found.id, path: root });
25532
- return found;
25533
- }
25534
- const base = slugify2(basename(root));
25535
- const taken = new Set(readdirSync(markerRoot));
25536
- for (let suffix = 0; ; suffix++) {
25537
- const name = suffix === 0 ? base : `${base}-${suffix}`;
25538
- if (taken.has(name)) continue;
25539
- const dir = join2(markerRoot, name);
25540
- try {
25541
- mkdirSync(dir);
25542
- } catch (error2) {
25543
- if (errno(error2) !== "EEXIST") throw error2;
25544
- let winner = awaitClaim(join2(dir, ".project"), () => readMarker(dir));
25545
- if (winner.id !== id2 && !(remote && winner.id === root)) continue;
25546
- if (winner.id !== id2 || winner.path !== root) winner = updateMarker(winner, { id: id2, path: root });
25547
- return winner;
25518
+ const marker = checkoutMarker(cwd);
25519
+ const { id: id2, path } = marker;
25520
+ const namespaces = projectNamespaces(home);
25521
+ const found = namespaces.find((candidate) => candidate.id === id2) ?? namespaces.find((candidate) => candidate.id === path);
25522
+ if (found) return found.id === id2 && found.path === path ? found : updateMarker(found, marker);
25523
+ const base = slugify2(basename(path));
25524
+ for (let suffix = 0; ; suffix++) {
25525
+ const name = suffix === 0 ? base : `${base}-${suffix}`;
25526
+ const dir = join2(root, name);
25527
+ if (lstatSync(dir, { throwIfNoEntry: false })) continue;
25528
+ const staged = mkdtempSync(join2(home, ".project-pending-"));
25529
+ try {
25530
+ writeFileSync(join2(staged, ".project"), JSON.stringify(marker));
25531
+ renameSync(staged, dir);
25532
+ } catch (error2) {
25533
+ rmSync(staged, { recursive: true, force: true });
25534
+ throw error2;
25535
+ }
25536
+ return { name, dir, ...marker };
25548
25537
  }
25549
- return updateMarker({ name, dir, id: id2, path: root }, { id: id2, path: root });
25538
+ } finally {
25539
+ release();
25550
25540
  }
25551
25541
  }
25552
25542
  function gitRoot(cwd) {
@@ -25952,8 +25942,7 @@ function createNotesStore(input) {
25952
25942
  }));
25953
25943
  }
25954
25944
  async function* scan(options, status) {
25955
- const glob = assertGlobPattern(options.glob);
25956
- const pattern = glob === "@default" ? void 0 : glob;
25945
+ const pattern = assertGlobPattern(options.glob);
25957
25946
  const normalized = normalizePattern(pattern, identity);
25958
25947
  const matcher = normalized === void 0 ? void 0 : globToRegExp(normalized);
25959
25948
  const namespaces = await namespacesForPattern(pattern, identity, status);
@@ -26163,7 +26152,7 @@ function withWarnings(text2, data) {
26163
26152
  var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
26164
26153
  var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "Only the crumpled balls." }));
26165
26154
  var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many pages at most." }));
26166
- var GLOB_PARAMETER = nullableString("Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf \xB7 `MAP.md` that page in every notebook \xB7 `**` everything \xB7 `@sessions/*/**` every session.");
26155
+ var GLOB_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf \xB7 `MAP.md` that page in every notebook \xB7 `**` everything \xB7 `@sessions/*/**` every session." }));
26167
26156
  var CWD_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
26168
26157
  var ADDRESS_PARAMETER = typebox_exports.String({ description: "Which drawer the page sits in. `plan.md` \u2014 this session's desk, cleared when it ends. `@project/` this project's shelf \xB7 `@human/` your human's file \xB7 `@self/` your own notebook \xB7 `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` \u2014 someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
26169
26158
  function failureOf(error2) {
@@ -26253,11 +26242,6 @@ var MatchSchema = typebox_exports.Object({
26253
26242
  text: typebox_exports.String(),
26254
26243
  offset_chars: typebox_exports.Integer()
26255
26244
  }, { additionalProperties: false });
26256
- var SearchedFileSchema = typebox_exports.Object({
26257
- ...ListedFileSchema.properties,
26258
- matches: typebox_exports.Array(MatchSchema),
26259
- more_matches: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1 }))
26260
- }, { additionalProperties: false });
26261
26245
  var SnapshotSchema = {
26262
26246
  more: typebox_exports.Integer({ description: "How many more were left out." }),
26263
26247
  namespaces_unavailable: typebox_exports.Array(typebox_exports.String(), { description: "Unreadable notebooks or notes." })
@@ -26282,11 +26266,11 @@ var NotesReadDataSchema = typebox_exports.Object({
26282
26266
  ...TextWindowSchema.properties
26283
26267
  }, { additionalProperties: false });
26284
26268
  var NotesListDataSchema = typebox_exports.Object({
26285
- files: typebox_exports.Array(ListedFileSchema),
26286
- ...SnapshotSchema
26287
- }, { additionalProperties: false });
26288
- var NotesSearchDataSchema = typebox_exports.Object({
26289
- files: typebox_exports.Array(SearchedFileSchema),
26269
+ files: typebox_exports.Array(typebox_exports.Object({
26270
+ ...ListedFileSchema.properties,
26271
+ matches: typebox_exports.Optional(typebox_exports.Array(MatchSchema)),
26272
+ more_matches: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1 }))
26273
+ }, { additionalProperties: false })),
26290
26274
  ...SnapshotSchema
26291
26275
  }, { additionalProperties: false });
26292
26276
  function snapshot(rows, limit, status, renderData, shrink) {
@@ -26402,41 +26386,24 @@ var notesRead = {
26402
26386
  },
26403
26387
  render: (result) => renderOutcome(result, renderReadData)
26404
26388
  };
26405
- var notesListParameters = typebox_exports.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
26389
+ var notesListParameters = typebox_exports.Object({
26390
+ glob: GLOB_PARAMETER,
26391
+ query: typebox_exports.Optional(searchQuery()),
26392
+ max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many hit lines per note at most; requires a query." })),
26393
+ crumpled: CRUMPLED_LIST_PARAMETER,
26394
+ limit: FILE_LIMIT_PARAMETER,
26395
+ cwd: CWD_PARAMETER
26396
+ }, { additionalProperties: false });
26406
26397
  function renderListData(data) {
26407
26398
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
26408
26399
  for (const file of data.files) {
26409
- lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at}${file.last_accessed === void 0 ? "" : ` | accessed ${file.last_accessed}`}${file.crumpled_at === void 0 ? "" : ` | crumpled ${file.crumpled_at}`}`);
26400
+ const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
26401
+ if (file.last_accessed !== void 0) fields.push(`accessed ${file.last_accessed}`);
26402
+ if (file.crumpled_at !== void 0) fields.push(`crumpled ${file.crumpled_at}`);
26403
+ if (file.matches) fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
26404
+ lines.push(fields.join(" | "));
26410
26405
  lines.push(...file.warnings.map((warning) => ` ${warning}`));
26411
- }
26412
- if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
26413
- for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
26414
- return lines.join("\n");
26415
- }
26416
- var notesList = {
26417
- name: "notes_list",
26418
- label: "Notes list",
26419
- description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile \u2014 narrow `glob`.",
26420
- parameters: notesListParameters,
26421
- outputSchema: resultSchema(NotesListDataSchema),
26422
- async execute(params, context2) {
26423
- try {
26424
- const identity = notesIdentityForCall(context2, params.cwd);
26425
- const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? void 0, crumpled: params.crumpled });
26426
- return snapshot(rows.map((row) => listedFile(row, identity)), params.limit, status, renderListData);
26427
- } catch (error2) {
26428
- return failureOf(error2);
26429
- }
26430
- },
26431
- render: (result) => renderOutcome(result, renderListData)
26432
- };
26433
- var notesSearchParameters = typebox_exports.Object({ query: typebox_exports.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many hit lines per page at most." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
26434
- function renderSearchData(data) {
26435
- const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
26436
- for (const file of data.files) {
26437
- 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` : ""}`);
26438
- lines.push(...file.warnings.map((warning) => ` ${warning}`));
26439
- for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
26406
+ for (const match of file.matches ?? []) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
26440
26407
  }
26441
26408
  if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
26442
26409
  for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
@@ -26460,26 +26427,34 @@ function fitSearchFile(file, fits) {
26460
26427
  const withText = (text2) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text2}${MATCH_SHORTENED_MARKER}` }] });
26461
26428
  return withText(prefixFit(first.text, (text2) => fits(withText(text2))));
26462
26429
  }
26463
- var notesSearch = {
26464
- name: "notes_search",
26465
- label: "Notes search",
26466
- 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 \u2014 narrow `glob`.",
26467
- parameters: notesSearchParameters,
26468
- outputSchema: resultSchema(NotesSearchDataSchema),
26430
+ var notesList = {
26431
+ name: "notes_list",
26432
+ label: "Notes list",
26433
+ 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 \u2014 narrow `glob`.",
26434
+ parameters: notesListParameters,
26435
+ outputSchema: resultSchema(NotesListDataSchema),
26469
26436
  async execute(params, context2) {
26470
26437
  try {
26438
+ const queries = searchQueries(params.query);
26439
+ const { glob, crumpled, limit } = params;
26440
+ if (!queries.length && params.max_matches_per_file !== void 0) return failure2("invalid_params", "`max_matches_per_file` requires a non-empty `query`.");
26471
26441
  const identity = notesIdentityForCall(context2, params.cwd);
26472
- const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
26442
+ const store = createNotesStore(identity);
26443
+ if (!queries.length) {
26444
+ const { rows: rows2, status: status2 } = await store.listWithStatus({ glob, crumpled });
26445
+ return snapshot(rows2.map((row) => listedFile(row, identity)), limit, status2, renderListData);
26446
+ }
26447
+ const { rows, status } = await store.searchWithStatus(queries, { glob, crumpled });
26473
26448
  const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => keepMatches({
26474
26449
  ...listedFile(row, identity),
26475
26450
  matches: row.matches.map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
26476
26451
  }, params.max_matches_per_file));
26477
- return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
26452
+ return snapshot(files, limit, status, renderListData, fitSearchFile);
26478
26453
  } catch (error2) {
26479
26454
  return failureOf(error2);
26480
26455
  }
26481
26456
  },
26482
- render: (result) => renderOutcome(result, renderSearchData)
26457
+ render: (result) => renderOutcome(result, renderListData)
26483
26458
  };
26484
26459
 
26485
26460
  // src/history/query.ts
@@ -26491,23 +26466,6 @@ function markMultiPage(page) {
26491
26466
  multiPages.add(page);
26492
26467
  return page;
26493
26468
  }
26494
- var ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
26495
- function timeBound(name, value) {
26496
- if (value === void 0) return success(void 0);
26497
- const match = ISO_8601.exec(value);
26498
- const at = match === null ? void 0 : Date.parse(match[1] === void 0 ? `${value}Z` : value);
26499
- return at === void 0 || Number.isNaN(at) ? failure2("invalid_time", `\`${name}\` isn't an ISO 8601 time: "${value}".`) : success(at);
26500
- }
26501
- function resolveTimeBounds(params) {
26502
- const since = timeBound("since", params.since);
26503
- if (!since.ok) return since;
26504
- const until = timeBound("until", params.until);
26505
- if (!until.ok) return until;
26506
- if (since.data !== void 0 && until.data !== void 0 && since.data >= until.data) {
26507
- return failure2("invalid_time", "`since` must be earlier than `until`.");
26508
- }
26509
- return success({ ...since.data === void 0 ? {} : { sinceMs: since.data }, ...until.data === void 0 ? {} : { untilMs: until.data } });
26510
- }
26511
26469
  var HistoryPageSchema = typebox_exports.Object({
26512
26470
  notice: typebox_exports.Optional(typebox_exports.String()),
26513
26471
  items: typebox_exports.Array(HistoryPageItemSchema),
@@ -26540,22 +26498,29 @@ function foldedRun(events, session) {
26540
26498
  const tools2 = Object.fromEntries(entries);
26541
26499
  return { ...session === void 0 ? {} : { session }, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools: tools2 };
26542
26500
  }
26501
+ var visible = (event) => event.role !== "user" && event.role !== "assistant" || eventDocument(event) !== "";
26502
+ function* queryHits(projection, params, session) {
26503
+ const { query, context: context2 } = params;
26504
+ const events = filteredItems(projection, context2 ? {} : params).filter(visible);
26505
+ for (const [index, event] of events.entries()) {
26506
+ if (context2 && !matchesFilter(event, params)) continue;
26507
+ const matchOffset = earliestMatchOffsetChars(eventDocument(event), query);
26508
+ if (matchOffset >= 0) yield { event, session, matchOffset, neighbors: context2 ? { events, index } : void 0 };
26509
+ }
26510
+ }
26543
26511
  function prepareSelection(projection, params) {
26544
- const folds = !params.roles && params.query === void 0;
26512
+ const { query, roles, session } = params;
26513
+ if (query) return { candidates: [...queryHits(projection, params, session)] };
26545
26514
  const candidates = [];
26546
26515
  let run = [];
26547
- for (const event of filteredItems(projection, params)) {
26548
- if (folds && (event.role === "tool" || event.role === "context")) {
26549
- run.push(event);
26550
- continue;
26516
+ for (const event of filteredItems(projection, params).filter(visible)) {
26517
+ if (!roles && (event.role === "tool" || event.role === "context")) run.push(event);
26518
+ else {
26519
+ candidates.push({ event, session, before: foldedRun(run, session) });
26520
+ run = [];
26551
26521
  }
26552
- if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
26553
- const matchOffset = params.query === void 0 ? void 0 : earliestMatchOffsetChars(eventDocument(event), params.query);
26554
- if (matchOffset !== void 0 && matchOffset < 0) continue;
26555
- candidates.push({ event, ...params.session === void 0 ? {} : { session: params.session }, matchOffset, before: foldedRun(run, params.session) });
26556
- run = [];
26557
26522
  }
26558
- return { candidates, session: params.session, tail: foldedRun(run, params.session) };
26523
+ return { candidates, tail: foldedRun(run, session) };
26559
26524
  }
26560
26525
  function pageData(prepared, start, end, maxChars, preview) {
26561
26526
  const { candidates, tail } = prepared;
@@ -26568,38 +26533,51 @@ function pageData(prepared, start, end, maxChars, preview) {
26568
26533
  const page = {
26569
26534
  items,
26570
26535
  ...end === candidates.length && tail ? { folded_after: tail } : {},
26571
- has_older: start > 0 && start < end || !!prepared.discarded && prepared.from !== "oldest",
26572
- has_newer: end < candidates.length && start < end || !!prepared.discarded && prepared.from === "oldest"
26536
+ has_older: start > 0 && start < end || !!prepared.discarded && !prepared.forward,
26537
+ has_newer: end < candidates.length && start < end || !!prepared.discarded && !!prepared.forward
26573
26538
  };
26574
26539
  return prepared.multi ? markMultiPage(page) : page;
26575
26540
  }
26576
- function resolveSelection(params) {
26577
- const bounds = resolveTimeBounds(params);
26578
- if (!bounds.ok) return bounds;
26579
- try {
26580
- const queries = searchQueries(params.query);
26581
- return success({ ...params, ...bounds.data, query: queries.length ? queries : void 0 });
26582
- } catch (error2) {
26583
- if (error2 instanceof InvalidQueryError) return failure2("invalid_query", error2.message);
26584
- throw error2;
26585
- }
26586
- }
26587
26541
  function selectPage(projection, params, fits, maxChars) {
26588
- const scoped = resolveSelection(params);
26589
- if (!scoped.ok) return scoped;
26590
- return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
26591
- }
26592
- function corpusSelection(params) {
26593
- if (params.before_seq !== void 0 || params.after_seq !== void 0) return failure2("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
26594
- return resolveSelection(params);
26542
+ return selectPrepared(prepareSelection(projection, params), params, fits, maxChars);
26595
26543
  }
26596
26544
  function sessionRepresentative(projection, scoped) {
26597
- const events = filteredItems(projection, scoped).filter((event) => event.role !== "user" && event.role !== "assistant" || eventDocument(event) !== "");
26545
+ const events = filteredItems(projection, scoped).filter(visible);
26598
26546
  if (scoped.roles) return events.at(-1);
26599
26547
  return events.find((event) => event.role === "user") ?? events.filter((event) => event.role === "assistant").at(-1) ?? events.at(-1);
26600
26548
  }
26601
- var eventTime = (event) => event.createdAt === void 0 || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
26602
- var compareCorpus = (a, b) => eventTime(a.event) - eventTime(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq;
26549
+ function eventTime(timestamp) {
26550
+ const at = Date.parse(timestamp ?? "");
26551
+ return Number.isNaN(at) ? -Infinity : at;
26552
+ }
26553
+ var compareCorpus = (a, b) => eventTime(a.event.createdAt) - eventTime(b.event.createdAt) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq;
26554
+ function addContext(page, hits, radius, fits, maxChars) {
26555
+ const key = (session, seq) => `${session ?? ""}\0${seq}`;
26556
+ const seen = new Set(page.items.map((item) => key(item.session, item.seq)));
26557
+ const compare = (a, b) => (isMultiPage(page) ? eventTime(a.created_at) - eventTime(b.created_at) || a.session.localeCompare(b.session) : 0) || a.seq - b.seq;
26558
+ for (let distance = 1; distance <= radius; distance++) {
26559
+ let found = false;
26560
+ for (const { neighbors, session } of hits) {
26561
+ if (!neighbors) continue;
26562
+ for (const index of [neighbors.index - distance, neighbors.index + distance]) {
26563
+ const event = neighbors.events[index];
26564
+ if (!event) continue;
26565
+ found = true;
26566
+ const id2 = key(session, event.seq);
26567
+ if (seen.has(id2)) continue;
26568
+ const item = { ...visibleItem(event, maxChars), ...session === void 0 ? {} : { session }, context: true };
26569
+ const previous = page.items;
26570
+ page.items = [...previous, item].sort(compare);
26571
+ if (!fits(page)) {
26572
+ page.items = previous;
26573
+ return;
26574
+ }
26575
+ seen.add(id2);
26576
+ }
26577
+ }
26578
+ if (!found) return;
26579
+ }
26580
+ }
26603
26581
  var CorpusCollector = class {
26604
26582
  constructor(scoped) {
26605
26583
  this.scoped = scoped;
@@ -26618,7 +26596,7 @@ var CorpusCollector = class {
26618
26596
  }
26619
26597
  if (this.candidates.length === this.limit) {
26620
26598
  this.discarded = true;
26621
- if (this.scoped.from === "oldest") {
26599
+ if (this.scoped.after) {
26622
26600
  if (low === this.limit) return;
26623
26601
  this.candidates.pop();
26624
26602
  } else {
@@ -26638,22 +26616,16 @@ var CorpusCollector = class {
26638
26616
  /** Returns whether this session contributes an overview representative. */
26639
26617
  add(session, projection) {
26640
26618
  if (this.scoped.query === void 0) return this.addRepresentative(session, sessionRepresentative(projection, this.scoped));
26641
- for (const event of filteredItems(projection, this.scoped)) {
26642
- const document = eventDocument(event);
26643
- if ((event.role === "user" || event.role === "assistant") && document === "") continue;
26644
- const matchOffset = earliestMatchOffsetChars(document, this.scoped.query);
26645
- if (matchOffset >= 0) this.admit({ session, event, matchOffset });
26646
- }
26619
+ for (const hit of queryHits(projection, this.scoped, session)) this.admit(hit);
26647
26620
  return true;
26648
26621
  }
26649
26622
  page(fits, maxChars, unvisited = false) {
26650
- return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited, from: this.scoped.from }, this.scoped, fits, maxChars);
26623
+ return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited, forward: !!this.scoped.after }, this.scoped, fits, maxChars);
26651
26624
  }
26652
26625
  };
26653
26626
  function selectPrepared(prepared, scoped, fits, maxChars) {
26654
26627
  const { candidates } = prepared;
26655
- const from = scoped.from ?? (scoped.after_seq !== void 0 ? "oldest" : "newest");
26656
- const newest = from === "newest";
26628
+ const newest = scoped.after === void 0;
26657
26629
  let start = newest ? candidates.length : 0;
26658
26630
  let end = start;
26659
26631
  const limit = Math.max(1, scoped.limit ?? 20);
@@ -26675,6 +26647,7 @@ function selectPrepared(prepared, scoped, fits, maxChars) {
26675
26647
  }
26676
26648
  const page = pageData(prepared, start, end, maxChars);
26677
26649
  if (!fits(page)) return { ok: false, pageTooLarge: { count: page.items.length, multi: prepared.multi === true } };
26650
+ if (scoped.context) addContext(page, candidates.slice(start, end), scoped.context, fits, maxChars);
26678
26651
  return success(page);
26679
26652
  }
26680
26653
 
@@ -26765,7 +26738,7 @@ function toolHeader(item) {
26765
26738
  }
26766
26739
  function renderPageItem(item) {
26767
26740
  const tool = toolHeader(item);
26768
- const lines = tool === void 0 ? [header(item)] : [header(item), tool];
26741
+ const lines = [header(item) + (item.context ? " | search context" : ""), ...tool ? [tool] : []];
26769
26742
  if (item.truncated) lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
26770
26743
  lines.push(item.content);
26771
26744
  return lines.join("\n");
@@ -26774,7 +26747,7 @@ function renderFoldedRow(row) {
26774
26747
  const tools2 = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
26775
26748
  const identity = row.session === void 0 ? {} : { session: row.session };
26776
26749
  const expand = `
26777
- \u2192 expand: ${JSON.stringify({ ...identity, after_seq: row.first_seq - 1, before_seq: row.last_seq + 1, roles: ["tool", "context"] })}`;
26750
+ \u2192 expand: ${JSON.stringify({ ...identity, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] })}`;
26778
26751
  return `${row.session === void 0 ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools2 ? ` | ${tools2}` : ""}${expand}`;
26779
26752
  }
26780
26753
  function renderPage(page) {
@@ -26784,13 +26757,14 @@ function renderPage(page) {
26784
26757
  const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
26785
26758
  return (page.notice ?? "") + body + (directions ? `
26786
26759
 
26787
- \u2192 more ${directions} results: narrow with since/until, query, roles or the session pattern` : "");
26760
+ \u2192 more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
26788
26761
  }
26789
- const first = page.items[0];
26790
- const last = page.items.at(-1);
26762
+ const hits = page.items.filter((item) => !item.context);
26763
+ const first = hits[0];
26764
+ const last = hits.at(-1);
26791
26765
  const cursors = [
26792
- page.has_older ? `\u2192 older: ${JSON.stringify({ ...first.session === void 0 ? {} : { session: first.session }, before_seq: first.seq })}` : "",
26793
- page.has_newer ? `\u2192 newer: ${JSON.stringify({ ...last.session === void 0 ? {} : { session: last.session }, after_seq: last.seq })}` : ""
26766
+ page.has_older ? `\u2192 older: ${JSON.stringify({ session: first.session, before: first.seq })}` : "",
26767
+ page.has_newer ? `\u2192 newer: ${JSON.stringify({ session: last.session, after: last.seq })}` : ""
26794
26768
  ].filter((line) => line !== "");
26795
26769
  return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}
26796
26770
 
@@ -26798,28 +26772,54 @@ ${cursors.join(" | ")}`);
26798
26772
  }
26799
26773
  function renderRead(data) {
26800
26774
  const tool = toolHeader(data);
26801
- const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...data.session === void 0 ? {} : { session: data.session }, after_seq: Math.max(0, data.seq - 10), before_seq: data.seq + 10 })})`;
26775
+ const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...data.session === void 0 ? {} : { session: data.session }, after: Math.max(0, data.seq - 10), before: data.seq + 10 })})`;
26802
26776
  return (data.notice ?? "") + [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
26803
26777
  }
26804
26778
  var plainText = (text2) => text2;
26805
26779
  function pageOutcome(result) {
26806
26780
  if (!("pageTooLarge" in result)) return result;
26807
26781
  const { count, multi } = result.pageTooLarge;
26808
- const narrow = multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
26782
+ const narrow = multi ? "narrow the session pattern, query, roles or time bounds (`after`/`before`), or read one session/seq with `history_read`" : "narrow with `after`/`before`, pass `roles` to skip folding, or `history_read` one seq";
26809
26783
  return failure2("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
26810
26784
  }
26785
+ var boundParameter = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Number()], { description: `${description} Use a seq (number or digits) or ISO 8601 time (UTC without offset); wildcards take only times.` }));
26811
26786
  var historyListParameters = typebox_exports.Object({
26812
26787
  session: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
26813
- query: typebox_exports.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
26814
26788
  roles: historyRoles(),
26815
- before_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Only entries before this seq." })),
26816
- after_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Only entries after this seq; 0 starts from the first page." })),
26817
- since: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Only entries at or after this time (ISO 8601; UTC without an offset)." })),
26818
- until: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Only entries before this time (ISO 8601; UTC without an offset)." })),
26819
- from: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("newest"), typebox_exports.Literal("oldest")], { description: "Which end `limit` counts from: newest or oldest. Entries still read oldest first." })),
26820
- limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
26789
+ query: typebox_exports.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
26790
+ after: boundParameter("Start strictly after this bound, paging forward; 0 starts at the oldest event."),
26791
+ before: boundParameter("Stop strictly before this bound; without `after`, take the newest eligible events."),
26792
+ context: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events on each side of a hit in its own session; requires a query." })),
26793
+ limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
26821
26794
  max_chars_per_item: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." }))
26822
26795
  }, { additionalProperties: false });
26796
+ var ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
26797
+ function parseBound(name, value) {
26798
+ if (value === void 0) return success(void 0);
26799
+ if (typeof value === "number" || /^\d+$/.test(value)) {
26800
+ const seq = Number(value);
26801
+ if (Number.isSafeInteger(seq) && seq >= 0) return success({ seq });
26802
+ } else if (typeof value === "string") {
26803
+ const match = ISO_8601.exec(value);
26804
+ const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
26805
+ if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10))) return success({ at });
26806
+ }
26807
+ return failure2("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
26808
+ }
26809
+ function parseSelection(params) {
26810
+ const after = parseBound("after", params.after);
26811
+ if (!after.ok) return after;
26812
+ const before = parseBound("before", params.before);
26813
+ if (!before.ok) return before;
26814
+ try {
26815
+ const query = searchQueries(params.query);
26816
+ if (!query.length && params.context !== void 0) return failure2("invalid_params", "`context` requires a non-empty `query`.");
26817
+ return success({ after: after.data, before: before.data, query: query.length ? query : void 0, roles: params.roles, context: params.context, limit: params.limit });
26818
+ } catch (error2) {
26819
+ if (error2 instanceof InvalidQueryError) return failure2("invalid_query", error2.message);
26820
+ throw error2;
26821
+ }
26822
+ }
26823
26823
  var historyList = {
26824
26824
  name: "history_list",
26825
26825
  label: "History list items",
@@ -26827,32 +26827,34 @@ var historyList = {
26827
26827
  parameters: historyListParameters,
26828
26828
  outputSchema: resultSchema(HistoryPageSchema),
26829
26829
  async execute(params, context2, wrapText = plainText) {
26830
+ const selection = parseSelection(params);
26831
+ if (!selection.ok) return selection;
26832
+ const scoped = selection.data;
26830
26833
  const fits = (page) => fitsResult(success(page), (result2) => wrapText(renderOutcome(result2, renderPage)));
26831
26834
  const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
26832
- if (params.session === void 0) return pageOutcome(selectPage(await currentHistory(context2), params, fits, maxChars));
26835
+ if (params.session === void 0) return pageOutcome(selectPage(await currentHistory(context2), scoped, fits, maxChars));
26833
26836
  const selector = parseSessionSelector(params.session);
26834
26837
  if (!selector.ok) return selector;
26835
26838
  const corpus = "corpus" in context2 ? context2.corpus : void 0;
26836
26839
  if (selector.data.wildcard) {
26837
- const scoped = corpusSelection(params);
26838
- if (!scoped.ok) return scoped;
26840
+ const { after, before, query, roles } = scoped;
26841
+ if (after && "seq" in after || before && "seq" in before) return failure2("invalid_bounds", "Wildcard history requires times, not seqs, for `after` and `before`.");
26839
26842
  if (corpus === void 0) return failure2("unknown_session", "This host supplied no cross-session history corpus.");
26840
26843
  const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
26841
- const queries = Array.isArray(scoped.data.query) ? scoped.data.query : void 0;
26842
- if (!queries) sessions.sort((a, b) => (scoped.data.from === "oldest" ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
26843
- const representative = !queries && scoped.data.roles === void 0 && scoped.data.since === void 0 && scoped.data.until === void 0;
26844
- const collector = new CorpusCollector(scoped.data);
26844
+ if (!query) sessions.sort((a, b) => (after ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
26845
+ const representative = !query && !roles && !after && !before;
26846
+ const collector = new CorpusCollector(scoped);
26845
26847
  let qualifying = 0;
26846
26848
  const notices = [];
26847
26849
  let unvisited = false;
26848
26850
  for (const [index, session] of sessions.entries()) {
26849
- const result3 = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, queries);
26851
+ const result3 = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, query);
26850
26852
  if (!result3.ok || !result3.data) continue;
26851
26853
  const added = "projection" in result3.data ? collector.add(sessionIdentity(session), result3.data.projection) : collector.addRepresentative(sessionIdentity(session), result3.data.event);
26852
26854
  if (!added) continue;
26853
26855
  qualifying++;
26854
26856
  if (result3.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result3.data.notice}`);
26855
- if (!queries && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
26857
+ if (!query && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
26856
26858
  unvisited = index + 1 < sessions.length;
26857
26859
  break;
26858
26860
  }
@@ -26866,7 +26868,7 @@ var historyList = {
26866
26868
  const loaded = await loadHistorySession(target.data);
26867
26869
  if (!loaded.ok) return loaded;
26868
26870
  const notice = loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice };
26869
- const result = pageOutcome(selectPage(loaded.data.projection, { ...params, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
26871
+ const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
26870
26872
  return result.ok ? success({ ...result.data, ...notice }) : result;
26871
26873
  },
26872
26874
  render: (result) => renderOutcome(result, renderPage)
@@ -28517,7 +28519,6 @@ var OPERATIONS = {
28517
28519
  notes_update: { operation: notesUpdate, history: false },
28518
28520
  notes_read: { operation: notesRead, history: false },
28519
28521
  notes_list: { operation: notesList, history: false },
28520
- notes_search: { operation: notesSearch, history: false },
28521
28522
  history_list: { operation: historyList, history: true },
28522
28523
  history_read: { operation: historyRead, history: true }
28523
28524
  };