notesoup 0.51.1 โ†’ 0.51.2

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 (34) hide show
  1. package/dist/plugins/pi/entries.d.ts +2 -0
  2. package/dist/plugins/pi/entries.js +2 -0
  3. package/dist/plugins/pi/reset/artifacts.d.ts +10 -2
  4. package/dist/plugins/pi/reset/artifacts.js +24 -5
  5. package/dist/plugins/pi/reset/lifecycle.d.ts +9 -8
  6. package/dist/plugins/pi/reset/lifecycle.js +109 -31
  7. package/dist/plugins/pi/runtime.js +9 -10
  8. package/dist/plugins/pi/text.d.ts +11 -14
  9. package/dist/plugins/pi/text.js +15 -16
  10. package/dist/test/agent-loop.test.js +316 -163
  11. package/dist/test/boot.integration.test.js +3 -3
  12. package/dist/test/claude-validation.test.js +4 -2
  13. package/dist/test/dsh-cli.test.js +7 -6
  14. package/dist/test/helpers/dsh-messages.js +3 -0
  15. package/dist/test/model-facing-text.test.js +10 -4
  16. package/dist/test/reset-lifecycle.test.js +105 -15
  17. package/docs/reset-lifecycle.md +42 -58
  18. package/package.json +2 -2
  19. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  20. package/plugins/paseo/OVERVIEW.md +7 -0
  21. package/plugins/paseo/README.md +12 -0
  22. package/plugins/paseo/client/source-row.ts +14 -0
  23. package/plugins/paseo/client/sticky-card.tsx +21 -0
  24. package/plugins/paseo/index.client.tsx +10 -0
  25. package/plugins/paseo/package.json +19 -0
  26. package/plugins/paseo/paseo-plugin.json +4 -0
  27. package/plugins/paseo/shared/last-word.ts +6 -0
  28. package/plugins/paseo/test/source-row.test.ts +19 -0
  29. package/plugins/paseo/tsconfig.json +16 -0
  30. package/plugins/pi/entries.ts +2 -0
  31. package/plugins/pi/reset/artifacts.ts +26 -5
  32. package/plugins/pi/reset/lifecycle.ts +101 -34
  33. package/plugins/pi/runtime.ts +9 -10
  34. package/plugins/pi/text.ts +17 -17
