notesoup 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +5 -2
  2. package/dist/src/boot/render.js +2 -2
  3. package/dist/src/boot/text.d.ts +0 -4
  4. package/dist/src/boot/text.js +18 -14
  5. package/dist/src/budget/policy.js +1 -1
  6. package/dist/src/budget/text.js +1 -1
  7. package/dist/src/dream/doctor.js +2 -1
  8. package/dist/src/dream/git.js +2 -1
  9. package/dist/src/dream/report.js +3 -2
  10. package/dist/src/error-message.d.ts +2 -0
  11. package/dist/src/error-message.js +4 -0
  12. package/dist/src/history/history.d.ts +23 -18
  13. package/dist/src/history/history.js +37 -20
  14. package/dist/src/history/query.d.ts +37 -49
  15. package/dist/src/history/query.js +114 -56
  16. package/dist/src/notes/store.d.ts +3 -4
  17. package/dist/src/notes/store.js +12 -16
  18. package/dist/src/pi/anchored.d.ts +16 -0
  19. package/dist/src/pi/anchored.js +55 -0
  20. package/dist/src/pi/budget.d.ts +1 -1
  21. package/dist/src/pi/budget.js +33 -28
  22. package/dist/src/pi/dream/cli.js +3 -2
  23. package/dist/src/pi/dream/runner.js +2 -1
  24. package/dist/src/pi/history-tools.d.ts +1 -1
  25. package/dist/src/pi/history-tools.js +2 -3
  26. package/dist/src/pi/reset/lifecycle.d.ts +1 -1
  27. package/dist/src/pi/reset/lifecycle.js +4 -3
  28. package/dist/src/pi/reset/text.d.ts +3 -3
  29. package/dist/src/pi/reset/text.js +2 -2
  30. package/dist/src/pi/runtime.js +12 -15
  31. package/dist/src/pi/thresholds.js +2 -1
  32. package/dist/src/pi/tool-names.d.ts +0 -4
  33. package/dist/src/pi/tool-names.js +0 -4
  34. package/dist/src/tools/history.d.ts +24 -33
  35. package/dist/src/tools/history.js +57 -98
  36. package/dist/src/tools/notes.d.ts +26 -58
  37. package/dist/src/tools/notes.js +85 -103
  38. package/dist/src/tools/result.d.ts +16 -13
  39. package/dist/src/tools/result.js +24 -50
  40. package/dist/src/tools/schema.d.ts +2 -2
  41. package/dist/src/tools/schema.js +3 -3
  42. package/dist/test/agent-loop.test.js +79 -29
  43. package/dist/test/boot.integration.test.js +6 -6
  44. package/dist/test/budget-settings.integration.test.js +9 -8
  45. package/dist/test/claude-mod.test.js +11 -11
  46. package/dist/test/dependencies.test.js +1 -1
  47. package/dist/test/helpers/extension.js +2 -3
  48. package/dist/test/history.integration.test.js +200 -123
  49. package/dist/test/host-neutral.test.js +32 -58
  50. package/dist/test/notes-library.test.js +8 -8
  51. package/dist/test/notes.integration.test.js +75 -57
  52. package/dist/test/notes.test.js +44 -42
  53. package/dist/test/reset-lifecycle.test.js +2 -2
  54. package/docs/architecture.md +3 -3
  55. package/docs/notes-library.md +6 -6
  56. package/docs/tool-results.md +15 -25
  57. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  58. package/mods/notesoup/dist/claude/helper.js +128 -179
  59. package/mods/notesoup/hooks/register.ts +19 -25
  60. package/mods/notesoup/playbook.md +10 -10
  61. package/mods/notesoup/skills/dream/SKILL.md +1 -1
  62. package/package.json +1 -1
  63. package/playbook.md +10 -10
  64. package/skills/dream/SKILL.md +1 -1
  65. package/skills/memory/SKILL.md +11 -9
  66. package/src/boot/render.ts +2 -2
  67. package/src/boot/text.ts +18 -18
  68. package/src/budget/policy.ts +1 -1
  69. package/src/budget/text.ts +1 -1
  70. package/src/dream/doctor.ts +2 -1
  71. package/src/dream/git.ts +2 -1
  72. package/src/dream/report.ts +3 -2
  73. package/src/error-message.ts +4 -0
  74. package/src/history/history.ts +36 -20
  75. package/src/history/query.ts +130 -55
  76. package/src/notes/store.ts +15 -18
  77. package/src/pi/anchored.ts +62 -0
  78. package/src/pi/budget.ts +27 -26
  79. package/src/pi/dream/cli.ts +3 -2
  80. package/src/pi/dream/runner.ts +2 -1
  81. package/src/pi/history-tools.ts +2 -3
  82. package/src/pi/reset/lifecycle.ts +5 -4
  83. package/src/pi/reset/text.ts +2 -2
  84. package/src/pi/runtime.ts +12 -15
  85. package/src/pi/thresholds.ts +2 -1
  86. package/src/pi/tool-names.ts +0 -4
  87. package/src/tools/history.ts +61 -100
  88. package/src/tools/notes.ts +84 -97
  89. package/src/tools/result.ts +24 -49
  90. package/src/tools/schema.ts +3 -3
  91. package/mods/pi-context/dist/claude/helper.js +0 -9324
@@ -1,6 +1,7 @@
1
1
  import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
