notesoup 0.53.2 → 0.54.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 (186) hide show
  1. package/README.md +6 -4
  2. package/dist/plugins/claude/src/helper.d.ts +2 -1
  3. package/dist/plugins/claude/src/helper.js +21 -24
  4. package/dist/plugins/claude/src/history.d.ts +3 -14
  5. package/dist/plugins/claude/src/history.js +2 -298
  6. package/dist/plugins/claude/src/text.d.ts +0 -1
  7. package/dist/plugins/claude/src/text.js +0 -1
  8. package/dist/plugins/codex/src/history.d.ts +3 -8
  9. package/dist/plugins/codex/src/history.js +2 -238
  10. package/dist/plugins/codex/src/hooks.js +1 -1
  11. package/dist/plugins/codex/src/identity.d.ts +1 -1
  12. package/dist/plugins/codex/src/identity.js +3 -3
  13. package/dist/plugins/codex/src/mcp.js +9 -8
  14. package/dist/plugins/codex/src/text.d.ts +1 -1
  15. package/dist/plugins/codex/src/text.js +2 -2
  16. package/dist/plugins/codex/src/transcript.d.ts +3 -39
  17. package/dist/plugins/codex/src/transcript.js +2 -313
  18. package/dist/plugins/dsh/engine.js +2 -2
  19. package/dist/plugins/dsh/history.d.ts +3 -0
  20. package/dist/plugins/dsh/history.js +15 -0
  21. package/dist/plugins/dsh/tools.js +12 -12
  22. package/dist/plugins/dsh/window.d.ts +1 -0
  23. package/dist/plugins/dsh/window.js +7 -3
  24. package/dist/plugins/pi/history-tools.d.ts +1 -1
  25. package/dist/plugins/pi/history-tools.js +9 -5
  26. package/dist/plugins/pi/history.d.ts +2 -3
  27. package/dist/plugins/pi/history.js +4 -147
  28. package/dist/plugins/pi/notes/tools.js +8 -6
  29. package/dist/plugins/pi/render.js +7 -4
  30. package/dist/plugins/pi/runtime.js +2 -2
  31. package/dist/plugins/pi/window.js +21 -7
  32. package/dist/src/boot/render.js +9 -11
  33. package/dist/src/boot/snapshot.d.ts +7 -7
  34. package/dist/src/boot/snapshot.js +17 -17
  35. package/dist/src/boot/text.d.ts +5 -3
  36. package/dist/src/boot/text.js +18 -10
  37. package/dist/src/dream/git.d.ts +2 -11
  38. package/dist/src/dream/git.js +6 -23
  39. package/dist/src/dream/lock.d.ts +2 -2
  40. package/dist/src/dream/lock.js +3 -3
  41. package/dist/src/history/claude.d.ts +16 -0
  42. package/dist/src/history/claude.js +336 -0
  43. package/dist/src/history/codex-transcript.d.ts +39 -0
  44. package/dist/src/history/codex-transcript.js +315 -0
  45. package/dist/src/history/codex.d.ts +8 -0
  46. package/dist/src/history/codex.js +238 -0
  47. package/dist/src/history/corpus.d.ts +35 -0
  48. package/dist/src/history/corpus.js +54 -0
  49. package/dist/src/history/history.d.ts +4 -8
  50. package/dist/src/history/history.js +3 -11
  51. package/dist/src/history/local.d.ts +17 -0
  52. package/dist/src/history/local.js +101 -0
  53. package/dist/src/history/pi.d.ts +36 -0
  54. package/dist/src/history/pi.js +202 -0
  55. package/dist/src/history/query.d.ts +15 -5
  56. package/dist/src/history/query.js +42 -13
  57. package/dist/src/index.d.ts +6 -3
  58. package/dist/src/index.js +6 -4
  59. package/dist/src/notes/address.d.ts +8 -8
  60. package/dist/src/notes/address.js +13 -13
  61. package/dist/src/notes/errors.d.ts +1 -1
  62. package/dist/src/notes/frontmatter.js +2 -2
  63. package/dist/src/notes/index.d.ts +1 -1
  64. package/dist/src/notes/index.js +1 -1
  65. package/dist/src/notes/paths.d.ts +6 -6
  66. package/dist/src/notes/paths.js +9 -9
  67. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  68. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  69. package/dist/src/notes/store.d.ts +4 -4
  70. package/dist/src/notes/store.js +55 -52
  71. package/dist/src/tools/dream.d.ts +21 -3
  72. package/dist/src/tools/dream.js +54 -16
  73. package/dist/src/tools/history.d.ts +7 -19
  74. package/dist/src/tools/history.js +80 -93
  75. package/dist/src/tools/notes-context.d.ts +10 -0
  76. package/dist/src/tools/notes-context.js +27 -0
  77. package/dist/src/tools/notes.d.ts +69 -20
  78. package/dist/src/tools/notes.js +40 -31
  79. package/dist/test/boot.integration.test.js +2 -3
  80. package/dist/test/claude-history.test.js +47 -34
  81. package/dist/test/claude-mod.test.js +96 -50
  82. package/dist/test/codex-history.test.js +4 -10
  83. package/dist/test/codex-plugin.test.js +50 -12
  84. package/dist/test/context-edit-budget.test.js +121 -0
  85. package/dist/test/dependencies.test.js +73 -6
  86. package/dist/test/dream-tools.test.js +153 -8
  87. package/dist/test/dsh.test.js +88 -19
  88. package/dist/test/helpers/dsh.d.ts +4 -1
  89. package/dist/test/helpers/dsh.js +20 -4
  90. package/dist/test/helpers/extension.d.ts +5 -1
  91. package/dist/test/helpers/extension.js +33 -2
  92. package/dist/test/helpers/history-corpus.d.ts +7 -0
  93. package/dist/test/helpers/history-corpus.js +26 -0
  94. package/dist/test/history-corpus.test.js +307 -0
  95. package/dist/test/history.integration.test.js +40 -48
  96. package/dist/test/host-neutral.test.js +20 -33
  97. package/dist/test/model-facing-text.test.js +14 -8
  98. package/dist/test/notes-cwd.test.d.ts +1 -0
  99. package/dist/test/notes-cwd.test.js +114 -0
  100. package/dist/test/notes-library.test.js +4 -4
  101. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  102. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  103. package/dist/test/notes.integration.test.js +73 -24
  104. package/dist/test/notes.test.js +51 -21
  105. package/dist/test/pi-render.test.js +33 -1
  106. package/dist/test/project-namespace.test.d.ts +1 -0
  107. package/dist/test/project-namespace.test.js +324 -0
  108. package/docs/architecture.md +19 -12
  109. package/docs/claude-code-mod.md +7 -5
  110. package/docs/codex.md +6 -6
  111. package/docs/dsh.md +9 -9
  112. package/docs/history-sessions.md +52 -0
  113. package/docs/notes-library.md +9 -5
  114. package/docs/skills.md +3 -3
  115. package/docs/tool-results.md +14 -8
  116. package/package.json +4 -6
  117. package/playbook.md +6 -6
  118. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  119. package/plugins/claude/dist/claude/helper.js +2164 -1341
  120. package/plugins/claude/hooks/register.ts +19 -11
  121. package/plugins/claude/playbook.md +6 -6
  122. package/plugins/claude/skills/memory/SKILL.md +9 -7
  123. package/plugins/claude/src/helper.ts +22 -25
  124. package/plugins/claude/src/history.ts +3 -257
  125. package/plugins/claude/src/text.ts +0 -1
  126. package/plugins/codex/README.md +1 -1
  127. package/plugins/codex/dist/codex/notesoup.js +1582 -969
  128. package/plugins/codex/src/history.ts +3 -193
  129. package/plugins/codex/src/hooks.ts +1 -1
  130. package/plugins/codex/src/identity.ts +3 -3
  131. package/plugins/codex/src/mcp.ts +9 -8
  132. package/plugins/codex/src/text.ts +2 -2
  133. package/plugins/codex/src/transcript.ts +3 -275
  134. package/plugins/dsh/engine.ts +2 -2
  135. package/plugins/dsh/history.ts +17 -0
  136. package/plugins/dsh/tools.ts +12 -12
  137. package/plugins/dsh/window.ts +8 -3
  138. package/plugins/paseo/OVERVIEW.md +4 -4
  139. package/plugins/paseo/README.md +1 -1
  140. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  141. package/plugins/paseo/client/markdown.tsx +159 -0
  142. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  143. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  144. package/plugins/paseo/client/paper-card.tsx +8 -19
  145. package/plugins/paseo/client/paper-palette.ts +40 -0
  146. package/plugins/paseo/client/sticky-card.tsx +6 -4
  147. package/plugins/paseo/package.json +3 -0
  148. package/plugins/paseo/paseo-plugin.json +2 -2
  149. package/plugins/paseo/shared/notes-op.ts +13 -9
  150. package/plugins/paseo/test/notes-op.test.ts +52 -73
  151. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  152. package/plugins/pi/history-tools.ts +11 -5
  153. package/plugins/pi/history.ts +8 -157
  154. package/plugins/pi/notes/tools.ts +8 -6
  155. package/plugins/pi/render.ts +6 -4
  156. package/plugins/pi/runtime.ts +2 -2
  157. package/plugins/pi/window.ts +22 -7
  158. package/skills/memory/SKILL.md +9 -7
  159. package/src/boot/render.ts +10 -13
  160. package/src/boot/snapshot.ts +20 -20
  161. package/src/boot/text.ts +18 -10
  162. package/src/dream/git.ts +7 -24
  163. package/src/dream/lock.ts +3 -3
  164. package/src/history/claude.ts +286 -0
  165. package/src/history/codex-transcript.ts +276 -0
  166. package/src/history/codex.ts +193 -0
  167. package/src/history/corpus.ts +69 -0
  168. package/src/history/history.ts +5 -12
  169. package/src/history/local.ts +93 -0
  170. package/src/history/pi.ts +199 -0
  171. package/src/history/query.ts +45 -15
  172. package/src/index.ts +8 -5
  173. package/src/notes/address.ts +13 -13
  174. package/src/notes/errors.ts +1 -1
  175. package/src/notes/frontmatter.ts +2 -2
  176. package/src/notes/index.ts +1 -1
  177. package/src/notes/paths.ts +9 -9
  178. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  179. package/src/notes/store.ts +61 -58
  180. package/src/tools/dream.ts +63 -16
  181. package/src/tools/history.ts +71 -101
  182. package/src/tools/notes-context.ts +29 -0
  183. package/src/tools/notes.ts +39 -29
  184. package/dist/test/project-home.test.js +0 -134
  185. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  186. /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
