@swarmvaultai/engine 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -21,13 +21,18 @@ If you only want to use SwarmVault as a tool, install `@swarmvaultai/cli` instea
21
21
  import {
22
22
  compileVault,
23
23
  createMcpServer,
24
+ createWebSearchAdapter,
24
25
  defaultVaultConfig,
26
+ defaultVaultSchema,
27
+ exploreVault,
25
28
  importInbox,
26
29
  ingestInput,
27
30
  initVault,
28
31
  installAgent,
32
+ getWebSearchAdapterForTask,
29
33
  lintVault,
30
34
  loadVaultConfig,
35
+ loadVaultSchema,
31
36
  queryVault,
32
37
  searchVault,
33
38
  startGraphServer,
@@ -41,20 +46,37 @@ The engine also exports the main runtime types for providers, graph artifacts, p
41
46
  ## Example
42
47
 
43
48
  ```ts
44
- import { compileVault, importInbox, initVault, queryVault, watchVault } from "@swarmvaultai/engine";
49
+ import { compileVault, importInbox, initVault, loadVaultSchema, queryVault, watchVault } from "@swarmvaultai/engine";
45
50
 
46
51
  const rootDir = process.cwd();
47
52
 
48
53
  await initVault(rootDir);
54
+ const schema = await loadVaultSchema(rootDir);
55
+ console.log(schema.path);
49
56
  await importInbox(rootDir);
50
57
  await compileVault(rootDir);
51
58
 
52
- const result = await queryVault(rootDir, "What changed most recently?", true);
53
- console.log(result.answer);
59
+ const saved = await queryVault(rootDir, "What changed most recently?", true);
60
+ console.log(saved.savedTo);
61
+
62
+ const exploration = await exploreVault(rootDir, "What should I investigate next?", 3);
63
+ console.log(exploration.hubPath);
54
64
 
55
65
  const watcher = await watchVault(rootDir, { lint: true });
56
66
  ```
57
67
 
68
+ ## Schema Layer
69
+
70
+ Each workspace carries a root markdown file named `swarmvault.schema.md`.
71
+
72
+ The engine treats that file as vault-specific operating guidance for compile and query work. Currently:
73
+
74
+ - `initVault()` creates the default schema file
75
+ - `loadVaultSchema()` resolves the canonical file and legacy `schema.md` fallback
76
+ - compile and query prompts include the schema content
77
+ - generated pages store `schema_hash`
78
+ - `lintVault()` marks generated pages stale when the schema changes
79
+
58
80
  ## Provider Model
59
81
 
60
82
  The engine supports:
@@ -88,30 +110,37 @@ This matters because many "OpenAI-compatible" backends only implement part of th
88
110
 
89
111
  ### Compile + Query
90
112
 
91
- - `compileVault(rootDir)` writes wiki pages, graph data, and search state
92
- - `queryVault(rootDir, question, save)` answers against the compiled vault
113
+ - `compileVault(rootDir)` writes wiki pages, graph data, and search state using the vault schema as guidance
114
+ - `queryVault(rootDir, question, save)` answers against the compiled vault using the same schema layer and can persist a first-class output page
115
+ - `exploreVault(rootDir, question, steps)` runs a save-first multi-step exploration loop and writes a hub page plus step outputs
93
116
  - `searchVault(rootDir, query, limit)` searches compiled pages directly
94
117
 
95
118
  ### Automation
96
119
 
97
120
  - `watchVault(rootDir, options)` watches the inbox and appends run records to `state/jobs.ndjson`
98
- - `lintVault(rootDir)` runs health and anti-drift checks
121
+ - `lintVault(rootDir, options)` runs structural lint, optional deep lint, and optional web-augmented evidence gathering
122
+
123
+ ### Web Search Adapters
124
+
125
+ - `createWebSearchAdapter(rootDir, id, config)` constructs a normalized web search adapter
126
+ - `getWebSearchAdapterForTask(rootDir, "deepLintProvider")` resolves the configured adapter for `lint --deep --web`
99
127
 
100
128
  ### MCP
101
129
 
102
130
  - `createMcpServer(rootDir)` creates an MCP server instance
103
131
  - `startMcpServer(rootDir)` runs the MCP server over stdio
104
132
 
105
- The MCP surface includes tools for workspace info, page search, page reads, source listing, querying, ingestion, compile, and lint, along with resources for config, graph, manifests, and page content.
133
+ The MCP surface includes tools for workspace info, page search, page reads, source listing, querying, ingestion, compile, and lint, along with resources for config, graph, manifests, schema, and page content.
106
134
 
107
135
  ## Artifacts
108
136
 
109
137
  Running the engine produces a local workspace with these main areas:
110
138
 
139
+ - `swarmvault.schema.md`: vault-specific compile and query instructions
111
140
  - `inbox/`: capture staging area for markdown bundles and imported files
112
141
  - `raw/sources/`: immutable source copies
113
142
  - `raw/assets/`: copied attachments referenced by ingested markdown bundles
114
- - `wiki/`: generated markdown pages and saved outputs
143
+ - `wiki/`: generated markdown pages, saved query outputs, and exploration hub pages
115
144
  - `state/manifests/`: source manifests
116
145
  - `state/extracts/`: extracted text
117
146
  - `state/analyses/`: model analysis output
@@ -119,6 +148,8 @@ Running the engine produces a local workspace with these main areas:
119
148
  - `state/search.sqlite`: full-text index
120
149
  - `state/jobs.ndjson`: watch-mode automation logs
121
150
 
151
+ Saved outputs are indexed immediately into the graph page registry and search index, then linked back into compiled source, concept, and entity pages during later compile runs.
152
+
122
153
  ## Notes
123
154
 
124
155
  - The engine expects Node `>=24`
package/dist/index.d.ts CHANGED
@@ -2,6 +2,9 @@ import { z } from 'zod';
2
2
  import { Readable, Writable } from 'node:stream';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
 
5
+ declare function installAgent(rootDir: string, agent: "codex" | "claude" | "cursor"): Promise<string>;
6
+ declare function installConfiguredAgents(rootDir: string): Promise<string[]>;
7
+
5
8
  declare const providerCapabilitySchema: z.ZodEnum<{
6
9
  responses: "responses";
7
10
  chat: "chat";
@@ -27,6 +30,12 @@ type PageKind = "index" | "source" | "concept" | "entity" | "output";
27
30
  type Freshness = "fresh" | "stale";
28
31
  type ClaimStatus = "extracted" | "inferred" | "conflicted" | "stale";
29
32
  type Polarity = "positive" | "negative" | "neutral";
33
+ type OutputOrigin = "query" | "explore";
34
+ declare const webSearchProviderTypeSchema: z.ZodEnum<{
35
+ custom: "custom";
36
+ "http-json": "http-json";
37
+ }>;
38
+ type WebSearchProviderType = z.infer<typeof webSearchProviderTypeSchema>;
30
39
  interface GenerationAttachment {
31
40
  mimeType: string;
32
41
  filePath: string;
@@ -62,6 +71,32 @@ interface ProviderConfig {
62
71
  capabilities?: ProviderCapability[];
63
72
  apiStyle?: "responses" | "chat";
64
73
  }
74
+ interface WebSearchProviderConfig {
75
+ type: WebSearchProviderType;
76
+ endpoint?: string;
77
+ method?: "GET" | "POST";
78
+ apiKeyEnv?: string;
79
+ apiKeyHeader?: string;
80
+ apiKeyPrefix?: string;
81
+ headers?: Record<string, string>;
82
+ queryParam?: string;
83
+ limitParam?: string;
84
+ resultsPath?: string;
85
+ titleField?: string;
86
+ urlField?: string;
87
+ snippetField?: string;
88
+ module?: string;
89
+ }
90
+ interface WebSearchResult {
91
+ title: string;
92
+ url: string;
93
+ snippet: string;
94
+ }
95
+ interface WebSearchAdapter {
96
+ readonly id: string;
97
+ readonly type: WebSearchProviderType;
98
+ search(query: string, limit?: number): Promise<WebSearchResult[]>;
99
+ }
65
100
  interface VaultConfig {
66
101
  workspace: {
67
102
  rawDir: string;
@@ -81,9 +116,16 @@ interface VaultConfig {
81
116
  port: number;
82
117
  };
83
118
  agents: Array<"codex" | "claude" | "cursor">;
119
+ webSearch?: {
120
+ providers: Record<string, WebSearchProviderConfig>;
121
+ tasks: {
122
+ deepLintProvider: string;
123
+ };
124
+ };
84
125
  }
85
126
  interface ResolvedPaths {
86
127
  rootDir: string;
128
+ schemaPath: string;
87
129
  rawDir: string;
88
130
  rawSourcesDir: string;
89
131
  rawAssetsDir: string;
@@ -137,6 +179,7 @@ interface SourceClaim {
137
179
  interface SourceAnalysis {
138
180
  sourceId: string;
139
181
  sourceHash: string;
182
+ schemaHash: string;
140
183
  title: string;
141
184
  summary: string;
142
185
  concepts: AnalyzedTerm[];
@@ -173,7 +216,13 @@ interface GraphPage {
173
216
  freshness: Freshness;
174
217
  confidence: number;
175
218
  backlinks: string[];
219
+ schemaHash: string;
176
220
  sourceHashes: Record<string, string>;
221
+ relatedPageIds: string[];
222
+ relatedNodeIds: string[];
223
+ relatedSourceIds: string[];
224
+ origin?: OutputOrigin;
225
+ question?: string;
177
226
  }
178
227
  interface GraphArtifact {
179
228
  generatedAt: string;
@@ -198,13 +247,21 @@ interface SearchResult {
198
247
  interface QueryResult {
199
248
  answer: string;
200
249
  savedTo?: string;
250
+ savedPageId?: string;
201
251
  citations: string[];
252
+ relatedPageIds: string[];
253
+ relatedNodeIds: string[];
254
+ relatedSourceIds: string[];
202
255
  }
203
256
  interface LintFinding {
204
257
  severity: "error" | "warning" | "info";
205
258
  code: string;
206
259
  message: string;
207
260
  pagePath?: string;
261
+ relatedSourceIds?: string[];
262
+ relatedPageIds?: string[];
263
+ suggestedQuery?: string;
264
+ evidence?: WebSearchResult[];
208
265
  }
209
266
  interface InboxImportSkip {
210
267
  path: string;
@@ -238,9 +295,38 @@ interface WatchRunRecord {
238
295
  interface WatchController {
239
296
  close(): Promise<void>;
240
297
  }
298
+ interface CompileState {
299
+ generatedAt: string;
300
+ schemaHash: string;
301
+ analyses: Record<string, string>;
302
+ sourceHashes: Record<string, string>;
303
+ outputHashes: Record<string, string>;
304
+ }
305
+ interface LintOptions {
306
+ deep?: boolean;
307
+ web?: boolean;
308
+ }
309
+ interface ExploreStepResult {
310
+ step: number;
311
+ question: string;
312
+ answer: string;
313
+ savedTo: string;
314
+ savedPageId: string;
315
+ citations: string[];
316
+ followUpQuestions: string[];
317
+ }
318
+ interface ExploreResult {
319
+ rootQuestion: string;
320
+ hubPath: string;
321
+ hubPageId: string;
322
+ stepCount: number;
323
+ steps: ExploreStepResult[];
324
+ suggestedQuestions: string[];
325
+ }
241
326
 
242
327
  declare function defaultVaultConfig(): VaultConfig;
243
- declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string): ResolvedPaths;
328
+ declare function defaultVaultSchema(): string;
329
+ declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string, schemaPath?: string): ResolvedPaths;
244
330
  declare function loadVaultConfig(rootDir: string): Promise<{
245
331
  config: VaultConfig;
246
332
  paths: ResolvedPaths;
@@ -255,9 +341,27 @@ declare function importInbox(rootDir: string, inputDir?: string): Promise<InboxI
255
341
  declare function listManifests(rootDir: string): Promise<SourceManifest[]>;
256
342
  declare function readExtractedText(rootDir: string, manifest: SourceManifest): Promise<string | undefined>;
257
343
 
344
+ declare function createMcpServer(rootDir: string): Promise<McpServer>;
345
+ declare function startMcpServer(rootDir: string, stdin?: Readable, stdout?: Writable): Promise<{
346
+ close: () => Promise<void>;
347
+ }>;
348
+
349
+ declare function createProvider(id: string, config: ProviderConfig, rootDir: string): Promise<ProviderAdapter>;
350
+ declare function getProviderForTask(rootDir: string, task: keyof Awaited<ReturnType<typeof loadVaultConfig>>["config"]["tasks"]): Promise<ProviderAdapter>;
351
+ declare function assertProviderCapability(provider: ProviderAdapter, capability: ProviderCapability): void;
352
+
353
+ interface VaultSchema {
354
+ path: string;
355
+ content: string;
356
+ hash: string;
357
+ isLegacyPath: boolean;
358
+ }
359
+ declare function loadVaultSchema(rootDir: string): Promise<VaultSchema>;
360
+
258
361
  declare function initVault(rootDir: string): Promise<void>;
259
362
  declare function compileVault(rootDir: string): Promise<CompileResult>;
260
363
  declare function queryVault(rootDir: string, question: string, save?: boolean): Promise<QueryResult>;
364
+ declare function exploreVault(rootDir: string, question: string, steps?: number): Promise<ExploreResult>;
261
365
  declare function searchVault(rootDir: string, query: string, limit?: number): Promise<SearchResult[]>;
262
366
  declare function listPages(rootDir: string): Promise<GraphPage[]>;
263
367
  declare function readPage(rootDir: string, relativePath: string): Promise<{
@@ -269,6 +373,7 @@ declare function readPage(rootDir: string, relativePath: string): Promise<{
269
373
  declare function getWorkspaceInfo(rootDir: string): Promise<{
270
374
  rootDir: string;
271
375
  configPath: string;
376
+ schemaPath: string;
272
377
  rawDir: string;
273
378
  wikiDir: string;
274
379
  stateDir: string;
@@ -277,29 +382,20 @@ declare function getWorkspaceInfo(rootDir: string): Promise<{
277
382
  sourceCount: number;
278
383
  pageCount: number;
279
384
  }>;
280
- declare function lintVault(rootDir: string): Promise<LintFinding[]>;
385
+ declare function lintVault(rootDir: string, options?: LintOptions): Promise<LintFinding[]>;
281
386
  declare function bootstrapDemo(rootDir: string, input?: string): Promise<{
282
387
  manifestId?: string;
283
388
  compile?: CompileResult;
284
389
  }>;
285
390
 
286
- declare function installAgent(rootDir: string, agent: "codex" | "claude" | "cursor"): Promise<string>;
287
- declare function installConfiguredAgents(rootDir: string): Promise<string[]>;
288
-
289
391
  declare function startGraphServer(rootDir: string, port?: number): Promise<{
290
392
  port: number;
291
393
  close: () => Promise<void>;
292
394
  }>;
293
395
 
294
- declare function createMcpServer(rootDir: string): Promise<McpServer>;
295
- declare function startMcpServer(rootDir: string, stdin?: Readable, stdout?: Writable): Promise<{
296
- close: () => Promise<void>;
297
- }>;
298
-
299
396
  declare function watchVault(rootDir: string, options?: WatchOptions): Promise<WatchController>;
300
397
 
301
- declare function createProvider(id: string, config: ProviderConfig, rootDir: string): Promise<ProviderAdapter>;
302
- declare function getProviderForTask(rootDir: string, task: keyof Awaited<ReturnType<typeof loadVaultConfig>>["config"]["tasks"]): Promise<ProviderAdapter>;
303
- declare function assertProviderCapability(provider: ProviderAdapter, capability: ProviderCapability): void;
398
+ declare function createWebSearchAdapter(id: string, config: WebSearchProviderConfig, rootDir: string): Promise<WebSearchAdapter>;
399
+ declare function getWebSearchAdapterForTask(rootDir: string, task: "deepLintProvider"): Promise<WebSearchAdapter>;
304
400
 
305
- export { type AnalyzedTerm, type ClaimStatus, type CompileResult, type Freshness, type GenerationAttachment, type GenerationRequest, type GenerationResponse, type GraphArtifact, type GraphEdge, type GraphNode, type GraphPage, type InboxImportResult, type InboxImportSkip, type LintFinding, type PageKind, type Polarity, type ProviderAdapter, type ProviderCapability, type ProviderConfig, type ProviderType, type QueryResult, type ResolvedPaths, type SearchResult, type SourceAnalysis, type SourceAttachment, type SourceClaim, type SourceManifest, type VaultConfig, type WatchController, type WatchOptions, type WatchRunRecord, assertProviderCapability, bootstrapDemo, compileVault, createMcpServer, createProvider, defaultVaultConfig, getProviderForTask, getWorkspaceInfo, importInbox, ingestInput, initVault, initWorkspace, installAgent, installConfiguredAgents, lintVault, listManifests, listPages, loadVaultConfig, providerCapabilitySchema, providerTypeSchema, queryVault, readExtractedText, readPage, resolvePaths, searchVault, startGraphServer, startMcpServer, watchVault };
401
+ export { type AnalyzedTerm, type ClaimStatus, type CompileResult, type CompileState, type ExploreResult, type ExploreStepResult, type Freshness, type GenerationAttachment, type GenerationRequest, type GenerationResponse, type GraphArtifact, type GraphEdge, type GraphNode, type GraphPage, type InboxImportResult, type InboxImportSkip, type LintFinding, type LintOptions, type OutputOrigin, type PageKind, type Polarity, type ProviderAdapter, type ProviderCapability, type ProviderConfig, type ProviderType, type QueryResult, type ResolvedPaths, type SearchResult, type SourceAnalysis, type SourceAttachment, type SourceClaim, type SourceManifest, type VaultConfig, type WatchController, type WatchOptions, type WatchRunRecord, type WebSearchAdapter, type WebSearchProviderConfig, type WebSearchProviderType, type WebSearchResult, assertProviderCapability, bootstrapDemo, compileVault, createMcpServer, createProvider, createWebSearchAdapter, defaultVaultConfig, defaultVaultSchema, exploreVault, getProviderForTask, getWebSearchAdapterForTask, getWorkspaceInfo, importInbox, ingestInput, initVault, initWorkspace, installAgent, installConfiguredAgents, lintVault, listManifests, listPages, loadVaultConfig, loadVaultSchema, providerCapabilitySchema, providerTypeSchema, queryVault, readExtractedText, readPage, resolvePaths, searchVault, startGraphServer, startMcpServer, watchVault, webSearchProviderTypeSchema };