notesoup 0.48.0 → 0.48.1
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/src/boot/text.js +1 -2
- package/dist/src/budget/constants.d.ts +2 -4
- package/dist/src/budget/constants.js +2 -4
- package/dist/src/budget/policy.d.ts +2 -2
- package/dist/src/budget/policy.js +3 -3
- package/dist/src/budget/text.js +1 -1
- package/dist/src/dsh/budget.js +1 -1
- package/dist/src/dsh/tools.js +1 -1
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +7 -8
- package/dist/src/pi/runtime.js +3 -2
- package/dist/test/agent-loop.test.js +1 -1
- package/dist/test/boot.integration.test.js +9 -1
- package/dist/test/budget-settings.integration.test.js +6 -4
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/model-facing-text.test.js +1 -1
- package/docs/dsh.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/src/boot/text.ts +1 -2
- package/src/budget/constants.ts +2 -4
- package/src/budget/policy.ts +3 -3
- package/src/budget/text.ts +1 -1
- package/src/dsh/budget.ts +1 -1
- package/src/dsh/tools.ts +1 -1
- package/src/pi/budget.ts +7 -8
- package/src/pi/runtime.ts +3 -2
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ pi -e npm:notesoup
|
|
|
30
30
|
|
|
31
31
|
- **Durable context windows.** `/fresh-window` (alias `/empty-brain`) clears and stops; `/fresh-window Continue reviewing the implementation` clears and continues. The model can also request a window itself with `empty_brain`, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
|
|
32
32
|
- **A boot block at every window head.** Static once-per-window content (cache-stable) with the window identity, the recent-notes index, and a short protocol teaching the model how to recover: notes for its own bookkeeping, history tools for everything before the reset.
|
|
33
|
-
- **`get_context_remaining`** —
|
|
33
|
+
- **`get_context_remaining`** — how much room the brain has left before the hard-reserve wipe, including the warning runway.
|
|
34
34
|
- **Eight history/notes tools**, flattened from the original Codex actions:
|
|
35
35
|
|
|
36
36
|
| Codex action | Pi tool |
|
package/dist/src/boot/text.js
CHANGED
|
@@ -20,8 +20,7 @@ export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in t
|
|
|
20
20
|
* notesoup's tool names. It lives once per window in the persisted boot block;
|
|
21
21
|
* it is never re-injected, so it stays cache-stable at the head of the window.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
* stays hidden (budget/constants.ts). Keep "zero = wiped" — do not make this honest.
|
|
23
|
+
* The reported room reaches zero at the hard-reserve wipe line.
|
|
25
24
|
*/
|
|
26
25
|
const PROTOCOL_BLOCK = `${NOTES_PROTOCOL_OPEN_TAG}
|
|
27
26
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_RESERVE_TOKENS = 16384;
|
|
2
2
|
export declare const DEFAULT_REMINDER_MARGIN_TOKENS = 24576;
|
|
3
3
|
/**
|
|
4
|
-
* The runway
|
|
5
|
-
*
|
|
6
|
-
* line (reserve + WARNING_RUNWAY_TOKENS); what lies below is overdraft the model
|
|
7
|
-
* never sees — Codex's fallback buffer, relocated above the line.
|
|
4
|
+
* The runway between the final warning and the hard-reserve wipe.
|
|
5
|
+
* get_context_remaining includes this room; zero is the hard-reserve line.
|
|
8
6
|
*/
|
|
9
7
|
export declare const WARNING_RUNWAY_TOKENS = 16384;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export const DEFAULT_RESERVE_TOKENS = 16_384;
|
|
2
2
|
export const DEFAULT_REMINDER_MARGIN_TOKENS = 24_576;
|
|
3
3
|
/**
|
|
4
|
-
* The runway
|
|
5
|
-
*
|
|
6
|
-
* line (reserve + WARNING_RUNWAY_TOKENS); what lies below is overdraft the model
|
|
7
|
-
* never sees — Codex's fallback buffer, relocated above the line.
|
|
4
|
+
* The runway between the final warning and the hard-reserve wipe.
|
|
5
|
+
* get_context_remaining includes this room; zero is the hard-reserve line.
|
|
8
6
|
*/
|
|
9
7
|
export const WARNING_RUNWAY_TOKENS = 16_384;
|
|
@@ -15,5 +15,5 @@ export declare function deriveThresholds(reserveTokens: number, margins: Notesou
|
|
|
15
15
|
thresholds: ResolvedThresholds;
|
|
16
16
|
warnings: string[];
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
export declare function remainingBudget(remaining: number | null,
|
|
18
|
+
/** Room before the hard-reserve wipe; unknown usage stays unknown. */
|
|
19
|
+
export declare function remainingBudget(remaining: number | null, reserve: number): number | null;
|
|
@@ -25,7 +25,7 @@ export function deriveThresholds(reserveTokens, margins) {
|
|
|
25
25
|
}
|
|
26
26
|
return { thresholds: { reminder: reserveTokens + reminderMargin, reserve: reserveTokens, warning: reserveTokens + WARNING_RUNWAY_TOKENS }, warnings };
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
export function remainingBudget(remaining,
|
|
30
|
-
return remaining === null ? null : Math.max(0, remaining -
|
|
28
|
+
/** Room before the hard-reserve wipe; unknown usage stays unknown. */
|
|
29
|
+
export function remainingBudget(remaining, reserve) {
|
|
30
|
+
return remaining === null ? null : Math.max(0, remaining - reserve);
|
|
31
31
|
}
|
package/dist/src/budget/text.js
CHANGED
|
@@ -63,5 +63,5 @@ export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready,
|
|
|
63
63
|
* at write time; get_context_remaining remains the live source for the current figure.
|
|
64
64
|
*/
|
|
65
65
|
export function tokenBudgetGuidance(remaining, wipeTool) {
|
|
66
|
-
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens left
|
|
66
|
+
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left in your brain.\nYour notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.\nWhat lives only in this brain leaves with it.\nA decent moment to put down where you are, while you still remember why.\nReady when you are: \`${wipeTool}\`.\n${GUIDANCE_CLOSE_TAG}`;
|
|
67
67
|
}
|
package/dist/src/dsh/budget.js
CHANGED
|
@@ -30,5 +30,5 @@ export async function measureBudget(ctx, agent, config, signal) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
const remaining = Math.max(0, contextWindow - used);
|
|
33
|
-
return { used, contextWindow, reserve, resetAt, remaining, countdown: remainingBudget(remaining,
|
|
33
|
+
return { used, contextWindow, reserve, resetAt, remaining, countdown: remainingBudget(remaining, reserve), warning: thresholds.warning, reminder: thresholds.reminder };
|
|
34
34
|
}
|
package/dist/src/dsh/tools.js
CHANGED
|
@@ -98,7 +98,7 @@ export function registerTools(ctx, engine) {
|
|
|
98
98
|
}));
|
|
99
99
|
ctx.tools.register(defineTool({
|
|
100
100
|
name: "get_context_remaining",
|
|
101
|
-
description: "
|
|
101
|
+
description: "Check how much room your brain has left before it gets forcibly emptied. Returns null when unknown.",
|
|
102
102
|
parameters: {},
|
|
103
103
|
output: { schema: { type: "object", properties: { remaining_tokens: { oneOf: [{ type: "integer" }, { type: "null" }], required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: JSON.stringify(value) }] },
|
|
104
104
|
async execute(_args, exec) {
|
package/dist/src/pi/budget.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function registerBudget(pi: ExtensionAPI, isEnabled: () => boolea
|
|
|
3
3
|
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
4
4
|
hardReserveDue: (ctx: ExtensionContext) => boolean;
|
|
5
5
|
consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
|
|
6
|
-
/** The same
|
|
6
|
+
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
7
7
|
statusFor: (ctx: ExtensionContext) => {
|
|
8
8
|
remaining: number | null;
|
|
9
9
|
};
|
package/dist/src/pi/budget.js
CHANGED
|
@@ -92,7 +92,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
92
92
|
if (remaining === null)
|
|
93
93
|
return result();
|
|
94
94
|
const windowId = currentWindowId(ctx);
|
|
95
|
-
const { reminder, warning } = thresholdsFor(ctx);
|
|
95
|
+
const { reminder, warning, reserve } = thresholdsFor(ctx);
|
|
96
96
|
if (remaining <= warning) {
|
|
97
97
|
if (hasWindowMessage(ctx, WARNING_TYPE))
|
|
98
98
|
return result();
|
|
@@ -116,28 +116,27 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
116
116
|
if (pendingGuidance?.windowId !== windowId) {
|
|
117
117
|
if (remaining > reminder)
|
|
118
118
|
return result();
|
|
119
|
-
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining,
|
|
119
|
+
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, reserve) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
|
|
120
120
|
}
|
|
121
121
|
return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
|
|
122
122
|
});
|
|
123
123
|
pi.registerTool(defineTool({
|
|
124
124
|
name: "get_context_remaining",
|
|
125
125
|
label: "Get context remaining",
|
|
126
|
-
description: "
|
|
126
|
+
description: "Check how much room your brain has left before it gets forcibly emptied. Returns null when unknown.",
|
|
127
127
|
parameters: Type.Object({}, { additionalProperties: false }),
|
|
128
128
|
async execute(_id, _params, _signal, _update, ctx) {
|
|
129
|
-
//
|
|
130
|
-
// the runway below it is overdraft the model never sees. See budget/constants.ts.
|
|
129
|
+
// Report room to the hard-reserve wipe, including the warning runway.
|
|
131
130
|
const remaining = remainingTokens(ctx);
|
|
132
|
-
return output({ remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx).
|
|
131
|
+
return output({ remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx).reserve) });
|
|
133
132
|
},
|
|
134
133
|
}));
|
|
135
134
|
return {
|
|
136
135
|
automaticResetEnabled,
|
|
137
136
|
hardReserveDue,
|
|
138
137
|
consumeTurnEnd,
|
|
139
|
-
/** The same
|
|
140
|
-
statusFor: (ctx) => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).
|
|
138
|
+
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
139
|
+
statusFor: (ctx) => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).reserve) }),
|
|
141
140
|
clear: () => { clearStaged(); notifiedWindows.clear(); },
|
|
142
141
|
};
|
|
143
142
|
}
|
package/dist/src/pi/runtime.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
|
|
|
4
4
|
import { VERSION, defineTool } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { registerBudget } from "./budget.js";
|
|
6
6
|
import { output } from "./tool-result.js";
|
|
7
|
-
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
|
|
7
|
+
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
9
|
import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
10
10
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE, RESET_LAST_WORD_TYPE } from "./entries.js";
|
|
@@ -75,7 +75,8 @@ export function registerContext(pi, settingsManager) {
|
|
|
75
75
|
const tail = branch.slice(branch.indexOf(marker) + 1);
|
|
76
76
|
const lastWordEntry = tail.find((entry) => entry.customType === RESET_LAST_WORD_TYPE);
|
|
77
77
|
const lastWord = lastWordEntry?.content?.startsWith(LAST_WORD_PREFIX) ? lastWordEntry.content.slice(LAST_WORD_PREFIX.length) : undefined;
|
|
78
|
-
|
|
78
|
+
const forced = markerResetOrigin(marker) === "forced";
|
|
79
|
+
ctx.ui.notify(`🥣 Brain emptied${forced ? " forcibly: overflow" : ""}${lastWord ? ` · last word: “${lastWord}”` : ""}`, forced ? "warning" : "info");
|
|
79
80
|
}
|
|
80
81
|
};
|
|
81
82
|
pi.on("turn_start", (_event, ctx) => notifyCommittedResets(ctx));
|
|
@@ -1354,7 +1354,7 @@ test("real AgentSession: injected settings managers own live policy and ignore c
|
|
|
1354
1354
|
});
|
|
1355
1355
|
await Promise.all([first.session.prompt("INJECTED_FIRST"), second.session.prompt("INJECTED_SECOND")]);
|
|
1356
1356
|
await Promise.all([first.session.waitForIdle(), second.session.waitForIdle()]);
|
|
1357
|
-
assert.deepEqual(contextRemainingResults(first), [0], "the injected high reserve reaches the
|
|
1357
|
+
assert.deepEqual(contextRemainingResults(first), [0], "the injected high reserve reaches the hard-reserve line in the real tool result");
|
|
1358
1358
|
assert.ok((contextRemainingResults(second)[0] ?? 0) > 0, "the second injected reserve produces a distinct real tool result");
|
|
1359
1359
|
assert.equal(resetMarkers(first).length, 1, "enabled injected policy resets at the first session's reserve");
|
|
1360
1360
|
assert.equal(resetMarkers(second).length, 0, "disabled injected policy does not inherit the first session's reset decision");
|
|
@@ -85,7 +85,7 @@ test("the root boot and reset boot carry durable window identity", async () => {
|
|
|
85
85
|
assert.equal(boundary.continue, true);
|
|
86
86
|
await runHandlers(captured, "turn_start", {}, ctx);
|
|
87
87
|
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
88
|
-
assert.
|
|
88
|
+
assert.deepEqual(noticesOf(ctx).filter((notice) => notice.message.includes("Brain emptied")), [{ message: "🥣 Brain emptied", type: "info" }], "the committed reset is announced once");
|
|
89
89
|
const entries = sessionManager.getBranch();
|
|
90
90
|
const marker = entries.find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
91
91
|
assert.ok(marker && marker.type === "custom");
|
|
@@ -371,6 +371,14 @@ test("notesoup command toggles future work, /empty-brain schedules a turn-end re
|
|
|
371
371
|
notices = await runCommand(captured, "notesoup", "", low);
|
|
372
372
|
assert.match(notices[0]?.message ?? "", /on/);
|
|
373
373
|
});
|
|
374
|
+
test("forced reset confirmation warns about overflow", async () => {
|
|
375
|
+
const sessionManager = manager();
|
|
376
|
+
const captured = makeExtension(sessionManager);
|
|
377
|
+
const ctx = context(sessionManager, undefined, { tokens: 199_000, contextWindow: 200_000, percent: 99.5 });
|
|
378
|
+
await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
379
|
+
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
380
|
+
assert.deepEqual(noticesOf(ctx).filter((notice) => notice.message.includes("Brain emptied")), [{ message: "🥣 Brain emptied forcibly: overflow", type: "warning" }]);
|
|
381
|
+
});
|
|
374
382
|
test("committed reset confirmation survives later work while repair refuses that suffix", async () => {
|
|
375
383
|
const sessionManager = manager();
|
|
376
384
|
const captured = makeExtension(sessionManager);
|
|
@@ -12,6 +12,7 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
|
|
|
12
12
|
const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
13
13
|
const guidance = await runContextHook(captured, low);
|
|
14
14
|
assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
|
|
15
|
+
assert.match(String((guidance?.messages[0]).content), /About 18616 tokens of room left in your brain\./, "the reminder reports room to the reserve, not to the warning");
|
|
15
16
|
assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
|
|
16
17
|
const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
|
|
17
18
|
assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
|
|
@@ -44,7 +45,7 @@ test("early guidance stays silent and the final warning notifies immediately onc
|
|
|
44
45
|
await runHandlers(captured, "agent_settled", {}, final);
|
|
45
46
|
assert.equal(noticesOf(final).filter((notice) => notice.message === "🥣 Brain almost full · taking notes").length, 1, "repeated injection and commit do not notify again");
|
|
46
47
|
});
|
|
47
|
-
test("the
|
|
48
|
+
test("the reported room ends at the hard reserve, clamps at zero, and preserves unknown usage", async () => {
|
|
48
49
|
const fixture = settingsFixture({
|
|
49
50
|
reserveTokens: 16_384,
|
|
50
51
|
project: { compaction: { reserveTokens: 32_768 } },
|
|
@@ -56,8 +57,9 @@ test("the visible countdown ends at the warning line, clamps at zero, and preser
|
|
|
56
57
|
const ctx = context(sm, undefined, { tokens, contextWindow: 200_000, percent: tokens === null ? null : tokens / 2000 }, true, fixture.cwd, trusted);
|
|
57
58
|
return resultJson(await call(captured, "get_context_remaining", {}, ctx)).remaining_tokens;
|
|
58
59
|
};
|
|
59
|
-
assert.equal(await readBudget(72_563),
|
|
60
|
-
assert.equal(await readBudget(
|
|
60
|
+
assert.equal(await readBudget(72_563), 94_669, "the reported room excludes only the project reserve (32768)");
|
|
61
|
+
assert.equal(await readBudget(150_848), 16_384, "the warning line still has the entire runway left");
|
|
62
|
+
assert.equal(await readBudget(167_232), 0, "the hard reserve reads zero");
|
|
61
63
|
assert.equal(await readBudget(190_000), 0, "below the reserve, still zero");
|
|
62
64
|
assert.equal(await readBudget(210_000), 0, "over the physical window");
|
|
63
65
|
assert.equal(await readBudget(null), null, "unknown usage remains unknown");
|
|
@@ -65,7 +67,7 @@ test("the visible countdown ends at the warning line, clamps at zero, and preser
|
|
|
65
67
|
assert.equal(resultJson(await call(captured, "get_context_remaining", {}, absent)).remaining_tokens, null);
|
|
66
68
|
const untrusted = context(sm, undefined, { tokens: 72_563, contextWindow: 200_000, percent: 36.2815 }, true, fixture.cwd, false);
|
|
67
69
|
await runHandlers(captured, "session_start", {}, untrusted);
|
|
68
|
-
assert.equal(await readBudget(72_563, false),
|
|
70
|
+
assert.equal(await readBudget(72_563, false), 111_053, "session start reloads the global reserve when the project is untrusted");
|
|
69
71
|
});
|
|
70
72
|
test("absent notesoup key or margins reproduce the default reminder threshold at Pi's default reserve", async () => {
|
|
71
73
|
assert.equal(DEFAULT_RESERVE_TOKENS, 16_384);
|
package/dist/test/dsh.test.js
CHANGED
|
@@ -233,7 +233,7 @@ test("dsh budget follows configured host reserve, close-out tool runs across ste
|
|
|
233
233
|
assert.equal(budget?.reserve, 60000);
|
|
234
234
|
assert.equal(budget?.warning, 76384);
|
|
235
235
|
assert.equal(budget?.reminder, 84576);
|
|
236
|
-
assert.equal(budget?.countdown, Math.max(0,
|
|
236
|
+
assert.equal(budget?.countdown, Math.max(0, 140000 - budget.used));
|
|
237
237
|
mock.script.push({ tool: "notes_write", input: { address: "handoff", content: "checkpoint", }, inputTokens: 125000 }, { tool: "empty_brain", input: {} }, { text: "fresh" });
|
|
238
238
|
await run(agent, "continue");
|
|
239
239
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 1);
|
|
@@ -10,7 +10,7 @@ import { CLAUDE_WARNING_PROMPT, COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_C
|
|
|
10
10
|
* The reviewed Design text is what the model actually reads, so the golden copies below pin it
|
|
11
11
|
* character for character: an edit that drifts the wording has to change them too.
|
|
12
12
|
*/
|
|
13
|
-
const GOLDEN_GUIDANCE = `About {remaining} tokens left
|
|
13
|
+
const GOLDEN_GUIDANCE = `About {remaining} tokens of room left in your brain.
|
|
14
14
|
Your notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.
|
|
15
15
|
What lives only in this brain leaves with it.
|
|
16
16
|
A decent moment to put down where you are, while you still remember why.
|
package/docs/dsh.md
CHANGED
|
@@ -34,7 +34,7 @@ warning = reserve + 16384
|
|
|
34
34
|
reminder = reserve + reminderMarginTokens
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining`
|
|
37
|
+
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining` and the numeric reminder report room to resetAt: physical remaining minus reserve, clamped at zero. The warning runway is included. Missing model capacity returns null. A profile with no positive reset budget fails with `BUDGET_CONFIG` and the numbers to fix. No independent percentage cutoff is added by notesoup.
|
|
38
38
|
|
|
39
39
|
The adapter uses `tokenMeter.measure`, model context from `resolveModelInfo`, and the mounted engine's resolved `config`. Alpha.2 keeps an old provider-usage anchor across surface replacement; until the fresh window has a response, notesoup uses the meter's current `surfaceTokens` plus its public tool-schema estimator instead of that stale anchor.
|
|
40
40
|
|
package/package.json
CHANGED
package/src/boot/text.ts
CHANGED
|
@@ -21,8 +21,7 @@ export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in t
|
|
|
21
21
|
* notesoup's tool names. It lives once per window in the persisted boot block;
|
|
22
22
|
* it is never re-injected, so it stays cache-stable at the head of the window.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
* stays hidden (budget/constants.ts). Keep "zero = wiped" — do not make this honest.
|
|
24
|
+
* The reported room reaches zero at the hard-reserve wipe line.
|
|
26
25
|
*/
|
|
27
26
|
const PROTOCOL_BLOCK = `${NOTES_PROTOCOL_OPEN_TAG}
|
|
28
27
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
package/src/budget/constants.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export const DEFAULT_RESERVE_TOKENS = 16_384;
|
|
2
2
|
export const DEFAULT_REMINDER_MARGIN_TOKENS = 24_576;
|
|
3
3
|
/**
|
|
4
|
-
* The runway
|
|
5
|
-
*
|
|
6
|
-
* line (reserve + WARNING_RUNWAY_TOKENS); what lies below is overdraft the model
|
|
7
|
-
* never sees — Codex's fallback buffer, relocated above the line.
|
|
4
|
+
* The runway between the final warning and the hard-reserve wipe.
|
|
5
|
+
* get_context_remaining includes this room; zero is the hard-reserve line.
|
|
8
6
|
*/
|
|
9
7
|
export const WARNING_RUNWAY_TOKENS = 16_384;
|
package/src/budget/policy.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function deriveThresholds(reserveTokens: number, margins: NotesoupSetting
|
|
|
26
26
|
return { thresholds: { reminder: reserveTokens + reminderMargin, reserve: reserveTokens, warning: reserveTokens + WARNING_RUNWAY_TOKENS }, warnings };
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
export function remainingBudget(remaining: number | null,
|
|
31
|
-
return remaining === null ? null : Math.max(0, remaining -
|
|
29
|
+
/** Room before the hard-reserve wipe; unknown usage stays unknown. */
|
|
30
|
+
export function remainingBudget(remaining: number | null, reserve: number): number | null {
|
|
31
|
+
return remaining === null ? null : Math.max(0, remaining - reserve);
|
|
32
32
|
}
|
package/src/budget/text.ts
CHANGED
|
@@ -81,5 +81,5 @@ export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready,
|
|
|
81
81
|
* at write time; get_context_remaining remains the live source for the current figure.
|
|
82
82
|
*/
|
|
83
83
|
export function tokenBudgetGuidance(remaining: number, wipeTool: string): string {
|
|
84
|
-
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens left
|
|
84
|
+
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left in your brain.\nYour notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.\nWhat lives only in this brain leaves with it.\nA decent moment to put down where you are, while you still remember why.\nReady when you are: \`${wipeTool}\`.\n${GUIDANCE_CLOSE_TAG}`;
|
|
85
85
|
}
|
package/src/dsh/budget.ts
CHANGED
|
@@ -31,5 +31,5 @@ export async function measureBudget(ctx: Context, agent: CompactionAgentContext,
|
|
|
31
31
|
if (event.type === "user/message" && event.data.source.kind === "compact-checkpoint") { used = measured.surfaceTokens + estimateToolsTokens(agent.session.requestHeader()); break; }
|
|
32
32
|
}
|
|
33
33
|
const remaining = Math.max(0, contextWindow - used);
|
|
34
|
-
return { used, contextWindow, reserve, resetAt, remaining, countdown: remainingBudget(remaining,
|
|
34
|
+
return { used, contextWindow, reserve, resetAt, remaining, countdown: remainingBudget(remaining, reserve)!, warning: thresholds.warning, reminder: thresholds.reminder };
|
|
35
35
|
}
|
package/src/dsh/tools.ts
CHANGED
|
@@ -93,7 +93,7 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
|
|
|
93
93
|
}));
|
|
94
94
|
ctx.tools.register(defineTool({
|
|
95
95
|
name: "get_context_remaining",
|
|
96
|
-
description: "
|
|
96
|
+
description: "Check how much room your brain has left before it gets forcibly emptied. Returns null when unknown.",
|
|
97
97
|
parameters: {},
|
|
98
98
|
output: { schema: { type: "object", properties: { remaining_tokens: { oneOf: [{ type: "integer" }, { type: "null" }], required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: JSON.stringify(value) }] },
|
|
99
99
|
async execute(_args, exec) {
|
package/src/pi/budget.ts
CHANGED
|
@@ -93,7 +93,7 @@ export function registerBudget(
|
|
|
93
93
|
const remaining = remainingTokens(ctx);
|
|
94
94
|
if (remaining === null) return result();
|
|
95
95
|
const windowId = currentWindowId(ctx);
|
|
96
|
-
const { reminder, warning } = thresholdsFor(ctx);
|
|
96
|
+
const { reminder, warning, reserve } = thresholdsFor(ctx);
|
|
97
97
|
if (remaining <= warning) {
|
|
98
98
|
if (hasWindowMessage(ctx, WARNING_TYPE)) return result();
|
|
99
99
|
// The critical close-out starts at reserve + runway, not at the hard reserve.
|
|
@@ -112,7 +112,7 @@ export function registerBudget(
|
|
|
112
112
|
if (hasWindowMessage(ctx, GUIDANCE_TYPE)) return result();
|
|
113
113
|
if (pendingGuidance?.windowId !== windowId) {
|
|
114
114
|
if (remaining > reminder) return result();
|
|
115
|
-
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining,
|
|
115
|
+
pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, reserve) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
|
|
116
116
|
}
|
|
117
117
|
return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
|
|
118
118
|
});
|
|
@@ -120,13 +120,12 @@ export function registerBudget(
|
|
|
120
120
|
pi.registerTool(defineTool({
|
|
121
121
|
name: "get_context_remaining",
|
|
122
122
|
label: "Get context remaining",
|
|
123
|
-
description: "
|
|
123
|
+
description: "Check how much room your brain has left before it gets forcibly emptied. Returns null when unknown.",
|
|
124
124
|
parameters: Type.Object({}, { additionalProperties: false }),
|
|
125
125
|
async execute(_id, _params, _signal, _update, ctx) {
|
|
126
|
-
//
|
|
127
|
-
// the runway below it is overdraft the model never sees. See budget/constants.ts.
|
|
126
|
+
// Report room to the hard-reserve wipe, including the warning runway.
|
|
128
127
|
const remaining = remainingTokens(ctx);
|
|
129
|
-
return output({ remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx as ExtensionContext).
|
|
128
|
+
return output({ remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx as ExtensionContext).reserve) });
|
|
130
129
|
},
|
|
131
130
|
}));
|
|
132
131
|
|
|
@@ -134,8 +133,8 @@ export function registerBudget(
|
|
|
134
133
|
automaticResetEnabled,
|
|
135
134
|
hardReserveDue,
|
|
136
135
|
consumeTurnEnd,
|
|
137
|
-
/** The same
|
|
138
|
-
statusFor: (ctx: ExtensionContext): { remaining: number | null } => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).
|
|
136
|
+
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
137
|
+
statusFor: (ctx: ExtensionContext): { remaining: number | null } => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).reserve) }),
|
|
139
138
|
clear: () => { clearStaged(); notifiedWindows.clear(); },
|
|
140
139
|
};
|
|
141
140
|
}
|
package/src/pi/runtime.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getCurrentSystemMessage, Type } from "@earendil-works/pi-ai";
|
|
|
4
4
|
import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { registerBudget } from "./budget.js";
|
|
6
6
|
import { output } from "./tool-result.js";
|
|
7
|
-
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
|
|
7
|
+
import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
9
|
import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
10
10
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE, RESET_LAST_WORD_TYPE } from "./entries.js";
|
|
@@ -75,7 +75,8 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
75
75
|
const tail = branch.slice(branch.indexOf(marker) + 1);
|
|
76
76
|
const lastWordEntry = tail.find((entry) => (entry as { customType?: string }).customType === RESET_LAST_WORD_TYPE) as { content?: string } | undefined;
|
|
77
77
|
const lastWord = lastWordEntry?.content?.startsWith(LAST_WORD_PREFIX) ? lastWordEntry.content.slice(LAST_WORD_PREFIX.length) : undefined;
|
|
78
|
-
|
|
78
|
+
const forced = markerResetOrigin(marker) === "forced";
|
|
79
|
+
ctx.ui.notify(`🥣 Brain emptied${forced ? " forcibly: overflow" : ""}${lastWord ? ` · last word: “${lastWord}”` : ""}`, forced ? "warning" : "info");
|
|
79
80
|
}
|
|
80
81
|
};
|
|
81
82
|
pi.on("turn_start", (_event, ctx) => notifyCommittedResets(ctx));
|