@@ -0,0 +1,21 @@
1
+ import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
+ import { Text, View } from "react-native";
3
+ import type { LastWord } from "../shared/last-word.ts";
4
+
5
+ export function StickyCard({ item, theme, layout }: PluginTimelineItemProps<LastWord>) {
6
+ const text = item.data.text.replace(/^\*You peel a sticky note off your forehead\.\*\n/, "");
7
+ return (
8
+ <View style={{
9
+ padding: layout.compact ? 12 : 16,
10
+ gap: 8,
11
+ minWidth: 0,
12
+ borderRadius: 12,
13
+ borderWidth: 1,
14
+ borderColor: theme.colors.border,
15
+ backgroundColor: theme.colors.surface1,
16
+ }}>
17
+ <Text style={{ color: theme.colors.foregroundMuted, fontWeight: "600" }}>Last word</Text>
18
+ <Text selectable style={{ color: theme.colors.foreground, flexShrink: 1 }}>{text}</Text>
19
+ </View>
20
+ );
21
+ }
@@ -0,0 +1,10 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { sourceRowTransformer } from "./client/source-row.ts";
3
+ import { StickyCard } from "./client/sticky-card.tsx";
4
+ import { CARD_KIND, lastWordSchema } from "./shared/last-word.ts";
5
+
6
+ export default function contribute(client: PluginClientContext) {
7
+ const removeRenderer = client.addTimelineRenderer({ kind: CARD_KIND, version: 1, schema: lastWordSchema, Component: StickyCard });
8
+ const removeTransformer = client.addTimelineTransformer(sourceRowTransformer);
9
+ return () => { removeTransformer(); removeRenderer(); };
10
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@astrosheep/notesoup-paseo",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "typecheck": "tsc --noEmit",
8
+ "test": "node --experimental-strip-types --test test/*.test.ts"
9
+ },
10
+ "devDependencies": {
11
+ "@getpaseo/plugin": "0.11.2",
12
+ "@types/node": "^22.19.19",
13
+ "@types/react": "~19.2.0",
14
+ "react": "19.1.0",
15
+ "react-native": "0.81.5",
16
+ "typescript": "^5.9.3",
17
+ "zod": "^4.4.3"
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "notesoup-last-word",
3
+ "requirements": { "paseo": ">=0.11.2 <0.12.0" }
4
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+
3
+ export const LAST_WORD_TYPE = "notesoup/reset-last-word";
4
+ export const CARD_KIND = "last-word";
5
+ export const lastWordSchema = z.object({ text: z.string() });
6
+ export type LastWord = z.infer<typeof lastWordSchema>;
@@ -0,0 +1,19 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { sourceRowTransformer } from "../client/source-row.ts";
4
+ import { LAST_WORD_TYPE, lastWordSchema } from "../shared/last-word.ts";
5
+
6
+ test("renders the Pi adapter's replayed last word in place and leaves other rows intact", () => {
7
+ const item = {
8
+ type: "tool_call" as const, callId: "pi-custom-1", name: LAST_WORD_TYPE,
9
+ status: "completed" as const, error: null,
10
+ detail: { type: "plain_text" as const, text: "*You peel a sticky note off your forehead.*\nKeep the handoff." },
11
+ metadata: { synthetic: true, customType: LAST_WORD_TYPE },
12
+ };
13
+ const result = sourceRowTransformer.transform({ item });
14
+ assert.equal(result?.items.length, 1);
15
+ assert.equal(lastWordSchema.parse(result!.items[0]!.data).text, item.detail.text);
16
+ assert.deepEqual(sourceRowTransformer.transform({ item }), result, "replay deterministically replaces one source row");
17
+ assert.equal(sourceRowTransformer.transform({ item: { ...item, metadata: { synthetic: true, customType: "other" } } }), undefined);
18
+ assert.equal(sourceRowTransformer.transform({ item: { ...item, detail: { type: "plain_text" } } }), undefined);
19
+ });
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2023"],
7
+ "types": ["react", "node"],
8
+ "jsx": "react-jsx",
9
+ "strict": true,
10
+ "allowImportingTsExtensions": true,
11
+ "skipLibCheck": true,
12
+ "noEmit": true,
13
+ "esModuleInterop": true
14
+ },
15
+ "include": ["**/*.ts", "**/*.tsx"]
16
+ }
@@ -5,3 +5,5 @@ export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
5
  export const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
6
  export const CONTINUATION_TYPE = "notesoup/continuation";
7
7
  export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
8
+ export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
9
+ export const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
@@ -1,12 +1,23 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
3
- import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../entries.js";
3
+ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../entries.js";
4
4
  import { selectContinuation, type ResetOrigin } from "../../../src/budget/text.js";
5
5
  import { isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, markerResetOrigin, type WindowMarker } from "../window.js";
6
6
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "../boot.js";
7
7
 
8
8
  export type ResetTailState = { readonly boot: boolean; readonly continuation: boolean };
9
9
 
10
+ /** Original user content, including images; custom boundary messages become LLM user messages. */
11
+ export type CarriedInput = Extract<SessionBoundaryDraft, { type: "custom_message" }>["content"];
12
+
13
+ export function carriedInputDrafts(inputs: readonly CarriedInput[]): Extract<SessionBoundaryDraft, { type: "custom_message" }>[] {
14
+ return inputs.map((content) => ({ type: "custom_message", customType: CARRIED_INPUT_TYPE, content, display: true }));
15
+ }
16
+
17
+ export function isCarriedInputEntry(entry: SessionEntry): boolean {
18
+ return entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE && entry.display === true;
19
+ }
20
+
10
21
  /** A sticky note, not a letter: over this, empty_brain refuses instead of truncating. */