@@ -13,10 +13,19 @@ import { PROTOCOL_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js
13
13
  import { CLAUDE_WARNING_PROMPT } from "../plugins/claude/src/text.js";
14
14
  import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, NORMAL_CONTINUATIONS, warningNotice } from "../src/budget/text.js";
15
15
  import { createNotesStore } from "../src/notes/index.js";
16
- import { resolveProjectHome } from "../src/notes/project-home.js";
16
+ import { resolveProjectNamespace } from "../src/notes/project-namespace.js";
17
17
  import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
18
18
  import { context, manager } from "./helpers/extension.js";
19
19
  const identity = { home: mkdtempSync(join(tmpdir(), "claude-mod-")), sessionId: "session", cwd: process.cwd(), agent: "claude", model: "claude" };
20
+ /** Every fake completion satisfies the host contract; success is explicit, never an omitted reason. */
21
+ function turnComplete(overrides = {}) {
22
+ const reason = overrides.reason ?? "answer";
23
+ return {
24
+ answer: reason === "answer" ? "done" : "", durationMs: 1, turnId: "turn-1",
25
+ ...overrides, reason, isAborted: reason === "aborted",
26
+ ...(reason === "refusal" ? { refusal: overrides.refusal ?? { category: null, explanation: null } } : {}),
27
+ };
28
+ }
20
29
  async function callTool(tool, params) {
21
30
  return await dispatch({ op: "tool", tool, identity, params });
22
31
  }
@@ -92,9 +101,9 @@ test("Claude notes survive removal of the session's worktree cwd", async (t) =>
92
101
  assert.match((await call("notes_read", { address })).result, /done/);
93
102
  }
94
103
  });
