notesoup 0.39.0 → 0.41.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 (91) hide show
  1. package/README.md +5 -2
  2. package/dist/src/boot/render.js +2 -2
  3. package/dist/src/boot/text.d.ts +0 -4
  4. package/dist/src/boot/text.js +18 -14
  5. package/dist/src/budget/policy.js +1 -1
  6. package/dist/src/budget/text.js +1 -1
  7. package/dist/src/dream/doctor.js +2 -1
  8. package/dist/src/dream/git.js +2 -1
  9. package/dist/src/dream/report.js +3 -2
  10. package/dist/src/error-message.d.ts +2 -0
  11. package/dist/src/error-message.js +4 -0
  12. package/dist/src/history/history.d.ts +23 -18
  13. package/dist/src/history/history.js +37 -20
  14. package/dist/src/history/query.d.ts +37 -49
  15. package/dist/src/history/query.js +114 -56
  16. package/dist/src/notes/store.d.ts +3 -4
  17. package/dist/src/notes/store.js +12 -16
  18. package/dist/src/pi/anchored.d.ts +16 -0
  19. package/dist/src/pi/anchored.js +55 -0
  20. package/dist/src/pi/budget.d.ts +1 -1
  21. package/dist/src/pi/budget.js +33 -28
  22. package/dist/src/pi/dream/cli.js +3 -2
  23. package/dist/src/pi/dream/runner.js +2 -1
  24. package/dist/src/pi/history-tools.d.ts +1 -1
  25. package/dist/src/pi/history-tools.js +2 -3
  26. package/dist/src/pi/reset/lifecycle.d.ts +1 -1
  27. package/dist/src/pi/reset/lifecycle.js +4 -3
  28. package/dist/src/pi/reset/text.d.ts +3 -3
  29. package/dist/src/pi/reset/text.js +2 -2
  30. package/dist/src/pi/runtime.js +12 -15
  31. package/dist/src/pi/thresholds.js +2 -1
  32. package/dist/src/pi/tool-names.d.ts +0 -4
  33. package/dist/src/pi/tool-names.js +0 -4
  34. package/dist/src/tools/history.d.ts +24 -33
  35. package/dist/src/tools/history.js +57 -98
  36. package/dist/src/tools/notes.d.ts +26 -58
  37. package/dist/src/tools/notes.js +85 -103
  38. package/dist/src/tools/result.d.ts +16 -13
  39. package/dist/src/tools/result.js +24 -50
  40. package/dist/src/tools/schema.d.ts +2 -2
  41. package/dist/src/tools/schema.js +3 -3
  42. package/dist/test/agent-loop.test.js +79 -29
  43. package/dist/test/boot.integration.test.js +6 -6
  44. package/dist/test/budget-settings.integration.test.js +9 -8
  45. package/dist/test/claude-mod.test.js +11 -11
  46. package/dist/test/dependencies.test.js +1 -1
  47. package/dist/test/helpers/extension.js +2 -3
  48. package/dist/test/history.integration.test.js +200 -123
  49. package/dist/test/host-neutral.test.js +32 -58
  50. package/dist/test/notes-library.test.js +8 -8
  51. package/dist/test/notes.integration.test.js +75 -57
  52. package/dist/test/notes.test.js +44 -42
  53. package/dist/test/reset-lifecycle.test.js +2 -2
  54. package/docs/architecture.md +3 -3
  55. package/docs/notes-library.md +6 -6
  56. package/docs/tool-results.md +15 -25
  57. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  58. package/mods/notesoup/dist/claude/helper.js +128 -179
  59. package/mods/notesoup/hooks/register.ts +19 -25
  60. package/mods/notesoup/playbook.md +10 -10
  61. package/mods/notesoup/skills/dream/SKILL.md +1 -1
  62. package/package.json +1 -1
  63. package/playbook.md +10 -10
  64. package/skills/dream/SKILL.md +1 -1
  65. package/skills/memory/SKILL.md +11 -9
  66. package/src/boot/render.ts +2 -2
  67. package/src/boot/text.ts +18 -18
  68. package/src/budget/policy.ts +1 -1
  69. package/src/budget/text.ts +1 -1
  70. package/src/dream/doctor.ts +2 -1
  71. package/src/dream/git.ts +2 -1
  72. package/src/dream/report.ts +3 -2
  73. package/src/error-message.ts +4 -0
  74. package/src/history/history.ts +36 -20
  75. package/src/history/query.ts +130 -55
  76. package/src/notes/store.ts +15 -18
  77. package/src/pi/anchored.ts +62 -0
  78. package/src/pi/budget.ts +27 -26
  79. package/src/pi/dream/cli.ts +3 -2
  80. package/src/pi/dream/runner.ts +2 -1
  81. package/src/pi/history-tools.ts +2 -3
  82. package/src/pi/reset/lifecycle.ts +5 -4
  83. package/src/pi/reset/text.ts +2 -2
  84. package/src/pi/runtime.ts +12 -15
  85. package/src/pi/thresholds.ts +2 -1
  86. package/src/pi/tool-names.ts +0 -4
  87. package/src/tools/history.ts +61 -100
  88. package/src/tools/notes.ts +84 -97
  89. package/src/tools/result.ts +24 -49
  90. package/src/tools/schema.ts +3 -3
  91. package/mods/pi-context/dist/claude/helper.js +0 -9324
