scip-query 0.4.3 → 0.6.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 (199) hide show
  1. package/dist/chunk-2DSS2NGF.js +10 -0
  2. package/dist/chunk-2RLP74AO.js +2 -0
  3. package/dist/chunk-4QJ7LVW5.js +2 -0
  4. package/dist/chunk-4TYGGOLO.js +5 -0
  5. package/dist/chunk-5IADAU5B.js +7 -0
  6. package/dist/chunk-7754WFFV.js +18 -0
  7. package/dist/chunk-7VOF4ZG6.js +2 -0
  8. package/dist/chunk-7Z4COVMC.js +2 -0
  9. package/dist/chunk-AJ5PWKD4.js +2 -0
  10. package/dist/chunk-BDBRZPX3.js +7 -0
  11. package/dist/chunk-BE6EQIWY.js +2 -0
  12. package/dist/chunk-BQ3INTYT.js +8 -0
  13. package/dist/chunk-D7KLLMPB.js +2 -0
  14. package/dist/chunk-D7YBWSON.js +29 -0
  15. package/dist/chunk-DE5ZBHMK.js +39 -0
  16. package/dist/chunk-DHYIJHXZ.js +33 -0
  17. package/dist/chunk-EEF3YEHW.js +2 -0
  18. package/dist/chunk-F2LLHRRZ.js +2 -0
  19. package/dist/chunk-FCC3XJTI.js +2 -0
  20. package/dist/chunk-GNXRLK5G.js +2 -0
  21. package/dist/chunk-GXVB36TG.js +62 -0
  22. package/dist/chunk-HMKJTAZD.js +2 -0
  23. package/dist/chunk-IBGBI3VU.js +2 -0
  24. package/dist/chunk-IYFZS4PV.js +84 -0
  25. package/dist/chunk-JH3A7HTU.js +2 -0
  26. package/dist/chunk-JS2RNIC7.js +2 -0
  27. package/dist/chunk-K5FQFCSN.js +41 -0
  28. package/dist/chunk-K6GBKEQE.js +6 -0
  29. package/dist/chunk-KO7YJRWP.js +12 -0
  30. package/dist/chunk-KYT47WU2.js +4 -0
  31. package/dist/chunk-LORWXBOO.js +2 -0
  32. package/dist/chunk-LX4H4LLG.js +89 -0
  33. package/dist/chunk-N3Z2SJCR.js +2 -0
  34. package/dist/chunk-NTDA4A2D.js +25 -0
  35. package/dist/chunk-NXMYYHDO.js +24 -0
  36. package/dist/chunk-PZ6ESKRH.js +7 -0
  37. package/dist/chunk-QXE6EDY2.js +6 -0
  38. package/dist/chunk-RJ7SPBJ5.js +5 -0
  39. package/dist/chunk-RWE6FHG3.js +3 -0
  40. package/dist/chunk-SDX6MDBL.js +2 -0
  41. package/dist/chunk-SG35Y7J2.js +2 -0
  42. package/dist/chunk-STOGKRJH.js +4 -0
  43. package/dist/chunk-TINPMWJK.js +2 -0
  44. package/dist/chunk-UJB62HV3.js +2 -0
  45. package/dist/chunk-VEUMRDHW.js +2 -0
  46. package/dist/chunk-WCDXJGYT.js +65 -0
  47. package/dist/chunk-WTSTDJZ7.js +6 -0
  48. package/dist/chunk-XAZTIDST.js +2 -0
  49. package/dist/chunk-XVDASCN7.js +35 -0
  50. package/dist/chunk-Y7H6D2EV.js +2 -0
  51. package/dist/chunk-Y7LOQSWY.js +2 -0
  52. package/dist/chunk-YIPCV7M7.js +70 -0
  53. package/dist/chunk-ZSRXMNMK.js +5 -0
  54. package/dist/chunk-ZXKURFVB.js +56 -0
  55. package/dist/cli.js +509 -8938
  56. package/dist/{db-6F9R9e_t.d.ts → db-BSTtBG_H.d.ts} +146 -1
  57. package/dist/index.d.ts +11 -2
  58. package/dist/index.js +13 -1616
  59. package/dist/postinstall.js +4 -100
  60. package/dist/queries/affected.d.ts +1 -1
  61. package/dist/queries/affected.js +1 -8
  62. package/dist/queries/bottlenecks.d.ts +1 -1
  63. package/dist/queries/bottlenecks.js +1 -8
  64. package/dist/queries/by-kind.d.ts +1 -4
  65. package/dist/queries/by-kind.js +1 -10
  66. package/dist/queries/call-graph.d.ts +1 -1
  67. package/dist/queries/call-graph.js +1 -8
  68. package/dist/queries/change-surface.d.ts +4 -1
  69. package/dist/queries/change-surface.js +1 -8
  70. package/dist/queries/code.d.ts +1 -1
  71. package/dist/queries/code.js +1 -8
  72. package/dist/queries/complexity-hotspots.d.ts +5 -3
  73. package/dist/queries/complexity-hotspots.js +1 -8
  74. package/dist/queries/complexity.d.ts +1 -1
  75. package/dist/queries/complexity.js +1 -8
  76. package/dist/queries/convergence.d.ts +1 -1
  77. package/dist/queries/convergence.js +1 -8
  78. package/dist/queries/coupling.d.ts +1 -1
  79. package/dist/queries/coupling.js +1 -10
  80. package/dist/queries/cycles.d.ts +1 -1
  81. package/dist/queries/cycles.js +1 -8
  82. package/dist/queries/dataflow.d.ts +1 -1
  83. package/dist/queries/dataflow.js +1 -8
  84. package/dist/queries/dead.d.ts +1 -1
  85. package/dist/queries/dead.js +1 -9
  86. package/dist/queries/deep-chains.d.ts +9 -1
  87. package/dist/queries/deep-chains.js +1 -8
  88. package/dist/queries/deps.d.ts +1 -1
  89. package/dist/queries/deps.js +1 -10
  90. package/dist/queries/diff-impact.d.ts +1 -1
  91. package/dist/queries/diff-impact.js +1 -7
  92. package/dist/queries/drift.d.ts +1 -1
  93. package/dist/queries/drift.js +1 -8
  94. package/dist/queries/extract-candidates.d.ts +1 -1
  95. package/dist/queries/extract-candidates.js +1 -8
  96. package/dist/queries/fan.d.ts +1 -1
  97. package/dist/queries/fan.js +1 -14
  98. package/dist/queries/files.d.ts +1 -1
  99. package/dist/queries/files.js +1 -6
  100. package/dist/queries/health.d.ts +1 -1
  101. package/dist/queries/health.js +1 -20
  102. package/dist/queries/hierarchy.d.ts +1 -1
  103. package/dist/queries/hierarchy.js +1 -8
  104. package/dist/queries/hotspots.d.ts +1 -1
  105. package/dist/queries/hotspots.js +1 -8
  106. package/dist/queries/imports.d.ts +1 -1
  107. package/dist/queries/imports.js +1 -12
  108. package/dist/queries/index.d.ts +1 -1
  109. package/dist/queries/index.js +1 -197
  110. package/dist/queries/isolated.d.ts +1 -1
  111. package/dist/queries/isolated.js +1 -9
  112. package/dist/queries/members.d.ts +4 -1
  113. package/dist/queries/members.js +1 -8
  114. package/dist/queries/methods.d.ts +1 -1
  115. package/dist/queries/methods.js +1 -8
  116. package/dist/queries/outline.d.ts +4 -1
  117. package/dist/queries/outline.js +1 -8
  118. package/dist/queries/passthrough-candidates.d.ts +1 -1
  119. package/dist/queries/passthrough-candidates.js +1 -8
  120. package/dist/queries/redundant-reexports.d.ts +1 -1
  121. package/dist/queries/redundant-reexports.js +1 -9
  122. package/dist/queries/refs.d.ts +1 -1
  123. package/dist/queries/refs.js +1 -8
  124. package/dist/queries/similar-chains.d.ts +1 -1
  125. package/dist/queries/similar-chains.js +1 -8
  126. package/dist/queries/similar-files.d.ts +1 -1
  127. package/dist/queries/similar-files.js +1 -8
  128. package/dist/queries/similar-signatures.d.ts +1 -1
  129. package/dist/queries/similar-signatures.js +1 -8
  130. package/dist/queries/similar.d.ts +1 -1
  131. package/dist/queries/similar.js +1 -10
  132. package/dist/queries/slice.d.ts +1 -1
  133. package/dist/queries/slice.js +1 -8
  134. package/dist/queries/stale-abstractions.d.ts +15 -5
  135. package/dist/queries/stale-abstractions.js +1 -8
  136. package/dist/queries/stats.d.ts +1 -1
  137. package/dist/queries/stats.js +1 -6
  138. package/dist/queries/surface.d.ts +1 -1
  139. package/dist/queries/surface.js +1 -8
  140. package/dist/queries/symbols.d.ts +1 -1
  141. package/dist/queries/symbols.js +1 -9
  142. package/dist/queries/system.d.ts +6 -2
  143. package/dist/queries/system.js +1 -9
  144. package/dist/queries/trace.d.ts +1 -1
  145. package/dist/queries/trace.js +1 -9
  146. package/dist/queries/wrapper-candidates.d.ts +1 -1
  147. package/dist/queries/wrapper-candidates.js +1 -8
  148. package/dist/reindex-worker.js +7 -672
  149. package/package.json +20 -2
  150. package/dist/chunk-334PCFO3.js +0 -221
  151. package/dist/chunk-46ZTW4AI.js +0 -61
  152. package/dist/chunk-4TYLS5XX.js +0 -10
  153. package/dist/chunk-4YN3PE57.js +0 -124
  154. package/dist/chunk-5YB6UXQ3.js +0 -101
  155. package/dist/chunk-6PVHJ332.js +0 -44
  156. package/dist/chunk-74RFWB5T.js +0 -24
  157. package/dist/chunk-7KGTWDAX.js +0 -87
  158. package/dist/chunk-7OGXSMLY.js +0 -105
  159. package/dist/chunk-AEBM56CO.js +0 -69
  160. package/dist/chunk-B747RITP.js +0 -38
  161. package/dist/chunk-B7LDMCUS.js +0 -110
  162. package/dist/chunk-C2VSV54P.js +0 -110
  163. package/dist/chunk-DIYEUFVP.js +0 -81
  164. package/dist/chunk-E74RY6AQ.js +0 -93
  165. package/dist/chunk-FIMTTUGE.js +0 -165
  166. package/dist/chunk-FMAYH7GS.js +0 -2542
  167. package/dist/chunk-FO2CBB7U.js +0 -23
  168. package/dist/chunk-HESWGDIV.js +0 -162
  169. package/dist/chunk-HL2LXSBW.js +0 -34
  170. package/dist/chunk-HW76DVE4.js +0 -216
  171. package/dist/chunk-IC5NTO47.js +0 -53
  172. package/dist/chunk-J34HAAEQ.js +0 -59
  173. package/dist/chunk-JSXGC2EH.js +0 -151
  174. package/dist/chunk-LQXBFCP2.js +0 -87
  175. package/dist/chunk-NML6M5AS.js +0 -37
  176. package/dist/chunk-NNFP4ZRF.js +0 -72
  177. package/dist/chunk-NWXTQGUE.js +0 -49
  178. package/dist/chunk-NYZ6INK3.js +0 -95
  179. package/dist/chunk-OMVF3BHY.js +0 -84
  180. package/dist/chunk-P3VCDYMJ.js +0 -269
  181. package/dist/chunk-PGQXIAJF.js +0 -79
  182. package/dist/chunk-PKDFXASW.js +0 -76
  183. package/dist/chunk-PSK5BPFE.js +0 -82
  184. package/dist/chunk-QZ4FRB65.js +0 -341
  185. package/dist/chunk-R2QBMQQN.js +0 -185
  186. package/dist/chunk-T3ALCNCP.js +0 -113
  187. package/dist/chunk-T6UVM534.js +0 -213
  188. package/dist/chunk-U74VYTLX.js +0 -46
  189. package/dist/chunk-UIRCHPOU.js +0 -34
  190. package/dist/chunk-UNS6ZQVX.js +0 -71
  191. package/dist/chunk-VJMTX3OR.js +0 -115
  192. package/dist/chunk-XJSPWHNT.js +0 -64
  193. package/dist/chunk-XMZAC2VU.js +0 -84
  194. package/dist/chunk-Y7FKURZG.js +0 -130
  195. package/dist/chunk-YMSJCSRG.js +0 -213
  196. package/dist/chunk-YQIWS5V6.js +0 -172
  197. package/dist/chunk-ZPEI7DRJ.js +0 -66
  198. package/dist/queries/clean-signature.d.ts +0 -9
  199. package/dist/queries/clean-signature.js +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scip-query",
