notesoup 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/boot/render.d.ts +14 -7
- package/dist/src/boot/render.js +29 -16
- package/dist/src/boot/text.d.ts +25 -4
- package/dist/src/boot/text.js +59 -11
- package/dist/src/budget/text.d.ts +29 -9
- package/dist/src/budget/text.js +51 -10
- package/dist/src/claude/helper.d.ts +2 -3
- package/dist/src/claude/helper.js +45 -11
- package/dist/src/claude/history.d.ts +9 -0
- package/dist/src/claude/history.js +271 -0
- package/dist/src/dsh/engine.d.ts +2 -1
- package/dist/src/dsh/engine.js +18 -9
- package/dist/src/dsh/index.js +9 -4
- package/dist/src/dsh/window.d.ts +2 -1
- package/dist/src/dsh/window.js +14 -8
- package/dist/src/history/query.js +59 -81
- package/dist/src/notes/address.d.ts +5 -0
- package/dist/src/notes/address.js +20 -21
- package/dist/src/notes/store.js +12 -19
- package/dist/src/pi/boot.d.ts +1 -1
- package/dist/src/pi/boot.js +28 -5
- package/dist/src/pi/budget.d.ts +0 -2
- package/dist/src/pi/budget.js +13 -53
- package/dist/src/pi/entries.d.ts +0 -1
- package/dist/src/pi/entries.js +0 -1
- package/dist/src/pi/history.d.ts +3 -0
- package/dist/src/pi/history.js +4 -0
- package/dist/src/pi/reset/artifacts.d.ts +7 -2
- package/dist/src/pi/reset/artifacts.js +16 -14
- package/dist/src/pi/reset/lifecycle.d.ts +21 -25
- package/dist/src/pi/reset/lifecycle.js +49 -73
- package/dist/src/pi/runtime.js +19 -18
- package/dist/src/pi/window.d.ts +12 -6
- package/dist/src/pi/window.js +7 -0
- package/dist/test/agent-loop.test.js +65 -42
- package/dist/test/boot.integration.test.js +119 -16
- package/dist/test/budget-settings.integration.test.js +4 -2
- package/dist/test/claude-history.test.d.ts +1 -0
- package/dist/test/claude-history.test.js +184 -0
- package/dist/test/claude-mod.test.js +243 -49
- package/dist/test/dsh.test.js +79 -2
- package/dist/test/helpers/extension.d.ts +3 -0
- package/dist/test/helpers/extension.js +33 -5
- package/dist/test/history.integration.test.js +66 -0
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/model-facing-text.test.d.ts +1 -0
- package/dist/test/model-facing-text.test.js +181 -0
- package/dist/test/notes.integration.test.js +16 -18
- package/dist/test/reset-lifecycle.test.js +202 -47
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +15 -3
- package/docs/dsh.md +1 -1
- package/docs/reset-lifecycle.md +32 -20
- package/docs/skills.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +836 -92
- package/mods/notesoup/hooks/register.ts +154 -52
- package/package.json +1 -1
- package/src/boot/render.ts +41 -23
- package/src/boot/text.ts +68 -11
- package/src/budget/text.ts +61 -10
- package/src/claude/helper.ts +53 -22
- package/src/claude/history.ts +228 -0
- package/src/dsh/engine.ts +16 -9
- package/src/dsh/index.ts +8 -3
- package/src/dsh/window.ts +15 -9
- package/src/history/query.ts +57 -82
- package/src/notes/address.ts +19 -16
- package/src/notes/store.ts +9 -14
- package/src/pi/boot.ts +27 -5
- package/src/pi/budget.ts +13 -50
- package/src/pi/entries.ts +0 -1
- package/src/pi/history.ts +7 -2
- package/src/pi/reset/artifacts.ts +17 -14
- package/src/pi/reset/lifecycle.ts +57 -80
- package/src/pi/runtime.ts +19 -18
- package/src/pi/window.ts +11 -1
package/README.md
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
|
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;
|
package/dist/src/boot/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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: "
|
|
34
|
-
{ scope: "project", label: "
|
|
35
|
-
{ scope: "agent", label:
|
|
36
|
-
{ scope: "model", label:
|
|
37
|
-
{ scope: "human", label: "
|
|
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(`
|
|
61
|
+
parts.push(`map\n\n${indent(mapBodyForBoot(map.address, map.body))}`);
|
|
60
62
|
if (fresh.length > 0)
|
|
61
|
-
parts.push(`
|
|
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
|
-
//
|
|
77
|
-
//
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
...(
|
|
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 = `${
|
|
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
|
}
|
package/dist/src/boot/text.d.ts
CHANGED
|
@@ -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
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
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_*";
|
package/dist/src/boot/text.js
CHANGED
|
@@ -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
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
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,6 +13,8 @@ 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;
|
|
@@ -21,12 +23,13 @@ export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end yo
|
|
|
21
23
|
* Deliberate fiction: the countdown ends at the warning line, and the runway below
|
|
22
24
|
* stays hidden (budget/constants.ts). Keep "zero = wiped" — do not make this honest.
|
|
23
25
|
*/
|
|
24
|
-
const PROTOCOL_BLOCK = `${
|
|
26
|
+
const PROTOCOL_BLOCK = `${NOTES_PROTOCOL_OPEN_TAG}
|
|
25
27
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
26
28
|
|
|
27
29
|
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
30
|
|
|
29
|
-
|
|
31
|
+
${PROTOCOL_HISTORY_SENTENCE}
|
|
32
|
+
A full window id is \`trunk:shortname\`.
|
|
30
33
|
|
|
31
34
|
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
35
|
|
|
@@ -50,9 +53,47 @@ Whichever one is actually about what you're doing wins.
|
|
|
50
53
|
Still a tie? *shrugs* You've got a brain. Use it.
|
|
51
54
|
|
|
52
55
|
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\`.
|
|
56
|
+
${NOTES_PROTOCOL_CLOSE_TAG}`;
|
|
57
|
+
/**
|
|
58
|
+
* The MAP page is taught once per window, as its own section between the protocol and the notes
|
|
59
|
+
* index. A MAP is the one note every waking window loads, so this block says what one holds.
|
|
60
|
+
*/
|
|
61
|
+
export const MAPS_BLOCK = `<notesoup:maps>
|
|
62
|
+
Every home's root can hold a \`MAP.md\`, and a MAP is the one page that never waits on a shelf — it
|
|
63
|
+
gets jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever wakes
|
|
64
|
+
up next reads it, and next is you. So keep it short, and keep it true.
|
|
65
|
+
|
|
66
|
+
Two things live in there:
|
|
67
|
+
|
|
68
|
+
- **Cheatsheet.** A cheatsheet is a cheatsheet. Scribble whatever you'll want next time — a rule, a
|
|
69
|
+
warning, a grudge, a name, a phone number you'll regret losing. Nobody grades it. Just keep it
|
|
70
|
+
under five lines, or it grows fat and everybody pays for it.
|
|
71
|
+
- **Index.** One line per durable note: the address, then a gist short enough to tell whether the
|
|
72
|
+
thing is worth opening.
|
|
73
|
+
|
|
74
|
+
\`\`\`
|
|
75
|
+
# CHEATSHEET
|
|
76
|
+
- Read the repo before asking; run it before believing it
|
|
77
|
+
- Report times in Beijing time
|
|
53
78
|
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
# INDEX
|
|
80
|
+
- release-and-local-install.md — version bump, local override install, host load timing
|
|
81
|
+
- history-api-v2-design.md — seq addressing; read before touching history
|
|
82
|
+
- current-reset-and-dream-scope.md — reset scope, dream territory, session ownership
|
|
83
|
+
\`\`\`
|
|
84
|
+
|
|
85
|
+
Every home gets one: \`@project\`, \`@human\`, \`@self\`, \`@model\`. New note, new line. New rule worth
|
|
86
|
+
remembering, new Cheatsheet line. And when a line stops being true, kill it — every window after you
|
|
87
|
+
reads that page as fact.
|
|
88
|
+
</notesoup:maps>`;
|
|
89
|
+
/**
|
|
90
|
+
* Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
|
|
91
|
+
* the model, not the human, owns when that reset happens. A host whose reset leaves the human's
|
|
92
|
+
* view intact must not carry these — the claim would be false there. The bare `empty_brain` token
|
|
93
|
+
* is interpolated by renderProtocolBlock; the prose itself stays plain English.
|
|
94
|
+
*/
|
|
95
|
+
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.
|
|
96
|
+
Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
|
|
56
97
|
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
57
98
|
notes: "notes_*",
|
|
58
99
|
notesList: "notes_list",
|
|
@@ -68,10 +109,17 @@ export function renderProtocolBlock(tools) {
|
|
|
68
109
|
get_context_remaining: tools.remaining,
|
|
69
110
|
empty_brain: tools.wipe,
|
|
70
111
|
};
|
|
112
|
+
// Host-specific prose is injected before the closing tag, so it rides the same substitution
|
|
113
|
+
// pass and any tool names in it follow the host's bindings.
|
|
114
|
+
const hinted = typeof tools.preResetHints === "string" && tools.preResetHints.length > 0
|
|
115
|
+
? PROTOCOL_BLOCK.replace(`\n${NOTES_PROTOCOL_CLOSE_TAG}`, () => `\n${tools.preResetHints}\n${NOTES_PROTOCOL_CLOSE_TAG}`)
|
|
116
|
+
: PROTOCOL_BLOCK;
|
|
71
117
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
72
118
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
73
119
|
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
74
|
-
?
|
|
75
|
-
:
|
|
76
|
-
|
|
120
|
+
? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
|
|
121
|
+
: hinted;
|
|
122
|
+
const history = typeof tools.historySentence === "string" && tools.historySentence.length > 0
|
|
123
|
+
? block.replace(PROTOCOL_HISTORY_SENTENCE, () => tools.historySentence) : block;
|
|
124
|
+
return history.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
|
|
77
125
|
}
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
export declare const GUIDANCE_OPEN_TAG = "<
|
|
2
|
-
export declare const GUIDANCE_CLOSE_TAG = "</
|
|
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
|
-
*
|
|
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
|
|
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
|
|
12
|
-
export declare const
|
|
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
|
|
16
|
-
export declare
|
|
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
|
|
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
|
package/dist/src/budget/text.js
CHANGED
|
@@ -1,26 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
export const
|
|
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
|
-
*
|
|
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
|
|
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
|
|
12
|
-
export const
|
|
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
|
|
16
|
-
export
|
|
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
|
|
66
|
+
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens left. Then this brain is emptied.\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
|
-
/**
|
|
8
|
+
/** Only rendered text and success cross the helper boundary; business data stays inside. */
|
|
10
9
|
export type ClaudeToolResult = {
|
|
11
10
|
text: string;
|
|
12
|
-
|
|
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>;
|
|
@@ -2,15 +2,16 @@ import { realpathSync } from "node:fs";
|
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { Check, Errors } from "typebox/value";
|
|
4
4
|
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../tools/notes.js";
|
|
5
|
+
import { historyList, historyRead, historyWindows } from "../tools/history.js";
|
|
6
|
+
import { readClaudeHistory } from "./history.js";
|
|
5
7
|
import { loadNotesSnapshot } from "../boot/snapshot.js";
|
|
6
8
|
import { renderBootBlock } from "../boot/render.js";
|
|
7
|
-
import { CLAUDE_WIPE_SENTENCE } from "../boot/text.js";
|
|
8
|
-
import { CLAUDE_WARNING_PROMPT,
|
|
9
|
+
import { CLAUDE_WIPE_SENTENCE, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE } from "../boot/text.js";
|
|
10
|
+
import { CLAUDE_WARNING_PROMPT, selectContinuation } from "../budget/text.js";
|
|
9
11
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
10
12
|
import { projectKey, snapshotNotesIdentity } from "../notes/index.js";
|
|
11
13
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
12
14
|
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
13
|
-
const TOOL_NAMES = ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"];
|
|
14
15
|
function identity(input) {
|
|
15
16
|
if (!input || typeof input !== "object" || typeof input.cwd !== "string")
|
|
16
17
|
throw new Error("invalid identity");
|
|
@@ -27,17 +28,17 @@ function paramProblem(schema, params) {
|
|
|
27
28
|
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
28
29
|
}
|
|
29
30
|
/** Bind one shared operation to the identity Claude supplies. Validate untyped Claude parameters against the shared operation schema before execution. */
|
|
30
|
-
function boundOperation(operation
|
|
31
|
+
function boundOperation(operation) {
|
|
31
32
|
return {
|
|
32
33
|
description: operation.description,
|
|
33
34
|
parameters: operation.parameters,
|
|
34
|
-
async call(params,
|
|
35
|
+
async call(params, ...context) {
|
|
35
36
|
// Refuse before the operation can act: a rejected shape never reaches a write.
|
|
36
37
|
if (!Check(operation.parameters, params))
|
|
37
38
|
throw new Error(`invalid ${operation.name} parameters: ${paramProblem(operation.parameters, params)}`);
|
|
38
39
|
// The same business outcome and the same renderer as the Pi tool; only the envelope differs.
|
|
39
|
-
const outcome = await operation.execute(params,
|
|
40
|
-
return { text: operation.render(outcome), outcome };
|
|
40
|
+
const outcome = await operation.execute(params, ...context);
|
|
41
|
+
return { text: operation.render(outcome), ok: outcome.ok };
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
}
|
|
@@ -48,26 +49,55 @@ const OPERATIONS = {
|
|
|
48
49
|
notes_list: boundOperation(notesList),
|
|
49
50
|
notes_search: boundOperation(notesSearch),
|
|
50
51
|
};
|
|
52
|
+
const HISTORY_OPERATIONS = {
|
|
53
|
+
history_list: boundOperation(historyList),
|
|
54
|
+
history_read: boundOperation(historyRead),
|
|
55
|
+
history_windows: boundOperation(historyWindows),
|
|
56
|
+
};
|
|
57
|
+
function historySource(value, sessionId) {
|
|
58
|
+
if (!value || typeof value !== "object")
|
|
59
|
+
throw new Error("Claude history transcript_path is unavailable");
|
|
60
|
+
const source = value;
|
|
61
|
+
if (source.sessionId !== sessionId)
|
|
62
|
+
throw new Error("Claude history binding belongs to a different session");
|
|
63
|
+
return source;
|
|
64
|
+
}
|
|
51
65
|
export async function dispatch(request) {
|
|
52
66
|
if (!request || typeof request !== "object" || Array.isArray(request))
|
|
53
67
|
throw new Error("malformed request");
|
|
54
68
|
const value = request;
|
|
55
69
|
if (value.op === "schemas")
|
|
56
|
-
return
|
|
70
|
+
return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
|
|
57
71
|
// The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
|
|
58
72
|
// cannot drift apart. The hooks module caches one copy per session.
|
|
59
73
|
if (value.op === "texts")
|
|
60
|
-
return { warning: CLAUDE_WARNING_PROMPT,
|
|
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.
|
|
77
|
+
if (value.op === "continuation") {
|
|
78
|
+
if (value.origin !== "normal" && value.origin !== "forced")
|
|
79
|
+
throw new Error("invalid reset origin");
|
|
80
|
+
return { text: selectContinuation(value.origin) };
|
|
81
|
+
}
|
|
61
82
|
// Threshold derivation crosses the boundary as raw facts: everything the engine could
|
|
62
83
|
// read, unvalidated. resolveClaudeLimits guards every field and never throws.
|
|
63
84
|
if (value.op === "limits")
|
|
64
85
|
return resolveClaudeLimits(value.facts);
|
|
65
86
|
if (value.op === "tool") {
|
|
66
|
-
if (typeof value.tool !== "string" || !
|
|
87
|
+
if (typeof value.tool !== "string" || (!Object.hasOwn(OPERATIONS, value.tool) && !Object.hasOwn(HISTORY_OPERATIONS, value.tool)))
|
|
67
88
|
throw new Error("unknown tool");
|
|
68
89
|
const id = identity(value.identity);
|
|
90
|
+
if (Object.hasOwn(HISTORY_OPERATIONS, value.tool)) {
|
|
91
|
+
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
92
|
+
return HISTORY_OPERATIONS[value.tool].call(value.params, projection, id.sessionId);
|
|
93
|
+
}
|
|
69
94
|
return OPERATIONS[value.tool].call(value.params, id);
|
|
70
95
|
}
|
|
96
|
+
if (value.op === "history_state") {
|
|
97
|
+
const id = identity(value.identity);
|
|
98
|
+
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
99
|
+
return { window: projection.windows.length - 1 };
|
|
100
|
+
}
|
|
71
101
|
if (value.op === "boot") {
|
|
72
102
|
const id = identity(value.identity);
|
|
73
103
|
if (!value.tools || typeof value.tools !== "object")
|
|
@@ -77,7 +107,11 @@ export async function dispatch(request) {
|
|
|
77
107
|
throw new Error("invalid context window");
|
|
78
108
|
const snapshot = await loadNotesSnapshot(id, typeof value.openedAt === "number" ? value.openedAt : Date.now());
|
|
79
109
|
const windowId = (index) => `claude:${id.sessionId}:${index}`;
|
|
80
|
-
|
|
110
|
+
const trunk = `claude:${id.sessionId}`;
|
|
111
|
+
const tree = { trunk, windows: Array.from({ length: window + 1 }, (_, index) => ({ shortName: String(index), isCurrent: index === window })) };
|
|
112
|
+
const rendered = renderBootBlock({ agentName: id.agent, modelName: id.model, tree, notes: snapshot, tools: value.tools });
|
|
113
|
+
// Retained Claude boots are restored by their full current/previous ids.
|
|
114
|
+
return `${rendered}\nCurrent context window id: ${windowId(window)}${window > 0 ? `\nPrevious context window id: ${windowId(window - 1)}` : ""}`;
|
|
81
115
|
}
|
|
82
116
|
throw new Error("unknown operation");
|
|
83
117
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type HistoryProjection } from "../history/history.js";
|
|
2
|
+
export type ClaudeHistorySource = {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
transcriptPath: string;
|
|
5
|
+
headUuid?: string;
|
|
6
|
+
};
|
|
7
|
+
/** All addresses are allocated on the full first-occurrence log, before branch selection. */
|
|
8
|
+
export declare function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistorySource, "transcriptPath">): HistoryProjection;
|
|
9
|
+
export declare function readClaudeHistory(source: ClaudeHistorySource): Promise<HistoryProjection>;
|