@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,151 +0,0 @@
1
- -- CodeGraph SQLite Schema
2
- -- Version 1
3
-
4
- -- Schema version tracking
5
- CREATE TABLE IF NOT EXISTS schema_versions (
6
- version INTEGER PRIMARY KEY,
7
- applied_at INTEGER NOT NULL,
8
- description TEXT
9
- );
10
-
11
- -- Insert initial version
12
- INSERT INTO schema_versions (version, applied_at, description)
13
- VALUES (1, strftime('%s', 'now') * 1000, 'Initial schema');
14
-
15
- -- =============================================================================
16
- -- Core Tables
17
- -- =============================================================================
18
-
19
- -- Nodes: Code symbols (functions, classes, variables, etc.)
20
- CREATE TABLE IF NOT EXISTS nodes (
21
- id TEXT PRIMARY KEY,
22
- kind TEXT DEFAULT 'unknown',
23
- name TEXT DEFAULT '',
24
- qualified_name TEXT DEFAULT '',
25
- file_path TEXT DEFAULT '',
26
- language TEXT DEFAULT 'unknown',
27
- start_line INTEGER DEFAULT 0,
28
- end_line INTEGER DEFAULT 0,
29
- start_column INTEGER DEFAULT 0,
30
- end_column INTEGER DEFAULT 0,
31
- docstring TEXT,
32
- signature TEXT,
33
- visibility TEXT,
34
- is_exported INTEGER DEFAULT 0,
35
- is_async INTEGER DEFAULT 0,
36
- is_static INTEGER DEFAULT 0,
37
- is_abstract INTEGER DEFAULT 0,
38
- decorators TEXT, -- JSON array
39
- type_parameters TEXT, -- JSON array
40
- updated_at INTEGER DEFAULT 0
41
- );
42
-
43
- -- Edges: Relationships between nodes
44
- CREATE TABLE IF NOT EXISTS edges (
45
- id INTEGER PRIMARY KEY AUTOINCREMENT,
46
- source TEXT,
47
- target TEXT,
48
- kind TEXT DEFAULT 'unknown',
49
- metadata TEXT, -- JSON object
50
- line INTEGER,
51
- col INTEGER,
52
- provenance TEXT DEFAULT NULL,
53
- FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE,
54
- FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE
55
- );
56
-
57
- -- Files: Tracked source files
58
- CREATE TABLE IF NOT EXISTS files (
59
- path TEXT PRIMARY KEY,
60
- content_hash TEXT DEFAULT '',
61
- language TEXT DEFAULT 'unknown',
62
- size INTEGER DEFAULT 0,
63
- modified_at INTEGER DEFAULT 0,
64
- indexed_at INTEGER DEFAULT 0,
65
- node_count INTEGER DEFAULT 0,
66
- errors TEXT -- JSON array
67
- );
68
-
69
- -- Unresolved References: References that need resolution after full indexing
70
- CREATE TABLE IF NOT EXISTS unresolved_refs (
71
- id INTEGER PRIMARY KEY AUTOINCREMENT,
72
- from_node_id TEXT,
73
- reference_name TEXT DEFAULT '',
74
- reference_kind TEXT DEFAULT 'unknown',
75
- line INTEGER DEFAULT 0,
76
- col INTEGER DEFAULT 0,
77
- candidates TEXT, -- JSON array
78
- file_path TEXT DEFAULT '',
79
- language TEXT DEFAULT 'unknown',
80
- FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE
81
- );
82
-
83
- -- =============================================================================
84
- -- Indexes for Query Performance
85
- -- =============================================================================
86
-
87
- -- Node indexes
88
- CREATE INDEX IF NOT EXISTS idx_nodes_kind ON nodes(kind);
89
- CREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes(name);
90
- CREATE INDEX IF NOT EXISTS idx_nodes_qualified_name ON nodes(qualified_name);
91
- CREATE INDEX IF NOT EXISTS idx_nodes_file_path ON nodes(file_path);
92
- CREATE INDEX IF NOT EXISTS idx_nodes_language ON nodes(language);
93
- CREATE INDEX IF NOT EXISTS idx_nodes_file_line ON nodes(file_path, start_line);
94
- CREATE INDEX IF NOT EXISTS idx_nodes_lower_name ON nodes(lower(name));
95
-
96
- -- Full-text search index on node names, docstrings, and signatures
97
- CREATE VIRTUAL TABLE IF NOT EXISTS nodes_fts USING fts5(
98
- id,
99
- name,
100
- qualified_name,
101
- docstring,
102
- signature,
103
- content='nodes',
104
- content_rowid='rowid'
105
- );
106
-
107
- -- Triggers to keep FTS index in sync
108
- CREATE TRIGGER IF NOT EXISTS nodes_ai AFTER INSERT ON nodes BEGIN
109
- INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature)
110
- VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature);
111
- END;
112
-
113
- CREATE TRIGGER IF NOT EXISTS nodes_ad AFTER DELETE ON nodes BEGIN
114
- INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature)
115
- VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature);
116
- END;
117
-
118
- CREATE TRIGGER IF NOT EXISTS nodes_au AFTER UPDATE ON nodes BEGIN
119
- INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature)
120
- VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature);
121
- INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature)
122
- VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature);
123
- END;
124
-
125
- -- Edge indexes.
126
- -- idx_edges_source / idx_edges_target are intentionally omitted —
127
- -- the (source, kind) and (target, kind) composites below cover the
128
- -- corresponding source-only / target-only lookups via SQLite's
129
- -- left-prefix scan, so the narrow indexes are dead weight on writes.
130
- -- Migration v4 drops them on existing databases.
131
- CREATE INDEX IF NOT EXISTS idx_edges_kind ON edges(kind);
132
- CREATE INDEX IF NOT EXISTS idx_edges_source_kind ON edges(source, kind);
133
- CREATE INDEX IF NOT EXISTS idx_edges_target_kind ON edges(target, kind);
134
-
135
- -- File indexes
136
- CREATE INDEX IF NOT EXISTS idx_files_language ON files(language);
137
- CREATE INDEX IF NOT EXISTS idx_files_modified_at ON files(modified_at);
138
-
139
- -- Unresolved refs indexes
140
- CREATE INDEX IF NOT EXISTS idx_unresolved_from_node ON unresolved_refs(from_node_id);
141
- CREATE INDEX IF NOT EXISTS idx_unresolved_name ON unresolved_refs(reference_name);
142
- CREATE INDEX IF NOT EXISTS idx_unresolved_file_path ON unresolved_refs(file_path);
143
- CREATE INDEX IF NOT EXISTS idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name);
144
- CREATE INDEX IF NOT EXISTS idx_edges_provenance ON edges(provenance);
145
-
146
- -- Project metadata for version/provenance tracking
147
- CREATE TABLE IF NOT EXISTS project_metadata (
148
- key TEXT PRIMARY KEY,
149
- value TEXT NOT NULL,
150
- updated_at INTEGER NOT NULL
151
- );
@@ -1,49 +0,0 @@
1
- /**
2
- * SQLite Adapter
3
- *
4
- * Thin wrapper over Node's built-in `node:sqlite` (`DatabaseSync`), exposed
5
- * through a small better-sqlite3-shaped interface so the rest of the codebase
6
- * is storage-agnostic.
7
- *
8
- * CodeGraph ships with a bundled Node runtime, so `node:sqlite` (real SQLite,
9
- * with WAL + FTS5) is always available — there is no native build step and no
10
- * wasm fallback. When run from source instead, it requires Node >= 22.5.
11
- */
12
- export interface SqliteStatement {
13
- run(...params: any[]): {
14
- changes: number
15
- lastInsertRowid: number | bigint
16
- }
17
- get(...params: any[]): any
18
- all(...params: any[]): any[]
19
- }
20
- export interface SqliteDatabase {
21
- prepare(sql: string): SqliteStatement
22
- exec(sql: string): void
23
- pragma(
24
- str: string,
25
- options?: {
26
- simple?: boolean
27
- },
28
- ): any
29
- transaction<T>(fn: (...args: any[]) => T): (...args: any[]) => T
30
- close(): void
31
- readonly open: boolean
32
- }
33
- /**
34
- * The active SQLite backend. Only one now (`node:sqlite`); kept as a named type
35
- * so `codegraph status` and the per-instance reporting have a stable shape.
36
- */
37
- export type SqliteBackend = 'node-sqlite'
38
- /**
39
- * Create a database connection backed by `node:sqlite`.
40
- *
41
- * Returns the active backend alongside the db so each `DatabaseConnection` can
42
- * report it per-instance — MCP can open multiple project DBs in one process, so
43
- * a process-global would race.
44
- */
45
- export declare function createDatabase(dbPath: string): {
46
- db: SqliteDatabase
47
- backend: SqliteBackend
48
- }
49
- //# sourceMappingURL=sqlite-adapter.d.ts.map
@@ -1,141 +0,0 @@
1
- "use strict";
2
- // Patched by Saluzi for bun:sqlite compatibility
3
- const __bunSqliteCompat = (() => {
4
- try { return require('node:sqlite'); } catch {
5
- try {
6
- const bunSqlite = require('bun:sqlite');
7
- return { ...bunSqlite, DatabaseSync: bunSqlite.Database, __isBun: true };
8
- } catch { return null; }
9
- }
10
- })();
11
- const __isBunSqlite = !!__bunSqliteCompat?.__isBun;
12
- /**
13
- * bun:sqlite requires object keys to include the named-param prefix
14
- * (e.g. `@id` for `@id` in SQL). node:sqlite and better-sqlite3 accept
15
- * bare keys (`id` for `@id`). This helper re-keys the object so that
16
- * bare keys get the `@` prefix bun:sqlite expects.
17
- */
18
- function __prefixNamedParams(params) {
19
- if (!__isBunSqlite || params.length !== 1 || typeof params[0] !== 'object' || params[0] === null || Array.isArray(params[0])) {
20
- return params;
21
- }
22
- const obj = params[0];
23
- const prefixed = {};
24
- for (const key of Object.keys(obj)) {
25
- if (key.startsWith('@') || key.startsWith('$') || key.startsWith(':')) {
26
- prefixed[key] = obj[key];
27
- } else {
28
- prefixed['@' + key] = obj[key];
29
- }
30
- }
31
- return [prefixed];
32
- }
33
- /**
34
- * SQLite Adapter
35
- *
36
- * Thin wrapper over Node's built-in `node:sqlite` (`DatabaseSync`), exposed
37
- * through a small better-sqlite3-shaped interface so the rest of the codebase
38
- * is storage-agnostic.
39
- *
40
- * CodeGraph ships with a bundled Node runtime, so `node:sqlite` (real SQLite,
41
- * with WAL + FTS5) is always available — there is no native build step and no
42
- * wasm fallback. When run from source instead, it requires Node >= 22.5.
43
- */
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.createDatabase = createDatabase;
46
- /**
47
- * Wraps Node's built-in `node:sqlite` (`DatabaseSync`) to match the
48
- * better-sqlite3 interface the rest of the code expects.
49
- *
50
- * node:sqlite is real SQLite compiled into Node, so it supports WAL, FTS5,
51
- * mmap, and `@named` params natively — the only shims needed are the
52
- * better-sqlite3 conveniences node:sqlite omits: a `.pragma()` helper, a
53
- * `.transaction()` helper, and `open` (node:sqlite exposes `isOpen`).
54
- */
55
- class NodeSqliteAdapter {
56
- _db;
57
- constructor(dbPath) {
58
- const { DatabaseSync } = __bunSqliteCompat;
59
- this._db = new DatabaseSync(dbPath);
60
- }
61
- get open() {
62
- return this._db.isOpen;
63
- }
64
- prepare(sql) {
65
- const stmt = this._db.prepare(sql);
66
- return {
67
- run(...params) {
68
- const r = stmt.run(...__prefixNamedParams(params));
69
- return {
70
- changes: Number(r?.changes ?? 0),
71
- lastInsertRowid: r?.lastInsertRowid ?? 0,
72
- };
73
- },
74
- get(...params) {
75
- return stmt.get(...__prefixNamedParams(params));
76
- },
77
- all(...params) {
78
- return stmt.all(...__prefixNamedParams(params));
79
- },
80
- };
81
- }
82
- exec(sql) {
83
- this._db.exec(sql);
84
- }
85
- pragma(str, options) {
86
- const trimmed = str.trim();
87
- // Write pragma ("key = value"): node:sqlite is real SQLite, so every pragma
88
- // (WAL, mmap, synchronous, …) applies as-is.
89
- if (trimmed.includes('=')) {
90
- this._db.exec(`PRAGMA ${trimmed}`);
91
- return;
92
- }
93
- // Read pragma. Default: the row object (e.g. { journal_mode: 'wal' }).
94
- // `{ simple: true }` returns just the single column value, like better-sqlite3.
95
- const row = this._db.prepare(`PRAGMA ${trimmed}`).get();
96
- if (options?.simple) {
97
- return row && typeof row === 'object' ? Object.values(row)[0] : row;
98
- }
99
- return row;
100
- }
101
- transaction(fn) {
102
- return (...args) => {
103
- this._db.exec('BEGIN');
104
- try {
105
- const result = fn(...args);
106
- this._db.exec('COMMIT');
107
- return result;
108
- }
109
- catch (error) {
110
- this._db.exec('ROLLBACK');
111
- throw error;
112
- }
113
- };
114
- }
115
- close() {
116
- // node:sqlite's DatabaseSync.close() throws if already closed; make it
117
- // idempotent to match better-sqlite3 (callers may close more than once).
118
- if (this._db.isOpen)
119
- this._db.close();
120
- }
121
- }
122
- /**
123
- * Create a database connection backed by `node:sqlite`.
124
- *
125
- * Returns the active backend alongside the db so each `DatabaseConnection` can
126
- * report it per-instance — MCP can open multiple project DBs in one process, so
127
- * a process-global would race.
128
- */
129
- function createDatabase(dbPath) {
130
- try {
131
- return { db: new NodeSqliteAdapter(dbPath), backend: 'node-sqlite' };
132
- }
133
- catch (error) {
134
- const msg = error instanceof Error ? error.message : String(error);
135
- throw new Error('Failed to open SQLite via the built-in node:sqlite module.\n' +
136
- 'CodeGraph requires node:sqlite (Node.js 22.5+). Install the self-contained\n' +
137
- 'CodeGraph release (it bundles a compatible Node), or run on Node 22.5+.\n' +
138
- `Underlying error: ${msg}`);
139
- }
140
- }
141
- //# sourceMappingURL=sqlite-adapter.js.map
@@ -1,62 +0,0 @@
1
- /**
2
- * Directory Management
3
- *
4
- * Manages the .codegraph/ directory structure for CodeGraph data.
5
- */
6
- /**
7
- * CodeGraph directory name
8
- */
9
- export declare const CODEGRAPH_DIR = '.codegraph'
10
- /**
11
- * Get the .codegraph directory path for a project
12
- */
13
- export declare function getCodeGraphDir(projectRoot: string): string
14
- /**
15
- * Check if a project has been initialized with CodeGraph
16
- * Requires both .codegraph/ directory AND codegraph.db to exist
17
- */
18
- export declare function isInitialized(projectRoot: string): boolean
19
- /**
20
- * Find the nearest parent directory containing .codegraph/
21
- *
22
- * Walks up from the given path to find a CodeGraph-initialized project,
23
- * similar to how git finds .git/ directories.
24
- *
25
- * @param startPath - Directory to start searching from
26
- * @returns The project root containing .codegraph/, or null if not found
27
- */
28
- export declare function findNearestCodeGraphRoot(
29
- startPath: string,
30
- ): string | null
31
- /**
32
- * Create the .codegraph directory structure
33
- * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
34
- */
35
- export declare function createDirectory(projectRoot: string): void
36
- /**
37
- * Remove the .codegraph directory
38
- */
39
- export declare function removeDirectory(projectRoot: string): void
40
- /**
41
- * Get all files in the .codegraph directory
42
- */
43
- export declare function listDirectoryContents(projectRoot: string): string[]
44
- /**
45
- * Get the total size of the .codegraph directory in bytes
46
- */
47
- export declare function getDirectorySize(projectRoot: string): number
48
- /**
49
- * Ensure a subdirectory exists within .codegraph
50
- */
51
- export declare function ensureSubdirectory(
52
- projectRoot: string,
53
- subdirName: string,
54
- ): string
55
- /**
56
- * Check if the .codegraph directory has valid structure
57
- */
58
- export declare function validateDirectory(projectRoot: string): {
59
- valid: boolean
60
- errors: string[]
61
- }
62
- //# sourceMappingURL=directory.d.ts.map
package/dist/directory.js DELETED
@@ -1,264 +0,0 @@
1
- "use strict";
2
- /**
3
- * Directory Management
4
- *
5
- * Manages the .codegraph/ directory structure for CodeGraph data.
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.CODEGRAPH_DIR = void 0;
42
- exports.getCodeGraphDir = getCodeGraphDir;
43
- exports.isInitialized = isInitialized;
44
- exports.findNearestCodeGraphRoot = findNearestCodeGraphRoot;
45
- exports.createDirectory = createDirectory;
46
- exports.removeDirectory = removeDirectory;
47
- exports.listDirectoryContents = listDirectoryContents;
48
- exports.getDirectorySize = getDirectorySize;
49
- exports.ensureSubdirectory = ensureSubdirectory;
50
- exports.validateDirectory = validateDirectory;
51
- const fs = __importStar(require("fs"));
52
- const path = __importStar(require("path"));
53
- /**
54
- * CodeGraph directory name
55
- */
56
- exports.CODEGRAPH_DIR = '.codegraph';
57
- /**
58
- * Get the .codegraph directory path for a project
59
- */
60
- function getCodeGraphDir(projectRoot) {
61
- return path.join(projectRoot, exports.CODEGRAPH_DIR);
62
- }
63
- /**
64
- * Check if a project has been initialized with CodeGraph
65
- * Requires both .codegraph/ directory AND codegraph.db to exist
66
- */
67
- function isInitialized(projectRoot) {
68
- const codegraphDir = getCodeGraphDir(projectRoot);
69
- if (!fs.existsSync(codegraphDir) || !fs.statSync(codegraphDir).isDirectory()) {
70
- return false;
71
- }
72
- // Must have codegraph.db, not just .codegraph folder
73
- const dbPath = path.join(codegraphDir, 'codegraph.db');
74
- return fs.existsSync(dbPath);
75
- }
76
- /**
77
- * Find the nearest parent directory containing .codegraph/
78
- *
79
- * Walks up from the given path to find a CodeGraph-initialized project,
80
- * similar to how git finds .git/ directories.
81
- *
82
- * @param startPath - Directory to start searching from
83
- * @returns The project root containing .codegraph/, or null if not found
84
- */
85
- function findNearestCodeGraphRoot(startPath) {
86
- let current = path.resolve(startPath);
87
- const root = path.parse(current).root;
88
- while (current !== root) {
89
- if (isInitialized(current)) {
90
- return current;
91
- }
92
- const parent = path.dirname(current);
93
- if (parent === current)
94
- break; // Reached filesystem root
95
- current = parent;
96
- }
97
- // Check root as well
98
- if (isInitialized(current)) {
99
- return current;
100
- }
101
- return null;
102
- }
103
- /**
104
- * Create the .codegraph directory structure
105
- * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
106
- */
107
- function createDirectory(projectRoot) {
108
- const codegraphDir = getCodeGraphDir(projectRoot);
109
- const dbPath = path.join(codegraphDir, 'codegraph.db');
110
- // Only throw if CodeGraph is actually initialized (db exists)
111
- // .codegraph/ folder alone is fine
112
- if (fs.existsSync(dbPath)) {
113
- throw new Error(`CodeGraph already initialized in ${projectRoot}`);
114
- }
115
- // Create main directory (if it doesn't exist)
116
- fs.mkdirSync(codegraphDir, { recursive: true });
117
- // Create .gitignore inside .codegraph (if it doesn't exist)
118
- const gitignorePath = path.join(codegraphDir, '.gitignore');
119
- if (!fs.existsSync(gitignorePath)) {
120
- const gitignoreContent = `# CodeGraph data files
121
- # These are local to each machine and should not be committed
122
-
123
- # Database
124
- *.db
125
- *.db-wal
126
- *.db-shm
127
-
128
- # Cache
129
- cache/
130
-
131
- # Logs
132
- *.log
133
-
134
- # Hook markers
135
- .dirty
136
- `;
137
- fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
138
- }
139
- }
140
- /**
141
- * Remove the .codegraph directory
142
- */
143
- function removeDirectory(projectRoot) {
144
- const codegraphDir = getCodeGraphDir(projectRoot);
145
- if (!fs.existsSync(codegraphDir)) {
146
- return;
147
- }
148
- // Verify .codegraph is a real directory, not a symlink pointing elsewhere
149
- const lstat = fs.lstatSync(codegraphDir);
150
- if (lstat.isSymbolicLink()) {
151
- // Only remove the symlink itself, never follow it for recursive delete
152
- fs.unlinkSync(codegraphDir);
153
- return;
154
- }
155
- if (!lstat.isDirectory()) {
156
- // Not a directory - remove the single file
157
- fs.unlinkSync(codegraphDir);
158
- return;
159
- }
160
- // Recursively remove directory
161
- fs.rmSync(codegraphDir, { recursive: true, force: true });
162
- }
163
- /**
164
- * Get all files in the .codegraph directory
165
- */
166
- function listDirectoryContents(projectRoot) {
167
- const codegraphDir = getCodeGraphDir(projectRoot);
168
- if (!fs.existsSync(codegraphDir)) {
169
- return [];
170
- }
171
- const files = [];
172
- function walkDir(dir, prefix = '') {
173
- const entries = fs.readdirSync(dir, { withFileTypes: true });
174
- for (const entry of entries) {
175
- const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
176
- // Skip symlinks to prevent following links outside .codegraph
177
- if (entry.isSymbolicLink()) {
178
- continue;
179
- }
180
- if (entry.isDirectory()) {
181
- walkDir(path.join(dir, entry.name), relativePath);
182
- }
183
- else {
184
- files.push(relativePath);
185
- }
186
- }
187
- }
188
- walkDir(codegraphDir);
189
- return files;
190
- }
191
- /**
192
- * Get the total size of the .codegraph directory in bytes
193
- */
194
- function getDirectorySize(projectRoot) {
195
- const codegraphDir = getCodeGraphDir(projectRoot);
196
- if (!fs.existsSync(codegraphDir)) {
197
- return 0;
198
- }
199
- let totalSize = 0;
200
- function walkDir(dir) {
201
- const entries = fs.readdirSync(dir, { withFileTypes: true });
202
- for (const entry of entries) {
203
- // Skip symlinks to prevent following links outside .codegraph
204
- if (entry.isSymbolicLink()) {
205
- continue;
206
- }
207
- const fullPath = path.join(dir, entry.name);
208
- if (entry.isDirectory()) {
209
- walkDir(fullPath);
210
- }
211
- else {
212
- const stats = fs.statSync(fullPath);
213
- totalSize += stats.size;
214
- }
215
- }
216
- }
217
- walkDir(codegraphDir);
218
- return totalSize;
219
- }
220
- /**
221
- * Ensure a subdirectory exists within .codegraph
222
- */
223
- function ensureSubdirectory(projectRoot, subdirName) {
224
- if (subdirName.includes('..') || subdirName.includes(path.sep) || subdirName.includes('/')) {
225
- throw new Error(`Invalid subdirectory name: ${subdirName}`);
226
- }
227
- const subdirPath = path.join(getCodeGraphDir(projectRoot), subdirName);
228
- if (!fs.existsSync(subdirPath)) {
229
- fs.mkdirSync(subdirPath, { recursive: true });
230
- }
231
- return subdirPath;
232
- }
233
- /**
234
- * Check if the .codegraph directory has valid structure
235
- */
236
- function validateDirectory(projectRoot) {
237
- const errors = [];
238
- const codegraphDir = getCodeGraphDir(projectRoot);
239
- if (!fs.existsSync(codegraphDir)) {
240
- errors.push('CodeGraph directory does not exist');
241
- return { valid: false, errors };
242
- }
243
- if (!fs.statSync(codegraphDir).isDirectory()) {
244
- errors.push('.codegraph exists but is not a directory');
245
- return { valid: false, errors };
246
- }
247
- // Auto-repair missing .gitignore (non-critical file)
248
- const gitignorePath = path.join(codegraphDir, '.gitignore');
249
- if (!fs.existsSync(gitignorePath)) {
250
- try {
251
- const gitignoreContent = `# CodeGraph data files\n# These are local to each machine and should not be committed\n\n# Database\n*.db\n*.db-wal\n*.db-shm\n\n# Cache\ncache/\n\n# Logs\n*.log\n\n# Hook markers\n.dirty\n`;
252
- fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
253
- }
254
- catch {
255
- // Non-fatal: warn but don't block
256
- errors.push('.gitignore missing in .codegraph directory and could not be created');
257
- }
258
- }
259
- return {
260
- valid: errors.length === 0,
261
- errors,
262
- };
263
- }
264
- //# sourceMappingURL=directory.js.map