notesoup 0.39.0 โ†’ 0.40.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.
Files changed (53) hide show
  1. package/README.md +5 -2
  2. package/dist/src/boot/render.js +2 -2
  3. package/dist/src/boot/text.d.ts +0 -4
  4. package/dist/src/boot/text.js +9 -13
  5. package/dist/src/history/history.d.ts +23 -18
  6. package/dist/src/history/history.js +37 -20
  7. package/dist/src/history/query.d.ts +37 -49
  8. package/dist/src/history/query.js +114 -56
  9. package/dist/src/notes/store.d.ts +3 -4
  10. package/dist/src/notes/store.js +12 -16
  11. package/dist/src/pi/history-tools.d.ts +1 -1
  12. package/dist/src/pi/history-tools.js +2 -3
  13. package/dist/src/pi/runtime.js +1 -1
  14. package/dist/src/pi/tool-names.d.ts +0 -4
  15. package/dist/src/pi/tool-names.js +0 -4
  16. package/dist/src/tools/history.d.ts +24 -33
  17. package/dist/src/tools/history.js +57 -98
  18. package/dist/src/tools/notes.d.ts +26 -58
  19. package/dist/src/tools/notes.js +85 -103
  20. package/dist/src/tools/result.d.ts +16 -13
  21. package/dist/src/tools/result.js +24 -50
  22. package/dist/src/tools/schema.d.ts +2 -2
  23. package/dist/src/tools/schema.js +3 -3
  24. package/dist/test/agent-loop.test.js +1 -1
  25. package/dist/test/boot.integration.test.js +1 -1
  26. package/dist/test/claude-mod.test.js +4 -4
  27. package/dist/test/dependencies.test.js +1 -1
  28. package/dist/test/helpers/extension.js +2 -3
  29. package/dist/test/history.integration.test.js +200 -123
  30. package/dist/test/host-neutral.test.js +32 -58
  31. package/dist/test/notes-library.test.js +8 -8
  32. package/dist/test/notes.integration.test.js +75 -57
  33. package/dist/test/notes.test.js +44 -42
  34. package/docs/architecture.md +3 -3
  35. package/docs/notes-library.md +6 -6
  36. package/docs/tool-results.md +15 -25
  37. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  38. package/mods/notesoup/dist/claude/helper.js +119 -178
  39. package/mods/notesoup/hooks/register.ts +1 -2
  40. package/package.json +1 -1
  41. package/skills/memory/SKILL.md +6 -6
  42. package/src/boot/render.ts +2 -2
  43. package/src/boot/text.ts +9 -17
  44. package/src/history/history.ts +36 -20
  45. package/src/history/query.ts +130 -55
  46. package/src/notes/store.ts +15 -18
  47. package/src/pi/history-tools.ts +2 -3
  48. package/src/pi/runtime.ts +1 -1
  49. package/src/pi/tool-names.ts +0 -4
  50. package/src/tools/history.ts +61 -100
  51. package/src/tools/notes.ts +84 -97
  52. package/src/tools/result.ts +24 -49
  53. package/src/tools/schema.ts +3 -3
@@ -10,10 +10,10 @@ import { renderBootBlock } from "../src/boot/render.js";
10
10
  import { HistoryPageItemSchema, HistoryRoleSchema, projectHistory } from "../src/history/history.js";
11
11
  import { createNotesStore } from "../src/notes/store.js";
12
12
  import { notesWrite, notesUpdate, notesRead } from "../src/tools/notes.js";
13
- import { historyWindows, historyList, historyRead, historySearch } from "../src/tools/history.js";
13
+ import { historyWindows, historyList, historyRead } from "../src/tools/history.js";
14
14
  import { historyRoles } from "../src/tools/schema.js";
15
15
  import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
16
- import { ERROR_DETAILS_MAX_BYTES, ERROR_MESSAGE_MAX_CHARS, failure, fitsResult, resultSchema, wireResult, readTextWindow, renderOutcome, renderTextWindow, success, structuredBytes, } from "../src/tools/result.js";
16
+ import { ERROR_MESSAGE_MAX_CHARS, failure, fitsResult, resultSchema, wireResult, readTextWindow, renderOutcome, renderTextWindow, success, structuredBytes, } from "../src/tools/result.js";
17
17
  function identity(t) {
18
18
  const home = mkdtempSync(join(tmpdir(), "host-neutral-notes-"));
19
19
  t.after(() => rmSync(home, { recursive: true, force: true }));
@@ -44,47 +44,42 @@ test("shared boot uses only explicit identity, loader, captured time and logical
44
44
  });
45
45
  assert.deepEqual(scopes, ["session", "project", "human", "agent", "model"]);
46
46
  assert.equal(snapshot.openedAt, openedAt);
47
- const tools = { notes: "memo_*", notesList: "memo_list", history: "archive_*", historyWindows: "archive_windows", historyList: "archive_list", historySearch: "archive_search", historyRead: "archive_read", remaining: "room", wipe: "forget" };
47
+ const tools = { notes: "memo_*", notesList: "memo_list", history: "archive_*", remaining: "room", wipe: "forget" };
48
48
  const block = { agentName: notesIdentity.agent, modelName: notesIdentity.model, firstWindowId: "root", currentWindowId: "next", notes: snapshot, tools };
49
49
  const rendered = renderBootBlock(block);
50
50
  assert.equal(renderBootBlock(block), rendered);
51
51
  assert.ok(rendered.includes("๐Ÿ˜€\n checkpoint.md ยท 1m ago"), "a feed entry is the note's own first line over its locator");
52
- assert.ok(rendered.includes("ask memo_list to try again"));
53
- assert.equal(/notes_\*|notes_list|history_\*|history_list|history_search|history_read|get_context_remaining|clear_memory/.test(rendered), false);
52
+ assert.ok(rendered.includes("ask `memo_list` to try again"));
53
+ assert.equal(/notes_\*|notes_list|history_\*|history_list|history_read|get_context_remaining|clear_memory/.test(rendered), false);
54
54
  });
