lmgrep 0.1.17 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (401) hide show
  1. package/README.md +226 -63
  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 +5 -754
  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 +97 -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 -33
  178. package/dist/index.js +32 -215
  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/EmbeddingPrefixes.d.ts +21 -0
  187. package/dist/infrastructure/ai/EmbeddingPrefixes.js +40 -0
  188. package/dist/infrastructure/ai/EmbeddingPrefixes.js.map +1 -0
  189. package/dist/infrastructure/ai/LmStudioProbe.d.ts +18 -0
  190. package/dist/infrastructure/ai/LmStudioProbe.js +49 -0
  191. package/dist/infrastructure/ai/LmStudioProbe.js.map +1 -0
  192. package/dist/infrastructure/ai/LocalModelReloader.d.ts +21 -0
  193. package/dist/infrastructure/ai/LocalModelReloader.js +61 -0
  194. package/dist/infrastructure/ai/LocalModelReloader.js.map +1 -0
  195. package/dist/infrastructure/ai/LocalRuntimeDetector.d.ts +36 -0
  196. package/dist/infrastructure/ai/LocalRuntimeDetector.js +61 -0
  197. package/dist/infrastructure/ai/LocalRuntimeDetector.js.map +1 -0
  198. package/dist/infrastructure/ai/ModelRuntime.d.ts +32 -0
  199. package/dist/infrastructure/ai/ModelRuntime.js +2 -0
  200. package/dist/infrastructure/ai/ModelRuntime.js.map +1 -0
  201. package/dist/infrastructure/ai/OllamaProbe.d.ts +21 -0
  202. package/dist/infrastructure/ai/OllamaProbe.js +69 -0
  203. package/dist/infrastructure/ai/OllamaProbe.js.map +1 -0
  204. package/dist/infrastructure/ai/ProviderFailure.d.ts +16 -0
  205. package/dist/infrastructure/ai/ProviderFailure.js +35 -0
  206. package/dist/infrastructure/ai/ProviderFailure.js.map +1 -0
  207. package/dist/infrastructure/ai/ProviderModuleLoader.d.ts +13 -0
  208. package/dist/infrastructure/ai/ProviderModuleLoader.js +49 -0
  209. package/dist/infrastructure/ai/ProviderModuleLoader.js.map +1 -0
  210. package/dist/infrastructure/ai/ProviderRegistry.d.ts +37 -0
  211. package/dist/infrastructure/ai/ProviderRegistry.js +55 -0
  212. package/dist/infrastructure/ai/ProviderRegistry.js.map +1 -0
  213. package/dist/infrastructure/fs/ConfigLoader.d.ts +59 -0
  214. package/dist/infrastructure/fs/ConfigLoader.js +194 -0
  215. package/dist/infrastructure/fs/ConfigLoader.js.map +1 -0
  216. package/dist/infrastructure/fs/DatabaseLocks.d.ts +52 -0
  217. package/dist/infrastructure/fs/DatabaseLocks.js +92 -0
  218. package/dist/infrastructure/fs/DatabaseLocks.js.map +1 -0
  219. package/dist/infrastructure/fs/DiskUsage.d.ts +6 -0
  220. package/dist/infrastructure/fs/DiskUsage.js +41 -0
  221. package/dist/infrastructure/fs/DiskUsage.js.map +1 -0
  222. package/dist/infrastructure/fs/IndexableFileRules.d.ts +33 -0
  223. package/dist/infrastructure/fs/IndexableFileRules.js +177 -0
  224. package/dist/infrastructure/fs/IndexableFileRules.js.map +1 -0
  225. package/dist/infrastructure/fs/Loggers.d.ts +14 -0
  226. package/dist/infrastructure/fs/Loggers.js +18 -0
  227. package/dist/infrastructure/fs/Loggers.js.map +1 -0
  228. package/dist/infrastructure/fs/PidFileLock.d.ts +40 -0
  229. package/dist/infrastructure/fs/PidFileLock.js +97 -0
  230. package/dist/infrastructure/fs/PidFileLock.js.map +1 -0
  231. package/dist/infrastructure/fs/ProjectIndexes.d.ts +8 -0
  232. package/dist/infrastructure/fs/ProjectIndexes.js +35 -0
  233. package/dist/infrastructure/fs/ProjectIndexes.js.map +1 -0
  234. package/dist/infrastructure/fs/ProjectMetadataStore.d.ts +42 -0
  235. package/dist/infrastructure/fs/ProjectMetadataStore.js +86 -0
  236. package/dist/infrastructure/fs/ProjectMetadataStore.js.map +1 -0
  237. package/dist/infrastructure/fs/ProjectRegistry.d.ts +25 -0
  238. package/dist/infrastructure/fs/ProjectRegistry.js +83 -0
  239. package/dist/infrastructure/fs/ProjectRegistry.js.map +1 -0
  240. package/dist/infrastructure/fs/StateDirectory.d.ts +28 -0
  241. package/dist/infrastructure/fs/StateDirectory.js +71 -0
  242. package/dist/infrastructure/fs/StateDirectory.js.map +1 -0
  243. package/dist/infrastructure/fs/Workspace.d.ts +25 -0
  244. package/dist/infrastructure/fs/Workspace.js +90 -0
  245. package/dist/infrastructure/fs/Workspace.js.map +1 -0
  246. package/dist/infrastructure/git/GitClient.d.ts +34 -0
  247. package/dist/infrastructure/git/GitClient.js +74 -0
  248. package/dist/infrastructure/git/GitClient.js.map +1 -0
  249. package/dist/infrastructure/lancedb/ChunkRepository.d.ts +38 -0
  250. package/dist/infrastructure/lancedb/ChunkRepository.js +166 -0
  251. package/dist/infrastructure/lancedb/ChunkRepository.js.map +1 -0
  252. package/dist/infrastructure/lancedb/DatabaseImporter.d.ts +22 -0
  253. package/dist/infrastructure/lancedb/DatabaseImporter.js +74 -0
  254. package/dist/infrastructure/lancedb/DatabaseImporter.js.map +1 -0
  255. package/dist/infrastructure/lancedb/FileManifestRepository.d.ts +34 -0
  256. package/dist/infrastructure/lancedb/FileManifestRepository.js +137 -0
  257. package/dist/infrastructure/lancedb/FileManifestRepository.js.map +1 -0
  258. package/dist/infrastructure/lancedb/IndexMaintenance.d.ts +53 -0
  259. package/dist/infrastructure/lancedb/IndexMaintenance.js +227 -0
  260. package/dist/infrastructure/lancedb/IndexMaintenance.js.map +1 -0
  261. package/dist/infrastructure/lancedb/LanceTables.d.ts +67 -0
  262. package/dist/infrastructure/lancedb/LanceTables.js +159 -0
  263. package/dist/infrastructure/lancedb/LanceTables.js.map +1 -0
  264. package/dist/infrastructure/lancedb/NativeTuning.d.ts +1 -0
  265. package/dist/infrastructure/lancedb/NativeTuning.js +9 -0
  266. package/dist/infrastructure/lancedb/NativeTuning.js.map +1 -0
  267. package/dist/infrastructure/lancedb/RowReplication.d.ts +27 -0
  268. package/dist/infrastructure/lancedb/RowReplication.js +82 -0
  269. package/dist/infrastructure/lancedb/RowReplication.js.map +1 -0
  270. package/dist/infrastructure/lancedb/VectorIndexPolicy.d.ts +60 -0
  271. package/dist/infrastructure/lancedb/VectorIndexPolicy.js +72 -0
  272. package/dist/infrastructure/lancedb/VectorIndexPolicy.js.map +1 -0
  273. package/dist/infrastructure/p2p/IndexShare.d.ts +45 -0
  274. package/dist/infrastructure/p2p/IndexShare.js +160 -0
  275. package/dist/infrastructure/p2p/IndexShare.js.map +1 -0
  276. package/dist/infrastructure/p2p/PeerSwarm.d.ts +16 -0
  277. package/dist/infrastructure/p2p/PeerSwarm.js +41 -0
  278. package/dist/infrastructure/p2p/PeerSwarm.js.map +1 -0
  279. package/dist/infrastructure/p2p/SecureChannel.d.ts +60 -0
  280. package/dist/infrastructure/p2p/SecureChannel.js +71 -0
  281. package/dist/infrastructure/p2p/SecureChannel.js.map +1 -0
  282. package/dist/infrastructure/p2p/ShareCode.d.ts +25 -0
  283. package/dist/infrastructure/p2p/ShareCode.js +304 -0
  284. package/dist/infrastructure/p2p/ShareCode.js.map +1 -0
  285. package/dist/infrastructure/process/ProcessRegistry.d.ts +50 -0
  286. package/dist/infrastructure/process/ProcessRegistry.js +109 -0
  287. package/dist/infrastructure/process/ProcessRegistry.js.map +1 -0
  288. package/dist/infrastructure/treesitter/ChunkContextBuilder.d.ts +45 -0
  289. package/dist/infrastructure/treesitter/ChunkContextBuilder.js +159 -0
  290. package/dist/infrastructure/treesitter/ChunkContextBuilder.js.map +1 -0
  291. package/dist/infrastructure/treesitter/LanguageCatalog.d.ts +30 -0
  292. package/dist/{lib/chunker/languages.js → infrastructure/treesitter/LanguageCatalog.js} +65 -41
  293. package/dist/infrastructure/treesitter/LanguageCatalog.js.map +1 -0
  294. package/dist/infrastructure/treesitter/SlidingWindowChunker.d.ts +15 -0
  295. package/dist/infrastructure/treesitter/SlidingWindowChunker.js +42 -0
  296. package/dist/infrastructure/treesitter/SlidingWindowChunker.js.map +1 -0
  297. package/dist/infrastructure/treesitter/TreeSitterChunker.d.ts +42 -0
  298. package/dist/infrastructure/treesitter/TreeSitterChunker.js +163 -0
  299. package/dist/infrastructure/treesitter/TreeSitterChunker.js.map +1 -0
  300. package/dist/mcp.d.ts +1 -1
  301. package/dist/mcp.js +15 -61
  302. package/dist/mcp.js.map +1 -1
  303. package/dist/presentation/cli/Cli.d.ts +31 -0
  304. package/dist/presentation/cli/Cli.js +120 -0
  305. package/dist/presentation/cli/Cli.js.map +1 -0
  306. package/dist/presentation/cli/CliOptions.d.ts +18 -0
  307. package/dist/presentation/cli/CliOptions.js +25 -0
  308. package/dist/presentation/cli/CliOptions.js.map +1 -0
  309. package/dist/presentation/cli/CommandContext.d.ts +50 -0
  310. package/dist/presentation/cli/CommandContext.js +88 -0
  311. package/dist/presentation/cli/CommandContext.js.map +1 -0
  312. package/dist/presentation/cli/ConfigTemplate.d.ts +31 -0
  313. package/dist/presentation/cli/ConfigTemplate.js +83 -0
  314. package/dist/presentation/cli/ConfigTemplate.js.map +1 -0
  315. package/dist/presentation/cli/Renderer.d.ts +90 -0
  316. package/dist/presentation/cli/Renderer.js +290 -0
  317. package/dist/presentation/cli/Renderer.js.map +1 -0
  318. package/dist/presentation/cli/commands/AskCommand.d.ts +14 -0
  319. package/dist/presentation/cli/commands/AskCommand.js +48 -0
  320. package/dist/presentation/cli/commands/AskCommand.js.map +1 -0
  321. package/dist/presentation/cli/commands/CompletionsCommand.d.ts +18 -0
  322. package/dist/presentation/cli/commands/CompletionsCommand.js +96 -0
  323. package/dist/presentation/cli/commands/CompletionsCommand.js.map +1 -0
  324. package/dist/presentation/cli/commands/ConfigCommands.d.ts +55 -0
  325. package/dist/presentation/cli/commands/ConfigCommands.js +204 -0
  326. package/dist/presentation/cli/commands/ConfigCommands.js.map +1 -0
  327. package/dist/presentation/cli/commands/IndexCommand.d.ts +18 -0
  328. package/dist/presentation/cli/commands/IndexCommand.js +54 -0
  329. package/dist/presentation/cli/commands/IndexCommand.js.map +1 -0
  330. package/dist/presentation/cli/commands/ProjectsCommand.d.ts +48 -0
  331. package/dist/presentation/cli/commands/ProjectsCommand.js +240 -0
  332. package/dist/presentation/cli/commands/ProjectsCommand.js.map +1 -0
  333. package/dist/presentation/cli/commands/SearchCommand.d.ts +19 -0
  334. package/dist/presentation/cli/commands/SearchCommand.js +55 -0
  335. package/dist/presentation/cli/commands/SearchCommand.js.map +1 -0
  336. package/dist/presentation/cli/commands/ServerCommands.d.ts +13 -0
  337. package/dist/presentation/cli/commands/ServerCommands.js +40 -0
  338. package/dist/presentation/cli/commands/ServerCommands.js.map +1 -0
  339. package/dist/presentation/cli/commands/ShareCommands.d.ts +22 -0
  340. package/dist/presentation/cli/commands/ShareCommands.js +134 -0
  341. package/dist/presentation/cli/commands/ShareCommands.js.map +1 -0
  342. package/dist/presentation/cli/commands/StatusCommand.d.ts +15 -0
  343. package/dist/presentation/cli/commands/StatusCommand.js +53 -0
  344. package/dist/presentation/cli/commands/StatusCommand.js.map +1 -0
  345. package/dist/presentation/mcp/HitFormatter.d.ts +17 -0
  346. package/dist/presentation/mcp/HitFormatter.js +42 -0
  347. package/dist/presentation/mcp/HitFormatter.js.map +1 -0
  348. package/dist/presentation/mcp/IndexWatchController.d.ts +17 -0
  349. package/dist/presentation/mcp/IndexWatchController.js +31 -0
  350. package/dist/presentation/mcp/IndexWatchController.js.map +1 -0
  351. package/dist/presentation/mcp/LmgrepCore.d.ts +66 -0
  352. package/dist/presentation/mcp/LmgrepCore.js +178 -0
  353. package/dist/presentation/mcp/LmgrepCore.js.map +1 -0
  354. package/dist/presentation/mcp/McpServer.d.ts +18 -0
  355. package/dist/presentation/mcp/McpServer.js +63 -0
  356. package/dist/presentation/mcp/McpServer.js.map +1 -0
  357. package/dist/presentation/mcp/ToolDescriptions.d.ts +40 -0
  358. package/dist/presentation/mcp/ToolDescriptions.js +85 -0
  359. package/dist/presentation/mcp/ToolDescriptions.js.map +1 -0
  360. package/package.json +84 -63
  361. package/dist/lib/build.d.ts +0 -7
  362. package/dist/lib/build.js +0 -284
  363. package/dist/lib/build.js.map +0 -1
  364. package/dist/lib/chunker/context.d.ts +0 -21
  365. package/dist/lib/chunker/context.js +0 -131
  366. package/dist/lib/chunker/context.js.map +0 -1
  367. package/dist/lib/chunker/index.d.ts +0 -7
  368. package/dist/lib/chunker/index.js +0 -150
  369. package/dist/lib/chunker/index.js.map +0 -1
  370. package/dist/lib/chunker/languages.d.ts +0 -15
  371. package/dist/lib/chunker/languages.js.map +0 -1
  372. package/dist/lib/config.d.ts +0 -12
  373. package/dist/lib/config.js +0 -83
  374. package/dist/lib/config.js.map +0 -1
  375. package/dist/lib/embedder.d.ts +0 -55
  376. package/dist/lib/embedder.js +0 -221
  377. package/dist/lib/embedder.js.map +0 -1
  378. package/dist/lib/p2p.d.ts +0 -32
  379. package/dist/lib/p2p.js +0 -281
  380. package/dist/lib/p2p.js.map +0 -1
  381. package/dist/lib/providers.d.ts +0 -1
  382. package/dist/lib/providers.js +0 -41
  383. package/dist/lib/providers.js.map +0 -1
  384. package/dist/lib/repair.d.ts +0 -10
  385. package/dist/lib/repair.js +0 -57
  386. package/dist/lib/repair.js.map +0 -1
  387. package/dist/lib/scanner.d.ts +0 -34
  388. package/dist/lib/scanner.js +0 -242
  389. package/dist/lib/scanner.js.map +0 -1
  390. package/dist/lib/search-tool.d.ts +0 -47
  391. package/dist/lib/search-tool.js +0 -239
  392. package/dist/lib/search-tool.js.map +0 -1
  393. package/dist/lib/serve.d.ts +0 -11
  394. package/dist/lib/serve.js +0 -127
  395. package/dist/lib/serve.js.map +0 -1
  396. package/dist/lib/store.d.ts +0 -177
  397. package/dist/lib/store.js +0 -825
  398. package/dist/lib/store.js.map +0 -1
  399. package/dist/lib/types.d.ts +0 -129
  400. package/dist/lib/types.js +0 -13
  401. package/dist/lib/types.js.map +0 -1
