notesoup 0.59.2 → 0.60.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 +3 -17
- package/dist/plugins/claude/src/helper.js +1 -2
- package/dist/plugins/codex/src/mcp.js +1 -2
- package/dist/plugins/dsh/tools.js +1 -2
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +2 -3
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- package/dist/src/history/query.d.ts +3 -14
- package/dist/src/history/query.js +73 -85
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/address.js +3 -3
- package/dist/src/notes/store.d.ts +2 -4
- package/dist/src/notes/store.js +1 -2
- package/dist/src/tools/history.d.ts +4 -6
- package/dist/src/tools/history.js +69 -29
- package/dist/src/tools/notes.d.ts +18 -78
- package/dist/src/tools/notes.js +39 -50
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/claude-history.test.js +5 -6
- package/dist/test/claude-mod.test.js +6 -7
- package/dist/test/codex-history.test.js +1 -1
- package/dist/test/codex-plugin.test.js +1 -2
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh.test.js +2 -2
- package/dist/test/history-corpus.test.js +21 -36
- package/dist/test/history-summary-cache.test.js +3 -3
- package/dist/test/history.integration.test.js +53 -106
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/note-policy.test.js +5 -5
- package/dist/test/notes-cwd.test.js +5 -5
- package/dist/test/notes-query-namespaces.test.js +2 -6
- package/dist/test/notes.integration.test.js +30 -35
- package/dist/test/notes.test.js +12 -14
- package/dist/test/project-namespace.test.js +3 -3
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +8 -9
- package/docs/notes-library.md +3 -3
- package/docs/tool-results.md +12 -6
- package/package.json +1 -1
- package/plugins/claude/dist/claude/helper.js +162 -153
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +1 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +161 -152
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/history/history.ts +11 -16
- package/src/history/query.ts +67 -99
- package/src/index.ts +1 -1
- package/src/notes/address.ts +2 -2
- package/src/notes/store.ts +3 -6
- package/src/tools/history.ts +60 -29
- package/src/tools/notes.ts +39 -54
- package/src/tools/schema.ts +0 -1
|
@@ -68,7 +68,7 @@ for (const scanFails of [false, true]) {
|
|
|
68
68
|
assert.equal(existsSync(lockPath), false);
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
test("notes_list and
|
|
71
|
+
test("notes_list browses and searches recent-first snapshots", async () => {
|
|
72
72
|
const session = manager();
|
|
73
73
|
const captured = makeExtension(session);
|
|
74
74
|
const ctx = context(session);
|
|
@@ -81,13 +81,16 @@ test("notes_list and notes_search are recent-first snapshots with narrowing hint
|
|
|
81
81
|
};
|
|
82
82
|
put("old.md", base + 1);
|
|
83
83
|
put("new.md", base + 3);
|
|
84
|
-
put("@project/design.md", base + 2);
|
|
84
|
+
put("@project/design.md", base + 2, "design\nThe NEEDLE");
|
|
85
|
+
put("unrelated.md", base + 4, "not a hit");
|
|
85
86
|
const listed = resultData(await call(captured, "notes_list", { limit: 2 }, ctx));
|
|
86
|
-
assert.deepEqual(listed.files.map((file) => file.address), ["
|
|
87
|
-
assert.equal(listed.more,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
assert.deepEqual(listed.files.map((file) => file.address), ["unrelated.md", "new.md"]);
|
|
88
|
+
assert.equal(listed.more, 2);
|
|
89
|
+
const searched = resultData(await call(captured, "notes_list", { query: "needle", limit: 2 }, ctx));
|
|
90
|
+
assert.deepEqual(searched.files.map((file) => [file.address, file.matches]), [
|
|
91
|
+
["new.md", [{ line: 1, text: "needle", offset_chars: 0 }]],
|
|
92
|
+
["@project/design.md", [{ line: 2, text: "The NEEDLE", offset_chars: 11 }]],
|
|
93
|
+
]);
|
|
91
94
|
assert.equal(searched.more, 1);
|
|
92
95
|
const narrowed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
|
|
93
96
|
assert.deepEqual(narrowed.files.map((file) => file.address), ["@project/design.md"]);
|
|
@@ -105,14 +108,9 @@ test("empty notes queries list scoped notes without fabricated matches", async (
|
|
|
105
108
|
for (const crumpled of [false, true]) {
|
|
106
109
|
const filters = { glob: "empty-query/**", crumpled, limit: 1 };
|
|
107
110
|
const listed = resultData(await call(captured, "notes_list", filters, ctx));
|
|
108
|
-
|
|
109
|
-
for (const query of [undefined, "", [], ["", ""]]) {
|
|
110
|
-
assert.deepEqual(resultData(await call(captured, "notes_search", { ...filters, query }, ctx)), expected);
|
|
111
|
-
}
|
|
111
|
+
assert.deepEqual(resultData(await call(captured, "notes_list", { ...filters, query: [] }, ctx)), listed);
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
assert.deepEqual(resultData(await call(captured, "notes_search", { ...filters, query: ["", "needle"] }, ctx)), resultData(await call(captured, "notes_search", { ...filters, query: "needle" }, ctx)));
|
|
115
|
-
assert.equal(resultError(await call(captured, "notes_search", { query: [42] }, ctx)).code, "invalid_query");
|
|
113
|
+
assert.match(resultError(await call(captured, "notes_list", { max_matches_per_file: 1 }, ctx)).message, /requires a non-empty `query`/);
|
|
116
114
|
});
|
|
117
115
|
test("notes_list reports omitted files when the wire budget truncates the snapshot", async () => {
|
|
118
116
|
const session = manager();
|
|
@@ -168,8 +166,8 @@ test("notes are real files that persist across sessions and round-trip Unicode",
|
|
|
168
166
|
const read = resultRead(rawRead);
|
|
169
167
|
assert.equal(read.address, "@human/checkpoint/进度.md");
|
|
170
168
|
assert.equal(read.content, "Café", "a negative offset reads the body tail in one call");
|
|
171
|
-
const searched = resultData(await call(restoredCaptured, "
|
|
172
|
-
assert.equal(searched.files[0]?.matches[0]?.line, 2);
|
|
169
|
+
const searched = resultData(await call(restoredCaptured, "notes_list", { glob: "@human/**", query: "Café" }, restoredCtx));
|
|
170
|
+
assert.equal(searched.files[0]?.matches?.[0]?.line, 2);
|
|
173
171
|
const listedFiles = resultData(await call(restoredCaptured, "notes_list", { glob: "@human/checkpoint/**" }, restoredCtx));
|
|
174
172
|
assert.equal(listedFiles.files.length, 1, "glob ** crosses into the checkpoint directory");
|
|
175
173
|
assert.equal(listedFiles.files[0]?.address, "@human/checkpoint/进度.md");
|
|
@@ -285,7 +283,7 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
|
|
|
285
283
|
await call(captured, "notes_write", { address: "@project/receipt", content: "body" }, ctx),
|
|
286
284
|
await call(captured, "notes_update", { address: "@project/receipt", edits: [{ oldText: "body", newText: "changed" }] }, ctx),
|
|
287
285
|
await call(captured, "notes_list", { glob: "@project/**" }, ctx),
|
|
288
|
-
await call(captured, "
|
|
286
|
+
await call(captured, "notes_list", { query: "changed", glob: "@project/**" }, ctx),
|
|
289
287
|
await call(captured, "notes_read", { address: "@project/receipt" }, ctx),
|
|
290
288
|
]) {
|
|
291
289
|
assert.equal(JSON.stringify(result).includes(root), false, "notes receipts never expose the absolute home");
|
|
@@ -305,17 +303,15 @@ test("an over-budget note search match is a marked prefix with an honest line ad
|
|
|
305
303
|
const hugeLine = `${'p'.repeat(500)}needle ${"y".repeat(TOOL_OUTPUT_MAX_BYTES * 2)}`;
|
|
306
304
|
await call(captured, "notes_write", { address: "a.md", content: "needle small" }, ctx);
|
|
307
305
|
await call(captured, "notes_write", { address: "search.md", content: hugeLine }, ctx);
|
|
308
|
-
const
|
|
309
|
-
const rawFound = await call(captured, "notes_search", { query: "needle", limit: 10 }, ctx);
|
|
306
|
+
const rawFound = await call(captured, "notes_list", { query: "needle", limit: 10 }, ctx);
|
|
310
307
|
const found = resultData(rawFound);
|
|
311
308
|
assert.ok(Buffer.byteLength(JSON.stringify(found), "utf8") <= TOOL_OUTPUT_MAX_BYTES, "the structured match result stays within budget");
|
|
312
309
|
assert.match(textOf(rawFound), /\[truncated\]/, "the model-facing match line carries the same marker");
|
|
313
|
-
pages.push(...found.files);
|
|
314
310
|
assert.equal(found.more, 1, "the oversized result names the omitted matching file");
|
|
315
|
-
assert.deepEqual(
|
|
316
|
-
const
|
|
317
|
-
assert.equal(
|
|
318
|
-
const match =
|
|
311
|
+
assert.deepEqual(found.files.map((file) => file.address), ["search.md"], "the snapshot keeps the most recently updated match");
|
|
312
|
+
const matches = found.files[0].matches;
|
|
313
|
+
assert.equal(matches.length, 1);
|
|
314
|
+
const match = matches[0];
|
|
319
315
|
assert.ok(match.text.endsWith(" [truncated]"), "a shortened match line ends with the ellipsis marker");
|
|
320
316
|
assert.ok(hugeLine.startsWith(match.text.slice(0, -" [truncated]".length)), "the match text is a plain prefix of the line plus its marker");
|
|
321
317
|
assert.equal(match.line, 1, "the informational line number survives");
|
|
@@ -340,18 +336,18 @@ for (const [label, padding, cap] of [
|
|
|
340
336
|
["both limits", Math.floor(TOOL_OUTPUT_MAX_BYTES / 3), 6],
|
|
341
337
|
["shortened first line", TOOL_OUTPUT_MAX_BYTES * 2, undefined],
|
|
342
338
|
]) {
|
|
343
|
-
test(`
|
|
339
|
+
test(`notes_list reports dropped match lines after ${label}`, async () => {
|
|
344
340
|
const session = manager();
|
|
345
341
|
const captured = makeExtension(session);
|
|
346
342
|
const ctx = context(session);
|
|
347
343
|
const lines = Array.from({ length: padding > TOOL_OUTPUT_MAX_BYTES ? 3 : 8 }, (_, index) => `needle ${index}${"y".repeat(padding)}`);
|
|
348
344
|
resultData(await call(captured, "notes_write", { address: "matches.md", content: lines.join("\n") }, ctx));
|
|
349
|
-
const raw = await call(captured, "
|
|
345
|
+
const raw = await call(captured, "notes_list", { query: "needle", max_matches_per_file: cap }, ctx);
|
|
350
346
|
assertWithinBudget(raw, label);
|
|
351
347
|
const found = resultData(raw);
|
|
352
348
|
assert.equal(found.more, 0, "line omissions are separate from omitted pages");
|
|
353
349
|
const [file] = found.files;
|
|
354
|
-
assert.ok(file);
|
|
350
|
+
assert.ok(file?.matches);
|
|
355
351
|
assert.ok(file.matches.length > 0 && file.matches.length < lines.length);
|
|
356
352
|
if (cap !== undefined)
|
|
357
353
|
assert.ok(file.matches.length <= cap);
|
|
@@ -361,30 +357,29 @@ for (const [label, padding, cap] of [
|
|
|
361
357
|
assert.ok(textOf(raw).includes(`${file.more_matches} more lines`));
|
|
362
358
|
});
|
|
363
359
|
}
|
|
364
|
-
test("
|
|
360
|
+
test("notes_list treats queries literally and preserves original Unicode offsets", async () => {
|
|
365
361
|
const session = manager();
|
|
366
362
|
const captured = makeExtension(session);
|
|
367
363
|
const ctx = context(session);
|
|
368
364
|
await call(captured, "notes_write", { address: "case-match.md", content: "😀İ NeEdLe.* tail" }, ctx);
|
|
369
|
-
const found = resultData(await call(captured, "
|
|
365
|
+
const found = resultData(await call(captured, "notes_list", { query: ["missing", "needle.*"], glob: "case-match.md" }, ctx));
|
|
370
366
|
assert.equal(found.files.length, 1);
|
|
371
|
-
assert.equal(found.files[0].matches.length, 1);
|
|
372
|
-
assert.equal(found.files[0].more_matches, undefined);
|
|
373
367
|
const hit = found.files[0];
|
|
368
|
+
assert.equal(hit.matches?.length, 1);
|
|
374
369
|
const read = resultRead(await call(captured, "notes_read", { address: hit.address, offset_chars: hit.matches[0].offset_chars }, ctx));
|
|
375
370
|
assert.equal(read.content, "NeEdLe.* tail");
|
|
376
|
-
const absent = resultData(await call(captured, "
|
|
371
|
+
const absent = resultData(await call(captured, "notes_list", { query: "needle.+", glob: "case-match.md" }, ctx));
|
|
377
372
|
assert.deepEqual(absent.files, []);
|
|
378
373
|
});
|
|
379
|
-
test("
|
|
374
|
+
test("notes_list scopes queries by glob", async () => {
|
|
380
375
|
const session = manager();
|
|
381
376
|
const captured = makeExtension(session);
|
|
382
377
|
const ctx = context(session);
|
|
383
378
|
await call(captured, "notes_write", { address: "deep/nested/a.md", content: "needle here" }, ctx);
|
|
384
379
|
await call(captured, "notes_write", { address: "top.md", content: "needle there" }, ctx);
|
|
385
|
-
const scoped = resultData(await call(captured, "
|
|
380
|
+
const scoped = resultData(await call(captured, "notes_list", { query: "needle", glob: "deep/**" }, ctx));
|
|
386
381
|
assert.deepEqual(scoped.files.map((file) => file.address), ["deep/nested/a.md"], "a glob scopes the search to the subtree");
|
|
387
|
-
const none = resultData(await call(captured, "
|
|
382
|
+
const none = resultData(await call(captured, "notes_list", { query: "needle", glob: "absent/**" }, ctx));
|
|
388
383
|
assert.deepEqual(none.files, [], "a non-matching glob is an empty page, not a refusal");
|
|
389
384
|
});
|
|
390
385
|
test("a large mutation keeps a receipt and budget warning while details.diff carries the UI diff", async () => {
|
package/dist/test/notes.test.js
CHANGED
|
@@ -16,7 +16,7 @@ import { parseNote } from "../src/notes/frontmatter.js";
|
|
|
16
16
|
import { createNotesStore, projectKey } from "../src/notes/index.js";
|
|
17
17
|
import { globToRegExp } from "../src/notes/address.js";
|
|
18
18
|
import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
|
|
19
|
-
import { notesList
|
|
19
|
+
import { notesList } from "../src/tools/notes.js";
|
|
20
20
|
import { notesIdentityFromPi } from "../plugins/pi/notes/adapter.js";
|
|
21
21
|
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
22
22
|
import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
|
|
@@ -34,7 +34,7 @@ test("tools register their namespaces and sequential note mutations", () => {
|
|
|
34
34
|
assert.equal(captured.tools.get("notes_write")?.executionMode, "sequential");
|
|
35
35
|
assert.equal(captured.tools.get("notes_update")?.executionMode, "sequential");
|
|
36
36
|
assert.equal(captured.tools.get("notes_read")?.executionMode, undefined);
|
|
37
|
-
for (const name of ["notes_write", "notes_update", "notes_read", "notes_list"
|
|
37
|
+
for (const name of ["notes_write", "notes_update", "notes_read", "notes_list"]) {
|
|
38
38
|
assert.equal(captured.tools.get(name)?.namespace?.name, "notes", `${name} is in notes`);
|
|
39
39
|
}
|
|
40
40
|
for (const name of ["history_list", "history_read"]) {
|
|
@@ -51,7 +51,7 @@ test("every notes tool declares a result schema that accepts its own structured
|
|
|
51
51
|
["notes_update", await call(captured, "notes_update", { address: "schema.md", edits: [{ oldText: "again", newText: "once" }] }, ctx)],
|
|
52
52
|
["notes_read", await call(captured, "notes_read", { address: "schema.md" }, ctx)],
|
|
53
53
|
["notes_list", await call(captured, "notes_list", {}, ctx)],
|
|
54
|
-
["
|
|
54
|
+
["notes_list", await call(captured, "notes_list", { query: "needle" }, ctx)],
|
|
55
55
|
["notes_read", await call(captured, "notes_read", { address: "absent.md" }, ctx)],
|
|
56
56
|
];
|
|
57
57
|
for (const [name, result] of delivered) {
|
|
@@ -67,7 +67,7 @@ test("note schemas accept their operations, reject unknown fields, and expose cr
|
|
|
67
67
|
["notes_update", { address: "a.md", crumpled: true }],
|
|
68
68
|
["notes_read", { address: "a.md" }],
|
|
69
69
|
["notes_list", { crumpled: true }],
|
|
70
|
-
["
|
|
70
|
+
["notes_list", { query: "x", crumpled: true }],
|
|
71
71
|
]) {
|
|
72
72
|
const schema = captured.tools.get(name).parameters;
|
|
73
73
|
assert.equal(Check(schema, params), true, name);
|
|
@@ -345,7 +345,7 @@ test("empty results distinguish hidden notes and unavailable notebooks", async (
|
|
|
345
345
|
assert.deepEqual(empty, { files: [], more: 0, namespaces_unavailable: [] });
|
|
346
346
|
await call(captured, "notes_write", { address: "@human/hidden.md", content: "needle" }, ctx);
|
|
347
347
|
await call(captured, "notes_update", { address: "@human/hidden.md", crumpled: true }, ctx);
|
|
348
|
-
const hidden = resultData(await call(captured, "
|
|
348
|
+
const hidden = resultData(await call(captured, "notes_list", { query: "needle", glob: "@human/**" }, ctx));
|
|
349
349
|
assert.deepEqual(hidden.files, [], "a crumpled note is hidden from search");
|
|
350
350
|
const identity = notesIdentityFromPi(ctx);
|
|
351
351
|
const broken = scopeDir("project", ctx);
|
|
@@ -357,7 +357,7 @@ test("empty results distinguish hidden notes and unavailable notebooks", async (
|
|
|
357
357
|
const partial = partialResult.data;
|
|
358
358
|
assert.deepEqual(partial.namespaces_unavailable, ["@project"]);
|
|
359
359
|
assert.deepEqual(partial.files, []);
|
|
360
|
-
const searchResult = await
|
|
360
|
+
const searchResult = await notesList.execute({ query: "needle", glob: "**" }, notesToolContext(identity, ctx.cwd));
|
|
361
361
|
assert.ok(searchResult.ok);
|
|
362
362
|
assert.deepEqual(searchResult.data.namespaces_unavailable, ["@project"]);
|
|
363
363
|
writeFileSync(join(process.env.NOTESOUP_HOME, "agents"), "not a directory");
|
|
@@ -391,8 +391,8 @@ test("notes receipts report resolved identity across scopes", async () => {
|
|
|
391
391
|
assert.deepEqual(listed.files.map((file) => file.address).sort(), notes.map((note) => note.address).sort(), "notes_list returns each full address");
|
|
392
392
|
for (const row of listed.files)
|
|
393
393
|
assertReceiptIdentity(row, row.address, notes.find((note) => note.address === row.address).scope, ctx);
|
|
394
|
-
const searched = resultData(await call(captured, "
|
|
395
|
-
assert.deepEqual(searched.files.map((file) => file.address), notes.map((note) => note.address).sort(), "
|
|
394
|
+
const searched = resultData(await call(captured, "notes_list", { query: "match", glob: "**" }, ctx));
|
|
395
|
+
assert.deepEqual(searched.files.map((file) => file.address), notes.map((note) => note.address).sort(), "search returns each full address");
|
|
396
396
|
for (const row of searched.files)
|
|
397
397
|
assertReceiptIdentity(row, row.address, notes.find((note) => note.address === row.address).scope, ctx);
|
|
398
398
|
});
|
|
@@ -410,12 +410,12 @@ test("list and search merge scopes and carry addresses; the path jail rejects es
|
|
|
410
410
|
assert.equal(typeof row.updated_at, "string");
|
|
411
411
|
const scoped = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
|
|
412
412
|
assert.deepEqual(scoped.files.map((file) => file.address), ["@human/three.md"], "an address glob filter narrows the set");
|
|
413
|
-
const searched = resultData(await call(captured, "
|
|
413
|
+
const searched = resultData(await call(captured, "notes_list", { query: "needle" }, ctx));
|
|
414
414
|
assert.equal(searched.files.length, 3, "literal search finds matches in every scope");
|
|
415
415
|
assert.deepEqual([...searched.files].map((file) => file.address).sort(), ["@human/three.md", "@project/two.md", "one.md"]);
|
|
416
416
|
for (const row of [...listed.files, ...searched.files])
|
|
417
417
|
assert.equal("scope" in row, false, "scope is derivable from the address and never echoed");
|
|
418
|
-
assert.equal(searched.files.every((file) => file.matches
|
|
418
|
+
assert.equal(searched.files.every((file) => file.matches?.length === 1), true);
|
|
419
419
|
const hit = searched.files[0].matches[0];
|
|
420
420
|
assert.equal(hit.line, 1);
|
|
421
421
|
assert.equal(hit.offset_chars, 0, "the offset counts into the note body, so it does not include serialized frontmatter");
|
|
@@ -427,10 +427,8 @@ test("list and search merge scopes and carry addresses; the path jail rejects es
|
|
|
427
427
|
assert.equal(resultError(await call(captured, tool, { address: path, content: "x", edits: [{ oldText: "a", newText: "b" }] }, ctx)).code, "invalid_address");
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
assert.deepEqual(resultData(await call(captured, "notes_search", { query: "" }, ctx)), resultData(await call(captured, "notes_search", {}, ctx)));
|
|
431
430
|
assert.equal(resultError(await call(captured, "notes_read", { address: "one.md", offset_chars: 99999 }, ctx)).code, "invalid_offset");
|
|
432
431
|
assert.equal(resultError(await call(captured, "notes_list", { glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
|
|
433
|
-
assert.equal(resultError(await call(captured, "notes_search", { query: "needle", glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
|
|
434
432
|
});
|
|
435
433
|
test("a read offsets the body in code points, not bytes or frontmatter", async () => {
|
|
436
434
|
freshRoot();
|
|
@@ -438,7 +436,7 @@ test("a read offsets the body in code points, not bytes or frontmatter", async (
|
|
|
438
436
|
const captured = makeExtension(session);
|
|
439
437
|
const ctx = context(session);
|
|
440
438
|
await call(captured, "notes_write", { address: "emoji.md", content: "🐑字\nneedle tail" }, ctx);
|
|
441
|
-
const search = resultData(await call(captured, "
|
|
439
|
+
const search = resultData(await call(captured, "notes_list", { query: "needle", glob: "emoji.md" }, ctx));
|
|
442
440
|
const match = search.files[0].matches[0];
|
|
443
441
|
assert.equal(match.line, 2);
|
|
444
442
|
assert.equal(match.offset_chars, 3, "the emoji and CJK line above contribute two code points plus the newline, not their bytes");
|
|
@@ -483,7 +481,7 @@ test("interior @ in a note path round-trips through write, list, search, read, u
|
|
|
483
481
|
assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "both addresses list in canonical form");
|
|
484
482
|
const globbed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
|
|
485
483
|
assert.deepEqual(globbed.files.map((row) => row.address), ["@project/mail/alice@example.com.md"], "a notebook glob still narrows to that notebook");
|
|
486
|
-
const searched = resultData(await call(captured, "
|
|
484
|
+
const searched = resultData(await call(captured, "notes_list", { query: "needle" }, ctx));
|
|
487
485
|
assert.deepEqual(searched.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "searched addresses carry the interior @ back out");
|
|
488
486
|
assert.match(resultRead(await call(captured, "notes_read", { address: "@project/mail/alice@example.com.md" }, ctx)).content, /mail needle$/);
|
|
489
487
|
await call(captured, "notes_update", { address: "release@v1.md", edits: [{ oldText: "release", newText: "shipped" }] }, ctx);
|
|
@@ -9,7 +9,7 @@ import { Check } from "typebox/value";
|
|
|
9
9
|
import { createNotesStore } from "../src/notes/index.js";
|
|
10
10
|
import { assertAddress } from "../src/notes/address.js";
|
|
11
11
|
import { normalizeRemote, projectKey } from "../src/notes/project-namespace.js";
|
|
12
|
-
import { notesList, notesRead,
|
|
12
|
+
import { notesList, notesRead, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
13
13
|
import { success } from "../src/result.js";
|
|
14
14
|
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
15
15
|
const toolContext = (identity) => notesToolContext(identity, "/work/current");
|
|
@@ -300,9 +300,9 @@ test("named projects read/list/search with root and sibling receipts, without to
|
|
|
300
300
|
const listed = data(await notesList.execute({ glob: "@projects/*/**" }, toolContext(own)));
|
|
301
301
|
assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
|
|
302
302
|
assert.equal(Check(notesList.outputSchema, listed), true);
|
|
303
|
-
const searched = data(await
|
|
303
|
+
const searched = data(await notesList.execute({ glob: "@projects/api-1/**", query: "needle" }, toolContext(own)));
|
|
304
304
|
assert.equal(searched.files[0]?.project_root, second);
|
|
305
|
-
assert.equal(Check(
|
|
305
|
+
assert.equal(Check(notesList.outputSchema, searched), true);
|
|
306
306
|
assert.equal(readFileSync(file, "utf8"), before, "named-notebook reads never rewrite access metadata");
|
|
307
307
|
});
|
|
308
308
|
test("named project writes, edits, crumples and both move endpoints refuse, including the current notebook", async (t) => {
|
package/docs/architecture.md
CHANGED
|
@@ -13,7 +13,7 @@ notesoup uses Pi's session branch as the durable source of truth. It does not ma
|
|
|
13
13
|
| `boot/snapshot.ts` | Load each of the five notebooks once; isolate filesystem errno failures | Explicit identity, captured time and optional scope loader |
|
|
14
14
|
| `boot/render.ts`, `boot/text.ts` | Render window data separately from fixed protocol/maps teaching; retain a combined boot for other hosts | Explicit snapshot and logical tool-name bindings; no I/O or clock |
|
|
15
15
|
| `history/history.ts` | Project decoded events and pair tool calls/results, preserving supplied addresses | Decoded items and branch visibility; never inference messages |
|
|
16
|
-
| `history/query.ts` | Bounded paging,
|
|
16
|
+
| `history/query.ts` | Bounded paging, literal matching and neighboring context, folding and chronological cross-session merging | Caller-supplied budget check and page-too-large facts; no tool dependencies or native SDK/session traversal |
|
|
17
17
|
| `history/corpus.ts`, `history/local.ts` | Session selector resolution and read-only local discovery, with explicit roots/env | Lazy projections and canonical identities; DSH contributes service-backed descriptors |
|
|
18
18
|
| `history/pi.ts`, `history/claude.ts`, `history/codex.ts`, `history/codex-transcript.ts` | Persisted wire decoding, stable seq allocation and recorded branch/lineage evidence | Node/structural data only; no SDK or plugin imports; shared by corpus and native adapter entries |
|
|
19
19
|
| `budget/constants.ts`, `budget/policy.ts`, `budget/text.ts` | Pure thresholds, unknown/clamped countdown and reminder text | Values supplied by the caller; no settings reads or scheduling |
|
|
@@ -58,7 +58,7 @@ Pi's `before_agent_start` mutates the public `systemPromptOptions.sections`: `no
|
|
|
58
58
|
|
|
59
59
|
The Pi boot remains a fixed snapshot for its window, stored as a hidden extension custom message and converted to a user-role model message. It contains only the window identity/tree and notes index/pinned bodies: no note, including `@human`, becomes a system instruction, and readonly semantics are unchanged. On resume, provider projection removes only a recognized old boot's consecutive top-level identity -> protocol -> maps -> notes prefix teaching; tags or quotations inside note bodies and ordinary messages remain untouched. Persisted boot/history bytes are never rewritten. Claude, Codex and dsh retain the combined renderer and their existing injection paths. History internally distinguishes native system summaries and extension-authored custom messages; its public `context` event groups both without implying provider instruction priority. Boot injection is silent, including startup, reload, and boot repair. `/empty` and `/fresh-window` acknowledge a new request with `🥣 Dumping Brain`. Normal reset completion is silent; only forced reset completion produces `🥣 Brain forcibly emptied: overflow` through `ctx.ui.notify`, after the verified checkpoint, marker, boot, and continuation are present in the session. Committed resets are checked at the next turn start or final settlement. `plugins/pi/reset/committed.ts` confirms an ordered hidden boot/continuation after a checkpoint-backed marker even when later conversation exists. That is distinct from `inspectResetTail`, which refuses suffix repair after real work or malformed ordering. Uncommitted reset drafts never announce success. Boot and continuation messages retain `display: false`.
|
|
60
60
|
|
|
61
|
-
The Pi history adapter supplies the selected raw session branch on demand without a cache. Its shared wire decoder allocates stable seq values from the session's append-order entry list, then selects current-branch-only visibility, so navigation cannot expose a sibling's history. Shared history pairs and queries those decoded events; it neither traverses SessionReader nor reconstructs inference messages. Optional `session` targeting uses a lazy `HistoryContext`/`HistoryCorpus`; filesystem-only Pi/Claude/Codex wire decoders are shared under `src/history/`, while DSH contributes descriptors through its native query service. Omitted `session` retains the original result/header/recipe shapes; explicit selectors carry canonical session identity throughout, and wildcard search merges hits chronologically without cross-session seq cursors. See [cross-session history](history-sessions.md). The public stream combines each tool call with its result at the call seq; paired result slots are not public event addresses, and unpaired results retain their own seq. Summaries and injected messages project as `context`. List pages chronologically
|
|
61
|
+
The Pi history adapter supplies the selected raw session branch on demand without a cache. Its shared wire decoder allocates stable seq values from the session's append-order entry list, then selects current-branch-only visibility, so navigation cannot expose a sibling's history. Shared history pairs and queries those decoded events; it neither traverses SessionReader nor reconstructs inference messages. Optional `session` targeting uses a lazy `HistoryContext`/`HistoryCorpus`; filesystem-only Pi/Claude/Codex wire decoders are shared under `src/history/`, while DSH contributes descriptors through its native query service. Omitted `session` retains the original result/header/recipe shapes; explicit selectors carry canonical session identity throughout, and wildcard search merges hits chronologically without cross-session seq cursors. See [cross-session history](history-sessions.md). The public stream combines each tool call with its result at the call seq; paired result slots are not public event addresses, and unpaired results retain their own seq. Summaries and injected messages project as `context`. List pages chronologically using exclusive `after` and `before` seq or time bounds. The tool layer normalizes the bounds and query; history selection pages and expands hits with their neighboring events. Tool executions retain structured call/result facts and any native nested-call metadata. A deterministic event document supplies both query-match positions and read windows. Nested calls have no independent seq and never imply that unrecorded child outputs are available.
|
|
62
62
|
|
|
63
63
|
The boot notes index in `boot/snapshot.ts` is a closed snapshot: the current session, project, human, agent, and model notebooks are each loaded at most once while constructing a boot. `boot/snapshot.ts` takes explicit `NotesIdentity`, captured `openedAt` and an optional notebook loader; `boot/render.ts` renders that snapshot and explicit tool bindings without reading the filesystem or consulting the clock. Pi supplies its unchanged tool names. MAP bodies and pocket metadata are derived from the same snapshot, so a boot cannot mix two filesystem reads. Note storage and notebook traversal use `node:fs/promises`; same-file operations queue by absolute physical filename across store instances in this process, without promising symlink/case-alias or cross-process locking. Known persisted metadata is camelCase. Old snake_case keys are unrecognized extras, not interpreted or migrated; startup does not migrate notes. A missing notebook (`ENOENT`) is normal. A real read failure omits only that notebook's index, preserves healthy notebooks, adds a model-facing `notes_list` recovery notice, and notifies the human once for that window. Boot/reset construction captures session, agent, and model identity before awaiting the snapshot, then checks lifecycle generation, active window, enabled state, and abort status before sending or returning artifacts; stale completions cannot commit into a switched or shut-down session. Boot acquisition uses listing and never updates access metadata. Explicit note reads update `lastAccessed` and `accessCount`; no fallback state is created.
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ Notes remain in their filesystem-backed notebooks, unchanged by session branch n
|
|
|
66
66
|
|
|
67
67
|
Every notes tool accepts an optional per-call `cwd`. The host adapter supplies a `NotesToolContext` containing its base cwd and default `NotesIdentity`; shared tool code resolves a relative override against that base, requires an existing directory, and derives one override `projectKey` through the existing project resolver. Storage, addresses, globs, receipts, and new session-note ownership all consume that same resolved identity. The override neither mutates the context nor changes `NotesIdentity.home`; the standalone store still receives explicit identities and has no cwd-discovery behavior. Dream markers survive resolution, so an override cannot widen dream write permission.
|
|
68
68
|
|
|
69
|
-
Notes/history operations return schema-derived `Outcome<T>` values, not host `content` objects. One bounded candidate is measured against both its complete structured serialization and its text renderer. Pi registers the outcome schema and packages that same value as `structuredContent`, derives `isError` from it and puts rendered text in `content`. Claude uses the same operations and renderers. Neither adapter parses text or independently chooses a page. Read continuation hints follow Pi's native trailing-notice style and are not part of the addressed text. See [tool results](tool-results.md) for the breaking protocol and coordinate contract.
|
|
69
|
+
`notes_list` uses one schema and renderer for browse rows and query hits. Notes/history operations return schema-derived `Outcome<T>` values, not host `content` objects. One bounded candidate is measured against both its complete structured serialization and its text renderer. Pi registers the outcome schema and packages that same value as `structuredContent`, derives `isError` from it and puts rendered text in `content`. Claude uses the same operations and renderers. Neither adapter parses text or independently chooses a page. Read continuation hints follow Pi's native trailing-notice style and are not part of the addressed text. See [tool results](tool-results.md) for the breaking protocol and coordinate contract.
|
|
70
70
|
|
|
71
71
|
The `/fresh-window` command only waits for idle when the session is busy with non-agent work; during model output it arms the close-out and steers the checkpoint prompt into the running turn. While enabled, `/compact` is cancelled with an actionable `/fresh-window` notice. Disabling notesoup stops new automatic resets, but an existing native checkpoint/marker still excludes earlier history and native compaction is still cancelled on that marked branch; a fresh root may use native Pi semantics. Threshold and warning accounting use active-window provider usage rather than pre-reset global usage. Pre-send hard-reserve checks estimate the complete projected transcript, including real system sections and tool declarations; native provider usage remains authoritative once available, and post-checkpoint unknown usage stays unknown. Budget policy and staged prompts are instance-owned, so concurrent sessions cannot share reserve/enablement or uncommitted drafts; default file-backed policy is cached per instance, while injected policy is resolved live on each decision and model/session transitions reset the diagnostic lifecycle.
|
|
72
72
|
|
package/docs/claude-code-mod.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Claude Code Mod
|
|
2
2
|
|
|
3
|
-
The package also ships `plugins/claude/`, an early-access Claude Code Mod that registers
|
|
3
|
+
The package also ships `plugins/claude/`, an early-access Claude Code Mod that registers four notes tools as `mcp__notesoup__notes_*`, two history tools as `mcp__notesoup__history_*`, and `mcp__notesoup__empty_brain` and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `plugins/claude/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
|
|
4
4
|
|
|
5
5
|
Warning and automatic clear use one budget policy. The existing warning and reset points are derived from Claude's own auto-compact threshold instead of a fixed percent, in `plugins/claude/src/thresholds.ts`, and reach the sandboxed hooks module through the helper's `limits` operation. At the hard point, the next main `turn.step` ends the old turn after its whole tool batch; a successful main `turn.complete` also checks the point when no request is already pending. Both enter the existing non-held reset worker, without a separate cap-specific trigger. Measurement alone never clears context, child events cannot reset the main brain, and aborted/error/refusal turns do not commit a budget reset. The policy resolves its native point as follows:
|
|
6
6
|
|
|
@@ -30,7 +30,7 @@ The notes tools also serve subagent calls, using the same session identity and s
|
|
|
30
30
|
|
|
31
31
|
## Persisted history
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
The [shared schemas and results](tool-results.md) apply here too: `notes_list` browses or searches with `query`; `history_list` uses `after` / `before` for paging and accepts `context` alongside a query. With `session` omitted they read the current main session's persisted JSONL, via the documented `classic.SessionStart.transcript_path`; no path is guessed and `$.session.messages()` is not treated as full history. The classic binding survives typed `session.start`, which fires later. Without that path, current-session history calls refuse and the boot says history is unavailable. Subagent history calls refuse rather than silently exposing the main transcript.
|
|
34
34
|
|
|
35
35
|
Explicit `session` selectors use the [local cross-harness corpus](history-sessions.md), including Pi/Claude/Codex files, without needing the current main transcript to have a head yet. Explicitly selecting the current Claude session still uses its strict live binding. Offline Claude targets prefer non-attachment graph leaves when available, then select the last remaining leaf in transcript order; no leaves still refuses. The persisted Claude decoder is shared under `src/history/claude.ts`; its plugin entry remains in `plugins/claude/src/history.ts`.
|
|
36
36
|
|
package/docs/codex.md
CHANGED
|
@@ -37,7 +37,7 @@ Keep the forms separate: `token_budget` is a table here, so do not also write `t
|
|
|
37
37
|
|
|
38
38
|
- **A boot per native window.** The `SessionStart` hook reads the thread's native rollout, binds the thread to this Codex root session, cwd, model, transcript and current window, and returns the shared notes boot with a window marker. The boot is deduped by the host's own persisted `hooks.additional_context` record for that exact thread and window, never by a quoted marker. A compact creates a new native window and therefore a fresh boot.
|
|
39
39
|
- **Codex's `new_context` and `get_context_remaining`.** They remain Codex's tools. notesoup has no MCP reset or budget fallback, and an MCP call cannot trigger a reset.
|
|
40
|
-
- **Five notebooks** through `notes_write`, `notes_update`, `notes_read
|
|
40
|
+
- **Five notebooks** through `notes_write`, `notes_update`, `notes_read` and `notes_list` (add `query` to search). `NOTESOUP_HOME` overrides the root (default `~/.agents/notes`); a root thread's agent name is `NOTESOUP_AGENT` or `anonymous`.
|
|
41
41
|
- **Native history** through `history_list` and `history_read`: the root thread's events and a child's own ancestry, addressed by stable session-wide seqs. The boot's window tree retains native window UUIDs for orientation. Optional `session` targets other local sessions/harnesses, and `history_list` accepts `session: "*"` with a query for cross-session search; see [cross-session history](history-sessions.md).
|
|
42
42
|
- **Per-turn model identity.** `@model` follows the current turn's `x-codex-turn-metadata.model`, not the model recorded at thread start. The start model only labels the boot.
|
|
43
43
|
- **Subagents and forks.** `SubagentStart` binds the child or fork to its own transcript while keeping the parent's root session. Its `@self` notebook is the slugged `agent_type` (for example `worker`), not the parent's.
|
package/docs/dsh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DeepSeek Harness adapter
|
|
2
2
|
|
|
3
|
-
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh page when context runs low: frozen boot text, the five notebooks,
|
|
3
|
+
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh page when context runs low: frozen boot text, the five notebooks, six notes/history tools, `get_context_remaining`, and `empty_brain`. A reset makes **zero model calls**. The old conversation leaves the model surface and remains in the session log for history reads. `notes_list` browses the notebooks or returns match lines and offsets when given `query`. Dream is not registered on dsh.
|
|
4
4
|
|
|
5
5
|
Install the package in your chosen dsh profile with `dsh plugin --profile <profile> add notesoup`, then copy the model declaration from [the profile patch example](dsh.profile.patch.yml) into `$DSH_HOME/profiles/<profile>/cordis.patch.yml`. The package bundle patch disables `compaction-basic` and inserts `notesoup-engine` and `notesoup`. Do not duplicate those rows when adding the model declaration. A source checkout needs `npm ci --ignore-scripts` and `npm run build`; use absolute `file:///.../dist/plugins/dsh/engine.js` and `file:///.../dist/plugins/dsh/index.js` module names. The example shows all rows for a profile assembled without the package bundle.
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ On load and before requests, preflight probes `systemPrompt.section`, `tools.reg
|
|
|
14
14
|
|
|
15
15
|
The boot is a `systemPrompt.section` at order **2450**, with `interpolate: false`. Shared snapshot/render functions read the five notebooks once, using a captured timestamp. Rendering is deterministic for those inputs. A `plugin:notesoup/window` record stores the ordinal, id, timestamp, digest and exact boot text. `agent/created` adopts it before the first assembly. Notes written later appear in the next window's boot. Missing records reconstruct from the notesoup compact checkpoint, or from the marked root system section. Neither path rereads notes or regenerates a summary. Records are informational; checkpoints control the model surface.
|
|
16
16
|
|
|
17
|
-
`history_list` and `history_read` obtain the full raw log through `ctx.sessionQuery.readSession`, then feed the shared pairing, paging and literal
|
|
17
|
+
`history_list` and `history_read` obtain the full raw log through `ctx.sessionQuery.readSession`, then feed the shared pairing, `after` / `before` paging and literal search with optional `context` around hits. Public history seq **1** is native dsh seq **0**; always use the seq a notesoup tool returns. A fork's selected seed prefix is available in its history; no sibling or parent suffix is fetched. Tool results are paired at their call seq. Text blocks are verbatim; other recorded blocks are shown as JSON. Omit `session` to browse the current session. Explicit `session: "dsh:<id-or-prefix>"` resolves through `ctx.sessionQuery.listSessions()` and reads with `readSession`; `session: "*"` with a query also searches the Pi/Claude/Codex local-file corpus. DSH service-backed discovery is available only inside DSH. All hits and continuation recipes retain their canonical session identity; see [cross-session history](history-sessions.md).
|
|
18
18
|
|
|
19
19
|
## Reset and budget
|
|
20
20
|
|
package/docs/history-sessions.md
CHANGED
|
@@ -15,7 +15,7 @@ history_read({ session: "claude:full-session-id", seq: 42 })
|
|
|
15
15
|
|
|
16
16
|
Within the requested harness an exact ID wins over prefixes. Without a harness, resolution checks the current harness first (exact ID, then prefixes); only if it has no matches are the other harnesses checked. No match returns `unknown_session`. Multiple matches return `ambiguous_session` with up to five qualified candidates; specify a harness or a longer ID rather than guessing.
|
|
17
17
|
|
|
18
|
-
Explicit targeting always returns the canonical `session: "<harness>:<full-id>"`, even when the target
|
|
18
|
+
Explicit targeting always returns the canonical `session: "<harness>:<full-id>"`, even when the target is the current session. Headers become `session <harness>:<id> | seq <seq> | <role>`. Copy that session into `history_read` and any continuation reads. Paging, `expand` and `neighborhood` recipes already carry it. Structured pages expose `has_older` and `has_newer`; use the first or last non-context row's seq as `before` or `after`, respectively. For example: `→ newer: {"session":"<harness>:<full-id>","after":42}`. An `after` bound pages forward; otherwise the page starts at the newest eligible end. See [tool results](tool-results.md#bounds-and-continuation) for query context and bounds.
|
|
19
19
|
|
|
20
20
|
## Browse or search across sessions
|
|
21
21
|
|
|
@@ -24,16 +24,15 @@ Any selector containing `*` selects multiple sessions; `*` matches any string an
|
|
|
24
24
|
```js
|
|
25
25
|
history_list({ session: "*" }) // Recent sessions, one opening prompt/topic each
|
|
26
26
|
history_list({ session: "*", query: ["deployment", "rollback"], limit: 20 })
|
|
27
|
-
history_list({ session: "codex:*", query: "migration", roles: ["tool"],
|
|
27
|
+
history_list({ session: "codex:*", query: "migration", roles: ["tool"], after: "2026-10-01", context: 1 })
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
- With a non-empty `query`, matching is literal, case-insensitive, and ORs a list of texts, as in one-session search. Local files are conservatively pre-filtered before full decoding: JSON escapes, Unicode case folding, generated event text and inherited Codex history must not lose hits. Uncertain cases use the full decoder. A possible hit in a Pi or Claude file stops the prefilter early: the strict decoder will read and validate the file next.
|
|
31
|
-
- Without
|
|
32
|
-
-
|
|
33
|
-
- `history_read` refuses wildcard selectors with `invalid_session`; take a specific `session` and `seq` from
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
- Search hits are merged by event time, oldest first, with a deterministic session/seq tie-break; untimed events sort before timed events. For query searches, `limit` counts from the newest event end by default, or the oldest with `from: "oldest"`. The complete text and structured result still share the 32 KiB budget, so large previews can reduce the admitted page.
|
|
31
|
+
- Without a non-empty `query`, return a recent-sessions overview. Consider sessions newest-modified first, or oldest-modified first with `after`; stop loading once `limit` sessions (default 20) produce a representative. Apply `roles`, `after` and `before` before choosing a representative. Without roles, prefer the first visible user event, falling back to the latest visible assistant event or the latest event of any role. With roles, choose the latest matching visible event. Return the representatives oldest first by event time.
|
|
32
|
+
- Wildcard bounds take only ISO 8601 times, both exclusive. Seqs from different sessions cannot define a common range. Time bounds exclude events with no usable timestamp.
|
|
33
|
+
- `history_read` refuses wildcard selectors with `invalid_session`; take a specific `session` and `seq` from the result instead.
|
|
34
|
+
- A query searches all roles, including tool arguments/output and injected context; `roles` can narrow the hits. `context: N` includes up to N neighbors on each side from the hit’s own session, even outside the hit bounds. There are no folded rows.
|
|
35
|
+
- Hits and context are merged oldest first by event time, with a deterministic session/seq tie-break; untimed events sort first. `limit` counts hits from the newest end by default or from the oldest end with `after`. The complete text and structured result still share the 32 KiB budget.
|
|
37
36
|
- Each event carries its canonical `session`. `has_older` and `has_newer` indicate more matching results beyond the page; an overview with unvisited sessions may have more even if those sessions have no representative. Narrow by session pattern, query, roles or time rather than trying to page across per-session seqs.
|
|
38
37
|
|
|
39
38
|
## Local discovery and limits
|
|
@@ -51,7 +50,7 @@ The default roots respect `PI_CODING_AGENT_DIR` (Pi agent directory), `CLAUDE_CO
|
|
|
51
50
|
|
|
52
51
|
## Strict recent-session cache
|
|
53
52
|
|
|
54
|
-
Only an unfiltered wildcard overview uses the persistent offline representative cache: no nonempty query and no `roles`, `
|
|
53
|
+
Only an unfiltered wildcard overview uses the persistent offline representative cache: no nonempty query and no `roles`, `after`, or `before`. Empty queries still mean an overview. Explicit session reads/lists, searches, filtered overviews, DSH service descriptors and the current live binding do not use this cache. Session discovery, modified-time ordering, representative ordering, output budgeting and full event-preview limits are unchanged.
|
|
55
54
|
|
|
56
55
|
A cold miss deliberately reads and strictly decodes the whole transcript, including selected Codex ancestry. It saves only the complete selected event, canonical session identity, notice and source metadata—not a projection, header-only approximation or full-text index. Entries are versioned with the decoder/selection contract; decoder or presentation changes must bump that version. The key includes the canonical root transcript path, harness and session ID. Every source has a `dev`/`ino`/size/nanosecond mtime/ctime fingerprint taken before reading and checked after decoding. Codex records the actual root and ancestor files, and cache hits re-run native lineage discovery so newly ambiguous or missing sources cannot be hidden by unchanged file fingerprints. The fingerprint list must exactly match the root and lineage witness list.
|
|
57
56
|
|
package/docs/notes-library.md
CHANGED
|
@@ -41,9 +41,9 @@ The standalone store does **not** accept `cwd`: its `projectKey` is already the
|
|
|
41
41
|
- `list({ glob?, crumpled? }?)` returns `Promise<NoteRow[]>`, sorted by update time descending with address tie-breaking. Rows contain address, scope, virtual path, metadata, body, and body byte size. Crumpled notes are excluded by default; `crumpled: true` returns only crumpled notes.
|
|
42
42
|
- `search(queries: string[], { glob?, crumpled? }?)` returns `Promise<NoteSearchRow[]>`, sorted by address, with the same selection and crumpled-note rules. Rows also carry body-budget `warnings`. An empty queries array returns matching notes with empty `matches`. Otherwise search is case-insensitive literal OR over body lines; matches contain one-based `line`, `text`, and code-point `offsetChars` into the body. Neither listing nor search increments access metadata.
|
|
43
43
|
|
|
44
|
-
`list` and `search` share `NotesQuery`: **glob is the only notebook/path selector**. Omit it
|
|
44
|
+
`list` and `search` share `NotesQuery`: **glob is the only notebook/path selector**. Omit it for the five current notebooks. Explicit `*` or `**` searches all notebooks, including other sessions, projects, agents and models (any pattern without `@` or `/` matches note filenames at any depth as `**/<pattern>`); `@sessions/*/**` selects all session notebooks. Use `@project/**`, `@self/**`, or `@projects/<name>/**` to select a notebook. The former `scope`/`who` query parameters are removed, without compatibility aliases. Row metadata still includes scope.
|
|
45
45
|
|
|
46
|
-
The library returns full data, not tool envelopes or paginated/truncated output. `NoteError` exposes the existing named store refusals through `code`, with `lineNumbers` for ambiguous edits and `editIndex` for a failed edit. Runtime API fields and known persisted note metadata use camelCase; Pi tool wire fields such as `updated_at`, `offset_chars`, and `replace_all` retain their established names. The notes partition status field is `NoteQueryStatus.namespacesUnavailable` in the library and `namespaces_unavailable` on the `notes_list
|
|
46
|
+
The library returns full data, not tool envelopes or paginated/truncated output. `NoteError` exposes the existing named store refusals through `code`, with `lineNumbers` for ambiguous edits and `editIndex` for a failed edit. Runtime API fields and known persisted note metadata use camelCase; Pi tool wire fields such as `updated_at`, `offset_chars`, and `replace_all` retain their established names. The notes partition status field is `NoteQueryStatus.namespacesUnavailable` in the library and `namespaces_unavailable` on the `notes_list` wire; both replace `NoteQueryStatus.homesUnavailable` and `homes_unavailable` with no compatibility alias, and the on-disk layout is unchanged. Unrecognized frontmatter keys, including old snake_case metadata, are preserved as ordinary extras; they are not interpreted as current camelCase fields or migrated automatically. Invalid addresses/identities and filesystem failures reject; only a missing `read` returns `undefined`. Notes remain markdown files with the existing size limits and same-directory atomic rename. Same-file read/modify/write work is serialized by absolute physical filename across all store instances in this process (including `.md` address aliases). Mutations additionally acquire notebook admission locks in stable order before file locks so concurrent stores cannot admit a sixth pin; reads/scans only acquire file locks. Symlink/case aliases and cross-process locking are not guaranteed. `list` and `search` asynchronously traverse notebooks and serialize each discovered file read against pending mutations, but are not global snapshots and may not discover a file created after traversal. Foreign named notebooks can be read, but their bodies cannot be written or edited through the store. Named project and session reads do not update access metadata. These are cooperative address rules, not an OS security sandbox.
|
|
47
47
|
|
|
48
48
|
Addresses are a relative path (a current-session note), `@project/`, `@human/`, `@self/`, `@model/`, or explicit `@projects/<slug>/`, `@sessions/<id>/`, `@agents/<slug>/` and `@models/<slug>/`. Named project and session addresses are read-only, including for rename sources and destinations. Session IDs use the same safe single-directory-component grammar as `NotesIdentity.sessionId`, not the agent/model slug grammar. Only the first character of an address is sigil-position: an unknown leading `@head` refuses, while `@` inside the path (`release@v1.md`, `@project/mail/alice@example.com.md`) is an ordinary character. Relative self/model addresses resolve to the supplied identity. Results show the current agent's and model's notes as `@self/` and `@model/`; only other agents' or models' notes carry an explicit `@agents/<slug>/` or `@models/<slug>/`. Globs accept either form. The disk layout remains `pi/session/<sessionId>/`, `project/<projectKey>/`, `human/`, `agents/<agent>/`, and `models/<model>/`. No data migration happens on library import or construction. Notes already using camelCase metadata retain their metadata; old snake_case keys are preserved as unrecognized extras, not interpreted or migrated. New session notes record the supplied project key.
|
|
49
49
|
|
|
@@ -58,7 +58,7 @@ Addresses are a relative path (a current-session note), `@project/`, `@human/`,
|
|
|
58
58
|
- Every physical notebook allows **5 live pins**, including existing default pages. Crumpled pins don't count. New pinning, writes that restore notes, explicit restores, and moves/renames all check admission and refuse with `pin_limit` before mutation if they would add a sixth pin. Same-notebook moves of an already-live pin don't consume another slot. Existing over-cap notes can still be edited, unpinned or crumpled. Boot defensively selects at most five pins, default-page-first then path order, visibly naming omitted pins in a manually over-cap notebook. Pinned bodies are injected whole, with budget warnings rather than truncation.
|
|
59
59
|
- `readonly: true` is a **soft lock**, not an authorization/security boundary. Existing locked notes refuse changes, overwrite, crumple/restore, rename/move, and dream deletion with `readonly`. Explicit `readonly: false` permits a metadata-only unlock or unlock plus the requested mutation in one call. A new/unlocked note may be written and locked together. Replacing a locked crumpled move target also requires explicit false. Reads/access counters still write, and filesystem edits can bypass the lock.
|
|
60
60
|
|
|
61
|
-
The
|
|
61
|
+
The four model tools accept the same policy options (write/update) and return effective policy visibly in receipts, read metadata and `notes_list` rows, alongside budget warnings. Notebook pin admission is serialized across stores **within this process**; manual edits and other processes are not locked by this cooperative API.
|
|
62
62
|
|
|
63
63
|
## Library and plugin boundary
|
|
64
64
|
|
package/docs/tool-results.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Notes and history tool results
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The six notes/history tools share one result model on Pi, Claude Code, Codex and Cordis. Pi exposes compact results as `structuredContent` to codemode and renders them as `content` for ordinary model calls. Host adapters use the same shared handlers and text rendering; they do not re-run a query or truncate a different page.
|
|
4
4
|
|
|
5
5
|
This is a breaking tool protocol change: successes no longer have `ok/data` wrappers, errors are flat, and read fields no longer sit under `window`. History execution details live once in the pageable document. Stored notes and raw Pi session entries are not deleted or rewritten by this change. In Pi, `get_context_remaining` independently declares `{ remaining_tokens }` as its output schema; `empty_brain` remains outside this protocol.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ This is a breaking tool protocol change: successes no longer have `ok/data` wrap
|
|
|
10
10
|
type Result<T> = T | { error: string; code: string };
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Each operation declares its concrete success schema; `error` is reserved for a refusal message. Success and expected failure both have a structured result; Pi's `isError` follows the outcome. Host-level argument validation, blocked execution and transport errors remain host failures. Shared handlers
|
|
13
|
+
Each operation declares its concrete success schema; `error` is reserved for a refusal message. Success and expected failure both have a structured result; Pi's `isError` follows the outcome. Host-level argument validation, blocked execution and transport errors remain host failures. Shared handlers return an internal `Outcome<T>` (`{ ok: true, data }` or `{ ok: false, error: { code, message } }`); this envelope is not the Pi wire result. The Claude hook returns rendered text as a string result and sets `isError: true` only on a refusal.
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
const result = await tools.notes_list({ glob: "@project/**" });
|
|
@@ -22,7 +22,7 @@ The text representation uses short mutation receipts, lists, search hits or raw
|
|
|
22
22
|
|
|
23
23
|
## Per-call project selection
|
|
24
24
|
|
|
25
|
-
All
|
|
25
|
+
All four notes tools accept optional `cwd`. Omitted means the host session's current project. A relative value resolves against the host session/binding cwd, and an existing directory is required; invalid explicit paths produce `invalid_cwd`. The override lasts one call and consistently drives `@project`, default/current-project globs, mutation endpoints, receipts, and new session-note ownership. It does not change the notes root or the physical session notebook.
|
|
26
26
|
|
|
27
27
|
## Read windows
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ The suffix and presentation header are never part of `text`, search offsets or t
|
|
|
55
55
|
|
|
56
56
|
The native adapter allocates seqs from session append order, selects the active branch and decodes facts. Shared history pairs calls and results without allocating a second transcript. A paired execution is addressed by its call seq. Its result's raw slot is not a public event address; list/search provide the canonical seq. Unpaired results remain independently addressable. Inactive-branch addresses are not readable.
|
|
57
57
|
|
|
58
|
-
Seqs address events across the whole session, including earlier windows. With `session` omitted, list and read headers use `seq <seq> | <role>`; the boot window tree supplies
|
|
58
|
+
Seqs address events across the whole session, including earlier windows. With `session` omitted, list and read headers use `seq <seq> | <role>`; the boot window tree supplies seq ranges for narrowing a list with `after` and `before`. With an explicit selector, returned events/read data carry canonical `session`, headers use `session <harness>:<id> | seq <seq> | <role>`, and all paging/expand/neighborhood recipes carry that same identity. Wildcards accept time bounds only, and report whether more results may exist beyond the page. See [cross-session history](history-sessions.md) for discovery, representative selection and refusal rules.
|
|
59
59
|
|
|
60
60
|
Tool events expose `tool`, `tool_status`, and, when recorded, `output_truncated` and `full_output_path`; a truncated run is named even when the host recorded no path, and the full text path is named only when it exists. `history_read` also reports `nested_calls`; a page row does not. Full arguments and nested-call records live only in the searchable/readable document, avoiding a second structured copy on every read.
|
|
61
61
|
|
|
@@ -67,13 +67,19 @@ Pi's nested records contain child ID, name, optional arguments, status, timing a
|
|
|
67
67
|
|
|
68
68
|
One selection determines the structured result and its text. Both complete representations must fit the 32 KiB output budget, including metadata, cursor and rendered notice. A programmatic caller does not receive an unbounded hidden payload beside a truncated textual one. History operations accept an optional pure text wrapper from the host: selection and read-window checks measure that wrapper around the shared rendering, and the caller must apply the same wrapper at delivery. Host prose stays in its plugin; no final clipping or separate query is involved.
|
|
69
69
|
|
|
70
|
-
`
|
|
70
|
+
`history_list` takes exclusive `after` and `before` bounds. Each accepts a seq (an integer or a digit-only string) or an ISO 8601 time (UTC when no offset is given). With `after`, `limit` counts forward (`after: 0` starts at the oldest event); without it, `limit` counts back from the newest eligible end. Both bounds define a range. Rows always come back oldest first.
|
|
71
|
+
|
|
72
|
+
With a non-empty `query`, `context: N` includes up to N events on each side of each hit, from the same session’s visible events. `after`, `before`, and `roles` limit hits, not their neighbors. Neighbor rows carry `context: true` and do not count toward `limit`; overlapping windows merge and the same output budget applies. History pages carry boolean `has_older` and `has_newer` flags. To page a single session, use the first non-context item's `seq` as `before` or the last non-context item's `seq` as `after`, with its `session` when present. Keep the search filters on the next call. Wildcard pages suggest narrowing by time, query, roles or session pattern instead. Only single-session browsing without roles folds tool/context runs.
|
|
73
|
+
|
|
74
|
+
`notes_list` with a non-empty `query` returns only matching notes and adds `matches` containing `line`, `text` and `offset_chars`, plus `more_matches` when lines are omitted. `max_matches_per_file` requires a query, as does history's `context`. Queries are literal and case-insensitive; a list matches any entry, ignoring empty entries. An empty or omitted query browses. Notes results are unpaged snapshots with a `more` count. Omit `glob` for current notebooks or supply a non-empty glob to narrow or widen the selection.
|
|
75
|
+
|
|
76
|
+
A history read can stop anywhere in the event document, including inside serialized arguments; concatenate its verbatim text slices before parsing any arguments.
|
|
71
77
|
|
|
72
78
|
`notes_write` and `notes_update` accept optional `pinned`, `budget`, and `readonly` policy fields. Their receipts, list/search rows, and read `metadata` expose the effective `pinned`, `budget`, and `readonly` values as structured fields **and visible text**. Successes also carry a `warnings` array (per file for list/search), rendered visibly when a body exceeds its budget: the default is 4096 Unicode code points for ordinary pages and 2048 for root `CHEATSHEET.md` and `MAP.md`, adjustable per note. Overflow saves successfully; boot injects full pinned bodies instead of cutting them. Pi's custom write/update/read renderers show policy and warnings even when collapsed, outside the expandable body/diff and clipped summary. A readonly note refuses mutations with `readonly` until explicitly unlocked with `readonly:false`; this is a soft lock, not security. Pin admission refuses a sixth live pin per notebook with `pin_limit`, including restore/move/rename. Invalid policy fields refuse with `invalid_policy`.
|
|
73
79
|
|
|
74
80
|
A note read reports unrecognized frontmatter under `metadata.extra`; a value too large to carry, or past the verbatim budget, is named in place as `[omitted: too large]` under its key rather than delivered in part, and the value itself stays in the note file. A rename receipt uses `address` for the destination and `rename_from` for the source; it has no duplicate `rename_to` field.
|
|
75
81
|
|
|
76
|
-
`output_too_large` is not one failure. Each operation's own message says what it means: a read that cannot deliver a single advancing character is refused rather than answered with an empty window, and a search result whose first match line cannot fit is cut to the longest prefix that does and ends with ` [truncated]`. `notes_update` returns a compact policy-bearing receipt plus any budget warning; Pi attaches the rendered diff under `details.diff` for the UI rather than repeating it in model-facing text or `structuredContent`. Narrowing helps only where a parameter genuinely reduces the selection — `glob` or `query`, `roles`, `limit`, `max_chars_per_item`,
|
|
82
|
+
`output_too_large` is not one failure. Each operation's own message says what it means: a read that cannot deliver a single advancing character is refused rather than answered with an empty window, and a search result whose first match line cannot fit is cut to the longest prefix that does and ends with ` [truncated]`. `notes_update` returns a compact policy-bearing receipt plus any budget warning; Pi attaches the rendered diff under `details.diff` for the UI rather than repeating it in model-facing text or `structuredContent`. Narrowing helps only where a parameter genuinely reduces the selection — `glob` or `query`, `roles`, `limit`, `max_chars_per_item`, or an `after`/`before` seq or time range — and cannot help a read whose own metadata is what overflows. History pages refuse with `page_too_large` for the same reason. Nothing is ever quietly delivered short: every other omission is reported on the successful result that carries it.
|
|
77
83
|
|
|
78
84
|
## Ownership
|
|
79
85
|
|