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
@@ -5,13 +5,15 @@ import { type CarriedInput } from "./artifacts.js";
5
5
  type BudgetOwner = {
6
6
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
7
7
  hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
8
+ hardReserveDueForInput?: (ctx: ExtensionContext, content: CarriedInput) => boolean;
9
+ fitsInFreshWindow?: (ctx: ExtensionContext, content: CarriedInput) => boolean;
8
10
  consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
9
11
  clear: () => void;
10
12
  };
11
13
  type ResetOptions = {
12
- isEnabled: () => boolean;
14
+ isEnabled: (ctx: ExtensionContext) => boolean;
13
15
  budget: BudgetOwner;
14
- buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
16
+ buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin, betweenTurns?: boolean) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
15
17
  getLifecycleGeneration?: () => number;
16
18
  onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
17
19
  };
@@ -47,6 +49,10 @@ export interface ResetTurnEndFacts {
47
49
  readonly queued: boolean;
48
50
  readonly automaticResetEnabled: boolean;
49
51
  readonly hardReserveDue: boolean;
52
+ /** True when this turn still has follow-up work (tool batch, pre-send cutoff, or queued input). */
53
+ readonly hasPendingWork: boolean;
54
+ /** True when the host view erases scrollback on reset (Pi TUI), so clean answers defer rollover until next input. */
55
+ readonly deferBetweenTurns?: boolean;
50
56
  }
51
57
  /** Facts for the pre-settlement boundary; policy guards stay lazy for the same reason. */
