notesoup 0.47.0 → 0.48.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/src/boot/render.d.ts +14 -7
- package/dist/src/boot/render.js +29 -16
- package/dist/src/boot/text.d.ts +25 -4
- package/dist/src/boot/text.js +59 -11
- package/dist/src/budget/text.d.ts +29 -9
- package/dist/src/budget/text.js +51 -10
- package/dist/src/claude/helper.d.ts +2 -3
- package/dist/src/claude/helper.js +45 -11
- package/dist/src/claude/history.d.ts +9 -0
- package/dist/src/claude/history.js +271 -0
- package/dist/src/dsh/engine.d.ts +2 -1
- package/dist/src/dsh/engine.js +18 -9
- package/dist/src/dsh/index.js +9 -4
- package/dist/src/dsh/window.d.ts +2 -1
- package/dist/src/dsh/window.js +14 -8
- package/dist/src/history/query.js +59 -81
- package/dist/src/notes/address.d.ts +5 -0
- package/dist/src/notes/address.js +20 -21
- package/dist/src/notes/store.js +12 -19
- package/dist/src/pi/boot.d.ts +1 -1
- package/dist/src/pi/boot.js +28 -5
- package/dist/src/pi/budget.d.ts +0 -2
- package/dist/src/pi/budget.js +13 -53
- package/dist/src/pi/entries.d.ts +0 -1
- package/dist/src/pi/entries.js +0 -1
- package/dist/src/pi/history.d.ts +3 -0
- package/dist/src/pi/history.js +4 -0
- package/dist/src/pi/reset/artifacts.d.ts +7 -2
- package/dist/src/pi/reset/artifacts.js +16 -14
- package/dist/src/pi/reset/lifecycle.d.ts +21 -25
- package/dist/src/pi/reset/lifecycle.js +49 -73
- package/dist/src/pi/runtime.js +19 -18
- package/dist/src/pi/window.d.ts +12 -6
- package/dist/src/pi/window.js +7 -0
- package/dist/test/agent-loop.test.js +65 -42
- package/dist/test/boot.integration.test.js +119 -16
- package/dist/test/budget-settings.integration.test.js +4 -2
- package/dist/test/claude-history.test.d.ts +1 -0
- package/dist/test/claude-history.test.js +184 -0
- package/dist/test/claude-mod.test.js +243 -49
- package/dist/test/dsh.test.js +79 -2
- package/dist/test/helpers/extension.d.ts +3 -0
- package/dist/test/helpers/extension.js +33 -5
- package/dist/test/history.integration.test.js +66 -0
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/model-facing-text.test.d.ts +1 -0
- package/dist/test/model-facing-text.test.js +181 -0
- package/dist/test/notes.integration.test.js +16 -18
- package/dist/test/reset-lifecycle.test.js +202 -47
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +15 -3
- package/docs/dsh.md +1 -1
- package/docs/reset-lifecycle.md +32 -20
- package/docs/skills.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +836 -92
- package/mods/notesoup/hooks/register.ts +154 -52
- package/package.json +1 -1
- package/src/boot/render.ts +41 -23
- package/src/boot/text.ts +68 -11
- package/src/budget/text.ts +61 -10
- package/src/claude/helper.ts +53 -22
- package/src/claude/history.ts +228 -0
- package/src/dsh/engine.ts +16 -9
- package/src/dsh/index.ts +8 -3
- package/src/dsh/window.ts +15 -9
- package/src/history/query.ts +57 -82
- package/src/notes/address.ts +19 -16
- package/src/notes/store.ts +9 -14
- package/src/pi/boot.ts +27 -5
- package/src/pi/budget.ts +13 -50
- package/src/pi/entries.ts +0 -1
- package/src/pi/history.ts +7 -2
- package/src/pi/reset/artifacts.ts +17 -14
- package/src/pi/reset/lifecycle.ts +57 -80
- package/src/pi/runtime.ts +19 -18
- package/src/pi/window.ts +11 -1
|
@@ -10,7 +10,7 @@ import { dispatch, handleLine } from "../src/claude/helper.js";
|
|
|
10
10
|
import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../src/claude/thresholds.js";
|
|
11
11
|
import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
|
|
12
12
|
import { PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
|
|
13
|
-
import { CLAUDE_WARNING_PROMPT,
|
|
13
|
+
import { CLAUDE_WARNING_PROMPT, COUNTDOWN_LINE, FORCED_CONTINUATIONS } from "../src/budget/text.js";
|
|
14
14
|
import { createNotesStore } from "../src/notes/index.js";
|
|
15
15
|
import { resolveProjectHome } from "../src/notes/project-home.js";
|
|
16
16
|
import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
|
|
@@ -60,33 +60,58 @@ function fakeEngine(home) {
|
|
|
60
60
|
},
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
test("Claude
|
|
63
|
+
test("Claude notes survive removal of the session's worktree cwd", async (t) => {
|
|
64
|
+
const root = mkdtempSync(join(tmpdir(), "claude-deleted-worktree-"));
|
|
65
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
66
|
+
const repo = join(root, "repo"), home = join(root, "notes"), worktree = join(repo, ".worktrees", "job");
|
|
67
|
+
mkdirSync(repo);
|
|
68
|
+
const git = (...args) => execFileSync("git", args, { cwd: repo, stdio: "pipe" });
|
|
69
|
+
git("init");
|
|
70
|
+
git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "--allow-empty", "-m", "fixture");
|
|
71
|
+
git("worktree", "add", "--detach", worktree);
|
|
72
|
+
const { host } = fakeEngine(home);
|
|
73
|
+
host.session.cwd = async () => worktree;
|
|
74
|
+
const handlers = new Map();
|
|
75
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
76
|
+
await handlers.get("session.start")(host, { cwd: worktree, isInteractive: true }, async () => ({}));
|
|
77
|
+
const call = (tool, params) => handlers.get("tool.call")(host, { tool: `mcp__notesoup__${tool}`, tool_use_id: "probe", ...params }, async () => ({}));
|
|
78
|
+
for (const address of ["task.md", "@project/task.md"]) {
|
|
79
|
+
assert.equal((await call("notes_write", { address, content: "pending" })).isError, undefined);
|
|
80
|
+
}
|
|
81
|
+
git("worktree", "remove", worktree);
|
|
82
|
+
for (const address of ["task.md", "@project/task.md"]) {
|
|
83
|
+
const updated = await call("notes_update", { address, edits: [{ oldText: "pending", newText: "done" }] });
|
|
84
|
+
assert.equal(updated.isError, undefined, updated.result);
|
|
85
|
+
assert.match((await call("notes_read", { address })).result, /done/);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
test("Claude helper exposes the eight shared notes/history schemas", async () => {
|
|
64
89
|
const schemas = await dispatch({ op: "schemas" });
|
|
65
|
-
assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"]);
|
|
90
|
+
assert.deepEqual(schemas.map((schema) => schema.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
|
|
66
91
|
assert.ok(schemas.every((schema) => schema.description.length > 20 && schema.inputSchema.type === "object"));
|
|
67
92
|
});
|
|
68
|
-
test("Claude helper delivers
|
|
93
|
+
test("Claude helper delivers only shared rendered text and success", async () => {
|
|
69
94
|
const write = await callTool("notes_write", { address: "checkpoint.md", content: "hello" });
|
|
70
|
-
assert.equal(write.
|
|
95
|
+
assert.equal(write.ok, true);
|
|
71
96
|
assert.match(write.text, /checkpoint\.md/);
|
|
72
97
|
assert.equal(write.text.includes("READ WINDOW"), false, "Claude reads the same presentation as Pi");
|
|
73
98
|
const missing = await callTool("notes_read", { address: "absent.md" });
|
|
74
|
-
assert.equal(missing.
|
|
75
|
-
assert.
|
|
99
|
+
assert.equal(missing.ok, false);
|
|
100
|
+
assert.deepEqual(Object.keys(missing).sort(), ["ok", "text"]);
|
|
76
101
|
assert.match(missing.text, /^error: not_found: /, "the refusal renders as the shared error line");
|
|
77
102
|
});
|
|
78
103
|
test("Claude helper rejects malformed or unknown requests", async () => {
|
|
79
104
|
const malformed = JSON.parse(await handleLine("not json"));
|
|
80
105
|
assert.equal(malformed.ok, false);
|
|
81
106
|
assert.match(malformed.error, /Unexpected|malformed/);
|
|
82
|
-
const unknown = JSON.parse(await handleLine(JSON.stringify({ op: "tool", tool: "
|
|
107
|
+
const unknown = JSON.parse(await handleLine(JSON.stringify({ op: "tool", tool: "history_search", identity, params: {} })));
|
|
83
108
|
assert.equal(unknown.ok, false);
|
|
84
109
|
assert.equal(unknown.error, "unknown tool");
|
|
85
110
|
});
|
|
86
111
|
test("Claude helper refuses schema-invalid parameters before any operation runs", async () => {
|
|
87
112
|
const address = "boundary.md";
|
|
88
113
|
const written = await callTool("notes_write", { address, content: "boundary body" });
|
|
89
|
-
assert.equal(written.
|
|
114
|
+
assert.equal(written.ok, true, "the fixture note exists before anything is refused");
|
|
90
115
|
const cases = [
|
|
91
116
|
{ name: "a string offset", params: { address, offset_chars: "0" } },
|
|
92
117
|
{ name: "a fractional offset", params: { address, offset_chars: 0.5 } },
|
|
@@ -102,10 +127,10 @@ test("Claude helper refuses schema-invalid parameters before any operation runs"
|
|
|
102
127
|
// Refusal happens before execute: a rejected mutation leaves nothing on disk.
|
|
103
128
|
await assert.rejects(callTool("notes_write", { address: "rejected.md", content: 42 }), /invalid notes_write parameters/);
|
|
104
129
|
const absent = await callTool("notes_read", { address: "rejected.md" });
|
|
105
|
-
assert.equal(absent.
|
|
106
|
-
assert.
|
|
130
|
+
assert.equal(absent.ok, false);
|
|
131
|
+
assert.match(absent.text, /^error: not_found: /, "the refused write never reached the store");
|
|
107
132
|
const valid = await callTool("notes_read", { address, offset_chars: 0, max_chars: 8 });
|
|
108
|
-
assert.equal(valid.
|
|
133
|
+
assert.equal(valid.ok, true, "a schema-valid window still reads");
|
|
109
134
|
assert.match(valid.text, /^boundary\.md/);
|
|
110
135
|
});
|
|
111
136
|
test("Claude helper boot uses actual Claude note tool bindings and a fresh snapshot", async () => {
|
|
@@ -116,14 +141,25 @@ test("Claude helper boot uses actual Claude note tool bindings and a fresh snaps
|
|
|
116
141
|
} });
|
|
117
142
|
assert.match(boot, /mcp__notesoup__notes_\*/);
|
|
118
143
|
assert.match(boot, /claude:session/);
|
|
119
|
-
assert.doesNotMatch(boot, /
|
|
144
|
+
assert.doesNotMatch(boot, /brain empty|continuation/);
|
|
145
|
+
assert.equal(boot.includes("chat view"), false, "a Claude boot never claims a reset clears the human's view");
|
|
120
146
|
});
|
|
121
147
|
test("Claude helper serves the shared reset prose and the host's wipe sentence", async () => {
|
|
122
148
|
const texts = await dispatch({ op: "texts" });
|
|
123
149
|
assert.equal(texts.warning, CLAUDE_WARNING_PROMPT, "the helper owns the one warning text the mod shows");
|
|
124
|
-
assert.equal(texts.continuation, CONTINUATION, "the reset message is Pi's, verbatim");
|
|
125
150
|
assert.equal(texts.wipeSentence, CLAUDE_WIPE_SENTENCE);
|
|
126
|
-
assert.match(texts.warning, /end your turn; the reset runs after it
|
|
151
|
+
assert.match(texts.warning, /end your turn; the reset runs after it\./);
|
|
152
|
+
assert.equal(texts.warning.endsWith(COUNTDOWN_LINE), true, "the Claude notice also ends with the countdown");
|
|
153
|
+
assert.equal(texts.continuation, undefined, "a plain text read never draws the reset handoff");
|
|
154
|
+
const random = Math.random;
|
|
155
|
+
Math.random = () => 0;
|
|
156
|
+
try {
|
|
157
|
+
assert.deepEqual(await dispatch({ op: "continuation", origin: "forced" }), { text: FORCED_CONTINUATIONS[0] }, "Claude's system-triggered reset draws the forced pool");
|
|
158
|
+
await assert.rejects(dispatch({ op: "continuation", origin: "user" }), /invalid reset origin/, "a third origin is refused, not invented");
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
Math.random = random;
|
|
162
|
+
}
|
|
127
163
|
});
|
|
128
164
|
/** The point values the resolver produced, without the margin bookkeeping. */
|
|
129
165
|
function limitPoints(facts) {
|
|
@@ -214,7 +250,7 @@ test("Claude Mod helper runs from a standalone copied plugin directory", () => {
|
|
|
214
250
|
}));
|
|
215
251
|
const schemas = run('{"op":"schemas"}');
|
|
216
252
|
assert.equal(schemas.ok, true);
|
|
217
|
-
assert.equal(schemas.result?.length,
|
|
253
|
+
assert.equal(schemas.result?.length, 8);
|
|
218
254
|
assert.equal(run("not json").ok, false);
|
|
219
255
|
}
|
|
220
256
|
finally {
|
|
@@ -254,6 +290,7 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
|
|
|
254
290
|
assert.match(boot.text, /mcp__notesoup__notes_\*/, "the boot text names the actual Claude note tool binding");
|
|
255
291
|
assert.ok(boot.text.includes(CLAUDE_WIPE_SENTENCE), "the boot speaks the Claude wipe path");
|
|
256
292
|
assert.equal(boot.text.includes("erase yourself with dignity"), false);
|
|
293
|
+
assert.equal(boot.text.includes("chat view"), false, "the Claude boot block carries no Pi-only pre-reset hints");
|
|
257
294
|
assert.equal(first.sentinel, "kept", "unrelated result fields survive");
|
|
258
295
|
assert.equal(bootRequests, 1, "the first prompt makes exactly one boot helper request");
|
|
259
296
|
assert.equal(nextCalls, 1, "the upstream chain runs exactly once per prompt");
|
|
@@ -303,7 +340,7 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
303
340
|
...upstream,
|
|
304
341
|
blocks: [...upstream.blocks, { name: "notesoup:boot", text: "# notesoup\nYour notes didn't load this time (helper exited unsuccessfully). Try `mcp__notesoup__notes_list`; if it fails too, tell the human." }],
|
|
305
342
|
}, "boot failure keeps the original fallback and upstream fields even if notify is absent or fails");
|
|
306
|
-
const expectedNotifications = mode === "no ui" || mode === "no toast" ? [] : ["🥣 Notes
|
|
343
|
+
const expectedNotifications = mode === "no ui" || mode === "no toast" ? [] : ["🥣 Notes went missing"];
|
|
307
344
|
assert.deepEqual(notifications, expectedNotifications, "one user-facing notification reports the notes boot failure");
|
|
308
345
|
assert.equal(bootRequests, 1);
|
|
309
346
|
assert.equal(nextCalls, 1);
|
|
@@ -322,7 +359,7 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
322
359
|
const handlers = new Map();
|
|
323
360
|
hooks.register((event, handler) => handlers.set(event, handler));
|
|
324
361
|
await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async (event) => event);
|
|
325
|
-
assert.deepEqual(registered.map((spec) => spec.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"]);
|
|
362
|
+
assert.deepEqual(registered.map((spec) => spec.name), ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search", "history_list", "history_read", "history_windows"]);
|
|
326
363
|
for (const spec of registered) {
|
|
327
364
|
assert.equal(spec.isDeferred, false, `${spec.name} is available from the start without tool search`);
|
|
328
365
|
assert.ok(spec.description.length > 20);
|
|
@@ -338,6 +375,13 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
338
375
|
// A tool this plugin never registered is somebody else's answer, not a notesoup refusal.
|
|
339
376
|
const foreign = await call("other_tool", {});
|
|
340
377
|
assert.equal("result" in foreign, false, "an unregistered tool falls through to the engine's own handling");
|
|
378
|
+
// A rejected host call is the only diagnosis there is, so its reason must reach the model.
|
|
379
|
+
const ran = host.process.run;
|
|
380
|
+
host.process.run = async () => { throw new Error("spawn timed out after 10000ms"); };
|
|
381
|
+
const crashed = await call("notes_write", { address: "hook.md", content: "again" });
|
|
382
|
+
host.process.run = ran;
|
|
383
|
+
assert.equal(crashed.isError, true);
|
|
384
|
+
assert.match(String(crashed.result), /^notesoup: helper execution failed: Error: spawn timed out after 10000ms$/, "the host's own reason survives the catch");
|
|
341
385
|
});
|
|
342
386
|
test("Claude Mod resets at Claude's resolved point after the turn, retains one fresh boot and deduplicates measure", async (t) => {
|
|
343
387
|
const home = mkdtempSync(join(tmpdir(), "claude-reset-home-"));
|
|
@@ -360,7 +404,7 @@ test("Claude Mod resets at Claude's resolved point after the turn, retains one f
|
|
|
360
404
|
return result;
|
|
361
405
|
};
|
|
362
406
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
363
|
-
assert.equal(registered.length,
|
|
407
|
+
assert.equal(registered.length, 8);
|
|
364
408
|
const initial = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
365
409
|
assert.equal(initial.blocks.length, 1, "below the warn point no warning joins the boot");
|
|
366
410
|
assert.match(initial.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
@@ -371,7 +415,7 @@ test("Claude Mod resets at Claude's resolved point after the turn, retains one f
|
|
|
371
415
|
host.session.usage = async () => { throw new Error("usage unavailable"); };
|
|
372
416
|
await invoke("session.measure");
|
|
373
417
|
await invoke("turn.complete");
|
|
374
|
-
assert.equal(notifications.filter((text) => text.includes("
|
|
418
|
+
assert.equal(notifications.filter((text) => text.includes("Brain fullness unknown")).length, 1, "usage failure logs once per session");
|
|
375
419
|
host.session.usage = async () => measured();
|
|
376
420
|
await dispatch({ op: "tool", tool: "notes_write", identity: { ...identity, home, cwd: home, sessionId: "hook-session" }, params: { address: "@human/MAP.md", content: "FRESH_NOTES_AT_RESET" } });
|
|
377
421
|
await invoke("turn.start");
|
|
@@ -390,7 +434,7 @@ test("Claude Mod resets at Claude's resolved point after the turn, retains one f
|
|
|
390
434
|
assert.match(kept[0].text, /Previous context window id: claude:hook-session:0/);
|
|
391
435
|
assert.match(kept[0].text, /FRESH_NOTES_AT_RESET/);
|
|
392
436
|
assert.doesNotMatch(kept[0].text, /OLD_SECRET/);
|
|
393
|
-
assert.
|
|
437
|
+
assert.ok(FORCED_CONTINUATIONS.includes(kept[1].text), "the handoff comes from the shared forced pool");
|
|
394
438
|
await invoke("session.measure");
|
|
395
439
|
assert.equal(compactions, 1, "invalidated tokens cannot immediately reset twice");
|
|
396
440
|
const upstream = { blocks: [{ name: "unrelated", text: "leave this alone" }], sentinel: "kept" };
|
|
@@ -418,13 +462,32 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
|
|
|
418
462
|
await invoke("session.measure");
|
|
419
463
|
await invoke("turn.complete");
|
|
420
464
|
assert.equal(attempts, 0, "headless sessions skip the unsupported capability from startup");
|
|
421
|
-
assert.deepEqual(notifications, ["🥣
|
|
465
|
+
assert.deepEqual(notifications, ["🥣 No brain when headless"]);
|
|
422
466
|
const manual = await invoke("command.run", { command: "empty-brain" });
|
|
423
|
-
assert.match(manual.text, /
|
|
467
|
+
assert.match(manual.text, /No brain when headless/);
|
|
424
468
|
assert.equal(notifications.length, 1);
|
|
425
469
|
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
426
470
|
assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
427
471
|
});
|
|
472
|
+
test("Claude Mod keeps its window numbering from a boot written before the tag rename", async (t) => {
|
|
473
|
+
const home = mkdtempSync(join(tmpdir(), "claude-legacy-boot-"));
|
|
474
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
475
|
+
const { host } = fakeEngine(home);
|
|
476
|
+
const handlers = new Map();
|
|
477
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
478
|
+
const invoke = (name, event = {}, next = async () => ({ sentinel: name })) => handlers.get(name)(host, event, next);
|
|
479
|
+
const boot = (spelling) => `<${spelling}>\nAgent name: claude (brain: claude)\n\nhook-session\n</${spelling}>\n\nCurrent context window id: claude:hook-session:3`;
|
|
480
|
+
for (const spelling of ["context_window", "notesoup:window_identity"]) {
|
|
481
|
+
const text = boot(spelling);
|
|
482
|
+
host.session.messages = async () => [{ role: "user", text }];
|
|
483
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
484
|
+
// A recognised retained boot is not injected a second time into prompt context.
|
|
485
|
+
const context = await invoke("prompt.context", {}, async () => ({ blocks: [] }));
|
|
486
|
+
assert.deepEqual(context.blocks, [], `${spelling} is recognised as this session's retained boot`);
|
|
487
|
+
const compacted = await invoke("session.compact", { trigger: "auto", instructions: "", messages: [] });
|
|
488
|
+
assert.match(compacted.messages[0].text, /Current context window id: claude:hook-session:4/, `${spelling} keeps its window ordinal`);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
428
491
|
test("Claude Mod refuses to wipe on boot failure and can retry without advancing the window", async (t) => {
|
|
429
492
|
const home = mkdtempSync(join(tmpdir(), "claude-reset-failure-"));
|
|
430
493
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
@@ -453,7 +516,7 @@ test("Claude Mod refuses to wipe on boot failure and can retry without advancing
|
|
|
453
516
|
assert.equal(result.skip, undefined);
|
|
454
517
|
assert.equal(result.messages.length, 2);
|
|
455
518
|
assert.match(result.messages[0].text, /Current context window id: claude:hook-session:1/, "a failed reset never consumes a window ordinal");
|
|
456
|
-
assert.
|
|
519
|
+
assert.ok(FORCED_CONTINUATIONS.includes(result.messages[1].text));
|
|
457
520
|
});
|
|
458
521
|
test("Claude Mod manual reset uses one hidden close-out turn, then recovers its boot on reload", async (t) => {
|
|
459
522
|
const home = mkdtempSync(join(tmpdir(), "claude-manual-home-"));
|
|
@@ -480,7 +543,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
480
543
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
481
544
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
482
545
|
const command = await invoke("command.run", { command: "empty-brain" });
|
|
483
|
-
assert.match(command.text, /
|
|
546
|
+
assert.match(command.text, /Brain being emptied/);
|
|
484
547
|
await Promise.resolve();
|
|
485
548
|
assert.equal(compactions, 0, "command.run must not call compact under its held turn");
|
|
486
549
|
assert.equal(timers.length, 1);
|
|
@@ -490,7 +553,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
490
553
|
assert.equal(compactions, 1);
|
|
491
554
|
assert.equal(kept.length, 2);
|
|
492
555
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:1/);
|
|
493
|
-
assert.
|
|
556
|
+
assert.ok(FORCED_CONTINUATIONS.includes(kept[1].text));
|
|
494
557
|
host.session.messages = async () => [{ role: "user", text: "OLD_SECRET" }, ...kept];
|
|
495
558
|
handlers = new Map();
|
|
496
559
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
@@ -595,7 +658,7 @@ test("Claude Mod skips the automatic reset when thresholds cannot be resolved",
|
|
|
595
658
|
await invoke("turn.complete");
|
|
596
659
|
await invoke("session.measure");
|
|
597
660
|
assert.equal(compactions, 0, "an unresolvable point never resets");
|
|
598
|
-
assert.equal(notifications.filter((text) => text.includes("
|
|
661
|
+
assert.equal(notifications.filter((text) => text.includes("Brain size unknown")).length, 1, "one line, not one per turn");
|
|
599
662
|
});
|
|
600
663
|
test("Claude skill projections stay byte-identical to canonical shared files", () => {
|
|
601
664
|
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/skills/memory/SKILL.md")), readFileSync(join(process.cwd(), "skills/memory/SKILL.md")));
|
|
@@ -681,12 +744,49 @@ async function retainedFixture(t) {
|
|
|
681
744
|
host.session.messages = async () => [{ role: "user", text: `# notesoup:boot\n${boot}` }];
|
|
682
745
|
const handlers = new Map();
|
|
683
746
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
684
|
-
const invoke = (name, e = {}, result = {}) => handlers.get(name)(host, e, async () => result);
|
|
747
|
+
const invoke = (name, e = {}, result = {}, next) => handlers.get(name)(host, e, next ?? (async () => result));
|
|
685
748
|
const context = async () => await invoke("prompt.context", {}, { blocks: [] });
|
|
686
749
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
687
750
|
assert.deepEqual((await context()).blocks, [], "the existing boot is retained, not injected twice");
|
|
688
751
|
return { home, host, invoke, context, boot };
|
|
689
752
|
}
|
|
753
|
+
test("Claude asks for one handoff per compaction and reuses it when the same window retries", async (t) => {
|
|
754
|
+
const { host, invoke } = await retainedFixture(t);
|
|
755
|
+
const run = host.process.run;
|
|
756
|
+
const draws = [];
|
|
757
|
+
host.process.run = async (argv, init) => {
|
|
758
|
+
const request = init?.stdin ? JSON.parse(init.stdin) : {};
|
|
759
|
+
if (request.op === "continuation")
|
|
760
|
+
draws.push(init?.stdin);
|
|
761
|
+
return run(argv, init);
|
|
762
|
+
};
|
|
763
|
+
// Every read path stays pure: no boot, warning, context, or measure draws a handoff.
|
|
764
|
+
await invoke("prompt.context", {}, { blocks: [] });
|
|
765
|
+
await invoke("session.measure");
|
|
766
|
+
await invoke("turn.start");
|
|
767
|
+
await invoke("turn.complete");
|
|
768
|
+
assert.equal(draws.length, 0, "only a reset draws, never a read");
|
|
769
|
+
const timers = [];
|
|
770
|
+
const lines = [];
|
|
771
|
+
host.clock.after = (_ms, callback) => { timers.push(callback); };
|
|
772
|
+
host.prompt.submit = async () => { await invoke("turn.start"); };
|
|
773
|
+
// The host retries one plugin compaction for the same window: one artifact, one draw.
|
|
774
|
+
host.session.compact = async ({ instructions }) => {
|
|
775
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
776
|
+
const result = await invoke("session.compact", { trigger: "plugin", instructions: instructions ?? "" });
|
|
777
|
+
lines.push(result.messages[1].text);
|
|
778
|
+
}
|
|
779
|
+
return { skip: "test default" };
|
|
780
|
+
};
|
|
781
|
+
assert.match((await invoke("command.run", { command: "fresh-window", args: "" })).text, /Brain being emptied/);
|
|
782
|
+
await Promise.resolve();
|
|
783
|
+
await timers.shift()();
|
|
784
|
+
await invoke("turn.complete");
|
|
785
|
+
assert.equal(draws.length, 1, "a retried compaction adds no second draw");
|
|
786
|
+
assert.equal(lines.length, 2, "both attempts returned a handoff");
|
|
787
|
+
assert.equal(lines[0], lines[1], "both attempts carry the same artifact's paragraph");
|
|
788
|
+
assert.ok(FORCED_CONTINUATIONS.includes(lines[0]), "Claude has no model reset tool, so its pool is always the forced one");
|
|
789
|
+
});
|
|
690
790
|
test("Claude session.end gives /clear, /resume and /branch a fresh boot and identity", async (t) => {
|
|
691
791
|
for (const action of ["clear", "resume", "branch"]) {
|
|
692
792
|
await t.test(action, async (t) => {
|
|
@@ -725,27 +825,64 @@ test("Claude lazy identity detects a switched session without session.start or s
|
|
|
725
825
|
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
726
826
|
assert.match(fresh.blocks[0].text, /Current context window id: claude:lazy-session:0/);
|
|
727
827
|
});
|
|
728
|
-
test("Claude native compaction
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const {
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
828
|
+
test("Claude native compaction becomes a notes-only reset, a veto, or a pass-through", async (t) => {
|
|
829
|
+
await t.test("manual and precompute are vetoed before upstream", async (t) => {
|
|
830
|
+
for (const [trigger, pattern] of [["manual", /No compacting brains here/], ["precompute", /No precomputing brains here/]]) {
|
|
831
|
+
const { invoke, context } = await retainedFixture(t);
|
|
832
|
+
let upstreamCalls = 0;
|
|
833
|
+
const result = await invoke("session.compact", { trigger, messages: [{ role: "user", text: "OLD" }] }, {}, async () => { upstreamCalls++; return { messages: [{ role: "user", text: "SUMMARY" }] }; });
|
|
834
|
+
assert.equal(upstreamCalls, 0, `${trigger} never runs the summarizer`);
|
|
835
|
+
assert.match(result.skip, pattern);
|
|
836
|
+
assert.equal(result.messages, undefined);
|
|
837
|
+
assert.deepEqual((await context()).blocks, [], "the retained boot is untouched");
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
await t.test("auto becomes the next window's notes boot", async (t) => {
|
|
841
|
+
const { invoke } = await retainedFixture(t);
|
|
842
|
+
let upstreamCalls = 0;
|
|
843
|
+
const result = await invoke("session.compact", { trigger: "auto", messages: [{ role: "user", text: "OLD" }] }, {}, async () => { upstreamCalls++; return { messages: [{ role: "user", text: "SUMMARY" }] }; });
|
|
844
|
+
assert.equal(upstreamCalls, 0, "an automatic compaction never runs the summarizer");
|
|
845
|
+
assert.equal(result.messages.length, 2);
|
|
846
|
+
assert.match(result.messages[0].text, /Current context window id: claude:hook-session:3/);
|
|
847
|
+
assert.doesNotMatch(result.messages[0].text, /OLD/);
|
|
848
|
+
assert.ok(FORCED_CONTINUATIONS.includes(result.messages[1].text));
|
|
849
|
+
const upstream = { blocks: [{ name: "claude:user-context", text: "upstream" }] };
|
|
850
|
+
const context = await invoke("prompt.context", {}, upstream);
|
|
851
|
+
assert.deepEqual(context.blocks, upstream.blocks, "the hijacked boot is retained, not injected again");
|
|
852
|
+
});
|
|
853
|
+
await t.test("a failed auto build falls back to native compaction", async (t) => {
|
|
854
|
+
const { host, invoke } = await retainedFixture(t);
|
|
855
|
+
const run = host.process.run;
|
|
856
|
+
host.process.run = async (argv, init) => JSON.parse(init.stdin).op === "boot" ? { exitCode: 1, stdout: "" } : run(argv, init);
|
|
857
|
+
const upstream = { messages: [{ role: "user", text: "SUMMARY" }], sentinel: "native" };
|
|
858
|
+
let upstreamCalls = 0;
|
|
859
|
+
const result = await invoke("session.compact", { trigger: "auto", messages: [{ role: "user", text: "OLD" }] }, upstream, async () => { upstreamCalls++; return upstream; });
|
|
860
|
+
assert.equal(upstreamCalls, 1, "an over-long prompt still compacts natively");
|
|
861
|
+
assert.equal(result, upstream);
|
|
862
|
+
});
|
|
863
|
+
await t.test("foreign plugin, veto, subagent and kept boot still pass through", async (t) => {
|
|
864
|
+
for (const mode of ["foreign plugin", "veto", "subagent", "kept boot"]) {
|
|
865
|
+
await t.test(mode, async (t) => {
|
|
866
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
867
|
+
const event = { trigger: mode === "subagent" ? "manual" : "plugin", messages: [{ role: "user", text: "OLD" }], ...(mode === "subagent" ? { agentId: "child" } : {}) };
|
|
868
|
+
const upstream = mode === "veto" ? { skip: "user veto" } : {
|
|
869
|
+
messages: mode === "kept boot" ? await host.session.messages() : [{ role: "user", text: "SUMMARY" }], sentinel: mode,
|
|
870
|
+
};
|
|
871
|
+
let upstreamCalls = 0;
|
|
872
|
+
const result = await invoke("session.compact", event, upstream, async () => { upstreamCalls++; return upstream; });
|
|
873
|
+
assert.equal(upstreamCalls, 1, "the engine's compaction is passed through");
|
|
874
|
+
assert.equal(result, upstream);
|
|
875
|
+
const after = await context();
|
|
876
|
+
if (mode === "foreign plugin") {
|
|
877
|
+
assert.deepEqual(after.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
878
|
+
assert.match(after.blocks[0].text, /Current context window id: claude:hook-session:2/);
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
assert.deepEqual(after.blocks, [], "veto, subagent and kept boot leave the main boot alone");
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
});
|
|
749
886
|
});
|
|
750
887
|
test("Claude serves every registered notes tool to subagents without leaking event fields into params", async (t) => {
|
|
751
888
|
const { invoke } = await retainedFixture(t);
|
|
@@ -835,3 +972,60 @@ test("Claude session.end cannot be undone by an in-flight old reset", async (t)
|
|
|
835
972
|
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
836
973
|
assert.match(fresh.blocks[0].text, /Current context window id: claude:after-flight:0/);
|
|
837
974
|
});
|
|
975
|
+
test("Claude history keeps classic transcript_path across startup, confirms append heads, and refuses subagent leakage", async (t) => {
|
|
976
|
+
const home = mkdtempSync(join(tmpdir(), "claude-history-hook-"));
|
|
977
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
978
|
+
const { host, registered } = fakeEngine(home);
|
|
979
|
+
const handlers = new Map();
|
|
980
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
981
|
+
const invoke = (name, event = {}, result = {}) => handlers.get(name)(host, event, async () => result);
|
|
982
|
+
const transcriptPath = join(home, "transcript.jsonl");
|
|
983
|
+
const root = { type: "user", uuid: "root", parentUuid: null, sessionId: "hook-session", message: { role: "user", content: "old request" } };
|
|
984
|
+
const attachment = { type: "attachment", uuid: "startup", parentUuid: "root", sessionId: "hook-session", rendered: [{ content: [{ type: "text", text: "startup injection" }] }] };
|
|
985
|
+
const sibling = { type: "assistant", uuid: "sibling", parentUuid: "root", sessionId: "hook-session", message: { role: "assistant", content: "another branch" } };
|
|
986
|
+
writeFileSync(transcriptPath, [root, attachment, sibling].map((row) => JSON.stringify(row)).join("\n") + "\n");
|
|
987
|
+
const call = (tool, params = {}, agentId) => invoke("tool.call", { tool: `mcp__notesoup__${tool}`, tool_use_id: "probe", ...params, ...(agentId ? { agentId } : {}) });
|
|
988
|
+
await invoke("classic.SessionStart", { session_id: "hook-session", transcript_path: transcriptPath, source: "startup" });
|
|
989
|
+
// Real order: classic -> startup attachment appends -> typed session.start.
|
|
990
|
+
await invoke("session.append", { uuid: "startup" }, { uuid: "startup", message: {} });
|
|
991
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
992
|
+
assert.equal(registered.length, 8);
|
|
993
|
+
const listed = await call("history_list", { roles: ["user", "context"] });
|
|
994
|
+
assert.equal(listed.isError, undefined, listed.result);
|
|
995
|
+
assert.match(listed.result, /old request/);
|
|
996
|
+
assert.match(listed.result, /startup injection/);
|
|
997
|
+
assert.doesNotMatch(listed.result, /another branch/);
|
|
998
|
+
const boot = await invoke("prompt.context", {}, { blocks: [] });
|
|
999
|
+
assert.match(boot.blocks[0].text, /mcp__notesoup__history_\*/);
|
|
1000
|
+
const subagent = await call("history_list", {}, "worker");
|
|
1001
|
+
assert.equal(subagent.isError, true);
|
|
1002
|
+
assert.match(subagent.result, /unavailable for subagents/);
|
|
1003
|
+
// Subagent classic payloads/append results must not overwrite the main binding.
|
|
1004
|
+
await invoke("classic.SessionStart", { session_id: "hook-session", transcript_path: "/wrong/subagent.jsonl", source: "startup", agent_id: "worker" });
|
|
1005
|
+
await invoke("session.append", { uuid: "subagent", agentId: "worker" }, { uuid: "subagent" });
|
|
1006
|
+
assert.equal((await call("history_read", { seq: 1 })).isError, undefined);
|
|
1007
|
+
// A resumed head is not supplied by SessionStart or messages(); don't use the last file row.
|
|
1008
|
+
await invoke("classic.SessionStart", { session_id: "hook-session", transcript_path: transcriptPath, source: "resume" });
|
|
1009
|
+
const beforeAppend = await call("history_list");
|
|
1010
|
+
assert.equal(beforeAppend.isError, true);
|
|
1011
|
+
assert.match(beforeAppend.result, /no confirmed active head/);
|
|
1012
|
+
await invoke("session.append", { uuid: "sibling" }, { uuid: "sibling" });
|
|
1013
|
+
const switched = await call("history_list");
|
|
1014
|
+
assert.match(switched.result, /another branch/);
|
|
1015
|
+
assert.doesNotMatch(switched.result, /startup injection/);
|
|
1016
|
+
});
|
|
1017
|
+
test("Claude history without a documented path refuses honestly and keeps notes usable", async (t) => {
|
|
1018
|
+
const home = mkdtempSync(join(tmpdir(), "claude-no-history-path-"));
|
|
1019
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
1020
|
+
const { host } = fakeEngine(home);
|
|
1021
|
+
const handlers = new Map();
|
|
1022
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
1023
|
+
await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async () => ({}));
|
|
1024
|
+
const history = await handlers.get("tool.call")(host, { tool: "mcp__notesoup__history_windows", tool_use_id: "history" }, async () => ({}));
|
|
1025
|
+
assert.equal(history.isError, true);
|
|
1026
|
+
assert.match(history.result, /transcript_path is unavailable/);
|
|
1027
|
+
const notes = await handlers.get("tool.call")(host, { tool: "mcp__notesoup__notes_list", tool_use_id: "notes" }, async () => ({}));
|
|
1028
|
+
assert.equal(notes.isError, undefined);
|
|
1029
|
+
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
1030
|
+
assert.match(boot.blocks[0].text, /History isn't available.*no main transcript_path/);
|
|
1031
|
+
});
|
package/dist/test/dsh.test.js
CHANGED
|
@@ -2,13 +2,14 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { createUserMessage, HarnessError, ToolCallId } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import { Session, SessionId, SessionSeq, pluginRecordOf } from "@deepseek-ai/dsh-session";
|
|
5
|
-
import { allItems } from "../src/history/history.js";
|
|
5
|
+
import { allItems, contentText } from "../src/history/history.js";
|
|
6
6
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { resolveProjectHome } from "../src/notes/project-home.js";
|
|
10
10
|
import { renderBootBlock } from "../src/boot/render.js";
|
|
11
11
|
import { loadNotesSnapshot } from "../src/boot/snapshot.js";
|
|
12
|
+
import { WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG } from "../src/boot/text.js";
|
|
12
13
|
import { notesRead } from "../src/tools/notes.js";
|
|
13
14
|
import { success } from "../src/tools/result.js";
|
|
14
15
|
import { createNotesStore } from "../src/notes/index.js";
|
|
@@ -16,6 +17,7 @@ import { dshFixture } from "./helpers/dsh.js";
|
|
|
16
17
|
import { decodeHistory } from "../src/dsh/history.js";
|
|
17
18
|
import { checkpointSnapshot, notesIdentity, recoverSnapshot, WINDOW_RECORD } from "../src/dsh/window.js";
|
|
18
19
|
import { measureBudget } from "../src/dsh/budget.js";
|
|
20
|
+
import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, NORMAL_CONTINUATIONS } from "../src/budget/text.js";
|
|
19
21
|
import { preflight } from "../src/dsh/engine.js";
|
|
20
22
|
import { BasicCompactionEngine } from "@deepseek-ai/dsh-compaction-basic";
|
|
21
23
|
function prompt(text) { return createUserMessage({ content: [{ type: "text", text }], source: { kind: "user" } }); }
|
|
@@ -83,6 +85,43 @@ test("dsh reload adopts persisted bytes before first assembly; missing records r
|
|
|
83
85
|
assert.equal(engine.windows.get(rootReloaded.session).snapshot.boot, rootBoot);
|
|
84
86
|
assert.equal(engine.windows.get(rootReloaded.session).snapshot.window, 0);
|
|
85
87
|
});
|
|
88
|
+
test("dsh reload keeps its window ordinal from a boot written before the tag rename", async (t) => {
|
|
89
|
+
const { engine, create, mock } = await dshFixture(t);
|
|
90
|
+
const agent = await create();
|
|
91
|
+
mock.script.push({ tool: "empty_brain", input: {} }, { text: "after" });
|
|
92
|
+
await run(agent, "before");
|
|
93
|
+
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
94
|
+
assert.ok(snapshot.boot.includes(WINDOW_IDENTITY_OPEN_TAG), "the current boot carries the renamed tag");
|
|
95
|
+
const legacy = withLegacyIdentityTags(withoutRecords(agent.session.snapshotEvents()));
|
|
96
|
+
assert.ok(JSON.stringify(legacy).includes("<context_window>\\nAgent name: dsh"), "the seed reproduces an old-spelling boot");
|
|
97
|
+
const resumed = await create(legacy, "session-legacy-tags");
|
|
98
|
+
await run(resumed, "continue");
|
|
99
|
+
assert.equal(engine.windows.get(resumed.session).snapshot.window, 1, "an old-tag boot still yields its window ordinal");
|
|
100
|
+
assert.equal(engine.windows.get(resumed.session).snapshot.windowId, snapshot.windowId, "and its window id");
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* The same seed with the pre-rename identity spelling: boots already on disk carry `context_window`,
|
|
104
|
+
* so a reader that only knows the new tag would silently lose their window numbering.
|
|
105
|
+
*/
|
|
106
|
+
function withLegacyIdentityTags(events) {
|
|
107
|
+
const legacy = (text) => text
|
|
108
|
+
.replaceAll(WINDOW_IDENTITY_OPEN_TAG, "<context_window>")
|
|
109
|
+
.replaceAll(WINDOW_IDENTITY_CLOSE_TAG, "</context_window>");
|
|
110
|
+
return events.map((event) => {
|
|
111
|
+
const copy = structuredClone(event);
|
|
112
|
+
if (copy.type !== "user/message")
|
|
113
|
+
return copy;
|
|
114
|
+
const data = copy.data;
|
|
115
|
+
if (typeof data.content === "string")
|
|
116
|
+
data.content = legacy(data.content);
|
|
117
|
+
else if (Array.isArray(data.content))
|
|
118
|
+
for (const block of data.content) {
|
|
119
|
+
if (typeof block.text === "string")
|
|
120
|
+
block.text = legacy(block.text);
|
|
121
|
+
}
|
|
122
|
+
return copy;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
86
125
|
/** Removal models migration loss: native references and contiguous seqs are remapped. */
|
|
87
126
|
function withoutRecords(events) {
|
|
88
127
|
const keep = events.filter((event) => !pluginRecordOf(event));
|
|
@@ -199,11 +238,49 @@ test("dsh budget follows configured host reserve, close-out tool runs across ste
|
|
|
199
238
|
await run(agent, "continue");
|
|
200
239
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 1);
|
|
201
240
|
assert.equal(agent.session.snapshotEvents().filter((event) => event.type === "user/message" && event.data.source.kind === "notesoup-budget" && event.data.source.phase === "warning").length, 1);
|
|
241
|
+
const dshWarning = agent.session.snapshotEvents().find((event) => event.type === "user/message" && event.data.source.kind === "notesoup-budget" && event.data.source.phase === "warning");
|
|
242
|
+
assert.ok(dshWarning && dshWarning.type === "user/message");
|
|
243
|
+
assert.ok(contentText(dshWarning.data.content).endsWith(COUNTDOWN_LINE), "the dsh notice ends with the shared countdown line");
|
|
202
244
|
mock.script.push({ text: "hard", inputTokens: 145000 }, { text: "recovered" });
|
|
203
245
|
await run(agent, "hard reserve");
|
|
204
246
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 2);
|
|
205
247
|
assert.equal(mock.requests.length, 6);
|
|
206
248
|
});
|
|
249
|
+
test("dsh draws one reset paragraph for its origin and reuses it for the steered copy", async (t) => {
|
|
250
|
+
const random = Math.random;
|
|
251
|
+
Math.random = () => 0;
|
|
252
|
+
try {
|
|
253
|
+
const { engine, create, mock } = await dshFixture(t, { thresholdRatio: 0.7, headroomTokens: 32768 });
|
|
254
|
+
const agent = await create();
|
|
255
|
+
// The model's own empty_brain call opens the normal handoff.
|
|
256
|
+
mock.script.push({ tool: "empty_brain", input: {} }, { text: "fresh" });
|
|
257
|
+
await run(agent, "model asked");
|
|
258
|
+
const modelCheckpoint = agent.session.eventAt(agent.session.surface.nodes[1]);
|
|
259
|
+
if (modelCheckpoint.type !== "user/message")
|
|
260
|
+
assert.fail("a reset must write a checkpoint message");
|
|
261
|
+
const modelText = contentText(modelCheckpoint.data.content);
|
|
262
|
+
assert.ok(modelText.endsWith(`${NORMAL_CONTINUATIONS[0]}\n</notesoup-continuation>`), "the model's call draws the normal pool");
|
|
263
|
+
assert.equal(FORCED_CONTINUATIONS.some((line) => modelText.includes(line)), false);
|
|
264
|
+
// A budget cutoff happens without a call, and its one draw serves both representations.
|
|
265
|
+
mock.script.push({ text: "hard", inputTokens: 145000 }, { text: "recovered" });
|
|
266
|
+
await run(agent, "nobody asked");
|
|
267
|
+
assert.equal(engine.windows.get(agent.session).snapshot.window, 2);
|
|
268
|
+
const checkpoints = agent.session.snapshotEvents().filter((event) => event.type === "user/message" && event.data.source.kind === "compact-checkpoint");
|
|
269
|
+
assert.equal(checkpoints.length, 2);
|
|
270
|
+
const budgetCheckpoint = checkpoints[1];
|
|
271
|
+
if (budgetCheckpoint.type !== "user/message")
|
|
272
|
+
assert.fail("the budget reset must write a checkpoint message");
|
|
273
|
+
const budgetText = contentText(budgetCheckpoint.data.content);
|
|
274
|
+
assert.ok(budgetText.endsWith(`${FORCED_CONTINUATIONS[0]}\n</notesoup-continuation>`), "a budget cutoff draws the forced pool");
|
|
275
|
+
assert.equal(NORMAL_CONTINUATIONS.some((line) => budgetText.includes(line)), false);
|
|
276
|
+
const steered = agent.session.snapshotEvents().filter((event) => event.type === "user/message" && event.data.source.kind === "notesoup-continuation").at(-1);
|
|
277
|
+
assert.ok(steered && steered.type === "user/message", "the budget reset steers its continuation");
|
|
278
|
+
assert.equal(contentText(steered.data.content), FORCED_CONTINUATIONS[0], "the steered copy is the same artifact, never a second draw");
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
Math.random = random;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
207
284
|
test("dsh explicit resets survive auto:false; shared tool reads and expected errors keep their codes", async (t) => {
|
|
208
285
|
const { ctx, engine, create, mock } = await dshFixture(t, { auto: false });
|
|
209
286
|
const agent = await create();
|
|
@@ -263,7 +340,7 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
263
340
|
if (refused.isError)
|
|
264
341
|
assert.equal(refused.error.info?.code, "invalid_scope");
|
|
265
342
|
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
266
|
-
const sharedBoot = renderBootBlock({ agentName: identity.agent, modelName: identity.model,
|
|
343
|
+
const sharedBoot = renderBootBlock({ agentName: identity.agent, modelName: identity.model, tree: { trunk: `dsh:${agent.session.id}`, windows: [{ shortName: "0", isCurrent: false }, { shortName: "1", isCurrent: true }] }, notes: await loadNotesSnapshot(identity, snapshot.openedAt), tools: { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "empty_brain" } });
|
|
267
344
|
// The shared protocol, including the MAP cheatsheet, is used verbatim inside host framing.
|
|
268
345
|
assert.ok(snapshot.boot.includes(sharedBoot.split("YOUR NOTES")[0]));
|
|
269
346
|
const blocked = ctx.on("tools/post-execute", async (exec, _result, next) => exec.name === "empty_brain" ? { kind: "block", feedback: [{ type: "text", text: "blocked" }] } : next());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { type ContextUsage, type ExtensionAPI, type ExtensionContext, type ExtensionToolContext, type RegisteredCommand, SessionManager, SettingsManager, type SessionBoundaryDraft, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { HistoryProjection } from "../../src/history/history.js";
|
|
3
4
|
import { type OperationError, type TextWindow } from "../../src/tools/result.js";
|
|
4
5
|
export type ExtensionTestEnvironment = {
|
|
5
6
|
readonly cwd: string;
|
|
@@ -67,6 +68,8 @@ export declare function objectSchema(tool: ToolDefinition | undefined): {
|
|
|
67
68
|
} | undefined;
|
|
68
69
|
export declare function manager(persisted?: boolean): SessionManager;
|
|
69
70
|
export declare function makeExtension(sessionManager: SessionManager, settingsManager?: SettingsManager): Captured;
|
|
71
|
+
/** Compare boot addresses to the host projection, without freezing its prose. */
|
|
72
|
+
export declare function assertBootHistory(body: string, projection: HistoryProjection): void;
|
|
70
73
|
export declare function explicitBoot(ctx: ExtensionContext, currentWindowId: string, previousWindowId: string | undefined): Promise<string>;
|
|
71
74
|
export declare function context(sessionManager: SessionManager, compact?: ExtensionContext["compact"], usage?: ContextUsage, idle?: boolean, cwd?: string, projectTrusted?: boolean, model?: string | {
|
|
72
75
|
provider: string;
|