@poe-platform/safe-bash 0.1.811 → 0.1.813

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 (351) hide show
  1. package/dist/audio-ast/id3-source.d.ts +27 -0
  2. package/dist/audio-ast/index.d.ts +5 -0
  3. package/dist/audio-ast/index.js +1001 -596
  4. package/dist/audio-ast/mp3-source.d.ts +18 -0
  5. package/dist/audio-ast/ogg-source.d.ts +25 -0
  6. package/dist/audio-ast/ogg-stream-source.d.ts +22 -0
  7. package/dist/audio-ast/vorbis.d.ts +14 -0
  8. package/dist/image-ast/index.js +139 -9
  9. package/dist/mp4-ast/containers/adapters.d.ts +7 -0
  10. package/dist/office-xml/retained-xml-document.d.ts +8 -0
  11. package/dist/pdf-ast/ast.d.ts +2 -0
  12. package/dist/pdf-ast/content/dictionary-cursor.d.ts +15 -0
  13. package/dist/pdf-ast/content/range-operator-parser.d.ts +4 -0
  14. package/dist/pdf-ast/content/stored-dictionary.d.ts +10 -0
  15. package/dist/pdf-ast/cos/lexer.d.ts +8 -5
  16. package/dist/pdf-ast/cos/object-reader.d.ts +4 -3
  17. package/dist/pdf-ast/cos/range-parser.d.ts +4 -0
  18. package/dist/pdf-ast/cos/retained-objects.d.ts +1 -0
  19. package/dist/pdf-ast/cos/retained-writer.d.ts +1 -0
  20. package/dist/pdf-ast/cos/value-parser.d.ts +32 -2
  21. package/dist/pdf-ast/edit/retained-append-attachments.d.ts +13 -0
  22. package/dist/pdf-ast/edit/retained-bookmarks.d.ts +13 -0
  23. package/dist/pdf-ast/edit/retained-graph.d.ts +6 -0
  24. package/dist/pdf-ast/edit/retained-save.d.ts +2 -0
  25. package/dist/pdf-ast/edit/retained-stamps.d.ts +9 -0
  26. package/dist/pdf-ast/extract/retained-form-field-details.d.ts +20 -0
  27. package/dist/pdf-ast/extract/retained-form-fields.d.ts +17 -4
  28. package/dist/pdf-ast/fonts/resolve.d.ts +3 -1
  29. package/dist/pdf-ast/index.d.ts +4 -1
  30. package/dist/pdf-ast/index.js +2127 -975
  31. package/dist/pdf-ast/retained-document.d.ts +4 -0
  32. package/dist/safe-bash/audio-ast.browser.js +7 -1
  33. package/dist/safe-bash/chunks/{chunk-HHSOUC3Z.js → chunk-HPQE675Q.js} +1 -1
  34. package/dist/safe-bash/chunks/{chunk-BUYRKFW2.js → chunk-I6ECNJMR.js} +1 -1
  35. package/dist/safe-bash/chunks/{pdftk-WRYEP3CA.js → pdftk-Y2TX74LY.js} +2 -1
  36. package/dist/safe-bash/command-chunks/biff-4ALVARRF-7SRX6R6N.js +5192 -0
  37. package/dist/safe-bash/command-chunks/{chunk-EHSM5ZQS.js → chunk-2DGJOOXM.js} +8 -8
  38. package/dist/safe-bash/command-chunks/{chunk-Q6S57NOQ.js → chunk-2E2H7MBH.js} +7 -7
  39. package/dist/safe-bash/command-chunks/{chunk-MMBZTYXO.js → chunk-2PQRZDNR.js} +221 -0
  40. package/dist/safe-bash/command-chunks/{chunk-5OO2P27R.js → chunk-2V6FOLXV.js} +78 -25
  41. package/dist/safe-bash/command-chunks/{chunk-56NYSX65.js → chunk-2Z3WRRFT.js} +9 -9
  42. package/dist/safe-bash/command-chunks/chunk-3D24WDND.js +63 -0
  43. package/dist/safe-bash/command-chunks/{chunk-47NEG4UO.js → chunk-3JST2Q7G.js} +219 -43
  44. package/dist/safe-bash/command-chunks/{chunk-WGG6G2KG.js → chunk-3LJAXFH5.js} +7 -7
  45. package/dist/safe-bash/command-chunks/{chunk-AHA6IWAJ.js → chunk-3TYDSGAH.js} +6 -6
  46. package/dist/safe-bash/command-chunks/{chunk-YSMNXMAO.js → chunk-3Y4XZB24.js} +4 -4
  47. package/dist/safe-bash/command-chunks/{chunk-ZIIO6GRY.js → chunk-4PBNMKAT.js} +7 -7
  48. package/dist/safe-bash/command-chunks/{chunk-JFYWVQ4V.js → chunk-4Z6W5EOC.js} +8 -8
  49. package/dist/safe-bash/command-chunks/{chunk-GEM47B2P.js → chunk-57DDYKE5.js} +7 -7
  50. package/dist/safe-bash/command-chunks/{chunk-HARUYHH7.js → chunk-5HUICAWD.js} +1 -1
  51. package/dist/safe-bash/command-chunks/{chunk-4CKFNXRN.js → chunk-5IFRAI7Y.js} +1 -1
  52. package/dist/safe-bash/command-chunks/{chunk-RHYJVTJO.js → chunk-5KGEZ3RW.js} +2 -2
  53. package/dist/safe-bash/command-chunks/{chunk-A5FZBR7X.js → chunk-5MFDRSGG.js} +4 -4
  54. package/dist/safe-bash/command-chunks/{chunk-7GKKMNL6.js → chunk-5P6I2T63.js} +8 -8
  55. package/dist/safe-bash/command-chunks/{chunk-6M6TM5Z5.js → chunk-5VQVZPP3.js} +3 -3
  56. package/dist/safe-bash/command-chunks/{chunk-MIRL7HTF.js → chunk-6244HYJY.js} +1 -1
  57. package/dist/safe-bash/command-chunks/chunk-63EMPQ7Z.js +115 -0
  58. package/dist/safe-bash/command-chunks/{chunk-XRVKWGVQ.js → chunk-6CY5BHBS.js} +6 -6
  59. package/dist/safe-bash/command-chunks/{chunk-XVP6V5K3.js → chunk-6IWE7PTK.js} +6 -6
  60. package/dist/safe-bash/command-chunks/{chunk-6QBMND4A.js → chunk-6SRHWVEB.js} +1 -1
  61. package/dist/safe-bash/command-chunks/chunk-6ZHQB453.js +35 -0
  62. package/dist/safe-bash/command-chunks/chunk-73NYFNAS.js +173 -0
  63. package/dist/safe-bash/command-chunks/{chunk-VU3EQF7F.js → chunk-7NXTEWPR.js} +229 -75
  64. package/dist/safe-bash/command-chunks/{chunk-554Z6IKP.js → chunk-7PRL6RJ6.js} +2 -2
  65. package/dist/safe-bash/command-chunks/{chunk-SDTPO2VV.js → chunk-7PZHWMK6.js} +7 -7
  66. package/dist/safe-bash/command-chunks/{chunk-XZ2FWFNV.js → chunk-7QZ2HP2F.js} +6 -6
  67. package/dist/safe-bash/command-chunks/{chunk-OEJM666F.js → chunk-7UC2Q6Z6.js} +5 -5
  68. package/dist/safe-bash/command-chunks/{chunk-COKYZUBW.js → chunk-AJI55RS7.js} +1 -1
  69. package/dist/safe-bash/command-chunks/{chunk-2VCKUNDZ.js → chunk-B2C3UPJS.js} +27 -17
  70. package/dist/safe-bash/command-chunks/{chunk-WXRYDALR.js → chunk-BBAB7LC4.js} +4 -4
  71. package/dist/safe-bash/command-chunks/{chunk-QYMEASQ6.js → chunk-BEHUSUOY.js} +4 -4
  72. package/dist/safe-bash/command-chunks/{chunk-Z2JW6M2D.js → chunk-BK7ISUJL.js} +3 -3
  73. package/dist/safe-bash/command-chunks/{chunk-33YCKZZX.js → chunk-C5KLFZGT.js} +6 -6
  74. package/dist/safe-bash/command-chunks/{chunk-TVH4JORU.js → chunk-C5QDEB3I.js} +3 -3
  75. package/dist/safe-bash/command-chunks/{chunk-N4R2SHSS.js → chunk-CCZZVCHX.js} +2 -2
  76. package/dist/safe-bash/command-chunks/{chunk-2VLAXKTS.js → chunk-CTDC4LJT.js} +121 -85
  77. package/dist/safe-bash/command-chunks/{chunk-S6R3IB36.js → chunk-D55REQA3.js} +1 -1
  78. package/dist/safe-bash/command-chunks/{chunk-Y4EYCZFT.js → chunk-D6WJY6QO.js} +10 -10
  79. package/dist/safe-bash/command-chunks/{chunk-2CORNDGF.js → chunk-DBLHCJJU.js} +2 -2
  80. package/dist/safe-bash/command-chunks/{chunk-SPW4GW4Z.js → chunk-DFI7QF3M.js} +2 -2
  81. package/dist/safe-bash/command-chunks/{chunk-456PHA3L.js → chunk-DMCI6T6N.js} +1 -1
  82. package/dist/safe-bash/command-chunks/{chunk-TW73OXPR.js → chunk-EJTNVXWF.js} +6 -6
  83. package/dist/safe-bash/command-chunks/{chunk-QD7ZRDUN.js → chunk-ET2VPDUA.js} +1 -1
  84. package/dist/safe-bash/command-chunks/{chunk-5LI2DLNZ.js → chunk-EXOQGXEU.js} +26 -26
  85. package/dist/safe-bash/command-chunks/{chunk-CRV2Q3PB.js → chunk-EZ4NQIPL.js} +1 -1
  86. package/dist/safe-bash/command-chunks/chunk-FWKLBDMK.js +0 -0
  87. package/dist/safe-bash/command-chunks/{chunk-22MOB45U.js → chunk-FWPVQGYK.js} +6 -6
  88. package/dist/safe-bash/command-chunks/{chunk-QC5RMGSA.js → chunk-G3RUXKVY.js} +3 -3
  89. package/dist/safe-bash/command-chunks/{chunk-JYUJAF4L.js → chunk-G7NENPYV.js} +4 -0
  90. package/dist/safe-bash/command-chunks/{chunk-KCOJA7EM.js → chunk-GKILM4HZ.js} +7 -7
  91. package/dist/safe-bash/command-chunks/{chunk-HTVIYLVB.js → chunk-GNXTMSYN.js} +4 -4
  92. package/dist/safe-bash/command-chunks/{chunk-D2ASPM7R.js → chunk-GOBUDKZ3.js} +3 -3
  93. package/dist/safe-bash/command-chunks/{chunk-RNSKXOG3.js → chunk-GVWVRPG6.js} +6 -6
  94. package/dist/safe-bash/command-chunks/{chunk-ZHRGYR7B.js → chunk-HCKYUQ3L.js} +7 -7
  95. package/dist/safe-bash/command-chunks/{chunk-AGLK7OJR.js → chunk-HDSIIQBS.js} +1 -1
  96. package/dist/safe-bash/command-chunks/{chunk-DM2CPMB4.js → chunk-HKOMXGJS.js} +2 -2
  97. package/dist/safe-bash/command-chunks/{chunk-IT7TAC3F.js → chunk-HVW53ARH.js} +16 -16
  98. package/dist/safe-bash/command-chunks/{chunk-M7QE2MN7.js → chunk-I4GMCWAT.js} +6 -6
  99. package/dist/safe-bash/command-chunks/{chunk-5MB64DWR.js → chunk-IHSOOSNC.js} +9 -9
  100. package/dist/safe-bash/command-chunks/{chunk-LCZDBW55.js → chunk-JAHJWVGF.js} +5 -5
  101. package/dist/safe-bash/command-chunks/{chunk-MOZD7RUY.js → chunk-JORIVUPM.js} +27 -11
  102. package/dist/safe-bash/command-chunks/{chunk-PMAM4N33.js → chunk-JUJHYPYL.js} +9 -9
  103. package/dist/safe-bash/command-chunks/{chunk-ENT3IV2G.js → chunk-KBUBSMCQ.js} +12 -12
  104. package/dist/safe-bash/command-chunks/{chunk-ZXR6LXV5.js → chunk-KCE5D4Z4.js} +48 -4
  105. package/dist/safe-bash/command-chunks/{chunk-FIIAYCWS.js → chunk-KZ5ODST6.js} +2 -2
  106. package/dist/safe-bash/command-chunks/{chunk-PNGDJA6M.js → chunk-LD7BONZY.js} +2 -2
  107. package/dist/safe-bash/command-chunks/{chunk-KJ4XXZIL.js → chunk-M3Z5PU2M.js} +582 -59
  108. package/dist/safe-bash/command-chunks/{chunk-LXLLA4PM.js → chunk-MKX4JAZ6.js} +17 -17
  109. package/dist/safe-bash/command-chunks/{chunk-RQIQ75W5.js → chunk-MNHBQBF6.js} +5 -5
  110. package/dist/safe-bash/command-chunks/{chunk-A2CLZMQZ.js → chunk-MPKY37QR.js} +1 -1
  111. package/dist/safe-bash/command-chunks/{chunk-K5GB2YMN.js → chunk-MUUWBZIC.js} +10 -10
  112. package/dist/safe-bash/command-chunks/{chunk-JOCFI7TG.js → chunk-N32GSM3J.js} +1 -1
  113. package/dist/safe-bash/command-chunks/{chunk-EUT24Y5Z.js → chunk-NKTULXVD.js} +8 -8
  114. package/dist/safe-bash/command-chunks/{chunk-5HPU7D36.js → chunk-NMPED6L5.js} +4 -4
  115. package/dist/safe-bash/command-chunks/{chunk-QZZ73J2O.js → chunk-NPFHUS4X.js} +6 -6
  116. package/dist/safe-bash/command-chunks/{chunk-X7FA7ZD5.js → chunk-O675URF4.js} +8 -8
  117. package/dist/safe-bash/command-chunks/{chunk-R6EGGK5M.js → chunk-P7EL2FWW.js} +7 -7
  118. package/dist/safe-bash/command-chunks/{chunk-YS25EI54.js → chunk-PCCFLPUQ.js} +2 -2
  119. package/dist/safe-bash/command-chunks/{chunk-RRL3Y562.js → chunk-PI6MOMHA.js} +11 -11
  120. package/dist/safe-bash/command-chunks/{chunk-26VCZHLJ.js → chunk-PIOQBOEK.js} +1 -1
  121. package/dist/safe-bash/command-chunks/chunk-PK36TVXB.js +175 -0
  122. package/dist/safe-bash/command-chunks/{chunk-72C3TZ2U.js → chunk-PKLJRB7W.js} +264 -129
  123. package/dist/safe-bash/command-chunks/{chunk-6CCQI6XZ.js → chunk-PSCOXGCA.js} +12 -12
  124. package/dist/safe-bash/command-chunks/{chunk-XPD636C4.js → chunk-PVGZMLC6.js} +3 -3
  125. package/dist/safe-bash/command-chunks/{chunk-JQVHUSDD.js → chunk-PXWS3Q7L.js} +5 -5
  126. package/dist/safe-bash/command-chunks/{chunk-HDJVJTCK.js → chunk-QFF5KBOM.js} +9 -9
  127. package/dist/safe-bash/command-chunks/{chunk-MPUHH2KR.js → chunk-QM2HZJSJ.js} +3 -3
  128. package/dist/safe-bash/command-chunks/{chunk-UAXSE3XE.js → chunk-R2BMZAHG.js} +5 -5
  129. package/dist/safe-bash/command-chunks/{chunk-KB7DUBVL.js → chunk-RGOQKIG6.js} +5 -5
  130. package/dist/safe-bash/command-chunks/{chunk-D2KZ66W4.js → chunk-RLCQ7BN3.js} +187 -39
  131. package/dist/safe-bash/command-chunks/{chunk-B5LDP7AA.js → chunk-S2N2V5U4.js} +2 -2
  132. package/dist/safe-bash/command-chunks/{chunk-OA75SGN2.js → chunk-SGPCXAG7.js} +7 -7
  133. package/dist/safe-bash/command-chunks/{chunk-Z5QOVRVH.js → chunk-SU26FZLJ.js} +1 -1
  134. package/dist/safe-bash/command-chunks/{chunk-QUM3SYAJ.js → chunk-SYSX46IV.js} +3 -3
  135. package/dist/safe-bash/command-chunks/chunk-T3E5RV3U.js +737 -0
  136. package/dist/safe-bash/command-chunks/{chunk-YORJDX4V.js → chunk-T5ERNELL.js} +4 -4
  137. package/dist/safe-bash/command-chunks/{chunk-KL3OIBKB.js → chunk-T6C5QP7T.js} +6495 -6343
  138. package/dist/safe-bash/command-chunks/{chunk-ATTWQVR2.js → chunk-TKRLZIFI.js} +17 -17
  139. package/dist/safe-bash/command-chunks/{chunk-ZMHEGDU2.js → chunk-TODWFDYB.js} +2 -2
  140. package/dist/safe-bash/command-chunks/{chunk-YSY6R6AS.js → chunk-TQEB4DH4.js} +703 -102
  141. package/dist/safe-bash/command-chunks/{chunk-36XGIPOG.js → chunk-U5TWQFZY.js} +1 -1
  142. package/dist/safe-bash/command-chunks/{chunk-APEWTWCC.js → chunk-UAF4IX5H.js} +6 -6
  143. package/dist/safe-bash/command-chunks/{chunk-6VPQ3CDZ.js → chunk-V37D6AHO.js} +5 -5
  144. package/dist/safe-bash/command-chunks/{chunk-RID6VYS3.js → chunk-V6XBEYPC.js} +8 -8
  145. package/dist/safe-bash/command-chunks/{chunk-WJCN2IXI.js → chunk-VQOINPVF.js} +2 -2
  146. package/dist/safe-bash/command-chunks/{chunk-W5YSINXC.js → chunk-VVWXY6IA.js} +6 -6
  147. package/dist/safe-bash/command-chunks/{chunk-HKATEVAP.js → chunk-WPVBUVFK.js} +6 -6
  148. package/dist/safe-bash/command-chunks/{chunk-UYWSIIUX.js → chunk-X53AEG36.js} +7 -7
  149. package/dist/safe-bash/command-chunks/{chunk-L5MCW6CM.js → chunk-X64XGIXZ.js} +9 -155
  150. package/dist/safe-bash/command-chunks/{chunk-Q73EMLLZ.js → chunk-X6RHJ6YN.js} +84 -5
  151. package/dist/safe-bash/command-chunks/{chunk-7PVHO47B.js → chunk-XG6UWQV5.js} +6 -6
  152. package/dist/safe-bash/command-chunks/{chunk-NQDIT667.js → chunk-XIDGHIGB.js} +5 -5
  153. package/dist/safe-bash/command-chunks/{chunk-DPR5CYQV.js → chunk-XITDDJFT.js} +2 -0
  154. package/dist/safe-bash/command-chunks/{chunk-CV7M2QJU.js → chunk-XLYIVBAR.js} +7 -7
  155. package/dist/safe-bash/command-chunks/{chunk-WVMHRNXZ.js → chunk-YUXTK3XA.js} +3 -3
  156. package/dist/safe-bash/command-chunks/{chunk-SPLOIABU.js → chunk-YXD6VGVG.js} +3 -3
  157. package/dist/safe-bash/command-chunks/{chunk-2ZFLMWOX.js → chunk-Z5BIM5B7.js} +1 -1
  158. package/dist/safe-bash/command-chunks/chunk-ZYLGNIGA.js +156 -0
  159. package/dist/safe-bash/command-chunks/{command-engine-BEWABZ75.js → command-engine-X3OLN7N6.js} +206 -86
  160. package/dist/safe-bash/command-chunks/{engine-AXXFTGCL-QBQNBI6K.js → engine-XUCIFZ7V-LJFGZM6O.js} +1 -1
  161. package/dist/safe-bash/command-chunks/paradox-4FCZE53D-LQPGVMEL.js +365 -0
  162. package/dist/safe-bash/commands/pandoc/index.browser.js +1 -1
  163. package/dist/safe-bash/full-core.browser.js +2 -2
  164. package/dist/safe-bash/plugins/index.browser.js +2 -2
  165. package/dist/safe-bash-command-apply-patch/apply.js +4 -4
  166. package/dist/safe-bash-command-apply-patch/index.js +4 -4
  167. package/dist/safe-bash-command-apply-patch/matcher.js +2 -2
  168. package/dist/safe-bash-command-apply-patch/parser.js +2 -2
  169. package/dist/safe-bash-command-apply-patch/shared.d.ts +2 -0
  170. package/dist/safe-bash-command-apply-patch/shared.js +1 -1
  171. package/dist/safe-bash-command-diff/diff.js +1 -1
  172. package/dist/safe-bash-command-diff/index.js +1 -1
  173. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  174. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  175. package/dist/safe-bash-command-ffprobe/media.d.ts +3 -1
  176. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  177. package/dist/safe-bash-command-html-to-markdown/budget.js +2 -1
  178. package/dist/safe-bash-command-html-to-markdown/entities.js +4 -3
  179. package/dist/safe-bash-command-html-to-markdown/index.js +564 -110
  180. package/dist/safe-bash-command-html-to-markdown/input.js +6 -5
  181. package/dist/safe-bash-command-html-to-markdown/options.js +2 -1
  182. package/dist/safe-bash-command-html-to-markdown/parser.js +5 -4
  183. package/dist/safe-bash-command-html-to-markdown/render.js +6 -5
  184. package/dist/safe-bash-command-html-to-markdown/text.js +3 -2
  185. package/dist/safe-bash-command-htmlq/index.js +361 -37
  186. package/dist/safe-bash-command-htmlq/tree.d.ts +3 -2
  187. package/dist/safe-bash-command-pandoc/command.js +7 -7
  188. package/dist/safe-bash-command-pandoc/index.js +55 -55
  189. package/dist/safe-bash-command-patch/index.js +6 -6
  190. package/dist/safe-bash-command-patch/patch-envelope.js +53 -3
  191. package/dist/safe-bash-command-patch/patch-formats.d.ts +2 -2
  192. package/dist/safe-bash-command-patch/patch-formats.js +2 -2
  193. package/dist/safe-bash-command-patch/patch-gnu-reject.d.ts +2 -1
  194. package/dist/safe-bash-command-patch/patch-gnu-reject.js +4 -3
  195. package/dist/safe-bash-command-patch/patch-publication.js +2 -1
  196. package/dist/safe-bash-command-patch/patch.js +6 -6
  197. package/dist/safe-bash-command-patch/unified.d.ts +10 -2
  198. package/dist/safe-bash-command-patch/unified.js +1 -1
  199. package/dist/safe-bash-command-pdftk/index.d.ts +6 -2
  200. package/dist/safe-bash-command-pdftk/index.js +835 -243
  201. package/dist/safe-bash-command-pptx/command-engine.d.ts +15 -3
  202. package/dist/safe-bash-command-pptx/engine.d.ts +2 -2
  203. package/dist/safe-bash-command-pptx/engine.js +1 -1
  204. package/dist/safe-bash-command-pptx/index.js +9 -2
  205. package/dist/safe-bash-command-soffice/index.js +1 -1
  206. package/dist/safe-bash-command-ssconvert/index.js +2 -2
  207. package/dist/safe-bash-command-xmllint/index.js +22 -31
  208. package/dist/safe-bash-diff-engine/document.d.ts +2 -1
  209. package/dist/safe-bash-diff-engine/document.js +7 -4
  210. package/dist/safe-bash-presentation-engine/accessibility.js +31 -30
  211. package/dist/safe-bash-presentation-engine/animation-editing.js +16 -15
  212. package/dist/safe-bash-presentation-engine/animations.js +16 -15
  213. package/dist/safe-bash-presentation-engine/backgrounds.js +17 -16
  214. package/dist/safe-bash-presentation-engine/bytes.js +3 -3
  215. package/dist/safe-bash-presentation-engine/chart-editing.js +34 -33
  216. package/dist/safe-bash-presentation-engine/chart-object-operations.js +25 -24
  217. package/dist/safe-bash-presentation-engine/charts.js +31 -30
  218. package/dist/safe-bash-presentation-engine/command-placeholder.js +59 -55
  219. package/dist/safe-bash-presentation-engine/comments.js +17 -16
  220. package/dist/safe-bash-presentation-engine/connector-operations.js +32 -31
  221. package/dist/safe-bash-presentation-engine/connectors.js +29 -28
  222. package/dist/safe-bash-presentation-engine/content-types.js +4 -4
  223. package/dist/safe-bash-presentation-engine/creation.js +6 -6
  224. package/dist/safe-bash-presentation-engine/diff.js +32 -31
  225. package/dist/safe-bash-presentation-engine/drawing-enums.d.ts +10 -10
  226. package/dist/safe-bash-presentation-engine/drawing-format.js +20 -19
  227. package/dist/safe-bash-presentation-engine/drawing-operations.js +31 -30
  228. package/dist/safe-bash-presentation-engine/drawing-schema.js +21 -20
  229. package/dist/safe-bash-presentation-engine/equations.js +17 -16
  230. package/dist/safe-bash-presentation-engine/errors.js +2 -2
  231. package/dist/safe-bash-presentation-engine/fields.js +17 -16
  232. package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
  233. package/dist/safe-bash-presentation-engine/image-extraction.js +20 -19
  234. package/dist/safe-bash-presentation-engine/image-formatting.js +32 -31
  235. package/dist/safe-bash-presentation-engine/image-insertion.js +18 -17
  236. package/dist/safe-bash-presentation-engine/image-replacement.js +21 -20
  237. package/dist/safe-bash-presentation-engine/image-value.js +4 -4
  238. package/dist/safe-bash-presentation-engine/images.js +19 -18
  239. package/dist/safe-bash-presentation-engine/index.d.ts +6 -2
  240. package/dist/safe-bash-presentation-engine/index.js +112 -97
  241. package/dist/safe-bash-presentation-engine/layouts.js +16 -15
  242. package/dist/safe-bash-presentation-engine/length.js +3 -3
  243. package/dist/safe-bash-presentation-engine/links.js +16 -15
  244. package/dist/safe-bash-presentation-engine/masters.js +15 -14
  245. package/dist/safe-bash-presentation-engine/media-editing.js +24 -23
  246. package/dist/safe-bash-presentation-engine/media-extraction.js +17 -16
  247. package/dist/safe-bash-presentation-engine/media.js +16 -15
  248. package/dist/safe-bash-presentation-engine/memberships.js +15 -14
  249. package/dist/safe-bash-presentation-engine/notes.js +16 -15
  250. package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
  251. package/dist/safe-bash-presentation-engine/ole-insertion.js +20 -19
  252. package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
  253. package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
  254. package/dist/safe-bash-presentation-engine/package-tools.d.ts +3 -0
  255. package/dist/safe-bash-presentation-engine/package-tools.js +27 -17
  256. package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
  257. package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
  258. package/dist/safe-bash-presentation-engine/presentation-model.js +58 -54
  259. package/dist/safe-bash-presentation-engine/presentation-settings.js +14 -13
  260. package/dist/safe-bash-presentation-engine/properties.js +16 -15
  261. package/dist/safe-bash-presentation-engine/relationships.js +4 -4
  262. package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
  263. package/dist/safe-bash-presentation-engine/retained-archive-staging.d.ts +19 -0
  264. package/dist/safe-bash-presentation-engine/retained-extraction-output.d.ts +18 -0
  265. package/dist/safe-bash-presentation-engine/retained-inspection.js +14 -12
  266. package/dist/safe-bash-presentation-engine/retained-package-extraction.d.ts +22 -0
  267. package/dist/safe-bash-presentation-engine/retained-package-packing.d.ts +19 -0
  268. package/dist/safe-bash-presentation-engine/retained-package.d.ts +2 -0
  269. package/dist/safe-bash-presentation-engine/retained-package.js +6 -4
  270. package/dist/safe-bash-presentation-engine/retained-slide-publication.d.ts +24 -0
  271. package/dist/safe-bash-presentation-engine/retained-text.js +19 -17
  272. package/dist/safe-bash-presentation-engine/retained-xml-parts.d.ts +5 -1
  273. package/dist/safe-bash-presentation-engine/retained-xml-publication.d.ts +18 -0
  274. package/dist/safe-bash-presentation-engine/retained-xml-replacement.d.ts +13 -0
  275. package/dist/safe-bash-presentation-engine/sanitize.js +17 -16
  276. package/dist/safe-bash-presentation-engine/selectors.js +10 -10
  277. package/dist/safe-bash-presentation-engine/shape-groups.js +31 -30
  278. package/dist/safe-bash-presentation-engine/shape-operations.js +30 -29
  279. package/dist/safe-bash-presentation-engine/shape-path-operations.js +32 -31
  280. package/dist/safe-bash-presentation-engine/shape-paths.js +16 -15
  281. package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
  282. package/dist/safe-bash-presentation-engine/shape-selection.js +31 -30
  283. package/dist/safe-bash-presentation-engine/shape-transforms.js +18 -17
  284. package/dist/safe-bash-presentation-engine/shapes.d.ts +1 -1
  285. package/dist/safe-bash-presentation-engine/shapes.js +27 -26
  286. package/dist/safe-bash-presentation-engine/slide-copy.js +17 -16
  287. package/dist/safe-bash-presentation-engine/slide-import.js +18 -17
  288. package/dist/safe-bash-presentation-engine/slide-merge-split.js +20 -19
  289. package/dist/safe-bash-presentation-engine/slide-model.js +43 -42
  290. package/dist/safe-bash-presentation-engine/slide-removal.js +18 -17
  291. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
  292. package/dist/safe-bash-presentation-engine/slides.d.ts +1 -0
  293. package/dist/safe-bash-presentation-engine/slides.js +23 -17
  294. package/dist/safe-bash-presentation-engine/table-operations.js +33 -32
  295. package/dist/safe-bash-presentation-engine/table-spans.js +32 -31
  296. package/dist/safe-bash-presentation-engine/tables.js +31 -30
  297. package/dist/safe-bash-presentation-engine/tags.js +16 -15
  298. package/dist/safe-bash-presentation-engine/template-bindings.js +33 -32
  299. package/dist/safe-bash-presentation-engine/template-repeat.js +40 -39
  300. package/dist/safe-bash-presentation-engine/text-fitting.js +27 -26
  301. package/dist/safe-bash-presentation-engine/text-frames.js +27 -26
  302. package/dist/safe-bash-presentation-engine/text-paragraphs.js +27 -26
  303. package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
  304. package/dist/safe-bash-presentation-engine/text-replacement.js +17 -16
  305. package/dist/safe-bash-presentation-engine/text-runs.js +20 -19
  306. package/dist/safe-bash-presentation-engine/themes.js +16 -15
  307. package/dist/safe-bash-presentation-engine/transitions.js +16 -15
  308. package/dist/safe-bash-presentation-engine/validation.js +10 -9
  309. package/dist/safe-bash-presentation-engine/xml-parts.d.ts +2 -0
  310. package/dist/safe-bash-presentation-engine/xml-parts.js +23 -15
  311. package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
  312. package/dist/safe-bash-presentation-engine/xml.js +3 -3
  313. package/dist/safe-bash-regex-engine/index.js +1 -1
  314. package/dist/safe-bash-regex-engine/python-glob.js +1 -1
  315. package/dist/safe-bash-regex-engine/text/regex.d.ts +19 -0
  316. package/dist/safe-bash-regex-engine/text/regex.js +1 -1
  317. package/dist/safe-bash-xml-engine/document.js +3 -3
  318. package/dist/safe-bash-xml-engine/evaluate.js +1 -1
  319. package/dist/safe-bash-xml-engine/index.d.ts +1 -0
  320. package/dist/safe-bash-xml-engine/index.js +8 -4
  321. package/dist/safe-bash-xml-engine/query.js +2 -2
  322. package/dist/safe-bash-xml-engine/recovery.d.ts +10 -0
  323. package/dist/safe-bash-xml-engine/stored-document.d.ts +1 -1
  324. package/dist/safe-bash-xml-engine/stored-document.js +1 -1
  325. package/dist/safe-bash-xml-engine/stored-evaluate.js +1 -1
  326. package/dist/spreadsheet-engine/formulas/functions/python-printf.js +56 -33
  327. package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +2 -2
  328. package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +86 -24
  329. package/dist/spreadsheet-format-xls/biff-metadata.d.ts +1 -0
  330. package/dist/spreadsheet-format-xls/biff-metadata.js +2 -2
  331. package/dist/spreadsheet-format-xls/biff-properties-merge.d.ts +6 -2
  332. package/dist/spreadsheet-format-xls/biff-properties-merge.js +413 -296
  333. package/dist/spreadsheet-format-xls/biff-properties-write.js +40 -23
  334. package/dist/spreadsheet-format-xls/biff-properties.js +3 -68
  335. package/dist/spreadsheet-format-xls/biff-property-index.d.ts +23 -0
  336. package/dist/spreadsheet-format-xls/biff-property-index.js +93 -0
  337. package/dist/spreadsheet-format-xls/biff-property-name.d.ts +4 -0
  338. package/dist/spreadsheet-format-xls/biff-property-name.js +114 -0
  339. package/dist/spreadsheet-format-xls/biff-property-text.d.ts +6 -0
  340. package/dist/spreadsheet-format-xls/biff-property-text.js +68 -0
  341. package/dist/spreadsheet-format-xls/biff-property-transcode.d.ts +5 -0
  342. package/dist/spreadsheet-format-xls/biff-property-transcode.js +45 -0
  343. package/dist/spreadsheet-format-xls/biff-write-metadata.js +10 -1
  344. package/package.json +6 -3
  345. package/dist/safe-bash/command-chunks/biff-3EFLKBAH-NYWZOYQS.js +0 -4942
  346. package/dist/safe-bash/command-chunks/chunk-5Q22ZLNC.js +0 -127
  347. package/dist/safe-bash/command-chunks/chunk-JKLOBSMP.js +0 -56
  348. package/dist/safe-bash/command-chunks/chunk-JYTESTBS.js +0 -99
  349. package/dist/safe-bash/command-chunks/chunk-WH3TIOTS.js +0 -326
  350. package/dist/safe-bash/command-chunks/paradox-ZWWXYY4J-JYOSWSBL.js +0 -362
  351. package/dist/spreadsheet-format-xls/biff-properties-layout.js +0 -56
