@aroman22/codegraph-vba 1.3.3
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 +855 -0
- package/dist/bin/codegraph.d.ts +26 -0
- package/dist/bin/command-supervision.d.ts +12 -0
- package/dist/bin/fatal-handler.d.ts +20 -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 +122 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/queries.d.ts +402 -0
- package/dist/db/sqlite-adapter.d.ts +53 -0
- package/dist/directory.d.ts +179 -0
- package/dist/errors.d.ts +136 -0
- package/dist/extraction/astro-extractor.d.ts +79 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/extraction-version.d.ts +25 -0
- package/dist/extraction/function-ref.d.ts +118 -0
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/grammars.d.ts +128 -0
- package/dist/extraction/index.d.ts +187 -0
- package/dist/extraction/languages/c-cpp.d.ts +12 -0
- package/dist/extraction/languages/csharp.d.ts +25 -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/r.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 +16 -0
- package/dist/extraction/liquid-extractor.d.ts +59 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/parse-pool.d.ts +126 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/razor-extractor.d.ts +42 -0
- package/dist/extraction/sql-query-extractor.d.ts +25 -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 +239 -0
- package/dist/extraction/tree-sitter.d.ts +647 -0
- package/dist/extraction/vba-extractor.d.ts +394 -0
- package/dist/extraction/vba-form-extractor.d.ts +89 -0
- package/dist/extraction/vba-preprocess.d.ts +81 -0
- package/dist/extraction/vue-extractor.d.ts +51 -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 +563 -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 +41 -0
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/claude.d.ts +62 -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 +38 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/shared.d.ts +101 -0
- package/dist/installer/targets/toml.d.ts +52 -0
- package/dist/installer/targets/types.d.ts +108 -0
- package/dist/mcp/daemon-manager.d.ts +42 -0
- package/dist/mcp/daemon-paths.d.ts +73 -0
- package/dist/mcp/daemon-registry.d.ts +47 -0
- package/dist/mcp/daemon.d.ts +258 -0
- package/dist/mcp/dynamic-boundaries.d.ts +41 -0
- package/dist/mcp/engine.d.ts +122 -0
- package/dist/mcp/index.d.ts +113 -0
- package/dist/mcp/liveness-watchdog.d.ts +18 -0
- package/dist/mcp/ppid-watchdog.d.ts +62 -0
- package/dist/mcp/proxy.d.ts +87 -0
- package/dist/mcp/query-pool.d.ts +94 -0
- package/dist/mcp/query-worker.d.ts +24 -0
- package/dist/mcp/server-instructions.d.ts +34 -0
- package/dist/mcp/session.d.ts +79 -0
- package/dist/mcp/stdin-teardown.d.ts +27 -0
- package/dist/mcp/tools.d.ts +591 -0
- package/dist/mcp/transport.d.ts +188 -0
- package/dist/mcp/version.d.ts +19 -0
- package/dist/project-config.d.ts +56 -0
- package/dist/reasoning/config.d.ts +45 -0
- package/dist/reasoning/credentials.d.ts +5 -0
- package/dist/reasoning/login.d.ts +21 -0
- package/dist/reasoning/reasoner.d.ts +43 -0
- package/dist/resolution/c-fnptr-synthesizer.d.ts +5 -0
- package/dist/resolution/callback-synthesizer.d.ts +15 -0
- package/dist/resolution/frameworks/astro.d.ts +9 -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/goframe.d.ts +41 -0
- package/dist/resolution/frameworks/index.d.ts +50 -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/goframe-synthesizer.d.ts +28 -0
- package/dist/resolution/import-resolver.d.ts +78 -0
- package/dist/resolution/index.d.ts +196 -0
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/name-matcher.d.ts +93 -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 +233 -0
- package/dist/resolution/workspace-packages.d.ts +48 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-utils.d.ts +87 -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 +358 -0
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/telemetry/index.d.ts +143 -0
- package/dist/types.d.ts +409 -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/upgrade/index.d.ts +132 -0
- package/dist/utils.d.ts +224 -0
- package/npm-sdk.js +75 -0
- package/npm-shim.js +246 -0
- package/package.json +32 -0
|
@@ -0,0 +1,402 @@
|
|
|
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 projectNameTokens;
|
|
14
|
+
private nodeCache;
|
|
15
|
+
private readonly maxCacheSize;
|
|
16
|
+
private stmts;
|
|
17
|
+
constructor(db: SqliteDatabase);
|
|
18
|
+
/** Set the normalized project-name tokens used to down-weight non-discriminative
|
|
19
|
+
* query words in path scoring (#720). Called once when the project opens. */
|
|
20
|
+
setProjectNameTokens(tokens: Set<string>): void;
|
|
21
|
+
/** The normalized project-name tokens (#720); empty if none were derived. */
|
|
22
|
+
getProjectNameTokens(): Set<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Insert a new node
|
|
25
|
+
*/
|
|
26
|
+
insertNode(node: Node): void;
|
|
27
|
+
/**
|
|
28
|
+
* Insert multiple nodes in a transaction
|
|
29
|
+
*/
|
|
30
|
+
insertNodes(nodes: Node[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* Update an existing node
|
|
33
|
+
*/
|
|
34
|
+
updateNode(node: Node): void;
|
|
35
|
+
/**
|
|
36
|
+
* Delete a node by ID
|
|
37
|
+
*/
|
|
38
|
+
deleteNode(id: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Delete all nodes for a file
|
|
41
|
+
*/
|
|
42
|
+
deleteNodesByFile(filePath: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get a node by ID
|
|
45
|
+
*/
|
|
46
|
+
getNodeById(id: string): Node | null;
|
|
47
|
+
/**
|
|
48
|
+
* Batch lookup: fetch many nodes by ID in a single SQL round-trip.
|
|
49
|
+
*
|
|
50
|
+
* Replaces the N+1 pattern in graph traversal where every edge would
|
|
51
|
+
* trigger its own `getNodeById` call. For a function with 50 callers
|
|
52
|
+
* this collapses 50 point reads into one IN-list query (~10-50x
|
|
53
|
+
* faster end-to-end).
|
|
54
|
+
*
|
|
55
|
+
* Returns a Map keyed by id so callers can preserve their own ordering
|
|
56
|
+
* (typically the order edges were returned from the graph). Missing IDs
|
|
57
|
+
* are simply absent from the map.
|
|
58
|
+
*
|
|
59
|
+
* Cache-aware: ids already in the LRU cache are served from memory and
|
|
60
|
+
* the SQL query only touches the misses.
|
|
61
|
+
*/
|
|
62
|
+
getNodesByIds(ids: readonly string[]): Map<string, Node>;
|
|
63
|
+
private getExistingNodeIds;
|
|
64
|
+
/**
|
|
65
|
+
* Add a node to the cache, evicting oldest if needed
|
|
66
|
+
*/
|
|
67
|
+
private cacheNode;
|
|
68
|
+
/**
|
|
69
|
+
* Clear the node cache
|
|
70
|
+
*/
|
|
71
|
+
clearCache(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get all nodes in a file
|
|
74
|
+
*/
|
|
75
|
+
getNodesByFile(filePath: string): Node[];
|
|
76
|
+
/**
|
|
77
|
+
* Find the file that holds the densest concentration of the project's
|
|
78
|
+
* internal call graph — the "core" file. Used by context-builder to
|
|
79
|
+
* boost ranking of symbols in that file's directory (so e.g. sinatra
|
|
80
|
+
* queries surface `lib/sinatra/base.rb`'s `route!` instead of
|
|
81
|
+
* `sinatra-contrib/lib/sinatra/multi_route.rb`'s `route` extension).
|
|
82
|
+
*
|
|
83
|
+
* Returns null if no file has a meaningful concentration (e.g. spread
|
|
84
|
+
* evenly across many files, or empty index).
|
|
85
|
+
*
|
|
86
|
+
* "Internal" = source and target are in the same file. Cross-file
|
|
87
|
+
* edges aren't useful here — they don't tell us which file is the
|
|
88
|
+
* functional center.
|
|
89
|
+
*
|
|
90
|
+
* Excludes test/spec files from candidacy via path-pattern. The agent's
|
|
91
|
+
* typical question is "how does X work", not "how is X tested", so
|
|
92
|
+
* boosting a test file's directory would be a misfire.
|
|
93
|
+
*/
|
|
94
|
+
getDominantFile(): {
|
|
95
|
+
filePath: string;
|
|
96
|
+
edgeCount: number;
|
|
97
|
+
nextEdgeCount: number;
|
|
98
|
+
} | null;
|
|
99
|
+
/**
|
|
100
|
+
* Find the file that holds the densest concentration of the project's
|
|
101
|
+
* `route` nodes (framework-emitted: Express/Gin/Flask/Rails/Drupal/etc.).
|
|
102
|
+
* Used by handleContext on small repos to inline the project's routing
|
|
103
|
+
* config when the agent's query is about request flow — eliminating the
|
|
104
|
+
* "Glob + Read routes.rb" pattern that beats codegraph on tiny realworld
|
|
105
|
+
* template repos.
|
|
106
|
+
*
|
|
107
|
+
* Excludes test/generated files from candidacy. Returns null if there
|
|
108
|
+
* are fewer than 3 non-test routes total, or if no file holds at least
|
|
109
|
+
* 30% of them (diffuse routing → no single answer file).
|
|
110
|
+
*/
|
|
111
|
+
getTopRouteFile(): {
|
|
112
|
+
filePath: string;
|
|
113
|
+
routeCount: number;
|
|
114
|
+
totalRoutes: number;
|
|
115
|
+
} | null;
|
|
116
|
+
/**
|
|
117
|
+
* Build a URL → handler manifest from the index. Each route node's
|
|
118
|
+
* `references` edge points at the function/method that handles the
|
|
119
|
+
* request. We join them in one pass; the agent gets the canonical
|
|
120
|
+
* routing answer ("POST /users/login → AuthController#login") without
|
|
121
|
+
* having to parse the framework's route DSL itself.
|
|
122
|
+
*
|
|
123
|
+
* Also returns the file with the most handler endpoints — used as the
|
|
124
|
+
* "top handler file" to inline source for, so the agent has both the
|
|
125
|
+
* mapping AND the handler implementations.
|
|
126
|
+
*/
|
|
127
|
+
getRoutingManifest(limit?: number): {
|
|
128
|
+
entries: Array<{
|
|
129
|
+
url: string;
|
|
130
|
+
handler: string;
|
|
131
|
+
handlerFile: string;
|
|
132
|
+
handlerLine: number;
|
|
133
|
+
handlerKind: string;
|
|
134
|
+
}>;
|
|
135
|
+
topHandlerFile: string | null;
|
|
136
|
+
topHandlerFileCount: number;
|
|
137
|
+
totalRoutes: number;
|
|
138
|
+
} | null;
|
|
139
|
+
/**
|
|
140
|
+
* Get all nodes of a specific kind
|
|
141
|
+
*/
|
|
142
|
+
getNodesByKind(kind: NodeKind): Node[];
|
|
143
|
+
/**
|
|
144
|
+
* Stream every node of a kind one at a time (lazy) instead of materializing
|
|
145
|
+
* them all like {@link getNodesByKind}. For unbounded kinds (`function`,
|
|
146
|
+
* `method`) on a symbol-dense project the full array is gigabytes; the
|
|
147
|
+
* dynamic-edge synthesizers only scan-and-filter, so they iterate to keep
|
|
148
|
+
* memory O(1) in the node count rather than O(nodes) (#610).
|
|
149
|
+
*/
|
|
150
|
+
iterateNodesByKind(kind: NodeKind): IterableIterator<Node>;
|
|
151
|
+
/**
|
|
152
|
+
* Get all nodes in the database
|
|
153
|
+
*/
|
|
154
|
+
getAllNodes(): Node[];
|
|
155
|
+
/**
|
|
156
|
+
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
157
|
+
*/
|
|
158
|
+
getNodesByName(name: string): Node[];
|
|
159
|
+
/**
|
|
160
|
+
* Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
|
|
161
|
+
*/
|
|
162
|
+
getNodesByQualifiedNameExact(qualifiedName: string): Node[];
|
|
163
|
+
/**
|
|
164
|
+
* Get nodes by lowercase name match (uses idx_nodes_lower_name expression index)
|
|
165
|
+
*/
|
|
166
|
+
getNodesByLowerName(lowerName: string): Node[];
|
|
167
|
+
/**
|
|
168
|
+
* Search nodes by name using FTS with fallback to LIKE for better matching
|
|
169
|
+
*
|
|
170
|
+
* Search strategy:
|
|
171
|
+
* 1. Try FTS5 prefix match (query*) for word-start matching
|
|
172
|
+
* 2. If no results, try LIKE for substring matching (e.g., "signIn" finds "signInWithGoogle")
|
|
173
|
+
* 3. Score results based on match quality
|
|
174
|
+
*/
|
|
175
|
+
searchNodes(query: string, options?: SearchOptions): SearchResult[];
|
|
176
|
+
private isEventHandlerNode;
|
|
177
|
+
/**
|
|
178
|
+
* Match-everything path used when the user supplied only field
|
|
179
|
+
* filters (`kind:function lang:typescript`) with no text. Returns
|
|
180
|
+
* candidates ordered by name; the caller's filter pass narrows to
|
|
181
|
+
* what was asked for.
|
|
182
|
+
*/
|
|
183
|
+
private searchAllByFilters;
|
|
184
|
+
/**
|
|
185
|
+
* Fuzzy fallback: when zero FTS/LIKE hits, try an edit-distance
|
|
186
|
+
* sweep over the distinct symbol-name set. Caps `maxDist` at 2 so
|
|
187
|
+
* `getUssr` finds `getUser` but `process` doesn't match `prosody`.
|
|
188
|
+
* Bounded edit distance keeps each comparison cheap; the per-query
|
|
189
|
+
* scan is O(distinct-name-count) which is far smaller than total
|
|
190
|
+
* node count on any real codebase.
|
|
191
|
+
*/
|
|
192
|
+
private searchNodesFuzzy;
|
|
193
|
+
/**
|
|
194
|
+
* FTS5 search with prefix matching
|
|
195
|
+
*/
|
|
196
|
+
private searchNodesFTS;
|
|
197
|
+
/**
|
|
198
|
+
* LIKE-based substring search for cases where FTS doesn't match
|
|
199
|
+
* Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
|
|
200
|
+
*/
|
|
201
|
+
private searchNodesLike;
|
|
202
|
+
/**
|
|
203
|
+
* Find nodes by exact name match
|
|
204
|
+
*
|
|
205
|
+
* Used for hybrid search - looks up symbols by exact name or case-insensitive match.
|
|
206
|
+
* Returns high-confidence matches for known symbol names extracted from query.
|
|
207
|
+
*
|
|
208
|
+
* @param names - Array of symbol names to look up
|
|
209
|
+
* @param options - Search options (kinds, languages, limit)
|
|
210
|
+
* @returns SearchResult array with exact matches scored at 1.0
|
|
211
|
+
*/
|
|
212
|
+
findNodesByExactName(names: string[], options?: SearchOptions): SearchResult[];
|
|
213
|
+
/**
|
|
214
|
+
* Find nodes whose name contains a substring (LIKE-based).
|
|
215
|
+
* Useful for CamelCase-part matching where FTS fails because
|
|
216
|
+
* e.g. "TransportSearchAction" is one FTS token, not matchable by "Search"*.
|
|
217
|
+
*
|
|
218
|
+
* Results are ordered by name length (shorter = more likely to be the core type).
|
|
219
|
+
*/
|
|
220
|
+
findNodesByNameSubstring(substring: string, options?: SearchOptions & {
|
|
221
|
+
excludePrefix?: boolean;
|
|
222
|
+
}): SearchResult[];
|
|
223
|
+
/**
|
|
224
|
+
* Insert a new edge
|
|
225
|
+
*/
|
|
226
|
+
insertEdge(edge: Edge): void;
|
|
227
|
+
/**
|
|
228
|
+
* Insert multiple edges in a transaction
|
|
229
|
+
*/
|
|
230
|
+
insertEdges(edges: Edge[]): void;
|
|
231
|
+
/**
|
|
232
|
+
* Delete all edges from a source node
|
|
233
|
+
*/
|
|
234
|
+
deleteEdgesBySource(sourceId: string): void;
|
|
235
|
+
/**
|
|
236
|
+
* Get outgoing edges from a node
|
|
237
|
+
*/
|
|
238
|
+
getOutgoingEdges(sourceId: string, kinds?: EdgeKind[], provenance?: string): Edge[];
|
|
239
|
+
/**
|
|
240
|
+
* Get incoming edges to a node
|
|
241
|
+
*/
|
|
242
|
+
getIncomingEdges(targetId: string, kinds?: EdgeKind[]): Edge[];
|
|
243
|
+
/**
|
|
244
|
+
* Find all edges where both source and target are in the given node set.
|
|
245
|
+
* Useful for recovering inter-node connectivity after BFS.
|
|
246
|
+
*/
|
|
247
|
+
findEdgesBetweenNodes(nodeIds: string[], kinds?: EdgeKind[]): Edge[];
|
|
248
|
+
/**
|
|
249
|
+
* Distinct file paths that DEPEND ON `filePath`: every file containing a
|
|
250
|
+
* symbol with a cross-file edge (any kind except `contains`) into a symbol
|
|
251
|
+
* of this file. This is the file-level projection of the symbol dependency
|
|
252
|
+
* graph and the basis for blast-radius / `affected` test selection.
|
|
253
|
+
*
|
|
254
|
+
* It deliberately does NOT restrict to `imports` edges. In this graph an
|
|
255
|
+
* `imports` edge connects a file to its own local import declarations
|
|
256
|
+
* (it is always same-file), so an imports-only lookup returns zero
|
|
257
|
+
* cross-file dependents for every file. The real cross-file dependency
|
|
258
|
+
* signal is the resolved call/reference graph — calls, references,
|
|
259
|
+
* instantiates, extends, implements, overrides, type_of, returns,
|
|
260
|
+
* decorates — exactly what {@link GraphTraverser.getImpactRadius} traverses.
|
|
261
|
+
* `contains` is excluded: a parent containing a symbol does not *depend* on
|
|
262
|
+
* it. One indexed query (idx_nodes_file_path + idx_edges_target_kind).
|
|
263
|
+
*/
|
|
264
|
+
getDependentFilePaths(filePath: string): string[];
|
|
265
|
+
/**
|
|
266
|
+
* Distinct file paths that `filePath` DEPENDS ON — the inverse of
|
|
267
|
+
* {@link getDependentFilePaths}: every file containing a symbol that a
|
|
268
|
+
* symbol of this file has a cross-file edge into. Same edge-kind rules
|
|
269
|
+
* (all kinds except `contains`); same reason imports-only is insufficient.
|
|
270
|
+
*/
|
|
271
|
+
getDependencyFilePaths(filePath: string): string[];
|
|
272
|
+
/**
|
|
273
|
+
* Cross-file edges whose TARGET is a node in `filePath` and whose SOURCE is a
|
|
274
|
+
* node in a *different* file, paired with the target node's (name, kind) so a
|
|
275
|
+
* caller can re-resolve the edge to the re-indexed target's new ID (node IDs
|
|
276
|
+
* are `sha256(filePath:kind:name:line)`, so any line shift in the callee file
|
|
277
|
+
* changes target IDs and a naive re-insert by old ID silently drops them).
|
|
278
|
+
* Used by `storeExtractionResult` to preserve incoming edges across a file
|
|
279
|
+
* re-index (issue #899). Same edge-kind rules as
|
|
280
|
+
* {@link getDependentFilePaths}: all kinds except `contains`.
|
|
281
|
+
*/
|
|
282
|
+
getCrossFileIncomingEdgesWithTarget(filePath: string): Array<Edge & {
|
|
283
|
+
targetName: string;
|
|
284
|
+
targetKind: NodeKind;
|
|
285
|
+
}>;
|
|
286
|
+
/**
|
|
287
|
+
* Insert or update a file record
|
|
288
|
+
*/
|
|
289
|
+
upsertFile(file: FileRecord): void;
|
|
290
|
+
/**
|
|
291
|
+
* Delete a file record and its nodes
|
|
292
|
+
*/
|
|
293
|
+
deleteFile(filePath: string): void;
|
|
294
|
+
/**
|
|
295
|
+
* Get a file record by path
|
|
296
|
+
*/
|
|
297
|
+
getFileByPath(filePath: string): FileRecord | null;
|
|
298
|
+
/**
|
|
299
|
+
* Get all tracked files
|
|
300
|
+
*/
|
|
301
|
+
getAllFiles(): FileRecord[];
|
|
302
|
+
/**
|
|
303
|
+
* Most recent index timestamp (ms since epoch) across all tracked files, or
|
|
304
|
+
* null when nothing is indexed yet. One indexed aggregate, no per-row scan. (#329)
|
|
305
|
+
*/
|
|
306
|
+
getLastIndexedAt(): number | null;
|
|
307
|
+
/**
|
|
308
|
+
* Get files that need re-indexing (hash changed)
|
|
309
|
+
*/
|
|
310
|
+
getStaleFiles(currentHashes: Map<string, string>): FileRecord[];
|
|
311
|
+
/**
|
|
312
|
+
* Insert an unresolved reference
|
|
313
|
+
*/
|
|
314
|
+
insertUnresolvedRef(ref: UnresolvedReference): void;
|
|
315
|
+
/**
|
|
316
|
+
* Insert multiple unresolved references in a transaction
|
|
317
|
+
*/
|
|
318
|
+
insertUnresolvedRefsBatch(refs: UnresolvedReference[]): void;
|
|
319
|
+
/**
|
|
320
|
+
* Delete unresolved references from a node
|
|
321
|
+
*/
|
|
322
|
+
deleteUnresolvedByNode(nodeId: string): void;
|
|
323
|
+
/**
|
|
324
|
+
* Get unresolved references by name (for resolution)
|
|
325
|
+
*/
|
|
326
|
+
getUnresolvedByName(name: string): UnresolvedReference[];
|
|
327
|
+
/**
|
|
328
|
+
* Get all unresolved references
|
|
329
|
+
*/
|
|
330
|
+
getUnresolvedReferences(): UnresolvedReference[];
|
|
331
|
+
/**
|
|
332
|
+
* Get the count of unresolved references without loading them into memory
|
|
333
|
+
*/
|
|
334
|
+
getUnresolvedReferencesCount(): number;
|
|
335
|
+
/**
|
|
336
|
+
* Get a batch of unresolved references using LIMIT/OFFSET pagination.
|
|
337
|
+
* Used to process references in bounded memory chunks.
|
|
338
|
+
*/
|
|
339
|
+
getUnresolvedReferencesBatch(offset: number, limit: number): UnresolvedReference[];
|
|
340
|
+
/**
|
|
341
|
+
* Get all tracked file paths (lightweight — no full FileRecord objects)
|
|
342
|
+
*/
|
|
343
|
+
getAllFilePaths(): string[];
|
|
344
|
+
/**
|
|
345
|
+
* Get all distinct node names (lightweight — just name strings for pre-filtering)
|
|
346
|
+
*/
|
|
347
|
+
getAllNodeNames(): string[];
|
|
348
|
+
/**
|
|
349
|
+
* Get unresolved references scoped to specific file paths.
|
|
350
|
+
* Uses the idx_unresolved_file_path index for efficient lookup.
|
|
351
|
+
*/
|
|
352
|
+
getUnresolvedReferencesByFiles(filePaths: string[]): UnresolvedReference[];
|
|
353
|
+
/**
|
|
354
|
+
* Delete all unresolved references (after resolution)
|
|
355
|
+
*/
|
|
356
|
+
clearUnresolvedReferences(): void;
|
|
357
|
+
/**
|
|
358
|
+
* Delete resolved references by their IDs
|
|
359
|
+
*/
|
|
360
|
+
deleteResolvedReferences(fromNodeIds: string[]): void;
|
|
361
|
+
/**
|
|
362
|
+
* Delete specific resolved references by (fromNodeId, referenceName, referenceKind) tuples.
|
|
363
|
+
* More precise than deleteResolvedReferences — only removes refs that were actually resolved.
|
|
364
|
+
*/
|
|
365
|
+
deleteSpecificResolvedReferences(refs: Array<{
|
|
366
|
+
fromNodeId: string;
|
|
367
|
+
referenceName: string;
|
|
368
|
+
referenceKind: string;
|
|
369
|
+
}>): void;
|
|
370
|
+
/**
|
|
371
|
+
* Lightweight (nodes, edges) count snapshot. Used around an index/sync
|
|
372
|
+
* run to compute true additions across extraction + resolution +
|
|
373
|
+
* synthesis — the per-phase counter in the orchestrator only sees
|
|
374
|
+
* extraction's contribution, which is why the CLI summary under-reported
|
|
375
|
+
* the edge count (resolution + synthesizer edges were invisible).
|
|
376
|
+
*/
|
|
377
|
+
getNodeAndEdgeCount(): {
|
|
378
|
+
nodes: number;
|
|
379
|
+
edges: number;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Get graph statistics
|
|
383
|
+
*/
|
|
384
|
+
getStats(): GraphStats;
|
|
385
|
+
/**
|
|
386
|
+
* Get a metadata value by key
|
|
387
|
+
*/
|
|
388
|
+
getMetadata(key: string): string | null;
|
|
389
|
+
/**
|
|
390
|
+
* Set a metadata key-value pair (upsert)
|
|
391
|
+
*/
|
|
392
|
+
setMetadata(key: string, value: string): void;
|
|
393
|
+
/**
|
|
394
|
+
* Get all metadata as a key-value record
|
|
395
|
+
*/
|
|
396
|
+
getAllMetadata(): Record<string, string>;
|
|
397
|
+
/**
|
|
398
|
+
* Clear all data from the database
|
|
399
|
+
*/
|
|
400
|
+
clear(): void;
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
* Lazily yield result rows one at a time instead of materializing the whole
|
|
21
|
+
* set with `all()`. Use for unbounded scans (e.g. every function/method node)
|
|
22
|
+
* so memory stays O(1) in the row count rather than O(rows) — see #610, where
|
|
23
|
+
* `all()`-ing every symbol on a dense project spiked the heap into an OOM.
|
|
24
|
+
*/
|
|
25
|
+
iterate(...params: any[]): IterableIterator<any>;
|
|
26
|
+
}
|
|
27
|
+
export interface SqliteDatabase {
|
|
28
|
+
prepare(sql: string): SqliteStatement;
|
|
29
|
+
exec(sql: string): void;
|
|
30
|
+
pragma(str: string, options?: {
|
|
31
|
+
simple?: boolean;
|
|
32
|
+
}): any;
|
|
33
|
+
transaction<T>(fn: (...args: any[]) => T): (...args: any[]) => T;
|
|
34
|
+
close(): void;
|
|
35
|
+
readonly open: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The active SQLite backend. Only one now (`node:sqlite`); kept as a named type
|
|
39
|
+
* so `codegraph status` and the per-instance reporting have a stable shape.
|
|
40
|
+
*/
|
|
41
|
+
export type SqliteBackend = 'node-sqlite';
|
|
42
|
+
/**
|
|
43
|
+
* Create a database connection backed by `node:sqlite`.
|
|
44
|
+
*
|
|
45
|
+
* Returns the active backend alongside the db so each `DatabaseConnection` can
|
|
46
|
+
* report it per-instance — MCP can open multiple project DBs in one process, so
|
|
47
|
+
* a process-global would race.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createDatabase(dbPath: string): {
|
|
50
|
+
db: SqliteDatabase;
|
|
51
|
+
backend: SqliteBackend;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=sqlite-adapter.d.ts.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory Management
|
|
3
|
+
*
|
|
4
|
+
* Manages the .codegraph/ directory structure for CodeGraph data.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the per-project data directory name, honoring the `CODEGRAPH_DIR`
|
|
8
|
+
* environment override (default `.codegraph`). The override is a single path
|
|
9
|
+
* segment that lives in the project root.
|
|
10
|
+
*
|
|
11
|
+
* Why this exists: two environments that share one working tree must NOT share
|
|
12
|
+
* one `.codegraph/` — most concretely Windows-native and WSL (issue #636). The
|
|
13
|
+
* daemon lockfile (`.codegraph/daemon.pid`) records a platform-specific pid and
|
|
14
|
+
* socket path (a Windows named pipe vs a WSL Unix socket), and SQLite file
|
|
15
|
+
* locking across the WSL2 ↔ Windows filesystem boundary is unreliable, so two
|
|
16
|
+
* daemons sharing one index risks corruption. Setting `CODEGRAPH_DIR=.codegraph-win`
|
|
17
|
+
* on one side gives each environment its own index in the same tree.
|
|
18
|
+
*
|
|
19
|
+
* Read live (not captured at load) so it is both process-accurate and testable.
|
|
20
|
+
* An override that isn't a plain directory name — empty, containing a path
|
|
21
|
+
* separator, `.`, `..`/traversal, or absolute — is ignored (we keep the
|
|
22
|
+
* default) rather than risk writing the index outside the project or into the
|
|
23
|
+
* project root itself; we warn once to stderr so the misconfiguration is seen.
|
|
24
|
+
*/
|
|
25
|
+
export declare function codeGraphDirName(): string;
|
|
26
|
+
/**
|
|
27
|
+
* CodeGraph directory name — a load-time snapshot of {@link codeGraphDirName}.
|
|
28
|
+
* A running process's environment is fixed, so this equals the live value;
|
|
29
|
+
* it's kept as a stable string export for backward compatibility. Internal code
|
|
30
|
+
* resolves the name through {@link codeGraphDirName} / {@link getCodeGraphDir}
|
|
31
|
+
* so the `CODEGRAPH_DIR` override always applies.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CODEGRAPH_DIR: string;
|
|
34
|
+
/**
|
|
35
|
+
* Is `name` (a single path segment) a CodeGraph data directory? Matches the
|
|
36
|
+
* default `.codegraph`, the active `CODEGRAPH_DIR` override, and any
|
|
37
|
+
* `.codegraph-*` sibling. File-watching and the indexer skip ALL of these, so
|
|
38
|
+
* when two environments share one working tree (Windows + WSL, issue #636)
|
|
39
|
+
* neither indexes or watches the other's index directory.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isCodeGraphDataDir(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the .codegraph directory path for a project
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCodeGraphDir(projectRoot: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a project has been initialized with CodeGraph
|
|
48
|
+
* Requires both .codegraph/ directory AND codegraph.db to exist
|
|
49
|
+
*/
|
|
50
|
+
export declare function isInitialized(projectRoot: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Find the nearest parent directory containing .codegraph/
|
|
53
|
+
*
|
|
54
|
+
* Walks up from the given path to find a CodeGraph-initialized project,
|
|
55
|
+
* similar to how git finds .git/ directories.
|
|
56
|
+
*
|
|
57
|
+
* @param startPath - Directory to start searching from
|
|
58
|
+
* @returns The project root containing .codegraph/, or null if not found
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Reason a directory is unsafe to use as an index ROOT, or null when it's fine.
|
|
62
|
+
*
|
|
63
|
+
* Indexing your home directory or a filesystem root drags in caches, `Library`,
|
|
64
|
+
* every other project, etc. — a multi-GB index, constant file-watcher churn, and
|
|
65
|
+
* (pre-1.0 on macOS) a file-descriptor blowup that exhausted `kern.maxfiles` and
|
|
66
|
+
* took unrelated apps / the whole machine down (#845). The classic trigger:
|
|
67
|
+
* running the installer or `codegraph init` from `$HOME`, which auto-indexes the
|
|
68
|
+
* current directory. These are never intended project roots, so the installer
|
|
69
|
+
* and `init`/`index` refuse them (overridable with `--force`).
|
|
70
|
+
*
|
|
71
|
+
* Pure-ish (reads only `os.homedir()` + realpath) so it's easy to unit-test.
|
|
72
|
+
* The returned string is a human phrase that slots into "… looks like {reason}".
|
|
73
|
+
*/
|
|
74
|
+
export declare function unsafeIndexRootReason(projectRoot: string): string | null;
|
|
75
|
+
export declare function findNearestCodeGraphRoot(startPath: string): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* Indexed sub-project roots beneath `root` (bounded breadth-first scan). For
|
|
78
|
+
* the monorepo case behind #964: the index lives in a CHILD
|
|
79
|
+
* (`packages/x/.codegraph/`), not at the workspace root the agent's cwd points
|
|
80
|
+
* at. Descent stops at the first indexed directory on a branch (a project's
|
|
81
|
+
* own sub-dirs aren't separate projects) and is bounded by depth + count so it
|
|
82
|
+
* never turns into a full-tree crawl on a large repo.
|
|
83
|
+
*/
|
|
84
|
+
export declare function findIndexedSubprojectRoots(root: string, opts?: {
|
|
85
|
+
maxDepth?: number;
|
|
86
|
+
max?: number;
|
|
87
|
+
}): string[];
|
|
88
|
+
/**
|
|
89
|
+
* Does `prompt` contain an explicit structural keyword (English or CJK)? A
|
|
90
|
+
* keyword is a strong, self-contained signal, so the front-load hook fires on it
|
|
91
|
+
* directly — no graph check needed. (A *code-token* match, by contrast, is only
|
|
92
|
+
* a candidate the hook verifies against the graph first; see {@link extractCodeTokens}.)
|
|
93
|
+
*/
|
|
94
|
+
export declare function hasStructuralKeyword(prompt: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Identifier-shaped tokens in `prompt` — camelCase / PascalCase-with-inner-cap,
|
|
97
|
+
* snake_case, a `name(` call, or the two sides of an `a.b` member access. Naming
|
|
98
|
+
* a symbol is a code question whatever the surrounding human language, and these
|
|
99
|
+
* shapes almost never occur in ordinary prose, so they catch the common
|
|
100
|
+
* "<symbol> 的调用链?" / "where is <symbol> 定義" prompts no keyword list would.
|
|
101
|
+
*
|
|
102
|
+
* These are *candidates*, not a verdict: a tech brand like `JavaScript` or
|
|
103
|
+
* `GitHub` is identifier-shaped too, so the front-load hook checks each token
|
|
104
|
+
* against the actual index ({@link getNodesByName}) and only fires when one is a
|
|
105
|
+
* real symbol here — otherwise a brand-name prompt would inject ~16KB of
|
|
106
|
+
* low-relevance context (issue #994 follow-up). A doc/data filename ("README.md")
|
|
107
|
+
* is excluded from the member-access form since it's a file reference, not a symbol.
|
|
108
|
+
*/
|
|
109
|
+
export declare function extractCodeTokens(prompt: string): string[];
|
|
110
|
+
/**
|
|
111
|
+
* Cheap, graph-free candidate gate for the front-load hook: could `prompt` be a
|
|
112
|
+
* structural / flow / impact / "where-how" question worth front-loading context
|
|
113
|
+
* for? True on an explicit keyword (English or CJK, issue #994) OR an
|
|
114
|
+
* identifier-shaped token. A keyword is sufficient to fire on its own; a
|
|
115
|
+
* token-only match is only a candidate the hook then verifies against the graph
|
|
116
|
+
* (a brand name like `JavaScript` is token-shaped but isn't a symbol). Every
|
|
117
|
+
* non-candidate prompt ("fix this typo", in any language) stays a zero-cost no-op.
|
|
118
|
+
*/
|
|
119
|
+
export declare function isStructuralPrompt(prompt: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* What the front-load hook should do for a prompt issued from a directory.
|
|
122
|
+
*/
|
|
123
|
+
export interface FrontloadPlan {
|
|
124
|
+
/** Open + explore this project and inject its source as context. `null` when
|
|
125
|
+
* there's no single project to front-load (none indexed, or several indexed
|
|
126
|
+
* sub-projects with no clear match — see {@link nudgeProjects}). */
|
|
127
|
+
exploreRoot: string | null;
|
|
128
|
+
/** Indexed sub-projects to surface in a "pass `projectPath`" nudge: the rest
|
|
129
|
+
* of a monorepo's indexed projects alongside `exploreRoot`, or — when no one
|
|
130
|
+
* project clearly matches — the full list (with `exploreRoot` null). */
|
|
131
|
+
nudgeProjects: string[];
|
|
132
|
+
/** True when the plan came from scanning DOWN into sub-projects (cwd itself
|
|
133
|
+
* is not under any index) — the monorepo case, where a follow-up
|
|
134
|
+
* `codegraph_explore` needs an explicit `projectPath`. */
|
|
135
|
+
viaSubScan: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Decide what the front-load hook injects for a `prompt` issued from `cwd`,
|
|
139
|
+
* shaped by where the `.codegraph/` index(es) actually are:
|
|
140
|
+
* 1. **cwd (or an ancestor) is indexed** → front-load that project. The
|
|
141
|
+
* normal single-project / nested-file case.
|
|
142
|
+
* 2. **cwd isn't indexed but looks like a workspace root** → the indexes live
|
|
143
|
+
* in sub-projects (the monorepo case behind #964). One indexed
|
|
144
|
+
* sub-project → front-load it; several → front-load the one the prompt
|
|
145
|
+
* names (by relative path like `packages/api`, or package directory name)
|
|
146
|
+
* and nudge about the rest; several with no match → nudge the full list so
|
|
147
|
+
* the agent passes `projectPath`, rather than guessing wrong.
|
|
148
|
+
* 3. **nothing indexed reachable** → do nothing (the agent's own tools apply).
|
|
149
|
+
*/
|
|
150
|
+
export declare function planFrontload(cwd: string, prompt: string): FrontloadPlan;
|
|
151
|
+
/**
|
|
152
|
+
* Create the .codegraph directory structure
|
|
153
|
+
* Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
|
|
154
|
+
*/
|
|
155
|
+
export declare function createDirectory(projectRoot: string): void;
|
|
156
|
+
/**
|
|
157
|
+
* Remove the .codegraph directory
|
|
158
|
+
*/
|
|
159
|
+
export declare function removeDirectory(projectRoot: string): void;
|
|
160
|
+
/**
|
|
161
|
+
* Get all files in the .codegraph directory
|
|
162
|
+
*/
|
|
163
|
+
export declare function listDirectoryContents(projectRoot: string): string[];
|
|
164
|
+
/**
|
|
165
|
+
* Get the total size of the .codegraph directory in bytes
|
|
166
|
+
*/
|
|
167
|
+
export declare function getDirectorySize(projectRoot: string): number;
|
|
168
|
+
/**
|
|
169
|
+
* Ensure a subdirectory exists within .codegraph
|
|
170
|
+
*/
|
|
171
|
+
export declare function ensureSubdirectory(projectRoot: string, subdirName: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* Check if the .codegraph directory has valid structure
|
|
174
|
+
*/
|
|
175
|
+
export declare function validateDirectory(projectRoot: string): {
|
|
176
|
+
valid: boolean;
|
|
177
|
+
errors: string[];
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=directory.d.ts.map
|