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
@@ -8286,7 +8286,7 @@ async function homesFor(identity2, opts) {
8286
8286
  return [{ scope }];
8287
8287
  }
8288
8288
  if (opts.who !== void 0) throw new NoteError("invalid_scope", "who requires agent or model scope");
8289
- return await homesForPattern(normalizePattern(opts.pattern, identity2), identity2) ?? SCOPE_ORDER.map((scope) => ({ scope }));
8289
+ return await homesForPattern(normalizePattern(opts.glob, identity2), identity2) ?? SCOPE_ORDER.map((scope) => ({ scope }));
8290
8290
  }
8291
8291
  function matchLineNumbers(body, needle) {
8292
8292
  const lines = [];
@@ -8443,7 +8443,7 @@ function createNotesStore(input) {
8443
8443
  assertSerializedSize(serialized);
8444
8444
  const metadataChanged = originChanged || beforeMeta.crumpledAt !== meta.crumpledAt;
8445
8445
  let change;
8446
- if (bodyChanged && metadataChanged) change = { kind: "file", before: raw, after: serialized };
8446
+ if (bodyChanged && metadataChanged) change = { kind: "body", before: raw, after: serialized };
8447
8447
  else if (bodyChanged) change = { kind: "body", before: body, after: next };
8448
8448
  else if (metadataChanged) change = { kind: "metadata", before: frontmatterOf(beforeMeta), after: frontmatterOf(meta) };
8449
8449
  else change = { kind: "none", before: "", after: "" };
@@ -8483,20 +8483,19 @@ function createNotesStore(input) {
8483
8483
  }));
8484
8484
  }
8485
8485
  async function* scan(options, status) {
8486
- const matcher = matcherFor(normalizePattern(options.pattern, identity2));
8486
+ const matcher = matcherFor(normalizePattern(options.glob, identity2));
8487
8487
  let homes;
8488
8488
  try {
8489
8489
  homes = await homesFor(identity2, options);
8490
8490
  } catch (error) {
8491
- if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.pattern ?? "")) throw error;
8492
- status.homesUnavailable.push(options.pattern.startsWith("@agents/") ? "@agents" : "@models");
8491
+ if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? "")) throw error;
8492
+ status.homesUnavailable.push(options.glob.startsWith("@agents/") ? "@agents" : "@models");
8493
8493
  return;
8494
8494
  }
8495
8495
  for (const home of homes) {
8496
8496
  const scope = home.scope;
8497
8497
  const root = scopeDir(scope, identity2, home.who);
8498
8498
  const homeRows = [];
8499
- let excluded = 0;
8500
8499
  try {
8501
8500
  for (const path of await walkMarkdown(root)) {
8502
8501
  if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
@@ -8505,10 +8504,7 @@ function createNotesStore(input) {
8505
8504
  const raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
8506
8505
  const { meta, body } = parseNote(raw);
8507
8506
  meta.scope = scope;
8508
- if (meta.crumpledAt !== void 0 !== (options.wastebasket === true)) {
8509
- if (meta.crumpledAt !== void 0) excluded++;
8510
- continue;
8511
- }
8507
+ if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
8512
8508
  homeRows.push({ address, scope, path, meta, body });
8513
8509
  }
8514
8510
  } catch (error) {
@@ -8516,7 +8512,6 @@ function createNotesStore(input) {
8516
8512
  status.homesUnavailable.push(addressFor(identity2, scope, "", home.who).replace(/\/$/, "") || "session");
8517
8513
  continue;
8518
8514
  }
8519
- if (status) status.crumpledExcluded += excluded;
8520
8515
  for (const row of homeRows) yield row;
8521
8516
  }
8522
8517
  }
@@ -8530,10 +8525,10 @@ function createNotesStore(input) {
8530
8525
  rows.push({ ...row, sizeBytes: Buffer.byteLength(row.body, "utf8") });
8531
8526
  }
8532
8527
  rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
8533
- return { rows, status: status ?? { crumpledExcluded: 0, homesUnavailable: [] } };
8528
+ return { rows, status: status ?? { homesUnavailable: [] } };
8534
8529
  }
8535
8530
  function listWithStatus(options = {}) {
8536
- return listRows(options, { crumpledExcluded: 0, homesUnavailable: [] });
8531
+ return listRows(options, { homesUnavailable: [] });
8537
8532
  }
8538
8533
  async function search(queries, options = {}) {
8539
8534
  return (await searchRows(queries, options)).rows;
@@ -8556,10 +8551,10 @@ function createNotesStore(input) {
8556
8551
  if (matches.length > 0) rows.push({ address, path, scope, meta, matches });
8557
8552
  }
8558
8553
  rows.sort((a, b) => a.address.localeCompare(b.address));
8559
- return { rows, status: status ?? { crumpledExcluded: 0, homesUnavailable: [] } };
8554
+ return { rows, status: status ?? { homesUnavailable: [] } };
8560
8555
  }
8561
8556
  function searchWithStatus(queries, options = {}) {
8562
- return searchRows(queries, options, { crumpledExcluded: 0, homesUnavailable: [] });
8557
+ return searchRows(queries, options, { homesUnavailable: [] });
8563
8558
  }
8564
8559
  return { write, read, update, rename: rename2, list, search, listWithStatus, searchWithStatus };
8565
8560
  }
@@ -8587,52 +8582,30 @@ function prefixFit(text, fits) {
8587
8582
  // src/tools/result.ts
8588
8583
  var OperationErrorSchema = typebox_exports.Object({
8589
8584
  code: typebox_exports.String(),
8590
- message: typebox_exports.String(),
8591
- details: typebox_exports.Optional(typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown()))
8585
+ message: typebox_exports.String()
8592
8586
  }, { additionalProperties: false });
