notesoup 0.51.8 → 0.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -10
- package/dist/plugins/claude/src/history.js +3 -7
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +27 -7
- package/dist/plugins/pi/render.d.ts +40 -0
- package/dist/plugins/pi/render.js +168 -0
- package/dist/plugins/pi/runtime.js +3 -0
- package/dist/plugins/pi/tool-result.d.ts +5 -2
- package/dist/plugins/pi/tool-result.js +4 -1
- package/dist/src/dream/git.d.ts +2 -3
- package/dist/src/dream/git.js +3 -8
- package/dist/src/dream/lock.d.ts +10 -27
- package/dist/src/dream/lock.js +16 -79
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/identity.d.ts +2 -0
- package/dist/src/notes/identity.js +3 -1
- package/dist/src/notes/store.d.ts +2 -0
- package/dist/src/notes/store.js +40 -4
- package/dist/src/tools/dream.d.ts +113 -0
- package/dist/src/tools/dream.js +112 -0
- package/dist/src/tools/notes.d.ts +15 -1
- package/dist/src/tools/notes.js +4 -4
- package/dist/test/claude-history.test.js +18 -2
- package/dist/test/claude-mod.test.js +115 -30
- package/dist/test/dependencies.test.js +3 -6
- package/dist/test/dream-skill.test.js +2 -3
- package/dist/test/dream-tools.test.js +67 -0
- package/dist/test/pi-render.test.js +89 -0
- package/docs/claude-code-mod.md +1 -1
- package/docs/notes-library.md +1 -1
- package/docs/skills.md +12 -15
- package/package.json +151 -149
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +30 -22
- package/plugins/claude/hooks/register.ts +52 -33
- package/plugins/claude/src/history.ts +3 -6
- package/plugins/pi/notes/tools.ts +26 -8
- package/plugins/pi/render.ts +165 -0
- package/plugins/pi/runtime.ts +3 -0
- package/plugins/pi/tool-result.ts +9 -1
- package/src/dream/git.ts +3 -8
- package/src/dream/lock.ts +18 -66
- package/src/notes/errors.ts +1 -1
- package/src/notes/identity.ts +4 -1
- package/src/notes/store.ts +37 -4
- package/src/tools/dream.ts +112 -0
- package/src/tools/notes.ts +4 -4
- package/dist/plugins/pi/dream/cli.d.ts +0 -10
- package/dist/plugins/pi/dream/cli.js +0 -173
- package/dist/plugins/pi/dream/runner.d.ts +0 -27
- package/dist/plugins/pi/dream/runner.js +0 -91
- package/dist/plugins/pi/dream/settings.d.ts +0 -7
- package/dist/plugins/pi/dream/settings.js +0 -17
- package/dist/src/dream/doctor.d.ts +0 -2
- package/dist/src/dream/doctor.js +0 -161
- package/dist/src/dream/gates.d.ts +0 -10
- package/dist/src/dream/gates.js +0 -26
- package/dist/src/dream/jail.d.ts +0 -11
- package/dist/src/dream/jail.js +0 -71
- package/dist/src/dream/report.d.ts +0 -7
- package/dist/src/dream/report.js +0 -34
- package/dist/src/dream/result.d.ts +0 -9
- package/dist/src/dream/settings.d.ts +0 -9
- package/dist/src/dream/settings.js +0 -16
- package/dist/test/doctor.test.js +0 -37
- package/dist/test/dream.test.d.ts +0 -1
- package/dist/test/dream.test.js +0 -150
- package/plugins/pi/dream/cli.ts +0 -118
- package/plugins/pi/dream/runner.ts +0 -92
- package/plugins/pi/dream/settings.ts +0 -17
- package/src/dream/doctor.ts +0 -118
- package/src/dream/gates.ts +0 -26
- package/src/dream/jail.ts +0 -62
- package/src/dream/report.ts +0 -32
- package/src/dream/result.ts +0 -2
- package/src/dream/settings.ts +0 -19
- /package/dist/{src/dream/result.js → test/dream-tools.test.d.ts} +0 -0
- /package/dist/test/{doctor.test.d.ts → pi-render.test.d.ts} +0 -0
|
@@ -36,7 +36,13 @@ async function loadHookModule(t) {
|
|
|
36
36
|
t.after(() => rmSync(loaded, { recursive: true, force: true }));
|
|
37
37
|
const module = join(loaded, "register.mjs");
|
|
38
38
|
writeFileSync(module, transpiled.outputFiles[0].text);
|
|
39
|
-
|
|
39
|
+
const hooks = await import(pathToFileURL(module).href);
|
|
40
|
+
return { register: (on) => hooks.register((event, matcherOrHandler, handler) => {
|
|
41
|
+
if (typeof matcherOrHandler === "function")
|
|
42
|
+
on(event, matcherOrHandler);
|
|
43
|
+
else
|
|
44
|
+
on(event, ($, e, next) => Object.entries(matcherOrHandler).every(([key, value]) => e[key] === value) ? handler($, e, next) : next(e));
|
|
45
|
+
}) };
|
|
40
46
|
}
|
|
41
47
|
/** An engine that answers the hook by running the real helper against a throwaway notes home. */
|
|
42
48
|
function fakeEngine(home) {
|
|
@@ -331,6 +337,43 @@ test("Claude Mod with NOTESOUP_DISABLED registers nothing and passes every event
|
|
|
331
337
|
const measured = await handlers.get("session.measure")(host, {}, async () => ({ marks: true }));
|
|
332
338
|
assert.deepEqual(measured, { marks: true }, "session.measure passes through without a reset");
|
|
333
339
|
assert.equal(helperCalls, 0, "the helper never runs while disabled");
|
|
340
|
+
const event = { text: "continue", context: ["upstream"] };
|
|
341
|
+
assert.equal(await handlers.get("prompt.submit")(host, event, async (e) => e), event);
|
|
342
|
+
const tool = { result: "upstream" };
|
|
343
|
+
assert.equal(await handlers.get("tool.call")(host, { tool: "Read" }, async () => tool), tool);
|
|
344
|
+
assert.equal(helperCalls, 0, "disabled warning routes are transparent too");
|
|
345
|
+
});
|
|
346
|
+
test("Claude Mod omits context_management always and memory unless kept; disabled passes through", async (t) => {
|
|
347
|
+
for (const mode of ["default", "keep", "disabled"]) {
|
|
348
|
+
await t.test(mode, async (t) => {
|
|
349
|
+
const home = mkdtempSync(join(tmpdir(), "claude-context-section-"));
|
|
350
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
351
|
+
const { host } = fakeEngine(home);
|
|
352
|
+
const readEnv = host.env.get;
|
|
353
|
+
host.env.get = async (name) => name === "NOTESOUP_KEEP_MEMORY" ? (mode === "keep" ? " YES " : undefined)
|
|
354
|
+
: name === "NOTESOUP_DISABLED" && mode === "disabled" ? "1" : readEnv(name);
|
|
355
|
+
const handlers = new Map(), sections = [];
|
|
356
|
+
(await loadHookModule(t)).register((event, handler) => event === "prompt.section" ? sections.push(handler) : handlers.set(event, handler));
|
|
357
|
+
await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async () => ({}));
|
|
358
|
+
for (const name of ["context_management", "memory"]) {
|
|
359
|
+
const event = { name, text: `engine ${name}` };
|
|
360
|
+
const upstream = { text: event.text };
|
|
361
|
+
let calls = 0;
|
|
362
|
+
const next = async (e) => { assert.equal(e, event); calls++; return upstream; };
|
|
363
|
+
// Chain the section hooks as the engine does; each matcher passes other names along.
|
|
364
|
+
const result = await sections.reduceRight((rest, handler) => (e) => handler(host, e, rest), next)(event);
|
|
365
|
+
const kept = mode === "disabled" || (mode === "keep" && name === "memory");
|
|
366
|
+
if (kept) {
|
|
367
|
+
assert.equal(result, upstream);
|
|
368
|
+
assert.equal(calls, 1);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
assert.deepEqual(result, { text: null });
|
|
372
|
+
assert.equal(calls, 0);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
334
377
|
});
|
|
335
378
|
test("Claude Mod boot failure preserves fallback with available, absent, or failing notifications", async (t) => {
|
|
336
379
|
for (const mode of ["available", "no ui", "no toast", "throws", "rejects"]) {
|
|
@@ -500,6 +543,8 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
|
|
|
500
543
|
assert.equal(notifications.length, 1);
|
|
501
544
|
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
502
545
|
assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
546
|
+
const event = { text: "continue" };
|
|
547
|
+
assert.equal(await handlers.get("prompt.submit")(host, event, async (e) => e), event, "headless prompts never warn");
|
|
503
548
|
});
|
|
504
549
|
test("Claude Mod keeps its window numbering from a boot written before the tag rename", async (t) => {
|
|
505
550
|
const home = mkdtempSync(join(tmpdir(), "claude-legacy-boot-"));
|
|
@@ -602,33 +647,65 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
602
647
|
assert.equal(prompts.length, 1, "a busy manual request reuses the current turn instead of submitting another");
|
|
603
648
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:2/);
|
|
604
649
|
});
|
|
605
|
-
test("Claude Mod
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const handlers = new Map();
|
|
610
|
-
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
611
|
-
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
612
|
-
let tokens = 142_423;
|
|
650
|
+
test("Claude Mod delivers one warning per window through main tools or prompt submission, never boot", async (t) => {
|
|
651
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
652
|
+
const texts = await dispatch({ op: "texts" });
|
|
653
|
+
let tokens = CLAUDE_200K.warn - 1;
|
|
613
654
|
host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
assert.
|
|
622
|
-
assert.equal(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
await
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
assert.deepEqual(
|
|
631
|
-
assert.equal(
|
|
655
|
+
const foreign = { result: "upstream result", context: ["upstream context"], ref: 1 };
|
|
656
|
+
const tool = (event = { tool: "Read" }, result = foreign) => invoke("tool.call", event, result);
|
|
657
|
+
const submit = () => invoke("prompt.submit", { text: "continue", context: ["earlier plugin"] }, {}, async (e) => e);
|
|
658
|
+
assert.equal(await tool(), foreign, "below the warn point the result passes through untouched");
|
|
659
|
+
tokens++;
|
|
660
|
+
assert.deepEqual((await context()).blocks, [], "prompt.context never delivers a warning, even above the runway");
|
|
661
|
+
const denied = { deny: "upstream refusal" };
|
|
662
|
+
assert.equal(await tool({ tool: "Read" }, denied), denied, "deny stays unchanged and does not consume the warning");
|
|
663
|
+
assert.equal(await invoke("tool.call", { tool: "Read", agentId: "child" }, foreign), foreign, "subagent results do not warn");
|
|
664
|
+
const own = await tool({ tool: "mcp__notesoup__notes_list" });
|
|
665
|
+
assert.equal(typeof own.result, "string", "a self-registered result still carries its original text");
|
|
666
|
+
assert.deepEqual(own.context, [texts.warning]);
|
|
667
|
+
assert.equal(await tool(), foreign, "another tool cannot warn twice in the same window");
|
|
668
|
+
assert.deepEqual((await submit()).context, ["earlier plugin"], "tool delivery also consumes the prompt route");
|
|
669
|
+
const reset = () => invoke("session.compact", { trigger: "auto", messages: [] });
|
|
670
|
+
await reset();
|
|
671
|
+
assert.deepEqual(await tool(), { ...foreign, context: [...foreign.context, texts.warning] }, "a new window can warn through a next() tool result");
|
|
672
|
+
assert.equal(await tool(), foreign);
|
|
673
|
+
await reset();
|
|
674
|
+
assert.deepEqual((await submit()).context, ["earlier plugin", texts.warning], "prompt submission preserves earlier context and warns once");
|
|
675
|
+
assert.deepEqual((await submit()).context, ["earlier plugin"]);
|
|
676
|
+
assert.equal(await tool(), foreign, "prompt delivery wins over the later tool route");
|
|
677
|
+
assert.deepEqual((await context()).blocks, [], "no notesoup:warning block is ever added to prompt context");
|
|
678
|
+
});
|
|
679
|
+
test("Claude Mod consumes a warning only after an accepted delivery and ignores stale generations", async (t) => {
|
|
680
|
+
const { host, invoke } = await retainedFixture(t);
|
|
681
|
+
const texts = await dispatch({ op: "texts" });
|
|
682
|
+
host.session.usage = async () => ({ context: { tokens: CLAUDE_200K.warn, window: 200_000 } });
|
|
683
|
+
const event = { text: "continue", context: ["upstream"] };
|
|
684
|
+
const drop = { drop: "another plugin refused" };
|
|
685
|
+
assert.equal(await invoke("prompt.submit", event, drop), drop);
|
|
686
|
+
await assert.rejects(invoke("prompt.submit", event, {}, async () => { throw new Error("submission failed"); }), /submission failed/);
|
|
687
|
+
assert.deepEqual(await invoke("prompt.submit", event, event), event, "a downstream context rewrite does not count as delivery");
|
|
688
|
+
let entered, release;
|
|
689
|
+
const ready = new Promise((resolve) => { entered = resolve; });
|
|
690
|
+
const held = new Promise((resolve) => { release = resolve; });
|
|
691
|
+
const pending = invoke("prompt.submit", event, {}, async (e) => {
|
|
692
|
+
assert.deepEqual(e.context, [...event.context, texts.warning]);
|
|
693
|
+
entered();
|
|
694
|
+
await held;
|
|
695
|
+
return e;
|
|
696
|
+
});
|
|
697
|
+
await ready;
|
|
698
|
+
const result = { result: "tool while prompt enters" };
|
|
699
|
+
assert.equal(await invoke("tool.call", { tool: "Read" }, result), result, "an in-flight accepted route reserves this window against duplicate tool delivery");
|
|
700
|
+
await invoke("session.end", { reason: "clear" });
|
|
701
|
+
host.session.id = async () => "next-session";
|
|
702
|
+
host.session.messages = async () => [];
|
|
703
|
+
await invoke("prompt.context", {}, { blocks: [] });
|
|
704
|
+
release();
|
|
705
|
+
await pending;
|
|
706
|
+
const delivered = await invoke("prompt.submit", event, {}, async (e) => e);
|
|
707
|
+
assert.deepEqual(delivered.context, [...event.context, texts.warning], "an old delivery cannot mark the new generation warned");
|
|
708
|
+
assert.equal(await invoke("prompt.submit", event, event), event, "only an accepted delivery consumes the new window");
|
|
632
709
|
});
|
|
633
710
|
test("Claude Mod moves the reset point to the hard window when auto-compact is off", async (t) => {
|
|
634
711
|
const home = mkdtempSync(join(tmpdir(), "claude-off-home-"));
|
|
@@ -677,6 +754,8 @@ test("Claude Mod stops the automatic reset and the manual command under DISABLE_
|
|
|
677
754
|
await invoke("session.measure");
|
|
678
755
|
assert.equal(compactions, 0, "the automatic reset is off and does not retry");
|
|
679
756
|
assert.equal(notifications.length, 1, "detection logs once, not per turn");
|
|
757
|
+
const upstream = { result: "upstream", context: ["other plugin"] };
|
|
758
|
+
assert.equal(await handlers.get("tool.call")(host, { tool: "Read" }, async () => upstream), upstream, "DISABLE_COMPACT also suppresses warnings");
|
|
680
759
|
});
|
|
681
760
|
test("Claude Mod skips the automatic reset when thresholds cannot be resolved", async (t) => {
|
|
682
761
|
const home = mkdtempSync(join(tmpdir(), "claude-nolimits-home-"));
|
|
@@ -829,7 +908,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
829
908
|
await t.test(action, async (t) => {
|
|
830
909
|
const { host, invoke, context } = await retainedFixture(t);
|
|
831
910
|
host.session.usage = async () => ({ context: { tokens: 142_424, window: 200_000 } });
|
|
832
|
-
assert.
|
|
911
|
+
assert.deepEqual((await invoke("prompt.submit", { text: "continue" }, {}, async (e) => e)).context, [CLAUDE_WARNING_PROMPT], "the old window has already warned");
|
|
833
912
|
await invoke("turn.start");
|
|
834
913
|
await invoke("command.run", { command: "empty" });
|
|
835
914
|
const ended = { sentinel: action };
|
|
@@ -842,7 +921,8 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
842
921
|
await invoke("turn.complete");
|
|
843
922
|
assert.equal(compactions, 0, "the old queued reset cannot spill into the new session");
|
|
844
923
|
const fresh = await context();
|
|
845
|
-
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"
|
|
924
|
+
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
925
|
+
assert.deepEqual((await invoke("prompt.submit", { text: "continue" }, {}, async (e) => e)).context, [CLAUDE_WARNING_PROMPT], "the new session can warn again");
|
|
846
926
|
assert.match(fresh.blocks[0].text, new RegExp(`Current context window id: claude:after-${action}:0`));
|
|
847
927
|
assert.doesNotMatch(fresh.blocks[0].text, /claude:hook-session:/);
|
|
848
928
|
const requests = [];
|
|
@@ -941,7 +1021,12 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
|
|
|
941
1021
|
host.session.cwd = async () => cwd;
|
|
942
1022
|
const seen = [];
|
|
943
1023
|
const run = host.process.run;
|
|
944
|
-
host.process.run = async (argv, init) => {
|
|
1024
|
+
host.process.run = async (argv, init) => {
|
|
1025
|
+
const request = JSON.parse(init.stdin);
|
|
1026
|
+
if (request.op === "tool")
|
|
1027
|
+
seen.push(request);
|
|
1028
|
+
return run(argv, init);
|
|
1029
|
+
};
|
|
945
1030
|
const write = (address, content) => invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "model-call", address, content });
|
|
946
1031
|
assert.equal((await write("@model/model.md", "opus")).result, "created @model/model.md");
|
|
947
1032
|
assert.equal(seen.at(-1).identity.model, "claude-opus-4-6");
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
2
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
4
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -149,7 +148,7 @@ test("the core entry is host-neutral and the Pi plugin entry owns the extension"
|
|
|
149
148
|
assert.equal(pi.createNotesoup, createNotesoup);
|
|
150
149
|
assert.equal(typeof createNotesoup(), "function");
|
|
151
150
|
});
|
|
152
|
-
test("the configured extension source
|
|
151
|
+
test("the configured extension source is the executable current entry", async () => {
|
|
153
152
|
const root = repository();
|
|
154
153
|
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
155
154
|
assert.deepEqual(manifest.pi.extensions, ["./plugins/pi/index.ts"], "Pi loads the plugin entry from TypeScript source");
|
|
@@ -163,11 +162,9 @@ test("the configured extension source and the moved dream CLI are executable cur
|
|
|
163
162
|
registerTool(tool) { tools.push(tool); },
|
|
164
163
|
registerCommand(name) { commands.push(name); },
|
|
165
164
|
});
|
|
166
|
-
assert.deepEqual(tools.map((tool) => tool.name).sort(), ["empty_brain", "get_context_remaining", "history_list", "history_read", "history_windows", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
|
|
165
|
+
assert.deepEqual(tools.map((tool) => tool.name).sort(), ["dream_begin", "dream_end", "dream_forget", "empty_brain", "get_context_remaining", "history_list", "history_read", "history_windows", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
|
|
166
|
+
assert.deepEqual(tools.filter((tool) => tool.exposure === "deferred").map((tool) => tool.name).sort(), ["dream_begin", "dream_end", "dream_forget"], "dream tools stay hidden until searched");
|
|
167
167
|
assert.deepEqual(commands.sort(), ["empty", "fresh-window", "notesoup"]);
|
|
168
|
-
const help = execFileSync(process.execPath, [resolve(root, manifest.bin.dream), "--help"], { cwd: root, encoding: "utf8" });
|
|
169
|
-
assert.ok(help.startsWith("dream doctor [--notes-home <dir>]"));
|
|
170
|
-
assert.ok(help.includes("Default playbook: <installed package root>/playbook.md"));
|
|
171
168
|
});
|
|
172
169
|
test("NOTESOUP_DISABLED turns the Pi extension fully off", async () => {
|
|
173
170
|
const built = await import(pathToFileURL(resolve(repository(), "dist/plugins/pi/index.js")).href);
|
|
@@ -24,12 +24,12 @@ function discoverSkill(skillsDir, name) {
|
|
|
24
24
|
assert.ok(skill.description.length > 0);
|
|
25
25
|
return skill;
|
|
26
26
|
}
|
|
27
|
-
test("dream skill is publicly discoverable and resolves the
|
|
27
|
+
test("dream skill is publicly discoverable and resolves the shared playbook", () => {
|
|
28
28
|
const root = packageRoot();
|
|
29
29
|
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
30
30
|
assert.deepEqual(manifest.pi.skills, ["./skills"]);
|
|
31
31
|
assert.deepEqual(manifest.pi.extensions, ["./plugins/pi/index.ts"]);
|
|
32
|
-
assert.equal(manifest.bin
|
|
32
|
+
assert.equal(manifest.bin, undefined, "the dream CLI is gone; dreams run through the dream_* tools");
|
|
33
33
|
assert.ok(manifest.files.includes("skills"));
|
|
34
34
|
discoverSkill(join(root, "skills"), "memory");
|
|
35
35
|
const skill = discoverSkill(join(root, "skills"), "dream");
|
|
@@ -53,7 +53,6 @@ test("npm tarball keeps the skill's relative playbook path portable after extrac
|
|
|
53
53
|
assert.ok(packedPaths.includes("skills/memory/SKILL.md"));
|
|
54
54
|
assert.ok(packedPaths.includes("playbook.md"));
|
|
55
55
|
assert.ok(packedPaths.includes("plugins/pi/index.ts"));
|
|
56
|
-
assert.ok(packedPaths.includes("dist/plugins/pi/dream/cli.js"));
|
|
57
56
|
const extracted = join(fixture, "extracted");
|
|
58
57
|
execFileSync("mkdir", ["-p", extracted]);
|
|
59
58
|
execFileSync("tar", ["-xzf", join(fixture, packed.filename), "-C", extracted]);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { createNotesStore } from "../src/notes/index.js";
|
|
8
|
+
import { dreamBegin, dreamEnd, dreamForget, dreamingIdentity } from "../src/tools/dream.js";
|
|
9
|
+
import { notesRead, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
10
|
+
function fixture(t) {
|
|
11
|
+
const home = mkdtempSync(join(tmpdir(), "dream-tools-"));
|
|
12
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
13
|
+
const mark = (name) => {
|
|
14
|
+
mkdirSync(join(home, "project", name), { recursive: true });
|
|
15
|
+
writeFileSync(join(home, "project", name, ".project"), JSON.stringify({ id: name, path: `/work/${name}` }));
|
|
16
|
+
};
|
|
17
|
+
mark("alpha");
|
|
18
|
+
mark("beta");
|
|
19
|
+
const as = (sessionId, projectKey) => ({ home, sessionId, projectKey, agent: "root", model: "m" });
|
|
20
|
+
return { home, as };
|
|
21
|
+
}
|
|
22
|
+
test("a dream opens one other project, writes its notes, deletes only crumpled ones, then closes", async (t) => {
|
|
23
|
+
const { home, as } = fixture(t);
|
|
24
|
+
// Seed: beta's project note and two beta sessions, plus one alpha session.
|
|
25
|
+
await createNotesStore(as("b1", "beta")).write("@project/rule", "keep");
|
|
26
|
+
await createNotesStore(as("b1", "beta")).write("checkpoint", "old");
|
|
27
|
+
await createNotesStore(as("b2", "beta")).write("trash", "x");
|
|
28
|
+
await createNotesStore(as("b2", "beta")).update("trash", undefined, { crumpled: true });
|
|
29
|
+
await createNotesStore(as("a1", "alpha")).write("mine", "alpha only");
|
|
30
|
+
const me = as("now", "alpha");
|
|
31
|
+
const state = {};
|
|
32
|
+
const ident = () => dreamingIdentity(me, state);
|
|
33
|
+
// Closed: named homes are read-only and forget refuses.
|
|
34
|
+
assert.equal((await notesWrite.execute({ address: "@projects/beta/rule", content: "x" }, ident())).ok, false);
|
|
35
|
+
assert.equal((await dreamForget.execute({ address: "@sessions/b2/trash" }, me, state)).ok, false);
|
|
36
|
+
const begun = await dreamBegin.execute({ project: "beta" }, me, state);
|
|
37
|
+
assert.ok(begun.ok);
|
|
38
|
+
assert.deepEqual(begun.data.files.map(f => f.address).sort(), ["@projects/beta/rule.md", "@sessions/b1/checkpoint.md", "@sessions/b2/trash.md"]);
|
|
39
|
+
assert.equal((await dreamBegin.execute({}, me, state)).ok, false, "only one dream at a time");
|
|
40
|
+
assert.ok(existsSync(join(home, ".dream.lock.beta")), "the project lock is held");
|
|
41
|
+
assert.equal((await dreamBegin.execute({ project: "beta" }, as("other", "alpha"), {})).ok, false, "another session can't dream the same project");
|
|
42
|
+
assert.ok((await notesWrite.execute({ address: "@projects/beta/rule", content: "merged" }, ident())).ok);
|
|
43
|
+
assert.ok((await notesUpdate.execute({ address: "@sessions/b1/checkpoint", edits: [{ oldText: "old", newText: "new" }] }, ident(), () => "")).ok);
|
|
44
|
+
assert.equal((await notesWrite.execute({ address: "@sessions/a1/mine", content: "x" }, ident())).ok, false, "another project's session stays read-only");
|
|
45
|
+
assert.equal((await notesWrite.execute({ address: "@projects/alpha/x", content: "x" }, ident())).ok, false, "other projects stay read-only");
|
|
46
|
+
const read = await notesRead.execute({ address: "@human/none" }, ident());
|
|
47
|
+
assert.equal(read.ok, false);
|
|
48
|
+
await createNotesStore(me).write("@human/pref", "p");
|
|
49
|
+
const before = (await createNotesStore(me).list({ glob: "@human/**" }))[0].meta.accessCount;
|
|
50
|
+
assert.ok((await notesRead.execute({ address: "@human/pref" }, ident())).ok);
|
|
51
|
+
assert.equal((await createNotesStore(me).list({ glob: "@human/**" }))[0].meta.accessCount, before, "dream reads leave no stamp");
|
|
52
|
+
assert.equal((await dreamForget.execute({ address: "@sessions/b1/checkpoint" }, me, state)).ok, false, "live notes refuse");
|
|
53
|
+
assert.ok((await dreamForget.execute({ address: "@sessions/b2/trash" }, me, state)).ok);
|
|
54
|
+
assert.equal(existsSync(join(home, "pi", "session", "b2", "trash.md")), false);
|
|
55
|
+
const ended = await dreamEnd.execute({}, me, state);
|
|
56
|
+
assert.ok(ended.ok && ended.data.commit && ended.data.commit !== begun.data.baseline, "dream_end commits the changes");
|
|
57
|
+
assert.equal(existsSync(join(home, ".dream.lock.beta")), false, "the lock is released");
|
|
58
|
+
assert.equal(execFileSync("git", ["status", "--porcelain"], { cwd: home, encoding: "utf8" }), "", "the audit leaves a clean tree");
|
|
59
|
+
assert.equal((await notesWrite.execute({ address: "@projects/beta/rule", content: "x" }, ident())).ok, false, "closed again");
|
|
60
|
+
assert.equal((await dreamEnd.execute({}, me, state)).ok, false);
|
|
61
|
+
});
|
|
62
|
+
test("dream_begin refuses an unknown project", async (t) => {
|
|
63
|
+
const { as } = fixture(t);
|
|
64
|
+
const state = {};
|
|
65
|
+
assert.equal((await dreamBegin.execute({ project: "nope" }, as("s", "alpha"), state)).ok, false);
|
|
66
|
+
assert.equal(state.project, undefined);
|
|
67
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { stripTerminalSequences } from "@earendil-works/pi-tui";
|
|
5
|
+
import { emptyBrainRenderers, notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../plugins/pi/render.js";
|
|
6
|
+
import { success, wireResult } from "../src/tools/result.js";
|
|
7
|
+
/** Flat theme for content assertions; strikethrough marks its text so crumple stays visible. */
|
|
8
|
+
const flatTheme = {
|
|
9
|
+
fg: (_color, text) => text,
|
|
10
|
+
bold: (text) => text,
|
|
11
|
+
italic: (text) => text,
|
|
12
|
+
strikethrough: (text) => `~~${text}~~`,
|
|
13
|
+
};
|
|
14
|
+
function toolResult(outcome) {
|
|
15
|
+
return { content: [{ type: "text", text: "receipt" }], structuredContent: wireResult(outcome), isError: !outcome.ok, details: undefined };
|
|
16
|
+
}
|
|
17
|
+
function jsonResult(value, isError = false) {
|
|
18
|
+
return { content: [{ type: "text", text: JSON.stringify(value) }], isError, details: undefined };
|
|
19
|
+
}
|
|
20
|
+
function lines(component, width = 80) {
|
|
21
|
+
return component.render(width).map((line) => stripTerminalSequences(line).trimEnd()).join("\n");
|
|
22
|
+
}
|
|
23
|
+
test("notes_write collapsed: outcome, address and content size", () => {
|
|
24
|
+
const result = toolResult(success({ address: "@self/grudge.md", outcome: "created" }));
|
|
25
|
+
const component = notesWriteRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "@self/grudge.md", content: "hello" } });
|
|
26
|
+
assert.equal(lines(component), "wrote @self/grudge.md · 5 chars");
|
|
27
|
+
});
|
|
28
|
+
test("notes_write expanded: the written content follows the header", () => {
|
|
29
|
+
const result = toolResult(success({ address: "plan.md", outcome: "overwrote" }));
|
|
30
|
+
const component = notesWriteRenderers.renderResult(result, { expanded: true }, flatTheme, { args: { address: "plan.md", content: "one\ntwo" } });
|
|
31
|
+
assert.equal(lines(component), "wrote plan.md · overwrote · 7 chars\n\none\ntwo");
|
|
32
|
+
});
|
|
33
|
+
test("notes_update edited: collapsed peeks at the first added line", () => {
|
|
34
|
+
const result = toolResult(success({ address: "a.md", change_kind: "body", diff: " 1 old\n-2 gone\n+2 here" }));
|
|
35
|
+
const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md" } });
|
|
36
|
+
assert.equal(lines(component), "edited a.md · + here");
|
|
37
|
+
});
|
|
38
|
+
test("notes_update crumple: the address is struck through", () => {
|
|
39
|
+
const result = toolResult(success({ address: "@self/stale.md", change_kind: "metadata", diff: "" }));
|
|
40
|
+
const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "@self/stale.md", crumpled: true } });
|
|
41
|
+
assert.equal(lines(component), "✂ crumpled ~~@self/stale.md~~");
|
|
42
|
+
});
|
|
43
|
+
test("notes_update moved: both addresses stay on the line", () => {
|
|
44
|
+
const result = toolResult(success({ address: "@self/new.md", change_kind: "moved", diff: "rename a.md -> @self/new.md", rename_from: "a.md" }));
|
|
45
|
+
const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md", rename_to: "@self/new.md" } });
|
|
46
|
+
assert.equal(lines(component), "renamed a.md → @self/new.md");
|
|
47
|
+
});
|
|
48
|
+
test("notes_update unchanged keeps quiet", () => {
|
|
49
|
+
const result = toolResult(success({ address: "a.md", change_kind: "none", diff: "" }));
|
|
50
|
+
const component = notesUpdateRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md" } });
|
|
51
|
+
assert.equal(lines(component), "unchanged a.md");
|
|
52
|
+
});
|
|
53
|
+
test("notes_read collapsed: size and a peek at the first line", () => {
|
|
54
|
+
const result = toolResult(success({ address: "@project/MAP.md", metadata: { origin: "self", created_at: "x", updated_at: "y", extra: {} }, text: "# MAP\n\nbody", total_chars: 11, next_offset_chars: null }));
|
|
55
|
+
const component = notesReadRenderers.renderResult(result, { expanded: false }, flatTheme);
|
|
56
|
+
assert.equal(lines(component), "read @project/MAP.md · 11 chars — # MAP");
|
|
57
|
+
});
|
|
58
|
+
test("notes_read expanded: truncation points at the next offset", () => {
|
|
59
|
+
const result = toolResult(success({ address: "a.md", metadata: { origin: "self", created_at: "x", updated_at: "y", extra: {} }, text: "part", total_chars: 10, next_offset_chars: 4 }));
|
|
60
|
+
const component = notesReadRenderers.renderResult(result, { expanded: true }, flatTheme);
|
|
61
|
+
assert.equal(lines(component), "read a.md · 10 chars · truncated — part\n\npart\n… continue at offset_chars=4");
|
|
62
|
+
});
|
|
63
|
+
test("refusals render as one error line with the code", () => {
|
|
64
|
+
const result = toolResult({ ok: false, error: { code: "not_found", message: "No note at x.md." } });
|
|
65
|
+
const component = notesReadRenderers.renderResult(result, { expanded: false }, flatTheme);
|
|
66
|
+
assert.equal(lines(component), "not_found: No note at x.md.");
|
|
67
|
+
});
|
|
68
|
+
test("results without a structured payload fall back to the receipt line", () => {
|
|
69
|
+
const result = { content: [{ type: "text", text: "created a.md" }], isError: false, details: undefined };
|
|
70
|
+
const component = notesWriteRenderers.renderResult(result, { expanded: false }, flatTheme, { args: { address: "a.md", content: "x" } });
|
|
71
|
+
assert.equal(lines(component), "created a.md");
|
|
72
|
+
});
|
|
73
|
+
test("empty_brain: divider with the last word, refusals in one line", () => {
|
|
74
|
+
initTheme();
|
|
75
|
+
const ok = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_requested" }), { expanded: false }, flatTheme, { args: { last_word: "cake was worth it" } });
|
|
76
|
+
const rendered = lines(ok, 40).split("\n");
|
|
77
|
+
assert.match(rendered[0] ?? "", /^── ✂ brain emptied ─+$/);
|
|
78
|
+
assert.equal(rendered[1], "“cake was worth it”");
|
|
79
|
+
const refused = emptyBrainRenderers.renderResult(jsonResult({ error: "notesoup is off" }, true), { expanded: false }, flatTheme, { args: {} });
|
|
80
|
+
assert.equal(lines(refused), "✂ brain refused to empty — notesoup is off");
|
|
81
|
+
const pending = emptyBrainRenderers.renderResult(jsonResult({ status: "rollover_already_pending" }), { expanded: false }, flatTheme, { args: {} });
|
|
82
|
+
assert.equal(lines(pending), "✂ brain already being emptied");
|
|
83
|
+
});
|
|
84
|
+
test("notes_update expanded diff goes through the host's diff renderer", () => {
|
|
85
|
+
initTheme();
|
|
86
|
+
const result = toolResult(success({ address: "a.md", change_kind: "body", diff: " 1 old\n-2 gone\n+2 here" }));
|
|
87
|
+
const component = notesUpdateRenderers.renderResult(result, { expanded: true }, flatTheme, { args: { address: "a.md" } });
|
|
88
|
+
assert.equal(lines(component), "edited a.md · + here\n\n 1 old\n-2 gone\n+2 here");
|
|
89
|
+
});
|
package/docs/claude-code-mod.md
CHANGED
|
@@ -22,7 +22,7 @@ The notes tools also serve subagent calls, using the same session identity and s
|
|
|
22
22
|
|
|
23
23
|
The active head comes from the main loop's successful `session.append` result UUID, including attachments and notices. On startup/resume, before such an append, the public API supplies no authoritative selected leaf: history explicitly refuses instead of assuming the last file row or `last-prompt.leafUuid` is current. The append result means the engine kept a row, but its disk write may lag; a head missing on disk is a retryable refusal, not permission to switch branches. Session end clears the binding; a new classic start rebinds it.
|
|
24
24
|
|
|
25
|
-
Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed.
|
|
25
|
+
Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed. Record types other than user, assistant, system and attachment are ignored, including future metadata, without allocating addresses or exposing payloads. If the selected branch requires a skipped record as an ancestor, history refuses with the missing ancestor UUID. Invalid supported message/block schemas and malformed committed JSONL lines still refuse explicitly. An incomplete final unterminated write is tolerated. Valid forward parent references are resolved after reading the snapshot, without reallocating addresses.
|
|
26
26
|
|
|
27
27
|
The selected tree follows the latest native `parentUuid` links. Compact boundaries also join their `logicalParentUuid` and recorded preserved segments through original ancestry, retaining old events instead of presenting only retained inference context. Auxiliary preservation UUIDs that were never persisted are skipped. Windows use `claude:<sessionId>:<ordinal>`, matching the boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window. `@previous` resolves through this oldest-first window list. A missing required ancestor is an explicit refusal.
|
|
28
28
|
|
package/docs/notes-library.md
CHANGED
|
@@ -26,7 +26,7 @@ const files = await notes.list({ glob: "@project/**" });
|
|
|
26
26
|
const matches = await notes.search(["library"]);
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
`/notes` ships JavaScript and TypeScript declarations. It does not import Pi or read `PI_*` environment variables. Pi packages are optional peers: a notes-only installation does not install them. Using the Pi plugin
|
|
29
|
+
`/notes` ships JavaScript and TypeScript declarations. It does not import Pi or read `PI_*` environment variables. Pi packages are optional peers: a notes-only installation does not install them. Using the Pi plugin or the dsh rows (`notesoup/dsh`) still requires its host. This is a filesystem library for Node, not a browser storage API.
|
|
30
30
|
|
|
31
31
|
## API and identity
|
|
32
32
|
|
package/docs/skills.md
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
# Skills
|
|
1
|
+
# Skills and dream
|
|
2
2
|
|
|
3
3
|
## Memory skill
|
|
4
4
|
|
|
5
5
|
The package provides `/skill:memory`, a short self-contained guide to the notes and history tools: note addresses and homes, finding and paging notes, searching and paging history, saving recovery state, and what to do when a memory tool is unavailable. It is a fallback for sessions where the boot protocol is missing or unclear and a reference on demand; normal tool calls do not require reading it. It is written independently of the boot text rather than generated from it. The Claude Code Mod ships the same guide; its history tools require the documented main-session transcript path and a confirmed append head.
|
|
6
6
|
|
|
7
|
-
## Dream
|
|
7
|
+
## Dream
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
`/skill:dream` reviews notes in the current agent session, following the shared `playbook.md`.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
In Pi the session gets three hidden `dream_*` tools; they are not declared to the model and are found with `tool_search` or codemode's `searchTools("dream")`:
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
- `dream_begin(project?)` opens one project, by default the current one, as in `@projects/<name>/`. It lists that project's notes and every session note whose frontmatter `project` names it, crumpled notes included. While it is open, `notes_write` and `notes_update` may edit those addresses (existing notes only in other sessions), and reads leave no access stamp. Other projects stay read-only.
|
|
14
|
+
- `dream_forget(address)` permanently deletes one crumpled note within reach; live notes refuse.
|
|
15
|
+
- `dream_end()` closes the dream.
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
One session dreams over one project at a time. New session notes record their project key in `project`; notes without it never appear in a project's dream. Standard linked Git worktrees share the main checkout's project key.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
## The dream lock and Git audit
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
`dream_begin` takes an exclusive `.dream.lock.<project>` in the notes home with a single O_CREAT|O_EXCL creation, then commits a baseline of the notes home to its Git repository (initialized on first use). `dream_end` commits the dream's changes and releases the lock, so `git show` reviews a dream and `git revert` rolls it back. A session shutdown releases the lock without the final commit.
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
If a dream process crashed, its lock remains and later runs refuse to start. There is no automatic recovery and no force-unlock command: after you have confirmed that no dream process is running, remove the stale lock by hand.
|
|
23
|
+
An existing lock refuses a new dream regardless of its age. If a Pi process crashed mid-dream, remove the stale lock by hand after confirming no dream is running:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
|
|
27
|
-
rm "${NOTESOUP_HOME:-$HOME/.agents/notes}/.dream.lock"
|
|
26
|
+
rm "${NOTESOUP_HOME:-$HOME/.agents/notes}/.dream.lock.<project>"
|
|
28
27
|
```
|
|
29
|
-
|
|
30
|
-
Removing a lock while a holder is running is outside the supported cooperative protocol and can let two dreams run at once.
|