notesoup 0.51.2 → 0.51.4
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.
- package/dist/plugins/pi/notes/tools.js +1 -1
- package/dist/plugins/pi/reset/lifecycle.d.ts +29 -14
- package/dist/plugins/pi/reset/lifecycle.js +46 -49
- package/dist/test/reset-lifecycle.test.js +173 -79
- package/docs/architecture.md +1 -1
- package/docs/reset-lifecycle.md +6 -5
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/paseo/OVERVIEW.md +6 -2
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/notes-op-card.tsx +109 -0
- package/plugins/paseo/client/notes-op-transformer.ts +115 -0
- package/plugins/paseo/client/sticky-card.tsx +19 -12
- package/plugins/paseo/index.client.tsx +10 -3
- package/plugins/paseo/package-lock.json +4018 -0
- package/plugins/paseo/shared/notes-op.ts +29 -0
- package/plugins/paseo/test/notes-op.test.ts +129 -0
- package/plugins/pi/notes/tools.ts +1 -1
- package/plugins/pi/reset/lifecycle.ts +59 -61
|
@@ -14,7 +14,7 @@ import { LAST_WORD_HINT, commandWarningContent } from "../plugins/pi/text.js";
|
|
|
14
14
|
import { historyFromSession, nextHistorySeq } from "../plugins/pi/history.js";
|
|
15
15
|
import { buildResetDrafts, inspectResetTail, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "../plugins/pi/reset/artifacts.js";
|
|
16
16
|
import { resetBoundaryCommitted } from "../plugins/pi/reset/committed.js";
|
|
17
|
-
import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../plugins/pi/reset/lifecycle.js";
|
|
17
|
+
import { finalizeResetBoundary, initialResetControl, reduceResetControl, registerResetLifecycle, } from "../plugins/pi/reset/lifecycle.js";
|
|
18
18
|
const previousNotesHome = process.env.PI_NOTES_HOME;
|
|
19
19
|
const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
|
|
20
20
|
process.env.PI_NOTES_HOME = testNotesHome;
|
|
@@ -122,6 +122,14 @@ function appendDrafts(sessionManager, entries) {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
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
|
+
}
|
|
125
133
|
function turnEndFacts(overrides = {}) {
|
|
126
134
|
return {
|
|
127
135
|
windowId: "pcw:test:window",
|
|
@@ -320,6 +328,48 @@ test("input arriving during reset construction survives even when the hidden ste
|
|
|
320
328
|
assert.equal(inspectResetTail(ctx, partialMarker, "partial"), undefined, "repair cannot append a continuation after human content");
|
|
321
329
|
assert.equal(resetBoundaryCommitted(ctx, partialMarker, "partial"), false);
|
|
322
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
|
+
});
|
|
323
373
|
test("abort during reset construction restores handled input at settlement, once", async () => {
|
|
324
374
|
const sessionManager = Manager.inMemory("/private/tmp/notesoup-cancelled-build-test");
|
|
325
375
|
const handlers = new Map();
|
|
@@ -540,12 +590,14 @@ test("reset-control: command policy deduplicates, spans turns, and retains a rea
|
|
|
540
590
|
assert.equal(duplicate.effect, "already-pending");
|
|
541
591
|
const noteTurn = reduceResetControl(first.state, { type: "turn_end", facts: turnEndFacts() });
|
|
542
592
|
assert.equal(noteTurn.effect, "none");
|
|
543
|
-
assert.deepEqual(noteTurn.
|
|
544
|
-
const tool = reduceResetControl(noteTurn
|
|
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 });
|
|
545
595
|
assert.equal(tool.effect, "close-out-armed", "the first tool call is recorded without changing settlement policy");
|
|
546
596
|
assert.deepEqual(tool.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
|
|
547
|
-
const
|
|
548
|
-
assert.equal(
|
|
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");
|
|
549
601
|
assert.deepEqual(commit.state, initialResetControl());
|
|
550
602
|
});
|
|
551
603
|
test("reset-control: command settlement policy preserves a pending tool request", () => {
|
|
@@ -555,7 +607,8 @@ test("reset-control: command settlement policy preserves a pending tool request"
|
|
|
555
607
|
assert.equal(manual.effect, "close-out-armed", "the user's stop intent outranks the pending rollover");
|
|
556
608
|
assert.deepEqual(manual.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
|
|
557
609
|
assert.equal(reduceResetControl(manual.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none", "the converted request no longer commits at turn end");
|
|
558
|
-
|
|
610
|
+
const intent = boundaryIntent(reduceResetControl(manual.state, { type: "before_settle", facts: beforeSettleFacts() }));
|
|
611
|
+
assert.equal(finalizeResetBoundary(intent, manual.state.request).resumeModel, false);
|
|
559
612
|
});
|
|
560
613
|
test("reset-control: duplicate commands preserve policy and both call orders retain the tool's last word", () => {
|
|
561
614
|
const windowId = "pcw:test:window";
|
|
@@ -572,76 +625,112 @@ test("reset-control: duplicate commands preserve policy and both call orders ret
|
|
|
572
625
|
assert.equal(repeated.effect, "already-pending");
|
|
573
626
|
assert.deepEqual(repeated.state, commandThenTool.state);
|
|
574
627
|
assert.equal(reduceResetControl(repeated.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none");
|
|
575
|
-
const
|
|
576
|
-
assert.equal(
|
|
577
|
-
|
|
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, []);
|
|
578
633
|
});
|
|
579
634
|
test("reset-control: a tool request needs no prior budget warning", () => {
|
|
580
635
|
const windowId = "pcw:test:window";
|
|
581
636
|
const requested = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
|
|
582
637
|
assert.equal(requested.effect, "close-out-armed");
|
|
583
638
|
assert.deepEqual(requested.state.request, { phase: "pending", windowId, tool: {} });
|
|
584
|
-
|
|
639
|
+
const intent = boundaryIntent(reduceResetControl(requested.state, { type: "turn_end", facts: turnEndFacts() }));
|
|
640
|
+
assert.equal(finalizeResetBoundary(intent, requested.state.request).resumeModel, true);
|
|
585
641
|
});
|
|
586
642
|
test("reset-control: fallback is normal-stop only; hard reserve remains safety", () => {
|
|
587
643
|
const windowId = "pcw:test:window";
|
|
588
644
|
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
589
|
-
const
|
|
590
|
-
|
|
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");
|
|
591
648
|
assert.deepEqual(fallback.state, initialResetControl());
|
|
592
649
|
const automatic = initialResetControl();
|
|
593
650
|
const normalStop = reduceResetControl(automatic, { type: "before_settle", facts: beforeSettleFacts() });
|
|
594
651
|
assert.equal(normalStop.effect, "none", "ignoring a budget warning and answering normally must not wipe memory");
|
|
595
|
-
assert.deepEqual(normalStop
|
|
652
|
+
assert.deepEqual(controlState(normalStop), initialResetControl());
|
|
596
653
|
const disabledAuto = reduceResetControl(automatic, { type: "before_settle", facts: beforeSettleFacts({ automaticResetEnabled: false }) });
|
|
597
654
|
assert.equal(disabledAuto.effect, "none");
|
|
598
|
-
assert.deepEqual(disabledAuto
|
|
655
|
+
assert.deepEqual(controlState(disabledAuto), initialResetControl());
|
|
599
656
|
const safety = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
|
|
600
|
-
assert.equal(safety.
|
|
657
|
+
assert.equal(finalizeResetBoundary(boundaryIntent(safety), automatic.request).resumeModel, true);
|
|
601
658
|
for (const outcome of [{ failed: true }, { aborted: true }]) {
|
|
602
659
|
const notNormalStop = reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts(outcome) });
|
|
603
660
|
assert.equal(notNormalStop.effect, "none");
|
|
604
|
-
assert.deepEqual(notNormalStop
|
|
661
|
+
assert.deepEqual(controlState(notNormalStop), initialResetControl());
|
|
605
662
|
}
|
|
606
663
|
});
|
|
607
664
|
test("reset-control: manual stop survives a hard-reserve reset across windows without a second wipe", () => {
|
|
608
665
|
const windowId = "pcw:test:window";
|
|
609
666
|
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
610
|
-
const
|
|
611
|
-
assert.equal(
|
|
612
|
-
|
|
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);
|
|
613
673
|
const freshWindowId = "pcw:test:fresh";
|
|
614
674
|
assert.equal(reduceResetControl(safety.state, { type: "tool_request", windowId: freshWindowId }).effect, "already-pending");
|
|
615
675
|
assert.equal(reduceResetControl(safety.state, { type: "command", windowId: freshWindowId, continueAfterReset: false }).effect, "already-pending");
|
|
616
676
|
const queued = reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId, queued: true }) });
|
|
617
|
-
assert.deepEqual(queued
|
|
618
|
-
const freshTurn = reduceResetControl(queued
|
|
677
|
+
assert.deepEqual(controlState(queued), safety.state);
|
|
678
|
+
const freshTurn = reduceResetControl(controlState(queued), { type: "turn_end", facts: turnEndFacts({ windowId: freshWindowId, hardReserveDue: true }) });
|
|
619
679
|
assert.equal(freshTurn.effect, "none");
|
|
620
|
-
const stop = reduceResetControl(freshTurn
|
|
680
|
+
const stop = reduceResetControl(controlState(freshTurn), { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId }) });
|
|
621
681
|
assert.equal(stop.effect, "stop", "the safety boundary already wiped; settlement must only stop");
|
|
622
|
-
assert.deepEqual(stop
|
|
623
|
-
|
|
624
|
-
assert.
|
|
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");
|
|
625
708
|
});
|
|
626
709
|
test("reset-control: manual overflow keeps stop intent while queued work supersedes the failure", () => {
|
|
627
710
|
const windowId = "pcw:test:window";
|
|
628
711
|
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
629
|
-
const overflow = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, queued: true, automaticResetEnabled: false }) });
|
|
630
|
-
assert.deepEqual(overflow.
|
|
631
|
-
const deferred = reduceResetControl(overflow
|
|
632
|
-
assert.deepEqual(deferred
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
assert.
|
|
637
|
-
assert.equal(
|
|
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);
|
|
638
723
|
const prompted = reduceResetControl(manual, { type: "input", windowId, input: "answer after reset" }).state;
|
|
639
724
|
const called = reduceResetControl(prompted, { type: "tool_request", windowId, lastWord: "saved" }).state;
|
|
640
|
-
const failed = reduceResetControl(called, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, automaticResetEnabled: false }) })
|
|
641
|
-
const
|
|
642
|
-
assert.equal(
|
|
643
|
-
|
|
644
|
-
assert.equal(
|
|
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"]);
|
|
645
734
|
assert.equal(retry.state.overflow, "spent", "manual recovery spends the same bounded attempt");
|
|
646
735
|
});
|
|
647
736
|
test("reset-control: explicit abort clears a pending request at turn end or settlement", () => {
|
|
@@ -649,42 +738,46 @@ test("reset-control: explicit abort clears a pending request at turn end or sett
|
|
|
649
738
|
const pending = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
650
739
|
const aborted = reduceResetControl(pending, { type: "turn_end", facts: turnEndFacts({ aborted: true }) });
|
|
651
740
|
assert.equal(aborted.effect, "none");
|
|
652
|
-
assert.deepEqual(aborted
|
|
653
|
-
assert.deepEqual(reduceResetControl(pending, { type: "before_settle", facts: beforeSettleFacts({ aborted: true }) })
|
|
741
|
+
assert.deepEqual(controlState(aborted), initialResetControl());
|
|
742
|
+
assert.deepEqual(controlState(reduceResetControl(pending, { type: "before_settle", facts: beforeSettleFacts({ aborted: true }) })), initialResetControl());
|
|
654
743
|
});
|
|
655
744
|
test("reset-control: overflow recovery is armed at turn_end and spent exactly once at settle", () => {
|
|
656
|
-
const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) });
|
|
657
|
-
assert.deepEqual(armed
|
|
658
|
-
const
|
|
659
|
-
assert.equal(
|
|
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"]);
|
|
660
753
|
assert.deepEqual(recovered.state, { request: { phase: "none" }, overflow: "spent" });
|
|
661
754
|
const repeated = reduceResetControl(recovered.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
662
755
|
assert.equal(repeated.effect, "none", "a spent recovery is never retried");
|
|
663
|
-
const rearmed = reduceResetControl(recovered.state, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) });
|
|
664
|
-
assert.deepEqual(rearmed
|
|
665
|
-
const bounded = reduceResetControl(rearmed
|
|
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() });
|
|
666
759
|
assert.equal(bounded.effect, "none", "a second failure chain stays bounded to the spent attempt");
|
|
667
|
-
assert.deepEqual(bounded
|
|
760
|
+
assert.deepEqual(controlState(bounded), { request: { phase: "none" }, overflow: "spent" });
|
|
668
761
|
});
|
|
669
762
|
test("reset-control: a queued turn defers recovery and its success supersedes the failure", () => {
|
|
670
|
-
const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) })
|
|
763
|
+
const armed = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
|
|
671
764
|
const deferred = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ queued: true }) });
|
|
672
765
|
assert.equal(deferred.effect, "none");
|
|
673
|
-
assert.deepEqual(deferred
|
|
766
|
+
assert.deepEqual(controlState(deferred), armed, "a queued message leaves the overflow chain armed");
|
|
674
767
|
const success = reduceResetControl(armed, { type: "turn_end", facts: turnEndFacts() });
|
|
675
|
-
assert.deepEqual(success
|
|
768
|
+
assert.deepEqual(controlState(success), initialResetControl(), "a successful queued turn clears the stale failure");
|
|
676
769
|
});
|
|
677
770
|
test("reset-control: disabled mode and explicit aborts disarm overflow without a recovery", () => {
|
|
678
|
-
const armed = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) })
|
|
771
|
+
const armed = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
|
|
679
772
|
const disabled = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ enabled: false }) });
|
|
680
773
|
assert.equal(disabled.effect, "none");
|
|
681
|
-
assert.deepEqual(disabled
|
|
774
|
+
assert.deepEqual(controlState(disabled), { request: { phase: "none" }, overflow: "idle" });
|
|
682
775
|
const automaticOff = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ automaticResetEnabled: false }) });
|
|
683
776
|
assert.equal(automaticOff.effect, "none");
|
|
684
|
-
assert.deepEqual(automaticOff
|
|
777
|
+
assert.deepEqual(controlState(automaticOff), { request: { phase: "none" }, overflow: "idle" });
|
|
685
778
|
const aborted = reduceResetControl(armed, { type: "before_settle", facts: beforeSettleFacts({ aborted: true }) });
|
|
686
779
|
assert.equal(aborted.effect, "none");
|
|
687
|
-
assert.deepEqual(aborted
|
|
780
|
+
assert.deepEqual(controlState(aborted), { request: { phase: "none" }, overflow: "idle" });
|
|
688
781
|
});
|
|
689
782
|
test("reset-control: lazy guards preserve overflow policy ordering", () => {
|
|
690
783
|
const calls = { queued: 0, automatic: 0, hardReserve: 0 };
|
|
@@ -709,7 +802,7 @@ test("reset-control: lazy guards preserve overflow policy ordering", () => {
|
|
|
709
802
|
aborted: false,
|
|
710
803
|
failed: false,
|
|
711
804
|
};
|
|
712
|
-
const pendingOverflow = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) })
|
|
805
|
+
const pendingOverflow = controlState(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }));
|
|
713
806
|
reduceResetControl(pendingOverflow, { type: "before_settle", facts: settleFacts });
|
|
714
807
|
assert.deepEqual(settleCalls, { queued: 1, enabled: 0, automatic: 0 }, "queued settle checks no further overflow policy");
|
|
715
808
|
});
|
|
@@ -834,9 +927,9 @@ test("reset-control: a tool request carries its last word to the turn-end commit
|
|
|
834
927
|
const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
|
835
928
|
assert.equal(armed.effect, "close-out-armed");
|
|
836
929
|
assert.deepEqual(armed.state.request, { phase: "pending", windowId, tool: { lastWord: "the shoes were loyal" } });
|
|
837
|
-
const
|
|
838
|
-
assert.equal(
|
|
839
|
-
assert.equal(
|
|
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);
|
|
840
933
|
});
|
|
841
934
|
test("reset-control: a call and a command keep their facts in either order", () => {
|
|
842
935
|
const windowId = "pcw:test:window";
|
|
@@ -845,35 +938,36 @@ test("reset-control: a call and a command keep their facts in either order", ()
|
|
|
845
938
|
const converted = reduceResetControl(toolFirst.state, { type: "command", windowId, continueAfterReset: false });
|
|
846
939
|
assert.equal(converted.effect, "close-out-armed");
|
|
847
940
|
assert.deepEqual(converted.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "the shoes were loyal" } });
|
|
848
|
-
const stop = reduceResetControl(converted.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
849
|
-
assert.equal(stop.
|
|
941
|
+
const stop = boundaryIntent(reduceResetControl(converted.state, { type: "before_settle", facts: beforeSettleFacts() }));
|
|
942
|
+
assert.equal(finalizeResetBoundary(stop, converted.state.request).resumeModel, false);
|
|
850
943
|
assert.equal(stop.origin, "normal", "a command arriving after a model wipe does not rewrite it as forced");
|
|
851
|
-
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");
|
|
852
945
|
// The command first, then the call: the acknowledgement records the call and keeps stopping.
|
|
853
946
|
const commandFirst = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false });
|
|
854
947
|
const acknowledged = reduceResetControl(commandFirst.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
|
|
855
948
|
assert.equal(acknowledged.effect, "close-out-armed");
|
|
856
949
|
assert.deepEqual(acknowledged.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
|
|
857
|
-
const settled = reduceResetControl(acknowledged.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
858
|
-
assert.equal(settled.
|
|
950
|
+
const settled = boundaryIntent(reduceResetControl(acknowledged.state, { type: "before_settle", facts: beforeSettleFacts() }));
|
|
951
|
+
assert.equal(finalizeResetBoundary(settled, acknowledged.state.request).resumeModel, false);
|
|
859
952
|
assert.equal(settled.origin, "normal", "the command-first order records the same origin");
|
|
860
|
-
assert.equal(settled.lastWord, "tell them I was funny");
|
|
953
|
+
assert.equal(settled.tool?.lastWord, "tell them I was funny");
|
|
861
954
|
});
|
|
862
955
|
test("reset-control: the origin is the empty_brain call, independent of command policy", () => {
|
|
863
956
|
const windowId = "pcw:test:window";
|
|
864
957
|
const tool = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
|
|
865
|
-
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");
|
|
866
959
|
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
867
|
-
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");
|
|
868
961
|
const acknowledged = reduceResetControl(manual, { type: "tool_request", windowId }).state;
|
|
869
|
-
assert.equal(reduceResetControl(acknowledged, { type: "before_settle", facts: beforeSettleFacts() }).origin, "normal", "a manual close-out the model actually wipes is normal but still stops");
|
|
870
|
-
assert.equal(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) }).origin, "forced", "the hard cutoff happens without a call");
|
|
871
|
-
const
|
|
872
|
-
assert.equal(
|
|
873
|
-
|
|
874
|
-
assert.
|
|
875
|
-
|
|
876
|
-
|
|
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");
|
|
877
971
|
});
|
|
878
972
|
test("a committed reset records its origin and draws that pool exactly once", async () => {
|
|
879
973
|
const random = Math.random;
|
|
@@ -916,7 +1010,7 @@ test("reset-control: a command retains tool calls with or without a last word an
|
|
|
916
1010
|
assert.deepEqual(ack.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
|
|
917
1011
|
const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state, { type: "tool_request", windowId });
|
|
918
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");
|
|
919
|
-
const
|
|
920
|
-
assert.equal(
|
|
921
|
-
assert.equal(
|
|
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");
|
|
922
1016
|
});
|
package/docs/architecture.md
CHANGED
|
@@ -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
|
|
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
|
|
package/docs/reset-lifecycle.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reset lifecycle
|
|
2
2
|
|
|
3
|
-
Pi reset control lives in `plugins/pi/reset/lifecycle.ts`: the pure `reduceResetControl` selects
|
|
3
|
+
Pi reset control lives in `plugins/pi/reset/lifecycle.ts`: the pure `reduceResetControl` selects state transitions or boundary intents; after asynchronous construction, `finalizeResetBoundary` owns final state, carried inputs and continuation. `registerResetLifecycle` adapts public Pi events, constructs boundaries and applies the finalizer's result unchanged. `budget.ts` stages reminders and checks settings; `reset/artifacts.ts` builds and repairs ordered artifacts; `reset/committed.ts` confirms durable boundaries. `window.ts` owns identities and provider projection; `runtime.ts` wires commands and tools. No Pi source patches, native summarization requests, or second commit database are used.
|
|
4
4
|
|
|
5
5
|
## Lifecycle at a glance
|
|
6
6
|
|
|
@@ -40,19 +40,20 @@ Raw session history remains available. The retain-none checkpoint excludes old c
|
|
|
40
40
|
|
|
41
41
|
## Reducer and run state
|
|
42
42
|
|
|
43
|
-
`ResetControlState` combines a request
|
|
43
|
+
`ResetControlState` combines a request, a bounded overflow phase, and an optional run-scoped `stopAfterReset` latch:
|
|
44
44
|
|
|
45
45
|
| Request | Meaning |
|
|
46
46
|
| --- | --- |
|
|
47
47
|
| `none` | No command or tool request. |
|
|
48
48
|
| `pending` | Current `windowId`, optional `tool: { lastWord? }`, and optional `command: { continueAfterReset, inputs? }`. Command inputs retain originals, not prompt-block wrappers. Duplicate commands retain the first policy/text; tool calls do not overwrite command policy. |
|
|
49
|
-
| `stop-pending` | A bare-command hard-reserve reset's stop intent survives the window change. It retains the tool request for construction retry, but stops without a second wipe after commit. |
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
`stopAfterReset` is separate from the request. It retains the safety boundary's intent after construction, while `request` becomes `none`. Settlement waits for queued work; if the window changed, it stops without a second wipe. If the window did not change, the boundary never committed, so settlement retries the retained intent with its stop policy and tool origin intact. A successful settle retry consumes the latch.
|
|
51
|
+
|
|
52
|
+
Overflow phases are `idle`, `pending`, `spent`, and `pending-spent`. `turn_end` arms enabled recovery; `agent_before_settle` waits for queued work and selects recovery intent. Only successful, current construction reaches finalization and spends the attempt. A successful queued turn supersedes the failure. Command overflow spends the same bounded attempt before continuing. Abort, final settlement, session start/tree/shutdown and `/notesoup off` clear transient state.
|
|
52
53
|
|
|
53
54
|
The adapter collects actual user `message_end` content until settlement or a successful reset boundary. Low-level `agent_start` events do not clear it: Pi can start additional loops while draining follow-ups/recovering. Custom boot/warning/continuation messages are never mistaken for human input. Successful boundary construction clears this run collection, so an automatic continuation does not replay old input.
|
|
54
55
|
|
|
55
|
-
Command state remains live during asynchronous notes acquisition.
|
|
56
|
+
Command state remains live during asynchronous notes acquisition. Boundary intent captures the trigger, explicit `continueAfterReset` policy, tool fact and origin, but contains no final state or continuation decision. After construction passes the currentness guard, the pure finalizer selects live command-owned originals, or the current run's inputs only for passive recovery, and resolves `resumeModel` and the next control state together. `resumeModel` is true when the policy requests continuation or carried input needs an answer; the adapter maps it to Pi's `continue` field. Late originals therefore join the same boundary and prevent a stop latch from being installed; delivery contents never replace explicit command policy. Hidden steers carry window/command identity; provider projection excludes them once that command ends, including steers Pi delivers only after the reset. Originals remain available exactly once as carried input. Construction captures session/window generations and rechecks identity, enabled state and abort status before returning drafts. Clearing the run invalidates any unfinished construction before resetting its input collection. Stale work preserves incoming/budget entries but discards reset drafts; construction failures notify only while current and do not claim continuation. If close-out cannot commit, stashed originals are restored with public `sendMessage(..., { triggerTurn: false })`, including cancellation during construction; clearing command state must not erase input already reported as handled.
|
|
56
57
|
|
|
57
58
|
After a manual safety reset, `context_with_system` checks the committed boundary before using public `ctx.abort()` to cancel an unavoidable empty tool follow-up with system-only context. Pending messages, ordinary user entries or carried inputs after the marker bypass cancellation. Later user prompts are not affected by the run-scoped stop latch.
|
|
58
59
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# Notesoup last word
|
|
2
2
|
|
|
3
|
-
Displays notesoup last-word messages already present in Paseo’s timeline as expanded, selectable cards.
|
|
3
|
+
Displays notesoup last-word messages already present in Paseo’s timeline as expanded, selectable paper cards. Last-word and notes cards share a pale-paper palette, tape accent, small corners, and compact spacing; last-word text stays visible without folding. Requires Paseo 0.11.2 on the client and daemon.
|
|
4
4
|
|
|
5
|
-
This client-only plugin transforms
|
|
5
|
+
This client-only plugin transforms existing timeline rows in place: last-word custom messages become sticky cards, and notes_read/notes_write/notes_update tool calls become paper cards with the address, state, and a content or diff preview. It does not read session files or append messages. Other timeline items are unchanged.
|
|
6
|
+
|
|
7
|
+
Notes cards start collapsed, with an expand arrow at the top right and a collapse arrow below the expanded body. Long content scrolls inside a bounded panel. Display limits are 4000 characters for reads and writes, and 8000 for diffs; expanding does not fetch more content.
|
|
8
|
+
|
|
9
|
+
Notes cards prefer the structured tool payload on live events. Replayed history carries only the rendered result text, so the transformer parses that fallback; replayed writes show no content preview.
|
|
6
10
|
|
|
7
11
|
Paseo 0.11.2 drops Pi boundary `entry_appended` events from its live timeline. This plugin cannot display messages that Paseo has not received; that adapter gap needs an upstream fix. Messages available through history can be rendered.
|
package/plugins/paseo/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Notesoup Paseo plugin
|
|
2
2
|
|
|
3
|
-
Client-only last-word
|
|
3
|
+
Client-only renderers: last-word sticky cards and paper cards for notes_read/notes_write/notes_update tool calls. See [OVERVIEW.md](OVERVIEW.md) for behavior and the upstream live-event limitation.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
cd plugins/paseo
|