notesoup 0.61.0 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -11
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +24 -5
  10. package/dist/plugins/claude/src/text.d.ts +7 -0
  11. package/dist/plugins/claude/src/text.js +12 -1
  12. package/dist/plugins/codex/src/hooks.js +1 -0
  13. package/dist/plugins/codex/src/identity.d.ts +6 -1
  14. package/dist/plugins/codex/src/identity.js +13 -1
  15. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  16. package/dist/plugins/codex/src/mcp.js +26 -88
  17. package/dist/plugins/codex/src/text.js +3 -3
  18. package/dist/plugins/dsh/tools.js +8 -4
  19. package/dist/plugins/mcp/operations.d.ts +15 -0
  20. package/dist/plugins/mcp/operations.js +43 -0
  21. package/dist/plugins/mcp/server.d.ts +14 -0
  22. package/dist/plugins/mcp/server.js +13 -0
  23. package/dist/plugins/pi/budget.d.ts +4 -1
  24. package/dist/plugins/pi/budget.js +35 -8
  25. package/dist/plugins/pi/entries.d.ts +2 -0
  26. package/dist/plugins/pi/entries.js +2 -0
  27. package/dist/plugins/pi/history-tools.js +2 -1
  28. package/dist/plugins/pi/history.js +18 -1
  29. package/dist/plugins/pi/notes/tools.js +7 -3
  30. package/dist/plugins/pi/render.d.ts +7 -1
  31. package/dist/plugins/pi/render.js +2 -2
  32. package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
  33. package/dist/plugins/pi/reset/artifacts.js +4 -4
  34. package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
  35. package/dist/plugins/pi/reset/lifecycle.js +109 -31
  36. package/dist/plugins/pi/runtime.js +104 -63
  37. package/dist/plugins/pi/tool-result.js +7 -7
  38. package/dist/plugins/pi/window.d.ts +25 -3
  39. package/dist/plugins/pi/window.js +219 -9
  40. package/dist/src/boot/render.js +18 -15
  41. package/dist/src/boot/text.d.ts +3 -1
  42. package/dist/src/boot/text.js +22 -20
  43. package/dist/src/budget/text.d.ts +7 -3
  44. package/dist/src/budget/text.js +24 -15
  45. package/dist/src/history/claude.d.ts +2 -0
  46. package/dist/src/history/claude.js +46 -0
  47. package/dist/src/history/codex-transcript.js +7 -5
  48. package/dist/src/history/codex.js +3 -0
  49. package/dist/src/history/corpus.d.ts +28 -1
  50. package/dist/src/history/corpus.js +40 -0
  51. package/dist/src/history/history.d.ts +37 -46
  52. package/dist/src/history/history.js +21 -40
  53. package/dist/src/history/local.js +67 -32
  54. package/dist/src/history/pi.d.ts +2 -1
  55. package/dist/src/history/pi.js +122 -48
  56. package/dist/src/history/prefilter.js +76 -19
  57. package/dist/src/history/query.d.ts +28 -49
  58. package/dist/src/history/query.js +83 -68
  59. package/dist/src/history/summary-cache.d.ts +8 -1
  60. package/dist/src/history/summary-cache.js +138 -12
  61. package/dist/src/index.d.ts +2 -2
  62. package/dist/src/index.js +1 -1
  63. package/dist/src/notes/errors.d.ts +1 -1
  64. package/dist/src/notes/frontmatter.d.ts +0 -2
  65. package/dist/src/notes/frontmatter.js +0 -2
  66. package/dist/src/notes/index.d.ts +1 -1
  67. package/dist/src/notes/index.js +1 -1
  68. package/dist/src/notes/policy.d.ts +15 -1
  69. package/dist/src/notes/policy.js +46 -5
  70. package/dist/src/notes/store.d.ts +12 -0
  71. package/dist/src/notes/store.js +16 -20
  72. package/dist/src/text-match.d.ts +10 -1
  73. package/dist/src/text-match.js +42 -3
  74. package/dist/src/tools/dream.d.ts +22 -93
  75. package/dist/src/tools/dream.js +30 -27
  76. package/dist/src/tools/history.d.ts +33 -26
  77. package/dist/src/tools/history.js +257 -163
  78. package/dist/src/tools/notes.d.ts +51 -163
  79. package/dist/src/tools/notes.js +146 -100
  80. package/dist/src/tools/output.d.ts +2 -1
  81. package/dist/src/tools/output.js +2 -1
  82. package/dist/src/tools/result.d.ts +4 -7
  83. package/dist/src/tools/result.js +8 -9
  84. package/dist/src/tools/schema.d.ts +4 -1
  85. package/dist/src/tools/schema.js +25 -1
  86. package/dist/test/agent-loop.test.js +394 -56
  87. package/dist/test/antigravity-live.test.d.ts +1 -0
  88. package/dist/test/antigravity-live.test.js +142 -0
  89. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  90. package/dist/test/antigravity-plugin.test.js +101 -0
  91. package/dist/test/boot.integration.test.js +156 -15
  92. package/dist/test/budget-settings.integration.test.js +4 -4
  93. package/dist/test/claude-history.test.js +14 -13
  94. package/dist/test/claude-mod.test.js +199 -16
  95. package/dist/test/claude-validation.test.js +69 -2
  96. package/dist/test/codex-history.test.js +15 -3
  97. package/dist/test/codex-plugin.test.js +76 -38
  98. package/dist/test/dependencies.test.js +7 -3
  99. package/dist/test/dream-skill.test.js +3 -3
  100. package/dist/test/dream-tools.test.js +101 -56
  101. package/dist/test/dsh.test.js +34 -19
  102. package/dist/test/helpers/dependency-graph.js +2 -2
  103. package/dist/test/helpers/extension.d.ts +68 -3
  104. package/dist/test/helpers/extension.js +74 -5
  105. package/dist/test/history-corpus.test.js +79 -77
  106. package/dist/test/history-summary-cache.test.js +97 -9
  107. package/dist/test/history.integration.test.js +234 -168
  108. package/dist/test/host-neutral.test.js +69 -19
  109. package/dist/test/marker.test.js +1 -1
  110. package/dist/test/model-facing-text.test.js +13 -3
  111. package/dist/test/note-policy.test.js +96 -77
  112. package/dist/test/notes.integration.test.js +212 -94
  113. package/dist/test/notes.test.js +184 -113
  114. package/dist/test/pi-render.test.js +20 -12
  115. package/dist/test/project-namespace.test.js +3 -2
  116. package/dist/test/reset-lifecycle.test.js +12 -2
  117. package/docs/antigravity.md +44 -0
  118. package/docs/architecture.md +6 -4
  119. package/docs/claude-code-mod.md +7 -7
  120. package/docs/codex.md +36 -38
  121. package/docs/dsh.md +3 -3
  122. package/docs/history-sessions.md +28 -50
  123. package/docs/notes-library.md +4 -4
  124. package/docs/reset-lifecycle.md +1 -1
  125. package/docs/skills.md +3 -3
  126. package/docs/tool-results.md +47 -28
  127. package/package.json +3 -2
  128. package/playbook.md +1 -1
  129. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  130. package/plugins/antigravity/hooks.json +7 -0
  131. package/plugins/antigravity/mcp_config.json +8 -0
  132. package/plugins/antigravity/plugin.json +6 -0
  133. package/plugins/antigravity/src/cli.ts +22 -0
  134. package/plugins/antigravity/src/hooks.ts +51 -0
  135. package/plugins/antigravity/src/identity.ts +127 -0
  136. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  137. package/plugins/claude/dist/claude/helper.js +1108 -539
  138. package/plugins/claude/hooks/register.ts +202 -62
  139. package/plugins/claude/playbook.md +1 -1
  140. package/plugins/claude/skills/dream/SKILL.md +1 -1
  141. package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
  142. package/plugins/claude/src/helper.ts +24 -5
  143. package/plugins/claude/src/text.ts +14 -1
  144. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  145. package/plugins/codex/.mcp.json +11 -0
  146. package/plugins/codex/README.md +5 -21
  147. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  148. package/plugins/codex/src/hooks.ts +1 -0
  149. package/plugins/codex/src/identity.ts +14 -1
  150. package/plugins/codex/src/mcp.ts +28 -98
  151. package/plugins/codex/src/text.ts +3 -3
  152. package/plugins/dsh/tools.ts +8 -4
  153. package/plugins/mcp/operations.ts +50 -0
  154. package/plugins/mcp/server.ts +23 -0
  155. package/plugins/paseo/README.md +5 -10
  156. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  157. package/plugins/paseo/client/markdown.tsx +50 -38
  158. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  159. package/plugins/paseo/client/paper-card.tsx +6 -5
  160. package/plugins/paseo/client/paper-palette.ts +2 -9
  161. package/plugins/paseo/client/sticky-card.tsx +2 -2
  162. package/plugins/paseo/client/tool-result.ts +7 -14
  163. package/plugins/paseo/package-lock.json +3406 -0
  164. package/plugins/paseo/package.json +1 -0
  165. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  166. package/plugins/pi/budget.ts +31 -8
  167. package/plugins/pi/entries.ts +2 -0
  168. package/plugins/pi/history-tools.ts +2 -1
  169. package/plugins/pi/history.ts +30 -1
  170. package/plugins/pi/notes/tools.ts +7 -3
  171. package/plugins/pi/render.ts +6 -6
  172. package/plugins/pi/reset/artifacts.ts +4 -3
  173. package/plugins/pi/reset/lifecycle.ts +125 -32
  174. package/plugins/pi/runtime.ts +98 -62
  175. package/plugins/pi/tool-result.ts +8 -8
  176. package/plugins/pi/window.ts +210 -10
  177. package/skills/dream/SKILL.md +1 -1
  178. package/skills/notesoup-guide/SKILL.md +92 -0
  179. package/src/boot/render.ts +18 -15
  180. package/src/boot/text.ts +23 -19
  181. package/src/budget/text.ts +27 -15
  182. package/src/history/claude.ts +41 -0
  183. package/src/history/codex-transcript.ts +6 -4
  184. package/src/history/codex.ts +2 -0
  185. package/src/history/corpus.ts +51 -2
  186. package/src/history/history.ts +35 -44
  187. package/src/history/local.ts +67 -27
  188. package/src/history/pi.ts +113 -35
  189. package/src/history/prefilter.ts +73 -15
  190. package/src/history/query.ts +93 -73
  191. package/src/history/summary-cache.ts +142 -17
  192. package/src/index.ts +2 -2
  193. package/src/notes/errors.ts +1 -1
  194. package/src/notes/frontmatter.ts +0 -3
  195. package/src/notes/index.ts +1 -1
  196. package/src/notes/policy.ts +44 -5
  197. package/src/notes/store.ts +17 -20
  198. package/src/text-match.ts +46 -4
  199. package/src/tools/dream.ts +29 -31
  200. package/src/tools/history.ts +249 -142
  201. package/src/tools/notes.ts +145 -113
  202. package/src/tools/output.ts +2 -1
  203. package/src/tools/result.ts +12 -11
  204. package/src/tools/schema.ts +24 -1
  205. package/plugins/claude/skills/memory/SKILL.md +0 -69
  206. package/plugins/codex/mcp.json +0 -10
  207. package/plugins/codex/plugin.json +0 -6
  208. package/plugins/paseo/client/markdown-core.tsx +0 -189
  209. package/plugins/paseo/client/typography.ts +0 -24
  210. package/skills/memory/SKILL.md +0 -69
