notesoup 0.60.1 → 0.62.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 (200) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -10
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +2 -1
  10. package/dist/plugins/codex/src/hooks.js +1 -0
  11. package/dist/plugins/codex/src/identity.d.ts +6 -1
  12. package/dist/plugins/codex/src/identity.js +13 -1
  13. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  14. package/dist/plugins/codex/src/mcp.js +26 -88
  15. package/dist/plugins/codex/src/text.js +3 -3
  16. package/dist/plugins/dsh/tools.js +8 -4
  17. package/dist/plugins/mcp/operations.d.ts +15 -0
  18. package/dist/plugins/mcp/operations.js +43 -0
  19. package/dist/plugins/mcp/server.d.ts +14 -0
  20. package/dist/plugins/mcp/server.js +13 -0
  21. package/dist/plugins/pi/budget.d.ts +1 -1
  22. package/dist/plugins/pi/budget.js +3 -2
  23. package/dist/plugins/pi/entries.d.ts +1 -0
  24. package/dist/plugins/pi/entries.js +1 -0
  25. package/dist/plugins/pi/history-tools.js +2 -1
  26. package/dist/plugins/pi/history.js +18 -1
  27. package/dist/plugins/pi/notes/tools.js +7 -3
  28. package/dist/plugins/pi/render.d.ts +7 -1
  29. package/dist/plugins/pi/render.js +2 -2
  30. package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
  31. package/dist/plugins/pi/reset/lifecycle.js +8 -9
  32. package/dist/plugins/pi/runtime.js +102 -61
  33. package/dist/plugins/pi/tool-result.js +7 -7
  34. package/dist/plugins/pi/window.d.ts +33 -3
  35. package/dist/plugins/pi/window.js +209 -9
  36. package/dist/src/boot/render.d.ts +5 -0
  37. package/dist/src/boot/render.js +60 -28
  38. package/dist/src/boot/text.d.ts +3 -3
  39. package/dist/src/boot/text.js +27 -26
  40. package/dist/src/budget/text.d.ts +2 -2
  41. package/dist/src/budget/text.js +13 -13
  42. package/dist/src/history/claude.d.ts +2 -0
  43. package/dist/src/history/claude.js +46 -0
  44. package/dist/src/history/codex-transcript.js +7 -5
  45. package/dist/src/history/codex.js +3 -0
  46. package/dist/src/history/corpus.d.ts +28 -1
  47. package/dist/src/history/corpus.js +40 -0
  48. package/dist/src/history/history.d.ts +37 -46
  49. package/dist/src/history/history.js +21 -40
  50. package/dist/src/history/local.js +67 -32
  51. package/dist/src/history/pi.d.ts +2 -1
  52. package/dist/src/history/pi.js +122 -48
  53. package/dist/src/history/prefilter.js +76 -19
  54. package/dist/src/history/query.d.ts +28 -49
  55. package/dist/src/history/query.js +83 -68
  56. package/dist/src/history/summary-cache.d.ts +8 -1
  57. package/dist/src/history/summary-cache.js +138 -12
  58. package/dist/src/index.d.ts +1 -1
  59. package/dist/src/index.js +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +4 -0
  61. package/dist/src/notes/frontmatter.js +15 -1
  62. package/dist/src/notes/index.d.ts +1 -1
  63. package/dist/src/notes/index.js +1 -1
  64. package/dist/src/notes/policy.d.ts +15 -1
  65. package/dist/src/notes/policy.js +47 -6
  66. package/dist/src/notes/store.d.ts +14 -0
  67. package/dist/src/notes/store.js +33 -12
  68. package/dist/src/text-match.d.ts +10 -1
  69. package/dist/src/text-match.js +42 -3
  70. package/dist/src/tools/dream.d.ts +22 -91
  71. package/dist/src/tools/dream.js +30 -27
  72. package/dist/src/tools/history.d.ts +33 -26
  73. package/dist/src/tools/history.js +257 -163
  74. package/dist/src/tools/notes.d.ts +58 -160
  75. package/dist/src/tools/notes.js +151 -99
  76. package/dist/src/tools/output.d.ts +2 -1
  77. package/dist/src/tools/output.js +2 -1
  78. package/dist/src/tools/result.d.ts +4 -7
  79. package/dist/src/tools/result.js +8 -9
  80. package/dist/src/tools/schema.d.ts +4 -1
  81. package/dist/src/tools/schema.js +25 -1
  82. package/dist/test/agent-loop.test.js +198 -16
  83. package/dist/test/antigravity-live.test.d.ts +1 -0
  84. package/dist/test/antigravity-live.test.js +142 -0
  85. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  86. package/dist/test/antigravity-plugin.test.js +101 -0
  87. package/dist/test/boot.integration.test.js +133 -14
  88. package/dist/test/claude-history.test.js +14 -13
  89. package/dist/test/claude-mod.test.js +9 -6
  90. package/dist/test/codex-history.test.js +15 -3
  91. package/dist/test/codex-plugin.test.js +76 -38
  92. package/dist/test/dependencies.test.js +7 -3
  93. package/dist/test/dream-skill.test.js +3 -3
  94. package/dist/test/dream-tools.test.js +101 -56
  95. package/dist/test/dsh.test.js +34 -19
  96. package/dist/test/helpers/dependency-graph.js +2 -2
  97. package/dist/test/helpers/extension.d.ts +65 -2
  98. package/dist/test/helpers/extension.js +72 -3
  99. package/dist/test/history-corpus.test.js +79 -77
  100. package/dist/test/history-summary-cache.test.js +97 -9
  101. package/dist/test/history.integration.test.js +234 -168
  102. package/dist/test/host-neutral.test.js +69 -19
  103. package/dist/test/marker.test.js +1 -1
  104. package/dist/test/note-policy.test.js +189 -56
  105. package/dist/test/notes.integration.test.js +212 -94
  106. package/dist/test/notes.test.js +184 -113
  107. package/dist/test/pi-render.test.js +20 -12
  108. package/dist/test/project-namespace.test.js +3 -2
  109. package/dist/test/reset-lifecycle.test.js +2 -2
  110. package/docs/antigravity.md +44 -0
  111. package/docs/architecture.md +6 -4
  112. package/docs/claude-code-mod.md +2 -2
  113. package/docs/codex.md +36 -38
  114. package/docs/dsh.md +4 -4
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +6 -6
  117. package/docs/reset-lifecycle.md +1 -1
  118. package/docs/skills.md +3 -3
  119. package/docs/tool-results.md +47 -28
  120. package/package.json +3 -2
  121. package/playbook.md +3 -3
  122. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  123. package/plugins/antigravity/hooks.json +7 -0
  124. package/plugins/antigravity/mcp_config.json +8 -0
  125. package/plugins/antigravity/plugin.json +6 -0
  126. package/plugins/antigravity/src/cli.ts +22 -0
  127. package/plugins/antigravity/src/hooks.ts +51 -0
  128. package/plugins/antigravity/src/identity.ts +127 -0
  129. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  130. package/plugins/claude/dist/claude/helper.js +1129 -549
  131. package/plugins/claude/hooks/register.ts +2 -2
  132. package/plugins/claude/playbook.md +3 -3
  133. package/plugins/claude/skills/dream/SKILL.md +2 -2
  134. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  135. package/plugins/claude/src/helper.ts +2 -1
  136. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  137. package/plugins/codex/.mcp.json +11 -0
  138. package/plugins/codex/README.md +5 -21
  139. package/plugins/codex/dist/codex/notesoup.js +18494 -17905
  140. package/plugins/codex/src/hooks.ts +1 -0
  141. package/plugins/codex/src/identity.ts +14 -1
  142. package/plugins/codex/src/mcp.ts +28 -98
  143. package/plugins/codex/src/text.ts +3 -3
  144. package/plugins/dsh/tools.ts +8 -4
  145. package/plugins/mcp/operations.ts +50 -0
  146. package/plugins/mcp/server.ts +23 -0
  147. package/plugins/paseo/README.md +5 -10
  148. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  149. package/plugins/paseo/client/markdown.tsx +50 -38
  150. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  151. package/plugins/paseo/client/paper-card.tsx +6 -5
  152. package/plugins/paseo/client/paper-palette.ts +2 -9
  153. package/plugins/paseo/client/sticky-card.tsx +2 -2
  154. package/plugins/paseo/client/tool-result.ts +7 -14
  155. package/plugins/paseo/package-lock.json +3406 -0
  156. package/plugins/paseo/package.json +1 -0
  157. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  158. package/plugins/pi/budget.ts +3 -3
  159. package/plugins/pi/entries.ts +1 -0
  160. package/plugins/pi/history-tools.ts +2 -1
  161. package/plugins/pi/history.ts +30 -1
  162. package/plugins/pi/notes/tools.ts +7 -3
  163. package/plugins/pi/render.ts +6 -6
  164. package/plugins/pi/reset/lifecycle.ts +9 -10
  165. package/plugins/pi/runtime.ts +96 -60
  166. package/plugins/pi/tool-result.ts +8 -8
  167. package/plugins/pi/window.ts +198 -9
  168. package/skills/dream/SKILL.md +2 -2
  169. package/skills/notesoup/SKILL.md +92 -0
  170. package/src/boot/render.ts +59 -25
  171. package/src/boot/text.ts +30 -27
  172. package/src/budget/text.ts +13 -13
  173. package/src/history/claude.ts +41 -0
  174. package/src/history/codex-transcript.ts +6 -4
  175. package/src/history/codex.ts +2 -0
  176. package/src/history/corpus.ts +51 -2
  177. package/src/history/history.ts +35 -44
  178. package/src/history/local.ts +67 -27
  179. package/src/history/pi.ts +113 -35
  180. package/src/history/prefilter.ts +73 -15
  181. package/src/history/query.ts +93 -73
  182. package/src/history/summary-cache.ts +142 -17
  183. package/src/index.ts +1 -1
  184. package/src/notes/frontmatter.ts +16 -1
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +45 -6
  187. package/src/notes/store.ts +30 -15
  188. package/src/text-match.ts +46 -4
  189. package/src/tools/dream.ts +29 -31
  190. package/src/tools/history.ts +249 -142
  191. package/src/tools/notes.ts +150 -112
  192. package/src/tools/output.ts +2 -1
  193. package/src/tools/result.ts +12 -11
  194. package/src/tools/schema.ts +24 -1
  195. package/plugins/claude/skills/memory/SKILL.md +0 -69
  196. package/plugins/codex/mcp.json +0 -10
  197. package/plugins/codex/plugin.json +0 -6
  198. package/plugins/paseo/client/markdown-core.tsx +0 -189
  199. package/plugins/paseo/client/typography.ts +0 -24
  200. package/skills/memory/SKILL.md +0 -69