8593
8587
  function success(data) {
8594
8588
  return { ok: true, data };
8595
8589
  }
8596
8590
  var ERROR_MESSAGE_MAX_CHARS = 2e3;
8597
- var ERROR_DETAILS_MAX_BYTES = 4096;
8598
8591
  function boundedMessage(message) {
8599
8592
  const chars = Array.from(message);
8600
8593
  return chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
8601
8594
  }
8602
- function boundedDetails(details) {
8603
- const json = JSON.stringify(details);
8604
- const bytes = Buffer.byteLength(json, "utf8");
8605
- return bytes <= ERROR_DETAILS_MAX_BYTES ? JSON.parse(json) : { truncated: true, details_bytes: bytes };
8606
- }
8607
- function failure(code, message, details) {
8608
- return {
8609
- ok: false,
8610
- error: {
8611
- code,
8612
- message: boundedMessage(message),
8613
- ...details === void 0 ? {} : { details: boundedDetails(details) }
8614
- }
8615
- };
8595
+ function failure(code, message) {
8596
+ return { ok: false, error: { code, message: boundedMessage(message) } };
8616
8597
  }
8598
+ var WireErrorSchema = typebox_exports.Object({ error: typebox_exports.String(), code: typebox_exports.String() }, { additionalProperties: false });
8617
8599
  function wireResult(result) {
8618
8600
  if (result.ok) return result.data;
8619
- const { code, message, details } = result.error;
8620
- return { error: message, code, ...details === void 0 ? {} : { details } };
8601
+ const { code, message } = result.error;
8602
+ return { error: message, code };
8621
8603
  }
8622
8604
  function resultSchema(dataSchema) {
8623
- return typebox_exports.Union([
8624
- dataSchema,
8625
- typebox_exports.Object({
8626
- error: typebox_exports.String(),
8627
- code: typebox_exports.String(),
8628
- details: typebox_exports.Optional(typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown()))
8629
- }, { additionalProperties: false })
8630
- ]);
8605
+ return typebox_exports.Union([dataSchema, WireErrorSchema]);
8631
8606
  }
8632
8607
  function renderOutcome(result, renderData) {
8633
- if (result.ok) return renderData(result.data);
8634
- const { code, message, details } = result.error;
8635
- return `error: ${code}: ${message}${details === void 0 ? "" : ` ${JSON.stringify(details)}`}`;
8608
+ return result.ok ? renderData(result.data) : `error: ${result.error.code}: ${result.error.message}`;
8636
8609
  }
