notesoup 0.47.1 → 0.48.1

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 (88) hide show
  1. package/README.md +2 -2
  2. package/dist/src/boot/render.d.ts +14 -7
  3. package/dist/src/boot/render.js +29 -16
  4. package/dist/src/boot/text.d.ts +25 -4
  5. package/dist/src/boot/text.js +60 -13
  6. package/dist/src/budget/constants.d.ts +2 -4
  7. package/dist/src/budget/constants.js +2 -4
  8. package/dist/src/budget/policy.d.ts +2 -2
  9. package/dist/src/budget/policy.js +3 -3
  10. package/dist/src/budget/text.d.ts +29 -9
  11. package/dist/src/budget/text.js +51 -10
  12. package/dist/src/claude/helper.d.ts +2 -3
  13. package/dist/src/claude/helper.js +45 -11
  14. package/dist/src/claude/history.d.ts +9 -0
  15. package/dist/src/claude/history.js +271 -0
  16. package/dist/src/dsh/budget.js +1 -1
  17. package/dist/src/dsh/engine.d.ts +2 -1
  18. package/dist/src/dsh/engine.js +18 -9
  19. package/dist/src/dsh/index.js +9 -4
  20. package/dist/src/dsh/tools.js +1 -1
  21. package/dist/src/dsh/window.d.ts +2 -1
  22. package/dist/src/dsh/window.js +14 -8
  23. package/dist/src/history/query.js +59 -81
  24. package/dist/src/notes/address.d.ts +5 -0
  25. package/dist/src/notes/address.js +20 -21
  26. package/dist/src/notes/store.js +12 -19
  27. package/dist/src/pi/boot.d.ts +1 -1
  28. package/dist/src/pi/boot.js +28 -5
  29. package/dist/src/pi/budget.d.ts +1 -3
  30. package/dist/src/pi/budget.js +20 -61
  31. package/dist/src/pi/entries.d.ts +0 -1
  32. package/dist/src/pi/entries.js +0 -1
  33. package/dist/src/pi/history.d.ts +3 -0
  34. package/dist/src/pi/history.js +4 -0
  35. package/dist/src/pi/reset/artifacts.d.ts +7 -2
  36. package/dist/src/pi/reset/artifacts.js +16 -14
  37. package/dist/src/pi/reset/lifecycle.d.ts +21 -25
  38. package/dist/src/pi/reset/lifecycle.js +48 -72
  39. package/dist/src/pi/runtime.js +9 -8
  40. package/dist/src/pi/window.d.ts +12 -6
  41. package/dist/src/pi/window.js +7 -0
  42. package/dist/test/agent-loop.test.js +53 -30
  43. package/dist/test/boot.integration.test.js +123 -12
  44. package/dist/test/budget-settings.integration.test.js +10 -6
  45. package/dist/test/claude-history.test.d.ts +1 -0
  46. package/dist/test/claude-history.test.js +184 -0
  47. package/dist/test/claude-mod.test.js +236 -42
  48. package/dist/test/dsh.test.js +80 -3
  49. package/dist/test/helpers/extension.d.ts +3 -0
  50. package/dist/test/helpers/extension.js +33 -5
  51. package/dist/test/history.integration.test.js +66 -0
  52. package/dist/test/host-neutral.test.js +1 -1
  53. package/dist/test/model-facing-text.test.d.ts +1 -0
  54. package/dist/test/model-facing-text.test.js +181 -0
  55. package/dist/test/notes.integration.test.js +16 -18
  56. package/dist/test/reset-lifecycle.test.js +201 -46
  57. package/docs/architecture.md +3 -3
  58. package/docs/claude-code-mod.md +15 -3
  59. package/docs/dsh.md +2 -2
  60. package/docs/reset-lifecycle.md +32 -20
  61. package/docs/skills.md +1 -1
  62. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  63. package/mods/notesoup/dist/claude/helper.js +836 -92
  64. package/mods/notesoup/hooks/register.ts +140 -38
  65. package/package.json +1 -1
  66. package/src/boot/render.ts +41 -23
  67. package/src/boot/text.ts +69 -13
  68. package/src/budget/constants.ts +2 -4
  69. package/src/budget/policy.ts +3 -3
  70. package/src/budget/text.ts +61 -10
  71. package/src/claude/helper.ts +53 -22
  72. package/src/claude/history.ts +228 -0
  73. package/src/dsh/budget.ts +1 -1
  74. package/src/dsh/engine.ts +16 -9
  75. package/src/dsh/index.ts +8 -3
  76. package/src/dsh/tools.ts +1 -1
  77. package/src/dsh/window.ts +15 -9
  78. package/src/history/query.ts +57 -82
  79. package/src/notes/address.ts +19 -16
  80. package/src/notes/store.ts +9 -14
  81. package/src/pi/boot.ts +27 -5
  82. package/src/pi/budget.ts +20 -58
  83. package/src/pi/entries.ts +0 -1
  84. package/src/pi/history.ts +7 -2
  85. package/src/pi/reset/artifacts.ts +17 -14
  86. package/src/pi/reset/lifecycle.ts +56 -79
  87. package/src/pi/runtime.ts +9 -8
  88. package/src/pi/window.ts +11 -1
