notesoup 0.51.1 → 0.51.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/plugins/pi/entries.d.ts +2 -0
  2. package/dist/plugins/pi/entries.js +2 -0
  3. package/dist/plugins/pi/reset/artifacts.d.ts +10 -2
  4. package/dist/plugins/pi/reset/artifacts.js +24 -5
  5. package/dist/plugins/pi/reset/lifecycle.d.ts +37 -21
  6. package/dist/plugins/pi/reset/lifecycle.js +132 -57
  7. package/dist/plugins/pi/runtime.js +9 -10
  8. package/dist/plugins/pi/text.d.ts +11 -14
  9. package/dist/plugins/pi/text.js +15 -16
  10. package/dist/test/agent-loop.test.js +316 -163
  11. package/dist/test/boot.integration.test.js +3 -3
  12. package/dist/test/claude-validation.test.js +4 -2
  13. package/dist/test/dsh-cli.test.js +7 -6
  14. package/dist/test/helpers/dsh-messages.js +3 -0
  15. package/dist/test/model-facing-text.test.js +10 -4
  16. package/dist/test/reset-lifecycle.test.js +272 -88
  17. package/docs/architecture.md +1 -1
  18. package/docs/reset-lifecycle.md +42 -57
  19. package/package.json +2 -2
  20. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  21. package/plugins/paseo/OVERVIEW.md +7 -0
  22. package/plugins/paseo/README.md +12 -0
  23. package/plugins/paseo/client/source-row.ts +14 -0
  24. package/plugins/paseo/client/sticky-card.tsx +21 -0
  25. package/plugins/paseo/index.client.tsx +10 -0
  26. package/plugins/paseo/package.json +19 -0
  27. package/plugins/paseo/paseo-plugin.json +4 -0
  28. package/plugins/paseo/shared/last-word.ts +6 -0
  29. package/plugins/paseo/test/source-row.test.ts +19 -0
  30. package/plugins/paseo/tsconfig.json +16 -0
  31. package/plugins/pi/entries.ts +2 -0
  32. package/plugins/pi/reset/artifacts.ts +26 -5
  33. package/plugins/pi/reset/lifecycle.ts +135 -70
  34. package/plugins/pi/runtime.ts +9 -10
  35. package/plugins/pi/text.ts +17 -17
@@ -6,14 +6,15 @@ import test from "node:test";
6
6
  import { Check } from "typebox/value";
7
7
  import { SessionManager as Manager } from "@earendil-works/pi-coding-agent";
8
8
  import notesoup from "../plugins/pi/extension.js";
9
- import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../plugins/pi/entries.js";
9
+ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../plugins/pi/entries.js";
10
10
  import { MANUAL_WIPE_TYPE } from "../plugins/pi/entries.js";
11
11
  import { assertBootHistory, toolContext } from "./helpers/extension.js";
12
12
  import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, NORMAL_CONTINUATIONS } from "../src/budget/text.js";
13
- import { LAST_WORD_HINT, WARNING_CALL_PROMPTED, warningContent } from "../plugins/pi/text.js";
13
+ import { LAST_WORD_HINT, commandWarningContent } from "../plugins/pi/text.js";
14
14
  import { historyFromSession, nextHistorySeq } from "../plugins/pi/history.js";
15
- import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../plugins/pi/reset/artifacts.js";
16
- import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../plugins/pi/reset/lifecycle.js";
15
+ import { buildResetDrafts, inspectResetTail, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "../plugins/pi/reset/artifacts.js";
16
+ import { resetBoundaryCommitted } from "../plugins/pi/reset/committed.js";
17
+ import { finalizeResetBoundary, initialResetControl, reduceResetControl, registerResetLifecycle, } from "../plugins/pi/reset/lifecycle.js";
17
18
  const previousNotesHome = process.env.PI_NOTES_HOME;
18
19
  const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
19
20
  process.env.PI_NOTES_HOME = testNotesHome;
@@ -121,6 +122,14 @@ function appendDrafts(sessionManager, entries) {
121
122
  }
122
123
  }
123
124
  }
125
+ function boundaryIntent(decision) {
126
+ assert.ok(decision.effect === "build-boundary", "expected construction intent, not a state transition");
127
+ return decision;
128
+ }
129
+ function controlState(decision) {
130
+ assert.ok(decision.effect !== "build-boundary", "expected a state transition, not construction intent");
131
+ return decision.state;
132
+ }
124
133
  function turnEndFacts(overrides = {}) {
125
134
  return {
126
135
  windowId: "pcw:test:window",
@@ -235,14 +244,13 @@ test("off stops future automatic/manual reset requests while an existing marker
235
244
  assert.equal(h.sent[0]?.customType, MANUAL_WIPE_TYPE);
236
245
  const warning = h.sessionManager.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE);
237
246
  assert.ok(warning && warning.type === "custom_message");
238
- assert.equal(warning.content, warningContent());
247
+ assert.equal(warning.content, commandWarningContent());
239
248
  const markers = h.sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
240
249
  assert.equal(markers.length, 1, "manual command waits for an agent boundary; it does not persist an immediate reset");
241
250
  });
