notesoup 0.48.0 → 0.49.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 +1 -1
- package/dist/src/boot/snapshot.js +10 -3
- package/dist/src/boot/text.js +1 -2
- package/dist/src/budget/constants.d.ts +2 -4
- package/dist/src/budget/constants.js +2 -4
- package/dist/src/budget/policy.d.ts +2 -2
- package/dist/src/budget/policy.js +3 -3
- package/dist/src/budget/text.js +1 -1
- package/dist/src/dsh/budget.js +1 -1
- package/dist/src/dsh/tools.js +1 -1
- package/dist/src/notes/address.js +0 -2
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/store.d.ts +4 -10
- package/dist/src/notes/store.js +42 -72
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +7 -8
- package/dist/src/pi/runtime.js +4 -3
- package/dist/src/tools/notes.js +8 -14
- package/dist/test/agent-loop.test.js +1 -1
- package/dist/test/boot.integration.test.js +10 -2
- package/dist/test/budget-settings.integration.test.js +6 -4
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/host-neutral.test.js +12 -0
- package/dist/test/model-facing-text.test.js +1 -1
- package/dist/test/notes-library.test.js +67 -10
- package/dist/test/notes.integration.test.js +9 -9
- package/dist/test/notes.test.js +46 -13
- package/dist/test/reset-lifecycle.test.js +23 -1
- package/docs/dsh.md +1 -1
- package/docs/notes-library.md +7 -7
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +51 -76
- package/package.json +1 -1
- package/src/boot/snapshot.ts +9 -3
- package/src/boot/text.ts +1 -2
- package/src/budget/constants.ts +2 -4
- package/src/budget/policy.ts +3 -3
- package/src/budget/text.ts +1 -1
- package/src/dsh/budget.ts +1 -1
- package/src/dsh/tools.ts +1 -1
- package/src/notes/address.ts +0 -1
- package/src/notes/errors.ts +1 -1
- package/src/notes/store.ts +41 -73
- package/src/pi/budget.ts +7 -8
- package/src/pi/runtime.ts +4 -3
- package/src/tools/notes.ts +8 -14
|
@@ -10,7 +10,7 @@ import { CLAUDE_WARNING_PROMPT, COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_C
|
|
|
10
10
|
* The reviewed Design text is what the model actually reads, so the golden copies below pin it
|
|
11
11
|
* character for character: an edit that drifts the wording has to change them too.
|
|
12
12
|
*/
|
|
13
|
-
const GOLDEN_GUIDANCE = `About {remaining} tokens left
|
|
13
|
+
const GOLDEN_GUIDANCE = `About {remaining} tokens of room left in your brain.
|
|
14
14
|
Your notes don't go anywhere — no wipe reaches the shelves. History has it too, already written down, though digging it back out is on you.
|
|
15
15
|
What lives only in this brain leaves with it.
|
|
16
16
|
A decent moment to put down where you are, while you still remember why.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import test from "node:test";
|
|
@@ -77,7 +77,7 @@ test("same-file read/modify/write operations serialize across stores and markdow
|
|
|
77
77
|
const before = (await notes.read("shared")).meta.accessCount;
|
|
78
78
|
const [readA, readB] = await Promise.all([notes.read("shared.md"), other.read("shared")]);
|
|
79
79
|
assert.ok(readA && readB);
|
|
80
|
-
assert.equal((await notes.list(
|
|
80
|
+
assert.equal((await notes.list())[0]?.meta.accessCount, before + 2, "parallel reads do not lose access-counter updates");
|
|
81
81
|
const file = join(home, "pi/session/session-a/shared.md");
|
|
82
82
|
const stableEdits = [{ oldText: "A", newText: "first" }];
|
|
83
83
|
const operation = notes.update("shared", stableEdits);
|
|
@@ -131,7 +131,7 @@ test("search offsets address the body and never move when access metadata grows"
|
|
|
131
131
|
// would shift by one character here, because the rewrite adds a digit to the frontmatter.
|
|
132
132
|
for (let read = 0; read < 12; read++)
|
|
133
133
|
await notes.read("counted.md");
|
|
134
|
-
assert.equal((await notes.list(
|
|
134
|
+
assert.equal((await notes.list()).find((row) => row.address === "counted.md").meta.accessCount, 12);
|
|
135
135
|
assert.equal(await offsetOf(), 0, "reads that rewrite access metadata do not move the match");
|
|
136
136
|
await notes.write("front.md", `---\nbig: ${"x".repeat(200)}\n---\n\nneedle later`);
|
|
137
137
|
const frontMatch = (await notes.search(["needle"])).find((row) => row.address === "front.md").matches[0];
|
|
@@ -145,15 +145,15 @@ test("invalid addressing and failed edits leave stored bytes untouched without p
|
|
|
145
145
|
const { home, context, notes } = fixture(t);
|
|
146
146
|
assert.throws(() => createNotesStore({ ...context, sessionId: "../escape" }));
|
|
147
147
|
await assert.rejects(() => notes.write("@project/../escape", "bad"), (error) => error instanceof NoteError && error.code === "invalid_address");
|
|
148
|
-
await assert.rejects(() => notes.list({
|
|
149
|
-
// The typed API disallows this; JavaScript callers must still receive a refusal.
|
|
150
|
-
// @ts-expect-error who cannot accompany project scope
|
|
151
|
-
await assert.rejects(() => notes.list({ scope: "project", who: "root" }), (error) => error instanceof NoteError && error.code === "invalid_scope");
|
|
148
|
+
await assert.rejects(() => notes.list({ glob: "@agents/../escape/**" }));
|
|
152
149
|
await notes.write("edit", "alpha\nbeta\nbeta");
|
|
153
150
|
const path = join(home, "pi/session/session-a/edit.md");
|
|
154
151
|
const before = readFileSync(path, "utf8");
|
|
155
152
|
await assert.rejects(() => notes.update("edit", [{ oldText: "beta", newText: "B" }]), (error) => error instanceof NoteError && error.code === "ambiguous_edit" && error.lineNumbers?.join(",") === "2,3");
|
|
156
153
|
await assert.rejects(() => notes.update("edit", [{ oldText: "alpha", newText: "A" }, { oldText: "absent", newText: "X" }]), (error) => error instanceof NoteError && error.code === "no_match" && error.editIndex === 1);
|
|
154
|
+
await assert.rejects(() => notes.update("edit", [{ oldText: "", newText: "X" }]), (error) => error instanceof NoteError && error.code === "invalid_edit");
|
|
155
|
+
// @ts-expect-error malformed JavaScript callers receive a parameter error, not no_match
|
|
156
|
+
await assert.rejects(() => notes.update("edit", [{ oldText: "alpha", newText: 5 }]), (error) => error instanceof NoteError && error.code === "invalid_edit");
|
|
157
157
|
assert.equal(readFileSync(path, "utf8"), before);
|
|
158
158
|
await assert.rejects(() => notes.update("absent", undefined, { crumpled: true }), (error) => error instanceof NoteError && error.code === "not_found");
|
|
159
159
|
await notes.update("edit", [{ oldText: "alpha", newText: "A" }]);
|
|
@@ -183,11 +183,68 @@ test("rename moves a note with metadata intact across scopes and refuses live ta
|
|
|
183
183
|
const replaced = await notes.rename("still-back.md", "occupied.md");
|
|
184
184
|
assert.equal(replaced.replacedCrumpledTarget, true, "a crumpled target is replaced");
|
|
185
185
|
assert.equal((await notes.read("occupied.md"))?.meta.createdAt, written.meta.createdAt, "the moved note keeps its identity, not the target's");
|
|
186
|
-
|
|
186
|
+
const beforeAlias = (await notes.read("occupied")).meta.updatedAt;
|
|
187
|
+
assert.equal((await notes.rename("occupied", "occupied.md")).meta.updatedAt, beforeAlias, "a same-file move is a successful no-op");
|
|
187
188
|
await assert.rejects(() => notes.rename("occupied.md", "@models/other-model/stolen.md"), (error) => error instanceof NoteError && error.code === "invalid_scope");
|
|
188
189
|
await assert.rejects(() => notes.rename("@agents/someone-else/private.md", "mine.md"), (error) => error instanceof NoteError && error.code === "invalid_scope");
|
|
189
190
|
await assert.rejects(() => notes.rename("absent.md", "anywhere.md"), (error) => error instanceof NoteError && error.code === "not_found");
|
|
190
191
|
});
|
|
192
|
+
test("combined moves validate everything before saving either endpoint", async (t) => {
|
|
193
|
+
const { home, notes } = fixture(t);
|
|
194
|
+
await notes.write("source", "alpha alpha", { origin: "user" });
|
|
195
|
+
await notes.write("target", "keep me");
|
|
196
|
+
const sourcePath = join(home, "pi/session/session-a/source.md");
|
|
197
|
+
const targetPath = join(home, "pi/session/session-a/target.md");
|
|
198
|
+
const sourceBefore = readFileSync(sourcePath, "utf8");
|
|
199
|
+
const targetBefore = readFileSync(targetPath, "utf8");
|
|
200
|
+
await assert.rejects(() => notes.update("source", [{ oldText: "alpha", newText: "A" }], { replaceAll: true, renameTo: "target" }), (error) => error instanceof NoteError && error.code === "already_exists");
|
|
201
|
+
await notes.update("target", undefined, { crumpled: true });
|
|
202
|
+
const crumpledBefore = readFileSync(targetPath, "utf8");
|
|
203
|
+
await assert.rejects(() => notes.update("source", [{ oldText: "missing", newText: "A" }], { renameTo: "target", origin: "external", crumpled: false }), (error) => error instanceof NoteError && error.code === "no_match");
|
|
204
|
+
assert.equal(readFileSync(sourcePath, "utf8"), sourceBefore);
|
|
205
|
+
assert.notEqual(crumpledBefore, targetBefore);
|
|
206
|
+
assert.equal(readFileSync(targetPath, "utf8"), crumpledBefore, "a failed edit does not consume a crumpled destination");
|
|
207
|
+
const result = await notes.update("source", [{ oldText: "alpha", newText: "A" }], { renameTo: "@project/moved", replaceAll: true, origin: "external", crumpled: true });
|
|
208
|
+
assert.equal(result.moved, true);
|
|
209
|
+
assert.equal(result.meta.origin, "external");
|
|
210
|
+
assert.ok(result.meta.crumpledAt);
|
|
211
|
+
assert.equal(result.meta.project, undefined);
|
|
212
|
+
assert.equal(existsSync(sourcePath), false);
|
|
213
|
+
assert.equal((await notes.read("@project/moved")).body, "A A");
|
|
214
|
+
const same = await notes.update("@project/moved", [{ oldText: "A A", newText: "B" }], { renameTo: "@project/moved.md", crumpled: false });
|
|
215
|
+
assert.equal(same.moved, false);
|
|
216
|
+
assert.equal(same.change.kind, "body");
|
|
217
|
+
assert.equal(same.meta.crumpledAt, undefined);
|
|
218
|
+
});
|
|
219
|
+
test("same-file case and directory aliases cannot delete a moved note", async (t) => {
|
|
220
|
+
const { home, notes } = fixture(t);
|
|
221
|
+
await notes.write("Mixed.md", "precious", { origin: "user" });
|
|
222
|
+
await notes.update("Mixed.md", undefined, { crumpled: true });
|
|
223
|
+
const directory = join(home, "pi/session/session-a");
|
|
224
|
+
symlinkSync(directory, join(directory, "linked"), "dir");
|
|
225
|
+
const result = await notes.update("Mixed.md", [{ oldText: "precious", newText: "saved" }], { renameTo: "linked/Mixed.md", crumpled: false });
|
|
226
|
+
assert.equal(result.moved, false);
|
|
227
|
+
assert.equal(result.replacedCrumpledTarget, false);
|
|
228
|
+
assert.equal((await notes.read("Mixed.md"))?.body, "saved");
|
|
229
|
+
assert.equal((await notes.read("linked/Mixed.md"))?.body, "saved");
|
|
230
|
+
// The host filesystem decides whether these two case spellings alias.
|
|
231
|
+
if (existsSync(join(directory, "mixed.md"))) {
|
|
232
|
+
await notes.update("Mixed.md", undefined, { crumpled: true });
|
|
233
|
+
const caseResult = await notes.update("Mixed.md", [{ oldText: "saved", newText: "still here" }], { renameTo: "mixed.md" });
|
|
234
|
+
assert.equal(caseResult.moved, false);
|
|
235
|
+
assert.equal((await notes.read("Mixed.md"))?.body, "still here");
|
|
236
|
+
assert.equal((await notes.read("mixed.md"))?.body, "still here");
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
test("glob is the single query selector for a named project home", async (t) => {
|
|
240
|
+
const { home, notes } = fixture(t);
|
|
241
|
+
mkdirSync(join(home, "project/other"), { recursive: true });
|
|
242
|
+
writeFileSync(join(home, "project/other/decision.md"), "needle");
|
|
243
|
+
const rows = await notes.list({ glob: "@projects/other/**" });
|
|
244
|
+
assert.deepEqual(rows.map(row => row.address), ["@projects/other/decision.md"]);
|
|
245
|
+
assert.equal((await notes.search(["needle"], { glob: "@projects/other/**" }))[0]?.matches[0]?.text, "needle");
|
|
246
|
+
await assert.rejects(() => notes.write(rows[0].address, "overwrite"), (error) => error instanceof NoteError && error.code === "invalid_scope", "named project queries do not grant writes");
|
|
247
|
+
});
|
|
191
248
|
test("ambiguous multiline anchors report each starting line", async (t) => {
|
|
192
249
|
const { notes } = fixture(t);
|
|
193
250
|
await notes.write("multiline", "a\nb\na\nb\na\nb");
|
|
@@ -219,10 +276,10 @@ test("one unreadable note is named without hiding its readable siblings", async
|
|
|
219
276
|
await notes.write("@project/bad.md", "bad body");
|
|
220
277
|
await notes.write("@project/good.md", "good body");
|
|
221
278
|
chmodSync(join(home, "project", "project-12345678", "bad.md"), 0o000);
|
|
222
|
-
const result = await notes.listWithStatus({
|
|
279
|
+
const result = await notes.listWithStatus({ glob: "@project/**" });
|
|
223
280
|
assert.deepEqual(result.rows.map((row) => row.address), ["@project/good.md"], "the readable sibling still lists");
|
|
224
281
|
assert.deepEqual(result.status.homesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
|
|
225
|
-
await assert.rejects(() => notes.list({
|
|
282
|
+
await assert.rejects(() => notes.list({ glob: "@project/**" }), (error) => error.code === "EACCES", "a caller that asked for no status still sees the failure");
|
|
226
283
|
});
|
|
227
284
|
test("a hand-written quoted numeric extra survives a rewrite as a string", async (t) => {
|
|
228
285
|
const { home, notes } = fixture(t);
|
|
@@ -135,26 +135,26 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
|
|
|
135
135
|
const captured = makeExtension(sm);
|
|
136
136
|
const ctx = context(sm);
|
|
137
137
|
await call(captured, "notes_write", { address: "journal.md", content: "log line" }, ctx);
|
|
138
|
-
const updatedBefore = (await listNotes(ctx
|
|
138
|
+
const updatedBefore = (await listNotes(ctx))[0].meta.updatedAt;
|
|
139
139
|
// metadata-only: content unchanged, and the recorded time is the original one
|
|
140
140
|
const markOnly = resultData(await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx));
|
|
141
141
|
assert.equal(markOnly.change_kind, "metadata");
|
|
142
142
|
assert.match(markOnly.diff, /^\+\s*\d+\s+crumpledAt: \d{4}-\d{2}-\d{2}T/m);
|
|
143
|
-
assert.deepEqual(await listNotes(ctx
|
|
144
|
-
const basket = (await listNotes(ctx, {
|
|
143
|
+
assert.deepEqual(await listNotes(ctx), [], "a crumpled note leaves the live list");
|
|
144
|
+
const basket = (await listNotes(ctx, { crumpled: true }))[0];
|
|
145
145
|
assert.ok(basket.meta.crumpledAt);
|
|
146
146
|
assert.equal(basket.meta.updatedAt, updatedBefore, "crumpling does not change updatedAt");
|
|
147
147
|
assert.equal(resultRead(await call(captured, "notes_read", { address: "journal.md" }, ctx)).content.endsWith("log line"), true, "read still reaches a crumpled note");
|
|
148
148
|
// re-crumpling keeps the first time; smoothing empties the basket
|
|
149
149
|
await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx);
|
|
150
|
-
assert.equal((await listNotes(ctx, {
|
|
150
|
+
assert.equal((await listNotes(ctx, { crumpled: true }))[0]?.meta.crumpledAt, basket.meta.crumpledAt);
|
|
151
151
|
await call(captured, "notes_update", { address: "journal.md", crumpled: false }, ctx);
|
|
152
|
-
assert.deepEqual(await listNotes(ctx, {
|
|
153
|
-
assert.equal((await listNotes(ctx
|
|
152
|
+
assert.deepEqual(await listNotes(ctx, { crumpled: true }), []);
|
|
153
|
+
assert.equal((await listNotes(ctx))[0]?.meta.crumpledAt, undefined);
|
|
154
154
|
// writing to a crumpled address always produces an uncrumpled note
|
|
155
155
|
await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx);
|
|
156
156
|
await call(captured, "notes_write", { address: "journal.md", content: "reopened" }, ctx);
|
|
157
|
-
assert.equal((await listNotes(ctx
|
|
157
|
+
assert.equal((await listNotes(ctx))[0]?.meta.crumpledAt, undefined, "writing always produces an uncrumpled note");
|
|
158
158
|
// metadata-only on a missing path is the typed not-found arm
|
|
159
159
|
const missing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
|
|
160
160
|
assert.equal(missing.code, "not_found");
|
|
@@ -162,10 +162,10 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
|
|
|
162
162
|
test("the filesystem notes loader treats an absent home as empty but surfaces a real directory read failure", async () => {
|
|
163
163
|
const sm = manager();
|
|
164
164
|
const ctx = context(sm);
|
|
165
|
-
assert.deepEqual(await listNotes(ctx, {
|
|
165
|
+
assert.deepEqual(await listNotes(ctx, { glob: "@human/**" }), [], "a home that has not been created is empty");
|
|
166
166
|
const blockedHome = scopeDir("human", ctx);
|
|
167
167
|
writeFileSync(blockedHome, "not a directory");
|
|
168
|
-
await assert.rejects(() => listNotes(ctx, {
|
|
168
|
+
await assert.rejects(() => listNotes(ctx, { glob: "@human/**" }), (error) => error.code === "ENOTDIR", "a non-ENOENT directory failure is not swallowed as an empty home");
|
|
169
169
|
});
|
|
170
170
|
test("boot note acquisition is one closed snapshot and isolates one or all failed homes", async () => {
|
|
171
171
|
const sm = manager();
|
package/dist/test/notes.test.js
CHANGED
|
@@ -13,7 +13,7 @@ import { join } from "node:path";
|
|
|
13
13
|
import test from "node:test";
|
|
14
14
|
import { Check } from "typebox/value";
|
|
15
15
|
import { parseNote } from "../src/notes/frontmatter.js";
|
|
16
|
-
import { projectKey } from "../src/notes/index.js";
|
|
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
19
|
import { notesList, notesSearch } from "../src/tools/notes.js";
|
|
@@ -163,7 +163,7 @@ test("session-note project ownership is per note, persistent across sessions, an
|
|
|
163
163
|
assert.equal(parseNote(readFileSync(physicalPath("session", "new-from-project-b.md", movedContext), "utf8")).meta.project, projectB, "only a newly-created session note uses the current project key");
|
|
164
164
|
await call(firstCaptured, "notes_write", { address: "@project/project-note.md", content: "project home note" }, movedContext);
|
|
165
165
|
assert.equal(parseNote(readFileSync(physicalPath("project", "project-note.md", movedContext), "utf8")).meta.project, undefined, "project-home notes do not receive session ownership metadata");
|
|
166
|
-
assert.equal((await listNotes(movedContext
|
|
166
|
+
assert.equal((await listNotes(movedContext)).filter(row => row.scope === "session").length, 2, "project ownership remains frontmatter, not a separate note");
|
|
167
167
|
});
|
|
168
168
|
test("linked git worktrees share the main checkout's project key", () => {
|
|
169
169
|
freshRoot();
|
|
@@ -204,7 +204,7 @@ legacy body`);
|
|
|
204
204
|
const parsed = parseNote(readFileSync(legacyFile, "utf8"), Date.parse("2026-02-01T00:00:00Z"));
|
|
205
205
|
assert.equal(parsed.meta.createdAt, Date.parse("2026-02-01T00:00:00Z"), "missing canonical timestamp takes the normal default");
|
|
206
206
|
assert.equal(parsed.meta.created_at, "2026-01-01T00:00:00.000+00:00", "unrecognized fields remain ordinary extras");
|
|
207
|
-
assert.equal((await listNotes(ctx
|
|
207
|
+
assert.equal((await listNotes(ctx))[0]?.address, "legacy.md");
|
|
208
208
|
assert.match(resultRead(await call(captured, "notes_read", { address: "legacy.md" }, ctx)).content, /legacy body$/);
|
|
209
209
|
await call(captured, "notes_update", { address: "legacy.md", edits: [{ oldText: "legacy body", newText: "edited body" }] }, ctx);
|
|
210
210
|
await call(captured, "notes_write", { address: "legacy.md", content: "overwritten body" }, ctx);
|
|
@@ -279,25 +279,28 @@ test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are n
|
|
|
279
279
|
const zero = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "zzz", newText: "y" }], replace_all: true }, ctx));
|
|
280
280
|
assert.match(zero.message, /edits\[0\]/, "replace_all with zero matches is the same zero-match error, not a silent no-op");
|
|
281
281
|
});
|
|
282
|
-
test("notes_update rename_to
|
|
282
|
+
test("notes_update combines rename_to with edits and metadata but protects live targets", async () => {
|
|
283
283
|
freshRoot();
|
|
284
284
|
const session = manager();
|
|
285
285
|
const captured = makeExtension(session);
|
|
286
286
|
const ctx = context(session);
|
|
287
287
|
await call(captured, "notes_write", { address: "move-me.md", content: "body" }, ctx);
|
|
288
|
-
const
|
|
289
|
-
assert.
|
|
288
|
+
const failed = resultError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
|
|
289
|
+
assert.equal(failed.code, "no_match", "a failed edit does not move the note");
|
|
290
290
|
await call(captured, "notes_write", { address: "occupied.md", content: "live target" }, ctx);
|
|
291
291
|
const conflict = resultError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "occupied.md" }, ctx));
|
|
292
292
|
assert.match(conflict.message, /occupied\.md/, "a live target refuses the move");
|
|
293
|
-
const renamed = resultData(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md" }, ctx));
|
|
293
|
+
const renamed = resultData(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md", edits: [{ oldText: "body", newText: "x" }], origin: "external", crumpled: true }, ctx));
|
|
294
294
|
assertReceiptIdentity(renamed, "moved.md", "session", ctx);
|
|
295
295
|
assert.equal(renamed.rename_from, "move-me.md");
|
|
296
296
|
assert.equal(renamed.change_kind, "moved");
|
|
297
297
|
assert.equal(renamed.address, "moved.md");
|
|
298
298
|
const gone = resultError(await call(captured, "notes_read", { address: "move-me.md" }, ctx));
|
|
299
299
|
assert.equal(gone.code, "not_found", "the old address is gone");
|
|
300
|
-
assert.equal(resultRead(await call(captured, "notes_read", { address: "moved.md" }, ctx)).content, "
|
|
300
|
+
assert.equal(resultRead(await call(captured, "notes_read", { address: "moved.md" }, ctx)).content, "x");
|
|
301
|
+
const movedMeta = (await listNotes(ctx, { crumpled: true }))[0].meta;
|
|
302
|
+
assert.equal(movedMeta.origin, "external");
|
|
303
|
+
assert.ok(movedMeta.crumpledAt);
|
|
301
304
|
// Empty filler values are not a combination: a model passing every parameter still gets its crumple.
|
|
302
305
|
const crumpled = resultData(await call(captured, "notes_update", { address: "moved.md", crumpled: true, edits: [], origin: "self", rename_to: "", replace_all: false }, ctx));
|
|
303
306
|
assert.equal(crumpled.address, "moved.md", "an empty rename_to is ignored as if omitted");
|
|
@@ -305,8 +308,8 @@ test("notes_update rename_to moves a note and refuses combinations and live targ
|
|
|
305
308
|
assert.equal(listedCrumpled.files.some((file) => file.address === "moved.md"), true, "the note was crumpled");
|
|
306
309
|
const fillerRename = resultData(await call(captured, "notes_update", { address: "moved.md", rename_to: "moved-again.md", edits: [], replace_all: false }, ctx));
|
|
307
310
|
assert.equal(fillerRename.address, "moved-again.md", "empty edits and replace_all: false ride along with a rename");
|
|
308
|
-
const realCombo =
|
|
309
|
-
assert.
|
|
311
|
+
const realCombo = resultData(await call(captured, "notes_update", { address: "moved-again.md", rename_to: "final.md", replace_all: true, crumpled: false }, ctx));
|
|
312
|
+
assert.equal(realCombo.address, "final.md", "replace_all is harmless without edits, and restoration can accompany the move");
|
|
310
313
|
});
|
|
311
314
|
test("write and update receipts distinguish outcomes and no-op edits", async () => {
|
|
312
315
|
freshRoot();
|
|
@@ -465,7 +468,7 @@ test("a read keeps its body window verbatim under the new presentation", async (
|
|
|
465
468
|
assert.equal(wholeText.endsWith("\n\n0123456789"), true, "a complete window carries no continuation footer");
|
|
466
469
|
assert.equal(wholeText.includes("more characters"), false);
|
|
467
470
|
});
|
|
468
|
-
test("@ addresses select one home,
|
|
471
|
+
test("@ addresses select one home, keep boundaries, and never fall back", async () => {
|
|
469
472
|
const root = freshRoot();
|
|
470
473
|
const session = manager();
|
|
471
474
|
const captured = makeExtension(session);
|
|
@@ -478,8 +481,38 @@ test("@ addresses select one home, reject illegal sigils, and never fall back",
|
|
|
478
481
|
assert.match(resultRead(await call(captured, "notes_read", { address: "same.md" }, ctx)).content, /session$/);
|
|
479
482
|
assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).code, "not_found");
|
|
480
483
|
assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /isn't a note address.*@project\/.*@human\//);
|
|
481
|
-
assert.equal(resultError(await call(captured, "notes_write", { address: "
|
|
482
|
-
assert.equal(
|
|
484
|
+
assert.equal(resultError(await call(captured, "notes_write", { address: "@glboal/same.md", content: "no" }, ctx)).code, "invalid_address", "an unknown leading head is still not a note address");
|
|
485
|
+
assert.equal(resultError(await call(captured, "notes_write", { address: "@project/../escape.md", content: "no" }, ctx)).code, "invalid_address", "traversal never hides behind a known head");
|
|
486
|
+
assert.equal(existsSync(join(root, "human", "escape.md")), false, "a refused address creates nothing anywhere");
|
|
487
|
+
});
|
|
488
|
+
test("interior @ in a note path round-trips through write, list, search, read, update and rename", async () => {
|
|
489
|
+
const root = freshRoot();
|
|
490
|
+
const session = manager();
|
|
491
|
+
const captured = makeExtension(session);
|
|
492
|
+
const ctx = context(session);
|
|
493
|
+
assertReceiptIdentity(resultData(await call(captured, "notes_write", { address: "release@v1.md", content: "release needle" }, ctx)), "release@v1.md", "session", ctx);
|
|
494
|
+
assertReceiptIdentity(resultData(await call(captured, "notes_write", { address: "@project/mail/alice@example.com.md", content: "mail needle" }, ctx)), "@project/mail/alice@example.com.md", "project", ctx);
|
|
495
|
+
assert.ok(existsSync(join(root, "pi", "session", session.getSessionId(), "release@v1.md")), "the session file keeps its interior @");
|
|
496
|
+
assert.ok(existsSync(physicalPath("project", "mail/alice@example.com.md", ctx)), "the project file keeps its interior @ inside a folder");
|
|
497
|
+
const listed = resultData(await call(captured, "notes_list", {}, ctx));
|
|
498
|
+
assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@project/mail/alice@example.com.md", "release@v1.md"], "both addresses list in canonical form");
|
|
499
|
+
const globbed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
|
|
500
|
+
assert.deepEqual(globbed.files.map((row) => row.address), ["@project/mail/alice@example.com.md"], "a home glob still narrows to that home");
|
|
501
|
+
const searched = resultData(await call(captured, "notes_search", { query: "needle" }, ctx));
|
|
502
|
+
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");
|
|
503
|
+
assert.match(resultRead(await call(captured, "notes_read", { address: "@project/mail/alice@example.com.md" }, ctx)).content, /mail needle$/);
|
|
504
|
+
await call(captured, "notes_update", { address: "release@v1.md", edits: [{ oldText: "release", newText: "shipped" }] }, ctx);
|
|
505
|
+
assert.match(resultRead(await call(captured, "notes_read", { address: "release@v1.md" }, ctx)).content, /shipped needle$/);
|
|
506
|
+
const store = createNotesStore(notesIdentityFromPi(ctx));
|
|
507
|
+
await store.rename("release@v1.md", "shipped@v2.md");
|
|
508
|
+
assert.match((await store.read("shipped@v2.md")).body, /shipped needle$/);
|
|
509
|
+
assert.equal(await store.read("release@v1.md"), undefined, "the rename leaves no old name behind");
|
|
510
|
+
// A file dropped on disk (before any address change) still lists and reads under its full address.
|
|
511
|
+
mkdirSync(join(root, "human"), { recursive: true });
|
|
512
|
+
writeFileSync(join(root, "human", "pre@existing.md"), "---\norigin: user\n---\n\nlegacy needle\n");
|
|
513
|
+
const legacy = resultData(await call(captured, "notes_list", { glob: "@human/**" }, ctx));
|
|
514
|
+
assert.deepEqual(legacy.files.map((row) => row.address), ["@human/pre@existing.md"]);
|
|
515
|
+
assert.match(resultRead(await call(captured, "notes_read", { address: "@human/pre@existing.md" }, ctx)).content, /legacy needle/);
|
|
483
516
|
});
|
|
484
517
|
test("Pi adapter defaults to anonymous agent identity", async () => {
|
|
485
518
|
const root = freshRoot();
|
|
@@ -3,6 +3,7 @@ import { mkdtempSync, rmSync } from "node:fs";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import test from "node:test";
|
|
6
|
+
import { Check } from "typebox/value";
|
|
6
7
|
import { SessionManager as Manager } from "@earendil-works/pi-coding-agent";
|
|
7
8
|
import notesoup from "../src/pi/extension.js";
|
|
8
9
|
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
@@ -80,7 +81,12 @@ function harness() {
|
|
|
80
81
|
// Pi 1.0 hands a tool the session context plus the nested-call surface; toolContext builds it.
|
|
81
82
|
return tool.execute("call", params, new AbortController().signal, () => { }, toolContext(ctx));
|
|
82
83
|
};
|
|
83
|
-
|
|
84
|
+
const toolParameters = (name) => {
|
|
85
|
+
const tool = tools.get(name);
|
|
86
|
+
assert.ok(tool, `${name} is registered`);
|
|
87
|
+
return tool.parameters;
|
|
88
|
+
};
|
|
89
|
+
return { sessionManager, handlers, sent, notices, emit, runCommand, callTool, toolParameters };
|
|
84
90
|
}
|
|
85
91
|
function resultEntries(results) {
|
|
86
92
|
let entries = [];
|
|
@@ -708,6 +714,9 @@ test("empty_brain trims the last word, refuses an oversized one, and a blank per
|
|
|
708
714
|
over.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
709
715
|
const refused = await over.callTool("empty_brain", { last_word: "x".repeat(MAX_LAST_WORD_CHARS + 1) });
|
|
710
716
|
assert.match(JSON.stringify(refused), /error/, "an oversized note is refused, not truncated");
|
|
717
|
+
assert.match(JSON.stringify(refused), new RegExp(`${MAX_LAST_WORD_CHARS + 1} characters`), "the refusal names the actual size and the limit");
|
|
718
|
+
const refusedAstral = await over.callTool("empty_brain", { last_word: "\u{1F41F}".repeat(MAX_LAST_WORD_CHARS + 1) });
|
|
719
|
+
assert.match(JSON.stringify(refusedAstral), new RegExp(`${MAX_LAST_WORD_CHARS + 1} characters`), "the guard counts code points, not UTF-16 units");
|
|
711
720
|
const untouched = resultEntries(await over.emit("turn_end", fakeBoundaryEvent()));
|
|
712
721
|
assert.equal(untouched.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a refused call requests no reset");
|
|
713
722
|
const h = harness();
|
|
@@ -716,6 +725,19 @@ test("empty_brain trims the last word, refuses an oversized one, and a blank per
|
|
|
716
725
|
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
717
726
|
assert.equal(boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a blank last word persists no entry");
|
|
718
727
|
});
|
|
728
|
+
test("empty_brain's schema admits whitespace-wrapped notes and leaves length to the handler", async () => {
|
|
729
|
+
const parameters = harness().toolParameters("empty_brain");
|
|
730
|
+
const padded = " ".repeat(300) + "x";
|
|
731
|
+
assert.equal(Check(parameters, { last_word: padded }), true, "300 spaces plus x is admitted by the schema");
|
|
732
|
+
assert.equal(Check(parameters, { last_word: "x".repeat(MAX_LAST_WORD_CHARS + 1) }), true, "the schema does not pre-empt the handler's code-point limit");
|
|
733
|
+
assert.equal(Check(parameters, { last_word: 42 }), false, "a genuine type violation is still refused by the schema");
|
|
734
|
+
const h = harness();
|
|
735
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
736
|
+
await h.callTool("empty_brain", { last_word: padded });
|
|
737
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
738
|
+
const lastWords = boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE);
|
|
739
|
+
assert.deepEqual(lastWords[0], { type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}x`, display: true }, "the handler records the trimmed note");
|
|
740
|
+
});
|
|
719
741
|
test("reset-control: a tool request carries its last word to the turn-end commit", () => {
|
|
720
742
|
const windowId = "pcw:test:window";
|
|
721
743
|
const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
package/docs/dsh.md
CHANGED
|
@@ -34,7 +34,7 @@ warning = reserve + 16384
|
|
|
34
34
|
reminder = reserve + reminderMarginTokens
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining`
|
|
37
|
+
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining` and the numeric reminder report room to resetAt: physical remaining minus reserve, clamped at zero. The warning runway is included. Missing model capacity returns null. A profile with no positive reset budget fails with `BUDGET_CONFIG` and the numbers to fix. No independent percentage cutoff is added by notesoup.
|
|
38
38
|
|
|
39
39
|
The adapter uses `tokenMeter.measure`, model context from `resolveModelInfo`, and the mounted engine's resolved `config`. Alpha.2 keeps an old provider-usage anchor across surface replacement; until the fresh window has a response, notesoup uses the meter's current `surfaceTokens` plus its public tool-schema estimator instead of that stale anchor.
|
|
40
40
|
|
package/docs/notes-library.md
CHANGED
|
@@ -32,18 +32,18 @@ const matches = await notes.search(["library"]);
|
|
|
32
32
|
|
|
33
33
|
`createNotesStore(identity)` snapshots the five required identity fields; changing the supplied object afterward does not retarget the store. It resolves `home` once, validates identity components, and creates no files until an operation needs to write. Create a new store to change identity. Multiple stores can use independent roots and identities without changing process environment.
|
|
34
34
|
|
|
35
|
-
- `write(address, content, { origin? }?)` returns `Promise<{ meta, outcome }>` (`created`, `overwritten` or `uncrumpled`).
|
|
35
|
+
- `write(address, content, { origin? }?)` returns `Promise<{ meta, outcome }>` (`created`, `overwritten` or `uncrumpled`). New notes default to origin `self`; overwriting preserves the existing origin unless explicitly supplied, creation time, project ownership, and unknown metadata, and always produces an uncrumpled note (it clears any `crumpledAt`).
|
|
36
36
|
- `read(address)` returns `Promise<{ meta, body, resolvedScope } | undefined>`. **Reads update** `lastAccessed` and `accessCount` on disk. The body is separate from metadata; the serialized frontmatter is not part of the read API.
|
|
37
|
-
- `update(address, edits?, { origin?, crumpled?, replaceAll? }?)` returns `Promise<{ meta, applied, resolvedScope, change }>`.
|
|
38
|
-
- `rename(fromAddress, toAddress)` returns `Promise<{ meta, replacedCrumpledTarget }>`.
|
|
39
|
-
- `list({ glob?,
|
|
40
|
-
- `search(queries: string[], { glob?,
|
|
37
|
+
- `update(address, edits?, { origin?, crumpled?, replaceAll?, renameTo? }?)` returns `Promise<{ meta, applied, resolvedScope, change, moved, replacedCrumpledTarget }>`. Body edits, origin, crumpled state and a move can be combined. Every edit, destination and size check passes before saving; a live target refuses with `already_exists`, while a crumpled target can be replaced. Cross-session moves update project ownership. Each replacement uses the evolving body in array order. `crumpled: true` keeps an existing `crumpledAt` or adds it; false removes it; omitted preserves it. `updatedAt` advances for body/origin changes and actual moves, not crumpling alone. `change` contains `{ kind, before, after }`, with kind `body`, `metadata` or `none`; a body edit that also changes metadata or moves includes the whole serialized file in its diff inputs. Moves lock both paths in stable order, atomically write the destination, then remove the source; this is not a crash-atomic two-file transaction.
|
|
38
|
+
- `rename(fromAddress, toAddress)` returns `Promise<{ meta, replacedCrumpledTarget }>`. It delegates to the same update path with `renameTo`, preserving metadata. A same-file destination, including a case or symlink alias resolved by the filesystem, applies accompanying edits without removing the source. An exact path alias needs only one lock.
|
|
39
|
+
- `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.
|
|
40
|
+
- `search(queries: string[], { glob?, crumpled? }?)` returns `Promise<NoteSearchRow[]>`, sorted by address, with the same selection and crumpled-note rules. 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.
|
|
41
41
|
|
|
42
|
-
`list` and `search` share
|
|
42
|
+
`list` and `search` share `NotesQuery`: **glob is the only home/path selector**. Omit it for the five current homes; use `@project/**`, `@self/**`, or `@projects/<name>/**` to select a home. The former `scope`/`who` query parameters are removed, without compatibility aliases. Row metadata still includes scope.
|
|
43
43
|
|
|
44
44
|
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. 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); symlink/case aliases and cross-process locking are not guaranteed. `list` and `search` asynchronously traverse homes 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 homes can be read (including the access-metadata update), but their bodies cannot be written or edited through the store. These are cooperative address rules, not an OS security sandbox.
|
|
45
45
|
|
|
46
|
-
Addresses are a path
|
|
46
|
+
Addresses are a relative path (a session note), `@project/`, `@human/`, `@self/`, `@model/`, or explicit `@agents/<slug>/` and `@models/<slug>/`. 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.
|
|
47
47
|
|
|
48
48
|
## Library and plugin boundary
|
|
49
49
|
|