codesift-mcp 0.13.1 → 0.15.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 (546) hide show
  1. package/README.md +5 -1
  2. package/dist/cli/commands-admin.d.ts +18 -0
  3. package/dist/cli/commands-admin.d.ts.map +1 -0
  4. package/dist/cli/commands-admin.js +187 -0
  5. package/dist/cli/commands-admin.js.map +1 -0
  6. package/dist/cli/commands-daemon.d.ts +42 -0
  7. package/dist/cli/commands-daemon.d.ts.map +1 -0
  8. package/dist/cli/commands-daemon.js +163 -0
  9. package/dist/cli/commands-daemon.js.map +1 -0
  10. package/dist/cli/commands-index.d.ts +12 -0
  11. package/dist/cli/commands-index.d.ts.map +1 -0
  12. package/dist/cli/commands-index.js +133 -0
  13. package/dist/cli/commands-index.js.map +1 -0
  14. package/dist/cli/commands-maintenance.d.ts +12 -0
  15. package/dist/cli/commands-maintenance.d.ts.map +1 -0
  16. package/dist/cli/commands-maintenance.js +409 -0
  17. package/dist/cli/commands-maintenance.js.map +1 -0
  18. package/dist/cli/commands-query.d.ts +21 -0
  19. package/dist/cli/commands-query.d.ts.map +1 -0
  20. package/dist/cli/commands-query.js +270 -0
  21. package/dist/cli/commands-query.js.map +1 -0
  22. package/dist/cli/commands.d.ts +2 -36
  23. package/dist/cli/commands.d.ts.map +1 -1
  24. package/dist/cli/commands.js +8 -854
  25. package/dist/cli/commands.js.map +1 -1
  26. package/dist/cli/embed-child.js +13 -2
  27. package/dist/cli/embed-child.js.map +1 -1
  28. package/dist/cli/hooks/pre-tool-use.d.ts +1 -0
  29. package/dist/cli/hooks/pre-tool-use.d.ts.map +1 -1
  30. package/dist/cli/hooks/pre-tool-use.js +11 -2
  31. package/dist/cli/hooks/pre-tool-use.js.map +1 -1
  32. package/dist/config.d.ts +13 -0
  33. package/dist/config.d.ts.map +1 -1
  34. package/dist/config.js +21 -0
  35. package/dist/config.js.map +1 -1
  36. package/dist/formatters-core.d.ts +7 -0
  37. package/dist/formatters-core.d.ts.map +1 -1
  38. package/dist/formatters-core.js +14 -3
  39. package/dist/formatters-core.js.map +1 -1
  40. package/dist/instructions.d.ts +1 -1
  41. package/dist/instructions.d.ts.map +1 -1
  42. package/dist/instructions.js +5 -2
  43. package/dist/instructions.js.map +1 -1
  44. package/dist/parser/extractors/hono-inline-analyzer.js +2 -2
  45. package/dist/parser/extractors/hono-inline-analyzer.js.map +1 -1
  46. package/dist/parser/extractors/php-class-metadata.d.ts +10 -0
  47. package/dist/parser/extractors/php-class-metadata.d.ts.map +1 -0
  48. package/dist/parser/extractors/php-class-metadata.js +65 -0
  49. package/dist/parser/extractors/php-class-metadata.js.map +1 -0
  50. package/dist/parser/extractors/php-doc.d.ts +13 -0
  51. package/dist/parser/extractors/php-doc.d.ts.map +1 -0
  52. package/dist/parser/extractors/php-doc.js +39 -0
  53. package/dist/parser/extractors/php-doc.js.map +1 -0
  54. package/dist/parser/extractors/php-node-metadata.d.ts +26 -0
  55. package/dist/parser/extractors/php-node-metadata.d.ts.map +1 -0
  56. package/dist/parser/extractors/php-node-metadata.js +132 -0
  57. package/dist/parser/extractors/php-node-metadata.js.map +1 -0
  58. package/dist/parser/extractors/php-symbol-builders.d.ts +13 -0
  59. package/dist/parser/extractors/php-symbol-builders.d.ts.map +1 -0
  60. package/dist/parser/extractors/php-symbol-builders.js +58 -0
  61. package/dist/parser/extractors/php-symbol-builders.js.map +1 -0
  62. package/dist/parser/extractors/php-walker.d.ts +4 -0
  63. package/dist/parser/extractors/php-walker.d.ts.map +1 -0
  64. package/dist/parser/extractors/php-walker.js +238 -0
  65. package/dist/parser/extractors/php-walker.js.map +1 -0
  66. package/dist/parser/extractors/php.d.ts +2 -33
  67. package/dist/parser/extractors/php.d.ts.map +1 -1
  68. package/dist/parser/extractors/php.js +2 -747
  69. package/dist/parser/extractors/php.js.map +1 -1
  70. package/dist/register-tool-groups/core/search.d.ts.map +1 -1
  71. package/dist/register-tool-groups/core/search.js +14 -0
  72. package/dist/register-tool-groups/core/search.js.map +1 -1
  73. package/dist/register-tool-groups/core/symbols.d.ts.map +1 -1
  74. package/dist/register-tool-groups/core/symbols.js +50 -5
  75. package/dist/register-tool-groups/core/symbols.js.map +1 -1
  76. package/dist/register-tool-loaders.d.ts +11 -11
  77. package/dist/register-tool-loaders.d.ts.map +1 -1
  78. package/dist/register-tools/runtime.d.ts +11 -0
  79. package/dist/register-tools/runtime.d.ts.map +1 -1
  80. package/dist/register-tools/runtime.js +40 -0
  81. package/dist/register-tools/runtime.js.map +1 -1
  82. package/dist/register-tools.d.ts.map +1 -1
  83. package/dist/register-tools.js +5 -1
  84. package/dist/register-tools.js.map +1 -1
  85. package/dist/retrieval/semantic-handlers.d.ts.map +1 -1
  86. package/dist/retrieval/semantic-handlers.js +10 -3
  87. package/dist/retrieval/semantic-handlers.js.map +1 -1
  88. package/dist/search/semantic.d.ts +2 -0
  89. package/dist/search/semantic.d.ts.map +1 -1
  90. package/dist/search/semantic.js +41 -9
  91. package/dist/search/semantic.js.map +1 -1
  92. package/dist/server.d.ts.map +1 -1
  93. package/dist/server.js +54 -2
  94. package/dist/server.js.map +1 -1
  95. package/dist/storage/_shared.d.ts +21 -0
  96. package/dist/storage/_shared.d.ts.map +1 -1
  97. package/dist/storage/_shared.js +36 -0
  98. package/dist/storage/_shared.js.map +1 -1
  99. package/dist/storage/chunk-store.d.ts +14 -2
  100. package/dist/storage/chunk-store.d.ts.map +1 -1
  101. package/dist/storage/chunk-store.js +214 -34
  102. package/dist/storage/chunk-store.js.map +1 -1
  103. package/dist/storage/embedding-store.d.ts +0 -12
  104. package/dist/storage/embedding-store.d.ts.map +1 -1
  105. package/dist/storage/embedding-store.js +69 -9
  106. package/dist/storage/embedding-store.js.map +1 -1
  107. package/dist/storage/index-cache.d.ts +12 -0
  108. package/dist/storage/index-cache.d.ts.map +1 -0
  109. package/dist/storage/index-cache.js +89 -0
  110. package/dist/storage/index-cache.js.map +1 -0
  111. package/dist/storage/index-footprint.d.ts +12 -0
  112. package/dist/storage/index-footprint.d.ts.map +1 -0
  113. package/dist/storage/index-footprint.js +41 -0
  114. package/dist/storage/index-footprint.js.map +1 -0
  115. package/dist/storage/index-json-mutations.d.ts +11 -0
  116. package/dist/storage/index-json-mutations.d.ts.map +1 -0
  117. package/dist/storage/index-json-mutations.js +93 -0
  118. package/dist/storage/index-json-mutations.js.map +1 -0
  119. package/dist/storage/index-migration.d.ts +22 -0
  120. package/dist/storage/index-migration.d.ts.map +1 -0
  121. package/dist/storage/index-migration.js +80 -0
  122. package/dist/storage/index-migration.js.map +1 -0
  123. package/dist/storage/index-store.d.ts +26 -55
  124. package/dist/storage/index-store.d.ts.map +1 -1
  125. package/dist/storage/index-store.js +82 -350
  126. package/dist/storage/index-store.js.map +1 -1
  127. package/dist/storage/index-version.d.ts +39 -0
  128. package/dist/storage/index-version.d.ts.map +1 -0
  129. package/dist/storage/index-version.js +87 -0
  130. package/dist/storage/index-version.js.map +1 -0
  131. package/dist/storage/registry.d.ts +9 -1
  132. package/dist/storage/registry.d.ts.map +1 -1
  133. package/dist/storage/registry.js +233 -9
  134. package/dist/storage/registry.js.map +1 -1
  135. package/dist/storage/shared-embedding-cache.d.ts +23 -3
  136. package/dist/storage/shared-embedding-cache.d.ts.map +1 -1
  137. package/dist/storage/shared-embedding-cache.js +300 -45
  138. package/dist/storage/shared-embedding-cache.js.map +1 -1
  139. package/dist/storage/sqlite/accessors.d.ts +34 -0
  140. package/dist/storage/sqlite/accessors.d.ts.map +1 -0
  141. package/dist/storage/sqlite/accessors.js +178 -0
  142. package/dist/storage/sqlite/accessors.js.map +1 -0
  143. package/dist/storage/sqlite/connection.d.ts +43 -0
  144. package/dist/storage/sqlite/connection.d.ts.map +1 -0
  145. package/dist/storage/sqlite/connection.js +241 -0
  146. package/dist/storage/sqlite/connection.js.map +1 -0
  147. package/dist/storage/sqlite/errors.d.ts +38 -0
  148. package/dist/storage/sqlite/errors.d.ts.map +1 -0
  149. package/dist/storage/sqlite/errors.js +150 -0
  150. package/dist/storage/sqlite/errors.js.map +1 -0
  151. package/dist/storage/sqlite/index-io.d.ts +49 -0
  152. package/dist/storage/sqlite/index-io.d.ts.map +1 -0
  153. package/dist/storage/sqlite/index-io.js +268 -0
  154. package/dist/storage/sqlite/index-io.js.map +1 -0
  155. package/dist/storage/sqlite/meta.d.ts +41 -0
  156. package/dist/storage/sqlite/meta.d.ts.map +1 -0
  157. package/dist/storage/sqlite/meta.js +28 -0
  158. package/dist/storage/sqlite/meta.js.map +1 -0
  159. package/dist/storage/sqlite/rows.d.ts +64 -0
  160. package/dist/storage/sqlite/rows.d.ts.map +1 -0
  161. package/dist/storage/sqlite/rows.js +186 -0
  162. package/dist/storage/sqlite/rows.js.map +1 -0
  163. package/dist/storage/sqlite/runtime.d.ts +6 -0
  164. package/dist/storage/sqlite/runtime.d.ts.map +1 -0
  165. package/dist/storage/sqlite/runtime.js +31 -0
  166. package/dist/storage/sqlite/runtime.js.map +1 -0
  167. package/dist/storage/sqlite/schema.d.ts +34 -0
  168. package/dist/storage/sqlite/schema.d.ts.map +1 -0
  169. package/dist/storage/sqlite/schema.js +98 -0
  170. package/dist/storage/sqlite/schema.js.map +1 -0
  171. package/dist/storage/sqlite-index-store.d.ts +40 -80
  172. package/dist/storage/sqlite-index-store.d.ts.map +1 -1
  173. package/dist/storage/sqlite-index-store.js +32 -577
  174. package/dist/storage/sqlite-index-store.js.map +1 -1
  175. package/dist/storage/telemetry/config.d.ts.map +1 -1
  176. package/dist/storage/telemetry/config.js +15 -3
  177. package/dist/storage/telemetry/config.js.map +1 -1
  178. package/dist/storage/telemetry/payload.d.ts.map +1 -1
  179. package/dist/storage/telemetry/payload.js +4 -1
  180. package/dist/storage/telemetry/payload.js.map +1 -1
  181. package/dist/storage/telemetry/retro-aggregator.d.ts +48 -0
  182. package/dist/storage/telemetry/retro-aggregator.d.ts.map +1 -0
  183. package/dist/storage/telemetry/retro-aggregator.js +221 -0
  184. package/dist/storage/telemetry/retro-aggregator.js.map +1 -0
  185. package/dist/storage/telemetry/sanitizer.d.ts +46 -0
  186. package/dist/storage/telemetry/sanitizer.d.ts.map +1 -1
  187. package/dist/storage/telemetry/sanitizer.js +25 -0
  188. package/dist/storage/telemetry/sanitizer.js.map +1 -1
  189. package/dist/storage/telemetry/uploader.d.ts +3 -1
  190. package/dist/storage/telemetry/uploader.d.ts.map +1 -1
  191. package/dist/storage/telemetry/uploader.js +161 -18
  192. package/dist/storage/telemetry/uploader.js.map +1 -1
  193. package/dist/storage/workspace-resolver.js +1 -1
  194. package/dist/storage/workspace-resolver.js.map +1 -1
  195. package/dist/tools/cross-repo-contract-adapters.d.ts +39 -0
  196. package/dist/tools/cross-repo-contract-adapters.d.ts.map +1 -0
  197. package/dist/tools/cross-repo-contract-adapters.js +70 -0
  198. package/dist/tools/cross-repo-contract-adapters.js.map +1 -0
  199. package/dist/tools/cross-repo-contract-group.d.ts +17 -0
  200. package/dist/tools/cross-repo-contract-group.d.ts.map +1 -0
  201. package/dist/tools/cross-repo-contract-group.js +89 -0
  202. package/dist/tools/cross-repo-contract-group.js.map +1 -0
  203. package/dist/tools/cross-repo-contract-matcher.d.ts +24 -0
  204. package/dist/tools/cross-repo-contract-matcher.d.ts.map +1 -0
  205. package/dist/tools/cross-repo-contract-matcher.js +134 -0
  206. package/dist/tools/cross-repo-contract-matcher.js.map +1 -0
  207. package/dist/tools/cross-repo-contract-resolver.d.ts +9 -0
  208. package/dist/tools/cross-repo-contract-resolver.d.ts.map +1 -0
  209. package/dist/tools/cross-repo-contract-resolver.js +86 -0
  210. package/dist/tools/cross-repo-contract-resolver.js.map +1 -0
  211. package/dist/tools/cross-repo-contract-tools.d.ts +12 -135
  212. package/dist/tools/cross-repo-contract-tools.d.ts.map +1 -1
  213. package/dist/tools/cross-repo-contract-tools.js +8 -589
  214. package/dist/tools/cross-repo-contract-tools.js.map +1 -1
  215. package/dist/tools/cross-repo-contract-types.d.ts +30 -0
  216. package/dist/tools/cross-repo-contract-types.d.ts.map +1 -0
  217. package/dist/tools/cross-repo-contract-types.js +3 -0
  218. package/dist/tools/cross-repo-contract-types.js.map +1 -0
  219. package/dist/tools/cross-repo-outbound-calls.d.ts +28 -0
  220. package/dist/tools/cross-repo-outbound-calls.d.ts.map +1 -0
  221. package/dist/tools/cross-repo-outbound-calls.js +347 -0
  222. package/dist/tools/cross-repo-outbound-calls.js.map +1 -0
  223. package/dist/tools/cross-repo-outbound-lexer/call-detectors.d.ts.map +1 -1
  224. package/dist/tools/cross-repo-outbound-lexer/call-detectors.js +2 -0
  225. package/dist/tools/cross-repo-outbound-lexer/call-detectors.js.map +1 -1
  226. package/dist/tools/cross-repo-outbound-lexer/types.d.ts +2 -0
  227. package/dist/tools/cross-repo-outbound-lexer/types.d.ts.map +1 -1
  228. package/dist/tools/index-tools/file-indexer.js +3 -3
  229. package/dist/tools/index-tools/file-indexer.js.map +1 -1
  230. package/dist/tools/index-tools/folder-indexer.d.ts.map +1 -1
  231. package/dist/tools/index-tools/folder-indexer.js +51 -3
  232. package/dist/tools/index-tools/folder-indexer.js.map +1 -1
  233. package/dist/tools/index-tools/parse.d.ts +12 -3
  234. package/dist/tools/index-tools/parse.d.ts.map +1 -1
  235. package/dist/tools/index-tools/parse.js +33 -8
  236. package/dist/tools/index-tools/parse.js.map +1 -1
  237. package/dist/tools/index-tools/registry.d.ts +35 -0
  238. package/dist/tools/index-tools/registry.d.ts.map +1 -1
  239. package/dist/tools/index-tools/registry.js +167 -3
  240. package/dist/tools/index-tools/registry.js.map +1 -1
  241. package/dist/tools/index-tools/state.d.ts +31 -0
  242. package/dist/tools/index-tools/state.d.ts.map +1 -1
  243. package/dist/tools/index-tools/state.js +53 -0
  244. package/dist/tools/index-tools/state.js.map +1 -1
  245. package/dist/tools/index-tools/types.d.ts +9 -0
  246. package/dist/tools/index-tools/types.d.ts.map +1 -1
  247. package/dist/tools/index-tools/watcher.js +3 -3
  248. package/dist/tools/index-tools/watcher.js.map +1 -1
  249. package/dist/tools/index-tools/worktree-seed.d.ts +44 -0
  250. package/dist/tools/index-tools/worktree-seed.d.ts.map +1 -0
  251. package/dist/tools/index-tools/worktree-seed.js +302 -0
  252. package/dist/tools/index-tools/worktree-seed.js.map +1 -0
  253. package/dist/tools/index-tools.d.ts +2 -2
  254. package/dist/tools/index-tools.d.ts.map +1 -1
  255. package/dist/tools/index-tools.js +5 -3
  256. package/dist/tools/index-tools.js.map +1 -1
  257. package/dist/tools/nest-ext-tools/graphql.d.ts +17 -0
  258. package/dist/tools/nest-ext-tools/graphql.d.ts.map +1 -0
  259. package/dist/tools/nest-ext-tools/graphql.js +54 -0
  260. package/dist/tools/nest-ext-tools/graphql.js.map +1 -0
  261. package/dist/tools/nest-ext-tools/microservice.d.ts +17 -0
  262. package/dist/tools/nest-ext-tools/microservice.d.ts.map +1 -0
  263. package/dist/tools/nest-ext-tools/microservice.js +51 -0
  264. package/dist/tools/nest-ext-tools/microservice.js.map +1 -0
  265. package/dist/tools/nest-ext-tools/openapi.d.ts +81 -0
  266. package/dist/tools/nest-ext-tools/openapi.d.ts.map +1 -0
  267. package/dist/tools/nest-ext-tools/openapi.js +254 -0
  268. package/dist/tools/nest-ext-tools/openapi.js.map +1 -0
  269. package/dist/tools/nest-ext-tools/queue.d.ts +27 -0
  270. package/dist/tools/nest-ext-tools/queue.d.ts.map +1 -0
  271. package/dist/tools/nest-ext-tools/queue.js +95 -0
  272. package/dist/tools/nest-ext-tools/queue.js.map +1 -0
  273. package/dist/tools/nest-ext-tools/schedule.d.ts +19 -0
  274. package/dist/tools/nest-ext-tools/schedule.d.ts.map +1 -0
  275. package/dist/tools/nest-ext-tools/schedule.js +89 -0
  276. package/dist/tools/nest-ext-tools/schedule.js.map +1 -0
  277. package/dist/tools/nest-ext-tools/scope.d.ts +19 -0
  278. package/dist/tools/nest-ext-tools/scope.d.ts.map +1 -0
  279. package/dist/tools/nest-ext-tools/scope.js +151 -0
  280. package/dist/tools/nest-ext-tools/scope.js.map +1 -0
  281. package/dist/tools/nest-ext-tools/shared.d.ts +33 -0
  282. package/dist/tools/nest-ext-tools/shared.d.ts.map +1 -0
  283. package/dist/tools/nest-ext-tools/shared.js +279 -0
  284. package/dist/tools/nest-ext-tools/shared.js.map +1 -0
  285. package/dist/tools/nest-ext-tools/typeorm.d.ts +22 -0
  286. package/dist/tools/nest-ext-tools/typeorm.d.ts.map +1 -0
  287. package/dist/tools/nest-ext-tools/typeorm.js +59 -0
  288. package/dist/tools/nest-ext-tools/typeorm.js.map +1 -0
  289. package/dist/tools/nest-ext-tools/websocket.d.ts +21 -0
  290. package/dist/tools/nest-ext-tools/websocket.d.ts.map +1 -0
  291. package/dist/tools/nest-ext-tools/websocket.js +70 -0
  292. package/dist/tools/nest-ext-tools/websocket.js.map +1 -0
  293. package/dist/tools/nest-ext-tools.d.ts +10 -204
  294. package/dist/tools/nest-ext-tools.d.ts.map +1 -1
  295. package/dist/tools/nest-ext-tools.js +10 -749
  296. package/dist/tools/nest-ext-tools.js.map +1 -1
  297. package/dist/tools/perf-tools.js +2 -2
  298. package/dist/tools/plan-turn/stale-index.d.ts +32 -0
  299. package/dist/tools/plan-turn/stale-index.d.ts.map +1 -1
  300. package/dist/tools/plan-turn/stale-index.js +42 -5
  301. package/dist/tools/plan-turn/stale-index.js.map +1 -1
  302. package/dist/tools/python-audit/checks/dead-code.d.ts +1 -1
  303. package/dist/tools/python-audit/checks/dead-code.d.ts.map +1 -1
  304. package/dist/tools/python-constants/constant-match.d.ts +5 -0
  305. package/dist/tools/python-constants/constant-match.d.ts.map +1 -0
  306. package/dist/tools/python-constants/constant-match.js +24 -0
  307. package/dist/tools/python-constants/constant-match.js.map +1 -0
  308. package/dist/tools/python-constants/file-context.d.ts +5 -0
  309. package/dist/tools/python-constants/file-context.d.ts.map +1 -0
  310. package/dist/tools/python-constants/file-context.js +91 -0
  311. package/dist/tools/python-constants/file-context.js.map +1 -0
  312. package/dist/tools/python-constants/function-defaults.d.ts +5 -0
  313. package/dist/tools/python-constants/function-defaults.d.ts.map +1 -0
  314. package/dist/tools/python-constants/function-defaults.js +98 -0
  315. package/dist/tools/python-constants/function-defaults.js.map +1 -0
  316. package/dist/tools/python-constants/model.d.ts +78 -0
  317. package/dist/tools/python-constants/model.d.ts.map +1 -0
  318. package/dist/tools/python-constants/model.js +2 -0
  319. package/dist/tools/python-constants/model.js.map +1 -0
  320. package/dist/tools/python-constants/syntax.d.ts +22 -0
  321. package/dist/tools/python-constants/syntax.d.ts.map +1 -0
  322. package/dist/tools/python-constants/syntax.js +93 -0
  323. package/dist/tools/python-constants/syntax.js.map +1 -0
  324. package/dist/tools/python-constants/value-resolver.d.ts +6 -0
  325. package/dist/tools/python-constants/value-resolver.d.ts.map +1 -0
  326. package/dist/tools/python-constants/value-resolver.js +320 -0
  327. package/dist/tools/python-constants/value-resolver.js.map +1 -0
  328. package/dist/tools/python-constants-tools.d.ts +3 -45
  329. package/dist/tools/python-constants-tools.d.ts.map +1 -1
  330. package/dist/tools/python-constants-tools.js +2 -505
  331. package/dist/tools/python-constants-tools.js.map +1 -1
  332. package/dist/tools/route-tools/django.d.ts +8 -0
  333. package/dist/tools/route-tools/django.d.ts.map +1 -0
  334. package/dist/tools/route-tools/django.js +52 -0
  335. package/dist/tools/route-tools/django.js.map +1 -0
  336. package/dist/tools/route-tools/express.d.ts +5 -0
  337. package/dist/tools/route-tools/express.d.ts.map +1 -0
  338. package/dist/tools/route-tools/express.js +33 -0
  339. package/dist/tools/route-tools/express.js.map +1 -0
  340. package/dist/tools/route-tools/file-sources.d.ts +7 -0
  341. package/dist/tools/route-tools/file-sources.d.ts.map +1 -0
  342. package/dist/tools/route-tools/file-sources.js +15 -0
  343. package/dist/tools/route-tools/file-sources.js.map +1 -0
  344. package/dist/tools/route-tools/handler-discovery.d.ts +4 -0
  345. package/dist/tools/route-tools/handler-discovery.d.ts.map +1 -0
  346. package/dist/tools/route-tools/handler-discovery.js +38 -0
  347. package/dist/tools/route-tools/handler-discovery.js.map +1 -0
  348. package/dist/tools/route-tools/hono.d.ts +5 -0
  349. package/dist/tools/route-tools/hono.d.ts.map +1 -0
  350. package/dist/tools/route-tools/hono.js +61 -0
  351. package/dist/tools/route-tools/hono.js.map +1 -0
  352. package/dist/tools/route-tools/ktor.d.ts +5 -0
  353. package/dist/tools/route-tools/ktor.d.ts.map +1 -0
  354. package/dist/tools/route-tools/ktor.js +76 -0
  355. package/dist/tools/route-tools/ktor.js.map +1 -0
  356. package/dist/tools/route-tools/laravel.d.ts +5 -0
  357. package/dist/tools/route-tools/laravel.d.ts.map +1 -0
  358. package/dist/tools/route-tools/laravel.js +45 -0
  359. package/dist/tools/route-tools/laravel.js.map +1 -0
  360. package/dist/tools/route-tools/mermaid-call-chain.d.ts +3 -0
  361. package/dist/tools/route-tools/mermaid-call-chain.d.ts.map +1 -0
  362. package/dist/tools/route-tools/mermaid-call-chain.js +50 -0
  363. package/dist/tools/route-tools/mermaid-call-chain.js.map +1 -0
  364. package/dist/tools/route-tools/nest.d.ts +5 -0
  365. package/dist/tools/route-tools/nest.d.ts.map +1 -0
  366. package/dist/tools/route-tools/nest.js +75 -0
  367. package/dist/tools/route-tools/nest.js.map +1 -0
  368. package/dist/tools/route-tools/next-trace.d.ts +4 -0
  369. package/dist/tools/route-tools/next-trace.d.ts.map +1 -0
  370. package/dist/tools/route-tools/next-trace.js +48 -0
  371. package/dist/tools/route-tools/next-trace.js.map +1 -0
  372. package/dist/tools/route-tools/next.d.ts +7 -0
  373. package/dist/tools/route-tools/next.d.ts.map +1 -0
  374. package/dist/tools/route-tools/next.js +77 -0
  375. package/dist/tools/route-tools/next.js.map +1 -0
  376. package/dist/tools/route-tools/python-decorators.d.ts +7 -0
  377. package/dist/tools/route-tools/python-decorators.d.ts.map +1 -0
  378. package/dist/tools/route-tools/python-decorators.js +53 -0
  379. package/dist/tools/route-tools/python-decorators.js.map +1 -0
  380. package/dist/tools/route-tools/route-mermaid.d.ts +4 -0
  381. package/dist/tools/route-tools/route-mermaid.d.ts.map +1 -0
  382. package/dist/tools/route-tools/route-mermaid.js +53 -0
  383. package/dist/tools/route-tools/route-mermaid.js.map +1 -0
  384. package/dist/tools/route-tools/spring-kotlin.d.ts +5 -0
  385. package/dist/tools/route-tools/spring-kotlin.d.ts.map +1 -0
  386. package/dist/tools/route-tools/spring-kotlin.js +52 -0
  387. package/dist/tools/route-tools/spring-kotlin.js.map +1 -0
  388. package/dist/tools/route-tools/trace-analysis.d.ts +4 -0
  389. package/dist/tools/route-tools/trace-analysis.d.ts.map +1 -0
  390. package/dist/tools/route-tools/trace-analysis.js +37 -0
  391. package/dist/tools/route-tools/trace-analysis.js.map +1 -0
  392. package/dist/tools/route-tools/trace-route.d.ts +6 -0
  393. package/dist/tools/route-tools/trace-route.d.ts.map +1 -0
  394. package/dist/tools/route-tools/trace-route.js +53 -0
  395. package/dist/tools/route-tools/trace-route.js.map +1 -0
  396. package/dist/tools/route-tools/types.d.ts +35 -0
  397. package/dist/tools/route-tools/types.d.ts.map +1 -0
  398. package/dist/tools/route-tools/types.js +2 -0
  399. package/dist/tools/route-tools/types.js.map +1 -0
  400. package/dist/tools/route-tools/yii2.d.ts +5 -0
  401. package/dist/tools/route-tools/yii2.d.ts.map +1 -0
  402. package/dist/tools/route-tools/yii2.js +73 -0
  403. package/dist/tools/route-tools/yii2.js.map +1 -0
  404. package/dist/tools/route-tools.d.ts +7 -49
  405. package/dist/tools/route-tools.d.ts.map +1 -1
  406. package/dist/tools/route-tools.js +5 -978
  407. package/dist/tools/route-tools.js.map +1 -1
  408. package/dist/tools/search-tools/types.d.ts +20 -0
  409. package/dist/tools/search-tools/types.d.ts.map +1 -1
  410. package/dist/tools/search-tools/zero-hit.d.ts.map +1 -1
  411. package/dist/tools/search-tools/zero-hit.js +0 -0
  412. package/dist/tools/search-tools/zero-hit.js.map +1 -1
  413. package/dist/tools/status-tools.d.ts +10 -0
  414. package/dist/tools/status-tools.d.ts.map +1 -1
  415. package/dist/tools/status-tools.js +14 -4
  416. package/dist/tools/status-tools.js.map +1 -1
  417. package/dist/tools/symbol-analysis-tools.d.ts +81 -0
  418. package/dist/tools/symbol-analysis-tools.d.ts.map +1 -0
  419. package/dist/tools/symbol-analysis-tools.js +327 -0
  420. package/dist/tools/symbol-analysis-tools.js.map +1 -0
  421. package/dist/tools/symbol-context-tools.d.ts +68 -0
  422. package/dist/tools/symbol-context-tools.d.ts.map +1 -0
  423. package/dist/tools/symbol-context-tools.js +232 -0
  424. package/dist/tools/symbol-context-tools.js.map +1 -0
  425. package/dist/tools/symbol-lookup-tools.d.ts +77 -0
  426. package/dist/tools/symbol-lookup-tools.d.ts.map +1 -0
  427. package/dist/tools/symbol-lookup-tools.js +305 -0
  428. package/dist/tools/symbol-lookup-tools.js.map +1 -0
  429. package/dist/tools/symbol-reference-tools.d.ts +38 -0
  430. package/dist/tools/symbol-reference-tools.d.ts.map +1 -0
  431. package/dist/tools/symbol-reference-tools.js +253 -0
  432. package/dist/tools/symbol-reference-tools.js.map +1 -0
  433. package/dist/tools/symbol-tool-internals.d.ts +9 -0
  434. package/dist/tools/symbol-tool-internals.d.ts.map +1 -0
  435. package/dist/tools/symbol-tool-internals.js +47 -0
  436. package/dist/tools/symbol-tool-internals.js.map +1 -0
  437. package/dist/tools/symbol-tools.d.ts +11 -176
  438. package/dist/tools/symbol-tools.d.ts.map +1 -1
  439. package/dist/tools/symbol-tools.js +7 -975
  440. package/dist/tools/symbol-tools.js.map +1 -1
  441. package/dist/tools/taint/python-context.d.ts +10 -0
  442. package/dist/tools/taint/python-context.d.ts.map +1 -0
  443. package/dist/tools/taint/python-context.js +150 -0
  444. package/dist/tools/taint/python-context.js.map +1 -0
  445. package/dist/tools/taint/taint-analyzer.d.ts +2 -0
  446. package/dist/tools/taint/taint-analyzer.d.ts.map +1 -0
  447. package/dist/tools/taint/taint-analyzer.js +2 -0
  448. package/dist/tools/taint/taint-analyzer.js.map +1 -0
  449. package/dist/tools/taint/taint-expression.d.ts +18 -0
  450. package/dist/tools/taint/taint-expression.d.ts.map +1 -0
  451. package/dist/tools/taint/taint-expression.js +265 -0
  452. package/dist/tools/taint/taint-expression.js.map +1 -0
  453. package/dist/tools/taint/taint-flow.d.ts +10 -0
  454. package/dist/tools/taint/taint-flow.d.ts.map +1 -0
  455. package/dist/tools/taint/taint-flow.js +178 -0
  456. package/dist/tools/taint/taint-flow.js.map +1 -0
  457. package/dist/tools/taint/taint-model.d.ts +113 -0
  458. package/dist/tools/taint/taint-model.d.ts.map +1 -0
  459. package/dist/tools/taint/taint-model.js +277 -0
  460. package/dist/tools/taint/taint-model.js.map +1 -0
  461. package/dist/tools/taint-tools.d.ts +2 -34
  462. package/dist/tools/taint-tools.d.ts.map +1 -1
  463. package/dist/tools/taint-tools.js +2 -852
  464. package/dist/tools/taint-tools.js.map +1 -1
  465. package/dist/tools/typescript-constants/file-context.d.ts +7 -0
  466. package/dist/tools/typescript-constants/file-context.d.ts.map +1 -0
  467. package/dist/tools/typescript-constants/file-context.js +219 -0
  468. package/dist/tools/typescript-constants/file-context.js.map +1 -0
  469. package/dist/tools/typescript-constants/symbol-resolver.d.ts +7 -0
  470. package/dist/tools/typescript-constants/symbol-resolver.d.ts.map +1 -0
  471. package/dist/tools/typescript-constants/symbol-resolver.js +165 -0
  472. package/dist/tools/typescript-constants/symbol-resolver.js.map +1 -0
  473. package/dist/tools/typescript-constants/types.d.ts +44 -0
  474. package/dist/tools/typescript-constants/types.d.ts.map +1 -0
  475. package/dist/tools/typescript-constants/types.js +2 -0
  476. package/dist/tools/typescript-constants/types.js.map +1 -0
  477. package/dist/tools/typescript-constants/value-evaluator.d.ts +8 -0
  478. package/dist/tools/typescript-constants/value-evaluator.d.ts.map +1 -0
  479. package/dist/tools/typescript-constants/value-evaluator.js +404 -0
  480. package/dist/tools/typescript-constants/value-evaluator.js.map +1 -0
  481. package/dist/tools/typescript-constants-tools.d.ts.map +1 -1
  482. package/dist/tools/typescript-constants-tools.js +19 -709
  483. package/dist/tools/typescript-constants-tools.js.map +1 -1
  484. package/dist/types.d.ts +6 -0
  485. package/dist/types.d.ts.map +1 -1
  486. package/dist/utils/git-head.d.ts +12 -0
  487. package/dist/utils/git-head.d.ts.map +1 -1
  488. package/dist/utils/git-head.js +25 -0
  489. package/dist/utils/git-head.js.map +1 -1
  490. package/dist/utils/import-graph/collect.d.ts +5 -0
  491. package/dist/utils/import-graph/collect.d.ts.map +1 -0
  492. package/dist/utils/import-graph/collect.js +47 -0
  493. package/dist/utils/import-graph/collect.js.map +1 -0
  494. package/dist/utils/import-graph/edge-accumulator.d.ts +7 -0
  495. package/dist/utils/import-graph/edge-accumulator.d.ts.map +1 -0
  496. package/dist/utils/import-graph/edge-accumulator.js +47 -0
  497. package/dist/utils/import-graph/edge-accumulator.js.map +1 -0
  498. package/dist/utils/import-graph/language-imports.d.ts +6 -0
  499. package/dist/utils/import-graph/language-imports.d.ts.map +1 -0
  500. package/dist/utils/import-graph/language-imports.js +84 -0
  501. package/dist/utils/import-graph/language-imports.js.map +1 -0
  502. package/dist/utils/import-graph/metrics.d.ts +6 -0
  503. package/dist/utils/import-graph/metrics.d.ts.map +1 -0
  504. package/dist/utils/import-graph/metrics.js +51 -0
  505. package/dist/utils/import-graph/metrics.js.map +1 -0
  506. package/dist/utils/import-graph/path-map.d.ts +7 -0
  507. package/dist/utils/import-graph/path-map.d.ts.map +1 -0
  508. package/dist/utils/import-graph/path-map.js +56 -0
  509. package/dist/utils/import-graph/path-map.js.map +1 -0
  510. package/dist/utils/import-graph/python-php-edge-collectors.d.ts +5 -0
  511. package/dist/utils/import-graph/python-php-edge-collectors.d.ts.map +1 -0
  512. package/dist/utils/import-graph/python-php-edge-collectors.js +56 -0
  513. package/dist/utils/import-graph/python-php-edge-collectors.js.map +1 -0
  514. package/dist/utils/import-graph/source-edge-collector.d.ts +13 -0
  515. package/dist/utils/import-graph/source-edge-collector.d.ts.map +1 -0
  516. package/dist/utils/import-graph/source-edge-collector.js +42 -0
  517. package/dist/utils/import-graph/source-edge-collector.js.map +1 -0
  518. package/dist/utils/import-graph/source-imports.d.ts +5 -0
  519. package/dist/utils/import-graph/source-imports.d.ts.map +1 -0
  520. package/dist/utils/import-graph/source-imports.js +33 -0
  521. package/dist/utils/import-graph/source-imports.js.map +1 -0
  522. package/dist/utils/import-graph/types.d.ts +15 -0
  523. package/dist/utils/import-graph/types.d.ts.map +1 -0
  524. package/dist/utils/import-graph/types.js +2 -0
  525. package/dist/utils/import-graph/types.js.map +1 -0
  526. package/dist/utils/import-graph/typescript-edge-collector.d.ts +7 -0
  527. package/dist/utils/import-graph/typescript-edge-collector.d.ts.map +1 -0
  528. package/dist/utils/import-graph/typescript-edge-collector.js +58 -0
  529. package/dist/utils/import-graph/typescript-edge-collector.js.map +1 -0
  530. package/dist/utils/import-graph/workspace-alias.d.ts +7 -0
  531. package/dist/utils/import-graph/workspace-alias.d.ts.map +1 -0
  532. package/dist/utils/import-graph/workspace-alias.js +95 -0
  533. package/dist/utils/import-graph/workspace-alias.js.map +1 -0
  534. package/dist/utils/import-graph/workspace-entry.d.ts +3 -0
  535. package/dist/utils/import-graph/workspace-entry.d.ts.map +1 -0
  536. package/dist/utils/import-graph/workspace-entry.js +81 -0
  537. package/dist/utils/import-graph/workspace-entry.js.map +1 -0
  538. package/dist/utils/import-graph.d.ts +10 -94
  539. package/dist/utils/import-graph.d.ts.map +1 -1
  540. package/dist/utils/import-graph.js +6 -702
  541. package/dist/utils/import-graph.js.map +1 -1
  542. package/package.json +6 -4
  543. package/rules/codesift.md +11 -2
  544. package/rules/codesift.mdc +11 -2
  545. package/rules/codex.md +11 -2
  546. package/rules/gemini.md +11 -2
