@veewo/gitnexus 1.3.4

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 (231) hide show
  1. package/README.md +234 -0
  2. package/dist/benchmark/agent-context/evaluators.d.ts +9 -0
  3. package/dist/benchmark/agent-context/evaluators.js +196 -0
  4. package/dist/benchmark/agent-context/evaluators.test.d.ts +1 -0
  5. package/dist/benchmark/agent-context/evaluators.test.js +39 -0
  6. package/dist/benchmark/agent-context/io.d.ts +2 -0
  7. package/dist/benchmark/agent-context/io.js +23 -0
  8. package/dist/benchmark/agent-context/io.test.d.ts +1 -0
  9. package/dist/benchmark/agent-context/io.test.js +19 -0
  10. package/dist/benchmark/agent-context/report.d.ts +2 -0
  11. package/dist/benchmark/agent-context/report.js +59 -0
  12. package/dist/benchmark/agent-context/report.test.d.ts +1 -0
  13. package/dist/benchmark/agent-context/report.test.js +85 -0
  14. package/dist/benchmark/agent-context/runner.d.ts +46 -0
  15. package/dist/benchmark/agent-context/runner.js +111 -0
  16. package/dist/benchmark/agent-context/runner.test.d.ts +1 -0
  17. package/dist/benchmark/agent-context/runner.test.js +79 -0
  18. package/dist/benchmark/agent-context/tool-runner.d.ts +7 -0
  19. package/dist/benchmark/agent-context/tool-runner.js +18 -0
  20. package/dist/benchmark/agent-context/tool-runner.test.d.ts +1 -0
  21. package/dist/benchmark/agent-context/tool-runner.test.js +11 -0
  22. package/dist/benchmark/agent-context/types.d.ts +40 -0
  23. package/dist/benchmark/agent-context/types.js +1 -0
  24. package/dist/benchmark/analyze-runner.d.ts +16 -0
  25. package/dist/benchmark/analyze-runner.js +51 -0
  26. package/dist/benchmark/analyze-runner.test.d.ts +1 -0
  27. package/dist/benchmark/analyze-runner.test.js +37 -0
  28. package/dist/benchmark/evaluators.d.ts +6 -0
  29. package/dist/benchmark/evaluators.js +10 -0
  30. package/dist/benchmark/evaluators.test.d.ts +1 -0
  31. package/dist/benchmark/evaluators.test.js +12 -0
  32. package/dist/benchmark/io.d.ts +7 -0
  33. package/dist/benchmark/io.js +25 -0
  34. package/dist/benchmark/io.test.d.ts +1 -0
  35. package/dist/benchmark/io.test.js +35 -0
  36. package/dist/benchmark/neonspark-candidates.d.ts +19 -0
  37. package/dist/benchmark/neonspark-candidates.js +94 -0
  38. package/dist/benchmark/neonspark-candidates.test.d.ts +1 -0
  39. package/dist/benchmark/neonspark-candidates.test.js +43 -0
  40. package/dist/benchmark/neonspark-materialize.d.ts +19 -0
  41. package/dist/benchmark/neonspark-materialize.js +111 -0
  42. package/dist/benchmark/neonspark-materialize.test.d.ts +1 -0
  43. package/dist/benchmark/neonspark-materialize.test.js +124 -0
  44. package/dist/benchmark/neonspark-sync.d.ts +3 -0
  45. package/dist/benchmark/neonspark-sync.js +53 -0
  46. package/dist/benchmark/neonspark-sync.test.d.ts +1 -0
  47. package/dist/benchmark/neonspark-sync.test.js +20 -0
  48. package/dist/benchmark/report.d.ts +1 -0
  49. package/dist/benchmark/report.js +7 -0
  50. package/dist/benchmark/runner.d.ts +48 -0
  51. package/dist/benchmark/runner.js +302 -0
  52. package/dist/benchmark/runner.test.d.ts +1 -0
  53. package/dist/benchmark/runner.test.js +50 -0
  54. package/dist/benchmark/scoring.d.ts +16 -0
  55. package/dist/benchmark/scoring.js +27 -0
  56. package/dist/benchmark/scoring.test.d.ts +1 -0
  57. package/dist/benchmark/scoring.test.js +24 -0
  58. package/dist/benchmark/tool-runner.d.ts +6 -0
  59. package/dist/benchmark/tool-runner.js +17 -0
  60. package/dist/benchmark/types.d.ts +36 -0
  61. package/dist/benchmark/types.js +1 -0
  62. package/dist/cli/ai-context.d.ts +22 -0
  63. package/dist/cli/ai-context.js +184 -0
  64. package/dist/cli/ai-context.test.d.ts +1 -0
  65. package/dist/cli/ai-context.test.js +30 -0
  66. package/dist/cli/analyze-multi-scope-regression.test.d.ts +1 -0
  67. package/dist/cli/analyze-multi-scope-regression.test.js +22 -0
  68. package/dist/cli/analyze-options.d.ts +7 -0
  69. package/dist/cli/analyze-options.js +56 -0
  70. package/dist/cli/analyze-options.test.d.ts +1 -0
  71. package/dist/cli/analyze-options.test.js +36 -0
  72. package/dist/cli/analyze.d.ts +14 -0
  73. package/dist/cli/analyze.js +384 -0
  74. package/dist/cli/augment.d.ts +13 -0
  75. package/dist/cli/augment.js +33 -0
  76. package/dist/cli/benchmark-agent-context.d.ts +29 -0
  77. package/dist/cli/benchmark-agent-context.js +61 -0
  78. package/dist/cli/benchmark-agent-context.test.d.ts +1 -0
  79. package/dist/cli/benchmark-agent-context.test.js +80 -0
  80. package/dist/cli/benchmark-unity.d.ts +15 -0
  81. package/dist/cli/benchmark-unity.js +31 -0
  82. package/dist/cli/benchmark-unity.test.d.ts +1 -0
  83. package/dist/cli/benchmark-unity.test.js +18 -0
  84. package/dist/cli/claude-hooks.d.ts +22 -0
  85. package/dist/cli/claude-hooks.js +97 -0
  86. package/dist/cli/clean.d.ts +10 -0
  87. package/dist/cli/clean.js +60 -0
  88. package/dist/cli/eval-server.d.ts +30 -0
  89. package/dist/cli/eval-server.js +372 -0
  90. package/dist/cli/index.d.ts +2 -0
  91. package/dist/cli/index.js +182 -0
  92. package/dist/cli/list.d.ts +6 -0
  93. package/dist/cli/list.js +33 -0
  94. package/dist/cli/mcp.d.ts +8 -0
  95. package/dist/cli/mcp.js +34 -0
  96. package/dist/cli/repo-manager-alias.test.d.ts +1 -0
  97. package/dist/cli/repo-manager-alias.test.js +40 -0
  98. package/dist/cli/scope-filter.test.d.ts +1 -0
  99. package/dist/cli/scope-filter.test.js +49 -0
  100. package/dist/cli/serve.d.ts +4 -0
  101. package/dist/cli/serve.js +6 -0
  102. package/dist/cli/setup.d.ts +8 -0
  103. package/dist/cli/setup.js +311 -0
  104. package/dist/cli/setup.test.d.ts +1 -0
  105. package/dist/cli/setup.test.js +31 -0
  106. package/dist/cli/status.d.ts +6 -0
  107. package/dist/cli/status.js +27 -0
  108. package/dist/cli/tool.d.ts +40 -0
  109. package/dist/cli/tool.js +94 -0
  110. package/dist/cli/version.test.d.ts +1 -0
  111. package/dist/cli/version.test.js +19 -0
  112. package/dist/cli/wiki.d.ts +15 -0
  113. package/dist/cli/wiki.js +361 -0
  114. package/dist/config/ignore-service.d.ts +1 -0
  115. package/dist/config/ignore-service.js +210 -0
  116. package/dist/config/supported-languages.d.ts +12 -0
  117. package/dist/config/supported-languages.js +15 -0
  118. package/dist/core/augmentation/engine.d.ts +26 -0
  119. package/dist/core/augmentation/engine.js +213 -0
  120. package/dist/core/embeddings/embedder.d.ts +60 -0
  121. package/dist/core/embeddings/embedder.js +251 -0
  122. package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
  123. package/dist/core/embeddings/embedding-pipeline.js +329 -0
  124. package/dist/core/embeddings/index.d.ts +9 -0
  125. package/dist/core/embeddings/index.js +9 -0
  126. package/dist/core/embeddings/text-generator.d.ts +24 -0
  127. package/dist/core/embeddings/text-generator.js +182 -0
  128. package/dist/core/embeddings/types.d.ts +87 -0
  129. package/dist/core/embeddings/types.js +32 -0
  130. package/dist/core/graph/graph.d.ts +2 -0
  131. package/dist/core/graph/graph.js +66 -0
  132. package/dist/core/graph/types.d.ts +61 -0
  133. package/dist/core/graph/types.js +1 -0
  134. package/dist/core/ingestion/ast-cache.d.ts +11 -0
  135. package/dist/core/ingestion/ast-cache.js +34 -0
  136. package/dist/core/ingestion/call-processor.d.ts +15 -0
  137. package/dist/core/ingestion/call-processor.js +327 -0
  138. package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
  139. package/dist/core/ingestion/cluster-enricher.js +170 -0
  140. package/dist/core/ingestion/community-processor.d.ts +39 -0
  141. package/dist/core/ingestion/community-processor.js +312 -0
  142. package/dist/core/ingestion/entry-point-scoring.d.ts +39 -0
  143. package/dist/core/ingestion/entry-point-scoring.js +260 -0
  144. package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
  145. package/dist/core/ingestion/filesystem-walker.js +80 -0
  146. package/dist/core/ingestion/framework-detection.d.ts +39 -0
  147. package/dist/core/ingestion/framework-detection.js +235 -0
  148. package/dist/core/ingestion/heritage-processor.d.ts +20 -0
  149. package/dist/core/ingestion/heritage-processor.js +197 -0
  150. package/dist/core/ingestion/import-processor.d.ts +38 -0
  151. package/dist/core/ingestion/import-processor.js +778 -0
  152. package/dist/core/ingestion/parsing-processor.d.ts +15 -0
  153. package/dist/core/ingestion/parsing-processor.js +291 -0
  154. package/dist/core/ingestion/pipeline.d.ts +5 -0
  155. package/dist/core/ingestion/pipeline.js +323 -0
  156. package/dist/core/ingestion/process-processor.d.ts +51 -0
  157. package/dist/core/ingestion/process-processor.js +309 -0
  158. package/dist/core/ingestion/scope-filter.d.ts +25 -0
  159. package/dist/core/ingestion/scope-filter.js +100 -0
  160. package/dist/core/ingestion/structure-processor.d.ts +2 -0
  161. package/dist/core/ingestion/structure-processor.js +36 -0
  162. package/dist/core/ingestion/symbol-table.d.ts +33 -0
  163. package/dist/core/ingestion/symbol-table.js +38 -0
  164. package/dist/core/ingestion/tree-sitter-queries.d.ts +12 -0
  165. package/dist/core/ingestion/tree-sitter-queries.js +398 -0
  166. package/dist/core/ingestion/utils.d.ts +10 -0
  167. package/dist/core/ingestion/utils.js +50 -0
  168. package/dist/core/ingestion/workers/parse-worker.d.ts +59 -0
  169. package/dist/core/ingestion/workers/parse-worker.js +672 -0
  170. package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
  171. package/dist/core/ingestion/workers/worker-pool.js +120 -0
  172. package/dist/core/kuzu/csv-generator.d.ts +29 -0
  173. package/dist/core/kuzu/csv-generator.js +336 -0
  174. package/dist/core/kuzu/kuzu-adapter.d.ts +101 -0
  175. package/dist/core/kuzu/kuzu-adapter.js +753 -0
  176. package/dist/core/kuzu/schema.d.ts +53 -0
  177. package/dist/core/kuzu/schema.js +407 -0
  178. package/dist/core/search/bm25-index.d.ts +23 -0
  179. package/dist/core/search/bm25-index.js +95 -0
  180. package/dist/core/search/hybrid-search.d.ts +49 -0
  181. package/dist/core/search/hybrid-search.js +118 -0
  182. package/dist/core/tree-sitter/parser-loader.d.ts +4 -0
  183. package/dist/core/tree-sitter/parser-loader.js +44 -0
  184. package/dist/core/wiki/generator.d.ts +110 -0
  185. package/dist/core/wiki/generator.js +786 -0
  186. package/dist/core/wiki/graph-queries.d.ts +80 -0
  187. package/dist/core/wiki/graph-queries.js +238 -0
  188. package/dist/core/wiki/html-viewer.d.ts +10 -0
  189. package/dist/core/wiki/html-viewer.js +297 -0
  190. package/dist/core/wiki/llm-client.d.ts +40 -0
  191. package/dist/core/wiki/llm-client.js +162 -0
  192. package/dist/core/wiki/prompts.d.ts +53 -0
  193. package/dist/core/wiki/prompts.js +174 -0
  194. package/dist/lib/utils.d.ts +1 -0
  195. package/dist/lib/utils.js +3 -0
  196. package/dist/mcp/core/embedder.d.ts +27 -0
  197. package/dist/mcp/core/embedder.js +108 -0
  198. package/dist/mcp/core/kuzu-adapter.d.ts +34 -0
  199. package/dist/mcp/core/kuzu-adapter.js +231 -0
  200. package/dist/mcp/local/local-backend.d.ts +160 -0
  201. package/dist/mcp/local/local-backend.js +1646 -0
  202. package/dist/mcp/resources.d.ts +31 -0
  203. package/dist/mcp/resources.js +407 -0
  204. package/dist/mcp/server.d.ts +23 -0
  205. package/dist/mcp/server.js +251 -0
  206. package/dist/mcp/staleness.d.ts +15 -0
  207. package/dist/mcp/staleness.js +29 -0
  208. package/dist/mcp/tools.d.ts +24 -0
  209. package/dist/mcp/tools.js +195 -0
  210. package/dist/server/api.d.ts +10 -0
  211. package/dist/server/api.js +344 -0
  212. package/dist/server/mcp-http.d.ts +13 -0
  213. package/dist/server/mcp-http.js +100 -0
  214. package/dist/storage/git.d.ts +6 -0
  215. package/dist/storage/git.js +32 -0
  216. package/dist/storage/repo-manager.d.ts +125 -0
  217. package/dist/storage/repo-manager.js +257 -0
  218. package/dist/types/pipeline.d.ts +34 -0
  219. package/dist/types/pipeline.js +18 -0
  220. package/hooks/claude/gitnexus-hook.cjs +135 -0
  221. package/hooks/claude/pre-tool-use.sh +78 -0
  222. package/hooks/claude/session-start.sh +42 -0
  223. package/package.json +92 -0
  224. package/skills/gitnexus-cli.md +82 -0
  225. package/skills/gitnexus-debugging.md +89 -0
  226. package/skills/gitnexus-exploring.md +78 -0
  227. package/skills/gitnexus-guide.md +64 -0
  228. package/skills/gitnexus-impact-analysis.md +97 -0
  229. package/skills/gitnexus-refactoring.md +121 -0
  230. package/vendor/leiden/index.cjs +355 -0
  231. package/vendor/leiden/utils.cjs +392 -0
