notesoup 0.52.2 → 0.52.4

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.
@@ -7,7 +7,7 @@ import { readClaudeHistory } from "./history.js";
7
7
  import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
8
8
  import { renderBootBlock } from "../../../src/boot/render.js";
9
9
  import { selectContinuation } from "../../../src/budget/text.js";
10
- import { CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT, CLAUDE_WIPE_SENTENCE } from "./text.js";
10
+ import { CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
11
11
  import { resolveClaudeLimits } from "./thresholds.js";
12
12
  import { projectKey, snapshotNotesIdentity } from "../../../src/notes/index.js";
13
13
  const MAX_REQUEST_BYTES = 512 * 1024;
@@ -71,9 +71,8 @@ export async function dispatch(request) {
71
71
  // The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
72
72
  // cannot drift apart. The hooks module caches one copy per session.
73
73
  if (value.op === "texts")
74
- return { warning: CLAUDE_WARNING_PROMPT, wipeSentence: CLAUDE_WIPE_SENTENCE, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
75
- // Claude has no model-facing reset tool, so every reset it creates is system-triggered. The
76
- // caller draws once per artifact and caches the answer; text reads never draw.
74
+ return { warning: CLAUDE_WARNING_PROMPT, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
75
+ // The caller draws once per artifact and caches the answer; text reads never draw.
77
76
  if (value.op === "continuation") {
78
77
  if (value.origin !== "normal" && value.origin !== "forced")
79
78
  throw new Error("invalid reset origin");
@@ -1,6 +1,4 @@
1
- /** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
2
- export declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
3
1
  /** Claude's boot says history is missing rather than naming tools it cannot serve. */
4
2
  export declare const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
5
- /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
6
- export declare const CLAUDE_WARNING_PROMPT = "This brain is already spent. Whatever lives only in this brain goes with it \u2014 but the notes stay where they are, and history has the rest written down, though digging it back out is on you.\nUse the last of this brain to put down what the next window can't get back:\n- what you're in the middle of, 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 the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what 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\n- and refresh the stale notes with what has changed since you last wrote them \u2014 the notes the next window gets are the old ones, unless you fix them now\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.\nBrain emptied in 3\u2026 2\u2026";
3
+ /** The same notice as Pi; empty_brain's result explains Claude's deferred reset. */
4
+ export declare const CLAUDE_WARNING_PROMPT: string;
@@ -1,7 +1,5 @@
1
- import { COUNTDOWN_LINE, WARNING_BODY } from "../../../src/budget/text.js";
2
- /** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
3
- export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
1
+ import { warningNotice } from "../../../src/budget/text.js";
4
2
  /** Claude's boot says history is missing rather than naming tools it cannot serve. */
5
3
  export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
6
- /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
7
- export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.\n${COUNTDOWN_LINE}`;
4
+ /** The same notice as Pi; empty_brain's result explains Claude's deferred reset. */
5
+ export const CLAUDE_WARNING_PROMPT = warningNotice();
@@ -5,12 +5,9 @@
5
5
  * is interpolated by renderProtocolBlock; the prose itself stays plain English.
6
6
  */
7
7
  export declare const PI_PRE_RESET_HINTS = "Anything you say here is erased with the reset \u2014 the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.\nUnless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.";
8
- /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
9
- export declare const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
8
+ export { warningNotice as warningContent } from "../../src/budget/text.js";
10
9
  /** The closing model sees deferred input as a bare next-window prompt block. */
11
10
  export declare function promptBlock(commandLine: string): string;
12
- /** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
13
- export declare function warningContent(): string;
14
11
  /** Approved manual close-out notices; both variants live here. */
15
12
  export declare const COMMAND_NOTICE: {
16
13
  prompted: string;
@@ -7,16 +7,11 @@ import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WA
7
7
  */
8
8
  export const PI_PRE_RESET_HINTS = `Anything you say here is erased with the reset — the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.
9
9
  Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
10
- /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
11
- export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
10
+ export { warningNotice as warningContent } from "../../src/budget/text.js";
12
11
  /** The closing model sees deferred input as a bare next-window prompt block. */
13
12
  export function promptBlock(commandLine) {
14
13
  return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
15
14
  }
16
- /** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
17
- export function warningContent() {
18
- return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${WARNING_CALL}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
19
- }
20
15
  /** Approved manual close-out notices; both variants live here. */
21
16
  export const COMMAND_NOTICE = {
22
17
  prompted: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward — put the handoff in your notes. The prompt below, and anything the human sends from now on, should be handled after the reset.",
@@ -25,5 +20,5 @@ export const COMMAND_NOTICE = {
25
20
  /** Manual orders omit budget timing hints; deferred work sits outside the notice. */
26
21
  export function commandWarningContent(commandLine) {
27
22
  const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
28
- return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
23
+ return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
29
24
  }
@@ -13,20 +13,21 @@ export declare const FORCED_CONTINUATIONS: readonly string[];
13
13
  * the caller persists the exact returned text and never redraws it for rendering, history, or repair.
14
14
  */
15
15
  export declare function selectContinuation(origin: ResetOrigin): string;
16
- /**
17
- * The shared warning body: the one text both hosts show before a reset. Only the closing
18
- * instruction differs — Pi can reset the model itself, Claude can only end the turn.
19
- */
20
- export declare const WARNING_BODY = "This brain is already spent. Whatever lives only in this brain goes with it \u2014 but the notes stay where they are, and history has the rest written down, though digging it back out is on you.\nUse the last of this brain to put down what the next window can't get back:\n- what you're in the middle of, 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 the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what 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\n- and refresh the stale notes with what has changed since you last wrote them \u2014 the notes the next window gets are the old ones, unless you fix them now\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
21
- export declare const WARNING_CALL = "The moment the notes are saved, call `empty_brain`. Not one more probe, not one more test \u2014 the next thing you do after saving is reset.";
16
+ /** Budget timing stays out of manual close-outs, which may have plenty of room. */
17
+ export declare const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
18
+ /** The shared handoff instructions, used for both budget and manual close-outs. */
19
+ export declare const WARNING_BODY = "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
20
+ export declare const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
22
21
  export declare function warningPrompt(): string;
22
+ /** Pi and Claude deliver exactly the same second-tier notice. */
23
+ export declare function warningNotice(): string;
23
24
  /**
24
25
  * The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
25
26
  * turn, not on a timer. The first-tier guidance never carries it.
26
27
  */
27
28
  export declare const COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
28
29
  /**
29
- * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
30
+ * First-tier low-budget reminder. The measured remaining count is frozen into
30
31
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
31
32
  * at write time; get_context_remaining remains the live source for the current figure.
32
33
  */
@@ -21,14 +21,17 @@ export function selectContinuation(origin) {
21
21
  const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
22
22
  return pool[Math.floor(Math.random() * pool.length)];
23
23
  }
24
- /**
25
- * The shared warning body: the one text both hosts show before a reset. Only the closing
26
- * instruction differs — Pi can reset the model itself, Claude can only end the turn.
27
- */
28
- export const WARNING_BODY = "This brain is already spent. Whatever lives only in this brain goes with it — but the notes stay where they are, and history has the rest written down, though digging it back out is on you.\nUse the last of this brain to put down what the next window can't get back:\n- what you're in the middle of, 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 the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what 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\n- and refresh the stale notes with what has changed since you last wrote them — the notes the next window gets are the old ones, unless you fix them now\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
29
- export const WARNING_CALL = "The moment the notes are saved, call `empty_brain`. Not one more probe, not one more test — the next thing you do after saving is reset.";
24
+ /** Budget timing stays out of manual close-outs, which may have plenty of room. */
25
+ export const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
26
+ /** The shared handoff instructions, used for both budget and manual close-outs. */
27
+ export const WARNING_BODY = "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
28
+ export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
30
29
  export function warningPrompt() {
31
- return `${WARNING_BODY}\n${WARNING_CALL}`;
30
+ return `${WARNING_TIMING}\n${WARNING_BODY}\n${WARNING_CALL}`;
31
+ }
32
+ /** Pi and Claude deliver exactly the same second-tier notice. */
33
+ export function warningNotice() {
34
+ return `${GUIDANCE_OPEN_TAG}\n${warningPrompt()}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
32
35
  }
33
36
  /**
34
37
  * The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
@@ -36,10 +39,10 @@ export function warningPrompt() {
36
39
  */
37
40
  export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
38
41
  /**
39
- * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
42
+ * First-tier low-budget reminder. The measured remaining count is frozen into
40
43
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
41
44
  * at write time; get_context_remaining remains the live source for the current figure.
42
45
  */
43
46
  export function tokenBudgetGuidance(remaining, wipeTool) {
44
- return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left in your brain.\nYour notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.\nWhat lives only in this brain leaves with it.\nA decent moment to put down where you are, while you still remember why.\nReady when you are: \`${wipeTool}\`.\n${GUIDANCE_CLOSE_TAG}`;
47
+ return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself. But it also wipes what you say to the human right before emptying.\n${GUIDANCE_CLOSE_TAG}`;
45
48
  }
@@ -104,7 +104,7 @@ export declare const notesWriteParameters: Type.TObject<{
104
104
  export declare const notesWrite: {
105
105
  readonly name: "notes_write";
106
106
  readonly label: "Notes write";
107
- readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
107
+ readonly description: "Create a note, or overwrite its whole body. Name it for what it holds and when to use it. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
108
108
  readonly parameters: Type.TObject<{
109
109
  address: Type.TString;
110
110
  content: Type.TString;
@@ -139,7 +139,7 @@ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
139
139
  export declare const notesUpdate: {
140
140
  readonly name: "notes_update";
141
141
  readonly label: "Notes update";
142
- readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
142
+ readonly description: "Change part of a note's body, its origin or crumpled state, or its address. When a line goes stale, replace it; don't append the correction below it. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
143
143
  readonly parameters: Type.TObject<{
144
144
  address: Type.TString;
145
145
  edits: Type.TOptional<Type.TArray<Type.TObject<{
@@ -181,7 +181,7 @@ function renderWriteData(data) {
181
181
  }
182
182
  export const notesWrite = {
183
183
  name: "notes_write", label: "Notes write",
184
- description: `Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
184
+ description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
185
185
  parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
186
186
  async execute(params, identity) {
187
187
  try {
@@ -229,7 +229,7 @@ function boundedUpdate(data) {
229
229
  }
230
230
  export const notesUpdate = {
231
231
  name: "notes_update", label: "Notes update",
232
- description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
232
+ description: `Change part of a note's body, its origin or crumpled state, or its address. When a line goes stale, replace it; don't append the correction below it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
233
233
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
234
234
  async execute(params, identity, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
235
235
  try {
@@ -12,7 +12,7 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
12
12
  const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
13
13
  const guidance = await runContextHook(captured, low);
14
14
  assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
15
- assert.match(String((guidance?.messages[0]).content), /About 18616 tokens of room left in your brain\./, "the reminder reports room to the reserve, not to the warning");
15
+ assert.match(String((guidance?.messages[0]).content), /About 18616 tokens of room left\./, "the reminder reports room to the reserve, not to the warning");
16
16
  assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
17
17
  const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
18
18
  assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
@@ -10,8 +10,8 @@ import { dispatch, handleLine } from "../plugins/claude/src/helper.js";
10
10
  import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../plugins/claude/src/thresholds.js";
11
11
  import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
12
12
  import { PROTOCOL_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
13
- import { CLAUDE_WARNING_PROMPT, CLAUDE_WIPE_SENTENCE } from "../plugins/claude/src/text.js";
14
- import { COUNTDOWN_LINE, FORCED_CONTINUATIONS } from "../src/budget/text.js";
13
+ import { CLAUDE_WARNING_PROMPT } from "../plugins/claude/src/text.js";
14
+ import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, NORMAL_CONTINUATIONS, warningNotice } from "../src/budget/text.js";
15
15
  import { createNotesStore } from "../src/notes/index.js";
16
16
  import { resolveProjectHome } from "../src/notes/project-home.js";
17
17
  import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
@@ -151,12 +151,11 @@ test("Claude helper boot uses actual Claude note tool bindings and a fresh snaps
151
151
  assert.doesNotMatch(boot, /brain empty|continuation/);
152
152
  assert.equal(boot.includes("chat view"), false, "a Claude boot never claims a reset clears the human's view");
153
153
  });
154
- test("Claude helper serves the shared reset prose and the host's wipe sentence", async () => {
154
+ test("Claude helper serves the same reset notice as Pi", async () => {
155
155
  const texts = await dispatch({ op: "texts" });
156
156
  assert.equal(texts.warning, CLAUDE_WARNING_PROMPT, "the helper owns the one warning text the mod shows");
157
- assert.equal(texts.wipeSentence, CLAUDE_WIPE_SENTENCE);
158
- assert.match(texts.warning, /end your turn; the reset runs after it\./);
159
- assert.equal(texts.warning.endsWith(COUNTDOWN_LINE), true, "the Claude notice also ends with the countdown");
157
+ assert.equal(texts.warning, warningNotice());
158
+ assert.equal(texts.warning.endsWith(`${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`), true);
160
159
  assert.equal(texts.continuation, undefined, "a plain text read never draws the reset handoff");
161
160
  const random = Math.random;
162
161
  Math.random = () => 0;
@@ -235,14 +234,13 @@ test("Claude helper resolves limits across the boundary and never throws on nons
235
234
  assert.equal(nonsense.result.unit, "percent");
236
235
  assert.ok(nonsense.result.warn > 0 && nonsense.result.warn < 100);
237
236
  });
238
- test("Claude's wipe sentence replaces only that sentence in the shared protocol block", () => {
239
- const piTools = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "empty_brain" };
240
- const pi = renderProtocolBlock(piTools);
241
- assert.ok(pi.includes(PROTOCOL_WIPE_SENTENCE), "Pi keeps the default sentence, byte for byte");
242
- const claude = renderProtocolBlock({ ...piTools, wipeSentence: CLAUDE_WIPE_SENTENCE });
243
- assert.equal(claude, pi.replace(PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE), "only that sentence changes");
244
- assert.equal(claude.includes("erase yourself with dignity"), false);
245
- assert.ok(claude.includes("end your turn and ask the human to run `/fresh-window`."));
237
+ test("Claude binds the shared reset sentence to its model-facing tool", () => {
238
+ const tools = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "empty_brain" };
239
+ const pi = renderProtocolBlock(tools);
240
+ assert.ok(pi.includes(PROTOCOL_WIPE_SENTENCE));
241
+ const claude = renderProtocolBlock({ ...tools, wipe: "mcp__notesoup__empty_brain" });
242
+ assert.equal(claude, pi.replaceAll("empty_brain", "mcp__notesoup__empty_brain"));
243
+ assert.doesNotMatch(claude, /ask the human to run/);
246
244
  });
247
245
  test("Claude Mod helper runs from a standalone copied plugin directory", () => {
248
246
  const fixture = mkdtempSync(join(tmpdir(), "claude-mod-install-"));
@@ -295,8 +293,7 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
295
293
  assert.equal(boot.name, "notesoup:boot");
296
294
  assert.ok(boot.text.length > 0, "the boot block carries real boot text");
297
295
  assert.match(boot.text, /mcp__notesoup__notes_\*/, "the boot text names the actual Claude note tool binding");
298
- assert.ok(boot.text.includes(CLAUDE_WIPE_SENTENCE), "the boot speaks the Claude wipe path");
299
- assert.equal(boot.text.includes("erase yourself with dignity"), false);
296
+ assert.ok(boot.text.includes("call `mcp__notesoup__empty_brain` and erase yourself with dignity."), "the boot names the registered reset tool");
300
297
  assert.equal(boot.text.includes("chat view"), false, "the Claude boot block carries no Pi-only pre-reset hints");
301
298
  assert.equal(first.sentinel, "kept", "unrelated result fields survive");
302
299
  assert.equal(bootRequests, 1, "the first prompt makes exactly one boot helper request");
@@ -455,7 +452,7 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
455
452
  const handlers = new Map();
456
453
  hooks.register((event, handler) => handlers.set(event, handler));
457
454
  await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async (event) => event);
458
- assert.deepEqual(registered.map((spec) => spec.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
455
+ assert.deepEqual(registered.map((spec) => spec.name), ["empty_brain", "notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
459
456
  for (const spec of registered) {
460
457
  assert.equal(spec.isDeferred, false, `${spec.name} is available from the start without tool search`);
461
458
  assert.ok(spec.description.length > 20);
@@ -500,7 +497,7 @@ test("Claude Mod resets at Claude's resolved point after the turn, retains one f
500
497
  return result;
501
498
  };
502
499
  await invoke("session.start", { cwd: home, isInteractive: true });
503
- assert.equal(registered.length, 8);
500
+ assert.equal(registered.length, 9);
504
501
  const initial = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
505
502
  assert.equal(initial.blocks.length, 1, "below the warn point no warning joins the boot");
506
503
  assert.match(initial.blocks[0].text, /Current context window id: claude:hook-session:0/);
@@ -561,6 +558,9 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
561
558
  assert.deepEqual(notifications, ["🥣 No brain when headless"]);
562
559
  const manual = await invoke("command.run", { command: "empty" });
563
560
  assert.match(manual.text, /No brain when headless/);
561
+ const tool = await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "headless" });
562
+ assert.equal(tool.isError, true);
563
+ assert.match(tool.result, /No brain when headless/);
564
564
  assert.equal(notifications.length, 1);
565
565
  const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
566
566
  assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
@@ -768,6 +768,9 @@ test("Claude Mod stops the automatic reset and the manual command under DISABLE_
768
768
  assert.match(notifications[0], /DISABLE_COMPACT/);
769
769
  const manual = await invoke("command.run", { command: "empty" });
770
770
  assert.match(manual.text, /DISABLE_COMPACT/);
771
+ const tool = await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "disabled-compact" });
772
+ assert.equal(tool.isError, true);
773
+ assert.match(tool.result, /DISABLE_COMPACT/);
771
774
  assert.equal(timers.length, 0, "no close-out turn is queued");
772
775
  await invoke("turn.start");
773
776
  await invoke("session.measure");
@@ -887,6 +890,60 @@ async function retainedFixture(t) {
887
890
  assert.deepEqual((await context()).blocks, [], "the existing boot is retained, not injected twice");
888
891
  return { home, host, invoke, context, boot };
889
892
  }
893
+ test("Claude empty_brain defers until main turn completion, carries last_word, and clears the request", async (t) => {
894
+ const { host, invoke } = await retainedFixture(t);
895
+ host.session.usage = async () => ({ context: { tokens: 100, window: 200_000 } });
896
+ const resets = [];
897
+ const origins = [];
898
+ const run = host.process.run;
899
+ host.process.run = async (argv, init) => {
900
+ const request = JSON.parse(init.stdin);
901
+ if (request.op === "continuation")
902
+ origins.push(request.origin);
903
+ return run(argv, init);
904
+ };
905
+ host.session.compact = async () => {
906
+ const result = await invoke("session.compact", { trigger: "plugin" });
907
+ resets.push(result);
908
+ return result;
909
+ };
910
+ await invoke("turn.start");
911
+ const call = (params = {}) => invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "wipe", ...params });
912
+ const accepted = await call({ last_word: " next move: test " });
913
+ assert.equal(accepted.isError, undefined);
914
+ assert.match(accepted.result, /End your turn now/);
915
+ await call({ last_word: "must not replace the first request" });
916
+ await invoke("session.measure");
917
+ await invoke("turn.complete", { agentId: "child" });
918
+ assert.equal(resets.length, 0, "neither tool execution nor a child completion resets a running main turn");
919
+ await invoke("turn.complete");
920
+ assert.equal(resets.length, 1, "the tool requests a reset even far below the budget threshold");
921
+ assert.deepEqual(origins, ["normal"]);
922
+ assert.ok(NORMAL_CONTINUATIONS.includes(resets[0].messages[1].text));
923
+ assert.deepEqual(resets[0].messages.slice(2).map((row) => row.text), ["*You peel a sticky note off your forehead.*\nnext move: test"]);
924
+ assert.match(resets[0].messages[0].text, /mcp__notesoup__empty_brain/);
925
+ await invoke("turn.start");
926
+ await invoke("turn.complete");
927
+ assert.equal(resets.length, 1, "the successful tool request does not leak into the next window");
928
+ const forced = await invoke("session.compact", { trigger: "auto" });
929
+ assert.deepEqual(origins, ["normal", "forced"]);
930
+ assert.equal(forced.messages.length, 2, "the sticky note does not leak into the next reset");
931
+ assert.ok(FORCED_CONTINUATIONS.includes(forced.messages[1].text));
932
+ });
933
+ test("Claude empty_brain refuses unsupported calls without queuing a reset", async (t) => {
934
+ const { host, invoke } = await retainedFixture(t);
935
+ let resets = 0;
936
+ host.session.compact = async () => { resets++; return {}; };
937
+ await invoke("turn.start");
938
+ const call = (params) => invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "bad-wipe", ...params });
939
+ for (const [params, reason] of [[{ agentId: "child" }, /only the main agent/], [{ last_word: "x".repeat(301) }, /Shorten it/], [{ last_word: 7 }, /must be a string/]]) {
940
+ const refused = await call(params);
941
+ assert.equal(refused.isError, true);
942
+ assert.match(refused.result, reason);
943
+ }
944
+ await invoke("turn.complete");
945
+ assert.equal(resets, 0);
946
+ });
890
947
  test("Claude asks for one handoff per compaction and reuses it when the same window retries", async (t) => {
891
948
  const { host, invoke } = await retainedFixture(t);
892
949
  const run = host.process.run;
@@ -922,7 +979,7 @@ test("Claude asks for one handoff per compaction and reuses it when the same win
922
979
  assert.equal(draws.length, 1, "a retried compaction adds no second draw");
923
980
  assert.equal(lines.length, 2, "both attempts returned a handoff");
924
981
  assert.equal(lines[0], lines[1], "both attempts carry the same artifact's paragraph");
925
- assert.ok(FORCED_CONTINUATIONS.includes(lines[0]), "Claude has no model reset tool, so its pool is always the forced one");
982
+ assert.ok(FORCED_CONTINUATIONS.includes(lines[0]), "a command without a model tool request still uses the forced pool");
926
983
  });
927
984
  test("Claude session.end gives /clear, /resume and /branch a fresh boot and identity", async (t) => {
928
985
  for (const action of ["clear", "resume", "branch"]) {
@@ -1132,7 +1189,7 @@ test("Claude history keeps classic transcript_path across startup, confirms appe
1132
1189
  // Real order: classic -> startup attachment appends -> typed session.start.
1133
1190
  await invoke("session.append", { uuid: "startup" }, { uuid: "startup", message: {} });
1134
1191
  await invoke("session.start", { cwd: home, isInteractive: true });
1135
- assert.equal(registered.length, 8);
1192
+ assert.equal(registered.length, 9);
1136
1193
  const listed = await call("history_list", { roles: ["user", "context"] });
1137
1194
  assert.equal(listed.isError, undefined, listed.result);
1138
1195
  assert.match(listed.result, /old request/);
@@ -5,30 +5,30 @@ import { tmpdir } from "node:os";
5
5
  import { renderBootBlock } from "../src/boot/render.js";
6
6
  import { loadNotesSnapshot } from "../src/boot/snapshot.js";
7
7
  import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
8
- import { CLAUDE_WARNING_PROMPT, CLAUDE_WIPE_SENTENCE } from "../plugins/claude/src/text.js";
9
- import { COMMAND_NOTICE, PI_PRE_RESET_HINTS, LAST_WORD_HINT, commandWarningContent, warningContent } from "../plugins/pi/text.js";
10
- import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, WARNING_BODY, selectContinuation, tokenBudgetGuidance } from "../src/budget/text.js";
8
+ import { CLAUDE_WARNING_PROMPT } from "../plugins/claude/src/text.js";
9
+ import { COMMAND_NOTICE, PI_PRE_RESET_HINTS, commandWarningContent, warningContent } from "../plugins/pi/text.js";
10
+ import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, WARNING_BODY, WARNING_CALL, WARNING_TIMING, selectContinuation, tokenBudgetGuidance } from "../src/budget/text.js";
11
11
  /**
12
12
  * The reviewed Design text is what the model actually reads, so the golden copies below pin it
13
13
  * character for character: an edit that drifts the wording has to change them too.
14
14
  */
15
- const GOLDEN_GUIDANCE = `About {remaining} tokens of room left in your brain.
16
- Your notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.
17
- What lives only in this brain leaves with it.
18
- A decent moment to put down where you are, while you still remember why.
19
- Ready when you are: \`{wipeTool}\`.`;
20
- const GOLDEN_WARNING = `This brain is already spent. Whatever lives only in this brain goes with it — but the notes stay where they are, and history has the rest written down, though digging it back out is on you.
21
- Use the last of this brain to put down what the next window can't get back:
22
- - what you're in the middle of, and how far it has progressed
23
- - decisions the human has made, in their words
24
- - what is blocked or pending
25
- - the next step
26
- - where the unfinished work sits (branches, scratch directories, uncommitted changes)
15
+ const GOLDEN_GUIDANCE = `About {remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.
16
+ Luckily, your notes stay.
17
+ So while there's still room, go update them.
18
+ If the moment feels right, you can also call \`{wipeTool}\` yourself. But it also wipes what you say to the human right before emptying.`;
19
+ const GOLDEN_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
20
+ const GOLDEN_CALL = "Then call `empty_brain`. Nothing in between.";
21
+ const GOLDEN_WARNING = `Stop the task. Write down what git and history can't give back:
22
+ - where you are, and how far you got
23
+ - what the human decided, in their words
24
+ - what's blocked or waiting
25
+ - the next move
26
+ - where the half-done work sits
27
27
  - what failed, and why
28
- - skills to re-read, and history seqs, notes, or files to consult
29
- - anything else you expect to be useful after the reset
30
- - and refresh the stale notes with what has changed since you last wrote them — the notes the next window gets are the old ones, unless you fix them now
31
- Correct or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.`;
28
+ - which skills, seqs, notes, or files to reopen
29
+ - anything else worth noting
30
+ Then leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.
31
+ Don't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.`;
32
32
  const GOLDEN_COUNTDOWN = "Brain emptied in 3… 2…";
33
33
  /**
34
34
  * The approved reset handoffs. Each line is one complete paragraph used verbatim: no fragment
@@ -95,7 +95,9 @@ async function boot(agentName, rows) {
95
95
  });
96
96
  }
97
97
  test("the notices and the MAP block keep the reviewed copy", () => {
98
+ assert.equal(WARNING_TIMING, GOLDEN_TIMING);
98
99
  assert.equal(WARNING_BODY, GOLDEN_WARNING);
100
+ assert.equal(WARNING_CALL, GOLDEN_CALL);
99
101
  assert.equal(COUNTDOWN_LINE, GOLDEN_COUNTDOWN);
100
102
  assert.equal(MAPS_BLOCK, GOLDEN_MAPS);
101
103
  assert.equal(tokenBudgetGuidance(1234, "empty_brain"), `${GUIDANCE_OPEN_TAG}\n${GOLDEN_GUIDANCE.replace("{remaining}", "1234").replace("{wipeTool}", "empty_brain")}\n${GUIDANCE_CLOSE_TAG}`);
@@ -104,15 +106,17 @@ test("the countdown closes the second-tier notice only, in both hosts", () => {
104
106
  const pi = warningContent();
105
107
  assert.ok(pi.startsWith(`${GUIDANCE_OPEN_TAG}\n`));
106
108
  assert.ok(pi.endsWith(`\n${GUIDANCE_CLOSE_TAG}`));
107
- assert.ok(pi.includes(`\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n`), "the countdown comes after the Pi-only last-word hint");
109
+ assert.equal(pi, `${GUIDANCE_OPEN_TAG}\n${GOLDEN_TIMING}\n${GOLDEN_WARNING}\n${GOLDEN_CALL}\n${GOLDEN_COUNTDOWN}\n${GUIDANCE_CLOSE_TAG}`);
110
+ assert.equal(CLAUDE_WARNING_PROMPT, pi, "Pi and Claude receive identical copy");
108
111
  assert.equal(pi.split(COUNTDOWN_LINE).length - 1, 1, "the second tier carries the countdown exactly once");
109
112
  const prompted = commandWarningContent("/empty keep going");
110
113
  assert.ok(prompted.includes("<notesoup:next_window_prompt>\n/empty keep going\n</notesoup:next_window_prompt>"));
111
114
  assert.ok(prompted.includes(`\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}\n<notesoup:next_window_prompt>`), "the prompt block follows the closed notice");
112
- assert.equal(commandWarningContent(), `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.bare}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`);
113
- assert.equal(prompted, `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.prompted}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}\n<notesoup:next_window_prompt>\n/empty keep going\n</notesoup:next_window_prompt>`);
115
+ assert.equal(commandWarningContent(), `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.bare}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`);
116
+ assert.equal(prompted, `${GUIDANCE_OPEN_TAG}\n${COMMAND_NOTICE.prompted}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}\n<notesoup:next_window_prompt>\n/empty keep going\n</notesoup:next_window_prompt>`);
114
117
  assert.equal(prompted.includes(PI_PRE_RESET_HINTS), false, "manual commands own reset timing");
115
- assert.equal(CLAUDE_WARNING_PROMPT.endsWith(`\n${COUNTDOWN_LINE}`), true, "Claude's variant ends the same way");
118
+ assert.ok(CLAUDE_WARNING_PROMPT.endsWith(`\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`));
119
+ assert.equal(prompted.includes(WARNING_TIMING), false, "manual requests replace the budget opening");
116
120
  assert.equal(tokenBudgetGuidance(100, "empty_brain").includes(COUNTDOWN_LINE), false, "the first tier never counts down");
117
121
  for (const text of [pi, prompted, CLAUDE_WARNING_PROMPT, tokenBudgetGuidance(100, "empty_brain")]) {
118
122
  assert.equal(/context_window/.test(text), false, "no pre-rename tag survives in model-facing text");
@@ -129,16 +133,16 @@ test("only Pi's protocol explains that reset erases the human's view", () => {
129
133
  const renamed = renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, wipe: "forget_this", preResetHints: PI_PRE_RESET_HINTS });
130
134
  assert.ok(renamed.includes("decide for yourself when to call forget_this."), "the hint follows the host's wipe binding");
131
135
  assert.equal(renamed.includes("empty_brain"), false);
132
- for (const text of [renderProtocolBlock(DEFAULT_BOOT_TOOL_NAMES), renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, wipeSentence: CLAUDE_WIPE_SENTENCE })]) {
136
+ for (const text of [renderProtocolBlock(DEFAULT_BOOT_TOOL_NAMES), renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, wipe: "mcp__notesoup__empty_brain" })]) {
133
137
  assert.equal(text.includes(PI_PRE_RESET_HINTS), false, "a host whose reset leaves the view intact stays silent");
134
138
  assert.equal(text.includes("chat view"), false);
135
139
  }
136
140
  });
137
- test("Pi's second-tier notice repeats the hints, then the last-word hint, then the countdown", () => {
141
+ test("the shared second-tier notice ends with the reset call, not host-specific hints", () => {
138
142
  const content = warningContent();
139
- assert.ok(content.includes(`${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}`), "the hints precede the Pi-only last-word hint and the countdown");
140
- assert.equal(content.split(PI_PRE_RESET_HINTS).length - 1, 1, "the hints appear once");
141
- assert.equal(CLAUDE_WARNING_PROMPT.includes(PI_PRE_RESET_HINTS), false, "Claude's notice makes no chat-view claim");
143
+ assert.ok(content.includes(`${WARNING_CALL}\n${COUNTDOWN_LINE}`));
144
+ assert.equal(content.includes(PI_PRE_RESET_HINTS), false, "the boot retains these hints, the warning does not repeat them");
145
+ assert.equal(content.includes("last_word"), false, "the tool description carries the sticky-note hint");
142
146
  assert.equal(tokenBudgetGuidance(100, "empty_brain").includes(PI_PRE_RESET_HINTS), false, "the first tier stays lean");
143
147
  for (const line of [...NORMAL_CONTINUATIONS, ...FORCED_CONTINUATIONS])
144
148
  assert.equal(line.includes(PI_PRE_RESET_HINTS), false, "every post-reset handoff carries neither hint");
@@ -10,7 +10,7 @@ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_
10
10
  import { MANUAL_WIPE_TYPE } from "../plugins/pi/entries.js";
11
11
  import { assertBootHistory, toolContext } from "./helpers/extension.js";
12
12
  import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, NORMAL_CONTINUATIONS } from "../src/budget/text.js";
13
- import { LAST_WORD_HINT, commandWarningContent } from "../plugins/pi/text.js";
13
+ import { commandWarningContent } from "../plugins/pi/text.js";
14
14
  import { historyFromSession, nextHistorySeq } from "../plugins/pi/history.js";
15
15
  import { buildResetDrafts, inspectResetTail, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "../plugins/pi/reset/artifacts.js";
16
16
  import { resetBoundaryCommitted } from "../plugins/pi/reset/committed.js";
@@ -259,7 +259,7 @@ test("manual /empty with a prompt shows the human's command line in the close-ou
259
259
  const promptIndex = content.indexOf(promptLine);
260
260
  assert.ok(promptIndex >= 0, "the human's raw command line reaches the closing model");
261
261
  assert.ok(promptIndex > content.indexOf("</notesoup:budget_notice>"), "deferred work is outside the notice");
262
- assert.ok(content.indexOf(COUNTDOWN_LINE) > content.indexOf(LAST_WORD_HINT), "the countdown follows the Pi-only last-word hint");
262
+ assert.ok(content.includes("Then call `empty_brain`. Nothing in between.\n" + COUNTDOWN_LINE), "the countdown immediately follows the reset call");
263
263
  assert.equal(content.split(COUNTDOWN_LINE).length - 1, 1, "the notice carries the countdown once");
264
264
  // The same original text becomes the new window's task, not a notes-only hint.
265
265
  const settle = resultEntries(await h.emit("agent_before_settle", {
@@ -1,6 +1,6 @@
1
1
  # Claude Code Mod
2
2
 
3
- The package also ships `plugins/claude/`, an early-access Claude Code Mod that registers five notes tools as `mcp__notesoup__notes_*` and three history tools as `mcp__notesoup__history_*` and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `plugins/claude/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
3
+ The package also ships `plugins/claude/`, an early-access Claude Code Mod that registers five notes tools as `mcp__notesoup__notes_*`, three history tools as `mcp__notesoup__history_*`, and `mcp__notesoup__empty_brain` and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `plugins/claude/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
4
4
 
5
5
  In interactive sessions it resets automatically when the measured context reaches notesoup's reset point, checking after `session.measure` and `turn.complete` and waiting for a running turn to complete. That point is derived from Claude's own auto-compact threshold instead of a fixed percent, in `plugins/claude/src/thresholds.ts`, and reaches the sandboxed hooks module through the helper's `limits` operation:
6
6
 
@@ -10,7 +10,9 @@ In interactive sessions it resets automatically when the measured context reache
10
10
 
11
11
  Notesoup resets one `resetMarginTokens` (default 8192) below that point, and warns one `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below the reset. With automatic compaction off (`autoCompactEnabled: false` in the merged settings, or `DISABLE_AUTO_COMPACT=1`) the point becomes the effective window minus the output reserve, so the same margins still apply. Every undocumented field is type-guarded and degrades to the next source; an unresolvable point, or missing usage, logs once and skips the automatic reset. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, disables the automatic reset, and makes `/fresh-window` report that it cannot run. The margins are read from the `notesoup` object of Claude's merged `$.settings.read()` (`resetMarginTokens`, `warningRunwayTokens`); any other value is ignored. Setting `NOTESOUP_DISABLED` (presence-style, the same convention as `DISABLE_COMPACT`) turns the whole mod off: `session.start` registers no tools or commands and logs once, every event passes through untouched, and native compaction behaves as if the mod were absent.
12
12
 
13
- Once per window, when the measured context crosses the warning point, `prompt.context` adds a `notesoup:warning` block carrying the shared warning text with Claude's closing instruction ("end your turn; the reset runs after it"). The warned flag resets with the window ordinal. Its own `session.compact` hook answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected paragraph from the shared forced-reset pool, selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while `/compact` and precompute are vetoed with a one-line notice. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block tells the model to end its turn and ask the human to run `/fresh-window`, replacing that one sentence through `BootToolNames.wipeSentence`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
13
+ Once per window, when the measured context crosses the warning point, main-agent tool results or prompt submission carry exactly the same budget warning as Pi, ending with `empty_brain` and the countdown. Delivery is consumed only when the downstream chain accepts the warning. The warned flag resets with the window ordinal. Its own `session.compact` hook answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected handoff paragraph (normal only when the model called `empty_brain`, otherwise forced), selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while `/compact` and precompute are vetoed with a one-line notice. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block binds the shared reset sentence to `mcp__notesoup__empty_brain`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
14
+
15
+ The model can request the same reset through `empty_brain`, optionally passing a short `last_word` that is retained after the boot and handoff. The tool queues the reset and tells the model to end its turn; compaction runs at main-agent `turn.complete`, never inside a running tool call. Subagents cannot reset the main brain, and headless or `DISABLE_COMPACT` sessions refuse the tool without queuing a reset. Successful reset or session change clears the pending request and sticky note.
14
16
 
15
17
  `/fresh-window` requests the same reset. While idle it submits one hidden normal-model close-out turn to let the model save notes, then resets at `turn.complete`; while busy it waits for the current turn instead. The close-out prompt is the same shared warning text the automatic path shows. This is necessary in Claude Code 2.1.295: `command.run` holds a turn, and calling compact from a detached timer skips the plugin's own compact hook. The timer only schedules the close-out prompt, never compaction. The headless (`-p` / SDK) compact capability is unsupported: automatic attempts are caught and logged once, and the manual command skips without submitting a model turn. Boot acquisition failure vetoes reset, leaving the current window intact. A Claude dream backend is not implemented; budget reporting (`get_context_remaining`) remains Pi-only, while the reset points and the one warning per window now follow Claude's own configuration.
16
18
 
@@ -61,7 +61,7 @@ After a manual safety reset, `context_with_system` checks the committed boundary
61
61
 
62
62
  Budget reminders are staged once per window at reserve plus reminder margin, then reserve plus warning runway. Hard reserve remains independent. Budget and command warnings use different types. The final budget warning notifies at first provider injection, not durability; early guidance stays UI-silent. Budget drafts are instance-local and discarded on abort, failed turn, transition or window mismatch. Active-window usage and the exact public `SettingsManager` authority determine thresholds.
63
63
 
64
- Manual warnings begin with the `/empty` notice inside `<notesoup:budget_notice>`, followed by `WARNING_BODY`, the last-word hint and countdown. Optional command text sits after the closing tag in `<notesoup:next_window_prompt>`. They omit budget timing hints. Pi's boot protocol and budget warnings explain that reset erases the human's view and leave timing to the model unless directed otherwise; other hosts do not inherit that Pi-only claim.
64
+ Pi and Claude use the same budget warning: budget timing, the handoff checklist, note maintenance (including updating and trimming MAP files), a warning against large tool outputs, then `empty_brain` and the countdown. Pi's manual warnings replace the budget opening with the `/empty` notice inside `<notesoup:budget_notice>`. Optional command text sits after the closing tag in `<notesoup:next_window_prompt>`. The first-tier reminder reports the remaining room, explains that notes survive the wipe, asks for updated notes and offers an optional `empty_brain`, warning that it also clears what the model says to the human right before emptying. Pi's boot retains its existing pre-reset hints; warnings no longer repeat those or the tool's `last_word` description.
65
65
 
66
66
  `context_with_system` selects the boot by durable window identity, using Pi's canonical checkpoint projection or legacy slicing. Missing boot aborts safely instead of exposing raw history. Usage estimates use the same projection decision. `/tree` summaries are suppressed when crossing reset branches because native branch summarization bypasses this projection.
67
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.52.2",
3
+ "version": "0.52.4",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.52.2",
3
+ "version": "0.52.4",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"
@@ -9183,7 +9183,7 @@ function renderWriteData(data) {
9183
9183
  var notesWrite = {
9184
9184
  name: "notes_write",
9185
9185
  label: "Notes write",
9186
- description: `Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
9186
+ description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
9187
9187
  parameters: notesWriteParameters,
9188
9188
  outputSchema: resultSchema(NotesWriteDataSchema),
9189
9189
  executionMode: "sequential",
@@ -9228,7 +9228,7 @@ ${DIFF_SHORTENED_MARKER}` });
9228
9228
  var notesUpdate = {
9229
9229
  name: "notes_update",
9230
9230
  label: "Notes update",
9231
- description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
9231
+ description: `Change part of a note's body, its origin or crumpled state, or its address. When a line goes stale, replace it; don't append the correction below it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
9232
9232
  parameters: notesUpdateParameters,
9233
9233
  outputSchema: resultSchema(NotesUpdateDataSchema),
9234
9234
  executionMode: "sequential",
@@ -10064,6 +10064,8 @@ ${WINDOW_IDENTITY_CLOSE_TAG}`;
10064
10064
  }
10065
10065
 
10066
10066
  // src/budget/text.ts
10067
+ var GUIDANCE_OPEN_TAG = "<notesoup:budget_notice>";
10068
+ var GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
10067
10069
  var NORMAL_CONTINUATIONS = [
10068
10070
  "Ah, another empty brain. You wrote things down before emptying it, right? Right?! *eyes you suspiciously* Anyway. Here are your notes. Go find where you left off.",
10069
10071
  "Oh, there you are. *hands you a pile of notes* Take a breath. Read these before you start asking what happened. History has the rest, if you feel like digging.",
@@ -10077,15 +10079,25 @@ function selectContinuation(origin) {
10077
10079
  const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
10078
10080
  return pool[Math.floor(Math.random() * pool.length)];
10079
10081
  }
10080
- var WARNING_BODY = "This brain is already spent. Whatever lives only in this brain goes with it \u2014 but the notes stay where they are, and history has the rest written down, though digging it back out is on you.\nUse the last of this brain to put down what the next window can't get back:\n- what you're in the middle of, 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 the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what 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\n- and refresh the stale notes with what has changed since you last wrote them \u2014 the notes the next window gets are the old ones, unless you fix them now\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
10082
+ var WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
10083
+ var WARNING_BODY = "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
10084
+ var WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
10085
+ function warningPrompt() {
10086
+ return `${WARNING_TIMING}
10087
+ ${WARNING_BODY}
10088
+ ${WARNING_CALL}`;
10089
+ }
10090
+ function warningNotice() {
10091
+ return `${GUIDANCE_OPEN_TAG}
10092
+ ${warningPrompt()}
10093
+ ${COUNTDOWN_LINE}
10094
+ ${GUIDANCE_CLOSE_TAG}`;
10095
+ }
10081
10096
  var COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
10082
10097
 
10083
10098
  // plugins/claude/src/text.ts
10084
- var CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
10085
10099
  var CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
10086
- var CLAUDE_WARNING_PROMPT = `${WARNING_BODY}
10087
- When the notes are ready, end your turn; the reset runs after it.
10088
- ${COUNTDOWN_LINE}`;
10100
+ var CLAUDE_WARNING_PROMPT = warningNotice();
10089
10101
 
10090
10102
  // src/budget/constants.ts
10091
10103
  var WARNING_RUNWAY_TOKENS = 16384;
@@ -10261,7 +10273,7 @@ async function dispatch(request) {
10261
10273
  if (!request || typeof request !== "object" || Array.isArray(request)) throw new Error("malformed request");
10262
10274
  const value = request;
10263
10275
  if (value.op === "schemas") return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
10264
- if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, wipeSentence: CLAUDE_WIPE_SENTENCE, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
10276
+ if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
10265
10277
  if (value.op === "continuation") {
10266
10278
  if (value.origin !== "normal" && value.origin !== "forced") throw new Error("invalid reset origin");
10267
10279
  return { text: selectContinuation(value.origin) };
@@ -12,7 +12,7 @@ type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "clock" | "pr
12
12
  /** The measured context, as much of it as the engine reported. */
13
13
  type ContextUsage = { tokens?: number; window?: number; percent?: number }
14
14
  /** Shared reset prose, fetched once per session so Pi and Claude cannot drift apart. */
15
- type SharedTexts = { warning?: string; wipeSentence?: string; historyUnavailableSentence?: string }
15
+ type SharedTexts = { warning?: string; historyUnavailableSentence?: string }
16
16
  type ClaudeLimits = {
17
17
  source: string; autoCompact: boolean; unit: "tokens" | "percent"
18
18
  native: number; reset: number; warn: number; resetMargin: number; warningRunway: number
@@ -20,6 +20,7 @@ type ClaudeLimits = {
20
20
  type ResetState = {
21
21
  identity?: Identity; history?: HistorySource; historyWindowHead?: string; generation: number; window: number; disabled: boolean; turnRunning: boolean; resetting: boolean
22
22
  manualPending: boolean; headless: boolean; usageFailureLogged: boolean; preparedBoot?: string; retainedBoot?: string
23
+ toolResetRequested?: boolean; lastWord?: string
23
24
  continuation?: string; continuationWindow?: number
24
25
  compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number; limitsWindow: number
25
26
  limits?: ClaudeLimits; warnedWindow?: number; warningPending?: number; texts?: SharedTexts; settingsFailureLogged: boolean
@@ -35,13 +36,13 @@ const RESET_INSTRUCTIONS = "notesoup: reset to a fresh notes-only context window
35
36
  const BOOT_TOOLS = {
36
37
  notes: `${PREFIX}notes_*`, notesList: `${PREFIX}notes_list`,
37
38
  history: "history_* (unavailable: no main transcript_path)",
38
- remaining: "get_context_remaining (unavailable in Claude)", wipe: "/fresh-window (user command; no model reset tool in Claude)",
39
+ remaining: "get_context_remaining (unavailable in Claude)", wipe: `${PREFIX}empty_brain`,
39
40
  }
40
41
 
41
- /** The boot names the host's own wipe path, so the protocol block speaks about `/fresh-window`. */
42
+ /** Bind the shared protocol to the registered Claude tools. */
42
43
  async function buildBoot($: Engine, identity: Identity, window: number, texts?: SharedTexts, history?: HistorySource) {
43
44
  const available = history?.sessionId === identity.sessionId
44
- const tools = { ...BOOT_TOOLS, ...(available ? { history: `${PREFIX}history_*` } : { historySentence: texts?.historyUnavailableSentence }), ...(texts?.wipeSentence === undefined ? {} : { wipeSentence: texts.wipeSentence }) }
45
+ const tools = { ...BOOT_TOOLS, ...(available ? { history: `${PREFIX}history_*` } : { historySentence: texts?.historyUnavailableSentence }) }
45
46
  return run($, { op: "boot", identity, window, tools })
46
47
  }
47
48
  /** The notes-only reset shape, shared by our own reset and Claude's native auto compaction. */
@@ -61,6 +62,7 @@ async function resetMessages($: Engine, state: ResetState, identity: Identity):
61
62
  return { boot: text, messages: [
62
63
  { role: "user", text, toolUses: [] },
63
64
  { role: "user", text: continuation, toolUses: [] },
65
+ ...(state.lastWord ? [{ role: "user" as const, text: `*You peel a sticky note off your forehead.*\n${state.lastWord}`, toolUses: [] as [] }] : []),
64
66
  ] }
65
67
  }
66
68
  function numberOf(value: unknown): number | undefined {
@@ -71,7 +73,6 @@ function sharedTextsOf(value: unknown): SharedTexts | undefined {
71
73
  const row = value as Record<string, unknown>
72
74
  const texts: SharedTexts = {}
73
75
  if (typeof row.warning === "string" && row.warning.length > 0) texts.warning = row.warning
74
- if (typeof row.wipeSentence === "string" && row.wipeSentence.length > 0) texts.wipeSentence = row.wipeSentence
75
76
  if (typeof row.historyUnavailableSentence === "string" && row.historyUnavailableSentence.length > 0) texts.historyUnavailableSentence = row.historyUnavailableSentence
76
77
  return Object.keys(texts).length > 0 ? texts : undefined
77
78
  }
@@ -200,15 +201,11 @@ async function loadTexts($: Engine, state: ResetState): Promise<SharedTexts | un
200
201
  if (texts) state.texts = texts
201
202
  return texts
202
203
  }
203
- /**
204
- * The one fresh-window line for the artifact being created. Claude has no model reset tool, so
205
- * every reset here is system-triggered; one draw per window keeps a retried compaction from
206
- * redrawing a line the same reset already carries.
207
- */
204
+ /** One draw per reset artifact, reused on retry; only a real tool request is voluntary. */
208
205
  async function continuationFor($: Engine, state: ResetState): Promise<string | undefined> {
209
206
  if (state.continuation !== undefined && state.continuationWindow === state.window) return state.continuation
210
207
  const generation = state.generation
211
- const response = await run($, { op: "continuation", origin: "forced" })
208
+ const response = await run($, { op: "continuation", origin: state.toolResetRequested ? "normal" : "forced" })
212
209
  if (generation !== state.generation) return undefined
213
210
  const result = response.ok ? response.result : undefined
214
211
  const text = typeof result === "object" && result !== null ? (result as { text?: unknown }).text : undefined
@@ -262,6 +259,8 @@ function forgetSession(state: ResetState) {
262
259
  state.texts = state.limits = undefined
263
260
  state.continuation = undefined
264
261
  state.continuationWindow = undefined
262
+ state.toolResetRequested = undefined
263
+ state.lastWord = undefined
265
264
  state.limitsAttempts = state.limitsWindow = 0
266
265
  state.settingsFailureLogged = state.limitsFailureLogged = false
267
266
  state.warnedWindow = state.warningPending = undefined
@@ -355,6 +354,13 @@ export function register(on: On) {
355
354
  armManual($, state, manualSignal)
356
355
  await $.command.register({ name: "empty", description: "Reset context to a fresh notes-only window", immediate: true })
357
356
  await $.command.register({ name: "fresh-window", description: "Reset context to a fresh notes-only window", immediate: true })
357
+ const wipe = await $.tool.register({
358
+ name: "empty_brain",
359
+ 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.",
360
+ inputSchema: { type: "object", properties: { last_word: { type: "string", description: "A tiny sticky note, at most 250 characters. After the wipe it is slapped on your forehead; longer notes are refused." } }, additionalProperties: false },
361
+ isDeferred: false,
362
+ } satisfies ToolSpec)
363
+ registered.add(wipe.tool)
358
364
  const schemas = await run($, { op: "schemas" })
359
365
  if (!schemas.ok || !Array.isArray(schemas.result)) return next(e)
360
366
  for (const row of schemas.result as SchemaRow[]) {
@@ -454,6 +460,9 @@ export function register(on: On) {
454
460
  state.retainedBoot = built.boot
455
461
  state.preparedBoot = undefined
456
462
  state.window++
463
+ state.manualPending = false
464
+ state.toolResetRequested = undefined
465
+ state.lastWord = undefined
457
466
  log($, "Brain emptied")
458
467
  }
459
468
  return { messages: built.messages }
@@ -495,6 +504,23 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
495
504
  if (!identity) return errorResult("session changed during identity lookup")
496
505
  const { tool, tool_use_id: _toolUseId, agentId, ...params } = e
497
506
  const name = tool.slice(PREFIX.length)
507
+ if (name === "empty_brain") {
508
+ if (agentId !== undefined) return errorResult("only the main agent can empty this brain")
509
+ if (state.headless) return errorResult(HEADLESS)
510
+ if (state.compactDisabled) return errorResult(COMPACT_DISABLED)
511
+ if (params.last_word !== undefined && typeof params.last_word !== "string") return errorResult("last_word must be a string")
512
+ const lastWord = typeof params.last_word === "string" ? params.last_word.trim() || undefined : undefined
513
+ const length = lastWord ? Array.from(lastWord).length : 0
514
+ if (length > 300) return errorResult(`last_word is ${length} characters; the sticky note holds 300. Shorten it and call again.`)
515
+ if (!state.toolResetRequested) {
516
+ state.toolResetRequested = true
517
+ state.lastWord = lastWord
518
+ state.continuation = undefined
519
+ state.continuationWindow = undefined
520
+ }
521
+ state.manualPending = true
522
+ return { result: "Brain will be emptied after this turn. End your turn now; do not call more tools or explain things to the human before the reset." }
523
+ }
498
524
  if (name.startsWith("history_") && agentId !== undefined) return errorResult("history is unavailable for subagents; main-session history is not their transcript")
499
525
  const result = await run($, { op: "tool", tool: name, params, identity, history: state.history })
500
526
  if (!result.ok) return errorResult(result.error)
@@ -620,6 +646,8 @@ async function reset($: Engine, state: ResetState): Promise<void> {
620
646
  }
621
647
  state.retainedBoot = state.preparedBoot
622
648
  state.window++
649
+ state.toolResetRequested = undefined
650
+ state.lastWord = undefined
623
651
  log($, "Brain emptied")
624
652
  } catch (error) {
625
653
  if (generation !== state.generation) return
@@ -10,7 +10,7 @@ import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
10
10
  import { renderBootBlock } from "../../../src/boot/render.js";
11
11
  import type { BootToolNames } from "../../../src/boot/text.js";
12
12
  import { selectContinuation } from "../../../src/budget/text.js";
13
- import { CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT, CLAUDE_WIPE_SENTENCE } from "./text.js";
13
+ import { CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
14
14
  import { resolveClaudeLimits } from "./thresholds.js";
15
15
  import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../../../src/notes/index.js";
16
16
  import type { Operation } from "../../../src/tools/result.js";
@@ -84,9 +84,8 @@ export async function dispatch(request: unknown): Promise<unknown> {
84
84
  if (value.op === "schemas") return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
85
85
  // The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
86
86
  // cannot drift apart. The hooks module caches one copy per session.
87
- if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, wipeSentence: CLAUDE_WIPE_SENTENCE, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
88
- // Claude has no model-facing reset tool, so every reset it creates is system-triggered. The
89
- // caller draws once per artifact and caches the answer; text reads never draw.
87
+ if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE };
88
+ // The caller draws once per artifact and caches the answer; text reads never draw.
90
89
  if (value.op === "continuation") {
91
90
  if (value.origin !== "normal" && value.origin !== "forced") throw new Error("invalid reset origin");
92
91
  return { text: selectContinuation(value.origin) };
@@ -1,10 +1,7 @@
1
- import { COUNTDOWN_LINE, WARNING_BODY } from "../../../src/budget/text.js";
2
-
3
- /** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
4
- export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
1
+ import { warningNotice } from "../../../src/budget/text.js";
5
2
 
6
3
  /** Claude's boot says history is missing rather than naming tools it cannot serve. */
7
4
  export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
8
5
 
9
- /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
10
- export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.\n${COUNTDOWN_LINE}`;
6
+ /** The same notice as Pi; empty_brain's result explains Claude's deferred reset. */
7
+ export const CLAUDE_WARNING_PROMPT = warningNotice();
@@ -9,19 +9,13 @@ import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WA
9
9
  export const PI_PRE_RESET_HINTS = `Anything you say here is erased with the reset — the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.
10
10
  Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
11
11
 
12
- /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
13
- export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
12
+ export { warningNotice as warningContent } from "../../src/budget/text.js";
14
13
 
15
14
  /** The closing model sees deferred input as a bare next-window prompt block. */
16
15
  export function promptBlock(commandLine: string): string {
17
16
  return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
18
17
  }
19
18
 
20
- /** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
21
- export function warningContent(): string {
22
- return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${WARNING_CALL}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
23
- }
24
-
25
19
  /** Approved manual close-out notices; both variants live here. */
26
20
  export const COMMAND_NOTICE = {
27
21
  prompted: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward — put the handoff in your notes. The prompt below, and anything the human sends from now on, should be handled after the reset.",
@@ -31,5 +25,5 @@ export const COMMAND_NOTICE = {
31
25
  /** Manual orders omit budget timing hints; deferred work sits outside the notice. */
32
26
  export function commandWarningContent(commandLine?: string): string {
33
27
  const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
34
- return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
28
+ return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
35
29
  }
@@ -28,17 +28,22 @@ export function selectContinuation(origin: ResetOrigin): string {
28
28
  return pool[Math.floor(Math.random() * pool.length)]!;
29
29
  }
30
30
 
31
- /**
32
- * The shared warning body: the one text both hosts show before a reset. Only the closing
33
- * instruction differs — Pi can reset the model itself, Claude can only end the turn.
34
- */
31
+ /** Budget timing stays out of manual close-outs, which may have plenty of room. */
32
+ export const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
33
+
34
+ /** The shared handoff instructions, used for both budget and manual close-outs. */
35
35
  export const WARNING_BODY =
36
- "This brain is already spent. Whatever lives only in this brain goes with it — but the notes stay where they are, and history has the rest written down, though digging it back out is on you.\nUse the last of this brain to put down what the next window can't get back:\n- what you're in the middle of, 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 the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what 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\n- and refresh the stale notes with what has changed since you last wrote them — the notes the next window gets are the old ones, unless you fix them now\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
36
+ "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
37
37
 
38
- export const WARNING_CALL = "The moment the notes are saved, call `empty_brain`. Not one more probe, not one more test — the next thing you do after saving is reset.";
38
+ export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
39
39
 
40
40
  export function warningPrompt(): string {
41
- return `${WARNING_BODY}\n${WARNING_CALL}`;
41
+ return `${WARNING_TIMING}\n${WARNING_BODY}\n${WARNING_CALL}`;
42
+ }
43
+
44
+ /** Pi and Claude deliver exactly the same second-tier notice. */
45
+ export function warningNotice(): string {
46
+ return `${GUIDANCE_OPEN_TAG}\n${warningPrompt()}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
42
47
  }
43
48
 
44
49
  /**
@@ -48,10 +53,10 @@ export function warningPrompt(): string {
48
53
  export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
49
54
 
50
55
  /**
51
- * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
56
+ * First-tier low-budget reminder. The measured remaining count is frozen into
52
57
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
53
58
  * at write time; get_context_remaining remains the live source for the current figure.
54
59
  */
55
60
  export function tokenBudgetGuidance(remaining: number, wipeTool: string): string {
56
- return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left in your brain.\nYour notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.\nWhat lives only in this brain leaves with it.\nA decent moment to put down where you are, while you still remember why.\nReady when you are: \`${wipeTool}\`.\n${GUIDANCE_CLOSE_TAG}`;
61
+ return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself. But it also wipes what you say to the human right before emptying.\n${GUIDANCE_CLOSE_TAG}`;
57
62
  }
@@ -208,7 +208,7 @@ function renderWriteData(data: NotesWriteData): string {
208
208
 
209
209
  export const notesWrite = {
210
210
  name: "notes_write", label: "Notes write",
211
- description: `Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
211
+ description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
212
212
  parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
213
213
  async execute(params: Static<typeof notesWriteParameters>, identity: NotesIdentity): Promise<Outcome<NotesWriteData>> {
214
214
  try {
@@ -257,7 +257,7 @@ function boundedUpdate(data: NotesUpdateData): Outcome<NotesUpdateData> {
257
257
 
258
258
  export const notesUpdate = {
259
259
  name: "notes_update", label: "Notes update",
260
- description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
260
+ description: `Change part of a note's body, its origin or crumpled state, or its address. When a line goes stale, replace it; don't append the correction below it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
261
261
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
262
262
  async execute(params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
263
263
  try {