@@ -125,12 +125,13 @@ async function openFixture(options) {
125
125
  await session.bindExtensions({
126
126
  uiContext: {
127
127
  notify(message, type) {
128
- if (message.startsWith("notesoup: memory cleared · ")) {
129
- const windowId = message.split(" · ")[1];
128
+ if (message === "🥣 Memory cleared") {
129
+ const marker = sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).at(-1);
130
+ const windowId = marker?.data?.windowId;
130
131
  assert.ok(sessionManager.getBranch().some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE && entry.data?.windowId === windowId), "notification follows the reset marker commit");
131
132
  assert.ok(sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE && entry.details?.windowId === windowId), "notification follows the reset boot commit");
132
133
  }
133
- if (type === "warning" && /^notesoup: context (?:almost full|running low)/.test(message))
134
+ if (type === "warning" && /^🥣 Context almost full/.test(message))
134
135
  budgetNotices++;
135
136
  notices.push(message);
136
137
  },
@@ -193,6 +194,9 @@ function assistant(fixture, content, stopReason = "stop", extra = {}) {
193
194
  function text(message) {
194
195
  return JSON.stringify(message?.messages ?? []);
195
196
  }
197
+ /** `text()` serializes to JSON, so match the reset prose in its escaped form. */
198
+ const CONTINUATION_JSON = JSON.stringify(CONTINUATION).slice(1, -1);
199
+ const WARNING_JSON = JSON.stringify(WARNING_PROMPT).slice(1, -1);
196
200
  function resetMarkers(fixture) {
197
201
  return fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
198
202
  }
@@ -214,7 +218,7 @@ function assertFreshRequest(fixture, requestIndex, oldSentinel) {
214
218
  const body = text(fixture.requests[requestIndex]);
215
219
  assert.equal(body.includes(oldSentinel), false, "the new provider request excludes the old window transcript");
216
220
  assert.ok(body.includes(CONTEXT_WINDOW_OPEN_TAG), "the new provider request includes the fresh context-window boot");
217
- assert.equal(body.split(CONTINUATION).length - 1, 1, "the fresh window carries exactly one reset message");
221
+ assert.equal(body.split(CONTINUATION_JSON).length - 1, 1, "the fresh window carries exactly one reset message");
218
222
  }
219
223
  test("real Pi codemode receives typed notes/history outcomes, including expected errors", { timeout: 20000 }, async () => {
220
224
  let fixture;
@@ -227,7 +231,7 @@ test("real Pi codemode receives typed notes/history outcomes, including expected
227
231
  return assistant(fixture, [{ type: "toolCall", id: "structured-smoke", name: "codemode", arguments: { code: `
228
232
  const written = await tools.notes_write({ address: "smoke.md", content: "A😀界Z" });
229
233
  const listed = await tools.notes_list({});
230
- const read = await tools.notes_read({ address: "smoke.md", offset_chars: 1, limit_chars: 2 });
234
+ const read = await tools.notes_read({ address: "smoke.md", offset_chars: 1, max_chars: 2 });
231
235
  const refused = await tools.notes_read({ address: "missing.md" });
232
236
  if ("error" in written || "error" in listed || "error" in read || !("error" in refused)) throw new Error("wrong outcome");
233
237
  if (read.text !== "😀界" || read.next_offset_chars !== 3) throw new Error("wrong window");
@@ -264,10 +268,9 @@ text({ marker: "HISTORY_SMOKE", calls: calls.call_count, complete: calls.complet
264
268
  fixture.close();
265
269
  }
266
270
  });
267
- test("real AgentSession: aborted early guidance retries silently with automatic reset disabled", async () => {
271
+ test("real AgentSession: aborted early guidance retries silently", async () => {
268
272
  let fixture;
269
273
  fixture = await openFixture({
270
- compactionEnabled: false,
271
274
  script: (request) => assistant(fixture, [{ type: "text", text: `response ${request}` }], request === 2 ? "aborted" : "stop", { usage: usage(50_000) }),
272
275
  });
273
276
  try {
@@ -293,6 +296,53 @@ test("real AgentSession: aborted early guidance retries silently with automatic
293
296
  fixture.close();
294
297
  }
295
298
  });
299
+ test("real AgentSession: no low-budget guidance while automatic reset is disabled", async () => {
300
+ let fixture;
301
+ fixture = await openFixture({
302
+ compactionEnabled: false,
303
+ script: (request) => assistant(fixture, [{ type: "text", text: `response ${request}` }], "stop", { usage: usage(62_000) }),
304
+ });
305
+ try {
306
+ for (const prompt of ["Establish usage below the reminder line.", "Cross the reminder line."]) {
307
+ await fixture.session.prompt(prompt);
308
+ await fixture.session.waitForIdle();
309
+ }
310
+ const guidance = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE);
311
+ assert.equal(guidance.length, 0, "nothing will be cleared, so nothing is announced");
312
+ }
313
+ finally {
314
+ fixture.close();
315
+ }
316
+ });
317
+ test("real AgentSession: early guidance reaches its crossing request and later requests keep one copy in place", async () => {
318
+ let fixture;
319
+ const contexts = [];
320
+ fixture = await openFixture({
321
+ script: (request, context) => {
322
+ contexts.push((context?.messages ?? []).map((message) => JSON.stringify(message).includes(GUIDANCE_OPEN_TAG) ? GUIDANCE_TYPE : message.role));
323
+ // 62k of 100k leaves ~38k: below the reminder line (40,960), above the warning (32,768).
324
+ return assistant(fixture, [{ type: "text", text: `response ${request}` }], "stop", { usage: usage(62_000) });
325
+ },
326
+ });
327
+ try {
328
+ await fixture.session.prompt("Establish usage below the reminder line.");
329
+ await fixture.session.waitForIdle();
330
+ await fixture.session.prompt("Cross the reminder line.");
331
+ await fixture.session.waitForIdle();
332
+ await fixture.session.prompt("Continue in the same window.");
333
+ await fixture.session.waitForIdle();
334
+ const crossing = contexts[1];
335
+ assert.equal(crossing.filter((type) => type === GUIDANCE_TYPE).length, 1, "the crossing request carries the reminder");
336
+ assert.equal(crossing.at(-1), GUIDANCE_TYPE, "the reminder follows the crossing user message");
337
+ const later = contexts[2];
338
+ assert.equal(later.filter((type) => type === GUIDANCE_TYPE).length, 1, "later requests carry exactly one copy");
339
+ assert.deepEqual(later.slice(0, crossing.length), crossing, "the durable copy sits where the crossing request had it");
340
+ assert.equal(later[crossing.length], "assistant", "the anchor reply directly follows the reminder");
341
+ }
342
+ finally {
343
+ fixture.close();
344
+ }
345
+ });
296
346
  test("real AgentSession: an aborted final warning stays silent until a successful retry commits it", async () => {
297
347
  let fixture;
298
348
  fixture = await openFixture({
@@ -302,7 +352,7 @@ test("real AgentSession: an aborted final warning stays silent until a successfu
302
352
  return assistant(fixture, [{ type: "toolCall", id: "abort-budget-probe-1", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(50_000) });
303
353
  if (request === 2)
304
354
  return assistant(fixture, [{ type: "toolCall", id: "abort-budget-probe-2", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(60_000) });
305
- assert.ok(text(context).includes(WARNING_PROMPT), "the final warning reaches the model on both attempts");
355
+ assert.ok(text(context).includes(WARNING_JSON), "the final warning reaches the model on both attempts");
306
356
  return assistant(fixture, [{ type: "text", text: `response ${request}` }], request === 3 ? "aborted" : "stop", { usage: usage(60_000) });
307
357
  },
308
358
  });
@@ -336,7 +386,7 @@ test("real AgentSession: final warning survives its reset boundary and notifies
336
386
  if (request === 2)
337
387
  return assistant(fixture, [{ type: "toolCall", id: "final-budget-probe-2", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(60_000) });
338
388
  if (request === 3) {
339
- assert.ok(text(context).includes(WARNING_PROMPT), "the final warning reaches the model");
389
+ assert.ok(text(context).includes(WARNING_JSON), "the final warning reaches the model");
340
390
  return assistant(fixture, [{ type: "toolCall", id: "final-budget-wipe", name: "clear_memory", arguments: {} }], "toolUse", { usage: usage(60_000) });
341
391
  }
342
392
  return assistant(fixture, [{ type: "text", text: "fresh window ready" }]);
@@ -351,12 +401,12 @@ test("real AgentSession: final warning survives its reset boundary and notifies
351
401
  assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === WARNING_TYPE).length, 1);
352
402
  assert.equal(resetMarkers(fixture).length, 1, "the reset commits in the same boundary as the final warning");
353
403
  assert.equal(fixture.budgetNotices(), 1, "the old-window committed warning reaches the UI after reset");
354
- assert.equal(fixture.notices.filter((notice) => notice.startsWith("notesoup: memory cleared · ")).length, 1, "reset notification remains intact");
404
+ assert.equal(fixture.notices.filter((notice) => notice === "🥣 Memory cleared").length, 1, "reset notification remains intact");
355
405
  assert.equal(fixture.notices.some((notice) => notice.includes("Context running low")), false, "early guidance stays silent");
356
406
  await fixture.session.prompt("Continue after reset.");
357
407
  await fixture.session.waitForIdle();
358
408
  assert.equal(fixture.budgetNotices(), 1, "later turns cannot repeat the consumed final warning");
359
- assert.equal(fixture.notices.filter((notice) => notice.startsWith("notesoup: memory cleared · ")).length, 1, "the prior reset notification is also deduplicated");
409
+ assert.equal(fixture.notices.filter((notice) => notice === "🥣 Memory cleared").length, 1, "the prior reset notification is also deduplicated");
360
410
  }
361
411
  finally {
362
412
  fixture.close();
@@ -376,7 +426,7 @@ test("real AgentSession: explicit tiny-session wipe ignores keepRecentTokens and
376
426
  assert.equal(fixture.notices.length, 0, "startup boot is silent");
377
427
  await fixture.session.prompt("OLD_CONTEXT_SENTINEL: retain this only in durable history.");
378
428
  await fixture.session.waitForIdle();
379
- assert.equal(fixture.notices.filter((message) => message.includes("memory cleared")).length, 1, "the reset notifies once");
429
+ assert.equal(fixture.notices.filter((message) => message.includes("Memory cleared")).length, 1, "the reset notifies once");
380
430
  assert.equal(fixture.requests.length, 2, "the tool starts exactly one continuation");
381
431
  assert.ok(text(fixture.requests[0]).includes("OLD_CONTEXT_SENTINEL"));
382
432
  assertFreshRequest(fixture, 1, "OLD_CONTEXT_SENTINEL");
@@ -406,7 +456,7 @@ test("real AgentSession: manual command spans its tool batch and stops at settle
406
456
  if (request === 1)
407
457
  return assistant(fixture, [{ type: "text", text: "before manual reset" }]);
408
458
  if (request === 2) {
409
- assert.ok(text(context).includes(WARNING_PROMPT), "idle /clear-memory sends the shared checkpoint prompt");
459
+ assert.ok(text(context).includes(WARNING_JSON), "idle /clear-memory sends the shared checkpoint prompt");
410
460
  return assistant(fixture, [{ type: "toolCall", id: "manual-note", name: "notes_write", arguments: { address: "manual-a.md", content: "MANUAL_NOTE_ALPHA" } }], "toolUse");
411
461
  }
412
462
  assert.equal(request, 3, "the close-out turn finishes in the old window");
@@ -465,7 +515,7 @@ test("real AgentSession: clear commands append a prompt after continuation and r
465
515
  assert.equal(request, 3, "exactly one fresh-window request");
466
516
  assert.equal(text(context).includes("PROMPT_RESET_OLD_SENTINEL"), false);
467
517
  assert.equal(text(context).split(prompt).length - 1, 1);
468
- assert.ok(text(context).indexOf(CONTINUATION) < text(context).indexOf(prompt), "wake-up prose precedes the appended prompt");
518
+ assert.ok(text(context).indexOf(CONTINUATION_JSON) < text(context).indexOf(prompt), "wake-up prose precedes the appended prompt");
469
519
  return assistant(fixture, [{ type: "text", text: "prompt handled" }]);
470
520
  },
471
521
  });
@@ -482,7 +532,7 @@ test("real AgentSession: clear commands append a prompt after continuation and r
482
532
  assert.equal(appended.customType, "notesoup/reset-prompt");
483
533
  assert.equal(appended.content, prompt);
484
534
  assert.equal(appended.display, true);
485
- assert.ok(fixture.notices.some((notice) => notice.includes("memory cleared")));
535
+ assert.ok(fixture.notices.some((notice) => notice.includes("Memory cleared")));
486
536
  }
487
537
  finally {
488
538
  fixture.close();
@@ -541,7 +591,7 @@ test("real AgentSession: streaming clear prompt keeps the first request", { time
541
591
  await fixture.session.waitForIdle();
542
592
  assert.equal(fixture.requests.length, 3);
543
593
  assert.equal(resetMarkers(fixture).length, 1);
544
- assert.ok(fixture.notices.some((notice) => notice.includes("already pending")));
594
+ assert.ok(fixture.notices.some((notice) => notice.includes("already queued")));
545
595
  }
546
596
  finally {
547
597
  release();
@@ -572,7 +622,7 @@ test("real AgentSession: manual hard-reserve reset stops clean and mixed-tool tu
572
622
  assert.equal(fixture.requests.length, 2);
573
623
  assert.equal(resetMarkers(fixture).length, 1, "the safety wipe is not repeated at settlement");
574
624
  assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("HARD_RESERVE_OLD_SENTINEL"), false);
575
- assert.ok(fixture.notices.some((notice) => notice.includes("memory cleared")));
625
+ assert.ok(fixture.notices.some((notice) => notice.includes("Memory cleared")));
576
626
  if (mixed) {
577
627
  assert.ok(existsSync(join(fixture.notesRoot, "pi", "session", fixture.sessionManager.getSessionId(), "pressure.md")), "the whole tool batch completes before the cut");
578
628
  assert.equal(fixture.streamSignals.at(-1), true, "Pi's unavoidable tool follow-up is cancelled before provider work");
@@ -643,7 +693,7 @@ test("real AgentSession: manual overflow wipes and stops even with automatic res
643
693
  assert.equal(fixture.requests.length, 2);
644
694
  assert.equal(resetMarkers(fixture).length, 1);
645
695
  assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("MANUAL_OVERFLOW_OLD_SENTINEL"), false);
646
- assert.ok(fixture.notices.some((notice) => notice.includes("memory cleared")));
696
+ assert.ok(fixture.notices.some((notice) => notice.includes("Memory cleared")));
647
697
  }
648
698
  finally {
649
699
  fixture.close();
@@ -664,7 +714,7 @@ test("real AgentSession: streaming /clear-memory steers a close-out and stops at
664
714
  return assistant(fixture, [{ type: "text", text: "current response finished" }]);
665
715
  }
666
716
  assert.equal(request, 2, "the steered warning gets exactly one close-out turn before the run stops");
667
- assert.ok(text(context).includes(WARNING_PROMPT), "the busy warning is delivered to the running agent");
717
+ assert.ok(text(context).includes(WARNING_JSON), "the busy warning is delivered to the running agent");
668
718
  return assistant(fixture, [{ type: "text", text: "close-out complete" }]);
669
719
  },
670
720
  });
@@ -673,7 +723,7 @@ test("real AgentSession: streaming /clear-memory steers a close-out and stops at
673
723
  await started;
674
724
  await fixture.session.prompt("/clear-memory", { streamingBehavior: "steer" });
675
725
  await fixture.session.prompt("/clear-memory", { streamingBehavior: "followUp" });
676
- assert.equal(fixture.notices.filter((notice) => notice.includes("queued; the agent is asked to close out")).length, 1, "the user is notified once while output is ongoing");
726
+ assert.equal(fixture.notices.filter((notice) => notice.includes("notes first, then it stops")).length, 1, "the user is notified once while output is ongoing");
677
727
  assert.equal(resetMarkers(fixture).length, 0, "the ongoing turn is not interrupted");
678
728
  releaseResponse();
679
729
  await running;
@@ -682,7 +732,7 @@ test("real AgentSession: streaming /clear-memory steers a close-out and stops at
682
732
  assert.equal(fixture.requests.length, 2, "the warning closes out and the run stops — no continuation in the fresh window");
683
733
  assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE).length, 1, "the busy warning is persisted once");
684
734
  assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("STREAMING_WIPE_OLD_SENTINEL"), false);
685
- assert.ok(fixture.notices.some((notice) => notice.includes("memory cleared")), "the committed boundary has a separate success notice");
735
+ assert.ok(fixture.notices.some((notice) => notice.includes("Memory cleared")), "the committed boundary has a separate success notice");
686
736
  }
687
737
  finally {
688
738
  releaseResponse();
@@ -747,7 +797,7 @@ test("real AgentSession: user abort, synthetic aborted response, and generic err
747
797
  await fixture.session.waitForIdle();
748
798
  assert.equal(resetMarkers(fixture).length, 0, `${mode} does not force a reset`);
749
799
  assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "compaction").length, 0);
750
- assert.equal(fixture.notices.some((notice) => notice.includes("memory cleared")), false);
800
+ assert.equal(fixture.notices.some((notice) => notice.includes("Memory cleared")), false);
751
801
  if (mode === "ctx-abort")
752
802
  assert.equal(fixture.streamSignals.at(-1), true, "this case aborts the real Pi operation signal");
753
803
  else
@@ -773,12 +823,12 @@ test("real AgentSession: steering and follow-up queued during a manual reset are
773
823
  compactionEnabled: false,
774
824
  script: async (request, context) => {
775
825
  if (request === 1) {
776
- assert.ok(text(context).includes(WARNING_PROMPT));
826
+ assert.ok(text(context).includes(WARNING_JSON));
777
827
  announceStarted();
778
828
  await gate;
779
829
  }
780
830
  if (request === 2) {
781
- assert.ok(text(context).includes(WARNING_PROMPT), `${delivery} is answered in the old window before the reset commits`);
831
+ assert.ok(text(context).includes(WARNING_JSON), `${delivery} is answered in the old window before the reset commits`);
782
832
  assert.equal(text(context).split("QUEUED_DURING_FALLBACK").length - 1, 1, `${delivery} is delivered once`);
783
833
  }
784
834
  return assistant(fixture, [{ type: "text", text: `response ${request}` }]);
@@ -1394,13 +1444,13 @@ test("real AgentSession: persisted budget warning re-arms after a later abort/er
1394
1444
  if (request === 2)
1395
1445
  return assistant(fixture, [{ type: "toolCall", id: "rearm-probe-2", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(60_000) });
1396
1446
  if (request === 3) {
1397
- assert.ok(text(context).includes(WARNING_PROMPT), "the low-budget request carries the close-out warning");
1447
+ assert.ok(text(context).includes(WARNING_JSON), "the low-budget request carries the close-out warning");
1398
1448
  warningTurnStarted();
1399
1449
  await warningGate;
1400
1450
  return assistant(fixture, [{ type: "toolCall", id: "rearm-note", name: "notes_write", arguments: { address: "warning-rearm.md", content: "DURABLE_WARNING_CHECKPOINT" } }], "toolUse", { usage: usage(60_000) });
1401
1451
  }
1402
1452
  if (request === 4 && mode === "generic-error") {
1403
- assert.equal(text(context).split(WARNING_PROMPT).length - 1, 1, "the durable warning is not injected a second time");
1453
+ assert.equal(text(context).split(WARNING_JSON).length - 1, 1, "the durable warning is not injected a second time");
1404
1454
  assert.ok(text(context).includes("REARM_QUEUED_FOLLOWUP"));
1405
1455
  return assistant(fixture, [{ type: "text", text: "ordinary provider failure" }], "error", { errorMessage: "synthetic non-overflow failure", usage: usage(60_000) });
1406
1456
  }
@@ -1421,7 +1471,7 @@ test("real AgentSession: persisted budget warning re-arms after a later abort/er
1421
1471
  assert.equal(afterFailure.filter((entry) => entry.type === "compaction").length, 0);
1422
1472
  const failedContext = fixture.streamContexts[3];
1423
1473
  assert.ok(failedContext);
1424
- assert.equal(text(failedContext).split(WARNING_PROMPT).length - 1, 1, "the persisted warning appears once, without duplicate injection");
1474
+ assert.equal(text(failedContext).split(WARNING_JSON).length - 1, 1, "the persisted warning appears once, without duplicate injection");
1425
1475
  assert.equal(text(failedContext).split("REARM_QUEUED_FOLLOWUP").length - 1, 1, "queued follow-up reaches the failed request once");
1426
1476
  assert.equal(fixture.streamSignals.at(-1), mode === "ctx-abort", "the abort case cancels Pi's real signal; the error case does not");
1427
1477
  await fixture.session.prompt("REARM_AFTER_FAILED_TURN");
@@ -1445,7 +1495,7 @@ test("real AgentSession: warning precedes a durable checkpoint, including failed
1445
1495
  script: (request, context) => {
1446
1496
  if (request === 3) {
1447
1497
  assert.ok(text(context).includes(GUIDANCE_OPEN_TAG), "the warning remains in its hidden guidance wrapper");
1448
- assert.ok(text(context).includes(WARNING_PROMPT), "the shared close-out warning reaches the provider before checkpoint choice");
1498
+ assert.ok(text(context).includes(WARNING_JSON), "the shared close-out warning reaches the provider before checkpoint choice");
1449
1499
  }
1450
1500
  if (request === 1)
1451
1501
  return assistant(fixture, [{ type: "toolCall", id: "budget-probe-1", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(50_000) });
@@ -1487,7 +1537,7 @@ test("real AgentSession: warning precedes a durable checkpoint, including failed
1487
1537
  await fixture.session.waitForIdle();
1488
1538
  assert.equal(resetMarkers(fixture).length, 0);
1489
1539
  assert.ok(text(fixture.requests.at(-1)).includes(`WARNING_${scenario.toUpperCase()}_SENTINEL`));
1490
- assert.equal(text(fixture.requests.at(-1)).split(WARNING_PROMPT).length - 1, 1, "the persisted warning remains visible without duplicate injection");
1540
+ assert.equal(text(fixture.requests.at(-1)).split(WARNING_JSON).length - 1, 1, "the persisted warning remains visible without duplicate injection");
1491
1541
  }
1492
1542
  }
1493
1543
  finally {
@@ -46,7 +46,7 @@ test("custom reset marker removes old provider context while history remains sea
46
46
  assert.ok(oldSeq);
47
47
  const read = resultRead(await call(captured, "history_read", { seq: oldSeq }, ctx));
48
48
  assert.match(read.content, /OLD-UNIQUE-TRANSCRIPT/);
49
- const found = resultData(await call(captured, "history_search", { query: "needle" }, ctx));
49
+ const found = resultData(await call(captured, "history_list", { query: "needle" }, ctx));
50
50
  assert.equal(found.items.length, 1);
51
51
  assert.equal(found.items[0]?.seq, oldSeq);
52
52
  });
@@ -86,7 +86,7 @@ test("the root boot and reset boot carry durable window identity", async () => {
86
86
  assert.equal(boundary.continue, true);
87
87
  await runHandlers(captured, "turn_start", {}, ctx);
88
88
  await runHandlers(captured, "agent_settled", {}, ctx);
89
- assert.equal(noticesOf(ctx).filter((notice) => notice.message.includes("memory cleared")).length, 1, "the committed reset is announced once");
89
+ assert.equal(noticesOf(ctx).filter((notice) => notice.message.includes("Memory cleared")).length, 1, "the committed reset is announced once");
90
90
  const entries = sessionManager.getBranch();
91
91
  const marker = entries.find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
92
92
  assert.ok(marker && marker.type === "custom");
@@ -115,7 +115,7 @@ test("an aborted async boot repair emits no boot, continuation, or incomplete-no
115
115
  controller.abort();
116
116
  await pending;
117
117
  assert.equal(captured.sent.length, 0, "aborted snapshot work cannot append the reset boot or continuation");
118
- assert.equal(noticesOf(ctx).some((notice) => notice.message.includes("notes index incomplete")), false, "aborted snapshot work cannot notify about missing homes");
118
+ assert.equal(noticesOf(ctx).some((notice) => notice.message.includes("didn't load")), false, "aborted snapshot work cannot notify about missing homes");
119
119
  assert.equal(sessionManager.getBranch().some((entry) => entry.type === "custom_message" && [BOOT_TYPE, CONTINUATION_TYPE].includes(entry.customType)), false);
120
120
  });
121
121
  test("a marker tail with only metadata repairs its missing boot and continuation without moving the boundary", async () => {
@@ -229,7 +229,7 @@ test("/clear-memory waits out non-agent busy work before starting its single-tur
229
229
  assert.equal(waits, 1);
230
230
  assert.equal(captured.sent.length, 1);
231
231
  assert.equal(captured.sent[0]?.options?.triggerTurn, true);
232
- assert.equal(notices.filter((message) => message.includes("received; the agent closes out its notes")).length, 1);
232
+ assert.equal(notices.filter((message) => message.includes("notes first, then it stops")).length, 1);
233
233
  });
234
234
  test("notesoup command toggles future work, /clear-memory schedules a turn-end reset, and /compact remains disabled", async () => {
235
235
  const sessionManager = manager();
@@ -252,7 +252,7 @@ test("notesoup command toggles future work, /clear-memory schedules a turn-end r
252
252
  assert.match(notices[0]?.message ?? "", /on/);
253
253
  notices = await runCommand(captured, "clear-memory", "", low);
254
254
  assert.equal(notices.length, 1, "the command acknowledges the reset request");
255
- assert.match(notices[0]?.message ?? "", /closes out its notes/);
255
+ assert.match(notices[0]?.message ?? "", /notes first, then it stops/);
256
256
  assert.equal(captured.sent.length, 2, "the command persists one hidden warning after the startup boot");
257
257
  assert.equal(captured.sent[1]?.options?.triggerTurn, true, "the manual checkpoint prompt starts an ordinary agent turn");
258
258
  assert.equal(captured.sent[1]?.message.customType, MANUAL_WIPE_TYPE);
@@ -283,7 +283,7 @@ test("committed reset confirmation survives later work while repair refuses that
283
283
  assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true, "later work does not undo a committed native boundary");
284
284
  await runHandlers(captured, "agent_settled", {}, ctx);
285
285
  await runHandlers(captured, "turn_start", {}, ctx);
286
- assert.equal(noticesOf(ctx).filter((notice) => notice.message.includes("memory cleared")).length, 1);
286
+ assert.equal(noticesOf(ctx).filter((notice) => notice.message.includes("Memory cleared")).length, 1);
287
287
  assert.equal(resetBoundaryCommitted(ctx, marker.id, "wrong-window"), false);
288
288
  const partial = manager();
289
289
  const partialCtx = context(partial);
@@ -10,7 +10,8 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
10
10
  const sessionManager = manager();
11
11
  const captured = makeExtension(sessionManager);
12
12
  const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
13
- assert.equal(await runContextHook(captured, low), undefined, "guidance is staged, not injected into this request");
13
+ const guidance = await runContextHook(captured, low);
14
+ assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
14
15
  assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
15
16
  const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
16
17
  assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
@@ -28,7 +29,7 @@ test("early guidance stays silent and the committed final warning notifies once"
28
29
  const sm = manager();
29
30
  const captured = makeExtension(sm);
30
31
  const early = context(sm, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
31
- assert.equal(await runContextHook(captured, early), undefined, "early guidance is persisted at turn_end, not injected immediately");
32
+ assert.equal((await runContextHook(captured, early))?.messages.length, 1, "early guidance reaches the crossing request");
32
33
  await commitTurnEndBoundary(captured, sm, early);
33
34
  await runHandlers(captured, "agent_settled", {}, early);
34
35
  assert.equal(noticesOf(early).filter((notice) => notice.message.includes("Context running low") || notice.message.includes("Context almost full")).length, 0, "early model guidance has no UI toast");
@@ -39,7 +40,7 @@ test("early guidance stays silent and the committed final warning notifies once"
39
40
  await commitTurnEndBoundary(captured, sm, final);
40
41
  await runHandlers(captured, "turn_start", {}, final);
41
42
  await runHandlers(captured, "agent_settled", {}, final);
42
- assert.equal(noticesOf(final).filter((notice) => notice.message === "notesoup: context almost full; close out the current memory window.").length, 1, "only the committed final warning notifies, exactly once");
43
+ assert.equal(noticesOf(final).filter((notice) => notice.message === "🥣 Context almost full · saving notes before memory clears").length, 1, "only the committed final warning notifies, exactly once");
43
44
  });
44
45
  test("the visible countdown ends at the warning line, clamps at zero, and preserves unknown usage", async () => {
45
46
  const fixture = settingsFixture({
@@ -83,7 +84,7 @@ test("absent notesoup key or margins reproduce the default reminder threshold at
83
84
  assert.equal(await runContextHook(captured, first), undefined, `${label}: nothing injected above the default reminder`);
84
85
  assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0, `${label}: no guidance above the default reminder`);
85
86
  const crossing = at(40_960);
86
- assert.equal(await runContextHook(captured, crossing), undefined, `${label}: default reminder crossing persists only`);
87
+ assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, `${label}: default reminder crossing reaches the request`);
87
88
  await commitTurnEndBoundary(captured, sm, crossing);
88
89
  assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, `${label}: default reminder fires`);
89
90
  assert.equal(noticesOf(first).length, 0, `${label}: valid defaults warn nobody`);
@@ -104,7 +105,7 @@ test("project notesoup reminder margin and reserve override global per key", asy
104
105
  assert.equal(await runContextHook(captured, at(90_001)), undefined, "nothing injected above the project-derived reminder");
105
106
  assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0);
106
107
  const crossing = at(90_000);
107
- assert.equal(await runContextHook(captured, crossing), undefined, "project-derived reminder crossing persists only");
108
+ assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, "project-derived reminder crossing reaches the request");
108
109
  await commitTurnEndBoundary(captured, sm, crossing);
109
110
  assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "project reminder margin wins");
110
111
  });
@@ -118,14 +119,14 @@ test("an invalid reminder margin degrades to its default with one warning and ne
118
119
  assert.equal(notices.length, 1, "one warning for the offending key");
119
120
  assert.equal(notices[0]?.type, "warning");
120
121
  assert.match(notices[0]?.message ?? "", /reminderMarginTokens/);
121
- assert.match(notices[0]?.message ?? "", /default reminder margin/);
122
+ assert.match(notices[0]?.message ?? "", /using the default/);
122
123
  assert.equal(/\d+\s*k?\s*(remaining|tokens)/i.test(notices[0]?.message ?? ""), false, "UI notices do not expose token counts");
123
124
  const window = 200_000;
124
125
  const at = (remaining) => context(sm, undefined, { tokens: window - remaining, percent: 0, contextWindow: window }, true, fixture.cwd);
125
126
  // The degraded reminder is Pi's default reserve + default margin = 40960.
126
127
  assert.equal(await runContextHook(captured, at(40_961)), undefined, "nothing injected above the degraded reminder");
127
128
  const crossing = at(40_960);
128
- assert.equal(await runContextHook(captured, crossing), undefined, "degraded reminder uses its default");
129
+ assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, "degraded reminder uses its default");
129
130
  await commitTurnEndBoundary(captured, sm, crossing);
130
131
  assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "the degraded reminder is persisted once");
131
132
  assert.equal(noticesOf(ctx).filter((notice) => notice.type === "warning").length, 1, "warning stays one-time across handler calls");
@@ -139,6 +140,6 @@ test("the warning supersedes the early reminder when usage jumps across both thr
139
140
  assert.deepEqual(warningResult?.messages.map((message) => message.customType), [WARNING_TYPE]);
140
141
  await commitTurnEndBoundary(captured, sm, ctx);
141
142
  const reloaded = makeExtension(sm);
142
- await runHandlers(reloaded, "context", {}, ctx);
143
+ await runHandlers(reloaded, "context", { messages: [] }, ctx);
143
144
  assert.equal(reloaded.sent.length, 0, "persisted warning also suppresses a late reminder after reload");
144
145
  });
@@ -81,8 +81,8 @@ test("Claude helper refuses schema-invalid parameters before any operation runs"
81
81
  const cases = [
82
82
  { name: "a string offset", params: { address, offset_chars: "0" } },
83
83
  { name: "a fractional offset", params: { address, offset_chars: 0.5 } },
84
- { name: "a zero limit", params: { address, limit_chars: 0 } },
85
- { name: "a limit past the maximum", params: { address, limit_chars: 999_999_999 } },
84
+ { name: "a zero limit", params: { address, max_chars: 0 } },
85
+ { name: "a limit past the maximum", params: { address, max_chars: 999_999_999 } },
86
86
  ];
87
87
  for (const { name, params } of cases) {
88
88
  const refused = JSON.parse(await handleLine(JSON.stringify({ op: "tool", tool: "notes_read", identity, params })));
@@ -95,14 +95,14 @@ test("Claude helper refuses schema-invalid parameters before any operation runs"
95
95
  const absent = await callTool("notes_read", { address: "rejected.md" });
96
96
  assert.equal(absent.outcome.ok, false);
97
97
  assert.equal(absent.outcome.error?.code, "not_found", "the refused write never reached the store");
98
- const valid = await callTool("notes_read", { address, offset_chars: 0, limit_chars: 8 });
98
+ const valid = await callTool("notes_read", { address, offset_chars: 0, max_chars: 8 });
99
99
  assert.equal(valid.outcome.ok, true, "a schema-valid window still reads");
100
100
  assert.match(valid.text, /^boundary\.md/);
101
101
  });
102
102
  test("Claude helper boot uses actual Claude note tool bindings and a fresh snapshot", async () => {
103
103
  const boot = await dispatch({ op: "boot", identity, openedAt: 1700000000000, tools: {
104
104
  notes: "mcp__notesoup__notes_*", notesList: "mcp__notesoup__notes_list",
105
- history: "history unavailable", historyWindows: "history_windows unavailable", historyList: "history_list unavailable", historySearch: "history_search unavailable", historyRead: "history_read unavailable",
105
+ history: "history unavailable",
106
106
  remaining: "remaining unavailable", wipe: "wipe unavailable",
107
107
  } });
108
108
  assert.match(boot, /mcp__notesoup__notes_\*/);
@@ -209,8 +209,8 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
209
209
  ...upstream,
210
210
  blocks: [...upstream.blocks, { name: "notesoup:boot", text: "# notesoup\nhelper exited unsuccessfully" }],
211
211
  }, "boot failure keeps the original fallback and upstream fields even if notify is absent or fails");
212
- const expectedNotifications = mode === "no ui" || mode === "no notify" ? [] : ["notesoup: Notes boot failed."];
213
- assert.deepEqual(notifications, expectedNotifications, "one user-facing notification names notesoup and the notes boot failure");
212
+ const expectedNotifications = mode === "no ui" || mode === "no notify" ? [] : ["🥣 Notes didn't load"];
213
+ assert.deepEqual(notifications, expectedNotifications, "one user-facing notification reports the notes boot failure");
214
214
  assert.equal(bootRequests, 1);
215
215
  assert.equal(nextCalls, 1);
216
216
  assert.deepEqual(await promptContext(structuredClone(failed)), failed);
@@ -274,7 +274,7 @@ test("Claude Mod resets at 85 after the turn, retains one fresh boot and dedupli
274
274
  host.session.usage = async () => { throw new Error("usage unavailable"); };
275
275
  await invoke("session.measure");
276
276
  await invoke("turn.complete");
277
- assert.equal(notifications.filter((text) => text.includes("context usage unavailable")).length, 1, "usage failure logs once per session");
277
+ assert.equal(notifications.filter((text) => text.includes("Context usage unavailable")).length, 1, "usage failure logs once per session");
278
278
  host.session.usage = async () => ({ context: { percent } });
279
279
  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" } });
280
280
  await invoke("turn.start");
@@ -316,9 +316,9 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
316
316
  await invoke("session.measure");
317
317
  await invoke("turn.complete");
318
318
  assert.equal(attempts, 0, "headless sessions skip the unsupported capability from startup");
319
- assert.deepEqual(notifications, ["notesoup: reset skipped in headless (-p / SDK) session."]);
319
+ assert.deepEqual(notifications, ["🥣 Clear-memory is off in headless (-p / SDK) sessions"]);
320
320
  const manual = await invoke("command.run", { command: "clear-memory" });
321
- assert.match(manual.text, /reset skipped in headless/);
321
+ assert.match(manual.text, /off in headless/);
322
322
  assert.equal(notifications.length, 1);
323
323
  const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
324
324
  assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
@@ -343,7 +343,7 @@ test("Claude Mod refuses to wipe on boot failure and can retry without advancing
343
343
  host.session.compact = async ({ instructions }) => result = await invoke("session.compact", { trigger: "plugin", instructions });
344
344
  await invoke("turn.start");
345
345
  await invoke("turn.complete");
346
- assert.match(result.skip, /Notes boot failed/);
346
+ assert.match(result.skip, /notes didn't load/);
347
347
  assert.equal(result.messages, undefined, "a failed builder must veto rather than fall through to summary");
348
348
  failBoot = false;
349
349
  await invoke("turn.start");
@@ -376,7 +376,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
376
376
  (await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
377
377
  await invoke("session.start", { cwd: home, isInteractive: true });
378
378
  const command = await invoke("command.run", { command: "clear-memory" });
379
- assert.match(command.text, /closing out/);
379
+ assert.match(command.text, /Clearing memory/);
380
380
  await Promise.resolve();
381
381
  assert.equal(compactions, 0, "command.run must not call compact under its held turn");
382
382
  assert.equal(timers.length, 1);
@@ -93,7 +93,7 @@ test("configured extension source and moved dream CLI are executable current ent
93
93
  registerTool(tool) { tools.push(tool); },
94
94
  registerCommand(name) { commands.push(name); },
95
95
  });
96
- assert.deepEqual(tools.map((tool) => tool.name).sort(), ["clear_memory", "get_context_remaining", "history_list", "history_read", "history_search", "history_windows", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
96
+ assert.deepEqual(tools.map((tool) => tool.name).sort(), ["clear_memory", "get_context_remaining", "history_list", "history_read", "history_windows", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
97
97
  assert.deepEqual(commands.sort(), ["clear-memory", "cm", "notesoup"]);
98
98
  const help = execFileSync(process.execPath, [resolve(root, manifest.bin.dream), "--help"], { cwd: root, encoding: "utf8" });
99
99
  assert.ok(help.startsWith("dream doctor [--notes-home <dir>]"));
@@ -210,8 +210,7 @@ function isTextWindow(value) {
210
210
  if (typeof value !== "object" || value === null)
211
211
  return false;
212
212
  const candidate = value;
213
- return typeof candidate.text === "string" && typeof candidate.offset_chars === "number" &&
214
- typeof candidate.total_chars === "number" &&
213
+ return typeof candidate.text === "string" && typeof candidate.total_chars === "number" &&
215
214
  (candidate.next_offset_chars === null || typeof candidate.next_offset_chars === "number");
216
215
  }
217
216
  /** Data of a successful outcome, asserting both the structured success and the non-error result. */
@@ -225,7 +224,7 @@ export function resultData(result) {
225
224
  export function resultError(result) {
226
225
  const outcome = outcomeOf(result);
227
226
  assert.equal(result.isError, true, "a refusal is delivered as an error result");
228
- const error = { code: outcome.code, message: outcome.error, ...(outcome.details === undefined ? {} : { details: outcome.details }) };
227
+ const error = { code: outcome.code, message: outcome.error };
229
228
  assert.ok(isOperationError(error), "refusal carries a code and an error message");
230
229
  return error;
231
230
  }