95
- test("Claude helper exposes the eight shared notes/history schemas", async () => {
104
+ test("Claude helper exposes the seven shared notes/history schemas", async () => {
96
105
  const schemas = await dispatch({ op: "schemas" });
97
- assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
106
+ assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read"]);
98
107
  assert.ok(schemas.every((schema) => schema.description.length > 20 && schema.inputSchema.type === "object"));
99
108
  });
100
109
  test("Claude helper delivers only shared rendered text and success", async () => {
@@ -107,6 +116,20 @@ test("Claude helper delivers only shared rendered text and success", async () =>
107
116
  assert.deepEqual(Object.keys(missing).sort(), ["ok", "text"]);
108
117
  assert.match(missing.text, /^error: not_found: /, "the refusal renders as the shared error line");
109
118
  });
119
+ test("Claude resolves relative cwd against the request identity, not the helper process", async (t) => {
120
+ const base = join(identity.home, "base"), other = join(identity.home, "other");
121
+ mkdirSync(base);
122
+ mkdirSync(other);
123
+ t.after(() => { rmSync(base, { recursive: true, force: true }); rmSync(other, { recursive: true, force: true }); });
124
+ const requestIdentity = { ...identity, cwd: base };
125
+ const written = await dispatch({ op: "tool", tool: "notes_write", identity: requestIdentity, params: { address: "@project/selected", content: "from Claude", cwd: "../other" } });
126
+ assert.equal(written.ok, true, written.text);
127
+ const project = resolveProjectNamespace(other, identity.home);
128
+ assert.match(readFileSync(join(project.dir, "selected.md"), "utf8"), /from Claude/);
129
+ const read = await dispatch({ op: "tool", tool: "notes_read", identity: requestIdentity, params: { address: "@project/selected", cwd: "../other" } });
130
+ assert.equal(read.ok, true, read.text);
131
+ assert.match(read.text, /from Claude/);
132
+ });
110
133
  test("Claude helper rejects malformed or unknown requests", async () => {
111
134
  const malformed = JSON.parse(await handleLine("not json"));
112
135
  assert.equal(malformed.ok, false);
@@ -265,7 +288,7 @@ test("Claude Mod helper runs from a standalone copied plugin directory", () => {
265
288
  }));
266
289
  const schemas = run('{"op":"schemas"}');
267
290
  assert.equal(schemas.ok, true);
268
- assert.equal(schemas.result?.length, 8);
291
+ assert.equal(schemas.result?.length, 7);
269
292
  assert.equal(run("not json").ok, false);
270
293
  }
271
294
  finally {
@@ -360,7 +383,7 @@ test("Claude Mod with NOTESOUP_DISABLED registers nothing and passes every event
360
383
  const native = { skip: "engine default" };
361
384
  const compact = await handlers.get("session.compact")(host, { trigger: "auto" }, async () => native);
362
385
  assert.equal(compact, native, "native compaction runs exactly as if the mod were absent");
363
- const completed = await handlers.get("turn.complete")(host, {}, async () => ({ done: true }));
386
+ const completed = await handlers.get("turn.complete")(host, turnComplete(), async () => ({ done: true }));
364
387
  assert.deepEqual(completed, { done: true }, "turn.complete passes through without a reset");
365
388
  assert.equal(handlers.has("session.measure"), false, "measure has no reset hook");
366
389
  assert.equal(helperCalls, 0, "the helper never runs while disabled");
@@ -461,7 +484,7 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
461
484
  const handlers = new Map();
462
485
  hooks.register((event, handler) => handlers.set(event, handler));
463
486
  await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async (event) => event);
464
- assert.deepEqual(registered.map((spec) => spec.name), ["empty_brain", "notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
487
+ assert.deepEqual(registered.map((spec) => spec.name), ["empty_brain", "notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read"]);
465
488
  for (const spec of registered) {
466
489
  assert.equal(spec.isDeferred, false, `${spec.name} is available from the start without tool search`);
467
490
  assert.ok(spec.description.length > 20);
@@ -507,35 +530,35 @@ test("Claude Mod crosses old reset thresholds without clearing and retains one f
507
530
  return result;
508
531
  };
509
532
  await invoke("session.start", { cwd: home, isInteractive: true });
510
- assert.equal(registered.length, 9);
533
+ assert.equal(registered.length, 8);
511
534
  const initial = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
512
535
  assert.equal(initial.blocks.length, 1, "below the warn point no warning joins the boot");
513
536
  assert.match(initial.blocks[0].text, /Current context window id: claude:hook-session:0/);
514
537
  await invoke("turn.start");
515
- await invoke("turn.complete");
538
+ await invoke("turn.complete", turnComplete());
516
539
  assert.equal(compactions, 0, "140000 is below every resolved point");
517
540
  host.session.usage = async () => { throw new Error("usage unavailable"); };
518
- await invoke("turn.complete");
541
+ await invoke("turn.complete", turnComplete());
519
542
  await invoke("tool.call", { tool: "Read" });
520
543
  assert.equal(notifications.filter((text) => text.includes("Brain fullness unknown")).length, 1, "warning usage failure logs once per session");
521
544
  host.session.usage = async () => measured();
522
545
  await dispatch({ op: "tool", tool: "notes_write", identity: { ...identity, home, cwd: home, sessionId: "hook-session" }, params: { address: "@human/MAP.md", content: "FRESH_NOTES_AT_RESET" } });
523
546
  await invoke("turn.start");
524
547
  tokens = 158_807;
525
- await invoke("turn.complete");
548
+ await invoke("turn.complete", turnComplete());
526
549
  assert.equal(compactions, 0, "one token below the resolved reset point");
527
550
  await invoke("turn.start");
528
551
  tokens = 158_808;
529
552
  assert.equal(compactions, 0, "measure cannot compact under a running turn");
530
- assert.deepEqual(await invoke("turn.complete"), { sentinel: "turn.complete" });
553
+ assert.deepEqual(await invoke("turn.complete", turnComplete()), { sentinel: "turn.complete" });
531
554
  assert.equal(compactions, 0, "the old reset point no longer clears at turn completion");
532
555
  tokens = 190_000;
533
556
  await invoke("turn.start");
534
- await invoke("turn.complete");
557
+ await invoke("turn.complete", turnComplete());
535
558
  assert.equal(compactions, 0, "even beyond the native threshold, only a native auto event or explicit request resets");
536
559
  await invoke("turn.start");
537
560
  await invoke("command.run", { command: "empty" });
538
- await invoke("turn.complete");
561
+ await invoke("turn.complete", turnComplete());
539
562
  assert.equal(compactions, 1);
540
563
  assert.equal(kept.length, 2, "the reset is the notes boot followed by the one reset message");
541
564
  assert.equal(kept[0].role, "user");
@@ -548,6 +571,29 @@ test("Claude Mod crosses old reset thresholds without clearing and retains one f
548
571
  const upstream = { blocks: [{ name: "unrelated", text: "leave this alone" }], sentinel: "kept" };
549
572
  assert.deepEqual(await handlers.get("prompt.context")(host, {}, async () => upstream), upstream, "the retained boot is not injected a second time");
550
573
  });
574
+ test("Claude Mod preserves context and cancels a queued reset after an unsuccessful turn", async (t) => {
575
+ for (const reason of ["aborted", "error", "refusal"]) {
576
+ await t.test(reason, async (t) => {
577
+ const home = mkdtempSync(join(tmpdir(), `claude-reset-${reason}-`));
578
+ t.after(() => rmSync(home, { recursive: true, force: true }));
579
+ const { host, notifications } = fakeEngine(home);
580
+ const handlers = new Map();
581
+ (await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
582
+ const invoke = (name, event = {}) => handlers.get(name)(host, event, async () => ({ sentinel: name }));
583
+ let compactions = 0;
584
+ host.session.compact = async () => { compactions++; return { skip: "reset must not run" }; };
585
+ await invoke("session.start", { cwd: home, isInteractive: true });
586
+ await invoke("turn.start");
587
+ await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: `reset-${reason}`, last_word: "DO_NOT_KEEP" });
588
+ await invoke("turn.complete", turnComplete({ reason }));
589
+ assert.equal(compactions, 0, `${reason} never submits the queued reset`);
590
+ assert.ok(notifications.some(text => text.includes("cancelled") && text.includes(reason)), `${reason} reports that its request was cancelled`);
591
+ await invoke("turn.start");
592
+ await invoke("turn.complete", turnComplete());
593
+ assert.equal(compactions, 0, `${reason} leaves no pending reset for a later successful turn`);
594
+ });
595
+ }
596
+ });
551
597
  test("Claude headless resets through its own manual command, retries failure and keeps user compact vetoed", async (t) => {
552
598
  const home = mkdtempSync(join(tmpdir(), "claude-headless-home-"));
553
599
  t.after(() => rmSync(home, { recursive: true, force: true }));
@@ -571,11 +617,11 @@ test("Claude headless resets through its own manual command, retries failure and
571
617
  await invoke("session.start", { cwd: home, isInteractive: false });
572
618
  assert.match(JSON.stringify(await invoke("session.compact", { trigger: "manual" })), /use \/fresh-window/);
573
619
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", last_word: "STICKY", tool_use_id: "reset" });
574
- await invoke("turn.complete");
620
+ await invoke("turn.complete", turnComplete());
575
621
  assert.equal(attempts, 1);
576
622
  assert.ok(notifications.some(x => x.includes("command unavailable")));
577
623
  reject = false;
578
- await invoke("turn.complete");
624
+ await invoke("turn.complete", turnComplete());
579
625
  assert.equal(attempts, 2, "failed requests remain pending");
580
626
  assert.ok(notifications.some(x => x.includes("Brain not emptied")));
581
627
  // Core dispatches the admitted manual event within our command hook.
@@ -589,14 +635,14 @@ test("Claude headless resets through its own manual command, retries failure and
589
635
  });
590
636
  return {};
591
637
  };
592
- await invoke("turn.complete");
638
+ await invoke("turn.complete", turnComplete());
593
639
  assert.match(kept[0].text, /claude:hook-session:1/);
594
640
  assert.equal(kept[2].text, "*You peel a sticky note off your forehead.*\nSTICKY");
595
- await invoke("turn.complete");
641
+ await invoke("turn.complete", turnComplete());
596
642
  assert.equal(attempts, 3, "success clears pending exactly once");
597
643
  assert.match(JSON.stringify(await invoke("session.compact", { trigger: "manual" })), /use \/fresh-window/);
598
644
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "reset2" });
599
- await invoke("turn.complete");
645
+ await invoke("turn.complete", turnComplete());
600
646
  assert.match(kept[0].text, /claude:hook-session:2/);
601
647
  assert.equal(kept.length, 2, "sticky is consumed once");
602
648
  });
@@ -612,7 +658,7 @@ test("Claude headless warns without proactive resets and supports both manual al
612
658
  const timers = [];
613
659
  host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
614
660
  host.clock.after = (_ms, callback) => { timers.push(callback); };
615
- host.prompt.submit = async () => { prompts++; await invoke("turn.start"); await invoke("turn.complete"); };
661
+ host.prompt.submit = async () => { prompts++; await invoke("turn.start"); await invoke("turn.complete", turnComplete()); };
616
662
  host.command.run = async ({ command }) => {
617
663
  attempts++;
618
664
  await handlers.get("command.run")(host, { command, origin: { kind: "plugin", name: "notesoup" } }, async () => {
@@ -629,10 +675,10 @@ test("Claude headless warns without proactive resets and supports both manual al
629
675
  tokens = CLAUDE_200K.reset;
630
676
  await invoke("turn.start");
631
677
  assert.equal(attempts, 0);
632
- await invoke("turn.complete");
678
+ await invoke("turn.complete", turnComplete());
633
679
  assert.equal(attempts, 0, "the old reset threshold and turn completion do not clear");
634
680
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "explicit" });
635
- await invoke("turn.complete");
681
+ await invoke("turn.complete", turnComplete());
636
682
  assert.equal(attempts, 1);
637
683
  for (const command of ["empty", "fresh-window"]) {
638
684
  assert.deepEqual(await invoke("command.run", { command }), { text: "🥣 Dumping Brain" });
@@ -645,7 +691,7 @@ test("Claude headless warns without proactive resets and supports both manual al
645
691
  await invoke("command.run", { command: "empty" });
646
692
  await Promise.resolve();
647
693
  await timers.shift()();
648
- await invoke("turn.complete");
694
+ await invoke("turn.complete", turnComplete());
649
695
  assert.equal(attempts, 4, "a failed close-out also leaves the reset pending");
650
696
  });
651
697
  test("Claude Mod keeps its window numbering from a boot written before the tag rename", async (t) => {
@@ -687,12 +733,12 @@ test("Claude Mod refuses to wipe on boot failure and can retry without advancing
687
733
  host.session.compact = async ({ instructions }) => result = await invoke("session.compact", { trigger: "plugin", instructions });
688
734
  await invoke("turn.start");
689
735
  await invoke("command.run", { command: "empty" });
690
- await invoke("turn.complete");
736
+ await invoke("turn.complete", turnComplete());
691
737
  assert.match(result.skip, /notes didn't load/);
692
738
  assert.equal(result.messages, undefined, "a failed builder must veto rather than fall through to summary");
693
739
  failBoot = false;
694
740
  await invoke("turn.start");
695
- await invoke("turn.complete");
741
+ await invoke("turn.complete", turnComplete());
696
742
  assert.equal(result.skip, undefined);
697
743
  assert.equal(result.messages.length, 2);
698
744
  assert.match(result.messages[0].text, /Current context window id: claude:hook-session:1/, "a failed reset never consumes a window ordinal");
@@ -720,7 +766,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
720
766
  host.prompt.submit = async ({ text }) => {
721
767
  prompts.push(text);
722
768
  await invoke("turn.start");
723
- await invoke("turn.complete");
769
+ await invoke("turn.complete", turnComplete());
724
770
  };
725
771
  (await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
726
772
  await invoke("session.start", { cwd: home, isInteractive: true });
@@ -746,7 +792,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
746
792
  assert.deepEqual(await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] })), { blocks: [] }, "reload does not duplicate the already-retained boot");
747
793
  await invoke("turn.start");
748
794
  await invoke("command.run", { command: "empty" });
749
- await invoke("turn.complete");
795
+ await invoke("turn.complete", turnComplete());
750
796
  assert.equal(prompts.length, 1, "a busy manual request reuses the current turn instead of submitting another");
751
797
  assert.match(kept[0].text, /Current context window id: claude:hook-session:2/);
752
798
  });
@@ -803,7 +849,7 @@ test("Claude warnings read the public nested breakdown and apply pct even withou
803
849
  tokens++;
804
850
  assert.deepEqual((await submit()).context, [CLAUDE_WARNING_PROMPT]);
805
851
  assert.equal((await submit()).context, undefined, "one warning per window");
806
- await invoke("turn.complete");
852
+ await invoke("turn.complete", turnComplete());
807
853
  assert.equal(resets, 0, "warning and turn completion never proactively clear");
808
854
  assert.equal((await invoke("session.compact", { trigger: "auto" })).messages.length, 2);
809
855
  assert.deepEqual((await submit()).context, [CLAUDE_WARNING_PROMPT], "native auto starts a new warning window");
@@ -854,7 +900,7 @@ test("Claude Mod keeps warning timing when auto-compact is off without clearing
854
900
  host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
855
901
  await invoke("session.start", { cwd: home, isInteractive: true });
856
902
  await invoke("turn.start");
857
- await invoke("turn.complete");
903
+ await invoke("turn.complete", turnComplete());
858
904
  const submit = () => handlers.get("prompt.submit")(host, { text: "continue" }, async (e) => e);
859
905
  assert.equal((await submit()).context, undefined);
860
906
  tokens = 155_424;
@@ -862,7 +908,7 @@ test("Claude Mod keeps warning timing when auto-compact is off without clearing
862
908
  assert.equal(compactions, 0);
863
909
  await invoke("turn.start");
864
910
  tokens = 171_808;
865
- await invoke("turn.complete");
911
+ await invoke("turn.complete", turnComplete());
866
912
  assert.equal(compactions, 0, "the former 200000 - 20000 - 8192 reset point is not a clear trigger");
867
913
  assert.deepEqual(notifications.filter((text) => text.includes("unavailable") || text.includes("Couldn't")), [], "a resolvable configuration logs no failure");
868
914
  });
@@ -889,7 +935,7 @@ test("Claude Mod suppresses warnings and explicit reset requests under DISABLE_C
889
935
  assert.match(tool.result, /DISABLE_COMPACT/);
890
936
  assert.equal(timers.length, 0, "no close-out turn is queued");
891
937
  await invoke("turn.start");
892
- await invoke("turn.complete");
938
+ await invoke("turn.complete", turnComplete());
893
939
  assert.equal(compactions, 0, "disabled reset requests never run");
894
940
  assert.equal(notifications.length, 1, "detection logs once, not per turn");
895
941
  const upstream = { result: "upstream", context: ["other plugin"] };
@@ -908,7 +954,7 @@ test("Claude Mod skips the warning when thresholds cannot be resolved", async (t
908
954
  host.session.compact = async () => { compactions++; return {}; };
909
955
  await invoke("session.start", { cwd: home, isInteractive: true });
910
956
  await invoke("turn.start");
911
- await invoke("turn.complete");
957
+ await invoke("turn.complete", turnComplete());
912
958
  await invoke("tool.call", { tool: "Read" });
913
959
  assert.equal(compactions, 0, "an unresolvable point never resets");
914
960
  assert.equal(notifications.filter((text) => text.includes("Brain size unknown")).length, 1, "one line, not one per turn");
@@ -935,9 +981,9 @@ test("Claude Mod keeps the turn latch through subagent turns", async (t) => {
935
981
  await invoke("turn.start");
936
982
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "explicit" });
937
983
  await invoke("turn.start", { agentId: "sub-1" });
938
- await invoke("turn.complete", { agentId: "sub-1" });
984
+ await invoke("turn.complete", turnComplete({ agentId: "sub-1" }));
939
985
  assert.equal(compactions, 0, "a subagent turn cannot release the main turn's latch");
940
- await invoke("turn.complete");
986
+ await invoke("turn.complete", turnComplete());
941
987
  assert.equal(compactions, 1, "the main turn still resets at its own end");
942
988
  });
943
989
  test("Claude Mod treats DISABLE_COMPACT=off as not disabled", async (t) => {
@@ -955,7 +1001,7 @@ test("Claude Mod treats DISABLE_COMPACT=off as not disabled", async (t) => {
955
1001
  assert.deepEqual(notifications.filter((text) => text.includes("DISABLE_COMPACT")), [], "an explicit off is not a disable");
956
1002
  await invoke("turn.start");
957
1003
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "explicit" });
958
- await invoke("turn.complete");
1004
+ await invoke("turn.complete", turnComplete());
959
1005
  assert.equal(compactions, 1, "the explicit reset still runs");
960
1006
  });
961
1007
  test("Claude Mod retries an unresolvable warning threshold inside the same window", async (t) => {
@@ -978,12 +1024,12 @@ test("Claude Mod retries an unresolvable warning threshold inside the same windo
978
1024
  host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
979
1025
  await invoke("session.start", { cwd: home, isInteractive: true });
980
1026
  await invoke("turn.start");
981
- await invoke("turn.complete");
1027
+ await invoke("turn.complete", turnComplete());
982
1028
  await handlers.get("prompt.submit")(host, { text: "continue" }, async (e) => e);
983
1029
  assert.equal(limitsCalls, 1, "the first limits round trip failed");
984
1030
  assert.equal(compactions, 0, "one failed resolution does not disable the window");
985
1031
  await invoke("turn.start");
986
- await invoke("turn.complete");
1032
+ await invoke("turn.complete", turnComplete());
987
1033
  const retried = await handlers.get("prompt.submit")(host, { text: "continue" }, async (e) => e);
988
1034
  assert.deepEqual(retried.context, [CLAUDE_WARNING_PROMPT]);
989
1035
  assert.equal(limitsCalls, 2, "the retry runs in the same window");
@@ -1030,16 +1076,16 @@ test("Claude empty_brain defers until main turn completion, carries last_word, a
1030
1076
  assert.equal(accepted.isError, undefined);
1031
1077
  assert.match(accepted.result, /End your turn now/);
1032
1078
  await call({ last_word: "must not replace the first request" });
1033
- await invoke("turn.complete", { agentId: "child" });
1079
+ await invoke("turn.complete", turnComplete({ agentId: "child" }));
1034
1080
  assert.equal(resets.length, 0, "neither tool execution nor a child completion resets a running main turn");
1035
- await invoke("turn.complete");
1081
+ await invoke("turn.complete", turnComplete());
1036
1082
  assert.equal(resets.length, 1, "the tool requests a reset even far below the budget threshold");
1037
1083
  assert.deepEqual(origins, ["normal"]);
1038
1084
  assert.ok(NORMAL_CONTINUATIONS.includes(resets[0].messages[1].text));
1039
1085
  assert.deepEqual(resets[0].messages.slice(2).map((row) => row.text), ["*You peel a sticky note off your forehead.*\nnext move: test"]);
1040
1086
  assert.match(resets[0].messages[0].text, /mcp__notesoup__empty_brain/);
1041
1087
  await invoke("turn.start");
1042
- await invoke("turn.complete");
1088
+ await invoke("turn.complete", turnComplete());
1043
1089
  assert.equal(resets.length, 1, "the successful tool request does not leak into the next window");
1044
1090
  const forced = await invoke("session.compact", { trigger: "auto" });
1045
1091
  assert.deepEqual(origins, ["normal", "forced"]);
@@ -1066,7 +1112,7 @@ test("Claude empty_brain refuses unsupported calls without queuing a reset", asy
1066
1112
  assert.equal(refused.isError, true);
1067
1113
  assert.match(refused.result, reason);
1068
1114
  }
1069
- await invoke("turn.complete");
1115
+ await invoke("turn.complete", turnComplete());
1070
1116
  assert.equal(resets, 0);
1071
1117
  });
1072
1118
  test("Claude asks for one handoff per compaction and reuses it when the same window retries", async (t) => {
@@ -1082,7 +1128,7 @@ test("Claude asks for one handoff per compaction and reuses it when the same win
1082
1128
  // Every read path stays pure: no boot, warning, context, or measure draws a handoff.
1083
1129
  await invoke("prompt.context", {}, { blocks: [] });
1084
1130
  await invoke("turn.start");
1085
- await invoke("turn.complete");
1131
+ await invoke("turn.complete", turnComplete());
1086
1132
  assert.equal(draws.length, 0, "only a reset draws, never a read");
1087
1133
  const timers = [];
1088
1134
  const lines = [];
@@ -1099,7 +1145,7 @@ test("Claude asks for one handoff per compaction and reuses it when the same win
1099
1145
  assert.equal((await invoke("command.run", { command: "fresh-window", args: "" })).text, "🥣 Dumping Brain");
1100
1146
  await Promise.resolve();
1101
1147
  await timers.shift()();
1102
- await invoke("turn.complete");
1148
+ await invoke("turn.complete", turnComplete());
1103
1149
  assert.equal(draws.length, 1, "a retried compaction adds no second draw");
1104
1150
  assert.equal(lines.length, 2, "both attempts returned a handoff");
1105
1151
  assert.equal(lines[0], lines[1], "both attempts carry the same artifact's paragraph");
@@ -1120,7 +1166,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
1120
1166
  // Clear the old running-turn and queued-reset state, not just the retained boot.
1121
1167
  let compactions = 0;
1122
1168
  host.session.compact = async () => { compactions++; return {}; };
1123
- await invoke("turn.complete");
1169
+ await invoke("turn.complete", turnComplete());
1124
1170
  assert.equal(compactions, 0, "the old queued reset cannot spill into the new session");
1125
1171
  const fresh = await context();
1126
1172
  assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
@@ -1132,7 +1178,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
1132
1178
  host.process.run = async (argv, init) => { requests.push(JSON.parse(init.stdin)); return run(argv, init); };
1133
1179
  const written = await invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "new-session", address: "session.md", content: action });
1134
1180
  assert.equal(written.result, "created session.md");
1135
- assert.equal(requests[0].identity?.sessionId, `after-${action}`, "tools also use the new session home");
1181
+ assert.equal(requests[0].identity?.sessionId, `after-${action}`, "tools also use the new session notebook");
1136
1182
  });
1137
1183
  }
1138
1184
  });
@@ -1244,9 +1290,9 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
1244
1290
  await write("@model/model.md", "fallback");
1245
1291
  assert.equal(seen.at(-1).identity.model, "claude");
1246
1292
  });
1247
- test("Claude current-cwd project resolution shares Pi's remote home across checkout spellings", async (t) => {
1293
+ test("Claude current-cwd project resolution shares Pi's remote notebook across checkout spellings", async (t) => {
1248
1294
  const { host, home, invoke } = await retainedFixture(t);
1249
- const root = realpathSync(mkdtempSync(join(tmpdir(), "claude-project-home-")));
1295
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "claude-project-notebook-")));
1250
1296
  t.after(() => rmSync(root, { recursive: true, force: true }));
1251
1297
  const first = join(root, "api");
1252
1298
  const second = join(root, "renamed");
@@ -1269,7 +1315,7 @@ test("Claude current-cwd project resolution shares Pi's remote home across check
1269
1315
  assert.equal(written.result, "overwrote @project/shared.md (project api)");
1270
1316
  assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
1271
1317
  assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
1272
- assert.equal(resolveProjectHome(second, home).name, piIdentity.projectKey);
1318
+ assert.equal(resolveProjectNamespace(second, home).name, piIdentity.projectKey);
1273
1319
  });
1274
1320
  test("Claude session.end cannot be undone by an in-flight old reset", async (t) => {
1275
1321
  const { host, invoke, context } = await retainedFixture(t);
@@ -1285,7 +1331,7 @@ test("Claude session.end cannot be undone by an in-flight old reset", async (t)
1285
1331
  return result;
1286
1332
  };
1287
1333
  await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "in-flight" });
1288
- const finishing = invoke("turn.complete");
1334
+ const finishing = invoke("turn.complete", turnComplete());
1289
1335
  await ready;
1290
1336
  await invoke("session.end", { reason: "clear", sessionId: "hook-session" });
1291
1337
  host.session.id = async () => "after-flight";
@@ -1314,7 +1360,7 @@ test("Claude history keeps classic transcript_path across startup, confirms appe
1314
1360
  // Real order: classic -> startup attachment appends -> typed session.start.
1315
1361
  await invoke("session.append", { uuid: "startup" }, { uuid: "startup", message: {} });
1316
1362
  await invoke("session.start", { cwd: home, isInteractive: true });
1317
- assert.equal(registered.length, 9);
1363
+ assert.equal(registered.length, 8);
1318
1364
  const listed = await call("history_list", { roles: ["user", "context"] });
1319
1365
  assert.equal(listed.isError, undefined, listed.result);
1320
1366
  assert.match(listed.result, /old request/);
@@ -1346,7 +1392,7 @@ test("Claude history without a documented path refuses honestly and keeps notes
1346
1392
  const handlers = new Map();
1347
1393
  (await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
1348
1394
  await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async () => ({}));
1349
- const history = await handlers.get("tool.call")(host, { tool: "mcp__notesoup__history_windows", tool_use_id: "history" }, async () => ({}));
1395
+ const history = await handlers.get("tool.call")(host, { tool: "mcp__notesoup__history_list", tool_use_id: "history" }, async () => ({}));
1350
1396
  assert.equal(history.isError, true);
1351
1397
  assert.match(history.result, /transcript_path is unavailable/);
1352
1398
  const notes = await handlers.get("tool.call")(host, { tool: "mcp__notesoup__notes_list", tool_use_id: "notes" }, async () => ({}));
@@ -7,7 +7,7 @@ import { test } from "node:test";
7
7
  import { readCodexHistory } from "../plugins/codex/src/history.js";
8
8
  import { readCodexTranscriptState } from "../plugins/codex/src/transcript.js";
9
9
  import { allItems, eventDocument } from "../src/history/history.js";
10
- import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
10
+ import { historyList, historyRead } from "../src/tools/history.js";
11
11
  /* Producer-shaped synthetic fixtures, not captured/private transcripts.
12
12
  * Frozen official rust-v0.160.1, d27764b82f7118f674371e6d6e76271d9d606edb:
13
13
  * - history/src/{lib.rs,rollout_payload.rs}: flattened JSONL envelope, top-level
@@ -123,14 +123,11 @@ test("two native checkpoints retain old raw history; replacement_history is not
123
123
  assert.equal(second.firstWindowId, W0);
124
124
  assert.deepEqual(allItems(second.projection).filter((i) => i.seq <= 3), allItems(first.projection));
125
125
  assert.doesNotMatch(allItems(second.projection).map(eventDocument).join("\n"), /COPIED CHECKPOINT TEXT/);
126
- const windows = await historyWindows.execute({}, second.projection, second.threadId);
127
- assert.ok(windows.ok);
128
- assert.equal(windows.data.session_id, ROOT);
129
- assert.deepEqual(windows.data.windows.map((w) => [w.window_id, w.first_seq, w.last_seq]), [
126
+ assert.deepEqual(second.projection.windows.map((w) => [w.windowId, w.items[0]?.seq, w.items.at(-1)?.seq]), [
130
127
  [`codex:${ROOT}:${W0}`, 2, 3], [`codex:${ROOT}:${W1}`, 4, 6], [`codex:${ROOT}:${W2}`, 7, 8],
131
128
  ]);
132
- const previous = await historyList.execute({ window_id: "@previous", roles: ["user"] }, second.projection);
133
- assert.match(historyList.render(previous), /middle text/);
129
+ const earlier = await historyList.execute({ after_seq: 3, before_seq: 7, roles: ["user"] }, second.projection);
130
+ assert.match(historyList.render(earlier), /^seq 6 \| user\nmiddle text$/);
134
131
  const old = await historyRead.execute({ seq: 2 }, second.projection);
135
132
  assert.match(historyRead.render(old), /old raw text/);
136
133
  const { projection: _projection, ...facts } = second;
@@ -211,9 +208,6 @@ test("child root session_id isn't thread identity; copied inference prefix isn't
211
208
  const result = await readCodexHistory({ transcriptPath: path, threadId: CHILD });
212
209
  assert.equal(result.rootSessionId, ROOT);
213
210
  assert.equal(result.threadId, CHILD);
214
- const windows = await historyWindows.execute({}, result.projection, result.threadId);
215
- assert.ok(windows.ok);
216
- assert.equal(windows.data.session_id, CHILD);
217
211
  assert.equal(result.model, "child-model");
218
212
  assert.equal(result.currentWindowId, WC);
219
213
  assert.doesNotMatch(allItems(result.projection).map(eventDocument).join("\n"), /INHERITED/);
@@ -11,6 +11,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
11
11
  import { Check } from "typebox/value";
12
12
  import { runHook } from "../plugins/codex/src/hooks.js";
13
13
  import { writeBinding } from "../plugins/codex/src/identity.js";
14
+ import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
14
15
  /* Producer-shaped synthetic fixtures, not captured/private transcripts.
15
16
  * Frozen official rust-v0.160.1, d27764b82f7118f674371e6d6e76271d9d606edb.
16
17
  * Legacy records omit ordinals; a Compacted record names the new native window.
@@ -146,7 +147,7 @@ test("a copied plugin without src or node_modules still initializes and lists al
146
147
  const client = await connect(t, data, join(copy, "dist/codex/notesoup.js"));
147
148
  const listed = await client.listTools();
148
149
  assert.deepEqual(listed.tools.map((tool) => tool.name).sort(), [
149
- "history_list", "history_read", "history_windows",
150
+ "history_list", "history_read",
150
151
  "notes_list", "notes_read", "notes_search", "notes_update", "notes_write",
151
152
  ]);
152
153
  for (const tool of listed.tools) {
@@ -162,7 +163,27 @@ test("a copied plugin without src or node_modules still initializes and lists al
162
163
  assert.match(refusal, /child post-compact boot/);
163
164
  });
164
165
  /* ---------------------------------------------------------------- MCP tools */
165
- test("notes tools use the hook thread as the session home and the current turn model as @model", async (t) => {
166
+ test("bundled Codex MCP reads another harness and wildcard results retain their session identity", async (t) => {
167
+ const f = await fixture(t);
168
+ const roots = isolateHistoryRoots(t, f.home);
169
+ await writePiTranscript(roots.pi, "foreign-pi");
170
+ await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta()), row("response_item", message("user", "Codex needle"))]));
171
+ await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript });
172
+ const client = await connect(t, f.data, CLI, f.home);
173
+ const read = await call(client, { name: "history_read", arguments: { session: "pi:foreign", seq: 1 }, _meta: metaFor(ROOT, ROOT) });
174
+ assert.equal(read.isError, undefined, textOf(read));
175
+ assert.equal(read.structuredContent.session, "pi:foreign-pi");
176
+ assert.match(textOf(read), /^session pi:foreign-pi \| seq 1 \| user/);
177
+ const list = await call(client, { name: "history_list", arguments: { session: "*", query: "needle" }, _meta: metaFor(ROOT, ROOT) });
178
+ assert.equal(list.isError, undefined, textOf(list));
179
+ const page = list.structuredContent;
180
+ assert.deepEqual(new Set(page.items.map((item) => item.session)), new Set([`codex:${ROOT}`, "pi:foreign-pi"]));
181
+ assert.equal(page.page_older, null);
182
+ assert.equal(page.page_newer, null);
183
+ const invalid = await call(client, { name: "history_read", arguments: { session: "*", seq: 1 }, _meta: metaFor(ROOT, ROOT) });
184
+ assert.equal(errorCode(invalid), "invalid_session");
185
+ });
186
+ test("notes tools use the hook thread as the session notebook and the current turn model as @model", async (t) => {
166
187
  const f = await fixture(t);
167
188
  await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta())]));
