notesoup 0.54.2 → 0.55.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 (70) hide show
  1. package/dist/plugins/pi/budget.js +1 -1
  2. package/dist/plugins/pi/marker.d.ts +1 -1
  3. package/dist/plugins/pi/marker.js +11 -7
  4. package/dist/plugins/pi/notes/tools.js +5 -1
  5. package/dist/plugins/pi/render.d.ts +4 -1
  6. package/dist/plugins/pi/render.js +3 -7
  7. package/dist/plugins/pi/runtime.js +5 -5
  8. package/dist/plugins/pi/tool-result.d.ts +4 -2
  9. package/dist/plugins/pi/tool-result.js +5 -4
  10. package/dist/src/history/claude.d.ts +1 -1
  11. package/dist/src/history/claude.js +11 -6
  12. package/dist/src/history/codex-transcript.d.ts +2 -0
  13. package/dist/src/history/codex-transcript.js +3 -2
  14. package/dist/src/history/corpus.d.ts +2 -1
  15. package/dist/src/history/corpus.js +5 -2
  16. package/dist/src/history/history.d.ts +1 -1
  17. package/dist/src/history/history.js +1 -1
  18. package/dist/src/history/local.d.ts +2 -6
  19. package/dist/src/history/local.js +34 -2
  20. package/dist/src/history/query.d.ts +4 -2
  21. package/dist/src/history/query.js +17 -8
  22. package/dist/src/tools/history.js +17 -13
  23. package/dist/src/tools/notes.d.ts +2 -7
  24. package/dist/src/tools/notes.js +5 -26
  25. package/dist/test/boot.integration.test.js +24 -0
  26. package/dist/test/budget-settings.integration.test.js +2 -2
  27. package/dist/test/claude-history.test.js +4 -6
  28. package/dist/test/codex-history.test.js +3 -2
  29. package/dist/test/dependencies.test.js +3 -4
  30. package/dist/test/dream-tools.test.js +3 -3
  31. package/dist/test/history-corpus.test.js +238 -14
  32. package/dist/test/history.integration.test.js +9 -9
  33. package/dist/test/host-neutral.test.js +7 -9
  34. package/dist/test/marker.test.js +34 -27
  35. package/dist/test/notes.integration.test.js +8 -10
  36. package/dist/test/notes.test.js +9 -7
  37. package/dist/test/pi-render.test.js +7 -7
  38. package/dist/test/project-namespace.test.js +4 -4
  39. package/docs/claude-code-mod.md +1 -1
  40. package/docs/history-sessions.md +9 -7
  41. package/docs/skills.md +1 -1
  42. package/docs/tool-results.md +3 -3
  43. package/package.json +1 -1
  44. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  45. package/plugins/claude/dist/claude/helper.js +68 -47
  46. package/plugins/claude/skills/memory/SKILL.md +4 -2
  47. package/plugins/codex/dist/codex/notesoup.js +68 -47
  48. package/plugins/paseo/OVERVIEW.md +2 -2
  49. package/plugins/paseo/client/brain-empty-card.tsx +1 -1
  50. package/plugins/paseo/client/notes-op-card.tsx +1 -1
  51. package/plugins/paseo/client/notes-op-transformer.ts +16 -1
  52. package/plugins/paseo/client/paper-palette.ts +18 -18
  53. package/plugins/paseo/test/fixtures/claude-tool-calls.ts +1 -1
  54. package/plugins/paseo/test/notes-op.test.ts +4 -4
  55. package/plugins/paseo/test/paper-palette.test.ts +3 -3
  56. package/plugins/pi/budget.ts +1 -1
  57. package/plugins/pi/marker.ts +11 -6
  58. package/plugins/pi/notes/tools.ts +5 -1
  59. package/plugins/pi/render.ts +7 -8
  60. package/plugins/pi/runtime.ts +4 -3
  61. package/plugins/pi/tool-result.ts +10 -9
  62. package/skills/memory/SKILL.md +4 -2
  63. package/src/history/claude.ts +9 -4
  64. package/src/history/codex-transcript.ts +3 -2
  65. package/src/history/corpus.ts +9 -3
  66. package/src/history/history.ts +1 -1
  67. package/src/history/local.ts +36 -4
  68. package/src/history/query.ts +17 -6
  69. package/src/tools/history.ts +13 -12
  70. package/src/tools/notes.ts +5 -27
