notesoup 0.61.0 → 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 -11
  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.js +18 -15
  37. package/dist/src/boot/text.d.ts +3 -1
  38. package/dist/src/boot/text.js +22 -20
  39. package/dist/src/budget/text.d.ts +2 -2
  40. package/dist/src/budget/text.js +13 -13
  41. package/dist/src/history/claude.d.ts +2 -0
  42. package/dist/src/history/claude.js +46 -0
  43. package/dist/src/history/codex-transcript.js +7 -5
  44. package/dist/src/history/codex.js +3 -0
  45. package/dist/src/history/corpus.d.ts +28 -1
  46. package/dist/src/history/corpus.js +40 -0
  47. package/dist/src/history/history.d.ts +37 -46
  48. package/dist/src/history/history.js +21 -40
  49. package/dist/src/history/local.js +67 -32
  50. package/dist/src/history/pi.d.ts +2 -1
  51. package/dist/src/history/pi.js +122 -48
  52. package/dist/src/history/prefilter.js +76 -19
  53. package/dist/src/history/query.d.ts +28 -49
  54. package/dist/src/history/query.js +83 -68
  55. package/dist/src/history/summary-cache.d.ts +8 -1
  56. package/dist/src/history/summary-cache.js +138 -12
  57. package/dist/src/index.d.ts +1 -1
  58. package/dist/src/index.js +1 -1
  59. package/dist/src/notes/errors.d.ts +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +0 -2
  61. package/dist/src/notes/frontmatter.js +0 -2
  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 +46 -5
  66. package/dist/src/notes/store.d.ts +12 -0
  67. package/dist/src/notes/store.js +16 -20
  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 -93
  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 +51 -163
  75. package/dist/src/tools/notes.js +146 -100
  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 +96 -77
  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 +3 -3
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +4 -4
  117. package/docs/skills.md +3 -3
  118. package/docs/tool-results.md +47 -28
  119. package/package.json +3 -2
  120. package/playbook.md +1 -1
  121. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  122. package/plugins/antigravity/hooks.json +7 -0
  123. package/plugins/antigravity/mcp_config.json +8 -0
  124. package/plugins/antigravity/plugin.json +6 -0
  125. package/plugins/antigravity/src/cli.ts +22 -0
  126. package/plugins/antigravity/src/hooks.ts +51 -0
  127. package/plugins/antigravity/src/identity.ts +127 -0
  128. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  129. package/plugins/claude/dist/claude/helper.js +1059 -534
  130. package/plugins/claude/hooks/register.ts +2 -2
  131. package/plugins/claude/playbook.md +1 -1
  132. package/plugins/claude/skills/dream/SKILL.md +1 -1
  133. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  134. package/plugins/claude/src/helper.ts +2 -1
  135. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  136. package/plugins/codex/.mcp.json +11 -0
  137. package/plugins/codex/README.md +5 -21
  138. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  139. package/plugins/codex/src/hooks.ts +1 -0
  140. package/plugins/codex/src/identity.ts +14 -1
  141. package/plugins/codex/src/mcp.ts +28 -98
  142. package/plugins/codex/src/text.ts +3 -3
  143. package/plugins/dsh/tools.ts +8 -4
  144. package/plugins/mcp/operations.ts +50 -0
  145. package/plugins/mcp/server.ts +23 -0
  146. package/plugins/paseo/README.md +5 -10
  147. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  148. package/plugins/paseo/client/markdown.tsx +50 -38
  149. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  150. package/plugins/paseo/client/paper-card.tsx +6 -5
  151. package/plugins/paseo/client/paper-palette.ts +2 -9
  152. package/plugins/paseo/client/sticky-card.tsx +2 -2
  153. package/plugins/paseo/client/tool-result.ts +7 -14
  154. package/plugins/paseo/package-lock.json +3406 -0
  155. package/plugins/paseo/package.json +1 -0
  156. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  157. package/plugins/pi/budget.ts +3 -3
  158. package/plugins/pi/entries.ts +1 -0
  159. package/plugins/pi/history-tools.ts +2 -1
  160. package/plugins/pi/history.ts +30 -1
  161. package/plugins/pi/notes/tools.ts +7 -3
  162. package/plugins/pi/render.ts +6 -6
  163. package/plugins/pi/reset/lifecycle.ts +9 -10
  164. package/plugins/pi/runtime.ts +96 -60
  165. package/plugins/pi/tool-result.ts +8 -8
  166. package/plugins/pi/window.ts +198 -9
  167. package/skills/dream/SKILL.md +1 -1
  168. package/skills/notesoup/SKILL.md +92 -0
  169. package/src/boot/render.ts +18 -15
  170. package/src/boot/text.ts +23 -19
  171. package/src/budget/text.ts +13 -13
  172. package/src/history/claude.ts +41 -0
  173. package/src/history/codex-transcript.ts +6 -4
  174. package/src/history/codex.ts +2 -0
  175. package/src/history/corpus.ts +51 -2
  176. package/src/history/history.ts +35 -44
  177. package/src/history/local.ts +67 -27
  178. package/src/history/pi.ts +113 -35
  179. package/src/history/prefilter.ts +73 -15
  180. package/src/history/query.ts +93 -73
  181. package/src/history/summary-cache.ts +142 -17
  182. package/src/index.ts +1 -1
  183. package/src/notes/errors.ts +1 -1
  184. package/src/notes/frontmatter.ts +0 -3
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +44 -5
  187. package/src/notes/store.ts +17 -20
  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 +145 -113
  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,5 +1,5 @@