11
22
  export const MAX_LAST_WORD_CHARS = 250;
12
23
 
@@ -33,8 +44,8 @@ function sendContinuation(pi: ExtensionAPI, content: string): void {
33
44
 
34
45
  /**
35
46
  * The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
36
- * continuation, then an optional parting line. The prompt is not persisted here โ€” it reached the
37
- * closing window inside the warning. The boot snapshot is acquired asynchronously after capturing
47
+ * continuation, then an optional parting line. The lifecycle appends carried inputs in the same
48
+ * boundary after these artifacts. The boot snapshot is acquired asynchronously after capturing
38
49
  * this identity. The continuation is drawn from the pool its origin names, here, once: the caller
39
50
  * persists the returned text and no read, render, or repair draws it again. The origin defaults to
40
51
  * `normal`, the same reading a legacy marker with no origin gets.
@@ -77,6 +88,8 @@ export function inspectResetTail(ctx: ExtensionContext, markerId: string, window
77
88
  if (markerIndex < 0) return undefined;
78
89
  let boot = false;
79
90
  let continuation = false;
91
+ let lastWord = false;
92
+ let carried = false;
80
93
  for (const entry of branch.slice(markerIndex + 1)) {
81
94
  if (isWindowBootEntry(entry, windowId)) {
82
95
  // The boot is unique and must precede the continuation; a repeat or a late
@@ -90,9 +103,17 @@ export function inspectResetTail(ctx: ExtensionContext, markerId: string, window
90
103
  continuation = true;
91
104
  continue;
92
105
  }
93
- if (isForeignResetTailEntry(entry)) {
94
- return undefined;
106
+ if (entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE) {
107
+ if (!continuation || lastWord || carried || entry.display !== true) return undefined;
108
+ lastWord = true;
109
+ continue;
110
+ }
111
+ if (isCarriedInputEntry(entry)) {
112
+ if (!continuation) return undefined;
113
+ carried = true;
114
+ continue;
95
115
  }
116
+ if (isForeignResetTailEntry(entry)) return undefined;
96
117
  }
97
118
  return { boot, continuation };
98
119
  }
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
3
  import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
3
4
  import type { AgentBeforeSettleEvent, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
@@ -6,6 +7,9 @@ import { nextHistorySeq } from "../history.js";
6
7
  import { resetBoundaryCommitted } from "./committed.js";
7
8
  import type { ResetOrigin } from "../../../src/budget/text.js";
8
9
  import { errorMessage } from "../../../src/error-message.js";
10
+ import { carriedInputDrafts, isCarriedInputEntry, type CarriedInput } from "./artifacts.js";
11
+ import { NEXT_WINDOW_PROMPT_TYPE } from "../entries.js";
12
+ import { promptBlock } from "../text.js";
9
13
 
10
14
  type BudgetOwner = {
11
15
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
@@ -37,7 +41,7 @@ export type ResetRequest =
37
41
  // A hard-reserve reset may precede the end of Pi's tool-batch continuation.
38
42
  | { readonly phase: "stop-pending"; readonly windowId: string; readonly tool?: { readonly lastWord?: string } }
39
43
  | { readonly phase: "pending"; readonly windowId: string;
40
- readonly command?: { readonly continueAfterReset: boolean };
44
+ readonly command?: { readonly continueAfterReset: boolean; readonly inputs?: readonly CarriedInput[] };
41
45
  readonly tool?: { readonly lastWord?: string } };
42
46
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
43
47
 
@@ -75,13 +79,11 @@ export interface ResetBeforeSettleFacts {
75
79
  }
76
80
 
77
81
  export type ResetControlEvent =
78
- | { readonly type: "command"; readonly windowId: string; readonly continueAfterReset: boolean }
82
+ | { readonly type: "command"; readonly windowId: string; readonly continueAfterReset: boolean; readonly input?: CarriedInput }
83
+ | { readonly type: "input"; readonly windowId: string; readonly input: CarriedInput }
79
84
  | { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string }
80
85
  | { readonly type: "turn_end"; readonly facts: ResetTurnEndFacts }
81
- | { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts }
82
- | { readonly type: "settled" }
83
- | { readonly type: "abort" }
84
- | { readonly type: "clear" };
86
+ | { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts };
85
87
 
86
88
  export type ResetControlEffect =
87
89
  | "none"
@@ -104,11 +106,16 @@ function requestForWindow(request: ResetRequest, windowId: string): ResetRequest
104
106
  return request.phase === "stop-pending" || (request.phase !== "none" && request.windowId === windowId) ? request : NO_REQUEST;
105
107
  }
106
108
 
107
- function commandCommit(request: Extract<ResetRequest, { phase: "pending" }>): ResetControlResult {
109
+ function commandContinues(request: Extract<ResetRequest, { phase: "pending" }>): boolean {
110
+ return request.command?.continueAfterReset === true || (request.command?.inputs?.length ?? 0) > 0;
111
+ }
112
+
113
+ function commandCommit(request: Extract<ResetRequest, { phase: "pending" }>, overflow = false): ResetControlResult {
108
114
  return {
109
- state: initialResetControl(),
110
- effect: request.command?.continueAfterReset ? "commit-boundary" : "commit-boundary-stop",
115
+ state: { request: NO_REQUEST, overflow: overflow ? "spent" : "idle" },
116
+ effect: commandContinues(request) ? "commit-boundary" : "commit-boundary-stop",
111
117
  ...requestDetails(request),
118
+ ...(overflow ? { origin: "forced" as const } : {}),
112
119
  };
113
120
  }
114
121
 
@@ -121,6 +128,11 @@ function requestDetails(request: ResetRequest): { origin: ResetOrigin; lastWord?
121
128
  /** Pure transitions: command policy schedules a reset without disguising actual tool calls. */
122
129
  export function reduceResetControl(state: ResetControlState, event: ResetControlEvent): ResetControlResult {
123
130
  switch (event.type) {
131
+ case "input": {
132
+ const request = requestForWindow(state.request, event.windowId);
133
+ if (request.phase !== "pending" || !request.command) return { state, effect: "none" };
134
+ return { state: { ...state, request: { ...request, command: { ...request.command, inputs: [...(request.command.inputs ?? []), event.input] } } }, effect: "none" };
135
+ }
124
136
  case "command":
125
137
  case "tool_request": {
126
138
  const current = requestForWindow(state.request, event.windowId);
@@ -128,7 +140,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
128
140
  const request = current.phase === "pending" ? current : { phase: "pending" as const, windowId: event.windowId };
129
141
  if (event.type === "command") {
130
142
  if (request.command) return { state, effect: "already-pending" };
131
- return { state: { ...state, request: { ...request, command: { continueAfterReset: event.continueAfterReset } } }, effect: "close-out-armed" };
143
+ return { state: { ...state, request: { ...request, command: { continueAfterReset: event.continueAfterReset, ...(event.input !== undefined ? { inputs: [event.input] } : {}) } } }, effect: "close-out-armed" };
132
144
  }
133
145
  // The call remains a real request even when command policy delays its commit.
134
146
  const duplicate = request.tool !== undefined;
@@ -157,7 +169,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
157
169
  // A direct tool request commits after the whole tool batch. The budget cutoff is
158
170
  // a separate hard-reserve safety path; ordinary close-out waits for settlement.
159
171
  if ((request.phase === "pending" && request.tool && !manual) || facts.hardReserveDue) {
160
- if (manual && request.command?.continueAfterReset) return commandCommit(request);
172
+ if (manual && commandContinues(request)) return commandCommit(request);
161
173
  if (manual) return { state: { request: { phase: "stop-pending", windowId: facts.windowId, ...(request.tool ? { tool: request.tool } : {}) }, overflow: "idle" }, effect: "commit-boundary-stop", ...requestDetails(request) };
162
174
  return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary", ...requestDetails(request) };
163
175
  }
@@ -181,7 +193,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
181
193
  }
182
194
  // An explicit manual wipe is not an automatic recovery/retry. It must still
183
195
  // clear on overflow, including when automatic reset is disabled.
184
- if (manual && facts.enabled) return commandCommit(request);
196
+ if (manual && facts.enabled) return commandCommit(request, true);
185
197
  const spent = state.overflow === "pending-spent";
186
198
  if (!facts.enabled || !facts.automaticResetEnabled) {
187
199
  return { state: { request: facts.failed ? NO_REQUEST : request, overflow: spent ? "spent" : "idle" }, effect: "none" };
@@ -194,11 +206,6 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
194
206
  if (facts.queued) return { state: { ...state, request }, effect: "none" };
195
207
  return commandCommit(request);
196
208
  }
197
- case "settled":
198
- return { state: initialResetControl(), effect: "none" };
199
- case "abort":
200
- case "clear":
201
- return { state: initialResetControl(), effect: "none" };
202
209
  }
203
210
  }
204
211
 
@@ -211,9 +218,32 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
211
218
  let sessionActive = true;
212
219
  let lifecycleGeneration = 0;
213
220
  let control = initialResetControl();
221
+ let runInputs: CarriedInput[] = [];
222
+ let commandId: string | undefined;
214
223
 
215
- const clear = () => { control = reduceResetControl(control, { type: "clear" }).state; };
216
- const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, continueAfterReset: boolean, lastWord: string | undefined, origin: ResetOrigin) => {
224
+ // Once input returns handled, Pi no longer owns its original content. If close-out
225
+ // fails/cancels, return that content to the transcript without starting another run.
226
+ const restoreCommandInputs = () => {
227
+ const request = control.request;
228
+ if (request.phase !== "pending" || !request.command?.inputs?.length) return;
229
+ const inputs = request.command.inputs;
230
+ control = { ...control, request: { ...request, command: { ...request.command, inputs: [] } } };
231
+ for (const draft of carriedInputDrafts(inputs)) {
232
+ pi.sendMessage(draft, { triggerTurn: false });
233
+ }
234
+ runInputs.push(...inputs);
235
+ };
236
+ const clear = (preserveInputs = true) => {
237
+ if (preserveInputs) restoreCommandInputs();
238
+ control = initialResetControl();
239
+ runInputs = [];
240
+ commandId = undefined;
241
+ };
242
+ const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, decision: ResetControlResult) => {
243
+ // Keep command state live while notes load: input arriving during this await must
244
+ // join this very boundary even if its steer cannot reach the closing model.
245
+ const passiveInputs = decision.effect === "recover-overflow" ? runInputs : [];
246
+ const origin = decision.origin ?? "forced";
217
247
  const generation = lifecycleGeneration;
218
248
  const outerGeneration = options.getLifecycleGeneration?.();
219
249
  const sessionId = ctx.sessionManager.getSessionId();
@@ -225,27 +255,61 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
225
255
  const firstSeq = nextHistorySeq(ctx, entries) + 1;
226
256
  let resetDrafts: SessionBoundaryDraft[];
227
257
  try {
228
- resetDrafts = await options.buildReset(ctx, isCurrent, lastWord, firstSeq, origin);
258
+ resetDrafts = await options.buildReset(ctx, isCurrent, decision.lastWord, firstSeq, origin);
229
259
  } catch (error) {
230
260
  if (isCurrent()) ctx.ui.notify(`๐Ÿฅฃ Brain still full: ${errorMessage(error)}`, "warning");
231
261
  return entries.length > 0 ? { entries } : undefined;
232
262
  }
233
263
  if (!isCurrent()) return entries.length > 0 ? { entries } : undefined;
264
+ const request = control.request;
265
+ const inputs = request.phase === "pending" && request.command ? request.command.inputs ?? [] : passiveInputs;
266
+ control = decision.state;
267
+ if (inputs.length > 0 && control.request.phase === "stop-pending") control = { ...control, request: NO_REQUEST };
268
+ runInputs = [];
234
269
  options.onResetReady?.(ctx, resetDrafts);
235
- return { entries: [...entries, ...resetDrafts], continue: continueAfterReset };
270
+ return { entries: [...entries, ...resetDrafts, ...carriedInputDrafts(inputs)], continue: inputs.length > 0 || decision.effect !== "commit-boundary-stop" };
236
271
  };
