codesearch-mcp 0.2.3-alpha → 0.4.0-alpha

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 (317) hide show
  1. package/CHANGELOG.md +88 -5
  2. package/LICENSE +661 -21
  3. package/README.md +76 -40
  4. package/dist/app.js +17 -38
  5. package/dist/src/ast/CallExtractor.d.ts +8 -0
  6. package/dist/src/ast/CallExtractor.js +68 -0
  7. package/dist/src/ast/GraphqlNameExtractor.d.ts +22 -0
  8. package/dist/src/ast/GraphqlNameExtractor.js +240 -0
  9. package/dist/src/ast/ImportEdgeExtractor.d.ts +11 -0
  10. package/dist/src/ast/ImportEdgeExtractor.js +129 -0
  11. package/dist/src/ast/IndexedNodeResolver.d.ts +14 -0
  12. package/dist/src/ast/IndexedNodeResolver.js +217 -0
  13. package/dist/src/ast/MemberExtractor.d.ts +8 -0
  14. package/dist/src/ast/MemberExtractor.js +129 -0
  15. package/dist/src/ast/TopLevelSymbolExtractor.d.ts +5 -0
  16. package/dist/src/ast/TopLevelSymbolExtractor.js +86 -0
  17. package/dist/src/ast/graphql-grammar.d.ts +24 -0
  18. package/dist/src/ast/graphql-grammar.js +93 -0
  19. package/dist/src/ast/node-helpers.d.ts +11 -0
  20. package/dist/src/ast/node-helpers.js +55 -0
  21. package/dist/src/chunking/AstChunker.d.ts +12 -0
  22. package/dist/src/chunking/AstChunker.js +30 -0
  23. package/dist/src/chunking/CharacterChunkStrategy.d.ts +8 -0
  24. package/dist/src/chunking/CharacterChunkStrategy.js +15 -0
  25. package/dist/src/chunking/DeclarationChunkStrategy.d.ts +15 -0
  26. package/dist/src/chunking/DeclarationChunkStrategy.js +87 -0
  27. package/dist/src/chunking/FragmentMerger.d.ts +11 -0
  28. package/dist/src/chunking/FragmentMerger.js +61 -0
  29. package/dist/src/chunking/ImportOnlyFilter.d.ts +5 -0
  30. package/dist/src/chunking/ImportOnlyFilter.js +14 -0
  31. package/dist/src/chunking/LangchainTextSplitter.d.ts +21 -0
  32. package/dist/src/chunking/LangchainTextSplitter.js +133 -0
  33. package/dist/src/chunking/MinSizeSplitPolicy.d.ts +9 -0
  34. package/dist/src/chunking/MinSizeSplitPolicy.js +18 -0
  35. package/dist/src/chunking/RunPacker.d.ts +12 -0
  36. package/dist/src/chunking/RunPacker.js +84 -0
  37. package/dist/src/chunking/create-chunker.d.ts +3 -0
  38. package/dist/src/chunking/create-chunker.js +15 -0
  39. package/dist/src/chunking/interfaces.d.ts +27 -0
  40. package/dist/src/commands/ConfigCommand.js +1 -9
  41. package/dist/src/commands/EvalCommand.d.ts +10 -5
  42. package/dist/src/commands/EvalCommand.js +60 -149
  43. package/dist/src/commands/IndexCommand.d.ts +10 -4
  44. package/dist/src/commands/IndexCommand.js +52 -146
  45. package/dist/src/commands/McpCommand.d.ts +6 -3
  46. package/dist/src/commands/McpCommand.js +19 -20
  47. package/dist/src/commands/WebCommand.d.ts +9 -3
  48. package/dist/src/commands/WebCommand.js +17 -11
  49. package/dist/src/commands/eval/baseline-comparison.d.ts +6 -0
  50. package/dist/src/commands/eval/baseline-comparison.js +54 -0
  51. package/dist/src/commands/eval/eval-args.d.ts +6 -0
  52. package/dist/src/commands/eval/eval-args.js +71 -0
  53. package/dist/src/commands/eval/eval-corpora.d.ts +6 -0
  54. package/dist/src/commands/eval/eval-corpora.js +76 -0
  55. package/dist/src/commands/eval/eval-metadata.d.ts +17 -0
  56. package/dist/src/commands/eval/eval-metadata.js +75 -0
  57. package/dist/src/commands/eval/index-inspector.d.ts +3 -0
  58. package/dist/src/commands/eval/index-inspector.js +21 -0
  59. package/dist/src/commands/eval/staged-search.d.ts +3 -0
  60. package/dist/src/commands/eval/staged-search.js +20 -0
  61. package/dist/src/commands/eval/suite-loader.d.ts +8 -0
  62. package/dist/src/commands/eval/suite-loader.js +52 -0
  63. package/dist/src/commands/index/backend-probe.d.ts +2 -0
  64. package/dist/src/commands/index/backend-probe.js +15 -0
  65. package/dist/src/commands/index/embedding-setup.d.ts +3 -0
  66. package/dist/src/commands/index/embedding-setup.js +16 -0
  67. package/dist/src/commands/index/index-summary.d.ts +2 -0
  68. package/dist/src/commands/index/index-summary.js +22 -0
  69. package/dist/src/commands/index/legacy-ollama-guard.d.ts +3 -0
  70. package/dist/src/commands/index/legacy-ollama-guard.js +23 -0
  71. package/dist/src/commands/index/prune-step.d.ts +3 -0
  72. package/dist/src/commands/index/prune-step.js +22 -0
  73. package/dist/src/commands/index/scan-targets.d.ts +8 -0
  74. package/dist/src/commands/index/scan-targets.js +107 -0
  75. package/dist/src/config-error.d.ts +0 -4
  76. package/dist/src/config-error.js +0 -4
  77. package/dist/src/config-store.d.ts +1 -55
  78. package/dist/src/config-store.js +11 -73
  79. package/dist/src/config.d.ts +9 -18
  80. package/dist/src/config.js +36 -35
  81. package/dist/src/constants.d.ts +17 -28
  82. package/dist/src/constants.js +35 -29
  83. package/dist/src/container.d.ts +10 -2
  84. package/dist/src/container.js +19 -8
  85. package/dist/src/db/drizzle-types.d.ts +7 -0
  86. package/dist/src/db/drizzle-types.js +2 -0
  87. package/dist/src/db/index.d.ts +1 -0
  88. package/dist/src/db/schema-steps.d.ts +8 -0
  89. package/dist/src/db/schema-steps.js +105 -0
  90. package/dist/src/db/schema.d.ts +17 -0
  91. package/dist/src/db/schema.js +1 -6
  92. package/dist/src/declarations/DeclarationTree.d.ts +19 -0
  93. package/dist/src/declarations/DeclarationTree.js +66 -0
  94. package/dist/src/declarations/DeclarationTreeBuilder.d.ts +22 -0
  95. package/dist/src/declarations/DeclarationTreeBuilder.js +179 -0
  96. package/dist/src/declarations/SourceLines.d.ts +37 -0
  97. package/dist/src/declarations/SourceLines.js +415 -0
  98. package/dist/src/dependency-traversal.d.ts +0 -6
  99. package/dist/src/dependency-traversal.js +0 -6
  100. package/dist/src/enriched-prompt.d.ts +0 -6
  101. package/dist/src/enriched-prompt.js +0 -6
  102. package/dist/src/error-record.d.ts +12 -0
  103. package/dist/src/error-record.js +248 -0
  104. package/dist/src/eval-corpus.d.ts +16 -0
  105. package/dist/src/eval-corpus.js +169 -0
  106. package/dist/src/eval-results.d.ts +6 -3
  107. package/dist/src/eval-results.js +323 -26
  108. package/dist/src/eval-vector-index.d.ts +5 -0
  109. package/dist/src/eval-vector-index.js +60 -0
  110. package/dist/src/file-utils.d.ts +0 -5
  111. package/dist/src/file-utils.js +0 -5
  112. package/dist/src/graph.d.ts +0 -25
  113. package/dist/src/graph.js +0 -28
  114. package/dist/src/help.js +9 -1
  115. package/dist/src/hnsw-settings.d.ts +3 -0
  116. package/dist/src/hnsw-settings.js +24 -0
  117. package/dist/src/index-args.d.ts +13 -0
  118. package/dist/src/index-args.js +48 -0
  119. package/dist/src/indexing/AnalysisBatcher.d.ts +12 -0
  120. package/dist/src/indexing/AnalysisBatcher.js +28 -0
  121. package/dist/src/indexing/ChunkEmbedder.d.ts +24 -0
  122. package/dist/src/indexing/ChunkEmbedder.js +37 -0
  123. package/dist/src/indexing/ConsoleScanReporter.d.ts +10 -0
  124. package/dist/src/indexing/ConsoleScanReporter.js +73 -0
  125. package/dist/src/indexing/EmbeddingSchemaPreparer.d.ts +14 -0
  126. package/dist/src/indexing/EmbeddingSchemaPreparer.js +66 -0
  127. package/dist/src/indexing/FileIngestor.d.ts +22 -0
  128. package/dist/src/indexing/FileIngestor.js +116 -0
  129. package/dist/src/indexing/IndexStore.d.ts +24 -0
  130. package/dist/src/indexing/IndexStore.js +69 -0
  131. package/dist/src/indexing/StaleFilePruner.d.ts +8 -0
  132. package/dist/src/indexing/StaleFilePruner.js +55 -0
  133. package/dist/src/indexing/analysis-rows.d.ts +4 -0
  134. package/dist/src/indexing/analysis-rows.js +65 -0
  135. package/dist/src/indexing/project-notices.d.ts +2 -0
  136. package/dist/src/indexing/project-notices.js +63 -0
  137. package/dist/src/interfaces/IAstParser.d.ts +4 -40
  138. package/dist/src/interfaces/ICallGraph.d.ts +28 -0
  139. package/dist/src/interfaces/ICallGraph.js +2 -0
  140. package/dist/src/interfaces/IChunkSearch.d.ts +42 -0
  141. package/dist/src/interfaces/IChunkSearch.js +2 -0
  142. package/dist/src/interfaces/IChunker.d.ts +3 -12
  143. package/dist/src/interfaces/ICorpusInspector.d.ts +7 -0
  144. package/dist/src/interfaces/ICorpusInspector.js +2 -0
  145. package/dist/src/interfaces/IDatabase.d.ts +8 -24
  146. package/dist/src/interfaces/IDependencyGraph.d.ts +24 -0
  147. package/dist/src/interfaces/IDependencyGraph.js +2 -0
  148. package/dist/src/interfaces/IEmbedder.d.ts +0 -9
  149. package/dist/src/interfaces/IIndexIdentityGuard.d.ts +3 -0
  150. package/dist/src/interfaces/IIndexIdentityGuard.js +2 -0
  151. package/dist/src/interfaces/IIndexedNodeResolver.d.ts +10 -0
  152. package/dist/src/interfaces/IIndexedNodeResolver.js +2 -0
  153. package/dist/src/interfaces/ILogger.d.ts +1 -11
  154. package/dist/src/interfaces/IMcpReadiness.d.ts +12 -0
  155. package/dist/src/interfaces/IMcpReadiness.js +2 -0
  156. package/dist/src/interfaces/IMcpToolHandler.d.ts +0 -5
  157. package/dist/src/interfaces/IMonorepoResolver.d.ts +0 -22
  158. package/dist/src/interfaces/IProjectCatalog.d.ts +13 -0
  159. package/dist/src/interfaces/IProjectCatalog.js +2 -0
  160. package/dist/src/interfaces/IProjectDiscovery.d.ts +0 -17
  161. package/dist/src/interfaces/IProjectRoots.d.ts +3 -0
  162. package/dist/src/interfaces/IProjectRoots.js +2 -0
  163. package/dist/src/interfaces/IRetrievalEvaluator.d.ts +153 -12
  164. package/dist/src/interfaces/IScanReporter.d.ts +13 -0
  165. package/dist/src/interfaces/IScanReporter.js +2 -0
  166. package/dist/src/interfaces/ISymbolLookup.d.ts +49 -0
  167. package/dist/src/interfaces/ISymbolLookup.js +2 -0
  168. package/dist/src/interfaces/IToolPaths.d.ts +62 -0
  169. package/dist/src/interfaces/IToolPaths.js +2 -0
  170. package/dist/src/interfaces/IWorkspaceFiles.d.ts +28 -0
  171. package/dist/src/interfaces/IWorkspaceFiles.js +2 -0
  172. package/dist/src/interfaces/SymbolKind.d.ts +1 -0
  173. package/dist/src/interfaces/SymbolKind.js +2 -0
  174. package/dist/src/interfaces/index.d.ts +12 -1
  175. package/dist/src/interrupt.js +0 -2
  176. package/dist/src/owner-path.d.ts +9 -10
  177. package/dist/src/owner-path.js +11 -23
  178. package/dist/src/project-scope.d.ts +1 -12
  179. package/dist/src/project-scope.js +5 -12
  180. package/dist/src/project-selector.d.ts +0 -5
  181. package/dist/src/project-selector.js +0 -11
  182. package/dist/src/retrieval-eval.d.ts +15 -6
  183. package/dist/src/retrieval-eval.js +388 -59
  184. package/dist/src/search/CallGraph.d.ts +9 -0
  185. package/dist/src/search/CallGraph.js +84 -0
  186. package/dist/src/search/ChunkSearch.d.ts +23 -0
  187. package/dist/src/search/ChunkSearch.js +115 -0
  188. package/dist/src/search/DependencyGraph.d.ts +19 -0
  189. package/dist/src/search/DependencyGraph.js +180 -0
  190. package/dist/src/search/IndexIdentityGuard.d.ts +11 -0
  191. package/dist/src/search/IndexIdentityGuard.js +37 -0
  192. package/dist/src/search/ProjectCatalog.d.ts +11 -0
  193. package/dist/src/search/ProjectCatalog.js +38 -0
  194. package/dist/src/search/SymbolLookup.d.ts +24 -0
  195. package/dist/src/search/SymbolLookup.js +97 -0
  196. package/dist/src/search/chunks/CandidateFetcher.d.ts +19 -0
  197. package/dist/src/search/chunks/CandidateFetcher.js +40 -0
  198. package/dist/src/search/chunks/IterativeScanGate.d.ts +10 -0
  199. package/dist/src/search/chunks/IterativeScanGate.js +42 -0
  200. package/dist/src/search/chunks/RerankStage.d.ts +15 -0
  201. package/dist/src/search/chunks/RerankStage.js +42 -0
  202. package/dist/src/search/chunks/search-metrics.d.ts +18 -0
  203. package/dist/src/search/chunks/search-metrics.js +32 -0
  204. package/dist/src/search/chunks/search-plan.d.ts +18 -0
  205. package/dist/src/search/chunks/search-plan.js +19 -0
  206. package/dist/src/search/create-search-services.d.ts +26 -0
  207. package/dist/src/search/create-search-services.js +29 -0
  208. package/dist/src/search/index-paths.d.ts +1 -0
  209. package/dist/src/search/index-paths.js +5 -0
  210. package/dist/src/search/result-shaping.d.ts +4 -0
  211. package/dist/src/search/result-shaping.js +19 -0
  212. package/dist/src/search/symbol-sql.d.ts +13 -0
  213. package/dist/src/search/symbol-sql.js +66 -0
  214. package/dist/src/search/symbols/SymbolGrepFallback.d.ts +19 -0
  215. package/dist/src/search/symbols/SymbolGrepFallback.js +106 -0
  216. package/dist/src/search/symbols/SymbolIndexQuery.d.ts +14 -0
  217. package/dist/src/search/symbols/SymbolIndexQuery.js +52 -0
  218. package/dist/src/search/symbols/SymbolTextSearch.d.ts +13 -0
  219. package/dist/src/search/symbols/SymbolTextSearch.js +84 -0
  220. package/dist/src/search/symbols/TargetColumnGate.d.ts +7 -0
  221. package/dist/src/search/symbols/TargetColumnGate.js +23 -0
  222. package/dist/src/search/symbols/find-symbol-constants.d.ts +4 -0
  223. package/dist/src/search/symbols/find-symbol-constants.js +8 -0
  224. package/dist/src/search/symbols/grep-args.d.ts +3 -0
  225. package/dist/src/search/symbols/grep-args.js +7 -0
  226. package/dist/src/search/symbols/grep-patterns.d.ts +4 -0
  227. package/dist/src/search/symbols/grep-patterns.js +60 -0
  228. package/dist/src/services/AstParserService.d.ts +10 -106
  229. package/dist/src/services/AstParserService.js +37 -1068
  230. package/dist/src/services/DatabaseService.d.ts +10 -17
  231. package/dist/src/services/DatabaseService.js +71 -115
  232. package/dist/src/services/EmbedderFactory.d.ts +0 -4
  233. package/dist/src/services/EmbedderFactory.js +0 -5
  234. package/dist/src/services/IndexerService.d.ts +7 -26
  235. package/dist/src/services/IndexerService.js +38 -286
  236. package/dist/src/services/InfinityEmbedder.d.ts +0 -21
  237. package/dist/src/services/InfinityEmbedder.js +0 -15
  238. package/dist/src/services/LoggerService.d.ts +7 -5
  239. package/dist/src/services/LoggerService.js +37 -41
  240. package/dist/src/services/McpReadiness.d.ts +18 -0
  241. package/dist/src/services/McpReadiness.js +73 -0
  242. package/dist/src/services/McpServer.d.ts +50 -19
  243. package/dist/src/services/McpServer.js +132 -62
  244. package/dist/src/services/MonorepoAwareDiscoveryService.d.ts +1 -45
  245. package/dist/src/services/MonorepoAwareDiscoveryService.js +1 -51
  246. package/dist/src/services/NxMonorepoResolver.d.ts +0 -29
  247. package/dist/src/services/NxMonorepoResolver.js +5 -56
  248. package/dist/src/services/OpenAICompatibleEmbedder.d.ts +0 -6
  249. package/dist/src/services/OpenAICompatibleEmbedder.js +0 -14
  250. package/dist/src/services/ProjectDiscoveryService.d.ts +0 -4
  251. package/dist/src/services/ProjectDiscoveryService.js +0 -4
  252. package/dist/src/services/VoyageEmbedder.d.ts +0 -6
  253. package/dist/src/services/VoyageEmbedder.js +0 -6
  254. package/dist/src/services/WebServerService.d.ts +5 -56
  255. package/dist/src/services/WebServerService.js +25 -63
  256. package/dist/src/services/http-retry.d.ts +0 -7
  257. package/dist/src/services/http-retry.js +1 -10
  258. package/dist/src/services/infinity-provisioning.d.ts +0 -74
  259. package/dist/src/services/infinity-provisioning.js +5 -88
  260. package/dist/src/services/legacy-ollama-index.d.ts +0 -16
  261. package/dist/src/services/legacy-ollama-index.js +0 -23
  262. package/dist/src/services/reranker.d.ts +0 -9
  263. package/dist/src/services/reranker.js +46 -12
  264. package/dist/src/setup.d.ts +24 -24
  265. package/dist/src/setup.js +205 -103
  266. package/dist/src/symbol-name.d.ts +1 -12
  267. package/dist/src/symbol-name.js +16 -25
  268. package/dist/src/symbol-rows.d.ts +0 -14
  269. package/dist/src/symbol-rows.js +0 -14
  270. package/dist/src/tool-call-log.d.ts +2 -0
  271. package/dist/src/tool-call-log.js +24 -0
  272. package/dist/src/tools/FindSymbolTool.d.ts +17 -7
  273. package/dist/src/tools/FindSymbolTool.js +54 -35
  274. package/dist/src/tools/GetCallersTool.d.ts +16 -8
  275. package/dist/src/tools/GetCallersTool.js +65 -35
  276. package/dist/src/tools/GetDependenciesTool.d.ts +16 -8
  277. package/dist/src/tools/GetDependenciesTool.js +36 -29
  278. package/dist/src/tools/GetDependentsTool.d.ts +20 -8
  279. package/dist/src/tools/GetDependentsTool.js +48 -34
  280. package/dist/src/tools/ListFilesTool.d.ts +16 -8
  281. package/dist/src/tools/ListFilesTool.js +20 -26
  282. package/dist/src/tools/ListProjectsTool.d.ts +11 -7
  283. package/dist/src/tools/ListProjectsTool.js +13 -11
  284. package/dist/src/tools/McpTool.d.ts +17 -0
  285. package/dist/src/tools/McpTool.js +28 -0
  286. package/dist/src/tools/ReadFileRangeTool.d.ts +16 -8
  287. package/dist/src/tools/ReadFileRangeTool.js +23 -25
  288. package/dist/src/tools/ReadFileTool.d.ts +15 -8
  289. package/dist/src/tools/ReadFileTool.js +19 -24
  290. package/dist/src/tools/SearchCodebaseTool.d.ts +22 -10
  291. package/dist/src/tools/SearchCodebaseTool.js +71 -50
  292. package/dist/src/tools/format-helpers.d.ts +9 -9
  293. package/dist/src/tools/format-helpers.js +146 -28
  294. package/dist/src/tools/tool-args.d.ts +38 -0
  295. package/dist/src/tools/tool-args.js +95 -0
  296. package/dist/src/web/dashboard.d.ts +0 -8
  297. package/dist/src/web/dashboard.js +7 -10
  298. package/dist/src/workspace/GrepRunner.d.ts +15 -0
  299. package/dist/src/workspace/GrepRunner.js +104 -0
  300. package/dist/src/workspace/ProjectRoots.d.ts +22 -0
  301. package/dist/src/workspace/ProjectRoots.js +102 -0
  302. package/dist/src/workspace/ToolPaths.d.ts +31 -0
  303. package/dist/src/workspace/ToolPaths.js +312 -0
  304. package/dist/src/workspace/WorkspaceFiles.d.ts +19 -0
  305. package/dist/src/workspace/WorkspaceFiles.js +285 -0
  306. package/dist/src/workspace/fs-access.d.ts +9 -0
  307. package/dist/src/workspace/fs-access.js +47 -0
  308. package/dist/src/workspace/path-helpers.d.ts +3 -0
  309. package/dist/src/workspace/path-helpers.js +43 -0
  310. package/package.json +5 -4
  311. package/dist/src/interfaces/ISearcher.d.ts +0 -35
  312. package/dist/src/services/AstChunker.d.ts +0 -42
  313. package/dist/src/services/AstChunker.js +0 -158
  314. package/dist/src/services/SearcherService.d.ts +0 -342
  315. package/dist/src/services/SearcherService.js +0 -1199
  316. package/docs/web-dashboard.md +0 -206
  317. /package/dist/src/{interfaces/ISearcher.js → chunking/interfaces.js} +0 -0