242
251
  test("manual /empty with a prompt shows the human's command line in the close-out", async () => {
243
252
  const h = harness();
244
- // Assert on values, not on the warning's wording: the command line must survive verbatim
245
- // and must precede the closing instruction, so the prompt cannot read as this window's task.
253
+ // Structure and carried values are checked here; exact copy lives in model-facing-text tests.
246
254
  await h.runCommand("empty", "Continue reviewing the implementation");
247
255
  const warning = h.sessionManager.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE);
248
256
  assert.ok(warning?.type === "custom_message", "the close-out warning is persisted");
@@ -250,11 +258,10 @@ test("manual /empty with a prompt shows the human's command line in the close-ou
250
258
  const promptLine = "/empty Continue reviewing the implementation";
251
259
  const promptIndex = content.indexOf(promptLine);
252
260
  assert.ok(promptIndex >= 0, "the human's raw command line reaches the closing model");
253
- const closingIndex = content.indexOf(WARNING_CALL_PROMPTED);
254
- assert.ok(closingIndex > promptIndex, "the closing instruction follows the prompt, so the order stays prompt then act");
261
+ assert.ok(promptIndex > content.indexOf("</notesoup:budget_notice>"), "deferred work is outside the notice");
255
262
  assert.ok(content.indexOf(COUNTDOWN_LINE) > content.indexOf(LAST_WORD_HINT), "the countdown follows the Pi-only last-word hint");
256
263
  assert.equal(content.split(COUNTDOWN_LINE).length - 1, 1, "the notice carries the countdown once");
257
- // The prompt was a note-to-self for the closing window: it never becomes the next window's task.
264
+ // The same original text becomes the new window's task, not a notes-only hint.
258
265
  const settle = resultEntries(await h.emit("agent_before_settle", {
259
266
  type: "agent_before_settle",
260
267
  entries: [],
@@ -267,7 +274,134 @@ test("manual /empty with a prompt shows the human's command line in the close-ou
267
274
  RESET_MARKER_TYPE,
268
275
  BOOT_TYPE,
269
276
  CONTINUATION_TYPE,
270
- ], "the reset tail is one boot, one continuation, and no persisted prompt");
277
+ CARRIED_INPUT_TYPE,
278
+ ], "the reset tail ends with the carried human input");
279
+ assert.deepEqual(settle.entries.at(-1), { type: "custom_message", customType: CARRIED_INPUT_TYPE, content: "Continue reviewing the implementation", display: true });
280
+ });
281
+ test("input arriving during reset construction survives even when the hidden steer is never delivered", async () => {
282
+ const sessionManager = Manager.inMemory("/private/tmp/notesoup-late-input-test");
283
+ const handlers = new Map();
284
+ const steers = [];
285
+ const api = {
286
+ on(name, handler) { handlers.set(name, handler); },
287
+ sendMessage(message, options) { steers.push({ message, options }); },
288
+ };
289
+ const ctx = {
290
+ cwd: "/private/tmp", sessionManager, model: undefined, hasPendingMessages: () => false,
291
+ isProjectTrusted: () => true, ui: { notify() { } },
292
+ };
293
+ let release;
294
+ const gate = new Promise((resolve) => { release = resolve; });
295
+ const lifecycle = registerResetLifecycle(api, {
296
+ isEnabled: () => true,
297
+ budget: { automaticResetEnabled: () => true, hardReserveDue: () => false, consumeTurnEnd: () => [], clear() { } },
298
+ async buildReset(ctx, isCurrent, lastWord, firstSeq, origin) {
299
+ await gate;
300
+ return buildResetDrafts(ctx, undefined, isCurrent, lastWord, firstSeq, origin);
301
+ },
302
+ });
303
+ lifecycle.command(`pcw:${sessionManager.getSessionId().slice(0, 8)}:root`, false);
304
+ lifecycle.request(`pcw:${sessionManager.getSessionId().slice(0, 8)}:root`, "handoff");
305
+ const pending = handlers.get("agent_before_settle")({ ...fakeBoundaryEvent(), type: "agent_before_settle" }, ctx);
306
+ assert.equal(await handlers.get("input")({ source: "extension", text: "not intercepted" }, ctx), undefined);
307
+ assert.deepEqual(await handlers.get("input")({ source: "rpc", text: " first\ninput " }, ctx), { action: "handled" });
308
+ assert.deepEqual(await handlers.get("input")({ source: "interactive", text: "second" }, ctx), { action: "handled" });
309
+ release();
310
+ const boundary = resultEntries([await pending]);
311
+ assert.equal(boundary.continue, true, "late input overrides the bare command's stop");
312
+ assert.deepEqual(boundary.entries.slice(-2).map((entry) => entry.type === "custom_message" ? entry.content : null), [" first\ninput ", "second"]);
313
+ assert.equal(steers.length, 2, "steers were queued but never delivered by this host");
314
+ appendDrafts(sessionManager, boundary.entries);
315
+ const marker = sessionManager.getBranch().find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
316
+ const windowId = marker.data.windowId;
317
+ assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true);
318
+ assert.deepEqual(inspectResetTail(ctx, marker.id, windowId), { boot: true, continuation: true }, "last word and trailing inputs form a complete ordered boundary");
319
+ await repairResetTail(api, ctx, marker);
320
+ assert.equal(steers.length, 2, "repair never duplicates a complete boundary with carried inputs");
321
+ sessionManager.appendCustomMessageEntry(BOOT_TYPE, "late boot", false, { windowId });
322
+ assert.equal(inspectResetTail(ctx, marker.id, windowId), undefined, "artifacts cannot restart after carried input");
323
+ assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true, "later malformed work does not undo a committed prefix");
324
+ sessionManager.appendCompaction("", null, 0);
325
+ const partialMarker = sessionManager.appendCustomEntry(RESET_MARKER_TYPE, { windowId: "partial" });
326
+ sessionManager.appendCustomMessageEntry(BOOT_TYPE, "boot", false, { windowId: "partial" });
327
+ sessionManager.appendCustomMessageEntry(CARRIED_INPUT_TYPE, "too early", true);
328
+ assert.equal(inspectResetTail(ctx, partialMarker, "partial"), undefined, "repair cannot append a continuation after human content");
329
+ assert.equal(resetBoundaryCommitted(ctx, partialMarker, "partial"), false);
330
+ });
331
+ test("overflow construction reads live run inputs and clear invalidates an unfinished build", async () => {
332
+ const sessionManager = Manager.inMemory("/private/tmp/notesoup-live-passive-input-test");
333
+ const handlers = new Map();
334
+ const api = { on(name, handler) { handlers.set(name, handler); } };
335
+ const ctx = { sessionManager, model: undefined, hasPendingMessages: () => false, ui: { notify() { } } };
336
+ let release;
337
+ let readyCount = 0;
338
+ const lifecycle = registerResetLifecycle(api, {
339
+ isEnabled: () => true,
340
+ budget: { automaticResetEnabled: () => true, hardReserveDue: () => false, consumeTurnEnd: () => [], clear() { } },
341
+ buildReset: () => new Promise((resolve) => { release = resolve; }),
342
+ onResetReady: () => { readyCount++; },
343
+ });
344
+ const user = (content) => handlers.get("message_end")({ message: { role: "user", content } }, ctx);
345
+ const failed = { ...fakeBoundaryEvent(), outcome: "error", message: { role: "assistant", stopReason: "error", errorMessage: "Prompt too long: context exceeds maximum context length" } };
346
+ const recover = async () => {
347
+ await handlers.get("turn_end")(failed, ctx);
348
+ return handlers.get("agent_before_settle")({ ...failed, type: "agent_before_settle" }, ctx);
349
+ };
350
+ await user("starting input");
351
+ const building = recover();
352
+ await Promise.resolve();
353
+ await user("delivered during construction");
354
+ release([]);
355
+ const result = resultEntries([await building]);
356
+ assert.equal(result.continue, true);
357
+ assert.deepEqual(result.entries.map((entry) => entry.type === "custom_message" ? entry.content : null), ["starting input", "delivered during construction"]);
358
+ lifecycle.clear();
359
+ await user("old run");
360
+ const stale = recover();
361
+ await Promise.resolve();
362
+ lifecycle.clear();
363
+ await user("new run");
364
+ release([{ type: "custom_message", customType: BOOT_TYPE, content: "stale", display: false }]);
365
+ assert.equal(await stale, undefined, "clearing the run invalidates construction before it can consume new inputs");
366
+ assert.equal(readyCount, 1);
367
+ const current = recover();
368
+ await Promise.resolve();
369
+ release([]);
370
+ const fresh = resultEntries([await current]);
371
+ assert.deepEqual(fresh.entries.map((entry) => entry.type === "custom_message" ? entry.content : null), ["new run"]);
372
+ });
373
+ test("abort during reset construction restores handled input at settlement, once", async () => {
374
+ const sessionManager = Manager.inMemory("/private/tmp/notesoup-cancelled-build-test");
375
+ const handlers = new Map();
376
+ const sent = [];
377
+ const api = {
378
+ on(name, handler) { handlers.set(name, handler); },
379
+ sendMessage(message, options) { sent.push({ message, options }); },
380
+ };
381
+ const controller = new AbortController();
382
+ const ctx = { sessionManager, signal: controller.signal, hasPendingMessages: () => false, ui: { notify() { } } };
383
+ let release;
384
+ const gate = new Promise((resolve) => { release = resolve; });
385
+ const lifecycle = registerResetLifecycle(api, {
386
+ isEnabled: () => true,
387
+ budget: { automaticResetEnabled: () => false, hardReserveDue: () => false, consumeTurnEnd: () => [], clear() { } },
388
+ async buildReset() { await gate; return []; },
389
+ });
390
+ const windowId = `pcw:${sessionManager.getSessionId().slice(0, 8)}:root`;
391
+ lifecycle.command(windowId, false);
392
+ const building = handlers.get("agent_before_settle")({ ...fakeBoundaryEvent(), type: "agent_before_settle" }, ctx);
393
+ assert.deepEqual(await handlers.get("input")({ source: "rpc", text: "cancelled during construction" }, ctx), { action: "handled" });
394
+ controller.abort();
395
+ release();
396
+ assert.equal(await building, undefined, "aborted construction must not commit a reset");
397
+ await handlers.get("agent_settled")({}, ctx);
398
+ await handlers.get("agent_settled")({}, ctx);
399
+ const restored = sent.filter((item) => item.message.customType === CARRIED_INPUT_TYPE);
400
+ assert.deepEqual(restored, [{ message: { type: "custom_message", customType: CARRIED_INPUT_TYPE, content: "cancelled during construction", display: true }, options: { triggerTurn: false } }]);
401
+ // A later command in the same window must not revive the cancelled command's steer.
402
+ lifecycle.command(windowId, false);
403
+ const stale = { role: "custom", ...sent[0].message };
404
+ assert.deepEqual(await handlers.get("context_with_system")({ messages: [stale] }, ctx), { messages: [] });
271
405
  });