237
272
 
273
+ // Pi may start multiple low-level loops while draining follow-ups/recovering.
274
+ // Keep the logical run's inputs until settlement or a successful boundary.
275
+ pi.on("message_end", (event) => {
276
+ if (event.message.role === "user") runInputs.push(event.message.content);
277
+ });
278
+ pi.on("input", (event, ctx) => {
279
+ if (event.source === "extension" || !sessionActive || !options.isEnabled()) return undefined;
280
+ const request = control.request;
281
+ if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx)) return undefined;
282
+ const content: CarriedInput = event.images?.length
283
+ ? [{ type: "text", text: event.text }, ...event.images]
284
+ : event.text;
285
+ control = reduceResetControl(control, { type: "input", windowId: request.windowId, input: content }).state;
286
+ const steerContent: CarriedInput = event.images?.length
287
+ ? [{ type: "text", text: promptBlock(event.text) }, ...event.images]
288
+ : promptBlock(event.text);
289
+ pi.sendMessage({ customType: NEXT_WINDOW_PROMPT_TYPE, content: steerContent, display: false, details: { windowId: request.windowId, commandId } }, { deliverAs: "steer" });
290
+ return { action: "handled" };
291
+ });
292
+
238
293
  // Boundary continue:false is not a veto of Pi's tool-batch follow-up. Once the
