@colbymchenry/codegraph 0.9.7 → 0.9.9
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.
- package/README.md +116 -32
- package/dist/bin/codegraph.d.ts +25 -0
- package/dist/bin/node-version-check.d.ts +37 -0
- package/dist/bin/uninstall.d.ts +14 -0
- package/dist/context/formatter.d.ts +30 -0
- package/dist/context/index.d.ts +119 -0
- package/dist/context/markers.d.ts +19 -0
- package/dist/db/index.d.ts +101 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/queries.d.ts +344 -0
- package/dist/db/sqlite-adapter.d.ts +46 -0
- package/dist/directory.d.ts +57 -0
- package/dist/errors.d.ts +136 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/grammars.d.ts +100 -0
- package/dist/extraction/index.d.ts +138 -0
- package/dist/extraction/languages/c-cpp.d.ts +4 -0
- package/dist/extraction/languages/csharp.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/scala.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/typescript.d.ts +3 -0
- package/dist/extraction/liquid-extractor.d.ts +52 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/svelte-extractor.d.ts +56 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-types.d.ts +193 -0
- package/dist/extraction/tree-sitter.d.ts +317 -0
- package/dist/extraction/vue-extractor.d.ts +36 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/queries.d.ts +106 -0
- package/dist/graph/traversal.d.ts +127 -0
- package/dist/index.d.ts +498 -0
- package/dist/installer/config-writer.d.ts +28 -0
- package/dist/installer/index.d.ts +100 -0
- package/dist/installer/instructions-template.d.ts +18 -0
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/claude.d.ts +56 -0
- package/dist/installer/targets/codex.d.ts +18 -0
- package/dist/installer/targets/cursor.d.ts +35 -0
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/opencode.d.ts +30 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/shared.d.ts +77 -0
- package/dist/installer/targets/toml.d.ts +52 -0
- package/dist/installer/targets/types.d.ts +101 -0
- package/dist/mcp/daemon-paths.d.ts +46 -0
- package/dist/mcp/daemon.d.ts +161 -0
- package/dist/mcp/engine.d.ts +105 -0
- package/dist/mcp/index.d.ts +112 -0
- package/dist/mcp/proxy.d.ts +81 -0
- package/dist/mcp/server-instructions.d.ts +19 -0
- package/dist/mcp/session.d.ts +77 -0
- package/dist/mcp/tools.d.ts +413 -0
- package/dist/mcp/transport.d.ts +188 -0
- package/dist/mcp/version.d.ts +19 -0
- package/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
- package/dist/resolution/frameworks/csharp.d.ts +8 -0
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/express.d.ts +8 -0
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/go.d.ts +8 -0
- package/dist/resolution/frameworks/index.d.ts +48 -0
- package/dist/resolution/frameworks/java.d.ts +8 -0
- package/dist/resolution/frameworks/laravel.d.ts +13 -0
- package/dist/resolution/frameworks/nestjs.d.ts +26 -0
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/python.d.ts +10 -0
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react.d.ts +8 -0
- package/dist/resolution/frameworks/ruby.d.ts +8 -0
- package/dist/resolution/frameworks/rust.d.ts +8 -0
- package/dist/resolution/frameworks/svelte.d.ts +9 -0
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift.d.ts +10 -0
- package/dist/resolution/frameworks/vue.d.ts +9 -0
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/import-resolver.d.ts +68 -0
- package/dist/resolution/index.d.ts +116 -0
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/name-matcher.d.ts +32 -0
- package/dist/resolution/path-aliases.d.ts +68 -0
- package/dist/resolution/strip-comments.d.ts +27 -0
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/types.d.ts +209 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-utils.d.ts +71 -0
- package/dist/sync/git-hooks.d.ts +45 -0
- package/dist/sync/index.d.ts +19 -0
- package/dist/sync/watch-policy.d.ts +48 -0
- package/dist/sync/watcher.d.ts +191 -0
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/types.d.ts +377 -0
- package/dist/ui/glyphs.d.ts +42 -0
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/types.d.ts +17 -0
- package/dist/utils.d.ts +205 -0
- package/npm-sdk.js +75 -0
- package/package.json +18 -7
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Queries
|
|
3
|
+
*
|
|
4
|
+
* Prepared statements for CRUD operations on the knowledge graph.
|
|
5
|
+
*/
|
|
6
|
+
import { SqliteDatabase } from './sqlite-adapter';
|
|
7
|
+
import { Node, Edge, FileRecord, UnresolvedReference, NodeKind, EdgeKind, GraphStats, SearchOptions, SearchResult } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Query builder for the knowledge graph database
|
|
10
|
+
*/
|
|
11
|
+
export declare class QueryBuilder {
|
|
12
|
+
private db;
|
|
13
|
+
private nodeCache;
|
|
14
|
+
private readonly maxCacheSize;
|
|
15
|
+
private stmts;
|
|
16
|
+
constructor(db: SqliteDatabase);
|
|
17
|
+
/**
|
|
18
|
+
* Insert a new node
|
|
19
|
+
*/
|
|
20
|
+
insertNode(node: Node): void;
|
|
21
|
+
/**
|
|
22
|
+
* Insert multiple nodes in a transaction
|
|
23
|
+
*/
|
|
24
|
+
insertNodes(nodes: Node[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Update an existing node
|
|
27
|
+
*/
|
|
28
|
+
updateNode(node: Node): void;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a node by ID
|
|
31
|
+
*/
|
|
32
|
+
deleteNode(id: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Delete all nodes for a file
|
|
35
|
+
*/
|
|
36
|
+
deleteNodesByFile(filePath: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get a node by ID
|
|
39
|
+
*/
|
|
40
|
+
getNodeById(id: string): Node | null;
|
|
41
|
+
/**
|
|
42
|
+
* Batch lookup: fetch many nodes by ID in a single SQL round-trip.
|
|
43
|
+
*
|
|
44
|
+
* Replaces the N+1 pattern in graph traversal where every edge would
|
|
45
|
+
* trigger its own `getNodeById` call. For a function with 50 callers
|
|
46
|
+
* this collapses 50 point reads into one IN-list query (~10-50x
|
|
47
|
+
* faster end-to-end).
|
|
48
|
+
*
|
|
49
|
+
* Returns a Map keyed by id so callers can preserve their own ordering
|
|
50
|
+
* (typically the order edges were returned from the graph). Missing IDs
|
|
51
|
+
* are simply absent from the map.
|
|
52
|
+
*
|
|
53
|
+
* Cache-aware: ids already in the LRU cache are served from memory and
|
|
54
|
+
* the SQL query only touches the misses.
|
|
55
|
+
*/
|
|
56
|
+
getNodesByIds(ids: readonly string[]): Map<string, Node>;
|
|
57
|
+
private getExistingNodeIds;
|
|
58
|
+
/**
|
|
59
|
+
* Add a node to the cache, evicting oldest if needed
|
|
60
|
+
*/
|
|
61
|
+
private cacheNode;
|
|
62
|
+
/**
|
|
63
|
+
* Clear the node cache
|
|
64
|
+
*/
|
|
65
|
+
clearCache(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get all nodes in a file
|
|
68
|
+
*/
|
|
69
|
+
getNodesByFile(filePath: string): Node[];
|
|
70
|
+
/**
|
|
71
|
+
* Find the file that holds the densest concentration of the project's
|
|
72
|
+
* internal call graph — the "core" file. Used by context-builder to
|
|
73
|
+
* boost ranking of symbols in that file's directory (so e.g. sinatra
|
|
74
|
+
* queries surface `lib/sinatra/base.rb`'s `route!` instead of
|
|
75
|
+
* `sinatra-contrib/lib/sinatra/multi_route.rb`'s `route` extension).
|
|
76
|
+
*
|
|
77
|
+
* Returns null if no file has a meaningful concentration (e.g. spread
|
|
78
|
+
* evenly across many files, or empty index).
|
|
79
|
+
*
|
|
80
|
+
* "Internal" = source and target are in the same file. Cross-file
|
|
81
|
+
* edges aren't useful here — they don't tell us which file is the
|
|
82
|
+
* functional center.
|
|
83
|
+
*
|
|
84
|
+
* Excludes test/spec files from candidacy via path-pattern. The agent's
|
|
85
|
+
* typical question is "how does X work", not "how is X tested", so
|
|
86
|
+
* boosting a test file's directory would be a misfire.
|
|
87
|
+
*/
|
|
88
|
+
getDominantFile(): {
|
|
89
|
+
filePath: string;
|
|
90
|
+
edgeCount: number;
|
|
91
|
+
nextEdgeCount: number;
|
|
92
|
+
} | null;
|
|
93
|
+
/**
|
|
94
|
+
* Find the file that holds the densest concentration of the project's
|
|
95
|
+
* `route` nodes (framework-emitted: Express/Gin/Flask/Rails/Drupal/etc.).
|
|
96
|
+
* Used by handleContext on small repos to inline the project's routing
|
|
97
|
+
* config when the agent's query is about request flow — eliminating the
|
|
98
|
+
* "Glob + Read routes.rb" pattern that beats codegraph on tiny realworld
|
|
99
|
+
* template repos.
|
|
100
|
+
*
|
|
101
|
+
* Excludes test/generated files from candidacy. Returns null if there
|
|
102
|
+
* are fewer than 3 non-test routes total, or if no file holds at least
|
|
103
|
+
* 30% of them (diffuse routing → no single answer file).
|
|
104
|
+
*/
|
|
105
|
+
getTopRouteFile(): {
|
|
106
|
+
filePath: string;
|
|
107
|
+
routeCount: number;
|
|
108
|
+
totalRoutes: number;
|
|
109
|
+
} | null;
|
|
110
|
+
/**
|
|
111
|
+
* Build a URL → handler manifest from the index. Each route node's
|
|
112
|
+
* `references` edge points at the function/method that handles the
|
|
113
|
+
* request. We join them in one pass; the agent gets the canonical
|
|
114
|
+
* routing answer ("POST /users/login → AuthController#login") without
|
|
115
|
+
* having to parse the framework's route DSL itself.
|
|
116
|
+
*
|
|
117
|
+
* Also returns the file with the most handler endpoints — used as the
|
|
118
|
+
* "top handler file" to inline source for, so the agent has both the
|
|
119
|
+
* mapping AND the handler implementations.
|
|
120
|
+
*/
|
|
121
|
+
getRoutingManifest(limit?: number): {
|
|
122
|
+
entries: Array<{
|
|
123
|
+
url: string;
|
|
124
|
+
handler: string;
|
|
125
|
+
handlerFile: string;
|
|
126
|
+
handlerLine: number;
|
|
127
|
+
handlerKind: string;
|
|
128
|
+
}>;
|
|
129
|
+
topHandlerFile: string | null;
|
|
130
|
+
topHandlerFileCount: number;
|
|
131
|
+
totalRoutes: number;
|
|
132
|
+
} | null;
|
|
133
|
+
/**
|
|
134
|
+
* Get all nodes of a specific kind
|
|
135
|
+
*/
|
|
136
|
+
getNodesByKind(kind: NodeKind): Node[];
|
|
137
|
+
/**
|
|
138
|
+
* Get all nodes in the database
|
|
139
|
+
*/
|
|
140
|
+
getAllNodes(): Node[];
|
|
141
|
+
/**
|
|
142
|
+
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
143
|
+
*/
|
|
144
|
+
getNodesByName(name: string): Node[];
|
|
145
|
+
/**
|
|
146
|
+
* Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
|
|
147
|
+
*/
|
|
148
|
+
getNodesByQualifiedNameExact(qualifiedName: string): Node[];
|
|
149
|
+
/**
|
|
150
|
+
* Get nodes by lowercase name match (uses idx_nodes_lower_name expression index)
|
|
151
|
+
*/
|
|
152
|
+
getNodesByLowerName(lowerName: string): Node[];
|
|
153
|
+
/**
|
|
154
|
+
* Search nodes by name using FTS with fallback to LIKE for better matching
|
|
155
|
+
*
|
|
156
|
+
* Search strategy:
|
|
157
|
+
* 1. Try FTS5 prefix match (query*) for word-start matching
|
|
158
|
+
* 2. If no results, try LIKE for substring matching (e.g., "signIn" finds "signInWithGoogle")
|
|
159
|
+
* 3. Score results based on match quality
|
|
160
|
+
*/
|
|
161
|
+
searchNodes(query: string, options?: SearchOptions): SearchResult[];
|
|
162
|
+
/**
|
|
163
|
+
* Match-everything path used when the user supplied only field
|
|
164
|
+
* filters (`kind:function lang:typescript`) with no text. Returns
|
|
165
|
+
* candidates ordered by name; the caller's filter pass narrows to
|
|
166
|
+
* what was asked for.
|
|
167
|
+
*/
|
|
168
|
+
private searchAllByFilters;
|
|
169
|
+
/**
|
|
170
|
+
* Fuzzy fallback: when zero FTS/LIKE hits, try an edit-distance
|
|
171
|
+
* sweep over the distinct symbol-name set. Caps `maxDist` at 2 so
|
|
172
|
+
* `getUssr` finds `getUser` but `process` doesn't match `prosody`.
|
|
173
|
+
* Bounded edit distance keeps each comparison cheap; the per-query
|
|
174
|
+
* scan is O(distinct-name-count) which is far smaller than total
|
|
175
|
+
* node count on any real codebase.
|
|
176
|
+
*/
|
|
177
|
+
private searchNodesFuzzy;
|
|
178
|
+
/**
|
|
179
|
+
* FTS5 search with prefix matching
|
|
180
|
+
*/
|
|
181
|
+
private searchNodesFTS;
|
|
182
|
+
/**
|
|
183
|
+
* LIKE-based substring search for cases where FTS doesn't match
|
|
184
|
+
* Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
|
|
185
|
+
*/
|
|
186
|
+
private searchNodesLike;
|
|
187
|
+
/**
|
|
188
|
+
* Find nodes by exact name match
|
|
189
|
+
*
|
|
190
|
+
* Used for hybrid search - looks up symbols by exact name or case-insensitive match.
|
|
191
|
+
* Returns high-confidence matches for known symbol names extracted from query.
|
|
192
|
+
*
|
|
193
|
+
* @param names - Array of symbol names to look up
|
|
194
|
+
* @param options - Search options (kinds, languages, limit)
|
|
195
|
+
* @returns SearchResult array with exact matches scored at 1.0
|
|
196
|
+
*/
|
|
197
|
+
findNodesByExactName(names: string[], options?: SearchOptions): SearchResult[];
|
|
198
|
+
/**
|
|
199
|
+
* Find nodes whose name contains a substring (LIKE-based).
|
|
200
|
+
* Useful for CamelCase-part matching where FTS fails because
|
|
201
|
+
* e.g. "TransportSearchAction" is one FTS token, not matchable by "Search"*.
|
|
202
|
+
*
|
|
203
|
+
* Results are ordered by name length (shorter = more likely to be the core type).
|
|
204
|
+
*/
|
|
205
|
+
findNodesByNameSubstring(substring: string, options?: SearchOptions & {
|
|
206
|
+
excludePrefix?: boolean;
|
|
207
|
+
}): SearchResult[];
|
|
208
|
+
/**
|
|
209
|
+
* Insert a new edge
|
|
210
|
+
*/
|
|
211
|
+
insertEdge(edge: Edge): void;
|
|
212
|
+
/**
|
|
213
|
+
* Insert multiple edges in a transaction
|
|
214
|
+
*/
|
|
215
|
+
insertEdges(edges: Edge[]): void;
|
|
216
|
+
/**
|
|
217
|
+
* Delete all edges from a source node
|
|
218
|
+
*/
|
|
219
|
+
deleteEdgesBySource(sourceId: string): void;
|
|
220
|
+
/**
|
|
221
|
+
* Get outgoing edges from a node
|
|
222
|
+
*/
|
|
223
|
+
getOutgoingEdges(sourceId: string, kinds?: EdgeKind[], provenance?: string): Edge[];
|
|
224
|
+
/**
|
|
225
|
+
* Get incoming edges to a node
|
|
226
|
+
*/
|
|
227
|
+
getIncomingEdges(targetId: string, kinds?: EdgeKind[]): Edge[];
|
|
228
|
+
/**
|
|
229
|
+
* Find all edges where both source and target are in the given node set.
|
|
230
|
+
* Useful for recovering inter-node connectivity after BFS.
|
|
231
|
+
*/
|
|
232
|
+
findEdgesBetweenNodes(nodeIds: string[], kinds?: EdgeKind[]): Edge[];
|
|
233
|
+
/**
|
|
234
|
+
* Insert or update a file record
|
|
235
|
+
*/
|
|
236
|
+
upsertFile(file: FileRecord): void;
|
|
237
|
+
/**
|
|
238
|
+
* Delete a file record and its nodes
|
|
239
|
+
*/
|
|
240
|
+
deleteFile(filePath: string): void;
|
|
241
|
+
/**
|
|
242
|
+
* Get a file record by path
|
|
243
|
+
*/
|
|
244
|
+
getFileByPath(filePath: string): FileRecord | null;
|
|
245
|
+
/**
|
|
246
|
+
* Get all tracked files
|
|
247
|
+
*/
|
|
248
|
+
getAllFiles(): FileRecord[];
|
|
249
|
+
/**
|
|
250
|
+
* Get files that need re-indexing (hash changed)
|
|
251
|
+
*/
|
|
252
|
+
getStaleFiles(currentHashes: Map<string, string>): FileRecord[];
|
|
253
|
+
/**
|
|
254
|
+
* Insert an unresolved reference
|
|
255
|
+
*/
|
|
256
|
+
insertUnresolvedRef(ref: UnresolvedReference): void;
|
|
257
|
+
/**
|
|
258
|
+
* Insert multiple unresolved references in a transaction
|
|
259
|
+
*/
|
|
260
|
+
insertUnresolvedRefsBatch(refs: UnresolvedReference[]): void;
|
|
261
|
+
/**
|
|
262
|
+
* Delete unresolved references from a node
|
|
263
|
+
*/
|
|
264
|
+
deleteUnresolvedByNode(nodeId: string): void;
|
|
265
|
+
/**
|
|
266
|
+
* Get unresolved references by name (for resolution)
|
|
267
|
+
*/
|
|
268
|
+
getUnresolvedByName(name: string): UnresolvedReference[];
|
|
269
|
+
/**
|
|
270
|
+
* Get all unresolved references
|
|
271
|
+
*/
|
|
272
|
+
getUnresolvedReferences(): UnresolvedReference[];
|
|
273
|
+
/**
|
|
274
|
+
* Get the count of unresolved references without loading them into memory
|
|
275
|
+
*/
|
|
276
|
+
getUnresolvedReferencesCount(): number;
|
|
277
|
+
/**
|
|
278
|
+
* Get a batch of unresolved references using LIMIT/OFFSET pagination.
|
|
279
|
+
* Used to process references in bounded memory chunks.
|
|
280
|
+
*/
|
|
281
|
+
getUnresolvedReferencesBatch(offset: number, limit: number): UnresolvedReference[];
|
|
282
|
+
/**
|
|
283
|
+
* Get all tracked file paths (lightweight — no full FileRecord objects)
|
|
284
|
+
*/
|
|
285
|
+
getAllFilePaths(): string[];
|
|
286
|
+
/**
|
|
287
|
+
* Get all distinct node names (lightweight — just name strings for pre-filtering)
|
|
288
|
+
*/
|
|
289
|
+
getAllNodeNames(): string[];
|
|
290
|
+
/**
|
|
291
|
+
* Get unresolved references scoped to specific file paths.
|
|
292
|
+
* Uses the idx_unresolved_file_path index for efficient lookup.
|
|
293
|
+
*/
|
|
294
|
+
getUnresolvedReferencesByFiles(filePaths: string[]): UnresolvedReference[];
|
|
295
|
+
/**
|
|
296
|
+
* Delete all unresolved references (after resolution)
|
|
297
|
+
*/
|
|
298
|
+
clearUnresolvedReferences(): void;
|
|
299
|
+
/**
|
|
300
|
+
* Delete resolved references by their IDs
|
|
301
|
+
*/
|
|
302
|
+
deleteResolvedReferences(fromNodeIds: string[]): void;
|
|
303
|
+
/**
|
|
304
|
+
* Delete specific resolved references by (fromNodeId, referenceName, referenceKind) tuples.
|
|
305
|
+
* More precise than deleteResolvedReferences — only removes refs that were actually resolved.
|
|
306
|
+
*/
|
|
307
|
+
deleteSpecificResolvedReferences(refs: Array<{
|
|
308
|
+
fromNodeId: string;
|
|
309
|
+
referenceName: string;
|
|
310
|
+
referenceKind: string;
|
|
311
|
+
}>): void;
|
|
312
|
+
/**
|
|
313
|
+
* Lightweight (nodes, edges) count snapshot. Used around an index/sync
|
|
314
|
+
* run to compute true additions across extraction + resolution +
|
|
315
|
+
* synthesis — the per-phase counter in the orchestrator only sees
|
|
316
|
+
* extraction's contribution, which is why the CLI summary under-reported
|
|
317
|
+
* the edge count (resolution + synthesizer edges were invisible).
|
|
318
|
+
*/
|
|
319
|
+
getNodeAndEdgeCount(): {
|
|
320
|
+
nodes: number;
|
|
321
|
+
edges: number;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Get graph statistics
|
|
325
|
+
*/
|
|
326
|
+
getStats(): GraphStats;
|
|
327
|
+
/**
|
|
328
|
+
* Get a metadata value by key
|
|
329
|
+
*/
|
|
330
|
+
getMetadata(key: string): string | null;
|
|
331
|
+
/**
|
|
332
|
+
* Set a metadata key-value pair (upsert)
|
|
333
|
+
*/
|
|
334
|
+
setMetadata(key: string, value: string): void;
|
|
335
|
+
/**
|
|
336
|
+
* Get all metadata as a key-value record
|
|
337
|
+
*/
|
|
338
|
+
getAllMetadata(): Record<string, string>;
|
|
339
|
+
/**
|
|
340
|
+
* Clear all data from the database
|
|
341
|
+
*/
|
|
342
|
+
clear(): void;
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
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(str: string, options?: {
|
|
24
|
+
simple?: boolean;
|
|
25
|
+
}): any;
|
|
26
|
+
transaction<T>(fn: (...args: any[]) => T): (...args: any[]) => T;
|
|
27
|
+
close(): void;
|
|
28
|
+
readonly open: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The active SQLite backend. Only one now (`node:sqlite`); kept as a named type
|
|
32
|
+
* so `codegraph status` and the per-instance reporting have a stable shape.
|
|
33
|
+
*/
|
|
34
|
+
export type SqliteBackend = 'node-sqlite';
|
|
35
|
+
/**
|
|
36
|
+
* Create a database connection backed by `node:sqlite`.
|
|
37
|
+
*
|
|
38
|
+
* Returns the active backend alongside the db so each `DatabaseConnection` can
|
|
39
|
+
* report it per-instance — MCP can open multiple project DBs in one process, so
|
|
40
|
+
* a process-global would race.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createDatabase(dbPath: string): {
|
|
43
|
+
db: SqliteDatabase;
|
|
44
|
+
backend: SqliteBackend;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=sqlite-adapter.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
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(startPath: string): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Create the .codegraph directory structure
|
|
31
|
+
* Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDirectory(projectRoot: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Remove the .codegraph directory
|
|
36
|
+
*/
|
|
37
|
+
export declare function removeDirectory(projectRoot: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get all files in the .codegraph directory
|
|
40
|
+
*/
|
|
41
|
+
export declare function listDirectoryContents(projectRoot: string): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Get the total size of the .codegraph directory in bytes
|
|
44
|
+
*/
|
|
45
|
+
export declare function getDirectorySize(projectRoot: string): number;
|
|
46
|
+
/**
|
|
47
|
+
* Ensure a subdirectory exists within .codegraph
|
|
48
|
+
*/
|
|
49
|
+
export declare function ensureSubdirectory(projectRoot: string, subdirName: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Check if the .codegraph directory has valid structure
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateDirectory(projectRoot: string): {
|
|
54
|
+
valid: boolean;
|
|
55
|
+
errors: string[];
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=directory.d.ts.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeGraph Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Custom error types for better error handling and debugging.
|
|
5
|
+
*
|
|
6
|
+
* @module errors
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { FileError, ParseError, setLogger, silentLogger } from 'codegraph';
|
|
11
|
+
*
|
|
12
|
+
* // Catch specific error types
|
|
13
|
+
* try {
|
|
14
|
+
* await cg.indexAll();
|
|
15
|
+
* } catch (error) {
|
|
16
|
+
* if (error instanceof FileError) {
|
|
17
|
+
* console.log(`File error at ${error.filePath}: ${error.message}`);
|
|
18
|
+
* } else if (error instanceof ParseError) {
|
|
19
|
+
* console.log(`Parse error at ${error.filePath}:${error.line}`);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Disable logging for tests
|
|
24
|
+
* setLogger(silentLogger);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Base error class for all CodeGraph errors.
|
|
29
|
+
*
|
|
30
|
+
* All CodeGraph-specific errors extend this class, allowing you to catch
|
|
31
|
+
* all CodeGraph errors with a single catch block.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* try {
|
|
36
|
+
* await cg.indexAll();
|
|
37
|
+
* } catch (error) {
|
|
38
|
+
* if (error instanceof CodeGraphError) {
|
|
39
|
+
* console.log(`CodeGraph error [${error.code}]: ${error.message}`);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class CodeGraphError extends Error {
|
|
45
|
+
/** Error code for categorization (e.g., 'FILE_ERROR', 'PARSE_ERROR') */
|
|
46
|
+
readonly code: string;
|
|
47
|
+
/** Additional context about the error */
|
|
48
|
+
readonly context?: Record<string, unknown>;
|
|
49
|
+
constructor(message: string, code: string, context?: Record<string, unknown>);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Error reading or accessing files
|
|
53
|
+
*/
|
|
54
|
+
export declare class FileError extends CodeGraphError {
|
|
55
|
+
readonly filePath: string;
|
|
56
|
+
constructor(message: string, filePath: string, cause?: Error);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Error parsing source code
|
|
60
|
+
*/
|
|
61
|
+
export declare class ParseError extends CodeGraphError {
|
|
62
|
+
readonly filePath: string;
|
|
63
|
+
readonly line?: number;
|
|
64
|
+
readonly column?: number;
|
|
65
|
+
constructor(message: string, filePath: string, options?: {
|
|
66
|
+
line?: number;
|
|
67
|
+
column?: number;
|
|
68
|
+
cause?: Error;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Error with database operations
|
|
73
|
+
*/
|
|
74
|
+
export declare class DatabaseError extends CodeGraphError {
|
|
75
|
+
readonly operation: string;
|
|
76
|
+
constructor(message: string, operation: string, cause?: Error);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Error with search operations
|
|
80
|
+
*/
|
|
81
|
+
export declare class SearchError extends CodeGraphError {
|
|
82
|
+
readonly query: string;
|
|
83
|
+
constructor(message: string, query: string, cause?: Error);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Error with vector/embedding operations
|
|
87
|
+
*/
|
|
88
|
+
export declare class VectorError extends CodeGraphError {
|
|
89
|
+
constructor(message: string, operation: string, cause?: Error);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Error with configuration
|
|
93
|
+
*/
|
|
94
|
+
export declare class ConfigError extends CodeGraphError {
|
|
95
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Simple logger for CodeGraph operations
|
|
99
|
+
*
|
|
100
|
+
* By default, logs to console.warn for warnings and console.error for errors.
|
|
101
|
+
* Can be configured to use custom logging.
|
|
102
|
+
*/
|
|
103
|
+
export interface Logger {
|
|
104
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
105
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
106
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Default console-based logger
|
|
110
|
+
*/
|
|
111
|
+
export declare const defaultLogger: Logger;
|
|
112
|
+
/**
|
|
113
|
+
* Silent logger (no output) - useful for tests
|
|
114
|
+
*/
|
|
115
|
+
export declare const silentLogger: Logger;
|
|
116
|
+
/**
|
|
117
|
+
* Set the global logger
|
|
118
|
+
*/
|
|
119
|
+
export declare function setLogger(logger: Logger): void;
|
|
120
|
+
/**
|
|
121
|
+
* Get the current logger
|
|
122
|
+
*/
|
|
123
|
+
export declare function getLogger(): Logger;
|
|
124
|
+
/**
|
|
125
|
+
* Log a debug message
|
|
126
|
+
*/
|
|
127
|
+
export declare function logDebug(message: string, context?: Record<string, unknown>): void;
|
|
128
|
+
/**
|
|
129
|
+
* Log a warning message
|
|
130
|
+
*/
|
|
131
|
+
export declare function logWarn(message: string, context?: Record<string, unknown>): void;
|
|
132
|
+
/**
|
|
133
|
+
* Log an error message
|
|
134
|
+
*/
|
|
135
|
+
export declare function logError(message: string, context?: Record<string, unknown>): void;
|
|
136
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ExtractionResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Custom extractor for Delphi DFM/FMX form files.
|
|
4
|
+
*
|
|
5
|
+
* DFM/FMX files describe the visual component hierarchy and event handler
|
|
6
|
+
* bindings. They use a simple text format (object/end blocks) that we parse
|
|
7
|
+
* with regex — no tree-sitter grammar exists for this format.
|
|
8
|
+
*
|
|
9
|
+
* Extracted information:
|
|
10
|
+
* - Components as NodeKind `component`
|
|
11
|
+
* - Nesting as EdgeKind `contains`
|
|
12
|
+
* - Event handlers (OnClick = MethodName) as UnresolvedReference → EdgeKind `references`
|
|
13
|
+
*/
|
|
14
|
+
export declare class DfmExtractor {
|
|
15
|
+
private filePath;
|
|
16
|
+
private source;
|
|
17
|
+
private nodes;
|
|
18
|
+
private edges;
|
|
19
|
+
private unresolvedReferences;
|
|
20
|
+
private errors;
|
|
21
|
+
constructor(filePath: string, source: string);
|
|
22
|
+
/**
|
|
23
|
+
* Extract components and event handler references from DFM/FMX source
|
|
24
|
+
*/
|
|
25
|
+
extract(): ExtractionResult;
|
|
26
|
+
/** Create a file node for the DFM form file */
|
|
27
|
+
private createFileNode;
|
|
28
|
+
/** Parse object/end blocks and extract components + event handlers */
|
|
29
|
+
private parseComponents;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=dfm-extractor.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated-file detection for symbol-disambiguation down-ranking.
|
|
3
|
+
*
|
|
4
|
+
* When a query like "Send" matches 17 symbols across protobuf scaffolding,
|
|
5
|
+
* test mocks, and the hand-written implementation, the FTS ranker often
|
|
6
|
+
* surfaces the generated stubs first because their names are identical
|
|
7
|
+
* to the implementation's name (validated empirically on cosmos-sdk —
|
|
8
|
+
* see project_go_multi_module_audit memory). Generated stubs frequently
|
|
9
|
+
* have no body to trace from, so the agent ends up reading source anyway.
|
|
10
|
+
*
|
|
11
|
+
* This helper is a pure path-based classifier consulted at disambiguation
|
|
12
|
+
* time (findSymbol / findAllSymbols / codegraph_search formatting), NOT
|
|
13
|
+
* a hard filter — generated nodes are still in the graph and remain
|
|
14
|
+
* reachable; they just rank LAST when there's a real implementation
|
|
15
|
+
* with the same name.
|
|
16
|
+
*
|
|
17
|
+
* Scope: suffix patterns only. Most generated files follow the
|
|
18
|
+
* `<basename>.<tool>.<ext>` convention (`.pb.go`, `_grpc.pb.go`,
|
|
19
|
+
* `.g.dart`, `_pb2.py`), and that covers ~all of what we saw in the
|
|
20
|
+
* Go audit. A future addition would be scanning for the canonical
|
|
21
|
+
* `// Code generated by` header during extraction, for the rare files
|
|
22
|
+
* that defy the suffix convention.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Whether `filePath` looks like a tool-generated source file based on
|
|
26
|
+
* its filename. Path-only — does not read content. The result is a
|
|
27
|
+
* relevance hint for disambiguation, not a hard claim.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isGeneratedFile(filePath: string): boolean;
|
|
30
|
+
//# sourceMappingURL=generated-detection.d.ts.map
|