@@ -1,20 +1,14 @@
1
1
  import {
2
- PatchPublication,
3
- TargetDocuments,
4
- TargetOutput,
5
- equalTargetLines,
6
- targetBytes
7
- } from "./chunk-WH3TIOTS.js";
8
- import {
9
- unwrapPatch
10
- } from "./chunk-JKLOBSMP.js";
2
+ PatchPublication
3
+ } from "./chunk-PK36TVXB.js";
11
4
  import {
12
5
  parsePatch
13
- } from "./chunk-2VLAXKTS.js";
6
+ } from "./chunk-CTDC4LJT.js";
14
7
  import {
8
+ parseUnified,
15
9
  reversePatch,
16
10
  startIndex
17
- } from "./chunk-MOZD7RUY.js";
11
+ } from "./chunk-JORIVUPM.js";
18
12
  import {
19
13
  authorizeOutputs,
20
14
  authorizePaths,
@@ -31,10 +25,22 @@ import {
31
25
  safeTarget
32
26
  } from "./chunk-AJEQUVDN.js";
33
27
  import {
34
- rejectText
35
- } from "./chunk-JYTESTBS.js";
28
+ rejectBytes
29
+ } from "./chunk-63EMPQ7Z.js";
30
+ import {
31
+ TargetDocuments,
32
+ TargetOutput,
33
+ equalTargetLines,
34
+ targetBytes
35
+ } from "./chunk-73NYFNAS.js";
36
+
37
+ // packages/safe-bash-command-patch/src/patch.ts
38
+ import { closeDocumentResources as closeDocumentResources2 } from "../../safe-bash-diff-engine/document.js";
39
+ import { PagedStorage as PagedStorage2 } from "@poe-platform/safe-fs/storage";
36
40
 
