@angri450/zvec-grep 0.2.2

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 (418) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +319 -0
  3. package/README_CN.md +297 -0
  4. package/dist/authorization/index.d.ts +7 -0
  5. package/dist/authorization/index.js +7 -0
  6. package/dist/authorization/index.js.map +1 -0
  7. package/dist/authorization/manager.d.ts +8 -0
  8. package/dist/authorization/manager.js +19 -0
  9. package/dist/authorization/manager.js.map +1 -0
  10. package/dist/authorization/operation.d.ts +7 -0
  11. package/dist/authorization/operation.js +50 -0
  12. package/dist/authorization/operation.js.map +1 -0
  13. package/dist/authorization/planner.d.ts +21 -0
  14. package/dist/authorization/planner.js +97 -0
  15. package/dist/authorization/planner.js.map +1 -0
  16. package/dist/authorization/prompt.d.ts +12 -0
  17. package/dist/authorization/prompt.js +63 -0
  18. package/dist/authorization/prompt.js.map +1 -0
  19. package/dist/authorization/store.d.ts +20 -0
  20. package/dist/authorization/store.js +251 -0
  21. package/dist/authorization/store.js.map +1 -0
  22. package/dist/authorization/target.d.ts +15 -0
  23. package/dist/authorization/target.js +49 -0
  24. package/dist/authorization/target.js.map +1 -0
  25. package/dist/authorization/types.d.ts +61 -0
  26. package/dist/authorization/types.js +2 -0
  27. package/dist/authorization/types.js.map +1 -0
  28. package/dist/cli/args.d.ts +6 -0
  29. package/dist/cli/args.js +1255 -0
  30. package/dist/cli/args.js.map +1 -0
  31. package/dist/cli/auth.d.ts +21 -0
  32. package/dist/cli/auth.js +209 -0
  33. package/dist/cli/auth.js.map +1 -0
  34. package/dist/cli/commands.d.ts +4 -0
  35. package/dist/cli/commands.js +801 -0
  36. package/dist/cli/commands.js.map +1 -0
  37. package/dist/cli/errors.d.ts +9 -0
  38. package/dist/cli/errors.js +131 -0
  39. package/dist/cli/errors.js.map +1 -0
  40. package/dist/cli/format/context.d.ts +9 -0
  41. package/dist/cli/format/context.js +786 -0
  42. package/dist/cli/format/context.js.map +1 -0
  43. package/dist/cli/format/debug.d.ts +4 -0
  44. package/dist/cli/format/debug.js +60 -0
  45. package/dist/cli/format/debug.js.map +1 -0
  46. package/dist/cli/format/highlight.d.ts +3 -0
  47. package/dist/cli/format/highlight.js +106 -0
  48. package/dist/cli/format/highlight.js.map +1 -0
  49. package/dist/cli/format/progress.d.ts +13 -0
  50. package/dist/cli/format/progress.js +290 -0
  51. package/dist/cli/format/progress.js.map +1 -0
  52. package/dist/cli/format/range.d.ts +3 -0
  53. package/dist/cli/format/range.js +24 -0
  54. package/dist/cli/format/range.js.map +1 -0
  55. package/dist/cli/format/status.d.ts +83 -0
  56. package/dist/cli/format/status.js +530 -0
  57. package/dist/cli/format/status.js.map +1 -0
  58. package/dist/cli/help.d.ts +1 -0
  59. package/dist/cli/help.js +546 -0
  60. package/dist/cli/help.js.map +1 -0
  61. package/dist/cli/index.d.ts +2 -0
  62. package/dist/cli/index.js +40 -0
  63. package/dist/cli/index.js.map +1 -0
  64. package/dist/cli/install.d.ts +4 -0
  65. package/dist/cli/install.js +1735 -0
  66. package/dist/cli/install.js.map +1 -0
  67. package/dist/cli/managed-rg.d.ts +10 -0
  68. package/dist/cli/managed-rg.js +337 -0
  69. package/dist/cli/managed-rg.js.map +1 -0
  70. package/dist/cli/server-search.d.ts +3 -0
  71. package/dist/cli/server-search.js +12 -0
  72. package/dist/cli/server-search.js.map +1 -0
  73. package/dist/cli/types.d.ts +87 -0
  74. package/dist/cli/types.js +10 -0
  75. package/dist/cli/types.js.map +1 -0
  76. package/dist/cli/version.d.ts +1 -0
  77. package/dist/cli/version.js +13 -0
  78. package/dist/cli/version.js.map +1 -0
  79. package/dist/client/daemon-client.d.ts +31 -0
  80. package/dist/client/daemon-client.js +203 -0
  81. package/dist/client/daemon-client.js.map +1 -0
  82. package/dist/client/mode-router.d.ts +9 -0
  83. package/dist/client/mode-router.js +28 -0
  84. package/dist/client/mode-router.js.map +1 -0
  85. package/dist/client/search-policy.d.ts +11 -0
  86. package/dist/client/search-policy.js +15 -0
  87. package/dist/client/search-policy.js.map +1 -0
  88. package/dist/daemon/backend.d.ts +78 -0
  89. package/dist/daemon/backend.js +1118 -0
  90. package/dist/daemon/backend.js.map +1 -0
  91. package/dist/daemon/change-set.d.ts +30 -0
  92. package/dist/daemon/change-set.js +163 -0
  93. package/dist/daemon/change-set.js.map +1 -0
  94. package/dist/daemon/config.d.ts +27 -0
  95. package/dist/daemon/config.js +107 -0
  96. package/dist/daemon/config.js.map +1 -0
  97. package/dist/daemon/errors.d.ts +5 -0
  98. package/dist/daemon/errors.js +11 -0
  99. package/dist/daemon/errors.js.map +1 -0
  100. package/dist/daemon/http-server.d.ts +30 -0
  101. package/dist/daemon/http-server.js +307 -0
  102. package/dist/daemon/http-server.js.map +1 -0
  103. package/dist/daemon/index-coordinator.d.ts +22 -0
  104. package/dist/daemon/index-coordinator.js +55 -0
  105. package/dist/daemon/index-coordinator.js.map +1 -0
  106. package/dist/daemon/job-scheduler.d.ts +85 -0
  107. package/dist/daemon/job-scheduler.js +492 -0
  108. package/dist/daemon/job-scheduler.js.map +1 -0
  109. package/dist/daemon/logger.d.ts +10 -0
  110. package/dist/daemon/logger.js +101 -0
  111. package/dist/daemon/logger.js.map +1 -0
  112. package/dist/daemon/model-pool.d.ts +48 -0
  113. package/dist/daemon/model-pool.js +190 -0
  114. package/dist/daemon/model-pool.js.map +1 -0
  115. package/dist/daemon/root-lease.d.ts +14 -0
  116. package/dist/daemon/root-lease.js +197 -0
  117. package/dist/daemon/root-lease.js.map +1 -0
  118. package/dist/daemon/root-runtime.d.ts +80 -0
  119. package/dist/daemon/root-runtime.js +340 -0
  120. package/dist/daemon/root-runtime.js.map +1 -0
  121. package/dist/daemon/runtime-manager.d.ts +47 -0
  122. package/dist/daemon/runtime-manager.js +252 -0
  123. package/dist/daemon/runtime-manager.js.map +1 -0
  124. package/dist/daemon/runtime.d.ts +12 -0
  125. package/dist/daemon/runtime.js +105 -0
  126. package/dist/daemon/runtime.js.map +1 -0
  127. package/dist/daemon/server-controller.d.ts +38 -0
  128. package/dist/daemon/server-controller.js +327 -0
  129. package/dist/daemon/server-controller.js.map +1 -0
  130. package/dist/daemon/watch-manager.d.ts +62 -0
  131. package/dist/daemon/watch-manager.js +415 -0
  132. package/dist/daemon/watch-manager.js.map +1 -0
  133. package/dist/daemon/workspace-read-session-cache.d.ts +31 -0
  134. package/dist/daemon/workspace-read-session-cache.js +115 -0
  135. package/dist/daemon/workspace-read-session-cache.js.map +1 -0
  136. package/dist/engine/code-formats.d.ts +3 -0
  137. package/dist/engine/code-formats.js +14 -0
  138. package/dist/engine/code-formats.js.map +1 -0
  139. package/dist/engine/config.d.ts +57 -0
  140. package/dist/engine/config.js +351 -0
  141. package/dist/engine/config.js.map +1 -0
  142. package/dist/engine/errors.d.ts +20 -0
  143. package/dist/engine/errors.js +51 -0
  144. package/dist/engine/errors.js.map +1 -0
  145. package/dist/engine/extraction/code/adapter.d.ts +19 -0
  146. package/dist/engine/extraction/code/adapter.js +24 -0
  147. package/dist/engine/extraction/code/adapter.js.map +1 -0
  148. package/dist/engine/extraction/code/extractor.d.ts +13 -0
  149. package/dist/engine/extraction/code/extractor.js +696 -0
  150. package/dist/engine/extraction/code/extractor.js.map +1 -0
  151. package/dist/engine/extraction/code/families/c-family.d.ts +2 -0
  152. package/dist/engine/extraction/code/families/c-family.js +122 -0
  153. package/dist/engine/extraction/code/families/c-family.js.map +1 -0
  154. package/dist/engine/extraction/code/families/js-ts.d.ts +12 -0
  155. package/dist/engine/extraction/code/families/js-ts.js +118 -0
  156. package/dist/engine/extraction/code/families/js-ts.js.map +1 -0
  157. package/dist/engine/extraction/code/families/metadata.d.ts +8 -0
  158. package/dist/engine/extraction/code/families/metadata.js +86 -0
  159. package/dist/engine/extraction/code/families/metadata.js.map +1 -0
  160. package/dist/engine/extraction/code/families/name-field.d.ts +3 -0
  161. package/dist/engine/extraction/code/families/name-field.js +22 -0
  162. package/dist/engine/extraction/code/families/name-field.js.map +1 -0
  163. package/dist/engine/extraction/code/languages/c.d.ts +1 -0
  164. package/dist/engine/extraction/code/languages/c.js +12 -0
  165. package/dist/engine/extraction/code/languages/c.js.map +1 -0
  166. package/dist/engine/extraction/code/languages/cpp.d.ts +1 -0
  167. package/dist/engine/extraction/code/languages/cpp.js +18 -0
  168. package/dist/engine/extraction/code/languages/cpp.js.map +1 -0
  169. package/dist/engine/extraction/code/languages/go.d.ts +2 -0
  170. package/dist/engine/extraction/code/languages/go.js +70 -0
  171. package/dist/engine/extraction/code/languages/go.js.map +1 -0
  172. package/dist/engine/extraction/code/languages/java.d.ts +1 -0
  173. package/dist/engine/extraction/code/languages/java.js +17 -0
  174. package/dist/engine/extraction/code/languages/java.js.map +1 -0
  175. package/dist/engine/extraction/code/languages/javascript.d.ts +2 -0
  176. package/dist/engine/extraction/code/languages/javascript.js +23 -0
  177. package/dist/engine/extraction/code/languages/javascript.js.map +1 -0
  178. package/dist/engine/extraction/code/languages/python.d.ts +2 -0
  179. package/dist/engine/extraction/code/languages/python.js +52 -0
  180. package/dist/engine/extraction/code/languages/python.js.map +1 -0
  181. package/dist/engine/extraction/code/languages/rust.d.ts +2 -0
  182. package/dist/engine/extraction/code/languages/rust.js +25 -0
  183. package/dist/engine/extraction/code/languages/rust.js.map +1 -0
  184. package/dist/engine/extraction/code/languages/typescript.d.ts +2 -0
  185. package/dist/engine/extraction/code/languages/typescript.js +37 -0
  186. package/dist/engine/extraction/code/languages/typescript.js.map +1 -0
  187. package/dist/engine/extraction/code/tree-sitter/grammar.d.ts +4 -0
  188. package/dist/engine/extraction/code/tree-sitter/grammar.js +49 -0
  189. package/dist/engine/extraction/code/tree-sitter/grammar.js.map +1 -0
  190. package/dist/engine/extraction/code/tree-sitter/nodes.d.ts +3 -0
  191. package/dist/engine/extraction/code/tree-sitter/nodes.js +27 -0
  192. package/dist/engine/extraction/code/tree-sitter/nodes.js.map +1 -0
  193. package/dist/engine/extraction/code/tree-sitter/parser.d.ts +2 -0
  194. package/dist/engine/extraction/code/tree-sitter/parser.js +31 -0
  195. package/dist/engine/extraction/code/tree-sitter/parser.js.map +1 -0
  196. package/dist/engine/extraction/ids.d.ts +1 -0
  197. package/dist/engine/extraction/ids.js +5 -0
  198. package/dist/engine/extraction/ids.js.map +1 -0
  199. package/dist/engine/extraction/image/extractor.d.ts +5 -0
  200. package/dist/engine/extraction/image/extractor.js +35 -0
  201. package/dist/engine/extraction/image/extractor.js.map +1 -0
  202. package/dist/engine/extraction/index.d.ts +4 -0
  203. package/dist/engine/extraction/index.js +3 -0
  204. package/dist/engine/extraction/index.js.map +1 -0
  205. package/dist/engine/extraction/markdown/extractor.d.ts +7 -0
  206. package/dist/engine/extraction/markdown/extractor.js +362 -0
  207. package/dist/engine/extraction/markdown/extractor.js.map +1 -0
  208. package/dist/engine/extraction/runtime.d.ts +9 -0
  209. package/dist/engine/extraction/runtime.js +37 -0
  210. package/dist/engine/extraction/runtime.js.map +1 -0
  211. package/dist/engine/extraction/source.d.ts +18 -0
  212. package/dist/engine/extraction/source.js +22 -0
  213. package/dist/engine/extraction/source.js.map +1 -0
  214. package/dist/engine/extraction/text/extractor.d.ts +7 -0
  215. package/dist/engine/extraction/text/extractor.js +168 -0
  216. package/dist/engine/extraction/text/extractor.js.map +1 -0
  217. package/dist/engine/extraction/types.d.ts +4 -0
  218. package/dist/engine/extraction/types.js +2 -0
  219. package/dist/engine/extraction/types.js.map +1 -0
  220. package/dist/engine/extraction/vector-content.d.ts +5 -0
  221. package/dist/engine/extraction/vector-content.js +83 -0
  222. package/dist/engine/extraction/vector-content.js.map +1 -0
  223. package/dist/engine/file-size-policy.d.ts +6 -0
  224. package/dist/engine/file-size-policy.js +20 -0
  225. package/dist/engine/file-size-policy.js.map +1 -0
  226. package/dist/engine/file-type.d.ts +15 -0
  227. package/dist/engine/file-type.js +152 -0
  228. package/dist/engine/file-type.js.map +1 -0
  229. package/dist/engine/index-status.d.ts +9 -0
  230. package/dist/engine/index-status.js +38 -0
  231. package/dist/engine/index-status.js.map +1 -0
  232. package/dist/engine/manifest.d.ts +13 -0
  233. package/dist/engine/manifest.js +124 -0
  234. package/dist/engine/manifest.js.map +1 -0
  235. package/dist/engine/models/artifact-cache-lock.d.ts +16 -0
  236. package/dist/engine/models/artifact-cache-lock.js +228 -0
  237. package/dist/engine/models/artifact-cache-lock.js.map +1 -0
  238. package/dist/engine/models/artifact-downloader.d.ts +77 -0
  239. package/dist/engine/models/artifact-downloader.js +766 -0
  240. package/dist/engine/models/artifact-downloader.js.map +1 -0
  241. package/dist/engine/models/backends/llama-cpp.d.ts +100 -0
  242. package/dist/engine/models/backends/llama-cpp.js +567 -0
  243. package/dist/engine/models/backends/llama-cpp.js.map +1 -0
  244. package/dist/engine/models/backends/model2vec-runtime.d.ts +63 -0
  245. package/dist/engine/models/backends/model2vec-runtime.js +112 -0
  246. package/dist/engine/models/backends/model2vec-runtime.js.map +1 -0
  247. package/dist/engine/models/backends/model2vec-tokenizer.d.ts +2 -0
  248. package/dist/engine/models/backends/model2vec-tokenizer.js +42 -0
  249. package/dist/engine/models/backends/model2vec-tokenizer.js.map +1 -0
  250. package/dist/engine/models/backends/model2vec-worker-pool.d.ts +25 -0
  251. package/dist/engine/models/backends/model2vec-worker-pool.js +264 -0
  252. package/dist/engine/models/backends/model2vec-worker-pool.js.map +1 -0
  253. package/dist/engine/models/backends/model2vec-worker.d.ts +1 -0
  254. package/dist/engine/models/backends/model2vec-worker.js +41 -0
  255. package/dist/engine/models/backends/model2vec-worker.js.map +1 -0
  256. package/dist/engine/models/backends/model2vec.d.ts +38 -0
  257. package/dist/engine/models/backends/model2vec.js +344 -0
  258. package/dist/engine/models/backends/model2vec.js.map +1 -0
  259. package/dist/engine/models/backends/qwen.d.ts +44 -0
  260. package/dist/engine/models/backends/qwen.js +411 -0
  261. package/dist/engine/models/backends/qwen.js.map +1 -0
  262. package/dist/engine/models/backends/transformers-js.d.ts +90 -0
  263. package/dist/engine/models/backends/transformers-js.js +411 -0
  264. package/dist/engine/models/backends/transformers-js.js.map +1 -0
  265. package/dist/engine/models/catalog.d.ts +490 -0
  266. package/dist/engine/models/catalog.js +522 -0
  267. package/dist/engine/models/catalog.js.map +1 -0
  268. package/dist/engine/models/download-progress.d.ts +16 -0
  269. package/dist/engine/models/download-progress.js +47 -0
  270. package/dist/engine/models/download-progress.js.map +1 -0
  271. package/dist/engine/models/embeddings.d.ts +73 -0
  272. package/dist/engine/models/embeddings.js +125 -0
  273. package/dist/engine/models/embeddings.js.map +1 -0
  274. package/dist/engine/models/factory.d.ts +2 -0
  275. package/dist/engine/models/factory.js +51 -0
  276. package/dist/engine/models/factory.js.map +1 -0
  277. package/dist/engine/models/index.d.ts +5 -0
  278. package/dist/engine/models/index.js +6 -0
  279. package/dist/engine/models/index.js.map +1 -0
  280. package/dist/engine/models/local-embedding-parallelism.d.ts +15 -0
  281. package/dist/engine/models/local-embedding-parallelism.js +63 -0
  282. package/dist/engine/models/local-embedding-parallelism.js.map +1 -0
  283. package/dist/engine/models/local-embedding-queue.d.ts +12 -0
  284. package/dist/engine/models/local-embedding-queue.js +65 -0
  285. package/dist/engine/models/local-embedding-queue.js.map +1 -0
  286. package/dist/engine/models/ranking.d.ts +19 -0
  287. package/dist/engine/models/ranking.js +2 -0
  288. package/dist/engine/models/ranking.js.map +1 -0
  289. package/dist/engine/models/resolution.d.ts +8 -0
  290. package/dist/engine/models/resolution.js +22 -0
  291. package/dist/engine/models/resolution.js.map +1 -0
  292. package/dist/engine/pipeline/indexing/index.d.ts +14 -0
  293. package/dist/engine/pipeline/indexing/index.js +1219 -0
  294. package/dist/engine/pipeline/indexing/index.js.map +1 -0
  295. package/dist/engine/pipeline/indexing/input-budget.d.ts +2 -0
  296. package/dist/engine/pipeline/indexing/input-budget.js +51 -0
  297. package/dist/engine/pipeline/indexing/input-budget.js.map +1 -0
  298. package/dist/engine/pipeline/indexing/root-paths.d.ts +7 -0
  299. package/dist/engine/pipeline/indexing/root-paths.js +148 -0
  300. package/dist/engine/pipeline/indexing/root-paths.js.map +1 -0
  301. package/dist/engine/pipeline/indexing/scanner/index.d.ts +14 -0
  302. package/dist/engine/pipeline/indexing/scanner/index.js +776 -0
  303. package/dist/engine/pipeline/indexing/scanner/index.js.map +1 -0
  304. package/dist/engine/pipeline/search/index.d.ts +12 -0
  305. package/dist/engine/pipeline/search/index.js +811 -0
  306. package/dist/engine/pipeline/search/index.js.map +1 -0
  307. package/dist/engine/service/index.d.ts +3 -0
  308. package/dist/engine/service/index.js +2 -0
  309. package/dist/engine/service/index.js.map +1 -0
  310. package/dist/engine/service/lexical.d.ts +28 -0
  311. package/dist/engine/service/lexical.js +446 -0
  312. package/dist/engine/service/lexical.js.map +1 -0
  313. package/dist/engine/service/root.d.ts +15 -0
  314. package/dist/engine/service/root.js +57 -0
  315. package/dist/engine/service/root.js.map +1 -0
  316. package/dist/engine/service/structure-enrichment.d.ts +8 -0
  317. package/dist/engine/service/structure-enrichment.js +178 -0
  318. package/dist/engine/service/structure-enrichment.js.map +1 -0
  319. package/dist/engine/service/types.d.ts +212 -0
  320. package/dist/engine/service/types.js +2 -0
  321. package/dist/engine/service/types.js.map +1 -0
  322. package/dist/engine/service/workspace-index.d.ts +26 -0
  323. package/dist/engine/service/workspace-index.js +157 -0
  324. package/dist/engine/service/workspace-index.js.map +1 -0
  325. package/dist/engine/service/zvec-grep.d.ts +15 -0
  326. package/dist/engine/service/zvec-grep.js +1520 -0
  327. package/dist/engine/service/zvec-grep.js.map +1 -0
  328. package/dist/engine/storage/index.d.ts +53 -0
  329. package/dist/engine/storage/index.js +3 -0
  330. package/dist/engine/storage/index.js.map +1 -0
  331. package/dist/engine/storage/layout.d.ts +10 -0
  332. package/dist/engine/storage/layout.js +29 -0
  333. package/dist/engine/storage/layout.js.map +1 -0
  334. package/dist/engine/storage/zvec.d.ts +4 -0
  335. package/dist/engine/storage/zvec.js +976 -0
  336. package/dist/engine/storage/zvec.js.map +1 -0
  337. package/dist/engine/types.d.ts +303 -0
  338. package/dist/engine/types.js +14 -0
  339. package/dist/engine/types.js.map +1 -0
  340. package/dist/engine/utils/atomic-file.d.ts +3 -0
  341. package/dist/engine/utils/atomic-file.js +39 -0
  342. package/dist/engine/utils/atomic-file.js.map +1 -0
  343. package/dist/engine/utils/daemon-lease.d.ts +17 -0
  344. package/dist/engine/utils/daemon-lease.js +175 -0
  345. package/dist/engine/utils/daemon-lease.js.map +1 -0
  346. package/dist/engine/utils/file-selection.d.ts +10 -0
  347. package/dist/engine/utils/file-selection.js +157 -0
  348. package/dist/engine/utils/file-selection.js.map +1 -0
  349. package/dist/engine/utils/glob.d.ts +9 -0
  350. package/dist/engine/utils/glob.js +208 -0
  351. package/dist/engine/utils/glob.js.map +1 -0
  352. package/dist/engine/utils/hash.d.ts +2 -0
  353. package/dist/engine/utils/hash.js +8 -0
  354. package/dist/engine/utils/hash.js.map +1 -0
  355. package/dist/engine/utils/json.d.ts +8 -0
  356. package/dist/engine/utils/json.js +83 -0
  357. package/dist/engine/utils/json.js.map +1 -0
  358. package/dist/engine/utils/lock.d.ts +19 -0
  359. package/dist/engine/utils/lock.js +254 -0
  360. package/dist/engine/utils/lock.js.map +1 -0
  361. package/dist/engine/utils/path.d.ts +4 -0
  362. package/dist/engine/utils/path.js +18 -0
  363. package/dist/engine/utils/path.js.map +1 -0
  364. package/dist/engine/utils/timing.d.ts +19 -0
  365. package/dist/engine/utils/timing.js +87 -0
  366. package/dist/engine/utils/timing.js.map +1 -0
  367. package/dist/index-progress.d.ts +10 -0
  368. package/dist/index-progress.js +159 -0
  369. package/dist/index-progress.js.map +1 -0
  370. package/dist/index.d.ts +6 -0
  371. package/dist/index.js +4 -0
  372. package/dist/index.js.map +1 -0
  373. package/dist/mcp/http-transport.d.ts +27 -0
  374. package/dist/mcp/http-transport.js +182 -0
  375. package/dist/mcp/http-transport.js.map +1 -0
  376. package/dist/mcp/input-normalization.d.ts +38 -0
  377. package/dist/mcp/input-normalization.js +104 -0
  378. package/dist/mcp/input-normalization.js.map +1 -0
  379. package/dist/mcp/progress-heartbeat.d.ts +17 -0
  380. package/dist/mcp/progress-heartbeat.js +46 -0
  381. package/dist/mcp/progress-heartbeat.js.map +1 -0
  382. package/dist/mcp/request-metadata.d.ts +2 -0
  383. package/dist/mcp/request-metadata.js +11 -0
  384. package/dist/mcp/request-metadata.js.map +1 -0
  385. package/dist/mcp/request-state.d.ts +40 -0
  386. package/dist/mcp/request-state.js +210 -0
  387. package/dist/mcp/request-state.js.map +1 -0
  388. package/dist/mcp/result-format.d.ts +13 -0
  389. package/dist/mcp/result-format.js +75 -0
  390. package/dist/mcp/result-format.js.map +1 -0
  391. package/dist/mcp/schemas.d.ts +668 -0
  392. package/dist/mcp/schemas.js +512 -0
  393. package/dist/mcp/schemas.js.map +1 -0
  394. package/dist/mcp/stdio-bridge.d.ts +15 -0
  395. package/dist/mcp/stdio-bridge.js +190 -0
  396. package/dist/mcp/stdio-bridge.js.map +1 -0
  397. package/dist/mcp/tools.d.ts +153 -0
  398. package/dist/mcp/tools.js +488 -0
  399. package/dist/mcp/tools.js.map +1 -0
  400. package/dist/mcp/toolset.d.ts +5 -0
  401. package/dist/mcp/toolset.js +12 -0
  402. package/dist/mcp/toolset.js.map +1 -0
  403. package/dist/observability/trace-context.d.ts +11 -0
  404. package/dist/observability/trace-context.js +138 -0
  405. package/dist/observability/trace-context.js.map +1 -0
  406. package/dist/prompts/zvec-grep-guidance.d.ts +2 -0
  407. package/dist/prompts/zvec-grep-guidance.js +9 -0
  408. package/dist/prompts/zvec-grep-guidance.js.map +1 -0
  409. package/docs/01-agents.md +217 -0
  410. package/docs/02-cli.md +259 -0
  411. package/docs/03-mcp.md +185 -0
  412. package/docs/04-pipeline.md +234 -0
  413. package/docs/05-architecture.md +86 -0
  414. package/docs/06-server.md +279 -0
  415. package/docs/07-embedding.md +227 -0
  416. package/docs/08-roadmap.md +85 -0
  417. package/docs/README.md +53 -0
  418. package/package.json +87 -0