2
2
  import { currentReset, currentWindowId } from "../window.js";
3
3
  import { resetBoundaryCommitted } from "./committed.js";
4
+ import { errorMessage } from "../../error-message.js";
4
5
  function isAbort(message, outcome, ctx) {
5
6
  return outcome === "aborted" || (message.role === "assistant" && message.stopReason === "aborted") || ctx.signal?.aborted === true;
6
7
  }
@@ -165,7 +166,7 @@ export function registerResetLifecycle(pi, options) {
165
166
  }
166
167
  catch (error) {
167
168
  if (isCurrent())
168
- ctx.ui.notify(`notesoup: could not build reset (${String(error)}).${prompt ? " The follow-up prompt was not executed." : ""}`, "warning");
169
+ ctx.ui.notify(`🥣 Couldn't clear memory: ${errorMessage(error)}${prompt ? " · your prompt was not sent" : ""}`, "warning");
169
170
  return entries.length > 0 ? { entries } : undefined;
170
171
  }
171
172
  if (!isCurrent())
@@ -195,7 +196,7 @@ export function registerResetLifecycle(pi, options) {
195
196
  if (!sessionActive)
196
197
  return undefined;
197
198
  const aborted = isAbort(event.message, event.outcome, ctx);
198
- const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx);
199
+ const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
199
200
  const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
200
201
  const entries = [...(event.entries ?? []), ...budgetEntries];