168
189
  await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript });
@@ -185,6 +206,23 @@ test("notes tools use the hook thread as the session home and the current turn m
185
206
  const listed = await call(client, { name: "notes_list", arguments: { glob: "@model/**" }, _meta: meta });
186
207
  assert.match(textOf(listed), /@model\/model\.md/);
187
208
  });
209
+ test("Codex resolves relative cwd against the verified binding, not the MCP process", async (t) => {
210
+ const f = await fixture(t);
211
+ await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta())]));
212
+ const base = join(f.home, "base"), other = join(f.home, "other");
213
+ await mkdir(base);
214
+ await mkdir(other);
215
+ await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: base, transcriptPath: f.transcript });
216
+ const client = await connect(t, f.data, CLI, f.home);
217
+ const meta = metaFor(ROOT, ROOT);
218
+ const written = await call(client, { name: "notes_write", arguments: { address: "@project/selected", content: "from Codex", cwd: "../other" }, _meta: meta });
219
+ assert.equal(written.isError, undefined, textOf(written));
220
+ assert.equal(written.structuredContent.project_key, "other");
221
+ assert.match(readFileSync(join(f.home, "project", "other", "selected.md"), "utf8"), /from Codex/);
222
+ const read = await call(client, { name: "notes_read", arguments: { address: "@project/selected", cwd: "../other" }, _meta: meta });
223
+ assert.equal(read.isError, undefined, textOf(read));
224
+ assert.equal(read.structuredContent.text, "from Codex");
225
+ });
188
226
  test("refusals precede reads and writes: unknown thread, stale root, bad model, bad params", async (t) => {
189
227
  const f = await fixture(t);
190
228
  await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta())]));