@@ -1,979 +1,11 @@
1
- import { readFile, open } from "node:fs/promises";
2
- import { execFileSync } from "node:child_process";
3
- import { join } from "node:path";
4
- import { searchBM25 } from "../search/bm25.js";
5
- import { findReferencesLsp } from "../lsp/lsp-tools.js";
6
- import { loadConfig } from "../config.js";
7
- import { isTestFileStrict as isTestFile } from "../utils/test-file.js";
8
- import { detectFrameworks, isFrameworkEntryPoint } from "../utils/framework-detect.js";
9
- import { getCodeIndex, getBM25Index } from "./index-tools.js";
10
- import { REACT_STDLIB_HOOKS, extractHookNames } from "./react-tools.js";
11
- const MAX_REFERENCES = 100;
12
- const MAX_DEAD_CODE_RESULTS = 100;
13
- const MAX_CONTEXT_LENGTH = 200; // Truncate context lines to prevent huge output from minified files
14
- /** Skip build artifacts and binary files — docs/audits are intentionally kept */
15
- const NOISE_PATH_PREFIXES = [".next/", "dist/", "build/", "coverage/", "node_modules/", "__snapshots__/"];
16
- const NOISE_EXTENSIONS = new Set([".snap", ".lock", ".map", ".svg", ".png", ".jpg", ".ico", ".woff", ".woff2"]);
17
- function isNoisePath(filePath) {
18
- if (NOISE_PATH_PREFIXES.some((p) => filePath.startsWith(p)))
19
- return true;
20
- const dot = filePath.lastIndexOf(".");
21
- if (dot >= 0 && NOISE_EXTENSIONS.has(filePath.slice(dot)))
22
- return true;
23
- return false;
24
- }
25
1
  /**
26
- * Find symbols with names similar to the requested ID. Used to recover from
27
- * hallucinated symbol IDs (telemetry shows 24-26% of get_symbol/get_symbols
28
- * calls return zero results). Extracts a name candidate from the requested
29
- * ID and returns up to `limit` symbols whose name matches case-insensitively.
30
- */
31
- /**
32
- * Resolve a non-canonical symbol reference to a real symbol ID when it is
33
- * UNAMBIGUOUS.
34
- *
35
- * Symbol IDs are `repo:file:name:line` — they embed the declaration line, so no
36
- * caller can construct one by hand. Agents therefore pass a bare name
37
- * ("getOptions") or a half-remembered path, and the lookup returns null; the
38
- * measured miss rate was 24% of get_symbol calls and 26% of get_symbols. The old
39
- * behaviour answered with a suggestion list, which is a second round trip for a
40
- * question we can already answer.
41
- *
42
- * Only an EXACT, SINGLE name match resolves. Two symbols named `handler` must
43
- * stay ambiguous — silently picking one would return the wrong source with no
44
- * signal, which is worse than the miss it replaces.
45
- */
46
- /**
47
- * Best-effort symbol NAME out of whatever the caller passed.
48
- *
49
- * Symbol IDs end in the declaration line (`repo:file:name:LINE`), so naively
50
- * taking the last segment yields "42" and matches nothing — every suggestion for
51
- * a well-formed-but-stale id was silently useless. Skip trailing numeric
52
- * segments, then fall back to the last non-empty one.
53
- */
54
- export function extractSymbolNameGuess(requestedId) {
55
- const parts = requestedId.split(/[:#/.]/).map((p) => p.trim()).filter(Boolean);
56
- for (let i = parts.length - 1; i >= 0; i--) {
57
- const p = parts[i];
58
- if (!/^\d+$/.test(p))
59
- return p;
60
- }
61
- return requestedId.trim();
62
- }
63
- export async function resolveSymbolIdExact(repo, requestedId) {
64
- const nameGuess = extractSymbolNameGuess(requestedId);
65
- if (!nameGuess)
66
- return null;
67
- const index = await getCodeIndex(repo, { skipFreshness: true });
68
- if (!index)
69
- return null;
70
- let match = null;
71
- for (const s of index.symbols) {
72
- if (s.name !== nameGuess)
73
- continue;
74
- if (match)
75
- return null; // ambiguous — let the caller show suggestions
76
- match = s.id;
77
- }
78
- return match;
79
- }
80
- export async function findSimilarSymbols(repo, requestedId, limit = 3) {
81
- const index = await getCodeIndex(repo, { skipFreshness: true });
82
- if (!index)
83
- return [];
84
- const nameGuess = extractSymbolNameGuess(requestedId);
85
- if (!nameGuess)
86
- return [];
87
- const lower = nameGuess.toLowerCase();
88
- const exact = [];
89
- const prefix = [];
90
- const substr = [];
91
- for (const s of index.symbols) {
92
- const sn = s.name.toLowerCase();
93
- if (sn === lower)
94
- exact.push(s);
95
- else if (sn.startsWith(lower) || lower.startsWith(sn))
96
- prefix.push(s);
97
- else if (sn.includes(lower) || lower.includes(sn))
98
- substr.push(s);
99
- if (exact.length >= limit)
100
- break;
101
- }
102
- const ranked = [...exact, ...prefix, ...substr].slice(0, limit);
103
- return ranked.map((s) => ({
104
- id: s.id,
105
- name: s.name,
106
- kind: s.kind,
107
- file: s.file,
108
- start_line: s.start_line,
109
- }));
110
- }
111
- async function requireCodeIndex(repo) {
112
- const index = await getCodeIndex(repo);
113
- if (!index) {
114
- throw new Error(`Repository "${repo}" not found. Index it first with index_folder.`);
115
- }
116
- return index;
117
- }
118
- async function requireBM25Index(repo) {
119
- const index = await getBM25Index(repo);
120
- if (!index) {
121
- throw new Error(`Repository "${repo}" not found. Index it first with index_folder.`);
122
- }
123
- return index;
124
- }
125
- function wordBoundaryPattern(name) {
126
- const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
127
- return new RegExp(`\\b${escaped}\\b`);
128
- }
129
- /**
130
- * Strip internal/BM25 fields from CodeSymbol for leaner output.
131
- * Removes: repo, tokens, start_col, end_col. Shortens id (strips repo prefix).
132
- */
133
- function stripSymbol(sym) {
134
- const { repo: _repo, tokens: _tokens, start_col: _sc, end_col: _ec, start_byte: _sb, end_byte: _eb, id, ...rest } = sym;
135
- // Strip "local/reponame:" prefix from id
136
- const shortId = id.includes(":") ? id.slice(id.indexOf(":") + 1) : id;
137
- return { ...rest, id: shortId };
138
- }
139
- /**
140
- * Read a source file and extract lines for a symbol (1-based, inclusive).
141
- * Uses byte offsets when available for precise reads without loading full file.
142
- * Returns undefined if the file cannot be read.
143
- */
144
- async function extractSource(repoRoot, file, startLine, endLine, startByte, endByte) {
145
- const filePath = join(repoRoot, file);
146
- // Fast path: use byte offsets to read exact range
147
- if (startByte != null && endByte != null && endByte > startByte) {
148
- try {
149
- const fh = await open(filePath, "r");
150
- try {
151
- const length = endByte - startByte;
152
- const buf = Buffer.alloc(length);
153
- await fh.read(buf, 0, length, startByte);
154
- return buf.toString("utf-8");
155
- }
156
- finally {
157
- await fh.close();
158
- }
159
- }
160
- catch {
161
- // Fall through to line-based extraction
162
- }
163
- }
164
- // Fallback: line-based extraction
165
- try {
166
- const content = await readFile(filePath, "utf-8");
167
- const lines = content.split("\n");
168
- return lines.slice(startLine - 1, endLine).join("\n");
169
- }
170
- catch {
171
- return undefined;
172
- }
173
- }
174
- /**
175
- * Retrieve a single symbol by ID with fresh source from disk.
176
- * When include_related is true (default), auto-prefetches:
177
- * - children (for classes/interfaces) — saves follow-up get_symbols call
178
- * - symbols in the same file that reference this symbol — saves find_references call
179
- */
180
- export async function getSymbol(repo, symbolId, options) {
181
- const index = await requireCodeIndex(repo);
182
- const includeRelated = options?.include_related ?? true;
183
- const symbol = index.symbols.find((s) => s.id === symbolId);
184
- if (!symbol)
185
- return null;
186
- const source = await extractSource(index.root, symbol.file, symbol.start_line, symbol.end_line, symbol.start_byte, symbol.end_byte);
187
- const result = { ...symbol };
188
- if (source !== undefined) {
189
- result.source = source;
190
- }
191
- const stripped = stripSymbol(result);
192
- if (!includeRelated) {
193
- return { symbol: stripped };
194
- }
195
- // Prefetch children for classes/interfaces
196
- const related = [];
197
- if (symbol.kind === "class" || symbol.kind === "interface") {
198
- const children = index.symbols.filter((s) => s.parent === symbol.id);
199
- for (const child of children.slice(0, 20)) {
200
- related.push(stripSymbol(child));
201
- }
202
- }
203
- const out = { symbol: stripped };
204
- if (related.length > 0)
205
- out.related = related;
206
- return out;
207
- }
208
- /**
209
- * Retrieve multiple symbols by ID with fresh source from disk.
210
- * Groups reads by file to minimize disk I/O.
211
- */
212
- export async function getSymbols(repo, symbolIds) {
213
- const index = await requireCodeIndex(repo);
214
- // Build lookup map for requested symbols
215
- const requestedIds = new Set(symbolIds);
216
- const symbolMap = new Map();
217
- for (const sym of index.symbols) {
218
- if (requestedIds.has(sym.id)) {
219
- symbolMap.set(sym.id, sym);
220
- }
221
- }
222
- // Group symbols by file to read each file only once
223
- const byFile = new Map();
224
- for (const id of symbolIds) {
225
- const sym = symbolMap.get(id);
226
- if (!sym)
227
- continue;
228
- let group = byFile.get(sym.file);
229
- if (!group) {
230
- group = [];
231
- byFile.set(sym.file, group);
232
- }
233
- group.push(sym);
234
- }
235
- // Read all files in parallel, extract source for all symbols in each file
236
- const results = new Map();
237
- const fileEntries = [...byFile.entries()];
238
- const fileContents = await Promise.all(fileEntries.map(([file]) => readFile(join(index.root, file), "utf-8").catch(() => undefined)));
239
- for (let i = 0; i < fileEntries.length; i++) {
240
- const [, symbols] = fileEntries[i];
241
- const lines = fileContents[i]?.split("\n");
242
- for (const sym of symbols) {
243
- const result = { ...sym };
244
- if (lines) {
245
- result.source = lines.slice(sym.start_line - 1, sym.end_line).join("\n");
246
- }
247
- results.set(sym.id, result);
248
- }
249
- }
250
- // Return in the same order as requested, skipping missing IDs
251
- const ordered = [];
252
- for (const id of symbolIds) {
253
- const sym = results.get(id);
254
- if (sym)
255
- ordered.push(stripSymbol(sym));
256
- }
257
- return ordered;
258
- }
259
- /**
260
- * Find references to a symbol name across indexed files.
261
- * Matches whole words only using word-boundary regex.
262
- */
263
- /**
264
- * Batch find references for multiple symbols in one pass.
265
- * Reads each file once instead of N times — critical for large repos.
266
- */
267
- export async function findReferencesBatch(repo, symbolNames, filePattern) {
268
- const index = await requireCodeIndex(repo);
269
- const patterns = symbolNames.map((name) => ({
270
- name,
271
- regex: wordBoundaryPattern(name),
272
- }));
273
- const fileFilter = filePattern
274
- ? new RegExp(filePattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, ".*"))
275
- : null;
276
- const result = {};
277
- for (const name of symbolNames)
278
- result[name] = [];
279
- for (const fileEntry of index.files) {
280
- if (fileFilter && !fileFilter.test(fileEntry.path))
281
- continue;
282
- if (!filePattern && isNoisePath(fileEntry.path))
283
- continue;
284
- let content;
285
- try {
286
- content = await readFile(join(index.root, fileEntry.path), "utf-8");
287
- }
288
- catch {
289
- continue;
290
- }
291
- const lines = content.split("\n");
292
- for (let i = 0; i < lines.length; i++) {
293
- const line = lines[i];
294
- if (line === undefined)
295
- continue;
296
- for (const { name, regex } of patterns) {
297
- const refs = result[name];
298
- if (refs.length >= MAX_REFERENCES)
299
- continue;
300
- const match = regex.exec(line);
301
- if (match) {
302
- const rawContext = line.trimEnd();
303
- refs.push({
304
- file: fileEntry.path,
305
- line: i + 1,
306
- col: match.index + 1,
307
- context: rawContext.length > MAX_CONTEXT_LENGTH
308
- ? rawContext.slice(0, MAX_CONTEXT_LENGTH) + "..."
309
- : rawContext,
310
- });
311
- }
312
- }
313
- }
314
- }
315
- return result;
316
- }
317
- const SEARCH_TIMEOUT_MS = 30_000;
318
- /** Directories to exclude from ripgrep reference search */
319
- const RG_EXCLUDE_DIRS = [
320
- "node_modules", ".git", ".next", "dist", ".codesift", "coverage",
321
- ".playwright-mcp", "__pycache__", "__snapshots__",
322
- ];
323
- /** Detect whether `rg` (ripgrep) is available. Cached at module level. */
324
- let rgAvailable = null;
325
- function hasRipgrep() {
326
- if (rgAvailable !== null)
327
- return rgAvailable;
328
- try {
329
- execFileSync("rg", ["--version"], { stdio: "pipe", timeout: 2000 });
330
- rgAvailable = true;
331
- }
332
- catch {
333
- rgAvailable = false;
334
- }
335
- return rgAvailable;
336
- }
337
- /**
338
- * Find references using ripgrep with word-boundary matching.
339
- * Returns compact `file:line: context` string when results ≤ threshold.
340
- */
341
- function findReferencesWithRipgrep(root, symbolName, maxResults, filePattern) {
342
- const args = [
343
- "-n", "--no-heading", "-w",
344
- "--max-columns", String(MAX_CONTEXT_LENGTH),
345
- "--max-columns-preview",
346
- "--max-count", String(Math.min(maxResults * 2, 5000)),
347
- ];
348
- // Exclude noise dirs
349
- for (const dir of RG_EXCLUDE_DIRS) {
350
- args.push("--glob", `!${dir}`);
351
- }
352
- // Exclude noise extensions
353
- for (const ext of [".snap", ".lock", ".map", ".svg", ".png", ".jpg", ".ico", ".woff", ".woff2", ".md", ".json", ".yaml", ".yml", ".toml", ".css", ".scss", ".html"]) {
354
- args.push("--glob", `!*${ext}`);
355
- }
356
- if (filePattern) {
357
- args.push("--glob", filePattern);
358
- }
359
- else {
360
- // Default to code files only (matches what agent would grep for)
361
- args.push("--type-add", "code:*.{ts,tsx,js,jsx,py,go,rs,java,kt,kts,rb,php,vue,svelte}");
362
- args.push("--type", "code");
363
- }
364
- args.push("--", symbolName, root);
365
- let stdout;
366
- try {
367
- stdout = execFileSync("rg", args, {
368
- encoding: "utf-8",
369
- maxBuffer: 20 * 1024 * 1024,
370
- timeout: SEARCH_TIMEOUT_MS,
371
- });
372
- }
373
- catch (err) {
374
- if (err && typeof err === "object" && "status" in err) {
375
- if (err.status === 1)
376
- return []; // no matches
377
- if ("stdout" in err && typeof err.stdout === "string") {
378
- stdout = err.stdout;
379
- if (!stdout)
380
- return [];
381
- }
382
- else {
383
- return [];
384
- }
385
- }
386
- else {
387
- return [];
388
- }
389
- }
390
- const rootPrefix = root.endsWith("/") ? root : root + "/";
391
- const lines = stdout.split("\n").filter(Boolean);
392
- const refs = [];
393
- for (const rawLine of lines) {
394
- if (refs.length >= maxResults)
395
- break;
396
- const match = rawLine.match(/^(.+?):(\d+):(.*)/);
397
- if (!match || !match[1] || !match[2] || match[3] === undefined)
398
- continue;
399
- const absPath = match[1];
400
- const relPath = absPath.startsWith(rootPrefix) ? absPath.slice(rootPrefix.length) : absPath;
401
- if (isNoisePath(relPath))
402
- continue;
403
- refs.push({
404
- file: relPath,
405
- line: parseInt(match[2], 10),
406
- context: match[3].length > MAX_CONTEXT_LENGTH ? match[3].slice(0, MAX_CONTEXT_LENGTH) + "..." : match[3],
407
- });
408
- }
409
- return refs;
410
- }
411
- export async function findReferences(repo, symbolName, filePattern) {
412
- // Try LSP first (type-safe, no false positives)
413
- const lspRefs = await findReferencesLsp(repo, symbolName);
414
- if (lspRefs !== null)
415
- return lspRefs;
416
- // Use ripgrep when available (10x+ faster than Node.js file walk)
417
- if (hasRipgrep()) {
418
- const index = await requireCodeIndex(repo);
419
- const result = findReferencesWithRipgrep(index.root, symbolName, MAX_REFERENCES, filePattern);
420
- // ripgrep helper may return compact string; convert back to Reference[]
421
- if (typeof result === "string") {
422
- return result.split("\n").filter(Boolean).map((line) => {
423
- const m = line.match(/^(.+?):(\d+): (.*)/);
424
- return m ? { file: m[1], line: parseInt(m[2], 10), context: m[3] } : { file: "", line: 0, context: line };
425
- });
426
- }
427
- return result;
428
- }
429
- // Node.js fallback
430
- const index = await requireCodeIndex(repo);
431
- const pattern = wordBoundaryPattern(symbolName);
432
- const searchStart = Date.now();
433
- const fileFilter = filePattern
434
- ? new RegExp(filePattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, ".*"))
435
- : null;
436
- const refs = [];
437
- for (const fileEntry of index.files) {
438
- if (refs.length >= MAX_REFERENCES)
439
- break;
440
- if (Date.now() - searchStart > SEARCH_TIMEOUT_MS)
441
- break;
442
- if (fileFilter && !fileFilter.test(fileEntry.path))
443
- continue;
444
- if (!filePattern && isNoisePath(fileEntry.path))
445
- continue;
446
- let content;
447
- try {
448
- content = await readFile(join(index.root, fileEntry.path), "utf-8");
449
- }
450
- catch {
451
- continue;
452
- }
453
- const lines = content.split("\n");
454
- for (let i = 0; i < lines.length; i++) {
455
- if (refs.length >= MAX_REFERENCES)
456
- break;
457
- const line = lines[i];
458
- if (line === undefined)
459
- continue;
460
- const match = pattern.exec(line);
461
- if (match) {
462
- const rawContext = line.trimEnd();
463
- refs.push({
464
- file: fileEntry.path,
465
- line: i + 1,
466
- context: rawContext.length > MAX_CONTEXT_LENGTH
467
- ? rawContext.slice(0, MAX_CONTEXT_LENGTH) + "..."
468
- : rawContext,
469
- });
470
- }
471
- }
472
- }
473
- return refs;
474
- }
475
- /** Format references as compact string for MCP output. Groups by file to avoid repeating paths. */
476
- export function formatRefsCompact(refs) {
477
- if (refs.length === 0)
478
- return "";
479
- // Group by file
480
- const groups = new Map();
481
- for (const r of refs) {
482
- let g = groups.get(r.file);
483
- if (!g) {
484
- g = [];
485
- groups.set(r.file, g);
486
- }
487
- g.push(` ${r.line}: ${r.context}`);
488
- }
489
- if (groups.size === refs.length) {
490
- // Each file has 1 ref — flat is fine
491
- return refs.map((r) => `${r.file}:${r.line}: ${r.context}`).join("\n");
492
- }
493
- const parts = [];
494
- for (const [file, lines] of groups) {
495
- parts.push(`${file}\n${lines.join("\n")}`);
496
- }
497
- return parts.join("\n");
498
- }
499
- /** Format a CodeSymbol as compact text: header line + source. ~70% less tokens than JSON. */
500
- export function formatSymbolCompact(sym) {
501
- const loc = `${sym.file}:${sym.start_line}-${sym.end_line}`;
502
- const sig = sym.signature ? ` ${sym.signature}` : "";
503
- const header = `${loc} ${sym.kind} ${sym.name}${sig}`;
504
- if (!sym.source)
505
- return header;
506
- return `${header}\n${sym.source}`;
507
- }
508
- /** Format multiple CodeSymbols as compact text, separated by blank lines. */
509
- export function formatSymbolsCompact(syms) {
510
- return syms.map(formatSymbolCompact).join("\n\n");
511
- }
512
- /** Format ContextBundle as compact text. */
513
- export function formatBundleCompact(bundle) {
514
- const parts = [];
515
- parts.push(formatSymbolCompact(bundle.symbol));
516
- if (bundle.imports.length > 0) {
517
- parts.push(`\n--- imports ---\n${bundle.imports.join("\n")}`);
518
- }
519
- if (bundle.siblings.length > 0) {
520
- const sibLines = bundle.siblings.map((s) => ` ${s.kind} ${s.name} :${s.start_line}-${s.end_line}`);
521
- parts.push(`\n--- siblings ---\n${sibLines.join("\n")}`);
522
- }
523
- if (bundle.types_used.length > 0) {
524
- parts.push(`\n--- types used ---\n${bundle.types_used.join(", ")}`);
525
- }
526
- return parts.join("");
527
- }
528
- /**
529
- * Search for a symbol by query and return it with full source.
530
- * Optionally includes references across the codebase.
531
- */
532
- export async function findAndShow(repo, query, includeRefs) {
533
- const bm25Index = await requireBM25Index(repo);
534
- const config = loadConfig();
535
- const results = searchBM25(bm25Index, query, 1, config.bm25FieldWeights);
536
- const topResult = results[0];
537
- if (!topResult)
538
- return null;
539
- const fullResult = await getSymbol(repo, topResult.symbol.id, { include_related: false });
540
- if (!fullResult)
541
- return null;
542
- const fullSymbol = fullResult.symbol;
543
- if (includeRefs) {
544
- const references = await findReferences(repo, fullSymbol.name);
545
- return { symbol: fullSymbol, references };
546
- }
547
- return { symbol: fullSymbol };
548
- }
549
- /**
550
- * Extract full import lines from file source.
551
- */
552
- function extractImportLines(source) {
553
- const lines = source.split("\n");
554
- return lines.filter((line) => {
555
- const trimmed = line.trim();
556
- return trimmed.startsWith("import ") || (trimmed.startsWith("const ") && trimmed.includes("require("));
557
- });
558
- }
559
- /**
560
- * Get a symbol with its file's imports and sibling symbols in one call.
561
- * Saves 2-3 round-trips vs get_symbol + search_text(imports) + get_file_outline.
562
- */
563
- export async function getContextBundle(repo, symbolName) {
564
- const bm25Index = await requireBM25Index(repo);
565
- const config = loadConfig();
566
- const results = searchBM25(bm25Index, symbolName, 1, config.bm25FieldWeights);
567
- const topResult = results[0];
568
- if (!topResult)
569
- return null;
570
- const index = await requireCodeIndex(repo);
571
- // Get full symbol with source
572
- const fullResult = await getSymbol(repo, topResult.symbol.id, { include_related: false });
573
- if (!fullResult)
574
- return null;
575
- const fullSymbol = fullResult.symbol;
576
- // Read the file to extract imports
577
- let fileSource;
578
- try {
579
- fileSource = await readFile(join(index.root, fullSymbol.file), "utf-8");
580
- }
581
- catch {
582
- return { symbol: fullSymbol, imports: [], siblings: [], types_used: [] };
583
- }
584
- const imports = extractImportLines(fileSource);
585
- // Get sibling symbols (other symbols in the same file)
586
- const siblings = index.symbols
587
- .filter((s) => s.file === fullSymbol.file && s.id !== fullSymbol.id)
588
- .map((s) => ({
589
- name: s.name,
590
- kind: s.kind,
591
- start_line: s.start_line,
592
- end_line: s.end_line,
593
- }));
594
- // Extract type names used in the symbol's source
595
- const typesUsed = extractTypesUsed(fullSymbol.source ?? "", index.symbols);
596
- // React-specific enrichment for components
597
- const bundle = { symbol: fullSymbol, imports, siblings, types_used: typesUsed };
598
- if (fullSymbol.kind === "component") {
599
- bundle.react_context = buildReactContext(fullSymbol, index.symbols);
600
- }
601
- return bundle;
602
- }
603
- /**
604
- * Build React-specific context for a component symbol:
605
- * hooks used, child/parent components via JSX, wrapper pattern.
606
- *
607
- * Uses REACT_STDLIB_HOOKS imported from react-tools.js as the single source
608
- * of truth for stdlib hook detection (CQ14 — no duplication).
609
- */
610
- function buildReactContext(component, allSymbols) {
611
- const source = component.source ?? "";
612
- // Extract hooks used (uses shared extractHookNames from react-tools.ts — CQ14)
613
- const hooks_used = [...extractHookNames(source)].map((name) => ({
614
- name,
615
- is_stdlib: REACT_STDLIB_HOOKS.has(name),
616
- }));
617
- // Extract child components from JSX (<PascalCase>)
618
- const childSet = new Set();
619
- const jsxPattern = /<([A-Z][a-zA-Z0-9_$]*)\b/g;
620
- let m;
621
- while ((m = jsxPattern.exec(source)) !== null) {
622
- const name = m[1];
623
- if (name !== component.name)
624
- childSet.add(name);
625
- }
626
- const child_components = [...childSet].sort();
627
- // Extract parent components: find other components whose source uses <ThisComponent>
628
- const ownPattern = new RegExp(`<${component.name}\\b`);
629
- const parent_components = allSymbols
630
- .filter((s) => s.kind === "component" &&
631
- s.id !== component.id &&
632
- s.name !== component.name &&
633
- s.source &&
634
- ownPattern.test(s.source))
635
- .map((s) => s.name);
636
- // Detect wrapper pattern from source — supports TypeScript generics:
637
- // forwardRef<HTMLDivElement, Props>(...), memo<Props>(...) (Item 9)
638
- let wrapper = null;
639
- if (/\b(?:React\.)?memo\s*(?:<[^>]+>)?\s*\(/.test(source))
640
- wrapper = "memo";
641
- else if (/\b(?:React\.)?forwardRef\s*(?:<[^>]+>)?\s*\(/.test(source))
642
- wrapper = "forwardRef";
643
- else if (/\b(?:React\.)?lazy\s*(?:<[^>]+>)?\s*\(/.test(source))
644
- wrapper = "lazy";
645
- // Extract props type from signature: (props: MyProps) or ({ a, b }: Props)
646
- let props_type = null;
647
- const sig = component.signature ?? "";
648
- // Pattern: (props: TypeName) or (arg: TypeName) or ({ ... }: TypeName)
649
- const propsMatch = sig.match(/\(\s*(?:\{[^}]*\}|\w+)\s*:\s*([A-Z]\w*)/);
650
- if (propsMatch) {
651
- props_type = propsMatch[1];
652
- }
653
- // Resolve props interface body when type name found in the index (Tier 4 — Item 16).
654
- // Look for an interface or type alias with the same name as props_type.
655
- let props_interface_source = null;
656
- if (props_type) {
657
- const decl = allSymbols.find((s) => (s.kind === "interface" || s.kind === "type") && s.name === props_type);
658
- if (decl?.source) {
659
- // Cap to 800 chars to keep bundle compact
660
- props_interface_source = decl.source.length > 800
661
- ? decl.source.slice(0, 800) + "..."
662
- : decl.source;
663
- }
664
- }
665
- return { props_type, props_interface_source, hooks_used, child_components, parent_components, wrapper };
666
- }
667
- /**
668
- * Extract type/interface names referenced in source by matching against known symbols.
669
- */
670
- function extractTypesUsed(source, allSymbols) {
671
- const typeNames = allSymbols
672
- .filter((s) => (s.kind === "interface" || s.kind === "type" || s.kind === "enum") && s.name.length >= 3)
673
- .map((s) => s.name);
674
- if (typeNames.length === 0)
675
- return [];
676
- // Single combined regex instead of N separate tests (O(n) vs O(n*m))
677
- const escaped = typeNames.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
678
- const combined = new RegExp(`\\b(${escaped.join("|")})\\b`, "g");
679
- const used = new Set();
680
- let m;
681
- while ((m = combined.exec(source)) !== null) {
682
- used.add(m[1]);
683
- }
684
- return [...used].sort();
685
- }
686
- // Kinds that are typically exported and should have external references
687
- const EXPORTABLE_KINDS = new Set([
688
- "function", "class", "interface", "type", "variable", "constant", "enum",
689
- "component", "hook",
690
- ]);
691
- /**
692
- * Collect top-level symbols of exportable kinds, filtered by test/pattern options.
693
- */
694
- function collectExportedSymbols(symbols, options) {
695
- return symbols.filter((s) => {
696
- if (!EXPORTABLE_KINDS.has(s.kind))
697
- return false;
698
- if (s.parent)
699
- return false;
700
- if (!options.includeTests && isTestFile(s.file))
701
- return false;
702
- if (options.filePattern && !s.file.includes(options.filePattern))
703
- return false;
704
- if (s.name.length < 3)
705
- return false;
706
- if (s.kind === "variable" && s.name === "default")
707
- return false;
708
- return true;
709
- });
710
- }
711
- // Bumped from 2000 → 5000 (F14: prior cap silently dropped references in
712
- // medium-large repos, producing false-positive dead-code candidates whose
713
- // real callers lived in unscanned files). Memory cost: roughly one file
714
- // content string per entry — at 5K average-sized source files this is on
715
- // the order of 50–200 MB peak, well within limits for analysis flows.
716
- const MAX_SCAN_FILES = 5000;
717
- /**
718
- * Resolve a relative import path against a source file's directory. Handles
719
- * the standard TS/Node extensions plus barrel-style `index` resolution.
720
- * Returns the candidate file path that exists in `allFiles`, or null.
721
- *
722
- * Intentionally narrow: only resolves `./` and `../` paths. Aliased imports
723
- * (tsconfig paths, package-json `imports`) are out of scope here — they show
724
- * up textually in scanned content anyway, so they don't drive false positives.
725
- */
726
- function resolveRelativeImport(fromFile, importPath, allFiles) {
727
- if (!importPath.startsWith("."))
728
- return null;
729
- const lastSlash = fromFile.lastIndexOf("/");
730
- const fromDir = lastSlash >= 0 ? fromFile.slice(0, lastSlash) : "";
731
- const segments = (fromDir + "/" + importPath).split("/");
732
- const stack = [];
733
- for (const seg of segments) {
734
- if (!seg || seg === ".")
735
- continue;
736
- if (seg === "..")
737
- stack.pop();
738
- else
739
- stack.push(seg);
740
- }
741
- const base = stack.join("/");
742
- if (allFiles.has(base))
743
- return base;
744
- // TS allows `import './x.js'` to resolve to `x.ts` — strip then re-extend.
745
- const stripped = base.replace(/\.(m?js|jsx)$/, "");
746
- const candidates = [
747
- stripped + ".ts",
748
- stripped + ".tsx",
749
- stripped + ".mjs",
750
- stripped + ".js",
751
- stripped + ".jsx",
752
- stripped + "/index.ts",
753
- stripped + "/index.tsx",
754
- stripped + "/index.js",
755
- stripped + "/index.jsx",
756
- ];
757
- for (const c of candidates) {
758
- if (allFiles.has(c))
759
- return c;
760
- }
761
- return null;
762
- }
763
- /**
764
- * Pre-scan content for re-export edges. A symbol re-exported from another
765
- * file isn't textually referenced in the barrel — without this pass barrel
766
- * patterns like `export * from './foo'` cause every symbol in `./foo` to be
767
- * misclassified as dead.
2
+ * Stable public facade for symbol-oriented tools.
768
3
  *
769
- * Returns a set of file paths that are reached via at least one re-export
770
- * (named or star). Callers treat any candidate whose defining file lands in
771
- * this set as live.
772
- */
773
- function collectReExportedFiles(fileContents, allFiles) {
774
- const reExported = new Set();
775
- // Matches: export * from "./x"; export { A, B } from "./x"; export type { T } from "./x";
776
- // Anchor dropped (`^\s*` removed) so block-comment-prefixed exports
777
- // (`/** doc */ export { Y } from "./x"`) and continuation-line exports
778
- // (`...; export * from "./x"`) are detected too.
779
- const RE = /\bexport\s+(?:\*|type\s+\*|\{[^}]*\}|type\s+\{[^}]*\})\s+from\s+['"]([^'"]+)['"]/gm;
780
- for (const [filePath, content] of fileContents) {
781
- RE.lastIndex = 0;
782
- let m;
783
- while ((m = RE.exec(content)) !== null) {
784
- const target = resolveRelativeImport(filePath, m[1], allFiles);
785
- if (target)
786
- reExported.add(target);
787
- }
788
- }
789
- return reExported;
790
- }
791
- /**
792
- * Find potentially dead code: exported symbols with 0 references outside their own file.
793
- * Scans all indexed files for word-boundary matches of each exported symbol name.
794
- *
795
- * F14 fixes (2026-05-05):
796
- * - Test files are now ALWAYS scanned for references regardless of
797
- * `include_tests`. The flag now gates only candidate selection (whether
798
- * test-internal exports can themselves be flagged dead). Symbols used
799
- * only in tests are no longer false-positive dead.
800
- * - Re-exports via `export * from './x'` and `export { Y } from './x'`
801
- * now mark `./x` as live; previously the lack of textual mention in the
802
- * barrel made every barrel-forwarded symbol look dead.
803
- * - MAX_SCAN_FILES raised 2000 → 5000; truncation now surfaces in the
804
- * `truncated` field so callers can react.
805
- */
806
- export async function findDeadCode(repo, options) {
807
- const index = await requireCodeIndex(repo);
808
- const includeTests = options?.include_tests ?? false;
809
- const filePattern = options?.file_pattern;
810
- const exportedSymbols = collectExportedSymbols(index.symbols, { includeTests, filePattern });
811
- const frameworks = detectFrameworks(index);
812
- // Read EVERY indexed file (incl. tests) for reference scanning. The previous
813
- // version honored `includeTests` here, which meant a symbol referenced only
814
- // from tests was misclassified as dead. Candidate selection still uses
815
- // `includeTests` (above) so test-only helpers don't appear in the result list.
816
- const fileContents = new Map();
817
- let scanTruncated = false;
818
- for (const file of index.files) {
819
- if (fileContents.size >= MAX_SCAN_FILES) {
820
- scanTruncated = true;
821
- break;
822
- }
823
- try {
824
- fileContents.set(file.path, await readFile(join(index.root, file.path), "utf-8"));
825
- }
826
- catch {
827
- // File may have been deleted
828
- }
829
- }
830
- // Build set of files that are forwarded via re-exports (barrel chains).
831
- // Symbols defined in such files are reachable even without textual mention.
832
- const allFilePaths = new Set(fileContents.keys());
833
- const reExportedFiles = collectReExportedFiles(fileContents, allFilePaths);
834
- // Reference index, built in ONE pass over file contents. Previously this scan
835
- // was O(exportedSymbols x files): a `\b<name>\b` regex over every file's full
836
- // text for every exported symbol. On a healthy repo (few dead symbols) the
837
- // early-exit never fires, so the full product ran — telemetry (2026-07-20)
838
- // measured a 1,066,401 ms (~17.8 min) p95 for find_dead_code.
839
- //
840
- // Tokenising on [^A-Za-z0-9_]+ mirrors the \b\w boundary semantics of the old
841
- // regex. Per token we only need "is it mentioned outside its defining file",
842
- // so we keep the first file that mentioned it plus a multi-file flag — O(1)
843
- // memory per unique token instead of a file set, and O(1) lookup per symbol.
844
- const tokenIndex = new Map();
845
- for (const [filePath, content] of fileContents) {
846
- for (const token of new Set(content.split(/[^A-Za-z0-9_]+/))) {
847
- if (!token)
848
- continue;
849
- const entry = tokenIndex.get(token);
850
- if (!entry)
851
- tokenIndex.set(token, { first: filePath, multi: false });
852
- else if (!entry.multi && entry.first !== filePath)
853
- entry.multi = true;
854
- }
855
- }
856
- const candidates = [];
857
- for (const sym of exportedSymbols) {
858
- if (candidates.length >= MAX_DEAD_CODE_RESULTS)
859
- break;
860
- if (isFrameworkEntryPoint(sym, frameworks))
861
- continue;
862
- // Re-export reachability — barrel forwards skip the textual-mention check.
863
- if (reExportedFiles.has(sym.file))
864
- continue;
865
- // Mentioned in any file other than the one defining it => not dead.
866
- const seen = tokenIndex.get(sym.name);
867
- const hasExternalRef = !!seen && (seen.multi || seen.first !== sym.file);
868
- if (!hasExternalRef) {
869
- candidates.push({
870
- name: sym.name,
871
- kind: sym.kind,
872
- file: sym.file,
873
- start_line: sym.start_line,
874
- end_line: sym.end_line,
875
- reason: "exported but no references found outside defining file",
876
- });
877
- }
878
- }
879
- return {
880
- candidates,
881
- scanned_symbols: exportedSymbols.length,
882
- scanned_files: fileContents.size,
883
- ...(candidates.length >= MAX_DEAD_CODE_RESULTS || scanTruncated ? { truncated: true } : {}),
884
- };
885
- }
886
- // ---------------------------------------------------------------------------
887
- // Unused import detection
888
- // ---------------------------------------------------------------------------
889
- const MAX_UNUSED_IMPORTS = 200;
890
- /**
891
- * Find imports whose imported names are never referenced in the file body.
892
- * Supports ES module named imports: import { A, B } from '...'
4
+ * Deferred tool loaders and external consumers import this exact module path.
5
+ * Keep exports explicit so internal split helpers cannot accidentally become public.
893
6
  */
894
- export async function findUnusedImports(repo, options) {
895
- const index = await requireCodeIndex(repo);
896
- const includeTests = options?.include_tests ?? false;
897
- const unused = [];
898
- let scannedFiles = 0;
899
- for (const file of index.files) {
900
- if (unused.length >= MAX_UNUSED_IMPORTS)
901
- break;
902
- if (!includeTests && isTestFile(file.path))
903
- continue;
904
- if (options?.file_pattern && !file.path.includes(options.file_pattern))
905
- continue;
906
- // Only analyze JS/TS/Kotlin files
907
- if (!/\.(ts|tsx|js|jsx|mjs|kt|kts)$/.test(file.path))
908
- continue;
909
- let source;
910
- try {
911
- source = await readFile(join(index.root, file.path), "utf-8");
912
- }
913
- catch {
914
- continue;
915
- }
916
- scannedFiles++;
917
- const lines = source.split("\n");
918
- // Find named import lines: import { A, B, C } from '...'
919
- // Also: import A from '...' and import * as A from '...'
920
- const importRegex = /^import\s+(?:type\s+)?(?:\{([^}]+)\}|(\*\s+as\s+\w+)|(\w+)).*from\s+['"][^'"]+['"]/;
921
- for (let i = 0; i < lines.length; i++) {
922
- const line = lines[i].trim();
923
- if (!line.startsWith("import "))
924
- continue;
925
- // Stop scanning imports when we hit non-import code
926
- if (i > 0 && !line.startsWith("import") && !line.startsWith("//") && !line.startsWith("/*") && line.length > 0 && !lines[i].trim().startsWith("*") && !lines[i].trim().startsWith("}")) {
927
- // Could be multi-line import continuation, keep going
928
- }
929
- const match = importRegex.exec(line);
930
- if (!match)
931
- continue;
932
- const names = [];
933
- if (match[1]) {
934
- // Named imports: { A, B as C, type D }
935
- for (const part of match[1].split(",")) {
936
- const trimmed = part.trim().replace(/^type\s+/, "");
937
- if (!trimmed)
938
- continue;
939
- // Handle "A as B" — the local name is B
940
- const asMatch = /(\w+)\s+as\s+(\w+)/.exec(trimmed);
941
- names.push(asMatch ? asMatch[2] : trimmed);
942
- }
943
- }
944
- else if (match[2]) {
945
- // Namespace import: * as A
946
- const nsMatch = /\*\s+as\s+(\w+)/.exec(match[2]);
947
- if (nsMatch)
948
- names.push(nsMatch[1]);
949
- }
950
- else if (match[3]) {
951
- // Default import: import A
952
- names.push(match[3]);
953
- }
954
- // Check each imported name against rest of file
955
- const bodyAfterImports = lines.slice(i + 1).join("\n");
956
- for (const name of names) {
957
- if (name.length < 2)
958
- continue;
959
- const nameRegex = new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
960
- if (!nameRegex.test(bodyAfterImports)) {
961
- unused.push({
962
- file: file.path,
963
- line: i + 1,
964
- import_text: line,
965
- imported_name: name,
966
- });
967
- if (unused.length >= MAX_UNUSED_IMPORTS)
968
- break;
969
- }
970
- }
971
- }
972
- }
973
- return {
974
- unused,
975
- scanned_files: scannedFiles,
976
- ...(unused.length >= MAX_UNUSED_IMPORTS ? { truncated: true } : {}),
977
- };
978
- }
7
+ export { AmbiguousSymbolIdError, extractSymbolNameGuess, findSimilarSymbols, getSymbol, getSymbols, isAmbiguousSymbolIdError, resolveSymbolIdExact, } from "./symbol-lookup-tools.js";
8
+ export { findReferences, findReferencesBatch, } from "./symbol-reference-tools.js";
9
+ export { findAndShow, formatBundleCompact, formatRefsCompact, formatSymbolCompact, formatSymbolsCompact, getContextBundle, } from "./symbol-context-tools.js";
10
+ export { findDeadCode, findUnusedImports, } from "./symbol-analysis-tools.js";
979
11
  //# sourceMappingURL=symbol-tools.js.map