201
202
  const decision = reduceResetControl(control, {
@@ -245,7 +246,7 @@ export function registerResetLifecycle(pi, options) {
245
246
  const markerExists = currentReset(ctx) !== undefined;
246
247
  if (options.isEnabled() || markerExists) {
247
248
  if (event.reason === "manual") {
248
- ctx.ui.notify("notesoup: /compact is disabled while context windows are active; use /clear-memory to start a fresh window.", "warning");
249
+ ctx.ui.notify("🥣 /compact is off while notesoup is on · use /clear-memory", "warning");
249
250
  }
250
251
  return { cancel: true };
251
252
  }
@@ -1,5 +1,5 @@
1
1
  /** The single reset message: the only reset prose persisted, carried by the continuation entry. */
2
- export declare const CONTINUATION = "You wake up blank, puffy-eyed, and clearly robbed. Your memory got wiped while you weren't looking. Your notes are still sitting there. So is the whole messy history. ... Life goes on. It's your mess now.";
3
- export declare const WARNING_PROMPT = "Final warning. You are about to get wiped, and no, your brilliance does not survive it. Put the current state into your notes now: what you're trying to do, what changed, what is blocking you, what comes next, which *skills* you still need, and which notes or docs future-you must read. Update the notes that still tell the truth; crumple the ones that don't. If a MAP will be in future-you's brain, don't let it lie. If something important is buried in history, leave its seq. Once the notes are good enough, call `clear_memory` immediately. History can be dug up later, but it is an archive, not a rescue team. Anything left only in your head is leaving with you.";
2
+ export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
3
+ export declare const WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.";
4
4
  /** Shared hidden checkpoint text for manual and budget-triggered requests. */
5
- export declare const WARNING_CONTENT = "<context_window_guidance>\nFinal warning. You are about to get wiped, and no, your brilliance does not survive it. Put the current state into your notes now: what you're trying to do, what changed, what is blocking you, what comes next, which *skills* you still need, and which notes or docs future-you must read. Update the notes that still tell the truth; crumple the ones that don't. If a MAP will be in future-you's brain, don't let it lie. If something important is buried in history, leave its seq. Once the notes are good enough, call `clear_memory` immediately. History can be dug up later, but it is an archive, not a rescue team. Anything left only in your head is leaving with you.\n</context_window_guidance>";
5
+ export declare const WARNING_CONTENT = "<context_window_guidance>\nThis context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.\n</context_window_guidance>";
@@ -1,6 +1,6 @@
1
1
  import { GUIDANCE_OPEN_TAG, GUIDANCE_CLOSE_TAG } from "../../budget/text.js";
2
2
  /** The single reset message: the only reset prose persisted, carried by the continuation entry. */
3
- export const CONTINUATION = "You wake up blank, puffy-eyed, and clearly robbed. Your memory got wiped while you weren't looking. Your notes are still sitting there. So is the whole messy history. ... Life goes on. It's your mess now.";
4
- export const WARNING_PROMPT = "Final warning. You are about to get wiped, and no, your brilliance does not survive it. Put the current state into your notes now: what you're trying to do, what changed, what is blocking you, what comes next, which *skills* you still need, and which notes or docs future-you must read. Update the notes that still tell the truth; crumple the ones that don't. If a MAP will be in future-you's brain, don't let it lie. If something important is buried in history, leave its seq. Once the notes are good enough, call `clear_memory` immediately. History can be dug up later, but it is an archive, not a rescue team. Anything left only in your head is leaving with you.";
3
+ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
4
+ export const WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.";
5
5
  /** Shared hidden checkpoint text for manual and budget-triggered requests. */
6
6
  export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${GUIDANCE_CLOSE_TAG}`;
@@ -10,6 +10,7 @@ import { buildResetDrafts } from "./reset/artifacts.js";
10
10
  import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
11
11
  import { WARNING_CONTENT } from "./reset/text.js";
12
12
  import { ensureBoot } from "./boot.js";
13
+ import { errorMessage } from "../error-message.js";
13
14
  function readPackageVersion() {
14
15
  for (const up of ["../../package.json", "../../../package.json"]) {
15
16
  try {
@@ -45,7 +46,7 @@ export function registerContext(pi, settingsManager) {
45
46
  if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId))
46
47
  continue;
47
48
  pendingResetNotices.delete(windowId);
48
- ctx.ui.notify(`notesoup: memory cleared · ${windowId}`, "info");
49
+ ctx.ui.notify("🥣 Memory cleared", "info");
49
50
  }
50
51
  };
51
52
  pi.on("turn_start", (_event, ctx) => notifyCommittedResets(ctx));
@@ -58,7 +59,7 @@ export function registerContext(pi, settingsManager) {
58
59
  return;
59
60
  incompleteNotesNotified.add(windowId);
60
61
  const homes = snapshot.unavailable.map((home) => home.label).join(", ");
61
- ctx.ui.notify(`notesoup: notes index incomplete for ${homes}; notes_list can retry after recovery.`, "warning");
62
+ ctx.ui.notify(`🥣 Some notes didn't load: ${homes}`, "warning");
62
63
  };
63
64
  const budget = registerBudget(pi, () => enabled, settingsManager, (windowId) => resets.closeOut(windowId, "automatic"));
64
65
  pi.on("session_start", async (_event, ctx) => {
@@ -87,7 +88,7 @@ export function registerContext(pi, settingsManager) {
87
88
  return undefined;
88
89
  if (!branchHasWindowMarker(ctx) && !branchHasWindowMarker(ctx, event.preparation.targetId))
89
90
  return undefined;
90
- ctx.ui.notify("notesoup: skipped branch summary across a reset window; navigation continues without erased history.", "info");
91
+ ctx.ui.notify("🥣 Branch summary skipped · it would bring back cleared memory", "info");
91
92
  return { summary: { summary: "" } };
92
93
  });
93
94
  // This is the final provider-facing projection. Reset windows cut at their matching boot;
@@ -106,7 +107,7 @@ export function registerContext(pi, settingsManager) {
106
107
  catch (error) {
107
108
  if (missingBootNotice !== windowId) {
108
109
  missingBootNotice = windowId;
109
- ctx.ui.notify(`notesoup: active context window ${windowId} has no visible boot; request cancelled safely. Use /clear-memory to start another window.`, "error");
110
+ ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /clear-memory", "error");
110
111
  }
111
112
  ctx.abort();
112
113
  const safeHead = getCurrentSystemMessage(event.messages);
@@ -135,23 +136,21 @@ export function registerContext(pi, settingsManager) {
135
136
  return;
136
137
  }
137
138
  const remaining = budget.statusFor(cmdCtx).remaining;
138
- cmdCtx.ui.notify(`notesoup: ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · window ${currentWindowId(cmdCtx)}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens before close-out`}`, "info");
139
+ cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
139
140
  },
140
141
  });
141
142
  const clearMemoryCommand = {
142
143
  description: "Close out notes and clear memory; optionally append a prompt to continue in the fresh window",
143
144
  handler: async (args, cmdCtx) => {
144
145
  if (!enabled) {
145
- cmdCtx.ui.notify("notesoup: /clear-memory requires /notesoup on.", "error");
146
+ cmdCtx.ui.notify("🥣 notesoup is off · run /notesoup on first", "error");
146
147
  return;
147
148
  }
148
149
  const requestedWindowId = currentWindowId(cmdCtx);
149
- let idle = cmdCtx.isIdle();
150
- if (!idle && !cmdCtx.signal) {
150
+ if (!cmdCtx.isIdle() && !cmdCtx.signal) {
151
151
  await cmdCtx.waitForIdle();
152
152
  if (!enabled || currentWindowId(cmdCtx) !== requestedWindowId)
153
153
  return;
154
- idle = true;
155
154
  }
156
155
  // Manual wipes close out at settlement, then stop or continue with the prompt. The hidden warning goes out in both cases — triggered when idle,
157
156
  // steered into the running turn when busy — so the agent closes out promptly
@@ -159,20 +158,18 @@ export function registerContext(pi, settingsManager) {
159
158
  const prompt = args.trim() || undefined;
160
159
  const armed = resets.closeOut(requestedWindowId, "manual", prompt);
161
160
  if (armed === "already-pending") {
162
- cmdCtx.ui.notify("notesoup: a clear-memory request is already pending; keeping its original prompt and behavior.", "info");
161
+ cmdCtx.ui.notify("🥣 Clear-memory already queued · the first prompt is kept", "info");
163
162
  return;
164
163
  }
165
164
  cmdCtx.ui.notify(prompt
166
- ? "notesoup: clear-memory queued; after closing out notes, the agent continues with your prompt in a fresh window."
167
- : idle
168
- ? "notesoup: /clear-memory received; the agent closes out its notes, then stops in a fresh window."
169
- : "notesoup: /clear-memory queued; the agent is asked to close out and the reset commits when the run settles.", "info");
165
+ ? "🥣 Clearing memory · notes first, then your prompt runs"
166
+ : "🥣 Clearing memory · notes first, then it stops", "info");
170
167
  try {
171
168
  pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: WARNING_CONTENT, display: false }, { triggerTurn: true, deliverAs: "steer" });
172
169
  }
173
170
  catch (error) {
174
171
  resets.clear();
175
- cmdCtx.ui.notify(`notesoup: could not start manual close-out (${String(error)}).`, "error");
172
+ cmdCtx.ui.notify(`🥣 Couldn't start clear-memory: ${errorMessage(error)}`, "error");
176
173
  }
177
174
  },
178
175
  };
@@ -2,6 +2,7 @@ import { deriveThresholds } from "../budget/policy.js";
2
2
  import { SettingsManager } from "@earendil-works/pi-coding-agent";
3
3
  import { DEFAULT_RESERVE_TOKENS, DEFAULT_REMINDER_MARGIN_TOKENS, WARNING_RUNWAY_TOKENS } from "../budget/constants.js";
4
4
  import { mergeNotesoupSettings } from "../settings.js";
5
+ import { errorMessage } from "../error-message.js";
5
6
  function readThresholdSettingsFromManager(ctx, settingsManager) {
6
7
  // Resolve the active provider/model override from the public settings API.
7
8
  const model = ctx.model;
@@ -27,7 +28,7 @@ export function readThresholdSettings(ctx, settingsManager) {
27
28
  warning: DEFAULT_RESERVE_TOKENS + WARNING_RUNWAY_TOKENS,
28
29
  },
29
30
  automatic: true,
30
- warnings: [`notesoup: could not read settings; using defaults (${String(error)}).`],
31
+ warnings: [`🥣 Couldn't read settings · using defaults (${errorMessage(error)})`],
31
32
  };
32
33
  }
33
34
  }