272
406
  test("reset construction failure preserves incoming and budget drafts without continuation", async () => {
273
407
  const sessionManager = Manager.inMemory("/private/tmp/notesoup-reset-failure-test");
@@ -456,12 +590,14 @@ test("reset-control: command policy deduplicates, spans turns, and retains a rea
456
590
  assert.equal(duplicate.effect, "already-pending");
457
591
  const noteTurn = reduceResetControl(first.state, { type: "turn_end", facts: turnEndFacts() });
458
592
  assert.equal(noteTurn.effect, "none");
459
- assert.deepEqual(noteTurn.state.request, first.state.request, "note/tool turns do not consume close-out");
460
- const tool = reduceResetControl(noteTurn.state, { type: "tool_request", windowId });
593
+ assert.deepEqual(controlState(noteTurn).request, first.state.request, "note/tool turns do not consume close-out");
594
+ const tool = reduceResetControl(controlState(noteTurn), { type: "tool_request", windowId });
461
595
  assert.equal(tool.effect, "close-out-armed", "the first tool call is recorded without changing settlement policy");
462
596
  assert.deepEqual(tool.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
463
- const commit = reduceResetControl(tool.state, { type: "before_settle", facts: beforeSettleFacts() });
464
- assert.equal(commit.effect, "commit-boundary-stop", "a manual close-out commits at settlement and stops");
597
+ const decision = reduceResetControl(tool.state, { type: "before_settle", facts: beforeSettleFacts() });
598
+ assert.equal(decision.effect, "build-boundary", "construction intent has no final state to install");
599
+ const commit = finalizeResetBoundary(boundaryIntent(decision), tool.state.request);
600
+ assert.equal(commit.resumeModel, false, "a manual close-out commits at settlement and stops");
465
601
  assert.deepEqual(commit.state, initialResetControl());
466
602
  });
467
603
  test("reset-control: command settlement policy preserves a pending tool request", () => {
@@ -471,7 +607,8 @@ test("reset-control: command settlement policy preserves a pending tool request"
471
607
  assert.equal(manual.effect, "close-out-armed", "the user's stop intent outranks the pending rollover");
472
608
  assert.deepEqual(manual.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
473
609
  assert.equal(reduceResetControl(manual.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none", "the converted request no longer commits at turn end");
474
- assert.equal(reduceResetControl(manual.state, { type: "before_settle", facts: beforeSettleFacts() }).effect, "commit-boundary-stop");
610
+ const intent = boundaryIntent(reduceResetControl(manual.state, { type: "before_settle", facts: beforeSettleFacts() }));
611
+ assert.equal(finalizeResetBoundary(intent, manual.state.request).resumeModel, false);
475
612
  });
476
613
  test("reset-control: duplicate commands preserve policy and both call orders retain the tool's last word", () => {
477
614
  const windowId = "pcw:test:window";
@@ -488,113 +625,159 @@ test("reset-control: duplicate commands preserve policy and both call orders ret
488
625
  assert.equal(repeated.effect, "already-pending");
489
626
  assert.deepEqual(repeated.state, commandThenTool.state);
490
627
  assert.equal(reduceResetControl(repeated.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none");
491
- const commit = reduceResetControl(repeated.state, { type: "before_settle", facts: beforeSettleFacts() });
492
- assert.equal(commit.effect, "commit-boundary");
493
- assert.equal(commit.lastWord, "pick up here");
628
+ const intent = boundaryIntent(reduceResetControl(repeated.state, { type: "before_settle", facts: beforeSettleFacts() }));
629
+ assert.equal(intent.tool?.lastWord, "pick up here");
630
+ const commit = finalizeResetBoundary(intent, repeated.state.request);
631
+ assert.equal(commit.resumeModel, true, "explicit continue policy does not require delivery contents");
632
+ assert.deepEqual(commit.inputs, []);
494
633
  });
495
634
  test("reset-control: a tool request needs no prior budget warning", () => {
496
635
  const windowId = "pcw:test:window";
497
636
  const requested = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
498
637
  assert.equal(requested.effect, "close-out-armed");
499
638
  assert.deepEqual(requested.state.request, { phase: "pending", windowId, tool: {} });
500
- assert.equal(reduceResetControl(requested.state, { type: "turn_end", facts: turnEndFacts() }).effect, "commit-boundary");
639
+ const intent = boundaryIntent(reduceResetControl(requested.state, { type: "turn_end", facts: turnEndFacts() }));
640
+ assert.equal(finalizeResetBoundary(intent, requested.state.request).resumeModel, true);
501
641
  });
502
642
  test("reset-control: fallback is normal-stop only; hard reserve remains safety", () => {
503
643
  const windowId = "pcw:test:window";
504
644
  const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
505
- const fallback = reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() });
506
- assert.equal(fallback.effect, "commit-boundary-stop", "manual close-out stops after the reset is committed");
645
+ const intent = boundaryIntent(reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() }));
646
+ const fallback = finalizeResetBoundary(intent, manual.request);
647
+ assert.equal(fallback.resumeModel, false, "manual close-out stops after the reset is committed");
507
648
  assert.deepEqual(fallback.state, initialResetControl());
508
649
  const automatic = initialResetControl();
509
650
  const normalStop = reduceResetControl(automatic, { type: "before_settle", facts: beforeSettleFacts() });
510
651
  assert.equal(normalStop.effect, "none", "ignoring a budget warning and answering normally must not wipe memory");
511
- assert.deepEqual(normalStop.state, initialResetControl());
652
+ assert.deepEqual(controlState(normalStop), initialResetControl());
512
653
  const disabledAuto = reduceResetControl(automatic, { type: "before_settle", facts: beforeSettleFacts({ automaticResetEnabled: false }) });
513
654
  assert.equal(disabledAuto.effect, "none");
514
- assert.deepEqual(disabledAuto.state, initialResetControl());
655
+ assert.deepEqual(controlState(disabledAuto), initialResetControl());
515
656
  const safety = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
516
- assert.equal(safety.effect, "commit-boundary");
657
+ assert.equal(finalizeResetBoundary(boundaryIntent(safety), automatic.request).resumeModel, true);
517
658
  for (const outcome of [{ failed: true }, { aborted: true }]) {
518
659
  const notNormalStop = reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts(outcome) });
519
660
  assert.equal(notNormalStop.effect, "none");
520
- assert.deepEqual(notNormalStop.state, initialResetControl());
661
+ assert.deepEqual(controlState(notNormalStop), initialResetControl());
521
662
  }
522
- assert.deepEqual(reduceResetControl(manual, { type: "settled" }).state, initialResetControl());
523
663
  });
524
664
  test("reset-control: manual stop survives a hard-reserve reset across windows without a second wipe", () => {
525
665
  const windowId = "pcw:test:window";
526
666
  const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
527
- const safety = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
528
- assert.equal(safety.effect, "commit-boundary-stop");
529
- assert.deepEqual(safety.state.request, { phase: "stop-pending", windowId });
667
+ const decision = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
668
+ assert.equal(decision.effect, "build-boundary", "construction does not install the stop latch");
669
+ const safety = finalizeResetBoundary(boundaryIntent(decision), manual.request);
670
+ assert.equal(safety.resumeModel, false);
671
+ assert.deepEqual(safety.state.request, { phase: "none" });
672
+ assert.deepEqual(safety.state.stopAfterReset, decision);
530
673
  const freshWindowId = "pcw:test:fresh";
531
674
  assert.equal(reduceResetControl(safety.state, { type: "tool_request", windowId: freshWindowId }).effect, "already-pending");
532
675
  assert.equal(reduceResetControl(safety.state, { type: "command", windowId: freshWindowId, continueAfterReset: false }).effect, "already-pending");
533
676
  const queued = reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId, queued: true }) });
534
- assert.deepEqual(queued.state, safety.state);
535
- const freshTurn = reduceResetControl(queued.state, { type: "turn_end", facts: turnEndFacts({ windowId: freshWindowId, hardReserveDue: true }) });
677
+ assert.deepEqual(controlState(queued), safety.state);
678
+ const freshTurn = reduceResetControl(controlState(queued), { type: "turn_end", facts: turnEndFacts({ windowId: freshWindowId, hardReserveDue: true }) });
536
679
  assert.equal(freshTurn.effect, "none");
537
- const stop = reduceResetControl(freshTurn.state, { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId }) });
680
+ const stop = reduceResetControl(controlState(freshTurn), { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId }) });
538
681
  assert.equal(stop.effect, "stop", "the safety boundary already wiped; settlement must only stop");
