notesoup 0.42.0 → 0.44.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 +11 -20
- package/dist/src/boot/snapshot.d.ts +2 -0
- package/dist/src/boot/snapshot.js +4 -5
- package/dist/src/boot/text.js +4 -2
- package/dist/src/budget/parse.d.ts +14 -0
- package/dist/src/budget/parse.js +36 -0
- package/dist/src/budget/policy.js +2 -7
- package/dist/src/budget/text.d.ts +2 -0
- package/dist/src/budget/text.js +2 -0
- package/dist/src/claude/helper.js +3 -4
- package/dist/src/claude/thresholds.js +45 -66
- package/dist/src/dream/lock.js +6 -13
- package/dist/src/dream/report.js +5 -15
- package/dist/src/history/history.js +4 -2
- package/dist/src/history/query.js +10 -22
- package/dist/src/notes/address.d.ts +2 -3
- package/dist/src/notes/address.js +10 -22
- package/dist/src/notes/errors.d.ts +2 -0
- package/dist/src/notes/errors.js +5 -0
- package/dist/src/notes/frontmatter.js +16 -2
- package/dist/src/notes/identity.js +2 -4
- package/dist/src/notes/paths.d.ts +7 -2
- package/dist/src/notes/paths.js +18 -60
- package/dist/src/notes/project-home.d.ts +25 -0
- package/dist/src/notes/project-home.js +231 -0
- package/dist/src/notes/store.d.ts +4 -2
- package/dist/src/notes/store.js +52 -45
- package/dist/src/pi/boot.js +17 -9
- package/dist/src/pi/budget.d.ts +3 -3
- package/dist/src/pi/budget.js +11 -11
- package/dist/src/pi/dream/cli.js +43 -11
- package/dist/src/pi/estimate.d.ts +1 -5
- package/dist/src/pi/estimate.js +4 -4
- package/dist/src/pi/history.js +1 -4
- package/dist/src/pi/notes/adapter.d.ts +1 -1
- package/dist/src/pi/notes/adapter.js +3 -3
- package/dist/src/pi/reset/artifacts.d.ts +0 -2
- package/dist/src/pi/reset/artifacts.js +4 -4
- package/dist/src/pi/reset/committed.js +2 -2
- package/dist/src/pi/runtime.js +8 -5
- package/dist/src/pi/thresholds.js +5 -9
- package/dist/src/pi/tool-result.d.ts +1 -4
- package/dist/src/pi/tool-result.js +1 -1
- package/dist/src/pi/window.d.ts +5 -0
- package/dist/src/pi/window.js +7 -0
- package/dist/src/settings.d.ts +2 -0
- package/dist/src/settings.js +4 -3
- package/dist/src/tools/history.js +4 -7
- package/dist/src/tools/notes.d.ts +47 -21
- package/dist/src/tools/notes.js +20 -19
- package/dist/src/tools/output.d.ts +0 -3
- package/dist/src/tools/output.js +1 -9
- package/dist/src/tools/result.d.ts +1 -0
- package/dist/src/tools/result.js +14 -20
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/agent-loop.test.js +1 -2
- package/dist/test/boot.integration.test.js +1 -1
- package/dist/test/claude-mod.test.js +253 -10
- package/dist/test/claude-validation.test.d.ts +1 -0
- package/dist/test/claude-validation.test.js +73 -0
- package/dist/test/dream-skill.test.js +2 -4
- package/dist/test/dream.test.js +14 -0
- package/dist/test/helpers/extension.js +1 -1
- package/dist/test/history.integration.test.js +2 -1
- package/dist/test/host-neutral.test.js +15 -0
- package/dist/test/notes-library.test.js +30 -1
- package/dist/test/notes.integration.test.js +7 -7
- package/dist/test/notes.test.js +36 -14
- package/dist/test/project-home.test.d.ts +1 -0
- package/dist/test/project-home.test.js +134 -0
- package/dist/test/reset-lifecycle.test.js +1 -1
- package/docs/claude-code-mod.md +5 -3
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +359 -218
- package/mods/notesoup/hooks/register.ts +158 -67
- package/mods/notesoup/playbook.md +1 -1
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/mods/notesoup/skills/memory/SKILL.md +62 -0
- package/package.json +5 -3
- package/playbook.md +1 -1
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +2 -1
- package/src/boot/render.ts +11 -21
- package/src/boot/snapshot.ts +5 -5
- package/src/boot/text.ts +4 -2
- package/src/budget/parse.ts +39 -0
- package/src/budget/policy.ts +2 -6
- package/src/budget/text.ts +3 -0
- package/src/claude/helper.ts +4 -4
- package/src/claude/thresholds.ts +45 -62
- package/src/dream/lock.ts +3 -9
- package/src/dream/report.ts +5 -10
- package/src/history/history.ts +4 -2
- package/src/history/query.ts +10 -23
- package/src/notes/address.ts +9 -21
- package/src/notes/errors.ts +6 -0
- package/src/notes/frontmatter.ts +12 -2
- package/src/notes/identity.ts +1 -3
- package/src/notes/paths.ts +14 -52
- package/src/notes/project-home.ts +197 -0
- package/src/notes/store.ts +46 -45
- package/src/pi/boot.ts +15 -17
- package/src/pi/budget.ts +10 -11
- package/src/pi/dream/cli.ts +35 -10
- package/src/pi/estimate.ts +4 -4
- package/src/pi/history.ts +1 -5
- package/src/pi/notes/adapter.ts +3 -3
- package/src/pi/reset/artifacts.ts +4 -4
- package/src/pi/reset/committed.ts +2 -2
- package/src/pi/runtime.ts +7 -6
- package/src/pi/thresholds.ts +5 -11
- package/src/pi/tool-result.ts +1 -1
- package/src/pi/window.ts +8 -0
- package/src/settings.ts +4 -3
- package/src/tools/history.ts +4 -8
- package/src/tools/notes.ts +22 -25
- package/src/tools/output.ts +1 -12
- package/src/tools/result.ts +14 -19
- package/src/tools/schema.ts +0 -1
- package/dist/src/dream/playbook.d.ts +0 -1
- package/dist/src/dream/playbook.js +0 -2
- package/dist/src/pi/reset/text.d.ts +0 -4
- package/dist/src/pi/reset/text.js +0 -7
- package/src/dream/playbook.ts +0 -3
- package/src/pi/reset/text.ts +0 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -10,7 +10,11 @@ import { dispatch, handleLine } from "../src/claude/helper.js";
|
|
|
10
10
|
import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../src/claude/thresholds.js";
|
|
11
11
|
import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
|
|
12
12
|
import { PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
|
|
13
|
-
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../src/
|
|
13
|
+
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../src/budget/text.js";
|
|
14
|
+
import { createNotesStore } from "../src/notes/index.js";
|
|
15
|
+
import { resolveProjectHome } from "../src/notes/project-home.js";
|
|
16
|
+
import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
|
|
17
|
+
import { context, manager } from "./helpers/extension.js";
|
|
14
18
|
const identity = { home: mkdtempSync(join(tmpdir(), "claude-mod-")), sessionId: "session", cwd: process.cwd(), agent: "claude", model: "claude" };
|
|
15
19
|
async function callTool(tool, params) {
|
|
16
20
|
return await dispatch({ op: "tool", tool, identity, params });
|
|
@@ -42,12 +46,13 @@ function fakeEngine(home) {
|
|
|
42
46
|
notifications,
|
|
43
47
|
host: {
|
|
44
48
|
env: { get: async (name) => name === "PI_NOTES_HOME" ? home : undefined },
|
|
45
|
-
session: { id: async () => "hook-session", messages: async () => [], usage: async () => ({ context: {} }), compact: async () => ({ skip: "test default" }) },
|
|
49
|
+
session: { id: async () => "hook-session", cwd: async () => home, model: async () => "claude", messages: async () => [], usage: async () => ({ context: {} }), compact: async () => ({ skip: "test default" }) },
|
|
50
|
+
settings: { read: async () => ({}) },
|
|
46
51
|
command: { register: async (spec) => ({ command: spec.name }) },
|
|
47
52
|
clock: { after: () => { throw new Error("test has no pending manual timer"); } },
|
|
48
53
|
prompt: { submit: async () => undefined },
|
|
49
54
|
tool: { register: async (spec) => { registered.push(structuredClone(spec)); return { tool: `mcp__notesoup__${spec.name}` }; } },
|
|
50
|
-
ui: {
|
|
55
|
+
ui: { toast: async (text) => { notifications.push(text); }, log: (text) => { notifications.push(text); } },
|
|
51
56
|
process: { run: async (argv, init) => ({
|
|
52
57
|
exitCode: 0,
|
|
53
58
|
stdout: execFileSync(argv[0], argv.slice(1), { cwd: init?.cwd, input: init?.stdin, encoding: "utf8" }),
|
|
@@ -157,7 +162,14 @@ test("Claude limits derive from Claude's own auto-compact point, never a fixed p
|
|
|
157
162
|
assert.equal(percent.unit, "percent");
|
|
158
163
|
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
164
|
assert.equal(limitPoints({ env: { pctOverride: "50" } }).native, 50);
|
|
160
|
-
|
|
165
|
+
// A real window is never re-expressed on the assumed 200K window, and no point is zero:
|
|
166
|
+
// the mod treats `measured >= reset` as due, so a zero point would clear memory every turn.
|
|
167
|
+
const tiny = limitPoints({ usage: { window: 8_000 } });
|
|
168
|
+
assert.deepEqual({ source: tiny.source, unit: tiny.unit }, { source: "window", unit: "tokens" }, "a real window answers even below the reserves");
|
|
169
|
+
assert.ok(tiny.reset >= 1 && tiny.warn >= 1, "a window smaller than the reserves still has a point");
|
|
170
|
+
const absurdMargin = limitPoints({ settings: { notesoup: { resetMarginTokens: 400_000 } } });
|
|
171
|
+
assert.equal(absurdMargin.source, "percent");
|
|
172
|
+
assert.ok(absurdMargin.reset > 0 && absurdMargin.warn > 0, "an absurd margin cannot zero the percent fallback either");
|
|
161
173
|
});
|
|
162
174
|
test("Claude limits read margins from the notesoup settings shape and ignore garbage", () => {
|
|
163
175
|
const base = { usage: { window: 200_000 }, breakdown: { autoCompactThreshold: 167_000, isAutoCompactEnabled: true } };
|
|
@@ -252,7 +264,7 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
|
|
|
252
264
|
assert.deepEqual(notifications, [], "successful boot never notifies");
|
|
253
265
|
});
|
|
254
266
|
test("Claude Mod boot failure preserves fallback with available, absent, or failing notifications", async (t) => {
|
|
255
|
-
for (const mode of ["available", "no ui", "no
|
|
267
|
+
for (const mode of ["available", "no ui", "no toast", "throws", "rejects"]) {
|
|
256
268
|
await t.test(mode, async (t) => {
|
|
257
269
|
const hooks = await loadHookModule(t);
|
|
258
270
|
const home = mkdtempSync(join(tmpdir(), "claude-hook-home-"));
|
|
@@ -260,10 +272,10 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
260
272
|
const { host, notifications } = fakeEngine(home);
|
|
261
273
|
if (mode === "no ui")
|
|
262
274
|
delete host.ui;
|
|
263
|
-
else if (mode === "no
|
|
275
|
+
else if (mode === "no toast")
|
|
264
276
|
host.ui = {};
|
|
265
277
|
else if (mode === "throws" || mode === "rejects") {
|
|
266
|
-
host.ui = {
|
|
278
|
+
host.ui = { toast: (text) => {
|
|
267
279
|
notifications.push(text);
|
|
268
280
|
if (mode === "throws")
|
|
269
281
|
throw new Error("notification unavailable");
|
|
@@ -291,7 +303,7 @@ test("Claude Mod boot failure preserves fallback with available, absent, or fail
|
|
|
291
303
|
...upstream,
|
|
292
304
|
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." }],
|
|
293
305
|
}, "boot failure keeps the original fallback and upstream fields even if notify is absent or fails");
|
|
294
|
-
const expectedNotifications = mode === "no ui" || mode === "no
|
|
306
|
+
const expectedNotifications = mode === "no ui" || mode === "no toast" ? [] : ["🥣 Notes didn't load"];
|
|
295
307
|
assert.deepEqual(notifications, expectedNotifications, "one user-facing notification reports the notes boot failure");
|
|
296
308
|
assert.equal(bootRequests, 1);
|
|
297
309
|
assert.equal(nextCalls, 1);
|
|
@@ -585,10 +597,241 @@ test("Claude Mod skips the automatic reset when thresholds cannot be resolved",
|
|
|
585
597
|
assert.equal(compactions, 0, "an unresolvable point never resets");
|
|
586
598
|
assert.equal(notifications.filter((text) => text.includes("Context thresholds unavailable")).length, 1, "one line, not one per turn");
|
|
587
599
|
});
|
|
588
|
-
test("Claude
|
|
600
|
+
test("Claude skill projections stay byte-identical to canonical shared files", () => {
|
|
601
|
+
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/skills/memory/SKILL.md")), readFileSync(join(process.cwd(), "skills/memory/SKILL.md")));
|
|
589
602
|
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/skills/dream/SKILL.md")), readFileSync(join(process.cwd(), "skills/dream/SKILL.md")));
|
|
590
603
|
assert.deepEqual(readFileSync(join(process.cwd(), "mods/notesoup/playbook.md")), readFileSync(join(process.cwd(), "playbook.md")));
|
|
591
604
|
const skill = readFileSync(join(process.cwd(), "mods/notesoup/skills/dream/SKILL.md"), "utf8");
|
|
592
605
|
assert.match(skill, /\.\.\/\.\.\/playbook\.md/);
|
|
593
606
|
assert.doesNotMatch(skill, /Claude.*runner|dream runner/i);
|
|
594
607
|
});
|
|
608
|
+
test("Claude Mod keeps the turn latch through subagent turns", async (t) => {
|
|
609
|
+
const home = mkdtempSync(join(tmpdir(), "claude-subagent-home-"));
|
|
610
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
611
|
+
const { host } = fakeEngine(home);
|
|
612
|
+
const handlers = new Map();
|
|
613
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
614
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
615
|
+
let compactions = 0;
|
|
616
|
+
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
617
|
+
host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
|
|
618
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
619
|
+
await invoke("turn.start");
|
|
620
|
+
await invoke("turn.start", { agentId: "sub-1" });
|
|
621
|
+
await invoke("turn.complete", { agentId: "sub-1" });
|
|
622
|
+
await invoke("session.measure");
|
|
623
|
+
assert.equal(compactions, 0, "a subagent turn cannot release the main turn's latch");
|
|
624
|
+
await invoke("turn.complete");
|
|
625
|
+
assert.equal(compactions, 1, "the main turn still resets at its own end");
|
|
626
|
+
});
|
|
627
|
+
test("Claude Mod treats DISABLE_COMPACT=off as not disabled", async (t) => {
|
|
628
|
+
const home = mkdtempSync(join(tmpdir(), "claude-flag-off-home-"));
|
|
629
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
630
|
+
const { host, notifications } = fakeEngine(home);
|
|
631
|
+
host.env = { get: async (name) => name === "PI_NOTES_HOME" ? home : name === "DISABLE_COMPACT" ? "off" : undefined };
|
|
632
|
+
const handlers = new Map();
|
|
633
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
634
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
635
|
+
let compactions = 0;
|
|
636
|
+
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
637
|
+
host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
|
|
638
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
639
|
+
assert.deepEqual(notifications.filter((text) => text.includes("DISABLE_COMPACT")), [], "an explicit off is not a disable");
|
|
640
|
+
await invoke("turn.start");
|
|
641
|
+
await invoke("turn.complete");
|
|
642
|
+
assert.equal(compactions, 1, "the automatic reset still runs");
|
|
643
|
+
});
|
|
644
|
+
test("Claude Mod retries an unresolvable threshold inside the same window", async (t) => {
|
|
645
|
+
const home = mkdtempSync(join(tmpdir(), "claude-retry-home-"));
|
|
646
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
647
|
+
const { host } = fakeEngine(home);
|
|
648
|
+
const helper = host.process.run;
|
|
649
|
+
let limitsCalls = 0;
|
|
650
|
+
host.process.run = async (argv, init) => {
|
|
651
|
+
const request = JSON.parse(String(init?.stdin ?? "{}"));
|
|
652
|
+
if (request.op === "limits" && ++limitsCalls === 1)
|
|
653
|
+
return { exitCode: 1, stdout: "" };
|
|
654
|
+
return await helper(argv, init);
|
|
655
|
+
};
|
|
656
|
+
const handlers = new Map();
|
|
657
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
658
|
+
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
659
|
+
let compactions = 0;
|
|
660
|
+
host.session.usage = async () => ({ context: { tokens: 190_000, window: 200_000 } });
|
|
661
|
+
host.session.compact = async ({ instructions }) => { compactions++; return await invoke("session.compact", { trigger: "plugin", instructions }); };
|
|
662
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
663
|
+
await invoke("turn.start");
|
|
664
|
+
await invoke("turn.complete");
|
|
665
|
+
assert.equal(limitsCalls, 1, "the first limits round trip failed");
|
|
666
|
+
assert.equal(compactions, 0, "one failed resolution does not disable the window");
|
|
667
|
+
await invoke("turn.start");
|
|
668
|
+
await invoke("turn.complete");
|
|
669
|
+
assert.equal(limitsCalls, 2, "the retry runs in the same window");
|
|
670
|
+
assert.equal(compactions, 1, "the retried resolution resets at the turn's end");
|
|
671
|
+
});
|
|
672
|
+
/** Start from a real retained boot, as after notesoup reset or a plugin reload. */
|
|
673
|
+
async function retainedFixture(t) {
|
|
674
|
+
const home = mkdtempSync(join(tmpdir(), "claude-lifecycle-"));
|
|
675
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
676
|
+
const { host } = fakeEngine(home);
|
|
677
|
+
const boot = await dispatch({ op: "boot", identity: { ...identity, home, cwd: home, sessionId: "hook-session" }, window: 2, tools: {
|
|
678
|
+
notes: "mcp__notesoup__notes_*", notesList: "mcp__notesoup__notes_list",
|
|
679
|
+
history: "unavailable", remaining: "unavailable", wipe: "/clear-memory",
|
|
680
|
+
} });
|
|
681
|
+
host.session.messages = async () => [{ role: "user", text: `# notesoup:boot\n${boot}` }];
|
|
682
|
+
const handlers = new Map();
|
|
683
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
684
|
+
const invoke = (name, e = {}, result = {}) => handlers.get(name)(host, e, async () => result);
|
|
685
|
+
const context = async () => await invoke("prompt.context", {}, { blocks: [] });
|
|
686
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
687
|
+
assert.deepEqual((await context()).blocks, [], "the existing boot is retained, not injected twice");
|
|
688
|
+
return { home, host, invoke, context, boot };
|
|
689
|
+
}
|
|
690
|
+
test("Claude session.end gives /clear, /resume and /branch a fresh boot and identity", async (t) => {
|
|
691
|
+
for (const action of ["clear", "resume", "branch"]) {
|
|
692
|
+
await t.test(action, async (t) => {
|
|
693
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
694
|
+
host.session.usage = async () => ({ context: { tokens: 142_424, window: 200_000 } });
|
|
695
|
+
assert.equal((await context()).blocks[0]?.name, "notesoup:warning", "the old window has already warned");
|
|
696
|
+
await invoke("turn.start");
|
|
697
|
+
await invoke("command.run", { command: "clear-memory" });
|
|
698
|
+
const ended = { sentinel: action };
|
|
699
|
+
assert.equal(await invoke("session.end", { reason: action === "clear" ? "clear" : "resume", sessionId: "hook-session" }, ended), ended);
|
|
700
|
+
host.session.id = async () => `after-${action}`;
|
|
701
|
+
host.session.messages = async () => [];
|
|
702
|
+
// Clear the old running-turn and queued-reset state, not just the retained boot.
|
|
703
|
+
let compactions = 0;
|
|
704
|
+
host.session.compact = async () => { compactions++; return {}; };
|
|
705
|
+
await invoke("turn.complete");
|
|
706
|
+
assert.equal(compactions, 0, "the old queued reset cannot spill into the new session");
|
|
707
|
+
const fresh = await context();
|
|
708
|
+
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot", "notesoup:warning"]);
|
|
709
|
+
assert.match(fresh.blocks[0].text, new RegExp(`Current context window id: claude:after-${action}:0`));
|
|
710
|
+
assert.doesNotMatch(fresh.blocks[0].text, /claude:hook-session:/);
|
|
711
|
+
const requests = [];
|
|
712
|
+
const run = host.process.run;
|
|
713
|
+
host.process.run = async (argv, init) => { requests.push(JSON.parse(init.stdin)); return run(argv, init); };
|
|
714
|
+
const written = await invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "new-session", address: "session.md", content: action });
|
|
715
|
+
assert.equal(written.result, "created session.md");
|
|
716
|
+
assert.equal(requests[0].identity?.sessionId, `after-${action}`, "tools also use the new session home");
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
test("Claude lazy identity detects a switched session without session.start or session.end", async (t) => {
|
|
721
|
+
const { host, context } = await retainedFixture(t);
|
|
722
|
+
host.session.id = async () => "lazy-session";
|
|
723
|
+
host.session.messages = async () => [];
|
|
724
|
+
const fresh = await context();
|
|
725
|
+
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
726
|
+
assert.match(fresh.blocks[0].text, /Current context window id: claude:lazy-session:0/);
|
|
727
|
+
});
|
|
728
|
+
test("Claude native compaction invalidates only a removed main-conversation retained boot", async (t) => {
|
|
729
|
+
for (const mode of ["manual", "auto", "foreign plugin", "veto", "precompute", "subagent", "kept boot"]) {
|
|
730
|
+
await t.test(mode, async (t) => {
|
|
731
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
732
|
+
const before = { role: "user", text: "OLD" };
|
|
733
|
+
const trigger = mode === "foreign plugin" ? "plugin" : mode === "precompute" ? "precompute" : mode === "auto" ? "auto" : "manual";
|
|
734
|
+
const event = { trigger, messages: [before], ...(mode === "subagent" ? { agentId: "child" } : {}) };
|
|
735
|
+
const upstream = mode === "veto" ? { skip: "user veto" } : {
|
|
736
|
+
messages: mode === "kept boot" ? await host.session.messages() : [{ role: "user", text: "SUMMARY" }], sentinel: mode,
|
|
737
|
+
};
|
|
738
|
+
assert.equal(await invoke("session.compact", event, upstream), upstream, "native compaction is passed through unchanged");
|
|
739
|
+
const after = await context();
|
|
740
|
+
if (["manual", "auto", "foreign plugin"].includes(mode)) {
|
|
741
|
+
assert.deepEqual(after.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
742
|
+
assert.match(after.blocks[0].text, /Current context window id: claude:hook-session:2/);
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
assert.deepEqual(after.blocks, [], "veto, precompute and subagent leave the main boot alone");
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
test("Claude serves every registered notes tool to subagents without leaking event fields into params", async (t) => {
|
|
751
|
+
const { invoke } = await retainedFixture(t);
|
|
752
|
+
const call = (tool, params) => invoke("tool.call", {
|
|
753
|
+
tool: `mcp__notesoup__${tool}`, tool_use_id: "child-call", agentId: "child", ...params,
|
|
754
|
+
});
|
|
755
|
+
assert.equal((await call("notes_write", { address: "child.md", content: "child body" })).result, "created child.md");
|
|
756
|
+
assert.match((await call("notes_read", { address: "child.md" })).result, /child body/);
|
|
757
|
+
assert.equal((await call("notes_update", { address: "child.md", edits: [{ oldText: "child body", newText: "updated body" }] })).isError, undefined);
|
|
758
|
+
assert.match((await call("notes_list", {})).result, /child\.md/);
|
|
759
|
+
assert.match((await call("notes_search", { query: "updated body" })).result, /child\.md/);
|
|
760
|
+
assert.equal((await call("notes_read", { address: "absent.md" })).isError, true, "refusals retain the error discriminator in subagents");
|
|
761
|
+
});
|
|
762
|
+
test("Claude identity uses the documented current model and cwd, with a safe model fallback", async (t) => {
|
|
763
|
+
const { host, home, invoke } = await retainedFixture(t);
|
|
764
|
+
let model = "Claude Opus 4.6";
|
|
765
|
+
let cwd = home;
|
|
766
|
+
host.session.model = async () => model;
|
|
767
|
+
host.session.cwd = async () => cwd;
|
|
768
|
+
const seen = [];
|
|
769
|
+
const run = host.process.run;
|
|
770
|
+
host.process.run = async (argv, init) => { seen.push(JSON.parse(init.stdin)); return run(argv, init); };
|
|
771
|
+
const write = (address, content) => invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "model-call", address, content });
|
|
772
|
+
assert.equal((await write("@model/model.md", "opus")).result, "created @model/model.md");
|
|
773
|
+
assert.equal(seen.at(-1).identity.model, "claude-opus-4-6");
|
|
774
|
+
assert.ok(readFileSync(join(home, "models/claude-opus-4-6/model.md"), "utf8").includes("opus"));
|
|
775
|
+
model = "Claude Sonnet 4.6";
|
|
776
|
+
cwd = mkdtempSync(join(tmpdir(), "claude-cwd-"));
|
|
777
|
+
t.after(() => rmSync(cwd, { recursive: true, force: true }));
|
|
778
|
+
await write("@model/model.md", "sonnet");
|
|
779
|
+
assert.equal(seen.at(-1).identity.model, "claude-sonnet-4-6");
|
|
780
|
+
assert.equal(seen.at(-1).identity.cwd, cwd, "a /cd or worktree move is not frozen at session.start");
|
|
781
|
+
assert.ok(readFileSync(join(home, "models/claude-sonnet-4-6/model.md"), "utf8").includes("sonnet"));
|
|
782
|
+
host.session.model = async () => { throw new Error("model unavailable"); };
|
|
783
|
+
await write("@model/model.md", "fallback");
|
|
784
|
+
assert.equal(seen.at(-1).identity.model, "claude");
|
|
785
|
+
});
|
|
786
|
+
test("Claude current-cwd project resolution shares Pi's remote home across checkout spellings", async (t) => {
|
|
787
|
+
const { host, home, invoke } = await retainedFixture(t);
|
|
788
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "claude-project-home-")));
|
|
789
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
790
|
+
const first = join(root, "api");
|
|
791
|
+
const second = join(root, "renamed");
|
|
792
|
+
for (const [cwd, remote] of [[first, "git@HOST:team/backend.git"], [second, "https://host/team/backend.git"]]) {
|
|
793
|
+
mkdirSync(join(cwd, ".git"), { recursive: true });
|
|
794
|
+
writeFileSync(join(cwd, ".git/config"), `[remote "origin"]\nurl = ${remote}\n`);
|
|
795
|
+
}
|
|
796
|
+
let cwd = first;
|
|
797
|
+
host.session.cwd = async () => cwd;
|
|
798
|
+
const piIdentity = notesIdentityFromPi(context(manager(), undefined, undefined, true, first), home);
|
|
799
|
+
assert.equal(piIdentity.projectKey, "api");
|
|
800
|
+
await createNotesStore(piIdentity).write("@project/shared", "Pi body");
|
|
801
|
+
const call = (tool, params) => invoke("tool.call", {
|
|
802
|
+
tool: `mcp__notesoup__${tool}`, tool_use_id: "project-call", ...params,
|
|
803
|
+
});
|
|
804
|
+
assert.match((await call("notes_read", { address: "@project/shared" })).result, /Pi body/);
|
|
805
|
+
cwd = second;
|
|
806
|
+
const written = await call("notes_write", { address: "@project/shared", content: "Claude body" });
|
|
807
|
+
assert.equal(written.isError, undefined);
|
|
808
|
+
assert.equal(written.result, "overwrote @project/shared.md (project api)");
|
|
809
|
+
assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
|
|
810
|
+
assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
|
|
811
|
+
assert.equal(resolveProjectHome(second, home).name, piIdentity.projectKey);
|
|
812
|
+
});
|
|
813
|
+
test("Claude session.end cannot be undone by an in-flight old reset", async (t) => {
|
|
814
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
815
|
+
let prepared;
|
|
816
|
+
const ready = new Promise((resolve) => { prepared = resolve; });
|
|
817
|
+
let release;
|
|
818
|
+
const hold = new Promise((resolve) => { release = resolve; });
|
|
819
|
+
host.session.usage = async () => ({ context: { tokens: 170_000, window: 200_000 } });
|
|
820
|
+
host.session.compact = async ({ instructions }) => {
|
|
821
|
+
const result = await invoke("session.compact", { trigger: "plugin", instructions });
|
|
822
|
+
prepared();
|
|
823
|
+
await hold;
|
|
824
|
+
return result;
|
|
825
|
+
};
|
|
826
|
+
const finishing = invoke("turn.complete");
|
|
827
|
+
await ready;
|
|
828
|
+
await invoke("session.end", { reason: "clear", sessionId: "hook-session" });
|
|
829
|
+
host.session.id = async () => "after-flight";
|
|
830
|
+
host.session.messages = async () => [];
|
|
831
|
+
host.session.usage = async () => ({ context: {} });
|
|
832
|
+
release();
|
|
833
|
+
await finishing;
|
|
834
|
+
const fresh = await context();
|
|
835
|
+
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
836
|
+
assert.match(fresh.blocks[0].text, /Current context window id: claude:after-flight:0/);
|
|
837
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
const plugin = join(process.cwd(), "mods/notesoup");
|
|
8
|
+
/** Only an absent executable may skip the real loader gate; other failures fail the suite. */
|
|
9
|
+
function validate(t, dir) {
|
|
10
|
+
const result = spawnSync("claude", ["plugin", "validate", dir, "--strict", "--json"], {
|
|
11
|
+
encoding: "utf8", timeout: 30_000,
|
|
12
|
+
});
|
|
13
|
+
if (result.error?.code === "ENOENT") {
|
|
14
|
+
t.skip("Claude mod validation skipped: claude is not installed (not found on PATH)");
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
assert.ifError(result.error);
|
|
18
|
+
assert.equal(result.signal, null, result.stderr);
|
|
19
|
+
const report = JSON.parse(result.stdout);
|
|
20
|
+
return { ...result, report };
|
|
21
|
+
}
|
|
22
|
+
test("Claude mod passes the installed engine's strict loader validation", (t) => {
|
|
23
|
+
const result = validate(t, plugin);
|
|
24
|
+
if (!result)
|
|
25
|
+
return;
|
|
26
|
+
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
27
|
+
assert.equal(result.report.success, true, result.stdout);
|
|
28
|
+
t.diagnostic("claude plugin validate mods/notesoup --strict: passed");
|
|
29
|
+
});
|
|
30
|
+
test("Claude mod typechecks against the vendored engine contract without Node globals", () => {
|
|
31
|
+
const result = spawnSync(process.execPath, ["node_modules/typescript/bin/tsc", "-p", "mods/notesoup/tsconfig.json"], {
|
|
32
|
+
encoding: "utf8", timeout: 30_000,
|
|
33
|
+
});
|
|
34
|
+
assert.ifError(result.error);
|
|
35
|
+
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
36
|
+
});
|
|
37
|
+
// Test each original ScanRefusal independently against the real scanner. A regression must
|
|
38
|
+
// fail the gate rather than silently transpile in our fake engine's lifecycle tests.
|
|
39
|
+
for (const mutation of [
|
|
40
|
+
{
|
|
41
|
+
name: "variable environment names",
|
|
42
|
+
from: 'return await $.env.get("CLAUDE_AUTOCOMPACT_PCT_OVERRIDE")',
|
|
43
|
+
to: 'const name = "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"; return await $.env.get(name)',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "bound session usage ops",
|
|
47
|
+
from: "const context = (await $.session.usage()).context",
|
|
48
|
+
to: "const read = $.session.usage; const context = (await read()).context",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "bound settings nouns",
|
|
52
|
+
from: "return await $.settings.read()",
|
|
53
|
+
to: "const settings = $.settings; return await settings.read()",
|
|
54
|
+
},
|
|
55
|
+
]) {
|
|
56
|
+
test(`Claude loader gate rejects ${mutation.name}`, (t) => {
|
|
57
|
+
const fixture = mkdtempSync(join(tmpdir(), "claude-scanner-gate-"));
|
|
58
|
+
t.after(() => rmSync(fixture, { recursive: true, force: true }));
|
|
59
|
+
const dir = join(fixture, "notesoup");
|
|
60
|
+
cpSync(plugin, dir, { recursive: true });
|
|
61
|
+
const source = join(dir, "hooks/register.ts");
|
|
62
|
+
const text = readFileSync(source, "utf8");
|
|
63
|
+
assert.equal(text.split(mutation.from).length, 2, "one scanner-safe call site is mutated");
|
|
64
|
+
writeFileSync(source, text.replace(mutation.from, mutation.to));
|
|
65
|
+
const result = validate(t, dir);
|
|
66
|
+
if (!result)
|
|
67
|
+
return;
|
|
68
|
+
assert.notEqual(result.status, 0, "the strict gate must fail a loader refusal");
|
|
69
|
+
assert.equal(result.report.success, false);
|
|
70
|
+
// This build emits a null error code for ScanRefusal, so use the module error path.
|
|
71
|
+
assert.ok(result.report.contents.some((entry) => entry.errors.some((error) => error.path === "modules../register.ts")), result.stdout);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -6,7 +6,6 @@ import { tmpdir } from "node:os";
|
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { loadSkillsFromDir } from "@earendil-works/pi-coding-agent";
|
|
9
|
-
import { loadPlaybook } from "../src/dream/playbook.js";
|
|
10
9
|
function packageRoot() {
|
|
11
10
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
12
11
|
while (!existsSync(join(dir, "package.json"))) {
|
|
@@ -38,7 +37,7 @@ test("dream skill is publicly discoverable and resolves the CLI's shared playboo
|
|
|
38
37
|
const packagePlaybook = resolve(root, "playbook.md");
|
|
39
38
|
assert.equal(skillPlaybook, packagePlaybook);
|
|
40
39
|
const playbook = readFileSync(packagePlaybook, "utf8");
|
|
41
|
-
assert.equal(
|
|
40
|
+
assert.equal(readFileSync(skillPlaybook, "utf8"), playbook);
|
|
42
41
|
});
|
|
43
42
|
test("npm tarball keeps the skill's relative playbook path portable after extraction", () => {
|
|
44
43
|
const root = packageRoot();
|
|
@@ -63,8 +62,7 @@ test("npm tarball keeps the skill's relative playbook path portable after extrac
|
|
|
63
62
|
const installedSkill = discoverSkill(join(installedRoot, "skills"), "dream");
|
|
64
63
|
const referencedPlaybook = resolve(installedSkill.baseDir, "../../playbook.md");
|
|
65
64
|
assert.equal(referencedPlaybook, resolve(installedRoot, "playbook.md"));
|
|
66
|
-
assert.equal(
|
|
67
|
-
assert.equal(loadPlaybook(referencedPlaybook), readFileSync(join(root, "playbook.md"), "utf8"));
|
|
65
|
+
assert.equal(readFileSync(referencedPlaybook, "utf8"), readFileSync(join(root, "playbook.md"), "utf8"));
|
|
68
66
|
}
|
|
69
67
|
finally {
|
|
70
68
|
rmSync(fixture, { recursive: true, force: true });
|
package/dist/test/dream.test.js
CHANGED
|
@@ -134,3 +134,17 @@ test("CLI commits partial writes when report writing fails", async () => {
|
|
|
134
134
|
assert.match(execFileSync("git", ["log", "--format=%s"], { cwd: home, encoding: "utf8" }).trim(), /\(failed\)/);
|
|
135
135
|
assert.equal(execFileSync("git", ["show", "HEAD:global/partial.md"], { cwd: home, encoding: "utf8" }), "half");
|
|
136
136
|
});
|
|
137
|
+
test("CLI refuses a malformed flag value before creating anything", async () => {
|
|
138
|
+
const numberHome = join(fixture(), "notes");
|
|
139
|
+
const badNumber = await captureErrors(() => main(["--notes-home", numberHome, "--min-hours", "abc"], { dreamerSettings: () => ({ warnings: [] }) }));
|
|
140
|
+
assert.equal(badNumber.code, 1);
|
|
141
|
+
assert.ok(badNumber.errors.some((line) => /--min-hours needs a positive whole number/.test(line)), badNumber.errors.join("\n"));
|
|
142
|
+
assert.equal(existsSync(numberHome), false, "a bad number is refused before the home is created");
|
|
143
|
+
for (const value of ["", "--force"]) {
|
|
144
|
+
const home = join(fixture(), "notes");
|
|
145
|
+
const badHome = await captureErrors(() => main(["--notes-home", value], { dreamerSettings: () => ({ warnings: [] }) }));
|
|
146
|
+
assert.equal(badHome.code, 1, `--notes-home ${JSON.stringify(value)} is refused`);
|
|
147
|
+
assert.ok(badHome.errors.some((line) => /--notes-home needs a directory path/.test(line)), badHome.errors.join("\n"));
|
|
148
|
+
assert.equal(existsSync(home), false, "a flag-looking path never becomes the home");
|
|
149
|
+
}
|
|
150
|
+
});
|
|
@@ -136,7 +136,7 @@ export function makeExtension(sessionManager, settingsManager) {
|
|
|
136
136
|
export async function explicitBoot(ctx, currentWindowId, previousWindowId) {
|
|
137
137
|
return renderBootBlock({
|
|
138
138
|
tools: PI_TOOL_NAMES,
|
|
139
|
-
agentName: agentSlug(
|
|
139
|
+
agentName: agentSlug(),
|
|
140
140
|
modelName: modelSlug(ctx),
|
|
141
141
|
firstWindowId: rootWindowId(ctx.sessionManager.getSessionId()),
|
|
142
142
|
currentWindowId,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { Check } from "typebox/value";
|
|
4
|
-
import {
|
|
4
|
+
import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
5
|
+
import { earliestMatchOffsetChars } from "../src/text-match.js";
|
|
5
6
|
import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
|
|
6
7
|
import { historyDocument, projectHistory } from "../src/history/history.js";
|
|
7
8
|
import { selectPage } from "../src/history/query.js";
|
|
@@ -272,3 +272,18 @@ test("one role schema declares the four public roles for the page item, the read
|
|
|
272
272
|
assert.equal(Check(HistoryRoleSchema, "developer"), false, "a role outside the four is refused");
|
|
273
273
|
assert.equal(Check(historyRead.outputSchema, read("developer")), false, "history_read refuses a role outside the four");
|
|
274
274
|
});
|
|
275
|
+
test("history paging bounds are the schema's, and a zero limit still pages one event", async () => {
|
|
276
|
+
const items = Array.from({ length: 3 }, (_, index) => ({ seq: index + 1, windowId: "root", role: "user", text: `message-${index}` }));
|
|
277
|
+
const projection = projectHistory([{ windowId: "root", items }], 3, new Set([1, 2, 3]));
|
|
278
|
+
assert.equal(Check(historyList.parameters, { limit: 0 }), false, "the schema refuses a zero limit");
|
|
279
|
+
assert.equal(Check(historyList.parameters, { limit: 501 }), false, "the schema refuses a limit past its maximum");
|
|
280
|
+
assert.equal(Check(historyList.parameters, { max_chars_per_item: 0 }), false, "the schema refuses a zero preview budget");
|
|
281
|
+
const zero = data(await historyList.execute({ limit: 0, from: "oldest", roles: ["user"] }, projection));
|
|
282
|
+
assert.equal(zero.items.length, 1, "an unvalidated zero limit still returns one row instead of none");
|
|
283
|
+
const negative = data(await historyList.execute({ max_chars_per_item: -5, roles: ["user"] }, projection));
|
|
284
|
+
const row = negative.items[0];
|
|
285
|
+
if ("folded" in row)
|
|
286
|
+
assert.fail("a role filter returns event rows only");
|
|
287
|
+
assert.equal(row.content, "", "a negative budget delivers nothing instead of cutting the tail");
|
|
288
|
+
assert.equal(row.truncated, true, "the empty preview says it was truncated");
|
|
289
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import test from "node:test";
|
|
@@ -212,3 +212,32 @@ test("a massively ambiguous edit still reports every match line to a library cal
|
|
|
212
212
|
});
|
|
213
213
|
assert.equal((await notes.read("many"))?.body.startsWith("beta\nbeta"), true, "the refused edit left the body alone");
|
|
214
214
|
});
|
|
215
|
+
test("one unreadable note is named without hiding its readable siblings", async (t) => {
|
|
216
|
+
if (process.getuid?.() === 0 || process.platform === "win32")
|
|
217
|
+
return t.skip("chmod 000 is not a read refusal for this user");
|
|
218
|
+
const { home, notes } = fixture(t);
|
|
219
|
+
await notes.write("@project/bad.md", "bad body");
|
|
220
|
+
await notes.write("@project/good.md", "good body");
|
|
221
|
+
chmodSync(join(home, "project", "project-12345678", "bad.md"), 0o000);
|
|
222
|
+
const result = await notes.listWithStatus({ scope: "project" });
|
|
223
|
+
assert.deepEqual(result.rows.map((row) => row.address), ["@project/good.md"], "the readable sibling still lists");
|
|
224
|
+
assert.deepEqual(result.status.homesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
|
|
225
|
+
await assert.rejects(() => notes.list({ scope: "project" }), (error) => error.code === "EACCES", "a caller that asked for no status still sees the failure");
|
|
226
|
+
});
|
|
227
|
+
test("a hand-written quoted numeric extra survives a rewrite as a string", async (t) => {
|
|
228
|
+
const { home, notes } = fixture(t);
|
|
229
|
+
await notes.write("typed", "body");
|
|
230
|
+
const path = join(home, "pi/session/session-a/typed.md");
|
|
231
|
+
writeFileSync(path, readFileSync(path, "utf8").replace("\n---\n\n", "\ncount: \"1\"\n---\n\n"));
|
|
232
|
+
assert.equal((await notes.read("typed"))?.meta.count, "1", "a quoted scalar is read as text");
|
|
233
|
+
const raw = readFileSync(path, "utf8");
|
|
234
|
+
assert.match(raw, /^count: "1"$/m, "a bare 1 would read back as a number");
|
|
235
|
+
assert.match(raw, /^origin: self$/m, "an ordinary string still stays bare");
|
|
236
|
+
});
|
|
237
|
+
test("writing keeps an existing note's origin unless the caller names one", async (t) => {
|
|
238
|
+
const { notes } = fixture(t);
|
|
239
|
+
await notes.write("owned", "first", { origin: "user" });
|
|
240
|
+
assert.equal((await notes.write("owned", "second")).meta.origin, "user", "a rewrite does not re-attribute the note");
|
|
241
|
+
assert.equal((await notes.write("owned", "third", { origin: "external" })).meta.origin, "external", "an explicit origin still wins");
|
|
242
|
+
assert.equal((await notes.write("fresh", "new")).meta.origin, "self", "a new note still defaults to self");
|
|
243
|
+
});
|
|
@@ -272,18 +272,18 @@ test("the boot block gives awake agents the notes-home file layout", async () =>
|
|
|
272
272
|
assert.equal(rendered.includes(process.env.PI_NOTES_HOME ?? ""), false, "the absolute notes home is never exposed");
|
|
273
273
|
assert.match(rendered, /`<path>`, no @[\s\S]*`@project\/<path>`[\s\S]*`@human\/<path>`/);
|
|
274
274
|
});
|
|
275
|
-
test("the boot
|
|
275
|
+
test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer", async () => {
|
|
276
276
|
const session = manager();
|
|
277
277
|
const captured = makeExtension(session);
|
|
278
278
|
const ctx = context(session);
|
|
279
279
|
await call(captured, "notes_write", { address: "MAP.md", content: "M".repeat(MAP_BOOT_MAX_CHARS + 10) }, ctx);
|
|
280
280
|
const rendered = await explicitBoot(ctx, "pcw:test:root", undefined);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
assert.ok(rendered.includes("
|
|
285
|
-
assert.
|
|
286
|
-
assert.
|
|
281
|
+
for (const tool of ["notes_*", "history_*", "get_context_remaining", "clear_memory"]) {
|
|
282
|
+
assert.ok(rendered.includes(`\`${tool}\``), `${tool} is bound in the protocol`);
|
|
283
|
+
}
|
|
284
|
+
assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
|
|
285
|
+
assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false, "the over-cap suffix is not inlined");
|
|
286
|
+
assert.ok(rendered.includes("`MAP.md`"), "the full MAP remains available by address");
|
|
287
287
|
for (const retired of ["history_windows", "history_list", "history_read"]) {
|
|
288
288
|
assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
|
|
289
289
|
}
|