@@ -239,12 +277,10 @@ test("history tools serve root and child native ancestry, and refuse stale nativ
239
277
  await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript, windowId: W1 });
240
278
  const client = await connect(t, f.data, CLI, f.home);
241
279
  const meta = metaFor(ROOT, ROOT, "gpt-5.1-codex", W1);
242
- const windows = await call(client, { name: "history_windows", arguments: {}, _meta: meta });
243
- assert.equal(windows.isError, undefined);
244
- assert.equal(windows.structuredContent.session_id, ROOT);
245
- assert.deepEqual(windows.structuredContent.windows.map((w) => w.window_id), [`codex:${ROOT}:${W0}`, `codex:${ROOT}:${W1}`]);
246
280
  const page = await call(client, { name: "history_list", arguments: {}, _meta: meta });
247
- assert.match(textOf(page), /root after/);
281
+ assert.equal(page.isError, undefined);
282
+ assert.match(textOf(page), /seq 2 \| user\nroot before/);
283
+ assert.match(textOf(page), /seq 4 \| user\nroot after/);
248
284
  const read = await call(client, { name: "history_read", arguments: { seq: 4 }, _meta: meta });
249
285
  assert.match(textOf(read), /root after/);
250
286
  const childPath = join(dirname(f.transcript), nativeName(CHILD));