55
- test("the shared result module bounds both surfaces and names what a window withheld", () => {
55
+ test("the shared result module bounds both surfaces and resumes by offset", () => {
56
56
  const text = `${"a".repeat(120)}๐Ÿ˜€${"b".repeat(30)}`;
57
57
  const chars = Array.from(text);
58
- // The requested count stops the read, and the footer says only that.
58
+ // The requested count stops the read, and the footer says only where to continue.
59
59
  const first = data(read(text, 0, 10));
60
60
  assert.equal(first.window.text, chars.slice(0, 10).join(""));
61
- assert.equal(first.window.limited_by, "limit");
62
61
  assert.equal(first.window.next_offset_chars, 10);
63
62
  assert.equal(first.window.total_chars, chars.length);
64
- assert.match(renderData(success(first)), /\[141 more characters\. Use offset_chars=10 to continue\.\]$/);
63
+ assert.match(renderData(success(first)), /\[truncated; continue at offset_chars=10\]$/);
65
64
  // Concatenating windows by their cursors reproduces the source, marker-free.
66
65
  const second = data(read(text, first.window.next_offset_chars ?? 0, 10));
67
- assert.equal(second.window.offset_chars, 10);
68
66
  assert.equal(`${first.window.text}${second.window.text}`, chars.slice(0, 20).join(""));
69
67
  // A negative offset counts back from the end and reaches a complete window: no footer at all.
70
68
  const tail = data(read(text, -4));
71
69
  assert.equal(tail.window.text, "bbbb");
72
- assert.equal(tail.window.offset_chars, chars.length - 4);
73
70
  assert.equal(tail.window.next_offset_chars, null);
74
- assert.equal(tail.window.limited_by, null);
75
71
  assert.equal(renderTextWindow(tail.window), "bbbb");
76
72
  // The byte cap, not the requested count, is what stops an oversized read, and the rendered
77
73
  // header is counted against the same budget as the payload.
78
74
  const huge = "b".repeat(4 * MAX_READ_WINDOW_CHARS);
79
75
  const capped = data(read(huge, 0, MAX_READ_WINDOW_CHARS));
80
76
  const cappedEnd = capped.window.next_offset_chars ?? 0;
81
- assert.equal(capped.window.limited_by, "bytes");
82
77
  assert.ok(cappedEnd < MAX_READ_WINDOW_CHARS, "the byte cap cut the requested window short");
83
78
  assert.equal(fitsResult(success(capped), renderData), true);
84
79
  assert.ok(Buffer.byteLength(renderData(success(capped)), "utf8") <= TOOL_OUTPUT_MAX_BYTES, "the model text fits");
85
80
  assert.ok(Buffer.byteLength(JSON.stringify(wireResult(success(capped))), "utf8") <= TOOL_OUTPUT_MAX_BYTES, "the structured outcome fits");
86
81
  assert.equal(capped.window.text, huge.slice(0, cappedEnd), "the delivered slice is a verbatim prefix");
87
- assert.match(renderData(success(capped)), new RegExp(`\\[Showing chars \\[0, ${cappedEnd}\\) of ${huge.length} \\(32KB limit\\)\\. Use offset_chars=${cappedEnd} to continue\\.\\]$`));
82
+ assert.match(renderData(success(capped)), new RegExp(`\\[truncated; continue at offset_chars=${cappedEnd}\\]$`));
88
83
  // Code points, not UTF-16 units.
89
84
  const emoji = data(read("๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€", 1, 1));
90
85
  assert.equal(emoji.window.text, "๐Ÿ˜€");
@@ -97,7 +92,7 @@ test("the shared result module bounds both surfaces and names what a window with
97
92
  assert.equal(empty.window.next_offset_chars, null);
98
93
  assert.equal(renderOutcome(success(first), () => "model text"), "model text");
99
94
  assert.equal(renderOutcome(failure("not_found", "note not found"), () => "never"), "error: not_found: note not found");
100
- assert.equal(renderOutcome(failure("ambiguous_edit", "occurs 2 times", { line_numbers: [2, 7] }), () => "never"), 'error: ambiguous_edit: occurs 2 times {"line_numbers":[2,7]}');
95
+ assert.equal(renderOutcome(failure("ambiguous_edit", "edit 0: occurs 2 times"), () => "never"), "error: ambiguous_edit: edit 0: occurs 2 times");
101
96
  const schema = resultSchema(Type.Object({ name: Type.String() }));
102
97
  assert.equal(Check(schema, wireResult(success({ name: "test" }))), true);
103
98
  assert.equal(Check(schema, wireResult(failure("not_found", "missing"))), true);
@@ -116,8 +111,6 @@ test("an envelope that cannot fit is refused rather than resumed forever", () =>
116
111
  const refusing = readTextWindow(text, 0, undefined, oversized.makeData, oversized.render);
117
112
  const error = refusal(refusing);
118
113
  assert.equal(error.code, "output_too_large");
119
- assert.equal(error.details?.offset_chars, 0);
120
- assert.equal(error.details?.budget_bytes, TOOL_OUTPUT_MAX_BYTES);
121
114
  assert.ok(structuredBytes(wireResult(refusing)) <= TOOL_OUTPUT_MAX_BYTES, "the refusal that replaces an unresumable window is itself bounded");
122
115
  assert.equal(fitsResult(refusing, oversized.render), true);
123
116
  // Empty text fitting is insufficient when not even one source character can fit.
@@ -140,22 +133,18 @@ test("every resumed window advances the cursor and reconstructs the source exact
140
133
  for (let offset = 0; offset < chars.length;) {
141
134
  const window = data(read(text, offset, MAX_READ_WINDOW_CHARS)).window;
142
135
  assert.equal(window.total_chars, chars.length, "one source, one length");
143
- assert.equal(window.offset_chars, offset, "each window starts where the last one stopped");
144
136
  if (window.next_offset_chars === null) {
145
- assert.equal(window.offset_chars + Array.from(window.text).length, window.total_chars, "the last window reaches the true end");
137
+ assert.equal(offset + Array.from(window.text).length, window.total_chars, "the last window reaches the true end");
146
138
  windows.push(window);
147
139
  break;
148
140
  }
149
- assert.ok(window.next_offset_chars > window.offset_chars, "a window with text left always advances the cursor");
141
+ assert.ok(window.next_offset_chars > offset, "a window with text left always advances the cursor");
150
142
  windows.push(window);
151
143
  offset = window.next_offset_chars;
152
144
  }
153
145
  assert.ok(windows.length > 1, "the fixture needed more than one window");
154
- assert.equal(windows.slice(0, -1).every((window) => window.limited_by === "bytes"), true, "the byte cap, not the count, split this read");
155
- assert.equal(windows.at(-1)?.limited_by, null, "the last window withholds nothing");
156
146
  assert.equal(windows.map((window) => window.text).join(""), text, "concatenating the windows reproduces the source code point for code point");
157
147
  for (const window of windows) {
158
- assert.equal(Array.from(window.text).length, (window.next_offset_chars ?? window.total_chars) - window.offset_chars, "the delivered length matches the cursor");
159
148
  assert.ok(structuredBytes(wireResult(success({ window }))) <= TOOL_OUTPUT_MAX_BYTES, "each window fits the structured surface");
160
149
  }
161
150
  });
@@ -171,7 +160,6 @@ test("window offsets count code points, not UTF-16 units or graphemes", () => {
171
160
  for (const { name, text, cursor } of cases) {
172
161
  const chars = Array.from(text);
173
162
  const window = data(read(text, cursor, undefined)).window;
174
- assert.equal(window.offset_chars, cursor, `${name}: the resolved offset is echoed`);
175
163
  assert.equal(window.total_chars, chars.length, `${name}: totals count code points`);
176
164
  assert.equal(window.text, chars.slice(cursor).join(""), `${name}: the slice starts on a code-point boundary`);
177
165
  assert.equal(window.text.includes("๏ฟฝ"), false, `${name}: no surrogate is split`);
@@ -180,38 +168,15 @@ test("window offsets count code points, not UTF-16 units or graphemes", () => {
180
168
  const emoji = "๐Ÿ˜€".repeat(3);
181
169
  const tail = data(read(emoji, -1)).window;
182
170
  assert.equal(tail.text, "๐Ÿ˜€");
183
- assert.equal(tail.offset_chars, 2, "the last code point is at 2, not at 5 UTF-16 units");
184
171
  assert.equal(tail.next_offset_chars, null);
185
172
  });
186
- test("the dynamic parts of a refusal are bounded by construction", () => {
187
- // A note edit that matched a million lines is the realistic unbounded case.
188
- const huge = failure("ambiguous_edit", `edit 0: oldText occurs ${"9".repeat(7)} times`, { line_numbers: Array.from({ length: 1_000_000 }, (_, index) => index + 1) });
189
- const error = refusal(huge);
190
- assert.equal(error.code, "ambiguous_edit");
191
- assert.deepEqual(Object.keys(error.details ?? {}).sort(), ["details_bytes", "truncated"], "oversized context is named, never partially serialized");
192
- assert.equal(error.details?.truncated, true);
193
- assert.ok(error.details?.details_bytes > ERROR_DETAILS_MAX_BYTES, "the lost size is reported");
194
- assert.ok(structuredBytes(wireResult(huge)) <= TOOL_OUTPUT_MAX_BYTES, "even a pathological refusal fits the budget");
195
- assert.equal(fitsResult(huge, () => renderOutcome(huge, () => "")), true);
196
- const small = refusal(failure("no_match", "edit 0: oldText does not occur in the note body", { edit_index: 0, line_numbers: [4] }));
197
- assert.deepEqual(small.details, { edit_index: 0, line_numbers: [4] }, "context inside the budget is kept as it is");
198
- // A flood of keys is the same hazard as a flood of values: a handler must not spend the budget
199
- // enumerating what it could not report anyway.
200
- const manyKeys = failure("unknown_window_id", 'unknown window_id "w"', Object.fromEntries([...Array.from({ length: 300 }, (_, index) => [`window_${index}`, index]), ["k".repeat(5000), 1]]));
201
- const keyed = refusal(manyKeys);
202
- assert.deepEqual(Object.keys(keyed.details ?? {}).sort(), ["details_bytes", "truncated"], "oversized keys are replaced by the marker, not trimmed into a partial list");
203
- assert.ok(structuredBytes(wireResult(manyKeys)) <= TOOL_OUTPUT_MAX_BYTES);
173
+ test("a runaway refusal message is clipped with its lost length", () => {
204
174
  const long = refusal(failure("internal_error", "m".repeat(50_000)));
205
175
  assert.ok(Array.from(long.message).length < ERROR_MESSAGE_MAX_CHARS + 40, "a runaway message is clipped with a marker");
206
176
  assert.match(long.message, /โ€ฆ\[truncated \d+ chars\]$/, "the clip says how much was dropped");
177
+ assert.ok(structuredBytes(wireResult(failure("internal_error", "m".repeat(50_000)))) <= TOOL_OUTPUT_MAX_BYTES, "even a pathological refusal fits the budget");
207
178
  });
208
- test("internal result invariants stay visible instead of becoming a bounded-looking refusal", () => {
209
- // Context JSON cannot express is a handler defect, and a defect is not a bounded refusal.
210
- const circular = {};
211
- circular.self = circular;
212
- assert.throws(() => failure("internal_error", "cyclic context", circular), TypeError, "a cyclic context throws instead of being swallowed");
213
- assert.throws(() => failure("internal_error", "unrepresentable context", { size: 1n }), TypeError, "a BigInt context throws instead of becoming an empty value");
214
- // A value with no JSON representation has no size to measure, so it is not measured as zero bytes.
179
+ test("structuredBytes has no size for a value with no JSON representation", () => {
215
180
  assert.throws(() => structuredBytes(undefined), TypeError, "undefined has no structured size");
216
181
  });
217
182
  test("shared note operations return canonical outcomes with a body-only read window", async (t) => {
@@ -224,7 +189,6 @@ test("shared note operations return canonical outcomes with a body-only read win
224
189
  assert.equal(change.kind, "body");
225
190
  return "caller-rendered-diff";
226
191
  }));
227
- assert.equal(updated.applied, 1);
228
192
  assert.equal(updated.change_kind, "body");
229
193
  assert.equal(updated.diff, "caller-rendered-diff");
230
194
  // Frontmatter is metadata, not body: the window addresses the body and counts only the body.
@@ -235,13 +199,11 @@ test("shared note operations return canonical outcomes with a body-only read win
235
199
  assert.equal(read.text, stored.body, "a complete read is the whole body and nothing else");
236
200
  assert.equal(read.total_chars, body.length);
237
201
  assert.equal(read.next_offset_chars, null);
238
- assert.equal(read.limited_by, null);
239
202
  assert.equal(read.metadata.origin, "self");
240
203
  assert.equal(notesRead.render(success(read)).includes("READ WINDOW"), false, "a read presents no metadata block");
241
204
  // A negative offset resolves against the body, never against the serialized file.
242
205
  const tail = data(await notesRead.execute({ address: "@project/test.md", offset_chars: -4 }, notesIdentity));
243
206
  assert.equal(tail.text, body.slice(-4).join(""));
244
- assert.equal(tail.offset_chars, body.length - 4);
245
207
  assert.equal(tail.total_chars, body.length, "metadata length never enters the body cursor");
246
208
  assert.equal(tail.next_offset_chars, null);
247
209
  assert.equal(refusal(await notesRead.execute({ address: "@project/missing.md" }, notesIdentity)).code, "not_found");
@@ -257,7 +219,7 @@ test("shared history operations read typed events through the addresses the adap
257
219
  const windows = data(await historyWindows.execute({}, projection, "explicit-session"));
258
220
  assert.equal(windows.session_id, "explicit-session");
259
221
  assert.equal(windows.windows.length, 1);
260
- assert.equal(windows.windows[0]?.item_count, 2, "a call and its result are one event, not two");
222
+ assert.deepEqual(windows.windows[0], { window_id: "root", created_at: null, first_seq: 1, last_seq: 2 }, "a call and its result are one event, not two");
261
223
  const listed = data(await historyList.execute({ roles: ["tool"] }, projection));
262
224
  assert.equal(listed.items.length, 1);
263
225
  const item = listed.items[0];
@@ -271,11 +233,12 @@ test("shared history operations read typed events through the addresses the adap
271
233
  assert.match(full.text, /one\.md/, "the document carries the arguments");
272
234
  assert.match(full.text, /needle output/, "the document carries the result");
273
235
  assert.equal(full.next_offset_chars, null);
274
- // A search offset addresses that same document, so reading from it resumes inside the result.
275
- const searched = data(await historySearch.execute({ query: "NEEDLE", roles: ["tool"] }, projection));
236
+ // A query offset addresses that same document, so reading from it resumes inside the result.
237
+ const searched = data(await historyList.execute({ query: "NEEDLE", roles: ["tool"] }, projection));
276
238
  assert.equal(searched.items.length, 1);
277
239
  const hit = searched.items[0];
278
- assert.ok(!('folded' in hit));
240
+ if ("folded" in hit)
241
+ assert.fail("a query returns event rows only");
279
242
  assert.equal(hit.seq, seq);
280
243
  assert.ok((hit.offset_chars ?? 0) > 0);
281
244
  const fromMatch = data(await historyRead.execute({ seq: hit.seq, offset_chars: hit.offset_chars }, projection));
@@ -284,10 +247,21 @@ test("shared history operations read typed events through the addresses the adap
284
247
  assert.match(refusal(await historyRead.execute({ seq: 9_999 }, projection)).message, /9,?999/, "an unknown address is refused by name");
285
248
  assert.equal(refusal(await historyRead.execute({ seq: 3 }, projection)).code, "not_an_event", "a paired result address is refused");
286
249
  });
250
+ test("an unknown window_id names at most five known windows in its message", async () => {
251
+ const windows = Array.from({ length: 7 }, (_, index) => ({ windowId: `pcw:w${index}`, items: [{ seq: index + 1, windowId: `pcw:w${index}`, role: "user", text: `message-${index}` }] }));
252
+ const projection = projectHistory(windows, 7, new Set([1, 2, 3, 4, 5, 6, 7]));
253
+ const outcome = await historyList.execute({ window_id: "pcw:absent" }, projection);
254
+ assert.equal(outcome.ok, false);
255
+ if (!outcome.ok) {
256
+ assert.equal(outcome.error.code, "unknown_window_id");
257
+ assert.match(outcome.error.message, /unknown window_id "pcw:absent"; known: pcw:w0, pcw:w1, pcw:w2, pcw:w3, pcw:w4/, "the message names the known windows itself");
258
+ assert.equal(outcome.error.message.includes("pcw:w5"), false, "at most five known windows are named");
259
+ }
260
+ });
287
261
  test("one role schema declares the four public roles for the page item, the read payload, and the role filter", () => {
288
262
  const read = (role) => ({
289
263
  seq: 1, window_id: "root", role, created_at: null,
290
- text: "", offset_chars: 0, total_chars: 0, next_offset_chars: null, limited_by: null,
264
+ text: "", total_chars: 0, next_offset_chars: null,
291
265
  });
292
266
  assert.equal(HistoryPageItemSchema.properties.role, HistoryRoleSchema, "the page item reuses the authoritative role schema");
293
267
  assert.deepEqual(historyRoles().items, HistoryRoleSchema, "the role filter carries the authoritative role schema");
@@ -31,16 +31,16 @@ test("standalone notes API persists camelCase metadata, edits, lists and searche
31
31
  assert.equal(metadataEdit.change.after.includes("needle"), false, "metadata-only diff excludes body");
32
32
  assert.equal((await notes.list()).some((row) => row.address === "checkpoint.md"), false, "a crumpled note leaves the live list");
33
33
  assert.equal((await notes.search(["needle"])).length, 0, "search also skips crumpled notes");
34
- const basket = (await notes.list({ wastebasket: true }))[0];
34
+ const basket = (await notes.list({ crumpled: true }))[0];
35
35
  assert.equal(basket.address, "checkpoint.md");
36
36
  assert.ok(basket.meta.crumpledAt);
37
37
  assert.equal(basket.meta.updatedAt, updatedBefore, "crumpling does not bump updatedAt");
38
38
  const crumpledAt = basket.meta.crumpledAt;
39
39
  await notes.update("checkpoint", undefined, { crumpled: true });
40
- assert.equal((await notes.list({ wastebasket: true }))[0]?.meta.crumpledAt, crumpledAt, "re-crumpling keeps the original time");
40
+ assert.equal((await notes.list({ crumpled: true }))[0]?.meta.crumpledAt, crumpledAt, "re-crumpling keeps the original time");
41
41
  await notes.update("checkpoint", undefined, { crumpled: false });
42
42
  assert.equal((await notes.list()).some((row) => row.address === "checkpoint.md"), true, "smoothing returns the note to the live list");
43
- assert.equal((await notes.list({ wastebasket: true })).length, 0);
43
+ assert.equal((await notes.list({ crumpled: true })).length, 0);
44
44
  const matches = await notes.search(["needle"]);
45
45
  assert.equal(matches[0]?.matches[0]?.line, 2);
46
46
  const body = (await notes.read("checkpoint")).body;
@@ -60,7 +60,7 @@ test("standalone notes API persists camelCase metadata, edits, lists and searche
60
60
  assert.deepEqual(rewritten.meta.recurrenceWindows, ["pcw:one", "pcw:two"]);
61
61
  assert.equal(rewritten.meta.crumpledAt, undefined, "writing always produces an uncrumpled note");
62
62
  const combined = await moved.update("checkpoint", [{ oldText: "new", newText: "final" }], { crumpled: true });
63
- assert.equal(combined.change.kind, "file");
63
+ assert.equal(combined.change.kind, "body");
64
64
  assert.match(combined.change.after, /\ncrumpledAt: \d{4}-\d{2}-\d{2}T/);
65
65
  assert.match(combined.change.after, /final body$/);
66
66
  assert.deepEqual((await moved.update("checkpoint", undefined, { crumpled: true })).change, { kind: "none", before: "", after: "" });
@@ -104,15 +104,15 @@ test("stores snapshot explicit identity and do not leak homes across instances",
104
104
  assert.equal((await notes.read("@agents/visitor/hello"))?.body, "visiting");
105
105
  await assert.rejects(() => notes.write("@agents/visitor/hello", "overwrite"), (error) => error instanceof NoteError && error.code === "invalid_scope");
106
106
  });
107
- test("list and search share scoped pattern scans and search offsets count Unicode code points", async (t) => {
107
+ test("list and search share scoped glob scans and search offsets count Unicode code points", async (t) => {
108
108
  const { notes } = fixture(t);
109
109
  await notes.write("shared.md", "๐Ÿ˜€ needle in session");
110
110
  await notes.write("@project/shared.md", "needle in project");
111
111
  await notes.write("@human/shared.md", "needle in human");
112
112
  await notes.write("@project/elsewhere.md", "unrelated");
113
- const pattern = "**/shared.md";
114
- const listed = await notes.list({ pattern });
115
- const searched = await notes.search(["needle"], { pattern });
113
+ const glob = "**/shared.md";
114
+ const listed = await notes.list({ glob });
115
+ const searched = await notes.search(["needle"], { glob });
116
116
  const listedAddresses = listed.map((row) => row.address).sort();
117
117
  const searchedAddresses = searched.map((row) => row.address).sort();
118
118
  assert.deepEqual(searchedAddresses, ["@human/shared.md", "@project/shared.md", "shared.md"]);
@@ -6,10 +6,11 @@ import { dirname } from "node:path";
6
6
  import test from "node:test";
7
7
  import { loadNotesSnapshot } from "../src/boot/snapshot.js";
8
8
  import { renderBootBlock } from "../src/boot/render.js";
9
+ import { MAP_BOOT_MAX_CHARS } from "../src/boot/text.js";
9
10
  import { localIso } from "../src/notes/frontmatter.js";
10
11
  import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
11
12
  import { MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
12
- import { MAX_METADATA_ENTRY_BYTES, notesUpdate } from "../src/tools/notes.js";
13
+ import { notesUpdate } from "../src/tools/notes.js";
13
14
  import { assertWithinBudget, call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
14
15
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
15
16
  const testEnvironment = installExtensionTestHooks("notesoup-integration");
@@ -35,11 +36,11 @@ test("notes_list and notes_search are recent-first snapshots with narrowing hint
35
36
  const listed = resultData(await call(captured, "notes_list", { limit: 2 }, ctx));
36
37
  assert.deepEqual(listed.files.map((file) => file.address), ["new.md", "@project/design.md"]);
37
38
  assert.equal(listed.more, 1);
38
- assert.deepEqual(Object.keys(listed).sort(), ["crumpled_excluded", "files", "homes_unavailable", "more"]);
39
+ assert.deepEqual(Object.keys(listed).sort(), ["files", "homes_unavailable", "more"]);
39
40
  const searched = resultData(await call(captured, "notes_search", { query: "needle", limit: 2 }, ctx));
40
41
  assert.deepEqual(searched.files.map((file) => file.address), ["new.md", "@project/design.md"]);
41
42
  assert.equal(searched.more, 1);
42
- const narrowed = resultData(await call(captured, "notes_list", { pattern: "@project/**" }, ctx));
43
+ const narrowed = resultData(await call(captured, "notes_list", { glob: "@project/**" }, ctx));
43
44
  assert.deepEqual(narrowed.files.map((file) => file.address), ["@project/design.md"]);
44
45
  assert.equal(narrowed.more, 0);
45
46
  });
@@ -81,7 +82,7 @@ test("notes_list is most-recently-updated first across merged scopes", async ()
81
82
  // A same-path pair in two scopes keeps both rows; equal timestamps tie-break by scope name.
82
83
  put("human", "a.md", base + 10);
83
84
  assert.deepEqual((await files({})).filter((file) => file.address.endsWith("a.md")).map((file) => file.address), ["@human/a.md", "a.md"], "equal timestamps tie-break by full address");
84
- assert.deepEqual((await files({ pattern: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare pattern narrows to the session home");
85
+ assert.deepEqual((await files({ glob: "*.md" })).map((file) => file.address), ["a.md", "b.md"], "a bare glob narrows to the session home");
85
86
  });
86
87
  test("notes are real files that persist across sessions and round-trip Unicode", async () => {
87
88
  const original = manager();
@@ -97,13 +98,13 @@ test("notes are real files that persist across sessions and round-trip Unicode",
97
98
  const read = resultRead(rawRead);
98
99
  assert.equal(read.address, "@human/checkpoint/่ฟ›ๅบฆ.md");
99
100
  assert.equal(read.content, "Cafรฉ", "a negative offset reads the body tail in one call");
100
- const searched = resultData(await call(restoredCaptured, "notes_search", { pattern: "@human/**", query: "Cafรฉ" }, restoredCtx));
101
+ const searched = resultData(await call(restoredCaptured, "notes_search", { glob: "@human/**", query: "Cafรฉ" }, restoredCtx));
101
102
  assert.equal(searched.files[0]?.matches[0]?.line, 2);
102
- const listedFiles = resultData(await call(restoredCaptured, "notes_list", { pattern: "@human/checkpoint/**" }, restoredCtx));
103
+ const listedFiles = resultData(await call(restoredCaptured, "notes_list", { glob: "@human/checkpoint/**" }, restoredCtx));
103
104
  assert.equal(listedFiles.files.length, 1, "glob ** crosses into the checkpoint directory");
104
105
  assert.equal(listedFiles.files[0]?.address, "@human/checkpoint/่ฟ›ๅบฆ.md");
105
106
  // A single-segment * never crosses `/`, so a nested-only store matches nothing at the root.
106
- const rootOnly = resultData(await call(restoredCaptured, "notes_list", { pattern: "@human/*" }, restoredCtx));
107
+ const rootOnly = resultData(await call(restoredCaptured, "notes_list", { glob: "@human/*" }, restoredCtx));
107
108
  assert.equal(rootOnly.files.length, 0, "glob * stays within one segment");
108
109
  assert.equal(searched.files[0]?.updated_at, listedFiles.files[0]?.updated_at);
109
110
  assert.equal(resultError(await call(captured, "notes_write", { address: "../escape", content: "x" }, ctx)).code, "invalid_address");
@@ -114,20 +115,20 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
114
115
  const ctx = context(sm);
115
116
  await call(captured, "notes_write", { address: "journal.md", content: "log line" }, ctx);
116
117
  const updatedBefore = (await listNotes(ctx, { scope: "session" }))[0].meta.updatedAt;
117
- // metadata-only: content unchanged, applied 0, and the recorded time is the original one
118
+ // metadata-only: content unchanged, and the recorded time is the original one
118
119
  const markOnly = resultData(await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx));
119
- assert.equal(markOnly.applied, 0);
120
+ assert.equal(markOnly.change_kind, "metadata");
120
121
  assert.match(markOnly.diff, /^\+\s*\d+\s+crumpledAt: \d{4}-\d{2}-\d{2}T/m);
121
122
  assert.deepEqual(await listNotes(ctx, { scope: "session" }), [], "a crumpled note leaves the live list");
122
- const basket = (await listNotes(ctx, { scope: "session", wastebasket: true }))[0];
123
+ const basket = (await listNotes(ctx, { scope: "session", crumpled: true }))[0];
123
124
  assert.ok(basket.meta.crumpledAt);
124
125
  assert.equal(basket.meta.updatedAt, updatedBefore, "crumpling does not change updatedAt");
125
126
  assert.equal(resultRead(await call(captured, "notes_read", { address: "journal.md" }, ctx)).content.endsWith("log line"), true, "read still reaches a crumpled note");
126
127
  // re-crumpling keeps the first time; smoothing empties the basket
127
128
  await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx);
128
- assert.equal((await listNotes(ctx, { scope: "session", wastebasket: true }))[0]?.meta.crumpledAt, basket.meta.crumpledAt);
129
+ assert.equal((await listNotes(ctx, { scope: "session", crumpled: true }))[0]?.meta.crumpledAt, basket.meta.crumpledAt);
129
130
  await call(captured, "notes_update", { address: "journal.md", crumpled: false }, ctx);
130
- assert.deepEqual(await listNotes(ctx, { scope: "session", wastebasket: true }), []);
131
+ assert.deepEqual(await listNotes(ctx, { scope: "session", crumpled: true }), []);
131
132
  assert.equal((await listNotes(ctx, { scope: "session" }))[0]?.meta.crumpledAt, undefined);
132
133
  // writing to a crumpled address always produces an uncrumpled note
133
134
  await call(captured, "notes_update", { address: "journal.md", crumpled: true }, ctx);
@@ -243,7 +244,7 @@ test("boot note acquisition is one closed snapshot and isolates one or all faile
243
244
  currentWindowId: "pcw:test:next",
244
245
  notes: oneFailed,
245
246
  });
246
- assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("THE HUMAN ยท @human\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n\n This drawer wouldn't open โ€” ask notes_list to try again."), "healthy homes and a per-section recovery notice survive one failure");
247
+ assert.ok(oneFailedText.includes("PROJECT_MAP_BODY") && oneFailedText.includes("THE HUMAN ยท @human\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n\n This drawer wouldn't open โ€” ask `notes_list` to try again."), "healthy homes and a per-section recovery notice survive one failure");
247
248
  assert.equal(oneFailedText.includes("HUMAN_POCKET_BODY"), false, "the failed home's index is omitted");
248
249
  assert.equal(oneFailedText.includes("Human note"), false, "the failed home takes no feed seats");
249
250
  const allFailed = await loadNotesSnapshot(notesIdentityFromPi(ctx), Date.now(), (scope) => {
@@ -269,7 +270,23 @@ test("the boot block gives awake agents the notes-home file layout", async () =>
269
270
  const session = manager();
270
271
  const rendered = await explicitBoot(context(session), "pcw:test:root", undefined);
271
272
  assert.equal(rendered.includes(process.env.PI_NOTES_HOME ?? ""), false, "the absolute notes home is never exposed");
272
- assert.match(rendered, /<path>, no @[\s\S]*@project\/<path>[\s\S]*@human\/<path>/);
273
+ assert.match(rendered, /`<path>`, no @[\s\S]*`@project\/<path>`[\s\S]*`@human\/<path>`/);
274
+ });
275
+ test("the boot protocol carries the approved copy and cuts an over-cap MAP with the approved notice", async () => {
276
+ const session = manager();
277
+ const captured = makeExtension(session);
278
+ const ctx = context(session);
279
+ await call(captured, "notes_write", { address: "MAP.md", content: "M".repeat(MAP_BOOT_MAX_CHARS + 10) }, ctx);
280
+ const rendered = await explicitBoot(ctx, "pcw:test:root", undefined);
281
+ assert.ok(rendered.includes("History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice."), "the History paragraph is the approved copy");
282
+ assert.ok(rendered.includes("- `@project/<path>` โ€” this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say."), "the @project bullet is the approved copy");
283
+ assert.ok(rendered.includes("- `<path>`, no @") && rendered.includes("- `@human/<path>`") && rendered.includes("- `@self/<path>`") && rendered.includes("- `@model/<path>`"), "every address bullet is backticked");
284
+ assert.ok(rendered.includes("Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`."), "the fake-address paragraph is the approved copy");
285
+ assert.ok(rendered.includes(`[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`MAP.md\`]`), "an over-cap MAP is cut with the approved notice");
286
+ assert.equal(rendered.includes("MAP cut at"), false, "the retired cut notice is gone");
287
+ for (const retired of ["history_windows", "history_list", "history_read"]) {
288
+ assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
289
+ }
273
290
  });
274
291
  test("an over-budget note is delivered as a bounded prefix and resumed by next_offset_chars", async () => {
275
292
  const session = manager();
@@ -284,20 +301,16 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
284
301
  assert.ok(first.content.length > 0, "the page is not empty");
285
302
  assert.equal(first.content.includes("โ€ฆ"), false, "the window text is a plain prefix with no marker");
286
303
  assert.ok(first.content.startsWith("H"), "the body is delivered first, with no frontmatter in the way");
287
- assert.equal(first.offset_chars, 0, "the default window starts at the resolved offset 0");
288
- assert.equal(first.total_chars, Array.from(text).length, "the window counts the body, not the serialized file");
289
- assert.equal(first.limited_by, "limit", "the requested window ended this page, not the byte budget");
290
304
  assert.equal(first.content.length, 12000, "the default window is the full requested count");
291
- assert.deepEqual(Object.keys(resultData(rawFirst)).sort(), ["address", "limited_by", "metadata", "next_offset_chars", "offset_chars", "text", "total_chars"], "read fields are flat");
305
+ assert.deepEqual(Object.keys(resultData(rawFirst)).sort(), ["address", "metadata", "next_offset_chars", "text", "total_chars"], "read fields are flat");
292
306
  assert.equal("access_count" in resultData(rawFirst).metadata, false, "access bookkeeping stays in storage");
293
- assert.equal(textOf(rawFirst).endsWith(`\n\n[${first.total_chars - first.content.length} more characters. Use offset_chars=${first.next_offset_chars} to continue.]`), true, "the footer names the resume cursor in the new read style");
294
- // Asking for the largest legal window still cannot exceed the byte budget, and says so.
295
- const rawWide = await call(captured, "notes_read", { address: "huge.md", limit_chars: MAX_READ_WINDOW_CHARS }, ctx);
307
+ assert.equal(textOf(rawFirst).endsWith(`\n\n[truncated; continue at offset_chars=${first.next_offset_chars}]`), true, "the footer names the resume cursor");
308
+ // Asking for the largest legal window still cannot exceed the byte budget.
309
+ const rawWide = await call(captured, "notes_read", { address: "huge.md", max_chars: MAX_READ_WINDOW_CHARS }, ctx);
296
310
  assertWithinBudget(rawWide, "widest requested window");
297
311
  const wide = resultRead(rawWide);
298
- assert.equal(wide.limited_by, "bytes", "the byte budget stopped this window");
299
312
  assert.ok(Array.from(wide.content).length < MAX_READ_WINDOW_CHARS, "the widest request is cut short");
300
- assert.match(textOf(rawWide), /\(32KB limit\)\. Use offset_chars=\d+ to continue\.\]$/, "a byte-stopped window names the budget that stopped it");
313
+ assert.match(textOf(rawWide), /\[truncated; continue at offset_chars=\d+\]$/, "a byte-stopped window still says where to continue");
301
314
  // Following the cursor reconstructs the body by plain concatenation.
302
315
  const parts = [first.content];
303
316
  let offset = first.next_offset_chars;
@@ -305,7 +318,6 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
305
318
  const rawChunk = await call(captured, "notes_read", { address: "huge.md", offset_chars: offset }, ctx);
306
319
  assertWithinBudget(rawChunk, `huge note chunk at ${offset}`);
307
320
  const chunk = resultRead(rawChunk);
308
- assert.equal(chunk.offset_chars, offset, "the response echoes the resolved absolute offset");
309
321
  parts.push(chunk.content);
310
322
  offset = chunk.next_offset_chars;
311
323
  }
@@ -317,8 +329,8 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
317
329
  for (const result of [
318
330
  await call(captured, "notes_write", { address: "@project/receipt", content: "body" }, ctx),
319
331
  await call(captured, "notes_update", { address: "@project/receipt", edits: [{ oldText: "body", newText: "changed" }] }, ctx),
320
- await call(captured, "notes_list", { pattern: "@project/**" }, ctx),
321
- await call(captured, "notes_search", { query: "changed", pattern: "@project/**" }, ctx),
332
+ await call(captured, "notes_list", { glob: "@project/**" }, ctx),
333
+ await call(captured, "notes_search", { query: "changed", glob: "@project/**" }, ctx),
322
334
  await call(captured, "notes_read", { address: "@project/receipt" }, ctx),
323
335
  ]) {
324
336
  assert.equal(JSON.stringify(result).includes(root), false, "notes receipts never expose the absolute home");
@@ -329,9 +341,8 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
329
341
  assert.deepEqual(Object.keys(missing).sort(), ["code", "message"], "the refusal carries a precise code and message");
330
342
  assert.equal(missing.message, "note not found");
331
343
  assert.equal(missing.code, "not_found");
332
- assert.equal(missingResult.details, undefined, "a refusal carries no details metadata");
333
344
  });
334
- test("an over-budget note search match is a named prefix with an honest line address", async () => {
345
+ test("an over-budget note search match is a marked prefix with an honest line address", async () => {
335
346
  const session = manager();
336
347
  const captured = makeExtension(session);
337
348
  const ctx = context(session);
@@ -340,18 +351,18 @@ test("an over-budget note search match is a named prefix with an honest line add
340
351
  await call(captured, "notes_write", { address: "a.md", content: "needle small" }, ctx);
341
352
  await call(captured, "notes_write", { address: "search.md", content: hugeLine }, ctx);
342
353
  const pages = [];
343
- const found = resultData(await call(captured, "notes_search", { query: "needle", limit: 10 }, ctx));
354
+ const rawFound = await call(captured, "notes_search", { query: "needle", limit: 10 }, ctx);
355
+ const found = resultData(rawFound);
344
356
  assert.ok(Buffer.byteLength(JSON.stringify(found), "utf8") <= TOOL_OUTPUT_MAX_BYTES, "the structured match result stays within budget");
357
+ assert.match(textOf(rawFound), /\[truncated\]/, "the model-facing match line carries the same marker");
345
358
  pages.push(...found.files);
346
359
  assert.equal(found.more, 1, "the oversized result names the omitted matching file");
347
360
  assert.deepEqual(pages.map((file) => file.address), ["search.md"], "the snapshot keeps the most recently updated match");
348
361
  const oversized = pages[0];
349
- assert.equal(oversized.matches_total, 1, "the file's full match count is named even though the line was cut");
350
362
  assert.equal(oversized.matches.length, 1);
351
363
  const match = oversized.matches[0];
352
- assert.equal(match.truncated, true, "the oversized match line is flagged as truncated");
353
- assert.ok(hugeLine.startsWith(match.text), "the match text is a plain prefix of the line");
354
- assert.equal(match.text.includes("โ€ฆ"), false, "no marker is appended to the match text");
364
+ assert.ok(match.text.endsWith(" [truncated]"), "a shortened match line ends with the ellipsis marker");
365
+ assert.ok(hugeLine.startsWith(match.text.slice(0, -" [truncated]".length)), "the match text is a plain prefix of the line plus its marker");
355
366
  assert.equal(match.line, 1, "the informational line number survives");
356
367
  assert.equal(match.offset_chars, 500, "the offset addresses the body directly, so the query's real position survives");
357
368
  const atMatch = resultRead(await call(captured, "notes_read", { address: "search.md", offset_chars: match.offset_chars }, ctx));
@@ -363,7 +374,6 @@ test("an over-budget note search match is a named prefix with an honest line add
363
374
  const rawChunk = await call(captured, "notes_read", { address: "search.md", offset_chars: offset }, ctx);
364
375
  assertWithinBudget(rawChunk, `search.md chunk at ${offset}`);
365
376
  const chunk = resultRead(rawChunk);
366
- assert.equal(chunk.offset_chars, offset, "the read echoes the resolved address");
367
377
  parts.push(chunk.content);
368
378
  offset = chunk.next_offset_chars;
369
379
  }
@@ -374,25 +384,25 @@ test("notes_search ignores case, treats queries literally, and preserves origina
374
384
  const captured = makeExtension(session);
375
385
  const ctx = context(session);
376
386
  await call(captured, "notes_write", { address: "case-match.md", content: "๐Ÿ˜€ฤฐ NeEdLe.* tail" }, ctx);
377
- const found = resultData(await call(captured, "notes_search", { query: ["missing", "needle.*"], pattern: "case-match.md" }, ctx));
387
+ const found = resultData(await call(captured, "notes_search", { query: ["missing", "needle.*"], glob: "case-match.md" }, ctx));
378
388
  assert.equal(found.files.length, 1);
379
389
  assert.equal(found.files[0].matches.length, 1);
380
390
  const hit = found.files[0];
381
391
  const read = resultRead(await call(captured, "notes_read", { address: hit.address, offset_chars: hit.matches[0].offset_chars }, ctx));
382
392
  assert.equal(read.content, "NeEdLe.* tail");
383
- const absent = resultData(await call(captured, "notes_search", { query: "needle.+", pattern: "case-match.md" }, ctx));
393
+ const absent = resultData(await call(captured, "notes_search", { query: "needle.+", glob: "case-match.md" }, ctx));
384
394
  assert.deepEqual(absent.files, []);
385
395
  });
386
- test("notes_search scopes by glob pattern; a non-matching pattern is an empty page, not an error", async () => {
396
+ test("notes_search scopes by glob; a non-matching glob is an empty page, not an error", async () => {
387
397
  const session = manager();
388
398
  const captured = makeExtension(session);
389
399
  const ctx = context(session);
390
400
  await call(captured, "notes_write", { address: "deep/nested/a.md", content: "needle here" }, ctx);
391
401
  await call(captured, "notes_write", { address: "top.md", content: "needle there" }, ctx);
392
- const scoped = resultData(await call(captured, "notes_search", { query: "needle", pattern: "deep/**" }, ctx));
402
+ const scoped = resultData(await call(captured, "notes_search", { query: "needle", glob: "deep/**" }, ctx));
393
403
  assert.deepEqual(scoped.files.map((file) => file.address), ["deep/nested/a.md"], "a glob scopes the search to the subtree");
394
- const none = resultData(await call(captured, "notes_search", { query: "needle", pattern: "absent/**" }, ctx));
395
- assert.deepEqual(none.files, [], "a non-matching pattern is an empty page, not a refusal");
404
+ const none = resultData(await call(captured, "notes_search", { query: "needle", glob: "absent/**" }, ctx));
405
+ assert.deepEqual(none.files, [], "a non-matching glob is an empty page, not a refusal");
396
406
  });
397
407
  test("an over-budget mutation diff is shortened on both surfaces, and the edit still lands whole", async () => {
398
408
  const session = manager();
@@ -404,15 +414,15 @@ test("an over-budget mutation diff is shortened on both surfaces, and the edit s
404
414
  assertWithinBudget(raw, "oversized diff receipt");
405
415
  const update = resultData(raw);
406
416
  assert.equal(update.change_kind, "body");
407
- assert.equal(update.applied, 1);
408
- assert.equal(update.diff_truncated, true, "the receipt names that its own diff was shortened");
409
417
  assert.ok(update.diff.length > 0, "a shortened diff is still delivered, not emptied");
410
- assert.match(textOf(raw), /update itself was applied/, "a shortened receipt never claims the note is unchanged");
418
+ assert.ok(update.diff.endsWith("[diff truncated; update applied]"), "a shortened diff ends with the marker line");
419
+ assert.match(textOf(raw), /^updated bulk-edit\.md/, "the receipt still names the note it updated");
420
+ assert.ok(textOf(raw).includes("[diff truncated; update applied]"), "the model-facing text carries the same marker");
411
421
  assert.equal(textOf(raw).includes(`+${"b".repeat(300)}`), false, "the delivered diff prefix stops inside the first change");
412
- const body = resultRead(await call(captured, "notes_read", { address: "bulk-edit.md", limit_chars: 300 }, ctx)).content;
422
+ const body = resultRead(await call(captured, "notes_read", { address: "bulk-edit.md", max_chars: 300 }, ctx)).content;
413
423
  assert.equal(body, "b".repeat(300), "every one of the 1500 replacements was applied, not just the ones that fit the receipt");
414
424
  });
415
- test("oversized note metadata is counted out of a read instead of quietly dropped", async () => {
425
+ test("oversized note metadata is named in place instead of riding along in the envelope", async () => {
416
426
  const session = manager();
417
427
  const captured = makeExtension(session);
418
428
  const ctx = context(session);
@@ -428,12 +438,11 @@ test("oversized note metadata is counted out of a read instead of quietly droppe
428
438
  assert.equal(metadata.origin, "external");
429
439
  assert.equal("access_count" in metadata, false, "access bookkeeping stays in storage");
430
440
  assert.equal(metadata.extra.small, "kept", "a small unrecognized key is delivered");
431
- assert.equal(metadata.extra.fat, undefined, "an oversized value is not delivered in part");
432
- assert.deepEqual(metadata.omitted_extra, { keys: 1, bytes: JSON.stringify("fat").length + 1 + JSON.stringify("x".repeat(8000)).length }, "the withheld entry is summarized, never listed, and its key bytes are counted");
433
- assert.match(textOf(raw), /too large to show/, "the model-facing text says metadata was withheld");
441
+ assert.equal(metadata.extra.fat, "[omitted: too large]", "an oversized value is named in place, not hidden");
442
+ assert.match(textOf(raw), /\[omitted: too large\]/, "the model-facing metadata carries the marker too");
434
443
  assert.equal(read.total_chars, 9, "the window counts the body only, whatever the front weighs");
435
444
  });
436
- test("a giant frontmatter key is counted out of a read instead of riding along in the envelope", async () => {
445
+ test("a giant frontmatter key is left out of a read instead of riding along in the envelope", async () => {
437
446
  const session = manager();
438
447
  const captured = makeExtension(session);
439
448
  const ctx = context(session);
@@ -450,8 +459,20 @@ test("a giant frontmatter key is counted out of a read instead of riding along i
450
459
  assert.equal(read.total_chars, 0);
451
460
  assert.equal(metadata.extra.small, "kept", "a small key beside a giant one is still delivered");
452
461
  assert.equal(Object.prototype.hasOwnProperty.call(metadata.extra, giantKey), false, "the giant key is never partially delivered");
453
- assert.deepEqual(metadata.omitted_extra, { keys: 1, bytes: JSON.stringify(giantKey).length + 1 + JSON.stringify("v").length }, "the accounting covers the key and the value, not the value alone");
454
- assert.equal(metadata.omitted_extra.bytes > MAX_METADATA_ENTRY_BYTES, true, "one oversized entry is counted in full, key included");
462
+ });
463
+ test("an extra value beyond the verbatim budget is named in place, not dropped", async () => {
464
+ const session = manager();
465
+ const captured = makeExtension(session);
466
+ const ctx = context(session);
467
+ const path = physicalPath("session", "many-extras.md", ctx);
468
+ mkdirSync(dirname(path), { recursive: true });
469
+ const stamp = localIso(Date.now());
470
+ const keys = Array.from({ length: 10 }, (_, index) => `k${index}: "${"x".repeat(400)}"`).join("\n");
471
+ writeFileSync(path, `---\norigin: self\ncreatedAt: ${stamp}\nupdatedAt: ${stamp}\nlastAccessed: ${stamp}\naccessCount: 0\n${keys}\n---\n\nbody`);
472
+ const metadata = resultData(await call(captured, "notes_read", { address: "many-extras.md" }, ctx)).metadata;
473
+ assert.equal(metadata.extra.k0, "x".repeat(400), "the first extras are delivered verbatim");
474
+ assert.equal(metadata.extra.k9, "[omitted: too large]", "an extra past the verbatim budget is named, not dropped");
475
+ assert.equal(Object.keys(metadata.extra).length, 10, "every key is still accounted for");
455
476
  });
456
477
  test("an unexpected notes defect propagates with its own identity while real filesystem refusals stay structured", async () => {
457
478
  const session = manager();
@@ -485,13 +506,10 @@ test("a body that repeats one anchor thousands of times refuses with bounded, co
485
506
  assertWithinBudget(raw, "refusal with thousands of match lines");
486
507
  const refusal = resultError(raw);
487
508
  assert.equal(refusal.code, "ambiguous_edit");
509
+ assert.match(refusal.message, /edit 0:/, "the message names the failing edit index");
488
510
  assert.match(refusal.message, /occurs 5000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 4992 more\)/, "the message names a bounded sample and the exact total");
489
- assert.match(refusal.message, /names 20 of 5000 match lines/, "the receipt says its own line list is partial");
490
- assert.deepEqual(refusal.details?.line_numbers, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
491
- assert.equal(refusal.details?.line_numbers_total, repeats, "the full count travels with the sample, so nothing is silently dropped");
492
- assert.equal(refusal.details?.edit_index, 0);
493
- assert.equal(resultRead(await call(captured, "notes_read", { address: "many.md", limit_chars: 15 }, ctx)).content, "beta\n".repeat(3), "the refused edit changed nothing");
511
+ assert.equal(resultRead(await call(captured, "notes_read", { address: "many.md", max_chars: 15 }, ctx)).content, "beta\n".repeat(3), "the refused edit changed nothing");
494
512
  const replaced = resultData(await call(captured, "notes_update", { address: "many.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
495
513
  assertWithinBudget(await call(captured, "notes_read", { address: "many.md" }, ctx), "read after replace_all");
496
- assert.equal(replaced.applied, 1);
514
+ assert.equal(replaced.change_kind, "body");
497
515
  });