539
- assert.deepEqual(stop.state, initialResetControl());
540
- assert.equal(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts() }).effect, "commit-boundary-stop", "a failed safety construction may be retried before settlement");
541
- assert.deepEqual(reduceResetControl(safety.state, { type: "abort" }).state, initialResetControl());
682
+ assert.deepEqual(controlState(stop), initialResetControl());
683
+ const uncommitted = boundaryIntent(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts() }));
684
+ assert.equal(uncommitted.continueAfterReset, false, "same-window retry retains the stop policy");
685
+ const retried = finalizeResetBoundary(uncommitted, safety.state.request);
686
+ assert.equal(retried.resumeModel, false);
687
+ assert.deepEqual(retried.state, initialResetControl(), "settle retry consumes the stop latch");
688
+ const retry = boundaryIntent(reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() }));
689
+ assert.equal(finalizeResetBoundary(retry, manual.request).resumeModel, false, "a failed safety construction leaves the command available for settlement retry");
690
+ assert.deepEqual(controlState(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId, aborted: true }) })), initialResetControl());
691
+ });
692
+ test("reset-control: one safety intent finalizes stop or continuation from live command originals", () => {
693
+ const windowId = "pcw:test:window";
694
+ const pending = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
695
+ const intent = boundaryIntent(reduceResetControl(pending, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) }));
696
+ assert.deepEqual(pending.request, { phase: "pending", windowId, command: { continueAfterReset: false } });
697
+ const stopped = finalizeResetBoundary(intent, pending.request, ["passive run input"]);
698
+ assert.equal(stopped.resumeModel, false);
699
+ assert.deepEqual(stopped.inputs, [], "a command boundary never replays passive run input");
700
+ assert.deepEqual(stopped.state.stopAfterReset, intent);
701
+ const live = reduceResetControl(pending, { type: "input", windowId, input: "late original" }).state;
702
+ const continued = finalizeResetBoundary(intent, live.request, ["passive run input"]);
703
+ assert.equal(continued.resumeModel, true);
704
+ assert.deepEqual(continued.inputs, ["late original"]);
705
+ assert.deepEqual(continued.state, initialResetControl(), "late originals prevent installing the stop latch");
706
+ assert.equal(intent.continueAfterReset, false, "delivery does not rewrite explicit command policy");
707
+ assert.deepEqual(live.request, { phase: "pending", windowId, command: { continueAfterReset: false, inputs: ["late original"] } }, "finalization is pure");
542
708
  });
