@mulmoclaude/core 4.1.0 → 4.2.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 (48) hide show
  1. package/assets/helps/collection-skills.md +19 -0
  2. package/assets/helps/error-recovery.md +63 -0
  3. package/dist/collection/core/calendarGrid.d.ts +2 -2
  4. package/dist/collection/core/serverTime.d.ts +93 -0
  5. package/dist/collection/index.cjs +9 -2
  6. package/dist/collection/index.d.ts +1 -0
  7. package/dist/collection/index.js +3 -3
  8. package/dist/collection/registry/server/index.cjs +2 -2
  9. package/dist/collection/registry/server/index.js +2 -2
  10. package/dist/collection/server/index.cjs +5 -3
  11. package/dist/collection/server/index.js +4 -4
  12. package/dist/collection/server/manageTool.d.ts +29 -0
  13. package/dist/collection-watchers/index.cjs +4 -4
  14. package/dist/collection-watchers/index.js +4 -4
  15. package/dist/{discovery-B9EESjHP.cjs → discovery-Dl9nRa-m.cjs} +38 -20
  16. package/dist/discovery-Dl9nRa-m.cjs.map +1 -0
  17. package/dist/{discovery-D88x2DmW.js → discovery-P64fgtuD.js} +38 -20
  18. package/dist/discovery-P64fgtuD.js.map +1 -0
  19. package/dist/feeds/index.cjs +2 -2
  20. package/dist/feeds/index.js +2 -2
  21. package/dist/feeds/server/index.cjs +4 -4
  22. package/dist/feeds/server/index.js +4 -4
  23. package/dist/google/index.cjs +2 -2
  24. package/dist/google/index.js +4 -4
  25. package/dist/google/index.js.map +1 -1
  26. package/dist/{ingestTypes-B312BwXg.js → ingestTypes-CIy1lHjf.js} +2 -2
  27. package/dist/{ingestTypes-B312BwXg.js.map → ingestTypes-CIy1lHjf.js.map} +1 -1
  28. package/dist/{ingestTypes-B4XfrUoq.cjs → ingestTypes-CaX7_s-K.cjs} +2 -2
  29. package/dist/{ingestTypes-B4XfrUoq.cjs.map → ingestTypes-CaX7_s-K.cjs.map} +1 -1
  30. package/dist/{itemId-DfTm08jm.js → itemId-BY2YPBkT.js} +200 -6
  31. package/dist/itemId-BY2YPBkT.js.map +1 -0
  32. package/dist/{itemId-Dzrr3vs5.cjs → itemId-CEQdK01z.cjs} +241 -5
  33. package/dist/itemId-CEQdK01z.cjs.map +1 -0
  34. package/dist/{promptSafety-CJ-sC1pX.js → promptSafety-Bp780ezk.js} +2 -2
  35. package/dist/{promptSafety-CJ-sC1pX.js.map → promptSafety-Bp780ezk.js.map} +1 -1
  36. package/dist/{promptSafety-CuczAN9d.cjs → promptSafety-C0BWDsfT.cjs} +2 -2
  37. package/dist/{promptSafety-CuczAN9d.cjs.map → promptSafety-C0BWDsfT.cjs.map} +1 -1
  38. package/dist/{server-dijB4BYv.js → server-C-Ngd3g2.js} +218 -14
  39. package/dist/server-C-Ngd3g2.js.map +1 -0
  40. package/dist/{server-DSrRdPvf.cjs → server-DZkN0GGh.cjs} +228 -12
  41. package/dist/server-DZkN0GGh.cjs.map +1 -0
  42. package/package.json +1 -1
  43. package/dist/discovery-B9EESjHP.cjs.map +0 -1
  44. package/dist/discovery-D88x2DmW.js.map +0 -1
  45. package/dist/itemId-DfTm08jm.js.map +0 -1
  46. package/dist/itemId-Dzrr3vs5.cjs.map +0 -1
  47. package/dist/server-DSrRdPvf.cjs.map +0 -1
  48. package/dist/server-dijB4BYv.js.map +0 -1
