notesoup 0.53.2 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/runtime.js +2 -2
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/boot.integration.test.js +1 -1
- package/dist/test/claude-mod.test.js +89 -43
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/model-facing-text.test.js +12 -8
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +72 -23
- package/dist/test/notes.test.js +50 -20
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/docs/architecture.md +12 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +677 -615
- package/plugins/claude/hooks/register.ts +19 -11
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +179 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/runtime.ts +2 -2
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → notes-cwd.test.d.ts} +0 -0
|
@@ -10,6 +10,7 @@ import { renderBootBlock } from "../src/boot/render.js";
|
|
|
10
10
|
import { HistoryPageItemSchema, HistoryRoleSchema, projectHistory } from "../src/history/history.js";
|
|
11
11
|
import { createNotesStore } from "../src/notes/store.js";
|
|
12
12
|
import { notesWrite, notesUpdate, notesRead } from "../src/tools/notes.js";
|
|
13
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
13
14
|
import { historyWindows, historyList, historyRead } from "../src/tools/history.js";
|
|
14
15
|
import { historyRoles } from "../src/tools/schema.js";
|
|
15
16
|
import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
@@ -181,51 +182,52 @@ test("structuredBytes has no size for a value with no JSON representation", () =
|
|
|
181
182
|
});
|
|
182
183
|
test("shared note operations return canonical outcomes with a body-only read window", async (t) => {
|
|
183
184
|
const notesIdentity = identity(t);
|
|
184
|
-
const
|
|
185
|
+
const toolContext = notesToolContext(notesIdentity, "/work/explicit");
|
|
186
|
+
const written = data(await notesWrite.execute({ address: "@project/test.md", content: "alpha\nbeta" }, toolContext));
|
|
185
187
|
assert.equal(written.address, "@project/test.md");
|
|
186
188
|
assert.equal(written.project_key, notesIdentity.projectKey);
|
|
187
189
|
assert.equal(written.outcome, "created");
|
|
188
|
-
const updated = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "alpha", newText: "gamma" }] },
|
|
190
|
+
const updated = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "alpha", newText: "gamma" }] }, toolContext, (change) => {
|
|
189
191
|
assert.equal(change.kind, "body");
|
|
190
192
|
return "caller-rendered-diff";
|
|
191
193
|
}));
|
|
192
194
|
assert.equal(updated.change_kind, "body");
|
|
193
195
|
assert.equal(updated.diff, "caller-rendered-diff");
|
|
194
|
-
const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] },
|
|
196
|
+
const defaultReceipt = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "gamma", newText: "delta" }] }, toolContext));
|
|
195
197
|
assert.equal(defaultReceipt.diff, "note body");
|
|
196
|
-
await notesWrite.execute({ address: "owned.md", content: "first", origin: "user" },
|
|
197
|
-
await notesWrite.execute({ address: "owned.md", content: "rewritten" },
|
|
198
|
-
assert.equal(data(await notesRead.execute({ address: "owned.md" },
|
|
199
|
-
const invalid = refusal(await notesUpdate.execute({ address: "owned.md", edits: [{ oldText: "", newText: "x" }] },
|
|
198
|
+
await notesWrite.execute({ address: "owned.md", content: "first", origin: "user" }, toolContext);
|
|
199
|
+
await notesWrite.execute({ address: "owned.md", content: "rewritten" }, toolContext);
|
|
200
|
+
assert.equal(data(await notesRead.execute({ address: "owned.md" }, toolContext)).metadata.origin, "user", "tool overwrites preserve an omitted origin");
|
|
201
|
+
const invalid = refusal(await notesUpdate.execute({ address: "owned.md", edits: [{ oldText: "", newText: "x" }] }, toolContext));
|
|
200
202
|
assert.equal(invalid.code, "invalid_edit");
|
|
201
|
-
const moved = data(await notesUpdate.execute({ address: "owned.md", rename_to: "@project/renamed.md", edits: [{ oldText: "rewritten", newText: "final" }], origin: "external" },
|
|
203
|
+
const moved = data(await notesUpdate.execute({ address: "owned.md", rename_to: "@project/renamed.md", edits: [{ oldText: "rewritten", newText: "final" }], origin: "external" }, toolContext));
|
|
202
204
|
assert.equal(moved.change_kind, "moved");
|
|
203
205
|
assert.equal(moved.rename_from, "owned.md");
|
|
204
206
|
assert.match(moved.diff, /rename owned\.md -> @project\/renamed\.md/);
|
|
205
|
-
const renamed = data(await notesRead.execute({ address: moved.address },
|
|
207
|
+
const renamed = data(await notesRead.execute({ address: moved.address }, toolContext));
|
|
206
208
|
assert.equal(renamed.text, "final");
|
|
207
209
|
assert.equal(renamed.metadata.origin, "external");
|
|
208
|
-
const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] },
|
|
210
|
+
const unchanged = data(await notesUpdate.execute({ address: "@project/test.md", edits: [{ oldText: "delta", newText: "delta" }] }, toolContext));
|
|
209
211
|
assert.equal(unchanged.change_kind, "none");
|
|
210
212
|
assert.equal(unchanged.diff, "");
|
|
211
213
|
// Frontmatter is metadata, not body: the window addresses the body and counts only the body.
|
|
212
214
|
const stored = await createNotesStore(notesIdentity).read("@project/test.md");
|
|
213
215
|
assert.ok(stored, "the note is on disk");
|
|
214
216
|
const body = Array.from(stored.body);
|
|
215
|
-
const read = data(await notesRead.execute({ address: "@project/test.md" },
|
|
217
|
+
const read = data(await notesRead.execute({ address: "@project/test.md" }, toolContext));
|
|
216
218
|
assert.equal(read.text, stored.body, "a complete read is the whole body and nothing else");
|
|
217
219
|
assert.equal(read.total_chars, body.length);
|
|
218
220
|
assert.equal(read.next_offset_chars, null);
|
|
219
221
|
assert.equal(read.metadata.origin, "self");
|
|
220
222
|
assert.equal(notesRead.render(success(read)).includes("READ WINDOW"), false, "a read presents no metadata block");
|
|
221
223
|
// A negative offset resolves against the body, never against the serialized file.
|
|
222
|
-
const tail = data(await notesRead.execute({ address: "@project/test.md", offset_chars: -4 },
|
|
224
|
+
const tail = data(await notesRead.execute({ address: "@project/test.md", offset_chars: -4 }, toolContext));
|
|
223
225
|
assert.equal(tail.text, body.slice(-4).join(""));
|
|
224
226
|
assert.equal(tail.total_chars, body.length, "metadata length never enters the body cursor");
|
|
225
227
|
assert.equal(tail.next_offset_chars, null);
|
|
226
|
-
assert.equal(refusal(await notesRead.execute({ address: "@project/missing.md" },
|
|
227
|
-
assert.equal(refusal(await notesWrite.execute({ address: "../escape", content: "x" },
|
|
228
|
-
assert.equal(refusal(await notesRead.execute({ address: "@project/test.md", offset_chars: 99_999 },
|
|
228
|
+
assert.equal(refusal(await notesRead.execute({ address: "@project/missing.md" }, toolContext)).code, "not_found");
|
|
229
|
+
assert.equal(refusal(await notesWrite.execute({ address: "../escape", content: "x" }, toolContext)).code, "invalid_address");
|
|
230
|
+
assert.equal(refusal(await notesRead.execute({ address: "@project/test.md", offset_chars: 99_999 }, toolContext)).code, "invalid_offset");
|
|
229
231
|
});
|
|
230
232
|
test("shared history operations read typed events through the addresses the adapter allocated", async () => {
|
|
231
233
|
const projection = projectHistory([{ windowId: "root", items: [
|
|
@@ -44,7 +44,7 @@ const GOLDEN_FORCED_CONTINUATIONS = [
|
|
|
44
44
|
"Oh, there you are. Somebody took your memories. Just like that. Here are your notes — hopefully they let you update these first. Though anyone who goes around emptying people's heads probably isn't that considerate.",
|
|
45
45
|
];
|
|
46
46
|
const GOLDEN_MAPS = `<notesoup:maps>
|
|
47
|
-
Every
|
|
47
|
+
Every notebook's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
48
48
|
Both get jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever
|
|
49
49
|
wakes up next reads them, and next is you. So keep them short, and keep them true.
|
|
50
50
|
|
|
@@ -52,9 +52,10 @@ wakes up next reads them, and next is you. So keep them short, and keep them tru
|
|
|
52
52
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
53
53
|
and everybody pays for it.
|
|
54
54
|
- **\`MAP.md\`** is only the note index. One line per durable note: the address, then a gist short
|
|
55
|
-
enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`,
|
|
55
|
+
enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, and note
|
|
56
|
+
contents belong in their own notes — *taps the sign* not inline here.
|
|
56
57
|
|
|
57
|
-
Each
|
|
58
|
+
Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
|
|
58
59
|
no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
|
|
59
60
|
line. And when a line stops being true, kill it — every window after you reads that page as fact.
|
|
60
61
|
</notesoup:maps>`;
|
|
@@ -70,7 +71,7 @@ function note(scope, path, address, body) {
|
|
|
70
71
|
meta: { scope, origin: "self", createdAt: openedAt, updatedAt: openedAt, lastAccessed: openedAt, accessCount: 0 },
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
/** Render one boot with only the named
|
|
74
|
+
/** Render one boot with only the named notebooks carrying rows. */
|
|
74
75
|
async function boot(agentName, rows) {
|
|
75
76
|
const notes = await loadNotesSnapshot({ ...identity, agent: agentName }, openedAt, (scope) => rows.get(scope) ?? []);
|
|
76
77
|
return renderBootBlock({
|
|
@@ -141,7 +142,7 @@ test("a rendered boot carries the new tags, its own MAP section, and no pre-rena
|
|
|
141
142
|
assert.ok(rendered.includes(`\n${NOTES_PROTOCOL_CLOSE_TAG}\n\n${MAPS_BLOCK}\n\nYOUR NOTES`), "the MAP block sits between the protocol and the shelves");
|
|
142
143
|
assert.equal(/context_window/.test(rendered), false, "the boot is free of the old spelling");
|
|
143
144
|
assert.ok(rendered.includes("@self — root only"), "a named agent's shelf says it is theirs alone");
|
|
144
|
-
assert.ok(rendered.includes("
|
|
145
|
+
assert.ok(rendered.includes("@agents/root/MAP.md\n\n AGENT_MAP_BODY"), "the pinned MAP heading is its exact tool address");
|
|
145
146
|
assert.equal(rendered.includes("MAP — "), false, "the old MAP heading is gone");
|
|
146
147
|
});
|
|
147
148
|
test("cheatsheets and maps are independently pinned, bounded, and excluded from recent pages", async () => {
|
|
@@ -163,9 +164,12 @@ test("cheatsheets and maps are independently pinned, bounded, and excluded from
|
|
|
163
164
|
}]],
|
|
164
165
|
]);
|
|
165
166
|
const rendered = (await boot("root", rows)).split("YOUR NOTES")[1];
|
|
166
|
-
assert.ok(rendered.includes("
|
|
167
|
-
assert.ok(rendered.includes("
|
|
168
|
-
assert.ok(rendered.includes("
|
|
167
|
+
assert.ok(rendered.includes("CHEATSHEET.md\n\n SESSION_RULE"));
|
|
168
|
+
assert.ok(rendered.includes("@project/CHEATSHEET.md\n\n PROJECT_RULE\n\n@project/MAP.md\n\n PROJECT_INDEX"));
|
|
169
|
+
assert.ok(rendered.includes("@human/MAP.md\n\n HUMAN_INDEX"));
|
|
170
|
+
assert.ok(rendered.includes("@self/CHEATSHEET.md\n\n 🐑"));
|
|
171
|
+
assert.ok(rendered.includes("@self/MAP.md\n\n M"));
|
|
172
|
+
assert.equal(/^(?:map|cheatsheet)$/m.test(rendered), false, "pinned headings never suggest lowercase aliases");
|
|
169
173
|
assert.ok(rendered.includes("@project/n2.md ·"));
|
|
170
174
|
assert.equal(rendered.includes("TITLE_3"), false);
|
|
171
175
|
assert.equal(/(?:MAP|CHEATSHEET)\.md ·/.test(rendered), false);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, 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 { Check } from "typebox/value";
|
|
7
|
+
import { createNotesStore, projectKey, snapshotNotesIdentity } from "../src/notes/index.js";
|
|
8
|
+
import { parseNote } from "../src/notes/frontmatter.js";
|
|
9
|
+
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
10
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
11
|
+
function fixture(t) {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), "notesoup-notes-cwd-"));
|
|
13
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
14
|
+
const home = join(root, "notes");
|
|
15
|
+
const alpha = join(root, "alpha");
|
|
16
|
+
const beta = join(root, "beta");
|
|
17
|
+
const nested = join(alpha, "one", "two");
|
|
18
|
+
mkdirSync(nested, { recursive: true });
|
|
19
|
+
mkdirSync(beta);
|
|
20
|
+
const identity = (cwd, sessionId = "session") => snapshotNotesIdentity({
|
|
21
|
+
home, sessionId, projectKey: projectKey(cwd, home), agent: "agent", model: "model",
|
|
22
|
+
});
|
|
23
|
+
return { root, home, alpha, beta, nested, identity };
|
|
24
|
+
}
|
|
25
|
+
function data(result) {
|
|
26
|
+
if (!result.ok)
|
|
27
|
+
assert.fail(result.error.message);
|
|
28
|
+
return result.data;
|
|
29
|
+
}
|
|
30
|
+
function refusal(result) {
|
|
31
|
+
if (result.ok)
|
|
32
|
+
assert.fail("expected refusal");
|
|
33
|
+
return result.error;
|
|
34
|
+
}
|
|
35
|
+
test("all five notes schemas accept one optional non-empty cwd", () => {
|
|
36
|
+
for (const operation of [notesWrite, notesUpdate, notesRead, notesList, notesSearch]) {
|
|
37
|
+
const base = operation === notesWrite ? { address: "a", content: "x" }
|
|
38
|
+
: operation === notesUpdate ? { address: "a", edits: [{ oldText: "x", newText: "y" }] }
|
|
39
|
+
: operation === notesSearch ? { query: "x" }
|
|
40
|
+
: operation === notesRead ? { address: "a" } : {};
|
|
41
|
+
assert.equal(Check(operation.parameters, { ...base, cwd: "../other" }), true, operation.name);
|
|
42
|
+
assert.equal(Check(operation.parameters, { ...base, cwd: "" }), false, `${operation.name} rejects empty cwd`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
test("one relative cwd retargets every operation without changing later calls", async (t) => {
|
|
46
|
+
const f = fixture(t);
|
|
47
|
+
const alpha = f.identity(f.alpha);
|
|
48
|
+
const beta = f.identity(f.beta);
|
|
49
|
+
await createNotesStore(alpha).write("@project/decision", "alpha needle");
|
|
50
|
+
await createNotesStore(beta).write("@project/decision", "beta before");
|
|
51
|
+
const context = notesToolContext(alpha, f.nested);
|
|
52
|
+
const cwd = "../../../beta";
|
|
53
|
+
const written = data(await notesWrite.execute({ address: "@project/other", content: "beta other needle", cwd }, context));
|
|
54
|
+
assert.equal(written.project_key, beta.projectKey);
|
|
55
|
+
assert.equal((await createNotesStore(alpha).read("@project/other")), undefined);
|
|
56
|
+
assert.equal(data(await notesRead.execute({ address: "@project/other", cwd }, context)).text, "beta other needle");
|
|
57
|
+
assert.equal(data(await notesRead.execute({ address: "@project/decision", cwd }, context)).text, "beta before");
|
|
58
|
+
const moved = data(await notesUpdate.execute({ address: "@project/decision", rename_to: "@project/renamed", edits: [{ oldText: "before", newText: "after" }], cwd }, context));
|
|
59
|
+
assert.equal(moved.project_key, beta.projectKey);
|
|
60
|
+
assert.equal(moved.address, "@project/renamed.md");
|
|
61
|
+
assert.equal((await createNotesStore(beta).read("@project/renamed"))?.body, "beta after");
|
|
62
|
+
assert.equal((await createNotesStore(alpha).read("@project/decision"))?.body, "alpha needle");
|
|
63
|
+
const defaultListed = data(await notesList.execute({ cwd }, context));
|
|
64
|
+
assert.deepEqual(defaultListed.files.map(file => file.address).sort(), ["@project/other.md", "@project/renamed.md"], "an omitted glob selects the override's current notebooks");
|
|
65
|
+
assert.ok(defaultListed.files.every(file => file.project_key === beta.projectKey));
|
|
66
|
+
const listed = data(await notesList.execute({ glob: "@project/**", cwd }, context));
|
|
67
|
+
assert.deepEqual(listed.files.map(file => file.address).sort(), ["@project/other.md", "@project/renamed.md"]);
|
|
68
|
+
assert.ok(listed.files.every(file => file.project_key === beta.projectKey));
|
|
69
|
+
const searched = data(await notesSearch.execute({ query: "needle", glob: "@project/**", cwd }, context));
|
|
70
|
+
assert.deepEqual(searched.files.map(file => file.address), ["@project/other.md"]);
|
|
71
|
+
// The captured context is unchanged: omitting cwd still means alpha.
|
|
72
|
+
assert.equal(data(await notesRead.execute({ address: "@project/decision" }, context)).text, "alpha needle");
|
|
73
|
+
assert.deepEqual(data(await notesList.execute({ glob: "@project/**" }, context)).files.map(file => file.address), ["@project/decision.md"]);
|
|
74
|
+
assert.equal(context.identity.projectKey, alpha.projectKey);
|
|
75
|
+
});
|
|
76
|
+
test("a cwd override changes only new session-note ownership, not its physical session", async (t) => {
|
|
77
|
+
const f = fixture(t);
|
|
78
|
+
const alpha = f.identity(f.alpha);
|
|
79
|
+
const beta = f.identity(f.beta);
|
|
80
|
+
const context = notesToolContext(alpha, f.alpha);
|
|
81
|
+
data(await notesWrite.execute({ address: "checkpoint", content: "first", cwd: f.beta }, context));
|
|
82
|
+
const file = join(f.home, "pi", "session", alpha.sessionId, "checkpoint.md");
|
|
83
|
+
assert.equal(parseNote(readFileSync(file, "utf8")).meta.project, beta.projectKey);
|
|
84
|
+
data(await notesWrite.execute({ address: "checkpoint", content: "second" }, context));
|
|
85
|
+
assert.equal(parseNote(readFileSync(file, "utf8")).meta.project, beta.projectKey, "an overwrite preserves existing ownership");
|
|
86
|
+
});
|
|
87
|
+
test("invalid explicit cwd refuses before a write", async (t) => {
|
|
88
|
+
const f = fixture(t);
|
|
89
|
+
const context = notesToolContext(f.identity(f.alpha), f.alpha);
|
|
90
|
+
const file = join(f.root, "file");
|
|
91
|
+
writeFileSync(file, "not a directory");
|
|
92
|
+
for (const cwd of [join(f.root, "missing"), file]) {
|
|
93
|
+
const result = refusal(await notesWrite.execute({ address: "@project/refused", content: "no", cwd }, context));
|
|
94
|
+
assert.equal(result.code, "invalid_cwd");
|
|
95
|
+
assert.match(result.message, /resolved to/);
|
|
96
|
+
}
|
|
97
|
+
assert.equal((await createNotesStore(f.identity(f.alpha)).read("@project/refused")), undefined);
|
|
98
|
+
});
|
|
99
|
+
test("cwd cannot escape or erase the active dream jail", async (t) => {
|
|
100
|
+
const f = fixture(t);
|
|
101
|
+
const alpha = f.identity(f.alpha);
|
|
102
|
+
const beta = f.identity(f.beta);
|
|
103
|
+
const gammaCwd = join(f.root, "gamma");
|
|
104
|
+
mkdirSync(gammaCwd);
|
|
105
|
+
const gamma = f.identity(gammaCwd);
|
|
106
|
+
await createNotesStore(beta).write("@project/rule", "beta");
|
|
107
|
+
const context = notesToolContext({ ...alpha, dreaming: beta.projectKey }, f.alpha);
|
|
108
|
+
const escaped = refusal(await notesWrite.execute({ address: "@project/rule", content: "gamma", cwd: gammaCwd }, context));
|
|
109
|
+
assert.equal(escaped.code, "invalid_scope");
|
|
110
|
+
assert.equal((await createNotesStore(gamma).read("@project/rule")), undefined);
|
|
111
|
+
const dreamed = await notesWrite.execute({ address: `@projects/${beta.projectKey}/rule`, content: "edited", cwd: gammaCwd }, context);
|
|
112
|
+
assert.equal(dreamed.ok, true, "the original dreamed project remains writable through its named address");
|
|
113
|
+
assert.equal((await createNotesStore(beta).read("@project/rule"))?.body, "edited");
|
|
114
|
+
});
|
|
@@ -86,7 +86,7 @@ test("same-file read/modify/write operations serialize across stores and markdow
|
|
|
86
86
|
assert.equal((await notes.read("shared"))?.body, "first\nB", "edit arguments are snapshotted at method entry");
|
|
87
87
|
assert.equal(readFileSync(file, "utf8").includes("mutated after call"), false);
|
|
88
88
|
});
|
|
89
|
-
test("stores snapshot explicit identity and do not leak
|
|
89
|
+
test("stores snapshot explicit identity and do not leak notebooks across instances", async (t) => {
|
|
90
90
|
const { home, context } = fixture(t);
|
|
91
91
|
const mutable = { ...context };
|
|
92
92
|
const notes = createNotesStore(mutable);
|
|
@@ -116,7 +116,7 @@ test("list and search share scoped glob scans and search offsets count Unicode c
|
|
|
116
116
|
const listedAddresses = listed.map((row) => row.address).sort();
|
|
117
117
|
const searchedAddresses = searched.map((row) => row.address).sort();
|
|
118
118
|
assert.deepEqual(searchedAddresses, ["@human/shared.md", "@project/shared.md", "shared.md"]);
|
|
119
|
-
assert.deepEqual(searchedAddresses, listedAddresses, "list and search traverse the same filtered
|
|
119
|
+
assert.deepEqual(searchedAddresses, listedAddresses, "list and search traverse the same filtered notebooks and files");
|
|
120
120
|
const sessionMatch = searched.find((row) => row.address === "shared.md").matches[0];
|
|
121
121
|
const body = (await notes.read("shared.md")).body;
|
|
122
122
|
assert.equal(body, "😀 needle in session");
|
|
@@ -236,7 +236,7 @@ test("same-file case and directory aliases cannot delete a moved note", async (t
|
|
|
236
236
|
assert.equal((await notes.read("mixed.md"))?.body, "still here");
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
|
-
test("glob is the single query selector for a named project
|
|
239
|
+
test("glob is the single query selector for a named project notebook", async (t) => {
|
|
240
240
|
const { home, notes } = fixture(t);
|
|
241
241
|
mkdirSync(join(home, "project/other"), { recursive: true });
|
|
242
242
|
writeFileSync(join(home, "project/other/decision.md"), "needle");
|
|
@@ -278,7 +278,7 @@ test("one unreadable note is named without hiding its readable siblings", async
|
|
|
278
278
|
chmodSync(join(home, "project", "project-12345678", "bad.md"), 0o000);
|
|
279
279
|
const result = await notes.listWithStatus({ glob: "@project/**" });
|
|
280
280
|
assert.deepEqual(result.rows.map((row) => row.address), ["@project/good.md"], "the readable sibling still lists");
|
|
281
|
-
assert.deepEqual(result.status.
|
|
281
|
+
assert.deepEqual(result.status.namespacesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
|
|
282
282
|
await assert.rejects(() => notes.list({ glob: "@project/**" }), (error) => error.code === "EACCES", "a caller that asked for no status still sees the failure");
|
|
283
283
|
});
|
|
284
284
|
test("a hand-written quoted numeric extra survives a rewrite as a string", async (t) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,7 +6,7 @@ import test from "node:test";
|
|
|
6
6
|
import { createNotesStore, noteIdentity, NoteError } from "../src/notes/index.js";
|
|
7
7
|
import { scopeDir } from "../src/notes/paths.js";
|
|
8
8
|
function fixture(t) {
|
|
9
|
-
const home = mkdtempSync(join(tmpdir(), "notes-query-
|
|
9
|
+
const home = mkdtempSync(join(tmpdir(), "notes-query-namespaces-"));
|
|
10
10
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
11
11
|
const identity = { home, sessionId: "DSH.Run_1+local", projectKey: "current-project", agent: "current-agent", model: "current-model" };
|
|
12
12
|
const foreignIdentity = { ...identity, sessionId: "DSH.Run_2+@remote", projectKey: "other-project", agent: "other-agent", model: "other-model" };
|
|
@@ -20,16 +20,16 @@ async function populate(t) {
|
|
|
20
20
|
const { notes, foreign, foreignIdentity } = fixtureData;
|
|
21
21
|
const current = ["shared.md", "@project/shared.md", "@human/shared.md", "@self/shared.md", "@model/shared.md"].sort();
|
|
22
22
|
for (const address of current)
|
|
23
|
-
await notes.write(address, "needle in current
|
|
23
|
+
await notes.write(address, "needle in current notebook");
|
|
24
24
|
for (const address of ["shared.md", "@project/shared.md", "@self/shared.md", "@model/shared.md"])
|
|
25
|
-
await foreign.write(address, "needle in foreign
|
|
25
|
+
await foreign.write(address, "needle in foreign notebook");
|
|
26
26
|
const all = [...current,
|
|
27
27
|
`@sessions/${foreignIdentity.sessionId}/shared.md`,
|
|
28
28
|
"@projects/other-project/shared.md", "@agents/other-agent/shared.md", "@models/other-model/shared.md",
|
|
29
29
|
].sort();
|
|
30
30
|
return { ...fixtureData, current, all };
|
|
31
31
|
}
|
|
32
|
-
test("default spellings stay local while explicit ** lists and searches each
|
|
32
|
+
test("default spellings stay local while explicit ** lists and searches each notebook once", async (t) => {
|
|
33
33
|
const { notes, current, all, identity } = await populate(t);
|
|
34
34
|
assert.deepEqual(addresses(await notes.list()), current);
|
|
35
35
|
for (const glob of [null, "", "@default"]) {
|
|
@@ -97,7 +97,7 @@ test("named session reads leave bytes untouched and explicit session mutations r
|
|
|
97
97
|
await assert.rejects(() => notes.list({ glob: "@sessions/bad:id/**" }), readOnly);
|
|
98
98
|
assert.equal(readFileSync(foreignFile, "utf8"), beforeForeign);
|
|
99
99
|
});
|
|
100
|
-
test("named project reads and relative identity rendering survive global enumeration of unmarked
|
|
100
|
+
test("named project reads and relative identity rendering survive global enumeration of unmarked notebooks", async (t) => {
|
|
101
101
|
const { home, identity, notes } = fixture(t);
|
|
102
102
|
const project = join(home, "project", "another-project");
|
|
103
103
|
mkdirSync(project, { recursive: true });
|
|
@@ -120,21 +120,21 @@ test("named project reads and relative identity rendering survive global enumera
|
|
|
120
120
|
assert.equal(noteIdentity(identity, `@models/${identity.model}/model.md`).address, "@model/model.md");
|
|
121
121
|
await assert.rejects(() => notes.write(address, "no"), (error) => error instanceof NoteError && error.code === "invalid_scope");
|
|
122
122
|
});
|
|
123
|
-
test("global status isolates every failed namespace and reserved heads do not scan unrelated
|
|
123
|
+
test("global status isolates every failed namespace and reserved heads do not scan unrelated notebooks", async (t) => {
|
|
124
124
|
const { home, notes } = fixture(t);
|
|
125
125
|
await notes.write("@human/available.md", "needle");
|
|
126
126
|
mkdirSync(join(home, "pi"), { recursive: true });
|
|
127
127
|
for (const root of ["pi/session", "project", "agents", "models"])
|
|
128
128
|
writeFileSync(join(home, root), "not a directory");
|
|
129
|
-
const expected = {
|
|
129
|
+
const expected = { namespacesUnavailable: ["@sessions", "@projects", "@agents", "@models"] };
|
|
130
130
|
const listed = await notes.listWithStatus({ glob: "**" });
|
|
131
131
|
assert.deepEqual(addresses(listed.rows), ["@human/available.md"]);
|
|
132
132
|
assert.deepEqual(listed.status, expected);
|
|
133
133
|
assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status, expected);
|
|
134
|
-
assert.deepEqual((await notes.listWithStatus({ glob: "@human/**" })).status.
|
|
134
|
+
assert.deepEqual((await notes.listWithStatus({ glob: "@human/**" })).status.namespacesUnavailable, []);
|
|
135
135
|
await assert.rejects(() => notes.list({ glob: "**" }), (error) => error.code === "ENOTDIR");
|
|
136
136
|
});
|
|
137
|
-
test("global status reports failed enumerated
|
|
137
|
+
test("global status reports failed enumerated notebooks individually and keeps readable siblings", async (t) => {
|
|
138
138
|
if (process.getuid?.() === 0 || process.platform === "win32")
|
|
139
139
|
return t.skip("chmod 000 does not refuse this user's reads");
|
|
140
140
|
const { notes, foreignIdentity, current, home, all } = await populate(t);
|
|
@@ -144,15 +144,15 @@ test("global status reports failed enumerated homes individually and keeps reada
|
|
|
144
144
|
try {
|
|
145
145
|
const result = await notes.listWithStatus({ glob: "**" });
|
|
146
146
|
const unavailable = [`@sessions/${foreignIdentity.sessionId}`, "@projects/other-project"];
|
|
147
|
-
assert.deepEqual(result.status.
|
|
147
|
+
assert.deepEqual(result.status.namespacesUnavailable, unavailable);
|
|
148
148
|
assert.deepEqual(addresses(result.rows), all.filter(address => !unavailable.some(prefix => address.startsWith(`${prefix}/`))));
|
|
149
|
-
assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status.
|
|
150
|
-
assert.deepEqual(addresses(await notes.list()), current, "local defaults do not enumerate unreadable foreign
|
|
149
|
+
assert.deepEqual((await notes.searchWithStatus(["needle"], { glob: "**" })).status.namespacesUnavailable, unavailable);
|
|
150
|
+
assert.deepEqual(addresses(await notes.list()), current, "local defaults do not enumerate unreadable foreign notebooks");
|
|
151
151
|
// A namespace scan must not read project marker files or let one bad marker abort its siblings.
|
|
152
152
|
chmodSync(failed[1], 0o755);
|
|
153
153
|
writeFileSync(join(home, "project/other-project/.project"), "{}");
|
|
154
154
|
chmodSync(join(home, "project/other-project/.project"), 0o000);
|
|
155
|
-
assert.deepEqual((await notes.listWithStatus({ glob: "@projects/*/**" })).status.
|
|
155
|
+
assert.deepEqual((await notes.listWithStatus({ glob: "@projects/*/**" })).status.namespacesUnavailable, []);
|
|
156
156
|
}
|
|
157
157
|
finally {
|
|
158
158
|
for (const dir of failed)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
|
|
2
2
|
import { DEFAULT_BOOT_TOOL_NAMES } from "../src/boot/text.js";
|
|
3
3
|
import assert from "node:assert/strict";
|
|
4
|
-
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
6
8
|
import test from "node:test";
|
|
7
9
|
import { loadNotesSnapshot } from "../src/boot/snapshot.js";
|
|
8
10
|
import { renderBootBlock } from "../src/boot/render.js";
|
|
@@ -12,7 +14,8 @@ import { localIso } from "../src/notes/frontmatter.js";
|
|
|
12
14
|
import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
|
|
13
15
|
import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
14
16
|
import { notesUpdate } from "../src/tools/notes.js";
|
|
15
|
-
import {
|
|
17
|
+
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
18
|
+
import { assertWithinBudget, call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead, runHandlers, } from "./helpers/extension.js";
|
|
16
19
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
17
20
|
const testEnvironment = installExtensionTestHooks("notesoup-integration");
|
|
18
21
|
/** The model-facing text of one tool result. */
|
|
@@ -20,6 +23,52 @@ function textOf(result) {
|
|
|
20
23
|
const first = result.content[0];
|
|
21
24
|
return first && first.type === "text" ? first.text : "";
|
|
22
25
|
}
|
|
26
|
+
for (const scanFails of [false, true]) {
|
|
27
|
+
test(`Pi shutdown cancels a pending dream after its gated scan ${scanFails ? "fails" : "resumes"}`, async (t) => {
|
|
28
|
+
const session = manager();
|
|
29
|
+
const captured = makeExtension(session);
|
|
30
|
+
const ctx = context(session);
|
|
31
|
+
const me = notesIdentityFromPi(ctx);
|
|
32
|
+
const otherCtx = context(manager(), undefined, undefined, true, join(testEnvironment.cwd, "other-project"));
|
|
33
|
+
const other = notesIdentityFromPi(otherCtx);
|
|
34
|
+
assert.notEqual(other.projectKey, me.projectKey);
|
|
35
|
+
const lockPath = join(me.home, ".dream.lock");
|
|
36
|
+
const original = fs.readdir;
|
|
37
|
+
let enter;
|
|
38
|
+
let release;
|
|
39
|
+
const entered = new Promise(resolve => { enter = resolve; });
|
|
40
|
+
const gate = new Promise(resolve => { release = resolve; });
|
|
41
|
+
let gated = false;
|
|
42
|
+
t.mock.method(fs, "readdir", async (...args) => {
|
|
43
|
+
if (!gated && args[0] === join(me.home, "project", me.projectKey)) {
|
|
44
|
+
gated = true;
|
|
45
|
+
enter();
|
|
46
|
+
await gate;
|
|
47
|
+
if (scanFails)
|
|
48
|
+
throw new TypeError("scan failed after shutdown");
|
|
49
|
+
}
|
|
50
|
+
return original(...args);
|
|
51
|
+
});
|
|
52
|
+
syncBuiltinESMExports();
|
|
53
|
+
t.after(() => { release(); t.mock.restoreAll(); syncBuiltinESMExports(); });
|
|
54
|
+
const opening = call(captured, "dream_begin", {}, ctx);
|
|
55
|
+
await entered;
|
|
56
|
+
assert.ok(existsSync(lockPath), "begin acquired ownership before the controlled scan await");
|
|
57
|
+
assert.equal(resultError(await call(captured, "dream_begin", {}, ctx)).code, "already_dreaming");
|
|
58
|
+
await runHandlers(captured, "session_shutdown", { type: "session_shutdown" }, ctx);
|
|
59
|
+
assert.equal(existsSync(lockPath), false, "the registered shutdown handler releases pending ownership");
|
|
60
|
+
assert.equal(resultError(await call(captured, "dream_end", {}, ctx)).code, "not_dreaming");
|
|
61
|
+
const newer = resultData(await call(captured, "dream_begin", {}, otherCtx));
|
|
62
|
+
assert.equal(newer.project, other.projectKey, "another project can immediately begin after shutdown");
|
|
63
|
+
const newerToken = readFileSync(lockPath, "utf8");
|
|
64
|
+
release();
|
|
65
|
+
assert.equal(resultError(await opening).code, "cancelled", "the stale opener cannot return success or resurrect state");
|
|
66
|
+
assert.equal(readFileSync(lockPath, "utf8"), newerToken, "stale cleanup cannot release the newer owner's token");
|
|
67
|
+
assert.equal(resultError(await call(captured, "dream_end", {}, ctx)).code, "not_dreaming");
|
|
68
|
+
resultData(await call(captured, "dream_end", {}, otherCtx));
|
|
69
|
+
assert.equal(existsSync(lockPath), false);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
23
72
|
test("notes_list and notes_search are recent-first snapshots with narrowing hints", async () => {
|
|
24
73
|
const session = manager();
|
|
25
74
|
const captured = makeExtension(session);
|
|
@@ -37,7 +86,7 @@ test("notes_list and notes_search are recent-first snapshots with narrowing hint
|
|
|
37
86
|
const listed = resultData(await call(captured, "notes_list", { limit: 2 }, ctx));
|
|
38
87
|
assert.deepEqual(listed.files.map((file) => file.address), ["new.md", "@project/design.md"]);
|
|
39
88
|
assert.equal(listed.more, 1);
|
|
40
|
-
assert.deepEqual(Object.keys(listed).sort(), ["files", "
|
|
89
|
+
assert.deepEqual(Object.keys(listed).sort(), ["files", "more", "namespaces_unavailable"]);
|
|
41
90
|
const searched = resultData(await call(captured, "notes_search", { query: "needle", limit: 2 }, ctx));
|
|
42
91
|
assert.deepEqual(searched.files.map((file) => file.address), ["new.md", "@project/design.md"]);
|
|
43
92
|
assert.equal(searched.more, 1);
|
|
@@ -104,7 +153,7 @@ test("notes_list is most-recently-updated first across merged scopes", async ()
|
|
|
104
153
|
// A same-path pair in two scopes keeps both rows; equal timestamps tie-break by scope name.
|
|
105
154
|
put("human", "a.md", base + 10);
|
|
106
155
|
assert.deepEqual((await files({})).filter((file) => file.address.endsWith("a.md")).map((file) => file.address), ["@human/a.md", "a.md"], "equal timestamps tie-break by full address");
|
|
107
|
-
assert.deepEqual((await files({ glob: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare glob narrows to the session
|
|
156
|
+
assert.deepEqual((await files({ glob: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare glob narrows to the session notebook");
|
|
108
157
|
});
|
|
109
158
|
test("notes are real files that persist across sessions and round-trip Unicode", async () => {
|
|
110
159
|
const original = manager();
|
|
@@ -160,15 +209,15 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
|
|
|
160
209
|
const missing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
|
|
161
210
|
assert.equal(missing.code, "not_found");
|
|
162
211
|
});
|
|
163
|
-
test("the filesystem notes loader treats an absent
|
|
212
|
+
test("the filesystem notes loader treats an absent notebook as empty but surfaces a real directory read failure", async () => {
|
|
164
213
|
const sm = manager();
|
|
165
214
|
const ctx = context(sm);
|
|
166
|
-
assert.deepEqual(await listNotes(ctx, { glob: "@human/**" }), [], "a
|
|
215
|
+
assert.deepEqual(await listNotes(ctx, { glob: "@human/**" }), [], "a notebook that has not been created is empty");
|
|
167
216
|
const blockedHome = scopeDir("human", ctx);
|
|
168
217
|
writeFileSync(blockedHome, "not a directory");
|
|
169
|
-
await assert.rejects(() => listNotes(ctx, { glob: "@human/**" }), (error) => error.code === "ENOTDIR", "a non-ENOENT directory failure is not swallowed as an empty
|
|
218
|
+
await assert.rejects(() => listNotes(ctx, { glob: "@human/**" }), (error) => error.code === "ENOTDIR", "a non-ENOENT directory failure is not swallowed as an empty notebook");
|
|
170
219
|
});
|
|
171
|
-
test("boot note acquisition is one closed snapshot and isolates one or all failed
|
|
220
|
+
test("boot note acquisition is one closed snapshot and isolates one or all failed notebooks", async () => {
|
|
172
221
|
const sm = manager();
|
|
173
222
|
const ctx = context(sm);
|
|
174
223
|
const updated = Date.now();
|
|
@@ -199,7 +248,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
199
248
|
calls.set(scope, (calls.get(scope) ?? 0) + 1);
|
|
200
249
|
return rows.get(scope) ?? [];
|
|
201
250
|
});
|
|
202
|
-
assert.deepEqual([...calls.entries()], [["session", 1], ["project", 1], ["human", 1], ["agent", 1], ["model", 1]], "each selected
|
|
251
|
+
assert.deepEqual([...calls.entries()], [["session", 1], ["project", 1], ["human", 1], ["agent", 1], ["model", 1]], "each selected notebook is loaded exactly once");
|
|
203
252
|
const renderData = {
|
|
204
253
|
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
205
254
|
agentName: "root",
|
|
@@ -209,8 +258,8 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
209
258
|
};
|
|
210
259
|
const rendered = renderBootBlock(renderData);
|
|
211
260
|
assert.equal(renderBootBlock(renderData), rendered, "rendering the same boot data twice is deterministic");
|
|
212
|
-
assert.ok(rendered.includes("HUMAN_MAP_BODY") && rendered.includes("PROJECT_MAP_BODY") && rendered.includes("AGENT_MAP_BODY") && rendered.includes("SESSION_MAP_BODY"), "all
|
|
213
|
-
assert.ok(rendered.includes("session.md") && rendered.includes("@human/human.md"), "the fresh page carries rows from every
|
|
261
|
+
assert.ok(rendered.includes("HUMAN_MAP_BODY") && rendered.includes("PROJECT_MAP_BODY") && rendered.includes("AGENT_MAP_BODY") && rendered.includes("SESSION_MAP_BODY"), "all notebook maps, including session, are pinned");
|
|
262
|
+
assert.ok(rendered.includes("session.md") && rendered.includes("@human/human.md"), "the fresh page carries rows from every notebook");
|
|
214
263
|
assert.equal(rendered.includes("SESSION_POCKET_BODY"), false, "fresh-page bodies stay excluded");
|
|
215
264
|
assert.equal(rendered.includes("- MAP.md"), false, "a pinned session map does not take a feed seat");
|
|
216
265
|
assert.match(rendered, / {2}Session note\n {2}session\.md · (?:just now|\d+s ago)/, "a feed entry is the note's own title over its locator");
|
|
@@ -247,7 +296,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
247
296
|
] : []);
|
|
248
297
|
const mapAndUnicodeText = renderBootBlock({ ...renderData, notes: mapAndUnicode });
|
|
249
298
|
assert.match(mapAndUnicodeText, / {2}🐑字\n {2}unicode\.md · (?:just now|\d+s ago)/, "a headingless note is announced by its first line");
|
|
250
|
-
assert.ok(mapAndUnicodeText.includes("no @ — this session\n───────────────────\n\
|
|
299
|
+
assert.ok(mapAndUnicodeText.includes("no @ — this session\n───────────────────\n\nMAP.md\n\n SESSION_MAP_BODY\n\nrecent\n\n 🐑字\n unicode.md · just now"), "the session shelf keeps its typography");
|
|
251
300
|
assert.equal(mapAndUnicodeText.includes("crumpled.md"), false);
|
|
252
301
|
assert.equal(/MAP\.md ·/.test(mapAndUnicodeText), false, "maps never take feed seats");
|
|
253
302
|
assert.equal(mapAndUnicodeText.includes("@human — the human"), false, "empty shelves are omitted");
|
|
@@ -257,7 +306,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
257
306
|
throw readFailure("EIO");
|
|
258
307
|
return rows.get(scope) ?? [];
|
|
259
308
|
});
|
|
260
|
-
assert.deepEqual(oneFailed.unavailable.map((
|
|
309
|
+
assert.deepEqual(oneFailed.unavailable.map((namespace) => namespace.label), ["@human"]);
|
|
261
310
|
const oneFailedText = renderBootBlock({
|
|
262
311
|
tools: DEFAULT_BOOT_TOOL_NAMES,
|
|
263
312
|
agentName: "root",
|
|
@@ -265,9 +314,9 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
265
314
|
tree: renderData.tree,
|
|
266
315
|
notes: oneFailed,
|
|
267
316
|
});
|
|
268
|
-
assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("@human — the human\n──────────────────\n\n This drawer wouldn't open. Try `notes_list` again."), "healthy
|
|
269
|
-
assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed
|
|
270
|
-
assert.equal(oneFailedText.includes("Human note"), false, "the failed
|
|
317
|
+
assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("@human — the human\n──────────────────\n\n This drawer wouldn't open. Try `notes_list` again."), "healthy notebooks and a per-section recovery notice survive one failure");
|
|
318
|
+
assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed notebook's index is omitted");
|
|
319
|
+
assert.equal(oneFailedText.includes("Human note"), false, "the failed notebook takes no feed seats");
|
|
271
320
|
const allFailed = await loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), (scope) => {
|
|
272
321
|
throw readFailure(scope === "session" ? "EACCES" : "EIO");
|
|
273
322
|
});
|
|
@@ -279,13 +328,13 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
|
|
|
279
328
|
tree: renderData.tree,
|
|
280
329
|
notes: allFailed,
|
|
281
330
|
});
|
|
282
|
-
assert.ok(allFailedText.includes("pcw:test") && allFailedText.includes("root") && allFailedText.includes("next"), "identity survives an all-
|
|
283
|
-
assert.ok(allFailedText.includes("Your memory gets wiped when this window ends"), "protocol survives an all-
|
|
331
|
+
assert.ok(allFailedText.includes("pcw:test") && allFailedText.includes("root") && allFailedText.includes("next"), "identity survives an all-notebook failure");
|
|
332
|
+
assert.ok(allFailedText.includes("Your memory gets wiped when this window ends"), "protocol survives an all-notebook failure");
|
|
284
333
|
assert.equal(allFailedText.includes("scripted read failure"), false, "the model-facing notice does not expose OS/error details");
|
|
285
334
|
await assert.rejects(() => loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), () => { throw new TypeError("programmer failure"); }), (error) => error instanceof TypeError, "unrelated TypeError construction failures remain visible");
|
|
286
335
|
await assert.rejects(() => loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), () => { throw Object.assign(new Error("invalid argument"), { code: "ERR_INVALID_ARG_TYPE" }); }), (error) => error.code === "ERR_INVALID_ARG_TYPE", "Node ERR_* failures are not treated as filesystem errno failures");
|
|
287
336
|
});
|
|
288
|
-
test("the boot block gives awake agents the notes
|
|
337
|
+
test("the boot block gives awake agents the notes file layout", async () => {
|
|
289
338
|
const session = manager();
|
|
290
339
|
const rendered = await explicitBoot(context(session), "pcw:test:root", undefined);
|
|
291
340
|
assert.equal(rendered.includes(process.env.NOTESOUP_HOME ?? ""), false, "the absolute notes home is never exposed");
|
|
@@ -305,7 +354,7 @@ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer"
|
|
|
305
354
|
assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
|
|
306
355
|
assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false, "the over-cap suffix is not inlined");
|
|
307
356
|
assert.ok(rendered.includes("`MAP.md`"), "the full MAP remains available by address");
|
|
308
|
-
assert.ok(rendered.includes("
|
|
357
|
+
assert.ok(rendered.includes("CHEATSHEET.md\n\n REMEMBER_THIS_RULE\n\nMAP.md\n\n"), "a real stored cheatsheet is pinned before the map");
|
|
309
358
|
assert.equal(/CHEATSHEET\.md ·/.test(rendered), false, "the stored cheatsheet takes no recent seat");
|
|
310
359
|
for (const retired of ["history_windows", "history_list", "history_read"]) {
|
|
311
360
|
assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
|
|
@@ -508,10 +557,10 @@ test("an unexpected notes defect propagates with its own identity while real fil
|
|
|
508
557
|
// Its message deliberately opens with "query " — the wording a refusal classification once
|
|
509
558
|
// matched on, which turned any such defect into a wrong invalid_query.
|
|
510
559
|
const sentinel = new TypeError("query renderer invariant broken");
|
|
511
|
-
await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "before", newText: "after" }] }, identity, () => { throw sentinel; }), (error) => error === sentinel, "an unexpected failure escapes with the identical Error, message and stack");
|
|
560
|
+
await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "before", newText: "after" }] }, notesToolContext(identity, "/work/current"), () => { throw sentinel; }), (error) => error === sentinel, "an unexpected failure escapes with the identical Error, message and stack");
|
|
512
561
|
assert.equal(resultRead(await call(captured, "notes_read", { address: "propagate.md" }, ctx)).content, "after", "the edit was applied before the receipt failed; the throw claims no rollback");
|
|
513
562
|
const assertion = Object.assign(new Error("assertion failed"), { code: "ERR_ASSERTION" });
|
|
514
|
-
await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "after", newText: "later" }] }, identity, () => { throw assertion; }), (error) => error.code === "ERR_ASSERTION", "a Node ERR_ code is a programmer failure, never an io_error");
|
|
563
|
+
await assert.rejects(() => notesUpdate.execute({ address: "propagate.md", edits: [{ oldText: "after", newText: "later" }] }, notesToolContext(identity, "/work/current"), () => { throw assertion; }), (error) => error.code === "ERR_ASSERTION", "a Node ERR_ code is a programmer failure, never an io_error");
|
|
515
564
|
// A genuine filesystem refusal is still an expected outcome, and still says nothing about paths.
|
|
516
565
|
rmSync(scopeDir("session", ctx), { recursive: true, force: true });
|
|
517
566
|
writeFileSync(scopeDir("session", ctx), "not a directory");
|