shelbymcp 0.1.0

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -0
  3. package/dist/config.d.ts +9 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +35 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/db/database.d.ts +8 -0
  8. package/dist/db/database.d.ts.map +1 -0
  9. package/dist/db/database.js +25 -0
  10. package/dist/db/database.js.map +1 -0
  11. package/dist/db/edges.d.ts +65 -0
  12. package/dist/db/edges.d.ts.map +1 -0
  13. package/dist/db/edges.js +256 -0
  14. package/dist/db/edges.js.map +1 -0
  15. package/dist/db/fts.d.ts +25 -0
  16. package/dist/db/fts.d.ts.map +1 -0
  17. package/dist/db/fts.js +53 -0
  18. package/dist/db/fts.js.map +1 -0
  19. package/dist/db/migrations.d.ts +11 -0
  20. package/dist/db/migrations.d.ts.map +1 -0
  21. package/dist/db/migrations.js +95 -0
  22. package/dist/db/migrations.js.map +1 -0
  23. package/dist/db/thoughts.d.ts +60 -0
  24. package/dist/db/thoughts.d.ts.map +1 -0
  25. package/dist/db/thoughts.js +194 -0
  26. package/dist/db/thoughts.js.map +1 -0
  27. package/dist/db/vectors.d.ts +16 -0
  28. package/dist/db/vectors.d.ts.map +1 -0
  29. package/dist/db/vectors.js +74 -0
  30. package/dist/db/vectors.js.map +1 -0
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +24 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/mcp/server.d.ts +8 -0
  36. package/dist/mcp/server.d.ts.map +1 -0
  37. package/dist/mcp/server.js +229 -0
  38. package/dist/mcp/server.js.map +1 -0
  39. package/dist/tools/capture.d.ts +4 -0
  40. package/dist/tools/capture.d.ts.map +1 -0
  41. package/dist/tools/capture.js +79 -0
  42. package/dist/tools/capture.js.map +1 -0
  43. package/dist/tools/delete.d.ts +4 -0
  44. package/dist/tools/delete.d.ts.map +1 -0
  45. package/dist/tools/delete.js +18 -0
  46. package/dist/tools/delete.js.map +1 -0
  47. package/dist/tools/get.d.ts +4 -0
  48. package/dist/tools/get.d.ts.map +1 -0
  49. package/dist/tools/get.js +19 -0
  50. package/dist/tools/get.js.map +1 -0
  51. package/dist/tools/graph.d.ts +5 -0
  52. package/dist/tools/graph.d.ts.map +1 -0
  53. package/dist/tools/graph.js +55 -0
  54. package/dist/tools/graph.js.map +1 -0
  55. package/dist/tools/helpers.d.ts +12 -0
  56. package/dist/tools/helpers.d.ts.map +1 -0
  57. package/dist/tools/helpers.js +21 -0
  58. package/dist/tools/helpers.js.map +1 -0
  59. package/dist/tools/list.d.ts +4 -0
  60. package/dist/tools/list.d.ts.map +1 -0
  61. package/dist/tools/list.js +18 -0
  62. package/dist/tools/list.js.map +1 -0
  63. package/dist/tools/search.d.ts +4 -0
  64. package/dist/tools/search.d.ts.map +1 -0
  65. package/dist/tools/search.js +73 -0
  66. package/dist/tools/search.js.map +1 -0
  67. package/dist/tools/stats.d.ts +4 -0
  68. package/dist/tools/stats.d.ts.map +1 -0
  69. package/dist/tools/stats.js +34 -0
  70. package/dist/tools/stats.js.map +1 -0
  71. package/dist/tools/update.d.ts +4 -0
  72. package/dist/tools/update.d.ts.map +1 -0
  73. package/dist/tools/update.js +59 -0
  74. package/dist/tools/update.js.map +1 -0
  75. package/package.json +58 -0
  76. package/skills/shelby-forage/SKILL.md +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Studio Moser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,335 @@