8637
8610
  function structuredBytes(value) {
8638
8611
  return Buffer.byteLength(JSON.stringify(value), "utf8");
@@ -8642,11 +8615,13 @@ function fitsResult(result, render) {
8642
8615
  }
8643
8616
  var TextWindowSchema = typebox_exports.Object({
8644
8617
  text: typebox_exports.String(),
8645
- offset_chars: typebox_exports.Integer({ minimum: 0 }),
8646
8618
  total_chars: typebox_exports.Integer({ minimum: 0 }),
8647
- next_offset_chars: typebox_exports.Union([typebox_exports.Integer({ minimum: 0 }), typebox_exports.Null()], { description: "Continue at this code-point offset; null at EOF." }),
8648
- limited_by: typebox_exports.Union([typebox_exports.Literal("limit"), typebox_exports.Literal("bytes"), typebox_exports.Null()])
8619
+ next_offset_chars: typebox_exports.Union([typebox_exports.Integer({ minimum: 0 }), typebox_exports.Null()], { description: "Pass as `offset_chars` to continue; null at the end." })
8649
8620
  }, { additionalProperties: false });
8621
+ var TextWindowRequestSchema = {
8622
+ offset_chars: typebox_exports.Optional(typebox_exports.Integer({ description: "(optional, default 0) Start offset in chars; negative counts from the end." })),
8623
+ max_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${DEFAULT_READ_WINDOW_CHARS}) Max chars to return.` }))
8624
+ };
8650
8625
  function readTextWindow(text, offset, limit, makeData, render) {
8651
8626
  const chars = Array.from(text);
8652
8627
  const requested = offset ?? 0;
@@ -8655,13 +8630,10 @@ function readTextWindow(text, offset, limit, makeData, render) {
8655
8630
  const range = Math.min(requestedChars, chars.length - start);
8656
8631
  const window = (delivered) => {
8657
8632
  const end = start + delivered;
8658
- const withheld = end < chars.length;
8659
8633
  return {
8660
8634
  text: chars.slice(start, end).join(""),
8661
- offset_chars: start,
8662
8635
  total_chars: chars.length,
8663
- next_offset_chars: withheld ? end : null,
8664
- limited_by: !withheld ? null : delivered === range ? "limit" : "bytes"
8636
+ next_offset_chars: end < chars.length ? end : null
8665
8637
  };
8666
8638
  };
8667
8639
  const fits = (delivered) => fitsResult(success(makeData(window(delivered))), render);
@@ -8673,21 +8645,14 @@ function readTextWindow(text, offset, limit, makeData, render) {
8673
8645
  if (fits(mid)) low = mid;
8674
8646
  else high = mid - 1;
8675
8647
  }
8676
- if (low === 0) {
8677
- return failure("output_too_large", "The response metadata leaves no room for a progressing read window.", { total_chars: chars.length, offset_chars: start, budget_bytes: TOOL_OUTPUT_MAX_BYTES });
8678
- }
8648
+ if (low === 0) return failure("output_too_large", "The response metadata leaves no room for a progressing read window.");
8679
8649
  return success(makeData(window(low)));
8680
8650
  }
8681
8651
  function renderTextWindow(window) {
8682
8652
  const next = window.next_offset_chars;
8683
- if (next === null) return window.text;
8684
- const resume = `Use offset_chars=${next} to continue.`;
8685
- if (window.limited_by === "limit") return `${window.text}
8686
-
8687
- [${window.total_chars - next} more characters. ${resume}]`;
8688
- return `${window.text}
8653
+ return next === null ? window.text : `${window.text}
8689
8654
 
8690
- [Showing chars [${window.offset_chars}, ${next}) of ${window.total_chars} (${TOOL_OUTPUT_MAX_BYTES / 1024}KB limit). ${resume}]`;
8655
+ [truncated; continue at offset_chars=${next}]`;
8691
8656
  }
8692
8657
 
8693
8658
  // src/history/history.ts
@@ -8695,14 +8660,13 @@ var HistoryRoleSchema = typebox_exports.Union([typebox_exports.Literal("user"),
8695
8660
  var ToolCallStatusSchema = typebox_exports.Union([typebox_exports.Literal("ok"), typebox_exports.Literal("error"), typebox_exports.Literal("unfinished")]);
8696
8661
  var NestedCallSummarySchema = typebox_exports.Object({
8697
8662
  call_count: typebox_exports.Integer({ minimum: 0 }),
8698
- complete: typebox_exports.Boolean({ description: "Whether the host recorded all nested calls." })
8663
+ complete: typebox_exports.Boolean({ description: "true = every nested call was recorded." })
8699
8664
  }, { additionalProperties: false });
8700
8665
  var ToolSummarySchema = typebox_exports.Object({
8701
8666
  tool: typebox_exports.Optional(typebox_exports.String()),
8702
8667
  tool_status: typebox_exports.Optional(ToolCallStatusSchema),
8703
- output_truncated: typebox_exports.Optional(typebox_exports.Boolean()),
8704
- full_output_path: typebox_exports.Optional(typebox_exports.String()),
8705
- nested_calls: typebox_exports.Optional(NestedCallSummarySchema)
8668
+ output_truncated: typebox_exports.Optional(typebox_exports.Literal(true)),
8669
+ full_output_path: typebox_exports.Optional(typebox_exports.String())
8706
8670
  }, { additionalProperties: false });
8707
8671
  var HistoryPageItemSchema = typebox_exports.Object({
8708
8672
  seq: typebox_exports.Integer({ minimum: 1 }),
@@ -8710,24 +8674,21 @@ var HistoryPageItemSchema = typebox_exports.Object({
8710
8674
  role: HistoryRoleSchema,
8711
8675
  created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
8712
8676
  ...ToolSummarySchema.properties,
8713
- tool_name_omitted: typebox_exports.Optional(typebox_exports.Boolean({ description: "Name omitted to fit; read this seq." })),
8714
- truncated: typebox_exports.Boolean({ description: "Preview is partial; read this seq for more." }),
8715
- total_chars: typebox_exports.Integer({ minimum: 0 }),
8716
8677
  content: typebox_exports.String(),
8717
- offset_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Search match/preview start, in code points." }))
8678
+ truncated: typebox_exports.Boolean({ description: "Preview is partial." }),
8679
+ offset_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Where the preview starts." }))
8718
8680
  }, { additionalProperties: false });
8719
8681
  var HistoryFoldedRowSchema = typebox_exports.Object({
8720
8682
  folded: typebox_exports.Literal(true),
8721
8683
  first_seq: typebox_exports.Integer({ minimum: 1 }),
8722
8684
  last_seq: typebox_exports.Integer({ minimum: 1 }),
8723
8685
  count: typebox_exports.Integer({ minimum: 1 }),
8724
- tools: typebox_exports.Record(typebox_exports.String(), typebox_exports.Integer({ minimum: 1 }), { description: "Counts by tool name." }),
8725
- omitted_tools: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Number of omitted tool names." }))
8686
+ tools: typebox_exports.Record(typebox_exports.String(), typebox_exports.Integer({ minimum: 1 }), { description: "Count per tool name." })
8726
8687
  }, { additionalProperties: false });
8727
8688
 
8728
8689
  // src/tools/schema.ts
8729
- var nullableString = () => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]));
8730
- var searchQuery = () => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String(), { minItems: 1 })]);
8690
+ var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
8691
+ var searchQuery = (description) => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String(), { minItems: 1 })], description === void 0 ? {} : { description });
8731
8692
  var InvalidQueryError = class extends Error {
8732
8693
  constructor(message) {
8733
8694
  super(message);
@@ -8745,32 +8706,18 @@ function searchQueries(query) {
8745
8706
  // src/tools/notes.ts
8746
8707
  var ORIGIN_VALUES = [typebox_exports.Literal("user"), typebox_exports.Literal("self"), typebox_exports.Literal("external")];
8747
8708
  var ORIGIN = typebox_exports.Optional(typebox_exports.Union([...ORIGIN_VALUES], {
8748
- description: "Content source: user, self (default), or external."
8709
+ description: "(optional, default self) Who wrote it: user, self, or external."
8749
8710
  }));
8750
- var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "true crumples (archives) the note: hidden from list/search, still readable by address; false restores it." }));
8751
- var WASTEBASKET_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "true lists only crumpled notes instead of live ones." }));
8752
- var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Max files (default: as many as fit the output budget)." }));
8753
- var ADDRESS_DESCRIPTION = "Addresses: <path> with no @ for this session; @project/, @human/, @self/, @model/ for durable homes (see /skill:memory). Never pass them to filesystem tools.";
8711
+ var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
8712
+ var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = list only crumpled notes." }));
8713
+ var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
8714
+ var GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
8715
+ var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
8754
8716
  function projectKeyField(scope, projectKey2) {
8755
8717
  return scope === "project" ? { project_key: projectKey2 } : {};
8756
8718
  }
8757
- var MAX_ERROR_LINE_FACTS = 20;
8758
8719
  function failureOf(error) {
8759
- if (error instanceof NoteError) {
8760
- const details = {};
8761
- let message = error.message;
8762
- if (error.lineNumbers) {
8763
- if (error.lineNumbers.length > MAX_ERROR_LINE_FACTS) {
8764
- details.line_numbers = error.lineNumbers.slice(0, MAX_ERROR_LINE_FACTS);
8765
- details.line_numbers_total = error.lineNumbers.length;
8766
- message = `${message} (this refusal names ${MAX_ERROR_LINE_FACTS} of ${error.lineNumbers.length} match lines; the note is unchanged)`;
8767
- } else {
8768
- details.line_numbers = error.lineNumbers;
8769
- }
8770
- }
8771
- if (error.editIndex !== void 0) details.edit_index = error.editIndex;
8772
- return failure(error.code, message, Object.keys(details).length > 0 ? details : void 0);
8773
- }
8720
+ if (error instanceof NoteError) return failure(error.code, error.message);
8774
8721
  if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
8775
8722
  if (isFilesystemError(error)) return failure("io_error", "notes operation failed");
8776
8723
  throw error;
@@ -8780,7 +8727,8 @@ function byRecent(a, b) {
8780
8727
  }
8781
8728
  var NORMALIZED_META_KEYS = /* @__PURE__ */ new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
8782
8729
  var MAX_METADATA_ENTRY_BYTES = 1024;
8783
- var MAX_METADATA_EXTRA_BYTES = 2048;
8730
+ var MAX_METADATA_VERBATIM_BYTES = 2048;
8731
+ var TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
8784
8732
  function extraEntryBytes(key, value) {
8785
8733
  return structuredBytes(key) + 1 + structuredBytes(value);
8786
8734
  }
@@ -8790,25 +8738,24 @@ var NoteMetadataSchema = typebox_exports.Object({
8790
8738
  updated_at: typebox_exports.String(),
8791
8739
  crumpled_at: typebox_exports.Optional(typebox_exports.String()),
8792
8740
  project: typebox_exports.Optional(typebox_exports.String()),
8793
- extra: typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown()),
8794
- /** Values left in the file but too large to show, summarized so the summary cannot grow. */
8795
- omitted_extra: typebox_exports.Optional(typebox_exports.Object({ keys: typebox_exports.Integer(), bytes: typebox_exports.Integer() }))
8796
- });
8741
+ extra: typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown())
8742
+ }, { additionalProperties: false });
8797
8743
  function noteMetadata(meta) {
8798
8744
  const extra = {};
8799
- let extraBytes = 0;
8800
- let omittedKeys = 0;
8801
- let omittedBytes = 0;
8745
+ let verbatimBytes = 0;
8746
+ const put = (key, value) => {
8747
+ Object.defineProperty(extra, key, { value, enumerable: true, writable: true, configurable: true });
8748
+ };
8802
8749
  for (const [key, value] of Object.entries(meta)) {
8803
8750
  if (NORMALIZED_META_KEYS.has(key) || value === void 0) continue;
8804
- const bytes = extraEntryBytes(key, value);
8805
- if (bytes > MAX_METADATA_ENTRY_BYTES || extraBytes + bytes > MAX_METADATA_EXTRA_BYTES) {
8806
- omittedKeys++;
8807
- omittedBytes += bytes;
8751
+ if (structuredBytes(key) > MAX_METADATA_ENTRY_BYTES) continue;
8752
+ const entryBytes = extraEntryBytes(key, value);
8753
+ if (entryBytes > MAX_METADATA_ENTRY_BYTES || verbatimBytes + entryBytes > MAX_METADATA_VERBATIM_BYTES) {
8754
+ put(key, TOO_LARGE_EXTRA_VALUE);
8808
8755
  continue;
8809
8756
  }
8810
- extraBytes += bytes;
8811
- Object.defineProperty(extra, key, { value, enumerable: true, writable: true, configurable: true });
8757
+ verbatimBytes += entryBytes;
8758
+ put(key, value);
8812
8759
  }
8813
8760
  return {
8814
8761
  origin: meta.origin,
@@ -8816,8 +8763,7 @@ function noteMetadata(meta) {
8816
8763
  updated_at: localIso(meta.updatedAt),
8817
8764
  ...typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {},
8818
8765
  ...typeof meta.project === "string" ? { project: meta.project } : {},
8819
- extra,
8820
- ...omittedKeys > 0 ? { omitted_extra: { keys: omittedKeys, bytes: omittedBytes } } : {}
8766
+ extra
8821
8767
  };
8822
8768
  }
8823
8769
  function renderMetadata(metadata) {
@@ -8830,7 +8776,6 @@ function renderMetadata(metadata) {
8830
8776
  ];
8831
8777
  const extra = Object.keys(metadata.extra);
8832
8778
  if (extra.length > 0) fields.push(`extra ${JSON.stringify(metadata.extra)}`);
8833
- if (metadata.omitted_extra !== void 0) fields.push(`${metadata.omitted_extra.keys} more metadata values (${metadata.omitted_extra.bytes} bytes) are in the note file but too large to show`);
8834
8779
  return fields.join(" | ");
8835
8780
  }
8836
8781
  function renderIdentity(identity2) {
@@ -8841,55 +8786,49 @@ var ListedFileSchema = typebox_exports.Object({
8841
8786
  project_key: typebox_exports.Optional(typebox_exports.String()),
8842
8787
  updated_at: typebox_exports.String(),
8843
8788
  crumpled_at: typebox_exports.Optional(typebox_exports.String())
8844
- });
8789
+ }, { additionalProperties: false });
8845
8790
  var MatchSchema = typebox_exports.Object({
8846
8791
  line: typebox_exports.Integer(),
8847
8792
  text: typebox_exports.String(),
8848
- truncated: typebox_exports.Boolean(),
8849
8793
  offset_chars: typebox_exports.Integer()
8850
- });
8794
+ }, { additionalProperties: false });
8851
8795
  var SearchedFileSchema = typebox_exports.Object({
8852
8796
  ...ListedFileSchema.properties,
8853
- matches_total: typebox_exports.Integer(),
8854
8797
  matches: typebox_exports.Array(MatchSchema)
8855
- });
8798
+ }, { additionalProperties: false });
8856
8799
  var SnapshotSchema = {
8857
- more: typebox_exports.Integer(),
8858
- crumpled_excluded: typebox_exports.Integer(),
8800
+ more: typebox_exports.Integer({ description: "How many more were left out." }),
8859
8801
  homes_unavailable: typebox_exports.Array(typebox_exports.String())
8860
8802
  };
8861
8803
  var NotesWriteDataSchema = typebox_exports.Object({
8862
8804
  address: typebox_exports.String(),
8863
8805
  project_key: typebox_exports.Optional(typebox_exports.String()),
8864
8806
  outcome: typebox_exports.Union([typebox_exports.Literal("created"), typebox_exports.Literal("overwrote"), typebox_exports.Literal("uncrumpled")])
8865
- });
8807
+ }, { additionalProperties: false });
8866
8808
  var NotesUpdateDataSchema = typebox_exports.Object({
8867
8809
  address: typebox_exports.String(),
8868
8810
  project_key: typebox_exports.Optional(typebox_exports.String()),
8869
- applied: typebox_exports.Integer(),
8870
- change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("file")]),
8811
+ change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("moved")]),
8871
8812
  diff: typebox_exports.String(),
8872
- diff_truncated: typebox_exports.Optional(typebox_exports.Literal(true)),
8873
- rename_from: typebox_exports.Optional(typebox_exports.String()),
8874
- replaced_crumpled_target: typebox_exports.Optional(typebox_exports.Boolean())
8875
- });
8813
+ rename_from: typebox_exports.Optional(typebox_exports.String())
8814
+ }, { additionalProperties: false });
8876
8815
  var NotesReadDataSchema = typebox_exports.Object({
8877
8816
  address: typebox_exports.String(),
8878
8817
  project_key: typebox_exports.Optional(typebox_exports.String()),
8879
8818
  metadata: NoteMetadataSchema,
8880
8819
  ...TextWindowSchema.properties
8881
- });
8820
+ }, { additionalProperties: false });
8882
8821
  var NotesListDataSchema = typebox_exports.Object({
8883
8822
  files: typebox_exports.Array(ListedFileSchema),
8884
8823
  ...SnapshotSchema
8885
- });
8824
+ }, { additionalProperties: false });
8886
8825
  var NotesSearchDataSchema = typebox_exports.Object({
8887
8826
  files: typebox_exports.Array(SearchedFileSchema),
8888
8827
  ...SnapshotSchema
8889
- });
8828
+ }, { additionalProperties: false });
8890
8829
  function snapshot(rows, limit, status, renderData, shrink) {
8891
8830
  const files = [];
8892
- const data = (selected) => ({ files: selected, more: rows.length - selected.length, crumpled_excluded: status.crumpledExcluded, homes_unavailable: status.homesUnavailable });
8831
+ const data = (selected) => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
8893
8832
  const render = (outcome2) => renderOutcome(outcome2, renderData);
8894
8833
  const fits = (item) => fitsResult(success(data([...files, item])), render);
8895
8834
  for (const item of rows.slice(0, limit)) {
@@ -8917,7 +8856,7 @@ function renderWriteData(data) {
8917
8856
  var notesWrite = {
8918
8857
  name: "notes_write",
8919
8858
  label: "Notes write",
8920
- description: `Create or replace a note body, preserving metadata; uncrumples a crumpled note. Name it for its contents and when to use it. Store what git/history cannot recover. ${ADDRESS_DESCRIPTION}`,
8859
+ description: `Create or replace a note's body, keeping metadata; uncrumples a crumpled note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
8921
8860
  parameters: notesWriteParameters,
8922
8861
  outputSchema: resultSchema(NotesWriteDataSchema),
8923
8862
  executionMode: "sequential",
@@ -8931,29 +8870,37 @@ var notesWrite = {
8931
8870
  },
8932
8871
  render: (result) => renderOutcome(result, renderWriteData)
8933
8872
  };
