@appsoftwareltd/etherpk-mcp 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -820,7 +820,7 @@ function looksLikeAgentSetupCode(value) {
820
820
  }
821
821
  var package_default = {
822
822
  name: "@appsoftwareltd/etherpk-mcp",
823
- version: "0.33.0",
823
+ version: "0.35.0",
824
824
  license: "Elastic-2.0",
825
825
  description: "EtherPK Headless Client: an MCP server over a synced knowledge graph, run beside the agent on the user's own machine.",
826
826
  type: "module",
@@ -4047,6 +4047,19 @@ function indentChars(line) {
4047
4047
  return leading(line).length;
4048
4048
  }
4049
4049
  /**
4050
+ * How far a whitespace-only line at `indent` moves. One that closed a branch lands past the node
4051
+ * still open (`open`) and no deeper than where the closed branch now starts, so it closes the same
4052
+ * branches once they have moved; else, and when no column lies between the two (only off the
4053
+ * two-space grid, where a bullet can move right), it moves with the bullet that owns it.
4054
+ */
4055
+ function blankDelta(indent, closed, open, owner) {
4056
+ const byOwner = owner ? owner.written - owner.raw : 0;
4057
+ if (!closed) return byOwner;
4058
+ const floor = open ? open.written + 1 : 0;
4059
+ if (floor > closed.written) return byOwner;
4060
+ return Math.min(Math.max(indent, floor), closed.written) - indent;
4061
+ }
4062
+ /**
4050
4063
  * The structural walk under both {@link outlineLines} and {@link normaliseIndentUnit}: visits each
4051
4064
  * line in order with the node stack resolved, reporting the line's owner (the nearest open bullet
4052
4065
  * whose block the line is inside) and the delta that would put it on the grid.
@@ -4066,8 +4079,11 @@ function walk(lines, blocks, measure, visit) {
4066
4079
  for (const b of blocks) starts.set(b.start, b);
4067
4080
  const stack = [];
4068
4081
  const top = () => stack.length ? stack[stack.length - 1] : null;
4082
+ /** Close the nodes at or past `indent`, and return the shallowest of them, if any. */
4069
4083
  const popTo = (indent) => {
4070
- while (stack.length && stack[stack.length - 1].raw >= indent) stack.pop();
4084
+ let closed = null;
4085
+ while (stack.length && stack[stack.length - 1].raw >= indent) closed = stack.pop();
4086
+ return closed;
4071
4087
  };
4072
4088
  /** The nearest open bullet on the stack, or null when only prose nodes (or nothing) remain. */
4073
4089
  const owningBullet = () => {
@@ -4086,13 +4102,13 @@ function walk(lines, blocks, measure, visit) {
4086
4102
  const block = starts.get(i);
4087
4103
  const span = block ? block.end - i + 1 : 1;
4088
4104
  const indent = measure(line);
4089
- popTo(indent);
4105
+ const closed = popTo(indent);
4090
4106
  if (isBlank(line) && !block) {
4091
4107
  const owner = owningBullet();
4092
4108
  visit(i, {
4093
4109
  depth: top()?.depth ?? 0,
4094
4110
  owner: owner ? owner.bullet : -1,
4095
- delta: owner ? owner.written - owner.raw : 0,
4111
+ delta: blankDelta(indent, closed, top(), owner),
4096
4112
  span
4097
4113
  });
4098
4114
  continue;
@@ -4185,8 +4201,86 @@ function relead(line, within, delta) {
4185
4201
  return " ".repeat(Math.max(0, col + delta)) + line.slice(chars);
4186
4202
  }
4187
4203
  /**
4204
+ * A section shifted left as a whole when it starts with a bullet indented with no bullet above it:
4205
+ * `## H` then ` - a` then ` - b` becomes `## H`, `- a`, ` - b`. A heading nests what follows
4206
+ * by its `#` level, not by indentation, and the editor writes the bullets under a heading at
4207
+ * column 0; to the outline walk an indented bullet would be the heading's child instead, and stay
4208
+ * indented with no parent.
4209
+ *
4210
+ * A section starts after a heading at column 0 with a bullet and runs to the next non-blank line at
4211
+ * column 0. It moves only when no line in it is shallower than that first bullet, and then every
4212
+ * line moves left by the bullet's indent (a fenced block only up to its fence column, so code keeps
4213
+ * its own indentation). That keeps every line where it was relative to every other, as the outline
4214
+ * reads them: a sub-heading or a paragraph beside the bullets stays beside them, never inside a
4215
+ * bullet's block. A section with a shallower line, one that a fenced block crosses, or one that
4216
+ * holds a fence line the editor pairs with nothing is left to the walk, as before: CommonMark may
4217
+ * read such a fence line as a fence the shift would open or close differently. Returns `lines`
4218
+ * itself when nothing moves.
4219
+ */
4220
+ function dedentHeadingSections(lines, blocks = fencedBlocks(lines)) {
4221
+ const first = frontmatterLines(lines);
4222
+ let out = null;
4223
+ const at = (i) => (out ?? lines)[i];
4224
+ for (let h = first; h < lines.length; h++) {
4225
+ if (!isHeading(at(h)) || indentColumns(at(h)) > 0 || insideBlock(blocks, h)) continue;
4226
+ const section = sectionUnder(at, lines.length, h);
4227
+ if (!section || !movable(at, lines, blocks, section)) continue;
4228
+ out ??= lines.slice();
4229
+ shiftSection(out, blocks, section);
4230
+ }
4231
+ return out ?? lines;
4232
+ }
4233
+ /**
4234
+ * The section after the heading on line `h`: from its first non-blank line, which must be a bullet
4235
+ * indented past column 0, to the next non-blank line at column 0. Null when there is none to move.
4236
+ */
4237
+ function sectionUnder(at, length, h) {
4238
+ let start = h + 1;
4239
+ while (start < length && isBlank(at(start))) start++;
4240
+ if (start >= length || !isBullet$1(at(start))) return null;
4241
+ let end = start;
4242
+ while (end < length && (isBlank(at(end)) || indentColumns(at(end)) > 0)) end++;
4243
+ return end === start ? null : {
4244
+ start,
4245
+ end,
4246
+ shift: indentColumns(at(start))
4247
+ };
4248
+ }
4249
+ /** Whether a section moves: nothing in it shallower than its first bullet, no fenced block across its edges, no loose fence line. */
4250
+ function movable(at, lines, blocks, { start, end, shift }) {
4251
+ for (let k = start; k < end; k++) if (!isBlank(at(k)) && indentColumns(at(k)) < shift) return false;
4252
+ if (blocks.some((b) => b.start < start && b.end >= start || b.start < end && b.end >= end)) return false;
4253
+ return !holdsLooseFence(lines, blocks, start, end);
4254
+ }
4255
+ /** Move every line of the section left by its shift, in place: a fenced block only up to its fence column. */
4256
+ function shiftSection(out, blocks, { start, end, shift }) {
4257
+ for (let k = start; k < end; k++) {
4258
+ const block = blocks.find((b) => b.start === k);
4259
+ if (block) {
4260
+ const within = indentColumns(out[k]);
4261
+ for (let j = k; j <= block.end; j++) out[j] = relead(out[j], within, -shift);
4262
+ k = block.end;
4263
+ continue;
4264
+ }
4265
+ out[k] = relead(out[k], Infinity, -shift);
4266
+ }
4267
+ }
4268
+ /** A tilde fence line: text to the editor, which pairs backtick fences only, but a fence to CommonMark. */
4269
+ var TILDE_FENCE = /^\s*(?:-\s)?~{3,}/;
4270
+ /** Whether a line from `start` to `end` (exclusive) is a fence line no fenced block pairs. */
4271
+ function holdsLooseFence(lines, blocks, start, end) {
4272
+ for (let k = start; k < end; k++) if ((fenceLineInfo(lines[k]) !== null || TILDE_FENCE.test(lines[k])) && !insideBlock(blocks, k)) return true;
4273
+ return false;
4274
+ }
4275
+ /** Whether line `i` is inside a fenced block, its fences included. */
4276
+ function insideBlock(blocks, i) {
4277
+ return blocks.some((b) => i >= b.start && i <= b.end);
4278
+ }
4279
+ /**
4188
4280
  * The document with every bullet on the Indent Unit grid: each bullet one unit under its parent
4189
- * (a top-level bullet at column 0, over-nesting collapsed), its continuation lines, soft lines and
4281
+ * (a top-level bullet at column 0, over-nesting collapsed, and the section under a top-level
4282
+ * heading shifted to column 0 when it starts indented: {@link dedentHeadingSections}), its
4283
+ * continuation lines, soft lines and
4190
4284
  * fenced block moved by the same amount so their indentation beyond the content column is kept
4191
4285
  * (an indented code block inside a bullet stays code). Tabs in leading whitespace become columns
4192
4286
  * (inside a fenced block only up to the fence column: a tab in the code is code); a line owned
@@ -4194,7 +4288,14 @@ function relead(line, within, delta) {
4194
4288
  * the grid comes back byte-identical, so callers may compare by reference.
4195
4289
  */
4196
4290
  function normaliseIndentUnit(text) {
4197
- const lines = text.split("\n");
4291
+ const split = text.split("\n");
4292
+ const once = regrid(dedentHeadingSections(split));
4293
+ const sections = dedentHeadingSections(once);
4294
+ const lines = sections === once ? once : regrid(sections);
4295
+ return lines === split ? text : lines.join("\n");
4296
+ }
4297
+ /** The walk's half of {@link normaliseIndentUnit}: `lines` with every bullet on the grid, or `lines` itself when none moves. */
4298
+ function regrid(lines) {
4198
4299
  const out = lines.slice();
4199
4300
  const frontmatter = frontmatterLines(lines);
4200
4301
  let changed = false;
@@ -4209,7 +4310,7 @@ function normaliseIndentUnit(text) {
4209
4310
  }
4210
4311
  }
4211
4312
  });
4212
- return changed ? out.join("\n") : text;
4313
+ return changed ? out : lines;
4213
4314
  }
4214
4315
  // ../client/src/lib/document/block-model.ts
4215
4316
  /**
@@ -14806,118 +14907,520 @@ function parseImageDisplaySizeHint(alt) {
14806
14907
  }
14807
14908
  return parsed;
14808
14909
  }
14809
- // ../client/src/lib/document/outliner.ts
14810
- function lineIndent(line) {
14811
- return line.length - line.trimStart().length;
14812
- }
14813
- function isBulletLine(line) {
14814
- return /^-\s/.test(line.trimStart());
14815
- }
14816
- /** A bullet whose content is `[ ]` / `[x]`; undefined if not a task. */
14817
- function taskDone(line) {
14818
- const m = /^-\s+\[([ xX])\]/.exec(line.trimStart());
14819
- return m ? m[1].toLowerCase() === "x" : void 0;
14910
+ // ../client/src/lib/storage/fs/asset-store.ts
14911
+ /**
14912
+ * The **Asset store** over a {@link DirectoryAdapter}: uploads land as binary files
14913
+ * under `assets/`, named `kebab-stem.<contenthash>.ext` (DESIGN.md → On-disk layout).
14914
+ * Identical bytes de-duplicate to one file **by content and extension alone** - the stem is
14915
+ * display, not identity - so the same file added again under a different name references the
14916
+ * one already stored rather than writing a second copy. Built on the same File-System seam as
14917
+ * {@link createFilesystemDocumentStore}, so the pure naming/dedup logic is Node-testable
14918
+ * over the in-memory adapter before any browser code runs.
14919
+ *
14920
+ * Assets are referenced from documents by a relative path — `../assets/<name>` — which
14921
+ * resolves from any journal entry or page (both sit one level under the graph root,
14922
+ * the Logseq convention). `resolve` reads those bytes back and hands out an object URL plus
14923
+ * the name and MIME type a download or a viewer needs; the URLs are cached per asset and
14924
+ * revoked on {@link AssetStore.dispose}.
14925
+ *
14926
+ * Remote (S3) upload and per-graph access control are deferred (DESIGN.md → Server
14927
+ * Backend); this is the Filesystem Backend path only.
14928
+ */
14929
+ /** Extensions rendered inline as images (everything else renders as a download link). */
14930
+ var IMAGE_EXTS = /* @__PURE__ */ new Set([
14931
+ "png",
14932
+ "jpg",
14933
+ "jpeg",
14934
+ "gif",
14935
+ "webp",
14936
+ "svg",
14937
+ "avif",
14938
+ "bmp"
14939
+ ]);
14940
+ /** A doc-relative asset reference: optional `../` hops, then `assets/<name>`. */
14941
+ var ASSET_REF$1 = /^(?:\.\.\/)*assets\/(.+)$/;
14942
+ /**
14943
+ * An asset could not be fetched just now: the connection failed, or the server answered with a
14944
+ * status that means "try again". It says nothing about whether the file exists, so something
14945
+ * showing the file asks again rather than calling it missing. `status` is the server's answer,
14946
+ * absent when the connection failed before there was one.
14947
+ */
14948
+ var AssetUnavailableError = class extends Error {
14949
+ name = "AssetUnavailableError";
14950
+ status;
14951
+ constructor(message, options = {}) {
14952
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
14953
+ this.status = options.status;
14954
+ }
14955
+ };
14956
+ /**
14957
+ * An asset arrived, but not as it was stored: the server offered a different number of chunks than
14958
+ * its encrypted metadata records, or the joined bytes do not match the size or hash recorded there.
14959
+ * Each chunk is authenticated on its own, so this is what catches a file cut short, or a reuse
14960
+ * answer that points at a different file (ADR 0027, amended 2026-10-05). The bytes are never
14961
+ * handed over. Distinct from a missing file (`null`), which is gone, and from an unavailable one,
14962
+ * which may come good by itself.
14963
+ */
14964
+ var AssetIntegrityError = class extends Error {
14965
+ name = "AssetIntegrityError";
14966
+ constructor(message = "This file did not arrive complete, so it was not opened. Try again in a moment.") {
14967
+ super(message);
14968
+ }
14969
+ };
14970
+ /** Split a file name into its stem and lower-cased extension (`''` ext when there is none). */
14971
+ function splitNameExt(fileName) {
14972
+ const dot = fileName.lastIndexOf(".");
14973
+ if (dot <= 0) return {
14974
+ stem: fileName,
14975
+ ext: ""
14976
+ };
14977
+ return {
14978
+ stem: fileName.slice(0, dot),
14979
+ ext: fileName.slice(dot + 1).toLowerCase()
14980
+ };
14820
14981
  }
14821
- /** Length of the bullet marker incl. its trailing space: `- ` (2) or `- [ ] ` (6). */
14822
- function markerLength(line) {
14823
- const indent = lineIndent(line);
14824
- const rest = line.slice(indent);
14825
- const task = /^-\s+\[[ xX]\]\s?/.exec(rest);
14826
- if (task) return task[0].length;
14827
- const bullet = /^-\s/.exec(rest);
14828
- return bullet ? bullet[0].length : 0;
14982
+ /** True when `ext` (with or without a leading dot) names an inline-rendered image format. */
14983
+ function isImageExt(ext) {
14984
+ return IMAGE_EXTS.has(ext.replace(/^\./, "").toLowerCase());
14829
14985
  }
14830
- /** Offset of a line's content: past its indent and, on a bullet, past the `- ` / `- [ ] ` marker. */
14831
- function contentStart(line) {
14832
- return lineIndent(line) + markerLength(line);
14986
+ /** The video formats the app plays, by extension ([[2026-11-18 Audio And Video Players]]). */
14987
+ var VIDEO_EXTS = ["webm", "mp4"];
14988
+ /** The audio formats the app plays, by extension. */
14989
+ var AUDIO_EXTS = [
14990
+ "mp3",
14991
+ "m4a",
14992
+ "wav",
14993
+ "ogg",
14994
+ "opus",
14995
+ "flac"
14996
+ ];
14997
+ /** Whether a file with this extension (with or without a leading dot) is played, and as what. */
14998
+ function mediaKindOfExt(ext) {
14999
+ const bare = ext.replace(/^\./, "").toLowerCase();
15000
+ if (VIDEO_EXTS.includes(bare)) return "video";
15001
+ if (AUDIO_EXTS.includes(bare)) return "audio";
15002
+ return null;
14833
15003
  }
14834
- /** The bullet's content (everything after the marker). `""` for an empty bullet. */
14835
- function bulletContent(line) {
14836
- return line.slice(contentStart(line));
15004
+ /** The on-disk asset name: `kebab-stem.<hash>.ext` (stem falls back to `asset` when slugging empties it). */
15005
+ function assetFileName(originalName, hash) {
15006
+ const { stem, ext } = splitNameExt(originalName);
15007
+ const slug = publishSlug(stem) || "asset";
15008
+ return ext ? `${slug}.${hash}.${ext}` : `${slug}.${hash}`;
14837
15009
  }
14838
- /** A heading line (`#`…`######` + space), tolerant of leading indent — matches the block model. */
14839
- function isHeadingLine(line) {
14840
- return /^#{1,6}\s/.test(line.trimStart());
15010
+ /** The de-duplication key: content plus extension. The stem is display, not identity. */
15011
+ function contentKey(hash, ext) {
15012
+ return `${hash}.${ext}`;
14841
15013
  }
14842
- /** Map from a fenced block's opener line index to the block, for O(1) "does a fence start here?". */
14843
- function fenceStartMap(blocks) {
14844
- const m = /* @__PURE__ */ new Map();
14845
- for (const b of blocks) m.set(b.start, b);
14846
- return m;
15014
+ /**
15015
+ * An on-disk asset name with its content hash taken back out — `q3-report.a1b2c3d4.pdf` reads as
15016
+ * `q3-report.pdf`. What a download is called and what titles an asset tab, so neither shows a
15017
+ * user a hash they never typed. A name this store did not write is returned unchanged.
15018
+ */
15019
+ function displayAssetName(fileName) {
15020
+ const parsed = assetHashFromName(fileName);
15021
+ if (!parsed) return fileName;
15022
+ const stem = fileName.slice(0, fileName.length - `.${parsed.hash}`.length - (parsed.ext ? parsed.ext.length + 1 : 0));
15023
+ return parsed.ext ? `${stem}.${parsed.ext}` : stem;
14847
15024
  }
14848
15025
  /**
14849
- * The branch rooted at line `i`: `i` plus all following lines more indented than it — its
14850
- * descendants and continuation lines. **Fence-opaque** (ADR 0021): a fenced block deeper than the
14851
- * root is swallowed whole, so its internal blank lines don't truncate the branch. **Indent decides
14852
- * blankness** (ADR 0021): a whitespace-only line is judged by its indentation like any other line —
14853
- * an indented soft line stays in the branch; a flush-left empty line (or one at/left of the root)
14854
- * ends it, as do a heading and any same-or-shallower content line.
15026
+ * MIME types for the formats the app itself renders, plus the handful a browser needs told about
15027
+ * to do anything sensible with a download. Deliberately small and deliberately **empty for
15028
+ * anything else**: a wrong type is worse than none, because a wrong one is acted on. The
15029
+ * Filesystem Backend has nowhere else to learn a type from — unlike the Server Backend, which
15030
+ * carries the uploader's own MIME type inside the encrypted asset metadata.
14855
15031
  */
14856
- function branchRange(lines, i, blocks = fencedBlocks(lines)) {
14857
- return {
14858
- start: i,
14859
- end: branchEnd$1(lines, i, fenceStartMap(blocks))
14860
- };
15032
+ var MIME_TYPES = {
15033
+ png: "image/png",
15034
+ jpg: "image/jpeg",
15035
+ jpeg: "image/jpeg",
15036
+ gif: "image/gif",
15037
+ webp: "image/webp",
15038
+ svg: "image/svg+xml",
15039
+ avif: "image/avif",
15040
+ bmp: "image/bmp",
15041
+ pdf: "application/pdf",
15042
+ epub: "application/epub+zip",
15043
+ txt: "text/plain",
15044
+ csv: "text/csv",
15045
+ json: "application/json",
15046
+ md: "text/markdown",
15047
+ mp3: "audio/mpeg",
15048
+ m4a: "audio/mp4",
15049
+ wav: "audio/wav",
15050
+ ogg: "audio/ogg",
15051
+ opus: "audio/ogg",
15052
+ flac: "audio/flac",
15053
+ mp4: "video/mp4",
15054
+ webm: "video/webm",
15055
+ zip: "application/zip"
15056
+ };
15057
+ /** The MIME type for a file extension (with or without a leading dot), or `''` when unknown. */
15058
+ function mimeTypeForExt(ext) {
15059
+ return MIME_TYPES[ext.replace(/^\./, "").toLowerCase()] ?? "";
14861
15060
  }
14862
- /** The last line of the branch rooted at line `i` ({@link branchRange}), given the fence openers. */
14863
- function branchEnd$1(lines, i, starts) {
14864
- const root = lineIndent(lines[i]);
14865
- const own = starts.get(i);
14866
- let end = own ? own.end : i;
14867
- let j = end + 1;
14868
- while (j < lines.length) {
14869
- const b = starts.get(j);
14870
- if (b) {
14871
- if (lineIndent(lines[b.start]) > root) {
14872
- end = b.end;
14873
- j = b.end + 1;
14874
- continue;
14875
- }
14876
- break;
14877
- }
14878
- const line = lines[j];
14879
- if (isHeadingLine(line)) break;
14880
- if (lineIndent(line) <= root) break;
14881
- end = j;
14882
- j++;
15061
+ /**
15062
+ * The on-disk name referenced by a doc-relative asset ref, or `null` if `ref` is not an asset
15063
+ * reference. A reference whose name decodes to anything but one file inside `assets/`, or does not
15064
+ * decode at all, is not one: it can never name a file on disk (see `isSafeAssetName`).
15065
+ */
15066
+ function assetNameFromRef(ref) {
15067
+ const clean = ref.split(/[?#]/)[0];
15068
+ const match = ASSET_REF$1.exec(clean);
15069
+ if (!match) return null;
15070
+ let name;
15071
+ try {
15072
+ name = decodeURIComponent(match[1]);
15073
+ } catch {
15074
+ return null;
14883
15075
  }
14884
- return end;
14885
- }
14886
- // ../client/src/lib/document/publish/markdown/list-item-end-rule.ts
14887
- /** The lines this parse ended a list item at. */
14888
- function endedAt(state) {
14889
- const env = state.env;
14890
- env.etherpkListItemEnds ??= /* @__PURE__ */ new Set();
14891
- return env.etherpkListItemEnds;
14892
- }
14893
- /** A line whose indentation, if any, is spaces only. */
14894
- var SPACE_INDENTED = /^ *\S/;
14895
- /** An empty bullet as the editor reads one: a dash and whitespace, indented with spaces. */
14896
- var EMPTY_BULLET = /^ *-[ \t]+$/;
14897
- /** The block rules whose reading of a line this rule ended an item at is never the editor's. */
14898
- var READ_AS_A_PARAGRAPH = [
14899
- "lheading",
14900
- "reference",
14901
- "html_block",
14902
- "code"
14903
- ];
14904
- /** Line `line` as typed, from its true start: inside a quote `bMarks` starts after the `>`. */
14905
- function rawLine(state, line) {
14906
- const end = state.eMarks[line];
14907
- return state.src.slice(state.src.lastIndexOf("\n", end - 1) + 1, end);
15076
+ return isSafeAssetName(name) ? name : null;
14908
15077
  }
14909
15078
  /**
14910
- * The first line of the innermost list item the parse is inside, or null when it is in no item or
14911
- * inside a quote. Walking back over the tokens pushed so far, the openers not yet closed are the
14912
- * containers the parse is inside, innermost first. A block being read has not pushed its own tokens.
15079
+ * The markdown to embed a saved asset: an inline image, a recording in the same image form (the
15080
+ * editor draws a player under it, `media-line.ts`), or a plain link that downloads on click.
15081
+ * For an image, an optional `displaySize` (e.g. `300` or `300x200`) is added as a `|` display-size
15082
+ * hint; the caller is responsible for passing a valid spec (see `normalizeDisplaySize`).
14913
15083
  */
14914
- function openItemLine(state) {
14915
- let closed = 0;
14916
- let item = null;
14917
- for (let i = state.tokens.length - 1; i >= 0; i--) {
14918
- const token = state.tokens[i];
14919
- if (token.nesting === -1) closed++;
14920
- else if (token.nesting === 1) {
15084
+ function buildAssetMarkdown(asset, displaySize) {
15085
+ if (!asset.isImage) return `${mediaKindOfExt(splitNameExt(asset.ref.split(/[?#]/)[0]).ext) !== null ? "!" : ""}[${asset.stem}](${asset.ref})`;
15086
+ return `![${displaySize ? `${asset.stem}|${displaySize}` : asset.stem}](${asset.ref})`;
15087
+ }
15088
+ /** First 8 hex chars of the SHA-256 of the bytes — the content hash in the asset name. */
15089
+ async function contentHash(bytes) {
15090
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
15091
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 8);
15092
+ }
15093
+ function createAssetStore(adapter) {
15094
+ const urlCache = /* @__PURE__ */ new Map();
15095
+ /**
15096
+ * Content key → the on-disk name already holding those bytes. Built from `assets/` on the
15097
+ * first save (so a store that only ever resolves never pays for the listing) and maintained
15098
+ * on every write after that.
15099
+ *
15100
+ * This is what keeps the [[Asset]] guarantee honest on this backend: identity is content,
15101
+ * not the name it was added under. Keying the write on the whole file name instead — which
15102
+ * is what this did before — stored the same bytes twice whenever the stem differed.
15103
+ */
15104
+ let contentIndex;
15105
+ /**
15106
+ * The index, listed once. The promise is what is kept, not the map: saves run several at once
15107
+ * (an upload's pool), and each one that found no map yet used to list the folder into a map of
15108
+ * its own. The last listing to finish replaced the rest, and every write recorded in the others
15109
+ * was forgotten, so adding the same files again stored and reported most of them as new.
15110
+ */
15111
+ function assetsByContent() {
15112
+ contentIndex ??= listByContent().catch((err) => {
15113
+ contentIndex = void 0;
15114
+ throw err;
15115
+ });
15116
+ return contentIndex;
15117
+ }
15118
+ async function listByContent() {
15119
+ const index = /* @__PURE__ */ new Map();
15120
+ for (const { name } of await adapter.list("assets")) {
15121
+ const parsed = assetHashFromName(name);
15122
+ if (parsed && !index.has(contentKey(parsed.hash, parsed.ext))) index.set(contentKey(parsed.hash, parsed.ext), name);
15123
+ }
15124
+ return index;
15125
+ }
15126
+ /**
15127
+ * Content key → the save storing those bytes right now. Two saves of the same bytes at once (a
15128
+ * file dropped twice in one batch) both missed the index and wrote the file twice, under each
15129
+ * name. The second waits for the first and references its file instead.
15130
+ */
15131
+ const storing = /* @__PURE__ */ new Map();
15132
+ /** The file holding `bytes` under `key`: one the folder already has, or one written now. */
15133
+ async function store(key, name, hash, bytes) {
15134
+ const index = await assetsByContent();
15135
+ const held = index.get(key);
15136
+ if (held !== void 0 && await adapter.exists("assets", held)) return {
15137
+ fileName: held,
15138
+ reused: true
15139
+ };
15140
+ const fileName = assetFileName(name, hash);
15141
+ await adapter.writeBinary("assets", fileName, bytes);
15142
+ index.set(key, fileName);
15143
+ return {
15144
+ fileName,
15145
+ reused: false
15146
+ };
15147
+ }
15148
+ return {
15149
+ async save({ name, bytes }, onBytes) {
15150
+ const hash = await contentHash(bytes);
15151
+ const { stem, ext } = splitNameExt(name);
15152
+ const key = contentKey(hash, ext);
15153
+ let stored;
15154
+ const pending = storing.get(key);
15155
+ if (pending) stored = await pending.then((fileName) => ({
15156
+ fileName,
15157
+ reused: true
15158
+ }), () => store(key, name, hash, bytes));
15159
+ else {
15160
+ const work = store(key, name, hash, bytes);
15161
+ storing.set(key, work.then((done) => done.fileName));
15162
+ try {
15163
+ stored = await work;
15164
+ } finally {
15165
+ storing.delete(key);
15166
+ }
15167
+ }
15168
+ onBytes?.(bytes.length);
15169
+ return {
15170
+ ref: `../assets/${stored.fileName}`,
15171
+ name: stored.fileName,
15172
+ stem: publishSlug(stem) || "asset",
15173
+ isImage: isImageExt(ext),
15174
+ ...stored.reused ? { reused: true } : {}
15175
+ };
15176
+ },
15177
+ async readBytes(ref) {
15178
+ const assetName = assetNameFromRef(ref);
15179
+ if (!assetName) return null;
15180
+ const { ext } = splitNameExt(assetName);
15181
+ try {
15182
+ const { bytes } = await adapter.readBinary("assets", assetName);
15183
+ return {
15184
+ bytes,
15185
+ name: displayAssetName(assetName),
15186
+ type: mimeTypeForExt(ext)
15187
+ };
15188
+ } catch {
15189
+ return null;
15190
+ }
15191
+ },
15192
+ async resolve(ref) {
15193
+ const assetName = assetNameFromRef(ref);
15194
+ if (!assetName) return null;
15195
+ const { ext } = splitNameExt(assetName);
15196
+ const meta = {
15197
+ name: displayAssetName(assetName),
15198
+ type: mimeTypeForExt(ext)
15199
+ };
15200
+ const cached = urlCache.get(assetName);
15201
+ if (cached) return {
15202
+ url: cached,
15203
+ ...meta
15204
+ };
15205
+ let content;
15206
+ try {
15207
+ content = await adapter.readBinary("assets", assetName);
15208
+ } catch {
15209
+ return null;
15210
+ }
15211
+ const url = URL.createObjectURL(new Blob([content.bytes], meta.type ? { type: meta.type } : {}));
15212
+ urlCache.set(assetName, url);
15213
+ return {
15214
+ url,
15215
+ ...meta
15216
+ };
15217
+ },
15218
+ dispose() {
15219
+ for (const url of urlCache.values()) URL.revokeObjectURL(url);
15220
+ urlCache.clear();
15221
+ },
15222
+ renamed(from, to) {
15223
+ const url = urlCache.get(from);
15224
+ if (url) URL.revokeObjectURL(url);
15225
+ urlCache.delete(from);
15226
+ const parsed = assetHashFromName(to);
15227
+ if (parsed) contentIndex?.then((index) => index.set(contentKey(parsed.hash, parsed.ext), to)).catch(() => {});
15228
+ }
15229
+ };
15230
+ }
15231
+ // ../client/src/lib/document/markdown-link-target.ts
15232
+ /**
15233
+ * The one definition of markdown link syntax, shared by every reader of one.
15234
+ *
15235
+ * Ten places used to spell this out, and each spelled the destination `[^)\s]+`, which stops at
15236
+ * the FIRST closing parenthesis. That is wrong the moment a file name contains one, and imported
15237
+ * attachments contain them all the time - `Quote_320_from_Garden_Fencing_ltd_(1)_1700000000000_0.pdf`
15238
+ * has the shape they take. Every reader then saw the same truncated target, so the link styling and the
15239
+ * download and delete controls landed in the middle of the text, and the [[Local Mirror]] reported
15240
+ * the stub as a document link to an attachment the graph plainly had (2026-09-10).
15241
+ *
15242
+ * Sharing only the destination would have left the same duplication one layer down: nine call
15243
+ * sites each re-spelling `\[([^\]]*)\]\(` around it. So the whole link is defined here, once, as
15244
+ * regex source with **named groups** - which is also what lets a caller read `groups.target`
15245
+ * without counting brackets, and what stops the next change to the grammar from silently missing
15246
+ * a site.
15247
+ *
15248
+ * Source rather than a compiled RegExp, because what varies between callers is not the link: it is
15249
+ * the anchoring and what surrounds it. One wants a whole line to be nothing but an image, one
15250
+ * wants a Logseq `{:height 100}` suffix after it, one scans prose. Each composes what it needs.
15251
+ *
15252
+ * CommonMark's rule for the unbracketed destination form: no whitespace, and parentheses only in
15253
+ * balanced pairs. Nesting is bounded here at two levels, one more than any real file name uses,
15254
+ * because an unbounded version needs a recursive parser and would buy nothing.
15255
+ *
15256
+ * Pure: strings of regex source, no DOM, no CodeMirror.
15257
+ */
15258
+ /**
15259
+ * The destination grammar. `excluded` adds characters the caller's context forbids on top of
15260
+ * whitespace and parentheses - an HTML attribute cannot hold its own quote, and a target inside
15261
+ * markdown brackets cannot hold `]`.
15262
+ */
15263
+ function linkTargetPattern(excluded = "") {
15264
+ const plain = `[^\\s()${excluded}]`;
15265
+ return `(?:${plain}|\\((?:${plain}|\\(${plain}*\\))*\\))+`;
15266
+ }
15267
+ /**
15268
+ * A whole markdown link or image, as regex source with named groups.
15269
+ *
15270
+ * - `bang` - `!` for an image, empty for a link.
15271
+ * - `label` - the alt text or link text, size hint and all.
15272
+ * - `target` - the destination.
15273
+ *
15274
+ * A regex may not repeat a group name, so compose this **once** per pattern. Wrap it in a group of
15275
+ * your own where you need the whole link as one capture.
15276
+ */
15277
+ var MARKDOWN_LINK = `(?<bang>!?)\\[(?<label>(?:[^\\[\\]]|\\[[^\\[\\]]*\\])*)\\]\\((?<target>${linkTargetPattern()})\\)`;
15278
+ /** A match's groups, typed. Every {@link MARKDOWN_LINK} match has all three. */
15279
+ function linkGroups(match) {
15280
+ return match.groups;
15281
+ }
15282
+ new RegExp(`^\\s*${MARKDOWN_LINK}\\s*$`);
15283
+ new RegExp(`^(\\s*-\\s(?:\\[[ xX]\\]\\s)?)${MARKDOWN_LINK}\\s*$`);
15284
+ // ../client/src/lib/document/media-line.ts
15285
+ /**
15286
+ * What a **media line** is: a line whose only content is `![alt](target)` over an audio or video
15287
+ * [[Asset]], which the editor draws a player under ([[2026-11-18 Audio And Video Players]]).
15288
+ *
15289
+ * The syntax is the image form of an [[Asset Reference]], and the file's type decides what is
15290
+ * drawn: a picture for an image (`image-line.ts`), a player for a recording. Both read the line
15291
+ * through `embed-line.ts`.
15292
+ *
15293
+ * Only an Asset Reference (`../assets/clip.webm`) is a media line. A recording on another site
15294
+ * (`![clip](https://example.com/clip.mp4)`) is not played: the Client's Content Security Policy
15295
+ * lets media come from the graph's own files only, so it stays the link it is.
15296
+ *
15297
+ * Pure over the line text, no DOM, no CodeMirror.
15298
+ */
15299
+ /** Whether a file with this extension is played, and as what: the Asset Store's list, as `isImageExt` is. */
15300
+ var mediaKindOfExtension = mediaKindOfExt;
15301
+ /**
15302
+ * Whether `![…](target)` names a recording in the graph's own files, and of which kind. Only an
15303
+ * [[Asset Reference]] can: the same question the asset link asks (`assetNameFromRef`), so a media
15304
+ * line always has its link above the player and its file where the Asset Store looks.
15305
+ */
15306
+ function mediaKindOfTarget(target) {
15307
+ const name = assetNameFromRef(target.trim());
15308
+ if (name === null) return null;
15309
+ const dot = name.lastIndexOf(".");
15310
+ return dot <= 0 ? null : mediaKindOfExtension(name.slice(dot + 1));
15311
+ }
15312
+ // ../client/src/lib/document/outliner.ts
15313
+ function lineIndent(line) {
15314
+ return line.length - line.trimStart().length;
15315
+ }
15316
+ function isBulletLine(line) {
15317
+ return /^-\s/.test(line.trimStart());
15318
+ }
15319
+ /** A bullet whose content is `[ ]` / `[x]`; undefined if not a task. */
15320
+ function taskDone(line) {
15321
+ const m = /^-\s+\[([ xX])\]/.exec(line.trimStart());
15322
+ return m ? m[1].toLowerCase() === "x" : void 0;
15323
+ }
15324
+ /** Length of the bullet marker incl. its trailing space: `- ` (2) or `- [ ] ` (6). */
15325
+ function markerLength(line) {
15326
+ const indent = lineIndent(line);
15327
+ const rest = line.slice(indent);
15328
+ const task = /^-\s+\[[ xX]\]\s?/.exec(rest);
15329
+ if (task) return task[0].length;
15330
+ const bullet = /^-\s/.exec(rest);
15331
+ return bullet ? bullet[0].length : 0;
15332
+ }
15333
+ /** Offset of a line's content: past its indent and, on a bullet, past the `- ` / `- [ ] ` marker. */
15334
+ function contentStart(line) {
15335
+ return lineIndent(line) + markerLength(line);
15336
+ }
15337
+ /** The bullet's content (everything after the marker). `""` for an empty bullet. */
15338
+ function bulletContent(line) {
15339
+ return line.slice(contentStart(line));
15340
+ }
15341
+ /** A heading line (`#`…`######` + space), tolerant of leading indent — matches the block model. */
15342
+ function isHeadingLine(line) {
15343
+ return /^#{1,6}\s/.test(line.trimStart());
15344
+ }
15345
+ /** Map from a fenced block's opener line index to the block, for O(1) "does a fence start here?". */
15346
+ function fenceStartMap(blocks) {
15347
+ const m = /* @__PURE__ */ new Map();
15348
+ for (const b of blocks) m.set(b.start, b);
15349
+ return m;
15350
+ }
15351
+ /**
15352
+ * The branch rooted at line `i`: `i` plus all following lines more indented than it — its
15353
+ * descendants and continuation lines. **Fence-opaque** (ADR 0021): a fenced block deeper than the
15354
+ * root is swallowed whole, so its internal blank lines don't truncate the branch. **Indent decides
15355
+ * blankness** (ADR 0021): a whitespace-only line is judged by its indentation like any other line —
15356
+ * an indented soft line stays in the branch; a flush-left empty line (or one at/left of the root)
15357
+ * ends it, as do a heading and any same-or-shallower content line.
15358
+ */
15359
+ function branchRange(lines, i, blocks = fencedBlocks(lines)) {
15360
+ return {
15361
+ start: i,
15362
+ end: branchEnd$1(lines, i, fenceStartMap(blocks))
15363
+ };
15364
+ }
15365
+ /** The last line of the branch rooted at line `i` ({@link branchRange}), given the fence openers. */
15366
+ function branchEnd$1(lines, i, starts) {
15367
+ const root = lineIndent(lines[i]);
15368
+ const own = starts.get(i);
15369
+ let end = own ? own.end : i;
15370
+ let j = end + 1;
15371
+ while (j < lines.length) {
15372
+ const b = starts.get(j);
15373
+ if (b) {
15374
+ if (lineIndent(lines[b.start]) > root) {
15375
+ end = b.end;
15376
+ j = b.end + 1;
15377
+ continue;
15378
+ }
15379
+ break;
15380
+ }
15381
+ const line = lines[j];
15382
+ if (isHeadingLine(line)) break;
15383
+ if (lineIndent(line) <= root) break;
15384
+ end = j;
15385
+ j++;
15386
+ }
15387
+ return end;
15388
+ }
15389
+ // ../client/src/lib/document/publish/markdown/list-item-end-rule.ts
15390
+ /** The lines this parse ended a list item at. */
15391
+ function endedAt(state) {
15392
+ const env = state.env;
15393
+ env.etherpkListItemEnds ??= /* @__PURE__ */ new Set();
15394
+ return env.etherpkListItemEnds;
15395
+ }
15396
+ /** A line whose indentation, if any, is spaces only. */
15397
+ var SPACE_INDENTED = /^ *\S/;
15398
+ /** An empty bullet as the editor reads one: a dash and whitespace, indented with spaces. */
15399
+ var EMPTY_BULLET = /^ *-[ \t]+$/;
15400
+ /** The block rules whose reading of a line this rule ended an item at is never the editor's. */
15401
+ var READ_AS_A_PARAGRAPH = [
15402
+ "lheading",
15403
+ "reference",
15404
+ "html_block",
15405
+ "code"
15406
+ ];
15407
+ /** Line `line` as typed, from its true start: inside a quote `bMarks` starts after the `>`. */
15408
+ function rawLine(state, line) {
15409
+ const end = state.eMarks[line];
15410
+ return state.src.slice(state.src.lastIndexOf("\n", end - 1) + 1, end);
15411
+ }
15412
+ /**
15413
+ * The first line of the innermost list item the parse is inside, or null when it is in no item or
15414
+ * inside a quote. Walking back over the tokens pushed so far, the openers not yet closed are the
15415
+ * containers the parse is inside, innermost first. A block being read has not pushed its own tokens.
15416
+ */
15417
+ function openItemLine(state) {
15418
+ let closed = 0;
15419
+ let item = null;
15420
+ for (let i = state.tokens.length - 1; i >= 0; i--) {
15421
+ const token = state.tokens[i];
15422
+ if (token.nesting === -1) closed++;
15423
+ else if (token.nesting === 1) {
14921
15424
  if (closed > 0) closed--;
14922
15425
  else if (token.type === "blockquote_open") return null;
14923
15426
  else if (token.type === "list_item_open" && item === null) item = token.map?.[0] ?? null;
@@ -15179,14 +15682,14 @@ function mapNames(source) {
15179
15682
  return readMapBody(source.split("\n")).items.map((item) => item.name).filter((name) => name !== "").join(", ");
15180
15683
  }
15181
15684
  /** A document-relative asset reference: any number of `../`, `assets/`, the name. */
15182
- var ASSET_REF$1 = /^(?:\.\.\/)*assets\/(.+)$/;
15685
+ var ASSET_REF = /^(?:\.\.\/)*assets\/(.+)$/;
15183
15686
  /**
15184
15687
  * The asset a reference names, decoded, or null when it names none. A name that decodes to
15185
15688
  * anything but one file inside `assets/` is not an asset: it would become a bundle path, and a site
15186
15689
  * folder, outside `assets/` (see `isSafeAssetName`). The link is then left as the author wrote it.
15187
15690
  */
15188
15691
  function assetNameOf(ref) {
15189
- const match = ASSET_REF$1.exec(ref);
15692
+ const match = ASSET_REF.exec(ref);
15190
15693
  if (!match) return null;
15191
15694
  const raw = match[1].split(/[?#]/)[0];
15192
15695
  let name;
@@ -15225,6 +15728,12 @@ function plainText(tokens) {
15225
15728
  }
15226
15729
  return lines.join("\n");
15227
15730
  }
15731
+ /** The browser's own player for a recording in the graph's files written as `target`, or null when it is none. */
15732
+ function mediaElement(asset, target, src, label) {
15733
+ const media = asset === null ? null : mediaKindOfTarget(target);
15734
+ if (media === null) return null;
15735
+ return `<${media} controls preload="metadata" src="${escapeHtml$3(src)}" aria-label="${escapeHtml$3(label)}"></${media}>`;
15736
+ }
15228
15737
  function createDocumentRenderer(options) {
15229
15738
  const md = new MarkdownIt({
15230
15739
  html: true,
@@ -15246,18 +15755,23 @@ function createDocumentRenderer(options) {
15246
15755
  mermaidFallback: false,
15247
15756
  assets: []
15248
15757
  };
15758
+ /** Where the site serves the asset `name`, noted as one the page uses; null when it is none or is not published. */
15759
+ function publishedAsset(name) {
15760
+ const href = name === null ? null : options.assetHref(name);
15761
+ if (name === null || href === null) return null;
15762
+ if (!state.assets.includes(name)) state.assets.push(name);
15763
+ return href;
15764
+ }
15249
15765
  md.renderer.rules.image;
15250
15766
  md.renderer.rules.image = (tokens, idx, opts, env, self) => {
15251
15767
  const token = tokens[idx];
15252
- const name = assetNameOf(String(token.attrGet("src") ?? ""));
15253
- if (name !== null) {
15254
- const href = options.assetHref(name);
15255
- if (href !== null) {
15256
- token.attrSet("src", href);
15257
- if (!state.assets.includes(name)) state.assets.push(name);
15258
- }
15259
- }
15768
+ const src = String(token.attrGet("src") ?? "");
15769
+ const name = assetNameOf(src);
15770
+ const href = publishedAsset(name);
15771
+ if (href !== null) token.attrSet("src", href);
15260
15772
  const parsed = parseImageDisplaySizeHint(self.renderInlineAsText(token.children ?? [], opts, env));
15773
+ const player = mediaElement(name, src, href ?? src, parsed.cleanAlt);
15774
+ if (player !== null) return player;
15261
15775
  token.attrSet("alt", parsed.cleanAlt);
15262
15776
  if (parsed.maxWidth !== void 0) {
15263
15777
  const style = [`max-width:${displayMaxWidth(parsed.maxWidth)}`];
@@ -15366,61 +15880,10 @@ function createDocumentRenderer(options) {
15366
15880
  return out;
15367
15881
  }
15368
15882
  return {
15369
- render,
15370
- renderInline,
15371
- fences
15372
- };
15373
- }
15374
- // ../client/src/lib/document/markdown-link-target.ts
15375
- /**
15376
- * The one definition of markdown link syntax, shared by every reader of one.
15377
- *
15378
- * Ten places used to spell this out, and each spelled the destination `[^)\s]+`, which stops at
15379
- * the FIRST closing parenthesis. That is wrong the moment a file name contains one, and imported
15380
- * attachments contain them all the time - `Quote_320_from_Garden_Fencing_ltd_(1)_1700000000000_0.pdf`
15381
- * has the shape they take. Every reader then saw the same truncated target, so the link styling and the
15382
- * download and delete controls landed in the middle of the text, and the [[Local Mirror]] reported
15383
- * the stub as a document link to an attachment the graph plainly had (2026-09-10).
15384
- *
15385
- * Sharing only the destination would have left the same duplication one layer down: nine call
15386
- * sites each re-spelling `\[([^\]]*)\]\(` around it. So the whole link is defined here, once, as
15387
- * regex source with **named groups** - which is also what lets a caller read `groups.target`
15388
- * without counting brackets, and what stops the next change to the grammar from silently missing
15389
- * a site.
15390
- *
15391
- * Source rather than a compiled RegExp, because what varies between callers is not the link: it is
15392
- * the anchoring and what surrounds it. One wants a whole line to be nothing but an image, one
15393
- * wants a Logseq `{:height 100}` suffix after it, one scans prose. Each composes what it needs.
15394
- *
15395
- * CommonMark's rule for the unbracketed destination form: no whitespace, and parentheses only in
15396
- * balanced pairs. Nesting is bounded here at two levels, one more than any real file name uses,
15397
- * because an unbounded version needs a recursive parser and would buy nothing.
15398
- *
15399
- * Pure: strings of regex source, no DOM, no CodeMirror.
15400
- */
15401
- /**
15402
- * The destination grammar. `excluded` adds characters the caller's context forbids on top of
15403
- * whitespace and parentheses - an HTML attribute cannot hold its own quote, and a target inside
15404
- * markdown brackets cannot hold `]`.
15405
- */
15406
- function linkTargetPattern(excluded = "") {
15407
- const plain = `[^\\s()${excluded}]`;
15408
- return `(?:${plain}|\\((?:${plain}|\\(${plain}*\\))*\\))+`;
15409
- }
15410
- /**
15411
- * A whole markdown link or image, as regex source with named groups.
15412
- *
15413
- * - `bang` - `!` for an image, empty for a link.
15414
- * - `label` - the alt text or link text, size hint and all.
15415
- * - `target` - the destination.
15416
- *
15417
- * A regex may not repeat a group name, so compose this **once** per pattern. Wrap it in a group of
15418
- * your own where you need the whole link as one capture.
15419
- */
15420
- var MARKDOWN_LINK = `(?<bang>!?)\\[(?<label>(?:[^\\[\\]]|\\[[^\\[\\]]*\\])*)\\]\\((?<target>${linkTargetPattern()})\\)`;
15421
- /** A match's groups, typed. Every {@link MARKDOWN_LINK} match has all three. */
15422
- function linkGroups(match) {
15423
- return match.groups;
15883
+ render,
15884
+ renderInline,
15885
+ fences
15886
+ };
15424
15887
  }
15425
15888
  // ../client/src/lib/document/line-endings.ts
15426
15889
  /** `text` with every `\r\n` and every lone `\r` written as `\n`; `text` itself when it holds no `\r`. */
@@ -17041,263 +17504,6 @@ async function openDiagramRenderer(env) {
17041
17504
  }
17042
17505
  };
17043
17506
  }
17044
- // ../client/src/lib/storage/fs/asset-store.ts
17045
- /**
17046
- * The **Asset store** over a {@link DirectoryAdapter}: uploads land as binary files
17047
- * under `assets/`, named `kebab-stem.<contenthash>.ext` (DESIGN.md → On-disk layout).
17048
- * Identical bytes de-duplicate to one file **by content and extension alone** - the stem is
17049
- * display, not identity - so the same file added again under a different name references the
17050
- * one already stored rather than writing a second copy. Built on the same File-System seam as
17051
- * {@link createFilesystemDocumentStore}, so the pure naming/dedup logic is Node-testable
17052
- * over the in-memory adapter before any browser code runs.
17053
- *
17054
- * Assets are referenced from documents by a relative path — `../assets/<name>` — which
17055
- * resolves from any journal entry or page (both sit one level under the graph root,
17056
- * the Logseq convention). `resolve` reads those bytes back and hands out an object URL plus
17057
- * the name and MIME type a download or a viewer needs; the URLs are cached per asset and
17058
- * revoked on {@link AssetStore.dispose}.
17059
- *
17060
- * Remote (S3) upload and per-graph access control are deferred (DESIGN.md → Server
17061
- * Backend); this is the Filesystem Backend path only.
17062
- */
17063
- /** Extensions rendered inline as images (everything else renders as a download link). */
17064
- var IMAGE_EXTS = /* @__PURE__ */ new Set([
17065
- "png",
17066
- "jpg",
17067
- "jpeg",
17068
- "gif",
17069
- "webp",
17070
- "svg",
17071
- "avif",
17072
- "bmp"
17073
- ]);
17074
- /** A doc-relative asset reference: optional `../` hops, then `assets/<name>`. */
17075
- var ASSET_REF = /^(?:\.\.\/)*assets\/(.+)$/;
17076
- /**
17077
- * An asset could not be fetched just now: the connection failed, or the server answered with a
17078
- * status that means "try again". It says nothing about whether the file exists, so something
17079
- * showing the file asks again rather than calling it missing. `status` is the server's answer,
17080
- * absent when the connection failed before there was one.
17081
- */
17082
- var AssetUnavailableError = class extends Error {
17083
- name = "AssetUnavailableError";
17084
- status;
17085
- constructor(message, options = {}) {
17086
- super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
17087
- this.status = options.status;
17088
- }
17089
- };
17090
- /**
17091
- * An asset arrived, but not as it was stored: the server offered a different number of chunks than
17092
- * its encrypted metadata records, or the joined bytes do not match the size or hash recorded there.
17093
- * Each chunk is authenticated on its own, so this is what catches a file cut short, or a reuse
17094
- * answer that points at a different file (ADR 0027, amended 2026-10-05). The bytes are never
17095
- * handed over. Distinct from a missing file (`null`), which is gone, and from an unavailable one,
17096
- * which may come good by itself.
17097
- */
17098
- var AssetIntegrityError = class extends Error {
17099
- name = "AssetIntegrityError";
17100
- constructor(message = "This file did not arrive complete, so it was not opened. Try again in a moment.") {
17101
- super(message);
17102
- }
17103
- };
17104
- /** Split a file name into its stem and lower-cased extension (`''` ext when there is none). */
17105
- function splitNameExt(fileName) {
17106
- const dot = fileName.lastIndexOf(".");
17107
- if (dot <= 0) return {
17108
- stem: fileName,
17109
- ext: ""
17110
- };
17111
- return {
17112
- stem: fileName.slice(0, dot),
17113
- ext: fileName.slice(dot + 1).toLowerCase()
17114
- };
17115
- }
17116
- /** True when `ext` (with or without a leading dot) names an inline-rendered image format. */
17117
- function isImageExt(ext) {
17118
- return IMAGE_EXTS.has(ext.replace(/^\./, "").toLowerCase());
17119
- }
17120
- /** The on-disk asset name: `kebab-stem.<hash>.ext` (stem falls back to `asset` when slugging empties it). */
17121
- function assetFileName(originalName, hash) {
17122
- const { stem, ext } = splitNameExt(originalName);
17123
- const slug = publishSlug(stem) || "asset";
17124
- return ext ? `${slug}.${hash}.${ext}` : `${slug}.${hash}`;
17125
- }
17126
- /** The de-duplication key: content plus extension. The stem is display, not identity. */
17127
- function contentKey(hash, ext) {
17128
- return `${hash}.${ext}`;
17129
- }
17130
- /**
17131
- * An on-disk asset name with its content hash taken back out — `q3-report.a1b2c3d4.pdf` reads as
17132
- * `q3-report.pdf`. What a download is called and what titles an asset tab, so neither shows a
17133
- * user a hash they never typed. A name this store did not write is returned unchanged.
17134
- */
17135
- function displayAssetName(fileName) {
17136
- const parsed = assetHashFromName(fileName);
17137
- if (!parsed) return fileName;
17138
- const stem = fileName.slice(0, fileName.length - `.${parsed.hash}`.length - (parsed.ext ? parsed.ext.length + 1 : 0));
17139
- return parsed.ext ? `${stem}.${parsed.ext}` : stem;
17140
- }
17141
- /**
17142
- * MIME types for the formats the app itself renders, plus the handful a browser needs told about
17143
- * to do anything sensible with a download. Deliberately small and deliberately **empty for
17144
- * anything else**: a wrong type is worse than none, because a wrong one is acted on. The
17145
- * Filesystem Backend has nowhere else to learn a type from — unlike the Server Backend, which
17146
- * carries the uploader's own MIME type inside the encrypted asset metadata.
17147
- */
17148
- var MIME_TYPES = {
17149
- png: "image/png",
17150
- jpg: "image/jpeg",
17151
- jpeg: "image/jpeg",
17152
- gif: "image/gif",
17153
- webp: "image/webp",
17154
- svg: "image/svg+xml",
17155
- avif: "image/avif",
17156
- bmp: "image/bmp",
17157
- pdf: "application/pdf",
17158
- epub: "application/epub+zip",
17159
- txt: "text/plain",
17160
- csv: "text/csv",
17161
- json: "application/json",
17162
- md: "text/markdown",
17163
- mp3: "audio/mpeg",
17164
- mp4: "video/mp4",
17165
- webm: "video/webm",
17166
- zip: "application/zip"
17167
- };
17168
- /** The MIME type for a file extension (with or without a leading dot), or `''` when unknown. */
17169
- function mimeTypeForExt(ext) {
17170
- return MIME_TYPES[ext.replace(/^\./, "").toLowerCase()] ?? "";
17171
- }
17172
- /**
17173
- * The on-disk name referenced by a doc-relative asset ref, or `null` if `ref` is not an asset
17174
- * reference. A reference whose name decodes to anything but one file inside `assets/`, or does not
17175
- * decode at all, is not one: it can never name a file on disk (see `isSafeAssetName`).
17176
- */
17177
- function assetNameFromRef(ref) {
17178
- const clean = ref.split(/[?#]/)[0];
17179
- const match = ASSET_REF.exec(clean);
17180
- if (!match) return null;
17181
- let name;
17182
- try {
17183
- name = decodeURIComponent(match[1]);
17184
- } catch {
17185
- return null;
17186
- }
17187
- return isSafeAssetName(name) ? name : null;
17188
- }
17189
- /**
17190
- * The markdown to embed a saved asset: an inline image, or a plain link that downloads on click.
17191
- * For an image, an optional `displaySize` (e.g. `300` or `300x200`) is added as a `|` display-size
17192
- * hint; the caller is responsible for passing a valid spec (see `normalizeDisplaySize`).
17193
- */
17194
- function buildAssetMarkdown(asset, displaySize) {
17195
- if (!asset.isImage) return `[${asset.stem}](${asset.ref})`;
17196
- return `![${displaySize ? `${asset.stem}|${displaySize}` : asset.stem}](${asset.ref})`;
17197
- }
17198
- /** First 8 hex chars of the SHA-256 of the bytes — the content hash in the asset name. */
17199
- async function contentHash(bytes) {
17200
- const digest = await crypto.subtle.digest("SHA-256", bytes);
17201
- return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 8);
17202
- }
17203
- function createAssetStore(adapter) {
17204
- const urlCache = /* @__PURE__ */ new Map();
17205
- /**
17206
- * Content key → the on-disk name already holding those bytes. Built from `assets/` on the
17207
- * first save (so a store that only ever resolves never pays for the listing) and maintained
17208
- * on every write after that.
17209
- *
17210
- * This is what keeps the [[Asset]] guarantee honest on this backend: identity is content,
17211
- * not the name it was added under. Keying the write on the whole file name instead — which
17212
- * is what this did before — stored the same bytes twice whenever the stem differed.
17213
- */
17214
- let contentIndex;
17215
- async function assetsByContent() {
17216
- if (contentIndex) return contentIndex;
17217
- const index = /* @__PURE__ */ new Map();
17218
- for (const { name } of await adapter.list("assets")) {
17219
- const parsed = assetHashFromName(name);
17220
- if (parsed && !index.has(contentKey(parsed.hash, parsed.ext))) index.set(contentKey(parsed.hash, parsed.ext), name);
17221
- }
17222
- contentIndex = index;
17223
- return index;
17224
- }
17225
- return {
17226
- async save({ name, bytes }, onBytes) {
17227
- const hash = await contentHash(bytes);
17228
- const { stem, ext } = splitNameExt(name);
17229
- const index = await assetsByContent();
17230
- const key = contentKey(hash, ext);
17231
- const held = index.get(key);
17232
- const existing = held !== void 0 && await adapter.exists("assets", held) ? held : void 0;
17233
- const fileName = existing ?? assetFileName(name, hash);
17234
- if (!existing) {
17235
- await adapter.writeBinary("assets", fileName, bytes);
17236
- index.set(key, fileName);
17237
- }
17238
- onBytes?.(bytes.length);
17239
- return {
17240
- ref: `../assets/${fileName}`,
17241
- name: fileName,
17242
- stem: publishSlug(stem) || "asset",
17243
- isImage: isImageExt(ext),
17244
- ...existing ? { reused: true } : {}
17245
- };
17246
- },
17247
- async readBytes(ref) {
17248
- const assetName = assetNameFromRef(ref);
17249
- if (!assetName) return null;
17250
- const { ext } = splitNameExt(assetName);
17251
- try {
17252
- const { bytes } = await adapter.readBinary("assets", assetName);
17253
- return {
17254
- bytes,
17255
- name: displayAssetName(assetName),
17256
- type: mimeTypeForExt(ext)
17257
- };
17258
- } catch {
17259
- return null;
17260
- }
17261
- },
17262
- async resolve(ref) {
17263
- const assetName = assetNameFromRef(ref);
17264
- if (!assetName) return null;
17265
- const { ext } = splitNameExt(assetName);
17266
- const meta = {
17267
- name: displayAssetName(assetName),
17268
- type: mimeTypeForExt(ext)
17269
- };
17270
- const cached = urlCache.get(assetName);
17271
- if (cached) return {
17272
- url: cached,
17273
- ...meta
17274
- };
17275
- let content;
17276
- try {
17277
- content = await adapter.readBinary("assets", assetName);
17278
- } catch {
17279
- return null;
17280
- }
17281
- const url = URL.createObjectURL(new Blob([content.bytes], meta.type ? { type: meta.type } : {}));
17282
- urlCache.set(assetName, url);
17283
- return {
17284
- url,
17285
- ...meta
17286
- };
17287
- },
17288
- dispose() {
17289
- for (const url of urlCache.values()) URL.revokeObjectURL(url);
17290
- urlCache.clear();
17291
- },
17292
- renamed(from, to) {
17293
- const url = urlCache.get(from);
17294
- if (url) URL.revokeObjectURL(url);
17295
- urlCache.delete(from);
17296
- const parsed = assetHashFromName(to);
17297
- if (parsed) contentIndex?.set(contentKey(parsed.hash, parsed.ext), to);
17298
- }
17299
- };
17300
- }
17301
17507
  // ../../extensions/excalidraw/src/format.ts
17302
17508
  var DRAWING_FENCE = "excalidraw.drawing";
17303
17509
  var HEADER_TYPE = "excalidraw.drawing";
@@ -19396,14 +19602,36 @@ function imagePixelSize(bytes) {
19396
19602
  function encodeConceptPath(concept) {
19397
19603
  return concept.split("/").map(encodeURIComponent).join("/");
19398
19604
  }
19399
- // ../client/src/lib/navigation/document-url.ts
19400
- /** The Document URL for a concept within a graph. */
19401
- function documentUrl(graphId, concept) {
19402
- return `${graphUrl(graphId)}/d/${encodeConceptPath(concept)}`;
19605
+ // ../client/src/lib/navigation/graph-address.ts
19606
+ var ROOT = "/graph";
19607
+ /** The path a reference's graph is written as. A legacy graph is written as it was read. */
19608
+ function referencedGraphPath(graph) {
19609
+ return graph.where === "legacy" ? `/g/${encodeURIComponent(graph.name)}` : graphAddressPath(graph);
19610
+ }
19611
+ /** The pattern of a referenced graph at the start of a path, capturing where (or none) and the name. */
19612
+ var REFERENCED_GRAPH_PATTERN = String.raw`\/(?:graph\/(folder|sync|browser)|g)\/([^/?#\s]+)`;
19613
+ /** The graph the two captures of {@link REFERENCED_GRAPH_PATTERN} name. Throws on a malformed escape. */
19614
+ function referencedGraphFrom(where, name) {
19615
+ return {
19616
+ where: where === void 0 ? "legacy" : where,
19617
+ name: decodeURIComponent(name)
19618
+ };
19619
+ }
19620
+ /**
19621
+ * Whether a reference is for the graph being served. A legacy reference carries an id: a synced
19622
+ * graph's is checked, and a folder graph's is not, since each browser gave the folder an id of its
19623
+ * own. A graph kept in the browser is checked by id, in either shape.
19624
+ */
19625
+ function referencesGraph(reference, served) {
19626
+ if (reference.where === "legacy") return served.where === "folder" || reference.name === served.name;
19627
+ return sameGraphAddress(reference, served);
19403
19628
  }
19404
- /** The bare workspace URL for a graph. */
19405
- function graphUrl(graphId) {
19406
- return `/g/${encodeURIComponent(graphId)}`;
19629
+ /** The path a workspace address begins with: `/graph/folder/reports`. */
19630
+ function graphAddressPath(address) {
19631
+ return `${ROOT}/${address.where}/${encodeURIComponent(address.name)}`;
19632
+ }
19633
+ function sameGraphAddress(left, right) {
19634
+ return left.where === right.where && left.name === right.name;
19407
19635
  }
19408
19636
  /**
19409
19637
  * The words that identify a task while its tags change: the text after the checkbox and the tag
@@ -19421,7 +19649,7 @@ async function taskFingerprint(label) {
19421
19649
  }
19422
19650
  /** The reference's address: the Document URL with the task in its fragment, which a browser never sends. */
19423
19651
  function taskReferenceUrl(reference, origin = "") {
19424
- return `${origin}${documentUrl(reference.graphId, reference.document)}#task=${reference.line}-${reference.fingerprint}`;
19652
+ return `${origin}${referencedGraphPath(reference.graph)}/d/${encodeConceptPath(reference.document)}#task=${reference.line}-${reference.fingerprint}`;
19425
19653
  }
19426
19654
  /** The scheme that marks a Task Reference as EtherPK's own, and not a web address to fetch. */
19427
19655
  var SCHEME = "etherpk:";
@@ -19429,7 +19657,7 @@ var SCHEME = "etherpk:";
19429
19657
  function taskReferenceId(reference) {
19430
19658
  return `${SCHEME}${taskReferenceUrl(reference)}`;
19431
19659
  }
19432
- var PATH = String.raw`\/g\/([^/?#\s]+)\/d\/([^?#\s]+?)(?:\?[^#\s]*)?#task=(\d+)-([0-9a-f]{12})(?![0-9a-f])`;
19660
+ var PATH = `${REFERENCED_GRAPH_PATTERN}${String.raw`\/d\/([^?#\s]+?)(?:\?[^#\s]*)?#task=(\d+)-([0-9a-f]{12})(?![0-9a-f])`}`;
19433
19661
  /** The `etherpk:` form, read first so that nothing shaped like a reference in a task's words wins. */
19434
19662
  var ETHERPK_REFERENCE = new RegExp(`${SCHEME}${PATH}`);
19435
19663
  /** The reference anywhere, with any origin or none: the web address an earlier version copied. */
@@ -19441,10 +19669,10 @@ var ANY_REFERENCE = new RegExp(PATH);
19441
19669
  function parseTaskReference(input) {
19442
19670
  const match = ETHERPK_REFERENCE.exec(input) ?? ANY_REFERENCE.exec(input);
19443
19671
  if (!match) return null;
19444
- const [, graph, path, line, fingerprint] = match;
19672
+ const [, where, graph, path, line, fingerprint] = match;
19445
19673
  try {
19446
19674
  return {
19447
- graphId: decodeURIComponent(graph),
19675
+ graph: referencedGraphFrom(where, graph),
19448
19676
  document: path.split("/").map(decodeURIComponent).join("/"),
19449
19677
  line: Number(line),
19450
19678
  fingerprint
@@ -19460,10 +19688,10 @@ function parseTaskReference(input) {
19460
19688
  * wrong task. A document that no longer answers to its name goes straight to the graph.
19461
19689
  */
19462
19690
  async function resolveTaskReference(reference, sources) {
19463
- if (sources.graphId !== null && sources.graphId !== reference.graphId) return {
19691
+ if (!referencesGraph(reference.graph, sources.graph)) return {
19464
19692
  ok: false,
19465
19693
  code: "other_graph",
19466
- servedGraphId: sources.graphId
19694
+ served: sources.graph
19467
19695
  };
19468
19696
  const named = sources.resolveDocument(reference.document);
19469
19697
  if (named !== null) {
@@ -19538,8 +19766,8 @@ async function taskLinesWith(lines, fingerprint) {
19538
19766
  return out;
19539
19767
  }
19540
19768
  // ../client/src/lib/document/lane-reference.ts
19541
- /** `/g/<graph>/k/<concept>#lane=<status>` or `/g/<graph>/kanban#lane=<status>`, the scheme before it optional. */
19542
- var LANE_REFERENCE = /(?:etherpk:)?\/g\/([^/?#\s]+)\/(?:k\/([^?#\s]+?)|kanban)#lane=([a-z]+)(?![a-z])/;
19769
+ /** `<graph address>/k/<concept>#lane=<status>` or `<graph address>/kanban#lane=<status>`, the scheme before it optional. */
19770
+ var LANE_REFERENCE = new RegExp(`(?:etherpk:)?${REFERENCED_GRAPH_PATTERN}${String.raw`\/(?:k\/([^?#\s]+?)|kanban)#lane=([a-z]+)(?![a-z])`}`);
19543
19771
  /**
19544
19772
  * The lane reference in `input`: the text as copied, or the `etherpk:` reference alone; null when
19545
19773
  * `input` holds none, or names a lane that is no task status.
@@ -19547,11 +19775,11 @@ var LANE_REFERENCE = /(?:etherpk:)?\/g\/([^/?#\s]+)\/(?:k\/([^?#\s]+?)|kanban)#l
19547
19775
  function parseLaneReference(input) {
19548
19776
  const match = LANE_REFERENCE.exec(input);
19549
19777
  if (!match) return null;
19550
- const [, graph, path, status] = match;
19778
+ const [, where, graph, path, status] = match;
19551
19779
  if (!TASK_STATUSES.includes(status)) return null;
19552
19780
  try {
19553
19781
  return {
19554
- graphId: decodeURIComponent(graph),
19782
+ graph: referencedGraphFrom(where, graph),
19555
19783
  concept: path === void 0 ? null : path.split("/").map(decodeURIComponent).join("/"),
19556
19784
  status
19557
19785
  };
@@ -20703,9 +20931,9 @@ async function graphPath(graph, args) {
20703
20931
  function taskSelection(graph, args) {
20704
20932
  if (args.reference !== void 0) {
20705
20933
  const lane = parseLaneReference(args.reference);
20706
- if (!lane) throw new ToolError("invalid_argument", "reference is not a lane reference. Pass the text Copy agent instruction wrote, or its etherpk:/g/…#lane= address; for one task, use read_task.");
20934
+ if (!lane) throw new ToolError("invalid_argument", "reference is not a lane reference. Pass the text Copy agent instruction wrote, or its etherpk:/graph/…#lane= address; for one task, use read_task.");
20707
20935
  if (args.concept !== void 0 || args.statuses !== void 0) throw new ToolError("invalid_argument", "A lane reference names the concept and status itself: pass reference without concept or statuses.");
20708
- if (graph.backend.kind === "synced" && lane.graphId !== graph.graphId) throw new ToolError("other_graph", `That lane reference is for another graph. This server serves "${graph.name}" (${graph.graphId}); ask the user to connect the graph the reference is from.`);
20936
+ if (!referencesGraph(lane.graph, servedAddress(graph))) throw new ToolError("other_graph", `That lane reference is for another graph. This server serves "${graph.name}" (${graphAddressPath(servedAddress(graph))}); ask the user to connect the graph the reference is from.`);
20709
20937
  return {
20710
20938
  concept: lane.concept,
20711
20939
  statuses: [lane.status],
@@ -21376,11 +21604,25 @@ async function setTask(graph, args) {
21376
21604
  reference: await referenceFor(graph, identity.concept, line, bulletLabel(next))
21377
21605
  };
21378
21606
  }
21607
+ /**
21608
+ * The [[Graph Address]] of the graph served (ADR 0192), which a reference is checked against and
21609
+ * written with: a synced graph by its id, a folder by its own name, as a browser that opened the
21610
+ * folder names it. The folder's id here is a key for this computer's caches and is in no address.
21611
+ */
21612
+ function servedAddress(graph) {
21613
+ return graph.backend.kind === "synced" ? {
21614
+ where: "sync",
21615
+ name: graph.graphId
21616
+ } : {
21617
+ where: "folder",
21618
+ name: basename(resolve(graph.backend.path))
21619
+ };
21620
+ }
21379
21621
  /** Where a Task Reference is resolved in this graph: its documents, read live, and its index. */
21380
21622
  function referenceSources(graph) {
21381
21623
  const hidden = hiddenKeys(graph);
21382
21624
  return {
21383
- graphId: graph.backend.kind === "synced" ? graph.graphId : null,
21625
+ graph: servedAddress(graph),
21384
21626
  resolveDocument: (name) => {
21385
21627
  const identity = resolveIdentity(graph, name);
21386
21628
  return identity && !isHidden(hidden, identity) ? identity.concept : null;
@@ -21396,7 +21638,7 @@ function referenceSources(graph) {
21396
21638
  async function referenceFor(graph, concept, line, label) {
21397
21639
  const fingerprint = await taskFingerprint(label);
21398
21640
  return taskReferenceId({
21399
- graphId: graph.graphId,
21641
+ graph: servedAddress(graph),
21400
21642
  document: concept,
21401
21643
  line,
21402
21644
  fingerprint
@@ -21409,11 +21651,11 @@ async function referenceFor(graph, concept, line, label) {
21409
21651
  */
21410
21652
  async function requireReferencedTask(graph, reference, purpose = "read") {
21411
21653
  const parsed = parseTaskReference(reference);
21412
- if (!parsed) throw new ToolError("invalid_argument", "That is not a task reference: one is etherpk:/g/<graph>/d/<document>#task=<line>-<fingerprint>, as Copy agent instruction in EtherPK writes it.");
21654
+ if (!parsed) throw new ToolError("invalid_argument", "That is not a task reference: one is etherpk:/graph/sync/<graph id>/d/<document>#task=<line>-<fingerprint>, or etherpk:/graph/folder/<folder name>/d/… for a graph folder, as Copy agent instruction in EtherPK writes it.");
21413
21655
  await graph.store.refresh();
21414
21656
  const found = await resolveTaskReference(parsed, referenceSources(graph));
21415
21657
  if (found.ok) return found;
21416
- if (found.code === "other_graph") throw new ToolError("other_graph", `That task reference is for another graph. This server serves "${graph.name}" (${found.servedGraphId}); ask the user to connect the graph the reference is from.`);
21658
+ if (found.code === "other_graph") throw new ToolError("other_graph", `That task reference is for another graph. This server serves "${graph.name}" (${graphAddressPath(found.served)}); ask the user to connect the graph the reference is from.`);
21417
21659
  if (found.code === "task_ambiguous") throw new ToolError("task_ambiguous", `More than one task has those words (${found.candidates.map((candidate) => `"${candidate.document}" line ${candidate.line}`).join(", ")}), so none was chosen. Ask the user which one, or name it by concept and line.`);
21418
21660
  const named = resolveIdentity(graph, parsed.document);
21419
21661
  if (purpose === "write" && named && await visibleText(graph, named) === null) throw protectedDocument(parsed.document);
@@ -22626,8 +22868,8 @@ function createMcpServer(source, info) {
22626
22868
  "search has two kinds of matching: mode \"text\" (default) matches words and quoted phrases, and mode \"semantic\" finds passages about what a question or description means even when no words match. Use semantic for questions and descriptions, text for names, identifiers and exact phrases. \"hybrid\" returns both groups. When you answer from a search result, cite the document and where in it (its breadcrumb or lines). Semantic mode needs a one-time \"semantic setup\" on this computer - if it is not set up, search says so and names the command.",
22627
22869
  "graph_insights says what the links show across the whole graph (the most-linked concepts, pages many documents ask for that do not exist yet, pages linked to nothing, groups of related concepts and the concepts bridging them), and graph_path finds how two concepts are connected. Use them to answer questions about the shape of the graph, or to suggest pages to write or link.",
22628
22870
  "Start with graph_info to see what you are connected to. read_documents reads several documents in one call. tasks lists tasks and set_task changes one (status, priority, due and scheduled dates) by document and line.",
22629
- "An agent instruction is how a person hands you one task: a few lines naming the graph, the task's words and a task reference, etherpk:/g/<graph>/d/<document>#task=<line>-<fingerprint> (an earlier version wrote a web address ending in the same #task=). The reference is not a web address: never fetch it. Pass the whole text to read_task for the task and its detail, to set_task (as reference) to change it, and to add_task_note to write what you did as a task comment (a bullet under the \"- Comments\" bullet nested directly under the task). Leave its status as it is unless the user asks you to change it. Tasks nested under a task are its subtasks: read_task lists them in subtasks, and you may tick off or change each one with set_task as you work through it, using its reference. A Kanban board shows a subtask only through its parent's card when the parent is on the same board. The detail can hold images and files (its assets list): read each with read_asset and look at it before you start, as it is part of the task. A reference finds the task after lines are added above it or its tags change; if its words were edited, or the edit has not reached this computer yet, it answers task_not_found, and you should ask the user for a fresh one.",
22630
- "An agent instruction can also hand you a whole lane of a Kanban board, to work through every task in it or to triage them: a few lines naming the graph, the board and the lane, and a lane reference, etherpk:/g/<graph>/k/<concept>#lane=<status> (etherpk:/g/<graph>/kanban#lane=<status> for the Graph Kanban, which holds every task in the graph). It is not a web address either. Pass the whole text to tasks as reference to list the lane's tasks as the board shows them now; each comes with its own task reference for read_task, set_task and add_task_note.",
22871
+ "An agent instruction is how a person hands you one task: a few lines naming the graph, the task's words and a task reference, etherpk:/graph/sync/<graph id>/d/<document>#task=<line>-<fingerprint> (etherpk:/graph/folder/<folder name>/d/… for a graph folder; an earlier version wrote etherpk:/g/<graph>/d/…, which is still read). The reference is not a web address: never fetch it. Pass the whole text to read_task for the task and its detail, to set_task (as reference) to change it, and to add_task_note to write what you did as a task comment (a bullet under the \"- Comments\" bullet nested directly under the task). Leave its status as it is unless the user asks you to change it. Tasks nested under a task are its subtasks: read_task lists them in subtasks, and you may tick off or change each one with set_task as you work through it, using its reference. A Kanban board shows a subtask only through its parent's card when the parent is on the same board. The detail can hold images and files (its assets list): read each with read_asset and look at it before you start, as it is part of the task. A reference finds the task after lines are added above it or its tags change; if its words were edited, or the edit has not reached this computer yet, it answers task_not_found, and you should ask the user for a fresh one.",
22872
+ "An agent instruction can also hand you a whole lane of a Kanban board, to work through every task in it or to triage them: a few lines naming the graph, the board and the lane, and a lane reference, etherpk:/graph/sync/<graph id>/k/<concept>#lane=<status> (ending /kanban#lane=<status> for the Graph Kanban, which holds every task in the graph). It is not a web address either. Pass the whole text to tasks as reference to list the lane's tasks as the board shows them now; each comes with its own task reference for read_task, set_task and add_task_note.",
22631
22873
  "Publishing: list_publications shows the publications this graph defines (a publication is a page whose frontmatter defines it - its outline is the site navigation) and the public documents none takes. A document is on a site when its frontmatter has public: true and names the publication in publications. create_publication and update_publication change the settings, and publish writes the site into the publish folder the user set for it on this machine with the etherpk-mcp publish command (the tool cannot choose a folder) and returns the report. publish with dryRun: true renders and reports without writing and needs no folder: run it after editing a publication's pages and fix what it names. Diagrams need a browser the user installs once with \"diagrams setup\".",
22632
22874
  "Themes: a publication's look is a theme - Mustache templates, a stylesheet, a script and a manifest. list_themes shows the bundled ones (read-only) and the graph's own. read_theme writes a theme's files to a folder on this machine to read and edit. customise_publication_theme copies a publication's bundled theme into the graph and points the publication at the copy (create_theme copies any theme). write_theme_file, delete_theme_file and import_theme_folder change a graph theme. preview_theme renders a theme to a folder (with screenshots when a browser is set up) to check before publish. For a snippet such as an analytics script, an include slot (update_publication includes, e.g. head) filled by a page may be lighter than a theme copy.",
22633
22875
  "Images and files are assets: upload_asset adds a file from this machine and returns the markdown to paste into a document. To put an image in a drawing, add a line to its excalidraw.drawing fence with the reference, width and height upload_asset returns: {\"type\":\"image\",\"customData\":{\"asset\":\"<reference>\"},\"x\":0,\"y\":0,\"width\":<width>,\"height\":<height>}. A shape added after it draws above it. Add lines only, and never edit or reorder the lines there. read_asset writes an asset to a local file you can open, and list_assets shows the assets documents reference. An asset is available only where a document you can read references it (or you uploaded it this session). read_asset, read_theme and preview_theme write under the graph's downloads directory and return the path - name a folder relative to it, never elsewhere.",
@@ -29321,7 +29563,7 @@ async function openHeadlessGraph(deps) {
29321
29563
  }
29322
29564
  // src/headless-folder.ts
29323
29565
  /**
29324
- * A local graph folder, open in a process with no editor: the client's filesystem store over a
29566
+ * A graph folder, open in a process with no editor: the client's filesystem store over a
29325
29567
  * directory adapter, with the same derived index, persistence and semantic search a synced
29326
29568
  * graph gets from `assembleHeadlessGraph` ([[2026-09-18 Headless Client Serves A Local Folder]]).
29327
29569
  *
@@ -30232,7 +30474,7 @@ var SUBDIRS = [
30232
30474
  * A {@link DirectoryAdapter} over a real directory through `node:fs`: the third adapter behind
30233
30475
  * the seam the filesystem store reads and writes through (the browser's `web-fs-adapter.ts`
30234
30476
  * and the tests' `memory-adapter.ts` are the other two), so `createFilesystemDocumentStore`
30235
- * runs unchanged in the [[Headless Client]] over a local graph folder.
30477
+ * runs unchanged in the [[Headless Client]] over a graph folder.
30236
30478
  *
30237
30479
  * The contract it keeps, because the store's external-change detection depends on it: a
30238
30480
  * listing reports each file's mtime in epoch milliseconds and its size in bytes, a write
@@ -30450,7 +30692,7 @@ var USAGE = `etherpk-mcp - EtherPK Headless Client (an MCP server over one synce
30450
30692
  background process, which holds the graph open, and every serve passes its agent's
30451
30693
  session to that process.
30452
30694
  ${CMD} serve --folder <path> [--no-semantic]
30453
- Serve a local graph folder the same way: no sign-in, no server. The agent gets search,
30695
+ Serve a graph folder the same way: no sign-in, no server. The agent gets search,
30454
30696
  backlinks, tasks and format-safe edits over the folder's markdown, alongside the files
30455
30697
  themselves. Edits made in an editor or by the agent directly are picked up as they land.
30456
30698
  The folder must already be a graph, with pages/ and journals/ folders in it (EtherPK
@@ -31068,7 +31310,7 @@ function graphRequest(command, args) {
31068
31310
  const folder = args.folder?.trim();
31069
31311
  const wanted = args.graph?.trim();
31070
31312
  if (folder && (wanted || args["sync-server"])) fail(`${command} takes either --folder <path> or --graph <id or name> (with an optional --sync-server), not both.`);
31071
- if (!folder && !wanted) fail(`${command} needs --graph <id or name>, or --folder <path> for a local graph folder.`);
31313
+ if (!folder && !wanted) fail(`${command} needs --graph <id or name>, or --folder <path> for a graph folder.`);
31072
31314
  return folder ? {
31073
31315
  kind: "folder",
31074
31316
  path: resolve(folder)
@@ -31309,7 +31551,7 @@ async function hostCommand(args) {
31309
31551
  });
31310
31552
  }
31311
31553
  /**
31312
- * A local graph folder: no sign-in and no server ([[2026-09-18 Headless Client Serves A Local
31554
+ * A graph folder: no sign-in and no server ([[2026-09-18 Headless Client Serves A Local
31313
31555
  * Folder]]). The folder is what it is; the CLI never creates a skeleton in whatever directory
31314
31556
  * was mistyped. The index lives under the cache root, keyed by the folder's path.
31315
31557
  */