lmgrep 0.1.18 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/README.md +253 -62
  2. package/completions/_lmgrep +49 -40
  3. package/dist/application/Lmgrep.d.ts +107 -0
  4. package/dist/application/Lmgrep.js +99 -0
  5. package/dist/application/Lmgrep.js.map +1 -0
  6. package/dist/application/LmgrepFactory.d.ts +40 -0
  7. package/dist/application/LmgrepFactory.js +155 -0
  8. package/dist/application/LmgrepFactory.js.map +1 -0
  9. package/dist/application/indexing/BranchBootstrapper.d.ts +21 -0
  10. package/dist/application/indexing/BranchBootstrapper.js +52 -0
  11. package/dist/application/indexing/BranchBootstrapper.js.map +1 -0
  12. package/dist/application/indexing/BranchManifestSweeper.d.ts +17 -0
  13. package/dist/application/indexing/BranchManifestSweeper.js +35 -0
  14. package/dist/application/indexing/BranchManifestSweeper.js.map +1 -0
  15. package/dist/application/indexing/Duration.d.ts +9 -0
  16. package/dist/application/indexing/Duration.js +25 -0
  17. package/dist/application/indexing/Duration.js.map +1 -0
  18. package/dist/application/indexing/EmbeddingAbortError.d.ts +11 -0
  19. package/dist/application/indexing/EmbeddingAbortError.js +20 -0
  20. package/dist/application/indexing/EmbeddingAbortError.js.map +1 -0
  21. package/dist/application/indexing/EmbeddingPipeline.d.ts +59 -0
  22. package/dist/application/indexing/EmbeddingPipeline.js +140 -0
  23. package/dist/application/indexing/EmbeddingPipeline.js.map +1 -0
  24. package/dist/application/indexing/IndexBuilder.d.ts +112 -0
  25. package/dist/application/indexing/IndexBuilder.js +370 -0
  26. package/dist/application/indexing/IndexBuilder.js.map +1 -0
  27. package/dist/application/indexing/IndexingProgress.d.ts +34 -0
  28. package/dist/application/indexing/IndexingProgress.js +2 -0
  29. package/dist/application/indexing/IndexingProgress.js.map +1 -0
  30. package/dist/application/operations/Deadline.d.ts +13 -0
  31. package/dist/application/operations/Deadline.js +29 -0
  32. package/dist/application/operations/Deadline.js.map +1 -0
  33. package/dist/application/operations/HealthMonitor.d.ts +58 -0
  34. package/dist/application/operations/HealthMonitor.js +128 -0
  35. package/dist/application/operations/HealthMonitor.js.map +1 -0
  36. package/dist/application/operations/IndexAlternatives.d.ts +35 -0
  37. package/dist/application/operations/IndexAlternatives.js +61 -0
  38. package/dist/application/operations/IndexAlternatives.js.map +1 -0
  39. package/dist/application/operations/IndexInventory.d.ts +69 -0
  40. package/dist/application/operations/IndexInventory.js +99 -0
  41. package/dist/application/operations/IndexInventory.js.map +1 -0
  42. package/dist/application/operations/StatusService.d.ts +90 -0
  43. package/dist/application/operations/StatusService.js +171 -0
  44. package/dist/application/operations/StatusService.js.map +1 -0
  45. package/dist/application/operations/WatchService.d.ts +67 -0
  46. package/dist/application/operations/WatchService.js +145 -0
  47. package/dist/application/operations/WatchService.js.map +1 -0
  48. package/dist/application/operations/WorkingTreeDiff.d.ts +19 -0
  49. package/dist/application/operations/WorkingTreeDiff.js +36 -0
  50. package/dist/application/operations/WorkingTreeDiff.js.map +1 -0
  51. package/dist/application/research/ResearchAgent.d.ts +68 -0
  52. package/dist/application/research/ResearchAgent.js +201 -0
  53. package/dist/application/research/ResearchAgent.js.map +1 -0
  54. package/dist/application/research/ResearchPrompts.d.ts +16 -0
  55. package/dist/application/research/ResearchPrompts.js +34 -0
  56. package/dist/application/research/ResearchPrompts.js.map +1 -0
  57. package/dist/application/search/SearchCriteria.d.ts +37 -0
  58. package/dist/application/search/SearchCriteria.js +48 -0
  59. package/dist/application/search/SearchCriteria.js.map +1 -0
  60. package/dist/application/search/SearchService.d.ts +36 -0
  61. package/dist/application/search/SearchService.js +108 -0
  62. package/dist/application/search/SearchService.js.map +1 -0
  63. package/dist/application/search/SearchTargetResolver.d.ts +56 -0
  64. package/dist/application/search/SearchTargetResolver.js +104 -0
  65. package/dist/application/search/SearchTargetResolver.js.map +1 -0
  66. package/dist/cli.d.ts +1 -1
  67. package/dist/cli.js +4 -953
  68. package/dist/cli.js.map +1 -1
  69. package/dist/domain/config/ConfigSource.d.ts +16 -0
  70. package/dist/domain/config/ConfigSource.js +2 -0
  71. package/dist/domain/config/ConfigSource.js.map +1 -0
  72. package/dist/domain/config/LmgrepConfig.d.ts +53 -0
  73. package/dist/domain/config/LmgrepConfig.js +2 -0
  74. package/dist/domain/config/LmgrepConfig.js.map +1 -0
  75. package/dist/domain/corpus/Chunk.d.ts +49 -0
  76. package/dist/domain/corpus/Chunk.js +60 -0
  77. package/dist/domain/corpus/Chunk.js.map +1 -0
  78. package/dist/domain/corpus/CodeLocation.d.ts +18 -0
  79. package/dist/domain/corpus/CodeLocation.js +34 -0
  80. package/dist/domain/corpus/CodeLocation.js.map +1 -0
  81. package/dist/domain/corpus/ContentHash.d.ts +15 -0
  82. package/dist/domain/corpus/ContentHash.js +30 -0
  83. package/dist/domain/corpus/ContentHash.js.map +1 -0
  84. package/dist/domain/corpus/FileVersion.d.ts +31 -0
  85. package/dist/domain/corpus/FileVersion.js +47 -0
  86. package/dist/domain/corpus/FileVersion.js.map +1 -0
  87. package/dist/domain/corpus/SourceFile.d.ts +26 -0
  88. package/dist/domain/corpus/SourceFile.js +47 -0
  89. package/dist/domain/corpus/SourceFile.js.map +1 -0
  90. package/dist/domain/corpus/Vector.d.ts +37 -0
  91. package/dist/domain/corpus/Vector.js +96 -0
  92. package/dist/domain/corpus/Vector.js.map +1 -0
  93. package/dist/domain/ports/ChatModelPort.d.ts +57 -0
  94. package/dist/domain/ports/ChatModelPort.js +2 -0
  95. package/dist/domain/ports/ChatModelPort.js.map +1 -0
  96. package/dist/domain/ports/ChunkRepositoryPort.d.ts +42 -0
  97. package/dist/domain/ports/ChunkRepositoryPort.js +2 -0
  98. package/dist/domain/ports/ChunkRepositoryPort.js.map +1 -0
  99. package/dist/domain/ports/ChunkerPort.d.ts +5 -0
  100. package/dist/domain/ports/ChunkerPort.js +2 -0
  101. package/dist/domain/ports/ChunkerPort.js.map +1 -0
  102. package/dist/domain/ports/DatabaseSessionPort.d.ts +10 -0
  103. package/dist/domain/ports/DatabaseSessionPort.js +2 -0
  104. package/dist/domain/ports/DatabaseSessionPort.js.map +1 -0
  105. package/dist/domain/ports/EmbedderPort.d.ts +14 -0
  106. package/dist/domain/ports/EmbedderPort.js +2 -0
  107. package/dist/domain/ports/EmbedderPort.js.map +1 -0
  108. package/dist/domain/ports/FileManifestRepositoryPort.d.ts +32 -0
  109. package/dist/domain/ports/FileManifestRepositoryPort.js +2 -0
  110. package/dist/domain/ports/FileManifestRepositoryPort.js.map +1 -0
  111. package/dist/domain/ports/GitPort.d.ts +24 -0
  112. package/dist/domain/ports/GitPort.js +2 -0
  113. package/dist/domain/ports/GitPort.js.map +1 -0
  114. package/dist/domain/ports/IndexMaintenancePort.d.ts +58 -0
  115. package/dist/domain/ports/IndexMaintenancePort.js +2 -0
  116. package/dist/domain/ports/IndexMaintenancePort.js.map +1 -0
  117. package/dist/domain/ports/IndexMetadataPort.d.ts +23 -0
  118. package/dist/domain/ports/IndexMetadataPort.js +2 -0
  119. package/dist/domain/ports/IndexMetadataPort.js.map +1 -0
  120. package/dist/domain/ports/LockPort.d.ts +17 -0
  121. package/dist/domain/ports/LockPort.js +2 -0
  122. package/dist/domain/ports/LockPort.js.map +1 -0
  123. package/dist/domain/ports/LoggerPort.d.ts +5 -0
  124. package/dist/domain/ports/LoggerPort.js +2 -0
  125. package/dist/domain/ports/LoggerPort.js.map +1 -0
  126. package/dist/domain/ports/ProjectIndexesPort.d.ts +20 -0
  127. package/dist/domain/ports/ProjectIndexesPort.js +2 -0
  128. package/dist/domain/ports/ProjectIndexesPort.js.map +1 -0
  129. package/dist/domain/ports/ProjectRegistryPort.d.ts +42 -0
  130. package/dist/domain/ports/ProjectRegistryPort.js +2 -0
  131. package/dist/domain/ports/ProjectRegistryPort.js.map +1 -0
  132. package/dist/domain/ports/StateDirectoryPort.d.ts +29 -0
  133. package/dist/domain/ports/StateDirectoryPort.js +2 -0
  134. package/dist/domain/ports/StateDirectoryPort.js.map +1 -0
  135. package/dist/domain/ports/WorkspacePort.d.ts +38 -0
  136. package/dist/domain/ports/WorkspacePort.js +2 -0
  137. package/dist/domain/ports/WorkspacePort.js.map +1 -0
  138. package/dist/domain/project/Branch.d.ts +20 -0
  139. package/dist/domain/project/Branch.js +33 -0
  140. package/dist/domain/project/Branch.js.map +1 -0
  141. package/dist/domain/project/DatabaseLocation.d.ts +32 -0
  142. package/dist/domain/project/DatabaseLocation.js +35 -0
  143. package/dist/domain/project/DatabaseLocation.js.map +1 -0
  144. package/dist/domain/project/IndexMetadata.d.ts +17 -0
  145. package/dist/domain/project/IndexMetadata.js +2 -0
  146. package/dist/domain/project/IndexMetadata.js.map +1 -0
  147. package/dist/domain/project/ModelIdentity.d.ts +58 -0
  148. package/dist/domain/project/ModelIdentity.js +94 -0
  149. package/dist/domain/project/ModelIdentity.js.map +1 -0
  150. package/dist/domain/project/Project.d.ts +17 -0
  151. package/dist/domain/project/Project.js +21 -0
  152. package/dist/domain/project/Project.js.map +1 -0
  153. package/dist/domain/project/ProjectId.d.ts +28 -0
  154. package/dist/domain/project/ProjectId.js +58 -0
  155. package/dist/domain/project/ProjectId.js.map +1 -0
  156. package/dist/domain/project/ProjectLocator.d.ts +112 -0
  157. package/dist/domain/project/ProjectLocator.js +178 -0
  158. package/dist/domain/project/ProjectLocator.js.map +1 -0
  159. package/dist/domain/research/Citation.d.ts +27 -0
  160. package/dist/domain/research/Citation.js +43 -0
  161. package/dist/domain/research/Citation.js.map +1 -0
  162. package/dist/domain/research/EvidenceLedger.d.ts +47 -0
  163. package/dist/domain/research/EvidenceLedger.js +111 -0
  164. package/dist/domain/research/EvidenceLedger.js.map +1 -0
  165. package/dist/domain/research/ResearchTrace.d.ts +19 -0
  166. package/dist/domain/research/ResearchTrace.js +22 -0
  167. package/dist/domain/research/ResearchTrace.js.map +1 -0
  168. package/dist/domain/retrieval/Hit.d.ts +19 -0
  169. package/dist/domain/retrieval/Hit.js +28 -0
  170. package/dist/domain/retrieval/Hit.js.map +1 -0
  171. package/dist/domain/retrieval/HitList.d.ts +35 -0
  172. package/dist/domain/retrieval/HitList.js +81 -0
  173. package/dist/domain/retrieval/HitList.js.map +1 -0
  174. package/dist/domain/retrieval/MissingIndexError.d.ts +11 -0
  175. package/dist/domain/retrieval/MissingIndexError.js +15 -0
  176. package/dist/domain/retrieval/MissingIndexError.js.map +1 -0
  177. package/dist/index.d.ts +43 -45
  178. package/dist/index.js +30 -567
  179. package/dist/index.js.map +1 -1
  180. package/dist/infrastructure/ai/AiSdkChatModel.d.ts +31 -0
  181. package/dist/infrastructure/ai/AiSdkChatModel.js +137 -0
  182. package/dist/infrastructure/ai/AiSdkChatModel.js.map +1 -0
  183. package/dist/infrastructure/ai/AiSdkEmbedder.d.ts +28 -0
  184. package/dist/infrastructure/ai/AiSdkEmbedder.js +79 -0
  185. package/dist/infrastructure/ai/AiSdkEmbedder.js.map +1 -0
  186. package/dist/infrastructure/ai/DockerModelRunnerProbe.d.ts +16 -0
  187. package/dist/infrastructure/ai/DockerModelRunnerProbe.js +52 -0
  188. package/dist/infrastructure/ai/DockerModelRunnerProbe.js.map +1 -0
  189. package/dist/infrastructure/ai/EmbeddingPrefixes.d.ts +21 -0
  190. package/dist/infrastructure/ai/EmbeddingPrefixes.js +40 -0
  191. package/dist/infrastructure/ai/EmbeddingPrefixes.js.map +1 -0
  192. package/dist/infrastructure/ai/LmStudioProbe.d.ts +18 -0
  193. package/dist/infrastructure/ai/LmStudioProbe.js +49 -0
  194. package/dist/infrastructure/ai/LmStudioProbe.js.map +1 -0
  195. package/dist/infrastructure/ai/LocalModelReloader.d.ts +21 -0
  196. package/dist/infrastructure/ai/LocalModelReloader.js +61 -0
  197. package/dist/infrastructure/ai/LocalModelReloader.js.map +1 -0
  198. package/dist/infrastructure/ai/LocalRuntimeDetector.d.ts +36 -0
  199. package/dist/infrastructure/ai/LocalRuntimeDetector.js +63 -0
  200. package/dist/infrastructure/ai/LocalRuntimeDetector.js.map +1 -0
  201. package/dist/infrastructure/ai/ModelRuntime.d.ts +32 -0
  202. package/dist/infrastructure/ai/ModelRuntime.js +2 -0
  203. package/dist/infrastructure/ai/ModelRuntime.js.map +1 -0
  204. package/dist/infrastructure/ai/OllamaProbe.d.ts +22 -0
  205. package/dist/infrastructure/ai/OllamaProbe.js +71 -0
  206. package/dist/infrastructure/ai/OllamaProbe.js.map +1 -0
  207. package/dist/infrastructure/ai/ProviderFailure.d.ts +16 -0
  208. package/dist/infrastructure/ai/ProviderFailure.js +35 -0
  209. package/dist/infrastructure/ai/ProviderFailure.js.map +1 -0
  210. package/dist/infrastructure/ai/ProviderModuleLoader.d.ts +14 -0
  211. package/dist/infrastructure/ai/ProviderModuleLoader.js +56 -0
  212. package/dist/infrastructure/ai/ProviderModuleLoader.js.map +1 -0
  213. package/dist/infrastructure/ai/ProviderRegistry.d.ts +38 -0
  214. package/dist/infrastructure/ai/ProviderRegistry.js +63 -0
  215. package/dist/infrastructure/ai/ProviderRegistry.js.map +1 -0
  216. package/dist/infrastructure/fs/ConfigLoader.d.ts +59 -0
  217. package/dist/infrastructure/fs/ConfigLoader.js +194 -0
  218. package/dist/infrastructure/fs/ConfigLoader.js.map +1 -0
  219. package/dist/infrastructure/fs/DatabaseLocks.d.ts +52 -0
  220. package/dist/infrastructure/fs/DatabaseLocks.js +92 -0
  221. package/dist/infrastructure/fs/DatabaseLocks.js.map +1 -0
  222. package/dist/infrastructure/fs/DiskUsage.d.ts +6 -0
  223. package/dist/infrastructure/fs/DiskUsage.js +41 -0
  224. package/dist/infrastructure/fs/DiskUsage.js.map +1 -0
  225. package/dist/infrastructure/fs/IndexableFileRules.d.ts +33 -0
  226. package/dist/infrastructure/fs/IndexableFileRules.js +177 -0
  227. package/dist/infrastructure/fs/IndexableFileRules.js.map +1 -0
  228. package/dist/infrastructure/fs/Loggers.d.ts +14 -0
  229. package/dist/infrastructure/fs/Loggers.js +18 -0
  230. package/dist/infrastructure/fs/Loggers.js.map +1 -0
  231. package/dist/infrastructure/fs/PidFileLock.d.ts +40 -0
  232. package/dist/infrastructure/fs/PidFileLock.js +97 -0
  233. package/dist/infrastructure/fs/PidFileLock.js.map +1 -0
  234. package/dist/infrastructure/fs/ProjectIndexes.d.ts +8 -0
  235. package/dist/infrastructure/fs/ProjectIndexes.js +35 -0
  236. package/dist/infrastructure/fs/ProjectIndexes.js.map +1 -0
  237. package/dist/infrastructure/fs/ProjectMetadataStore.d.ts +42 -0
  238. package/dist/infrastructure/fs/ProjectMetadataStore.js +86 -0
  239. package/dist/infrastructure/fs/ProjectMetadataStore.js.map +1 -0
  240. package/dist/infrastructure/fs/ProjectRegistry.d.ts +25 -0
  241. package/dist/infrastructure/fs/ProjectRegistry.js +83 -0
  242. package/dist/infrastructure/fs/ProjectRegistry.js.map +1 -0
  243. package/dist/infrastructure/fs/StateDirectory.d.ts +28 -0
  244. package/dist/infrastructure/fs/StateDirectory.js +71 -0
  245. package/dist/infrastructure/fs/StateDirectory.js.map +1 -0
  246. package/dist/infrastructure/fs/Workspace.d.ts +25 -0
  247. package/dist/infrastructure/fs/Workspace.js +90 -0
  248. package/dist/infrastructure/fs/Workspace.js.map +1 -0
  249. package/dist/infrastructure/git/GitClient.d.ts +34 -0
  250. package/dist/infrastructure/git/GitClient.js +74 -0
  251. package/dist/infrastructure/git/GitClient.js.map +1 -0
  252. package/dist/infrastructure/lancedb/ChunkRepository.d.ts +38 -0
  253. package/dist/infrastructure/lancedb/ChunkRepository.js +166 -0
  254. package/dist/infrastructure/lancedb/ChunkRepository.js.map +1 -0
  255. package/dist/infrastructure/lancedb/DatabaseImporter.d.ts +22 -0
  256. package/dist/infrastructure/lancedb/DatabaseImporter.js +74 -0
  257. package/dist/infrastructure/lancedb/DatabaseImporter.js.map +1 -0
  258. package/dist/infrastructure/lancedb/FileManifestRepository.d.ts +34 -0
  259. package/dist/infrastructure/lancedb/FileManifestRepository.js +137 -0
  260. package/dist/infrastructure/lancedb/FileManifestRepository.js.map +1 -0
  261. package/dist/infrastructure/lancedb/IndexMaintenance.d.ts +53 -0
  262. package/dist/infrastructure/lancedb/IndexMaintenance.js +227 -0
  263. package/dist/infrastructure/lancedb/IndexMaintenance.js.map +1 -0
  264. package/dist/infrastructure/lancedb/LanceTables.d.ts +67 -0
  265. package/dist/infrastructure/lancedb/LanceTables.js +159 -0
  266. package/dist/infrastructure/lancedb/LanceTables.js.map +1 -0
  267. package/dist/{lib/native-tuning.js → infrastructure/lancedb/NativeTuning.js} +1 -1
  268. package/dist/infrastructure/lancedb/NativeTuning.js.map +1 -0
  269. package/dist/infrastructure/lancedb/RowReplication.d.ts +27 -0
  270. package/dist/infrastructure/lancedb/RowReplication.js +82 -0
  271. package/dist/infrastructure/lancedb/RowReplication.js.map +1 -0
  272. package/dist/infrastructure/lancedb/VectorIndexPolicy.d.ts +60 -0
  273. package/dist/infrastructure/lancedb/VectorIndexPolicy.js +72 -0
  274. package/dist/infrastructure/lancedb/VectorIndexPolicy.js.map +1 -0
  275. package/dist/infrastructure/p2p/IndexShare.d.ts +45 -0
  276. package/dist/infrastructure/p2p/IndexShare.js +160 -0
  277. package/dist/infrastructure/p2p/IndexShare.js.map +1 -0
  278. package/dist/infrastructure/p2p/PeerSwarm.d.ts +16 -0
  279. package/dist/infrastructure/p2p/PeerSwarm.js +41 -0
  280. package/dist/infrastructure/p2p/PeerSwarm.js.map +1 -0
  281. package/dist/infrastructure/p2p/SecureChannel.d.ts +60 -0
  282. package/dist/infrastructure/p2p/SecureChannel.js +71 -0
  283. package/dist/infrastructure/p2p/SecureChannel.js.map +1 -0
  284. package/dist/infrastructure/p2p/ShareCode.d.ts +25 -0
  285. package/dist/infrastructure/p2p/ShareCode.js +304 -0
  286. package/dist/infrastructure/p2p/ShareCode.js.map +1 -0
  287. package/dist/infrastructure/process/ProcessRegistry.d.ts +50 -0
  288. package/dist/infrastructure/process/ProcessRegistry.js +109 -0
  289. package/dist/infrastructure/process/ProcessRegistry.js.map +1 -0
  290. package/dist/infrastructure/treesitter/ChunkContextBuilder.d.ts +45 -0
  291. package/dist/infrastructure/treesitter/ChunkContextBuilder.js +159 -0
  292. package/dist/infrastructure/treesitter/ChunkContextBuilder.js.map +1 -0
  293. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.d.ts +8 -0
  294. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.js +12 -0
  295. package/dist/infrastructure/treesitter/EmbeddedTreeSitterAssets.js.map +1 -0
  296. package/dist/infrastructure/treesitter/LanguageCatalog.d.ts +30 -0
  297. package/dist/{lib/chunker/languages.js → infrastructure/treesitter/LanguageCatalog.js} +38 -29
  298. package/dist/infrastructure/treesitter/LanguageCatalog.js.map +1 -0
  299. package/dist/infrastructure/treesitter/SlidingWindowChunker.d.ts +15 -0
  300. package/dist/infrastructure/treesitter/SlidingWindowChunker.js +42 -0
  301. package/dist/infrastructure/treesitter/SlidingWindowChunker.js.map +1 -0
  302. package/dist/infrastructure/treesitter/TreeSitterChunker.d.ts +42 -0
  303. package/dist/infrastructure/treesitter/TreeSitterChunker.js +165 -0
  304. package/dist/infrastructure/treesitter/TreeSitterChunker.js.map +1 -0
  305. package/dist/mcp.d.ts +1 -1
  306. package/dist/mcp.js +14 -72
  307. package/dist/mcp.js.map +1 -1
  308. package/dist/presentation/cli/Cli.d.ts +31 -0
  309. package/dist/presentation/cli/Cli.js +120 -0
  310. package/dist/presentation/cli/Cli.js.map +1 -0
  311. package/dist/presentation/cli/CliOptions.d.ts +18 -0
  312. package/dist/presentation/cli/CliOptions.js +25 -0
  313. package/dist/presentation/cli/CliOptions.js.map +1 -0
  314. package/dist/presentation/cli/CommandContext.d.ts +50 -0
  315. package/dist/presentation/cli/CommandContext.js +88 -0
  316. package/dist/presentation/cli/CommandContext.js.map +1 -0
  317. package/dist/presentation/cli/ConfigTemplate.d.ts +31 -0
  318. package/dist/presentation/cli/ConfigTemplate.js +83 -0
  319. package/dist/presentation/cli/ConfigTemplate.js.map +1 -0
  320. package/dist/presentation/cli/Renderer.d.ts +90 -0
  321. package/dist/presentation/cli/Renderer.js +290 -0
  322. package/dist/presentation/cli/Renderer.js.map +1 -0
  323. package/dist/presentation/cli/commands/AskCommand.d.ts +14 -0
  324. package/dist/presentation/cli/commands/AskCommand.js +48 -0
  325. package/dist/presentation/cli/commands/AskCommand.js.map +1 -0
  326. package/dist/presentation/cli/commands/CompletionsCommand.d.ts +18 -0
  327. package/dist/presentation/cli/commands/CompletionsCommand.js +96 -0
  328. package/dist/presentation/cli/commands/CompletionsCommand.js.map +1 -0
  329. package/dist/presentation/cli/commands/ConfigCommands.d.ts +56 -0
  330. package/dist/presentation/cli/commands/ConfigCommands.js +220 -0
  331. package/dist/presentation/cli/commands/ConfigCommands.js.map +1 -0
  332. package/dist/presentation/cli/commands/IndexCommand.d.ts +18 -0
  333. package/dist/presentation/cli/commands/IndexCommand.js +54 -0
  334. package/dist/presentation/cli/commands/IndexCommand.js.map +1 -0
  335. package/dist/presentation/cli/commands/ProjectsCommand.d.ts +48 -0
  336. package/dist/presentation/cli/commands/ProjectsCommand.js +240 -0
  337. package/dist/presentation/cli/commands/ProjectsCommand.js.map +1 -0
  338. package/dist/presentation/cli/commands/SearchCommand.d.ts +19 -0
  339. package/dist/presentation/cli/commands/SearchCommand.js +55 -0
  340. package/dist/presentation/cli/commands/SearchCommand.js.map +1 -0
  341. package/dist/presentation/cli/commands/ServerCommands.d.ts +13 -0
  342. package/dist/presentation/cli/commands/ServerCommands.js +40 -0
  343. package/dist/presentation/cli/commands/ServerCommands.js.map +1 -0
  344. package/dist/presentation/cli/commands/ShareCommands.d.ts +22 -0
  345. package/dist/presentation/cli/commands/ShareCommands.js +134 -0
  346. package/dist/presentation/cli/commands/ShareCommands.js.map +1 -0
  347. package/dist/presentation/cli/commands/StatusCommand.d.ts +15 -0
  348. package/dist/presentation/cli/commands/StatusCommand.js +53 -0
  349. package/dist/presentation/cli/commands/StatusCommand.js.map +1 -0
  350. package/dist/presentation/mcp/HitFormatter.d.ts +17 -0
  351. package/dist/presentation/mcp/HitFormatter.js +42 -0
  352. package/dist/presentation/mcp/HitFormatter.js.map +1 -0
  353. package/dist/presentation/mcp/IndexWatchController.d.ts +17 -0
  354. package/dist/presentation/mcp/IndexWatchController.js +31 -0
  355. package/dist/presentation/mcp/IndexWatchController.js.map +1 -0
  356. package/dist/presentation/mcp/LmgrepCore.d.ts +66 -0
  357. package/dist/presentation/mcp/LmgrepCore.js +178 -0
  358. package/dist/presentation/mcp/LmgrepCore.js.map +1 -0
  359. package/dist/presentation/mcp/McpServer.d.ts +18 -0
  360. package/dist/presentation/mcp/McpServer.js +63 -0
  361. package/dist/presentation/mcp/McpServer.js.map +1 -0
  362. package/dist/presentation/mcp/ToolDescriptions.d.ts +40 -0
  363. package/dist/presentation/mcp/ToolDescriptions.js +85 -0
  364. package/dist/presentation/mcp/ToolDescriptions.js.map +1 -0
  365. package/package.json +93 -89
  366. package/dist/lib/build.d.ts +0 -21
  367. package/dist/lib/build.js +0 -374
  368. package/dist/lib/build.js.map +0 -1
  369. package/dist/lib/chunker/context.d.ts +0 -21
  370. package/dist/lib/chunker/context.js +0 -131
  371. package/dist/lib/chunker/context.js.map +0 -1
  372. package/dist/lib/chunker/index.d.ts +0 -7
  373. package/dist/lib/chunker/index.js +0 -209
  374. package/dist/lib/chunker/index.js.map +0 -1
  375. package/dist/lib/chunker/languages.d.ts +0 -15
  376. package/dist/lib/chunker/languages.js.map +0 -1
  377. package/dist/lib/config.d.ts +0 -12
  378. package/dist/lib/config.js +0 -83
  379. package/dist/lib/config.js.map +0 -1
  380. package/dist/lib/embedder.d.ts +0 -65
  381. package/dist/lib/embedder.js +0 -236
  382. package/dist/lib/embedder.js.map +0 -1
  383. package/dist/lib/facet-session.d.ts +0 -44
  384. package/dist/lib/facet-session.js +0 -125
  385. package/dist/lib/facet-session.js.map +0 -1
  386. package/dist/lib/native-tuning.js.map +0 -1
  387. package/dist/lib/p2p.d.ts +0 -32
  388. package/dist/lib/p2p.js +0 -281
  389. package/dist/lib/p2p.js.map +0 -1
  390. package/dist/lib/providers.d.ts +0 -1
  391. package/dist/lib/providers.js +0 -41
  392. package/dist/lib/providers.js.map +0 -1
  393. package/dist/lib/repair.d.ts +0 -10
  394. package/dist/lib/repair.js +0 -57
  395. package/dist/lib/repair.js.map +0 -1
  396. package/dist/lib/scanner.d.ts +0 -34
  397. package/dist/lib/scanner.js +0 -242
  398. package/dist/lib/scanner.js.map +0 -1
  399. package/dist/lib/search-tool.d.ts +0 -55
  400. package/dist/lib/search-tool.js +0 -319
  401. package/dist/lib/search-tool.js.map +0 -1
  402. package/dist/lib/serve.d.ts +0 -11
  403. package/dist/lib/serve.js +0 -144
  404. package/dist/lib/serve.js.map +0 -1
  405. package/dist/lib/store.d.ts +0 -252
  406. package/dist/lib/store.js +0 -1216
  407. package/dist/lib/store.js.map +0 -1
  408. package/dist/lib/types.d.ts +0 -194
  409. package/dist/lib/types.js +0 -13
  410. package/dist/lib/types.js.map +0 -1
  411. package/dist/lib/vocab.d.ts +0 -20
  412. package/dist/lib/vocab.js +0 -275
  413. package/dist/lib/vocab.js.map +0 -1
  414. /package/dist/{lib/native-tuning.d.ts → infrastructure/lancedb/NativeTuning.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LanceTables.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/LanceTables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAmB,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAGxE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACxB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd;;;OAGG;IACH,WAAW,EAAE,OAAO;CACX,CAAC;AAIX;;;;;;;GAOG;AACH,MAAM,OAAO,WAAW;IAWb;IACQ;IAXlB;;;OAGG;IACH,MAAM,CAAU,iBAAiB,GAAG,EAAE,CAAC;IAE/B,EAAE,CAAyB;IAClB,IAAI,GAAG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E ??= "4";
6
6
  process.env.RAYON_NUM_THREADS ??= "4";
7
7
  process.env.MATMUL_NUM_THREADS ??= "4";
8
8
  export {};
9
- //# sourceMappingURL=native-tuning.js.map
9
+ //# sourceMappingURL=NativeTuning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeTuning.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/NativeTuning.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,wDAAwD;AACxD,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,GAAG,CAAC;AACzC,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,GAAG,CAAC;AACvC,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG,CAAC;AACtC,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,GAAG,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Branch } from "../../domain/project/Branch.js";
2
+ import { type LanceTables } from "./LanceTables.js";
3
+ /** A manifest row as it travels between peers. */
4
+ export interface ManifestRow {
5
+ filePath: string;
6
+ fileHash: string;
7
+ branch: string;
8
+ }
9
+ /**
10
+ * Row-level access to the tables, for replication between databases.
11
+ *
12
+ * Peer sharing copies rows verbatim — embeddings included, since avoiding
13
+ * re-embedding is the entire point — so it works below the domain model rather
14
+ * than through it. Keeping that access behind this one class means the rest of
15
+ * the system never sees raw rows.
16
+ */
17
+ export declare class RowReplication {
18
+ private readonly tables;
19
+ private readonly branch;
20
+ constructor(tables: LanceTables, branch: Branch);
21
+ chunkCount(): Promise<number>;
22
+ /** Stream chunk rows in pages, so a large index never loads at once. */
23
+ streamChunkRows(batchSize: number): AsyncGenerator<Record<string, unknown>[]>;
24
+ allManifestRows(): Promise<ManifestRow[]>;
25
+ addChunkRows(rows: Record<string, unknown>[]): Promise<void>;
26
+ addManifestRows(rows: ManifestRow[]): Promise<void>;
27
+ }
@@ -0,0 +1,82 @@
1
+ import { TableName } from "./LanceTables.js";
2
+ /**
3
+ * Row-level access to the tables, for replication between databases.
4
+ *
5
+ * Peer sharing copies rows verbatim — embeddings included, since avoiding
6
+ * re-embedding is the entire point — so it works below the domain model rather
7
+ * than through it. Keeping that access behind this one class means the rest of
8
+ * the system never sees raw rows.
9
+ */
10
+ export class RowReplication {
11
+ tables;
12
+ branch;
13
+ constructor(tables, branch) {
14
+ this.tables = tables;
15
+ this.branch = branch;
16
+ }
17
+ async chunkCount() {
18
+ const table = await this.tables.table(TableName.Chunks);
19
+ return table ? table.countRows() : 0;
20
+ }
21
+ /** Stream chunk rows in pages, so a large index never loads at once. */
22
+ async *streamChunkRows(batchSize) {
23
+ const table = await this.tables.table(TableName.Chunks);
24
+ if (!table)
25
+ return;
26
+ const total = await table.countRows();
27
+ for (let offset = 0; offset < total; offset += batchSize) {
28
+ const rows = await table
29
+ .query()
30
+ .limit(batchSize)
31
+ .offset(offset)
32
+ .toArray();
33
+ if (rows.length === 0)
34
+ break;
35
+ yield rows.map((r) => ({
36
+ id: r.id,
37
+ filePath: r.filePath,
38
+ startLine: r.startLine,
39
+ endLine: r.endLine,
40
+ type: r.type,
41
+ name: r.name,
42
+ content: r.content,
43
+ context: r.context,
44
+ hash: r.hash,
45
+ fileHash: r.fileHash ?? "",
46
+ // Arrow typed arrays do not survive JSON; send plain numbers.
47
+ vector: Array.from(r.vector),
48
+ }));
49
+ }
50
+ }
51
+ async allManifestRows() {
52
+ const table = await this.tables.table(TableName.Files);
53
+ if (!table)
54
+ return [];
55
+ const rows = await table.query().toArray();
56
+ return rows.map((r) => ({
57
+ filePath: r.filePath,
58
+ fileHash: r.fileHash,
59
+ branch: r.branch ?? this.branch.toString(),
60
+ }));
61
+ }
62
+ async addChunkRows(rows) {
63
+ if (rows.length === 0)
64
+ return;
65
+ const { table, seeded } = await this.tables.tableOrCreate(TableName.Chunks, rows);
66
+ if (!seeded)
67
+ await table.add(rows);
68
+ }
69
+ async addManifestRows(rows) {
70
+ if (rows.length === 0)
71
+ return;
72
+ const records = rows.map((r) => ({
73
+ filePath: r.filePath,
74
+ fileHash: r.fileHash,
75
+ branch: r.branch ?? this.branch.toString(),
76
+ }));
77
+ const { table, seeded } = await this.tables.tableOrCreate(TableName.Files, records);
78
+ if (!seeded)
79
+ await table.add(records);
80
+ }
81
+ }
82
+ //# sourceMappingURL=RowReplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RowReplication.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/RowReplication.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS/D;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IAER;IACA;IAFlB,YACkB,MAAmB,EACnB,MAAc;QADd,WAAM,GAAN,MAAM,CAAa;QACnB,WAAM,GAAN,MAAM,CAAQ;IAC7B,CAAC;IAEJ,KAAK,CAAC,UAAU;QACf,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,CAAC,eAAe,CACrB,SAAiB;QAEjB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC;QACtC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,CAAC;YAC1D,MAAM,IAAI,GAAG,MAAM,KAAK;iBACtB,KAAK,EAAE;iBACP,KAAK,CAAC,SAAS,CAAC;iBAChB,MAAM,CAAC,MAAM,CAAC;iBACd,OAAO,EAAE,CAAC;YAC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CAAC;YAAE,OAAO;QAC9B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CACxD,SAAS,CAAC,MAAM,EAChB,IAAI,CACJ,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAmB;QACxC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAChC,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;SAC1C,CAAC,CAAC,CAAC;QACJ,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CACxD,SAAS,CAAC,KAAK,EACf,OAAO,CACP,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;CACD"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Tuning for the LanceDB vector index. The numbers here were measured on a
3
+ * 43k-chunk / 3584-dimension index; the comments record what they bought so a
4
+ * later change can tell a tuned value from an arbitrary one.
5
+ */
6
+ export declare const VectorIndexPolicy: {
7
+ /**
8
+ * Below this row count a brute-force scan is cheap enough that training an
9
+ * index costs more than it saves, and IVF-PQ has too few vectors to cluster
10
+ * well.
11
+ */
12
+ readonly MIN_ROWS_FOR_ANN: 5000;
13
+ /**
14
+ * Re-absorb new rows into the index once the unindexed tail passes this
15
+ * share of the indexed body. Rows outside the index are searched by flat
16
+ * scan, so the tail is exactly what needs bounding.
17
+ */
18
+ readonly UNINDEXED_REINDEX_RATIO: 0.2;
19
+ /** ...but always tolerate a small tail, so a 3-chunk edit never retrains. */
20
+ readonly UNINDEXED_REINDEX_FLOOR: 2000;
21
+ /**
22
+ * Vector searches run without an explicit distance type, which LanceDB
23
+ * resolves to L2. The index has its own default, so it is pinned: an index
24
+ * built on a different metric would silently reorder every result.
25
+ */
26
+ readonly DISTANCE_TYPE: "l2";
27
+ /**
28
+ * IVF-PQ stores compressed vectors, so its raw distances approximate the
29
+ * real ones. `refineFactor` makes LanceDB pull the uncompressed vectors for
30
+ * the top `limit * factor` candidates and re-score them exactly.
31
+ *
32
+ * It is not optional. Measured mean recall@20 against an exact scan:
33
+ *
34
+ * off -> 53% 1 -> 75% 3 -> 86% 10 -> 91% 20 -> 94% 50 -> 94%
35
+ *
36
+ * and without it `_distance` is wrong by ~0.07, which matters because score
37
+ * is derived from it and users filter on `--min-score`. With refinement the
38
+ * scores match an exact scan to the digit.
39
+ *
40
+ * 20 sits at the knee: ~94% recall at ~11ms/query versus ~115ms for an
41
+ * exact scan. Beyond it recall flattens (the probed partitions run out of
42
+ * candidates) while latency keeps climbing. The refined set is bounded by
43
+ * the query limit, not by table size, so this costs a fixed few MB.
44
+ *
45
+ * Harmless on tables with no index: a flat scan already computes exact
46
+ * distances and returns identical rows.
47
+ */
48
+ readonly REFINE_FACTOR: 20;
49
+ };
50
+ /**
51
+ * Columns a search reads off a result row.
52
+ *
53
+ * Selecting explicitly keeps the embedding out of the result set — without it
54
+ * LanceDB ships every over-fetched row's full vector back into JS for nothing.
55
+ *
56
+ * `_distance` is listed on purpose: LanceDB currently auto-projects it into any
57
+ * scoring query but warns that it will stop, so naming it pins the behaviour
58
+ * rather than relying on a deprecated default.
59
+ */
60
+ export declare const SEARCH_COLUMNS: readonly ["id", "filePath", "startLine", "endLine", "type", "name", "content", "context", "fileHash", "_distance"];
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Tuning for the LanceDB vector index. The numbers here were measured on a
3
+ * 43k-chunk / 3584-dimension index; the comments record what they bought so a
4
+ * later change can tell a tuned value from an arbitrary one.
5
+ */
6
+ export const VectorIndexPolicy = {
7
+ /**
8
+ * Below this row count a brute-force scan is cheap enough that training an
9
+ * index costs more than it saves, and IVF-PQ has too few vectors to cluster
10
+ * well.
11
+ */
12
+ MIN_ROWS_FOR_ANN: 5_000,
13
+ /**
14
+ * Re-absorb new rows into the index once the unindexed tail passes this
15
+ * share of the indexed body. Rows outside the index are searched by flat
16
+ * scan, so the tail is exactly what needs bounding.
17
+ */
18
+ UNINDEXED_REINDEX_RATIO: 0.2,
19
+ /** ...but always tolerate a small tail, so a 3-chunk edit never retrains. */
20
+ UNINDEXED_REINDEX_FLOOR: 2_000,
21
+ /**
22
+ * Vector searches run without an explicit distance type, which LanceDB
23
+ * resolves to L2. The index has its own default, so it is pinned: an index
24
+ * built on a different metric would silently reorder every result.
25
+ */
26
+ DISTANCE_TYPE: "l2",
27
+ /**
28
+ * IVF-PQ stores compressed vectors, so its raw distances approximate the
29
+ * real ones. `refineFactor` makes LanceDB pull the uncompressed vectors for
30
+ * the top `limit * factor` candidates and re-score them exactly.
31
+ *
32
+ * It is not optional. Measured mean recall@20 against an exact scan:
33
+ *
34
+ * off -> 53% 1 -> 75% 3 -> 86% 10 -> 91% 20 -> 94% 50 -> 94%
35
+ *
36
+ * and without it `_distance` is wrong by ~0.07, which matters because score
37
+ * is derived from it and users filter on `--min-score`. With refinement the
38
+ * scores match an exact scan to the digit.
39
+ *
40
+ * 20 sits at the knee: ~94% recall at ~11ms/query versus ~115ms for an
41
+ * exact scan. Beyond it recall flattens (the probed partitions run out of
42
+ * candidates) while latency keeps climbing. The refined set is bounded by
43
+ * the query limit, not by table size, so this costs a fixed few MB.
44
+ *
45
+ * Harmless on tables with no index: a flat scan already computes exact
46
+ * distances and returns identical rows.
47
+ */
48
+ REFINE_FACTOR: 20,
49
+ };
50
+ /**
51
+ * Columns a search reads off a result row.
52
+ *
53
+ * Selecting explicitly keeps the embedding out of the result set — without it
54
+ * LanceDB ships every over-fetched row's full vector back into JS for nothing.
55
+ *
56
+ * `_distance` is listed on purpose: LanceDB currently auto-projects it into any
57
+ * scoring query but warns that it will stop, so naming it pins the behaviour
58
+ * rather than relying on a deprecated default.
59
+ */
60
+ export const SEARCH_COLUMNS = [
61
+ "id",
62
+ "filePath",
63
+ "startLine",
64
+ "endLine",
65
+ "type",
66
+ "name",
67
+ "content",
68
+ "context",
69
+ "fileHash",
70
+ "_distance",
71
+ ];
72
+ //# sourceMappingURL=VectorIndexPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorIndexPolicy.js","sourceRoot":"","sources":["../../../src/infrastructure/lancedb/VectorIndexPolicy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC;;;;OAIG;IACH,gBAAgB,EAAE,KAAK;IAEvB;;;;OAIG;IACH,uBAAuB,EAAE,GAAG;IAE5B,6EAA6E;IAC7E,uBAAuB,EAAE,KAAK;IAE9B;;;;OAIG;IACH,aAAa,EAAE,IAAI;IAEnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,EAAE,EAAE;CACR,CAAC;AAEX;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,IAAI;IACJ,UAAU;IACV,WAAW;IACX,SAAS;IACT,MAAM;IACN,MAAM;IACN,SAAS;IACT,SAAS;IACT,UAAU;IACV,WAAW;CACF,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { IndexMetadata } from "../../domain/project/IndexMetadata.js";
2
+ import type { RowReplication } from "../lancedb/RowReplication.js";
3
+ import { ShareCode } from "./ShareCode.js";
4
+ export interface ShareProgress {
5
+ onProgress?: (done: number, total: number) => void;
6
+ }
7
+ export interface ReceiveOptions extends ShareProgress {
8
+ onMeta?: (meta: {
9
+ model?: string;
10
+ dimensions?: number;
11
+ chunkCount: number;
12
+ remote?: string;
13
+ }) => void;
14
+ onWarning?: (message: string) => void;
15
+ }
16
+ export interface ReceiveResult {
17
+ chunks: number;
18
+ files: number;
19
+ }
20
+ /**
21
+ * Sends and receives a whole index between two machines.
22
+ *
23
+ * The transfer copies rows verbatim, embeddings included: re-embedding a large
24
+ * repository is the expensive thing, and avoiding it is the entire reason to
25
+ * share. That makes model compatibility the receiver's responsibility to check
26
+ * — vectors from a different model are silently meaningless, so a mismatch is
27
+ * warned about explicitly.
28
+ */
29
+ export declare class IndexShare {
30
+ private readonly rows;
31
+ private static readonly BATCH_SIZE;
32
+ private static readonly PEER_TIMEOUT_MS;
33
+ constructor(rows: RowReplication);
34
+ /**
35
+ * Publish the index and return the code a peer needs. `done` resolves once
36
+ * a peer has taken the whole transfer.
37
+ */
38
+ send(metadata: IndexMetadata | undefined, options?: ShareProgress): Promise<{
39
+ code: string;
40
+ done: Promise<void>;
41
+ }>;
42
+ /** Connect to a sharer and write everything it sends into this database. */
43
+ receive(code: ShareCode, localMetadata: IndexMetadata | undefined, options?: ReceiveOptions): Promise<ReceiveResult>;
44
+ private warnOnModelMismatch;
45
+ }
@@ -0,0 +1,160 @@
1
+ import { ModelIdentity } from "../../domain/project/ModelIdentity.js";
2
+ import { PeerSwarm } from "./PeerSwarm.js";
3
+ import { SecureChannel, } from "./SecureChannel.js";
4
+ import { ShareCode } from "./ShareCode.js";
5
+ /**
6
+ * Sends and receives a whole index between two machines.
7
+ *
8
+ * The transfer copies rows verbatim, embeddings included: re-embedding a large
9
+ * repository is the expensive thing, and avoiding it is the entire reason to
10
+ * share. That makes model compatibility the receiver's responsibility to check
11
+ * — vectors from a different model are silently meaningless, so a mismatch is
12
+ * warned about explicitly.
13
+ */
14
+ export class IndexShare {
15
+ rows;
16
+ static BATCH_SIZE = 200;
17
+ static PEER_TIMEOUT_MS = 5 * 60 * 1000;
18
+ constructor(rows) {
19
+ this.rows = rows;
20
+ }
21
+ /**
22
+ * Publish the index and return the code a peer needs. `done` resolves once
23
+ * a peer has taken the whole transfer.
24
+ */
25
+ async send(metadata, options = {}) {
26
+ const swarm = await PeerSwarm.create();
27
+ const code = ShareCode.generate();
28
+ const channel = new SecureChannel(code.toEncryptionKey());
29
+ const chunkCount = await this.rows.chunkCount();
30
+ const done = new Promise((resolve, reject) => {
31
+ const timeout = setTimeout(() => {
32
+ void swarm.destroy();
33
+ reject(new Error("Timed out waiting for peer (5 minutes)."));
34
+ }, IndexShare.PEER_TIMEOUT_MS);
35
+ swarm.onConnection(async (socket) => {
36
+ clearTimeout(timeout);
37
+ try {
38
+ channel.send(socket, {
39
+ type: "meta",
40
+ model: metadata?.model,
41
+ dimensions: metadata?.dimensions,
42
+ chunkCount,
43
+ branch: metadata?.branch ?? "main",
44
+ remote: metadata?.remote,
45
+ });
46
+ // Wait for the receiver to accept before streaming — it may
47
+ // refuse on an incompatible model.
48
+ await channel.await(socket, "ready");
49
+ let sent = 0;
50
+ for await (const batch of this.rows.streamChunkRows(IndexShare.BATCH_SIZE)) {
51
+ channel.send(socket, { type: "chunks", batch });
52
+ sent += batch.length;
53
+ options.onProgress?.(sent, chunkCount);
54
+ }
55
+ const files = await this.rows.allManifestRows();
56
+ if (files.length > 0) {
57
+ channel.send(socket, { type: "files", batch: files });
58
+ }
59
+ channel.send(socket, { type: "done" });
60
+ // Wait for the ack so the socket is not torn down before
61
+ // the receiver has committed.
62
+ await channel.await(socket, "ack");
63
+ socket.end();
64
+ await swarm.destroy();
65
+ resolve();
66
+ }
67
+ catch (err) {
68
+ await swarm.destroy();
69
+ reject(err);
70
+ }
71
+ });
72
+ swarm.join(code.toTopic(), "server").catch(reject);
73
+ });
74
+ return { code: code.toString(), done };
75
+ }
76
+ /** Connect to a sharer and write everything it sends into this database. */
77
+ async receive(code, localMetadata, options = {}) {
78
+ const swarm = await PeerSwarm.create();
79
+ const channel = new SecureChannel(code.toEncryptionKey());
80
+ return new Promise((resolve, reject) => {
81
+ const timeout = setTimeout(() => {
82
+ void swarm.destroy();
83
+ reject(new Error("Timed out waiting for peer (5 minutes)."));
84
+ }, IndexShare.PEER_TIMEOUT_MS);
85
+ const fail = (err) => {
86
+ void swarm.destroy().then(() => reject(err));
87
+ };
88
+ swarm.onConnection((socket) => {
89
+ clearTimeout(timeout);
90
+ let expected = 0;
91
+ let chunks = 0;
92
+ let files = 0;
93
+ let accepted = false;
94
+ const handle = (message) => {
95
+ switch (message.type) {
96
+ case "meta": {
97
+ expected = message.chunkCount;
98
+ options.onMeta?.({
99
+ model: message.model,
100
+ dimensions: message.dimensions,
101
+ chunkCount: message.chunkCount,
102
+ remote: message.remote,
103
+ });
104
+ this.warnOnModelMismatch(localMetadata, message, options.onWarning);
105
+ channel.send(socket, { type: "ready" });
106
+ accepted = true;
107
+ break;
108
+ }
109
+ case "chunks": {
110
+ // Ignore anything arriving before the handshake.
111
+ if (!accepted)
112
+ break;
113
+ chunks += message.batch.length;
114
+ options.onProgress?.(chunks, expected);
115
+ this.rows.addChunkRows(message.batch).catch(fail);
116
+ break;
117
+ }
118
+ case "files": {
119
+ if (!accepted)
120
+ break;
121
+ files += message.batch.length;
122
+ this.rows.addManifestRows(message.batch).catch(fail);
123
+ break;
124
+ }
125
+ case "done": {
126
+ channel.send(socket, { type: "ack" });
127
+ void swarm.destroy().then(() => resolve({ chunks, files }));
128
+ break;
129
+ }
130
+ }
131
+ };
132
+ const read = channel.reader((message) => {
133
+ try {
134
+ handle(message);
135
+ }
136
+ catch (err) {
137
+ fail(new Error(`Protocol error: ${err}`));
138
+ }
139
+ });
140
+ socket.on("data", read);
141
+ socket.on("error", fail);
142
+ });
143
+ swarm.join(code.toTopic(), "client").catch(reject);
144
+ });
145
+ }
146
+ warnOnModelMismatch(local, remote, onWarning) {
147
+ if (!local?.model || !remote.model)
148
+ return;
149
+ const localFamily = ModelIdentity.of(local.model).family;
150
+ const remoteFamily = ModelIdentity.of(remote.model).family;
151
+ if (localFamily === remoteFamily &&
152
+ local.dimensions === remote.dimensions) {
153
+ return;
154
+ }
155
+ onWarning?.(`Warning: source uses "${remote.model}" (${remote.dimensions} dims) ` +
156
+ `but local index uses "${local.model}" (${local.dimensions} dims). ` +
157
+ "Imported vectors may not be compatible.");
158
+ }
159
+ }
160
+ //# sourceMappingURL=IndexShare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexShare.js","sourceRoot":"","sources":["../../../src/infrastructure/p2p/IndexShare.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEN,aAAa,GAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAqB3C;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAU;IAIO;IAHrB,MAAM,CAAU,UAAU,GAAG,GAAG,CAAC;IACjC,MAAM,CAAU,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAExD,YAA6B,IAAoB;QAApB,SAAI,GAAJ,IAAI,CAAgB;IAAG,CAAC;IAErD;;;OAGG;IACH,KAAK,CAAC,IAAI,CACT,QAAmC,EACnC,UAAyB,EAAE;QAE3B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QAEhD,MAAM,IAAI,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC/B,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;gBACrB,MAAM,CAAC,IAAI,KAAK,CAAC,yCAAyC,CAAC,C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,IAAI,CAAC,KAAK,EAAE,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK;YAAE,OAAO;QAC3C,MAAM,WAAW,GAAG,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;QACzD,MAAM,YAAY,GAAG,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;QAC3D,IACC,WAAW,KAAK,YAAY;YAC5B,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EACrC,CAAC;YACF,OAAO;QACR,CAAC;QACD,SAAS,EAAE,CACV,yBAAyB,MAAM,CAAC,KAAK,MAAM,MAAM,CAAC,UAAU,SAAS;YACpE,yBAAyB,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,UAAU,UAAU;YACpE,yCAAyC,CAC1C,CAAC;IACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { DuplexSocket } from "./SecureChannel.js";
2
+ /**
3
+ * Peer discovery over Hyperswarm.
4
+ *
5
+ * Imported lazily and treated as optional: sharing is a side feature, and its
6
+ * native dependency should not be required to run a search.
7
+ */
8
+ export declare class PeerSwarm {
9
+ private readonly swarm;
10
+ private constructor();
11
+ static create(): Promise<PeerSwarm>;
12
+ onConnection(handler: (socket: DuplexSocket) => void): void;
13
+ /** Announce as a server (sharer) or dial as a client (receiver). */
14
+ join(topic: Buffer, role: "server" | "client"): Promise<void>;
15
+ destroy(): Promise<void>;
16
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Peer discovery over Hyperswarm.
3
+ *
4
+ * Imported lazily and treated as optional: sharing is a side feature, and its
5
+ * native dependency should not be required to run a search.
6
+ */
7
+ export class PeerSwarm {
8
+ swarm;
9
+ constructor(swarm) {
10
+ this.swarm = swarm;
11
+ }
12
+ static async create() {
13
+ let module;
14
+ try {
15
+ // @ts-expect-error -- no type declarations for hyperswarm
16
+ module = await import("hyperswarm");
17
+ }
18
+ catch {
19
+ throw new Error("hyperswarm is not installed. Run: pnpm add hyperswarm");
20
+ }
21
+ const Constructor = (module.default ??
22
+ module);
23
+ return new PeerSwarm(new Constructor());
24
+ }
25
+ onConnection(handler) {
26
+ this.swarm.on("connection", handler);
27
+ }
28
+ /** Announce as a server (sharer) or dial as a client (receiver). */
29
+ async join(topic, role) {
30
+ await this.swarm
31
+ .join(topic, {
32
+ server: role === "server",
33
+ client: role === "client",
34
+ })
35
+ .flushed();
36
+ }
37
+ async destroy() {
38
+ await this.swarm.destroy().catch(() => { });
39
+ }
40
+ }
41
+ //# sourceMappingURL=PeerSwarm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PeerSwarm.js","sourceRoot":"","sources":["../../../src/infrastructure/p2p/PeerSwarm.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACgB;IAArC,YAAqC,KAAyB;QAAzB,UAAK,GAAL,KAAK,CAAoB;IAAG,CAAC;IAElE,MAAM,CAAC,KAAK,CAAC,MAAM;QAClB,IAAI,MAAkD,CAAC;QACvD,IAAI,CAAC;YACJ,0DAA0D;YAC1D,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,OAAO;YAClC,MAAM,CAAiC,CAAC;QACzC,OAAO,IAAI,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,YAAY,CAAC,OAAuC;QACnD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,IAAyB;QAClD,MAAM,IAAI,CAAC,KAAK;aACd,IAAI,CAAC,KAAK,EAAE;YACZ,MAAM,EAAE,IAAI,KAAK,QAAQ;YACzB,MAAM,EAAE,IAAI,KAAK,QAAQ;SACzB,CAAC;aACD,OAAO,EAAE,CAAC;IACb,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;CACD"}
@@ -0,0 +1,60 @@
1
+ /** Messages exchanged during a share. */
2
+ export type ShareMessage = {
3
+ type: "meta";
4
+ model?: string;
5
+ dimensions?: number;
6
+ chunkCount: number;
7
+ branch: string;
8
+ remote?: string;
9
+ } | {
10
+ type: "ready";
11
+ } | {
12
+ type: "chunks";
13
+ batch: Record<string, unknown>[];
14
+ } | {
15
+ type: "files";
16
+ batch: Array<{
17
+ filePath: string;
18
+ fileHash: string;
19
+ branch: string;
20
+ }>;
21
+ } | {
22
+ type: "done";
23
+ } | {
24
+ type: "ack";
25
+ };
26
+ /** The transport a share runs over. */
27
+ export interface DuplexSocket {
28
+ write(data: Buffer): boolean;
29
+ on(event: "data", cb: (chunk: Buffer) => void): void;
30
+ on(event: "end" | "close" | "error", cb: (err?: Error) => void): void;
31
+ end(): void;
32
+ destroy(): void;
33
+ }
34
+ /**
35
+ * Authenticated encryption and message framing over a raw peer socket.
36
+ *
37
+ * AES-256-GCM, so a tampered payload fails to decrypt rather than being parsed
38
+ * — a peer discovered over a public DHT is not trusted. Frames carry an
39
+ * explicit length prefix because a stream socket splits and merges writes
40
+ * arbitrarily, and JSON alone gives no way to find a message boundary.
41
+ */
42
+ export declare class SecureChannel {
43
+ private readonly key;
44
+ private static readonly IV_BYTES;
45
+ private static readonly TAG_BYTES;
46
+ private static readonly LENGTH_PREFIX_BYTES;
47
+ constructor(key: Buffer);
48
+ send(socket: {
49
+ write(data: Buffer): boolean;
50
+ }, message: ShareMessage): void;
51
+ /**
52
+ * A stateful reader: feed it raw socket chunks, and it emits whole
53
+ * messages as their frames complete.
54
+ */
55
+ reader(onMessage: (message: ShareMessage) => void): (chunk: Buffer) => void;
56
+ /** Resolve once a message of the expected type arrives. */
57
+ await(socket: DuplexSocket, expected: ShareMessage["type"]): Promise<ShareMessage>;
58
+ private encrypt;
59
+ private decrypt;
60
+ }