scip-query 0.1.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 (330) hide show
  1. package/IMPROVEMENTS.md +143 -0
  2. package/PLAN.md +320 -0
  3. package/README.md +1213 -0
  4. package/dist/chunk-2QZ23IBN.js +55 -0
  5. package/dist/chunk-2QZ23IBN.js.map +1 -0
  6. package/dist/chunk-36OMT7ZJ.js +144 -0
  7. package/dist/chunk-36OMT7ZJ.js.map +1 -0
  8. package/dist/chunk-3E2X7RIE.js +101 -0
  9. package/dist/chunk-3E2X7RIE.js.map +1 -0
  10. package/dist/chunk-3UOUTZQT.js +45 -0
  11. package/dist/chunk-3UOUTZQT.js.map +1 -0
  12. package/dist/chunk-3ZZJVBIO.js +88 -0
  13. package/dist/chunk-3ZZJVBIO.js.map +1 -0
  14. package/dist/chunk-4TYLS5XX.js +10 -0
  15. package/dist/chunk-4TYLS5XX.js.map +1 -0
  16. package/dist/chunk-5FGUEU7N.js +101 -0
  17. package/dist/chunk-5FGUEU7N.js.map +1 -0
  18. package/dist/chunk-5WTJAXY2.js +61 -0
  19. package/dist/chunk-5WTJAXY2.js.map +1 -0
  20. package/dist/chunk-6NBLIDF4.js +24 -0
  21. package/dist/chunk-6NBLIDF4.js.map +1 -0
  22. package/dist/chunk-6SXADWLW.js +43 -0
  23. package/dist/chunk-6SXADWLW.js.map +1 -0
  24. package/dist/chunk-6VJ6Q7IE.js +65 -0
  25. package/dist/chunk-6VJ6Q7IE.js.map +1 -0
  26. package/dist/chunk-7OZPA5OO.js +258 -0
  27. package/dist/chunk-7OZPA5OO.js.map +1 -0
  28. package/dist/chunk-BEPIEVLR.js +76 -0
  29. package/dist/chunk-BEPIEVLR.js.map +1 -0
  30. package/dist/chunk-BFSCMC22.js +42 -0
  31. package/dist/chunk-BFSCMC22.js.map +1 -0
  32. package/dist/chunk-BP2ATLK2.js +110 -0
  33. package/dist/chunk-BP2ATLK2.js.map +1 -0
  34. package/dist/chunk-CM454WL3.js +114 -0
  35. package/dist/chunk-CM454WL3.js.map +1 -0
  36. package/dist/chunk-DCKMSTJ4.js +74 -0
  37. package/dist/chunk-DCKMSTJ4.js.map +1 -0
  38. package/dist/chunk-DEZKCZXD.js +40 -0
  39. package/dist/chunk-DEZKCZXD.js.map +1 -0
  40. package/dist/chunk-DVWGWHFW.js +99 -0
  41. package/dist/chunk-DVWGWHFW.js.map +1 -0
  42. package/dist/chunk-EMDQWNYR.js +102 -0
  43. package/dist/chunk-EMDQWNYR.js.map +1 -0
  44. package/dist/chunk-FFSWWE5O.js +33 -0
  45. package/dist/chunk-FFSWWE5O.js.map +1 -0
  46. package/dist/chunk-FGXRVW7G.js +73 -0
  47. package/dist/chunk-FGXRVW7G.js.map +1 -0
  48. package/dist/chunk-FUHJCHS4.js +158 -0
  49. package/dist/chunk-FUHJCHS4.js.map +1 -0
  50. package/dist/chunk-GJFURBEW.js +64 -0
  51. package/dist/chunk-GJFURBEW.js.map +1 -0
  52. package/dist/chunk-GTILYBH6.js +102 -0
  53. package/dist/chunk-GTILYBH6.js.map +1 -0
  54. package/dist/chunk-JJP7KQND.js +1 -0
  55. package/dist/chunk-JJP7KQND.js.map +1 -0
  56. package/dist/chunk-JKP5GH6T.js +213 -0
  57. package/dist/chunk-JKP5GH6T.js.map +1 -0
  58. package/dist/chunk-KCBMVQL5.js +38 -0
  59. package/dist/chunk-KCBMVQL5.js.map +1 -0
  60. package/dist/chunk-KVSW5KYP.js +78 -0
  61. package/dist/chunk-KVSW5KYP.js.map +1 -0
  62. package/dist/chunk-LAWMH22O.js +172 -0
  63. package/dist/chunk-LAWMH22O.js.map +1 -0
  64. package/dist/chunk-LB7OS35Q.js +72 -0
  65. package/dist/chunk-LB7OS35Q.js.map +1 -0
  66. package/dist/chunk-LUSIFBXO.js +57 -0
  67. package/dist/chunk-LUSIFBXO.js.map +1 -0
  68. package/dist/chunk-MBVNHJVN.js +44 -0
  69. package/dist/chunk-MBVNHJVN.js.map +1 -0
  70. package/dist/chunk-MGNMHKX3.js +15 -0
  71. package/dist/chunk-MGNMHKX3.js.map +1 -0
  72. package/dist/chunk-N5KEREIA.js +41 -0
  73. package/dist/chunk-N5KEREIA.js.map +1 -0
  74. package/dist/chunk-NDSQYIWT.js +71 -0
  75. package/dist/chunk-NDSQYIWT.js.map +1 -0
  76. package/dist/chunk-NUZ4OMU3.js +28 -0
  77. package/dist/chunk-NUZ4OMU3.js.map +1 -0
  78. package/dist/chunk-QOV2R2WT.js +170 -0
  79. package/dist/chunk-QOV2R2WT.js.map +1 -0
  80. package/dist/chunk-SEFSL2GF.js +78 -0
  81. package/dist/chunk-SEFSL2GF.js.map +1 -0
  82. package/dist/chunk-T6ARFSBZ.js +103 -0
  83. package/dist/chunk-T6ARFSBZ.js.map +1 -0
  84. package/dist/chunk-TBP6BICL.js +46 -0
  85. package/dist/chunk-TBP6BICL.js.map +1 -0
  86. package/dist/chunk-TDNNOR6D.js +97 -0
  87. package/dist/chunk-TDNNOR6D.js.map +1 -0
  88. package/dist/chunk-TSPZOMHC.js +195 -0
  89. package/dist/chunk-TSPZOMHC.js.map +1 -0
  90. package/dist/chunk-UNTPVD36.js +55 -0
  91. package/dist/chunk-UNTPVD36.js.map +1 -0
  92. package/dist/chunk-VRUJH4BO.js +88 -0
  93. package/dist/chunk-VRUJH4BO.js.map +1 -0
  94. package/dist/chunk-VZ7AMAFL.js +76 -0
  95. package/dist/chunk-VZ7AMAFL.js.map +1 -0
  96. package/dist/chunk-XFXDXEUN.js +24 -0
  97. package/dist/chunk-XFXDXEUN.js.map +1 -0
  98. package/dist/chunk-YZAA4LYG.js +169 -0
  99. package/dist/chunk-YZAA4LYG.js.map +1 -0
  100. package/dist/chunk-Z73NYSBZ.js +92 -0
  101. package/dist/chunk-Z73NYSBZ.js.map +1 -0
  102. package/dist/chunk-ZJRYBOEE.js +125 -0
  103. package/dist/chunk-ZJRYBOEE.js.map +1 -0
  104. package/dist/cli.js +5798 -0
  105. package/dist/cli.js.map +1 -0
  106. package/dist/db-BxaevAyc.d.ts +683 -0
  107. package/dist/index.d.ts +254 -0
  108. package/dist/index.js +1271 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/postinstall.js +167 -0
  111. package/dist/postinstall.js.map +1 -0
  112. package/dist/queries/affected.d.ts +14 -0
  113. package/dist/queries/affected.js +9 -0
  114. package/dist/queries/affected.js.map +1 -0
  115. package/dist/queries/bottlenecks.d.ts +18 -0
  116. package/dist/queries/bottlenecks.js +8 -0
  117. package/dist/queries/bottlenecks.js.map +1 -0
  118. package/dist/queries/by-kind.d.ts +20 -0
  119. package/dist/queries/by-kind.js +10 -0
  120. package/dist/queries/by-kind.js.map +1 -0
  121. package/dist/queries/call-graph.d.ts +13 -0
  122. package/dist/queries/call-graph.js +9 -0
  123. package/dist/queries/call-graph.js.map +1 -0
  124. package/dist/queries/change-surface.d.ts +10 -0
  125. package/dist/queries/change-surface.js +9 -0
  126. package/dist/queries/change-surface.js.map +1 -0
  127. package/dist/queries/clean-signature.d.ts +9 -0
  128. package/dist/queries/clean-signature.js +7 -0
  129. package/dist/queries/clean-signature.js.map +1 -0
  130. package/dist/queries/code.d.ts +17 -0
  131. package/dist/queries/code.js +9 -0
  132. package/dist/queries/code.js.map +1 -0
  133. package/dist/queries/complexity-hotspots.d.ts +19 -0
  134. package/dist/queries/complexity-hotspots.js +9 -0
  135. package/dist/queries/complexity-hotspots.js.map +1 -0
  136. package/dist/queries/complexity.d.ts +13 -0
  137. package/dist/queries/complexity.js +9 -0
  138. package/dist/queries/complexity.js.map +1 -0
  139. package/dist/queries/convergence.d.ts +11 -0
  140. package/dist/queries/convergence.js +9 -0
  141. package/dist/queries/convergence.js.map +1 -0
  142. package/dist/queries/coupling.d.ts +17 -0
  143. package/dist/queries/coupling.js +9 -0
  144. package/dist/queries/coupling.js.map +1 -0
  145. package/dist/queries/cycles.d.ts +16 -0
  146. package/dist/queries/cycles.js +8 -0
  147. package/dist/queries/cycles.js.map +1 -0
  148. package/dist/queries/dataflow.d.ts +19 -0
  149. package/dist/queries/dataflow.js +9 -0
  150. package/dist/queries/dataflow.js.map +1 -0
  151. package/dist/queries/dead.d.ts +10 -0
  152. package/dist/queries/dead.js +9 -0
  153. package/dist/queries/dead.js.map +1 -0
  154. package/dist/queries/deep-chains.d.ts +16 -0
  155. package/dist/queries/deep-chains.js +8 -0
  156. package/dist/queries/deep-chains.js.map +1 -0
  157. package/dist/queries/deps.d.ts +9 -0
  158. package/dist/queries/deps.js +9 -0
  159. package/dist/queries/deps.js.map +1 -0
  160. package/dist/queries/diff-impact.d.ts +13 -0
  161. package/dist/queries/diff-impact.js +9 -0
  162. package/dist/queries/diff-impact.js.map +1 -0
  163. package/dist/queries/doc-coverage.d.ts +14 -0
  164. package/dist/queries/doc-coverage.js +8 -0
  165. package/dist/queries/doc-coverage.js.map +1 -0
  166. package/dist/queries/drift.d.ts +25 -0
  167. package/dist/queries/drift.js +8 -0
  168. package/dist/queries/drift.js.map +1 -0
  169. package/dist/queries/extract-candidates.d.ts +25 -0
  170. package/dist/queries/extract-candidates.js +9 -0
  171. package/dist/queries/extract-candidates.js.map +1 -0
  172. package/dist/queries/fan.d.ts +29 -0
  173. package/dist/queries/fan.js +14 -0
  174. package/dist/queries/fan.js.map +1 -0
  175. package/dist/queries/files.d.ts +6 -0
  176. package/dist/queries/files.js +7 -0
  177. package/dist/queries/files.js.map +1 -0
  178. package/dist/queries/health.d.ts +18 -0
  179. package/dist/queries/health.js +21 -0
  180. package/dist/queries/health.js.map +1 -0
  181. package/dist/queries/hierarchy.d.ts +13 -0
  182. package/dist/queries/hierarchy.js +8 -0
  183. package/dist/queries/hierarchy.js.map +1 -0
  184. package/dist/queries/hotspots.d.ts +13 -0
  185. package/dist/queries/hotspots.js +8 -0
  186. package/dist/queries/hotspots.js.map +1 -0
  187. package/dist/queries/imports.d.ts +19 -0
  188. package/dist/queries/imports.js +12 -0
  189. package/dist/queries/imports.js.map +1 -0
  190. package/dist/queries/index.d.ts +47 -0
  191. package/dist/queries/index.js +207 -0
  192. package/dist/queries/index.js.map +1 -0
  193. package/dist/queries/isolated.d.ts +14 -0
  194. package/dist/queries/isolated.js +9 -0
  195. package/dist/queries/isolated.js.map +1 -0
  196. package/dist/queries/members.d.ts +10 -0
  197. package/dist/queries/members.js +8 -0
  198. package/dist/queries/members.js.map +1 -0
  199. package/dist/queries/methods.d.ts +6 -0
  200. package/dist/queries/methods.js +8 -0
  201. package/dist/queries/methods.js.map +1 -0
  202. package/dist/queries/outline.d.ts +10 -0
  203. package/dist/queries/outline.js +8 -0
  204. package/dist/queries/outline.js.map +1 -0
  205. package/dist/queries/passthrough-candidates.d.ts +18 -0
  206. package/dist/queries/passthrough-candidates.js +9 -0
  207. package/dist/queries/passthrough-candidates.js.map +1 -0
  208. package/dist/queries/redundant-reexports.d.ts +22 -0
  209. package/dist/queries/redundant-reexports.js +8 -0
  210. package/dist/queries/redundant-reexports.js.map +1 -0
  211. package/dist/queries/refs.d.ts +6 -0
  212. package/dist/queries/refs.js +7 -0
  213. package/dist/queries/refs.js.map +1 -0
  214. package/dist/queries/similar-chains.d.ts +29 -0
  215. package/dist/queries/similar-chains.js +8 -0
  216. package/dist/queries/similar-chains.js.map +1 -0
  217. package/dist/queries/similar-files.d.ts +19 -0
  218. package/dist/queries/similar-files.js +8 -0
  219. package/dist/queries/similar-files.js.map +1 -0
  220. package/dist/queries/similar-signatures.d.ts +21 -0
  221. package/dist/queries/similar-signatures.js +8 -0
  222. package/dist/queries/similar-signatures.js.map +1 -0
  223. package/dist/queries/similar.d.ts +34 -0
  224. package/dist/queries/similar.js +11 -0
  225. package/dist/queries/similar.js.map +1 -0
  226. package/dist/queries/slice.d.ts +21 -0
  227. package/dist/queries/slice.js +9 -0
  228. package/dist/queries/slice.js.map +1 -0
  229. package/dist/queries/stale-abstractions.d.ts +18 -0
  230. package/dist/queries/stale-abstractions.js +9 -0
  231. package/dist/queries/stale-abstractions.js.map +1 -0
  232. package/dist/queries/stats.d.ts +6 -0
  233. package/dist/queries/stats.js +7 -0
  234. package/dist/queries/stats.js.map +1 -0
  235. package/dist/queries/surface.d.ts +7 -0
  236. package/dist/queries/surface.js +8 -0
  237. package/dist/queries/surface.js.map +1 -0
  238. package/dist/queries/symbols.d.ts +6 -0
  239. package/dist/queries/symbols.js +9 -0
  240. package/dist/queries/symbols.js.map +1 -0
  241. package/dist/queries/system.d.ts +7 -0
  242. package/dist/queries/system.js +9 -0
  243. package/dist/queries/system.js.map +1 -0
  244. package/dist/queries/test-coverage.d.ts +22 -0
  245. package/dist/queries/test-coverage.js +11 -0
  246. package/dist/queries/test-coverage.js.map +1 -0
  247. package/dist/queries/trace.d.ts +6 -0
  248. package/dist/queries/trace.js +8 -0
  249. package/dist/queries/trace.js.map +1 -0
  250. package/dist/queries/wrapper-candidates.d.ts +17 -0
  251. package/dist/queries/wrapper-candidates.js +9 -0
  252. package/dist/queries/wrapper-candidates.js.map +1 -0
  253. package/dist/reindex-worker.js +368 -0
  254. package/dist/reindex-worker.js.map +1 -0
  255. package/docs/AGENT_GUIDE.md +359 -0
  256. package/package.json +70 -0
  257. package/reports/debloat/2026-04-10-scip-query-self-audit.md +161 -0
  258. package/skills/concrete-plan/SKILL.md +318 -0
  259. package/skills/scip-debloat/SKILL.md +413 -0
  260. package/skills/scip-explore/SKILL.md +235 -0
  261. package/skills/scip-verify/SKILL.md +323 -0
  262. package/src/cli.ts +1480 -0
  263. package/src/config.ts +117 -0
  264. package/src/db.ts +127 -0
  265. package/src/gitignore-filter.ts +143 -0
  266. package/src/index.ts +11 -0
  267. package/src/postinstall.ts +8 -0
  268. package/src/queries/affected.ts +86 -0
  269. package/src/queries/bottlenecks.ts +67 -0
  270. package/src/queries/by-kind.ts +204 -0
  271. package/src/queries/call-graph.ts +66 -0
  272. package/src/queries/change-surface.ts +110 -0
  273. package/src/queries/clean-signature.ts +22 -0
  274. package/src/queries/code.ts +101 -0
  275. package/src/queries/complexity-hotspots.ts +119 -0
  276. package/src/queries/complexity.ts +152 -0
  277. package/src/queries/convergence.ts +82 -0
  278. package/src/queries/coupling.ts +99 -0
  279. package/src/queries/cycles.ts +78 -0
  280. package/src/queries/dataflow.ts +128 -0
  281. package/src/queries/dead.ts +122 -0
  282. package/src/queries/deep-chains.ts +59 -0
  283. package/src/queries/deps.ts +46 -0
  284. package/src/queries/diff-impact.ts +204 -0
  285. package/src/queries/doc-coverage.ts +86 -0
  286. package/src/queries/drift.ts +224 -0
  287. package/src/queries/extract-candidates.ts +167 -0
  288. package/src/queries/fan.ts +148 -0
  289. package/src/queries/files.ts +16 -0
  290. package/src/queries/health.ts +324 -0
  291. package/src/queries/hierarchy.ts +49 -0
  292. package/src/queries/hotspots.ts +53 -0
  293. package/src/queries/imports.ts +95 -0
  294. package/src/queries/index.ts +45 -0
  295. package/src/queries/isolated.ts +67 -0
  296. package/src/queries/members.ts +54 -0
  297. package/src/queries/methods.ts +27 -0
  298. package/src/queries/outline.ts +52 -0
  299. package/src/queries/passthrough-candidates.ts +94 -0
  300. package/src/queries/redundant-reexports.ts +170 -0
  301. package/src/queries/refs.ts +27 -0
  302. package/src/queries/similar-chains.ts +314 -0
  303. package/src/queries/similar-files.ts +140 -0
  304. package/src/queries/similar-signatures.ts +151 -0
  305. package/src/queries/similar.ts +305 -0
  306. package/src/queries/slice.ts +154 -0
  307. package/src/queries/stale-abstractions.ts +82 -0
  308. package/src/queries/stats.ts +22 -0
  309. package/src/queries/surface.ts +34 -0
  310. package/src/queries/symbols.ts +39 -0
  311. package/src/queries/system.ts +86 -0
  312. package/src/queries/test-coverage.ts +106 -0
  313. package/src/queries/trace.ts +55 -0
  314. package/src/queries/wrapper-candidates.ts +112 -0
  315. package/src/query-support.ts +226 -0
  316. package/src/reindex/detect.ts +58 -0
  317. package/src/reindex/index.ts +153 -0
  318. package/src/reindex/indexers.ts +220 -0
  319. package/src/reindex/install.ts +125 -0
  320. package/src/reindex-worker.ts +35 -0
  321. package/src/setup.ts +202 -0
  322. package/src/symbol-parser.ts +278 -0
  323. package/src/types.ts +654 -0
  324. package/src/watch.ts +274 -0
  325. package/tests/gitignore-filter.test.ts +48 -0
  326. package/tests/queries.test.ts +300 -0
  327. package/tests/symbol-parser.test.ts +157 -0
  328. package/tsconfig.json +20 -0
  329. package/tsup.config.ts +40 -0
  330. package/vitest.config.ts +7 -0
