notesoup 0.57.0 → 0.57.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.
- package/dist/plugins/pi/entries.d.ts +0 -1
- package/dist/plugins/pi/entries.js +0 -1
- package/dist/plugins/pi/reset/lifecycle.d.ts +6 -2
- package/dist/plugins/pi/reset/lifecycle.js +26 -40
- package/dist/plugins/pi/runtime.js +11 -4
- package/dist/plugins/pi/text.d.ts +0 -2
- package/dist/plugins/pi/text.js +1 -5
- package/dist/test/agent-loop.test.js +158 -88
- package/dist/test/marker.test.js +1 -1
- package/dist/test/model-facing-text.test.js +2 -3
- package/dist/test/reset-lifecycle.test.js +62 -6
- package/docs/reset-lifecycle.md +13 -12
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pi/entries.ts +0 -1
- package/plugins/pi/reset/lifecycle.ts +29 -42
- package/plugins/pi/runtime.ts +11 -4
- package/plugins/pi/text.ts +1 -6
|
@@ -6,5 +6,4 @@ export declare const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
|
6
6
|
export declare const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
7
|
export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
8
8
|
export declare const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
|
-
export declare const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
10
9
|
export declare const MARKER_TYPE = "notesoup/marker";
|
|
@@ -6,5 +6,4 @@ 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
8
|
export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
|
-
export const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
10
9
|
export const MARKER_TYPE = "notesoup/marker";
|
|
@@ -25,6 +25,7 @@ export type ResetRequest = {
|
|
|
25
25
|
};
|
|
26
26
|
readonly tool?: {
|
|
27
27
|
readonly lastWord?: string;
|
|
28
|
+
readonly terminate?: boolean;
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
|
|
@@ -68,6 +69,7 @@ export type ResetControlEvent = {
|
|
|
68
69
|
readonly type: "tool_request";
|
|
69
70
|
readonly windowId: string;
|
|
70
71
|
readonly lastWord?: string;
|
|
72
|
+
readonly terminate?: boolean;
|
|
71
73
|
} | {
|
|
72
74
|
readonly type: "turn_end";
|
|
73
75
|
readonly facts: ResetTurnEndFacts;
|
|
@@ -76,15 +78,17 @@ export type ResetControlEvent = {
|
|
|
76
78
|
readonly facts: ResetBeforeSettleFacts;
|
|
77
79
|
};
|
|
78
80
|
/** Construction intent, not final state: handled inputs can still arrive while notes load. Only `turn-end`
|
|
79
|
-
* may latch a stop; overflow kinds spend recovery; only
|
|
81
|
+
* may latch a stop; overflow kinds spend recovery; only hard-reserve and overflow carry passive run inputs. */
|
|
80
82
|
export interface ResetBoundaryIntent {
|
|
81
83
|
readonly effect: "build-boundary";
|
|
82
84
|
readonly boundary: "turn-end" | "settle" | "command-overflow" | "overflow-recovery";
|
|
83
85
|
readonly windowId: string;
|
|
84
86
|
readonly continueAfterReset: boolean;
|
|
85
87
|
readonly origin: ResetOrigin;
|
|
88
|
+
readonly carryRunInputs?: boolean;
|
|
86
89
|
readonly tool?: {
|
|
87
90
|
readonly lastWord?: string;
|
|
91
|
+
readonly terminate?: boolean;
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
export type ResetControlResult = ResetBoundaryIntent | {
|
|
@@ -111,7 +115,7 @@ export declare function reduceResetControl(state: ResetControlState, event: Rese
|
|
|
111
115
|
*/
|
|
112
116
|
export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
|
|
113
117
|
command(windowId: string, continueAfterReset: boolean, input?: CarriedInput): "none" | "stop" | "close-out-armed" | "already-pending";
|
|
114
|
-
request(windowId: string, lastWord?: string): "rollover_already_pending" | "rollover_requested";
|
|
118
|
+
request(windowId: string, lastWord?: string, terminate?: boolean): "rollover_already_pending" | "rollover_requested";
|
|
115
119
|
clear: (preserveInputs?: boolean) => void;
|
|
116
120
|
};
|
|
117
121
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
|
|
3
2
|
import { currentReset, currentWindowId } from "../window.js";
|
|
4
3
|
import { nextHistorySeq } from "../history.js";
|
|
@@ -6,8 +5,6 @@ import { buildMarkerDraft } from "../marker.js";
|
|
|
6
5
|
import { resetBoundaryCommitted } from "./committed.js";
|
|
7
6
|
import { errorMessage } from "../../../src/error-message.js";
|
|
8
7
|
import { carriedInputDrafts, isCarriedInputEntry } from "./artifacts.js";
|
|
9
|
-
import { NEXT_WINDOW_PROMPT_TYPE } from "../entries.js";
|
|
10
|
-
import { promptBlock } from "../text.js";
|
|
11
8
|
function isAbort(message, outcome, ctx) {
|
|
12
9
|
return outcome === "aborted" || (message.role === "assistant" && message.stopReason === "aborted") || ctx.signal?.aborted === true;
|
|
13
10
|
}
|
|
@@ -25,15 +22,15 @@ function requestForWindow(request, windowId) {
|
|
|
25
22
|
return request.phase === "pending" && request.windowId === windowId ? request : NO_REQUEST;
|
|
26
23
|
}
|
|
27
24
|
const spendsOverflow = (boundary) => boundary === "command-overflow" || boundary === "overflow-recovery";
|
|
28
|
-
function boundaryIntent(request, windowId, boundary) {
|
|
25
|
+
function boundaryIntent(request, windowId, boundary, carryRunInputs = false) {
|
|
29
26
|
const tool = request.phase === "none" ? undefined : request.tool;
|
|
30
|
-
const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ??
|
|
31
|
-
return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal" };
|
|
27
|
+
const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? !request.tool?.terminate : true;
|
|
28
|
+
return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal", ...(carryRunInputs ? { carryRunInputs: true } : {}) };
|
|
32
29
|
}
|
|
33
30
|
/** Resolve once, after a successful current build. No delivery policy is left to the adapter. */
|
|
34
31
|
export function finalizeResetBoundary(intent, request, passiveInputs = []) {
|
|
35
32
|
const inputs = request.phase === "pending" && request.command ? request.command.inputs ?? []
|
|
36
|
-
: intent.boundary === "overflow-recovery" ? passiveInputs : [];
|
|
33
|
+
: intent.boundary === "overflow-recovery" || intent.carryRunInputs ? passiveInputs : [];
|
|
37
34
|
const resumeModel = intent.continueAfterReset || inputs.length > 0;
|
|
38
35
|
const state = {
|
|
39
36
|
request: NO_REQUEST,
|
|
@@ -64,7 +61,10 @@ export function reduceResetControl(state, event) {
|
|
|
64
61
|
// The call remains a real request even when command policy delays its commit.
|
|
65
62
|
const duplicate = request.tool !== undefined;
|
|
66
63
|
const lastWord = request.tool?.lastWord ?? event.lastWord;
|
|
67
|
-
const tool = duplicate && !request.command ? request.tool :
|
|
64
|
+
const tool = duplicate && !request.command ? request.tool : {
|
|
65
|
+
...(lastWord ? { lastWord } : {}),
|
|
66
|
+
...((duplicate ? request.tool?.terminate : event.terminate) ? { terminate: true } : {}),
|
|
67
|
+
};
|
|
68
68
|
return { state: { ...state, request: { ...request, tool } }, effect: duplicate ? "already-pending" : "close-out-armed" };
|
|
69
69
|
}
|
|
70
70
|
case "turn_end": {
|
|
@@ -90,8 +90,9 @@ export function reduceResetControl(state, event) {
|
|
|
90
90
|
}
|
|
91
91
|
// A direct tool request commits after the whole tool batch. The budget cutoff is
|
|
92
92
|
// a separate hard-reserve safety path; ordinary close-out waits for settlement.
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
const toolReset = request.phase === "pending" && request.tool !== undefined;
|
|
94
|
+
if ((toolReset && !manual) || facts.hardReserveDue) {
|
|
95
|
+
return boundaryIntent(request, facts.windowId, "turn-end", !manual && !toolReset && facts.hardReserveDue);
|
|
95
96
|
}
|
|
96
97
|
return { state: { request, overflow: "idle" }, effect: "none" };
|
|
97
98
|
}
|
|
@@ -146,17 +147,16 @@ export function registerResetLifecycle(pi, options) {
|
|
|
146
147
|
let lifecycleGeneration = 0;
|
|
147
148
|
let control = initialResetControl();
|
|
148
149
|
let runInputs = [];
|
|
149
|
-
let commandId;
|
|
150
150
|
// Once input returns handled, Pi no longer owns its original content. If close-out
|
|
151
|
-
// fails/cancels,
|
|
152
|
-
const restoreCommandInputs = () => {
|
|
151
|
+
// fails/cancels, restore it; only an ordinary error starts a turn to answer it.
|
|
152
|
+
const restoreCommandInputs = (triggerTurn = false) => {
|
|
153
153
|
const request = control.request;
|
|
154
154
|
if (request.phase !== "pending" || !request.command?.inputs?.length)
|
|
155
155
|
return;
|
|
156
156
|
const inputs = request.command.inputs;
|
|
157
157
|
control = { ...control, request: { ...request, command: { ...request.command, inputs: [] } } };
|
|
158
158
|
for (const draft of carriedInputDrafts(inputs)) {
|
|
159
|
-
pi.sendMessage(draft, { triggerTurn
|
|
159
|
+
pi.sendMessage(draft, { triggerTurn });
|
|
160
160
|
}
|
|
161
161
|
runInputs.push(...inputs);
|
|
162
162
|
};
|
|
@@ -166,11 +166,9 @@ export function registerResetLifecycle(pi, options) {
|
|
|
166
166
|
restoreCommandInputs();
|
|
167
167
|
control = initialResetControl();
|
|
168
168
|
runInputs = [];
|
|
169
|
-
commandId = undefined;
|
|
170
169
|
};
|
|
171
170
|
const resetBoundaryResult = async (entries, ctx, intent) => {
|
|
172
|
-
// Keep command state live while notes load
|
|
173
|
-
// join this very boundary even if its steer cannot reach the closing model.
|
|
171
|
+
// Keep command state live while notes load so input arriving during this await joins this boundary.
|
|
174
172
|
const generation = lifecycleGeneration;
|
|
175
173
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
176
174
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -213,37 +211,22 @@ export function registerResetLifecycle(pi, options) {
|
|
|
213
211
|
? [{ type: "text", text: event.text }, ...event.images]
|
|
214
212
|
: event.text;
|
|
215
213
|
control = reduceResetControl(control, { type: "input", windowId: request.windowId, input: content }).state;
|
|
216
|
-
const steerContent = event.images?.length
|
|
217
|
-
? [{ type: "text", text: promptBlock(event.text) }, ...event.images]
|
|
218
|
-
: promptBlock(event.text);
|
|
219
|
-
pi.sendMessage({ customType: NEXT_WINDOW_PROMPT_TYPE, content: steerContent, display: false, details: { windowId: request.windowId, commandId } }, { deliverAs: "steer" });
|
|
220
214
|
return { action: "handled" };
|
|
221
215
|
});
|
|
222
216
|
// Boundary continue:false is not a veto of Pi's tool-batch follow-up. Once the
|
|
223
217
|
// safety reset is actually committed, cancel that empty follow-up before provider
|
|
224
218
|
// work. Real queued user input is allowed through and answered before settlement.
|
|
225
219
|
pi.on("context_with_system", (event, ctx) => {
|
|
226
|
-
const request = control.request;
|
|
227
|
-
// Steering can be queued during buildReset's await and arrive after the boundary.
|
|
228
|
-
// It is closing-model context only; originals already live in the carried entries.
|
|
229
|
-
const messages = event.messages.filter((message) => {
|
|
230
|
-
if (message.role !== "custom" || message.customType !== NEXT_WINDOW_PROMPT_TYPE)
|
|
231
|
-
return true;
|
|
232
|
-
const details = message.details;
|
|
233
|
-
return request.phase === "pending" && request.command !== undefined &&
|
|
234
|
-
request.windowId === currentWindowId(ctx) && details?.windowId === request.windowId && commandId !== undefined && details?.commandId === commandId;
|
|
235
|
-
});
|
|
236
|
-
const filtered = messages.length === event.messages.length ? undefined : { messages };
|
|
237
220
|
const stop = control.stopAfterReset;
|
|
238
221
|
if (!sessionActive || !stop || ctx.hasPendingMessages())
|
|
239
|
-
return
|
|
222
|
+
return undefined;
|
|
240
223
|
const marker = currentReset(ctx);
|
|
241
224
|
if (!marker || marker.data.windowId === stop.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId))
|
|
242
|
-
return
|
|
225
|
+
return undefined;
|
|
243
226
|
const branch = ctx.sessionManager.getBranch();
|
|
244
227
|
const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
|
|
245
228
|
if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry)))
|
|
246
|
-
return
|
|
229
|
+
return undefined;
|
|
247
230
|
ctx.abort();
|
|
248
231
|
const system = getCurrentSystemMessage(event.messages);
|
|
249
232
|
return { messages: system ? [system] : [] };
|
|
@@ -270,9 +253,14 @@ export function registerResetLifecycle(pi, options) {
|
|
|
270
253
|
});
|
|
271
254
|
if (decision.effect === "build-boundary")
|
|
272
255
|
return await resetBoundaryResult(entries, ctx, decision);
|
|
273
|
-
if (aborted
|
|
256
|
+
if (aborted)
|
|
274
257
|
restoreCommandInputs();
|
|
258
|
+
else if (event.outcome === "error" && decision.state.request.phase === "none")
|
|
259
|
+
restoreCommandInputs(true);
|
|
275
260
|
control = decision.state;
|
|
261
|
+
if (!aborted && event.outcome === "completed" && event.message.role === "assistant" && event.message.stopReason === "stop" &&
|
|
262
|
+
event.context.pendingMessages.length === 0 && !ctx.hasPendingMessages())
|
|
263
|
+
runInputs = [];
|
|
276
264
|
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
277
265
|
const marker = buildMarkerDraft(ctx, entries);
|
|
278
266
|
if (marker)
|
|
@@ -331,12 +319,10 @@ export function registerResetLifecycle(pi, options) {
|
|
|
331
319
|
command(windowId, continueAfterReset, input) {
|
|
332
320
|
const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset, ...(input !== undefined ? { input } : {}) });
|
|
333
321
|
control = decision.state;
|
|
334
|
-
if (decision.effect === "close-out-armed")
|
|
335
|
-
commandId = randomUUID();
|
|
336
322
|
return decision.effect;
|
|
337
323
|
},
|
|
338
|
-
request(windowId, lastWord) {
|
|
339
|
-
const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
|
|
324
|
+
request(windowId, lastWord, terminate = false) {
|
|
325
|
+
const decision = reduceResetControl(control, { type: "tool_request", windowId, terminate, ...(lastWord ? { lastWord } : {}) });
|
|
340
326
|
control = decision.state;
|
|
341
327
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
342
328
|
},
|
|
@@ -3,7 +3,7 @@ import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
|
3
3
|
import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
|
|
4
4
|
import { VERSION, defineTool } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { registerBudget } from "./budget.js";
|
|
6
|
-
import { output } from "./tool-result.js";
|
|
6
|
+
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
|
|
7
7
|
import { emptyBrainRenderers } from "./render.js";
|
|
8
8
|
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
|
|
9
9
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
@@ -26,6 +26,9 @@ function readPackageVersion() {
|
|
|
26
26
|
return "dev";
|
|
27
27
|
}
|
|
28
28
|
const buildLabel = `v${readPackageVersion()}`;
|
|
29
|
+
const notesoupTools = [NOTES_NAMESPACE, HISTORY_NAMESPACE, DREAM_NAMESPACE]
|
|
30
|
+
.map(({ name, description }) => `${name}: ${description}`)
|
|
31
|
+
.join("\n") + "\nDiscover deferred tools through codemode or tool_search when available.";
|
|
29
32
|
function branchHasWindowMarker(ctx, fromId) {
|
|
30
33
|
return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
|
|
31
34
|
}
|
|
@@ -78,7 +81,8 @@ export function registerContext(pi, settingsManager) {
|
|
|
78
81
|
ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
|
-
pi.on("before_agent_start", (
|
|
84
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
85
|
+
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
82
86
|
if (enabled)
|
|
83
87
|
maybeSendMarker(pi, ctx);
|
|
84
88
|
});
|
|
@@ -212,7 +216,10 @@ export function registerContext(pi, settingsManager) {
|
|
|
212
216
|
name: "empty_brain",
|
|
213
217
|
label: "Empty Brain",
|
|
214
218
|
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.",
|
|
215
|
-
parameters: Type.Object({
|
|
219
|
+
parameters: Type.Object({
|
|
220
|
+
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.` })),
|
|
221
|
+
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
|
|
222
|
+
}, { additionalProperties: false }),
|
|
216
223
|
renderCall: emptyBrainRenderers.renderCall,
|
|
217
224
|
renderResult: emptyBrainRenderers.renderResult,
|
|
218
225
|
async execute(_id, params, _signal, _update, ctx) {
|
|
@@ -222,7 +229,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
222
229
|
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
223
230
|
if (length > MAX_LAST_WORD_CHARS)
|
|
224
231
|
return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
|
|
225
|
-
return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
|
|
232
|
+
return output({ status: resets.request(currentWindowId(ctx), lastWord, params.terminate) }, undefined, true);
|
|
226
233
|
},
|
|
227
234
|
}));
|
|
228
235
|
const resets = registerResetLifecycle(pi, {
|
|
@@ -8,8 +8,6 @@ export declare const PI_PRE_RESET_HINTS = "Anything you say here is erased with
|
|
|
8
8
|
export { warningNotice as warningContent } from "../../src/budget/text.js";
|
|
9
9
|
/** Odometer breadcrumb: the marker names its own seq, so history paging reads the landscape directly. */
|
|
10
10
|
export declare function markerContent(seq: number): string;
|
|
11
|
-
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
12
|
-
export declare function promptBlock(commandLine: string): string;
|
|
13
11
|
/** Approved manual close-out notices; both variants live here. */
|
|
14
12
|
export declare const COMMAND_NOTICE: {
|
|
15
13
|
prompted: string;
|
package/dist/plugins/pi/text.js
CHANGED
|
@@ -12,10 +12,6 @@ export { warningNotice as warningContent } from "../../src/budget/text.js";
|
|
|
12
12
|
export function markerContent(seq) {
|
|
13
13
|
return `<notesoup:marker seq="${seq}" />`;
|
|
14
14
|
}
|
|
15
|
-
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
16
|
-
export function promptBlock(commandLine) {
|
|
17
|
-
return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
|
|
18
|
-
}
|
|
19
15
|
/** Approved manual close-out notices; both variants live here. */
|
|
20
16
|
export const COMMAND_NOTICE = {
|
|
21
17
|
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 command below is context for your notes, not a task for the fresh window. Anything the human sends separately from now on should be handled after the reset.",
|
|
@@ -24,5 +20,5 @@ export const COMMAND_NOTICE = {
|
|
|
24
20
|
/** Manual orders omit budget timing hints; deferred work sits outside the notice. */
|
|
25
21
|
export function commandWarningContent(commandLine) {
|
|
26
22
|
const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
|
|
27
|
-
return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${
|
|
23
|
+
return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${commandLine}` : ""}`;
|
|
28
24
|
}
|
|
@@ -6,16 +6,14 @@ import test from "node:test";
|
|
|
6
6
|
import { createAssistantMessageEventStream, getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
7
7
|
import { createAgentSession, createCodemodeExtension, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import notesoup, { createNotesoup } from "../plugins/pi/extension.js";
|
|
9
|
-
import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE,
|
|
9
|
+
import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
|
|
10
10
|
import { historyFromSession } from "../plugins/pi/history.js";
|
|
11
11
|
import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
|
|
12
12
|
import { assertBootHistory } from "./helpers/extension.js";
|
|
13
13
|
import { NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_OPEN_TAG } from "../src/boot/text.js";
|
|
14
14
|
import { FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
|
|
15
|
-
import { commandWarningContent
|
|
16
|
-
import {
|
|
17
|
-
import { buildResetDrafts } from "../plugins/pi/reset/artifacts.js";
|
|
18
|
-
import { currentWindowId } from "../plugins/pi/window.js";
|
|
15
|
+
import { commandWarningContent } from "../plugins/pi/text.js";
|
|
16
|
+
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE } from "../plugins/pi/tool-result.js";
|
|
19
17
|
async function openFixture(options) {
|
|
20
18
|
const dir = options.cwd ?? mkdtempSync(join(tmpdir(), "notesoup-agent-loop-"));
|
|
21
19
|
const ownsDir = options.cwd === undefined;
|
|
@@ -278,6 +276,49 @@ test("real AgentSession: turn-end markers reach tool continuations and allow one
|
|
|
278
276
|
}
|
|
279
277
|
}
|
|
280
278
|
});
|
|
279
|
+
test("real AgentSession: notesoup tool directory is a stable system section across requests and reset", async () => {
|
|
280
|
+
let fixture;
|
|
281
|
+
let directory;
|
|
282
|
+
const activeTools = ["empty_brain", "get_context_remaining", "notes_write"];
|
|
283
|
+
const namespaces = [NOTES_NAMESPACE, HISTORY_NAMESPACE, DREAM_NAMESPACE];
|
|
284
|
+
fixture = await openFixture({
|
|
285
|
+
compactionEnabled: false,
|
|
286
|
+
tools: activeTools,
|
|
287
|
+
hook: (pi) => pi.on("before_agent_start", (event) => {
|
|
288
|
+
event.systemPromptOptions.sections.host_context = "Host-owned context";
|
|
289
|
+
}),
|
|
290
|
+
script: (request, context) => {
|
|
291
|
+
const system = getCurrentSystemMessage(context.messages);
|
|
292
|
+
const section = system?.sections?.notesoup_tools;
|
|
293
|
+
assert.equal(typeof section, "string", "the directory reaches the model as a named system section");
|
|
294
|
+
for (const { name, description } of namespaces)
|
|
295
|
+
assert.ok(section.includes(`${name}: ${description}`));
|
|
296
|
+
assert.ok(system?.sections?.preamble?.includes("Use the tools as requested."), "the host prompt is preserved");
|
|
297
|
+
assert.ok(system?.sections?.host_context?.includes("Host-owned context"), "other sections are preserved");
|
|
298
|
+
assert.deepEqual(system?.toolsAdded?.map((tool) => tool.name).sort(), activeTools, "discovery does not activate tools");
|
|
299
|
+
if (directory === undefined)
|
|
300
|
+
directory = section;
|
|
301
|
+
else
|
|
302
|
+
assert.equal(section, directory, "the directory is unchanged across requests and reset");
|
|
303
|
+
assert.equal(context.messages.filter((message) => message.role === "system" && message.sections?.notesoup_tools !== undefined).length, 1, "unchanged content adds no section delta");
|
|
304
|
+
return request === 2
|
|
305
|
+
? assistant(fixture, [{ type: "toolCall", id: "directory-reset", name: "empty_brain", arguments: {} }], "toolUse")
|
|
306
|
+
: assistant(fixture, [{ type: "text", text: "directory available" }]);
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
try {
|
|
310
|
+
await fixture.session.prompt("Read the directory.");
|
|
311
|
+
await fixture.session.waitForIdle();
|
|
312
|
+
await fixture.session.prompt("DIRECTORY_RESET_SENTINEL");
|
|
313
|
+
await fixture.session.waitForIdle();
|
|
314
|
+
assert.equal(fixture.requests.length, 3, "two prompts and one reset continuation");
|
|
315
|
+
assert.equal(resetMarkers(fixture).length, 1);
|
|
316
|
+
assertFreshRequest(fixture, 2, "DIRECTORY_RESET_SENTINEL");
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
fixture.close();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
281
322
|
test("real Pi codemode receives typed notes/history outcomes, including expected errors", async () => {
|
|
282
323
|
let fixture;
|
|
283
324
|
fixture = await openFixture({
|
|
@@ -509,6 +550,60 @@ test("real AgentSession: explicit tiny-session wipe ignores keepRecentTokens and
|
|
|
509
550
|
fixture.close();
|
|
510
551
|
}
|
|
511
552
|
});
|
|
553
|
+
test("real AgentSession: terminate wipes and stops, including a mixed tool batch, without closing the session", async () => {
|
|
554
|
+
for (const mixedBatch of [false, true]) {
|
|
555
|
+
let fixture;
|
|
556
|
+
fixture = await openFixture({
|
|
557
|
+
compactionEnabled: false,
|
|
558
|
+
script: (request) => request === 1
|
|
559
|
+
? assistant(fixture, [
|
|
560
|
+
{ type: "toolCall", id: "wipe-stop", name: "empty_brain", arguments: { terminate: true, last_word: "saved for later" } },
|
|
561
|
+
...(mixedBatch ? [{ type: "toolCall", id: "remaining", name: "get_context_remaining", arguments: {} }] : []),
|
|
562
|
+
], "toolUse")
|
|
563
|
+
: assistant(fixture, [{ type: "text", text: "answering new input" }]),
|
|
564
|
+
});
|
|
565
|
+
try {
|
|
566
|
+
await fixture.session.prompt("TERMINATE_OLD_CONTEXT");
|
|
567
|
+
await fixture.session.waitForIdle();
|
|
568
|
+
assert.equal(fixture.requests.length, 1, "no automatic provider request after wiping");
|
|
569
|
+
assert.equal(resetMarkers(fixture).length, 1);
|
|
570
|
+
assert.ok(fixture.sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE));
|
|
571
|
+
await fixture.session.prompt("A new task");
|
|
572
|
+
await fixture.session.waitForIdle();
|
|
573
|
+
assert.equal(fixture.requests.length, 2, "new user input still runs");
|
|
574
|
+
assertFreshRequest(fixture, 1, "TERMINATE_OLD_CONTEXT");
|
|
575
|
+
assert.ok(text(fixture.requests[1]).includes("saved for later"));
|
|
576
|
+
}
|
|
577
|
+
finally {
|
|
578
|
+
fixture.close();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
test("real AgentSession: a model-requested reset does not carry its original text-and-image prompt", async () => {
|
|
583
|
+
let fixture;
|
|
584
|
+
const input = "IMAGE_RESET_UNANSWERED: describe this image";
|
|
585
|
+
const image = { type: "image", data: "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAAn0lEQVRoge2SQQkAQRDD6qSOT20ErIh7hIFCBKSh4etpohuwAdUrsgv1LtEN2IDqFdmFepfoBmxA9YrsQr1LdAM2oHpFdqHeJboBG1C9IrtQ7xLdgA2oXpFdqHeJbsAGVK/ILtS7RDdgA6pXZBfqXaIbsAHVK7IL9S7RDdiA6hXZhXqX6AZsQPWK7EK9S3QDNqB6RXah3iW6ARtQveIfHlqMEYdT3J7gAAAAAElFTkSuQmCC", mimeType: "image/png" };
|
|
586
|
+
fixture = await openFixture({
|
|
587
|
+
compactionEnabled: false,
|
|
588
|
+
script: (request, context) => {
|
|
589
|
+
if (request === 1)
|
|
590
|
+
return assistant(fixture, [{ type: "toolCall", id: "wipe-image-input", name: "empty_brain", arguments: {} }], "toolUse");
|
|
591
|
+
assert.equal(request, 2);
|
|
592
|
+
assert.equal(JSON.stringify(context.messages).includes(input) || JSON.stringify(context.messages).includes(image.data), false, "the model-requested reset does not replay the input it already received");
|
|
593
|
+
return assistant(fixture, [{ type: "text", text: "image prompt answered" }]);
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
try {
|
|
597
|
+
await fixture.session.prompt(input, { images: [image] });
|
|
598
|
+
await fixture.session.waitForIdle();
|
|
599
|
+
assert.equal(fixture.requests.length, 2);
|
|
600
|
+
const carried = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE);
|
|
601
|
+
assert.equal(carried.length, 0, "a model-requested reset owns its handoff through notes and last_word");
|
|
602
|
+
}
|
|
603
|
+
finally {
|
|
604
|
+
fixture.close();
|
|
605
|
+
}
|
|
606
|
+
});
|
|
512
607
|
test("real AgentSession: manual command spans its tool batch and stops at settlement", async () => {
|
|
513
608
|
let fixture;
|
|
514
609
|
fixture = await openFixture({
|
|
@@ -566,7 +661,7 @@ test("real AgentSession: /empty text is close-out context and stops after reset"
|
|
|
566
661
|
if (request === 1)
|
|
567
662
|
return assistant(fixture, [{ type: "text", text: "initial work" }]);
|
|
568
663
|
if (request === 2) {
|
|
569
|
-
assert.ok(text(context).includes(JSON.stringify(
|
|
664
|
+
assert.ok(text(context).includes(JSON.stringify(`/empty ${prompt}`).slice(1, -1)));
|
|
570
665
|
return assistant(fixture, [{ type: "toolCall", id: "prompt-wipe", name: "empty_brain", arguments: { last_word: "saved" } }], "toolUse");
|
|
571
666
|
}
|
|
572
667
|
throw new Error("command argument must not start fresh-window work");
|
|
@@ -624,7 +719,7 @@ test("real AgentSession: streaming clear prompt keeps the first request", async
|
|
|
624
719
|
// The close-out embeds the human's command line verbatim, so the closing turn sees
|
|
625
720
|
// the command context. Only the accepted command appears.
|
|
626
721
|
if (request === 2) {
|
|
627
|
-
assert.ok(text(context).includes(JSON.stringify(
|
|
722
|
+
assert.ok(text(context).includes(JSON.stringify("/fresh-window FIRST_RESET_PROMPT").slice(1, -1)), "the close-out carries the original command line as plain text");
|
|
628
723
|
assert.equal(text(context).includes("IGNORED_RESET_PROMPT"), false, "the refused repeat never enters the close-out");
|
|
629
724
|
}
|
|
630
725
|
assert.ok(request <= 2);
|
|
@@ -649,6 +744,31 @@ test("real AgentSession: streaming clear prompt keeps the first request", async
|
|
|
649
744
|
fixture.close();
|
|
650
745
|
}
|
|
651
746
|
});
|
|
747
|
+
test("real AgentSession: hard-reserve reset carries the original text and image and continues", async () => {
|
|
748
|
+
let fixture;
|
|
749
|
+
const input = "HARD_RESERVE_IMAGE_INPUT";
|
|
750
|
+
const image = { type: "image", data: "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAAn0lEQVRoge2SQQkAQRDD6qSOT20ErIh7gIFCBKSh4et1LtEN2IDqFdmFepfoBmxA9YrsQr1LdAM2oHpFdqHeJboBG1C9IrtQ7xLdgA2oXpFdqHeJbsAGVK/ILtS7RDdgA6pXZBfqXaIbsAHVK7IL9S7RDdiA6hXZhXqX6AZsQPWK7EK9S3QDNqB6RXah3iW6ARtQveIfHlqMEYdT3J7gAAAAAElFTkSuQmCC", mimeType: "image/png" };
|
|
751
|
+
fixture = await openFixture({
|
|
752
|
+
defaultReserveTokens: 80_000,
|
|
753
|
+
script: (request, context) => {
|
|
754
|
+
if (request === 1)
|
|
755
|
+
return assistant(fixture, [{ type: "text", text: "reserve reached" }], "stop", { usage: usage(80_000) });
|
|
756
|
+
assert.equal(request, 2);
|
|
757
|
+
assertUserContent(context, [{ type: "text", text: input }, image]);
|
|
758
|
+
return assistant(fixture, [{ type: "text", text: "carried image answered" }]);
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
try {
|
|
762
|
+
await fixture.session.prompt(input, { images: [image] });
|
|
763
|
+
await fixture.session.waitForIdle();
|
|
764
|
+
assert.equal(fixture.requests.length, 2);
|
|
765
|
+
assert.equal(resetMarkers(fixture).length, 1);
|
|
766
|
+
assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE).length, 1);
|
|
767
|
+
}
|
|
768
|
+
finally {
|
|
769
|
+
fixture.close();
|
|
770
|
+
}
|
|
771
|
+
});
|
|
652
772
|
test("real AgentSession: manual hard-reserve reset stops clean and mixed-tool turns without fresh provider work", async () => {
|
|
653
773
|
for (const mixed of [false, true]) {
|
|
654
774
|
let fixture;
|
|
@@ -835,98 +955,48 @@ test("real AgentSession: user abort, synthetic aborted response, and generic err
|
|
|
835
955
|
}
|
|
836
956
|
}
|
|
837
957
|
});
|
|
838
|
-
test("real AgentSession: input during prompted /empty is
|
|
958
|
+
test("real AgentSession: input during prompted /empty is carried with images and answered after reset", async () => {
|
|
839
959
|
let fixture;
|
|
840
|
-
let
|
|
841
|
-
let
|
|
842
|
-
const
|
|
843
|
-
const
|
|
960
|
+
let closeoutStarted;
|
|
961
|
+
let releaseCloseout;
|
|
962
|
+
const closeoutReady = new Promise((resolve) => { closeoutStarted = resolve; });
|
|
963
|
+
const closeoutGate = new Promise((resolve) => { releaseCloseout = resolve; });
|
|
844
964
|
const input = "DEFERRED_HUMAN_INPUT\n verbatim";
|
|
845
965
|
const image = { type: "image", data: "aGVsbG8=", mimeType: "image/png" };
|
|
846
966
|
fixture = await openFixture({
|
|
847
967
|
script: async (request, context) => {
|
|
848
968
|
if (request === 1) {
|
|
849
|
-
|
|
850
|
-
await
|
|
851
|
-
|
|
969
|
+
closeoutStarted();
|
|
970
|
+
await closeoutGate;
|
|
971
|
+
assert.ok(text(context).includes(JSON.stringify(commandWarningContent("/empty CLOSE_OUT_CONTEXT")).slice(1, -1)));
|
|
972
|
+
assert.equal(text(context).includes(input), false, "the separate input is not sent to the closing model");
|
|
973
|
+
assert.equal(text(context).includes("next_window_prompt"), false, "no hidden steer reaches the provider");
|
|
974
|
+
return assistant(fixture, [{ type: "text", text: "close-out ready for reset" }], "stop", { usage: usage(80_000) });
|
|
852
975
|
}
|
|
853
|
-
|
|
854
|
-
assertUserContent(context, [{ type: "text", text: promptBlock(input) }, image]);
|
|
855
|
-
return assistant(fixture, [{ type: "toolCall", id: "deferred-pressure", name: "notes_write", arguments: { address: "deferred.md", content: "saved" } }], "toolUse", { usage: usage(80_000) });
|
|
856
|
-
}
|
|
857
|
-
assert.equal(request, 3, "carried input continues despite command stop policy");
|
|
858
|
-
assertFreshRequest(fixture, 2, "saving notes");
|
|
976
|
+
assert.equal(request, 2, "the intercepted input resumes in the fresh window");
|
|
859
977
|
assertUserContent(context, [{ type: "text", text: input }, image]);
|
|
978
|
+
assert.equal(text(context).includes("CLOSE_OUT_CONTEXT"), false, "the fresh window excludes old-window close-out text");
|
|
979
|
+
assert.equal(text(context).includes("next_window_prompt"), false, "the fresh provider request contains no hidden steer");
|
|
860
980
|
return assistant(fixture, [{ type: "text", text: "deferred input answered" }]);
|
|
861
981
|
},
|
|
862
982
|
});
|
|
863
983
|
try {
|
|
864
|
-
const
|
|
865
|
-
await
|
|
984
|
+
const closing = fixture.session.prompt("/empty CLOSE_OUT_CONTEXT");
|
|
985
|
+
await closeoutReady;
|
|
866
986
|
await fixture.session.prompt(input, { images: [image], streamingBehavior: "followUp" });
|
|
867
|
-
|
|
868
|
-
await command;
|
|
869
|
-
await fixture.session.waitForIdle();
|
|
870
|
-
assert.equal(fixture.requests.length, 3);
|
|
871
|
-
assert.equal(resetMarkers(fixture).length, 1);
|
|
872
|
-
const branch = fixture.sessionManager.getBranch();
|
|
873
|
-
const steer = branch.find((entry) => entry.type === "custom_message" && entry.customType === NEXT_WINDOW_PROMPT_TYPE);
|
|
874
|
-
assert.ok(steer?.type === "custom_message");
|
|
875
|
-
assert.equal(steer.display, false);
|
|
876
|
-
assert.deepEqual(steer.content, [{ type: "text", text: promptBlock(input) }, image], "the bare block and original images reach the closing model");
|
|
877
|
-
assert.equal(branch.filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE).length, 1);
|
|
878
|
-
assert.equal(fixture.streamSignals.at(-1), false, "the stop-pending safeguard cannot swallow carried input");
|
|
879
|
-
}
|
|
880
|
-
finally {
|
|
881
|
-
release();
|
|
882
|
-
fixture.close();
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
test("real AgentSession: a hidden steer queued during reset construction is not replayed beside carried input", async () => {
|
|
886
|
-
let fixture;
|
|
887
|
-
let started;
|
|
888
|
-
let release;
|
|
889
|
-
const building = new Promise((resolve) => { started = resolve; });
|
|
890
|
-
const gate = new Promise((resolve) => { release = resolve; });
|
|
891
|
-
const input = "LATE_BUILD_INPUT";
|
|
892
|
-
fixture = await openFixture({
|
|
893
|
-
tools: [],
|
|
894
|
-
extensionFactory: (pi) => {
|
|
895
|
-
const lifecycle = registerResetLifecycle(pi, {
|
|
896
|
-
isEnabled: () => true,
|
|
897
|
-
budget: { automaticResetEnabled: () => false, hardReserveDue: () => false, consumeTurnEnd: () => [], clear() { } },
|
|
898
|
-
async buildReset(ctx, isCurrent, lastWord, firstSeq, origin) {
|
|
899
|
-
started();
|
|
900
|
-
await gate;
|
|
901
|
-
return buildResetDrafts(ctx, undefined, isCurrent, lastWord, firstSeq, origin);
|
|
902
|
-
},
|
|
903
|
-
});
|
|
904
|
-
pi.on("before_agent_start", (_event, ctx) => { lifecycle.command(currentWindowId(ctx), false); });
|
|
905
|
-
},
|
|
906
|
-
script: (request, context) => {
|
|
907
|
-
if (request === 1)
|
|
908
|
-
return assistant(fixture, [{ type: "text", text: "closing old window" }]);
|
|
909
|
-
assert.equal(request, 2);
|
|
910
|
-
assertUserContent(context, [{ type: "text", text: input }]);
|
|
911
|
-
assert.equal(text(context).includes("notesoup:next_window_prompt"), false, "the stale queued steer must not duplicate the carried input");
|
|
912
|
-
return assistant(fixture, [{ type: "text", text: "late input answered" }]);
|
|
913
|
-
},
|
|
914
|
-
});
|
|
915
|
-
try {
|
|
916
|
-
const closing = fixture.session.prompt("close out");
|
|
917
|
-
await building;
|
|
918
|
-
await fixture.session.prompt(input, { streamingBehavior: "steer" });
|
|
919
|
-
release();
|
|
987
|
+
releaseCloseout();
|
|
920
988
|
await closing;
|
|
921
989
|
await fixture.session.waitForIdle();
|
|
922
990
|
assert.equal(fixture.requests.length, 2);
|
|
923
|
-
assert.equal(text(fixture.requests[1]).includes("notesoup:next_window_prompt"), false);
|
|
924
991
|
const branch = fixture.sessionManager.getBranch();
|
|
925
|
-
|
|
926
|
-
assert.
|
|
992
|
+
assert.equal(branch.some((entry) => entry.type === "custom_message" && JSON.stringify(entry).includes("next-window-prompt")), false, "the branch contains no next-window steer");
|
|
993
|
+
assert.equal(resetMarkers(fixture).length, 1, "one reset marker commits at settlement");
|
|
994
|
+
const carried = branch.filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE);
|
|
995
|
+
assert.equal(carried.length, 1);
|
|
996
|
+
assert.deepEqual(carried[0]?.type === "custom_message" ? carried[0].content : undefined, [{ type: "text", text: input }, image]);
|
|
927
997
|
}
|
|
928
998
|
finally {
|
|
929
|
-
|
|
999
|
+
releaseCloseout();
|
|
930
1000
|
fixture.close();
|
|
931
1001
|
}
|
|
932
1002
|
});
|
|
@@ -948,7 +1018,6 @@ test("real AgentSession: abort after handled input preserves originals without f
|
|
|
948
1018
|
}
|
|
949
1019
|
assert.equal(request, 2);
|
|
950
1020
|
assertUserContent(context, original);
|
|
951
|
-
assert.equal(text(context).includes("notesoup:next_window_prompt"), false);
|
|
952
1021
|
return assistant(fixture, [{ type: "text", text: "resumed after abort" }]);
|
|
953
1022
|
},
|
|
954
1023
|
});
|
|
@@ -973,7 +1042,7 @@ test("real AgentSession: abort after handled input preserves originals without f
|
|
|
973
1042
|
fixture.close();
|
|
974
1043
|
}
|
|
975
1044
|
});
|
|
976
|
-
test("real AgentSession: a close-out error
|
|
1045
|
+
test("real AgentSession: a close-out error answers handled input without resetting", async () => {
|
|
977
1046
|
let fixture;
|
|
978
1047
|
let started;
|
|
979
1048
|
let release;
|
|
@@ -989,7 +1058,7 @@ test("real AgentSession: a close-out error does not discard handled input", asyn
|
|
|
989
1058
|
}
|
|
990
1059
|
assert.equal(request, 2);
|
|
991
1060
|
assertUserContent(context, [{ type: "text", text: "ERROR_HANDLED_INPUT" }]);
|
|
992
|
-
assert.equal(text(context).includes("
|
|
1061
|
+
assert.equal(text(context).includes("next_window_prompt"), false, "no hidden steer reaches the provider");
|
|
993
1062
|
return assistant(fixture, [{ type: "text", text: "handled input answered without reset" }]);
|
|
994
1063
|
},
|
|
995
1064
|
});
|
|
@@ -1000,11 +1069,12 @@ test("real AgentSession: a close-out error does not discard handled input", asyn
|
|
|
1000
1069
|
release();
|
|
1001
1070
|
await closing;
|
|
1002
1071
|
await fixture.session.waitForIdle();
|
|
1003
|
-
const originals = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE);
|
|
1004
|
-
assert.equal(originals.length, 1);
|
|
1005
1072
|
assert.equal(fixture.requests.length, 2);
|
|
1006
1073
|
assertUserContent(fixture.requests[1], [{ type: "text", text: "ERROR_HANDLED_INPUT" }]);
|
|
1007
|
-
|
|
1074
|
+
const originals = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE);
|
|
1075
|
+
assert.equal(originals.length, 1, "the failed close-out restores one visible copy");
|
|
1076
|
+
assert.deepEqual(originals[0]?.type === "custom_message" ? originals[0].content : undefined, "ERROR_HANDLED_INPUT");
|
|
1077
|
+
assert.equal(resetMarkers(fixture).length, 0, "ordinary errors do not force a reset");
|
|
1008
1078
|
}
|
|
1009
1079
|
finally {
|
|
1010
1080
|
release();
|
|
@@ -1167,7 +1237,7 @@ test("real AgentSession: two retain-none checkpoints survive session-file reopen
|
|
|
1167
1237
|
assert.equal(branch.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).length, 2);
|
|
1168
1238
|
assert.ok(JSON.stringify(branch).includes("PERSISTED_OLD_WINDOW_SENTINEL"), "raw history survives disk reopen");
|
|
1169
1239
|
const canonical = reopened.buildSessionProjection().messages;
|
|
1170
|
-
assert.equal(JSON.stringify(canonical).includes("PERSISTED_OLD_WINDOW_SENTINEL"), false, "
|
|
1240
|
+
assert.equal(JSON.stringify(canonical).includes("PERSISTED_OLD_WINDOW_SENTINEL"), false, "model-requested resets do not carry the original prompt");
|
|
1171
1241
|
assert.ok(canonical.some((message) => message.role === "compactionSummary"), "the accepted empty-summary wrapper survives reload");
|
|
1172
1242
|
const system = getCurrentSystemMessage(canonical);
|
|
1173
1243
|
assert.ok(JSON.stringify(system).includes("Use the tools as requested."), "the complete system prompt survives the checkpoint");
|
|
@@ -1364,7 +1434,7 @@ test("real AgentSession: overflow and recoverable length reset and retry once; r
|
|
|
1364
1434
|
assert.equal(repeated.sessionManager.getBranch().filter((entry) => entry.type === "compaction").length, 2);
|
|
1365
1435
|
assert.equal(repeated.requests.length, 3, "an automatic continuation still gets only one recovery request");
|
|
1366
1436
|
assertFreshRequest(repeated, 2, "REPEATED_OVERFLOW_SENTINEL");
|
|
1367
|
-
assert.equal(repeated.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE).length, 0, "
|
|
1437
|
+
assert.equal(repeated.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE).length, 0, "model-owned reset and its input-free continuation do not carry the original prompt");
|
|
1368
1438
|
}
|
|
1369
1439
|
finally {
|
|
1370
1440
|
repeated.close();
|
package/dist/test/marker.test.js
CHANGED
|
@@ -10,7 +10,7 @@ test.beforeEach(env.beforeEach);
|
|
|
10
10
|
test.afterEach(env.afterEach);
|
|
11
11
|
test.after(env.dispose);
|
|
12
12
|
function beforeAgentStart(captured, ctx) {
|
|
13
|
-
return runHandlers(captured, "before_agent_start", { type: "before_agent_start" }, ctx);
|
|
13
|
+
return runHandlers(captured, "before_agent_start", { type: "before_agent_start", systemPromptOptions: { sections: {} } }, ctx);
|
|
14
14
|
}
|
|
15
15
|
test("marker stamps its own seq at run start once the interval is reached, never mid-turn", async () => {
|
|
16
16
|
const sessionManager = managerWithMessages(99);
|
|
@@ -98,10 +98,9 @@ test("the countdown closes the second-tier notice only, in both hosts", () => {
|
|
|
98
98
|
assert.equal(CLAUDE_WARNING_PROMPT, pi, "Pi and Claude receive identical copy");
|
|
99
99
|
assert.equal(pi.split(COUNTDOWN_LINE).length - 1, 1, "the second tier carries the countdown exactly once");
|
|
100
100
|
const prompted = commandWarningContent("/empty keep going");
|
|
101
|
-
assert.
|
|
102
|
-
assert.ok(prompted.includes(`\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}\n<notesoup:next_window_prompt>`), "the prompt block follows the closed notice");
|
|
101
|
+
assert.equal(prompted, `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.prompted}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}\n/empty keep going`);
|
|
103
102
|
assert.equal(commandWarningContent(), `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.bare}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`);
|
|
104
|
-
assert.
|
|
103
|
+
assert.ok(prompted.endsWith("\n/empty keep going"), "command text remains plain close-out context");
|
|
105
104
|
assert.equal(prompted.includes(PI_PRE_RESET_HINTS), false, "manual commands own reset timing");
|
|
106
105
|
assert.ok(CLAUDE_WARNING_PROMPT.endsWith(`\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`));
|
|
107
106
|
assert.equal(prompted.includes(WARNING_TIMING), false, "manual requests replace the budget opening");
|
|
@@ -168,6 +168,20 @@ function fakeBoundaryEvent(entries = [], message) {
|
|
|
168
168
|
toolResultEntryIds: [],
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
+
test("tool continuation defaults to true, preserves the first request, and yields to command policy", () => {
|
|
172
|
+
const windowId = "pcw:test:window";
|
|
173
|
+
for (const terminate of [undefined, false, true]) {
|
|
174
|
+
const requested = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, terminate }).state;
|
|
175
|
+
const duplicate = reduceResetControl(requested, { type: "tool_request", windowId, terminate: !terminate }).state;
|
|
176
|
+
const intent = boundaryIntent(reduceResetControl(duplicate, { type: "turn_end", facts: turnEndFacts() }));
|
|
177
|
+
assert.equal(finalizeResetBoundary(intent, duplicate.request).resumeModel, !terminate);
|
|
178
|
+
const commanded = reduceResetControl(requested, { type: "command", windowId, continueAfterReset: false }).state;
|
|
179
|
+
const commandIntent = boundaryIntent(reduceResetControl(commanded, { type: "before_settle", facts: beforeSettleFacts() }));
|
|
180
|
+
assert.equal(finalizeResetBoundary(commandIntent, commanded.request).resumeModel, false);
|
|
181
|
+
const withInput = reduceResetControl(commanded, { type: "input", windowId, input: "new task" }).state;
|
|
182
|
+
assert.equal(finalizeResetBoundary(commandIntent, withInput.request).resumeModel, true);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
171
185
|
test("public reset boundary drafts one marker, one boot, and one continuation after a tool batch", async () => {
|
|
172
186
|
const h = harness();
|
|
173
187
|
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
@@ -196,6 +210,31 @@ test("public reset boundary drafts one marker, one boot, and one continuation af
|
|
|
196
210
|
assert.deepEqual(branch.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).map((entry) => entry.type === "custom" ? entry.data : undefined), [{ windowId, origin: "normal" }], "the boundary records the model's own call");
|
|
197
211
|
assert.equal(branch.filter((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE).length, 1);
|
|
198
212
|
});
|
|
213
|
+
test("hard-reserve reset carries original text and images and continues", async () => {
|
|
214
|
+
const sessionManager = Manager.inMemory("/private/tmp/notesoup-hard-reserve-carry-test");
|
|
215
|
+
const handlers = new Map();
|
|
216
|
+
const api = { on(name, handler) { const list = handlers.get(name) ?? []; list.push(handler); handlers.set(name, list); } };
|
|
217
|
+
const ctx = { sessionManager, model: undefined, hasPendingMessages: () => false, ui: { notify() { } } };
|
|
218
|
+
registerResetLifecycle(api, {
|
|
219
|
+
isEnabled: () => true,
|
|
220
|
+
budget: { automaticResetEnabled: () => true, hardReserveDue: () => true, consumeTurnEnd: () => [], clear() { } },
|
|
221
|
+
buildReset: () => [],
|
|
222
|
+
});
|
|
223
|
+
const original = [
|
|
224
|
+
{ type: "text", text: "Describe this image" },
|
|
225
|
+
{ type: "image", data: "aW1hZ2U=", mimeType: "image/png" },
|
|
226
|
+
];
|
|
227
|
+
for (const handler of handlers.get("message_end") ?? [])
|
|
228
|
+
await handler({ type: "message_end", message: { role: "user", content: original, timestamp: Date.now() } }, ctx);
|
|
229
|
+
let result;
|
|
230
|
+
for (const handler of handlers.get("turn_end") ?? [])
|
|
231
|
+
result = await handler(fakeBoundaryEvent([], { role: "assistant", content: [], stopReason: "stop", timestamp: Date.now() }), ctx);
|
|
232
|
+
const boundary = resultEntries([result]);
|
|
233
|
+
const carried = boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE);
|
|
234
|
+
assert.equal(carried.length, 1);
|
|
235
|
+
assert.deepEqual(carried[0]?.type === "custom_message" ? carried[0].content : undefined, original);
|
|
236
|
+
assert.equal(boundary.continue, true);
|
|
237
|
+
});
|
|
199
238
|
test("manual /empty spans tool turns and commits the stop at settlement", async () => {
|
|
200
239
|
const h = harness();
|
|
201
240
|
await h.runCommand("empty");
|
|
@@ -276,7 +315,7 @@ test("manual /empty with a prompt shows the human's command line in the close-ou
|
|
|
276
315
|
CONTINUATION_TYPE,
|
|
277
316
|
], "the reset tail contains no command argument");
|
|
278
317
|
});
|
|
279
|
-
test("input arriving during reset construction
|
|
318
|
+
test("input arriving during reset construction is carried without a hidden steer", async () => {
|
|
280
319
|
const sessionManager = Manager.inMemory("/private/tmp/notesoup-late-input-test");
|
|
281
320
|
const handlers = new Map();
|
|
282
321
|
const steers = [];
|
|
@@ -308,14 +347,14 @@ test("input arriving during reset construction survives even when the hidden ste
|
|
|
308
347
|
const boundary = resultEntries([await pending]);
|
|
309
348
|
assert.equal(boundary.continue, true, "late input overrides the bare command's stop");
|
|
310
349
|
assert.deepEqual(boundary.entries.slice(-2).map((entry) => entry.type === "custom_message" ? entry.content : null), [" first\ninput ", "second"]);
|
|
311
|
-
assert.equal(steers.length,
|
|
350
|
+
assert.equal(steers.length, 0, "handled inputs are not steered to the closing model");
|
|
312
351
|
appendDrafts(sessionManager, boundary.entries);
|
|
313
352
|
const marker = sessionManager.getBranch().find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
314
353
|
const windowId = marker.data.windowId;
|
|
315
354
|
assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true);
|
|
316
355
|
assert.deepEqual(inspectResetTail(ctx, marker.id, windowId), { boot: true, continuation: true }, "last word and trailing inputs form a complete ordered boundary");
|
|
317
356
|
await repairResetTail(api, ctx, marker);
|
|
318
|
-
assert.equal(steers.length,
|
|
357
|
+
assert.equal(steers.length, 0, "reset repair does not send prompt steers");
|
|
319
358
|
sessionManager.appendCustomMessageEntry(BOOT_TYPE, "late boot", false, { windowId });
|
|
320
359
|
assert.equal(inspectResetTail(ctx, marker.id, windowId), undefined, "artifacts cannot restart after carried input");
|
|
321
360
|
assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true, "later malformed work does not undo a committed prefix");
|
|
@@ -396,10 +435,27 @@ test("abort during reset construction restores handled input at settlement, once
|
|
|
396
435
|
await handlers.get("agent_settled")({}, ctx);
|
|
397
436
|
const restored = sent.filter((item) => item.message.customType === CARRIED_INPUT_TYPE);
|
|
398
437
|
assert.deepEqual(restored, [{ message: { type: "custom_message", customType: CARRIED_INPUT_TYPE, content: "cancelled during construction", display: true }, options: { triggerTurn: false } }]);
|
|
399
|
-
|
|
438
|
+
});
|
|
439
|
+
test("close-out error restores intercepted input and triggers its answer turn", async () => {
|
|
440
|
+
const sessionManager = Manager.inMemory("/private/tmp/notesoup-error-input-restore-test");
|
|
441
|
+
const handlers = new Map();
|
|
442
|
+
const sent = [];
|
|
443
|
+
const api = {
|
|
444
|
+
on(name, handler) { handlers.set(name, handler); },
|
|
445
|
+
sendMessage(message, options) { sent.push({ message, options }); },
|
|
446
|
+
};
|
|
447
|
+
const ctx = { sessionManager, hasPendingMessages: () => false, ui: { notify() { } } };
|
|
448
|
+
const lifecycle = registerResetLifecycle(api, {
|
|
449
|
+
isEnabled: () => true,
|
|
450
|
+
budget: { automaticResetEnabled: () => false, hardReserveDue: () => false, consumeTurnEnd: () => [], clear() { } },
|
|
451
|
+
buildReset: () => [],
|
|
452
|
+
});
|
|
453
|
+
const windowId = `pcw:${sessionManager.getSessionId().slice(0, 8)}:root`;
|
|
400
454
|
lifecycle.command(windowId, false);
|
|
401
|
-
|
|
402
|
-
|
|
455
|
+
assert.deepEqual(await handlers.get("input")({ source: "rpc", text: "restore after error" }, ctx), { action: "handled" });
|
|
456
|
+
const error = { ...fakeBoundaryEvent(), outcome: "error", message: { role: "assistant", content: [], stopReason: "error", timestamp: Date.now() } };
|
|
457
|
+
await handlers.get("turn_end")(error, ctx);
|
|
458
|
+
assert.deepEqual(sent, [{ message: { type: "custom_message", customType: CARRIED_INPUT_TYPE, content: "restore after error", display: true }, options: { triggerTurn: true } }]);
|
|
403
459
|
});
|
|
404
460
|
test("reset construction failure preserves incoming and budget drafts without continuation", async () => {
|
|
405
461
|
const sessionManager = Manager.inMemory("/private/tmp/notesoup-reset-failure-test");
|
package/docs/reset-lifecycle.md
CHANGED
|
@@ -4,22 +4,23 @@ Pi reset control lives in `plugins/pi/reset/lifecycle.ts`: the pure `reduceReset
|
|
|
4
4
|
|
|
5
5
|
## Lifecycle at a glance
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**Carry input unless it already entered model context and the model requested `empty_brain`; that handoff belongs to the model. Every `/empty` or `/fresh-window` stops after resetting unless separate human input arrives during emptying.**
|
|
8
8
|
|
|
9
9
|
| Trigger | Behavior |
|
|
10
10
|
| --- | --- |
|
|
11
|
-
| `empty_brain` tool | Record the actual call and optional last word. Without command policy, reset after the whole tool batch at `turn_end` and continue. Under command policy, wait for settlement. |
|
|
11
|
+
| `empty_brain` tool | Record the actual call and optional last word. Without command policy, reset after the whole tool batch at `turn_end` and continue unless `terminate: true` (default: false). Termination stops automatic continuation, not the session or new user input. Under command policy, wait for settlement. |
|
|
12
12
|
| `/empty <text>` or `/fresh-window <text>` | Send a hidden close-out warning (trigger when idle, steer when busy), with the argument verbatim as context for notes, then reset and stop unless separate human input arrives during emptying. |
|
|
13
13
|
| Bare `/empty` or `/fresh-window` | Close out, reset, and stop, unless more human input arrives while close-out is pending. |
|
|
14
|
-
| Human input during command close-out | Intercept public `input` events except source `extension`, return `handled`, and
|
|
15
|
-
|
|
|
14
|
+
| Human input during command close-out | Intercept public `input` events except source `extension`, return `handled`, and keep the original text/images in command state for the reset boundary. Do not steer the input into the closing model; use `/empty <text>` for close-out context. |
|
|
15
|
+
| Model-requested `empty_brain` reset | Do not carry the human input already present in model context; the model owns its handoff through notes/`last_word`. |
|
|
16
|
+
| Passive provider overflow / recoverable length | With automatic reset enabled, force a retain-none reset and continue once, carrying the failed run's human inputs. A hard-reserve reset also carries the run's inputs and continues. |
|
|
16
17
|
| Command close-out overflow | Force a reset even if automatic reset is disabled. Apply command policy: continue with separate carried input, otherwise stop. The recovery attempt is spent, so an oversized carried prompt cannot loop. |
|
|
17
18
|
| Budget warning | Stage reminders when automatic reset is enabled. Warnings alone never authorize reset. |
|
|
18
|
-
| Hard reserve | Independently reset at `turn_end` when automatic reset is enabled. A command stop latch cancels empty tool follow-ups, but never real queued or carried human input. |
|
|
19
|
-
| Abort / ordinary error | Restore stashed originals as visible user-content custom messages before clearing command state. Explicit abort stays stopped; ordinary close-out errors
|
|
19
|
+
| Hard reserve | Independently reset at `turn_end` when automatic reset is enabled and carry the run's text/images, then continue. A command stop latch cancels empty tool follow-ups, but never real queued or carried human input. |
|
|
20
|
+
| Abort / ordinary error | Restore stashed originals as visible user-content custom messages before clearing command state. Explicit abort stays stopped; ordinary close-out errors trigger a turn for the restored input without forcing a reset. |
|
|
20
21
|
| `/compact` while active | Cancel native compaction; manual attempts receive a `/fresh-window` notice. |
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
The model-requested `empty_brain` call already has the human message in model context, so it does not carry that input into the new window; the model owns the handoff through notes/`last_word`. Hard-reserve and overflow-recovery resets carry the collected run inputs. A normal completed stop with no pending messages clears the collection so a later safety reset cannot replay it.
|
|
23
24
|
|
|
24
25
|
## Boundary order and handoff
|
|
25
26
|
|
|
@@ -45,15 +46,15 @@ Raw session history remains available. The retain-none checkpoint excludes old c
|
|
|
45
46
|
| Request | Meaning |
|
|
46
47
|
| --- | --- |
|
|
47
48
|
| `none` | No command or tool request. |
|
|
48
|
-
| `pending` | Current `windowId`, optional `tool: { lastWord? }`, and optional `command: { continueAfterReset, inputs? }`. Command inputs retain
|
|
49
|
+
| `pending` | Current `windowId`, optional `tool: { lastWord?, terminate? }`, and optional `command: { continueAfterReset, inputs? }`. Command inputs retain their original text/images. Separate human input during close-out is intercepted and carried, never steered. Duplicate commands retain the first policy/text; tool calls do not overwrite command policy. |
|
|
49
50
|
|
|
50
51
|
`stopAfterReset` is separate from the request. It retains the safety boundary's intent after construction, while `request` becomes `none`. Settlement waits for queued work; if the window changed, it stops without a second wipe. If the window did not change, the boundary never committed, so settlement retries the retained intent with its stop policy and tool origin intact. A successful settle retry consumes the latch.
|
|
51
52
|
|
|
52
53
|
Overflow phases are `idle`, `pending`, `spent`, and `pending-spent`. `turn_end` arms enabled recovery; `agent_before_settle` waits for queued work and selects recovery intent. Only successful, current construction reaches finalization and spends the attempt. A successful queued turn supersedes the failure. Command overflow spends the same bounded attempt before continuing. Abort, final settlement, session start/tree/shutdown and `/notesoup off` clear transient state.
|
|
53
54
|
|
|
54
|
-
The adapter collects actual user `message_end` content until settlement or a successful
|
|
55
|
+
The adapter collects actual user `message_end` content until settlement or a successful boundary. A successful model-requested `empty_brain` boundary does not carry those inputs because they already entered model context; hard-reserve and overflow-recovery boundaries do carry them. A normal completed stop with no pending messages clears the collection to prevent a later safety reset from replaying answered input.
|
|
55
56
|
|
|
56
|
-
Command state remains live during asynchronous notes acquisition
|
|
57
|
+
Command state remains live during asynchronous notes acquisition so separately arriving input joins the reset boundary. Handled command-close-out input is not delivered to the closing model and is carried as original text/images. Command text is included as plain close-out context by `/empty <text>`. After construction passes the currentness guard, finalization selects command-owned originals, overflow-recovery inputs, or hard-reserve run inputs; tool-request resets do not carry the user message already present in model context. It resolves `resumeModel` and the next control state together. Separate human inputs are never sent as hidden steers. Construction captures session/window generations and rechecks identity, enabled state and abort status before returning drafts; stale work preserves incoming/budget entries but discards reset drafts. If close-out cannot commit, stashed originals are restored with public `sendMessage(..., { triggerTurn: false })` except on an ordinary turn-end error, which triggers a turn for the restored input; abort and other restore paths stay stopped.
|
|
57
58
|
|
|
58
59
|
After a manual safety reset, `context_with_system` checks the committed boundary before using public `ctx.abort()` to cancel an unavoidable empty tool follow-up with system-only context. Pending messages, ordinary user entries or carried inputs after the marker bypass cancellation. Later user prompts are not affected by the run-scoped stop latch.
|
|
59
60
|
|
|
@@ -61,7 +62,7 @@ After a manual safety reset, `context_with_system` checks the committed boundary
|
|
|
61
62
|
|
|
62
63
|
Budget reminders are staged once per window at reserve plus reminder margin, then reserve plus warning runway. Hard reserve remains independent. Budget and command warnings use different types. The final budget warning notifies at first provider injection, not durability; early guidance stays UI-silent. Budget drafts are instance-local and discarded on abort, failed turn, transition or window mismatch. Active-window usage and the exact public `SettingsManager` authority determine thresholds.
|
|
63
64
|
|
|
64
|
-
Pi and Claude use the same budget warning: budget timing, the handoff checklist, note maintenance (including updating and trimming CHEATSHEET.md and MAP.md), a warning against large tool outputs, then `empty_brain` and the countdown. Pi's manual warnings replace the budget opening with the `/empty` notice inside `<notesoup:budget_notice>`. Optional command text sits after the closing tag
|
|
65
|
+
Pi and Claude use the same budget warning: budget timing, the handoff checklist, note maintenance (including updating and trimming CHEATSHEET.md and MAP.md), a warning against large tool outputs, then `empty_brain` and the countdown. Pi's manual warnings replace the budget opening with the `/empty` notice inside `<notesoup:budget_notice>`. Optional command text sits after the closing tag as plain text for the closing model's notes; separate human input during close-out is intercepted and carried, never steered. The first-tier reminder reports the remaining room, explains that notes survive the wipe, asks for updated notes and offers an optional `empty_brain`, warning that it also clears what the model says to the human right before emptying. Pi's boot retains its existing pre-reset hints; warnings no longer repeat those or the tool's `last_word` description.
|
|
65
66
|
|
|
66
67
|
`context_with_system` selects the boot by durable window identity, using Pi's canonical checkpoint projection or legacy slicing. Missing boot aborts safely instead of exposing raw history. Usage estimates use the same projection decision. `/tree` summaries are suppressed when crossing reset branches because native branch summarization bypasses this projection.
|
|
67
68
|
|
|
@@ -69,4 +70,4 @@ Pi and Claude use the same budget warning: budget timing, the handoff checklist,
|
|
|
69
70
|
|
|
70
71
|
## Validation
|
|
71
72
|
|
|
72
|
-
Scripted SDK tests run Pi's real agent loop without network calls: smaller-model overflow and prompt replay, command text, bare stop, intercepted text/images, hard-reserve handling, overflowing close-out and bounded retry. They also cover passive tool-loop steering/follow-ups and input-free automatic continuations. Focused tests check late input during asynchronous construction,
|
|
73
|
+
Scripted SDK tests run Pi's real agent loop without network calls: smaller-model overflow and prompt replay, command text, bare stop, intercepted text/images, hard-reserve handling, overflowing close-out and bounded retry. They also cover passive tool-loop steering/follow-ups and input-free automatic continuations. Focused tests check late input during asynchronous construction, absence of input steers, abort/error restoration, ordered carry artifacts, commit confirmation, safe repair, canonical projection and persisted history. External-provider behavior and every malformed persisted/filesystem case are not established by this suite.
|
package/package.json
CHANGED
package/plugins/pi/entries.ts
CHANGED
|
@@ -6,5 +6,4 @@ 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
8
|
export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
|
-
export const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
10
9
|
export const MARKER_TYPE = "notesoup/marker";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
3
2
|
import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
|
|
4
3
|
import type { AgentBeforeSettleEvent, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
@@ -9,8 +8,6 @@ import { resetBoundaryCommitted } from "./committed.js";
|
|
|
9
8
|
import type { ResetOrigin } from "../../../src/budget/text.js";
|
|
10
9
|
import { errorMessage } from "../../../src/error-message.js";
|
|
11
10
|
import { carriedInputDrafts, isCarriedInputEntry, type CarriedInput } from "./artifacts.js";
|
|
12
|
-
import { NEXT_WINDOW_PROMPT_TYPE } from "../entries.js";
|
|
13
|
-
import { promptBlock } from "../text.js";
|
|
14
11
|
|
|
15
12
|
type BudgetOwner = {
|
|
16
13
|
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
@@ -41,7 +38,7 @@ export type ResetRequest =
|
|
|
41
38
|
| { readonly phase: "none" }
|
|
42
39
|
| { readonly phase: "pending"; readonly windowId: string;
|
|
43
40
|
readonly command?: { readonly continueAfterReset: boolean; readonly inputs?: readonly CarriedInput[] };
|
|
44
|
-
readonly tool?: { readonly lastWord?: string } };
|
|
41
|
+
readonly tool?: { readonly lastWord?: string; readonly terminate?: boolean } };
|
|
45
42
|
export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
|
|
46
43
|
|
|
47
44
|
export interface ResetControlState {
|
|
@@ -82,19 +79,20 @@ export interface ResetBeforeSettleFacts {
|
|
|
82
79
|
export type ResetControlEvent =
|
|
83
80
|
| { readonly type: "command"; readonly windowId: string; readonly continueAfterReset: boolean; readonly input?: CarriedInput }
|
|
84
81
|
| { readonly type: "input"; readonly windowId: string; readonly input: CarriedInput }
|
|
85
|
-
| { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string }
|
|
82
|
+
| { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string; readonly terminate?: boolean }
|
|
86
83
|
| { readonly type: "turn_end"; readonly facts: ResetTurnEndFacts }
|
|
87
84
|
| { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts };
|
|
88
85
|
|
|
89
86
|
/** Construction intent, not final state: handled inputs can still arrive while notes load. Only `turn-end`
|
|
90
|
-
* may latch a stop; overflow kinds spend recovery; only
|
|
87
|
+
* may latch a stop; overflow kinds spend recovery; only hard-reserve and overflow carry passive run inputs. */
|
|
91
88
|
export interface ResetBoundaryIntent {
|
|
92
89
|
readonly effect: "build-boundary";
|
|
93
90
|
readonly boundary: "turn-end" | "settle" | "command-overflow" | "overflow-recovery";
|
|
94
91
|
readonly windowId: string;
|
|
95
92
|
readonly continueAfterReset: boolean;
|
|
96
93
|
readonly origin: ResetOrigin;
|
|
97
|
-
readonly
|
|
94
|
+
readonly carryRunInputs?: boolean;
|
|
95
|
+
readonly tool?: { readonly lastWord?: string; readonly terminate?: boolean };
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
export type ResetControlResult = ResetBoundaryIntent |
|
|
@@ -106,16 +104,16 @@ function requestForWindow(request: ResetRequest, windowId: string): ResetRequest
|
|
|
106
104
|
|
|
107
105
|
const spendsOverflow = (boundary: ResetBoundaryIntent["boundary"]) => boundary === "command-overflow" || boundary === "overflow-recovery";
|
|
108
106
|
|
|
109
|
-
function boundaryIntent(request: ResetRequest, windowId: string, boundary: ResetBoundaryIntent["boundary"]): ResetBoundaryIntent {
|
|
107
|
+
function boundaryIntent(request: ResetRequest, windowId: string, boundary: ResetBoundaryIntent["boundary"], carryRunInputs = false): ResetBoundaryIntent {
|
|
110
108
|
const tool = request.phase === "none" ? undefined : request.tool;
|
|
111
|
-
const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ??
|
|
112
|
-
return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal" };
|
|
109
|
+
const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? !request.tool?.terminate : true;
|
|
110
|
+
return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal", ...(carryRunInputs ? { carryRunInputs: true } : {}) };
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
/** Resolve once, after a successful current build. No delivery policy is left to the adapter. */
|
|
116
114
|
export function finalizeResetBoundary(intent: ResetBoundaryIntent, request: ResetRequest, passiveInputs: readonly CarriedInput[] = []) {
|
|
117
115
|
const inputs = request.phase === "pending" && request.command ? request.command.inputs ?? []
|
|
118
|
-
: intent.boundary === "overflow-recovery" ? passiveInputs : [];
|
|
116
|
+
: intent.boundary === "overflow-recovery" || intent.carryRunInputs ? passiveInputs : [];
|
|
119
117
|
const resumeModel = intent.continueAfterReset || inputs.length > 0;
|
|
120
118
|
const state: ResetControlState = {
|
|
121
119
|
request: NO_REQUEST,
|
|
@@ -147,7 +145,10 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
147
145
|
// The call remains a real request even when command policy delays its commit.
|
|
148
146
|
const duplicate = request.tool !== undefined;
|
|
149
147
|
const lastWord = request.tool?.lastWord ?? event.lastWord;
|
|
150
|
-
const tool = duplicate && !request.command ? request.tool :
|
|
148
|
+
const tool = duplicate && !request.command ? request.tool : {
|
|
149
|
+
...(lastWord ? { lastWord } : {}),
|
|
150
|
+
...((duplicate ? request.tool?.terminate : event.terminate) ? { terminate: true } : {}),
|
|
151
|
+
};
|
|
151
152
|
return { state: { ...state, request: { ...request, tool } }, effect: duplicate ? "already-pending" : "close-out-armed" };
|
|
152
153
|
}
|
|
153
154
|
case "turn_end": {
|
|
@@ -170,8 +171,9 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
170
171
|
}
|
|
171
172
|
// A direct tool request commits after the whole tool batch. The budget cutoff is
|
|
172
173
|
// a separate hard-reserve safety path; ordinary close-out waits for settlement.
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
const toolReset = request.phase === "pending" && request.tool !== undefined;
|
|
175
|
+
if ((toolReset && !manual) || facts.hardReserveDue) {
|
|
176
|
+
return boundaryIntent(request, facts.windowId, "turn-end", !manual && !toolReset && facts.hardReserveDue);
|
|
175
177
|
}
|
|
176
178
|
return { state: { request, overflow: "idle" }, effect: "none" };
|
|
177
179
|
}
|
|
@@ -220,17 +222,16 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
220
222
|
let lifecycleGeneration = 0;
|
|
221
223
|
let control = initialResetControl();
|
|
222
224
|
let runInputs: CarriedInput[] = [];
|
|
223
|
-
let commandId: string | undefined;
|
|
224
225
|
|
|
225
226
|
// Once input returns handled, Pi no longer owns its original content. If close-out
|
|
226
|
-
// fails/cancels,
|
|
227
|
-
const restoreCommandInputs = () => {
|
|
227
|
+
// fails/cancels, restore it; only an ordinary error starts a turn to answer it.
|
|
228
|
+
const restoreCommandInputs = (triggerTurn = false) => {
|
|
228
229
|
const request = control.request;
|
|
229
230
|
if (request.phase !== "pending" || !request.command?.inputs?.length) return;
|
|
230
231
|
const inputs = request.command.inputs;
|
|
231
232
|
control = { ...control, request: { ...request, command: { ...request.command, inputs: [] } } };
|
|
232
233
|
for (const draft of carriedInputDrafts(inputs)) {
|
|
233
|
-
pi.sendMessage(draft, { triggerTurn
|
|
234
|
+
pi.sendMessage(draft, { triggerTurn });
|
|
234
235
|
}
|
|
235
236
|
runInputs.push(...inputs);
|
|
236
237
|
};
|
|
@@ -239,11 +240,9 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
239
240
|
if (preserveInputs) restoreCommandInputs();
|
|
240
241
|
control = initialResetControl();
|
|
241
242
|
runInputs = [];
|
|
242
|
-
commandId = undefined;
|
|
243
243
|
};
|
|
244
244
|
const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, intent: ResetBoundaryIntent) => {
|
|
245
|
-
// Keep command state live while notes load
|
|
246
|
-
// join this very boundary even if its steer cannot reach the closing model.
|
|
245
|
+
// Keep command state live while notes load so input arriving during this await joins this boundary.
|
|
247
246
|
const generation = lifecycleGeneration;
|
|
248
247
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
249
248
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -281,10 +280,6 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
281
280
|
? [{ type: "text", text: event.text }, ...event.images]
|
|
282
281
|
: event.text;
|
|
283
282
|
control = reduceResetControl(control, { type: "input", windowId: request.windowId, input: content }).state;
|
|
284
|
-
const steerContent: CarriedInput = event.images?.length
|
|
285
|
-
? [{ type: "text", text: promptBlock(event.text) }, ...event.images]
|
|
286
|
-
: promptBlock(event.text);
|
|
287
|
-
pi.sendMessage({ customType: NEXT_WINDOW_PROMPT_TYPE, content: steerContent, display: false, details: { windowId: request.windowId, commandId } }, { deliverAs: "steer" });
|
|
288
283
|
return { action: "handled" };
|
|
289
284
|
});
|
|
290
285
|
|
|
@@ -292,23 +287,13 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
292
287
|
// safety reset is actually committed, cancel that empty follow-up before provider
|
|
293
288
|
// work. Real queued user input is allowed through and answered before settlement.
|
|
294
289
|
pi.on("context_with_system", (event, ctx) => {
|
|
295
|
-
const request = control.request;
|
|
296
|
-
// Steering can be queued during buildReset's await and arrive after the boundary.
|
|
297
|
-
// It is closing-model context only; originals already live in the carried entries.
|
|
298
|
-
const messages = event.messages.filter((message) => {
|
|
299
|
-
if (message.role !== "custom" || message.customType !== NEXT_WINDOW_PROMPT_TYPE) return true;
|
|
300
|
-
const details = message.details as { windowId?: unknown; commandId?: unknown } | undefined;
|
|
301
|
-
return request.phase === "pending" && request.command !== undefined &&
|
|
302
|
-
request.windowId === currentWindowId(ctx) && details?.windowId === request.windowId && commandId !== undefined && details?.commandId === commandId;
|
|
303
|
-
});
|
|
304
|
-
const filtered = messages.length === event.messages.length ? undefined : { messages };
|
|
305
290
|
const stop = control.stopAfterReset;
|
|
306
|
-
if (!sessionActive || !stop || ctx.hasPendingMessages()) return
|
|
291
|
+
if (!sessionActive || !stop || ctx.hasPendingMessages()) return undefined;
|
|
307
292
|
const marker = currentReset(ctx);
|
|
308
|
-
if (!marker || marker.data.windowId === stop.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId)) return
|
|
293
|
+
if (!marker || marker.data.windowId === stop.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId)) return undefined;
|
|
309
294
|
const branch = ctx.sessionManager.getBranch();
|
|
310
295
|
const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
|
|
311
|
-
if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry))) return
|
|
296
|
+
if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry))) return undefined;
|
|
312
297
|
ctx.abort();
|
|
313
298
|
const system = getCurrentSystemMessage(event.messages);
|
|
314
299
|
return { messages: system ? [system] : [] };
|
|
@@ -334,8 +319,11 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
334
319
|
},
|
|
335
320
|
});
|
|
336
321
|
if (decision.effect === "build-boundary") return await resetBoundaryResult(entries, ctx, decision);
|
|
337
|
-
if (aborted
|
|
322
|
+
if (aborted) restoreCommandInputs();
|
|
323
|
+
else if (event.outcome === "error" && decision.state.request.phase === "none") restoreCommandInputs(true);
|
|
338
324
|
control = decision.state;
|
|
325
|
+
if (!aborted && event.outcome === "completed" && event.message.role === "assistant" && event.message.stopReason === "stop" &&
|
|
326
|
+
event.context.pendingMessages.length === 0 && !ctx.hasPendingMessages()) runInputs = [];
|
|
339
327
|
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
340
328
|
const marker = buildMarkerDraft(ctx, entries);
|
|
341
329
|
if (marker) entries.push(marker);
|
|
@@ -390,11 +378,10 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
390
378
|
command(windowId: string, continueAfterReset: boolean, input?: CarriedInput) {
|
|
391
379
|
const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset, ...(input !== undefined ? { input } : {}) });
|
|
392
380
|
control = decision.state;
|
|
393
|
-
if (decision.effect === "close-out-armed") commandId = randomUUID();
|
|
394
381
|
return decision.effect;
|
|
395
382
|
},
|
|
396
|
-
request(windowId: string, lastWord?: string) {
|
|
397
|
-
const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
|
|
383
|
+
request(windowId: string, lastWord?: string, terminate = false) {
|
|
384
|
+
const decision = reduceResetControl(control, { type: "tool_request", windowId, terminate, ...(lastWord ? { lastWord } : {}) });
|
|
398
385
|
control = decision.state;
|
|
399
386
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
400
387
|
},
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
|
3
3
|
import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
|
|
4
4
|
import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { registerBudget } from "./budget.js";
|
|
6
|
-
import { output } from "./tool-result.js";
|
|
6
|
+
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
|
|
7
7
|
import { emptyBrainRenderers } from "./render.js";
|
|
8
8
|
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
|
|
9
9
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
@@ -24,6 +24,9 @@ function readPackageVersion(): string {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const buildLabel = `v${readPackageVersion()}`;
|
|
27
|
+
const notesoupTools = [NOTES_NAMESPACE, HISTORY_NAMESPACE, DREAM_NAMESPACE]
|
|
28
|
+
.map(({ name, description }) => `${name}: ${description}`)
|
|
29
|
+
.join("\n") + "\nDiscover deferred tools through codemode or tool_search when available.";
|
|
27
30
|
|
|
28
31
|
function branchHasWindowMarker(ctx: ExtensionContext, fromId?: string): boolean {
|
|
29
32
|
return ctx.sessionManager.getBranch(fromId).some((entry) => isWindowMarker(entry));
|
|
@@ -77,7 +80,8 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
77
80
|
if (markerResetOrigin(marker) === "forced") ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
78
81
|
}
|
|
79
82
|
};
|
|
80
|
-
pi.on("before_agent_start", (
|
|
83
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
84
|
+
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
81
85
|
if (enabled) maybeSendMarker(pi, ctx);
|
|
82
86
|
});
|
|
83
87
|
pi.on("turn_start", (_event, ctx) => {
|
|
@@ -207,7 +211,10 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
207
211
|
name: "empty_brain",
|
|
208
212
|
label: "Empty Brain",
|
|
209
213
|
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.",
|
|
210
|
-
parameters: Type.Object({
|
|
214
|
+
parameters: Type.Object({
|
|
215
|
+
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.` })),
|
|
216
|
+
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
|
|
217
|
+
}, { additionalProperties: false }),
|
|
211
218
|
renderCall: emptyBrainRenderers.renderCall,
|
|
212
219
|
renderResult: emptyBrainRenderers.renderResult,
|
|
213
220
|
async execute(_id, params, _signal, _update, ctx) {
|
|
@@ -215,7 +222,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
215
222
|
const lastWord = sanitizeLastWord(params.last_word);
|
|
216
223
|
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
217
224
|
if (length > MAX_LAST_WORD_CHARS) return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
|
|
218
|
-
return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
|
|
225
|
+
return output({ status: resets.request(currentWindowId(ctx), lastWord, params.terminate) }, undefined, true);
|
|
219
226
|
},
|
|
220
227
|
}));
|
|
221
228
|
|
package/plugins/pi/text.ts
CHANGED
|
@@ -16,11 +16,6 @@ export function markerContent(seq: number): string {
|
|
|
16
16
|
return `<notesoup:marker seq="${seq}" />`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
20
|
-
export function promptBlock(commandLine: string): string {
|
|
21
|
-
return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
19
|
/** Approved manual close-out notices; both variants live here. */
|
|
25
20
|
export const COMMAND_NOTICE = {
|
|
26
21
|
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 command below is context for your notes, not a task for the fresh window. Anything the human sends separately from now on should be handled after the reset.",
|
|
@@ -30,5 +25,5 @@ export const COMMAND_NOTICE = {
|
|
|
30
25
|
/** Manual orders omit budget timing hints; deferred work sits outside the notice. */
|
|
31
26
|
export function commandWarningContent(commandLine?: string): string {
|
|
32
27
|
const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
|
|
33
|
-
return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${
|
|
28
|
+
return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${commandLine}` : ""}`;
|
|
34
29
|
}
|