543
709
  test("reset-control: manual overflow keeps stop intent while queued work supersedes the failure", () => {
544
710
  const windowId = "pcw:test:window";
545
711
  const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
546
- const overflow = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, queued: true, automaticResetEnabled: false }) });
547
- assert.deepEqual(overflow.state.request, manual.request);
548
- const deferred = reduceResetControl(overflow.state, { type: "before_settle", facts: beforeSettleFacts({ failed: true, queued: true, automaticResetEnabled: false }) });
549
- assert.deepEqual(deferred.state, overflow.state);
550
- assert.equal(reduceResetControl(overflow.state, { type: "before_settle", facts: beforeSettleFacts({ failed: true, automaticResetEnabled: false }) }).effect, "commit-boundary-stop", "manual overflow resets but does not retry the model");
551
- const success = reduceResetControl(deferred.state, { type: "turn_end", facts: turnEndFacts() });
552
- assert.deepEqual(success.state.request, manual.request, "a successful queued turn clears only the overflow, not the manual wipe");
553
- assert.equal(success.state.overflow, "idle");
554
- assert.equal(reduceResetControl(success.state, { type: "before_settle", facts: beforeSettleFacts() }).effect, "commit-boundary-stop");
555
- });
556
- test("reset-control: abort and lifecycle transitions clear every pending phase", () => {
712
+ const overflow = controlState(reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, queued: true, automaticResetEnabled: false }) }));
713
+ assert.deepEqual(overflow.request, manual.request);
714
+ const deferred = controlState(reduceResetControl(overflow, { type: "before_settle", facts: beforeSettleFacts({ failed: true, queued: true, automaticResetEnabled: false }) }));
715
+ assert.deepEqual(deferred, overflow);
716
+ const stopIntent = boundaryIntent(reduceResetControl(overflow, { type: "before_settle", facts: beforeSettleFacts({ failed: true, automaticResetEnabled: false }) }));
717
+ assert.equal(finalizeResetBoundary(stopIntent, overflow.request).resumeModel, false, "manual overflow resets but does not retry the model");
718
+ const success = controlState(reduceResetControl(deferred, { type: "turn_end", facts: turnEndFacts() }));
719
+ assert.deepEqual(success.request, manual.request, "a successful queued turn clears only the overflow, not the manual wipe");
720
+ assert.equal(success.overflow, "idle");
721
+ const successIntent = boundaryIntent(reduceResetControl(success, { type: "before_settle", facts: beforeSettleFacts() }));
722
+ assert.equal(finalizeResetBoundary(successIntent, success.request).resumeModel, false);
723
+ const prompted = reduceResetControl(manual, { type: "input", windowId, input: "answer after reset" }).state;
724
+ const called = reduceResetControl(prompted, { type: "tool_request", windowId, lastWord: "saved" }).state;
725
+ const failed = controlState(reduceResetControl(called, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, automaticResetEnabled: false }) }));
726
+ const decision = reduceResetControl(failed, { type: "before_settle", facts: beforeSettleFacts({ failed: true, automaticResetEnabled: false }) });
727
+ assert.equal(failed.overflow, "pending", "construction alone does not spend overflow recovery");
728
+ const retryIntent = boundaryIntent(decision);
729
+ assert.equal(retryIntent.origin, "forced", "an overflowing close-out is forced even after a tool request");
730
+ assert.equal(retryIntent.tool?.lastWord, "saved");
731
+ const retry = finalizeResetBoundary(retryIntent, failed.request, ["passive input is not command-owned"]);
732
+ assert.equal(retry.resumeModel, true, "manual input continues even when automatic reset is disabled");
733
+ assert.deepEqual(retry.inputs, ["answer after reset"]);
734
+ assert.equal(retry.state.overflow, "spent", "manual recovery spends the same bounded attempt");
735
+ });
736
+ test("reset-control: explicit abort clears a pending request at turn end or settlement", () => {
557
737
  const windowId = "pcw:test:window";
558
738
  const pending = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
559
739
  const aborted = reduceResetControl(pending, { type: "turn_end", facts: turnEndFacts({ aborted: true }) });
560
740
  assert.equal(aborted.effect, "none");
561
- assert.deepEqual(aborted.state, initialResetControl());
562
- assert.deepEqual(reduceResetControl(pending, { type: "clear" }).state, initialResetControl());
563
- assert.deepEqual(reduceResetControl(pending, { type: "settled" }).state, initialResetControl());
741
+ assert.deepEqual(controlState(aborted), initialResetControl());
742
+ assert.deepEqual(controlState(reduceResetControl(pending, { type: "before_settle", facts: beforeSettleFacts({ aborted: true }) })), initialResetControl());
564
743
  });
