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
@@ -1,32 +1,45 @@
1
- /** Host-neutral history operations: one bounded payload for text and structured results. */
1
+ /** Host-neutral history operations: bounded plain-text output. */
2
2
  import { Type } from "typebox";
3
- import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
3
+ import { HISTORY_PREVIEW_CHARS, HISTORY_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
4
4
  import { failure, success } from "../result.js";
5
- import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
6
- import { historyRoles, searchQuery } from "./schema.js";
5
+ import { fitsText, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema } from "./result.js";
6
+ import { historyRoles, parseIsoTimestamp, searchQuery } from "./schema.js";
7
+ import { localIso } from "../notes/frontmatter.js";
7
8
  import { InvalidQueryError, searchQueries } from "../text-match.js";
8
- import { HistoryPageSchema, CorpusCollector, isMultiPage, markMultiPage, selectPage } from "../history/query.js";
9
- import { currentHistory, loadHistoryRepresentative, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity } from "../history/corpus.js";
10
- import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema } from "../history/history.js";
11
- /** One read: identity, tool summary and a flat document slice. */
12
- const HistoryReadDataSchema = Type.Object({
13
- session: Type.Optional(Type.String()),
14
- notice: Type.Optional(Type.String()),
15
- seq: Type.Integer({ minimum: 1 }),
16
- role: HistoryRoleSchema,
17
- created_at: Type.Union([Type.String(), Type.Null()]),
18
- ...ToolSummarySchema.properties,
19
- nested_calls: Type.Optional(NestedCallSummarySchema),
20
- ...TextWindowSchema.properties,
21
- }, { additionalProperties: false });
9
+ import { CorpusCollector, selectPage } from "../history/query.js";
10
+ import { currentHistory, loadHistoryRepresentative, loadHistorySession, loadHistorySummary, matchesSession, parseSessionSelector, resolveSession, resolveSummaryForSelection, sessionIdentity } from "../history/corpus.js";
11
+ import { allItems, eventDocument, nestedCallSummary, toolSummary } from "../history/history.js";
12
+ const WILDCARD_CONCURRENCY = 12;
13
+ async function loadOverviewSession(session, scoped) {
14
+ if (session.loadSummary) {
15
+ const summary = await loadHistorySummary(session);
16
+ if (!summary.ok)
17
+ return undefined;
18
+ const resolved = resolveSummaryForSelection(summary.data, scoped);
19
+ if (resolved.kind === "empty")
20
+ return undefined;
21
+ if (resolved.kind === "hit")
22
+ return { event: resolved.event, notice: resolved.notice };
23
+ if (summary.data.loaded)
24
+ return summary.data.loaded;
25
+ }
26
+ else if (!scoped.roles && !scoped.after && !scoped.before && session.loadRepresentative) {
27
+ const rep = await loadHistoryRepresentative(session);
28
+ return rep.ok ? rep.data : undefined;
29
+ }
30
+ const loaded = await loadHistorySession(session);
31
+ return loaded.ok ? loaded.data : undefined;
32
+ }
22
33
  /* ------------------------------------------------------------------ rendering */
23
34
  function header(item) {
24
- return `${item.session === undefined ? "" : `session ${item.session} | `}seq ${item.seq} | ${item.role}`;
35
+ const atMs = item.created_at ? Date.parse(item.created_at) : NaN;
36
+ const at = Number.isFinite(atMs) ? localIso(atMs) : undefined;
37
+ return [item.session === undefined ? undefined : `session ${item.session}`, `seq ${item.seq}`, item.role, ...(at === undefined ? [] : [at])].filter(Boolean).join(" | ");
25
38
  }
