notesoup 0.40.0 โ 0.42.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/dist/src/boot/render.js +1 -1
- package/dist/src/boot/text.d.ts +12 -0
- package/dist/src/boot/text.js +25 -5
- package/dist/src/budget/policy.js +1 -1
- package/dist/src/budget/text.d.ts +12 -0
- package/dist/src/budget/text.js +13 -1
- package/dist/src/claude/helper.js +23 -2
- package/dist/src/claude/thresholds.d.ts +39 -0
- package/dist/src/claude/thresholds.js +149 -0
- package/dist/src/dream/doctor.js +3 -2
- package/dist/src/dream/git.js +2 -1
- package/dist/src/dream/jail.js +10 -10
- package/dist/src/dream/report.js +3 -2
- package/dist/src/error-message.d.ts +2 -0
- package/dist/src/error-message.js +4 -0
- package/dist/src/history/history.js +1 -1
- package/dist/src/history/query.js +6 -6
- package/dist/src/notes/address.d.ts +1 -1
- package/dist/src/notes/address.js +12 -12
- package/dist/src/notes/store.js +16 -12
- package/dist/src/pi/anchored.d.ts +16 -0
- package/dist/src/pi/anchored.js +55 -0
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +33 -28
- package/dist/src/pi/dream/cli.js +3 -2
- package/dist/src/pi/dream/runner.js +2 -1
- package/dist/src/pi/reset/lifecycle.d.ts +1 -1
- package/dist/src/pi/reset/lifecycle.js +4 -3
- package/dist/src/pi/reset/text.d.ts +3 -4
- package/dist/src/pi/reset/text.js +5 -4
- package/dist/src/pi/runtime.js +13 -16
- package/dist/src/pi/thresholds.js +2 -1
- package/dist/src/pi/tool-result.js +2 -2
- package/dist/src/settings.d.ts +8 -0
- package/dist/src/settings.js +6 -1
- package/dist/src/tools/history.js +12 -12
- package/dist/src/tools/notes.d.ts +3 -3
- package/dist/src/tools/notes.js +12 -11
- package/dist/src/tools/output.d.ts +2 -0
- package/dist/src/tools/output.js +2 -0
- package/dist/src/tools/result.js +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +78 -28
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/budget-settings.integration.test.js +9 -8
- package/dist/test/claude-mod.test.js +213 -23
- package/dist/test/dream.test.js +3 -3
- package/dist/test/history.integration.test.js +7 -8
- package/dist/test/host-neutral.test.js +2 -2
- package/dist/test/notes-library.test.js +1 -1
- package/dist/test/notes.integration.test.js +5 -5
- package/dist/test/notes.test.js +16 -16
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/claude-code-mod.md +10 -2
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +212 -45
- package/mods/notesoup/hooks/register.ts +209 -48
- package/mods/notesoup/playbook.md +10 -10
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/package.json +1 -1
- package/playbook.md +10 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +5 -3
- package/src/boot/render.ts +1 -1
- package/src/boot/text.ts +31 -5
- package/src/budget/policy.ts +1 -1
- package/src/budget/text.ts +18 -1
- package/src/claude/helper.ts +20 -3
- package/src/claude/thresholds.ts +170 -0
- package/src/dream/doctor.ts +3 -2
- package/src/dream/git.ts +2 -1
- package/src/dream/jail.ts +10 -10
- package/src/dream/report.ts +3 -2
- package/src/error-message.ts +4 -0
- package/src/history/history.ts +1 -1
- package/src/history/query.ts +6 -6
- package/src/notes/address.ts +12 -12
- package/src/notes/store.ts +17 -12
- package/src/pi/anchored.ts +62 -0
- package/src/pi/budget.ts +27 -26
- package/src/pi/dream/cli.ts +3 -2
- package/src/pi/dream/runner.ts +2 -1
- package/src/pi/reset/lifecycle.ts +5 -4
- package/src/pi/reset/text.ts +6 -7
- package/src/pi/runtime.ts +13 -16
- package/src/pi/thresholds.ts +2 -1
- package/src/pi/tool-result.ts +2 -2
- package/src/settings.ts +18 -2
- package/src/tools/history.ts +12 -12
- package/src/tools/notes.ts +14 -12
- package/src/tools/output.ts +2 -0
- package/src/tools/result.ts +2 -2
- package/src/tools/schema.ts +3 -3
|
@@ -10,7 +10,8 @@ test("low-budget guidance and warning persist at turn_end, once per active windo
|
|
|
10
10
|
const sessionManager = manager();
|
|
11
11
|
const captured = makeExtension(sessionManager);
|
|
12
12
|
const low = context(sessionManager, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
13
|
-
|
|
13
|
+
const guidance = await runContextHook(captured, low);
|
|
14
|
+
assert.deepEqual(guidance?.messages.map((message) => message.customType), [GUIDANCE_TYPE], "guidance reaches the crossing request");
|
|
14
15
|
assert.equal(captured.sent.length, 0, "guidance does not trigger a detached turn");
|
|
15
16
|
const guidanceBoundary = await commitTurnEndBoundary(captured, sessionManager, low);
|
|
16
17
|
assert.equal(guidanceBoundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1);
|
|
@@ -28,7 +29,7 @@ test("early guidance stays silent and the committed final warning notifies once"
|
|
|
28
29
|
const sm = manager();
|
|
29
30
|
const captured = makeExtension(sm);
|
|
30
31
|
const early = context(sm, undefined, { tokens: 165_000, percent: 82.5, contextWindow: 200_000 });
|
|
31
|
-
assert.equal(await runContextHook(captured, early),
|
|
32
|
+
assert.equal((await runContextHook(captured, early))?.messages.length, 1, "early guidance reaches the crossing request");
|
|
32
33
|
await commitTurnEndBoundary(captured, sm, early);
|
|
33
34
|
await runHandlers(captured, "agent_settled", {}, early);
|
|
34
35
|
assert.equal(noticesOf(early).filter((notice) => notice.message.includes("Context running low") || notice.message.includes("Context almost full")).length, 0, "early model guidance has no UI toast");
|
|
@@ -39,7 +40,7 @@ test("early guidance stays silent and the committed final warning notifies once"
|
|
|
39
40
|
await commitTurnEndBoundary(captured, sm, final);
|
|
40
41
|
await runHandlers(captured, "turn_start", {}, final);
|
|
41
42
|
await runHandlers(captured, "agent_settled", {}, final);
|
|
42
|
-
assert.equal(noticesOf(final).filter((notice) => notice.message === "
|
|
43
|
+
assert.equal(noticesOf(final).filter((notice) => notice.message === "๐ฅฃ Context almost full ยท saving notes before memory clears").length, 1, "only the committed final warning notifies, exactly once");
|
|
43
44
|
});
|
|
44
45
|
test("the visible countdown ends at the warning line, clamps at zero, and preserves unknown usage", async () => {
|
|
45
46
|
const fixture = settingsFixture({
|
|
@@ -83,7 +84,7 @@ test("absent notesoup key or margins reproduce the default reminder threshold at
|
|
|
83
84
|
assert.equal(await runContextHook(captured, first), undefined, `${label}: nothing injected above the default reminder`);
|
|
84
85
|
assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0, `${label}: no guidance above the default reminder`);
|
|
85
86
|
const crossing = at(40_960);
|
|
86
|
-
assert.equal(await runContextHook(captured, crossing),
|
|
87
|
+
assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, `${label}: default reminder crossing reaches the request`);
|
|
87
88
|
await commitTurnEndBoundary(captured, sm, crossing);
|
|
88
89
|
assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, `${label}: default reminder fires`);
|
|
89
90
|
assert.equal(noticesOf(first).length, 0, `${label}: valid defaults warn nobody`);
|
|
@@ -104,7 +105,7 @@ test("project notesoup reminder margin and reserve override global per key", asy
|
|
|
104
105
|
assert.equal(await runContextHook(captured, at(90_001)), undefined, "nothing injected above the project-derived reminder");
|
|
105
106
|
assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0);
|
|
106
107
|
const crossing = at(90_000);
|
|
107
|
-
assert.equal(await runContextHook(captured, crossing),
|
|
108
|
+
assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, "project-derived reminder crossing reaches the request");
|
|
108
109
|
await commitTurnEndBoundary(captured, sm, crossing);
|
|
109
110
|
assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "project reminder margin wins");
|
|
110
111
|
});
|
|
@@ -118,14 +119,14 @@ test("an invalid reminder margin degrades to its default with one warning and ne
|
|
|
118
119
|
assert.equal(notices.length, 1, "one warning for the offending key");
|
|
119
120
|
assert.equal(notices[0]?.type, "warning");
|
|
120
121
|
assert.match(notices[0]?.message ?? "", /reminderMarginTokens/);
|
|
121
|
-
assert.match(notices[0]?.message ?? "", /
|
|
122
|
+
assert.match(notices[0]?.message ?? "", /using the default/);
|
|
122
123
|
assert.equal(/\d+\s*k?\s*(remaining|tokens)/i.test(notices[0]?.message ?? ""), false, "UI notices do not expose token counts");
|
|
123
124
|
const window = 200_000;
|
|
124
125
|
const at = (remaining) => context(sm, undefined, { tokens: window - remaining, percent: 0, contextWindow: window }, true, fixture.cwd);
|
|
125
126
|
// The degraded reminder is Pi's default reserve + default margin = 40960.
|
|
126
127
|
assert.equal(await runContextHook(captured, at(40_961)), undefined, "nothing injected above the degraded reminder");
|
|
127
128
|
const crossing = at(40_960);
|
|
128
|
-
assert.equal(await runContextHook(captured, crossing),
|
|
129
|
+
assert.equal((await runContextHook(captured, crossing))?.messages.length, 1, "degraded reminder uses its default");
|
|
129
130
|
await commitTurnEndBoundary(captured, sm, crossing);
|
|
130
131
|
assert.equal(sm.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === GUIDANCE_TYPE).length, 1, "the degraded reminder is persisted once");
|
|
131
132
|
assert.equal(noticesOf(ctx).filter((notice) => notice.type === "warning").length, 1, "warning stays one-time across handler calls");
|
|
@@ -139,6 +140,6 @@ test("the warning supersedes the early reminder when usage jumps across both thr
|
|
|
139
140
|
assert.deepEqual(warningResult?.messages.map((message) => message.customType), [WARNING_TYPE]);
|
|
140
141
|
await commitTurnEndBoundary(captured, sm, ctx);
|
|
141
142
|
const reloaded = makeExtension(sm);
|
|
142
|
-
await runHandlers(reloaded, "context", {}, ctx);
|
|
143
|
+
await runHandlers(reloaded, "context", { messages: [] }, ctx);
|
|
143
144
|
assert.equal(reloaded.sent.length, 0, "persisted warning also suppresses a late reminder after reload");
|
|
144
145
|
});
|
|
@@ -7,6 +7,10 @@ import { pathToFileURL } from "node:url";
|
|
|
7
7
|
import test from "node:test";
|
|
8
8
|
import { build } from "esbuild";
|
|
9
9
|
import { dispatch, handleLine } from "../src/claude/helper.js";
|
|
10
|
+
import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../src/claude/thresholds.js";
|
|
11
|
+
import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
|
|
12
|
+
import { PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
|
|
13
|
+
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../src/pi/reset/text.js";
|
|
10
14
|
const identity = { home: mkdtempSync(join(tmpdir(), "claude-mod-")), sessionId: "session", cwd: process.cwd(), agent: "claude", model: "claude" };
|
|
11
15
|
async function callTool(tool, params) {
|
|
12
16
|
return await dispatch({ op: "tool", tool, identity, params });
|
|
@@ -87,7 +91,7 @@ test("Claude helper refuses schema-invalid parameters before any operation runs"
|
|
|
87
91
|
for (const { name, params } of cases) {
|
|
88
92
|
const refused = JSON.parse(await handleLine(JSON.stringify({ op: "tool", tool: "notes_read", identity, params })));
|
|
89
93
|
assert.equal(refused.ok, false, `${name} is refused at the boundary`);
|
|
90
|
-
assert.
|
|
94
|
+
assert.match(refused.error ?? "", /^invalid notes_read parameters: (offset_chars|max_chars) /, `${name} names the refused parameter`);
|
|
91
95
|
}
|
|
92
96
|
await assert.rejects(callTool("notes_read", { address, offset_chars: "0" }), /invalid notes_read parameters/);
|
|
93
97
|
// Refusal happens before execute: a rejected mutation leaves nothing on disk.
|
|
@@ -109,6 +113,82 @@ test("Claude helper boot uses actual Claude note tool bindings and a fresh snaps
|
|
|
109
113
|
assert.match(boot, /claude:session/);
|
|
110
114
|
assert.doesNotMatch(boot, /memory cleared|continuation/);
|
|
111
115
|
});
|
|
116
|
+
test("Claude helper serves the shared reset prose and the host's wipe sentence", async () => {
|
|
117
|
+
const texts = await dispatch({ op: "texts" });
|
|
118
|
+
assert.equal(texts.warning, CLAUDE_WARNING_PROMPT, "the helper owns the one warning text the mod shows");
|
|
119
|
+
assert.equal(texts.continuation, CONTINUATION, "the reset message is Pi's, verbatim");
|
|
120
|
+
assert.equal(texts.wipeSentence, CLAUDE_WIPE_SENTENCE);
|
|
121
|
+
assert.match(texts.warning, /end your turn; the reset runs after it\.$/);
|
|
122
|
+
});
|
|
123
|
+
/** The point values the resolver produced, without the margin bookkeeping. */
|
|
124
|
+
function limitPoints(facts) {
|
|
125
|
+
const limits = resolveClaudeLimits(facts);
|
|
126
|
+
return { source: limits.source, unit: limits.unit, autoCompact: limits.autoCompact, native: limits.native, reset: limits.reset, warn: limits.warn };
|
|
127
|
+
}
|
|
128
|
+
// Claude compacts at min(floor((W-20000)*pct/100), W-20000-13000); notesoup resets 8192 below
|
|
129
|
+
// that and warns 16384 earlier. These are the numbers, not prose.
|
|
130
|
+
const CLAUDE_200K = { native: 167_000, reset: 158_808, warn: 142_424 };
|
|
131
|
+
test("Claude limits derive from Claude's own auto-compact point, never a fixed percent", () => {
|
|
132
|
+
// (a) Claude's own threshold is the most faithful source, and the percent override can only lower it.
|
|
133
|
+
const fromBreakdown = { usage: { tokens: 166_000, window: 200_000 }, breakdown: { autoCompactThreshold: 167_000, isAutoCompactEnabled: true } };
|
|
134
|
+
assert.deepEqual(limitPoints(fromBreakdown), { source: "auto-compact", unit: "tokens", autoCompact: true, ...CLAUDE_200K });
|
|
135
|
+
assert.deepEqual(limitPoints({ ...fromBreakdown, env: { pctOverride: "50" } }), { source: "auto-compact", unit: "tokens", autoCompact: true, native: 90_000, reset: 81_808, warn: 65_424 }, "floor((167000+13000)*50/100)");
|
|
136
|
+
assert.deepEqual(limitPoints({ ...fromBreakdown, env: { pctOverride: "96" } }), { source: "auto-compact", unit: "tokens", autoCompact: true, ...CLAUDE_200K }, "an override above the default cannot raise the point");
|
|
137
|
+
for (const pctOverride of ["0", "101", "abc", ""])
|
|
138
|
+
assert.deepEqual(limitPoints({ ...fromBreakdown, env: { pctOverride } }), { source: "auto-compact", unit: "tokens", autoCompact: true, ...CLAUDE_200K }, `pct ${pctOverride} is ignored`);
|
|
139
|
+
// (b) The same point computed from the reported window, settings and environment.
|
|
140
|
+
assert.deepEqual(limitPoints({ usage: { tokens: 960_000, window: 1_000_000 } }), { source: "window", unit: "tokens", autoCompact: true, native: 967_000, reset: 958_808, warn: 942_424 });
|
|
141
|
+
assert.equal(limitPoints({ usage: { window: 1_000_000 }, settings: { autoCompactWindow: 500_000 } }).native, 467_000);
|
|
142
|
+
assert.equal(limitPoints({
|
|
143
|
+
usage: { window: 1_000_000 },
|
|
144
|
+
breakdown: { model: "claude-opus-4-6" },
|
|
145
|
+
env: { autoCompactWindow: "400000" },
|
|
146
|
+
settings: { autoCompactWindow: 500_000, modelSettings: { "claude-opus-4-6": { autoCompactWindow: 300_000 } } },
|
|
147
|
+
}).native, 267_000, "the smallest configured window wins");
|
|
148
|
+
// Auto-compact off: the point moves to the hard window, and the margins stay.
|
|
149
|
+
const offSettings = { usage: { tokens: 171_808, window: 200_000 }, settings: { autoCompactEnabled: false } };
|
|
150
|
+
assert.deepEqual(limitPoints(offSettings), { source: "window", unit: "tokens", autoCompact: false, native: 180_000, reset: 171_808, warn: 155_424 });
|
|
151
|
+
assert.deepEqual(limitPoints({ usage: { window: 200_000 }, env: { disableAutoCompact: "1" } }), { source: "window", unit: "tokens", autoCompact: false, native: 180_000, reset: 171_808, warn: 155_424 });
|
|
152
|
+
assert.deepEqual(limitPoints({ usage: { window: 200_000 }, breakdown: { isAutoCompactEnabled: false } }), { source: "window", unit: "tokens", autoCompact: false, native: 180_000, reset: 171_808, warn: 155_424 });
|
|
153
|
+
assert.deepEqual(limitPoints({ usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000, isAutoCompactEnabled: false } }), { source: "window", unit: "tokens", autoCompact: false, native: 180_000, reset: 171_808, warn: 155_424 }, "an off session ignores a stale threshold");
|
|
154
|
+
// (c) No window, no breakdown: the same reserves expressed on the classic 200K window.
|
|
155
|
+
const percent = limitPoints({});
|
|
156
|
+
assert.equal(percent.source, "percent");
|
|
157
|
+
assert.equal(percent.unit, "percent");
|
|
158
|
+
assert.ok(Math.abs(percent.native - 83.5) < 1e-9 && Math.abs(percent.reset - 79.404) < 1e-9 && Math.abs(percent.warn - 71.212) < 1e-9, "83.5 / 79.4 / 71.2 on 200K");
|
|
159
|
+
assert.equal(limitPoints({ env: { pctOverride: "50" } }).native, 50);
|
|
160
|
+
assert.equal(limitPoints({ usage: { window: 8_000 } }).unit, "percent", "a window too small for the reserve degrades to percent");
|
|
161
|
+
});
|
|
162
|
+
test("Claude limits read margins from the notesoup settings shape and ignore garbage", () => {
|
|
163
|
+
const base = { usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000, isAutoCompactEnabled: true } };
|
|
164
|
+
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 });
|
|
165
|
+
for (const notesoup of [{ resetMarginTokens: 0 }, { resetMarginTokens: 8.5 }, { warningRunwayTokens: -1 }, { warningRunwayTokens: "big" }, "nonsense", null])
|
|
166
|
+
assert.deepEqual(limitPoints({ ...base, settings: { notesoup } }), { source: "auto-compact", unit: "tokens", autoCompact: true, ...CLAUDE_200K }, `notesoup ${JSON.stringify(notesoup)} degrades to the defaults`);
|
|
167
|
+
assert.equal(limitPoints({ ...base, settings: "nonsense", env: "nonsense", usage: "nonsense", breakdown: "nonsense" }).unit, "percent", "malformed facts degrade rather than throw");
|
|
168
|
+
// Malformed facts never throw: the resolver is the mod-helper boundary.
|
|
169
|
+
for (const facts of [undefined, null, "x", 7, [], { usage: { window: "nope" }, breakdown: { autoCompactThreshold: null } }])
|
|
170
|
+
assert.equal(resolveClaudeLimits(facts).unit, "percent");
|
|
171
|
+
});
|
|
172
|
+
test("Claude helper resolves limits across the boundary and never throws on nonsense", async () => {
|
|
173
|
+
const resolved = await dispatch({ op: "limits", facts: { usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000 } } });
|
|
174
|
+
assert.equal(resolved.native, 167_000);
|
|
175
|
+
assert.equal(resolved.reset, 167_000 - DEFAULT_CLAUDE_RESET_MARGIN_TOKENS);
|
|
176
|
+
assert.equal(DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, 8_192);
|
|
177
|
+
assert.equal(WARNING_RUNWAY_TOKENS, 16_384);
|
|
178
|
+
const nonsense = JSON.parse(await handleLine(JSON.stringify({ op: "limits", facts: "nonsense" })));
|
|
179
|
+
assert.equal(nonsense.ok, true);
|
|
180
|
+
assert.equal(nonsense.result.unit, "percent");
|
|
181
|
+
assert.ok(nonsense.result.warn > 0 && nonsense.result.warn < 100);
|
|
182
|
+
});
|
|
183
|
+
test("Claude's wipe sentence replaces only that sentence in the shared protocol block", () => {
|
|
184
|
+
const piTools = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "clear_memory" };
|
|
185
|
+
const pi = renderProtocolBlock(piTools);
|
|
186
|
+
assert.ok(pi.includes(PROTOCOL_WIPE_SENTENCE), "Pi keeps the default sentence, byte for byte");
|
|
187
|
+
const claude = renderProtocolBlock({ ...piTools, wipeSentence: CLAUDE_WIPE_SENTENCE });
|
|
188
|
+
assert.equal(claude, pi.replace(PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE), "only that sentence changes");
|
|
189
|
+
assert.equal(claude.includes("erase yourself with dignity"), false);
|
|
190
|
+
assert.ok(claude.includes("end your turn and ask the human to run `/clear-memory`."));
|
|
191
|
+
});
|
|
112
192
|
test("Claude Mod helper runs from a standalone copied plugin directory", () => {
|
|
113
193
|
const fixture = mkdtempSync(join(tmpdir(), "claude-mod-install-"));
|
|
114
194
|
try {
|
|
@@ -160,6 +240,8 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
|
|
|
160
240
|
assert.equal(boot.name, "notesoup:boot");
|
|
161
241
|
assert.ok(boot.text.length > 0, "the boot block carries real boot text");
|
|
162
242
|
assert.match(boot.text, /mcp__notesoup__notes_\*/, "the boot text names the actual Claude note tool binding");
|
|
243
|
+
assert.ok(boot.text.includes(CLAUDE_WIPE_SENTENCE), "the boot speaks the Claude wipe path");
|
|
244
|
+
assert.equal(boot.text.includes("erase yourself with dignity"), false);
|
|
163
245
|
assert.equal(first.sentinel, "kept", "unrelated result fields survive");
|
|
164
246
|
assert.equal(bootRequests, 1, "the first prompt makes exactly one boot helper request");
|
|
165
247
|
assert.equal(nextCalls, 1, "the upstream chain runs exactly once per prompt");
|
|
@@ -207,10 +289,10 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
207
289
|
const failed = await promptContext(structuredClone(upstream));
|
|
208
290
|
assert.deepEqual(failed, {
|
|
209
291
|
...upstream,
|
|
210
|
-
blocks: [...upstream.blocks, { name: "notesoup:boot", text: "# notesoup\
|
|
292
|
+
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." }],
|
|
211
293
|
}, "boot failure keeps the original fallback and upstream fields even if notify is absent or fails");
|
|
212
|
-
const expectedNotifications = mode === "no ui" || mode === "no notify" ? [] : ["
|
|
213
|
-
assert.deepEqual(notifications, expectedNotifications, "one user-facing notification
|
|
294
|
+
const expectedNotifications = mode === "no ui" || mode === "no notify" ? [] : ["๐ฅฃ Notes didn't load"];
|
|
295
|
+
assert.deepEqual(notifications, expectedNotifications, "one user-facing notification reports the notes boot failure");
|
|
214
296
|
assert.equal(bootRequests, 1);
|
|
215
297
|
assert.equal(nextCalls, 1);
|
|
216
298
|
assert.deepEqual(await promptContext(structuredClone(failed)), failed);
|
|
@@ -245,52 +327,60 @@ test("Claude Mod hook delivers the helper's shared text, and marks only a refusa
|
|
|
245
327
|
const foreign = await call("other_tool", {});
|
|
246
328
|
assert.equal("result" in foreign, false, "an unregistered tool falls through to the engine's own handling");
|
|
247
329
|
});
|
|
248
|
-
test("Claude Mod resets at
|
|
330
|
+
test("Claude Mod resets at Claude's resolved point after the turn, retains one fresh boot and deduplicates measure", async (t) => {
|
|
249
331
|
const home = mkdtempSync(join(tmpdir(), "claude-reset-home-"));
|
|
250
332
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
251
333
|
const { host, registered, notifications } = fakeEngine(home);
|
|
252
334
|
const handlers = new Map();
|
|
253
335
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
254
336
|
const invoke = (name, event = {}) => handlers.get(name)(host, event, async () => ({ sentinel: name }));
|
|
255
|
-
|
|
337
|
+
// A 200K window resolves to Claude's 167 000 point, so notesoup resets 8 192 below it.
|
|
338
|
+
let tokens = 140_000;
|
|
256
339
|
let compactions = 0;
|
|
257
340
|
let kept = [];
|
|
258
|
-
|
|
341
|
+
const measured = () => ({ context: { tokens, window: 200_000, percent: tokens === undefined ? undefined : (tokens / 200_000) * 100 } });
|
|
342
|
+
host.session.usage = async () => measured();
|
|
259
343
|
host.session.compact = async ({ instructions }) => {
|
|
260
344
|
compactions++;
|
|
261
345
|
const result = await invoke("session.compact", { trigger: "plugin", instructions: `${instructions} (rewritten upstream)`, messages: [{ role: "user", text: "OLD_SECRET" }] });
|
|
262
346
|
kept = result.messages;
|
|
263
|
-
|
|
347
|
+
tokens = undefined; // The real engine invalidates token usage after compact.
|
|
264
348
|
return result;
|
|
265
349
|
};
|
|
266
350
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
267
351
|
assert.equal(registered.length, 5);
|
|
268
352
|
const initial = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
353
|
+
assert.equal(initial.blocks.length, 1, "below the warn point no warning joins the boot");
|
|
269
354
|
assert.match(initial.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
270
355
|
await invoke("turn.start");
|
|
271
356
|
await invoke("session.measure");
|
|
272
357
|
await invoke("turn.complete");
|
|
273
|
-
assert.equal(compactions, 0, "
|
|
358
|
+
assert.equal(compactions, 0, "140000 is below every resolved point");
|
|
274
359
|
host.session.usage = async () => { throw new Error("usage unavailable"); };
|
|
275
360
|
await invoke("session.measure");
|
|
276
361
|
await invoke("turn.complete");
|
|
277
|
-
assert.equal(notifications.filter((text) => text.includes("
|
|
278
|
-
host.session.usage = async () => (
|
|
362
|
+
assert.equal(notifications.filter((text) => text.includes("Context usage unavailable")).length, 1, "usage failure logs once per session");
|
|
363
|
+
host.session.usage = async () => measured();
|
|
279
364
|
await dispatch({ op: "tool", tool: "notes_write", identity: { ...identity, home, cwd: home, sessionId: "hook-session" }, params: { address: "@human/MAP.md", content: "FRESH_NOTES_AT_RESET" } });
|
|
280
365
|
await invoke("turn.start");
|
|
281
|
-
|
|
366
|
+
tokens = 158_807;
|
|
367
|
+
await invoke("turn.complete");
|
|
368
|
+
assert.equal(compactions, 0, "one token below the resolved reset point");
|
|
369
|
+
await invoke("turn.start");
|
|
370
|
+
tokens = 158_808;
|
|
282
371
|
await invoke("session.measure");
|
|
283
372
|
assert.equal(compactions, 0, "measure cannot compact under a running turn");
|
|
284
373
|
assert.deepEqual(await invoke("turn.complete"), { sentinel: "turn.complete" });
|
|
285
374
|
assert.equal(compactions, 1);
|
|
286
|
-
assert.equal(kept.length,
|
|
375
|
+
assert.equal(kept.length, 2, "the reset is the notes boot followed by the one reset message");
|
|
287
376
|
assert.equal(kept[0].role, "user");
|
|
288
377
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:1/);
|
|
289
378
|
assert.match(kept[0].text, /Previous context window id: claude:hook-session:0/);
|
|
290
379
|
assert.match(kept[0].text, /FRESH_NOTES_AT_RESET/);
|
|
291
380
|
assert.doesNotMatch(kept[0].text, /OLD_SECRET/);
|
|
381
|
+
assert.equal(kept[1].text, CONTINUATION, "the continuation is Pi's message, verbatim");
|
|
292
382
|
await invoke("session.measure");
|
|
293
|
-
assert.equal(compactions, 1, "invalidated
|
|
383
|
+
assert.equal(compactions, 1, "invalidated tokens cannot immediately reset twice");
|
|
294
384
|
const upstream = { blocks: [{ name: "unrelated", text: "leave this alone" }], sentinel: "kept" };
|
|
295
385
|
assert.deepEqual(await handlers.get("prompt.context")(host, {}, async () => upstream), upstream, "the retained boot is not injected a second time");
|
|
296
386
|
});
|
|
@@ -301,24 +391,24 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
|
|
|
301
391
|
const handlers = new Map();
|
|
302
392
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
303
393
|
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({ sentinel: name }));
|
|
304
|
-
let
|
|
394
|
+
let tokens;
|
|
305
395
|
let attempts = 0;
|
|
306
|
-
host.session.usage = async () => ({ context: {
|
|
396
|
+
host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
|
|
307
397
|
host.session.compact = async () => { attempts++; throw new Error("not available in a headless (-p / SDK) session yet"); };
|
|
308
398
|
await invoke("session.start", { cwd: home, isInteractive: false });
|
|
309
399
|
await invoke("turn.start");
|
|
310
400
|
await invoke("turn.complete");
|
|
311
401
|
await invoke("session.measure");
|
|
312
|
-
assert.equal(attempts, 0, "no
|
|
313
|
-
|
|
402
|
+
assert.equal(attempts, 0, "no measured tokens means no automatic reset");
|
|
403
|
+
tokens = 190_000;
|
|
314
404
|
await invoke("turn.start");
|
|
315
405
|
assert.deepEqual(await invoke("turn.complete"), { sentinel: "turn.complete" }, "a rejection does not break the turn chain");
|
|
316
406
|
await invoke("session.measure");
|
|
317
407
|
await invoke("turn.complete");
|
|
318
408
|
assert.equal(attempts, 0, "headless sessions skip the unsupported capability from startup");
|
|
319
|
-
assert.deepEqual(notifications, ["
|
|
409
|
+
assert.deepEqual(notifications, ["๐ฅฃ Clear-memory is off in headless (-p / SDK) sessions"]);
|
|
320
410
|
const manual = await invoke("command.run", { command: "clear-memory" });
|
|
321
|
-
assert.match(manual.text, /
|
|
411
|
+
assert.match(manual.text, /off in headless/);
|
|
322
412
|
assert.equal(notifications.length, 1);
|
|
323
413
|
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
324
414
|
assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
@@ -338,18 +428,20 @@ test("Claude Mod refuses to wipe on boot failure and can retry without advancing
|
|
|
338
428
|
return { exitCode: 1, stdout: "" };
|
|
339
429
|
return run(argv, init);
|
|
340
430
|
};
|
|
341
|
-
host.session.usage = async () => ({ context: {
|
|
431
|
+
host.session.usage = async () => ({ context: { tokens: 170_000, window: 200_000 } });
|
|
342
432
|
let result = {};
|
|
343
433
|
host.session.compact = async ({ instructions }) => result = await invoke("session.compact", { trigger: "plugin", instructions });
|
|
344
434
|
await invoke("turn.start");
|
|
345
435
|
await invoke("turn.complete");
|
|
346
|
-
assert.match(result.skip, /
|
|
436
|
+
assert.match(result.skip, /notes didn't load/);
|
|
347
437
|
assert.equal(result.messages, undefined, "a failed builder must veto rather than fall through to summary");
|
|
348
438
|
failBoot = false;
|
|
349
439
|
await invoke("turn.start");
|
|
350
440
|
await invoke("turn.complete");
|
|
351
441
|
assert.equal(result.skip, undefined);
|
|
442
|
+
assert.equal(result.messages.length, 2);
|
|
352
443
|
assert.match(result.messages[0].text, /Current context window id: claude:hook-session:1/, "a failed reset never consumes a window ordinal");
|
|
444
|
+
assert.equal(result.messages[1].text, CONTINUATION);
|
|
353
445
|
});
|
|
354
446
|
test("Claude Mod manual reset uses one hidden close-out turn, then recovers its boot on reload", async (t) => {
|
|
355
447
|
const home = mkdtempSync(join(tmpdir(), "claude-manual-home-"));
|
|
@@ -376,14 +468,17 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
376
468
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
377
469
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
378
470
|
const command = await invoke("command.run", { command: "clear-memory" });
|
|
379
|
-
assert.match(command.text, /
|
|
471
|
+
assert.match(command.text, /Clearing memory/);
|
|
380
472
|
await Promise.resolve();
|
|
381
473
|
assert.equal(compactions, 0, "command.run must not call compact under its held turn");
|
|
382
474
|
assert.equal(timers.length, 1);
|
|
383
475
|
await timers.shift()();
|
|
384
476
|
assert.equal(prompts.length, 1, "exactly one hidden normal-model close-out turn, not a summary");
|
|
477
|
+
assert.equal(prompts[0], CLAUDE_WARNING_PROMPT, "the close-out is the same warning text the automatic path shows");
|
|
385
478
|
assert.equal(compactions, 1);
|
|
479
|
+
assert.equal(kept.length, 2);
|
|
386
480
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:1/);
|
|
481
|
+
assert.equal(kept[1].text, CONTINUATION);
|
|
387
482
|
host.session.messages = async () => [{ role: "user", text: "OLD_SECRET" }, ...kept];
|
|
388
483
|
handlers = new Map();
|
|
389
484
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
@@ -395,6 +490,101 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
395
490
|
assert.equal(prompts.length, 1, "a busy manual request reuses the current turn instead of submitting another");
|
|
396
491
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:2/);
|
|
397
492
|
});
|
|
493
|
+
test("Claude Mod warns once per window once the measured context crosses the runway", async (t) => {
|
|
494
|
+
const home = mkdtempSync(join(tmpdir(), "claude-warn-home-"));
|
|
495
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
496
|
+
const { host } = fakeEngine(home);
|
|
497
|
+
const handlers = new Map();
|
|
498
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
499
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
500
|
+
let tokens = 142_423;
|
|
501
|
+
host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
|
|
502
|
+
host.session.compact = async ({ instructions }) => await invoke("session.compact", { trigger: "plugin", instructions });
|
|
503
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
504
|
+
const promptContext = (result) => handlers.get("prompt.context")(host, {}, async () => result);
|
|
505
|
+
const upstream = { blocks: [{ name: "claude:user-context", text: "upstream" }] };
|
|
506
|
+
assert.deepEqual((await promptContext(structuredClone(upstream))).blocks.map((block) => block.name), ["claude:user-context", "notesoup:boot"], "one token below the warn point is silent");
|
|
507
|
+
tokens = 142_424;
|
|
508
|
+
const warned = await promptContext(structuredClone(upstream));
|
|
509
|
+
assert.deepEqual(warned.blocks.map((block) => block.name), ["claude:user-context", "notesoup:boot", "notesoup:warning"]);
|
|
510
|
+
assert.equal(warned.blocks[2].text, CLAUDE_WARNING_PROMPT);
|
|
511
|
+
assert.deepEqual(await promptContext(structuredClone(warned)), warned, "one warning per window");
|
|
512
|
+
// A reset opens a new window, and the flag resets with it.
|
|
513
|
+
await invoke("turn.start");
|
|
514
|
+
tokens = 158_808;
|
|
515
|
+
await invoke("turn.complete");
|
|
516
|
+
tokens = 142_424;
|
|
517
|
+
const again = await promptContext(structuredClone(upstream));
|
|
518
|
+
assert.deepEqual(again.blocks.map((block) => block.name), ["claude:user-context", "notesoup:warning"], "the new window warns again, and its retained boot is not duplicated");
|
|
519
|
+
assert.equal(again.blocks[1].text, CLAUDE_WARNING_PROMPT);
|
|
520
|
+
});
|
|
521
|
+
test("Claude Mod moves the reset point to the hard window when auto-compact is off", async (t) => {
|
|
522
|
+
const home = mkdtempSync(join(tmpdir(), "claude-off-home-"));
|
|
523
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
524
|
+
const { host, notifications } = fakeEngine(home);
|
|
525
|
+
host.settings = { read: async () => ({ autoCompactEnabled: false }) };
|
|
526
|
+
const handlers = new Map();
|
|
527
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
528
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
529
|
+
let tokens = 171_807;
|
|
530
|
+
let compactions = 0;
|
|
531
|
+
host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
|
|
532
|
+
host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
|
|
533
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
534
|
+
await invoke("turn.start");
|
|
535
|
+
await invoke("turn.complete");
|
|
536
|
+
assert.equal(compactions, 0, "171807 is below the hard-window point");
|
|
537
|
+
await invoke("turn.start");
|
|
538
|
+
tokens = 171_808;
|
|
539
|
+
await invoke("turn.complete");
|
|
540
|
+
assert.equal(compactions, 1, "200000 - 20000 - 8192");
|
|
541
|
+
assert.deepEqual(notifications.filter((text) => text.includes("unavailable") || text.includes("Couldn't")), [], "a resolvable configuration logs no failure");
|
|
542
|
+
});
|
|
543
|
+
test("Claude Mod stops the automatic reset and the manual command under DISABLE_COMPACT", async (t) => {
|
|
544
|
+
const home = mkdtempSync(join(tmpdir(), "claude-disabled-home-"));
|
|
545
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
546
|
+
const { host, notifications } = fakeEngine(home);
|
|
547
|
+
host.env = { get: async (name) => name === "PI_NOTES_HOME" ? home : name === "DISABLE_COMPACT" ? "1" : undefined };
|
|
548
|
+
const timers = [];
|
|
549
|
+
host.clock.after = (_ms, callback) => { timers.push(callback); };
|
|
550
|
+
const handlers = new Map();
|
|
551
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
552
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
553
|
+
let compactions = 0;
|
|
554
|
+
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
555
|
+
host.session.compact = async () => { compactions++; return {}; };
|
|
556
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
557
|
+
assert.equal(notifications.length, 1, "one startup line");
|
|
558
|
+
assert.match(notifications[0], /DISABLE_COMPACT/);
|
|
559
|
+
const manual = await invoke("command.run", { command: "clear-memory" });
|
|
560
|
+
assert.match(manual.text, /DISABLE_COMPACT/);
|
|
561
|
+
assert.equal(timers.length, 0, "no close-out turn is queued");
|
|
562
|
+
await invoke("turn.start");
|
|
563
|
+
await invoke("session.measure");
|
|
564
|
+
await invoke("turn.complete");
|
|
565
|
+
await invoke("session.measure");
|
|
566
|
+
assert.equal(compactions, 0, "the automatic reset is off and does not retry");
|
|
567
|
+
assert.equal(notifications.length, 1, "detection logs once, not per turn");
|
|
568
|
+
});
|
|
569
|
+
test("Claude Mod skips the automatic reset when thresholds cannot be resolved", async (t) => {
|
|
570
|
+
const home = mkdtempSync(join(tmpdir(), "claude-nolimits-home-"));
|
|
571
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
572
|
+
const { host, notifications } = fakeEngine(home);
|
|
573
|
+
host.process.run = async () => ({ exitCode: 1, stdout: "" });
|
|
574
|
+
const handlers = new Map();
|
|
575
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
576
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
577
|
+
let compactions = 0;
|
|
578
|
+
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
579
|
+
host.session.compact = async () => { compactions++; return {}; };
|
|
580
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
581
|
+
await invoke("turn.start");
|
|
582
|
+
await invoke("session.measure");
|
|
583
|
+
await invoke("turn.complete");
|
|
584
|
+
await invoke("session.measure");
|
|
585
|
+
assert.equal(compactions, 0, "an unresolvable point never resets");
|
|
586
|
+
assert.equal(notifications.filter((text) => text.includes("Context thresholds unavailable")).length, 1, "one line, not one per turn");
|
|
587
|
+
});
|
|
398
588
|
test("Claude dream skill projection stays byte-identical to canonical shared files", () => {
|
|
399
589
|
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/skills/dream/SKILL.md")), readFileSync(join(process.cwd(), "skills/dream/SKILL.md")));
|
|
400
590
|
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/playbook.md")), readFileSync(join(process.cwd(), "playbook.md")));
|
package/dist/test/dream.test.js
CHANGED
|
@@ -84,11 +84,11 @@ test("dreamer delete is jailed to the notes home and refuses live notes", async
|
|
|
84
84
|
const ctx = { cwd: home };
|
|
85
85
|
await del.execute("d1", { path: "global/dead.md" }, undefined, undefined, ctx);
|
|
86
86
|
assert.equal(existsSync(join(home, "global/dead.md")), false);
|
|
87
|
-
await assert.rejects(() => del.execute("d2", { path: "global/live.md" }, undefined, undefined, ctx), /
|
|
87
|
+
await assert.rejects(() => del.execute("d2", { path: "global/live.md" }, undefined, undefined, ctx), /global\/live\.md/);
|
|
88
88
|
assert.equal(existsSync(join(home, "global/live.md")), true);
|
|
89
|
-
await assert.rejects(() => del.execute("d3", { path: join("..", basename(outside), "keep.md") }, undefined, undefined, ctx), /
|
|
89
|
+
await assert.rejects(() => del.execute("d3", { path: join("..", basename(outside), "keep.md") }, undefined, undefined, ctx), /outside the notes home/);
|
|
90
90
|
symlinkSync(join(outside, "keep.md"), join(home, "link.md"));
|
|
91
|
-
await assert.rejects(() => del.execute("d4", { path: "link.md" }, undefined, undefined, ctx), /
|
|
91
|
+
await assert.rejects(() => del.execute("d4", { path: "link.md" }, undefined, undefined, ctx), /outside the notes home/);
|
|
92
92
|
assert.equal(existsSync(join(outside, "keep.md")), true);
|
|
93
93
|
});
|
|
94
94
|
test("CLI lists dreamer deletions in the report", async () => {
|
|
@@ -107,11 +107,10 @@ test("seq is stable across branch changes, abandoned entries stay unreadable, an
|
|
|
107
107
|
assert.equal(branchId !== abandonedId, true);
|
|
108
108
|
const offBranch = resultError(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
109
109
|
assert.equal(offBranch.code, "not_on_branch");
|
|
110
|
-
assert.match(offBranch.message, /another branch/);
|
|
111
110
|
assert.equal(JSON.stringify(offBranch).includes("abandoned"), false, "the refusal does not leak the abandoned entry's text");
|
|
112
111
|
const unknown = resultError(await call(captured, "history_read", { seq: 4 }, ctx));
|
|
113
112
|
assert.equal(unknown.code, "unknown_seq");
|
|
114
|
-
assert.match(unknown.message, /
|
|
113
|
+
assert.match(unknown.message, /\b4\b.*\b3\b/);
|
|
115
114
|
});
|
|
116
115
|
test("a result address consumed by a pairing names its call instead of serving a second read", async () => {
|
|
117
116
|
const session = manager();
|
|
@@ -123,7 +122,7 @@ test("a result address consumed by a pairing names its call instead of serving a
|
|
|
123
122
|
assert.deepEqual(seqs(await call(captured, "history_list", { roles: ["tool"] }, ctx)), [2], "the pairing is one event at the call's address");
|
|
124
123
|
const consumed = resultError(await call(captured, "history_read", { seq: 3 }, ctx));
|
|
125
124
|
assert.equal(consumed.code, "not_an_event");
|
|
126
|
-
assert.match(consumed.message, /
|
|
125
|
+
assert.match(consumed.message, /seq 2\b/);
|
|
127
126
|
const callSeq = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
|
|
128
127
|
assert.equal(callSeq.seq, 2);
|
|
129
128
|
assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
|
|
@@ -445,7 +444,7 @@ test("list renders paging and fold recipes, read renders a neighborhood call, an
|
|
|
445
444
|
const noPrevious = resultError(await call(soloCaptured, "history_list", { window_id: "@previous" }, context(solo)));
|
|
446
445
|
assert.equal(noPrevious.code, "unknown_window_id");
|
|
447
446
|
assert.match(noPrevious.message, /@previous/);
|
|
448
|
-
assert.match(noPrevious.message, new RegExp(
|
|
447
|
+
assert.match(noPrevious.message, new RegExp(`${soloWindows.windows[0].window_id}\\.$`), "the refusal names the window the session does have");
|
|
449
448
|
});
|
|
450
449
|
test("compaction summary becomes context and is folded in the default list", async () => {
|
|
451
450
|
const session = manager();
|
|
@@ -482,7 +481,7 @@ test("a query covers every role, carries match offsets and refuses an empty lite
|
|
|
482
481
|
assert.deepEqual(next.items.map((item) => item.seq), [3]);
|
|
483
482
|
const absent = await call(captured, "history_list", { query: "absent" }, ctx);
|
|
484
483
|
assert.deepEqual(page(absent).items, []);
|
|
485
|
-
assert.
|
|
484
|
+
assert.notEqual(rendered(absent).trim(), "", "an empty page says so instead of rendering nothing");
|
|
486
485
|
assert.deepEqual(resultError(await call(captured, "history_list", { query: "" }, ctx)).code, "invalid_query");
|
|
487
486
|
});
|
|
488
487
|
test("page_older and page_newer round-trip a session with no duplicates and no gaps", async () => {
|
|
@@ -574,7 +573,7 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
574
573
|
assert.equal(tail.next_offset_chars, null, "the true end has no continuation");
|
|
575
574
|
const past = resultError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
|
|
576
575
|
assert.equal(past.code, "invalid_offset");
|
|
577
|
-
assert.match(past.message, new RegExp(
|
|
576
|
+
assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
|
|
578
577
|
});
|
|
579
578
|
test("history windows expose stable ranges and session identity", async () => {
|
|
580
579
|
const session = manager();
|
|
@@ -617,11 +616,11 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
|
|
|
617
616
|
const offBranch = await historyRead.execute({ seq: 12 }, projection);
|
|
618
617
|
assert.equal(offBranch.ok, false);
|
|
619
618
|
if (!offBranch.ok)
|
|
620
|
-
assert.
|
|
619
|
+
assert.equal(offBranch.error.code, "not_on_branch");
|
|
621
620
|
const unknown = await historyRead.execute({ seq: 13 }, projection);
|
|
622
621
|
assert.equal(unknown.ok, false);
|
|
623
622
|
if (!unknown.ok)
|
|
624
|
-
assert.match(unknown.error.message, /
|
|
623
|
+
assert.match(unknown.error.message, /\b13\b.*\b12\b/);
|
|
625
624
|
const listed = await historyList.execute({}, projection);
|
|
626
625
|
assert.equal(listed.ok, true);
|
|
627
626
|
if (listed.ok)
|
|
@@ -49,7 +49,7 @@ test("shared boot uses only explicit identity, loader, captured time and logical
|
|
|
49
49
|
const rendered = renderBootBlock(block);
|
|
50
50
|
assert.equal(renderBootBlock(block), rendered);
|
|
51
51
|
assert.ok(rendered.includes("๐\n checkpoint.md ยท 1m ago"), "a feed entry is the note's own first line over its locator");
|
|
52
|
-
assert.ok(rendered.includes("
|
|
52
|
+
assert.ok(rendered.includes("Try `memo_list` again"));
|
|
53
53
|
assert.equal(/notes_\*|notes_list|history_\*|history_list|history_read|get_context_remaining|clear_memory/.test(rendered), false);
|
|
54
54
|
});
|
|
55
55
|
test("the shared result module bounds both surfaces and resumes by offset", () => {
|
|
@@ -254,7 +254,7 @@ test("an unknown window_id names at most five known windows in its message", asy
|
|
|
254
254
|
assert.equal(outcome.ok, false);
|
|
255
255
|
if (!outcome.ok) {
|
|
256
256
|
assert.equal(outcome.error.code, "unknown_window_id");
|
|
257
|
-
assert.match(outcome.error.message, /
|
|
257
|
+
assert.match(outcome.error.message, /"pcw:absent".*pcw:w0, pcw:w1, pcw:w2, pcw:w3, pcw:w4\.$/, "the message names the known windows itself");
|
|
258
258
|
assert.equal(outcome.error.message.includes("pcw:w5"), false, "at most five known windows are named");
|
|
259
259
|
}
|
|
260
260
|
});
|
|
@@ -206,7 +206,7 @@ test("a massively ambiguous edit still reports every match line to a library cal
|
|
|
206
206
|
assert.equal(error.lineNumbers?.length, 2000, "the domain keeps every match line rather than a sample");
|
|
207
207
|
assert.deepEqual(error.lineNumbers?.slice(0, 3), [1, 2, 3]);
|
|
208
208
|
assert.equal(error.lineNumbers?.[1999], 2000);
|
|
209
|
-
assert.match(error.message, /
|
|
209
|
+
assert.match(error.message, /2000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 1992 more\)/, "the message names the exact total and a bounded sample");
|
|
210
210
|
assert.ok(Buffer.byteLength(error.message, "utf8") < 300, "the message stays small however many lines matched");
|
|
211
211
|
return true;
|
|
212
212
|
});
|
|
@@ -136,7 +136,7 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
|
|
|
136
136
|
assert.equal((await listNotes(ctx, { scope: "session" }))[0]?.meta.crumpledAt, undefined, "writing always produces an uncrumpled note");
|
|
137
137
|
// metadata-only on a missing path is the typed not-found arm
|
|
138
138
|
const missing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
|
|
139
|
-
assert.equal(missing.
|
|
139
|
+
assert.equal(missing.code, "not_found");
|
|
140
140
|
});
|
|
141
141
|
test("the filesystem notes loader treats an absent home as empty but surfaces a real directory read failure", async () => {
|
|
142
142
|
const sm = manager();
|
|
@@ -244,7 +244,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
244
244
|
currentWindowId: "pcw:test:next",
|
|
245
245
|
notes: oneFailed,
|
|
246
246
|
});
|
|
247
|
-
assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("THE HUMAN ยท @human\nโโโโโโโโโโโโโโโโโโ\n\n This drawer wouldn't open
|
|
247
|
+
assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("THE HUMAN ยท @human\nโโโโโโโโโโโโโโโโโโ\n\n This drawer wouldn't open. Try `notes_list` again."), "healthy homes and a per-section recovery notice survive one failure");
|
|
248
248
|
assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed home's index is omitted");
|
|
249
249
|
assert.equal(oneFailedText.includes("Human note"), false, "the failed home takes no feed seats");
|
|
250
250
|
const allFailed = await loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), (scope) => {
|
|
@@ -339,7 +339,7 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
|
|
|
339
339
|
assert.equal(JSON.stringify(missingResult).includes(root), false, "failure receipts never expose the absolute home");
|
|
340
340
|
const missing = resultError(missingResult);
|
|
341
341
|
assert.deepEqual(Object.keys(missing).sort(), ["code", "message"], "the refusal carries a precise code and message");
|
|
342
|
-
assert.equal(missing.
|
|
342
|
+
assert.equal(missing.code, "not_found");
|
|
343
343
|
assert.equal(missing.code, "not_found");
|
|
344
344
|
});
|
|
345
345
|
test("an over-budget note search match is a marked prefix with an honest line address", async () => {
|
|
@@ -506,8 +506,8 @@ test("a body that repeats one anchor thousands of times refuses with bounded, co
|
|
|
506
506
|
assertWithinBudget(raw, "refusal with thousands of match lines");
|
|
507
507
|
const refusal = resultError(raw);
|
|
508
508
|
assert.equal(refusal.code, "ambiguous_edit");
|
|
509
|
-
assert.match(refusal.message, /
|
|
510
|
-
assert.match(refusal.message, /
|
|
509
|
+
assert.match(refusal.message, /edits\[0\]/, "the message names the failing edit index");
|
|
510
|
+
assert.match(refusal.message, /5000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 4992 more\)/, "the message names a bounded sample and the exact total");
|
|
511
511
|
assert.equal(resultRead(await call(captured, "notes_read", { address: "many.md", max_chars: 15 }, ctx)).content, "beta\n".repeat(3), "the refused edit changed nothing");
|
|
512
512
|
const replaced = resultData(await call(captured, "notes_update", { address: "many.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
|
|
513
513
|
assertWithinBudget(await call(captured, "notes_read", { address: "many.md" }, ctx), "read after replace_all");
|