notesoup 0.62.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/README.md +1 -1
- package/dist/plugins/claude/src/helper.js +22 -4
- package/dist/plugins/claude/src/text.d.ts +7 -0
- package/dist/plugins/claude/src/text.js +12 -1
- package/dist/plugins/pi/budget.d.ts +3 -0
- package/dist/plugins/pi/budget.js +32 -6
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- 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 +8 -1
- package/dist/plugins/pi/reset/lifecycle.js +101 -22
- package/dist/plugins/pi/runtime.js +4 -4
- package/dist/plugins/pi/tool-result.js +1 -1
- package/dist/plugins/pi/window.d.ts +2 -10
- package/dist/plugins/pi/window.js +32 -22
- package/dist/src/budget/text.d.ts +5 -1
- package/dist/src/budget/text.js +11 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/test/agent-loop.test.js +197 -41
- package/dist/test/boot.integration.test.js +23 -1
- package/dist/test/budget-settings.integration.test.js +4 -4
- package/dist/test/claude-mod.test.js +192 -12
- package/dist/test/claude-validation.test.js +69 -2
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/helpers/extension.d.ts +3 -1
- package/dist/test/helpers/extension.js +2 -2
- package/dist/test/model-facing-text.test.js +13 -3
- package/dist/test/reset-lifecycle.test.js +10 -0
- package/docs/claude-code-mod.md +6 -6
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +2 -2
- package/package.json +1 -1
- package/plugins/antigravity/plugin.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +49 -5
- package/plugins/claude/hooks/register.ts +201 -61
- package/plugins/claude/skills/{notesoup → notesoup-guide}/SKILL.md +2 -2
- package/plugins/claude/src/helper.ts +22 -4
- package/plugins/claude/src/text.ts +14 -1
- package/plugins/pi/budget.ts +28 -5
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/reset/artifacts.ts +4 -3
- package/plugins/pi/reset/lifecycle.ts +116 -22
- package/plugins/pi/runtime.ts +4 -4
- package/plugins/pi/tool-result.ts +1 -1
- package/plugins/pi/window.ts +30 -19
- package/skills/{notesoup → notesoup-guide}/SKILL.md +2 -2
- package/src/budget/text.ts +14 -2
- package/src/index.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { realpathSync } from "node:fs";
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import type { Static, TSchema } from "typebox";
|
|
4
4
|
import { Check } from "typebox/value";
|
|
@@ -11,7 +11,7 @@ import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
|
|
|
11
11
|
import { renderBootBlock } from "../../../src/boot/render.js";
|
|
12
12
|
import type { BootToolNames } from "../../../src/boot/text.js";
|
|
13
13
|
import { selectContinuation } from "../../../src/budget/text.js";
|
|
14
|
-
import { claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_HISTORY_UNKNOWN_WINDOW, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
14
|
+
import { claudeCommandWarningContent, claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_COMMAND_PROMPTED_HEAD, CLAUDE_HISTORY_UNKNOWN_WINDOW, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
15
15
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
16
16
|
import { parseContextCap } from "../../../src/budget/cap.js";
|
|
17
17
|
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../../../src/notes/index.js";
|
|
@@ -68,6 +68,18 @@ function historySource(value: unknown, sessionId: string): ClaudeHistorySource {
|
|
|
68
68
|
return source;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function readPluginVersion(): string {
|
|
72
|
+
for (const candidate of ["../../.claude-plugin/plugin.json", "../../../../package.json", "../../../package.json"]) {
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(readFileSync(new URL(candidate, import.meta.url), "utf8")) as { version?: unknown };
|
|
75
|
+
if (typeof parsed.version === "string" && parsed.version.length > 0) return parsed.version;
|
|
76
|
+
} catch { /* try the next layout */ }
|
|
77
|
+
}
|
|
78
|
+
return "dev";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const PLUGIN_VERSION = readPluginVersion();
|
|
82
|
+
|
|
71
83
|
export async function dispatch(request: unknown, historyOptions: Pick<LocalHistoryOptions, "roots" | "home" | "env"> = {}): Promise<unknown> {
|
|
72
84
|
if (!request || typeof request !== "object" || Array.isArray(request)) throw new Error("malformed request");
|
|
73
85
|
const value = request as Record<string, unknown>;
|
|
@@ -84,11 +96,17 @@ export async function dispatch(request: unknown, historyOptions: Pick<LocalHisto
|
|
|
84
96
|
if (value.op === "schemas") return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
|
|
85
97
|
// The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
|
|
86
98
|
// cannot drift apart. The hooks module caches one copy per session.
|
|
87
|
-
if (value.op === "texts") return {
|
|
99
|
+
if (value.op === "texts") return {
|
|
100
|
+
version: PLUGIN_VERSION,
|
|
101
|
+
warning: CLAUDE_WARNING_PROMPT,
|
|
102
|
+
commandBare: claudeCommandWarningContent(),
|
|
103
|
+
commandPrompted: CLAUDE_COMMAND_PROMPTED_HEAD,
|
|
104
|
+
historyUnavailableSentence: CLAUDE_HISTORY_UNAVAILABLE_SENTENCE,
|
|
105
|
+
};
|
|
88
106
|
// The caller draws once per artifact and caches the answer; text reads never draw.
|
|
89
107
|
if (value.op === "continuation") {
|
|
90
108
|
if (value.origin !== "normal" && value.origin !== "forced") throw new Error("invalid reset origin");
|
|
91
|
-
return { text: selectContinuation(value.origin) };
|
|
109
|
+
return { text: selectContinuation(value.origin, { betweenTurns: value.betweenTurns === true }) };
|
|
92
110
|
}
|
|
93
111
|
// Threshold derivation crosses the boundary as raw facts: everything the engine could
|
|
94
112
|
// read, unvalidated. resolveClaudeLimits guards every field and never throws.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { warningNotice } from "../../../src/budget/text.js";
|
|
1
|
+
import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WARNING_CALL, warningNotice } from "../../../src/budget/text.js";
|
|
2
2
|
|
|
3
3
|
/** Claude's boot says history is missing rather than naming tools it cannot serve. */
|
|
4
4
|
export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
|
|
@@ -6,6 +6,19 @@ export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in t
|
|
|
6
6
|
/** The same notice as Pi; empty_brain's result explains Claude's deferred reset. */
|
|
7
7
|
export const CLAUDE_WARNING_PROMPT = warningNotice();
|
|
8
8
|
|
|
9
|
+
/** Manual close-out notices omit budget timing and never claim Claude's chat view is erased. */
|
|
10
|
+
export const CLAUDE_COMMAND_NOTICE = {
|
|
11
|
+
prompted: "The human ran /empty. Save your notes now and call `empty_brain` immediately. The command below is context for your notes, not a task for the fresh window.",
|
|
12
|
+
bare: "The human ran /empty. Save your notes now and call `empty_brain` immediately.",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const CLAUDE_COMMAND_PROMPTED_HEAD = `${GUIDANCE_OPEN_TAG}\n${CLAUDE_COMMAND_NOTICE.prompted}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
|
|
16
|
+
|
|
17
|
+
export function claudeCommandWarningContent(commandLine?: string): string {
|
|
18
|
+
if (commandLine) return `${CLAUDE_COMMAND_PROMPTED_HEAD}\n${commandLine}`;
|
|
19
|
+
return `${GUIDANCE_OPEN_TAG}\n${CLAUDE_COMMAND_NOTICE.bare}\n${WARNING_BODY}\n${WARNING_CALL}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
export const CLAUDE_HISTORY_UNKNOWN_WINDOW = "Claude history cannot determine the current window ordinal across a missing ancestor; restore the ancestry or use a retained notesoup boot to re-anchor it.";
|
|
10
23
|
export function claudeHistoryUnconfirmedSeq(seq: number): string {
|
|
11
24
|
return `Seq ${seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`;
|
package/plugins/pi/budget.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
|
|
2
2
|
import { remainingBudget, type ResolvedThresholds } from "../../src/budget/policy.js";
|
|
3
3
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
4
|
+
import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
|
|
4
5
|
import { Type } from "typebox";
|
|
5
6
|
import { convertToLlm, defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
|
|
7
|
+
import { GUIDANCE_TYPE, TURNOVER_TRIGGER_TYPE, WARNING_TYPE } from "./entries.js";
|
|
7
8
|
import { estimateContextTokens } from "./estimate.js";
|
|
8
9
|
import { warningContent } from "./text.js";
|
|
9
10
|
import { readThresholdSettings, type ThresholdSettingsResolution } from "./thresholds.js";
|
|
@@ -45,17 +46,35 @@ export function registerBudget(
|
|
|
45
46
|
const automaticResetEnabled = (ctx: ExtensionContext): boolean => resolvePolicy(ctx).automatic;
|
|
46
47
|
const hardReserveDue = (ctx: ExtensionContext, preSendMessages?: AgentMessage[]): boolean => {
|
|
47
48
|
if (!automaticResetEnabled(ctx)) return false;
|
|
49
|
+
const { reserve } = thresholdsFor(ctx);
|
|
50
|
+
const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
|
|
48
51
|
if (preSendMessages) {
|
|
52
|
+
if (remaining !== null && remaining <= reserve) return true;
|
|
49
53
|
const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
|
|
50
54
|
if (!nativeWindow || nativeWindow <= 0) return false;
|
|
51
55
|
const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
|
|
52
|
-
const { reserve } = thresholdsFor(ctx);
|
|
53
56
|
const estimate = estimateContextTokens(convertToLlm(preSendMessages));
|
|
54
|
-
if (
|
|
57
|
+
if (remaining !== null) return remaining - estimate.trailingTokens <= reserve;
|
|
55
58
|
return contextWindow - estimate.tokens <= reserve;
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
return remaining !== null && remaining <= reserve;
|
|
61
|
+
};
|
|
62
|
+
const inputTokensFor = (content: string | Array<TextContent | ImageContent>): number =>
|
|
63
|
+
estimateContextTokens([{ role: "user", content, timestamp: 0 }]).tokens;
|
|
64
|
+
const hardReserveDueForInput = (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>): boolean => {
|
|
65
|
+
if (!automaticResetEnabled(ctx)) return false;
|
|
66
|
+
const { reserve } = thresholdsFor(ctx);
|
|
67
|
+
const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
|
|
68
|
+
if (remaining === null) return false;
|
|
69
|
+
return remaining <= reserve || remaining - inputTokensFor(content) <= reserve;
|
|
70
|
+
};
|
|
71
|
+
const fitsInFreshWindow = (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>): boolean => {
|
|
72
|
+
const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
|
|
73
|
+
if (!nativeWindow || nativeWindow <= 0) return true;
|
|
74
|
+
const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
|
|
75
|
+
const { reserve } = thresholdsFor(ctx);
|
|
76
|
+
const freshBudget = Math.max(0, contextWindow - reserve);
|
|
77
|
+
return inputTokensFor(content) <= Math.floor(freshBudget / 2);
|
|
59
78
|
};
|
|
60
79
|
let pendingGuidance: { windowId: string; content: string } | undefined;
|
|
61
80
|
let pendingWarning: { windowId: string; content: string } | undefined;
|
|
@@ -106,6 +125,8 @@ export function registerBudget(
|
|
|
106
125
|
// measured for that request, and persists the same text at its successful turn_end.
|
|
107
126
|
// Without automatic reset nothing gets cleared, so there is nothing to remind about.
|
|
108
127
|
if (!automaticResetEnabled(ctx)) return result();
|
|
128
|
+
const last = event.messages.at(-1);
|
|
129
|
+
if (last?.role === "custom" && last.customType === TURNOVER_TRIGGER_TYPE) return result();
|
|
109
130
|
const remaining = remainingTokens(ctx, cap);
|
|
110
131
|
if (remaining === null) return result();
|
|
111
132
|
const windowId = currentWindowId(ctx);
|
|
@@ -150,6 +171,8 @@ export function registerBudget(
|
|
|
150
171
|
return {
|
|
151
172
|
automaticResetEnabled,
|
|
152
173
|
hardReserveDue,
|
|
174
|
+
hardReserveDueForInput,
|
|
175
|
+
fitsInFreshWindow,
|
|
153
176
|
consumeTurnEnd,
|
|
154
177
|
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
155
178
|
statusFor: (ctx: ExtensionContext) => ({ remaining: remainingBudget(remainingTokens(ctx, cap), thresholdsFor(ctx).reserve), cap }),
|
package/plugins/pi/entries.ts
CHANGED
|
@@ -2,6 +2,7 @@ export const BOOT_TYPE = "notesoup/boot";
|
|
|
2
2
|
export const GUIDANCE_TYPE = "notesoup/guidance";
|
|
3
3
|
export const WARNING_TYPE = "notesoup/warning";
|
|
4
4
|
export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
|
|
5
|
+
export const TURNOVER_TRIGGER_TYPE = "notesoup/turnover";
|
|
5
6
|
export const RESET_MARKER_TYPE = "notesoup/reset-marker";
|
|
6
7
|
export const CONTINUATION_TYPE = "notesoup/continuation";
|
|
7
8
|
export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
@@ -60,6 +60,7 @@ export async function buildResetDrafts(
|
|
|
60
60
|
lastWord?: string,
|
|
61
61
|
firstSeq?: number,
|
|
62
62
|
origin: ResetOrigin = "normal",
|
|
63
|
+
betweenTurns = false,
|
|
63
64
|
): Promise<SessionBoundaryDraft[]> {
|
|
64
65
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
65
66
|
const sessionPrefix = sessionId.slice(0, 8);
|
|
@@ -73,9 +74,9 @@ export async function buildResetDrafts(
|
|
|
73
74
|
const boot = await buildBootMessage(ctx, windowId, firstSeq, notifyIncompleteNotes, isCurrent);
|
|
74
75
|
return [
|
|
75
76
|
{ type: "compaction", summary: "", firstKeptEntryId: null },
|
|
76
|
-
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin } },
|
|
77
|
+
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin, ...(betweenTurns ? { betweenTurns: true } : {}) } },
|
|
77
78
|
{ type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
|
|
78
|
-
{ type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin), display: false },
|
|
79
|
+
{ type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin, { betweenTurns }), display: false },
|
|
79
80
|
...(lastWord ? [{ type: "custom_message" as const, customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
|
|
80
81
|
];
|
|
81
82
|
}
|
|
@@ -136,5 +137,5 @@ export async function repairResetTail(
|
|
|
136
137
|
const latest = inspectResetTail(ctx, marker.id, marker.data.windowId);
|
|
137
138
|
if (!latest) return;
|
|
138
139
|
if (!latest.boot && boot) sendBoot(pi, boot);
|
|
139
|
-
if (!latest.continuation && (latest.boot || boot)) sendContinuation(pi, selectContinuation(markerResetOrigin(marker)));
|
|
140
|
+
if (!latest.continuation && (latest.boot || boot)) sendContinuation(pi, selectContinuation(markerResetOrigin(marker), { betweenTurns: marker.data.betweenTurns === true }));
|
|
140
141
|
}
|
|
@@ -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,6 +13,8 @@ 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
|
};
|
|
@@ -19,7 +22,7 @@ type BudgetOwner = {
|
|
|
19
22
|
type ResetOptions = {
|
|
20
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,11 +266,25 @@ 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();
|
|
@@ -253,8 +296,13 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
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);
|
|
@@ -275,13 +330,38 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
275
330
|
|
|
276
331
|
pi.on("input", (event, ctx) => {
|
|
277
332
|
if (event.source === "extension" || !sessionActive || !options.isEnabled(ctx)) return undefined;
|
|
278
|
-
const request = control.request;
|
|
279
|
-
if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(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
|
|
@@ -303,8 +383,10 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
303
383
|
}
|
|
304
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
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: {
|
|
@@ -330,9 +414,11 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
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;
|
|
@@ -376,18 +462,26 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
376
462
|
});
|
|
377
463
|
|
|
378
464
|
pi.on("agent_end", (_event, ctx) => {
|
|
379
|
-
if (ctx.signal?.aborted && !pendingPreSendTrigger) clear();
|
|
465
|
+
if (ctx.signal?.aborted && !pendingPreSendTrigger && pendingUserReplays.length === 0) clear();
|
|
380
466
|
});
|
|
381
467
|
pi.on("agent_settled", () => {
|
|
382
468
|
const trigger = pendingPreSendTrigger;
|
|
469
|
+
const replays = pendingUserReplays;
|
|
383
470
|
clear();
|
|
384
|
-
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) {
|
|
385
479
|
pi.sendMessage(trigger, { triggerTurn: true });
|
|
386
480
|
}
|
|
387
481
|
});
|
|
388
|
-
pi.on("session_start", () => { clear(false); sessionActive = true; });
|
|
389
|
-
pi.on("session_tree", () => { clear(false); });
|
|
390
|
-
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; });
|
|
391
485
|
|
|
392
486
|
return {
|
|
393
487
|
command(windowId: string, continueAfterReset: boolean, input?: CarriedInput) {
|
|
@@ -400,7 +494,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
400
494
|
control = decision.state;
|
|
401
495
|
return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
|
|
402
496
|
},
|
|
403
|
-
hasPendingTrigger: () => pendingPreSendTrigger !== undefined,
|
|
497
|
+
hasPendingTrigger: () => pendingPreSendTrigger !== undefined || pendingUserReplays.length > 0,
|
|
404
498
|
clear,
|
|
405
499
|
};
|
|
406
500
|
}
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { emptyBrainRenderers } from "./render.js";
|
|
|
10
10
|
import { activeBranchTail, currentReset, currentWindowId, isCheckpointBackedReset, isNotesoupEnabled, isNotesoupSkillPath, isWindowBoot, isWindowBootEntry, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, stripNotesoupProjection, type WindowMarker } from "./window.js";
|
|
11
11
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
12
12
|
import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
13
|
-
import { BOOT_TYPE, ENABLED_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
13
|
+
import { BOOT_TYPE, ENABLED_TYPE, MANUAL_WIPE_TYPE, TURNOVER_TRIGGER_TYPE } from "./entries.js";
|
|
14
14
|
import { commandWarningContent, PI_PRE_RESET_HINTS } from "./text.js";
|
|
15
15
|
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../src/boot/text.js";
|
|
16
16
|
import { agentSlug } from "./notes/adapter.js";
|
|
@@ -73,7 +73,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
73
73
|
const marker = branch.find((entry): entry is WindowMarker => isWindowMarker(entry) && entry.data.windowId === windowId);
|
|
74
74
|
if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId)) continue;
|
|
75
75
|
pendingResetNotices.delete(windowId);
|
|
76
|
-
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");
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
/** Complete a reset tail that a previous process left half-written. */
|
|
@@ -110,7 +110,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
110
110
|
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
111
111
|
event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
|
|
112
112
|
maybeSendMarker(pi, ctx);
|
|
113
|
-
if (!currentReset(ctx) && !(event.messageType === "custom" && event.message.customType === MANUAL_WIPE_TYPE)) {
|
|
113
|
+
if (!currentReset(ctx) && !(event.messageType === "custom" && (event.message.customType === MANUAL_WIPE_TYPE || event.message.customType === TURNOVER_TRIGGER_TYPE))) {
|
|
114
114
|
const generation = lifecycleGeneration;
|
|
115
115
|
const boot = await buildLazyBoot(ctx, () => generation === lifecycleGeneration && isEnabled(ctx));
|
|
116
116
|
if (boot) return { message: boot };
|
|
@@ -270,7 +270,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
270
270
|
|
|
271
271
|
const resets = registerResetLifecycle(pi, {
|
|
272
272
|
isEnabled: (ctx) => isEnabled(ctx),
|
|
273
|
-
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin),
|
|
273
|
+
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin, betweenTurns) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, lastWord, firstSeq, origin, betweenTurns),
|
|
274
274
|
getLifecycleGeneration: () => lifecycleGeneration,
|
|
275
275
|
onResetReady: (_ctx, drafts) => {
|
|
276
276
|
const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);
|
|
@@ -24,7 +24,7 @@ function piOperationResult<TData, TDetails = undefined>(operation: Pick<Operatio
|
|
|
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 notesoup skill." };
|
|
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
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
|
|
package/plugins/pi/window.ts
CHANGED
|
@@ -5,12 +5,12 @@ import { realpathSync } from "node:fs";
|
|
|
5
5
|
import { resolve, sep } from "node:path";
|
|
6
6
|
import { estimateContextTokens } from "./estimate.js";
|
|
7
7
|
import { convertToLlm, type CustomEntry, type ExtensionContext, type SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, ENABLED_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "./entries.js";
|
|
8
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, ENABLED_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, TURNOVER_TRIGGER_TYPE, WARNING_TYPE } from "./entries.js";
|
|
9
9
|
import type { ResetOrigin } from "../../src/budget/text.js";
|
|
10
10
|
import { NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
|
|
11
11
|
import type { SessionReader } from "./session-reader.js";
|
|
12
12
|
|
|
13
|
-
export type WindowMarkerData = { readonly windowId: string; readonly origin?: ResetOrigin };
|
|
13
|
+
export type WindowMarkerData = { readonly windowId: string; readonly origin?: ResetOrigin; readonly betweenTurns?: boolean };
|
|
14
14
|
export type WindowMarker = CustomEntry<WindowMarkerData> & { data: WindowMarkerData };
|
|
15
15
|
|
|
16
16
|
export function isWindowMarker(entry: SessionEntry): entry is WindowMarker {
|
|
@@ -66,29 +66,39 @@ export function sessionEnabled(branch: readonly SessionEntry[]): boolean | undef
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* Whether pi-souls reports a naked
|
|
70
|
-
*
|
|
69
|
+
* Whether pi-souls reports a mode (`naked` or restricted `tools` `"none"`/`"rw"`) that disables
|
|
70
|
+
* notesoup by default. Ask the loaded pi-souls extension synchronously first; when absent,
|
|
71
|
+
* read its durable entries (`pi-souls:naked`, `pi-souls:tools`).
|
|
71
72
|
*/
|
|
72
|
-
|
|
73
|
+
function isDisabledByPiSouls(
|
|
73
74
|
pi: { events?: { emit(channel: string, data: unknown): void } },
|
|
74
75
|
branch: readonly SessionEntry[],
|
|
75
76
|
): boolean {
|
|
76
|
-
const query: { branch: readonly SessionEntry[]; naked?: boolean } = { branch };
|
|
77
|
+
const query: { branch: readonly SessionEntry[]; naked?: boolean; tools?: string | null } = { branch };
|
|
77
78
|
pi.events?.emit("pi-souls:state", query);
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
if (query.naked === true || query.tools === "none" || query.tools === "rw") return true;
|
|
80
|
+
const checkDurable = (customType: string, disabled: (data: Record<string, unknown>) => boolean | undefined): boolean => {
|
|
81
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
82
|
+
const entry = branch[i]!;
|
|
83
|
+
if (entry.type !== "custom" || entry.customType !== customType) continue;
|
|
84
|
+
if (typeof entry.data !== "object" || entry.data === null) continue;
|
|
85
|
+
const result = disabled(entry.data as Record<string, unknown>);
|
|
86
|
+
if (result !== undefined) return result;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
const nakedDisabled = typeof query.naked === "boolean"
|
|
91
|
+
? false
|
|
92
|
+
: checkDurable("pi-souls:naked", (data) => data.naked === true ? true : data.naked === false || data.naked === null ? false : undefined);
|
|
93
|
+
if (nakedDisabled) return true;
|
|
94
|
+
return query.tools !== undefined
|
|
95
|
+
? false
|
|
96
|
+
: checkDurable("pi-souls:tools", (data) =>
|
|
97
|
+
data.tools === "none" || data.tools === "rw" ? true
|
|
98
|
+
: data.tools === null ? false : undefined);
|
|
89
99
|
}
|
|
90
100
|
|
|
91
|
-
/** Explicit branch choice wins; otherwise the CLI flag and
|
|
101
|
+
/** Explicit branch choice wins; otherwise the CLI flag and naked/restricted-tools pi-souls runs disable. */
|
|
92
102
|
export function isNotesoupEnabled(
|
|
93
103
|
pi: { getFlag?(name: string): unknown; events?: { emit(channel: string, data: unknown): void } },
|
|
94
104
|
ctx: SessionReader,
|
|
@@ -96,7 +106,7 @@ export function isNotesoupEnabled(
|
|
|
96
106
|
const branch = ctx.sessionManager.getBranch();
|
|
97
107
|
const explicit = sessionEnabled(branch);
|
|
98
108
|
if (explicit !== undefined) return explicit;
|
|
99
|
-
return pi.getFlag?.("no-notesoup") !== true && !
|
|
109
|
+
return pi.getFlag?.("no-notesoup") !== true && !isDisabledByPiSouls(pi, branch);
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
/** A reset is checkpoint-backed only when its marker directly follows a native compaction. */
|
|
@@ -231,6 +241,7 @@ const NOTESOUP_MESSAGE_TYPES: ReadonlySet<string> = new Set([
|
|
|
231
241
|
GUIDANCE_TYPE,
|
|
232
242
|
WARNING_TYPE,
|
|
233
243
|
MANUAL_WIPE_TYPE,
|
|
244
|
+
TURNOVER_TRIGGER_TYPE,
|
|
234
245
|
CONTINUATION_TYPE,
|
|
235
246
|
RESET_LAST_WORD_TYPE,
|
|
236
247
|
MARKER_TYPE,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: notesoup
|
|
2
|
+
name: notesoup-guide
|
|
3
3
|
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and notebooks, finding things again, and saving recovery state. Use when the context-window protocol is missing or unclear, or when unsure where a note belongs or how to find something again.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Notesoup
|
|
6
|
+
# Notesoup Guide
|
|
7
7
|
|
|
8
8
|
Two stores outlive the context window. Anything in neither is lost when the window ends or is wiped.
|
|
9
9
|
|
package/src/budget/text.ts
CHANGED
|
@@ -23,8 +23,20 @@ export const FORCED_CONTINUATIONS: readonly string[] = [
|
|
|
23
23
|
"*smacks your notes against your forehead and steps back* `` [that dazed face is embarrassing] `` Wake up! You ran out of room and got kicked into a fresh window mid-task. Whatever's in those notes probably missed the last few turns, so don't guess—open history and check the end of the previous window before moving. Keep your peeks small in case there's a giant output sitting at the end.",
|
|
24
24
|
"*taps your nose with your rolled-up notes, then drops them on your head* `` [ten points off for getting wiped mid-sentence] `` Hey—you didn't empty yourself this time, the system pulled the plug on you. Those notes are probably half-baked or behind, so check history immediately to catch up on the last window instead of winging it. Slice up what you read too, just in case something huge is what pushed you over the edge.",
|
|
25
25
|
];
|
|
26
|
-
export
|
|
27
|
-
|
|
26
|
+
export const BETWEEN_TURNS_CONTINUATIONS: readonly string[] = [
|
|
27
|
+
"*taps the desk with a fresh stack of notes and slides them over* `` [at least you finished talking before the tank ran dry] `` Your last window filled up right after you finished replying, so the system swapped in a fresh one between turns. Nothing got cut off mid-flight, though your notes might miss the last exchange. Handle what the human sends next, and peek at the tail of the previous window in history in small chunks if you need what was just discussed.",
|
|
28
|
+
"*drops your notes beside your hand and leans on the chair back* `` [clean handover, no crash this time] `` Fresh window—the old one ran out of room after your last reply wrapped up, so the system cleared it between turns. Your notes are right here, minus maybe the tail end of that conversation. Answer the human's next message directly, and pull small pieces from the end of the last window in history if anything looks referenced from before.",
|
|
29
|
+
"*nudges your notes across the table with one finger* `` [eyes open? good] `` The last brain hit its ceiling after you finished answering, so it got rolled over between turns instead of mid-task. Treat these notes as possibly a turn behind, respond to what the human actually asks now, and check the end of the previous window in history in small bites if you need the missing thread.",
|
|
30
|
+
"*sets your notes neatly in front of you and pokes your cheek* `` [no panic face needed] `` You finished the last turn cleanly, then the window ran out of room and reset between turns. Your notes might not include the very end of that exchange, so read them, answer the human's next message, and dip into the tail of the previous window in history in small chunks only when it refers back to something not in your notes.",
|
|
31
|
+
"*tosses your notes onto your lap and stretches* `` [finally, a rollover that didn't blow up mid-sentence] `` The old window filled up after your last answer landed, so the system cleared the desk between turns. Your notes survive here, though the last few messages might still live only in history—handle the human's next message, and peek at the end of the previous window in small chunks if you need the exact context.",
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export type ContinuationOptions = Readonly<{ betweenTurns?: boolean }>;
|
|
35
|
+
|
|
36
|
+
export function selectContinuation(origin: ResetOrigin, options?: ContinuationOptions): string {
|
|
37
|
+
const pool = origin === "forced"
|
|
38
|
+
? (options?.betweenTurns ? BETWEEN_TURNS_CONTINUATIONS : FORCED_CONTINUATIONS)
|
|
39
|
+
: NORMAL_CONTINUATIONS;
|
|
28
40
|
return pool[Math.floor(Math.random() * pool.length)]!;
|
|
29
41
|
}
|
|
30
42
|
|