@@ -3,11 +3,12 @@ import test from "node:test";
3
3
  import { Check } from "typebox/value";
4
4
  import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
5
5
  import { earliestMatchOffsetChars } from "../src/text-match.js";
6
- import { historyList, historyRead } from "../src/tools/history.js";
6
+ import { historyList, historySearch, historyRead } from "../src/tools/history.js";
7
7
  import { historyDocument, projectHistory } from "../src/history/history.js";
8
- import { CorpusCollector, HistoryPageSchema, selectPage } from "../src/history/query.js";
9
- import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
8
+ import { CorpusCollector, selectPage } from "../src/history/query.js";
9
+ import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultText, resultTextError, } from "./helpers/extension.js";
10
10
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
11
+ import { historyFromSession } from "../plugins/pi/history.js";
11
12
  import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
12
13
  import { mkdtemp, rm } from "node:fs/promises";
13
14
  import { tmpdir } from "node:os";
@@ -23,11 +24,20 @@ function toolCall(session, id, name, args) {
23
24
  function toolResult(session, id, name, text, extra = {}) {
24
25
  return append(session, { role: "toolResult", toolCallId: id, toolName: name, content: [{ type: "text", text }], isError: false, timestamp: Date.now(), ...extra });
25
26
  }
26
- function page(result) {
27
- return resultData(result);
27
+ async function listData(session, params = {}) {
28
+ const result = await historyList.execute(params, historyFromSession({ sessionManager: session }));
29
+ assert.ok(result.ok);
30
+ return result.data;
28
31
  }
29
- function seqs(result) {
30
- return page(result).items.map((item) => item.seq);
32
+ async function searchData(session, params) {
33
+ const result = await historySearch.execute(params, historyFromSession({ sessionManager: session }));
34
+ assert.ok(result.ok);
35
+ return result.data;
36
+ }
37
+ async function readData(session, params) {
38
+ const result = await historyRead.execute(params, historyFromSession({ sessionManager: session }));
39
+ assert.ok(result.ok);
40
+ return result.data;
31
41
  }
32
42
  /** What the model reads for one result, so a test can check the text surface directly. */
33
43
  function rendered(result) {
@@ -41,46 +51,39 @@ test("Pi registered tools resolve another persisted session and propagate its id
41
51
  const session = manager(), captured = makeExtension(session), ctx = context(session);
42
52
  appendText(session, "user", "live needle");
43
53
  const read = await call(captured, "history_read", { session: "pi:foreign", seq: 1 }, ctx);
44
- assert.equal(resultData(read).session, "pi:foreign-pi");
54
+ assert.match(resultText(read), /session pi:foreign-pi \| seq 1/);
45
55
  assert.match(rendered(read), /foreign needle/);
46
- const across = page(await call(captured, "history_list", { session: "pi:*", query: "needle" }, ctx));
47
- assert.equal(across.items.length, 2);
48
- assert.ok(across.items.every((item) => typeof item.session === "string"));
49
- const current = resultData(await call(captured, "history_read", { session: `pi:${session.getSessionId()}`, seq: 1 }, ctx));
50
- assert.equal(current.session, `pi:${session.getSessionId()}`);
56
+ const across = resultText(await call(captured, "history_search", { session: "pi:*", query: "needle" }, ctx));
57
+ assert.match(across, /=== session pi:foreign-pi ===\nseq 1/);
58
+ assert.ok(across.includes(`session pi:${session.getSessionId()} ===\nseq 1`));
59
+ const current = resultText(await call(captured, "history_read", { session: `pi:${session.getSessionId()}`, seq: 1 }, ctx));
60
+ assert.ok(current.includes(`session pi:${session.getSessionId()} | seq 1`));
51
61
  });
52
62
  test("Pi registers the shared history schemas", () => {
53
63
  const captured = makeExtension(manager());
54
64
  const listSchema = captured.tools.get("history_list").parameters;
55
65
  assert.deepEqual(listSchema, historyList.parameters);
56
- assert.ok(Check(listSchema, { after: 0, before: "2026-10-10", query: "needle", context: 1 }));
66
+ assert.ok(Check(listSchema, { after: 0, before: 10 }));
67
+ assert.ok(Check(listSchema, { since: "2026-10-10", until: "2026-10-11" }));
68
+ for (const params of [{ after: "2" }, { before: "2026-10-10" }, { after: -1 }, { query: "needle" }, { context: 1 }])
69
+ assert.equal(Check(listSchema, params), false);
70
+ const searchSchema = captured.tools.get("history_search").parameters;
71
+ assert.deepEqual(searchSchema, historySearch.parameters);
72
+ assert.ok(Check(searchSchema, { since: "2026-10-10", query: "needle", context: 1 }));
73
+ assert.equal(Check(searchSchema, { after: 1 }), false);
74
+ assert.equal(Check(searchSchema, { session: "*" }), false);
57
75
  assert.deepEqual(captured.tools.get("history_read").parameters, historyRead.parameters);
58
76
  });
59
- test("every history operation declares a result schema its own payload satisfies", async () => {
60
- const session = manager();
61
- const captured = makeExtension(session);
62
- const ctx = context(session);
77
+ test("history tools expose bounded plain text and plain-text refusals", async () => {
78
+ const session = manager(), captured = makeExtension(session), ctx = context(session);
63
79
  appendText(session, "user", "hello");
64
- toolCall(session, "call-1", "bash", { command: "pwd" });
65
- toolResult(session, "call-1", "bash", "/tmp");
66
- for (const toolName of ["history_list", "history_read"]) {
67
- const operation = { history_list: historyList, history_read: historyRead }[toolName];
68
- const result = await call(captured, toolName, toolName === "history_read" ? { seq: 1 } : { query: "hello" }, ctx);
69
- const structured = result.structuredContent;
70
- assert.ok(structured !== undefined, `${toolName} carries a structured outcome`);
71
- assert.equal(Check(operation.outputSchema, structured), true, `${toolName} payload satisfies its own outputSchema`);
72
- if (toolName === "history_list") {
73
- assert.deepEqual(page(result).items, [{ seq: 1, role: "user", created_at: page(result).items[0].created_at, content: "hello", truncated: false, offset_chars: 0 }]);
74
- }
75
- else {
76
- assert.deepEqual(Object.keys(resultData(result)).sort(), ["seq", "role", "created_at", "text", "total_chars", "next_offset_chars"].sort());
77
- }
78
- assertWithinBudget(result, `${toolName} page`);
80
+ for (const name of ["history_list", "history_search", "history_read"]) {
81
+ assert.equal(captured.tools.get(name).outputSchema, undefined);
82
+ const result = await call(captured, name, name === "history_read" ? { seq: 1 } : name === "history_search" ? { query: "hello" } : {}, ctx);
83
+ assert.match(resultText(result), /hello/);
84
+ assertWithinBudget(result, name);
79
85
  }
80
- const conversation = await call(captured, "history_list", {}, ctx);
81
- assert.equal(Check(historyList.outputSchema, conversation.structuredContent), true);
82
- const refusal = await call(captured, "history_read", { seq: 999 }, ctx);
83
- assert.equal(Check(historyRead.outputSchema, refusal.structuredContent), true, "a refusal satisfies the same result schema");
86
+ assert.equal(resultTextError(await call(captured, "history_read", { seq: 999 }, ctx)).code, "unknown_seq");
84
87
  });
85
88
  test("pairing uses append seq rather than the presentation order of unnumbered segments", async () => {
86
89
  const projection = projectHistory([
@@ -102,17 +105,17 @@ test("seq is stable across branch changes, abandoned entries stay unreadable, an
102
105
  const ctx = context(session);
103
106
  const firstId = appendText(session, "user", "first");
104
107
  const abandonedId = appendText(session, "assistant", "abandoned reply");
105
- const before = page(await call(captured, "history_list", { roles: ["user", "assistant"] }, ctx));
108
+ const before = (await listData(session, { roles: ["user", "assistant"] }));
106
109
  assert.deepEqual(before.items.map((item) => [item.seq, item.content]), [[1, "first"], [2, "abandoned reply"]]);
107
110
  session.branch(firstId);
108
111
  const branchId = appendText(session, "user", "new branch");
109
- const after = page(await call(captured, "history_list", { roles: ["user", "assistant"] }, ctx));
112
+ const after = (await listData(session, { roles: ["user", "assistant"] }));
110
113
  assert.deepEqual(after.items.map((item) => [item.seq, item.content]), [[1, "first"], [3, "new branch"]]);
111
114
  assert.equal(branchId !== abandonedId, true);
112
- const offBranch = resultError(await call(captured, "history_read", { seq: 2 }, ctx));
115
+ const offBranch = resultTextError(await call(captured, "history_read", { seq: 2 }, ctx));
113
116
  assert.equal(offBranch.code, "not_on_branch");
114
117
  assert.equal(JSON.stringify(offBranch).includes("abandoned"), false, "the refusal does not leak the abandoned entry's text");
115
- const unknown = resultError(await call(captured, "history_read", { seq: 4 }, ctx));
118
+ const unknown = resultTextError(await call(captured, "history_read", { seq: 4 }, ctx));
116
119
  assert.equal(unknown.code, "unknown_seq");
117
120
  assert.match(unknown.message, /\b4\b.*\b3\b/);
118
121
  });
@@ -123,19 +126,13 @@ test("a result address consumed by a pairing resolves directly to its call event
123
126
  toolCall(session, "paired", "edit", { path: "a.md" });
124
127
  toolResult(session, "paired", "edit", "edited");
125
128
  // The assistant message takes seq 1 and its tool call seq 2; the result at seq 3 is absorbed.
126
- assert.deepEqual(seqs(await call(captured, "history_list", { roles: ["tool"] }, ctx)), [2], "the pairing is one event at the call's address");
127
- const consumed = resultRead(await call(captured, "history_read", { seq: 3 }, ctx));
129
+ assert.deepEqual((await listData(session, { roles: ["tool"] })).items.map(item => item.seq), [2], "the pairing is one event at the call's address");
130
+ const consumed = (await readData(session, { seq: 3 }));
128
131
  assert.equal(consumed.seq, 2);
129
- assert.equal(consumed.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
130
- const callSeq = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
132
+ assert.equal(consumed.text, 'edit {"path":"a.md"}\n--- output ---\nedited');
133
+ const callSeq = (await readData(session, { seq: 2 }));
131
134
  assert.equal(callSeq.seq, 2);
132
- assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
133
- });
134
- test("history page schema exposes plain boolean paging flags", () => {
135
- for (const field of [HistoryPageSchema.properties.has_older, HistoryPageSchema.properties.has_newer]) {
136
- assert.equal(field.type, "boolean");
137
- assert.equal("description" in field, false);
138
- }
135
+ assert.equal(callSeq.text, 'edit {"path":"a.md"}\n--- output ---\nedited');
139
136
  });
140
137
  test("history_list pages forward with after and otherwise back from before", async () => {
141
138
  const session = manager();
@@ -143,29 +140,27 @@ test("history_list pages forward with after and otherwise back from before", asy
143
140
  const ctx = context(session);
144
141
  for (let index = 1; index <= 7; index++)
145
142
  appendText(session, "user", `message-${index}`);
146
- const list = (params) => call(captured, "history_list", params, ctx);
147
- assert.deepEqual(seqs(await list({ limit: 2 })), [6, 7]);
148
- assert.deepEqual(seqs(await list({ after: 0, limit: 2 })), [1, 2]);
149
- assert.deepEqual(seqs(await list({ after: "2", limit: 2 })), [3, 4]);
143
+ const list = async (params) => (await listData(session, params)).items.map(item => item.seq);
144
+ assert.deepEqual(await list({ limit: 2 }), [6, 7]);
145
+ assert.deepEqual(await list({ after: 0, limit: 2 }), [1, 2]);
146
+ assert.deepEqual(await list({ after: 2, limit: 2 }), [3, 4]);
150
147
  const older = await list({ before: 6, limit: 2 });
151
- assert.deepEqual(seqs(older), [4, 5]);
152
- assert.match(rendered(older), /→ older: \{"before":4\}/);
153
- assert.deepEqual(seqs(await list({ after: 1, before: 5 })), [2, 3, 4]);
148
+ assert.deepEqual(older, [4, 5]);
149
+ assert.match(resultText(await call(captured, "history_list", { before: 6, limit: 2 }, ctx)), /→ older: \{"limit":2,"before":4\}/);
150
+ assert.deepEqual(await list({ after: 1, before: 5 }), [2, 3, 4]);
154
151
  });
155
- test("history_list merges context across hit bounds without moving the page anchor", async () => {
156
- const session = manager();
157
- const captured = makeExtension(session);
158
- const ctx = context(session);
159
- for (const text of ["setup", "needle one", "shared reply", "needle two", "follow-up", "unrelated", "needle three"]) {
160
- appendText(session, text.startsWith("needle") ? "user" : "assistant", text);
161
- }
162
- const result = await call(captured, "history_list", { after: 1, query: "needle", roles: ["user"], limit: 2, context: 1 }, ctx);
163
- assert.deepEqual(page(result).items.map(item => [item.content, !!item.context]), [
152
+ test("history_search merges visible neighbors outside hit filters without consuming the hit limit", async () => {
153
+ const texts = ["setup", "needle one", "shared reply", "needle two", "follow-up", "unrelated", "needle three"];
154
+ const items = texts.map((text, index) => ({ seq: index + 1, windowId: "w", role: text.startsWith("needle") ? "user" : "assistant", text, createdAt: new Date(Date.UTC(2026, 9, 10, 0, 0, index)).toISOString() }));
155
+ const projection = projectHistory([{ windowId: "w", items }], 7, new Set(items.map(item => item.seq)));
156
+ const result = await historySearch.execute({ since: "2026-10-10", query: "needle", roles: ["user"], limit: 2, context: 1 }, projection);
157
+ assert.ok(result.ok);
158
+ assert.deepEqual(result.data.items.map(item => [item.content, !!item.context]), [
164
159
  ["setup", true], ["needle one", false], ["shared reply", true], ["needle two", false], ["follow-up", true],
165
160
  ]);
166
- assert.ok(Check(historyList.outputSchema, result.structuredContent));
167
- assert.match(rendered(result), /→ newer: \{"after":4\}/);
168
- assert.match(resultError(await call(captured, "history_list", { context: 1 }, ctx)).message, /requires a non-empty `query`/);
161
+ assert.match(historySearch.render(result), /→ more newer results: narrow with since\/until/);
162
+ assert.match(historySearch.render(result), /seq 3 \| assistant \| [^|\n]+ \| search context/);
163
+ assert.doesNotMatch(historySearch.render(result), /=== session/);
169
164
  });
170
165
  test("a one-row page budget admits the newest candidate first", () => {
171
166
  const windowId = "w1";
@@ -182,10 +177,10 @@ test("a one-row page budget admits the newest candidate first", () => {
182
177
  });
183
178
  test("query reports budget failures while tools refuse the page", async () => {
184
179
  const projection = projectHistory([{ windowId: "w1", items: [{ seq: 1, windowId: "w1", role: "user", text: "message" }] }], 1, new Set([1]));
185
- assert.deepEqual(selectPage(projection, {}, () => false, 100), { ok: false, pageTooLarge: { count: 1, multi: false } });
180
+ assert.deepEqual(selectPage(projection, {}, () => false, 100), { ok: false, pageTooLarge: true });
186
181
  const collector = new CorpusCollector({});
187
- collector.add("pi:budget", projection);
188
- assert.deepEqual(collector.page(() => false, 100), { ok: false, pageTooLarge: { count: 1, multi: true } });
182
+ collector.addRepresentative("pi:budget", projection);
183
+ assert.deepEqual(collector.page(() => false, 100), { ok: false, pageTooLarge: true });
189
184
  const context = {
190
185
  current: () => projection,
191
186
  corpus: { currentHarness: "pi", async sessions() {
@@ -193,8 +188,10 @@ test("query reports budget failures while tools refuse the page", async () => {
193
188
  } },
194
189
  };
195
190
  const wrap = (text) => "x".repeat(TOOL_OUTPUT_MAX_BYTES + 1) + text;
196
- for (const session of [undefined, "pi:budget", "*"]) {
197
- const result = await historyList.execute({ session }, context, wrap);
191
+ for (const [operation, session] of [[historyList, undefined], [historyList, "pi:budget"], [historyList, "*"], [historySearch, undefined], [historySearch, "pi:budget"], [historySearch, "*"]]) {
192
+ const result = operation === historyList
193
+ ? await historyList.execute({ session }, context, wrap)
194
+ : await historySearch.execute({ session, query: "message" }, context, wrap);
198
195
  assert.ok(!result.ok);
199
196
  assert.equal(result.error.code, "page_too_large");
200
197
  }
@@ -212,14 +209,14 @@ test("history page selection still charges host wrapping and session notices bef
212
209
  const wrap = (text) => "host ".repeat(200) + text;
213
210
  for (const session of [undefined, "pi:wrapped", "*"]) {
214
211
  const params = { session, query: "needle", max_chars_per_item: 50_000 };
215
- const plain = await historyList.execute(params, context);
216
- const wrapped = await historyList.execute(params, context, wrap);
212
+ const plain = await historySearch.execute(params, context);
213
+ const wrapped = await historySearch.execute(params, context, wrap);
217
214
  assert.ok(plain.ok && wrapped.ok);
218
215
  assert.ok(wrapped.data.items[0].content.length < plain.data.items[0].content.length);
219
216
  assert.ok(text.startsWith(wrapped.data.items[0].content), "the preview is still verbatim");
220
217
  if (session !== undefined)
221
218
  assert.ok(wrapped.data.notice?.includes(notice));
222
- assert.ok(Buffer.byteLength(wrap(historyList.render(wrapped)), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
219
+ assert.ok(Buffer.byteLength(wrap(historySearch.render(wrapped)), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
223
220
  assert.ok(Buffer.byteLength(JSON.stringify(wrapped.data), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
224
221
  }
225
222
  });
@@ -270,7 +267,7 @@ test("conversation paging prepares ordered folds once, including during first-ro
270
267
  assert.ok(attempts > 3, "the first preview exercised repeated budget probes");
271
268
  assert.equal(traversals, 1, "shortening also reuses the same prepared folds");
272
269
  });
273
- test("list shortening charges folded rows against both text and JSON budgets", async () => {
270
+ test("list shortening charges folded rows against the rendered text budget", async () => {
274
271
  const windowId = "w1";
275
272
  const items = [
276
273
  { seq: 1, windowId, role: "user", text: "older" },
@@ -293,10 +290,26 @@ test("list shortening charges folded rows against both text and JSON budgets", a
293
290
  assert.deepEqual(folded.data.folded_after, { first_seq: 3, last_seq: 3, count: 1, tools: { read: 1 } });
294
291
  assert.equal(folded.data.has_older, true);
295
292
  assert.equal(folded.data.has_newer, false);
296
- assert.ok(Buffer.byteLength(JSON.stringify(folded.data), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
293
+ assert.ok(Buffer.byteLength(JSON.stringify(folded.data), "utf8") > TOOL_OUTPUT_MAX_BYTES, "JSON escaping does not shrink a plain-text page");
297
294
  assert.ok(Buffer.byteLength(historyList.render(folded), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
298
295
  });
299
- test("after and before accept exclusive ISO 8601 times and default to UTC", async () => {
296
+ test("escape-heavy history fits by rendered UTF-8 bytes, not JSON bytes", async () => {
297
+ const text = '\n"\\😀'.repeat(4_500);
298
+ const projection = projectHistory([{ windowId: "w", items: [{ seq: 1, windowId: "w", role: "user", text }] }], 1, new Set([1]));
299
+ const list = await historyList.execute({ max_chars_per_item: 50_000 }, projection);
300
+ assert.ok(list.ok);
301
+ assert.equal(list.data.items[0].content, text);
302
+ assert.equal(list.data.items[0].truncated, false);
303
+ assert.ok(Buffer.byteLength(historyList.render(list), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
304
+ assert.ok(Buffer.byteLength(JSON.stringify(list.data), "utf8") > TOOL_OUTPUT_MAX_BYTES);
305
+ const read = await historyRead.execute({ seq: 1, max_chars: 50_000 }, projection);
306
+ assert.ok(read.ok);
307
+ assert.equal(read.data.text, text);
308
+ assert.equal(read.data.next_offset_chars, null);
309
+ assert.ok(Buffer.byteLength(historyRead.render(read), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
310
+ assert.ok(Buffer.byteLength(JSON.stringify(read.data), "utf8") > TOOL_OUTPUT_MAX_BYTES);
311
+ });
312
+ test("since and until accept exclusive ISO 8601 times, reading offset-less values as host local time", async () => {
300
313
  const items = [
301
314
  { seq: 1, windowId: "w1", role: "user", text: "first needle", createdAt: "2026-10-10T00:00:00.000Z" },
302
315
  { seq: 2, windowId: "w1", role: "assistant", text: "second", createdAt: "2026-10-10T06:00:00.000Z" },
@@ -306,27 +319,54 @@ test("after and before accept exclusive ISO 8601 times and default to UTC", asyn
306
319
  ];
307
320
  const projection = projectHistory([{ windowId: "w1", items }], 5, new Set([1, 2, 3, 4, 5]));
308
321
  const selected = async (params) => {
309
- const outcome = await historyList.execute(params, projection);
322
+ const outcome = await historySearch.execute(params, projection);
310
323
  assert.equal(outcome.ok, true, JSON.stringify(outcome));
311
324
  return outcome.ok ? outcome.data.items.map((item) => item.seq) : [];
312
325
  };
313
- assert.deepEqual(await selected({ after: "2026-10-10T06:00", limit: 1 }), [3]);
314
- assert.deepEqual(await selected({ after: "2026-10-10", before: "2026-10-10T18:00Z" }), [2, 3]);
315
- const malformed = await historyList.execute({ after: "yesterday" }, projection);
326
+ const all = ["first", "second", "third", "fourth", "fifth"];
327
+ const after = (at) => items.filter((item) => item.createdAt !== undefined && Date.parse(item.createdAt) > at).map((item) => item.seq);
328
+ // No offset means the host wall clock, so the expectation follows the local date constructor.
329
+ assert.deepEqual(await selected({ query: all, since: "2026-10-09T23:00" }), after(new Date(2026, 9, 9, 23, 0).getTime()));
330
+ assert.deepEqual(await selected({ query: all, limit: 1, since: "2026-10-10T06:00" }), after(new Date(2026, 9, 10, 6, 0).getTime()).slice(0, 1));
331
+ // An explicit offset fixes the instant regardless of the host timezone.
332
+ assert.deepEqual(await selected({ query: all, since: "2026-10-10T06:00Z" }), [3, 4]);
333
+ assert.deepEqual(await selected({ query: all, since: "2026-10-10T14:00:00+08:00" }), [3, 4]);
334
+ assert.deepEqual(await selected({ query: all, since: "2026-10-09T00:00:00Z", until: "2026-10-10T06:00Z" }), [1]);
335
+ const listWindow = await historyList.execute({ since: "2026-10-09T00:00:00Z", until: "2026-10-11T00:00:00Z", limit: 2 }, projection);
336
+ assert.equal(listWindow.ok, true);
337
+ if (listWindow.ok) {
338
+ assert.deepEqual(listWindow.data.items.map((item) => item.seq), [1, 2]);
339
+ assert.equal(listWindow.data.has_newer, true);
340
+ const newerMatch = /→ newer: (\{[^\n]+\})/.exec(historyList.render(listWindow));
341
+ assert.ok(newerMatch);
342
+ const next = await historyList.execute(JSON.parse(newerMatch[1]), projection);
343
+ assert.equal(next.ok, true);
344
+ if (next.ok)
345
+ assert.deepEqual(next.data.items.map((item) => item.seq), [3, 4]);
346
+ }
347
+ const malformed = await historySearch.execute({ query: all, since: "yesterday" }, projection);
316
348
  assert.ok(!malformed.ok);
317
- assert.match(malformed.error.message, /`after`.*"yesterday"/);
349
+ assert.match(malformed.error.message, /since.*"yesterday"/);
350
+ for (const value of ["2026-02-30", "2026-13-01"]) {
351
+ for (const bound of ["since", "until"]) {
352
+ const invalid = await historySearch.execute({ query: all, [bound]: value }, projection);
353
+ assert.ok(!invalid.ok);
354
+ assert.equal(invalid.error.code, "invalid_bounds");
355
+ assert.ok(invalid.error.message.includes(value));
356
+ }
357
+ }
318
358
  });
319
- test("time bounds also keep untimed events out of the folded conversation view", async () => {
359
+ test("time bounds keep untimed matching events out of search", async () => {
320
360
  const items = [
321
361
  { seq: 1, windowId: "w1", role: "user", text: "before", createdAt: "2026-10-10T00:00:00.000Z" },
322
362
  { seq: 2, windowId: "w1", role: "tool", text: "output", createdAt: undefined },
323
363
  { seq: 3, windowId: "w1", role: "user", text: "after", createdAt: "2026-10-10T12:00:00.000Z" },
324
364
  ];
325
365
  const projection = projectHistory([{ windowId: "w1", items }], 3, new Set([1, 2, 3]));
326
- const bounded = await historyList.execute({ before: "2026-10-11" }, projection);
366
+ const bounded = await historySearch.execute({ query: ["before", "after", "output"], until: "2026-10-11" }, projection);
327
367
  assert.equal(bounded.ok, true);
328
368
  if (bounded.ok)
329
- assert.deepEqual(bounded.data.items.map((item) => `seq ${item.seq}`), ["seq 1", "seq 3"], "an untimed tool event is not folded into a bounded selection");
369
+ assert.deepEqual(bounded.data.items.map((item) => `seq ${item.seq}`), ["seq 1", "seq 3"], "an untimed event is excluded by the time bound");
330
370
  const unbounded = await historyList.execute({}, projection);
331
371
  assert.equal(unbounded.ok, true);
332
372
  if (unbounded.ok)
@@ -351,7 +391,7 @@ test("conversation view folds tools and injected messages, while explicit roles
351
391
  toolResult(session, "tc-2", "read", "contents");
352
392
  session.appendCustomMessageEntry("square", "injected event", false);
353
393
  append(session, { role: "assistant", content: [], stopReason: "toolUse", timestamp: Date.now() });
354
- const conversation = page(await call(captured, "history_list", {}, ctx));
394
+ const conversation = (await listData(session, {}));
355
395
  assert.ok(conversation.folded_after);
356
396
  assert.ok(conversation.items.every((item) => "seq" in item && !("folded" in item)));
357
397
  assert.equal(conversation.items.some((item) => item.role === "developer"), false);
@@ -361,18 +401,18 @@ test("conversation view folds tools and injected messages, while explicit roles
361
401
  assert.equal(folded.count, 3, "two tool events and one injected context are folded, not the empty assistant message");
362
402
  assert.deepEqual(folded.tools, { bash: 1, read: 1 });
363
403
  assert.equal("custom_types" in folded, false);
364
- const empty = page(await call(captured, "history_list", { roles: ["context"], before: 2 }, ctx));
404
+ const empty = (await listData(session, { roles: ["context"], before: 2 }));
365
405
  assert.deepEqual(empty.items, []);
366
- const hiddenOnly = page(await call(captured, "history_list", { after: 2, before: 6 }, ctx));
406
+ const hiddenOnly = (await listData(session, { after: 2, before: 6 }));
367
407
  assert.deepEqual(hiddenOnly.items, []);
368
408
  assert.deepEqual(hiddenOnly.folded_after, { first_seq: 3, last_seq: 4, count: 2, tools: { bash: 1, read: 1 } });
369
- const expanded = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
409
+ const expanded = (await listData(session, { roles: ["tool"] }));
370
410
  assert.deepEqual(expanded.items.map((item) => [item.seq, item.role, item.tool, item.tool_status]), [[3, "tool", "bash", "ok"], [4, "tool", "read", "ok"]]);
371
411
  assert.equal(expanded.items[0].content, 'bash {"command":"pwd"}\n--- output ---\nok');
372
412
  assert.equal(expanded.items[1].content, 'read {"path":"README.md"}\n--- output ---\ncontents');
373
413
  assert.equal(expanded.items.every((item) => !("call_seq" in item || "result_seq" in item || "tool_name" in item)), true);
374
- assert.deepEqual(seqs(await call(captured, "history_list", { query: "bash", roles: ["tool"] }, ctx)), [3]);
375
- const injected = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
414
+ assert.deepEqual((await searchData(session, { query: "bash", roles: ["tool"] })).items.map(item => item.seq), [3]);
415
+ const injected = (await listData(session, { roles: ["context"] }));
376
416
  assert.deepEqual(injected.items.map((item) => [item.role, item.content]), [["context", "injected event"]]);
377
417
  assert.equal(turnId.length > 0, true);
378
418
  });
@@ -386,27 +426,27 @@ test("tool summaries and documents preserve pending, errored, and orphan runs",
386
426
  toolResult(session, "orphan", "edit", "orphan output", {
387
427
  nestedCalls: { complete: true, calls: [{ id: "orphan/1", name: "read", arguments: { path: "orphan-nested.md" }, status: "ok" }] },
388
428
  });
389
- const events = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
429
+ const events = (await listData(session, { roles: ["tool"] }));
390
430
  // The orphan result ran and succeeded; nothing about its missing call changes that. Only the
391
431
  // pending call, which no result ended, is unfinished.
392
432
  assert.deepEqual(events.items.map((item) => [item.seq, item.tool_status]), [[2, "error"], [5, "unfinished"], [6, "ok"]]);
393
433
  assert.equal(events.items[0].content, 'edit {"path":"😀.md","oldText":"before"}\n--- output ---\nreplacement OK');
394
434
  assert.equal(events.items[1].content, 'edit {"path":"pending.md"}', "an unfinished call claims no output");
395
435
  assert.equal(events.items[2].content, 'edit (arguments not recorded)\n--- output ---\norphan output\n--- nested calls (complete, 1 recorded) ---\n- orphan/1 read [ok] {"path":"orphan-nested.md"}', "an orphan result invents no arguments, and keeps the nested evidence the host recorded");
396
- const errored = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
436
+ const errored = (await readData(session, { seq: 2 }));
397
437
  assert.equal(errored.tool, "edit");
398
438
  assert.equal(errored.tool_status, "error");
399
439
  assert.equal(errored.text, events.items[0].content);
400
440
  assert.equal("execution" in errored, false, "arguments are delivered once, in the document");
401
- const pending = resultRead(await call(captured, "history_read", { seq: 5 }, ctx));
441
+ const pending = (await readData(session, { seq: 5 }));
402
442
  assert.equal(pending.tool_status, "unfinished");
403
- const orphan = resultRead(await call(captured, "history_read", { seq: 6 }, ctx));
443
+ const orphan = (await readData(session, { seq: 6 }));
404
444
  assert.deepEqual(orphan.nested_calls, { call_count: 1, complete: true });
405
445
  assert.equal(orphan.text, events.items[2].content, "an orphan's nested evidence stays readable despite the missing call");
406
- assert.deepEqual(seqs(await call(captured, "history_list", { query: "edit", roles: ["tool"] }, ctx)), [2, 5, 6]);
407
- assert.deepEqual(seqs(await call(captured, "history_list", { query: "pending.md", roles: ["tool"] }, ctx)), [5]);
408
- assert.deepEqual(seqs(await call(captured, "history_list", { query: "orphan output", roles: ["tool"] }, ctx)), [6]);
409
- assert.deepEqual(seqs(await call(captured, "history_list", { query: "orphan-nested.md", roles: ["tool"] }, ctx)), [6], "nested evidence stays findable even when the call it belongs to was never recorded");
446
+ assert.deepEqual((await searchData(session, { query: "edit", roles: ["tool"] })).items.map(item => item.seq), [2, 5, 6]);
447
+ assert.deepEqual((await searchData(session, { query: "pending.md", roles: ["tool"] })).items.map(item => item.seq), [5]);
448
+ assert.deepEqual((await searchData(session, { query: "orphan output", roles: ["tool"] })).items.map(item => item.seq), [6]);
449
+ assert.deepEqual((await searchData(session, { query: "orphan-nested.md", roles: ["tool"] })).items.map(item => item.seq), [6], "nested evidence stays findable even when the call it belongs to was never recorded");
410
450
  });
411
451
  test("native nested-call records are searchable, readable, and never gain a result or an address", async () => {
412
452
  const session = manager();
@@ -423,15 +463,15 @@ test("native nested-call records are searchable, readable, and never gain a resu
423
463
  ],
424
464
  },
425
465
  });
426
- const found = page(await call(captured, "history_list", { query: "nested-needle" }, ctx));
466
+ const found = (await searchData(session, { query: "nested-needle" }));
427
467
  assert.deepEqual(found.items.map((item) => item.seq), [2], "nested arguments are part of the searchable document");
428
- const read = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
468
+ const read = (await readData(session, { seq: 2 }));
429
469
  assert.deepEqual(read.nested_calls, { call_count: 3, complete: false }, "the host's completeness flag stays unchanged");
430
470
  assert.equal(read.text, 'codemode {"script":"run()"}\n--- output ---\nscript finished\n--- nested calls (incomplete, 3 recorded) ---\n- codemode/1 read [ok] 12ms {"path":"nested-needle.md"}\n- codemode/2 bash [error] 4ms error: exit 1 (arguments not recorded)\n- codemode/3 spawn [unfinished] (arguments not recorded)');
431
471
  assert.equal(read.next_offset_chars, null);
432
472
  assert.equal("execution" in read, false, "nested records are not duplicated outside the document");
433
- const rendered = read.content;
434
- for (const [needle, offset] of [["nested-needle.md", earliestMatchOffsetChars(read.content, ["nested-needle.md"])], ["exit 1", earliestMatchOffsetChars(read.content, ["exit 1"])], ["unfinished", earliestMatchOffsetChars(read.content, ["unfinished"])]]) {
473
+ const rendered = read.text;
474
+ for (const [needle, offset] of [["nested-needle.md", earliestMatchOffsetChars(read.text, ["nested-needle.md"])], ["exit 1", earliestMatchOffsetChars(read.text, ["exit 1"])], ["unfinished", earliestMatchOffsetChars(read.text, ["unfinished"])]]) {
435
475
  assert.ok(offset >= 0 && rendered.slice(offset).startsWith(needle), `nested evidence "${needle}" is readable in the document`);
436
476
  }
437
477
  });
@@ -441,11 +481,11 @@ test("absent nested calls mean unavailable, not a known-empty record", async ()
441
481
  const ctx = context(session);
442
482
  toolCall(session, "plain", "read", { path: "a.md" });
443
483
  toolResult(session, "plain", "read", "contents");
444
- const listed = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
484
+ const listed = (await listData(session, { roles: ["tool"] }));
445
485
  assert.equal("nested_calls" in listed.items[0], false, "a page row never carries nested-call evidence; one read does");
446
- const read = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
486
+ const read = (await readData(session, { seq: 2 }));
447
487
  assert.equal("nested_calls" in read, false);
448
- assert.equal(read.content.includes("nested calls"), false);
488
+ assert.equal(read.text.includes("nested calls"), false);
449
489
  });
450
490
  test("oversized arguments and long nested records remain fully pageable and searchable", async () => {
451
491
  const session = manager();
@@ -459,14 +499,15 @@ test("oversized arguments and long nested records remain fully pageable and sear
459
499
  calls: Array.from({ length: 400 }, (_, index) => ({ id: `big/${index}`, name: "read", arguments: { path: `p${index}.md` }, status: "ok", durationMs: 1 })),
460
500
  },
461
501
  });
462
- let read = resultRead(await call(captured, "history_read", { seq: 2, max_chars: 50_000 }, ctx));
502
+ let read = (await readData(session, { seq: 2, max_chars: 50_000 }));
463
503
  assert.deepEqual(read.nested_calls, { call_count: 400, complete: true }, "the read counts every recorded call, not only the records one page can carry");
464
504
  let document = read.text;
465
505
  while (read.next_offset_chars !== null) {
466
506
  const next = read.next_offset_chars;
467
507
  const result = await call(captured, "history_read", { seq: 2, offset_chars: next, max_chars: 50_000 }, ctx);
468
508
  assertWithinBudget(result, "bounded document page");
469
- read = resultRead(result);
509
+ assert.ok(resultText(result).length > 0);
510
+ read = await readData(session, { seq: 2, offset_chars: next, max_chars: 50_000 });
470
511
  assert.ok(read.text.length > 0, "every continuation makes progress");
471
512
  document += read.text;
472
513
  }
@@ -474,11 +515,11 @@ test("oversized arguments and long nested records remain fully pageable and sear
474
515
  assert.equal(document, `write ${JSON.stringify({ path: "big.md", content: huge })}\n--- output ---\nwritten\n--- nested calls (complete, 400 recorded) ---\n${expectedCalls}`, "paging reconstructs all arguments and all recorded calls exactly");
475
516
  assertWithinBudget(await call(captured, "history_read", { seq: 2 }, ctx), "bounded first read");
476
517
  assertWithinBudget(await call(captured, "history_list", { roles: ["tool"] }, ctx), "bounded list row");
477
- const hit = page(await call(captured, "history_list", { query: "big.md", max_chars_per_item: 40 }, ctx));
518
+ const hit = (await searchData(session, { query: "big.md", max_chars_per_item: 40 }));
478
519
  assert.deepEqual(hit.items.map((item) => item.seq), [2], "the document still carries the real arguments, so a query still finds them");
479
- const late = page(await call(captured, "history_list", { query: "p399.md" }, ctx)).items[0];
520
+ const late = (await searchData(session, { query: "p399.md" })).items[0];
480
521
  assert.equal(late.seq, 2);
481
- const resumed = resultRead(await call(captured, "history_read", { seq: 2, offset_chars: late.offset_chars }, ctx));
522
+ const resumed = (await readData(session, { seq: 2, offset_chars: late.offset_chars }));
482
523
  assert.ok(resumed.text.startsWith("p399.md"), "a query can jump directly to evidence beyond the first read");
483
524
  });
484
525
  test("standalone bash execution retains command, output, and truncation path", async () => {
@@ -487,7 +528,8 @@ test("standalone bash execution retains command, output, and truncation path", a
487
528
  const ctx = context(session);
488
529
  append(session, { role: "bashExecution", command: "echo needle", output: "needle output", exitCode: 0, cancelled: false, truncated: true, fullOutputPath: "/tmp/bash-output.txt", timestamp: Date.now() });
489
530
  const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
490
- const found = page(raw);
531
+ assert.match(resultText(raw), /output truncated/);
532
+ const found = await listData(session, { roles: ["tool"] });
491
533
  assert.equal(found.items.length, 1);
492
534
  assert.deepEqual(found.items[0], {
493
535
  seq: 1,
@@ -500,10 +542,10 @@ test("standalone bash execution retains command, output, and truncation path", a
500
542
  truncated: false,
501
543
  content: 'bash {"command":"echo needle"}\n--- output ---\nneedle output',
502
544
  });
503
- const query = page(await call(captured, "history_list", { roles: ["tool"], query: "NEEDLE OUTPUT" }, ctx));
545
+ const query = (await searchData(session, { roles: ["tool"], query: "NEEDLE OUTPUT" }));
504
546
  assert.deepEqual(query.items.map((item) => item.seq), [1]);
505
- const read = resultRead(await call(captured, "history_read", { seq: 1, offset_chars: query.items[0].offset_chars }, ctx));
506
- assert.equal(read.content, "needle output");
547
+ const read = (await readData(session, { seq: 1, offset_chars: query.items[0].offset_chars }));
548
+ assert.equal(read.text, "needle output");
507
549
  assert.equal(read.seq, 1);
508
550
  });
509
551
  test("a truncated tool run without a recorded path still reports output_truncated", async () => {
@@ -512,12 +554,13 @@ test("a truncated tool run without a recorded path still reports output_truncate
512
554
  const ctx = context(session);
513
555
  append(session, { role: "bashExecution", command: "echo big", output: "big output", exitCode: 0, cancelled: false, truncated: true, timestamp: Date.now() });
514
556
  const raw = await call(captured, "history_list", { roles: ["tool"] }, ctx);
515
- const found = page(raw);
557
+ assert.match(resultText(raw), /output truncated/);
558
+ const found = await listData(session, { roles: ["tool"] });
516
559
  assert.equal(found.items.length, 1);
517
560
  const item = found.items[0];
518
561
  assert.equal(item.output_truncated, true, "the truncation is reported even with no path");
519
562
  assert.equal("full_output_path" in item, false, "no path is invented");
520
- const read = resultRead(await call(captured, "history_read", { seq: 1 }, ctx));
563
+ const read = (await readData(session, { seq: 1 }));
521
564
  assert.equal(read.output_truncated, true, "the read reports the same truncation");
522
565
  assert.equal("full_output_path" in read, false);
523
566
  });
@@ -531,11 +574,11 @@ test("list renders paging and fold recipes across resets, and read renders a nei
531
574
  appendText(session, "user", "current window");
532
575
  const listed = await call(captured, "history_list", {}, ctx);
533
576
  assert.match(rendered(listed), /→ older: \{"before":\d+\}/, "the footer prints the call to page older");
534
- const earlier = page(await call(captured, "history_list", { before: 31, limit: 30 }, ctx));
577
+ const earlier = (await listData(session, { before: 31, limit: 30 }));
535
578
  assert.deepEqual(earlier.items.map((item) => item.seq), Array.from({ length: 30 }, (_, index) => index + 1));
536
- const earlierQuery = page(await call(captured, "history_list", { query: "older window", before: 31, limit: 30 }, ctx));
537
- assert.equal(earlierQuery.items.length, 30, "queries and seq bounds recover earlier windows without a separate address");
538
- const current = page(await call(captured, "history_list", { after: 30 }, ctx));
579
+ const earlierQuery = (await searchData(session, { query: "older window", limit: 30 }));
580
+ assert.equal(earlierQuery.items.length, 30, "search recovers earlier windows without a separate address");
581
+ const current = (await listData(session, { after: 30 }));
539
582
  assert.deepEqual(current.items.map((item) => [item.seq, item.content]), [[31, "current window"]], "the reset marker consumes no address");
540
583
  toolCall(session, "t1", "bash", { command: "ls" });
541
584
  toolResult(session, "t1", "bash", "done");
@@ -543,9 +586,38 @@ test("list renders paging and fold recipes across resets, and read renders a nei
543
586
  const folded = await call(captured, "history_list", {}, ctx);
544
587
  assert.match(rendered(folded), /→ expand: \{"after":\d+,"before":\d+,"roles":\["tool","context"\]\}/, "a folded row prints its own expand recipe");
545
588
  appendText(session, "user", "needle read target");
546
- const hits = page(await call(captured, "history_list", { query: "needle read target" }, ctx));
589
+ const hits = (await searchData(session, { query: "needle read target" }));
547
590
  const read = await call(captured, "history_read", { seq: hits.items[0].seq }, ctx);
548
- assert.match(rendered(read), /neighborhood → `history_list`\(\{"after":\d+,"before":\d+\}\)/, "a read prints the call for surrounding events");
591
+ assert.match(rendered(read), /→ history_list: \{"after":\d+,"before":\d+\}/, "a read prints the call for surrounding events");
592
+ });
593
+ test("history headers carry local ISO timestamps, and preview markers stay inline", async () => {
594
+ const windowId = "w1";
595
+ const at = new Date(2026, 10, 27, 13, 40, 5, 250).toISOString();
596
+ const items = [
597
+ { seq: 1, windowId, role: "user", text: "timed needle", createdAt: at },
598
+ { seq: 2, windowId, role: "assistant", text: "reply without airtime", createdAt: undefined },
599
+ ];
600
+ const projection = projectHistory([{ windowId, items }], 2, new Set([1, 2]));
601
+ const stamp = "2026-11-27T13:40:05\\.250[+-]\\d{2}:\\d{2}";
602
+ const listed = await historyList.execute({}, projection);
603
+ assert.ok(listed.ok);
604
+ assert.match(historyList.render(listed), new RegExp(`^seq 1 \\| user \\| ${stamp}\\ntimed needle`), "a timed row prints the local wall clock");
605
+ assert.match(historyList.render(listed), /\nseq 2 \| assistant\nreply without airtime$/, "an untimed row ends at the role");
606
+ const read = await historyRead.execute({ seq: 1 }, projection);
607
+ assert.match(historyRead.render(read), new RegExp(`^seq 1 \\| user \\| ${stamp}\\n→ history_list: \\{"after":0,"before":11\\}`), "a read prints its header and a list recipe");
608
+ const untimedRead = await historyRead.execute({ seq: 2 }, projection);
609
+ assert.match(historyRead.render(untimedRead), /^seq 2 \| assistant\n→ history_list: /);
610
+ // A search match names its start on the header line and marks the cut on the content line.
611
+ const hit = await historySearch.execute({ query: "needle", max_chars_per_item: 5 }, projection);
612
+ assert.ok(hit.ok);
613
+ assert.match(historySearch.render(hit), new RegExp(`^seq 1 \\| user \\| ${stamp} \\| offset_chars 6\\nneedl \\[truncated\\]$`), "a match preview names its start and marks the cut");
614
+ // A match at the document start still prints no offset marker.
615
+ const fromStart = await historySearch.execute({ query: "timed", max_chars_per_item: 5 }, projection);
616
+ assert.ok(fromStart.ok);
617
+ assert.match(historySearch.render(fromStart), new RegExp(`^seq 1 \\| user \\| ${stamp}\\ntimed \\[truncated\\]$`), "a zero offset stays off the header");
618
+ const zeroList = await historyList.execute({ max_chars_per_item: 5 }, projection);
619
+ assert.ok(zeroList.ok);
620
+ assert.doesNotMatch(historyList.render(zeroList), /offset_chars 0/, "a zero offset is not printed");
549
621
  });
550
622
  test("compaction summary becomes context and is folded in the default list", async () => {
551
623
  const session = manager();
@@ -554,41 +626,34 @@ test("compaction summary becomes context and is folded in the default list", asy
554
626
  appendText(session, "user", "before checkpoint");
555
627
  session.appendCompaction("summary needle", session.getLeafId(), 100);
556
628
  appendText(session, "assistant", "after checkpoint");
557
- const regular = page(await call(captured, "history_list", {}, ctx));
629
+ const regular = (await listData(session, {}));
558
630
  assert.deepEqual(regular.items.map((item) => item.role), ["user", "assistant"]);
559
631
  const folded = regular.items[1].folded_before;
560
632
  assert.equal(folded.count, 1);
561
633
  assert.deepEqual(folded.tools, {});
562
- const contextItems = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
634
+ const contextItems = (await listData(session, { roles: ["context"] }));
563
635
  assert.deepEqual(contextItems.items.map((item) => [item.role, item.content]), [["context", "summary needle"]]);
564
636
  });
565
- test("a query covers every role, carries match offsets and treats empty queries as omitted", async () => {
637
+ test("a query covers every role, carries match offsets and returns empty for empty queries", async () => {
566
638
  const session = manager();
567
639
  const captured = makeExtension(session);
568
640
  const ctx = context(session);
569
641
  appendText(session, "user", "visible needle");
570
642
  session.appendCustomMessageEntry("notesoup/boot", "developer needle", false);
571
643
  appendText(session, "assistant", "assistant needle");
572
- const all = page(await call(captured, "history_list", { query: "needle" }, ctx));
644
+ const all = (await searchData(session, { query: "needle" }));
573
645
  assert.deepEqual(all.items.map((item) => item.role), ["user", "context", "assistant"]);
574
646
  assert.ok(all.items.every((item) => typeof item.seq === "number" && typeof item.offset_chars === "number"));
575
- const developers = page(await call(captured, "history_list", { query: "needle", roles: ["context"] }, ctx));
647
+ const developers = (await searchData(session, { query: "needle", roles: ["context"] }));
576
648
  assert.deepEqual(developers.items.map((item) => item.role), ["context"]);
577
649
  assert.equal("custom_type" in developers.items[0], false);
578
- const first = page(await call(captured, "history_list", { query: "needle", after: 1, limit: 1 }, ctx));
579
- assert.deepEqual(first.items.map((item) => item.seq), [2]);
580
- assert.equal(first.has_newer, true);
581
- const next = page(await call(captured, "history_list", { query: "needle", after: first.items.at(-1).seq, limit: 2 }, ctx));
582
- assert.deepEqual(next.items.map((item) => item.seq), [3]);
583
- const absent = await call(captured, "history_list", { query: "absent" }, ctx);
584
- assert.deepEqual(page(absent).items, []);
650
+ const absent = await call(captured, "history_search", { query: "absent" }, ctx);
651
+ assert.deepEqual((await searchData(session, { query: "absent" })).items, []);
585
652
  assert.notEqual(rendered(absent).trim(), "", "an empty page says so instead of rendering nothing");
586
653
  for (const query of ["", [], ["", ""]]) {
587
- assert.deepEqual(page(await call(captured, "history_list", { query }, ctx)), page(await call(captured, "history_list", {}, ctx)), "empty queries preserve conversation folding");
588
- const filters = { roles: ["context"], after: 1, before: 3 };
589
- assert.deepEqual(page(await call(captured, "history_list", { ...filters, query }, ctx)), page(await call(captured, "history_list", filters, ctx)), "other filters still apply");
654
+ assert.deepEqual(await searchData(session, { query, context: 1 }), { items: [], has_older: false, has_newer: false });
590
655
  }
591
- assert.deepEqual(page(await call(captured, "history_list", { query: ["", "needle"] }, ctx)), all, "empty entries do not turn OR into match-all");
656
+ assert.deepEqual((await searchData(session, { query: ["", "needle"] })), all, "empty entries do not turn OR into match-all");
592
657
  });
593
658
  test("has_older and has_newer round-trip a session with no duplicates and no gaps", async () => {
594
659
  const session = manager();
@@ -597,25 +662,25 @@ test("has_older and has_newer round-trip a session with no duplicates and no gap
597
662
  for (let seq = 1; seq <= 10; seq++)
598
663
  appendText(session, "user", `needle ${seq}`);
599
664
  const forward = [];
600
- let current = page(await call(captured, "history_list", { query: "needle", after: 0, limit: 3 }, ctx));
665
+ let current = (await listData(session, { after: 0, limit: 3 }));
601
666
  assert.deepEqual(current.items.map((item) => item.seq), [1, 2, 3]);
602
667
  assert.equal(current.has_older, false, "the first page in `from` oldest has nothing older");
603
668
  assert.equal(current.has_newer, true);
604
669
  forward.push(...current.items.map((item) => item.seq));
605
670
  while (current.has_newer) {
606
671
  const cursor = { after: current.items.at(-1).seq };
607
- current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
672
+ current = (await listData(session, { ...cursor, limit: 3 }));
608
673
  forward.push(...current.items.map((item) => item.seq));
609
674
  }
610
675
  assert.deepEqual(forward, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "has_newer visits every event exactly once, in order");
611
676
  const backward = [];
612
- current = page(await call(captured, "history_list", { query: "needle", limit: 3 }, ctx));
677
+ current = (await listData(session, { limit: 3 }));
613
678
  assert.deepEqual(current.items.map((item) => item.seq), [8, 9, 10]);
614
679
  assert.equal(current.has_older, true);
615
680
  backward.push(...current.items.map((item) => item.seq));
616
681
  while (current.has_older) {
617
682
  const cursor = { before: current.items[0].seq };
618
- current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
683
+ current = (await listData(session, { ...cursor, limit: 3 }));
619
684
  backward.push(...current.items.map((item) => item.seq));
620
685
  }
621
686
  assert.deepEqual(backward, [8, 9, 10, 5, 6, 7, 2, 3, 4, 1], "has_older walks back with no duplicates and no gaps");
@@ -627,24 +692,24 @@ test("query previews start at case-insensitive literal matches and offsets read
627
692
  const ctx = context(session);
628
693
  const prefix = "😀İ".repeat(1000);
629
694
  appendText(session, "user", prefix + "NeEdLe.* trailing");
630
- const found = page(await call(captured, "history_list", { query: ["absent", "needle.*"], max_chars_per_item: 8 }, ctx));
695
+ const found = (await searchData(session, { query: ["absent", "needle.*"], max_chars_per_item: 8 }));
631
696
  assert.equal(found.items.length, 1);
632
697
  const hit = found.items[0];
633
698
  assert.equal(hit.offset_chars, 2000);
634
699
  assert.equal("match_offset_chars" in hit, false);
635
700
  assert.equal(hit.content, "NeEdLe.*");
636
701
  assert.equal(hit.truncated, true);
637
- const read = resultRead(await call(captured, "history_read", { seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 8 }, ctx));
638
- assert.equal(read.content, hit.content);
639
- const listed = page(await call(captured, "history_list", { max_chars_per_item: 8 }, ctx));
702
+ const read = (await readData(session, { seq: hit.seq, offset_chars: hit.offset_chars, max_chars: 8 }));
703
+ assert.equal(read.text, hit.content);
704
+ const listed = (await listData(session, { max_chars_per_item: 8 }));
640
705
  assert.equal(listed.items.length, 1);
641
706
  assert.equal("offset_chars" in listed.items[0], false, "a list preview reports no match offset");
642
- const atStart = page(await call(captured, "history_list", { query: "😀", max_chars_per_item: 4 }, ctx));
707
+ const atStart = (await searchData(session, { query: "😀", max_chars_per_item: 4 }));
643
708
  const zero = atStart.items[0];
644
709
  assert.equal(zero.offset_chars, 0, "a match at the document start reports an explicit zero offset");
645
710
  assert.equal(zero.content, "😀İ😀İ", "an explicit zero offset still previews from the document start");
646
711
  assert.equal(zero.truncated, true);
647
- assert.deepEqual(page(await call(captured, "history_list", { query: "needle.+" }, ctx)).items, []);
712
+ assert.deepEqual((await searchData(session, { query: "needle.+" })).items, []);
648
713
  });
649
714
  test("history_read paginates one document with an accurate limit and a bounded byte cap", async () => {
650
715
  const session = manager();
@@ -652,31 +717,32 @@ test("history_read paginates one document with an accurate limit and a bounded b
652
717
  const ctx = context(session);
653
718
  const content = "z".repeat(TOOL_OUTPUT_MAX_BYTES * 2);
654
719
  appendText(session, "user", content);
655
- const seq = seqs(await call(captured, "history_list", { max_chars_per_item: 1 }, ctx))[0];
720
+ const seq = (await listData(session, { max_chars_per_item: 1 })).items.map(item => item.seq)[0];
656
721
  // 50k requested chars of 64 KiB of text exceeds the byte cap, so the delivered slice stops short
657
722
  // of the request rather than at it.
658
723
  const full = await call(captured, "history_read", { seq, max_chars: 50_000 }, ctx);
659
724
  assertWithinBudget(full, "history_read page");
660
- const read = resultRead(full);
725
+ assert.match(resultText(full), /seq 1 \| user/);
726
+ const read = await readData(session, { seq, max_chars: 50_000 });
661
727
  assert.equal(read.seq, seq);
662
728
  assert.equal(read.total_chars, content.length);
663
- assert.equal(read.content, content.slice(0, read.content.length), "the delivered slice is a verbatim prefix");
729
+ assert.equal(read.text, content.slice(0, read.text.length), "the delivered slice is a verbatim prefix");
664
730
  assert.equal(read.next_offset_chars !== null, true);
665
731
  const text = full.content[0];
666
732
  assert.equal(text.type === "text" && text.text.includes("READ WINDOW"), false, "no READ WINDOW block survives");
667
- assert.match(text.type === "text" ? text.text : "", /\[truncated; continue at offset_chars=\d+\]$/, "a byte-capped window states where to continue");
668
- const next = resultRead(await call(captured, "history_read", { seq, offset_chars: read.next_offset_chars, max_chars: 50_000 }, ctx));
669
- assert.equal(read.content + next.content, content.slice(0, read.content.length + next.content.length));
670
- assert.equal(Array.from(read.content).length, read.next_offset_chars, "the cursor addresses the first undelivered character");
671
- const limited = resultRead(await call(captured, "history_read", { seq, max_chars: 10 }, ctx));
672
- assert.equal(limited.content, "z".repeat(10));
733
+ assert.match(text.type === "text" ? text.text : "", /\[truncated at \d+\/\d+ chars; continue at offset_chars=\d+\]$/, "a byte-capped window states delivered/total and where to continue");
734
+ const next = (await readData(session, { seq, offset_chars: read.next_offset_chars, max_chars: 50_000 }));
735
+ assert.equal(read.text + next.text, content.slice(0, read.text.length + next.text.length));
736
+ assert.equal(Array.from(read.text).length, read.next_offset_chars, "the cursor addresses the first undelivered character");
737
+ const limited = (await readData(session, { seq, max_chars: 10 }));
738
+ assert.equal(limited.text, "z".repeat(10));
673
739
  const limitedText = (await call(captured, "history_read", { seq, max_chars: 10 }, ctx)).content[0];
674
- const limitedSuffix = "\n\n[truncated; continue at offset_chars=10]";
740
+ const limitedSuffix = `\n\n[truncated at 10/${content.length} chars; continue at offset_chars=10]`;
675
741
  assert.equal(limitedText.type === "text" && limitedText.text.endsWith(limitedSuffix), true, "a count-limited window states where to resume");
676
- const tail = resultRead(await call(captured, "history_read", { seq, offset_chars: -10 }, ctx));
677
- assert.equal(tail.content, "z".repeat(10));
742
+ const tail = (await readData(session, { seq, offset_chars: -10 }));
743
+ assert.equal(tail.text, "z".repeat(10));
678
744
  assert.equal(tail.next_offset_chars, null, "the true end has no continuation");
679
- const past = resultError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
745
+ const past = resultTextError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
680
746
  assert.equal(past.code, "invalid_offset");
681
747
  assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
682
748
  });
@@ -697,7 +763,7 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
697
763
  assert.equal(historyDocument(tool).includes("READ WINDOW"), false);
698
764
  assert.equal(historyDocument(tool).includes("offset_chars"), false);
699
765
  assert.equal(historyDocument(tool).includes("seq "), false, "the document carries no UI identity block");
700
- const found = await historyList.execute({ query: "NEEDLE" }, projection);
766
+ const found = await historySearch.execute({ query: "NEEDLE" }, projection);
701
767
  assert.equal(found.ok, true);
702
768
  if (found.ok) {
703
769
  const hit = found.data.items[0];