@swarmvaultai/engine 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,54 @@ 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
+ importInbox,
24
26
  ingestInput,
25
27
  initVault,
26
28
  installAgent,
27
29
  lintVault,
28
30
  loadVaultConfig,
29
31
  queryVault,
30
- startGraphServer
32
+ searchVault,
33
+ startGraphServer,
34
+ startMcpServer,
35
+ watchVault,
31
36
  } from "@swarmvaultai/engine";
32
37
  ```
33
38
 
34
- The engine also exports the main runtime types for providers, graph artifacts, pages, manifests, and lint findings.
39
+ The engine also exports the main runtime types for providers, graph artifacts, pages, manifests, query results, lint findings, and watch records.
35
40
 
36
41
  ## Example
37
42
 
38
43
  ```ts
39
- import { compileVault, ingestInput, initVault, queryVault } from "@swarmvaultai/engine";
44
+ import { compileVault, importInbox, initVault, queryVault, watchVault } from "@swarmvaultai/engine";
40
45
 
41
46
  const rootDir = process.cwd();
42
47
 
43
48
  await initVault(rootDir);
44
- await ingestInput(rootDir, "./research.md");
49
+ await importInbox(rootDir);
45
50
  await compileVault(rootDir);
46
51
 
47
52
  const result = await queryVault(rootDir, "What changed most recently?", true);
48
53
  console.log(result.answer);
54
+
55
+ const watcher = await watchVault(rootDir, { lint: true });
49
56
  ```
50
57
 
51
58
  ## Provider Model
52
59
 
53
60
  The engine supports:
54
61
 
62
+ - `heuristic`
55
63
  - `openai`
56
- - `ollama`
57
64
  - `anthropic`
58
65
  - `gemini`
66
+ - `ollama`
59
67
  - `openai-compatible`
60
68
  - `custom`
61
- - `heuristic`
62
69
 
63
- Providers are validated through capabilities such as:
70
+ Providers are capability-driven. Each provider declares support for features such as:
64
71
 
65
72
  - `chat`
66
73
  - `structured`
@@ -70,29 +77,56 @@ Providers are validated through capabilities such as:
70
77
  - `streaming`
71
78
  - `local`
72
79
 
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.
80
+ This matters because many "OpenAI-compatible" backends only implement part of the OpenAI surface.
74
81
 
75
- ## Artifacts
82
+ ## Main Engine Surfaces
76
83
 
77
- Running the engine produces a local workspace with four main areas:
84
+ ### Ingest
78
85
 
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
86
+ - `ingestInput(rootDir, input)` ingests a local path or URL
87
+ - `importInbox(rootDir, inputDir?)` recursively imports supported inbox files and browser-clipper style bundles
88
+
89
+ ### Compile + Query
90
+
91
+ - `compileVault(rootDir)` writes wiki pages, graph data, and search state
92
+ - `queryVault(rootDir, question, save)` answers against the compiled vault
93
+ - `searchVault(rootDir, query, limit)` searches compiled pages directly
94
+
95
+ ### Automation
83
96
 
84
- Important artifacts include:
97
+ - `watchVault(rootDir, options)` watches the inbox and appends run records to `state/jobs.ndjson`
98
+ - `lintVault(rootDir)` runs health and anti-drift checks
85
99
 
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`
100
+ ### MCP
101
+
102
+ - `createMcpServer(rootDir)` creates an MCP server instance
103
+ - `startMcpServer(rootDir)` runs the MCP server over stdio
104
+
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.
106
+
107
+ ## Artifacts
108
+
109
+ Running the engine produces a local workspace with these main areas:
110
+
111
+ - `inbox/`: capture staging area for markdown bundles and imported files
112
+ - `raw/sources/`: immutable source copies
113
+ - `raw/assets/`: copied attachments referenced by ingested markdown bundles
114
+ - `wiki/`: generated markdown pages and saved outputs
115
+ - `state/manifests/`: source manifests
116
+ - `state/extracts/`: extracted text
117
+ - `state/analyses/`: model analysis output
118
+ - `state/graph.json`: compiled graph
119
+ - `state/search.sqlite`: full-text index
120
+ - `state/jobs.ndjson`: watch-mode automation logs
93
121
 
94
122
  ## Notes
95
123
 
96
124
  - The engine expects Node `>=24`
97
125
  - The local search layer currently uses the built-in `node:sqlite` module, which may emit an experimental warning in Node 24
