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/cli.js CHANGED
@@ -1,757 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  process.title = "lmgrep";
3
- import { Command } from "commander";
4
- import { createHash } from "node:crypto";
5
- import { readFileSync, writeFileSync, existsSync, rmSync, mkdirSync, } from "node:fs";
6
- import { homedir } from "node:os";
7
- import { join, resolve } from "node:path";
8
- import { execSync, spawnSync } from "node:child_process";
9
- import { createIndex } from "./index.js";
10
- import { getGlobalConfigPath } from "./lib/config.js";
11
- import { walkFiles } from "./lib/scanner.js";
12
- import { renameSync } from "node:fs";
13
- import { Store, buildSlug, getDbPath, getLegacyDbPath, readProjectMetadata, extractModelFamily, discoverIndexedProjects, discoverRunningProcesses, } from "./lib/store.js";
14
- const program = new Command();
15
- program
16
- .name("lmgrep")
17
- .description("Semantic code search with any AI embedding provider")
18
- .version("0.1.0");
19
- program
20
- .command("index")
21
- .description("Index the current directory for semantic search")
22
- .option("-r, --reset", "Reset and rebuild the entire index")
23
- .option("-v, --verbose", "Show file-by-file progress")
24
- .option("-s, --since <duration>", "Only consider files modified within duration (e.g. 10m, 2h, 1d)")
25
- .option("-f, --force", "Force re-embed even if file hash unchanged (use with --since)")
26
- .option("-d, --dry", "Show what would be indexed without actually doing it")
27
- .action(async (opts) => {
28
- const cwd = process.cwd();
29
- const index = await createIndex({ cwd });
30
- await index.build({
31
- reset: opts.reset,
32
- verbose: opts.verbose,
33
- since: opts.since,
34
- force: opts.force,
35
- dry: opts.dry,
36
- });
37
- await index.close();
38
- });
39
- program
40
- .command("search <query>")
41
- .description("Search the codebase using natural language")
42
- .option("-m, --limit <n>", "Max results", "25")
43
- .option("--scores", "Show relevance scores")
44
- .option("--compact", "Show file paths only")
45
- .option("--json", "Output results as JSON")
46
- .option("--min-score <n>", "Minimum score threshold")
47
- .option("--file-prefix <prefix>", "Only search files matching this path prefix")
48
- .option("--not <query>", "Exclude results similar to this query")
49
- .option("--type <types>", "Only return chunks of these AST types (comma-separated)")
50
- .option("--language <langs>", "Only return chunks from files with these extensions (comma-separated, e.g. .ts,.py)")
51
- .option("--project <path>", "Search a different project's index")
52
- .option("--across <paths>", "Search multiple project indexes (comma-separated paths)")
53
- .action(async (query, opts) => {
54
- const cwd = process.cwd();
55
- const index = await createIndex({ cwd });
56
- const results = await index.search(query, {
57
- limit: Number.parseInt(opts.limit, 10),
58
- filePrefix: opts.filePrefix,
59
- not: opts.not,
60
- minScore: opts.minScore
61
- ? Number.parseFloat(opts.minScore)
62
- : undefined,
63
- type: opts.type
64
- ? opts.type.split(",").map((s) => s.trim())
65
- : undefined,
66
- language: opts.language
67
- ? opts.language.split(",").map((s) => s.trim())
68
- : undefined,
69
- project: opts.project,
70
- across: opts.across
71
- ? opts.across.split(",").map((s) => s.trim())
72
- : undefined,
73
- });
74
- if (opts.json) {
75
- console.log(JSON.stringify(results, null, 2));
76
- await index.close();
77
- return;
78
- }
79
- if (results.length === 0) {
80
- console.log("No results found.");
81
- }
82
- else if (opts.compact) {
83
- const seen = new Set();
84
- for (const r of results) {
85
- if (!seen.has(r.filePath)) {
86
- seen.add(r.filePath);
87
- console.log(r.filePath);
88
- }
89
- }
90
- }
91
- else {
92
- for (const r of results) {
93
- const header = `${r.filePath}:${r.startLine}-${r.endLine} [${r.type}] ${r.name}`;
94
- const score = opts.scores
95
- ? ` (score: ${r.score.toFixed(3)})`
96
- : "";
97
- console.log(`\n${"─".repeat(60)}`);
98
- console.log(`${header}${score}`);
99
- console.log(`${"─".repeat(60)}`);
100
- console.log(r.context);
101
- console.log();
102
- console.log(r.content);
103
- }
104
- }
105
- await index.close();
106
- });
107
- program
108
- .command("status")
109
- .description("Show index stats and check embedding connectivity")
110
- .option("-c, --changes", "Scan for changed files since last index")
111
- .option("--json", "Output status as JSON")
112
- .action(async (opts) => {
113
- const cwd = process.cwd();
114
- const index = await createIndex({ cwd });
115
- const info = await index.status();
116
- const processes = discoverRunningProcesses();
117
- if (opts.json) {
118
- const output = { ...info, processes };
119
- if (opts.changes) {
120
- const projectRoot = info.projectRoot;
121
- const projectStore = Store.forProject(projectRoot);
122
- const storedFileHashes = await projectStore.getFileHashes();
123
- const currentFiles = walkFiles(projectRoot);
124
- const changes = computeChanges(projectRoot, currentFiles, storedFileHashes);
125
- output.changes = changes;
126
- await projectStore.close();
127
- }
128
- console.log(JSON.stringify(output, null, 2));
129
- await index.close();
130
- return;
131
- }
132
- console.log(`Project root: ${info.projectRoot}`);
133
- if (info.prefix)
134
- console.log(`Subdirectory: ${info.prefix}`);
135
- console.log(`Model: ${info.config.model}`);
136
- if (info.config.provider)
137
- console.log(`Provider: ${info.config.provider}`);
138
- if (info.config.baseURL)
139
- console.log(`Base URL: ${info.config.baseURL}`);
140
- console.log(`Batch size: ${info.config.batchSize}`);
141
- if (info.config.maxTokens)
142
- console.log(`Max tokens: ${info.config.maxTokens}`);
143
- if (info.fileCount === 0) {
144
- console.log("\nNo index found. Run `lmgrep index` first.");
145
- await index.close();
146
- return;
147
- }
148
- console.log(`\nIndex stats:`);
149
- console.log(` Files: ${info.fileCount}`);
150
- console.log(` Chunks: ${info.chunkCount}`);
151
- console.log(` Unique hashes: ${info.uniqueHashes}`);
152
- if (info.indexModel)
153
- console.log(` Index model: ${info.indexModel}`);
154
- if (info.indexDimensions)
155
- console.log(` Dimensions: ${info.indexDimensions}`);
156
- if (info.chunkCount !== info.uniqueHashes) {
157
- console.log(` Duplicates: ${info.chunkCount - info.uniqueHashes}`);
158
- }
159
- console.log(`\nEmbedding check:`);
160
- if (info.embeddingOk) {
161
- console.log(` OK (${info.embeddingLatencyMs}ms)`);
162
- }
163
- else {
164
- console.log(` FAILED`);
165
- if (info.embeddingError) {
166
- for (const line of info.embeddingError.split("\n")) {
167
- console.log(` ${line}`);
168
- }
169
- }
170
- }
171
- console.log(`\nSearch check:`);
172
- if (info.searchOk) {
173
- console.log(` OK (${info.searchResultCount} result, ${info.searchLatencyMs}ms)`);
174
- }
175
- else if (info.embeddingOk && info.fileCount > 0) {
176
- console.log(` FAILED (query returned no results)`);
177
- }
178
- else {
179
- console.log(` SKIPPED`);
180
- }
181
- if (processes.length > 0) {
182
- console.log(`\nRunning processes:`);
183
- for (const proc of processes) {
184
- const kindLabel = proc.kind === "mcp" ? "MCP server" :
185
- proc.kind === "serve" ? "serve" :
186
- "CLI";
187
- const project = proc.projectRoot ?? "unknown";
188
- const watching = proc.watching ? ", watching" : "";
189
- console.log(` ${kindLabel} (pid ${proc.pid})${watching}`);
190
- console.log(` index: ${project}`);
191
- }
192
- }
193
- else {
194
- console.log(`\nNo running lmgrep processes.`);
195
- }
196
- if (opts.changes) {
197
- console.log(`\nScanning for changes...`);
198
- const projectRoot = info.projectRoot;
199
- const projectStore = Store.forProject(projectRoot);
200
- const storedFileHashes = await projectStore.getFileHashes();
201
- const currentFiles = walkFiles(projectRoot);
202
- const { added, modified, deleted } = computeChanges(projectRoot, currentFiles, storedFileHashes);
203
- const total = added.length + modified.length + deleted.length;
204
- if (total === 0) {
205
- console.log(" No changes detected.");
206
- }
207
- else {
208
- if (added.length > 0) {
209
- console.log(` Added: ${added.length}`);
210
- for (const f of added.slice(0, 10))
211
- console.log(` + ${f}`);
212
- if (added.length > 10)
213
- console.log(` ... and ${added.length - 10} more`);
214
- }
215
- if (modified.length > 0) {
216
- console.log(` Modified: ${modified.length}`);
217
- for (const f of modified.slice(0, 10))
218
- console.log(` ~ ${f}`);
219
- if (modified.length > 10)
220
- console.log(` ... and ${modified.length - 10} more`);
221
- }
222
- if (deleted.length > 0) {
223
- console.log(` Deleted: ${deleted.length}`);
224
- for (const f of deleted.slice(0, 10))
225
- console.log(` - ${f}`);
226
- if (deleted.length > 10)
227
- console.log(` ... and ${deleted.length - 10} more`);
228
- }
229
- console.log(`\n Run \`lmgrep index\` to update the index.`);
230
- }
231
- await projectStore.close();
232
- }
233
- await index.close();
234
- });
235
- program
236
- .command("repair")
237
- .description("Detect and fix index inconsistencies (orphaned/stale chunks)")
238
- .option("-d, --dry", "Show what would be repaired without making changes")
239
- .option("--json", "Output repair results as JSON")
240
- .action(async (opts) => {
241
- const cwd = process.cwd();
242
- const index = await createIndex({ cwd });
243
- const result = await index.repair(opts.dry);
244
- if (opts.json) {
245
- console.log(JSON.stringify(result, null, 2));
246
- }
247
- await index.close();
248
- });
249
- program
250
- .command("serve")
251
- .description("Watch the current directory and re-index on changes")
252
- .action(async () => {
253
- const cwd = process.cwd();
254
- const index = await createIndex({ cwd });
255
- await index.watch();
256
- });
257
- program
258
- .command("mcp")
259
- .description("Start the MCP server (stdio transport)")
260
- .action(async () => {
261
- await import("./mcp.js");
262
- });
263
- program
264
- .command("export")
265
- .description("Share this project's index with a peer via P2P")
266
- .action(async () => {
267
- const cwd = process.cwd();
268
- const { startExport } = await import("./lib/p2p.js");
269
- const { code, done } = await startExport({
270
- cwd,
271
- onProgress(sent, total) {
272
- process.stderr.write(`\rSending: ${sent}/${total} chunks`);
273
- },
274
- });
275
- console.log(`Share code: ${code}`);
276
- console.log("Waiting for peer... (Ctrl+C to cancel)\n");
277
- await done;
278
- process.stderr.write("\n");
279
- console.log("Transfer complete.");
280
- });
281
- program
282
- .command("init")
283
- .description("Detect your embedding setup and create config")
284
- .option("--force", "Overwrite existing config")
285
- .option("--local", "Write a project-local .lmgrep.yml instead of the global config")
286
- .action(async (opts) => {
287
- const cwd = process.cwd();
288
- const configPath = opts.local
289
- ? join(cwd, ".lmgrep.yml")
290
- : getGlobalConfigPath();
291
- if (existsSync(configPath) && !opts.force) {
292
- console.error(`Config already exists at ${configPath}. Use --force to overwrite.`);
293
- process.exit(1);
294
- }
295
- // Check if there's an existing index with model info
296
- const dbPath = getDbPath(cwd);
297
- const meta = existsSync(dbPath)
298
- ? readProjectMetadata(dbPath)
299
- : undefined;
300
- const indexFamily = meta?.model
301
- ? extractModelFamily(meta.model)
302
- : undefined;
303
- // Detect Ollama
304
- const ollama = await detectOllama();
305
- if (!ollama.running) {
306
- console.log("Ollama not detected.\n");
307
- console.log("Install Ollama:");
308
- console.log(" curl -fsSL https://ollama.com/install.sh | sh\n");
309
- if (indexFamily) {
310
- console.log(`This index was built with "${meta.model}" (${meta.dimensions} dims).`);
311
- console.log(`After installing Ollama, pull a compatible model and run \`lmgrep init\` again.`);
312
- }
313
- else {
314
- console.log("After installing, run `lmgrep init` again to auto-configure.");
315
- }
316
- // Still write a template config
317
- mkdirSync(join(configPath, ".."), { recursive: true });
318
- writeFileSync(configPath, buildConfigTemplate());
319
- console.log(`\nWrote ${configPath} (edit model before indexing)`);
320
- return;
321
- }
322
- console.log("Found Ollama.");
323
- // If we have index metadata, try to find a compatible model
324
- let selectedModel;
325
- if (indexFamily && meta?.dimensions) {
326
- console.log(`Index built with "${meta.model}" (${indexFamily}, ${meta.dimensions} dims)`);
327
- // Check if a compatible model is already pulled
328
- const compatible = ollama.models.find((m) => {
329
- const family = extractModelFamily(`ollama:${m}`);
330
- return family === indexFamily;
331
- });
332
- if (compatible) {
333
- selectedModel = compatible;
334
- console.log(`Found compatible model: ${compatible}`);
335
- }
336
- else {
337
- console.log(`\nNo compatible model found locally. You need a model from the "${indexFamily}" family.`);
338
- console.log("Pull one with:");
339
- console.log(` ollama pull ${indexFamily}\n`);
340
- console.log("Then run `lmgrep init` again to auto-configure.");
341
- }
342
- }
343
- // If no index constraint, pick the first embedding model or suggest one
344
- if (!selectedModel && !indexFamily) {
345
- if (ollama.models.length > 0) {
346
- // Prefer embedding-oriented models
347
- const embeddingModel = ollama.models.find((m) => m.includes("embed") ||
348
- m.includes("nomic") ||
349
- m.includes("bge") ||
350
- m.includes("minilm"));
351
- selectedModel = embeddingModel ?? ollama.models[0];
352
- console.log(`Using model: ${selectedModel}`);
353
- }
354
- else {
355
- console.log("\nNo models found. Pull an embedding model:");
356
- console.log(" ollama pull nomic-embed-text\n");
357
- console.log("Then run `lmgrep init` again.");
358
- }
359
- }
360
- const modelString = selectedModel
361
- ? `ollama:${selectedModel}`
362
- : undefined;
363
- mkdirSync(join(configPath, ".."), { recursive: true });
364
- writeFileSync(configPath, buildConfigTemplate({
365
- model: modelString,
366
- baseURL: modelString
367
- ? "http://localhost:11434/v1"
368
- : undefined,
369
- }));
370
- console.log(`Wrote ${configPath}`);
371
- });
372
- program
373
- .command("config")
374
- .description("Open the global config file in your editor")
375
- .action(() => {
376
- const configPath = getGlobalConfigPath();
377
- if (!existsSync(configPath)) {
378
- console.error(`No config found at ${configPath}. Run \`lmgrep init\` first.`);
379
- process.exit(1);
380
- }
381
- const editorCmd = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
382
- console.log(`Opening ${configPath}`);
383
- // $EDITOR may include flags (e.g. "code -w"). Split on whitespace
384
- // for the command/flags, but pass the path as its own argv entry so
385
- // paths containing spaces (e.g. macOS "Application Support") aren't
386
- // re-split by the shell.
387
- const parts = editorCmd.trim().split(/\s+/);
388
- const editor = parts[0];
389
- const editorArgs = parts.slice(1);
390
- const result = spawnSync(editor, [...editorArgs, configPath], {
391
- stdio: "inherit",
392
- });
393
- if (result.error || (result.status != null && result.status !== 0)) {
394
- console.error(`Could not open editor "${editorCmd}". Set $EDITOR or $VISUAL.`);
395
- process.exit(1);
396
- }
397
- });
398
- program
399
- .command("migrate")
400
- .description("Rename existing index directories to match the current slug scheme")
401
- .option("-d, --dry", "Show what would be migrated without making changes")
402
- .action(async (opts) => {
403
- const baseDir = join(homedir(), ".local", "state", "lmgrep");
404
- const projects = discoverIndexedProjects();
405
- if (projects.length === 0) {
406
- console.log("No indexed projects found.");
407
- return;
408
- }
409
- const moves = [];
410
- // Track which target paths already exist on disk OR are claimed by an
411
- // already-correctly-named source — those count as conflicts for any
412
- // other source mapping to the same target.
413
- const claimedTargets = new Set();
414
- for (const { dbPath, metadata } of projects) {
415
- const id = metadata.remote ?? metadata.root;
416
- const targetSlug = buildSlug(id);
417
- const targetPath = resolve(join(baseDir, targetSlug));
418
- if (resolve(dbPath) === targetPath) {
419
- claimedTargets.add(targetPath);
420
- }
421
- }
422
- for (const { dbPath, metadata } of projects) {
423
- const id = metadata.remote ?? metadata.root;
424
- const targetSlug = buildSlug(id);
425
- const targetPath = join(baseDir, targetSlug);
426
- const targetAbs = resolve(targetPath);
427
- if (resolve(dbPath) === targetAbs)
428
- continue;
429
- const conflict = claimedTargets.has(targetAbs) || existsSync(targetPath);
430
- moves.push({ from: dbPath, to: targetPath, id, conflict });
431
- // First non-conflicting mover claims the target so subsequent
432
- // movers in this run see it as a conflict.
433
- if (!conflict)
434
- claimedTargets.add(targetAbs);
435
- }
436
- if (moves.length === 0) {
437
- console.log("All indexes already use the current slug scheme.");
438
- return;
439
- }
440
- console.log(`Found ${moves.length} index(es) to migrate:\n`);
441
- for (const m of moves) {
442
- const arrow = m.conflict ? "→ (conflict, skipped)" : "→";
443
- console.log(` ${m.from}\n ${arrow} ${m.to}\n`);
444
- }
445
- const conflicts = moves.filter((m) => m.conflict);
446
- if (conflicts.length > 0) {
447
- console.log(`${conflicts.length} conflict(s): target already exists. ` +
448
- "These are likely sibling worktrees that already share a unified " +
449
- "index — delete the stale source manually with `rm -rf` after " +
450
- "verifying it's redundant.");
451
- }
452
- if (opts.dry) {
453
- console.log("\nDry run — no changes made.");
454
- return;
455
- }
456
- let migrated = 0;
457
- for (const m of moves) {
458
- if (m.conflict)
459
- continue;
460
- try {
461
- renameSync(m.from, m.to);
462
- migrated++;
463
- }
464
- catch (err) {
465
- const msg = err instanceof Error ? err.message : String(err);
466
- console.error(`Failed to migrate ${m.from}: ${msg}`);
467
- }
468
- }
469
- console.log(`\nMigrated ${migrated} index(es).`);
470
- });
471
- program
472
- .command("compact")
473
- .description("Compact the index to reclaim disk space")
474
- .action(async () => {
475
- const cwd = process.cwd();
476
- const store = Store.forProject(cwd);
477
- await store.compact();
478
- console.log("Compaction complete.");
479
- await store.close();
480
- });
481
- program
482
- .command("prune")
483
- .description("Delete the index database for the current directory")
484
- .option("--force", "Skip confirmation")
485
- .action(async (opts) => {
486
- const cwd = process.cwd();
487
- const dbPath = getDbPath(cwd);
488
- if (!existsSync(dbPath)) {
489
- console.log("No index found for this directory.");
490
- return;
491
- }
492
- if (!opts.force) {
493
- const readline = await import("node:readline");
494
- const rl = readline.createInterface({
495
- input: process.stdin,
496
- output: process.stdout,
497
- });
498
- const answer = await new Promise((resolve) => {
499
- rl.question(`Delete index at ${dbPath}? [y/N] `, resolve);
500
- });
501
- rl.close();
502
- if (answer.toLowerCase() !== "y") {
503
- console.log("Cancelled.");
504
- return;
505
- }
506
- }
507
- rmSync(dbPath, { recursive: true, force: true });
508
- console.log(`Deleted index at ${dbPath}`);
509
- });
510
- program
511
- .command("import [source]")
512
- .description("Import chunks from a peer (share code) or another lmgrep database (path). " +
513
- "If no argument is given, tries to find a legacy index for this directory.")
514
- .option("--reset", "Reset the current index before importing")
515
- .action(async (source, opts) => {
516
- const cwd = process.cwd();
517
- // P2P import if source looks like a share code
518
- if (source) {
519
- const { SHARE_CODE_RE, startImport } = await import("./lib/p2p.js");
520
- if (SHARE_CODE_RE.test(source)) {
521
- console.log("Connecting to peer...");
522
- const result = await startImport({
523
- cwd,
524
- code: source,
525
- reset: opts.reset,
526
- onProgress(received, total) {
527
- process.stderr.write(`\rReceiving: ${received}/${total} chunks`);
528
- },
529
- onMeta(meta) {
530
- console.log(`Peer index: ${meta.chunkCount} chunks` +
531
- (meta.model ? `, model: ${meta.model}` : "") +
532
- (meta.dimensions ? `, ${meta.dimensions} dims` : ""));
533
- },
534
- });
535
- process.stderr.write("\n");
536
- console.log(`Imported ${result.chunks} chunks and ${result.files} file hashes from peer.`);
537
- return;
538
- }
539
- }
540
- // Local import (existing logic)
541
- let sourcePath;
542
- const dbPath = source;
543
- if (dbPath) {
544
- sourcePath = resolve(cwd, dbPath);
545
- }
546
- else {
547
- const legacy = getLegacyDbPath(cwd);
548
- if (existsSync(legacy)) {
549
- sourcePath = legacy;
550
- console.log(`Found legacy index at ${legacy}`);
551
- }
552
- else {
553
- console.error("No legacy index found. Provide a path: lmgrep import <db-path>");
554
- process.exit(1);
555
- }
556
- }
557
- if (!existsSync(sourcePath)) {
558
- console.error(`Database not found: ${sourcePath}`);
559
- process.exit(1);
560
- }
561
- const newDbPath = getDbPath(cwd);
562
- if (resolve(sourcePath) === resolve(newDbPath)) {
563
- console.error("Source and destination are the same database.");
564
- process.exit(1);
565
- }
566
- const store = Store.forProject(cwd);
567
- if (opts.reset) {
568
- await store.reset();
569
- }
570
- const { chunks, files } = await store.importFrom(sourcePath);
571
- console.log(`Imported ${chunks} chunks and ${files} file hashes from ${sourcePath}`);
572
- // Show model info from source to guide the user
573
- const sourceMeta = readProjectMetadata(sourcePath);
574
- if (sourceMeta?.model) {
575
- const family = extractModelFamily(sourceMeta.model);
576
- console.log(`\nThis index was built with "${sourceMeta.model}" (${family}${sourceMeta.dimensions ? `, ${sourceMeta.dimensions} dims` : ""}).`);
577
- console.log(`Configure a compatible model in .lmgrep.yml, then run \`lmgrep init\` to auto-detect.`);
578
- }
579
- await store.close();
580
- });
581
- {
582
- const completionsCmd = program
583
- .command("completions")
584
- .description("Output shell completions");
585
- // Resolve the completions directory relative to this script
586
- const completionsDir = join(import.meta.dirname, "..", "completions");
587
- completionsCmd
588
- .command("zsh")
589
- .description("Output zsh completions")
590
- .option("--install", "Install to site-functions and reload completions")
591
- .action((opts) => {
592
- const script = readFileSync(join(completionsDir, "_lmgrep"), "utf-8");
593
- if (opts.install) {
594
- const siteFunctions = findZshSiteFunctions();
595
- if (!siteFunctions) {
596
- console.error("Could not find a writable zsh site-functions directory.\n" +
597
- "Output manually with: lmgrep completions zsh > /path/to/_lmgrep");
598
- process.exit(1);
599
- }
600
- const target = join(siteFunctions, "_lmgrep");
601
- mkdirSync(siteFunctions, { recursive: true });
602
- writeFileSync(target, script);
603
- console.log(`Installed completions to ${target}`);
604
- console.log("Restart your shell or run: exec zsh");
605
- return;
606
- }
607
- console.log(script);
608
- });
609
- }
610
- // Auto-detect MCP mode: no args + both stdin and stdout are piped (stdio transport)
611
- const userArgs = process.argv.slice(2);
612
- if (userArgs.length === 0 && !process.stdin.isTTY && !process.stdout.isTTY) {
613
- await import("./mcp.js");
614
- }
615
- else {
616
- program.parse();
617
- }
618
- // --- Zsh helpers ---
619
- function findZshSiteFunctions() {
620
- // Prefer user-local paths, fall back to system paths
621
- const candidates = [
622
- join(homedir(), ".local", "share", "zsh", "site-functions"),
623
- "/usr/local/share/zsh/site-functions",
624
- "/usr/share/zsh/site-functions",
625
- ];
626
- // Also check $fpath entries that contain "site-functions"
627
- try {
628
- const fpath = execSync("zsh -c 'echo $fpath'", {
629
- stdio: ["ignore", "pipe", "ignore"],
630
- timeout: 3000,
631
- })
632
- .toString()
633
- .trim();
634
- for (const p of fpath.split(" ")) {
635
- if (p.includes("site-functions") && !candidates.includes(p)) {
636
- candidates.push(p);
637
- }
638
- }
639
- }
640
- catch { }
641
- // Return the first candidate that exists or is in a writable parent
642
- for (const candidate of candidates) {
643
- try {
644
- if (existsSync(candidate)) {
645
- // Check if writable
646
- writeFileSync(join(candidate, ".lmgrep-test"), "");
647
- rmSync(join(candidate, ".lmgrep-test"));
648
- return candidate;
649
- }
650
- // Check if parent is writable (we can create the dir)
651
- const parent = join(candidate, "..");
652
- if (existsSync(parent)) {
653
- mkdirSync(candidate, { recursive: true });
654
- return candidate;
655
- }
656
- }
657
- catch {
658
- // not writable, try next
659
- }
660
- }
661
- return undefined;
662
- }
663
- // --- Helpers ---
664
- async function detectOllama() {
665
- try {
666
- const res = await fetch("http://localhost:11434/api/tags", {
667
- signal: AbortSignal.timeout(3000),
668
- });
669
- if (!res.ok)
670
- return { running: true, models: [] };
671
- const data = (await res.json());
672
- const models = (data.models ?? []).map((m) => m.name);
673
- return { running: true, models };
674
- }
675
- catch {
676
- return { running: false, models: [] };
677
- }
678
- }
679
- function buildConfigTemplate(overrides) {
680
- const model = overrides?.model;
681
- const hasModel = !!model;
682
- const modelLine = hasModel
683
- ? `model: ${model}`
684
- : `# model: ollama:nomic-embed-text # ← set your model here`;
685
- const baseURLLine = overrides?.baseURL
686
- ? `baseURL: ${overrides.baseURL}`
687
- : `# baseURL: http://localhost:11434/v1`;
688
- return `# lmgrep configuration
689
- #
690
- # Quick start with Ollama:
691
- # 1. Install: curl -fsSL https://ollama.com/install.sh | sh
692
- # 2. Pull a model: ollama pull nomic-embed-text
693
- # 3. Run: lmgrep init --force (to auto-detect)
694
-
695
- # Embedding model in "provider:model" format
696
- ${modelLine}
697
-
698
- # Base URL for the embedding API
699
- ${baseURLLine}
700
-
701
- # Batch size for embedding API calls
702
- batchSize: 100
703
-
704
- # Optional: override the provider package
705
- # provider: "@ai-sdk/openai"
706
-
707
- # Optional: embedding dimensions (if model supports it)
708
- # dimensions: 384
709
-
710
- # Optional: max tokens per chunk (estimated at 4 chars/token)
711
- # maxTokens: 8192
712
-
713
- # Optional: prefixes for asymmetric embedding models
714
- # queryPrefix: "search_query: "
715
- # documentPrefix: "search_document: "
716
-
717
- # Optional: additional ignore patterns (merged with .gitignore)
718
- # ignore:
719
- # - "*.generated.ts"
720
- # - "fixtures/"
721
-
722
- # Optional: extra file extensions to index
723
- # extensions:
724
- # include: [".sql", ".graphql", ".proto"]
725
- # exclude: [".json"]
726
- `;
727
- }
728
- function computeChanges(projectRoot, currentFiles, storedFileHashes) {
729
- const added = [];
730
- const modified = [];
731
- const deleted = [];
732
- const seen = new Set();
733
- for (const file of currentFiles) {
734
- seen.add(file);
735
- try {
736
- const content = readFileSync(join(projectRoot, file));
737
- const fileHash = createHash("sha256")
738
- .update(content)
739
- .digest("hex")
740
- .slice(0, 16);
741
- const stored = storedFileHashes.get(file);
742
- if (!stored) {
743
- added.push(file);
744
- }
745
- else if (stored !== fileHash) {
746
- modified.push(file);
747
- }
748
- }
749
- catch { }
750
- }
751
- for (const [fp] of storedFileHashes) {
752
- if (!seen.has(fp))
753
- deleted.push(fp);
754
- }
755
- return { added, modified, deleted };
756
- }
3
+ // Must come first sets TOKIO/RAYON/UV thread caps before the LanceDB native
4
+ // binding initializes its runtime.
5
+ import "./infrastructure/lancedb/NativeTuning.js";
6
+ import { Cli } from "./presentation/cli/Cli.js";
7
+ await new Cli().run();
757
8
  //# sourceMappingURL=cli.js.map