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
@@ -0,0 +1,49 @@
1
+ import { execSync } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { join } from "node:path";
4
+ /**
5
+ * Imports an AI SDK provider package.
6
+ *
7
+ * Providers are peer dependencies the user installs, so resolution has to
8
+ * reach beyond this package's own `node_modules`: an `npm i -g @ai-sdk/openai`
9
+ * is a normal setup and would otherwise fail to resolve.
10
+ */
11
+ export class ProviderModuleLoader {
12
+ cache = new Map();
13
+ async load(packageName) {
14
+ const cached = this.cache.get(packageName);
15
+ if (cached)
16
+ return cached;
17
+ const loaded = await this.resolve(packageName);
18
+ this.cache.set(packageName, loaded);
19
+ return loaded;
20
+ }
21
+ async resolve(packageName) {
22
+ // Local resolution first — the common case.
23
+ try {
24
+ return await import(packageName);
25
+ }
26
+ catch { }
27
+ for (const globalPath of this.globalModulePaths()) {
28
+ try {
29
+ const req = createRequire(join(globalPath, ".placeholder"));
30
+ return await import(req.resolve(packageName));
31
+ }
32
+ catch { }
33
+ }
34
+ throw new Error(`Provider "${packageName}" is not installed. Run:\n\n npm install -g ${packageName}\n`);
35
+ }
36
+ globalModulePaths() {
37
+ const paths = [];
38
+ for (const command of ["pnpm root -g", "npm root -g"]) {
39
+ try {
40
+ const out = execSync(command, { stdio: "pipe" }).toString().trim();
41
+ if (out)
42
+ paths.push(out);
43
+ }
44
+ catch { }
45
+ }
46
+ return paths;
47
+ }
48
+ }
49
+ //# sourceMappingURL=ProviderModuleLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderModuleLoader.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/ProviderModuleLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,M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I,CAAC;gBACJ,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;gBACnE,IAAI,GAAG;oBAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACX,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
@@ -0,0 +1,37 @@
1
+ import { ProviderModuleLoader } from "./ProviderModuleLoader.js";
2
+ /** A `provider:model` string split into its parts. */
3
+ export declare class ModelReference {
4
+ readonly provider: string;
5
+ readonly model: string;
6
+ readonly full: string;
7
+ private constructor();
8
+ static parse(value: string, label: string): ModelReference;
9
+ }
10
+ export interface ProviderRequest {
11
+ reference: ModelReference;
12
+ /** Package to import; defaults to `@ai-sdk/<provider>`. */
13
+ packageName?: string;
14
+ baseURL?: string;
15
+ /**
16
+ * Whether a configured `baseURL` should force use of the `create*` factory
17
+ * even when the module exports a ready-made default instance.
18
+ *
19
+ * It matters because a bare default export (e.g. `openai`) ignores baseURL
20
+ * and would silently talk to the cloud. The chat path sets this; the
21
+ * embedding path historically does not, and the two are kept distinct here
22
+ * rather than quietly unified.
23
+ */
24
+ preferFactoryWhenBaseUrlSet: boolean;
25
+ }
26
+ /**
27
+ * Turns a `provider:model` string plus config into a live AI SDK provider.
28
+ *
29
+ * Both the embedding and chat paths need the same import-and-instantiate
30
+ * dance, so it lives here once; the one place they genuinely differ is
31
+ * expressed as {@link ProviderRequest.preferFactoryWhenBaseUrlSet}.
32
+ */
33
+ export declare class ProviderRegistry {
34
+ private readonly loader;
35
+ constructor(loader?: ProviderModuleLoader);
36
+ instantiate(request: ProviderRequest): Promise<unknown>;
37
+ }
@@ -0,0 +1,55 @@
1
+ import { ProviderModuleLoader } from "./ProviderModuleLoader.js";
2
+ /** A `provider:model` string split into its parts. */
3
+ export class ModelReference {
4
+ provider;
5
+ model;
6
+ full;
7
+ constructor(provider, model, full) {
8
+ this.provider = provider;
9
+ this.model = model;
10
+ this.full = full;
11
+ }
12
+ static parse(value, label) {
13
+ const colon = value.indexOf(":");
14
+ if (colon === -1) {
15
+ throw new Error(`${label} must be in "provider:model" format. Got: "${value}"`);
16
+ }
17
+ return new ModelReference(value.slice(0, colon), value.slice(colon + 1), value);
18
+ }
19
+ }
20
+ /**
21
+ * Turns a `provider:model` string plus config into a live AI SDK provider.
22
+ *
23
+ * Both the embedding and chat paths need the same import-and-instantiate
24
+ * dance, so it lives here once; the one place they genuinely differ is
25
+ * expressed as {@link ProviderRequest.preferFactoryWhenBaseUrlSet}.
26
+ */
27
+ export class ProviderRegistry {
28
+ loader;
29
+ constructor(loader = new ProviderModuleLoader()) {
30
+ this.loader = loader;
31
+ }
32
+ async instantiate(request) {
33
+ const providerName = request.reference.provider;
34
+ const packageName = request.packageName ?? `@ai-sdk/${providerName}`;
35
+ const module = await this.loader.load(packageName);
36
+ let instance = module[providerName];
37
+ const forceFactory = request.preferFactoryWhenBaseUrlSet && Boolean(request.baseURL);
38
+ if (!instance || forceFactory) {
39
+ const factoryKey = Object.keys(module).find((k) => k.startsWith("create"));
40
+ if (factoryKey) {
41
+ const factory = module[factoryKey];
42
+ instance = factory({
43
+ name: providerName,
44
+ ...(request.baseURL ? { baseURL: request.baseURL } : {}),
45
+ });
46
+ }
47
+ }
48
+ if (!instance) {
49
+ throw new Error(`Package "${packageName}" has no usable provider export. ` +
50
+ `Available: ${Object.keys(module).join(", ")}`);
51
+ }
52
+ return instance;
53
+ }
54
+ }
55
+ //# sourceMappingURL=ProviderRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderRegistry.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/ProviderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,sDAAsD;AACtD,MAAM,OAAO,cAAc;IA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AC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CACtB,CAAC;YACF,IAAI,UAAU,EAAE,CAAC;gBAChB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAErB,CAAC;gBACb,QAAQ,GAAG,OAAO,CAAC;oBAClB,IAAI,EAAE,YAAY;oBAClB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxD,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,YAAY,WAAW,mCAAmC;gBACzD,cAAc,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC/C,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD"}
@@ -0,0 +1,59 @@
1
+ import type { ConfigSource } from "../../domain/config/ConfigSource.js";
2
+ import type { LmgrepConfig } from "../../domain/config/LmgrepConfig.js";
3
+ /**
4
+ * Loads configuration from two kinds of file, split by what the settings
5
+ * actually describe.
6
+ *
7
+ * **Machine settings** — which model to embed with, which to answer with,
8
+ * where those servers listen — describe *this computer's* inference setup.
9
+ * They live in one global file. They used to be settable per project too,
10
+ * which was the single most confusing thing about lmgrep: the model determines
11
+ * what a stored vector *means*, so a project file could silently point an
12
+ * index at incompatible embeddings, and `status` would report an effective
13
+ * model without saying which of three files produced it.
14
+ *
15
+ * **Project settings** — what to ignore, which extensions to index — describe
16
+ * *this repository*, are worth committing, and mean the same thing on every
17
+ * machine that checks it out.
18
+ *
19
+ * Machine keys found in a project file are reported and ignored rather than
20
+ * applied. Wanting a different model for one project is a real thing to want;
21
+ * it is now spelled as a different database (`--database`), because the model
22
+ * is a property of an index rather than of a directory.
23
+ */
24
+ export declare class ConfigLoader {
25
+ /** Settings that describe this machine's inference setup. */
26
+ private static readonly MACHINE_SCHEMA;
27
+ /** Settings that describe a repository. */
28
+ private static readonly PROJECT_SCHEMA;
29
+ private static readonly FILE_NAME;
30
+ private static readonly PROJECT_FILE_NAMES;
31
+ private static readonly DEFAULTS;
32
+ /** Populated by {@link load}: what was read, and what was ignored. */
33
+ readonly sources: ConfigSource[];
34
+ readonly warnings: string[];
35
+ load(cwd: string): LmgrepConfig;
36
+ /**
37
+ * The XDG-compliant global config directory.
38
+ * Linux: $XDG_CONFIG_HOME/lmgrep or ~/.config/lmgrep
39
+ * macOS: ~/Library/Application Support/lmgrep
40
+ */
41
+ configDirectory(): string;
42
+ globalConfigPath(): string;
43
+ /** Path of the project file in `cwd`, whether or not it exists. */
44
+ projectConfigPath(cwd: string): string;
45
+ /**
46
+ * Parse a single machine config file, ignoring the layering.
47
+ *
48
+ * `init` rewrites one specific file, so it needs that file's own contents —
49
+ * merging layers here would copy one file's settings into another.
50
+ */
51
+ readFile(path: string): Partial<LmgrepConfig> | undefined;
52
+ private readMachineFile;
53
+ private readProjectFile;
54
+ private parseYaml;
55
+ private pick;
56
+ private static machineKeys;
57
+ private static projectKeys;
58
+ private validate;
59
+ }
@@ -0,0 +1,194 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { homedir, platform } from "node:os";
3
+ import { join } from "node:path";
4
+ import { parse } from "yaml";
5
+ import { z } from "zod";
6
+ /**
7
+ * Loads configuration from two kinds of file, split by what the settings
8
+ * actually describe.
9
+ *
10
+ * **Machine settings** — which model to embed with, which to answer with,
11
+ * where those servers listen — describe *this computer's* inference setup.
12
+ * They live in one global file. They used to be settable per project too,
13
+ * which was the single most confusing thing about lmgrep: the model determines
14
+ * what a stored vector *means*, so a project file could silently point an
15
+ * index at incompatible embeddings, and `status` would report an effective
16
+ * model without saying which of three files produced it.
17
+ *
18
+ * **Project settings** — what to ignore, which extensions to index — describe
19
+ * *this repository*, are worth committing, and mean the same thing on every
20
+ * machine that checks it out.
21
+ *
22
+ * Machine keys found in a project file are reported and ignored rather than
23
+ * applied. Wanting a different model for one project is a real thing to want;
24
+ * it is now spelled as a different database (`--database`), because the model
25
+ * is a property of an index rather than of a directory.
26
+ */
27
+ export class ConfigLoader {
28
+ /** Settings that describe this machine's inference setup. */
29
+ static MACHINE_SCHEMA = z.object({
30
+ model: z
31
+ .string()
32
+ .regex(/^.+:.+$/, 'Model must be in "provider:model" format (e.g. "ollama:nomic-embed-text")'),
33
+ provider: z.string().optional(),
34
+ baseURL: z.string().url().optional(),
35
+ local: z.boolean().optional(),
36
+ batchSize: z.number().int().positive().default(100),
37
+ dimensions: z.number().int().positive().optional(),
38
+ queryPrefix: z.string().optional(),
39
+ documentPrefix: z.string().optional(),
40
+ maxTokens: z.number().int().positive().optional(),
41
+ chatModel: z
42
+ .string()
43
+ .regex(/^.+:.+$/, 'chatModel must be in "provider:model" format (e.g. "lmstudio:qwen/qwen3.5-9b")')
44
+ .optional(),
45
+ chatProvider: z.string().optional(),
46
+ chatBaseURL: z.string().url().optional(),
47
+ chatMaxSteps: z.number().int().positive().optional(),
48
+ chatTimeoutMs: z.number().int().positive().optional(),
49
+ });
50
+ /** Settings that describe a repository. */
51
+ static PROJECT_SCHEMA = z.object({
52
+ ignore: z.array(z.string()).optional(),
53
+ extensions: z
54
+ .object({
55
+ include: z.array(z.string()).optional(),
56
+ exclude: z.array(z.string()).optional(),
57
+ })
58
+ .optional(),
59
+ });
60
+ static FILE_NAME = "config.yml";
61
+ static PROJECT_FILE_NAMES = [".lmgrep.yml", ".lmgrep.yaml"];
62
+ static DEFAULTS = { batchSize: 100 };
63
+ /** Populated by {@link load}: what was read, and what was ignored. */
64
+ sources = [];
65
+ warnings = [];
66
+ load(cwd) {
67
+ const layers = [];
68
+ // Home-level files are machine settings wherever they sit; the bare
69
+ // ~/.lmgrep.yml predates the XDG path and is still honoured so an
70
+ // upgrade does not silently unconfigure anyone.
71
+ const legacy = this.readMachineFile(join(homedir(), ".lmgrep.yml"), "deprecated");
72
+ if (legacy)
73
+ layers.push(legacy);
74
+ const global = this.readMachineFile(this.globalConfigPath());
75
+ if (global)
76
+ layers.push(global);
77
+ const project = this.readProjectFile(cwd);
78
+ if (project)
79
+ layers.push(project);
80
+ if (layers.length === 0) {
81
+ throw new Error("No configuration found. Run `lmgrep init` to set up your embedding model.");
82
+ }
83
+ return this.validate(Object.assign({ ...ConfigLoader.DEFAULTS }, ...layers));
84
+ }
85
+ /**
86
+ * The XDG-compliant global config directory.
87
+ * Linux: $XDG_CONFIG_HOME/lmgrep or ~/.config/lmgrep
88
+ * macOS: ~/Library/Application Support/lmgrep
89
+ */
90
+ configDirectory() {
91
+ if (platform() === "darwin") {
92
+ return join(homedir(), "Library", "Application Support", "lmgrep");
93
+ }
94
+ const xdg = process.env.XDG_CONFIG_HOME;
95
+ return join(xdg || join(homedir(), ".config"), "lmgrep");
96
+ }
97
+ globalConfigPath() {
98
+ return join(this.configDirectory(), ConfigLoader.FILE_NAME);
99
+ }
100
+ /** Path of the project file in `cwd`, whether or not it exists. */
101
+ projectConfigPath(cwd) {
102
+ for (const name of ConfigLoader.PROJECT_FILE_NAMES) {
103
+ if (existsSync(join(cwd, name)))
104
+ return join(cwd, name);
105
+ }
106
+ return join(cwd, ConfigLoader.PROJECT_FILE_NAMES[0]);
107
+ }
108
+ /**
109
+ * Parse a single machine config file, ignoring the layering.
110
+ *
111
+ * `init` rewrites one specific file, so it needs that file's own contents —
112
+ * merging layers here would copy one file's settings into another.
113
+ */
114
+ readFile(path) {
115
+ const raw = this.parseYaml(path);
116
+ if (!raw)
117
+ return undefined;
118
+ return ConfigLoader.MACHINE_SCHEMA.partial().parse(this.pick(raw, ConfigLoader.machineKeys()));
119
+ }
120
+ readMachineFile(path, deprecated) {
121
+ const raw = this.parseYaml(path);
122
+ if (!raw)
123
+ return undefined;
124
+ const projectKeys = ConfigLoader.projectKeys().filter((k) => k in raw);
125
+ if (projectKeys.length > 0) {
126
+ this.warnings.push(`${path}: ${projectKeys.join(", ")} ${projectKeys.length === 1 ? "is a project setting" : "are project settings"} — ` +
127
+ "move to .lmgrep.yml in the repository it applies to.");
128
+ }
129
+ const parsed = ConfigLoader.MACHINE_SCHEMA.partial().parse(this.pick(raw, ConfigLoader.machineKeys()));
130
+ // Deprecation is not warned about here: `lmgrep status` marks the
131
+ // location in its provenance listing, which is where someone is
132
+ // actually looking at their configuration. Printing it before every
133
+ // search would be noise on the one path that must stay quiet.
134
+ this.sources.push({
135
+ path,
136
+ scope: "machine",
137
+ keys: Object.keys(parsed),
138
+ ...(deprecated ? { deprecated: true } : {}),
139
+ });
140
+ return parsed;
141
+ }
142
+ readProjectFile(cwd) {
143
+ for (const name of ConfigLoader.PROJECT_FILE_NAMES) {
144
+ const path = join(cwd, name);
145
+ const raw = this.parseYaml(path);
146
+ if (!raw)
147
+ continue;
148
+ const machineKeys = ConfigLoader.machineKeys().filter((k) => k in raw);
149
+ if (machineKeys.length > 0) {
150
+ // Named individually because the consequence differs per key:
151
+ // a stray `model` here silently decided what an index meant.
152
+ this.warnings.push(`${path}: ignoring ${machineKeys.join(", ")} — these describe your machine, ` +
153
+ `not this repository. Set them in ${this.globalConfigPath()}. ` +
154
+ "For a project-specific model, index it under `--in <name>` instead.");
155
+ }
156
+ const parsed = ConfigLoader.PROJECT_SCHEMA.parse(this.pick(raw, ConfigLoader.projectKeys()));
157
+ this.sources.push({
158
+ path,
159
+ scope: "project",
160
+ keys: Object.keys(parsed),
161
+ });
162
+ return parsed;
163
+ }
164
+ return undefined;
165
+ }
166
+ parseYaml(path) {
167
+ if (!existsSync(path))
168
+ return undefined;
169
+ const parsed = parse(readFileSync(path, "utf-8"));
170
+ if (parsed == null || typeof parsed !== "object")
171
+ return undefined;
172
+ return parsed;
173
+ }
174
+ pick(raw, keys) {
175
+ const out = {};
176
+ for (const key of keys)
177
+ if (key in raw)
178
+ out[key] = raw[key];
179
+ return out;
180
+ }
181
+ static machineKeys() {
182
+ return Object.keys(ConfigLoader.MACHINE_SCHEMA.shape);
183
+ }
184
+ static projectKeys() {
185
+ return Object.keys(ConfigLoader.PROJECT_SCHEMA.shape);
186
+ }
187
+ validate(config) {
188
+ if (!config.model) {
189
+ throw new Error(`No model configured. Run \`lmgrep init\` to detect your setup, or set \`model\` in ${this.globalConfigPath()}.`);
190
+ }
191
+ return config;
192
+ }
193
+ }
194
+ //# sourceMappingURL=ConfigLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigLoader.js","sourceRoot":"","sources":["../../../src/infrastructure/fs/ConfigLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,YAAY;IACxB,6DAA6D;IACrD,MAAM,CAAU,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;QACjD,KAAK,EAAE,CAAC;aACN,MAAM,EAAE;aACR,KAAK,CACL,SAAS,EACT,2EAA2E,CAC3E;QACF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;QACpC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;QACnD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAA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MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;IAEO,QAAQ,CACf,MAA4D;QAE5D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACd,sFAAsF,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAChH,CAAC;QACH,CAAC;QACD,OAAO,MAAsB,CAAC;IAC/B,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { LockPort } from "../../domain/ports/LockPort.js";
2
+ /**
3
+ * The two locks a database has, which exist for different reasons and are
4
+ * therefore scoped differently.
5
+ *
6
+ * The **write mutex** (`.writelock`) is per *database*, because that is what
7
+ * concurrent writers actually contend for: two indexers writing the same
8
+ * tables race into duplicate rows. It is held only around a build.
9
+ *
10
+ * The **maintainer** lock is per *worktree*. Watching is inherently per
11
+ * working tree — a watcher scans its own root and maintains its own branch's
12
+ * manifest — but worktrees of one repository share a single database. Keying
13
+ * this lock by database, as it once was, meant the first worktree to start
14
+ * silently prevented every sibling from ever watching, leaving their branches
15
+ * to go stale with no indication. It also doubles as the liveness registry
16
+ * `lmgrep status` reads, which is why the owning worktree is recorded in it.
17
+ *
18
+ * Both live in the state directory rather than beside the database. Locks
19
+ * coordinate processes on *this machine*; a database now lives inside a
20
+ * repository, which may be on a network filesystem, may be read-only, and is
21
+ * the wrong place to record which local pid is busy with it. Keeping them
22
+ * together in one directory is also what lets `status` find every running
23
+ * lmgrep by reading a single directory.
24
+ */
25
+ export declare class DatabaseLocks implements LockPort {
26
+ private readonly databasePath;
27
+ /** Working tree this process would be responsible for. */
28
+ private readonly workspaceRoot;
29
+ private static readonly DEFAULT_WAIT_MS;
30
+ private static readonly DEFAULT_POLL_MS;
31
+ /** Enough to separate worktrees without making the filename unreadable. */
32
+ private static readonly ROOT_DIGEST_LENGTH;
33
+ private readonly maintainer;
34
+ private readonly writer;
35
+ constructor(locksDirectory: string, databasePath: string,
36
+ /** Working tree this process would be responsible for. */
37
+ workspaceRoot: string);
38
+ acquireMaintainer(): boolean;
39
+ releaseMaintainer(): void;
40
+ isMaintained(): boolean;
41
+ /**
42
+ * Run `fn` holding the write mutex. Waits for a busy lock, taking over one
43
+ * whose owner has died. Throws if it cannot be acquired in time — better to
44
+ * fail than to write concurrently and duplicate rows.
45
+ */
46
+ withWriteLock<T>(fn: () => Promise<T>, options?: {
47
+ waitMs?: number;
48
+ pollMs?: number;
49
+ }): Promise<T>;
50
+ /** Short stable name for a path, used to key lock files. */
51
+ private static digestOf;
52
+ }
@@ -0,0 +1,92 @@
1
+ import { createHash } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { PidFileLock } from "./PidFileLock.js";
4
+ /**
5
+ * The two locks a database has, which exist for different reasons and are
6
+ * therefore scoped differently.
7
+ *
8
+ * The **write mutex** (`.writelock`) is per *database*, because that is what
9
+ * concurrent writers actually contend for: two indexers writing the same
10
+ * tables race into duplicate rows. It is held only around a build.
11
+ *
12
+ * The **maintainer** lock is per *worktree*. Watching is inherently per
13
+ * working tree — a watcher scans its own root and maintains its own branch's
14
+ * manifest — but worktrees of one repository share a single database. Keying
15
+ * this lock by database, as it once was, meant the first worktree to start
16
+ * silently prevented every sibling from ever watching, leaving their branches
17
+ * to go stale with no indication. It also doubles as the liveness registry
18
+ * `lmgrep status` reads, which is why the owning worktree is recorded in it.
19
+ *
20
+ * Both live in the state directory rather than beside the database. Locks
21
+ * coordinate processes on *this machine*; a database now lives inside a
22
+ * repository, which may be on a network filesystem, may be read-only, and is
23
+ * the wrong place to record which local pid is busy with it. Keeping them
24
+ * together in one directory is also what lets `status` find every running
25
+ * lmgrep by reading a single directory.
26
+ */
27
+ export class DatabaseLocks {
28
+ databasePath;
29
+ workspaceRoot;
30
+ static DEFAULT_WAIT_MS = 120_000;
31
+ static DEFAULT_POLL_MS = 200;
32
+ /** Enough to separate worktrees without making the filename unreadable. */
33
+ static ROOT_DIGEST_LENGTH = 12;
34
+ maintainer;
35
+ writer;
36
+ constructor(locksDirectory, databasePath,
37
+ /** Working tree this process would be responsible for. */
38
+ workspaceRoot) {
39
+ this.databasePath = databasePath;
40
+ this.workspaceRoot = workspaceRoot;
41
+ const database = DatabaseLocks.digestOf(databasePath);
42
+ this.maintainer = new PidFileLock(join(locksDirectory, `${database}@${DatabaseLocks.digestOf(workspaceRoot)}.lock`));
43
+ this.writer = new PidFileLock(join(locksDirectory, `${database}.writelock`));
44
+ }
45
+ acquireMaintainer() {
46
+ // The database path goes in the payload because it is no longer in the
47
+ // filename: a digest cannot be reversed, and `status` needs to name the
48
+ // index a process is holding.
49
+ return this.maintainer.tryAcquire({
50
+ root: this.workspaceRoot,
51
+ database: this.databasePath,
52
+ });
53
+ }
54
+ releaseMaintainer() {
55
+ this.maintainer.release();
56
+ }
57
+ isMaintained() {
58
+ return this.maintainer.isHeldByLiveProcess();
59
+ }
60
+ /**
61
+ * Run `fn` holding the write mutex. Waits for a busy lock, taking over one
62
+ * whose owner has died. Throws if it cannot be acquired in time — better to
63
+ * fail than to write concurrently and duplicate rows.
64
+ */
65
+ async withWriteLock(fn, options = {}) {
66
+ const waitMs = options.waitMs ?? DatabaseLocks.DEFAULT_WAIT_MS;
67
+ const pollMs = options.pollMs ?? DatabaseLocks.DEFAULT_POLL_MS;
68
+ let waited = 0;
69
+ while (!this.writer.tryAcquire()) {
70
+ if (waited >= waitMs) {
71
+ throw new Error("Could not acquire the index write lock — another indexer is busy. " +
72
+ "Try again once it finishes.");
73
+ }
74
+ await new Promise((r) => setTimeout(r, pollMs));
75
+ waited += pollMs;
76
+ }
77
+ try {
78
+ return await fn();
79
+ }
80
+ finally {
81
+ this.writer.releaseIfOwned();
82
+ }
83
+ }
84
+ /** Short stable name for a path, used to key lock files. */
85
+ static digestOf(path) {
86
+ return createHash("sha256")
87
+ .update(path)
88
+ .digest("hex")
89
+ .slice(0, DatabaseLocks.ROOT_DIGEST_LENGTH);
90
+ }
91
+ }
92
+ //# sourceMappingURL=DatabaseLocks.js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,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa,CAClB,EAAoB,EACpB,UAAgD,EAAE;QAElD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,eAAe,CAAC;QAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,eAAe,CAAC;QAE/D,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;YAClC,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CACd,oEAAoE;oBACnE,6BAA6B,CAC9B,CAAC;YACH,CAAC;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAChD,MAAM,IAAI,MAAM,CAAC;QAClB,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,MAAM,EAAE,EAAE,CAAC;QACnB,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,4DAA4D;IACpD,MAAM,CAAC,QAAQ,CAAC,IAAY;QACnC,OAAO,UAAU,CAAC,QAAQ,CAAC;aACzB,MAAM,CAAC,IAAI,CAAC;aACZ,MAAM,CAAC,KAAK,CAAC;aACb,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Recursive on-disk size, for reporting what an index actually costs. */
2
+ export declare class DiskUsage {
3
+ /** Bytes used by `path` and everything under it; 0 when unreadable. */
4
+ static of(path: string): number;
5
+ static format(bytes: number): string;
6
+ }
@@ -0,0 +1,41 @@
1
+ import { readdirSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ /** Recursive on-disk size, for reporting what an index actually costs. */
4
+ export class DiskUsage {
5
+ /** Bytes used by `path` and everything under it; 0 when unreadable. */
6
+ static of(path) {
7
+ let total = 0;
8
+ let entries;
9
+ try {
10
+ entries = readdirSync(path, { withFileTypes: true });
11
+ }
12
+ catch {
13
+ return 0;
14
+ }
15
+ for (const entry of entries) {
16
+ const child = join(path, entry.name);
17
+ if (entry.isDirectory()) {
18
+ total += DiskUsage.of(child);
19
+ continue;
20
+ }
21
+ try {
22
+ total += statSync(child).size;
23
+ }
24
+ catch {
25
+ // Vanished mid-walk; the number is a report, not an invariant.
26
+ }
27
+ }
28
+ return total;
29
+ }
30
+ static format(bytes) {
31
+ const units = ["B", "KB", "MB", "GB", "TB"];
32
+ let value = bytes;
33
+ let unit = 0;
34
+ while (value >= 1024 && unit < units.length - 1) {
35
+ value /= 1024;
36
+ unit++;
37
+ }
38
+ return `${value < 10 && unit > 0 ? value.toFixed(1) : Math.round(value)}${units[unit]}`;
39
+ }
40
+ }
41
+ //# sourceMappingURL=DiskUsage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DiskUsage.js","sourceRoot":"","sources":["../../../src/infrastructure/fs/DiskUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,0EAA0E;AAC1E,MAAM,OAAO,SAAS;IACrB,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,IAAY;QACrB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,OAAmC,CAAC;QACxC,IAAI,CAAC;YACJ,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,CAAC,CAAC;QACV,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACzB,KAAK,IAAI,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC7B,SAAS;YACV,CAAC;YACD,IAAI,CAAC;gBACJ,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACR,+DAA+D;YAChE,CAAC;QACF,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAa;QAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjD,KAAK,IAAI,IAAI,CAAC;YACd,IAAI,EAAE,CAAC;QACR,CAAC;QACD,OAAO,GAAG,KAAK,GAAG,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;IACzF,CAAC;CACD"}
@@ -0,0 +1,33 @@
1
+ import type { ExtensionRules } from "../../domain/ports/WorkspacePort.js";
2
+ /**
3
+ * Decides which files are worth indexing.
4
+ *
5
+ * Two independent filters: an extension allow-list (is this even source?) and
6
+ * ignore patterns (should this source be skipped?). Ignore rules come from the
7
+ * built-in list, the user's config, `.gitignore` and `.lmgrepignore`, plus
8
+ * nested `.gitignore` files further down the tree.
9
+ */
10
+ export declare class IndexableFileRules {
11
+ private readonly cwd;
12
+ static readonly DEFAULT_IGNORE: string[];
13
+ static readonly CODE_EXTENSIONS: Set<string>;
14
+ private readonly root;
15
+ private readonly extensions;
16
+ private readonly nested;
17
+ constructor(cwd: string, extraIgnore?: string[], extensionRules?: ExtensionRules);
18
+ /** Whether the path's extension is one we index at all. */
19
+ hasIndexableExtension(filePath: string): boolean;
20
+ /** Whether the root-level ignore rules exclude this path. */
21
+ isIgnored(filePath: string): boolean;
22
+ /**
23
+ * Load `.gitignore` files sitting in subdirectories, so a nested ignore
24
+ * applies to its own subtree the way git applies it.
25
+ */
26
+ loadNestedIgnores(relativePaths: readonly string[]): void;
27
+ /** Whether any nested `.gitignore` excludes this path. */
28
+ isIgnoredByNested(filePath: string): boolean;
29
+ /** Full decision for a scanned path. */
30
+ admits(filePath: string): boolean;
31
+ private static buildIgnore;
32
+ private static buildExtensions;
33
+ }