@@ -2,11 +2,12 @@ const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
2
2
  const require_dist = require("./dist-CsgSfWwR.cjs");
3
3
  const require_root = require("./root-rPH6FGDT.cjs");
4
4
  const require_relPath = require("./relPath-CTAjGdCL.cjs");
5
- const require_itemId = require("./itemId-Dzrr3vs5.cjs");
6
- const require_promptSafety = require("./promptSafety-CuczAN9d.cjs");
7
- const require_discovery = require("./discovery-B9EESjHP.cjs");
5
+ const require_itemId = require("./itemId-CEQdK01z.cjs");
6
+ const require_promptSafety = require("./promptSafety-C0BWDsfT.cjs");
7
+ const require_discovery = require("./discovery-Dl9nRa-m.cjs");
8
8
  const require_feeds_paths = require("./feeds/paths.cjs");
9
9
  const require_skill_bridge_index = require("./skill-bridge/index.cjs");
10
+ let node_fs = require("node:fs");
10
11
  let node_path = require("node:path");
11
12
  node_path = require_rolldown_runtime.__toESM(node_path, 1);
12
13
  let node_crypto = require("node:crypto");
@@ -394,13 +395,16 @@ function enforcedProblem(key, spec, value) {
394
395
  * outside the canonical `YYYY-MM-DDTHH:MM[:SS]` shape (e.g. a `Z` suffix,
395
396
  * which the day view can't place). `string`-backed types accept anything
396
397
  * stringifiable; `ref` existence is out of scope. */
398
+ /** Named in the lint's own message, so the shape is shown rather than
399
+ * described. */
400
+ var CANONICAL_SERVER_TIME_EXAMPLE = "2026-08-15T01:45:54.605987654Z";
397
401
  function strictTypeProblem(key, spec, value) {
398
402
  switch (spec.type) {
399
403
  case "number":
400
404
  case "money": return Number.isFinite(require_promptSafety.coerceNumeric(value)) ? null : `'${key}' = '${String(value)}' is not numeric (a '${spec.type}' field stores a plain number)`;
401
405
  case "boolean": return value === true || value === false ? null : `'${key}' = '${String(value)}' is not a boolean (store true or false, unquoted)`;
402
406
  case "date": return require_itemId.parseIsoDate(value) !== null ? null : `'${key}' = '${String(value)}' is not a real YYYY-MM-DD date`;
403
- case "datetime": return require_itemId.parseIsoDateTime(value) !== null ? null : `'${key}' = '${String(value)}' is not a YYYY-MM-DDTHH:MM datetime (seconds optional, no timezone suffix — the shape the calendar parses)`;
407
+ case "datetime": return require_itemId.parseIsoDateTime(value) !== null || require_itemId.isCanonicalServerTime(value) ? null : `'${key}' = '${String(value)}' is not a YYYY-MM-DDTHH:MM datetime (seconds optional, no timezone suffix — the shape the calendar parses), nor a server-stamped instant (${CANONICAL_SERVER_TIME_EXAMPLE})`;
404
408
  default: return null;
405
409
  }
406
410
  }
@@ -1558,6 +1562,26 @@ var SCHEMA_FILE = "schema.json";
1558
1562
  var SCHEMA_DOCS_FILE = "collection-skills.md";
1559
1563
  /** Cap the rejected-schema issue list so a deeply-broken schema can't flood the result. */
1560
1564
  var MAX_SCHEMA_ISSUES = 20;
1565
+ /** Cap the rows one putItems call may write. `putOneItem` validates and
1566
+ * writes one record at a time, so a large `itemsFile` holds the tool call
1567
+ * open for minutes. Over the cap the call is refused WHOLE — a truncating
1568
+ * write that reported success would leave a half-filled collection nobody
1569
+ * knows is half-filled. */
1570
+ var MAX_PUT_ITEMS = 1e3;
1571
+ /** Refuse an `itemsFile` larger than this, from `stat` and before any read.
1572
+ * The row cap alone cannot bound the work: the file has to be read and parsed
1573
+ * WHOLE before there are rows to count, so a huge blob is paid for in full
1574
+ * first. 8 MiB is far past what 1000 records need and far short of trouble. */
1575
+ var MAX_ITEMS_FILE_BYTES = 8388608;
1576
+ /** `itemsFile` is opened read-only, without following a symlink, and without
1577
+ * blocking on a fifo — see `openContainedItemsFile`.
1578
+ *
1579
+ * `O_NOFOLLOW` and `O_NONBLOCK` are POSIX-only: on Windows they are absent, and
1580
+ * `x | undefined` is `x`, so the flags silently soften to a plain read-only
1581
+ * open. They are hardening where they exist, never the guarantee — the symlink
1582
+ * refusal is an explicit `lstat` (`verifyOpenedItemsFile`) so it holds on every
1583
+ * platform. `?? 0` states that rather than leaving it to coercion. */
1584
+ var OPEN_ITEMS_FILE_FLAGS = node_fs.constants.O_RDONLY | (node_fs.constants.O_NOFOLLOW ?? 0) | (node_fs.constants.O_NONBLOCK ?? 0);
1561
1585
  /** The workspace help-docs dir both hosts seed (`@mulmoclaude/core/workspace-setup`
1562
1586
  * syncs the bundled assets here) — the user-editable copy schemaDocs prefers. */
1563
1587
  var HELPS_DIR = "config/helps";
@@ -1758,13 +1782,167 @@ async function handleQueryItems(collection, queryArg, deps) {
1758
1782
  rows
1759
1783
  });
1760
1784
  }
