@appsoftwareltd/etherpk-mcp 0.18.1 → 0.18.3

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
@@ -713,7 +713,7 @@ function looksLikeAgentSetupCode(value) {
713
713
  }
714
714
  var package_default = {
715
715
  name: "@appsoftwareltd/etherpk-mcp",
716
- version: "0.18.1",
716
+ version: "0.18.3",
717
717
  license: "Elastic-2.0",
718
718
  description: "EtherPK Headless Client: an MCP server over a synced knowledge graph, run beside the agent on the user's own machine.",
719
719
  type: "module",
@@ -4561,6 +4561,22 @@ function withoutFreeTags(text, which = () => true) {
4561
4561
  return (out + text.slice(at)).trim();
4562
4562
  }
4563
4563
  /**
4564
+ * What a task list shows for a task's label: its words, without the tag run or its Free Tags, and
4565
+ * the Free Tags as written, for pills. A task whose text is only Free Tags shows them as its words
4566
+ * with no pills, and one written as Task Tags alone shows its tags.
4567
+ */
4568
+ function taskDisplay(label) {
4569
+ const text = parseTaskTags(label).text;
4570
+ const words = withoutFreeTags(text);
4571
+ return words === "" ? {
4572
+ text: text || label,
4573
+ freeTags: []
4574
+ } : {
4575
+ text: words,
4576
+ freeTags: freeTagsIn(text)
4577
+ };
4578
+ }
4579
+ /**
4564
4580
  * A task's [[Task Status]], from its checkbox and its bare-letter tags: the one statement of the
4565
4581
  * rule, which the index's SQL (`STATUS_SQL` in index-db.ts) mirrors.
4566
4582
  *
@@ -4690,6 +4706,18 @@ new Set(STATE_TAGS.map(([kind]) => kind));
4690
4706
  * construction (ADR 0015). Pure and DOM-free.
4691
4707
  */
4692
4708
  /**
4709
+ * A task's title as a [[Lane Filter]] matches it: the words a [[Kanban Board]] card shows, without
4710
+ * the task's [[Task Tag]] run or [[Free Tag]]s, folded in JS so that case is ignored beyond the
4711
+ * ASCII that SQLite's own LIKE folds.
4712
+ */
4713
+ function taskTitleKey(label) {
4714
+ return taskDisplay(label).text.toLowerCase();
4715
+ }
4716
+ /** What a person typed into a [[Lane Filter]], as {@link taskTitleKey} is searched for it. */
4717
+ function taskTitleSearchKey(typed) {
4718
+ return typed.trim().toLowerCase();
4719
+ }
4720
+ /**
4693
4721
  * A predicate over source line numbers: is this line inside a [[Fenced Code Block]]?
4694
4722
  *
4695
4723
  * A `- [ ] x` written inside a fence must not become a [[Task]]: the [[Tasks View]] would list
@@ -4802,6 +4830,7 @@ function deriveDoc(text, options = {}) {
4802
4830
  const candidateTasks = blocks.filter((b) => b.kind === "task");
4803
4831
  const fenced = candidateTasks.length === 0 ? () => false : fencedLines(text);
4804
4832
  const taskBlocks = candidateTasks.filter((b) => !fenced(b.startLine));
4833
+ const taskIds = new Set(taskBlocks.map((b) => b.localId));
4805
4834
  const tasks = taskBlocks.map((b) => {
4806
4835
  const tags = parseTaskTags(b.label);
4807
4836
  return {
@@ -4818,7 +4847,9 @@ function deriveDoc(text, options = {}) {
4818
4847
  due: tags.due,
4819
4848
  completion: tags.completion,
4820
4849
  scheduled: tags.scheduled,
4821
- freeTag: freeTagsIn(tags.text)[0]?.toLowerCase() ?? null
4850
+ freeTag: freeTagsIn(tags.text)[0]?.toLowerCase() ?? null,
4851
+ parentTaskLocalId: nearestTaskAbove(blocks, taskIds, b),
4852
+ titleKey: taskTitleKey(b.label)
4822
4853
  };
4823
4854
  });
4824
4855
  const maps = deriveMaps(text, blocks, links, lineToBlock);
@@ -4929,6 +4960,11 @@ function deriveMaps(text, blocks, links, lineToBlock) {
4929
4960
  searchText
4930
4961
  };
4931
4962
  }
4963
+ /** The nearest ancestor of `block` that is a task, through any plain bullets and headings between. */
4964
+ function nearestTaskAbove(blocks, taskIds, block) {
4965
+ for (let id = block.parentId; id !== null; id = blocks[id]?.parentId ?? null) if (taskIds.has(id)) return id;
4966
+ return null;
4967
+ }
4932
4968
  /**
4933
4969
  * The [[Task Concept]] rows for one document (ADR 0051): for each task, every concept
4934
4970
  * wikilinked on its own block or on ANY ancestor, up to the root.
@@ -5443,9 +5479,12 @@ CREATE TABLE IF NOT EXISTS tasks (
5443
5479
  priority INTEGER, waiting INTEGER NOT NULL DEFAULT 0, doing INTEGER NOT NULL DEFAULT 0,
5444
5480
  test INTEGER NOT NULL DEFAULT 0, cancelled INTEGER NOT NULL DEFAULT 0,
5445
5481
  archived INTEGER NOT NULL DEFAULT 0, due TEXT, completion TEXT, scheduled TEXT,
5446
- free_tag TEXT);
5482
+ free_tag TEXT, parent_task_local_id INTEGER, title_key TEXT NOT NULL DEFAULT '');
5447
5483
  -- free_tag is the task's first [[Free Tag]], lower-cased, or NULL: what a [[Kanban Board]] section
5448
- -- orders by first (ADR 0166).
5484
+ -- orders by first (ADR 0166). parent_task_local_id is the block of the task's [[Parent Task]], or
5485
+ -- NULL: a column, because which [[Subtask]]s leave a board has to be decided in the WHERE clause
5486
+ -- for its counts and paging to be right (ADR 0174). title_key is the task's words, lower-cased, for a
5487
+ -- [[Lane Filter]], which is in the WHERE clause for the same reason.
5449
5488
  -- [[Task Concept]] (ADR 0051): one row per (task, concept it answers to). Concepts are stored
5450
5489
  -- AS WRITTEN and pooled over [[Alias]]es at query time, exactly as backlinksFor does — baking
5451
5490
  -- the canonical name in would go stale the moment a page is renamed.
@@ -5490,7 +5529,7 @@ CREATE INDEX IF NOT EXISTS aliases_page ON aliases(page_id);
5490
5529
  CREATE INDEX IF NOT EXISTS publication_includes_page ON publication_includes(page_id);
5491
5530
  CREATE INDEX IF NOT EXISTS publication_includes_key ON publication_includes(concept_key);
5492
5531
  CREATE INDEX IF NOT EXISTS links_page ON links(page_id);
5493
- CREATE INDEX IF NOT EXISTS tasks_page ON tasks(page_id);
5532
+ CREATE INDEX IF NOT EXISTS tasks_page ON tasks(page_id, block_local_id);
5494
5533
  -- The Name Filter's whole selectivity: without it, filtering to a concept scans every task
5495
5534
  -- row in the graph. Mirrors links_concept_key, and like it stays put during a bulk rebuild.
5496
5535
  CREATE INDEX IF NOT EXISTS task_concepts_key ON task_concepts(concept_key);
@@ -5527,7 +5566,7 @@ function createSchema(db) {
5527
5566
  db.exec(SCHEMA$1);
5528
5567
  db.run("INSERT OR IGNORE INTO index_metadata (key, value) VALUES ('active_generation', 1)");
5529
5568
  db.run("INSERT OR IGNORE INTO index_metadata (key, value) VALUES ('revision', 0)");
5530
- db.exec(`PRAGMA user_version = 19`);
5569
+ db.exec(`PRAGMA user_version = 21`);
5531
5570
  }
5532
5571
  function activeIndexGeneration(db) {
5533
5572
  return db.all("SELECT value FROM index_metadata WHERE key = 'active_generation'")[0]?.value ?? 1;
@@ -5548,7 +5587,7 @@ function advanceIndexRevision(db) {
5548
5587
  */
5549
5588
  function isUsableIndex(db) {
5550
5589
  try {
5551
- return db.all("PRAGMA user_version")[0]?.user_version === 19;
5590
+ return db.all("PRAGMA user_version")[0]?.user_version === 21;
5552
5591
  } catch {
5553
5592
  return false;
5554
5593
  }
@@ -5696,8 +5735,8 @@ function insertDerived(db, pageId, doc) {
5696
5735
  l.blockLocalId
5697
5736
  ]);
5698
5737
  for (const t of tasks) db.run(`INSERT INTO tasks (page_id, block_local_id, done, text, line,
5699
- priority, waiting, doing, test, cancelled, archived, due, completion, scheduled, free_tag)
5700
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, [
5738
+ priority, waiting, doing, test, cancelled, archived, due, completion, scheduled, free_tag, parent_task_local_id, title_key)
5739
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, [
5701
5740
  pageId,
5702
5741
  t.blockLocalId,
5703
5742
  Number(t.done),
@@ -5712,7 +5751,9 @@ function insertDerived(db, pageId, doc) {
5712
5751
  t.due,
5713
5752
  t.completion,
5714
5753
  t.scheduled,
5715
- t.freeTag
5754
+ t.freeTag,
5755
+ t.parentTaskLocalId,
5756
+ t.titleKey
5716
5757
  ]);
5717
5758
  insertTaskConcepts(db, pageId, doc, tasks, taskConcepts);
5718
5759
  insertMapRows(db, pageId, doc, mapItems, mapConcepts);
@@ -6780,6 +6821,71 @@ var BY_FREE_TAG_SQL = "(t.free_tag IS NULL), t.free_tag ASC";
6780
6821
  */
6781
6822
  var TIE_BREAK_SQL = "p.concept_key ASC, t.line ASC, t.page_id ASC, t.block_local_id ASC";
6782
6823
  /**
6824
+ * Every name a [[Name Filter]] matches: the page it resolves to, by its own name and its [[Alias]]es,
6825
+ * the pooling backlinksFor performs, so filtering by an alias finds tasks written against the
6826
+ * canonical name and vice versa. A name with no page is a [[Pageless Concept]] and matches only
6827
+ * itself, which is right: it has none.
6828
+ */
6829
+ function namesForFilter(db, concept) {
6830
+ const key = conceptKey$1(concept);
6831
+ const pageId = canonicalPageId(db, key);
6832
+ return pageId === null ? [key] : namesForPage(db, pageId);
6833
+ }
6834
+ /** SQL: the task under alias `task` answers to one of `names`. One parameter per name. */
6835
+ function answersToNames(task, alias, names) {
6836
+ return `EXISTS (SELECT 1 FROM task_concepts ${alias}
6837
+ WHERE ${alias}.page_id = ${task}.page_id AND ${alias}.block_local_id = ${task}.block_local_id
6838
+ AND ${alias}.concept_key IN (${names.map(() => "?").join(",")}))`;
6839
+ }
6840
+ /**
6841
+ * SQL: the task is not a [[Subtask]] of a task on the same board (ADR 0174), a board for `names`,
6842
+ * or the Graph Kanban with null. One parameter per name. Its parent is on the board when that task
6843
+ * answers to the board's concept and is not Archived, whatever lane it is in. What is under an
6844
+ * Archived parent or one the board's concept does not reach would otherwise be on no card at all.
6845
+ */
6846
+ function onlyBoardCards(names) {
6847
+ return `(t.parent_task_local_id IS NULL OR NOT EXISTS (
6848
+ SELECT 1 FROM tasks parent
6849
+ WHERE parent.page_id = t.page_id AND parent.block_local_id = t.parent_task_local_id
6850
+ AND NOT ${STATUS_SQL.archived.replaceAll("t.", "parent.")} ${names === null ? "" : `AND ${answersToNames("parent", "ptc", names)}`}))`;
6851
+ }
6852
+ /** The tasks at `priorities`, or null when that is all of them. */
6853
+ function priorityClause(priorities) {
6854
+ if (priorities.length >= TASK_PRIORITY_FILTERS.length) return null;
6855
+ const levels = priorities.filter((p) => p !== null);
6856
+ const clauses = [];
6857
+ if (levels.length > 0) clauses.push(`t.priority IN (${levels.map(() => "?").join(",")})`);
6858
+ if (priorities.includes(null)) clauses.push("t.priority IS NULL");
6859
+ return {
6860
+ sql: `(${clauses.join(" OR ")})`,
6861
+ params: levels
6862
+ };
6863
+ }
6864
+ /** The tasks due in `window` of `today`, or null for any. */
6865
+ function dueClause(window, today) {
6866
+ if (window === "any") return null;
6867
+ if (window === "overdue") return {
6868
+ sql: "(t.due IS NOT NULL AND t.due < ?)",
6869
+ params: [today]
6870
+ };
6871
+ if (window === "today") return {
6872
+ sql: "t.due = ?",
6873
+ params: [today]
6874
+ };
6875
+ return {
6876
+ sql: "(t.due IS NOT NULL AND t.due >= ? AND t.due <= ?)",
6877
+ params: [today, addDays(today, 7)]
6878
+ };
6879
+ }
6880
+ /** The tasks whose title holds `typed`, or null when it asks for nothing. `instr`, not LIKE, so % and _ are plain. */
6881
+ function titleClause(typed) {
6882
+ const key = taskTitleSearchKey(typed ?? "");
6883
+ return key === "" ? null : {
6884
+ sql: "instr(t.title_key, ?) > 0",
6885
+ params: [key]
6886
+ };
6887
+ }
6888
+ /**
6783
6889
  * The WHERE clause and parameters shared by {@link tasksMatching} and its count, so the two
6784
6890
  * can never drift into answering different questions about the same filter.
6785
6891
  *
@@ -6791,39 +6897,25 @@ function taskPredicate(db, query) {
6791
6897
  if (query.statuses.length === 0 || query.priorities.length === 0) return null;
6792
6898
  const where = ["p.generation = ?"];
6793
6899
  const params = [activeIndexGeneration(db)];
6794
- if (query.concept !== null) {
6795
- const key = conceptKey$1(query.concept);
6796
- const pageId = canonicalPageId(db, key);
6797
- const names = pageId === null ? [key] : namesForPage(db, pageId);
6900
+ const names = query.concept === null ? null : namesForFilter(db, query.concept);
6901
+ if (names !== null) {
6798
6902
  if (names.length === 0) return null;
6799
- where.push(`EXISTS (SELECT 1 FROM task_concepts tc
6800
- WHERE tc.page_id = t.page_id AND tc.block_local_id = t.block_local_id
6801
- AND tc.concept_key IN (${names.map(() => "?").join(",")}))`);
6903
+ where.push(answersToNames("t", "tc", names));
6802
6904
  params.push(...names);
6803
6905
  }
6906
+ if (query.asBoard) {
6907
+ where.push(onlyBoardCards(names));
6908
+ params.push(...names ?? []);
6909
+ }
6804
6910
  if (query.statuses.length < TASK_STATUSES.length) where.push(`(${query.statuses.map((s) => STATUS_SQL[s]).join(" OR ")})`);
6805
- if (query.priorities.length < TASK_PRIORITY_FILTERS.length) {
6806
- const levels = query.priorities.filter((p) => p !== null);
6807
- const clauses = [];
6808
- if (levels.length > 0) {
6809
- clauses.push(`t.priority IN (${levels.map(() => "?").join(",")})`);
6810
- params.push(...levels);
6811
- }
6812
- if (query.priorities.includes(null)) clauses.push("t.priority IS NULL");
6813
- where.push(`(${clauses.join(" OR ")})`);
6814
- }
6815
- if (query.due !== "any") {
6816
- const today = query.today;
6817
- if (query.due === "overdue") {
6818
- where.push("(t.due IS NOT NULL AND t.due < ?)");
6819
- params.push(today);
6820
- } else if (query.due === "today") {
6821
- where.push("t.due = ?");
6822
- params.push(today);
6823
- } else {
6824
- where.push("(t.due IS NOT NULL AND t.due >= ? AND t.due <= ?)");
6825
- params.push(today, addDays(today, 7));
6826
- }
6911
+ for (const clause of [
6912
+ priorityClause(query.priorities),
6913
+ dueClause(query.due, query.today),
6914
+ titleClause(query.titleContains)
6915
+ ]) {
6916
+ if (clause === null) continue;
6917
+ where.push(clause.sql);
6918
+ params.push(...clause.params);
6827
6919
  }
6828
6920
  return {
6829
6921
  where: where.join(" AND "),
@@ -6860,59 +6952,129 @@ function tasksMatching(db, query, offset, limit) {
6860
6952
  hits: [],
6861
6953
  hasMore: false
6862
6954
  };
6863
- const ancestry = ancestryFor(db, page);
6955
+ const around = taskSurroundings(db, page, new Set(query.concept === null ? [] : namesForFilter(db, query.concept)));
6864
6956
  return {
6865
- hits: page.map((row) => {
6866
- const found = ancestry.get(row.page_id)?.get(row.block_local_id);
6867
- return {
6868
- ...toHit(row),
6869
- breadcrumb: found?.breadcrumb ?? [],
6870
- parentTask: found?.parentTask ?? null
6871
- };
6872
- }),
6957
+ hits: page.map((row) => ({
6958
+ ...toHit(row),
6959
+ ...around(row)
6960
+ })),
6873
6961
  hasMore
6874
6962
  };
6875
6963
  }
6876
6964
  /**
6877
- * Ancestor labels for a whole page of tasks, and each task's nearest task ancestor: one read for
6878
- * every document involved, then the chains walked in JS. The same shape searchText uses, and for
6879
- * the same reason - a recursive SQL walk per row would be one query per task.
6965
+ * What is around each task on a page of results: one read per table for every document involved,
6966
+ * then the chains walked in JS. The same shape searchText uses, and for the same reason - a
6967
+ * recursive SQL walk per row would be one query per task.
6880
6968
  */
6881
- function ancestryFor(db, rows) {
6969
+ function taskSurroundings(db, rows, asked) {
6882
6970
  const ids = [...new Set(rows.map((row) => row.page_id))];
6883
- const placeholders = ids.map(() => "?").join(",");
6884
- const blocks = db.all(`SELECT page_id, local_id, parent_local_id, kind, label FROM blocks WHERE page_id IN (${placeholders})`, ids);
6971
+ const blocks = blocksOfPages(db, ids);
6972
+ const tasks = tasksOfPages(db, ids);
6973
+ const links = firstLinksOfPages(db, ids);
6974
+ const names = namesOfPages(db, ids);
6975
+ return (row) => {
6976
+ const pageBlocks = blocks.get(row.page_id) ?? /* @__PURE__ */ new Map();
6977
+ const pageTasks = tasks.get(row.page_id) ?? /* @__PURE__ */ new Map();
6978
+ const parent = parentTaskOf(pageTasks, row.block_local_id);
6979
+ const concept = nearestAncestorLink(pageBlocks, links.get(row.page_id), row.block_local_id);
6980
+ return {
6981
+ breadcrumb: searchBreadcrumb(pageBlocks, row.block_local_id),
6982
+ parentTask: parent?.text ?? null,
6983
+ parentTaskLine: parent?.line ?? null,
6984
+ ancestorConcept: concept === null || asked.has(concept.key) || names.get(row.page_id)?.has(concept.key) ? null : concept.concept,
6985
+ subtasks: countSubtasks(pageTasks, row.block_local_id)
6986
+ };
6987
+ };
6988
+ }
6989
+ /** The `?,?,?` for an `IN` over `ids`. */
6990
+ function placeholdersFor(ids) {
6991
+ return ids.map(() => "?").join(",");
6992
+ }
6993
+ function blocksOfPages(db, ids) {
6994
+ const rows = db.all(`SELECT page_id, local_id, parent_local_id, label FROM blocks WHERE page_id IN (${placeholdersFor(ids)})`, [...ids]);
6885
6995
  const byPage = /* @__PURE__ */ new Map();
6886
- for (const block of blocks) {
6887
- let page = byPage.get(block.page_id);
6888
- if (!page) byPage.set(block.page_id, page = /* @__PURE__ */ new Map());
6889
- page.set(block.local_id, {
6890
- parent_local_id: block.parent_local_id,
6891
- kind: block.kind,
6892
- label: block.label
6996
+ for (const row of rows) {
6997
+ let page = byPage.get(row.page_id);
6998
+ if (!page) byPage.set(row.page_id, page = /* @__PURE__ */ new Map());
6999
+ page.set(row.local_id, row);
7000
+ }
7001
+ return byPage;
7002
+ }
7003
+ function tasksOfPages(db, ids) {
7004
+ const rows = db.all(`SELECT page_id, block_local_id, parent_task_local_id, text, line, done, archived FROM tasks WHERE page_id IN (${placeholdersFor(ids)})`, [...ids]);
7005
+ const byPage = /* @__PURE__ */ new Map();
7006
+ for (const row of rows) {
7007
+ let page = byPage.get(row.page_id);
7008
+ if (!page) byPage.set(row.page_id, page = /* @__PURE__ */ new Map());
7009
+ const archived = row.done !== 0 && row.archived !== 0;
7010
+ page.set(row.block_local_id, {
7011
+ parent: row.parent_task_local_id,
7012
+ children: [],
7013
+ text: row.text,
7014
+ line: row.line,
7015
+ finished: row.done !== 0,
7016
+ archived
6893
7017
  });
6894
7018
  }
6895
- const out = /* @__PURE__ */ new Map();
7019
+ for (const page of byPage.values()) for (const [id, task] of page) if (task.parent !== null) page.get(task.parent)?.children.push(id);
7020
+ return byPage;
7021
+ }
7022
+ function parentTaskOf(tasks, localId) {
7023
+ const parent = tasks.get(localId)?.parent ?? null;
7024
+ return parent === null ? null : tasks.get(parent) ?? null;
7025
+ }
7026
+ function countSubtasks(tasks, localId) {
7027
+ const count = {
7028
+ done: 0,
7029
+ total: 0
7030
+ };
7031
+ const stack = [...tasks.get(localId)?.children ?? []];
7032
+ while (stack.length > 0) {
7033
+ const task = tasks.get(stack.pop());
7034
+ if (!task) continue;
7035
+ stack.push(...task.children);
7036
+ if (task.archived) continue;
7037
+ count.total++;
7038
+ if (task.finished) count.done++;
7039
+ }
7040
+ return count;
7041
+ }
7042
+ /** The first concept written on each block that links one, by page. */
7043
+ function firstLinksOfPages(db, ids) {
7044
+ const rows = db.all(`SELECT page_id, block_local_id, concept, concept_key FROM links
7045
+ WHERE page_id IN (${placeholdersFor(ids)}) AND block_local_id IS NOT NULL
7046
+ ORDER BY line ASC, match_start ASC`, [...ids]);
7047
+ const byPage = /* @__PURE__ */ new Map();
6896
7048
  for (const row of rows) {
6897
- const page = byPage.get(row.page_id);
6898
- if (!page) continue;
6899
- let chains = out.get(row.page_id);
6900
- if (!chains) out.set(row.page_id, chains = /* @__PURE__ */ new Map());
6901
- chains.set(row.block_local_id, {
6902
- breadcrumb: searchBreadcrumb(page, row.block_local_id),
6903
- parentTask: nearestTask(page, row.block_local_id)
7049
+ let page = byPage.get(row.page_id);
7050
+ if (!page) byPage.set(row.page_id, page = /* @__PURE__ */ new Map());
7051
+ if (!page.has(row.block_local_id)) page.set(row.block_local_id, {
7052
+ concept: row.concept,
7053
+ key: row.concept_key
6904
7054
  });
6905
7055
  }
6906
- return out;
7056
+ return byPage;
7057
+ }
7058
+ /** Each page's own name and its [[Alias]]es, as keys. */
7059
+ function namesOfPages(db, ids) {
7060
+ const rows = db.all(`SELECT id AS page_id, concept_key AS k FROM pages WHERE id IN (${placeholdersFor(ids)})
7061
+ UNION ALL SELECT page_id, alias_key AS k FROM aliases WHERE page_id IN (${placeholdersFor(ids)})`, [...ids, ...ids]);
7062
+ const byPage = /* @__PURE__ */ new Map();
7063
+ for (const row of rows) {
7064
+ const names = byPage.get(row.page_id);
7065
+ if (names) names.add(row.k);
7066
+ else byPage.set(row.page_id, /* @__PURE__ */ new Set([row.k]));
7067
+ }
7068
+ return byPage;
6907
7069
  }
6908
- /** The label of the nearest ancestor of `localId` that is a task, or null. */
6909
- function nearestTask(blocks, localId) {
7070
+ /** The nearest link on a block above `localId`, its own line not counted. */
7071
+ function nearestAncestorLink(blocks, links, localId) {
7072
+ if (!links) return null;
6910
7073
  let parent = blocks.get(localId)?.parent_local_id ?? null;
6911
7074
  for (let guard = 0; parent !== null && guard <= blocks.size; guard++) {
6912
- const block = blocks.get(parent);
6913
- if (!block) break;
6914
- if (block.kind === "task") return block.label;
6915
- parent = block.parent_local_id;
7075
+ const link = links.get(parent);
7076
+ if (link) return link;
7077
+ parent = blocks.get(parent)?.parent_local_id ?? null;
6916
7078
  }
6917
7079
  return null;
6918
7080
  }
@@ -7228,7 +7390,7 @@ function cacheRoot(env) {
7228
7390
  * recovered from a joined path (see there).
7229
7391
  */
7230
7392
  var CACHE_FILE_NAME = `local-cache.v${CACHE_DB_VERSION}.bin`;
7231
- var INDEX_FILE_NAME = `index.v19.sqlite`;
7393
+ var INDEX_FILE_NAME = `index.v21.sqlite`;
7232
7394
  var VECTORS_FILE_NAME = `vectors.v1.sqlite`;
7233
7395
  function cacheFile(dir) {
7234
7396
  return join(dir, CACHE_FILE_NAME);
@@ -19476,20 +19638,22 @@ function taskSelection(graph, args) {
19476
19638
  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.`);
19477
19639
  return {
19478
19640
  concept: lane.concept,
19479
- statuses: [lane.status]
19641
+ statuses: [lane.status],
19642
+ asBoard: true
19480
19643
  };
19481
19644
  }
