pi-vault-mind 0.14.2 → 0.16.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/README.md +5 -5
  3. package/agents/broadcaster.agent.md +2 -2
  4. package/agents/heavy-lifter.agent.md +1 -1
  5. package/agents/main.agent.md +29 -0
  6. package/agents/manager.agent.md +1 -1
  7. package/agents/miner.agent.md +1 -1
  8. package/dist/packages/obsidian/src/client.js +331 -0
  9. package/dist/packages/obsidian/src/types.js +1 -0
  10. package/dist/src/activity.d.ts +49 -0
  11. package/dist/src/activity.js +175 -0
  12. package/dist/src/agent-bus/Agent.d.ts +9 -1
  13. package/dist/src/agent-bus/Agent.js +18 -2
  14. package/dist/src/agent-bus/index.d.ts +5 -5
  15. package/dist/src/agent-bus/index.js +1 -1
  16. package/dist/src/agent-queue.js +12 -3
  17. package/dist/src/agents/BroadcasterAgent.d.ts +1 -1
  18. package/dist/src/agents/BroadcasterAgent.js +2 -2
  19. package/dist/src/agents/HeavyLifterAgent.d.ts +1 -1
  20. package/dist/src/agents/HeavyLifterAgent.js +2 -2
  21. package/dist/src/agents/ManagerAgent.js +1 -1
  22. package/dist/src/agents/MinerAgent.d.ts +1 -1
  23. package/dist/src/agents/MinerAgent.js +2 -2
  24. package/dist/src/agents/index.d.ts +2 -2
  25. package/dist/src/agents/index.js +2 -2
  26. package/dist/src/auth.d.ts +17 -15
  27. package/dist/src/auth.js +26 -37
  28. package/dist/src/autosync.js +2 -2
  29. package/dist/src/commands.d.ts +2 -19
  30. package/dist/src/commands.js +301 -231
  31. package/dist/src/config-keys.d.ts +16 -0
  32. package/dist/src/config-keys.js +45 -0
  33. package/dist/src/discover-schema.js +4 -4
  34. package/dist/src/edits.d.ts +21 -0
  35. package/dist/src/edits.js +75 -0
  36. package/dist/src/embedding-probe.d.ts +34 -0
  37. package/dist/src/embedding-probe.js +142 -0
  38. package/dist/src/embedding-providers.d.ts +133 -0
  39. package/dist/src/embedding-providers.js +173 -0
  40. package/dist/src/embedding-secrets.d.ts +38 -0
  41. package/dist/src/embedding-secrets.js +291 -0
  42. package/dist/src/engine.d.ts +6 -0
  43. package/dist/src/engine.js +78 -6
  44. package/dist/src/events.js +7 -10
  45. package/dist/src/extension-packages.d.ts +9 -0
  46. package/dist/src/extension-packages.js +14 -0
  47. package/dist/src/git.d.ts +19 -0
  48. package/dist/src/git.js +78 -0
  49. package/dist/src/graph.d.ts +2 -1
  50. package/dist/src/graph.js +47 -13
  51. package/dist/src/identities-config.d.ts +6 -0
  52. package/dist/src/identities-config.js +39 -0
  53. package/dist/src/identity-injector.js +1 -1
  54. package/dist/src/index.js +9 -26
  55. package/dist/src/lance.d.ts +9 -0
  56. package/dist/src/lance.js +143 -203
  57. package/dist/src/modal-client.d.ts +16 -0
  58. package/dist/src/modal-client.js +16 -0
  59. package/dist/src/modal-config.d.ts +37 -14
  60. package/dist/src/modal-config.js +59 -32
  61. package/dist/src/model-router.d.ts +27 -0
  62. package/dist/src/model-router.js +67 -0
  63. package/dist/src/models.d.ts +42 -0
  64. package/dist/src/models.js +78 -0
  65. package/dist/src/personalize.js +17 -3
  66. package/dist/src/scaffold.d.ts +48 -0
  67. package/dist/src/scaffold.js +246 -0
  68. package/dist/src/server.d.ts +47 -4
  69. package/dist/src/server.js +988 -221
  70. package/dist/src/session-search.d.ts +63 -0
  71. package/dist/src/session-search.js +379 -0
  72. package/dist/src/settings-ui.d.ts +2 -2
  73. package/dist/src/settings-ui.js +76 -135
  74. package/dist/src/sync.d.ts +3 -3
  75. package/dist/src/sync.js +19 -15
  76. package/dist/src/tool-catalog.d.ts +18 -0
  77. package/dist/src/tool-catalog.js +232 -0
  78. package/dist/src/tools/marksman.js +1 -1
  79. package/dist/src/tools.js +111 -65
  80. package/dist/src/types.d.ts +127 -71
  81. package/dist/src/utils.d.ts +57 -6
  82. package/dist/src/utils.js +114 -28
  83. package/dist/src/vault-tools.d.ts +34 -0
  84. package/dist/src/vault-tools.js +99 -0
  85. package/dist/src/vault-writer.js +4 -1
  86. package/dist/src/vm-handlers.js +140 -43
  87. package/dist/src/watcher.js +9 -9
  88. package/dist/test/activity-tool.test.js +54 -0
  89. package/dist/test/agent-bus/Agent.test.js +174 -0
  90. package/dist/test/agent-bus/AgentLoader.test.js +180 -0
  91. package/dist/test/agent-bus/AgentRegistry.test.js +86 -0
  92. package/dist/test/agent-bus/LLMProvider.test.js +162 -0
  93. package/dist/test/agent-bus/TaskQueue.test.js +256 -0
  94. package/dist/test/agent-dispatch-context.test.js +73 -0
  95. package/dist/test/agent-queue.test.js +1 -1
  96. package/dist/test/agents/Agents.test.js +282 -0
  97. package/dist/test/auth.test.js +57 -56
  98. package/dist/test/bridge-identity.test.js +34 -3
  99. package/dist/test/classify-search-mode.test.js +51 -0
  100. package/dist/test/commands.test.js +410 -0
  101. package/dist/test/config-merge.test.js +98 -0
  102. package/dist/test/context-capture.test.js +56 -0
  103. package/dist/test/discover-schema.test.js +8 -5
  104. package/dist/test/dispatch.test.js +45 -91
  105. package/dist/test/edits.test.js +144 -0
  106. package/dist/test/embedding-probe.test.js +424 -0
  107. package/dist/test/embedding-providers.test.js +157 -0
  108. package/dist/test/embedding-secrets.test.js +210 -0
  109. package/dist/test/engine-identity.test.js +1 -1
  110. package/dist/test/events.test.js +675 -0
  111. package/dist/test/git-bridge.test.js +160 -0
  112. package/dist/test/graph.test.js +464 -0
  113. package/dist/test/helpers/server.js +81 -0
  114. package/dist/test/identity-injector.test.js +197 -0
  115. package/dist/test/index.test.js +5 -7
  116. package/dist/test/lance-modal.test.js +67 -2
  117. package/dist/test/lance.test.js +429 -0
  118. package/dist/test/modal-client.test.js +1 -1
  119. package/dist/test/modal-config.test.js +92 -79
  120. package/dist/test/model-readiness.test.js +122 -0
  121. package/dist/test/model-router.test.js +99 -0
  122. package/dist/test/obsidian-client.test.js +42 -0
  123. package/dist/test/personalize.test.js +1 -1
  124. package/dist/test/rest-models.test.js +153 -0
  125. package/dist/test/rest-queue.test.js +135 -87
  126. package/dist/test/rest-setup.test.js +625 -115
  127. package/dist/test/rest-vm.test.js +355 -94
  128. package/dist/test/server-cors.test.js +48 -0
  129. package/dist/test/server-ws.test.js +61 -34
  130. package/dist/test/session-crud.test.js +323 -0
  131. package/dist/test/session-search.test.js +139 -0
  132. package/dist/test/settings-ui.test.js +113 -4
  133. package/dist/test/sync.test.js +12 -12
  134. package/dist/test/tombstone.test.js +8 -10
  135. package/dist/test/tool-catalog.test.js +86 -0
  136. package/dist/test/utils.test.js +588 -0
  137. package/dist/test/vault-tools.test.js +103 -12
  138. package/dist/test/vault-writer.test.js +371 -0
  139. package/dist/test/vm-handlers.test.js +620 -0
  140. package/extension-packages.json +9 -0
  141. package/package.json +107 -90
  142. package/pi-vault-mind.config.example.json +24 -2
  143. package/scripts/check-deps.sh +35 -32
  144. package/scripts/cli-e2e.mjs +215 -0
  145. package/scripts/configuration-e2e.mjs +783 -0
  146. package/scripts/e2e-commands.mjs +391 -0
  147. package/scripts/e2e-ws.mjs +3 -2
  148. package/scripts/fetch-modal-token.sh +4 -3
  149. package/scripts/generate-config-keys-json.mjs +45 -0
  150. package/scripts/generate-extension-packages-json.mjs +55 -0
  151. package/scripts/pi-session-query +0 -0
  152. package/scripts/publish-obsidian-plugin.sh +0 -0
  153. package/scripts/reset-test-vault.sh +2 -2
  154. package/scripts/setup-test-config.sh +0 -0
  155. package/scripts/setup-vault-pi.sh +48 -9
  156. package/scripts/test-slash-commands.mjs +2 -2
  157. package/scripts/vault-pi.sh +12 -3
  158. package/skills/github-release-notes-file/SKILL.md +42 -0
  159. package/skills/obsidian-guided-test-session/SKILL.md +110 -0
  160. package/skills/obsidian-interactive-test/SKILL.md +88 -0
  161. package/skills/obsidian-plugin-publish/SKILL.md +58 -0
  162. package/skills/pi-vault-mind-release/SKILL.md +141 -0
  163. package/skills/pre-test-release/SKILL.md +116 -0
  164. package/dist/test/auto-indexer.test.js +0 -2