@@ -0,0 +1,143 @@
1
+ # Improvement Opportunities
2
+
3
+ Self-audit of the scip-query codebase using its own analysis tools. Each finding includes the command that surfaced it, what it means, and what the fix looks like.
4
+
5
+ ---
6
+
7
+ ## 1. Replace 26 inline `symbolNoise` filters with `db.symbolNoise`
8
+
9
+ **Found by:** `grep` on `similar` output (78-80% callee overlap driven by shared SQL boilerplate)
10
+
11
+ **Problem:** The fragment `AND gs.symbol NOT LIKE '%typeLiteral%'` appears 26 times across 16 query files. The companion `AND gs.symbol NOT LIKE '%().(%'` appears in most of those too. `db.symbolNoise` was added as a reusable getter but never wired in.
12
+
13
+ **Files affected:**
14
+ - `bottlenecks.ts`, `by-kind.ts`, `call-graph.ts` (3 occurrences), `dead.ts`, `doc-coverage.ts` (3), `extract-candidates.ts` (2), `fan.ts`, `hotspots.ts`, `isolated.ts`, `members.ts`, `methods.ts`, `outline.ts`, `similar.ts` (4), `symbols.ts`, `system.ts`, `test-coverage.ts` (2), `trace.ts` (2)
15
+
16
+ **Fix:** Replace each inline `AND gs.symbol NOT LIKE '%typeLiteral%' AND gs.symbol NOT LIKE '%().(%'` with `AND ${db.symbolNoise}` (or a string interpolation of the getter). This cuts ~50 lines and ensures the noise filter is defined in one place — if we need to add a new pattern (e.g., filtering out synthetic generics), it changes in one spot.
17
+
18
+ ---
19
+
20
+ ## 2. Replace 32 inline `node_modules` exclusions with `db.pathExclusions`
21
+
22
+ **Found by:** `grep` on `similar-files` output (100% dep-profile similarity across all query modules)
23
+
24
+ **Problem:** `d.relative_path NOT LIKE 'node_modules/%'` appears 32 times across 18 files. Often paired with `.git/%` exclusions. The `db.pathExclusions` getter exists but isn't used.
25
+
26
+ **Files affected:** Every query file.
27
+
28
+ **Fix:** Same pattern as #1 — interpolate `${db.pathExclusions}` where applicable. Some queries use different table aliases (`def_d`, `ref_d`, `d1`, `d2`) so the getter may need a parameter for the alias, or we add alias-specific variants.
29
+
30
+ ---
31
+
32
+ ## 3. Extract shared `buildFileDepGraph()` helper
33
+
34
+ **Found by:** `similar-chains`, `cycles`, `deep-chains`, `similar-files` all contain identical graph-building SQL
35
+
36
+ **Problem:** Four query modules build the exact same file dependency graph:
37
+ - `cycles.ts:17-35`
38
+ - `deep-chains.ts:16-34`
39
+ - `similar-chains.ts:125-143`
40
+ - `similar-files.ts:66-84`
41
+
42
+ Each runs this ~18-line SQL query, builds a `Map<string, Set<string>>` adjacency list, and filters by gitignore. The code is identical except for the `scopeFilter` variable name.
43
+
44
+ **Fix:** Extract a shared `buildFileDepGraph(db, scope?)` helper that returns a `Map<string, Set<string>>`. All four modules import and call it. Saves ~54 lines and ensures graph-building logic stays consistent (e.g., if we later add `.d.ts` exclusions, it changes in one place).
45
+
46
+ ---
47
+
48
+ ## 4. Extract shared test-file pattern constants
49
+
50
+ **Found by:** `grep` on test-pattern strings
51
+
52
+ **Problem:** Test file path patterns (`%/__tests__/%`, `%.test.%`, `%.spec.%`, etc.) are defined:
53
+ - As an array in `test-coverage.ts:7-16`
54
+ - As individual SQL fragments in `dead.ts:34-37`
55
+ - As individual SQL fragments in `isolated.ts:35-37`
56
+
57
+ Three different representations of the same concept.
58
+
59
+ **Fix:** Export a `TEST_FILE_PATTERNS` constant (and a `testFileExclusionSql(alias)` helper that generates the SQL) from a shared location. `dead.ts`, `isolated.ts`, and `test-coverage.ts` all import it.
60
+
61
+ ---
62
+
63
+ ## 5. `queries/index.ts` barrel has score 136 bottleneck
64
+
65
+ **Found by:** `bottlenecks` command
66
+
67
+ **Problem:** The barrel re-export file (`queries/index.ts`) has fan-in=2, fan-out=68. Every query symbol is re-exported through it, so any consumer (`cli.ts`, `index.ts`) pulls the entire query surface. This is fine for a CLI tool, but if this package is used as a library, consumers pay for every query module even if they use one.
68
+
69
+ **Fix (for later):** Support tree-shaking by also exporting individual query modules:
70
+ ```ts
71
+ // Direct import for library consumers
72
+ import { hotspots } from 'scip-query/queries/hotspots';
73
+ ```
74
+ This needs `exports` map entries in `package.json`. Not urgent — the barrel is correct for CLI use.
75
+
76
+ ---
77
+
78
+ ## 6. `cli.ts` is the highest fan-out non-barrel file (23 external symbols)
79
+
80
+ **Found by:** `fan-out` command
81
+
82
+ **Problem:** `cli.ts` imports from 8 internal modules and references 23 external symbols. It's a 770+ line file that defines 34 commands inline. Each command's `.action()` handler does its own `openDb()` / `queries.X()` / `console.log()` / `db.close()` dance.
83
+
84
+ **Fix:** This isn't a bug — CLIs are inherently high fan-out. But if the file keeps growing, the repetitive `openDb` → query → format → `close` pattern could be extracted into a `runQuery(queryFn, formatter)` wrapper that handles the lifecycle. Each command would then be ~3 lines instead of ~15.
85
+
86
+ ---
87
+
88
+ ## 7. `similar-files` shows 100% similarity across all query modules
89
+
90
+ **Found by:** `similar-files --min-similarity 0.7`
91
+
92
+ **Problem:** Every query file depends on the same 3 files: `db.ts`, `types.ts`, `symbol-parser.ts`. This makes the file-level similarity metric saturate at 100%. It's not a code quality issue — it's a signal that the dependency profile is too uniform to distinguish files at this level.
93
+
94
+ **Implication for the tool itself:** The `similar-files` command should probably discount "universal" dependencies (files imported by >50% of the codebase) to surface more meaningful similarity. Universal deps like `types.ts` are infrastructure, not similarity signals.
95
+
96
+ ---
97
+
98
+ ## 8. Callee-set queries repeat identical SQL in `similar.ts` and `extract-candidates.ts`
99
+
100
+ **Found by:** `similar` command (78% overlap between those two files)
101
+
102
+ **Problem:** Both `similar.ts` and `extract-candidates.ts` run the same "find all callees of a symbol within its definition range" SQL query. `similar.ts` has it in `findCallees()` (line ~120) and `getAllCalleeFingerprints()` (line ~175). `extract-candidates.ts` has it inline (line ~55).
103
+
104
+ **Fix:** Extract a `getCalleesForSymbol(db, documentId, startLine, endLine, symbolId)` helper. Used by `similar.ts` (twice) and `extract-candidates.ts` (once). Also usable by `call-graph.ts` which runs a similar query.
105
+
106
+ ---
107
+
108
+ ## 9. Deep chains are all rooted at `queries/index.ts` → `cli.ts`
109
+
110
+ **Found by:** `deep-chains --min-depth 4`
111
+
112
+ **Problem:** Every deep chain starts at `index.ts` or `cli.ts` because they're the barrel/entry points. The chains themselves are only depth 4-5, which is healthy. No action needed — this confirms the architecture is flat.
113
+
114
+ **Assessment:** Not an issue. Healthy architecture signal.
115
+
116
+ ---
117
+
118
+ ## 10. No circular dependencies
119
+
120
+ **Found by:** `cycles` command
121
+
122
+ **Assessment:** Clean. No action needed.
123
+
124
+ ---
125
+
126
+ ## Summary
127
+
128
+ | # | Finding | Severity | Effort | Lines saved |
129
+ |---|---------|----------|--------|-------------|
130
+ | 1 | Inline `symbolNoise` filters (26x) | Medium | Low | ~50 |
131
+ | 2 | Inline `node_modules` exclusions (32x) | Medium | Low | ~30 |
132
+ | 3 | Duplicated graph-building SQL (4 files) | Medium | Low | ~54 |
133
+ | 4 | Duplicated test-file patterns (3 files) | Low | Low | ~15 |
134
+ | 5 | Barrel bottleneck (tree-shaking) | Low | Medium | 0 (structure) |
135
+ | 6 | CLI fan-out / repetitive handlers | Low | Medium | ~100 |
136
+ | 7 | `similar-files` universal dep discount | Low | Medium | 0 (algorithm) |
137
+ | 8 | Duplicated callee-set SQL | Medium | Low | ~30 |
138
+ | 9 | Deep chains rooted at entry points | None | — | — |
139
+ | 10 | No cycles | None | — | — |
140
+
141
+ **Quick wins (items 1-4, 8):** ~180 lines eliminated, 5 shared helpers, ~30 minutes of work. All low-risk mechanical extractions.
142
+
143
+ **Structural improvements (items 5-7):** Algorithm and architecture changes that improve the tool's own quality and the accuracy of its similarity detection. Medium effort, high value for the product.
package/PLAN.md ADDED
@@ -0,0 +1,320 @@
1
+ # Implementation Plan: Phase 2 Commands + Agent Documentation
2
+
3
+ This plan adds 10 new analysis commands and a comprehensive agent usage guide. Organized into 4 phases to keep diffs bounded and independently testable.
4
+
5
+ ---
6
+
7
+ ## Phase 1: Transitive Impact + Change Planning (3 commands)
8
+
9
+ These serve Use Case 1 — deep understanding for concrete planning.
10
+
11
+ ### 1.1 `affected <symbol>`
12
+
13
+ **Purpose:** Full transitive closure of symbols that could break if a given symbol changes. Walks rdeps recursively at the symbol level (not just file level like `rdeps`).
14
+
15
+ **Implementation:**
16
+ - New file: `src/queries/affected.ts`
17
+ - Algorithm: BFS from the target symbol through the mention graph. For each symbol that references the target, find symbols that reference *that* symbol, and so on. Track depth. Cap at configurable max depth (default 5) to avoid full-graph traversal on hub symbols.
18
+ - Reuse: `findFirstSymbolMatch()` from `query-support.ts` to resolve the target.
19
+ - SQL core: Recursive walk on `mentions` (role=0) → `defn_enclosing_ranges` → back to `mentions`. Each hop finds the enclosing symbol of each reference site, then finds references to *that* symbol.
20
+ - Output type: `AffectedResult` — array of `{ symbol, shortName, file, depth }` sorted by depth then file.
21
+ - CLI: `scip-query affected <symbol> [--max-depth N] [--scope path]`
22
+
23
+ **Value:** "If I change this function's signature, what's the full blast wave?" Direct rdeps are depth 1. Their consumers are depth 2. This shows the full picture.
24
+
25
+ ### 1.2 `change-surface <file>`
26
+
27
+ **Purpose:** Pre-change briefing: "I'm about to modify this file. What do I need to know?"
28
+
29
+ **Implementation:**
30
+ - New file: `src/queries/change-surface.ts`
31
+ - Composes existing queries internally — not a raw SQL query but an orchestrator:
32
+ 1. Call `symbols()` to get all symbols in the file
33
+ 2. For each symbol, call the refs logic to count external consumers
34
+ 3. Call `testCoverage()` to check which symbols are test-covered
35
+ 4. Call `fanIn()` to get reference counts
36
+ - Output type: `ChangeSurfaceResult` — per-symbol: `{ symbol, shortName, externalConsumers: number, testFiles: string[], riskLevel: 'low' | 'medium' | 'high' }` where risk = high if fan-in > 10 and no test coverage.
37
+ - CLI: `scip-query change-surface <file>`
38
+
39
+ **Value:** One command before modifying a file. Shows what's exported, who uses it, what's tested, and what's risky.
40
+
41
+ ### 1.3 `diff-impact`
42
+
43
+ **Purpose:** Given the current git diff, compute the affected symbol set.
44
+
45
+ **Implementation:**
46
+ - New file: `src/queries/diff-impact.ts`
47
+ - Algorithm:
48
+ 1. Run `git diff --name-only HEAD` (via `execFileSync`) to get changed files
49
+ 2. For each changed file, get all symbols defined in it via `symbols()` logic
50
+ 3. For each symbol, get its fan-in count and test coverage
51
+ 4. Aggregate: total changed symbols, total consumers affected, test coverage gaps
52
+ - Output type: `DiffImpactResult` — `{ changedFiles, changedSymbols[], affectedConsumers[], uncoveredSymbols[], summary }`
53
+ - CLI: `scip-query diff-impact [--base <ref>]` (default: diff against HEAD)
54
+ - Note: Needs git available. If not in a git repo, error gracefully.
55
+
56
+ **Value:** "You changed 3 files — here are the 47 symbols affected, the 12 files that consume them, and the 5 gaps in test coverage."
57
+
58
+ ### Phase 1 files to create:
59
+ - `src/queries/affected.ts`
60
+ - `src/queries/change-surface.ts`
61
+ - `src/queries/diff-impact.ts`
62
+ - Types added to `src/types.ts`
63
+ - Exports added to `src/queries/index.ts`
64
+ - CLI commands added to `src/cli.ts`
65
+
66
+ ### Phase 1 files to modify:
67
+ - `src/types.ts` — add `AffectedResult`, `ChangeSurfaceResult`, `DiffImpactResult`
68
+ - `src/queries/index.ts` — add exports
69
+ - `src/cli.ts` — add 3 commands
70
+
71
+ ---
72
+
73
+ ## Phase 2: De-bloating Commands (5 commands)
74
+
75
+ These serve Use Case 2 — keeping the codebase clean.
76
+
77
+ ### 2.1 `drift [module]`
78
+
79
+ **Purpose:** Detect pattern drift — files that don't match the typical dependency profile for their directory.
80
+
81
+ **Implementation:**
82
+ - New file: `src/queries/drift.ts`
83
+ - Algorithm:
84
+ 1. Build file dep profiles per directory (group files by their parent dir)
85
+ 2. For each directory with 3+ files, compute the "median" dependency set — deps that appear in >50% of files in that dir
86
+ 3. For each file, compute how much it deviates from the median: which expected deps are missing, which unexpected deps are present
87
+ 4. Score deviation as a percentage. Report files with highest deviation.
88
+ - Reuse: `buildFileDepGraph()` from `query-support.ts` for the dep edges.
89
+ - Output type: `DriftResult` — `{ file, directory, deviationPercent, missingExpectedDeps[], unexpectedDeps[] }`
90
+ - CLI: `scip-query drift [module] [--min-deviation N]` (default min-deviation: 30%)
91
+
92
+ **Value:** Finds the files that don't follow the conventions of their neighbors. If 8 of 10 services import a validator and 2 don't, those 2 are flagged.
93
+
94
+ ### 2.2 `wrapper-candidates`
95
+
96
+ **Purpose:** Find symbols that are only ever called through one intermediary — premature abstractions that add indirection without value.
97
+
98
+ **Implementation:**
99
+ - New file: `src/queries/wrapper-candidates.ts`
100
+ - Algorithm:
101
+ 1. Find all symbols with fan-in = 1 (exactly one caller)
102
+ 2. For each, check if that single caller has fan-in > 3 (is widely used)
103
+ 3. If so, the single-caller symbol is a wrapper candidate — it could be inlined into its caller
104
+ 4. Also check LOC: small wrappers (< 10 LOC) are the strongest candidates
105
+ - SQL: Subquery on `mentions` grouped by `symbol_id`, `HAVING COUNT(DISTINCT document_id) = 1`, then join to find the caller's fan-in.
106
+ - Output type: `WrapperCandidate` — `{ symbol, shortName, file, loc, singleCaller, callerFanIn }`
107
+ - CLI: `scip-query wrapper-candidates [--scope path] [--max-loc N]`
108
+
109
+ **Value:** "This function exists only to call another function. You can inline it." Catches over-engineering.
110
+
111
+ ### 2.3 `passthrough-candidates`
112
+
113
+ **Purpose:** Find functions that just forward to one other function without adding logic.
114
+
115
+ **Implementation:**
116
+ - New file: `src/queries/passthrough-candidates.ts`
117
+ - Algorithm:
118
+ 1. Find symbols with exactly 1 callee (they only call one external thing)
119
+ 2. Filter to small functions (< 15 LOC)
120
+ 3. These are likely passthroughs: `getUser(id) { return userRepo.findById(id); }`
121
+ - Reuse: `getCalleeRowsForSymbol()` from `query-support.ts` to count callees.
122
+ - Output type: `PassthroughCandidate` — `{ symbol, shortName, file, loc, forwardsTo, forwardsToFile }`
123
+ - CLI: `scip-query passthrough-candidates [--scope path] [--max-loc N]`
124
+
125
+ **Value:** Finds functions that are pure indirection. Either inline them or verify they exist for a reason (dependency inversion, testing boundary, etc.)
126
+
127
+ ### 2.4 `stale-abstractions`
128
+
129
+ **Purpose:** Find interfaces/base classes/generics with exactly 1 implementation or 1 caller.
130
+
131
+ **Implementation:**
132
+ - New file: `src/queries/stale-abstractions.ts`
133
+ - Algorithm:
134
+ 1. Find type-level symbols (using `#` in the SCIP symbol — indicates class/interface/type)
135
+ 2. For each, count cross-file references (fan-in)
136
+ 3. Symbols with fan-in = 1 are single-consumer abstractions
137
+ 4. Cross-reference with LOC: large single-consumer abstractions are the most wasteful
138
+ - SQL: Filter `gs.symbol LIKE '%#%'` (type-level), then count mentions with role=0 from different documents.
139
+ - Output type: `StaleAbstraction` — `{ symbol, shortName, file, loc, consumers: number, implementors: number }`
140
+ - CLI: `scip-query stale-abstractions [--scope path] [--min-loc N]`
141
+
142
+ **Value:** An interface with one implementation isn't an abstraction — it's indirection. A generic helper called from one place isn't reusable — it's premature.
143
+
144
+ ### 2.5 `complexity-hotspots`
145
+
146
+ **Purpose:** Composite complexity score per symbol combining LOC, fan-in, fan-out, and callee count.
147
+
148
+ **Implementation:**
149
+ - New file: `src/queries/complexity-hotspots.ts`
150
+ - Algorithm:
151
+ 1. For each non-trivial symbol (>= minLoc), compute:
152
+ - LOC (from defn_enclosing_ranges)
153
+ - Fan-in (count of distinct referencing documents)
154
+ - Fan-out (count of distinct referenced symbols in other files)
155
+ - Callee count (total callees within definition range)
156
+ 2. Score = `(LOC / 50) * (fanIn / 5) * (fanOut / 5)` (normalized so a 50-LOC function with 5 consumers and 5 callees scores ~1.0)
157
+ 3. Sort by score descending
158
+ - Reuse: Similar SQL patterns to `bottlenecks.ts` and `fan.ts`.
159
+ - Output type: `ComplexityHotspot` — `{ symbol, shortName, file, loc, fanIn, fanOut, calleeCount, score }`
160
+ - CLI: `scip-query complexity-hotspots [--scope path] [--min-loc N] [-n limit]`
161
+
162
+ **Value:** The symbols with the highest scores are the ones most likely to contain bugs, be hardest to modify, and benefit most from decomposition. Combines multiple signals into one prioritized view.
163
+
164
+ ### Phase 2 files to create:
165
+ - `src/queries/drift.ts`
166
+ - `src/queries/wrapper-candidates.ts`
167
+ - `src/queries/passthrough-candidates.ts`
168
+ - `src/queries/stale-abstractions.ts`
169
+ - `src/queries/complexity-hotspots.ts`
170
+
171
+ ### Phase 2 files to modify:
172
+ - `src/types.ts` — add 5 result types
173
+ - `src/queries/index.ts` — add 5 exports
174
+ - `src/cli.ts` — add 5 commands
175
+
176
+ ---
177
+
178
+ ## Phase 3: Composite Health Report (2 commands)
179
+
180
+ ### 3.1 `health`
181
+
182
+ **Purpose:** Single command that runs all de-bloat analyses and produces a prioritized action list.
183
+
184
+ **Implementation:**
185
+ - New file: `src/queries/health.ts`
186
+ - Algorithm: Run each analysis in sequence, aggregate results:
187
+ 1. `dead()` → count dead symbols, total recoverable LOC
188
+ 2. `isolated()` → count orphaned symbols
189
+ 3. `cycles()` → count circular deps
190
+ 4. `similarAll()` → count high-similarity pairs
191
+ 5. `extractCandidates()` → count extraction opportunities
192
+ 6. `wrapperCandidates()` → count wrapper symbols (new, from Phase 2)
193
+ 7. `passthroughCandidates()` → count passthroughs (new, from Phase 2)
194
+ 8. `staleAbstractions()` → count single-consumer types (new, from Phase 2)
195
+ 9. `drift()` → count drifted files (new, from Phase 2)
196
+ 10. `complexityHotspots()` → top 5 most complex symbols (new, from Phase 2)
197
+ - Output: Grouped sections with counts and top items. A "health score" (0-100) based on weighted findings. Concrete action items sorted by effort/impact.
198
+ - Output type: `HealthReport` — sections for each analysis, overall score, prioritized action list.
199
+ - CLI: `scip-query health [--scope path] [--json]` (JSON mode for programmatic consumption by agents)
200
+
201
+ **Value:** The difference between "powerful tool for experts" and "tool that actually gets used." One command, one report, one action list.
202
+
203
+ ### 3.2 `convergence <symbol1> <symbol2>`
204
+
205
+ **Purpose:** Given two similar symbols (flagged by `similar`), show what a consolidated version would look like.
206
+
207
+ **Implementation:**
208
+ - New file: `src/queries/convergence.ts`
209
+ - Algorithm:
210
+ 1. Get callee sets for both symbols (via `getCalleeRowsForSymbol()`)
211
+ 2. Compute shared callees (the body of the consolidated function)
212
+ 3. Compute unique-to-A and unique-to-B (the parameterization points)
213
+ 4. Report: "The consolidated function would call [shared callees]. A's unique behavior ([unique-to-A]) and B's unique behavior ([unique-to-B]) become parameters or strategy arguments."
214
+ 5. Also show the file locations and LOC of both symbols for context.
215
+ - Output type: `ConvergenceResult` — `{ symbolA, symbolB, sharedCallees[], uniqueToA[], uniqueToB[], consolidationStrategy }`
216
+ - CLI: `scip-query convergence <symbol1> <symbol2>`
217
+
218
+ **Value:** Turns a similarity finding into a concrete refactoring prescription. "These two are 75% similar" becomes "here's what the merged version looks like."
219
+
220
+ ### Phase 3 files to create:
221
+ - `src/queries/health.ts`
222
+ - `src/queries/convergence.ts`
223
+
224
+ ### Phase 3 files to modify:
225
+ - `src/types.ts` — add `HealthReport`, `ConvergenceResult`
226
+ - `src/queries/index.ts` — add 2 exports
227
+ - `src/cli.ts` — add 2 commands
228
+
229
+ ### Phase 3 depends on: Phase 2 (health report calls Phase 2 commands)
230
+
231
+ ---
232
+
233
+ ## Phase 4: Agent Usage Guide + Use Case Documentation
234
+
235
+ ### 4.1 `docs/AGENT_GUIDE.md`
236
+
237
+ Comprehensive guide for AI agents (and humans) on how to use scip-query for specific goals. Structured as goal-oriented workflows, not command reference (that's already in README.md).
238
+
239
+ **Sections:**
240
+
241
+ #### "I need to understand how a system works before making changes"
242
+ 1. Start with `system <module>` for the full map
243
+ 2. Pick the entry point and run `call-graph <symbol>` to see what it calls and who calls it
244
+ 3. Run `deps <file>` and `rdeps <file>` to map the file-level dependency boundary
245
+ 4. Run `surface <module>` to understand the true public API (not just what's exported)
246
+ 5. Run `trace <symbol>` for any specific symbol you need to understand
247
+ 6. Run `change-surface <file>` for a pre-change briefing on anything you're about to modify
248
+ 7. Run `diff-impact` after making changes to verify the blast radius
249
+
250
+ #### "I need to write a concrete implementation plan"
251
+ 1. Run `system <module>` to understand the target area
252
+ 2. Run `symbols <file>` on each file you'll modify to get line ranges and signatures
253
+ 3. Run `surface <module>` to identify the public contract you must preserve
254
+ 4. Run `refs <symbol>` for any symbol you plan to change, rename, or remove
255
+ 5. Run `affected <symbol>` for transitive impact on critical symbols
256
+ 6. Run `fan-in <symbol>` to quantify blast radius for each change
257
+ 7. Run `test-coverage <symbol>` to identify test gaps before you start
258
+
259
+ #### "I want to clean up and de-bloat a codebase"
260
+ 1. Run `health` for the full prioritized report (start here)
261
+ 2. Address dead code first: `dead --min-loc 10 --skip-barrels` → safe deletions
262
+ 3. Address isolated symbols: `isolated --min-loc 5` → completely safe deletions
263
+ 4. Break cycles: `cycles` → structural fixes
264
+ 5. Reduce duplication: `similar --min-similarity 0.6` → consolidation candidates
265
+ 6. For each similar pair, run `convergence <a> <b>` to get the refactoring prescription
266
+ 7. Find extraction opportunities: `extract-candidates --min-loc 20`
267
+ 8. Remove unnecessary indirection: `wrapper-candidates`, `passthrough-candidates`
268
+ 9. Prune premature abstractions: `stale-abstractions`
269
+ 10. Fix pattern drift: `drift` → bring outlier files into line with their neighbors
270
+
271
+ #### "I want to assess code quality and risk"
272
+ 1. Run `health` for the overall score
273
+ 2. Run `complexity-hotspots -n 20` for the riskiest symbols
274
+ 3. Run `bottlenecks -n 20` for coupling pressure points
275
+ 4. Run `deep-chains --min-depth 5` for architectural layering issues
276
+ 5. Run `test-coverage` for the coverage percentage
277
+ 6. Run `doc-coverage` for documentation gaps
278
+
279
+ #### "I want to understand the impact of a change I already made"
280
+ 1. Run `diff-impact` to see what your changes affect
281
+ 2. Run `affected <symbol>` for any symbol you modified
282
+ 3. Run `test-coverage <symbol>` for each affected symbol to find test gaps
283
+
284
+ #### Command cheat sheet
285
+ Quick reference table: "If you want to know X, run Y."
286
+
287
+ ### 4.2 Update `README.md`
288
+
289
+ - Add link to AGENT_GUIDE.md in the README
290
+ - Add a "Workflows" section that links to the guide
291
+ - Update command count and command table with new Phase 1-3 commands
292
+
293
+ ### Phase 4 files to create:
294
+ - `docs/AGENT_GUIDE.md`
295
+
296
+ ### Phase 4 files to modify:
297
+ - `README.md` — add workflows section, update command count
298
+
299
+ ---
300
+
301
+ ## Execution Order
302
+
303
+ ```
304
+ Phase 1 (impact + planning) → 3 new commands, ~400 LOC
305
+ Phase 2 (de-bloating) → 5 new commands, ~500 LOC
306
+ Phase 3 (health + convergence) → 2 new commands, ~300 LOC
307
+ Phase 4 (documentation) → 1 new doc, README update
308
+
309
+ Total: 10 new commands, ~1200 LOC of query logic, 1 agent guide
310
+ ```
311
+
312
+ Each phase is independently testable and committable. Phase 3 depends on Phase 2. Phase 4 depends on Phases 1-3 (references all commands). Phases 1 and 2 are independent and can be built in parallel.
313
+
314
+ ### Shared infrastructure all phases will use:
315
+ - `query-support.ts` — `buildFileDepGraph()`, `findFirstSymbolMatch()`, `getCalleeRowsForSymbol()`
316
+ - `db.ts` — `pathExclusionsFor()`, `symbolNoiseFor()`, `symbolNoise`, `localSymbolPredicate`
317
+ - `clean-signature.ts` — for any command that displays signatures
318
+ - `symbol-parser.ts` — `shortenSymbol()` for all display output
319
+
320
+ No new shared infrastructure needed. The existing helpers cover all planned commands.