@smthrs/std 0.0.0-stage → 1.0.0-rc.3

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 (555) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/LICENSE +21 -0
  3. package/README.md +152 -2
  4. package/dist/cjs/ApplyPatch.d.ts +174 -0
  5. package/dist/cjs/ApplyPatch.d.ts.map +1 -0
  6. package/dist/cjs/ApplyPatch.js +309 -0
  7. package/dist/cjs/ApplyPatch.js.map +7 -0
  8. package/dist/cjs/Bash.d.ts +304 -0
  9. package/dist/cjs/Bash.d.ts.map +1 -0
  10. package/dist/cjs/Bash.js +321 -0
  11. package/dist/cjs/Bash.js.map +7 -0
  12. package/dist/cjs/Checkpoints.d.ts +279 -0
  13. package/dist/cjs/Checkpoints.d.ts.map +1 -0
  14. package/dist/cjs/Checkpoints.js +145 -0
  15. package/dist/cjs/Checkpoints.js.map +7 -0
  16. package/dist/cjs/Container.d.ts +132 -0
  17. package/dist/cjs/Container.d.ts.map +1 -0
  18. package/dist/cjs/Container.js +113 -0
  19. package/dist/cjs/Container.js.map +7 -0
  20. package/dist/cjs/Edit.d.ts +203 -0
  21. package/dist/cjs/Edit.d.ts.map +1 -0
  22. package/dist/cjs/Edit.js +258 -0
  23. package/dist/cjs/Edit.js.map +7 -0
  24. package/dist/cjs/ExaWebSearch.d.ts +22 -0
  25. package/dist/cjs/ExaWebSearch.d.ts.map +1 -0
  26. package/dist/cjs/ExaWebSearch.js +138 -0
  27. package/dist/cjs/ExaWebSearch.js.map +7 -0
  28. package/dist/cjs/Explore.d.ts +328 -0
  29. package/dist/cjs/Explore.d.ts.map +1 -0
  30. package/dist/cjs/Explore.js +90 -0
  31. package/dist/cjs/Explore.js.map +7 -0
  32. package/dist/cjs/Fetch.d.ts +130 -0
  33. package/dist/cjs/Fetch.d.ts.map +1 -0
  34. package/dist/cjs/Fetch.js +64 -0
  35. package/dist/cjs/Fetch.js.map +7 -0
  36. package/dist/cjs/Glob.d.ts +204 -0
  37. package/dist/cjs/Glob.d.ts.map +1 -0
  38. package/dist/cjs/Glob.js +94 -0
  39. package/dist/cjs/Glob.js.map +7 -0
  40. package/dist/cjs/Grep.d.ts +347 -0
  41. package/dist/cjs/Grep.d.ts.map +1 -0
  42. package/dist/cjs/Grep.js +181 -0
  43. package/dist/cjs/Grep.js.map +7 -0
  44. package/dist/cjs/HttpPost.d.ts +130 -0
  45. package/dist/cjs/HttpPost.d.ts.map +1 -0
  46. package/dist/cjs/HttpPost.js +72 -0
  47. package/dist/cjs/HttpPost.js.map +7 -0
  48. package/dist/cjs/LanguageServer.d.ts +90 -0
  49. package/dist/cjs/LanguageServer.d.ts.map +1 -0
  50. package/dist/cjs/LanguageServer.js +60 -0
  51. package/dist/cjs/LanguageServer.js.map +7 -0
  52. package/dist/cjs/Ls.d.ts +164 -0
  53. package/dist/cjs/Ls.d.ts.map +1 -0
  54. package/dist/cjs/Ls.js +136 -0
  55. package/dist/cjs/Ls.js.map +7 -0
  56. package/dist/cjs/Lsp.d.ts +125 -0
  57. package/dist/cjs/Lsp.d.ts.map +1 -0
  58. package/dist/cjs/Lsp.js +137 -0
  59. package/dist/cjs/Lsp.js.map +7 -0
  60. package/dist/cjs/Manifest.d.ts +918 -0
  61. package/dist/cjs/Manifest.d.ts.map +1 -0
  62. package/dist/cjs/Manifest.js +144 -0
  63. package/dist/cjs/Manifest.js.map +7 -0
  64. package/dist/cjs/NativeSearch.d.ts +38 -0
  65. package/dist/cjs/NativeSearch.d.ts.map +1 -0
  66. package/dist/cjs/NativeSearch.js +326 -0
  67. package/dist/cjs/NativeSearch.js.map +7 -0
  68. package/dist/cjs/NodeLanguageServer.d.ts +128 -0
  69. package/dist/cjs/NodeLanguageServer.d.ts.map +1 -0
  70. package/dist/cjs/NodeLanguageServer.js +796 -0
  71. package/dist/cjs/NodeLanguageServer.js.map +7 -0
  72. package/dist/cjs/PortableSearch.d.ts +24 -0
  73. package/dist/cjs/PortableSearch.d.ts.map +1 -0
  74. package/dist/cjs/PortableSearch.js +233 -0
  75. package/dist/cjs/PortableSearch.js.map +7 -0
  76. package/dist/cjs/Probe.d.ts +193 -0
  77. package/dist/cjs/Probe.d.ts.map +1 -0
  78. package/dist/cjs/Probe.js +134 -0
  79. package/dist/cjs/Probe.js.map +7 -0
  80. package/dist/cjs/Read.d.ts +189 -0
  81. package/dist/cjs/Read.d.ts.map +1 -0
  82. package/dist/cjs/Read.js +223 -0
  83. package/dist/cjs/Read.js.map +7 -0
  84. package/dist/cjs/Relocate.d.ts +73 -0
  85. package/dist/cjs/Relocate.d.ts.map +1 -0
  86. package/dist/cjs/Relocate.js +72 -0
  87. package/dist/cjs/Relocate.js.map +7 -0
  88. package/dist/cjs/Search.d.ts +163 -0
  89. package/dist/cjs/Search.d.ts.map +1 -0
  90. package/dist/cjs/Search.js +51 -0
  91. package/dist/cjs/Search.js.map +7 -0
  92. package/dist/cjs/SearchConformance.d.ts +115 -0
  93. package/dist/cjs/SearchConformance.d.ts.map +1 -0
  94. package/dist/cjs/SearchConformance.js +172 -0
  95. package/dist/cjs/SearchConformance.js.map +7 -0
  96. package/dist/cjs/SearchContract.d.ts +114 -0
  97. package/dist/cjs/SearchContract.d.ts.map +1 -0
  98. package/dist/cjs/SearchContract.js +339 -0
  99. package/dist/cjs/SearchContract.js.map +7 -0
  100. package/dist/cjs/ShellCommand.d.ts +164 -0
  101. package/dist/cjs/ShellCommand.d.ts.map +1 -0
  102. package/dist/cjs/ShellCommand.js +102 -0
  103. package/dist/cjs/ShellCommand.js.map +7 -0
  104. package/dist/cjs/StdError.d.ts +55 -0
  105. package/dist/cjs/StdError.d.ts.map +1 -0
  106. package/dist/cjs/StdError.js +74 -0
  107. package/dist/cjs/StdError.js.map +7 -0
  108. package/dist/cjs/TestRun.d.ts +311 -0
  109. package/dist/cjs/TestRun.d.ts.map +1 -0
  110. package/dist/cjs/TestRun.js +228 -0
  111. package/dist/cjs/TestRun.js.map +7 -0
  112. package/dist/cjs/TestRunner.d.ts +102 -0
  113. package/dist/cjs/TestRunner.d.ts.map +1 -0
  114. package/dist/cjs/TestRunner.js +54 -0
  115. package/dist/cjs/TestRunner.js.map +7 -0
  116. package/dist/cjs/TreeFingerprint.d.ts +140 -0
  117. package/dist/cjs/TreeFingerprint.d.ts.map +1 -0
  118. package/dist/cjs/TreeFingerprint.js +87 -0
  119. package/dist/cjs/TreeFingerprint.js.map +7 -0
  120. package/dist/cjs/UpdatePlan.d.ts +152 -0
  121. package/dist/cjs/UpdatePlan.d.ts.map +1 -0
  122. package/dist/cjs/UpdatePlan.js +87 -0
  123. package/dist/cjs/UpdatePlan.js.map +7 -0
  124. package/dist/cjs/WebFetch.d.ts +134 -0
  125. package/dist/cjs/WebFetch.d.ts.map +1 -0
  126. package/dist/cjs/WebFetch.js +140 -0
  127. package/dist/cjs/WebFetch.js.map +7 -0
  128. package/dist/cjs/WebSearch.d.ts +181 -0
  129. package/dist/cjs/WebSearch.d.ts.map +1 -0
  130. package/dist/cjs/WebSearch.js +86 -0
  131. package/dist/cjs/WebSearch.js.map +7 -0
  132. package/dist/cjs/Write.d.ts +147 -0
  133. package/dist/cjs/Write.d.ts.map +1 -0
  134. package/dist/cjs/Write.js +122 -0
  135. package/dist/cjs/Write.js.map +7 -0
  136. package/dist/cjs/index.d.ts +127 -0
  137. package/dist/cjs/index.d.ts.map +1 -0
  138. package/dist/cjs/index.js +99 -0
  139. package/dist/cjs/index.js.map +7 -0
  140. package/dist/cjs/internal/ApplyPatch.d.ts +145 -0
  141. package/dist/cjs/internal/ApplyPatch.d.ts.map +1 -0
  142. package/dist/cjs/internal/ApplyPatch.js +462 -0
  143. package/dist/cjs/internal/ApplyPatch.js.map +7 -0
  144. package/dist/cjs/internal/CodexText.d.ts +73 -0
  145. package/dist/cjs/internal/CodexText.d.ts.map +1 -0
  146. package/dist/cjs/internal/CodexText.js +108 -0
  147. package/dist/cjs/internal/CodexText.js.map +7 -0
  148. package/dist/cjs/internal/Declaration.d.ts +49 -0
  149. package/dist/cjs/internal/Declaration.d.ts.map +1 -0
  150. package/dist/cjs/internal/Declaration.js +46 -0
  151. package/dist/cjs/internal/Declaration.js.map +7 -0
  152. package/dist/cjs/internal/Diagnostics.d.ts +77 -0
  153. package/dist/cjs/internal/Diagnostics.d.ts.map +1 -0
  154. package/dist/cjs/internal/Diagnostics.js +89 -0
  155. package/dist/cjs/internal/Diagnostics.js.map +7 -0
  156. package/dist/cjs/internal/EnvelopePrecheck.d.ts +67 -0
  157. package/dist/cjs/internal/EnvelopePrecheck.d.ts.map +1 -0
  158. package/dist/cjs/internal/EnvelopePrecheck.js +124 -0
  159. package/dist/cjs/internal/EnvelopePrecheck.js.map +7 -0
  160. package/dist/cjs/internal/Exec.d.ts +139 -0
  161. package/dist/cjs/internal/Exec.d.ts.map +1 -0
  162. package/dist/cjs/internal/Exec.js +158 -0
  163. package/dist/cjs/internal/Exec.js.map +7 -0
  164. package/dist/cjs/internal/FileMutation.d.ts +109 -0
  165. package/dist/cjs/internal/FileMutation.d.ts.map +1 -0
  166. package/dist/cjs/internal/FileMutation.js +116 -0
  167. package/dist/cjs/internal/FileMutation.js.map +7 -0
  168. package/dist/cjs/internal/FsFailure.d.ts +38 -0
  169. package/dist/cjs/internal/FsFailure.d.ts.map +1 -0
  170. package/dist/cjs/internal/FsFailure.js +40 -0
  171. package/dist/cjs/internal/FsFailure.js.map +7 -0
  172. package/dist/cjs/internal/GitWorktree.d.ts +98 -0
  173. package/dist/cjs/internal/GitWorktree.d.ts.map +1 -0
  174. package/dist/cjs/internal/GitWorktree.js +270 -0
  175. package/dist/cjs/internal/GitWorktree.js.map +7 -0
  176. package/dist/cjs/internal/Grouping.d.ts +51 -0
  177. package/dist/cjs/internal/Grouping.d.ts.map +1 -0
  178. package/dist/cjs/internal/Grouping.js +83 -0
  179. package/dist/cjs/internal/Grouping.js.map +7 -0
  180. package/dist/cjs/internal/Html.d.ts +20 -0
  181. package/dist/cjs/internal/Html.d.ts.map +1 -0
  182. package/dist/cjs/internal/Html.js +81 -0
  183. package/dist/cjs/internal/Html.js.map +7 -0
  184. package/dist/cjs/internal/Http.d.ts +95 -0
  185. package/dist/cjs/internal/Http.d.ts.map +1 -0
  186. package/dist/cjs/internal/Http.js +153 -0
  187. package/dist/cjs/internal/Http.js.map +7 -0
  188. package/dist/cjs/internal/HttpNetwork.d.ts +27 -0
  189. package/dist/cjs/internal/HttpNetwork.d.ts.map +1 -0
  190. package/dist/cjs/internal/HttpNetwork.js +146 -0
  191. package/dist/cjs/internal/HttpNetwork.js.map +7 -0
  192. package/dist/cjs/internal/Ignore.d.ts +37 -0
  193. package/dist/cjs/internal/Ignore.d.ts.map +1 -0
  194. package/dist/cjs/internal/Ignore.js +100 -0
  195. package/dist/cjs/internal/Ignore.js.map +7 -0
  196. package/dist/cjs/internal/LinearRegex.d.ts +19 -0
  197. package/dist/cjs/internal/LinearRegex.d.ts.map +1 -0
  198. package/dist/cjs/internal/LinearRegex.js +166 -0
  199. package/dist/cjs/internal/LinearRegex.js.map +7 -0
  200. package/dist/cjs/internal/Match.d.ts +85 -0
  201. package/dist/cjs/internal/Match.d.ts.map +1 -0
  202. package/dist/cjs/internal/Match.js +99 -0
  203. package/dist/cjs/internal/Match.js.map +7 -0
  204. package/dist/cjs/internal/Paths.d.ts +23 -0
  205. package/dist/cjs/internal/Paths.d.ts.map +1 -0
  206. package/dist/cjs/internal/Paths.js +52 -0
  207. package/dist/cjs/internal/Paths.js.map +7 -0
  208. package/dist/cjs/internal/Preserve.d.ts +25 -0
  209. package/dist/cjs/internal/Preserve.d.ts.map +1 -0
  210. package/dist/cjs/internal/Preserve.js +88 -0
  211. package/dist/cjs/internal/Preserve.js.map +7 -0
  212. package/dist/cjs/internal/Prune.d.ts +35 -0
  213. package/dist/cjs/internal/Prune.d.ts.map +1 -0
  214. package/dist/cjs/internal/Prune.js +54 -0
  215. package/dist/cjs/internal/Prune.js.map +7 -0
  216. package/dist/cjs/internal/SearchContract.d.ts +63 -0
  217. package/dist/cjs/internal/SearchContract.d.ts.map +1 -0
  218. package/dist/cjs/internal/SearchContract.js +46 -0
  219. package/dist/cjs/internal/SearchContract.js.map +7 -0
  220. package/dist/cjs/internal/Symbols.d.ts +39 -0
  221. package/dist/cjs/internal/Symbols.d.ts.map +1 -0
  222. package/dist/cjs/internal/Symbols.js +59 -0
  223. package/dist/cjs/internal/Symbols.js.map +7 -0
  224. package/dist/cjs/internal/TestReport.d.ts +52 -0
  225. package/dist/cjs/internal/TestReport.d.ts.map +1 -0
  226. package/dist/cjs/internal/TestReport.js +131 -0
  227. package/dist/cjs/internal/TestReport.js.map +7 -0
  228. package/dist/cjs/internal/Text.d.ts +114 -0
  229. package/dist/cjs/internal/Text.d.ts.map +1 -0
  230. package/dist/cjs/internal/Text.js +82 -0
  231. package/dist/cjs/internal/Text.js.map +7 -0
  232. package/dist/cjs/internal/Url.d.ts +13 -0
  233. package/dist/cjs/internal/Url.d.ts.map +1 -0
  234. package/dist/cjs/internal/Url.js +35 -0
  235. package/dist/cjs/internal/Url.js.map +7 -0
  236. package/dist/cjs/internal/Walk.d.ts +72 -0
  237. package/dist/cjs/internal/Walk.d.ts.map +1 -0
  238. package/dist/cjs/internal/Walk.js +108 -0
  239. package/dist/cjs/internal/Walk.js.map +7 -0
  240. package/dist/cjs/package.json +1 -0
  241. package/dist/esm/ApplyPatch.d.ts +174 -0
  242. package/dist/esm/ApplyPatch.d.ts.map +1 -0
  243. package/dist/esm/ApplyPatch.js +346 -0
  244. package/dist/esm/ApplyPatch.js.map +1 -0
  245. package/dist/esm/Bash.d.ts +304 -0
  246. package/dist/esm/Bash.d.ts.map +1 -0
  247. package/dist/esm/Bash.js +469 -0
  248. package/dist/esm/Bash.js.map +1 -0
  249. package/dist/esm/Checkpoints.d.ts +279 -0
  250. package/dist/esm/Checkpoints.d.ts.map +1 -0
  251. package/dist/esm/Checkpoints.js +298 -0
  252. package/dist/esm/Checkpoints.js.map +1 -0
  253. package/dist/esm/Container.d.ts +132 -0
  254. package/dist/esm/Container.d.ts.map +1 -0
  255. package/dist/esm/Container.js +151 -0
  256. package/dist/esm/Container.js.map +1 -0
  257. package/dist/esm/Edit.d.ts +203 -0
  258. package/dist/esm/Edit.d.ts.map +1 -0
  259. package/dist/esm/Edit.js +296 -0
  260. package/dist/esm/Edit.js.map +1 -0
  261. package/dist/esm/ExaWebSearch.d.ts +22 -0
  262. package/dist/esm/ExaWebSearch.d.ts.map +1 -0
  263. package/dist/esm/ExaWebSearch.js +107 -0
  264. package/dist/esm/ExaWebSearch.js.map +1 -0
  265. package/dist/esm/Explore.d.ts +328 -0
  266. package/dist/esm/Explore.d.ts.map +1 -0
  267. package/dist/esm/Explore.js +106 -0
  268. package/dist/esm/Explore.js.map +1 -0
  269. package/dist/esm/Fetch.d.ts +130 -0
  270. package/dist/esm/Fetch.d.ts.map +1 -0
  271. package/dist/esm/Fetch.js +91 -0
  272. package/dist/esm/Fetch.js.map +1 -0
  273. package/dist/esm/Glob.d.ts +204 -0
  274. package/dist/esm/Glob.d.ts.map +1 -0
  275. package/dist/esm/Glob.js +177 -0
  276. package/dist/esm/Glob.js.map +1 -0
  277. package/dist/esm/Grep.d.ts +347 -0
  278. package/dist/esm/Grep.d.ts.map +1 -0
  279. package/dist/esm/Grep.js +289 -0
  280. package/dist/esm/Grep.js.map +1 -0
  281. package/dist/esm/HttpPost.d.ts +130 -0
  282. package/dist/esm/HttpPost.d.ts.map +1 -0
  283. package/dist/esm/HttpPost.js +89 -0
  284. package/dist/esm/HttpPost.js.map +1 -0
  285. package/dist/esm/LanguageServer.d.ts +90 -0
  286. package/dist/esm/LanguageServer.d.ts.map +1 -0
  287. package/dist/esm/LanguageServer.js +57 -0
  288. package/dist/esm/LanguageServer.js.map +1 -0
  289. package/dist/esm/Ls.d.ts +164 -0
  290. package/dist/esm/Ls.d.ts.map +1 -0
  291. package/dist/esm/Ls.js +178 -0
  292. package/dist/esm/Ls.js.map +1 -0
  293. package/dist/esm/Lsp.d.ts +125 -0
  294. package/dist/esm/Lsp.d.ts.map +1 -0
  295. package/dist/esm/Lsp.js +165 -0
  296. package/dist/esm/Lsp.js.map +1 -0
  297. package/dist/esm/Manifest.d.ts +918 -0
  298. package/dist/esm/Manifest.d.ts.map +1 -0
  299. package/dist/esm/Manifest.js +153 -0
  300. package/dist/esm/Manifest.js.map +1 -0
  301. package/dist/esm/NativeSearch.d.ts +38 -0
  302. package/dist/esm/NativeSearch.d.ts.map +1 -0
  303. package/dist/esm/NativeSearch.js +378 -0
  304. package/dist/esm/NativeSearch.js.map +1 -0
  305. package/dist/esm/NodeLanguageServer.d.ts +128 -0
  306. package/dist/esm/NodeLanguageServer.d.ts.map +1 -0
  307. package/dist/esm/NodeLanguageServer.js +843 -0
  308. package/dist/esm/NodeLanguageServer.js.map +1 -0
  309. package/dist/esm/PortableSearch.d.ts +24 -0
  310. package/dist/esm/PortableSearch.d.ts.map +1 -0
  311. package/dist/esm/PortableSearch.js +240 -0
  312. package/dist/esm/PortableSearch.js.map +1 -0
  313. package/dist/esm/Probe.d.ts +193 -0
  314. package/dist/esm/Probe.d.ts.map +1 -0
  315. package/dist/esm/Probe.js +225 -0
  316. package/dist/esm/Probe.js.map +1 -0
  317. package/dist/esm/Read.d.ts +189 -0
  318. package/dist/esm/Read.d.ts.map +1 -0
  319. package/dist/esm/Read.js +300 -0
  320. package/dist/esm/Read.js.map +1 -0
  321. package/dist/esm/Relocate.d.ts +73 -0
  322. package/dist/esm/Relocate.d.ts.map +1 -0
  323. package/dist/esm/Relocate.js +153 -0
  324. package/dist/esm/Relocate.js.map +1 -0
  325. package/dist/esm/Search.d.ts +163 -0
  326. package/dist/esm/Search.d.ts.map +1 -0
  327. package/dist/esm/Search.js +47 -0
  328. package/dist/esm/Search.js.map +1 -0
  329. package/dist/esm/SearchConformance.d.ts +115 -0
  330. package/dist/esm/SearchConformance.d.ts.map +1 -0
  331. package/dist/esm/SearchConformance.js +193 -0
  332. package/dist/esm/SearchConformance.js.map +1 -0
  333. package/dist/esm/SearchContract.d.ts +114 -0
  334. package/dist/esm/SearchContract.d.ts.map +1 -0
  335. package/dist/esm/SearchContract.js +461 -0
  336. package/dist/esm/SearchContract.js.map +1 -0
  337. package/dist/esm/ShellCommand.d.ts +164 -0
  338. package/dist/esm/ShellCommand.d.ts.map +1 -0
  339. package/dist/esm/ShellCommand.js +159 -0
  340. package/dist/esm/ShellCommand.js.map +1 -0
  341. package/dist/esm/StdError.d.ts +55 -0
  342. package/dist/esm/StdError.d.ts.map +1 -0
  343. package/dist/esm/StdError.js +71 -0
  344. package/dist/esm/StdError.js.map +1 -0
  345. package/dist/esm/TestRun.d.ts +311 -0
  346. package/dist/esm/TestRun.d.ts.map +1 -0
  347. package/dist/esm/TestRun.js +316 -0
  348. package/dist/esm/TestRun.js.map +1 -0
  349. package/dist/esm/TestRunner.d.ts +102 -0
  350. package/dist/esm/TestRunner.d.ts.map +1 -0
  351. package/dist/esm/TestRunner.js +68 -0
  352. package/dist/esm/TestRunner.js.map +1 -0
  353. package/dist/esm/TreeFingerprint.d.ts +140 -0
  354. package/dist/esm/TreeFingerprint.d.ts.map +1 -0
  355. package/dist/esm/TreeFingerprint.js +170 -0
  356. package/dist/esm/TreeFingerprint.js.map +1 -0
  357. package/dist/esm/UpdatePlan.d.ts +152 -0
  358. package/dist/esm/UpdatePlan.d.ts.map +1 -0
  359. package/dist/esm/UpdatePlan.js +129 -0
  360. package/dist/esm/UpdatePlan.js.map +1 -0
  361. package/dist/esm/WebFetch.d.ts +134 -0
  362. package/dist/esm/WebFetch.d.ts.map +1 -0
  363. package/dist/esm/WebFetch.js +151 -0
  364. package/dist/esm/WebFetch.js.map +1 -0
  365. package/dist/esm/WebSearch.d.ts +181 -0
  366. package/dist/esm/WebSearch.d.ts.map +1 -0
  367. package/dist/esm/WebSearch.js +134 -0
  368. package/dist/esm/WebSearch.js.map +1 -0
  369. package/dist/esm/Write.d.ts +147 -0
  370. package/dist/esm/Write.d.ts.map +1 -0
  371. package/dist/esm/Write.js +144 -0
  372. package/dist/esm/Write.js.map +1 -0
  373. package/dist/esm/index.d.ts +127 -0
  374. package/dist/esm/index.d.ts.map +1 -0
  375. package/dist/esm/index.js +127 -0
  376. package/dist/esm/index.js.map +1 -0
  377. package/dist/esm/internal/ApplyPatch.d.ts +145 -0
  378. package/dist/esm/internal/ApplyPatch.d.ts.map +1 -0
  379. package/dist/esm/internal/ApplyPatch.js +489 -0
  380. package/dist/esm/internal/ApplyPatch.js.map +1 -0
  381. package/dist/esm/internal/CodexText.d.ts +73 -0
  382. package/dist/esm/internal/CodexText.d.ts.map +1 -0
  383. package/dist/esm/internal/CodexText.js +156 -0
  384. package/dist/esm/internal/CodexText.js.map +1 -0
  385. package/dist/esm/internal/Declaration.d.ts +49 -0
  386. package/dist/esm/internal/Declaration.d.ts.map +1 -0
  387. package/dist/esm/internal/Declaration.js +42 -0
  388. package/dist/esm/internal/Declaration.js.map +1 -0
  389. package/dist/esm/internal/Diagnostics.d.ts +77 -0
  390. package/dist/esm/internal/Diagnostics.d.ts.map +1 -0
  391. package/dist/esm/internal/Diagnostics.js +99 -0
  392. package/dist/esm/internal/Diagnostics.js.map +1 -0
  393. package/dist/esm/internal/EnvelopePrecheck.d.ts +67 -0
  394. package/dist/esm/internal/EnvelopePrecheck.d.ts.map +1 -0
  395. package/dist/esm/internal/EnvelopePrecheck.js +167 -0
  396. package/dist/esm/internal/EnvelopePrecheck.js.map +1 -0
  397. package/dist/esm/internal/Exec.d.ts +139 -0
  398. package/dist/esm/internal/Exec.d.ts.map +1 -0
  399. package/dist/esm/internal/Exec.js +193 -0
  400. package/dist/esm/internal/Exec.js.map +1 -0
  401. package/dist/esm/internal/FileMutation.d.ts +109 -0
  402. package/dist/esm/internal/FileMutation.d.ts.map +1 -0
  403. package/dist/esm/internal/FileMutation.js +123 -0
  404. package/dist/esm/internal/FileMutation.js.map +1 -0
  405. package/dist/esm/internal/FsFailure.d.ts +38 -0
  406. package/dist/esm/internal/FsFailure.d.ts.map +1 -0
  407. package/dist/esm/internal/FsFailure.js +39 -0
  408. package/dist/esm/internal/FsFailure.js.map +1 -0
  409. package/dist/esm/internal/GitWorktree.d.ts +98 -0
  410. package/dist/esm/internal/GitWorktree.d.ts.map +1 -0
  411. package/dist/esm/internal/GitWorktree.js +345 -0
  412. package/dist/esm/internal/GitWorktree.js.map +1 -0
  413. package/dist/esm/internal/Grouping.d.ts +51 -0
  414. package/dist/esm/internal/Grouping.d.ts.map +1 -0
  415. package/dist/esm/internal/Grouping.js +99 -0
  416. package/dist/esm/internal/Grouping.js.map +1 -0
  417. package/dist/esm/internal/Html.d.ts +20 -0
  418. package/dist/esm/internal/Html.d.ts.map +1 -0
  419. package/dist/esm/internal/Html.js +70 -0
  420. package/dist/esm/internal/Html.js.map +1 -0
  421. package/dist/esm/internal/Http.d.ts +95 -0
  422. package/dist/esm/internal/Http.d.ts.map +1 -0
  423. package/dist/esm/internal/Http.js +154 -0
  424. package/dist/esm/internal/Http.js.map +1 -0
  425. package/dist/esm/internal/HttpNetwork.d.ts +27 -0
  426. package/dist/esm/internal/HttpNetwork.d.ts.map +1 -0
  427. package/dist/esm/internal/HttpNetwork.js +114 -0
  428. package/dist/esm/internal/HttpNetwork.js.map +1 -0
  429. package/dist/esm/internal/Ignore.d.ts +37 -0
  430. package/dist/esm/internal/Ignore.d.ts.map +1 -0
  431. package/dist/esm/internal/Ignore.js +128 -0
  432. package/dist/esm/internal/Ignore.js.map +1 -0
  433. package/dist/esm/internal/LinearRegex.d.ts +19 -0
  434. package/dist/esm/internal/LinearRegex.d.ts.map +1 -0
  435. package/dist/esm/internal/LinearRegex.js +176 -0
  436. package/dist/esm/internal/LinearRegex.js.map +1 -0
  437. package/dist/esm/internal/Match.d.ts +85 -0
  438. package/dist/esm/internal/Match.d.ts.map +1 -0
  439. package/dist/esm/internal/Match.js +142 -0
  440. package/dist/esm/internal/Match.js.map +1 -0
  441. package/dist/esm/internal/Paths.d.ts +23 -0
  442. package/dist/esm/internal/Paths.d.ts.map +1 -0
  443. package/dist/esm/internal/Paths.js +40 -0
  444. package/dist/esm/internal/Paths.js.map +1 -0
  445. package/dist/esm/internal/Preserve.d.ts +25 -0
  446. package/dist/esm/internal/Preserve.d.ts.map +1 -0
  447. package/dist/esm/internal/Preserve.js +70 -0
  448. package/dist/esm/internal/Preserve.js.map +1 -0
  449. package/dist/esm/internal/Prune.d.ts +35 -0
  450. package/dist/esm/internal/Prune.d.ts.map +1 -0
  451. package/dist/esm/internal/Prune.js +60 -0
  452. package/dist/esm/internal/Prune.js.map +1 -0
  453. package/dist/esm/internal/SearchContract.d.ts +63 -0
  454. package/dist/esm/internal/SearchContract.d.ts.map +1 -0
  455. package/dist/esm/internal/SearchContract.js +66 -0
  456. package/dist/esm/internal/SearchContract.js.map +1 -0
  457. package/dist/esm/internal/Symbols.d.ts +39 -0
  458. package/dist/esm/internal/Symbols.d.ts.map +1 -0
  459. package/dist/esm/internal/Symbols.js +79 -0
  460. package/dist/esm/internal/Symbols.js.map +1 -0
  461. package/dist/esm/internal/TestReport.d.ts +52 -0
  462. package/dist/esm/internal/TestReport.d.ts.map +1 -0
  463. package/dist/esm/internal/TestReport.js +172 -0
  464. package/dist/esm/internal/TestReport.js.map +1 -0
  465. package/dist/esm/internal/Text.d.ts +114 -0
  466. package/dist/esm/internal/Text.d.ts.map +1 -0
  467. package/dist/esm/internal/Text.js +130 -0
  468. package/dist/esm/internal/Text.js.map +1 -0
  469. package/dist/esm/internal/Url.d.ts +13 -0
  470. package/dist/esm/internal/Url.d.ts.map +1 -0
  471. package/dist/esm/internal/Url.js +27 -0
  472. package/dist/esm/internal/Url.js.map +1 -0
  473. package/dist/esm/internal/Walk.d.ts +72 -0
  474. package/dist/esm/internal/Walk.d.ts.map +1 -0
  475. package/dist/esm/internal/Walk.js +126 -0
  476. package/dist/esm/internal/Walk.js.map +1 -0
  477. package/docs/README.md +117 -0
  478. package/docs/api.md +472 -0
  479. package/docs/concepts/effects-and-capabilities.md +136 -0
  480. package/docs/concepts/flows-and-handlers.md +115 -0
  481. package/docs/concepts/limits-and-disclosure.md +102 -0
  482. package/docs/concepts/search-contract.md +182 -0
  483. package/docs/guides/bind-the-standard-flows.md +114 -0
  484. package/docs/guides/implement-a-search-peer.md +133 -0
  485. package/docs/guides/pin-a-checkpoint.md +141 -0
  486. package/docs/guides/query-a-language-server.md +257 -0
  487. package/docs/guides/reach-the-network.md +141 -0
  488. package/docs/guides/read-and-edit-a-file.md +240 -0
  489. package/docs/guides/run-a-shell-command.md +215 -0
  490. package/docs/guides/run-the-test-suite.md +154 -0
  491. package/docs/guides/search-a-workspace.md +148 -0
  492. package/docs/installation.md +111 -0
  493. package/docs/quickstart.md +125 -0
  494. package/docs/reference/flows.md +556 -0
  495. package/docs/troubleshooting.md +322 -0
  496. package/package.json +439 -3
  497. package/src/ApplyPatch.ts +458 -0
  498. package/src/Bash.ts +549 -0
  499. package/src/Checkpoints.ts +422 -0
  500. package/src/Container.ts +212 -0
  501. package/src/Edit.ts +366 -0
  502. package/src/ExaWebSearch.ts +145 -0
  503. package/src/Explore.ts +139 -0
  504. package/src/Fetch.ts +117 -0
  505. package/src/Glob.ts +200 -0
  506. package/src/Grep.ts +320 -0
  507. package/src/HttpPost.ts +120 -0
  508. package/src/LanguageServer.ts +110 -0
  509. package/src/Ls.ts +228 -0
  510. package/src/Lsp.ts +184 -0
  511. package/src/Manifest.ts +162 -0
  512. package/src/NativeSearch.ts +457 -0
  513. package/src/NodeLanguageServer.ts +1148 -0
  514. package/src/PortableSearch.ts +264 -0
  515. package/src/Probe.ts +284 -0
  516. package/src/Read.ts +359 -0
  517. package/src/Relocate.ts +166 -0
  518. package/src/Search.ts +185 -0
  519. package/src/SearchConformance.ts +288 -0
  520. package/src/SearchContract.ts +489 -0
  521. package/src/ShellCommand.ts +201 -0
  522. package/src/StdError.ts +80 -0
  523. package/src/TestRun.ts +401 -0
  524. package/src/TestRunner.ts +119 -0
  525. package/src/TreeFingerprint.ts +200 -0
  526. package/src/UpdatePlan.ts +171 -0
  527. package/src/WebFetch.ts +194 -0
  528. package/src/WebSearch.ts +165 -0
  529. package/src/Write.ts +195 -0
  530. package/src/index.ts +154 -0
  531. package/src/internal/ApplyPatch.ts +601 -0
  532. package/src/internal/CodexText.ts +182 -0
  533. package/src/internal/Declaration.ts +60 -0
  534. package/src/internal/Diagnostics.ts +134 -0
  535. package/src/internal/EnvelopePrecheck.ts +233 -0
  536. package/src/internal/Exec.ts +314 -0
  537. package/src/internal/FileMutation.ts +231 -0
  538. package/src/internal/FsFailure.ts +51 -0
  539. package/src/internal/GitWorktree.ts +473 -0
  540. package/src/internal/Grouping.ts +106 -0
  541. package/src/internal/Html.ts +87 -0
  542. package/src/internal/Http.ts +209 -0
  543. package/src/internal/HttpNetwork.ts +153 -0
  544. package/src/internal/Ignore.ts +135 -0
  545. package/src/internal/LinearRegex.ts +173 -0
  546. package/src/internal/Match.ts +172 -0
  547. package/src/internal/Paths.ts +42 -0
  548. package/src/internal/Preserve.ts +108 -0
  549. package/src/internal/Prune.ts +62 -0
  550. package/src/internal/SearchContract.ts +77 -0
  551. package/src/internal/Symbols.ts +88 -0
  552. package/src/internal/TestReport.ts +194 -0
  553. package/src/internal/Text.ts +170 -0
  554. package/src/internal/Url.ts +23 -0
  555. package/src/internal/Walk.ts +176 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Walk.d.ts","sourceRoot":"","sources":["../../../src/internal/Walk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAK/C;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAwC,CAAA;AAa3F;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,MAAM,EAAE,IAAI,MAAM,KAAG,MAG9E,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,YAAY,UAAU,CAAC,UAAU,EACjC,YAAY,aAAa,CAAC,MAAM,CAAC,KAChC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAKpC,CAAA;AAEH;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,GAChB,YAAY,UAAU,CAAC,UAAU,EACjC,MAAM,IAAI,CAAC,IAAI,EACf,MAAM,MAAM,EACZ,QAAQ,OAAO,EACf,kBAAgB,EAChB,WAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAoB,KACrE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAmEtC,CAAA"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Walk_exports = {};