37
41
  // packages/safe-bash-command-patch/src/stored-hunks.ts
42
+ import { closeDocumentResources } from "../../safe-bash-diff-engine/document.js";
43
+ import { PagedStorage } from "@poe-platform/safe-fs/storage";
38
44
  import { ToolError } from "../../safe-bash-diff-engine/shared.js";
39
45
  async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace = false, application, documents) {
40
46
  const source = { length: original.length, at(index) {
@@ -42,13 +48,34 @@ async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace
42
48
  } };
43
49
  budget.countLines(source.length);
44
50
  const result = new TargetOutput(documents);
51
+ const indices = new PagedStorage(budget.context, 16, documents.cache);
45
52
  try {
46
53
  let cursor = 0;
47
54
  let offset = 0;
48
55
  let outputOffset = 0;
49
56
  for (const [hunkIndex, hunk] of patch.hunks.entries()) {
50
57
  budget.step();
51
- const oldLines = hunk.lines.filter((line) => line.kind !== "+");
58
+ const oldIndex = indices.allocate((hunk.oldCount + hunk.newCount) * 8), newIndex = oldIndex + hunk.oldCount * 8;
59
+ let oldPosition = oldIndex, newPosition = newIndex;
60
+ const cell = new Uint8Array(8), view = new DataView(cell.buffer);
61
+ for (let index = 0; index < hunk.lines.length; index++) {
62
+ view.setFloat64(0, index, true);
63
+ if (hunk.lines[index].kind !== "+") {
64
+ await indices.write(oldPosition, cell);
65
+ oldPosition += 8;
66
+ }
67
+ if (hunk.lines[index].kind !== "-") {
68
+ await indices.write(newPosition, cell);
69
+ newPosition += 8;
70
+ }
71
+ budget.step();
72
+ const pause = budget.checkpoint();
73
+ if (pause) await pause;
74
+ }
75
+ const indexedLine = async (base, index) => {
76
+ const bytes = await indices.read(base + index * 8, 8);
77
+ return hunk.lines[new DataView(bytes.buffer).getFloat64(0, true)].text;
78
+ };
52
79
  let leading = 0;
53
80
  let trailing = 0;
54
81
  while (leading < hunk.lines.length && hunk.lines[leading].kind === " ") leading++;
@@ -65,11 +92,11 @@ async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace
65
92
  if (c) await c;
66
93
  }
67
94
  if (position < 0 || position > source.length - hunk.oldCount + suffixFuzz) return false;
68
- for (let lineIndex = 0; lineIndex < oldLines.length; lineIndex++) {
69
- if (lineIndex < prefixFuzz || lineIndex >= oldLines.length - suffixFuzz) continue;
95
+ for (let lineIndex = 0; lineIndex < hunk.oldCount; lineIndex++) {
96
+ if (lineIndex < prefixFuzz || lineIndex >= hunk.oldCount - suffixFuzz) continue;
70
97
  const actual = source.at(position + lineIndex);
71
98
  if (actual === void 0) return false;
72
- const expectedLine = oldLines[lineIndex].text;
99
+ const expectedLine = await indexedLine(oldIndex, lineIndex);
73
100
  if (!await equalTargetLines(actual, expectedLine, budget, ignoreWhitespace)) return false;
74
101
  {
75
102
  const c = budget.checkpoint();
@@ -105,7 +132,7 @@ async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace
105
132
  if (found >= 0) break;
106
133
  continue;
107
134
  }
108
- const retained = oldLines.length - Math.max(0, prefixFuzz) - suffixFuzz;
135
+ const retained = hunk.oldCount - Math.max(0, prefixFuzz) - suffixFuzz;
109
136
  if (retained === 0) {
110
137
  if (await matches(expected, Math.max(0, prefixFuzz), suffixFuzz)) {
111
138
  found = expected;
@@ -152,48 +179,46 @@ async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace
152
179
  if (found < 0 && application.merge && !misordered) {
153
180
  const position = Math.max(cursor, Math.min(source.length, expected));
154
181
  while (cursor < position) await result.append(source.at(cursor++));
155
- let local = Array.from({ length: Math.min(hunk.oldCount, source.length - cursor) }, (_, index) => source.at(cursor + index));
182
+ let localLength = Math.min(hunk.oldCount, source.length - cursor);
156
183
  let anchored = false;
157
- for (let index = 0; index < oldLines.length; index++) {
158
- if (await equalTargetLines(oldLines[index].text, local[index] ?? "", budget)) {
184
+ for (let index = 0; index < hunk.oldCount; index++) {
185
+ if (await equalTargetLines(await indexedLine(oldIndex, index), index < localLength ? source.at(cursor + index) : "", budget)) {
159
186
  anchored = true;
160
187
  break;
161
188
  }
162
189
  }
163
- if (!anchored) local = [];
164
- const incoming = hunk.lines.filter((line) => line.kind !== "-").map((line) => line.text);
165
- const base = oldLines.map((line) => line.text);
190
+ if (!anchored) localLength = 0;
166
191
  let prefix = 0;
167
192
  let suffix = 0;
168
- while (prefix < Math.min(local.length, incoming.length, base.length) && await equalTargetLines(local[prefix], incoming[prefix], budget) && await equalTargetLines(local[prefix], base[prefix], budget)) prefix++;
169
- while (suffix < Math.min(local.length, incoming.length, base.length) - prefix && await equalTargetLines(local[local.length - suffix - 1], incoming[incoming.length - suffix - 1], budget) && await equalTargetLines(local[local.length - suffix - 1], base[base.length - suffix - 1], budget)) suffix++;
193
+ while (prefix < Math.min(localLength, hunk.newCount, hunk.oldCount) && await equalTargetLines(source.at(cursor + prefix), await indexedLine(newIndex, prefix), budget) && await equalTargetLines(source.at(cursor + prefix), await indexedLine(oldIndex, prefix), budget)) prefix++;
194
+ while (suffix < Math.min(localLength, hunk.newCount, hunk.oldCount) - prefix && await equalTargetLines(source.at(cursor + localLength - suffix - 1), await indexedLine(newIndex, hunk.newCount - suffix - 1), budget) && await equalTargetLines(source.at(cursor + localLength - suffix - 1), await indexedLine(oldIndex, hunk.oldCount - suffix - 1), budget)) suffix++;
170
195
  {
171
196
  const c = budget.checkpoint();
172
197
  if (c) await c;
173
198
  }
174
- for (const line of local.slice(0, prefix)) await result.append(line);
199
+ for (let index = 0; index < prefix; index++) await result.append(source.at(cursor + index));
175
200
  const mergeStart = result.length + 1;
176
- let identical = local.length === incoming.length;
177
- for (let index = 0; identical && index < local.length; index++) identical = await equalTargetLines(local[index], incoming[index], budget);
201
+ let identical = localLength === hunk.newCount;
202
+ for (let index = 0; identical && index < localLength; index++) identical = await equalTargetLines(source.at(cursor + index), await indexedLine(newIndex, index), budget);
178
203
  if (identical) {
179
204
  const last = application.outcomes?.pop();
180
205
  if (last) application.outcomes.push({ ...last, failed: false, fuzz: 0, offset: position - startIndex(hunk.oldStart, hunk.oldCount) });
181
- for (const line of local.slice(prefix, local.length - suffix)) await result.append(line);
206
+ for (let index = prefix; index < localLength - suffix; index++) await result.append(source.at(cursor + index));
182
207
  } else {
183
208
  await result.append("<<<<<<<\n");
184
- for (const line of local.slice(prefix, local.length - suffix)) await result.append(line);
209
+ for (let index = prefix; index < localLength - suffix; index++) await result.append(source.at(cursor + index));
185
210
  if (application.merge === "diff3") {
186
211
  await result.append("|||||||\n");
187
- for (const line of base.slice(prefix, base.length - suffix)) await result.append(line);
212
+ for (let index = prefix; index < hunk.oldCount - suffix; index++) await result.append(await indexedLine(oldIndex, index));
188
213
  }
189
214
  await result.append("=======\n");
190
- for (const line of incoming.slice(prefix, incoming.length - suffix)) await result.append(line);
215
+ for (let index = prefix; index < hunk.newCount - suffix; index++) await result.append(await indexedLine(newIndex, index));
191
216
  await result.append(">>>>>>>\n");
192
217
  const last = application.outcomes?.pop();
193
218
  if (last) application.outcomes.push({ ...last, mergeRange: [mergeStart, result.length] });
194
219
  }
195
- for (const line of local.slice(local.length - suffix)) await result.append(line);
196
- cursor += local.length;
220
+ for (let index = localLength - suffix; index < localLength; index++) await result.append(source.at(cursor + index));
221
+ cursor += localLength;
197
222
  outputOffset = result.length - cursor;
198
223
  continue;
199
224
  }
@@ -202,46 +227,130 @@ async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace
202
227
  throw new ToolError(`hunk ${hunkIndex + 1} does not match ${patch.oldPath}`, 1);
203
228
  }
204
229
  while (cursor < found + matchedPrefixFuzz) await result.append(source.at(cursor++));
205
- let removed = [];
206
- let added = [];
207
- const flush = async () => {
208
- if (!removed.length && !added.length) return;
230
+ let changeStart = matchedPrefixFuzz, changeCursor = cursor;
231
+ const flush = async (end) => {
232
+ let removed = 0, added = 0;
233
+ for (let index = changeStart; index < end; index++) {
234
+ if (hunk.lines[index].kind === "+") added++;
235
+ else removed++;
236
+ budget.step();
237
+ const pause = budget.checkpoint();
238
+ if (pause) await pause;
239
+ }
240
+ if (!removed && !added) return;
209
241
  if (application.ifdef) {
210
- await result.append(`#${removed.length ? "ifndef" : "ifdef"} ${application.ifdef}
242
+ await result.append(`#${removed ? "ifndef" : "ifdef"} ${application.ifdef}
211
243
  `);
212
- for (const text of removed) await result.append(text);
213
- if (removed.length && added.length) await result.append("#else\n");
214
- for (const text of added) await result.append(text);
215
- await result.append("#endif\n");
216
- } else for (const text of added) await result.append(text);
217
- removed = [];
218
- added = [];
244
+ let position = changeCursor;
245
+ for (let index = changeStart; index < end; index++) if (hunk.lines[index].kind === "-") await result.append(source.at(position++) ?? hunk.lines[index].text);
246
+ if (removed && added) await result.append("#else\n");
247
+ }
248
+ for (let index = changeStart; index < end; index++) if (hunk.lines[index].kind === "+") await result.append(hunk.lines[index].text);
249
+ if (application.ifdef) await result.append("#endif\n");
219
250
  };
220
- for (const line of hunk.lines.slice(matchedPrefixFuzz, hunk.lines.length - matchedSuffixFuzz)) {
221
- if (line.kind === "+") added.push(line.text);
222
- else if (line.kind === " ") {
223
- await flush();
251
+ for (let index = matchedPrefixFuzz; index < hunk.lines.length - matchedSuffixFuzz; index++) {
252
+ const line = hunk.lines[index];
253
+ if (line.kind === " ") {
254
+ await flush(index);
224
255
  if (cursor < source.length) await result.append(source.at(cursor++));
225
- } else {
226
- removed.push(source.at(cursor) ?? line.text);
227
- cursor++;
228
- }
256
+ changeStart = index + 1;
257
+ changeCursor = cursor;
258
+ } else if (line.kind === "-") cursor++;
229
259
  }
230
- await flush();
260
+ await flush(hunk.lines.length - matchedSuffixFuzz);
231
261
  outputOffset = result.length - cursor;
232
262
  }
233
263
  while (cursor < source.length) await result.append(source.at(cursor++));
234
264
  return await result.finish();
235
265
  } finally {
236
- await result.close();
266
+ await closeDocumentResources([result, indices]);
267
+ }
268
+ }
269
+
270
+ // packages/safe-bash-command-patch/src/stored-input.ts
271
+ import { ToolError as ToolError2 } from "../../safe-bash-diff-engine/shared.js";
272
+ var StoredPatchInput = class {
273
+ constructor(document, crlf = false, start = 0, length = document.length - start) {
274
+ this.document = document;
275
+ this.crlf = crlf;
276
+ this.start = start;
277
+ this.length = length;
278
+ }
279
+ document;
280
+ crlf;
281
+ start;
282
+ length;
283
+ cachedIndex = -1;
284
+ cachedLine = "";
285
+ async read(index) {
286
+ if (index < 0 || index >= this.length) return void 0;
287
+ if (index === this.cachedIndex) return this.cachedLine;
288
+ const line = await this.document.line(this.start + index);
289
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
290
+ let text = "";
291
+ for await (const block of this.document.range(line.start, line.end - (this.crlf ? 2 : 1))) text += decoder.decode(block, { stream: true });
292
+ text += decoder.decode();
293
+ this.cachedIndex = index;
294
+ this.cachedLine = text;
295
+ return text;
296
+ }
297
+ async signature(index) {
298
+ const line = await this.document.line(this.start + index);
299
+ if (line.end - line.start !== (this.crlf ? 5 : 4)) return false;
300
+ const bytes = await this.document.data.read(8 + line.start, 3);
301
+ return bytes[0] === 45 && bytes[1] === 45 && bytes[2] === 32;
302
+ }
303
+ };
304
+ async function unwrapStoredPatch(document, budget) {
305
+ if (document.size && (await document.data.read(8 + document.size - 1, 1))[0] !== 10) throw new ToolError2("patch is truncated: missing final LF");
306
+ let crlf = true;
307
+ for (let index = 0; index < document.length; index++) {
308
+ const line = await document.line(index);
309
+ budget.step(line.end - line.start);
310
+ const pause = budget.checkpoint();
311
+ if (pause) await pause;
312
+ if (line.end - line.start < 2 || (await document.data.read(8 + line.end - 2, 1))[0] !== 13) {
313
+ crlf = false;
314
+ break;
315
+ }
316
+ if (index + 1 > budget.limits.maxLines) throw new ToolError2("transport line limit exceeded");
317
+ }
318
+ const input = new StoredPatchInput(document, crlf);
319
+ let start = 0;
320
+ if (/^(?:From [0-9a-f]{40,64} |(?:From|Date|Subject|To|Cc|MIME-Version|Content-Type):)/u.test(await input.read(0) ?? "")) {
321
+ while (start < input.length) {
322
+ budget.step();
323
+ const pause = budget.checkpoint();
324
+ if (pause) await pause;
325
+ const line = await input.read(start);
326
+ if (/^(?:--- |\*\*\* |diff |\d+(?:,\d+)?[acd]\d)/u.test(line)) break;
327
+ if (/^(?:old mode |new mode |new file mode |deleted file mode |rename |copy |similarity index |dissimilarity index |GIT binary patch|Binary files |index |@@|[+\\])/u.test(line)) throw new ToolError2("unsupported or malformed mail patch metadata");
328
+ if (++start > budget.limits.maxLines) throw new ToolError2("mail preamble limit exceeded");
329
+ }
330
+ if (start === input.length) throw new ToolError2("mail preamble without patch");
331
+ }
332
+ let end = input.length;
333
+ for (let index = start + 1; index < input.length; index++) {
334
+ budget.step();
335
+ const pause = budget.checkpoint();
336
+ if (pause) await pause;
337
+ if (!await input.signature(index)) continue;
338
+ end = index;
339
+ if (input.length - index > budget.limits.maxLines) throw new ToolError2("mail signature limit exceeded");
340
+ for (index++; index < input.length; index++) {
341
+ budget.step();
342
+ const pause2 = budget.checkpoint();
343
+ if (pause2) await pause2;
344
+ if (/^(?:diff |---|\+\+\+|\*\*\*|@@|index |old mode |new mode |new file mode |deleted file mode |rename |copy |similarity index |dissimilarity index |GIT binary patch|Binary files |[+\\]|\d+(?:,\d+)?[acd]\d)/u.test(await input.read(index))) throw new ToolError2("patch data after mail signature");
345
+ }
237
346
  }
347
+ return new StoredPatchInput(document, crlf, start, end - start);
238
348
  }
239
349
 
240
350
  // packages/safe-bash-command-patch/src/patch.ts
241
351
  import { FsError, dirname, pipeBytes, resolvePath, writeBytes } from "../../safe-bash-contracts/index.js";
242
352
  import { publicDiagnosticMessage } from "../../safe-bash-contracts/diagnostics.js";
243
- import { Budget as Budget2, ToolError as ToolError2, definition, host, inspect, integer } from "../../safe-bash-diff-engine/shared.js";
244
- import { encodeBytes } from "../../safe-bash-io-engine/byte-encoding.js";
353
+ import { Budget as Budget3, ToolError as ToolError3, definition, host, inspect, integer } from "../../safe-bash-diff-engine/shared.js";
245
354
  function flags(args) {
246
355
  const result = { input: "-", reverse: false, dryRun: false, atomic: false, quiet: false, force: false, backup: true, fuzz: 2, ignoreWhitespace: false, removeEmpty: false };
247
356
  const operands = [];
@@ -252,7 +361,7 @@ function flags(args) {
252
361
  if (["simple", "never"].includes(parameter)) result.versionControl = "simple";
253
362
  else if (["numbered", "t"].includes(parameter)) result.versionControl = "numbered";
254
363
  else if (["existing", "nil"].includes(parameter)) result.versionControl = "existing";
255
- else throw new ToolError2(`invalid version control: ${parameter}`);
364
+ else throw new ToolError3(`invalid version control: ${parameter}`);
256
365
  };
257
366
  let literal = false;
258
367
  let backupSelected = false;
@@ -260,7 +369,7 @@ function flags(args) {
260
369
  const arg = args[index];
261
370
  const value = (attached, name) => {
262
371
  const next = attached ?? args[++index];
263
- if (next === void 0) throw new ToolError2(`${name} requires an argument`);
372
+ if (next === void 0) throw new ToolError3(`${name} requires an argument`);
264
373
  return next;
265
374
  };
266
375
  if (literal || arg === "-" || !arg.startsWith("-")) operands.push(arg);
@@ -281,7 +390,7 @@ function flags(args) {
281
390
  else if (arg === "--set-utc") result.setTime = "utc";
282
391
  else if (arg === "--merge" || arg.startsWith("--merge=")) {
283
392
  const style = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : "merge";
284
- if (style !== "merge" && style !== "diff3") throw new ToolError2(`invalid merge style: ${style}`);
393
+ if (style !== "merge" && style !== "diff3") throw new ToolError3(`invalid merge style: ${style}`);
285
394
  result.merge = style;
286
395
  } else if (arg === "--backup") result.alwaysBackup = true;
287
396
  else if (arg === "--forward") result.forward = true;
@@ -302,13 +411,13 @@ function flags(args) {
302
411
  const parameter = value(arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : void 0, name);
303
412
  if (name === "--ifdef") result.ifdef = parameter;
304
413
  else if (name === "--quoting-style") {
305
- if (!["literal", "shell", "shell-always", "shell-escape", "shell-escape-always", "c", "escape", "locale", "clocale"].includes(parameter)) throw new ToolError2(`invalid quoting style: ${parameter}`);
414
+ if (!["literal", "shell", "shell-always", "shell-escape", "shell-escape-always", "c", "escape", "locale", "clocale"].includes(parameter)) throw new ToolError3(`invalid quoting style: ${parameter}`);
306
415
  result.quotingStyle = parameter;
307
416
  } else if (name === "--reject-format") {
308
- if (parameter !== "unified" && parameter !== "context") throw new ToolError2(`invalid reject format: ${parameter}`);
417
+ if (parameter !== "unified" && parameter !== "context") throw new ToolError3(`invalid reject format: ${parameter}`);
309
418
  result.rejectFormat = parameter;
310
419
  } else if (name === "--read-only") {
311
- if (!["ignore", "warn", "fail"].includes(parameter)) throw new ToolError2(`invalid read-only behavior: ${parameter}`);
420
+ if (!["ignore", "warn", "fail"].includes(parameter)) throw new ToolError3(`invalid read-only behavior: ${parameter}`);
312
421
  result.readOnly = parameter;
313
422
  } else if (name === "--strip") result.strip = integer(parameter, "strip count");
314
423
  else if (name === "--fuzz") result.fuzz = integer(parameter, "fuzz");
@@ -320,9 +429,9 @@ function flags(args) {
320
429
  else if (name === "--basename-prefix") result.basenamePrefix = parameter;
321
430
  else if (name === "--version-control") versionControl(parameter);
322
431
  else if (name === "--get") {
323
- if (parameter !== "0") throw new ToolError2("version-control acquisition is unsupported; use --get=0");
432
+ if (parameter !== "0") throw new ToolError3("version-control acquisition is unsupported; use --get=0");
324
433
  } else result.input = parameter;
325
- } else if (arg.startsWith("--")) throw new ToolError2(`unsupported option: ${arg}`);
434
+ } else if (arg.startsWith("--")) throw new ToolError3(`unsupported option: ${arg}`);
326
435
  else for (let offset = 1; offset < arg.length; offset++) {
327
436
  const flag = arg[offset];
328
437
  if (flag === "R") result.reverse = true;
@@ -353,18 +462,18 @@ function flags(args) {
353
462
  else if (flag === "Y") result.basenamePrefix = parameter;
354
463
  else if (flag === "V") versionControl(parameter);
355
464
  else if (flag === "g") {
356
- if (parameter !== "0") throw new ToolError2("version-control acquisition is unsupported; use -g0");
465
+ if (parameter !== "0") throw new ToolError3("version-control acquisition is unsupported; use -g0");
357
466
  } else result.input = parameter;
358
467
  break;
359
- } else throw new ToolError2(`unsupported option: -${flag}`);
468
+ } else throw new ToolError3(`unsupported option: -${flag}`);
360
469
  }
361
470
  }
362
- if (operands.length > 2) throw new ToolError2("expected at most a target file and a patch input file");
471
+ if (operands.length > 2) throw new ToolError3("expected at most a target file and a patch input file");
363
472
  if (operands.length) result.target = operands[0];
364
473
  if (operands.length === 2) result.input = operands[1];
365
- if (!result.input || result.input.includes("\0")) throw new ToolError2("invalid patch input path");
366
- for (const path of [result.output, result.directory]) if (path !== void 0 && (!path || path.includes("\0"))) throw new ToolError2("invalid patch option path");
367
- if (result.ifdef !== void 0 && (!result.ifdef || [...result.ifdef].some((c) => !"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_".includes(c)))) throw new ToolError2("invalid ifdef symbol");
474
+ if (!result.input || result.input.includes("\0")) throw new ToolError3("invalid patch input path");
475
+ for (const path of [result.output, result.directory]) if (path !== void 0 && (!path || path.includes("\0"))) throw new ToolError3("invalid patch option path");
476
+ if (result.ifdef !== void 0 && (!result.ifdef || [...result.ifdef].some((c) => !"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_".includes(c)))) throw new ToolError3("invalid ifdef symbol");
368
477
  if (result.merge) result.fuzz = 0;
369
478
  if (result.posix && !backupSelected) result.backup = false;
370
479
  return result;
@@ -425,12 +534,12 @@ async function unchanged(item, budget, documents) {
425
534
  if (item.sourcePath !== void 0) {
426
535
  const source = await inspect(budget, item.sourcePath);
427
536
  regular(source, item.sourcePath);
428
- if (source === void 0 !== (item.sourceOriginal === void 0) || source && !await sameTarget(item.sourcePath, item.sourceOriginal, documents)) throw new ToolError2(`target changed during preflight: ${item.sourcePath}`, 1);
537
+ if (source === void 0 !== (item.sourceOriginal === void 0) || source && !await sameTarget(item.sourcePath, item.sourceOriginal, documents)) throw new ToolError3(`target changed during preflight: ${item.sourcePath}`, 1);
429
538
  }
430
539
  const stat = await inspect(budget, item.path);
431
540
  regular(stat, item.path);
432
541
  if (stat === void 0 !== (item.original === void 0) || item.original !== void 0 && !await sameTarget(item.path, item.original, documents)) {
433
- throw new ToolError2(`target changed during preflight: ${item.path}`, 1);
542
+ throw new ToolError3(`target changed during preflight: ${item.path}`, 1);
434
543
  }
435
544
  for (const path of [item.backupPath, item.rejectPath]) {
436
545
  if (path !== void 0) regular(await inspect(budget, path), path);
@@ -442,13 +551,12 @@ async function publish(item, budget, rejects, publication, documents) {
442
551
  await unchanged(item, budget, documents);
443
552
  const write = async (path, text, append = false, createParents = true, mode, mtimeMs) => {
444
553
  if (createParents) await ensureParents(path, budget);
445
- else if ((await inspect(budget, dirname(path)))?.type !== "directory") throw new ToolError2(`reject parent does not exist: ${dirname(path)}`);
554
+ else if ((await inspect(budget, dirname(path)))?.type !== "directory") throw new ToolError3(`reject parent does not exist: ${dirname(path)}`);
446
555
  const stat = await inspect(budget, path);
447
556
  regular(stat, path);
448
557
  const capabilities = await host(context, async () => await context.fs.capabilitiesFor?.(path, { signal: context.signal, create: true }) ?? context.fs.capabilities);
449
- if (capabilities?.atomicStagingAncestry !== true && !(publication.trusted && capabilities?.trustedOwnedStaging === true)) throw new ToolError2("filesystem does not support race-safe patch publication");
558
+ if (capabilities?.atomicStagingAncestry !== true && !(publication.trusted && capabilities?.trustedOwnedStaging === true)) throw new ToolError3("filesystem does not support race-safe patch publication");
450
559
  const publicationMode = capabilities?.permissions === false ? void 0 : mode ?? (stat ? stat.mode & 4095 : void 0);
451
- if (typeof text === "string") text = await documents.load(targetBytes(text));
452
560
  if (append && stat) text = await documents.concat(await documents.read(path), text);
453
561
  await publication.write(path, text.range(0, text.size), stat, publicationMode, mtimeMs);
454
562
  };
@@ -457,7 +565,7 @@ async function publish(item, budget, rejects, publication, documents) {
457
565
  if (item.original !== void 0) {
458
566
  const expected = await inspect(budget, item.path);
459
567
  regular(expected, item.path);
460
- if (!expected) throw new ToolError2(`target changed during publication: ${item.path}`, 1);
568
+ if (!expected) throw new ToolError3(`target changed during publication: ${item.path}`, 1);
461
569
  await publication.remove(item.path, expected);
462
570
  }
463
571
  } else if (!item.skipWrite) {
@@ -473,9 +581,9 @@ async function run(context, budget) {
473
581
  const outputToStdout = options.output === "-";
474
582
  if (options.directory !== void 0) {
475
583
  const cwd = resolvePath(context.cwd, options.directory);
476
- if ((await inspect(budget, cwd))?.type !== "directory") throw new ToolError2(`not a directory: ${options.directory}`);
584
+ if ((await inspect(budget, cwd))?.type !== "directory") throw new ToolError3(`not a directory: ${options.directory}`);
477
585
  context = { ...context, cwd };
478
- budget = new Budget2(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
586
+ budget = new Budget3(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
479
587
  }
480
588
  let publication = new PatchPublication(context);
481
589
  if (!options.dryRun) {
@@ -483,8 +591,8 @@ async function run(context, budget) {
483
591
  const capabilities = await host(context, async () => await fs.capabilitiesFor?.(context.cwd, { signal: context.signal }) ?? fs.capabilities);
484
592
  if (capabilities.readOnly === true) throw new FsError("EROFS", { syscall: "patch", path: context.cwd });
485
593
  const trusted = capabilities.atomicStagingAncestry !== true && capabilities.trustedOwnedStaging === true;
486
- if ((trusted ? !fs.prepareDirectory || !fs.removeFileConditional : !fs.confineExtraction || capabilities.atomicStagingAncestry !== true) || !fs.createStagedFile || !fs.publishStagedFile || !fs.removeStagedFile) {
487
- throw new ToolError2("filesystem does not support race-safe patch publication");
594
+ if ((trusted ? !fs.prepareDirectory || !fs.removeFileConditional || !fs.writeFileConditional : !fs.confineExtraction || capabilities.atomicStagingAncestry !== true) || !fs.createStagedFile || !fs.publishStagedFile || !fs.removeStagedFile) {
595
+ throw new ToolError3("filesystem does not support race-safe patch publication");
488
596
  }
489
597
  publication = new PatchPublication(context, trusted);
490
598
  await publication.capture(`${context.cwd === "/" ? "" : context.cwd}/.patch-admission`);
@@ -498,28 +606,41 @@ async function run(context, budget) {
498
606
  return typeof value === "function" ? value.bind(selected) : value;
499
607
  }
500
608
  }) };
501
- budget = new Budget2(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
609
+ budget = new Budget3(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
502
610
  }
503
611
  const documents = new TargetDocuments(budget);
612
+ const messages = new PagedStorage2(budget.context, 16, documents.cache);
504
613
  try {
505
614
  const empty = await documents.load({ async *[Symbol.asyncIterator]() {
506
615
  } });
507
616
  const output = options.output === void 0 ? void 0 : safeTarget(options.output, 0, true);
508
- if (options.output !== void 0 && output === void 0) throw new ToolError2("/dev/null is not an output file");
617
+ if (options.output !== void 0 && output === void 0) throw new ToolError3("/dev/null is not an output file");
509
618
  const outputPath = output === void 0 || outputToStdout ? void 0 : resolvePath(context.cwd, output);
510
619
  const explicit = options.target === void 0 ? void 0 : safeTarget(options.target, 0, true);
511
- if (options.target !== void 0 && explicit === void 0) throw new ToolError2("/dev/null is not an explicit target");
620
+ if (options.target !== void 0 && explicit === void 0) throw new ToolError3("/dev/null is not an explicit target");
512
621
  if (options.input !== "-") {
513
622
  const stat = await inspect(budget, options.input);
514
- if (stat?.type !== "file") throw new ToolError2("patch input must be a regular file");
623
+ if (stat?.type !== "file") throw new ToolError3("patch input must be a regular file");
515
624
  }
516
- const input = await budget.read(options.input === "-" ? "-" : resolvePath(context.cwd, options.input));
625
+ const inputPath = resolvePath(context.cwd, options.input);
626
+ const inputCapabilities = options.input === "-" ? void 0 : await host(context, async () => await context.fs.capabilitiesFor?.(inputPath, { signal: context.signal }) ?? context.fs.capabilities);
627
+ const input = options.input === "-" ? await documents.load(budget.stdinSource()) : inputCapabilities?.retainedRead && context.fs.openReadFile ? await documents.read(inputPath) : context.fs.readStream && inputCapabilities?.streamingRead !== false ? await documents.load(budget.streamSource(inputPath)) : await documents.load(targetBytes(await budget.read(inputPath)));
517
628
  const progress = options.atomic ? void 0 : {};
518
- const sections = await parsePatch(await unwrapPatch(input, budget), budget, options.format, explicit, progress);
629
+ const sections = await parsePatch(await unwrapStoredPatch(input, budget), budget, options.format, explicit, progress, async (chunks) => {
630
+ const converted = await documents.load({ async *[Symbol.asyncIterator]() {
631
+ for await (const chunk of chunks) yield* targetBytes(chunk);
632
+ } });
633
+ try {
634
+ return await parseUnified(new StoredPatchInput(converted), budget);
635
+ } finally {
636
+ await documents.release(converted);
637
+ }
638
+ });
639
+ await documents.release(input);
519
640
  const parsed = options.format === "normal" ? sections : sections.filter((patch) => !patch.unlocated);
520
- if (sections.length && !parsed.length) throw new ToolError2("no identifiable patch; normal input requires a target, Index header, or -n");
641
+ if (sections.length && !parsed.length) throw new ToolError3("no identifiable patch; normal input requires a target, Index header, or -n");
521
642
  const reject = options.reject === void 0 || options.reject === "-" ? options.reject : safeTarget(options.reject, 0, true);
522
- if (options.reject !== void 0 && reject === void 0) throw new ToolError2("/dev/null is not a reject file; use -r -");
643
+ if (options.reject !== void 0 && reject === void 0) throw new ToolError3("/dev/null is not a reject file; use -r -");
523
644
  const paths = {
524
645
  strip: options.strip,
525
646
  explicit,
@@ -556,23 +677,37 @@ async function run(context, budget) {
556
677
  const backupPaths = /* @__PURE__ */ new Set();
557
678
  const rejectPaths = /* @__PURE__ */ new Set();
558
679
  const parents = /* @__PURE__ */ new Set();
559
- const messages = [];
680
+ let messageSize = 0, messagePosition = 0;
560
681
  let exitCode = 0;
561
682
  let committed = 0;
562
683
  let publishing = false;
563
684
  let activePath;
564
685
  let outputContents = empty;
565
686
  const statusSink = outputToStdout ? context.stderr : context.stdout;
566
- const status = async (text) => {
687
+ const appendStatus = async (text) => {
567
688
  if (!text) return;
568
689
  budget.output(text);
569
- if (options.atomic) messages.push(text);
570
- else await writeBytes(statusSink, encodeBytes(text), context.signal);
690
+ for await (const bytes of targetBytes(text)) {
691
+ await messages.append(bytes);
692
+ messageSize += bytes.length;
693
+ }
694
+ };
695
+ const flushStatus = async (final = false) => {
696
+ if (options.atomic && !final) return;
697
+ while (messagePosition < messageSize) {
698
+ const bytes = await messages.read(8 + messagePosition, Math.min(16384, messageSize - messagePosition));
699
+ await writeBytes(statusSink, bytes, context.signal);
700
+ messagePosition += bytes.length;
701
+ }
702
+ };
703
+ const status = async (text) => {
704
+ await appendStatus(text);
705
+ await flushStatus();
571
706
  };
572
707
  const applySection = async (authorizedPatch) => {
573
708
  const sourcePatch = authorizedPatch.patch;
574
709
  if (sourcePatch.unlocated) {
575
- if (options.atomic) throw new ToolError2("no file to patch; provide a target or Index header", 1);
710
+ if (options.atomic) throw new ToolError3("no file to patch; provide a target or Index header", 1);
576
711
  await status(`No file to patch. Skipping patch.
577
712
  ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
578
713
  `);
@@ -584,7 +719,7 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
584
719
  activePath = path;
585
720
  const pruning = pruneParents(name, context.cwd).filter((parent) => parent !== context.cwd);
586
721
  if (!options.dryRun) await publication.capture(path, pruning);
587
- if (path === paths.input || backupPaths.has(path) || rejectPaths.has(path)) throw new ToolError2(`patch target aliases input or an earlier output: ${path}`);
722
+ if (path === paths.input || backupPaths.has(path) || rejectPaths.has(path)) throw new ToolError3(`patch target aliases input or an earlier output: ${path}`);
588
723
  targets.add(path);
589
724
  const prior = options.atomic ? staged.get(path) : void 0;
590
725
  const stat = await inspect(budget, path);
@@ -596,12 +731,12 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
596
731
  await status(`File ${name} is read-only; ${refuse ? "refusing to patch" : "trying to patch anyway"}
597
732
  `);
598
733
  if (refuse) {
599
- if (options.atomic) throw new ToolError2(`read-only target: ${name}`, 1);
734
+ if (options.atomic) throw new ToolError3(`read-only target: ${name}`, 1);
600
735
  const destination = rejectName(outputToStdout ? "-" : name, paths);
601
736
  const rejectPath2 = options.dryRun || destination === void 0 ? void 0 : resolvePath(context.cwd, destination);
602
737
  if (rejectPath2 !== void 0) {
603
738
  await authorizeOutputs([rejectPath2], targets, paths.input, budget);
604
- if (backupPaths.has(rejectPath2)) throw new ToolError2("reject path aliases another section's backup");
739
+ if (backupPaths.has(rejectPath2)) throw new ToolError3("reject path aliases another section's backup");
605
740
  const patch = options.reverse ? reversePatch(sourcePatch) : sourcePatch;
606
741
  const outcomes2 = patch.hunks.map((hunk, index) => ({
607
742
  hunk,
@@ -613,7 +748,7 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
613
748
  offset: 0,
614
749
  fuzz: 0
615
750
  }));
616
- const reject2 = await rejectText(sourcePatch, outcomes2, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, options.reverse, budget, options.rejectFormat);
751
+ const reject2 = await documents.load(rejectBytes(sourcePatch, outcomes2, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, options.reverse, budget, options.rejectFormat));
617
752
  const original2 = await documents.read(path);
618
753
  publishing = true;
619
754
  await publish({ path, original: original2, result: original2, remove: false, skipWrite: true, rejectPath: rejectPath2, reject: reject2, parents: [] }, budget, rejects, publication, documents);
@@ -640,7 +775,7 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
640
775
  }
641
776
  const applied = await applyContent(sourcePatch, current, exists, options, budget, documents);
642
777
  if (!applied) {
643
- if (options.atomic) throw new ToolError2(`patch target does not exist: ${path}`, 1);
778
+ if (options.atomic) throw new ToolError3(`patch target does not exist: ${path}`, 1);
644
779
  await status(`No file to patch. Skipping patch ${name}.
645
780
  ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
646
781
  `);
@@ -657,17 +792,17 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
657
792
  }
658
793
  const failed = outcomes.filter((outcome) => outcome.failed);
659
794
  const conflict = failed.length > 0 || deletion && result.size !== 0;
660
- if (options.atomic && conflict) throw new ToolError2(failed.length ? `hunk ${failed[0].index} does not match ${name}` : `deletion patch leaves content: ${name}`, 1);
795
+ if (options.atomic && conflict) throw new ToolError3(failed.length ? `hunk ${failed[0].index} does not match ${name}` : `deletion patch leaves content: ${name}`, 1);
661
796
  if (conflict) exitCode = 1;
662
797
  const mismatch = reverseMismatch || outcomes.some((outcome) => outcome.failed || outcome.offset !== 0 || outcome.fuzz !== 0);
663
798
  const backup = !options.dryRun && !outputToStdout && (options.alwaysBackup || options.backup && mismatch) && !touched.has(path) ? original ?? empty : void 0;
664
799
  const backupPath = backup === void 0 ? prior?.backupPath : await backupName(path, budget, options);
665
800
  const rejectDestination = rejectName(outputToStdout ? "-" : name, paths);
666
801
  const rejectPath = !options.dryRun && !options.merge && failed.length && rejectDestination !== void 0 ? resolvePath(context.cwd, rejectDestination) : void 0;
667
- const rejected = rejectPath === void 0 ? void 0 : await rejectText(sourcePatch, outcomes, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, reversed, budget, options.rejectFormat);
802
+ const rejected = rejectPath === void 0 ? void 0 : await documents.load(rejectBytes(sourcePatch, outcomes, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, reversed, budget, options.rejectFormat));
668
803
  await authorizeOutputs([outputPath, backupPath, rejectPath], targets, paths.input, budget);
669
804
  if (backupPath !== void 0 && rejectPaths.has(backupPath) || rejectPath !== void 0 && backupPaths.has(rejectPath)) {
670
- throw new ToolError2("reject path aliases another section's backup");
805
+ throw new ToolError3("reject path aliases another section's backup");
671
806
  }
672
807
  if (backupPath !== void 0) backupPaths.add(backupPath);
673
808
  if (rejectPath !== void 0) rejectPaths.add(rejectPath);
@@ -686,7 +821,7 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
686
821
  else if (!options.force && mismatch) timeMessage = `Not setting time of file ${name} (contents mismatch)
687
822
  `;
688
823
  else {
689
- if (!options.dryRun && !context.fs.utimes) throw new ToolError2("filesystem does not support setting timestamps");
824
+ if (!options.dryRun && !context.fs.utimes) throw new ToolError3("filesystem does not support setting timestamps");
690
825
  mtimeMs = newTime;
691
826
  }
692
827
  }
@@ -706,38 +841,38 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
706
841
  parents: remove ? pruning : []
707
842
  };
708
843
  const displayName = quotePatchName(name, options.quotingStyle);
709
- let message = options.quiet ? "" : `${options.dryRun ? "checking" : "patching"} file ${output === void 0 ? displayName : `${quotePatchName(output, options.quotingStyle)} (read from ${displayName})`}
710
- `;
844
+ budget.outputLength(result.size);
845
+ if (backup !== void 0) budget.outputLength(backup.size);
711
846
  if (options.verbose) {
712
847
  const format = sourcePatch.format ?? "unified";
713
848
  const headers = sourcePatch.oldHeader === void 0 ? "" : `|${format === "context" ? "***" : "---"} ${sourcePatch.oldHeader}
714
849
  |${format === "context" ? "---" : "+++"} ${sourcePatch.newHeader}
715
850
  `;
716
- message = `Hmm... Looks like a ${format} diff to me...
851
+ await appendStatus(`Hmm... Looks like a ${format} diff to me...
717
852
  The text leading up to this was:
718
853
  --------------------------
719
854
  ${headers}--------------------------
720
- ` + message;
855
+ `);
721
856
  }
722
- if (autoReversed) message += "Reversed (or previously applied) patch detected! Assuming -R.\n";
857
+ if (!options.quiet) await appendStatus(`${options.dryRun ? "checking" : "patching"} file ${output === void 0 ? displayName : `${quotePatchName(output, options.quotingStyle)} (read from ${displayName})`}
858
+ `);
859
+ if (autoReversed) await appendStatus("Reversed (or previously applied) patch detected! Assuming -R.\n");
723
860
  for (const outcome of outcomes) {
724
- if (outcome.misordered) message += "misordered hunks! output would be garbled\n";
861
+ if (outcome.misordered) await appendStatus("misordered hunks! output would be garbled\n");
725
862
  if (options.quiet) continue;
726
- if (outcome.failed && options.merge) message += `Hunk #${outcome.index} NOT MERGED at ${outcome.mergeRange?.[0] ?? outcome.line}-${outcome.mergeRange?.[1] ?? outcome.line}.
727
- `;
728
- else if (outcome.failed) message += `Hunk #${outcome.index} FAILED at ${outcome.line}.
729
- `;
730
- else if (options.verbose || outcome.offset || outcome.fuzz) message += `Hunk #${outcome.index} succeeded at ${outcome.line}${outcome.fuzz ? ` with fuzz ${outcome.fuzz}` : ""}${outcome.offset ? ` (offset ${outcome.offset} ${outcome.offset === 1 ? "line" : "lines"})` : ""}.
731
- `;
863
+ if (outcome.failed && options.merge) await appendStatus(`Hunk #${outcome.index} NOT MERGED at ${outcome.mergeRange?.[0] ?? outcome.line}-${outcome.mergeRange?.[1] ?? outcome.line}.
864
+ `);
865
+ else if (outcome.failed) await appendStatus(`Hunk #${outcome.index} FAILED at ${outcome.line}.
866
+ `);
867
+ else if (options.verbose || outcome.offset || outcome.fuzz) await appendStatus(`Hunk #${outcome.index} succeeded at ${outcome.line}${outcome.fuzz ? ` with fuzz ${outcome.fuzz}` : ""}${outcome.offset ? ` (offset ${outcome.offset} ${outcome.offset === 1 ? "line" : "lines"})` : ""}.
868
+ `);
732
869
  }
733
- if (failed.length && !options.merge) message += `${failed.length} out of ${outcomes.length} ${outcomes.length === 1 ? "hunk" : "hunks"} FAILED${options.dryRun || rejectPath === void 0 ? "" : ` -- saving rejects to file ${rejectDestination}`}
734
- `;
735
- if (deletion && result.size !== 0) message += `Not deleting file ${name} as content differs from patch
736
- `;
737
- message += timeMessage;
738
- budget.outputLength(result.size);
739
- if (backup !== void 0) budget.outputLength(backup.size);
740
- await status(message);
870
+ if (failed.length && !options.merge) await appendStatus(`${failed.length} out of ${outcomes.length} ${outcomes.length === 1 ? "hunk" : "hunks"} FAILED${options.dryRun || rejectPath === void 0 ? "" : ` -- saving rejects to file ${rejectDestination}`}
871
+ `);
872
+ if (deletion && result.size !== 0) await appendStatus(`Not deleting file ${name} as content differs from patch
873
+ `);
874
+ await appendStatus(timeMessage);
875
+ await flushStatus();
741
876
  touched.add(path);
742
877
  if (options.atomic) {
743
878
  if (outputToStdout) stdoutItems.push(item);
@@ -761,7 +896,7 @@ ${headers}--------------------------
761
896
  } catch (error) {
762
897
  context.signal.throwIfAborted();
763
898
  if (committed === 0 && !publishing) throw error;
764
- throw new ToolError2(`commit stopped; ${committed}/${authorized.length} files committed; failing operation may have side effects; path ${activePath}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
899
+ throw new ToolError3(`commit stopped; ${committed}/${authorized.length} files committed; failing operation may have side effects; path ${activePath}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
765
900
  }
766
901
  }
767
902
  if (options.atomic && (!options.dryRun || outputToStdout)) {
@@ -774,18 +909,18 @@ ${headers}--------------------------
774
909
  committed++;
775
910
  } catch (error) {
776
911
  context.signal.throwIfAborted();
777
- throw new ToolError2(`commit stopped; ${committed}/${prepared.length} files committed; failing operation may have side effects; path ${item.path}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
912
+ throw new ToolError3(`commit stopped; ${committed}/${prepared.length} files committed; failing operation may have side effects; path ${item.path}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
778
913
  }
779
914
  for (const parent of item.parents) parents.add(parent);
780
915
  }
781
916
  }
782
917
  if (!options.dryRun) await pruneDirectories(parents, budget);
783
918
  if (options.verbose) await status("done\n");
784
- if (options.atomic && (!options.quiet || messages.length)) await writeBytes(statusSink, encodeBytes(messages.join("")), context.signal);
919
+ await flushStatus(true);
785
920
  if (progress?.error) throw progress.error;
786
921
  return exitCode;
787
922
  } finally {
788
- await documents.close();
923
+ await closeDocumentResources2([messages, documents]);
789
924
  }
790
925
  }
791
926
  function patchCommand(options = {}) {