1
+ <p align="center">
2
+ <img src="docs/assets/shelby-mcp-header.png" alt="ShelbyMCP" width="720" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <strong>The knowledge-graph memory server for AI tools.</strong><br/>
7
+ Mem0-grade intelligence. Engram-grade simplicity.
8
+ </p>
9
+
10
+ <p align="center">
11
+ <a href="#quick-start"><strong>Quick Start</strong></a> ·
12
+ <a href="docs/ARCHITECTURE.md"><strong>Architecture</strong></a> ·
13
+ <a href="docs/AGENT-SETUP.md"><strong>Agent Setup</strong></a> ·
14
+ <a href="#contributing"><strong>Contributing</strong></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License" /></a>
19
+ <a href="https://github.com/Studio-Moser/shelbymcp/stargazers"><img src="https://img.shields.io/github/stars/Studio-Moser/shelbymcp?style=flat" alt="Stars" /></a>
20
+ </p>
21
+
22
+ ---
23
+
24
+ ## What is ShelbyMCP?
25
+
26
+ Every AI memory server is a bag of embeddings. **ShelbyMCP connects your thoughts.**
27
+
28
+ ShelbyMCP is a zero-dependency MCP memory server with a built-in knowledge graph. It gives Claude Code, Cursor, Codex, Windsurf, and any MCP-compatible AI tool persistent memory that understands how your thoughts are related — not just what they contain.
29
+
30
+ Ship it with the **Forage skill**, a scheduled task that runs on your existing AI subscription to continuously enrich, consolidate, and connect your memories. No Docker. No Python. No cloud accounts. Just a binary and a database file.
31
+
32
+ ### Why ShelbyMCP?
33
+
34
+ | Problem | ShelbyMCP's answer |
35
+ |---|---|
36
+ | Every conversation starts from zero | Persistent memory across sessions |
37
+ | Memories are a flat pile of text | Knowledge graph with typed relationships (refines, cites, refuted_by, tags) |
38
+ | Search results blow up your context window | Pre-computed summaries — search returns one-liners, fetch full content on demand |
39
+ | No memory maintenance | Forage skill auto-consolidates, deduplicates, and connects |
40
+ | Vector search requires heavy infra | Forage skill backfills embeddings using your existing AI subscription |
41
+ | Requires Docker/Python/Cloud | `npx shelbymcp`, single SQLite file |
42
+
43
+ ---
44
+
45
+ ## Quick Start
46
+
47
+ ### Install
48
+
49
+ ```bash
50
+ # npx (no install needed)
51
+ npx shelbymcp
52
+
53
+ # Or install globally
54
+ npm install -g shelbymcp
55
+
56
+ # Or build from source
57
+ git clone https://github.com/Studio-Moser/shelbymcp.git
58
+ cd shelbymcp
59
+ npm install && npm run build
60
+ ```
61
+
62
+ ### Connect to Claude Code
63
+
64
+ Add to your `~/.claude/mcp.json`:
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "memory": {
70
+ "command": "npx",
71
+ "args": ["shelbymcp", "--db", "~/.shelbymcp/memory.db"]
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### (Optional) Install the Forage Skill
78
+
79
+ The Forage skill runs on Claude Code's scheduler to continuously improve your memories:
80
+
81
+ ```bash
82
+ cp -r skills/shelby-forage ~/.claude/scheduled-tasks/shelby-forage
83
+ ```
84
+
85
+ That's it. Your AI now remembers.
86
+
87
+ ---
88
+
89
+ ## How It Works
90
+
91
+ ```
92
+ You (in Claude Code): "We decided to use CloudKit for sync instead of Firebase"
93
+
94
+ Claude Code → capture_thought tool → ShelbyMCP:
95
+ 1. Stores thought in SQLite
96
+ 2. Agent provides metadata (type: decision, topics: [sync, cloud])
97
+ 3. Agent suggests relationships to existing thoughts
98
+ 4. FTS5 indexes content for keyword search
99
+
100
+ Later:
101
+ You: "What did we decide about our sync strategy?"
102
+
103
+ Claude Code → search_thoughts tool → ShelbyMCP:
104
+ 1. FTS5 keyword search for "sync strategy"
105
+ 2. Returns thought + all connected thoughts via knowledge graph
106
+ 3. Agent has full context of decisions, alternatives considered, and related work
107
+ ```
108
+
109
+ ### With the Forage Skill (scheduled, daily):
110
+
111
+ ```
112
+ Forage runs on Claude Code's scheduler:
113
+ 1. Backfills embeddings for thoughts that don't have them
114
+ 2. Re-classifies poorly tagged thoughts
115
+ 3. Finds duplicate thoughts and merges them
116
+ 4. Detects contradictions ("we said PostgreSQL last month but SQLite this week")
117
+ 5. Discovers connections between thoughts across projects
118
+ 6. Sweeps for stale action items that fell through the cracks
119
+ 7. Generates a weekly digest of your thinking
120
+ ```
121
+
122
+ ---
123
+
124
+ ## MCP Tools
125
+
126
+ 9 focused tools — research shows 5-8 tools per server is the sweet spot for agent accuracy.
127
+
128
+ | Tool | Description |
129
+ |---|---|
130
+ | `capture_thought` | Store a thought with summary, metadata, topics, and relationships. Accepts an array for bulk capture. |
131
+ | `search_thoughts` | Full-text search with knowledge graph expansion. Auto-detects FTS5 vs. vector mode. Returns summaries, not full content. |
132
+ | `list_thoughts` | Browse/filter by type, topic, person, project, date range |
133
+ | `get_thought` | Retrieve a specific thought by ID (full content) |
134
+ | `update_thought` | Update content or metadata. Accepts `ids` array for bulk updates. |
135
+ | `delete_thought` | Remove a thought |
136
+ | `manage_edges` | Create or remove typed relationships between thoughts (link, unlink) |
137
+ | `explore_graph` | Traverse the knowledge graph from a starting thought. Depth 1 = direct connections, 2+ = full traversal. |
138
+ | `thought_stats` | Aggregate statistics about your memory |
139
+
140
+ ---
141
+
142
+ ## Knowledge Graph
143
+
144
+ What makes ShelbyMCP different from every other memory server is the knowledge graph. Thoughts aren't isolated — they're connected.
145
+
146
+ ### Edge Types
147
+
148
+ | Edge Type | Meaning | Example |
149
+ |---|---|---|
150
+ | `refines` | A thought that adds detail to another | "Use CloudKit" → "Configure change tokens for sync" |
151
+ | `cites` | A thought that references another as evidence | "Decision doc" → "Performance benchmark results" |
152
+ | `refuted_by` | A thought that contradicts another | "Use Firebase" ← "Switch to CloudKit" |
153
+ | `tags` | A thought that categorizes another | "Architecture" → "CloudKit sync design" |
154
+ | `related` | General association | "Auth system" ↔ "User migration plan" |
155
+ | `follows` | Sequential relationship | "Phase 1 plan" → "Phase 2 plan" |
156
+
157
+ Agents create edges at capture time ("this decision relates to thought X") and the Forage skill discovers additional connections over time.
158
+
159
+ ---
160
+
161
+ ## The Forage Skill
162
+
163
+ ShelbyMCP ships with `shelby-forage`, a scheduled skill that runs on your existing AI subscription (Claude Code, Codex, etc.) to continuously improve your memory. The server stays zero-dependency — the intelligence comes from tools you're already paying for.
164
+
165
+ | Task | Frequency | What it does |
166
+ |---|---|---|
167
+ | **Embed backfill** | Daily | Generate embeddings for thoughts that don't have them |
168
+ | **Auto-classify** | Daily | Re-scan poorly tagged thoughts, improve metadata |
169
+ | **Consolidation** | Daily | Find duplicate/similar thoughts, merge into rich summaries |
170
+ | **Contradiction detection** | Daily | Flag conflicting memories for user resolution |
171
+ | **Connection discovery** | Daily | Find related thoughts, create knowledge graph edges |
172
+ | **Stale sweep** | Weekly | Flag old action items that fell through the cracks |
173
+ | **Digest** | Weekly | Generate a summary of the week's thinking |
174
+
175
+ ### Install
176
+
177
+ ```bash
178
+ cp -r skills/shelby-forage ~/.claude/scheduled-tasks/shelby-forage
179
+ ```
180
+
181
+ The skill runs daily by default. Edit the SKILL.md frontmatter to adjust the schedule.
182
+
183
+ ### Without the Forage Skill
184
+
185
+ ShelbyMCP works fine without it — you get persistent storage, FTS5 search, and knowledge graph. The Forage skill adds the intelligence layer that makes memories smarter over time. Think of it as optional but recommended.
186
+
187
+ ---
188
+
189
+ ## Agent Setup
190
+
191
+ ShelbyMCP works with any MCP-compatible AI tool. See [docs/AGENT-SETUP.md](docs/AGENT-SETUP.md) for setup guides:
192
+
193
+ - Claude Code
194
+ - Cursor
195
+ - Codex
196
+ - Windsurf
197
+ - Gemini CLI
198
+ - OpenCode
199
+ - Any MCP-compatible client
200
+
201
+ ---
202
+
203
+ ## Architecture
204
+
205
+ ShelbyMCP is a single binary that communicates via MCP (stdio JSON-RPC) and stores everything in a single SQLite file.
206
+
207
+ ```
208
+ AI Tool (Claude Code, Cursor, etc.)
209
+
210
+ │ MCP (stdio JSON-RPC)
211
+
212
+
213
+ ┌──────────────────────┐
214
+ │ ShelbyMCP │
215
+ │ │
216
+ │ ┌──────────────────┐ │
217
+ │ │ MCP Protocol │ │ ← JSON-RPC request/response
218
+ │ │ (stdio) │ │
219
+ │ └────────┬─────────┘ │
220
+ │ │ │
221
+ │ ┌────────▼─────────┐ │
222
+ │ │ Tool Router │ │ ← Routes to capture/search/link/etc.
223
+ │ └────────┬─────────┘ │
224
+ │ │ │
225
+ │ ┌────────▼─────────┐ │
226
+ │ │ SQLite DB │ │
227
+ │ │ ┌─────────────┐ │ │
228
+ │ │ │ thoughts │ │ │ ← Content, metadata, embeddings
229
+ │ │ │ thought_fts │ │ │ ← FTS5 full-text index
230
+ │ │ │ edges │ │ │ ← Knowledge graph relationships
231
+ │ │ └─────────────┘ │ │
232
+ │ └──────────────────┘ │
233
+ └──────────────────────┘
234
+
235
+
236
+ ~/.shelbymcp/memory.db (single file)
237
+ ```
238
+
239
+ See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full technical design.
240
+
241
+ ---
242
+
243
+ ## Comparison
244
+
245
+ | | ShelbyMCP | Engram | Mem0 | Basic Memory | Cipher |
246
+ |---|---|---|---|---|---|
247
+ | **Dependencies** | Zero | Zero | Docker+Qdrant+Neo4j | Python+pip | Node.js |
248
+ | **Storage** | SQLite | SQLite | Qdrant+Neo4j+SQLite | Markdown+SQLite | Files |
249
+ | **Knowledge graph** | Native (typed edges) | No | Neo4j (separate service) | Derived from Markdown | No |
250
+ | **Full-text search** | FTS5 | FTS5 | Limited | FTS5 | No |
251
+ | **Vector search** | Via Forage skill | No | Built-in | Optional | No |
252
+ | **Memory maintenance** | Forage skill (daily) | No | Built-in | No | No |
253
+ | **Contradiction detection** | Forage skill | No | No | No | No |
254
+ | **Zero-install** | `npx shelbymcp` | `go install` | No | `pip install` | `npm install` |
255
+ | **Single file DB** | Yes | Yes | No | No (Markdown files) | No |
256
+
257
+ ---
258
+
259
+ ## Part of the Shelby Ecosystem
260
+
261
+ ShelbyMCP is the open-source memory server. **Shelby for Mac** (coming soon) is the native macOS app that adds:
262
+
263
+ - Always-on embedding pipeline (no scheduled skill needed)
264
+ - Instant auto-classification at capture time
265
+ - Semantic vector search
266
+ - CloudKit sync across all your Macs
267
+ - Heartbeat system (Pulse / Tidyup / Forage)
268
+ - Native menu bar + global hotkey quick capture
269
+ - Extension discovery and management
270
+
271
+ ShelbyMCP and Shelby for Mac use the same SQLite database. Start with the MCP server, upgrade to the Mac app when you want more.
272
+
273
+ ---
274
+
275
+ ## Design Principles for Contributors
276
+
277
+ These are non-negotiable. They exist because MCP servers directly impact token costs for every user on every message.
278
+
279
+ 1. **Tool descriptions MUST be static.** Tool definitions become part of the agent's system prompt and are sent on every message. Dynamic data (counts, timestamps, user-specific info) in descriptions breaks prompt caching — costing 10x more tokens. Put dynamic data in tool *responses*, not descriptions. See [Architecture: Token Efficiency Patterns](docs/ARCHITECTURE.md#token-efficiency-patterns).
280
+
281
+ 2. **Search returns summaries, not full content.** A search hitting 20 thoughts at 2,000 words each = 40K wasted tokens. Search results return the agent-provided `summary` field (one line). The agent calls `get_thought` for full content when it needs it.
282
+
283
+ 3. **All list/search tools have a `limit` parameter.** Default 20, max 100. Responses include `total_count` and `has_more`. No unbounded queries.
284
+
285
+ 4. **The server runs zero inference.** Agents provide metadata (type, topics, summary, relationships) at capture time. The Forage skill handles enrichment. The server is pure storage + retrieval.
286
+
287
+ 5. **All logging to stderr.** `console.error` only. stdout is the MCP JSON-RPC channel. A single `console.log` breaks everything.
288
+
289
+ 6. **Keep the tool count focused.** 9 tools. Research (Block, Phil Schmid, Docker) shows 5-8 per server is optimal. Consolidate related operations into single tools with action parameters.
290
+
291
+ 7. **Errors are instructions.** Return `isError: true` with actionable messages. "Not found" is useless. "No thought with ID abc123. Try search_thoughts to find it by content." helps the agent self-correct.
292
+
293
+ 8. **Every tool gets annotations.** MCP spec annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) on every registered tool. See [Architecture: Tool Annotations](docs/ARCHITECTURE.md#tool-annotations).
294
+
295
+ ---
296
+
297
+ ## Development
298
+
299
+ ```bash
300
+ # Install dependencies
301
+ npm install
302
+
303
+ # Build
304
+ npm run build
305
+
306
+ # Run tests
307
+ npm test
308
+
309
+ # Run in development
310
+ npm run dev -- --db ./test.db --verbose
311
+ ```
312
+
313
+ See [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) for the full development guide.
314
+
315
+ ---
316
+
317
+ ## Contributing
318
+
319
+ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for the workflow.
320
+
321
+ - **Issues first** — Open an issue before starting work
322
+ - **PRs welcome** — Bug fixes, new MCP tools, documentation improvements
323
+ - **Forage tasks** — Propose new Forage skill tasks for memory enrichment
324
+
325
+ ---
326
+
327
+ ## License
328
+
329
+ MIT - see [LICENSE](LICENSE) for details.
330
+
331
+ ---
332
+
333
+ <p align="center">
334
+ <sub>Built by <a href="https://github.com/Studio-Moser">Studio Moser</a>. Your AI deserves a memory that connects the dots.</sub>
335
+ </p>
@@ -0,0 +1,9 @@
1
+ export interface ShelbyConfig {
2
+ dbPath: string;
3
+ verbose: boolean;
4
+ logFile: string | null;
5
+ }
6
+ export declare function parseArgs(argv: string[]): ShelbyConfig | "version";
7
+ export declare function getDefaultDbPath(): string;
8
+ export declare function getDefaultDbDir(): string;
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAKD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,SAAS,CAyBlE;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
package/dist/config.js ADDED
@@ -0,0 +1,35 @@
1
+ import { resolve } from "node:path";
2
+ import { homedir } from "node:os";
3
+ const DEFAULT_DB_DIR = resolve(homedir(), ".shelbymcp");
4
+ const DEFAULT_DB_PATH = resolve(DEFAULT_DB_DIR, "memory.db");
5
+ export function parseArgs(argv) {
6
+ const config = {
7
+ dbPath: DEFAULT_DB_PATH,
8
+ verbose: false,
9
+ logFile: null,
10
+ };
11
+ for (let i = 0; i < argv.length; i++) {
12
+ const arg = argv[i];
13
+ switch (arg) {
14
+ case "--db":
15
+ config.dbPath = resolve(argv[++i] ?? DEFAULT_DB_PATH);
16
+ break;
17
+ case "--verbose":
18
+ config.verbose = true;
19
+ break;
20
+ case "--log-file":
21
+ config.logFile = resolve(argv[++i] ?? "");
22
+ break;
23
+ case "--version":
24
+ return "version";
25
+ }
26
+ }
27
+ return config;
28
+ }
29
+ export function getDefaultDbPath() {
30
+ return DEFAULT_DB_PATH;
31
+ }
32
+ export function getDefaultDbDir() {
33
+ return DEFAULT_DB_DIR;
34
+ }
35
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAQlC,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AACxD,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;AAE7D,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,MAAM,GAAiB;QAC3B,MAAM,EAAE,eAAe;QACvB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,IAAI;KACd,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,QAAQ,GAAG,EAAE,CAAC;YACZ,KAAK,MAAM;gBACT,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC;gBACtD,MAAM;YACR,KAAK,WAAW;gBACd,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;gBACtB,MAAM;YACR,KAAK,YAAY;gBACf,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC1C,MAAM;YACR,KAAK,WAAW;gBACd,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import Database from "better-sqlite3";
2
+ export declare class ThoughtDatabase {
3
+ readonly db: Database.Database;
4
+ constructor(dbPath: string);
5
+ getSchemaVersion(): number;
6
+ close(): void;
7
+ }
8
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAKtC,qBAAa,eAAe;IAC1B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;gBAEnB,MAAM,EAAE,MAAM;IAc1B,gBAAgB,IAAI,MAAM;IAI1B,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,25 @@
1
+ import Database from "better-sqlite3";
2
+ import { mkdirSync } from "node:fs";
3
+ import { dirname } from "node:path";
4
+ import { runMigrations, getSchemaVersion } from "./migrations.js";
5
+ export class ThoughtDatabase {
6
+ db;
7
+ constructor(dbPath) {
8
+ if (dbPath !== ":memory:") {
9
+ mkdirSync(dirname(dbPath), { recursive: true });
10
+ }
11
+ this.db = new Database(dbPath);
12
+ if (dbPath !== ":memory:") {
13
+ this.db.pragma("journal_mode = WAL");
14
+ }
15
+ this.db.pragma("foreign_keys = ON");
16
+ runMigrations(this.db);
17
+ }
18
+ getSchemaVersion() {
19
+ return getSchemaVersion(this.db);
20
+ }
21
+ close() {
22
+ this.db.close();
23
+ }
24
+ }
25
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,OAAO,eAAe;IACjB,EAAE,CAAoB;IAE/B,YAAY,MAAc;QACxB,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;YAC1B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAEpC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,gBAAgB;QACd,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,65 @@
1
+ import type { ThoughtDatabase } from "./database.js";
2
+ export declare const VALID_EDGE_TYPES: readonly ["refines", "cites", "refuted_by", "tags", "related", "follows"];
3
+ export type EdgeType = (typeof VALID_EDGE_TYPES)[number];
4
+ export interface EdgeInput {
5
+ source_id: string;
6
+ target_id: string;
7
+ edge_type: string;
8
+ metadata?: Record<string, unknown>;
9
+ }
10
+ export interface EdgeRecord {
11
+ id: string;
12
+ source_id: string;
13
+ target_id: string;
14
+ edge_type: string;
15
+ metadata: Record<string, unknown> | null;
16
+ created_at: string;
17
+ }
18
+ export interface ConnectedThought {
19
+ thought_id: string;
20
+ summary: string | null;
21
+ type: string;
22
+ edge_id: string;
23
+ edge_type: string;
24
+ direction: "outgoing" | "incoming";
25
+ }
26
+ export interface GraphNode {
27
+ id: string;
28
+ summary: string | null;
29
+ type: string;
30
+ depth: number;
31
+ edges: Array<{
32
+ edge_id: string;
33
+ edge_type: string;
34
+ connected_to: string;
35
+ direction: "outgoing" | "incoming";
36
+ }>;
37
+ }
38
+ /**
39
+ * Create an edge between two thoughts. Returns the new edge's UUID.
40
+ * Throws if source or target don't exist, or if a duplicate edge exists.
41
+ */
42
+ export declare function linkThoughts(db: ThoughtDatabase, input: EdgeInput): string;
43
+ /**
44
+ * Remove an edge between two thoughts. Returns true if an edge was deleted.
45
+ */
46
+ export declare function unlinkThoughts(db: ThoughtDatabase, source_id: string, target_id: string, edge_type: string): boolean;
47
+ /**
48
+ * Get a single edge by ID.
49
+ */
50
+ export declare function getEdge(db: ThoughtDatabase, id: string): EdgeRecord | null;
51
+ /**
52
+ * Get all edges between two specific thoughts (any type).
53
+ */
54
+ export declare function getEdgesBetween(db: ThoughtDatabase, source_id: string, target_id: string): EdgeRecord[];
55
+ /**
56
+ * Get direct connections for a thought (both outgoing and incoming).
57
+ * Optionally filter by edge types.
58
+ */
59
+ export declare function getConnections(db: ThoughtDatabase, thought_id: string, edge_types?: string[]): ConnectedThought[];
60
+ /**
61
+ * BFS traversal from a starting thought up to max_depth (capped at 5).
62
+ * Returns all discovered nodes with their depth and edges.
63
+ */
64
+ export declare function traverseGraph(db: ThoughtDatabase, thought_id: string, max_depth: number, edge_types?: string[]): GraphNode[];
65
+ //# sourceMappingURL=edges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edges.d.ts","sourceRoot":"","sources":["../../src/db/edges.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD,eAAO,MAAM,gBAAgB,2EAOnB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;CACpC;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;KACpC,CAAC,CAAC;CACJ;AA0BD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CA8C1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,MAAM,GACT,UAAU,GAAG,IAAI,CAMnB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,UAAU,EAAE,CAQd;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,gBAAgB,EAAE,CAuDpB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,SAAS,EAAE,CAwHb"}