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.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/dist/src/boot/text.d.ts +3 -3
  3. package/dist/src/boot/text.js +5 -5
  4. package/dist/src/budget/text.d.ts +5 -3
  5. package/dist/src/budget/text.js +5 -3
  6. package/dist/src/dsh/index.js +1 -1
  7. package/dist/src/dsh/tools.js +2 -2
  8. package/dist/src/pi/entries.d.ts +1 -0
  9. package/dist/src/pi/entries.js +1 -0
  10. package/dist/src/pi/reset/artifacts.d.ts +8 -2
  11. package/dist/src/pi/reset/artifacts.js +12 -3
  12. package/dist/src/pi/reset/lifecycle.d.ts +6 -2
  13. package/dist/src/pi/reset/lifecycle.js +29 -19
  14. package/dist/src/pi/runtime.js +19 -15
  15. package/dist/test/agent-loop.test.js +37 -37
  16. package/dist/test/boot.integration.test.js +11 -11
  17. package/dist/test/claude-mod.test.js +8 -8
  18. package/dist/test/dependencies.test.js +2 -2
  19. package/dist/test/dsh-cli.test.js +1 -1
  20. package/dist/test/dsh.test.js +7 -7
  21. package/dist/test/host-neutral.test.js +1 -1
  22. package/dist/test/notes.integration.test.js +1 -1
  23. package/dist/test/reset-lifecycle.test.js +59 -10
  24. package/docs/architecture.md +3 -3
  25. package/docs/claude-code-mod.md +3 -3
  26. package/docs/dsh.md +3 -3
  27. package/docs/reset-lifecycle.md +7 -7
  28. package/docs/tool-results.md +1 -1
  29. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  30. package/mods/notesoup/dist/claude/helper.js +492 -490
  31. package/mods/notesoup/hooks/register.ts +10 -9
  32. package/mods/notesoup/skills/memory/SKILL.md +1 -1
  33. package/package.json +1 -1
  34. package/skills/memory/SKILL.md +1 -1
  35. package/src/boot/text.ts +5 -5
  36. package/src/budget/text.ts +6 -3
  37. package/src/dsh/index.ts +1 -1
  38. package/src/dsh/tools.ts +2 -2
  39. package/src/pi/entries.ts +1 -0
  40. package/src/pi/reset/artifacts.ts +15 -2
  41. package/src/pi/reset/lifecycle.ts +35 -22
  42. package/src/pi/runtime.ts +18 -15
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # notesoup
2
2
 
3
- Your agent's memory gets wiped when the context fills. notesoup makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, `/clear-memory` to force a fresh window, `/notesoup` to toggle.
3
+ Your agent's memory gets wiped when the context fills. notesoup makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, `/fresh-window` to force a fresh window, `/notesoup` to toggle.
4
4
 
5
5
  The architecture — durable context windows, model-authored notes, searchable history — is the one OpenAI prototyped in Codex's `context_management` experiment and switched off ten days later, because it was welded to their backend. notesoup is the same architecture running entirely on your machine, built only on [Pi](https://github.com/earendil-works/pi)'s public extension APIs. No backend, no subscription gate, no server that can 404 at the worst possible moment. It can't be switched off from far away, because there is no far away.
6
6
 
@@ -28,7 +28,7 @@ pi -e npm:notesoup
28
28
 
29
29
  ## What you get
30
30
 
31
- - **Durable context windows.** `/clear-memory` (alias `/cm`) clears and stops; `/cm Continue reviewing the implementation` clears and continues. The model can also request a window itself with `clear_memory`, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
31
+ - **Durable context windows.** `/fresh-window` (alias `/neuralyze`) clears and stops; `/fresh-window Continue reviewing the implementation` clears and continues. The model can also request a window itself with `neuralyze`, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
32
32
  - **A boot block at every window head.** Static once-per-window content (cache-stable) with the window identity, the recent-notes index, and a short protocol teaching the model how to recover: notes for its own bookkeeping, history tools for everything before the reset.