239
294
  // safety reset is actually committed, cancel that empty follow-up before provider
240
295
  // work. Real queued user input is allowed through and answered before settlement.
241
296
  pi.on("context_with_system", (event, ctx) => {
242
297
  const request = control.request;
243
- if (!sessionActive || request.phase !== "stop-pending" || ctx.hasPendingMessages()) return undefined;
298
+ // Steering can be queued during buildReset's await and arrive after the boundary.
299
+ // It is closing-model context only; originals already live in the carried entries.
300
+ const messages = event.messages.filter((message) => {
301
+ if (message.role !== "custom" || message.customType !== NEXT_WINDOW_PROMPT_TYPE) return true;
302
+ const details = message.details as { windowId?: unknown; commandId?: unknown } | undefined;
303
+ return request.phase === "pending" && request.command !== undefined &&
304
+ request.windowId === currentWindowId(ctx) && details?.windowId === request.windowId && commandId !== undefined && details?.commandId === commandId;
305
+ });
306
+ const filtered = messages.length === event.messages.length ? undefined : { messages };
307
+ if (!sessionActive || request.phase !== "stop-pending" || ctx.hasPendingMessages()) return filtered;
244
308
  const marker = currentReset(ctx);
245
- if (!marker || marker.data.windowId === request.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId)) return undefined;
309
+ if (!marker || marker.data.windowId === request.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId)) return filtered;
246
310
  const branch = ctx.sessionManager.getBranch();
