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,163 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { Language, Parser } from "web-tree-sitter";
4
+ import { Chunk } from "../../domain/corpus/Chunk.js";
5
+ import { CodeLocation } from "../../domain/corpus/CodeLocation.js";
6
+ import { ContentHash } from "../../domain/corpus/ContentHash.js";
7
+ import { ChunkContextBuilder } from "./ChunkContextBuilder.js";
8
+ import { LanguageCatalog } from "./LanguageCatalog.js";
9
+ import { SlidingWindowChunker } from "./SlidingWindowChunker.js";
10
+ /**
11
+ * Splits source into chunks along AST boundaries.
12
+ *
13
+ * Node-bounded chunks are what make results readable: a hit is a whole
14
+ * function or class, not an arbitrary window through the middle of one. Files
15
+ * with no grammar, or no chunkable structure, fall back to a sliding window.
16
+ */
17
+ export class TreeSitterChunker {
18
+ catalog;
19
+ context;
20
+ fallback;
21
+ /** Chunks larger than this are split by recursing into their children. */
22
+ static MAX_CHUNK_TOKENS = 8192;
23
+ /** A one-line fragment shorter than this is noise, not a unit of code. */
24
+ static MIN_CHUNK_CHARS = 50;
25
+ parser;
26
+ loaded = new Map();
27
+ constructor(catalog = new LanguageCatalog(), context = new ChunkContextBuilder(), fallback = new SlidingWindowChunker()) {
28
+ this.catalog = catalog;
29
+ this.context = context;
30
+ this.fallback = fallback;
31
+ }
32
+ async chunk(filePath, cwd) {
33
+ const language = this.catalog.forFile(filePath);
34
+ if (!language)
35
+ return this.fallback.chunk(filePath, cwd);
36
+ // Parser.init() must run before any Language.load(): it bootstraps the
37
+ // wasm runtime that grammar loading calls into. Reversing these two
38
+ // lines fails with "cannot read loadWebAssemblyModule of undefined".
39
+ const parser = await this.getParser();
40
+ const grammar = await this.loadGrammar(language);
41
+ if (!grammar)
42
+ return this.fallback.chunk(filePath, cwd);
43
+ parser.setLanguage(grammar);
44
+ const source = readFileSync(join(cwd, filePath), "utf-8");
45
+ const tree = parser.parse(source);
46
+ if (!tree)
47
+ return this.fallback.chunk(filePath, cwd);
48
+ const chunks = language.id === "markdown"
49
+ ? this.chunkMarkdown(tree.rootNode, filePath, source)
50
+ : this.collect(tree.rootNode, language, filePath, source, []);
51
+ return chunks.length > 0 ? chunks : this.fallback.chunk(filePath, cwd);
52
+ }
53
+ /**
54
+ * Markdown needs its own pass: the block grammar nests `section` nodes by
55
+ * heading level, so emitting them whole would collapse a document into one
56
+ * chunk. Splitting at every heading the grammar reports (so a `#` inside a
57
+ * fenced code block is not mistaken for one) gives complete,
58
+ * non-overlapping, heading-granular chunks instead.
59
+ */
60
+ chunkMarkdown(root, filePath, source) {
61
+ const lines = source.split("\n");
62
+ const headingRows = [];
63
+ const visit = (node) => {
64
+ if (node.type === "atx_heading" || node.type === "setext_heading") {
65
+ headingRows.push(node.startPosition.row);
66
+ }
67
+ for (const child of node.children)
68
+ visit(child);
69
+ };
70
+ visit(root);
71
+ const starts = [...new Set([0, ...headingRows])].sort((a, b) => a - b);
72
+ const chunks = [];
73
+ for (let i = 0; i < starts.length; i++) {
74
+ const start = starts[i];
75
+ const end = i + 1 < starts.length ? starts[i + 1] : lines.length;
76
+ const content = lines.slice(start, end).join("\n");
77
+ if (content.trim().length === 0)
78
+ continue;
79
+ const heading = (lines[start] ?? "").replace(/^\s*#+\s*/, "").trim();
80
+ chunks.push(new Chunk({
81
+ location: new CodeLocation(filePath, start + 1, end),
82
+ type: "section",
83
+ name: heading.slice(0, 80) || `lines_${start + 1}_${end}`,
84
+ content,
85
+ context: this.context.buildFileOnly(filePath),
86
+ hash: ContentHash.of(content),
87
+ }));
88
+ }
89
+ return chunks;
90
+ }
91
+ collect(node, language, filePath, source, chunks) {
92
+ if (!language.chunkTypes.includes(node.type)) {
93
+ for (const child of node.children) {
94
+ this.collect(child, language, filePath, source, chunks);
95
+ }
96
+ return chunks;
97
+ }
98
+ const content = node.text;
99
+ // Too large to embed whole: descend instead, so a big class becomes its
100
+ // methods rather than being truncated or skipped.
101
+ const estimatedTokens = Math.ceil(content.length / 4);
102
+ if (estimatedTokens > TreeSitterChunker.MAX_CHUNK_TOKENS &&
103
+ this.hasChunkableDescendants(node, language)) {
104
+ for (const child of node.children) {
105
+ this.collect(child, language, filePath, source, chunks);
106
+ }
107
+ return chunks;
108
+ }
109
+ // A short one-liner carries no retrievable meaning on its own.
110
+ if (content.split("\n").length < 2 &&
111
+ content.length < TreeSitterChunker.MIN_CHUNK_CHARS) {
112
+ return chunks;
113
+ }
114
+ chunks.push(new Chunk({
115
+ location: new CodeLocation(filePath, node.startPosition.row + 1, node.endPosition.row + 1),
116
+ type: node.type,
117
+ name: this.nodeName(node) ?? `anonymous_${node.startPosition.row}`,
118
+ content,
119
+ context: this.context.build(node, filePath, source, language),
120
+ hash: ContentHash.of(content),
121
+ }));
122
+ return chunks;
123
+ }
124
+ hasChunkableDescendants(node, language) {
125
+ for (const child of node.children) {
126
+ if (language.chunkTypes.includes(child.type))
127
+ return true;
128
+ if (this.hasChunkableDescendants(child, language))
129
+ return true;
130
+ }
131
+ return false;
132
+ }
133
+ nodeName(node) {
134
+ return (node.childForFieldName("name") ??
135
+ node.children.find((c) => c.type === "identifier" ||
136
+ c.type === "type_identifier" ||
137
+ // nix binds its target via an attrpath (e.g. `outputs = ...`)
138
+ c.type === "attrpath"))?.text;
139
+ }
140
+ async getParser() {
141
+ if (!this.parser) {
142
+ await Parser.init();
143
+ this.parser = new Parser();
144
+ }
145
+ return this.parser;
146
+ }
147
+ /**
148
+ * Grammars are cached for the process lifetime. They are wasm modules whose
149
+ * linear memory only ever grows, so loading one repeatedly would leak.
150
+ */
151
+ async loadGrammar(language) {
152
+ const cached = this.loaded.get(language.id);
153
+ if (cached)
154
+ return cached;
155
+ const wasmPath = this.catalog.wasmPathFor(language);
156
+ if (!wasmPath)
157
+ return undefined;
158
+ const grammar = await Language.load(wasmPath);
159
+ this.loaded.set(language.id, grammar);
160
+ return grammar;
161
+ }
162
+ }
163
+ //# sourceMappingURL=TreeSitterChunker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeSitterChunker.js","sourceRoot":"","sources":["../../../src/infrastructure/treesitter/TreeSitterChunker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAa,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAuB,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAUX;IACA;IACA;IAXlB,0EAA0E;IAClE,MAAM,CAAU,gBAAgB,GAAG,IAAI,CAAC;IAChD,0EAA0E;IAClE,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IAErC,MAAM,CAAqB;IAClB,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,YACkB,UAAU,IAAI,eAAe,EAAE,EAC/B,UAAU,IAAI,mBAAmB,EAAE,EACnC,WAAW,IAAI,oBAAoB,EAAE;QAFrC,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAA4B;QACnC,aAAQ,GAAR,QAAQ,CAA6B;IACpD,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,GAAW;QACxC,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usr/bin/env node
2
- export {};
2
+ import "./infrastructure/lancedb/NativeTuning.js";
package/dist/mcp.js CHANGED
@@ -1,67 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  process.title = "lmgrep-mcp";
3
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
- import { z } from "zod";
6
- import { createLmgrepCore } from "./lib/search-tool.js";
7
- const core = await createLmgrepCore({ cwd: process.cwd() });
8
- const server = new McpServer({
9
- name: "lmgrep",
10
- version: "0.1.0",
11
- });
12
- const searchTool = server.tool("search", core.buildSearchDescription(), {
13
- query: z.string().describe(core.searchParams.query.description),
14
- limit: z
15
- .number()
16
- .optional()
17
- .default(core.searchParams.limit.default)
18
- .describe(core.searchParams.limit.description),
19
- filePrefix: z
20
- .string()
21
- .optional()
22
- .describe(core.searchParams.filePrefix.description),
23
- type: z
24
- .array(z.string())
25
- .optional()
26
- .describe(core.searchParams.type.description),
27
- language: z
28
- .array(z.string())
29
- .optional()
30
- .describe(core.searchParams.language.description),
31
- project: z
32
- .string()
33
- .optional()
34
- .describe(core.searchParams.project.description),
35
- }, async (args) => {
36
- const result = await core.executeSearch(args);
37
- return {
38
- content: [{ type: "text", text: result.text }],
39
- ...(result.isError ? { isError: true } : {}),
40
- };
41
- });
42
- server.tool("list_other_indexed_projects", core.listProjectsDescription, {}, async () => {
43
- const result = await core.executeListProjects();
44
- return { content: [{ type: "text", text: result.text }] };
45
- });
46
- core.onHealthChange(() => {
47
- searchTool.update({ description: core.buildSearchDescription() });
48
- });
49
- core.startHealthLoop();
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 { LmgrepCore } from "./presentation/mcp/LmgrepCore.js";
7
+ import { LmgrepMcpServer } from "./presentation/mcp/McpServer.js";
8
+ const core = await LmgrepCore.open({
9
+ cwd: process.cwd(),
10
+ database: process.env.LMGREP_DATABASE || undefined,
11
+ });
12
+ const shutdown = () => {
13
+ core.dispose().finally(() => process.exit(0));
14
+ };
50
15
  process.on("exit", () => {
51
16
  core.dispose().catch(() => { });
52
17
  });
53
- process.on("SIGINT", () => {
54
- core.dispose().finally(() => process.exit(0));
55
- });
56
- process.on("SIGTERM", () => {
57
- core.dispose().finally(() => process.exit(0));
58
- });
59
- async function main() {
60
- const transport = new StdioServerTransport();
61
- await server.connect(transport);
62
- }
63
- main().catch((err) => {
64
- console.error("lmgrep MCP server error:", err);
65
- process.exit(1);
66
- });
18
+ process.on("SIGINT", shutdown);
19
+ process.on("SIGTERM", shutdown);
20
+ await new LmgrepMcpServer(core).serve();
67
21
  //# sourceMappingURL=mcp.js.map
package/dist/mcp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";AACA,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAE5D,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC5B,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;CAChB,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAC7B,QAAQ,EACR,IAAI,CAAC,sBAAsB,EAAE,EAC7B;IACC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CA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AC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";AACA,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC;AAE7B,8EAA8E;AAC9E,mCAAmC;AACnC,OAAO,0CAA0C,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC;IAClC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS;CAClD,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,GAAS,EAAE;IAC3B,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AACF,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEhC,MAAM,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { CommandContext } from "./CommandContext.js";
2
+ /**
3
+ * Assembles and runs the command-line interface.
4
+ *
5
+ * Two things here are deliberate. A bare `lmgrep <words>` searches, because
6
+ * searching is what lmgrep is for and it should not cost a subcommand. And the
7
+ * help is grouped, because a flat list of a dozen commands says nothing about
8
+ * which two anyone actually needs — the first group is the whole product, and
9
+ * the rest is setup you do once.
10
+ */
11
+ export declare class Cli {
12
+ private readonly context;
13
+ /** Help grouping, by command name. Order here is order in `--help`. */
14
+ private static readonly GROUPS;
15
+ private readonly program;
16
+ constructor(context?: CommandContext);
17
+ run(argv?: string[]): Promise<void>;
18
+ /**
19
+ * Treat a leading word that is not a command as the start of a query.
20
+ *
21
+ * The ambiguity is real but small: `lmgrep status` is the command, not a
22
+ * search for the word "status". Anything of more than one word, and
23
+ * anything that is not a command name, searches — which covers every query
24
+ * a person would actually type.
25
+ */
26
+ private withImplicitSearch;
27
+ private commandNames;
28
+ private group;
29
+ private static looksLikeStdioLaunch;
30
+ private commands;
31
+ }
@@ -0,0 +1,120 @@
1
+ import { Command } from "commander";
2
+ import { CommandContext } from "./CommandContext.js";
3
+ import { AskCommand } from "./commands/AskCommand.js";
4
+ import { CompletionsCommand } from "./commands/CompletionsCommand.js";
5
+ import { ConfigCommands } from "./commands/ConfigCommands.js";
6
+ import { IndexCommand } from "./commands/IndexCommand.js";
7
+ import { ProjectsCommand } from "./commands/ProjectsCommand.js";
8
+ import { SearchCommand } from "./commands/SearchCommand.js";
9
+ import { ServerCommands } from "./commands/ServerCommands.js";
10
+ import { ShareCommands } from "./commands/ShareCommands.js";
11
+ import { StatusCommand } from "./commands/StatusCommand.js";
12
+ /**
13
+ * Assembles and runs the command-line interface.
14
+ *
15
+ * Two things here are deliberate. A bare `lmgrep <words>` searches, because
16
+ * searching is what lmgrep is for and it should not cost a subcommand. And the
17
+ * help is grouped, because a flat list of a dozen commands says nothing about
18
+ * which two anyone actually needs — the first group is the whole product, and
19
+ * the rest is setup you do once.
20
+ */
21
+ export class Cli {
22
+ context;
23
+ /** Help grouping, by command name. Order here is order in `--help`. */
24
+ static GROUPS = [
25
+ ["Searching:", ["search", "ask"]],
26
+ ["Your projects:", ["index", "status", "projects"]],
27
+ ["Setup:", ["init", "config", "mcp", "completions"]],
28
+ ["Other:", ["serve", "share", "import"]],
29
+ ];
30
+ program = new Command();
31
+ constructor(context = new CommandContext()) {
32
+ this.context = context;
33
+ this.program
34
+ .name("lmgrep")
35
+ .description("Semantic code search, powered by a local embedding model")
36
+ .version("0.1.0")
37
+ .showHelpAfterError()
38
+ .addHelpText("after", "\nA bare query searches: lmgrep how are webhooks authenticated" +
39
+ "\nFirst time here: lmgrep init → lmgrep index");
40
+ for (const command of this.commands())
41
+ command.register(this.program);
42
+ this.group();
43
+ }
44
+ async run(argv = process.argv) {
45
+ // With no arguments and both streams piped, this was launched as an
46
+ // MCP server over stdio rather than by a human at a terminal.
47
+ if (Cli.looksLikeStdioLaunch(argv)) {
48
+ await import("../../mcp.js");
49
+ return;
50
+ }
51
+ try {
52
+ await this.program.parseAsync(this.withImplicitSearch(argv));
53
+ }
54
+ catch (err) {
55
+ // Every failure reaching here is a user-facing condition — no
56
+ // index, an unreachable provider, incompatible embeddings — not a
57
+ // defect. Report the message and set an exit code; a stack trace
58
+ // would only bury it. Guarding once here means no command can
59
+ // forget to.
60
+ this.context.fail(err);
61
+ }
62
+ }
63
+ /**
64
+ * Treat a leading word that is not a command as the start of a query.
65
+ *
66
+ * The ambiguity is real but small: `lmgrep status` is the command, not a
67
+ * search for the word "status". Anything of more than one word, and
68
+ * anything that is not a command name, searches — which covers every query
69
+ * a person would actually type.
70
+ */
71
+ withImplicitSearch(argv) {
72
+ const rest = argv.slice(2);
73
+ const first = rest[0];
74
+ if (!first || first.startsWith("-"))
75
+ return argv;
76
+ if (this.commandNames().has(first))
77
+ return argv;
78
+ return [...argv.slice(0, 2), "search", ...rest];
79
+ }
80
+ commandNames() {
81
+ const names = new Set(["help"]);
82
+ for (const command of this.program.commands) {
83
+ names.add(command.name());
84
+ for (const alias of command.aliases())
85
+ names.add(alias);
86
+ }
87
+ return names;
88
+ }
89
+ group() {
90
+ const groupOf = new Map();
91
+ for (const [group, names] of Cli.GROUPS) {
92
+ for (const name of names)
93
+ groupOf.set(name, group);
94
+ }
95
+ for (const command of this.program.commands) {
96
+ const group = groupOf.get(command.name());
97
+ if (group)
98
+ command.helpGroup(group);
99
+ }
100
+ }
101
+ static looksLikeStdioLaunch(argv) {
102
+ return (argv.slice(2).length === 0 &&
103
+ !process.stdin.isTTY &&
104
+ !process.stdout.isTTY);
105
+ }
106
+ commands() {
107
+ return [
108
+ new SearchCommand(this.context),
109
+ new AskCommand(this.context),
110
+ new IndexCommand(this.context),
111
+ new StatusCommand(this.context),
112
+ new ProjectsCommand(this.context),
113
+ new ConfigCommands(this.context),
114
+ new ServerCommands(this.context),
115
+ new ShareCommands(this.context),
116
+ new CompletionsCommand(this.context),
117
+ ];
118
+ }
119
+ }
120
+ //# sourceMappingURL=Cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../../../src/presentation/cli/Cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAO5D;;;;;;;;GAQG;AACH,MAAM,OAAO,GAAG;IAWc;IAV7B,uEAAuE;IAC/D,MAAM,CAAU,MAAM,GAA+C;QAC5E,CAAC,YAAY,EAAE,CAAC,QAAQ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,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1C,IAAI,KAAK;gBAAE,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,IAAc;QACjD,OAAO,CACN,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC;YAC1B,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK;YACpB,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CACrB,CAAC;IACH,CAAC;IAEO,QAAQ;QACf,OAAO;YACN,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;YAC5B,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;YAC9B,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;YACjC,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;YAChC,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;YAChC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/B,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC;SACpC,CAAC;IACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Command } from "commander";
2
+ /** The one option every command shares, and its help text. */
3
+ export declare class CliOptions {
4
+ /**
5
+ * `--in` replaced three overlapping options — `--project`, `--across` and
6
+ * `--database` — which were three spellings of "somewhere other than here".
7
+ *
8
+ * A value with a separator is a project directory, because that is what
9
+ * people have to hand; a bare name is a standalone index kept in the state
10
+ * directory, for corpora that are not repositories.
11
+ */
12
+ static readonly TARGET: string;
13
+ static target(command: Command): Command;
14
+ /** Commander calls this once per occurrence of a repeatable option. */
15
+ private static collect;
16
+ /** The single target a write command operates on, if any. */
17
+ static single(targets: string[] | undefined): string | undefined;
18
+ }
@@ -0,0 +1,25 @@
1
+ /** The one option every command shares, and its help text. */
2
+ export class CliOptions {
3
+ /**
4
+ * `--in` replaced three overlapping options — `--project`, `--across` and
5
+ * `--database` — which were three spellings of "somewhere other than here".
6
+ *
7
+ * A value with a separator is a project directory, because that is what
8
+ * people have to hand; a bare name is a standalone index kept in the state
9
+ * directory, for corpora that are not repositories.
10
+ */
11
+ static TARGET = "Project directory, or the name of a standalone index. " +
12
+ "Repeat to search several at once; use `.` to include the current project.";
13
+ static target(command) {
14
+ return command.option("--in <project-or-name>", CliOptions.TARGET, CliOptions.collect, []);
15
+ }
16
+ /** Commander calls this once per occurrence of a repeatable option. */
17
+ static collect(value, previous) {
18
+ return [...previous, value];
19
+ }
20
+ /** The single target a write command operates on, if any. */
21
+ static single(targets) {
22
+ return targets && targets.length > 0 ? targets[0] : undefined;
23
+ }
24
+ }
25
+ //# sourceMappingURL=CliOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CliOptions.js","sourceRoot":"","sources":["../../../src/presentation/cli/CliOptions.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,OAAO,UAAU;IACtB;;;;;;;OAOG;IACH,MAAM,CAAU,MAAM,GACrB,wDAAwD;QACxD,2EAA2E,CAAC;IAE7E,MAAM,CAAC,MAAM,CAAC,OAAgB;QAC7B,OAAO,OAAO,CAAC,MAAM,CACpB,wBAAwB,EACxB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,OAAO,EAClB,EAAc,CACd,CAAC;IACH,CAAC;IAED,uEAAuE;IAC/D,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,QAAkB;QACvD,OAAO,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,6DAA6D;IAC7D,MAAM,CAAC,MAAM,CAAC,OAA6B;QAC1C,OAAO,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/D,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { Lmgrep } from "../../application/Lmgrep.js";
2
+ import { LmgrepFactory } from "../../application/LmgrepFactory.js";
3
+ import { Renderer } from "./Renderer.js";
4
+ /** Options every command accepts. */
5
+ export interface GlobalOptions {
6
+ /** Repeatable `--in` targets. Write commands use only the first. */
7
+ in?: string[];
8
+ }
9
+ /**
10
+ * Shared plumbing for CLI commands: opening an Lmgrep, closing it again, and
11
+ * turning a thrown error into an exit code.
12
+ *
13
+ * Commands run through {@link withLmgrep} rather than opening their own, so no
14
+ * command can forget to close the database — a leaked LanceDB connection keeps
15
+ * a native runtime and its buffers alive for the life of the process.
16
+ */
17
+ export declare class CommandContext {
18
+ readonly renderer: Renderer;
19
+ private readonly factory;
20
+ constructor(renderer?: Renderer, factory?: LmgrepFactory);
21
+ get cwd(): string;
22
+ open(options: GlobalOptions): Promise<Lmgrep>;
23
+ /**
24
+ * Split `--in` values into the three things they can mean.
25
+ *
26
+ * The first path-like value replaces the working directory — "act as if I
27
+ * were there" — which is what makes `status --in ../other` and
28
+ * `search --in ../other` mean the obvious thing without a second flag. Any
29
+ * further paths are additional projects to search. A bare name selects a
30
+ * standalone index instead.
31
+ */
32
+ static targets(options: GlobalOptions): {
33
+ cwd: string;
34
+ name?: string;
35
+ across: string[];
36
+ };
37
+ /** Open, run, and always close — even when `run` throws. */
38
+ withLmgrep<T>(options: GlobalOptions, run: (lmgrep: Lmgrep) => Promise<T>): Promise<T | undefined>;
39
+ /**
40
+ * Report a failure the way a CLI should: message on stderr, non-zero exit,
41
+ * no stack trace. Errors reaching here are user-facing conditions (no
42
+ * index, bad path, unreachable provider), not defects. Called once from
43
+ * {@link Cli.run} so no command can forget to.
44
+ */
45
+ fail(error: unknown): void;
46
+ static isPathLike(value: string): boolean;
47
+ static integer(value: string | undefined, fallback: number): number;
48
+ /** Parse a comma-separated option into trimmed values. */
49
+ static list(value?: string): string[] | undefined;
50
+ }
@@ -0,0 +1,88 @@
1
+ import { resolve } from "node:path";
2
+ import { LmgrepFactory } from "../../application/LmgrepFactory.js";
3
+ import { Renderer } from "./Renderer.js";
4
+ /**
5
+ * Shared plumbing for CLI commands: opening an Lmgrep, closing it again, and
6
+ * turning a thrown error into an exit code.
7
+ *
8
+ * Commands run through {@link withLmgrep} rather than opening their own, so no
9
+ * command can forget to close the database — a leaked LanceDB connection keeps
10
+ * a native runtime and its buffers alive for the life of the process.
11
+ */
12
+ export class CommandContext {
13
+ renderer;
14
+ factory;
15
+ constructor(renderer = new Renderer(), factory = new LmgrepFactory()) {
16
+ this.renderer = renderer;
17
+ this.factory = factory;
18
+ }
19
+ get cwd() {
20
+ return process.cwd();
21
+ }
22
+ async open(options) {
23
+ const targets = CommandContext.targets(options);
24
+ return this.factory.open({
25
+ cwd: targets.cwd,
26
+ database: targets.name,
27
+ onWarning: (message) => this.renderer.error(message),
28
+ });
29
+ }
30
+ /**
31
+ * Split `--in` values into the three things they can mean.
32
+ *
33
+ * The first path-like value replaces the working directory — "act as if I
34
+ * were there" — which is what makes `status --in ../other` and
35
+ * `search --in ../other` mean the obvious thing without a second flag. Any
36
+ * further paths are additional projects to search. A bare name selects a
37
+ * standalone index instead.
38
+ */
39
+ static targets(options) {
40
+ const values = options.in ?? [];
41
+ const paths = values.filter((v) => CommandContext.isPathLike(v));
42
+ const name = values.find((v) => !CommandContext.isPathLike(v));
43
+ return {
44
+ cwd: paths[0] ? resolve(process.cwd(), paths[0]) : process.cwd(),
45
+ name,
46
+ across: paths.slice(1),
47
+ };
48
+ }
49
+ /** Open, run, and always close — even when `run` throws. */
50
+ async withLmgrep(options, run) {
51
+ const lmgrep = await this.open(options);
52
+ try {
53
+ return await run(lmgrep);
54
+ }
55
+ finally {
56
+ await lmgrep.close();
57
+ }
58
+ }
59
+ /**
60
+ * Report a failure the way a CLI should: message on stderr, non-zero exit,
61
+ * no stack trace. Errors reaching here are user-facing conditions (no
62
+ * index, bad path, unreachable provider), not defects. Called once from
63
+ * {@link Cli.run} so no command can forget to.
64
+ */
65
+ fail(error) {
66
+ this.renderer.error(error instanceof Error ? error.message : String(error));
67
+ process.exitCode = 1;
68
+ }
69
+ static isPathLike(value) {
70
+ return (value.includes("/") ||
71
+ value.includes("\\") ||
72
+ value === "." ||
73
+ value === "..");
74
+ }
75
+ static integer(value, fallback) {
76
+ if (value === undefined)
77
+ return fallback;
78
+ const n = Number.parseInt(value, 10);
79
+ return Number.isNaN(n) ? fallback : n;
80
+ }
81
+ /** Parse a comma-separated option into trimmed values. */
82
+ static list(value) {
83
+ if (!value)
84
+ return undefined;
85
+ return value.split(",").map((s) => s.trim());
86
+ }
87
+ }
88
+ //# sourceMappingURL=CommandContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandContext.js","sourceRoot":"","sources":["../../../src/presentation/cli/CommandContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IAEhB;IACQ;IAFlB,YACU,WAAqB,IAAI,QAAQ,EAAE,EAC3B,UAAyB,IAAI,aAAa,EAAE;QADpD,aAAQ,GAAR,QAAQ,CAA2B;QAC3B,YAAO,GAAP,OAAO,CAAqC;IAC3D,CAAC;IAEJ,IAAI,GAAG;QACN,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAsB;QAChC,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACxB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,QAAQ,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