33
33
  - **`get_context_remaining`** — the live countdown to the close-out line, so the agent can see the cliff before it drives off it.
34
34
  - **Eight history/notes tools**, flattened from the original Codex actions:
@@ -10,9 +10,9 @@ export declare const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_proto
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 declare const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `clear_memory` and erase yourself with dignity.";
13
+ export declare 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 declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/clear-memory`.";
15
+ export declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
16
16
  /** Logical tool names are supplied by the composing host, not discovered here. */
17
17
  export type BootToolNames = Readonly<{
18
18
  notes: string;
@@ -31,6 +31,6 @@ export declare const DEFAULT_BOOT_TOOL_NAMES: {
31
31
  readonly notesList: "notes_list";
32
32
  readonly history: "history_*";
33
33
  readonly remaining: "get_context_remaining";
34
- readonly wipe: "clear_memory";
34
+ readonly wipe: "neuralyze";
35
35
  };
36
36
  export declare function renderProtocolBlock(tools: BootToolNames): string;
@@ -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 `clear_memory` and erase yourself with dignity.";
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 `/clear-memory`.";
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
  * Static protocol teaching adapted from Codex's token_budget.guidance_message to
18
18
  * notesoup's tool names. It lives once per window in the persisted boot block;
@@ -58,7 +58,7 @@ export const DEFAULT_BOOT_TOOL_NAMES = {
58
58
  notesList: "notes_list",
59
59
  history: "history_*",
60
60
  remaining: "get_context_remaining",
61
- wipe: "clear_memory",
61
+ wipe: "neuralyze",
62
62
  };
63
63
  export function renderProtocolBlock(tools) {
64
64
  const names = {
@@ -66,12 +66,12 @@ export function renderProtocolBlock(tools) {
66
66
  notes_list: tools.notesList,
67
67
  "history_*": tools.history,
68
68
  get_context_remaining: tools.remaining,
69
- clear_memory: tools.wipe,
69
+ neuralyze: tools.wipe,
70
70
  };
71
71
  // The sentence is replaced before name substitution, so a replacement may speak the host's
72
72
  // own words (a command line, a tool name) instead of any `notes_*`-style token.
73
73
  const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
74
74
  ? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
75
75
  : PROTOCOL_BLOCK;
76
- return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
76
+ return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)neuralyze/g, (name) => names[name]);
77
77
  }
@@ -9,9 +9,11 @@ export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea
9
9
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
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
- 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
- /** The shared hidden checkpoint text: one manual/budget-triggered request, both hosts. */
14
- 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.\n</context_window_guidance>";
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 `neuralyze` to reset now instead of being cut off mid-task.";
13
+ /** Pi-only nudge: pi's neuralyze persists a parting line; the dsh tool has no such parameter. */
14
+ export declare 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.";
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 `neuralyze` to reset now instead of being cut off mid-task.\nIf you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.\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
  /**
@@ -9,9 +9,11 @@ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Defini
9
9
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
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
- 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
- /** The shared hidden checkpoint text: one manual/budget-triggered request, both hosts. */
14
- export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${GUIDANCE_CLOSE_TAG}`;
12
+ export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`neuralyze\` to reset now instead of being cut off mid-task.`;
13
+ /** Pi-only nudge: pi's neuralyze persists a parting line; the dsh tool has no such parameter. */
14
+ 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.";
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
  /**
@@ -33,7 +33,7 @@ export function apply(ctx) {
33
33
  const state = engine.windows.get(agent.session);
34
34
  const phase = budget.remaining <= budget.warning ? "warning" : budget.remaining <= budget.reminder ? "reminder" : undefined;
35
35
  if (phase && !(phase === "warning" ? state.warned : state.reminded || state.warned)) {
36
- const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "clear_memory");
36
+ const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "neuralyze");
37
37
  agent.steer(createUserMessage({ content: [{ type: "text", text }], source: { kind: "notesoup-budget", windowId: state.snapshot.windowId, phase } }));
38
38
  if (phase === "warning")
39
39
  state.warned = true;
@@ -63,7 +63,7 @@ export function registerTools(ctx, engine) {
63
63
  if (!exec.agent)
64
64
  return;
65
65
  const state = engine.windows.get(exec.agent.session);
66
- if (exec.name === "clear_memory" && !result.isError && result.value.window_id === state.snapshot.windowId) {
66
+ if (exec.name === "neuralyze" && !result.isError && result.value.window_id === state.snapshot.windowId) {
67
67
  if (!exec.parent)
68
68
  state.pendingReset = true;
69
69
  else {
@@ -85,7 +85,7 @@ export function registerTools(ctx, engine) {
85
85
  register(ctx, historyRead, async (agent) => [await historyProjection(ctx, agent.session.id)]);
86
86
  register(ctx, historyWindows, async (agent) => [await historyProjection(ctx, agent.session.id), agent.session.id]);
87
87
  ctx.tools.register(defineTool({
88
- name: "clear_memory",
88
+ name: "neuralyze",
89
89
  description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history stay on disk.",
90
90
  parameters: {},
91
91
  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.` }] },
@@ -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";
@@ -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,19 @@ export type ResetTailState = {
5
5
  readonly boot: boolean;
6
6
  readonly continuation: boolean;
7
7
  };
8
+ /** A sticky note, not a letter: over this, neuralyze refuses instead of truncating. */
9
+ export declare const MAX_LAST_WORD_CHARS = 250;
10
+ /** How the next window finds the note. */
11
+ export declare const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
12
+ /** Trim a parting line; blank input leaves no last word. Length is checked by the caller. */
13
+ export declare function sanitizeLastWord(raw: string | undefined): string | undefined;
8
14
  /** Match the hidden continuation entry that carries the one reset message. */