247
311
  const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
248
- if (branch.slice(markerIndex + 1).some((entry) => entry.type === "message" && entry.message.role === "user")) return undefined;
312
+ if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry))) return filtered;
249
313
  ctx.abort();
250
314
  const system = getCurrentSystemMessage(event.messages);
251
315
  return { messages: system ? [system] : [] };
@@ -270,8 +334,9 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
270
334
  get hardReserveDue() { return options.budget.hardReserveDue(ctx); },
271
335
  },
272
336
  });
337
+ if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision);
338
+ if (aborted || (event.outcome === "error" && decision.state.request.phase === "none")) restoreCommandInputs();
273
339
  control = decision.state;
274
- if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.lastWord, decision.origin ?? "forced");
275
340
  return entries.length > 0 ? { entries } : undefined;
276
341
  });
277
342
 
@@ -288,10 +353,11 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
288
353
  failed: event.outcome === "error",
289
354
  },
290
355
  });
356
+ if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop" || decision.effect === "recover-overflow") return await resetBoundaryResult(event.entries, ctx, decision);
357
+ if (decision.state.request.phase === "none") restoreCommandInputs();
291
358
  control = decision.state;
292
359
  if (decision.effect === "stop") return { entries: event.entries, continue: false };
293
- if (decision.effect !== "commit-boundary" && decision.effect !== "commit-boundary-stop" && decision.effect !== "recover-overflow") return undefined;
294
- return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.lastWord, decision.origin ?? "forced");
360
+ return undefined;
295
361
  });
