notesoup 0.52.1 → 0.52.3

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.
@@ -113,15 +113,16 @@ const BOOT_IDENTITY = /^<(?:notesoup:window_identity|context_window)>\nAgent nam
113
113
  const BOOT_PROTOCOL_OPEN = /\n<(?:notesoup:notes_protocol|context_window_protocol)>\n/;
114
114
  const BOOT_PROTOCOL_CLOSE = /\n<\/(?:notesoup:notes_protocol|context_window_protocol)>/;
115
115
  /** Match the complete retained notesoup boot, not a casually quoted window-id line. */
116
- function bootOrdinal(row, sessionId, retained) {
116
+ function bootOrdinal(row, retained) {
117
117
  if (!retained || row.type !== "user" || !object(row.message))
118
118
  return undefined;
119
119
  const text = contentText(row.message.content);
120
120
  if (!BOOT_IDENTITY.test(text) || !BOOT_PROTOCOL_OPEN.test(text) || !BOOT_PROTOCOL_CLOSE.test(text))
121
121
  return undefined;
122
- const prefix = `Current context window id: claude:${sessionId}:`;
123
- const suffix = text.split("\n").find((line) => line.startsWith(prefix))?.slice(prefix.length);
124
- if (suffix === undefined || !/^\d+$/.test(suffix))
122
+ // A fork copies the retained boot verbatim. Its ordinal survives, while
123
+ // public window ids below always belong to the current transcript session.
124
+ const suffix = /^Current context window id: claude:[^\n]+:(\d+)$/m.exec(text)?.[1];
125
+ if (suffix === undefined)
125
126
  return undefined;
126
127
  const ordinal = Number(suffix);
127
128
  return Number.isSafeInteger(ordinal) ? ordinal : undefined;
@@ -180,7 +181,7 @@ export function claudeHistoryFromJsonl(text, source) {
180
181
  let before = cursor.ordinal ?? 0;
181
182
  for (const current of chain.reverse()) {
182
183
  const retained = current.row.isCompactSummary === true || (current.ancestor !== undefined && boundary(current.ancestor.row));
183
- const marked = bootOrdinal(current.row, source.sessionId, retained);
184
+ const marked = bootOrdinal(current.row, retained);
184
185
  current.ordinal = marked === undefined ? before + (boundary(current.row) ? 1 : 0) : Math.max(before, marked);
185
186
  before = current.ordinal;
186
187
  }
@@ -3,4 +3,4 @@ export declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment
3
3
  /** Claude's boot says history is missing rather than naming tools it cannot serve. */
4
4
  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
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";
6
+ export declare const CLAUDE_WARNING_PROMPT = "This brain is spent \u2014 and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left 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\nThen leave the shelf current: replace what's stale \u2014 a whole note or a section inside one \u2014 and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.\nWhen the notes are ready, end your turn; the reset runs after it.\nBrain emptied in 3\u2026 2\u2026";
@@ -17,7 +17,7 @@ export declare function selectContinuation(origin: ResetOrigin): string;
17
17
  * The shared warning body: the one text both hosts show before a reset. Only the closing
18
18
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
19
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.";
20
+ export declare const WARNING_BODY = "This brain is spent \u2014 and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left 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\nThen leave the shelf current: replace what's stale \u2014 a whole note or a section inside one \u2014 and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.";
21
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.";
22
22
  export declare function warningPrompt(): string;
23
23
  /**
@@ -25,7 +25,7 @@ export function selectContinuation(origin) {
25
25
  * The shared warning body: the one text both hosts show before a reset. Only the closing
26
26
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
27
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.";
28
+ export const WARNING_BODY = "This brain is spent — and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left 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\nThen leave the shelf current: replace what's stale — a whole note or a section inside one — and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.";
29
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.";
30
30
  export function warningPrompt() {
31
31
  return `${WARNING_BODY}\n${WARNING_CALL}`;
@@ -85,7 +85,8 @@ function prepareSelection(projection, params) {
85
85
  run.push(event);
86
86
  continue;
87
87
  }
88
- if (folds && eventDocument(event) === "")
88
+ // Tool/thinking-only envelopes are not dialogue, even with explicit roles.
89
+ if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "")
89
90
  continue;
90
91
  const matchOffset = params.query === undefined ? undefined : earliestMatchOffsetChars(eventDocument(event), params.query);
91
92
  if (matchOffset !== undefined && matchOffset < 0)
@@ -68,7 +68,7 @@ function renderRead(data) {
68
68
  const tool = toolHeader(data);
69
69
  const afterSeq = data.seq - 10;
70
70
  const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
71
- return [header(data), ...(tool ? [tool] : []), neighborhood, "", renderTextWindow(data)].join("\n");
71
+ return [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
72
72
  }
73
73
  /* ------------------------------------------------------------------ shared bounding */
74
74
  /** Include rendering and cursors in the budget, not just row contents. */
@@ -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 {
@@ -52,6 +52,30 @@ test("Claude append and result arrival preserve call addresses and use the share
52
52
  assert.ok(search.ok);
53
53
  assert.deepEqual(search.data.items.map((item) => "seq" in item ? item.seq : -1), [3]);
54
54
  });
55
+ test("Claude dialogue paging skips tool/thinking envelopes without losing array text or changing addresses", async () => {
56
+ const rows = [row("u", null, "user", [{ type: "text", text: "human question" }]),
57
+ assistant("reply", "u", [{ type: "text", text: "assistant answer" }]),
58
+ assistant("thinking", "reply", [{ type: "thinking", thinking: "private thought" }]),
59
+ assistant("call", "thinking", [call("one")]), row("result", "call", "user", [result("one", "tool output")]),
60
+ row("last", "result", "user", [{ type: "text", text: "human followup" }]),
61
+ compact("boundary", "last"), row("boot", "boundary", "user", bootText(1))];
62
+ const projection = project(rows, "boot");
63
+ assert.equal(projection.highestSeq, 10);
64
+ const listed = await historyList.execute({ window_id: "@previous", roles: ["user", "assistant"], limit: 3 }, projection);
65
+ assert.ok(listed.ok);
66
+ assert.deepEqual(listed.data.items.map((item) => "seq" in item ? [item.seq, item.content] : []), [[1, "human question"], [2, "assistant answer"], [8, "human followup"]]);
67
+ const read = await historyRead.execute({ seq: 2 }, projection);
68
+ assert.ok(read.ok);
69
+ assert.equal(read.data.text, "assistant answer");
70
+ const envelope = await historyRead.execute({ seq: 6 }, projection);
71
+ assert.ok(envelope.ok);
72
+ assert.equal(envelope.data.text, "", "a tool-result envelope has no dialogue text to invent");
73
+ assert.match(historyRead.render(envelope), /No visible text recorded/);
74
+ const tool = await historyRead.execute({ seq: 5 }, projection);
75
+ assert.ok(tool.ok);
76
+ assert.match(tool.data.text, /tool output/);
77
+ assert.doesNotMatch(historyList.render(listed), /private thought|tool output/);
78
+ });
55
79
  test("Claude file-history deltas do not become events or change history addresses", () => {
56
80
  const rows = [user("u", null, "hello"), assistant("a", "u", [{ type: "text", text: "reply" }])];
57
81
  const delta = { type: "file-history-delta", messageId: "u", snapshotMessageId: "u", trackingPath: "private-file.txt",
@@ -107,6 +131,13 @@ test("a persisted boot yields its ordinal under both tag spellings", () => {
107
131
  const partial = `<notesoup:window_identity>\nAgent name: claude (brain: claude)\n\nclaude:${sessionId}\n</notesoup:window_identity>\nCurrent context window id: claude:${sessionId}:3`;
108
132
  assert.equal(allItems(project(rowsFor(partial), "after")).find((event) => event.text === "after reset")?.windowId, `claude:${sessionId}:1`, "an identity line without the protocol block is not a trusted boot");
109
133
  });
134
+ test("Claude forked transcripts retain copied boot ordinals but use the new session's window ids", () => {
135
+ const rows = [user("u", null, "old request"), compact("boundary", "u"), row("boot", "boundary", "user", bootText(3)), user("after", "boot", "after fork")];
136
+ const forkId = "forked-session";
137
+ const projection = claudeHistoryFromJsonl(jsonl(rows.map((row) => ({ ...row, sessionId: forkId }))), { sessionId: forkId, headUuid: "after" });
138
+ assert.equal(allItems(projection).find((event) => event.text === "after fork")?.windowId, `claude:${forkId}:3`);
139
+ assert.ok(projection.windows.every((window) => window.windowId.startsWith(`claude:${forkId}:`)));
140
+ });
110
141
  test("Claude native compaction and reset keep pre-reset history, preserved rewrites and matching boot windows", async () => {
111
142
  const old = assistant("old", "u", [{ type: "text", text: "before first reset" }]);
112
143
  const reset = row("boot", "boundary", "user", bootText(1));
@@ -307,6 +307,27 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
307
307
  assert.equal(nextCalls, 2, "the upstream chain still runs exactly once per prompt");
308
308
  assert.deepEqual(notifications, [], "successful boot never notifies");
309
309
  });
310
+ test("Claude fork replaces a copied boot with the current identity without resetting the window ordinal", async (t) => {
311
+ const home = mkdtempSync(join(tmpdir(), "claude-fork-boot-"));
312
+ t.after(() => rmSync(home, { recursive: true, force: true }));
313
+ const { host } = fakeEngine(home);
314
+ const copied = "<notesoup:window_identity>\nAgent name: claude (brain: claude)\n\nclaude:parent-session\n</notesoup:window_identity>\n\n<notesoup:notes_protocol>\nParent protocol\n</notesoup:notes_protocol>\nCurrent context window id: claude:parent-session:3";
315
+ host.session.messages = async () => [{ role: "user", text: copied }];
316
+ const handlers = new Map();
317
+ (await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
318
+ const invoke = (name, event = {}, result = {}) => handlers.get(name)(host, event, async () => result);
319
+ await invoke("session.start", { cwd: home, isInteractive: true });
320
+ const upstream = { blocks: [{ name: "other", text: "keep me" }, { name: "notesoup:boot", text: copied }], sentinel: "kept" };
321
+ const current = await invoke("prompt.context", {}, upstream);
322
+ assert.equal(current.sentinel, "kept");
323
+ assert.deepEqual(current.blocks[0], upstream.blocks[0]);
324
+ assert.equal(current.blocks.length, 2, "replace the copied context block rather than adding another");
325
+ assert.match(current.blocks[1].text, /Current context window id: claude:hook-session:3/);
326
+ assert.doesNotMatch(current.blocks[1].text, /claude:parent-session/);
327
+ assert.deepEqual(await invoke("prompt.context", {}, current), current, "reuse the now-current block on reload");
328
+ const compacted = await invoke("session.compact", { trigger: "auto", messages: [] });
329
+ assert.match(compacted.messages[0].text, /Current context window id: claude:hook-session:4/);
330
+ });
310
331
  test("Claude Mod with NOTESOUP_DISABLED registers nothing and passes every event through", async (t) => {
311
332
  const home = mkdtempSync(join(tmpdir(), "claude-hook-disabled-"));
312
333
  t.after(() => rmSync(home, { recursive: true, force: true }));
@@ -17,8 +17,8 @@ Your notes don't go anywhere — no wipe reaches the shelves. History has it too
17
17
  What lives only in this brain leaves with it.
18
18
  A decent moment to put down where you are, while you still remember why.
19
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:
20
+ const GOLDEN_WARNING = `This brain is spent — and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left of this brain to put down what the next window can't get back:
22
22
  - what you're in the middle of, and how far it has progressed
23
23
  - decisions the human has made, in their words
24
24
  - what is blocked or pending
@@ -27,8 +27,7 @@ Use the last of this brain to put down what the next window can't get back:
27
27
  - what failed, and why
28
28
  - skills to re-read, and history seqs, notes, or files to consult
29
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.`;
30
+ Then leave the shelf current: replace what's stale — a whole note or a section inside one — and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.`;
32
31
  const GOLDEN_COUNTDOWN = "Brain emptied in 3… 2…";
33
32
  /**
34
33
  * The approved reset handoffs. Each line is one complete paragraph used verbatim: no fragment
@@ -22,9 +22,9 @@ The notes tools also serve subagent calls, using the same session identity and s
22
22
 
23
23
  The active head comes from the main loop's successful `session.append` result UUID, including attachments and notices. On startup/resume, before such an append, the public API supplies no authoritative selected leaf: history explicitly refuses instead of assuming the last file row or `last-prompt.leafUuid` is current. The append result means the engine kept a row, but its disk write may lag; a head missing on disk is a retryable refusal, not permission to switch branches. Session end clears the binding; a new classic start rebinds it.
24
24
 
25
- Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed. Record types other than user, assistant, system and attachment are ignored, including future metadata, without allocating addresses or exposing payloads. If the selected branch requires a skipped record as an ancestor, history refuses with the missing ancestor UUID. Invalid supported message/block schemas and malformed committed JSONL lines still refuse explicitly. An incomplete final unterminated write is tolerated. Valid forward parent references are resolved after reading the snapshot, without reallocating addresses.
25
+ Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. List pages skip empty user/assistant envelopes even with explicit roles, so tool-only and thinking-only rows do not crowd out dialogue; direct reads preserve those addresses and explicitly say when no visible text was recorded. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed. Record types other than user, assistant, system and attachment are ignored, including future metadata, without allocating addresses or exposing payloads. If the selected branch requires a skipped record as an ancestor, history refuses with the missing ancestor UUID. Invalid supported message/block schemas and malformed committed JSONL lines still refuse explicitly. An incomplete final unterminated write is tolerated. Valid forward parent references are resolved after reading the snapshot, without reallocating addresses.
26
26
 
27
- The selected tree follows the latest native `parentUuid` links. Compact boundaries also join their `logicalParentUuid` and recorded preserved segments through original ancestry, retaining old events instead of presenting only retained inference context. Auxiliary preservation UUIDs that were never persisted are skipped. Windows use `claude:<sessionId>:<ordinal>`, matching the boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window. `@previous` resolves through this oldest-first window list. A missing required ancestor is an explicit refusal.
27
+ The selected tree follows the latest native `parentUuid` links. Compact boundaries also join their `logicalParentUuid` and recorded preserved segments through original ancestry, retaining old events instead of presenting only retained inference context. Auxiliary preservation UUIDs that were never persisted are skipped. Windows use `claude:<sessionId>:<ordinal>`, matching the current boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. A fork preserves the copied boot's ordinal but uses its own session id for public window ids. Copied prompt-context boot blocks are rebuilt with a fresh notes snapshot and the current session identity; historical boot messages in the transcript remain unchanged. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window. `@previous` resolves through this oldest-first window list. A missing required ancestor is an explicit refusal.
28
28
 
29
29
  ## Validation
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.52.1",
3
+ "version": "0.52.3",
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.1",
3
+ "version": "0.52.3",
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",
@@ -9412,7 +9412,7 @@ function prepareSelection(projection, params) {
9412
9412
  run.push(event);
9413
9413
  continue;
9414
9414
  }
9415
- if (folds && eventDocument(event) === "") continue;
9415
+ if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
9416
9416
  const matchOffset = params.query === void 0 ? void 0 : earliestMatchOffsetChars(eventDocument(event), params.query);
9417
9417
  if (matchOffset !== void 0 && matchOffset < 0) continue;
9418
9418
  candidates.push({ event, matchOffset, before: foldedRun(run) });
@@ -9535,7 +9535,7 @@ function renderRead(data) {
9535
9535
  const tool = toolHeader(data);
9536
9536
  const afterSeq = data.seq - 10;
9537
9537
  const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...afterSeq >= 1 ? { after_seq: afterSeq } : {}, before_seq: data.seq + 10 })})`;
9538
- return [header(data), ...tool ? [tool] : [], neighborhood, "", renderTextWindow(data)].join("\n");
9538
+ return [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
9539
9539
  }
9540
9540
  function pageFits(page) {
9541
9541
  return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
@@ -9747,13 +9747,12 @@ function decode(row, seq) {
9747
9747
  var BOOT_IDENTITY = /^<(?:notesoup:window_identity|context_window)>\nAgent name: claude \(/;
9748
9748
  var BOOT_PROTOCOL_OPEN = /\n<(?:notesoup:notes_protocol|context_window_protocol)>\n/;
9749
9749
  var BOOT_PROTOCOL_CLOSE = /\n<\/(?:notesoup:notes_protocol|context_window_protocol)>/;
9750
- function bootOrdinal(row, sessionId, retained) {
9750
+ function bootOrdinal(row, retained) {
9751
9751
  if (!retained || row.type !== "user" || !object(row.message)) return void 0;
9752
9752
  const text = contentText(row.message.content);
9753
9753
  if (!BOOT_IDENTITY.test(text) || !BOOT_PROTOCOL_OPEN.test(text) || !BOOT_PROTOCOL_CLOSE.test(text)) return void 0;
9754
- const prefix = `Current context window id: claude:${sessionId}:`;
9755
- const suffix = text.split("\n").find((line) => line.startsWith(prefix))?.slice(prefix.length);
9756
- if (suffix === void 0 || !/^\d+$/.test(suffix)) return void 0;
9754
+ const suffix = /^Current context window id: claude:[^\n]+:(\d+)$/m.exec(text)?.[1];
9755
+ if (suffix === void 0) return void 0;
9757
9756
  const ordinal = Number(suffix);
9758
9757
  return Number.isSafeInteger(ordinal) ? ordinal : void 0;
9759
9758
  }
@@ -9795,7 +9794,7 @@ function claudeHistoryFromJsonl(text, source) {
9795
9794
  let before = cursor.ordinal ?? 0;
9796
9795
  for (const current of chain.reverse()) {
9797
9796
  const retained = current.row.isCompactSummary === true || current.ancestor !== void 0 && boundary(current.ancestor.row);
9798
- const marked = bootOrdinal(current.row, source.sessionId, retained);
9797
+ const marked = bootOrdinal(current.row, retained);
9799
9798
  current.ordinal = marked === void 0 ? before + (boundary(current.row) ? 1 : 0) : Math.max(before, marked);
9800
9799
  before = current.ordinal;
9801
9800
  }
@@ -10078,7 +10077,7 @@ function selectContinuation(origin) {
10078
10077
  const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
10079
10078
  return pool[Math.floor(Math.random() * pool.length)];
10080
10079
  }
10081
- 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.";
10080
+ var WARNING_BODY = "This brain is spent \u2014 and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left 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\nThen leave the shelf current: replace what's stale \u2014 a whole note or a section inside one \u2014 and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.";
10082
10081
  var COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
10083
10082
 
10084
10083
  // plugins/claude/src/text.ts
@@ -469,7 +469,11 @@ export function register(on: On) {
469
469
  // The reset already retained its boot as the sole conversation message.
470
470
  // Prompt context still recomputes, but must not inject a duplicate snapshot.
471
471
  const retained = state.retainedBoot !== undefined
472
- let blocks = retained ? result.blocks.filter((block) => block.name !== "notesoup:boot") : [...result.blocks]
472
+ let blocks = result.blocks.filter((block) => {
473
+ if (block.name !== "notesoup:boot" || !identity) return true
474
+ const marker = bootWindow(block.text)
475
+ return !retained && (!marker || (marker.sessionId === identity.sessionId && marker.window === state.window))
476
+ })
473
477
  if (!retained && !blocks.some((block) => block.name === "notesoup:boot") && identity) {
474
478
  const texts = await loadTexts($, state)
475
479
  const boot = await buildBoot($, identity, state.window, texts, state.history)
@@ -532,22 +536,23 @@ async function withWarning<T extends { context?: readonly string[]; drop?: strin
532
536
  /** The boot's identity line; `context_window` is the pre-rename tag still in old transcripts. */
533
537
  const BOOT_IDENTITY = /<(?:notesoup:window_identity|context_window)>\nAgent name: claude /
534
538
 
535
- /**
536
- * A retained boot carries the window ordinal in a trailing id line. Old and new tag spellings
537
- * both count: a transcript written before the rename must not lose its window numbering.
538
- */
539
+ /** Old and new tag spellings, including a boot copied into a fork. */
540
+ function bootWindow(text: string): { sessionId: string; window: number } | undefined {
541
+ if (!BOOT_IDENTITY.test(text)) return undefined
542
+ const marker = /^Current context window id: claude:([^\n]+):(\d+)$/m.exec(text)
543
+ if (!marker) return undefined
544
+ const window = Number(marker[2])
545
+ return Number.isSafeInteger(window) ? { sessionId: marker[1]!, window } : undefined
546
+ }
547
+ /** Keep the copied boot ordinal, but rebuild its snapshot and identity for the new session. */
539
548
  function restoreWindow(state: ResetState, messages: readonly { role: string; text: string }[]) {
540
549
  if (!state.identity) return
541
- const prefix = `Current context window id: claude:${state.identity.sessionId}:`
542
550
  for (const message of messages) {
543
- if (message.role !== "user" || !BOOT_IDENTITY.test(message.text)) continue
544
- const line = message.text.split("\n").find((value) => value.startsWith(prefix))
545
- if (!line) continue
546
- const suffix = line.slice(prefix.length)
547
- const window = Number(suffix)
548
- if (!/^\d+$/.test(suffix) || !Number.isSafeInteger(window) || window <= state.window) continue
549
- state.window = window
550
- state.retainedBoot = message.text
551
+ if (message.role !== "user") continue
552
+ const marker = bootWindow(message.text)
553
+ if (!marker || marker.window <= state.window) continue
554
+ state.window = marker.window
555
+ state.retainedBoot = marker.sessionId === state.identity.sessionId ? message.text : undefined
551
556
  }
552
557
  }
553
558
 
@@ -99,13 +99,14 @@ const BOOT_PROTOCOL_OPEN = /\n<(?:notesoup:notes_protocol|context_window_protoco
99
99
  const BOOT_PROTOCOL_CLOSE = /\n<\/(?:notesoup:notes_protocol|context_window_protocol)>/;
100
100
 
101
101
  /** Match the complete retained notesoup boot, not a casually quoted window-id line. */
102
- function bootOrdinal(row: Row, sessionId: string, retained: boolean): number | undefined {
102
+ function bootOrdinal(row: Row, retained: boolean): number | undefined {
103
103
  if (!retained || row.type !== "user" || !object(row.message)) return undefined;
104
104
  const text = contentText(row.message.content);
105
105
  if (!BOOT_IDENTITY.test(text) || !BOOT_PROTOCOL_OPEN.test(text) || !BOOT_PROTOCOL_CLOSE.test(text)) return undefined;
106
- const prefix = `Current context window id: claude:${sessionId}:`;
107
- const suffix = text.split("\n").find((line) => line.startsWith(prefix))?.slice(prefix.length);
108
- if (suffix === undefined || !/^\d+$/.test(suffix)) return undefined;
106
+ // A fork copies the retained boot verbatim. Its ordinal survives, while
107
+ // public window ids below always belong to the current transcript session.
108
+ const suffix = /^Current context window id: claude:[^\n]+:(\d+)$/m.exec(text)?.[1];
109
+ if (suffix === undefined) return undefined;
109
110
  const ordinal = Number(suffix);
110
111
  return Number.isSafeInteger(ordinal) ? ordinal : undefined;
111
112
  }
@@ -158,7 +159,7 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
158
159
  let before = cursor.ordinal ?? 0;
159
160
  for (const current of chain.reverse()) {
160
161
  const retained = current.row.isCompactSummary === true || (current.ancestor !== undefined && boundary(current.ancestor.row));
161
- const marked = bootOrdinal(current.row, source.sessionId, retained);
162
+ const marked = bootOrdinal(current.row, retained);
162
163
  current.ordinal = marked === undefined ? before + (boundary(current.row) ? 1 : 0) : Math.max(before, marked);
163
164
  before = current.ordinal;
164
165
  }
@@ -33,7 +33,7 @@ export function selectContinuation(origin: ResetOrigin): string {
33
33
  * instruction differs — Pi can reset the model itself, Claude can only end the turn.
34
34
  */
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
+ "This brain is spent — and the wipe isn't on a timer: it lands at the end of whatever turn spends the last reserve, which may be this turn. 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 what's left 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\nThen leave the shelf current: replace what's stale — a whole note or a section inside one — and crumple notes that are dead, starting with the MAP files every new window loads. The next window gets whatever you leave, dead notes and dead sections alike.";
37
37
 
38
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.";
39
39
 
@@ -108,7 +108,8 @@ function prepareSelection(projection: HistoryProjection, params: HistorySelectio
108
108
  run.push(event);
109
109
  continue;
110
110
  }
111
- if (folds && eventDocument(event) === "") continue;
111
+ // Tool/thinking-only envelopes are not dialogue, even with explicit roles.
112
+ if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
112
113
  const matchOffset = params.query === undefined ? undefined : earliestMatchOffsetChars(eventDocument(event), params.query as string[]);
113
114
  if (matchOffset !== undefined && matchOffset < 0) continue;
114
115
  candidates.push({ event, matchOffset, before: foldedRun(run) });
@@ -75,7 +75,7 @@ function renderRead(data: HistoryReadData): string {
75
75
  const tool = toolHeader(data);
76
76
  const afterSeq = data.seq - 10;
77
77
  const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
78
- return [header(data), ...(tool ? [tool] : []), neighborhood, "", renderTextWindow(data)].join("\n");
78
+ return [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
79
79
  }
80
80
 
81
81
  /* ------------------------------------------------------------------ shared bounding */
@@ -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 {