@swarmvaultai/engine 0.1.2 → 0.1.4

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  `@swarmvaultai/engine` is the runtime library behind SwarmVault.
4
4
 
5
- It provides the ingest, compile, query, lint, provider, graph, search, and viewer-serving primitives used by the CLI.
5
+ It exposes the primitives for initializing a workspace, ingesting sources, importing an inbox, compiling a wiki, querying the vault, running lint, serving the graph viewer, watching the inbox, and exposing the vault over MCP.
6
6
 
7
7
  ## Who This Is For
8
8
 
@@ -10,7 +10,8 @@ Use this package if you want to:
10
10
 
11
11
  - build your own interface on top of the SwarmVault runtime
12
12
  - integrate vault operations into another Node application
13
- - customize provider loading or workspace orchestration without shelling out to the CLI
13
+ - embed watch or MCP behavior without shelling out to the CLI
14
+ - customize provider loading or orchestration in code
14
15
 
15
16
  If you only want to use SwarmVault as a tool, install `@swarmvaultai/cli` instead.
16
17
 
@@ -19,48 +20,70 @@ If you only want to use SwarmVault as a tool, install `@swarmvaultai/cli` instea
19
20
  ```ts
20
21
  import {
21
22
  compileVault,
22
- createProvider,
23
+ createMcpServer,
23
24
  defaultVaultConfig,
25
+ defaultVaultSchema,
26
+ importInbox,
24
27
  ingestInput,
25
28
  initVault,
26
29
  installAgent,
27
30
  lintVault,
28
31
  loadVaultConfig,
32
+ loadVaultSchema,
29
33
  queryVault,
30
- startGraphServer
34
+ searchVault,
35
+ startGraphServer,
36
+ startMcpServer,
37
+ watchVault,
31
38
  } from "@swarmvaultai/engine";
32
39
  ```
33
40
 
34
- The engine also exports the main runtime types for providers, graph artifacts, pages, manifests, and lint findings.
41
+ The engine also exports the main runtime types for providers, graph artifacts, pages, manifests, query results, lint findings, and watch records.
35
42
 
36
43
  ## Example
37
44
 
38
45
  ```ts
39
- import { compileVault, ingestInput, initVault, queryVault } from "@swarmvaultai/engine";
46
+ import { compileVault, importInbox, initVault, loadVaultSchema, queryVault, watchVault } from "@swarmvaultai/engine";
40
47
 
41
48
  const rootDir = process.cwd();
42
49
 
43
50
  await initVault(rootDir);
44
- await ingestInput(rootDir, "./research.md");
51
+ const schema = await loadVaultSchema(rootDir);
52
+ console.log(schema.path);
53
+ await importInbox(rootDir);
45
54
  await compileVault(rootDir);
46
55
 
47
56
  const result = await queryVault(rootDir, "What changed most recently?", true);
48
57
  console.log(result.answer);
58
+
59
+ const watcher = await watchVault(rootDir, { lint: true });
49
60
  ```
50
61
 
62
+ ## Schema Layer
63
+
64
+ Each workspace carries a root markdown file named `swarmvault.schema.md`.
65
+
66
+ The engine treats that file as vault-specific operating guidance for compile and query work. In `v0.1.4`:
67
+
68
+ - `initVault()` creates the default schema file
69
+ - `loadVaultSchema()` resolves the canonical file and legacy `schema.md` fallback
70
+ - compile and query prompts include the schema content
71
+ - generated pages store `schema_hash`
72
+ - `lintVault()` marks generated pages stale when the schema changes
73
+
51
74
  ## Provider Model
52
75
 
53
76
  The engine supports:
54
77
 
78
+ - `heuristic`
55
79
  - `openai`
56
- - `ollama`
57
80
  - `anthropic`
58
81
  - `gemini`
82
+ - `ollama`
59
83
  - `openai-compatible`
60
84
  - `custom`
61
- - `heuristic`
62
85
 
63
- Providers are validated through capabilities such as:
86
+ Providers are capability-driven. Each provider declares support for features such as:
64
87
 
65
88
  - `chat`
66
89
  - `structured`
