lmgrep 0.1.18 → 0.2.1

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 (414) hide show
  1. package/README.md +253 -62
  2. package/completions/_lmgrep +49 -40
  3. package/dist/application/Lmgrep.d.ts +107 -0
  4. package/dist/application/Lmgrep.js +99 -0
  5. package/dist/application/Lmgrep.js.map +1 -0
  6. package/dist/application/LmgrepFactory.d.ts +40 -0
  7. package/dist/application/LmgrepFactory.js +155 -0
  8. package/dist/application/LmgrepFactory.js.map +1 -0
  9. package/dist/application/indexing/BranchBootstrapper.d.ts +21 -0
  10. package/dist/application/indexing/BranchBootstrapper.js +52 -0
  11. package/dist/application/indexing/BranchBootstrapper.js.map +1 -0
  12. package/dist/application/indexing/BranchManifestSweeper.d.ts +17 -0
  13. package/dist/application/indexing/BranchManifestSweeper.js +35 -0
  14. package/dist/application/indexing/BranchManifestSweeper.js.map +1 -0
  15. package/dist/application/indexing/Duration.d.ts +9 -0
  16. package/dist/application/indexing/Duration.js +25 -0
  17. package/dist/application/indexing/Duration.js.map +1 -0
  18. package/dist/application/indexing/EmbeddingAbortError.d.ts +11 -0
  19. package/dist/application/indexing/EmbeddingAbortError.js +20 -0
  20. package/dist/application/indexing/EmbeddingAbortError.js.map +1 -0
  21. package/dist/application/indexing/EmbeddingPipeline.d.ts +59 -0
  22. package/dist/application/indexing/EmbeddingPipeline.js +140 -0
  23. package/dist/application/indexing/EmbeddingPipeline.js.map +1 -0
  24. package/dist/application/indexing/IndexBuilder.d.ts +112 -0
  25. package/dist/application/indexing/IndexBuilder.js +370 -0
  26. package/dist/application/indexing/IndexBuilder.js.map +1 -0
  27. package/dist/application/indexing/IndexingProgress.d.ts +34 -0
  28. package/dist/application/indexing/IndexingProgress.js +2 -0
  29. package/dist/application/indexing/IndexingProgress.js.map +1 -0
  30. package/dist/application/operations/Deadline.d.ts +13 -0
  31. package/dist/application/operations/Deadline.js +29 -0
  32. package/dist/application/operations/Deadline.js.map +1 -0
  33. package/dist/application/operations/HealthMonitor.d.ts +58 -0
  34. package/dist/application/operations/HealthMonitor.js +128 -0
  35. package/dist/application/operations/HealthMonitor.js.map +1 -0
  36. package/dist/application/operations/IndexAlternatives.d.ts +35 -0
  37. package/dist/application/operations/IndexAlternatives.js +61 -0
  38. package/dist/application/operations/IndexAlternatives.js.map +1 -0
  39. package/dist/application/operations/IndexInventory.d.ts +69 -0
  40. package/dist/application/operations/IndexInventory.js +99 -0
  41. package/dist/application/operations/IndexInventory.js.map +1 -0
  42. package/dist/application/operations/StatusService.d.ts +90 -0
  43. package/dist/application/operations/StatusService.js +171 -0
  44. package/dist/application/operations/StatusService.js.map +1 -0
  45. package/dist/application/operations/WatchService.d.ts +67 -0
  46. package/dist/application/operations/WatchService.js +145 -0
  47. package/dist/application/operations/WatchService.js.map +1 -0
  48. package/dist/application/operations/WorkingTreeDiff.d.ts +19 -0
  49. package/dist/application/operations/WorkingTreeDiff.js +36 -0
  50. package/dist/application/operations/WorkingTreeDiff.js.map +1 -0
  51. package/dist/application/research/ResearchAgent.d.ts +68 -0
  52. package/dist/application/research/ResearchAgent.js +201 -0
  53. package/dist/application/research/ResearchAgent.js.map +1 -0
  54. package/dist/application/research/ResearchPrompts.d.ts +16 -0
  55. package/dist/application/research/ResearchPrompts.js +34 -0
  56. package/dist/application/research/ResearchPrompts.js.map +1 -0
  57. package/dist/application/search/SearchCriteria.d.ts +37 -0
  58. package/dist/application/search/SearchCriteria.js +48 -0
  59. package/dist/application/search/SearchCriteria.js.map +1 -0
  60. package/dist/application/search/SearchService.d.ts +36 -0
  61. package/dist/application/search/SearchService.js +108 -0
  62. package/dist/application/search/SearchService.js.map +1 -0
  63. package/dist/application/search/SearchTargetResolver.d.ts +56 -0
  64. package/dist/application/search/SearchTargetResolver.js +104 -0
  65. package/dist/application/search/SearchTargetResolver.js.map +1 -0
  66. package/dist/cli.d.ts +1 -1
  67. package/dist/cli.js +4 -953
  68. package/dist/cli.js.map +1 -1
  69. package/dist/domain/config/ConfigSource.d.ts +16 -0
  70. package/dist/domain/config/ConfigSource.js +2 -0
  71. package/dist/domain/config/ConfigSource.js.map +1 -0
  72. package/dist/domain/config/LmgrepConfig.d.ts +53 -0
  73. package/dist/domain/config/LmgrepConfig.js +2 -0
  74. package/dist/domain/config/LmgrepConfig.js.map +1 -0
  75. package/dist/domain/corpus/Chunk.d.ts +49 -0
  76. package/dist/domain/corpus/Chunk.js +60 -0
  77. package/dist/domain/corpus/Chunk.js.map +1 -0
  78. package/dist/domain/corpus/CodeLocation.d.ts +18 -0
  79. package/dist/domain/corpus/CodeLocation.js +34 -0
  80. package/dist/domain/corpus/CodeLocation.js.map +1 -0
  81. package/dist/domain/corpus/ContentHash.d.ts +15 -0
  82. package/dist/domain/corpus/ContentHash.js +30 -0
  83. package/dist/domain/corpus/ContentHash.js.map +1 -0
  84. package/dist/domain/corpus/FileVersion.d.ts +31 -0
  85. package/dist/domain/corpus/FileVersion.js +47 -0
  86. package/dist/domain/corpus/FileVersion.js.map +1 -0
  87. package/dist/domain/corpus/SourceFile.d.ts +26 -0
  88. package/dist/domain/corpus/SourceFile.js +47 -0
  89. package/dist/domain/corpus/SourceFile.js.map +1 -0
  90. package/dist/domain/corpus/Vector.d.ts +37 -0
  91. package/dist/domain/corpus/Vector.js +96 -0
  92. package/dist/domain/corpus/Vector.js.map +1 -0
  93. package/dist/domain/ports/ChatModelPort.d.ts +57 -0
  94. package/dist/domain/ports/ChatModelPort.js +2 -0
  95. package/dist/domain/ports/ChatModelPort.js.map +1 -0
  96. package/dist/domain/ports/ChunkRepositoryPort.d.ts +42 -0
  97. package/dist/domain/ports/ChunkRepositoryPort.js +2 -0
  98. package/dist/domain/ports/ChunkRepositoryPort.js.map +1 -0
  99. package/dist/domain/ports/ChunkerPort.d.ts +5 -0
  100. package/dist/domain/ports/ChunkerPort.js +2 -0
  101. package/dist/domain/ports/ChunkerPort.js.map +1 -0
  102. package/dist/domain/ports/DatabaseSessionPort.d.ts +10 -0
  103. package/dist/domain/ports/DatabaseSessionPort.js +2 -0
  104. package/dist/domain/ports/DatabaseSessionPort.js.map +1 -0
  105. package/dist/domain/ports/EmbedderPort.d.ts +14 -0
  106. package/dist/domain/ports/EmbedderPort.js +2 -0
  107. package/dist/domain/ports/EmbedderPort.js.map +1 -0
  108. package/dist/domain/ports/FileManifestRepositoryPort.d.ts +32 -0
  109. package/dist/domain/ports/FileManifestRepositoryPort.js +2 -0
  110. package/dist/domain/ports/FileManifestRepositoryPort.js.map +1 -0
  111. package/dist/domain/ports/GitPort.d.ts +24 -0
  112. package/dist/domain/ports/GitPort.js +2 -0
  113. package/dist/domain/ports/GitPort.js.map +1 -0
  114. package/dist/domain/ports/IndexMaintenancePort.d.ts +58 -0
  115. package/dist/domain/ports/IndexMaintenancePort.js +2 -0
  116. package/dist/domain/ports/IndexMaintenancePort.js.map +1 -0
  117. package/dist/domain/ports/IndexMetadataPort.d.ts +23 -0
  118. package/dist/domain/ports/IndexMetadataPort.js +2 -0
  119. package/dist/domain/ports/IndexMetadataPort.js.map +1 -0
  120. package/dist/domain/ports/LockPort.d.ts +17 -0
  121. package/dist/domain/ports/LockPort.js +2 -0
  122. package/dist/domain/ports/LockPort.js.map +1 -0
  123. package/dist/domain/ports/LoggerPort.d.ts +5 -0
  124. package/dist/domain/ports/LoggerPort.js +2 -0
  125. package/dist/domain/ports/LoggerPort.js.map +1 -0
  126. package/dist/domain/ports/ProjectIndexesPort.d.ts +20 -0
  127. package/dist/domain/ports/ProjectIndexesPort.js +2 -0
  128. package/dist/domain/ports/ProjectIndexesPort.js.map +1 -0
  129. package/dist/domain/ports/ProjectRegistryPort.d.ts +42 -0
  130. package/dist/domain/ports/ProjectRegistryPort.js +2 -0
  131. package/dist/domain/ports/ProjectRegistryPort.js.map +1 -0
  132. package/dist/domain/ports/StateDirectoryPort.d.ts +29 -0
  133. package/dist/domain/ports/StateDirectoryPort.js +2 -0
  134. package/dist/domain/ports/StateDirectoryPort.js.map +1 -0
  135. package/dist/domain/ports/WorkspacePort.d.ts +38 -0
  136. package/dist/domain/ports/WorkspacePort.js +2 -0
  137. package/dist/domain/ports/WorkspacePort.js.map +1 -0
  138. package/dist/domain/project/Branch.d.ts +20 -0
  139. package/dist/domain/project/Branch.js +33 -0
  140. package/dist/domain/project/Branch.js.map +1 -0
  141. package/dist/domain/project/DatabaseLocation.d.ts +32 -0
  142. package/dist/domain/project/DatabaseLocation.js +35 -0
  143. package/dist/domain/project/DatabaseLocation.js.map +1 -0
  144. package/dist/domain/project/IndexMetadata.d.ts +17 -0
  145. package/dist/domain/project/IndexMetadata.js +2 -0
  146. package/dist/domain/project/IndexMetadata.js.map +1 -0
  147. package/dist/domain/project/ModelIdentity.d.ts +58 -0
  148. package/dist/domain/project/ModelIdentity.js +94 -0
  149. package/dist/domain/project/ModelIdentity.js.map +1 -0
  150. package/dist/domain/project/Project.d.ts +17 -0
  151. package/dist/domain/project/Project.js +21 -0
  152. package/dist/domain/project/Project.js.map +1 -0
  153. package/dist/domain/project/ProjectId.d.ts +28 -0
  154. package/dist/domain/project/ProjectId.js +58 -0
  155. package/dist/domain/project/ProjectId.js.map +1 -0
  156. package/dist/domain/project/ProjectLocator.d.ts +112 -0
  157. package/dist/domain/project/ProjectLocator.js +178 -0
  158. package/dist/domain/project/ProjectLocator.js.map +1 -0
  159. package/dist/domain/research/Citation.d.ts +27 -0
  160. package/dist/domain/research/Citation.js +43 -0
  161. package/dist/domain/research/Citation.js.map +1 -0
  162. package/dist/domain/research/EvidenceLedger.d.ts +47 -0
  163. package/dist/domain/research/EvidenceLedger.js +111 -0
  164. package/dist/domain/research/EvidenceLedger.js.map +1 -0
  165. package/dist/domain/research/ResearchTrace.d.ts +19 -0
  166. package/dist/domain/research/ResearchTrace.js +22 -0
  167. package/dist/domain/research/ResearchTrace.js.map +1 -0
  168. package/dist/domain/retrieval/Hit.d.ts +19 -0
  169. package/dist/domain/retrieval/Hit.js +28 -0
  170. package/dist/domain/retrieval/Hit.js.map +1 -0
  171. package/dist/domain/retrieval/HitList.d.ts +35 -0
  172. package/dist/domain/retrieval/HitList.js +81 -0
  173. package/dist/domain/retrieval/HitList.js.map +1 -0
  174. package/dist/domain/retrieval/MissingIndexError.d.ts +11 -0
  175. package/dist/domain/retrieval/MissingIndexError.js +15 -0
  176. package/dist/domain/retrieval/MissingIndexError.js.map +1 -0
  177. package/dist/index.d.ts +43 -45
  178. package/dist/index.js +30 -567
  179. package/dist/index.js.map +1 -1
  180. package/dist/infrastructure/ai/AiSdkChatModel.d.ts +31 -0
  181. package/dist/infrastructure/ai/AiSdkChatModel.js +137 -0
  182. package/dist/infrastructure/ai/AiSdkChatModel.js.map +1 -0
  183. package/dist/infrastructure/ai/AiSdkEmbedder.d.ts +28 -0
  184. package/dist/infrastructure/ai/AiSdkEmbedder.js +79 -0
  185. package/dist/infrastructure/ai/AiSdkEmbedder.js.map +1 -0
  186. package/dist/infrastructure/ai/DockerModelRunnerProbe.d.ts +16 -0
  187. package/dist/infrastructure/ai/DockerModelRunnerProbe.js +52 -0
  188. package/dist/infrastructure/ai/DockerModelRunnerProbe.js.map +1 -0
  189. package/dist/infrastructure/ai/EmbeddingPrefixes.d.ts +21 -0
  190. package/dist/infrastructure/ai/EmbeddingPrefixes.js +40 -0
  191. package/dist/infrastructure/ai/EmbeddingPrefixes.js.map +1 -0
  192. package/dist/infrastructure/ai/LmStudioProbe.d.ts +18 -0
  193. package/dist/infrastructure/ai/LmStudioProbe.js +49 -0
  194. package/dist/infrastructure/ai/LmStudioProbe.js.map +1 -0
  195. package/dist/infrastructure/ai/LocalModelReloader.d.ts +21 -0
  196. package/dist/infrastructure/ai/LocalModelReloader.js +61 -0
  197. package/dist/infrastructure/ai/LocalModelReloader.js.map +1 -0
  198. package/dist/infrastructure/ai/LocalRuntimeDetector.d.ts +36 -0
  199. package/dist/infrastructure/ai/LocalRuntimeDetector.js +63 -0
  200. package/dist/infrastructure/ai/LocalRuntimeDetector.js.map +1 -0
  201. package/dist/infrastructure/ai/ModelRuntime.d.ts +32 -0
  202. package/dist/infrastructure/ai/ModelRuntime.js +2 -0
  203. package/dist/infrastructure/ai/ModelRuntime.js.map +1 -0
  204. package/dist/infrastructure/ai/OllamaProbe.d.ts +22 -0
  205. package/dist/infrastructure/ai/OllamaProbe.js +71 -0
  206. package/dist/infrastructure/ai/OllamaProbe.js.map +1 -0
  207. package/dist/infrastructure/ai/ProviderFailure.d.ts +16 -0
  208. package/dist/infrastructure/ai/ProviderFailure.js +35 -0
  209. package/dist/infrastructure/ai/ProviderFailure.js.map +1 -0
  210. package/dist/infrastructure/ai/ProviderModuleLoader.d.ts +14 -0
  211. package/dist/infrastructure/ai/ProviderModuleLoader.js +56 -0
  212. package/dist/infrastructure/ai/ProviderModuleLoader.js.map +1 -0
  213. package/dist/infrastructure/ai/ProviderRegistry.d.ts +38 -0
  214. package/dist/infrastructure/ai/ProviderRegistry.js +63 -0
  215. package/dist/infrastructure/ai/ProviderRegistry.js.map +1 -0
  216. package/dist/infrastructure/fs/ConfigLoader.d.ts +59 -0
  217. package/dist/infrastructure/fs/ConfigLoader.js +194 -0
  218. package/dist/infrastructure/fs/ConfigLoader.js.map +1 -0
  219. package/dist/infrastructure/fs/DatabaseLocks.d.ts +52 -0
  220. package/dist/infrastructure/fs/DatabaseLocks.js +92 -0
  221. package/dist/infrastructure/fs/DatabaseLocks.js.map +1 -0
  222. package/dist/infrastructure/fs/DiskUsage.d.ts +6 -0
  223. package/dist/infrastructure/fs/DiskUsage.js +41 -0
  224. package/dist/infrastructure/fs/DiskUsage.js.map +1 -0
  225. package/dist/infrastructure/fs/IndexableFileRules.d.ts +33 -0
  226. package/dist/infrastructure/fs/IndexableFileRules.js +177 -0
  227. package/dist/infrastructure/fs/IndexableFileRules.js.map +1 -0
  228. package/dist/infrastructure/fs/Loggers.d.ts +14 -0
  229. package/dist/infrastructure/fs/Loggers.js +18 -0
  230. package/dist/infrastructure/fs/Loggers.js.map +1 -0
  231. package/dist/infrastructure/fs/PidFileLock.d.ts +40 -0
  232. package/dist/infrastructure/fs/PidFileLock.js +97 -0
  233. package/dist/infrastructure/fs/PidFileLock.js.map +1 -0
  234. package/dist/infrastructure/fs/ProjectIndexes.d.ts +8 -0
  235. package/dist/infrastructure/fs/ProjectIndexes.js +35 -0
  236. package/dist/infrastructure/fs/ProjectIndexes.js.map +1 -0
  237. package/dist/infrastructure/fs/ProjectMetadataStore.d.ts +42 -0
  238. package/dist/infrastructure/fs/ProjectMetadataStore.js +86 -0
  239. package/dist/infrastructure/fs/ProjectMetadataStore.js.map +1 -0
  240. package/dist/infrastructure/fs/ProjectRegistry.d.ts +25 -0
  241. package/dist/infrastructure/fs/ProjectRegistry.js +83 -0
  242. package/dist/infrastructure/fs/ProjectRegistry.js.map +1 -0
  243. package/dist/infrastructure/fs/StateDirectory.d.ts +28 -0
  244. package/dist/infrastructure/fs/StateDirectory.js +71 -0
  245. package/dist/infrastructure/fs/StateDirectory.js.map +1 -0
  246. package/dist/infrastructure/fs/Workspace.d.ts +25 -0
  247. package/dist/infrastructure/fs/Workspace.js +90 -0
  248. package/dist/infrastructure/fs/Workspace.js.map +1 -0
  249. package/dist/infrastructure/git/GitClient.d.ts +34 -0
  250. package/dist/infrastructure/git/GitClient.js +74 -0
  251. package/dist/infrastructure/git/GitClient.js.map +1 -0
  252. package/dist/infrastructure/lancedb/ChunkRepository.d.ts +38 -0
  253. package/dist/infrastructure/lancedb/ChunkRepository.js +166 -0
  254. package/dist/infrastructure/lancedb/ChunkRepository.js.map +1 -0
  255. package/dist/infrastructure/lancedb/DatabaseImporter.d.ts +22 -0
  256. package/dist/infrastructure/lancedb/DatabaseImporter.js +74 -0
  257. package/dist/infrastructure/lancedb/DatabaseImporter.js.map +1 -0
  258. package/dist/infrastructure/lancedb/FileManifestRepository.d.ts +34 -0
  259. package/dist/infrastructure/lancedb/FileManifestRepository.js +137 -0
  260. package/dist/infrastructure/lancedb/FileManifestRepository.js.map +1 -0
  261. package/dist/infrastructure/lancedb/IndexMaintenance.d.ts +53 -0
  262. package/dist/infrastructure/lancedb/IndexMaintenance.js +227 -0
  263. package/dist/infrastructure/lancedb/IndexMaintenance.js.map +1 -0
  264. package/dist/infrastructure/lancedb/LanceTables.d.ts +67 -0
  265. package/dist/infrastructure/lancedb/LanceTables.js +159 -0
  266. package/dist/infrastructure/lancedb/LanceTables.js.map +1 -0
  267. package/dist/{lib/native-tuning.js → infrastructure/lancedb/NativeTuning.js} +1 -1
  268. package/dist/infrastructure/lancedb/NativeTuning.js.map +1 -0
  269. package/dist/infrastructure/lancedb/RowReplication.d.ts +27 -0
  270. package/dist/infrastructure/lancedb/RowReplication.js +82 -0
  271. package/dist/infrastructure/lancedb/RowReplication.js.map +1 -0
  272. package/dist/infrastructure/lancedb/VectorIndexPolicy.d.ts +60 -0
  273. package/dist/infrastructure/lancedb/VectorIndexPolicy.js +72 -0
  274. package/dist/infrastructure/lancedb/VectorIndexPolicy.js.map +1 -0
  275. package/dist/infrastructure/p2p/IndexShare.d.ts +45 -0
  276. package/dist/infrastructure/p2p/IndexShare.js +160 -0
  277. package/dist/infrastructure/p2p/IndexShare.js.map +1 -0
  278. package/dist/infrastructure/p2p/PeerSwarm.d.ts +16 -0
  279. package/dist/infrastructure/p2p/PeerSwarm.js +41 -0
  280. package/dist/infrastructure/p2p/PeerSwarm.js.map +1 -0
  281. package/dist/infrastructure/p2p/SecureChannel.d.ts +60 -0
  282. package/dist/infrastructure/p2p/SecureChannel.js +71 -0
  283. package/dist/infrastructure/p2p/SecureChannel.js.map +1 -0
  284. package/dist/infrastructure/p2p/ShareCode.d.ts +25 -0
  285. package/dist/infrastructure/p2p/ShareCode.js +304 -0
  286. package/dist/infrastructure/p2p/ShareCode.js.map +1 -0
  287. package/dist/infrastructure/process/ProcessRegistry.d.ts +50 -0
  288. package/dist/infrastructure/process/ProcessRegistry.js +109 -0
  289. package/dist/infrastructure/process/ProcessRegistry.js.map +1 -0
  290. package/dist/infrastructure/treesitter/ChunkContextBuilder.d.ts +45 -0
  291. package/dist/infrastructure/treesitter/ChunkContextBuilder.js +159 -0
  292. package/dist/infrastructure/treesitter/ChunkContextBuilder.js.map +1 -0
  293. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.d.ts +8 -0
  294. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.js +12 -0
  295. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.js.map +1 -0
  296. package/dist/infrastructure/treesitter/LanguageCatalog.d.ts +30 -0
  297. package/dist/{lib/chunker/languages.js → infrastructure/treesitter/LanguageCatalog.js} +38 -29
  298. package/dist/infrastructure/treesitter/LanguageCatalog.js.map +1 -0
  299. package/dist/infrastructure/treesitter/SlidingWindowChunker.d.ts +15 -0
  300. package/dist/infrastructure/treesitter/SlidingWindowChunker.js +42 -0
  301. package/dist/infrastructure/treesitter/SlidingWindowChunker.js.map +1 -0
  302. package/dist/infrastructure/treesitter/TreeSitterChunker.d.ts +42 -0
  303. package/dist/infrastructure/treesitter/TreeSitterChunker.js +165 -0
  304. package/dist/infrastructure/treesitter/TreeSitterChunker.js.map +1 -0
  305. package/dist/mcp.d.ts +1 -1
  306. package/dist/mcp.js +14 -72
  307. package/dist/mcp.js.map +1 -1
  308. package/dist/presentation/cli/Cli.d.ts +31 -0
  309. package/dist/presentation/cli/Cli.js +120 -0
  310. package/dist/presentation/cli/Cli.js.map +1 -0
  311. package/dist/presentation/cli/CliOptions.d.ts +18 -0
  312. package/dist/presentation/cli/CliOptions.js +25 -0
  313. package/dist/presentation/cli/CliOptions.js.map +1 -0
  314. package/dist/presentation/cli/CommandContext.d.ts +50 -0
  315. package/dist/presentation/cli/CommandContext.js +88 -0
  316. package/dist/presentation/cli/CommandContext.js.map +1 -0
  317. package/dist/presentation/cli/ConfigTemplate.d.ts +31 -0
  318. package/dist/presentation/cli/ConfigTemplate.js +83 -0
  319. package/dist/presentation/cli/ConfigTemplate.js.map +1 -0
  320. package/dist/presentation/cli/Renderer.d.ts +90 -0
  321. package/dist/presentation/cli/Renderer.js +290 -0
  322. package/dist/presentation/cli/Renderer.js.map +1 -0
  323. package/dist/presentation/cli/commands/AskCommand.d.ts +14 -0
  324. package/dist/presentation/cli/commands/AskCommand.js +48 -0
  325. package/dist/presentation/cli/commands/AskCommand.js.map +1 -0
  326. package/dist/presentation/cli/commands/CompletionsCommand.d.ts +18 -0
  327. package/dist/presentation/cli/commands/CompletionsCommand.js +96 -0
  328. package/dist/presentation/cli/commands/CompletionsCommand.js.map +1 -0
  329. package/dist/presentation/cli/commands/ConfigCommands.d.ts +56 -0
  330. package/dist/presentation/cli/commands/ConfigCommands.js +220 -0
  331. package/dist/presentation/cli/commands/ConfigCommands.js.map +1 -0
  332. package/dist/presentation/cli/commands/IndexCommand.d.ts +18 -0
  333. package/dist/presentation/cli/commands/IndexCommand.js +54 -0
  334. package/dist/presentation/cli/commands/IndexCommand.js.map +1 -0
  335. package/dist/presentation/cli/commands/ProjectsCommand.d.ts +48 -0
  336. package/dist/presentation/cli/commands/ProjectsCommand.js +240 -0
  337. package/dist/presentation/cli/commands/ProjectsCommand.js.map +1 -0
  338. package/dist/presentation/cli/commands/SearchCommand.d.ts +19 -0
  339. package/dist/presentation/cli/commands/SearchCommand.js +55 -0
  340. package/dist/presentation/cli/commands/SearchCommand.js.map +1 -0
  341. package/dist/presentation/cli/commands/ServerCommands.d.ts +13 -0
  342. package/dist/presentation/cli/commands/ServerCommands.js +40 -0
  343. package/dist/presentation/cli/commands/ServerCommands.js.map +1 -0
  344. package/dist/presentation/cli/commands/ShareCommands.d.ts +22 -0
  345. package/dist/presentation/cli/commands/ShareCommands.js +134 -0
  346. package/dist/presentation/cli/commands/ShareCommands.js.map +1 -0
  347. package/dist/presentation/cli/commands/StatusCommand.d.ts +15 -0
  348. package/dist/presentation/cli/commands/StatusCommand.js +53 -0
  349. package/dist/presentation/cli/commands/StatusCommand.js.map +1 -0
  350. package/dist/presentation/mcp/HitFormatter.d.ts +17 -0
  351. package/dist/presentation/mcp/HitFormatter.js +42 -0
  352. package/dist/presentation/mcp/HitFormatter.js.map +1 -0
  353. package/dist/presentation/mcp/IndexWatchController.d.ts +17 -0
  354. package/dist/presentation/mcp/IndexWatchController.js +31 -0
  355. package/dist/presentation/mcp/IndexWatchController.js.map +1 -0
  356. package/dist/presentation/mcp/LmgrepCore.d.ts +66 -0
  357. package/dist/presentation/mcp/LmgrepCore.js +178 -0
  358. package/dist/presentation/mcp/LmgrepCore.js.map +1 -0
  359. package/dist/presentation/mcp/McpServer.d.ts +18 -0
  360. package/dist/presentation/mcp/McpServer.js +63 -0
  361. package/dist/presentation/mcp/McpServer.js.map +1 -0
  362. package/dist/presentation/mcp/ToolDescriptions.d.ts +40 -0
  363. package/dist/presentation/mcp/ToolDescriptions.js +85 -0
  364. package/dist/presentation/mcp/ToolDescriptions.js.map +1 -0
  365. package/package.json +93 -89
  366. package/dist/lib/build.d.ts +0 -21
  367. package/dist/lib/build.js +0 -374
  368. package/dist/lib/build.js.map +0 -1
  369. package/dist/lib/chunker/context.d.ts +0 -21
  370. package/dist/lib/chunker/context.js +0 -131
  371. package/dist/lib/chunker/context.js.map +0 -1
  372. package/dist/lib/chunker/index.d.ts +0 -7
  373. package/dist/lib/chunker/index.js +0 -209
  374. package/dist/lib/chunker/index.js.map +0 -1
  375. package/dist/lib/chunker/languages.d.ts +0 -15
  376. package/dist/lib/chunker/languages.js.map +0 -1
  377. package/dist/lib/config.d.ts +0 -12
  378. package/dist/lib/config.js +0 -83
  379. package/dist/lib/config.js.map +0 -1
  380. package/dist/lib/embedder.d.ts +0 -65
  381. package/dist/lib/embedder.js +0 -236
  382. package/dist/lib/embedder.js.map +0 -1
  383. package/dist/lib/facet-session.d.ts +0 -44
  384. package/dist/lib/facet-session.js +0 -125
  385. package/dist/lib/facet-session.js.map +0 -1
  386. package/dist/lib/native-tuning.js.map +0 -1
  387. package/dist/lib/p2p.d.ts +0 -32
  388. package/dist/lib/p2p.js +0 -281
  389. package/dist/lib/p2p.js.map +0 -1
  390. package/dist/lib/providers.d.ts +0 -1
  391. package/dist/lib/providers.js +0 -41
  392. package/dist/lib/providers.js.map +0 -1
  393. package/dist/lib/repair.d.ts +0 -10
  394. package/dist/lib/repair.js +0 -57
  395. package/dist/lib/repair.js.map +0 -1
  396. package/dist/lib/scanner.d.ts +0 -34
  397. package/dist/lib/scanner.js +0 -242
  398. package/dist/lib/scanner.js.map +0 -1
  399. package/dist/lib/search-tool.d.ts +0 -55
  400. package/dist/lib/search-tool.js +0 -319
  401. package/dist/lib/search-tool.js.map +0 -1
  402. package/dist/lib/serve.d.ts +0 -11
  403. package/dist/lib/serve.js +0 -144
  404. package/dist/lib/serve.js.map +0 -1
  405. package/dist/lib/store.d.ts +0 -252
  406. package/dist/lib/store.js +0 -1216
  407. package/dist/lib/store.js.map +0 -1
  408. package/dist/lib/types.d.ts +0 -194
  409. package/dist/lib/types.js +0 -13
  410. package/dist/lib/types.js.map +0 -1
  411. package/dist/lib/vocab.d.ts +0 -20
  412. package/dist/lib/vocab.js +0 -275
  413. package/dist/lib/vocab.js.map +0 -1
  414. /package/dist/{lib/native-tuning.d.ts → infrastructure/lancedb/NativeTuning.d.ts} +0 -0