565
744
  test("reset-control: overflow recovery is armed at turn_end and spent exactly once at settle", () => {
566
- const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) });
567
- assert.deepEqual(armed.state, { request: { phase: "none" }, overflow: "pending" });
568
- const recovered = reduceResetControl(armed.state, { type: "before_settle", facts: beforeSettleFacts() });
569
- assert.equal(recovered.effect, "recover-overflow", "the first settle commits the bounded recovery");
745
+ const armed = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
746
+ assert.deepEqual(armed, { request: { phase: "none" }, overflow: "pending" });
747
+ const intent = boundaryIntent(reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts() }));
748
+ assert.equal(armed.overflow, "pending", "failed construction would leave recovery unspent");
749
+ assert.equal(intent.boundary, "overflow-recovery");
750
+ const recovered = finalizeResetBoundary(intent, armed.request, ["failed run's user input"]);
751
+ assert.equal(recovered.resumeModel, true);
752
+ assert.deepEqual(recovered.inputs, ["failed run's user input"]);
570
753
  assert.deepEqual(recovered.state, { request: { phase: "none" }, overflow: "spent" });
571
754
  const repeated = reduceResetControl(recovered.state, { type: "before_settle", facts: beforeSettleFacts() });
572
755
  assert.equal(repeated.effect, "none", "a spent recovery is never retried");
573
- const rearmed = reduceResetControl(recovered.state, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) });
574
- assert.deepEqual(rearmed.state, { request: { phase: "none" }, overflow: "pending-spent" });
575
- const bounded = reduceResetControl(rearmed.state, { type: "before_settle", facts: beforeSettleFacts() });
756
+ const rearmed = controlState(reduceResetControl(recovered.state, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
757
+ assert.deepEqual(rearmed, { request: { phase: "none" }, overflow: "pending-spent" });
758
+ const bounded = reduceResetControl(rearmed, { type: "before_settle", facts: beforeSettleFacts() });
576
759
  assert.equal(bounded.effect, "none", "a second failure chain stays bounded to the spent attempt");
577
- assert.deepEqual(bounded.state, { request: { phase: "none" }, overflow: "spent" });
760
+ assert.deepEqual(controlState(bounded), { request: { phase: "none" }, overflow: "spent" });
578
761
  });
579
762
  test("reset-control: a queued turn defers recovery and its success supersedes the failure", () => {
580
- const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }).state;
763
+ const armed = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
581
764
  const deferred = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ queued: true }) });
582
765
  assert.equal(deferred.effect, "none");
583
- assert.deepEqual(deferred.state, armed, "a queued message leaves the overflow chain armed");
766
+ assert.deepEqual(controlState(deferred), armed, "a queued message leaves the overflow chain armed");
584
767
  const success = reduceResetControl(armed, { type: "turn_end", facts: turnEndFacts() });
585
- assert.deepEqual(success.state, initialResetControl(), "a successful queued turn clears the stale failure");
768
+ assert.deepEqual(controlState(success), initialResetControl(), "a successful queued turn clears the stale failure");
586
769
  });