98
- - The graph viewer is served from the companion `@swarmvaultai/viewer` package build output
126
+ - The viewer source lives in the companion `@swarmvaultai/viewer` package, and the built assets are bundled into the engine package for CLI installs
127
+
128
+ ## Links
129
+
130
+ - Website: https://www.swarmvault.ai
131
+ - Docs: https://www.swarmvault.ai/docs
132
+ - 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: {
@@ -82,9 +85,12 @@ interface VaultConfig {
82
85
  interface ResolvedPaths {
83
86
  rootDir: string;
84
87
  rawDir: string;
88
+ rawSourcesDir: string;
89
+ rawAssetsDir: string;
85
90
  wikiDir: string;
86
91
  stateDir: string;
87
92
  agentDir: string;
93
+ inboxDir: string;
88
94
  manifestsDir: string;
89
95
  extractsDir: string;
90
96
  analysesDir: string;
@@ -92,8 +98,14 @@ interface ResolvedPaths {
92
98
  graphPath: string;
93
99
  searchDbPath: string;
94
100
  compileStatePath: string;
101
+ jobsLogPath: string;
95
102
  configPath: string;
96
103
  }
104
+ interface SourceAttachment {
105
+ path: string;
106
+ mimeType: string;
107
+ originalPath?: string;
108
+ }
97
109
  interface SourceManifest {
98
110
  sourceId: string;
99
111
  title: string;
@@ -107,6 +119,7 @@ interface SourceManifest {
107
119
  contentHash: string;
108
120
  createdAt: string;
109
121
  updatedAt: string;
122
+ attachments?: SourceAttachment[];
110
123
  }
111
124
  interface AnalyzedTerm {
112
125
  id: string;
@@ -193,6 +206,38 @@ interface LintFinding {
193
206
  message: string;
194
207
  pagePath?: string;
195
208
  }
209
+ interface InboxImportSkip {
210
+ path: string;
211
+ reason: string;
212
+ }
213
+ interface InboxImportResult {
214
+ inputDir: string;
215
+ scannedCount: number;
216
+ attachmentCount: number;
217
+ imported: SourceManifest[];
218
+ skipped: InboxImportSkip[];
219
+ }
220
+ interface WatchOptions {
221
+ lint?: boolean;
222
+ debounceMs?: number;
223
+ }
224
+ interface WatchRunRecord {
225
+ startedAt: string;
226
+ finishedAt: string;
227
+ durationMs: number;
228
+ inputDir: string;
229
+ reasons: string[];
230
+ importedCount: number;
231
+ scannedCount: number;
232
+ attachmentCount: number;
233
+ changedPages: string[];
234
+ lintFindingCount?: number;
235
+ success: boolean;
236
+ error?: string;
237
+ }
238
+ interface WatchController {
239
+ close(): Promise<void>;
240
+ }
196
241
 
197
242
  declare function defaultVaultConfig(): VaultConfig;
198
243
  declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string): ResolvedPaths;
@@ -206,12 +251,32 @@ declare function initWorkspace(rootDir: string): Promise<{
206
251
  }>;
207
252
 
208
253
  declare function ingestInput(rootDir: string, input: string): Promise<SourceManifest>;
254
+ declare function importInbox(rootDir: string, inputDir?: string): Promise<InboxImportResult>;
209
255
  declare function listManifests(rootDir: string): Promise<SourceManifest[]>;
210
256
  declare function readExtractedText(rootDir: string, manifest: SourceManifest): Promise<string | undefined>;
211
257
 
212
258
  declare function initVault(rootDir: string): Promise<void>;
213
259
  declare function compileVault(rootDir: string): Promise<CompileResult>;
214
260
  declare function queryVault(rootDir: string, question: string, save?: boolean): Promise<QueryResult>;
261
+ declare function searchVault(rootDir: string, query: string, limit?: number): Promise<SearchResult[]>;
262
+ declare function listPages(rootDir: string): Promise<GraphPage[]>;
263
+ declare function readPage(rootDir: string, relativePath: string): Promise<{
264
+ path: string;
265
+ title: string;
266
+ frontmatter: Record<string, unknown>;
267
+ content: string;
268
+ } | null>;
269
+ declare function getWorkspaceInfo(rootDir: string): Promise<{
270
+ rootDir: string;
271
+ configPath: string;
272
+ rawDir: string;
273
+ wikiDir: string;
274
+ stateDir: string;
275
+ agentDir: string;
276
+ inboxDir: string;
277
+ sourceCount: number;
278
+ pageCount: number;
279
+ }>;
215
280
  declare function lintVault(rootDir: string): Promise<LintFinding[]>;
216
281
  declare function bootstrapDemo(rootDir: string, input?: string): Promise<{
217
282
  manifestId?: string;
@@ -226,8 +291,15 @@ declare function startGraphServer(rootDir: string, port?: number): Promise<{
226
291
  close: () => Promise<void>;
227
292
  }>;
228
293
 
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
+ declare function watchVault(rootDir: string, options?: WatchOptions): Promise<WatchController>;
300
+
229
301
  declare function createProvider(id: string, config: ProviderConfig, rootDir: string): Promise<ProviderAdapter>;
230
302
  declare function getProviderForTask(rootDir: string, task: keyof Awaited<ReturnType<typeof loadVaultConfig>>["config"]["tasks"]): Promise<ProviderAdapter>;
231
303
  declare function assertProviderCapability(provider: ProviderAdapter, capability: ProviderCapability): void;
232
304
 
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 };
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 };