package/dist/lib/store.js DELETED
@@ -1,825 +0,0 @@
1
- import { connect } from "@lancedb/lancedb";
2
- import { execSync } from "node:child_process";
3
- import { createHash } from "node:crypto";
4
- import { mkdirSync, statSync, writeFileSync, readFileSync, readdirSync, existsSync, unlinkSync, } from "node:fs";
5
- import { homedir } from "node:os";
6
- import { join, resolve } from "node:path";
7
- const CHUNKS_TABLE = "chunks";
8
- const FILES_TABLE = "files";
9
- const DELETE_BATCH_SIZE = 50;
10
- function buildInFilter(column, values) {
11
- const escaped = values.map((v) => `'${v.replace(/'/g, "''")}'`);
12
- return `${column} IN (${escaped.join(", ")})`;
13
- }
14
- async function batchDelete(table, column, values) {
15
- for (let i = 0; i < values.length; i += DELETE_BATCH_SIZE) {
16
- const batch = values.slice(i, i + DELETE_BATCH_SIZE);
17
- await table.delete(buildInFilter(column, batch));
18
- }
19
- }
20
- /**
21
- * Legacy indexes (pre branch-scoping) have a `files` table without a `branch`
22
- * column. Detect and backfill it with the current branch so queries that filter
23
- * by branch keep working.
24
- */
25
- async function migrateBranchColumn(table, currentBranch) {
26
- const schema = await table.schema();
27
- if (schema.fields.some((f) => f.name === "branch"))
28
- return;
29
- const escaped = currentBranch.replace(/'/g, "''");
30
- await table.addColumns([
31
- { name: "branch", valueSql: `CAST('${escaped}' AS STRING)` },
32
- ]);
33
- }
34
- function git(cwd, ...args) {
35
- try {
36
- return execSync(`git ${args.join(" ")}`, {
37
- cwd,
38
- stdio: ["ignore", "pipe", "ignore"],
39
- timeout: 5000,
40
- })
41
- .toString()
42
- .trim();
43
- }
44
- catch {
45
- return undefined;
46
- }
47
- }
48
- /**
49
- * Resolve the project identity for a directory.
50
- *
51
- * For git repos: uses the remote origin URL as identity so that multiple
52
- * worktrees of the same repo share one index.
53
- *
54
- * For non-git directories: falls back to hashing the absolute path.
55
- *
56
- * Returns { id, root } where id is the string to hash for the DB path,
57
- * and root is the project root directory (git toplevel or cwd).
58
- */
59
- export function resolveProject(cwd) {
60
- const absolute = resolve(cwd);
61
- const gitRoot = git(absolute, "rev-parse", "--show-toplevel");
62
- if (gitRoot) {
63
- const branch = git(gitRoot, "rev-parse", "--abbrev-ref", "HEAD") ?? "HEAD";
64
- const remoteUrl = git(gitRoot, "remote", "get-url", "origin");
65
- if (remoteUrl) {
66
- return { id: remoteUrl, root: gitRoot, branch };
67
- }
68
- // Git repo with no remote — use the git root path
69
- return { id: gitRoot, root: gitRoot, branch };
70
- }
71
- return { id: absolute, root: absolute, branch: "_default" };
72
- }
73
- function slugifyId(id) {
74
- // Strip git URL scheme and trailing .git so worktrees of the same repo
75
- // produce the same human-readable prefix regardless of the worktree path.
76
- // git@host:user/repo.git → user/repo
77
- // https://host/user/repo.git → host/user/repo (we'll take the last two)
78
- // /abs/path/to/project → path/to/project (we'll take the last two)
79
- let s = id.replace(/\.git$/, "");
80
- const scpMatch = s.match(/^[^@]+@[^:]+:(.+)$/);
81
- if (scpMatch) {
82
- s = scpMatch[1];
83
- }
84
- else {
85
- s = s.replace(/^[a-z]+:\/\/[^/]+\//, "");
86
- }
87
- const parts = s.split("/").filter(Boolean);
88
- return parts.slice(-2).join("-").replace(/[^a-zA-Z0-9_-]/g, "_");
89
- }
90
- export function buildSlug(id) {
91
- const hash = createHash("sha256").update(id).digest("hex").slice(0, 8);
92
- return `${slugifyId(id)}-${hash}`;
93
- }
94
- export function getDbPath(cwd) {
95
- const { id } = resolveProject(cwd);
96
- return join(homedir(), ".local", "state", "lmgrep", buildSlug(id));
97
- }
98
- /**
99
- * Compute the DB path using the pre-git-aware scheme (absolute path hash).
100
- * Used by `lmgrep import` to find legacy indexes.
101
- */
102
- export function getLegacyDbPath(cwd) {
103
- const absolute = resolve(cwd);
104
- const hash = createHash("sha256").update(absolute).digest("hex").slice(0, 6);
105
- const parts = absolute.split("/").filter(Boolean);
106
- const slug = parts.slice(-2).join("-").replace(/[^a-zA-Z0-9_-]/g, "_");
107
- return join(homedir(), ".local", "state", "lmgrep", `${slug}-${hash}`);
108
- }
109
- /**
110
- * Find the project root and compute the prefix (subdirectory offset).
111
- * For git repos, the root is the git toplevel. For non-git dirs, walks up
112
- * looking for an existing index.
113
- */
114
- export function findIndexedAncestor(cwd) {
115
- const absolute = resolve(cwd);
116
- const { root } = resolveProject(cwd);
117
- // For git repos, the root is always the git toplevel
118
- const dbPath = getDbPath(root);
119
- try {
120
- if (statSync(dbPath).isDirectory()) {
121
- const prefix = root === absolute ? "" : absolute.slice(root.length + 1);
122
- return { root, prefix };
123
- }
124
- }
125
- catch {
126
- // no index yet
127
- }
128
- // For non-git dirs, walk up looking for an ancestor with an index
129
- if (root === absolute) {
130
- let current = resolve(absolute, "..");
131
- while (true) {
132
- const ancestorDb = getDbPath(current);
133
- try {
134
- if (statSync(ancestorDb).isDirectory()) {
135
- const prefix = absolute.slice(current.length + 1);
136
- return { root: current, prefix };
137
- }
138
- }
139
- catch {
140
- // keep climbing
141
- }
142
- const parent = resolve(current, "..");
143
- if (parent === current)
144
- break;
145
- current = parent;
146
- }
147
- }
148
- return undefined;
149
- }
150
- // --- Project metadata ---
151
- const METADATA_FILE = "lmgrep.json";
152
- /**
153
- * Extract the base model family name from a full model string.
154
- * Strips provider prefix (e.g. "openai:", "ollama:") and quantization/tag
155
- * suffixes (e.g. ":Q4_K_M", ":latest", ":fp16").
156
- *
157
- * Examples:
158
- * "openai:nomic-embed-text" → "nomic-embed-text"
159
- * "ollama:nomic-embed-text:Q4_K_M" → "nomic-embed-text"
160
- * "lmstudio:bge-large-en:fp16" → "bge-large-en"
161
- * "openai:text-embedding-3-small" → "text-embedding-3-small"
162
- */
163
- export function extractModelFamily(model) {
164
- // Strip provider prefix (first colon-separated segment)
165
- const colonIdx = model.indexOf(":");
166
- if (colonIdx === -1)
167
- return model;
168
- const rest = model.slice(colonIdx + 1);
169
- // Strip quant/tag suffix: known patterns like Q4_K_M, Q8_0, fp16, latest, etc.
170
- // These appear as the last colon-separated segment
171
- const lastColon = rest.lastIndexOf(":");
172
- if (lastColon === -1)
173
- return rest;
174
- const suffix = rest.slice(lastColon + 1);
175
- // Match common quantization and tag patterns
176
- if (/^(Q\d|q\d|fp\d|f\d|latest|gguf|ggml)/i.test(suffix)) {
177
- return rest.slice(0, lastColon);
178
- }
179
- // Not a recognized suffix — keep the whole thing (could be part of model name)
180
- return rest;
181
- }
182
- export function writeProjectMetadata(cwd, extra) {
183
- const dbPath = getDbPath(cwd);
184
- const { id, root, branch } = resolveProject(cwd);
185
- const gitRoot = git(resolve(cwd), "rev-parse", "--show-toplevel");
186
- const remote = gitRoot
187
- ? git(gitRoot, "remote", "get-url", "origin") ?? undefined
188
- : undefined;
189
- mkdirSync(dbPath, { recursive: true });
190
- // Preserve existing model/dimensions if not provided (don't overwrite baseline)
191
- const existing = readProjectMetadata(dbPath);
192
- const metadata = {
193
- root,
194
- remote,
195
- branch,
196
- indexedAt: new Date().toISOString(),
197
- model: existing?.model ?? extra?.model,
198
- dimensions: existing?.dimensions ?? extra?.dimensions,
199
- };
200
- writeFileSync(join(dbPath, METADATA_FILE), JSON.stringify(metadata, null, 2));
201
- }
202
- export function readProjectMetadata(dbPath) {
203
- const metaPath = join(dbPath, METADATA_FILE);
204
- try {
205
- return JSON.parse(readFileSync(metaPath, "utf-8"));
206
- }
207
- catch {
208
- return undefined;
209
- }
210
- }
211
- /**
212
- * Scan all lmgrep indexes and return their metadata.
213
- */
214
- export function discoverIndexedProjects() {
215
- const baseDir = join(homedir(), ".local", "state", "lmgrep");
216
- if (!existsSync(baseDir))
217
- return [];
218
- const results = [];
219
- for (const entry of readdirSync(baseDir, { withFileTypes: true })) {
220
- if (!entry.isDirectory())
221
- continue;
222
- const dbPath = join(baseDir, entry.name);
223
- const metadata = readProjectMetadata(dbPath);
224
- if (metadata) {
225
- results.push({ dbPath, metadata });
226
- }
227
- }
228
- return results;
229
- }
230
- // --- DB-level write lock ---
231
- function isProcessAlive(pid) {
232
- try {
233
- process.kill(pid, 0);
234
- return true;
235
- }
236
- catch {
237
- return false;
238
- }
239
- }
240
- /**
241
- * Acquire an exclusive write lock for a project's DB.
242
- * Returns true if the lock was acquired, false if another process holds it.
243
- */
244
- export function acquireDbLock(cwd) {
245
- const lockPath = `${getDbPath(cwd)}.lock`;
246
- if (existsSync(lockPath)) {
247
- try {
248
- const pid = Number.parseInt(readFileSync(lockPath, "utf-8").trim(), 10);
249
- if (isProcessAlive(pid))
250
- return false;
251
- }
252
- catch {
253
- // stale lock, take over
254
- }
255
- }
256
- const dbPath = getDbPath(cwd);
257
- mkdirSync(dbPath, { recursive: true });
258
- writeFileSync(lockPath, `${process.pid}\n`);
259
- return true;
260
- }
261
- /**
262
- * Release the write lock for a project's DB.
263
- */
264
- export function releaseDbLock(cwd) {
265
- try {
266
- unlinkSync(`${getDbPath(cwd)}.lock`);
267
- }
268
- catch { }
269
- }
270
- /**
271
- * Check if a write lock is held by a live process.
272
- */
273
- export function isDbLocked(cwd) {
274
- const lockPath = `${getDbPath(cwd)}.lock`;
275
- if (!existsSync(lockPath))
276
- return false;
277
- try {
278
- const pid = Number.parseInt(readFileSync(lockPath, "utf-8").trim(), 10);
279
- return isProcessAlive(pid);
280
- }
281
- catch {
282
- return false;
283
- }
284
- }
285
- function getProcessInfo(pid) {
286
- try {
287
- const name = readFileSync(`/proc/${pid}/comm`, "utf-8").trim();
288
- const cmdline = readFileSync(`/proc/${pid}/cmdline`, "utf-8")
289
- .replace(/\0/g, " ")
290
- .trim();
291
- return { name, cmdline };
292
- }
293
- catch {
294
- return undefined;
295
- }
296
- }
297
- function classifyProcess(info) {
298
- if (info.name === "lmgrep-mcp" || info.cmdline.includes("mcp"))
299
- return "mcp";
300
- if (info.cmdline.includes("serve"))
301
- return "serve";
302
- return "cli";
303
- }
304
- /**
305
- * Scan all lock files to find running lmgrep processes,
306
- * which indexes they hold, and whether they are watching for changes.
307
- */
308
- export function discoverRunningProcesses() {
309
- const baseDir = join(homedir(), ".local", "state", "lmgrep");
310
- if (!existsSync(baseDir))
311
- return [];
312
- const results = [];
313
- const seen = new Set();
314
- for (const entry of readdirSync(baseDir)) {
315
- if (!entry.endsWith(".lock"))
316
- continue;
317
- const lockPath = join(baseDir, entry);
318
- let pid;
319
- try {
320
- pid = Number.parseInt(readFileSync(lockPath, "utf-8").trim(), 10);
321
- }
322
- catch {
323
- continue;
324
- }
325
- if (!isProcessAlive(pid) || seen.has(pid))
326
- continue;
327
- seen.add(pid);
328
- const info = getProcessInfo(pid);
329
- if (!info)
330
- continue;
331
- const kind = classifyProcess(info);
332
- // Resolve which project this lock belongs to
333
- const dbDir = entry.slice(0, -".lock".length);
334
- const dbPath = join(baseDir, dbDir);
335
- const metadata = readProjectMetadata(dbPath);
336
- results.push({
337
- pid,
338
- processName: info.name,
339
- cmdline: info.cmdline,
340
- kind,
341
- projectRoot: metadata?.root,
342
- // MCP and serve processes watch; plain CLI invocations don't
343
- watching: kind === "mcp" || kind === "serve",
344
- });
345
- }
346
- return results;
347
- }
348
- export class Store {
349
- dbPath;
350
- branch;
351
- db;
352
- chunksTable;
353
- filesTable;
354
- constructor(dbPath, branch = "_default") {
355
- this.dbPath = dbPath;
356
- this.branch = branch;
357
- }
358
- static forProject(cwd) {
359
- const { branch } = resolveProject(cwd);
360
- return new Store(getDbPath(cwd), branch);
361
- }
362
- // --- Connection ---
363
- async connection() {
364
- if (this.db)
365
- return this.db;
366
- mkdirSync(this.dbPath, { recursive: true });
367
- this.db = await connect(this.dbPath);
368
- return this.db;
369
- }
370
- async openChunks() {
371
- if (this.chunksTable)
372
- return this.chunksTable;
373
- const conn = await this.connection();
374
- const tables = await conn.tableNames();
375
- if (tables.includes(CHUNKS_TABLE)) {
376
- this.chunksTable = await conn.openTable(CHUNKS_TABLE);
377
- return this.chunksTable;
378
- }
379
- return undefined;
380
- }
381
- async openFiles() {
382
- if (this.filesTable)
383
- return this.filesTable;
384
- const conn = await this.connection();
385
- const tables = await conn.tableNames();
386
- if (tables.includes(FILES_TABLE)) {
387
- const t = await conn.openTable(FILES_TABLE);
388
- await migrateBranchColumn(t, this.branch);
389
- this.filesTable = t;
390
- return this.filesTable;
391
- }
392
- return undefined;
393
- }
394
- // --- Chunks ---
395
- async addChunks(chunks) {
396
- if (chunks.length === 0)
397
- return;
398
- const conn = await this.connection();
399
- const records = chunks.map((c) => ({
400
- id: c.id,
401
- filePath: c.filePath,
402
- startLine: c.startLine,
403
- endLine: c.endLine,
404
- type: c.type,
405
- name: c.name,
406
- content: c.content,
407
- context: c.context,
408
- hash: c.hash,
409
- vector: c.vector,
410
- }));
411
- const tables = await conn.tableNames();
412
- if (tables.includes(CHUNKS_TABLE)) {
413
- const t = await conn.openTable(CHUNKS_TABLE);
414
- this.chunksTable = t;
415
- await t.add(records);
416
- }
417
- else {
418
- this.chunksTable = await conn.createTable(CHUNKS_TABLE, records);
419
- }
420
- }
421
- /**
422
- * Delete chunks for files that are no longer referenced by ANY branch.
423
- * If another branch still has a file hash entry for a given path,
424
- * the chunks are kept (they're shared via content-addressing).
425
- */
426
- async deleteChunksByFiles(filePaths) {
427
- const t = await this.openChunks();
428
- if (!t || filePaths.length === 0)
429
- return;
430
- const filesTable = await this.openFiles();
431
- if (!filesTable) {
432
- // No files table means no other branches — safe to delete all
433
- await batchDelete(t, "filePath", filePaths);
434
- return;
435
- }
436
- // Find which files are still referenced by other branches
437
- const escaped = this.branch.replace(/'/g, "''");
438
- const stillReferenced = new Set();
439
- for (let i = 0; i < filePaths.length; i += DELETE_BATCH_SIZE) {
440
- const batch = filePaths.slice(i, i + DELETE_BATCH_SIZE);
441
- const pathFilter = buildInFilter("filePath", batch);
442
- const refs = await filesTable
443
- .query()
444
- .where(`branch != '${escaped}' AND ${pathFilter}`)
445
- .select(["filePath"])
446
- .toArray();
447
- for (const r of refs) {
448
- stillReferenced.add(r.filePath);
449
- }
450
- }
451
- // Only delete chunks for files not referenced by other branches
452
- const toDelete = filePaths.filter((fp) => !stillReferenced.has(fp));
453
- if (toDelete.length > 0) {
454
- await batchDelete(t, "filePath", toDelete);
455
- }
456
- }
457
- branchFilesCache;
458
- /**
459
- * Get the set of file paths indexed on the current branch (cached).
460
- */
461
- async getBranchFiles() {
462
- if (this.branchFilesCache)
463
- return this.branchFilesCache;
464
- const t = await this.openFiles();
465
- if (!t)
466
- return undefined;
467
- const escaped = this.branch.replace(/'/g, "''");
468
- const rows = await t
469
- .query()
470
- .where(`branch = '${escaped}'`)
471
- .select(["filePath"])
472
- .toArray();
473
- this.branchFilesCache = new Set(rows.map((r) => r.filePath));
474
- return this.branchFilesCache;
475
- }
476
- /** Invalidate the branch files cache (call after index/import). */
477
- invalidateBranchFilesCache() {
478
- this.branchFilesCache = undefined;
479
- }
480
- async search(queryVector, limit = 25, filePrefix, typeFilter,
481
- /** Pass false to skip branch scoping (e.g. for cross-project search). */
482
- scopeToBranch = true) {
483
- const t = await this.openChunks();
484
- if (!t) {
485
- throw new Error("No index found. Run `lmgrep index` first.");
486
- }
487
- const branchFiles = scopeToBranch ? await this.getBranchFiles() : undefined;
488
- // Over-fetch when branch-filtering since some results will be discarded
489
- const fetchLimit = branchFiles ? limit * 3 : limit;
490
- let query = t.search(queryVector).limit(fetchLimit);
491
- const conditions = [];
492
- if (filePrefix) {
493
- conditions.push(`filePath LIKE '${filePrefix.replace(/'/g, "''")}%'`);
494
- }
495
- if (typeFilter && typeFilter.length > 0) {
496
- const escaped = typeFilter.map((t) => `'${t.replace(/'/g, "''")}'`);
497
- conditions.push(`type IN (${escaped.join(", ")})`);
498
- }
499
- if (conditions.length > 0) {
500
- query = query.where(conditions.join(" AND "));
501
- }
502
- const results = await query.toArray();
503
- let mapped = results.map((r) => ({
504
- filePath: r.filePath,
505
- startLine: r.startLine,
506
- endLine: r.endLine,
507
- type: r.type,
508
- name: r.name,
509
- content: r.content,
510
- context: r.context,
511
- score: r._distance != null ? 1 - r._distance : 0,
512
- }));
513
- if (branchFiles) {
514
- mapped = mapped.filter((r) => branchFiles.has(r.filePath));
515
- }
516
- return mapped.slice(0, limit);
517
- }
518
- async getIndexedFiles() {
519
- const t = await this.openChunks();
520
- if (!t)
521
- return new Map();
522
- const rows = await t.query().select(["filePath", "hash"]).toArray();
523
- const map = new Map();
524
- for (const row of rows) {
525
- const fp = row.filePath;
526
- const hash = row.hash;
527
- const existing = map.get(fp) ?? [];
528
- existing.push(hash);
529
- map.set(fp, existing);
530
- }
531
- return map;
532
- }
533
- async getIndexedHashes() {
534
- const t = await this.openChunks();
535
- if (!t)
536
- return new Set();
537
- const rows = await t.query().select(["hash"]).toArray();
538
- return new Set(rows.map((r) => r.hash));
539
- }
540
- /**
541
- * Given a set of chunk hashes, return those that already exist in the
542
- * chunks table. Runs as batched IN() queries in the DB.
543
- */
544
- async filterExistingChunkHashes(hashes) {
545
- const t = await this.openChunks();
546
- if (!t || hashes.length === 0)
547
- return new Set();
548
- const existing = new Set();
549
- const unique = [...new Set(hashes)];
550
- for (let i = 0; i < unique.length; i += DELETE_BATCH_SIZE) {
551
- const batch = unique.slice(i, i + DELETE_BATCH_SIZE);
552
- const filter = buildInFilter("hash", batch);
553
- const rows = await t
554
- .query()
555
- .where(filter)
556
- .select(["hash"])
557
- .toArray();
558
- for (const r of rows) {
559
- existing.add(r.hash);
560
- }
561
- }
562
- return existing;
563
- }
564
- async chunkCount() {
565
- const t = await this.openChunks();
566
- if (!t)
567
- return 0;
568
- return await t.countRows();
569
- }
570
- // --- File hashes (change detection) ---
571
- async getFileHashes() {
572
- const t = await this.openFiles();
573
- if (!t)
574
- return new Map();
575
- const escaped = this.branch.replace(/'/g, "''");
576
- const rows = await t
577
- .query()
578
- .where(`branch = '${escaped}'`)
579
- .select(["filePath", "fileHash"])
580
- .toArray();
581
- const map = new Map();
582
- for (const row of rows) {
583
- map.set(row.filePath, row.fileHash);
584
- }
585
- return map;
586
- }
587
- /**
588
- * Given a set of file hashes, return those that already exist in the
589
- * files table on ANY branch. The query runs in the DB, not in JS.
590
- */
591
- async filterKnownFileHashes(hashes) {
592
- const t = await this.openFiles();
593
- if (!t || hashes.length === 0)
594
- return new Set();
595
- const known = new Set();
596
- for (let i = 0; i < hashes.length; i += DELETE_BATCH_SIZE) {
597
- const batch = hashes.slice(i, i + DELETE_BATCH_SIZE);
598
- const filter = buildInFilter("fileHash", batch);
599
- const rows = await t
600
- .query()
601
- .where(filter)
602
- .select(["fileHash"])
603
- .toArray();
604
- for (const r of rows) {
605
- known.add(r.fileHash);
606
- }
607
- }
608
- return known;
609
- }
610
- async upsertFileHashes(entries) {
611
- if (entries.length === 0)
612
- return;
613
- const records = entries.map((e) => ({
614
- filePath: e.filePath,
615
- fileHash: e.fileHash,
616
- branch: e.branch ?? this.branch,
617
- }));
618
- const conn = await this.connection();
619
- const tables = await conn.tableNames();
620
- if (tables.includes(FILES_TABLE)) {
621
- const t = await conn.openTable(FILES_TABLE);
622
- this.filesTable = t;
623
- // Delete existing entries for the same branch + filePath pairs.
624
- // Group by branch so we don't accidentally clobber other branches'
625
- // rows for the same path.
626
- const byBranch = new Map();
627
- for (const r of records) {
628
- const list = byBranch.get(r.branch) ?? [];
629
- list.push(r.filePath);
630
- byBranch.set(r.branch, list);
631
- }
632
- for (const [branch, paths] of byBranch) {
633
- const escaped = branch.replace(/'/g, "''");
634
- for (let i = 0; i < paths.length; i += DELETE_BATCH_SIZE) {
635
- const batch = paths.slice(i, i + DELETE_BATCH_SIZE);
636
- const pathFilter = buildInFilter("filePath", batch);
637
- await t.delete(`branch = '${escaped}' AND ${pathFilter}`);
638
- }
639
- }
640
- await t.add(records);
641
- }
642
- else {
643
- this.filesTable = await conn.createTable(FILES_TABLE, records);
644
- }
645
- }
646
- async deleteFileHashes(filePaths) {
647
- const t = await this.openFiles();
648
- if (!t || filePaths.length === 0)
649
- return;
650
- const escaped = this.branch.replace(/'/g, "''");
651
- for (let i = 0; i < filePaths.length; i += DELETE_BATCH_SIZE) {
652
- const batch = filePaths.slice(i, i + DELETE_BATCH_SIZE);
653
- const pathFilter = buildInFilter("filePath", batch);
654
- await t.delete(`branch = '${escaped}' AND ${pathFilter}`);
655
- }
656
- }
657
- // --- Admin ---
658
- async *streamAllChunks(batchSize) {
659
- const t = await this.openChunks();
660
- if (!t)
661
- return;
662
- const total = await t.countRows();
663
- for (let offset = 0; offset < total; offset += batchSize) {
664
- const rows = await t.query().limit(batchSize).offset(offset).toArray();
665
- if (rows.length === 0)
666
- break;
667
- yield rows.map((r) => ({
668
- id: r.id,
669
- filePath: r.filePath,
670
- startLine: r.startLine,
671
- endLine: r.endLine,
672
- type: r.type,
673
- name: r.name,
674
- content: r.content,
675
- context: r.context,
676
- hash: r.hash,
677
- vector: Array.from(r.vector),
678
- }));
679
- }
680
- }
681
- async getAllFileEntries() {
682
- const t = await this.openFiles();
683
- if (!t)
684
- return [];
685
- const rows = await t.query().toArray();
686
- return rows.map((r) => ({
687
- filePath: r.filePath,
688
- fileHash: r.fileHash,
689
- branch: r.branch ?? this.branch,
690
- }));
691
- }
692
- async reset() {
693
- const conn = await this.connection();
694
- const tables = await conn.tableNames();
695
- if (tables.includes(CHUNKS_TABLE))
696
- await conn.dropTable(CHUNKS_TABLE);
697
- if (tables.includes(FILES_TABLE))
698
- await conn.dropTable(FILES_TABLE);
699
- this.chunksTable = undefined;
700
- this.filesTable = undefined;
701
- }
702
- async compact() {
703
- const t = await this.openChunks();
704
- if (t)
705
- await t.optimize();
706
- const f = await this.openFiles();
707
- if (f)
708
- await f.optimize();
709
- }
710
- /**
711
- * Import all chunks and file hashes from another Store's database.
712
- * Returns { chunks, files } counts of imported records.
713
- */
714
- async importFrom(sourcePath) {
715
- const sourceConn = await connect(sourcePath);
716
- const sourceTables = await sourceConn.tableNames();
717
- let chunks = 0;
718
- let files = 0;
719
- if (sourceTables.includes(CHUNKS_TABLE)) {
720
- const sourceChunks = await sourceConn.openTable(CHUNKS_TABLE);
721
- const rawChunkRows = await sourceChunks.query().toArray();
722
- if (rawChunkRows.length > 0) {
723
- // Convert Arrow typed arrays to plain JS objects so LanceDB can
724
- // infer the schema when creating a new table.
725
- const rows = rawChunkRows.map((r) => ({
726
- id: r.id,
727
- filePath: r.filePath,
728
- startLine: r.startLine,
729
- endLine: r.endLine,
730
- type: r.type,
731
- name: r.name,
732
- content: r.content,
733
- context: r.context,
734
- hash: r.hash,
735
- vector: Array.from(r.vector),
736
- }));
737
- const conn = await this.connection();
738
- const destTables = await conn.tableNames();
739
- if (destTables.includes(CHUNKS_TABLE)) {
740
- const t = await conn.openTable(CHUNKS_TABLE);
741
- this.chunksTable = t;
742
- await t.add(rows);
743
- }
744
- else {
745
- this.chunksTable = await conn.createTable(CHUNKS_TABLE, rows);
746
- }
747
- chunks = rows.length;
748
- }
749
- }
750
- if (sourceTables.includes(FILES_TABLE)) {
751
- const sourceFiles = await sourceConn.openTable(FILES_TABLE);
752
- const rawRows = await sourceFiles.query().toArray();
753
- if (rawRows.length > 0) {
754
- // Ensure branch column exists (legacy DBs won't have it)
755
- const rows = rawRows.map((r) => ({
756
- filePath: r.filePath,
757
- fileHash: r.fileHash,
758
- branch: r.branch ?? this.branch,
759
- }));
760
- const conn = await this.connection();
761
- const destTables = await conn.tableNames();
762
- if (destTables.includes(FILES_TABLE)) {
763
- const t = await conn.openTable(FILES_TABLE);
764
- this.filesTable = t;
765
- await t.add(rows);
766
- }
767
- else {
768
- this.filesTable = await conn.createTable(FILES_TABLE, rows);
769
- }
770
- files = rows.length;
771
- }
772
- }
773
- return { chunks, files };
774
- }
775
- /**
776
- * Return all distinct branch names present in the files table.
777
- */
778
- async getStoredBranches() {
779
- const t = await this.openFiles();
780
- if (!t)
781
- return [];
782
- const rows = await t.query().select(["branch"]).toArray();
783
- return [...new Set(rows.map((r) => r.branch))];
784
- }
785
- /**
786
- * Delete all file manifest rows for a given branch.
787
- */
788
- async deleteBranchManifest(branch) {
789
- const t = await this.openFiles();
790
- if (!t)
791
- return;
792
- const escaped = branch.replace(/'/g, "''");
793
- await t.delete(`branch = '${escaped}'`);
794
- }
795
- /**
796
- * Copy another branch's file manifest to this store's branch.
797
- * Used to bootstrap a new branch from a merge base.
798
- */
799
- async copyBranchManifest(sourceBranch) {
800
- const t = await this.openFiles();
801
- if (!t)
802
- return 0;
803
- const escaped = sourceBranch.replace(/'/g, "''");
804
- const rows = await t
805
- .query()
806
- .where(`branch = '${escaped}'`)
807
- .select(["filePath", "fileHash"])
808
- .toArray();
809
- if (rows.length === 0)
810
- return 0;
811
- const records = rows.map((r) => ({
812
- filePath: r.filePath,
813
- fileHash: r.fileHash,
814
- branch: this.branch,
815
- }));
816
- await t.add(records);
817
- return records.length;
818
- }
819
- async close() {
820
- this.chunksTable = undefined;
821
- this.filesTable = undefined;
822
- this.db = undefined;
823
- }
824
- }
825
- //# sourceMappingURL=store.js.map