@mduenas/codegraph 0.4.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 (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +641 -0
  3. package/dist/bin/codegraph.d.ts +20 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +704 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/config.d.ts +51 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +291 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/context/formatter.d.ts +30 -0
  12. package/dist/context/formatter.d.ts.map +1 -0
  13. package/dist/context/formatter.js +244 -0
  14. package/dist/context/formatter.js.map +1 -0
  15. package/dist/context/index.d.ts +86 -0
  16. package/dist/context/index.d.ts.map +1 -0
  17. package/dist/context/index.js +402 -0
  18. package/dist/context/index.js.map +1 -0
  19. package/dist/db/index.d.ts +64 -0
  20. package/dist/db/index.d.ts.map +1 -0
  21. package/dist/db/index.js +170 -0
  22. package/dist/db/index.js.map +1 -0
  23. package/dist/db/migrations.d.ts +44 -0
  24. package/dist/db/migrations.d.ts.map +1 -0
  25. package/dist/db/migrations.js +105 -0
  26. package/dist/db/migrations.js.map +1 -0
  27. package/dist/db/queries.d.ts +148 -0
  28. package/dist/db/queries.d.ts.map +1 -0
  29. package/dist/db/queries.js +669 -0
  30. package/dist/db/queries.js.map +1 -0
  31. package/dist/directory.d.ts +45 -0
  32. package/dist/directory.d.ts.map +1 -0
  33. package/dist/directory.js +191 -0
  34. package/dist/directory.js.map +1 -0
  35. package/dist/errors.d.ts +136 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +219 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/extraction/grammars.d.ts +36 -0
  40. package/dist/extraction/grammars.d.ts.map +1 -0
  41. package/dist/extraction/grammars.js +181 -0
  42. package/dist/extraction/grammars.js.map +1 -0
  43. package/dist/extraction/index.d.ts +91 -0
  44. package/dist/extraction/index.d.ts.map +1 -0
  45. package/dist/extraction/index.js +493 -0
  46. package/dist/extraction/index.js.map +1 -0
  47. package/dist/extraction/tree-sitter.d.ts +176 -0
  48. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  49. package/dist/extraction/tree-sitter.js +1798 -0
  50. package/dist/extraction/tree-sitter.js.map +1 -0
  51. package/dist/graph/index.d.ts +8 -0
  52. package/dist/graph/index.d.ts.map +1 -0
  53. package/dist/graph/index.js +13 -0
  54. package/dist/graph/index.js.map +1 -0
  55. package/dist/graph/queries.d.ts +106 -0
  56. package/dist/graph/queries.d.ts.map +1 -0
  57. package/dist/graph/queries.js +355 -0
  58. package/dist/graph/queries.js.map +1 -0
  59. package/dist/graph/traversal.d.ts +127 -0
  60. package/dist/graph/traversal.d.ts.map +1 -0
  61. package/dist/graph/traversal.js +465 -0
  62. package/dist/graph/traversal.js.map +1 -0
  63. package/dist/index.d.ts +496 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +818 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/installer/banner.d.ts +40 -0
  68. package/dist/installer/banner.d.ts.map +1 -0
  69. package/dist/installer/banner.js +162 -0
  70. package/dist/installer/banner.js.map +1 -0
  71. package/dist/installer/claude-md-template.d.ts +10 -0
  72. package/dist/installer/claude-md-template.d.ts.map +1 -0
  73. package/dist/installer/claude-md-template.js +46 -0
  74. package/dist/installer/claude-md-template.js.map +1 -0
  75. package/dist/installer/config-writer.d.ts +36 -0
  76. package/dist/installer/config-writer.d.ts.map +1 -0
  77. package/dist/installer/config-writer.js +282 -0
  78. package/dist/installer/config-writer.js.map +1 -0
  79. package/dist/installer/index.d.ts +13 -0
  80. package/dist/installer/index.d.ts.map +1 -0
  81. package/dist/installer/index.js +155 -0
  82. package/dist/installer/index.js.map +1 -0
  83. package/dist/installer/prompts.d.ts +18 -0
  84. package/dist/installer/prompts.d.ts.map +1 -0
  85. package/dist/installer/prompts.js +113 -0
  86. package/dist/installer/prompts.js.map +1 -0
  87. package/dist/mcp/index.d.ts +64 -0
  88. package/dist/mcp/index.d.ts.map +1 -0
  89. package/dist/mcp/index.js +207 -0
  90. package/dist/mcp/index.js.map +1 -0
  91. package/dist/mcp/tools.d.ts +93 -0
  92. package/dist/mcp/tools.d.ts.map +1 -0
  93. package/dist/mcp/tools.js +442 -0
  94. package/dist/mcp/tools.js.map +1 -0
  95. package/dist/mcp/transport.d.ts +89 -0
  96. package/dist/mcp/transport.d.ts.map +1 -0
  97. package/dist/mcp/transport.js +170 -0
  98. package/dist/mcp/transport.js.map +1 -0
  99. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  100. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  101. package/dist/resolution/frameworks/csharp.js +274 -0
  102. package/dist/resolution/frameworks/csharp.js.map +1 -0
  103. package/dist/resolution/frameworks/express.d.ts +8 -0
  104. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  105. package/dist/resolution/frameworks/express.js +208 -0
  106. package/dist/resolution/frameworks/express.js.map +1 -0
  107. package/dist/resolution/frameworks/go.d.ts +8 -0
  108. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  109. package/dist/resolution/frameworks/go.js +225 -0
  110. package/dist/resolution/frameworks/go.js.map +1 -0
  111. package/dist/resolution/frameworks/index.d.ts +33 -0
  112. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  113. package/dist/resolution/frameworks/index.js +113 -0
  114. package/dist/resolution/frameworks/index.js.map +1 -0
  115. package/dist/resolution/frameworks/java.d.ts +8 -0
  116. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  117. package/dist/resolution/frameworks/java.js +239 -0
  118. package/dist/resolution/frameworks/java.js.map +1 -0
  119. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  120. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  121. package/dist/resolution/frameworks/laravel.js +198 -0
  122. package/dist/resolution/frameworks/laravel.js.map +1 -0
  123. package/dist/resolution/frameworks/python.d.ts +10 -0
  124. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  125. package/dist/resolution/frameworks/python.js +331 -0
  126. package/dist/resolution/frameworks/python.js.map +1 -0
  127. package/dist/resolution/frameworks/react.d.ts +8 -0
  128. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  129. package/dist/resolution/frameworks/react.js +294 -0
  130. package/dist/resolution/frameworks/react.js.map +1 -0
  131. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  132. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  133. package/dist/resolution/frameworks/ruby.js +262 -0
  134. package/dist/resolution/frameworks/ruby.js.map +1 -0
  135. package/dist/resolution/frameworks/rust.d.ts +8 -0
  136. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  137. package/dist/resolution/frameworks/rust.js +222 -0
  138. package/dist/resolution/frameworks/rust.js.map +1 -0
  139. package/dist/resolution/frameworks/swift.d.ts +10 -0
  140. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  141. package/dist/resolution/frameworks/swift.js +486 -0
  142. package/dist/resolution/frameworks/swift.js.map +1 -0
  143. package/dist/resolution/import-resolver.d.ts +20 -0
  144. package/dist/resolution/import-resolver.d.ts.map +1 -0
  145. package/dist/resolution/import-resolver.js +445 -0
  146. package/dist/resolution/import-resolver.js.map +1 -0
  147. package/dist/resolution/index.d.ts +72 -0
  148. package/dist/resolution/index.d.ts.map +1 -0
  149. package/dist/resolution/index.js +301 -0
  150. package/dist/resolution/index.js.map +1 -0
  151. package/dist/resolution/name-matcher.d.ts +27 -0
  152. package/dist/resolution/name-matcher.d.ts.map +1 -0
  153. package/dist/resolution/name-matcher.js +210 -0
  154. package/dist/resolution/name-matcher.js.map +1 -0
  155. package/dist/resolution/types.d.ts +108 -0
  156. package/dist/resolution/types.d.ts.map +1 -0
  157. package/dist/resolution/types.js +8 -0
  158. package/dist/resolution/types.js.map +1 -0
  159. package/dist/sync/git-hooks.d.ts +66 -0
  160. package/dist/sync/git-hooks.d.ts.map +1 -0
  161. package/dist/sync/git-hooks.js +281 -0
  162. package/dist/sync/git-hooks.js.map +1 -0
  163. package/dist/sync/index.d.ts +13 -0
  164. package/dist/sync/index.d.ts.map +1 -0
  165. package/dist/sync/index.js +18 -0
  166. package/dist/sync/index.js.map +1 -0
  167. package/dist/types.d.ts +410 -0
  168. package/dist/types.d.ts.map +1 -0
  169. package/dist/types.js +165 -0
  170. package/dist/types.js.map +1 -0
  171. package/dist/utils.d.ts +116 -0
  172. package/dist/utils.d.ts.map +1 -0
  173. package/dist/utils.js +295 -0
  174. package/dist/utils.js.map +1 -0
  175. package/dist/vectors/embedder.d.ts +140 -0
  176. package/dist/vectors/embedder.d.ts.map +1 -0
  177. package/dist/vectors/embedder.js +336 -0
  178. package/dist/vectors/embedder.js.map +1 -0
  179. package/dist/vectors/index.d.ts +9 -0
  180. package/dist/vectors/index.d.ts.map +1 -0
  181. package/dist/vectors/index.js +20 -0
  182. package/dist/vectors/index.js.map +1 -0
  183. package/dist/vectors/manager.d.ts +119 -0
  184. package/dist/vectors/manager.d.ts.map +1 -0
  185. package/dist/vectors/manager.js +274 -0
  186. package/dist/vectors/manager.js.map +1 -0
  187. package/dist/vectors/search.d.ts +134 -0
  188. package/dist/vectors/search.d.ts.map +1 -0
  189. package/dist/vectors/search.js +409 -0
  190. package/dist/vectors/search.js.map +1 -0
  191. package/package.json +67 -0
  192. package/scripts/postinstall.js +68 -0
@@ -0,0 +1,496 @@
1
+ /**
2
+ * CodeGraph
3
+ *
4
+ * A local-first code intelligence system that builds a semantic
5
+ * knowledge graph from any codebase.
6
+ */
7
+ import { CodeGraphConfig, Node, Edge, FileRecord, ExtractionResult, Subgraph, TraversalOptions, SearchOptions, SearchResult, Context, GraphStats, TaskInput, TaskContext, BuildContextOptions, FindRelevantContextOptions } from './types';
8
+ import { IndexProgress, IndexResult, SyncResult } from './extraction';
9
+ import { ResolutionResult } from './resolution';
10
+ import { EmbeddingProgress } from './vectors';
11
+ import { HookInstallResult, HookRemoveResult } from './sync';
12
+ export * from './types';
13
+ export { getDatabasePath } from './db';
14
+ export { getConfigPath } from './config';
15
+ export { getCodeGraphDir, isInitialized } from './directory';
16
+ export { IndexProgress, IndexResult, SyncResult } from './extraction';
17
+ export { detectLanguage, isLanguageSupported, getSupportedLanguages } from './extraction';
18
+ export { ResolutionResult } from './resolution';
19
+ export { EmbeddingProgress } from './vectors';
20
+ export { HookInstallResult, HookRemoveResult } from './sync';
21
+ export { CodeGraphError, FileError, ParseError, DatabaseError, SearchError, VectorError, ConfigError, Logger, setLogger, getLogger, silentLogger, defaultLogger, } from './errors';
22
+ export { Mutex, processInBatches, debounce, throttle, MemoryMonitor } from './utils';
23
+ export { MCPServer } from './mcp';
24
+ /**
25
+ * Options for initializing a new CodeGraph project
26
+ */
27
+ export interface InitOptions {
28
+ /** Custom configuration overrides */
29
+ config?: Partial<CodeGraphConfig>;
30
+ /** Whether to run initial indexing after init */
31
+ index?: boolean;
32
+ /** Progress callback for indexing */
33
+ onProgress?: (progress: IndexProgress) => void;
34
+ }
35
+ /**
36
+ * Options for opening an existing CodeGraph project
37
+ */
38
+ export interface OpenOptions {
39
+ /** Whether to run sync if files have changed */
40
+ sync?: boolean;
41
+ /** Whether to run in read-only mode */
42
+ readOnly?: boolean;
43
+ }
44
+ /**
45
+ * Options for indexing
46
+ */
47
+ export interface IndexOptions {
48
+ /** Progress callback */
49
+ onProgress?: (progress: IndexProgress) => void;
50
+ /** Abort signal for cancellation */
51
+ signal?: AbortSignal;
52
+ }
53
+ /**
54
+ * Main CodeGraph class
55
+ *
56
+ * Provides the primary interface for interacting with the code knowledge graph.
57
+ */
58
+ export declare class CodeGraph {
59
+ private db;
60
+ private queries;
61
+ private config;
62
+ private projectRoot;
63
+ private orchestrator;
64
+ private resolver;
65
+ private graphManager;
66
+ private traverser;
67
+ private vectorManager;
68
+ private contextBuilder;
69
+ private gitHooksManager;
70
+ private indexMutex;
71
+ private constructor();
72
+ /**
73
+ * Initialize a new CodeGraph project
74
+ *
75
+ * Creates the .codegraph directory, database, and configuration.
76
+ *
77
+ * @param projectRoot - Path to the project root directory
78
+ * @param options - Initialization options
79
+ * @returns A new CodeGraph instance
80
+ */
81
+ static init(projectRoot: string, options?: InitOptions): Promise<CodeGraph>;
82
+ /**
83
+ * Initialize synchronously (without indexing)
84
+ */
85
+ static initSync(projectRoot: string, options?: Omit<InitOptions, 'index' | 'onProgress'>): CodeGraph;
86
+ /**
87
+ * Open an existing CodeGraph project
88
+ *
89
+ * @param projectRoot - Path to the project root directory
90
+ * @param options - Open options
91
+ * @returns A CodeGraph instance
92
+ */
93
+ static open(projectRoot: string, options?: OpenOptions): Promise<CodeGraph>;
94
+ /**
95
+ * Open synchronously (without sync)
96
+ */
97
+ static openSync(projectRoot: string): CodeGraph;
98
+ /**
99
+ * Check if a directory has been initialized as a CodeGraph project
100
+ */
101
+ static isInitialized(projectRoot: string): boolean;
102
+ /**
103
+ * Close the CodeGraph instance and release resources
104
+ */
105
+ close(): void;
106
+ /**
107
+ * Get the current configuration
108
+ */
109
+ getConfig(): CodeGraphConfig;
110
+ /**
111
+ * Update configuration
112
+ */
113
+ updateConfig(updates: Partial<CodeGraphConfig>): void;
114
+ /**
115
+ * Get the project root directory
116
+ */
117
+ getProjectRoot(): string;
118
+ /**
119
+ * Index all files in the project
120
+ *
121
+ * Uses a mutex to prevent concurrent indexing operations.
122
+ */
123
+ indexAll(options?: IndexOptions): Promise<IndexResult>;
124
+ /**
125
+ * Index specific files
126
+ *
127
+ * Uses a mutex to prevent concurrent indexing operations.
128
+ */
129
+ indexFiles(filePaths: string[]): Promise<IndexResult>;
130
+ /**
131
+ * Sync with current file state (incremental update)
132
+ *
133
+ * Uses a mutex to prevent concurrent indexing operations.
134
+ */
135
+ sync(options?: IndexOptions): Promise<SyncResult>;
136
+ /**
137
+ * Check if an indexing operation is currently in progress
138
+ */
139
+ isIndexing(): boolean;
140
+ /**
141
+ * Get files that have changed since last index
142
+ */
143
+ getChangedFiles(): {
144
+ added: string[];
145
+ modified: string[];
146
+ removed: string[];
147
+ };
148
+ /**
149
+ * Extract nodes and edges from source code (without storing)
150
+ */
151
+ extractFromSource(filePath: string, source: string): ExtractionResult;
152
+ /**
153
+ * Resolve unresolved references and create edges
154
+ *
155
+ * This method takes unresolved references from extraction and attempts
156
+ * to resolve them using multiple strategies:
157
+ * - Framework-specific patterns (React, Express, Laravel)
158
+ * - Import-based resolution
159
+ * - Name-based symbol matching
160
+ */
161
+ resolveReferences(): ResolutionResult;
162
+ /**
163
+ * Get detected frameworks in the project
164
+ */
165
+ getDetectedFrameworks(): string[];
166
+ /**
167
+ * Re-initialize the resolver (useful after adding new files)
168
+ */
169
+ reinitializeResolver(): void;
170
+ /**
171
+ * Get statistics about the knowledge graph
172
+ */
173
+ getStats(): GraphStats;
174
+ /**
175
+ * Get a node by ID
176
+ */
177
+ getNode(id: string): Node | null;
178
+ /**
179
+ * Get all nodes in a file
180
+ */
181
+ getNodesInFile(filePath: string): Node[];
182
+ /**
183
+ * Get all nodes of a specific kind
184
+ */
185
+ getNodesByKind(kind: Node['kind']): Node[];
186
+ /**
187
+ * Search nodes by text
188
+ */
189
+ searchNodes(query: string, options?: SearchOptions): SearchResult[];
190
+ /**
191
+ * Get outgoing edges from a node
192
+ */
193
+ getOutgoingEdges(nodeId: string): Edge[];
194
+ /**
195
+ * Get incoming edges to a node
196
+ */
197
+ getIncomingEdges(nodeId: string): Edge[];
198
+ /**
199
+ * Get a file record by path
200
+ */
201
+ getFile(filePath: string): FileRecord | null;
202
+ /**
203
+ * Get all tracked files
204
+ */
205
+ getFiles(): FileRecord[];
206
+ /**
207
+ * Get the context for a node (ancestors, children, references)
208
+ *
209
+ * Returns comprehensive context about a node including its containment
210
+ * hierarchy, children, incoming/outgoing references, type information,
211
+ * and relevant imports.
212
+ *
213
+ * @param nodeId - ID of the focal node
214
+ * @returns Context object with all related information
215
+ */
216
+ getContext(nodeId: string): Context;
217
+ /**
218
+ * Traverse the graph from a starting node
219
+ *
220
+ * Uses breadth-first search by default. Supports filtering by edge types,
221
+ * node types, and traversal direction.
222
+ *
223
+ * @param startId - Starting node ID
224
+ * @param options - Traversal options
225
+ * @returns Subgraph containing traversed nodes and edges
226
+ */
227
+ traverse(startId: string, options?: TraversalOptions): Subgraph;
228
+ /**
229
+ * Get the call graph for a function
230
+ *
231
+ * Returns both callers (functions that call this function) and
232
+ * callees (functions called by this function) up to the specified depth.
233
+ *
234
+ * @param nodeId - ID of the function/method node
235
+ * @param depth - Maximum depth in each direction (default: 2)
236
+ * @returns Subgraph containing the call graph
237
+ */
238
+ getCallGraph(nodeId: string, depth?: number): Subgraph;
239
+ /**
240
+ * Get the type hierarchy for a class/interface
241
+ *
242
+ * Returns both ancestors (types this extends/implements) and
243
+ * descendants (types that extend/implement this).
244
+ *
245
+ * @param nodeId - ID of the class/interface node
246
+ * @returns Subgraph containing the type hierarchy
247
+ */
248
+ getTypeHierarchy(nodeId: string): Subgraph;
249
+ /**
250
+ * Find all usages of a symbol
251
+ *
252
+ * Returns all nodes that reference the specified symbol through
253
+ * any edge type (calls, references, type_of, etc.).
254
+ *
255
+ * @param nodeId - ID of the symbol node
256
+ * @returns Array of nodes and edges that reference this symbol
257
+ */
258
+ findUsages(nodeId: string): Array<{
259
+ node: Node;
260
+ edge: Edge;
261
+ }>;
262
+ /**
263
+ * Get callers of a function/method
264
+ *
265
+ * @param nodeId - ID of the function/method node
266
+ * @param maxDepth - Maximum depth to traverse (default: 1)
267
+ * @returns Array of nodes that call this function
268
+ */
269
+ getCallers(nodeId: string, maxDepth?: number): Array<{
270
+ node: Node;
271
+ edge: Edge;
272
+ }>;
273
+ /**
274
+ * Get callees of a function/method
275
+ *
276
+ * @param nodeId - ID of the function/method node
277
+ * @param maxDepth - Maximum depth to traverse (default: 1)
278
+ * @returns Array of nodes called by this function
279
+ */
280
+ getCallees(nodeId: string, maxDepth?: number): Array<{
281
+ node: Node;
282
+ edge: Edge;
283
+ }>;
284
+ /**
285
+ * Calculate the impact radius of a node
286
+ *
287
+ * Returns all nodes that could be affected by changes to this node.
288
+ *
289
+ * @param nodeId - ID of the node
290
+ * @param maxDepth - Maximum depth to traverse (default: 3)
291
+ * @returns Subgraph containing potentially impacted nodes
292
+ */
293
+ getImpactRadius(nodeId: string, maxDepth?: number): Subgraph;
294
+ /**
295
+ * Find the shortest path between two nodes
296
+ *
297
+ * @param fromId - Starting node ID
298
+ * @param toId - Target node ID
299
+ * @param edgeKinds - Edge types to consider (all if empty)
300
+ * @returns Array of nodes and edges forming the path, or null if no path exists
301
+ */
302
+ findPath(fromId: string, toId: string, edgeKinds?: Edge['kind'][]): Array<{
303
+ node: Node;
304
+ edge: Edge | null;
305
+ }> | null;
306
+ /**
307
+ * Get ancestors of a node in the containment hierarchy
308
+ *
309
+ * @param nodeId - ID of the node
310
+ * @returns Array of ancestor nodes from immediate parent to root
311
+ */
312
+ getAncestors(nodeId: string): Node[];
313
+ /**
314
+ * Get immediate children of a node
315
+ *
316
+ * @param nodeId - ID of the node
317
+ * @returns Array of child nodes
318
+ */
319
+ getChildren(nodeId: string): Node[];
320
+ /**
321
+ * Get dependencies of a file
322
+ *
323
+ * @param filePath - Path to the file
324
+ * @returns Array of file paths this file depends on
325
+ */
326
+ getFileDependencies(filePath: string): string[];
327
+ /**
328
+ * Get dependents of a file
329
+ *
330
+ * @param filePath - Path to the file
331
+ * @returns Array of file paths that depend on this file
332
+ */
333
+ getFileDependents(filePath: string): string[];
334
+ /**
335
+ * Find circular dependencies in the codebase
336
+ *
337
+ * @returns Array of cycles, each cycle is an array of file paths
338
+ */
339
+ findCircularDependencies(): string[][];
340
+ /**
341
+ * Find dead code (unreferenced symbols)
342
+ *
343
+ * @param kinds - Node kinds to check (default: functions, methods, classes)
344
+ * @returns Array of unreferenced nodes
345
+ */
346
+ findDeadCode(kinds?: Node['kind'][]): Node[];
347
+ /**
348
+ * Get complexity metrics for a node
349
+ *
350
+ * @param nodeId - ID of the node
351
+ * @returns Object containing various complexity metrics
352
+ */
353
+ getNodeMetrics(nodeId: string): {
354
+ incomingEdgeCount: number;
355
+ outgoingEdgeCount: number;
356
+ callCount: number;
357
+ callerCount: number;
358
+ childCount: number;
359
+ depth: number;
360
+ };
361
+ /**
362
+ * Initialize the embedding system
363
+ *
364
+ * This downloads the embedding model on first use and initializes
365
+ * the vector search system. Must be called before using semantic search.
366
+ */
367
+ initializeEmbeddings(): Promise<void>;
368
+ /**
369
+ * Check if embeddings are initialized
370
+ */
371
+ isEmbeddingsInitialized(): boolean;
372
+ /**
373
+ * Generate embeddings for all eligible nodes
374
+ *
375
+ * @param onProgress - Optional progress callback
376
+ * @returns Number of nodes embedded
377
+ */
378
+ generateEmbeddings(onProgress?: (progress: EmbeddingProgress) => void): Promise<number>;
379
+ /**
380
+ * Semantic search using embeddings
381
+ *
382
+ * Searches for code nodes semantically similar to the query.
383
+ * Requires embeddings to be initialized first.
384
+ *
385
+ * @param query - Natural language search query
386
+ * @param limit - Maximum number of results (default: 10)
387
+ * @returns Array of search results with similarity scores
388
+ */
389
+ semanticSearch(query: string, limit?: number): Promise<SearchResult[]>;
390
+ /**
391
+ * Find similar code blocks
392
+ *
393
+ * Finds nodes semantically similar to a given node.
394
+ * Requires embeddings to be initialized first.
395
+ *
396
+ * @param nodeId - ID of the node to find similar nodes for
397
+ * @param limit - Maximum number of results (default: 10)
398
+ * @returns Array of similar nodes with similarity scores
399
+ */
400
+ findSimilar(nodeId: string, limit?: number): Promise<SearchResult[]>;
401
+ /**
402
+ * Get vector embedding statistics
403
+ */
404
+ getEmbeddingStats(): {
405
+ totalVectors: number;
406
+ vssEnabled: boolean;
407
+ modelId: string;
408
+ dimension: number;
409
+ } | null;
410
+ /**
411
+ * Get the source code for a node
412
+ *
413
+ * Reads the file and extracts the code between startLine and endLine.
414
+ *
415
+ * @param nodeId - ID of the node
416
+ * @returns Code string or null if not found
417
+ */
418
+ getCode(nodeId: string): Promise<string | null>;
419
+ /**
420
+ * Find relevant subgraph for a query
421
+ *
422
+ * Combines semantic search with graph traversal to find the most
423
+ * relevant nodes and their relationships for a given query.
424
+ *
425
+ * @param query - Natural language query describing the task
426
+ * @param options - Search and traversal options
427
+ * @returns Subgraph of relevant nodes and edges
428
+ */
429
+ findRelevantContext(query: string, options?: FindRelevantContextOptions): Promise<Subgraph>;
430
+ /**
431
+ * Build context for a task
432
+ *
433
+ * Creates comprehensive context by:
434
+ * 1. Running semantic search to find entry points
435
+ * 2. Expanding the graph around entry points
436
+ * 3. Extracting code blocks for key nodes
437
+ * 4. Formatting output for Claude
438
+ *
439
+ * @param input - Task description (string or {title, description})
440
+ * @param options - Build options (maxNodes, includeCode, format, etc.)
441
+ * @returns TaskContext object or formatted string (markdown/JSON)
442
+ */
443
+ buildContext(input: TaskInput, options?: BuildContextOptions): Promise<TaskContext | string>;
444
+ /**
445
+ * Check if the project is a git repository
446
+ */
447
+ isGitRepository(): boolean;
448
+ /**
449
+ * Check if the CodeGraph git hook is installed
450
+ */
451
+ isGitHookInstalled(): boolean;
452
+ /**
453
+ * Install git hooks for automatic incremental indexing
454
+ *
455
+ * Installs a post-commit hook that automatically runs `codegraph sync`
456
+ * after each commit to keep the graph up-to-date.
457
+ *
458
+ * If a post-commit hook already exists:
459
+ * - If it's a CodeGraph hook, it will be updated
460
+ * - If it's a user hook, it will be backed up before installing
461
+ *
462
+ * @returns Result indicating success/failure and any messages
463
+ */
464
+ installGitHooks(): HookInstallResult;
465
+ /**
466
+ * Remove CodeGraph git hooks
467
+ *
468
+ * Removes the CodeGraph post-commit hook. If a backup of a previous
469
+ * user hook exists, it will be restored.
470
+ *
471
+ * @returns Result indicating success/failure and any messages
472
+ */
473
+ removeGitHooks(): HookRemoveResult;
474
+ /**
475
+ * Optimize the database (vacuum and analyze)
476
+ */
477
+ optimize(): void;
478
+ /**
479
+ * Clear all data from the graph
480
+ */
481
+ clear(): void;
482
+ /**
483
+ * Alias for close() for backwards compatibility.
484
+ * @deprecated Use close() instead
485
+ */
486
+ destroy(): void;
487
+ /**
488
+ * Completely remove CodeGraph from the project.
489
+ * This closes the database and deletes the .codegraph directory.
490
+ *
491
+ * WARNING: This permanently deletes all CodeGraph data for the project.
492
+ */
493
+ uninitialize(): void;
494
+ }
495
+ export default CodeGraph;
496
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,eAAe,EACf,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,UAAU,EACV,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAUjB,OAAO,EAEL,aAAa,EACb,WAAW,EACX,UAAU,EAEX,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAsC,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAElF,OAAO,EAA0C,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAIrG,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EA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