@@ -3,19 +3,20 @@ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import test from "node:test";
6
- import { createAssistantMessageEventStream, getCurrentSystemMessage, getSystemMessageText } from "@earendil-works/pi-ai";
6
+ import { createAssistantMessageEventStream, getCurrentSystemMessage, getCurrentTools, getSystemMessageText } from "@earendil-works/pi-ai";
7
7
  import { createAgentSession, convertToLlm, createCodemodeExtension, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
8
8
  import notesoup, { createNotesoup } from "../plugins/pi/extension.js";
9
- import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
9
+ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, ENABLED_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
10
10
  import { historyFromSession } from "../plugins/pi/history.js";
11
11
  import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
12
+ import { NOTESOUP_TOOL_NAMES, rootWindowId } from "../plugins/pi/window.js";
12
13
  import { assertBootHistory } from "./helpers/extension.js";
13
14
  import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NAMELESS_AGENT, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
14
15
  import { createNotesStore } from "../src/notes/index.js";
15
16
  import { agentSlug } from "../plugins/pi/notes/adapter.js";
16
17
  import { registerBudget } from "../plugins/pi/budget.js";
17
18
  import { estimateContextTokens } from "../plugins/pi/estimate.js";
18
- import { FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
19
+ import { BETWEEN_TURNS_CONTINUATIONS, FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
19
20
  import { commandWarningContent, PI_PRE_RESET_HINTS } from "../plugins/pi/text.js";
20
21
  import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE } from "../plugins/pi/tool-result.js";
21
22
  async function openFixture(options) {
@@ -76,7 +77,8 @@ async function openFixture(options) {
76
77
  agentDir,
77
78
  settingsManager,
78
79
  noExtensions: true,
79
- noSkills: true,
80
+ noSkills: options.skillPaths === undefined,
81
+ additionalSkillPaths: options.skillPaths,
80
82
  noThemes: true,
81
83
  noPromptTemplates: true,
82
84
  systemPromptOverride: () => options.systemPrompt ?? "Use the tools as requested.",
@@ -130,6 +132,7 @@ async function openFixture(options) {
130
132
  return stream;
131
133
  };
132
134
  await session.bindExtensions({
135
+ mode: options.mode,
133
136
  uiContext: {
134
137
  notify(message) {
135
138
  notices.push(message);
@@ -193,7 +196,7 @@ function text(message) {
193
196
  return JSON.stringify(message?.messages ?? []);
194
197
  }
195
198
  /** `text()` serializes to JSON, so match the reset prose in its escaped form. */
196
- const CONTINUATION_JSON_LINES = [...NORMAL_CONTINUATIONS, ...FORCED_CONTINUATIONS].map((line) => JSON.stringify(line).slice(1, -1));
199
+ const CONTINUATION_JSON_LINES = [...NORMAL_CONTINUATIONS, ...FORCED_CONTINUATIONS, ...BETWEEN_TURNS_CONTINUATIONS].map((line) => JSON.stringify(line).slice(1, -1));
197
200
  /** How many distinct reset paragraphs a serialized request carries; one fresh window carries one. */
198
201
  function continuationLinesIn(body) {
199
202
  return CONTINUATION_JSON_LINES.filter((line) => body.includes(line));
@@ -241,6 +244,9 @@ test("real AgentSession: turn-end markers reach tool continuations and allow one
241
244
  : assistant(fixture, [{ type: "text", text: "steered input handled" }]),
242
245
  });
243
246
  try {
247
+ // Seed the root boot explicitly so the marker interval starts at a stable anchor;
248
+ // lazy boot placement is covered by its own tests below.
249
+ fixture.sessionManager.appendCustomMessageEntry(BOOT_TYPE, "seed boot", false, { windowId: rootWindowId(fixture.sessionManager.getSessionId()) });
244
250
  for (let i = 0; i < seedCount; i++)
245
251
  fixture.sessionManager.appendMessage(assistant(fixture, [{ type: "text", text: "seed" }]));
246
252
  await fixture.session.prompt("MARKER_INITIAL_USER");
@@ -378,12 +384,12 @@ test("real AgentSession: identity changes update system teaching and the next bo
378
384
  process.env.NOTESOUP_AGENT = previousAgent;
379
385
  }
380
386
  });
381
- test("real Pi codemode receives typed notes/history outcomes, including expected errors", async () => {
387
+ test("real Pi codemode receives strings except structured notes_read, including refusals", async () => {
382
388
  let fixture;
383
389
  fixture = await openFixture({
384
390
  codemode: true,
385
391
  compactionEnabled: false,
386
- tools: ["codemode", "notes_write", "notes_read", "notes_list", "history_list", "history_read"],
392
+ tools: ["codemode", "notes_write", "notes_read", "notes_list", "history_list", "history_read", "history_search"],
387
393
  script: (request) => {
388
394
  if (request === 1)
389
395
  return assistant(fixture, [{ type: "toolCall", id: "structured-smoke", name: "codemode", arguments: { code: `
@@ -391,35 +397,38 @@ const written = await tools.notes_write({ address: "smoke.md", content: "A😀
391
397
  const listed = await tools.notes_list({});
392
398
  const read = await tools.notes_read({ address: "smoke.md", offset_chars: 1, max_chars: 2 });
393
399
  const refused = await tools.notes_read({ address: "missing.md" });
394
- if ("error" in written || "error" in listed || "error" in read || !("error" in refused)) throw new Error("wrong outcome");
400
+ if (typeof written !== "string" || !written.includes("smoke.md") || typeof listed !== "string" || !listed.includes("smoke.md")) throw new Error("wrong text outcomes");
395
401
  if (read.text !== "😀界" || read.next_offset_chars !== 3) throw new Error("wrong window");
396
402
  if (refused.code !== "not_found") throw new Error("missing typed refusal");
397
- text({ marker: "TYPED_SMOKE", files: listed.files.map(f => f.address), body: read.text, error: refused.code });
403
+ let plainRefusal;
404
+ try { await tools.notes_write({ address: "../invalid", content: "no" }); }
405
+ catch (error) { plainRefusal = String(error); }
406
+ if (!plainRefusal || !plainRefusal.includes("invalid_address")) throw new Error("missing text refusal");
407
+ text({ marker: "TYPED_SMOKE", body: read.text, error: refused.code });
398
408
  ` } }], "toolUse");
399
409
  if (request === 2)
400
410
  return assistant(fixture, [{ type: "toolCall", id: "structured-history-smoke", name: "codemode", arguments: { code: `
401
411
  const page = await tools.history_list({ roles: ["tool"] });
402
- if ("error" in page) throw new Error("history list failed");
403
- const parent = page.items.find(item => item.tool === "codemode");
412
+ if (typeof page !== "string") throw new Error("history list must be text");
413
+ const parent = /seq (\\d+) \\| tool(?: \\| [^|\\n]+)?\\ntool codemode/.exec(page);
404
414
  if (!parent) throw new Error("missing codemode parent");
405
- const read = await tools.history_read({ seq: parent.seq });
406
- if ("error" in read || read.tool !== "codemode") throw new Error("missing typed tool summary");
407
- const calls = read.nested_calls;
408
- if (!calls || !read.text.includes("notes_read [error]")) throw new Error("missing nested refusal evidence");
409
- text({ marker: "HISTORY_SMOKE", calls: calls.call_count, complete: calls.complete });
415
+ const read = await tools.history_read({ seq: Number(parent[1]) });
416
+ if (typeof read !== "string" || !read.includes("tool codemode")) throw new Error("missing tool summary");
417
+ if (!read.includes("nested calls 5 recorded, complete") || !read.includes("notes_read [error]")) throw new Error("missing nested refusal evidence");
418
+ text({ marker: "HISTORY_SMOKE" });
410
419
  ` } }], "toolUse");
411
420
  return assistant(fixture, [{ type: "text", text: "structured smoke complete" }]);
412
421
  },
413
422
  });
414
423
  try {
415
- await fixture.session.prompt("Exercise the structured tools through real codemode.");
424
+ await fixture.session.prompt("Exercise notes and history through real codemode.");
416
425
  const results = fixture.sessionManager.getBranch().flatMap(entry => entry.type === "message" && entry.message.role === "toolResult" ? [entry.message] : []);
417
426
  assert.equal(results.length, 2, "nested calls are not separate transcript events");
418
427
  assert.ok(results.every(result => !result.isError), JSON.stringify(results));
419
428
  const output = results.map(result => result.content.filter(part => part.type === "text").map(part => part.text).join("\n")).join("\n");
420
429
  assert.match(output, /TYPED_SMOKE/);
421
430
  assert.match(output, /HISTORY_SMOKE/);
422
- assert.equal(results[0].nestedCalls?.calls.length, 4);
431
+ assert.equal(results[0].nestedCalls?.calls.length, 5);
423
432
  assert.equal(results[0].nestedCalls?.complete, true);
424
433
  }
425
434
  finally {
@@ -794,7 +803,7 @@ test("real AgentSession: streaming clear prompt keeps the first request", async
794
803
  fixture.close();
795
804
  }
796
805
  });
797
- test("real AgentSession: hard-reserve reset continues without replaying its original text or image, including pre-send oversized input", async () => {
806
+ test("real AgentSession: mid-turn hard-reserve reset continues without replaying its original text or image, including pre-send oversized input", async () => {
798
807
  let fixture;
799
808
  const input = "HARD_RESERVE_IMAGE_INPUT";
800
809
  const oversized = `PRE_SEND_OVERSIZED_${"x".repeat(100_000)}`;
@@ -803,7 +812,7 @@ test("real AgentSession: hard-reserve reset continues without replaying its orig
803
812
  defaultReserveTokens: 80_000,
804
813
  script: (request, context) => {
805
814
  if (request === 1)
806
- return assistant(fixture, [{ type: "text", text: "reserve reached" }], "stop", { usage: usage(80_000) });
815
+ return assistant(fixture, [{ type: "toolCall", id: "hr-tool", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(80_000) });
807
816
  if (request === 2) {
808
817
  assertFreshRequest(fixture, 1, input);
809
818
  assert.equal(context.messages.some((message) => message.role === "user" && Array.isArray(message.content) && message.content.some((block) => block.type === "image")), false);
@@ -835,6 +844,125 @@ test("real AgentSession: hard-reserve reset continues without replaying its orig
835
844
  fixture.close();
836
845
  }
837
846
  });
847
+ test("real AgentSession: TUI clean final answer stays visible, rolls over cleanly on next input (including near-reserve pushes and /skill expansion), and preserves oversized pastes in history", async () => {
848
+ let fixture;
849
+ const skillDir = mkdtempSync(join(tmpdir(), "notesoup-turnover-skill-"));
850
+ mkdirSync(join(skillDir, "expand-check"), { recursive: true });
851
+ writeFileSync(join(skillDir, "expand-check", "SKILL.md"), "---\nname: expand-check\ndescription: verifies skill expansion across turnover\n---\nSKILL_BODY_EXPANDED_TOKEN\n");
852
+ const image = { type: "image", data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC", mimeType: "image/png" };
853
+ const boundaryPush = `BOUNDARY_PUSH_${"a".repeat(4_000)}`;
854
+ const oversized = `DEFERRED_OVERSIZED_${"x".repeat(100_000)}`;
855
+ fixture = await openFixture({
856
+ mode: "tui",
857
+ skillPaths: [skillDir],
858
+ defaultReserveTokens: 80_000,
859
+ script: (request, context) => {
860
+ if (request === 1)
861
+ return assistant(fixture, [{ type: "text", text: "VISIBLE_FINAL_ANSWER" }], "stop", { usage: usage(80_000) });
862
+ if (request === 2) {
863
+ assertFreshRequest(fixture, 1, "VISIBLE_FINAL_ANSWER");
864
+ assert.ok(text(context).includes("NEXT_HUMAN_FOLLOWUP"), "next human prompt reaches the fresh window directly");
865
+ assert.ok(context.messages.some((message) => message.role === "user" && Array.isArray(message.content) && message.content.some((block) => block.type === "image")), "attached image crosses cleanly");
866
+ // Just 500 tokens above reserve (remaining = 80_500 > 80_000), so the next ~1k-token message pushes over reserve.
867
+ return assistant(fixture, [{ type: "text", text: "NEAR_RESERVE_ANSWER" }], "stop", { usage: usage(19_500) });
868
+ }
869
+ if (request === 3) {
870
+ assertFreshRequest(fixture, 2, "NEAR_RESERVE_ANSWER");
871
+ assert.ok(text(context).includes("BOUNDARY_PUSH_"), "normal message pushing past reserve rolls over cleanly into the fresh window instead of burying itself in history");
872
+ return assistant(fixture, [{ type: "text", text: "BEFORE_SKILL_ANSWER" }], "stop", { usage: usage(80_000) });
873
+ }
874
+ if (request === 4) {
875
+ assertFreshRequest(fixture, 3, "BEFORE_SKILL_ANSWER");
876
+ assert.ok(text(context).includes("SKILL_BODY_EXPANDED_TOKEN"), "/skill commands expand cleanly after TUI between-turns turnover");
877
+ return assistant(fixture, [{ type: "text", text: "AFTER_SKILL_ANSWER" }], "stop", { usage: usage(80_000) });
878
+ }
879
+ assert.equal(request, 5, "oversized prompt falls back to pre-send history reset without extra provider call");
880
+ assertFreshRequest(fixture, 4, "DEFERRED_OVERSIZED_");
881
+ return assistant(fixture, [{ type: "text", text: "handled oversized from history" }]);
882
+ },
883
+ });
884
+ try {
885
+ await fixture.session.prompt("FIRST_QUESTION");
886
+ await fixture.session.waitForIdle();
887
+ assert.equal(fixture.requests.length, 1, "no ghost continuation after a clean final answer");
888
+ assert.equal(resetMarkers(fixture).length, 0, "final answer stays visible in TUI instead of wiping immediately");
889
+ assert.ok(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("VISIBLE_FINAL_ANSWER"));
890
+ await fixture.session.prompt("NEXT_HUMAN_FOLLOWUP", { images: [image] });
891
+ await fixture.session.waitForIdle();
892
+ assert.equal(fixture.requests.length, 2, "turnover costs zero extra provider requests");
893
+ assert.equal(resetMarkers(fixture).length, 1);
894
+ const firstMarker = resetMarkers(fixture)[0];
895
+ assert.equal(firstMarker.data.origin, "forced");
896
+ assert.equal(firstMarker.data.betweenTurns, true);
897
+ const continuations = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
898
+ assert.ok(BETWEEN_TURNS_CONTINUATIONS.includes(String(continuations[0].content)), "between-turns turnover uses the honest between-turns pool");
899
+ assert.equal(fixture.notices.some((n) => n.includes("overflow") || n.includes("Brain almost full")), false, "clean between-turns rollover does not flash an overflow or warning toast");
900
+ const userCopies = fixture.sessionManager.getBranch().filter((entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("NEXT_HUMAN_FOLLOWUP"));
901
+ assert.equal(userCopies.length, 1, "withheld user message is recorded once as a real user entry in the fresh window");
902
+ // Near-reserve boundary push (~1k tokens when remaining is reserve + 500) rotates cleanly instead of tripping pre-send overflow.
903
+ await fixture.session.prompt(boundaryPush);
904
+ await fixture.session.waitForIdle();
905
+ assert.equal(fixture.requests.length, 3);
906
+ assert.equal(resetMarkers(fixture).length, 2);
907
+ assert.equal(resetMarkers(fixture)[1].data.betweenTurns, true);
908
+ assert.equal(fixture.notices.some((n) => n.includes("overflow")), false);
909
+ // /skill command right after a full window preserves template/skill expansion.
910
+ await fixture.session.prompt("/skill:expand-check");
911
+ await fixture.session.waitForIdle();
912
+ assert.equal(fixture.requests.length, 4);
913
+ assert.equal(resetMarkers(fixture).length, 3);
914
+ assert.equal(fixture.notices.some((n) => n.includes("overflow")), false);
915
+ // Oversized prompt falls back to pre-send history reset.
916
+ await fixture.session.prompt(oversized);
917
+ await fixture.session.waitForIdle();
918
+ assert.equal(fixture.requests.length, 5);
919
+ assert.equal(resetMarkers(fixture).length, 4);
920
+ const oversizedEntry = fixture.sessionManager.getBranch().find((entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("DEFERRED_OVERSIZED_"));
921
+ assert.ok(oversizedEntry, "oversized follow-up is preserved in raw history rather than carried verbatim into the fresh window");
922
+ }
923
+ finally {
924
+ fixture.close();
925
+ rmSync(skillDir, { recursive: true, force: true });
926
+ }
927
+ });
928
+ test("real AgentSession: RPC clean final answer rotates quietly at turn_end without breaking prompt disposition or splitting agent_settled", async () => {
929
+ let fixture;
930
+ fixture = await openFixture({
931
+ mode: "rpc",
932
+ defaultReserveTokens: 80_000,
933
+ script: (request, context) => {
934
+ if (request === 1)
935
+ return assistant(fixture, [{ type: "text", text: "RPC_FIRST_ANSWER" }], "stop", { usage: usage(80_000) });
936
+ assert.equal(request, 2);
937
+ assertFreshRequest(fixture, 1, "RPC_FIRST_ANSWER");
938
+ assert.ok(text(context).includes("RPC_SECOND_QUESTION"));
939
+ return assistant(fixture, [{ type: "text", text: "RPC_SECOND_ANSWER" }]);
940
+ },
941
+ });
942
+ try {
943
+ await fixture.session.prompt("RPC_FIRST_QUESTION", { source: "rpc" });
944
+ assert.equal(fixture.requests.length, 1, "no ghost continuation after clean final answer in RPC");
945
+ assert.equal(resetMarkers(fixture).length, 1, "non-TUI mode rotates quietly right at turn_end");
946
+ const marker = resetMarkers(fixture)[0];
947
+ assert.equal(marker.data.origin, "forced");
948
+ assert.equal(marker.data.betweenTurns, true);
949
+ const continuations = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
950
+ assert.ok(BETWEEN_TURNS_CONTINUATIONS.includes(String(continuations[0].content)));
951
+ assert.equal(fixture.notices.some((n) => n.includes("overflow")), false, "quiet between-turns rotation does not flash overflow");
952
+ const settledBefore = fixture.events.filter((e) => e.type === "agent_settled").length;
953
+ let disposition;
954
+ await fixture.session.prompt("RPC_SECOND_QUESTION", {
955
+ source: "rpc",
956
+ preflightResult: (value) => { disposition = value; },
957
+ });
958
+ assert.equal(disposition, "started", "next RPC prompt starts directly without input interception");
959
+ assert.equal(fixture.requests.length, 2, "await session.prompt resolves only after the assistant replies");
960
+ assert.equal(fixture.events.filter((e) => e.type === "agent_settled").length - settledBefore, 1, "exactly one agent_settled for the second RPC turn");
961
+ }
962
+ finally {
963
+ fixture.close();
964
+ }
965
+ });
838
966
  test("real AgentSession: manual hard-reserve reset stops clean and mixed-tool turns without fresh provider work", async () => {
839
967
  for (const mixed of [false, true]) {
840
968
  let fixture;
@@ -1377,7 +1505,7 @@ test("real AgentSession: new input queued while a forced reset commits is delive
1377
1505
  script: (request) => {
1378
1506
  if (request === 1)
1379
1507
  return boundaryEvent === "turn_end"
1380
- ? assistant(fixture, [{ type: "text", text: "reserve reached" }], "stop", { usage: usage(80_000) })
1508
+ ? assistant(fixture, [{ type: "toolCall", id: "hr-queue", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(80_000) })
1381
1509
  : assistant(fixture, [], "error", { errorMessage: "Prompt too long: context exceeds maximum context length" });
1382
1510
  return assistant(fixture, [{ type: "text", text: "new input handled" }]);
1383
1511
  },
@@ -1555,39 +1683,74 @@ test("real AgentSession: overflow and recoverable length continue once without r
1555
1683
  repeated.close();
1556
1684
  }
1557
1685
  });
1558
- test("real AgentSession: a smaller-model overflow continues on that model without replaying submitted input", async () => {
1559
- let fixture;
1560
- fixture = await openFixture({
1561
- contextWindow: 200_000,
1562
- script: (request, context) => {
1563
- if (request === 1)
1564
- return assistant(fixture, [{ type: "text", text: "LARGE_MODEL_HISTORY" }], "stop", { usage: usage(150_000) });
1565
- if (request === 2)
1566
- return assistant(fixture, [], "error", { errorMessage: "Prompt too long: context exceeds maximum context length" });
1567
- assert.equal(request, 3);
1568
- assert.equal(text(context).includes("CONTINUE_AFTER_MODEL_SWITCH"), false);
1569
- return assistant(fixture, [{ type: "text", text: "continued on smaller model" }]);
1570
- },
1571
- });
1572
- try {
1573
- await fixture.session.prompt("LARGE_MODEL_TASK");
1574
- await fixture.session.waitForIdle();
1575
- assert.equal(resetMarkers(fixture).length, 0, "150k fits the original model's reserve");
1576
- const smaller = { ...fixture.model, id: `${fixture.model.id}-small`, contextWindow: 100_000 };
1577
- fixture.model = smaller;
1578
- await fixture.session.setModel(smaller, { persist: false });
1579
- await fixture.session.prompt("CONTINUE_AFTER_MODEL_SWITCH");
1580
- await fixture.session.waitForIdle();
1581
- assert.equal(resetMarkers(fixture).length, 1, "model downgrade overflow commits one reset");
1582
- assert.equal(fixture.requests.length, 3, "one failed small-model request and one recovery request");
1583
- assert.equal(fixture.session.model?.id, smaller.id, "recovery stays on the selected model");
1584
- assertFreshRequest(fixture, 2, "LARGE_MODEL_HISTORY");
1585
- assertFreshRequest(fixture, 2, "CONTINUE_AFTER_MODEL_SWITCH");
1586
- assert.ok(FORCED_CONTINUATIONS.some((line) => text(fixture.requests[2]).includes(JSON.stringify(line).slice(1, -1))), "recovery uses the forced continuation");
1587
- assert.ok(fixture.sessionManager.getBranch().some((entry) => entry.type === "message" && JSON.stringify(entry.message).includes("CONTINUE_AFTER_MODEL_SWITCH")), "the latest user request survives in raw history");
1686
+ test("real AgentSession: a smaller-model downgrade rolls over proactively, and passive smaller-model overflow recovers without replaying submitted input", async () => {
1687
+ // (a) In TUI, downgrading to a smaller model whose window is already below persisted usage rolls over cleanly between turns before hitting the provider.
1688
+ {
1689
+ let fixture;
1690
+ fixture = await openFixture({
1691
+ mode: "tui",
1692
+ contextWindow: 200_000,
1693
+ script: (request, context) => {
1694
+ if (request === 1)
1695
+ return assistant(fixture, [{ type: "text", text: "LARGE_MODEL_HISTORY" }], "stop", { usage: usage(150_000) });
1696
+ assert.equal(request, 2, "proactive rollover avoids a doomed overflow request on the smaller model");
1697
+ assertFreshRequest(fixture, 1, "LARGE_MODEL_HISTORY");
1698
+ assert.ok(text(context).includes("CONTINUE_AFTER_MODEL_SWITCH"), "withheld user message reaches the fresh smaller-model window directly");
1699
+ return assistant(fixture, [{ type: "text", text: "continued on smaller model" }]);
1700
+ },
1701
+ });
1702
+ try {
1703
+ await fixture.session.prompt("LARGE_MODEL_TASK");
1704
+ await fixture.session.waitForIdle();
1705
+ assert.equal(resetMarkers(fixture).length, 0, "150k fits the original model's reserve");
1706
+ const smaller = { ...fixture.model, id: `${fixture.model.id}-small`, contextWindow: 100_000 };
1707
+ fixture.model = smaller;
1708
+ await fixture.session.setModel(smaller, { persist: false });
1709
+ await fixture.session.prompt("CONTINUE_AFTER_MODEL_SWITCH");
1710
+ await fixture.session.waitForIdle();
1711
+ assert.equal(resetMarkers(fixture).length, 1, "model downgrade triggers one clean between-turns rollover");
1712
+ assert.equal(fixture.requests.length, 2);
1713
+ assert.equal(fixture.session.model?.id, smaller.id, "rollover stays on the selected model");
1714
+ }
1715
+ finally {
1716
+ fixture.close();
1717
+ }
1588
1718
  }
1589
- finally {
1590
- fixture.close();
1719
+ // (b) When usage still appears below the smaller model's nominal reserve, a real provider overflow recovers without replaying submitted input.
1720
+ {
1721
+ let fixture;
1722
+ fixture = await openFixture({
1723
+ contextWindow: 200_000,
1724
+ script: (request, context) => {
1725
+ if (request === 1)
1726
+ return assistant(fixture, [{ type: "text", text: "LARGE_MODEL_HISTORY" }], "stop", { usage: usage(50_000) });
1727
+ if (request === 2)
1728
+ return assistant(fixture, [], "error", { errorMessage: "Prompt too long: context exceeds maximum context length" });
1729
+ assert.equal(request, 3);
1730
+ assert.equal(text(context).includes("CONTINUE_AFTER_MODEL_SWITCH"), false);
1731
+ return assistant(fixture, [{ type: "text", text: "continued on smaller model" }]);
1732
+ },
1733
+ });
1734
+ try {
1735
+ await fixture.session.prompt("LARGE_MODEL_TASK");
1736
+ await fixture.session.waitForIdle();
1737
+ assert.equal(resetMarkers(fixture).length, 0);
1738
+ const smaller = { ...fixture.model, id: `${fixture.model.id}-small`, contextWindow: 100_000 };
1739
+ fixture.model = smaller;
1740
+ await fixture.session.setModel(smaller, { persist: false });
1741
+ await fixture.session.prompt("CONTINUE_AFTER_MODEL_SWITCH");
1742
+ await fixture.session.waitForIdle();
1743
+ assert.equal(resetMarkers(fixture).length, 1, "passive model downgrade overflow commits one reset");
1744
+ assert.equal(fixture.requests.length, 3, "one failed small-model request and one recovery request");
1745
+ assert.equal(fixture.session.model?.id, smaller.id, "recovery stays on the selected model");
1746
+ assertFreshRequest(fixture, 2, "LARGE_MODEL_HISTORY");
1747
+ assertFreshRequest(fixture, 2, "CONTINUE_AFTER_MODEL_SWITCH");
1748
+ assert.ok(FORCED_CONTINUATIONS.some((line) => text(fixture.requests[2]).includes(JSON.stringify(line).slice(1, -1))), "recovery uses the forced continuation");
1749
+ assert.ok(fixture.sessionManager.getBranch().some((entry) => entry.type === "message" && JSON.stringify(entry.message).includes("CONTINUE_AFTER_MODEL_SWITCH")), "the latest user request survives in raw history");
1750
+ }
1751
+ finally {
1752
+ fixture.close();
1753
+ }
1591
1754
  }
1592
1755
  });
1593
1756
  test("real AgentSession: concurrent trusted projects keep reserve and automatic policy isolated", async () => {
@@ -1604,9 +1767,11 @@ test("real AgentSession: concurrent trusted projects keep reserve and automatic
1604
1767
  let modelInvalidated;
1605
1768
  let sessionInvalidated;
1606
1769
  const script = (fixture, highUsage) => () => {
1607
- const response = assistant(fixture(), [{ type: "text", text: "policy isolation response" }], "stop", { usage: usage(highUsage.next ? 85_000 : 100) });
1770
+ const isHigh = highUsage.next;
1608
1771
  highUsage.next = false;
1609
- return response;
1772
+ return isHigh
1773
+ ? assistant(fixture(), [{ type: "toolCall", id: "policy-probe", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(85_000) })
1774
+ : assistant(fixture(), [{ type: "text", text: "policy isolation response" }], "stop", { usage: usage(100) });
1610
1775
  };
1611
1776
  const automaticUsage = { next: true };
1612
1777
  const modelUsage = { next: true };
@@ -1746,7 +1911,6 @@ test("real AgentSession: injected settings managers own live policy and ignore c
1746
1911
  await first.session.prompt("INJECTED_LIVE_ENABLE_LOW_RESERVE");
1747
1912
  await first.session.waitForIdle();
1748
1913
  assert.equal(resetMarkers(first).length, 1, "live enablement and a lower reserve apply on the next turn");
1749
- firstHighUsage.next = true;
1750
1914
  firstManager.applyOverrides({ compaction: { reserveTokens: 80_000 } });
1751
1915
  await first.session.prompt("INJECTED_LIVE_HIGH_RESERVE");
1752
1916
  await first.session.waitForIdle();
@@ -1942,3 +2106,177 @@ test("real AgentSession: warning precedes a durable checkpoint, including failed
1942
2106
  }
1943
2107
  }
1944
2108
  });
2109
+ function bootEntries(fixture) {
2110
+ return fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE);
2111
+ }
2112
+ function branchIndex(fixture, predicate) {
2113
+ return fixture.sessionManager.getBranch().findIndex(predicate);
2114
+ }
2115
+ test("real AgentSession: the root boot is lazy, beats the first user message, and also serves an idle custom turn", async () => {
2116
+ let fixture;
2117
+ fixture = await openFixture({
2118
+ compactionEnabled: false,
2119
+ script: () => assistant(fixture, [{ type: "text", text: "ok" }]),
2120
+ });
2121
+ try {
2122
+ await fixture.session.prompt("/notesoup off");
2123
+ await fixture.session.prompt("OFF_BEFORE_FIRST_TURN");
2124
+ await fixture.session.waitForIdle();
2125
+ assert.equal(bootEntries(fixture).length, 0, "a disabled session writes no root boot");
2126
+ assert.equal(fixture.requests.length, 1);
2127
+ await fixture.session.prompt("/notesoup on");
2128
+ await fixture.session.prompt("FIRST_ON_TURN");
2129
+ await fixture.session.waitForIdle();
2130
+ const boots = bootEntries(fixture);
2131
+ assert.equal(boots.length, 1, "the first enabled turn writes exactly one root boot");
2132
+ const bootIndex = fixture.sessionManager.getBranch().indexOf(boots[0]);
2133
+ const userIndex = branchIndex(fixture, (entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("FIRST_ON_TURN"));
2134
+ assert.ok(bootIndex >= 0 && bootIndex < userIndex, "the boot is persisted before the user message it introduces");
2135
+ }
2136
+ finally {
2137
+ fixture.close();
2138
+ }
2139
+ let custom;
2140
+ custom = await openFixture({
2141
+ compactionEnabled: false,
2142
+ script: () => assistant(custom, [{ type: "text", text: "custom ok" }]),
2143
+ });
2144
+ try {
2145
+ custom.session.sendCustomMessage({ customType: "test/custom-turn", content: "CUSTOM_TRIGGER", display: false }, { triggerTurn: true });
2146
+ await custom.session.waitForIdle();
2147
+ const boots = bootEntries(custom);
2148
+ assert.equal(boots.length, 1, "before_agent_start boots a custom-triggered idle turn");
2149
+ const bootIndex = custom.sessionManager.getBranch().indexOf(boots[0]);
2150
+ const assistantIndex = branchIndex(custom, (entry) => entry.type === "message" && entry.message.role === "assistant");
2151
+ assert.ok(assistantIndex >= 0, "the custom turn produced a response");
2152
+ assert.ok(bootIndex >= 0 && bootIndex < assistantIndex, "the boot is persisted before the response it introduces");
2153
+ }
2154
+ finally {
2155
+ custom.close();
2156
+ }
2157
+ });
2158
+ test("real AgentSession: /notesoup off strips teaching, skills and tools, survives reload, and /notesoup on restores them", async (t) => {
2159
+ const customSkillDir = mkdtempSync(join(tmpdir(), "notesoup-keep-skill-"));
2160
+ t.after(() => rmSync(customSkillDir, { recursive: true, force: true }));
2161
+ writeFileSync(join(customSkillDir, "SKILL.md"), "---\nname: keep-skill\ndescription: a non-notesoup skill\n---\n");
2162
+ const allTools = [...NOTESOUP_TOOL_NAMES].sort();
2163
+ let fixture;
2164
+ fixture = await openFixture({
2165
+ compactionEnabled: false,
2166
+ skillPaths: [join(process.cwd(), "skills"), customSkillDir],
2167
+ tools: [...NOTESOUP_TOOL_NAMES],
2168
+ script: (request, context) => {
2169
+ const system = getCurrentSystemMessage(context.messages);
2170
+ const customTypes = context.messages.filter((message) => message.role === "custom").map((message) => message.customType);
2171
+ if (request === 2 || request === 3) {
2172
+ assert.equal(system?.sections?.notesoup_protocol, undefined, "the protocol section is stripped while off");
2173
+ assert.equal(system?.sections?.notesoup_tools, undefined, "the tool directory section is stripped while off");
2174
+ const skills = system?.sections?.skills ?? "";
2175
+ assert.ok(skills.includes("<name>keep-skill</name>"), "a non-notesoup skill survives");
2176
+ assert.equal(skills.includes("<name>notesoup-guide</name>"), false, "notesoup-guide skill is stripped");
2177
+ assert.equal(skills.includes("<name>dream</name>"), false, "notesoup dream skill is stripped");
2178
+ assert.deepEqual(getCurrentTools(context.messages), [], "all 12 notesoup tools leave the projection");
2179
+ for (const type of [BOOT_TYPE, MARKER_TYPE, GUIDANCE_TYPE, WARNING_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, MANUAL_WIPE_TYPE]) {
2180
+ assert.equal(customTypes.includes(type), false, `${type} is stripped while off`);
2181
+ }
2182
+ assert.ok(customTypes.includes(CARRIED_INPUT_TYPE), "carried human input survives");
2183
+ const deltas = context.messages.filter((message) => message.role === "system").slice(1);
2184
+ assert.equal(deltas.some((message) => {
2185
+ const delta = message;
2186
+ const emptyContent = delta.content === "" || (Array.isArray(delta.content) && delta.content.length === 0);
2187
+ return emptyContent && !delta.toolsAdded?.length && !delta.toolsRemoved?.length && !(delta.sections && Object.keys(delta.sections).length > 0);
2188
+ }), false, "empty delta system messages are dropped while off");
2189
+ }
2190
+ else if (request === 4) {
2191
+ assert.ok(system?.sections?.notesoup_protocol?.includes(NOTES_PROTOCOL_OPEN_TAG), "the protocol returns after /notesoup on");
2192
+ assert.equal(typeof system?.sections?.notesoup_tools, "string", "the tool directory returns");
2193
+ const skills = system?.sections?.skills ?? "";
2194
+ for (const name of ["notesoup", "dream", "keep-skill"])
2195
+ assert.ok(skills.includes(`<name>${name}</name>`), `${name} skill is visible after on`);
2196
+ assert.deepEqual(getCurrentTools(context.messages).map((tool) => tool.name).sort(), allTools, "all 12 notesoup tools return");
2197
+ }
2198
+ return assistant(fixture, [{ type: "text", text: "done" }]);
2199
+ },
2200
+ });
2201
+ try {
2202
+ await fixture.session.prompt("FIRST_TURN_SENTINEL");
2203
+ await fixture.session.waitForIdle();
2204
+ assert.equal(bootEntries(fixture).length, 1);
2205
+ for (const type of [MARKER_TYPE, GUIDANCE_TYPE, WARNING_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, MANUAL_WIPE_TYPE, CARRIED_INPUT_TYPE]) {
2206
+ fixture.sessionManager.appendCustomMessageEntry(type, `${type}-sentinel`, false);
2207
+ }
2208
+ await fixture.session.prompt("/notesoup off");
2209
+ assert.equal(resetMarkers(fixture).length, 0);
2210
+ await fixture.session.prompt("OFF_TURN");
2211
+ await fixture.session.waitForIdle();
2212
+ assert.equal(fixture.sessionManager.getBranch().some((entry) => entry.type === "custom" && entry.customType === ENABLED_TYPE && entry.data.enabled === false), true, "the off choice is durable on the branch");
2213
+ await fixture.session.reload();
2214
+ await fixture.session.prompt("AFTER_RELOAD");
2215
+ await fixture.session.waitForIdle();
2216
+ assert.equal(fixture.requests.length, 3, "reload neither boots nor adds a request");
2217
+ await fixture.session.prompt("/notesoup on");
2218
+ await fixture.session.prompt("RESTORED_TURN");
2219
+ await fixture.session.waitForIdle();
2220
+ assert.equal(fixture.requests.length, 4);
2221
+ }
2222
+ finally {
2223
+ fixture.close();
2224
+ }
2225
+ });
2226
+ test("real AgentSession: /notesoup off after reset allows native compaction and /notesoup on re-boots cleanly", async () => {
2227
+ let fixture;
2228
+ fixture = await openFixture({
2229
+ compactionEnabled: true,
2230
+ tools: [...NOTESOUP_TOOL_NAMES],
2231
+ script: (request, context) => {
2232
+ if (request === 1) {
2233
+ return assistant(fixture, [{ type: "toolCall", id: "wipe-1", name: "empty_brain", arguments: {} }], "toolUse");
2234
+ }
2235
+ if (request === 2) {
2236
+ return assistant(fixture, [{ type: "text", text: "POST_RESET_REPLY" }]);
2237
+ }
2238
+ if (request === 3) {
2239
+ const rendered = text(context);
2240
+ assert.equal(rendered.includes("PRE_RESET_SENTINEL"), false, "pre-reset history stays hidden while off");
2241
+ assert.equal(context.messages.some((m) => m.role === "compactionSummary"), false, "empty reset wrapper stays stripped before native compaction");
2242
+ return assistant(fixture, [{ type: "text", text: "OFF_BEFORE_COMPACT_REPLY" }]);
2243
+ }
2244
+ if (request === 4) {
2245
+ const rendered = text(context);
2246
+ assert.ok(rendered.includes("NATIVE_SUMMARY_WHILE_OFF"), "native compaction summary reaches the model while off");
2247
+ assert.equal(rendered.includes("PRE_RESET_SENTINEL"), false);
2248
+ return assistant(fixture, [{ type: "text", text: "OFF_AFTER_COMPACT_REPLY" }]);
2249
+ }
2250
+ if (request === 5) {
2251
+ const rendered = text(context);
2252
+ assert.ok(rendered.includes("NATIVE_SUMMARY_WHILE_OFF"), "re-enabling notesoup keeps the native compaction summary");
2253
+ assert.ok(context.messages.some((m) => m.role === "custom" && m.customType === BOOT_TYPE), "re-enabling notesoup lazily injects a fresh boot");
2254
+ return assistant(fixture, [{ type: "text", text: "BACK_ON_REPLY" }]);
2255
+ }
2256
+ return assistant(fixture, [{ type: "text", text: `reply-${request}` }]);
2257
+ },
2258
+ });
2259
+ try {
2260
+ await fixture.session.prompt("PRE_RESET_SENTINEL");
2261
+ await fixture.session.waitForIdle();
2262
+ assert.equal(resetMarkers(fixture).length, 1);
2263
+ await fixture.session.prompt("/notesoup off");
2264
+ await fixture.session.prompt("OFF_BEFORE_COMPACT_PROMPT");
2265
+ await fixture.session.waitForIdle();
2266
+ assert.equal(fixture.requests.length, 3);
2267
+ // Simulate Pi native compaction landing while notesoup is off (keeping only the latest turn).
2268
+ const keptId = [...fixture.sessionManager.getBranch()].reverse().find((entry) => entry.type === "message")?.id ?? null;
2269
+ fixture.sessionManager.appendCompaction("NATIVE_SUMMARY_WHILE_OFF", keptId, 42_000);
2270
+ await fixture.session.prompt("OFF_AFTER_COMPACT_PROMPT");
2271
+ await fixture.session.waitForIdle();
2272
+ assert.equal(fixture.requests.length, 4);
2273
+ await fixture.session.prompt("/notesoup on");
2274
+ await fixture.session.prompt("BACK_ON_PROMPT");
2275
+ await fixture.session.waitForIdle();
2276
+ assert.equal(fixture.requests.length, 5);
2277
+ assert.equal(bootEntries(fixture).length, 3, "root boot + reset boot + post-compaction re-enable boot");
2278
+ }
2279
+ finally {
2280
+ fixture.close();
2281
+ }
2282
+ });
@@ -0,0 +1 @@
1
+ export {};