@@ -140,7 +140,6 @@ export const NotesWriteDataSchema = Type.Object({
140
140
  export const NotesUpdateDataSchema = Type.Object({
141
141
  ...NoteIdentitySchema,
142
142
  change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
143
- diff: Type.String(),
144
143
  rename_from: Type.Optional(Type.String()),
145
144
  }, { additionalProperties: false });
146
145
  export const NotesReadDataSchema = Type.Object({
@@ -212,51 +211,31 @@ export const notesUpdateParameters = Type.Object({
212
211
  cwd: CWD_PARAMETER,
213
212
  }, { additionalProperties: false });
214
213
  function renderUpdateData(data) {
215
- const head = data.rename_from === undefined
214
+ return data.rename_from === undefined
216
215
  ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}`
217
216
  : `moved ${data.rename_from} -> ${data.address}`;
218
- const lines = [head];
219
- if (data.diff.length > 0)
220
- lines.push("diff:", data.diff);
221
- return lines.join("\n");
222
- }
223
- function renderUpdate(result) {
224
- return renderOutcome(result, renderUpdateData);
225
- }
226
- /** A shortened diff still says so in the receipt's own text, on both surfaces. */
227
- export const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
228
- const RECEIPT_TOO_LONG = `Saved, but the receipt is too long to hand back (${TOOL_OUTPUT_LIMIT} per call). Check the note with \`notes_read\`.`;
229
- /** Bound a mutation receipt on both surfaces; a huge diff is cut to the longest fitting prefix and marked. */
230
- function boundedUpdate(data) {
231
- if (fitsResult(success(data), renderUpdate))
232
- return success(data);
233
- if (data.diff === "")
234
- return failure("output_too_large", RECEIPT_TOO_LONG);
235
- const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}\n${DIFF_SHORTENED_MARKER}` }), renderUpdate));
236
- const result = success({ ...data, diff: `${diff}\n${DIFF_SHORTENED_MARKER}` });
237
- return fitsResult(result, renderUpdate) ? result : failure("output_too_large", RECEIPT_TOO_LONG);
238
217
  }
239
218
  export const notesUpdate = {
240
219
  name: "notes_update", label: "Notes update",
241
220
  description: `Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
242
221
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
243
- async execute(params, context, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
222
+ async execute(params, context, onChange) {
244
223
  try {
245
224
  const identity = notesIdentityForCall(context, params.cwd);
246
225
  const store = createNotesStore(identity);
247
226
  // Empty filler is not a request: models that pass every parameter get the edit path.
248
227
  const renameTo = params.rename_to === "" ? undefined : params.rename_to;
249
228
  const { change, moved } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
229
+ onChange?.(change);
250
230
  const from = noteIdentity(identity, params.address).address;
251
231
  const to = noteIdentity(identity, renameTo ?? params.address);
252
- const diff = renderDiff(change);
253
- return boundedUpdate({ ...to, ...(moved ? { rename_from: from } : {}), change_kind: moved ? "moved" : change.kind, diff: moved ? [`rename ${from} -> ${to.address}`, diff].filter(Boolean).join("\n") : diff });
232
+ return success({ ...to, ...(moved ? { rename_from: from } : {}), change_kind: moved ? "moved" : change.kind });
254
233
  }
255
234
  catch (error) {
256
235
  return failureOf(error);
257
236
  }
258
237
  },
259
- render: renderUpdate,
238
+ render: (result) => renderOutcome(result, renderUpdateData),
260
239
  };
261
240
  export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
262
241
  function renderReadData(data) {
@@ -51,6 +51,30 @@ test("custom reset marker removes old provider context while history remains sea
51
51
  assert.equal(found.items.length, 1);
52
52
  assert.equal(found.items[0]?.seq, oldSeq);
53
53
  });
54
+ test("a checkpoint-backed reset projects from its boot and drops the empty compaction wrapper", async () => {
55
+ const sessionManager = manager();
56
+ const captured = makeExtension(sessionManager);
57
+ const ctx = context(sessionManager);
58
+ appendText(sessionManager, "user", "before the reset");
59
+ await call(captured, "empty_brain", {}, ctx);
60
+ assert.equal((await commitTurnEndBoundary(captured, sessionManager, ctx)).continue, true);
61
+ // Pi projects the empty retain-none checkpoint into a compactionSummary that precedes the boot.
62
+ const sessionMessages = sessionManager.buildSessionProjection().messages;
63
+ const wrapperIndex = sessionMessages.findIndex((message) => message.role === "compactionSummary");
64
+ const bootIndex = sessionMessages.findIndex((message) => message.role === "custom" && message.customType === BOOT_TYPE);
65
+ assert.ok(wrapperIndex >= 0 && wrapperIndex < bootIndex, "the empty wrapper sits before the boot");
66
+ const projected = await runContextWithSystemHook(captured, ctx, [
67
+ { role: "system", content: "SYSTEM HEAD", timestamp: 0 },
68
+ ...sessionMessages,
69
+ ]);
70
+ const messages = (projected?.messages ?? []);
71
+ assert.equal(messages[0]?.role, "system", "the leading system message survives");
72
+ assert.equal(messages[0]?.role === "system" ? messages[0].content : undefined, "SYSTEM HEAD");
73
+ const first = messages[1];
74
+ assert.ok(first?.role === "custom", "the window starts at its boot");
75
+ assert.equal(first.customType, BOOT_TYPE);
76
+ assert.equal(messages.some((message) => message.role === "compactionSummary"), false, "the empty checkpoint wrapper never reaches the provider");
77
+ });
54
78
  test("the root boot and reset boot carry durable window identity", async () => {
55
79
  const sessionManager = manager();
56
80
  const captured = makeExtension(sessionManager);
@@ -108,12 +108,12 @@ test("early guidance stays silent and the final warning notifies immediately onc
108
108
  const final = context(sm, undefined, { tokens: 181_000, percent: 90.5, contextWindow: 200_000 });
109
109
  const warning = await runContextHook(captured, final);
110
110
  assert.equal(warning?.messages[0]?.customType, WARNING_TYPE);
111
- assert.equal(noticesOf(final).filter((notice) => notice.message === "🄣 Brain almost full · taking notes").length, 1, "notify at injection, before any turn_end");
111
+ assert.equal(noticesOf(final).filter((notice) => notice.message === "🄣 Brain almost full").length, 1, "notify at injection, before any turn_end");
112
112
  await runContextHook(captured, final);
113
113
  await commitTurnEndBoundary(captured, sm, final);
114
114
  await runHandlers(captured, "turn_start", {}, final);
115
115
  await runHandlers(captured, "agent_settled", {}, final);
116
- assert.equal(noticesOf(final).filter((notice) => notice.message === "🄣 Brain almost full · taking notes").length, 1, "repeated injection and commit do not notify again");
116
+ assert.equal(noticesOf(final).filter((notice) => notice.message === "🄣 Brain almost full").length, 1, "repeated injection and commit do not notify again");
117
117
  });
118
118
  test("the reported room ends at the hard reserve, clamps at zero, and preserves unknown usage", async () => {
119
119
  const fixture = settingsFixture({
@@ -66,9 +66,8 @@ test("Claude append and result arrival preserve call addresses and use the share
66
66
  assert.doesNotMatch(read.data.text, /hidden/);
67
67
  assert.equal(allItems(completed).find((event) => event.seq === 4)?.execution?.status, "error");
68
68
  const resultRead = await historyRead.execute({ seq: 7 }, completed);
69
- assert.ok(!resultRead.ok);
70
- assert.equal(resultRead.error.code, "not_an_event");
71
- assert.match(resultRead.error.message, /read seq 3/);
69
+ assert.ok(resultRead.ok);
70
+ assert.equal(resultRead.data.seq, 3);
72
71
  const search = await historyList.execute({ query: "output one" }, completed);
73
72
  assert.ok(search.ok);
74
73
  assert.deepEqual(search.data.items.map((item) => "seq" in item ? item.seq : -1), [3]);
@@ -349,9 +348,8 @@ test("Claude gap windows sort by confirmed ordinal despite forward references, w
349
348
  assert.deepEqual(allItems(projection).filter((event) => event.role === "tool").map((event) => [event.seq, event.text]), [[4, "output"]]);
350
349
  assert.equal(projection.pairedResults.get(8), 4);
351
350
  const alias = await historyRead.execute({ seq: 8 }, projection);
352
- assert.ok(!alias.ok);
353
- assert.equal(alias.error.code, "not_an_event");
354
- assert.match(alias.error.message, /read seq 4/);
351
+ assert.ok(alias.ok);
352
+ assert.equal(alias.data.seq, 4);
355
353
  });
356
354
  test("Claude gap notices participate in list/read budgets without changing read coordinates", async (t) => {
357
355
  const root = mkdtempSync(join(tmpdir(), "claude-history-budget-"));
@@ -93,8 +93,9 @@ test("root: raw messages, top-level envelope metadata, native tool pairing and n
93
93
  assert.equal(tool.data.output_truncated, undefined);
94
94
  assert.equal(tool.data.nested_calls, undefined);
95
95
  const paired = await historyRead.execute({ seq: 9 }, projection);
96
- assert.equal(paired.ok, false);
97
- assert.match(historyRead.render(paired), /read seq 7 instead/);
96
+ assert.equal(paired.ok, true);
97
+ if (paired.ok)
98
+ assert.equal(paired.data.seq, 7);
98
99
  const omitted = await historyRead.execute({ seq: 6 }, projection);
99
100
  assert.match(historyRead.render(omitted), /holds nothing/);
100
101
  const page = await historyList.execute({ query: "printf output" }, projection);
@@ -46,10 +46,9 @@ test("the host-neutral core resolves without any SDK or plugin dependency", () =
46
46
  const sharedRuntime = new Set(["typebox"]);
47
47
  assert.deepEqual(dependencyViolations(root, shared, parsed.options, sharedRuntime), []);
48
48
  for (const name of sharedRuntime) {
49
- assert.equal(typeof manifest.dependencies?.[name], "string", `${name} is a declared runtime dependency`);
50
- assert.equal(manifest.devDependencies?.[name], undefined, `${name} is not a development-only dependency`);
51
- assert.equal(manifest.peerDependencies?.[name], undefined, `${name} is not a host-supplied peer`);
52
- assert.equal(manifest.peerDependenciesMeta?.[name], undefined, `${name} has no peer metadata`);
49
+ assert.equal(manifest.dependencies?.[name], undefined, `${name} is supplied by the host`);
50
+ assert.equal(manifest.peerDependencies?.[name], "*", `${name} is a host-supplied peer dependency`);
51
+ assert.equal(typeof manifest.devDependencies?.[name], "string", `${name} is pinned in devDependencies`);
53
52
  }
54
53
  for (const name of ["@earendil-works/pi-agent-core", "@earendil-works/pi-ai", "@earendil-works/pi-coding-agent"]) {
55
54
  assert.equal(manifest.dependencies?.[name], undefined, `${name} is supplied by the host`);
@@ -46,7 +46,7 @@ test("a dream opens one other project, writes its notes, deletes only crumpled o
46
46
  assert.ok(existsSync(join(home, ".dream.lock")), "the notes-home lock is held");
47
47
  assert.equal((await dreamBegin.execute({ project: "beta" }, as("other", "alpha"), {})).ok, false, "another session can't dream the same project");
48
48
  assert.ok((await notesWrite.execute({ address: "@projects/beta/rule", content: "merged" }, ident())).ok);
49
- assert.ok((await notesUpdate.execute({ address: "@sessions/b1/checkpoint", edits: [{ oldText: "old", newText: "new" }] }, ident(), () => "")).ok);
49
+ assert.ok((await notesUpdate.execute({ address: "@sessions/b1/checkpoint", edits: [{ oldText: "old", newText: "new" }] }, ident())).ok);
50
50
  assert.equal((await notesWrite.execute({ address: "@sessions/a1/mine", content: "x" }, ident())).ok, false, "another project's session stays read-only");
51
51
  assert.equal((await notesWrite.execute({ address: "@projects/alpha/x", content: "x" }, ident())).ok, false, "other projects stay read-only");
52
52
  const read = await notesRead.execute({ address: "@human/none" }, ident());
@@ -188,12 +188,12 @@ test("named-project mutation receipts carry their project metadata and fit their
188
188
  assert.equal(written.data.project_root, "/work/two/beta");
189
189
  assert.deepEqual(written.data.project_siblings, [{ name: "beta", path: "/work/beta" }]);
190
190
  assert.equal(Check(notesWrite.outputSchema, written.data), true, "notes_write accepts its own named-project receipt");
191
- const updated = await notesUpdate.execute({ address: "@projects/beta-1/rule", edits: [{ oldText: "merged", newText: "done" }] }, ident(), () => "");
191
+ const updated = await notesUpdate.execute({ address: "@projects/beta-1/rule", edits: [{ oldText: "merged", newText: "done" }] }, ident());
192
192
  assert.ok(updated.ok);
193
193
  assert.equal(updated.data.project_root, "/work/two/beta");
194
194
  assert.deepEqual(updated.data.project_siblings, [{ name: "beta", path: "/work/beta" }]);
195
195
  assert.equal(Check(notesUpdate.outputSchema, updated.data), true, "notes_update accepts its own named-project receipt");
196
- assert.ok((await notesUpdate.execute({ address: "@projects/beta-1/rule", crumpled: true }, ident(), () => "")).ok);
196
+ assert.ok((await notesUpdate.execute({ address: "@projects/beta-1/rule", crumpled: true }, ident())).ok);
197
197
  const forgotten = await dreamForget.execute({ address: "@projects/beta-1/rule" }, me, state);
198
198
  assert.ok(forgotten.ok);
199
199
  assert.equal(forgotten.data.project_root, "/work/two/beta");
@@ -8,7 +8,7 @@ import { Check } from "typebox/value";
8
8
  import { localHistoryCorpus } from "../src/history/local.js";
9
9
  import { parseSessionSelector } from "../src/history/corpus.js";
10
10
  import { allItems, projectHistory } from "../src/history/history.js";
11
- import { offlineClaudeHead } from "../src/history/claude.js";
11
+ import { claudeHistoryFromJsonl, offlineClaudeHead } from "../src/history/claude.js";
12
12
  import { piHistoryFromJsonl } from "../src/history/pi.js";
13
13
  import { historyList, historyRead } from "../src/tools/history.js";
14
14
  import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
@@ -131,11 +131,12 @@ test("all single-session recipes preserve the resolved identity, including folde
131
131
  });
132
132
  test("wildcard refusals precede discovery, and read accepts no wildcard selector", async () => {
133
133
  const ctx = { current: () => { throw new Error("must not load current"); }, corpus: { currentHarness: "pi", sessions: async () => { throw new Error("must not discover"); } } };
134
- for (const query of [undefined, "", [], ["", ""]]) {
135
- refusal(await historyList.execute({ session: "*", query }, ctx), "missing_query");
136
- }
137
- for (const bounds of [{ before_seq: 10 }, { after_seq: 1 }, { before_seq: 10, after_seq: 1 }]) {
138
- refusal(await historyList.execute({ session: "*", query: "needle", ...bounds }, ctx), "invalid_bounds");
134
+ for (const session of ["*", "pi:*", "pre*fix"]) {
135
+ for (const query of [undefined, "", [], ["", ""], "needle"]) {
136
+ for (const bounds of [{ before_seq: 10 }, { after_seq: 1 }, { before_seq: 10, after_seq: 1 }]) {
137
+ refusal(await historyList.execute({ session, query, ...bounds }, ctx), "invalid_bounds");
138
+ }
139
+ }
139
140
  }
140
141
  for (const session of ["*", "pi:*", "cl*", "dsh:pre*suffix"]) {
141
142
  refusal(await historyRead.execute({ session, seq: 1 }, ctx), "invalid_session");
@@ -158,7 +159,7 @@ test("native filesystem discovery decodes three harnesses, compressed Codex, and
158
159
  const tool = data(await historyRead.execute({ session: "pi:pi-one", seq: 3 }, f.ctx));
159
160
  assert.equal(tool.tool, "read");
160
161
  assert.match(tool.text, /needle\.md.*\n--- output ---\nneedle tool output/);
161
- refusal(await historyRead.execute({ session: "pi:pi-one", seq: 4 }, f.ctx), "not_an_event");
162
+ assert.equal(data(await historyRead.execute({ session: "pi:pi-one", seq: 4 }, f.ctx)).seq, 3);
162
163
  for (let index = 0; index < paths.length; index++) {
163
164
  assert.deepEqual(await readFile(paths[index]), before[index].bytes);
164
165
  assert.equal((await stat(paths[index])).mtimeMs, before[index].time);
@@ -185,6 +186,103 @@ test("wildcard query merges every role chronologically, limits from either end,
185
186
  assert.ok(Check(historyList.outputSchema, page));
186
187
  assert.match(historyList.render(result), /session pi:pi-one \| seq 1 \| user/);
187
188
  });
189
+ test("query-less wildcards browse recent sessions, normalize empty queries, and keep canonical IDs", async (t) => {
190
+ const { ctx } = await fixture(t);
191
+ for (const query of [undefined, "", [], ["", ""]]) {
192
+ const result = await historyList.execute({ session: "*", query }, ctx);
193
+ const page = data(result);
194
+ assert.deepEqual(page.items.map((item) => "seq" in item ? [item.session, item.seq, item.role] : null), [
195
+ ["pi:pi-one", 1, "user"], ["claude:claude-one", 1, "user"], ["pi:current", 1, "user"], [`codex:${CODEX}`, 2, "assistant"],
196
+ ]);
197
+ assert.equal(page.page_older, null);
198
+ assert.equal(page.page_newer, null);
199
+ assert.ok(Check(historyList.outputSchema, page));
200
+ }
201
+ const harness = data(await historyList.execute({ session: "claude:*" }, ctx));
202
+ assert.deepEqual(harness.items.map((item) => item.session), ["claude:claude-one"]);
203
+ assert.equal(data(await historyList.execute({ session: "pi:absent*" }, ctx)).items.length, 0);
204
+ });
205
+ test("session overviews order discovery by mtime, stop at the session limit, then sort representatives by event time", async () => {
206
+ const loaded = [];
207
+ const sessions = Array.from({ length: 25 }, (_, index) => {
208
+ const createdAt = new Date(Date.parse(AT) + (25 - index) * 1000).toISOString();
209
+ return {
210
+ harness: "pi", id: `s-${index}`, modifiedAt: index,
211
+ async load(queries) {
212
+ assert.equal(queries, undefined);
213
+ loaded.push(index);
214
+ return { projection: projectHistory([{ windowId: "w", items: [{ seq: 1, windowId: "w", role: "user", text: `topic ${index}`, createdAt }] }], 1, new Set([1])) };
215
+ },
216
+ };
217
+ });
218
+ const ctx = context(sessions);
219
+ const recent = data(await historyList.execute({ session: "*" }, ctx));
220
+ assert.deepEqual(loaded, Array.from({ length: 20 }, (_, index) => 24 - index));
221
+ assert.deepEqual(recent.items.map((item) => item.session), loaded.map((index) => `pi:s-${index}`));
222
+ loaded.length = 0;
223
+ const oldest = data(await historyList.execute({ session: "*", from: "oldest", limit: 2 }, ctx));
224
+ assert.deepEqual(loaded, [0, 1]);
225
+ assert.deepEqual(oldest.items.map((item) => item.session), ["pi:s-1", "pi:s-0"]);
226
+ loaded.length = 0;
227
+ const pattern = data(await historyList.execute({ session: "pi:s-2*", limit: 2 }, ctx));
228
+ assert.deepEqual(loaded, [24, 23]);
229
+ assert.deepEqual(pattern.items.map((item) => item.session), ["pi:s-24", "pi:s-23"]);
230
+ });
231
+ test("session representatives respect visibility, role/time filters, opening users and dialogue/any fallbacks", async () => {
232
+ const at = (seconds) => new Date(Date.parse(AT) + seconds * 1000).toISOString();
233
+ const messages = [
234
+ ["system", "early context", 0], ["user", "", 0], ["user", "opening topic", 1],
235
+ ["assistant", "visible reply", 2], ["user", "later topic", 3], ["tool", "tool output", 4],
236
+ ["assistant", "", 5], ["system", "late context", 6],
237
+ ];
238
+ const p = projectHistory([{ windowId: "w", items: messages.map(([role, text, seconds], index) => ({ seq: index + 1, windowId: "w", role, text, createdAt: at(seconds) })) }], 8, new Set([1, 2, 3, 4, 5, 6, 7, 8]));
239
+ const ctx = context([descriptor("claude", "topic", p)]);
240
+ const chosen = async (params) => data(await historyList.execute({ session: "*", ...params }, ctx)).items.map((item) => "seq" in item ? item.seq : "folded");
241
+ assert.deepEqual(await chosen({}), [3]);
242
+ assert.deepEqual(await chosen({ roles: ["user"] }), [5]);
243
+ assert.deepEqual(await chosen({ roles: ["assistant"] }), [4]);
244
+ assert.deepEqual(await chosen({ roles: ["user", "assistant"] }), [5]);
245
+ assert.deepEqual(await chosen({ roles: ["context", "tool"] }), [8]);
246
+ assert.deepEqual(await chosen({ roles: ["tool"] }), [6]);
247
+ assert.deepEqual(await chosen({ roles: [] }), []);
248
+ assert.deepEqual(await chosen({ since: at(2), until: at(3) }), [4]);
249
+ assert.deepEqual(await chosen({ since: at(3) }), [5]);
250
+ assert.deepEqual(await chosen({ until: at(1) }), [1]);
251
+ assert.deepEqual(await chosen({ since: at(4) }), [8]);
252
+ assert.deepEqual(await chosen({ since: at(4), roles: ["user"] }), []);
253
+ assert.deepEqual(await chosen({ since: at(7) }), []);
254
+ const noUsers = { ...p, windows: p.windows.map((window) => ({ ...window, items: window.items.filter((item) => item.role !== "user") })) };
255
+ const fallback = data(await historyList.execute({ session: "*" }, context([descriptor("pi", "assistant-topic", noUsers)])));
256
+ assert.deepEqual(fallback.items.map((item) => "seq" in item ? item.seq : null), [4]);
257
+ });
258
+ test("empty, filtered-out and unavailable sessions do not consume overview slots", async () => {
259
+ const loaded = [];
260
+ const sessions = [
261
+ { ...descriptor("pi", "broken"), modifiedAt: 6, load: async () => { throw new Error("unreadable"); } },
262
+ { ...descriptor("pi", "empty", projectHistory([], 0, new Set())), modifiedAt: 5 },
263
+ { ...descriptor("pi", "filtered", projection("context", "system")), modifiedAt: 4 },
264
+ { ...descriptor("pi", "topic"), modifiedAt: 3 },
265
+ { ...descriptor("pi", "unneeded"), modifiedAt: 2, load: async () => { throw new Error("must not load beyond limit"); } },
266
+ ].map((session) => ({ ...session, async load() { loaded.push(session.id); return session.load(); } }));
267
+ const page = data(await historyList.execute({ session: "*", roles: ["user"], limit: 1 }, context(sessions)));
268
+ assert.deepEqual(page.items.map((item) => item.session), ["pi:topic"]);
269
+ assert.ok(loaded.includes("empty") && loaded.includes("filtered") && !loaded.includes("unneeded"));
270
+ assert.deepEqual(data(await historyList.execute({ session: "*" }, context([]))), { items: [], page_older: null, page_newer: null });
271
+ });
272
+ test("wildcard queries reach lazy loaders and pre-filtered misses are not errors", async () => {
273
+ const seen = [];
274
+ const ctx = context([
275
+ { ...descriptor("pi", "miss"), async load(queries) { seen.push(queries); return undefined; } },
276
+ { ...descriptor("pi", "broken"), async load(queries) { seen.push(queries); throw new Error("unsupported"); } },
277
+ { ...descriptor("claude", "hit"), async load(queries) { seen.push(queries); return { projection: projection("other") }; } },
278
+ ]);
279
+ const page = data(await historyList.execute({ session: "*", query: ["", "needle", "other"] }, ctx));
280
+ assert.equal(page.items.length, 5);
281
+ assert.ok(page.items.every((item) => item.session === "claude:hit"));
282
+ assert.deepEqual(seen, [["needle", "other"], ["needle", "other"], ["needle", "other"]]);
283
+ refusal(await historyList.execute({ session: "pi:miss" }, ctx), "history_unavailable");
284
+ refusal(await historyRead.execute({ session: "pi:broken", seq: 1 }, ctx), "history_unavailable");
285
+ });
188
286
  test("query offsets and text continuation retain cross-session identity and Unicode coordinates", async (t) => {
189
287
  const { ctx } = await fixture(t);
190
288
  const page = data(await historyList.execute({ session: "pi:*", query: "NEEDLE", roles: ["user"], max_chars_per_item: 3 }, ctx));
@@ -248,6 +346,12 @@ test("oversized cross-session reads/searches obey both wire budgets and retain c
248
346
  assert.ok(Buffer.byteLength(historyRead.render(read)) <= TOOL_OUTPUT_MAX_BYTES);
249
347
  assert.equal(data(read).session, "codex:long-id");
250
348
  assert.ok(data(read).next_offset_chars > 0);
349
+ const overview = await historyList.execute({ session: "*", max_chars_per_item: 50_000 }, ctx);
350
+ assert.ok(Buffer.byteLength(JSON.stringify(data(overview))) <= TOOL_OUTPUT_MAX_BYTES);
351
+ assert.ok(Buffer.byteLength(historyList.render(overview)) <= TOOL_OUTPUT_MAX_BYTES);
352
+ assert.equal(data(overview).items.length, 1);
353
+ assert.equal(data(overview).page_older, null);
354
+ assert.equal(data(overview).page_newer, null);
251
355
  });
252
356
  test("qualified lookup and current-harness matches do not inspect unrelated roots", async (t) => {
253
357
  const f = await fixture(t);
@@ -279,12 +383,121 @@ test("cross-session Claude gaps are visible even on an empty page, budgeted, and
279
383
  assert.ok(Buffer.byteLength(JSON.stringify(data(read))) <= TOOL_OUTPUT_MAX_BYTES);
280
384
  assert.ok(Buffer.byteLength(historyRead.render(read)) <= TOOL_OUTPUT_MAX_BYTES);
281
385
  });
282
- test("invalid persisted sessions refuse visibly instead of fabricating a successful partial corpus", async (t) => {
386
+ test("wildcards skip corrupt and unreadable sessions, while single-session lists and reads still refuse", async (t) => {
283
387
  const f = await fixture(t);
284
- await f.put(join(f.roots.pi, "--workspace--", "2026-10-06_broken.jsonl"), "not-json\n");
285
- const message = refusal(await historyList.execute({ session: "pi:*", query: "needle" }, f.ctx), "history_unavailable");
286
- assert.match(message, /pi:broken/);
287
- refusal(await historyRead.execute({ session: "pi:broken", seq: 1 }, f.ctx), "history_unavailable");
388
+ await f.put(join(f.roots.pi, "--workspace--", "2026-10-06_broken.jsonl"), "not-json needle\n", 100);
389
+ const sessions = await f.corpus.sessions();
390
+ await rm(f.claudePath);
391
+ const ctx = { current: () => projection(), corpus: { currentHarness: "pi", sessions: async () => sessions } };
392
+ for (const query of [undefined, "needle"]) {
393
+ const page = data(await historyList.execute({ session: "*", query }, ctx));
394
+ assert.ok(page.items.length > 0);
395
+ assert.ok(page.items.every((item) => item.session !== "pi:broken" && item.session !== "claude:claude-one"));
396
+ }
397
+ for (const session of ["pi:broken", "claude:claude-one"]) {
398
+ assert.ok(refusal(await historyList.execute({ session, query: "absent" }, ctx), "history_unavailable").includes(session));
399
+ refusal(await historyRead.execute({ session, seq: 1 }, ctx), "history_unavailable");
400
+ }
401
+ });
402
+ test("local query misses skip full decoding for Pi, Claude and compressed/uncompressed Codex", async (t) => {
403
+ const f = await fixture(t);
404
+ for (const session of (await f.corpus.sessions()).filter((session) => session.id !== "current")) {
405
+ assert.equal(await session.load(["absentword"]), undefined, session.harness);
406
+ assert.ok(await session.load(["absentword", "NEEDLE"]), session.harness);
407
+ }
408
+ await f.put(f.codexPath.replace(/\.zst$/, ""), f.codexText, 100);
409
+ const uncompressed = (await f.corpus.sessions("codex"))[0];
410
+ assert.equal(await uncompressed.load(["absentword"]), undefined);
411
+ assert.ok(await uncompressed.load(["NEEDLE"]));
412
+ await f.put(f.piPath, "not-json unrelated\n");
413
+ await f.put(f.claudePath, "not-json unrelated\n");
414
+ await f.put(f.codexPath, zstdCompressSync(Buffer.from("not-json unrelated\n")));
415
+ await f.put(f.codexPath.replace(/\.zst$/, ""), "not-json unrelated\n", 100);
416
+ for (const session of (await f.corpus.sessions()).filter((session) => session.id !== "current")) {
417
+ assert.equal(await session.load(["needle"]), undefined, session.harness);
418
+ assert.equal(await session.load(["entirelyabsent phrasewithoutmatch"]), undefined, session.harness);
419
+ await assert.rejects(() => session.load());
420
+ await assert.rejects(() => session.load([]));
421
+ await assert.rejects(() => session.load(["unrelated"]));
422
+ }
423
+ await rm(f.codexPath.replace(/\.zst$/, ""));
424
+ const compressed = (await f.corpus.sessions("codex"))[0];
425
+ assert.equal(await compressed.load(["needle"]), undefined);
426
+ await assert.rejects(() => compressed.load());
427
+ });
428
+ test("raw filtering never loses escaped JSON, Unicode or OR-query matches", async (t) => {
429
+ const f = await fixture(t);
430
+ const content = 'NEEDLE 你儽 šŸ˜€ quote"slash\\ line\nbreak İ LONGÅæ CASEĪ£';
431
+ const escapeText = (text) => text.replaceAll("NEEDLE", "\\u004e\\u0045\\u0045\\u0044\\u004c\\u0045")
432
+ .replaceAll("你儽", "\\u4f60\\u597d").replaceAll("šŸ˜€", "\\ud83d\\ude00").replaceAll("İ", "\\u0130");
433
+ await f.put(f.piPath, escapeText(rows([
434
+ { type: "session", id: "pi-one" },
435
+ { type: "message", id: "u", parentId: null, timestamp: AT, message: { role: "user", content } },
436
+ ])));
437
+ await f.put(f.claudePath, escapeText(rows([
438
+ { type: "user", uuid: "u", parentUuid: null, sessionId: "claude-one", timestamp: AT, message: { role: "user", content } },
439
+ ])));
440
+ const codexText = escapeText(f.codexText.replace("Codex needle", JSON.stringify(content).slice(1, -1)));
441
+ await f.put(f.codexPath, zstdCompressSync(Buffer.from(codexText)));
442
+ for (const query of ["needle", "你儽", "šŸ˜€", 'quote"slash\\', "line\nbreak", "İ", "longs", "caseĻ‚", ["absentword", "needle"]]) {
443
+ const page = data(await historyList.execute({ session: "*", query }, f.ctx));
444
+ assert.deepEqual(page.items.map((item) => item.session), ["claude:claude-one", "pi:pi-one", `codex:${CODEX}`], JSON.stringify(query));
445
+ }
446
+ assert.deepEqual(data(await historyList.execute({ session: "*", query: "absentword" }, f.ctx)).items, []);
447
+ });
448
+ test("raw filtering preserves generated tool documents, compact arguments and nested JSON escapes", async (t) => {
449
+ const f = await fixture(t);
450
+ await f.put(f.piPath, rows([
451
+ { type: "session", id: "pi-one" },
452
+ { type: "message", id: "t", parentId: null, timestamp: AT, message: { role: "toolResult", content: [{ type: "text", text: "done" }] } },
453
+ ]));
454
+ for (const query of ["unknown", "arguments", "output"]) {
455
+ const page = data(await historyList.execute({ session: "pi:pi-*", query }, f.ctx));
456
+ assert.equal(page.items.length, 1, query);
457
+ }
458
+ await f.put(f.piPath, rows([
459
+ { type: "session", id: "pi-one" },
460
+ { type: "message", id: "t", parentId: null, timestamp: AT, message: { role: "assistant", content: [{ type: "toolCall", id: "c", name: "read", arguments: { value: "\ud800" } }] } },
461
+ ]));
462
+ assert.equal(data(await historyList.execute({ session: "pi:pi-*", query: "ud" }, f.ctx)).items.length, 1);
463
+ const codexRows = f.codexText.split("\n").filter(Boolean).map((line) => JSON.parse(line));
464
+ codexRows[1].payload = { type: "function_call", call_id: "t", name: "read", arguments: '{ "path" : "\\u006eeedle" }' };
465
+ await f.put(f.codexPath, zstdCompressSync(Buffer.from(rows(codexRows))));
466
+ for (const query of ["needle", '"path":"needle"']) {
467
+ const page = data(await historyList.execute({ session: "codex:*", query }, f.ctx));
468
+ assert.equal(page.items.length, 1, query);
469
+ }
470
+ });
471
+ test("Codex raw pre-filtering preserves query hits inherited through history_base", async (t) => {
472
+ const f = await fixture(t);
473
+ const child = "019a0000-0000-7000-8000-000000000002";
474
+ const parent = rows([
475
+ { type: "session_meta", ordinal: 0, timestamp: AT, payload: { id: CODEX, cwd: "/workspace", cli_version: "0.160.1", history_mode: "paginated", context_window: { window_id: WINDOW } } },
476
+ { type: "response_item", ordinal: 1, timestamp: AT, payload: { type: "message", role: "user", content: [{ type: "input_text", text: "ancestralneedle" }] } },
477
+ ]);
478
+ await f.put(f.codexPath, zstdCompressSync(Buffer.from(parent)));
479
+ await f.put(join(dirname(f.codexPath), `rollout-2026-10-06T01-02-03-${child}.jsonl`), rows([
480
+ { type: "session_meta", ordinal: 2, timestamp: AT, payload: { id: child, cwd: "/workspace", cli_version: "0.160.1", history_mode: "paginated", history_base: { thread_id: CODEX, end_ordinal_exclusive: 2, end_byte_offset: Buffer.byteLength(parent) }, context_window: { window_id: WINDOW } } },
481
+ { type: "response_item", ordinal: 3, timestamp: AT, payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: "local only" }] } },
482
+ ]));
483
+ const page = data(await historyList.execute({ session: `codex:${child}*`, query: "ancestralneedle" }, f.ctx));
484
+ assert.deepEqual(page.items.map((item) => "seq" in item ? [item.session, item.seq] : null), [[`codex:${child}`, 2]]);
485
+ });
486
+ test("offline Claude attachments and retry branches are readable and searchable through session selectors", async (t) => {
487
+ const f = await fixture(t);
488
+ await f.put(f.claudePath, rows([
489
+ { type: "user", uuid: "u", parentUuid: null, sessionId: "claude-one", timestamp: AT, message: { role: "user", content: "topic" } },
490
+ { type: "assistant", uuid: "left", parentUuid: "u", sessionId: "claude-one", timestamp: AT, message: { role: "assistant", content: "leftneedle" } },
491
+ { type: "assistant", uuid: "right", parentUuid: "u", sessionId: "claude-one", timestamp: AT, message: { role: "assistant", content: "rightneedle" } },
492
+ { type: "attachment", uuid: "hook", parentUuid: "u", sessionId: "claude-one", attachment: { type: "hook_success" } },
493
+ ]));
494
+ assert.equal(data(await historyRead.execute({ session: "claude:claude-one", seq: 3 }, f.ctx)).text, "rightneedle");
495
+ refusal(await historyRead.execute({ session: "claude:claude-one", seq: 2 }, f.ctx), "not_on_branch");
496
+ for (const session of ["claude:claude-one", "claude:*"]) {
497
+ const page = data(await historyList.execute({ session, query: "needle" }, f.ctx));
498
+ assert.deepEqual(page.items.map((item) => "seq" in item ? item.seq : null), [3]);
499
+ }
500
+ assert.deepEqual(data(await historyList.execute({ session: "claude:*" }, f.ctx)).items.map((item) => "seq" in item ? item.seq : null), [1]);
288
501
  });
289
502
  test("offline Pi follows persisted parent links, preserves branch seq holes and rejects corrupt ancestry", async () => {
290
503
  const base = { type: "session", version: 3, id: "branch", timestamp: AT };
@@ -297,11 +510,22 @@ test("offline Pi follows persisted parent links, preserves branch seq holes and
297
510
  assert.throws(() => piHistoryFromJsonl(text + "bad\n", "branch"), /malformed Pi/);
298
511
  assert.throws(() => piHistoryFromJsonl(text, "wrong"), /different session/);
299
512
  });
300
- test("offline Claude requires one evidenced leaf, accounts for logical compact links, and never guesses among branches", () => {
513
+ test("offline Claude prefers non-attachment leaves, then transcript order, and keeps compact links", () => {
301
514
  const user = (uuid, parentUuid) => ({ type: "user", uuid, parentUuid, sessionId: "s", message: { role: "user", content: "text" } });
302
515
  assert.equal(offlineClaudeHead(rows([user("u", null), user("a", "u")])), "a");
303
516
  assert.equal(offlineClaudeHead(rows([user("u", null), { type: "system", uuid: "b", parentUuid: null, logicalParentUuid: "u", subtype: "compact_boundary" }, user("a", "b")])), "a");
304
517
  assert.equal(offlineClaudeHead(rows([user("u", null), user("preserved", null), { type: "system", uuid: "b", parentUuid: null, logicalParentUuid: "u", subtype: "compact_boundary", compactMetadata: { preservedSegment: { headUuid: "preserved", tailUuid: "preserved" } } }, user("a", "b")])), "a");
305
- assert.throws(() => offlineClaudeHead(rows([user("u", null), user("left", "u"), user("right", "u")])), /2 possible heads/);
518
+ const attachment = (uuid, parentUuid) => ({ type: "attachment", uuid, parentUuid, sessionId: "s", attachment: { type: "hook_success" } });
519
+ assert.equal(offlineClaudeHead(rows([user("u", null), user("left", "u"), user("right", "u")])), "right");
520
+ assert.equal(offlineClaudeHead(rows([user("u", null), user("right", "u"), user("left", "u")])), "left");
521
+ assert.equal(offlineClaudeHead(rows([user("u", null), user("left", "u"), user("right", "u"), user("left", "u")])), "left");
522
+ assert.equal(offlineClaudeHead(rows([user("u", null), user("answer", "u"), attachment("hook", "u")])), "answer");
523
+ assert.equal(offlineClaudeHead(rows([user("u", null), attachment("hook", "u")])), "hook");
524
+ assert.equal(offlineClaudeHead(rows([attachment("first", null), attachment("last", null)])), "last");
306
525
  assert.throws(() => offlineClaudeHead(""), /0 possible heads/);
526
+ assert.throws(() => offlineClaudeHead(rows([user("a", "b"), user("b", "a")])), /0 possible heads/);
527
+ // Live decoding still requires a host-confirmed head, regardless of offline selection.
528
+ const branch = rows([user("u", null), user("left", "u"), user("right", "u")]);
529
+ assert.throws(() => claudeHistoryFromJsonl(branch, { sessionId: "s" }), /no confirmed active head/);
530
+ assert.deepEqual(allItems(claudeHistoryFromJsonl(branch, { sessionId: "s", headUuid: "left" })).map((item) => item.seq), [1, 2]);
307
531
  });
@@ -131,8 +131,8 @@ test("pairing uses append seq rather than the presentation order of unnumbered s
131
131
  assert.deepEqual(projection.windows.map((window) => window.windowId), ["unknown-a", "unknown-b"], "pairing must not invent segment chronology");
132
132
  assert.deepEqual(projection.windows.flatMap((window) => window.items).filter((event) => event.role === "tool").map((event) => [event.seq, event.text]), [[2, "output"]]);
133
133
  const alias = await historyRead.execute({ seq: 3 }, projection);
134
- assert.ok(!alias.ok);
135
- assert.equal(alias.error.code, "not_an_event");
134
+ assert.ok(alias.ok);
135
+ assert.equal(alias.data.seq, 2);
136
136
  });
137
137
  test("seq is stable across branch changes, abandoned entries stay unreadable, and a paired result seq is refused precisely", async () => {
138
138
  const session = manager();
@@ -154,7 +154,7 @@ test("seq is stable across branch changes, abandoned entries stay unreadable, an
154
154
  assert.equal(unknown.code, "unknown_seq");
155
155
  assert.match(unknown.message, /\b4\b.*\b3\b/);
156
156
  });
157
- test("a result address consumed by a pairing names its call instead of serving a second read", async () => {
157
+ test("a result address consumed by a pairing resolves directly to its call event", async () => {
158
158
  const session = manager();
159
159
  const captured = makeExtension(session);
160
160
  const ctx = context(session);
@@ -162,9 +162,9 @@ test("a result address consumed by a pairing names its call instead of serving a
162
162
  toolResult(session, "paired", "edit", "edited");
163
163
  // The assistant message takes seq 1 and its tool call seq 2; the result at seq 3 is absorbed.
164
164
  assert.deepEqual(seqs(await call(captured, "history_list", { roles: ["tool"] }, ctx)), [2], "the pairing is one event at the call's address");
165
- const consumed = resultError(await call(captured, "history_read", { seq: 3 }, ctx));
166
- assert.equal(consumed.code, "not_an_event");
167
- assert.match(consumed.message, /seq 2\b/);
165
+ const consumed = resultRead(await call(captured, "history_read", { seq: 3 }, ctx));
166
+ assert.equal(consumed.seq, 2);
167
+ assert.equal(consumed.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
168
168
  const callSeq = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
169
169
  assert.equal(callSeq.seq, 2);
170
170
  assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
@@ -703,9 +703,9 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
703
703
  assert.equal(hit.offset_chars, earliestMatchOffsetChars('read {"path":"one"}\n--- output ---\nšŸ˜€ needle', ["NEEDLE"]));
704
704
  }
705
705
  const consumed = await historyRead.execute({ seq: 6 }, projection);
706
- assert.equal(consumed.ok, false);
707
- if (!consumed.ok)
708
- assert.equal(consumed.error.code, "not_an_event");
706
+ assert.equal(consumed.ok, true);
707
+ if (consumed.ok)
708
+ assert.equal(consumed.data.seq, 5);
709
709
  const offBranch = await historyRead.execute({ seq: 12 }, projection);
710
710
  assert.equal(offBranch.ok, false);
711
711
  if (!offBranch.ok)
@@ -187,14 +187,13 @@ test("shared note operations return canonical outcomes with a body-only read win
187
187
  assert.equal(written.address, "@project/test.md");
188
188
  assert.equal(written.project_key, notesIdentity.projectKey);
189
189
  assert.equal(written.outcome, "created");
190
+ let observedKind = "";
190
191
  const updated = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "alpha", newText: "gamma" }] }, toolContext, (change) => {
191
- assert.equal(change.kind, "body");
192
- return "caller-rendered-diff";
192
+ observedKind = change.kind;
193
193
  }));
194
+ assert.equal(observedKind, "body");
194
195
  assert.equal(updated.change_kind, "body");
195
- assert.equal(updated.diff, "caller-rendered-diff");
196
- const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] }, toolContext));
197
- assert.equal(defaultReceipt.diff, "note body");
196
+ assert.equal(notesUpdate.render(success(updated)), `updated @project/test.md (project ${notesIdentity.projectKey})`);
198
197
  await notesWrite.execute({ address: "owned.md", content: "first", origin: "user" }, toolContext);
199
198
  await notesWrite.execute({ address: "owned.md", content: "rewritten" }, toolContext);
200
199
  assert.equal(data(await notesRead.execute({ address: "owned.md" }, toolContext)).metadata.origin, "user", "tool overwrites preserve an omitted origin");
@@ -203,13 +202,12 @@ test("shared note operations return canonical outcomes with a body-only read win
203
202
  const moved = data(await notesUpdate.execute({ address: "owned.md", rename_to: "@project/renamed.md", edits: [{ oldText: "rewritten", newText: "final" }], origin: "external" }, toolContext));
204
203
  assert.equal(moved.change_kind, "moved");
205
204
  assert.equal(moved.rename_from, "owned.md");
206
- assert.match(moved.diff, /rename owned\.md -> @project\/renamed\.md/);
205
+ assert.equal(notesUpdate.render(success(moved)), "moved owned.md -> @project/renamed.md");
207
206
  const renamed = data(await notesRead.execute({ address: moved.address }, toolContext));
208
207
  assert.equal(renamed.text, "final");
209
208
  assert.equal(renamed.metadata.origin, "external");
210
- const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] }, toolContext));
209
+ const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "gamma" }] }, toolContext));
211
210
  assert.equal(unchanged.change_kind, "none");
212
- assert.equal(unchanged.diff, "");
213
211
  // Frontmatter is metadata, not body: the window addresses the body and counts only the body.
214
212
  const stored = await createNotesStore(notesIdentity).read("@project/test.md");
215
213
  assert.ok(stored, "the note is on disk");
@@ -260,7 +258,7 @@ test("shared history operations read typed events through the addresses the adap
260
258
  assert.match(fromMatch.text, /^needle output/, "the match offset lands on the matched text");
261
259
  assert.equal(fromMatch.total_chars, full.total_chars, "one document, one length");
262
260
  assert.match(refusal(await historyRead.execute({ seq: 9_999 }, projection)).message, /9,?999/, "an unknown address is refused by name");
263
- assert.equal(refusal(await historyRead.execute({ seq: 3 }, projection)).code, "not_an_event", "a paired result address is refused");
261
+ assert.equal(data(await historyRead.execute({ seq: 3 }, projection)).seq, 2, "a paired result address resolves to its call event");
264
262
  });
265
263
  test("one role schema declares the four public roles for the page item, the read payload, and the role filter", () => {
266
264
  const read = (role) => ({