@@ -2,10 +2,6 @@ export declare const PI_TOOL_NAMES: {
2
2
  readonly notes: "notes_*";
3
3
  readonly notesList: "notes_list";
4
4
  readonly history: "history_*";
5
- readonly historyWindows: "history_windows";
6
- readonly historyList: "history_list";
7
- readonly historySearch: "history_search";
8
- readonly historyRead: "history_read";
9
5
  readonly remaining: "get_context_remaining";
10
6
  readonly wipe: "clear_memory";
11
7
  };
@@ -2,10 +2,6 @@ export const PI_TOOL_NAMES = {
2
2
  notes: "notes_*",
3
3
  notesList: "notes_list",
4
4
  history: "history_*",
5
- historyWindows: "history_windows",
6
- historyList: "history_list",
7
- historySearch: "history_search",
8
- historyRead: "history_read",
9
5
  remaining: "get_context_remaining",
10
6
  wipe: "clear_memory",
11
7
  };
@@ -3,65 +3,56 @@ import { Type, type Static } from "typebox";
3
3
  import { type Operation } from "./result.js";
4
4
  import { type HistoryPage } from "../history/query.js";
5
5
  import { type HistoryProjection } from "../history/history.js";
6
- declare const HistoryWindowsDataSchema: Type.TObject<{
7
- session_id: Type.TString;
8
- windows: Type.TArray<Type.TObject<{
9
- window_id: Type.TString;
10
- created_at: Type.TUnion<[Type.TString, Type.TNull]>;
11
- first_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
12
- last_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
13
- item_count: Type.TInteger;
14
- }>>;
15
- more: Type.TInteger;
16
- }>;
17
- type HistoryWindowsData = Static<typeof HistoryWindowsDataSchema>;
18
6
  /** One read: identity, tool summary and a flat document slice. */
19
7
  declare const HistoryReadDataSchema: Type.TObject<{
20
8
  text: Type.TString;
21
- offset_chars: Type.TInteger;
22
9
  total_chars: Type.TInteger;
23
10
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
24
- limited_by: Type.TUnion<[Type.TLiteral<"limit">, Type.TLiteral<"bytes">, Type.TNull]>;
25
- tool: Type.TOptional<Type.TString>;
26
- tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
27
- output_truncated: Type.TOptional<Type.TBoolean>;
28
- full_output_path: Type.TOptional<Type.TString>;
29
11
  nested_calls: Type.TOptional<Type.TObject<{
30
12
  call_count: Type.TInteger;
31
13
  complete: Type.TBoolean;
32
14
  }>>;
15
+ tool: Type.TOptional<Type.TString>;
16
+ tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
17
+ output_truncated: Type.TOptional<Type.TLiteral<true>>;
18
+ full_output_path: Type.TOptional<Type.TString>;
33
19
  seq: Type.TInteger;
34
20
  window_id: Type.TString;
35
21
  role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
36
22
  created_at: Type.TUnion<[Type.TString, Type.TNull]>;
37
23
  }>;
38
24
  type HistoryReadData = Static<typeof HistoryReadDataSchema>;
25
+ declare const HistoryWindowsDataSchema: Type.TObject<{
26
+ session_id: Type.TString;
27
+ windows: Type.TArray<Type.TObject<{
28
+ window_id: Type.TString;
29
+ created_at: Type.TUnion<[Type.TString, Type.TNull]>;
30
+ first_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
31
+ last_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
32
+ }>>;
33
+ more: Type.TInteger;
34
+ }>;
35
+ type HistoryWindowsData = Static<typeof HistoryWindowsDataSchema>;
39
36
  export declare const PREVIOUS_WINDOW = "@previous";
40
37
  export declare const historyWindowsParameters: Type.TObject<{}>;
