context-vault 2.4.0 → 2.4.2

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 ADDED
@@ -0,0 +1,438 @@
1
+ # context-vault
2
+
3
+ [![npm version](https://img.shields.io/npm/v/context-vault)](https://www.npmjs.com/package/context-vault)
4
+ [![npm downloads](https://img.shields.io/npm/dm/context-vault)](https://www.npmjs.com/package/context-vault)
5
+ [![license](https://img.shields.io/npm/l/context-vault)](./LICENSE)
6
+ [![node](https://img.shields.io/node/v/context-vault)](https://nodejs.org)
7
+
8
+ Persistent memory for AI agents — saves and searches knowledge across sessions.
9
+
10
+ <p align="center">
11
+ <img src="https://github.com/fellanH/context-mcp/raw/main/demo.gif" alt="context-vault demo — Claude Code and Cursor using the knowledge vault" width="800">
12
+ </p>
13
+
14
+ ## Quick Start
15
+
16
+ ```bash
17
+ npm install -g context-vault
18
+ context-vault setup
19
+ ```
20
+
21
+ Setup auto-detects your tools (Claude Code, Codex, Claude Desktop, Cursor, Windsurf, Antigravity, Cline), downloads the embedding model, seeds your vault with a starter entry, and verifies everything works. Then open your AI tool and try:
22
+
23
+ > "Search my vault for getting started"
24
+
25
+ For hosted MCP setup (Claude Code, Cursor, GPT Actions), see [connect-in-2-minutes](https://github.com/fellanH/context-mcp/blob/main/docs/distribution/connect-in-2-minutes.md).
26
+
27
+ > **Note:** `context-mcp` still works as a CLI alias but `context-vault` is the primary command.
28
+
29
+ ## What It Does
30
+
31
+ - **Save** insights, decisions, patterns, and any custom knowledge kind from AI sessions
32
+ - **Search** with hybrid full-text + semantic similarity, ranked by relevance and recency
33
+ - **Own your data** — plain markdown files in folders you control, git-versioned, human-editable
34
+
35
+ ## Tools
36
+
37
+ The server exposes six tools. Your AI agent calls them automatically — you don't invoke them directly.
38
+
39
+ | Tool | Type | Description |
40
+ |------|------|-------------|
41
+ | `get_context` | Read | Hybrid FTS5 + vector search across all knowledge |
42
+ | `save_context` | Write | Save new knowledge or update existing entries by ID |
43
+ | `list_context` | Browse | List vault entries with filtering and pagination |
44
+ | `delete_context` | Delete | Remove an entry by ID (file + index) |
45
+ | `submit_feedback` | Write | Submit bug reports or feature requests |
46
+ | `context_status` | Diag | Show resolved config, health, and per-kind file counts |
47
+
48
+ ### `get_context` — Search your vault
49
+
50
+ ```js
51
+ get_context({
52
+ query: "react query caching", // Natural language or keywords
53
+ kind: "insight", // Optional: filter by kind
54
+ tags: ["react"], // Optional: filter by tags
55
+ limit: 5 // Optional: max results (default 10)
56
+ })
57
+ ```
58
+
59
+ Returns entries ranked by combined full-text and semantic similarity, with recency weighting.
60
+
61
+ ### `save_context` — Save or update knowledge
62
+
63
+ ```js
64
+ // Create new entry
65
+ save_context({
66
+ kind: "insight", // Determines folder: insights/
67
+ body: "React Query staleTime defaults to 0",
68
+ tags: ["react", "performance"],
69
+ title: "staleTime gotcha", // Optional
70
+ meta: { type: "gotcha" }, // Optional: any structured data
71
+ folder: "react/hooks", // Optional: subfolder organization
72
+ source: "debugging-session" // Optional: provenance
73
+ })
74
+ // → ~/vault/knowledge/insights/react/hooks/staletime-gotcha.md
75
+
76
+ // Update existing entry by ID
77
+ save_context({
78
+ id: "01HXYZ...", // ULID from a previous save
79
+ body: "Updated content here", // Only provide fields you want to change
80
+ tags: ["react", "updated"] // Omitted fields are preserved
81
+ })
82
+ ```
83
+
84
+ The `kind` field accepts any string — `"insight"`, `"decision"`, `"pattern"`, `"reference"`, or any custom kind. The folder is auto-created from the pluralized kind name.
85
+
86
+ When updating (`id` provided), omitted fields are preserved from the original. You cannot change `kind` or `identity_key` — delete and re-create instead.
87
+
88
+ ### `list_context` — Browse entries
89
+
90
+ ```js
91
+ list_context({
92
+ kind: "insight", // Optional: filter by kind
93
+ category: "knowledge", // Optional: knowledge, entity, or event
94
+ tags: ["react"], // Optional: filter by tags
95
+ limit: 10, // Optional: max results (default 20, max 100)
96
+ offset: 0 // Optional: pagination offset
97
+ })
98
+ ```
99
+
100
+ Returns entry metadata (id, title, kind, category, tags, created_at) without body content. Use `get_context` with a search query to retrieve full entries.
101
+
102
+ ### `delete_context` — Remove an entry
103
+
104
+ ```js
105
+ delete_context({
106
+ id: "01HXYZ..." // ULID of the entry to delete
107
+ })
108
+ ```
109
+
110
+ Removes the markdown file from disk and cleans up the database and vector index.
111
+
112
+ ### `context_status` — Diagnostics
113
+
114
+ Shows vault path, database size, file counts per kind, embedding coverage, and any issues.
115
+
116
+ ## Quick Reference
117
+
118
+ ### CLI Commands
119
+
120
+ | Command | Description |
121
+ |---------|-------------|
122
+ | `context-vault setup` | Interactive installer — detects tools, writes configs |
123
+ | `context-vault connect --key cv_...` | Connect AI tools to hosted vault |
124
+ | `context-vault serve` | Start the MCP server (used by AI clients) |
125
+ | `context-vault ui [--port 3141]` | Launch web dashboard |
126
+ | `context-vault status` | Show vault health, paths, and entry counts |
127
+ | `context-vault reindex` | Rebuild search index from vault files |
128
+ | `context-vault update` | Check for and install updates |
129
+ | `context-vault uninstall` | Remove MCP configs and optionally data |
130
+ | `context-vault migrate` | Migrate vault between local and hosted |
131
+
132
+ ### AI Tool Examples
133
+
134
+ Tell your AI agent any of these:
135
+
136
+ - **"Search my vault for React hooks"** → hybrid full-text + semantic search
137
+ - **"Save an insight: always use useCallback for event handlers"** → creates a new entry
138
+ - **"List my recent decisions"** → browse entries filtered by kind
139
+ - **"Show my vault status"** → diagnostics and health check
140
+ - **"Delete entry 01HXYZ..."** → remove by ID
141
+
142
+ ## Common Workflows
143
+
144
+ ### Save and Retrieve
145
+
146
+ ```
147
+ You: "Save an insight: React Query's staleTime defaults to 0"
148
+ AI: ✓ Saved insight → knowledge/insights/react-querys-staletime-defaults.md
149
+
150
+ You: "Search my vault for React Query"
151
+ AI: [Returns the saved insight with full content]
152
+ ```
153
+
154
+ ### Build a Project Knowledge Base
155
+
156
+ ```
157
+ You: "Save a decision: we chose SQLite over Postgres for the local-first architecture"
158
+ You: "Save a pattern: all API handlers follow the try/catch/respond pattern in src/api/"
159
+ You: "What decisions have we made about the database?"
160
+ AI: [Returns relevant decisions ranked by relevance]
161
+ ```
162
+
163
+ ### Track Contacts and Entities
164
+
165
+ ```
166
+ You: "Save a contact for Alice (alice@example.com) — lead developer on Project X"
167
+ You: "Search my vault for Alice"
168
+ AI: [Returns the contact entry]
169
+ ```
170
+
171
+ ### Session Summaries
172
+
173
+ ```
174
+ You: "Save a session summary: debugged auth token refresh, fixed race condition in useAuth hook"
175
+ You: "What did I work on last week?"
176
+ AI: [Returns recent session entries]
177
+ ```
178
+
179
+ ## Knowledge Organization
180
+
181
+ ### Folders and Kinds
182
+
183
+ Entries are organized into three categories — **knowledge** (enduring insights, decisions, patterns), **entity** (contacts, projects, tools), and **event** (sessions, conversations, logs). See [DATA_CATEGORIES](https://github.com/fellanH/context-mcp/blob/main/docs/DATA_CATEGORIES.md) for the full category system, kind mappings, and write semantics.
184
+
185
+ Each top-level subdirectory in the vault maps to a `kind` value. The directory name is depluralized:
186
+
187
+ ```
188
+ knowledge/insights/ → kind: "insight"
189
+ knowledge/decisions/ → kind: "decision"
190
+ knowledge/patterns/ → kind: "pattern"
191
+ knowledge/references/ → kind: "reference"
192
+ ```
193
+
194
+ Within each kind directory, nested subfolders provide human-browsable organization. The subfolder path is stored in `meta.folder`:
195
+
196
+ ```
197
+ ON DISK IN DB (vault table)
198
+ knowledge/insights/ kind: "insight", meta.folder: null
199
+ flat-file.md
200
+ knowledge/insights/react/hooks/ kind: "insight", meta.folder: "react/hooks"
201
+ use-query-gotcha.md
202
+ ```
203
+
204
+ Tags are semantic (what the content is about). Folder structure is organizational (where it lives). These are separate concerns.
205
+
206
+ ### File Format
207
+
208
+ All knowledge files use YAML frontmatter:
209
+
210
+ ```markdown
211
+ ---
212
+ id: 01HXYZ...
213
+ tags: ["react", "performance"]
214
+ source: claude-code
215
+ created: 2026-02-17T12:00:00Z
216
+ ---
217
+ React Query's staleTime defaults to 0 — set it explicitly or every mount triggers a refetch.
218
+ ```
219
+
220
+ Standard keys: `id`, `tags`, `source`, `created`. Any extra frontmatter keys (`type`, `status`, `language`, `folder`, etc.) are stored in a `meta` JSON column automatically.
221
+
222
+ ### Custom Kinds
223
+
224
+ No code changes required:
225
+
226
+ 1. `mkdir ~/vault/knowledge/references/`
227
+ 2. Add `.md` files with YAML frontmatter
228
+ 3. The next session auto-indexes them
229
+
230
+ The kind name comes from the directory: `references/` → kind `reference`.
231
+
232
+ ## Configuration
233
+
234
+ Works out of the box with zero config. All paths are overridable:
235
+
236
+ ```
237
+ CLI args > env vars > config file > convention defaults
238
+ ```
239
+
240
+ ### Defaults
241
+
242
+ | Setting | Default |
243
+ |---------|---------|
244
+ | Vault dir | `~/vault/` |
245
+ | Data dir | `~/.context-mcp/` |
246
+ | Database | `~/.context-mcp/vault.db` |
247
+ | Dev dir | `~/dev/` |
248
+
249
+ ### Config File (`~/.context-mcp/config.json`)
250
+
251
+ Lives in the data directory alongside the database. Created by `setup`, or create it manually:
252
+
253
+ ```json
254
+ {
255
+ "vaultDir": "/Users/you/vault/",
256
+ "dataDir": "/Users/you/.context-mcp",
257
+ "dbPath": "/Users/you/.context-mcp/vault.db",
258
+ "devDir": "/Users/you/dev"
259
+ }
260
+ ```
261
+
262
+ ### Environment Variables
263
+
264
+ Both `CONTEXT_VAULT_*` and `CONTEXT_MCP_*` prefixes are supported. The `CONTEXT_VAULT_*` prefix takes priority.
265
+
266
+ | Variable | Overrides |
267
+ |----------|-----------|
268
+ | `CONTEXT_VAULT_VAULT_DIR` / `CONTEXT_MCP_VAULT_DIR` | Vault directory (knowledge files) |
269
+ | `CONTEXT_VAULT_DB_PATH` / `CONTEXT_MCP_DB_PATH` | Database path |
270
+ | `CONTEXT_VAULT_DEV_DIR` / `CONTEXT_MCP_DEV_DIR` | Dev directory |
271
+ | `CONTEXT_VAULT_DATA_DIR` / `CONTEXT_MCP_DATA_DIR` | Data directory (DB + config storage) |
272
+
273
+ ### CLI Arguments
274
+
275
+ ```bash
276
+ context-vault serve --vault-dir /custom/vault --dev-dir /custom/dev
277
+ context-vault serve --data-dir /custom/data --db-path /custom/data/vault.db
278
+ ```
279
+
280
+ ## CLI
281
+
282
+ ```bash
283
+ context-vault <command> [options]
284
+ ```
285
+
286
+ | Command | Description |
287
+ |---------|-------------|
288
+ | `setup` | Interactive MCP installer — detects tools, writes configs |
289
+ | `connect --key cv_...` | Connect AI tools to hosted vault |
290
+ | `serve` | Start the MCP server (used by AI clients in MCP configs) |
291
+ | `ui [--port 3141]` | Launch the web dashboard |
292
+ | `reindex` | Rebuild search index from knowledge files |
293
+ | `status` | Show vault diagnostics (paths, counts, health) |
294
+ | `update` | Check for and install updates |
295
+ | `uninstall` | Remove MCP configs and optionally data |
296
+ | `migrate --to-hosted/--to-local` | Migrate vault between local and hosted |
297
+
298
+ If running from source without a global install, use `npx context-vault` or `node packages/local/bin/cli.js` instead of `context-vault`.
299
+
300
+ ## Install
301
+
302
+ ### npm (Recommended)
303
+
304
+ ```bash
305
+ npm install -g context-vault
306
+ context-vault setup
307
+ ```
308
+
309
+ The `setup` command auto-detects installed tools (Claude Code, Codex, Claude Desktop, Cursor, Windsurf, Antigravity, Cline), lets you pick which to configure, and writes the correct MCP config for each. Existing configs are preserved — only the `context-vault` entry is added or updated.
310
+
311
+ ### Manual Configuration
312
+
313
+ If you prefer manual setup, add to your tool's MCP config. Pass `--vault-dir` to point at your vault folder (omit it to use the default `~/vault/`).
314
+
315
+ **npm install** (portable — survives upgrades):
316
+
317
+ ```json
318
+ {
319
+ "mcpServers": {
320
+ "context-vault": {
321
+ "command": "context-vault",
322
+ "args": ["serve", "--vault-dir", "/path/to/vault"]
323
+ }
324
+ }
325
+ }
326
+ ```
327
+
328
+ You can also pass config via environment variables in the MCP config block:
329
+
330
+ ```json
331
+ {
332
+ "mcpServers": {
333
+ "context-vault": {
334
+ "command": "context-vault",
335
+ "args": ["serve"],
336
+ "env": {
337
+ "CONTEXT_VAULT_VAULT_DIR": "/path/to/vault"
338
+ }
339
+ }
340
+ }
341
+ }
342
+ ```
343
+
344
+ ### How the Server Runs
345
+
346
+ The server is an MCP (Model Context Protocol) process — you don't start or stop it manually. Your AI client (Claude Code, Codex, Cursor, Windsurf, Cline, etc.) spawns it automatically as a child process when a session begins, based on the `mcpServers` config above. The server communicates over stdio and lives for the duration of the session. When the session ends, the client terminates the process and SQLite cleans up its WAL files.
347
+
348
+ This means:
349
+ - **No daemon, no port, no background service.** The server only runs while your AI client is active.
350
+ - **Multiple sessions** can run separate server instances concurrently — SQLite WAL mode handles concurrent access safely.
351
+ - **Embedding model** is downloaded during `setup` (~22MB, all-MiniLM-L6-v2). If setup was skipped, it downloads on first use.
352
+ - **Auto-reindex** on first tool call per session ensures the search index is always in sync with your files on disk. No manual reindex needed.
353
+
354
+ ## Web Dashboard
355
+
356
+ The `context-vault ui` command launches a web dashboard for browsing, searching, and managing your vault entries.
357
+
358
+ ## How It Works
359
+
360
+ ```
361
+ YOUR FILES (source of truth) SEARCH INDEX (derived)
362
+ ~/vault/ ~/.context-mcp/vault.db
363
+ ├── knowledge/ ┌───────────────────────────────┐
364
+ │ ├── insights/ │ vault table │
365
+ │ │ ├── react-query-caching.md │ kind: insight │
366
+ │ │ └── react/hooks/ │ meta.folder: "react/hooks" │
367
+ │ │ └── use-query-gotcha.md │ kind: decision │
368
+ │ ├── decisions/ │ kind: pattern │
369
+ │ │ └── use-sqlite-over-pg.md │ kind: <any custom> │
370
+ │ └── patterns/ │ + FTS5 full-text │
371
+ │ └── api-error-handler.md │ + vec0 embeddings │
372
+ ├── entities/ └───────────────────────────────┘
373
+ └── events/
374
+ Human-editable, git-versioned Fast hybrid search, RAG-ready
375
+ You own these files Rebuilt from files anytime
376
+ ```
377
+
378
+ The SQLite database is stored at `~/.context-mcp/vault.db` by default (configurable via `--db-path`, `CONTEXT_VAULT_DB_PATH`, or `config.json`). It contains FTS5 full-text indexes and sqlite-vec embeddings (384-dim float32, all-MiniLM-L6-v2). The database is a derived index — delete it and the server rebuilds it automatically on next session.
379
+
380
+ Requires **Node.js 20** or later.
381
+
382
+ ## Troubleshooting
383
+
384
+ ### Native module build failures
385
+
386
+ `better-sqlite3` and `sqlite-vec` include native C code compiled for your platform. If install fails:
387
+
388
+ ```bash
389
+ npm rebuild better-sqlite3 sqlite-vec
390
+ ```
391
+
392
+ On Apple Silicon Macs, ensure you're running a native ARM Node.js (not Rosetta). Check with `node -p process.arch` — it should say `arm64`.
393
+
394
+ ### Vault directory not found
395
+
396
+ If `context_status` or `get_context` reports the vault directory doesn't exist:
397
+
398
+ ```bash
399
+ context-vault status # Shows resolved paths
400
+ mkdir -p ~/vault # Create the default vault directory
401
+ ```
402
+
403
+ Or re-run `context-vault setup` to reconfigure.
404
+
405
+ ### Embedding model download
406
+
407
+ The embedding model (all-MiniLM-L6-v2, ~22MB) is normally downloaded during `context-vault setup`. If setup was skipped or the cache was cleared, it downloads automatically on first use. If it hangs, check your network or proxy settings.
408
+
409
+ ### Stale search index
410
+
411
+ If search results seem outdated or missing:
412
+
413
+ ```bash
414
+ context-vault reindex
415
+ ```
416
+
417
+ This rebuilds the entire index from your vault files. Auto-reindex runs on every session start, but manual reindex can help diagnose issues.
418
+
419
+ ### Config path debugging
420
+
421
+ ```bash
422
+ context-vault status
423
+ ```
424
+
425
+ Shows all resolved paths (vault dir, data dir, DB path, config file) and where each was resolved from (defaults, config file, env, or CLI args).
426
+
427
+ ## Dependencies
428
+
429
+ | Package | Purpose |
430
+ |---------|---------|
431
+ | `@modelcontextprotocol/sdk` | MCP protocol (McpServer, StdioServerTransport) |
432
+ | `better-sqlite3` | SQLite driver |
433
+ | `sqlite-vec` | Vector search (384-dim float32) |
434
+ | `@huggingface/transformers` | Local embeddings (all-MiniLM-L6-v2, ~22MB) |
435
+
436
+ ## License
437
+
438
+ MIT