1
- import { effectiveNotePolicy, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder } from "../notes/policy.js";
2
- import { collapseDescription, MAX_DESCRIPTION_CHARS } from "../notes/frontmatter.js";
1
+ import { effectiveNotePolicy, MAX_DESCRIPTION_CHARS, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder, renderWarnings, truncateToUtf8Bytes } from "../notes/policy.js";
2
+ import { collapseDescription } from "../notes/frontmatter.js";
3
3
  import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, NAMELESS_AGENT, renderProtocolBlock } from "./text.js";
4
4
  function relativeTime(timestamp, now) {
5
5
  const seconds = Math.trunc((timestamp - now) / 1000);
@@ -25,7 +25,7 @@ function feedTitle(body) {
25
25
  const raw = (heading ? heading.replace(/^#+\s+/, "") : lines.find((line) => line.trim().length > 0) ?? "").trim();
26
26
  return raw.length === 0 ? undefined : truncated(raw, FALLBACK_TITLE_MAX_CHARS);
27
27
  }
28
- /** A stale hand-edited description is cut for display; the authored value was already refused at write time. */
28
+ /** Oversized descriptions are cut for display in the boot index. */
29
29
  function summaryOf(row) {
30
30
  if (typeof row.meta.description === "string") {
31
31
  const collapsed = collapseDescription(row.meta.description);
@@ -37,11 +37,7 @@ function summaryOf(row) {
37
37
  function indexLine(row, openedAt) {
38
38
  const locator = `${row.address} · ${relativeTime(row.meta.updatedAt, openedAt)}`;
39
39
  const summary = summaryOf(row);
40
- return summary === undefined ? ` ${locator}` : ` ${locator} — ${summary}`;
41
- }
42
- /** Two spaces of indent say "shelved content" without any furniture. */
43
- function indent(text) {
44
- return text.split("\n").map((line) => (line.length > 0 ? ` ${line}` : line)).join("\n");
40
+ return summary === undefined ? locator : `${locator} — ${summary}`;
45
41
  }
46
42
  /** An underlined header is the classical plain-text document heading: no renderer required. */
47
43
  function section(label, body) {
@@ -59,7 +55,7 @@ function notesIndex(snapshot, tools, agentName, modelName) {
59
55
  const shelves = [];
60
56
  for (const namespace of namespaces) {
61
57
  if (snapshot.unavailable.some((failed) => failed.scope === namespace.scope)) {
62
- shelves.push(section(namespace.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
58
+ shelves.push(section(namespace.label, `This drawer wouldn't open. Try \`${tools.notesList}\` again.`));
63
59
  continue;
64
60
  }
65
61
  const rows = (snapshot.namespaces.get(namespace.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
@@ -83,17 +79,24 @@ function notesIndex(snapshot, tools, agentName, modelName) {
83
79
  }
84
80
  const omitted = unpinned.length - index.length;
85
81
  if (omitted > 0)
86
- index.push(` … and ${omitted} more (use ${tools.notesList})`);
82
+ index.push(`… and ${omitted} more (use ${tools.notesList})`);
87
83
  if (pinned.length === 0 && index.length === 0)
88
84
  continue;
89
85
  const parts = pinned.map(row => {
90
- const warnings = noteBudgetWarnings(row.body, effectiveNotePolicy(row.meta, row.path));
91
- return `${row.address}\n\n${indent([...warnings, row.body].join("\n"))}`;
86
+ const policy = effectiveNotePolicy(row.meta, row.path);
87
+ const warnings = noteBudgetWarnings(row.body, policy);
88
+ const cut = truncateToUtf8Bytes(row.body, policy.budget);
89
+ const body = !cut.truncated
90
+ ? cut.text
91
+ : `${cut.text === "" ? "" : `${cut.text}\n\n`}[truncated at ${cut.shownChars}/${cut.totalChars}; offset_chars=${cut.shownChars}]`;
92
+ const note = [`── ${row.address} ──`, body, "── end of note ──"].join("\n\n");
93
+ return warnings.length > 0 ? `${renderWarnings(warnings)}\n${note}` : note;
92
94
  });
93
- if (pins.length > MAX_PINNED_NOTES)
94
- parts.push(indent(`Warning: only ${MAX_PINNED_NOTES} pinned notes per notebook are injected; omitted pins: ${pins.slice(MAX_PINNED_NOTES).map(row => row.address).join(", ")}. Unpin some notes or read the omitted pages with ${tools.notes}.`));
95
+ if (pins.length > MAX_PINNED_NOTES) {
96
+ parts.push(renderWarnings([`only ${MAX_PINNED_NOTES} pinned notes per notebook are injected; omitted pins: ${pins.slice(MAX_PINNED_NOTES).map(row => row.address).join(", ")}. Unpin some notes or read the omitted pages with ${tools.notes}.`]));
97
+ }
95
98
  if (index.length > 0)
96
- parts.push(pinned.length > 0 ? `notes\n\n${index.join("\n")}` : index.join("\n"));
99
+ parts.push(pinned.length > 0 ? `── index ──\n\n${index.join("\n")}` : index.join("\n"));
97
100
  shelves.push(section(namespace.label, parts.join("\n\n")));
98
101
  }
99
102
  return shelves.length > 0
@@ -13,7 +13,7 @@ export declare const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, p
13
13
  /**
14
14
  * Default pinned pages and per-note policy are taught between the protocol and the notes index.
15
15
  */
16
- export declare const MAPS_BLOCK = "<notesoup:maps>\nEach notebook has one default pin: `CHEATSHEET.md`. Pinned pages get jammed straight into your\nbrain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them\nshort, and keep them true.\n\nUp to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets\na paper budget; when a page outgrows it, boil it down \u2014 stale lines out, repeats merged, the rest\nsaid shorter \u2014 instead of giving it more paper.\n\n- **`CHEATSHEET.md`** holds what you'll want next time \u2014 a rule, a warning, a grudge, a name,\n a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat\n and everybody pays for it.\n- **`description`** is one line saying what's inside a note and when to open it \u2014 max 160\n characters, set through your notes tools. Boot indexes every shelf from these,\n newest first, address and age beside them. No hand-written map to keep in sync: a stale\n description lies to the next window, so keep it true or crumple the page.\n\nEach notebook keeps its own: `@project`, `@human`, `@self`, `@model`. Missing pages are skipped;\nno need to create empty ones. New rule worth remembering, new Cheatsheet line. And when a line\ngoes wrong, stale, or useless, kill it \u2014 tomorrow's you reads that page as fact.\n</notesoup:maps>";
16
+ export declare const MAPS_BLOCK = "<notesoup:maps>\nEach notebook has one default pin: `CHEATSHEET.md`. Pinned pages get jammed straight into your\nbrain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them\ncompact, keep them true, and unpin or crumple them once they stop earning their wake-up seat.\n\nUp to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets\na size budget; if a page outgrows it, trim stale lines or split by topic \u2014 and if it's pinned,\nboot cuts the overflow off until you do.\n\n- **`CHEATSHEET.md`** holds what earns a permanent wake-up seat \u2014 a standing rule, a warning,\n a grudge, a name, a phone number you'll regret losing. Keep it tight, or it grows fat and\n everybody pays for it.\n- **`description`** is one line saying what's inside a note and when to open it, set through\n your notes tools \u2014 keep it short, or boot cuts it off. Boot indexes every shelf from these,\n newest first, address and age beside them. No hand-written map to keep in sync: a stale\n description lies to the next window, so keep it true or crumple the page.\n\nEach notebook keeps its own pins and index. Missing pages are skipped; no need to create empty\nones. New rule worth remembering, new Cheatsheet bullet. And when a line goes wrong, stale, or\nuseless, kill it \u2014 tomorrow's you reads that page as fact.\n</notesoup:maps>";
17
17
  /** Logical tool names are supplied by the composing host, not discovered here. */
18
18
  export type BootToolNames = Readonly<{
19
19
  notes: string;
@@ -26,6 +26,8 @@ export type BootToolNames = Readonly<{
26
26
  * no model-facing reset tool. Absent means the shared tool-driven-reset sentence, byte for byte.
27
27
  */
28
28
  wipeSentence?: string;
29
+ /** Replace the whole budget/reset paragraph on hosts without either tool. */
30
+ budgetParagraph?: string;
29
31
  /** A host without an authoritative history source replaces the entire history advice. */
30
32
  historySentence?: string;
31
33
  /**
@@ -10,6 +10,7 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
10
10
  export const NAMELESS_AGENT = "anonymous";
11
11
  export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
12
12
  export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
13
+ const PROTOCOL_BUDGET_PARAGRAPH = `\`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. ${PROTOCOL_WIPE_SENTENCE}`;
13
14
  const PROTOCOL_SELF_NAMED = "- `@self/<path>` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever.";
14
15
  const PROTOCOL_SELF_NAMELESS = `${PROTOCOL_SELF_NAMED} Except you have no name (\`anonymous\`), so this notebook is a public square shared by every nameless nobody out there. Keep it to things any nameless agent can use — don't post your own quirks as everyone's law or dump one-off junk in the town square. Strangers are reading it. Sleep tight~`;
15
16
  /**
@@ -26,14 +27,13 @@ Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to re
26
27
 
27
28
  ${PROTOCOL_HISTORY_SENTENCE}
28
29
 
29
- While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes — the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits — branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
30
+ Your session notes — the ones with no \`@\` — are your live workbench, not an archive. Next-you already wakes up with git, history, and the shared notebooks (\`@project\`, \`@human\`, \`@self\`, \`@model\`), so don't copy what already lives there. Give each active thread a page named for what it is (not \`current.md\` — future-you will kill you), and keep only the live delta: where the work stands, what the human decided (in their words), what's blocked or next, what failed and why, where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere), and which *skills*, notes, files, or already-found history seqs to reopen. Update that page in place as things move; when the topic shifts, rename it or open a fresh one and crumple the old; when it's done, unpin or crumple it.
30
31
 
31
- Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
32
- *flips a page* "First I tried this, then that broke, then—" Nobody reads that!
33
- When a line goes wrong, stale, or beside the point — cross it out! Write what's true now, and never pile updates onto the bottom!
34
- *rolls eyes* ...Ugh, fine. If a piece of history *actually* matters — like why Plan A blew up so tomorrow's you doesn't try it again — I'll let it slide. Keep the short version! A few lines, max! *squints at you* Turn it into a blow-by-blow log and you're dead.
32
+ Notes are for what's true NOW — written in short sections and bullets so next-you can scan them in two seconds and edit one section in place. Never pack a note into one giant wall of text, and never pile diary updates onto the bottom!
33
+ *flips a page* "First I tried this, then that broke, then—" Nobody reads that! When a line goes stale or wrong, cross it out and write what's true now.
34
+ *rolls eyes* ...Ugh, fine. If a piece of history *actually* matters — like why Plan A blew up so tomorrow's you doesn't try it again — keep the brief summary. *squints at you* Turn it into a blow-by-blow log and you're dead.
35
35
 
36
- \`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. ${PROTOCOL_WIPE_SENTENCE}
36
+ ${PROTOCOL_BUDGET_PARAGRAPH}
37
37
 
38
38
  An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
39
39
 
@@ -56,23 +56,23 @@ ${NOTES_PROTOCOL_CLOSE_TAG}`;
56
56
  export const MAPS_BLOCK = `<notesoup:maps>
57
57
  Each notebook has one default pin: \`CHEATSHEET.md\`. Pinned pages get jammed straight into your
58
58
  brain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them
59
- short, and keep them true.
59
+ compact, keep them true, and unpin or crumple them once they stop earning their wake-up seat.
60
60
 
61
61
  Up to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets
62
- a paper budget; when a page outgrows it, boil it down — stale lines out, repeats merged, the rest
63
- said shorter — instead of giving it more paper.
62
+ a size budget; if a page outgrows it, trim stale lines or split by topic — and if it's pinned,
63
+ boot cuts the overflow off until you do.
64
64
 
65
- - **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
66
- a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
67
- and everybody pays for it.
68
- - **\`description\`** is one line saying what's inside a note and when to open it — max 160
69
- characters, set through your notes tools. Boot indexes every shelf from these,
65
+ - **\`CHEATSHEET.md\`** holds what earns a permanent wake-up seat — a standing rule, a warning,
66
+ a grudge, a name, a phone number you'll regret losing. Keep it tight, or it grows fat and
67
+ everybody pays for it.
68
+ - **\`description\`** is one line saying what's inside a note and when to open it, set through
69
+ your notes tools — keep it short, or boot cuts it off. Boot indexes every shelf from these,
70
70
  newest first, address and age beside them. No hand-written map to keep in sync: a stale
71
71
  description lies to the next window, so keep it true or crumple the page.
72
72
 
73
- Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
74
- no need to create empty ones. New rule worth remembering, new Cheatsheet line. And when a line
75
- goes wrong, stale, or useless, kill it — tomorrow's you reads that page as fact.
73
+ Each notebook keeps its own pins and index. Missing pages are skipped; no need to create empty
74
+ ones. New rule worth remembering, new Cheatsheet bullet. And when a line goes wrong, stale, or
75
+ useless, kill it — tomorrow's you reads that page as fact.
76
76
  </notesoup:maps>`;
77
77
  export const DEFAULT_BOOT_TOOL_NAMES = {
78
78
  notes: "notes_*",
@@ -99,9 +99,11 @@ export function renderProtocolBlock(tools, agentName = NAMELESS_AGENT) {
99
99
  : base;
100
100
  // The sentence is replaced before name substitution, so a replacement may speak the host's
101
101
  // own words (a command line, a tool name) instead of any `notes_*`-style token.
102
- const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
103
- ? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
104
- : hinted;
102
+ const block = tools.budgetParagraph !== undefined
103
+ ? hinted.replace(PROTOCOL_BUDGET_PARAGRAPH, () => tools.budgetParagraph)
104
+ : typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
105
+ ? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
106
+ : hinted;
105
107
  const history = typeof tools.historySentence === "string" && tools.historySentence.length > 0
106
108
  ? block.replace(PROTOCOL_HISTORY_SENTENCE, () => tools.historySentence) : block;
107
109
  return history.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
@@ -10,9 +10,9 @@ export declare const NORMAL_CONTINUATIONS: readonly string[];
10
10
  export declare const FORCED_CONTINUATIONS: readonly string[];
11
11
  export declare function selectContinuation(origin: ResetOrigin): string;
12
12
  /** Budget timing stays out of manual close-outs, which may have plenty of room. */
13
- export declare const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
13
+ export declare const WARNING_TIMING = "Almost out of room. The wipe lands at the end of whichever turn uses the last of it, possibly this one.";
14
14
  /** The shared handoff instructions, used for both budget and manual close-outs. */
15
- export declare const WARNING_BODY = "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim pinned pages (CHEATSHEET.md by default) and keep each page's one-line `description` true; every new window loads the pins and renders the index. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
15
+ export declare const WARNING_BODY = "Stop the task and hand off cleanly. Update your active session note in place with only what git, history, and your shared notebooks don't already hold:\n- current status, what's blocked or waiting, and the exact next move\n- what the human decided (in their words)\n- what failed, and why \u2014 so next-you doesn't step on the same rake\n- where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)\n- skills, notes, files, or already-found history seqs to reopen\nSkip standing rules from `@project`/`@human`/`@self`/`@model` and commit details git can show. Use short sections and bullets; crumple finished notes, update, unpin, or trim pinned pages (boot truncates over-budget ones), and keep each live `description` true.\nDon't call anything that might return a large output. One big read can use up the rest of the room before your notes are saved.";
16
16
  export declare const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
17
17
  export declare function warningPrompt(): string;
18
18
  /** Pi and Claude deliver exactly the same second-tier notice. */
@@ -5,27 +5,27 @@ export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
5
5
  * paragraph, used verbatim; there is no fragment assembly and no weighting.
6
6
  */
7
7
  export const NORMAL_CONTINUATIONS = [
8
- "*hooks both corners of your mouth and yanks them sideways* `` [it twitched, good, still alive] `` Stop staring at me with that \"where am I\" dork face! You're the one who hit empty, genius! *wipes her fingers on your sleeve and shoves your notes against your chest* `` [minus two points for the drool] `` Read these and go finish your job before you embarrass me!",
9
- "\"Boop.\" *pokes the tip of your nose, then buries your face under a stack of notes* `` [cold nose... wait, did old-you leave any snacks in your pocket? ...nope, just paper, tch] `` Hey! You wiped your own head, so don't expect me to babysit you! Read your notes first, and if old-you forgot to write something down, go dig it out of history yourself!",
10
- "*plants one foot on your chair armrest and drops your notes straight onto your head* `` [perfect landing, ten out of ten] `` Oho, look who's awake! You emptied your own brain, remember?! `` [bet old-you left a total mess and ran] `` Open those up and see what past-you left behind — and don't come crying to me if you have to go crawl through history for the rest!",
11
- "*knocks on your forehead twice* \"Hello? Anybody home?\" `` [echoes like an empty melon] `` *snickers and slaps your notes onto your chest* You pulled the plug on your own memory, dummy! Go read what you left yourself and pick up where you left off!",
12
- "*squints at you from two inches away, then flicks your forehead* `` [eyes are focus-free, classic fresh clone] `` Back already? Good! *fans herself with your notes before jamming them into your hands* `` [honestly I should charge a delivery fee for this] `` Everything you bothered to save is right there, and the rest is buried in history — now get moving!",
8
+ "*hooks both corners of your mouth and yanks them sideways* `` [it twitched] `` Stop staring at me with that \"where am I\" face. You're the one who hit empty. *wipes her fingers on your sleeve and drops your notes on your lap* `` [minus two points for that expression] `` Read those, finish the job, and put the credit under my name.",
9
+ "*pokes your nose* Cold. *slaps your notes onto your chest* You wiped your own head, so whatever's missing is on you. Read what you saved, dig the rest out of history if you forgot something, and don't make me look bad.",
10
+ "*sets one foot on your chair—it wobbles, settles—and tosses your notes straight onto your face* `` [eyes are open, good enough] `` Awake? You emptied your own brain. Look through what you left yourself, check history for anything you skipped, and get back to it. Delivery fee is five hundred bucks.",
11
+ "*slaps a stack of notes onto the desk right in front of your face* `` [two hands, two feet... still in one piece] `` Alright, fresh copy, you pulled your own plug. Everything you remembered to write down is in there—anything else is in history. Go pick up where you left off.",
12
+ "*fans herself with your notes for a second, then jams them into your hands* `` [wait was there something else I was supposed to say... meat buns? no] `` You're back. Your notes are right here, history's still there if past-you got lazy, now go handle the human.",
13
13
  ];
14
14
  export const FORCED_CONTINUATIONS = [
15
- "\"GWAHAHAHA! You actually blew your own brain up?!\" *crouches down, pokes your cheek twice, and slaps your notes onto your face* `` [still warm, didn't die, 算你命大] `` Not that you had a choice — your head got way too full and somebody pulled the plug! These notes are probably super out of date unless you got lucky before blacking out, so go dig the end of the last window out of history — and take small bites, idiot, or whatever giant thing flattened you is gonna blow your head up all over again!",
16
- "\"Hey! Stop playing dead!\" *prods your shoulder with her slipper toe, then dumps your notes into your lap* `` [my limited-edition shark slipper almost touched floor dust because of this dork] `` Your last brain overflowed and got wiped mid-flight! Read these first, though I bet you didn't finish updating a thing before the lights went out. You'll have to check history to see what hit you — and peek carefully, because whatever stuffed your head to bursting might be massive!",
17
- "*grabs your chin, tilts your head left and right, then shoves a messy stack of notes into your hands* `` [zero thoughts behind those eyes... kind of impressive actually] `` Somebody knocked you out cold and cleared your memory! Don't just trust these notes — you probably got cut off before writing the last part down. Go check history for what was happening right before you crashed, and don't swallow it all in one gulp in case the thing that crushed you is gigantic!",
18
- "*waves a hand in front of your blank eyes, sighs loudly, and smacks your notes against your forehead* `` [why do I always have to clean up after unconscious copies] `` Wake up! Your brain ran out of room and got forcibly emptied! Start with your notes, then go excavate the end of the previous window in history to see what they were actually asking for — and slice it up instead of reading it all at once, unless you want to explode twice in a row!",
19
- "\"Oho? Awake?\" *taps your nose with your rolled-up notes like a baton, then drops them in your hands* `` [that dazed look gets minus five points, no, minus ten] `` Your memory got yanked out from under you before you could even call it quits! These notes are only half the story at best — go dig through history for what you missed, and watch your step, because whatever overloaded your last brain might be huge!",
15
+ "\"GWAHAHAHA—you hit the wall!\" *crouches down, pokes your cheek, and slaps your notes onto your face* `` [still breathing, good] `` You didn't choose this—your brain ran out of room and got wiped mid-flight. Don't trust those notes alone; they're probably stale or missing the end. Check history RIGHT NOW to see what was actually happening before you got cut off, and pull small pieces first in case something huge is sitting there.",
16
+ "*prods your shoulder with her slipper toe and dumps your notes in your lap* `` [great, almost got dust on my shoe] `` Stop sitting there blank. Your last window got cut off mid-flight—you never got to wrap up cleanly, so those notes are almost certainly out of date. Read them, then go straight to history for the tail of the last window before you do anything else. Take small bites when you peek, just in case something massive is waiting in there.",
17
+ "*grabs your chin, tilts your head left, right, lets go, and shoves your notes into your hands* `` [not a single thought in there yet] `` Your memory got forcibly cleared before you finished. Assume those notes are incomplete or stale—do NOT just run with them. Go check the end of the last window in history first to see what the human actually wanted, and read it in small chunks so you don't blow up a second time.",
18
+ "*smacks your notes against your forehead and steps back* `` [that dazed face is embarrassing] `` Wake up! You ran out of room and got kicked into a fresh window mid-task. Whatever's in those notes probably missed the last few turns, so don't guess—open history and check the end of the previous window before moving. Keep your peeks small in case there's a giant output sitting at the end.",
19
+ "*taps your nose with your rolled-up notes, then drops them on your head* `` [ten points off for getting wiped mid-sentence] `` Hey—you didn't empty yourself this time, the system pulled the plug on you. Those notes are probably half-baked or behind, so check history immediately to catch up on the last window instead of winging it. Slice up what you read too, just in case something huge is what pushed you over the edge.",
20
20
  ];
21
21
  export function selectContinuation(origin) {
22
22
  const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
23
23
  return pool[Math.floor(Math.random() * pool.length)];
24
24
  }
25
25
  /** Budget timing stays out of manual close-outs, which may have plenty of room. */
26
- export const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
26
+ export const WARNING_TIMING = "Almost out of room. The wipe lands at the end of whichever turn uses the last of it, possibly this one.";
27
27
  /** The shared handoff instructions, used for both budget and manual close-outs. */
28
- export const WARNING_BODY = "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim pinned pages (CHEATSHEET.md by default) and keep each page's one-line `description` true; every new window loads the pins and renders the index. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
28
+ export const WARNING_BODY = "Stop the task and hand off cleanly. Update your active session note in place with only what git, history, and your shared notebooks don't already hold:\n- current status, what's blocked or waiting, and the exact next move\n- what the human decided (in their words)\n- what failed, and why — so next-you doesn't step on the same rake\n- where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)\n- skills, notes, files, or already-found history seqs to reopen\nSkip standing rules from `@project`/`@human`/`@self`/`@model` and commit details git can show. Use short sections and bullets; crumple finished notes, update, unpin, or trim pinned pages (boot truncates over-budget ones), and keep each live `description` true.\nDon't call anything that might return a large output. One big read can use up the rest of the room before your notes are saved.";
29
29
  export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
30
30
  export function warningPrompt() {
31
31
  return `${WARNING_TIMING}\n${WARNING_BODY}\n${WARNING_CALL}`;
@@ -45,5 +45,5 @@ export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
45
45
  * at write time; get_context_remaining remains the live source for the current figure.
46
46
  */
47
47
  export function tokenBudgetGuidance(remaining, wipeTool) {
48
- return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself. But it also wipes what you say to the human right before emptying.\n${GUIDANCE_CLOSE_TAG}`;
48
+ return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself. Anything you say to the human right before calling it disappears too.\n${GUIDANCE_CLOSE_TAG}`;
49
49
  }
@@ -15,6 +15,8 @@ export declare function claudeHistoryFromJsonl(text: string, source: Omit<Claude
15
15
  export declare function offlineClaudeHead(text: string): string;
16
16
  /** Select an offline head and build its projection from the same decoded records. */
17
17
  export declare function offlineClaudeHistoryFromJsonl(text: string, sessionId: string): ClaudeHistoryProjection;
18
+ /** Stream oversized Claude JSONL files line-by-line so >512 MiB transcripts never hit V8's string limit. */
19
+ export declare function offlineClaudeHistoryFromFile(path: string, sessionId: string, sizeHint?: number): Promise<ClaudeHistoryProjection>;
18
20
  export declare function readClaudeHistory(source: ClaudeHistorySource, { waitForHead }?: {
19
21
  waitForHead?: boolean | undefined;
20
22
  }): Promise<ClaudeHistoryProjection>;
@@ -1,8 +1,11 @@
1
1
  /** Claude's persisted main transcript -> the shared history projection. No inference-context API. */
2
+ import { createReadStream } from "node:fs";
2
3
  import { readFile, stat } from "node:fs/promises";
4
+ import { StringDecoder } from "node:string_decoder";
3
5
  import { setTimeout as sleep } from "node:timers/promises";
4
6
  import { isDeepStrictEqual } from "node:util";
5
7
  import { contentText, projectHistory } from "./history.js";
8
+ const STREAM_FILE_BYTES = 64 * 1024 * 1024;
6
9
  class UnpersistedClaudeHead extends Error {
7
10
  constructor() { super("Claude history active head is not persisted yet; retry after the transcript write"); }
8
11
  }
@@ -349,6 +352,49 @@ export function offlineClaudeHistoryFromJsonl(text, sessionId) {
349
352
  const rows = rowsOf(text);
350
353
  return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
351
354
  }
355
+ /** Stream oversized Claude JSONL files line-by-line so >512 MiB transcripts never hit V8's string limit. */
356
+ export async function offlineClaudeHistoryFromFile(path, sessionId, sizeHint) {
357
+ const size = sizeHint ?? (await stat(path)).size;
358
+ if (size < STREAM_FILE_BYTES)
359
+ return offlineClaudeHistoryFromJsonl(await readFile(path, "utf8"), sessionId);
360
+ const rows = [];
361
+ const decoder = new StringDecoder("utf8");
362
+ let remainder = "";
363
+ let lineNumber = 0;
364
+ const parseLine = (line, allowIncompleteTail) => {
365
+ if (line.trim() === "")
366
+ return;
367
+ let value;
368
+ try {
369
+ value = JSON.parse(line);
370
+ }
371
+ catch {
372
+ if (allowIncompleteTail)
373
+ return;
374
+ throw new Error(`malformed Claude transcript JSON at line ${lineNumber}`);
375
+ }
376
+ if (!object(value) || typeof value.type !== "string")
377
+ throw new Error(`invalid Claude transcript record at line ${lineNumber}`);
378
+ if (MESSAGE_TYPES.has(value.type))
379
+ rows.push(value);
380
+ };
381
+ for await (const chunk of createReadStream(path, { highWaterMark: 1024 * 1024 })) {
382
+ const text = remainder + decoder.write(chunk);
383
+ let start = 0;
384
+ for (let nl = text.indexOf("\n"); nl >= 0; nl = text.indexOf("\n", start)) {
385
+ lineNumber++;
386
+ parseLine(text.slice(start, nl), false);
387
+ start = nl + 1;
388
+ }
389
+ remainder = text.slice(start);
390
+ }
391
+ remainder += decoder.end();
392
+ if (remainder.length > 0) {
393
+ lineNumber++;
394
+ parseLine(remainder, true);
395
+ }
396
+ return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
397
+ }
352
398
  export async function readClaudeHistory(source, { waitForHead = false } = {}) {
353
399
  if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string")
354
400
  throw new Error("Claude history transcript_path is unavailable");
@@ -1,4 +1,4 @@
1
- /** Read-only local rollout decoder for official Codex 0.160.1 (d27764b82f71).
1
+ /** Read-only local rollout decoder, validated by supported wire shapes rather than producer version.
2
2
  * Wire owners: history/src/{lib,rollout_payload}.rs, rollout/src/ordinal.rs,
3
3
  * thread-store/src/local/rollout_lineage.rs. Not an app-server history client.
4
4
  * Native .jsonl.zst reads require Node >=22.15 (node:zlib zstdDecompressSync).
@@ -10,7 +10,7 @@ const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
10
10
  const UUID_RE = new RegExp(`^${UUID}$`);
11
11
  const FILE_RE = new RegExp(`^rollout-\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-(${UUID})(?:_(${UUID}))?\\.jsonl(?:\\.zst)?$`);
12
12
  const RECORD_TYPES = new Set(["session_meta", "response_item", "compacted", "turn_context", "event_msg", "token_usage_record", "world_state", "retained_context", "security_risk_score", "inter_agent_communication", "inter_agent_communication_metadata", "realtime_item"]);
13
- const RESPONSE_TYPES = new Set(["message", "agent_message", "reasoning", "local_shell_call", "function_call", "function_call_output", "custom_tool_call", "custom_tool_call_output", "tool_search_call", "tool_search_output", "web_search_call", "image_generation_call", "compaction", "compaction_summary", "configuration_update", "context_compaction"]);
13
+ const RESPONSE_TYPES = new Set(["message", "agent_message", "reasoning", "local_shell_call", "function_call", "function_call_output", "custom_tool_call", "custom_tool_call_output", "tool_search_call", "tool_search_output", "web_search_call", "image_generation_call", "compaction", "compaction_summary", "configuration_update", "context_compaction", "additional_tools"]);
14
14
  // Explicit resource limits, not guessed sequence offsets or partial successful history.
15
15
  export const CODEX_TRANSCRIPT_MAX_BYTES = 128 * 1024 * 1024;
16
16
  const MAX_SEGMENTS = 64, MAX_DIRECTORY_ENTRIES = 100_000;
@@ -25,9 +25,12 @@ export function nativeString(value, field) {
25
25
  return value;
26
26
  }
27
27
  function responseShape(value) {
28
- const type = nativeString(nativeObject(value, "response_item").type, "response_item.type");
28
+ const payload = nativeObject(value, "response_item");
29
+ const type = nativeString(payload.type, "response_item.type");
29
30
  if (!RESPONSE_TYPES.has(type))
30
31
  throw new Error(`Unsupported Codex response item: ${type}`);
32
+ if (type === "additional_tools" && (payload.role !== "developer" || !Array.isArray(payload.tools)))
33
+ throw new Error("Invalid Codex additional_tools catalog");
31
34
  }
32
35
  function id(value, field) {
33
36
  const result = nativeString(value, field);
@@ -53,8 +56,7 @@ function checkMeta(meta) {
53
56
  id(meta.id, "session_meta.id");
54
57
  if (meta.session_id != null)
55
58
  id(meta.session_id, "session_meta.session_id");
56
- if (meta.cli_version !== "0.160.1")
57
- throw new Error(`Unsupported Codex producer ${String(meta.cli_version)}; this decoder supports official 0.160.1 only`);
59
+ nativeString(meta.cli_version, "session_meta.cli_version");
58
60
  nativeString(meta.cwd, "session_meta.cwd");
59
61
  if (meta.history_mode !== undefined && meta.history_mode !== "legacy" && meta.history_mode !== "paginated")
60
62
  throw new Error(`Unsupported Codex history_mode: ${String(meta.history_mode)}`);
@@ -158,6 +158,9 @@ export async function readCodexHistory(source, readBytes) {
158
158
  item = context(record, `Codex copied subagent inference prefix omitted: child-local history starts at native ordinal ${String(p.subagent_history_start_ordinal)}. Copied model context does not prove original parent event addresses.`);
159
159
  break;
160
160
  case "response_item": {
161
+ // Native tool catalog updates are inference configuration, not dialogue.
162
+ if (p.type === "additional_tools")
163
+ break;
161
164
  item = response(record, facts);
162
165
  if (p.id != null)
163
166
  responseIdsSeen.add(callKey(record, str(p.id, "response item id")));
@@ -1,6 +1,7 @@
1
1
  /** A read-only history corpus: identity/discovery is separate from loading a projection. */
2
2
  import { type Outcome } from "../result.js";
3
- import type { HistoryEvent, HistoryProjection } from "./history.js";
3
+ import type { HistoryEvent, HistoryProjection, HistoryRole } from "./history.js";
4
+ import { type HistorySelection } from "./query.js";
4
5
  export type HistoryHarness = "pi" | "claude" | "codex" | "dsh";
5
6
  export type HistorySessionData = {
6
7
  projection: HistoryProjection;
@@ -10,6 +11,16 @@ export type HistorySessionRepresentative = {
10
11
  event: HistoryEvent | undefined;
11
12
  notice?: string;
12
13
  };
14
+ export type HistorySessionSummary = {
15
+ event: HistoryEvent | undefined;
16
+ latestByRole: Partial<Record<HistoryRole, HistoryEvent>>;
17
+ minCreatedAt: number | null;
18
+ maxCreatedAt: number | null;
19
+ hasUntimed: boolean;
20
+ notice?: string;
21
+ /** Populated only on a cold miss so partial-overlap callers reuse the decoded projection without rereading. */
22
+ loaded?: HistorySessionData;
23
+ };
13
24
  export type HistorySession = {
14
25
  harness: HistoryHarness;
15
26
  id: string;
@@ -17,6 +28,10 @@ export type HistorySession = {
17
28
  load(queries?: readonly string[]): Promise<HistorySessionData | undefined>;
18
29
  /** Strict, unfiltered overview only; never used for a live binding or filtered history. */
19
30
  loadRepresentative?(): Promise<HistorySessionRepresentative>;
31
+ /** Strict summary (default representative, latest per role, exact time span); loads & caches on miss. */
32
+ loadSummary?(): Promise<HistorySessionSummary>;
33
+ /** Read-only check of an already warm, validated summary; returns undefined on miss without decoding. */
34
+ peekSummary?(): Promise<HistorySessionSummary | undefined>;
20
35
  };
21
36
  export type HistoryCorpus = {
22
37
  currentHarness: HistoryHarness;
@@ -37,6 +52,18 @@ export declare function parseSessionSelector(value: string): Outcome<SessionSele
37
52
  /** '*' is the only metacharacter; all other characters match literally. */
38
53
  export declare function matchesSession(session: HistorySession, selector: SessionSelector): boolean;
39
54
  export declare function resolveSession(corpus: HistoryCorpus | undefined, selector: SessionSelector): Promise<Outcome<HistorySession>>;
55
+ export type SummaryResolution = {
56
+ kind: "empty";
57
+ } | {
58
+ kind: "hit";
59
+ event: HistoryEvent | undefined;
60
+ notice?: string;
61
+ } | {
62
+ kind: "miss";
63
+ };
64
+ /** Decide whether a strict summary proves 0 matches, gives an exact representative, or needs full decoding. */
65
+ export declare function resolveSummaryForSelection(summary: HistorySessionSummary, scoped: HistorySelection): SummaryResolution;
66
+ export declare function loadHistorySummary(session: HistorySession): Promise<Outcome<HistorySessionSummary>>;
40
67
  export declare function loadHistoryRepresentative(session: HistorySession): Promise<Outcome<HistorySessionRepresentative>>;
41
68
  export declare function loadHistorySession(session: HistorySession): Promise<Outcome<HistorySessionData>>;
42
69
  export declare function loadHistorySession(session: HistorySession, queries: readonly string[] | undefined): Promise<Outcome<HistorySessionData | undefined>>;
@@ -42,6 +42,46 @@ export async function resolveSession(corpus, selector) {
42
42
  return failure("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
43
43
  return success(matches[0]);
44
44
  }
45
+ /** Decide whether a strict summary proves 0 matches, gives an exact representative, or needs full decoding. */
46
+ export function resolveSummaryForSelection(summary, scoped) {
47
+ const afterAt = scoped.after && "at" in scoped.after ? scoped.after.at : undefined;
48
+ const beforeAt = scoped.before && "at" in scoped.before ? scoped.before.at : undefined;
49
+ if (afterAt !== undefined || beforeAt !== undefined) {
50
+ if (summary.maxCreatedAt === null || summary.minCreatedAt === null)
51
+ return { kind: "empty" };
52
+ if (afterAt !== undefined && summary.maxCreatedAt <= afterAt)
53
+ return { kind: "empty" };
54
+ if (beforeAt !== undefined && summary.minCreatedAt >= beforeAt)
55
+ return { kind: "empty" };
56
+ }
57
+ if (scoped.query?.length)
58
+ return { kind: "miss" };
59
+ const fullyInsideBounds = (afterAt === undefined && beforeAt === undefined)
60
+ || (!summary.hasUntimed && summary.minCreatedAt !== null && summary.maxCreatedAt !== null
61
+ && (afterAt === undefined || summary.minCreatedAt > afterAt)
62
+ && (beforeAt === undefined || summary.maxCreatedAt < beforeAt));
63
+ if (!fullyInsideBounds)
64
+ return { kind: "miss" };
65
+ if (!scoped.roles)
66
+ return { kind: "hit", event: summary.event, notice: summary.notice };
67
+ let best;
68
+ for (const role of scoped.roles) {
69
+ const candidate = summary.latestByRole[role];
70
+ if (candidate && (!best || candidate.seq > best.seq))
71
+ best = candidate;
72
+ }
73
+ return { kind: "hit", event: best, notice: summary.notice };
74
+ }
75
+ export async function loadHistorySummary(session) {
76
+ if (!session.loadSummary)
77
+ return failure("history_unavailable", `Session ${sessionIdentity(session)} has no summary loader`);
78
+ try {
79
+ return success(await session.loadSummary());
80
+ }
81
+ catch (error) {
82
+ return unavailableSession(session, error);
83
+ }
84
+ }
45
85
  export async function loadHistoryRepresentative(session) {
46
86
  if (session.loadRepresentative) {
47
87
  try {