@@ -297,6 +297,86 @@ export const vaultTagsTool = defineTool({
297
297
  }
298
298
  },
299
299
  });
300
+ /**
301
+ * Search the Obsidian vault's own index (filenames/titles, paths, tags) without
302
+ * hitting LanceDB. Lists `.md` files under `vaultPath` and scores each by title
303
+ * match (frontmatter `title` or basename), path substring, and tag match
304
+ * (frontmatter + inline `#tags`). Returns ranked vault hits. Empty vault or empty
305
+ * query yields `[]`; never throws.
306
+ */
307
+ export const searchVaultNative = async (vaultPath, query, limit, tags) => {
308
+ const q = query.trim().toLowerCase();
309
+ if (!vaultPath || !q)
310
+ return [];
311
+ let mdFiles;
312
+ try {
313
+ if (!fs.existsSync(vaultPath))
314
+ return [];
315
+ mdFiles = listFilesRecursive(vaultPath, vaultPath).filter((f) => f.toLowerCase().endsWith(".md"));
316
+ }
317
+ catch {
318
+ return [];
319
+ }
320
+ const wantTags = (tags ?? []).map((t) => t.replace(/^#/, "").toLowerCase()).filter(Boolean);
321
+ const scored = [];
322
+ for (const relPath of mdFiles) {
323
+ let content;
324
+ try {
325
+ content = fs.readFileSync(path.join(vaultPath, relPath), "utf-8");
326
+ }
327
+ catch {
328
+ continue;
329
+ }
330
+ const fm = extractFrontmatter(content);
331
+ const fmTitle = (fm?.title ?? "").trim();
332
+ const title = fmTitle || path.basename(relPath, path.extname(relPath));
333
+ const fileTags = [
334
+ ...new Set([...extractFrontmatterTags(content), ...extractInlineTags(content)]),
335
+ ];
336
+ const fileTagsLc = fileTags.map((t) => t.toLowerCase());
337
+ const normalizedPath = relPath.replace(/\\/g, "/").toLowerCase();
338
+ const titleLc = title.toLowerCase();
339
+ let score = 0;
340
+ if (titleLc === q)
341
+ score += 10;
342
+ else if (titleLc.includes(q))
343
+ score += 5;
344
+ if (normalizedPath.includes(q))
345
+ score += 2;
346
+ if (fileTagsLc.includes(q))
347
+ score += 3;
348
+ if (wantTags.length > 0) {
349
+ score += wantTags.filter((t) => fileTagsLc.includes(t)).length * 3;
350
+ }
351
+ if (score > 0) {
352
+ scored.push({
353
+ hit: { source: relPath.replace(/\\/g, "/"), title, tags: fileTags, _source: "vault" },
354
+ score,
355
+ });
356
+ }
357
+ }
358
+ scored.sort((a, b) => b.score - a.score || a.hit.source.localeCompare(b.hit.source));
359
+ return scored.slice(0, Math.max(0, limit)).map((s) => s.hit);
360
+ };
361
+ /**
362
+ * Flatten a `queryGraph` result into the unified search shape: every entity
363
+ * becomes a hit tagged `_source: "graph"` (with `entity` set to its name), the
364
+ * raw relations array is preserved as a sibling, and any miss `message` is
365
+ * carried through so callers can surface "no matching entities" instead of
366
+ * losing it. Shared by all three vm_search dispatchers so the graph result
367
+ * shape cannot drift between the HTTP, bridge, and pi-tool surfaces.
368
+ */
369
+ export const normalizeGraphResult = (graphResult) => {
370
+ const g = (graphResult ?? {});
371
+ const hits = (g.entities ?? []).map((e) => {
372
+ const row = e;
373
+ return { ...row, entity: row.name, _source: "graph" };
374
+ });
375
+ const normalized = { hits, relations: g.relations ?? [] };
376
+ if (g.message !== undefined)
377
+ normalized.message = g.message;
378
+ return normalized;
379
+ };
300
380
  export const registerVaultTools = (pi) => {
301
381
  const existing = new Set(pi.getAllTools().map((t) => t.name));
302
382
  if (!existing.has("vault_read"))
@@ -312,3 +392,22 @@ export const registerVaultTools = (pi) => {
312
392
  if (!existing.has("vault_tags"))
313
393
  pi.registerTool(vaultTagsTool);
314
394
  };
395
+ /** Infer an explicit search strategy from a natural-language query (Auto mode).
396
+ * Deterministic heuristics; never returns "auto"/"vault"/"full". */
397
+ export function classifySearchMode(query) {
398
+ const q = query.trim();
399
+ if (!q)
400
+ return { mode: "hybrid", rationale: "Empty query — using balanced hybrid search." };
401
+ if (/["'][^"']+["']/.test(q))
402
+ return { mode: "fts", rationale: "Quoted phrase — matching exact words." };
403
+ const lower = q.toLowerCase();
404
+ if (/^(who|what)\s+(is|are|was|were)\s+/.test(lower) ||
405
+ /\b(related to|connected to|connections?|depends? on|relationship)\b/.test(lower))
406
+ return { mode: "graph", rationale: "Entity or its connections — traversing the graph." };
407
+ if (q.endsWith("?") ||
408
+ /^(how|why|when|where|can|should|does|do|is|are|will|would|explain|summari[sz]e|tell me)\b/.test(lower))
409
+ return { mode: "semantic", rationale: "Natural-language question — searching by meaning." };
410
+ if (q.split(/\s+/).length <= 3)
411
+ return { mode: "hybrid", rationale: "Short keywords — blending meaning and exact matches." };
412
+ return { mode: "semantic", rationale: "Descriptive phrase — searching by meaning." };
413
+ }
@@ -94,7 +94,9 @@ export class VaultWriter {
94
94
  async syncGraphToCanvas() {
95
95
  const libraryDir = this.libraryDir();
96
96
  this.ensureDir(libraryDir);
97
- const canvasPath = path.join(libraryDir, "Library-Graph.canvas");
97
+ const canvasPath = this.cfg.graph?.canvasPath
98
+ ? path.join(this.vaultPath, this.cfg.graph.canvasPath)
99
+ : path.join(libraryDir, "Library-Graph.canvas");
98
100
  try {
99
101
  const db = await connect(this.cfg.dataDir);
100
102
  const existing = await db.tableNames();
@@ -131,6 +133,7 @@ export class VaultWriter {
131
133
  });
132
134
  }
133
135
  }
136
+ this.ensureDir(path.dirname(canvasPath));
134
137
  fs.writeFileSync(canvasPath, JSON.stringify({ nodes, edges }, null, 2), "utf-8");
135
138
  return edges.length;
136
139
  }
@@ -13,11 +13,10 @@ import * as path from "node:path";
13
13
  import { promisify } from "node:util";
14
14
  import { registerExtensionToolHandler } from "./bridge.js";
15
15
  import { queryGraph } from "./graph.js";
16
- import { queryCollection, searchFts, searchHybrid, upsertEntry } from "./lance.js";
17
- import { getStatus } from "./lance.js";
18
- import { loadConfig } from "./utils.js";
19
- import { collectionNames } from "./utils.js";
20
- import { ensureDir, findConfig } from "./utils.js";
16
+ import { getStatus, queryCollection, searchFts, searchHybrid, searchHybridRanked, upsertEntry, } from "./lance.js";
17
+ import { resolveSessionsDir, searchSessions } from "./session-search.js";
18
+ import { collectionNames, ensureDir, findConfig, getConfigPath, loadConfig } from "./utils.js";
19
+ import { classifySearchMode, normalizeGraphResult, searchVaultNative } from "./vault-tools.js";
21
20
  import { VaultWriter } from "./vault-writer.js";
22
21
  const execFileAsync = promisify(execFile);
23
22
  function ok(text) {
@@ -39,27 +38,127 @@ async function handleVmSearch(args, identity) {
39
38
  const cfg = loadConfig(cwd);
40
39
  const collection = String(args.collection ?? "main");
41
40
  const query = String(args.query ?? "");
41
+ const mode = String(args.mode ?? "hybrid");
42
42
  const limit = Number(args.limit ?? 5);
43
- const readError = checkReadCollection(identity, collection);
44
- try {
45
- const results = await searchHybrid(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity);
46
- return ok(JSON.stringify(results, null, 2));
47
- }
48
- catch (e) {
49
- return err(e instanceof Error ? e.message : String(e));
43
+ const entity = String(args.entity ?? query);
44
+ const depth = Number(args.depth ?? 1);
45
+ const sources = Array.isArray(args.sources)
46
+ ? args.sources
47
+ : ["vault"];
48
+ const VALID_MODES = {
49
+ auto: true,
50
+ hybrid: true,
51
+ semantic: true,
52
+ fts: true,
53
+ graph: true,
54
+ full: true,
55
+ vault: true,
56
+ };
57
+ if (!VALID_MODES[mode]) {
58
+ return err(`Unknown mode: ${mode}. Use hybrid, semantic, fts, graph, vault, or full.`);
50
59
  }
51
- }
52
- async function handleVmFtsSearch(args, identity) {
53
- const cwd = process.cwd();
54
- const cfg = loadConfig(cwd);
55
- const collection = String(args.collection ?? "main");
56
- const query = String(args.query ?? "");
57
- const limit = Number(args.limit ?? 5);
60
+ const typedMode = mode;
61
+ const resolvedMode = typedMode === "auto" ? classifySearchMode(query).mode : typedMode;
58
62
  const readError = checkReadCollection(identity, collection);
59
63
  if (readError)
60
64
  return err(readError);
61
65
  try {
62
- const results = await searchFts(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity);
66
+ let results;
67
+ let relations;
68
+ let message;
69
+ if (resolvedMode === "hybrid") {
70
+ results = await searchHybridRanked(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity);
71
+ }
72
+ else if (resolvedMode === "semantic") {
73
+ results = await searchHybrid(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity);
74
+ }
75
+ else if (resolvedMode === "fts") {
76
+ results = await searchFts(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity);
77
+ }
78
+ else if (resolvedMode === "graph") {
79
+ const norm = normalizeGraphResult(await queryGraph(cfg.vaultMind.dataDir, cfg.vaultMind, entity, depth, identity));
80
+ results = norm.hits;
81
+ relations = norm.relations;
82
+ message = norm.message;
83
+ }
84
+ else if (resolvedMode === "vault") {
85
+ results = await searchVaultNative(cfg.vaultMind.vaults?.default?.path ?? "", query, limit, Array.isArray(args.tags) ? args.tags : undefined);
86
+ }
87
+ else {
88
+ // "full" — run all backends, merge + dedupe, tag by source.
89
+ const [hybridResults, semanticResults, ftsResults, graphResult, vaultResults] = await Promise.all([
90
+ searchHybridRanked(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity).catch((err) => {
91
+ console.error("[pi-vault-mind] Full-mode hybrid search failed:", err);
92
+ return [];
93
+ }),
94
+ searchHybrid(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity).catch((err) => {
95
+ console.error("[pi-vault-mind] Full-mode semantic search failed:", err);
96
+ return [];
97
+ }),
98
+ searchFts(cfg.vaultMind.dataDir, collection, query, limit, cfg.vaultMind, identity).catch((err) => {
99
+ console.error("[pi-vault-mind] Full-mode FTS search failed:", err);
100
+ return [];
101
+ }),
102
+ queryGraph(cfg.vaultMind.dataDir, cfg.vaultMind, entity, depth, identity).catch((err) => {
103
+ console.error("[pi-vault-mind] Full-mode graph search failed:", err);
104
+ return { entities: [], relations: [] };
105
+ }),
106
+ searchVaultNative(cfg.vaultMind.vaults?.default?.path ?? "", query, limit, Array.isArray(args.tags) ? args.tags : undefined).catch((err) => {
107
+ console.error("[pi-vault-mind] Full-mode vault search failed:", err);
108
+ return [];
109
+ }),
110
+ ]);
111
+ const graphNorm = normalizeGraphResult(graphResult);
112
+ relations = graphNorm.relations;
113
+ message = graphNorm.message;
114
+ const tagged = [
115
+ ...hybridResults.map((r) => ({
116
+ ...r,
117
+ _source: "hybrid",
118
+ })),
119
+ ...semanticResults.map((r) => ({
120
+ ...r,
121
+ _source: "semantic",
122
+ })),
123
+ ...ftsResults.map((r) => ({
124
+ ...r,
125
+ _source: "fts",
126
+ })),
127
+ ...graphNorm.hits.map((r) => ({
128
+ ...r,
129
+ _source: "graph",
130
+ })),
131
+ ...vaultResults.map((r) => ({
132
+ ...r,
133
+ _source: "vault",
134
+ })),
135
+ ];
136
+ const seen = new Set();
137
+ const merged = [];
138
+ for (const row of tagged) {
139
+ const key = String(row.id ?? row.fact ?? JSON.stringify(row));
140
+ if (!seen.has(key)) {
141
+ seen.add(key);
142
+ merged.push(row);
143
+ }
144
+ }
145
+ results = merged.slice(0, limit);
146
+ }
147
+ if (sources.includes("sessions")) {
148
+ results = [...results, ...searchSessions(resolveSessionsDir(), query, limit)];
149
+ }
150
+ if (relations !== undefined) {
151
+ const payload = {
152
+ hits: results,
153
+ relations,
154
+ collection,
155
+ query,
156
+ mode: typedMode,
157
+ };
158
+ if (message !== undefined)
159
+ payload.message = message;
160
+ return ok(JSON.stringify(payload, null, 2));
161
+ }
63
162
  return ok(JSON.stringify(results, null, 2));
64
163
  }
65
164
  catch (e) {
@@ -77,7 +176,7 @@ async function handleVmQuery(args, identity) {
77
176
  if (!def)
78
177
  return err(`Unknown collection "${collection}". Available: ${collectionNames(cfg).join(", ")}`);
79
178
  if (!fs.existsSync(def.path))
80
- return err(`Collection "${collection}" not found at ${def.path}. Run /vm init.`);
179
+ return err(`Collection "${collection}" not found at ${def.path}. Run /vm setup.`);
81
180
  const query = args.query ? String(args.query) : null;
82
181
  const filters = (args.filters ?? {});
83
182
  const limit = Number(args.limit ?? 50);
@@ -85,7 +184,7 @@ async function handleVmQuery(args, identity) {
85
184
  const entries = await queryCollection(def.path, def.schema, query, filters, limit, offset, identity);
86
185
  return ok(JSON.stringify(entries, null, 2));
87
186
  }
88
- async function handleVmAppend(args, identity, isAutopilot) {
187
+ async function handleVmAppend(args, identity, _isAutopilot) {
89
188
  const cwd = process.cwd();
90
189
  const cfg = loadConfig(cwd);
91
190
  const collection = String(args.collection ?? "");
@@ -117,21 +216,6 @@ async function handleVmAppend(args, identity, isAutopilot) {
117
216
  return err(e instanceof Error ? e.message : String(e));
118
217
  }
119
218
  }
120
- async function handleVmGraphQuery(args, identity) {
121
- const cwd = process.cwd();
122
- const cfg = loadConfig(cwd);
123
- const collection = String(args.collection ?? "main");
124
- const readError = checkReadCollection(identity, collection);
125
- if (readError)
126
- return err(readError);
127
- try {
128
- const results = await queryGraph(cfg.vaultMind.dataDir, cfg.vaultMind, String(args.entity ?? ""), Number(args.depth ?? 1));
129
- return ok(JSON.stringify(results, null, 2));
130
- }
131
- catch (e) {
132
- return err(e instanceof Error ? e.message : String(e));
133
- }
134
- }
135
219
  async function handleVmSync(args, identity, isAutopilot) {
136
220
  // Identity guard: check canPublish
137
221
  if (identity && identity.canPublish !== true) {
@@ -202,7 +286,7 @@ async function handleVmPromote(args, identity, isAutopilot) {
202
286
  if (!targetDef)
203
287
  return err(`Unknown target collection "${targetCollection}".`);
204
288
  if (!pendingDef)
205
- return err("Pending collection not configured. Run /vm init.");
289
+ return err("Pending collection not configured. Run /vm setup.");
206
290
  if (!fs.existsSync(sourceDef.path))
207
291
  return err(`Source collection file missing at ${sourceDef.path}.`);
208
292
  const lines = fs.readFileSync(sourceDef.path, "utf-8").split("\n").filter(Boolean);
@@ -343,7 +427,7 @@ async function handleVmStats(_args, _identity) {
343
427
  const cfg = loadConfig(cwd);
344
428
  const lines = [
345
429
  "pi-vault-mind Stats",
346
- `Config path: project=${findConfig(cwd).project || "(none)"}, global=${findConfig(cwd).global || "(none)"}`,
430
+ `Config path: ${findConfig(cwd).project || "(none)"}`,
347
431
  "",
348
432
  `LanceDB DataDir: ${cfg.vaultMind.dataDir}`,
349
433
  `Injectors: ${cfg.injectors.length}`,
@@ -390,7 +474,7 @@ async function handleVmDescribe(args, _identity) {
390
474
  if (!def)
391
475
  return err(`Unknown collection "${collection}". Available: ${collectionNames(cfg).join(", ")}`);
392
476
  if (!fs.existsSync(def.path))
393
- return err(`Collection "${collection}" not found at ${def.path}. Run /vm init.`);
477
+ return err(`Collection "${collection}" not found at ${def.path}. Run /vm setup.`);
394
478
  const lines = fs.readFileSync(def.path, "utf-8").split("\n").filter(Boolean);
395
479
  const total = lines.length;
396
480
  let first = null;
@@ -428,7 +512,7 @@ async function handleVmDescribe(args, _identity) {
428
512
  async function handleVmConfigure(args, _identity) {
429
513
  const cwd = process.cwd();
430
514
  const action = String(args.action ?? "read");
431
- const cfgPath = findConfig(cwd).project || path.join(cwd, "pi-vault-mind.config.json");
515
+ const cfgPath = getConfigPath(cwd);
432
516
  if (action === "read" || !args.config) {
433
517
  const cfg = loadConfig(cwd);
434
518
  return ok(JSON.stringify(cfg, null, 2));
@@ -445,6 +529,21 @@ async function handleVmConfigure(args, _identity) {
445
529
  const merged = { ...existing, ...args.config };
446
530
  ensureDir(cfgPath);
447
531
  fs.writeFileSync(cfgPath, `${JSON.stringify(merged, null, 2)}\n`, "utf-8");
532
+ // If the update touched identities, reload the bridge registry.
533
+ // Dynamic import avoids a circular dependency (engine.ts may import
534
+ // from vm-handlers.ts indirectly through the tool registration path).
535
+ if (args.config && typeof args.config === "object") {
536
+ const configKeys = Object.keys(args.config);
537
+ if (configKeys.some((k) => k === "identities" || k.startsWith("identities."))) {
538
+ const { refreshAgentIdentities } = await import("./engine.js");
539
+ const configObj = args.config;
540
+ const identitiesVal = configObj.identities;
541
+ const roles = identitiesVal && typeof identitiesVal === "object" && "roles" in identitiesVal
542
+ ? Object.keys(identitiesVal.roles)
543
+ : undefined;
544
+ refreshAgentIdentities(roles);
545
+ }
546
+ }
448
547
  return ok(JSON.stringify(merged, null, 2));
449
548
  }
450
549
  // ── Registration ──────────────────────────────────────────────────────────────
@@ -454,10 +553,8 @@ async function handleVmConfigure(args, _identity) {
454
553
  */
455
554
  export function registerAllExtensionTools(_bus) {
456
555
  registerExtensionToolHandler("vm_search", handleVmSearch);
457
- registerExtensionToolHandler("vm_fts_search", handleVmFtsSearch);
458
556
  registerExtensionToolHandler("vm_query", handleVmQuery);
459
557
  registerExtensionToolHandler("vm_append", handleVmAppend);
460
- registerExtensionToolHandler("vm_graph_query", handleVmGraphQuery);
461
558
  registerExtensionToolHandler("vm_sync", handleVmSync);
462
559
  registerExtensionToolHandler("vm_promote", handleVmPromote);
463
560
  registerExtensionToolHandler("vm_ingest", handleVmIngest);
@@ -19,12 +19,12 @@ import { buildCheckpointInstructions } from "./context-capture.js";
19
19
  */
20
20
  import * as fs from "node:fs";
21
21
  import * as path from "node:path";
22
- import { createJob, getJob, markBatchRunning, markJobDone, markJobFailed, markJobRunning, markerStillPresent, sweepCompletedJobs, } from "./agent-queue.js";
22
+ import { createJob, getJob, markBatchRunning, markerStillPresent, markJobDone, markJobFailed, markJobRunning, sweepCompletedJobs, } from "./agent-queue.js";
23
23
  import { decrementDispatch, incrementDispatch, setWatcherStatus } from "./status.js";
24
- import { expandHome } from "./utils.js";
24
+ import { expandHome, loadConfig, resolveVaultFile } from "./utils.js";
25
25
  // ── Constants ────────────────────────────────────────────────────────────────────
26
26
  const MARKER_REGEX = /@agent-(\w+)(?::(\S+))?\s*(.*)/;
27
- const WRITEBACK_MARKER_REGEX = /<!--\s*pi-dispatch:(\S+)\s*-->/;
27
+ const _WRITEBACK_MARKER_REGEX = /<!--\s*pi-dispatch:(\S+)\s*-->/;
28
28
  const DEBOUNCE_MS = 1000;
29
29
  const MAX_CONCURRENT = 3;
30
30
  /** How long to wait after the last new marker before flushing a batch. */
@@ -249,7 +249,7 @@ export function startWatcher(pi, vaults, state) {
249
249
  continue;
250
250
  }
251
251
  console.log(`[pi-vault-mind] Watching vault "${name}" at ${vaultPath}`);
252
- const watcher = fs.watch(vaultPath, { recursive: true }, (eventType, filename) => {
252
+ const watcher = fs.watch(vaultPath, { recursive: true }, (_eventType, filename) => {
253
253
  if (!filename || !state.running)
254
254
  return;
255
255
  const filePath = path.join(vaultPath, filename);
@@ -362,7 +362,7 @@ function enqueueBatch(pi, vaultPath, group, state) {
362
362
  state.batchTimers.set(key, timer);
363
363
  }
364
364
  /** Dispatch pending jobs in the same vault+role buffer to the internal agent bus. */
365
- function flushBatch(pi, key, state) {
365
+ function flushBatch(_pi, key, state) {
366
366
  const timer = state.batchTimers.get(key);
367
367
  if (timer) {
368
368
  clearTimeout(timer);
@@ -428,7 +428,7 @@ function flushBatch(pi, key, state) {
428
428
  setTimeout(() => {
429
429
  for (const id of ids) {
430
430
  const job = getJob(vaultPath, id);
431
- if (!job || job.status !== "running")
431
+ if (job?.status !== "running")
432
432
  continue;
433
433
  if (markerStillPresent(job.filePath, id)) {
434
434
  markJobFailed(vaultPath, id, "Batch timeout: marker not replaced in time");
@@ -437,7 +437,7 @@ function flushBatch(pi, key, state) {
437
437
  }, 10 * 60 * 1000);
438
438
  }
439
439
  /** True if the file still contains the dispatch marker for a given job id. */
440
- const markerStillPresentFor = (filePath, dispatchId) => {
440
+ const _markerStillPresentFor = (filePath, dispatchId) => {
441
441
  try {
442
442
  const content = fs.readFileSync(filePath, "utf-8");
443
443
  return content.includes(`<!-- pi-dispatch:${dispatchId} -->`);
@@ -462,7 +462,7 @@ function dispatchGroup(pi, group, state) {
462
462
  const timeoutMs = 10 * 60 * 1000; // 10 minutes; subagent long tasks can take a while
463
463
  setTimeout(() => {
464
464
  const job = getJob(vaultPath, group.dispatchId);
465
- if (!job || job.status !== "running")
465
+ if (job?.status !== "running")
466
466
  return;
467
467
  // If the marker is gone, the subagent completed without us noticing
468
468
  if (!fs.existsSync(job.filePath) ||
@@ -538,7 +538,7 @@ export function createManualDispatch(pi, state, opts) {
538
538
  ? path.isAbsolute(opts.filePath)
539
539
  ? opts.filePath
540
540
  : path.join(vaultPath, opts.filePath)
541
- : path.join(vaultPath, ".vault-mind", "manual-dispatch.md");
541
+ : path.join(vaultPath, resolveVaultFile(loadConfig(vaultPath).vaultMind, "manualDispatch"));
542
542
  const agentName = resolveAgentName(role);
543
543
  const dispatchId = generateDispatchId(role);
544
544
  const combinedInstruction = [
@@ -0,0 +1,54 @@
1
+ import { strict as assert } from "node:assert";
2
+ import * as fs from "node:fs";
3
+ import * as os from "node:os";
4
+ import * as path from "node:path";
5
+ import { after, before, describe, it } from "node:test";
6
+ import { mapToolCallToActivity } from "../src/activity.js";
7
+ describe("mapToolCallToActivity", () => {
8
+ let vaultPath;
9
+ before(() => {
10
+ vaultPath = fs.mkdtempSync(path.join(os.tmpdir(), "pvm-activity-tool-"));
11
+ });
12
+ after(() => {
13
+ fs.rmSync(vaultPath, { recursive: true, force: true });
14
+ });
15
+ it("creates a tool-kind activity event with dispatchId as jobId", () => {
16
+ const event = mapToolCallToActivity("vault_search", "agent-1", "dispatch-123", { query: "test" }, vaultPath);
17
+ assert.equal(event.kind, "tool");
18
+ assert.equal(event.label, "vault_search");
19
+ assert.equal(event.jobId, "dispatch-123");
20
+ assert.ok(event.detail !== undefined);
21
+ assert.ok(event.detail.includes("query"));
22
+ });
23
+ it("falls back to agentId as jobId when dispatchId is undefined", () => {
24
+ const event = mapToolCallToActivity("read", "agent-1", undefined, { path: "foo.md" }, vaultPath);
25
+ assert.equal(event.jobId, "agent-1");
26
+ });
27
+ it("omits detail when args is empty", () => {
28
+ const event = mapToolCallToActivity("bash", "agent-1", "d1", {}, vaultPath);
29
+ assert.equal(event.detail, undefined);
30
+ });
31
+ it("truncates long args detail with ellipsis", () => {
32
+ const longArgs = {};
33
+ for (let i = 0; i < 30; i++) {
34
+ longArgs[`key${i}`] = `value-${i}-padding-padding-padding`;
35
+ }
36
+ const event = mapToolCallToActivity("write", "agent-1", "d1", longArgs, vaultPath);
37
+ assert.ok(event.detail !== undefined);
38
+ assert.ok(event.detail.endsWith("…"), "detail should end with ellipsis");
39
+ assert.ok(event.detail.length <= 202, "detail should be truncated to ~200 chars + ellipsis");
40
+ });
41
+ it("produces a valid ISO timestamp", () => {
42
+ const event = mapToolCallToActivity("grep", "agent-1", "d1", { pattern: "test" }, vaultPath);
43
+ assert.ok(!Number.isNaN(Date.parse(event.ts)), "ts should be a valid ISO timestamp");
44
+ });
45
+ it("produces monotonic IDs", () => {
46
+ const e1 = mapToolCallToActivity("read", "agent-1", "d1", {}, vaultPath);
47
+ const e2 = mapToolCallToActivity("read", "agent-1", "d1", {}, vaultPath);
48
+ assert.ok(e2.id > e1.id, "second ID should be greater than first");
49
+ });
50
+ it("does not set a tone", () => {
51
+ const event = mapToolCallToActivity("vault_search", "agent-1", "d1", { q: "x" }, vaultPath);
52
+ assert.equal(event.tone, undefined);
53
+ });
54
+ });