@appsoftwareltd/etherpk-mcp 0.30.0 → 0.32.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.30.0",
823
+ version: "0.32.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",
@@ -4923,7 +4923,15 @@ function parseTaskTextFilter(typed) {
4923
4923
  * and the index is plaintext at rest, so the conservative reading is the only safe one.
4924
4924
  */
4925
4925
  function fencedLines(text) {
4926
- const lines = text.split("\n");
4926
+ return indexFencedLines(text.split("\n"));
4927
+ }
4928
+ /**
4929
+ * {@link fencedLines} over a document's lines: whether the index reads 0-based line `line` as fenced,
4930
+ * so that a `- [ ]` there is no task. The editor draws a task's checkbox from this same answer
4931
+ * (`task-checkbox.ts`), so a checkbox shows exactly where the [[Tasks View]] lists a task, at every
4932
+ * step of typing a fence, before its closer arrives too.
4933
+ */
4934
+ function indexFencedLines(lines) {
4927
4935
  const spans = fencedBlocks(lines).map((b) => [b.start, b.end]);
4928
4936
  const inside = (line) => spans.some(([from, to]) => line >= from && line <= to);
4929
4937
  for (let index = 0; index < lines.length; index++) {
@@ -5565,8 +5573,15 @@ function parseSearchQuery(input, knownKeys) {
5565
5573
  terms
5566
5574
  };
5567
5575
  }
5568
- /** The filter for a value as typed, or null when there is no value yet. */
5569
- function filterValue(key, raw, negated) {
5576
+ /**
5577
+ * The filter for a value as typed, or null when there is no value yet.
5578
+ *
5579
+ * The value is trimmed. A token only holds whitespace after a quote, and an unclosed one runs to
5580
+ * the end of the input (`status:done" ` while typing), so without this the value would carry the
5581
+ * input's trailing whitespace, and lose it when taking another filter out trimmed the input.
5582
+ */
5583
+ function filterValue(key, typed, negated) {
5584
+ const raw = typed.trim();
5570
5585
  if (raw === "*") return {
5571
5586
  key,
5572
5587
  value: null,
@@ -5585,7 +5600,7 @@ function filterValue(key, raw, negated) {
5585
5600
  }
5586
5601
  if (raw.length > 1 && raw.endsWith("*")) return {
5587
5602
  key,
5588
- value: raw.slice(0, -1),
5603
+ value: raw.slice(0, -1).trimEnd(),
5589
5604
  prefix: true,
5590
5605
  negated
5591
5606
  };
@@ -9759,7 +9774,7 @@ function keyRetryDelayMs(round, random = Math.random) {
9759
9774
  return Math.floor(ceiling / 2 + random() * (ceiling / 2));
9760
9775
  }
9761
9776
  // ../client/src/lib/document/quick-notes.ts
9762
- /** A hard ceiling, so a corrupt or hostile list cannot swamp the View or the root doc. */
9777
+ /** A hard ceiling, so a corrupt or hostile list cannot swamp the modal or the root doc. */
9763
9778
  var MAX_QUICK_NOTES = 1e4;
9764
9779
  /**
9765
9780
  * Keep only well-formed notes, deduped by id (first seen wins) - tolerant of a hand-edited
@@ -10872,6 +10887,8 @@ var RelayUnansweredError = class extends Error {};
10872
10887
  function createGraphSync(deps) {
10873
10888
  const engines = /* @__PURE__ */ new Map();
10874
10889
  const retained = /* @__PURE__ */ new Map([[deps.rootDocId, 1]]);
10890
+ /** Documents watched for edits (`watchDocs`), by how many watches hold each. */
10891
+ const watched = /* @__PURE__ */ new Map();
10875
10892
  const retiring = /* @__PURE__ */ new Set();
10876
10893
  /**
10877
10894
  * Batch walks holding an engine: one count per `seedDocsFromCache` or `readyDocs` not yet
@@ -11131,13 +11148,28 @@ function createGraphSync(deps) {
11131
11148
  * reconnect.
11132
11149
  */
11133
11150
  function subscribeRetained() {
11134
- const docIds = [...retained.keys()];
11151
+ const docIds = [.../* @__PURE__ */ new Set([...retained.keys(), ...watched.keys()])];
11135
11152
  const batchSize = SYNC_PROTOCOL_LIMITS.maxSubscriptionDocIds;
11136
11153
  for (let start = 0; start < docIds.length; start += batchSize) sendNow({
11137
11154
  type: "subscribe",
11138
11155
  docIds: docIds.slice(start, start + batchSize)
11139
11156
  });
11140
11157
  }
11158
+ /** Subscribe to documents, or unsubscribe, in batches the relay accepts. Closed, the next open subscribes. */
11159
+ function sendSubscription(type, docIds) {
11160
+ if (!open || docIds.length === 0) return;
11161
+ const batchSize = SYNC_PROTOCOL_LIMITS.maxSubscriptionDocIds;
11162
+ for (let start = 0; start < docIds.length; start += batchSize) {
11163
+ const batch = docIds.slice(start, start + batchSize);
11164
+ rawSend(type === "subscribe" ? {
11165
+ type: "subscribe",
11166
+ docIds: batch
11167
+ } : {
11168
+ type: "unsubscribe",
11169
+ docIds: batch
11170
+ });
11171
+ }
11172
+ }
11141
11173
  function pumpCatchups() {
11142
11174
  if (!open || !socket || catchupInFlight) return;
11143
11175
  catchupInFlight = foregroundCatchups.shift() ?? backgroundCatchups.shift();
@@ -11207,6 +11239,8 @@ function createGraphSync(deps) {
11207
11239
  sendNow(message);
11208
11240
  }
11209
11241
  const readied = /* @__PURE__ */ new Map();
11242
+ /** Documents a `catchUpDoc` is waiting on: their catch-up goes ahead of background walks. */
11243
+ const urgentCatchups = /* @__PURE__ */ new Map();
11210
11244
  const syncEnabled = /* @__PURE__ */ new Set();
11211
11245
  function activate(docId, e) {
11212
11246
  readied.set(docId, e.ready());
@@ -11337,7 +11371,7 @@ function createGraphSync(deps) {
11337
11371
  onIdle: () => queueMicrotask(() => retireEngineIfIdle(docId)),
11338
11372
  onQueueChange: () => noteQueue(docId),
11339
11373
  catchupPriority: () => {
11340
- return retained.has(docId) ? "foreground" : "background";
11374
+ return retained.has(docId) || urgentCatchups.has(docId) ? "foreground" : "background";
11341
11375
  }
11342
11376
  });
11343
11377
  engines.set(docId, e);
@@ -11529,7 +11563,16 @@ function createGraphSync(deps) {
11529
11563
  engine(message.docId).receive(message).catch(report).finally(() => finishCatchup(message.requestId));
11530
11564
  return;
11531
11565
  }
11532
- engine(message.docId).receive(message).catch(report);
11566
+ engineForPushed(message.docId).receive(message).catch(report);
11567
+ }
11568
+ /**
11569
+ * The engine a relay message for `docId` goes to. An edit to a watched document nobody shows
11570
+ * makes one to take it in; it goes once idle, as an engine a read made does, and the watch's
11571
+ * subscription brings the next edit.
11572
+ */
11573
+ function engineForPushed(docId) {
11574
+ if (!engines.has(docId) && watched.has(docId) && !retained.has(docId)) retiring.add(docId);
11575
+ return engine(docId);
11533
11576
  }
11534
11577
  /**
11535
11578
  * Forget everything that belonged to one socket generation. Durable IndexedDB rows, not these
@@ -11717,7 +11760,7 @@ function createGraphSync(deps) {
11717
11760
  if (open) retainedEngine.advertisePresence().catch(reportError);
11718
11761
  return;
11719
11762
  }
11720
- rawSend({
11763
+ if (!watched.has(docId)) rawSend({
11721
11764
  type: "unsubscribe",
11722
11765
  docIds: [docId]
11723
11766
  });
@@ -11725,6 +11768,35 @@ function createGraphSync(deps) {
11725
11768
  });
11726
11769
  };
11727
11770
  },
11771
+ watchDocs(docIds) {
11772
+ const ids = [...new Set(docIds)].filter((docId) => docId !== deps.rootDocId);
11773
+ const started = [];
11774
+ for (const docId of ids) {
11775
+ const count = watched.get(docId) ?? 0;
11776
+ watched.set(docId, count + 1);
11777
+ if (count === 0 && !retained.has(docId)) started.push(docId);
11778
+ }
11779
+ sendSubscription("subscribe", started);
11780
+ let released = false;
11781
+ return () => {
11782
+ if (released || disposed) return;
11783
+ released = true;
11784
+ const ended = [];
11785
+ for (const docId of ids) {
11786
+ const next = (watched.get(docId) ?? 1) - 1;
11787
+ if (next > 0) {
11788
+ watched.set(docId, next);
11789
+ continue;
11790
+ }
11791
+ watched.delete(docId);
11792
+ if (retained.has(docId)) continue;
11793
+ ended.push(docId);
11794
+ retiring.add(docId);
11795
+ retireEngineIfIdle(docId);
11796
+ }
11797
+ sendSubscription("unsubscribe", ended);
11798
+ };
11799
+ },
11728
11800
  deleteDoc: (docId) => engine(docId).delete(),
11729
11801
  compactDoc: (docId) => deps.cache.docCache(docId).compact(),
11730
11802
  uploadSnapshot: (docId) => engine(docId).compact(),
@@ -12126,6 +12198,20 @@ function createGraphSync(deps) {
12126
12198
  retireDocs: releaseBatch,
12127
12199
  firstCatchupPageDoc: (docId) => engine(docId).firstCatchupPage(),
12128
12200
  caughtUpDoc: (docId) => engine(docId).caughtUp(),
12201
+ async catchUpDoc(docId) {
12202
+ const e = engine(docId);
12203
+ await (readied.get(docId) ?? Promise.resolve());
12204
+ if (disposed || !open || engines.get(docId) !== e) return;
12205
+ urgentCatchups.set(docId, (urgentCatchups.get(docId) ?? 0) + 1);
12206
+ try {
12207
+ e.resync();
12208
+ await e.caughtUp();
12209
+ } finally {
12210
+ const left = (urgentCatchups.get(docId) ?? 1) - 1;
12211
+ if (left > 0) urgentCatchups.set(docId, left);
12212
+ else urgentCatchups.delete(docId);
12213
+ }
12214
+ },
12129
12215
  async docsNeedingCatchup(docIds) {
12130
12216
  const changed = [];
12131
12217
  for (let start = 0; start < docIds.length; start += SYNC_PROTOCOL_LIMITS.maxSubscriptionDocIds) {
@@ -25806,36 +25892,56 @@ function isDocumentFile(name) {
25806
25892
  function fileKey(subdir, fileName) {
25807
25893
  return `${subdir}/${fileName}`;
25808
25894
  }
25895
+ /** A file's text, or null when it is no longer there. Any other failure is the caller's. */
25896
+ async function readUnlessGone(adapter, subdir, name) {
25897
+ try {
25898
+ return (await adapter.read(subdir, name)).text;
25899
+ } catch (error) {
25900
+ if (error?.name === "NotFoundError") return null;
25901
+ throw error;
25902
+ }
25903
+ }
25904
+ /**
25905
+ * The entry for one listed document file: the last scan's, when the listing's stamps have not moved
25906
+ * (or a save of ours is writing it), else read from the file. Null for a file removed since the
25907
+ * listing (a delete or a rename finishing while a reconcile scans): it is gone.
25908
+ */
25909
+ async function entryFor(context, subdir, kind, listed) {
25910
+ const { name, lastModified, size } = listed;
25911
+ const known = context.previous.get(fileKey(subdir, name));
25912
+ if (known && (known.lastModified === lastModified && known.size === size || context.writeInFlight(subdir, name))) return known;
25913
+ const text = await readUnlessGone(context.adapter, subdir, name);
25914
+ if (text === null) return null;
25915
+ const fm = parseFrontmatter(text);
25916
+ const concept = kind === "journal" ? journalConceptOf(name) : conceptOf$1(fm, fileStem(name));
25917
+ return {
25918
+ kind,
25919
+ concept,
25920
+ key: conceptKey(concept),
25921
+ subdir,
25922
+ fileName: name,
25923
+ aliases: aliasesOf(fm),
25924
+ lastModified,
25925
+ size
25926
+ };
25927
+ }
25809
25928
  async function scanGraph(adapter, options = {}) {
25810
25929
  const previous = /* @__PURE__ */ new Map();
25811
25930
  for (const entry of options.previous ?? []) previous.set(fileKey(entry.subdir, entry.fileName), entry);
25812
- const writeInFlight = options.writeInFlight ?? (() => false);
25931
+ const context = {
25932
+ adapter,
25933
+ previous,
25934
+ writeInFlight: options.writeInFlight ?? (() => false)
25935
+ };
25813
25936
  const journals = [];
25814
25937
  const pages = [];
25815
25938
  for (const subdir of SCANNED_SUBDIRS) {
25816
25939
  const kind = documentKindOf(subdir);
25817
25940
  if (!kind) continue;
25818
- for (const { name, lastModified, size } of await adapter.list(subdir)) {
25819
- if (!isDocumentFile(name)) continue;
25820
- const known = previous.get(fileKey(subdir, name));
25821
- if (known !== void 0 && (known.lastModified === lastModified && known.size === size || writeInFlight(subdir, name))) {
25822
- (kind === "journal" ? journals : pages).push(known);
25823
- continue;
25824
- }
25825
- const { text } = await adapter.read(subdir, name);
25826
- const fm = parseFrontmatter(text);
25827
- const concept = kind === "journal" ? journalConceptOf(name) : conceptOf$1(fm, fileStem(name));
25828
- const entry = {
25829
- kind,
25830
- concept,
25831
- key: conceptKey(concept),
25832
- subdir,
25833
- fileName: name,
25834
- aliases: aliasesOf(fm),
25835
- lastModified,
25836
- size
25837
- };
25838
- (kind === "journal" ? journals : pages).push(entry);
25941
+ for (const listed of await adapter.list(subdir)) {
25942
+ if (!isDocumentFile(listed.name)) continue;
25943
+ const entry = await entryFor(context, subdir, kind, listed);
25944
+ if (entry) (kind === "journal" ? journals : pages).push(entry);
25839
25945
  }
25840
25946
  }
25841
25947
  journals.sort((a, b) => b.concept.localeCompare(a.concept));
@@ -27444,6 +27550,12 @@ function createServerDocumentStore(graph, options) {
27444
27550
  const health = graph.docSync(docId).health();
27445
27551
  if (health === "key-unavailable" || health === "ciphertext-corrupt") throw new DocumentSyncDegradedError(target, health);
27446
27552
  },
27553
+ async whenCurrent(target) {
27554
+ const docId = docIdFor(target);
27555
+ if (!docId) return;
27556
+ await this.whenReady(target);
27557
+ await reachedWithin(graph.catchUpDoc(docId), Math.max(0, options.readyTimeoutMs ?? 2e3));
27558
+ },
27447
27559
  getAwareness(target) {
27448
27560
  const docId = docIdFor(target);
27449
27561
  return docId ? graph.docSync(docId).awareness : void 0;
@@ -27452,6 +27564,10 @@ function createServerDocumentStore(graph, options) {
27452
27564
  const docId = docIdFor(target);
27453
27565
  return docId ? graph.retainDoc(docId) : () => {};
27454
27566
  },
27567
+ watchDocuments(targets) {
27568
+ const docIds = targets.map((target) => docIdFor(target)).filter((docId) => docId !== void 0);
27569
+ return graph.watchDocs(docIds);
27570
+ },
27455
27571
  async scan() {
27456
27572
  await graph.ready();
27457
27573
  if (graph.isConnected() || await new Promise((resolve) => {