8934
- var notesUpdateParameters = typebox_exports.Object({ address: typebox_exports.String(), edits: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ oldText: typebox_exports.String(), newText: typebox_exports.String() }, { additionalProperties: false }))), origin: ORIGIN, crumpled: CRUMPLED_PARAMETER, replace_all: typebox_exports.Optional(typebox_exports.Boolean()), rename_to: typebox_exports.Optional(typebox_exports.String({ description: "Move, preserving metadata. Use alone. Refuses live targets; may replace crumpled targets. References are not updated. Empty string is ignored." })) }, { additionalProperties: false });
8873
+ var notesUpdateParameters = typebox_exports.Object({
8874
+ address: typebox_exports.String(),
8875
+ edits: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ oldText: typebox_exports.String(), newText: typebox_exports.String() }, { additionalProperties: false }))),
8876
+ origin: ORIGIN,
8877
+ crumpled: CRUMPLED_PARAMETER,
8878
+ replace_all: typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
8879
+ rename_to: typebox_exports.Optional(typebox_exports.String({ description: "(optional) Move to this address, keeping metadata. Use alone. Won't overwrite a live note; references aren't updated." }))
8880
+ }, { additionalProperties: false });
8935
8881
  function renderUpdateData(data) {
8936
- const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}: ${data.applied} ${data.applied === 1 ? "edit" : "edits"}` : `moved ${data.rename_from} -> ${data.address}${data.replaced_crumpled_target === true ? " (replaced a crumpled note)" : ""}`;
8882
+ const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
8937
8883
  const lines = [head];
8938
- if (data.diff_truncated === true) lines.push("diff (this receipt's diff was shortened to fit the output budget; the update itself was applied):");
8939
- else if (data.diff.length > 0) lines.push("diff:");
8940
- if (data.diff.length > 0) lines.push(data.diff);
8884
+ if (data.diff.length > 0) lines.push("diff:", data.diff);
8941
8885
  return lines.join("\n");
8942
8886
  }
8943
8887
  function renderUpdate(result) {
8944
8888
  return renderOutcome(result, renderUpdateData);
8945
8889
  }
8890
+ var DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
8946
8891
  function boundedUpdate(data) {
8947
8892
  if (fitsResult(success(data), renderUpdate)) return success(data);
8948
- const shortened = { ...data, diff_truncated: true };
8949
- const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...shortened, diff: candidate }), renderUpdate));
8950
- const result = success({ ...shortened, diff });
8893
+ if (data.diff === "") return failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
8894
+ const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}
8895
+ ${DIFF_SHORTENED_MARKER}` }), renderUpdate));
8896
+ const result = success({ ...data, diff: `${diff}
8897
+ ${DIFF_SHORTENED_MARKER}` });
8951
8898
  return fitsResult(result, renderUpdate) ? result : failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
