notesoup 0.45.1 → 0.45.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/src/budget/text.d.ts +4 -2
- package/dist/src/budget/text.js +4 -2
- package/dist/src/pi/entries.d.ts +1 -0
- package/dist/src/pi/entries.js +1 -0
- package/dist/src/pi/reset/artifacts.d.ts +6 -2
- package/dist/src/pi/reset/artifacts.js +14 -3
- package/dist/src/pi/reset/lifecycle.d.ts +6 -2
- package/dist/src/pi/reset/lifecycle.js +28 -18
- package/dist/src/pi/runtime.js +6 -6
- package/dist/test/reset-lifecycle.test.js +47 -3
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +487 -485
- package/package.json +1 -1
- package/src/budget/text.ts +5 -2
- package/src/pi/entries.ts +1 -0
- package/src/pi/reset/artifacts.ts +15 -2
- package/src/pi/reset/lifecycle.ts +34 -21
- package/src/pi/runtime.ts +6 -6
|
@@ -10,8 +10,10 @@ export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
12
12
|
export declare const WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.";
|
|
13
|
-
/**
|
|
14
|
-
export declare const
|
|
13
|
+
/** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
|
|
14
|
+
export declare const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
|
|
15
|
+
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
|
|
16
|
+
export declare const WARNING_CONTENT = "<context_window_guidance>\nThis context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.\nIf you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.\n</context_window_guidance>";
|
|
15
17
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
16
18
|
export declare const CLAUDE_WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, end your turn; the reset runs after it.";
|
|
17
19
|
/**
|
package/dist/src/budget/text.js
CHANGED
|
@@ -10,8 +10,10 @@ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Defini
|
|
|
10
10
|
*/
|
|
11
11
|
export const WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
12
12
|
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
|
|
13
|
-
/**
|
|
14
|
-
export const
|
|
13
|
+
/** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
|
|
14
|
+
export const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
|
|
15
|
+
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
|
|
16
|
+
export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
|
|
15
17
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
16
18
|
export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
|
|
17
19
|
/**
|
package/dist/src/pi/entries.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
|
|
|
5
5
|
export declare const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
6
6
|
export declare const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
7
|
export declare const RESET_PROMPT_TYPE = "notesoup/reset-prompt";
|
|
8
|
+
export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
package/dist/src/pi/entries.js
CHANGED
|
@@ -5,3 +5,4 @@ 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_PROMPT_TYPE = "notesoup/reset-prompt";
|
|
8
|
+
export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
@@ -5,13 +5,17 @@ export type ResetTailState = {
|
|
|
5
5
|
readonly boot: boolean;
|
|
6
6
|
readonly continuation: boolean;
|
|
7
7
|
};
|
|
8
|
+
/** Cap for the parting line: one visible line, not an essay. */
|
|
9
|
+
export declare const MAX_LAST_WORD_CHARS = 500;
|
|
10
|
+
/** Trim and cap a parting line; blank input leaves no last word. */
|
|
11
|
+
export declare function sanitizeLastWord(raw: string | undefined): string | undefined;
|
|
8
12
|
/** Match the hidden continuation entry that carries the one reset message. */
|
|
9
13
|
export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
|
|
10
14
|
/**
|
|
11
15
|
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
12
|
-
* continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
16
|
+
* continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
13
17
|
*/
|
|
14
|
-
export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string): Promise<SessionBoundaryDraft[]>;
|
|
18
|
+
export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string, lastWord?: string): Promise<SessionBoundaryDraft[]>;
|
|
15
19
|
/**
|
|
16
20
|
* Inspect the persisted tail of a reset marker. It reports which reset messages are present
|
|
17
21
|
* only while the tail stays repairable: metadata may follow the marker, but real conversation,
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
|
|
2
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
|
|
3
3
|
import { CONTINUATION } from "../../budget/text.js";
|
|
4
4
|
import { currentWindowId, isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, previousWindowId } from "../window.js";
|
|
5
5
|
import { buildBootMessage, sendBoot } from "../boot.js";
|
|
6
|
+
/** Cap for the parting line: one visible line, not an essay. */
|
|
7
|
+
export const MAX_LAST_WORD_CHARS = 500;
|
|
8
|
+
/** Trim and cap a parting line; blank input leaves no last word. */
|
|
9
|
+
export function sanitizeLastWord(raw) {
|
|
10
|
+
const trimmed = raw?.trim();
|
|
11
|
+
if (!trimmed)
|
|
12
|
+
return undefined;
|
|
13
|
+
const chars = Array.from(trimmed);
|
|
14
|
+
return chars.length > MAX_LAST_WORD_CHARS ? `${chars.slice(0, MAX_LAST_WORD_CHARS).join("")}…` : trimmed;
|
|
15
|
+
}
|
|
6
16
|
/** Match the hidden continuation entry that carries the one reset message. */
|
|
7
17
|
export function isWindowContinuationEntry(entry) {
|
|
8
18
|
return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
|
|
@@ -13,9 +23,9 @@ function sendContinuation(pi) {
|
|
|
13
23
|
}
|
|
14
24
|
/**
|
|
15
25
|
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
16
|
-
* continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
26
|
+
* continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
17
27
|
*/
|
|
18
|
-
export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt) {
|
|
28
|
+
export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt, lastWord) {
|
|
19
29
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
20
30
|
const previousId = currentWindowId(ctx);
|
|
21
31
|
const sessionPrefix = sessionId.slice(0, 8);
|
|
@@ -30,6 +40,7 @@ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = (
|
|
|
30
40
|
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
|
|
31
41
|
{ type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
|
|
32
42
|
{ type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
|
|
43
|
+
...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: lastWord, display: true }] : []),
|
|
33
44
|
...(prompt ? [{ type: "custom_message", customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
|
|
34
45
|
];
|
|
35
46
|
}
|
|
@@ -8,7 +8,7 @@ type BudgetOwner = {
|
|
|
8
8
|
type ResetOptions = {
|
|
9
9
|
isEnabled: () => boolean;
|
|
10
10
|
budget: BudgetOwner;
|
|
11
|
-
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
11
|
+
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string, lastWord?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
12
12
|
getLifecycleGeneration?: () => number;
|
|
13
13
|
onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
|
|
14
14
|
};
|
|
@@ -24,10 +24,12 @@ export type ResetRequest = {
|
|
|
24
24
|
readonly windowId: string;
|
|
25
25
|
readonly source: ResetRequestSource;
|
|
26
26
|
readonly prompt?: string;
|
|
27
|
+
readonly lastWord?: string;
|
|
27
28
|
} | {
|
|
28
29
|
readonly phase: "tool-requested";
|
|
29
30
|
readonly windowId: string;
|
|
30
31
|
readonly source: ToolResetRequestSource;
|
|
32
|
+
readonly lastWord?: string;
|
|
31
33
|
};
|
|
32
34
|
export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
|
|
33
35
|
export interface ResetControlState {
|
|
@@ -63,6 +65,7 @@ export type ResetControlEvent = {
|
|
|
63
65
|
} | {
|
|
64
66
|
readonly type: "tool_request";
|
|
65
67
|
readonly windowId: string;
|
|
68
|
+
readonly lastWord?: string;
|
|
66
69
|
} | {
|
|
67
70
|
readonly type: "turn_end";
|
|
68
71
|
readonly facts: ResetTurnEndFacts;
|
|
@@ -81,6 +84,7 @@ export interface ResetControlResult {
|
|
|
81
84
|
readonly state: ResetControlState;
|
|
82
85
|
readonly effect: ResetControlEffect;
|
|
83
86
|
readonly prompt?: string;
|
|
87
|
+
readonly lastWord?: string;
|
|
84
88
|
}
|
|
85
89
|
/** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
|
|
86
90
|
export declare function reduceResetControl(state: ResetControlState, event: ResetControlEvent): ResetControlResult;
|
|
@@ -95,7 +99,7 @@ export declare function reduceResetControl(state: ResetControlState, event: Rese
|
|
|
95
99
|
*/
|
|
96
100
|
export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
|
|
97
101
|
closeOut(windowId: string, source: ResetRequestSource, prompt?: string): ResetControlEffect;
|
|
98
|
-
request(windowId: string): "rollover_already_pending" | "rollover_requested";
|
|
102
|
+
request(windowId: string, lastWord?: string): "rollover_already_pending" | "rollover_requested";
|
|
99
103
|
clear: () => void;
|
|
100
104
|
};
|
|
101
105
|
export {};
|
|
@@ -18,10 +18,15 @@ export function initialResetControl() {
|
|
|
18
18
|
function requestForWindow(request, windowId) {
|
|
19
19
|
return request.phase === "stop-pending" || (request.phase !== "none" && request.windowId === windowId) ? request : NO_REQUEST;
|
|
20
20
|
}
|
|
21
|
-
function manualCommit(prompt) {
|
|
21
|
+
function manualCommit(prompt, lastWord) {
|
|
22
|
+
const parting = lastWord ? { lastWord } : {};
|
|
22
23
|
return prompt
|
|
23
|
-
? { state: initialResetControl(), effect: "commit-boundary", prompt }
|
|
24
|
-
: { state: initialResetControl(), effect: "commit-boundary-stop" };
|
|
24
|
+
? { state: initialResetControl(), effect: "commit-boundary", prompt, ...parting }
|
|
25
|
+
: { state: initialResetControl(), effect: "commit-boundary-stop", ...parting };
|
|
26
|
+
}
|
|
27
|
+
/** The parting line rides either committing phase; other phases never carry one. */
|
|
28
|
+
function requestLastWord(request) {
|
|
29
|
+
return request.phase === "close-out" || request.phase === "tool-requested" ? request.lastWord : undefined;
|
|
25
30
|
}
|
|
26
31
|
/** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
|
|
27
32
|
export function reduceResetControl(state, event) {
|
|
@@ -52,16 +57,20 @@ export function reduceResetControl(state, event) {
|
|
|
52
57
|
if (request.phase === "tool-requested" && request.windowId === event.windowId) {
|
|
53
58
|
return { state, effect: "already-pending" };
|
|
54
59
|
}
|
|
60
|
+
const parting = event.lastWord ? { lastWord: event.lastWord } : {};
|
|
55
61
|
// A manual close-out must settle so the stop actually lands; the agent's own wipe
|
|
56
62
|
// call during one is only an acknowledgement, never a conversion to a turn-end
|
|
57
63
|
// commit that pi's tool-batch continuation can overrun. A budget close-out still
|
|
58
64
|
// upgrades: context pressure cannot wait for settlement.
|
|
59
65
|
if (request.phase === "close-out" && request.windowId === event.windowId) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
// The acknowledging call still contributes its last word; the manual commit keeps the wheel.
|
|
67
|
+
if (request.source === "manual") {
|
|
68
|
+
const lastWord = request.lastWord ?? event.lastWord;
|
|
69
|
+
return { state: { ...state, request: { ...request, ...(lastWord ? { lastWord } : {}) } }, effect: "already-pending" };
|
|
70
|
+
}
|
|
71
|
+
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "automatic", ...parting } }, effect: "close-out-armed" };
|
|
63
72
|
}
|
|
64
|
-
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool" } }, effect: "close-out-armed" };
|
|
73
|
+
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool", ...parting } }, effect: "close-out-armed" };
|
|
65
74
|
}
|
|
66
75
|
case "turn_end": {
|
|
67
76
|
const facts = event.facts;
|
|
@@ -87,11 +96,12 @@ export function reduceResetControl(state, event) {
|
|
|
87
96
|
// A direct tool request commits after the whole tool batch. The budget cutoff is
|
|
88
97
|
// a separate hard-reserve safety path; ordinary close-out waits for settlement.
|
|
89
98
|
if (request.phase === "tool-requested" || facts.hardReserveDue) {
|
|
99
|
+
const lastWord = requestLastWord(request);
|
|
90
100
|
if (manual && request.prompt)
|
|
91
|
-
return manualCommit(request.prompt);
|
|
101
|
+
return manualCommit(request.prompt, lastWord);
|
|
92
102
|
if (manual)
|
|
93
|
-
return { state: { request: { phase: "stop-pending", windowId: facts.windowId }, overflow: "idle" }, effect: "commit-boundary-stop" };
|
|
94
|
-
return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary" };
|
|
103
|
+
return { state: { request: { phase: "stop-pending", windowId: facts.windowId }, overflow: "idle" }, effect: "commit-boundary-stop", ...(lastWord ? { lastWord } : {}) };
|
|
104
|
+
return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary", ...(lastWord ? { lastWord } : {}) };
|
|
95
105
|
}
|
|
96
106
|
return { state: { request, overflow: "idle" }, effect: "none" };
|
|
97
107
|
}
|
|
@@ -117,7 +127,7 @@ export function reduceResetControl(state, event) {
|
|
|
117
127
|
// An explicit manual wipe is not an automatic recovery/retry. It must still
|
|
118
128
|
// clear on overflow, including when automatic reset is disabled.
|
|
119
129
|
if (manual && facts.enabled)
|
|
120
|
-
return manualCommit(request.prompt);
|
|
130
|
+
return manualCommit(request.prompt, requestLastWord(request));
|
|
121
131
|
const spent = state.overflow === "pending-spent";
|
|
122
132
|
if (!facts.enabled || !facts.automaticResetEnabled) {
|
|
123
133
|
return { state: { request: facts.failed ? NO_REQUEST : request, overflow: spent ? "spent" : "idle" }, effect: "none" };
|
|
@@ -129,7 +139,7 @@ export function reduceResetControl(state, event) {
|
|
|
129
139
|
}
|
|
130
140
|
if (facts.queued)
|
|
131
141
|
return { state: { ...state, request }, effect: "none" };
|
|
132
|
-
return manualCommit(request.prompt);
|
|
142
|
+
return manualCommit(request.prompt, requestLastWord(request));
|
|
133
143
|
}
|
|
134
144
|
case "settled":
|
|
135
145
|
return { state: initialResetControl(), effect: "none" };
|
|
@@ -152,7 +162,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
152
162
|
let lifecycleGeneration = 0;
|
|
153
163
|
let control = initialResetControl();
|
|
154
164
|
const clear = () => { control = reduceResetControl(control, { type: "clear" }).state; };
|
|
155
|
-
const resetBoundaryResult = async (entries, ctx, continueAfterReset, prompt) => {
|
|
165
|
+
const resetBoundaryResult = async (entries, ctx, continueAfterReset, prompt, lastWord) => {
|
|
156
166
|
const generation = lifecycleGeneration;
|
|
157
167
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
158
168
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -162,7 +172,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
162
172
|
ctx.signal?.aborted !== true && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
163
173
|
let resetDrafts;
|
|
164
174
|
try {
|
|
165
|
-
resetDrafts = await options.buildReset(ctx, isCurrent, prompt);
|
|
175
|
+
resetDrafts = await options.buildReset(ctx, isCurrent, prompt, lastWord);
|
|
166
176
|
}
|
|
167
177
|
catch (error) {
|
|
168
178
|
if (isCurrent())
|
|
@@ -214,7 +224,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
214
224
|
});
|
|
215
225
|
control = decision.state;
|
|
216
226
|
if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop")
|
|
217
|
-
return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt);
|
|
227
|
+
return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt, decision.lastWord);
|
|
218
228
|
return entries.length > 0 ? { entries } : undefined;
|
|
219
229
|
});
|
|
220
230
|
pi.on("agent_before_settle", async (event, ctx) => {
|
|
@@ -236,7 +246,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
236
246
|
return { entries: event.entries, continue: false };
|
|
237
247
|
if (decision.effect !== "commit-boundary" && decision.effect !== "commit-boundary-stop" && decision.effect !== "recover-overflow")
|
|
238
248
|
return undefined;
|
|
239
|
-
return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt);
|
|
249
|
+
return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt, decision.lastWord);
|
|
240
250
|
});
|
|
241
251
|
pi.on("session_before_compact", (event, ctx) => {
|
|
242
252
|
if (!sessionActive)
|
|
@@ -268,8 +278,8 @@ export function registerResetLifecycle(pi, options) {
|
|
|
268
278
|
control = decision.state;
|
|
269
279
|
return decision.effect;
|
|
270
280
|
},
|
|
271
|
-
request(windowId) {
|
|
272
|
-
const decision = reduceResetControl(control, { type: "tool_request", windowId });
|
|
281
|
+
request(windowId, lastWord) {
|
|
282
|
+
const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
|
|
273
283
|
control = decision.state;
|
|
274
284
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
275
285
|
},
|
package/dist/src/pi/runtime.js
CHANGED
|
@@ -6,7 +6,7 @@ import { registerBudget } from "./budget.js";
|
|
|
6
6
|
import { output } from "./tool-result.js";
|
|
7
7
|
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
|
-
import { buildResetDrafts, repairResetTail } from "./reset/artifacts.js";
|
|
9
|
+
import { buildResetDrafts, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
10
10
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
11
11
|
import { WARNING_CONTENT } from "../budget/text.js";
|
|
12
12
|
import { buildBootMessage, sendBoot } from "./boot.js";
|
|
@@ -205,17 +205,17 @@ export function registerContext(pi, settingsManager) {
|
|
|
205
205
|
pi.registerTool(defineTool({
|
|
206
206
|
name: "clear_memory",
|
|
207
207
|
label: "Clear memory",
|
|
208
|
-
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive.",
|
|
209
|
-
parameters: Type.Object({}, { additionalProperties: false }),
|
|
210
|
-
async execute(_id,
|
|
208
|
+
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to leave one short visible line where this window closes.",
|
|
209
|
+
parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: "A parting line shown where this window closes; the next window can read it too." })) }, { additionalProperties: false }),
|
|
210
|
+
async execute(_id, params, _signal, _update, ctx) {
|
|
211
211
|
if (!enabled)
|
|
212
212
|
return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
213
|
-
return output({ status: resets.request(currentWindowId(ctx)) }, undefined, true);
|
|
213
|
+
return output({ status: resets.request(currentWindowId(ctx), sanitizeLastWord(params.last_word)) }, undefined, true);
|
|
214
214
|
},
|
|
215
215
|
}));
|
|
216
216
|
const resets = registerResetLifecycle(pi, {
|
|
217
217
|
isEnabled: () => enabled,
|
|
218
|
-
buildReset: (ctx, isCurrent, prompt) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt),
|
|
218
|
+
buildReset: (ctx, isCurrent, prompt, lastWord) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt, lastWord),
|
|
219
219
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
220
220
|
onResetReady: (_ctx, drafts) => {
|
|
221
221
|
const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);
|
|
@@ -5,10 +5,11 @@ import { join } from "node:path";
|
|
|
5
5
|
import test from "node:test";
|
|
6
6
|
import { SessionManager as Manager } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import notesoup from "../src/pi/extension.js";
|
|
8
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
8
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
9
9
|
import { MANUAL_WIPE_TYPE } from "../src/pi/entries.js";
|
|
10
10
|
import { toolContext } from "./helpers/extension.js";
|
|
11
11
|
import { WARNING_CONTENT } from "../src/budget/text.js";
|
|
12
|
+
import { MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../src/pi/reset/artifacts.js";
|
|
12
13
|
import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../src/pi/reset/lifecycle.js";
|
|
13
14
|
const previousNotesHome = process.env.PI_NOTES_HOME;
|
|
14
15
|
const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
|
|
@@ -72,11 +73,11 @@ function harness() {
|
|
|
72
73
|
});
|
|
73
74
|
await command.handler(args, commandCtx);
|
|
74
75
|
};
|
|
75
|
-
const callTool = async (name) => {
|
|
76
|
+
const callTool = async (name, params = {}) => {
|
|
76
77
|
const tool = tools.get(name);
|
|
77
78
|
assert.ok(tool, `${name} is registered`);
|
|
78
79
|
// Pi 1.0 hands a tool the session context plus the nested-call surface; toolContext builds it.
|
|
79
|
-
return tool.execute("call",
|
|
80
|
+
return tool.execute("call", params, new AbortController().signal, () => { }, toolContext(ctx));
|
|
80
81
|
};
|
|
81
82
|
return { sessionManager, handlers, sent, notices, emit, runCommand, callTool };
|
|
82
83
|
}
|
|
@@ -603,3 +604,46 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
603
604
|
CONTINUATION_TYPE,
|
|
604
605
|
], "the persisted reset shape remains marker -> boot -> continuation");
|
|
605
606
|
});
|
|
607
|
+
test("a clear_memory last word lands as a visible entry after the continuation", async () => {
|
|
608
|
+
const h = harness();
|
|
609
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
610
|
+
await h.callTool("clear_memory", { last_word: "feed the ants" });
|
|
611
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
612
|
+
const lastWords = boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE);
|
|
613
|
+
assert.equal(lastWords.length, 1, "the boundary persists exactly one parting line");
|
|
614
|
+
assert.deepEqual(lastWords[0], { type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: "feed the ants", display: true });
|
|
615
|
+
const continuationIndex = boundary.entries.findIndex((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
616
|
+
assert.ok(boundary.entries.indexOf(lastWords[0]) > continuationIndex, "the parting line follows the continuation");
|
|
617
|
+
});
|
|
618
|
+
test("clear_memory sanitizes the last word: trim, cap, and blank persists no entry", async () => {
|
|
619
|
+
assert.equal(sanitizeLastWord(" hi "), "hi");
|
|
620
|
+
assert.equal(sanitizeLastWord(" "), undefined);
|
|
621
|
+
assert.equal(sanitizeLastWord(undefined), undefined);
|
|
622
|
+
assert.equal(sanitizeLastWord("x".repeat(MAX_LAST_WORD_CHARS + 10))?.length, MAX_LAST_WORD_CHARS + 1, "capped with an ellipsis");
|
|
623
|
+
const h = harness();
|
|
624
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
625
|
+
await h.callTool("clear_memory", { last_word: " " });
|
|
626
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
627
|
+
assert.equal(boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a blank last word persists no entry");
|
|
628
|
+
});
|
|
629
|
+
test("reset-control: a tool request carries its last word to the turn-end commit", () => {
|
|
630
|
+
const windowId = "pcw:test:window";
|
|
631
|
+
const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
|
632
|
+
assert.equal(armed.effect, "close-out-armed");
|
|
633
|
+
assert.deepEqual(armed.state.request, { phase: "tool-requested", windowId, source: "tool", lastWord: "the shoes were loyal" });
|
|
634
|
+
const commit = reduceResetControl(armed.state, { type: "turn_end", facts: turnEndFacts() });
|
|
635
|
+
assert.equal(commit.effect, "commit-boundary");
|
|
636
|
+
assert.equal(commit.lastWord, "the shoes were loyal");
|
|
637
|
+
});
|
|
638
|
+
test("reset-control: a manual close-out adopts the acknowledging call's last word and still stops at settlement", () => {
|
|
639
|
+
const windowId = "pcw:test:window";
|
|
640
|
+
const manual = reduceResetControl(initialResetControl(), { type: "close_out", windowId, source: "manual" });
|
|
641
|
+
const ack = reduceResetControl(manual.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
|
|
642
|
+
assert.equal(ack.effect, "already-pending", "the acknowledgement never converts the manual close-out");
|
|
643
|
+
assert.deepEqual(ack.state.request, { phase: "close-out", windowId, source: "manual", lastWord: "tell them I was funny" });
|
|
644
|
+
const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "close_out", windowId, source: "manual" }).state, { type: "tool_request", windowId });
|
|
645
|
+
assert.deepEqual(silentAck.state.request, { phase: "close-out", windowId, source: "manual" }, "no new key without a last word");
|
|
646
|
+
const commit = reduceResetControl(ack.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
647
|
+
assert.equal(commit.effect, "commit-boundary-stop");
|
|
648
|
+
assert.equal(commit.lastWord, "tell them I was funny");
|
|
649
|
+
});
|