@@ -253,10 +289,12 @@ test("history tools serve root and child native ancestry, and refuse stale nativ
253
289
  row("response_item", message("user", "child task")),
254
290
  ]));
255
291
  await bind(f.data, { threadId: CHILD, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: childPath, agent: "worker", agentType: "worker" });
256
- const childWindows = await call(client, { name: "history_windows", arguments: {}, _meta: metaFor(CHILD, ROOT) });
257
- assert.equal(childWindows.structuredContent.session_id, CHILD);
258
- assert.match(textOf(childWindows), new RegExp(`codex:${CHILD}`));
259
- assert.doesNotMatch(textOf(childWindows), new RegExp(`codex:${ROOT}`));
292
+ const invalidFilter = await call(client, { name: "history_list", arguments: { window_id: "anything" }, _meta: meta });
293
+ assert.equal(errorCode(invalidFilter), "invalid_params");
294
+ const childHistory = await call(client, { name: "history_list", arguments: {}, _meta: metaFor(CHILD, ROOT) });
295
+ assert.equal(childHistory.isError, undefined);
296
+ assert.match(textOf(childHistory), /^seq 2 \| user\nchild task$/);
297
+ assert.doesNotMatch(textOf(childHistory), /root before|root after/);
260
298
  const other = join(dirname(f.transcript), nativeName("019a0000-0000-7000-8000-000000000077"));
261
299
  await writeFile(other, jsonl([row("session_meta", sessionMeta(CHILD, { session_id: "019a0000-0000-7000-8000-000000000088" })), row("response_item", message("user", "elsewhere"))]));
262
300
  await bind(f.data, { threadId: CHILD, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: other });
@@ -282,7 +320,7 @@ test("a root boot carries the native window, native reset names, and is deduped
282
320
  assert.match(boot, new RegExp(`Agent name: anonymous \\(brain: gpt-5-4\\)`));
283
321
  assert.match(boot, new RegExp(`codex:${ROOT}`));
284
322
  assert.match(boot, new RegExp(`<notesoup:codex_window>\\nthread: ${ROOT}\\nwindow: ${W0}`));
285
- // The shared trunk:shortname rule renders the same address history tools serve.
323
+ // The boot tree still labels its native current window.
286
324
  assert.match(boot, new RegExp(`${W0} {4}← you are here`));
287
325
  assert.match(boot, /native `new_context`/);
288
326
  assert.match(boot, /get_context_remaining/);