notesoup 0.61.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -11
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +24 -5
- package/dist/plugins/claude/src/text.d.ts +7 -0
- package/dist/plugins/claude/src/text.js +12 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +4 -1
- package/dist/plugins/pi/budget.js +35 -8
- package/dist/plugins/pi/entries.d.ts +2 -0
- package/dist/plugins/pi/entries.js +2 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
- package/dist/plugins/pi/reset/artifacts.js +4 -4
- package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
- package/dist/plugins/pi/reset/lifecycle.js +109 -31
- package/dist/plugins/pi/runtime.js +104 -63
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +25 -3
- package/dist/plugins/pi/window.js +219 -9
- package/dist/src/boot/render.js +18 -15
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +22 -20
- package/dist/src/budget/text.d.ts +7 -3
- package/dist/src/budget/text.js +24 -15
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +0 -2
- package/dist/src/notes/frontmatter.js +0 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +46 -5
- package/dist/src/notes/store.d.ts +12 -0
- package/dist/src/notes/store.js +16 -20
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -93
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +51 -163
- package/dist/src/tools/notes.js +146 -100
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +394 -56
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +156 -15
- package/dist/test/budget-settings.integration.test.js +4 -4
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +199 -16
- package/dist/test/claude-validation.test.js +69 -2
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +68 -3
- package/dist/test/helpers/extension.js +74 -5
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/model-facing-text.test.js +13 -3
- package/dist/test/note-policy.test.js +96 -77
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +12 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +36 -38
- package/docs/dsh.md +3 -3
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +4 -4
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +1 -1
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1108 -539
- package/plugins/claude/hooks/register.ts +202 -62
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +24 -5
- package/plugins/claude/src/text.ts +14 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18480 -17946
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +31 -8
- package/plugins/pi/entries.ts +2 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/artifacts.ts +4 -3
- package/plugins/pi/reset/lifecycle.ts +125 -32
- package/plugins/pi/runtime.ts +98 -62
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +210 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup-guide/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +27 -15
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +2 -2
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +0 -3
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +44 -5
- package/src/notes/store.ts +17 -20
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +145 -113
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { AgentBeforeSettleEvent, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { TURNOVER_TRIGGER_TYPE } from "../entries.js";
|
|
4
5
|
import { currentReset, currentWindowId } from "../window.js";
|
|
5
6
|
import { nextHistorySeq } from "../history.js";
|
|
6
7
|
import { buildMarkerDraft } from "../marker.js";
|
|
@@ -12,14 +13,16 @@ import { carriedInputDrafts, isCarriedInputEntry, type CarriedInput } from "./ar
|
|
|
12
13
|
type BudgetOwner = {
|
|
13
14
|
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
14
15
|
hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
|
|
16
|
+
hardReserveDueForInput?: (ctx: ExtensionContext, content: CarriedInput) => boolean;
|
|
17
|
+
fitsInFreshWindow?: (ctx: ExtensionContext, content: CarriedInput) => boolean;
|
|
15
18
|
consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
|
|
16
19
|
clear: () => void;
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
type ResetOptions = {
|
|
20
|
-
isEnabled: () => boolean;
|
|
23
|
+
isEnabled: (ctx: ExtensionContext) => boolean;
|
|
21
24
|
budget: BudgetOwner;
|
|
22
|
-
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
25
|
+
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin, betweenTurns?: boolean) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
23
26
|
getLifecycleGeneration?: () => number;
|
|
24
27
|
onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
|
|
25
28
|
};
|
|
@@ -64,6 +67,10 @@ export interface ResetTurnEndFacts {
|
|
|
64
67
|
readonly queued: boolean;
|
|
65
68
|
readonly automaticResetEnabled: boolean;
|
|
66
69
|
readonly hardReserveDue: boolean;
|
|
70
|
+
/** True when this turn still has follow-up work (tool batch, pre-send cutoff, or queued input). */
|
|
71
|
+
readonly hasPendingWork: boolean;
|
|
72
|
+
/** True when the host view erases scrollback on reset (Pi TUI), so clean answers defer rollover until next input. */
|
|
73
|
+
readonly deferBetweenTurns?: boolean;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
/** Facts for the pre-settlement boundary; policy guards stay lazy for the same reason. */
|
|
@@ -91,6 +98,7 @@ export interface ResetBoundaryIntent {
|
|
|
91
98
|
readonly windowId: string;
|
|
92
99
|
readonly continueAfterReset: boolean;
|
|
93
100
|
readonly origin: ResetOrigin;
|
|
101
|
+
readonly betweenTurns?: boolean;
|
|
94
102
|
readonly tool?: { readonly lastWord?: string; readonly terminate?: boolean };
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -115,7 +123,7 @@ export function finalizeResetBoundary(intent: ResetBoundaryIntent, request: Rese
|
|
|
115
123
|
const resumeModel = intent.continueAfterReset || inputs.length > 0;
|
|
116
124
|
const state: ResetControlState = {
|
|
117
125
|
request: NO_REQUEST,
|
|
118
|
-
...(intent.boundary === "turn-end" && !resumeModel ? { stopAfterReset: intent } : {}),
|
|
126
|
+
...(intent.boundary === "turn-end" && !resumeModel && !intent.betweenTurns ? { stopAfterReset: intent } : {}),
|
|
119
127
|
overflow: spendsOverflow(intent.boundary) ? "spent" : "idle",
|
|
120
128
|
};
|
|
121
129
|
return { state, inputs, resumeModel };
|
|
@@ -167,12 +175,30 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
|
|
|
167
175
|
if (!facts.enabled) {
|
|
168
176
|
return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "none" };
|
|
169
177
|
}
|
|
170
|
-
// A direct tool request commits after the whole tool batch.
|
|
171
|
-
//
|
|
178
|
+
// A direct tool request commits after the whole tool batch. An automatic hard-reserve
|
|
179
|
+
// cutoff fires at turn_end with continuation while work is still in flight (tool batch,
|
|
180
|
+
// pre-send, queued input, or manual close-out). For a clean final answer:
|
|
181
|
+
// - non-erasing views (RPC/print/JSON) rotate quietly at turn_end with continue:false;
|
|
182
|
+
// - scrollback-erasing views (Pi TUI) defer rollover until the human's next input.
|
|
172
183
|
const toolReset = request.phase === "pending" && request.tool !== undefined;
|
|
173
|
-
if (
|
|
184
|
+
if (toolReset && !manual) {
|
|
174
185
|
return boundaryIntent(request, facts.windowId, "turn-end");
|
|
175
186
|
}
|
|
187
|
+
if (facts.hardReserveDue) {
|
|
188
|
+
if (manual || toolReset || facts.hasPendingWork) {
|
|
189
|
+
return boundaryIntent(request, facts.windowId, "turn-end");
|
|
190
|
+
}
|
|
191
|
+
if (!facts.deferBetweenTurns) {
|
|
192
|
+
return {
|
|
193
|
+
effect: "build-boundary",
|
|
194
|
+
boundary: "turn-end",
|
|
195
|
+
windowId: facts.windowId,
|
|
196
|
+
continueAfterReset: false,
|
|
197
|
+
origin: "forced",
|
|
198
|
+
betweenTurns: true,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
176
202
|
return { state: { request, overflow: "idle" }, effect: "none" };
|
|
177
203
|
}
|
|
178
204
|
case "before_settle": {
|
|
@@ -221,6 +247,9 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
221
247
|
let control = initialResetControl();
|
|
222
248
|
let preSendHardReserveWindowId: string | undefined;
|
|
223
249
|
let pendingPreSendTrigger: Extract<SessionBoundaryDraft, { type: "custom_message" }> | undefined;
|
|
250
|
+
let pendingTurnover: { readonly windowId: string; readonly inputs: CarriedInput[] } | undefined;
|
|
251
|
+
let pendingUserReplays: CarriedInput[] = [];
|
|
252
|
+
let failedTurnoverWindowId: string | undefined;
|
|
224
253
|
|
|
225
254
|
// Once input returns handled, Pi no longer owns its original content. If close-out
|
|
226
255
|
// fails/cancels, restore it; only an ordinary error starts a turn to answer it.
|
|
@@ -237,24 +266,43 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
237
266
|
lifecycleGeneration++;
|
|
238
267
|
preSendHardReserveWindowId = undefined;
|
|
239
268
|
pendingPreSendTrigger = undefined;
|
|
240
|
-
|
|
269
|
+
const turnoverInputs = pendingTurnover?.inputs ?? [];
|
|
270
|
+
pendingTurnover = undefined;
|
|
271
|
+
pendingUserReplays = [];
|
|
272
|
+
if (preserveInputs) {
|
|
273
|
+
restoreCommandInputs();
|
|
274
|
+
for (const draft of carriedInputDrafts(turnoverInputs)) {
|
|
275
|
+
pi.sendMessage(draft, { triggerTurn: false });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
241
278
|
control = initialResetControl();
|
|
242
279
|
};
|
|
243
|
-
const resetBoundaryResult = async (
|
|
244
|
-
|
|
280
|
+
const resetBoundaryResult = async (
|
|
281
|
+
entries: SessionBoundaryDraft[],
|
|
282
|
+
ctx: ExtensionContext,
|
|
283
|
+
intent: ResetBoundaryIntent,
|
|
284
|
+
preSendHardReserve = false,
|
|
285
|
+
turnover?: { readonly windowId: string; readonly inputs: CarriedInput[] },
|
|
286
|
+
) => {
|
|
287
|
+
// Keep command/turnover state live while notes load so input arriving during this await joins this boundary.
|
|
245
288
|
const generation = lifecycleGeneration;
|
|
246
289
|
const outerGeneration = options.getLifecycleGeneration?.();
|
|
247
290
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
248
291
|
const windowId = currentWindowId(ctx);
|
|
249
292
|
const isCurrent = () => sessionActive && lifecycleGeneration === generation &&
|
|
250
|
-
(outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled() &&
|
|
293
|
+
(outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled(ctx) &&
|
|
251
294
|
(preSendHardReserve || ctx.signal?.aborted !== true) && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
252
295
|
// The retain-none checkpoint belongs to the old window; capture its successor before notes await.
|
|
253
296
|
const firstSeq = nextHistorySeq(ctx, entries) + 1;
|
|
254
297
|
let resetDrafts: SessionBoundaryDraft[];
|
|
255
298
|
try {
|
|
256
|
-
resetDrafts = await options.buildReset(ctx, isCurrent, intent.tool?.lastWord, firstSeq, intent.origin);
|
|
299
|
+
resetDrafts = await options.buildReset(ctx, isCurrent, intent.tool?.lastWord, firstSeq, intent.origin, turnover !== undefined || intent.betweenTurns === true);
|
|
257
300
|
} catch (error) {
|
|
301
|
+
if (turnover && pendingTurnover === turnover) {
|
|
302
|
+
pendingUserReplays = [...turnover.inputs];
|
|
303
|
+
pendingTurnover = undefined;
|
|
304
|
+
failedTurnoverWindowId = windowId;
|
|
305
|
+
}
|
|
258
306
|
if (isCurrent()) ctx.ui.notify(`🥣 Brain still full: ${errorMessage(error)}`, "warning");
|
|
259
307
|
return entries.length > 0 ? { entries } : undefined;
|
|
260
308
|
}
|
|
@@ -262,6 +310,13 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
262
310
|
const finalized = finalizeResetBoundary(intent, control.request);
|
|
263
311
|
control = finalized.state;
|
|
264
312
|
options.onResetReady?.(ctx, resetDrafts);
|
|
313
|
+
if (turnover && pendingTurnover === turnover) {
|
|
314
|
+
// Commit the entire fresh window atomically; agent_settled delivers the withheld user prompt directly.
|
|
315
|
+
pendingUserReplays = [...turnover.inputs];
|
|
316
|
+
pendingTurnover = undefined;
|
|
317
|
+
failedTurnoverWindowId = undefined;
|
|
318
|
+
return { entries: [...entries, ...resetDrafts], continue: false };
|
|
319
|
+
}
|
|
265
320
|
const allDrafts = [...resetDrafts, ...carriedInputDrafts(finalized.inputs)];
|
|
266
321
|
if (preSendHardReserve && finalized.resumeModel) {
|
|
267
322
|
const last = allDrafts.at(-1);
|
|
@@ -274,14 +329,39 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
274
329
|
};
|
|
275
330
|
|
|
276
331
|
pi.on("input", (event, ctx) => {
|
|
277
|
-
if (event.source === "extension" || !sessionActive || !options.isEnabled()) return undefined;
|
|
278
|
-
const request = control.request;
|
|
279
|
-
if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx)) return undefined;
|
|
332
|
+
if (event.source === "extension" || !sessionActive || !options.isEnabled(ctx)) return undefined;
|
|
280
333
|
const content: CarriedInput = event.images?.length
|
|
281
334
|
? [{ type: "text", text: event.text }, ...event.images]
|
|
282
335
|
: event.text;
|
|
283
|
-
|
|
284
|
-
|
|
336
|
+
const windowId = currentWindowId(ctx);
|
|
337
|
+
const request = control.request;
|
|
338
|
+
if (request.phase === "pending" && request.command && request.windowId === windowId) {
|
|
339
|
+
control = reduceResetControl(control, { type: "input", windowId, input: content }).state;
|
|
340
|
+
return { action: "handled" };
|
|
341
|
+
}
|
|
342
|
+
if (pendingTurnover && pendingTurnover.windowId === windowId) {
|
|
343
|
+
pendingTurnover.inputs.push(content);
|
|
344
|
+
return { action: "handled" };
|
|
345
|
+
}
|
|
346
|
+
if (
|
|
347
|
+
ctx.mode === "tui" &&
|
|
348
|
+
event.source === "interactive" &&
|
|
349
|
+
!event.streamingBehavior &&
|
|
350
|
+
ctx.isIdle() &&
|
|
351
|
+
request.phase === "none" &&
|
|
352
|
+
!control.stopAfterReset &&
|
|
353
|
+
failedTurnoverWindowId !== windowId &&
|
|
354
|
+
(options.budget.hardReserveDueForInput
|
|
355
|
+
? options.budget.hardReserveDueForInput(ctx, content)
|
|
356
|
+
: options.budget.hardReserveDue(ctx))
|
|
357
|
+
) {
|
|
358
|
+
const fits = options.budget.fitsInFreshWindow ? options.budget.fitsInFreshWindow(ctx, content) : true;
|
|
359
|
+
if (!fits) return undefined;
|
|
360
|
+
pendingTurnover = { windowId, inputs: [content] };
|
|
361
|
+
pi.sendMessage({ customType: TURNOVER_TRIGGER_TYPE, content: "", display: false }, { triggerTurn: true });
|
|
362
|
+
return { action: "handled" };
|
|
363
|
+
}
|
|
364
|
+
return undefined;
|
|
285
365
|
});
|
|
286
366
|
|
|
287
367
|
// Boundary continue:false is not a veto of Pi's tool-batch follow-up. Once the
|
|
@@ -301,10 +381,12 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
301
381
|
const system = getCurrentSystemMessage(event.messages);
|
|
302
382
|
return { messages: system ? [system] : [] };
|
|
303
383
|
}
|
|
304
|
-
if (!options.isEnabled() || ctx.signal?.aborted) return undefined;
|
|
384
|
+
if (!options.isEnabled(ctx) || ctx.signal?.aborted) return undefined;
|
|
305
385
|
if (control.request.phase === "pending" && control.request.command !== undefined) return undefined;
|
|
306
|
-
|
|
307
|
-
|
|
386
|
+
const windowId = currentWindowId(ctx);
|
|
387
|
+
const turnoverDue = pendingTurnover !== undefined && pendingTurnover.windowId === windowId;
|
|
388
|
+
if (!turnoverDue && (failedTurnoverWindowId === windowId || !options.budget.hardReserveDue(ctx, event.messages))) return undefined;
|
|
389
|
+
preSendHardReserveWindowId = windowId;
|
|
308
390
|
ctx.abort();
|
|
309
391
|
const system = getCurrentSystemMessage(event.messages);
|
|
310
392
|
return { messages: system ? [system] : [] };
|
|
@@ -315,10 +397,12 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
315
397
|
const windowId = currentWindowId(ctx);
|
|
316
398
|
const preSendHardReserve = preSendHardReserveWindowId !== undefined && preSendHardReserveWindowId === windowId;
|
|
317
399
|
preSendHardReserveWindowId = undefined;
|
|
400
|
+
const turnover = preSendHardReserve && pendingTurnover?.windowId === windowId ? pendingTurnover : undefined;
|
|
318
401
|
const aborted = preSendHardReserve ? false : isAbort(event.message, event.outcome, ctx);
|
|
319
402
|
const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
|
|
320
|
-
const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
|
|
403
|
+
const budgetEntries = options.isEnabled(ctx) && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
|
|
321
404
|
const entries = [...(event.entries ?? []), ...budgetEntries];
|
|
405
|
+
const hasToolTurn = event.toolResults.length > 0 || (event.message.role === "assistant" && event.message.stopReason === "toolUse");
|
|
322
406
|
const decision = reduceResetControl(control, {
|
|
323
407
|
type: "turn_end",
|
|
324
408
|
facts: {
|
|
@@ -326,17 +410,19 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
326
410
|
aborted,
|
|
327
411
|
overflow: aborted ? false : isOverflowLike(event.message, ctx),
|
|
328
412
|
failed: event.outcome === "error",
|
|
329
|
-
enabled: options.isEnabled(),
|
|
413
|
+
enabled: options.isEnabled(ctx),
|
|
330
414
|
get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
|
|
331
415
|
get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
|
|
332
416
|
get hardReserveDue() { return preSendHardReserve || options.budget.hardReserveDue(ctx); },
|
|
417
|
+
get hasPendingWork() { return preSendHardReserve || hasToolTurn || event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
|
|
418
|
+
deferBetweenTurns: ctx.mode === "tui",
|
|
333
419
|
},
|
|
334
420
|
});
|
|
335
|
-
if (decision.effect === "build-boundary") return await resetBoundaryResult(entries, ctx, decision, preSendHardReserve);
|
|
421
|
+
if (decision.effect === "build-boundary") return await resetBoundaryResult(entries, ctx, decision, preSendHardReserve, turnover);
|
|
336
422
|
if (aborted) restoreCommandInputs();
|
|
337
423
|
else if (event.outcome === "error" && decision.state.request.phase === "none") restoreCommandInputs(true);
|
|
338
424
|
control = decision.state;
|
|
339
|
-
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
425
|
+
if (!aborted && event.outcome !== "error" && options.isEnabled(ctx)) {
|
|
340
426
|
const marker = buildMarkerDraft(ctx, entries);
|
|
341
427
|
if (marker) entries.push(marker);
|
|
342
428
|
}
|
|
@@ -350,7 +436,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
350
436
|
facts: {
|
|
351
437
|
windowId: currentWindowId(ctx),
|
|
352
438
|
get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
|
|
353
|
-
get enabled() { return options.isEnabled(); },
|
|
439
|
+
get enabled() { return options.isEnabled(ctx); },
|
|
354
440
|
get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
|
|
355
441
|
aborted: event.outcome === "aborted" || ctx.signal?.aborted === true,
|
|
356
442
|
failed: event.outcome === "error",
|
|
@@ -366,8 +452,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
366
452
|
pi.on("session_before_compact", (event, ctx) => {
|
|
367
453
|
if (!sessionActive) return undefined;
|
|
368
454
|
if (event.signal.aborted) return { cancel: true };
|
|
369
|
-
|
|
370
|
-
if (options.isEnabled() || markerExists) {
|
|
455
|
+
if (options.isEnabled(ctx)) {
|
|
371
456
|
if (event.reason === "manual") {
|
|
372
457
|
ctx.ui.notify("🥣 No compacting brains here · use /fresh-window", "warning");
|
|
373
458
|
}
|
|
@@ -377,18 +462,26 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
377
462
|
});
|
|
378
463
|
|
|
379
464
|
pi.on("agent_end", (_event, ctx) => {
|
|
380
|
-
if (ctx.signal?.aborted && !pendingPreSendTrigger) clear();
|
|
465
|
+
if (ctx.signal?.aborted && !pendingPreSendTrigger && pendingUserReplays.length === 0) clear();
|
|
381
466
|
});
|
|
382
467
|
pi.on("agent_settled", () => {
|
|
383
468
|
const trigger = pendingPreSendTrigger;
|
|
469
|
+
const replays = pendingUserReplays;
|
|
384
470
|
clear();
|
|
385
|
-
if (
|
|
471
|
+
if (replays.length > 0) {
|
|
472
|
+
for (let i = 0; i < replays.length; i++) {
|
|
473
|
+
pi.sendUserMessage(replays[i]!, {
|
|
474
|
+
...(i > 0 ? { deliverAs: "followUp" } : {}),
|
|
475
|
+
expandPromptTemplates: true,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
} else if (trigger) {
|
|
386
479
|
pi.sendMessage(trigger, { triggerTurn: true });
|
|
387
480
|
}
|
|
388
481
|
});
|
|
389
|
-
pi.on("session_start", () => { clear(false); sessionActive = true; });
|
|
390
|
-
pi.on("session_tree", () => { clear(false); });
|
|
391
|
-
pi.on("session_shutdown", () => { clear(false); options.budget.clear(); sessionActive = false; });
|
|
482
|
+
pi.on("session_start", () => { failedTurnoverWindowId = undefined; clear(false); sessionActive = true; });
|
|
483
|
+
pi.on("session_tree", () => { failedTurnoverWindowId = undefined; clear(false); });
|
|
484
|
+
pi.on("session_shutdown", () => { failedTurnoverWindowId = undefined; clear(false); options.budget.clear(); sessionActive = false; });
|
|
392
485
|
|
|
393
486
|
return {
|
|
394
487
|
command(windowId: string, continueAfterReset: boolean, input?: CarriedInput) {
|
|
@@ -401,7 +494,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
401
494
|
control = decision.state;
|
|
402
495
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
403
496
|
},
|
|
404
|
-
hasPendingTrigger: () => pendingPreSendTrigger !== undefined,
|
|
497
|
+
hasPendingTrigger: () => pendingPreSendTrigger !== undefined || pendingUserReplays.length > 0,
|
|
405
498
|
clear,
|
|
406
499
|
};
|
|
407
500
|
}
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
3
4
|
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
4
5
|
import { Type } from "typebox";
|
|
@@ -6,18 +7,19 @@ import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, t
|
|
|
6
7
|
import { registerBudget } from "./budget.js";
|
|
7
8
|
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
|
|
8
9
|
import { emptyBrainRenderers } from "./render.js";
|
|
9
|
-
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow,
|
|
10
|
+
import { activeBranchTail, currentReset, currentWindowId, isCheckpointBackedReset, isNotesoupEnabled, isNotesoupSkillPath, isWindowBoot, isWindowBootEntry, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, stripNotesoupProjection, type WindowMarker } from "./window.js";
|
|
10
11
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
11
12
|
import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
12
|
-
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
13
|
+
import { BOOT_TYPE, ENABLED_TYPE, MANUAL_WIPE_TYPE, TURNOVER_TRIGGER_TYPE } from "./entries.js";
|
|
13
14
|
import { commandWarningContent, PI_PRE_RESET_HINTS } from "./text.js";
|
|
14
15
|
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../src/boot/text.js";
|
|
15
16
|
import { agentSlug } from "./notes/adapter.js";
|
|
16
|
-
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
|
|
17
|
+
import { buildBootMessage, sendBoot, type BootMessage, type IncompleteNotesNotifier } from "./boot.js";
|
|
17
18
|
import { maybeSendMarker } from "./marker.js";
|
|
18
19
|
import { nextHistorySeq } from "./history.js";
|
|
19
20
|
import { errorMessage } from "../../src/error-message.js";
|
|
20
21
|
import { parseContextCap } from "../../src/budget/cap.js";
|
|
22
|
+
import type { SessionReader } from "./session-reader.js";
|
|
21
23
|
|
|
22
24
|
function readPackageVersion(): string {
|
|
23
25
|
for (const up of ["../../package.json", "../../../package.json"]) {
|
|
@@ -37,36 +39,26 @@ function branchHasWindowMarker(ctx: ExtensionContext, fromId?: string): boolean
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
+
* Resolve notesoup's own `skills/` directory in both layouts: direct TypeScript source
|
|
43
|
+
* (`plugins/pi/runtime.ts`) and the compiled package (`dist/plugins/pi/runtime.js`).
|
|
42
44
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const reset = currentReset(ctx);
|
|
51
|
-
const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
|
|
52
|
-
const stillCurrent = () => isCurrent() &&
|
|
53
|
-
ctx.signal?.aborted !== true &&
|
|
54
|
-
ctx.sessionManager.getSessionId() === sessionId &&
|
|
55
|
-
currentWindowId(ctx) === windowId;
|
|
56
|
-
if (reset) {
|
|
57
|
-
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
58
|
-
return;
|
|
45
|
+
function resolveNotesoupSkillDirs(): string[] {
|
|
46
|
+
const dirs = new Set<string>();
|
|
47
|
+
for (const candidate of ["../../skills", "../../../skills"]) {
|
|
48
|
+
try {
|
|
49
|
+
const path = fileURLToPath(new URL(candidate, import.meta.url));
|
|
50
|
+
if (existsSync(path)) dirs.add(realpathSync(path));
|
|
51
|
+
} catch { /* not a source or compiled layout */ }
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
62
|
-
if (!stillCurrent()) return;
|
|
63
|
-
if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId))) return;
|
|
64
|
-
sendBoot(pi, boot);
|
|
53
|
+
return [...dirs];
|
|
65
54
|
}
|
|
66
55
|
|
|
56
|
+
const notesoupSkillDirs = resolveNotesoupSkillDirs();
|
|
57
|
+
|
|
67
58
|
/** Register the context-window runtime and its context-owned commands/tools. */
|
|
68
59
|
export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
|
|
69
|
-
|
|
60
|
+
pi.registerFlag("no-notesoup", { description: "Start with notesoup off (/notesoup on overrides)", type: "boolean", default: false });
|
|
61
|
+
const isEnabled = (ctx: SessionReader) => isNotesoupEnabled(pi, ctx);
|
|
70
62
|
let lifecycleGeneration = 0;
|
|
71
63
|
let missingBootNotice: string | undefined;
|
|
72
64
|
const incompleteNotesNotified = new Set<string>();
|
|
@@ -81,13 +73,49 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
81
73
|
const marker = branch.find((entry): entry is WindowMarker => isWindowMarker(entry) && entry.data.windowId === windowId);
|
|
82
74
|
if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId)) continue;
|
|
83
75
|
pendingResetNotices.delete(windowId);
|
|
84
|
-
if (markerResetOrigin(marker) === "forced") ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
76
|
+
if (markerResetOrigin(marker) === "forced" && !marker.data.betweenTurns) ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
85
77
|
}
|
|
86
78
|
};
|
|
87
|
-
|
|
79
|
+
/** Complete a reset tail that a previous process left half-written. */
|
|
80
|
+
const ensureResetRepair = async (ctx: ExtensionContext, isCurrent: () => boolean): Promise<void> => {
|
|
81
|
+
const reset = currentReset(ctx);
|
|
82
|
+
if (!reset) return;
|
|
83
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
84
|
+
const windowId = reset.data.windowId;
|
|
85
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
86
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
87
|
+
await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
|
|
88
|
+
};
|
|
89
|
+
/** Root windows (or windows after a native compaction while off) boot lazily before the first provider-facing turn. */
|
|
90
|
+
const buildLazyBoot = async (ctx: ExtensionContext, isCurrent: () => boolean): Promise<BootMessage | undefined> => {
|
|
91
|
+
if (currentReset(ctx)) return undefined;
|
|
92
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
93
|
+
const windowId = currentWindowId(ctx);
|
|
94
|
+
const hasBoot = () =>
|
|
95
|
+
activeBranchTail(ctx.sessionManager.getBranch()).some((entry) => isWindowBootEntry(entry, windowId)) ||
|
|
96
|
+
ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId));
|
|
97
|
+
if (hasBoot()) return undefined;
|
|
98
|
+
const stillCurrent = () => isCurrent() && ctx.signal?.aborted !== true &&
|
|
99
|
+
ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId && !currentReset(ctx);
|
|
100
|
+
const boot = await buildBootMessage(ctx, windowId, nextHistorySeq(ctx), notifyIncompleteNotes, stillCurrent);
|
|
101
|
+
if (!stillCurrent() || hasBoot()) return undefined;
|
|
102
|
+
return boot;
|
|
103
|
+
};
|
|
104
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
105
|
+
if (!isEnabled(ctx)) {
|
|
106
|
+
event.systemPromptOptions.skills = event.systemPromptOptions.skills.filter((skill) =>
|
|
107
|
+
!isNotesoupSkillPath(skill.filePath, notesoupSkillDirs));
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
88
110
|
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
89
111
|
event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
|
|
90
|
-
|
|
112
|
+
maybeSendMarker(pi, ctx);
|
|
113
|
+
if (!currentReset(ctx) && !(event.messageType === "custom" && (event.message.customType === MANUAL_WIPE_TYPE || event.message.customType === TURNOVER_TRIGGER_TYPE))) {
|
|
114
|
+
const generation = lifecycleGeneration;
|
|
115
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
116
|
+
if (boot) return { message: boot };
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
91
119
|
});
|
|
92
120
|
pi.on("turn_start", (_event, ctx) => {
|
|
93
121
|
notifyCommittedResets(ctx);
|
|
@@ -102,20 +130,19 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
102
130
|
const namespaces = snapshot.unavailable.map((namespace) => namespace.label).join(", ");
|
|
103
131
|
ctx.ui.notify(`🥣 Some notes went missing: ${namespaces}`, "warning");
|
|
104
132
|
};
|
|
105
|
-
const budget = registerBudget(pi, () =>
|
|
133
|
+
const budget = registerBudget(pi, (ctx) => isEnabled(ctx), settingsManager);
|
|
106
134
|
|
|
107
135
|
pi.on("session_start", async (_event, ctx) => {
|
|
108
136
|
const generation = ++lifecycleGeneration;
|
|
109
|
-
if (!enabled) return;
|
|
110
137
|
missingBootNotice = undefined;
|
|
111
138
|
pendingResetNotices.clear();
|
|
112
|
-
await
|
|
139
|
+
if (isEnabled(ctx)) await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
113
140
|
});
|
|
114
141
|
pi.on("session_tree", async (_event, ctx) => {
|
|
115
142
|
const generation = ++lifecycleGeneration;
|
|
116
143
|
missingBootNotice = undefined;
|
|
117
144
|
pendingResetNotices.clear();
|
|
118
|
-
if (
|
|
145
|
+
if (isEnabled(ctx)) await ensureResetRepair(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
119
146
|
});
|
|
120
147
|
pi.on("session_shutdown", () => {
|
|
121
148
|
lifecycleGeneration++;
|
|
@@ -135,12 +162,10 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
135
162
|
// root windows only refresh a forked boot identity and retain the copied root transcript.
|
|
136
163
|
pi.on("context_with_system", (event, ctx) => {
|
|
137
164
|
const reset = currentReset(ctx);
|
|
138
|
-
const windowId =
|
|
165
|
+
const windowId = currentWindowId(ctx);
|
|
139
166
|
try {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
return { messages: projectRootWindow(event.messages, windowId) };
|
|
167
|
+
const projected = reset ? projectWindow(event.messages, windowId) : projectRootWindow(event.messages, windowId);
|
|
168
|
+
return { messages: isEnabled(ctx) ? projected : stripNotesoupProjection(projected, notesoupSkillDirs) };
|
|
144
169
|
} catch (error) {
|
|
145
170
|
if (missingBootNotice !== windowId) {
|
|
146
171
|
missingBootNotice = windowId;
|
|
@@ -155,7 +180,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
155
180
|
pi.registerCommand("notesoup", {
|
|
156
181
|
description: "Show notesoup status, toggle context windows, or cap their capacity",
|
|
157
182
|
getArgumentCompletions: (prefix) =>
|
|
158
|
-
["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
183
|
+
["on", "off", "reset", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
159
184
|
handler: async (args, cmdCtx) => {
|
|
160
185
|
const arg = args.trim().toLowerCase();
|
|
161
186
|
const parts = arg.split(/\s+/);
|
|
@@ -169,38 +194,39 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
169
194
|
const error = budget.setCap(value ?? undefined, cmdCtx);
|
|
170
195
|
if (error) { cmdCtx.ui.notify(`🥣 ${error}`, "error"); return; }
|
|
171
196
|
}
|
|
172
|
-
} else if (arg === "on") {
|
|
173
|
-
enabled
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
} else if (arg === "on" || arg === "off" || arg === "reset") {
|
|
198
|
+
pi.appendEntry(ENABLED_TYPE, { version: 1, enabled: arg === "reset" ? null : arg === "on" });
|
|
199
|
+
if (isEnabled(cmdCtx)) {
|
|
200
|
+
const generation = ++lifecycleGeneration;
|
|
201
|
+
await ensureResetRepair(cmdCtx, () => generation === lifecycleGeneration && isEnabled(cmdCtx));
|
|
202
|
+
} else {
|
|
203
|
+
lifecycleGeneration++;
|
|
204
|
+
pendingResetNotices.clear();
|
|
205
|
+
incompleteNotesNotified.clear();
|
|
206
|
+
missingBootNotice = undefined;
|
|
207
|
+
budget.clear();
|
|
208
|
+
resets.clear();
|
|
209
|
+
}
|
|
184
210
|
} else if (arg !== "") {
|
|
185
|
-
cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
|
|
211
|
+
cmdCtx.ui.notify("Usage: /notesoup [on|off|reset|cap [100k|1m|tokens|off]]", "error");
|
|
186
212
|
return;
|
|
187
213
|
}
|
|
188
214
|
const { remaining, cap } = budget.statusFor(cmdCtx);
|
|
189
|
-
cmdCtx.ui.notify(`🥣 notesoup ${
|
|
215
|
+
cmdCtx.ui.notify(`🥣 notesoup ${isEnabled(cmdCtx) ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
190
216
|
},
|
|
191
217
|
});
|
|
192
218
|
|
|
193
219
|
const emptyBrainCommand = (name: "empty" | "fresh-window") => ({
|
|
194
220
|
description: "Flush memory to notes, reset, and stop; optional text provides close-out context",
|
|
195
221
|
handler: async (args: string, cmdCtx: ExtensionCommandContext) => {
|
|
196
|
-
if (!
|
|
222
|
+
if (!isEnabled(cmdCtx)) {
|
|
197
223
|
cmdCtx.ui.notify("🥣 notesoup is off · no brain to empty", "error");
|
|
198
224
|
return;
|
|
199
225
|
}
|
|
200
226
|
const requestedWindowId = currentWindowId(cmdCtx);
|
|
201
227
|
if (!cmdCtx.isIdle() && !cmdCtx.signal) {
|
|
202
228
|
await cmdCtx.waitForIdle();
|
|
203
|
-
if (!
|
|
229
|
+
if (!isEnabled(cmdCtx) || currentWindowId(cmdCtx) !== requestedWindowId) return;
|
|
204
230
|
}
|
|
205
231
|
// Manual wipes close out at settlement, then stop unless later human input arrives. The hidden warning is triggered when idle,
|
|
206
232
|
// steered into the running turn when busy — so the agent closes out promptly
|
|
@@ -228,13 +254,13 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
228
254
|
label: "Empty Brain",
|
|
229
255
|
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
|
|
230
256
|
parameters: Type.Object({
|
|
231
|
-
last_word: Type.Optional(Type.String({ description: `A tiny sticky note
|
|
232
|
-
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe.
|
|
257
|
+
last_word: Type.Optional(Type.String({ description: `A tiny sticky note (at most ${LAST_WORD_ADVERTISED_CHARS} characters), slapped on your forehead after the wipe.` })),
|
|
258
|
+
terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe." })),
|
|
233
259
|
}, { additionalProperties: false }),
|
|
234
260
|
renderCall: emptyBrainRenderers.renderCall,
|
|
235
261
|
renderResult: emptyBrainRenderers.renderResult,
|
|
236
262
|
async execute(_id, params, _signal, _update, ctx) {
|
|
237
|
-
if (!
|
|
263
|
+
if (!isEnabled(ctx)) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
238
264
|
const lastWord = sanitizeLastWord(params.last_word);
|
|
239
265
|
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
240
266
|
if (length > MAX_LAST_WORD_CHARS) return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
|
|
@@ -243,8 +269,8 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
243
269
|
}));
|
|
244
270
|
|
|
245
271
|
const resets = registerResetLifecycle(pi, {
|
|
246
|
-
isEnabled: () =>
|
|
247
|
-
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin),
|
|
272
|
+
isEnabled: (ctx) => isEnabled(ctx),
|
|
273
|
+
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin, betweenTurns) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin, betweenTurns),
|
|
248
274
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
249
275
|
onResetReady: (_ctx, drafts) => {
|
|
250
276
|
const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);
|
|
@@ -255,4 +281,14 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
255
281
|
},
|
|
256
282
|
budget,
|
|
257
283
|
});
|
|
284
|
+
|
|
285
|
+
// Registered after the reset lifecycle so a reset that swallows this input (`handled`)
|
|
286
|
+
// never gets a root boot for a turn that will not run.
|
|
287
|
+
pi.on("input", async (event, ctx) => {
|
|
288
|
+
if (!ctx.isIdle() || event.streamingBehavior || !isEnabled(ctx) || currentReset(ctx)) return undefined;
|
|
289
|
+
const generation = lifecycleGeneration;
|
|
290
|
+
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
291
|
+
if (boot) sendBoot(pi, boot);
|
|
292
|
+
return undefined;
|
|
293
|
+
});
|
|
258
294
|
}
|
|
@@ -4,7 +4,7 @@ import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
|
4
4
|
import type { JsonValue } from "@earendil-works/pi-ai";
|
|
5
5
|
import type { Static, TSchema } from "typebox";
|
|
6
6
|
import type { Outcome } from "../../src/result.js";
|
|
7
|
-
import { wireResult, type Operation
|
|
7
|
+
import { wireResult, type Operation } from "../../src/tools/result.js";
|
|
8
8
|
|
|
9
9
|
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
10
10
|
export function output(value: unknown, details?: unknown, terminate = false) {
|
|
@@ -14,19 +14,19 @@ export function output(value: unknown, details?: unknown, terminate = false) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
17
|
-
function piOperationResult<TData, TDetails = undefined>(
|
|
17
|
+
function piOperationResult<TData, TDetails = undefined>(operation: Pick<Operation<TSchema, TData, []>, "render" | "outputSchema">, outcome: Outcome<TData>, details?: TDetails): AgentToolResult<TDetails> {
|
|
18
18
|
return {
|
|
19
|
-
content: [{ type: "text", text: render(outcome) }],
|
|
20
|
-
structuredContent: wireResult(outcome) as unknown as JsonValue,
|
|
19
|
+
content: [{ type: "text", text: operation.render(outcome) }],
|
|
20
|
+
...(operation.outputSchema !== undefined ? { structuredContent: wireResult(outcome) as unknown as JsonValue } : {}),
|
|
21
21
|
isError: !outcome.ok,
|
|
22
22
|
details: details as TDetails,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export type ToolNamespace = { name: string; description: string };
|
|
27
|
-
export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the
|
|
27
|
+
export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the notesoup-guide skill." };
|
|
28
28
|
export const DREAM_NAMESPACE: ToolNamespace = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
|
|
29
|
-
export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "Session history (this or other local sessions): history_list to browse
|
|
29
|
+
export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "Session history (this or other local sessions): history_list to browse a timeline or list sessions, history_search to find passages, history_read to read one event." };
|
|
30
30
|
|
|
31
31
|
/** Optional TUI renderers; without them the host draws its default call line and receipt text. */
|
|
32
32
|
export type OperationRenderers<TParams extends TSchema, TDetails = undefined> = Pick<ToolDefinition<TParams, TDetails>, "renderCall" | "renderResult">;
|
|
@@ -45,14 +45,14 @@ export function registerOperation<TParams extends TSchema, TData, TRest extends
|
|
|
45
45
|
label: operation.label,
|
|
46
46
|
description: operation.description,
|
|
47
47
|
parameters: operation.parameters,
|
|
48
|
-
outputSchema: operation.outputSchema,
|
|
48
|
+
...(operation.outputSchema ? { outputSchema: operation.outputSchema } : {}),
|
|
49
49
|
executionMode: operation.executionMode,
|
|
50
50
|
...(namespace ? { namespace } : {}),
|
|
51
51
|
...(exposure ? { exposure } : {}),
|
|
52
52
|
...renderers,
|
|
53
53
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
54
54
|
const result = await run(params, ctx);
|
|
55
|
-
return piOperationResult(operation
|
|
55
|
+
return piOperationResult(operation, result, result.details);
|
|
56
56
|
},
|
|
57
57
|
}));
|
|
58
58
|
}
|