@@ -1,342 +0,0 @@
1
- import * as fs from 'fs';
2
- import type { Config } from '../config';
3
- import type { IEmbedder } from '../interfaces';
4
- import type { IDatabase } from '../interfaces';
5
- import { type IndexingExclusion, type ProjectMeta } from '../file-utils';
6
- import type { ILogger } from '../interfaces';
7
- import type { IProjectDiscovery } from '../interfaces';
8
- export interface ChunkRow {
9
- serviceName: string;
10
- filePath: string;
11
- startLine: number;
12
- content: string;
13
- ownerPath?: string | null;
14
- }
15
- export interface SearchResult extends ChunkRow {
16
- score: number;
17
- }
18
- export interface NeighborResult {
19
- result: SearchResult;
20
- prevChunk: ChunkRow | null;
21
- nextChunk: ChunkRow | null;
22
- }
23
- export interface GraphContext {
24
- imports: string[];
25
- usedBy: string[];
26
- }
27
- /** A tool path argument refused on its form alone, before any lookup. */
28
- export type PathRefusal = {
29
- ok: false;
30
- reason: 'invalid';
31
- missing: boolean;
32
- } | {
33
- ok: false;
34
- reason: 'absolute';
35
- relative: string;
36
- } | {
37
- ok: false;
38
- reason: 'outside_workspace';
39
- };
40
- export type ResolvedToolPath = {
41
- ok: true;
42
- relPath: string;
43
- absPath: string;
44
- } | PathRefusal;
45
- export type NotIndexedExplanation = IndexingExclusion | {
46
- kind: 'no_project';
47
- } | {
48
- kind: 'project_not_indexed';
49
- project: string;
50
- } | {
51
- kind: 'unknown';
52
- };
53
- /** A well-formed path that leads to no readable data. */
54
- export type PathFailure = {
55
- ok: false;
56
- reason: 'outside_workspace';
57
- } | {
58
- ok: false;
59
- reason: 'unreadable';
60
- code: string;
61
- } | {
62
- ok: false;
63
- reason: 'not_found';
64
- candidates: string[];
65
- } | {
66
- ok: false;
67
- reason: 'deleted';
68
- } | {
69
- ok: false;
70
- reason: 'not_indexed';
71
- explanation: NotIndexedExplanation;
72
- } | {
73
- ok: false;
74
- reason: 'not_a_file';
75
- } | {
76
- ok: false;
77
- reason: 'not_a_directory';
78
- };
79
- export type FileRangeResult = {
80
- ok: true;
81
- filePath: string;
82
- startLine: number;
83
- endLine: number;
84
- lines: string[];
85
- hasMore: boolean;
86
- } | PathFailure | {
87
- ok: false;
88
- reason: 'past_end';
89
- lineCount: number;
90
- startLine: number;
91
- } | {
92
- ok: false;
93
- reason: 'bad_range';
94
- startLine: number;
95
- endLine: number;
96
- };
97
- export type ListFilesResult = {
98
- ok: true;
99
- tree: string;
100
- } | PathFailure;
101
- export type GrepSymbolResult = {
102
- ok: true;
103
- matches: GrepMatch[];
104
- truncated: boolean;
105
- partial: boolean;
106
- } | {
107
- ok: false;
108
- };
109
- /** Filesystem access of the path tools — injectable so error codes are testable without permissions. */
110
- export interface SearcherFs {
111
- realpath(p: string): Promise<string>;
112
- stat(p: string): Promise<fs.Stats>;
113
- readdir(p: string): Promise<fs.Dirent[]>;
114
- createReadStream(p: string): NodeJS.ReadableStream;
115
- }
116
- export interface DependencyRow {
117
- fromFile: string;
118
- fromSymbol: string | null;
119
- toFile: string;
120
- toSymbol: string | null;
121
- depType: string;
122
- depth?: number;
123
- via?: string;
124
- }
125
- export interface ProjectRow extends ProjectMeta {
126
- serviceName: string;
127
- chunks: number;
128
- packageName?: string | null;
129
- type?: 'app' | 'lib';
130
- /** Real filesystem root of the project (resolved via discovery). */
131
- path?: string;
132
- /** `path` in workspace-relative form (`.` for the workspace root). */
133
- relPath?: string;
134
- /** Error code of `stat` on `path`, null when it exists. */
135
- rootError?: string | null;
136
- }
137
- export interface GrepMatch {
138
- filePath: string;
139
- line: number;
140
- }
141
- export type SymbolKind = 'function' | 'class' | 'type' | 'interface' | 'variable' | 'method' | 'get_accessor' | 'set_accessor' | 'constructor' | 'function_property' | 'method_signature' | 'graphql_query' | 'graphql_mutation' | 'graphql_subscription' | 'graphql_field' | 'graphql_type' | 'all';
142
- export interface CallerRow {
143
- fromFile: string;
144
- fromSymbol: string | null;
145
- calleeName: string;
146
- calleeFile: string;
147
- line: number | null;
148
- }
149
- export interface SymbolHit {
150
- filePath: string;
151
- line: number;
152
- column: number;
153
- kind: Exclude<SymbolKind, 'all'>;
154
- signature: string;
155
- /** `container.name`, or `name` when the container is null. */
156
- qualified: string;
157
- isStatic: boolean;
158
- source: 'index' | 'grep';
159
- /** Qualified TypeScript name of the decorated declaration (GraphQL rows only); null otherwise. */
160
- target: string | null;
161
- }
162
- export declare class SearcherService {
163
- private db;
164
- private embedder;
165
- private discovery;
166
- private config;
167
- private logger;
168
- private readonly fs;
169
- constructor(db: IDatabase, embedder: IEmbedder, discovery: IProjectDiscovery, config: Config, logger?: ILogger, fsDeps?: Partial<SearcherFs>);
170
- /**
171
- * Whether `code_symbol.target` exists — `true` once a check finds it (never
172
- * re-checked again in this process), `false` until then (re-checked on
173
- * every lookup, so a `rag-index` run that adds the column takes effect
174
- * without restarting `rag-mcp`). See "find_symbol works before the target
175
- * column exists" (`graphql-symbols`).
176
- */
177
- private targetColumnPresent;
178
- /** Real path of `workspaceRoot`; cached only once resolved, so a transient failure is retried. */
179
- private realRootCache?;
180
- /** Lazily-built, cached map of project name → real filesystem root. */
181
- private rootMap?;
182
- /** Cached, lazily-built map of leaf project name → real filesystem root (via discovery). */
183
- private projectRootMap;
184
- /**
185
- * Resolve a project name to its real filesystem root. Uses discovery (leaf
186
- * projects) so nested-monorepo names like `repo/app` map to their true path;
187
- * falls back to `join(workspaceRoot, name)` when the name is unknown (e.g. a
188
- * project since removed from disk, or a flat project not surfaced by discovery).
189
- */
190
- private resolveProjectRoot;
191
- private toRel;
192
- private toAbs;
193
- private workspaceRoot;
194
- private realWorkspaceRoot;
195
- /**
196
- * Lexical validation of a tool path argument: refusals for an empty value,
197
- * `\`, an absolute path and a `..` escape; otherwise the canonical
198
- * workspace-relative form. The only filesystem access is the cached real path
199
- * of `workspaceRoot`.
200
- */
201
- resolveToolPath(input: string | null | undefined): Promise<ResolvedToolPath>;
202
- /**
203
- * Whether the real location of `absPath` — of the target, else of its nearest
204
- * existing ancestor plus the remaining segments — lies under the real
205
- * workspace root.
206
- */
207
- private realLocation;
208
- /**
209
- * Workspace boundary of the disk tools. A real location outside the workspace
210
- * is allowed only for content the indexer already read (a symlinked share):
211
- * the file itself for `file`, any file below it for `dir`.
212
- */
213
- checkRealLocation(relPath: string, absPath: string, kind: 'file' | 'dir'): Promise<{
214
- ok: true;
215
- } | Extract<PathFailure, {
216
- reason: 'outside_workspace' | 'unreadable';
217
- }>>;
218
- private pathExists;
219
- /** Whether any table of the index holds `relPath` (a canonical path, never `../…`). */
220
- isIndexedPath(relPath: string): Promise<boolean>;
221
- /** Whether the indexer read the file at `relPath`. */
222
- isContentPath(relPath: string): Promise<boolean>;
223
- private hasContentUnder;
224
- /**
225
- * Up to three index paths ending in `/<relPath>` (`file`) or directories
226
- * ending in `/<relPath>` that hold one (`dir`), in byte order. For `dir`, the
227
- * root of a project named `relPath` comes first.
228
- */
229
- findPathCandidates(relPath: string, kind: 'file' | 'dir'): Promise<string[]>;
230
- /** `findPathCandidates`, with a failed lookup logged and answered by no candidates. */
231
- private candidatesOrNone;
232
- /**
233
- * `relPath` with a leading project name replaced by that project's root
234
- * (`repo/app/src/x.ts` → `repo/apps/app/src/x.ts`), or null when no name
235
- * prefixes it, the root equals the name, or the result names nothing.
236
- */
237
- private substituteProjectName;
238
- private findProjectRootByName;
239
- /** Longest workspace-relative project root accepted by `match`; discovery is re-run once before giving up. */
240
- private findProjectRoot;
241
- /** Root directory (workspace-relative) of the project the text-search fallback for `relPath` runs in. */
242
- fallbackRoot(relPath: string): string | null;
243
- /**
244
- * Why a graph tool has no data for `relPath`, or null when the path is in the
245
- * index path set. Touches the disk only for an unknown path, and answers a
246
- * real location outside the workspace as `not_found` without looking at it.
247
- */
248
- checkGraphPath(relPath: string): Promise<PathFailure | null>;
249
- private explainNotIndexed;
250
- /**
251
- * Project-level dependency edges aggregated from `code_dependency`: an edge
252
- * `A → B` means some file in project A imports a file owned by project B.
253
- * Used by the graph to draw links between a monorepo's sub-projects. Only
254
- * edges whose target file belongs to an indexed project are returned (targets
255
- * outside any indexed project — e.g. unindexed libs — are skipped).
256
- */
257
- getProjectEdges(): Promise<{
258
- from: string;
259
- to: string;
260
- }[]>;
261
- prepareQuery(raw: string): Promise<{
262
- query: string;
263
- translated: boolean;
264
- }>;
265
- /**
266
- * Refuse when the configured embedding model disagrees with the one that built
267
- * the index — embedding a query into a foreign vector space returns noise. A
268
- * missing `index_meta` row with an empty (or altogether absent) `code_chunk`
269
- * does not block — but a *populated* `code_chunk` with no `index_meta` row is a
270
- * pre-`index_meta` install, treated as the legacy `ollama`/`bge-m3` index (same
271
- * interpretation as the `rag-index` legacy-Ollama guard), read-only — this check
272
- * never writes `index_meta`.
273
- */
274
- assertIndexMatches(): Promise<void>;
275
- private compareIndexed;
276
- listProjects(): Promise<ProjectRow[]>;
277
- searchChunks(query: string, limit: number, project: string | null, threshold?: number, rerankOverride?: boolean): Promise<SearchResult[]>;
278
- /**
279
- * Emit one structured search-tuning line (via `logger.metric`, at `info`
280
- * regardless of `logging.level`). `candidates` are in cosine order, so a
281
- * candidate's array index is its cosine rank — `maxCosineRankSurvived` is the
282
- * deepest cosine position that survived reranking into the returned set. Read
283
- * it alongside `poolSaturated` to tune `candidateFloor`/`overfetch`/threshold
284
- * per hardware. Never logs chunk content, embeddings, or credentials.
285
- */
286
- private emitSearchMetrics;
287
- fetchNeighbors(results: SearchResult[]): Promise<NeighborResult[]>;
288
- fetchGraphContext(results: SearchResult[]): Promise<Map<string, GraphContext>>;
289
- getDependencies(filePath: string, symbol?: string | null, transitive?: boolean): Promise<DependencyRow[]>;
290
- getDependents(filePath: string, symbol?: string | null, transitive?: boolean): Promise<DependencyRow[]>;
291
- getCallers(symbol: string, project: string, calleeFile?: string | null): Promise<CallerRow[]>;
292
- /**
293
- * Whole-word text search for `symbol` under `rootDir` (workspace-relative).
294
- * grep exiting ≥ 2 after printing matches is a partial result; without
295
- * matches, or when grep cannot be spawned, the search failed.
296
- */
297
- grepSymbol(symbol: string, rootDir: string, excludeFile: string): Promise<GrepSymbolResult>;
298
- findSymbol(name: string, project: string | null, kind: SymbolKind): Promise<{
299
- hits: SymbolHit[];
300
- truncated: boolean;
301
- grepFailed: boolean;
302
- }>;
303
- /**
304
- * Whether `code_symbol.target` exists. A present result is cached for the
305
- * process; an absent one is re-checked on every call. Propagates on a
306
- * failing check, same as any other failed index query.
307
- */
308
- private hasTargetColumn;
309
- private findSymbolFromIndex;
310
- private grepFindSymbol;
311
- listFiles(relPath: string, depth: number, pattern: string | null): Promise<ListFilesResult>;
312
- /**
313
- * The read tools' common front: workspace boundary, then existence and type.
314
- * A missing file still in the index is `deleted`; otherwise `not_found`.
315
- */
316
- private openableFile;
317
- /**
318
- * Streams the file's lines (as `readline` yields them) to `onLine` until it
319
- * returns false. An open or read error discards everything read so far.
320
- */
321
- private readLines;
322
- readFile(relPath: string, maxLines: number): Promise<FileRangeResult>;
323
- readFileRange(relPath: string, startLine: number, endLine: number): Promise<FileRangeResult>;
324
- /** Throws when `absDir` itself cannot be read; an unreadable subdirectory is marked in place. */
325
- private walkDir;
326
- /**
327
- * ERE pattern for a grep-fallback kind, or null when that kind is never
328
- * grepped (`function_property`/`method_signature` are index-only; a bare
329
- * `constructor` search only makes sense when the name itself is `constructor`).
330
- */
331
- private buildFindSymbolPattern;
332
- /** 1-based index of the first whole-word occurrence of `name` in `line`, or -1. */
333
- private static wholeWordIndex;
334
- private inferKind;
335
- /**
336
- * Async wrapper around grep to avoid blocking the event loop. `ok: false`
337
- * means grep could not be spawned (`output: null`) or exited with status ≥ 2,
338
- * keeping whatever it printed — distinguishable from a clean "no matches",
339
- * which is `ok: true, output: null`.
340
- */
341
- private spawnGrep;
342
- }