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
|
@@ -3,7 +3,7 @@ import { realpathSync } from "node:fs";
|
|
|
3
3
|
import { resolve, sep } from "node:path";
|
|
4
4
|
import { estimateContextTokens } from "./estimate.js";
|
|
5
5
|
import { convertToLlm } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
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";
|
|
6
|
+
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";
|
|
7
7
|
import { NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
|
|
8
8
|
export function isWindowMarker(entry) {
|
|
9
9
|
return entry.type === "custom" && entry.customType === RESET_MARKER_TYPE &&
|
|
@@ -59,36 +59,45 @@ export function sessionEnabled(branch) {
|
|
|
59
59
|
return undefined;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Whether pi-souls reports a naked
|
|
63
|
-
*
|
|
62
|
+
* Whether pi-souls reports a mode (`naked` or restricted `tools` `"none"`/`"rw"`) that disables
|
|
63
|
+
* notesoup by default. Ask the loaded pi-souls extension synchronously first; when absent,
|
|
64
|
+
* read its durable entries (`pi-souls:naked`, `pi-souls:tools`).
|
|
64
65
|
*/
|
|
65
|
-
|
|
66
|
+
function isDisabledByPiSouls(pi, branch) {
|
|
66
67
|
const query = { branch };
|
|
67
68
|
pi.events?.emit("pi-souls:state", query);
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
69
|
+
if (query.naked === true || query.tools === "none" || query.tools === "rw")
|
|
70
|
+
return true;
|
|
71
|
+
const checkDurable = (customType, disabled) => {
|
|
72
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
73
|
+
const entry = branch[i];
|
|
74
|
+
if (entry.type !== "custom" || entry.customType !== customType)
|
|
75
|
+
continue;
|
|
76
|
+
if (typeof entry.data !== "object" || entry.data === null)
|
|
77
|
+
continue;
|
|
78
|
+
const result = disabled(entry.data);
|
|
79
|
+
if (result !== undefined)
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
const nakedDisabled = typeof query.naked === "boolean"
|
|
85
|
+
? false
|
|
86
|
+
: checkDurable("pi-souls:naked", (data) => data.naked === true ? true : data.naked === false || data.naked === null ? false : undefined);
|
|
87
|
+
if (nakedDisabled)
|
|
88
|
+
return true;
|
|
89
|
+
return query.tools !== undefined
|
|
90
|
+
? false
|
|
91
|
+
: checkDurable("pi-souls:tools", (data) => data.tools === "none" || data.tools === "rw" ? true
|
|
92
|
+
: data.tools === null ? false : undefined);
|
|
84
93
|
}
|
|
85
|
-
/** Explicit branch choice wins; otherwise the CLI flag and
|
|
94
|
+
/** Explicit branch choice wins; otherwise the CLI flag and naked/restricted-tools pi-souls runs disable. */
|
|
86
95
|
export function isNotesoupEnabled(pi, ctx) {
|
|
87
96
|
const branch = ctx.sessionManager.getBranch();
|
|
88
97
|
const explicit = sessionEnabled(branch);
|
|
89
98
|
if (explicit !== undefined)
|
|
90
99
|
return explicit;
|
|
91
|
-
return pi.getFlag?.("no-notesoup") !== true && !
|
|
100
|
+
return pi.getFlag?.("no-notesoup") !== true && !isDisabledByPiSouls(pi, branch);
|
|
92
101
|
}
|
|
93
102
|
/** A reset is checkpoint-backed only when its marker directly follows a native compaction. */
|
|
94
103
|
export function isCheckpointBackedReset(ctx, marker = currentReset(ctx)) {
|
|
@@ -222,6 +231,7 @@ const NOTESOUP_MESSAGE_TYPES = new Set([
|
|
|
222
231
|
GUIDANCE_TYPE,
|
|
223
232
|
WARNING_TYPE,
|
|
224
233
|
MANUAL_WIPE_TYPE,
|
|
234
|
+
TURNOVER_TRIGGER_TYPE,
|
|
225
235
|
CONTINUATION_TYPE,
|
|
226
236
|
RESET_LAST_WORD_TYPE,
|
|
227
237
|
MARKER_TYPE,
|
|
@@ -8,7 +8,11 @@ export type ResetOrigin = "normal" | "forced";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const NORMAL_CONTINUATIONS: readonly string[];
|
|
10
10
|
export declare const FORCED_CONTINUATIONS: readonly string[];
|
|
11
|
-
export declare
|
|
11
|
+
export declare const BETWEEN_TURNS_CONTINUATIONS: readonly string[];
|
|
12
|
+
export type ContinuationOptions = Readonly<{
|
|
13
|
+
betweenTurns?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function selectContinuation(origin: ResetOrigin, options?: ContinuationOptions): string;
|
|
12
16
|
/** Budget timing stays out of manual close-outs, which may have plenty of room. */
|
|
13
17
|
export declare const WARNING_TIMING = "Almost out of room. The wipe lands at the end of whichever turn uses the last of it, possibly this one.";
|
|
14
18
|
/** The shared handoff instructions, used for both budget and manual close-outs. */
|
package/dist/src/budget/text.js
CHANGED
|
@@ -18,8 +18,17 @@ export const FORCED_CONTINUATIONS = [
|
|
|
18
18
|
"*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.",
|
|
19
19
|
"*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.",
|
|
20
20
|
];
|
|
21
|
-
export
|
|
22
|
-
|
|
21
|
+
export const BETWEEN_TURNS_CONTINUATIONS = [
|
|
22
|
+
"*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.",
|
|
23
|
+
"*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.",
|
|
24
|
+
"*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.",
|
|
25
|
+
"*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.",
|
|
26
|
+
"*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.",
|
|
27
|
+
];
|
|
28
|
+
export function selectContinuation(origin, options) {
|
|
29
|
+
const pool = origin === "forced"
|
|
30
|
+
? (options?.betweenTurns ? BETWEEN_TURNS_CONTINUATIONS : FORCED_CONTINUATIONS)
|
|
31
|
+
: NORMAL_CONTINUATIONS;
|
|
23
32
|
return pool[Math.floor(Math.random() * pool.length)];
|
|
24
33
|
}
|
|
25
34
|
/** Budget timing stays out of manual close-outs, which may have plenty of room. */
|
package/dist/src/index.d.ts
CHANGED
|
@@ -30,4 +30,4 @@ export type { Operation, Renderer, TextWindow } from "./tools/result.js";
|
|
|
30
30
|
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
|
31
31
|
export type { ResolvedThresholds } from "./budget/policy.js";
|
|
32
32
|
export { selectContinuation, tokenBudgetGuidance, warningPrompt, WARNING_BODY } from "./budget/text.js";
|
|
33
|
-
export type { ResetOrigin } from "./budget/text.js";
|
|
33
|
+
export type { ContinuationOptions, ResetOrigin } from "./budget/text.js";
|
|
@@ -16,7 +16,7 @@ import { createNotesStore } from "../src/notes/index.js";
|
|
|
16
16
|
import { agentSlug } from "../plugins/pi/notes/adapter.js";
|
|
17
17
|
import { registerBudget } from "../plugins/pi/budget.js";
|
|
18
18
|
import { estimateContextTokens } from "../plugins/pi/estimate.js";
|
|
19
|
-
import { FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
|
|
19
|
+
import { BETWEEN_TURNS_CONTINUATIONS, FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
|
|
20
20
|
import { commandWarningContent, PI_PRE_RESET_HINTS } from "../plugins/pi/text.js";
|
|
21
21
|
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE } from "../plugins/pi/tool-result.js";
|
|
22
22
|
async function openFixture(options) {
|
|
@@ -132,6 +132,7 @@ async function openFixture(options) {
|
|
|
132
132
|
return stream;
|
|
133
133
|
};
|
|
134
134
|
await session.bindExtensions({
|
|
135
|
+
mode: options.mode,
|
|
135
136
|
uiContext: {
|
|
136
137
|
notify(message) {
|
|
137
138
|
notices.push(message);
|
|
@@ -195,7 +196,7 @@ function text(message) {
|
|
|
195
196
|
return JSON.stringify(message?.messages ?? []);
|
|
196
197
|
}
|
|
197
198
|
/** `text()` serializes to JSON, so match the reset prose in its escaped form. */
|
|
198
|
-
const CONTINUATION_JSON_LINES = [...NORMAL_CONTINUATIONS, ...FORCED_CONTINUATIONS].map((line) => JSON.stringify(line).slice(1, -1));
|
|
199
|
+
const CONTINUATION_JSON_LINES = [...NORMAL_CONTINUATIONS, ...FORCED_CONTINUATIONS, ...BETWEEN_TURNS_CONTINUATIONS].map((line) => JSON.stringify(line).slice(1, -1));
|
|
199
200
|
/** How many distinct reset paragraphs a serialized request carries; one fresh window carries one. */
|
|
200
201
|
function continuationLinesIn(body) {
|
|
201
202
|
return CONTINUATION_JSON_LINES.filter((line) => body.includes(line));
|
|
@@ -802,7 +803,7 @@ test("real AgentSession: streaming clear prompt keeps the first request", async
|
|
|
802
803
|
fixture.close();
|
|
803
804
|
}
|
|
804
805
|
});
|
|
805
|
-
test("real AgentSession: hard-reserve reset continues without replaying its original text or image, including pre-send oversized input", async () => {
|
|
806
|
+
test("real AgentSession: mid-turn hard-reserve reset continues without replaying its original text or image, including pre-send oversized input", async () => {
|
|
806
807
|
let fixture;
|
|
807
808
|
const input = "HARD_RESERVE_IMAGE_INPUT";
|
|
808
809
|
const oversized = `PRE_SEND_OVERSIZED_${"x".repeat(100_000)}`;
|
|
@@ -811,7 +812,7 @@ test("real AgentSession: hard-reserve reset continues without replaying its orig
|
|
|
811
812
|
defaultReserveTokens: 80_000,
|
|
812
813
|
script: (request, context) => {
|
|
813
814
|
if (request === 1)
|
|
814
|
-
return assistant(fixture, [{ type: "
|
|
815
|
+
return assistant(fixture, [{ type: "toolCall", id: "hr-tool", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(80_000) });
|
|
815
816
|
if (request === 2) {
|
|
816
817
|
assertFreshRequest(fixture, 1, input);
|
|
817
818
|
assert.equal(context.messages.some((message) => message.role === "user" && Array.isArray(message.content) && message.content.some((block) => block.type === "image")), false);
|
|
@@ -843,6 +844,125 @@ test("real AgentSession: hard-reserve reset continues without replaying its orig
|
|
|
843
844
|
fixture.close();
|
|
844
845
|
}
|
|
845
846
|
});
|
|
847
|
+
test("real AgentSession: TUI clean final answer stays visible, rolls over cleanly on next input (including near-reserve pushes and /skill expansion), and preserves oversized pastes in history", async () => {
|
|
848
|
+
let fixture;
|
|
849
|
+
const skillDir = mkdtempSync(join(tmpdir(), "notesoup-turnover-skill-"));
|
|
850
|
+
mkdirSync(join(skillDir, "expand-check"), { recursive: true });
|
|
851
|
+
writeFileSync(join(skillDir, "expand-check", "SKILL.md"), "---\nname: expand-check\ndescription: verifies skill expansion across turnover\n---\nSKILL_BODY_EXPANDED_TOKEN\n");
|
|
852
|
+
const image = { type: "image", data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC", mimeType: "image/png" };
|
|
853
|
+
const boundaryPush = `BOUNDARY_PUSH_${"a".repeat(4_000)}`;
|
|
854
|
+
const oversized = `DEFERRED_OVERSIZED_${"x".repeat(100_000)}`;
|
|
855
|
+
fixture = await openFixture({
|
|
856
|
+
mode: "tui",
|
|
857
|
+
skillPaths: [skillDir],
|
|
858
|
+
defaultReserveTokens: 80_000,
|
|
859
|
+
script: (request, context) => {
|
|
860
|
+
if (request === 1)
|
|
861
|
+
return assistant(fixture, [{ type: "text", text: "VISIBLE_FINAL_ANSWER" }], "stop", { usage: usage(80_000) });
|
|
862
|
+
if (request === 2) {
|
|
863
|
+
assertFreshRequest(fixture, 1, "VISIBLE_FINAL_ANSWER");
|
|
864
|
+
assert.ok(text(context).includes("NEXT_HUMAN_FOLLOWUP"), "next human prompt reaches the fresh window directly");
|
|
865
|
+
assert.ok(context.messages.some((message) => message.role === "user" && Array.isArray(message.content) && message.content.some((block) => block.type === "image")), "attached image crosses cleanly");
|
|
866
|
+
// Just 500 tokens above reserve (remaining = 80_500 > 80_000), so the next ~1k-token message pushes over reserve.
|
|
867
|
+
return assistant(fixture, [{ type: "text", text: "NEAR_RESERVE_ANSWER" }], "stop", { usage: usage(19_500) });
|
|
868
|
+
}
|
|
869
|
+
if (request === 3) {
|
|
870
|
+
assertFreshRequest(fixture, 2, "NEAR_RESERVE_ANSWER");
|
|
871
|
+
assert.ok(text(context).includes("BOUNDARY_PUSH_"), "normal message pushing past reserve rolls over cleanly into the fresh window instead of burying itself in history");
|
|
872
|
+
return assistant(fixture, [{ type: "text", text: "BEFORE_SKILL_ANSWER" }], "stop", { usage: usage(80_000) });
|
|
873
|
+
}
|
|
874
|
+
if (request === 4) {
|
|
875
|
+
assertFreshRequest(fixture, 3, "BEFORE_SKILL_ANSWER");
|
|
876
|
+
assert.ok(text(context).includes("SKILL_BODY_EXPANDED_TOKEN"), "/skill commands expand cleanly after TUI between-turns turnover");
|
|
877
|
+
return assistant(fixture, [{ type: "text", text: "AFTER_SKILL_ANSWER" }], "stop", { usage: usage(80_000) });
|
|
878
|
+
}
|
|
879
|
+
assert.equal(request, 5, "oversized prompt falls back to pre-send history reset without extra provider call");
|
|
880
|
+
assertFreshRequest(fixture, 4, "DEFERRED_OVERSIZED_");
|
|
881
|
+
return assistant(fixture, [{ type: "text", text: "handled oversized from history" }]);
|
|
882
|
+
},
|
|
883
|
+
});
|
|
884
|
+
try {
|
|
885
|
+
await fixture.session.prompt("FIRST_QUESTION");
|
|
886
|
+
await fixture.session.waitForIdle();
|
|
887
|
+
assert.equal(fixture.requests.length, 1, "no ghost continuation after a clean final answer");
|
|
888
|
+
assert.equal(resetMarkers(fixture).length, 0, "final answer stays visible in TUI instead of wiping immediately");
|
|
889
|
+
assert.ok(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("VISIBLE_FINAL_ANSWER"));
|
|
890
|
+
await fixture.session.prompt("NEXT_HUMAN_FOLLOWUP", { images: [image] });
|
|
891
|
+
await fixture.session.waitForIdle();
|
|
892
|
+
assert.equal(fixture.requests.length, 2, "turnover costs zero extra provider requests");
|
|
893
|
+
assert.equal(resetMarkers(fixture).length, 1);
|
|
894
|
+
const firstMarker = resetMarkers(fixture)[0];
|
|
895
|
+
assert.equal(firstMarker.data.origin, "forced");
|
|
896
|
+
assert.equal(firstMarker.data.betweenTurns, true);
|
|
897
|
+
const continuations = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
898
|
+
assert.ok(BETWEEN_TURNS_CONTINUATIONS.includes(String(continuations[0].content)), "between-turns turnover uses the honest between-turns pool");
|
|
899
|
+
assert.equal(fixture.notices.some((n) => n.includes("overflow") || n.includes("Brain almost full")), false, "clean between-turns rollover does not flash an overflow or warning toast");
|
|
900
|
+
const userCopies = fixture.sessionManager.getBranch().filter((entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("NEXT_HUMAN_FOLLOWUP"));
|
|
901
|
+
assert.equal(userCopies.length, 1, "withheld user message is recorded once as a real user entry in the fresh window");
|
|
902
|
+
// Near-reserve boundary push (~1k tokens when remaining is reserve + 500) rotates cleanly instead of tripping pre-send overflow.
|
|
903
|
+
await fixture.session.prompt(boundaryPush);
|
|
904
|
+
await fixture.session.waitForIdle();
|
|
905
|
+
assert.equal(fixture.requests.length, 3);
|
|
906
|
+
assert.equal(resetMarkers(fixture).length, 2);
|
|
907
|
+
assert.equal(resetMarkers(fixture)[1].data.betweenTurns, true);
|
|
908
|
+
assert.equal(fixture.notices.some((n) => n.includes("overflow")), false);
|
|
909
|
+
// /skill command right after a full window preserves template/skill expansion.
|
|
910
|
+
await fixture.session.prompt("/skill:expand-check");
|
|
911
|
+
await fixture.session.waitForIdle();
|
|
912
|
+
assert.equal(fixture.requests.length, 4);
|
|
913
|
+
assert.equal(resetMarkers(fixture).length, 3);
|
|
914
|
+
assert.equal(fixture.notices.some((n) => n.includes("overflow")), false);
|
|
915
|
+
// Oversized prompt falls back to pre-send history reset.
|
|
916
|
+
await fixture.session.prompt(oversized);
|
|
917
|
+
await fixture.session.waitForIdle();
|
|
918
|
+
assert.equal(fixture.requests.length, 5);
|
|
919
|
+
assert.equal(resetMarkers(fixture).length, 4);
|
|
920
|
+
const oversizedEntry = fixture.sessionManager.getBranch().find((entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("DEFERRED_OVERSIZED_"));
|
|
921
|
+
assert.ok(oversizedEntry, "oversized follow-up is preserved in raw history rather than carried verbatim into the fresh window");
|
|
922
|
+
}
|
|
923
|
+
finally {
|
|
924
|
+
fixture.close();
|
|
925
|
+
rmSync(skillDir, { recursive: true, force: true });
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
test("real AgentSession: RPC clean final answer rotates quietly at turn_end without breaking prompt disposition or splitting agent_settled", async () => {
|
|
929
|
+
let fixture;
|
|
930
|
+
fixture = await openFixture({
|
|
931
|
+
mode: "rpc",
|
|
932
|
+
defaultReserveTokens: 80_000,
|
|
933
|
+
script: (request, context) => {
|
|
934
|
+
if (request === 1)
|
|
935
|
+
return assistant(fixture, [{ type: "text", text: "RPC_FIRST_ANSWER" }], "stop", { usage: usage(80_000) });
|
|
936
|
+
assert.equal(request, 2);
|
|
937
|
+
assertFreshRequest(fixture, 1, "RPC_FIRST_ANSWER");
|
|
938
|
+
assert.ok(text(context).includes("RPC_SECOND_QUESTION"));
|
|
939
|
+
return assistant(fixture, [{ type: "text", text: "RPC_SECOND_ANSWER" }]);
|
|
940
|
+
},
|
|
941
|
+
});
|
|
942
|
+
try {
|
|
943
|
+
await fixture.session.prompt("RPC_FIRST_QUESTION", { source: "rpc" });
|
|
944
|
+
assert.equal(fixture.requests.length, 1, "no ghost continuation after clean final answer in RPC");
|
|
945
|
+
assert.equal(resetMarkers(fixture).length, 1, "non-TUI mode rotates quietly right at turn_end");
|
|
946
|
+
const marker = resetMarkers(fixture)[0];
|
|
947
|
+
assert.equal(marker.data.origin, "forced");
|
|
948
|
+
assert.equal(marker.data.betweenTurns, true);
|
|
949
|
+
const continuations = fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
950
|
+
assert.ok(BETWEEN_TURNS_CONTINUATIONS.includes(String(continuations[0].content)));
|
|
951
|
+
assert.equal(fixture.notices.some((n) => n.includes("overflow")), false, "quiet between-turns rotation does not flash overflow");
|
|
952
|
+
const settledBefore = fixture.events.filter((e) => e.type === "agent_settled").length;
|
|
953
|
+
let disposition;
|
|
954
|
+
await fixture.session.prompt("RPC_SECOND_QUESTION", {
|
|
955
|
+
source: "rpc",
|
|
956
|
+
preflightResult: (value) => { disposition = value; },
|
|
957
|
+
});
|
|
958
|
+
assert.equal(disposition, "started", "next RPC prompt starts directly without input interception");
|
|
959
|
+
assert.equal(fixture.requests.length, 2, "await session.prompt resolves only after the assistant replies");
|
|
960
|
+
assert.equal(fixture.events.filter((e) => e.type === "agent_settled").length - settledBefore, 1, "exactly one agent_settled for the second RPC turn");
|
|
961
|
+
}
|
|
962
|
+
finally {
|
|
963
|
+
fixture.close();
|
|
964
|
+
}
|
|
965
|
+
});
|
|
846
966
|
test("real AgentSession: manual hard-reserve reset stops clean and mixed-tool turns without fresh provider work", async () => {
|
|
847
967
|
for (const mixed of [false, true]) {
|
|
848
968
|
let fixture;
|
|
@@ -1385,7 +1505,7 @@ test("real AgentSession: new input queued while a forced reset commits is delive
|
|
|
1385
1505
|
script: (request) => {
|
|
1386
1506
|
if (request === 1)
|
|
1387
1507
|
return boundaryEvent === "turn_end"
|
|
1388
|
-
? assistant(fixture, [{ type: "
|
|
1508
|
+
? assistant(fixture, [{ type: "toolCall", id: "hr-queue", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(80_000) })
|
|
1389
1509
|
: assistant(fixture, [], "error", { errorMessage: "Prompt too long: context exceeds maximum context length" });
|
|
1390
1510
|
return assistant(fixture, [{ type: "text", text: "new input handled" }]);
|
|
1391
1511
|
},
|
|
@@ -1563,39 +1683,74 @@ test("real AgentSession: overflow and recoverable length continue once without r
|
|
|
1563
1683
|
repeated.close();
|
|
1564
1684
|
}
|
|
1565
1685
|
});
|
|
1566
|
-
test("real AgentSession: a smaller-model
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1686
|
+
test("real AgentSession: a smaller-model downgrade rolls over proactively, and passive smaller-model overflow recovers without replaying submitted input", async () => {
|
|
1687
|
+
// (a) In TUI, downgrading to a smaller model whose window is already below persisted usage rolls over cleanly between turns before hitting the provider.
|
|
1688
|
+
{
|
|
1689
|
+
let fixture;
|
|
1690
|
+
fixture = await openFixture({
|
|
1691
|
+
mode: "tui",
|
|
1692
|
+
contextWindow: 200_000,
|
|
1693
|
+
script: (request, context) => {
|
|
1694
|
+
if (request === 1)
|
|
1695
|
+
return assistant(fixture, [{ type: "text", text: "LARGE_MODEL_HISTORY" }], "stop", { usage: usage(150_000) });
|
|
1696
|
+
assert.equal(request, 2, "proactive rollover avoids a doomed overflow request on the smaller model");
|
|
1697
|
+
assertFreshRequest(fixture, 1, "LARGE_MODEL_HISTORY");
|
|
1698
|
+
assert.ok(text(context).includes("CONTINUE_AFTER_MODEL_SWITCH"), "withheld user message reaches the fresh smaller-model window directly");
|
|
1699
|
+
return assistant(fixture, [{ type: "text", text: "continued on smaller model" }]);
|
|
1700
|
+
},
|
|
1701
|
+
});
|
|
1702
|
+
try {
|
|
1703
|
+
await fixture.session.prompt("LARGE_MODEL_TASK");
|
|
1704
|
+
await fixture.session.waitForIdle();
|
|
1705
|
+
assert.equal(resetMarkers(fixture).length, 0, "150k fits the original model's reserve");
|
|
1706
|
+
const smaller = { ...fixture.model, id: `${fixture.model.id}-small`, contextWindow: 100_000 };
|
|
1707
|
+
fixture.model = smaller;
|
|
1708
|
+
await fixture.session.setModel(smaller, { persist: false });
|
|
1709
|
+
await fixture.session.prompt("CONTINUE_AFTER_MODEL_SWITCH");
|
|
1710
|
+
await fixture.session.waitForIdle();
|
|
1711
|
+
assert.equal(resetMarkers(fixture).length, 1, "model downgrade triggers one clean between-turns rollover");
|
|
1712
|
+
assert.equal(fixture.requests.length, 2);
|
|
1713
|
+
assert.equal(fixture.session.model?.id, smaller.id, "rollover stays on the selected model");
|
|
1714
|
+
}
|
|
1715
|
+
finally {
|
|
1716
|
+
fixture.close();
|
|
1717
|
+
}
|
|
1596
1718
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1719
|
+
// (b) When usage still appears below the smaller model's nominal reserve, a real provider overflow recovers without replaying submitted input.
|
|
1720
|
+
{
|
|
1721
|
+
let fixture;
|
|
1722
|
+
fixture = await openFixture({
|
|
1723
|
+
contextWindow: 200_000,
|
|
1724
|
+
script: (request, context) => {
|
|
1725
|
+
if (request === 1)
|
|
1726
|
+
return assistant(fixture, [{ type: "text", text: "LARGE_MODEL_HISTORY" }], "stop", { usage: usage(50_000) });
|
|
1727
|
+
if (request === 2)
|
|
1728
|
+
return assistant(fixture, [], "error", { errorMessage: "Prompt too long: context exceeds maximum context length" });
|
|
1729
|
+
assert.equal(request, 3);
|
|
1730
|
+
assert.equal(text(context).includes("CONTINUE_AFTER_MODEL_SWITCH"), false);
|
|
1731
|
+
return assistant(fixture, [{ type: "text", text: "continued on smaller model" }]);
|
|
1732
|
+
},
|
|
1733
|
+
});
|
|
1734
|
+
try {
|
|
1735
|
+
await fixture.session.prompt("LARGE_MODEL_TASK");
|
|
1736
|
+
await fixture.session.waitForIdle();
|
|
1737
|
+
assert.equal(resetMarkers(fixture).length, 0);
|
|
1738
|
+
const smaller = { ...fixture.model, id: `${fixture.model.id}-small`, contextWindow: 100_000 };
|
|
1739
|
+
fixture.model = smaller;
|
|
1740
|
+
await fixture.session.setModel(smaller, { persist: false });
|
|
1741
|
+
await fixture.session.prompt("CONTINUE_AFTER_MODEL_SWITCH");
|
|
1742
|
+
await fixture.session.waitForIdle();
|
|
1743
|
+
assert.equal(resetMarkers(fixture).length, 1, "passive model downgrade overflow commits one reset");
|
|
1744
|
+
assert.equal(fixture.requests.length, 3, "one failed small-model request and one recovery request");
|
|
1745
|
+
assert.equal(fixture.session.model?.id, smaller.id, "recovery stays on the selected model");
|
|
1746
|
+
assertFreshRequest(fixture, 2, "LARGE_MODEL_HISTORY");
|
|
1747
|
+
assertFreshRequest(fixture, 2, "CONTINUE_AFTER_MODEL_SWITCH");
|
|
1748
|
+
assert.ok(FORCED_CONTINUATIONS.some((line) => text(fixture.requests[2]).includes(JSON.stringify(line).slice(1, -1))), "recovery uses the forced continuation");
|
|
1749
|
+
assert.ok(fixture.sessionManager.getBranch().some((entry) => entry.type === "message" && JSON.stringify(entry.message).includes("CONTINUE_AFTER_MODEL_SWITCH")), "the latest user request survives in raw history");
|
|
1750
|
+
}
|
|
1751
|
+
finally {
|
|
1752
|
+
fixture.close();
|
|
1753
|
+
}
|
|
1599
1754
|
}
|
|
1600
1755
|
});
|
|
1601
1756
|
test("real AgentSession: concurrent trusted projects keep reserve and automatic policy isolated", async () => {
|
|
@@ -1612,9 +1767,11 @@ test("real AgentSession: concurrent trusted projects keep reserve and automatic
|
|
|
1612
1767
|
let modelInvalidated;
|
|
1613
1768
|
let sessionInvalidated;
|
|
1614
1769
|
const script = (fixture, highUsage) => () => {
|
|
1615
|
-
const
|
|
1770
|
+
const isHigh = highUsage.next;
|
|
1616
1771
|
highUsage.next = false;
|
|
1617
|
-
return
|
|
1772
|
+
return isHigh
|
|
1773
|
+
? assistant(fixture(), [{ type: "toolCall", id: "policy-probe", name: "notes_list", arguments: {} }], "toolUse", { usage: usage(85_000) })
|
|
1774
|
+
: assistant(fixture(), [{ type: "text", text: "policy isolation response" }], "stop", { usage: usage(100) });
|
|
1618
1775
|
};
|
|
1619
1776
|
const automaticUsage = { next: true };
|
|
1620
1777
|
const modelUsage = { next: true };
|
|
@@ -1754,7 +1911,6 @@ test("real AgentSession: injected settings managers own live policy and ignore c
|
|
|
1754
1911
|
await first.session.prompt("INJECTED_LIVE_ENABLE_LOW_RESERVE");
|
|
1755
1912
|
await first.session.waitForIdle();
|
|
1756
1913
|
assert.equal(resetMarkers(first).length, 1, "live enablement and a lower reserve apply on the next turn");
|
|
1757
|
-
firstHighUsage.next = true;
|
|
1758
1914
|
firstManager.applyOverrides({ compaction: { reserveTokens: 80_000 } });
|
|
1759
1915
|
await first.session.prompt("INJECTED_LIVE_HIGH_RESERVE");
|
|
1760
1916
|
await first.session.waitForIdle();
|
|
@@ -2017,7 +2173,7 @@ test("real AgentSession: /notesoup off strips teaching, skills and tools, surviv
|
|
|
2017
2173
|
assert.equal(system?.sections?.notesoup_tools, undefined, "the tool directory section is stripped while off");
|
|
2018
2174
|
const skills = system?.sections?.skills ?? "";
|
|
2019
2175
|
assert.ok(skills.includes("<name>keep-skill</name>"), "a non-notesoup skill survives");
|
|
2020
|
-
assert.equal(skills.includes("<name>notesoup</name>"), false, "notesoup skill is stripped");
|
|
2176
|
+
assert.equal(skills.includes("<name>notesoup-guide</name>"), false, "notesoup-guide skill is stripped");
|
|
2021
2177
|
assert.equal(skills.includes("<name>dream</name>"), false, "notesoup dream skill is stripped");
|
|
2022
2178
|
assert.deepEqual(getCurrentTools(context.messages), [], "all 12 notesoup tools leave the projection");
|
|
2023
2179
|
for (const type of [BOOT_TYPE, MARKER_TYPE, GUIDANCE_TYPE, WARNING_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, MANUAL_WIPE_TYPE]) {
|
|
@@ -493,7 +493,7 @@ test("only forced resets notify, once and after their durable boundary commits",
|
|
|
493
493
|
};
|
|
494
494
|
if (!forced)
|
|
495
495
|
await call(captured, "empty_brain", {}, ctx);
|
|
496
|
-
await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
496
|
+
await commitTurnEndBoundary(captured, sessionManager, ctx, forced ? { stopReason: "toolUse" } : undefined);
|
|
497
497
|
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
498
498
|
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
499
499
|
assert.deepEqual(severities, forced ? ["warning"] : []);
|
|
@@ -575,4 +575,26 @@ test("pi-souls naked state disables notesoup, /notesoup on overrides it, and /so
|
|
|
575
575
|
assert.match((await runCommand(fallbackCaptured, "notesoup", "", fallbackCtx))[0]?.message ?? "", /notesoup off/, "the naked entry disables on its own");
|
|
576
576
|
fallback.appendCustomEntry("pi-souls:naked", { naked: false });
|
|
577
577
|
assert.match((await runCommand(fallbackCaptured, "notesoup", "", fallbackCtx))[0]?.message ?? "", /notesoup on/, "/soul naked off re-enables notesoup when no explicit choice exists");
|
|
578
|
+
// Same contract for pi-souls /soul tools none|rw|reset: live event and durable fallback both disable unless overridden.
|
|
579
|
+
for (const mode of ["none", "rw"]) {
|
|
580
|
+
const restrictedManager = manager();
|
|
581
|
+
const restrictedCaptured = makeExtension(restrictedManager);
|
|
582
|
+
const restrictedCtx = context(restrictedManager);
|
|
583
|
+
restrictedCaptured.events.on("pi-souls:state", (data) => { data.tools = mode; });
|
|
584
|
+
assert.match((await runCommand(restrictedCaptured, "notesoup", "", restrictedCtx))[0]?.message ?? "", /notesoup off/, `tools=${mode} disables notesoup by default`);
|
|
585
|
+
assert.match((await runCommand(restrictedCaptured, "notesoup", "on", restrictedCtx))[0]?.message ?? "", /notesoup on/, `/notesoup on overrides tools=${mode}`);
|
|
586
|
+
}
|
|
587
|
+
fallback.appendCustomEntry("pi-souls:tools", { version: 1, tools: "rw" });
|
|
588
|
+
assert.match((await runCommand(fallbackCaptured, "notesoup", "", fallbackCtx))[0]?.message ?? "", /notesoup off/, "durable tools=rw disables notesoup");
|
|
589
|
+
fallback.appendCustomEntry("pi-souls:tools", { version: 1, tools: "none" });
|
|
590
|
+
assert.match((await runCommand(fallbackCaptured, "notesoup", "", fallbackCtx))[0]?.message ?? "", /notesoup off/, "durable tools=none disables notesoup");
|
|
591
|
+
// Live tools: null means pi-souls answered authoritatively (unrestricted), overriding durable fallback.
|
|
592
|
+
const authoritative = manager();
|
|
593
|
+
authoritative.appendCustomEntry("pi-souls:tools", { version: 1, tools: "none" });
|
|
594
|
+
const authoritativeCaptured = makeExtension(authoritative);
|
|
595
|
+
const authoritativeCtx = context(authoritative);
|
|
596
|
+
authoritativeCaptured.events.on("pi-souls:state", (data) => { data.tools = null; });
|
|
597
|
+
assert.match((await runCommand(authoritativeCaptured, "notesoup", "", authoritativeCtx))[0]?.message ?? "", /notesoup on/, "live tools=null answers authoritatively");
|
|
598
|
+
fallback.appendCustomEntry("pi-souls:tools", { version: 1, tools: null });
|
|
599
|
+
assert.match((await runCommand(fallbackCaptured, "notesoup", "", fallbackCtx))[0]?.message ?? "", /notesoup on/, "/soul tools reset re-enables notesoup");
|
|
578
600
|
});
|
|
@@ -62,8 +62,8 @@ test("Pi cap controls warning, reported room and hard wipe, without changing the
|
|
|
62
62
|
const warning = await runContextHook(captured, at(67_232));
|
|
63
63
|
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE);
|
|
64
64
|
assert.equal(await room(at(83_615)), 1);
|
|
65
|
-
assert.equal((await commitTurnEndBoundary(captured, sm, at(83_615))).entries.some((e) => e.type === "custom" && e.customType === RESET_MARKER_TYPE), false);
|
|
66
|
-
const hard = await commitTurnEndBoundary(captured, sm, at(83_616));
|
|
65
|
+
assert.equal((await commitTurnEndBoundary(captured, sm, at(83_615), { stopReason: "toolUse" })).entries.some((e) => e.type === "custom" && e.customType === RESET_MARKER_TYPE), false);
|
|
66
|
+
const hard = await commitTurnEndBoundary(captured, sm, at(83_616), { stopReason: "toolUse" });
|
|
67
67
|
assert.equal(hard.entries.filter((e) => e.type === "custom" && e.customType === RESET_MARKER_TYPE).length, 1);
|
|
68
68
|
assert.equal(await room(at(1000)), 82_616, "the cap survives a notesoup reset");
|
|
69
69
|
assert.equal(await room(at(1000, 64_000)), 46_616, "a cap cannot enlarge a smaller model window");
|
|
@@ -120,10 +120,10 @@ test("Pi warning, reported room, and hard wipe use the notesoup reserve override
|
|
|
120
120
|
const room = async (remaining) => resultJson(await call(captured, "get_context_remaining", {}, at(remaining))).remaining_tokens;
|
|
121
121
|
assert.equal(await room(24_576), 16_384);
|
|
122
122
|
assert.equal(await room(8193), 1);
|
|
123
|
-
const before = await commitTurnEndBoundary(captured, sm, at(8193));
|
|
123
|
+
const before = await commitTurnEndBoundary(captured, sm, at(8193), { stopReason: "toolUse" });
|
|
124
124
|
assert.equal(before.entries.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE), false, "no wipe above the overridden reserve, even below Pi's reserve");
|
|
125
125
|
assert.equal(await room(8192), 0);
|
|
126
|
-
const hard = await commitTurnEndBoundary(captured, sm, at(8192));
|
|
126
|
+
const hard = await commitTurnEndBoundary(captured, sm, at(8192), { stopReason: "toolUse" });
|
|
127
127
|
assert.equal(hard.entries.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).length, 1, "hard wipe at the overridden reserve");
|
|
128
128
|
});
|
|
129
129
|
test("low-budget guidance and warning persist at turn_end, once per active window", async () => {
|