notesoup 0.58.2 → 0.59.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 +2 -1
- package/dist/plugins/claude/src/helper.js +13 -0
- package/dist/plugins/claude/src/thresholds.js +17 -12
- package/dist/plugins/pi/budget.d.ts +3 -0
- package/dist/plugins/pi/budget.js +22 -11
- package/dist/plugins/pi/runtime.js +22 -6
- package/dist/src/boot/text.d.ts +1 -1
- package/dist/src/boot/text.js +5 -4
- package/dist/src/budget/cap.d.ts +2 -0
- package/dist/src/budget/cap.js +11 -0
- package/dist/src/notes/policy.d.ts +1 -1
- package/dist/src/notes/policy.js +4 -3
- package/dist/src/tools/notes.js +1 -1
- package/dist/test/agent-loop.test.js +13 -39
- package/dist/test/boot.integration.test.js +20 -18
- package/dist/test/budget-settings.integration.test.js +63 -14
- package/dist/test/claude-history.test.js +1 -2
- package/dist/test/claude-mod.test.js +96 -29
- package/dist/test/codex-history.test.js +9 -6
- package/dist/test/codex-plugin.test.js +4 -8
- package/dist/test/dream-skill.test.js +6 -10
- package/dist/test/dsh-cli.test.js +2 -3
- package/dist/test/dsh.test.js +1 -7
- package/dist/test/helpers/extension.js +3 -1
- package/dist/test/history-corpus.test.js +2 -3
- package/dist/test/history-prefilter.test.js +33 -40
- package/dist/test/history-summary-cache.test.js +1 -1
- package/dist/test/history.integration.test.js +11 -37
- package/dist/test/host-neutral.test.js +2 -2
- package/dist/test/marker.test.js +1 -2
- package/dist/test/model-facing-text.test.js +20 -187
- package/dist/test/note-policy.test.js +40 -22
- package/dist/test/notes-library.test.js +2 -2
- package/dist/test/notes.integration.test.js +36 -149
- package/dist/test/notes.test.js +13 -61
- package/dist/test/pi-render.test.js +23 -62
- package/dist/test/reset-lifecycle.test.js +4 -9
- package/docs/architecture.md +1 -1
- package/docs/claude-code-mod.md +5 -3
- package/docs/dsh.md +1 -1
- package/docs/notes-library.md +1 -1
- package/docs/reset-lifecycle.md +3 -1
- package/docs/tool-results.md +1 -1
- package/package.json +1 -1
- package/playbook.md +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +47 -17
- package/plugins/claude/hooks/register.ts +51 -5
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/memory/SKILL.md +1 -1
- package/plugins/claude/src/helper.ts +11 -0
- package/plugins/claude/src/thresholds.ts +18 -11
- package/plugins/codex/dist/codex/notesoup.js +10 -8
- package/plugins/pi/budget.ts +21 -11
- package/plugins/pi/runtime.ts +18 -6
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/text.ts +5 -4
- package/src/budget/cap.ts +9 -0
- package/src/notes/policy.ts +4 -3
- package/src/tools/notes.ts +1 -1
|
@@ -142,7 +142,6 @@ test("resuming old root/reset boots removes only top-level teaching in projectio
|
|
|
142
142
|
const messages = projected?.messages;
|
|
143
143
|
const boot = messages.find((message) => message.role === "custom" && message.customType === BOOT_TYPE);
|
|
144
144
|
assert.equal(boot?.role === "custom" ? boot.content : undefined, expected);
|
|
145
|
-
assert.ok(expected.includes("keep this note's protocol quote") && expected.includes(" <notesoup:maps>\n"), "notes retain same-name tags verbatim");
|
|
146
145
|
assert.ok(messages.some((message) => message.role === "user" && JSON.stringify(message.content) === JSON.stringify([{ type: "text", text: oldBoot }])), "ordinary user content is not rewritten");
|
|
147
146
|
assert.deepEqual(sm.getBranch(), before, "projection never migrates or edits the persisted boot/history");
|
|
148
147
|
const persisted = sm.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE);
|
|
@@ -232,7 +231,7 @@ test("an aborted async boot repair emits no boot, continuation, or incomplete-no
|
|
|
232
231
|
controller.abort();
|
|
233
232
|
await pending;
|
|
234
233
|
assert.equal(captured.sent.length, 0, "aborted snapshot work cannot append the reset boot or continuation");
|
|
235
|
-
assert.equal(noticesOf(ctx).
|
|
234
|
+
assert.equal(noticesOf(ctx).length, 0, "aborted snapshot work cannot notify");
|
|
236
235
|
assert.equal(sessionManager.getBranch().some((entry) => entry.type === "custom_message" && [BOOT_TYPE, CONTINUATION_TYPE].includes(entry.customType)), false);
|
|
237
236
|
});
|
|
238
237
|
test("a marker tail with only metadata repairs its missing boot and continuation without moving the boundary", async () => {
|
|
@@ -372,17 +371,14 @@ test("/empty waits out non-agent busy work before starting its single-turn reque
|
|
|
372
371
|
const cmd = captured.commands.get("empty");
|
|
373
372
|
assert.ok(cmd);
|
|
374
373
|
let waits = 0;
|
|
375
|
-
const notices = [];
|
|
376
374
|
const ctx = Object.assign(context(sessionManager, undefined, undefined, false), {
|
|
377
375
|
signal: undefined,
|
|
378
376
|
waitForIdle: async () => { waits++; },
|
|
379
|
-
ui: { notify: (message) => notices.push(message) },
|
|
380
377
|
});
|
|
381
378
|
await cmd.handler("", ctx);
|
|
382
379
|
assert.equal(waits, 1);
|
|
383
380
|
assert.equal(captured.sent.length, 1);
|
|
384
381
|
assert.equal(captured.sent[0]?.options?.triggerTurn, true);
|
|
385
|
-
assert.equal(notices.filter((message) => message.includes("Dumping Brain")).length, 1);
|
|
386
382
|
});
|
|
387
383
|
test("notesoup command toggles future work, /empty schedules a turn-end reset, and /compact remains disabled", async () => {
|
|
388
384
|
const sessionManager = manager();
|
|
@@ -394,20 +390,15 @@ test("notesoup command toggles future work, /empty schedules a turn-end reset, a
|
|
|
394
390
|
assert.equal(captured.sent.length, 1);
|
|
395
391
|
assert.equal(captured.sent[0]?.message.customType, BOOT_TYPE);
|
|
396
392
|
let notices = await runCommand(captured, "notesoup", "off", low);
|
|
397
|
-
assert.match(notices[0]?.message ?? "", /off/);
|
|
398
393
|
assert.equal(await runContextHook(captured, low), undefined, "no guidance while off");
|
|
399
394
|
assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0, "no guidance persisted while off");
|
|
400
395
|
await runHandlers(captured, "session_start", { reason: "startup" }, low);
|
|
401
396
|
assert.equal(captured.sent.length, 1, "no new boot block is persisted while off");
|
|
402
397
|
const offResultRaw = await call(captured, "empty_brain", {}, low);
|
|
403
398
|
assert.equal(offResultRaw.isError, true, "a refusal is a failed tool call, not a successful answer");
|
|
404
|
-
const offResult = resultJson(offResultRaw);
|
|
405
|
-
assert.match(offResult.error ?? "", /off/, "empty_brain refuses while off");
|
|
406
399
|
notices = await runCommand(captured, "notesoup", "on", low);
|
|
407
|
-
assert.match(notices[0]?.message ?? "", /on/);
|
|
408
400
|
notices = await runCommand(captured, "empty", "", low);
|
|
409
401
|
assert.equal(notices.length, 1, "the command acknowledges the reset request");
|
|
410
|
-
assert.match(notices[0]?.message ?? "", /Dumping Brain/);
|
|
411
402
|
assert.equal(captured.sent.length, 2, "the command persists one hidden warning after the startup boot");
|
|
412
403
|
assert.equal(captured.sent[1]?.options?.triggerTurn, true, "the manual checkpoint prompt starts an ordinary agent turn");
|
|
413
404
|
assert.equal(captured.sent[1]?.message.customType, MANUAL_WIPE_TYPE);
|
|
@@ -423,13 +414,25 @@ test("notesoup command toggles future work, /empty schedules a turn-end reset, a
|
|
|
423
414
|
notices = await runCommand(captured, "notesoup", "", low);
|
|
424
415
|
assert.match(notices[0]?.message ?? "", /on/);
|
|
425
416
|
});
|
|
426
|
-
test("forced
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
417
|
+
test("only forced resets notify, once and after their durable boundary commits", async () => {
|
|
418
|
+
for (const forced of [false, true]) {
|
|
419
|
+
const sessionManager = manager();
|
|
420
|
+
const captured = makeExtension(sessionManager);
|
|
421
|
+
const ctx = forced ? context(sessionManager, undefined, { tokens: 199_000, contextWindow: 200_000, percent: 99.5 }) : context(sessionManager);
|
|
422
|
+
const severities = [];
|
|
423
|
+
ctx.ui.notify = (_message, severity) => {
|
|
424
|
+
const marker = sessionManager.getBranch().filter(entry => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).at(-1);
|
|
425
|
+
assert.ok(marker?.type === "custom");
|
|
426
|
+
assert.ok(resetBoundaryCommitted(ctx, marker.id, marker.data.windowId));
|
|
427
|
+
severities.push(severity);
|
|
428
|
+
};
|
|
429
|
+
if (!forced)
|
|
430
|
+
await call(captured, "empty_brain", {}, ctx);
|
|
431
|
+
await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
432
|
+
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
433
|
+
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
434
|
+
assert.deepEqual(severities, forced ? ["warning"] : []);
|
|
435
|
+
}
|
|
433
436
|
});
|
|
434
437
|
test("committed reset confirmation survives later work while repair refuses that suffix", async () => {
|
|
435
438
|
const sessionManager = manager();
|
|
@@ -446,7 +449,6 @@ test("committed reset confirmation survives later work while repair refuses that
|
|
|
446
449
|
assert.equal(resetBoundaryCommitted(ctx, marker.id, windowId), true, "later work does not undo a committed native boundary");
|
|
447
450
|
await runHandlers(captured, "agent_settled", {}, ctx);
|
|
448
451
|
await runHandlers(captured, "turn_start", {}, ctx);
|
|
449
|
-
assert.deepEqual(noticesOf(ctx), [], "later work does not announce normal reset completion");
|
|
450
452
|
assert.equal(resetBoundaryCommitted(ctx, marker.id, "wrong-window"), false);
|
|
451
453
|
const partial = manager();
|
|
452
454
|
const partialCtx = context(partial);
|
|
@@ -4,13 +4,19 @@ import test from "node:test";
|
|
|
4
4
|
import { SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { Check } from "typebox/value";
|
|
6
6
|
import { DEFAULT_REMINDER_MARGIN_TOKENS, DEFAULT_RESERVE_TOKENS } from "../src/budget/constants.js";
|
|
7
|
+
import { tokenBudgetGuidance } from "../src/budget/text.js";
|
|
7
8
|
import { GUIDANCE_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
|
|
8
9
|
import { deriveThresholds } from "../src/budget/policy.js";
|
|
10
|
+
import { parseContextCap } from "../src/budget/cap.js";
|
|
9
11
|
import { readThresholdSettings } from "../plugins/pi/thresholds.js";
|
|
10
12
|
import { NOTESOUP_SETTINGS_KEY } from "../src/settings.js";
|
|
11
|
-
import { appendText, call, commitTurnEndBoundary, context, makeExtension, manager, noticesOf, resultJson, runContextHook, runHandlers, sentOf, settingsFixture, writeJson, } from "./helpers/extension.js";
|
|
13
|
+
import { appendText, call, commitTurnEndBoundary, context, makeExtension, manager, noticesOf, resultJson, runContextHook, runHandlers, runCommand, sentOf, settingsFixture, writeJson, } from "./helpers/extension.js";
|
|
12
14
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
13
15
|
const testEnvironment = installExtensionTestHooks("notesoup-integration");
|
|
16
|
+
const explicitBudgetSettings = {
|
|
17
|
+
compaction: { enabled: true, reserveTokens: 16_384 },
|
|
18
|
+
notesoup: { reminderMarginTokens: 24_576, warningRunwayTokens: 16_384 },
|
|
19
|
+
};
|
|
14
20
|
test("budget derivation preserves defaults and validates overrides independently", () => {
|
|
15
21
|
assert.deepEqual(deriveThresholds(32_768, {}), {
|
|
16
22
|
thresholds: { reserve: 32_768, reminder: 57_344, warning: 49_152 }, warnings: [],
|
|
@@ -22,14 +28,57 @@ test("budget derivation preserves defaults and validates overrides independently
|
|
|
22
28
|
assert.deepEqual(invalid.thresholds, deriveThresholds(32_768, {}).thresholds);
|
|
23
29
|
assert.equal(invalid.warnings.length, 3);
|
|
24
30
|
for (const key of ["reserveTokens", "warningRunwayTokens", "reminderMarginTokens"]) {
|
|
25
|
-
assert.equal(invalid.warnings.filter((warning) => warning.includes(`notesoup.${key}
|
|
31
|
+
assert.equal(invalid.warnings.filter((warning) => warning.includes(`notesoup.${key}`)).length, 1);
|
|
26
32
|
}
|
|
27
33
|
assert.deepEqual(deriveThresholds(32_768, { reserveTokens: 8192, warningRunwayTokens: null }).thresholds, { reserve: 8192, reminder: 32_768, warning: 24_576 }, "an invalid runway does not discard a valid reserve");
|
|
28
34
|
});
|
|
35
|
+
test("context caps accept whole tokens and decimal k/m suffixes without lossy rounding", () => {
|
|
36
|
+
for (const [text, tokens] of [["100k", 100_000], ["100000", 100_000], [" 1M ", 1_000_000], ["1.5k", 1500], ["off", null]]) {
|
|
37
|
+
assert.equal(parseContextCap(text), tokens);
|
|
38
|
+
}
|
|
39
|
+
for (const text of ["", "0", "-1k", "1.5", "NaN", "Infinity", "100k extra", "1e5", "9007199254740992"])
|
|
40
|
+
assert.equal(parseContextCap(text), undefined, text);
|
|
41
|
+
});
|
|
42
|
+
test("Pi cap controls warning, reported room and hard wipe, without changing the model or settings", async () => {
|
|
43
|
+
const sm = manager();
|
|
44
|
+
appendText(sm, "user", "ongoing work");
|
|
45
|
+
const settings = SettingsManager.inMemory(explicitBudgetSettings);
|
|
46
|
+
const captured = makeExtension(sm, settings);
|
|
47
|
+
const at = (tokens, window = 200_000) => {
|
|
48
|
+
const ctx = context(sm, undefined, { tokens, percent: tokens / window * 100, contextWindow: window });
|
|
49
|
+
ctx.model = { provider: "test", id: "cap-model", contextWindow: window };
|
|
50
|
+
return ctx;
|
|
51
|
+
};
|
|
52
|
+
const native = at(0), beforeSettings = settings.getSettings();
|
|
53
|
+
const room = async (ctx = at(0)) => resultJson(await call(captured, "get_context_remaining", {}, ctx)).remaining_tokens;
|
|
54
|
+
await runCommand(captured, "notesoup", "cap 100k", native);
|
|
55
|
+
assert.equal(await room(), 83_616);
|
|
56
|
+
assert.equal(native.model?.contextWindow, 200_000);
|
|
57
|
+
assert.deepEqual(settings.getSettings(), beforeSettings);
|
|
58
|
+
for (const invalid of ["cap 0", "cap nonsense", "cap 100k extra", "cap 16k"]) {
|
|
59
|
+
assert.equal((await runCommand(captured, "notesoup", invalid, at(0)))[0]?.type, "error");
|
|
60
|
+
assert.equal(await room(), 83_616, "invalid caps leave the previous cap intact");
|
|
61
|
+
}
|
|
62
|
+
const warning = await runContextHook(captured, at(67_232));
|
|
63
|
+
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE);
|
|
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));
|
|
67
|
+
assert.equal(hard.entries.filter((e) => e.type === "custom" && e.customType === RESET_MARKER_TYPE).length, 1);
|
|
68
|
+
assert.equal(await room(at(1000)), 82_616, "the cap survives a notesoup reset");
|
|
69
|
+
assert.equal(await room(at(1000, 64_000)), 46_616, "a cap cannot enlarge a smaller model window");
|
|
70
|
+
await runCommand(captured, "notesoup", "cap off", at(0));
|
|
71
|
+
assert.equal(await room(), 183_616);
|
|
72
|
+
await runCommand(captured, "notesoup", "cap 100k", at(0));
|
|
73
|
+
await runHandlers(captured, "model_select", {}, at(0, 64_000));
|
|
74
|
+
assert.equal(await room(at(0, 64_000)), 47_616, "switching models preserves the cap but uses the smaller window");
|
|
75
|
+
await runHandlers(captured, "session_start", {}, at(0));
|
|
76
|
+
assert.equal(await room(), 183_616, "a new/reloaded session does not inherit the runtime cap");
|
|
77
|
+
});
|
|
29
78
|
test("Pi budget settings merge per key without changing native compaction settings or enablement", async () => {
|
|
30
79
|
const fixture = settingsFixture({
|
|
31
80
|
reserveTokens: 32_768,
|
|
32
|
-
global: { notesoup: { reserveTokens: 12_000, warningRunwayTokens: 20_000 } },
|
|
81
|
+
global: { notesoup: { reserveTokens: 12_000, warningRunwayTokens: 20_000, reminderMarginTokens: 24_576 } },
|
|
33
82
|
project: { notesoup: { reserveTokens: 8192 } },
|
|
34
83
|
});
|
|
35
84
|
const sm = manager();
|
|
@@ -57,7 +106,7 @@ test("Pi budget settings merge per key without changing native compaction settin
|
|
|
57
106
|
assert.equal(disabled.getCompactionSettings().enabled, false);
|
|
58
107
|
});
|
|
59
108
|
test("Pi warning, reported room, and hard wipe use the notesoup reserve override", async () => {
|
|
60
|
-
const fixture = settingsFixture({ reserveTokens: 32_768, global: { notesoup: { reserveTokens: 8192, warningRunwayTokens: 16_384 } } });
|
|
109
|
+
const fixture = settingsFixture({ reserveTokens: 32_768, global: { notesoup: { reserveTokens: 8192, warningRunwayTokens: 16_384, reminderMarginTokens: 24_576 } } });
|
|
61
110
|
const sm = manager();
|
|
62
111
|
appendText(sm, "user", "ongoing work");
|
|
63
112
|
const captured = makeExtension(sm);
|
|
@@ -65,7 +114,7 @@ test("Pi warning, reported room, and hard wipe use the notesoup reserve override
|
|
|
65
114
|
const at = (remaining) => context(sm, undefined, { tokens: 200_000 - remaining, percent: 0, contextWindow: 200_000 }, true, fixture.cwd);
|
|
66
115
|
const early = await runContextHook(captured, at(24_577));
|
|
67
116
|
assert.equal(early?.messages[0]?.customType, GUIDANCE_TYPE, "no warning above reserve + runway");
|
|
68
|
-
assert.
|
|
117
|
+
assert.equal(early?.messages[0]?.content, tokenBudgetGuidance(16_385, "empty_brain"), "guidance subtracts the overridden reserve");
|
|
69
118
|
const warning = await runContextHook(captured, at(24_576));
|
|
70
119
|
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE, "warn at 8192 + 16384, not native reserve + runway");
|
|
71
120
|
const room = async (remaining) => resultJson(await call(captured, "get_context_remaining", {}, at(remaining))).remaining_tokens;
|
|
@@ -79,11 +128,11 @@ test("Pi warning, reported room, and hard wipe use the notesoup reserve override
|
|
|
79
128
|
});
|
|
80
129
|
test("low-budget guidance and warning persist at turn_end, once per active window", async () => {
|
|
81
130
|
const sessionManager = manager();
|
|
82
|
-
const captured = makeExtension(sessionManager);
|
|
131
|
+
const captured = makeExtension(sessionManager, SettingsManager.inMemory(explicitBudgetSettings));
|
|
83
132
|
const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
84
133
|
const guidance = await runContextHook(captured, low);
|
|
85
134
|
assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
|
|
86
|
-
assert.
|
|
135
|
+
assert.equal((guidance?.messages[0]).content, tokenBudgetGuidance(18_616, "empty_brain"), "the reminder reports room to the reserve, not to the warning");
|
|
87
136
|
assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
|
|
88
137
|
const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
|
|
89
138
|
assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
|
|
@@ -99,22 +148,22 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
|
|
|
99
148
|
});
|
|
100
149
|
test("early guidance stays silent and the final warning notifies immediately once", async () => {
|
|
101
150
|
const sm = manager();
|
|
102
|
-
const captured = makeExtension(sm);
|
|
151
|
+
const captured = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
103
152
|
const early = context(sm, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
104
153
|
assert.equal((await runContextHook(captured, early))?.messages.length, 1, "early guidance reaches the crossing request");
|
|
105
154
|
await commitTurnEndBoundary(captured, sm, early);
|
|
106
155
|
await runHandlers(captured, "agent_settled", {}, early);
|
|
107
|
-
assert.equal(noticesOf(early).filter((notice) => notice.
|
|
156
|
+
assert.equal(noticesOf(early).filter((notice) => notice.type === "warning").length, 0, "early model guidance has no UI toast");
|
|
108
157
|
assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "early guidance remains durable for the model");
|
|
109
158
|
const final = context(sm, undefined, { tokens: 181_000, percent: 90.5, contextWindow: 200_000 });
|
|
110
159
|
const warning = await runContextHook(captured, final);
|
|
111
160
|
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE);
|
|
112
|
-
assert.equal(noticesOf(final).filter((notice) => notice.
|
|
161
|
+
assert.equal(noticesOf(final).filter((notice) => notice.type === "warning").length, 1, "notify at injection, before any turn_end");
|
|
113
162
|
await runContextHook(captured, final);
|
|
114
163
|
await commitTurnEndBoundary(captured, sm, final);
|
|
115
164
|
await runHandlers(captured, "turn_start", {}, final);
|
|
116
165
|
await runHandlers(captured, "agent_settled", {}, final);
|
|
117
|
-
assert.equal(noticesOf(final).filter((notice) => notice.
|
|
166
|
+
assert.equal(noticesOf(final).filter((notice) => notice.type === "warning").length, 1, "repeated injection and commit do not notify again");
|
|
118
167
|
});
|
|
119
168
|
test("get_context_remaining declares its output and returns matching structured and text values", async () => {
|
|
120
169
|
const fixture = settingsFixture({ reserveTokens: 16_384 });
|
|
@@ -146,7 +195,7 @@ test("the reported room ends at the hard reserve, clamps at zero, and preserves
|
|
|
146
195
|
return resultJson(await call(captured, "get_context_remaining", {}, ctx)).remaining_tokens;
|
|
147
196
|
};
|
|
148
197
|
assert.equal(await readBudget(72_563), 94_669, "the reported room excludes only the project reserve (32768)");
|
|
149
|
-
assert.equal(await readBudget(150_848), 16_384, "
|
|
198
|
+
assert.equal(await readBudget(150_848), 16_384, "an intermediate usage reports the room above the configured reserve");
|
|
150
199
|
assert.equal(await readBudget(167_232), 0, "the hard reserve reads zero");
|
|
151
200
|
assert.equal(await readBudget(190_000), 0, "below the reserve, still zero");
|
|
152
201
|
assert.equal(await readBudget(210_000), 0, "over the physical window");
|
|
@@ -226,12 +275,12 @@ test("an invalid reminder margin degrades to its default with one warning and ne
|
|
|
226
275
|
test("the warning supersedes the early reminder when usage jumps across both thresholds", async () => {
|
|
227
276
|
const sm = manager();
|
|
228
277
|
appendText(sm, "user", "ongoing work");
|
|
229
|
-
const captured = makeExtension(sm);
|
|
278
|
+
const captured = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
230
279
|
const ctx = context(sm, undefined, { tokens: 199_000, percent: 99.5, contextWindow: 200_000 }, false);
|
|
231
280
|
const warningResult = await runContextHook(captured, ctx);
|
|
232
281
|
assert.deepEqual(warningResult?.messages.map((message) => message.customType), [WARNING_TYPE]);
|
|
233
282
|
await commitTurnEndBoundary(captured, sm, ctx);
|
|
234
|
-
const reloaded = makeExtension(sm);
|
|
283
|
+
const reloaded = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
235
284
|
await runHandlers(reloaded, "context", { messages: [] }, ctx);
|
|
236
285
|
assert.equal(reloaded.sent.length, 0, "persisted warning also suppresses a late reminder after reload");
|
|
237
286
|
});
|
|
@@ -90,7 +90,6 @@ test("Claude dialogue paging skips tool/thinking envelopes without losing array
|
|
|
90
90
|
const envelope = await historyRead.execute({ seq: 6 }, projection);
|
|
91
91
|
assert.ok(envelope.ok);
|
|
92
92
|
assert.equal(envelope.data.text, "", "a tool-result envelope has no dialogue text to invent");
|
|
93
|
-
assert.match(historyRead.render(envelope), /No visible text recorded/);
|
|
94
93
|
const tool = await historyRead.execute({ seq: 5 }, projection);
|
|
95
94
|
assert.ok(tool.ok);
|
|
96
95
|
assert.match(tool.data.text, /tool output/);
|
|
@@ -295,7 +294,7 @@ test("Claude helper reports gaps on list/read and re-anchors reset state only wi
|
|
|
295
294
|
for (const [tool, params] of [["history_list", {}], ["history_read", { seq: 2 }],
|
|
296
295
|
["history_list", { query: "no matches" }], ["history_read", { seq: 99 }]]) {
|
|
297
296
|
const response = await invoke(tool, params);
|
|
298
|
-
assert.match(response.text, /
|
|
297
|
+
assert.match(response.text, /"missing"/, "the gap evidence still names the missing ancestor");
|
|
299
298
|
assert.doesNotMatch(response.text, /do not expose/);
|
|
300
299
|
}
|
|
301
300
|
assert.match((await invoke("history_list")).text, /confirmed suffix/);
|
|
@@ -278,6 +278,14 @@ test("Claude limits derive from Claude's own auto-compact point, never a fixed p
|
|
|
278
278
|
assert.equal(absurdMargin.source, "percent");
|
|
279
279
|
assert.ok(absurdMargin.reset > 0 && absurdMargin.warn > 0, "an absurd margin cannot zero the percent fallback either");
|
|
280
280
|
});
|
|
281
|
+
test("Claude caps the capacity before deriving the same warning and hard points", () => {
|
|
282
|
+
const facts = { usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000 }, capTokens: 100_000 };
|
|
283
|
+
assert.deepEqual(limitPoints(facts), { source: "window", unit: "tokens", autoCompact: true, native: 67_000, reset: 58_808, warn: 42_424 });
|
|
284
|
+
assert.equal(resolveClaudeLimits({ ...facts, capTokens: 1_000_000 }).reset, 158_808, "a cap never enlarges the model window");
|
|
285
|
+
assert.equal(resolveClaudeLimits({ usage: { window: 64_000 }, capTokens: 100_000 }).reset, 22_808, "a smaller model keeps its own limit");
|
|
286
|
+
assert.equal(resolveClaudeLimits({ ...facts, breakdown: { autoCompactThreshold: 50_000 } }).reset, 41_808, "an earlier native hard point still wins");
|
|
287
|
+
assert.equal(resolveClaudeLimits({ ...facts, settings: { autoCompactWindow: 80_000 }, breakdown: {} }).reset, 38_808, "a smaller configured window still wins");
|
|
288
|
+
});
|
|
281
289
|
test("Claude limits read margins from the notesoup settings shape and ignore garbage", () => {
|
|
282
290
|
const base = { usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000, isAutoCompactEnabled: true } };
|
|
283
291
|
assert.deepEqual(limitPoints({ ...base, settings: { notesoup: { resetMarginTokens: 10_000, warningRunwayTokens: 5_000 } } }), { source: "auto-compact", unit: "tokens", autoCompact: true, native: 167_000, reset: 157_000, warn: 152_000 });
|
|
@@ -497,12 +505,12 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
497
505
|
...upstream,
|
|
498
506
|
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." }],
|
|
499
507
|
}, "boot failure keeps the original fallback and upstream fields even if notify is absent or fails");
|
|
500
|
-
const expectedNotifications = mode === "no ui" || mode === "no toast" ?
|
|
501
|
-
assert.
|
|
508
|
+
const expectedNotifications = mode === "no ui" || mode === "no toast" ? 0 : 1;
|
|
509
|
+
assert.equal(notifications.length, expectedNotifications, "one user-facing notification reports the notes boot failure");
|
|
502
510
|
assert.equal(bootRequests, 1);
|
|
503
511
|
assert.equal(nextCalls, 1);
|
|
504
512
|
assert.deepEqual(await promptContext(structuredClone(failed)), failed);
|
|
505
|
-
assert.
|
|
513
|
+
assert.equal(notifications.length, expectedNotifications, "a persisted fallback does not notify again");
|
|
506
514
|
assert.equal(bootRequests, 1, "a persisted fallback needs no second boot request");
|
|
507
515
|
assert.equal(nextCalls, 2, "the upstream chain still runs exactly once per prompt");
|
|
508
516
|
});
|
|
@@ -530,8 +538,17 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
530
538
|
assert.equal(wipeSchema.required, undefined, "both arguments are optional");
|
|
531
539
|
assert.equal(wipeSchema.additionalProperties, false);
|
|
532
540
|
const call = (tool, params) => handlers.get("tool.call")(host, { tool: `mcp__notesoup__${tool}`, tool_use_id: "hook-1", ...params }, async (event) => event);
|
|
541
|
+
let helperText;
|
|
542
|
+
const run = host.process.run;
|
|
543
|
+
host.process.run = async (argv, init) => {
|
|
544
|
+
const response = await run(argv, init);
|
|
545
|
+
if (JSON.parse(init.stdin).op === "tool")
|
|
546
|
+
helperText = JSON.parse(response.stdout).result.text;
|
|
547
|
+
return response;
|
|
548
|
+
};
|
|
533
549
|
const written = await call("notes_write", { address: "hook.md", content: "hook body" });
|
|
534
|
-
assert.equal(
|
|
550
|
+
assert.equal(typeof helperText, "string");
|
|
551
|
+
assert.equal(written.result, helperText, "the hook hands back the shared text unchanged");
|
|
535
552
|
assert.equal("isError" in written, false, "a success carries no discriminator at all, not a false one");
|
|
536
553
|
const refused = await call("notes_read", { address: "absent.md" });
|
|
537
554
|
assert.equal(refused.isError, true, "a refusal carries the literal the public ToolCallResult declares");
|
|
@@ -547,7 +564,7 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
547
564
|
assert.equal(crashed.isError, true);
|
|
548
565
|
assert.match(String(crashed.result), /^notesoup: helper execution failed: Error: spawn timed out after 10000ms$/, "the host's own reason survives the catch");
|
|
549
566
|
});
|
|
550
|
-
test("Claude Mod
|
|
567
|
+
test("Claude Mod clears at the shared hard point after successful settlement and retains one fresh boot", async (t) => {
|
|
551
568
|
const home = mkdtempSync(join(tmpdir(), "claude-reset-home-"));
|
|
552
569
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
553
570
|
const { host, registered, notifications } = fakeEngine(home);
|
|
@@ -555,7 +572,7 @@ test("Claude Mod crosses old reset thresholds without clearing and retains one f
|
|
|
555
572
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
556
573
|
const invoke = (name, event = {}) => handlers.get(name)(host, event, async () => ({ sentinel: name }));
|
|
557
574
|
assert.equal(handlers.has("session.measure"), false, "measure has no reset hook");
|
|
558
|
-
//
|
|
575
|
+
// Warning and automatic reset share the same native-derived points.
|
|
559
576
|
let tokens = 140_000;
|
|
560
577
|
let compactions = 0;
|
|
561
578
|
let kept = [];
|
|
@@ -588,16 +605,8 @@ test("Claude Mod crosses old reset thresholds without clearing and retains one f
|
|
|
588
605
|
assert.equal(compactions, 0, "one token below the resolved reset point");
|
|
589
606
|
await invoke("turn.start");
|
|
590
607
|
tokens = 158_808;
|
|
591
|
-
assert.equal(compactions, 0, "
|
|
608
|
+
assert.equal(compactions, 0, "measurement alone cannot compact under a running turn");
|
|
592
609
|
assert.deepEqual(await invoke("turn.complete", turnComplete()), { sentinel: "turn.complete" });
|
|
593
|
-
assert.equal(compactions, 0, "the old reset point no longer clears at turn completion");
|
|
594
|
-
tokens = 190_000;
|
|
595
|
-
await invoke("turn.start");
|
|
596
|
-
await invoke("turn.complete", turnComplete());
|
|
597
|
-
assert.equal(compactions, 0, "even beyond the native threshold, only a native auto event or explicit request resets");
|
|
598
|
-
await invoke("turn.start");
|
|
599
|
-
await invoke("command.run", { command: "empty" });
|
|
600
|
-
await invoke("turn.complete", turnComplete());
|
|
601
610
|
await settleHooks();
|
|
602
611
|
assert.equal(compactions, 1);
|
|
603
612
|
assert.equal(kept.length, 2, "the reset is the notes boot followed by the one reset message");
|
|
@@ -691,7 +700,7 @@ test("Claude headless resets through its own manual command, retries failure and
|
|
|
691
700
|
assert.match(kept[0].text, /claude:hook-session:2/);
|
|
692
701
|
assert.equal(kept.length, 2, "sticky is consumed once");
|
|
693
702
|
});
|
|
694
|
-
test("Claude headless warns
|
|
703
|
+
test("Claude headless warns, automatically resets at the hard point, and supports both manual aliases", async (t) => {
|
|
695
704
|
const home = mkdtempSync(join(tmpdir(), "claude-headless-auto-"));
|
|
696
705
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
697
706
|
const { host } = fakeEngine(home);
|
|
@@ -716,11 +725,8 @@ test("Claude headless warns without proactive resets and supports both manual al
|
|
|
716
725
|
await invoke("turn.start");
|
|
717
726
|
assert.equal(attempts, 0);
|
|
718
727
|
await invoke("turn.complete", turnComplete());
|
|
719
|
-
assert.equal(attempts, 0, "the old reset threshold and turn completion do not clear");
|
|
720
|
-
await invoke("tool.call", { tool: "mcp__notesoup__empty_brain", tool_use_id: "explicit" });
|
|
721
|
-
await invoke("turn.complete", turnComplete());
|
|
722
728
|
await settleHooks();
|
|
723
|
-
assert.equal(attempts, 1);
|
|
729
|
+
assert.equal(attempts, 1, "the hard point clears after successful settlement without a tool request");
|
|
724
730
|
for (const command of ["empty", "fresh-window"]) {
|
|
725
731
|
assert.deepEqual(await invoke("command.run", { command }), { text: "🥣 Dumping Brain" });
|
|
726
732
|
await settleHooks();
|
|
@@ -808,7 +814,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
808
814
|
};
|
|
809
815
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
810
816
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
811
|
-
assert.deepEqual(commands.sort(), ["empty", "fresh-window"], "
|
|
817
|
+
assert.deepEqual(commands.sort(), ["empty", "fresh-window", "notesoup"], "the cap command and both reset aliases are registered");
|
|
812
818
|
assert.deepEqual(await invoke("command.run", { command: "empty-brain" }), {}, "the retired spelling passes through instead of resetting");
|
|
813
819
|
assert.equal(compactions, 0);
|
|
814
820
|
const command = await invoke("command.run", { command: "empty" });
|
|
@@ -1139,13 +1145,9 @@ test("Claude Mod retries an unresolvable warning threshold inside the same windo
|
|
|
1139
1145
|
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
1140
1146
|
host.command.run = async ({ args }) => { compactions++; await nativeCompaction(host, handlers, args); return {}; };
|
|
1141
1147
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
1142
|
-
await invoke("turn.start");
|
|
1143
|
-
await invoke("turn.complete", turnComplete());
|
|
1144
1148
|
await handlers.get("prompt.submit")(host, { text: "continue" }, async (e) => e);
|
|
1145
1149
|
assert.equal(limitsCalls, 1, "the first limits round trip failed");
|
|
1146
1150
|
assert.equal(compactions, 0, "one failed resolution does not disable the window");
|
|
1147
|
-
await invoke("turn.start");
|
|
1148
|
-
await invoke("turn.complete", turnComplete());
|
|
1149
1151
|
const retried = await handlers.get("prompt.submit")(host, { text: "continue" }, async (e) => e);
|
|
1150
1152
|
assert.deepEqual(retried.context, [CLAUDE_WARNING_PROMPT]);
|
|
1151
1153
|
assert.equal(limitsCalls, 2, "the retry runs in the same window");
|
|
@@ -1169,6 +1171,72 @@ async function retainedFixture(t) {
|
|
|
1169
1171
|
assert.deepEqual((await context()).blocks, [], "the existing boot is retained, not injected twice");
|
|
1170
1172
|
return { home, host, invoke, context, boot, handlers, notifications };
|
|
1171
1173
|
}
|
|
1174
|
+
test("Claude runtime cap warns and clears at a safe main batch boundary, then survives the reset", async (t) => {
|
|
1175
|
+
const { host, invoke, handlers } = await retainedFixture(t);
|
|
1176
|
+
let tokens = 42_423, window = 200_000, resets = 0;
|
|
1177
|
+
const prompts = [];
|
|
1178
|
+
const settings = { autoCompactWindow: 200_000 };
|
|
1179
|
+
host.settings.read = async () => settings;
|
|
1180
|
+
host.session.usage = async () => ({ context: { tokens, window, breakdown: { autoCompactThreshold: window - 33_000, isAutoCompactEnabled: true, model: "claude" } } });
|
|
1181
|
+
host.prompt.submit = async ({ text }) => { prompts.push(text); return { text }; };
|
|
1182
|
+
host.command.run = async ({ command, args }) => {
|
|
1183
|
+
assert.equal(command, "compact", "the existing notes-only reset runs; /autocompact is never called");
|
|
1184
|
+
resets++;
|
|
1185
|
+
await nativeCompaction(host, handlers, args);
|
|
1186
|
+
tokens = undefined;
|
|
1187
|
+
return {};
|
|
1188
|
+
};
|
|
1189
|
+
const cap = async (args) => await invoke("command.run", { command: "notesoup", args });
|
|
1190
|
+
assert.match((await cap("cap 100k")).text, /100,000/);
|
|
1191
|
+
for (const value of ["cap 0", "cap garbage", "cap 100k extra", "cap 1k"]) {
|
|
1192
|
+
assert.match((await cap(value)).text, /Usage:|too small/);
|
|
1193
|
+
assert.match((await cap("cap")).text, /100,000/, "a refused cap keeps the previous one");
|
|
1194
|
+
}
|
|
1195
|
+
assert.equal((await invoke("tool.call", { tool: "Read" })).context, undefined);
|
|
1196
|
+
tokens = 42_424;
|
|
1197
|
+
assert.deepEqual((await invoke("tool.call", { tool: "Read" })).context, [CLAUDE_WARNING_PROMPT]);
|
|
1198
|
+
tokens = 58_807;
|
|
1199
|
+
await invoke("turn.start", { turnId: "main" });
|
|
1200
|
+
const step = handlers.get("turn.step");
|
|
1201
|
+
const chunks = async (agentId) => {
|
|
1202
|
+
const result = [];
|
|
1203
|
+
for await (const chunk of step(host, { turnId: "main", index: 1, ...(agentId ? { agentId } : {}) }, async function* () { yield { kind: "text", text: "model" }; return {}; }))
|
|
1204
|
+
result.push(chunk);
|
|
1205
|
+
return result;
|
|
1206
|
+
};
|
|
1207
|
+
assert.deepEqual(await chunks(), [{ kind: "text", text: "model" }]);
|
|
1208
|
+
tokens = 58_808;
|
|
1209
|
+
await Promise.all([invoke("tool.call", { tool: "Read" }), invoke("tool.call", { tool: "Bash" })]);
|
|
1210
|
+
assert.equal(resets, 0, "all sibling tool results finish before the hard point can act");
|
|
1211
|
+
assert.deepEqual(await chunks("child"), [{ kind: "text", text: "model" }], "child steps never reset the main brain");
|
|
1212
|
+
assert.deepEqual(await chunks(), [{ kind: "stop", stopReason: "end_turn", usage: null }]);
|
|
1213
|
+
await invoke("turn.complete", turnComplete({ turnId: "main", reason: "error" }));
|
|
1214
|
+
await settleHooks();
|
|
1215
|
+
assert.equal(resets, 0, "a failed turn cannot commit a budget reset");
|
|
1216
|
+
await invoke("turn.start", { turnId: "main" });
|
|
1217
|
+
await chunks();
|
|
1218
|
+
await invoke("turn.complete", turnComplete({ turnId: "main" }));
|
|
1219
|
+
await settleHooks();
|
|
1220
|
+
assert.equal(resets, 1);
|
|
1221
|
+
assert.equal(prompts.length, 1, "a confirmed automatic reset continues exactly once");
|
|
1222
|
+
assert.ok(FORCED_CONTINUATIONS.includes((await host.session.messages())[1].text), "only a real tool request uses the normal handoff pool");
|
|
1223
|
+
assert.match((await cap("cap")).text, /100,000/, "cap survives notesoup rollover");
|
|
1224
|
+
assert.deepEqual(settings, { autoCompactWindow: 200_000 }, "the user's settings stay untouched");
|
|
1225
|
+
await cap("cap off");
|
|
1226
|
+
tokens = 80_000;
|
|
1227
|
+
await invoke("turn.start", { turnId: "main" });
|
|
1228
|
+
assert.deepEqual(await chunks(), [{ kind: "text", text: "model" }], "off immediately restores the native budget");
|
|
1229
|
+
window = 64_000;
|
|
1230
|
+
tokens = 22_807;
|
|
1231
|
+
await cap("cap 100k");
|
|
1232
|
+
assert.deepEqual(await chunks(), [{ kind: "text", text: "model" }]);
|
|
1233
|
+
tokens++;
|
|
1234
|
+
await invoke("turn.complete", turnComplete({ turnId: "main" }));
|
|
1235
|
+
await settleHooks();
|
|
1236
|
+
assert.equal(resets, 2, "a smaller model clears at its own point, not at the cap's point");
|
|
1237
|
+
await invoke("session.end");
|
|
1238
|
+
assert.match((await cap("cap")).text, /cap off/, "a different session does not inherit the runtime cap");
|
|
1239
|
+
});
|
|
1172
1240
|
test("Claude empty_brain stops at the batch boundary, carries last_word, and resumes once after commit", async (t) => {
|
|
1173
1241
|
const { host, invoke, handlers } = await retainedFixture(t);
|
|
1174
1242
|
host.session.usage = async () => ({ context: { tokens: 100, window: 200_000 } });
|
|
@@ -1583,7 +1651,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
1583
1651
|
const run = host.process.run;
|
|
1584
1652
|
host.process.run = async (argv, init) => { requests.push(JSON.parse(init.stdin)); return run(argv, init); };
|
|
1585
1653
|
const written = await invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "new-session", address: "session.md", content: action });
|
|
1586
|
-
assert.
|
|
1654
|
+
assert.match(written.result, /^created session\.md\b/);
|
|
1587
1655
|
assert.equal(requests[0].identity?.sessionId, `after-${action}`, "tools also use the new session notebook");
|
|
1588
1656
|
});
|
|
1589
1657
|
}
|
|
@@ -1660,7 +1728,7 @@ test("Claude serves every registered notes tool to subagents without leaking eve
|
|
|
1660
1728
|
const call = (tool, params) => invoke("tool.call", {
|
|
1661
1729
|
tool: `mcp__notesoup__${tool}`, tool_use_id: "child-call", agentId: "child", ...params,
|
|
1662
1730
|
});
|
|
1663
|
-
assert.equal((await call("notes_write", { address: "child.md", content: "child body" })).
|
|
1731
|
+
assert.equal((await call("notes_write", { address: "child.md", content: "child body" })).isError, undefined);
|
|
1664
1732
|
assert.match((await call("notes_read", { address: "child.md" })).result, /child body/);
|
|
1665
1733
|
assert.equal((await call("notes_update", { address: "child.md", edits: [{ oldText: "child body", newText: "updated body" }] })).isError, undefined);
|
|
1666
1734
|
assert.match((await call("notes_list", {})).result, /child\.md/);
|
|
@@ -1682,7 +1750,7 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
|
|
|
1682
1750
|
return run(argv, init);
|
|
1683
1751
|
};
|
|
1684
1752
|
const write = (address, content) => invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "model-call", address, content });
|
|
1685
|
-
|
|
1753
|
+
await write("@model/model.md", "opus");
|
|
1686
1754
|
assert.equal(seen.at(-1).identity.model, "claude-opus-4-6");
|
|
1687
1755
|
assert.ok(readFileSync(join(home, "models/claude-opus-4-6/model.md"), "utf8").includes("opus"));
|
|
1688
1756
|
model = "Claude Sonnet 4.6";
|
|
@@ -1718,7 +1786,6 @@ test("Claude current-cwd project resolution shares Pi's remote notebook across c
|
|
|
1718
1786
|
cwd = second;
|
|
1719
1787
|
const written = await call("notes_write", { address: "@project/shared", content: "Claude body" });
|
|
1720
1788
|
assert.equal(written.isError, undefined);
|
|
1721
|
-
assert.equal(written.result, "overwrote @project/shared.md (project api) | pinned false | budget 2048 | readonly false");
|
|
1722
1789
|
assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
|
|
1723
1790
|
assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
|
|
1724
1791
|
assert.equal(resolveProjectNamespace(second, home).name, piIdentity.projectKey);
|
|
@@ -169,8 +169,8 @@ test("root: raw messages, top-level envelope metadata, native tool pairing and n
|
|
|
169
169
|
assert.ok(tool.ok);
|
|
170
170
|
assert.equal(tool.data.tool, "exec_command");
|
|
171
171
|
assert.equal(tool.data.tool_status, "error");
|
|
172
|
-
assert.match(
|
|
173
|
-
assert.match(
|
|
172
|
+
assert.match(tool.data.text, /printf output/);
|
|
173
|
+
assert.match(tool.data.text, /partial\nerror/);
|
|
174
174
|
assert.equal(tool.data.output_truncated, undefined);
|
|
175
175
|
assert.equal(tool.data.nested_calls, undefined);
|
|
176
176
|
const paired = await historyRead.execute({ seq: 9 }, projection);
|
|
@@ -178,11 +178,12 @@ test("root: raw messages, top-level envelope metadata, native tool pairing and n
|
|
|
178
178
|
if (paired.ok)
|
|
179
179
|
assert.equal(paired.data.seq, 7);
|
|
180
180
|
const omitted = await historyRead.execute({ seq: 6 }, projection);
|
|
181
|
-
assert.
|
|
181
|
+
assert.ok(!omitted.ok);
|
|
182
|
+
assert.equal(omitted.error.code, "unknown_seq");
|
|
182
183
|
const page = await historyList.execute({ query: "printf output" }, projection);
|
|
183
184
|
assert.ok(page.ok);
|
|
184
185
|
assert.equal(page.data.items.length, 1);
|
|
185
|
-
assert.
|
|
186
|
+
assert.equal(page.data.items[0]?.seq, 7);
|
|
186
187
|
assert.deepEqual(await readFile(f.path), before);
|
|
187
188
|
assert.equal((await stat(f.path)).mtimeMs, info.mtimeMs);
|
|
188
189
|
});
|
|
@@ -209,9 +210,11 @@ test("two native checkpoints retain old raw history; replacement_history is not
|
|
|
209
210
|
[`codex:${ROOT}:${W0}`, 2, 3], [`codex:${ROOT}:${W1}`, 4, 6], [`codex:${ROOT}:${W2}`, 7, 8],
|
|
210
211
|
]);
|
|
211
212
|
const earlier = await historyList.execute({ after_seq: 3, before_seq: 7, roles: ["user"] }, second.projection);
|
|
212
|
-
assert.
|
|
213
|
+
assert.ok(earlier.ok);
|
|
214
|
+
assert.deepEqual(earlier.data.items.map((item) => [item.seq, item.role, item.content]), [[6, "user", "middle text"]]);
|
|
213
215
|
const old = await historyRead.execute({ seq: 2 }, second.projection);
|
|
214
|
-
assert.
|
|
216
|
+
assert.ok(old.ok);
|
|
217
|
+
assert.match(old.data.text, /old raw text/);
|
|
215
218
|
const { projection: _projection, dependencies: _dependencies, lineageSources: _lineageSources, ...facts } = second;
|
|
216
219
|
assert.deepEqual(await readCodexTranscriptState({ transcriptPath: f.path, threadId: ROOT }), facts);
|
|
217
220
|
assert.deepEqual(await readCodexHistory({ transcriptPath: f.path, threadId: ROOT }), second);
|
|
@@ -183,7 +183,7 @@ test("bundled Codex MCP reads another harness and wildcard results retain their
|
|
|
183
183
|
assert.equal(page.has_newer, false);
|
|
184
184
|
const limited = await call(client, { name: "history_list", arguments: { session: "*", query: "needle", limit: 1 }, _meta: metaFor(ROOT, ROOT) });
|
|
185
185
|
assert.equal(limited.structuredContent.has_older, true);
|
|
186
|
-
assert.
|
|
186
|
+
assert.equal(limited.structuredContent.items.length, 1, "the limit bounds the page to one item");
|
|
187
187
|
assert.doesNotMatch(textOf(limited), /before_seq|after_seq/);
|
|
188
188
|
const invalid = await call(client, { name: "history_read", arguments: { session: "*", seq: 1 }, _meta: metaFor(ROOT, ROOT) });
|
|
189
189
|
assert.equal(errorCode(invalid), "invalid_session");
|
|
@@ -294,7 +294,7 @@ test("history tools serve root and child native ancestry, and refuse stale nativ
|
|
|
294
294
|
row("response_item", message("user", "child task")),
|
|
295
295
|
]));
|
|
296
296
|
await bind(f.data, { threadId: CHILD, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: childPath, agent: "worker", agentType: "worker" });
|
|
297
|
-
const invalidFilter = await call(client, { name: "history_list", arguments: {
|
|
297
|
+
const invalidFilter = await call(client, { name: "history_list", arguments: { limit: 0 }, _meta: meta });
|
|
298
298
|
assert.equal(errorCode(invalidFilter), "invalid_params");
|
|
299
299
|
const childHistory = await call(client, { name: "history_list", arguments: {}, _meta: metaFor(CHILD, ROOT) });
|
|
300
300
|
assert.equal(childHistory.isError, undefined);
|
|
@@ -321,18 +321,14 @@ test("a root boot carries the native window, native reset names, and is deduped
|
|
|
321
321
|
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
322
322
|
const first = await runHook("SessionStart", startPayload(f), env);
|
|
323
323
|
const boot = bootOf(first);
|
|
324
|
-
assert.match(boot, /YOUR NOTES/);
|
|
325
324
|
assert.ok(boot.includes(NOTES_PROTOCOL_OPEN_TAG) && boot.includes(MAPS_BLOCK), "Codex keeps teaching in its native boot hook");
|
|
326
325
|
assert.match(boot, new RegExp(`Agent name: anonymous \\(brain: gpt-5-4\\)`));
|
|
327
326
|
assert.match(boot, new RegExp(`codex:${ROOT}`));
|
|
328
327
|
assert.match(boot, new RegExp(`<notesoup:codex_window>\\nthread: ${ROOT}\\nwindow: ${W0}`));
|
|
329
|
-
|
|
330
|
-
assert.match(boot, new RegExp(`${W0} {4}← you are here`));
|
|
331
|
-
assert.match(boot, /native `new_context`/);
|
|
328
|
+
assert.ok(boot.includes("`new_context`"), "the protocol speaks Codex's own reset tool");
|
|
332
329
|
assert.match(boot, /get_context_remaining/);
|
|
333
330
|
assert.match(boot, /notes_\*/);
|
|
334
331
|
assert.doesNotMatch(boot, /empty_brain/);
|
|
335
|
-
assert.match(boot, /Child limitation/);
|
|
336
332
|
const binding = JSON.parse(readFileSync(join(f.data, "bindings", `${ROOT}.json`), "utf8"));
|
|
337
333
|
assert.equal(binding.rootSessionId, ROOT);
|
|
338
334
|
assert.equal(binding.home, f.home);
|
|
@@ -377,7 +373,7 @@ test("a fork gets its own boot instead of inheriting the parent's recorded ident
|
|
|
377
373
|
const boot = parsed.hookSpecificOutput?.additionalContext ?? "";
|
|
378
374
|
assert.match(boot, new RegExp(`thread: ${FORK}`));
|
|
379
375
|
assert.match(boot, new RegExp(`Agent name: worker \\(brain: gpt-5-4\\)`));
|
|
380
|
-
assert.
|
|
376
|
+
assert.ok(boot.includes("worker map"), "the subagent reads its own library, not the parent's");
|
|
381
377
|
assert.equal(JSON.parse(readFileSync(join(f.data, "bindings", `${FORK}.json`), "utf8")).rootSessionId, ROOT);
|
|
382
378
|
});
|
|
383
379
|
test("child PreCompact stops before native history is cut; root PreCompact is transparent", async (t) => {
|