587
770
  test("reset-control: disabled mode and explicit aborts disarm overflow without a recovery", () => {
588
- const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }).state;
771
+ const armed = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
589
772
  const disabled = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ enabled: false }) });
590
773
  assert.equal(disabled.effect, "none");
591
- assert.deepEqual(disabled.state, { request: { phase: "none" }, overflow: "idle" });
774
+ assert.deepEqual(controlState(disabled), { request: { phase: "none" }, overflow: "idle" });
592
775
  const automaticOff = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ automaticResetEnabled: false }) });
593
776
  assert.equal(automaticOff.effect, "none");
594
- assert.deepEqual(automaticOff.state, { request: { phase: "none" }, overflow: "idle" });
777
+ assert.deepEqual(controlState(automaticOff), { request: { phase: "none" }, overflow: "idle" });
595
778
  const aborted = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ aborted: true }) });
596
779
  assert.equal(aborted.effect, "none");
597
- assert.deepEqual(aborted.state, { request: { phase: "none" }, overflow: "idle" });
780
+ assert.deepEqual(controlState(aborted), { request: { phase: "none" }, overflow: "idle" });
598
781
  });
599
782
  test("reset-control: lazy guards preserve overflow policy ordering", () => {
600
783
  const calls = { queued: 0, automatic: 0, hardReserve: 0 };
@@ -619,7 +802,7 @@ test("reset-control: lazy guards preserve overflow policy ordering", () => {
619
802
  aborted: false,
620
803
  failed: false,
621
804
  };
622
- const pendingOverflow = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }).state;
805
+ const pendingOverflow = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
623
806
  reduceResetControl(pendingOverflow, { type: "before_settle", facts: settleFacts });
624
807
  assert.deepEqual(settleCalls, { queued: 1, enabled: 0, automatic: 0 }, "queued settle checks no further overflow policy");
625
808
  });
@@ -744,9 +927,9 @@ test("reset-control: a tool request carries its last word to the turn-end commit
744
927
  const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
745
928
  assert.equal(armed.effect, "close-out-armed");
746
929
  assert.deepEqual(armed.state.request, { phase: "pending", windowId, tool: { lastWord: "the shoes were loyal" } });
747
- const commit = reduceResetControl(armed.state, { type: "turn_end", facts: turnEndFacts() });
748
- assert.equal(commit.effect, "commit-boundary");
749
- assert.equal(commit.lastWord, "the shoes were loyal");
930
+ const intent = boundaryIntent(reduceResetControl(armed.state, { type: "turn_end", facts: turnEndFacts() }));
931
+ assert.equal(intent.tool?.lastWord, "the shoes were loyal");
932
+ assert.equal(finalizeResetBoundary(intent, armed.state.request).resumeModel, true);
750
933
  });
751
934
  test("reset-control: a call and a command keep their facts in either order", () => {
752
935
  const windowId = "pcw:test:window";
@@ -755,35 +938,36 @@ test("reset-control: a call and a command keep their facts in either order", ()
755
938
  const converted = reduceResetControl(toolFirst.state, { type: "command", windowId, continueAfterReset: false });
756
939
  assert.equal(converted.effect, "close-out-armed");
757
940
  assert.deepEqual(converted.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "the shoes were loyal" } });
758
- const stop = reduceResetControl(converted.state, { type: "before_settle", facts: beforeSettleFacts() });
759
- assert.equal(stop.effect, "commit-boundary-stop");
941
+ const stop = boundaryIntent(reduceResetControl(converted.state, { type: "before_settle", facts: beforeSettleFacts() }));
942
+ assert.equal(finalizeResetBoundary(stop, converted.state.request).resumeModel, false);
760
943
  assert.equal(stop.origin, "normal", "a command arriving after a model wipe does not rewrite it as forced");
761
- assert.equal(stop.lastWord, "the shoes were loyal", "the call's parting line survives the conversion");
944
+ assert.equal(stop.tool?.lastWord, "the shoes were loyal", "the call's parting line survives the conversion");
762
945
  // The command first, then the call: the acknowledgement records the call and keeps stopping.
763
946
  const commandFirst = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false });
764
947
  const acknowledged = reduceResetControl(commandFirst.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
765
948
  assert.equal(acknowledged.effect, "close-out-armed");
766
949
  assert.deepEqual(acknowledged.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
767
- const settled = reduceResetControl(acknowledged.state, { type: "before_settle", facts: beforeSettleFacts() });
768
- assert.equal(settled.effect, "commit-boundary-stop");
950
+ const settled = boundaryIntent(reduceResetControl(acknowledged.state, { type: "before_settle", facts: beforeSettleFacts() }));
951
+ assert.equal(finalizeResetBoundary(settled, acknowledged.state.request).resumeModel, false);
769
952
  assert.equal(settled.origin, "normal", "the command-first order records the same origin");
770
- assert.equal(settled.lastWord, "tell them I was funny");
953
+ assert.equal(settled.tool?.lastWord, "tell them I was funny");
771
954
  });
772
955
  test("reset-control: the origin is the empty_brain call, independent of command policy", () => {
773
956
  const windowId = "pcw:test:window";
774
957
  const tool = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
775
- assert.equal(reduceResetControl(tool.state, { type: "turn_end", facts: turnEndFacts() }).origin, "normal", "the model's own call is a normal reset");
958
+ assert.equal(boundaryIntent(reduceResetControl(tool.state, { type: "turn_end", facts: turnEndFacts() })).origin, "normal", "the model's own call is a normal reset");
776
959
  const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
777
- assert.equal(reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() }).origin, "forced", "a command close-out with no call is a system reset");
960
+ assert.equal(boundaryIntent(reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() })).origin, "forced", "a command close-out with no call is a system reset");
778
961
  const acknowledged = reduceResetControl(manual, { type: "tool_request", windowId }).state;
