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
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOG_SERIALIZERS = exports.MAX_AGGREGATED = exports.MAX_PARAM_CHARS = exports.MAX_PARAMS = exports.MAX_QUERY_CHARS = exports.MAX_FRAMES = exports.MAX_CAUSES = void 0;
4
+ exports.serializeError = serializeError;
5
+ exports.rootCauseMessage = rootCauseMessage;
6
+ exports.errorMessage = errorMessage;
7
+ const drizzle_orm_1 = require("drizzle-orm");
8
+ exports.MAX_CAUSES = 5;
9
+ exports.MAX_FRAMES = 30;
10
+ exports.MAX_QUERY_CHARS = 500;
11
+ exports.MAX_PARAMS = 30;
12
+ exports.MAX_PARAM_CHARS = 120;
13
+ exports.MAX_AGGREGATED = 10;
14
+ const DRIVER_FIELDS = [
15
+ 'code', 'errno', 'syscall', 'path', 'detail', 'hint', 'where', 'schema', 'table', 'column', 'constraint',
16
+ ];
17
+ const FRAME_PREFIX = ' at ';
18
+ function read(obj, key) {
19
+ try {
20
+ return obj[key];
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ }
26
+ function isError(value) {
27
+ try {
28
+ return value instanceof Error;
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ }
34
+ function isAggregate(err) {
35
+ try {
36
+ return err instanceof AggregateError;
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }
42
+ function headOf(value, max) {
43
+ try {
44
+ if (!Array.isArray(value))
45
+ return undefined;
46
+ const length = value.length;
47
+ const items = [];
48
+ const count = typeof length === 'number' ? Math.min(length, max) : 0;
49
+ for (let i = 0; i < count; i++)
50
+ items.push(value[i]);
51
+ return { items, total: typeof length === 'number' && length > items.length ? length : items.length };
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ }
57
+ function isDrizzle(err) {
58
+ try {
59
+ return err instanceof drizzle_orm_1.DrizzleQueryError;
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ }
65
+ function limit(text, max) {
66
+ return text.length > max ? `${text.slice(0, max)}…(+${text.length - max})` : text;
67
+ }
68
+ function typeOf(err) {
69
+ const ctor = read(err, 'constructor');
70
+ const ctorName = typeof ctor === 'function' ? read(ctor, 'name') : undefined;
71
+ if (typeof ctorName === 'string' && ctorName)
72
+ return ctorName;
73
+ const name = read(err, 'name');
74
+ return typeof name === 'string' ? name : 'Error';
75
+ }
76
+ function rawMessage(err) {
77
+ const message = read(err, 'message');
78
+ return typeof message === 'string' ? message : undefined;
79
+ }
80
+ function messageOf(err) {
81
+ const message = rawMessage(err);
82
+ if (message === undefined || !isDrizzle(err))
83
+ return message;
84
+ const tail = message.indexOf('\nparams: ');
85
+ return limit(tail === -1 ? message : message.slice(0, tail), exports.MAX_QUERY_CHARS);
86
+ }
87
+ function aggregatedOf(err) {
88
+ const head = isAggregate(err) ? headOf(read(err, 'errors'), exports.MAX_AGGREGATED) : undefined;
89
+ return head ?? { items: [], total: 0 };
90
+ }
91
+ function textOf(err) {
92
+ const message = messageOf(err);
93
+ if (message === undefined)
94
+ return typeOf(err);
95
+ if (message)
96
+ return message;
97
+ const nested = aggregatedOf(err).items.filter(isError).map(messageOf).filter((m) => !!m);
98
+ return nested.length ? [...new Set(nested)].join('; ') : typeOf(err);
99
+ }
100
+ function limitFrames(frames) {
101
+ if (frames.length <= exports.MAX_FRAMES)
102
+ return frames;
103
+ return [...frames.slice(0, exports.MAX_FRAMES), ` … +${frames.length - exports.MAX_FRAMES} frames`];
104
+ }
105
+ function stackOf(err, type, message) {
106
+ const stack = read(err, 'stack');
107
+ if (typeof stack !== 'string')
108
+ return undefined;
109
+ if (isDrizzle(err)) {
110
+ const name = read(err, 'name');
111
+ const raw = rawMessage(err) ?? '';
112
+ const native = `${typeof name === 'string' ? name : ''}${raw ? `: ${raw}` : ''}`;
113
+ const header = message !== undefined ? `${type}: ${message}` : type;
114
+ if (!stack.startsWith(`${native}\n`))
115
+ return header;
116
+ return [header, ...limitFrames(stack.slice(native.length + 1).split('\n'))].join('\n');
117
+ }
118
+ const lines = stack.split('\n');
119
+ const firstFrame = lines.findIndex(line => line.startsWith(FRAME_PREFIX));
120
+ if (firstFrame === -1)
121
+ return stack;
122
+ return [...lines.slice(0, firstFrame), ...limitFrames(lines.slice(firstFrame))].join('\n');
123
+ }
124
+ function renderParam(value) {
125
+ try {
126
+ if (value === null || typeof value === 'boolean' || typeof value === 'number')
127
+ return value;
128
+ if (typeof value === 'string')
129
+ return limit(value, exports.MAX_PARAM_CHARS);
130
+ if (value instanceof Date)
131
+ return value.toISOString();
132
+ if (Buffer.isBuffer(value))
133
+ return `[Buffer ${value.length} bytes]`;
134
+ const json = JSON.stringify(value);
135
+ if (typeof json === 'string')
136
+ return limit(json, exports.MAX_PARAM_CHARS);
137
+ }
138
+ catch {
139
+ }
140
+ try {
141
+ return limit(String(value), exports.MAX_PARAM_CHARS);
142
+ }
143
+ catch {
144
+ return '[unserializable]';
145
+ }
146
+ }
147
+ function compactParams({ items, total }) {
148
+ const values = items.map(renderParam);
149
+ if (total > exports.MAX_PARAMS)
150
+ values.push(`…(+${total - exports.MAX_PARAMS})`);
151
+ return { count: total, values };
152
+ }
153
+ function linkOf(err, expand = true) {
154
+ const type = typeOf(err);
155
+ const message = messageOf(err);
156
+ const link = { type };
157
+ if (message !== undefined)
158
+ link.message = message;
159
+ const stack = stackOf(err, type, message);
160
+ if (stack !== undefined)
161
+ link.stack = stack;
162
+ for (const field of DRIVER_FIELDS) {
163
+ const value = read(err, field);
164
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
165
+ link[field] = value;
166
+ }
167
+ if (isDrizzle(err)) {
168
+ const query = read(err, 'query');
169
+ if (typeof query === 'string')
170
+ link.query = limit(query, exports.MAX_QUERY_CHARS);
171
+ const params = headOf(read(err, 'params'), exports.MAX_PARAMS);
172
+ if (params)
173
+ link.params = compactParams(params);
174
+ }
175
+ const nested = expand ? aggregatedOf(err) : { items: [], total: 0 };
176
+ if (nested.total) {
177
+ const errors = nested.items.map(e => (isError(e) ? linkOf(e, false) : { value: renderParam(e) }));
178
+ if (nested.total > exports.MAX_AGGREGATED)
179
+ errors.push(`…(+${nested.total - exports.MAX_AGGREGATED})`);
180
+ link.errors = errors;
181
+ }
182
+ return link;
183
+ }
184
+ function causeChain(err) {
185
+ const chain = { errors: [] };
186
+ const visited = new Set([err]);
187
+ let current = err;
188
+ for (;;) {
189
+ const cause = read(current, 'cause');
190
+ if (cause === undefined)
191
+ return chain;
192
+ if (chain.errors.length >= exports.MAX_CAUSES) {
193
+ chain.truncated = 'depth';
194
+ return chain;
195
+ }
196
+ if (!isError(cause)) {
197
+ chain.tail = { value: cause };
198
+ return chain;
199
+ }
200
+ if (visited.has(cause)) {
201
+ chain.truncated = 'cycle';
202
+ return chain;
203
+ }
204
+ visited.add(cause);
205
+ chain.errors.push(cause);
206
+ current = cause;
207
+ }
208
+ }
209
+ function serializeError(value) {
210
+ if (!isError(value))
211
+ return value;
212
+ const record = linkOf(value);
213
+ const chain = causeChain(value);
214
+ const causes = chain.errors.map(e => linkOf(e));
215
+ if (chain.tail)
216
+ causes.push(chain.tail);
217
+ if (causes.length)
218
+ record.causes = causes;
219
+ if (chain.truncated)
220
+ record.causesTruncated = chain.truncated;
221
+ return record;
222
+ }
223
+ function rootCauseMessage(value) {
224
+ if (!isError(value)) {
225
+ try {
226
+ return String(value);
227
+ }
228
+ catch {
229
+ return '[unserializable]';
230
+ }
231
+ }
232
+ const errors = causeChain(value).errors;
233
+ const root = errors.length ? errors[errors.length - 1] : value;
234
+ const code = read(root, 'code');
235
+ const text = textOf(root);
236
+ return typeof code === 'string' ? `${text} (${code})` : text;
237
+ }
238
+ function errorMessage(value) {
239
+ if (isError(value))
240
+ return textOf(value);
241
+ try {
242
+ return String(value);
243
+ }
244
+ catch {
245
+ return '[unserializable]';
246
+ }
247
+ }
248
+ exports.LOG_SERIALIZERS = { err: serializeError };
@@ -0,0 +1,16 @@
1
+ import type { ICorpusInspector } from './interfaces/ICorpusInspector';
2
+ import type { IDatabase } from './interfaces/IDatabase';
3
+ import type { CorpusRef } from './interfaces/IRetrievalEvaluator';
4
+ export declare class GitCorpusInspector implements ICorpusInspector {
5
+ headCommit(root: string): Promise<string>;
6
+ trackedChanges(root: string): Promise<string[]>;
7
+ untrackedFiles(root: string, skipDirs: readonly string[]): Promise<string[]>;
8
+ listFiles(dir: string): Promise<string[]>;
9
+ readFile(absPath: string): Promise<Buffer | null>;
10
+ }
11
+ export declare function checkCorpus(corpus: CorpusRef, corpusDir: string, keptDir: string, inspector: ICorpusInspector): Promise<string[]>;
12
+ export declare const FINGERPRINT_SQL = "SELECT COUNT(*)::int AS chunks,\n md5(coalesce(string_agg(\n \"serviceName\" || E'\\t' || \"filePath\" || E'\\t' || coalesce(\"startLine\"::text, '') || E'\\t'\n || md5(content) || E'\\t' || coalesce(\"ownerPath\", '') || E'\\t' || md5(embedding::text),\n E'\\n' ORDER BY \"serviceName\" COLLATE \"C\", \"filePath\" COLLATE \"C\", \"startLine\", md5(content)\n ), '')) AS fingerprint\nFROM code_chunk\nWHERE \"serviceName\" = ANY($1::text[])";
13
+ export declare function fingerprintCorpus(db: Pick<IDatabase, 'query'>, projects: string[]): Promise<{
14
+ chunks: number;
15
+ fingerprint: string;
16
+ }>;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FINGERPRINT_SQL = exports.GitCorpusInspector = void 0;
40
+ exports.checkCorpus = checkCorpus;
41
+ exports.fingerprintCorpus = fingerprintCorpus;
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
44
+ const child_process_1 = require("child_process");
45
+ const util_1 = require("util");
46
+ const ignore_1 = __importDefault(require("ignore"));
47
+ const file_utils_1 = require("./file-utils");
48
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
49
+ const RAGIGNORE = '.ragignore';
50
+ async function git(root, args) {
51
+ const { stdout } = await execFileAsync('git', args, { cwd: root, encoding: 'utf-8', maxBuffer: 64 * 1024 * 1024 });
52
+ return stdout;
53
+ }
54
+ function nulSeparated(out) {
55
+ return out.split('\0').filter(s => s.length > 0);
56
+ }
57
+ class GitCorpusInspector {
58
+ async headCommit(root) {
59
+ return (await git(root, ['rev-parse', 'HEAD'])).trim();
60
+ }
61
+ async trackedChanges(root) {
62
+ return nulSeparated(await git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=no']))
63
+ .map(entry => (/^[ MADRCUT?!]{2} /.test(entry) ? entry.slice(3) : entry));
64
+ }
65
+ async untrackedFiles(root, skipDirs) {
66
+ const excludes = skipDirs.flatMap(d => ['-x', d]);
67
+ return nulSeparated(await git(root, ['ls-files', '--others', '-z', ...excludes]));
68
+ }
69
+ async listFiles(dir) {
70
+ const out = [];
71
+ const walk = async (rel) => {
72
+ let entries;
73
+ try {
74
+ entries = await fs.promises.readdir(path.join(dir, rel), { withFileTypes: true });
75
+ }
76
+ catch {
77
+ return;
78
+ }
79
+ for (const e of entries) {
80
+ const child = rel ? `${rel}/${e.name}` : e.name;
81
+ if (e.isDirectory())
82
+ await walk(child);
83
+ else
84
+ out.push(child);
85
+ }
86
+ };
87
+ await walk('');
88
+ return out.sort();
89
+ }
90
+ async readFile(absPath) {
91
+ try {
92
+ return await fs.promises.readFile(absPath);
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ }
98
+ }
99
+ exports.GitCorpusInspector = GitCorpusInspector;
100
+ async function isCollectable(file, corpusDir, inspector, ignoreCache) {
101
+ if ((0, file_utils_1.indexingExclusion)(file, (0, ignore_1.default)()) !== null)
102
+ return false;
103
+ const segments = file.split('/');
104
+ for (let depth = segments.length - 1; depth >= 0; depth--) {
105
+ const dir = segments.slice(0, depth).join('/');
106
+ if (!ignoreCache.has(dir)) {
107
+ const bytes = await inspector.readFile(path.join(corpusDir, dir, RAGIGNORE));
108
+ ignoreCache.set(dir, bytes === null ? null : (0, ignore_1.default)().add(bytes.toString('utf-8')));
109
+ }
110
+ const ig = ignoreCache.get(dir);
111
+ if (ig && (0, file_utils_1.indexingExclusion)(segments.slice(depth).join('/'), ig) !== null)
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+ function listed(files, max = 10) {
117
+ return files.length <= max ? files.join(', ') : `${files.slice(0, max).join(', ')} and ${files.length - max} more`;
118
+ }
119
+ async function checkCorpus(corpus, corpusDir, keptDir, inspector) {
120
+ const failures = [];
121
+ const head = await inspector.headCommit(corpusDir);
122
+ if (head !== corpus.commit) {
123
+ failures.push(`checked out at ${head}, suite declares ${corpus.commit}`);
124
+ }
125
+ const changed = await inspector.trackedChanges(corpusDir);
126
+ if (changed.length > 0)
127
+ failures.push(`tracked files differ from the commit: ${listed(changed)}`);
128
+ const untracked = await inspector.untrackedFiles(corpusDir, [...file_utils_1.IGNORE_DIRS]);
129
+ const ignoreCache = new Map();
130
+ const collectable = [];
131
+ for (const file of untracked) {
132
+ if (path.posix.basename(file) === RAGIGNORE)
133
+ continue;
134
+ if (await isCollectable(file, corpusDir, inspector, ignoreCache))
135
+ collectable.push(file);
136
+ }
137
+ if (collectable.length > 0)
138
+ failures.push(`untracked files the indexer would collect: ${listed(collectable)}`);
139
+ const untrackedIgnores = untracked.filter(f => path.posix.basename(f) === RAGIGNORE).sort();
140
+ const kept = (await inspector.listFiles(keptDir)).filter(f => path.posix.basename(f) === RAGIGNORE);
141
+ const keptSet = new Set(kept);
142
+ const missingCopy = untrackedIgnores.filter(f => !keptSet.has(f));
143
+ const missingFile = kept.filter(f => !untrackedIgnores.includes(f));
144
+ if (missingCopy.length > 0)
145
+ failures.push(`untracked .ragignore with no kept copy: ${listed(missingCopy)}`);
146
+ if (missingFile.length > 0)
147
+ failures.push(`kept .ragignore missing from the checkout: ${listed(missingFile)}`);
148
+ for (const file of untrackedIgnores.filter(f => keptSet.has(f))) {
149
+ const [actual, copy] = await Promise.all([
150
+ inspector.readFile(path.join(corpusDir, file)),
151
+ inspector.readFile(path.join(keptDir, file)),
152
+ ]);
153
+ if (actual === null || copy === null || !actual.equals(copy))
154
+ failures.push(`${file} differs from its kept copy`);
155
+ }
156
+ return failures;
157
+ }
158
+ exports.FINGERPRINT_SQL = `SELECT COUNT(*)::int AS chunks,
159
+ md5(coalesce(string_agg(
160
+ "serviceName" || E'\\t' || "filePath" || E'\\t' || coalesce("startLine"::text, '') || E'\\t'
161
+ || md5(content) || E'\\t' || coalesce("ownerPath", '') || E'\\t' || md5(embedding::text),
162
+ E'\\n' ORDER BY "serviceName" COLLATE "C", "filePath" COLLATE "C", "startLine", md5(content)
163
+ ), '')) AS fingerprint
164
+ FROM code_chunk
165
+ WHERE "serviceName" = ANY($1::text[])`;
166
+ async function fingerprintCorpus(db, projects) {
167
+ const [row] = await db.query(exports.FINGERPRINT_SQL, [projects]);
168
+ return { chunks: Number(row.chunks), fingerprint: row.fingerprint };
169
+ }
@@ -1,7 +1,9 @@
1
- import type { EvalResultFile, CompareResult } from './interfaces/IRetrievalEvaluator';
2
- /** `yyyy-mm-dd_hh-mm` in local time, matching the existing `benchmarks/results/` naming. */
1
+ import type { EvalResultFile, EvalRunResult, CompareResult, CaseProgress } from './interfaces/IRetrievalEvaluator';
2
+ export declare function degradedNotices(run: EvalRunResult): string[];
3
+ export declare function renderSummary(result: EvalResultFile): string[];
4
+ export declare function renderComparison(baselinePath: string, cmp: CompareResult): string[];
5
+ export declare function renderProgress(p: CaseProgress): string;
3
6
  export declare function timestampSlug(date: Date): string;
4
- /** Writes the JSON + Markdown result files for one eval run; returns their paths. */
5
7
  export declare function writeResultFiles(resultsDir: string, suiteLabel: string, result: EvalResultFile, now: Date, comparison?: {
6
8
  baselinePath: string;
7
9
  result: CompareResult;
@@ -9,4 +11,5 @@ export declare function writeResultFiles(resultsDir: string, suiteLabel: string,
9
11
  jsonPath: string;
10
12
  mdPath: string;
11
13
  };
14
+ export declare function normaliseResultFile(raw: any): EvalResultFile;
12
15
  export declare function readResultFile(filePath: string): EvalResultFile;