@@ -0,0 +1,776 @@
1
+ import { lstat, open, readFile, readdir, realpath, stat, } from "node:fs/promises";
2
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
3
+ import { detectFileType } from "../../../file-type.js";
4
+ import { resolveMaxFileSizeBytes } from "../../../file-size-policy.js";
5
+ import { sha256Text } from "../../../utils/hash.js";
6
+ import { matchesFileSelection, resolveFileTypePatterns, } from "../../../utils/file-selection.js";
7
+ import { normalizePathPattern, pathPatternMatches, pathPatternMightMatchDescendant, } from "../../../utils/glob.js";
8
+ import { normalizePath, toDisplayPath } from "../../../utils/path.js";
9
+ import { matchesRootExcludePatterns, matchesRootPatterns, normalizeRootPath, validateRootPaths, } from "../root-paths.js";
10
+ const BINARY_SNIFF_BYTES = 8192;
11
+ const BINARY_CONTROL_CHAR_RATIO = 0.3;
12
+ const MAX_GITIGNORE_CACHE_ENTRIES = 4_096;
13
+ const DEFAULT_IGNORED_DIRECTORY_NAMES = [
14
+ "node_modules",
15
+ "vendor",
16
+ "thirdparty",
17
+ "third_party",
18
+ "external",
19
+ "deps",
20
+ "dist",
21
+ "build",
22
+ "out",
23
+ "target",
24
+ "coverage",
25
+ "generated",
26
+ "__pycache__",
27
+ "venv",
28
+ ".venv",
29
+ "env",
30
+ ".tox",
31
+ ".eggs",
32
+ "Pods",
33
+ ".next",
34
+ ".nuxt",
35
+ ".svelte-kit",
36
+ ".turbo",
37
+ ".vite",
38
+ ".parcel-cache",
39
+ ".cache",
40
+ ".gradle",
41
+ ".pytest_cache",
42
+ ".mypy_cache",
43
+ ".ruff_cache",
44
+ "tmp",
45
+ "temp",
46
+ "logs",
47
+ "locale",
48
+ "locales",
49
+ "translations",
50
+ ];
51
+ const DEFAULT_IGNORED_FILE_PATTERNS = [
52
+ // Cross-ecosystem dependency resolution output. These files remain
53
+ // available to exact rg search and can be restored with an explicit include.
54
+ "*.lock",
55
+ "*.lockb",
56
+ "*-lock.json",
57
+ "*-lock.yaml",
58
+ "npm-shrinkwrap.json",
59
+ "go.sum",
60
+ "*.resolved",
61
+ // Generated localization, browser, and compiler artifacts.
62
+ "*.po",
63
+ "*.pot",
64
+ "*.map",
65
+ "*.min.*",
66
+ "*.bundle.*",
67
+ // General generated-source naming conventions outside generated directories.
68
+ "*.generated.*",
69
+ "*.gen.*",
70
+ "*.designer.*",
71
+ "*.pb.*",
72
+ "*_pb2.*",
73
+ "*.g.*",
74
+ // Raster assets require an explicitly selected path to enter the semantic
75
+ // index. Exact search behavior is unaffected.
76
+ "*.gif",
77
+ "*.jpeg",
78
+ "*.jpg",
79
+ "*.png",
80
+ "*.webp",
81
+ ];
82
+ const HARD_SKIP_HIDDEN_NAMES = new Set([".git", ".zvec-grep"]);
83
+ const DEFAULT_IGNORE_RULES = [
84
+ ...DEFAULT_IGNORED_DIRECTORY_NAMES.map((pattern) => ({
85
+ basePath: "",
86
+ pattern,
87
+ negated: false,
88
+ directoryOnly: true,
89
+ anchored: false,
90
+ hasSlash: false,
91
+ })),
92
+ ...DEFAULT_IGNORED_FILE_PATTERNS.map((pattern) => ({
93
+ basePath: "",
94
+ pattern,
95
+ negated: false,
96
+ directoryOnly: false,
97
+ anchored: false,
98
+ hasSlash: false,
99
+ })),
100
+ ];
101
+ const gitIgnoreRuleCache = new Map();
102
+ function knownFilesByPath(files) {
103
+ return new Map((files ?? []).map((file) => [normalizePath(file.absolutePath), file]));
104
+ }
105
+ export async function scanRootPaths(workspaceIndexId, rootPaths, options = {}) {
106
+ const validatedRootPaths = validateRootPaths(rootPaths);
107
+ const files = [];
108
+ const diagnostics = createScanDiagnostics();
109
+ const knownFiles = knownFilesByPath(options.knownFiles);
110
+ for (const rootPath of validatedRootPaths) {
111
+ throwIfAborted(options.signal);
112
+ await scanRootPath(workspaceIndexId, rootPath, files, diagnostics, options.signal, knownFiles);
113
+ }
114
+ return { files, diagnostics };
115
+ }
116
+ export async function scanFilePath(workspaceIndexId, rootPaths, absolutePath, options = {}) {
117
+ const files = [];
118
+ const diagnostics = createScanDiagnostics();
119
+ const knownFiles = knownFilesByPath(options.knownFiles);
120
+ for (const rootPath of matchingRootPaths(rootPaths, absolutePath)) {
121
+ throwIfAborted(options.signal);
122
+ const root = normalizeRootPath(rootPath);
123
+ const targetInfo = await lstat(absolutePath).catch(() => null);
124
+ const followedInfo = targetInfo?.isSymbolicLink() && root.follow
125
+ ? await stat(absolutePath).catch(() => null)
126
+ : targetInfo;
127
+ if (!followedInfo?.isFile()) {
128
+ continue;
129
+ }
130
+ if (!root.recursive && dirname(absolutePath) !== root.absolutePath) {
131
+ continue;
132
+ }
133
+ const relativePath = toDisplayPath(relative(root.absolutePath, absolutePath));
134
+ const rules = await ignoreRulesForDirectory(root, dirname(absolutePath));
135
+ const fileTypes = await resolveFileTypePatterns(root.fileTypes, root.excludedFileTypes);
136
+ if (!pathCanBeScanned(root, relativePath, basename(absolutePath), false, rules) ||
137
+ !matchesFileSelection(relativePath, root, fileTypes) ||
138
+ (await hasExcludedNestedGitAncestor(root, absolutePath, false))) {
139
+ continue;
140
+ }
141
+ const file = await readFileInfo(workspaceIndexId, root, absolutePath, diagnostics, knownFiles);
142
+ if (file) {
143
+ files.push(file);
144
+ }
145
+ }
146
+ return { files: dedupeFiles(files), diagnostics };
147
+ }
148
+ export async function pathCanAffectIndex(rootPaths, absolutePath, isDirectory) {
149
+ for (const configuredRoot of rootPaths) {
150
+ const root = normalizeRootPath(configuredRoot);
151
+ const pathFromRoot = relative(root.absolutePath, absolutePath);
152
+ if (isAbsolute(pathFromRoot) ||
153
+ pathFromRoot === ".." ||
154
+ pathFromRoot.startsWith(`..${sep}`)) {
155
+ continue;
156
+ }
157
+ if (pathFromRoot.length === 0) {
158
+ return true;
159
+ }
160
+ const depth = pathFromRoot.split(sep).filter(Boolean).length;
161
+ if ((!root.recursive &&
162
+ (isDirectory || dirname(absolutePath) !== root.absolutePath)) ||
163
+ (root.maxDepth !== undefined &&
164
+ (isDirectory ? depth >= root.maxDepth : depth > root.maxDepth))) {
165
+ continue;
166
+ }
167
+ const relativePath = toDisplayPath(pathFromRoot);
168
+ const rules = await ignoreRulesForDirectory(root, dirname(absolutePath));
169
+ if (!pathCanBeScanned(root, relativePath, basename(absolutePath), isDirectory, rules) ||
170
+ (await hasExcludedNestedGitAncestor(root, absolutePath, isDirectory))) {
171
+ continue;
172
+ }
173
+ if (isDirectory) {
174
+ return true;
175
+ }
176
+ const fileTypes = await resolveFileTypePatterns(root.fileTypes, root.excludedFileTypes);
177
+ if (matchesFileSelection(relativePath, root, fileTypes)) {
178
+ return true;
179
+ }
180
+ }
181
+ return false;
182
+ }
183
+ export async function scanDirectoryPath(workspaceIndexId, rootPaths, absolutePath, options = {}) {
184
+ const files = [];
185
+ const diagnostics = createScanDiagnostics();
186
+ const knownFiles = knownFilesByPath(options.knownFiles);
187
+ for (const rootPath of matchingRootPaths(rootPaths, absolutePath)) {
188
+ throwIfAborted(options.signal);
189
+ const root = normalizeRootPath(rootPath);
190
+ if (!root.recursive && absolutePath !== root.absolutePath) {
191
+ continue;
192
+ }
193
+ const info = await lstat(absolutePath).catch(() => null);
194
+ const followedInfo = info?.isSymbolicLink() && root.follow
195
+ ? await stat(absolutePath).catch(() => null)
196
+ : info;
197
+ if (!followedInfo?.isDirectory()) {
198
+ continue;
199
+ }
200
+ const relativePath = toDisplayPath(relative(root.absolutePath, absolutePath));
201
+ const parentRules = await ignoreRulesForDirectory(root, dirname(absolutePath));
202
+ const fileTypes = await resolveFileTypePatterns(root.fileTypes, root.excludedFileTypes);
203
+ if (relativePath &&
204
+ (!pathCanBeScanned(root, relativePath, basename(absolutePath), true, parentRules) ||
205
+ (await hasExcludedNestedGitAncestor(root, absolutePath, true)))) {
206
+ continue;
207
+ }
208
+ const rootRealPath = await realpath(root.absolutePath).catch(() => root.absolutePath);
209
+ const directoryRealPath = await realpath(absolutePath).catch(() => absolutePath);
210
+ const depth = relativePath.split("/").filter(Boolean).length;
211
+ await walk(workspaceIndexId, root, absolutePath, files, diagnostics, parentRules, fileTypes, new Set([rootRealPath, directoryRealPath]), depth, options.signal, knownFiles);
212
+ }
213
+ return { files: dedupeFiles(files), diagnostics };
214
+ }
215
+ async function hasExcludedNestedGitAncestor(rootPath, absolutePath, includeTarget) {
216
+ const pathFromRoot = relative(rootPath.absolutePath, absolutePath);
217
+ const segments = pathFromRoot.split(sep).filter(Boolean);
218
+ const directorySegments = includeTarget ? segments : segments.slice(0, -1);
219
+ let current = rootPath.absolutePath;
220
+ for (const segment of directorySegments) {
221
+ current = join(current, segment);
222
+ const relativeDirectory = toDisplayPath(relative(rootPath.absolutePath, current));
223
+ if ((await isNestedGitRepositoryDirectory(current)) &&
224
+ !nestedGitRepositoryExplicitlyIncluded(relativeDirectory, rootPath)) {
225
+ return true;
226
+ }
227
+ }
228
+ return false;
229
+ }
230
+ function matchingRootPaths(rootPaths, absolutePath) {
231
+ return validateRootPaths(rootPaths).filter((rootPath) => {
232
+ const root = normalizeRootPath(rootPath);
233
+ const pathFromRoot = relative(root.absolutePath, absolutePath);
234
+ return (!isAbsolute(pathFromRoot) &&
235
+ pathFromRoot !== ".." &&
236
+ !pathFromRoot.startsWith(`..${sep}`));
237
+ });
238
+ }
239
+ async function ignoreRulesForDirectory(rootPath, directory) {
240
+ const pathFromRoot = relative(rootPath.absolutePath, directory);
241
+ if (isAbsolute(pathFromRoot) ||
242
+ pathFromRoot === ".." ||
243
+ pathFromRoot.startsWith(`..${sep}`)) {
244
+ return [...DEFAULT_IGNORE_RULES];
245
+ }
246
+ const rules = [
247
+ ...(rootPath.noIgnore ? [] : DEFAULT_IGNORE_RULES),
248
+ ...(await readConfiguredIgnoreRules(rootPath)),
249
+ ];
250
+ let current = rootPath.absolutePath;
251
+ if (!rootPath.noIgnore) {
252
+ rules.push(...(await readGitIgnoreRules(rootPath, current)));
253
+ }
254
+ if (!pathFromRoot) {
255
+ return rules;
256
+ }
257
+ for (const segment of pathFromRoot.split(sep).filter(Boolean)) {
258
+ current = join(current, segment);
259
+ if (!rootPath.noIgnore) {
260
+ rules.push(...(await readGitIgnoreRules(rootPath, current)));
261
+ }
262
+ }
263
+ return rules;
264
+ }
265
+ function pathCanBeScanned(rootPath, relativePath, name, isDirectory, ignoreRules) {
266
+ if (relativePath
267
+ .split("/")
268
+ .some((segment) => HARD_SKIP_HIDDEN_NAMES.has(segment))) {
269
+ return false;
270
+ }
271
+ const ignoreMatch = matchIgnoreRules(relativePath, isDirectory, ignoreRules);
272
+ if (ignoreMatch.ignored &&
273
+ !ignoredPathExplicitlyIncluded(relativePath, rootPath, ignoreMatch)) {
274
+ return false;
275
+ }
276
+ if (matchesRootExcludePatterns(relativePath, rootPath)) {
277
+ return false;
278
+ }
279
+ if (isDirectory) {
280
+ return !shouldSkipHiddenDirectory(name, relativePath, rootPath);
281
+ }
282
+ return (!shouldSkipHiddenFile(name, relativePath, rootPath) &&
283
+ matchesRootPatterns(relativePath, rootPath));
284
+ }
285
+ function dedupeFiles(files) {
286
+ return [...new Map(files.map((file) => [file.id, file])).values()];
287
+ }
288
+ async function scanRootPath(workspaceIndexId, rootPath, files, diagnostics, signal, knownFiles = new Map()) {
289
+ throwIfAborted(signal);
290
+ const root = normalizeRootPath(rootPath);
291
+ const fileTypes = await resolveFileTypePatterns(root.fileTypes, root.excludedFileTypes);
292
+ const info = await stat(root.absolutePath).catch(() => null);
293
+ if (!info) {
294
+ return;
295
+ }
296
+ if (info.isFile()) {
297
+ const relativePath = basename(root.absolutePath);
298
+ const file = matchesFileSelection(relativePath, root, fileTypes)
299
+ ? await readFileInfo(workspaceIndexId, root, root.absolutePath, diagnostics, knownFiles)
300
+ : null;
301
+ if (file) {
302
+ files.push(file);
303
+ }
304
+ return;
305
+ }
306
+ if (!info.isDirectory()) {
307
+ return;
308
+ }
309
+ if (HARD_SKIP_HIDDEN_NAMES.has(basename(root.absolutePath))) {
310
+ return;
311
+ }
312
+ const rootRealPath = await realpath(root.absolutePath).catch(() => root.absolutePath);
313
+ await walk(workspaceIndexId, root, root.absolutePath, files, diagnostics, [
314
+ ...(root.noIgnore ? [] : DEFAULT_IGNORE_RULES),
315
+ ...(await readConfiguredIgnoreRules(root)),
316
+ ], fileTypes, new Set([rootRealPath]), 0, signal, knownFiles);
317
+ }
318
+ async function walk(workspaceIndexId, rootPath, currentPath, files, diagnostics, parentIgnoreRules, fileTypes, visitedDirectories, depth, signal, knownFiles = new Map()) {
319
+ throwIfAborted(signal);
320
+ let entries;
321
+ const ignoreRules = [
322
+ ...parentIgnoreRules,
323
+ ...(rootPath.noIgnore
324
+ ? []
325
+ : await readGitIgnoreRules(rootPath, currentPath)),
326
+ ];
327
+ try {
328
+ entries = await readdir(currentPath, { withFileTypes: true });
329
+ }
330
+ catch {
331
+ return;
332
+ }
333
+ for (const entry of entries) {
334
+ throwIfAborted(signal);
335
+ const absolutePath = join(currentPath, entry.name);
336
+ const relativePath = toDisplayPath(relative(rootPath.absolutePath, absolutePath));
337
+ let isDirectory = entry.isDirectory();
338
+ let isFile = entry.isFile();
339
+ if (entry.isSymbolicLink() && rootPath.follow) {
340
+ const target = await stat(absolutePath).catch(() => null);
341
+ isDirectory = target?.isDirectory() === true;
342
+ isFile = target?.isFile() === true;
343
+ }
344
+ if (isDirectory) {
345
+ if (!rootPath.recursive) {
346
+ continue;
347
+ }
348
+ if (rootPath.maxDepth !== undefined && depth + 1 >= rootPath.maxDepth) {
349
+ continue;
350
+ }
351
+ const ignoreMatch = matchIgnoreRules(relativePath, true, ignoreRules);
352
+ if (HARD_SKIP_HIDDEN_NAMES.has(entry.name) ||
353
+ matchesRootExcludePatterns(relativePath, rootPath) ||
354
+ (ignoreMatch.ignored &&
355
+ !ignoredPathExplicitlyIncluded(relativePath, rootPath, ignoreMatch)) ||
356
+ shouldSkipHiddenDirectory(entry.name, relativePath, rootPath)) {
357
+ continue;
358
+ }
359
+ if ((await isNestedGitRepositoryDirectory(absolutePath)) &&
360
+ !nestedGitRepositoryExplicitlyIncluded(relativePath, rootPath)) {
361
+ continue;
362
+ }
363
+ const realDirectory = await realpath(absolutePath).catch(() => null);
364
+ if (!realDirectory || visitedDirectories.has(realDirectory)) {
365
+ continue;
366
+ }
367
+ visitedDirectories.add(realDirectory);
368
+ await walk(workspaceIndexId, rootPath, absolutePath, files, diagnostics, ignoreRules, fileTypes, visitedDirectories, depth + 1, signal, knownFiles);
369
+ continue;
370
+ }
371
+ if (!isFile) {
372
+ continue;
373
+ }
374
+ if (rootPath.maxDepth !== undefined && depth + 1 > rootPath.maxDepth) {
375
+ continue;
376
+ }
377
+ if (HARD_SKIP_HIDDEN_NAMES.has(entry.name)) {
378
+ continue;
379
+ }
380
+ const ignoreMatch = matchIgnoreRules(relativePath, false, ignoreRules);
381
+ if (ignoreMatch.ignored &&
382
+ !ignoredPathExplicitlyIncluded(relativePath, rootPath, ignoreMatch)) {
383
+ continue;
384
+ }
385
+ if (shouldSkipHiddenFile(entry.name, relativePath, rootPath)) {
386
+ continue;
387
+ }
388
+ if (!matchesRootPatterns(relativePath, rootPath)) {
389
+ continue;
390
+ }
391
+ if (!matchesFileSelection(relativePath, rootPath, fileTypes)) {
392
+ continue;
393
+ }
394
+ const file = await readFileInfo(workspaceIndexId, rootPath, absolutePath, diagnostics, knownFiles);
395
+ throwIfAborted(signal);
396
+ if (file) {
397
+ files.push(file);
398
+ }
399
+ }
400
+ }
401
+ function throwIfAborted(signal) {
402
+ if (!signal?.aborted) {
403
+ return;
404
+ }
405
+ throw signal.reason instanceof Error
406
+ ? signal.reason
407
+ : new Error("Indexing was cancelled.");
408
+ }
409
+ function isHiddenName(name) {
410
+ return name.startsWith(".") && name !== "." && name !== "..";
411
+ }
412
+ async function readGitIgnoreRules(rootPath, currentPath) {
413
+ const ignorePath = join(currentPath, ".gitignore");
414
+ const content = await readFile(ignorePath, "utf8").catch(() => null);
415
+ const basePath = toDisplayPath(relative(rootPath.absolutePath, currentPath));
416
+ const cacheKey = `${ignorePath}\0${basePath}`;
417
+ if (content === null) {
418
+ gitIgnoreRuleCache.delete(cacheKey);
419
+ return [];
420
+ }
421
+ const cached = gitIgnoreRuleCache.get(cacheKey);
422
+ if (cached?.content === content) {
423
+ return cached.rules;
424
+ }
425
+ const rules = parseGitIgnoreRules(content, basePath);
426
+ gitIgnoreRuleCache.set(cacheKey, { content, rules });
427
+ if (gitIgnoreRuleCache.size > MAX_GITIGNORE_CACHE_ENTRIES) {
428
+ gitIgnoreRuleCache.delete(gitIgnoreRuleCache.keys().next().value);
429
+ }
430
+ return rules;
431
+ }
432
+ async function readConfiguredIgnoreRules(rootPath) {
433
+ const rules = [];
434
+ for (const path of rootPath.ignoreFiles ?? []) {
435
+ const absolutePath = isAbsolute(path)
436
+ ? path
437
+ : resolve(rootPath.absolutePath, path);
438
+ const content = await readFile(absolutePath, "utf8");
439
+ rules.push(...parseGitIgnoreRules(content, ""));
440
+ }
441
+ return rules;
442
+ }
443
+ function parseGitIgnoreRules(content, basePath) {
444
+ const rules = [];
445
+ for (const rawLine of content.split(/\r?\n/)) {
446
+ const rule = parseGitIgnoreRule(rawLine, basePath);
447
+ if (rule) {
448
+ rules.push(rule);
449
+ }
450
+ }
451
+ return rules;
452
+ }
453
+ function parseGitIgnoreRule(line, basePath) {
454
+ let pattern = line.trim();
455
+ if (pattern.length === 0 || pattern.startsWith("#")) {
456
+ return null;
457
+ }
458
+ let negated = false;
459
+ if (pattern.startsWith("\\#") || pattern.startsWith("\\!")) {
460
+ pattern = pattern.slice(1);
461
+ }
462
+ else if (pattern.startsWith("!")) {
463
+ negated = true;
464
+ pattern = pattern.slice(1).trim();
465
+ }
466
+ if (pattern.length === 0) {
467
+ return null;
468
+ }
469
+ const directoryOnly = pattern.endsWith("/");
470
+ pattern = directoryOnly ? pattern.replace(/\/+$/, "") : pattern;
471
+ const anchored = pattern.startsWith("/");
472
+ pattern = anchored ? pattern.replace(/^\/+/, "") : pattern;
473
+ pattern = normalizePathPattern(pattern);
474
+ if (pattern.length === 0) {
475
+ return null;
476
+ }
477
+ return {
478
+ basePath,
479
+ pattern,
480
+ negated,
481
+ directoryOnly,
482
+ anchored,
483
+ hasSlash: pattern.includes("/"),
484
+ };
485
+ }
486
+ function matchIgnoreRules(relativePath, isDirectory, rules) {
487
+ let ignored = false;
488
+ let matchedNegation = false;
489
+ let matchedRule;
490
+ for (const rule of rules) {
491
+ if (!ignoreRuleMatches(rule, relativePath, isDirectory)) {
492
+ continue;
493
+ }
494
+ ignored = !rule.negated;
495
+ matchedNegation = rule.negated;
496
+ matchedRule = rule;
497
+ }
498
+ return {
499
+ ignored,
500
+ matchedNegation,
501
+ matchedRule,
502
+ };
503
+ }
504
+ function ignoredPathExplicitlyIncluded(relativePath, rootPath, ignoreMatch) {
505
+ if (!ignoreMatch.ignored || !ignoreMatch.matchedRule || !rootPath.include) {
506
+ return false;
507
+ }
508
+ return rootPath.include.some((pattern) => includePatternNamesIgnoredPath(pattern, relativePath, ignoreMatch.matchedRule.pattern));
509
+ }
510
+ function includePatternNamesIgnoredPath(includePattern, relativePath, ignoredPattern) {
511
+ const normalizedInclude = normalizePathPattern(includePattern);
512
+ const normalizedRelativePath = normalizePathPattern(relativePath);
513
+ const ignoredSegments = ignoredPattern.split("/");
514
+ if (!pathPatternMightMatchDescendant(normalizedInclude, normalizedRelativePath) &&
515
+ !pathPatternMatches(normalizedInclude, normalizedRelativePath)) {
516
+ return false;
517
+ }
518
+ return normalizedInclude
519
+ .split("/")
520
+ .some((segment) => ignoredSegments.some((ignoredSegment) => includeSegmentNamesIgnoredPath(segment, ignoredSegment)));
521
+ }
522
+ function includeSegmentNamesIgnoredPath(segment, ignoredSegment) {
523
+ if (segment === "*" || segment === "**" || segment === "?") {
524
+ return false;
525
+ }
526
+ return (segmentMatches(segment, ignoredSegment) ||
527
+ segmentMatches(ignoredSegment, segment));
528
+ }
529
+ function ignoreRuleMatches(rule, relativePath, isDirectory) {
530
+ const path = relativeToIgnoreRuleBase(relativePath, rule.basePath);
531
+ if (path === null || path.length === 0) {
532
+ return false;
533
+ }
534
+ if (rule.directoryOnly) {
535
+ if (rule.anchored || rule.hasSlash) {
536
+ return pathPatternMatches(rule.pattern, path);
537
+ }
538
+ return pathContainsMatchingSegment(path, rule.pattern);
539
+ }
540
+ if (rule.anchored || rule.hasSlash) {
541
+ return pathPatternMatches(rule.pattern, path);
542
+ }
543
+ if (isDirectory && pathContainsMatchingSegment(path, rule.pattern)) {
544
+ return true;
545
+ }
546
+ return segmentMatches(rule.pattern, basename(path));
547
+ }
548
+ function relativeToIgnoreRuleBase(relativePath, basePath) {
549
+ if (basePath.length === 0) {
550
+ return relativePath;
551
+ }
552
+ if (relativePath === basePath) {
553
+ return "";
554
+ }
555
+ const prefix = `${basePath}/`;
556
+ return relativePath.startsWith(prefix)
557
+ ? relativePath.slice(prefix.length)
558
+ : null;
559
+ }
560
+ function pathContainsMatchingSegment(path, pattern) {
561
+ return path.split("/").some((segment) => segmentMatches(pattern, segment));
562
+ }
563
+ function segmentMatches(pattern, segment) {
564
+ return pathPatternMatches(pattern, segment);
565
+ }
566
+ function shouldSkipHiddenDirectory(name, relativePath, rootPath) {
567
+ if (!isHiddenName(name) || rootPath.hidden) {
568
+ return false;
569
+ }
570
+ return !hasIncludeDescendant(relativePath, rootPath.include);
571
+ }
572
+ function shouldSkipHiddenFile(name, relativePath, rootPath) {
573
+ return (isHiddenName(name) &&
574
+ !rootPath.hidden &&
575
+ !hasExplicitHiddenFileInclude(relativePath, rootPath.include));
576
+ }
577
+ async function isNestedGitRepositoryDirectory(absolutePath) {
578
+ const marker = await stat(join(absolutePath, ".git")).catch(() => null);
579
+ return marker !== null && (marker.isFile() || marker.isDirectory());
580
+ }
581
+ function nestedGitRepositoryExplicitlyIncluded(relativePath, rootPath) {
582
+ if (!rootPath.include || rootPath.include.length === 0) {
583
+ return false;
584
+ }
585
+ const normalizedRelativePath = normalizePathPattern(relativePath);
586
+ return rootPath.include.some((pattern) => {
587
+ const normalizedPattern = normalizePathPattern(pattern);
588
+ return (pathPatternMatches(normalizedPattern, normalizedRelativePath) ||
589
+ normalizedPattern.startsWith(`${normalizedRelativePath}/`));
590
+ });
591
+ }
592
+ function hasIncludeDescendant(relativePath, includePatterns) {
593
+ if (!includePatterns || includePatterns.length === 0) {
594
+ return false;
595
+ }
596
+ return includePatterns.some((pattern) => includePatternDeclaresHiddenDirectory(pattern, relativePath) &&
597
+ pathPatternMightMatchDescendant(pattern, relativePath));
598
+ }
599
+ function hasExplicitHiddenFileInclude(relativePath, includePatterns) {
600
+ if (!includePatterns || includePatterns.length === 0) {
601
+ return false;
602
+ }
603
+ return includePatterns.some((pattern) => includePatternDeclaresHiddenDirectory(pattern, relativePath) &&
604
+ pathPatternMatches(pattern, relativePath));
605
+ }
606
+ function includePatternDeclaresHiddenDirectory(pattern, relativePath) {
607
+ const name = basename(relativePath);
608
+ if (!isHiddenName(name)) {
609
+ return true;
610
+ }
611
+ return normalizePathPattern(pattern)
612
+ .split("/")
613
+ .some((segment) => hiddenPatternSegmentMatches(segment, name));
614
+ }
615
+ function hiddenPatternSegmentMatches(patternSegment, name) {
616
+ if (!patternSegment.startsWith(".")) {
617
+ return false;
618
+ }
619
+ if (!patternSegment.includes("*") && !patternSegment.includes("?")) {
620
+ return patternSegment === name;
621
+ }
622
+ return segmentGlobToRegExp(patternSegment).test(name);
623
+ }
624
+ function segmentGlobToRegExp(pattern) {
625
+ let expression = "^";
626
+ for (const char of pattern) {
627
+ if (char === "*") {
628
+ expression += "[^/]*";
629
+ }
630
+ else if (char === "?") {
631
+ expression += "[^/]";
632
+ }
633
+ else {
634
+ expression += escapeRegExp(char);
635
+ }
636
+ }
637
+ return new RegExp(`${expression}$`);
638
+ }
639
+ function escapeRegExp(value) {
640
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
641
+ }
642
+ async function readFileInfo(workspaceIndexId, rootPath, absolutePath, diagnostics, knownFiles = new Map()) {
643
+ const info = await stat(absolutePath).catch(() => null);
644
+ if (!info || !info.isFile()) {
645
+ return null;
646
+ }
647
+ const relativePath = toDisplayPath(relative(rootPath.absolutePath, absolutePath)) ||
648
+ basename(absolutePath);
649
+ if (info.size === 0) {
650
+ recordSkippedFile(diagnostics, {
651
+ absolutePath,
652
+ relativePath,
653
+ reason: "empty",
654
+ sizeBytes: 0,
655
+ });
656
+ return null;
657
+ }
658
+ const detected = detectFileType(absolutePath);
659
+ if (!detected) {
660
+ recordSkippedFile(diagnostics, {
661
+ absolutePath,
662
+ relativePath,
663
+ reason: "unsupported",
664
+ sizeBytes: info.size,
665
+ });
666
+ return null;
667
+ }
668
+ const maxFileSize = resolveMaxFileSizeBytes(detected.kind, rootPath.maxFileSizeBytes);
669
+ if (info.size > maxFileSize) {
670
+ recordSkippedFile(diagnostics, {
671
+ absolutePath,
672
+ relativePath,
673
+ reason: "too_large",
674
+ sizeBytes: info.size,
675
+ limitBytes: maxFileSize,
676
+ });
677
+ return null;
678
+ }
679
+ const lastModifiedTime = Math.trunc(info.mtimeMs);
680
+ const known = knownFiles.get(normalizePath(absolutePath));
681
+ if (known?.contentHash &&
682
+ known.sizeBytes === info.size &&
683
+ known.lastModifiedTime === lastModifiedTime) {
684
+ return {
685
+ id: makeFileId(workspaceIndexId, absolutePath),
686
+ absolutePath,
687
+ relativePath,
688
+ rootPath: rootPath.absolutePath,
689
+ sizeBytes: info.size,
690
+ lastModifiedTime,
691
+ kind: detected.kind,
692
+ format: detected.format,
693
+ };
694
+ }
695
+ if (detected.kind !== "image" && (await isLikelyBinaryFile(absolutePath))) {
696
+ recordSkippedFile(diagnostics, {
697
+ absolutePath,
698
+ relativePath,
699
+ reason: "binary",
700
+ sizeBytes: info.size,
701
+ });
702
+ return null;
703
+ }
704
+ return {
705
+ id: makeFileId(workspaceIndexId, absolutePath),
706
+ absolutePath,
707
+ relativePath,
708
+ rootPath: rootPath.absolutePath,
709
+ sizeBytes: info.size,
710
+ lastModifiedTime,
711
+ kind: detected.kind,
712
+ format: detected.format,
713
+ };
714
+ }
715
+ const MAX_SKIPPED_FILE_SAMPLES = 20;
716
+ export function createScanDiagnostics() {
717
+ return {
718
+ skippedFiles: 0,
719
+ skippedByReason: {
720
+ empty: 0,
721
+ too_large: 0,
722
+ unsupported: 0,
723
+ binary: 0,
724
+ },
725
+ skippedSamples: [],
726
+ };
727
+ }
728
+ function recordSkippedFile(diagnostics, skipped) {
729
+ diagnostics.skippedFiles++;
730
+ diagnostics.skippedByReason[skipped.reason]++;
731
+ if (diagnostics.skippedSamples.length < MAX_SKIPPED_FILE_SAMPLES) {
732
+ diagnostics.skippedSamples.push(skipped);
733
+ }
734
+ }
735
+ async function isLikelyBinaryFile(path) {
736
+ let handle;
737
+ try {
738
+ handle = await open(path, "r");
739
+ const buffer = Buffer.alloc(BINARY_SNIFF_BYTES);
740
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
741
+ if (bytesRead === 0) {
742
+ return false;
743
+ }
744
+ let suspicious = 0;
745
+ for (let index = 0; index < bytesRead; index++) {
746
+ const value = buffer[index];
747
+ if (value === 0) {
748
+ return true;
749
+ }
750
+ if (isSuspiciousControlByte(value)) {
751
+ suspicious++;
752
+ }
753
+ }
754
+ return suspicious / bytesRead > BINARY_CONTROL_CHAR_RATIO;
755
+ }
756
+ catch {
757
+ return false;
758
+ }
759
+ finally {
760
+ await handle?.close().catch(() => undefined);
761
+ }
762
+ }
763
+ function isSuspiciousControlByte(value) {
764
+ return (value < 32 &&
765
+ value !== 7 &&
766
+ value !== 8 &&
767
+ value !== 9 &&
768
+ value !== 10 &&
769
+ value !== 12 &&
770
+ value !== 13 &&
771
+ value !== 27);
772
+ }
773
+ function makeFileId(workspaceIndexId, absolutePath) {
774
+ return sha256Text(`${workspaceIndexId}\0${normalizePath(absolutePath)}`);
775
+ }
776
+ //# sourceMappingURL=index.js.map