52
58
  export interface ResetBeforeSettleFacts {
@@ -86,6 +92,7 @@ export interface ResetBoundaryIntent {
86
92
  readonly windowId: string;
87
93
  readonly continueAfterReset: boolean;
88
94
  readonly origin: ResetOrigin;
95
+ readonly betweenTurns?: boolean;
89
96
  readonly tool?: {
90
97
  readonly lastWord?: string;
91
98
  readonly terminate?: boolean;
@@ -1,4 +1,5 @@
1
1
  import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
2
+ import { TURNOVER_TRIGGER_TYPE } from "../entries.js";
2
3
  import { currentReset, currentWindowId } from "../window.js";
3
4
  import { nextHistorySeq } from "../history.js";
4
5
  import { buildMarkerDraft } from "../marker.js";
@@ -33,7 +34,7 @@ export function finalizeResetBoundary(intent, request) {
33
34
  const resumeModel = intent.continueAfterReset || inputs.length > 0;
34
35
  const state = {
35
36
  request: NO_REQUEST,
36
- ...(intent.boundary === "turn-end" && !resumeModel ? { stopAfterReset: intent } : {}),
37
+ ...(intent.boundary === "turn-end" && !resumeModel && !intent.betweenTurns ? { stopAfterReset: intent } : {}),
37
38
  overflow: spendsOverflow(intent.boundary) ? "spent" : "idle",
38
39
  };
39
40
  return { state, inputs, resumeModel };
@@ -87,12 +88,30 @@ export function reduceResetControl(state, event) {
87
88
  if (!facts.enabled) {
88
89
  return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "none" };
89
90
  }
90
- // A direct tool request commits after the whole tool batch. The budget cutoff is
91
- // a separate hard-reserve safety path; ordinary close-out waits for settlement.
91
+ // A direct tool request commits after the whole tool batch. An automatic hard-reserve
92
+ // cutoff fires at turn_end with continuation while work is still in flight (tool batch,
93
+ // pre-send, queued input, or manual close-out). For a clean final answer:
94
+ // - non-erasing views (RPC/print/JSON) rotate quietly at turn_end with continue:false;
95
+ // - scrollback-erasing views (Pi TUI) defer rollover until the human's next input.
92
96
  const toolReset = request.phase === "pending" && request.tool !== undefined;
93
- if ((toolReset && !manual) || facts.hardReserveDue) {
97
+ if (toolReset && !manual) {
94
98
  return boundaryIntent(request, facts.windowId, "turn-end");
95
99
  }
100
+ if (facts.hardReserveDue) {
101
+ if (manual || toolReset || facts.hasPendingWork) {
102
+ return boundaryIntent(request, facts.windowId, "turn-end");
103
+ }
104
+ if (!facts.deferBetweenTurns) {
105
+ return {
106
+ effect: "build-boundary",
107
+ boundary: "turn-end",
108
+ windowId: facts.windowId,
109
+ continueAfterReset: false,
110
+ origin: "forced",
111
+ betweenTurns: true,
112
+ };
113
+ }
114
+ }
96
115
  return { state: { request, overflow: "idle" }, effect: "none" };
97
116
  }
98
117
  case "before_settle": {
@@ -147,6 +166,9 @@ export function registerResetLifecycle(pi, options) {
147
166
  let control = initialResetControl();
148
167
  let preSendHardReserveWindowId;
149
168
  let pendingPreSendTrigger;
169
+ let pendingTurnover;
170
+ let pendingUserReplays = [];
171
+ let failedTurnoverWindowId;
150
172
  // Once input returns handled, Pi no longer owns its original content. If close-out
151
173
  // fails/cancels, restore it; only an ordinary error starts a turn to answer it.
152
174
  const restoreCommandInputs = (triggerTurn = false) => {
@@ -163,26 +185,38 @@ export function registerResetLifecycle(pi, options) {
163
185
  lifecycleGeneration++;
164
186
  preSendHardReserveWindowId = undefined;
165
187
  pendingPreSendTrigger = undefined;
166
- if (preserveInputs)
188
+ const turnoverInputs = pendingTurnover?.inputs ?? [];
189
+ pendingTurnover = undefined;
190
+ pendingUserReplays = [];
191
+ if (preserveInputs) {
167
192
  restoreCommandInputs();
193
+ for (const draft of carriedInputDrafts(turnoverInputs)) {
194
+ pi.sendMessage(draft, { triggerTurn: false });
195
+ }
196
+ }
168
197
  control = initialResetControl();
169
198
  };
170
- const resetBoundaryResult = async (entries, ctx, intent, preSendHardReserve = false) => {
171
- // Keep command state live while notes load so input arriving during this await joins this boundary.
199
+ const resetBoundaryResult = async (entries, ctx, intent, preSendHardReserve = false, turnover) => {
200
+ // Keep command/turnover state live while notes load so input arriving during this await joins this boundary.
172
201
  const generation = lifecycleGeneration;
173
202
  const outerGeneration = options.getLifecycleGeneration?.();
174
203
  const sessionId = ctx.sessionManager.getSessionId();
175
204
  const windowId = currentWindowId(ctx);
176
205
  const isCurrent = () => sessionActive && lifecycleGeneration === generation &&
177
- (outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled() &&
206
+ (outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled(ctx) &&
178
207
  (preSendHardReserve || ctx.signal?.aborted !== true) && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
179
208
  // The retain-none checkpoint belongs to the old window; capture its successor before notes await.
180
209
  const firstSeq = nextHistorySeq(ctx, entries) + 1;
181
210
  let resetDrafts;
182
211
  try {
183
- resetDrafts = await options.buildReset(ctx, isCurrent, intent.tool?.lastWord, firstSeq, intent.origin);
212
+ resetDrafts = await options.buildReset(ctx, isCurrent, intent.tool?.lastWord, firstSeq, intent.origin, turnover !== undefined || intent.betweenTurns === true);
184
213
  }
185
214
  catch (error) {
215
+ if (turnover && pendingTurnover === turnover) {
216
+ pendingUserReplays = [...turnover.inputs];
217
+ pendingTurnover = undefined;
218
+ failedTurnoverWindowId = windowId;
219
+ }
186
220
  if (isCurrent())
187
221
  ctx.ui.notify(`🥣 Brain still full: ${errorMessage(error)}`, "warning");
188
222
  return entries.length > 0 ? { entries } : undefined;
@@ -192,6 +226,13 @@ export function registerResetLifecycle(pi, options) {
192
226
  const finalized = finalizeResetBoundary(intent, control.request);
193
227
  control = finalized.state;
194
228
  options.onResetReady?.(ctx, resetDrafts);
229
+ if (turnover && pendingTurnover === turnover) {
230
+ // Commit the entire fresh window atomically; agent_settled delivers the withheld user prompt directly.
231
+ pendingUserReplays = [...turnover.inputs];
232
+ pendingTurnover = undefined;
233
+ failedTurnoverWindowId = undefined;
234
+ return { entries: [...entries, ...resetDrafts], continue: false };
235
+ }
195
236
  const allDrafts = [...resetDrafts, ...carriedInputDrafts(finalized.inputs)];
196
237
  if (preSendHardReserve && finalized.resumeModel) {
197
238
  const last = allDrafts.at(-1);
@@ -203,16 +244,39 @@ export function registerResetLifecycle(pi, options) {
203
244
  return { entries: [...entries, ...allDrafts], continue: finalized.resumeModel };
204
245
  };
205
246
  pi.on("input", (event, ctx) => {
206
- if (event.source === "extension" || !sessionActive || !options.isEnabled())
207
- return undefined;
208
- const request = control.request;
209
- if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx))
247
+ if (event.source === "extension" || !sessionActive || !options.isEnabled(ctx))
210
248
  return undefined;
211
249
  const content = event.images?.length
212
250
  ? [{ type: "text", text: event.text }, ...event.images]
213
251
  : event.text;
214
- control = reduceResetControl(control, { type: "input", windowId: request.windowId, input: content }).state;
215
- return { action: "handled" };
252
+ const windowId = currentWindowId(ctx);
253
+ const request = control.request;
254
+ if (request.phase === "pending" && request.command && request.windowId === windowId) {
255
+ control = reduceResetControl(control, { type: "input", windowId, input: content }).state;
256
+ return { action: "handled" };
257
+ }
258
+ if (pendingTurnover && pendingTurnover.windowId === windowId) {
259
+ pendingTurnover.inputs.push(content);
260
+ return { action: "handled" };
261
+ }
262
+ if (ctx.mode === "tui" &&
263
+ event.source === "interactive" &&
264
+ !event.streamingBehavior &&
265
+ ctx.isIdle() &&
266
+ request.phase === "none" &&
267
+ !control.stopAfterReset &&
268
+ failedTurnoverWindowId !== windowId &&
269
+ (options.budget.hardReserveDueForInput
270
+ ? options.budget.hardReserveDueForInput(ctx, content)
271
+ : options.budget.hardReserveDue(ctx))) {
272
+ const fits = options.budget.fitsInFreshWindow ? options.budget.fitsInFreshWindow(ctx, content) : true;
273
+ if (!fits)
274
+ return undefined;
275
+ pendingTurnover = { windowId, inputs: [content] };
276
+ pi.sendMessage({ customType: TURNOVER_TRIGGER_TYPE, content: "", display: false }, { triggerTurn: true });
277
+ return { action: "handled" };
278
+ }
279
+ return undefined;
216
280
  });
217
281
  // Boundary continue:false is not a veto of Pi's tool-batch follow-up. Once the
218
282
  // safety reset is actually committed, cancel that empty follow-up before provider
@@ -235,13 +299,15 @@ export function registerResetLifecycle(pi, options) {
235
299
  const system = getCurrentSystemMessage(event.messages);
236
300
  return { messages: system ? [system] : [] };
237
301
  }
238
- if (!options.isEnabled() || ctx.signal?.aborted)
302
+ if (!options.isEnabled(ctx) || ctx.signal?.aborted)
239
303
  return undefined;
240
304
  if (control.request.phase === "pending" && control.request.command !== undefined)
241
305
  return undefined;
242
- if (!options.budget.hardReserveDue(ctx, event.messages))
306
+ const windowId = currentWindowId(ctx);
307
+ const turnoverDue = pendingTurnover !== undefined && pendingTurnover.windowId === windowId;
308
+ if (!turnoverDue && (failedTurnoverWindowId === windowId || !options.budget.hardReserveDue(ctx, event.messages)))
243
309
  return undefined;
244
- preSendHardReserveWindowId = currentWindowId(ctx);
310
+ preSendHardReserveWindowId = windowId;
245
311
  ctx.abort();
246
312
  const system = getCurrentSystemMessage(event.messages);
247
313
  return { messages: system ? [system] : [] };
@@ -252,10 +318,12 @@ export function registerResetLifecycle(pi, options) {
252
318
  const windowId = currentWindowId(ctx);
253
319
  const preSendHardReserve = preSendHardReserveWindowId !== undefined && preSendHardReserveWindowId === windowId;
254
320
  preSendHardReserveWindowId = undefined;
321
+ const turnover = preSendHardReserve && pendingTurnover?.windowId === windowId ? pendingTurnover : undefined;
255
322
  const aborted = preSendHardReserve ? false : isAbort(event.message, event.outcome, ctx);
256
323
  const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
257
- const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
324
+ const budgetEntries = options.isEnabled(ctx) && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
258
325
  const entries = [...(event.entries ?? []), ...budgetEntries];
326
+ const hasToolTurn = event.toolResults.length > 0 || (event.message.role === "assistant" && event.message.stopReason === "toolUse");
259
327
  const decision = reduceResetControl(control, {
260
328
  type: "turn_end",
261
329
  facts: {
@@ -263,20 +331,22 @@ export function registerResetLifecycle(pi, options) {
263
331
  aborted,
264
332
  overflow: aborted ? false : isOverflowLike(event.message, ctx),
265
333
  failed: event.outcome === "error",
266
- enabled: options.isEnabled(),
334
+ enabled: options.isEnabled(ctx),
267
335
  get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
268
336
  get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
269
337
  get hardReserveDue() { return preSendHardReserve || options.budget.hardReserveDue(ctx); },
338
+ get hasPendingWork() { return preSendHardReserve || hasToolTurn || event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
339
+ deferBetweenTurns: ctx.mode === "tui",
270
340
  },
271
341
  });
272
342
  if (decision.effect === "build-boundary")
273
- return await resetBoundaryResult(entries, ctx, decision, preSendHardReserve);
343
+ return await resetBoundaryResult(entries, ctx, decision, preSendHardReserve, turnover);
274
344
  if (aborted)
275
345
  restoreCommandInputs();
276
346
  else if (event.outcome === "error" && decision.state.request.phase === "none")
277
347
  restoreCommandInputs(true);
278
348
  control = decision.state;
279
- if (!aborted && event.outcome !== "error" && options.isEnabled()) {
349
+ if (!aborted && event.outcome !== "error" && options.isEnabled(ctx)) {
280
350
  const marker = buildMarkerDraft(ctx, entries);
281
351
  if (marker)
282
352
  entries.push(marker);
@@ -291,7 +361,7 @@ export function registerResetLifecycle(pi, options) {
291
361
  facts: {
292
362
  windowId: currentWindowId(ctx),
293
363
  get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
294
- get enabled() { return options.isEnabled(); },
364
+ get enabled() { return options.isEnabled(ctx); },
295
365
  get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
296
366
  aborted: event.outcome === "aborted" || ctx.signal?.aborted === true,
297
367
  failed: event.outcome === "error",
@@ -311,8 +381,7 @@ export function registerResetLifecycle(pi, options) {
311
381
  return undefined;
312
382
  if (event.signal.aborted)
313
383
  return { cancel: true };
314
- const markerExists = currentReset(ctx) !== undefined;
315
- if (options.isEnabled() || markerExists) {
384
+ if (options.isEnabled(ctx)) {
316
385
  if (event.reason === "manual") {
317
386
  ctx.ui.notify("🥣 No compacting brains here · use /fresh-window", "warning");
318
387
  }
@@ -321,19 +390,28 @@ export function registerResetLifecycle(pi, options) {
321
390
  return undefined;
322
391
  });
323
392
  pi.on("agent_end", (_event, ctx) => {
324
- if (ctx.signal?.aborted && !pendingPreSendTrigger)
393
+ if (ctx.signal?.aborted && !pendingPreSendTrigger && pendingUserReplays.length === 0)
325
394
  clear();
326
395
  });
327
396
  pi.on("agent_settled", () => {
328
397
  const trigger = pendingPreSendTrigger;
398
+ const replays = pendingUserReplays;
329
399
  clear();
330
- if (trigger) {
400
+ if (replays.length > 0) {
401
+ for (let i = 0; i < replays.length; i++) {
402
+ pi.sendUserMessage(replays[i], {
403
+ ...(i > 0 ? { deliverAs: "followUp" } : {}),
404
+ expandPromptTemplates: true,
405
+ });
406
+ }
407
+ }
408
+ else if (trigger) {
331
409
  pi.sendMessage(trigger, { triggerTurn: true });
332
410
  }
333
411
  });
334
- pi.on("session_start", () => { clear(false); sessionActive = true; });
335
- pi.on("session_tree", () => { clear(false); });
336
- pi.on("session_shutdown", () => { clear(false); options.budget.clear(); sessionActive = false; });
412
+ pi.on("session_start", () => { failedTurnoverWindowId = undefined; clear(false); sessionActive = true; });
413
+ pi.on("session_tree", () => { failedTurnoverWindowId = undefined; clear(false); });
414
+ pi.on("session_shutdown", () => { failedTurnoverWindowId = undefined; clear(false); options.budget.clear(); sessionActive = false; });
337
415
  return {
338
416
  command(windowId, continueAfterReset, input) {
339
417
  const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset, ...(input !== undefined ? { input } : {}) });
@@ -345,7 +423,7 @@ export function registerResetLifecycle(pi, options) {
345
423
  control = decision.state;
346
424
  return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
347
425
  },
348
- hasPendingTrigger: () => pendingPreSendTrigger !== undefined,
426
+ hasPendingTrigger: () => pendingPreSendTrigger !== undefined || pendingUserReplays.length > 0,
349
427
  clear,
350
428
  };
351
429
  }
@@ -1,4 +1,5 @@
1
- import { readFileSync } from "node:fs";
1
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
2
3
  import { resetBoundaryCommitted } from "./reset/committed.js";
3
4
  import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
4
5
  import { Type } from "typebox";
@@ -6,10 +7,10 @@ import { VERSION, defineTool } from "@earendil-works/pi-coding-agent";
6
7
  import { registerBudget } from "./budget.js";
7
8
  import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
8
9
  import { emptyBrainRenderers } from "./render.js";
9
- import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
10
+ import { activeBranchTail, currentReset, currentWindowId, isCheckpointBackedReset, isNotesoupEnabled, isNotesoupSkillPath, isWindowBoot, isWindowBootEntry, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, stripNotesoupProjection } from "./window.js";
10
11
  import { registerResetLifecycle } from "./reset/lifecycle.js";
11
12
  import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
12
- import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
13
+ import { BOOT_TYPE, ENABLED_TYPE, MANUAL_WIPE_TYPE, TURNOVER_TRIGGER_TYPE } from "./entries.js";
13
14
  import { commandWarningContent, PI_PRE_RESET_HINTS } from "./text.js";
14
15
  import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../src/boot/text.js";
15
16
  import { agentSlug } from "./notes/adapter.js";
@@ -37,33 +38,26 @@ function branchHasWindowMarker(ctx, fromId) {
37
38
  return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
38
39
  }
39
40
  /**
40
- * Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
41
- * boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
41
+ * Resolve notesoup's own `skills/` directory in both layouts: direct TypeScript source
42
+ * (`plugins/pi/runtime.ts`) and the compiled package (`dist/plugins/pi/runtime.js`).
42
43
  */
43
- async function ensureBoot(pi, ctx, notifyIncompleteNotes, isCurrent = () => true) {
44
- const sessionId = ctx.sessionManager.getSessionId();
45
- const reset = currentReset(ctx);
46
- const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
47
- const stillCurrent = () => isCurrent() &&
48
- ctx.signal?.aborted !== true &&
49
- ctx.sessionManager.getSessionId() === sessionId &&
50
- currentWindowId(ctx) === windowId;
51
- if (reset) {
52
- await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
53
- return;
44
+ function resolveNotesoupSkillDirs() {
45
+ const dirs = new Set();
46
+ for (const candidate of ["../../skills", "../../../skills"]) {
47
+ try {
48
+ const path = fileURLToPath(new URL(candidate, import.meta.url));
49
+ if (existsSync(path))
50
+ dirs.add(realpathSync(path));
51
+ }
52
+ catch { /* not a source or compiled layout */ }
54
53
  }
55
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
56
- return;
57
- const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
58
- if (!stillCurrent())
59
- return;
60
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
61
- return;
62
- sendBoot(pi, boot);
54
+ return [...dirs];
63
55
  }
56
+ const notesoupSkillDirs = resolveNotesoupSkillDirs();
64
57
  /** Register the context-window runtime and its context-owned commands/tools. */
65
58
  export function registerContext(pi, settingsManager) {
66
- let enabled = true;
59
+ pi.registerFlag("no-notesoup", { description: "Start with notesoup off (/notesoup on overrides)", type: "boolean", default: false });
60
+ const isEnabled = (ctx) => isNotesoupEnabled(pi, ctx);
67
61
  let lifecycleGeneration = 0;
68
62
  let missingBootNotice;
69
63
  const incompleteNotesNotified = new Set();
@@ -81,15 +75,53 @@ export function registerContext(pi, settingsManager) {
81
75
  if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId))
82
76
  continue;
83
77
  pendingResetNotices.delete(windowId);
84
- if (markerResetOrigin(marker) === "forced")
78
+ if (markerResetOrigin(marker) === "forced" && !marker.data.betweenTurns)
85
79
  ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
86
80
  }
87
81
  };
88
- pi.on("before_agent_start", (event, ctx) => {
82
+ /** Complete a reset tail that a previous process left half-written. */
83
+ const ensureResetRepair = async (ctx, isCurrent) => {
84
+ const reset = currentReset(ctx);
85
+ if (!reset)
86
+ return;
87
+ const sessionId = ctx.sessionManager.getSessionId();
88
+ const windowId = reset.data.windowId;
89
+ const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
90
+ ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
91
+ await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
92
+ };
93
+ /** Root windows (or windows after a native compaction while off) boot lazily before the first provider-facing turn. */
94
+ const buildLazyBoot = async (ctx, isCurrent) => {
95
+ if (currentReset(ctx))
96
+ return undefined;
97
+ const sessionId = ctx.sessionManager.getSessionId();
98
+ const windowId = currentWindowId(ctx);
99
+ const hasBoot = () => activeBranchTail(ctx.sessionManager.getBranch()).some((entry) => isWindowBootEntry(entry, windowId)) ||
100
+ ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId));
101
+ if (hasBoot())
102
+ return undefined;
103
+ const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
104
+ ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId && !currentReset(ctx);
105
+ const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
106
+ if (!stillCurrent() || hasBoot())
107
+ return undefined;
108
+ return boot;
109
+ };
110
+ pi.on("before_agent_start", async (event, ctx) => {
111
+ if (!isEnabled(ctx)) {
112
+ event.systemPromptOptions.skills = event.systemPromptOptions.skills.filter((skill) => !isNotesoupSkillPath(skill.filePath, notesoupSkillDirs));
113
+ return undefined;
114
+ }
89
115
  event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
90
116
  event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
91
- if (enabled)
92
- maybeSendMarker(pi, ctx);
117
+ maybeSendMarker(pi, ctx);
118
+ if (!currentReset(ctx) && !(event.messageType === "custom" && (event.message.customType === MANUAL_WIPE_TYPE || event.message.customType === TURNOVER_TRIGGER_TYPE))) {
119
+ const generation = lifecycleGeneration;
120
+ const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
121
+ if (boot)
122
+ return { message: boot };
123
+ }
124
+ return undefined;
93
125
  });
94
126
  pi.on("turn_start", (_event, ctx) => {
95
127
  notifyCommittedResets(ctx);
@@ -106,21 +138,20 @@ export function registerContext(pi, settingsManager) {
106
138
  const namespaces = snapshot.unavailable.map((namespace) => namespace.label).join(", ");
107
139
  ctx.ui.notify(`🥣 Some notes went missing: ${namespaces}`, "warning");
108
140
  };
109
- const budget = registerBudget(pi, () => enabled, settingsManager);
141
+ const budget = registerBudget(pi, (ctx) => isEnabled(ctx), settingsManager);
110
142
  pi.on("session_start", async (_event, ctx) => {
111
143
  const generation = ++lifecycleGeneration;
112
- if (!enabled)
113
- return;
114
144
  missingBootNotice = undefined;
115
145
  pendingResetNotices.clear();
116
- await ensureBoot(pi, ctx, notifyIncompleteNotes, () => generation === lifecycleGeneration && enabled);
146
+ if (isEnabled(ctx))
147
+ await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
117
148
  });
118
149
  pi.on("session_tree", async (_event, ctx) => {
119
150
  const generation = ++lifecycleGeneration;
120
151
  missingBootNotice = undefined;
121
152
  pendingResetNotices.clear();
122
- if (enabled)
123
- await ensureBoot(pi, ctx, notifyIncompleteNotes, () => generation === lifecycleGeneration && enabled);
153
+ if (isEnabled(ctx))
154
+ await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
124
155
  });
125
156
  pi.on("session_shutdown", () => {
126
157
  lifecycleGeneration++;
@@ -140,12 +171,10 @@ export function registerContext(pi, settingsManager) {
140
171
  // root windows only refresh a forked boot identity and retain the copied root transcript.
141
172
  pi.on("context_with_system", (event, ctx) => {
142
173
  const reset = currentReset(ctx);
143
- const windowId = reset?.data.windowId ?? rootWindowId(ctx.sessionManager.getSessionId());
174
+ const windowId = currentWindowId(ctx);
144
175
  try {
145
- if (reset) {
146
- return { messages: projectWindow(event.messages, windowId) };
147
- }
148
- return { messages: projectRootWindow(event.messages, windowId) };
176
+ const projected = reset ? projectWindow(event.messages, windowId) : projectRootWindow(event.messages, windowId);
177
+ return { messages: isEnabled(ctx) ? projected : stripNotesoupProjection(projected, notesoupSkillDirs) };
149
178
  }
150
179
  catch (error) {
151
180
  if (missingBootNotice !== windowId) {
@@ -159,7 +188,7 @@ export function registerContext(pi, settingsManager) {
159
188
  });
160
189
  pi.registerCommand("notesoup", {
161
190
  description: "Show notesoup status, toggle context windows, or cap their capacity",
162
- getArgumentCompletions: (prefix) => ["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
191
+ getArgumentCompletions: (prefix) => ["on", "off", "reset", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
163
192
  handler: async (args, cmdCtx) => {
164
193
  const arg = args.trim().toLowerCase();
165
194
  const parts = arg.split(/\s+/);
@@ -177,39 +206,40 @@ export function registerContext(pi, settingsManager) {
177
206
  }
178
207
  }
179
208
  }
180
- else if (arg === "on") {
181
- enabled = true;
182
- const generation = ++lifecycleGeneration;
183
- await ensureBoot(pi, cmdCtx, notifyIncompleteNotes, () => generation === lifecycleGeneration && enabled);
184
- }
185
- else if (arg === "off") {
186
- enabled = false;
187
- lifecycleGeneration++;
188
- pendingResetNotices.clear();
189
- incompleteNotesNotified.clear();
190
- missingBootNotice = undefined;
191
- budget.clear();
192
- resets.clear();
209
+ else if (arg === "on" || arg === "off" || arg === "reset") {
210
+ pi.appendEntry(ENABLED_TYPE, { version: 1, enabled: arg === "reset" ? null : arg === "on" });
211
+ if (isEnabled(cmdCtx)) {
212
+ const generation = ++lifecycleGeneration;
213
+ await ensureResetRepair(cmdCtx, () => generation === lifecycleGeneration && isEnabled(cmdCtx));
214
+ }
215
+ else {
216
+ lifecycleGeneration++;
217
+ pendingResetNotices.clear();
218
+ incompleteNotesNotified.clear();
219
+ missingBootNotice = undefined;
220
+ budget.clear();
221
+ resets.clear();
222
+ }
193
223
  }
194
224
  else if (arg !== "") {
195
- cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
225
+ cmdCtx.ui.notify("Usage: /notesoup [on|off|reset|cap [100k|1m|tokens|off]]", "error");
196
226
  return;
197
227
  }
198
228
  const { remaining, cap } = budget.statusFor(cmdCtx);
199
- cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
229
+ cmdCtx.ui.notify(`🥣 notesoup ${isEnabled(cmdCtx) ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
200
230
  },
201
231
  });
202
232
  const emptyBrainCommand = (name) => ({
203
233
  description: "Flush memory to notes, reset, and stop; optional text provides close-out context",
204
234
  handler: async (args, cmdCtx) => {
205
- if (!enabled) {
235
+ if (!isEnabled(cmdCtx)) {
206
236
  cmdCtx.ui.notify("🥣 notesoup is off · no brain to empty", "error");
207
237
  return;
208
238
  }
209
239
  const requestedWindowId = currentWindowId(cmdCtx);
210
240
  if (!cmdCtx.isIdle() && !cmdCtx.signal) {
211
241
  await cmdCtx.waitForIdle();
212
- if (!enabled || currentWindowId(cmdCtx) !== requestedWindowId)
242
+ if (!isEnabled(cmdCtx) || currentWindowId(cmdCtx) !== requestedWindowId)
213
243
  return;
214
244
  }
215
245
  // Manual wipes close out at settlement, then stop unless later human input arrives. The hidden warning is triggered when idle,
@@ -238,13 +268,13 @@ export function registerContext(pi, settingsManager) {
238
268
  label: "Empty Brain",
239
269
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
240
270
  parameters: Type.Object({
241
- last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })),
242
- terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
271
+ last_word: Type.Optional(Type.String({ description: `A tiny sticky note (at most ${LAST_WORD_ADVERTISED_CHARS} characters), slapped on your forehead after the wipe.` })),
272
+ terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe." })),
243
273
  }, { additionalProperties: false }),
244
274
  renderCall: emptyBrainRenderers.renderCall,
245
275
  renderResult: emptyBrainRenderers.renderResult,
246
276
  async execute(_id, params, _signal, _update, ctx) {
247
- if (!enabled)
277
+ if (!isEnabled(ctx))
248
278
  return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
249
279
  const lastWord = sanitizeLastWord(params.last_word);
250
280
  const length = lastWord ? Array.from(lastWord).length : 0;
@@ -254,8 +284,8 @@ export function registerContext(pi, settingsManager) {
254
284
  },
255
285
  }));
256
286
  const resets = registerResetLifecycle(pi, {
257
- isEnabled: () => enabled,
258
- buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin),
287
+ isEnabled: (ctx) => isEnabled(ctx),
288
+ buildReset: (ctx, isCurrent, lastWord, firstSeq, origin, betweenTurns) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin, betweenTurns),
259
289
  getLifecycleGeneration: () => lifecycleGeneration,
260
290
  onResetReady: (_ctx, drafts) => {
261
291
  const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);
@@ -267,4 +297,15 @@ export function registerContext(pi, settingsManager) {
267
297
  },
268
298
  budget,
269
299
  });
300
+ // Registered after the reset lifecycle so a reset that swallows this input (`handled`)
301
+ // never gets a root boot for a turn that will not run.
302
+ pi.on("input", async (event, ctx) => {
303
+ if (!ctx.isIdle() || event.streamingBehavior || !isEnabled(ctx) || currentReset(ctx))
304
+ return undefined;
305
+ const generation = lifecycleGeneration;
306
+ const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
307
+ if (boot)
308
+ sendBoot(pi, boot);
309
+ return undefined;
310
+ });
270
311
  }
@@ -8,17 +8,17 @@ export function output(value, details, terminate = false) {
8
8
  return { content: [{ type: "text", text: JSON.stringify(value) }], details, terminate, ...(refused ? { isError: true } : {}) };
9
9
  }
10
10
  /** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
11
- function piOperationResult(render, outcome, details) {
11
+ function piOperationResult(operation, outcome, details) {
12
12
  return {
13
- content: [{ type: "text", text: render(outcome) }],
14
- structuredContent: wireResult(outcome),
13
+ content: [{ type: "text", text: operation.render(outcome) }],
14
+ ...(operation.outputSchema !== undefined ? { structuredContent: wireResult(outcome) } : {}),
15
15
  isError: !outcome.ok,
16
16
  details: details,
17
17
  };
18
18
  }
19
- export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
19
+ export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the notesoup-guide skill." };
20
20
  export const DREAM_NAMESPACE = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
21
- export const HISTORY_NAMESPACE = { name: "history", description: "Session history (this or other local sessions): history_list to browse/search, history_read to read one event." };
21
+ export const HISTORY_NAMESPACE = { name: "history", description: "Session history (this or other local sessions): history_list to browse a timeline or list sessions, history_search to find passages, history_read to read one event." };
22
22
  /** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
23
23
  export function registerOperation(pi, operation, run, namespace, renderers, exposure) {
24
24
  pi.registerTool(defineTool({
@@ -26,14 +26,14 @@ export function registerOperation(pi, operation, run, namespace, renderers, expo
26
26
  label: operation.label,
27
27
  description: operation.description,
28
28
  parameters: operation.parameters,
29
- outputSchema: operation.outputSchema,
29
+ ...(operation.outputSchema ? { outputSchema: operation.outputSchema } : {}),
30
30
  executionMode: operation.executionMode,
31
31
  ...(namespace ? { namespace } : {}),
32
32
  ...(exposure ? { exposure } : {}),
33
33
  ...renderers,
34
34
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
35
35
  const result = await run(params, ctx);
36
- return piOperationResult(operation.render, result, result.details);
36
+ return piOperationResult(operation, result, result.details);
37
37
  },
38
38
  }));
39
39
  }