@saluzi/codegraph 0.1.0 → 0.2.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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/package.json +42 -10
  4. package/scripts/add-lang/bench.sh +60 -0
  5. package/scripts/add-lang/check-grammar.mjs +75 -0
  6. package/scripts/add-lang/dump-ast.mjs +103 -0
  7. package/scripts/add-lang/verify-extraction.mjs +70 -0
  8. package/scripts/agent-eval/ab-adoption.sh +91 -0
  9. package/scripts/agent-eval/ab-hook.sh +86 -0
  10. package/scripts/agent-eval/ab-impl.sh +78 -0
  11. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  12. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  13. package/scripts/agent-eval/arms-F.sh +21 -0
  14. package/scripts/agent-eval/arms-matrix.sh +37 -0
  15. package/scripts/agent-eval/audit.sh +68 -0
  16. package/scripts/agent-eval/bench-readme.sh +28 -0
  17. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  18. package/scripts/agent-eval/block-read-hook.sh +19 -0
  19. package/scripts/agent-eval/hook-settings.json +15 -0
  20. package/scripts/agent-eval/itrun.sh +120 -0
  21. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  22. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  23. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  24. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  25. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  26. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  27. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  28. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  29. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  30. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  31. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  32. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  33. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  34. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  35. package/scripts/agent-eval/offload-eval.md +76 -0
  36. package/scripts/agent-eval/parse-arms.mjs +116 -0
  37. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  38. package/scripts/agent-eval/parse-run.mjs +45 -0
  39. package/scripts/agent-eval/parse-session.mjs +93 -0
  40. package/scripts/agent-eval/probe-context.mjs +21 -0
  41. package/scripts/agent-eval/probe-explore.mjs +40 -0
  42. package/scripts/agent-eval/probe-node.mjs +20 -0
  43. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  44. package/scripts/agent-eval/probe-trace.mjs +20 -0
  45. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  46. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  47. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  48. package/scripts/agent-eval/run-agent.sh +34 -0
  49. package/scripts/agent-eval/run-all.sh +75 -0
  50. package/scripts/agent-eval/run-arms.sh +56 -0
  51. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  52. package/scripts/build-bundle.sh +123 -0
  53. package/scripts/extract-release-notes.mjs +130 -0
  54. package/scripts/local-install.sh +41 -0
  55. package/scripts/npm-sdk.js +75 -0
  56. package/scripts/npm-shim.js +275 -0
  57. package/scripts/pack-npm.sh +119 -0
  58. package/scripts/prepare-release.mjs +270 -0
  59. package/dist/bin/codegraph.d.ts +0 -25
  60. package/dist/bin/node-version-check.d.ts +0 -37
  61. package/dist/bin/uninstall.d.ts +0 -14
  62. package/dist/context/formatter.d.ts +0 -33
  63. package/dist/context/formatter.js +0 -244
  64. package/dist/context/index.d.ts +0 -117
  65. package/dist/context/index.js +0 -1050
  66. package/dist/db/index.d.ts +0 -101
  67. package/dist/db/index.js +0 -250
  68. package/dist/db/migrations.d.ts +0 -47
  69. package/dist/db/migrations.js +0 -131
  70. package/dist/db/queries.d.ts +0 -291
  71. package/dist/db/queries.js +0 -1349
  72. package/dist/db/schema.sql +0 -151
  73. package/dist/db/sqlite-adapter.d.ts +0 -49
  74. package/dist/db/sqlite-adapter.js +0 -141
  75. package/dist/directory.d.ts +0 -62
  76. package/dist/directory.js +0 -264
  77. package/dist/errors.d.ts +0 -149
  78. package/dist/errors.js +0 -219
  79. package/dist/extraction/dfm-extractor.d.ts +0 -31
  80. package/dist/extraction/dfm-extractor.js +0 -151
  81. package/dist/extraction/grammars.d.ts +0 -94
  82. package/dist/extraction/grammars.js +0 -357
  83. package/dist/extraction/index.d.ts +0 -148
  84. package/dist/extraction/index.js +0 -1286
  85. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  86. package/dist/extraction/languages/c-cpp.js +0 -126
  87. package/dist/extraction/languages/csharp.d.ts +0 -3
  88. package/dist/extraction/languages/csharp.js +0 -72
  89. package/dist/extraction/languages/dart.d.ts +0 -3
  90. package/dist/extraction/languages/dart.js +0 -192
  91. package/dist/extraction/languages/go.d.ts +0 -3
  92. package/dist/extraction/languages/go.js +0 -58
  93. package/dist/extraction/languages/index.d.ts +0 -10
  94. package/dist/extraction/languages/index.js +0 -49
  95. package/dist/extraction/languages/java.d.ts +0 -3
  96. package/dist/extraction/languages/java.js +0 -64
  97. package/dist/extraction/languages/javascript.d.ts +0 -3
  98. package/dist/extraction/languages/javascript.js +0 -90
  99. package/dist/extraction/languages/kotlin.d.ts +0 -3
  100. package/dist/extraction/languages/kotlin.js +0 -253
  101. package/dist/extraction/languages/lua.d.ts +0 -3
  102. package/dist/extraction/languages/lua.js +0 -150
  103. package/dist/extraction/languages/luau.d.ts +0 -3
  104. package/dist/extraction/languages/luau.js +0 -37
  105. package/dist/extraction/languages/pascal.d.ts +0 -3
  106. package/dist/extraction/languages/pascal.js +0 -66
  107. package/dist/extraction/languages/php.d.ts +0 -3
  108. package/dist/extraction/languages/php.js +0 -107
  109. package/dist/extraction/languages/python.d.ts +0 -3
  110. package/dist/extraction/languages/python.js +0 -56
  111. package/dist/extraction/languages/ruby.d.ts +0 -3
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/rust.d.ts +0 -3
  114. package/dist/extraction/languages/rust.js +0 -109
  115. package/dist/extraction/languages/scala.d.ts +0 -3
  116. package/dist/extraction/languages/scala.js +0 -139
  117. package/dist/extraction/languages/swift.d.ts +0 -3
  118. package/dist/extraction/languages/swift.js +0 -91
  119. package/dist/extraction/languages/typescript.d.ts +0 -3
  120. package/dist/extraction/languages/typescript.js +0 -129
  121. package/dist/extraction/liquid-extractor.d.ts +0 -52
  122. package/dist/extraction/liquid-extractor.js +0 -313
  123. package/dist/extraction/parse-worker.d.ts +0 -8
  124. package/dist/extraction/parse-worker.js +0 -94
  125. package/dist/extraction/svelte-extractor.d.ts +0 -56
  126. package/dist/extraction/svelte-extractor.js +0 -272
  127. package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
  128. package/dist/extraction/tree-sitter-helpers.js +0 -103
  129. package/dist/extraction/tree-sitter-types.d.ts +0 -191
  130. package/dist/extraction/tree-sitter-types.js +0 -10
  131. package/dist/extraction/tree-sitter.d.ts +0 -238
  132. package/dist/extraction/tree-sitter.js +0 -2430
  133. package/dist/extraction/vue-extractor.d.ts +0 -36
  134. package/dist/extraction/vue-extractor.js +0 -163
  135. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  136. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  137. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  138. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  139. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  140. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  141. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  142. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  143. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  144. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  145. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  146. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  147. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  148. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  149. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  150. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  151. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  152. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  153. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  154. package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
  155. package/dist/extraction/wasm-runtime-flags.js +0 -105
  156. package/dist/graph/index.d.ts +0 -8
  157. package/dist/graph/index.js +0 -13
  158. package/dist/graph/queries.d.ts +0 -109
  159. package/dist/graph/queries.js +0 -366
  160. package/dist/graph/traversal.d.ts +0 -137
  161. package/dist/graph/traversal.js +0 -528
  162. package/dist/index.d.ts +0 -509
  163. package/dist/index.js +0 -800
  164. package/dist/installer/claude-md-template.d.ts +0 -19
  165. package/dist/installer/config-writer.d.ts +0 -29
  166. package/dist/installer/index.d.ts +0 -140
  167. package/dist/installer/instructions-template.d.ts +0 -30
  168. package/dist/installer/targets/claude.d.ts +0 -55
  169. package/dist/installer/targets/codex.d.ts +0 -18
  170. package/dist/installer/targets/cursor.d.ts +0 -35
  171. package/dist/installer/targets/hermes.d.ts +0 -18
  172. package/dist/installer/targets/opencode.d.ts +0 -30
  173. package/dist/installer/targets/registry.d.ts +0 -38
  174. package/dist/installer/targets/shared.d.ts +0 -92
  175. package/dist/installer/targets/toml.d.ts +0 -64
  176. package/dist/installer/targets/types.d.ts +0 -122
  177. package/dist/mcp/index.d.ts +0 -98
  178. package/dist/mcp/server-instructions.d.ts +0 -20
  179. package/dist/mcp/tools.d.ts +0 -269
  180. package/dist/mcp/transport.d.ts +0 -117
  181. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
  182. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  183. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  184. package/dist/resolution/frameworks/csharp.js +0 -213
  185. package/dist/resolution/frameworks/drupal.d.ts +0 -51
  186. package/dist/resolution/frameworks/drupal.js +0 -335
  187. package/dist/resolution/frameworks/express.d.ts +0 -8
  188. package/dist/resolution/frameworks/express.js +0 -225
  189. package/dist/resolution/frameworks/go.d.ts +0 -8
  190. package/dist/resolution/frameworks/go.js +0 -158
  191. package/dist/resolution/frameworks/index.d.ts +0 -52
  192. package/dist/resolution/frameworks/index.js +0 -137
  193. package/dist/resolution/frameworks/java.d.ts +0 -8
  194. package/dist/resolution/frameworks/java.js +0 -177
  195. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  196. package/dist/resolution/frameworks/laravel.js +0 -248
  197. package/dist/resolution/frameworks/nestjs.d.ts +0 -26
  198. package/dist/resolution/frameworks/nestjs.js +0 -374
  199. package/dist/resolution/frameworks/python.d.ts +0 -10
  200. package/dist/resolution/frameworks/python.js +0 -278
  201. package/dist/resolution/frameworks/react.d.ts +0 -8
  202. package/dist/resolution/frameworks/react.js +0 -272
  203. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  204. package/dist/resolution/frameworks/ruby.js +0 -198
  205. package/dist/resolution/frameworks/rust.d.ts +0 -8
  206. package/dist/resolution/frameworks/rust.js +0 -207
  207. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  208. package/dist/resolution/frameworks/svelte.js +0 -249
  209. package/dist/resolution/frameworks/swift.d.ts +0 -10
  210. package/dist/resolution/frameworks/swift.js +0 -376
  211. package/dist/resolution/frameworks/vue.d.ts +0 -9
  212. package/dist/resolution/frameworks/vue.js +0 -306
  213. package/dist/resolution/import-resolver.d.ts +0 -61
  214. package/dist/resolution/import-resolver.js +0 -663
  215. package/dist/resolution/index.d.ts +0 -118
  216. package/dist/resolution/index.js +0 -744
  217. package/dist/resolution/lru-cache.d.ts +0 -24
  218. package/dist/resolution/lru-cache.js +0 -62
  219. package/dist/resolution/name-matcher.d.ts +0 -50
  220. package/dist/resolution/name-matcher.js +0 -384
  221. package/dist/resolution/path-aliases.d.ts +0 -72
  222. package/dist/resolution/path-aliases.js +0 -238
  223. package/dist/resolution/strip-comments.d.ts +0 -40
  224. package/dist/resolution/strip-comments.js +0 -441
  225. package/dist/resolution/types.d.ts +0 -181
  226. package/dist/resolution/types.js +0 -8
  227. package/dist/search/query-parser.d.ts +0 -61
  228. package/dist/search/query-parser.js +0 -177
  229. package/dist/search/query-utils.d.ts +0 -59
  230. package/dist/search/query-utils.js +0 -383
  231. package/dist/sync/git-hooks.d.ts +0 -54
  232. package/dist/sync/git-hooks.js +0 -223
  233. package/dist/sync/index.d.ts +0 -25
  234. package/dist/sync/index.js +0 -28
  235. package/dist/sync/watch-policy.d.ts +0 -51
  236. package/dist/sync/watch-policy.js +0 -124
  237. package/dist/sync/watcher.d.ts +0 -83
  238. package/dist/sync/watcher.js +0 -192
  239. package/dist/types.d.ts +0 -433
  240. package/dist/types.js +0 -75
  241. package/dist/ui/glyphs.d.ts +0 -42
  242. package/dist/ui/shimmer-progress.d.ts +0 -11
  243. package/dist/ui/shimmer-worker.d.ts +0 -2
  244. package/dist/ui/types.d.ts +0 -20
  245. package/dist/utils.d.ts +0 -231
  246. package/dist/utils.js +0 -549
