@saluzi/codegraph 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/package.json +42 -10
  4. package/scripts/add-lang/bench.sh +60 -0
  5. package/scripts/add-lang/check-grammar.mjs +75 -0
  6. package/scripts/add-lang/dump-ast.mjs +103 -0
  7. package/scripts/add-lang/verify-extraction.mjs +70 -0
  8. package/scripts/agent-eval/ab-adoption.sh +91 -0
  9. package/scripts/agent-eval/ab-hook.sh +86 -0
  10. package/scripts/agent-eval/ab-impl.sh +78 -0
  11. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  12. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  13. package/scripts/agent-eval/arms-F.sh +21 -0
  14. package/scripts/agent-eval/arms-matrix.sh +37 -0
  15. package/scripts/agent-eval/audit.sh +68 -0
  16. package/scripts/agent-eval/bench-readme.sh +28 -0
  17. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  18. package/scripts/agent-eval/block-read-hook.sh +19 -0
  19. package/scripts/agent-eval/hook-settings.json +15 -0
  20. package/scripts/agent-eval/itrun.sh +120 -0
  21. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  22. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  23. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  24. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  25. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  26. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  27. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  28. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  29. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  30. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  31. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  32. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  33. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  34. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  35. package/scripts/agent-eval/offload-eval.md +76 -0
  36. package/scripts/agent-eval/parse-arms.mjs +116 -0
  37. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  38. package/scripts/agent-eval/parse-run.mjs +45 -0
  39. package/scripts/agent-eval/parse-session.mjs +93 -0
  40. package/scripts/agent-eval/probe-context.mjs +21 -0
  41. package/scripts/agent-eval/probe-explore.mjs +40 -0
  42. package/scripts/agent-eval/probe-node.mjs +20 -0
  43. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  44. package/scripts/agent-eval/probe-trace.mjs +20 -0
  45. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  46. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  47. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  48. package/scripts/agent-eval/run-agent.sh +34 -0
  49. package/scripts/agent-eval/run-all.sh +75 -0
  50. package/scripts/agent-eval/run-arms.sh +56 -0
  51. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  52. package/scripts/build-bundle.sh +123 -0
  53. package/scripts/extract-release-notes.mjs +130 -0
  54. package/scripts/local-install.sh +41 -0
  55. package/scripts/npm-sdk.js +75 -0
  56. package/scripts/npm-shim.js +275 -0
  57. package/scripts/pack-npm.sh +119 -0
  58. package/scripts/prepare-release.mjs +270 -0
  59. package/dist/bin/codegraph.d.ts +0 -25
  60. package/dist/bin/node-version-check.d.ts +0 -37
  61. package/dist/bin/uninstall.d.ts +0 -14
  62. package/dist/context/formatter.d.ts +0 -33
  63. package/dist/context/formatter.js +0 -244
  64. package/dist/context/index.d.ts +0 -117
  65. package/dist/context/index.js +0 -1050
  66. package/dist/db/index.d.ts +0 -101
  67. package/dist/db/index.js +0 -250
  68. package/dist/db/migrations.d.ts +0 -47
  69. package/dist/db/migrations.js +0 -131
  70. package/dist/db/queries.d.ts +0 -291
  71. package/dist/db/queries.js +0 -1349
  72. package/dist/db/schema.sql +0 -151
  73. package/dist/db/sqlite-adapter.d.ts +0 -49
  74. package/dist/db/sqlite-adapter.js +0 -141
  75. package/dist/directory.d.ts +0 -62
  76. package/dist/directory.js +0 -264
  77. package/dist/errors.d.ts +0 -149
  78. package/dist/errors.js +0 -219
  79. package/dist/extraction/dfm-extractor.d.ts +0 -31
  80. package/dist/extraction/dfm-extractor.js +0 -151
  81. package/dist/extraction/grammars.d.ts +0 -94
  82. package/dist/extraction/grammars.js +0 -357
  83. package/dist/extraction/index.d.ts +0 -148
  84. package/dist/extraction/index.js +0 -1286
  85. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  86. package/dist/extraction/languages/c-cpp.js +0 -126
  87. package/dist/extraction/languages/csharp.d.ts +0 -3
  88. package/dist/extraction/languages/csharp.js +0 -72
  89. package/dist/extraction/languages/dart.d.ts +0 -3
  90. package/dist/extraction/languages/dart.js +0 -192
  91. package/dist/extraction/languages/go.d.ts +0 -3
  92. package/dist/extraction/languages/go.js +0 -58
  93. package/dist/extraction/languages/index.d.ts +0 -10
  94. package/dist/extraction/languages/index.js +0 -49
  95. package/dist/extraction/languages/java.d.ts +0 -3
  96. package/dist/extraction/languages/java.js +0 -64
  97. package/dist/extraction/languages/javascript.d.ts +0 -3
  98. package/dist/extraction/languages/javascript.js +0 -90
  99. package/dist/extraction/languages/kotlin.d.ts +0 -3
  100. package/dist/extraction/languages/kotlin.js +0 -253
  101. package/dist/extraction/languages/lua.d.ts +0 -3
  102. package/dist/extraction/languages/lua.js +0 -150
  103. package/dist/extraction/languages/luau.d.ts +0 -3
  104. package/dist/extraction/languages/luau.js +0 -37
  105. package/dist/extraction/languages/pascal.d.ts +0 -3
  106. package/dist/extraction/languages/pascal.js +0 -66
  107. package/dist/extraction/languages/php.d.ts +0 -3
  108. package/dist/extraction/languages/php.js +0 -107
  109. package/dist/extraction/languages/python.d.ts +0 -3
  110. package/dist/extraction/languages/python.js +0 -56
  111. package/dist/extraction/languages/ruby.d.ts +0 -3
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/rust.d.ts +0 -3
  114. package/dist/extraction/languages/rust.js +0 -109
  115. package/dist/extraction/languages/scala.d.ts +0 -3
  116. package/dist/extraction/languages/scala.js +0 -139
  117. package/dist/extraction/languages/swift.d.ts +0 -3
  118. package/dist/extraction/languages/swift.js +0 -91
  119. package/dist/extraction/languages/typescript.d.ts +0 -3
  120. package/dist/extraction/languages/typescript.js +0 -129
  121. package/dist/extraction/liquid-extractor.d.ts +0 -52
  122. package/dist/extraction/liquid-extractor.js +0 -313
  123. package/dist/extraction/parse-worker.d.ts +0 -8
  124. package/dist/extraction/parse-worker.js +0 -94
  125. package/dist/extraction/svelte-extractor.d.ts +0 -56
  126. package/dist/extraction/svelte-extractor.js +0 -272
  127. package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
  128. package/dist/extraction/tree-sitter-helpers.js +0 -103
  129. package/dist/extraction/tree-sitter-types.d.ts +0 -191
  130. package/dist/extraction/tree-sitter-types.js +0 -10
  131. package/dist/extraction/tree-sitter.d.ts +0 -238
  132. package/dist/extraction/tree-sitter.js +0 -2430
  133. package/dist/extraction/vue-extractor.d.ts +0 -36
  134. package/dist/extraction/vue-extractor.js +0 -163
  135. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  136. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  137. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  138. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  139. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  140. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  141. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  142. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  143. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  144. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  145. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  146. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  147. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  148. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  149. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  150. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  151. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  152. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  153. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  154. package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
  155. package/dist/extraction/wasm-runtime-flags.js +0 -105
  156. package/dist/graph/index.d.ts +0 -8
  157. package/dist/graph/index.js +0 -13
  158. package/dist/graph/queries.d.ts +0 -109
  159. package/dist/graph/queries.js +0 -366
  160. package/dist/graph/traversal.d.ts +0 -137
  161. package/dist/graph/traversal.js +0 -528
  162. package/dist/index.d.ts +0 -509
  163. package/dist/index.js +0 -800
  164. package/dist/installer/claude-md-template.d.ts +0 -19
  165. package/dist/installer/config-writer.d.ts +0 -29
  166. package/dist/installer/index.d.ts +0 -140
  167. package/dist/installer/instructions-template.d.ts +0 -30
  168. package/dist/installer/targets/claude.d.ts +0 -55
  169. package/dist/installer/targets/codex.d.ts +0 -18
  170. package/dist/installer/targets/cursor.d.ts +0 -35
  171. package/dist/installer/targets/hermes.d.ts +0 -18
  172. package/dist/installer/targets/opencode.d.ts +0 -30
  173. package/dist/installer/targets/registry.d.ts +0 -38
  174. package/dist/installer/targets/shared.d.ts +0 -92
  175. package/dist/installer/targets/toml.d.ts +0 -64
  176. package/dist/installer/targets/types.d.ts +0 -122
  177. package/dist/mcp/index.d.ts +0 -98
  178. package/dist/mcp/server-instructions.d.ts +0 -20
  179. package/dist/mcp/tools.d.ts +0 -269
  180. package/dist/mcp/transport.d.ts +0 -117
  181. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
  182. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  183. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  184. package/dist/resolution/frameworks/csharp.js +0 -213
  185. package/dist/resolution/frameworks/drupal.d.ts +0 -51
  186. package/dist/resolution/frameworks/drupal.js +0 -335
  187. package/dist/resolution/frameworks/express.d.ts +0 -8
  188. package/dist/resolution/frameworks/express.js +0 -225
  189. package/dist/resolution/frameworks/go.d.ts +0 -8
  190. package/dist/resolution/frameworks/go.js +0 -158
  191. package/dist/resolution/frameworks/index.d.ts +0 -52
  192. package/dist/resolution/frameworks/index.js +0 -137
  193. package/dist/resolution/frameworks/java.d.ts +0 -8
  194. package/dist/resolution/frameworks/java.js +0 -177
  195. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  196. package/dist/resolution/frameworks/laravel.js +0 -248
  197. package/dist/resolution/frameworks/nestjs.d.ts +0 -26
  198. package/dist/resolution/frameworks/nestjs.js +0 -374
  199. package/dist/resolution/frameworks/python.d.ts +0 -10
  200. package/dist/resolution/frameworks/python.js +0 -278
  201. package/dist/resolution/frameworks/react.d.ts +0 -8
  202. package/dist/resolution/frameworks/react.js +0 -272
  203. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  204. package/dist/resolution/frameworks/ruby.js +0 -198
  205. package/dist/resolution/frameworks/rust.d.ts +0 -8
  206. package/dist/resolution/frameworks/rust.js +0 -207
  207. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  208. package/dist/resolution/frameworks/svelte.js +0 -249
  209. package/dist/resolution/frameworks/swift.d.ts +0 -10
  210. package/dist/resolution/frameworks/swift.js +0 -376
  211. package/dist/resolution/frameworks/vue.d.ts +0 -9
  212. package/dist/resolution/frameworks/vue.js +0 -306
  213. package/dist/resolution/import-resolver.d.ts +0 -61
  214. package/dist/resolution/import-resolver.js +0 -663
  215. package/dist/resolution/index.d.ts +0 -118
  216. package/dist/resolution/index.js +0 -744
  217. package/dist/resolution/lru-cache.d.ts +0 -24
  218. package/dist/resolution/lru-cache.js +0 -62
  219. package/dist/resolution/name-matcher.d.ts +0 -50
  220. package/dist/resolution/name-matcher.js +0 -384
  221. package/dist/resolution/path-aliases.d.ts +0 -72
  222. package/dist/resolution/path-aliases.js +0 -238
  223. package/dist/resolution/strip-comments.d.ts +0 -40
  224. package/dist/resolution/strip-comments.js +0 -441
  225. package/dist/resolution/types.d.ts +0 -181
  226. package/dist/resolution/types.js +0 -8
  227. package/dist/search/query-parser.d.ts +0 -61
  228. package/dist/search/query-parser.js +0 -177
  229. package/dist/search/query-utils.d.ts +0 -59
  230. package/dist/search/query-utils.js +0 -383
  231. package/dist/sync/git-hooks.d.ts +0 -54
  232. package/dist/sync/git-hooks.js +0 -223
  233. package/dist/sync/index.d.ts +0 -25
  234. package/dist/sync/index.js +0 -28
  235. package/dist/sync/watch-policy.d.ts +0 -51
  236. package/dist/sync/watch-policy.js +0 -124
  237. package/dist/sync/watcher.d.ts +0 -83
  238. package/dist/sync/watcher.js +0 -192
  239. package/dist/types.d.ts +0 -433
  240. package/dist/types.js +0 -75
  241. package/dist/ui/glyphs.d.ts +0 -42
  242. package/dist/ui/shimmer-progress.d.ts +0 -11
  243. package/dist/ui/shimmer-worker.d.ts +0 -2
  244. package/dist/ui/types.d.ts +0 -20
  245. package/dist/utils.d.ts +0 -231
  246. package/dist/utils.js +0 -549