30
+ __export(Walk_exports, {
31
+ files: () => files,
32
+ relativeForPattern: () => relativeForPattern,
33
+ skippedDirectories: () => skippedDirectories,
34
+ symbolicLinks: () => symbolicLinks
35
+ });
36
+ module.exports = __toCommonJS(Walk_exports);
37
+ var import_effect = require("effect");
38
+ var Ignore = __toESM(require("./Ignore.js"), 1);
39
+ var Prune = __toESM(require("./Prune.js"), 1);
40
+ var import_SearchContract = require("./SearchContract.js");
41
+ const skippedDirectories = new Set(Prune.repositoryDirectories);
42
+ const concurrency = 16;
43
+ const relativeForPattern = (path, from, to) => {
44
+ const relative = path.relative(from, to);
45
+ return path.sep === "\\" ? relative.replaceAll("\\", "/") : relative;
46
+ };
47
+ const symbolicLinks = (fileSystem, candidates) => import_effect.Effect.forEach(
48
+ candidates,
49
+ (candidate) => fileSystem.readLink(candidate).pipe(import_effect.Effect.as(true), import_effect.Effect.orElseSucceed(() => false)),
50
+ { concurrency }
51
+ );
52
+ const files = (fileSystem, path, root, hidden, noIgnore = false, included = () => true) => import_effect.Effect.gen(function* () {
53
+ const info = yield* fileSystem.stat(root).pipe(import_effect.Effect.mapError((error) => (0, import_SearchContract.rootFailure)(root, error)));
54
+ if (info.type === "File") return { explicitFile: true, files: [path.normalize(root)], ignored: false };
55
+ const files2 = [];
56
+ let excluded = false;
57
+ const directories = [{
58
+ directory: root,
59
+ scopes: []
60
+ }];
61
+ while (directories.length > 0) {
62
+ const next = directories.pop();
63
+ const { directory } = next;
64
+ let scopes = next.scopes;
65
+ const children = yield* fileSystem.readDirectory(directory).pipe(
66
+ import_effect.Effect.catch(
67
+ (error) => directory === root ? import_effect.Effect.fail((0, import_SearchContract.rootFailure)(directory, error)) : import_effect.Effect.succeed([])
68
+ )
69
+ );
70
+ if (!noIgnore && children.includes(".gitignore")) {
71
+ const content = yield* fileSystem.readFileString(path.join(directory, ".gitignore")).pipe(
72
+ import_effect.Effect.orElseSucceed(() => "")
73
+ );
74
+ const scope = Ignore.parse(directory, content);
75
+ if (scope.rules.length > 0) scopes = [...scopes, scope];
76
+ }
77
+ const candidates = children.filter((child) => !skippedDirectories.has(child) && (hidden || !child.startsWith("."))).map((child) => path.join(directory, child));
78
+ const entries = yield* import_effect.Effect.forEach(candidates, (candidate) => fileSystem.stat(candidate).pipe(
79
+ import_effect.Effect.map((candidateInfo) => ({
80
+ candidate,
81
+ type: candidateInfo.type
82
+ })),
83
+ import_effect.Effect.orElseSucceed(() => ({ candidate, type: void 0 }))
84
+ ), { concurrency });
85
+ const nested = [];
86
+ for (const entry of entries) {
87
+ if (entry.type !== void 0 && Ignore.ignored(
88
+ scopes,
89
+ entry.candidate,
90
+ path.basename(entry.candidate),
91
+ entry.type === "Directory",
92
+ (from, to) => relativeForPattern(path, from, to)
93
+ )) {
94
+ if (entry.type === "Directory" || included(relativeForPattern(path, root, entry.candidate), path.basename(entry.candidate))) excluded = true;
95
+ continue;
96
+ }
97
+ if (entry.type === "Directory") nested.push(entry.candidate);
98
+ else if (entry.type === "File") files2.push(path.normalize(entry.candidate));
99
+ }
100
+ const links = yield* symbolicLinks(fileSystem, nested);
101
+ for (let index = 0; index < nested.length; index++) {
102
+ const candidate = nested[index];
103
+ if (links[index] !== true) directories.push({ directory: candidate, scopes });
104
+ }
105
+ }
106
+ return { explicitFile: false, files: files2.sort(), ignored: excluded };
107
+ });
108
+ //# sourceMappingURL=Walk.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/Walk.ts"],
4
+ "sourcesContent": ["/**\n * The directory names a repository walk never descends into.\n *\n * `grep` and `glob` walk with the kernel filesystem, and every entry costs a\n * guarded stat. A walk rooted at \".\" that descends into `.git` visits tens of\n * thousands of object files no search wants: one such `grep` held a benchmark\n * frame for its entire fifteen-minute ceiling. The skip set is the same\n * convention ripgrep ships \u2014 version control, dependency trees, and caches \u2014\n * and an explicit root inside a skipped directory still walks, because\n * skipping applies to descent, never to what the caller named.\n *\n * @since 1.0.0\n */\n\nimport type * as Path from \"@smthrs/kernel/Path\"\nimport { Effect } from \"effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport type * as StdError from \"../StdError.ts\"\nimport * as Ignore from \"./Ignore.ts\"\nimport * as Prune from \"./Prune.ts\"\nimport { rootFailure } from \"./SearchContract.ts\"\n\n/**\n * Directory basenames excluded from recursive descent.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const skippedDirectories: ReadonlySet<string> = new Set(Prune.repositoryDirectories)\n\n/**\n * How many filesystem questions one directory level asks at a time.\n *\n * A metadata call through the layer costs far more in fiber scheduling than in\n * kernel time, so asking one entry at a time is what makes a walk slow: the\n * same probe measured 28.8 \u00B5s sequentially and 6.0 \u00B5s at this width on the\n * SWE-bench pytest tree. The bound keeps the file-descriptor and thread-pool\n * pressure of a wide directory predictable.\n */\nconst concurrency = 16\n\n/**\n * Separates pattern path segments with slashes while preserving POSIX filenames.\n *\n * @private\n * @since 1.0.0\n */\nexport const relativeForPattern = (path: Path.Path, from: string, to: string): string => {\n const relative = path.relative(from, to)\n return path.sep === \"\\\\\" ? relative.replaceAll(\"\\\\\", \"/\") : relative\n}\n\n/**\n * Answers whether each path is a symbolic link, which neither peer follows.\n *\n * `FileSystem.stat` resolves links, so the only probe available is `readLink`,\n * and every probe is one more call in a loop that already makes one per entry.\n * The walk therefore probes directories, where following a link would duplicate\n * a subtree or loop forever, and the callers probe the far smaller set of files\n * they are about to report \u2014 batched, never one at a time.\n *\n * @private\n * @since 1.0.0\n */\nexport const symbolicLinks = (\n fileSystem: FileSystem.FileSystem,\n candidates: ReadonlyArray<string>\n): Effect.Effect<ReadonlyArray<boolean>> =>\n Effect.forEach(\n candidates,\n (candidate) => fileSystem.readLink(candidate).pipe(Effect.as(true), Effect.orElseSucceed(() => false)),\n { concurrency }\n )\n\n/**\n * One walk: admitted files, explicit-root status, and ignore exclusions.\n *\n * @private\n * @since 1.0.0\n */\nexport interface Walked {\n readonly ignored: boolean\n readonly explicitFile: boolean\n readonly files: ReadonlyArray<string>\n}\n\n/**\n * Lists the files a search under `root` reaches.\n *\n * Only the root the caller named is allowed to fail the walk. Every entry\n * below it that the process cannot inspect \u2014 a dangling symlink, a symlink\n * loop, a directory it may not list \u2014 is skipped and the walk continues, which\n * is what `rg --no-messages` does with the same tree. Turning one of those into\n * a typed failure would make a whole repository unsearchable because of one\n * link, and would answer differently from the native peer. Only .gitignore\n * files within this root are read; ignored directories are never descended.\n * `included` narrows the empty-result diagnostic without changing descent.\n *\n * @private\n * @since 1.0.0\n */\nexport const files = (\n fileSystem: FileSystem.FileSystem,\n path: Path.Path,\n root: string,\n hidden: boolean,\n noIgnore = false,\n included: (relative: string, basename: string) => boolean = () => true\n): Effect.Effect<Walked, StdError.StdError> =>\n Effect.gen(function*() {\n const info = yield* fileSystem.stat(root).pipe(Effect.mapError((error) => rootFailure(root, error)))\n if (info.type === \"File\") return { explicitFile: true, files: [path.normalize(root)], ignored: false }\n const files: Array<string> = []\n let excluded = false\n const directories: Array<{ directory: string; scopes: ReadonlyArray<Ignore.Scope> }> = [{\n directory: root,\n scopes: []\n }]\n while (directories.length > 0) {\n const next = directories.pop()!\n const { directory } = next\n let scopes = next.scopes\n const children: ReadonlyArray<string> = yield* fileSystem.readDirectory(directory).pipe(\n Effect.catch((error) =>\n directory === root\n ? Effect.fail(rootFailure(directory, error))\n : Effect.succeed<ReadonlyArray<string>>([])\n )\n )\n if (!noIgnore && children.includes(\".gitignore\")) {\n const content = yield* fileSystem.readFileString(path.join(directory, \".gitignore\")).pipe(\n Effect.orElseSucceed(() => \"\")\n )\n const scope = Ignore.parse(directory, content)\n if (scope.rules.length > 0) scopes = [...scopes, scope]\n }\n const candidates = children\n .filter((child) => !skippedDirectories.has(child) && (hidden || !child.startsWith(\".\")))\n .map((child) => path.join(directory, child))\n const entries = yield* Effect.forEach(candidates, (candidate) =>\n fileSystem.stat(candidate).pipe(\n Effect.map((candidateInfo): { readonly candidate: string; readonly type: string | undefined } => ({\n candidate,\n type: candidateInfo.type\n })),\n Effect.orElseSucceed(() => ({ candidate, type: undefined }))\n ), { concurrency })\n const nested: Array<string> = []\n for (const entry of entries) {\n if (\n entry.type !== undefined &&\n Ignore.ignored(\n scopes,\n entry.candidate,\n path.basename(entry.candidate),\n entry.type === \"Directory\",\n (from, to) => relativeForPattern(path, from, to)\n )\n ) {\n if (\n entry.type === \"Directory\" ||\n included(relativeForPattern(path, root, entry.candidate), path.basename(entry.candidate))\n ) excluded = true\n continue\n }\n if (entry.type === \"Directory\") nested.push(entry.candidate)\n else if (entry.type === \"File\") files.push(path.normalize(entry.candidate))\n }\n const links = yield* symbolicLinks(fileSystem, nested)\n for (let index = 0; index < nested.length; index++) {\n const candidate = nested[index]!\n if (links[index] !== true) directories.push({ directory: candidate, scopes })\n }\n }\n return { explicitFile: false, files: files.sort(), ignored: excluded }\n })\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,oBAAuB;AAGvB,aAAwB;AACxB,YAAuB;AACvB,4BAA4B;AAQrB,MAAM,qBAA0C,IAAI,IAAI,MAAM,qBAAqB;AAW1F,MAAM,cAAc;AAQb,MAAM,qBAAqB,CAAC,MAAiB,MAAc,OAAuB;AACvF,QAAM,WAAW,KAAK,SAAS,MAAM,EAAE;AACvC,SAAO,KAAK,QAAQ,OAAO,SAAS,WAAW,MAAM,GAAG,IAAI;AAC9D;AAcO,MAAM,gBAAgB,CAC3B,YACA,eAEA,qBAAO;AAAA,EACL;AAAA,EACA,CAAC,cAAc,WAAW,SAAS,SAAS,EAAE,KAAK,qBAAO,GAAG,IAAI,GAAG,qBAAO,cAAc,MAAM,KAAK,CAAC;AAAA,EACrG,EAAE,YAAY;AAChB;AA6BK,MAAM,QAAQ,CACnB,YACA,MACA,MACA,QACA,WAAW,OACX,WAA4D,MAAM,SAElE,qBAAO,IAAI,aAAY;AACrB,QAAM,OAAO,OAAO,WAAW,KAAK,IAAI,EAAE,KAAK,qBAAO,SAAS,CAAC,cAAU,mCAAY,MAAM,KAAK,CAAC,CAAC;AACnG,MAAI,KAAK,SAAS,OAAQ,QAAO,EAAE,cAAc,MAAM,OAAO,CAAC,KAAK,UAAU,IAAI,CAAC,GAAG,SAAS,MAAM;AACrG,QAAMA,SAAuB,CAAC;AAC9B,MAAI,WAAW;AACf,QAAM,cAAiF,CAAC;AAAA,IACtF,WAAW;AAAA,IACX,QAAQ,CAAC;AAAA,EACX,CAAC;AACD,SAAO,YAAY,SAAS,GAAG;AAC7B,UAAM,OAAO,YAAY,IAAI;AAC7B,UAAM,EAAE,UAAU,IAAI;AACtB,QAAI,SAAS,KAAK;AAClB,UAAM,WAAkC,OAAO,WAAW,cAAc,SAAS,EAAE;AAAA,MACjF,qBAAO;AAAA,QAAM,CAAC,UACZ,cAAc,OACV,qBAAO,SAAK,mCAAY,WAAW,KAAK,CAAC,IACzC,qBAAO,QAA+B,CAAC,CAAC;AAAA,MAC9C;AAAA,IACF;AACA,QAAI,CAAC,YAAY,SAAS,SAAS,YAAY,GAAG;AAChD,YAAM,UAAU,OAAO,WAAW,eAAe,KAAK,KAAK,WAAW,YAAY,CAAC,EAAE;AAAA,QACnF,qBAAO,cAAc,MAAM,EAAE;AAAA,MAC/B;AACA,YAAM,QAAQ,OAAO,MAAM,WAAW,OAAO;AAC7C,UAAI,MAAM,MAAM,SAAS,EAAG,UAAS,CAAC,GAAG,QAAQ,KAAK;AAAA,IACxD;AACA,UAAM,aAAa,SAChB,OAAO,CAAC,UAAU,CAAC,mBAAmB,IAAI,KAAK,MAAM,UAAU,CAAC,MAAM,WAAW,GAAG,EAAE,EACtF,IAAI,CAAC,UAAU,KAAK,KAAK,WAAW,KAAK,CAAC;AAC7C,UAAM,UAAU,OAAO,qBAAO,QAAQ,YAAY,CAAC,cACjD,WAAW,KAAK,SAAS,EAAE;AAAA,MACzB,qBAAO,IAAI,CAAC,mBAAsF;AAAA,QAChG;AAAA,QACA,MAAM,cAAc;AAAA,MACtB,EAAE;AAAA,MACF,qBAAO,cAAc,OAAO,EAAE,WAAW,MAAM,OAAU,EAAE;AAAA,IAC7D,GAAG,EAAE,YAAY,CAAC;AACpB,UAAM,SAAwB,CAAC;AAC/B,eAAW,SAAS,SAAS;AAC3B,UACE,MAAM,SAAS,UACf,OAAO;AAAA,QACL;AAAA,QACA,MAAM;AAAA,QACN,KAAK,SAAS,MAAM,SAAS;AAAA,QAC7B,MAAM,SAAS;AAAA,QACf,CAAC,MAAM,OAAO,mBAAmB,MAAM,MAAM,EAAE;AAAA,MACjD,GACA;AACA,YACE,MAAM,SAAS,eACf,SAAS,mBAAmB,MAAM,MAAM,MAAM,SAAS,GAAG,KAAK,SAAS,MAAM,SAAS,CAAC,EACxF,YAAW;AACb;AAAA,MACF;AACA,UAAI,MAAM,SAAS,YAAa,QAAO,KAAK,MAAM,SAAS;AAAA,eAClD,MAAM,SAAS,OAAQ,CAAAA,OAAM,KAAK,KAAK,UAAU,MAAM,SAAS,CAAC;AAAA,IAC5E;AACA,UAAM,QAAQ,OAAO,cAAc,YAAY,MAAM;AACrD,aAAS,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;AAClD,YAAM,YAAY,OAAO,KAAK;AAC9B,UAAI,MAAM,KAAK,MAAM,KAAM,aAAY,KAAK,EAAE,WAAW,WAAW,OAAO,CAAC;AAAA,IAC9E;AAAA,EACF;AACA,SAAO,EAAE,cAAc,OAAO,OAAOA,OAAM,KAAK,GAAG,SAAS,SAAS;AACvE,CAAC;",
6
+ "names": ["files"]
7
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * apply_patch flow declaration and portable handler.
3
+ *
4
+ * A Codex CLI clone: the V4A patch grammar (`*** Begin Patch` /
5
+ * `*** Add File:` / `*** Update File:` / `*** Delete File:` /
6
+ * `*** End Patch`), the fuzzy context-matching applier, and Codex's error
7
+ * and summary text, expressed as a flow over the kernel filesystem.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ import * as Effect from "effect/Effect";
12
+ import * as FileSystem from "effect/FileSystem";
13
+ import * as Schema from "effect/Schema";
14
+ import * as StdError from "./StdError.ts";
15
+ /**
16
+ * Registry name for the apply_patch flow. Matches the Codex CLI tool name.
17
+ *
18
+ * @category identifiers
19
+ * @since 1.0.0
20
+ */
21
+ export declare const name = "apply_patch";
22
+ /**
23
+ * Model-facing description of the apply_patch flow. Matches the Codex CLI
24
+ * freeform tool description.
25
+ *
26
+ * @category descriptions
27
+ * @since 1.0.0
28
+ */
29
+ export declare const description = "The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.";
30
+ /**
31
+ * Input schema for the apply_patch flow.
32
+ *
33
+ * Codex delivers the patch as freeform text; the JSON function fallback uses
34
+ * a single `input` field, which is the shape cloned here.
35
+ *
36
+ * @category schemas
37
+ * @since 1.0.0
38
+ */
39
+ export declare const Input: Schema.Struct<{
40
+ readonly input: Schema.String;
41
+ }>;
42
+ /**
43
+ * Decoded input accepted by the `apply_patch` flow.
44
+ *
45
+ * @category models
46
+ * @since 1.0.0
47
+ */
48
+ export type Input = typeof Input.Type;
49
+ /**
50
+ * Output schema for the apply_patch flow.
51
+ *
52
+ * @category schemas
53
+ * @since 1.0.0
54
+ */
55
+ export declare const Output: Schema.Struct<{
56
+ readonly output: Schema.String;
57
+ readonly added: Schema.$Array<Schema.String>;
58
+ readonly modified: Schema.$Array<Schema.String>;
59
+ readonly deleted: Schema.$Array<Schema.String>;
60
+ }>;
61
+ /**
62
+ * Decoded output returned by the `apply_patch` flow.
63
+ *
64
+ * @category models
65
+ * @since 1.0.0
66
+ */
67
+ export type Output = typeof Output.Type;
68
+ /**
69
+ * Static conservative effect envelope for the apply_patch flow.
70
+ *
71
+ * @category effects
72
+ * @since 1.0.0
73
+ */
74
+ export declare const effects: import("@smthrs/plan/Effects").Declaration;
75
+ /**
76
+ * Narrows the effect envelope for a decoded invocation.
77
+ *
78
+ * A patch names its files inside its own text rather than in a decoded field,
79
+ * and the parse that finds them is the same parse that can fail, so there is
80
+ * nothing here to narrow before the handler runs: the static envelope is the
81
+ * honest answer.
82
+ *
83
+ * @category effects
84
+ * @since 1.0.0
85
+ */
86
+ export declare const effectsFor: (_input: typeof Input.Type) => import("@smthrs/plan/Effects").Declaration;
87
+ /**
88
+ * Capabilities required by the apply_patch flow.
89
+ *
90
+ * @category capabilities
91
+ * @since 1.0.0
92
+ */
93
+ export declare const capabilities: string[];
94
+ /**
95
+ * Declaration-only apply_patch flow.
96
+ *
97
+ * @category flows
98
+ * @since 1.0.0
99
+ */
100
+ export declare const flow: {
101
+ readonly name: "apply_patch";
102
+ readonly description: "The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.";
103
+ readonly input: Schema.Struct<{
104
+ readonly input: Schema.String;
105
+ }>;
106
+ readonly output: Schema.Struct<{
107
+ readonly output: Schema.String;
108
+ readonly added: Schema.$Array<Schema.String>;
109
+ readonly modified: Schema.$Array<Schema.String>;
110
+ readonly deleted: Schema.$Array<Schema.String>;
111
+ }>;
112
+ readonly capabilities: string[];
113
+ readonly effects: import("@smthrs/plan/Effects").Declaration;
114
+ };
115
+ /**
116
+ * What a call to this flow does, for a reader of a run.
117
+ *
118
+ * Display metadata only. `@smthrs/registry` `Descriptor.FlowActivity` is the
119
+ * governing vocabulary and `StandardFlows` binds this value onto the flow's
120
+ * descriptor, where the binding site checks it. `declarationDigest` excludes
121
+ * it, so declaring it cannot invalidate a call identity or a cached prompt.
122
+ *
123
+ * @category presentation
124
+ * @since 1.0.0-rc.0
125
+ */
126
+ export declare const activity: "writes";
127
+ /**
128
+ * How one recorded call to this flow reads: the verb for each settlement, the
129
+ * input field that is its subject, and the measured output fields a one-line
130
+ * summary may count.
131
+ *
132
+ * Display metadata only, governed by `@smthrs/registry`
133
+ * `Descriptor.CallPresentation` and checked where `StandardFlows` binds it.
134
+ *
135
+ * @category presentation
136
+ * @since 1.0.0-rc.0
137
+ */
138
+ export declare const presentation: {
139
+ readonly verb: {
140
+ readonly pending: "patching";
141
+ readonly success: "patched";
142
+ readonly failure: "failed to patch";
143
+ };
144
+ readonly subject: "patch";
145
+ readonly result: "patch";
146
+ };
147
+ /**
148
+ * Every path a patch writes, in the order it names them, including a move's
149
+ * destination. The patch is read by the parser {@link run} uses, so a header
150
+ * `run` accepts is never missed.
151
+ *
152
+ * Returns `undefined` when `run` would refuse the patch. A caller asking
153
+ * permission for the call then asks for everything the flow declares.
154
+ *
155
+ * @category parsing
156
+ * @since 1.0.0-rc.1
157
+ */
158
+ export declare const paths: (patch: string) => ReadonlyArray<string> | undefined;
159
+ /**
160
+ * Parses and applies a V4A patch through the permission-aware kernel
161
+ * filesystem, preserving Codex error text.
162
+ *
163
+ * @category handlers
164
+ * @since 1.0.0
165
+ */
166
+ export declare const run: (input: {
167
+ readonly input: string;
168
+ }) => Effect.Effect<{
169
+ readonly output: string;
170
+ readonly added: readonly string[];
171
+ readonly modified: readonly string[];
172
+ readonly deleted: readonly string[];
173
+ }, StdError.StdError, import("effect/Path").Path | FileSystem.FileSystem>;
174
+ //# sourceMappingURL=ApplyPatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplyPatch.d.ts","sourceRoot":"","sources":["../../src/ApplyPatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAOvC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,IAAI,gBAAgB,CAAA;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,iHACwF,CAAA;AAEhH;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK;;EAEhB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,MAAM;;;;;EAOjB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAA;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,4CAAuF,CAAA;AAE3G;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,OAAO,KAAK,CAAC,IAAI,+CAAY,CAAA;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAgE,CAAA;AAEzF;;;;;GAKG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;CAAsF,CAAA;AAEvG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,EAAG,QAAiB,CAAA;AAEzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY;;;;;;;;CAIf,CAAA;AAEV;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,aAAa,CAAC,MAAM,CAAC,GAAG,SAc7D,CAAA;AAsBD;;;;;;GAMG;AACH,eAAO,MAAM,GAAG;;;;;;;yEA0Pd,CAAA"}
@@ -0,0 +1,346 @@
1
+ /**
2
+ * apply_patch flow declaration and portable handler.
3
+ *
4
+ * A Codex CLI clone: the V4A patch grammar (`*** Begin Patch` /
5
+ * `*** Add File:` / `*** Update File:` / `*** Delete File:` /
6
+ * `*** End Patch`), the fuzzy context-matching applier, and Codex's error
7
+ * and summary text, expressed as a flow over the kernel filesystem.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ import * as Path from "@smthrs/kernel/Path";
12
+ import * as Effect from "effect/Effect";
13
+ import * as FileSystem from "effect/FileSystem";
14
+ import * as Schema from "effect/Schema";
15
+ import * as ApplyPatchText from "./internal/ApplyPatch.js";
16
+ import { capability, envelope } from "./internal/Declaration.js";
17
+ import * as Diagnostics from "./internal/Diagnostics.js";
18
+ import * as FileMutation from "./internal/FileMutation.js";
19
+ import * as FsFailure from "./internal/FsFailure.js";
20
+ import * as Preserve from "./internal/Preserve.js";
21
+ import * as StdError from "./StdError.js";
22
+ /**
23
+ * Registry name for the apply_patch flow. Matches the Codex CLI tool name.
24
+ *
25
+ * @category identifiers
26
+ * @since 1.0.0
27
+ */
28
+ export const name = "apply_patch";
29
+ /**
30
+ * Model-facing description of the apply_patch flow. Matches the Codex CLI
31
+ * freeform tool description.
32
+ *
33
+ * @category descriptions
34
+ * @since 1.0.0
35
+ */
36
+ export const description = "The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.";
37
+ /**
38
+ * Input schema for the apply_patch flow.
39
+ *
40
+ * Codex delivers the patch as freeform text; the JSON function fallback uses
41
+ * a single `input` field, which is the shape cloned here.
42
+ *
43
+ * @category schemas
44
+ * @since 1.0.0
45
+ */
46
+ export const Input = Schema.Struct({
47
+ input: Schema.String.annotate({ description: "The entire contents of the apply_patch command" })
48
+ });
49
+ /**
50
+ * Output schema for the apply_patch flow.
51
+ *
52
+ * @category schemas
53
+ * @since 1.0.0
54
+ */
55
+ export const Output = Schema.Struct({
56
+ output: Schema.String.annotate({
57
+ description: "Codex-style summary: 'Success. Updated the following files:' with A/M/D lines"
58
+ }),
59
+ added: Schema.Array(Schema.String).annotate({ description: "Paths of files created by the patch" }),
60
+ modified: Schema.Array(Schema.String).annotate({ description: "Paths of files updated by the patch" }),
61
+ deleted: Schema.Array(Schema.String).annotate({ description: "Paths of files deleted by the patch" })
62
+ });
63
+ /**
64
+ * Static conservative effect envelope for the apply_patch flow.
65
+ *
66
+ * @category effects
67
+ * @since 1.0.0
68
+ */
69
+ export const effects = envelope({ tier: "compensable", mode: "hermetic", reads: ["/**"], writes: ["/**"] });
70
+ /**
71
+ * Narrows the effect envelope for a decoded invocation.
72
+ *
73
+ * A patch names its files inside its own text rather than in a decoded field,
74
+ * and the parse that finds them is the same parse that can fail, so there is
75
+ * nothing here to narrow before the handler runs: the static envelope is the
76
+ * honest answer.
77
+ *
78
+ * @category effects
79
+ * @since 1.0.0
80
+ */
81
+ export const effectsFor = (_input) => effects;
82
+ /**
83
+ * Capabilities required by the apply_patch flow.
84
+ *
85
+ * @category capabilities
86
+ * @since 1.0.0
87
+ */
88
+ export const capabilities = [capability("fs:read", "/**"), capability("fs:write", "/**")];
89
+ /**
90
+ * Declaration-only apply_patch flow.
91
+ *
92
+ * @category flows
93
+ * @since 1.0.0
94
+ */
95
+ export const flow = { name, description, input: Input, output: Output, capabilities, effects };
96
+ /**
97
+ * What a call to this flow does, for a reader of a run.
98
+ *
99
+ * Display metadata only. `@smthrs/registry` `Descriptor.FlowActivity` is the
100
+ * governing vocabulary and `StandardFlows` binds this value onto the flow's
101
+ * descriptor, where the binding site checks it. `declarationDigest` excludes
102
+ * it, so declaring it cannot invalidate a call identity or a cached prompt.
103
+ *
104
+ * @category presentation
105
+ * @since 1.0.0-rc.0
106
+ */
107
+ export const activity = "writes";
108
+ /**
109
+ * How one recorded call to this flow reads: the verb for each settlement, the
110
+ * input field that is its subject, and the measured output fields a one-line
111
+ * summary may count.
112
+ *
113
+ * Display metadata only, governed by `@smthrs/registry`
114
+ * `Descriptor.CallPresentation` and checked where `StandardFlows` binds it.
115
+ *
116
+ * @category presentation
117
+ * @since 1.0.0-rc.0
118
+ */
119
+ export const presentation = {
120
+ verb: { pending: "patching", success: "patched", failure: "failed to patch" },
121
+ subject: "patch",
122
+ result: "patch"
123
+ };
124
+ /**
125
+ * Every path a patch writes, in the order it names them, including a move's
126
+ * destination. The patch is read by the parser {@link run} uses, so a header
127
+ * `run` accepts is never missed.
128
+ *
129
+ * Returns `undefined` when `run` would refuse the patch. A caller asking
130
+ * permission for the call then asks for everything the flow declares.
131
+ *
132
+ * @category parsing
133
+ * @since 1.0.0-rc.1
134
+ */
135
+ export const paths = (patch) => {
136
+ let parsed;
137
+ try {
138
+ parsed = ApplyPatchText.parsePatch(patch);
139
+ }
140
+ catch {
141
+ return undefined;
142
+ }
143
+ return [
144
+ ...new Set(parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]))
145
+ ];
146
+ };
147
+ /**
148
+ * The one sentence a model sees for a failure this handler did not design.
149
+ * The raw failure goes to the log, never into the tool result.
150
+ */
151
+ const unknownFailureSentence = "Something went wrong on our side. Not your fault.";
152
+ const unknownFailure = (error, path) => Effect.logError("apply_patch failed unexpectedly", error).pipe(Effect.andThen(Effect.fail(new StdError.StdError(path === undefined
153
+ ? { code: "command_failed", message: unknownFailureSentence }
154
+ : { code: "command_failed", message: unknownFailureSentence, path }))));
155
+ const encoder = new TextEncoder();
156
+ const decoder = new TextDecoder("utf-8", { fatal: true });
157
+ /**
158
+ * Parses and applies a V4A patch through the permission-aware kernel
159
+ * filesystem, preserving Codex error text.
160
+ *
161
+ * @category handlers
162
+ * @since 1.0.0
163
+ */
164
+ export const run = Effect.fn("ApplyPatch.run")(function* (input) {
165
+ const fileSystem = yield* FileSystem.FileSystem;
166
+ const path = yield* Path.Path;
167
+ let parsed;
168
+ try {
169
+ parsed = ApplyPatchText.parsePatch(input.input);
170
+ }
171
+ catch (error) {
172
+ if (error instanceof ApplyPatchText.ParseError) {
173
+ return yield* Effect.fail(new StdError.StdError({ code: "invalid_input", message: error.message }));
174
+ }
175
+ return yield* unknownFailure(error);
176
+ }
177
+ // Every update hunk is derived from the file as it is on disk, so two
178
+ // sections naming one path both start from the same original and the second
179
+ // write erases the first — while the summary reports two modifications.
180
+ // The preflight cannot honestly validate the second section against a file
181
+ // the first has not written yet, so the patch is refused whole rather than
182
+ // applied by halves. A file needing several edits carries several `@@`
183
+ // chunks inside one section, which is the shape the parser already accepts.
184
+ // Resolve against the injected workspace, then follow existing filesystem
185
+ // aliases. For a new file, resolve its parent (which may be a symlink).
186
+ const identity = (value) => {
187
+ const resolved = path.resolve(value);
188
+ return fileSystem.realPath(resolved).pipe(Effect.catch((error) => error.reason._tag === "NotFound"
189
+ ? fileSystem.realPath(path.dirname(resolved)).pipe(Effect.map((parent) => path.resolve(parent, path.basename(resolved))), Effect.catch((parentError) => parentError.reason._tag === "NotFound"
190
+ ? Effect.succeed(resolved)
191
+ : Effect.fail(parentError)))
192
+ : Effect.fail(error)), Effect.mapError(FsFailure.denied(value, () => new StdError.StdError({
193
+ code: "command_failed",
194
+ message: `Failed to resolve patch path ${value}`,
195
+ path: value
196
+ }))));
197
+ };
198
+ const touched = new Set();
199
+ for (const hunk of parsed.hunks) {
200
+ const source = yield* identity(hunk.path);
201
+ const destination = hunk.kind === "update" && hunk.movePath !== undefined
202
+ ? yield* identity(hunk.movePath)
203
+ : undefined;
204
+ const claims = [[hunk.path, source]];
205
+ if (hunk.kind === "update" && hunk.movePath !== undefined && destination !== source) {
206
+ claims.push([hunk.movePath, destination]);
207
+ }
208
+ for (const [claimed, key] of claims) {
209
+ if (touched.has(key)) {
210
+ return yield* Effect.fail(new StdError.StdError({
211
+ code: "invalid_input",
212
+ message: `The patch names ${claimed} in more than one section; give one section per path`,
213
+ path: claimed
214
+ }));
215
+ }
216
+ touched.add(key);
217
+ }
218
+ }
219
+ yield* FileMutation.validate(fileSystem, parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]));
220
+ // Create only parents the patch already intends to create, before taking
221
+ // stable sibling locks for new destinations as well as existing sources.
222
+ for (const hunk of parsed.hunks) {
223
+ const destination = hunk.kind === "add" ? hunk.path : hunk.kind === "update" ? hunk.movePath : undefined;
224
+ if (destination !== undefined && !FileMutation.isVersioned(fileSystem)) {
225
+ yield* fileSystem.makeDirectory(path.dirname(destination), { recursive: true }).pipe(Effect.mapError(FsFailure.denied(destination, () => new StdError.StdError({
226
+ code: "command_failed",
227
+ message: `Failed to create parent directories for ${destination}`,
228
+ path: destination
229
+ }))));
230
+ }
231
+ }
232
+ return yield* Effect.scoped(Effect.gen(function* () {
233
+ const mutation = yield* FileMutation.acquire(fileSystem, parsed.hunks.flatMap((hunk) => hunk.kind === "update" && hunk.movePath !== undefined ? [hunk.path, hunk.movePath] : [hunk.path]), path);
234
+ const added = [];
235
+ const modified = [];
236
+ const deleted = [];
237
+ const prepared = new Map();
238
+ for (const hunk of parsed.hunks) {
239
+ if (hunk.kind !== "update")
240
+ continue;
241
+ const bytes = yield* mutation.read(hunk.path, fileSystem.readFile(hunk.path).pipe(Effect.mapError(FsFailure.reading(hunk.path, `Failed to read file to update ${hunk.path}`))));
242
+ if (bytes.includes(0)) {
243
+ return yield* Effect.fail(new StdError.StdError({
244
+ code: "binary_file",
245
+ message: `Cannot read binary file: ${hunk.path}`,
246
+ path: hunk.path
247
+ }));
248
+ }
249
+ const original = yield* Effect.try({
250
+ try: () => decoder.decode(bytes),
251
+ catch: () => new StdError.StdError({
252
+ code: "binary_file",
253
+ message: `File is not valid UTF-8: ${hunk.path}`,
254
+ path: hunk.path
255
+ })
256
+ });
257
+ let contents;
258
+ try {
259
+ contents = ApplyPatchText.deriveNewContents(original, hunk.path, hunk.chunks);
260
+ }
261
+ catch (error) {
262
+ if (error instanceof ApplyPatchText.ComputeReplacementsError) {
263
+ return yield* Effect.fail(new StdError.StdError({ code: "no_match", message: error.message, path: hunk.path }));
264
+ }
265
+ return yield* unknownFailure(error, hunk.path);
266
+ }
267
+ prepared.set(hunk, contents);
268
+ }
269
+ // Prepare one complete provider request before touching any file. A move
270
+ // carries both its destination write and source removal in the same commit.
271
+ const changes = [];
272
+ const moves = new Set();
273
+ for (const hunk of parsed.hunks) {
274
+ if (hunk.kind === "delete") {
275
+ changes.push({ path: hunk.path, content: null });
276
+ }
277
+ else if (hunk.kind === "add") {
278
+ changes.push({ path: hunk.path, content: encoder.encode(hunk.contents) });
279
+ }
280
+ else {
281
+ changes.push({
282
+ path: hunk.movePath ?? hunk.path,
283
+ content: encoder.encode(prepared.get(hunk))
284
+ });
285
+ if (hunk.movePath !== undefined && (yield* identity(hunk.movePath)) !== (yield* identity(hunk.path))) {
286
+ moves.add(hunk);
287
+ changes.push({ path: hunk.path, content: null });
288
+ }
289
+ }
290
+ }
291
+ // A denial names itself, so the model does not retry a write the host refuses.
292
+ const mutationFailure = (code, message, offendingPath) => (error) => error.reason._tag === "PermissionDenied"
293
+ ? mutationError("permission_denied", `Permission denied: ${offendingPath}`, offendingPath)
294
+ : mutationError(code, message, offendingPath);
295
+ const mutationError = (code, message, offendingPath) => new StdError.StdError({
296
+ code,
297
+ message: `${message}; applied before failure: added=${JSON.stringify(added)}, modified=${JSON.stringify(modified)}, deleted=${JSON.stringify(deleted)}`,
298
+ path: offendingPath
299
+ });
300
+ yield* mutation.commit(changes, Effect.gen(function* () {
301
+ for (const hunk of parsed.hunks) {
302
+ switch (hunk.kind) {
303
+ case "add": {
304
+ yield* fileSystem.writeFile(hunk.path, encoder.encode(hunk.contents)).pipe(Effect.mapError(mutationFailure("command_failed", `Failed to write file ${hunk.path}`, hunk.path)));
305
+ added.push(hunk.path);
306
+ break;
307
+ }
308
+ case "delete": {
309
+ yield* fileSystem.remove(hunk.path).pipe(Effect.mapError(mutationFailure("not_found", `Failed to delete file ${hunk.path}`, hunk.path)));
310
+ deleted.push(hunk.path);
311
+ break;
312
+ }
313
+ case "update": {
314
+ const contents = prepared.get(hunk);
315
+ const destination = hunk.movePath ?? hunk.path;
316
+ yield* Preserve.writeFile(fileSystem, destination, encoder.encode(contents)).pipe(Effect.mapError((error) => error.reason.method === "chmod"
317
+ ? mutationError("command_failed", `Could not preserve the mode of ${destination} before replacement by chmod`, destination)
318
+ : mutationFailure("command_failed", `Failed to write file ${destination}`, destination)(error)));
319
+ modified.push(destination);
320
+ if (moves.has(hunk)) {
321
+ yield* fileSystem.remove(hunk.path).pipe(Effect.mapError(mutationFailure("command_failed", `Failed to remove original ${hunk.path}`, hunk.path)));
322
+ }
323
+ break;
324
+ }
325
+ }
326
+ }
327
+ }));
328
+ // Publish diagnostics only after the whole provider operation succeeds.
329
+ for (const change of changes) {
330
+ if (change.content === null)
331
+ yield* Diagnostics.close(path.resolve(change.path));
332
+ else
333
+ yield* Diagnostics.sync(path.resolve(change.path), decoder.decode(change.content));
334
+ }
335
+ const summary = {
336
+ added: parsed.hunks.filter((hunk) => hunk.kind === "add").map((hunk) => hunk.path),
337
+ deleted: parsed.hunks.filter((hunk) => hunk.kind === "delete").map((hunk) => hunk.path),
338
+ modified: parsed.hunks.filter((hunk) => hunk.kind === "update").map((hunk) => hunk.movePath ?? hunk.path)
339
+ };
340
+ return {
341
+ output: ApplyPatchText.printSummary(summary),
342
+ ...summary
343
+ };
344
+ }));
345
+ });
346
+ //# sourceMappingURL=ApplyPatch.js.map