296
362
 
297
363
  pi.on("session_before_compact", (event, ctx) => {
@@ -308,19 +374,20 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
308
374
  });
309
375
 
310
376
  pi.on("agent_end", (_event, ctx) => {
311
- if (ctx.signal?.aborted) control = reduceResetControl(control, { type: "abort" }).state;
377
+ if (ctx.signal?.aborted) clear();
312
378
  });
313
379
  pi.on("agent_settled", () => {
314
- control = reduceResetControl(control, { type: "settled" }).state;
380
+ clear();
315
381
  });
316
- pi.on("session_start", () => { lifecycleGeneration++; clear(); sessionActive = true; });
317
- pi.on("session_tree", () => { lifecycleGeneration++; clear(); });
318
- pi.on("session_shutdown", () => { lifecycleGeneration++; clear(); options.budget.clear(); sessionActive = false; });
382
+ pi.on("session_start", () => { lifecycleGeneration++; clear(false); sessionActive = true; });
383
+ pi.on("session_tree", () => { lifecycleGeneration++; clear(false); });
384
+ pi.on("session_shutdown", () => { lifecycleGeneration++; clear(false); options.budget.clear(); sessionActive = false; });
319
385
 
320
386
  return {
321
- command(windowId: string, continueAfterReset: boolean) {
322
- const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset });
387
+ command(windowId: string, continueAfterReset: boolean, input?: CarriedInput) {
388
+ const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset, ...(input !== undefined ? { input } : {}) });
323
389
  control = decision.state;
390
+ if (decision.effect === "close-out-armed") commandId = randomUUID();
324
391
  return decision.effect;
325
392
  },
326
393
  request(windowId: string, lastWord?: string) {
@@ -6,9 +6,9 @@ import { registerBudget } from "./budget.js";
6
6
  import { output } from "./tool-result.js";
7
7
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
8
8
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
- import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
10
- import { BOOT_TYPE, MANUAL_WIPE_TYPE, RESET_LAST_WORD_TYPE } from "./entries.js";
11
- import { warningContent } from "./text.js";
9
+ import { buildResetDrafts, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
10
+ import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
11
+ import { commandWarningContent } from "./text.js";
12
12
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
13
13
  import { nextHistorySeq } from "./history.js";
14
14
  import { errorMessage } from "../../src/error-message.js";
@@ -72,11 +72,10 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
72
72
  const marker = branch.find((entry): entry is WindowMarker => isWindowMarker(entry) && entry.data.windowId === windowId);
73
73
  if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId)) continue;
74
74
  pendingResetNotices.delete(windowId);
75
- const tail = branch.slice(branch.indexOf(marker) + 1);
76
- const lastWordEntry = tail.find((entry) => (entry as { customType?: string }).customType === RESET_LAST_WORD_TYPE) as { content?: string } | undefined;
77
- const lastWord = lastWordEntry?.content?.startsWith(LAST_WORD_PREFIX) ? lastWordEntry.content.slice(LAST_WORD_PREFIX.length) : undefined;
75
+ // The last word already lands as its own visible sticky-note entry; the
76
+ // committed notice stays a one-line marker instead of repeating it.
78
77
  const forced = markerResetOrigin(marker) === "forced";
79
- ctx.ui.notify(`๐Ÿฅฃ Brain emptied${forced ? " forcibly: overflow" : ""}${lastWord ? ` ยท last word: โ€œ${lastWord}โ€` : ""}`, forced ? "warning" : "info");
78
+ ctx.ui.notify(forced ? "๐Ÿฅฃ Brain forcibly emptied: overflow" : "๐Ÿฅฃ Fresh brain", forced ? "warning" : "info");
80
79
  }