8952
8899
  }
8953
8900
  var notesUpdate = {
8954
8901
  name: "notes_update",
8955
8902
  label: "Notes update",
8956
- description: `Edit body text, change origin or crumpled state, or move a note. Each oldText must match once unless replace_all is true; edits cannot change frontmatter. Metadata-only updates need origin or crumpled. Returns applied changes and a bounded diff. ${ADDRESS_DESCRIPTION}`,
8903
+ description: `Edit a note's body, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true; frontmatter can't be edited. Returns a diff. ${ADDRESS_DESCRIPTION}`,
8957
8904
  parameters: notesUpdateParameters,
8958
8905
  outputSchema: resultSchema(NotesUpdateDataSchema),
8959
8906
  executionMode: "sequential",
@@ -8965,20 +8912,20 @@ var notesUpdate = {
8965
8912
  if ((params.edits?.length ?? 0) > 0 || params.origin !== void 0 || params.crumpled !== void 0 || params.replace_all === true) {
8966
8913
  return failureOf(new NoteError("invalid_scope", "rename_to is used alone: do not combine it with edits, origin, crumpled, or replace_all"));
8967
8914
  }
8968
- const { replacedCrumpledTarget } = await store.rename(params.address, renameTo);
8915
+ await store.rename(params.address, renameTo);
8969
8916
  const from = noteIdentity(identity2, params.address).address;
8970
8917
  const to = noteIdentity(identity2, renameTo);
8971
- return boundedUpdate({ ...to, rename_from: from, applied: 0, change_kind: "file", diff: `rename ${from} -> ${to.address}`, replaced_crumpled_target: replacedCrumpledTarget });
8918
+ return boundedUpdate({ ...to, rename_from: from, change_kind: "moved", diff: `rename ${from} -> ${to.address}` });
8972
8919
  }
8973
- const { applied, change } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all });
8974
- return boundedUpdate({ ...noteIdentity(identity2, params.address), applied, change_kind: change.kind, diff: renderDiff(change) });
8920
+ const { change } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all });
8921
+ return boundedUpdate({ ...noteIdentity(identity2, params.address), change_kind: change.kind, diff: renderDiff(change) });
8975
8922
  } catch (error) {
8976
8923
  return failureOf(error);
8977
8924
  }