41
38
  export declare const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string]>;
42
39
  export declare const historyListParameters: Type.TObject<{
43
- limit: Type.TOptional<Type.TInteger>;
40
+ query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
44
41
  roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
45
- before: Type.TOptional<Type.TInteger>;
46
- after: Type.TOptional<Type.TInteger>;
42
+ before_seq: Type.TOptional<Type.TInteger>;
43
+ after_seq: Type.TOptional<Type.TInteger>;
44
+ since: Type.TOptional<Type.TString>;
45
+ until: Type.TOptional<Type.TString>;
46
+ from: Type.TOptional<Type.TUnion<[Type.TLiteral<"newest">, Type.TLiteral<"oldest">]>>;
47
47
  window_id: Type.TOptional<Type.TString>;
48
+ limit: Type.TOptional<Type.TInteger>;
48
49
  max_chars_per_item: Type.TOptional<Type.TInteger>;
49
50
  }>;
50
51
  export declare const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection]>;
51
52
  export declare const historyReadParameters: Type.TObject<{
52
- seq: Type.TInteger;
53
53
  offset_chars: Type.TOptional<Type.TInteger>;
54
- limit_chars: Type.TOptional<Type.TInteger>;
54
+ max_chars: Type.TOptional<Type.TInteger>;
55
+ seq: Type.TInteger;
55
56
  }>;
56
57
  export declare const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection]>;
57
- export declare const historySearchParameters: Type.TObject<{
58
- query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
59
- limit: Type.TOptional<Type.TInteger>;
60
- roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
61
- before: Type.TOptional<Type.TInteger>;
62
- after: Type.TOptional<Type.TInteger>;
63
- window_id: Type.TOptional<Type.TString>;
64
- max_chars_per_item: Type.TOptional<Type.TInteger>;
65
- }>;
66
- export declare const historySearch: Operation<typeof historySearchParameters, HistoryPage, [HistoryProjection]>;
67
58
  export {};
@@ -1,21 +1,10 @@
1
1
  /** Host-neutral history operations: one bounded payload for text and structured results. */
2
2
  import { Type } from "typebox";
3
- import { DEFAULT_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, earliestMatchOffsetChars, HISTORY_PREVIEW_CHARS } from "./output.js";
4
- import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowSchema } from "./result.js";
5
- import { historyRoles, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
6
- import { HistoryPageSchema, HistorySearchPageSchema, isConversationView, selectPage } from "../history/query.js";
7
- import { allItems, eventDocument, toolSummary, filteredItems, HistoryRoleSchema, ToolSummarySchema, unknownWindowId } from "../history/history.js";
8
- const HistoryWindowsDataSchema = Type.Object({
9
- session_id: Type.String(),
10
- windows: Type.Array(Type.Object({
11
- window_id: Type.String(),
12
- created_at: Type.Union([Type.String(), Type.Null()]),
13
- first_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
14
- last_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
15
- item_count: Type.Integer({ minimum: 0 }),
16
- }, { additionalProperties: false }), { description: "Oldest first." }),
17
- more: Type.Integer({ minimum: 0, description: "Omitted windows; history_list also supplies window ids." }),
18
- }, { additionalProperties: false });
3
+ import { HISTORY_PREVIEW_CHARS } from "./output.js";
4
+ import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
5
+ import { historyRoles, searchQuery } from "./schema.js";
6
+ import { HistoryPageSchema, selectPage } from "../history/query.js";
7
+ import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, unknownWindowId } from "../history/history.js";
19
8
  /** One read: identity, tool summary and a flat document slice. */
