notesoup 0.45.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +5 -5
- package/dist/src/budget/text.d.ts +5 -3
- package/dist/src/budget/text.js +5 -3
- package/dist/src/dsh/index.js +1 -1
- package/dist/src/dsh/tools.js +2 -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 +8 -2
- package/dist/src/pi/reset/artifacts.js +12 -3
- package/dist/src/pi/reset/lifecycle.d.ts +6 -2
- package/dist/src/pi/reset/lifecycle.js +29 -19
- package/dist/src/pi/runtime.js +19 -15
- package/dist/test/agent-loop.test.js +37 -37
- package/dist/test/boot.integration.test.js +11 -11
- package/dist/test/claude-mod.test.js +8 -8
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh-cli.test.js +1 -1
- package/dist/test/dsh.test.js +7 -7
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/notes.integration.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +59 -10
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +3 -3
- package/docs/dsh.md +3 -3
- package/docs/reset-lifecycle.md +7 -7
- package/docs/tool-results.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +492 -490
- package/mods/notesoup/hooks/register.ts +10 -9
- package/mods/notesoup/skills/memory/SKILL.md +1 -1
- package/package.json +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/text.ts +5 -5
- package/src/budget/text.ts +6 -3
- package/src/dsh/index.ts +1 -1
- package/src/dsh/tools.ts +2 -2
- package/src/pi/entries.ts +1 -0
- package/src/pi/reset/artifacts.ts +15 -2
- package/src/pi/reset/lifecycle.ts +35 -22
- package/src/pi/runtime.ts +18 -15
|
@@ -25,18 +25,18 @@ type ResetState = {
|
|
|
25
25
|
}
|
|
26
26
|
const HEADLESS = "Clear-memory is off in headless (-p / SDK) sessions"
|
|
27
27
|
const COMPACT_DISABLED = "Clear-memory can't run: compaction is off in this session (DISABLE_COMPACT)"
|
|
28
|
-
const THRESHOLDS_UNAVAILABLE = "Context thresholds unavailable · automatic
|
|
29
|
-
const SETTINGS_UNAVAILABLE = "Notesoup settings unreadable · using the default
|
|
28
|
+
const THRESHOLDS_UNAVAILABLE = "Context thresholds unavailable · automatic flush skipped"
|
|
29
|
+
const SETTINGS_UNAVAILABLE = "Notesoup settings unreadable · using the default flush margins"
|
|
30
30
|
/** Bounded retries: a transient helper failure must not disable thresholds for a whole window. */
|
|
31
31
|
const MAX_LIMITS_ATTEMPTS = 3
|
|
32
32
|
const RESET_INSTRUCTIONS = "notesoup: reset to a fresh notes-only context window."
|
|
33
33
|
const BOOT_TOOLS = {
|
|
34
34
|
notes: `${PREFIX}notes_*`, notesList: `${PREFIX}notes_list`,
|
|
35
35
|
history: "history_* (unavailable in Claude)",
|
|
36
|
-
remaining: "get_context_remaining (unavailable in Claude)", wipe: "/
|
|
36
|
+
remaining: "get_context_remaining (unavailable in Claude)", wipe: "/fresh-window (user command; no model reset tool in Claude)",
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** The boot names the host's own wipe path, so the protocol block speaks about `/
|
|
39
|
+
/** The boot names the host's own wipe path, so the protocol block speaks about `/fresh-window`. */
|
|
40
40
|
async function buildBoot($: Engine, identity: Identity, window: number, texts?: SharedTexts) {
|
|
41
41
|
const tools = texts?.wipeSentence === undefined ? BOOT_TOOLS : { ...BOOT_TOOLS, wipeSentence: texts.wipeSentence }
|
|
42
42
|
return run($, { op: "boot", identity, window, tools }, identity.cwd)
|
|
@@ -102,7 +102,7 @@ async function contextUsage($: Engine, state: ResetState): Promise<ContextUsage
|
|
|
102
102
|
} catch {
|
|
103
103
|
if (!state.usageFailureLogged) {
|
|
104
104
|
state.usageFailureLogged = true
|
|
105
|
-
log($, "Context usage unavailable · automatic
|
|
105
|
+
log($, "Context usage unavailable · automatic flush skipped")
|
|
106
106
|
}
|
|
107
107
|
return undefined
|
|
108
108
|
}
|
|
@@ -258,7 +258,8 @@ export function register(on: On) {
|
|
|
258
258
|
registered.clear()
|
|
259
259
|
await loadTexts($, state)
|
|
260
260
|
armManual($, state, manualSignal)
|
|
261
|
-
await $.command.register({ name: "
|
|
261
|
+
await $.command.register({ name: "neuralyze", description: "Reset context to a fresh notes-only window", immediate: true })
|
|
262
|
+
await $.command.register({ name: "fresh-window", description: "Reset context to a fresh notes-only window", immediate: true })
|
|
262
263
|
const schemas = await run($, { op: "schemas" }, e.cwd)
|
|
263
264
|
if (!schemas.ok || !Array.isArray(schemas.result)) return next(e)
|
|
264
265
|
for (const row of schemas.result as SchemaRow[]) {
|
|
@@ -306,11 +307,11 @@ export function register(on: On) {
|
|
|
306
307
|
return result
|
|
307
308
|
})
|
|
308
309
|
on("command.run", async ($, e, next) => {
|
|
309
|
-
if (e.command !== "
|
|
310
|
-
if (!await refreshIdentity($, state)) return { text: "🥣 Session changed · try
|
|
310
|
+
if (e.command !== "neuralyze" && e.command !== "fresh-window") return next(e)
|
|
311
|
+
if (!await refreshIdentity($, state)) return { text: "🥣 Session changed · try /fresh-window again" }
|
|
311
312
|
if (state.headless) return { text: `🥣 ${HEADLESS}` }
|
|
312
313
|
if (state.compactDisabled) return { text: `🥣 ${COMPACT_DISABLED}` }
|
|
313
|
-
if (state.resetting || state.manualPending) return { text: "🥣
|
|
314
|
+
if (state.resetting || state.manualPending) return { text: "🥣 Neuralyze already queued" }
|
|
314
315
|
if (state.turnRunning) {
|
|
315
316
|
state.manualPending = true
|
|
316
317
|
return { text: "🥣 Clear-memory queued · runs after this turn" }
|
|
@@ -53,7 +53,7 @@ Before a long or risky step, or when room runs low, keep session notes named for
|
|
|
53
53
|
- how the work was being done, and which skills are still needed
|
|
54
54
|
- where to dig: seqs, note addresses, files
|
|
55
55
|
|
|
56
|
-
`get_context_remaining` reports the room left. `
|
|
56
|
+
`get_context_remaining` reports the room left. `neuralyze` starts a fresh window, so save the note first.
|
|
57
57
|
|
|
58
58
|
## When a tool is missing or refuses
|
|
59
59
|
|
package/package.json
CHANGED
package/skills/memory/SKILL.md
CHANGED
|
@@ -53,7 +53,7 @@ Before a long or risky step, or when room runs low, keep session notes named for
|
|
|
53
53
|
- how the work was being done, and which skills are still needed
|
|
54
54
|
- where to dig: seqs, note addresses, files
|
|
55
55
|
|
|
56
|
-
`get_context_remaining` reports the room left. `
|
|
56
|
+
`get_context_remaining` reports the room left. `neuralyze` starts a fresh window, so save the note first.
|
|
57
57
|
|
|
58
58
|
## When a tool is missing or refuses
|
|
59
59
|
|
package/src/boot/text.ts
CHANGED
|
@@ -10,9 +10,9 @@ export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
|
10
10
|
* The one sentence that tells the model how to end its window voluntarily. A host with no
|
|
11
11
|
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
12
12
|
*/
|
|
13
|
-
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `
|
|
13
|
+
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `neuralyze` and erase yourself with dignity.";
|
|
14
14
|
/** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
|
|
15
|
-
export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/
|
|
15
|
+
export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
@@ -74,7 +74,7 @@ export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
|
74
74
|
notesList: "notes_list",
|
|
75
75
|
history: "history_*",
|
|
76
76
|
remaining: "get_context_remaining",
|
|
77
|
-
wipe: "
|
|
77
|
+
wipe: "neuralyze",
|
|
78
78
|
} as const satisfies BootToolNames;
|
|
79
79
|
|
|
80
80
|
export function renderProtocolBlock(tools: BootToolNames): string {
|
|
@@ -83,12 +83,12 @@ export function renderProtocolBlock(tools: BootToolNames): string {
|
|
|
83
83
|
notes_list: tools.notesList,
|
|
84
84
|
"history_*": tools.history,
|
|
85
85
|
get_context_remaining: tools.remaining,
|
|
86
|
-
|
|
86
|
+
neuralyze: tools.wipe,
|
|
87
87
|
};
|
|
88
88
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
89
89
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
90
90
|
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
91
91
|
? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence!)
|
|
92
92
|
: PROTOCOL_BLOCK;
|
|
93
|
-
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|
|
|
93
|
+
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)neuralyze/g, (name) => names[name]!);
|
|
94
94
|
}
|
package/src/budget/text.ts
CHANGED
|
@@ -13,10 +13,13 @@ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Defini
|
|
|
13
13
|
export const WARNING_BODY =
|
|
14
14
|
"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.";
|
|
15
15
|
|
|
16
|
-
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`
|
|
16
|
+
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`neuralyze\` to reset now instead of being cut off mid-task.`;
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
export const
|
|
18
|
+
/** Pi-only nudge: pi's neuralyze persists a parting line; the dsh tool has no such parameter. */
|
|
19
|
+
export const LAST_WORD_HINT = "If you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
20
|
+
|
|
21
|
+
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
|
|
22
|
+
export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
|
|
20
23
|
|
|
21
24
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
22
25
|
export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
|
package/src/dsh/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function apply(ctx: Context): void {
|
|
|
43
43
|
const state = engine.windows.get(agent.session);
|
|
44
44
|
const phase = budget.remaining <= budget.warning ? "warning" : budget.remaining <= budget.reminder ? "reminder" : undefined;
|
|
45
45
|
if (phase && !(phase === "warning" ? state.warned : state.reminded || state.warned)) {
|
|
46
|
-
const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "
|
|
46
|
+
const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "neuralyze");
|
|
47
47
|
agent.steer(createUserMessage({ content: [{ type: "text", text }], source: { kind: "notesoup-budget", windowId: state.snapshot.windowId, phase } }));
|
|
48
48
|
if (phase === "warning") state.warned = true;
|
|
49
49
|
else state.reminded = true;
|
package/src/dsh/tools.ts
CHANGED
|
@@ -60,7 +60,7 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
|
|
|
60
60
|
ctx.on("tools/result", (exec, result) => {
|
|
61
61
|
if (!exec.agent) return;
|
|
62
62
|
const state = engine.windows.get(exec.agent.session);
|
|
63
|
-
if (exec.name === "
|
|
63
|
+
if (exec.name === "neuralyze" && !result.isError && (result.value as { window_id?: string }).window_id === state.snapshot.windowId) {
|
|
64
64
|
if (!exec.parent) state.pendingReset = true;
|
|
65
65
|
else {
|
|
66
66
|
const roots = nestedResets.get(exec.agent) ?? new Set<string>();
|
|
@@ -80,7 +80,7 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
|
|
|
80
80
|
register(ctx, historyRead, async (agent) => [await historyProjection(ctx, agent.session.id)] as const);
|
|
81
81
|
register(ctx, historyWindows, async (agent) => [await historyProjection(ctx, agent.session.id), agent.session.id] as const);
|
|
82
82
|
ctx.tools.register(defineTool({
|
|
83
|
-
name: "
|
|
83
|
+
name: "neuralyze",
|
|
84
84
|
description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history stay on disk.",
|
|
85
85
|
parameters: {},
|
|
86
86
|
output: { schema: { type: "object", properties: { window_id: { type: "string", required: true }, reset_requested: { type: "boolean", required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: `notesoup: reset requested for ${value.window_id}; finish this tool batch, then recover from your notes.` }] },
|
package/src/pi/entries.ts
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";
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
|
|
3
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
|
|
4
4
|
import { CONTINUATION } from "../../budget/text.js";
|
|
5
5
|
import { currentWindowId, isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, previousWindowId, type WindowMarker } from "../window.js";
|
|
6
6
|
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "../boot.js";
|
|
7
7
|
|
|
8
8
|
export type ResetTailState = { readonly boot: boolean; readonly continuation: boolean };
|
|
9
9
|
|
|
10
|
+
/** A sticky note, not a letter: over this, neuralyze refuses instead of truncating. */
|
|
11
|
+
export const MAX_LAST_WORD_CHARS = 250;
|
|
12
|
+
|
|
13
|
+
/** How the next window finds the note. */
|
|
14
|
+
export const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
|
|
15
|
+
|
|
16
|
+
/** Trim a parting line; blank input leaves no last word. Length is checked by the caller. */
|
|
17
|
+
export function sanitizeLastWord(raw: string | undefined): string | undefined {
|
|
18
|
+
return raw?.trim() || undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
/** Match the hidden continuation entry that carries the one reset message. */
|
|
11
22
|
export function isWindowContinuationEntry(entry: SessionEntry): boolean {
|
|
12
23
|
return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
|
|
@@ -22,13 +33,14 @@ function sendContinuation(pi: ExtensionAPI): void {
|
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
35
|
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
25
|
-
* continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
36
|
+
* continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
|
|
26
37
|
*/
|
|
27
38
|
export async function buildResetDrafts(
|
|
28
39
|
ctx: ExtensionContext,
|
|
29
40
|
notifyIncompleteNotes?: IncompleteNotesNotifier,
|
|
30
41
|
isCurrent: () => boolean = () => true,
|
|
31
42
|
prompt?: string,
|
|
43
|
+
lastWord?: string,
|
|
32
44
|
): Promise<SessionBoundaryDraft[]> {
|
|
33
45
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
34
46
|
const previousId = currentWindowId(ctx);
|
|
@@ -46,6 +58,7 @@ export async function buildResetDrafts(
|
|
|
46
58
|
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
|
|
47
59
|
{ type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
|
|
48
60
|
{ type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
|
|
61
|
+
...(lastWord ? [{ type: "custom_message" as const, customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
|
|
49
62
|
...(prompt ? [{ type: "custom_message" as const, customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
|
|
50
63
|
];
|
|
51
64
|
}
|
|
@@ -15,7 +15,7 @@ type BudgetOwner = {
|
|
|
15
15
|
type ResetOptions = {
|
|
16
16
|
isEnabled: () => boolean;
|
|
17
17
|
budget: BudgetOwner;
|
|
18
|
-
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
18
|
+
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string, lastWord?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
19
19
|
getLifecycleGeneration?: () => number;
|
|
20
20
|
onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
|
|
21
21
|
};
|
|
@@ -37,8 +37,8 @@ export type ResetRequest =
|
|
|
37
37
|
// The safety reset may change windows before Pi finishes its tool-batch continuation.
|
|
38
38
|
// This run-scoped stop intent survives that change; windowId is the pre-reset window.
|
|
39
39
|
| { readonly phase: "stop-pending"; readonly windowId: string }
|
|
40
|
-
| { readonly phase: "close-out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string }
|
|
41
|
-
| { readonly phase: "tool-requested"; readonly windowId: string; readonly source: ToolResetRequestSource };
|
|
40
|
+
| { readonly phase: "close-out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string; readonly lastWord?: string }
|
|
41
|
+
| { readonly phase: "tool-requested"; readonly windowId: string; readonly source: ToolResetRequestSource; readonly lastWord?: string };
|
|
42
42
|
export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
|
|
43
43
|
|
|
44
44
|
export interface ResetControlState {
|
|
@@ -76,7 +76,7 @@ export interface ResetBeforeSettleFacts {
|
|
|
76
76
|
|
|
77
77
|
export type ResetControlEvent =
|
|
78
78
|
| { readonly type: "close_out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string }
|
|
79
|
-
| { readonly type: "tool_request"; readonly windowId: string }
|
|
79
|
+
| { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string }
|
|
80
80
|
| { readonly type: "turn_end"; readonly facts: ResetTurnEndFacts }
|
|
81
81
|
| { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts }
|
|
82
82
|
| { readonly type: "settled" }
|
|
@@ -96,16 +96,23 @@ export interface ResetControlResult {
|
|
|
96
96
|
readonly state: ResetControlState;
|
|
97
97
|
readonly effect: ResetControlEffect;
|
|
98
98
|
readonly prompt?: string;
|
|
99
|
+
readonly lastWord?: string;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function requestForWindow(request: ResetRequest, windowId: string): ResetRequest {
|
|
102
103
|
return request.phase === "stop-pending" || (request.phase !== "none" && request.windowId === windowId) ? request : NO_REQUEST;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
function manualCommit(prompt?: string): ResetControlResult {
|
|
106
|
+
function manualCommit(prompt?: string, lastWord?: string): ResetControlResult {
|
|
107
|
+
const parting = lastWord ? { lastWord } : {};
|
|
106
108
|
return prompt
|
|
107
|
-
? { state: initialResetControl(), effect: "commit-boundary", prompt }
|
|
108
|
-
: { state: initialResetControl(), effect: "commit-boundary-stop" };
|
|
109
|
+
? { state: initialResetControl(), effect: "commit-boundary", prompt, ...parting }
|
|
110
|
+
: { state: initialResetControl(), effect: "commit-boundary-stop", ...parting };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The parting line rides either committing phase; other phases never carry one. */
|
|
114
|
+
function requestLastWord(request: ResetRequest): string | undefined {
|
|
115
|
+
return request.phase === "close-out" || request.phase === "tool-requested" ? request.lastWord : undefined;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
/** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
|
|
@@ -134,15 +141,20 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
134
141
|
if (request.phase === "tool-requested" && request.windowId === event.windowId) {
|
|
135
142
|
return { state, effect: "already-pending" };
|
|
136
143
|
}
|
|
144
|
+
const parting = event.lastWord ? { lastWord: event.lastWord } : {};
|
|
137
145
|
// A manual close-out must settle so the stop actually lands; the agent's own wipe
|
|
138
146
|
// call during one is only an acknowledgement, never a conversion to a turn-end
|
|
139
147
|
// commit that pi's tool-batch continuation can overrun. A budget close-out still
|
|
140
148
|
// upgrades: context pressure cannot wait for settlement.
|
|
141
149
|
if (request.phase === "close-out" && request.windowId === event.windowId) {
|
|
142
|
-
|
|
143
|
-
|
|
150
|
+
// The acknowledging call still contributes its last word; the manual commit keeps the wheel.
|
|
151
|
+
if (request.source === "manual") {
|
|
152
|
+
const lastWord = request.lastWord ?? event.lastWord;
|
|
153
|
+
return { state: { ...state, request: { ...request, ...(lastWord ? { lastWord } : {}) } }, effect: "already-pending" };
|
|
154
|
+
}
|
|
155
|
+
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "automatic", ...parting } }, effect: "close-out-armed" };
|
|
144
156
|
}
|
|
145
|
-
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool" } }, effect: "close-out-armed" };
|
|
157
|
+
return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool", ...parting } }, effect: "close-out-armed" };
|
|
146
158
|
}
|
|
147
159
|
case "turn_end": {
|
|
148
160
|
const facts = event.facts;
|
|
@@ -165,9 +177,10 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
165
177
|
// A direct tool request commits after the whole tool batch. The budget cutoff is
|
|
166
178
|
// a separate hard-reserve safety path; ordinary close-out waits for settlement.
|
|
167
179
|
if (request.phase === "tool-requested" || facts.hardReserveDue) {
|
|
168
|
-
|
|
169
|
-
if (manual) return
|
|
170
|
-
return { state: { request:
|
|
180
|
+
const lastWord = requestLastWord(request);
|
|
181
|
+
if (manual && request.prompt) return manualCommit(request.prompt, lastWord);
|
|
182
|
+
if (manual) return { state: { request: { phase: "stop-pending", windowId: facts.windowId }, overflow: "idle" }, effect: "commit-boundary-stop", ...(lastWord ? { lastWord } : {}) };
|
|
183
|
+
return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary", ...(lastWord ? { lastWord } : {}) };
|
|
171
184
|
}
|
|
172
185
|
return { state: { request, overflow: "idle" }, effect: "none" };
|
|
173
186
|
}
|
|
@@ -189,7 +202,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
189
202
|
}
|
|
190
203
|
// An explicit manual wipe is not an automatic recovery/retry. It must still
|
|
191
204
|
// clear on overflow, including when automatic reset is disabled.
|
|
192
|
-
if (manual && facts.enabled) return manualCommit(request.prompt);
|
|
205
|
+
if (manual && facts.enabled) return manualCommit(request.prompt, requestLastWord(request));
|
|
193
206
|
const spent = state.overflow === "pending-spent";
|
|
194
207
|
if (!facts.enabled || !facts.automaticResetEnabled) {
|
|
195
208
|
return { state: { request: facts.failed ? NO_REQUEST : request, overflow: spent ? "spent" : "idle" }, effect: "none" };
|
|
@@ -200,7 +213,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
200
213
|
return { state: { ...state, request: NO_REQUEST }, effect: "none" };
|
|
201
214
|
}
|
|
202
215
|
if (facts.queued) return { state: { ...state, request }, effect: "none" };
|
|
203
|
-
return manualCommit(request.prompt);
|
|
216
|
+
return manualCommit(request.prompt, requestLastWord(request));
|
|
204
217
|
}
|
|
205
218
|
case "settled":
|
|
206
219
|
return { state: initialResetControl(), effect: "none" };
|
|
@@ -225,7 +238,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
225
238
|
let control = initialResetControl();
|
|
226
239
|
|
|
227
240
|
const clear = () => { control = reduceResetControl(control, { type: "clear" }).state; };
|
|
228
|
-
const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, continueAfterReset: boolean, prompt?: string) => {
|
|
241
|
+
const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, continueAfterReset: boolean, prompt?: string, lastWord?: string) => {
|
|
229
242
|
const generation = lifecycleGeneration;
|
|
230
243
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
231
244
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -235,7 +248,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
235
248
|
ctx.signal?.aborted !== true && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
236
249
|
let resetDrafts: SessionBoundaryDraft[];
|
|
237
250
|
try {
|
|
238
|
-
resetDrafts = await options.buildReset(ctx, isCurrent, prompt);
|
|
251
|
+
resetDrafts = await options.buildReset(ctx, isCurrent, prompt, lastWord);
|
|
239
252
|
} catch (error) {
|
|
240
253
|
if (isCurrent()) ctx.ui.notify(`🥣 Couldn't clear memory: ${errorMessage(error)}${prompt ? " · your prompt was not sent" : ""}`, "warning");
|
|
241
254
|
return entries.length > 0 ? { entries } : undefined;
|
|
@@ -281,7 +294,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
281
294
|
},
|
|
282
295
|
});
|
|
283
296
|
control = decision.state;
|
|
284
|
-
if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt);
|
|
297
|
+
if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt, decision.lastWord);
|
|
285
298
|
return entries.length > 0 ? { entries } : undefined;
|
|
286
299
|
});
|
|
287
300
|
|
|
@@ -301,7 +314,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
301
314
|
control = decision.state;
|
|
302
315
|
if (decision.effect === "stop") return { entries: event.entries, continue: false };
|
|
303
316
|
if (decision.effect !== "commit-boundary" && decision.effect !== "commit-boundary-stop" && decision.effect !== "recover-overflow") return undefined;
|
|
304
|
-
return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt);
|
|
317
|
+
return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt, decision.lastWord);
|
|
305
318
|
});
|
|
306
319
|
|
|
307
320
|
pi.on("session_before_compact", (event, ctx) => {
|
|
@@ -310,7 +323,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
310
323
|
const markerExists = currentReset(ctx) !== undefined;
|
|
311
324
|
if (options.isEnabled() || markerExists) {
|
|
312
325
|
if (event.reason === "manual") {
|
|
313
|
-
ctx.ui.notify("🥣 /compact is off while notesoup is on · use /
|
|
326
|
+
ctx.ui.notify("🥣 /compact is off while notesoup is on · use /fresh-window", "warning");
|
|
314
327
|
}
|
|
315
328
|
return { cancel: true };
|
|
316
329
|
}
|
|
@@ -333,8 +346,8 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
333
346
|
control = decision.state;
|
|
334
347
|
return decision.effect;
|
|
335
348
|
},
|
|
336
|
-
request(windowId: string) {
|
|
337
|
-
const decision = reduceResetControl(control, { type: "tool_request", windowId });
|
|
349
|
+
request(windowId: string, lastWord?: string) {
|
|
350
|
+
const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
|
|
338
351
|
control = decision.state;
|
|
339
352
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
340
353
|
},
|
package/src/pi/runtime.ts
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, type WindowMarker } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
|
-
import { buildResetDrafts, repairResetTail } from "./reset/artifacts.js";
|
|
9
|
+
import { buildResetDrafts, MAX_LAST_WORD_CHARS, 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, type IncompleteNotesNotifier } from "./boot.js";
|
|
@@ -128,7 +128,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
128
128
|
} catch (error) {
|
|
129
129
|
if (missingBootNotice !== windowId) {
|
|
130
130
|
missingBootNotice = windowId;
|
|
131
|
-
ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /
|
|
131
|
+
ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /fresh-window", "error");
|
|
132
132
|
}
|
|
133
133
|
ctx.abort();
|
|
134
134
|
const safeHead = getCurrentSystemMessage(event.messages);
|
|
@@ -163,8 +163,8 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
const
|
|
167
|
-
description: "
|
|
166
|
+
const neuralyzeCommand = {
|
|
167
|
+
description: "Flush memory to notes and continue in a fresh window; optional prompt runs there",
|
|
168
168
|
handler: async (args: string, cmdCtx: ExtensionCommandContext) => {
|
|
169
169
|
if (!enabled) {
|
|
170
170
|
cmdCtx.ui.notify("🥣 notesoup is off · run /notesoup on first", "error");
|
|
@@ -181,7 +181,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
181
181
|
const prompt = args.trim() || undefined;
|
|
182
182
|
const armed = resets.closeOut(requestedWindowId, "manual", prompt);
|
|
183
183
|
if (armed === "already-pending") {
|
|
184
|
-
cmdCtx.ui.notify("🥣
|
|
184
|
+
cmdCtx.ui.notify("🥣 Neuralyze already queued · the first prompt is kept", "info");
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
cmdCtx.ui.notify(prompt
|
|
@@ -191,27 +191,30 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
191
191
|
pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: WARNING_CONTENT, display: false }, { triggerTurn: true, deliverAs: "steer" });
|
|
192
192
|
} catch (error) {
|
|
193
193
|
resets.clear();
|
|
194
|
-
cmdCtx.ui.notify(`🥣 Couldn't start
|
|
194
|
+
cmdCtx.ui.notify(`🥣 Couldn't start /fresh-window: ${errorMessage(error)}`, "error");
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
197
|
};
|
|
198
|
-
pi.registerCommand("
|
|
199
|
-
pi.registerCommand("
|
|
198
|
+
pi.registerCommand("neuralyze", neuralyzeCommand);
|
|
199
|
+
pi.registerCommand("fresh-window", neuralyzeCommand);
|
|
200
200
|
|
|
201
201
|
pi.registerTool(defineTool({
|
|
202
|
-
name: "
|
|
203
|
-
label: "
|
|
204
|
-
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive.",
|
|
205
|
-
parameters: Type.Object({}, { additionalProperties: false }),
|
|
206
|
-
async execute(_id,
|
|
202
|
+
name: "neuralyze",
|
|
203
|
+
label: "Neuralyze",
|
|
204
|
+
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.",
|
|
205
|
+
parameters: Type.Object({ last_word: Type.Optional(Type.String({ maxLength: MAX_LAST_WORD_CHARS, description: `A tiny sticky note, at most ${MAX_LAST_WORD_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
|
|
206
|
+
async execute(_id, params, _signal, _update, ctx) {
|
|
207
207
|
if (!enabled) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
208
|
-
|
|
208
|
+
const lastWord = sanitizeLastWord(params.last_word);
|
|
209
|
+
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
210
|
+
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.` });
|
|
211
|
+
return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
|
|
209
212
|
},
|
|
210
213
|
}));
|
|
211
214
|
|
|
212
215
|
const resets = registerResetLifecycle(pi, {
|
|
213
216
|
isEnabled: () => enabled,
|
|
214
|
-
buildReset: (ctx, isCurrent, prompt) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt),
|
|
217
|
+
buildReset: (ctx, isCurrent, prompt, lastWord) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt, lastWord),
|
|
215
218
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
216
219
|
onResetReady: (_ctx, drafts) => {
|
|
217
220
|
const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);
|