@@ -0,0 +1,137 @@
1
+ import { ContentHash } from "../../domain/corpus/ContentHash.js";
2
+ import { FileManifest, } from "../../domain/corpus/SourceFile.js";
3
+ import { Branch } from "../../domain/project/Branch.js";
4
+ import { LanceTables, TableName } from "./LanceTables.js";
5
+ /**
6
+ * The branch-scoped file manifest in LanceDB.
7
+ *
8
+ * The current branch's manifest is cached because every search consults it to
9
+ * scope results, and re-reading it per query would dominate search latency.
10
+ * Anything that writes the manifest must {@link invalidate}.
11
+ */
12
+ export class FileManifestRepository {
13
+ tables;
14
+ branch;
15
+ cached;
16
+ constructor(tables, branch) {
17
+ this.tables = tables;
18
+ this.branch = branch;
19
+ }
20
+ async current() {
21
+ const table = await this.tables.table(TableName.Files);
22
+ if (!table)
23
+ return FileManifest.empty();
24
+ const rows = await table
25
+ .query()
26
+ .where(`branch = '${this.branch.toSqlLiteral()}'`)
27
+ .select(["filePath", "fileHash"])
28
+ .toArray();
29
+ return FileManifest.fromEntries(rows.map((r) => [
30
+ r.filePath,
31
+ ContentHash.fromStored(r.fileHash),
32
+ ]));
33
+ }
34
+ async branchVersions() {
35
+ if (this.cached)
36
+ return this.cached;
37
+ const table = await this.tables.table(TableName.Files);
38
+ if (!table)
39
+ return undefined;
40
+ this.cached = await this.current();
41
+ return this.cached;
42
+ }
43
+ invalidate() {
44
+ this.cached = undefined;
45
+ }
46
+ async upsert(entries) {
47
+ if (entries.length === 0)
48
+ return;
49
+ const records = entries.map((e) => ({
50
+ filePath: e.path,
51
+ fileHash: e.hash.toString(),
52
+ branch: this.branch.toString(),
53
+ }));
54
+ const { table, seeded } = await this.tables.tableOrCreate(TableName.Files, records);
55
+ if (seeded) {
56
+ this.invalidate();
57
+ return;
58
+ }
59
+ // Replace this branch's rows for these paths, leaving other branches'
60
+ // rows for the same paths untouched.
61
+ const paths = records.map((r) => r.filePath);
62
+ for (let i = 0; i < paths.length; i += LanceTables.FILTER_BATCH_SIZE) {
63
+ const batch = paths.slice(i, i + LanceTables.FILTER_BATCH_SIZE);
64
+ await table.delete(`branch = '${this.branch.toSqlLiteral()}' AND ${LanceTables.inFilter("filePath", batch)}`);
65
+ }
66
+ await table.add(records);
67
+ this.invalidate();
68
+ }
69
+ async deleteFiles(filePaths) {
70
+ const table = await this.tables.table(TableName.Files);
71
+ if (!table || filePaths.length === 0)
72
+ return;
73
+ for (let i = 0; i < filePaths.length; i += LanceTables.FILTER_BATCH_SIZE) {
74
+ const batch = filePaths.slice(i, i + LanceTables.FILTER_BATCH_SIZE);
75
+ await table.delete(`branch = '${this.branch.toSqlLiteral()}' AND ${LanceTables.inFilter("filePath", batch)}`);
76
+ }
77
+ this.invalidate();
78
+ }
79
+ /**
80
+ * Which of these file versions any branch has already indexed. A hit means
81
+ * the content is embedded, so the file can be registered on this branch
82
+ * without re-chunking it.
83
+ */
84
+ async knownHashes(hashes) {
85
+ const table = await this.tables.table(TableName.Files);
86
+ if (!table || hashes.length === 0)
87
+ return new Set();
88
+ return LanceTables.selectIn(table, "fileHash", hashes.map((h) => h.toString()));
89
+ }
90
+ async allEntries() {
91
+ const table = await this.tables.table(TableName.Files);
92
+ if (!table)
93
+ return [];
94
+ const rows = await table.query().toArray();
95
+ return rows.map((r) => ({
96
+ filePath: r.filePath,
97
+ fileHash: ContentHash.fromStored(r.fileHash),
98
+ branch: Branch.of(r.branch),
99
+ }));
100
+ }
101
+ async storedBranches() {
102
+ const table = await this.tables.table(TableName.Files);
103
+ if (!table)
104
+ return [];
105
+ const rows = await table.query().select(["branch"]).toArray();
106
+ return [...new Set(rows.map((r) => r.branch))];
107
+ }
108
+ async deleteBranch(branch) {
109
+ const table = await this.tables.table(TableName.Files);
110
+ if (!table)
111
+ return;
112
+ await table.delete(`branch = '${LanceTables.quote(branch)}'`);
113
+ this.invalidate();
114
+ }
115
+ /** Seed this branch's manifest from another's — used on a new branch. */
116
+ async copyFromBranch(sourceBranch) {
117
+ const table = await this.tables.table(TableName.Files);
118
+ if (!table)
119
+ return 0;
120
+ const rows = await table
121
+ .query()
122
+ .where(`branch = '${LanceTables.quote(sourceBranch)}'`)
123
+ .select(["filePath", "fileHash"])
124
+ .toArray();
125
+ if (rows.length === 0)
126
+ return 0;
127
+ const records = rows.map((r) => ({
128
+ filePath: r.filePath,
129
+ fileHash: r.fileHash,
130
+ branch: this.branch.toString(),
131
+ }));
132
+ await table.add(records);
133
+ this.invalidate();
134
+ return records.length;
135
+ }
136
+ }
137
+ //# sourceMappingURL=FileManifestRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileManifestRepository.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/FileManifestRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EACN,YAAY,GAEZ,MAAM,mCAAmC,CAAC;AAK3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I,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,CAAC;QAErB,MAAM,IAAI,GAAG,MAAM,KAAK;aACtB,KAAK,EAAE;aACP,KAAK,CAAC,aAAa,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC;aACtD,MAAM,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;aAChC,OAAO,EAAE,CAAC;QACZ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QAEhC,MAAM,OAAO,GAAc,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,QAAQ,EAAE,CAAC,CAAC,QAAkB;YAC9B,QAAQ,EAAE,CAAC,CAAC,QAAkB;YAC9B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;SAC9B,CAAC,CAAC,CAAC;QACJ,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,MAAM,CAAC;IACvB,CAAC;CACD"}
@@ -0,0 +1,53 @@
1
+ import type { FileManifestRepositoryPort } from "../../domain/ports/FileManifestRepositoryPort.js";
2
+ import type { DedupeReport, IndexMaintenancePort, OptimizeOptions, OptimizeReport, VectorIndexState } from "../../domain/ports/IndexMaintenancePort.js";
3
+ import { type LanceTables } from "./LanceTables.js";
4
+ /**
5
+ * Keeps the LanceDB tables compact and their ANN indexes current.
6
+ *
7
+ * Without a vector index LanceDB answers a search by brute force: it decodes
8
+ * every stored embedding to score it. At high dimensions that walks the whole
9
+ * table through memory per query, so peak RSS tracks index size roughly 1:1.
10
+ * IVF-PQ turns that into a handful of probes.
11
+ *
12
+ * Compaction matters for the same reason — small appends leave hundreds of
13
+ * fragments, each carrying its own decode buffers.
14
+ */
15
+ export declare class IndexMaintenance implements IndexMaintenancePort {
16
+ private readonly tables;
17
+ private readonly manifest;
18
+ /** Tables holding embeddings, and therefore wanting a vector index. */
19
+ private static readonly VECTOR_TABLES;
20
+ constructor(tables: LanceTables, manifest: FileManifestRepositoryPort);
21
+ /**
22
+ * Cheap and idempotent when there is nothing to do, so it is safe to call
23
+ * after every build.
24
+ */
25
+ optimize(options?: OptimizeOptions): Promise<OptimizeReport>;
26
+ /**
27
+ * What `lmgrep compact` runs: the same work as {@link optimize} but
28
+ * unconditional, plus compaction of the files table (which holds no
29
+ * embeddings, so it never needs a vector index).
30
+ */
31
+ compact(): Promise<OptimizeReport>;
32
+ /**
33
+ * Remove tables no longer part of the schema.
34
+ *
35
+ * Databases built before faceting was removed still carry a `vocab` table
36
+ * holding one embedding per corpus term — nothing reads it now, and at
37
+ * full embedding width that is real disk. Dropping it here means users
38
+ * reclaim the space by running the command they already run.
39
+ */
40
+ private dropLegacyTables;
41
+ private optimizeTable;
42
+ /**
43
+ * Remove rows that should not be there: exact id duplicates (from
44
+ * concurrent unlocked indexing) and chunks whose file version no branch
45
+ * references any more. Survivors are rewritten into a fresh table, which is
46
+ * also what reclaims the disk the dropped rows held.
47
+ */
48
+ dedupe(): Promise<DedupeReport>;
49
+ vectorIndexState(): Promise<VectorIndexState>;
50
+ reset(): Promise<void>;
51
+ /** Arrow rows carry typed arrays; LanceDB needs plain values to re-infer a schema. */
52
+ private toPlainRow;
53
+ }
@@ -0,0 +1,227 @@
1
+ import { Index } from "@lancedb/lancedb";
2
+ import { ChunkRepository } from "./ChunkRepository.js";
3
+ import { TableName } from "./LanceTables.js";
4
+ import { VectorIndexPolicy } from "./VectorIndexPolicy.js";
5
+ /**
6
+ * Keeps the LanceDB tables compact and their ANN indexes current.
7
+ *
8
+ * Without a vector index LanceDB answers a search by brute force: it decodes
9
+ * every stored embedding to score it. At high dimensions that walks the whole
10
+ * table through memory per query, so peak RSS tracks index size roughly 1:1.
11
+ * IVF-PQ turns that into a handful of probes.
12
+ *
13
+ * Compaction matters for the same reason — small appends leave hundreds of
14
+ * fragments, each carrying its own decode buffers.
15
+ */
16
+ export class IndexMaintenance {
17
+ tables;
18
+ manifest;
19
+ /** Tables holding embeddings, and therefore wanting a vector index. */
20
+ static VECTOR_TABLES = [TableName.Chunks];
21
+ constructor(tables, manifest) {
22
+ this.tables = tables;
23
+ this.manifest = manifest;
24
+ }
25
+ /**
26
+ * Cheap and idempotent when there is nothing to do, so it is safe to call
27
+ * after every build.
28
+ */
29
+ async optimize(options = {}) {
30
+ const report = { tables: [] };
31
+ for (const name of IndexMaintenance.VECTOR_TABLES) {
32
+ const table = await this.tables.table(name);
33
+ if (!table)
34
+ continue;
35
+ report.tables.push(await this.optimizeTable(name, table, options.force ?? false, options.create ?? false));
36
+ }
37
+ return report;
38
+ }
39
+ /**
40
+ * What `lmgrep compact` runs: the same work as {@link optimize} but
41
+ * unconditional, plus compaction of the files table (which holds no
42
+ * embeddings, so it never needs a vector index).
43
+ */
44
+ async compact() {
45
+ const report = await this.optimize({ force: true, create: true });
46
+ await this.dropLegacyTables(report);
47
+ const files = await this.tables.table(TableName.Files);
48
+ if (files) {
49
+ await files.optimize();
50
+ report.tables.push({
51
+ table: TableName.Files,
52
+ rows: await files.countRows(),
53
+ action: "optimized",
54
+ });
55
+ }
56
+ return report;
57
+ }
58
+ /**
59
+ * Remove tables no longer part of the schema.
60
+ *
61
+ * Databases built before faceting was removed still carry a `vocab` table
62
+ * holding one embedding per corpus term — nothing reads it now, and at
63
+ * full embedding width that is real disk. Dropping it here means users
64
+ * reclaim the space by running the command they already run.
65
+ */
66
+ async dropLegacyTables(report) {
67
+ const vocab = await this.tables.table(TableName.LegacyVocab);
68
+ if (!vocab)
69
+ return;
70
+ const rows = await vocab.countRows();
71
+ await this.tables.dropTable(TableName.LegacyVocab);
72
+ report.tables.push({
73
+ table: TableName.LegacyVocab,
74
+ rows,
75
+ action: "dropped",
76
+ });
77
+ }
78
+ async optimizeTable(name, table, force, create) {
79
+ const rows = await table.countRows();
80
+ // listIndices reports the columns each index covers, so this stays
81
+ // correct if a scalar index is ever added alongside the vector one.
82
+ const indices = await table.listIndices();
83
+ const vectorIndex = indices.find((i) => i.columns.includes("vector"));
84
+ if (!vectorIndex) {
85
+ // The size guard is not overridable. `force` means "don't wait for
86
+ // the tail to grow", not "cluster a table with too few vectors to
87
+ // cluster" — IVF-PQ on a small table trains empty partitions and
88
+ // degrades recall for no memory saving.
89
+ if (rows < VectorIndexPolicy.MIN_ROWS_FOR_ANN) {
90
+ return { table: name, rows, action: "skipped-small" };
91
+ }
92
+ if (!create) {
93
+ return { table: name, rows, action: "needs-index" };
94
+ }
95
+ // numPartitions and numSubVectors are left to LanceDB, which
96
+ // derives them from row count and dimensionality. Hard-coding them
97
+ // would only reproduce that rule for dimensions already seen.
98
+ await table.createIndex("vector", {
99
+ config: Index.ivfPq({
100
+ distanceType: VectorIndexPolicy.DISTANCE_TYPE,
101
+ }),
102
+ replace: true,
103
+ });
104
+ await table.optimize();
105
+ return { table: name, rows, action: "created" };
106
+ }
107
+ const stats = await table.indexStats(vectorIndex.name);
108
+ const unindexed = stats?.numUnindexedRows ?? 0;
109
+ const indexed = stats?.numIndexedRows ?? 0;
110
+ const tolerated = Math.max(VectorIndexPolicy.UNINDEXED_REINDEX_FLOOR, Math.floor(indexed * VectorIndexPolicy.UNINDEXED_REINDEX_RATIO));
111
+ if (!force && unindexed <= tolerated) {
112
+ return { table: name, rows, action: "up-to-date", unindexed };
113
+ }
114
+ // optimize() both compacts fragments and folds the unindexed tail into
115
+ // the existing index — no retraining from scratch.
116
+ await table.optimize();
117
+ return { table: name, rows, action: "optimized", unindexed };
118
+ }
119
+ /**
120
+ * Remove rows that should not be there: exact id duplicates (from
121
+ * concurrent unlocked indexing) and chunks whose file version no branch
122
+ * references any more. Survivors are rewritten into a fresh table, which is
123
+ * also what reclaims the disk the dropped rows held.
124
+ */
125
+ async dedupe() {
126
+ const table = await this.tables.table(TableName.Chunks);
127
+ if (!table) {
128
+ return { before: 0, after: 0, duplicateIds: 0, staleVersions: 0 };
129
+ }
130
+ const before = await table.countRows();
131
+ // (filePath, fileHash) pairs any branch still references.
132
+ const referenced = new Map();
133
+ for (const entry of await this.manifest.allEntries()) {
134
+ const set = referenced.get(entry.filePath) ?? new Set();
135
+ set.add(entry.fileHash.toString());
136
+ referenced.set(entry.filePath, set);
137
+ }
138
+ const kept = [];
139
+ const seenIds = new Set();
140
+ let duplicateIds = 0;
141
+ let staleVersions = 0;
142
+ const total = before;
143
+ const BATCH = 2000;
144
+ for (let offset = 0; offset < total; offset += BATCH) {
145
+ const rows = await table.query().limit(BATCH).offset(offset).toArray();
146
+ if (rows.length === 0)
147
+ break;
148
+ for (const row of rows) {
149
+ const id = row.id;
150
+ if (seenIds.has(id)) {
151
+ duplicateIds++;
152
+ continue;
153
+ }
154
+ seenIds.add(id);
155
+ const filePath = row.filePath;
156
+ const fileHash = row.fileHash ?? "";
157
+ // "" is the legacy wildcard — never stale.
158
+ if (fileHash !== "" && !referenced.get(filePath)?.has(fileHash)) {
159
+ staleVersions++;
160
+ continue;
161
+ }
162
+ kept.push(this.toPlainRow(row));
163
+ }
164
+ }
165
+ if (duplicateIds + staleVersions === 0) {
166
+ return { before, after: before, duplicateIds, staleVersions };
167
+ }
168
+ await this.tables.dropTable(TableName.Chunks);
169
+ if (kept.length > 0) {
170
+ const { table: rebuilt, seeded } = await this.tables.tableOrCreate(TableName.Chunks, kept);
171
+ if (!seeded)
172
+ await rebuilt.add(kept);
173
+ }
174
+ return { before, after: kept.length, duplicateIds, staleVersions };
175
+ }
176
+ async vectorIndexState() {
177
+ const table = await this.tables.table(TableName.Chunks);
178
+ if (!table) {
179
+ return { rows: 0, built: false, unindexed: 0, worthBuilding: false };
180
+ }
181
+ const rows = await table.countRows();
182
+ const index = (await table.listIndices()).find((i) => i.columns.includes("vector"));
183
+ if (!index) {
184
+ return {
185
+ rows,
186
+ built: false,
187
+ unindexed: rows,
188
+ worthBuilding: rows >= VectorIndexPolicy.MIN_ROWS_FOR_ANN,
189
+ };
190
+ }
191
+ const stats = await table.indexStats(index.name);
192
+ return {
193
+ rows,
194
+ built: true,
195
+ unindexed: stats?.numUnindexedRows ?? 0,
196
+ worthBuilding: true,
197
+ };
198
+ }
199
+ async reset() {
200
+ for (const name of [
201
+ TableName.Chunks,
202
+ TableName.Files,
203
+ TableName.LegacyVocab,
204
+ ]) {
205
+ await this.tables.dropTable(name);
206
+ }
207
+ this.manifest.invalidate();
208
+ }
209
+ /** Arrow rows carry typed arrays; LanceDB needs plain values to re-infer a schema. */
210
+ toPlainRow(row) {
211
+ const chunk = ChunkRepository.rowToChunk(row);
212
+ return {
213
+ id: row.id,
214
+ filePath: chunk.location.filePath,
215
+ startLine: chunk.location.startLine,
216
+ endLine: chunk.location.endLine,
217
+ type: chunk.type,
218
+ name: chunk.name,
219
+ content: chunk.content,
220
+ context: chunk.context,
221
+ hash: chunk.hash.toString(),
222
+ fileHash: chunk.fileVersion.toStored(),
223
+ vector: Array.from(row.vector),
224
+ };
225
+ }
226
+ }
227
+ //# sourceMappingURL=IndexMaintenance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexMaintenance.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/IndexMaintenance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;AAUrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAoB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,gBAAgB;IAKV;IACA;IALlB,uEAAuE;IAC/D,MAAM,CAAU,aAAa,GAAG,CAAC,SAAS,CAAC,MAAM,CAAU,CAAC;IAEpE,YACkB,MAAmB,EACnB,QAAoC;QADpC,WAAM,GAAN,MAAM,CAAa;QACn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AC,CAAC;QAC9C,OAAO;YACN,EAAE,EAAE,GAAG,CAAC,EAAY;YACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACjC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;YACnC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO;YAC/B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC3B,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE;YACtC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAA0B,CAAC;SAClD,CAAC;IACH,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { type Table } from "@lancedb/lancedb";
2
+ import type { Branch } from "../../domain/project/Branch.js";
3
+ /**
4
+ * Table names inside a LanceDB database directory.
5
+ *
6
+ * A const object rather than a `const enum`: const enums are erased at emit,
7
+ * so importing one across modules compiles but can vanish at runtime.
8
+ */
9
+ export declare const TableName: {
10
+ readonly Chunks: "chunks";
11
+ readonly Files: "files";
12
+ /**
13
+ * Written by the removed faceting feature. Nothing reads it; it is listed
14
+ * so maintenance can drop it and give the disk back.
15
+ */
16
+ readonly LegacyVocab: "vocab";
17
+ };
18
+ export type TableName = (typeof TableName)[keyof typeof TableName];
19
+ /**
20
+ * Shared access to one LanceDB database: connecting, opening tables lazily,
21
+ * and running the schema backfills legacy databases need.
22
+ *
23
+ * The repositories share an instance so they share a connection — LanceDB
24
+ * connections are per-directory and opening several would multiply the native
25
+ * runtime's memory.
26
+ */
27
+ export declare class LanceTables {
28
+ readonly path: string;
29
+ private readonly branch;
30
+ /**
31
+ * Predicates are built by string interpolation, so batches are kept small
32
+ * enough that no single filter grows unreasonably long.
33
+ */
34
+ static readonly FILTER_BATCH_SIZE = 50;
35
+ private db;
36
+ private readonly open;
37
+ constructor(path: string, branch: Branch);
38
+ private connection;
39
+ /** Open a table, or undefined when the database has never held it. */
40
+ table(name: TableName): Promise<Table | undefined>;
41
+ /**
42
+ * Open a table, creating it from `seed` rows when it does not exist.
43
+ * `seeded` says whether creation consumed the rows, so the caller knows not
44
+ * to insert them a second time.
45
+ */
46
+ tableOrCreate(name: TableName, seed: Record<string, unknown>[]): Promise<{
47
+ table: Table;
48
+ seeded: boolean;
49
+ }>;
50
+ tableNames(): Promise<string[]>;
51
+ dropTable(name: TableName): Promise<void>;
52
+ /** Forget cached handles so the next access re-opens and re-migrates. */
53
+ forget(name?: TableName): void;
54
+ close(): void;
55
+ /** `column IN ('a', 'b')`, with values single-quote escaped. */
56
+ static inFilter(column: string, values: readonly string[]): string;
57
+ static quote(value: string): string;
58
+ /** Run `column IN (...)` deletes in batches small enough for one predicate. */
59
+ static deleteIn(table: Table, column: string, values: readonly string[]): Promise<void>;
60
+ /** Run a batched `column IN (...)` select, collecting one column's values. */
61
+ static selectIn(table: Table, column: string, values: readonly string[]): Promise<Set<string>>;
62
+ /**
63
+ * Backfill columns that legacy databases predate. Both are additive and
64
+ * idempotent — a table that already has the column is left alone.
65
+ */
66
+ private migrate;
67
+ }
@@ -0,0 +1,159 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { connect } from "@lancedb/lancedb";
3
+ /**
4
+ * Table names inside a LanceDB database directory.
5
+ *
6
+ * A const object rather than a `const enum`: const enums are erased at emit,
7
+ * so importing one across modules compiles but can vanish at runtime.
8
+ */
9
+ export const TableName = {
10
+ Chunks: "chunks",
11
+ Files: "files",
12
+ /**
13
+ * Written by the removed faceting feature. Nothing reads it; it is listed
14
+ * so maintenance can drop it and give the disk back.
15
+ */
16
+ LegacyVocab: "vocab",
17
+ };
18
+ /**
19
+ * Shared access to one LanceDB database: connecting, opening tables lazily,
20
+ * and running the schema backfills legacy databases need.
21
+ *
22
+ * The repositories share an instance so they share a connection — LanceDB
23
+ * connections are per-directory and opening several would multiply the native
24
+ * runtime's memory.
25
+ */
26
+ export class LanceTables {
27
+ path;
28
+ branch;
29
+ /**
30
+ * Predicates are built by string interpolation, so batches are kept small
31
+ * enough that no single filter grows unreasonably long.
32
+ */
33
+ static FILTER_BATCH_SIZE = 50;
34
+ db;
35
+ open = new Map();
36
+ constructor(path, branch) {
37
+ this.path = path;
38
+ this.branch = branch;
39
+ }
40
+ async connection() {
41
+ if (this.db)
42
+ return this.db;
43
+ mkdirSync(this.path, { recursive: true });
44
+ this.db = await connect(this.path);
45
+ return this.db;
46
+ }
47
+ /** Open a table, or undefined when the database has never held it. */
48
+ async table(name) {
49
+ const cached = this.open.get(name);
50
+ if (cached)
51
+ return cached;
52
+ const conn = await this.connection();
53
+ const names = await conn.tableNames();
54
+ if (!names.includes(name))
55
+ return undefined;
56
+ const table = await conn.openTable(name);
57
+ await this.migrate(name, table);
58
+ this.open.set(name, table);
59
+ return table;
60
+ }
61
+ /**
62
+ * Open a table, creating it from `seed` rows when it does not exist.
63
+ * `seeded` says whether creation consumed the rows, so the caller knows not
64
+ * to insert them a second time.
65
+ */
66
+ async tableOrCreate(name, seed) {
67
+ const existing = await this.table(name);
68
+ if (existing)
69
+ return { table: existing, seeded: false };
70
+ const conn = await this.connection();
71
+ const created = await conn.createTable(name, seed);
72
+ this.open.set(name, created);
73
+ return { table: created, seeded: true };
74
+ }
75
+ async tableNames() {
76
+ return (await this.connection()).tableNames();
77
+ }
78
+ async dropTable(name) {
79
+ const conn = await this.connection();
80
+ const names = await conn.tableNames();
81
+ if (names.includes(name))
82
+ await conn.dropTable(name);
83
+ this.open.delete(name);
84
+ }
85
+ /** Forget cached handles so the next access re-opens and re-migrates. */
86
+ forget(name) {
87
+ if (name)
88
+ this.open.delete(name);
89
+ else
90
+ this.open.clear();
91
+ }
92
+ close() {
93
+ this.open.clear();
94
+ this.db = undefined;
95
+ }
96
+ /** `column IN ('a', 'b')`, with values single-quote escaped. */
97
+ static inFilter(column, values) {
98
+ const escaped = values.map((v) => `'${v.replace(/'/g, "''")}'`);
99
+ return `${column} IN (${escaped.join(", ")})`;
100
+ }
101
+ static quote(value) {
102
+ return value.replace(/'/g, "''");
103
+ }
104
+ /** Run `column IN (...)` deletes in batches small enough for one predicate. */
105
+ static async deleteIn(table, column, values) {
106
+ for (let i = 0; i < values.length; i += LanceTables.FILTER_BATCH_SIZE) {
107
+ const batch = values.slice(i, i + LanceTables.FILTER_BATCH_SIZE);
108
+ await table.delete(LanceTables.inFilter(column, batch));
109
+ }
110
+ }
111
+ /** Run a batched `column IN (...)` select, collecting one column's values. */
112
+ static async selectIn(table, column, values) {
113
+ const found = new Set();
114
+ for (let i = 0; i < values.length; i += LanceTables.FILTER_BATCH_SIZE) {
115
+ const batch = values.slice(i, i + LanceTables.FILTER_BATCH_SIZE);
116
+ const rows = await table
117
+ .query()
118
+ .where(LanceTables.inFilter(column, batch))
119
+ .select([column])
120
+ .toArray();
121
+ for (const r of rows)
122
+ found.add(r[column]);
123
+ }
124
+ return found;
125
+ }
126
+ /**
127
+ * Backfill columns that legacy databases predate. Both are additive and
128
+ * idempotent — a table that already has the column is left alone.
129
+ */
130
+ async migrate(name, table) {
131
+ if (name === TableName.Files) {
132
+ // Pre branch-scoping `files` tables have no `branch` column. Fill it
133
+ // with the current branch so branch-filtered queries keep working.
134
+ const schema = await table.schema();
135
+ if (schema.fields.some((f) => f.name === "branch"))
136
+ return;
137
+ await table.addColumns([
138
+ {
139
+ name: "branch",
140
+ valueSql: `CAST('${LanceTables.quote(this.branch.toString())}' AS STRING)`,
141
+ },
142
+ ]);
143
+ return;
144
+ }
145
+ if (name === TableName.Chunks) {
146
+ // Pre version-scoping `chunks` tables have no `fileHash`. Fill it
147
+ // with "" — treated as a wildcard at search time, so legacy chunks
148
+ // keep appearing until their file is re-indexed and gets a real
149
+ // version hash.
150
+ const schema = await table.schema();
151
+ if (schema.fields.some((f) => f.name === "fileHash"))
152
+ return;
153
+ await table.addColumns([
154
+ { name: "fileHash", valueSql: `CAST('' AS STRING)` },
155
+ ]);
156
+ }
157
+ }
158
+ }
159
+ //# sourceMappingURL=LanceTables.js.map