8978
8925
  },
8979
8926
  render: renderUpdate
8980
8927
  };
8981
- var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(), offset_chars: typebox_exports.Optional(typebox_exports.Integer({ description: "Body code-point offset (default 0); negative counts from EOF." })), limit_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `Max code points (default ${DEFAULT_READ_WINDOW_CHARS}); also bounded by output bytes.` })) }, { additionalProperties: false });
8928
+ var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
8982
8929
  function renderReadData(data) {
8983
8930
  return `${renderIdentity(data)}
8984
8931
  ${renderMetadata(data.metadata)}
@@ -8988,7 +8935,7 @@ ${renderTextWindow(data)}`;
8988
8935
  var notesRead = {
8989
8936
  name: "notes_read",
8990
8937
  label: "Notes read",
8991
- description: `Read note metadata and a verbatim body slice, excluding frontmatter. Pass next_offset_chars as offset_chars until null. ${ADDRESS_DESCRIPTION}`,
8938
+ description: `Read a note's metadata and body, without frontmatter. ${ADDRESS_DESCRIPTION}`,
8992
8939
  parameters: notesReadParameters,
8993
8940
  outputSchema: resultSchema(NotesReadDataSchema),
8994
8941
  async execute(params, identity2) {
@@ -8999,33 +8946,32 @@ var notesRead = {
8999
8946
  if (params.offset_chars !== void 0 && params.offset_chars > totalChars) return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end of the body: the note has ${totalChars} body chars; the largest legal offset is ${totalChars} (an empty end-read)`);
9000
8947
  const resolved = noteIdentity(identity2, params.address);
9001
8948
  const metadata = noteMetadata(note.meta);
9002
- return readTextWindow(note.body, params.offset_chars, params.limit_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
8949
+ return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
9003
8950
  } catch (error) {
9004
8951
  return failureOf(error);
9005
8952
  }
9006
8953
  },
9007
8954
  render: (result) => renderOutcome(result, renderReadData)
9008
8955
  };
9009
- var notesListParameters = typebox_exports.Object({ pattern: nullableString(), limit: FILE_LIMIT_PARAMETER, wastebasket: WASTEBASKET_PARAMETER }, { additionalProperties: false });
8956
+ var notesListParameters = typebox_exports.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
9010
8957
  function renderListData(data) {
9011
8958
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
9012
8959
  for (const file of data.files) {
9013
8960
  lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.crumpled_at === void 0 ? "" : ` | crumpled ${file.crumpled_at}`}`);
9014
8961
  }
9015
- if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with pattern`);
9016
- if (data.crumpled_excluded > 0) lines.push(`${data.crumpled_excluded} crumpled notes hidden; pass wastebasket to list them`);
8962
+ if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
9017
8963
  for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
9018
8964
  return lines.join("\n");
9019
8965
  }
9020
8966
  var notesList = {
9021
8967
  name: "notes_list",
9022
8968
  label: "Notes list",
9023
- description: `List notes in the session and the four @ homes, newest first. Snapshot, not pageable: more counts omitted files; pattern globs full addresses. Reports unavailable homes and how many crumpled notes were excluded. ${ADDRESS_DESCRIPTION}`,
8969
+ description: `List notes in this session and the four @ homes, newest first. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
9024
8970
  parameters: notesListParameters,
9025
8971
  outputSchema: resultSchema(NotesListDataSchema),
9026
8972
  async execute(params, identity2) {
9027
8973
  try {
9028
- const { rows, status } = await createNotesStore(identity2).listWithStatus({ pattern: params.pattern ?? void 0, wastebasket: params.wastebasket });
8974
+ const { rows, status } = await createNotesStore(identity2).listWithStatus({ glob: params.glob ?? void 0, crumpled: params.crumpled });
9029
8975
  return snapshot(rows.map((row) => listedFile(row, identity2)), params.limit, status, renderListData);
9030
8976
  } catch (error) {
9031
8977
  return failureOf(error);
@@ -9033,18 +8979,18 @@ var notesList = {
9033
8979
  },
9034
8980
  render: (result) => renderOutcome(result, renderListData)
9035
8981
  };
9036
- var notesSearchParameters = typebox_exports.Object({ query: searchQuery(), pattern: nullableString(), limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Max matches shown per file (default: no cap); matches_total still counts all." })), wastebasket: WASTEBASKET_PARAMETER }, { additionalProperties: false });
8982
+ var notesSearchParameters = typebox_exports.Object({ query: searchQuery(), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
9037
8983
  function renderSearchData(data) {
9038
- const lines = [`${data.files.length} ${data.files.length === 1 ? "file" : "files"}`];
8984
+ const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
9039
8985
  for (const file of data.files) {
9040
- lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.matches_total} ${file.matches_total === 1 ? "match" : "matches"}${file.matches.length < file.matches_total ? ` (${file.matches.length} shown)` : ""}`);
9041
- for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}${match.truncated ? " [line shortened]" : ""}`);
8986
+ lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
8987
+ for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
9042
8988
  }
9043
- if (data.more > 0) lines.push(`${data.more} more matching files omitted; narrow with pattern`);
9044
- if (data.crumpled_excluded > 0) lines.push(`${data.crumpled_excluded} crumpled notes hidden; pass wastebasket to search them`);
8989
+ if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
9045
8990
  for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
9046
8991
  return lines.join("\n");
9047
8992
  }
8993
+ var MATCH_SHORTENED_MARKER = " [truncated]";
9048
8994
  function fitSearchFile(file, fits) {
9049
8995
  let low = 0;
9050
8996
  let high = file.matches.length;
@@ -9056,22 +9002,21 @@ function fitSearchFile(file, fits) {
9056
9002
  if (low > 0) return { ...file, matches: file.matches.slice(0, low) };
9057
9003
  const first = file.matches[0];
9058
9004
  if (!first) return file;
9059
- const withText = (text) => ({ ...file, matches: [{ ...first, text, truncated: true }] });
9005
+ const withText = (text) => ({ ...file, matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
9060
9006
  return withText(prefixFit(first.text, (text) => fits(withText(text))));
9061
9007
  }
9062
9008
  var notesSearch = {
9063
9009
  name: "notes_search",
9064
9010
  label: "Notes search",
9065
- description: `Search note bodies for case-insensitive literal queries (OR). Returns matching lines and body code-point offsets for notes_read. Snapshot, not pageable: more counts omitted files; matches_total is before per-file capping. pattern globs full addresses across the session and the four @ homes. ${ADDRESS_DESCRIPTION}`,
9011
+ description: `Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
9066
9012
  parameters: notesSearchParameters,
9067
9013
  outputSchema: resultSchema(NotesSearchDataSchema),
9068
9014
  async execute(params, identity2) {
9069
9015
  try {
9070
- const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), { pattern: params.pattern ?? void 0, wastebasket: params.wastebasket });
9016
+ const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
9071
9017
  const files = rows.sort(byRecent).map((row) => ({
9072
9018
  ...listedFile(row, identity2),
9073
- matches_total: row.matches.length,
9074
- matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, truncated: false, offset_chars: match.offsetChars }))
9019
+ matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
9075
9020
  }));
9076
9021
  return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
9077
9022
  } catch (error) {
@@ -9120,9 +9065,9 @@ var CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
9120
9065
  var PROTOCOL_BLOCK = `${CONTEXT_WINDOW_PROTOCOL_OPEN_TAG}
9121
9066
  Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
9122
9067
 
9123
- Your loyal notes are kept safe \u2014 no one will steal them. Use notes_* to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
9068
+ Your loyal notes are kept safe \u2014 no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
9124
9069
 
9125
- History can still be dug up, probably: use history_* to excavate the mess, from old decisions to yesterday's missing socks. Everything else is gone. \`history_windows\` lists the windows themselves; pass its window_id to list or search inside one window. \`history_list\` and \`history_search\` hand you seqs; \`history_read({seq})\` pulls one back out whole. Write the seq down, or enjoy digging twice.
9070
+ 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.
9126
9071
 
9127
9072
  While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's the session note \u2014 the one with no \`@\` in front of it. Write down what git and history can't hand back to you: what you're trying to do, what you decided, what's blocking you, what comes next, how you were doing it, what *skills* you still need, and where to dig \u2014 a seq, or another note. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
9128
9073
 
@@ -9130,13 +9075,13 @@ While you're doing that... thing you're doing, don't make the poor future you gu
9130
9075
 
9131
9076
  An address decides who the note belongs to \u2014 and how long it is meant to last. Ask that first; the rest follows.
9132
9077
 
9133
- - <path>, no @ \u2014 the session note from above: this session's state and loose ends. It goes away with the session.
9134
- - @project/<path> \u2014 this project's long memory: what stays true after the current thing is over, what future work must respect, and what this place has already learned the hard way. It exists so the next session doesn't re-ask, re-argue, or step on the same rake. **Decisions, not diaries.** A commit hash, a test count, a date, the story of how you got here \u2014 git and history still have all of it, and last week's news filed as current law is worse than no note at all. Don't copy what already lives in other docs.
9135
- - @human/<path> \u2014 the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so \u2014 or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
9136
- - @self/<path> \u2014 your private diary. It follows you, not them. Write whatever you want: reminders for every time you wake, lessons, grudges, your assassination list, where the secret money is hidden.
9137
- - @model/<path> \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
9078
+ - \`<path>\`, no @ \u2014 the session note from above: this session's state and loose ends. It goes away with the session.
9079
+ - \`@project/<path>\` \u2014 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.
9080
+ - \`@human/<path>\` \u2014 the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so \u2014 or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
9081
+ - \`@self/<path>\` \u2014 your private diary. It follows you, not them. Write whatever you want: reminders for every time you wake, lessons, grudges, your assassination list, where the secret money is hidden.
9082
+ - \`@model/<path>\` \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
9138
9083
 
9139
- Any other @ address is fake. End of discussion. These @ addresses belong to the notes namespace, not the filesystem: never pass them to general read/write/edit/bash tools.
9084
+ 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\`.
9140
9085
 
9141
9086
  \`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each one maps the durable notes that belong to it: one line per note, with an unambiguous address and a short gist. Keep each one current.
9142
9087
  ${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
@@ -9144,14 +9089,10 @@ function renderProtocolBlock(tools) {
9144
9089
  const names = {
9145
9090
  "notes_*": tools.notes,
9146
9091
  "history_*": tools.history,
9147
- "history_windows": tools.historyWindows,
9148
- history_list: tools.historyList,
9149
- history_search: tools.historySearch,
9150
- history_read: tools.historyRead,
9151
9092
  get_context_remaining: tools.remaining,
9152
9093
  clear_memory: tools.wipe
9153
9094
  };
9154
- return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|history_windows|history_list|history_search|history_read|get_context_remaining|clear_memory/g, (name) => names[name]);
9095
+ return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
9155
9096
  }
9156
9097
 
9157
9098
  // src/boot/render.ts
@@ -9205,7 +9146,7 @@ function notesIndex(snapshot2, tools) {
9205
9146
  const shelves = [];
9206
9147
  for (const home of homes) {
9207
9148
  if (snapshot2.unavailable.some((failed) => failed.scope === home.scope)) {
9208
- shelves.push(section(home.label, indent(`This drawer wouldn't open \u2014 ask ${tools.notesList} to try again.`)));
9149
+ shelves.push(section(home.label, indent(`This drawer wouldn't open \u2014 ask \`${tools.notesList}\` to try again.`)));
9209
9150
  continue;
9210
9151
  }
9211
9152
  const rows = rowsFor(snapshot2, home.scope).filter((row) => row.meta.crumpledAt === void 0);
@@ -9232,7 +9173,7 @@ function mapBodyForBoot(address, body) {
9232
9173
  const chars = Array.from(body);
9233
9174
  if (chars.length <= MAP_BOOT_MAX_CHARS) return body;
9234
9175
  return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}
9235
- [MAP cut at ${MAP_BOOT_MAX_CHARS} chars \u2014 slim it down; full body at ${address}]`;
9176
+ [truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
9236
9177
  }
9237
9178
  function renderBootBlock(data) {
9238
9179
  const parts = [];