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
@@ -0,0 +1,620 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { randomUUID } from "node:crypto";
3
+ import * as fs from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import * as path from "node:path";
6
+ import { afterEach, before, beforeEach, describe, it } from "node:test";
7
+ import { LanceSchema } from "@lancedb/lancedb/embedding";
8
+ import * as arrow from "apache-arrow";
9
+ import { MessageBus } from "../src/agent-bus/MessageBus.js";
10
+ import { createBridge, registerAgentIdentity, unregisterAgentIdentity, } from "../src/bridge.js";
11
+ import { connect, resetConnection, upsertPrecomputed } from "../src/lance.js";
12
+ import { MODAL_TOKEN_ENV } from "../src/modal-config.js";
13
+ import { registerAllExtensionTools } from "../src/vm-handlers.js";
14
+ const fakePi = {
15
+ sendUserMessage: () => { },
16
+ };
17
+ let bus;
18
+ before(() => {
19
+ bus = new MessageBus();
20
+ registerAllExtensionTools(bus);
21
+ createBridge(fakePi, bus);
22
+ });
23
+ async function callTool(agentId, toolName, args) {
24
+ const requestId = randomUUID();
25
+ const responseTopic = `bridge_resp_${requestId}`;
26
+ let response;
27
+ const responseHandler = (msg) => {
28
+ response = msg.payload;
29
+ };
30
+ bus.subscribe(responseTopic, responseHandler);
31
+ await bus.publish("pi_tool_bridge_requests", "test-client", {
32
+ requestId,
33
+ agentId,
34
+ toolName,
35
+ args,
36
+ responseTopic,
37
+ });
38
+ bus.unsubscribe(responseTopic, responseHandler);
39
+ if (response === undefined)
40
+ throw new Error(`No bridge response for ${toolName}`);
41
+ return response;
42
+ }
43
+ function getResultText(resp) {
44
+ if (resp.error)
45
+ return `Error: ${resp.error}`;
46
+ const r = resp.result;
47
+ return r?.content?.[0]?.text ?? "";
48
+ }
49
+ const writeProjectConfig = (dir, dataDir) => {
50
+ const configDir = path.join(dir, ".vault-mind");
51
+ fs.mkdirSync(configDir, { recursive: true });
52
+ fs.writeFileSync(path.join(configDir, "vault-mind.config.json"), JSON.stringify({
53
+ version: 2,
54
+ collections: {
55
+ main: {
56
+ path: "collections/main.jsonl",
57
+ schema: ["id", "fact"],
58
+ dedupField: "fact",
59
+ },
60
+ },
61
+ injectors: [],
62
+ vaultMind: {
63
+ dataDir,
64
+ embedding: {
65
+ remoteUrl: "https://pvm.modal.run",
66
+ model: "testmodel",
67
+ },
68
+ ftsEnabled: true,
69
+ graph: { enabled: false },
70
+ },
71
+ }), "utf-8");
72
+ fs.mkdirSync(path.join(dir, "collections"), { recursive: true });
73
+ };
74
+ async function seedCollection(dataDir, cfg, identity) {
75
+ await upsertPrecomputed(dataDir, "main", "testmodel", 3, [
76
+ {
77
+ id: "search-1",
78
+ text: "authentication tokens",
79
+ vector: [1, 0, 0],
80
+ metadata: { source: "notes/auth.md", domain: "test", tag: "test" },
81
+ },
82
+ ], cfg, identity);
83
+ }
84
+ async function seedGraph(dataDir) {
85
+ const conn = await connect(dataDir);
86
+ const existing = new Set(await conn.tableNames());
87
+ if (!existing.has("entities")) {
88
+ await conn.createEmptyTable("entities", LanceSchema({
89
+ id: new arrow.Utf8(),
90
+ name: new arrow.Utf8(),
91
+ type: new arrow.Utf8(),
92
+ aliases: new arrow.Utf8(),
93
+ summary: new arrow.Utf8(),
94
+ collection_ids: new arrow.Utf8(),
95
+ created_at: new arrow.Utf8(),
96
+ updated_at: new arrow.Utf8(),
97
+ }));
98
+ }
99
+ if (!existing.has("relations")) {
100
+ await conn.createEmptyTable("relations", LanceSchema({
101
+ id: new arrow.Utf8(),
102
+ from_entity_id: new arrow.Utf8(),
103
+ to_entity_id: new arrow.Utf8(),
104
+ relation_type: new arrow.Utf8(),
105
+ fact: new arrow.Utf8(),
106
+ fact_strength: new arrow.Float32(),
107
+ source_entry_ids: new arrow.Utf8(),
108
+ valid_at: new arrow.Utf8(),
109
+ expired_at: new arrow.Utf8(),
110
+ created_at: new arrow.Utf8(),
111
+ }));
112
+ }
113
+ const entityTable = await conn.openTable("entities");
114
+ await entityTable.add([
115
+ {
116
+ id: "ent-1",
117
+ name: "Authentication",
118
+ type: "system",
119
+ aliases: "",
120
+ summary: "",
121
+ collection_ids: JSON.stringify(["search-1"]),
122
+ created_at: new Date().toISOString(),
123
+ updated_at: "",
124
+ },
125
+ ]);
126
+ }
127
+ describe("vm-handlers", () => {
128
+ let testDir;
129
+ let lanceDir;
130
+ let origCwd;
131
+ let origHome;
132
+ let origToken;
133
+ const agentId = `vm-search-${randomUUID()}`;
134
+ beforeEach(() => {
135
+ origCwd = process.cwd();
136
+ origHome = process.env.HOME;
137
+ origToken = process.env[MODAL_TOKEN_ENV];
138
+ process.env[MODAL_TOKEN_ENV] = "tok";
139
+ testDir = path.join(tmpdir(), `pvm-vm-handlers-${randomUUID()}`);
140
+ lanceDir = path.join(tmpdir(), `pvm-vm-handlers-lance-${randomUUID()}`);
141
+ fs.mkdirSync(testDir, { recursive: true });
142
+ fs.mkdirSync(lanceDir, { recursive: true });
143
+ writeProjectConfig(testDir, lanceDir);
144
+ process.env.HOME = testDir;
145
+ process.env.USERPROFILE = testDir;
146
+ process.chdir(testDir);
147
+ registerAgentIdentity({
148
+ id: agentId,
149
+ role: "test",
150
+ allowedTools: ["vm_search", "vm_query"],
151
+ writeCollections: [],
152
+ canPublish: false,
153
+ });
154
+ resetConnection();
155
+ });
156
+ afterEach(() => {
157
+ process.chdir(origCwd);
158
+ if (origHome !== undefined) {
159
+ process.env.HOME = origHome;
160
+ process.env.USERPROFILE = origHome;
161
+ }
162
+ else {
163
+ delete process.env.HOME;
164
+ delete process.env.USERPROFILE;
165
+ }
166
+ if (origToken === undefined)
167
+ delete process.env[MODAL_TOKEN_ENV];
168
+ else
169
+ process.env[MODAL_TOKEN_ENV] = origToken;
170
+ unregisterAgentIdentity(agentId);
171
+ resetConnection();
172
+ if (fs.existsSync(testDir))
173
+ fs.rmSync(testDir, { recursive: true, force: true });
174
+ if (fs.existsSync(lanceDir))
175
+ fs.rmSync(lanceDir, { recursive: true, force: true });
176
+ });
177
+ describe("vm_search mode dispatch", () => {
178
+ const identity = {
179
+ id: agentId,
180
+ role: "test",
181
+ allowedTools: ["vm_search", "vm_query"],
182
+ writeCollections: [],
183
+ canPublish: false,
184
+ };
185
+ const cfg = {
186
+ dataDir: lanceDir,
187
+ embedding: {
188
+ remoteUrl: "https://pvm.modal.run",
189
+ model: "testmodel",
190
+ },
191
+ ftsEnabled: true,
192
+ graph: { enabled: false },
193
+ };
194
+ beforeEach(async () => {
195
+ await seedCollection(lanceDir, cfg, identity);
196
+ await seedGraph(lanceDir);
197
+ });
198
+ it("mode='hybrid' calls searchHybridRanked", async () => {
199
+ const resp = await callTool(agentId, "vm_search", {
200
+ collection: "main",
201
+ query: "authentication",
202
+ mode: "hybrid",
203
+ limit: 5,
204
+ });
205
+ const text = getResultText(resp);
206
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
207
+ const results = JSON.parse(text);
208
+ assert.ok(results.length > 0);
209
+ assert.ok(results.some((r) => r._source === "fts" || r._source === "vector"), "hybrid result should be tagged with _source");
210
+ });
211
+ it("mode='semantic' calls searchHybrid", async () => {
212
+ const resp = await callTool(agentId, "vm_search", {
213
+ collection: "main",
214
+ query: "authentication",
215
+ mode: "semantic",
216
+ limit: 5,
217
+ });
218
+ const text = getResultText(resp);
219
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
220
+ const results = JSON.parse(text);
221
+ assert.ok(results.length > 0);
222
+ assert.ok(results.some((r) => String(r.fact).includes("authentication")), "semantic result should contain the seeded fact");
223
+ });
224
+ it("mode='fts' calls searchFts", async () => {
225
+ const resp = await callTool(agentId, "vm_search", {
226
+ collection: "main",
227
+ query: "authentication",
228
+ mode: "fts",
229
+ limit: 5,
230
+ });
231
+ const text = getResultText(resp);
232
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
233
+ const results = JSON.parse(text);
234
+ assert.ok(results.length > 0);
235
+ assert.ok(results.some((r) => String(r.fact).includes("authentication")), "fts result should contain the seeded fact");
236
+ });
237
+ it("mode='graph' calls queryGraph", async () => {
238
+ const resp = await callTool(agentId, "vm_search", {
239
+ collection: "main",
240
+ query: "Authentication",
241
+ mode: "graph",
242
+ entity: "Authentication",
243
+ depth: 1,
244
+ });
245
+ const text = getResultText(resp);
246
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
247
+ const graph = JSON.parse(text);
248
+ assert.ok(Array.isArray(graph.hits), "graph result should expose a flat hits array");
249
+ assert.ok(Array.isArray(graph.relations), "graph result should expose a relations sibling array");
250
+ assert.ok(graph.hits.every((h) => h._source === "graph"), "every graph hit should be tagged _source:'graph'");
251
+ });
252
+ it("mode='graph' returns entities when an identity is resolved", async () => {
253
+ const resp = await callTool(agentId, "vm_search", {
254
+ collection: "main",
255
+ query: "Authentication",
256
+ mode: "graph",
257
+ entity: "Authentication",
258
+ depth: 1,
259
+ });
260
+ const text = getResultText(resp);
261
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
262
+ const graph = JSON.parse(text);
263
+ assert.ok(graph.hits.length > 0, "graph entities should not be filtered out for an authenticated caller");
264
+ assert.ok(Array.isArray(graph.relations), "graph result should include a relations array");
265
+ });
266
+ it("mode='full' runs all four searches in parallel", async () => {
267
+ const resp = await callTool(agentId, "vm_search", {
268
+ collection: "main",
269
+ query: "authentication",
270
+ mode: "full",
271
+ limit: 10,
272
+ entity: "Authentication",
273
+ depth: 1,
274
+ });
275
+ const text = getResultText(resp);
276
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
277
+ const full = JSON.parse(text);
278
+ const sources = new Set(full.hits.map((r) => r._source));
279
+ assert.ok(sources.has("hybrid") || sources.has("fts") || sources.has("semantic"));
280
+ assert.ok(sources.has("graph"));
281
+ });
282
+ it("invalid mode returns error", async () => {
283
+ const resp = await callTool(agentId, "vm_search", {
284
+ collection: "main",
285
+ query: "authentication",
286
+ mode: "unknown",
287
+ });
288
+ const text = getResultText(resp);
289
+ assert.ok(text.startsWith("Error:"), `Expected error for invalid mode, got: "${text}"`);
290
+ });
291
+ });
292
+ describe("vm_query", () => {
293
+ it("returns entries from the JSONL collection", async () => {
294
+ const collectionPath = path.join(testDir, "collections", "main.jsonl");
295
+ fs.writeFileSync(collectionPath, [
296
+ JSON.stringify({ id: "q1", fact: "first entry", visibility: "public" }),
297
+ JSON.stringify({ id: "q2", fact: "second entry", visibility: "public" }),
298
+ "",
299
+ ].join("\n"), "utf-8");
300
+ const resp = await callTool(agentId, "vm_query", {
301
+ collection: "main",
302
+ query: "first",
303
+ });
304
+ const text = getResultText(resp);
305
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
306
+ const results = JSON.parse(text);
307
+ assert.equal(results.length, 1);
308
+ assert.equal(results[0]?.id, "q1");
309
+ });
310
+ it("returns error for unknown collection", async () => {
311
+ const resp = await callTool(agentId, "vm_query", { collection: "missing" });
312
+ const text = getResultText(resp);
313
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
314
+ });
315
+ });
316
+ describe("vm_append", () => {
317
+ it("appends a valid entry to the collection", async () => {
318
+ registerAgentIdentity({
319
+ id: agentId,
320
+ role: "test",
321
+ allowedTools: ["vm_append"],
322
+ writeCollections: ["main"],
323
+ canPublish: false,
324
+ });
325
+ const resp = await callTool(agentId, "vm_append", {
326
+ collection: "main",
327
+ entry: { id: "append-1", fact: "appended fact" },
328
+ });
329
+ const text = getResultText(resp);
330
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
331
+ assert.ok(text.includes('Appended to "main"'));
332
+ const collectionPath = path.join(testDir, "collections", "main.jsonl");
333
+ const lines = fs.readFileSync(collectionPath, "utf-8").split("\n").filter(Boolean);
334
+ const last = JSON.parse(lines[lines.length - 1]);
335
+ assert.equal(last.id, "append-1");
336
+ assert.equal(last.fact, "appended fact");
337
+ assert.equal(last.identity, agentId);
338
+ });
339
+ it("returns error for unknown collection", async () => {
340
+ registerAgentIdentity({
341
+ id: agentId,
342
+ role: "test",
343
+ allowedTools: ["vm_append"],
344
+ writeCollections: ["main"],
345
+ canPublish: false,
346
+ });
347
+ const resp = await callTool(agentId, "vm_append", {
348
+ collection: "missing",
349
+ entry: { id: "x", fact: "y" },
350
+ });
351
+ const text = getResultText(resp);
352
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
353
+ });
354
+ it("denies append when identity lacks writeCollections", async () => {
355
+ registerAgentIdentity({
356
+ id: agentId,
357
+ role: "test",
358
+ allowedTools: ["vm_append"],
359
+ writeCollections: [],
360
+ canPublish: false,
361
+ });
362
+ const resp = await callTool(agentId, "vm_append", {
363
+ collection: "main",
364
+ entry: { id: "x", fact: "y" },
365
+ });
366
+ const text = getResultText(resp);
367
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
368
+ assert.ok(text.includes("not allowed to write"));
369
+ });
370
+ });
371
+ describe("vm_ingest", () => {
372
+ it("ingests plain text and reports line count", async () => {
373
+ registerAgentIdentity({
374
+ id: agentId,
375
+ role: "test",
376
+ allowedTools: ["vm_ingest"],
377
+ writeCollections: [],
378
+ canPublish: false,
379
+ });
380
+ const resp = await callTool(agentId, "vm_ingest", {
381
+ source: "alpha\nbeta\ngamma",
382
+ sourceType: "text",
383
+ });
384
+ const text = getResultText(resp);
385
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
386
+ assert.ok(text.includes("Lines: 3"));
387
+ assert.ok(text.includes("alpha"));
388
+ });
389
+ it("returns error for missing file source", async () => {
390
+ registerAgentIdentity({
391
+ id: agentId,
392
+ role: "test",
393
+ allowedTools: ["vm_ingest"],
394
+ writeCollections: [],
395
+ canPublish: false,
396
+ });
397
+ const resp = await callTool(agentId, "vm_ingest", {
398
+ source: path.join(testDir, "missing-file.md"),
399
+ sourceType: "file",
400
+ });
401
+ const text = getResultText(resp);
402
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
403
+ assert.ok(text.includes("Cannot read file"));
404
+ });
405
+ });
406
+ describe("vm_export", () => {
407
+ it("exports a collection as JSON", async () => {
408
+ registerAgentIdentity({
409
+ id: agentId,
410
+ role: "test",
411
+ allowedTools: ["vm_export"],
412
+ writeCollections: [],
413
+ canPublish: false,
414
+ });
415
+ const collectionPath = path.join(testDir, "collections", "main.jsonl");
416
+ fs.writeFileSync(collectionPath, [
417
+ JSON.stringify({ id: "e1", fact: "first" }),
418
+ JSON.stringify({ id: "e2", fact: "second" }),
419
+ "",
420
+ ].join("\n"), "utf-8");
421
+ const resp = await callTool(agentId, "vm_export", {
422
+ collection: "main",
423
+ format: "json",
424
+ });
425
+ const text = getResultText(resp);
426
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
427
+ const entries = JSON.parse(text);
428
+ assert.equal(entries.length, 2);
429
+ assert.equal(entries[0]?.id, "e1");
430
+ assert.equal(entries[1]?.id, "e2");
431
+ });
432
+ it("returns error for unknown collection", async () => {
433
+ registerAgentIdentity({
434
+ id: agentId,
435
+ role: "test",
436
+ allowedTools: ["vm_export"],
437
+ writeCollections: [],
438
+ canPublish: false,
439
+ });
440
+ const resp = await callTool(agentId, "vm_export", { collection: "missing" });
441
+ const text = getResultText(resp);
442
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
443
+ });
444
+ });
445
+ describe("vm_stats", () => {
446
+ it("returns stats for a populated collection", async () => {
447
+ registerAgentIdentity({
448
+ id: agentId,
449
+ role: "test",
450
+ allowedTools: ["vm_stats"],
451
+ writeCollections: [],
452
+ canPublish: false,
453
+ });
454
+ const collectionPath = path.join(testDir, "collections", "main.jsonl");
455
+ fs.writeFileSync(collectionPath, [
456
+ JSON.stringify({ id: "s1", fact: "alpha" }),
457
+ JSON.stringify({ id: "s2", fact: "beta" }),
458
+ "",
459
+ ].join("\n"), "utf-8");
460
+ const resp = await callTool(agentId, "vm_stats", {});
461
+ const text = getResultText(resp);
462
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
463
+ assert.ok(text.includes('"main"'));
464
+ assert.ok(text.includes("Entries: 2"));
465
+ assert.ok(text.includes("Schema: [id, fact]"));
466
+ });
467
+ });
468
+ describe("vm_status", () => {
469
+ it("returns vault status JSON", async () => {
470
+ registerAgentIdentity({
471
+ id: agentId,
472
+ role: "test",
473
+ allowedTools: ["vm_status"],
474
+ writeCollections: [],
475
+ canPublish: false,
476
+ });
477
+ const resp = await callTool(agentId, "vm_status", {});
478
+ const text = getResultText(resp);
479
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
480
+ const status = JSON.parse(text);
481
+ assert.ok("dataDir" in status);
482
+ assert.ok("tables" in status);
483
+ });
484
+ });
485
+ describe("vm_describe", () => {
486
+ it("describes a collection schema and entries", async () => {
487
+ registerAgentIdentity({
488
+ id: agentId,
489
+ role: "test",
490
+ allowedTools: ["vm_describe"],
491
+ writeCollections: [],
492
+ canPublish: false,
493
+ });
494
+ const collectionPath = path.join(testDir, "collections", "main.jsonl");
495
+ fs.writeFileSync(collectionPath, [
496
+ JSON.stringify({ id: "d1", fact: "first described" }),
497
+ JSON.stringify({ id: "d2", fact: "second described" }),
498
+ "",
499
+ ].join("\n"), "utf-8");
500
+ const resp = await callTool(agentId, "vm_describe", { collection: "main" });
501
+ const text = getResultText(resp);
502
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
503
+ assert.ok(text.includes('Collection: "main"'));
504
+ assert.ok(text.includes("Schema: [id, fact]"));
505
+ assert.ok(text.includes("Total entries: 2"));
506
+ assert.ok(text.includes('"id": "d1"'));
507
+ assert.ok(text.includes('"id": "d2"'));
508
+ });
509
+ it("returns error for unknown collection", async () => {
510
+ registerAgentIdentity({
511
+ id: agentId,
512
+ role: "test",
513
+ allowedTools: ["vm_describe"],
514
+ writeCollections: [],
515
+ canPublish: false,
516
+ });
517
+ const resp = await callTool(agentId, "vm_describe", { collection: "missing" });
518
+ const text = getResultText(resp);
519
+ assert.ok(text.startsWith("Error:"), `Expected error, got: "${text}"`);
520
+ });
521
+ });
522
+ describe("vm_configure", () => {
523
+ it("writes a configuration change", async () => {
524
+ registerAgentIdentity({
525
+ id: agentId,
526
+ role: "test",
527
+ allowedTools: ["vm_configure"],
528
+ writeCollections: [],
529
+ canPublish: false,
530
+ });
531
+ const resp = await callTool(agentId, "vm_configure", {
532
+ action: "write",
533
+ config: { injectors: [{ name: "test-injector", regex: ".*", collection: "main" }] },
534
+ });
535
+ const text = getResultText(resp);
536
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
537
+ const cfg = JSON.parse(text);
538
+ assert.deepEqual(cfg.injectors, [{ name: "test-injector", regex: ".*", collection: "main" }]);
539
+ });
540
+ it("reads configuration when action is read", async () => {
541
+ registerAgentIdentity({
542
+ id: agentId,
543
+ role: "test",
544
+ allowedTools: ["vm_configure"],
545
+ writeCollections: [],
546
+ canPublish: false,
547
+ });
548
+ const resp = await callTool(agentId, "vm_configure", { action: "read" });
549
+ const text = getResultText(resp);
550
+ assert.ok(!text.startsWith("Error:"), `Expected success, got: "${text}"`);
551
+ const cfg = JSON.parse(text);
552
+ assert.equal(cfg.version, 2);
553
+ assert.ok("collections" in cfg);
554
+ });
555
+ });
556
+ describe("vm_sync", () => {
557
+ it("requires publish authorization", async () => {
558
+ registerAgentIdentity({
559
+ id: agentId,
560
+ role: "test",
561
+ allowedTools: ["vm_sync"],
562
+ writeCollections: [],
563
+ canPublish: false,
564
+ });
565
+ const resp = await callTool(agentId, "vm_sync", { vault: "default" });
566
+ const text = getResultText(resp);
567
+ assert.ok(text.startsWith("Error:"), `Expected authorization error, got: "${text}"`);
568
+ assert.ok(text.includes("not authorized to publish"));
569
+ });
570
+ it("gates destructive sync in autopilot mode", async () => {
571
+ registerAgentIdentity({
572
+ id: agentId,
573
+ role: "test",
574
+ allowedTools: ["vm_sync"],
575
+ writeCollections: [],
576
+ canPublish: true,
577
+ });
578
+ const resp = await callTool(agentId, "vm_sync", { vault: "default" });
579
+ const text = getResultText(resp);
580
+ assert.ok(!text.startsWith("Error:"), `Expected approval gate, got: "${text}"`);
581
+ assert.ok(text.includes("requires approval"));
582
+ });
583
+ });
584
+ describe("vm_promote", () => {
585
+ it("requires publish authorization", async () => {
586
+ registerAgentIdentity({
587
+ id: agentId,
588
+ role: "test",
589
+ allowedTools: ["vm_promote"],
590
+ writeCollections: [],
591
+ canPublish: false,
592
+ });
593
+ const resp = await callTool(agentId, "vm_promote", {
594
+ sourceCollection: "main",
595
+ targetCollection: "main",
596
+ entryIds: ["p1"],
597
+ });
598
+ const text = getResultText(resp);
599
+ assert.ok(text.startsWith("Error:"), `Expected authorization error, got: "${text}"`);
600
+ assert.ok(text.includes("not authorized to publish"));
601
+ });
602
+ it("gates destructive promote in autopilot mode", async () => {
603
+ registerAgentIdentity({
604
+ id: agentId,
605
+ role: "test",
606
+ allowedTools: ["vm_promote"],
607
+ writeCollections: [],
608
+ canPublish: true,
609
+ });
610
+ const resp = await callTool(agentId, "vm_promote", {
611
+ sourceCollection: "main",
612
+ targetCollection: "main",
613
+ entryIds: ["p1"],
614
+ });
615
+ const text = getResultText(resp);
616
+ assert.ok(!text.startsWith("Error:"), `Expected approval gate, got: "${text}"`);
617
+ assert.ok(text.includes("requires approval"));
618
+ });
619
+ });
620
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "required": [
3
+ "npm:pi-vault-mind",
4
+ "npm:pi-context",
5
+ "npm:@kylebrodeur/pi-model-discovery",
6
+ "npm:@kylebrodeur/pi-model-router"
7
+ ],
8
+ "optional": ["npm:pi-1password"]
9
+ }