contextpro-mcp 0.0.0-stage → 1.4.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 (466) hide show
  1. package/CHANGELOG.md +416 -0
  2. package/INSTALL.md +128 -0
  3. package/INSTRUCTIONS.md +33 -0
  4. package/LICENSE +21 -0
  5. package/NOTICE +12 -0
  6. package/README.md +164 -2
  7. package/SECURITY.md +27 -0
  8. package/agent-guide.md +323 -0
  9. package/agent-instructions.md +1 -0
  10. package/build/core/agent-setup.d.ts +5 -0
  11. package/build/core/agent-setup.d.ts.map +1 -0
  12. package/build/core/agent-setup.js +94 -0
  13. package/build/core/agent-setup.js.map +1 -0
  14. package/build/core/artifacts.d.ts +64 -0
  15. package/build/core/artifacts.d.ts.map +1 -0
  16. package/build/core/artifacts.js +370 -0
  17. package/build/core/artifacts.js.map +1 -0
  18. package/build/core/bounded-source.d.ts +15 -0
  19. package/build/core/bounded-source.d.ts.map +1 -0
  20. package/build/core/bounded-source.js +78 -0
  21. package/build/core/bounded-source.js.map +1 -0
  22. package/build/core/changed-since.d.ts +20 -0
  23. package/build/core/changed-since.d.ts.map +1 -0
  24. package/build/core/changed-since.js +43 -0
  25. package/build/core/changed-since.js.map +1 -0
  26. package/build/core/chat-model.d.ts +8 -0
  27. package/build/core/chat-model.d.ts.map +1 -0
  28. package/build/core/chat-model.js +135 -0
  29. package/build/core/chat-model.js.map +1 -0
  30. package/build/core/clustering.d.ts +6 -0
  31. package/build/core/clustering.d.ts.map +1 -0
  32. package/build/core/clustering.js +201 -0
  33. package/build/core/clustering.js.map +1 -0
  34. package/build/core/context-metadata.d.ts +50 -0
  35. package/build/core/context-metadata.d.ts.map +1 -0
  36. package/build/core/context-metadata.js +118 -0
  37. package/build/core/context-metadata.js.map +1 -0
  38. package/build/core/data-dir.d.ts +5 -0
  39. package/build/core/data-dir.d.ts.map +1 -0
  40. package/build/core/data-dir.js +53 -0
  41. package/build/core/data-dir.js.map +1 -0
  42. package/build/core/db-native.d.ts +28 -0
  43. package/build/core/db-native.d.ts.map +1 -0
  44. package/build/core/db-native.js +120 -0
  45. package/build/core/db-native.js.map +1 -0
  46. package/build/core/db.d.ts +294 -0
  47. package/build/core/db.d.ts.map +1 -0
  48. package/build/core/db.js +1047 -0
  49. package/build/core/db.js.map +1 -0
  50. package/build/core/doctor.d.ts +13 -0
  51. package/build/core/doctor.d.ts.map +1 -0
  52. package/build/core/doctor.js +55 -0
  53. package/build/core/doctor.js.map +1 -0
  54. package/build/core/efficiency.d.ts +16 -0
  55. package/build/core/efficiency.d.ts.map +1 -0
  56. package/build/core/efficiency.js +170 -0
  57. package/build/core/efficiency.js.map +1 -0
  58. package/build/core/embedding-tracker.d.ts +25 -0
  59. package/build/core/embedding-tracker.d.ts.map +1 -0
  60. package/build/core/embedding-tracker.js +228 -0
  61. package/build/core/embedding-tracker.js.map +1 -0
  62. package/build/core/embeddings.d.ts +90 -0
  63. package/build/core/embeddings.d.ts.map +1 -0
  64. package/build/core/embeddings.js +693 -0
  65. package/build/core/embeddings.js.map +1 -0
  66. package/build/core/evidence-state.d.ts +42 -0
  67. package/build/core/evidence-state.d.ts.map +1 -0
  68. package/build/core/evidence-state.js +153 -0
  69. package/build/core/evidence-state.js.map +1 -0
  70. package/build/core/extractor-stamp.d.ts +10 -0
  71. package/build/core/extractor-stamp.d.ts.map +1 -0
  72. package/build/core/extractor-stamp.js +51 -0
  73. package/build/core/extractor-stamp.js.map +1 -0
  74. package/build/core/feature-brief-cache.d.ts +37 -0
  75. package/build/core/feature-brief-cache.d.ts.map +1 -0
  76. package/build/core/feature-brief-cache.js +100 -0
  77. package/build/core/feature-brief-cache.js.map +1 -0
  78. package/build/core/file-fingerprint.d.ts +15 -0
  79. package/build/core/file-fingerprint.d.ts.map +1 -0
  80. package/build/core/file-fingerprint.js +24 -0
  81. package/build/core/file-fingerprint.js.map +1 -0
  82. package/build/core/graph-analytics.d.ts +46 -0
  83. package/build/core/graph-analytics.d.ts.map +1 -0
  84. package/build/core/graph-analytics.js +371 -0
  85. package/build/core/graph-analytics.js.map +1 -0
  86. package/build/core/hub.d.ts +23 -0
  87. package/build/core/hub.d.ts.map +1 -0
  88. package/build/core/hub.js +123 -0
  89. package/build/core/hub.js.map +1 -0
  90. package/build/core/ignore-dirs.d.ts +7 -0
  91. package/build/core/ignore-dirs.d.ts.map +1 -0
  92. package/build/core/ignore-dirs.js +84 -0
  93. package/build/core/ignore-dirs.js.map +1 -0
  94. package/build/core/index-freshness.d.ts +15 -0
  95. package/build/core/index-freshness.d.ts.map +1 -0
  96. package/build/core/index-freshness.js +96 -0
  97. package/build/core/index-freshness.js.map +1 -0
  98. package/build/core/index-reconcile.d.ts +28 -0
  99. package/build/core/index-reconcile.d.ts.map +1 -0
  100. package/build/core/index-reconcile.js +129 -0
  101. package/build/core/index-reconcile.js.map +1 -0
  102. package/build/core/local-daemon.d.ts +5 -0
  103. package/build/core/local-daemon.d.ts.map +1 -0
  104. package/build/core/local-daemon.js +282 -0
  105. package/build/core/local-daemon.js.map +1 -0
  106. package/build/core/memory-graph.d.ts +68 -0
  107. package/build/core/memory-graph.d.ts.map +1 -0
  108. package/build/core/memory-graph.js +152 -0
  109. package/build/core/memory-graph.js.map +1 -0
  110. package/build/core/native-repair.d.ts +12 -0
  111. package/build/core/native-repair.d.ts.map +1 -0
  112. package/build/core/native-repair.js +167 -0
  113. package/build/core/native-repair.js.map +1 -0
  114. package/build/core/native-runtime.d.ts +12 -0
  115. package/build/core/native-runtime.d.ts.map +1 -0
  116. package/build/core/native-runtime.js +38 -0
  117. package/build/core/native-runtime.js.map +1 -0
  118. package/build/core/pagerank.d.ts +29 -0
  119. package/build/core/pagerank.d.ts.map +1 -0
  120. package/build/core/pagerank.js +90 -0
  121. package/build/core/pagerank.js.map +1 -0
  122. package/build/core/parser-process.d.ts +21 -0
  123. package/build/core/parser-process.d.ts.map +1 -0
  124. package/build/core/parser-process.js +103 -0
  125. package/build/core/parser-process.js.map +1 -0
  126. package/build/core/parser-worker.d.ts +2 -0
  127. package/build/core/parser-worker.d.ts.map +1 -0
  128. package/build/core/parser-worker.js +17 -0
  129. package/build/core/parser-worker.js.map +1 -0
  130. package/build/core/parser.d.ts +66 -0
  131. package/build/core/parser.d.ts.map +1 -0
  132. package/build/core/parser.js +750 -0
  133. package/build/core/parser.js.map +1 -0
  134. package/build/core/path-guard.d.ts +6 -0
  135. package/build/core/path-guard.d.ts.map +1 -0
  136. package/build/core/path-guard.js +55 -0
  137. package/build/core/path-guard.js.map +1 -0
  138. package/build/core/process-lifecycle.d.ts +30 -0
  139. package/build/core/process-lifecycle.d.ts.map +1 -0
  140. package/build/core/process-lifecycle.js +129 -0
  141. package/build/core/process-lifecycle.js.map +1 -0
  142. package/build/core/project-config.d.ts +83 -0
  143. package/build/core/project-config.d.ts.map +1 -0
  144. package/build/core/project-config.js +302 -0
  145. package/build/core/project-config.js.map +1 -0
  146. package/build/core/project-graph.d.ts +69 -0
  147. package/build/core/project-graph.d.ts.map +1 -0
  148. package/build/core/project-graph.js +874 -0
  149. package/build/core/project-graph.js.map +1 -0
  150. package/build/core/provider-config.d.ts +15 -0
  151. package/build/core/provider-config.d.ts.map +1 -0
  152. package/build/core/provider-config.js +67 -0
  153. package/build/core/provider-config.js.map +1 -0
  154. package/build/core/provider-usage.d.ts +21 -0
  155. package/build/core/provider-usage.d.ts.map +1 -0
  156. package/build/core/provider-usage.js +52 -0
  157. package/build/core/provider-usage.js.map +1 -0
  158. package/build/core/python-language-server.d.ts +23 -0
  159. package/build/core/python-language-server.d.ts.map +1 -0
  160. package/build/core/python-language-server.js +217 -0
  161. package/build/core/python-language-server.js.map +1 -0
  162. package/build/core/python-runtime-identity.d.ts +3 -0
  163. package/build/core/python-runtime-identity.d.ts.map +1 -0
  164. package/build/core/python-runtime-identity.js +53 -0
  165. package/build/core/python-runtime-identity.js.map +1 -0
  166. package/build/core/reconcile-scheduler.d.ts +20 -0
  167. package/build/core/reconcile-scheduler.d.ts.map +1 -0
  168. package/build/core/reconcile-scheduler.js +58 -0
  169. package/build/core/reconcile-scheduler.js.map +1 -0
  170. package/build/core/request-context.d.ts +7 -0
  171. package/build/core/request-context.d.ts.map +1 -0
  172. package/build/core/request-context.js +17 -0
  173. package/build/core/request-context.js.map +1 -0
  174. package/build/core/request-root.d.ts +19 -0
  175. package/build/core/request-root.d.ts.map +1 -0
  176. package/build/core/request-root.js +26 -0
  177. package/build/core/request-root.js.map +1 -0
  178. package/build/core/root-guard.d.ts +8 -0
  179. package/build/core/root-guard.d.ts.map +1 -0
  180. package/build/core/root-guard.js +53 -0
  181. package/build/core/root-guard.js.map +1 -0
  182. package/build/core/roots-detect.d.ts +17 -0
  183. package/build/core/roots-detect.d.ts.map +1 -0
  184. package/build/core/roots-detect.js +63 -0
  185. package/build/core/roots-detect.js.map +1 -0
  186. package/build/core/runtime-session.d.ts +5 -0
  187. package/build/core/runtime-session.d.ts.map +1 -0
  188. package/build/core/runtime-session.js +10 -0
  189. package/build/core/runtime-session.js.map +1 -0
  190. package/build/core/scip-index.d.ts +71 -0
  191. package/build/core/scip-index.d.ts.map +1 -0
  192. package/build/core/scip-index.js +343 -0
  193. package/build/core/scip-index.js.map +1 -0
  194. package/build/core/semantic-diff.d.ts +32 -0
  195. package/build/core/semantic-diff.d.ts.map +1 -0
  196. package/build/core/semantic-diff.js +259 -0
  197. package/build/core/semantic-diff.js.map +1 -0
  198. package/build/core/source-context.d.ts +3 -0
  199. package/build/core/source-context.d.ts.map +1 -0
  200. package/build/core/source-context.js +86 -0
  201. package/build/core/source-context.js.map +1 -0
  202. package/build/core/source-mask.d.ts +8 -0
  203. package/build/core/source-mask.d.ts.map +1 -0
  204. package/build/core/source-mask.js +156 -0
  205. package/build/core/source-mask.js.map +1 -0
  206. package/build/core/source-mutation.d.ts +16 -0
  207. package/build/core/source-mutation.d.ts.map +1 -0
  208. package/build/core/source-mutation.js +193 -0
  209. package/build/core/source-mutation.js.map +1 -0
  210. package/build/core/sql-schema.d.ts +59 -0
  211. package/build/core/sql-schema.d.ts.map +1 -0
  212. package/build/core/sql-schema.js +218 -0
  213. package/build/core/sql-schema.js.map +1 -0
  214. package/build/core/startup-health.d.ts +40 -0
  215. package/build/core/startup-health.d.ts.map +1 -0
  216. package/build/core/startup-health.js +132 -0
  217. package/build/core/startup-health.js.map +1 -0
  218. package/build/core/team-ledger.d.ts +60 -0
  219. package/build/core/team-ledger.d.ts.map +1 -0
  220. package/build/core/team-ledger.js +171 -0
  221. package/build/core/team-ledger.js.map +1 -0
  222. package/build/core/test-impact.d.ts +23 -0
  223. package/build/core/test-impact.d.ts.map +1 -0
  224. package/build/core/test-impact.js +131 -0
  225. package/build/core/test-impact.js.map +1 -0
  226. package/build/core/tool-metrics.d.ts +29 -0
  227. package/build/core/tool-metrics.d.ts.map +1 -0
  228. package/build/core/tool-metrics.js +74 -0
  229. package/build/core/tool-metrics.js.map +1 -0
  230. package/build/core/tool-profile.d.ts +12 -0
  231. package/build/core/tool-profile.d.ts.map +1 -0
  232. package/build/core/tool-profile.js +102 -0
  233. package/build/core/tool-profile.js.map +1 -0
  234. package/build/core/tool-trace.d.ts +8 -0
  235. package/build/core/tool-trace.d.ts.map +1 -0
  236. package/build/core/tool-trace.js +70 -0
  237. package/build/core/tool-trace.js.map +1 -0
  238. package/build/core/tree-sitter-runtime.d.ts +20 -0
  239. package/build/core/tree-sitter-runtime.d.ts.map +1 -0
  240. package/build/core/tree-sitter-runtime.js +324 -0
  241. package/build/core/tree-sitter-runtime.js.map +1 -0
  242. package/build/core/tree-sitter.d.ts +6 -0
  243. package/build/core/tree-sitter.d.ts.map +1 -0
  244. package/build/core/tree-sitter.js +24 -0
  245. package/build/core/tree-sitter.js.map +1 -0
  246. package/build/core/typescript-reference-process.d.ts +30 -0
  247. package/build/core/typescript-reference-process.d.ts.map +1 -0
  248. package/build/core/typescript-reference-process.js +124 -0
  249. package/build/core/typescript-reference-process.js.map +1 -0
  250. package/build/core/typescript-reference-worker.d.ts +2 -0
  251. package/build/core/typescript-reference-worker.d.ts.map +1 -0
  252. package/build/core/typescript-reference-worker.js +14 -0
  253. package/build/core/typescript-reference-worker.js.map +1 -0
  254. package/build/core/typescript-references.d.ts +71 -0
  255. package/build/core/typescript-references.d.ts.map +1 -0
  256. package/build/core/typescript-references.js +392 -0
  257. package/build/core/typescript-references.js.map +1 -0
  258. package/build/core/typescript-skeleton.d.ts +5 -0
  259. package/build/core/typescript-skeleton.d.ts.map +1 -0
  260. package/build/core/typescript-skeleton.js +49 -0
  261. package/build/core/typescript-skeleton.js.map +1 -0
  262. package/build/core/walker.d.ts +16 -0
  263. package/build/core/walker.d.ts.map +1 -0
  264. package/build/core/walker.js +152 -0
  265. package/build/core/walker.js.map +1 -0
  266. package/build/core/workspace-router.d.ts +28 -0
  267. package/build/core/workspace-router.d.ts.map +1 -0
  268. package/build/core/workspace-router.js +93 -0
  269. package/build/core/workspace-router.js.map +1 -0
  270. package/build/core/worktree-gc.d.ts +16 -0
  271. package/build/core/worktree-gc.d.ts.map +1 -0
  272. package/build/core/worktree-gc.js +69 -0
  273. package/build/core/worktree-gc.js.map +1 -0
  274. package/build/core/worktree-overlay.d.ts +22 -0
  275. package/build/core/worktree-overlay.d.ts.map +1 -0
  276. package/build/core/worktree-overlay.js +84 -0
  277. package/build/core/worktree-overlay.js.map +1 -0
  278. package/build/core/worktree-root-guard.d.ts +8 -0
  279. package/build/core/worktree-root-guard.d.ts.map +1 -0
  280. package/build/core/worktree-root-guard.js +82 -0
  281. package/build/core/worktree-root-guard.js.map +1 -0
  282. package/build/core/worktree-seed.d.ts +14 -0
  283. package/build/core/worktree-seed.d.ts.map +1 -0
  284. package/build/core/worktree-seed.js +98 -0
  285. package/build/core/worktree-seed.js.map +1 -0
  286. package/build/git/shadow.d.ts +40 -0
  287. package/build/git/shadow.d.ts.map +1 -0
  288. package/build/git/shadow.js +298 -0
  289. package/build/git/shadow.js.map +1 -0
  290. package/build/index.d.ts +3 -0
  291. package/build/index.d.ts.map +1 -0
  292. package/build/index.js +599 -0
  293. package/build/index.js.map +1 -0
  294. package/build/tools/agentic-context.d.ts +86 -0
  295. package/build/tools/agentic-context.d.ts.map +1 -0
  296. package/build/tools/agentic-context.js +1546 -0
  297. package/build/tools/agentic-context.js.map +1 -0
  298. package/build/tools/blast-radius.d.ts +24 -0
  299. package/build/tools/blast-radius.d.ts.map +1 -0
  300. package/build/tools/blast-radius.js +231 -0
  301. package/build/tools/blast-radius.js.map +1 -0
  302. package/build/tools/changed-since.d.ts +7 -0
  303. package/build/tools/changed-since.d.ts.map +1 -0
  304. package/build/tools/changed-since.js +68 -0
  305. package/build/tools/changed-since.js.map +1 -0
  306. package/build/tools/compiler-actions.d.ts +26 -0
  307. package/build/tools/compiler-actions.d.ts.map +1 -0
  308. package/build/tools/compiler-actions.js +121 -0
  309. package/build/tools/compiler-actions.js.map +1 -0
  310. package/build/tools/context-tree.d.ts +9 -0
  311. package/build/tools/context-tree.d.ts.map +1 -0
  312. package/build/tools/context-tree.js +131 -0
  313. package/build/tools/context-tree.js.map +1 -0
  314. package/build/tools/context.d.ts +37 -0
  315. package/build/tools/context.d.ts.map +1 -0
  316. package/build/tools/context.js +800 -0
  317. package/build/tools/context.js.map +1 -0
  318. package/build/tools/diff.d.ts +9 -0
  319. package/build/tools/diff.d.ts.map +1 -0
  320. package/build/tools/diff.js +176 -0
  321. package/build/tools/diff.js.map +1 -0
  322. package/build/tools/directory-prior.d.ts +16 -0
  323. package/build/tools/directory-prior.d.ts.map +1 -0
  324. package/build/tools/directory-prior.js +121 -0
  325. package/build/tools/directory-prior.js.map +1 -0
  326. package/build/tools/discovery-documents.d.ts +11 -0
  327. package/build/tools/discovery-documents.d.ts.map +1 -0
  328. package/build/tools/discovery-documents.js +71 -0
  329. package/build/tools/discovery-documents.js.map +1 -0
  330. package/build/tools/discovery-hints.d.ts +25 -0
  331. package/build/tools/discovery-hints.d.ts.map +1 -0
  332. package/build/tools/discovery-hints.js +329 -0
  333. package/build/tools/discovery-hints.js.map +1 -0
  334. package/build/tools/efficiency-report.d.ts +13 -0
  335. package/build/tools/efficiency-report.d.ts.map +1 -0
  336. package/build/tools/efficiency-report.js +78 -0
  337. package/build/tools/efficiency-report.js.map +1 -0
  338. package/build/tools/evidence-retrieval.d.ts +33 -0
  339. package/build/tools/evidence-retrieval.d.ts.map +1 -0
  340. package/build/tools/evidence-retrieval.js +200 -0
  341. package/build/tools/evidence-retrieval.js.map +1 -0
  342. package/build/tools/exact-references.d.ts +10 -0
  343. package/build/tools/exact-references.d.ts.map +1 -0
  344. package/build/tools/exact-references.js +349 -0
  345. package/build/tools/exact-references.js.map +1 -0
  346. package/build/tools/explain.d.ts +14 -0
  347. package/build/tools/explain.d.ts.map +1 -0
  348. package/build/tools/explain.js +370 -0
  349. package/build/tools/explain.js.map +1 -0
  350. package/build/tools/feature-brief.d.ts +7 -0
  351. package/build/tools/feature-brief.d.ts.map +1 -0
  352. package/build/tools/feature-brief.js +89 -0
  353. package/build/tools/feature-brief.js.map +1 -0
  354. package/build/tools/feature-hub.d.ts +15 -0
  355. package/build/tools/feature-hub.d.ts.map +1 -0
  356. package/build/tools/feature-hub.js +404 -0
  357. package/build/tools/feature-hub.js.map +1 -0
  358. package/build/tools/file-skeleton.d.ts +7 -0
  359. package/build/tools/file-skeleton.d.ts.map +1 -0
  360. package/build/tools/file-skeleton.js +190 -0
  361. package/build/tools/file-skeleton.js.map +1 -0
  362. package/build/tools/grep.d.ts +25 -0
  363. package/build/tools/grep.d.ts.map +1 -0
  364. package/build/tools/grep.js +341 -0
  365. package/build/tools/grep.js.map +1 -0
  366. package/build/tools/impact-delta.d.ts +7 -0
  367. package/build/tools/impact-delta.d.ts.map +1 -0
  368. package/build/tools/impact-delta.js +102 -0
  369. package/build/tools/impact-delta.js.map +1 -0
  370. package/build/tools/memory-tools.d.ts +69 -0
  371. package/build/tools/memory-tools.d.ts.map +1 -0
  372. package/build/tools/memory-tools.js +366 -0
  373. package/build/tools/memory-tools.js.map +1 -0
  374. package/build/tools/planning-helpers.d.ts +26 -0
  375. package/build/tools/planning-helpers.d.ts.map +1 -0
  376. package/build/tools/planning-helpers.js +269 -0
  377. package/build/tools/planning-helpers.js.map +1 -0
  378. package/build/tools/project-graph.d.ts +19 -0
  379. package/build/tools/project-graph.d.ts.map +1 -0
  380. package/build/tools/project-graph.js +259 -0
  381. package/build/tools/project-graph.js.map +1 -0
  382. package/build/tools/propose-commit.d.ts +9 -0
  383. package/build/tools/propose-commit.d.ts.map +1 -0
  384. package/build/tools/propose-commit.js +156 -0
  385. package/build/tools/propose-commit.js.map +1 -0
  386. package/build/tools/register-tools.d.ts +18 -0
  387. package/build/tools/register-tools.d.ts.map +1 -0
  388. package/build/tools/register-tools.js +1131 -0
  389. package/build/tools/register-tools.js.map +1 -0
  390. package/build/tools/reindex.d.ts +76 -0
  391. package/build/tools/reindex.d.ts.map +1 -0
  392. package/build/tools/reindex.js +871 -0
  393. package/build/tools/reindex.js.map +1 -0
  394. package/build/tools/related.d.ts +6 -0
  395. package/build/tools/related.d.ts.map +1 -0
  396. package/build/tools/related.js +143 -0
  397. package/build/tools/related.js.map +1 -0
  398. package/build/tools/repo-map.d.ts +59 -0
  399. package/build/tools/repo-map.d.ts.map +1 -0
  400. package/build/tools/repo-map.js +270 -0
  401. package/build/tools/repo-map.js.map +1 -0
  402. package/build/tools/resolve-symbol.d.ts +41 -0
  403. package/build/tools/resolve-symbol.d.ts.map +1 -0
  404. package/build/tools/resolve-symbol.js +250 -0
  405. package/build/tools/resolve-symbol.js.map +1 -0
  406. package/build/tools/retrieval-helpers.d.ts +35 -0
  407. package/build/tools/retrieval-helpers.d.ts.map +1 -0
  408. package/build/tools/retrieval-helpers.js +302 -0
  409. package/build/tools/retrieval-helpers.js.map +1 -0
  410. package/build/tools/scip-index.d.ts +12 -0
  411. package/build/tools/scip-index.d.ts.map +1 -0
  412. package/build/tools/scip-index.js +66 -0
  413. package/build/tools/scip-index.js.map +1 -0
  414. package/build/tools/scoped-discovery.d.ts +7 -0
  415. package/build/tools/scoped-discovery.d.ts.map +1 -0
  416. package/build/tools/scoped-discovery.js +89 -0
  417. package/build/tools/scoped-discovery.js.map +1 -0
  418. package/build/tools/search.d.ts +62 -0
  419. package/build/tools/search.d.ts.map +1 -0
  420. package/build/tools/search.js +419 -0
  421. package/build/tools/search.js.map +1 -0
  422. package/build/tools/semantic-diff.d.ts +7 -0
  423. package/build/tools/semantic-diff.d.ts.map +1 -0
  424. package/build/tools/semantic-diff.js +45 -0
  425. package/build/tools/semantic-diff.js.map +1 -0
  426. package/build/tools/semantic-identifiers.d.ts +51 -0
  427. package/build/tools/semantic-identifiers.d.ts.map +1 -0
  428. package/build/tools/semantic-identifiers.js +522 -0
  429. package/build/tools/semantic-identifiers.js.map +1 -0
  430. package/build/tools/semantic-navigate.d.ts +18 -0
  431. package/build/tools/semantic-navigate.d.ts.map +1 -0
  432. package/build/tools/semantic-navigate.js +413 -0
  433. package/build/tools/semantic-navigate.js.map +1 -0
  434. package/build/tools/semantic-search.d.ts +30 -0
  435. package/build/tools/semantic-search.d.ts.map +1 -0
  436. package/build/tools/semantic-search.js +466 -0
  437. package/build/tools/semantic-search.js.map +1 -0
  438. package/build/tools/sql-schema.d.ts +23 -0
  439. package/build/tools/sql-schema.d.ts.map +1 -0
  440. package/build/tools/sql-schema.js +155 -0
  441. package/build/tools/sql-schema.js.map +1 -0
  442. package/build/tools/static-analysis.d.ts +7 -0
  443. package/build/tools/static-analysis.d.ts.map +1 -0
  444. package/build/tools/static-analysis.js +331 -0
  445. package/build/tools/static-analysis.js.map +1 -0
  446. package/build/tools/status.d.ts +74 -0
  447. package/build/tools/status.d.ts.map +1 -0
  448. package/build/tools/status.js +227 -0
  449. package/build/tools/status.js.map +1 -0
  450. package/build/tools/symbolic-edit.d.ts +57 -0
  451. package/build/tools/symbolic-edit.d.ts.map +1 -0
  452. package/build/tools/symbolic-edit.js +500 -0
  453. package/build/tools/symbolic-edit.js.map +1 -0
  454. package/build/tools/test-impact.d.ts +7 -0
  455. package/build/tools/test-impact.d.ts.map +1 -0
  456. package/build/tools/test-impact.js +34 -0
  457. package/build/tools/test-impact.js.map +1 -0
  458. package/build/tools/test-map.d.ts +8 -0
  459. package/build/tools/test-map.d.ts.map +1 -0
  460. package/build/tools/test-map.js +75 -0
  461. package/build/tools/test-map.js.map +1 -0
  462. package/docs/README.md +26 -0
  463. package/docs/architecture.md +35 -0
  464. package/docs/configuration.md +178 -0
  465. package/docs/maintenance.md +77 -0
  466. package/package.json +80 -4