@@ -0,0 +1,231 @@
1
+ /**
2
+ * KuzuDB Adapter (Connection Pool)
3
+ *
4
+ * Manages a pool of KuzuDB databases keyed by repoId, each with
5
+ * multiple Connection objects for safe concurrent query execution.
6
+ *
7
+ * KuzuDB Connections are NOT thread-safe — a single Connection
8
+ * segfaults if concurrent .query() calls hit it simultaneously.
9
+ * This adapter provides a checkout/return connection pool so each
10
+ * concurrent query gets its own Connection from the same Database.
11
+ *
12
+ * @see https://docs.kuzudb.com/concurrency — multiple Connections
13
+ * from the same Database is the officially supported concurrency pattern.
14
+ */
15
+ import fs from 'fs/promises';
16
+ import kuzu from 'kuzu';
17
+ const pool = new Map();
18
+ /** Max repos in the pool (LRU eviction) */
19
+ const MAX_POOL_SIZE = 5;
20
+ /** Idle timeout before closing a repo's connections */
21
+ const IDLE_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
22
+ /** Max connections per repo (caps concurrent queries per repo) */
23
+ const MAX_CONNS_PER_REPO = 8;
24
+ /** Connections created eagerly on init */
25
+ const INITIAL_CONNS_PER_REPO = 2;
26
+ let idleTimer = null;
27
+ /**
28
+ * Start the idle cleanup timer (runs every 60s)
29
+ */
30
+ function ensureIdleTimer() {
31
+ if (idleTimer)
32
+ return;
33
+ idleTimer = setInterval(() => {
34
+ const now = Date.now();
35
+ for (const [repoId, entry] of pool) {
36
+ if (now - entry.lastUsed > IDLE_TIMEOUT_MS) {
37
+ closeOne(repoId);
38
+ }
39
+ }
40
+ }, 60_000);
41
+ if (idleTimer && typeof idleTimer === 'object' && 'unref' in idleTimer) {
42
+ idleTimer.unref();
43
+ }
44
+ }
45
+ /**
46
+ * Evict the least-recently-used repo if pool is at capacity
47
+ */
48
+ function evictLRU() {
49
+ if (pool.size < MAX_POOL_SIZE)
50
+ return;
51
+ let oldestId = null;
52
+ let oldestTime = Infinity;
53
+ for (const [id, entry] of pool) {
54
+ if (entry.lastUsed < oldestTime) {
55
+ oldestTime = entry.lastUsed;
56
+ oldestId = id;
57
+ }
58
+ }
59
+ if (oldestId) {
60
+ closeOne(oldestId);
61
+ }
62
+ }
63
+ /**
64
+ * Close all connections for a repo and remove it from the pool
65
+ */
66
+ function closeOne(repoId) {
67
+ const entry = pool.get(repoId);
68
+ if (!entry)
69
+ return;
70
+ for (const conn of entry.available) {
71
+ try {
72
+ conn.close();
73
+ }
74
+ catch { }
75
+ }
76
+ try {
77
+ entry.db.close();
78
+ }
79
+ catch { }
80
+ pool.delete(repoId);
81
+ }
82
+ /**
83
+ * Create a new Connection from a repo's Database.
84
+ * Silences stdout to prevent native module output from corrupting MCP stdio.
85
+ */
86
+ function createConnection(db) {
87
+ const origWrite = process.stdout.write;
88
+ process.stdout.write = (() => true);
89
+ try {
90
+ return new kuzu.Connection(db);
91
+ }
92
+ finally {
93
+ process.stdout.write = origWrite;
94
+ }
95
+ }
96
+ const LOCK_RETRY_ATTEMPTS = 3;
97
+ const LOCK_RETRY_DELAY_MS = 2000;
98
+ /**
99
+ * Initialize (or reuse) a Database + connection pool for a specific repo.
100
+ * Retries on lock errors (e.g., when `gitnexus analyze` is running).
101
+ */
102
+ export const initKuzu = async (repoId, dbPath) => {
103
+ const existing = pool.get(repoId);
104
+ if (existing) {
105
+ existing.lastUsed = Date.now();
106
+ return;
107
+ }
108
+ // Check if database exists
109
+ try {
110
+ await fs.stat(dbPath);
111
+ }
112
+ catch {
113
+ throw new Error(`KuzuDB not found at ${dbPath}. Run: gitnexus analyze`);
114
+ }
115
+ evictLRU();
116
+ // Open in read-only mode — MCP server never writes to the database.
117
+ // This allows multiple MCP server instances to read concurrently, and
118
+ // avoids lock conflicts when `gitnexus analyze` is writing.
119
+ let lastError = null;
120
+ for (let attempt = 1; attempt <= LOCK_RETRY_ATTEMPTS; attempt++) {
121
+ const origWrite = process.stdout.write;
122
+ process.stdout.write = (() => true);
123
+ try {
124
+ const db = new kuzu.Database(dbPath, 0, // bufferManagerSize (default)
125
+ false, // enableCompression (default)
126
+ true);
127
+ process.stdout.write = origWrite;
128
+ // Pre-create a small pool of connections
129
+ const available = [];
130
+ for (let i = 0; i < INITIAL_CONNS_PER_REPO; i++) {
131
+ available.push(createConnection(db));
132
+ }
133
+ pool.set(repoId, { db, available, checkedOut: 0, waiters: [], lastUsed: Date.now(), dbPath });
134
+ ensureIdleTimer();
135
+ return;
136
+ }
137
+ catch (err) {
138
+ process.stdout.write = origWrite;
139
+ lastError = err instanceof Error ? err : new Error(String(err));
140
+ const isLockError = lastError.message.includes('Could not set lock')
141
+ || lastError.message.includes('lock');
142
+ if (!isLockError || attempt === LOCK_RETRY_ATTEMPTS)
143
+ break;
144
+ await new Promise(resolve => setTimeout(resolve, LOCK_RETRY_DELAY_MS * attempt));
145
+ }
146
+ }
147
+ throw new Error(`KuzuDB unavailable for ${repoId}. Another process may be rebuilding the index. ` +
148
+ `Retry later. (${lastError?.message || 'unknown error'})`);
149
+ };
150
+ /**
151
+ * Checkout a connection from the pool.
152
+ * Returns an available connection, or creates a new one if under the cap.
153
+ * If all connections are busy and at cap, queues the caller until one is returned.
154
+ */
155
+ function checkout(entry) {
156
+ // Fast path: grab an available connection
157
+ if (entry.available.length > 0) {
158
+ entry.checkedOut++;
159
+ return Promise.resolve(entry.available.pop());
160
+ }
161
+ // Grow the pool if under the cap
162
+ const totalConns = entry.available.length + entry.checkedOut;
163
+ if (totalConns < MAX_CONNS_PER_REPO) {
164
+ entry.checkedOut++;
165
+ return Promise.resolve(createConnection(entry.db));
166
+ }
167
+ // At capacity — queue the caller. checkin() will resolve this when
168
+ // a connection is returned, handing it directly to the next waiter.
169
+ return new Promise(resolve => {
170
+ entry.waiters.push(resolve);
171
+ });
172
+ }
173
+ /**
174
+ * Return a connection to the pool after use.
175
+ * If there are queued waiters, hand the connection directly to the next one
176
+ * instead of putting it back in the available array (avoids race conditions).
177
+ */
178
+ function checkin(entry, conn) {
179
+ if (entry.waiters.length > 0) {
180
+ // Hand directly to the next waiter — no intermediate available state
181
+ const waiter = entry.waiters.shift();
182
+ waiter(conn);
183
+ }
184
+ else {
185
+ entry.checkedOut--;
186
+ entry.available.push(conn);
187
+ }
188
+ }
189
+ /**
190
+ * Execute a query on a specific repo's connection pool.
191
+ * Automatically checks out a connection, runs the query, and returns it.
192
+ */
193
+ export const executeQuery = async (repoId, cypher) => {
194
+ const entry = pool.get(repoId);
195
+ if (!entry) {
196
+ throw new Error(`KuzuDB not initialized for repo "${repoId}". Call initKuzu first.`);
197
+ }
198
+ entry.lastUsed = Date.now();
199
+ const conn = await checkout(entry);
200
+ try {
201
+ const queryResult = await conn.query(cypher);
202
+ const result = Array.isArray(queryResult) ? queryResult[0] : queryResult;
203
+ const rows = await result.getAll();
204
+ return rows;
205
+ }
206
+ finally {
207
+ checkin(entry, conn);
208
+ }
209
+ };
210
+ /**
211
+ * Close one or all repo pools.
212
+ * If repoId is provided, close only that repo's connections.
213
+ * If omitted, close all repos.
214
+ */
215
+ export const closeKuzu = async (repoId) => {
216
+ if (repoId) {
217
+ closeOne(repoId);
218
+ return;
219
+ }
220
+ for (const id of [...pool.keys()]) {
221
+ closeOne(id);
222
+ }
223
+ if (idleTimer) {
224
+ clearInterval(idleTimer);
225
+ idleTimer = null;
226
+ }
227
+ };
228
+ /**
229
+ * Check if a specific repo's pool is active
230
+ */
231
+ export const isKuzuReady = (repoId) => pool.has(repoId);
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Local Backend (Multi-Repo)
3
+ *
4
+ * Provides tool implementations using local .gitnexus/ indexes.
5
+ * Supports multiple indexed repositories via a global registry.
6
+ * KuzuDB connections are opened lazily per repo on first query.
7
+ */
8
+ import { type RegistryEntry } from '../../storage/repo-manager.js';
9
+ export interface CodebaseContext {
10
+ projectName: string;
11
+ stats: {
12
+ fileCount: number;
13
+ functionCount: number;
14
+ communityCount: number;
15
+ processCount: number;
16
+ };
17
+ }
18
+ interface RepoHandle {
19
+ id: string;
20
+ name: string;
21
+ repoPath: string;
22
+ storagePath: string;
23
+ kuzuPath: string;
24
+ indexedAt: string;
25
+ lastCommit: string;
26
+ stats?: RegistryEntry['stats'];
27
+ }
28
+ export declare class LocalBackend {
29
+ private repos;
30
+ private contextCache;
31
+ private initializedRepos;
32
+ /**
33
+ * Initialize from the global registry.
34
+ * Returns true if at least one repo is available.
35
+ */
36
+ init(): Promise<boolean>;
37
+ /**
38
+ * Re-read the global registry and update the in-memory repo map.
39
+ * New repos are added, existing repos are updated, removed repos are pruned.
40
+ * KuzuDB connections for removed repos are NOT closed (they idle-timeout naturally).
41
+ */
42
+ private refreshRepos;
43
+ /**
44
+ * Generate a stable repo ID from name + path.
45
+ * If names collide, append a hash of the path.
46
+ */
47
+ private repoId;
48
+ /**
49
+ * Resolve which repo to use.
50
+ * - If repoParam is given, match by name or path
51
+ * - If only 1 repo, use it
52
+ * - If 0 or multiple without param, throw with helpful message
53
+ *
54
+ * On a miss, re-reads the registry once in case a new repo was indexed
55
+ * while the MCP server was running.
56
+ */
57
+ resolveRepo(repoParam?: string): Promise<RepoHandle>;
58
+ /**
59
+ * Try to resolve a repo from the in-memory cache. Returns null on miss.
60
+ */
61
+ private resolveRepoFromCache;
62
+ private ensureInitialized;
63
+ /**
64
+ * Get context for a specific repo (or the single repo if only one).
65
+ */
66
+ getContext(repoId?: string): CodebaseContext | null;
67
+ /**
68
+ * List all registered repos with their metadata.
69
+ * Re-reads the global registry so newly indexed repos are discovered
70
+ * without restarting the MCP server.
71
+ */
72
+ listRepos(): Promise<Array<{
73
+ name: string;
74
+ path: string;
75
+ indexedAt: string;
76
+ lastCommit: string;
77
+ stats?: any;
78
+ }>>;
79
+ callTool(method: string, params: any): Promise<any>;
80
+ /**
81
+ * Query tool — process-grouped search.
82
+ *
83
+ * 1. Hybrid search (BM25 + semantic) to find matching symbols
84
+ * 2. Trace each match to its process(es) via STEP_IN_PROCESS
85
+ * 3. Group by process, rank by aggregate relevance + internal cluster cohesion
86
+ * 4. Return: { processes, process_symbols, definitions }
87
+ */
88
+ private query;
89
+ /**
90
+ * BM25 keyword search helper - uses KuzuDB FTS for always-fresh results
91
+ */
92
+ private bm25Search;
93
+ /**
94
+ * Semantic vector search helper
95
+ */
96
+ private semanticSearch;
97
+ executeCypher(repoName: string, query: string): Promise<any>;
98
+ private cypher;
99
+ /**
100
+ * Format raw Cypher result rows as a markdown table for LLM readability.
101
+ * Falls back to raw result if rows aren't tabular objects.
102
+ */
103
+ private formatCypherAsMarkdown;
104
+ /**
105
+ * Aggregate same-named clusters: group by heuristicLabel, sum symbols,
106
+ * weighted-average cohesion, filter out tiny clusters (<5 symbols).
107
+ * Raw communities stay intact in KuzuDB for Cypher queries.
108
+ */
109
+ private aggregateClusters;
110
+ private overview;
111
+ /**
112
+ * Context tool — 360-degree symbol view with categorized refs.
113
+ * Disambiguation when multiple symbols share a name.
114
+ * UID-based direct lookup. No cluster in output.
115
+ */
116
+ private context;
117
+ /**
118
+ * Legacy explore — kept for backwards compatibility with resources.ts.
119
+ * Routes cluster/process types to direct graph queries.
120
+ */
121
+ private explore;
122
+ /**
123
+ * Detect changes — git-diff based impact analysis.
124
+ * Maps changed lines to indexed symbols, then finds affected processes.
125
+ */
126
+ private detectChanges;
127
+ /**
128
+ * Rename tool — multi-file coordinated rename using graph + text search.
129
+ * Graph refs are tagged "graph" (high confidence).
130
+ * Additional refs found via text search are tagged "text_search" (lower confidence).
131
+ */
132
+ private rename;
133
+ private impact;
134
+ /**
135
+ * Query clusters (communities) directly from graph.
136
+ * Used by getClustersResource — avoids legacy overview() dispatch.
137
+ */
138
+ queryClusters(repoName?: string, limit?: number): Promise<{
139
+ clusters: any[];
140
+ }>;
141
+ /**
142
+ * Query processes directly from graph.
143
+ * Used by getProcessesResource — avoids legacy overview() dispatch.
144
+ */
145
+ queryProcesses(repoName?: string, limit?: number): Promise<{
146
+ processes: any[];
147
+ }>;
148
+ /**
149
+ * Query cluster detail (members) directly from graph.
150
+ * Used by getClusterDetailResource.
151
+ */
152
+ queryClusterDetail(name: string, repoName?: string): Promise<any>;
153
+ /**
154
+ * Query process detail (steps) directly from graph.
155
+ * Used by getProcessDetailResource.
156
+ */
157
+ queryProcessDetail(name: string, repoName?: string): Promise<any>;
158
+ disconnect(): Promise<void>;
159
+ }
160
+ export {};