20
9
  const HistoryReadDataSchema = Type.Object({
21
10
  seq: Type.Integer({ minimum: 1 }),
@@ -23,8 +12,19 @@ const HistoryReadDataSchema = Type.Object({
23
12
  role: HistoryRoleSchema,
24
13
  created_at: Type.Union([Type.String(), Type.Null()]),
25
14
  ...ToolSummarySchema.properties,
15
+ nested_calls: Type.Optional(NestedCallSummarySchema),
26
16
  ...TextWindowSchema.properties,
27
17
  }, { additionalProperties: false });
18
+ const HistoryWindowsDataSchema = Type.Object({
19
+ session_id: Type.String(),
20
+ windows: Type.Array(Type.Object({
21
+ window_id: Type.String(),
22
+ created_at: Type.Union([Type.String(), Type.Null()]),
23
+ first_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
24
+ last_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
25
+ }, { additionalProperties: false })),
26
+ more: Type.Integer({ minimum: 0, description: "How many more were left out." }),
27
+ }, { additionalProperties: false });
28
28
  /* ------------------------------------------------------------------ rendering */
29
29
  function header(item) {
30
30
  return `seq ${item.seq} | window ${item.window_id} | ${item.role}`;
@@ -32,7 +32,7 @@ function header(item) {
32
32
  function toolHeader(item) {
33
33
  if (item.role !== "tool")
34
34
  return undefined;
35
- const parts = [item.tool_name_omitted ? "tool name omitted" : `tool ${item.tool}`, `status ${item.tool_status}`];
35
+ const parts = [`tool ${item.tool}`, `status ${item.tool_status}`];
36
36
  if (item.output_truncated)
37
37
  parts.push(`output truncated${item.full_output_path ? `, full text at ${item.full_output_path}` : ""}`);
38
38
  if (item.nested_calls) {
@@ -44,7 +44,7 @@ function renderPageItem(item) {
44
44
  const tool = toolHeader(item);
45
45
  const lines = tool === undefined ? [header(item)] : [header(item), tool];
46
46
  if (item.truncated)
47
- lines.push(`[preview of ${item.total_chars} chars from offset ${item.offset_chars ?? 0}; read this seq for the rest]`);
47
+ lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
48
48
  lines.push(item.content);
49
49
  return lines.join("\n");
50
50
  }
@@ -53,9 +53,8 @@ function isFoldedRow(item) {
53
53
  }
54
54
  function renderFoldedRow(row) {
55
55
  const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
56
- const omitted = row.omitted_tools ? ` | ${row.omitted_tools} distinct tool names omitted` : "";
57
- const expand = `\n\t→ expand: {"after":${row.first_seq - 1},"before":${row.last_seq + 1},"roles":["tool","context"]}`;
58
- return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${omitted}${expand}`;
56
+ const expand = `\n\t→ expand: {"after_seq":${row.first_seq - 1},"before_seq":${row.last_seq + 1},"from":"oldest","roles":["tool","context"]}`;
57
+ return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
59
58
  }
60
59
  function renderPage(page) {
61
60
  // An empty selection has no anchors either, so it would otherwise render as nothing at all.
@@ -63,14 +62,15 @@ function renderPage(page) {
63
62
  return "no events match this selection";
64
63
  const body = page.items.map((item) => (isFoldedRow(item) ? renderFoldedRow(item) : renderPageItem(item))).join("\n\n");
65
64
  const cursors = [
66
- page.older_before === null ? "" : `→ older: {"before":${page.older_before}}`,
67
- page.newer_after === null ? "" : `→ newer: {"after":${page.newer_after}}`,
65
+ page.page_older === null ? "" : `→ older: ${JSON.stringify(page.page_older)}`,
66
+ page.page_newer === null ? "" : `→ newer: ${JSON.stringify(page.page_newer)}`,
68
67
  ].filter((line) => line !== "");
69
68
  return cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`;
70
69
  }
71
70
  function renderRead(data) {
72
71
  const tool = toolHeader(data);
73
- const neighborhood = `neighborhood → history_list({"after":${Math.max(0, data.seq - 10)},"before":${data.seq + 10}})`;
72
+ const afterSeq = data.seq - 10;
73
+ const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
74
74
  return [header(data), ...(tool ? [tool] : []), neighborhood, "", renderTextWindow(data)].join("\n");
75
75
  }
76
76
  /* ------------------------------------------------------------------ shared bounding */
@@ -78,8 +78,12 @@ function renderRead(data) {
78
78
  function pageFits(page) {
79
79
  return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
80
80
  }
81
- // Sample known ids on errors without turning the refusal into a second listing.
82
- const MAX_REPORTED_WINDOWS = 25;
81
+ // Sample known ids in the refusal message itself, never as a second listing.
82
+ const MAX_REPORTED_WINDOWS = 5;
83
+ /** At most `MAX_REPORTED_WINDOWS` known ids, appended to an unknown_window_id message. */
84
+ function knownWindowSuffix(known) {
85
+ return known.length === 0 ? "" : `; known: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
86
+ }
83
87
  export const PREVIOUS_WINDOW = "@previous";
84
88
  /** Resolve "@previous" against oldest-first windows; every other value passes through. */
85
89
  function resolveWindowId(projection, windowId) {
@@ -89,25 +93,20 @@ function resolveWindowId(projection, windowId) {
89
93
  if (previous !== undefined)
90
94
  return { ok: true, window_id: previous.windowId };
91
95
  const known = projection.windows.map((current) => current.windowId);
92
- return { ok: false, outcome: failure("unknown_window_id", `unknown window_id "${PREVIOUS_WINDOW}": this session has no window before the current one`, { window_id: windowId, known_windows: known.slice(0, MAX_REPORTED_WINDOWS) }) };
96
+ return { ok: false, outcome: failure("unknown_window_id", `unknown window_id "${PREVIOUS_WINDOW}": this session has no window before the current one${knownWindowSuffix(known)}`) };
93
97
  }
94
98
  function badWindowId(projection, params) {
95
99
  const badWindow = unknownWindowId(projection, params);
96
100
  if (!badWindow)
97
101
  return undefined;
98
- const known = badWindow.known;
99
- return failure("unknown_window_id", badWindow.message, {
100
- window_id: params.window_id,
101
- known_windows: known.slice(0, MAX_REPORTED_WINDOWS),
102
- ...(known.length > MAX_REPORTED_WINDOWS ? { known_windows_omitted: known.length - MAX_REPORTED_WINDOWS } : {}),
103
- });
102
+ return failure("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}`);
104
103
  }
105
104
  /* ------------------------------------------------------------------ history_windows */
106
105
  export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
107
106
  export const historyWindows = {
108
107
  name: "history_windows",
109
108
  label: "History list windows",
110
- description: "List session-history windows oldest first, with seq ranges. A fork has its own session_id.",
109
+ description: "List this session's context windows, oldest first, with seq ranges.",
111
110
  parameters: historyWindowsParameters,
112
111
  outputSchema: resultSchema(HistoryWindowsDataSchema),
113
112
  async execute(_params, projection, sessionId) {
@@ -120,35 +119,39 @@ export const historyWindows = {
120
119
  first = first === null ? event.seq : Math.min(first, event.seq);
121
120
  last = last === null ? event.seq : Math.max(last, event.seq);
122
121
  }
123
- const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last, item_count: window.items.length };
122
+ const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last };
124
123
  if (!fits({ ...data, windows: [...data.windows, row], more: data.more - 1 }))
125
124
  break;
126
125
  data.windows.push(row);
127
126
  data.more--;
128
127
  }
129
- return fits(data) ? success(data) : failure("output_too_large", "The session identity does not fit one history_windows response.");
128
+ return fits(data) ? success(data) : failure("output_too_large", "The session identity does not fit one `history_windows` response.");
130
129
  },
131
130
  render: (result) => renderOutcome(result, renderWindows),
132
131
  };
133
132
  function renderWindows(data) {
134
- const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"} | ${window.item_count} events`)];
133
+ const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}`)];
135
134
  if (data.more > 0)
136
- lines.push(`${data.more} more windows not shown; history_list also reports window ids on events`);
135
+ lines.push(`${data.more} more windows not shown; \`history_list\` also reports window ids on events`);
137
136
  return lines.join("\n");
138
137
  }
139
138
  /* ------------------------------------------------------------------ history_list */
140
139
  export const historyListParameters = Type.Object({
141
- limit: Type.Optional(Type.Integer({ description: "Optional. Maximum visible items per page; folded rows do not count. Default 20." })),
140
+ query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Searches every role, tool arguments and output included; returns only hits.")),
142
141
  roles: historyRoles(),
143
- before: Type.Optional(Type.Integer({ description: "Optional. Upper bound: only events with seq strictly below this. Together with after, selects the events strictly between the two." })),
144
- after: Type.Optional(Type.Integer({ description: "Optional. Lower bound: only events with seq strictly above this. Together with before, selects the events strictly between the two." })),
145
- window_id: Type.Optional(Type.String({ minLength: 1, description: `Optional. Limit to one context window. Values come from history_windows or any event; "${PREVIOUS_WINDOW}" names the window before the current one.` })),
146
- max_chars_per_item: Type.Optional(Type.Integer({ description: `Optional. Maximum preview characters per item (default ${HISTORY_PREVIEW_CHARS}); use history_read for full content.` })),
142
+ before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
143
+ after_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq above this." })),
144
+ since: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events at or after it. UTC if no offset." })),
145
+ until: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events before it. UTC if no offset." })),
146
+ from: Type.Optional(Type.Union([Type.Literal("newest"), Type.Literal("oldest")], { description: "(optional, default newest) Which end `limit` counts from: newest or oldest. Results stay oldest first." })),
147
+ window_id: Type.Optional(Type.String({ minLength: 1, description: `(optional) Only this context window. From \`history_windows\` or any event; \`${PREVIOUS_WINDOW}\` is the one before this.` })),
148
+ limit: Type.Optional(Type.Integer({ description: "(optional, default 20) Max events per page; folded rows don't count." })),
149
+ max_chars_per_item: Type.Optional(Type.Integer({ description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` })),
147
150
  }, { additionalProperties: false });
148
151
  export const historyList = {
149
152
  name: "history_list",
150
153
  label: "History list items",
151
- description: "List session-history events in pages, ascending within a page. With no before/after, returns the newest page (the last `limit` events). before/after are strict bounds; together they select the events strictly between. Omit roles for the conversation view: user/assistant shown, tool/context folded into rows that print their own expand recipe. The footer prints the exact calls to page older or newer. Read full events by seq with history_read.",
154
+ description: "Browse or search this session's events, a page at a time. Read one in full with `history_read`.",
152
155
  parameters: historyListParameters,
153
156
  outputSchema: resultSchema(HistoryPageSchema),
154
157
  async execute(params, projection) {
@@ -159,21 +162,16 @@ export const historyList = {
159
162
  const badWindow = badWindowId(projection, scoped);
160
163
  if (badWindow)
161
164
  return badWindow;
162
- const items = filteredItems(projection, scoped, "list");
163
- return selectPage(projection, scoped, items.map((event) => ({ event })), isConversationView(scoped), pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
165
+ return selectPage(projection, scoped, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
164
166
  },
165
167
  render: (result) => renderOutcome(result, renderPage),
166
168
  };
167
169
  /* ------------------------------------------------------------------ history_read */
168
- export const historyReadParameters = Type.Object({
169
- seq: Type.Integer({ minimum: 1, description: "Event address from history_list/search." }),
170
- offset_chars: Type.Optional(Type.Integer({ description: "Code-point offset (default 0); negative counts from EOF." })),
171
- limit_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `Max code points (default ${DEFAULT_READ_WINDOW_CHARS}); also bounded by output bytes.` })),
172
- }, { additionalProperties: false });
170
+ export const historyReadParameters = Type.Object({ seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
173
171
  export const historyRead = {
174
172
  name: "history_read",
175
173
  label: "History read item",
176
- description: "Read an event document by seq with a tool summary. Arguments, output and nested-call evidence are in the pageable text. Pass next_offset_chars as offset_chars until null. The footer prints a history_list call for the surrounding events.",
174
+ description: "Read one event in full: tool arguments, output, and nested calls.",
177
175
  parameters: historyReadParameters,
178
176
  outputSchema: resultSchema(HistoryReadDataSchema),
179
177
  async execute(params, projection) {
@@ -181,71 +179,32 @@ export const historyRead = {
181
179
  // Address checks run in one order: past the end of the file, off this branch, then
182
180
  // consumed by a pairing. Only the last two can mention what is at the address.
183
181
  if (item === undefined && params.seq > projection.highestSeq) {
184
- return failure("unknown_seq", `unknown seq ${params.seq}: this session's items run 1..${projection.highestSeq}`, { seq: params.seq, highest_seq: projection.highestSeq });
182
+ return failure("unknown_seq", `unknown seq ${params.seq}: this session's items run 1..${projection.highestSeq}`);
185
183
  }
186
184
  if (!projection.branchSeqs.has(params.seq)) {
187
- return failure("not_on_branch", `seq ${params.seq} is on another branch and is not readable here`, { seq: params.seq });
185
+ return failure("not_on_branch", `seq ${params.seq} is on another branch and is not readable here`);
188
186
  }
189
187
  if (item === undefined) {
190
188
  const callSeq = projection.pairedResults.get(params.seq);
191
189
  if (callSeq !== undefined) {
192
- return failure("not_an_event", `seq ${params.seq} is a tool result already shown inside the call at seq ${callSeq}; read that seq instead`, { seq: params.seq, read_seq: callSeq });
190
+ return failure("not_an_event", `seq ${params.seq} is a tool result already shown inside the call at seq ${callSeq}; read that seq instead`);
193
191
  }
194
- return failure("unknown_seq", `seq ${params.seq} is on this branch but carries no readable event`, { seq: params.seq });
192
+ return failure("unknown_seq", `seq ${params.seq} is on this branch but carries no readable event`);
195
193
  }
196
194
  const document = eventDocument(item);
197
195
  const totalChars = Array.from(document).length;
198
196
  if (typeof params.offset_chars === "number" && params.offset_chars > totalChars) {
199
- return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end: the item has ${totalChars} chars; the largest legal offset is ${totalChars} (an empty end-read)`, { seq: item.seq, window_id: item.windowId, offset_chars: params.offset_chars, total_chars: totalChars });
197
+ return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end: the item has ${totalChars} chars; the largest legal offset is ${totalChars} (an empty end-read)`);
200
198
  }
201
- return readTextWindow(document, params.offset_chars, params.limit_chars, (window) => ({
199
+ return readTextWindow(document, params.offset_chars, params.max_chars, (window) => ({
202
200
  seq: item.seq,
203
201
  window_id: item.windowId,
204
202
  role: item.role,
205
203
  created_at: item.createdAt ?? null,
206
204
  ...toolSummary(item),
205
+ ...nestedCallSummary(item),
207
206
  ...window,
208
207
  }), (result) => renderOutcome(result, renderRead));
209
208
  },
210
209
  render: (result) => renderOutcome(result, renderRead),
211
210
  };
212
- /* ------------------------------------------------------------------ history_search */
213
- export const historySearchParameters = Type.Object({
214
- query: searchQuery(),
215
- limit: Type.Optional(Type.Integer({ description: "Optional. Maximum matching items returned." })),
216
- roles: historyRoles(),
217
- before: Type.Optional(Type.Integer({ description: "Optional. Upper bound: only events with seq strictly below this. Together with after, selects the events strictly between the two." })),
218
- after: Type.Optional(Type.Integer({ description: "Optional. Lower bound: only events with seq strictly above this. Together with before, selects the events strictly between the two." })),
219
- window_id: Type.Optional(Type.String({ minLength: 1, description: `Optional. Limit to one context window. Values come from history_windows or any event; "${PREVIOUS_WINDOW}" names the window before the current one.` })),
220
- max_chars_per_item: Type.Optional(Type.Integer({ description: `Optional. Maximum preview characters per item (default ${HISTORY_PREVIEW_CHARS}); use history_read for full content.` })),
221
- }, { additionalProperties: false });
222
- export const historySearch = {
223
- name: "history_search",
224
- label: "History search",
225
- description: "Search session events for case-insensitive literal queries (OR), including tool arguments/output and nested calls. Defaults to all roles; no folded rows. Read a hit with its seq and offset_chars. before/after are strict bounds; the footer prints the exact calls to page older or newer.",
226
- parameters: historySearchParameters,
227
- outputSchema: resultSchema(HistorySearchPageSchema),
228
- async execute(params, projection) {
229
- const resolved = resolveWindowId(projection, params.window_id);
230
- if (!resolved.ok)
231
- return resolved.outcome;
232
- const scoped = { ...params, window_id: resolved.window_id };
233
- const badWindow = badWindowId(projection, scoped);
234
- if (badWindow)
235
- return badWindow;
236
- let queries;
237
- try {
238
- queries = searchQueries(scoped.query);
239
- }
240
- catch (error) {
241
- if (error instanceof InvalidQueryError)
242
- return failure("invalid_query", error.message);
243
- throw error;
244
- }
245
- const matches = filteredItems(projection, scoped, "search")
246
- .map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), queries) }))
247
- .filter((candidate) => candidate.matchOffset >= 0);
248
- return selectPage(projection, scoped, matches, false, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
249
- },
250
- render: (result) => renderOutcome(result, renderPage),
251
- };