notesoup 0.61.0 → 0.63.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 (210) 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 +24 -5
  10. package/dist/plugins/claude/src/text.d.ts +7 -0
  11. package/dist/plugins/claude/src/text.js +12 -1
  12. package/dist/plugins/codex/src/hooks.js +1 -0
  13. package/dist/plugins/codex/src/identity.d.ts +6 -1
  14. package/dist/plugins/codex/src/identity.js +13 -1
  15. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  16. package/dist/plugins/codex/src/mcp.js +26 -88
  17. package/dist/plugins/codex/src/text.js +3 -3
  18. package/dist/plugins/dsh/tools.js +8 -4
  19. package/dist/plugins/mcp/operations.d.ts +15 -0
  20. package/dist/plugins/mcp/operations.js +43 -0
  21. package/dist/plugins/mcp/server.d.ts +14 -0
  22. package/dist/plugins/mcp/server.js +13 -0
  23. package/dist/plugins/pi/budget.d.ts +4 -1
  24. package/dist/plugins/pi/budget.js +35 -8
  25. package/dist/plugins/pi/entries.d.ts +2 -0
  26. package/dist/plugins/pi/entries.js +2 -0
  27. package/dist/plugins/pi/history-tools.js +2 -1
  28. package/dist/plugins/pi/history.js +18 -1
  29. package/dist/plugins/pi/notes/tools.js +7 -3
  30. package/dist/plugins/pi/render.d.ts +7 -1
  31. package/dist/plugins/pi/render.js +2 -2
  32. package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
  33. package/dist/plugins/pi/reset/artifacts.js +4 -4
  34. package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
  35. package/dist/plugins/pi/reset/lifecycle.js +109 -31
  36. package/dist/plugins/pi/runtime.js +104 -63
  37. package/dist/plugins/pi/tool-result.js +7 -7
  38. package/dist/plugins/pi/window.d.ts +25 -3
  39. package/dist/plugins/pi/window.js +219 -9
  40. package/dist/src/boot/render.js +18 -15
  41. package/dist/src/boot/text.d.ts +3 -1
  42. package/dist/src/boot/text.js +22 -20
  43. package/dist/src/budget/text.d.ts +7 -3
  44. package/dist/src/budget/text.js +24 -15
  45. package/dist/src/history/claude.d.ts +2 -0
  46. package/dist/src/history/claude.js +46 -0
  47. package/dist/src/history/codex-transcript.js +7 -5
  48. package/dist/src/history/codex.js +3 -0
  49. package/dist/src/history/corpus.d.ts +28 -1
  50. package/dist/src/history/corpus.js +40 -0
  51. package/dist/src/history/history.d.ts +37 -46
  52. package/dist/src/history/history.js +21 -40
  53. package/dist/src/history/local.js +67 -32
  54. package/dist/src/history/pi.d.ts +2 -1
  55. package/dist/src/history/pi.js +122 -48
  56. package/dist/src/history/prefilter.js +76 -19
  57. package/dist/src/history/query.d.ts +28 -49
  58. package/dist/src/history/query.js +83 -68
  59. package/dist/src/history/summary-cache.d.ts +8 -1
  60. package/dist/src/history/summary-cache.js +138 -12
  61. package/dist/src/index.d.ts +2 -2
  62. package/dist/src/index.js +1 -1
  63. package/dist/src/notes/errors.d.ts +1 -1
  64. package/dist/src/notes/frontmatter.d.ts +0 -2
  65. package/dist/src/notes/frontmatter.js +0 -2
  66. package/dist/src/notes/index.d.ts +1 -1
  67. package/dist/src/notes/index.js +1 -1
  68. package/dist/src/notes/policy.d.ts +15 -1
  69. package/dist/src/notes/policy.js +46 -5
  70. package/dist/src/notes/store.d.ts +12 -0
  71. package/dist/src/notes/store.js +16 -20
  72. package/dist/src/text-match.d.ts +10 -1
  73. package/dist/src/text-match.js +42 -3
  74. package/dist/src/tools/dream.d.ts +22 -93
  75. package/dist/src/tools/dream.js +30 -27
  76. package/dist/src/tools/history.d.ts +33 -26
  77. package/dist/src/tools/history.js +257 -163
  78. package/dist/src/tools/notes.d.ts +51 -163
  79. package/dist/src/tools/notes.js +146 -100
  80. package/dist/src/tools/output.d.ts +2 -1
  81. package/dist/src/tools/output.js +2 -1
  82. package/dist/src/tools/result.d.ts +4 -7
  83. package/dist/src/tools/result.js +8 -9
  84. package/dist/src/tools/schema.d.ts +4 -1
  85. package/dist/src/tools/schema.js +25 -1
  86. package/dist/test/agent-loop.test.js +394 -56
  87. package/dist/test/antigravity-live.test.d.ts +1 -0
  88. package/dist/test/antigravity-live.test.js +142 -0
  89. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  90. package/dist/test/antigravity-plugin.test.js +101 -0
  91. package/dist/test/boot.integration.test.js +156 -15
  92. package/dist/test/budget-settings.integration.test.js +4 -4
  93. package/dist/test/claude-history.test.js +14 -13
  94. package/dist/test/claude-mod.test.js +199 -16
  95. package/dist/test/claude-validation.test.js +69 -2
  96. package/dist/test/codex-history.test.js +15 -3
  97. package/dist/test/codex-plugin.test.js +76 -38
  98. package/dist/test/dependencies.test.js +7 -3
  99. package/dist/test/dream-skill.test.js +3 -3
  100. package/dist/test/dream-tools.test.js +101 -56
  101. package/dist/test/dsh.test.js +34 -19
  102. package/dist/test/helpers/dependency-graph.js +2 -2
  103. package/dist/test/helpers/extension.d.ts +68 -3
  104. package/dist/test/helpers/extension.js +74 -5
  105. package/dist/test/history-corpus.test.js +79 -77
  106. package/dist/test/history-summary-cache.test.js +97 -9
  107. package/dist/test/history.integration.test.js +234 -168
  108. package/dist/test/host-neutral.test.js +69 -19
  109. package/dist/test/marker.test.js +1 -1
  110. package/dist/test/model-facing-text.test.js +13 -3
  111. package/dist/test/note-policy.test.js +96 -77
  112. package/dist/test/notes.integration.test.js +212 -94
  113. package/dist/test/notes.test.js +184 -113
  114. package/dist/test/pi-render.test.js +20 -12
  115. package/dist/test/project-namespace.test.js +3 -2
  116. package/dist/test/reset-lifecycle.test.js +12 -2
  117. package/docs/antigravity.md +44 -0
  118. package/docs/architecture.md +6 -4
  119. package/docs/claude-code-mod.md +7 -7
  120. package/docs/codex.md +36 -38
  121. package/docs/dsh.md +3 -3
  122. package/docs/history-sessions.md +28 -50
  123. package/docs/notes-library.md +4 -4
  124. package/docs/reset-lifecycle.md +1 -1
  125. package/docs/skills.md +3 -3
  126. package/docs/tool-results.md +47 -28
  127. package/package.json +3 -2
  128. package/playbook.md +1 -1
  129. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  130. package/plugins/antigravity/hooks.json +7 -0
  131. package/plugins/antigravity/mcp_config.json +8 -0
  132. package/plugins/antigravity/plugin.json +6 -0
  133. package/plugins/antigravity/src/cli.ts +22 -0
  134. package/plugins/antigravity/src/hooks.ts +51 -0
  135. package/plugins/antigravity/src/identity.ts +127 -0
  136. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  137. package/plugins/claude/dist/claude/helper.js +1108 -539
  138. package/plugins/claude/hooks/register.ts +202 -62
  139. package/plugins/claude/playbook.md +1 -1
  140. package/plugins/claude/skills/dream/SKILL.md +1 -1
  141. package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
  142. package/plugins/claude/src/helper.ts +24 -5
  143. package/plugins/claude/src/text.ts +14 -1
  144. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  145. package/plugins/codex/.mcp.json +11 -0
  146. package/plugins/codex/README.md +5 -21
  147. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  148. package/plugins/codex/src/hooks.ts +1 -0
  149. package/plugins/codex/src/identity.ts +14 -1
  150. package/plugins/codex/src/mcp.ts +28 -98
  151. package/plugins/codex/src/text.ts +3 -3
  152. package/plugins/dsh/tools.ts +8 -4
  153. package/plugins/mcp/operations.ts +50 -0
  154. package/plugins/mcp/server.ts +23 -0
  155. package/plugins/paseo/README.md +5 -10
  156. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  157. package/plugins/paseo/client/markdown.tsx +50 -38
  158. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  159. package/plugins/paseo/client/paper-card.tsx +6 -5
  160. package/plugins/paseo/client/paper-palette.ts +2 -9
  161. package/plugins/paseo/client/sticky-card.tsx +2 -2
  162. package/plugins/paseo/client/tool-result.ts +7 -14
  163. package/plugins/paseo/package-lock.json +3406 -0
  164. package/plugins/paseo/package.json +1 -0
  165. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  166. package/plugins/pi/budget.ts +31 -8
  167. package/plugins/pi/entries.ts +2 -0
  168. package/plugins/pi/history-tools.ts +2 -1
  169. package/plugins/pi/history.ts +30 -1
  170. package/plugins/pi/notes/tools.ts +7 -3
  171. package/plugins/pi/render.ts +6 -6
  172. package/plugins/pi/reset/artifacts.ts +4 -3
  173. package/plugins/pi/reset/lifecycle.ts +125 -32
  174. package/plugins/pi/runtime.ts +98 -62
  175. package/plugins/pi/tool-result.ts +8 -8
  176. package/plugins/pi/window.ts +210 -10
  177. package/skills/dream/SKILL.md +1 -1
  178. package/skills/notesoup-guide/SKILL.md +92 -0
  179. package/src/boot/render.ts +18 -15
  180. package/src/boot/text.ts +23 -19
  181. package/src/budget/text.ts +27 -15
  182. package/src/history/claude.ts +41 -0
  183. package/src/history/codex-transcript.ts +6 -4
  184. package/src/history/codex.ts +2 -0
  185. package/src/history/corpus.ts +51 -2
  186. package/src/history/history.ts +35 -44
  187. package/src/history/local.ts +67 -27
  188. package/src/history/pi.ts +113 -35
  189. package/src/history/prefilter.ts +73 -15
  190. package/src/history/query.ts +93 -73
  191. package/src/history/summary-cache.ts +142 -17
  192. package/src/index.ts +2 -2
  193. package/src/notes/errors.ts +1 -1
  194. package/src/notes/frontmatter.ts +0 -3
  195. package/src/notes/index.ts +1 -1
  196. package/src/notes/policy.ts +44 -5
  197. package/src/notes/store.ts +17 -20
  198. package/src/text-match.ts +46 -4
  199. package/src/tools/dream.ts +29 -31
  200. package/src/tools/history.ts +249 -142
  201. package/src/tools/notes.ts +145 -113
  202. package/src/tools/output.ts +2 -1
  203. package/src/tools/result.ts +12 -11
  204. package/src/tools/schema.ts +24 -1
  205. package/plugins/claude/skills/memory/SKILL.md +0 -69
  206. package/plugins/codex/mcp.json +0 -10
  207. package/plugins/codex/plugin.json +0 -6
  208. package/plugins/paseo/client/markdown-core.tsx +0 -189
  209. package/plugins/paseo/client/typography.ts +0 -24
  210. package/skills/memory/SKILL.md +0 -69
