notesoup 0.58.2 → 0.58.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/boot/text.d.ts +1 -1
- package/dist/src/boot/text.js +5 -4
- 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 +18 -13
- package/dist/test/claude-history.test.js +1 -2
- package/dist/test/claude-mod.test.js +16 -8
- 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/dsh.md +1 -1
- package/docs/notes-library.md +1 -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 +10 -8
- 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/codex/dist/codex/notesoup.js +10 -8
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/text.ts +5 -4
- package/src/notes/policy.ts +4 -3
- package/src/tools/notes.ts +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ Notes have optional `pinned`, `budget`, and `readonly` frontmatter fields, also
|
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
- **Pinned** notes are injected **in full** at boot. Root `CHEATSHEET.md` and `MAP.md` default to pinned; every other page defaults to unpinned. Explicit `pinned: false` overrides even a default page. Each notebook allows **five live pins**, including its existing default pages; crumpled notes do not count. A sixth pin, restore or move that exceeds the cap refuses without changing either note. Manually over-cap notebooks get a boot warning naming the omitted pins, with default pages shown first.
|
|
63
|
-
- **Budget** defaults to **
|
|
63
|
+
- **Budget** defaults to **4096 Unicode code points for ordinary pages**, and **2048 for root CHEATSHEET.md and MAP.md**. Any positive safe integer is allowed. Over-budget writes and updates succeed with a visible warning; pinned bodies are never truncated to their budget. This advisory budget is separate from the existing hard serialized-file byte limit. Tool results/read metadata/list/search expose effective policy and budget warnings.
|
|
64
64
|
- **Readonly** defaults to false. `readonly: true` is a **soft lock**, not security: mutations refuse until explicitly unlocked with `readonly: false`, either by itself or in the same call as the requested changes. A write can create and lock a note together. Reads still record access metadata; direct filesystem edits can bypass the lock.
|
|
65
65
|
|
|
66
66
|
Absent fields stay absent on disk. On move/rename, implicit pin defaults follow the new root path; explicit true/false values travel with the note. The original origin, other metadata, and unknown frontmatter are preserved. See the [library API](docs/notes-library.md#per-note-policy) for details.
|
package/dist/src/boot/text.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, p
|
|
|
15
15
|
/**
|
|
16
16
|
* Default pinned pages and per-note policy are taught between the protocol and the notes index.
|
|
17
17
|
*/
|
|
18
|
-
export declare const MAPS_BLOCK = "<notesoup:maps>\nEvery notebook's root has two default pins: `CHEATSHEET.md` and `MAP.md`.\nPinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next\nreads them, and next is you. So keep them short, and keep them true.\n\nSet `pinned`, `budget`, and `readonly` with the note tools or frontmatter. Each notebook allows five\nlive pins, including the defaults; `pinned:false` unpins even a default page.
|
|
18
|
+
export declare const MAPS_BLOCK = "<notesoup:maps>\nEvery notebook's root has two default pins: `CHEATSHEET.md` and `MAP.md`.\nPinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next\nreads them, and next is you. So keep them short, and keep them true.\n\nSet `pinned`, `budget`, and `readonly` with the note tools or frontmatter. Each notebook allows five\nlive pins, including the defaults; `pinned:false` unpins even a default page. Budgets start at 4096\nUnicode code points, or 2048 for root `CHEATSHEET.md` and `MAP.md`; set a positive integer to\nchange one. Going over warns but saves, and pinned bodies arrive whole, not cut short.\n`readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock,\non its own or with your changes.\n\n- **`CHEATSHEET.md`** holds what you'll want next time \u2014 a rule, a warning, a grudge, a name,\n a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat\n and everybody pays for it.\n- **`MAP.md`** is only the note index. One line per durable note: the address, then a gist short\n enough to tell whether the thing is worth opening. Rules belong in `CHEATSHEET.md`, and note\n contents belong in their own notes \u2014 *taps the sign* not inline here.\n\nEach notebook keeps its own: `@project`, `@human`, `@self`, `@model`. Missing pages are skipped;\nno need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet\nline. And when a line stops being true, kill it \u2014 every window after you reads that page as fact.\n</notesoup:maps>";
|
|
19
19
|
/** Logical tool names are supplied by the composing host, not discovered here. */
|
|
20
20
|
export type BootToolNames = Readonly<{
|
|
21
21
|
notes: string;
|
package/dist/src/boot/text.js
CHANGED
|
@@ -62,10 +62,11 @@ Pinned pages get jammed straight into your brain the moment you wake up. Whoever
|
|
|
62
62
|
reads them, and next is you. So keep them short, and keep them true.
|
|
63
63
|
|
|
64
64
|
Set \`pinned\`, \`budget\`, and \`readonly\` with the note tools or frontmatter. Each notebook allows five
|
|
65
|
-
live pins, including the defaults; \`pinned:false\` unpins even a default page.
|
|
66
|
-
|
|
67
|
-
and pinned bodies arrive whole, not cut short.
|
|
68
|
-
explicitly set \`readonly:false\` to unlock,
|
|
65
|
+
live pins, including the defaults; \`pinned:false\` unpins even a default page. Budgets start at 4096
|
|
66
|
+
Unicode code points, or 2048 for root \`CHEATSHEET.md\` and \`MAP.md\`; set a positive integer to
|
|
67
|
+
change one. Going over warns but saves, and pinned bodies arrive whole, not cut short.
|
|
68
|
+
\`readonly:true\` is a soft lock, not security; explicitly set \`readonly:false\` to unlock,
|
|
69
|
+
on its own or with your changes.
|
|
69
70
|
|
|
70
71
|
- **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
|
|
71
72
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
@@ -4,7 +4,7 @@ export type NotePolicyFields = {
|
|
|
4
4
|
readonly?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export type NotePolicy = Required<NotePolicyFields>;
|
|
7
|
-
export declare const DEFAULT_NOTE_BUDGET =
|
|
7
|
+
export declare const DEFAULT_NOTE_BUDGET = 4096;
|
|
8
8
|
export declare const MAX_PINNED_NOTES = 5;
|
|
9
9
|
export declare function validateNotePolicy(fields: NotePolicyFields): void;
|
|
10
10
|
/** Only root default pages are pinned implicitly; an explicit false always wins. */
|
package/dist/src/notes/policy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NoteError } from "./errors.js";
|
|
2
|
-
export const DEFAULT_NOTE_BUDGET =
|
|
2
|
+
export const DEFAULT_NOTE_BUDGET = 4096;
|
|
3
3
|
export const MAX_PINNED_NOTES = 5;
|
|
4
4
|
/** Defaults and ordering live here; no other layer assigns behavior by page name. */
|
|
5
5
|
const DEFAULT_PINNED_PAGES = ["CHEATSHEET.md", "MAP.md"];
|
|
@@ -15,9 +15,10 @@ export function validateNotePolicy(fields) {
|
|
|
15
15
|
/** Only root default pages are pinned implicitly; an explicit false always wins. */
|
|
16
16
|
export function effectiveNotePolicy(fields, path) {
|
|
17
17
|
validateNotePolicy(fields);
|
|
18
|
+
const defaultPage = DEFAULT_PINNED_PAGES.some(page => page === path);
|
|
18
19
|
return {
|
|
19
|
-
pinned: fields.pinned ??
|
|
20
|
-
budget: fields.budget ?? DEFAULT_NOTE_BUDGET,
|
|
20
|
+
pinned: fields.pinned ?? defaultPage,
|
|
21
|
+
budget: fields.budget ?? (defaultPage ? 2048 : DEFAULT_NOTE_BUDGET),
|
|
21
22
|
readonly: fields.readonly ?? false,
|
|
22
23
|
};
|
|
23
24
|
}
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -17,7 +17,7 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
|
17
17
|
}));
|
|
18
18
|
const POLICY_PARAMETERS = {
|
|
19
19
|
pinned: Type.Optional(Type.Boolean({ description: "Inject the full body at boot. At most 5 live pins per notebook; root CHEATSHEET.md/MAP.md default true, all others false. Explicit false overrides the default." })),
|
|
20
|
-
budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "Body budget in Unicode code points (default
|
|
20
|
+
budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "Body budget in Unicode code points (default 4096; root CHEATSHEET.md and MAP.md default 2048). Over budget warns but saves; boot does not truncate." })),
|
|
21
21
|
readonly: Type.Optional(Type.Boolean({ description: "Soft lock, not a security boundary. true locks changes; explicitly pass false to unlock, including in the same call as edits or overwrite." })),
|
|
22
22
|
};
|
|
23
23
|
const PolicySchema = {
|
|
@@ -10,7 +10,7 @@ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL
|
|
|
10
10
|
import { historyFromSession } from "../plugins/pi/history.js";
|
|
11
11
|
import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
|
|
12
12
|
import { assertBootHistory } from "./helpers/extension.js";
|
|
13
|
-
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
|
|
13
|
+
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NAMELESS_AGENT, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
|
|
14
14
|
import { createNotesStore } from "../src/notes/index.js";
|
|
15
15
|
import { agentSlug } from "../plugins/pi/notes/adapter.js";
|
|
16
16
|
import { registerBudget } from "../plugins/pi/budget.js";
|
|
@@ -70,7 +70,6 @@ async function openFixture(options) {
|
|
|
70
70
|
const streamSignals = [];
|
|
71
71
|
const events = [];
|
|
72
72
|
const notices = [];
|
|
73
|
-
let budgetNotices = 0;
|
|
74
73
|
let session;
|
|
75
74
|
const loader = new DefaultResourceLoader({
|
|
76
75
|
cwd: dir,
|
|
@@ -132,15 +131,7 @@ async function openFixture(options) {
|
|
|
132
131
|
};
|
|
133
132
|
await session.bindExtensions({
|
|
134
133
|
uiContext: {
|
|
135
|
-
notify(message
|
|
136
|
-
if (message === "🥣 Brain forcibly emptied: overflow") {
|
|
137
|
-
const marker = sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).at(-1);
|
|
138
|
-
const windowId = marker?.data?.windowId;
|
|
139
|
-
assert.ok(sessionManager.getBranch().some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE && entry.data?.windowId === windowId), "notification follows the reset marker commit");
|
|
140
|
-
assert.ok(sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE && entry.details?.windowId === windowId), "notification follows the reset boot commit");
|
|
141
|
-
}
|
|
142
|
-
if (type === "warning" && /^🥣 Brain almost full/.test(message))
|
|
143
|
-
budgetNotices++;
|
|
134
|
+
notify(message) {
|
|
144
135
|
notices.push(message);
|
|
145
136
|
},
|
|
146
137
|
},
|
|
@@ -156,7 +147,6 @@ async function openFixture(options) {
|
|
|
156
147
|
streamSignals,
|
|
157
148
|
events,
|
|
158
149
|
notices,
|
|
159
|
-
budgetNotices: () => budgetNotices,
|
|
160
150
|
close: () => {
|
|
161
151
|
session.dispose();
|
|
162
152
|
if (managesEnvironment) {
|
|
@@ -213,8 +203,6 @@ const COMMAND_WARNING_JSON = JSON.stringify(commandWarningContent()).slice(1, -1
|
|
|
213
203
|
function assertUserContent(context, content) {
|
|
214
204
|
assert.ok(context?.messages.some((message) => message.role === "user" && JSON.stringify(message.content) === JSON.stringify(content)), "carried input reaches the provider verbatim as user content");
|
|
215
205
|
}
|
|
216
|
-
/** Recognize reset completion notices, including the removed normal-reset wording. */
|
|
217
|
-
const isResetSuccessNotice = (notice) => notice.includes("🥣 Fresh brain") || notice.includes("🥣 Brain forcibly emptied");
|
|
218
206
|
function resetMarkers(fixture) {
|
|
219
207
|
return fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
220
208
|
}
|
|
@@ -304,7 +292,7 @@ test("real AgentSession: protocol and tool directory stay in system while window
|
|
|
304
292
|
const boots = context.messages.filter((message) => message.role === "user" && JSON.stringify(message.content).includes(WINDOW_IDENTITY_OPEN_TAG));
|
|
305
293
|
assert.equal(boots.length, 1, "one user boot reaches the provider");
|
|
306
294
|
const boot = JSON.stringify(boots[0]);
|
|
307
|
-
assert.ok(boot.includes(
|
|
295
|
+
assert.ok(boot.includes(request === 3 ? "HUMAN_PIN_AFTER_RESET" : "HUMAN_PIN_BEFORE_RESET"), "the notes snapshot changes only at reset");
|
|
308
296
|
assert.equal(boot.includes(NOTES_PROTOCOL_OPEN_TAG), false);
|
|
309
297
|
assert.equal(boot.includes("<notesoup:maps>"), false);
|
|
310
298
|
assert.equal(context.messages.filter((message) => message.role === "system" && message.sections?.notesoup_protocol !== undefined).length, 1, "unchanged teaching adds no duplicate delta");
|
|
@@ -358,7 +346,7 @@ test("real AgentSession: identity changes update system teaching and the next bo
|
|
|
358
346
|
compactionEnabled: false,
|
|
359
347
|
script: (request, context) => {
|
|
360
348
|
const protocol = getCurrentSystemMessage(context.messages)?.sections?.notesoup_protocol;
|
|
361
|
-
assert.
|
|
349
|
+
assert.ok(protocol?.includes(renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, request === 1 ? NAMELESS_AGENT : "boot-tester")), "the protocol follows the live named/nameless identity");
|
|
362
350
|
if (request >= 3) {
|
|
363
351
|
const boot = context.messages.find((message) => message.role === "user" && JSON.stringify(message.content).includes(WINDOW_IDENTITY_OPEN_TAG));
|
|
364
352
|
assert.ok(JSON.stringify(boot).includes("Agent name: boot-tester (brain: boot-split-model)"));
|
|
@@ -445,22 +433,21 @@ test("real AgentSession: aborted early guidance retries silently", async () => {
|
|
|
445
433
|
});
|
|
446
434
|
try {
|
|
447
435
|
const guidance = () => fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE);
|
|
448
|
-
const notices = () => fixture.budgetNotices();
|
|
449
436
|
await fixture.session.prompt("Establish usage below the reminder line.");
|
|
450
437
|
await fixture.session.waitForIdle();
|
|
451
438
|
assert.equal(guidance().length, 0);
|
|
452
439
|
await fixture.session.prompt("Abort this low-budget request.");
|
|
453
440
|
await fixture.session.waitForIdle();
|
|
454
441
|
assert.equal(guidance().length, 0, "an aborted turn does not commit early guidance");
|
|
455
|
-
assert.equal(notices
|
|
442
|
+
assert.equal(fixture.notices.length, 0, "early guidance never notifies");
|
|
456
443
|
await fixture.session.prompt("Retry successfully.");
|
|
457
444
|
await fixture.session.waitForIdle();
|
|
458
445
|
assert.equal(guidance().length, 1, "the successful retry commits the model guidance");
|
|
459
|
-
assert.equal(notices
|
|
446
|
+
assert.equal(fixture.notices.length, 0, "committed early guidance stays UI-silent");
|
|
460
447
|
await fixture.session.prompt("Continue in the same window.");
|
|
461
448
|
await fixture.session.waitForIdle();
|
|
462
449
|
assert.equal(guidance().length, 1);
|
|
463
|
-
assert.equal(notices
|
|
450
|
+
assert.equal(fixture.notices.length, 0, "later turns cannot toast the early reminder");
|
|
464
451
|
}
|
|
465
452
|
finally {
|
|
466
453
|
fixture.close();
|
|
@@ -523,25 +510,23 @@ test("real AgentSession: a final warning notifies before the response, even if a
|
|
|
523
510
|
if (request === 2)
|
|
524
511
|
return assistant(fixture, [{ type: "toolCall", id: "abort-budget-probe-2", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(60_000) });
|
|
525
512
|
assert.ok(text(context).includes(WARNING_JSON), "the final warning reaches the model on both attempts");
|
|
526
|
-
assert.equal(fixture.
|
|
513
|
+
assert.equal(fixture.notices.length, 1, "the UI is notified before the model responds, once across retries");
|
|
527
514
|
return assistant(fixture, [{ type: "text", text: `response ${request}` }], request === 3 ? "aborted" : "stop", { usage: usage(60_000) });
|
|
528
515
|
},
|
|
529
516
|
});
|
|
530
517
|
try {
|
|
531
518
|
const warnings = () => fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === WARNING_TYPE);
|
|
532
|
-
const notices = () => fixture.budgetNotices();
|
|
533
519
|
await fixture.session.prompt("Establish usage and reach the final runway.");
|
|
534
520
|
await fixture.session.waitForIdle();
|
|
535
521
|
assert.equal(fixture.requests.length, 3, "budget probes reach one final-warning attempt");
|
|
536
522
|
assert.equal(warnings().length, 0, "the aborted attempt leaves no durable warning");
|
|
537
|
-
assert.equal(notices
|
|
523
|
+
assert.equal(fixture.notices.length, 1, "the aborted request already notified at injection");
|
|
538
524
|
await fixture.session.prompt("Retry successfully.");
|
|
539
525
|
await fixture.session.waitForIdle();
|
|
540
526
|
assert.equal(warnings().length, 1, "the successful retry commits one hidden warning");
|
|
541
527
|
assert.equal(resetMarkers(fixture).length, 0, "committing the warning does not authorize a reset at normal stop");
|
|
542
528
|
assert.equal(fixture.requests.length, 4, "the retry settles without a fresh-window continuation");
|
|
543
|
-
assert.equal(notices
|
|
544
|
-
assert.equal(fixture.notices.some((notice) => notice.includes("Context running low")), false, "early guidance remains UI-silent");
|
|
529
|
+
assert.equal(fixture.notices.length, 1, "committing the retry does not repeat the notification");
|
|
545
530
|
}
|
|
546
531
|
finally {
|
|
547
532
|
fixture.close();
|
|
@@ -558,7 +543,7 @@ test("real AgentSession: final warning survives its reset boundary and notifies
|
|
|
558
543
|
return assistant(fixture, [{ type: "toolCall", id: "final-budget-probe-2", name: "get_context_remaining", arguments: {} }], "toolUse", { usage: usage(60_000) });
|
|
559
544
|
if (request === 3) {
|
|
560
545
|
assert.ok(text(context).includes(WARNING_JSON), "the final warning reaches the model");
|
|
561
|
-
assert.equal(fixture.
|
|
546
|
+
assert.equal(fixture.notices.length, 1, "warning notifies before the wipe tool runs");
|
|
562
547
|
return assistant(fixture, [{ type: "toolCall", id: "final-budget-wipe", name: "empty_brain", arguments: {} }], "toolUse", { usage: usage(60_000) });
|
|
563
548
|
}
|
|
564
549
|
return assistant(fixture, [{ type: "text", text: "fresh window ready" }]);
|
|
@@ -572,13 +557,10 @@ test("real AgentSession: final warning survives its reset boundary and notifies
|
|
|
572
557
|
assertFreshRequest(fixture, 3, "FINAL_WARNING_RESET_SENTINEL");
|
|
573
558
|
assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === WARNING_TYPE).length, 1);
|
|
574
559
|
assert.equal(resetMarkers(fixture).length, 1, "the reset commits in the same boundary as the final warning");
|
|
575
|
-
assert.equal(fixture.
|
|
576
|
-
assert.equal(fixture.notices.filter(isResetSuccessNotice).length, 0, "normal reset completion stays silent");
|
|
577
|
-
assert.equal(fixture.notices.some((notice) => notice.includes("Context running low")), false, "early guidance stays silent");
|
|
560
|
+
assert.equal(fixture.notices.length, 1, "the old-window committed warning reaches the UI after reset");
|
|
578
561
|
await fixture.session.prompt("Continue after reset.");
|
|
579
562
|
await fixture.session.waitForIdle();
|
|
580
|
-
assert.equal(fixture.
|
|
581
|
-
assert.equal(fixture.notices.filter(isResetSuccessNotice).length, 0, "later turns do not announce normal reset completion");
|
|
563
|
+
assert.equal(fixture.notices.length, 1, "later turns cannot repeat the consumed final warning");
|
|
582
564
|
}
|
|
583
565
|
finally {
|
|
584
566
|
fixture.close();
|
|
@@ -598,7 +580,6 @@ test("real AgentSession: explicit tiny-session wipe ignores keepRecentTokens and
|
|
|
598
580
|
assert.equal(fixture.notices.length, 0, "startup boot is silent");
|
|
599
581
|
await fixture.session.prompt("OLD_CONTEXT_SENTINEL: retain this only in durable history.");
|
|
600
582
|
await fixture.session.waitForIdle();
|
|
601
|
-
assert.deepEqual(fixture.notices.filter(isResetSuccessNotice), [], "normal reset completion stays silent");
|
|
602
583
|
assert.equal(fixture.requests.length, 2, "the tool starts exactly one continuation");
|
|
603
584
|
assert.ok(text(fixture.requests[0]).includes("OLD_CONTEXT_SENTINEL"));
|
|
604
585
|
assertFreshRequest(fixture, 1, "OLD_CONTEXT_SENTINEL");
|
|
@@ -747,7 +728,6 @@ test("real AgentSession: /empty text is close-out context and stops after reset"
|
|
|
747
728
|
const branch = fixture.sessionManager.getBranch();
|
|
748
729
|
assert.equal(branch.some((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE), false);
|
|
749
730
|
assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("AFTER_CLEAR_PROMPT_SENTINEL"), false);
|
|
750
|
-
assert.equal(fixture.notices.some(isResetSuccessNotice), false);
|
|
751
731
|
}
|
|
752
732
|
finally {
|
|
753
733
|
fixture.close();
|
|
@@ -808,7 +788,6 @@ test("real AgentSession: streaming clear prompt keeps the first request", async
|
|
|
808
788
|
assert.equal(fixture.requests.length, 2);
|
|
809
789
|
assert.equal(fixture.sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE), false);
|
|
810
790
|
assert.equal(resetMarkers(fixture).length, 1);
|
|
811
|
-
assert.ok(fixture.notices.some((notice) => notice.includes("Brain already being emptied")));
|
|
812
791
|
}
|
|
813
792
|
finally {
|
|
814
793
|
release();
|
|
@@ -880,7 +859,6 @@ test("real AgentSession: manual hard-reserve reset stops clean and mixed-tool tu
|
|
|
880
859
|
assert.equal(fixture.requests.length, 2);
|
|
881
860
|
assert.equal(resetMarkers(fixture).length, 1, "the safety wipe is not repeated at settlement");
|
|
882
861
|
assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("HARD_RESERVE_OLD_SENTINEL"), false);
|
|
883
|
-
assert.equal(fixture.notices.some(isResetSuccessNotice), !mixed, "only forced reset completion notifies");
|
|
884
862
|
if (mixed) {
|
|
885
863
|
assert.ok(existsSync(join(fixture.notesRoot, "pi", "session", fixture.sessionManager.getSessionId(), "pressure.md")), "the whole tool batch completes before the cut");
|
|
886
864
|
assert.equal(fixture.streamSignals.at(-1), true, "Pi's unavoidable tool follow-up is cancelled before provider work");
|
|
@@ -917,7 +895,6 @@ test("real AgentSession: overflowing /empty close-out forces a reset and stops",
|
|
|
917
895
|
assert.equal(resetMarkers(fixture).length, 1);
|
|
918
896
|
assert.equal(fixture.sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE), false);
|
|
919
897
|
assert.equal(resetMarkers(fixture)[0].data.origin, "forced");
|
|
920
|
-
assert.ok(fixture.notices.some(isResetSuccessNotice));
|
|
921
898
|
}
|
|
922
899
|
finally {
|
|
923
900
|
fixture.close();
|
|
@@ -947,7 +924,6 @@ test("real AgentSession: streaming /empty steers a close-out and stops at settle
|
|
|
947
924
|
await started;
|
|
948
925
|
await fixture.session.prompt("/empty", { streamingBehavior: "steer" });
|
|
949
926
|
await fixture.session.prompt("/empty", { streamingBehavior: "followUp" });
|
|
950
|
-
assert.equal(fixture.notices.filter((notice) => notice.includes("Dumping Brain")).length, 1, "the user is notified once while output is ongoing");
|
|
951
927
|
assert.equal(resetMarkers(fixture).length, 0, "the ongoing turn is not interrupted");
|
|
952
928
|
releaseResponse();
|
|
953
929
|
await running;
|
|
@@ -956,7 +932,6 @@ test("real AgentSession: streaming /empty steers a close-out and stops at settle
|
|
|
956
932
|
assert.equal(fixture.requests.length, 2, "the warning closes out and the run stops — no continuation in the fresh window");
|
|
957
933
|
assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE).length, 1, "the busy warning is persisted once");
|
|
958
934
|
assert.equal(JSON.stringify(fixture.sessionManager.buildSessionProjection().messages).includes("STREAMING_WIPE_OLD_SENTINEL"), false);
|
|
959
|
-
assert.ok(fixture.notices.some(isResetSuccessNotice), "the committed boundary has a separate success notice");
|
|
960
935
|
}
|
|
961
936
|
finally {
|
|
962
937
|
releaseResponse();
|
|
@@ -1021,7 +996,6 @@ test("real AgentSession: user abort, synthetic aborted response, and generic err
|
|
|
1021
996
|
await fixture.session.waitForIdle();
|
|
1022
997
|
assert.equal(resetMarkers(fixture).length, 0, `${mode} does not force a reset`);
|
|
1023
998
|
assert.equal(fixture.sessionManager.getBranch().filter((entry) => entry.type === "compaction").length, 0);
|
|
1024
|
-
assert.equal(fixture.notices.some(isResetSuccessNotice), false);
|
|
1025
999
|
if (mode === "ctx-abort")
|
|
1026
1000
|
assert.equal(fixture.streamSignals.at(-1), true, "this case aborts the real Pi operation signal");
|
|
1027
1001
|
else
|
|
@@ -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,6 +4,7 @@ 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";
|
|
9
10
|
import { readThresholdSettings } from "../plugins/pi/thresholds.js";
|
|
@@ -11,6 +12,10 @@ import { NOTESOUP_SETTINGS_KEY } from "../src/settings.js";
|
|
|
11
12
|
import { appendText, call, commitTurnEndBoundary, context, makeExtension, manager, noticesOf, resultJson, runContextHook, runHandlers, sentOf, settingsFixture, writeJson, } from "./helpers/extension.js";
|
|
12
13
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
13
14
|
const testEnvironment = installExtensionTestHooks("notesoup-integration");
|
|
15
|
+
const explicitBudgetSettings = {
|
|
16
|
+
compaction: { enabled: true, reserveTokens: 16_384 },
|
|
17
|
+
notesoup: { reminderMarginTokens: 24_576, warningRunwayTokens: 16_384 },
|
|
18
|
+
};
|
|
14
19
|
test("budget derivation preserves defaults and validates overrides independently", () => {
|
|
15
20
|
assert.deepEqual(deriveThresholds(32_768, {}), {
|
|
16
21
|
thresholds: { reserve: 32_768, reminder: 57_344, warning: 49_152 }, warnings: [],
|
|
@@ -22,14 +27,14 @@ test("budget derivation preserves defaults and validates overrides independently
|
|
|
22
27
|
assert.deepEqual(invalid.thresholds, deriveThresholds(32_768, {}).thresholds);
|
|
23
28
|
assert.equal(invalid.warnings.length, 3);
|
|
24
29
|
for (const key of ["reserveTokens", "warningRunwayTokens", "reminderMarginTokens"]) {
|
|
25
|
-
assert.equal(invalid.warnings.filter((warning) => warning.includes(`notesoup.${key}
|
|
30
|
+
assert.equal(invalid.warnings.filter((warning) => warning.includes(`notesoup.${key}`)).length, 1);
|
|
26
31
|
}
|
|
27
32
|
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
33
|
});
|
|
29
34
|
test("Pi budget settings merge per key without changing native compaction settings or enablement", async () => {
|
|
30
35
|
const fixture = settingsFixture({
|
|
31
36
|
reserveTokens: 32_768,
|
|
32
|
-
global: { notesoup: { reserveTokens: 12_000, warningRunwayTokens: 20_000 } },
|
|
37
|
+
global: { notesoup: { reserveTokens: 12_000, warningRunwayTokens: 20_000, reminderMarginTokens: 24_576 } },
|
|
33
38
|
project: { notesoup: { reserveTokens: 8192 } },
|
|
34
39
|
});
|
|
35
40
|
const sm = manager();
|
|
@@ -57,7 +62,7 @@ test("Pi budget settings merge per key without changing native compaction settin
|
|
|
57
62
|
assert.equal(disabled.getCompactionSettings().enabled, false);
|
|
58
63
|
});
|
|
59
64
|
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 } } });
|
|
65
|
+
const fixture = settingsFixture({ reserveTokens: 32_768, global: { notesoup: { reserveTokens: 8192, warningRunwayTokens: 16_384, reminderMarginTokens: 24_576 } } });
|
|
61
66
|
const sm = manager();
|
|
62
67
|
appendText(sm, "user", "ongoing work");
|
|
63
68
|
const captured = makeExtension(sm);
|
|
@@ -65,7 +70,7 @@ test("Pi warning, reported room, and hard wipe use the notesoup reserve override
|
|
|
65
70
|
const at = (remaining) => context(sm, undefined, { tokens: 200_000 - remaining, percent: 0, contextWindow: 200_000 }, true, fixture.cwd);
|
|
66
71
|
const early = await runContextHook(captured, at(24_577));
|
|
67
72
|
assert.equal(early?.messages[0]?.customType, GUIDANCE_TYPE, "no warning above reserve + runway");
|
|
68
|
-
assert.
|
|
73
|
+
assert.equal(early?.messages[0]?.content, tokenBudgetGuidance(16_385, "empty_brain"), "guidance subtracts the overridden reserve");
|
|
69
74
|
const warning = await runContextHook(captured, at(24_576));
|
|
70
75
|
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE, "warn at 8192 + 16384, not native reserve + runway");
|
|
71
76
|
const room = async (remaining) => resultJson(await call(captured, "get_context_remaining", {}, at(remaining))).remaining_tokens;
|
|
@@ -79,11 +84,11 @@ test("Pi warning, reported room, and hard wipe use the notesoup reserve override
|
|
|
79
84
|
});
|
|
80
85
|
test("low-budget guidance and warning persist at turn_end, once per active window", async () => {
|
|
81
86
|
const sessionManager = manager();
|
|
82
|
-
const captured = makeExtension(sessionManager);
|
|
87
|
+
const captured = makeExtension(sessionManager, SettingsManager.inMemory(explicitBudgetSettings));
|
|
83
88
|
const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
84
89
|
const guidance = await runContextHook(captured, low);
|
|
85
90
|
assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
|
|
86
|
-
assert.
|
|
91
|
+
assert.equal((guidance?.messages[0]).content, tokenBudgetGuidance(18_616, "empty_brain"), "the reminder reports room to the reserve, not to the warning");
|
|
87
92
|
assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
|
|
88
93
|
const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
|
|
89
94
|
assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
|
|
@@ -99,22 +104,22 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
|
|
|
99
104
|
});
|
|
100
105
|
test("early guidance stays silent and the final warning notifies immediately once", async () => {
|
|
101
106
|
const sm = manager();
|
|
102
|
-
const captured = makeExtension(sm);
|
|
107
|
+
const captured = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
103
108
|
const early = context(sm, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
104
109
|
assert.equal((await runContextHook(captured, early))?.messages.length, 1, "early guidance reaches the crossing request");
|
|
105
110
|
await commitTurnEndBoundary(captured, sm, early);
|
|
106
111
|
await runHandlers(captured, "agent_settled", {}, early);
|
|
107
|
-
assert.equal(noticesOf(early).filter((notice) => notice.
|
|
112
|
+
assert.equal(noticesOf(early).filter((notice) => notice.type === "warning").length, 0, "early model guidance has no UI toast");
|
|
108
113
|
assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "early guidance remains durable for the model");
|
|
109
114
|
const final = context(sm, undefined, { tokens: 181_000, percent: 90.5, contextWindow: 200_000 });
|
|
110
115
|
const warning = await runContextHook(captured, final);
|
|
111
116
|
assert.equal(warning?.messages[0]?.customType, WARNING_TYPE);
|
|
112
|
-
assert.equal(noticesOf(final).filter((notice) => notice.
|
|
117
|
+
assert.equal(noticesOf(final).filter((notice) => notice.type === "warning").length, 1, "notify at injection, before any turn_end");
|
|
113
118
|
await runContextHook(captured, final);
|
|
114
119
|
await commitTurnEndBoundary(captured, sm, final);
|
|
115
120
|
await runHandlers(captured, "turn_start", {}, final);
|
|
116
121
|
await runHandlers(captured, "agent_settled", {}, final);
|
|
117
|
-
assert.equal(noticesOf(final).filter((notice) => notice.
|
|
122
|
+
assert.equal(noticesOf(final).filter((notice) => notice.type === "warning").length, 1, "repeated injection and commit do not notify again");
|
|
118
123
|
});
|
|
119
124
|
test("get_context_remaining declares its output and returns matching structured and text values", async () => {
|
|
120
125
|
const fixture = settingsFixture({ reserveTokens: 16_384 });
|
|
@@ -146,7 +151,7 @@ test("the reported room ends at the hard reserve, clamps at zero, and preserves
|
|
|
146
151
|
return resultJson(await call(captured, "get_context_remaining", {}, ctx)).remaining_tokens;
|
|
147
152
|
};
|
|
148
153
|
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, "
|
|
154
|
+
assert.equal(await readBudget(150_848), 16_384, "an intermediate usage reports the room above the configured reserve");
|
|
150
155
|
assert.equal(await readBudget(167_232), 0, "the hard reserve reads zero");
|
|
151
156
|
assert.equal(await readBudget(190_000), 0, "below the reserve, still zero");
|
|
152
157
|
assert.equal(await readBudget(210_000), 0, "over the physical window");
|
|
@@ -226,12 +231,12 @@ test("an invalid reminder margin degrades to its default with one warning and ne
|
|
|
226
231
|
test("the warning supersedes the early reminder when usage jumps across both thresholds", async () => {
|
|
227
232
|
const sm = manager();
|
|
228
233
|
appendText(sm, "user", "ongoing work");
|
|
229
|
-
const captured = makeExtension(sm);
|
|
234
|
+
const captured = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
230
235
|
const ctx = context(sm, undefined, { tokens: 199_000, percent: 99.5, contextWindow: 200_000 }, false);
|
|
231
236
|
const warningResult = await runContextHook(captured, ctx);
|
|
232
237
|
assert.deepEqual(warningResult?.messages.map((message) => message.customType), [WARNING_TYPE]);
|
|
233
238
|
await commitTurnEndBoundary(captured, sm, ctx);
|
|
234
|
-
const reloaded = makeExtension(sm);
|
|
239
|
+
const reloaded = makeExtension(sm, SettingsManager.inMemory(explicitBudgetSettings));
|
|
235
240
|
await runHandlers(reloaded, "context", { messages: [] }, ctx);
|
|
236
241
|
assert.equal(reloaded.sent.length, 0, "persisted warning also suppresses a late reminder after reload");
|
|
237
242
|
});
|
|
@@ -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/);
|
|
@@ -497,12 +497,12 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
497
497
|
...upstream,
|
|
498
498
|
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
499
|
}, "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.
|
|
500
|
+
const expectedNotifications = mode === "no ui" || mode === "no toast" ? 0 : 1;
|
|
501
|
+
assert.equal(notifications.length, expectedNotifications, "one user-facing notification reports the notes boot failure");
|
|
502
502
|
assert.equal(bootRequests, 1);
|
|
503
503
|
assert.equal(nextCalls, 1);
|
|
504
504
|
assert.deepEqual(await promptContext(structuredClone(failed)), failed);
|
|
505
|
-
assert.
|
|
505
|
+
assert.equal(notifications.length, expectedNotifications, "a persisted fallback does not notify again");
|
|
506
506
|
assert.equal(bootRequests, 1, "a persisted fallback needs no second boot request");
|
|
507
507
|
assert.equal(nextCalls, 2, "the upstream chain still runs exactly once per prompt");
|
|
508
508
|
});
|
|
@@ -530,8 +530,17 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
530
530
|
assert.equal(wipeSchema.required, undefined, "both arguments are optional");
|
|
531
531
|
assert.equal(wipeSchema.additionalProperties, false);
|
|
532
532
|
const call = (tool, params) => handlers.get("tool.call")(host, { tool: `mcp__notesoup__${tool}`, tool_use_id: "hook-1", ...params }, async (event) => event);
|
|
533
|
+
let helperText;
|
|
534
|
+
const run = host.process.run;
|
|
535
|
+
host.process.run = async (argv, init) => {
|
|
536
|
+
const response = await run(argv, init);
|
|
537
|
+
if (JSON.parse(init.stdin).op === "tool")
|
|
538
|
+
helperText = JSON.parse(response.stdout).result.text;
|
|
539
|
+
return response;
|
|
540
|
+
};
|
|
533
541
|
const written = await call("notes_write", { address: "hook.md", content: "hook body" });
|
|
534
|
-
assert.equal(
|
|
542
|
+
assert.equal(typeof helperText, "string");
|
|
543
|
+
assert.equal(written.result, helperText, "the hook hands back the shared text unchanged");
|
|
535
544
|
assert.equal("isError" in written, false, "a success carries no discriminator at all, not a false one");
|
|
536
545
|
const refused = await call("notes_read", { address: "absent.md" });
|
|
537
546
|
assert.equal(refused.isError, true, "a refusal carries the literal the public ToolCallResult declares");
|
|
@@ -1583,7 +1592,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
1583
1592
|
const run = host.process.run;
|
|
1584
1593
|
host.process.run = async (argv, init) => { requests.push(JSON.parse(init.stdin)); return run(argv, init); };
|
|
1585
1594
|
const written = await invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "new-session", address: "session.md", content: action });
|
|
1586
|
-
assert.
|
|
1595
|
+
assert.match(written.result, /^created session\.md\b/);
|
|
1587
1596
|
assert.equal(requests[0].identity?.sessionId, `after-${action}`, "tools also use the new session notebook");
|
|
1588
1597
|
});
|
|
1589
1598
|
}
|
|
@@ -1660,7 +1669,7 @@ test("Claude serves every registered notes tool to subagents without leaking eve
|
|
|
1660
1669
|
const call = (tool, params) => invoke("tool.call", {
|
|
1661
1670
|
tool: `mcp__notesoup__${tool}`, tool_use_id: "child-call", agentId: "child", ...params,
|
|
1662
1671
|
});
|
|
1663
|
-
assert.equal((await call("notes_write", { address: "child.md", content: "child body" })).
|
|
1672
|
+
assert.equal((await call("notes_write", { address: "child.md", content: "child body" })).isError, undefined);
|
|
1664
1673
|
assert.match((await call("notes_read", { address: "child.md" })).result, /child body/);
|
|
1665
1674
|
assert.equal((await call("notes_update", { address: "child.md", edits: [{ oldText: "child body", newText: "updated body" }] })).isError, undefined);
|
|
1666
1675
|
assert.match((await call("notes_list", {})).result, /child\.md/);
|
|
@@ -1682,7 +1691,7 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
|
|
|
1682
1691
|
return run(argv, init);
|
|
1683
1692
|
};
|
|
1684
1693
|
const write = (address, content) => invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "model-call", address, content });
|
|
1685
|
-
|
|
1694
|
+
await write("@model/model.md", "opus");
|
|
1686
1695
|
assert.equal(seen.at(-1).identity.model, "claude-opus-4-6");
|
|
1687
1696
|
assert.ok(readFileSync(join(home, "models/claude-opus-4-6/model.md"), "utf8").includes("opus"));
|
|
1688
1697
|
model = "Claude Sonnet 4.6";
|
|
@@ -1718,7 +1727,6 @@ test("Claude current-cwd project resolution shares Pi's remote notebook across c
|
|
|
1718
1727
|
cwd = second;
|
|
1719
1728
|
const written = await call("notes_write", { address: "@project/shared", content: "Claude body" });
|
|
1720
1729
|
assert.equal(written.isError, undefined);
|
|
1721
|
-
assert.equal(written.result, "overwrote @project/shared.md (project api) | pinned false | budget 2048 | readonly false");
|
|
1722
1730
|
assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
|
|
1723
1731
|
assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
|
|
1724
1732
|
assert.equal(resolveProjectNamespace(second, home).name, piIdentity.projectKey);
|