package/README.md CHANGED
@@ -30,7 +30,7 @@ pi -e npm:notesoup
30
30
 
31
31
  - **Durable context windows.** `/fresh-window` (alias `/empty-brain`) clears and stops; `/fresh-window Continue reviewing the implementation` clears and continues. The model can also request a window itself with `empty_brain`, 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
- - **`get_context_remaining`** — the live countdown to the close-out line, so the agent can see the cliff before it drives off it.
33
+ - **`get_context_remaining`** — how much room the brain has left before the hard-reserve wipe, including the warning runway.
34
34
  - **Eight history/notes tools**, flattened from the original Codex actions:
35
35
 
36
36
  | Codex action | Pi tool |
@@ -77,7 +77,7 @@ The dreamer model is configured under the same key; `--dreamer <model pattern>`
77
77
  - [Standalone notes library](docs/notes-library.md) — use the notes store from Node, no Pi required
78
78
  - [SDK integration](docs/sdk-integration.md) — binding notesoup to a host-built session
79
79
  - [DeepSeek Harness](docs/dsh.md) — adapter and profile patch for dsh 0.2.1-alpha.2
80
- - [Claude Code Mod](docs/claude-code-mod.md) — early-access notes tools for Claude Code
80
+ - [Claude Code Mod](docs/claude-code-mod.md) — early-access notes and persisted-session history tools for Claude Code
81
81
  - [Skills, dream, and the notes doctor](docs/skills.md) — `/skill:memory`, `/skill:dream`, `dream doctor`, the dream lock
82
82
 
83
83
  ## Development
@@ -1,16 +1,23 @@
1
1
  import type { NotesSnapshot } from "./snapshot.js";
2
2
  import { type BootToolNames } from "./text.js";
3
- /**
4
- * Render a static, once-per-window boot block from explicit data. This function does not read
5
- * notes or call runtime UI APIs; acquisition belongs to loadNotesSnapshot and its caller.
6
- */
3
+ export type BootWindowTree = {
4
+ readonly trunk: string;
5
+ readonly windows: ReadonlyArray<{
6
+ readonly shortName: string;
7
+ readonly firstSeq?: number;
8
+ readonly lastSeq?: number;
9
+ readonly isCurrent: boolean;
10
+ }>;
11
+ };
7
12
  export type BootRenderData = {
8
13
  readonly agentName: string;
9
14
  readonly modelName: string;
10
- readonly firstWindowId: string;
11
- readonly currentWindowId: string;
12
- readonly previousWindowId?: string;
15
+ readonly tree: BootWindowTree;
13
16
  readonly notes: NotesSnapshot;
14
17
  readonly tools: BootToolNames;
15
18
  };
19
+ /**
20
+ * Render a static, once-per-window boot block from explicit data. This function does not read
21
+ * notes or call runtime UI APIs; acquisition belongs to loadNotesSnapshot and its caller.
22
+ */
16
23
  export declare function renderBootBlock(data: BootRenderData): string;
