Persistent project knowledge graph for coding agents. MCP server with semantic search, in-process embeddings, and web explorer.
TypeScript agentic-codingaiai-agentsclaude-codecode-contextcoding-agentembeddingsknowledge-graphllmmcpmcp-serveropencodepersistent-memorysqlitetypescript
Replace better-sqlite3 with libsql for zero-compilation installs
0xk3vin1c73158b7540
diff --git a/.gitignore b/.gitignoreindex a18603a..c30c411 100644--- a/.gitignore+++ b/.gitignore@@ -6,3 +6,4 @@ dist/*.tgz*.log.env*+.osgrepdiff --git a/README.md b/README.mdindex 7f7a636..a07ba0b 100644--- a/README.md+++ b/README.md@@ -128,7 +128,7 @@ megamemory serve --port 8080 # custom portsrc/index.ts CLI entry + MCP servertools.ts Tool handlers (understand, create, update, link, remove)- db.ts SQLite persistence (better-sqlite3, WAL mode)+ db.ts SQLite persistence (libsql, WAL mode)embeddings.ts In-process embeddings (all-MiniLM-L6-v2, 384 dims)types.ts TypeScript typescli-utils.ts Colored output + interactive promptsdiff --git a/package-lock.json b/package-lock.jsonindex faafbab..f34245e 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,17 +1,17 @@{"name": "megamemory",- "version": "1.0.1",+ "version": "1.1.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "megamemory",- "version": "1.0.1",+ "version": "1.1.0","license": "MIT","dependencies": {"@modelcontextprotocol/sdk": "^1.12.1","@xenova/transformers": "^2.17.2",- "better-sqlite3": "^11.7.0",+ "libsql": "^0.5.22","picocolors": "^1.1.1","zod": "^3.24.2"},@@ -19,7 +19,6 @@"megamemory": "dist/index.js"},"devDependencies": {- "@types/better-sqlite3": "^7.6.12","@types/node": "^20.17.14","tsx": "^4.19.2","typescript": "^5.7.3",@@ -499,6 +498,123 @@"dev": true,"license": "MIT"},+ "node_modules/@libsql/darwin-arm64": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/darwin-arm64/-/darwin-arm64-0.5.22.tgz",+ "integrity": "sha512-4B8ZlX3nIDPndfct7GNe0nI3Yw6ibocEicWdC4fvQbSs/jdq/RC2oCsoJxJ4NzXkvktX70C1J4FcmmoBy069UA==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@libsql/darwin-x64": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/darwin-x64/-/darwin-x64-0.5.22.tgz",+ "integrity": "sha512-ny2HYWt6lFSIdNFzUFIJ04uiW6finXfMNJ7wypkAD8Pqdm6nAByO+Fdqu8t7sD0sqJGeUCiOg480icjyQ2/8VA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@libsql/linux-arm-gnueabihf": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-arm-gnueabihf/-/linux-arm-gnueabihf-0.5.22.tgz",+ "integrity": "sha512-3Uo3SoDPJe/zBnyZKosziRGtszXaEtv57raWrZIahtQDsjxBVjuzYQinCm9LRCJCUT5t2r5Z5nLDPJi2CwZVoA==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/linux-arm-musleabihf": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-arm-musleabihf/-/linux-arm-musleabihf-0.5.22.tgz",+ "integrity": "sha512-LCsXh07jvSojTNJptT9CowOzwITznD+YFGGW+1XxUr7fS+7/ydUrpDfsMX7UqTqjm7xG17eq86VkWJgHJfvpNg==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/linux-arm64-gnu": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.5.22.tgz",+ "integrity": "sha512-KSdnOMy88c9mpOFKUEzPskSaF3VLflfSUCBwas/pn1/sV3pEhtMF6H8VUCd2rsedwoukeeCSEONqX7LLnQwRMA==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/linux-arm64-musl": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.5.22.tgz",+ "integrity": "sha512-mCHSMAsDTLK5YH//lcV3eFEgiR23Ym0U9oEvgZA0667gqRZg/2px+7LshDvErEKv2XZ8ixzw3p1IrBzLQHGSsw==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/linux-x64-gnu": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.5.22.tgz",+ "integrity": "sha512-kNBHaIkSg78Y4BqAdgjcR2mBilZXs4HYkAmi58J+4GRwDQZh5fIUWbnQvB9f95DkWUIGVeenqLRFY2pcTmlsew==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/linux-x64-musl": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/linux-x64-musl/-/linux-x64-musl-0.5.22.tgz",+ "integrity": "sha512-UZ4Xdxm4pu3pQXjvfJiyCzZop/9j/eA2JjmhMaAhe3EVLH2g11Fy4fwyUp9sT1QJYR1kpc2JLuybPM0kuXv/Tg==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@libsql/win32-x64-msvc": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.5.22.tgz",+ "integrity": "sha512-Fj0j8RnBpo43tVZUVoNK6BV/9AtDUM5S7DF3LB4qTYg1LMSZqi3yeCneUTLJD6XomQJlZzbI4mst89yspVSAnA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ]+ },"node_modules/@modelcontextprotocol/sdk": {"version": "1.26.0","resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.26.0.tgz",@@ -539,6 +655,12 @@}}},+ "node_modules/@neon-rs/load": {+ "version": "0.0.4",+ "resolved": "https://registry.npmjs.org/@neon-rs/load/-/load-0.0.4.tgz",+ "integrity": "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw==",+ "license": "MIT"+ },"node_modules/@protobufjs/aspromise": {"version": "1.1.2","resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",@@ -960,16 +1082,6 @@"dev": true,"license": "MIT"},- "node_modules/@types/better-sqlite3": {- "version": "7.6.13",- "resolved": "https://registry.npmjs.org/@types/better-sqlite3/-/better-sqlite3-7.6.13.tgz",- "integrity": "sha512-NMv9ASNARoKksWtsq/SHakpYAYnhBrQgGD8zkLYk/jaK8jUGn08CfEdTRgYhMypUQAfzSP8W6gNLe0q19/t4VA==",- "dev": true,- "license": "MIT",- "dependencies": {- "@types/node": "*"- }- },"node_modules/@types/chai": {"version": "5.2.3","resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",@@ -1316,26 +1428,6 @@],"license": "MIT"},- "node_modules/better-sqlite3": {- "version": "11.10.0",- "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.10.0.tgz",- "integrity": "sha512-EwhOpyXiOEL/lKzHz9AW1msWFNzGc/z+LzeB3/jnFJpxu+th2yqvzsSWas1v9jgs9+xiXJcD5A8CJxAG2TaghQ==",- "hasInstallScript": true,- "license": "MIT",- "dependencies": {- "bindings": "^1.5.0",- "prebuild-install": "^7.1.1"- }- },- "node_modules/bindings": {- "version": "1.5.0",- "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",- "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",- "license": "MIT",- "dependencies": {- "file-uri-to-path": "1.0.0"- }- },"node_modules/bl": {"version": "4.1.0","resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",@@ -1612,9 +1704,9 @@}},"node_modules/detect-libc": {- "version": "2.1.2",- "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",- "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",+ "version": "2.0.2",+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz",+ "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==","license": "Apache-2.0","engines": {"node": ">=8"@@ -1918,12 +2010,6 @@}}},- "node_modules/file-uri-to-path": {- "version": "1.0.0",- "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",- "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",- "license": "MIT"- },"node_modules/finalhandler": {"version": "2.1.1","resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",@@ -2037,9 +2123,9 @@}},"node_modules/get-tsconfig": {- "version": "4.13.3",- "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.3.tgz",- "integrity": "sha512-vp8Cj/+9Q/ibZUrq1rhy8mCTQpCk31A3uu9wc1C50yAb3x2pFHOsGdAZQ7jD86ARayyxZUViYeIztW+GE8dcrg==",+ "version": "4.13.6",+ "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.6.tgz",+ "integrity": "sha512-shZT/QMiSHc/YBLxxOkMtgSid5HFoauqCE3/exfsEcwg1WkeqjG+V40yBbBrsD+jW2HDXcs28xOfcbm2jI8Ddw==","dev": true,"license": "MIT","dependencies": {@@ -2098,9 +2184,9 @@}},"node_modules/hono": {- "version": "4.11.7",- "resolved": "https://registry.npmjs.org/hono/-/hono-4.11.7.tgz",- "integrity": "sha512-l7qMiNee7t82bH3SeyUCt9UF15EVmaBvsppY2zQtrbIhl/yzBTny+YUxsVjSjQ6gaqaeVtZmGocom8TzBlA4Yw==",+ "version": "4.11.8",+ "resolved": "https://registry.npmjs.org/hono/-/hono-4.11.8.tgz",+ "integrity": "sha512-eVkB/CYCCei7K2WElZW9yYQFWssG0DhaDhVvr7wy5jJ22K+ck8fWW0EsLpB0sITUTvPnc97+rrbQqIr5iqiy9Q==","license": "MIT","engines": {"node": ">=16.9.0"@@ -2231,6 +2317,38 @@"integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==","license": "BSD-2-Clause"},+ "node_modules/libsql": {+ "version": "0.5.22",+ "resolved": "https://registry.npmjs.org/libsql/-/libsql-0.5.22.tgz",+ "integrity": "sha512-NscWthMQt7fpU8lqd7LXMvT9pi+KhhmTHAJWUB/Lj6MWa0MKFv0F2V4C6WKKpjCVZl0VwcDz4nOI3CyaT1DDiA==",+ "cpu": [+ "x64",+ "arm64",+ "wasm32",+ "arm"+ ],+ "license": "MIT",+ "os": [+ "darwin",+ "linux",+ "win32"+ ],+ "dependencies": {+ "@neon-rs/load": "^0.0.4",+ "detect-libc": "2.0.2"+ },+ "optionalDependencies": {+ "@libsql/darwin-arm64": "0.5.22",+ "@libsql/darwin-x64": "0.5.22",+ "@libsql/linux-arm-gnueabihf": "0.5.22",+ "@libsql/linux-arm-musleabihf": "0.5.22",+ "@libsql/linux-arm64-gnu": "0.5.22",+ "@libsql/linux-arm64-musl": "0.5.22",+ "@libsql/linux-x64-gnu": "0.5.22",+ "@libsql/linux-x64-musl": "0.5.22",+ "@libsql/win32-x64-msvc": "0.5.22"+ }+ },"node_modules/long": {"version": "4.0.0","resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",@@ -2608,6 +2726,34 @@"node": ">=10"}},+ "node_modules/prebuild-install/node_modules/tar-fs": {+ "version": "2.1.4",+ "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz",+ "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==",+ "license": "MIT",+ "dependencies": {+ "chownr": "^1.1.1",+ "mkdirp-classic": "^0.5.2",+ "pump": "^3.0.0",+ "tar-stream": "^2.1.4"+ }+ },+ "node_modules/prebuild-install/node_modules/tar-stream": {+ "version": "2.2.0",+ "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",+ "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",+ "license": "MIT",+ "dependencies": {+ "bl": "^4.0.3",+ "end-of-stream": "^1.4.1",+ "fs-constants": "^1.0.0",+ "inherits": "^2.0.3",+ "readable-stream": "^3.1.1"+ },+ "engines": {+ "node": ">=6"+ }+ },"node_modules/protobufjs": {"version": "6.11.4","resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.4.tgz",@@ -2917,31 +3063,6 @@"url": "https://opencollective.com/libvips"}},- "node_modules/sharp/node_modules/tar-fs": {- "version": "3.1.1",- "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.1.tgz",- "integrity": "sha512-LZA0oaPOc2fVo82Txf3gw+AkEd38szODlptMYejQUhndHMLQ9M059uXR+AfS7DNo0NpINvSqDsvyaCrBVkptWg==",- "license": "MIT",- "dependencies": {- "pump": "^3.0.0",- "tar-stream": "^3.1.5"- },- "optionalDependencies": {- "bare-fs": "^4.0.1",- "bare-path": "^3.0.0"- }- },- "node_modules/sharp/node_modules/tar-stream": {- "version": "3.1.7",- "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.7.tgz",- "integrity": "sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==",- "license": "MIT",- "dependencies": {- "b4a": "^1.6.4",- "fast-fifo": "^1.2.0",- "streamx": "^2.15.0"- }- },"node_modules/shebang-command": {"version": "2.0.0","resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",@@ -3159,31 +3280,28 @@}},"node_modules/tar-fs": {- "version": "2.1.4",- "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz",- "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==",+ "version": "3.1.1",+ "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.1.tgz",+ "integrity": "sha512-LZA0oaPOc2fVo82Txf3gw+AkEd38szODlptMYejQUhndHMLQ9M059uXR+AfS7DNo0NpINvSqDsvyaCrBVkptWg==","license": "MIT","dependencies": {- "chownr": "^1.1.1",- "mkdirp-classic": "^0.5.2","pump": "^3.0.0",- "tar-stream": "^2.1.4"+ "tar-stream": "^3.1.5"+ },+ "optionalDependencies": {+ "bare-fs": "^4.0.1",+ "bare-path": "^3.0.0"}},"node_modules/tar-stream": {- "version": "2.2.0",- "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",- "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",+ "version": "3.1.7",+ "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.7.tgz",+ "integrity": "sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==","license": "MIT","dependencies": {- "bl": "^4.0.3",- "end-of-stream": "^1.4.1",- "fs-constants": "^1.0.0",- "inherits": "^2.0.3",- "readable-stream": "^3.1.1"- },- "engines": {- "node": ">=6"+ "b4a": "^1.6.4",+ "fast-fifo": "^1.2.0",+ "streamx": "^2.15.0"}},"node_modules/text-decoder": {diff --git a/package.json b/package.jsonindex af4ffe8..c26dd28 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "megamemory",- "version": "1.0.1",+ "version": "1.1.0","description": "MCP server that gives coding agents persistent project understanding via a knowledge graph","type": "module","main": "dist/index.js",@@ -47,12 +47,11 @@"dependencies": {"@modelcontextprotocol/sdk": "^1.12.1","@xenova/transformers": "^2.17.2",- "better-sqlite3": "^11.7.0",+ "libsql": "^0.5.22","picocolors": "^1.1.1","zod": "^3.24.2"},"devDependencies": {- "@types/better-sqlite3": "^7.6.12","@types/node": "^20.17.14","tsx": "^4.19.2","typescript": "^5.7.3",diff --git a/src/db.ts b/src/db.tsindex 8bf7772..0e5a4ec 100644--- a/src/db.ts+++ b/src/db.ts@@ -1,4 +1,4 @@-import Database from "better-sqlite3";+import Database from "libsql";import path from "path";import fs from "fs";import type { NodeRow, EdgeRow } from "./types.js";@@ -22,7 +22,13 @@ export class KnowledgeDB {}private migrate(): void {- const version = this.db.pragma("user_version", { simple: true }) as number;+ const pragmaResult = this.db.pragma("user_version", { simple: true });+ // libsql returns { user_version: N } instead of raw N like better-sqlite3+ const version = (+ typeof pragmaResult === "object" && pragmaResult !== null+ ? (pragmaResult as Record<string, unknown>).user_version+ : pragmaResult+ ) as number;if (version < 1) {this.db.exec(`