26
39
  function toolHeader(item) {
27
40
  if (item.role !== "tool")
28
41
  return undefined;
29
- const parts = [`tool ${item.tool}`, `status ${item.tool_status}`];
42
+ const parts = [...(item.tool ? [`tool ${item.tool}`] : []), `status ${item.tool_status}`];
30
43
  if (item.output_truncated)
31
44
  parts.push(`output truncated${item.full_output_path ? `, full text at ${item.full_output_path}` : ""}`);
32
45
  if (item.nested_calls) {
@@ -36,91 +49,185 @@ function toolHeader(item) {
36
49
  }
37
50
  function renderPageItem(item) {
38
51
  const tool = toolHeader(item);
39
- const lines = [header(item) + (item.context ? " | search context" : ""), ...(tool ? [tool] : [])];
40
- if (item.truncated)
41
- lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
42
- lines.push(item.content);
52
+ const offset = (item.offset_chars ?? 0) > 0 ? ` | offset_chars ${item.offset_chars}` : "";
53
+ // The session banner already names the session above its rows; per-row identity stays local.
54
+ const lines = [header({ seq: item.seq, role: item.role, created_at: item.created_at }) + offset + (item.context ? " | search context" : ""), ...(tool ? [tool] : [])];
55
+ lines.push(item.truncated ? (item.content ? `${item.content} [truncated]` : "[truncated]") : item.content);
43
56
  return lines.join("\n");
44
57
  }
45
- function renderFoldedRow(row) {
58
+ function renderFoldedRow(row, session) {
46
59
  const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
47
- const identity = row.session === undefined ? {} : { session: row.session };
48
- const expand = `\n\t→ expand: ${JSON.stringify({ ...identity, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] })}`;
49
- return `${row.session === undefined ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
60
+ const expand = JSON.stringify({ session, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] });
61
+ return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}\n\t→ expand: ${expand}`;
50
62
  }
51
- function renderPage(page) {
52
- // An empty selection has no anchors either, so it would otherwise render as nothing at all.
53
- if (page.items.length === 0 && !page.folded_after)
54
- return `${page.notice ?? ""}No events match these filters.`;
55
- const body = [...page.items.flatMap((item) => [...(item.folded_before ? [renderFoldedRow(item.folded_before)] : []), renderPageItem(item)]), ...(page.folded_after ? [renderFoldedRow(page.folded_after)] : [])].join("\n\n");
56
- if (isMultiPage(page)) {
57
- const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
58
- return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
59
- }
60
- const hits = page.items.filter(item => !item.context);
61
- const first = hits[0];
62
- const last = hits.at(-1);
63
+ const sessionBanner = (session) => session === undefined ? "" : `=== session ${session} ===\n`;
64
+ const EMPTY_PAGE = "No events match these filters.";
65
+ function renderTimelinePage(page) {
66
+ const { session } = page.paging;
67
+ const body = [...page.items.flatMap((item) => [...(item.folded_before ? [renderFoldedRow(item.folded_before, session)] : []), renderPageItem(item)]), ...(page.folded_after ? [renderFoldedRow(page.folded_after, session)] : [])].join("\n\n");
63
68
  const cursors = [
64
- page.has_older ? `→ older: ${JSON.stringify({ session: first.session, before: first.seq })}` : "",
65
- page.has_newer ? `→ newer: ${JSON.stringify({ session: last.session, after: last.seq })}` : "",
66
- ].filter((line) => line !== "");
67
- return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`);
69
+ page.has_older ? `→ older: ${JSON.stringify({ ...page.paging, before: page.items[0].seq })}` : "",
70
+ page.has_newer ? `→ newer: ${JSON.stringify({ ...page.paging, after: page.items.at(-1).seq })}` : "",
71
+ ].filter(Boolean);
72
+ return (page.notice ?? "") + sessionBanner(session) + (body || EMPTY_PAGE) + (cursors.length ? `\n\n${cursors.join(" | ")}` : "");
73
+ }
74
+ function renderCollectionPage(page, narrow) {
75
+ const sessions = new Map(page.items.filter(item => !item.context).map(item => [item.session, []]));
76
+ for (const item of page.items)
77
+ sessions.get(item.session).push(item);
78
+ const body = [...sessions].map(([session, items]) => sessionBanner(session) + items.sort((a, b) => a.seq - b.seq).map(renderPageItem).join("\n\n")).join("\n\n");
79
+ const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
80
+ return (page.notice ?? "") + (body || sessionBanner(page.session) + EMPTY_PAGE) + (directions ? `\n\n→ more ${directions} results: ${narrow}` : "");
68
81
  }
82
+ const renderOverviewPage = (page) => renderCollectionPage(page, "narrow with since/until, roles or the session pattern");
83
+ const renderSearchPage = (page) => renderCollectionPage(page, "narrow with since/until, query, roles or the session pattern");
69
84
  function renderRead(data) {
70
85
  const tool = toolHeader(data);
71
- const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }), after: Math.max(0, data.seq - 10), before: data.seq + 10 })})`;
86
+ const neighborhood = `→ history_list: ${JSON.stringify({ session: data.session, after: Math.max(0, data.seq - 10), before: data.seq + 10 })}`;
72
87
  return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
73
88
  }
74
89
  const plainText = (text) => text;
75
90
  /** Translate query budget facts into this tool's bounded refusal; successful pages are unchanged. */
76
- function pageOutcome(result) {
91
+ function pageOutcome(result, narrow) {
77
92
  if (!("pageTooLarge" in result))
78
93
  return result;
79
- const { count, multi } = result.pageTooLarge;
80
- const narrow = multi ? "narrow the session pattern, query, roles or time bounds (`after`/`before`), or read one session/seq with `history_read`" : "narrow with `after`/`before`, pass `roles` to skip folding, or `history_read` one seq";
81
- return failure("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
94
+ return failure("page_too_large", `These events exceed the ${TOOL_OUTPUT_LIMIT} limit; ${narrow}, or use history_read for one event.`);
95
+ }
96
+ async function loadNamedSession(context, selector) {
97
+ if (!("corpus" in context))
98
+ return failure("unknown_session", "Other sessions are unavailable here.");
99
+ const target = await resolveSession(context.corpus, selector);
100
+ if (!target.ok)
101
+ return target;
102
+ const loaded = await loadHistorySession(target.data);
103
+ return loaded.ok ? success({ ...loaded.data, session: sessionIdentity(target.data) }) : loaded;
104
+ }
105
+ async function loadTimeline(context, session, tool) {
106
+ if (session === undefined)
107
+ return success({ projection: await currentHistory(context) });
108
+ const selector = parseSessionSelector(session);
109
+ if (!selector.ok)
110
+ return selector;
111
+ if (selector.data.wildcard)
112
+ return failure("invalid_session", `${tool} needs one session ID or prefix. Use history_list or history_search for wildcards.`);
113
+ return loadNamedSession(context, selector.data);
82
114
  }
83
115
  /* ------------------------------------------------------------------ history_list */
84
- const boundParameter = (description) => Type.Optional(Type.Union([Type.String(), Type.Number()], { description: `${description} Use a seq (number or digits) or ISO 8601 time (UTC without offset); wildcards take only times.` }));
116
+ const sessionParameter = (description) => Type.Optional(Type.String({ minLength: 1, description }));
117
+ const limitParameter = (description) => Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description }));
118
+ const previewParameter = Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "Maximum characters per preview." }));
119
+ const seqBound = (description) => Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description }));
120
+ const timeBound = (description) => Type.Optional(Type.String({ description: `${description} ISO 8601 (local time if no offset).` }));
121
+ function parseTimeBounds(params) {
122
+ const since = params.since === undefined ? undefined : parseIsoTimestamp(params.since);
123
+ const until = params.until === undefined ? undefined : parseIsoTimestamp(params.until);
124
+ if (params.since !== undefined && since === undefined)
125
+ return failure("invalid_bounds", `since must be an ISO 8601 time; got ${JSON.stringify(params.since)}.`);
126
+ if (params.until !== undefined && until === undefined)
127
+ return failure("invalid_bounds", `until must be an ISO 8601 time; got ${JSON.stringify(params.until)}.`);
128
+ return success({ since, until });
129
+ }
85
130
  export const historyListParameters = Type.Object({
86
- session: Type.Optional(Type.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
131
+ session: sessionParameter("Session ID, prefix, or wildcard (e.g. `*`, `pi:*`) for one event per session. Omit for current session."),
132
+ roles: historyRoles(true),
133
+ after: seqBound("Exclusive seq; page forward (0 starts at the beginning)."),
134
+ before: seqBound("Exclusive seq; without `after`, takes newest events."),
135
+ since: timeBound("Exclusive start time; oldest first."),
136
+ until: timeBound("Exclusive end time; without `since`, newest first."),
137
+ limit: limitParameter("Events or sessions per page."),
138
+ max_chars_per_item: previewParameter,
139
+ }, { additionalProperties: false });
140
+ export const historyList = {
141
+ name: "history_list",
142
+ label: "Browse history",
143
+ description: "Browse one session's timeline (oldest to newest), or pass a wildcard `session` to overview matching sessions.",
144
+ parameters: historyListParameters,
145
+ async execute(params, context, wrapText = plainText) {
146
+ const { after, before, roles, limit, max_chars_per_item } = params;
147
+ const bounds = parseTimeBounds(params);
148
+ if (!bounds.ok)
149
+ return bounds;
150
+ const { since, until } = bounds.data;
151
+ const selector = params.session === undefined ? undefined : parseSessionSelector(params.session);
152
+ if (selector && !selector.ok)
153
+ return selector;
154
+ if (selector?.ok && selector.data.wildcard) {
155
+ if (after !== undefined || before !== undefined) {
156
+ return failure("invalid_bounds", "after and before are seq numbers for a single session; use since and until with wildcard sessions.");
157
+ }
158
+ const wild = selector.data;
159
+ if (!("corpus" in context))
160
+ return failure("unknown_session", "Other sessions are unavailable here.");
161
+ const scoped = {
162
+ after: since === undefined ? undefined : { at: since },
163
+ before: until === undefined ? undefined : { at: until },
164
+ roles,
165
+ limit,
166
+ };
167
+ const sessions = (await context.corpus.sessions(wild.harness)).filter((s) => matchesSession(s, wild));
168
+ sessions.sort((a, b) => (since !== undefined ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
169
+ const targetCount = Math.min(500, Math.max(1, limit ?? 20));
170
+ const collector = new CorpusCollector(scoped);
171
+ const notices = [];
172
+ let qualifying = 0, offset = 0;
173
+ while (offset < sessions.length && qualifying < targetCount) {
174
+ const batchSize = Math.min(WILDCARD_CONCURRENCY, targetCount - qualifying, sessions.length - offset);
175
+ const batch = sessions.slice(offset, offset + batchSize);
176
+ const loadedBatch = await Promise.all(batch.map((s) => loadOverviewSession(s, scoped)));
177
+ for (let i = 0; i < batch.length; i++) {
178
+ const s = batch[i];
179
+ const item = loadedBatch[i];
180
+ if (!item)
181
+ continue;
182
+ const added = collector.addRepresentative(sessionIdentity(s), item.projection ?? item.event);
183
+ if (!added)
184
+ continue;
185
+ qualifying++;
186
+ if (item.notice)
187
+ notices.push(`session ${sessionIdentity(s)}: ${item.notice}`);
188
+ }
189
+ offset += batch.length;
190
+ }
191
+ const unvisited = offset < sessions.length;
192
+ const decorateOverview = (page) => ({ ...page, ...(notices.length ? { notice: notices.join("") } : {}) });
193
+ const overview = pageOutcome(collector.page((page) => fitsText(wrapText(renderOverviewPage(decorateOverview(page)))), max_chars_per_item ?? HISTORY_PREVIEW_CHARS, unvisited), "narrow with since/until, roles or the session pattern");
194
+ return overview.ok ? success(decorateOverview(overview.data)) : overview;
195
+ }
196
+ const loaded = await loadTimeline(context, params.session, "history_list");
197
+ if (!loaded.ok)
198
+ return loaded;
199
+ const { projection, session, notice } = loaded.data;
200
+ const paging = { session, roles, since: params.since, until: params.until, limit, max_chars_per_item };
201
+ const decorate = (page) => ({ ...page, paging, ...(notice === undefined ? {} : { notice }) });
202
+ const result = pageOutcome(selectPage(projection, {
203
+ roles, limit,
204
+ after: after === undefined ? undefined : { seq: after },
205
+ before: before === undefined ? undefined : { seq: before },
206
+ since, until,
207
+ }, page => fitsText(wrapText(renderTimelinePage(decorate(page)))), max_chars_per_item ?? HISTORY_PREVIEW_CHARS), "narrow with after/before, since/until or specify roles");
208
+ return result.ok ? success(decorate(result.data)) : result;
209
+ },
210
+ render: (result) => renderOutcome(result, (page) => "paging" in page ? renderTimelinePage(page) : renderOverviewPage(page)),
211
+ };
212
+ /* ------------------------------------------------------------------ history_search */
213
+ export const historySearchParameters = Type.Object({
214
+ session: sessionParameter("Session ID, prefix, or wildcard (e.g. `*`, `pi:*`). Omit for current session."),
215
+ query: searchQuery("Case-insensitive literal text, or a list (any match)."),
216
+ since: timeBound("Exclusive start time; oldest matches first."),
217
+ until: timeBound("Exclusive end time; without `since`, newest matches first."),
87
218
  roles: historyRoles(),
88
- query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
89
- after: boundParameter("Start strictly after this bound, paging forward; 0 starts at the oldest event."),
90
- before: boundParameter("Stop strictly before this bound; without `after`, take the newest eligible events."),
91
- context: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events on each side of a hit in its own session; requires a query." })),
92
- limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
93
- max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." })),
219
+ context: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events shown on each side of a hit." })),
220
+ limit: limitParameter("Hits per page."),
221
+ max_chars_per_item: previewParameter,
94
222
  }, { additionalProperties: false });
95
- const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
96
- function parseBound(name, value) {
97
- if (value === undefined)
98
- return success(undefined);
99
- if (typeof value === "number" || /^\d+$/.test(value)) {
100
- const seq = Number(value);
101
- if (Number.isSafeInteger(seq) && seq >= 0)
102
- return success({ seq });
103
- }
104
- else if (typeof value === "string") {
105
- const match = ISO_8601.exec(value);
106
- const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
107
- if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10)))
108
- return success({ at });
109
- }
110
- return failure("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
111
- }
112
- function parseSelection(params) {
113
- const after = parseBound("after", params.after);
114
- if (!after.ok)
115
- return after;
116
- const before = parseBound("before", params.before);
117
- if (!before.ok)
118
- return before;
223
+ function searchSelection(params) {
224
+ const bounds = parseTimeBounds(params);
225
+ if (!bounds.ok)
226
+ return bounds;
227
+ const { since, until } = bounds.data;
119
228
  try {
120
229
  const query = searchQueries(params.query);
121
- if (!query.length && params.context !== undefined)
122
- return failure("invalid_params", "`context` requires a non-empty `query`.");
123
- return success({ after: after.data, before: before.data, query: query.length ? query : undefined, roles: params.roles, context: params.context, limit: params.limit });
230
+ return success({ after: since === undefined ? undefined : { at: since }, before: until === undefined ? undefined : { at: until }, query, roles: params.roles, context: params.context, limit: params.limit });
124
231
  }
125
232
  catch (error) {
126
233
  if (error instanceof InvalidQueryError)
@@ -128,99 +235,86 @@ function parseSelection(params) {
128
235
  throw error;
129
236
  }
130
237
  }
131
- export const historyList = {
132
- name: "history_list",
133
- label: "History list items",
134
- description: "Flip back through the record, a page at a time. Another session: its ID. `*` pulls every recent session off the shelf; add `query` to search them.",
135
- parameters: historyListParameters,
136
- outputSchema: resultSchema(HistoryPageSchema),
238
+ export const historySearch = {
239
+ name: "history_search",
240
+ label: "Search history",
241
+ description: "Search passages by literal text in one or more sessions, including tool arguments and output.",
242
+ parameters: historySearchParameters,
137
243
  async execute(params, context, wrapText = plainText) {
138
- const selection = parseSelection(params);
244
+ const selection = searchSelection(params);
139
245
  if (!selection.ok)
140
246
  return selection;
141
247
  const scoped = selection.data;
142
- // Charge wrapped rendering, identities, notices and recipes, not only event previews.
143
- const fits = (page) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
144
- const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
248
+ const { after, before, query } = scoped;
249
+ const collector = new CorpusCollector(scoped);
250
+ const notices = [];
251
+ let session;
145
252
  if (params.session === undefined)
146
- return pageOutcome(selectPage(await currentHistory(context), scoped, fits, maxChars));
147
- const selector = parseSessionSelector(params.session);
148
- if (!selector.ok)
149
- return selector;
150
- const corpus = "corpus" in context ? context.corpus : undefined;
151
- if (selector.data.wildcard) {
152
- const { after, before, query, roles } = scoped;
153
- if ((after && "seq" in after) || (before && "seq" in before))
154
- return failure("invalid_bounds", "Wildcard history requires times, not seqs, for `after` and `before`.");
155
- if (corpus === undefined)
156
- return failure("unknown_session", "This host supplied no cross-session history corpus.");
157
- const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
158
- if (!query)
159
- sessions.sort((a, b) => (after ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
160
- const representative = !query && !roles && !after && !before;
161
- const collector = new CorpusCollector(scoped);
162
- let qualifying = 0;
163
- const notices = [];
164
- let unvisited = false;
165
- for (const [index, session] of sessions.entries()) {
166
- const result = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, query);
167
- if (!result.ok || !result.data)
168
- continue;
169
- const added = "projection" in result.data ? collector.add(sessionIdentity(session), result.data.projection) : collector.addRepresentative(sessionIdentity(session), result.data.event);
170
- if (!added)
171
- continue;
172
- qualifying++;
173
- if (result.data.notice)
174
- notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
175
- if (!query && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
176
- unvisited = index + 1 < sessions.length;
177
- break;
253
+ collector.addMatches("", await currentHistory(context));
254
+ else {
255
+ const selector = parseSessionSelector(params.session);
256
+ if (!selector.ok)
257
+ return selector;
258
+ const corpus = "corpus" in context ? context.corpus : undefined;
259
+ if (!selector.data.wildcard) {
260
+ const loaded = await loadNamedSession(context, selector.data);
261
+ if (!loaded.ok)
262
+ return loaded;
263
+ session = loaded.data.session;
264
+ collector.addMatches(session, loaded.data.projection);
265
+ if (loaded.data.notice)
266
+ notices.push(loaded.data.notice);
267
+ }
268
+ else {
269
+ if (!corpus)
270
+ return failure("unknown_session", "Other sessions are unavailable here.");
271
+ if (query && query.length > 0) {
272
+ const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
273
+ const hasTimeBounds = after !== undefined || before !== undefined;
274
+ const noticesByIndex = new Array(sessions.length);
275
+ let next = 0;
276
+ const workers = Math.min(WILDCARD_CONCURRENCY, sessions.length);
277
+ await Promise.all(Array.from({ length: workers }, async () => {
278
+ while (next < sessions.length) {
279
+ const index = next++;
280
+ const session = sessions[index];
281
+ if (hasTimeBounds && session.peekSummary) {
282
+ const summary = await session.peekSummary();
283
+ if (summary && resolveSummaryForSelection(summary, scoped).kind === "empty")
284
+ continue;
285
+ }
286
+ const result = await loadHistorySession(session, query);
287
+ if (!result.ok || !result.data)
288
+ continue;
289
+ collector.addMatches(sessionIdentity(session), result.data.projection);
290
+ if (result.data.notice)
291
+ noticesByIndex[index] = `session ${sessionIdentity(session)}: ${result.data.notice}`;
292
+ }
293
+ }));
294
+ for (const entry of noticesByIndex)
295
+ if (entry)
296
+ notices.push(entry);
178
297
  }
179
298
  }
180
- const notice = notices.length ? { notice: notices.join("") } : {};
181
- const result = pageOutcome(collector.page((page) => fits(markMultiPage({ ...page, ...notice })), maxChars, unvisited));
182
- return result.ok ? success(markMultiPage({ ...result.data, ...notice })) : result;
183
299
  }
184
- const target = await resolveSession(corpus, selector.data);
185
- if (!target.ok)
186
- return target;
187
- const loaded = await loadHistorySession(target.data);
188
- if (!loaded.ok)
189
- return loaded;
190
- const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
191
- const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
192
- return result.ok ? success({ ...result.data, ...notice }) : result;
300
+ const decorate = (page) => ({ ...page, ...(session === undefined ? {} : { session }), ...(notices.length ? { notice: notices.join("") } : {}) });
301
+ const result = pageOutcome(collector.page(page => fitsText(wrapText(renderSearchPage(decorate(page)))), params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS), "narrow with since/until, query, roles or the session pattern");
302
+ return result.ok ? success(decorate(result.data)) : result;
193
303
  },
194
- render: (result) => renderOutcome(result, renderPage),
304
+ render: (result) => renderOutcome(result, renderSearchPage),
195
305
  };
196
306
  /* ------------------------------------------------------------------ history_read */
197
- export const historyReadParameters = Type.Object({ session: Type.Optional(Type.String({ minLength: 1, description: "Whose record: a session ID or prefix. Leave it out for this one." })), seq: Type.Integer({ minimum: 1, description: "Which entry, by its seq from `history_list`; bring its session along if it had one." }), ...TextWindowRequestSchema }, { additionalProperties: false });
307
+ export const historyReadParameters = Type.Object({ session: sessionParameter("Session ID or prefix. Omit for current session."), seq: Type.Integer({ minimum: 1, description: "Event seq to read." }), ...TextWindowRequestSchema }, { additionalProperties: false });
198
308
  export const historyRead = {
199
309
  name: "history_read",
200
- label: "History read item",
201
- description: "Open one entry: what was called, what came back, the calls nested inside. Long entries come in slices; follow `next_offset_chars`.",
310
+ label: "Read history event",
311
+ description: "Read one history event, including tool arguments, output, and nested calls.",
202
312
  parameters: historyReadParameters,
203
- outputSchema: resultSchema(HistoryReadDataSchema),
204
313
  async execute(params, context, wrapText = plainText) {
205
- let projection;
206
- let identity = {};
207
- if (params.session === undefined)
208
- projection = await currentHistory(context);
209
- else {
210
- const selector = parseSessionSelector(params.session);
211
- if (!selector.ok)
212
- return selector;
213
- if (selector.data.wildcard)
214
- return failure("invalid_session", "`history_read` reads one session; pass a specific `session` ID, not a wildcard.");
215
- const target = await resolveSession("corpus" in context ? context.corpus : undefined, selector.data);
216
- if (!target.ok)
217
- return target;
218
- const loaded = await loadHistorySession(target.data);
219
- if (!loaded.ok)
220
- return loaded;
221
- projection = loaded.data.projection;
222
- identity = { session: sessionIdentity(target.data), ...(loaded.data.notice === undefined ? {} : { notice: loaded.data.notice }) };
223
- }
314
+ const loaded = await loadTimeline(context, params.session, "history_read");
315
+ if (!loaded.ok)
316
+ return loaded;
317
+ const { projection, ...identity } = loaded.data;
224
318
  // Address checks run in one order: past the end of the file, off this branch, then
225
319
  // resolved through any tool-result pairing to its call event.
226
320
  if (params.seq > projection.highestSeq) {
@@ -241,7 +335,7 @@ export const historyRead = {
241
335
  if (typeof params.offset_chars === "number" && params.offset_chars > totalChars) {
242
336
  return failure("invalid_offset", `This event ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
243
337
  }
244
- return readTextWindow(document, params.offset_chars, params.max_chars, (window) => ({
338
+ return readTextWindow(document, params.offset_chars, params.max_chars ?? HISTORY_READ_WINDOW_CHARS, (window) => ({
245
339
  ...identity,
246
340
  seq: item.seq,
247
341
  role: item.role,