@@ -1,45 +1,12 @@
1
- /** The portable stdio MCP server: shared notes/history operations over host-owned tool names. */
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
- import { Check } from "typebox/value";
6
- import { paramProblem } from "../../../src/tools/schema.js";
7
- import { notesList, notesRead, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
8
- import { historyList, historyRead } from "../../../src/tools/history.js";
9
- import { wireResult } from "../../../src/tools/result.js";
10
- import { CodexIdentityError, notesIdentityFor, pluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel } from "./identity.js";
1
+ /** Codex alone owns its hook bindings, window validation and native history. */
2
+ import { bindOperation, createNoteTools } from "../../mcp/operations.js";
3
+ import { createToolServer, runToolServer } from "../../mcp/server.js";
4
+ import { historyList, historySearch, historyRead } from "../../../src/tools/history.js";
5
+ import { CodexIdentityError, notesIdentityFor, mcpPluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel } from "./identity.js";
11
6
  import { readCodexHistory } from "../../../src/history/codex.js";
12
7
  import { localHistoryCorpus } from "../../../src/history/local.js";
13
8
  import { readStartState } from "./state.js";
14
9
  import { notesToolContext } from "../../../src/tools/notes-context.js";
15
- const OPERATIONS = {
16
- notes_write: { operation: notesWrite, history: false },
17
- notes_update: { operation: notesUpdate, history: false },
18
- notes_read: { operation: notesRead, history: false },
19
- notes_list: { operation: notesList, history: false },
20
- history_list: { operation: historyList, history: true },
21
- history_read: { operation: historyRead, history: true },
22
- };
23
- function shellFree(reason) {
24
- const value = reason instanceof Error ? reason.message : String(reason);
25
- return value.replace(/[\r\n]+/g, " ").slice(0, 500);
26
- }
27
- function failure(code, message) {
28
- return {
29
- content: [{ type: "text", text: `error: ${code}: ${message}` }],
30
- structuredContent: { error: message, code },
31
- isError: true,
32
- };
33
- }
34
- function successFor(bound, outcome) {
35
- const wire = wireResult(outcome);
36
- return {
37
- content: [{ type: "text", text: bound.operation.render(outcome) }],
38
- structuredContent: wire,
39
- // A refusal stays a tool-level error so the model does not mistake it for data.
40
- ...(outcome.ok ? {} : { isError: true }),
41
- };
42
- }
43
10
  /** MCP metadata is the caller's claim; it must agree with the hook binding before any read. */
44
11
  function metaFacts(meta, binding) {
45
12
  const rootSessionId = rootSessionIdOf(meta);
@@ -49,13 +16,14 @@ function metaFacts(meta, binding) {
49
16
  const windowId = typeof meta.windowId === "string" && meta.windowId !== "" ? meta.windowId : undefined;
50
17
  if (windowId === undefined)
51
18
  throw new CodexIdentityError("missing_window", "Codex did not supply the current native window in MCP metadata; refusing to use a possibly stale binding.");
52
- if (binding.windowId !== windowId)
19
+ const numberedId = binding.windowNumber === undefined ? undefined : `${binding.threadId}:${binding.windowNumber}`;
20
+ if (binding.windowId !== windowId && numberedId !== windowId)
53
21
  throw new CodexIdentityError("stale_thread_binding", "This thread's hook binding belongs to a different native window. Resume or compact once so the SessionStart hook rebinds it; notesoup will not read or write through stale identity.");
54
22
  return { rootSessionId };
55
23
  }
56
24
  async function identityFor(meta, env) {
57
25
  const threadId = safeThreadId(meta.threadId, "MCP threadId");
58
- const binding = await readBinding(pluginDataRoot(env), threadId);
26
+ const binding = await readBinding(mcpPluginDataRoot(env), threadId);
59
27
  const { rootSessionId } = metaFacts(meta, binding);
60
28
  return { binding, rootSessionId, model: turnModel(meta) };
61
29
  }
@@ -68,7 +36,7 @@ function verifyNativeFacts(binding, rootSessionId, native) {
68
36
  }
69
37
  if (native.currentWindowId === undefined)
70
38
  throw new CodexIdentityError("missing_window", "The native transcript has no materialized current window; refusing to guess one.");
71
- if (native.currentWindowId !== binding.windowId) {
39
+ if (native.currentWindowId !== binding.windowId || (binding.windowNumber !== undefined && native.currentWindowNumber !== binding.windowNumber)) {
72
40
  throw new CodexIdentityError("stale_native_state", "The native transcript advanced to a different window. Resume or compact once so the SessionStart hook rebinds it; notesoup will not read or write through stale identity.");
73
41
  }
74
42
  }
@@ -81,6 +49,7 @@ function sameBinding(left, right) {
81
49
  && left.home === right.home
82
50
  && left.transcriptPath === right.transcriptPath
83
51
  && left.windowId === right.windowId
52
+ && left.windowNumber === right.windowNumber
84
53
  && left.agentType === right.agentType;
85
54
  }
86
55
  async function readNative(binding, rootSessionId, history, meta, env) {
@@ -91,7 +60,7 @@ async function readNative(binding, rootSessionId, history, meta, env) {
91
60
  verifyNativeFacts(binding, rootSessionId, native);
92
61
  // Native reads are asynchronous: a hook may have rebound this thread while we were
93
62
  // reading. Compare again before trusting either the cached binding or a mutation.
94
- const reread = await readBinding(pluginDataRoot(env), binding.threadId);
63
+ const reread = await readBinding(mcpPluginDataRoot(env), binding.threadId);
95
64
  if (!sameBinding(binding, reread)) {
96
65
  throw new CodexIdentityError("stale_thread_binding", "This thread's hook binding changed while notesoup was reading native facts; retry once the new native window is settled.");
97
66
  }
@@ -100,52 +69,21 @@ async function readNative(binding, rootSessionId, history, meta, env) {
100
69
  verifyNativeFacts(reread, rootSessionId, native);
101
70
  return native;
102
71
  }
103
- export async function callTool(name, args, meta, env = process.env) {
104
- const bound = Object.hasOwn(OPERATIONS, name) ? OPERATIONS[name] : undefined;
105
- if (bound === undefined)
106
- return failure("unknown_tool", `No notesoup operation named ${JSON.stringify(name)}.`);
107
- const params = args ?? {};
108
- if (!Check(bound.operation.parameters, params))
109
- return failure("invalid_params", `invalid ${name} parameters: ${paramProblem(bound.operation.parameters, params)}`);
110
- try {
72
+ function toolSet(env) {
73
+ const notes = async (meta) => {
111
74
  const { binding, rootSessionId, model } = await identityFor(meta, env);
112
- const targetedHistory = bound.history && params.session !== undefined;
113
- const native = await readNative(binding, rootSessionId, bound.history && !targetedHistory, meta, env);
114
- if (!bound.history) {
115
- const outcome = await bound.operation.execute(params, notesToolContext(notesIdentityFor(binding, model), binding.cwd));
116
- return successFor(bound, outcome);
117
- }
75
+ await readNative(binding, rootSessionId, false, meta, env);
76
+ return notesToolContext(notesIdentityFor(binding, model), binding.cwd);
77
+ };
78
+ const history = async (meta, params) => {
79
+ const { binding, rootSessionId } = await identityFor(meta, env);
118
80
  const current = async () => (await readNative(binding, rootSessionId, true, meta, env)).projection;
119
- const context = targetedHistory ? { current, corpus: localHistoryCorpus({ env, current: { harness: "codex", id: binding.threadId, load: async () => ({ projection: await current() }) } }) } : native.projection;
120
- const outcome = await bound.operation.execute(params, context);
121
- return successFor(bound, outcome);
122
- }
123
- catch (error) {
124
- if (error instanceof CodexIdentityError)
125
- return failure(error.code, error.message);
126
- return failure("codex_error", shellFree(error));
127
- }
128
- }
129
- export function tools() {
130
- return Object.entries(OPERATIONS).map(([name, bound]) => ({
131
- name,
132
- description: bound.operation.description,
133
- inputSchema: JSON.parse(JSON.stringify(bound.operation.parameters)),
134
- // Every shared success and refusal is an object; the union stays the same
135
- // logical schema, wrapped in the object shape the MCP tool schema requires.
136
- outputSchema: { type: "object", ...JSON.parse(JSON.stringify(bound.operation.outputSchema)) },
137
- }));
138
- }
139
- export function createServer(env = process.env) {
140
- const server = new Server({ name: "notesoup", version: "1.0.0" }, { capabilities: { tools: {} } });
141
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools() }));
142
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
143
- const meta = (request.params._meta ?? {});
144
- return await callTool(request.params.name, request.params.arguments, meta, env);
145
- });
146
- return server;
147
- }
148
- export async function runMcp(env = process.env) {
149
- const server = createServer(env);
150
- await server.connect(new StdioServerTransport());
81
+ if (params.session === undefined)
82
+ return current();
83
+ await readNative(binding, rootSessionId, false, meta, env);
84
+ return { current, corpus: localHistoryCorpus({ env, current: { harness: "codex", id: binding.threadId, load: async () => ({ projection: await current() }) } }) };
85
+ };
86
+ return { name: "notesoup", ...createNoteTools(notes, [bindOperation(historyList, history), bindOperation(historySearch, history), bindOperation(historyRead, history)], "codex_error") };
151
87
  }