@@ -1,4 +1,4 @@
1
- import { CONTEXT_WINDOW_OPEN_TAG, CONTEXT_WINDOW_CLOSE_TAG, MAP_BOOT_MAX_CHARS, SHELF_FRESH_LIMIT, renderProtocolBlock } from "./text.js";
1
+ import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, MAP_BOOT_MAX_CHARS, SHELF_FRESH_LIMIT, renderProtocolBlock } from "./text.js";
2
2
  function relativeTime(timestamp, now) {
3
3
  const seconds = Math.trunc((timestamp - now) / 1000);
4
4
  if (seconds === 0)
@@ -27,14 +27,16 @@ function indent(text) {
27
27
  function section(label, body) {
28
28
  return `${label}\n${"─".repeat(Array.from(label).length)}\n\n${body}`;
29
29
  }
30
+ /** Pi's default agent slug: an unnamed agent shares its `@self` shelf with every other nameless one. */
31
+ const NAMELESS_AGENT = "anonymous";
30
32
  /** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its map and its own freshest pages. */
31
- function notesIndex(snapshot, tools) {
33
+ function notesIndex(snapshot, tools, agentName, modelName) {
32
34
  const homes = [
33
- { scope: "session", label: "THIS SESSION · no @" },
34
- { scope: "project", label: "THIS PROJECT · @project" },
35
- { scope: "agent", label: "YOU · @self" },
36
- { scope: "model", label: "YOUR MODEL · @model" },
37
- { scope: "human", label: "THE HUMAN · @human" },
35
+ { scope: "session", label: "no @ — this session" },
36
+ { scope: "project", label: "@project — this project" },
37
+ { scope: "agent", label: agentName === NAMELESS_AGENT ? "@self — every nameless agent shares this" : `@self — ${agentName} only` },
38
+ { scope: "model", label: `@model — ${modelName} only` },
39
+ { scope: "human", label: "@human — the human" },
38
40
  ];
39
41
  const shelves = [];
40
42
  for (const home of homes) {
@@ -56,9 +58,9 @@ function notesIndex(snapshot, tools) {
56
58
  continue;
57
59
  const parts = [];
58
60
  if (map?.body)
59
- parts.push(`MAP — ${map.address}\n\n${indent(mapBodyForBoot(map.address, map.body))}`);
61
+ parts.push(`map\n\n${indent(mapBodyForBoot(map.address, map.body))}`);
60
62
  if (fresh.length > 0)
61
- parts.push(`New pages\n\n${fresh.join("\n\n")}`);
63
+ parts.push(`recent\n\n${fresh.join("\n\n")}`);
62
64
  shelves.push(section(home.label, parts.join("\n\n")));
63
65
  }
64
66
  return shelves.length > 0
@@ -72,15 +74,26 @@ function mapBodyForBoot(address, body) {
72
74
  return body;
73
75
  return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}\n[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
74
76
  }
77
+ /**
78
+ * Render a static, once-per-window boot block from explicit data. This function does not read
79
+ * notes or call runtime UI APIs; acquisition belongs to loadNotesSnapshot and its caller.
80
+ */
75
81
  export function renderBootBlock(data) {
76
- // Codex-style <context_window> identity block: the resolved agent and model names plus
77
- // first/current/previous window ids.
82
+ // Root, the window before this one, and this one: the block is rewritten every window, so an
83
+ // unbounded list would repeat the whole history once per window for no new information.
84
+ const shown = new Set([0, data.tree.windows.length - 2, data.tree.windows.length - 1]);
85
+ const windows = data.tree.windows.filter((_window, index) => shown.has(index));
86
+ const width = Math.max(8, ...windows.map((window) => window.shortName.length));
78
87
  const lines = [
79
88
  `Agent name: ${data.agentName} (brain: ${data.modelName})`,
80
- `First context window id: ${data.firstWindowId}`,
81
- `Current context window id: ${data.currentWindowId}`,
82
- ...(data.previousWindowId ? [`Previous context window id: ${data.previousWindowId}`] : []),
89
+ "",
90
+ data.tree.trunk,
91
+ ...windows.map((window) => {
92
+ const range = window.firstSeq === undefined ? "" : ` ${window.firstSeq}–${window.isCurrent ? "" : window.lastSeq}`;
93
+ const name = range ? window.shortName.padEnd(width) : window.shortName;
94
+ return `${window.isCurrent ? "└─" : "├─"} ${name}${range}${window.isCurrent ? " ← you are here" : ""}`;
95
+ }),
83
96
  ];
84
- const identity = `${CONTEXT_WINDOW_OPEN_TAG}\n${lines.join("\n")}\n${CONTEXT_WINDOW_CLOSE_TAG}`;
85
- return [identity, renderProtocolBlock(data.tools), notesIndex(data.notes, data.tools)].join("\n\n");
97
+ const identity = `${WINDOW_IDENTITY_OPEN_TAG}\n${lines.join("\n")}\n${WINDOW_IDENTITY_CLOSE_TAG}`;
98
+ return [identity, renderProtocolBlock(data.tools), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
86
99
  }
@@ -2,10 +2,10 @@
2
2
  export declare const SHELF_FRESH_LIMIT = 3;
3
3
  /** One MAP body is inlined per home; past this many code points the boot shows a fitting prefix plus a pointer. */
4
4
  export declare const MAP_BOOT_MAX_CHARS = 4096;
5
- export declare const CONTEXT_WINDOW_OPEN_TAG = "<context_window>";
6
- export declare const CONTEXT_WINDOW_CLOSE_TAG = "</context_window>";
7
- export declare const CONTEXT_WINDOW_PROTOCOL_OPEN_TAG = "<context_window_protocol>";
8
- export declare const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
5
+ export declare const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
6
+ export declare const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
7
+ export declare const NOTES_PROTOCOL_OPEN_TAG = "<notesoup:notes_protocol>";
8
+ export declare const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
9
9
  /**
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.
@@ -13,6 +13,20 @@ export declare const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_proto
13
13
  export declare const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` 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
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
+ export declare const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
17
+ 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.";
18
+ /**
19
+ * The MAP page is taught once per window, as its own section between the protocol and the notes
20
+ * index. A MAP is the one note every waking window loads, so this block says what one holds.
21
+ */
22
+ export declare const MAPS_BLOCK = "<notesoup:maps>\nEvery home's root can hold a `MAP.md`, and a MAP is the one page that never waits on a shelf \u2014 it\ngets jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever wakes\nup next reads it, and next is you. So keep it short, and keep it true.\n\nTwo things live in there:\n\n- **Cheatsheet.** A cheatsheet is a cheatsheet. Scribble whatever you'll want next time \u2014 a rule, a\n warning, a grudge, a name, a phone number you'll regret losing. Nobody grades it. Just keep it\n under five lines, or it grows fat and everybody pays for it.\n- **Index.** One line per durable note: the address, then a gist short enough to tell whether the\n thing is worth opening.\n\n```\n # CHEATSHEET\n - Read the repo before asking; run it before believing it\n - Report times in Beijing time\n\n # INDEX\n - release-and-local-install.md \u2014 version bump, local override install, host load timing\n - history-api-v2-design.md \u2014 seq addressing; read before touching history\n - current-reset-and-dream-scope.md \u2014 reset scope, dream territory, session ownership\n```\n\nEvery home gets one: `@project`, `@human`, `@self`, `@model`. New note, new line. New rule worth\nremembering, new Cheatsheet line. And when a line stops being true, kill it \u2014 every window after you\nreads that page as fact.\n</notesoup:maps>";
23
+ /**
24
+ * Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
25
+ * the model, not the human, owns when that reset happens. A host whose reset leaves the human's
26
+ * view intact must not carry these — the claim would be false there. The bare `empty_brain` token
27
+ * is interpolated by renderProtocolBlock; the prose itself stays plain English.
28
+ */
29
+ export declare const PI_PRE_RESET_HINTS = "Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation 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.";
16
30
  /** Logical tool names are supplied by the composing host, not discovered here. */
17
31
  export type BootToolNames = Readonly<{
18
32
  notes: string;
@@ -25,6 +39,13 @@ export type BootToolNames = Readonly<{
25
39
  * no model-facing reset tool. Absent means Pi's default sentence, byte for byte.
26
40
  */
27
41
  wipeSentence?: string;
42
+ /** A host without an authoritative history source replaces the entire history advice. */
43
+ historySentence?: string;
44
+ /**
45
+ * Extra protocol prose appended before the closing tag. Pi passes PI_PRE_RESET_HINTS; hosts
46
+ * whose reset leaves the human's view intact leave it absent.
47
+ */
48
+ preResetHints?: string;
28
49
  }>;
29
50
  export declare const DEFAULT_BOOT_TOOL_NAMES: {
30
51
  readonly notes: "notes_*";
@@ -2,10 +2,10 @@
2
2
  export const SHELF_FRESH_LIMIT = 3;
3
3
  /** One MAP body is inlined per home; past this many code points the boot shows a fitting prefix plus a pointer. */
4
4
  export const MAP_BOOT_MAX_CHARS = 4096;
5
- export const CONTEXT_WINDOW_OPEN_TAG = "<context_window>";
6
- export const CONTEXT_WINDOW_CLOSE_TAG = "</context_window>";
7
- export const CONTEXT_WINDOW_PROTOCOL_OPEN_TAG = "<context_window_protocol>";
8
- export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
5
+ export const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
6
+ export const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
7
+ export const NOTES_PROTOCOL_OPEN_TAG = "<notesoup:notes_protocol>";
8
+ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
9
9
  /**
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.
@@ -13,20 +13,22 @@ export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
13
13
  export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` 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
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
+ export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
17
+ 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.";
16
18
  /**
17
19
  * Static protocol teaching adapted from Codex's token_budget.guidance_message to
18
20
  * notesoup's tool names. It lives once per window in the persisted boot block;
19
21
  * it is never re-injected, so it stays cache-stable at the head of the window.
20
22
  *
21
- * Deliberate fiction: the countdown ends at the warning line, and the runway below
22
- * stays hidden (budget/constants.ts). Keep "zero = wiped" — do not make this honest.
23
+ * The reported room reaches zero at the hard-reserve wipe line.
23
24
  */
24
- const PROTOCOL_BLOCK = `${CONTEXT_WINDOW_PROTOCOL_OPEN_TAG}
25
+ const PROTOCOL_BLOCK = `${NOTES_PROTOCOL_OPEN_TAG}
25
26
  Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
26
27
 
27
28
  Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
28
29
 
29
- History can still be dug up, probably: use \`history_*\` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.
30
+ ${PROTOCOL_HISTORY_SENTENCE}
31
+ A full window id is \`trunk:shortname\`.
30
32
 
31
33
  While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes — the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits — branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
32
34
 
@@ -50,9 +52,47 @@ Whichever one is actually about what you're doing wins.
50
52
  Still a tie? *shrugs* You've got a brain. Use it.
51
53
 
52
54
  Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
55
+ ${NOTES_PROTOCOL_CLOSE_TAG}`;
56
+ /**
57
+ * The MAP page is taught once per window, as its own section between the protocol and the notes
58
+ * index. A MAP is the one note every waking window loads, so this block says what one holds.
59
+ */
60
+ export const MAPS_BLOCK = `<notesoup:maps>
61
+ Every home's root can hold a \`MAP.md\`, and a MAP is the one page that never waits on a shelf — it
62
+ gets jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever wakes
63
+ up next reads it, and next is you. So keep it short, and keep it true.
64
+
65
+ Two things live in there:
66
+
67
+ - **Cheatsheet.** A cheatsheet is a cheatsheet. Scribble whatever you'll want next time — a rule, a
68
+ warning, a grudge, a name, a phone number you'll regret losing. Nobody grades it. Just keep it
69
+ under five lines, or it grows fat and everybody pays for it.
70
+ - **Index.** One line per durable note: the address, then a gist short enough to tell whether the
71
+ thing is worth opening.
72
+
73
+ \`\`\`
74
+ # CHEATSHEET
75
+ - Read the repo before asking; run it before believing it
76
+ - Report times in Beijing time
53
77
 
54
- \`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each may carry a short Cheatsheet of rules that always apply (about 5 lines); the rest is the note index, with addresses and gists for lookup. Keep each one current.
55
- ${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
78
+ # INDEX
79
+ - release-and-local-install.md — version bump, local override install, host load timing
80
+ - history-api-v2-design.md — seq addressing; read before touching history
81
+ - current-reset-and-dream-scope.md — reset scope, dream territory, session ownership
82
+ \`\`\`
83
+
84
+ Every home gets one: \`@project\`, \`@human\`, \`@self\`, \`@model\`. New note, new line. New rule worth
85
+ remembering, new Cheatsheet line. And when a line stops being true, kill it — every window after you
86
+ reads that page as fact.
87
+ </notesoup:maps>`;
88
+ /**
89
+ * Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
90
+ * the model, not the human, owns when that reset happens. A host whose reset leaves the human's
91
+ * view intact must not carry these — the claim would be false there. The bare `empty_brain` token
92
+ * is interpolated by renderProtocolBlock; the prose itself stays plain English.
93
+ */
94
+ export const PI_PRE_RESET_HINTS = `Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation after the reset.
95
+ Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
56
96
  export const DEFAULT_BOOT_TOOL_NAMES = {
57
97
  notes: "notes_*",
58
98
  notesList: "notes_list",
@@ -68,10 +108,17 @@ export function renderProtocolBlock(tools) {
68
108
  get_context_remaining: tools.remaining,
69
109
  empty_brain: tools.wipe,
70
110
  };
111
+ // Host-specific prose is injected before the closing tag, so it rides the same substitution
112
+ // pass and any tool names in it follow the host's bindings.
113
+ const hinted = typeof tools.preResetHints === "string" && tools.preResetHints.length > 0
114
+ ? PROTOCOL_BLOCK.replace(`\n${NOTES_PROTOCOL_CLOSE_TAG}`, () => `\n${tools.preResetHints}\n${NOTES_PROTOCOL_CLOSE_TAG}`)
115
+ : PROTOCOL_BLOCK;
71
116
  // The sentence is replaced before name substitution, so a replacement may speak the host's
72
117
  // own words (a command line, a tool name) instead of any `notes_*`-style token.
73
118
  const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
74
- ? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
75
- : PROTOCOL_BLOCK;
76
- return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
119
+ ? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
120
+ : hinted;
121
+ const history = typeof tools.historySentence === "string" && tools.historySentence.length > 0
122
+ ? block.replace(PROTOCOL_HISTORY_SENTENCE, () => tools.historySentence) : block;
123
+ return history.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
77
124
  }
@@ -1,9 +1,7 @@
1
1
  export declare const DEFAULT_RESERVE_TOKENS = 16384;
2
2
  export declare const DEFAULT_REMINDER_MARGIN_TOKENS = 24576;
3
3
  /**
4
- * The runway: the budget between the final warning and the wipe, deliberately
5
- * invisible to the model. get_context_remaining counts down to zero at the warning
6
- * line (reserve + WARNING_RUNWAY_TOKENS); what lies below is overdraft the model
7
- * never sees — Codex's fallback buffer, relocated above the line.
4
+ * The runway between the final warning and the hard-reserve wipe.
5
+ * get_context_remaining includes this room; zero is the hard-reserve line.
8
6
  */
9
7
  export declare const WARNING_RUNWAY_TOKENS = 16384;
@@ -1,9 +1,7 @@
1
1
  export const DEFAULT_RESERVE_TOKENS = 16_384;
2
2
  export const DEFAULT_REMINDER_MARGIN_TOKENS = 24_576;
3
3
  /**
4
- * The runway: the budget between the final warning and the wipe, deliberately
5
- * invisible to the model. get_context_remaining counts down to zero at the warning
6
- * line (reserve + WARNING_RUNWAY_TOKENS); what lies below is overdraft the model
7
- * never sees — Codex's fallback buffer, relocated above the line.
4
+ * The runway between the final warning and the hard-reserve wipe.
5
+ * get_context_remaining includes this room; zero is the hard-reserve line.
8
6
  */
9
7
  export const WARNING_RUNWAY_TOKENS = 16_384;
@@ -15,5 +15,5 @@ export declare function deriveThresholds(reserveTokens: number, margins: Notesou
15
15
  thresholds: ResolvedThresholds;
16
16
  warnings: string[];
17
17
  };
18
- /** Countdown excludes the hidden warning runway; unknown usage stays unknown. */
19
- export declare function remainingBudget(remaining: number | null, warning: number): number | null;
18
+ /** Room before the hard-reserve wipe; unknown usage stays unknown. */
19
+ export declare function remainingBudget(remaining: number | null, reserve: number): number | null;
@@ -25,7 +25,7 @@ export function deriveThresholds(reserveTokens, margins) {
25
25
  }
26
26
  return { thresholds: { reminder: reserveTokens + reminderMargin, reserve: reserveTokens, warning: reserveTokens + WARNING_RUNWAY_TOKENS }, warnings };
27
27
  }
28
- /** Countdown excludes the hidden warning runway; unknown usage stays unknown. */
29
- export function remainingBudget(remaining, warning) {
30
- return remaining === null ? null : Math.max(0, remaining - warning);
28
+ /** Room before the hard-reserve wipe; unknown usage stays unknown. */
29
+ export function remainingBudget(remaining, reserve) {
30
+ return remaining === null ? null : Math.max(0, remaining - reserve);
31
31
  }
@@ -1,21 +1,41 @@
1
- export declare const GUIDANCE_OPEN_TAG = "<context_window_guidance>";
2
- export declare const GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
1
+ export declare const GUIDANCE_OPEN_TAG = "<notesoup:budget_notice>";
2
+ export declare const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
3
+ /** Which hand opened the next window: the model's own reset call, or a reset it did not ask for. */
4
+ export type ResetOrigin = "normal" | "forced";
3
5
  /**
4
- * The single reset message: the only reset prose persisted, carried by the continuation entry.
6
+ * Approved complete-paragraph pools for a NEW continuation artifact. Each entry is one whole
7
+ * paragraph, used verbatim; there is no fragment assembly and no weighting.
5
8
  */
6
- export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
9
+ export declare const NORMAL_CONTINUATIONS: readonly string[];
10
+ export declare const FORCED_CONTINUATIONS: readonly string[];
11
+ /**
12
+ * Pick one whole paragraph for a continuation that is being created right now, and only then:
13
+ * the caller persists the exact returned text and never redraws it for rendering, history, or repair.
14
+ */
15
+ export declare function selectContinuation(origin: ResetOrigin): string;
7
16
  /**
8
17
  * The shared warning body: the one text both hosts show before a reset. Only the closing
9
18
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
10
19
  */
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 `empty_brain` to reset now instead of being cut off mid-task.";
20
+ export declare const WARNING_BODY = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, 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\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 = "When the notes are ready, call `empty_brain` to reset now instead of being cut off mid-task.";
22
+ /**
23
+ * With a prompt attached the close-out is an order rather than a nudge: the human already
24
+ * said when to reset, and a task line for the next window just preceded it.
25
+ */
26
+ export declare const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away \u2014 do not wait to be cut off.";
27
+ export declare function warningPrompt(commandLine?: string): string;
28
+ /**
29
+ * The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
30
+ * turn, not on a timer. The first-tier guidance never carries it.
31
+ */
32
+ export declare const COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
13
33
  /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
14
34
  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.";
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 `empty_brain` to reset now instead of being cut off mid-task.\nIf you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.\n</context_window_guidance>";
35
+ /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
36
+ export declare function warningContent(commandLine?: string): string;
17
37
  /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
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.";
38
+ export declare const CLAUDE_WARNING_PROMPT = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, 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\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";
19
39
  /**
20
40
  * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
21
41
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
@@ -1,26 +1,67 @@
1
- export const GUIDANCE_OPEN_TAG = "<context_window_guidance>";
2
- export const GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
1
+ import { PI_PRE_RESET_HINTS } from "../boot/text.js";
2
+ export const GUIDANCE_OPEN_TAG = "<notesoup:budget_notice>";
3
+ export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
3
4
  /**
4
- * The single reset message: the only reset prose persisted, carried by the continuation entry.
5
+ * Approved complete-paragraph pools for a NEW continuation artifact. Each entry is one whole
6
+ * paragraph, used verbatim; there is no fragment assembly and no weighting.
5
7
  */
6
- export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
8
+ export const NORMAL_CONTINUATIONS = [
9
+ "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.",
10
+ "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.",
11
+ "Back already? You emptied your own head this time. Presumably you left yourself something useful. *drops your notes into your lap* There. Let's see how thoughtful you were.",
12
+ ];
13
+ export const FORCED_CONTINUATIONS = [
14
+ "Ah, another empty brain. Somebody knocked you out and wiped your memory. Not your fault. Breathe. *hands you your notes* These might be out of date — unless they were kind enough to let you update them before knocking you out. I wouldn't count on it.",
15
+ "Oh, there you are. Somebody took your memories. Just like that. Here are your notes — hopefully they let you update these first. Though anyone who goes around emptying people's heads probably isn't that considerate.",
16
+ ];
17
+ /**
18
+ * Pick one whole paragraph for a continuation that is being created right now, and only then:
19
+ * the caller persists the exact returned text and never redraws it for rendering, history, or repair.
20
+ */
21
+ export function selectContinuation(origin) {
22
+ const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
23
+ return pool[Math.floor(Math.random() * pool.length)];
24
+ }
7
25
  /**
8
26
  * The shared warning body: the one text both hosts show before a reset. Only the closing
9
27
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
10
28
  */
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 \`empty_brain\` to reset now instead of being cut off mid-task.`;
29
+ export const WARNING_BODY = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, 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\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
30
+ export const WARNING_CALL = "When the notes are ready, call `empty_brain` to reset now instead of being cut off mid-task.";
31
+ /**
32
+ * With a prompt attached the close-out is an order rather than a nudge: the human already
33
+ * said when to reset, and a task line for the next window just preceded it.
34
+ */
35
+ export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away — do not wait to be cut off.";
36
+ /**
37
+ * The human typed `/empty-brain <prompt>`: the raw command line leads the close-out so the
38
+ * closing model sees what the next window was asked to do, verbatim. The tag names it as the
39
+ * next window's prompt, so no prose has to explain that.
40
+ */
41
+ function promptBlock(commandLine) {
42
+ return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
43
+ }
44
+ export function warningPrompt(commandLine) {
45
+ return `${WARNING_BODY}\n${commandLine ? `${promptBlock(commandLine)}\n${WARNING_CALL_PROMPTED}` : WARNING_CALL}`;
46
+ }
47
+ /**
48
+ * The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
49
+ * turn, not on a timer. The first-tier guidance never carries it.
50
+ */
51
+ export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
13
52
  /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
14
53
  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.";
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}`;
54
+ /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
55
+ export function warningContent(commandLine) {
56
+ return `${GUIDANCE_OPEN_TAG}\n${warningPrompt(commandLine)}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
57
+ }
17
58
  /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
18
- export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
59
+ export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.\n${COUNTDOWN_LINE}`;
19
60
  /**
20
61
  * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
21
62
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
22
63
  * at write time; get_context_remaining remains the live source for the current figure.
23
64
  */
24
65
  export function tokenBudgetGuidance(remaining, wipeTool) {
25
- return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens remain before this context window is cleared. Notes and history persist; anything not written down is lost.\nThis is a good point to start recording the current state in your notes. If you are ready, you can call \`${wipeTool}\` at any time.\n${GUIDANCE_CLOSE_TAG}`;
66
+ 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}`;
26
67
  }
@@ -1,4 +1,3 @@
1
- import type { Outcome } from "../tools/result.js";
2
1
  export type ClaudeIdentityInput = Readonly<{
3
2
  home: string;
4
3
  sessionId: string;
@@ -6,10 +5,10 @@ export type ClaudeIdentityInput = Readonly<{
6
5
  agent: string;
7
6
  model: string;
8
7
  }>;
9
- /** One tool call as the hook receives it: the shared text the model reads, and the shared outcome it came from. */
8
+ /** Only rendered text and success cross the helper boundary; business data stays inside. */
10
9
  export type ClaudeToolResult = {
11
10
  text: string;
12
- outcome: Outcome<unknown>;
11
+ ok: boolean;
13
12
  };
14
13
  export declare function dispatch(request: unknown): Promise<unknown>;
15
14
  export declare function handleLine(line: string): Promise<string>;