notesoup 0.51.0 → 0.51.2
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/README.md +0 -1
- package/dist/plugins/pi/entries.d.ts +2 -0
- package/dist/plugins/pi/entries.js +2 -0
- package/dist/plugins/pi/reset/artifacts.d.ts +10 -2
- package/dist/plugins/pi/reset/artifacts.js +24 -5
- package/dist/plugins/pi/reset/lifecycle.d.ts +9 -8
- package/dist/plugins/pi/reset/lifecycle.js +109 -31
- package/dist/plugins/pi/runtime.js +9 -10
- package/dist/plugins/pi/text.d.ts +11 -14
- package/dist/plugins/pi/text.js +15 -16
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/test/agent-loop.test.js +316 -163
- package/dist/test/boot.integration.test.js +3 -3
- package/dist/test/claude-validation.test.js +4 -2
- package/dist/test/dsh-cli.test.js +7 -6
- package/dist/test/helpers/dsh-messages.js +3 -0
- package/dist/test/model-facing-text.test.js +10 -4
- package/dist/test/reset-lifecycle.test.js +105 -15
- package/docs/notes-library.md +1 -1
- package/docs/reset-lifecycle.md +42 -58
- package/package.json +2 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +485 -485
- package/plugins/paseo/OVERVIEW.md +7 -0
- package/plugins/paseo/README.md +12 -0
- package/plugins/paseo/client/source-row.ts +14 -0
- package/plugins/paseo/client/sticky-card.tsx +21 -0
- package/plugins/paseo/index.client.tsx +10 -0
- package/plugins/paseo/package.json +19 -0
- package/plugins/paseo/paseo-plugin.json +4 -0
- package/plugins/paseo/shared/last-word.ts +6 -0
- package/plugins/paseo/test/source-row.test.ts +19 -0
- package/plugins/paseo/tsconfig.json +16 -0
- package/plugins/pi/entries.ts +2 -0
- package/plugins/pi/reset/artifacts.ts +26 -5
- package/plugins/pi/reset/lifecycle.ts +101 -34
- package/plugins/pi/runtime.ts +9 -10
- package/plugins/pi/text.ts +17 -17
- package/src/index.ts +1 -1
- package/docs/sdk-integration.md +0 -39
package/README.md
CHANGED
|
@@ -75,7 +75,6 @@ The dreamer model is configured under the same key; `--dreamer <model pattern>`
|
|
|
75
75
|
- [Architecture](docs/architecture.md) and [reset lifecycle](docs/reset-lifecycle.md) — how windows, checkpoints, markers and branches actually work
|
|
76
76
|
- [Tool results](docs/tool-results.md) — receipts, paging, and error shapes
|
|
77
77
|
- [Standalone notes library](docs/notes-library.md) — use the notes store from Node, no Pi required
|
|
78
|
-
- [SDK integration](docs/sdk-integration.md) — binding notesoup to a host-built session
|
|
79
78
|
- [DeepSeek Harness](docs/dsh.md) — adapter and profile patch for dsh 0.2.1-alpha.2
|
|
80
79
|
- [Claude Code Mod](docs/claude-code-mod.md) — early-access notes and persisted-session history tools for Claude Code
|
|
81
80
|
- [Skills, dream, and the notes doctor](docs/skills.md) — `/skill:memory`, `/skill:dream`, `dream doctor`, the dream lock
|
|
@@ -5,3 +5,5 @@ export declare const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
|
|
|
5
5
|
export declare const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
6
6
|
export declare const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
7
|
export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
8
|
+
export declare const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
|
+
export declare const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
@@ -5,3 +5,5 @@ export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
|
|
|
5
5
|
export const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
6
6
|
export const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
7
|
export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
8
|
+
export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
|
+
export const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
@@ -6,6 +6,14 @@ export type ResetTailState = {
|
|
|
6
6
|
readonly boot: boolean;
|
|
7
7
|
readonly continuation: boolean;
|
|
8
8
|
};
|
|
9
|
+
/** Original user content, including images; custom boundary messages become LLM user messages. */
|
|
10
|
+
export type CarriedInput = Extract<SessionBoundaryDraft, {
|
|
11
|
+
type: "custom_message";
|
|
12
|
+
}>["content"];
|
|
13
|
+
export declare function carriedInputDrafts(inputs: readonly CarriedInput[]): Extract<SessionBoundaryDraft, {
|
|
14
|
+
type: "custom_message";
|
|
15
|
+
}>[];
|
|
16
|
+
export declare function isCarriedInputEntry(entry: SessionEntry): boolean;
|
|
9
17
|
/** A sticky note, not a letter: over this, empty_brain refuses instead of truncating. */
|
|
10
18
|
export declare const MAX_LAST_WORD_CHARS = 250;
|
|
11
19
|
/** How the next window finds the note. */
|
|
@@ -16,8 +24,8 @@ export declare function sanitizeLastWord(raw: string | undefined): string | unde
|
|
|
16
24
|
export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
|
|
17
25
|
/**
|
|
18
26
|
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
19
|
-
* continuation, then an optional parting line. The
|
|
20
|
-
*
|
|
27
|
+
* continuation, then an optional parting line. The lifecycle appends carried inputs in the same
|
|
28
|
+
* boundary after these artifacts. The boot snapshot is acquired asynchronously after capturing
|
|
21
29
|
* this identity. The continuation is drawn from the pool its origin names, here, once: the caller
|
|
22
30
|
* persists the returned text and no read, render, or repair draws it again. The origin defaults to
|
|
23
31
|
* `normal`, the same reading a legacy marker with no origin gets.
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../entries.js";
|
|
2
|
+
import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../entries.js";
|
|
3
3
|
import { selectContinuation } from "../../../src/budget/text.js";
|
|
4
4
|
import { isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, markerResetOrigin } from "../window.js";
|
|
5
5
|
import { buildBootMessage, sendBoot } from "../boot.js";
|
|
6
|
+
export function carriedInputDrafts(inputs) {
|
|
7
|
+
return inputs.map((content) => ({ type: "custom_message", customType: CARRIED_INPUT_TYPE, content, display: true }));
|
|
8
|
+
}
|
|
9
|
+
export function isCarriedInputEntry(entry) {
|
|
10
|
+
return entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE && entry.display === true;
|
|
11
|
+
}
|
|
6
12
|
/** A sticky note, not a letter: over this, empty_brain refuses instead of truncating. */
|
|
7
13
|
export const MAX_LAST_WORD_CHARS = 250;
|
|
8
14
|
/** How the next window finds the note. */
|
|
@@ -21,8 +27,8 @@ function sendContinuation(pi, content) {
|
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
|
|
24
|
-
* continuation, then an optional parting line. The
|
|
25
|
-
*
|
|
30
|
+
* continuation, then an optional parting line. The lifecycle appends carried inputs in the same
|
|
31
|
+
* boundary after these artifacts. The boot snapshot is acquired asynchronously after capturing
|
|
26
32
|
* this identity. The continuation is drawn from the pool its origin names, here, once: the caller
|
|
27
33
|
* persists the returned text and no read, render, or repair draws it again. The origin defaults to
|
|
28
34
|
* `normal`, the same reading a legacy marker with no origin gets.
|
|
@@ -56,6 +62,8 @@ export function inspectResetTail(ctx, markerId, windowId) {
|
|
|
56
62
|
return undefined;
|
|
57
63
|
let boot = false;
|
|
58
64
|
let continuation = false;
|
|
65
|
+
let lastWord = false;
|
|
66
|
+
let carried = false;
|
|
59
67
|
for (const entry of branch.slice(markerIndex + 1)) {
|
|
60
68
|
if (isWindowBootEntry(entry, windowId)) {
|
|
61
69
|
// The boot is unique and must precede the continuation; a repeat or a late
|
|
@@ -71,9 +79,20 @@ export function inspectResetTail(ctx, markerId, windowId) {
|
|
|
71
79
|
continuation = true;
|
|
72
80
|
continue;
|
|
73
81
|
}
|
|
74
|
-
if (
|
|
75
|
-
|
|
82
|
+
if (entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE) {
|
|
83
|
+
if (!continuation || lastWord || carried || entry.display !== true)
|
|
84
|
+
return undefined;
|
|
85
|
+
lastWord = true;
|
|
86
|
+
continue;
|
|
76
87
|
}
|
|
88
|
+
if (isCarriedInputEntry(entry)) {
|
|
89
|
+
if (!continuation)
|
|
90
|
+
return undefined;
|
|
91
|
+
carried = true;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (isForeignResetTailEntry(entry))
|
|
95
|
+
return undefined;
|
|
77
96
|
}
|
|
78
97
|
return { boot, continuation };
|
|
79
98
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { ResetOrigin } from "../../../src/budget/text.js";
|
|
3
|
+
import { type CarriedInput } from "./artifacts.js";
|
|
3
4
|
type BudgetOwner = {
|
|
4
5
|
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
5
6
|
hardReserveDue: (ctx: ExtensionContext) => boolean;
|
|
@@ -26,6 +27,7 @@ export type ResetRequest = {
|
|
|
26
27
|
readonly windowId: string;
|
|
27
28
|
readonly command?: {
|
|
28
29
|
readonly continueAfterReset: boolean;
|
|
30
|
+
readonly inputs?: readonly CarriedInput[];
|
|
29
31
|
};
|
|
30
32
|
readonly tool?: {
|
|
31
33
|
readonly lastWord?: string;
|
|
@@ -61,6 +63,11 @@ export type ResetControlEvent = {
|
|
|
61
63
|
readonly type: "command";
|
|
62
64
|
readonly windowId: string;
|
|
63
65
|
readonly continueAfterReset: boolean;
|
|
66
|
+
readonly input?: CarriedInput;
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: "input";
|
|
69
|
+
readonly windowId: string;
|
|
70
|
+
readonly input: CarriedInput;
|
|
64
71
|
} | {
|
|
65
72
|
readonly type: "tool_request";
|
|
66
73
|
readonly windowId: string;
|
|
@@ -71,12 +78,6 @@ export type ResetControlEvent = {
|
|
|
71
78
|
} | {
|
|
72
79
|
readonly type: "before_settle";
|
|
73
80
|
readonly facts: ResetBeforeSettleFacts;
|
|
74
|
-
} | {
|
|
75
|
-
readonly type: "settled";
|
|
76
|
-
} | {
|
|
77
|
-
readonly type: "abort";
|
|
78
|
-
} | {
|
|
79
|
-
readonly type: "clear";
|
|
80
81
|
};
|
|
81
82
|
export type ResetControlEffect = "none" | "close-out-armed" | "already-pending" | "commit-boundary" | "commit-boundary-stop" | "stop" | "recover-overflow";
|
|
82
83
|
export interface ResetControlResult {
|
|
@@ -94,8 +95,8 @@ export declare function reduceResetControl(state: ResetControlState, event: Rese
|
|
|
94
95
|
* Budget warnings carry no lifecycle state. Overflow recovery remains bounded.
|
|
95
96
|
*/
|
|
96
97
|
export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
|
|
97
|
-
command(windowId: string, continueAfterReset: boolean): ResetControlEffect;
|
|
98
|
+
command(windowId: string, continueAfterReset: boolean, input?: CarriedInput): ResetControlEffect;
|
|
98
99
|
request(windowId: string, lastWord?: string): "rollover_already_pending" | "rollover_requested";
|
|
99
|
-
clear: () => void;
|
|
100
|
+
clear: (preserveInputs?: boolean) => void;
|
|
100
101
|
};
|
|
101
102
|
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
|
|
2
3
|
import { currentReset, currentWindowId } from "../window.js";
|
|
3
4
|
import { nextHistorySeq } from "../history.js";
|
|
4
5
|
import { resetBoundaryCommitted } from "./committed.js";
|
|
5
6
|
import { errorMessage } from "../../../src/error-message.js";
|
|
7
|
+
import { carriedInputDrafts, isCarriedInputEntry } from "./artifacts.js";
|
|
8
|
+
import { NEXT_WINDOW_PROMPT_TYPE } from "../entries.js";
|
|
9
|
+
import { promptBlock } from "../text.js";
|
|
6
10
|
function isAbort(message, outcome, ctx) {
|
|
7
11
|
return outcome === "aborted" || (message.role === "assistant" && message.stopReason === "aborted") || ctx.signal?.aborted === true;
|
|
8
12
|
}
|
|
@@ -19,11 +23,15 @@ export function initialResetControl() {
|
|
|
19
23
|
function requestForWindow(request, windowId) {
|
|
20
24
|
return request.phase === "stop-pending" || (request.phase !== "none" && request.windowId === windowId) ? request : NO_REQUEST;
|
|
21
25
|
}
|
|
22
|
-
function
|
|
26
|
+
function commandContinues(request) {
|
|
27
|
+
return request.command?.continueAfterReset === true || (request.command?.inputs?.length ?? 0) > 0;
|
|
28
|
+
}
|
|
29
|
+
function commandCommit(request, overflow = false) {
|
|
23
30
|
return {
|
|
24
|
-
state:
|
|
25
|
-
effect: request
|
|
31
|
+
state: { request: NO_REQUEST, overflow: overflow ? "spent" : "idle" },
|
|
32
|
+
effect: commandContinues(request) ? "commit-boundary" : "commit-boundary-stop",
|
|
26
33
|
...requestDetails(request),
|
|
34
|
+
...(overflow ? { origin: "forced" } : {}),
|
|
27
35
|
};
|
|
28
36
|
}
|
|
29
37
|
/** The tool request itself is the origin fact; the stop latch retains it for construction retry. */
|
|
@@ -34,6 +42,12 @@ function requestDetails(request) {
|
|
|
34
42
|
/** Pure transitions: command policy schedules a reset without disguising actual tool calls. */
|
|
35
43
|
export function reduceResetControl(state, event) {
|
|
36
44
|
switch (event.type) {
|
|
45
|
+
case "input": {
|
|
46
|
+
const request = requestForWindow(state.request, event.windowId);
|
|
47
|
+
if (request.phase !== "pending" || !request.command)
|
|
48
|
+
return { state, effect: "none" };
|
|
49
|
+
return { state: { ...state, request: { ...request, command: { ...request.command, inputs: [...(request.command.inputs ?? []), event.input] } } }, effect: "none" };
|
|
50
|
+
}
|
|
37
51
|
case "command":
|
|
38
52
|
case "tool_request": {
|
|
39
53
|
const current = requestForWindow(state.request, event.windowId);
|
|
@@ -43,7 +57,7 @@ export function reduceResetControl(state, event) {
|
|
|
43
57
|
if (event.type === "command") {
|
|
44
58
|
if (request.command)
|
|
45
59
|
return { state, effect: "already-pending" };
|
|
46
|
-
return { state: { ...state, request: { ...request, command: { continueAfterReset: event.continueAfterReset } } }, effect: "close-out-armed" };
|
|
60
|
+
return { state: { ...state, request: { ...request, command: { continueAfterReset: event.continueAfterReset, ...(event.input !== undefined ? { inputs: [event.input] } : {}) } } }, effect: "close-out-armed" };
|
|
47
61
|
}
|
|
48
62
|
// The call remains a real request even when command policy delays its commit.
|
|
49
63
|
const duplicate = request.tool !== undefined;
|
|
@@ -75,7 +89,7 @@ export function reduceResetControl(state, event) {
|
|
|
75
89
|
// A direct tool request commits after the whole tool batch. The budget cutoff is
|
|
76
90
|
// a separate hard-reserve safety path; ordinary close-out waits for settlement.
|
|
77
91
|
if ((request.phase === "pending" && request.tool && !manual) || facts.hardReserveDue) {
|
|
78
|
-
if (manual && request
|
|
92
|
+
if (manual && commandContinues(request))
|
|
79
93
|
return commandCommit(request);
|
|
80
94
|
if (manual)
|
|
81
95
|
return { state: { request: { phase: "stop-pending", windowId: facts.windowId, ...(request.tool ? { tool: request.tool } : {}) }, overflow: "idle" }, effect: "commit-boundary-stop", ...requestDetails(request) };
|
|
@@ -105,7 +119,7 @@ export function reduceResetControl(state, event) {
|
|
|
105
119
|
// An explicit manual wipe is not an automatic recovery/retry. It must still
|
|
106
120
|
// clear on overflow, including when automatic reset is disabled.
|
|
107
121
|
if (manual && facts.enabled)
|
|
108
|
-
return commandCommit(request);
|
|
122
|
+
return commandCommit(request, true);
|
|
109
123
|
const spent = state.overflow === "pending-spent";
|
|
110
124
|
if (!facts.enabled || !facts.automaticResetEnabled) {
|
|
111
125
|
return { state: { request: facts.failed ? NO_REQUEST : request, overflow: spent ? "spent" : "idle" }, effect: "none" };
|
|
@@ -119,11 +133,6 @@ export function reduceResetControl(state, event) {
|
|
|
119
133
|
return { state: { ...state, request }, effect: "none" };
|
|
120
134
|
return commandCommit(request);
|
|
121
135
|
}
|
|
122
|
-
case "settled":
|
|
123
|
-
return { state: initialResetControl(), effect: "none" };
|
|
124
|
-
case "abort":
|
|
125
|
-
case "clear":
|
|
126
|
-
return { state: initialResetControl(), effect: "none" };
|
|
127
136
|
}
|
|
128
137
|
}
|
|
129
138
|
/**
|
|
@@ -135,8 +144,33 @@ export function registerResetLifecycle(pi, options) {
|
|
|
135
144
|
let sessionActive = true;
|
|
136
145
|
let lifecycleGeneration = 0;
|
|
137
146
|
let control = initialResetControl();
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
let runInputs = [];
|
|
148
|
+
let commandId;
|
|
149
|
+
// Once input returns handled, Pi no longer owns its original content. If close-out
|
|
150
|
+
// fails/cancels, return that content to the transcript without starting another run.
|
|
151
|
+
const restoreCommandInputs = () => {
|
|
152
|
+
const request = control.request;
|
|
153
|
+
if (request.phase !== "pending" || !request.command?.inputs?.length)
|
|
154
|
+
return;
|
|
155
|
+
const inputs = request.command.inputs;
|
|
156
|
+
control = { ...control, request: { ...request, command: { ...request.command, inputs: [] } } };
|
|
157
|
+
for (const draft of carriedInputDrafts(inputs)) {
|
|
158
|
+
pi.sendMessage(draft, { triggerTurn: false });
|
|
159
|
+
}
|
|
160
|
+
runInputs.push(...inputs);
|
|
161
|
+
};
|
|
162
|
+
const clear = (preserveInputs = true) => {
|
|
163
|
+
if (preserveInputs)
|
|
164
|
+
restoreCommandInputs();
|
|
165
|
+
control = initialResetControl();
|
|
166
|
+
runInputs = [];
|
|
167
|
+
commandId = undefined;
|
|
168
|
+
};
|
|
169
|
+
const resetBoundaryResult = async (entries, ctx, decision) => {
|
|
170
|
+
// Keep command state live while notes load: input arriving during this await must
|
|
171
|
+
// join this very boundary even if its steer cannot reach the closing model.
|
|
172
|
+
const passiveInputs = decision.effect === "recover-overflow" ? runInputs : [];
|
|
173
|
+
const origin = decision.origin ?? "forced";
|
|
140
174
|
const generation = lifecycleGeneration;
|
|
141
175
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
142
176
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -148,7 +182,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
148
182
|
const firstSeq = nextHistorySeq(ctx, entries) + 1;
|
|
149
183
|
let resetDrafts;
|
|
150
184
|
try {
|
|
151
|
-
resetDrafts = await options.buildReset(ctx, isCurrent, lastWord, firstSeq, origin);
|
|
185
|
+
resetDrafts = await options.buildReset(ctx, isCurrent, decision.lastWord, firstSeq, origin);
|
|
152
186
|
}
|
|
153
187
|
catch (error) {
|
|
154
188
|
if (isCurrent())
|
|
@@ -157,23 +191,61 @@ export function registerResetLifecycle(pi, options) {
|
|
|
157
191
|
}
|
|
158
192
|
if (!isCurrent())
|
|
159
193
|
return entries.length > 0 ? { entries } : undefined;
|
|
194
|
+
const request = control.request;
|
|
195
|
+
const inputs = request.phase === "pending" && request.command ? request.command.inputs ?? [] : passiveInputs;
|
|
196
|
+
control = decision.state;
|
|
197
|
+
if (inputs.length > 0 && control.request.phase === "stop-pending")
|
|
198
|
+
control = { ...control, request: NO_REQUEST };
|
|
199
|
+
runInputs = [];
|
|
160
200
|
options.onResetReady?.(ctx, resetDrafts);
|
|
161
|
-
return { entries: [...entries, ...resetDrafts], continue:
|
|
201
|
+
return { entries: [...entries, ...resetDrafts, ...carriedInputDrafts(inputs)], continue: inputs.length > 0 || decision.effect !== "commit-boundary-stop" };
|
|
162
202
|
};
|
|
203
|
+
// Pi may start multiple low-level loops while draining follow-ups/recovering.
|
|
204
|
+
// Keep the logical run's inputs until settlement or a successful boundary.
|
|
205
|
+
pi.on("message_end", (event) => {
|
|
206
|
+
if (event.message.role === "user")
|
|
207
|
+
runInputs.push(event.message.content);
|
|
208
|
+
});
|
|
209
|
+
pi.on("input", (event, ctx) => {
|
|
210
|
+
if (event.source === "extension" || !sessionActive || !options.isEnabled())
|
|
211
|
+
return undefined;
|
|
212
|
+
const request = control.request;
|
|
213
|
+
if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx))
|
|
214
|
+
return undefined;
|
|
215
|
+
const content = event.images?.length
|
|
216
|
+
? [{ type: "text", text: event.text }, ...event.images]
|
|
217
|
+
: event.text;
|
|
218
|
+
control = reduceResetControl(control, { type: "input", windowId: request.windowId, input: content }).state;
|
|
219
|
+
const steerContent = event.images?.length
|
|
220
|
+
? [{ type: "text", text: promptBlock(event.text) }, ...event.images]
|
|
221
|
+
: promptBlock(event.text);
|
|
222
|
+
pi.sendMessage({ customType: NEXT_WINDOW_PROMPT_TYPE, content: steerContent, display: false, details: { windowId: request.windowId, commandId } }, { deliverAs: "steer" });
|
|
223
|
+
return { action: "handled" };
|
|
224
|
+
});
|
|
163
225
|
// Boundary continue:false is not a veto of Pi's tool-batch follow-up. Once the
|
|
164
226
|
// safety reset is actually committed, cancel that empty follow-up before provider
|
|
165
227
|
// work. Real queued user input is allowed through and answered before settlement.
|
|
166
228
|
pi.on("context_with_system", (event, ctx) => {
|
|
167
229
|
const request = control.request;
|
|
230
|
+
// Steering can be queued during buildReset's await and arrive after the boundary.
|
|
231
|
+
// It is closing-model context only; originals already live in the carried entries.
|
|
232
|
+
const messages = event.messages.filter((message) => {
|
|
233
|
+
if (message.role !== "custom" || message.customType !== NEXT_WINDOW_PROMPT_TYPE)
|
|
234
|
+
return true;
|
|
235
|
+
const details = message.details;
|
|
236
|
+
return request.phase === "pending" && request.command !== undefined &&
|
|
237
|
+
request.windowId === currentWindowId(ctx) && details?.windowId === request.windowId && commandId !== undefined && details?.commandId === commandId;
|
|
238
|
+
});
|
|
239
|
+
const filtered = messages.length === event.messages.length ? undefined : { messages };
|
|
168
240
|
if (!sessionActive || request.phase !== "stop-pending" || ctx.hasPendingMessages())
|
|
169
|
-
return
|
|
241
|
+
return filtered;
|
|
170
242
|
const marker = currentReset(ctx);
|
|
171
243
|
if (!marker || marker.data.windowId === request.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId))
|
|
172
|
-
return
|
|
244
|
+
return filtered;
|
|
173
245
|
const branch = ctx.sessionManager.getBranch();
|
|
174
246
|
const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
|
|
175
|
-
if (branch.slice(markerIndex + 1).some((entry) => entry.type === "message" && entry.message.role === "user"))
|
|
176
|
-
return
|
|
247
|
+
if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry)))
|
|
248
|
+
return filtered;
|
|
177
249
|
ctx.abort();
|
|
178
250
|
const system = getCurrentSystemMessage(event.messages);
|
|
179
251
|
return { messages: system ? [system] : [] };
|
|
@@ -198,9 +270,11 @@ export function registerResetLifecycle(pi, options) {
|
|
|
198
270
|
get hardReserveDue() { return options.budget.hardReserveDue(ctx); },
|
|
199
271
|
},
|
|
200
272
|
});
|
|
201
|
-
control = decision.state;
|
|
202
273
|
if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop")
|
|
203
|
-
return await resetBoundaryResult(entries, ctx, decision
|
|
274
|
+
return await resetBoundaryResult(entries, ctx, decision);
|
|
275
|
+
if (aborted || (event.outcome === "error" && decision.state.request.phase === "none"))
|
|
276
|
+
restoreCommandInputs();
|
|
277
|
+
control = decision.state;
|
|
204
278
|
return entries.length > 0 ? { entries } : undefined;
|
|
205
279
|
});
|
|
206
280
|
pi.on("agent_before_settle", async (event, ctx) => {
|
|
@@ -217,12 +291,14 @@ export function registerResetLifecycle(pi, options) {
|
|
|
217
291
|
failed: event.outcome === "error",
|
|
218
292
|
},
|
|
219
293
|
});
|
|
294
|
+
if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop" || decision.effect === "recover-overflow")
|
|
295
|
+
return await resetBoundaryResult(event.entries, ctx, decision);
|
|
296
|
+
if (decision.state.request.phase === "none")
|
|
297
|
+
restoreCommandInputs();
|
|
220
298
|
control = decision.state;
|
|
221
299
|
if (decision.effect === "stop")
|
|
222
300
|
return { entries: event.entries, continue: false };
|
|
223
|
-
|
|
224
|
-
return undefined;
|
|
225
|
-
return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.lastWord, decision.origin ?? "forced");
|
|
301
|
+
return undefined;
|
|
226
302
|
});
|
|
227
303
|
pi.on("session_before_compact", (event, ctx) => {
|
|
228
304
|
if (!sessionActive)
|
|
@@ -240,18 +316,20 @@ export function registerResetLifecycle(pi, options) {
|
|
|
240
316
|
});
|
|
241
317
|
pi.on("agent_end", (_event, ctx) => {
|
|
242
318
|
if (ctx.signal?.aborted)
|
|
243
|
-
|
|
319
|
+
clear();
|
|
244
320
|
});
|
|
245
321
|
pi.on("agent_settled", () => {
|
|
246
|
-
|
|
322
|
+
clear();
|
|
247
323
|
});
|
|
248
|
-
pi.on("session_start", () => { lifecycleGeneration++; clear(); sessionActive = true; });
|
|
249
|
-
pi.on("session_tree", () => { lifecycleGeneration++; clear(); });
|
|
250
|
-
pi.on("session_shutdown", () => { lifecycleGeneration++; clear(); options.budget.clear(); sessionActive = false; });
|
|
324
|
+
pi.on("session_start", () => { lifecycleGeneration++; clear(false); sessionActive = true; });
|
|
325
|
+
pi.on("session_tree", () => { lifecycleGeneration++; clear(false); });
|
|
326
|
+
pi.on("session_shutdown", () => { lifecycleGeneration++; clear(false); options.budget.clear(); sessionActive = false; });
|
|
251
327
|
return {
|
|
252
|
-
command(windowId, continueAfterReset) {
|
|
253
|
-
const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset });
|
|
328
|
+
command(windowId, continueAfterReset, input) {
|
|
329
|
+
const decision = reduceResetControl(control, { type: "command", windowId, continueAfterReset, ...(input !== undefined ? { input } : {}) });
|
|
254
330
|
control = decision.state;
|
|
331
|
+
if (decision.effect === "close-out-armed")
|
|
332
|
+
commandId = randomUUID();
|
|
255
333
|
return decision.effect;
|
|
256
334
|
},
|
|
257
335
|
request(windowId, lastWord) {
|
|
@@ -6,9 +6,9 @@ import { registerBudget } from "./budget.js";
|
|
|
6
6
|
import { output } from "./tool-result.js";
|
|
7
7
|
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
|
-
import { buildResetDrafts,
|
|
10
|
-
import { BOOT_TYPE, MANUAL_WIPE_TYPE
|
|
11
|
-
import {
|
|
9
|
+
import { buildResetDrafts, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
10
|
+
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
11
|
+
import { commandWarningContent } from "./text.js";
|
|
12
12
|
import { buildBootMessage, sendBoot } from "./boot.js";
|
|
13
13
|
import { nextHistorySeq } from "./history.js";
|
|
14
14
|
import { errorMessage } from "../../src/error-message.js";
|
|
@@ -72,11 +72,10 @@ export function registerContext(pi, settingsManager) {
|
|
|
72
72
|
if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId))
|
|
73
73
|
continue;
|
|
74
74
|
pendingResetNotices.delete(windowId);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const lastWord = lastWordEntry?.content?.startsWith(LAST_WORD_PREFIX) ? lastWordEntry.content.slice(LAST_WORD_PREFIX.length) : undefined;
|
|
75
|
+
// The last word already lands as its own visible sticky-note entry; the
|
|
76
|
+
// committed notice stays a one-line marker instead of repeating it.
|
|
78
77
|
const forced = markerResetOrigin(marker) === "forced";
|
|
79
|
-
ctx.ui.notify(
|
|
78
|
+
ctx.ui.notify(forced ? "🥣 Brain forcibly emptied: overflow" : "🥣 Fresh brain", forced ? "warning" : "info");
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
pi.on("turn_start", (_event, ctx) => notifyCommittedResets(ctx));
|
|
@@ -187,15 +186,15 @@ export function registerContext(pi, settingsManager) {
|
|
|
187
186
|
// Manual wipes close out at settlement, then stop or continue with the prompt. The hidden warning goes out in both cases — triggered when idle,
|
|
188
187
|
// steered into the running turn when busy — so the agent closes out promptly
|
|
189
188
|
// instead of the reset waiting for the whole run.
|
|
190
|
-
const prompt = args.trim()
|
|
191
|
-
const armed = resets.command(requestedWindowId, prompt !== undefined);
|
|
189
|
+
const prompt = args.trim() ? args : undefined;
|
|
190
|
+
const armed = resets.command(requestedWindowId, prompt !== undefined, prompt);
|
|
192
191
|
if (armed === "already-pending") {
|
|
193
192
|
cmdCtx.ui.notify("🥣 Brain already being emptied", "info");
|
|
194
193
|
return;
|
|
195
194
|
}
|
|
196
195
|
cmdCtx.ui.notify("🥣 Brain being emptied", "info");
|
|
197
196
|
try {
|
|
198
|
-
pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content:
|
|
197
|
+
pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: commandWarningContent(prompt !== undefined ? `/empty ${prompt}` : undefined), display: false }, { triggerTurn: true, deliverAs: "steer" });
|
|
199
198
|
}
|
|
200
199
|
catch (error) {
|
|
201
200
|
resets.clear();
|
|
@@ -4,20 +4,17 @@
|
|
|
4
4
|
* view intact must not carry these — the claim would be false there. The bare `empty_brain` token
|
|
5
5
|
* is interpolated by renderProtocolBlock; the prose itself stays plain English.
|
|
6
6
|
*/
|
|
7
|
-
export declare const PI_PRE_RESET_HINTS = "
|
|
7
|
+
export declare const PI_PRE_RESET_HINTS = "Anything you say here is erased with the reset \u2014 the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.\nUnless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.";
|
|
8
8
|
/** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
|
|
9
9
|
export declare const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
10
|
-
/**
|
|
11
|
-
* With a prompt attached the close-out is an order rather than a nudge: the human already
|
|
12
|
-
* said when to reset, and a task line for the next window just preceded it. Only Pi has a
|
|
13
|
-
* reset command that takes a prompt, so this lives with the Pi text.
|
|
14
|
-
*/
|
|
15
|
-
export declare const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away \u2014 do not wait to be cut off.";
|
|
16
|
-
/**
|
|
17
|
-
* The human typed `/empty <prompt>`: the raw command line leads the close-out so the
|
|
18
|
-
* closing model sees what the next window was asked to do, verbatim. The tag names it as the
|
|
19
|
-
* next window's prompt, so no prose has to explain that.
|
|
20
|
-
*/
|
|
10
|
+
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
21
11
|
export declare function promptBlock(commandLine: string): string;
|
|
22
|
-
/**
|
|
23
|
-
export declare function warningContent(
|
|
12
|
+
/** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
|
|
13
|
+
export declare function warningContent(): string;
|
|
14
|
+
/** Approved manual close-out notices; both variants live here. */
|
|
15
|
+
export declare const COMMAND_NOTICE: {
|
|
16
|
+
prompted: string;
|
|
17
|
+
bare: string;
|
|
18
|
+
};
|
|
19
|
+
/** Manual orders omit budget timing hints; deferred work sits outside the notice. */
|
|
20
|
+
export declare function commandWarningContent(commandLine?: string): string;
|
package/dist/plugins/pi/text.js
CHANGED
|
@@ -5,26 +5,25 @@ import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WA
|
|
|
5
5
|
* view intact must not carry these — the claim would be false there. The bare `empty_brain` token
|
|
6
6
|
* is interpolated by renderProtocolBlock; the prose itself stays plain English.
|
|
7
7
|
*/
|
|
8
|
-
export const PI_PRE_RESET_HINTS = `
|
|
8
|
+
export const PI_PRE_RESET_HINTS = `Anything you say here is erased with the reset — the human can't read it afterward either. Put the handoff in your notes; explanations belong after the reset.
|
|
9
9
|
Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
|
|
10
10
|
/** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
|
|
11
11
|
export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
12
|
-
/**
|
|
13
|
-
* With a prompt attached the close-out is an order rather than a nudge: the human already
|
|
14
|
-
* said when to reset, and a task line for the next window just preceded it. Only Pi has a
|
|
15
|
-
* reset command that takes a prompt, so this lives with the Pi text.
|
|
16
|
-
*/
|
|
17
|
-
export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away — do not wait to be cut off.";
|
|
18
|
-
/**
|
|
19
|
-
* The human typed `/empty <prompt>`: the raw command line leads the close-out so the
|
|
20
|
-
* closing model sees what the next window was asked to do, verbatim. The tag names it as the
|
|
21
|
-
* next window's prompt, so no prose has to explain that.
|
|
22
|
-
*/
|
|
12
|
+
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
23
13
|
export function promptBlock(commandLine) {
|
|
24
14
|
return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
|
|
25
15
|
}
|
|
26
|
-
/**
|
|
27
|
-
export function warningContent(
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
/** Pi's hidden budget warning (dsh reads warningPrompt() directly). */
|
|
17
|
+
export function warningContent() {
|
|
18
|
+
return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${WARNING_CALL}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
|
|
19
|
+
}
|
|
20
|
+
/** Approved manual close-out notices; both variants live here. */
|
|
21
|
+
export const COMMAND_NOTICE = {
|
|
22
|
+
prompted: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward — put the handoff in your notes. The prompt below, and anything the human sends from now on, should be handled after the reset.",
|
|
23
|
+
bare: "The human ran /empty. Save your notes now and call `empty_brain` immediately. Anything you say here will be erased afterward — put the handoff in your notes. Anything the human sends from now on should be handled after the reset.",
|
|
24
|
+
};
|
|
25
|
+
/** Manual orders omit budget timing hints; deferred work sits outside the notice. */
|
|
26
|
+
export function commandWarningContent(commandLine) {
|
|
27
|
+
const notice = commandLine ? COMMAND_NOTICE.prompted : COMMAND_NOTICE.bare;
|
|
28
|
+
return `${GUIDANCE_OPEN_TAG}\n${notice}\n${WARNING_BODY}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}${commandLine ? `\n${promptBlock(commandLine)}` : ""}`;
|
|
30
29
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This is the deliberate embedding surface for a host adapter — a curated list, not a re-export
|
|
10
10
|
* of every internal module. The notes family is also published as `notesoup/notes`; the Pi
|
|
11
|
-
* extension is
|
|
11
|
+
* extension is loaded through the Pi manifest; dsh uses `notesoup/dsh` and `notesoup/dsh/engine`.
|
|
12
12
|
*/
|
|
13
13
|
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
14
14
|
export type { NoteEditResult, NoteMatch, NoteMeta, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NotesIdentity, NotesQuery, NotesStore, NoteWriteResult, Origin, Scope, } from "./notes/index.js";
|
package/dist/src/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This is the deliberate embedding surface for a host adapter — a curated list, not a re-export
|
|
10
10
|
* of every internal module. The notes family is also published as `notesoup/notes`; the Pi
|
|
11
|
-
* extension is
|
|
11
|
+
* extension is loaded through the Pi manifest; dsh uses `notesoup/dsh` and `notesoup/dsh/engine`.
|
|
12
12
|
*/
|
|
13
13
|
// Notes: the standalone filesystem library, addressed by an explicit identity.
|
|
14
14
|
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|