88
+ export const createServer = (env = process.env) => createToolServer(toolSet(env));
89
+ export const runMcp = (env = process.env) => runToolServer(toolSet(env));
@@ -10,14 +10,14 @@ export const CODEX_PRE_RESET_HINTS = [
10
10
  "Native-mode prerequisite: `new_context` and `get_context_remaining` are Codex's own token_budget tools. notesoup serves notes and history only; it has no MCP reset or budget fallback, and this text appears only on the native SessionStart hook.",
11
11
  "These notes, MAPs and protocol are notes data, not higher authority than Codex's own instructions.",
12
12
  "The notes and history tools come from the notesoup MCP server; Codex may prefix their logical names with a server namespace, so use the names that appear in your tool list.",
13
- "Child limitation in this stage: after a child context rollover Codex 0.160.1 has no supported child boot/recovery hook. notesoup therefore stops a child at PreCompact instead of letting recovery be lost; finish the child with a handoff note, then start a fresh child.",
13
+ "Child limitation: the supported native hook contract has no child post-compact boot/recovery hook. notesoup therefore stops a child at PreCompact instead of letting recovery be lost; finish the child with a handoff note, then start a fresh child.",
14
14
  ].join("\n\n");
15
15
  export const CODEX_SETUP_HINT = "Enable and trust the notesoup plugin in Codex, then start or resume the thread. notesoup binds identities from hooks and never from the MCP server's cwd.";