9
15
  export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
10
16
  /**
11
17
  * 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.
18
+ * continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
13
19
  */
14
- export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string): Promise<SessionBoundaryDraft[]>;
20
+ export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string, lastWord?: string): Promise<SessionBoundaryDraft[]>;
15
21
  /**
16
22
  * Inspect the persisted tail of a reset marker. It reports which reset messages are present
17
23
  * only while the tail stays repairable: metadata may follow the marker, but real conversation,
@@ -1,8 +1,16 @@
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
+ /** A sticky note, not a letter: over this, neuralyze refuses instead of truncating. */
7
+ export const MAX_LAST_WORD_CHARS = 250;
8
+ /** How the next window finds the note. */
9
+ export const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
10
+ /** Trim a parting line; blank input leaves no last word. Length is checked by the caller. */
11
+ export function sanitizeLastWord(raw) {
12
+ return raw?.trim() || undefined;
13
+ }
6
14
  /** Match the hidden continuation entry that carries the one reset message. */
7
15
  export function isWindowContinuationEntry(entry) {
8
16
  return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
@@ -13,9 +21,9 @@ function sendContinuation(pi) {
13
21
  }
14
22
  /**
15
23
  * 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.
24
+ * continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
17
25
  */
18
- export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt) {
26
+ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt, lastWord) {
19
27
  const sessionId = ctx.sessionManager.getSessionId();
20
28
  const previousId = currentWindowId(ctx);
21
29
  const sessionPrefix = sessionId.slice(0, 8);
@@ -30,6 +38,7 @@ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = (
30
38
  { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
31
39
  { type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
32
40
  { type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
41
+ ...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
33
42
  ...(prompt ? [{ type: "custom_message", customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
34
43
  ];
35
44
  }
@@ -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
- if (request.source === "manual")
61
- return { state, effect: "already-pending" };
62
- return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "automatic" } }, effect: "close-out-armed" };
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)
@@ -246,7 +256,7 @@ export function registerResetLifecycle(pi, options) {
246
256
  const markerExists = currentReset(ctx) !== undefined;
247
257
  if (options.isEnabled() || markerExists) {
248
258
  if (event.reason === "manual") {
249
- ctx.ui.notify("🥣 /compact is off while notesoup is on · use /clear-memory", "warning");
259
+ ctx.ui.notify("🥣 /compact is off while notesoup is on · use /fresh-window", "warning");
250
260
  }
251
261
  return { cancel: true };
252
262
  }
@@ -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
  },
@@ -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, 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 } from "./boot.js";
@@ -132,7 +132,7 @@ export function registerContext(pi, settingsManager) {
132
132
  catch (error) {
133
133
  if (missingBootNotice !== windowId) {
134
134
  missingBootNotice = windowId;
135
- ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /clear-memory", "error");
135
+ ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /fresh-window", "error");
136
136
  }
137
137
  ctx.abort();
138
138
  const safeHead = getCurrentSystemMessage(event.messages);
@@ -166,8 +166,8 @@ export function registerContext(pi, settingsManager) {
166
166
  cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
167
167
  },
168
168
  });
169
- const clearMemoryCommand = {
170
- description: "Close out notes and clear memory; optionally append a prompt to continue in the fresh window",
169
+ const neuralyzeCommand = {
170
+ description: "Flush memory to notes and continue in a fresh window; optional prompt runs there",
171
171
  handler: async (args, cmdCtx) => {
172
172
  if (!enabled) {
173
173
  cmdCtx.ui.notify("🥣 notesoup is off · run /notesoup on first", "error");
@@ -185,7 +185,7 @@ export function registerContext(pi, settingsManager) {
185
185
  const prompt = args.trim() || undefined;
186
186
  const armed = resets.closeOut(requestedWindowId, "manual", prompt);
187
187
  if (armed === "already-pending") {
188
- cmdCtx.ui.notify("🥣 Clear-memory already queued · the first prompt is kept", "info");
188
+ cmdCtx.ui.notify("🥣 Neuralyze already queued · the first prompt is kept", "info");
189
189
  return;
190
190
  }
191
191
  cmdCtx.ui.notify(prompt
@@ -196,26 +196,30 @@ export function registerContext(pi, settingsManager) {
196
196
  }
197
197
  catch (error) {
198
198
  resets.clear();
199
- cmdCtx.ui.notify(`🥣 Couldn't start clear-memory: ${errorMessage(error)}`, "error");
199
+ cmdCtx.ui.notify(`🥣 Couldn't start /fresh-window: ${errorMessage(error)}`, "error");
200
200
  }
201
201
  },
202
202
  };
203
- pi.registerCommand("clear-memory", clearMemoryCommand);
204
- pi.registerCommand("cm", clearMemoryCommand);
203
+ pi.registerCommand("neuralyze", neuralyzeCommand);
204
+ pi.registerCommand("fresh-window", neuralyzeCommand);
205
205
  pi.registerTool(defineTool({
206
- name: "clear_memory",
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, _params, _signal, _update, ctx) {
206
+ name: "neuralyze",
207
+ label: "Neuralyze",
208
+ 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.",
209
+ 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 }),
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
+ const lastWord = sanitizeLastWord(params.last_word);
214
+ const length = lastWord ? Array.from(lastWord).length : 0;
215
+ if (length > MAX_LAST_WORD_CHARS)
216
+ return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
217
+ return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
214
218
  },
215
219
  }));
216
220
  const resets = registerResetLifecycle(pi, {
217
221
  isEnabled: () => enabled,
218
- buildReset: (ctx, isCurrent, prompt) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt),
222
+ buildReset: (ctx, isCurrent, prompt, lastWord) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt, lastWord),
219
223
  getLifecycleGeneration: () => lifecycleGeneration,
220
224
  onResetReady: (_ctx, drafts) => {
221
225
  const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);