@@ -1,101 +0,0 @@
1
- /**
2
- * Database Layer
3
- *
4
- * Handles SQLite database initialization and connection management.
5
- */
6
- import { SqliteDatabase, SqliteBackend } from './sqlite-adapter'
7
- import { SchemaVersion } from '../types'
8
- export { SqliteDatabase, SqliteBackend } from './sqlite-adapter'
9
- /**
10
- * Database connection wrapper with lifecycle management
11
- */
12
- export declare class DatabaseConnection {
13
- private db
14
- private dbPath
15
- private backend
16
- private constructor()
17
- /**
18
- * Initialize a new database at the given path
19
- */
20
- static initialize(dbPath: string): DatabaseConnection
21
- /**
22
- * Open an existing database
23
- */
24
- static open(dbPath: string): DatabaseConnection
25
- /**
26
- * Get the underlying database instance
27
- */
28
- getDb(): SqliteDatabase
29
- /**
30
- * Get the SQLite backend serving this connection. Per-instance so
31
- * MCP cross-project queries report the right backend even when
32
- * multiple project DBs are open in the same process.
33
- */
34
- getBackend(): SqliteBackend
35
- /**
36
- * Get database file path
37
- */
38
- getPath(): string
39
- /**
40
- * The journal mode actually in effect (e.g. 'wal', 'delete').
41
- *
42
- * SQLite silently keeps the prior mode if WAL can't be enabled — e.g. on
43
- * filesystems without shared-memory support (some network/virtualized mounts,
44
- * WSL2 /mnt), and always on the wasm backend. So the effective mode can differ
45
- * from what `configureConnection` requested. Surfaced in `codegraph status` so
46
- * a "database is locked" report is triageable: 'wal' ⇒ readers never block on a
47
- * writer; anything else ⇒ they can. See issue #238.
48
- */
49
- getJournalMode(): string
50
- /**
51
- * Get current schema version
52
- */
53
- getSchemaVersion(): SchemaVersion | null
54
- /**
55
- * Execute a function within a transaction
56
- */
57
- transaction<T>(fn: () => T): T
58
- /**
59
- * Get database file size in bytes
60
- */
61
- getSize(): number
62
- /**
63
- * Optimize database (vacuum and analyze)
64
- */
65
- optimize(): void
66
- /**
67
- * Lightweight, non-blocking maintenance to run after bulk writes
68
- * (indexAll, sync). Two operations:
69
- *
70
- * - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes
71
- * tables whose row counts changed materially since the last
72
- * ANALYZE. Without it, the query planner has no statistics on the
73
- * freshly-bulk-loaded tables and can pick suboptimal indexes.
74
- *
75
- * - `PRAGMA wal_checkpoint(PASSIVE)` — fold pending WAL pages back
76
- * into the main database file so the WAL file doesn't grow
77
- * unboundedly between automatic checkpoints (auto-fires at 1000
78
- * pages by default; large indexAll runs blow past that).
79
- *
80
- * Both operations are silently swallowed on failure — they're a
81
- * best-effort optimization, never load-bearing for correctness.
82
- */
83
- runMaintenance(): void
84
- /**
85
- * Close the database connection
86
- */
87
- close(): void
88
- /**
89
- * Check if the database connection is open
90
- */
91
- isOpen(): boolean
92
- }
93
- /**
94
- * Default database filename
95
- */
96
- export declare const DATABASE_FILENAME = 'codegraph.db'
97
- /**
98
- * Get the default database path for a project
99
- */
100
- export declare function getDatabasePath(projectRoot: string): string
101
- //# sourceMappingURL=index.d.ts.map
package/dist/db/index.js DELETED
@@ -1,250 +0,0 @@
1
- "use strict";
2
- /**
3
- * Database Layer
4
- *
5
- * Handles SQLite database initialization and connection management.
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.DATABASE_FILENAME = exports.DatabaseConnection = void 0;
42
- exports.getDatabasePath = getDatabasePath;
43
- const sqlite_adapter_1 = require("./sqlite-adapter");
44
- const fs = __importStar(require("fs"));
45
- const path = __importStar(require("path"));
46
- const migrations_1 = require("./migrations");
47
- /**
48
- * Apply connection-level PRAGMAs. Shared by `initialize` and `open` so the two
49
- * paths can't drift.
50
- *
51
- * `busy_timeout` is set FIRST, before any pragma that might touch the database
52
- * file (notably `journal_mode`). If another process holds a write lock at open
53
- * time, the later pragmas — and the connection's first query — then wait out
54
- * the lock instead of throwing "database is locked" immediately. See issue #238.
55
- *
56
- * The 5s window (was 120s) rides out a normal incremental sync; the old
57
- * 2-minute wait presented as a frozen, hung agent. With WAL, reads never block
58
- * on a writer, so this timeout only governs cross-process write contention
59
- * (e.g. the git-hook `codegraph sync` running while the MCP server writes).
60
- */
61
- function configureConnection(db) {
62
- db.pragma('busy_timeout = 5000'); // MUST be first — see above
63
- db.pragma('foreign_keys = ON');
64
- db.pragma('journal_mode = WAL'); // node:sqlite supports WAL on every platform
65
- db.pragma('synchronous = NORMAL'); // safe with WAL mode
66
- db.pragma('cache_size = -64000'); // 64 MB page cache
67
- db.pragma('temp_store = MEMORY'); // temp tables in memory
68
- db.pragma('mmap_size = 268435456'); // 256 MB memory-mapped I/O
69
- }
70
- /**
71
- * Database connection wrapper with lifecycle management
72
- */
73
- class DatabaseConnection {
74
- db;
75
- dbPath;
76
- backend;
77
- constructor(db, dbPath, backend) {
78
- this.db = db;
79
- this.dbPath = dbPath;
80
- this.backend = backend;
81
- }
82
- /**
83
- * Initialize a new database at the given path
84
- */
85
- static initialize(dbPath) {
86
- // Ensure parent directory exists
87
- const dir = path.dirname(dbPath);
88
- if (!fs.existsSync(dir)) {
89
- fs.mkdirSync(dir, { recursive: true });
90
- }
91
- // Create and configure database
92
- const { db, backend } = (0, sqlite_adapter_1.createDatabase)(dbPath);
93
- configureConnection(db);
94
- // Run schema initialization
95
- const schemaPath = path.join(__dirname, 'schema.sql');
96
- const schema = fs.readFileSync(schemaPath, 'utf-8');
97
- db.exec(schema);
98
- // Record current schema version so migrations aren't re-applied on open
99
- const currentVersion = (0, migrations_1.getCurrentVersion)(db);
100
- if (currentVersion < migrations_1.CURRENT_SCHEMA_VERSION) {
101
- db.prepare('INSERT OR IGNORE INTO schema_versions (version, applied_at, description) VALUES (?, ?, ?)').run(migrations_1.CURRENT_SCHEMA_VERSION, Date.now(), 'Initial schema includes all migrations');
102
- }
103
- return new DatabaseConnection(db, dbPath, backend);
104
- }
105
- /**
106
- * Open an existing database
107
- */
108
- static open(dbPath) {
109
- if (!fs.existsSync(dbPath)) {
110
- throw new Error(`Database not found: ${dbPath}`);
111
- }
112
- const { db, backend } = (0, sqlite_adapter_1.createDatabase)(dbPath);
113
- configureConnection(db);
114
- // Check and run migrations if needed
115
- const conn = new DatabaseConnection(db, dbPath, backend);
116
- const currentVersion = (0, migrations_1.getCurrentVersion)(db);
117
- if (currentVersion < migrations_1.CURRENT_SCHEMA_VERSION) {
118
- (0, migrations_1.runMigrations)(db, currentVersion);
119
- }
120
- return conn;
121
- }
122
- /**
123
- * Get the underlying database instance
124
- */
125
- getDb() {
126
- return this.db;
127
- }
128
- /**
129
- * Get the SQLite backend serving this connection. Per-instance so
130
- * MCP cross-project queries report the right backend even when
131
- * multiple project DBs are open in the same process.
132
- */
133
- getBackend() {
134
- return this.backend;
135
- }
136
- /**
137
- * Get database file path
138
- */
139
- getPath() {
140
- return this.dbPath;
141
- }
142
- /**
143
- * The journal mode actually in effect (e.g. 'wal', 'delete').
144
- *
145
- * SQLite silently keeps the prior mode if WAL can't be enabled — e.g. on
146
- * filesystems without shared-memory support (some network/virtualized mounts,
147
- * WSL2 /mnt), and always on the wasm backend. So the effective mode can differ
148
- * from what `configureConnection` requested. Surfaced in `codegraph status` so
149
- * a "database is locked" report is triageable: 'wal' ⇒ readers never block on a
150
- * writer; anything else ⇒ they can. See issue #238.
151
- */
152
- getJournalMode() {
153
- const raw = this.db.pragma('journal_mode');
154
- const row = Array.isArray(raw) ? raw[0] : raw;
155
- const mode = row && typeof row === 'object'
156
- ? row.journal_mode
157
- : row;
158
- return String(mode ?? '').toLowerCase();
159
- }
160
- /**
161
- * Get current schema version
162
- */
163
- getSchemaVersion() {
164
- const row = this.db
165
- .prepare('SELECT version, applied_at, description FROM schema_versions ORDER BY version DESC LIMIT 1')
166
- .get();
167
- if (!row)
168
- return null;
169
- return {
170
- version: row.version,
171
- appliedAt: row.applied_at,
172
- description: row.description ?? undefined,
173
- };
174
- }
175
- /**
176
- * Execute a function within a transaction
177
- */
178
- transaction(fn) {
179
- return this.db.transaction(fn)();
180
- }
181
- /**
182
- * Get database file size in bytes
183
- */
184
- getSize() {
185
- const stats = fs.statSync(this.dbPath);
186
- return stats.size;
187
- }
188
- /**
189
- * Optimize database (vacuum and analyze)
190
- */
191
- optimize() {
192
- this.db.exec('VACUUM');
193
- this.db.exec('ANALYZE');
194
- }
195
- /**
196
- * Lightweight, non-blocking maintenance to run after bulk writes
197
- * (indexAll, sync). Two operations:
198
- *
199
- * - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes
200
- * tables whose row counts changed materially since the last
201
- * ANALYZE. Without it, the query planner has no statistics on the
202
- * freshly-bulk-loaded tables and can pick suboptimal indexes.
203
- *
204
- * - `PRAGMA wal_checkpoint(PASSIVE)` — fold pending WAL pages back
205
- * into the main database file so the WAL file doesn't grow
206
- * unboundedly between automatic checkpoints (auto-fires at 1000
207
- * pages by default; large indexAll runs blow past that).
208
- *
209
- * Both operations are silently swallowed on failure — they're a
210
- * best-effort optimization, never load-bearing for correctness.
211
- */
212
- runMaintenance() {
213
- try {
214
- this.db.exec('PRAGMA optimize');
215
- }
216
- catch {
217
- // ignore
218
- }
219
- try {
220
- this.db.exec('PRAGMA wal_checkpoint(PASSIVE)');
221
- }
222
- catch {
223
- // ignore (e.g., not in WAL mode)
224
- }
225
- }
226
- /**
227
- * Close the database connection
228
- */
229
- close() {
230
- this.db.close();
231
- }
232
- /**
233
- * Check if the database connection is open
234
- */
235
- isOpen() {
236
- return this.db.open;
237
- }
238
- }
239
- exports.DatabaseConnection = DatabaseConnection;
240
- /**
241
- * Default database filename
242
- */
243
- exports.DATABASE_FILENAME = 'codegraph.db';
244
- /**
245
- * Get the default database path for a project
246
- */
247
- function getDatabasePath(projectRoot) {
248
- return path.join(projectRoot, '.codegraph', exports.DATABASE_FILENAME);
249
- }
250
- //# sourceMappingURL=index.js.map
@@ -1,47 +0,0 @@
1
- /**
2
- * Database Migrations
3
- *
4
- * Schema versioning and migration support.
5
- */
6
- import { SqliteDatabase } from './sqlite-adapter'
7
- /**
8
- * Current schema version
9
- */
10
- export declare const CURRENT_SCHEMA_VERSION = 4
11
- /**
12
- * Migration definition
13
- */
14
- interface Migration {
15
- version: number
16
- description: string
17
- up: (db: SqliteDatabase) => void
18
- }
19
- /**
20
- * Get the current schema version from the database
21
- */
22
- export declare function getCurrentVersion(db: SqliteDatabase): number
23
- /**
24
- * Run all pending migrations
25
- */
26
- export declare function runMigrations(
27
- db: SqliteDatabase,
28
- fromVersion: number,
29
- ): void
30
- /**
31
- * Check if the database needs migration
32
- */
33
- export declare function needsMigration(db: SqliteDatabase): boolean
34
- /**
35
- * Get list of pending migrations
36
- */
37
- export declare function getPendingMigrations(db: SqliteDatabase): Migration[]
38
- /**
39
- * Get migration history from database
40
- */
41
- export declare function getMigrationHistory(db: SqliteDatabase): Array<{
42
- version: number
43
- appliedAt: number
44
- description: string | null
45
- }>
46
- export {}
47
- //# sourceMappingURL=migrations.d.ts.map
@@ -1,131 +0,0 @@
1
- "use strict";
2
- /**
3
- * Database Migrations
4
- *
5
- * Schema versioning and migration support.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.CURRENT_SCHEMA_VERSION = void 0;
9
- exports.getCurrentVersion = getCurrentVersion;
10
- exports.runMigrations = runMigrations;
11
- exports.needsMigration = needsMigration;
12
- exports.getPendingMigrations = getPendingMigrations;
13
- exports.getMigrationHistory = getMigrationHistory;
14
- /**
15
- * Current schema version
16
- */
17
- exports.CURRENT_SCHEMA_VERSION = 4;
18
- /**
19
- * All migrations in order
20
- *
21
- * Note: Version 1 is the initial schema, handled by schema.sql
22
- * Future migrations go here.
23
- */
24
- const migrations = [
25
- {
26
- version: 2,
27
- description: 'Add project metadata, provenance tracking, and unresolved ref context',
28
- up: (db) => {
29
- db.exec(`
30
- CREATE TABLE IF NOT EXISTS project_metadata (
31
- key TEXT PRIMARY KEY,
32
- value TEXT NOT NULL,
33
- updated_at INTEGER NOT NULL
34
- );
35
- ALTER TABLE unresolved_refs ADD COLUMN file_path TEXT NOT NULL DEFAULT '';
36
- ALTER TABLE unresolved_refs ADD COLUMN language TEXT NOT NULL DEFAULT 'unknown';
37
- ALTER TABLE edges ADD COLUMN provenance TEXT DEFAULT NULL;
38
- CREATE INDEX IF NOT EXISTS idx_unresolved_file_path ON unresolved_refs(file_path);
39
- CREATE INDEX IF NOT EXISTS idx_edges_provenance ON edges(provenance);
40
- `);
41
- },
42
- },
43
- {
44
- version: 3,
45
- description: 'Add lower(name) expression index for memory-efficient case-insensitive lookups',
46
- up: (db) => {
47
- db.exec(`
48
- CREATE INDEX IF NOT EXISTS idx_nodes_lower_name ON nodes(lower(name));
49
- `);
50
- },
51
- },
52
- {
53
- version: 4,
54
- description: 'Drop redundant idx_edges_source / idx_edges_target (covered by source_kind / target_kind composites)',
55
- up: (db) => {
56
- db.exec(`
57
- DROP INDEX IF EXISTS idx_edges_source;
58
- DROP INDEX IF EXISTS idx_edges_target;
59
- `);
60
- },
61
- },
62
- ];
63
- /**
64
- * Get the current schema version from the database
65
- */
66
- function getCurrentVersion(db) {
67
- try {
68
- const row = db
69
- .prepare('SELECT MAX(version) as version FROM schema_versions')
70
- .get();
71
- return row?.version ?? 0;
72
- }
73
- catch {
74
- // Table doesn't exist yet
75
- return 0;
76
- }
77
- }
78
- /**
79
- * Record a migration as applied
80
- */
81
- function recordMigration(db, version, description) {
82
- db.prepare('INSERT INTO schema_versions (version, applied_at, description) VALUES (?, ?, ?)').run(version, Date.now(), description);
83
- }
84
- /**
85
- * Run all pending migrations
86
- */
87
- function runMigrations(db, fromVersion) {
88
- const pending = migrations.filter((m) => m.version > fromVersion);
89
- if (pending.length === 0) {
90
- return;
91
- }
92
- // Sort by version
93
- pending.sort((a, b) => a.version - b.version);
94
- // Run each migration in a transaction
95
- for (const migration of pending) {
96
- db.transaction(() => {
97
- migration.up(db);
98
- recordMigration(db, migration.version, migration.description);
99
- })();
100
- }
101
- }
102
- /**
103
- * Check if the database needs migration
104
- */
105
- function needsMigration(db) {
106
- const current = getCurrentVersion(db);
107
- return current < exports.CURRENT_SCHEMA_VERSION;
108
- }
109
- /**
110
- * Get list of pending migrations
111
- */
112
- function getPendingMigrations(db) {
113
- const current = getCurrentVersion(db);
114
- return migrations
115
- .filter((m) => m.version > current)
116
- .sort((a, b) => a.version - b.version);
117
- }
118
- /**
119
- * Get migration history from database
120
- */
121
- function getMigrationHistory(db) {
122
- const rows = db
123
- .prepare('SELECT version, applied_at, description FROM schema_versions ORDER BY version')
124
- .all();
125
- return rows.map((row) => ({
126
- version: row.version,
127
- appliedAt: row.applied_at,
128
- description: row.description,
129
- }));
130
- }
131
- //# sourceMappingURL=migrations.js.map