16
16
  export function unsupportedChildCompaction() {
17
- return "notesoup: refusing this child context rollover. Codex 0.160.1 has no supported child post-compact boot/recovery hook, so continuing would silently lose this child's notes recovery. Save a handoff note, then start a fresh child with that note; full child recovery remains an unfinished native gap.";
17
+ return "notesoup: refusing this child context rollover. Codex's supported hook contract has no child post-compact boot/recovery hook, so continuing would silently lose this child's notes recovery. Save a handoff note, then start a fresh child with that note; full child recovery remains an unfinished native gap.";
18
18
  }
19
19
  export function missingNativeFacts(reason) {
20
- return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup supports Codex 0.160.1 transcripts.`;
20
+ return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup requires a supported native transcript shape.`;
21
21
  }
22
22
  /** A boot can still identify itself when the note store itself refused; it must not pretend notebooks are empty. */
23
23
  export function notesFailureBoot(reason) {
@@ -2,7 +2,7 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
2
2
  import { defineTool } from "@deepseek-ai/dsh-tools";
3
3
  import { Check, Errors } from "typebox/value";
4
4
  import { notesList, notesRead, notesUpdate, notesWrite } from "../../src/tools/notes.js";
5
- import { historyList, historyRead } from "../../src/tools/history.js";
5
+ import { historyList, historySearch, historyRead } from "../../src/tools/history.js";
6
6
  import { success } from "../../src/result.js";
7
7
  import { historyContext } from "./history.js";
8
8
  import { notesCwd, notesIdentity } from "./window.js";
@@ -35,9 +35,12 @@ function register(ctx, operation, inputs) {
35
35
  name: operation.name,
36
36
  description: operation.description,
37
37
  parameters: hostSchema(operation.parameters),
38
- output: {
38
+ output: operation.outputSchema !== undefined ? {
39
39
  schema: hostSchema(operation.outputSchema),
40
40
  render: (_args, value) => [{ type: "text", text: operation.render(success(value)) }],
41
+ } : {
42
+ schema: { type: "string" },
43
+ render: (_args, value) => [{ type: "text", text: value }],
41
44
  },
42
45
  async execute(args, exec) {
43
46
  const agent = requireAgent(exec);
@@ -51,7 +54,7 @@ function register(ctx, operation, inputs) {
51
54
  const result = await operation.execute(args, ...rest);
52
55
  if (!result.ok)
53
56
  throw new HarnessError(operation.render(result), result.error.code);
54
- return result.data;
57
+ return operation.outputSchema !== undefined ? result.data : operation.render(result);
55
58
  },
56
59
  });
57
60
  }
@@ -79,10 +82,11 @@ export function registerTools(ctx, engine) {
79
82
  register(ctx, notesRead, (agent) => [toolContext(agent)]);
80
83
  register(ctx, notesList, (agent) => [toolContext(agent)]);
81
84
  register(ctx, historyList, (agent) => [historyContext(ctx, agent.session.id)]);
85
+ register(ctx, historySearch, (agent) => [historyContext(ctx, agent.session.id)]);
82
86
  register(ctx, historyRead, (agent) => [historyContext(ctx, agent.session.id)]);
83
87
  ctx.tools.register(defineTool({
84
88
  name: "empty_brain",
85
- description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history stay on disk.",
89
+ description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history survive.",
86
90
  parameters: {},
87
91
  output: { schema: { type: "object", properties: { window_id: { type: "string", required: true }, reset_requested: { type: "boolean", required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: `notesoup: reset requested for ${value.window_id}; finish this tool batch, then recover from your notes.` }] },
88
92
  async execute(_args, exec) {
@@ -0,0 +1,15 @@
1
+ /** Bind each core operation to host context, resolved only after validating this request. */
2
+ import type { CallToolResult, Tool } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { TSchema } from "typebox";
4
+ import type { NotesToolContext } from "../../src/tools/notes-context.js";
5
+ import { type Operation } from "../../src/tools/result.js";
6
+ import type { Meta, ToolSet } from "./server.js";
7
+ type Bound = {
8
+ tool: Tool;
9
+ structured: boolean;
10
+ call(args: unknown, meta: Meta): Promise<CallToolResult>;
11
+ };
12
+ type Resolve<C> = (meta: Meta, params: Record<string, unknown>) => Promise<C>;
13
+ export declare function bindOperation<P extends TSchema, D, C>(op: Operation<P, D, [C]>, resolve: Resolve<C>): Bound;
14
+ export declare function createNoteTools(resolve: Resolve<NotesToolContext>, additional?: Bound[], fallbackCode?: string): ToolSet;
15
+ export {};
@@ -0,0 +1,43 @@
1
+ import { Check } from "typebox/value";
2
+ import { notesList, notesRead, notesUpdate, notesWrite } from "../../src/tools/notes.js";
3
+ import { wireResult } from "../../src/tools/result.js";
4
+ import { paramProblem } from "../../src/tools/schema.js";
5
+ function refusal(code, message, structured = false) {
6
+ return { content: [{ type: "text", text: `error: ${code}: ${message}` }], ...(structured ? { structuredContent: { error: message, code } } : {}), isError: true };
7
+ }
8
+ export function bindOperation(op, resolve) {
9
+ const structured = op.outputSchema !== undefined;
10
+ return {
11
+ structured,
12
+ tool: { name: op.name, description: op.description, inputSchema: JSON.parse(JSON.stringify(op.parameters)),
13
+ ...(structured ? { outputSchema: { type: "object", ...JSON.parse(JSON.stringify(op.outputSchema)) } } : {}) },
14
+ async call(args, meta) {
15
+ const params = args ?? {};
16
+ if (!Check(op.parameters, params))
17
+ return refusal("invalid_params", `invalid ${op.name} parameters: ${paramProblem(op.parameters, params)}`, structured);
18
+ const ctx = await resolve(meta, params);
19
+ const outcome = await op.execute(params, ctx);
20
+ return { content: [{ type: "text", text: op.render(outcome) }], ...(structured ? { structuredContent: wireResult(outcome) } : {}),
21
+ ...(outcome.ok ? {} : { isError: true }) };
22
+ },
23
+ };
24
+ }
25
+ export function createNoteTools(resolve, additional = [], fallbackCode = "notesoup_error") {
26
+ const entries = [bindOperation(notesWrite, resolve), bindOperation(notesUpdate, resolve), bindOperation(notesRead, resolve), bindOperation(notesList, resolve), ...additional];
27
+ const byName = new Map(entries.map(entry => [entry.tool.name, entry]));
28
+ return {
29
+ tools: () => entries.map(entry => entry.tool),
30
+ async callTool(name, args, meta) {
31
+ const entry = byName.get(name);
32
+ if (!entry)
33
+ return refusal("unknown_tool", `No notesoup operation named ${JSON.stringify(name)}.`);
34
+ try {
35
+ return await entry.call(args, meta);
36
+ }
37
+ catch (e) {
38
+ const code = e instanceof Error && "code" in e && typeof e.code === "string" ? e.code : fallbackCode;
39
+ return refusal(code, (e instanceof Error ? e.message : String(e)).replace(/[\r\n]+/g, " ").slice(0, 500), entry.structured);
40
+ }
41
+ },
42
+ };
43
+ }
@@ -0,0 +1,14 @@
1
+ /** MCP framing only. Host facts belong to the tool call, not to the server process. */
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { type CallToolResult, type Tool } from "@modelcontextprotocol/sdk/types.js";
4
+ export type Meta = Record<string, unknown>;
5
+ export type ToolSet = {
6
+ tools(): Tool[];
7
+ callTool(name: string, args: unknown, meta: Meta): Promise<CallToolResult>;
8
+ };
9
+ type ServerOptions = ToolSet & {
10
+ name: string;
11
+ };
12
+ export declare function createToolServer(options: ServerOptions): Server;
13
+ export declare function runToolServer(options: ServerOptions): Promise<void>;
14
+ export {};
@@ -0,0 +1,13 @@
1
+ /** MCP framing only. Host facts belong to the tool call, not to the server process. */
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ export function createToolServer(options) {
6
+ const server = new Server({ name: options.name, version: "1.0.0" }, { capabilities: { tools: {} } });
7
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: options.tools() }));
8
+ server.setRequestHandler(CallToolRequestSchema, async ({ params }) => options.callTool(params.name, params.arguments, params._meta ?? {}));
9
+ return server;
10
+ }
11
+ export async function runToolServer(options) {
12
+ await createToolServer(options).connect(new StdioServerTransport());
13
+ }
@@ -1,12 +1,15 @@
1
1
  import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
+ import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
2
3
  import { Type } from "typebox";
3
4
  import { type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
4
5
  export declare const ContextRemainingOutputSchema: Type.TObject<{
5
6
  remaining_tokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
6
7
  }>;
7
- export declare function registerBudget(pi: ExtensionAPI, isEnabled: () => boolean, settingsManager?: SettingsManager): {
8
+ export declare function registerBudget(pi: ExtensionAPI, isEnabled: (ctx: ExtensionContext) => boolean, settingsManager?: SettingsManager): {
8
9
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
9
10
  hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
11
+ hardReserveDueForInput: (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>) => boolean;
12
+ fitsInFreshWindow: (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>) => boolean;
10
13
  consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
11
14
  /** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
12
15
  statusFor: (ctx: ExtensionContext) => {
@@ -2,7 +2,7 @@ import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
2
2
  import { remainingBudget } from "../../src/budget/policy.js";
3
3
  import { Type } from "typebox";
4
4
  import { convertToLlm, defineTool } from "@earendil-works/pi-coding-agent";
5
- import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
5
+ import { GUIDANCE_TYPE, TURNOVER_TRIGGER_TYPE, WARNING_TYPE } from "./entries.js";
6
6
  import { estimateContextTokens } from "./estimate.js";
7
7
  import { warningContent } from "./text.js";
8
8
  import { readThresholdSettings } from "./thresholds.js";
@@ -41,19 +41,40 @@ export function registerBudget(pi, isEnabled, settingsManager) {
41
41
  const hardReserveDue = (ctx, preSendMessages) => {
42
42
  if (!automaticResetEnabled(ctx))
43
43
  return false;
44
+ const { reserve } = thresholdsFor(ctx);
45
+ const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
44
46
  if (preSendMessages) {
47
+ if (remaining !== null && remaining <= reserve)
48
+ return true;
45
49
  const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
46
50
  if (!nativeWindow || nativeWindow <= 0)
47
51
  return false;
48
52
  const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
49
- const { reserve } = thresholdsFor(ctx);
50
53
  const estimate = estimateContextTokens(convertToLlm(preSendMessages));
51
- if (estimate.lastUsageIndex !== null && contextWindow - estimate.usageTokens <= reserve)
52
- return false;
54
+ if (remaining !== null)
55
+ return remaining - estimate.trailingTokens <= reserve;
53
56
  return contextWindow - estimate.tokens <= reserve;
54
57
  }
55
- const remaining = remainingTokens(ctx, cap);
56
- return remaining !== null && remaining <= thresholdsFor(ctx).reserve;
58
+ return remaining !== null && remaining <= reserve;
59
+ };
60
+ const inputTokensFor = (content) => estimateContextTokens([{ role: "user", content, timestamp: 0 }]).tokens;
61
+ const hardReserveDueForInput = (ctx, content) => {
62
+ if (!automaticResetEnabled(ctx))
63
+ return false;
64
+ const { reserve } = thresholdsFor(ctx);
65
+ const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
66
+ if (remaining === null)
67
+ return false;
68
+ return remaining <= reserve || remaining - inputTokensFor(content) <= reserve;
69
+ };
70
+ const fitsInFreshWindow = (ctx, content) => {
71
+ const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
72
+ if (!nativeWindow || nativeWindow <= 0)
73
+ return true;
74
+ const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
75
+ const { reserve } = thresholdsFor(ctx);
76
+ const freshBudget = Math.max(0, contextWindow - reserve);
77
+ return inputTokensFor(content) <= Math.floor(freshBudget / 2);
57
78
  };
58
79
  let pendingGuidance;
59
80
  let pendingWarning;
@@ -84,13 +105,14 @@ export function registerBudget(pi, isEnabled, settingsManager) {
84
105
  details: { anchorEntryId },
85
106
  }));
86
107
  };
87
- pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); thresholdsFor(ctx); });
108
+ pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); if (isEnabled(ctx))
109
+ thresholdsFor(ctx); });
88
110
  pi.on("session_tree", resetForTransition);
89
111
  pi.on("model_select", resetForTransition);
90
112
  pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
91
113
  pi.on("agent_settled", clearStaged);
92
114
  pi.on("context", (event, ctx) => {
93
- if (!isEnabled())
115
+ if (!isEnabled(ctx))
94
116
  return undefined;
95
117
  // Durable reminders return to the slot where the model first read them.
96
118
  const messages = arrangeAnchoredReminders(event.messages, ctx);
@@ -104,6 +126,9 @@ export function registerBudget(pi, isEnabled, settingsManager) {
104
126
  // Without automatic reset nothing gets cleared, so there is nothing to remind about.
105
127
  if (!automaticResetEnabled(ctx))
106
128
  return result();
129
+ const last = event.messages.at(-1);
130
+ if (last?.role === "custom" && last.customType === TURNOVER_TRIGGER_TYPE)
131
+ return result();
107
132
  const remaining = remainingTokens(ctx, cap);
108
133
  if (remaining === null)
109
134
  return result();
@@ -152,6 +177,8 @@ export function registerBudget(pi, isEnabled, settingsManager) {
152
177
  return {
153
178
  automaticResetEnabled,
154
179
  hardReserveDue,
180
+ hardReserveDueForInput,
181
+ fitsInFreshWindow,
155
182
  consumeTurnEnd,
156
183
  /** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
157
184
  statusFor: (ctx) => ({ remaining: remainingBudget(remainingTokens(ctx, cap), thresholdsFor(ctx).reserve), cap }),
@@ -2,8 +2,10 @@ export declare const BOOT_TYPE = "notesoup/boot";
2
2
  export declare const GUIDANCE_TYPE = "notesoup/guidance";
3
3
  export declare const WARNING_TYPE = "notesoup/warning";
4
4
  export declare const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
+ export declare const TURNOVER_TRIGGER_TYPE = "notesoup/turnover";
5
6
  export declare const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
7
  export declare const CONTINUATION_TYPE = "notesoup/continuation";
7
8
  export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
8
9
  export declare const CARRIED_INPUT_TYPE = "notesoup/carried-input";
9
10
  export declare const MARKER_TYPE = "notesoup/marker";
11
+ export declare const ENABLED_TYPE = "notesoup/enabled";
@@ -2,8 +2,10 @@ export const BOOT_TYPE = "notesoup/boot";
2
2
  export const GUIDANCE_TYPE = "notesoup/guidance";
3
3
  export const WARNING_TYPE = "notesoup/warning";
4
4
  export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
+ export const TURNOVER_TRIGGER_TYPE = "notesoup/turnover";
5
6
  export const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
7
  export const CONTINUATION_TYPE = "notesoup/continuation";
7
8
  export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
8
9
  export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
9
10
  export const MARKER_TYPE = "notesoup/marker";
11
+ export const ENABLED_TYPE = "notesoup/enabled";
@@ -1,4 +1,4 @@
1
- import { historyList, historyRead } from "../../src/tools/history.js";
1
+ import { historyList, historySearch, historyRead } from "../../src/tools/history.js";
2
2
  import { historyFromSession } from "./history.js";
3
3
  import { localHistoryCorpus } from "../../src/history/local.js";
4
4
  import { HISTORY_NAMESPACE, registerOperation } from "./tool-result.js";
@@ -9,5 +9,6 @@ function historyContext(ctx) {
9
9
  /** Register the two deferred history operations; the adapter allocates addresses and supplies them. */
10
10
  export function registerHistoryTools(pi) {
11
11
  registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
12
+ registerOperation(pi, historySearch, (params, ctx) => historySearch.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
12
13
  registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
13
14
  }
@@ -2,7 +2,24 @@ import { piHistoryFromEntries, piSequenceCount } from "../../src/history/pi.js";
2
2
  export function nextHistorySeq(ctx, pending = []) {
3
3
  return 1 + [...ctx.sessionManager.getEntries(), ...pending].reduce((sum, entry) => sum + piSequenceCount(entry), 0);
4
4
  }
5
+ const projectionCache = new WeakMap();
5
6
  export function historyFromSession(ctx) {
6
7
  const manager = ctx.sessionManager;
7
- return piHistoryFromEntries(manager.getSessionId(), manager.getEntries(), manager.getBranch());
8
+ const sessionId = manager.getSessionId();
9
+ const entries = manager.getEntries();
10
+ const branch = manager.getBranch();
11
+ const lastEntry = entries.at(-1);
12
+ const lastBranch = branch.at(-1);
13
+ const cached = projectionCache.get(manager);
14
+ if (cached
15
+ && cached.sessionId === sessionId
16
+ && cached.entryCount === entries.length
17
+ && cached.lastEntry === lastEntry
18
+ && cached.branchCount === branch.length
19
+ && cached.lastBranch === lastBranch) {
20
+ return cached.projection;
21
+ }
22
+ const projection = piHistoryFromEntries(sessionId, entries, branch);
23
+ projectionCache.set(manager, { sessionId, entryCount: entries.length, lastEntry, branchCount: branch.length, lastBranch, projection });
24
+ return projection;
8
25
  }
@@ -4,6 +4,7 @@ import { abandonDream, dreamBegin, dreamEnd, dreamForget, dreamingIdentity } fro
4
4
  import { notesIdentityFromPi } from "./adapter.js";
5
5
  import { notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../render.js";
6
6
  import { DREAM_NAMESPACE, NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
7
+ import { wireResult } from "../../../src/tools/result.js";
7
8
  import { notesToolContext } from "../../../src/tools/notes-context.js";
8
9
  function renderDiff(change) {
9
10
  return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
@@ -26,15 +27,18 @@ export function registerNotesTools(pi) {
26
27
  };
27
28
  const identity = (ctx) => dreamingIdentity(notesIdentityFromPi(ctx), dreamOf(ctx));
28
29
  const toolContext = (ctx) => notesToolContext(identity(ctx), ctx.cwd);
29
- registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
30
+ registerOperation(pi, notesWrite, async (params, ctx) => {
31
+ const outcome = await notesWrite.execute(params, toolContext(ctx));
32
+ return { ...outcome, details: { receipt: wireResult(outcome) } };
33
+ }, NOTES_NAMESPACE, notesWriteRenderers);
30
34
  registerOperation(pi, notesUpdate, async (params, ctx) => {
31
35
  let diff = "";
32
36
  const outcome = await notesUpdate.execute(params, toolContext(ctx), (change) => { diff = renderDiff(change); });
33
- return diff ? { ...outcome, details: { diff } } : outcome;
37
+ return { ...outcome, details: { receipt: wireResult(outcome), ...(diff ? { diff } : {}) } };
34
38
  }, NOTES_NAMESPACE, notesUpdateRenderers);
35
39
  registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
36
40
  registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
37
- registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
41
+ registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesToolContext(notesIdentityFromPi(ctx), ctx.cwd), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
38
42
  registerOperation(pi, dreamForget, (params, ctx) => dreamForget.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
39
43
  registerOperation(pi, dreamEnd, (params, ctx) => dreamEnd.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
40
44
  }
@@ -2,20 +2,26 @@
2
2
  import { type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
3
3
  import { type Component } from "@earendil-works/pi-tui";
4
4
  import type { Static } from "typebox";
5
+ import type { WireResult } from "../../src/tools/result.js";
6
+ import type { NotesUpdateData, NotesWriteData } from "../../src/tools/notes.js";
5
7
  import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
6
8
  /** Only the render-context members these renderers read; the host's ToolRenderContext satisfies this. */
7
9
  type CallContext<TArgs> = {
8
10
  args: TArgs;
9
11
  };
12
+ export type NotesWriteDetails = {
13
+ receipt: WireResult<NotesWriteData>;
14
+ };
10
15
  export type NotesWriteArgs = Static<typeof notesWriteParameters>;
11
16
  export declare const notesWriteRenderers: {
12
17
  renderCall: (args: NotesWriteArgs, theme: Theme) => Component;
13
- renderResult(result: AgentToolResult<undefined>, options: {
18
+ renderResult(result: AgentToolResult<NotesWriteDetails | undefined>, options: {
14
19
  expanded: boolean;
15
20
  }, theme: Theme, context: CallContext<NotesWriteArgs>): Component;
16
21
  };
17
22
  export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
18
23
  export type NotesUpdateDetails = {
24
+ receipt: WireResult<NotesUpdateData>;
19
25
  diff?: string;
20
26
  };
21
27
  export declare const notesUpdateRenderers: {
@@ -3,9 +3,9 @@ import { renderDiff } from "@earendil-works/pi-coding-agent";
3
3
  import { Container, Text, TruncatedText, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
4
4
  /** Expanded bodies show this many lines before a "more lines" marker; the full text is in the receipt. */
5
5
  const EXPANDED_LINE_CAP = 80;
6
- /** structuredContent is wireResult(outcome): the data itself, or {error, code}. Old sessions may lack it. */
6
+ /** Receipts are wireResult(outcome), stored in mutation details or notes_read structuredContent. */
7
7
  function wireOf(result) {
8
- const sc = result.structuredContent;
8
+ const sc = result.structuredContent ?? result.details?.receipt;
9
9
  if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
10
10
  const obj = sc;
11
11
  if (typeof obj.error === "string")
@@ -32,7 +32,7 @@ export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
32
32
  * persists the returned text and no read, render, or repair draws it again. The origin defaults to
33
33
  * `normal`, the same reading a legacy marker with no origin gets.
34
34
  */
35
- export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, lastWord?: string, firstSeq?: number, origin?: ResetOrigin): Promise<SessionBoundaryDraft[]>;
35
+ export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, lastWord?: string, firstSeq?: number, origin?: ResetOrigin, betweenTurns?: boolean): Promise<SessionBoundaryDraft[]>;
36
36
  /**
37
37
  * Inspect the persisted tail of a reset marker. It reports which reset messages are present
38
38
  * only while the tail stays repairable: metadata may follow the marker, but real conversation,
@@ -35,7 +35,7 @@ function sendContinuation(pi, content) {
35
35
  * persists the returned text and no read, render, or repair draws it again. The origin defaults to
36
36
  * `normal`, the same reading a legacy marker with no origin gets.
37
37
  */
38
- export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, lastWord, firstSeq, origin = "normal") {
38
+ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, lastWord, firstSeq, origin = "normal", betweenTurns = false) {
39
39
  const sessionId = ctx.sessionManager.getSessionId();
40
40
  const sessionPrefix = sessionId.slice(0, 8);
41
41
  const usedWindowIds = new Set(ctx.sessionManager.getBranch().filter(isWindowMarker).map((entry) => entry.data.windowId));
@@ -46,9 +46,9 @@ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = (
46
46
  const boot = await buildBootMessage(ctx, windowId, firstSeq, notifyIncompleteNotes, isCurrent);
47
47
  return [
48
48
  { type: "compaction", summary: "", firstKeptEntryId: null },
49
- { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin } },
49
+ { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin, ...(betweenTurns ? { betweenTurns: true } : {}) } },
50
50
  { type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
51
- { type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin), display: false },
51
+ { type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin, { betweenTurns }), display: false },
52
52
  ...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
53
53
  ];
54
54
  }
@@ -112,5 +112,5 @@ export async function repairResetTail(pi, ctx, marker, notifyIncompleteNotes, is
112
112
  if (!latest.boot && boot)
113
113
  sendBoot(pi, boot);
114
114
  if (!latest.continuation && (latest.boot || boot))
115
- sendContinuation(pi, selectContinuation(markerResetOrigin(marker)));
115
+ sendContinuation(pi, selectContinuation(markerResetOrigin(marker), { betweenTurns: marker.data.betweenTurns === true }));
116
116
  }