@@ -0,0 +1,41 @@
1
+ import { type FreshnessMetadata, type TrustMetadata } from "../core/context-metadata.js";
2
+ export interface ResolveSymbolOptions {
3
+ rootDir: string;
4
+ symbolName: string;
5
+ fileContext?: string;
6
+ kind?: string;
7
+ limit?: number;
8
+ format?: "text" | "json";
9
+ }
10
+ export interface ResolvedSymbolCandidate {
11
+ name: string;
12
+ kind: string;
13
+ path: string;
14
+ line: number;
15
+ endLine: number | null;
16
+ signature: string | null;
17
+ parentName: string | null;
18
+ score: number;
19
+ reasons: string[];
20
+ }
21
+ export interface ResolveSymbolData {
22
+ repo: {
23
+ root: string;
24
+ fileContext: string | null;
25
+ projectId: string | null;
26
+ clientId: string | null;
27
+ fingerprint: string | null;
28
+ };
29
+ query: {
30
+ symbolName: string;
31
+ kind: string | null;
32
+ };
33
+ freshness: FreshnessMetadata;
34
+ trust: TrustMetadata;
35
+ bestMatch: ResolvedSymbolCandidate | null;
36
+ ambiguous: boolean;
37
+ candidates: ResolvedSymbolCandidate[];
38
+ }
39
+ export declare function resolveSymbolData(options: ResolveSymbolOptions): Promise<ResolveSymbolData>;
40
+ export declare function resolveSymbol(options: ResolveSymbolOptions): Promise<string>;
41
+ //# sourceMappingURL=resolve-symbol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-symbol.d.ts","sourceRoot":"","sources":["../../src/tools/resolve-symbol.ts"],"names":[],"mappings":"AAOA,OAAO,EAA6D,KAAK,iBAAiB,EAAE,KAAK,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AAiB,CAAC,CAgIjG;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlF"}
@@ -0,0 +1,250 @@
1
+ // Symbol resolution with ambiguity scoring and file-context-aware ranking
2
+ // FEATURE: ResolveSymbol — precise definition lookup for ambiguous identifiers
3
+ import { dirname, resolve } from "path";
4
+ import { getDB } from "../core/db.js";
5
+ import { loadProjectConfig } from "../core/project-config.js";
6
+ import { persistArtifact } from "../core/artifacts.js";
7
+ import { buildFreshnessMetadata, buildTrustMetadata, getIndexState } from "../core/context-metadata.js";
8
+ function nameSegments(name) {
9
+ // Split camelCase and snake_case into lowercase word segments.
10
+ return name
11
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
12
+ .replace(/[_-]+/g, " ")
13
+ .toLowerCase()
14
+ .split(/\s+/)
15
+ .filter(Boolean);
16
+ }
17
+ function isLikelyTestPath(path) {
18
+ return /(^|\/)(tests?|__tests__|spec)\//.test(path)
19
+ || /\.(test|spec|demo)\./.test(path)
20
+ || /(^|\/)test_[^/]+\.py$/.test(path)
21
+ || /_test\.go$/.test(path);
22
+ }
23
+ function scoreSymbolCandidate(input) {
24
+ let score = 0;
25
+ const reasons = [];
26
+ const exactMatch = input.symbol.name === input.symbolName;
27
+ const normalizedQuery = input.symbolName.toLowerCase();
28
+ const normalizedName = input.symbol.name.toLowerCase();
29
+ const querySegments = nameSegments(input.symbolName);
30
+ const nameSegs = nameSegments(input.symbol.name);
31
+ if (exactMatch) {
32
+ score += 100;
33
+ reasons.push("exact name match");
34
+ }
35
+ else if (normalizedName === normalizedQuery) {
36
+ score += 90;
37
+ reasons.push("case-insensitive exact name match");
38
+ }
39
+ else if (querySegments.length > 0 && querySegments.every((seg) => nameSegs.includes(seg))) {
40
+ // All query word-segments are present as whole words in the symbol name.
41
+ // e.g. "fee model" matches "FeeModel"; "run" matches "run_scanner" but NOT "drunk".
42
+ score += 55;
43
+ reasons.push("word-boundary segment match");
44
+ }
45
+ else if (nameSegs.includes(normalizedQuery)) {
46
+ // The whole query is one of the symbol's word segments. This is what kills the
47
+ // fee-in-feed substring collision: "fee" is NOT a segment of "run_venue_a_feed".
48
+ score += 50;
49
+ reasons.push("matches a whole word segment");
50
+ }
51
+ else if (normalizedName.includes(normalizedQuery)) {
52
+ // Pure substring — lowest tier, and only counts when the query is reasonably long
53
+ // so 2-3 char queries don't spray across unrelated names.
54
+ score += normalizedQuery.length >= 4 ? 20 : 8;
55
+ reasons.push("partial (substring) name match");
56
+ }
57
+ if (input.expectedKind && input.symbol.kind === input.expectedKind) {
58
+ score += 35;
59
+ reasons.push(`kind match (${input.expectedKind})`);
60
+ }
61
+ else if (input.expectedKind && input.symbol.kind !== input.expectedKind) {
62
+ score -= 15;
63
+ reasons.push(`kind mismatch (${input.symbol.kind})`);
64
+ }
65
+ if (input.fileContext && input.file.path === input.fileContext) {
66
+ score += 40;
67
+ reasons.push("same file as file_context");
68
+ }
69
+ if (input.importedFileIds.has(input.file.id)) {
70
+ score += 30;
71
+ reasons.push("definition is in a directly imported file");
72
+ }
73
+ if (input.fileContext && dirname(input.file.path) === dirname(input.fileContext)) {
74
+ score += 10;
75
+ reasons.push("same directory as file_context");
76
+ }
77
+ if (input.symbol.parent_symbol_id !== null) {
78
+ score += 5;
79
+ reasons.push("nested/member definition");
80
+ }
81
+ // Tie-breakers when file_context is absent: prefer non-test, well-imported definitions.
82
+ if (isLikelyTestPath(input.file.path)) {
83
+ score -= 6;
84
+ reasons.push("in a test file (de-prioritized)");
85
+ }
86
+ if (input.importerCount > 0) {
87
+ const bump = Math.min(8, input.importerCount);
88
+ score += bump;
89
+ reasons.push(`${input.importerCount} importer(s)`);
90
+ }
91
+ return { score, reasons };
92
+ }
93
+ function resolveParentName(symbol, siblings) {
94
+ if (symbol.parent_symbol_id === null)
95
+ return null;
96
+ return siblings.find((candidate) => candidate.id === symbol.parent_symbol_id)?.name ?? null;
97
+ }
98
+ export async function resolveSymbolData(options) {
99
+ const [db, config, indexState] = await Promise.all([
100
+ getDB(options.rootDir),
101
+ loadProjectConfig(options.rootDir),
102
+ getIndexState(options.rootDir),
103
+ ]);
104
+ const allFiles = db.getAllFiles();
105
+ const filesById = new Map(allFiles.map((file) => [file.id, file]));
106
+ const currentFile = options.fileContext ? db.getFile(options.fileContext) : null;
107
+ const importedFileIds = new Set();
108
+ if (currentFile) {
109
+ for (const imp of db.getImportsFrom(currentFile.id)) {
110
+ if (imp.target_file_id !== null)
111
+ importedFileIds.add(imp.target_file_id);
112
+ }
113
+ }
114
+ const rawMatches = db.searchSymbolsByName(options.symbolName);
115
+ const exactMatches = rawMatches.filter((symbol) => symbol.name === options.symbolName);
116
+ const candidateRows = exactMatches.length > 0 ? exactMatches : rawMatches;
117
+ const ranked = candidateRows
118
+ .map((symbol) => {
119
+ const file = filesById.get(symbol.file_id);
120
+ if (!file)
121
+ return null;
122
+ const siblings = db.getSymbolsByFile(file.id);
123
+ const importerCount = db.getImportersOf(file.id).length;
124
+ const { score, reasons } = scoreSymbolCandidate({
125
+ symbolName: options.symbolName,
126
+ expectedKind: options.kind,
127
+ symbol,
128
+ file,
129
+ fileContext: options.fileContext,
130
+ importedFileIds,
131
+ importerCount,
132
+ });
133
+ const candidate = {
134
+ name: symbol.name,
135
+ kind: symbol.kind,
136
+ path: file.path,
137
+ line: symbol.line_start,
138
+ endLine: symbol.line_end,
139
+ signature: symbol.signature,
140
+ parentName: resolveParentName(symbol, siblings),
141
+ score,
142
+ reasons,
143
+ };
144
+ return candidate;
145
+ })
146
+ .filter((candidate) => candidate !== null)
147
+ .sort((left, right) => right.score - left.score || left.path.localeCompare(right.path) || left.line - right.line);
148
+ const limited = ranked.slice(0, options.limit ?? 8);
149
+ const bestMatch = limited[0] ?? null;
150
+ const ambiguous = limited.length > 1 && bestMatch !== null && (bestMatch.score - limited[1].score) < 20;
151
+ const freshness = buildFreshnessMetadata(indexState, {
152
+ staleCount: 0,
153
+ refreshed: false,
154
+ warning: indexState.state === "empty"
155
+ ? "Index is empty. Run reindex before resolving symbols."
156
+ : indexState.state === "indexing"
157
+ ? "Indexing is still in progress. Wait for completion before trusting symbol resolution."
158
+ : indexState.state === "stale"
159
+ ? "Index is stale relative to the workspace. Run reindex before trusting symbol resolution."
160
+ : null,
161
+ });
162
+ const evidence = [
163
+ ...(bestMatch ? [`best candidate ${bestMatch.path}:L${bestMatch.line}`] : []),
164
+ ...(currentFile ? [`file context ${currentFile.path}`] : []),
165
+ ...(importedFileIds.size > 0 ? [`${importedFileIds.size} directly imported files considered`] : []),
166
+ ];
167
+ const ambiguities = [
168
+ ...(limited.length === 0 ? ["no symbol candidates found"] : []),
169
+ ...(ambiguous ? ["top symbol candidates are close in score"] : []),
170
+ ];
171
+ const partial = {
172
+ repo: {
173
+ root: resolve(options.rootDir),
174
+ fileContext: options.fileContext ?? null,
175
+ projectId: config?.projectId ?? null,
176
+ clientId: config?.clientId ?? null,
177
+ fingerprint: config?.repoFingerprint ?? null,
178
+ },
179
+ query: {
180
+ symbolName: options.symbolName,
181
+ kind: options.kind ?? null,
182
+ },
183
+ freshness,
184
+ trust: buildTrustMetadata({
185
+ baseConfidence: bestMatch ? (ambiguous ? 0.62 : 0.84) : 0.24,
186
+ freshness,
187
+ evidence,
188
+ ambiguities,
189
+ artifact: null,
190
+ }),
191
+ bestMatch,
192
+ ambiguous,
193
+ candidates: limited,
194
+ };
195
+ const artifact = await persistArtifact({
196
+ rootDir: options.rootDir,
197
+ kind: "resolve_symbol",
198
+ key: JSON.stringify({
199
+ symbolName: options.symbolName,
200
+ fileContext: options.fileContext ?? null,
201
+ kind: options.kind ?? null,
202
+ limit: options.limit ?? 8,
203
+ }),
204
+ repoFingerprint: partial.repo.fingerprint,
205
+ projectId: partial.repo.projectId,
206
+ clientId: partial.repo.clientId,
207
+ metadata: {
208
+ symbolName: options.symbolName,
209
+ kind: options.kind ?? "",
210
+ },
211
+ payload: partial,
212
+ });
213
+ return {
214
+ ...partial,
215
+ trust: buildTrustMetadata({
216
+ baseConfidence: bestMatch ? (ambiguous ? 0.62 : 0.84) : 0.24,
217
+ freshness,
218
+ evidence,
219
+ ambiguities,
220
+ artifact,
221
+ }),
222
+ };
223
+ }
224
+ export async function resolveSymbol(options) {
225
+ const data = await resolveSymbolData(options);
226
+ if (options.format === "json") {
227
+ return JSON.stringify(data, null, 2);
228
+ }
229
+ if (data.candidates.length === 0) {
230
+ return `No symbol matches found for "${options.symbolName}".`;
231
+ }
232
+ const lines = [
233
+ `=== Resolve Symbol: ${options.symbolName} ===`,
234
+ `File Context: ${data.repo.fileContext ?? "none"}`,
235
+ `Ambiguous: ${data.ambiguous ? "yes" : "no"}`,
236
+ data.trust.artifact ? `Artifact: ${data.trust.artifact.id}` : "",
237
+ "",
238
+ ].filter(Boolean);
239
+ for (const candidate of data.candidates) {
240
+ lines.push(`${candidate.kind}: ${candidate.path} L${candidate.line}${candidate.endLine && candidate.endLine > candidate.line ? `-L${candidate.endLine}` : ""}`);
241
+ if (candidate.signature)
242
+ lines.push(` ${candidate.signature}`);
243
+ if (candidate.parentName)
244
+ lines.push(` parent: ${candidate.parentName}`);
245
+ lines.push(` score: ${candidate.score} | ${candidate.reasons.join(", ")}`);
246
+ lines.push("");
247
+ }
248
+ return lines.join("\n");
249
+ }
250
+ //# sourceMappingURL=resolve-symbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-symbol.js","sourceRoot":"","sources":["../../src/tools/resolve-symbol.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+EAA+E;AAE/E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,KAAK,EAAgC,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAA8C,MAAM,6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CAAC"}
@@ -0,0 +1,35 @@
1
+ export declare function unique<T>(items: T[]): T[];
2
+ export declare function parseMetadata(raw: string): Record<string, string>;
3
+ export declare function parseJsonArray(raw: string | null): string[];
4
+ export declare function isTestFile(path: string): boolean;
5
+ export declare function isTestEvidence(path: string): boolean;
6
+ export declare function findTestsForFiles(rootDir: string, files: string[]): Promise<Array<{
7
+ path: string;
8
+ reason: string;
9
+ score: number;
10
+ }>>;
11
+ export declare function getRecentDiffSummary(rootDir: string, filePath: string): Promise<{
12
+ path: string;
13
+ commit: string;
14
+ summary: string;
15
+ } | null>;
16
+ export declare function getProjectMemoryHits(rootDir: string, query: string, topK: number, keywordOnly?: boolean): Promise<Array<{
17
+ id: string;
18
+ kind: string;
19
+ summary: string;
20
+ }>>;
21
+ /** Bounded lexical risk lookup; never pay for embeddings on the context path. */
22
+ export declare function getProjectRiskEvidence(rootDir: string, query: string): Promise<Array<{
23
+ id: string;
24
+ risks: string[];
25
+ }>>;
26
+ export declare function resolveFilesFromSymbols(rootDir: string, symbols: string[] | undefined): Promise<string[]>;
27
+ export declare function findTextDependents(rootDir: string, filePath: string, symbolNames?: string[]): Promise<string[]>;
28
+ export declare function scanExactMentions(rootDir: string, candidateFiles: string[], symbolNames: string[]): Promise<string[]>;
29
+ export declare function fileRisk(rootDir: string, filePath: string): Promise<{
30
+ importers: number;
31
+ imports: number;
32
+ churn: number;
33
+ }>;
34
+ export declare function hubMatchesForFiles(rootDir: string, filePaths: string[]): Promise<string[]>;
35
+ //# sourceMappingURL=retrieval-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieval-helpers.d.ts","sourceRoot":"","sources":["../../src/tools/retrieval-helpers.ts"],"names":[],"mappings":"AAiBA,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEzC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAA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MAAM,EAAE,CAAC,CAa/G;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwBzH;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAU3H;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAehI;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAWhG"}
@@ -0,0 +1,302 @@
1
+ // Shared retrieval utilities: test discovery, diff summaries, memory hits, import resolution
2
+ // FEATURE: Helper layer for agentic-context — query-independent data fetching functions
3
+ import { execFile } from "child_process";
4
+ import { memoryEvidenceStatus } from "../core/evidence-state.js";
5
+ import { promisify } from "util";
6
+ import { readFile } from "fs/promises";
7
+ import { basename } from "path";
8
+ import { fetchQueryEmbedding, hasCompatibleEmbeddingModel } from "../core/embeddings.js";
9
+ import { getDB } from "../core/db.js";
10
+ import { loadProjectConfig } from "../core/project-config.js";
11
+ import { discoverHubs, parseHubFile } from "../core/hub.js";
12
+ import { walkDirectory } from "../core/walker.js";
13
+ import { resolveProjectPath } from "../core/path-guard.js";
14
+ const execFileAsync = promisify(execFile);
15
+ export function unique(items) {
16
+ return Array.from(new Set(items));
17
+ }
18
+ export function parseMetadata(raw) {
19
+ try {
20
+ const parsed = JSON.parse(raw);
21
+ if (!parsed || typeof parsed !== "object")
22
+ return {};
23
+ return Object.fromEntries(Object.entries(parsed).map(([key, value]) => [key, String(value)]));
24
+ }
25
+ catch {
26
+ return {};
27
+ }
28
+ }
29
+ export function parseJsonArray(raw) {
30
+ if (!raw)
31
+ return [];
32
+ try {
33
+ const parsed = JSON.parse(raw);
34
+ return Array.isArray(parsed) ? parsed.map((value) => String(value)) : [];
35
+ }
36
+ catch {
37
+ return [];
38
+ }
39
+ }
40
+ export function isTestFile(path) {
41
+ const name = basename(path).toLowerCase();
42
+ return /\.(?:test|spec|demo|smoke)\.\w+$/.test(path)
43
+ || /^test_[^/]+\.py$/.test(name)
44
+ || /_test\.py$/.test(name);
45
+ }
46
+ // Helpers are test evidence, but test selection must traverse them to runnable tests.
47
+ export function isTestEvidence(path) {
48
+ return isTestFile(path) || /(?:^|\/)(?:tests?|__tests__)\/.*\.(?:[cm]?[jt]sx?|py)$/i.test(path);
49
+ }
50
+ function baseNameWithoutTestAffixes(path) {
51
+ const base = path.replace(/\.\w+$/, "").split("/").pop() ?? "";
52
+ return base
53
+ .replace(/\.(test|spec|demo)$/i, "")
54
+ .replace(/^test_/i, "")
55
+ .replace(/_test$/i, "");
56
+ }
57
+ async function findConventionTests(rootDir, sourceFile, allFiles) {
58
+ const base = baseNameWithoutTestAffixes(sourceFile);
59
+ return allFiles.filter((file) => {
60
+ if (!isTestFile(file))
61
+ return false;
62
+ const testBase = baseNameWithoutTestAffixes(file);
63
+ return testBase === base;
64
+ });
65
+ }
66
+ async function findImporterTests(rootDir, file, maxDepth) {
67
+ const db = await getDB(rootDir);
68
+ const target = db.getFile(file);
69
+ if (!target)
70
+ return [];
71
+ const indexedFiles = db.getAllFiles();
72
+ const fileById = new Map(indexedFiles.map((candidate) => [candidate.id, candidate]));
73
+ const queue = [{ fileId: target.id, via: [file], depth: 0 }];
74
+ const visited = new Set([target.id]);
75
+ const results = [];
76
+ while (queue.length > 0) {
77
+ const current = queue.shift();
78
+ if (current.depth >= maxDepth)
79
+ continue;
80
+ for (const importer of db.getImportersOf(current.fileId)) {
81
+ const source = fileById.get(importer.source_file_id);
82
+ if (!source || visited.has(source.id))
83
+ continue;
84
+ visited.add(source.id);
85
+ const path = source.path;
86
+ const via = [...current.via, path];
87
+ const depth = current.depth + 1;
88
+ if (isTestFile(path)) {
89
+ results.push({
90
+ path,
91
+ reason: depth === 1 ? "Imports target module" : `Imports dependent chain: ${via.join(" <- ")}`,
92
+ score: Math.max(0.68, 0.9 - depth * 0.08),
93
+ });
94
+ continue;
95
+ }
96
+ queue.push({ fileId: source.id, via, depth });
97
+ }
98
+ }
99
+ return results;
100
+ }
101
+ export async function findTestsForFiles(rootDir, files) {
102
+ const entries = await walkDirectory({ rootDir, depthLimit: 0 });
103
+ const allFiles = entries.filter((entry) => !entry.isDirectory).map((entry) => entry.relativePath);
104
+ const results = [];
105
+ for (const file of files) {
106
+ const convention = await findConventionTests(rootDir, file, allFiles);
107
+ for (const testPath of convention) {
108
+ results.push({ path: testPath, reason: "Matched by test naming convention", score: 0.68 });
109
+ }
110
+ results.push(...await findImporterTests(rootDir, file, 5));
111
+ }
112
+ const deduped = new Map();
113
+ for (const item of results) {
114
+ const existing = deduped.get(item.path);
115
+ if (!existing || item.score > existing.score)
116
+ deduped.set(item.path, item);
117
+ }
118
+ return [...deduped.values()].sort((a, b) => b.score - a.score);
119
+ }
120
+ export async function getRecentDiffSummary(rootDir, filePath) {
121
+ try {
122
+ const { stdout } = await execFileAsync("git", ["log", "--oneline", "-n", "1", "--", filePath], {
123
+ cwd: rootDir,
124
+ timeout: 5000,
125
+ });
126
+ const line = stdout.trim().split("\n")[0];
127
+ if (!line)
128
+ return null;
129
+ const [commit, ...summary] = line.split(" ");
130
+ return { path: filePath, commit, summary: summary.join(" ") };
131
+ }
132
+ catch {
133
+ return null;
134
+ }
135
+ }
136
+ export async function getProjectMemoryHits(rootDir, query, topK, keywordOnly = false) {
137
+ if (!Number.isFinite(topK) || topK <= 0)
138
+ return [];
139
+ const db = await getDB(rootDir);
140
+ const config = await loadProjectConfig(rootDir);
141
+ const projectId = config?.projectId ?? "";
142
+ const clientId = config?.clientId ?? "";
143
+ let queryVector;
144
+ try {
145
+ queryVector = keywordOnly || !hasCompatibleEmbeddingModel(db) ? [] : await fetchQueryEmbedding(query);
146
+ }
147
+ catch {
148
+ queryVector = [];
149
+ }
150
+ const terms = query.toLowerCase().match(/[\p{L}\p{N}_]+/gu) ?? [];
151
+ const lexicalHits = db.listMemoryNodes().map((node) => ({ node, distance: 1, score: terms.reduce((sum, term) => sum + Number(`${node.label} ${node.content}`.toLowerCase().includes(term)), 0) }))
152
+ .filter((hit) => hit.score > 0).sort((a, b) => b.score - a.score || a.node.id.localeCompare(b.node.id));
153
+ const semanticHits = queryVector.length && hasCompatibleEmbeddingModel(db) ? db.searchMemoryNodes(queryVector, Math.max(topK * 6, 18)) : [];
154
+ const hits = [...semanticHits, ...lexicalHits.filter((hit) => !semanticHits.some((candidate) => candidate.node.id === hit.node.id))];
155
+ const filtered = [];
156
+ for (const hit of hits) {
157
+ const evidenceStatus = await memoryEvidenceStatus(rootDir, hit.node);
158
+ if (evidenceStatus === "stale" || evidenceStatus === "superseded")
159
+ continue;
160
+ const metadata = parseMetadata(hit.node.metadata);
161
+ const scope = metadata.scope ?? "project";
162
+ if (scope === "global") {
163
+ // Global memories are always relevant.
164
+ }
165
+ else if (scope === "client") {
166
+ if (metadata.client_id !== clientId)
167
+ continue;
168
+ }
169
+ else if (scope === "project") {
170
+ if (metadata.project_id !== projectId)
171
+ continue;
172
+ }
173
+ else {
174
+ continue;
175
+ }
176
+ filtered.push({
177
+ id: hit.node.id,
178
+ kind: metadata.record_kind ?? "memory",
179
+ summary: `[${evidenceStatus}] ${hit.node.content.slice(0, 220)}`,
180
+ });
181
+ if (filtered.length >= topK)
182
+ break;
183
+ }
184
+ return filtered;
185
+ }
186
+ /** Bounded lexical risk lookup; never pay for embeddings on the context path. */
187
+ export async function getProjectRiskEvidence(rootDir, query) {
188
+ const db = await getDB(rootDir), config = await loadProjectConfig(rootDir);
189
+ const terms = [...new Set(query.toLowerCase().match(/[\p{L}\p{N}_]+/gu) ?? [])];
190
+ const candidates = db.listMemoryNodes().flatMap(node => {
191
+ const metadata = parseMetadata(node.metadata);
192
+ if (metadata.record_kind !== "task" || metadata.scope !== "project" || metadata.project_id !== (config?.projectId ?? ""))
193
+ return [];
194
+ // Older task records used a labelled content line. Preserve inspection and
195
+ // compatibility, but still require current bound evidence below.
196
+ const risks = metadata.open_risks !== undefined ? parseJsonArray(metadata.open_risks)
197
+ : (node.content.match(/^Open Risks: (.+)$/m)?.[1].split(" | ") ?? []);
198
+ if (!risks.length)
199
+ return [];
200
+ const text = `${node.label} ${node.content}`.toLowerCase();
201
+ const score = terms.reduce((sum, term) => sum + Number(text.includes(term)), 0);
202
+ return score ? [{ node, risks, score }] : [];
203
+ }).sort((a, b) => b.score - a.score || a.node.id.localeCompare(b.node.id));
204
+ const result = [];
205
+ for (const { node, risks } of candidates.slice(0, 12)) {
206
+ if (await memoryEvidenceStatus(rootDir, node) !== "current")
207
+ continue;
208
+ result.push({ id: node.id, risks: risks.slice(0, 2) });
209
+ if (result.length === 2)
210
+ break;
211
+ }
212
+ return result;
213
+ }
214
+ export async function resolveFilesFromSymbols(rootDir, symbols) {
215
+ if (!symbols || symbols.length === 0)
216
+ return [];
217
+ const db = await getDB(rootDir);
218
+ const files = [];
219
+ const indexedFiles = db.getAllFiles();
220
+ for (const symbol of symbols) {
221
+ const matches = db.searchSymbolsByName(symbol);
222
+ for (const match of matches) {
223
+ const file = indexedFiles.find((candidate) => candidate.id === match.file_id);
224
+ if (file)
225
+ files.push(file.path);
226
+ }
227
+ }
228
+ return unique(files);
229
+ }
230
+ export async function findTextDependents(rootDir, filePath, symbolNames = []) {
231
+ const db = await getDB(rootDir);
232
+ const dbFile = db.getFile(filePath);
233
+ if (dbFile) {
234
+ const importerRows = db.getImportersOf(dbFile.id);
235
+ const importerPaths = importerRows
236
+ .map((row) => db.getFileById(row.source_file_id)?.path)
237
+ .filter((path) => path !== undefined && path !== filePath);
238
+ if (importerPaths.length > 0 || symbolNames.length === 0)
239
+ return unique(importerPaths);
240
+ }
241
+ const entries = await walkDirectory({ rootDir, depthLimit: 0 });
242
+ const candidates = entries.filter((entry) => !entry.isDirectory).map((entry) => entry.relativePath);
243
+ const baseName = basename(filePath).replace(/\.\w+$/, "");
244
+ const matches = [];
245
+ for (const candidate of candidates) {
246
+ if (candidate === filePath)
247
+ continue;
248
+ try {
249
+ const content = await readFile(resolveProjectPath(rootDir, candidate, "candidate file"), "utf-8");
250
+ if (content.includes(baseName) || symbolNames.some((symbol) => content.includes(symbol))) {
251
+ matches.push(candidate);
252
+ }
253
+ }
254
+ catch { }
255
+ }
256
+ return unique(matches);
257
+ }
258
+ export async function scanExactMentions(rootDir, candidateFiles, symbolNames) {
259
+ if (candidateFiles.length === 0 || symbolNames.length === 0)
260
+ return [];
261
+ const matches = [];
262
+ for (const candidate of candidateFiles) {
263
+ try {
264
+ const content = await readFile(resolveProjectPath(rootDir, candidate, "candidate file"), "utf-8");
265
+ if (symbolNames.some((symbol) => content.includes(symbol)))
266
+ matches.push(candidate);
267
+ }
268
+ catch { }
269
+ }
270
+ return unique(matches);
271
+ }
272
+ export async function fileRisk(rootDir, filePath) {
273
+ const db = await getDB(rootDir);
274
+ const dbFile = db.getFile(filePath);
275
+ let importers = 0;
276
+ let imports = 0;
277
+ if (dbFile) {
278
+ importers = db.getImportersOf(dbFile.id).length;
279
+ imports = db.getImportsFrom(dbFile.id).length;
280
+ }
281
+ let churn = 0;
282
+ try {
283
+ const { stdout } = await execFileAsync("git", ["log", "--oneline", "--", filePath], { cwd: rootDir, timeout: 5000 });
284
+ churn = stdout.trim().split("\n").filter(Boolean).length;
285
+ }
286
+ catch { }
287
+ return { importers, imports, churn };
288
+ }
289
+ export async function hubMatchesForFiles(rootDir, filePaths) {
290
+ const hubs = await discoverHubs(rootDir).catch(() => []);
291
+ const matches = [];
292
+ for (const hubPath of hubs) {
293
+ const hub = await parseHubFile(resolveProjectPath(rootDir, hubPath, "hubPath")).catch(() => null);
294
+ if (!hub)
295
+ continue;
296
+ if (hub.links.some((link) => filePaths.includes(link.target))) {
297
+ matches.push(hubPath);
298
+ }
299
+ }
300
+ return matches;
301
+ }
302
+ //# sourceMappingURL=retrieval-helpers.js.map