19482
19645
  const statuses = args.statuses ?? OPEN_TASK_STATUSES;
19483
19646
  for (const status of statuses) if (!TASK_STATUSES.includes(status)) throw new ToolError("invalid_argument", `Unknown task status "${status}".`);
19484
19647
  return {
19485
19648
  concept: args.concept?.trim() ? args.concept.trim() === "today" ? todayISO() : args.concept.trim() : null,
19486
- statuses
19649
+ statuses,
19650
+ asBoard: args.board ?? false
19487
19651
  };
19488
19652
  }
19489
19653
  async function tasks(graph, args = {}) {
19490
19654
  const offset = bounded(args.offset, 0, Number.MAX_SAFE_INTEGER);
19491
19655
  const limit = bounded(args.limit, 100, 200);
19492
- const { concept, statuses } = taskSelection(graph, args);
19656
+ const { concept, statuses, asBoard } = taskSelection(graph, args);
19493
19657
  const priorities = args.priorities ? args.priorities.map((priority) => priority === "none" ? null : priority) : [...TASK_PRIORITY_FILTERS];
19494
19658
  await graph.store.refresh();
19495
19659
  const hidden = hiddenKeys(graph);
@@ -19504,6 +19668,7 @@ async function tasks(graph, args = {}) {
19504
19668
  priorities,
19505
19669
  due: args.due ?? "any",
19506
19670
  groupBy: "document",
19671
+ asBoard,
19507
19672
  today: todayISO()
19508
19673
  }, offset, limit);