3
- "version": "0.4.3",
3
+ "version": "0.6.0",
4
4
  "description": "Language-agnostic code intelligence CLI powered by SCIP indexes",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -66,9 +66,27 @@
66
66
  "commander": "^13.1.0",
67
67
  "ignore": "^7.0.3"
68
68
  },
69
+ "//optionalDependencies": "Native parsers and bundled SCIP indexers go in optionalDependencies so a failed install (missing build tools, restricted registry, incompatible platform) downgrades scip-query gracefully — the affected language falls back to regex parsing or asks the user to install its indexer manually — instead of blocking npm install.",
70
+ "optionalDependencies": {
71
+ "@sourcegraph/scip-typescript": "^0.4.0",
72
+ "scip-python-plus": "^0.7.4",
73
+ "tree-sitter": "^0.22.4",
74
+ "tree-sitter-c": "^0.21.4",
75
+ "tree-sitter-c-sharp": "^0.21.3",
76
+ "tree-sitter-cpp": "^0.22.3",
77
+ "tree-sitter-java": "^0.21.0",
78
+ "tree-sitter-javascript": "^0.23.1",
79
+ "tree-sitter-kotlin": "^0.3.8",
80
+ "tree-sitter-php": "^0.23.11",
81
+ "tree-sitter-python": "^0.23.6",
82
+ "tree-sitter-ruby": "^0.23.1",
83
+ "tree-sitter-rust": "^0.23.3",
84
+ "tree-sitter-scala": "^0.24.0",
85
+ "tree-sitter-typescript": "^0.23.2",
86
+ "tree-sitter-vb-dotnet": "^0.1.9"
87
+ },
69
88
  "devDependencies": {
70
89
  "@eslint/js": "^10.0.1",
71
- "@sourcegraph/scip-typescript": "^0.4.0",
72
90
  "@types/better-sqlite3": "^7.6.12",
73
91
  "@types/node": "^22.10.0",
74
92
  "eslint": "^10.2.0",
@@ -1,221 +0,0 @@
1
- import {
2
- stats
3
- } from "./chunk-74RFWB5T.js";
4
- import {
5
- wrapperCandidates
6
- } from "./chunk-7OGXSMLY.js";
7
- import {
8
- similarAll
9
- } from "./chunk-QZ4FRB65.js";
10
- import {
11
- staleAbstractions
12
- } from "./chunk-XJSPWHNT.js";
13
- import {
14
- isolated
15
- } from "./chunk-UIRCHPOU.js";
16
- import {
17
- passthroughCandidates
18
- } from "./chunk-NWXTQGUE.js";
19
- import {
20
- drift
21
- } from "./chunk-FIMTTUGE.js";
22
- import {
23
- extractCandidates
24
- } from "./chunk-5YB6UXQ3.js";
25
- import {
26
- complexityHotspots
27
- } from "./chunk-Y7FKURZG.js";
28
- import {
29
- cycles
30
- } from "./chunk-46ZTW4AI.js";
31
- import {
32
- dead
33
- } from "./chunk-C2VSV54P.js";
34
- import {
35
- isEntrySurface
36
- } from "./chunk-OMVF3BHY.js";
37
-
38
- // src/queries/health.ts
39
- function health(db, opts = {}) {
40
- const { scope } = opts;
41
- const s = stats(db);
42
- const deadResult = dead(db, { scope, minLoc: 3, skipBarrels: true });
43
- const isolatedResult = isolated(db, { scope, minLoc: 3 });
44
- const cycleResult = cycles(db, { scope });
45
- const similarResult = similarAll(db, { scope, minSimilarity: 0.6, limit: 50, minCallees: 4 });
46
- const extractResult = extractCandidates(db, { scope, minLoc: 15, minCallees: 5, limit: 50 });
47
- const wrapperResult = wrapperCandidates(db, { scope, maxLoc: 15, limit: 50 });
48
- const passthroughResult = passthroughCandidates(db, { scope, maxLoc: 15, limit: 50 });
49
- const staleResult = staleAbstractions(db, { scope, minLoc: 3, limit: 50 });
50
- const driftResult = drift(db, { scope });
51
- const complexResult = complexityHotspots(db, { scope, minLoc: 10, limit: 10 });
52
- const trueDeadSymbols = deadResult.symbols.filter(
53
- (s2) => !isEntrySurface(db, s2.relativePath) && s2.kind === "dead-code"
54
- );
55
- const trueDeadCount = trueDeadSymbols.length;
56
- const trueDeadLoc = trueDeadSymbols.reduce((sum, s2) => sum + s2.loc, 0);
57
- const trueIsolatedCount = isolatedResult.filter(
58
- (s2) => !isEntrySurface(db, s2.relativePath)
59
- ).length;
60
- const trueStaleCount = staleResult.length;
61
- const trueDriftCount = driftResult.results.length;
62
- const trueSimilarCount = similarResult.length;
63
- const actions = [];
64
- if (trueDeadCount > 0) {
65
- actions.push({
66
- category: "Dead code",
67
- description: `${trueDeadCount} symbols with zero references anywhere \u2014 safe to delete`,
68
- effort: "low",
69
- impact: "high",
70
- count: trueDeadCount,
71
- locRecoverable: trueDeadLoc
72
- });
73
- }
74
- if (trueIsolatedCount > 0) {
75
- actions.push({
76
- category: "Isolated symbols",
77
- description: `${trueIsolatedCount} symbols completely disconnected from the codebase graph`,
78
- effort: "low",
79
- impact: "medium",
80
- count: trueIsolatedCount,
81
- locRecoverable: isolatedResult.filter((s2) => !isEntrySurface(db, s2.relativePath)).reduce((sum, s2) => sum + s2.loc, 0)
82
- });
83
- }
84
- if (cycleResult.length > 0) {
85
- actions.push({
86
- category: "Circular dependencies",
87
- description: `${cycleResult.length} cycle(s) \u2014 break with dependency inversion or module restructuring`,
88
- effort: "medium",
89
- impact: "high",
90
- count: cycleResult.length,
91
- locRecoverable: 0
92
- });
93
- }
94
- if (trueSimilarCount > 0) {
95
- actions.push({
96
- category: "Similar functions",
97
- description: `${trueSimilarCount} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,
98
- effort: "medium",
99
- impact: "medium",
100
- count: trueSimilarCount,
101
- locRecoverable: 0
102
- });
103
- }
104
- if (extractResult.length > 0) {
105
- actions.push({
106
- category: "Extraction candidates",
107
- description: `${extractResult.length} large functions with isolated callee clusters \u2014 extract method opportunities`,
108
- effort: "medium",
109
- impact: "medium",
110
- count: extractResult.length,
111
- locRecoverable: 0
112
- });
113
- }
114
- if (wrapperResult.length > 0) {
115
- actions.push({
116
- category: "Wrapper functions",
117
- description: `${wrapperResult.length} single-consumer symbols that could be inlined`,
118
- effort: "low",
119
- impact: "low",
120
- count: wrapperResult.length,
121
- locRecoverable: wrapperResult.reduce((sum, r) => sum + r.loc, 0)
122
- });
123
- }
124
- if (passthroughResult.length > 0) {
125
- actions.push({
126
- category: "Passthrough functions",
127
- description: `${passthroughResult.length} functions that just forward to one callee \u2014 unnecessary indirection`,
128
- effort: "low",
129
- impact: "low",
130
- count: passthroughResult.length,
131
- locRecoverable: passthroughResult.reduce((sum, r) => sum + r.loc, 0)
132
- });
133
- }
134
- if (trueStaleCount > 0) {
135
- const unused = staleResult.filter((s2) => s2.consumers === 0).length;
136
- const singleUse = trueStaleCount - unused;
137
- const parts = [];
138
- if (unused > 0) parts.push(`${unused} unused`);
139
- if (singleUse > 0) parts.push(`${singleUse} single-consumer (not in types file)`);
140
- actions.push({
141
- category: "Stale abstractions",
142
- description: `${parts.join(", ")} \u2014 premature abstraction`,
143
- effort: "low",
144
- impact: "medium",
145
- count: trueStaleCount,
146
- locRecoverable: staleResult.reduce((sum, r) => sum + r.loc, 0)
147
- });
148
- }
149
- if (trueDriftCount > 0) {
150
- const parts = [];
151
- if (driftResult.unusedImports > 0) parts.push(`${driftResult.unusedImports} unused imports`);
152
- if (driftResult.layerViolations > 0) parts.push(`${driftResult.layerViolations} layer violations`);
153
- if (driftResult.patternDeviations > 0) parts.push(`${driftResult.patternDeviations} unique deps`);
154
- actions.push({
155
- category: "Structural drift",
156
- description: parts.join(", "),
157
- effort: driftResult.layerViolations > 0 ? "medium" : "low",
158
- impact: driftResult.layerViolations > 0 ? "medium" : "low",
159
- count: trueDriftCount,
160
- locRecoverable: 0
161
- });
162
- }
163
- const impactWeight = { high: 3, medium: 2, low: 1 };
164
- const effortWeight = { low: 3, medium: 2, high: 1 };
165
- actions.sort((a, b) => {
166
- const scoreA = impactWeight[a.impact] * effortWeight[a.effort];
167
- const scoreB = impactWeight[b.impact] * effortWeight[b.effort];
168
- return scoreB - scoreA;
169
- });
170
- const fileCount = Math.max(s.documents, 1);
171
- const symbolCount = Math.max(s.symbols, 1);
172
- let score = 100;
173
- const deadPercent = trueDeadCount / symbolCount;
174
- score -= Math.min(20, Math.round(deadPercent * 200));
175
- const isolatedPercent = trueIsolatedCount / symbolCount;
176
- score -= Math.min(10, Math.round(isolatedPercent * 200));
177
- score -= Math.min(15, cycleResult.length * 5);
178
- score -= Math.min(10, trueSimilarCount * 2);
179
- score -= Math.min(5, extractResult.length * 2);
180
- score -= Math.min(3, wrapperResult.length);
181
- score -= Math.min(3, passthroughResult.length);
182
- const stalePercent = trueStaleCount / Math.max(symbolCount * 0.1, 1);
183
- score -= Math.min(8, Math.round(stalePercent * 10));
184
- const driftPercent = trueDriftCount / fileCount;
185
- score -= Math.min(5, Math.round(driftPercent * 50));
186
- const extremeComplexity = complexResult.filter((r) => r.score > 50).length;
187
- score -= Math.min(5, extremeComplexity * 2);
188
- score = Math.max(0, Math.min(100, score));
189
- return {
190
- score,
191
- overview: {
192
- documents: s.documents,
193
- symbols: s.symbols,
194
- indexSizeBytes: s.indexSizeBytes
195
- },
196
- findings: {
197
- deadSymbols: trueDeadCount,
198
- deadLoc: trueDeadLoc,
199
- isolatedSymbols: trueIsolatedCount,
200
- isolatedLoc: isolatedResult.filter((s2) => !isEntrySurface(db, s2.relativePath)).reduce((sum, s2) => sum + s2.loc, 0),
201
- cycles: cycleResult.length,
202
- similarPairs: trueSimilarCount,
203
- extractionCandidates: extractResult.length,
204
- wrappers: wrapperResult.length,
205
- passthroughs: passthroughResult.length,
206
- staleTypes: trueStaleCount,
207
- driftedFiles: trueDriftCount,
208
- complexityHotspotCount: complexResult.length
209
- },
210
- actions,
211
- topComplexity: complexResult.slice(0, 5).map((r) => ({
212
- symbol: r.shortName,
213
- score: r.score
214
- }))
215
- };
216
- }
217
-
218
- export {
219
- health
220
- };
221
- //# sourceMappingURL=chunk-334PCFO3.js.map
@@ -1,61 +0,0 @@
1
- import {
2
- buildFileDepGraph
3
- } from "./chunk-FMAYH7GS.js";
4
-
5
- // src/queries/cycles.ts
6
- function cycles(db, opts = {}) {
7
- const { scope, maxDepth = 10 } = opts;
8
- const graph = buildFileDepGraph(db, scope);
9
- const allCycles = [];
10
- const visited = /* @__PURE__ */ new Set();
11
- const inStack = /* @__PURE__ */ new Set();
12
- const stack = [];
13
- function dfs(node, depth) {
14
- if (depth > maxDepth) return;
15
- if (inStack.has(node)) {
16
- const cycleStart = stack.indexOf(node);
17
- if (cycleStart !== -1) {
18
- const cyclePath = stack.slice(cycleStart).concat(node);
19
- const minIdx = cyclePath.indexOf(
20
- cyclePath.reduce((a, b) => a < b ? a : b)
21
- );
22
- const normalized = [
23
- ...cyclePath.slice(minIdx, -1),
24
- ...cyclePath.slice(0, minIdx),
25
- cyclePath[minIdx]
26
- ];
27
- const key = normalized.join(" -> ");
28
- if (!seenCycles.has(key)) {
29
- seenCycles.add(key);
30
- allCycles.push({ path: normalized });
31
- }
32
- }
33
- return;
34
- }
35
- if (visited.has(node)) return;
36
- visited.add(node);
37
- inStack.add(node);
38
- stack.push(node);
39
- const neighbors = graph.get(node);
40
- if (neighbors) {
41
- for (const neighbor of neighbors) {
42
- dfs(neighbor, depth + 1);
43
- }
44
- }
45
- stack.pop();
46
- inStack.delete(node);
47
- }
48
- const seenCycles = /* @__PURE__ */ new Set();
49
- for (const node of graph.keys()) {
50
- if (!visited.has(node)) {
51
- dfs(node, 0);
52
- }
53
- }
54
- allCycles.sort((a, b) => a.path.length - b.path.length);
55
- return allCycles;
56
- }
57
-
58
- export {
59
- cycles
60
- };
61
- //# sourceMappingURL=chunk-46ZTW4AI.js.map
@@ -1,10 +0,0 @@
1
- // src/queries/clean-signature.ts
2
- function cleanSignature(sig) {
3
- if (!sig || !sig.trim()) return null;
4
- return sig.replace(/^```\w*\s*/, "").replace(/\s*```$/, "").replace(/^\(method\)\s*/, "").replace(/^\(property\)\s*/, "").replace(/^\(function\)\s*/, "").replace(/^\(class\)\s*/, "").replace(/^\(interface\)\s*/, "").replace(/^\(enum\)\s*/, "").replace(/^\(type alias\)\s*/, "").replace(/^\(const\)\s*/, "").replace(/^\(var\)\s*/, "").trim() || null;
5
- }
6
-
7
- export {
8
- cleanSignature
9
- };
10
- //# sourceMappingURL=chunk-4TYLS5XX.js.map
@@ -1,124 +0,0 @@
1
- import {
2
- buildFileDepGraph,
3
- findFirstSymbolMatch,
4
- resolveIndexedFile
5
- } from "./chunk-FMAYH7GS.js";
6
- import {
7
- shortenSymbol
8
- } from "./chunk-YMSJCSRG.js";
9
-
10
- // src/queries/fan.ts
11
- function fanIn(db, symbolPattern) {
12
- const match = findFirstSymbolMatch(db, symbolPattern);
13
- if (!match) {
14
- return [];
15
- }
16
- const row = db.get(
17
- `SELECT COUNT(DISTINCT c.document_id) AS file_count
18
- FROM mentions m
19
- JOIN chunks c ON m.chunk_id = c.id
20
- WHERE m.symbol_id = ?
21
- AND m.role != 1`,
22
- match.symbolId
23
- );
24
- return [{
25
- name: shortenSymbol(match.symbol),
26
- count: row?.file_count ?? 0
27
- }];
28
- }
29
- function fanOut(db, filePattern) {
30
- const resolvedFile = resolveIndexedFile(db, filePattern);
31
- if (!resolvedFile) {
32
- return [];
33
- }
34
- const rows = db.all(
35
- `SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
36
- FROM mentions m
37
- JOIN chunks c ON m.chunk_id = c.id
38
- JOIN documents d ON c.document_id = d.id
39
- JOIN global_symbols gs ON m.symbol_id = gs.id
40
- JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
41
- JOIN documents def_d ON der.document_id = def_d.id
42
- WHERE d.relative_path = ?
43
- AND m.role != 1
44
- AND def_d.id != d.id
45
- GROUP BY d.id
46
- ORDER BY symbol_count DESC`,
47
- resolvedFile
48
- );
49
- const indexedResults = rows.filter((r) => !db.isIgnored(r.relative_path)).map((r) => ({
50
- name: r.relative_path,
51
- count: r.symbol_count
52
- }));
53
- if (indexedResults.length > 0) {
54
- return indexedResults;
55
- }
56
- const graph = buildFileDepGraph(db);
57
- const deps = graph.get(resolvedFile);
58
- if (!deps || deps.size === 0) {
59
- return [];
60
- }
61
- return [{
62
- name: resolvedFile,
63
- count: deps.size
64
- }];
65
- }
66
- function topFanIn(db, opts = {}) {
67
- const { limit = 30, scope } = opts;
68
- const scopeFilter = scope ? `AND def_d.relative_path LIKE '%${scope}%'` : "";
69
- const rows = db.all(
70
- `SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
71
- FROM mentions m
72
- JOIN chunks c ON m.chunk_id = c.id
73
- JOIN global_symbols gs ON m.symbol_id = gs.id
74
- JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
75
- JOIN documents def_d ON der.document_id = def_d.id
76
- WHERE m.role != 1
77
- ${db.pathExclusionsFor("def_d")}
78
- ${db.symbolNoiseFor("gs")}
79
- ${scopeFilter}
80
- GROUP BY gs.id
81
- HAVING file_count > 1
82
- ORDER BY file_count DESC
83
- LIMIT ?`,
84
- limit
85
- );
86
- return rows.map((r) => ({
87
- name: shortenSymbol(r.symbol),
88
- count: r.file_count
89
- }));
90
- }
91
- function topFanOut(db, opts = {}) {
92
- const { limit = 30, scope } = opts;
93
- const scopeFilter = scope ? `AND d.relative_path LIKE '%${scope}%'` : "";
94
- const rows = db.all(
95
- `SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
96
- FROM mentions m
97
- JOIN chunks c ON m.chunk_id = c.id
98
- JOIN documents d ON c.document_id = d.id
99
- JOIN global_symbols gs ON m.symbol_id = gs.id
100
- JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
101
- JOIN documents def_d ON der.document_id = def_d.id
102
- WHERE m.role != 1
103
- AND def_d.id != d.id
104
- ${db.pathExclusionsFor("d")}
105
- ${db.symbolNoiseFor("gs")}
106
- ${scopeFilter}
107
- GROUP BY d.id
108
- ORDER BY symbol_count DESC
109
- LIMIT ?`,
110
- limit
111
- );
112
- return rows.filter((r) => !db.isIgnored(r.relative_path)).map((r) => ({
113
- name: r.relative_path,
114
- count: r.symbol_count
115
- }));
116
- }
117
-
118
- export {
119
- fanIn,
120
- fanOut,
121
- topFanIn,
122
- topFanOut
123
- };
124
- //# sourceMappingURL=chunk-4YN3PE57.js.map
@@ -1,101 +0,0 @@
1
- import {
2
- getCalleeRowsForSymbol,
3
- getScopedDefinitions
4
- } from "./chunk-FMAYH7GS.js";
5
- import {
6
- isFunctionLikeSymbol,
7
- shortenSymbol
8
- } from "./chunk-YMSJCSRG.js";
9
-
10
- // src/queries/extract-candidates.ts
11
- function extractCandidates(db, opts = {}) {
12
- const { scope, minLoc = 10, minCallees = 6, limit = 20 } = opts;
13
- const symbols = getScopedDefinitions(db, scope).filter((definition) => definitionLoc(definition) >= minLoc && isFunctionLikeSymbol(definition.symbol)).sort((left, right) => definitionLoc(right) - definitionLoc(left));
14
- const results = [];
15
- for (const sym of symbols) {
16
- if (db.isIgnored(sym.relativePath)) continue;
17
- const basename = sym.relativePath.split("/").pop() ?? "";
18
- if (basename.includes("types")) continue;
19
- const calleeChunks = getCalleeRowsForSymbol(db, sym);
20
- const calleeSet = new Set(calleeChunks.map((c) => c.symbol));
21
- if (calleeSet.size < minCallees) continue;
22
- const cooccurrence = /* @__PURE__ */ new Map();
23
- for (const callee of calleeSet) {
24
- cooccurrence.set(callee, /* @__PURE__ */ new Set());
25
- }
26
- const chunkToCallees = /* @__PURE__ */ new Map();
27
- for (const cc of calleeChunks) {
28
- if (!chunkToCallees.has(cc.chunkId)) chunkToCallees.set(cc.chunkId, /* @__PURE__ */ new Set());
29
- chunkToCallees.get(cc.chunkId).add(cc.symbol);
30
- }
31
- for (const callees of chunkToCallees.values()) {
32
- const arr = [...callees];
33
- for (let i = 0; i < arr.length; i++) {
34
- for (let j = i + 1; j < arr.length; j++) {
35
- cooccurrence.get(arr[i]).add(arr[j]);
36
- cooccurrence.get(arr[j]).add(arr[i]);
37
- }
38
- }
39
- }
40
- const visited = /* @__PURE__ */ new Set();
41
- const clusters = [];
42
- for (const callee of calleeSet) {
43
- if (visited.has(callee)) continue;
44
- const cluster = /* @__PURE__ */ new Set();
45
- const queue = [callee];
46
- while (queue.length > 0) {
47
- const current = queue.pop();
48
- if (visited.has(current)) continue;
49
- visited.add(current);
50
- cluster.add(current);
51
- for (const neighbor of cooccurrence.get(current) ?? []) {
52
- if (!visited.has(neighbor)) queue.push(neighbor);
53
- }
54
- }
55
- clusters.push(cluster);
56
- }
57
- if (clusters.length < 2) continue;
58
- const scoredClusters = clusters.filter((c) => c.size >= 2).map((cluster) => {
59
- const otherCallees = /* @__PURE__ */ new Set();
60
- for (const c of clusters) {
61
- if (c !== cluster) {
62
- for (const s of c) otherCallees.add(s);
63
- }
64
- }
65
- let crossEdges = 0;
66
- for (const callee of cluster) {
67
- for (const neighbor of cooccurrence.get(callee) ?? []) {
68
- if (otherCallees.has(neighbor)) crossEdges++;
69
- }
70
- }
71
- const maxCrossEdges = cluster.size * otherCallees.size;
72
- const isolation = maxCrossEdges > 0 ? 1 - crossEdges / maxCrossEdges : 1;
73
- return {
74
- callees: [...cluster].map(shortenSymbol),
75
- isolation
76
- };
77
- }).filter((c) => c.isolation > 0.5).sort((a, b) => b.isolation - a.isolation);
78
- if (scoredClusters.length > 0) {
79
- results.push({
80
- symbol: sym.symbol,
81
- shortName: shortenSymbol(sym.symbol),
82
- relativePath: sym.relativePath,
83
- startLine: sym.startLine,
84
- endLine: sym.endLine,
85
- loc: definitionLoc(sym),
86
- totalCallees: calleeSet.size,
87
- clusters: scoredClusters
88
- });
89
- }
90
- }
91
- results.sort((a, b) => b.clusters.length - a.clusters.length || b.loc - a.loc);
92
- return results.slice(0, limit);
93
- }
94
- function definitionLoc(definition) {
95
- return definition.endLine - definition.startLine + 1;
96
- }
97
-
98
- export {
99
- extractCandidates
100
- };
101
- //# sourceMappingURL=chunk-5YB6UXQ3.js.map
@@ -1,44 +0,0 @@
1
- import {
2
- buildFileDepGraph
3
- } from "./chunk-FMAYH7GS.js";
4
-
5
- // src/queries/deep-chains.ts
6
- function deepChains(db, opts = {}) {
7
- const { limit = 10, scope, minDepth = 3 } = opts;
8
- const graph = buildFileDepGraph(db, scope);
9
- const results = [];
10
- function dfs(node, path, visited) {
11
- const neighbors = graph.get(node);
12
- if (!neighbors || neighbors.size === 0) {
13
- if (path.length >= minDepth) {
14
- results.push({ chain: [...path], depth: path.length });
15
- }
16
- return;
17
- }
18
- let extended = false;
19
- for (const next of neighbors) {
20
- if (visited.has(next)) continue;
21
- visited.add(next);
22
- path.push(next);
23
- dfs(next, path, visited);
24
- path.pop();
25
- visited.delete(next);
26
- extended = true;
27
- }
28
- if (!extended && path.length >= minDepth) {
29
- results.push({ chain: [...path], depth: path.length });
30
- }
31
- }
32
- for (const startNode of graph.keys()) {
33
- const visited = /* @__PURE__ */ new Set([startNode]);
34
- dfs(startNode, [startNode], visited);
35
- if (results.length > limit * 10) break;
36
- }
37
- results.sort((a, b) => b.depth - a.depth);
38
- return results.slice(0, limit);
39
- }
40
-
41
- export {
42
- deepChains
43
- };
44
- //# sourceMappingURL=chunk-6PVHJ332.js.map
@@ -1,24 +0,0 @@
1
- // src/queries/stats.ts
2
- function stats(db) {
3
- const documents = db.get("SELECT COUNT(*) as c FROM documents").c;
4
- const symbols = db.get("SELECT COUNT(*) as c FROM global_symbols").c;
5
- const definitions = db.get(
6
- "SELECT COUNT(*) as c FROM mentions WHERE role = 1"
7
- ).c;
8
- const references = db.get(
9
- "SELECT COUNT(*) as c FROM mentions WHERE role != 1"
10
- ).c;
11
- return {
12
- documents,
13
- symbols,
14
- definitions,
15
- references,
16
- indexSizeBytes: db.sizeBytes(),
17
- lastBuilt: db.lastModified()
18
- };
19
- }
20
-
21
- export {
22
- stats
23
- };
24
- //# sourceMappingURL=chunk-74RFWB5T.js.map