@@ -1,366 +0,0 @@
1
- "use strict";
2
- /**
3
- * Graph Query Functions
4
- *
5
- * Higher-level query functions built on top of traversal algorithms.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.GraphQueryManager = void 0;
9
- const traversal_1 = require("./traversal");
10
- /**
11
- * Graph query manager for complex queries
12
- */
13
- class GraphQueryManager {
14
- queries;
15
- traverser;
16
- constructor(queries) {
17
- this.queries = queries;
18
- this.traverser = new traversal_1.GraphTraverser(queries);
19
- }
20
- /**
21
- * Get full context for a node
22
- *
23
- * Returns the focal node along with its ancestors, children,
24
- * and both incoming and outgoing references.
25
- *
26
- * @param nodeId - ID of the focal node
27
- * @returns Context object with all related information
28
- */
29
- getContext(nodeId) {
30
- const focal = this.queries.getNodeById(nodeId);
31
- if (!focal) {
32
- throw new Error(`Node not found: ${nodeId}`);
33
- }
34
- // Get ancestors (containment hierarchy)
35
- const ancestors = this.traverser.getAncestors(nodeId);
36
- // Get children
37
- const children = this.traverser.getChildren(nodeId);
38
- // Get incoming references (things that reference this node)
39
- const incomingEdges = this.queries.getIncomingEdges(nodeId);
40
- const incomingRefs = [];
41
- for (const edge of incomingEdges) {
42
- // Skip containment edges (already in ancestors)
43
- if (edge.kind === 'contains') {
44
- continue;
45
- }
46
- const node = this.queries.getNodeById(edge.source);
47
- if (node) {
48
- incomingRefs.push({ node, edge });
49
- }
50
- }
51
- // Get outgoing references (things this node references)
52
- const outgoingEdges = this.queries.getOutgoingEdges(nodeId);
53
- const outgoingRefs = [];
54
- for (const edge of outgoingEdges) {
55
- // Skip containment edges (already in children)
56
- if (edge.kind === 'contains') {
57
- continue;
58
- }
59
- const node = this.queries.getNodeById(edge.target);
60
- if (node) {
61
- outgoingRefs.push({ node, edge });
62
- }
63
- }
64
- // Get type information (type_of, returns edges)
65
- const types = [];
66
- const typeEdgeKinds = ['type_of', 'returns'];
67
- for (const kind of typeEdgeKinds) {
68
- const typeEdges = this.queries.getOutgoingEdges(nodeId, [kind]);
69
- for (const edge of typeEdges) {
70
- const typeNode = this.queries.getNodeById(edge.target);
71
- if (typeNode && !types.some((t) => t.id === typeNode.id)) {
72
- types.push(typeNode);
73
- }
74
- }
75
- }
76
- // Get relevant imports
77
- const imports = [];
78
- const fileNode = ancestors.find((a) => a.kind === 'file');
79
- if (fileNode) {
80
- const importEdges = this.queries.getOutgoingEdges(fileNode.id, ['imports']);
81
- for (const edge of importEdges) {
82
- const importNode = this.queries.getNodeById(edge.target);
83
- if (importNode) {
84
- imports.push(importNode);
85
- }
86
- }
87
- }
88
- return {
89
- focal,
90
- ancestors,
91
- children,
92
- incomingRefs,
93
- outgoingRefs,
94
- types,
95
- imports,
96
- };
97
- }
98
- /**
99
- * Get dependencies of a file
100
- *
101
- * Returns all files that this file imports from.
102
- *
103
- * @param filePath - Path to the file
104
- * @returns Array of file paths this file depends on
105
- */
106
- getFileDependencies(filePath) {
107
- const nodes = this.queries.getNodesByFile(filePath);
108
- const fileNode = nodes.find((n) => n.kind === 'file');
109
- if (!fileNode) {
110
- return [];
111
- }
112
- const dependencies = new Set();
113
- const importEdges = this.queries.getOutgoingEdges(fileNode.id, ['imports']);
114
- for (const edge of importEdges) {
115
- const targetNode = this.queries.getNodeById(edge.target);
116
- if (targetNode && targetNode.filePath !== filePath) {
117
- dependencies.add(targetNode.filePath);
118
- }
119
- }
120
- return Array.from(dependencies);
121
- }
122
- /**
123
- * Get dependents of a file
124
- *
125
- * Returns all files that import from this file.
126
- *
127
- * @param filePath - Path to the file
128
- * @returns Array of file paths that depend on this file
129
- */
130
- getFileDependents(filePath) {
131
- const nodes = this.queries.getNodesByFile(filePath);
132
- const dependents = new Set();
133
- // Check file-level incoming import edges (file:X imports file:Y)
134
- const fileNode = nodes.find((n) => n.kind === 'file');
135
- if (fileNode) {
136
- const incomingFileEdges = this.queries.getIncomingEdges(fileNode.id, ['imports']);
137
- for (const edge of incomingFileEdges) {
138
- const sourceNode = this.queries.getNodeById(edge.source);
139
- if (sourceNode && sourceNode.filePath !== filePath) {
140
- dependents.add(sourceNode.filePath);
141
- }
142
- }
143
- }
144
- // Also check node-level imports of exported symbols
145
- for (const node of nodes) {
146
- if (node.isExported) {
147
- const incomingEdges = this.queries.getIncomingEdges(node.id, ['imports']);
148
- for (const edge of incomingEdges) {
149
- const sourceNode = this.queries.getNodeById(edge.source);
150
- if (sourceNode && sourceNode.filePath !== filePath) {
151
- dependents.add(sourceNode.filePath);
152
- }
153
- }
154
- }
155
- }
156
- return Array.from(dependents);
157
- }
158
- /**
159
- * Get all symbols exported by a file
160
- *
161
- * @param filePath - Path to the file
162
- * @returns Array of exported nodes
163
- */
164
- getExportedSymbols(filePath) {
165
- const nodes = this.queries.getNodesByFile(filePath);
166
- return nodes.filter((n) => n.isExported);
167
- }
168
- /**
169
- * Find symbols by qualified name pattern
170
- *
171
- * @param pattern - Pattern to match (supports * wildcard)
172
- * @returns Array of matching nodes
173
- */
174
- findByQualifiedName(pattern) {
175
- // Convert glob pattern to regex
176
- const regexPattern = pattern
177
- .replace(/[.+^${}()|[\]\\]/g, '\\$&')
178
- .replace(/\*/g, '.*')
179
- .replace(/\?/g, '.');
180
- const regex = new RegExp(`^${regexPattern}$`);
181
- // This is inefficient for large graphs - would need FTS index on qualified_name
182
- // For now, use kind-based filtering if possible
183
- const allNodes = [];
184
- const kinds = [
185
- 'class',
186
- 'function',
187
- 'method',
188
- 'interface',
189
- 'type_alias',
190
- 'variable',
191
- 'constant',
192
- ];
193
- for (const kind of kinds) {
194
- const nodes = this.queries.getNodesByKind(kind);
195
- for (const node of nodes) {
196
- if (regex.test(node.qualifiedName)) {
197
- allNodes.push(node);
198
- }
199
- }
200
- }
201
- return allNodes;
202
- }
203
- /**
204
- * Get the module/package structure
205
- *
206
- * Returns a tree structure of files organized by directory.
207
- *
208
- * @returns Map of directory paths to contained files
209
- */
210
- getModuleStructure() {
211
- const files = this.queries.getAllFiles();
212
- const structure = new Map();
213
- for (const file of files) {
214
- const parts = file.path.split('/');
215
- const dir = parts.slice(0, -1).join('/') || '.';
216
- if (!structure.has(dir)) {
217
- structure.set(dir, []);
218
- }
219
- structure.get(dir).push(file.path);
220
- }
221
- return structure;
222
- }
223
- /**
224
- * Find circular dependencies in the graph
225
- *
226
- * @returns Array of cycles, each cycle is an array of node IDs
227
- */
228
- findCircularDependencies() {
229
- const files = this.queries.getAllFiles();
230
- const cycles = [];
231
- const visited = new Set();
232
- const recursionStack = new Set();
233
- const dfs = (filePath, path) => {
234
- if (recursionStack.has(filePath)) {
235
- // Found a cycle
236
- const cycleStart = path.indexOf(filePath);
237
- if (cycleStart !== -1) {
238
- cycles.push(path.slice(cycleStart));
239
- }
240
- return;
241
- }
242
- if (visited.has(filePath)) {
243
- return;
244
- }
245
- visited.add(filePath);
246
- recursionStack.add(filePath);
247
- const dependencies = this.getFileDependencies(filePath);
248
- for (const dep of dependencies) {
249
- dfs(dep, [...path, filePath]);
250
- }
251
- recursionStack.delete(filePath);
252
- };
253
- for (const file of files) {
254
- if (!visited.has(file.path)) {
255
- dfs(file.path, []);
256
- }
257
- }
258
- return cycles;
259
- }
260
- /**
261
- * Get complexity metrics for a node
262
- *
263
- * @param nodeId - ID of the node
264
- * @returns Object containing various complexity metrics
265
- */
266
- getNodeMetrics(nodeId) {
267
- const incomingEdges = this.queries.getIncomingEdges(nodeId);
268
- const outgoingEdges = this.queries.getOutgoingEdges(nodeId);
269
- const callEdges = outgoingEdges.filter((e) => e.kind === 'calls');
270
- const callerEdges = incomingEdges.filter((e) => e.kind === 'calls');
271
- const containsEdges = outgoingEdges.filter((e) => e.kind === 'contains');
272
- const ancestors = this.traverser.getAncestors(nodeId);
273
- return {
274
- incomingEdgeCount: incomingEdges.length,
275
- outgoingEdgeCount: outgoingEdges.length,
276
- callCount: callEdges.length,
277
- callerCount: callerEdges.length,
278
- childCount: containsEdges.length,
279
- depth: ancestors.length,
280
- };
281
- }
282
- /**
283
- * Find dead code (nodes with no incoming references)
284
- *
285
- * @param kinds - Node kinds to check (default: functions, methods, classes)
286
- * @returns Array of unreferenced nodes
287
- */
288
- findDeadCode(kinds) {
289
- const targetKinds = kinds || ['function', 'method', 'class'];
290
- const deadCode = [];
291
- for (const kind of targetKinds) {
292
- const nodes = this.queries.getNodesByKind(kind);
293
- for (const node of nodes) {
294
- // Skip exported symbols (they may be used externally)
295
- if (node.isExported) {
296
- continue;
297
- }
298
- const incomingEdges = this.queries.getIncomingEdges(node.id);
299
- // Filter out containment edges
300
- const references = incomingEdges.filter((e) => e.kind !== 'contains');
301
- if (references.length === 0) {
302
- deadCode.push(node);
303
- }
304
- }
305
- }
306
- return deadCode;
307
- }
308
- /**
309
- * Get subgraph containing nodes matching a filter
310
- *
311
- * @param filter - Filter function to select nodes
312
- * @param includeEdges - Whether to include edges between matching nodes
313
- * @returns Subgraph containing matching nodes
314
- */
315
- getFilteredSubgraph(filter, includeEdges = true) {
316
- const nodes = new Map();
317
- const edges = [];
318
- // Get all nodes of common kinds
319
- const kinds = [
320
- 'file',
321
- 'module',
322
- 'class',
323
- 'struct',
324
- 'interface',
325
- 'trait',
326
- 'function',
327
- 'method',
328
- 'variable',
329
- 'constant',
330
- 'enum',
331
- 'type_alias',
332
- ];
333
- for (const kind of kinds) {
334
- const kindNodes = this.queries.getNodesByKind(kind);
335
- for (const node of kindNodes) {
336
- if (filter(node)) {
337
- nodes.set(node.id, node);
338
- }
339
- }
340
- }
341
- // Include edges between matching nodes
342
- if (includeEdges) {
343
- for (const nodeId of nodes.keys()) {
344
- const outgoing = this.queries.getOutgoingEdges(nodeId);
345
- for (const edge of outgoing) {
346
- if (nodes.has(edge.target)) {
347
- edges.push(edge);
348
- }
349
- }
350
- }
351
- }
352
- return {
353
- nodes,
354
- edges,
355
- roots: [],
356
- };
357
- }
358
- /**
359
- * Access the underlying traverser for direct traversal operations
360
- */
361
- getTraverser() {
362
- return this.traverser;
363
- }
364
- }
365
- exports.GraphQueryManager = GraphQueryManager;
366
- //# sourceMappingURL=queries.js.map
@@ -1,137 +0,0 @@
1
- /**
2
- * Graph Traversal Algorithms
3
- *
4
- * BFS and DFS traversal for the code knowledge graph.
5
- */
6
- import { Node, Edge, Subgraph, TraversalOptions, EdgeKind } from '../types'
7
- import { QueryBuilder } from '../db/queries'
8
- /**
9
- * Graph traverser for BFS and DFS traversal
10
- */
11
- export declare class GraphTraverser {
12
- private queries
13
- constructor(queries: QueryBuilder)
14
- /**
15
- * Traverse the graph using breadth-first search
16
- *
17
- * @param startId - Starting node ID
18
- * @param options - Traversal options
19
- * @returns Subgraph containing traversed nodes and edges
20
- */
21
- traverseBFS(startId: string, options?: TraversalOptions): Subgraph
22
- /**
23
- * Traverse the graph using depth-first search
24
- *
25
- * @param startId - Starting node ID
26
- * @param options - Traversal options
27
- * @returns Subgraph containing traversed nodes and edges
28
- */
29
- traverseDFS(startId: string, options?: TraversalOptions): Subgraph
30
- /**
31
- * Recursive DFS helper
32
- */
33
- private dfsRecursive
34
- /**
35
- * Get adjacent edges based on direction
36
- */
37
- private getAdjacentEdges
38
- /**
39
- * Find all callers of a function/method
40
- *
41
- * @param nodeId - ID of the function/method node
42
- * @param maxDepth - Maximum depth to traverse (default: 1)
43
- * @returns Array of nodes that call this function
44
- */
45
- getCallers(
46
- nodeId: string,
47
- maxDepth?: number,
48
- ): Array<{
49
- node: Node
50
- edge: Edge
51
- }>
52
- private getCallersRecursive
53
- /**
54
- * Find all functions/methods called by a function
55
- *
56
- * @param nodeId - ID of the function/method node
57
- * @param maxDepth - Maximum depth to traverse (default: 1)
58
- * @returns Array of nodes called by this function
59
- */
60
- getCallees(
61
- nodeId: string,
62
- maxDepth?: number,
63
- ): Array<{
64
- node: Node
65
- edge: Edge
66
- }>
67
- private getCalleesRecursive
68
- /**
69
- * Get the call graph for a function (both callers and callees)
70
- *
71
- * @param nodeId - ID of the function/method node
72
- * @param depth - Maximum depth in each direction (default: 2)
73
- * @returns Subgraph containing the call graph
74
- */
75
- getCallGraph(nodeId: string, depth?: number): Subgraph
76
- /**
77
- * Get the type hierarchy for a class/interface
78
- *
79
- * @param nodeId - ID of the class/interface node
80
- * @returns Subgraph containing the type hierarchy
81
- */
82
- getTypeHierarchy(nodeId: string): Subgraph
83
- private getTypeAncestors
84
- private getTypeDescendants
85
- /**
86
- * Find all usages of a symbol
87
- *
88
- * @param nodeId - ID of the symbol node
89
- * @returns Array of nodes and edges that reference this symbol
90
- */
91
- findUsages(nodeId: string): Array<{
92
- node: Node
93
- edge: Edge
94
- }>
95
- /**
96
- * Calculate the impact radius of a node
97
- *
98
- * Returns all nodes that could be affected by changes to this node.
99
- *
100
- * @param nodeId - ID of the node
101
- * @param maxDepth - Maximum depth to traverse (default: 3)
102
- * @returns Subgraph containing potentially impacted nodes
103
- */
104
- getImpactRadius(nodeId: string, maxDepth?: number): Subgraph
105
- private getImpactRecursive
106
- /**
107
- * Find the shortest path between two nodes
108
- *
109
- * @param fromId - Starting node ID
110
- * @param toId - Target node ID
111
- * @param edgeKinds - Edge types to consider (all if empty)
112
- * @returns Array of nodes and edges forming the path, or null if no path exists
113
- */
114
- findPath(
115
- fromId: string,
116
- toId: string,
117
- edgeKinds?: EdgeKind[],
118
- ): Array<{
119
- node: Node
120
- edge: Edge | null
121
- }> | null
122
- /**
123
- * Get the containment hierarchy for a node (ancestors)
124
- *
125
- * @param nodeId - ID of the node
126
- * @returns Array of ancestor nodes from immediate parent to root
127
- */
128
- getAncestors(nodeId: string): Node[]
129
- /**
130
- * Get immediate children of a node
131
- *
132
- * @param nodeId - ID of the node
133
- * @returns Array of child nodes
134
- */
135
- getChildren(nodeId: string): Node[]
136
- }
137
- //# sourceMappingURL=traversal.d.ts.map