@@ -70,29 +93,57 @@ Providers are validated through capabilities such as:
70
93
  - `streaming`
71
94
  - `local`
72
95
 
73
- This matters because many "OpenAI-compatible" providers implement only part of the OpenAI surface. The engine is designed to route by capability, not by brand name.
96
+ This matters because many "OpenAI-compatible" backends only implement part of the OpenAI surface.
74
97
 
75
- ## Artifacts
98
+ ## Main Engine Surfaces
76
99
 
77
- Running the engine produces a local workspace with four main areas:
100
+ ### Ingest
78
101
 
79
- - `raw/`: immutable source inputs and captured assets
80
- - `wiki/`: generated markdown pages and saved outputs
81
- - `state/`: manifests, extracts, graph state, compile state, and search index
82
- - `agent/`: generated agent rules
102
+ - `ingestInput(rootDir, input)` ingests a local path or URL
103
+ - `importInbox(rootDir, inputDir?)` recursively imports supported inbox files and browser-clipper style bundles
104
+
105
+ ### Compile + Query
83
106
 
84
- Important artifacts include:
107
+ - `compileVault(rootDir)` writes wiki pages, graph data, and search state using the vault schema as guidance
108
+ - `queryVault(rootDir, question, save)` answers against the compiled vault using the same schema layer
109
+ - `searchVault(rootDir, query, limit)` searches compiled pages directly
85
110
 
86
- - `state/graph.json`
87
- - `state/search.sqlite`
88
- - `wiki/index.md`
89
- - `wiki/sources/*.md`
90
- - `wiki/concepts/*.md`
91
- - `wiki/entities/*.md`
92
- - `wiki/outputs/*.md`
111
+ ### Automation
112
+
113
+ - `watchVault(rootDir, options)` watches the inbox and appends run records to `state/jobs.ndjson`
114
+ - `lintVault(rootDir)` runs health and anti-drift checks
115
+
116
+ ### MCP
117
+
118
+ - `createMcpServer(rootDir)` creates an MCP server instance
119
+ - `startMcpServer(rootDir)` runs the MCP server over stdio
120
+
121
+ 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.
122
+
123
+ ## Artifacts
124
+
125
+ Running the engine produces a local workspace with these main areas:
126
+
127
+ - `swarmvault.schema.md`: vault-specific compile and query instructions
128
+ - `inbox/`: capture staging area for markdown bundles and imported files
129
+ - `raw/sources/`: immutable source copies
130
+ - `raw/assets/`: copied attachments referenced by ingested markdown bundles
131
+ - `wiki/`: generated markdown pages and saved outputs
132
+ - `state/manifests/`: source manifests
133
+ - `state/extracts/`: extracted text
134
+ - `state/analyses/`: model analysis output
135
+ - `state/graph.json`: compiled graph
136
+ - `state/search.sqlite`: full-text index
137
+ - `state/jobs.ndjson`: watch-mode automation logs
93
138
 
94
139
  ## Notes
95
140
 
96
141
  - The engine expects Node `>=24`
97
142
  - The local search layer currently uses the built-in `node:sqlite` module, which may emit an experimental warning in Node 24
98
143
  - The viewer source lives in the companion `@swarmvaultai/viewer` package, and the built assets are bundled into the engine package for CLI installs
144
+
145
+ ## Links
146
+
147
+ - Website: https://www.swarmvault.ai
148
+ - Docs: https://www.swarmvault.ai/docs
149
+ - GitHub: https://github.com/swarmclawai/swarmvault
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ import { Readable, Writable } from 'node:stream';
3
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
4
 