1785
+ /** Rewrite a sandbox-mount prefix to the host's workspace root, so the path the
1786
+ * agent wrote to and the file this process reads are the same bytes. Anything
1787
+ * not under the mount is returned untouched — a host with no sandbox hands the
1788
+ * agent real paths already. */
1789
+ function toHostWorkspacePath(absPath, sandboxRoot, workspaceRoot) {
1790
+ if (!sandboxRoot) return absPath;
1791
+ if (absPath === sandboxRoot) return workspaceRoot;
1792
+ const prefix = sandboxRoot.endsWith("/") ? sandboxRoot : `${sandboxRoot}/`;
1793
+ if (!absPath.startsWith(prefix)) return absPath;
1794
+ return node_path.default.join(workspaceRoot, ...absPath.slice(prefix.length).split("/"));
1795
+ }
1796
+ /** The host path an `itemsFile` names — translated out of the sandbox, and
1797
+ * required to land INSIDE the workspace.
1798
+ *
1799
+ * Containment is not tidiness. `manageCollection` is always available to a
1800
+ * sandboxed agent, and an unconstrained absolute path would turn this
1801
+ * host-side handler into a read primitive for the whole host filesystem —
1802
+ * point it at any JSON array the server user can open, store the rows, read
1803
+ * them back with `getItems`. The sandbox mounts a few app directories besides
1804
+ * the workspace, but nothing that gives the agent that reach, and the
1805
+ * workspace is where its own generated files land — so confining reads to it
1806
+ * denies the primitive without costing the feature anything.
1807
+ *
1808
+ * This is the CHEAP check, for the ordinary case and a precise message. The
1809
+ * binding one is on the opened descriptor (`verifyOpenedItemsFile`) — a path
1810
+ * checked here and read again later is a path that can change in between. */
1811
+ function resolveItemsFilePath(itemsFile, deps) {
1812
+ const root = resolveBase(deps);
1813
+ const hostPath = toHostWorkspacePath(itemsFile, deps.sandboxWorkspacePath, root);
1814
+ if (!require_discovery.isContainedInRoot(hostPath, root)) return outsideWorkspaceRefusal(require_promptSafety.defangForPrompt(itemsFile));
1815
+ return { hostPath };
1816
+ }
1817
+ function outsideWorkspaceRefusal(shown) {
1818
+ return `manageCollection: \`itemsFile\` must be inside the workspace — '${shown}' is not, and the host reads this file on your behalf. Write the generated rows under the workspace and pass that path.`;
1819
+ }
1820
+ function symlinkRefusal(shown) {
1821
+ return `manageCollection: \`itemsFile\` '${shown}' is a symbolic link. Pass the real path of a regular file inside the workspace.`;
1822
+ }
1823
+ function openItemsFileRefusal(err, shown) {
1824
+ if (require_dist.isErrorWithCode(err) && (err.code === "ELOOP" || err.code === "EMLINK")) return symlinkRefusal(shown);
1825
+ return `manageCollection: could not read \`itemsFile\` '${shown}' — ${require_promptSafety.defangForPrompt(require_dist.errorMessage(err))}. It must exist inside the workspace and be readable by the host.`;
1826
+ }
1827
+ /** Everything decided about the file, decided about the OPEN DESCRIPTOR rather
1828
+ * than about the path a second time.
1829
+ *
1830
+ * Re-`stat`ing and re-`readFile`ing the pathname would leave a TOCTOU window
1831
+ * the containment check cannot close: the caller is a sandboxed agent with
1832
+ * write access to the workspace, so it can point `rows.json` at an in-workspace
1833
+ * file, call the tool, and swap the symlink to a host file outside the mount
1834
+ * while the first `await` is pending — restoring exactly the read primitive
1835
+ * containment exists to deny. Bound to one descriptor, a swap after the open
1836
+ * changes nothing about the bytes this call goes on to read.
1837
+ *
1838
+ * The `dev`/`ino` comparison is what ties the two together: it proves the
1839
+ * descriptor's inode is the one reachable at a contained path. A hardlink
1840
+ * would satisfy it, but the agent cannot create one across the mount boundary
1841
+ * — only the workspace is mounted, and a hardlink cannot cross filesystems. */
1842
+ async function verifyOpenedItemsFile(handle, hostPath, root, shown) {
1843
+ const opened = await handle.stat();
1844
+ if (!opened.isFile()) return `manageCollection: \`itemsFile\` '${shown}' is not a regular file. It must be a JSON file holding an array of record objects.`;
1845
+ if (opened.size > 8388608) return `manageCollection: \`itemsFile\` '${shown}' is ${opened.size} bytes, over the limit of ${MAX_ITEMS_FILE_BYTES}. Nothing was read; split the rows across several files and call once per file.`;
1846
+ let real;
1847
+ let atPath;
1848
+ let link;
1849
+ try {
1850
+ link = await (0, node_fs_promises.lstat)(hostPath);
1851
+ real = await (0, node_fs_promises.realpath)(hostPath);
1852
+ atPath = await (0, node_fs_promises.stat)(real);
1853
+ } catch (err) {
1854
+ return openItemsFileRefusal(err, shown);
1855
+ }
1856
+ if (link.isSymbolicLink()) return symlinkRefusal(shown);
1857
+ if (!require_discovery.isContainedInRoot(real, root)) return outsideWorkspaceRefusal(shown);
1858
+ if (atPath.ino !== opened.ino || atPath.dev !== opened.dev) return `manageCollection: \`itemsFile\` '${shown}' changed while it was being opened. Nothing was read; write the file, then call putItems.`;
1859
+ return { size: opened.size };
1860
+ }
1861
+ /** Open the file ONCE, then prove that descriptor is the contained file.
1862
+ * `O_NOFOLLOW` refuses a symlink outright rather than resolving it, and
1863
+ * `O_NONBLOCK` keeps a fifo from parking this call on `open` itself — the
1864
+ * descriptor is what `verifyOpenedItemsFile` then judges. */
1865
+ async function openContainedItemsFile(hostPath, root, shown) {
1866
+ let handle;
1867
+ try {
1868
+ handle = await (0, node_fs_promises.open)(hostPath, OPEN_ITEMS_FILE_FLAGS);
1869
+ } catch (err) {
1870
+ return openItemsFileRefusal(err, shown);
1871
+ }
1872
+ const verified = await verifyOpenedItemsFile(handle, hostPath, root, shown);
1873
+ if (typeof verified !== "string") return {
1874
+ handle,
1875
+ size: verified.size
1876
+ };
1877
+ await handle.close();
1878
+ return verified;
1879
+ }
1880
+ /** Read the descriptor into a buffer bounded by the size that was CHECKED,
1881
+ * rather than to EOF.
1882
+ *
1883
+ * `FileHandle.readFile()` reads until end-of-file, which the size check cannot
1884
+ * bound: the agent can hold the same file open and append to it after the
1885
+ * `stat` and before the read, and because appending does not change the inode,
1886
+ * the identity check cannot see it either. A 2-byte file that passed the gate
1887
+ * can hand back gigabytes. Allocating `size + 1` makes the cap hold on the
1888
+ * bytes actually taken, whatever the file does meanwhile — and that one extra
1889
+ * byte is what detects the growth, so a file being written under us is refused
1890
+ * rather than parsed as the truncated half it would otherwise look like. */
1891
+ async function readItemsBytes(handle, size, shown) {
1892
+ const buffer = Buffer.allocUnsafe(size + 1);
1893
+ const { bytesRead } = await handle.read(buffer, 0, size + 1, 0);
1894
+ if (bytesRead > size) return `manageCollection: \`itemsFile\` '${shown}' grew while it was being read. Nothing was written; finish writing the file, then call putItems.`;
1895
+ return { raw: buffer.subarray(0, bytesRead).toString("utf-8") };
1896
+ }
1897
+ function parseItemsJson(raw, shown) {
1898
+ let parsed;
1899
+ try {
1900
+ parsed = JSON.parse(raw);
1901
+ } catch (err) {
1902
+ return `manageCollection: \`itemsFile\` '${shown}' could not be read as JSON — ${require_promptSafety.defangForPrompt(require_dist.errorMessage(err))}. It must hold a JSON array of record objects.`;
1903
+ }
1904
+ if (!isRecordArray(parsed) || parsed.length === 0) return `manageCollection: \`itemsFile\` '${shown}' must hold a non-empty JSON array of record objects.`;
1905
+ return parsed;
1906
+ }
1907
+ /** Read the rows an `itemsFile` holds. Every failure comes back as tool text,
1908
+ * never a throw: a bad path or a malformed file is something the agent can fix
1909
+ * and retry. The path it passed is what the messages name, even when the bytes
1910
+ * were read from the translated host path — it is the one the agent recognises. */
1911
+ async function readItemsFile(itemsFile, deps) {
1912
+ const shown = require_promptSafety.defangForPrompt(itemsFile);
1913
+ const resolved = resolveItemsFilePath(itemsFile, deps);
1914
+ if (typeof resolved === "string") return resolved;
1915
+ const opened = await openContainedItemsFile(resolved.hostPath, resolveBase(deps), shown);
1916
+ if (typeof opened === "string") return opened;
1917
+ let read;
1918
+ try {
1919
+ read = await readItemsBytes(opened.handle, opened.size, shown);
1920
+ } catch (err) {
1921
+ return openItemsFileRefusal(err, shown);
1922
+ } finally {
1923
+ await opened.handle.close();
1924
+ }
1925
+ return typeof read === "string" ? read : parseItemsJson(read.raw, shown);
1926
+ }
1927
+ /** The rows this call will write, from whichever source it named. The cap is
1928
+ * checked here — on the resolved rows, so it holds for `items` and `itemsFile`
1929
+ * alike — and BEFORE the first write, so an over-cap call leaves the
1930
+ * collection exactly as it found it instead of half-filled. */
1931
+ async function resolvePutRows(args, deps) {
1932
+ const rows = args.itemsFile === void 0 ? args.items : await readItemsFile(args.itemsFile, deps);
1933
+ if (typeof rows === "string") return rows;
1934
+ if (rows.length > 1e3) return `manageCollection: refused — ${rows.length} rows is over the putItems limit of ${MAX_PUT_ITEMS}. Nothing was written; split them across several calls.`;
1935
+ return rows;
1936
+ }
1761
1937
  async function handlePutItems(collection, args, deps) {
1762
1938
  const store = require_discovery.storeFor(collection, { workspaceRoot: deps.workspaceRoot });
1763
1939
  const { write } = store;
1764
1940
  if (!write) return `manageCollection: ${require_discovery.readOnlyRefusal(collection.slug)} (its records are the rows of '${collection.schema.dataSource?.path}'; edit that file to change the data).`;
1941
+ const rows = await resolvePutRows(args, deps);
1942
+ if (typeof rows === "string") return rows;
1765
1943
  const written = [];
1766
1944
  const rejected = [];
1767
- for (const record of args.items) {
1945
+ for (const record of rows) {
1768
1946
  const outcome = await putOneItem(collection, store, write, record, args.mode, deps);
1769
1947
  if (outcome.written) written.push(outcome.written);
1770
1948
  if (outcome.rejected) rejected.push(outcome.rejected);
@@ -1827,14 +2005,36 @@ function parsePutMode(mode) {
1827
2005
  function isRecordArray(value) {
1828
2006
  return require_dist.isUnknownArray(value) && value.every(require_dist.isRecord);
1829
2007
  }
2008
+ /** `items` and `itemsFile` are ALTERNATIVES, never a pair: two row sets in one
2009
+ * call has no correct reading — honouring one silently discards the other, and
2010
+ * concatenating them writes rows the caller never asked to write together. So
2011
+ * both present is refused, rather than resolved by precedence.
2012
+ *
2013
+ * A relative `itemsFile` is refused too, for a reason the agent cannot see from
2014
+ * where it stands: this tool runs inside the HOST'S SERVER PROCESS, whose
2015
+ * working directory is not the agent's. A relative path would not reliably
2016
+ * fail — it would resolve against an unrelated directory and either miss or,
2017
+ * worse, read a different file that happens to share the name. */
2018
+ function parseItemsSource(items, itemsFile) {
2019
+ if (items !== void 0 && itemsFile !== void 0) return "manageCollection: pass either `items` or `itemsFile` for putItems, not both — two row sets in one call is ambiguous.";
2020
+ if (itemsFile !== void 0) return parseItemsFile(itemsFile);
2021
+ if (!isRecordArray(items) || items.length === 0) return "manageCollection: putItems needs `items` (a non-empty array of record objects) or `itemsFile` (an absolute path to a JSON file of them — use it for a set a script generated, so the rows never pass through your context).";
2022
+ return { items };
2023
+ }
2024
+ function parseItemsFile(itemsFile) {
2025
+ const file = typeof itemsFile === "string" ? itemsFile.trim() : "";
2026
+ if (!file) return "manageCollection: `itemsFile` must be a non-empty absolute path to a JSON file of record objects.";
2027
+ if (!node_path.default.isAbsolute(file)) return `manageCollection: \`itemsFile\` must be an ABSOLUTE path — '${require_promptSafety.defangForPrompt(file)}' is relative, and this tool runs in the host's server process, whose working directory is not yours. Pass the full path.`;
2028
+ return { itemsFile: file };
2029
+ }
1830
2030
  function parsePutItems(args, slug) {
1831
- const { items, mode } = args;
1832
- if (!isRecordArray(items) || items.length === 0) return "manageCollection: `items` is required for putItems — a non-empty array of record objects.";
1833
- const putMode = parsePutMode(mode);
2031
+ const source = parseItemsSource(args.items, args.itemsFile);
2032
+ if (typeof source === "string") return source;
2033
+ const putMode = parsePutMode(args.mode);
1834
2034
  if (putMode === null) return "manageCollection: `mode` must be \"upsert\" (default), \"create\", or \"merge\".";
1835
2035
  return {
2036
+ ...source,
1836
2037
  slug,
1837
- items,
1838
2038
  mode: putMode
1839
2039
  };
1840
2040
  }
@@ -1960,7 +2160,7 @@ async function handlePutSchema(slug, schemaArg, deps) {
1960
2160
  written: true
1961
2161
  });
1962
2162
  }
1963
- var MANAGE_COLLECTION_PROMPT = "Use `manageCollection` instead of raw Read/Write/Edit when working with a collection's records OR its schema (raw file I/O stays available as the escape hatch). Before authoring or changing a collection's `schema.json`, call `schemaDocs` to load the field/DSL reference — the default reply is the core authoring guide plus a table of contents; fetch advanced sections (actions, bells, calendar/kanban views, dataSource, storage) by passing their heading as `topic` rather than dumping `topic: \"all\"`. Then read with `getSchema` and write with `putSchema` — `putSchema` validates the whole schema before writing and returns actionable errors instead of silently failing discovery's validation. `getItems` is the only way to see computed values — `derived` fields (e.g. a portfolio's value), `toggle` projections, and `embed` records are host-computed and never present in the stored JSON files. On large collections pass `ids` and/or `fields` to keep the result small. For a question that spans collections (\"which clients have unpaid invoices?\"), start with `getOntology`: it lists every collection with its primaryKey, record count, and outbound `ref`/`embed` relations, so you know which collections to join before reading any records. `putItems` validates every row against the schema before writing (required fields, enum values, primaryKey = record id) and returns `{ written, rejected }`; fix each rejected row using its `problem` text and retry just those rows. Never include computed fields in a row you write. To update a few fields of an existing record, use `mode: \"merge\"` with a partial row ({ id, <changed fields> }) — the default upsert replaces the WHOLE record, so a partial upsert would silently erase every optional field it omits. `deleteItems` removes records by id and returns `{ deleted, rejected }`; an id that doesn't exist comes back rejected rather than counted as deleted, so check `rejected` before reporting a deletion as done. Answer aggregation questions (counts, sums, averages, group-bys) with `queryItems` on ANY collection — on a dataSource (CSV) collection it scans the whole file (getItems is row-capped, so aggregates computed from its output can be silently wrong on large files); on a file-backed collection it aggregates the enriched records, so computed fields (derived/rollup/toggle) are queryable columns.";
2163
+ var MANAGE_COLLECTION_PROMPT = "Use `manageCollection` instead of raw Read/Write/Edit when working with a collection's records OR its schema (raw file I/O stays available as the escape hatch). Before authoring or changing a collection's `schema.json`, call `schemaDocs` to load the field/DSL reference — the default reply is the core authoring guide plus a table of contents; fetch advanced sections (actions, bells, calendar/kanban views, dataSource, storage) by passing their heading as `topic` rather than dumping `topic: \"all\"`. Then read with `getSchema` and write with `putSchema` — `putSchema` validates the whole schema before writing and returns actionable errors instead of silently failing discovery's validation. `getItems` is the only way to see computed values — `derived` fields (e.g. a portfolio's value), `toggle` projections, and `embed` records are host-computed and never present in the stored JSON files. On large collections pass `ids` and/or `fields` to keep the result small. For a question that spans collections (\"which clients have unpaid invoices?\"), start with `getOntology`: it lists every collection with its primaryKey, record count, and outbound `ref`/`embed` relations, so you know which collections to join before reading any records. `putItems` validates every row against the schema before writing (required fields, enum values, primaryKey = record id) and returns `{ written, rejected }`; fix each rejected row using its `problem` text and retry just those rows. Never include computed fields in a row you write. When the rows come from a script rather than from you (a generated schedule, an imported set, anything past a few dozen records), write them to a JSON file UNDER THE WORKSPACE and pass its absolute path as `itemsFile` instead of `items` — the host reads the file, so the rows never pass through your context. Do NOT hand-transcribe a generated file into `items`, and never drive the collection by spawning the MCP bridge yourself. To update a few fields of an existing record, use `mode: \"merge\"` with a partial row ({ id, <changed fields> }) — the default upsert replaces the WHOLE record, so a partial upsert would silently erase every optional field it omits. `deleteItems` removes records by id and returns `{ deleted, rejected }`; an id that doesn't exist comes back rejected rather than counted as deleted, so check `rejected` before reporting a deletion as done. Answer aggregation questions (counts, sums, averages, group-bys) with `queryItems` on ANY collection — on a dataSource (CSV) collection it scans the whole file (getItems is row-capped, so aggregates computed from its output can be silently wrong on large files); on a file-backed collection it aggregates the enriched records, so computed fields (derived/rollup/toggle) are queryable columns.";
1964
2164
  /** Validate getItems' optional `ids`/`fields` args, then delegate. */
1965
2165
  async function dispatchGetItems(collection, args, deps) {
1966
2166
  const ids = optionalStringArray(args.ids, "ids");
@@ -2051,7 +2251,11 @@ var MANAGE_COLLECTION_DEFINITION = {
2051
2251
  items: {
2052
2252
  type: "array",
2053
2253
  items: { type: "object" },
2054
- description: "putItems: the record objects to store. Each must carry the schema's primaryKey value (it doubles as the filename)."
2254
+ description: "putItems: the record objects to store, inline. Each must carry the schema's primaryKey value (it doubles as the filename). For rows a script generated, pass `itemsFile` instead — never both."
2255
+ },
2256
+ itemsFile: {
2257
+ type: "string",
2258
+ description: "putItems: an ABSOLUTE path to a JSON file holding the array of record objects, read by the host — the alternative to `items` for rows a script produced. Use it whenever the data already exists as a file: passing a generated set of several hundred records through `items` means writing every byte of it yourself. The path must be absolute (this tool runs in the host's server process, whose working directory is not yours) and must be INSIDE the workspace — write the generated file under the workspace, not to a system temp dir. The file must hold a non-empty JSON array, and `items` and `itemsFile` are mutually exclusive."
2055
2259
  },
2056
2260
  mode: {
2057
2261
  type: "string",
@@ -2087,6 +2291,18 @@ function makeManageCollectionTool(deps = {}) {
2087
2291
  };
2088
2292
  }
2089
2293
  //#endregion
2294
+ Object.defineProperty(exports, "MAX_ITEMS_FILE_BYTES", {
2295
+ enumerable: true,
2296
+ get: function() {
2297
+ return MAX_ITEMS_FILE_BYTES;
2298
+ }
2299
+ });
2300
+ Object.defineProperty(exports, "MAX_PUT_ITEMS", {
2301
+ enumerable: true,
2302
+ get: function() {
2303
+ return MAX_PUT_ITEMS;
2304
+ }
2305
+ });
2090
2306
  Object.defineProperty(exports, "MAX_RECORD_ISSUES", {
2091
2307
  enumerable: true,
2092
2308
  get: function() {
@@ -2304,4 +2520,4 @@ Object.defineProperty(exports, "validateRecordObject", {
2304
2520
  }
2305
2521
  });
2306
2522
 
2307
- //# sourceMappingURL=server-DSrRdPvf.cjs.map
2523
+ //# sourceMappingURL=server-DZkN0GGh.cjs.map