19509
19674
  const shown = result.hits.filter((hit) => !hidden.has(conceptKey(hit.concept)));
@@ -19522,6 +19687,11 @@ async function tasks(graph, args = {}) {
19522
19687
  scheduled: hit.scheduled,
19523
19688
  completion: hit.completion,
19524
19689
  breadcrumb: hit.breadcrumb,
19690
+ parentTask: hit.parentTask === null ? null : {
19691
+ text: hit.parentTask,
19692
+ line: hit.parentTaskLine
19693
+ },
19694
+ subtasks: hit.subtasks,
19525
19695
  freeTags: freeTagsIn(hit.text),
19526
19696
  reference: await referenceFor(graph, hit.concept, hit.line, hit.text)
19527
19697
  }))),
@@ -20193,6 +20363,25 @@ function subtreeEnd(blocks, localId) {
20193
20363
  return end;
20194
20364
  }
20195
20365
  /**
20366
+ * The tasks nested under the task on block `root`, at any depth, in document order, with how many
20367
+ * tasks down each one is. `tasks` are in document order, so a parent is always met before its own
20368
+ * subtasks: only a task whose parent has already been reached is under `root`.
20369
+ */
20370
+ function tasksNestedUnder(tasks, root) {
20371
+ const depths = /* @__PURE__ */ new Map([[root, 0]]);
20372
+ const nested = [];
20373
+ for (const task of tasks) {
20374
+ const above = task.parentTaskLocalId === null ? void 0 : depths.get(task.parentTaskLocalId);
20375
+ if (above === void 0) continue;
20376
+ depths.set(task.blockLocalId, above + 1);
20377
+ nested.push({
20378
+ task,
20379
+ depth: above + 1
20380
+ });
20381
+ }
20382
+ return nested;
20383
+ }
20384
+ /**
20196
20385
  * The task a Task Reference names: its words and tags, where it is now, what is above it (the
20197
20386
  * headings and bullets its breadcrumb names) and its detail (its continuation lines and
20198
20387
  * everything nested under it), and how it was found. For the text around it, read the document.
@@ -20202,10 +20391,11 @@ async function readTask(graph, args) {
20202
20391
  const lines = found.body.split("\n");
20203
20392
  const line = lines[found.line];
20204
20393
  const task = parseTaskLine(line);
20205
- const { blocks } = deriveDoc(found.body);
20394
+ const { blocks, tasks: bodyTasks } = deriveDoc(found.body);
20206
20395
  const block = blocks.find((candidate) => candidate.startLine === found.line);
20207
20396
  const end = block ? subtreeEnd(blocks, block.localId) : found.line;
20208
20397
  const structure = readTaskStructure(lines, found.line);
20398
+ const subtasks = block ? tasksNestedUnder(bodyTasks, block.localId) : [];
20209
20399
  return {
20210
20400
  concept: found.document,
20211
20401
  line: found.line,
@@ -20220,7 +20410,14 @@ async function readTask(graph, args) {
20220
20410
  foundBy: found.foundBy,
20221
20411
  reference: await referenceFor(graph, found.document, found.line, bulletLabel(line)),
20222
20412
  assets: structure?.assets ?? [...new Set(assetReferencesIn(lines.slice(found.line, end + 1).join("\n")))],
20223
- comments: structure ? taskComments(lines, structure) : []
20413
+ comments: structure ? taskComments(lines, structure) : [],
20414
+ subtasks: await Promise.all(subtasks.map(async ({ task: nested, depth }) => ({
20415
+ text: nested.text,
20416
+ status: taskStatus(nested.done, nested),
20417
+ line: nested.line,
20418
+ depth,
20419
+ reference: await referenceFor(graph, found.document, nested.line, nested.text)
20420
+ })))
20224
20421
  };
20225
20422
  }
20226
20423
  /**
@@ -21304,7 +21501,7 @@ function createMcpServer(source, info) {
21304
21501
  "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.",
21305
21502
  "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.",
21306
21503
  "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.",
21307
- "A task reference is how a person hands you one task: a few lines naming the graph, the task's words and a 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. 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 it answers task_not_found, and you should ask the user for a fresh one.",
21504
+ "A task reference is how a person hands you one task: a few lines naming the graph, the task's words and a 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 it answers task_not_found, and you should ask the user for a fresh one.",
21308
21505
  "A lane reference is how a person hands 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 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.",
21309
21506
  "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\".",
21310
21507
  "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.",
@@ -21376,7 +21573,7 @@ function createMcpServer(source, info) {
21376
21573
  }, async (args) => run((graph) => graphPath(graph, args)));
21377
21574
  server.registerTool("tasks", {
21378
21575
  title: "Tasks",
21379
- description: `Tasks ("- [ ]" bullets) across the graph with their tags, and freeTags: the person's own #words anywhere in a task's text (#bug), which carry no status. Defaults to every unfinished task. A concept filter matches tasks written on that page or on a page named for it ("[[Concept]] Notes"), linking it, or nested under a block or heading that links it. A lane reference (a Kanban lane the user copied) in reference lists that lane's tasks: it sets the concept and status, so pass it without concept or statuses; errors invalid_argument (not a lane reference) and other_graph (the lane is in another graph). At most 200 per call.`,
21576
+ description: `Tasks ("- [ ]" bullets) across the graph with their tags, and freeTags: the person's own #words anywhere in a task's text (#bug), which carry no status. Defaults to every unfinished task. A concept filter matches tasks written on that page or on a page named for it ("[[Concept]] Notes"), linking it, or nested under a block or heading that links it. A task nested under another lists its parentTask (its text and line), and subtasks counts the tasks nested under each one (done of total; cancelled counts as done, archived is left out). board: true lists what a Kanban board shows: a task whose parent task is also on the board is left out, as you reach it through its parent with read_task. A lane reference (a Kanban lane the user copied) in reference lists that lane's tasks as the board shows them: it sets the concept and status, so pass it without concept or statuses; errors invalid_argument (not a lane reference) and other_graph (the lane is in another graph). At most 200 per call.`,
21380
21577
  inputSchema: {
21381
21578
  reference: z.string().min(1).optional().describe("A lane reference as the user gave it: the whole text, or the etherpk: reference alone. In place of concept and statuses."),
21382
21579
  concept: concept.optional(),
@@ -21401,13 +21598,14 @@ function createMcpServer(source, info) {
21401
21598
  "today",
21402
21599
  "next7"
21403
21600
  ]).optional(),
21601
+ board: z.boolean().optional().describe("List as a Kanban board shows them: without a task whose parent task is also on the board."),
21404
21602
  offset,
21405
21603
  limit: z.number().int().positive().max(200).optional()
21406
21604
  }
21407
21605
  }, async (args) => run((graph) => tasks(graph, args)));
21408
21606
  server.registerTool("read_task", {
21409
21607
  title: "Read a task",
21410
- description: "The task a task reference names: its text, status, priority, due and scheduled days, its free tags, its document and current 0-based line, its breadcrumb (the headings and bullets above it), its detail (its continuation lines and everything nested under it), foundBy (at_line, moved or other_document), its current reference, assets: the images and files the task and its detail show, to read with read_asset, and comments: the task comments, each the text of one bullet under the \"Comments\" bullet nested directly under the task (they are in its detail too). Errors: task_not_found (its words were edited or it was deleted), task_ambiguous (two tasks have its words; the message names them), other_graph (the reference is from another graph).",
21608
+ description: "The task a task reference names: its text, status, priority, due and scheduled days, its free tags, its document and current 0-based line, its breadcrumb (the headings and bullets above it), its detail (its continuation lines and everything nested under it), foundBy (at_line, moved or other_document), its current reference, assets: the images and files the task and its detail show, to read with read_asset, comments: the task comments, each the text of one bullet under the \"Comments\" bullet nested directly under the task (they are in its detail too), and subtasks: every task nested under it at any depth, each with its text, status, line, depth and a reference for set_task, read_task and add_task_note. Errors: task_not_found (its words were edited or it was deleted), task_ambiguous (two tasks have its words; the message names them), other_graph (the reference is from another graph).",
21411
21609
  inputSchema: { reference: z.string().min(1).describe("The task reference as the user gave it: the whole text, or the etherpk: reference alone.") }
21412
21610
  }, async (args) => run((graph) => readTask(graph, args)));
21413
21611
  server.registerTool("add_task_note", {