3
5
  declare const providerCapabilitySchema: z.ZodEnum<{
4
6
  responses: "responses";
@@ -66,6 +68,7 @@ interface VaultConfig {
66
68
  wikiDir: string;
67
69
  stateDir: string;
68
70
  agentDir: string;
71
+ inboxDir: string;
69
72
  };
70
73
  providers: Record<string, ProviderConfig>;
71
74
  tasks: {
@@ -81,10 +84,14 @@ interface VaultConfig {
81
84
  }
82
85
  interface ResolvedPaths {
83
86
  rootDir: string;
87
+ schemaPath: string;
84
88
  rawDir: string;
89
+ rawSourcesDir: string;
90
+ rawAssetsDir: string;
85
91
  wikiDir: string;
86
92
  stateDir: string;
87
93
  agentDir: string;
94
+ inboxDir: string;
88
95
  manifestsDir: string;
89
96
  extractsDir: string;
90
97
  analysesDir: string;
@@ -92,8 +99,14 @@ interface ResolvedPaths {
92
99
  graphPath: string;
93
100
  searchDbPath: string;
94
101
  compileStatePath: string;
102
+ jobsLogPath: string;
95
103
  configPath: string;
96
104
  }
105
+ interface SourceAttachment {
106
+ path: string;
107
+ mimeType: string;
108
+ originalPath?: string;
109
+ }
97
110
  interface SourceManifest {
98
111
  sourceId: string;
99
112
  title: string;
@@ -107,6 +120,7 @@ interface SourceManifest {
107
120
  contentHash: string;
108
121
  createdAt: string;
109
122
  updatedAt: string;
123
+ attachments?: SourceAttachment[];
110
124
  }
111
125
  interface AnalyzedTerm {
112
126
  id: string;
@@ -124,6 +138,7 @@ interface SourceClaim {
124
138
  interface SourceAnalysis {
125
139
  sourceId: string;
126
140
  sourceHash: string;
141
+ schemaHash: string;
127
142
  title: string;
128
143
  summary: string;
129
144
  concepts: AnalyzedTerm[];
@@ -160,6 +175,7 @@ interface GraphPage {
160
175
  freshness: Freshness;
161
176
  confidence: number;
162
177
  backlinks: string[];
178
+ schemaHash: string;
163
179
  sourceHashes: Record<string, string>;
164
180
  }
165
181
  interface GraphArtifact {
@@ -193,9 +209,42 @@ interface LintFinding {
193
209
  message: string;
194
210
  pagePath?: string;
195
211
  }
212
+ interface InboxImportSkip {
213
+ path: string;
214
+ reason: string;
215
+ }
216
+ interface InboxImportResult {
217
+ inputDir: string;
218
+ scannedCount: number;
219
+ attachmentCount: number;
220
+ imported: SourceManifest[];
221
+ skipped: InboxImportSkip[];
222
+ }
223
+ interface WatchOptions {
224
+ lint?: boolean;
225
+ debounceMs?: number;
226
+ }
227
+ interface WatchRunRecord {
228
+ startedAt: string;
229
+ finishedAt: string;
230
+ durationMs: number;
231
+ inputDir: string;
232
+ reasons: string[];
233
+ importedCount: number;
234
+ scannedCount: number;
235
+ attachmentCount: number;
236
+ changedPages: string[];
237
+ lintFindingCount?: number;
238
+ success: boolean;
239
+ error?: string;
240
+ }
241
+ interface WatchController {
242
+ close(): Promise<void>;
243
+ }
196
244
 
197
245
  declare function defaultVaultConfig(): VaultConfig;
198
- declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string): ResolvedPaths;
246
+ declare function defaultVaultSchema(): string;
247
+ declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string, schemaPath?: string): ResolvedPaths;
199
248
  declare function loadVaultConfig(rootDir: string): Promise<{
200
249
  config: VaultConfig;
201
250
  paths: ResolvedPaths;
@@ -206,12 +255,33 @@ declare function initWorkspace(rootDir: string): Promise<{
206
255
  }>;
207
256
 
208
257
  declare function ingestInput(rootDir: string, input: string): Promise<SourceManifest>;
258
+ declare function importInbox(rootDir: string, inputDir?: string): Promise<InboxImportResult>;
209
259
  declare function listManifests(rootDir: string): Promise<SourceManifest[]>;
210
260
  declare function readExtractedText(rootDir: string, manifest: SourceManifest): Promise<string | undefined>;
211
261
 
212
262
  declare function initVault(rootDir: string): Promise<void>;
213
263
  declare function compileVault(rootDir: string): Promise<CompileResult>;
214
264
  declare function queryVault(rootDir: string, question: string, save?: boolean): Promise<QueryResult>;
265
+ declare function searchVault(rootDir: string, query: string, limit?: number): Promise<SearchResult[]>;
266
+ declare function listPages(rootDir: string): Promise<GraphPage[]>;
267
+ declare function readPage(rootDir: string, relativePath: string): Promise<{
268
+ path: string;
269
+ title: string;
270
+ frontmatter: Record<string, unknown>;
271
+ content: string;
272
+ } | null>;
273
+ declare function getWorkspaceInfo(rootDir: string): Promise<{
274
+ rootDir: string;
275
+ configPath: string;
276
+ schemaPath: string;
277
+ rawDir: string;
278
+ wikiDir: string;
279
+ stateDir: string;
280
+ agentDir: string;
281
+ inboxDir: string;
282
+ sourceCount: number;
283
+ pageCount: number;
284
+ }>;
215
285
  declare function lintVault(rootDir: string): Promise<LintFinding[]>;
216
286
  declare function bootstrapDemo(rootDir: string, input?: string): Promise<{
217
287
  manifestId?: string;
@@ -221,13 +291,28 @@ declare function bootstrapDemo(rootDir: string, input?: string): Promise<{
221
291
  declare function installAgent(rootDir: string, agent: "codex" | "claude" | "cursor"): Promise<string>;
222
292
  declare function installConfiguredAgents(rootDir: string): Promise<string[]>;
223
293
 
294
+ interface VaultSchema {
295
+ path: string;
296
+ content: string;
297
+ hash: string;
298
+ isLegacyPath: boolean;
299
+ }
300
+ declare function loadVaultSchema(rootDir: string): Promise<VaultSchema>;
301
+
224
302
  declare function startGraphServer(rootDir: string, port?: number): Promise<{
225
303
  port: number;
226
304
  close: () => Promise<void>;
227
305
  }>;
228
306
 
307
+ declare function createMcpServer(rootDir: string): Promise<McpServer>;
308
+ declare function startMcpServer(rootDir: string, stdin?: Readable, stdout?: Writable): Promise<{
309
+ close: () => Promise<void>;
310
+ }>;
311
+
312
+ declare function watchVault(rootDir: string, options?: WatchOptions): Promise<WatchController>;
313
+
229
314
  declare function createProvider(id: string, config: ProviderConfig, rootDir: string): Promise<ProviderAdapter>;
230
315
  declare function getProviderForTask(rootDir: string, task: keyof Awaited<ReturnType<typeof loadVaultConfig>>["config"]["tasks"]): Promise<ProviderAdapter>;
231
316
  declare function assertProviderCapability(provider: ProviderAdapter, capability: ProviderCapability): void;
232
317
 
233
- export { type AnalyzedTerm, type ClaimStatus, type CompileResult, type Freshness, type GenerationAttachment, type GenerationRequest, type GenerationResponse, type GraphArtifact, type GraphEdge, type GraphNode, type GraphPage, type LintFinding, type PageKind, type Polarity, type ProviderAdapter, type ProviderCapability, type ProviderConfig, type ProviderType, type QueryResult, type ResolvedPaths, type SearchResult, type SourceAnalysis, type SourceClaim, type SourceManifest, type VaultConfig, assertProviderCapability, bootstrapDemo, compileVault, createProvider, defaultVaultConfig, getProviderForTask, ingestInput, initVault, initWorkspace, installAgent, installConfiguredAgents, lintVault, listManifests, loadVaultConfig, providerCapabilitySchema, providerTypeSchema, queryVault, readExtractedText, resolvePaths, startGraphServer };
318
+ 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, defaultVaultSchema, getProviderForTask, getWorkspaceInfo, importInbox, ingestInput, initVault, initWorkspace, installAgent, installConfiguredAgents, lintVault, listManifests, listPages, loadVaultConfig, loadVaultSchema, providerCapabilitySchema, providerTypeSchema, queryVault, readExtractedText, readPage, resolvePaths, searchVault, startGraphServer, startMcpServer, watchVault };