81
80
  };
82
81
  pi.on("turn_start", (_event, ctx) => notifyCommittedResets(ctx));
@@ -183,15 +182,15 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
183
182
  // Manual wipes close out at settlement, then stop or continue with the prompt. The hidden warning goes out in both cases โ€” triggered when idle,
184
183
  // steered into the running turn when busy โ€” so the agent closes out promptly
185
184
  // instead of the reset waiting for the whole run.
186
- const prompt = args.trim() || undefined;
187
- const armed = resets.command(requestedWindowId, prompt !== undefined);
185
+ const prompt = args.trim() ? args : undefined;
186
+ const armed = resets.command(requestedWindowId, prompt !== undefined, prompt);
188
187
  if (armed === "already-pending") {
189
188
  cmdCtx.ui.notify("๐Ÿฅฃ Brain already being emptied", "info");
190
189
  return;
191
190
  }
192
191
  cmdCtx.ui.notify("๐Ÿฅฃ Brain being emptied", "info");
193
192
  try {
194
- pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: warningContent(prompt ? `/empty ${prompt}` : undefined), display: false }, { triggerTurn: true, deliverAs: "steer" });
193
+ pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: commandWarningContent(prompt !== undefined ? `/empty ${prompt}` : undefined), display: false }, { triggerTurn: true, deliverAs: "steer" });
195
194
  } catch (error) {
196
195
  resets.clear();
197
196
  cmdCtx.ui.notify(`๐Ÿฅฃ Brain refused to empty: ${errorMessage(error)}`, "error");
@@ -6,30 +6,30 @@ import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WA
6
6
  * view intact must not carry these โ€” the claim would be false there. The bare `empty_brain` token
7
7
  * is interpolated by renderProtocolBlock; the prose itself stays plain English.
8
8
  */
9
- export const PI_PRE_RESET_HINTS = `Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation after the reset.
9
+ export const PI_PRE_RESET_HINTS = `Anything you say here is erased with the reset โ€” the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.
10
10
  Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
11
11
 
12
12
  /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
13
13
  export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
14
14
 
15
- /**
16
- * With a prompt attached the close-out is an order rather than a nudge: the human already
17
- * said when to reset, and a task line for the next window just preceded it. Only Pi has a
18
- * reset command that takes a prompt, so this lives with the Pi text.
19
- */
20
- export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away โ€” do not wait to be cut off.";
21
-
22
- /**
23
- * The human typed `/empty <prompt>`: the raw command line leads the close-out so the
24
- * closing model sees what the next window was asked to do, verbatim. The tag names it as the
25
- * next window's prompt, so no prose has to explain that.
26
- */
15
+ /** The closing model sees deferred input as a bare next-window prompt block. */
27
16
  export function promptBlock(commandLine: string): string {
28
17
  return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
29
18
  }
30
19
 
31
- /** The hidden checkpoint text for Pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
32
- export function warningContent(commandLine?: string): string {
33
- const closeOut = commandLine ? `${promptBlock(commandLine)}\n${WARNING_CALL_PROMPTED}` : WARNING_CALL;
34
- return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${closeOut}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
20
+ /** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
21
+ export function warningContent(): string {
22
+ return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${WARNING_CALL}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
23
+ }
24
+
25
+ /** Approved manual close-out notices; both variants live here. */
26
+ export const COMMAND_NOTICE = {
27
+ prompted: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward โ€” put the handoff in your notes. The prompt below, and anything the human sends from now on, should be handled after the reset.",
28
+ bare: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward โ€” put the handoff in your notes. Anything the human sends from now on should be handled after the reset.",
29
+ };
30
+
31
+ /** Manual orders omit budget timing hints; deferred work sits outside the notice. */
32
+ export function commandWarningContent(commandLine?: string): string {
33
+ const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
34
+ return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
35
35
  }