779
- assert.equal(reduceResetControl(acknowledged, { type: "before_settle", facts: beforeSettleFacts() }).origin, "normal", "a manual close-out the model actually wipes is normal but still stops");
780
- assert.equal(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) }).origin, "forced", "the hard cutoff happens without a call");
781
- const safety = reduceResetControl(acknowledged, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
782
- assert.equal(safety.origin, "normal", "an acknowledged call survives the hard cutoff it was armed against");
783
- assert.deepEqual(safety.state.request, { phase: "stop-pending", windowId, tool: {} }, "the recorded call survives into the run-scoped stop latch");
784
- assert.equal(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts() }).origin, "normal", "a retried safety construction keeps the recorded origin");
785
- const overflow = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }).state;
786
- assert.equal(reduceResetControl(overflow, { type: "before_settle", facts: beforeSettleFacts() }).origin, "forced", "overflow recovery has no call behind it");
962
+ assert.equal(boundaryIntent(reduceResetControl(acknowledged, { type: "before_settle", facts: beforeSettleFacts() })).origin, "normal", "a manual close-out the model actually wipes is normal but still stops");
963
+ assert.equal(boundaryIntent(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) })).origin, "forced", "the hard cutoff happens without a call");
964
+ const intent = boundaryIntent(reduceResetControl(acknowledged, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) }));
965
+ assert.equal(intent.origin, "normal", "an acknowledged call survives the hard cutoff it was armed against");
966
+ const safety = finalizeResetBoundary(intent, acknowledged.request);
967
+ assert.deepEqual(safety.state.stopAfterReset?.tool, {}, "the recorded call survives into the run-scoped stop latch");
968
+ assert.equal(boundaryIntent(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts() })).origin, "normal", "a retried safety construction keeps the recorded origin");
969
+ const overflow = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
970
+ assert.equal(boundaryIntent(reduceResetControl(overflow, { type: "before_settle", facts: beforeSettleFacts() })).origin, "forced", "overflow recovery has no call behind it");
787
971
  });
788
972
  test("a committed reset records its origin and draws that pool exactly once", async () => {
789
973
  const random = Math.random;
@@ -826,7 +1010,7 @@ test("reset-control: a command retains tool calls with or without a last word an
826
1010
  assert.deepEqual(ack.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
827
1011
  const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state, { type: "tool_request", windowId });
828
1012
  assert.deepEqual(silentAck.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} }, "a call with no last word is still a real tool request");
829
- const commit = reduceResetControl(ack.state, { type: "before_settle", facts: beforeSettleFacts() });
830
- assert.equal(commit.effect, "commit-boundary-stop");
831
- assert.equal(commit.lastWord, "tell them I was funny");
1013
+ const intent = boundaryIntent(reduceResetControl(ack.state, { type: "before_settle", facts: beforeSettleFacts() }));
1014
+ assert.equal(finalizeResetBoundary(intent, ack.state.request).resumeModel, false);
1015
+ assert.equal(intent.tool?.lastWord, "tell them I was funny");
832
1016
  });
@@ -46,7 +46,7 @@ The runtime in `plugins/pi/runtime.ts` performs final context projection by sele
46
46
 
47
47
  Boot and reminder deduplication inspect the current branch-local window. Reloading JSONL therefore does not duplicate messages, while navigation to a sibling branch cannot inherit another branch's window state. A fork/clone receives a new session ID while copying its selected path, so startup must also verify that a root boot's `details.windowId` matches the new `rootWindowId(sessionId)` before treating it as present.
48
48
 
49
- Manual `/fresh-window` stores command settlement policy and sends a hidden warning: idle commands start a model turn, running commands steer it. Tool requests are recorded independently and retained under that policy. A bare command settles and stops; a command with text settles and continues, with its text supplied only to the closing window. Budget warnings create no reset state: only an explicit tool request, hard reserve or bounded overflow recovery triggers a reset. Abort and ordinary errors do not count as successful settlement. Hard reserve preserves a bare command's stop in a run-scoped latch; `context_with_system` cancels only an empty tool-batch follow-up after confirming the committed boundary. Queued user input is answered before stopping. See [reset lifecycle](reset-lifecycle.md) for the state and recovery rules.
49
+ Manual `/fresh-window` stores command settlement policy and sends a hidden warning: idle commands start a model turn, running commands steer it. Tool requests are recorded independently and retained under that policy. A bare command settles and stops unless later human input arrives; a command with text settles and continues, with its text supplied to the closing window and carried verbatim into the fresh window. Budget warnings create no reset state: only an explicit tool request, hard reserve or bounded overflow recovery triggers a reset. Abort and ordinary errors do not count as successful settlement. Hard reserve preserves a bare command's stop in a run-scoped latch; `context_with_system` cancels only an empty tool-batch follow-up after confirming the committed boundary. Queued user input is answered before stopping. See [reset lifecycle](reset-lifecycle.md) for the state and recovery rules.
50
50
 
51
51
  Boot is a fixed snapshot for its window, stored as an extension custom message and converted by Pi to a user-role model message. History internally distinguishes native system summaries and extension-authored custom messages; its public `context` event groups both without implying provider instruction priority. A system-role projection is technically possible through `context_with_system`, but would change the authority of the mixed protocol/MAP content and provider-specific prompt/cache behavior; it is not a prerequisite for persistence. Boot injection is silent, including startup, reload, and boot repair. Only an actual context reset produces a brain-cleared notice through `ctx.ui.notify`, after the verified checkpoint, marker, boot, and continuation are present in the session. Committed resets are checked at the next turn start or final settlement. `plugins/pi/reset/committed.ts` confirms an ordered hidden boot/continuation after a checkpoint-backed marker even when later conversation exists. That is distinct from `inspectResetTail`, which refuses suffix repair after real work or malformed ordering. Uncommitted reset drafts never announce success. Boot and continuation messages retain `display: false`.
52
52