@poe-platform/safe-bash 0.1.802 → 0.1.804

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 (748) hide show
  1. package/README.md +60 -33
  2. package/dist/image-ast/ast.d.ts +1 -0
  3. package/dist/image-ast/browser/ast.d.ts +1 -0
  4. package/dist/image-ast/browser/codecs/jpeg.d.ts +2 -2
  5. package/dist/image-ast/codecs/jpeg.d.ts +2 -2
  6. package/dist/image-ast/index.browser.js +692 -8355
  7. package/dist/image-ast/index.js +692 -8355
  8. package/dist/mp4-ast/codecs.d.ts +7 -2
  9. package/dist/safe-bash/chunks/{chunk-CHYGPFVM.js → chunk-22SX3F2R.js} +1 -1
  10. package/dist/safe-bash/chunks/{chunk-FBUCWVTE.js → chunk-2IVBJTBD.js} +1 -1
  11. package/dist/safe-bash/chunks/chunk-2POETUMB.js +190 -0
  12. package/dist/safe-bash/chunks/{chunk-XVOSKJE2.js → chunk-47D7WBJK.js} +1 -1
  13. package/dist/safe-bash/chunks/{chunk-VKNVHEX3.js → chunk-4ESI236Y.js} +1 -1
  14. package/dist/safe-bash/chunks/{chunk-74GHTNJA.js → chunk-4KTMKD5W.js} +1 -1
  15. package/dist/safe-bash/chunks/{chunk-55YJASTN.js → chunk-4T53AERN.js} +1 -1
  16. package/dist/safe-bash/chunks/{chunk-DQP3VHSB.js → chunk-5XIFJVOO.js} +1 -1
  17. package/dist/safe-bash/chunks/{chunk-NZQXYWA3.js → chunk-62BOHHJT.js} +1 -2
  18. package/dist/safe-bash/chunks/{chunk-HZAMGT5I.js → chunk-67WIFM3N.js} +17 -6
  19. package/dist/safe-bash/chunks/{chunk-4D4N7IU2.js → chunk-6LNFRPW5.js} +2 -2
  20. package/dist/safe-bash/chunks/{chunk-6O77NL2S.js → chunk-6SMICPI3.js} +1 -1
  21. package/dist/safe-bash/chunks/{chunk-4BSJLKNM.js → chunk-7O76UFQD.js} +1 -1
  22. package/dist/safe-bash/chunks/{chunk-44ALJ4QG.js → chunk-AW5KIT6V.js} +3549 -84
  23. package/dist/safe-bash/chunks/{chunk-RSTHLAF3.js → chunk-B2Z73HTZ.js} +52 -28
  24. package/dist/safe-bash/chunks/chunk-B3ZMOJVM.js +319 -0
  25. package/dist/safe-bash/chunks/{chunk-7ZBU7KYV.js → chunk-CFAWS3O4.js} +1 -1
  26. package/dist/safe-bash/chunks/{chunk-I5HZ4FGE.js → chunk-CL2FCTTO.js} +1 -1
  27. package/dist/safe-bash/chunks/{chunk-KDNSPLII.js → chunk-CTXNARJH.js} +2 -1
  28. package/dist/safe-bash/chunks/{chunk-TFIBK2GI.js → chunk-D5Q7NFWI.js} +1 -1
  29. package/dist/safe-bash/chunks/{chunk-OQRVVGR6.js → chunk-DSOOVZ6Q.js} +1 -1
  30. package/dist/safe-bash/chunks/{chunk-VTH3MLDU.js → chunk-DUTAG6ZD.js} +1 -1
  31. package/dist/safe-bash/chunks/{chunk-XAQMU6OY.js → chunk-EE5YGFIZ.js} +1 -1
  32. package/dist/safe-bash/chunks/{chunk-FZE4HW6G.js → chunk-EJOYT2ME.js} +1 -1
  33. package/dist/safe-bash/chunks/chunk-FAAIR6EJ.js +887 -0
  34. package/dist/safe-bash/chunks/{chunk-OV6IHKO6.js → chunk-FOB2FZR4.js} +2 -2
  35. package/dist/safe-bash/chunks/chunk-G6V4RRSQ.js +14 -0
  36. package/dist/safe-bash/chunks/{chunk-UTBUUFDM.js → chunk-GGQAGQXQ.js} +1 -1
  37. package/dist/safe-bash/chunks/{chunk-K6VCD7IY.js → chunk-HIIYIJ5G.js} +2 -4
  38. package/dist/safe-bash/chunks/chunk-IOHH2GTI.js +56 -0
  39. package/dist/safe-bash/chunks/{chunk-CTVWDACF.js → chunk-IQW34XQT.js} +1 -1
  40. package/dist/safe-bash/chunks/{chunk-HZ7BWKQ3.js → chunk-IS572AAT.js} +1 -1
  41. package/dist/safe-bash/chunks/{chunk-AUSNDQTJ.js → chunk-JPSUHHOA.js} +1 -1
  42. package/dist/safe-bash/chunks/{chunk-ZVD5IS4V.js → chunk-KBZ4UB2O.js} +2 -2
  43. package/dist/safe-bash/chunks/{chunk-AM5ESLPH.js → chunk-KU5CVWKA.js} +1 -1
  44. package/dist/safe-bash/chunks/{chunk-NQCM3TYR.js → chunk-LPOVNKNB.js} +225 -176
  45. package/dist/safe-bash/chunks/{chunk-46Z5E5EV.js → chunk-MBOC3LZ4.js} +1 -1
  46. package/dist/safe-bash/chunks/{chunk-6PAVEFT3.js → chunk-N4BQFD3P.js} +1 -1
  47. package/dist/safe-bash/chunks/{chunk-CS4MNM6I.js → chunk-NGKCVNWS.js} +1 -1
  48. package/dist/safe-bash/chunks/{chunk-7R5BDCG7.js → chunk-OHML2BEU.js} +1 -1
  49. package/dist/safe-bash/chunks/{chunk-C5OWC2TL.js → chunk-OQ3AGYCZ.js} +1 -1
  50. package/dist/safe-bash/chunks/{chunk-B7TAL7S5.js → chunk-PTAEWLSE.js} +0 -2
  51. package/dist/safe-bash/chunks/{chunk-LVOBFF4D.js → chunk-Q4FNLOTI.js} +1 -1
  52. package/dist/safe-bash/chunks/chunk-Q5XO3NAS.js +1036 -0
  53. package/dist/safe-bash/chunks/{chunk-GEG3BWGE.js → chunk-RHFRJIWQ.js} +1 -1
  54. package/dist/safe-bash/chunks/chunk-RUR6J33T.js +11 -0
  55. package/dist/safe-bash/chunks/{chunk-WDLGKIHD.js → chunk-S4RFUUXO.js} +841 -26
  56. package/dist/safe-bash/chunks/{chunk-RRR7AQ24.js → chunk-SD2ISU5L.js} +1 -1
  57. package/dist/safe-bash/chunks/{chunk-3NDIFSNM.js → chunk-SUJ3NTMH.js} +3 -3
  58. package/dist/safe-bash/chunks/{chunk-R3NAKOED.js → chunk-SZRUU5HS.js} +2 -2
  59. package/dist/safe-bash/chunks/{chunk-PH63PLPZ.js → chunk-TC3F4UFF.js} +1 -1
  60. package/dist/safe-bash/chunks/{chunk-3R3AANOR.js → chunk-TCKYOLUE.js} +1 -1
  61. package/dist/safe-bash/chunks/{chunk-D3ANYGMC.js → chunk-UV4X32QU.js} +1 -1
  62. package/dist/safe-bash/chunks/{chunk-E7OYNDGL.js → chunk-V7QT2RWC.js} +1 -1
  63. package/dist/safe-bash/chunks/{chunk-SHEMU2Z7.js → chunk-W2IYOVHK.js} +839 -1211
  64. package/dist/safe-bash/chunks/{chunk-3HQU4OJO.js → chunk-XNGVOSGI.js} +1 -1
  65. package/dist/safe-bash/chunks/{chunk-J42RIHHJ.js → chunk-XQWCQSRN.js} +1 -1
  66. package/dist/safe-bash/chunks/{chunk-BJA5XNP6.js → chunk-Y7FW6GLT.js} +6 -6
  67. package/dist/safe-bash/chunks/{chunk-QGUV42T5.js → chunk-YL3GBUG4.js} +1 -1
  68. package/dist/safe-bash/chunks/chunk-YOXUCJER.js +389 -0
  69. package/dist/safe-bash/chunks/{chunk-HBCN24ZA.js → chunk-Z2AAYYJN.js} +2 -2
  70. package/dist/safe-bash/chunks/chunk-ZKYKJCZZ.js +30 -0
  71. package/dist/safe-bash/chunks/core-IE3AFIDX.js +85806 -0
  72. package/dist/safe-bash/chunks/{ffmpeg-WTC3TEFI.js → ffmpeg-YANDK6HU.js} +2 -2
  73. package/dist/safe-bash/chunks/{gh-6WU6PXL4.js → gh-4MBJ2S5V.js} +2 -2
  74. package/dist/safe-bash/chunks/{git-EFZIGJW4.js → git-2QONJNRQ.js} +2 -2
  75. package/dist/safe-bash/chunks/{imagemagick-EIEYGWPF.js → imagemagick-JLEHGYSN.js} +2 -2
  76. package/dist/safe-bash/chunks/{mmdc-ROQJT5HQ.js → mmdc-6LD7A6ND.js} +2 -2
  77. package/dist/safe-bash/chunks/{pdfimages-DW7LWXFI.js → pdfimages-RSHL7LOP.js} +2 -2
  78. package/dist/safe-bash/chunks/{pdfinfo-TIP6XLUQ.js → pdfinfo-L3SGWPNG.js} +2 -2
  79. package/dist/safe-bash/chunks/{pdftk-DMG22ITZ.js → pdftk-LFBJNU5A.js} +2 -2
  80. package/dist/safe-bash/chunks/{pdftoppm-WNDYR72T.js → pdftoppm-NXXFUIHG.js} +2 -2
  81. package/dist/safe-bash/chunks/{pdftotext-5IPZ4NI7.js → pdftotext-4IHNWT6F.js} +2 -2
  82. package/dist/safe-bash/chunks/{qpdf-TTX2DIUA.js → qpdf-ZEIREV63.js} +2 -2
  83. package/dist/safe-bash/chunks/read-builtin-A4QKAT45.js +9 -0
  84. package/dist/safe-bash/chunks/{sips-XYS46JPJ.js → sips-D5YBG2V3.js} +2 -2
  85. package/dist/safe-bash/chunks/{soffice-TU73E5KL.js → soffice-RAJU3JUT.js} +2 -2
  86. package/dist/safe-bash/chunks/source-files-3XWRRHFA.js +7 -0
  87. package/dist/safe-bash/chunks/{wkhtmltopdf-FSZ2CHGE.js → wkhtmltopdf-7UE4FORZ.js} +2 -2
  88. package/dist/safe-bash/command-chunks/{chunk-7KWZXKY6.js → chunk-26RTBV2I.js} +1 -0
  89. package/dist/safe-bash/command-chunks/{chunk-AQJ2ROJO.js → chunk-2WYNMZR2.js} +10 -8
  90. package/dist/safe-bash/command-chunks/{chunk-BDSMROQZ.js → chunk-36GFRF2N.js} +2 -1
  91. package/dist/safe-bash/command-chunks/{chunk-GC5TJZOF.js → chunk-3VIA2IA7.js} +114 -31
  92. package/dist/safe-bash/command-chunks/{chunk-NKFYQSES.js → chunk-4CTI3ZTX.js} +1 -0
  93. package/dist/safe-bash/command-chunks/{chunk-WH627NJL.js → chunk-4MYP2FX4.js} +2 -1
  94. package/dist/safe-bash/command-chunks/chunk-4R5ADJM5.js +178 -0
  95. package/dist/safe-bash/command-chunks/{chunk-P2N33UMN.js → chunk-5MIKM54M.js} +4 -4
  96. package/dist/safe-bash/command-chunks/{chunk-DB453IE6.js → chunk-6FZQUOSJ.js} +1 -1
  97. package/dist/safe-bash/command-chunks/{chunk-WPYIOKE3.js → chunk-6GKYHPJG.js} +2 -2
  98. package/dist/safe-bash/command-chunks/{chunk-7K6JYKPJ.js → chunk-6M2ELGEN.js} +17 -15
  99. package/dist/safe-bash/command-chunks/{chunk-PXEIT2O4.js → chunk-6UR7V3ET.js} +8 -1
  100. package/dist/safe-bash/command-chunks/{chunk-6KJ3LPI2.js → chunk-6XBS5B46.js} +26 -3
  101. package/dist/safe-bash/command-chunks/{chunk-5PWJG2UK.js → chunk-6YXLZX7L.js} +2 -2
  102. package/dist/safe-bash/command-chunks/{chunk-EK6YNAXT.js → chunk-753YOR54.js} +31 -5
  103. package/dist/safe-bash/command-chunks/{chunk-RMWQAAO5.js → chunk-7IR4NRNE.js} +2 -2
  104. package/dist/safe-bash/command-chunks/{chunk-FZTK4MFI.js → chunk-7NM73SVK.js} +8 -8
  105. package/dist/safe-bash/command-chunks/{chunk-NXEQ3ESQ.js → chunk-7QD5YY4F.js} +6 -11
  106. package/dist/safe-bash/command-chunks/{chunk-EMPU65ZK.js → chunk-A5LBSJGH.js} +1 -0
  107. package/dist/safe-bash/command-chunks/chunk-A7MU7762.js +200 -0
  108. package/dist/safe-bash/command-chunks/{chunk-ORYGZYKW.js → chunk-ARZMP2L2.js} +3 -3
  109. package/dist/safe-bash/command-chunks/{chunk-OQKC5ZU2.js → chunk-BAKFZ477.js} +62 -20
  110. package/dist/safe-bash/command-chunks/{chunk-QRRYN2KO.js → chunk-BC7BK6R6.js} +0 -2424
  111. package/dist/safe-bash/command-chunks/{chunk-F4TEEZTL.js → chunk-BOEOJS2Q.js} +1 -1
  112. package/dist/safe-bash/command-chunks/{chunk-XS72HTMA.js → chunk-BWGGLYEB.js} +5 -22
  113. package/dist/safe-bash/command-chunks/{chunk-PMBFZXTK.js → chunk-C5ZZKP7V.js} +1 -1
  114. package/dist/safe-bash/command-chunks/{chunk-LHIOAFWW.js → chunk-C7SEB6WU.js} +1 -1
  115. package/dist/safe-bash/command-chunks/{chunk-XPT2UGBF.js → chunk-CHJKFRT7.js} +1 -1
  116. package/dist/safe-bash/command-chunks/{chunk-TIOCQVUQ.js → chunk-CON26Q2O.js} +1 -1
  117. package/dist/safe-bash/command-chunks/{chunk-E55UKBIE.js → chunk-DBAT3IK2.js} +1 -1
  118. package/dist/safe-bash/command-chunks/{chunk-Z45N42QC.js → chunk-DPAYAVMS.js} +15 -1
  119. package/dist/safe-bash/command-chunks/chunk-DS3NXVUM.js +368 -0
  120. package/dist/safe-bash/command-chunks/{chunk-5ZMZ573Q.js → chunk-DSJ3VRL3.js} +16 -4
  121. package/dist/safe-bash/command-chunks/{chunk-K2GDEMEU.js → chunk-EFRCFWVR.js} +4 -4
  122. package/dist/safe-bash/command-chunks/{chunk-DZCY63VJ.js → chunk-EV6HIJ5H.js} +6 -5
  123. package/dist/safe-bash/command-chunks/{chunk-JDYXY44P.js → chunk-FJURV46Y.js} +3 -3
  124. package/dist/safe-bash/command-chunks/{chunk-TZZ4WUKH.js → chunk-FZAWGKSE.js} +6 -4
  125. package/dist/safe-bash/command-chunks/{chunk-YHFXOX6U.js → chunk-GOCFQ6XV.js} +4 -4
  126. package/dist/safe-bash/command-chunks/{chunk-YOFC45RK.js → chunk-HH5O7DJI.js} +1 -1
  127. package/dist/safe-bash/command-chunks/{chunk-3HHCU5YU.js → chunk-HK7F5SDC.js} +13 -0
  128. package/dist/safe-bash/command-chunks/{chunk-JNZ3CVAE.js → chunk-HQBXIZC7.js} +8 -3
  129. package/dist/safe-bash/command-chunks/{chunk-2JRBIDAD.js → chunk-I63DBZXZ.js} +2 -2
  130. package/dist/safe-bash/command-chunks/{chunk-WNE7FPVR.js → chunk-I64TLTIW.js} +24 -16
  131. package/dist/safe-bash/command-chunks/{chunk-QKFSRZGQ.js → chunk-ICANWOXH.js} +7 -31
  132. package/dist/safe-bash/command-chunks/{chunk-SQRQW3CT.js → chunk-IJ6LGLXM.js} +1 -1
  133. package/dist/safe-bash/command-chunks/{chunk-5E4WAO4O.js → chunk-JD5QNRNO.js} +3 -3
  134. package/dist/safe-bash/command-chunks/{chunk-KJIMDLBB.js → chunk-JNANXVJV.js} +1 -1
  135. package/dist/safe-bash/command-chunks/{chunk-TGSNCQSR.js → chunk-JT4RYCA6.js} +1771 -1663
  136. package/dist/safe-bash/command-chunks/{chunk-II77KPZN.js → chunk-JWW6FYBN.js} +2 -2
  137. package/dist/safe-bash/command-chunks/{chunk-ZYXH3B66.js → chunk-LCJWKTCJ.js} +250 -203
  138. package/dist/safe-bash/command-chunks/{chunk-I237SNW5.js → chunk-LFJJQQND.js} +1 -1
  139. package/dist/safe-bash/command-chunks/chunk-LU4HBPP2.js +97 -0
  140. package/dist/safe-bash/command-chunks/{chunk-XJXU3VVH.js → chunk-LWOE65OE.js} +20 -5
  141. package/dist/safe-bash/command-chunks/{chunk-GMIHJYDG.js → chunk-M32HFSX7.js} +22 -6
  142. package/dist/safe-bash/command-chunks/{chunk-YG4EPFWC.js → chunk-M3NINRDU.js} +2880 -172
  143. package/dist/safe-bash/command-chunks/chunk-MQREDAL6.js +164 -0
  144. package/dist/safe-bash/command-chunks/{chunk-LWS62ISU.js → chunk-N6DIASO2.js} +1 -1
  145. package/dist/safe-bash/command-chunks/chunk-NGL7YK7O.js +188 -0
  146. package/dist/safe-bash/command-chunks/{chunk-PEF7K3UQ.js → chunk-NJYHWKIL.js} +40 -10
  147. package/dist/safe-bash/command-chunks/{chunk-VXSLJH7G.js → chunk-OJQRSCBP.js} +27 -7
  148. package/dist/safe-bash/command-chunks/{chunk-OQU6UT6X.js → chunk-OV3XREFN.js} +11 -0
  149. package/dist/safe-bash/command-chunks/{chunk-MIXBO6U7.js → chunk-PTZLF456.js} +2 -2
  150. package/dist/safe-bash/command-chunks/{chunk-ALDC4XP4.js → chunk-QILLRNES.js} +34 -10
  151. package/dist/safe-bash/command-chunks/{chunk-L22T3H7L.js → chunk-QR25JLKO.js} +1 -1
  152. package/dist/safe-bash/command-chunks/{chunk-7U7EXOXX.js → chunk-R7C4MGZ5.js} +17 -223
  153. package/dist/safe-bash/command-chunks/{chunk-LCF3OB7P.js → chunk-RBME3JEH.js} +1 -1
  154. package/dist/safe-bash/command-chunks/{chunk-2KG2QLJE.js → chunk-RFWGYT7G.js} +3 -0
  155. package/dist/safe-bash/command-chunks/{chunk-5TBUOBDE.js → chunk-RZMVRT26.js} +27 -13
  156. package/dist/safe-bash/command-chunks/chunk-TFR6B3WB.js +44 -0
  157. package/dist/safe-bash/command-chunks/chunk-TOH3OF3O.js +179 -0
  158. package/dist/safe-bash/command-chunks/{chunk-VGG2DL5Q.js → chunk-TRR4MYWF.js} +4 -0
  159. package/dist/safe-bash/command-chunks/chunk-TT4DAFBT.js +13621 -0
  160. package/dist/safe-bash/command-chunks/{chunk-LWSBAWLT.js → chunk-TXI64OAG.js} +1 -1
  161. package/dist/safe-bash/command-chunks/chunk-TZRI7BJZ.js +496 -0
  162. package/dist/safe-bash/command-chunks/{chunk-QOKBZFFD.js → chunk-U3MMODA5.js} +2 -7
  163. package/dist/safe-bash/command-chunks/{chunk-ZYHTWNAE.js → chunk-UAW423ZL.js} +11 -11
  164. package/dist/safe-bash/command-chunks/{chunk-C5YYCQHW.js → chunk-UXEEUGOV.js} +222 -12
  165. package/dist/safe-bash/command-chunks/{chunk-GY3BWK7K.js → chunk-VOZPMJRX.js} +87 -80
  166. package/dist/safe-bash/command-chunks/{chunk-MQFIPHIQ.js → chunk-WPANOB4A.js} +38 -35
  167. package/dist/safe-bash/command-chunks/{chunk-Y2WBSJG6.js → chunk-X4QZQI5Q.js} +65 -64
  168. package/dist/safe-bash/command-chunks/{chunk-FPVUD6TH.js → chunk-XGI57GCN.js} +10 -8
  169. package/dist/safe-bash/command-chunks/{chunk-5UBXNSFZ.js → chunk-XUCU7QQT.js} +1281 -1278
  170. package/dist/safe-bash/command-chunks/chunk-Y22VXJBD.js +296 -0
  171. package/dist/safe-bash/command-chunks/{chunk-WVHONVZ4.js → chunk-YMFUUPDX.js} +5 -3
  172. package/dist/safe-bash/command-chunks/{chunk-IR2BY7EL.js → chunk-YYGIBXFZ.js} +2 -2
  173. package/dist/safe-bash/command-chunks/{chunk-MSFXC3OC.js → chunk-Z4FO6OHE.js} +2 -2
  174. package/dist/safe-bash/command-chunks/{chunk-6GWJUQAV.js → chunk-Z5ZZVDUD.js} +181 -133
  175. package/dist/safe-bash/command-chunks/{chunk-W5DNF4JH.js → chunk-ZHN3QDCI.js} +1 -1
  176. package/dist/safe-bash/commands/alias/index.d.ts +2 -0
  177. package/dist/safe-bash/commands/alias/index.js +2 -0
  178. package/dist/safe-bash/commands/apply-patch/index.browser.js +2 -3
  179. package/dist/safe-bash/commands/apply-patch/index.d.ts +0 -1
  180. package/dist/safe-bash/commands/apply-patch/index.js +0 -1
  181. package/dist/safe-bash/commands/archive/index.browser.js +2 -3
  182. package/dist/safe-bash/commands/archive/index.d.ts +0 -1
  183. package/dist/safe-bash/commands/archive/index.js +0 -1
  184. package/dist/safe-bash/commands/bytes/compression/index.js +54 -51
  185. package/dist/safe-bash/commands/bytes/index.js +2 -1
  186. package/dist/safe-bash/commands/chmod/index.browser.js +14 -0
  187. package/dist/safe-bash/commands/chmod/index.d.ts +2 -0
  188. package/dist/safe-bash/commands/chmod/index.js +2 -0
  189. package/dist/safe-bash/commands/column/index.browser.js +2 -3
  190. package/dist/safe-bash/commands/column/index.d.ts +0 -1
  191. package/dist/safe-bash/commands/column/index.js +0 -1
  192. package/dist/safe-bash/commands/copy-source.js +1 -0
  193. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  194. package/dist/safe-bash/commands/csvkit/index.browser.js +72 -0
  195. package/dist/safe-bash/commands/csvkit/index.d.ts +0 -5
  196. package/dist/safe-bash/commands/csvkit/index.js +0 -50
  197. package/dist/safe-bash/commands/docx/index.browser.js +5 -7
  198. package/dist/safe-bash/commands/du/index.browser.js +2 -3
  199. package/dist/safe-bash/commands/du/index.d.ts +0 -1
  200. package/dist/safe-bash/commands/du/index.js +0 -1
  201. package/dist/safe-bash/commands/expr/index.browser.js +2 -3
  202. package/dist/safe-bash/commands/expr/index.d.ts +0 -1
  203. package/dist/safe-bash/commands/expr/index.js +0 -1
  204. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  205. package/dist/safe-bash/commands/file/index.browser.js +2 -3
  206. package/dist/safe-bash/commands/file/index.d.ts +0 -1
  207. package/dist/safe-bash/commands/file/index.js +0 -1
  208. package/dist/safe-bash/commands/filesystem.js +1 -1
  209. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  210. package/dist/safe-bash/commands/grep-aliases/index.browser.js +3 -3
  211. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  212. package/dist/safe-bash/commands/html-to-markdown/index.browser.js +2 -3
  213. package/dist/safe-bash/commands/html-to-markdown/index.d.ts +0 -1
  214. package/dist/safe-bash/commands/html-to-markdown/index.js +0 -1
  215. package/dist/safe-bash/commands/htmlq/index.d.ts +1 -5
  216. package/dist/safe-bash/commands/htmlq/index.js +1 -143
  217. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  218. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  219. package/dist/safe-bash/commands/llm/index.browser.js +2 -2
  220. package/dist/safe-bash/commands/llm/providers/index.browser.js +1 -1
  221. package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
  222. package/dist/safe-bash/commands/media/index.browser.js +4 -16314
  223. package/dist/safe-bash/commands/media/index.d.ts +1 -5
  224. package/dist/safe-bash/commands/media/index.js +1 -3
  225. package/dist/safe-bash/commands/media/plugin.d.ts +1 -18
  226. package/dist/safe-bash/commands/media/plugin.js +1 -90
  227. package/dist/safe-bash/commands/media/remote.d.ts +1 -63
  228. package/dist/safe-bash/commands/media/remote.js +1 -405
  229. package/dist/safe-bash/commands/media/settings.d.ts +1 -4
  230. package/dist/safe-bash/commands/media/settings.js +1 -26
  231. package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -7
  232. package/dist/safe-bash/commands/metadata/chmod.js +1 -204
  233. package/dist/safe-bash/commands/metadata/index.browser.js +3 -8
  234. package/dist/safe-bash/commands/metadata/index.d.ts +0 -1
  235. package/dist/safe-bash/commands/metadata/index.js +2 -2
  236. package/dist/safe-bash/commands/metadata/internal.d.ts +1 -30
  237. package/dist/safe-bash/commands/metadata/internal.js +1 -76
  238. package/dist/safe-bash/commands/metadata/mktemp.d.ts +1 -3
  239. package/dist/safe-bash/commands/metadata/mktemp.js +1 -202
  240. package/dist/safe-bash/commands/metadata/stat.d.ts +1 -7
  241. package/dist/safe-bash/commands/metadata/stat.js +1 -530
  242. package/dist/safe-bash/commands/mktemp/index.browser.js +13 -0
  243. package/dist/safe-bash/commands/mktemp/index.d.ts +2 -0
  244. package/dist/safe-bash/commands/mktemp/index.js +2 -0
  245. package/dist/safe-bash/commands/network/curl.js +1 -3
  246. package/dist/safe-bash/commands/network/index.browser.js +3 -4
  247. package/dist/safe-bash/commands/network/public.d.ts +0 -1
  248. package/dist/safe-bash/commands/network/public.js +0 -1
  249. package/dist/safe-bash/commands/network/transport.js +2 -1
  250. package/dist/safe-bash/commands/network/wget.js +1 -3
  251. package/dist/safe-bash/commands/node/browser.d.ts +0 -1
  252. package/dist/safe-bash/commands/node/browser.js +0 -1
  253. package/dist/safe-bash/commands/node/default-runtime.d.ts +3 -0
  254. package/dist/safe-bash/commands/node/default-runtime.js +15 -0
  255. package/dist/safe-bash/commands/node/index.browser.js +7 -8
  256. package/dist/safe-bash/commands/node/index.js +3 -3
  257. package/dist/safe-bash/commands/node/path.js +1 -1
  258. package/dist/safe-bash/commands/node/preload.d.ts +1 -1
  259. package/dist/safe-bash/commands/node/preload.js +4 -1
  260. package/dist/safe-bash/commands/node/quickjs.d.ts +2 -0
  261. package/dist/safe-bash/commands/node/quickjs.js +2 -0
  262. package/dist/safe-bash/commands/node/safejs.js +26 -12
  263. package/dist/safe-bash/commands/op/index.browser.js +2 -3
  264. package/dist/safe-bash/commands/op/index.d.ts +0 -11
  265. package/dist/safe-bash/commands/op/index.js +0 -84
  266. package/dist/safe-bash/commands/pandoc/index.browser.js +44 -0
  267. package/dist/safe-bash/commands/pandoc/index.d.ts +0 -1
  268. package/dist/safe-bash/commands/pandoc/index.js +0 -1
  269. package/dist/safe-bash/commands/portable-random.d.ts +1 -1
  270. package/dist/safe-bash/commands/portable-random.js +1 -12
  271. package/dist/safe-bash/commands/pr/index.browser.js +2 -2
  272. package/dist/safe-bash/commands/python/docker-runner.js +4 -3
  273. package/dist/safe-bash/commands/python/docker.d.ts +1 -0
  274. package/dist/safe-bash/commands/python/docker.js +5 -2
  275. package/dist/safe-bash/commands/python/index.browser.js +17 -13
  276. package/dist/safe-bash/commands/python/index.d.ts +2 -1
  277. package/dist/safe-bash/commands/python/index.js +10 -8
  278. package/dist/safe-bash/commands/python/llm-capability.js +65 -2
  279. package/dist/safe-bash/commands/python/llm-dependencies.d.ts +27 -0
  280. package/dist/safe-bash/commands/python/llm-dependencies.js +66 -0
  281. package/dist/safe-bash/commands/python/llm-module.js +6 -4
  282. package/dist/safe-bash/commands/python/llm-reference-module.d.ts +3 -0
  283. package/dist/safe-bash/commands/python/llm-reference-module.js +690 -0
  284. package/dist/safe-bash/commands/python/worker.browser.js +2 -3
  285. package/dist/safe-bash/commands/python/worker.d.ts +0 -1
  286. package/dist/safe-bash/commands/python/worker.js +0 -1
  287. package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.d.ts +1 -1
  288. package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.js +3 -3
  289. package/dist/safe-bash/commands/regex-execution/public.browser.js +7 -7
  290. package/dist/safe-bash/commands/safejs/options.js +5 -1
  291. package/dist/safe-bash/commands/safejs/runtime.d.ts +1 -0
  292. package/dist/safe-bash/commands/safejs/runtime.js +1 -1
  293. package/dist/safe-bash/commands/split/index.browser.js +2 -3
  294. package/dist/safe-bash/commands/split/index.d.ts +0 -1
  295. package/dist/safe-bash/commands/split/index.js +0 -1
  296. package/dist/safe-bash/commands/ssconvert/index.browser.js +98 -0
  297. package/dist/safe-bash/commands/stat/index.browser.js +13 -0
  298. package/dist/safe-bash/commands/stat/index.d.ts +2 -0
  299. package/dist/safe-bash/commands/stat/index.js +2 -0
  300. package/dist/safe-bash/commands/stream-format/index.browser.js +3 -4
  301. package/dist/safe-bash/commands/stream-format/index.d.ts +0 -1
  302. package/dist/safe-bash/commands/stream-format/index.js +0 -1
  303. package/dist/safe-bash/commands/stream-inspection/index.browser.js +3 -4
  304. package/dist/safe-bash/commands/stream-inspection/index.d.ts +0 -1
  305. package/dist/safe-bash/commands/stream-inspection/index.js +0 -1
  306. package/dist/safe-bash/commands/streams.js +2 -1
  307. package/dist/safe-bash/commands/table-text/index.browser.js +3 -4
  308. package/dist/safe-bash/commands/table-text/index.d.ts +0 -1
  309. package/dist/safe-bash/commands/table-text/index.js +0 -1
  310. package/dist/safe-bash/commands/text.js +74 -34
  311. package/dist/safe-bash/commands/time-env/index.browser.js +3 -4
  312. package/dist/safe-bash/commands/time-env/index.d.ts +0 -1
  313. package/dist/safe-bash/commands/time-env/index.js +0 -1
  314. package/dist/safe-bash/commands/tree/index.browser.js +2 -3
  315. package/dist/safe-bash/commands/tree/index.d.ts +0 -1
  316. package/dist/safe-bash/commands/tree/index.js +0 -1
  317. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  318. package/dist/safe-bash/commands/unalias/index.d.ts +2 -0
  319. package/dist/safe-bash/commands/unalias/index.js +2 -0
  320. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  321. package/dist/safe-bash/commands/yq/index.browser.js +2 -2
  322. package/dist/safe-bash/core.browser.js +2 -2
  323. package/dist/safe-bash/core.d.ts +7 -1
  324. package/dist/safe-bash/core.js +7 -1
  325. package/dist/safe-bash/execution-runtime.js +2 -1
  326. package/dist/safe-bash/fs/s3/http/index.d.ts +2 -2
  327. package/dist/safe-bash/fs/s3/http/index.js +1 -1
  328. package/dist/safe-bash/full-core.browser.js +254 -916
  329. package/dist/safe-bash/internal/op/types.d.ts +1 -0
  330. package/dist/safe-bash/jobs.browser.js +5 -5
  331. package/dist/safe-bash/lazy-optional.d.ts +3 -3
  332. package/dist/safe-bash/lazy-optional.js +1 -1
  333. package/dist/safe-bash/opt-in/commands/cmp/index.js +7 -6
  334. package/dist/safe-bash/opt-in/commands/dd/index.js +1 -1
  335. package/dist/safe-bash/opt-in/commands/dd/io.js +51 -5
  336. package/dist/safe-bash/opt-in/commands/truncate/index.js +2 -2
  337. package/dist/safe-bash/opt-in/commands/yq/native-work.js +3 -0
  338. package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +2 -1
  339. package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +4 -2
  340. package/dist/safe-bash/opt-in/optional.d.ts +1 -1
  341. package/dist/safe-bash/opt-in/optional.js +1 -1
  342. package/dist/safe-bash/opt-in/shell/extensions/read/index.js +2 -344
  343. package/dist/safe-bash/optional-host.browser.js +19 -14
  344. package/dist/safe-bash/optional-host.d.ts +1 -0
  345. package/dist/safe-bash/optional-host.js +1 -0
  346. package/dist/safe-bash/playwright/controller.js +41 -3
  347. package/dist/safe-bash/playwright/native-storage-targets.js +4 -2
  348. package/dist/safe-bash/plugins/base.d.ts +1 -1
  349. package/dist/safe-bash/plugins/base.js +3 -3
  350. package/dist/safe-bash/plugins/composition.d.ts +5 -2
  351. package/dist/safe-bash/plugins/composition.js +10 -7
  352. package/dist/safe-bash/plugins/index.browser.js +44 -41
  353. package/dist/safe-bash/plugins/index.js +3 -2
  354. package/dist/safe-bash/plugins/portable-commands.d.ts +3 -0
  355. package/dist/safe-bash/plugins/portable-commands.js +31 -0
  356. package/dist/safe-bash/registry-entry.browser.js +41 -42
  357. package/dist/safe-bash/search.browser.js +32 -33
  358. package/dist/safe-bash/shell/arithmetic.js +19 -6
  359. package/dist/safe-bash/shell/arrays/state.js +1 -1
  360. package/dist/safe-bash/shell/arrays/syntax.js +4 -3
  361. package/dist/safe-bash/shell/index.d.ts +0 -1
  362. package/dist/safe-bash/shell/index.js +0 -1
  363. package/dist/safe-bash/shell/parser.d.ts +2 -2
  364. package/dist/safe-bash/shell/parser.js +268 -64
  365. package/dist/safe-bash/shell/read-builtin.d.ts +3 -0
  366. package/dist/safe-bash/shell/read-builtin.js +344 -0
  367. package/dist/safe-bash/shell/runtime.d.ts +24 -4
  368. package/dist/safe-bash/shell/runtime.js +392 -414
  369. package/dist/safe-bash/shell/session-state.js +25 -0
  370. package/dist/safe-bash/shell/shell.js +76 -154
  371. package/dist/safe-bash/shell/tilde-expansion.d.ts +1 -1
  372. package/dist/safe-bash/shell/tilde-expansion.js +2 -2
  373. package/dist/safe-bash/shell/types.d.ts +7 -0
  374. package/dist/safe-bash/shell/value-state.js +1 -1
  375. package/dist/safe-bash/shell/worker-limits.js +1 -0
  376. package/dist/safe-bash/shell-entry.browser.js +32 -33
  377. package/dist/safe-bash/trap.browser.js +4 -4
  378. package/dist/safe-bash/worker/host.js +1 -1
  379. package/dist/safe-bash/yq-browser/index.js +1 -1
  380. package/dist/safe-bash-calendar-engine/time-env/calendar.d.ts +1 -1
  381. package/dist/safe-bash-calendar-engine/time-env/calendar.js +1 -1
  382. package/dist/safe-bash-calendar-engine/time-env/format.js +1 -1
  383. package/dist/safe-bash-command-alias/index.d.ts +13 -0
  384. package/dist/safe-bash-command-alias/index.js +88 -0
  385. package/dist/safe-bash-command-apply-patch/apply.js +3 -3
  386. package/dist/safe-bash-command-apply-patch/index.js +3 -3
  387. package/dist/safe-bash-command-apply-patch/matcher.js +1 -1
  388. package/dist/safe-bash-command-apply-patch/parser.js +1 -1
  389. package/dist/safe-bash-command-awk/awk-pipes.js +2 -2
  390. package/dist/safe-bash-command-awk/awk-reader.js +1 -1
  391. package/dist/safe-bash-command-awk/awk-runtime.js +3 -3
  392. package/dist/safe-bash-command-awk/awk.js +5 -5
  393. package/dist/safe-bash-command-awk/index.js +5 -5
  394. package/dist/safe-bash-command-bc/index.js +218 -65
  395. package/dist/safe-bash-command-bzip2/index.js +4 -3
  396. package/dist/safe-bash-command-chmod/LICENSE +21 -0
  397. package/dist/safe-bash-command-chmod/command.d.ts +7 -0
  398. package/dist/safe-bash-command-chmod/command.js +11 -0
  399. package/dist/safe-bash-command-chmod/index.d.ts +6 -0
  400. package/dist/safe-bash-command-chmod/index.js +27 -0
  401. package/dist/safe-bash-command-cmp/index.js +7 -6
  402. package/dist/safe-bash-command-column/column.js +3 -3
  403. package/dist/safe-bash-command-column/index.js +3 -3
  404. package/dist/safe-bash-command-column/layout.js +2 -2
  405. package/dist/safe-bash-command-csvkit/index.d.ts +1 -0
  406. package/dist/safe-bash-command-csvkit/index.js +1505 -7
  407. package/dist/safe-bash-command-csvkit/sync-support.js +2 -7
  408. package/dist/safe-bash-command-curl/curl.js +1 -1
  409. package/dist/safe-bash-command-curl/index.js +1 -1
  410. package/dist/safe-bash-command-date/date.js +1 -1
  411. package/dist/safe-bash-command-date/index.js +1 -1
  412. package/dist/safe-bash-command-dd/index.js +1 -1
  413. package/dist/safe-bash-command-dd/io.js +51 -5
  414. package/dist/safe-bash-command-diff/diff.js +1 -1
  415. package/dist/safe-bash-command-diff/index.js +1 -1
  416. package/dist/safe-bash-command-diff3/index.js +10 -13
  417. package/dist/safe-bash-command-exiftool/index.js +283 -55
  418. package/dist/safe-bash-command-exiftool/registry.d.ts +4 -2
  419. package/dist/safe-bash-command-factor/command.js +2 -2
  420. package/dist/safe-bash-command-factor/index.js +2 -2
  421. package/dist/safe-bash-command-fd/arguments.d.ts +2 -0
  422. package/dist/safe-bash-command-fd/index.js +42 -12
  423. package/dist/safe-bash-command-ffmpeg/index.js +356 -66
  424. package/dist/safe-bash-command-find/find-format.d.ts +3 -0
  425. package/dist/safe-bash-command-find/find-format.js +1 -1
  426. package/dist/safe-bash-command-find/find.js +2 -2
  427. package/dist/safe-bash-command-find/index.js +2 -2
  428. package/dist/safe-bash-command-fmt/index.js +10 -6
  429. package/dist/safe-bash-command-fold/engine.d.ts +1 -1
  430. package/dist/safe-bash-command-fold/family.js +2 -2
  431. package/dist/safe-bash-command-fold/index.js +1 -1
  432. package/dist/safe-bash-command-gzip/index.js +45 -42
  433. package/dist/safe-bash-command-hexdump/command.js +2 -2
  434. package/dist/safe-bash-command-hexdump/index.js +2 -2
  435. package/dist/safe-bash-command-html-to-markdown/entities.js +1 -1
  436. package/dist/safe-bash-command-html-to-markdown/index.js +4 -4
  437. package/dist/safe-bash-command-html-to-markdown/input.js +3 -3
  438. package/dist/safe-bash-command-html-to-markdown/parser.js +2 -2
  439. package/dist/safe-bash-command-html-to-markdown/render.js +3 -3
  440. package/dist/safe-bash-command-htmlq/contracts.d.ts +5 -2
  441. package/dist/safe-bash-command-htmlq/index.d.ts +2 -1
  442. package/dist/safe-bash-command-htmlq/index.js +175 -49
  443. package/dist/safe-bash-command-htmlq/sync.d.ts +1 -0
  444. package/dist/safe-bash-command-imagemagick/index.js +59 -7
  445. package/dist/safe-bash-command-install/arguments.d.ts +27 -0
  446. package/dist/safe-bash-command-install/arguments.js +224 -0
  447. package/dist/safe-bash-command-install/index.d.ts +7 -0
  448. package/dist/safe-bash-command-install/index.js +942 -0
  449. package/dist/safe-bash-command-install/mode.d.ts +6 -0
  450. package/dist/safe-bash-command-install/mode.js +71 -0
  451. package/dist/safe-bash-command-install/options.d.ts +40 -0
  452. package/dist/safe-bash-command-install/options.js +27 -0
  453. package/dist/safe-bash-command-jq/index.js +1 -1
  454. package/dist/safe-bash-command-jq/jq.js +1 -1
  455. package/dist/safe-bash-command-less/index.js +42 -57
  456. package/dist/safe-bash-command-llm/command.js +1 -1
  457. package/dist/safe-bash-command-llm/elevenlabs.js +2 -2
  458. package/dist/safe-bash-command-llm/index.js +4 -4
  459. package/dist/safe-bash-command-llm/openai.js +2 -2
  460. package/dist/safe-bash-command-llm/providers/elevenlabs.js +2 -2
  461. package/dist/safe-bash-command-llm/providers/index.js +3 -3
  462. package/dist/safe-bash-command-llm/providers/openai.js +2 -2
  463. package/dist/safe-bash-command-llm/providers/shared.js +1 -1
  464. package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.browser.d.ts +463 -46
  465. package/dist/safe-bash-command-mcp/index.browser.js +19308 -0
  466. package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.d.ts +15 -6
  467. package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.js +2835 -2783
  468. package/dist/safe-bash-command-media/LICENSE +21 -0
  469. package/dist/safe-bash-command-media/index.d.ts +6 -0
  470. package/dist/safe-bash-command-media/index.js +30 -0
  471. package/dist/safe-bash-command-media/plugin.d.ts +18 -0
  472. package/dist/safe-bash-command-media/plugin.js +11 -0
  473. package/dist/safe-bash-command-media/remote.d.ts +63 -0
  474. package/dist/safe-bash-command-media/remote.js +11 -0
  475. package/dist/safe-bash-command-media/settings.d.ts +4 -0
  476. package/dist/safe-bash-command-media/settings.js +41 -0
  477. package/dist/safe-bash-command-mktemp/LICENSE +21 -0
  478. package/dist/safe-bash-command-mktemp/command.d.ts +3 -0
  479. package/dist/safe-bash-command-mktemp/command.js +9 -0
  480. package/dist/safe-bash-command-mktemp/index.d.ts +6 -0
  481. package/dist/safe-bash-command-mktemp/index.js +25 -0
  482. package/dist/safe-bash-command-mmdc/arguments.d.ts +1 -0
  483. package/dist/safe-bash-command-mmdc/command.d.ts +2 -0
  484. package/dist/safe-bash-command-mmdc/contracts.d.ts +8 -1
  485. package/dist/safe-bash-command-mmdc/index.js +359 -7
  486. package/dist/safe-bash-command-nl/index.js +1 -1
  487. package/dist/safe-bash-command-nl/nl.js +1 -1
  488. package/dist/safe-bash-command-node/LICENSE +21 -0
  489. package/dist/safe-bash-command-node/index.d.ts +17 -0
  490. package/dist/safe-bash-command-node/index.js +328 -0
  491. package/dist/safe-bash-command-numfmt/index.js +1 -0
  492. package/dist/safe-bash-command-od/index.js +16 -8
  493. package/dist/safe-bash-command-op/index.js +62 -36
  494. package/dist/safe-bash-command-op/types.d.ts +1 -0
  495. package/dist/safe-bash-command-pandoc/command.js +3 -3
  496. package/dist/safe-bash-command-pandoc/index.d.ts +1 -0
  497. package/dist/safe-bash-command-pandoc/index.js +5 -3
  498. package/dist/safe-bash-command-pandoc/sync.d.ts +1 -0
  499. package/dist/safe-bash-command-patch/index.js +4 -4
  500. package/dist/safe-bash-command-patch/patch.js +4 -4
  501. package/dist/safe-bash-command-pdfimages/index.js +1 -1
  502. package/dist/safe-bash-command-pdfinfo/index.js +30 -5
  503. package/dist/safe-bash-command-pdftk/index.js +21 -23
  504. package/dist/safe-bash-command-pdftoppm/index.js +17 -4
  505. package/dist/safe-bash-command-pdftotext/index.js +11 -14
  506. package/dist/safe-bash-command-qpdf/index.d.ts +1 -0
  507. package/dist/safe-bash-command-qpdf/index.js +9 -6
  508. package/dist/safe-bash-command-rg/index.js +1 -1
  509. package/dist/safe-bash-command-rg/rg-command.js +1 -1
  510. package/dist/safe-bash-command-sed/index.js +1 -1
  511. package/dist/safe-bash-command-sed/sed.js +1 -1
  512. package/dist/safe-bash-command-shuf/input.d.ts +2 -2
  513. package/dist/safe-bash-command-shuf/input.js +2 -1
  514. package/dist/safe-bash-command-shuf/shuf.js +4 -2
  515. package/dist/safe-bash-command-sips/index.js +15 -7
  516. package/dist/safe-bash-command-soffice/index.js +97 -12
  517. package/dist/safe-bash-command-sponge/index.js +13 -3
  518. package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -0
  519. package/dist/safe-bash-command-sqlite3/index.js +510 -70
  520. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +2 -2
  521. package/dist/safe-bash-command-ssconvert/index.js +44 -22
  522. package/dist/safe-bash-command-stat/LICENSE +21 -0
  523. package/dist/safe-bash-command-stat/command.d.ts +7 -0
  524. package/dist/safe-bash-command-stat/command.js +9 -0
  525. package/dist/safe-bash-command-stat/index.d.ts +6 -0
  526. package/dist/safe-bash-command-stat/index.js +25 -0
  527. package/dist/safe-bash-command-tar/create.d.ts +1 -0
  528. package/dist/safe-bash-command-tar/create.js +2 -2
  529. package/dist/safe-bash-command-tar/extract.js +2 -2
  530. package/dist/safe-bash-command-tar/index.js +4 -4
  531. package/dist/safe-bash-command-tar/modes.js +4 -4
  532. package/dist/safe-bash-command-tar/options.js +1 -1
  533. package/dist/safe-bash-command-truncate/index.js +2 -2
  534. package/dist/safe-bash-command-tsort/command.js +2 -2
  535. package/dist/safe-bash-command-tsort/index.js +2 -2
  536. package/dist/safe-bash-command-unalias/index.d.ts +12 -0
  537. package/dist/safe-bash-command-unalias/index.js +67 -0
  538. package/dist/safe-bash-command-unrtf/index.js +37 -5
  539. package/dist/safe-bash-command-xan/argv.d.ts +1 -1
  540. package/dist/safe-bash-command-xan/argv.js +2 -2
  541. package/dist/safe-bash-command-xan/budget.d.ts +0 -1
  542. package/dist/safe-bash-command-xan/budget.js +1 -1
  543. package/dist/safe-bash-command-xan/commands.js +6 -6
  544. package/dist/safe-bash-command-xan/csv.js +2 -2
  545. package/dist/safe-bash-command-xan/index.js +8 -9
  546. package/dist/safe-bash-command-xan/io.js +4 -4
  547. package/dist/safe-bash-command-xan/options.js +1 -1
  548. package/dist/safe-bash-command-xan/selector.js +2 -2
  549. package/dist/safe-bash-command-xmllint/index.js +45 -23
  550. package/dist/safe-bash-command-xxd/index.js +47 -12
  551. package/dist/safe-bash-command-xz/command.d.ts +1 -1
  552. package/dist/safe-bash-command-xz/index.js +3 -2
  553. package/dist/safe-bash-command-yq/accounting.js +1 -1
  554. package/dist/safe-bash-command-yq/index.js +4 -2
  555. package/dist/safe-bash-command-yq/native-work.js +3 -0
  556. package/dist/safe-bash-command-yq/parser.js +2 -2
  557. package/dist/safe-bash-command-yq/query.js +8 -5
  558. package/dist/safe-bash-command-yq/toml.js +2 -2
  559. package/dist/safe-bash-command-zip/index.js +3 -3
  560. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  561. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  562. package/dist/safe-bash-compression-engine/files.js +6 -6
  563. package/dist/safe-bash-compression-engine/index.js +5 -5
  564. package/dist/safe-bash-compression-engine/operand.js +6 -6
  565. package/dist/safe-bash-compression-engine/options.js +1 -1
  566. package/dist/safe-bash-compression-engine/stream.js +5 -5
  567. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  568. package/dist/safe-bash-contracts/command.js +3 -3
  569. package/dist/safe-bash-contracts/default-executor.js +2 -2
  570. package/dist/safe-bash-contracts/diagnostics.js +3 -3
  571. package/dist/safe-bash-contracts/escaping.js +6 -6
  572. package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
  573. package/dist/safe-bash-contracts/filesystem-output.js +5 -5
  574. package/dist/safe-bash-contracts/http.d.ts +7 -0
  575. package/dist/safe-bash-contracts/index.js +8 -8
  576. package/dist/safe-bash-contracts/io.d.ts +2 -0
  577. package/dist/safe-bash-contracts/io.js +2 -2
  578. package/dist/safe-bash-contracts/output.js +3 -3
  579. package/dist/safe-bash-contracts/runtime-control.d.ts +2 -2
  580. package/dist/safe-bash-contracts/runtime-control.js +4 -2
  581. package/dist/safe-bash-contracts/signals.d.ts +2 -0
  582. package/dist/safe-bash-contracts/signals.js +3 -1
  583. package/dist/safe-bash-contracts/yield.js +1 -1
  584. package/dist/safe-bash-csv-engine/index.d.ts +2 -1
  585. package/dist/safe-bash-csv-engine/index.js +21 -15
  586. package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
  587. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +6 -6
  588. package/dist/safe-bash-io-engine/internal.js +1 -1
  589. package/dist/safe-bash-io-engine/shell/pattern.js +38 -18
  590. package/dist/safe-bash-line-ending-engine/convert.js +9 -204
  591. package/dist/safe-bash-line-ending-engine/encoding.js +9 -42
  592. package/dist/safe-bash-line-ending-engine/index.js +48 -0
  593. package/dist/safe-bash-line-ending-engine/info.js +9 -90
  594. package/dist/safe-bash-line-ending-engine/internal.js +15 -160
  595. package/dist/safe-bash-line-ending-engine/io.js +12 -289
  596. package/dist/safe-bash-line-ending-engine/stage.js +10 -160
  597. package/dist/safe-bash-markdown-engine/index.js +3 -3
  598. package/dist/safe-bash-metadata-engine/LICENSE +21 -0
  599. package/dist/safe-bash-metadata-engine/index.d.ts +30 -0
  600. package/dist/safe-bash-metadata-engine/index.js +82 -0
  601. package/dist/safe-bash-metadata-engine/random.d.ts +1 -0
  602. package/dist/safe-bash-metadata-engine/random.js +21 -0
  603. package/dist/safe-bash-network-engine/args.d.ts +6 -0
  604. package/dist/safe-bash-network-engine/args.js +4 -2
  605. package/dist/safe-bash-network-engine/body.js +1 -1
  606. package/dist/safe-bash-network-engine/fetch-transport.js +3 -1
  607. package/dist/safe-bash-network-engine/index.js +3 -1
  608. package/dist/safe-bash-network-engine/input.js +2 -2
  609. package/dist/safe-bash-network-engine/platform-portable.js +3 -1
  610. package/dist/safe-bash-query-engine/dates.d.ts +1 -1
  611. package/dist/safe-bash-query-engine/dates.js +1 -1
  612. package/dist/safe-bash-query-engine/index.js +6 -6
  613. package/dist/safe-bash-query-engine/interpreter.js +4 -4
  614. package/dist/safe-bash-query-engine/parser.js +1 -1
  615. package/dist/safe-bash-query-engine/query-core.js +6 -6
  616. package/dist/safe-bash-regex-engine/execution/bounded-provider.js +10 -0
  617. package/dist/safe-bash-regex-engine/index.js +1 -1
  618. package/dist/safe-bash-regex-engine/text/regex.d.ts +1 -1
  619. package/dist/safe-bash-regex-engine/text/regex.js +1 -1
  620. package/dist/safe-bash-search-engine/ergonomic-regex.d.ts +1 -0
  621. package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
  622. package/dist/safe-bash-search-engine/glob.js +2 -2
  623. package/dist/safe-bash-search-engine/grep.js +17 -10
  624. package/dist/safe-bash-search-engine/matcher.d.ts +2 -2
  625. package/dist/safe-bash-search-engine/matcher.js +13 -9
  626. package/dist/safe-bash-search-engine/options.d.ts +2 -0
  627. package/dist/safe-bash-search-engine/options.js +1 -1
  628. package/dist/safe-bash-search-engine/output.js +1 -1
  629. package/dist/safe-bash-search-engine/shared.js +2 -2
  630. package/dist/safe-bash-search-engine/walk.js +15 -3
  631. package/dist/safe-bash-text-stream-engine/stream-format/shared.d.ts +1 -1
  632. package/dist/safe-bash-text-stream-engine/stream-format/shared.js +2 -1
  633. package/dist/safe-bash-xml-engine/document.js +3 -3
  634. package/dist/safe-bash-xml-engine/evaluate.js +2 -2
  635. package/dist/safe-bash-xml-engine/index.js +4 -4
  636. package/dist/safe-bash-xml-engine/io.js +7 -2
  637. package/dist/safe-bash-xml-engine/limits.d.ts +0 -2
  638. package/dist/safe-bash-xml-engine/limits.js +1 -1
  639. package/dist/safe-bash-xml-engine/query.js +3 -3
  640. package/dist/safe-bash-zip-engine/index.js +3 -3
  641. package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
  642. package/dist/safe-bash-zip-engine/zip/safety.js +1 -1
  643. package/dist/safe-bash-zip-engine/zip/sfx.js +3 -3
  644. package/dist/safe-bash-zip-engine/zip/volumes.js +1 -1
  645. package/dist/safe-bash-zip-engine/zip-format.js +3 -3
  646. package/dist/safe-playwright-cloudflare/browser-snapshot-json.js +2 -2
  647. package/dist/safe-playwright-cloudflare/browser-snapshot-references.js +1 -1
  648. package/dist/safe-playwright-cloudflare/browser-socket-closure.js +18 -3
  649. package/dist/safe-playwright-cloudflare/shell-browser-resource.js +1 -1
  650. package/dist/xlsx-ast/xlsx.js +6 -5
  651. package/package.json +112 -98
  652. package/dist/media-cli/bytes.d.ts +0 -8
  653. package/dist/media-cli/bytes.js +0 -40
  654. package/dist/media-cli/concat.d.ts +0 -30
  655. package/dist/media-cli/concat.js +0 -197
  656. package/dist/media-cli/content.js +0 -66
  657. package/dist/media-cli/dependency-grammars.d.ts +0 -12
  658. package/dist/media-cli/dependency-grammars.js +0 -557
  659. package/dist/media-cli/discover.js +0 -286
  660. package/dist/media-cli/engine.js +0 -190
  661. package/dist/media-cli/filename-expression.js +0 -147
  662. package/dist/media-cli/filesystem.js +0 -35
  663. package/dist/media-cli/frontend-contract.js +0 -8
  664. package/dist/media-cli/frontend-issues.d.ts +0 -6
  665. package/dist/media-cli/frontend-issues.js +0 -9
  666. package/dist/media-cli/imagemagick-operand.d.ts +0 -42
  667. package/dist/media-cli/imagemagick-operand.js +0 -229
  668. package/dist/media-cli/imagemagick-references.d.ts +0 -7
  669. package/dist/media-cli/imagemagick-references.js +0 -42
  670. package/dist/media-cli/imagemagick.generated.js +0 -3254
  671. package/dist/media-cli/imagemagick.js +0 -615
  672. package/dist/media-cli/index.js +0 -12
  673. package/dist/media-cli/mvg.d.ts +0 -10
  674. package/dist/media-cli/mvg.js +0 -102
  675. package/dist/media-cli/network.js +0 -78
  676. package/dist/media-cli/options.generated.js +0 -3312
  677. package/dist/media-cli/preset.d.ts +0 -11
  678. package/dist/media-cli/preset.js +0 -57
  679. package/dist/media-cli/resolution-path.d.ts +0 -23
  680. package/dist/media-cli/resolution-path.js +0 -217
  681. package/dist/media-cli/resolver.js +0 -494
  682. package/dist/media-cli/resources.d.ts +0 -16
  683. package/dist/media-cli/resources.js +0 -187
  684. package/dist/media-cli/shim.js +0 -52
  685. package/dist/media-cli/tee.d.ts +0 -6
  686. package/dist/media-cli/tee.js +0 -38
  687. package/dist/office-package/zip-sync.js +0 -111
  688. package/dist/remote-execution/binary.js +0 -178
  689. package/dist/remote-execution/callback-result.js +0 -26
  690. package/dist/remote-execution/canonical-capabilities.d.ts +0 -5
  691. package/dist/remote-execution/canonical-capabilities.js +0 -45
  692. package/dist/remote-execution/canonical-metadata.d.ts +0 -4
  693. package/dist/remote-execution/canonical-metadata.js +0 -32
  694. package/dist/remote-execution/client.js +0 -824
  695. package/dist/remote-execution/deployment.js +0 -131
  696. package/dist/remote-execution/descriptors.js +0 -267
  697. package/dist/remote-execution/effects.js +0 -357
  698. package/dist/remote-execution/endpoint.js +0 -224
  699. package/dist/remote-execution/files.js +0 -291
  700. package/dist/remote-execution/hosting-operation.js +0 -26
  701. package/dist/remote-execution/hosting-request.d.ts +0 -4
  702. package/dist/remote-execution/hosting-request.js +0 -12
  703. package/dist/remote-execution/hosting-stream.d.ts +0 -8
  704. package/dist/remote-execution/hosting-stream.js +0 -64
  705. package/dist/remote-execution/index.js +0 -18
  706. package/dist/remote-execution/invocation-admission.d.ts +0 -3
  707. package/dist/remote-execution/invocation-admission.js +0 -17
  708. package/dist/remote-execution/job-binding.js +0 -1269
  709. package/dist/remote-execution/materializations.js +0 -284
  710. package/dist/remote-execution/modal-driver.js +0 -90
  711. package/dist/remote-execution/native-result.d.ts +0 -3
  712. package/dist/remote-execution/native-result.js +0 -16
  713. package/dist/remote-execution/output-freshness.d.ts +0 -4
  714. package/dist/remote-execution/output-freshness.js +0 -19
  715. package/dist/remote-execution/output-retrieval.js +0 -474
  716. package/dist/remote-execution/process-http.js +0 -607
  717. package/dist/remote-execution/process.js +0 -577
  718. package/dist/remote-execution/protocol.js +0 -208
  719. package/dist/remote-execution/relay.js +0 -91
  720. package/dist/remote-execution/rest-driver.js +0 -93
  721. package/dist/remote-execution/upload-descriptor.js +0 -201
  722. package/dist/remote-execution/upload-protocol.js +0 -62
  723. package/dist/remote-execution/uploads.js +0 -324
  724. package/dist/remote-execution/wire-json.d.ts +0 -4
  725. package/dist/remote-execution/wire-json.js +0 -44
  726. package/dist/remote-execution/wire-validation.js +0 -131
  727. package/dist/remote-execution/wire.generated.js +0 -4224
  728. package/dist/safe-bash/chunks/chunk-GETUOD5D.js +0 -161
  729. package/dist/safe-bash/chunks/chunk-IWDICZVK.js +0 -20
  730. package/dist/safe-bash/chunks/chunk-MHMMRCYC.js +0 -3464
  731. package/dist/safe-bash/chunks/chunk-UE5KZDEK.js +0 -77
  732. package/dist/safe-bash/chunks/chunk-VSAJ4OTM.js +0 -962
  733. package/dist/safe-bash/chunks/csvkit-TACDU7FC.js +0 -1618
  734. package/dist/safe-bash/chunks/implementation-MLFHUQ5M.js +0 -133
  735. package/dist/safe-bash/commands/csvkit/sync.js +0 -1639
  736. package/dist/safe-bash/commands/node/unconfigured.d.ts +0 -3
  737. package/dist/safe-bash/commands/node/unconfigured.js +0 -10
  738. package/dist/safe-bash/commands/pandoc/implementation.d.ts +0 -8
  739. package/dist/safe-bash/commands/pandoc/implementation.js +0 -94
  740. package/dist/safe-bash-mcp/index.browser.js +0 -9157
  741. package/dist/safe-bash/command-chunks/{chunk-ZRRBXU3M.js → chunk-GIN5GUDP.js} +4 -4
  742. package/dist/safe-bash/command-chunks/{chunk-LAOM65EE.js → chunk-IEO4XVN6.js} +3 -3
  743. package/dist/safe-bash/command-chunks/{chunk-364TMWBT.js → chunk-MWREVL44.js} +6 -6
  744. package/dist/safe-bash/command-chunks/{chunk-464RVBGB.js → chunk-Q5TDKFHK.js} +3 -3
  745. package/dist/safe-bash/command-chunks/{chunk-AJR3AQYA.js → chunk-UKX3LZHR.js} +0 -0
  746. package/dist/safe-bash/command-chunks/{chunk-XIIBTGC5.js → chunk-XPXEQKRW.js} +9 -9
  747. package/dist/safe-bash/command-chunks/{chunk-FDBUV4HJ.js → chunk-Y4HGTG3E.js} +3 -3
  748. /package/dist/{safe-bash/commands/csvkit → safe-bash-command-csvkit}/sync.d.ts +0 -0
@@ -1,16 +1,23 @@
1
+ import {
2
+ evalSyncCsvcut,
3
+ evalSyncCsvgrep,
4
+ evalSyncDiff3,
5
+ evalSyncHtmlq,
6
+ evalSyncUnrtf
7
+ } from "./chunk-YOXUCJER.js";
1
8
  import {
2
9
  evalSyncYqPrep,
3
10
  formatSyncYqYamlLines
4
- } from "./chunk-TFIBK2GI.js";
5
- import {
6
- captureIgnoredTrapSignals,
7
- defaultPortableTrapExtension,
8
- isIdlePortableTrapInstance
9
- } from "./chunk-3NDIFSNM.js";
11
+ } from "./chunk-D5Q7NFWI.js";
10
12
  import {
13
+ abortManagedController,
14
+ addAbortSignalWaiter,
11
15
  bindFileOutputBudget,
12
16
  clearRgFastRunnerPool,
17
+ combineManagedSignals,
13
18
  createFmtEngine,
19
+ createManagedControlController,
20
+ creationUmask,
14
21
  defaultEchoExecutors,
15
22
  defaultMkdirExecutors,
16
23
  defaultPredicateExecutors,
@@ -35,39 +42,47 @@ import {
35
42
  executionCommands,
36
43
  extractFastPrintfSpecifiers,
37
44
  formatPrintf,
45
+ getRuntimeBackingFileSystem,
46
+ interruptible,
47
+ isManagedAbortSignal,
48
+ isSyncResolved,
38
49
  openFileOutput,
39
50
  parseFmtArguments,
40
51
  printfCommand,
52
+ registerManagedAbortSignal,
53
+ removeAbortSignalWaiter,
41
54
  tryFastEcho,
42
55
  tryFastPredicate,
43
56
  tryFastPrintf,
44
57
  variablePresence,
45
58
  wcDisplayWidth
46
- } from "./chunk-44ALJ4QG.js";
47
- import {
48
- evalSyncGetopt
49
- } from "./chunk-AUSNDQTJ.js";
59
+ } from "./chunk-AW5KIT6V.js";
50
60
  import {
51
61
  evalSyncIconv
52
- } from "./chunk-CTVWDACF.js";
62
+ } from "./chunk-IQW34XQT.js";
53
63
  import {
54
64
  evalSyncLineEndings
55
- } from "./chunk-3R3AANOR.js";
65
+ } from "./chunk-TCKYOLUE.js";
56
66
  import {
57
67
  evalSyncMdq
58
- } from "./chunk-OV6IHKO6.js";
59
- import {
60
- evalSyncXmllint,
61
- evalSyncXq
62
- } from "./chunk-C5OWC2TL.js";
68
+ } from "./chunk-FOB2FZR4.js";
63
69
  import {
64
70
  PublicDiagnostic,
65
71
  publicDiagnosticMessage,
66
72
  writeDiagnostic
67
- } from "./chunk-PH63PLPZ.js";
73
+ } from "./chunk-TC3F4UFF.js";
68
74
  import {
69
75
  evalSyncPr
70
- } from "./chunk-CHYGPFVM.js";
76
+ } from "./chunk-22SX3F2R.js";
77
+ import {
78
+ evalSyncGetopt
79
+ } from "./chunk-JPSUHHOA.js";
80
+ import {
81
+ bytesToHex,
82
+ compareUtf8,
83
+ latin1Bytes,
84
+ latin1Text
85
+ } from "./chunk-UV4X32QU.js";
71
86
  import {
72
87
  EreLedger,
73
88
  EreProfileLimitError,
@@ -77,65 +92,17 @@ import {
77
92
  matchEre,
78
93
  tryCompileEreSync,
79
94
  tryMatchEreSync
80
- } from "./chunk-6O77NL2S.js";
95
+ } from "./chunk-6SMICPI3.js";
81
96
  import {
82
97
  jobsExtension
83
- } from "./chunk-BJA5XNP6.js";
98
+ } from "./chunk-Y7FW6GLT.js";
84
99
  import {
85
- concatShellValues,
86
- shellValueByteLength,
87
- shellValueBytes,
88
- shellValueFromBytes,
89
- shellValueRetainedBytes,
90
- shellValueText
91
- } from "./chunk-J42RIHHJ.js";
100
+ evalSyncXmllint,
101
+ evalSyncXq
102
+ } from "./chunk-OQ3AGYCZ.js";
92
103
  import {
93
104
  openCommandFile
94
- } from "./chunk-I5HZ4FGE.js";
95
- import {
96
- CommandRegistry,
97
- commandRuntimeIdentity,
98
- createCommandArguments,
99
- getCommandArguments,
100
- validateExitCode
101
- } from "./chunk-7R5BDCG7.js";
102
- import {
103
- evalSyncTree
104
- } from "./chunk-55YJASTN.js";
105
- import {
106
- evalSyncFile
107
- } from "./chunk-4BSJLKNM.js";
108
- import {
109
- evalSyncHtmlToMarkdown
110
- } from "./chunk-DQP3VHSB.js";
111
- import {
112
- evalSyncDu
113
- } from "./chunk-GEG3BWGE.js";
114
- import {
115
- abortManagedController,
116
- addAbortSignalWaiter,
117
- combineManagedSignals,
118
- createManagedControlController,
119
- creationUmask,
120
- evalSyncStat,
121
- getRuntimeBackingFileSystem,
122
- gnuInformationSync,
123
- interruptible,
124
- isManagedAbortSignal,
125
- isSyncResolved,
126
- registerManagedAbortSignal,
127
- removeAbortSignalWaiter
128
- } from "./chunk-VSAJ4OTM.js";
129
- import {
130
- bytesToHex,
131
- compareUtf8,
132
- latin1Bytes,
133
- latin1Text
134
- } from "./chunk-D3ANYGMC.js";
135
- import {
136
- FsError,
137
- isFsError
138
- } from "./chunk-VTH3MLDU.js";
105
+ } from "./chunk-CL2FCTTO.js";
139
106
  import {
140
107
  basename,
141
108
  cancelTurn,
@@ -150,7 +117,11 @@ import {
150
117
  runYieldCheckpoint,
151
118
  scheduleTurn,
152
119
  yieldTurn
153
- } from "./chunk-NZQXYWA3.js";
120
+ } from "./chunk-62BOHHJT.js";
121
+ import {
122
+ FsError,
123
+ isFsError
124
+ } from "./chunk-DUTAG6ZD.js";
154
125
  import {
155
126
  createBytePipe,
156
127
  outputFailure,
@@ -158,37 +129,63 @@ import {
158
129
  toByteSource,
159
130
  writeBytes,
160
131
  writeText
161
- } from "./chunk-74GHTNJA.js";
132
+ } from "./chunk-4KTMKD5W.js";
162
133
  import {
163
- evalSyncTar,
164
- evalSyncUnzip,
165
- evalSyncZip
166
- } from "./chunk-QGUV42T5.js";
134
+ captureIgnoredTrapSignals,
135
+ defaultPortableTrapExtension,
136
+ isIdlePortableTrapInstance
137
+ } from "./chunk-SUJ3NTMH.js";
138
+ import {
139
+ concatShellValues,
140
+ shellValueByteLength,
141
+ shellValueBytes,
142
+ shellValueFromBytes,
143
+ shellValueRetainedBytes,
144
+ shellValueText
145
+ } from "./chunk-XQWCQSRN.js";
146
+ import {
147
+ evalSyncDu
148
+ } from "./chunk-RHFRJIWQ.js";
167
149
  import {
168
150
  evalSyncDate,
169
151
  evalSyncPrintenv
170
- } from "./chunk-ZVD5IS4V.js";
152
+ } from "./chunk-KBZ4UB2O.js";
153
+ import {
154
+ evalSyncTree
155
+ } from "./chunk-4T53AERN.js";
156
+ import {
157
+ evalSyncFile
158
+ } from "./chunk-7O76UFQD.js";
159
+ import {
160
+ evalSyncHtmlToMarkdown
161
+ } from "./chunk-5XIFJVOO.js";
162
+ import {
163
+ CommandRegistry,
164
+ builtInDirectContextExecutors,
165
+ commandRuntimeIdentity,
166
+ createCommandArguments,
167
+ getCommandArguments,
168
+ validateExitCode
169
+ } from "./chunk-OHML2BEU.js";
170
+ import {
171
+ evalSyncStat
172
+ } from "./chunk-IOHH2GTI.js";
173
+ import {
174
+ evalSyncTar,
175
+ evalSyncUnzip,
176
+ evalSyncZip
177
+ } from "./chunk-YL3GBUG4.js";
171
178
  import {
172
179
  RESOLVED_EXIT_ONE,
173
180
  RESOLVED_EXIT_ZERO,
174
181
  UsageError,
175
- builtInDirectContextExecutors,
182
+ builtInDirectContextExecutors as builtInDirectContextExecutors2,
176
183
  pathOf,
177
- registerDefaultExecutor,
178
- registerDefaultExecutors,
179
184
  syncCommandEvaluators
180
- } from "./chunk-E7OYNDGL.js";
185
+ } from "./chunk-V7QT2RWC.js";
181
186
  import {
182
187
  init_platform
183
- } from "./chunk-B7TAL7S5.js";
184
-
185
- // packages/safe-bash/src/fs/memory/index.ts
186
- init_platform();
187
- import {
188
- createMemoryFileSystem,
189
- defaultMemoryFileSystemLimits,
190
- MemoryFileSystem
191
- } from "@poe-platform/safe-fs/core";
188
+ } from "./chunk-PTAEWLSE.js";
192
189
 
193
190
  // packages/safe-bash/src/shell/types.ts
194
191
  init_platform();
@@ -468,6 +465,7 @@ function integer(text3) {
468
465
  return value;
469
466
  }
470
467
  function parseArithmetic(source, offset = 0, budget = new ParseBudget()) {
468
+ if (source.includes("\\\n")) source = source.replace(/\\\n/gu, "");
471
469
  const tokens = [];
472
470
  let position = 0;
473
471
  while (position < source.length) {
@@ -616,7 +614,11 @@ function arithmeticEnd(source, start, allowSubshell = false, maxSyntaxDepth = In
616
614
  }
617
615
  if (character === "(") depth++;
618
616
  if (character === ")") {
619
- if (depth === 0 && source[position + 1] === ")") return position;
617
+ if (depth === 0) {
618
+ let nextClose = position + 1;
619
+ while (source.startsWith("\\\n", nextClose)) nextClose += 2;
620
+ if (source[nextClose] === ")") return position;
621
+ }
620
622
  if (--depth < 0) {
621
623
  if (allowSubshell) return -1;
622
624
  break;
@@ -696,7 +698,7 @@ var SMALL_BIGINTS = Array.from({ length: 4097 }, (_, i) => BigInt(i));
696
698
  function smallBigInt(n) {
697
699
  return n >= 0 && n <= 4096 ? SMALL_BIGINTS[n] : BigInt(n);
698
700
  }
699
- var LARGE_INT_KEYS = new Int32Array(16);
701
+ var LARGE_INT_KEYS = new Float64Array(16);
700
702
  var LARGE_INT_STRS = new Array(16).fill("");
701
703
  function intToStr(n) {
702
704
  if (n >= 0 && n <= 65536) {
@@ -789,7 +791,7 @@ function evalSafeSmi(node, refs, budget) {
789
791
  const v = evalSafeSmi(node.operand, refs, budget);
790
792
  if (v === void 0 || v < -94906265 || v > 94906265) return void 0;
791
793
  if (node.operator === "+") return v;
792
- if (node.operator === "-") return -v;
794
+ if (node.operator === "-") return v === 0 ? 0 : -v;
793
795
  if (node.operator === "!") return v === 0 ? 1 : 0;
794
796
  return void 0;
795
797
  }
@@ -836,10 +838,14 @@ function evalSafeSmi(node, refs, budget) {
836
838
  return l - r;
837
839
  case "*":
838
840
  return l * r;
839
- case "/":
840
- return Math.trunc(l / r);
841
- case "%":
842
- return l % r | 0;
841
+ case "/": {
842
+ const q = Math.trunc(l / r);
843
+ return q === 0 ? 0 : q;
844
+ }
845
+ case "%": {
846
+ const m = l % r | 0;
847
+ return m === 0 ? 0 : m;
848
+ }
843
849
  case "<":
844
850
  return l < r ? 1 : 0;
845
851
  case "<=":
@@ -1561,7 +1567,8 @@ function stringIndex(source, budget, word) {
1561
1567
  }
1562
1568
  function arraySelector(source, offset, budget = new ParseBudget(), word) {
1563
1569
  budget.admit();
1564
- return source === "@" || source === "*" ? { kind: "members", separator: source } : { kind: "element", index: word ? stringIndex(source, budget, word) : literalIndex(source, offset, budget) };
1570
+ const cleanSource = source.includes("\\\n") ? source.replace(/\\\n/gu, "") : source;
1571
+ return cleanSource === "@" || cleanSource === "*" ? { kind: "members", separator: cleanSource } : { kind: "element", index: word ? stringIndex(cleanSource, budget, word) : literalIndex(cleanSource, offset, budget) };
1565
1572
  }
1566
1573
  function setArraySelector(part, selector) {
1567
1574
  selectors.set(part, selector);
@@ -1928,6 +1935,11 @@ var HereDocumentSyntaxError = class extends Error {
1928
1935
  }
1929
1936
  diagnostic;
1930
1937
  };
1938
+ function isSelfDelimitingCompound(command) {
1939
+ if (!command || command.redirects.length > 0) return false;
1940
+ if (command.kind === "function") return isSelfDelimitingCompound(command.body);
1941
+ return command.kind !== "simple" && command.kind !== "arithmetic" && command.kind !== "conditional";
1942
+ }
1931
1943
  var scriptSeparators = /* @__PURE__ */ new WeakMap();
1932
1944
  var functionLayouts = /* @__PURE__ */ new WeakMap();
1933
1945
  function functionReprintedLines(script) {
@@ -2082,7 +2094,7 @@ var IncompleteShellInput = class extends Error {
2082
2094
  var CompoundListEofError = class extends ShellSyntaxError {
2083
2095
  };
2084
2096
  var Lexer = class {
2085
- constructor(budget, source, depth, warnings = [], lineOffset = 0, byteLocale2 = false, documentLine, partial = false, lineIndex = new SourceLineIndex(source, budget), sourceOffset = 0, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax) {
2097
+ constructor(budget, source, depth, warnings = [], lineOffset = 0, byteLocale2 = false, documentLine, partial = false, lineIndex = new SourceLineIndex(source, budget), sourceOffset = 0, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax, aliases) {
2086
2098
  this.budget = budget;
2087
2099
  this.source = source;
2088
2100
  this.depth = depth;
@@ -2097,6 +2109,7 @@ var Lexer = class {
2097
2109
  this.sourceValues = sourceValues;
2098
2110
  this.byteSource = byteSource;
2099
2111
  this.syntax = syntax;
2112
+ this.aliases = aliases;
2100
2113
  if (depth > this.budget.maxSyntaxDepth) throw new ShellSyntaxError(`Syntax nesting exceeds ${this.budget.maxSyntaxDepth}`, 0);
2101
2114
  }
2102
2115
  budget;
@@ -2113,6 +2126,7 @@ var Lexer = class {
2113
2126
  sourceValues;
2114
2127
  byteSource;
2115
2128
  syntax;
2129
+ aliases;
2116
2130
  position = 0;
2117
2131
  operandDepth = 0;
2118
2132
  printedNewlineReduction = 0;
@@ -2375,7 +2389,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2375
2389
  }
2376
2390
  this.error("Unterminated delimiter expansion syntax");
2377
2391
  }
2378
- word(terminator, enclosingQuoted = false, literal = false, arithmetic = false, arithmeticExpansion = false) {
2392
+ word(terminator, enclosingQuoted = false, literal = false, arithmetic = false, arithmeticExpansion = false, assignmentSubscriptEnd = -1) {
2379
2393
  this.budget.admit();
2380
2394
  const offset = this.position;
2381
2395
  const reduction = this.printedNewlineReduction;
@@ -2452,7 +2466,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2452
2466
  if (++brackets > this.budget.maxSyntaxDepth) this.error(`Subscript syntax nesting exceeds ${this.budget.maxSyntaxDepth}`);
2453
2467
  } else if (current === "]" && brackets > 0) brackets--;
2454
2468
  else if (terminator.includes(current) && (!arithmetic || current !== ":" || parentheses === 0 && conditionals === 0)) break;
2455
- } else if (!this.braceReplay) {
2469
+ } else if (!this.braceReplay && this.position > assignmentSubscriptEnd) {
2456
2470
  if (!enclosingQuoted && !literal && current === "(" && (patternParentheses > 0 || this.position > offset && "?*+@!".includes(this.source[this.position - 1] ?? " ") && (this.position - 1 === offset || this.source[this.position - 2] !== "\\") && !(this.source[this.position + 1] === ")" && /^\(\)\s*(?:\{|\(|if\b|case\b|while\b|until\b|for\b|select\b|\[\[)/u.test(this.source.slice(this.position))) && this.hasClosingExtglobParen(this.position))) {
2457
2471
  if (++patternParentheses > this.budget.maxSyntaxDepth) this.error(`Syntax nesting exceeds ${this.budget.maxSyntaxDepth}`);
2458
2472
  } else if (!enclosingQuoted && !literal && current === ")" && patternParentheses > 0) {
@@ -2472,7 +2486,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2472
2486
  let script;
2473
2487
  try {
2474
2488
  this.budget.admit();
2475
- nested = new Parser(this.budget, this.source.slice(start), this.depth + this.operandDepth + 1, this.warnings, this.lineAt(start) - 1, void 0, this.byteLocale, false, this.lineIndex, this.sourceOffset + start, false, this.sourceValues, this.byteSource, this.syntax);
2489
+ nested = new Parser(this.budget, this.source.slice(start), this.depth + this.operandDepth + 1, this.warnings, this.lineAt(start) - 1, void 0, this.byteLocale, false, this.lineIndex, this.sourceOffset + start, false, this.sourceValues, this.byteSource, this.syntax, this.aliases);
2476
2490
  script = nested.script(/* @__PURE__ */ new Set([")"]));
2477
2491
  } catch (error) {
2478
2492
  if (this.documentLine !== void 0 && error instanceof ShellSyntaxError && !/nesting|exceeds/u.test(error.reason)) throw this.documentSubstitutionError(this.source.slice(start), error);
@@ -2490,7 +2504,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2490
2504
  parts.push({ kind: "process-substitution", direction, script, line, sourceLine: script.line ?? line, quoted: true });
2491
2505
  continue;
2492
2506
  }
2493
- if (current === "$" && this.source[this.position + 1] === "'" && !enclosingQuoted && !literal) {
2507
+ if (current === "$" && this.source[this.position + 1] === "'" && !enclosingQuoted) {
2494
2508
  plain = false;
2495
2509
  this.unprintedWords++;
2496
2510
  const start = this.position;
@@ -2515,8 +2529,9 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2515
2529
  text3(this.source.slice(start, end), true, false, start, end);
2516
2530
  } else text3(this.source.slice(this.position + 1, end), true, false, this.position, Math.min(end + 1, this.source.length));
2517
2531
  this.position = Math.min(end + 1, this.source.length);
2518
- } else if (current === '"') {
2532
+ } else if (current === '"' || current === "$" && this.source[this.position + 1] === '"' && !enclosingQuoted) {
2519
2533
  plain = false;
2534
+ if (current === "$") this.position++;
2520
2535
  const quoteLine = this.lineAt(this.position);
2521
2536
  this.position++;
2522
2537
  text3("", true, true, this.position - 1, this.position);
@@ -2571,7 +2586,6 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2571
2586
  } else if (current === "$" || current === "`") {
2572
2587
  plain = false;
2573
2588
  if (literal) {
2574
- if (current === "$" && ["'", '"'].includes(this.source[this.position + 1] ?? "")) this.error("Unsupported shell quoting in here-document delimiter");
2575
2589
  text3(this.literalExpansion(), current === "`");
2576
2590
  } else this.expansion(parts, enclosingQuoted);
2577
2591
  } else {
@@ -2691,6 +2705,47 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2691
2705
  }
2692
2706
  this.error("Unterminated ANSI-C quote", { quote: "'", line: quoteLine });
2693
2707
  }
2708
+ readExpansionName() {
2709
+ while (this.source.startsWith("\\\n", this.position)) this.position += 2;
2710
+ const first = this.source[this.position];
2711
+ if (first && /^[?@*#-]$/u.test(first)) {
2712
+ this.position++;
2713
+ return first;
2714
+ }
2715
+ if (first && /^[0-9]$/u.test(first)) {
2716
+ let name2 = "";
2717
+ while (this.position < this.source.length) {
2718
+ if (this.source.startsWith("\\\n", this.position)) {
2719
+ this.position += 2;
2720
+ continue;
2721
+ }
2722
+ const ch = this.source[this.position];
2723
+ if (!ch || !/^[0-9]$/u.test(ch)) break;
2724
+ name2 += ch;
2725
+ this.position++;
2726
+ }
2727
+ return name2;
2728
+ }
2729
+ if (first && /^[a-zA-Z_]$/u.test(first)) {
2730
+ let name2 = "";
2731
+ while (this.position < this.source.length) {
2732
+ if (this.source.startsWith("\\\n", this.position)) {
2733
+ this.position += 2;
2734
+ continue;
2735
+ }
2736
+ const ch = this.source[this.position];
2737
+ if (!ch || !/^[a-zA-Z_0-9]$/u.test(ch)) break;
2738
+ name2 += ch;
2739
+ this.position++;
2740
+ }
2741
+ return name2;
2742
+ }
2743
+ return void 0;
2744
+ }
2745
+ peekAfterContinuation(offset = this.position) {
2746
+ while (this.source.startsWith("\\\n", offset)) offset += 2;
2747
+ return offset;
2748
+ }
2694
2749
  expansion(parts, quoted) {
2695
2750
  this.budget.admit();
2696
2751
  const spellingStart = this.position;
@@ -2704,8 +2759,9 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2704
2759
  this.position++;
2705
2760
  let source = "";
2706
2761
  const sourceValues = this.sourceValues ? /* @__PURE__ */ new Map() : void 0;
2762
+ const backtickEscapable = quoted && this.documentLine === void 0 ? /[$`\\"]/u : /[$`\\]/u;
2707
2763
  while (this.position < this.source.length && this.source[this.position] !== "`") {
2708
- if (this.source[this.position] === "\\" && /[$`\\]/u.test(this.source[this.position + 1] ?? "")) this.position++;
2764
+ if (this.source[this.position] === "\\" && backtickEscapable.test(this.source[this.position + 1] ?? "")) this.position++;
2709
2765
  const opaque = this.sourceValues?.get(this.sourceOffset + this.position);
2710
2766
  if (opaque !== void 0) {
2711
2767
  this.budget.admit();
@@ -2716,7 +2772,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2716
2772
  if (this.source[this.position] !== "`") this.error("Unterminated command substitution");
2717
2773
  this.position++;
2718
2774
  try {
2719
- parts.push({ kind: "substitution", form: "backtick", script: parseSource(source, this.depth + this.operandDepth + 1, this.warnings, line - 1, this.byteLocale, this.budget, this.documentLine === void 0, sourceValues, this.byteSource, this.syntax), line, quoted });
2775
+ parts.push({ kind: "substitution", form: "backtick", script: parseSource(source, this.depth + this.operandDepth + 1, this.warnings, line - 1, this.byteLocale, this.budget, this.documentLine === void 0, sourceValues, this.byteSource, this.syntax, this.aliases), line, quoted });
2720
2776
  } catch (error) {
2721
2777
  if (this.documentLine === void 0 || !(error instanceof ShellSyntaxError) || /nesting|exceeds/u.test(error.reason)) throw error;
2722
2778
  this.budget.admit();
@@ -2729,20 +2785,24 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2729
2785
  return;
2730
2786
  }
2731
2787
  this.position++;
2732
- if (this.source[this.position] === "$" || this.source[this.position] === "!" && !this.syntax.specialParameters.length || !quoted && ["'", '"'].includes(this.source[this.position] ?? "")) this.error("Unsupported shell quoting or special parameter");
2733
- if (this.source.startsWith("((", this.position)) {
2734
- const start = this.position + 2;
2735
- const end = arithmeticEnd(this.source, start, false, this.budget.maxSyntaxDepth);
2788
+ while (this.source.startsWith("\\\n", this.position)) this.position += 2;
2789
+ const firstParen = this.source[this.position] === "(" ? this.position : -1;
2790
+ const secondParen = firstParen !== -1 ? this.peekAfterContinuation(firstParen + 1) : -1;
2791
+ const arithmeticEndPos = secondParen !== -1 && this.source[secondParen] === "(" ? arithmeticEnd(this.source, secondParen + 1, true, this.budget.maxSyntaxDepth) : -1;
2792
+ if (arithmeticEndPos !== -1) {
2793
+ const start = secondParen + 1;
2794
+ const end = arithmeticEndPos;
2736
2795
  const source = this.source.slice(start, end);
2737
2796
  parts.push({ kind: "arithmetic", expression: prepareArithmetic(source, this.budget), source, line, quoted });
2738
- this.position = end + 2;
2797
+ const afterFirstClose = this.peekAfterContinuation(end + 1);
2798
+ this.position = afterFirstClose + 1;
2739
2799
  } else if (this.source[this.position] === "(") {
2740
2800
  const start = this.position + 1;
2741
2801
  let nested;
2742
2802
  let script;
2743
2803
  try {
2744
2804
  this.budget.admit();
2745
- nested = new Parser(this.budget, this.source.slice(start), this.depth + this.operandDepth + 1, this.warnings, this.lineAt(start) - 1, void 0, this.byteLocale, false, this.lineIndex, this.sourceOffset + start, false, this.sourceValues, this.byteSource, this.syntax);
2805
+ nested = new Parser(this.budget, this.source.slice(start), this.depth + this.operandDepth + 1, this.warnings, this.lineAt(start) - 1, void 0, this.byteLocale, false, this.lineIndex, this.sourceOffset + start, false, this.sourceValues, this.byteSource, this.syntax, this.aliases);
2746
2806
  script = nested.script(/* @__PURE__ */ new Set([")"]));
2747
2807
  } catch (error) {
2748
2808
  if (this.documentLine !== void 0 && error instanceof ShellSyntaxError && !/nesting|exceeds/u.test(error.reason)) throw this.documentSubstitutionError(this.source.slice(start), error);
@@ -2759,23 +2819,28 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2759
2819
  else this.printedNewlineReduction += this.source.slice(start, this.position - 1).split("\n").length - 1 - script.printedNewlines;
2760
2820
  parts.push({ kind: "substitution", form: "dollar-parenthesis", script, line, sourceLine: script.line ?? line, quoted });
2761
2821
  } else if (this.source[this.position] === "{") {
2762
- this.position++;
2822
+ this.position = this.peekAfterContinuation(this.position + 1);
2763
2823
  const parameterStart = this.position - 2;
2764
- const listing = this.source[this.position] === "!" && /[a-zA-Z_0-9]/u.test(this.source[this.position + 1] ?? "");
2765
- if (listing) this.position++;
2766
- const length = !listing && this.source[this.position] === "#" && (/[a-zA-Z_0-9]/u.test(this.source[this.position + 1] ?? "") || ["@", "*"].includes(this.source[this.position + 1] ?? "") && this.source[this.position + 2] === "}" || this.syntax.specialParameters.some((parameter) => parameter.name === this.source[this.position + 1]));
2767
- if (length) this.position++;
2824
+ const afterBang = this.peekAfterContinuation(this.position + 1);
2825
+ const listing = this.source[this.position] === "!" && /[a-zA-Z_0-9]/u.test(this.source[afterBang] ?? "");
2826
+ if (listing) this.position = afterBang;
2827
+ const afterHash = this.peekAfterContinuation(this.position + 1);
2828
+ const length = !listing && this.source[this.position] === "#" && (/[a-zA-Z_0-9]/u.test(this.source[afterHash] ?? "") || ["@", "*"].includes(this.source[afterHash] ?? "") && this.source[this.peekAfterContinuation(afterHash + 1)] === "}" || this.syntax.specialParameters.some((parameter) => parameter.name === this.source[afterHash]));
2829
+ if (length) this.position = afterHash;
2768
2830
  const specialParameter = this.syntax.specialParameters.find((parameter) => parameter.name === this.source[this.position]);
2769
- const name2 = specialParameter?.name ?? /^(?:[a-zA-Z_][a-zA-Z_0-9]*|[0-9]+|[?@*#-])/u.exec(this.source.slice(this.position))?.[0];
2831
+ if (specialParameter) this.position += specialParameter.name.length;
2832
+ const dollarBang = !specialParameter && "$!".includes(this.source[this.position] ?? " ") ? this.source[this.position++] : void 0;
2833
+ const name2 = specialParameter?.name ?? dollarBang ?? this.readExpansionName();
2770
2834
  if (!name2) this.error("Unsupported parameter expansion");
2771
- this.position += name2.length;
2835
+ this.position = this.peekAfterContinuation(this.position);
2772
2836
  let prefixNames;
2773
2837
  let indirect = false;
2774
2838
  if (listing && this.source[this.position] !== "[") {
2775
2839
  const separator = this.source[this.position];
2776
- if ((separator === "*" || separator === "@") && this.source[this.position + 1] === "}") {
2840
+ const afterSep = this.peekAfterContinuation(this.position + 1);
2841
+ if ((separator === "*" || separator === "@") && this.source[afterSep] === "}") {
2777
2842
  prefixNames = separator;
2778
- this.position++;
2843
+ this.position = afterSep;
2779
2844
  } else indirect = true;
2780
2845
  }
2781
2846
  let selector;
@@ -2786,7 +2851,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2786
2851
  const end = this.position;
2787
2852
  if (this.source[end] !== "]") this.error("Unterminated indexed-array subscript");
2788
2853
  selector = arraySelector(this.source.slice(start, end), start, this.budget, keyWord);
2789
- this.position = end + 1;
2854
+ this.position = this.peekAfterContinuation(end + 1);
2790
2855
  if (listing && selector.kind === "members" && this.source[this.position] !== "}" && this.source[this.position] !== "@") this.error("Unsupported array-key operator");
2791
2856
  }
2792
2857
  if (listing && selector?.kind === "element") indirect = true;
@@ -2796,14 +2861,34 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2796
2861
  }
2797
2862
  let transform;
2798
2863
  if (this.source[this.position] === "@") {
2799
- const operation2 = this.source[this.position + 1];
2800
- if (length || prefixNames || !["Q", "E", "a", "A", "K", "k", "P", "u", "U", "L"].includes(operation2 ?? "") || this.source[this.position + 2] !== "}") this.error("Unsupported parameter transform");
2864
+ const opPos = this.peekAfterContinuation(this.position + 1);
2865
+ const operation2 = this.source[opPos];
2866
+ const closePos = this.peekAfterContinuation(opPos + 1);
2867
+ if (length || prefixNames || !["Q", "E", "a", "A", "K", "k", "P", "u", "U", "L"].includes(operation2 ?? "") || this.source[closePos] !== "}") this.error("Unsupported parameter transform");
2801
2868
  transform = operation2;
2802
- this.position += 2;
2869
+ this.position = closePos;
2870
+ }
2871
+ const firstOpChar = this.source[this.position];
2872
+ const secondOpPos = this.peekAfterContinuation(this.position + 1);
2873
+ const secondOpChar = this.source[secondOpPos];
2874
+ const caseOperator = firstOpChar === "^" || firstOpChar === "," ? firstOpChar.repeat(secondOpChar === firstOpChar ? 2 : 1) : void 0;
2875
+ let operator = caseOperator;
2876
+ let operatorEnd = caseOperator ? caseOperator.length === 2 ? secondOpPos + 1 : this.position + 1 : this.position;
2877
+ if (!operator) {
2878
+ if (firstOpChar === ":" && secondOpChar && "-=+?".includes(secondOpChar)) {
2879
+ operator = `:${secondOpChar}`;
2880
+ operatorEnd = secondOpPos + 1;
2881
+ } else if ((firstOpChar === "#" || firstOpChar === "%") && secondOpChar === firstOpChar) {
2882
+ operator = `${firstOpChar}${secondOpChar}`;
2883
+ operatorEnd = secondOpPos + 1;
2884
+ } else if (firstOpChar === "/" && secondOpChar && "/#%".includes(secondOpChar)) {
2885
+ operator = `/${secondOpChar}`;
2886
+ operatorEnd = secondOpPos + 1;
2887
+ } else if (firstOpChar && "-=+?#%/".includes(firstOpChar)) {
2888
+ operator = firstOpChar;
2889
+ operatorEnd = this.position + 1;
2890
+ }
2803
2891
  }
2804
- const caseCharacter = this.source[this.position];
2805
- const caseOperator = caseCharacter === "^" || caseCharacter === "," ? caseCharacter.repeat(this.source[this.position + 1] === caseCharacter ? 2 : 1) : void 0;
2806
- const operator = caseOperator ?? /^(?::[-=+?]|##|%%|\/\/|\/[#%]?|[-=+?#%])/u.exec(this.source.slice(this.position))?.[0];
2807
2892
  let alternate;
2808
2893
  let replacement;
2809
2894
  let substring;
@@ -2813,7 +2898,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2813
2898
  try {
2814
2899
  if (operator) {
2815
2900
  if (length) this.error("Invalid length expansion");
2816
- this.position += operator.length;
2901
+ this.position = operatorEnd;
2817
2902
  alternate = this.word(operator.startsWith("/") ? "/}" : "}", quoted && !caseOperator && !["#", "##", "%", "%%"].includes(operator) && !operator.startsWith("/"));
2818
2903
  if (operator.startsWith("/") && this.source[this.position] === "/") {
2819
2904
  this.position++;
@@ -2821,7 +2906,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2821
2906
  }
2822
2907
  } else {
2823
2908
  if (length || name2 !== "@" && name2 !== "*" && !/^(?:[a-zA-Z_][a-zA-Z_0-9]*|[0-9]+)$/u.test(name2)) this.error("Unsupported non-scalar substring expansion");
2824
- this.position++;
2909
+ this.position = secondOpPos;
2825
2910
  const offset = this.word(":}", true, false, true);
2826
2911
  let substringLength;
2827
2912
  if (this.source[this.position] === ":") {
@@ -2835,6 +2920,7 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2835
2920
  this.operandDepth--;
2836
2921
  }
2837
2922
  }
2923
+ this.position = this.peekAfterContinuation(this.position);
2838
2924
  if (this.source[this.position] !== "}") {
2839
2925
  let end = this.position;
2840
2926
  if (this.ordinaryBacktick && !selector && !operator && !substring && /^[a-zA-Z_]/u.test(name2) && !"^,@".includes(this.source[this.position] ?? "")) {
@@ -2852,9 +2938,10 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2852
2938
  }
2853
2939
  } else {
2854
2940
  const specialParameter = this.syntax.specialParameters.find((parameter) => parameter.name === this.source[this.position]);
2855
- const name2 = specialParameter?.name ?? /^(?:[a-zA-Z_][a-zA-Z_0-9]*|[?@*#0-9-])/u.exec(this.source.slice(this.position))?.[0];
2941
+ if (specialParameter) this.position += specialParameter.name.length;
2942
+ const dollarBang = !specialParameter && "$!".includes(this.source[this.position] ?? " ") ? this.source[this.position++] : void 0;
2943
+ const name2 = specialParameter?.name ?? dollarBang ?? (this.source[this.position] && /^[0-9]$/u.test(this.source[this.position]) ? this.source[this.position++] : this.readExpansionName());
2856
2944
  if (name2) {
2857
- this.position += name2.length;
2858
2945
  parts.push({ kind: "variable", name: name2, quoted, line, ...specialParameter ? { specialParameter } : {} });
2859
2946
  } else parts.push({ kind: "text", value: "$", quoted });
2860
2947
  }
@@ -2865,16 +2952,22 @@ shell: command substitution: line ${line}: \`${sourceLine}'
2865
2952
  }
2866
2953
  };
2867
2954
  var Parser = class {
2868
- constructor(budget, source, depth, warnings = [], lineOffset = 0, position, byteLocale2 = false, partial = false, lineIndex = new SourceLineIndex(source, budget), sourceOffset = 0, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax) {
2955
+ constructor(budget, source, depth, warnings = [], lineOffset = 0, position, byteLocale2 = false, partial = false, lineIndex = new SourceLineIndex(source, budget), sourceOffset = 0, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax, aliases) {
2869
2956
  this.budget = budget;
2957
+ this.aliases = aliases;
2870
2958
  if (position === void 0 && depth === 0 && source.includes("\0")) throw new ShellSyntaxError("NUL bytes are not valid shell source", source.indexOf("\0"));
2871
2959
  budget.admit();
2872
- this.lexer = new Lexer(budget, source, depth, warnings, lineOffset, byteLocale2, void 0, partial, lineIndex, sourceOffset, ordinaryBacktick, sourceValues, byteSource, syntax);
2960
+ this.lexer = new Lexer(budget, source, depth, warnings, lineOffset, byteLocale2, void 0, partial, lineIndex, sourceOffset, ordinaryBacktick, sourceValues, byteSource, syntax, aliases);
2873
2961
  this.lexer.position = position ?? 0;
2874
2962
  this.current = this.lexer.next();
2875
2963
  }
2876
2964
  budget;
2965
+ aliases;
2877
2966
  lexer;
2967
+ aliasFrames = [];
2968
+ aliasNextWords = /* @__PURE__ */ new WeakSet();
2969
+ tokenAliases = /* @__PURE__ */ new WeakMap();
2970
+ tokenLexers = /* @__PURE__ */ new WeakMap();
2878
2971
  current;
2879
2972
  lookahead;
2880
2973
  nesting = 0;
@@ -2887,12 +2980,74 @@ var Parser = class {
2887
2980
  }
2888
2981
  advance() {
2889
2982
  const previous = this.current;
2890
- this.current = this.lookahead ?? this.lexer.next();
2983
+ this.current = this.lookahead ?? this.nextToken();
2984
+ this.lexer = this.tokenLexers.get(this.current) ?? this.lexer;
2891
2985
  this.lookahead = void 0;
2892
2986
  return previous;
2893
2987
  }
2894
2988
  peek() {
2895
- return this.lookahead ??= this.lexer.next();
2989
+ if (!this.lookahead) {
2990
+ const lexer = this.lexer;
2991
+ this.lookahead = this.nextToken();
2992
+ this.lexer = lexer;
2993
+ }
2994
+ return this.lookahead;
2995
+ }
2996
+ nextToken() {
2997
+ let token = this.lexer.next();
2998
+ if (!this.aliases?.size) return token;
2999
+ this.tokenLexers.set(token, this.lexer);
3000
+ this.tokenAliases.set(token, this.aliasFrames.map((frame) => frame.name));
3001
+ let trailing = false;
3002
+ while (token.kind === "end" && this.aliasFrames.length) {
3003
+ const frame = this.aliasFrames.pop();
3004
+ this.lexer = frame.lexer;
3005
+ trailing ||= frame.trailing;
3006
+ token = frame.next;
3007
+ }
3008
+ if (trailing) this.aliasNextWords.add(token);
3009
+ return token;
3010
+ }
3011
+ expandAlias() {
3012
+ while (this.current.kind === "word") {
3013
+ const name2 = this.current.word?.plain;
3014
+ if (name2 === void 0 || this.current.word.parts.some((part) => part.quoted) || this.tokenAliases.get(this.current)?.includes(name2)) return;
3015
+ const value = this.aliases?.get(name2);
3016
+ if (value === void 0) return;
3017
+ this.budget.admit(value.length + 1);
3018
+ const lexer = this.lexer;
3019
+ const line = lexer.lineAt(this.current.offset);
3020
+ const next = this.lookahead ?? lexer.next();
3021
+ this.tokenLexers.set(next, this.tokenLexers.get(next) ?? lexer);
3022
+ this.lookahead = void 0;
3023
+ this.aliasFrames.push({ lexer, next, name: name2, trailing: value.endsWith(" ") || value.endsWith(" ") });
3024
+ this.lexer = new Lexer(this.budget, value, lexer.depth, lexer.warnings, line - 1, lexer.byteLocale, void 0, false, void 0, 0, false, void 0, lexer.byteSource, lexer.syntax, this.aliases);
3025
+ this.current = this.nextToken();
3026
+ }
3027
+ }
3028
+ assignmentWord(compound = false) {
3029
+ const word = this.current.word;
3030
+ const bracket = word.spelling?.indexOf("[") ?? -1;
3031
+ const prefix = word.spelling?.slice(0, bracket);
3032
+ if (bracket >= 0 && (compound && bracket === 0 || prefix && scalarAssignmentName({
3033
+ offset: word.offset,
3034
+ parts: [{ kind: "text", quoted: false, value: prefix + "=" }]
3035
+ }) === prefix)) {
3036
+ const scanner = new Lexer(this.budget, this.lexer.source, this.lexer.depth, [], this.lexer.lineOffset, this.lexer.byteLocale, void 0, false, this.lexer.lineIndex, this.lexer.sourceOffset, this.lexer.ordinaryBacktick, this.lexer.sourceValues, this.lexer.byteSource, this.lexer.syntax);
3037
+ scanner.position = word.offset + bracket + 1;
3038
+ scanner.word("]");
3039
+ const end = scanner.position;
3040
+ if (end >= this.current.end && this.lexer.source[end] === "]" && (this.lexer.source[end + 1] === "=" || this.lexer.source.slice(end + 1, end + 3) === "+=")) {
3041
+ this.lexer.position = word.offset;
3042
+ const parsed = this.lexer.word(void 0, false, false, false, false, end);
3043
+ this.budget.admit();
3044
+ const complete = { ...parsed, spelling: this.lexer.source.slice(word.offset, this.lexer.position) };
3045
+ this.lookahead = void 0;
3046
+ this.current = this.lexer.next();
3047
+ return complete;
3048
+ }
3049
+ }
3050
+ return this.advance().word;
2896
3051
  }
2897
3052
  is(value) {
2898
3053
  return this.current.value === value;
@@ -2915,6 +3070,8 @@ var Parser = class {
2915
3070
  const line = this.lexer.lineAt(this.current.offset);
2916
3071
  if (captureInputUnits) this.completedInput = { lists, count: 0, line };
2917
3072
  while (this.current.kind !== "end" && !stops.has(this.current.value)) {
3073
+ this.expandAlias();
3074
+ if (this.isEnd() || stops.has(this.current.value)) break;
2918
3075
  this.budget.admit();
2919
3076
  const pipelines = [this.pipeline()];
2920
3077
  const operators = [];
@@ -2927,13 +3084,13 @@ var Parser = class {
2927
3084
  lists.push({ pipelines, operators, ...terminator ? { terminator } : {} });
2928
3085
  separators.push(this.is("\n"));
2929
3086
  if (captureInputUnits && this.is("\n")) this.completedInput.count = lists.length;
2930
- if (inputUnit && this.is("\n")) break;
3087
+ if (inputUnit && !this.aliasFrames.length && this.is("\n")) break;
2931
3088
  if (terminator || this.is(";") || this.is("\n")) {
2932
3089
  this.advance();
2933
3090
  if (captureInputUnits && this.is("\n")) this.completedInput.count = lists.length;
2934
- if (inputUnit && this.is("\n")) break;
3091
+ if (inputUnit && !this.aliasFrames.length && this.is("\n")) break;
2935
3092
  this.newlines();
2936
- } else if (!this.isEnd() && !this.is(")") && !(stops.has(this.current.value) && [";;", ";&", ";;&"].includes(this.current.value))) this.error("Expected command separator");
3093
+ } else if (!this.isEnd() && !this.is(")") && !(stops.has(this.current.value) && ([";;", ";&", ";;&"].includes(this.current.value) || isSelfDelimitingCompound(pipelines.at(-1)?.commands.at(-1))))) this.error("Expected command separator");
2937
3094
  }
2938
3095
  const printed = printedSimpleLines(lists, separators, this.budget);
2939
3096
  scriptSeparators.set(lists, Object.freeze(separators));
@@ -2961,6 +3118,7 @@ var Parser = class {
2961
3118
  return { commands, negate };
2962
3119
  }
2963
3120
  command() {
3121
+ this.expandAlias();
2964
3122
  if (++this.nesting + this.lexer.depth > this.lexer.budget.maxSyntaxDepth) this.error(`Syntax nesting exceeds ${this.lexer.budget.maxSyntaxDepth}`);
2965
3123
  this.budget.admit();
2966
3124
  const line = this.lexer.lineAt(this.current.offset);
@@ -2976,7 +3134,8 @@ var Parser = class {
2976
3134
  }
2977
3135
  commandInner() {
2978
3136
  this.budget.admit();
2979
- const arithmeticCommandEnd = this.is("(") && this.lexer.source.startsWith("((", this.current.offset) ? arithmeticEnd(this.lexer.source, this.current.offset + 2, true, this.lexer.budget.maxSyntaxDepth) : -1;
3137
+ const arithmeticSecondOpen = this.is("(") ? this.lexer.peekAfterContinuation(this.current.offset + 1) : -1;
3138
+ const arithmeticCommandEnd = arithmeticSecondOpen !== -1 && this.lexer.source[arithmeticSecondOpen] === "(" ? arithmeticEnd(this.lexer.source, arithmeticSecondOpen + 1, true, this.lexer.budget.maxSyntaxDepth) : -1;
2980
3139
  let command;
2981
3140
  if (this.is("[[")) {
2982
3141
  const start = this.current.end;
@@ -3049,11 +3208,11 @@ var Parser = class {
3049
3208
  this.advance();
3050
3209
  command = { kind: "conditional", expression, source, redirects: [] };
3051
3210
  } else if (arithmeticCommandEnd !== -1) {
3052
- const start = this.current.offset + 2;
3211
+ const start = arithmeticSecondOpen + 1;
3053
3212
  const end = arithmeticCommandEnd;
3054
3213
  const source = this.lexer.source.slice(start, end);
3055
3214
  command = { kind: "arithmetic", expression: prepareArithmetic(source, this.budget), source, redirects: [] };
3056
- this.lexer.position = end + 2;
3215
+ this.lexer.position = this.lexer.peekAfterContinuation(end + 1) + 1;
3057
3216
  this.lookahead = void 0;
3058
3217
  this.current = this.lexer.next();
3059
3218
  } else if (this.is("(") || this.is("{")) {
@@ -3119,32 +3278,60 @@ var Parser = class {
3119
3278
  const body = this.nonemptyScript(/* @__PURE__ */ new Set(["done"]));
3120
3279
  this.expect("done", true);
3121
3280
  command = { kind, condition, body, redirects: [] };
3122
- } else if (this.is("for") && this.peek().value === "(" && this.lexer.source.startsWith("((", this.peek().offset)) {
3281
+ } else if (this.is("for") && this.peek().value === "(" && this.lexer.source[this.lexer.peekAfterContinuation(this.peek().offset + 1)] === "(") {
3123
3282
  this.advance();
3124
- const start = this.current.offset + 2;
3283
+ const start = this.lexer.peekAfterContinuation(this.current.offset + 1) + 1;
3125
3284
  let partStart = start;
3126
3285
  let depth = 0;
3127
3286
  let end = start;
3287
+ let quote = "";
3288
+ let ansiQuote = false;
3289
+ const quotedSubstitutions = [];
3128
3290
  this.budget.admit(4);
3129
3291
  const sources = [];
3130
3292
  for (; end < this.lexer.source.length; end++) {
3131
3293
  this.budget.admit();
3132
3294
  const character = this.lexer.source[end];
3295
+ if (character === "\\" && (quote !== "'" || ansiQuote)) {
3296
+ end++;
3297
+ continue;
3298
+ }
3299
+ if (quote === '"' && character === "$" && this.lexer.source[end + 1] === "(") {
3300
+ if (quotedSubstitutions.length >= 64) this.error("Syntax nesting exceeds 64");
3301
+ quotedSubstitutions.push(depth);
3302
+ depth++;
3303
+ end++;
3304
+ quote = "";
3305
+ continue;
3306
+ }
3307
+ if (quote) {
3308
+ if (character === quote) quote = "";
3309
+ continue;
3310
+ }
3311
+ if (character === "'" || character === '"' || character === "`") {
3312
+ quote = character;
3313
+ ansiQuote = character === "'" && this.lexer.source[end - 1] === "$";
3314
+ continue;
3315
+ }
3133
3316
  if (character === "(") depth++;
3134
3317
  else if (character === ")") {
3135
- if (!depth && this.lexer.source[end + 1] === ")") break;
3318
+ if (!depth && this.lexer.source[this.lexer.peekAfterContinuation(end + 1)] === ")") break;
3136
3319
  if (--depth < 0) this.error("Unterminated arithmetic for", true);
3320
+ if (quotedSubstitutions.at(-1) === depth) {
3321
+ quotedSubstitutions.pop();
3322
+ quote = '"';
3323
+ }
3137
3324
  } else if (character === ";" && !depth) {
3138
3325
  if (sources.length === 2) this.error("Arithmetic for requires three expressions");
3139
3326
  sources.push(this.lexer.source.slice(partStart, end));
3140
3327
  partStart = end + 1;
3141
3328
  }
3142
3329
  }
3143
- if (end === this.lexer.source.length) this.error("Unterminated arithmetic for", true);
3330
+ if (quote || end === this.lexer.source.length) this.error("Unterminated arithmetic for", true);
3144
3331
  if (sources.length !== 2) this.error("Arithmetic for requires three expressions");
3145
3332
  sources.push(this.lexer.source.slice(partStart, end));
3146
3333
  const expressions = sources.map((source) => source.trim() ? prepareArithmetic(source, this.budget) : void 0);
3147
- this.lexer.position = end + 2;
3334
+ this.lexer.position = this.lexer.peekAfterContinuation(end + 1) + 1;
3148
3335
  this.lookahead = void 0;
3149
3336
  this.current = this.lexer.next();
3150
3337
  if (this.is(";")) this.advance();
@@ -3201,6 +3388,10 @@ var Parser = class {
3201
3388
  };
3202
3389
  let line;
3203
3390
  while (true) {
3391
+ if (this.aliasNextWords.has(this.current) || words.every((previous) => getArrayAssignment(previous) || scalarAssignmentName(previous))) {
3392
+ this.aliasNextWords.delete(this.current);
3393
+ this.expandAlias();
3394
+ }
3204
3395
  const wordLine = this.lexer.lineAt(Math.max(this.current.offset, this.current.end - 1));
3205
3396
  const redirect2 = this.redirect();
3206
3397
  if (redirect2) {
@@ -3208,14 +3399,14 @@ var Parser = class {
3208
3399
  redirects.push(redirect2);
3209
3400
  } else if (this.current.kind === "word") {
3210
3401
  line ??= wordLine;
3211
- let word = this.advance().word;
3402
+ let word = words.every((previous) => getArrayAssignment(previous) || scalarAssignmentName(previous)) || indexedDeclaration() ? this.assignmentWord() : this.advance().word;
3212
3403
  const head = compoundHead(word, this.budget);
3213
3404
  if (head && this.is("(")) {
3214
3405
  this.advance();
3215
3406
  const entries = [];
3216
3407
  this.newlines();
3217
3408
  while (this.current.kind === "word") {
3218
- const original = this.advance().word;
3409
+ const original = this.assignmentWord(true);
3219
3410
  const entry = compoundEntry(original, this.budget, (source) => parseArraySubscript(source, this.budget, this.lexer.byteLocale, this.lexer.depth, this.lexer.byteSource, this.lexer.syntax), (source, start) => {
3220
3411
  const lexer = new Lexer(this.budget, source, this.lexer.depth, [], 0, this.lexer.byteLocale, void 0, false, void 0, 0, false, void 0, this.lexer.byteSource, this.lexer.syntax);
3221
3412
  lexer.position = start;
@@ -3340,7 +3531,7 @@ function hereDocumentWords(document, line, byteLocale2, warnings, budgetOrSyntax
3340
3531
  }
3341
3532
  })();
3342
3533
  }
3343
- function parseShellUnit(source, position = 0, byteLocale2 = false, budgetOrByteSource = new ParseBudget(), lineIndexOrSyntax, sourceValues, byteSource = false, syntax) {
3534
+ function parseShellUnit(source, position = 0, byteLocale2 = false, budgetOrByteSource = new ParseBudget(), lineIndexOrSyntax, sourceValues, byteSource = false, syntax, aliases) {
3344
3535
  const budget = budgetOrByteSource instanceof ParseBudget ? budgetOrByteSource : new ParseBudget();
3345
3536
  const lineIndex = lineIndexOrSyntax instanceof SourceLineIndex ? lineIndexOrSyntax : new SourceLineIndex(source, budget);
3346
3537
  const captured = captureShellSyntax(syntax === void 0 ? lineIndexOrSyntax instanceof SourceLineIndex ? void 0 : lineIndexOrSyntax : syntax);
@@ -3348,7 +3539,7 @@ function parseShellUnit(source, position = 0, byteLocale2 = false, budgetOrByteS
3348
3539
  const warnings = [];
3349
3540
  budget.admit();
3350
3541
  if (lineIndex.source !== source || lineIndex.budget !== budget) throw new TypeError("Source line index belongs to a different source or parse budget");
3351
- const parser = new Parser(budget, source, 0, warnings, 0, position, byteLocale2, false, lineIndex, 0, false, sourceValues, raw, captured);
3542
+ const parser = new Parser(budget, source, 0, warnings, 0, position, byteLocale2, false, lineIndex, 0, false, sourceValues, raw, captured, aliases);
3352
3543
  const script = parser.script(/* @__PURE__ */ new Set(), true);
3353
3544
  const next = parser.current.end;
3354
3545
  const nul = source.indexOf("\0", position);
@@ -3356,7 +3547,7 @@ function parseShellUnit(source, position = 0, byteLocale2 = false, budgetOrByteS
3356
3547
  budget.admit(2);
3357
3548
  return { script: { ...script, ...warnings.length ? { warnings } : {} }, next };
3358
3549
  }
3359
- function parseShellInputUnit(source, byteLocale2 = false, budgetOrSyntax = new ParseBudget(), suppliedLineIndex, syntax) {
3550
+ function parseShellInputUnit(source, byteLocale2 = false, budgetOrSyntax = new ParseBudget(), suppliedLineIndex, syntax, aliases) {
3360
3551
  const budget = budgetOrSyntax instanceof ParseBudget ? budgetOrSyntax : new ParseBudget();
3361
3552
  const lineIndex = suppliedLineIndex ?? new SourceLineIndex(source, budget);
3362
3553
  const captured = captureShellSyntax(syntax === void 0 ? budgetOrSyntax instanceof ParseBudget ? void 0 : budgetOrSyntax : syntax);
@@ -3364,7 +3555,7 @@ function parseShellInputUnit(source, byteLocale2 = false, budgetOrSyntax = new P
3364
3555
  try {
3365
3556
  budget.admit();
3366
3557
  if (lineIndex.source !== source || lineIndex.budget !== budget) throw new TypeError("Source line index belongs to a different source or parse budget");
3367
- const parser = new Parser(budget, source, 0, warnings, 0, 0, byteLocale2, true, lineIndex, 0, false, void 0, false, captured);
3558
+ const parser = new Parser(budget, source, 0, warnings, 0, 0, byteLocale2, true, lineIndex, 0, false, void 0, false, captured, aliases);
3368
3559
  const script = parser.script(/* @__PURE__ */ new Set(), true);
3369
3560
  budget.admit(2);
3370
3561
  return { script: { ...script, ...warnings.length ? { warnings } : {} }, next: parser.current.end };
@@ -3374,10 +3565,10 @@ function parseShellInputUnit(source, byteLocale2 = false, budgetOrSyntax = new P
3374
3565
  throw error;
3375
3566
  }
3376
3567
  }
3377
- function parseSource(source, depth, warnings, lineOffset, byteLocale2, budget, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax) {
3568
+ function parseSource(source, depth, warnings, lineOffset, byteLocale2, budget, ordinaryBacktick = false, sourceValues, byteSource = false, syntax = defaultSyntax, aliases) {
3378
3569
  budget.admit();
3379
3570
  const warningCount = warnings.length;
3380
- const parser = new Parser(budget, source, depth, warnings, lineOffset, void 0, byteLocale2, false, void 0, 0, ordinaryBacktick, sourceValues, byteSource, syntax);
3571
+ const parser = new Parser(budget, source, depth, warnings, lineOffset, void 0, byteLocale2, false, void 0, 0, ordinaryBacktick, sourceValues, byteSource, syntax, aliases);
3381
3572
  try {
3382
3573
  const script = parser.script(/* @__PURE__ */ new Set(), false, ordinaryBacktick);
3383
3574
  if (parser.current.kind !== "end") parser.error("Unexpected token");
@@ -3393,502 +3584,6 @@ function parseSource(source, depth, warnings, lineOffset, byteLocale2, budget, o
3393
3584
  }
3394
3585
  }
3395
3586
 
3396
- // packages/safe-bash/src/commands/csvcut/index.ts
3397
- init_platform();
3398
- import {
3399
- CsvBudget,
3400
- CsvParser,
3401
- generatedHeaders,
3402
- parseCsvcutArguments,
3403
- resolveColumns,
3404
- serializeRow,
3405
- createCsvcutCommand as createRawCsvcutCommand,
3406
- createCsvcutCommands as createRawCsvcutCommands,
3407
- csvcutCommand as rawCsvcutCommand
3408
- } from "../../safe-bash-command-csvcut/index.js";
3409
- import { CsvBudget as CsvBudget2, CsvError, CsvParser as CsvParser2, csvcut, cutCsv, defaultCsvLimits, generatedHeaders as generatedHeaders2, parseCsvRecords, parseCsvcutArguments as parseCsvcutArguments2, resolveColumns as resolveColumns2, serializeRow as serializeRow2 } from "../../safe-bash-command-csvcut/index.js";
3410
- builtInDirectContextExecutors.add(rawCsvcutCommand.execute);
3411
- function createCsvcutCommand(options) {
3412
- const def = createRawCsvcutCommand(options);
3413
- if (options?.limits === void 0) builtInDirectContextExecutors.add(def.execute);
3414
- return def;
3415
- }
3416
- function createCsvcutCommands(options) {
3417
- const defs = createRawCsvcutCommands(options);
3418
- if (options?.limits === void 0) {
3419
- for (let i = 0; i < defs.length; i++) builtInDirectContextExecutors.add(defs[i].execute);
3420
- }
3421
- return defs;
3422
- }
3423
- function csvcutCommands(options = {}) {
3424
- const commands = createCsvcutCommands(options);
3425
- const replace = options.replace ?? false;
3426
- return {
3427
- name: "csvcut",
3428
- setup(host) {
3429
- for (const command of commands) host.commands.register(command, { replace });
3430
- }
3431
- };
3432
- }
3433
- var _syncAbortSignal;
3434
- var syncAbortSignal = () => _syncAbortSignal ??= new AbortController().signal;
3435
- function evalSyncCsvcut(inBytes, opArgs, readFileSync) {
3436
- if (inBytes !== void 0 && inBytes.byteLength > 16384) return void 0;
3437
- const budget = new CsvBudget({}, syncAbortSignal());
3438
- try {
3439
- const supplied = parseCsvcutArguments(opArgs, budget);
3440
- if (supplied.help || supplied.version) return void 0;
3441
- if (supplied.encoding && supplied.encoding.toLowerCase() !== "utf-8" && supplied.encoding.toLowerCase() !== "utf-8-sig") {
3442
- return void 0;
3443
- }
3444
- let sourceBytes = inBytes;
3445
- if (supplied.filePath !== void 0 && supplied.filePath !== "-") {
3446
- if (!readFileSync) return void 0;
3447
- const fileBytes = readFileSync(supplied.filePath);
3448
- if (!fileBytes || fileBytes.byteLength > 16384) return void 0;
3449
- sourceBytes = fileBytes;
3450
- }
3451
- if (supplied.names && supplied.headerless) return void 0;
3452
- const dialect = { ...supplied.dialect, profile: supplied.dialect?.profile ?? "utf8-sig-permissive-v1" };
3453
- if (Number.isSafeInteger(dialect.skipLines) && dialect.skipLines < 0) dialect.skipLines = 0;
3454
- if (sourceBytes === void 0) return void 0;
3455
- const parser = new CsvParser(dialect, budget);
3456
- const rows = [...parser.push(sourceBytes), ...parser.end()];
3457
- const first = rows[0];
3458
- if (supplied.names && !first) return void 0;
3459
- const headers = supplied.headerless ? generatedHeaders(first?.cells.length ?? 0, budget) : first?.cells ?? [];
3460
- let out = supplied.addBom ? "\uFEFF" : "";
3461
- if (supplied.names) {
3462
- for (let i = 0; i < headers.length; i++) {
3463
- out += `${String(i + (supplied.zero ? 0 : 1)).padStart(3, " ")}: ${headers[i]}
3464
- `;
3465
- }
3466
- return out;
3467
- }
3468
- const columns = headers.length ? resolveColumns(supplied, headers, budget) : [];
3469
- const project2 = (cells) => {
3470
- const projected = [];
3471
- for (let i = 0; i < columns.length; i++) {
3472
- projected.push(cells[columns[i]] ?? "");
3473
- }
3474
- return projected;
3475
- };
3476
- const heading = project2(headers);
3477
- if (supplied.lineNumbers) heading.unshift("line_number");
3478
- out += serializeRow(heading, budget);
3479
- let number2 = 0;
3480
- for (let i = supplied.headerless ? 0 : 1; i < rows.length; i++) {
3481
- const cells = project2(rows[i].cells);
3482
- if (supplied.deleteEmptyRows && cells.every((c) => c === "")) continue;
3483
- if (supplied.lineNumbers) cells.unshift(String(++number2));
3484
- out += serializeRow(cells, budget);
3485
- }
3486
- return out;
3487
- } catch {
3488
- return void 0;
3489
- } finally {
3490
- budget.dispose();
3491
- }
3492
- }
3493
-
3494
- // packages/safe-bash/src/commands/csvgrep/index.ts
3495
- init_platform();
3496
- import {
3497
- CsvBudget as CsvBudget3,
3498
- CsvParser as CsvParser3,
3499
- createMatcher,
3500
- generatedHeaders as generatedHeaders3,
3501
- matchesRow,
3502
- parseCsvgrepArguments,
3503
- selectColumns,
3504
- serializeRow as serializeRow3,
3505
- createCsvgrepCommand as createRawCsvgrepCommand,
3506
- createCsvgrepCommands as createRawCsvgrepCommands,
3507
- csvgrepCommand as rawCsvgrepCommand
3508
- } from "../../safe-bash-command-csvgrep/index.js";
3509
- import { CsvBudget as CsvBudget4, CsvError as CsvError2, CsvParser as CsvParser4, createMatcher as createMatcher2, csvgrep, generatedHeaders as generatedHeaders4, matchesRow as matchesRow2, parseCsvgrepArguments as parseCsvgrepArguments2, selectColumns as selectColumns2, serializeRow as serializeRow4 } from "../../safe-bash-command-csvgrep/index.js";
3510
- builtInDirectContextExecutors.add(rawCsvgrepCommand.execute);
3511
- function createCsvgrepCommand(options) {
3512
- const def = createRawCsvgrepCommand(options);
3513
- if (options?.limits === void 0) builtInDirectContextExecutors.add(def.execute);
3514
- return def;
3515
- }
3516
- function createCsvgrepCommands(options) {
3517
- const defs = createRawCsvgrepCommands(options);
3518
- if (options?.limits === void 0) {
3519
- for (let i = 0; i < defs.length; i++) builtInDirectContextExecutors.add(defs[i].execute);
3520
- }
3521
- return defs;
3522
- }
3523
- function csvgrepCommands(options = {}) {
3524
- const commands = createCsvgrepCommands(options);
3525
- const replace = options.replace ?? false;
3526
- return {
3527
- name: "csvgrep",
3528
- setup(host) {
3529
- for (const command of commands) host.commands.register(command, { replace });
3530
- }
3531
- };
3532
- }
3533
- var _syncAbortSignal2;
3534
- var syncAbortSignal2 = () => _syncAbortSignal2 ??= new AbortController().signal;
3535
- function evalSyncCsvgrep(inBytes, opArgs, readFileSync) {
3536
- if (inBytes !== void 0 && inBytes.byteLength > 16384) return void 0;
3537
- const budget = new CsvBudget3({}, syncAbortSignal2());
3538
- try {
3539
- const options = parseCsvgrepArguments(opArgs, budget);
3540
- if (!options.names) {
3541
- if (!options.columns) return void 0;
3542
- const modes = [options.match !== void 0, options.regex !== void 0, options.file !== void 0].filter(Boolean).length;
3543
- if (modes !== 1) return void 0;
3544
- }
3545
- if (options.names && options.headerless) return void 0;
3546
- let fileMatchSet = /* @__PURE__ */ new Set();
3547
- if (options.file !== void 0) {
3548
- if (!readFileSync) return void 0;
3549
- const patBytes = readFileSync(options.file);
3550
- if (!patBytes || patBytes.byteLength > 16384) return void 0;
3551
- const patText = new TextDecoder("utf-8", { fatal: false }).decode(patBytes);
3552
- fileMatchSet = new Set(patText.split(/\r?\n/).filter((l) => l.length > 0));
3553
- }
3554
- let sourceBytes = inBytes;
3555
- if (options.filePath !== void 0 && options.filePath !== "-") {
3556
- if (!readFileSync) return void 0;
3557
- const fileBytes = readFileSync(options.filePath);
3558
- if (!fileBytes || fileBytes.byteLength > 16384) return void 0;
3559
- sourceBytes = fileBytes;
3560
- }
3561
- if (sourceBytes === void 0) return void 0;
3562
- const parser = new CsvParser3(options.dialect ?? {}, budget);
3563
- const rows = [...parser.push(sourceBytes), ...parser.end()];
3564
- const matcher = options.names ? void 0 : createMatcher(options, fileMatchSet, budget);
3565
- let headers;
3566
- let columns = [];
3567
- let out = "";
3568
- for (const row of rows) {
3569
- if (headers === void 0) {
3570
- headers = options.headerless ? generatedHeaders3(row.cells.length + (options.lineNumbers ? 1 : 0), budget) : row.cells;
3571
- if (options.lineNumbers && !options.headerless) {
3572
- headers = ["line_numbers", ...headers];
3573
- }
3574
- if (options.names) {
3575
- for (let i = 0; i < headers.length; i++) {
3576
- out += `${String(i + (options.zero ? 0 : 1)).padStart(3)}: ${headers[i]}
3577
- `;
3578
- }
3579
- return out;
3580
- }
3581
- columns = selectColumns(options.columns, headers, options.zero ?? false, budget, void 0, options.lineNumbers ? 1 : 0);
3582
- out += serializeRow3(headers, budget);
3583
- if (!options.headerless) continue;
3584
- }
3585
- const cells = options.lineNumbers ? [String(row.line - (options.headerless ? 0 : 1)), ...row.cells] : row.cells;
3586
- if (matchesRow(cells, columns, matcher, options.any ?? false, options.invert ?? false, budget)) {
3587
- out += serializeRow3(cells, budget);
3588
- }
3589
- }
3590
- if (headers === void 0) {
3591
- if (options.names) return void 0;
3592
- out += serializeRow3([], budget);
3593
- }
3594
- return out;
3595
- } catch {
3596
- return void 0;
3597
- } finally {
3598
- budget.dispose();
3599
- }
3600
- }
3601
-
3602
- // packages/safe-bash/src/commands/htmlq/index.ts
3603
- init_platform();
3604
- import {
3605
- HtmlBudget,
3606
- HtmlError,
3607
- detachHtmlNode,
3608
- getInternalHtmlNode,
3609
- htmlText,
3610
- htmlq,
3611
- htmlqBaseline,
3612
- htmlqBytes,
3613
- inclusiveHtmlDescendants,
3614
- invocationOptions,
3615
- parseHtml,
3616
- parseHtmlSync,
3617
- parseHtmlqArguments,
3618
- replaceHtmlAttribute,
3619
- rustWhitespaceOnly,
3620
- selectHtml,
3621
- serializeHtml,
3622
- serializeHtmlBytes
3623
- } from "../../safe-bash-command-htmlq/index.js";
3624
- import { createHtmlqCommand, createHtmlqCommands, htmlqCommand, htmlqCommands } from "../../safe-bash-command-htmlq/index.js";
3625
- var _syncAbortSignal3;
3626
- var syncAbortSignal3 = () => _syncAbortSignal3 ??= new AbortController().signal;
3627
- var syncHtmlDecoder = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
3628
- var syncHtmlEncoder = new TextEncoder();
3629
- var syncHtmlLimits = Object.freeze({
3630
- inputBytes: Infinity,
3631
- decodedBytes: Infinity,
3632
- retainedBytes: Infinity,
3633
- nodes: Infinity,
3634
- attributes: Infinity,
3635
- depth: Infinity,
3636
- tokenBytes: Infinity,
3637
- work: Infinity,
3638
- outputBytes: Infinity
3639
- });
3640
- function evalSyncHtmlq(inBytes, opArgs, readFileSync, writeFileSync) {
3641
- if (inBytes && inBytes.byteLength > 16384) return void 0;
3642
- try {
3643
- const invocation = invocationOptions({ signal: syncAbortSignal3(), limits: syncHtmlLimits });
3644
- const args = parseHtmlqArguments(opArgs, invocation);
3645
- if (args.help || args.version) return void 0;
3646
- let srcBytes = inBytes;
3647
- if (args.filename !== "-") {
3648
- if (!readFileSync) return void 0;
3649
- const fBytes = readFileSync(args.filename);
3650
- if (!fBytes || fBytes.byteLength > 16384) return void 0;
3651
- srcBytes = fBytes;
3652
- }
3653
- if (!srcBytes) return void 0;
3654
- const budget = new HtmlBudget(invocation);
3655
- const original = syncHtmlDecoder.decode(srcBytes);
3656
- const document = parseHtmlSync(original, invocation, budget);
3657
- let base;
3658
- if (args.base) {
3659
- try {
3660
- base = new URL(args.base);
3661
- } catch {
3662
- base = void 0;
3663
- }
3664
- }
3665
- if (args.detectBase) {
3666
- const first = selectHtml(document, "base", invocation).next().value;
3667
- const href = first?.attributes.find((a) => a.name === "href")?.value ?? "";
3668
- if (href) {
3669
- try {
3670
- base = new URL(href);
3671
- } catch {
3672
- }
3673
- }
3674
- }
3675
- const selected = selectHtml(document, args.selector, invocation);
3676
- let removal = "";
3677
- if (args.removeNodes.length) {
3678
- removal = args.removeNodes.join(",");
3679
- try {
3680
- selectHtml(document, removal, invocation);
3681
- } catch (error) {
3682
- if (!(error instanceof HtmlError) || error.code !== "E_SELECTOR") throw error;
3683
- removal = "";
3684
- }
3685
- }
3686
- let out = "";
3687
- let selectedIndex = 0;
3688
- for (const node of selected) {
3689
- const isFirstNode = selectedIndex++ === 0;
3690
- if (removal) {
3691
- const first = selectHtml(node, removal, invocation).next().value;
3692
- if (first) detachHtmlNode(first, invocation);
3693
- }
3694
- if (base && node.namespace === "html" && ["a", "area", "link"].includes(node.name)) {
3695
- const href = node.attributes.find((a) => a.namespace === "none" && a.name === "href")?.value;
3696
- if (href !== void 0) {
3697
- let value;
3698
- if (href.startsWith("////")) {
3699
- let i = 0;
3700
- while (href[i] === "/") i++;
3701
- value = href.slice(i);
3702
- } else {
3703
- try {
3704
- value = new URL(href, base).href;
3705
- } catch {
3706
- value = base.href;
3707
- }
3708
- }
3709
- replaceHtmlAttribute(node, "href", value, invocation);
3710
- }
3711
- }
3712
- if (args.attributes.length) {
3713
- for (const name2 of args.attributes) {
3714
- const attribute = node.attributes.find((a) => a.namespace === "none" && a.name === name2);
3715
- if (attribute) out += attribute.value + "\n";
3716
- }
3717
- } else if (args.text) {
3718
- const internal = !args.ignoreWhitespace && !isFirstNode ? getInternalHtmlNode(node) : void 0;
3719
- if (internal && internal.children.length === 1 && internal.children[0].kind === "text" && internal.children[0].children.length === 0) {
3720
- out += internal.children[0].data + "\n";
3721
- } else {
3722
- for (const descendant of inclusiveHtmlDescendants(node, invocation)) {
3723
- if (descendant.kind !== "text") continue;
3724
- if (args.ignoreWhitespace && rustWhitespaceOnly(descendant.data)) continue;
3725
- out += descendant.data;
3726
- if (args.ignoreWhitespace) out += "\n";
3727
- }
3728
- out += "\n";
3729
- }
3730
- } else {
3731
- out += serializeHtml(node, invocation, args.pretty ? "pretty" : "normalized") + "\n";
3732
- }
3733
- }
3734
- if (args.output !== "-") {
3735
- if (!writeFileSync || !writeFileSync(args.output, syncHtmlEncoder.encode(out))) return void 0;
3736
- return "";
3737
- }
3738
- return out;
3739
- } catch {
3740
- return void 0;
3741
- }
3742
- }
3743
-
3744
- // packages/safe-bash/src/commands/unrtf/index.ts
3745
- init_platform();
3746
- import {
3747
- renderRtfSync,
3748
- createUnrtfCommand as createRawUnrtfCommand,
3749
- createUnrtfCommands as createRawUnrtfCommands
3750
- } from "../../safe-bash-command-unrtf/index.js";
3751
- import { UnrtfError, charsetCodePages, codecLabels, extractRtf, renderRtf, renderRtfSync as renderRtfSync2, tokenizeRtf, unrtf, unrtfBaseline, unrtfCommand } from "../../safe-bash-command-unrtf/index.js";
3752
- function createUnrtfCommand(options = {}) {
3753
- return registerDefaultExecutor(createRawUnrtfCommand(options), options);
3754
- }
3755
- function createUnrtfCommands(options = {}) {
3756
- return registerDefaultExecutors(createRawUnrtfCommands(options), options);
3757
- }
3758
- function unrtfCommands(options = {}) {
3759
- const commands = createUnrtfCommands(options);
3760
- const replace = options.replace ?? false;
3761
- return {
3762
- name: "unrtf",
3763
- setup(host) {
3764
- if (!replace) {
3765
- for (const command of commands) {
3766
- if (host.commands.has(command.name)) throw new Error(`Command already registered: ${command.name}`);
3767
- }
3768
- }
3769
- for (const command of commands) host.commands.register(command, { replace });
3770
- }
3771
- };
3772
- }
3773
- var _syncUnrtfSignal;
3774
- var syncUnrtfSignal = () => _syncUnrtfSignal ??= new AbortController().signal;
3775
- var syncUnrtfDecoder = new TextDecoder("utf-8", { fatal: false });
3776
- var unrtfCache = /* @__PURE__ */ new Map();
3777
- function evalSyncUnrtf(inBytes, opArgs, readFileSync) {
3778
- let format = "html";
3779
- let profile;
3780
- let quiet;
3781
- let noremap;
3782
- let file;
3783
- let literal = false;
3784
- for (let i = 0; i < opArgs.length; i++) {
3785
- const arg = opArgs[i];
3786
- if (literal) {
3787
- if (file !== void 0) return void 0;
3788
- file = arg;
3789
- } else if (arg === "--") literal = true;
3790
- else if (arg === "--text") format = "text";
3791
- else if (arg === "--html") format = "html";
3792
- else if (arg === "--latex") format = "latex";
3793
- else if (arg.startsWith("--profile=")) profile = arg.slice("--profile=".length);
3794
- else if (arg === "--quiet") quiet = true;
3795
- else if (arg === "--noremap") noremap = true;
3796
- else if (arg === "--nopict" || arg === "-n") continue;
3797
- else if (arg.startsWith("-")) return void 0;
3798
- else {
3799
- if (file !== void 0) return void 0;
3800
- file = arg;
3801
- }
3802
- }
3803
- let srcBytes = inBytes;
3804
- if (file !== void 0) {
3805
- if (!readFileSync || file.includes("\0")) return void 0;
3806
- srcBytes = readFileSync(file) ?? readFileSync(file + ".rtf");
3807
- }
3808
- if (!srcBytes || srcBytes.byteLength === 0 || srcBytes.byteLength > 16384) return void 0;
3809
- const cacheKey = `${format}|\0${profile ?? ""}|\0${quiet ? 1 : 0}|\0${noremap ? 1 : 0}|\0${syncUnrtfDecoder.decode(srcBytes)}`;
3810
- const cached = unrtfCache.get(cacheKey);
3811
- if (cached !== void 0) return cached;
3812
- try {
3813
- let out = renderRtfSync(srcBytes, {
3814
- format,
3815
- signal: syncUnrtfSignal(),
3816
- ...quiet === void 0 ? {} : { quiet },
3817
- ...noremap === void 0 ? {} : { noremap },
3818
- ...profile === void 0 ? {} : { profile }
3819
- });
3820
- if (out.endsWith("\n")) out = out.slice(0, -1);
3821
- if (unrtfCache.size >= 8) unrtfCache.clear();
3822
- unrtfCache.set(cacheKey, out);
3823
- return out;
3824
- } catch {
3825
- return void 0;
3826
- }
3827
- }
3828
-
3829
- // packages/safe-bash/src/commands/diff3/index.ts
3830
- init_platform();
3831
- import {
3832
- compareDiff3,
3833
- diff3DefaultLimits,
3834
- parseDiff3Arguments,
3835
- createDiff3Command as createRawDiff3Command,
3836
- createDiff3Commands as createRawDiff3Commands
3837
- } from "../../safe-bash-command-diff3/index.js";
3838
- import { Diff3Error, analyzeDiff3, compareDiff3 as compareDiff32, createDiff3Engine, diff3, diff3Command, diff3DefaultLimits as diff3DefaultLimits2, parseDiff3Arguments as parseDiff3Arguments2, validateDiff3Invocation } from "../../safe-bash-command-diff3/index.js";
3839
- function createDiff3Command(options = {}) {
3840
- return registerDefaultExecutor(createRawDiff3Command(options), options);
3841
- }
3842
- function createDiff3Commands(options = {}) {
3843
- return registerDefaultExecutors(createRawDiff3Commands(options), options);
3844
- }
3845
- function diff3Commands(options = {}) {
3846
- const commands = createDiff3Commands(options);
3847
- const replace = options.replace ?? false;
3848
- return {
3849
- name: "diff3-commands",
3850
- setup(host) {
3851
- if (!replace) {
3852
- for (const command of commands) {
3853
- if (host.commands.has(command.name)) throw new Error(`Command already registered: ${command.name}`);
3854
- }
3855
- }
3856
- for (const command of commands) host.commands.register(command, { replace });
3857
- }
3858
- };
3859
- }
3860
- var _syncDiff3Signal;
3861
- var syncDiff3Signal = () => _syncDiff3Signal ??= new AbortController().signal;
3862
- var syncDiff3Decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
3863
- function evalSyncDiff3(inBytes, opArgs, readFileSync) {
3864
- try {
3865
- const options = parseDiff3Arguments([...opArgs], diff3DefaultLimits);
3866
- if (options.information !== void 0 || options.files.length !== 3) return void 0;
3867
- const inputs = [];
3868
- let stdinUsed = false;
3869
- for (const file of options.files) {
3870
- let srcBytes;
3871
- if (file === "-") {
3872
- if (stdinUsed || !inBytes) return void 0;
3873
- stdinUsed = true;
3874
- srcBytes = inBytes;
3875
- } else {
3876
- if (!readFileSync) return void 0;
3877
- srcBytes = readFileSync(file);
3878
- }
3879
- if (!srcBytes || srcBytes.byteLength > 16384) return void 0;
3880
- inputs.push(srcBytes);
3881
- }
3882
- const rendered = compareDiff3(inputs, options, diff3DefaultLimits, syncDiff3Signal());
3883
- if (rendered.exitCode !== 0 || rendered.stderr.byteLength !== 0) return void 0;
3884
- let out = syncDiff3Decoder.decode(rendered.stdout);
3885
- if (out.endsWith("\n")) out = out.slice(0, -1);
3886
- return out;
3887
- } catch {
3888
- return void 0;
3889
- }
3890
- }
3891
-
3892
3587
  // packages/safe-bash/src/commands/search/index.ts
3893
3588
  init_platform();
3894
3589
 
@@ -3900,7 +3595,7 @@ import { createRgCommand } from "../../safe-bash-command-rg/index.js";
3900
3595
  import { evalSyncRg } from "../../safe-bash-command-rg/index.js";
3901
3596
  function createSearchCommands(options = {}) {
3902
3597
  const definitions = [createRgCommand(options)];
3903
- for (let i = 0; i < definitions.length; i++) builtInDirectContextExecutors.add(definitions[i].execute);
3598
+ for (let i = 0; i < definitions.length; i++) builtInDirectContextExecutors2.add(definitions[i].execute);
3904
3599
  return definitions;
3905
3600
  }
3906
3601
  function searchCommands(options = {}) {
@@ -3918,6 +3613,7 @@ function searchCommands(options = {}) {
3918
3613
 
3919
3614
  // packages/safe-bash/src/shell/shell.ts
3920
3615
  init_platform();
3616
+ import { utf8ByteLength } from "../../safe-bash-byte-engine/index.js";
3921
3617
 
3922
3618
  // packages/safe-bash/src/commands/text-programs/awk-reader.ts
3923
3619
  init_platform();
@@ -6473,7 +6169,7 @@ var ValueStore = class {
6473
6169
  return this._values?.get(name2)?.value ?? this._strings?.get(name2) ?? text3;
6474
6170
  }
6475
6171
  publishString(name2, value, rawVariables) {
6476
- if (this.arena.hasInfiniteBytes) {
6172
+ if (this.arena.hasInfiniteBytes && this.arena.maximumSlots === Infinity) {
6477
6173
  this.arena.assertOpen();
6478
6174
  rawVariables[name2] = value;
6479
6175
  this.invalidate(name2);
@@ -7548,7 +7244,7 @@ function observeDescriptor(source, scope, budget, signal) {
7548
7244
  }
7549
7245
 
7550
7246
  // packages/safe-bash/src/shell/runtime.ts
7551
- import { MemoryFileSystem as MemoryFileSystem2, isCleanAbsolutePath, retargetScopedFileSystem, scopeFileSystem, tryGetMemoryDirectoryEntryNamesSync, tryMkdirMemorySync, tryOpenMemoryRedirectHandleSync, tryResolveMemoryDevicePath as tryResolveMemoryDevicePath2, tryRmRfMemorySync, tryWriteMemoryFileInDirSync, tryWriteMemoryFileSync } from "@poe-platform/safe-fs/core";
7247
+ import { MemoryFileSystem, isCleanAbsolutePath, retargetScopedFileSystem, scopeFileSystem, tryGetMemoryDirectoryEntryNamesSync, tryMkdirMemorySync, tryOpenMemoryRedirectHandleSync, tryResolveMemoryDevicePath as tryResolveMemoryDevicePath2, tryRmRfMemorySync, tryWriteMemoryFileInDirSync, tryWriteMemoryFileSync } from "@poe-platform/safe-fs/core";
7552
7248
 
7553
7249
  // packages/safe-bash/src/shell/brace-expansion.ts
7554
7250
  init_platform();
@@ -7958,9 +7654,13 @@ async function* expandBraces(word, budget, signal) {
7958
7654
  }
7959
7655
  }
7960
7656
 
7657
+ // packages/safe-bash/src/shell/runtime.ts
7658
+ import { createAliasCommand } from "../../safe-bash-command-alias/index.js";
7659
+ import { createUnaliasCommand } from "../../safe-bash-command-unalias/index.js";
7660
+
7961
7661
  // packages/safe-bash/src/shell/tilde-expansion.ts
7962
7662
  init_platform();
7963
- function expandTildes(parts, variables, budget, assignmentStart) {
7663
+ function expandTildes(parts, variables, budget, assignmentStart, colonEndsInitialTilde = false) {
7964
7664
  const result = [];
7965
7665
  for (let index = 0; index < parts.length; index++) {
7966
7666
  const part = parts[index];
@@ -7975,7 +7675,7 @@ function expandTildes(parts, variables, budget, assignmentStart) {
7975
7675
  const initial = index === 0 && offset === (assignmentStart ?? 0);
7976
7676
  if (!initial && !(assignmentStart !== void 0 && offset > 0 && part.value[offset - 1] === ":")) continue;
7977
7677
  let end = offset + 1;
7978
- while (end < part.value.length && part.value[end] !== "/" && !(assignmentStart !== void 0 && part.value[end] === ":")) {
7678
+ while (end < part.value.length && part.value[end] !== "/" && !((assignmentStart !== void 0 || colonEndsInitialTilde && initial) && part.value[end] === ":")) {
7979
7679
  if (end % 1024 === 0) budget.cpuCheckpoint();
7980
7680
  end++;
7981
7681
  }
@@ -9428,6 +9128,12 @@ import { createBaseCommand, evalSyncBase32 } from "../../safe-bash-base-encoding
9428
9128
 
9429
9129
  // packages/safe-bash/src/shell/runtime.ts
9430
9130
  import { evalSyncShuf } from "../../safe-bash-command-shuf/index.js";
9131
+
9132
+ // packages/safe-bash/src/commands/gnu-information.ts
9133
+ init_platform();
9134
+ import { gnuInformation, gnuInformationSync } from "../../safe-bash-io-engine/gnu-information.js";
9135
+
9136
+ // packages/safe-bash/src/shell/runtime.ts
9431
9137
  import { evalSyncDd } from "../../safe-bash-command-dd/index.js";
9432
9138
  import { evalSyncXan } from "../../safe-bash-command-xan/index.js";
9433
9139
 
@@ -11963,7 +11669,7 @@ function createSession(budget, scope) {
11963
11669
  budget,
11964
11670
  budget.limits.maxExpansionBytes,
11965
11671
  budget.limits.maxExpansionFields,
11966
- ArrayLedger.createInternal(budget.limits.maxCommands ?? 1e4),
11672
+ ArrayLedger.createInternal(budget.limits.maxCommands ?? Infinity),
11967
11673
  scope
11968
11674
  );
11969
11675
  scope.setArraySession(session);
@@ -13380,7 +13086,7 @@ async function umaskBuiltin(context, state) {
13380
13086
  }
13381
13087
 
13382
13088
  // packages/safe-bash/src/shell/runtime.ts
13383
- import { abortManagedController as abortManagedController2, addAbortSignalWaiter as addAbortSignalWaiter2, combineManagedSignals as combineManagedSignals2, createManagedControlController as createManagedControlController2, getRuntimeBackingFileSystem as getRuntimeBackingFileSystem2, interruptible as interruptible2, isSyncResolved as isSyncResolved5, registerRuntimeBackingFileSystem, removeAbortSignalWaiter as removeAbortSignalWaiter2, toNativeAbortSignal } from "../../safe-bash-contracts/runtime-control.js";
13089
+ import { abortManagedController as abortManagedController2, combineManagedSignals as combineManagedSignals2, releaseCombinedSignal, createManagedControlController as createManagedControlController2, getRuntimeBackingFileSystem as getRuntimeBackingFileSystem2, interruptible as interruptible2, isSyncResolved as isSyncResolved5, registerRuntimeBackingFileSystem, toNativeAbortSignal } from "../../safe-bash-contracts/runtime-control.js";
13384
13090
  var sharedCaptureDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
13385
13091
  var cachedCaptureAsciiBytes = new Uint8Array(4096);
13386
13092
  var cachedCaptureAsciiLen = 0;
@@ -13440,6 +13146,7 @@ var defaultLimits = {
13440
13146
  maxPathnameComponents: Infinity,
13441
13147
  maxRedirects: Infinity,
13442
13148
  maxPipelineStages: Infinity,
13149
+ maxPipelineBytes: Infinity,
13443
13150
  maxLoopIterations: Infinity,
13444
13151
  maxSubstitutionDepth: Infinity,
13445
13152
  maxFunctionDepth: Infinity,
@@ -13497,13 +13204,16 @@ var shellBuiltinNames = /* @__PURE__ */ new Set([
13497
13204
  ".",
13498
13205
  "source",
13499
13206
  "eval",
13207
+ "exec",
13500
13208
  "getopts",
13501
13209
  "let",
13502
13210
  "pushd",
13503
13211
  "dirs",
13504
13212
  "popd",
13505
13213
  "shopt",
13506
- "hash"
13214
+ "hash",
13215
+ "alias",
13216
+ "unalias"
13507
13217
  ]);
13508
13218
  var implementedBuiltins = new Set([...shellBuiltinNames].filter((name2) => !["echo", "printf", "test", "["].includes(name2)));
13509
13219
  var extensionExitFailures = /* @__PURE__ */ new WeakMap();
@@ -13566,9 +13276,10 @@ function publishCommandSpelling(state, description) {
13566
13276
  (monitor?.raw ?? state).variables.BASH_COMMAND = description;
13567
13277
  }
13568
13278
  function resolveLimits(...limits) {
13569
- const result = Object.assign({}, defaultLimits, ...limits);
13279
+ const definedLimits = limits.map((layer) => Object.fromEntries(Object.entries(layer ?? {}).filter(([, value]) => value !== void 0)));
13280
+ const result = Object.assign({}, defaultLimits, ...definedLimits);
13570
13281
  const commandLimits = resolveCommandLimits(...limits.map((value) => value?.commandLimits));
13571
- for (const [key, value] of Object.entries(Object.assign({}, ...limits))) {
13282
+ for (const [key, value] of Object.entries(Object.assign({}, ...definedLimits))) {
13572
13283
  if (key === "commandLimits") continue;
13573
13284
  if ((value !== Infinity || key === "pipeHighWaterMark") && (!Number.isSafeInteger(value) || value < (key === "pipeHighWaterMark" ? 1 : 0))) {
13574
13285
  throw new RangeError(`${key} must be a ${key === "pipeHighWaterMark" ? "positive" : "nonnegative"} safe integer`);
@@ -13760,6 +13471,7 @@ function tickSharedWallClockBudgets() {
13760
13471
  }
13761
13472
  }
13762
13473
  var Budget2 = class {
13474
+ pipelineBytes = 0;
13763
13475
  get fileSystemOperations() {
13764
13476
  return this._fileSystemOperations;
13765
13477
  }
@@ -13794,7 +13506,7 @@ var Budget2 = class {
13794
13506
  if (limits.maxRedirects < 1) this.canRedirect1 = false;
13795
13507
  if (limits.maxSourceBytes < 1073741823) this.maxSourceBytesSmi = limits.maxSourceBytes | 0;
13796
13508
  if (limits.maxPipelineStages < 1073741823) this.maxPipelineStagesSmi = limits.maxPipelineStages | 0;
13797
- if (limits.pipeHighWaterMark < 65536) this.canSyncPurePipe = false;
13509
+ if (limits.pipeHighWaterMark < 65536 || limits.maxPipelineBytes !== Infinity) this.canSyncPurePipe = false;
13798
13510
  this.signal = signal ? combineManagedSignals2(signal, this.controller.signal) : this.controller.signal;
13799
13511
  if (signal) inheritYieldCheckpoint(signal, this.signal);
13800
13512
  this.parsing = new ParseBudget(limits.maxParseUnits === Infinity ? void 0 : limits.maxParseUnits, this.signal, this, limits.maxSyntaxDepth);
@@ -13887,6 +13599,7 @@ var Budget2 = class {
13887
13599
  return this._wallClockDeadline;
13888
13600
  }
13889
13601
  close() {
13602
+ if (this._hasExternalSignal) releaseCombinedSignal(this.signal);
13890
13603
  const timer = this._wallClockTimer;
13891
13604
  if (timer === void 0) return;
13892
13605
  if (timer === true) {
@@ -13933,6 +13646,14 @@ var Budget2 = class {
13933
13646
  set fsOperations(value) {
13934
13647
  this._fileSystemOperations = value;
13935
13648
  }
13649
+ pipelineInput = (bytes) => {
13650
+ if (this.limits.maxPipelineBytes === Infinity) return;
13651
+ this.assertPipelineInput(bytes);
13652
+ this.pipelineBytes += bytes;
13653
+ };
13654
+ assertPipelineInput(bytes) {
13655
+ if (bytes > this.limits.maxPipelineBytes - this.pipelineBytes) this.fail("maxPipelineBytes");
13656
+ }
13936
13657
  reservePipelineStages(count) {
13937
13658
  this.signal.throwIfAborted();
13938
13659
  if (count > this.limits.maxPipelineStages - this._pipelineStages) this.fail("maxPipelineStages");
@@ -14254,7 +13975,7 @@ var Capture = class {
14254
13975
  }
14255
13976
  if (same) return cachedCaptureAsciiStr;
14256
13977
  }
14257
- const decoded = typeof globalThis.Buffer === "function" ? globalThis.Buffer.prototype.utf8Slice.call(buf, 0, len) : sharedCaptureDecoder.decode(buf.subarray(0, len));
13978
+ const decoded = sharedCaptureDecoder.decode(buf.subarray(0, len));
14258
13979
  if (len <= 4096) {
14259
13980
  for (let i = 0; i < len; i++) cachedCaptureAsciiBytes[i] = buf[i];
14260
13981
  cachedCaptureAsciiLen = len;
@@ -14292,6 +14013,16 @@ var invokedValues = /* @__PURE__ */ new WeakMap();
14292
14013
  var functionDiagnostics = /* @__PURE__ */ new WeakMap();
14293
14014
  var childIdentities = /* @__PURE__ */ new WeakMap();
14294
14015
  var declarationArrays = /* @__PURE__ */ Symbol("declarationArrays");
14016
+ var execDescriptorFrames = /* @__PURE__ */ new WeakMap();
14017
+ async function closeExecDescriptors(state) {
14018
+ const raw = stateMonitor(state)?.raw ?? state;
14019
+ const frame = execDescriptorFrames.get(raw);
14020
+ if (!frame) return;
14021
+ execDescriptorFrames.delete(raw);
14022
+ const results = await Promise.allSettled([...frame.releases.values()].map((release) => release()));
14023
+ frame.releases.clear();
14024
+ throwCleanupFailures(results.filter((result) => result.status === "rejected").map((result) => result.reason));
14025
+ }
14295
14026
  var DescriptorLifetime = class {
14296
14027
  constructor(finalize) {
14297
14028
  this.finalize = finalize;
@@ -14516,6 +14247,8 @@ var ExpansionFailure = class extends Error {
14516
14247
  }
14517
14248
  line;
14518
14249
  };
14250
+ var FailglobFailure = class extends ExpansionFailure {
14251
+ };
14519
14252
  var CommandFailure = class extends Error {
14520
14253
  constructor(message2, status) {
14521
14254
  super(message2);
@@ -14729,6 +14462,7 @@ var BudgetedPipeStageSink = class {
14729
14462
  return Boolean(w.open && pipe && !pipe.failed && !pipe.signal?.aborted && pipe.readerReferences && (!pipe.writes || pipe.writes.size === 0) && (pipe.availableBytes ?? 0) < (pipe.highWaterMark ?? 0));
14730
14463
  }
14731
14464
  writeSync(chunk) {
14465
+ this.budget.assertPipelineInput(chunk.byteLength);
14732
14466
  this.budget.bytes += chunk.byteLength;
14733
14467
  this.writable.write(chunk);
14734
14468
  if (chunk.byteLength && this.written) this.written.add(this.index);
@@ -14965,10 +14699,19 @@ function bindCommandIO(context, io, limits = {}) {
14965
14699
  });
14966
14700
  }
14967
14701
  var FastShellCommandContext = class _FastShellCommandContext {
14968
- constructor(runtime, state, io, scope, name2, args, argumentValues, env, signalIsScoped) {
14969
- const directContext = FAST_DIRECT_CONTEXT_COMMANDS.has(name2) || name2 === "find" && !args.includes("-exec") && !args.includes("-ok");
14702
+ get signal() {
14703
+ const self = this._self ?? this;
14704
+ return self._nativeSignal ??= toNativeAbortSignal(self._rawSignal);
14705
+ }
14706
+ set signal(signal) {
14707
+ const self = this._self ?? this;
14708
+ self._rawSignal = signal;
14709
+ self._nativeSignal = void 0;
14710
+ }
14711
+ constructor(runtime, state, io, scope, name2, args, argumentValues, env, signalIsScoped, definition) {
14712
+ const directContext = builtInDirectContextExecutors2.has(definition.execute) && !customRegisteredCommands.has(definition.execute) && (FAST_DIRECT_CONTEXT_COMMANDS.has(name2) || name2 === "find" && !args.includes("-exec") && !args.includes("-ok"));
14970
14713
  if (!directContext) {
14971
- const { [invocationScope]: ignoredScope, [valueScope]: ignoredAllocation, [declarationArrays]: ignoredArrays, argumentValues: ignoredArguments, ...publicIO } = io;
14714
+ const { [invocationScope]: ignoredScope, [valueScope]: ignoredAllocation, [declarationArrays]: ignoredArrays, argumentValues: ignoredArguments, signal: ignoredSignal, ...publicIO } = io;
14972
14715
  Object.defineProperties(this, Object.getOwnPropertyDescriptors(publicIO));
14973
14716
  }
14974
14717
  this._self = this;
@@ -14987,14 +14730,20 @@ var FastShellCommandContext = class _FastShellCommandContext {
14987
14730
  this._argumentValues = argumentValues;
14988
14731
  this._env = env;
14989
14732
  this.cwd = state.cwd;
14990
- this.signal = runtime._isMemoryBackingFs && runtime.commandSignal === runtime.signal ? runtime.commandSignal : toNativeAbortSignal(runtime.commandSignal);
14733
+ this.signal = runtime.commandSignal;
14991
14734
  this.onInternalError = runtime.budget.onInternalError;
14992
14735
  this.argv0 = io.argv0;
14993
14736
  this.capabilities = io.capabilities;
14994
14737
  this.processSignals = io.processSignals;
14995
14738
  this.diagnosticLine = io.diagnosticLine;
14996
14739
  this.scriptName = io.scriptName;
14997
- if (directContext) return;
14740
+ if (directContext) {
14741
+ Object.defineProperty(this, "signal", {
14742
+ ...Object.getOwnPropertyDescriptor(_FastShellCommandContext.prototype, "signal"),
14743
+ enumerable: true
14744
+ });
14745
+ return;
14746
+ }
14998
14747
  workerRuntimeContexts.set(this, {
14999
14748
  budget: runtime.budget,
15000
14749
  umask: state.umask ?? 18,
@@ -15035,7 +14784,7 @@ var FastShellCommandContext = class _FastShellCommandContext {
15035
14784
  this.command = name2;
15036
14785
  this.args = args;
15037
14786
  this.cwd = state.cwd;
15038
- this.signal = runtime._isMemoryBackingFs ? signal : toNativeAbortSignal(signal);
14787
+ this.signal = signal;
15039
14788
  this.onInternalError = runtime.budget.onInternalError;
15040
14789
  this.argv0 = io.argv0;
15041
14790
  this.capabilities = io.capabilities;
@@ -15179,7 +14928,6 @@ var FastShellCommandContext = class _FastShellCommandContext {
15179
14928
  }
15180
14929
  get fs() {
15181
14930
  const self = this._self ?? this;
15182
- self.signal = toNativeAbortSignal(self.signal);
15183
14931
  if (!self._contextFs) {
15184
14932
  self._contextFs = self._runtime.getContextFsForFast(self._state.umask ?? 18, self._getScopedSignal());
15185
14933
  }
@@ -15265,7 +15013,7 @@ function isFastDirectCommand(name2, words) {
15265
15013
  }
15266
15014
  return true;
15267
15015
  }
15268
- var fastShellCommandAccessors = ["env", "fs", "shellPredicates", "inputBudget", "executionScope", "registerCleanup", "invoke", "argumentValues"].map((key) => [key, Object.getOwnPropertyDescriptor(FastShellCommandContext.prototype, key)]);
15016
+ var fastShellCommandAccessors = ["signal", "env", "fs", "shellPredicates", "inputBudget", "executionScope", "registerCleanup", "invoke", "argumentValues", "stdinInput", "stdoutFile"].map((key) => [key, Object.getOwnPropertyDescriptor(FastShellCommandContext.prototype, key)]);
15269
15017
  function cloneRawState(raw, hasLocals) {
15270
15018
  const variables = Object.assign(/* @__PURE__ */ Object.create(null), raw.variables);
15271
15019
  const exported = raw.exported.size ? new Set(raw.exported) : /* @__PURE__ */ new Set();
@@ -15289,6 +15037,11 @@ function cloneRawState(raw, hasLocals) {
15289
15037
  if (raw.variableAttributes) cloned.variableAttributes = new Map(raw.variableAttributes);
15290
15038
  if (raw.getopts) cloned.getopts = cloneGetoptsBinding(raw);
15291
15039
  if (raw.functionNames) cloned.functionNames = [...raw.functionNames];
15040
+ if (raw.aliases) cloned.aliases = new Map(raw.aliases);
15041
+ if (raw.loopDepth > 0 || raw._subshellInLoop) {
15042
+ cloned._subshellInLoop = true;
15043
+ }
15044
+ cloned.loopDepth = 0;
15292
15045
  return cloned;
15293
15046
  }
15294
15047
  function tryCloneStateSync(state, scope, inheritLocals = true) {
@@ -16163,7 +15916,6 @@ function hasGlobOrEscape(text3, extglob = false) {
16163
15916
  }
16164
15917
  return false;
16165
15918
  }
16166
- var nextProcessSubstitutionId = 0;
16167
15919
  var fastSubScratchArgs = [];
16168
15920
  var defaultValueScopeReserve = ValueScope.prototype.reserve;
16169
15921
  var defaultStringCodePointAt = String.prototype.codePointAt;
@@ -16377,14 +16129,12 @@ var PooledSyncPipeWriter = class {
16377
16129
  signal;
16378
16130
  target = EMPTY_BYTES;
16379
16131
  used = 0;
16380
- overflowed = false;
16381
16132
  lineCountOnly = -1;
16382
16133
  reset(budget, signal, target, lineCountOnly = -1) {
16383
16134
  this.budget = budget;
16384
16135
  this.signal = signal;
16385
16136
  this.target = target;
16386
16137
  this.used = 0;
16387
- this.overflowed = false;
16388
16138
  this.lineCountOnly = lineCountOnly;
16389
16139
  }
16390
16140
  writeLineCountSync(count, totalBytes) {
@@ -16392,27 +16142,31 @@ var PooledSyncPipeWriter = class {
16392
16142
  if (totalBytes > 0) {
16393
16143
  const budget = this.budget;
16394
16144
  if (budget.bytes + totalBytes > budget.maxOutputBytesSmi && totalBytes > budget.limits.maxOutputBytes - budget.bytes) budget.fail("maxOutputBytes");
16395
- if (this.used + totalBytes > this.target.byteLength) {
16396
- this.overflowed = true;
16397
- return false;
16398
- }
16399
16145
  this.used += totalBytes;
16400
16146
  budget.bytes += totalBytes;
16401
16147
  }
16402
16148
  this.lineCountOnly = count;
16403
16149
  return true;
16404
16150
  }
16151
+ reserve(length) {
16152
+ const required = this.used + length;
16153
+ if (required <= this.target.byteLength) return;
16154
+ const capacity = Math.min(this.budget.limits.maxOutputBytes, Math.max(required, this.target.byteLength * 2));
16155
+ const target = new Uint8Array(capacity);
16156
+ target.set(this.target.subarray(0, this.used));
16157
+ this.target = target;
16158
+ }
16405
16159
  writeSync(chunk) {
16406
16160
  this.signal.throwIfAborted();
16407
16161
  const len = chunk.byteLength;
16408
16162
  if (len === 0) return true;
16409
16163
  const budget = this.budget;
16410
16164
  if (budget.bytes + len > budget.maxOutputBytesSmi && len > budget.limits.maxOutputBytes - budget.bytes) budget.fail("maxOutputBytes");
16411
- if (this.used + len > this.target.byteLength) {
16412
- this.overflowed = true;
16413
- return false;
16414
- }
16165
+ this.reserve(len);
16415
16166
  this.target.set(chunk, this.used);
16167
+ if (this.lineCountOnly >= 0) {
16168
+ for (const byte of chunk) if (byte === 10) this.lineCountOnly++;
16169
+ }
16416
16170
  this.used += len;
16417
16171
  budget.bytes += len;
16418
16172
  return true;
@@ -16422,21 +16176,22 @@ var PooledSyncPipeWriter = class {
16422
16176
  if (len === 0) return true;
16423
16177
  const budget = this.budget;
16424
16178
  if (budget.bytes + len > budget.maxOutputBytesSmi && len > budget.limits.maxOutputBytes - budget.bytes) budget.fail("maxOutputBytes");
16425
- if (this.used + len > this.target.byteLength) {
16426
- this.overflowed = true;
16427
- return false;
16428
- }
16179
+ this.reserve(len);
16429
16180
  const dst = this.target;
16430
16181
  const base = this.used;
16431
- for (let i = 0; i < len; i++) dst[base + i] = src[i];
16182
+ for (let i = 0; i < len; i++) {
16183
+ const byte = src[i];
16184
+ dst[base + i] = byte;
16185
+ if (this.lineCountOnly >= 0 && byte === 10) this.lineCountOnly++;
16186
+ }
16432
16187
  this.used = base + len;
16433
16188
  budget.bytes += len;
16434
16189
  return true;
16435
16190
  }
16436
16191
  write(chunk) {
16437
16192
  try {
16438
- if (this.writeSync(chunk)) return resolvedVoid4;
16439
- return Promise.reject(new Error("Sync pipe stage buffer overflow"));
16193
+ this.writeSync(chunk);
16194
+ return resolvedVoid4;
16440
16195
  } catch (err) {
16441
16196
  return Promise.reject(err);
16442
16197
  }
@@ -16747,7 +16502,7 @@ function fastStringHexIdentity(str) {
16747
16502
  return bytesToHex(fastSharedTextEncoder.encode(str));
16748
16503
  }
16749
16504
  var syncConditionalFileUnaryOps = /* @__PURE__ */ new Set(["-e", "-a", "-f", "-d", "-s", "-L", "-h", "-r", "-w", "-x"]);
16750
- var memoryFilePredicateImplementation = Object.getOwnPropertyDescriptors(MemoryFileSystem2.prototype);
16505
+ var memoryFilePredicateImplementation = Object.getOwnPropertyDescriptors(MemoryFileSystem.prototype);
16751
16506
  var evalSingleUnitCache = /* @__PURE__ */ new Map();
16752
16507
  function isDefaultShellSyntax(syntax) {
16753
16508
  if (!syntax) return true;
@@ -16804,14 +16559,13 @@ var Runtime = class _Runtime {
16804
16559
  this._canFastMemoryRedirect = void 0;
16805
16560
  this.sourceFs = runtimeFileSystems.get(fs) ?? fs;
16806
16561
  this.backingFs = getRuntimeBackingFileSystem2(this.sourceFs) ?? this.sourceFs;
16807
- this._isMemoryBackingFs = Object.getPrototypeOf(this.backingFs) === MemoryFileSystem2.prototype && Object.getOwnPropertyNames(this.backingFs).every((name2) => {
16808
- const method = Object.getOwnPropertyDescriptor(MemoryFileSystem2.prototype, name2)?.value;
16562
+ this._isMemoryBackingFs = Object.getPrototypeOf(this.backingFs) === MemoryFileSystem.prototype && Object.getOwnPropertyNames(this.backingFs).every((name2) => {
16563
+ const method = Object.getOwnPropertyDescriptor(MemoryFileSystem.prototype, name2)?.value;
16809
16564
  return typeof method !== "function" || Object.getOwnPropertyDescriptor(this.backingFs, name2)?.value === method;
16810
- }) && Object.getOwnPropertyNames(MemoryFileSystem2.prototype).every((name2) => {
16811
- const method = Object.getOwnPropertyDescriptor(MemoryFileSystem2.prototype, name2)?.value;
16565
+ }) && Object.getOwnPropertyNames(MemoryFileSystem.prototype).every((name2) => {
16566
+ const method = Object.getOwnPropertyDescriptor(MemoryFileSystem.prototype, name2)?.value;
16812
16567
  return typeof method !== "function" || Reflect.get(this.backingFs, name2) === method;
16813
16568
  });
16814
- if (this._isMemoryBackingFs) this.backingFs._activeRuntimeBudget = budget;
16815
16569
  registerInternalYieldCheckpoint(signal, budget.yieldCheckpoint);
16816
16570
  if (commandSignal !== signal) {
16817
16571
  inheritYieldCheckpoint(signal, commandSignal);
@@ -16823,6 +16577,22 @@ var Runtime = class _Runtime {
16823
16577
  }
16824
16578
  }
16825
16579
  reuseDefaultContextFs;
16580
+ persistentIO(state, io) {
16581
+ const frame = execDescriptorFrames.get(stateMonitor(state)?.raw ?? state);
16582
+ if (!frame || io.execFrame === frame && io.execVersion === frame.version) return io;
16583
+ const changed = new Map([...frame.descriptors].filter(([number2]) => io.execFrame !== frame || (frame.revisions.get(number2) ?? 0) > (io.execVersion ?? 0)));
16584
+ const descriptors = new Map(io.descriptors ?? [[0, { input: io.stdin }], [1, { output: io.stdout }], [2, { output: io.stderr }]]);
16585
+ for (const [number2, descriptor] of changed) descriptors.set(number2, descriptor);
16586
+ return {
16587
+ ...io,
16588
+ descriptors,
16589
+ execFrame: frame,
16590
+ execVersion: frame.version,
16591
+ ...changed.has(0) ? { stdin: descriptors.get(0)?.closed ? closedSource : descriptors.get(0)?.input ?? closedSource, stdinIsDefault: false } : {},
16592
+ ...changed.has(1) ? { stdout: descriptors.get(1)?.closed ? closedSink : descriptors.get(1)?.output ?? closedSink } : {},
16593
+ ...changed.has(2) ? { stderr: descriptors.get(2)?.closed ? closedSink : descriptors.get(2)?.output ?? closedSink } : {}
16594
+ };
16595
+ }
16826
16596
  static clearStaticPools() {
16827
16597
  clearRuntimePools();
16828
16598
  }
@@ -16848,11 +16618,12 @@ var Runtime = class _Runtime {
16848
16618
  const reusableEntry = reusableDefaultContextFsBySourceFs.get(this.sourceFs);
16849
16619
  if (reusableEntry && reusableEntry.inUseBy === this) {
16850
16620
  retargetScopedFileSystem(reusableEntry.scoped, noopFsCharge, NEVER_ABORTED_SIGNAL, noopFsCharge, 256);
16621
+ registerRuntimeBackingFileSystem(reusableEntry.scoped, this.backingFs);
16851
16622
  reusableEntry.inUseBy = void 0;
16852
16623
  }
16853
16624
  }
16854
16625
  if (this.backingFs) {
16855
- const emptyFs = _sharedEmptyMemoryFs ??= new MemoryFileSystem2();
16626
+ const emptyFs = _sharedEmptyMemoryFs ??= new MemoryFileSystem();
16856
16627
  this.backingFs = emptyFs;
16857
16628
  this.sourceFs = emptyFs;
16858
16629
  this._rawFs = emptyFs;
@@ -16866,7 +16637,7 @@ var Runtime = class _Runtime {
16866
16637
  if (!this._fs) {
16867
16638
  this._fs = scopeFileSystem(this._rawFs, this.budget.chargeFs, this.signal, this.budget.cleanupChargeFs, { maxPathComponents: this.budget.limits.maxPathnameComponents });
16868
16639
  runtimeFileSystems.set(this._fs, this.sourceFs);
16869
- registerRuntimeBackingFileSystem(this._fs, this.backingFs);
16640
+ registerRuntimeBackingFileSystem(this._fs, this.backingFs, this.budget.chargeFs);
16870
16641
  }
16871
16642
  return this._fs;
16872
16643
  }
@@ -16877,7 +16648,8 @@ var Runtime = class _Runtime {
16877
16648
  if (this.reuseDefaultContextFs && sig === this.signal && umask === 18 && !this._contextFs && this._isMemoryBackingFs) {
16878
16649
  const entry = reusableDefaultContextFsBySourceFs.get(this.sourceFs);
16879
16650
  if (entry && (entry.inUseBy === void 0 || entry.inUseBy === this)) {
16880
- if (retargetScopedFileSystem(entry.scoped, this.budget.chargeFs, sig, this.budget.cleanupChargeFs, this.budget.limits.maxPathnameComponents)) {
16651
+ if (retargetScopedFileSystem(entry.scoped, this.budget.chargeFs, toNativeAbortSignal(sig), this.budget.cleanupChargeFs, this.budget.limits.maxPathnameComponents)) {
16652
+ registerRuntimeBackingFileSystem(entry.scoped, this.backingFs, this.budget.chargeFs);
16881
16653
  entry.inUseBy = this;
16882
16654
  this._contextFsMask = umask;
16883
16655
  this._contextFsSignal = sig;
@@ -16886,9 +16658,9 @@ var Runtime = class _Runtime {
16886
16658
  }
16887
16659
  }
16888
16660
  }
16889
- const created = scopeFileSystem(creationFileSystem(this.sourceFs, umask), this.budget.chargeFs, sig, this.budget.cleanupChargeFs, { maxPathComponents: this.budget.limits.maxPathnameComponents });
16661
+ const created = scopeFileSystem(creationFileSystem(this.sourceFs, umask), this.budget.chargeFs, toNativeAbortSignal(sig), this.budget.cleanupChargeFs, { maxPathComponents: this.budget.limits.maxPathnameComponents });
16890
16662
  runtimeFileSystems.set(created, this.sourceFs);
16891
- registerRuntimeBackingFileSystem(created, this.backingFs);
16663
+ registerRuntimeBackingFileSystem(created, this.backingFs, this.budget.chargeFs);
16892
16664
  this._contextFsMask = umask;
16893
16665
  this._contextFsSignal = sig;
16894
16666
  this._contextFs = created;
@@ -17927,6 +17699,8 @@ var Runtime = class _Runtime {
17927
17699
  }
17928
17700
  variable(state, name2) {
17929
17701
  name2 = this.referenceName(state, name2);
17702
+ if (name2 === "$" || name2 === "BASHPID") return "1";
17703
+ if (name2 === "!") return "";
17930
17704
  if (name2 === "RANDOM" || name2 === "SECONDS") return readDynamicVariable(stateMonitor(state)?.raw ?? state, name2) ?? state.variables[name2];
17931
17705
  const binding = arrayStore(state)?.get(name2);
17932
17706
  if (binding) return binding.get(binding.associative ? binding.keys.get("30")?.index ?? -1 : 0);
@@ -19031,8 +18805,13 @@ var Runtime = class _Runtime {
19031
18805
  }
19032
18806
  const expandedEntries = [];
19033
18807
  let elementFields;
18808
+ let attributedElement;
19034
18809
  if (assignment.kind === "element") {
19035
18810
  elementFields = await this.valueWord(assignment.value, state, io, false, false, false, false, void 0, false, false, 0);
18811
+ if (selectedIndex !== void 0 && state.variableAttributes?.get(name2)?.includes("i")) {
18812
+ const previous = assignment.append ? store.get(name2)?.getValue(selectedIndex) ?? (selectedIndex === 0 ? state.variables[name2] : void 0) ?? "" : void 0;
18813
+ attributedElement = await this.attributeValue(state, name2, concatShellValues(elementFields, io[valueScope]), io, "assignment", previous);
18814
+ }
19036
18815
  } else for (const entry of assignment.entries) {
19037
18816
  const original = compoundEntryWords.get(entry);
19038
18817
  let expandedEntry = false;
@@ -19052,6 +18831,36 @@ var Runtime = class _Runtime {
19052
18831
  }
19053
18832
  current = store.get(name2);
19054
18833
  initialMaximum = current?.maximum ?? (state.variables[name2] === void 0 ? -1 : 0);
18834
+ if (assignment.kind === "compound" && expandedEntries.length > 0 && (state.variableAttributes?.get(name2)?.includes("i") || !isAssociative && expandedEntries.some(({ entry }) => entry.index && numericIndex(entry.index) === void 0))) {
18835
+ let cursor = assignment.append ? initialMaximum + 1 : 0;
18836
+ if (!assignment.append) await this.arrayAssignment({ ...assignment, entries: [] }, state, io, void 0, origin, associative, true);
18837
+ for (const { entry, fields } of expandedEntries) {
18838
+ const values = entry.index ? [concatShellValues(fields, io[valueScope])] : fields;
18839
+ for (const value of values) {
18840
+ const index = entry.index && !isAssociative ? await this.arrayIndex(store.get(name2), entry.index, state, io, operation2, true) : cursor;
18841
+ const part = { kind: "text", value: shellValueText(value), quoted: true };
18842
+ if (typeof value !== "string") invokedValues.set(part, value);
18843
+ await this.arrayAssignment(
18844
+ {
18845
+ kind: "element",
18846
+ name: name2,
18847
+ append: entry.append ?? false,
18848
+ index: isAssociative ? entry.index : { decimal: String(index) },
18849
+ value: { offset: entry.value.offset, parts: [part] }
18850
+ },
18851
+ state,
18852
+ io,
18853
+ void 0,
18854
+ origin,
18855
+ associative,
18856
+ true
18857
+ );
18858
+ cursor = index + 1;
18859
+ }
18860
+ }
18861
+ if (declaration) await this.arrayAssignment({ ...assignment, append: true, entries: [] }, state, io, declaration, origin, associative, true);
18862
+ return;
18863
+ }
19055
18864
  this.assertArrayWritable(state, name2, origin);
19056
18865
  const watch = await store.watch(name2, operation2, this.signal);
19057
18866
  const supersede = await stateMonitor(state).prepareTypedPublication(name2, operation2, this.signal);
@@ -19085,7 +18894,8 @@ var Runtime = class _Runtime {
19085
18894
  if (index > 2147483647) throw new ArrayFailure("index outside 0..2147483647");
19086
18895
  const previous = append ? targetBinding.getValue(index) ?? "" : void 0;
19087
18896
  if (append && !state.variableAttributes?.get(name2)?.includes("i")) value = await join([previous, value]);
19088
- if (state.variableAttributes?.get(name2)) value = await this.attributeValue(state, name2, value, io, "assignment", previous);
18897
+ if (attributedElement !== void 0) value = attributedElement;
18898
+ else if (state.variableAttributes?.get(name2)) value = await this.attributeValue(state, name2, value, io, "assignment", previous);
19089
18899
  else if (shellValueByteLength(value) > this.budget.limits.maxExpansionBytes) this.budget.fail("maxExpansionBytes");
19090
18900
  const token = await valueToken(targetBinding.owner, value, this.signal);
19091
18901
  if (canReviseInPlace) {
@@ -19228,7 +19038,11 @@ var Runtime = class _Runtime {
19228
19038
  }
19229
19039
  }
19230
19040
  async run(script, state, io) {
19231
- return this.finishShell(state, io, (await this.runUnit(script, state, io)).exitCode);
19041
+ try {
19042
+ return await this.finishShell(state, io, (await this.runUnit(script, state, io)).exitCode);
19043
+ } finally {
19044
+ await closeExecDescriptors(state);
19045
+ }
19232
19046
  }
19233
19047
  extensionContext(state, io, command = "", args = [], argumentValues = args) {
19234
19048
  const frame = state.extensions;
@@ -20225,7 +20039,7 @@ var Runtime = class _Runtime {
20225
20039
  if (state.isolated) throw error;
20226
20040
  throw error.reason;
20227
20041
  }
20228
- if (error instanceof Flow && error.kind === "exit") {
20042
+ if (error instanceof Flow && (error.kind === "exit" || error.kind === "return" || error.kind === "break" || error.kind === "continue")) {
20229
20043
  if (this.tryFinishShellSync(state)) return { exitCode: error.status, terminated: true };
20230
20044
  return this.finishShell(monitor.proxy, io, error.status).then((exitCode) => ({ exitCode, terminated: true }));
20231
20045
  }
@@ -20247,7 +20061,7 @@ var Runtime = class _Runtime {
20247
20061
  if (state.isolated) throw error;
20248
20062
  throw error.reason;
20249
20063
  }
20250
- if (error instanceof Flow && error.kind === "exit") return { exitCode: await this.finishShell(state, io, error.status), terminated: true };
20064
+ if (error instanceof Flow && (error.kind === "exit" || error.kind === "return" || error.kind === "break" || error.kind === "continue")) return { exitCode: await this.finishShell(state, io, error.status), terminated: true };
20251
20065
  throw error;
20252
20066
  }
20253
20067
  }
@@ -20260,7 +20074,7 @@ var Runtime = class _Runtime {
20260
20074
  if (state.isolated) throw error;
20261
20075
  throw error.reason;
20262
20076
  }
20263
- if (error instanceof Flow && error.kind === "exit") return { exitCode: await this.finishShell(state, io, error.status), terminated: true };
20077
+ if (error instanceof Flow && (error.kind === "exit" || error.kind === "return" || error.kind === "break" || error.kind === "continue")) return { exitCode: await this.finishShell(state, io, error.status), terminated: true };
20264
20078
  throw error;
20265
20079
  }
20266
20080
  }
@@ -20296,7 +20110,7 @@ var Runtime = class _Runtime {
20296
20110
  if (cSingle !== void 0 && !customRegisteredRegistries.has(this.commands) && !hasShellFunction(rawState, cSingle.w0Plain) && !rawState.extensions?.builtins.has(cSingle.w0Plain) && command.words.length <= this.budget.maxExpansionFieldsSmi && (this.budget.commands + 1 <= this.budget.maxCommandsSmi || this.budget.commands + 1 <= this.budget.limits.maxCommands)) {
20297
20111
  w0Plain = cSingle.w0Plain;
20298
20112
  const extD = this.commands.get(w0Plain);
20299
- if (!extD || !builtInDirectContextExecutors.has(extD.execute) || customRegisteredCommands.has(extD.execute)) return void 0;
20113
+ if (!extD || !builtInDirectContextExecutors2.has(extD.execute) || customRegisteredCommands.has(extD.execute)) return void 0;
20300
20114
  externalDef = extD;
20301
20115
  args = cSingle.args;
20302
20116
  lastArg = cSingle.lastArg;
@@ -20314,7 +20128,7 @@ var Runtime = class _Runtime {
20314
20128
  }
20315
20129
  w0Plain = w0P;
20316
20130
  const extD = this.commands.get(w0Plain);
20317
- if (!extD || !builtInDirectContextExecutors.has(extD.execute) || customRegisteredCommands.has(extD.execute) || customRegisteredRegistries.has(this.commands) || command.words.length > this.budget.maxExpansionFieldsSmi || this.budget.commands + 1 > this.budget.maxCommandsSmi && this.budget.commands + 1 > this.budget.limits.maxCommands) {
20131
+ if (!extD || !builtInDirectContextExecutors2.has(extD.execute) || customRegisteredCommands.has(extD.execute) || customRegisteredRegistries.has(this.commands) || command.words.length > this.budget.maxExpansionFieldsSmi || this.budget.commands + 1 > this.budget.maxCommandsSmi && this.budget.commands + 1 > this.budget.limits.maxCommands) {
20318
20132
  return void 0;
20319
20133
  }
20320
20134
  externalDef = extD;
@@ -20338,7 +20152,9 @@ var Runtime = class _Runtime {
20338
20152
  try {
20339
20153
  for (let i = 1; i < command.words.length; i++) {
20340
20154
  const w = command.words[i];
20341
- if (w.plain === void 0 && !(w.parts.length === 1 && w.parts[0].kind === "text" && w.parts[0].quoted === true && !w.parts[0].byteValue)) allPlain = false;
20155
+ if (w.plain !== void 0 ? w.plain.includes("{") || w.plain.startsWith("~") || hasGlobOrEscape(w.plain, true) : !(w.parts.length === 1 && w.parts[0].kind === "text" && w.parts[0].quoted === true && !w.parts[0].byteValue)) {
20156
+ allPlain = false;
20157
+ }
20342
20158
  const v = this.fastValueWord(w, rawState, io, true, false, false, true, void 0, diagnosticLine);
20343
20159
  if (typeof v !== "string") return void 0;
20344
20160
  args[i - 1] = v;
@@ -20348,6 +20164,7 @@ var Runtime = class _Runtime {
20348
20164
  return void 0;
20349
20165
  }
20350
20166
  if (allPlain) {
20167
+ Object.freeze(args);
20351
20168
  command._cachedConstArgs = args;
20352
20169
  if (command.redirects.length === 0 || command.redirects[0].target.plain !== void 0 && (command.redirects[0].operator === ">" || command.redirects[0].operator === ">>")) {
20353
20170
  command._cachedFastSingle = {
@@ -20410,7 +20227,7 @@ var Runtime = class _Runtime {
20410
20227
  context._scopedSignal = void 0;
20411
20228
  }
20412
20229
  } else {
20413
- context = new FastShellCommandContext(this, rawState, io, scope, w0Plain, args, void 0, void 0, this._isMemoryBackingFs);
20230
+ context = new FastShellCommandContext(this, rawState, io, scope, w0Plain, args, void 0, void 0, this._isMemoryBackingFs, externalDef);
20414
20231
  if (redirectSink) context.stdout = redirectSink;
20415
20232
  }
20416
20233
  if (redirectSink && io.descriptors) {
@@ -20427,7 +20244,7 @@ var Runtime = class _Runtime {
20427
20244
  const cmd = pipeline.commands[i];
20428
20245
  if (cmd.kind !== "simple" || !this.isPureExternalStageCommand(cmd, rawState) || cmd.words.length > this.budget.maxExpansionFieldsSmi) return void 0;
20429
20246
  }
20430
- return this.executeFastPurePipelineUnit(pipeline, state, rawState, monitor, io, ignored || pipeline.negate);
20247
+ return this.tryExecuteSyncPurePipelineUnit(pipeline, state, rawState, monitor, io, ignored || pipeline.negate);
20431
20248
  }
20432
20249
  return void 0;
20433
20250
  }
@@ -20473,15 +20290,26 @@ var Runtime = class _Runtime {
20473
20290
  return finalStatus === 0 ? SYNC_UNIT_ZERO : SYNC_UNIT_ONE;
20474
20291
  }
20475
20292
  } catch (error) {
20476
- return this.finishFastSingleExternalUnitAsync(void 0, error, true, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch);
20293
+ return this.finishFastSingleExternalUnitAsync(context, void 0, error, true, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch);
20477
20294
  }
20478
- return this.finishFastSingleExternalUnitAsync(raw, void 0, false, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch);
20295
+ return this.finishFastSingleExternalUnitAsync(context, raw, void 0, false, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch);
20479
20296
  }
20480
- async finishFastSingleExternalUnitAsync(raw, initialError, hasInitialError, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch) {
20297
+ async finishFastSingleExternalUnitAsync(context, raw, initialError, hasInitialError, redirectSink, diagnosticLine, negate, ignored, monitor, rawState, existing, elem0, store, state, io, scope, restEpoch) {
20481
20298
  let rawStatus = 0;
20299
+ let commandSettled = hasInitialError;
20300
+ const pending = hasInitialError ? void 0 : Promise.resolve(raw).then(
20301
+ (result) => {
20302
+ commandSettled = true;
20303
+ return result;
20304
+ },
20305
+ (error) => {
20306
+ commandSettled = true;
20307
+ throw error;
20308
+ }
20309
+ );
20482
20310
  try {
20483
20311
  if (hasInitialError) throw initialError;
20484
- const res = this.budget._hasExternalSignal ? await interruptible2(Promise.resolve(raw), this.signal) : await raw;
20312
+ const res = this.budget._hasExternalSignal ? await interruptible2(pending, this.signal) : await pending;
20485
20313
  this.signal.throwIfAborted();
20486
20314
  if (redirectSink?.failedError !== void 0) throw redirectSink.failedError;
20487
20315
  rawStatus = validateExitCode(res.exitCode);
@@ -20504,6 +20332,10 @@ var Runtime = class _Runtime {
20504
20332
  this.budget.endPathLookupSuspension();
20505
20333
  scope.leaveWork();
20506
20334
  redirectSink?.handle.close();
20335
+ if (commandSettled) context.releaseDirectStage();
20336
+ else {
20337
+ void pending.then(() => context.releaseDirectStage(), () => context.releaseDirectStage());
20338
+ }
20507
20339
  }
20508
20340
  if (!existing) {
20509
20341
  monitor.lazyPipeStatus = rawStatus === 0 ? singleStatusZero : rawStatus === 1 ? singleStatusOne : [rawStatus];
@@ -20522,9 +20354,6 @@ var Runtime = class _Runtime {
20522
20354
  }
20523
20355
  return finalStatus === 0 ? SYNC_UNIT_ZERO : finalStatus === 1 ? SYNC_UNIT_ONE : { exitCode: finalStatus, terminated: false };
20524
20356
  }
20525
- executeFastPurePipelineUnit(pipeline, state, rawState, monitor, io, ignored) {
20526
- return this.tryExecuteSyncPurePipelineUnit(pipeline, state, rawState, monitor, io, ignored);
20527
- }
20528
20357
  tryExecuteSyncPurePipelineUnit(pipeline, state, rawState, monitor, io, ignored) {
20529
20358
  const backing = this.backingFs;
20530
20359
  if (syncPurePipelineSlotInUse || !this._isMemoryBackingFs || !backing || backing.capabilitiesFor !== void 0 || this.middleware.length > 0 || customRegisteredRegistries.has(this.commands) || !io.stdinIsDefault || this.signal.aborted || hasYieldCheckpoint(this.signal) || !this.budget.canSyncPurePipe || !(io.stdout instanceof Capture && io.stdout._scratch4k !== void 0 && io.stdout.length === 0 && io.stdout.write === Capture.prototype.write) || !(io.stderr instanceof Capture && io.stderr.length === 0 && io.stderr.write === Capture.prototype.write)) {
@@ -20535,7 +20364,7 @@ var Runtime = class _Runtime {
20535
20364
  const cmd = pipeline.commands[i];
20536
20365
  const name2 = cmd.words[0].plain;
20537
20366
  const extDef = this.commands.get(name2);
20538
- if (!extDef || !builtInDirectContextExecutors.has(extDef.execute) || customRegisteredCommands.has(extDef.execute)) {
20367
+ if (!extDef || !builtInDirectContextExecutors2.has(extDef.execute) || customRegisteredCommands.has(extDef.execute)) {
20539
20368
  return void 0;
20540
20369
  }
20541
20370
  let stageArgs = cmd._cachedPlainArgs;
@@ -20615,7 +20444,7 @@ var Runtime = class _Runtime {
20615
20444
  stageStdout = sharedSyncPipeWriter;
20616
20445
  }
20617
20446
  if (!context) {
20618
- context = new FastShellCommandContext(this, rawState, io, scope, firstName, stageArgs, void 0, void 0, true);
20447
+ context = new FastShellCommandContext(this, rawState, io, scope, firstName, stageArgs, void 0, void 0, true, extDef);
20619
20448
  pooledSyncPipeContext = context;
20620
20449
  }
20621
20450
  context.resetDirectStage(this, rawState, io, scope, firstName, stageArgs, inputSource, isFirst, stageStdout, this.signal);
@@ -20639,7 +20468,7 @@ var Runtime = class _Runtime {
20639
20468
  statuses ??= new Array(n).fill(0);
20640
20469
  statuses[index] = status;
20641
20470
  }
20642
- }).finally(() => scope.leaveWork()).then(() => runStages(index + 1, nextBuf, sharedSyncPipeWriter.used));
20471
+ }).finally(() => scope.leaveWork()).then(() => runStages(index + 1, sharedSyncPipeWriter.target, sharedSyncPipeWriter.used));
20643
20472
  }
20644
20473
  scope.leaveWork();
20645
20474
  this.signal.throwIfAborted();
@@ -20647,7 +20476,7 @@ var Runtime = class _Runtime {
20647
20476
  statuses ??= new Array(n).fill(0);
20648
20477
  statuses[index] = 1;
20649
20478
  }
20650
- prevBuf = nextBuf;
20479
+ prevBuf = sharedSyncPipeWriter.target;
20651
20480
  prevLen = sharedSyncPipeWriter.used;
20652
20481
  }
20653
20482
  };
@@ -20657,6 +20486,7 @@ var Runtime = class _Runtime {
20657
20486
  sharedSyncPipeWriter.signal = void 0;
20658
20487
  sharedSyncPipeWriter.target = EMPTY_BYTES;
20659
20488
  sharedSyncPipeReader.reset(EMPTY_BYTES, 0);
20489
+ sharedSyncPipeReader.clearViews();
20660
20490
  syncPurePipelineSlotInUse = false;
20661
20491
  this.budget.leavePipelineStages(n);
20662
20492
  };
@@ -20686,234 +20516,6 @@ var Runtime = class _Runtime {
20686
20516
  release();
20687
20517
  return finish();
20688
20518
  }
20689
- executeFastPurePipelineUnitSlow(pipeline, state, rawState, monitor, io, ignored) {
20690
- const n = pipeline.commands.length;
20691
- this.budget.enterPipelineStages(n);
20692
- this.budget.commands += n;
20693
- const pipeOptions = { highWaterMark: this.budget.limits.pipeHighWaterMark, signal: this.signal };
20694
- const pipes = new Array(n - 1);
20695
- for (let i = 0; i < n - 1; i++) {
20696
- pipes[i] = createBytePipe(pipeOptions);
20697
- }
20698
- const controllers = new Array(n);
20699
- for (let i = 0; i < n; i++) {
20700
- controllers[i] = createManagedControlController2();
20701
- }
20702
- const onParentAbort = (reason) => {
20703
- for (let i = 0; i < n; i++) abortManagedController2(controllers[i], reason);
20704
- };
20705
- addAbortSignalWaiter2(this.signal, onParentAbort);
20706
- const scope = io[invocationScope];
20707
- const onScopeSeal = () => {
20708
- const closedReason = new Error("Invocation is closed");
20709
- for (let i = 0; i < n; i++) abortManagedController2(controllers[i], closedReason);
20710
- for (let i = 0; i < n - 1; i++) void pipes[i].abort(closedReason);
20711
- };
20712
- scope.addSealCallback(onScopeSeal);
20713
- const statuses = new Array(n);
20714
- let asyncTasks;
20715
- try {
20716
- for (let index = 0; index < n; index++) {
20717
- const cmd = pipeline.commands[index];
20718
- const firstName = cmd.words[0].plain;
20719
- const extDef = this.commands.get(firstName);
20720
- let stageArgs = cmd._cachedPlainArgs;
20721
- if (!stageArgs) {
20722
- stageArgs = new Array(cmd.words.length - 1);
20723
- for (let w = 1; w < cmd.words.length; w++) {
20724
- const word = cmd.words[w];
20725
- stageArgs[w - 1] = word.plain ?? word.parts.map((p) => p.value).join("");
20726
- }
20727
- cmd._cachedPlainArgs = stageArgs;
20728
- }
20729
- const incoming = index > 0 ? pipes[index - 1] : void 0;
20730
- const outgoing = index < n - 1 ? pipes[index] : void 0;
20731
- const reading = incoming?.endpoints?.read;
20732
- const writing = outgoing?.endpoints?.write;
20733
- const stageSignal = controllers[index].signal;
20734
- let input;
20735
- if (incoming) {
20736
- reading.abortSignal = stageSignal;
20737
- input = reading;
20738
- } else if (io.stdinIsDefault) input = io.stdin;
20739
- else input = new ShellInput(io.stdin, this.budget, stageSignal, void 0, true);
20740
- const writable = writing?.writable ?? outgoing?.writable;
20741
- const stageStdout = outgoing ? new BudgetedPipeStageSink(this.budget, writable, stageSignal, void 0, index, controllers[index]) : signalSink(io.stdout, stageSignal);
20742
- const context = new FastShellCommandContext(this, rawState, io, scope, firstName, stageArgs, void 0, void 0, true);
20743
- context.stdin = input;
20744
- if (incoming) context.stdinIsDefault = false;
20745
- context.stdout = stageStdout;
20746
- context.signal = this._isMemoryBackingFs ? stageSignal : toNativeAbortSignal(stageSignal);
20747
- context._scopedSignal = stageSignal;
20748
- if (asyncTasks === void 0) {
20749
- scope.enterWork();
20750
- this.budget.beginPathLookupSuspension();
20751
- let syncExitCode = -1;
20752
- let pendingRes;
20753
- let syncErr;
20754
- let hasSyncErr = false;
20755
- try {
20756
- const resPromise = extDef.execute(context);
20757
- if (resPromise === RESOLVED_EXIT_ZERO) {
20758
- stageSignal.throwIfAborted();
20759
- syncExitCode = 0;
20760
- } else if (resPromise === RESOLVED_EXIT_ONE) {
20761
- stageSignal.throwIfAborted();
20762
- syncExitCode = 1;
20763
- } else pendingRes = Promise.resolve(resPromise);
20764
- } catch (error) {
20765
- hasSyncErr = true;
20766
- syncErr = error;
20767
- }
20768
- if (syncExitCode >= 0) {
20769
- this.budget.endPathLookupSuspension();
20770
- scope.leaveWork();
20771
- let asyncCleanup;
20772
- if (!incoming && input !== io.stdin) {
20773
- const closedInput = input.close();
20774
- if (!isSyncResolved5(closedInput)) asyncCleanup = closedInput;
20775
- }
20776
- if (!asyncCleanup && reading) {
20777
- const closedRead = reading.close();
20778
- if (!isSyncResolved5(closedRead)) asyncCleanup = closedRead;
20779
- }
20780
- if (!asyncCleanup && writing) {
20781
- const closedWrite = writing.close();
20782
- if (!isSyncResolved5(closedWrite)) asyncCleanup = closedWrite;
20783
- }
20784
- if (!asyncCleanup && outgoing && !writing) {
20785
- const closedOut = outgoing.close();
20786
- if (!isSyncResolved5(closedOut)) asyncCleanup = closedOut;
20787
- }
20788
- if (!asyncCleanup) {
20789
- statuses[index] = syncExitCode;
20790
- continue;
20791
- }
20792
- asyncTasks = new Array(n);
20793
- for (let prev = 0; prev < index; prev++) asyncTasks[prev] = Promise.resolve(statuses[prev]);
20794
- asyncTasks[index] = asyncCleanup.then(() => syncExitCode);
20795
- continue;
20796
- }
20797
- asyncTasks = new Array(n);
20798
- for (let prev = 0; prev < index; prev++) asyncTasks[prev] = Promise.resolve(statuses[prev]);
20799
- asyncTasks[index] = this.finishFastPurePipelineStageAsync(cmd, context, incoming, outgoing, reading, writing, input, stageSignal, scope, io, pendingRes, hasSyncErr, syncErr);
20800
- continue;
20801
- }
20802
- scope.enterWork();
20803
- this.budget.beginPathLookupSuspension();
20804
- asyncTasks[index] = this.finishFastPurePipelineStageAsync(cmd, context, incoming, outgoing, reading, writing, input, stageSignal, scope, io, void 0, false, void 0, extDef);
20805
- }
20806
- if (asyncTasks !== void 0) {
20807
- return this.finishFastPurePipelineUnitAsync(asyncTasks, n, pipes, controllers, onParentAbort, onScopeSeal, scope, monitor, rawState, pipeline, state, io, ignored);
20808
- }
20809
- } catch (syncFatal) {
20810
- scope.removeSealCallback(onScopeSeal);
20811
- removeAbortSignalWaiter2(this.signal, onParentAbort);
20812
- for (let i = 0; i < n; i++) abortManagedController2(controllers[i], SHARED_PIPELINE_CLOSED);
20813
- for (let i = 0; i < n - 1; i++) void pipes[i].abort();
20814
- this.budget.leavePipelineStages(n);
20815
- throw syncFatal;
20816
- }
20817
- scope.removeSealCallback(onScopeSeal);
20818
- removeAbortSignalWaiter2(this.signal, onParentAbort);
20819
- for (let i = 0; i < n; i++) {
20820
- abortManagedController2(controllers[i], SHARED_PIPELINE_CLOSED);
20821
- }
20822
- for (let i = 0; i < n - 1; i++) {
20823
- void pipes[i].abort();
20824
- }
20825
- this.budget.leavePipelineStages(n);
20826
- const restEpoch = monitor.chargeInternal(syncRestorationCharge, syncRestorationTickets).epoch;
20827
- monitor.lazyPipeStatus = statuses;
20828
- monitor.chargeInternal(syncPipeStatusCharge, syncPipeStatusTickets);
20829
- const rawStatus = rawState.pipefail ? statuses.findLast((s) => s !== 0) ?? 0 : statuses[n - 1];
20830
- const finalStatus = pipeline.negate ? Number(rawStatus === 0) : rawStatus;
20831
- rawState.status = finalStatus;
20832
- monitor.epoch = restEpoch;
20833
- if (rawStatus !== 0 && !pipeline.negate && !ignored && rawState.errexit) {
20834
- if (this.tryFinishShellSync(state)) return { exitCode: finalStatus, terminated: true };
20835
- return this.finishShell(state, io, finalStatus).then((exitCode) => ({ exitCode, terminated: true }));
20836
- }
20837
- return finalStatus === 0 ? SYNC_UNIT_ZERO : finalStatus === 1 ? SYNC_UNIT_ONE : { exitCode: finalStatus, terminated: false };
20838
- }
20839
- async finishFastPurePipelineStageAsync(cmd, context, incoming, outgoing, reading, writing, input, stageSignal, scope, io, pendingRes, hasSyncErr, syncErr, extDef) {
20840
- let exitCode = 0;
20841
- try {
20842
- if (hasSyncErr) throw syncErr;
20843
- const res = await (pendingRes ?? extDef.execute(context));
20844
- stageSignal.throwIfAborted();
20845
- exitCode = validateExitCode(res.exitCode);
20846
- } catch (error) {
20847
- if (error instanceof PipelineClosed || stageSignal.aborted && Object.is(stageSignal.reason, SHARED_PIPELINE_CLOSED)) exitCode = 141;
20848
- else if (errorCode(error) === "EPIPE" && !this.signal.aborted) exitCode = 141;
20849
- else {
20850
- this.signal.throwIfAborted();
20851
- if (error instanceof Flow || error instanceof ShellLimitError || error instanceof ShellSyntaxError) throw error;
20852
- const line = io.diagnosticCommandLines?.get(cmd) ?? (cmd.line ?? 1) + (io.diagnosticOffset ?? 0);
20853
- try {
20854
- await writeDiagnostic(context.stderr, `${io.scriptName ?? "shell"}: line ${line}: ${message(error, this.budget.onInternalError)}
20855
- `);
20856
- } catch (failure) {
20857
- this.signal.throwIfAborted();
20858
- publicDiagnosticMessage(failure, this.budget.onInternalError);
20859
- }
20860
- exitCode = error instanceof CommandFailure ? error.status : 1;
20861
- }
20862
- } finally {
20863
- this.budget.endPathLookupSuspension();
20864
- scope.leaveWork();
20865
- if (!incoming && input !== io.stdin) {
20866
- const closedInput = input.close();
20867
- if (!isSyncResolved5(closedInput)) {
20868
- await closedInput.catch((error) => {
20869
- if (!(error instanceof PipelineClosed)) throw error;
20870
- });
20871
- }
20872
- }
20873
- if (reading) {
20874
- const closedRead = reading.close();
20875
- if (!isSyncResolved5(closedRead)) await closedRead;
20876
- }
20877
- if (writing) {
20878
- const closedWrite = writing.close();
20879
- if (!isSyncResolved5(closedWrite)) await closedWrite;
20880
- }
20881
- if (outgoing && !writing) {
20882
- const closedOut = outgoing.close();
20883
- if (!isSyncResolved5(closedOut)) await closedOut.catch(() => void 0);
20884
- }
20885
- }
20886
- return exitCode;
20887
- }
20888
- async finishFastPurePipelineUnitAsync(tasks, n, pipes, controllers, onParentAbort, onScopeSeal, scope, monitor, rawState, pipeline, state, io, ignored) {
20889
- let statuses;
20890
- try {
20891
- statuses = this.budget._hasExternalSignal ? await interruptible2(Promise.all(tasks), this.signal) : await Promise.all(tasks);
20892
- } finally {
20893
- scope.removeSealCallback(onScopeSeal);
20894
- removeAbortSignalWaiter2(this.signal, onParentAbort);
20895
- for (let i = 0; i < n; i++) {
20896
- abortManagedController2(controllers[i], SHARED_PIPELINE_CLOSED);
20897
- }
20898
- for (let i = 0; i < n - 1; i++) {
20899
- const ab = pipes[i].abort();
20900
- if (!isSyncResolved5(ab)) await ab;
20901
- }
20902
- this.budget.leavePipelineStages(n);
20903
- }
20904
- const restEpoch = monitor.chargeInternal(syncRestorationCharge, syncRestorationTickets).epoch;
20905
- monitor.lazyPipeStatus = statuses;
20906
- monitor.chargeInternal(syncPipeStatusCharge, syncPipeStatusTickets);
20907
- const rawStatus = rawState.pipefail ? statuses.findLast((s) => s !== 0) ?? 0 : statuses[n - 1];
20908
- const finalStatus = pipeline.negate ? Number(rawStatus === 0) : rawStatus;
20909
- rawState.status = finalStatus;
20910
- monitor.epoch = restEpoch;
20911
- if (rawStatus !== 0 && !pipeline.negate && !ignored && rawState.errexit) {
20912
- if (this.tryFinishShellSync(state)) return { exitCode: finalStatus, terminated: true };
20913
- return { exitCode: await this.finishShell(state, io, finalStatus), terminated: true };
20914
- }
20915
- return finalStatus === 0 ? SYNC_UNIT_ZERO : finalStatus === 1 ? SYNC_UNIT_ONE : { exitCode: finalStatus, terminated: false };
20916
- }
20917
20519
  async inputUnit(script, state, io, startListIndex = 0, startPipelineIndex = 0, skipFirstSync = false) {
20918
20520
  try {
20919
20521
  return await this.script(script, state, io, startListIndex, startPipelineIndex, skipFirstSync);
@@ -20926,6 +20528,7 @@ var Runtime = class _Runtime {
20926
20528
  }
20927
20529
  }
20928
20530
  trySyncPipeline(pipeline, state, io, ignored) {
20531
+ io = this.persistentIO(state, io);
20929
20532
  const _rawSt = stateMonitor(state)?.raw ?? state;
20930
20533
  if ((_rawSt._syncPendingFunctionResumes?.length ?? 0) > 0 || _rawSt._syncPendingEvalResume !== void 0) return void 0;
20931
20534
  if (this.budget.limits.maxExpansionBytes < 65536 || this.budget.limits.maxCommands < 1e3 || this.script !== _Runtime.prototype.script) return void 0;
@@ -21121,7 +20724,7 @@ var Runtime = class _Runtime {
21121
20724
  const uArg = wu.plain ?? (wu.parts.length === 1 && wu.parts[0].kind === "text" ? wu.parts[0].value : void 0);
21122
20725
  if (uArg !== void 0) {
21123
20726
  const br = uArg.indexOf("[");
21124
- if (br > 0 && uArg.endsWith("]") && (wu.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0)) {
20727
+ if (br > 0 && uArg.endsWith("]") && (wu.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && !rawState.failglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0)) {
21125
20728
  const arrName = uArg.slice(0, br);
21126
20729
  const subStr = uArg.slice(br + 1, -1);
21127
20730
  const b = isShellIdentifier(arrName) ? st?.get(arrName) : void 0;
@@ -21243,7 +20846,7 @@ var Runtime = class _Runtime {
21243
20846
  }
21244
20847
  if ((w0Plain === "dirname" || w0Plain === "basename") && !hasShellFunction(rawState, w0Plain) && !rawState.extensions?.builtins.has(w0Plain)) {
21245
20848
  const def = this.commands.get(w0Plain);
21246
- if (def && builtInDirectContextExecutors.has(def.execute) && !customRegisteredCommands.has(def.execute)) {
20849
+ if (def && builtInDirectContextExecutors2.has(def.execute) && !customRegisteredCommands.has(def.execute)) {
21247
20850
  if (w0Plain === "dirname" && command.words.length === 2 && isNoBraceSyncWord(command.words[1])) return true;
21248
20851
  if (w0Plain === "basename" && (command.words.length === 2 || command.words.length === 3 || command.words.length === 4 && command.words[1]?.plain === "-s") && command.words.slice(1).every(isNoBraceSyncWord)) return true;
21249
20852
  }
@@ -21266,7 +20869,7 @@ var Runtime = class _Runtime {
21266
20869
  let targetOk = false;
21267
20870
  if (w2Plain !== void 0) {
21268
20871
  const br = w2Plain.indexOf("[");
21269
- if (br > 0 && w2Plain.endsWith("]") && (w2?.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0)) {
20872
+ if (br > 0 && w2Plain.endsWith("]") && (w2?.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && !rawState.failglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0)) {
21270
20873
  const arrName = w2Plain.slice(0, br);
21271
20874
  const subStr = w2Plain.slice(br + 1, -1);
21272
20875
  const b = isShellIdentifier(arrName) ? st?.get(arrName) : void 0;
@@ -21742,7 +21345,7 @@ var Runtime = class _Runtime {
21742
21345
  const follow = op !== "-L" && op !== "-h";
21743
21346
  const syscall = isAccess ? "access" : follow ? "stat" : "lstat";
21744
21347
  const prototype = Object.getPrototypeOf(mem);
21745
- if (prototype !== MemoryFileSystem2.prototype) return void 0;
21348
+ if (prototype !== MemoryFileSystem.prototype) return void 0;
21746
21349
  for (const method of ["stat", "lstat", "access", "snapshot"]) {
21747
21350
  const descriptor = Object.getOwnPropertyDescriptor(mem, method) ?? Object.getOwnPropertyDescriptor(prototype, method);
21748
21351
  if (!descriptor || !("value" in descriptor) || descriptor.value !== memoryFilePredicateImplementation[method]?.value) return void 0;
@@ -22780,7 +22383,7 @@ var Runtime = class _Runtime {
22780
22383
  if (this.budget.limits.maxExpansionFields === Infinity && command.words.length >= 4 && w0Plain === "printf" && command.words[1]?.plain === "-v" && command.redirects.length === 0 && canMutatePipeStatus && (!pipeline.negate || ignored || !rawState.errexit) && !hasShellFunction(rawState, "printf") && !rawState.extensions?.builtins.has("printf")) {
22781
22384
  const def = this.commands.get("printf");
22782
22385
  if (def && def.execute === printfCommand.execute && command.words.length <= this.budget.maxExpansionFieldsSmi && (this.arePureArgWords(command.words, rawState) || command.words.every((w, idx) => idx < 4 ? this.isPureArgWord(w, rawState) : this.isPureArgWord(w, rawState) || this.canSyncArrayMembersWord(w, rawState)))) {
22783
- let targetSpec = command.words[2]?.plain !== void 0 && (rawState.noglob || !hasGlobOrEscape(command.words[2].plain, !!rawState.extglob) || !rawState.nullglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0) ? command.words[2].plain : void 0;
22386
+ let targetSpec = command.words[2]?.plain !== void 0 && (rawState.noglob || !hasGlobOrEscape(command.words[2].plain, !!rawState.extglob) || !rawState.nullglob && !rawState.failglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0) ? command.words[2].plain : void 0;
22784
22387
  if (targetSpec === void 0) {
22785
22388
  try {
22786
22389
  targetSpec = this.fastValueWord(command.words[2], rawState, io, true, false, false, true, void 0, diagnosticLine);
@@ -23238,7 +22841,7 @@ var Runtime = class _Runtime {
23238
22841
  const fastSyncSink = io.stdout instanceof BudgetedSyncSink && io.stdout.write === BudgetedSyncSink.prototype.write || io.stdout instanceof Capture && io.stdout.write === Capture.prototype.write ? io.stdout : void 0;
23239
22842
  const fastPipeSink = !fastSyncSink && io.stdout instanceof BudgetedPipeStageSink && io.stdout.write === BudgetedPipeStageSink.prototype.write && io.stdout.canWriteSync() ? io.stdout : void 0;
23240
22843
  const syncOut = fastSyncSink || fastPipeSink ? void 0 : syncSinks.get(io.stdout);
23241
- if (def && builtInDirectContextExecutors.has(def.execute) && !customRegisteredCommands.has(def.execute) && (fastSyncSink || fastPipeSink || syncOut)) {
22844
+ if (def && builtInDirectContextExecutors2.has(def.execute) && !customRegisteredCommands.has(def.execute) && (fastSyncSink || fastPipeSink || syncOut)) {
23242
22845
  let outText;
23243
22846
  let lastArg = w0Plain;
23244
22847
  try {
@@ -23777,7 +23380,7 @@ var Runtime = class _Runtime {
23777
23380
  const ops = [];
23778
23381
  for (let ui = uStart; ui < command.words.length; ui++) {
23779
23382
  const wu = command.words[ui];
23780
- const canSkipGlobUnset = Boolean(wu.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0);
23383
+ const canSkipGlobUnset = Boolean(wu.parts[0]?.quoted || rawState.noglob || !rawState.nullglob && !rawState.failglob && this._isMemoryBackingFs && tryGetMemoryDirectoryEntryNamesSync(this.backingFs, rawState.cwd)?.size === 0);
23781
23384
  let tExpanded;
23782
23385
  try {
23783
23386
  const fv = this.fastValueWord(wu, rawState, io, !canSkipGlobUnset, false, false, true, void 0, diagnosticLine);
@@ -24445,7 +24048,7 @@ var Runtime = class _Runtime {
24445
24048
  }
24446
24049
  }
24447
24050
  }
24448
- if (w0Plain === "eval" && canMutatePipeStatus && !pipeline.negate && !hasShellFunction(rawState, "eval") && !rawState.extensions?.builtins.has("eval") && isDefaultShellSyntax(rawState.extensions?.syntax) && !rawState.nounset && !rawState.readonlyVariables?.size && rawState.depth < this.budget.limits.maxSubstitutionDepth && !hasYieldCheckpoint(this.signal) && (this._syncReturnDepth > 0 || (this.budget.commands + 32 & 2047) >= 32)) {
24051
+ if (w0Plain === "eval" && !rawState.expand_aliases && canMutatePipeStatus && !pipeline.negate && !hasShellFunction(rawState, "eval") && !rawState.extensions?.builtins.has("eval") && isDefaultShellSyntax(rawState.extensions?.syntax) && !rawState.nounset && !rawState.readonlyVariables?.size && rawState.depth < this.budget.limits.maxSubstitutionDepth && !hasYieldCheckpoint(this.signal) && (this._syncReturnDepth > 0 || (this.budget.commands + 32 & 2047) >= 32)) {
24449
24052
  const evalArgs = [];
24450
24053
  let argsOk = true;
24451
24054
  try {
@@ -25013,7 +24616,7 @@ var Runtime = class _Runtime {
25013
24616
  const initializer = command.expressions[0]?.tree;
25014
24617
  if (initializer?.kind !== "binary" || initializer.operator !== "=" || initializer.left.kind !== "name") return void 0;
25015
24618
  const induction = initializer.left.name;
25016
- const dynamicNames = /* @__PURE__ */ new Set(["PIPESTATUS", "LINENO", "_", "FUNCNAME", "DIRSTACK", "BASH_SUBSHELL"]);
24619
+ const dynamicNames = /* @__PURE__ */ new Set(["PIPESTATUS", "LINENO", "_", "FUNCNAME", "DIRSTACK", "BASH_SUBSHELL", "BASHPID"]);
25017
24620
  const assignments2 = [];
25018
24621
  const appends = /* @__PURE__ */ new Map();
25019
24622
  for (const list of command.body.lists) {
@@ -25152,10 +24755,11 @@ var Runtime = class _Runtime {
25152
24755
  const part = word.parts[i];
25153
24756
  if (part.kind === "text") {
25154
24757
  if (part.byteValue || invokedValues.has(part)) return false;
24758
+ if (!part.quoted && (part.value.includes("~") || part.value.includes("{") || hasGlobOrEscape(part.value, true))) return false;
25155
24759
  continue;
25156
24760
  }
25157
24761
  if (part.kind === "variable") {
25158
- if (part.name === "RANDOM" || part.name === "SECONDS" || stateMonitor(rawState)?.store?.get(part.name)) return false;
24762
+ if (part.name === "RANDOM" || part.name === "SECONDS" || part.name === "BASHPID" || stateMonitor(rawState)?.store?.get(part.name)) return false;
25159
24763
  if (this._syncLoopFnCheckDepth > 0 && (part.substring || getArraySelector(part)?.kind === "element")) return false;
25160
24764
  if (part.prefixNames !== void 0) {
25161
24765
  if (part.prefixNames === "@") return false;
@@ -26802,8 +26406,8 @@ var Runtime = class _Runtime {
26802
26406
  rawState.status = 0;
26803
26407
  }
26804
26408
  runYieldCheckpoint(this.signal);
26805
- for (let r = 0; r < regNames.length; r++) {
26806
- rawState.variables[regNames[r]] = intToStr(sharedLoopIntRegs[r]);
26409
+ for (const name2 of touchedIntNamesList) {
26410
+ rawState.variables[name2] = intToStr(sharedLoopIntRegs[regNames.indexOf(name2)]);
26807
26411
  }
26808
26412
  regNames.length = 0;
26809
26413
  if (hasDeferredSteps && lastInductionInt !== void 0) lastInductionVal = intToStr(lastInductionInt);
@@ -28080,8 +27684,8 @@ ${s1}
28080
27684
  encoded = encoded.slice();
28081
27685
  if (step.targetDirPrefix !== void 0 && step.targetNamePrefix !== void 0) {
28082
27686
  const fileName = this.evalSyncRedirectSuffix(step.targetWord, step.targetDirPrefix, step.targetNamePrefix, rawState, io);
28083
- if (tryWriteMemoryFileInDirSync(this.backingFs, step.targetDirPrefix, fileName, encoded, append, mode, this.commandSignal)) return;
28084
- tryWriteMemoryFileSync(this.backingFs, step.targetDirPrefix + fileName, encoded, append, mode, this.commandSignal);
27687
+ if (!fileName.includes("/") && fileName !== "." && fileName !== ".." && tryWriteMemoryFileInDirSync(this.backingFs, step.targetDirPrefix, fileName, encoded, append, mode, this.commandSignal)) return;
27688
+ tryWriteMemoryFileSync(this.backingFs, normalizePath(step.targetDirPrefix + fileName, rawState.cwd), encoded, append, mode, this.commandSignal);
28085
27689
  return;
28086
27690
  }
28087
27691
  const targetVal = this.evalSyncRedirectWord(step.targetWord, rawState, io);
@@ -28610,6 +28214,7 @@ ${s1}
28610
28214
  }
28611
28215
  const firstIndex = listIndex === startListIndex ? startPipelineIndex : 0;
28612
28216
  for (let index = firstIndex; index < list.pipelines.length; index++) {
28217
+ io = this.persistentIO(state, io);
28613
28218
  if (state.noexec) throw new Flow("discard", 0);
28614
28219
  const operator = index > 0 ? list.operators[index - 1] : void 0;
28615
28220
  const resumingEnteredPipeline = skipFirstSync && listIndex === startListIndex && index === startPipelineIndex;
@@ -28765,7 +28370,8 @@ ${s1}
28765
28370
  }
28766
28371
  for (let index = 1; index < pipeline.commands.length; index++) pipes.push(createBytePipe({
28767
28372
  highWaterMark: this.budget.limits.pipeHighWaterMark,
28768
- signal: this.signal
28373
+ signal: this.signal,
28374
+ admitWrite: this.budget.pipelineInput
28769
28375
  }));
28770
28376
  for (let index = 0; index < pipeline.commands.length; index++) {
28771
28377
  controllers.push(createManagedControlController2());
@@ -28800,6 +28406,7 @@ ${s1}
28800
28406
  void installation.catch(() => void 0);
28801
28407
  }
28802
28408
  const tasks = pipeline.commands.map(async (command, index) => {
28409
+ const inCurrentShell = !!state.lastpipe && index === pipeline.commands.length - 1;
28803
28410
  let admitted = false;
28804
28411
  const admit = () => {
28805
28412
  if (admitted) return;
@@ -28832,7 +28439,7 @@ ${s1}
28832
28439
  let stageOwnsCleanup = false;
28833
28440
  try {
28834
28441
  const rawStateForChild = stateMonitor(state)?.raw ?? state;
28835
- const isPureStage = !terminal && !(io.descriptors && (io.descriptors.size > 3 || io.descriptors.get(0)?.closed || io.descriptors.get(1)?.closed || io.descriptors.get(2)?.closed)) && runtime.isPureExternalStageCommand(command, rawStateForChild);
28442
+ const isPureStage = !inCurrentShell && !terminal && !(io.descriptors && (io.descriptors.size > 3 || io.descriptors.get(0)?.closed || io.descriptors.get(1)?.closed || io.descriptors.get(2)?.closed)) && runtime.isPureExternalStageCommand(command, rawStateForChild);
28836
28443
  const references = isPureStage ? void 0 : cleanupRefs = new PipeDescriptorFrame(io[invocationScope]);
28837
28444
  const descriptorFrame = isPureStage ? void 0 : cleanupDescFrame = new PreparedDescriptorFrame(references, this.budget);
28838
28445
  const reading = incoming?.endpoints?.read;
@@ -28854,14 +28461,14 @@ ${s1}
28854
28461
  try {
28855
28462
  const isFastPure = isPureStage || runtime.isPureExternalStageCommand(command, rawStateForChild);
28856
28463
  const forkedExt = isFastPure ? forkExtensions(state.extensions, "pipeline") : void 0;
28857
- const child = isFastPure ? Object.assign(cloneRawState(rawStateForChild, false), {
28464
+ const child = inCurrentShell ? state : isFastPure ? Object.assign(cloneRawState(rawStateForChild, false), {
28858
28465
  extensions: forkedExt,
28859
28466
  isolated: true,
28860
28467
  _readOnlyStage: true
28861
28468
  }) : tryCloneStateSync(state) ?? await cloneState(state, this.signal);
28862
- preparedChild = child;
28863
- child.variables.BASH_SUBSHELL = String(Number(state.variables.BASH_SUBSHELL ?? 0) + 1);
28864
- if (!child._readOnlyStage) {
28469
+ preparedChild = inCurrentShell ? void 0 : child;
28470
+ if (!inCurrentShell) child.variables.BASH_SUBSHELL = String(Number(state.variables.BASH_SUBSHELL ?? 0) + 1);
28471
+ if (!inCurrentShell && !child._readOnlyStage) {
28865
28472
  child.extensions = void 0;
28866
28473
  child.extensions = forkExtensions(state.extensions, "pipeline");
28867
28474
  child.isolated = true;
@@ -28903,7 +28510,7 @@ ${s1}
28903
28510
  await installation;
28904
28511
  signal.throwIfAborted();
28905
28512
  }
28906
- const work = runtime.runPipelineStageWork(command, child, childIO, io, (reason) => {
28513
+ const work = inCurrentShell ? runtime.command(command, child, { ...childIO, terminal: void 0 }) : runtime.runPipelineStageWork(command, child, childIO, io, (reason) => {
28907
28514
  checkpointFailure = reason;
28908
28515
  });
28909
28516
  preparedChild = void 0;
@@ -29193,6 +28800,7 @@ ${s1}
29193
28800
  return status;
29194
28801
  }
29195
28802
  async executeCommand(command, state, originalIO, fileShortcut = false) {
28803
+ originalIO = this.persistentIO(state, originalIO);
29196
28804
  const terminal = originalIO.terminal?.target === command ? originalIO.terminal : void 0;
29197
28805
  if (!state._readOnlyStage) state = trackState(state, this.budget, originalIO[invocationScope]);
29198
28806
  if (originalIO.asyncDefaultInput) {
@@ -29516,6 +29124,18 @@ ${s1}
29516
29124
  let diagnosticFailure;
29517
29125
  let outputTracker;
29518
29126
  const snapshotHolder = {};
29127
+ const execState = stateMonitor(state)?.raw ?? state;
29128
+ const savedExecDescriptors = /* @__PURE__ */ new Map();
29129
+ if (command.redirects.length) {
29130
+ const frame = execDescriptorFrames.get(execState);
29131
+ for (const redirect of command.redirects) {
29132
+ for (const number2 of redirect.operator === "&>" || redirect.operator === "&>>" ? [1, 2] : [redirect.descriptor]) {
29133
+ if (savedExecDescriptors.has(number2)) continue;
29134
+ const descriptor = originalIO.descriptors?.get(number2) ?? (number2 === 0 ? { input: originalIO.stdin } : number2 === 1 ? { output: originalIO.stdout } : number2 === 2 ? { output: originalIO.stderr } : { closed: true });
29135
+ savedExecDescriptors.set(number2, { descriptor, revision: frame?.revisions.get(number2), release: descriptor.lifetime?.acquire() });
29136
+ }
29137
+ }
29138
+ }
29519
29139
  try {
29520
29140
  let status = 0;
29521
29141
  if (command.kind === "simple") {
@@ -29543,11 +29163,28 @@ ${s1}
29543
29163
  return errResult.status;
29544
29164
  } finally {
29545
29165
  try {
29546
- if (!references && outputs.size === 0 && inputs.size === 0 && processSubstitutions.length === 0) allocation.close();
29547
- else await this.cleanupCommandResources(references, outputs, inputs, processSubstitutions, allocation, diagnosticFailure, io);
29166
+ const frame = execDescriptorFrames.get(execState);
29167
+ const retirements = [];
29168
+ for (const [number2, saved] of savedExecDescriptors) {
29169
+ if (frame && !snapshotHolder.persistentRedirects && frame.revisions.get(number2) !== saved.revision) {
29170
+ const release = frame.releases.get(number2);
29171
+ if (saved.release) frame.releases.set(number2, saved.release);
29172
+ else frame.releases.delete(number2);
29173
+ frame.descriptors.set(number2, saved.descriptor);
29174
+ frame.revisions.set(number2, ++frame.version);
29175
+ if (release) retirements.push(release());
29176
+ } else if (saved.release) retirements.push(saved.release());
29177
+ }
29178
+ const retired = await Promise.allSettled(retirements);
29179
+ throwCleanupFailures(retired.filter((result) => result.status === "rejected").map((result) => result.reason));
29548
29180
  } finally {
29549
- snapshotHolder.finish?.();
29550
- if (snapshotHolder.scope) await snapshotHolder.scope.close();
29181
+ try {
29182
+ if (!references && outputs.size === 0 && inputs.size === 0 && processSubstitutions.length === 0) allocation.close();
29183
+ else await this.cleanupCommandResources(references, outputs, inputs, processSubstitutions, allocation, diagnosticFailure, io);
29184
+ } finally {
29185
+ snapshotHolder.finish?.();
29186
+ if (snapshotHolder.scope) await snapshotHolder.scope.close();
29187
+ }
29551
29188
  }
29552
29189
  }
29553
29190
  }
@@ -29754,7 +29391,7 @@ ${s1}
29754
29391
  }
29755
29392
  }
29756
29393
  if (!matched) continue;
29757
- if (clause.body.lists.length) status = await this.script(clause.body, state, io);
29394
+ status = clause.body.lists.length ? await this.script(clause.body, state, io) : 0;
29758
29395
  if (clause.terminator === ";;" || clause.terminator === "esac") break;
29759
29396
  fallthrough = clause.terminator === ";&";
29760
29397
  }
@@ -29775,7 +29412,7 @@ ${s1}
29775
29412
  }
29776
29413
  }
29777
29414
  if (!matched) continue;
29778
- if (clause.body.lists.length) status = await this.script(clause.body, state, io);
29415
+ status = clause.body.lists.length ? await this.script(clause.body, state, io) : 0;
29779
29416
  if (clause.terminator === ";;" || clause.terminator === "esac") break;
29780
29417
  fallthrough = clause.terminator === ";&";
29781
29418
  }
@@ -30045,6 +29682,7 @@ ${s1}
30045
29682
  publicDiagnosticMessage(failure, this.budget.onInternalError);
30046
29683
  }
30047
29684
  }
29685
+ if (error instanceof FailglobFailure) throw completedExit(1, state.errexit ? "exit" : "discard");
30048
29686
  if (error instanceof ExpansionFailure || error instanceof BraceExpansionFailure) throw completedExit(error instanceof ParameterExpansionFailure && !state.isolated ? 127 : 1);
30049
29687
  if (error instanceof FatalCommandFailure) throw completedExit(error.status);
30050
29688
  if (error instanceof DiscardCommandFailure) throw completedExit(error.status, "discard");
@@ -30148,6 +29786,8 @@ ${s1}
30148
29786
  const descriptor = descriptors.get(0)?.closed ? void 0 : descriptors.get(0);
30149
29787
  const stdinIsDefault = descriptor?.input ? descriptor.stdinIsDefault : false;
30150
29788
  return {
29789
+ ...io.execVersion === void 0 ? {} : { execVersion: io.execVersion },
29790
+ ...io.execFrame === void 0 ? {} : { execFrame: io.execFrame },
30151
29791
  capabilities: io.capabilities,
30152
29792
  ...io.argv0 === void 0 ? {} : { argv0: io.argv0 },
30153
29793
  [invocationScope]: io[invocationScope],
@@ -30275,7 +29915,16 @@ ${s1}
30275
29915
  await replaceDescriptor(redirect.descriptor, { input, stdinIsDefault: false, lifetime, ...file ? { file } : {}, ...output ? { output } : {} });
30276
29916
  } else {
30277
29917
  const append = redirect.operator === ">>" || redirect.operator === "&>>";
30278
- const flag = append ? "a" : state.noclobber && redirect.operator !== ">|" ? "wx" : "w";
29918
+ let flag = append ? "a" : state.noclobber && redirect.operator !== ">|" ? "wx" : "w";
29919
+ if (flag === "wx") {
29920
+ try {
29921
+ const stat = await resourceFs.stat(path, options);
29922
+ if (stat.type !== "file" && stat.type !== "directory") flag = "w";
29923
+ } catch (error) {
29924
+ this.signal.throwIfAborted();
29925
+ if (!(error instanceof FsError) || error.code !== "ENOENT") throw error;
29926
+ }
29927
+ }
30279
29928
  const capabilities = await this.fs.capabilitiesFor?.(path, { ...options, ...flag === "wx" ? { creation: "exclusive" } : {} }) ?? this.fs.capabilities;
30280
29929
  const streaming = capabilities.preferStreamingRedirection === true && typeof this.fs.writeStream === "function" && (append ? capabilities.streamingAppend ?? capabilities.streamingWrite : capabilities.streamingWrite) === true;
30281
29930
  const canonical = capabilities.open === true && !streaming;
@@ -30697,6 +30346,29 @@ ${s1}
30697
30346
  }
30698
30347
  }
30699
30348
  if (!words.length) return state.substitutionStatus;
30349
+ if (words[declarationIndex] === "exec" && !functionCommand && !state.extensions?.builtins.has("exec")) {
30350
+ snapshotHolder.persistentRedirects = true;
30351
+ const raw = stateMonitor(state)?.raw ?? state;
30352
+ let frame = execDescriptorFrames.get(raw);
30353
+ if (!frame) {
30354
+ frame = { version: 0, descriptors: /* @__PURE__ */ new Map(), revisions: /* @__PURE__ */ new Map(), releases: /* @__PURE__ */ new Map() };
30355
+ execDescriptorFrames.set(raw, frame);
30356
+ this.budget.executionCleanup.register(() => closeExecDescriptors(raw));
30357
+ }
30358
+ for (const redirect of command.redirects) {
30359
+ const numbers = redirect.operator === "&>" || redirect.operator === "&>>" ? [1, 2] : [redirect.descriptor];
30360
+ for (const number2 of numbers) {
30361
+ const descriptor = io.descriptors?.get(number2) ?? { closed: true };
30362
+ const release = descriptor.lifetime?.acquire();
30363
+ const previousRelease = frame.releases.get(number2);
30364
+ if (release) frame.releases.set(number2, release);
30365
+ else frame.releases.delete(number2);
30366
+ frame.descriptors.set(number2, descriptor);
30367
+ frame.revisions.set(number2, ++frame.version);
30368
+ await previousRelease?.();
30369
+ }
30370
+ }
30371
+ }
30700
30372
  const args = words.slice(1);
30701
30373
  const argValues = allStrings ? args : wordValues.slice(1);
30702
30374
  const dispatchIO = compounds ? { ...io, [declarationArrays]: compounds } : io;
@@ -30816,7 +30488,7 @@ ${s1}
30816
30488
  if (body) env[`BASH_FUNC_${key}%%`] = functionDisplay(key, body).slice(key.length + 1).trimEnd();
30817
30489
  }
30818
30490
  }
30819
- const context = new FastShellCommandContext(this, state, io, scope, name2, values, void 0, env, this._isMemoryBackingFs);
30491
+ const context = new FastShellCommandContext(this, state, io, scope, name2, values, void 0, env, this._isMemoryBackingFs, definition);
30820
30492
  const runtimeFrame = {};
30821
30493
  scope.enterWork();
30822
30494
  this.budget.beginPathLookupSuspension();
@@ -31510,6 +31182,37 @@ ${s1}
31510
31182
  state.lastArgument = context2.args.at(-1) ?? context2.command;
31511
31183
  return { exitCode };
31512
31184
  }
31185
+ if (context2.command === "exec") {
31186
+ let execIdx = 0;
31187
+ while (execIdx < context2.args.length) {
31188
+ const f = context2.args[execIdx];
31189
+ if (f === "--") {
31190
+ execIdx += 1;
31191
+ break;
31192
+ }
31193
+ if (f === "-a" && execIdx + 1 < context2.args.length) {
31194
+ execIdx += 2;
31195
+ continue;
31196
+ }
31197
+ if (f === "-c" || f === "-l") {
31198
+ execIdx += 1;
31199
+ continue;
31200
+ }
31201
+ break;
31202
+ }
31203
+ const execRest = context2.args.slice(execIdx);
31204
+ const execCmd = execRest[0];
31205
+ if (execCmd === void 0) {
31206
+ return { exitCode: 0 };
31207
+ }
31208
+ const execArgs = execRest.slice(1);
31209
+ const status = await this.dispatch(execCmd, execArgs, state, { ...io, ...context2 }, assignments2, true, context2.argumentValues.values.slice(execIdx + 1));
31210
+ throw completedExit(status, "exit");
31211
+ }
31212
+ if (context2.command === "read" && context2.args.some((arg) => arg.startsWith("-") && (arg.includes("u") || arg.includes("t")))) {
31213
+ const { executeRead } = await import("./read-builtin-A4QKAT45.js");
31214
+ return { exitCode: await executeRead(true, this.extensionContext(state, { ...io, ...context2 }, context2.command, context2.args, context2.argumentValues.values)) };
31215
+ }
31513
31216
  const builtinWork = this.builtin({ ...context2, [declarationArrays]: io[declarationArrays] }, state, assignments2, (error, diagnostic) => {
31514
31217
  builtinFailure = { error, diagnostic };
31515
31218
  }, bypassFunctions);
@@ -31907,7 +31610,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
31907
31610
  try {
31908
31611
  do {
31909
31612
  this.signal.throwIfAborted();
31910
- const unit = parseShellUnit(source, position, byteLocale(state.variables), this.budget.parsing, lineIndex, void 0, false, state.extensions?.syntax);
31613
+ const unit = parseShellUnit(source, position, byteLocale(state.variables), this.budget.parsing, lineIndex, void 0, false, state.extensions?.syntax, state.expand_aliases ? state.aliases : void 0);
31911
31614
  for (const warning of unit.script.warnings ?? []) await writeDiagnostic(io.stderr, `${io.scriptName}: warning: ${warning}
31912
31615
  `);
31913
31616
  if (unit.script.lists.length) {
@@ -31948,7 +31651,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
31948
31651
  }
31949
31652
  const unitIO = { ...io, diagnosticOffset: offset };
31950
31653
  try {
31951
- const unit = eof ? parseShellUnit(source, 0, byteLocale(state.variables), this.budget.parsing, lineIndex, void 0, false, state.extensions?.syntax) : parseShellInputUnit(source, byteLocale(state.variables), this.budget.parsing, lineIndex, state.extensions?.syntax);
31654
+ const unit = eof ? parseShellUnit(source, 0, byteLocale(state.variables), this.budget.parsing, lineIndex, void 0, false, state.extensions?.syntax, state.expand_aliases ? state.aliases : void 0) : parseShellInputUnit(source, byteLocale(state.variables), this.budget.parsing, lineIndex, state.extensions?.syntax, state.expand_aliases ? state.aliases : void 0);
31952
31655
  if (unit) {
31953
31656
  for (const warning of unit.script.warnings ?? []) await writeDiagnostic(io.stderr, `${io.scriptName}: warning: ${warning}
31954
31657
  `);
@@ -32197,7 +31900,8 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
32197
31900
  else {
32198
31901
  const options2 = { signal: this.signal };
32199
31902
  const stat = await interruptible2(this.fs.stat(path, options2), this.signal);
32200
- if (stat.type !== "file") throw new CommandFailure(`${target}: ${stat.type === "directory" ? "Is a directory" : "not a regular file"}`, 126);
31903
+ if (stat.type === "directory") throw new CommandFailure(`${target}: Is a directory`, 126);
31904
+ if (stat.type !== "file" && (direct || stat.type !== "character" && stat.type !== "fifo")) throw new CommandFailure(`${target}: not a regular file`, 126);
32201
31905
  if (direct) {
32202
31906
  const capabilities = this.fs.capabilitiesFor ? await interruptible2(this.fs.capabilitiesFor(path, options2), this.signal) : this.fs.capabilities;
32203
31907
  if (capabilities.permissions !== true) throw new CommandFailure(`${target}: execution permissions are not supported by this filesystem`, 126);
@@ -32268,7 +31972,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
32268
31972
  this.signal.throwIfAborted();
32269
31973
  let unit;
32270
31974
  try {
32271
- unit = parseShellUnit(source, position, byteLocale(child.variables), this.budget.parsing, lineIndex, void 0, false, child.extensions?.syntax);
31975
+ unit = parseShellUnit(source, position, byteLocale(child.variables), this.budget.parsing, lineIndex, void 0, false, child.extensions?.syntax, child.expand_aliases ? child.aliases : void 0);
32272
31976
  } catch (error) {
32273
31977
  if (!(error instanceof ShellSyntaxError)) throw error;
32274
31978
  await writeDiagnostic(context.stderr, `${target}: line ${lineIndex.lineAt(error.offset)}: syntax error: ${error.reason}
@@ -32291,7 +31995,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
32291
31995
  }
32292
31996
  }
32293
31997
  async runCurrentText(source, state, io, fatalSyntax, syntaxName, byteSource = false, includeSyntaxContext = true, sourceValues) {
32294
- if (!sourceValues && !byteSource && isDefaultShellSyntax(state.extensions?.syntax) && source.length <= 4096) {
31998
+ if (!state.expand_aliases && !sourceValues && !byteSource && isDefaultShellSyntax(state.extensions?.syntax) && source.length <= 4096) {
32295
31999
  try {
32296
32000
  const cachedUnit = getOrParseSingleEvalUnit(source, byteLocale(state.variables), this.budget.parsing);
32297
32001
  if (cachedUnit) {
@@ -32318,7 +32022,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
32318
32022
  try {
32319
32023
  do {
32320
32024
  this.signal.throwIfAborted();
32321
- const unit = parseShellUnit(source, position, byteLocale(state.variables), this.budget.parsing, lineIndex, sourceValues, byteSource, state.extensions?.syntax);
32025
+ const unit = parseShellUnit(source, position, byteLocale(state.variables), this.budget.parsing, lineIndex, sourceValues, byteSource, state.extensions?.syntax, state.expand_aliases ? state.aliases : void 0);
32322
32026
  for (const warning of unit.script.warnings ?? []) await writeDiagnostic(io.stderr, `${io.scriptName ?? "shell"}: warning: ${warning}
32323
32027
  `);
32324
32028
  if (unit.script.lists.length) {
@@ -32421,7 +32125,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
32421
32125
  const path = pathOf(state, target);
32422
32126
  const stat = await interruptible2(this.fs.stat(path, options), this.signal);
32423
32127
  if (stat.type === "directory") throw new CommandFailure(`${context.command}: ${target}: is a directory`, 1);
32424
- if (stat.type !== "file") throw new CommandFailure(`${target}: not a regular file`, 1);
32128
+ if (stat.type !== "file" && stat.type !== "character" && stat.type !== "fifo") throw new CommandFailure(`${target}: not a regular file`, 1);
32425
32129
  await interruptible2(this.fs.access(path, ACCESS_MODES.R_OK, options), this.signal);
32426
32130
  const maxBytes = this.budget.limits.maxSourceBytes - this.budget.sourceBytes;
32427
32131
  if (stat.size > maxBytes) this.budget.fail("maxSourceBytes");
@@ -33062,7 +32766,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
33062
32766
  return 1;
33063
32767
  }
33064
32768
  const options = /* @__PURE__ */ new Map();
33065
- for (const name2 of setNamespace ? ["allexport", "braceexpand", "errexit", "noclobber", "noexec", "noglob", "nounset", "pipefail"] : ["dotglob", "extglob", "globstar", "nocaseglob", "nocasematch", "nullglob"]) {
32769
+ for (const name2 of setNamespace ? ["allexport", "braceexpand", "errexit", "noclobber", "noexec", "noglob", "nounset", "pipefail"] : ["dotglob", "expand_aliases", "extglob", "failglob", "globstar", "inherit_errexit", "lastpipe", "nocaseglob", "nocasematch", "nullglob"]) {
33066
32770
  options.set(name2, {
33067
32771
  get enabled() {
33068
32772
  return name2 === "braceexpand" ? state.braceexpand !== false : !!state[name2];
@@ -33475,6 +33179,12 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
33475
33179
  return status;
33476
33180
  }
33477
33181
  if (command === "shopt") return this.shoptBuiltin(context, state);
33182
+ if (command === "alias" || command === "unalias") {
33183
+ const aliases = state.aliases ??= /* @__PURE__ */ new Map();
33184
+ const limits = { maxArgumentBytes: this.budget.limits.maxExpansionBytes, maxAliasBytes: this.budget.limits.maxExpansionBytes };
33185
+ const definition = command === "alias" ? createAliasCommand({ aliases, limits }) : createUnaliasCommand({ aliases, limits });
33186
+ return (await definition.execute(context)).exitCode;
33187
+ }
33478
33188
  if (command === "let") return this.letBuiltin(context, state);
33479
33189
  if (command === "mapfile" || command === "readarray") return this.mapfileBuiltin(context, state);
33480
33190
  if (command === "getopts") return this.getoptsBuiltin(context, state);
@@ -34362,6 +34072,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34362
34072
  }
34363
34073
  if (command === "break" || command === "continue") {
34364
34074
  if (!state.loopDepth) {
34075
+ if (state._subshellInLoop) throw completedExit(0, command, 1);
34365
34076
  await writeDiagnostic(stderr, `${command}: only meaningful in a loop
34366
34077
  `);
34367
34078
  return 0;
@@ -34566,7 +34277,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34566
34277
  const operator = part.operator.at(-1);
34567
34278
  if (operator === "+" ? !missing : missing) {
34568
34279
  if (operator === "=") throw new ArrayFailure(`${part.name}[${memberSelector.separator}]: bad array subscript`);
34569
- const alternate = concatShellValues(await this.valueWord(part.alternate, state, this.parameterOperandIO(part.alternate, state, io), false, false, hereString, false, void 0, hereDocument), io[valueScope]);
34280
+ const alternate = concatShellValues(await this.valueWord(part.alternate, state, this.parameterOperandIO(part.alternate, state, io), false, false, hereString, false, void 0, hereDocument || part.quoted), io[valueScope]);
34570
34281
  if (operator === "?") throw new ParameterExpansionFailure(`${part.name}: ${shellValueText(alternate) || "parameter not set"}`, io.diagnosticLine ?? part.line);
34571
34282
  return alternate;
34572
34283
  }
@@ -34584,12 +34295,13 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34584
34295
  if (operator === "+" ? !missing : missing) {
34585
34296
  const operandIO = this.parameterOperandIO(part.alternate, state, io);
34586
34297
  if (operator === "=") {
34587
- await this.arrayAssignment({ kind: "element", name: part.name, index: element.index, append: false, value: part.alternate }, state, operandIO);
34298
+ const elemAlt = part.quoted ? { ...part.alternate, parts: part.alternate.parts.map((p) => ({ ...p, quoted: true })) } : part.alternate;
34299
+ await this.arrayAssignment({ kind: "element", name: part.name, index: element.index, append: false, value: elemAlt }, state, operandIO);
34588
34300
  const assigned = store.get(part.name);
34589
34301
  const assignedIndex = assigned.associative ? await this.arrayIndex(assigned, element.index, state, io, store.owner) : index2;
34590
34302
  return assignedIndex === void 0 ? "" : assigned.getValue(assignedIndex) ?? "";
34591
34303
  }
34592
- const alternate = concatShellValues(await this.valueWord(part.alternate, state, operandIO, false, false, hereString, false, void 0, hereDocument), io[valueScope]);
34304
+ const alternate = concatShellValues(await this.valueWord(part.alternate, state, operandIO, false, false, hereString, false, void 0, hereDocument || part.quoted), io[valueScope]);
34593
34305
  if (operator === "?") throw new ParameterExpansionFailure(`${part.name}: ${shellValueText(alternate) || (part.operator.startsWith(":") ? "parameter null or not set" : "parameter not set")}`, io.diagnosticLine ?? part.line);
34594
34306
  return alternate;
34595
34307
  }
@@ -34791,13 +34503,29 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34791
34503
  if (part.kind === "process-substitution") {
34792
34504
  if (state.depth >= this.budget.limits.maxSubstitutionDepth) this.budget.fail("maxSubstitutionDepth");
34793
34505
  this.signal.throwIfAborted();
34794
- const tempPath = `/.procsub-${++nextProcessSubstitutionId}`;
34506
+ const ids = state.processSubstitutionIds ??= { next: 0 };
34507
+ const requestedDirectory = pathOf(state, state.variables.TMPDIR || "/tmp");
34508
+ const directory = requestedDirectory === "/" ? "/tmp" : requestedDirectory;
34509
+ await this.sourceFs.mkdir(directory, { recursive: true, signal: this.signal });
34510
+ let tempPath = "";
34511
+ let owned = false;
34795
34512
  io[invocationScope].register(async () => {
34796
- try {
34513
+ if (owned) try {
34797
34514
  await this.sourceFs.rm(tempPath, { force: true });
34798
34515
  } catch {
34799
34516
  }
34800
34517
  });
34518
+ while (!owned) {
34519
+ this.budget.tick();
34520
+ tempPath = pathOf(state, `${directory}/.procsub-${++ids.next}`);
34521
+ try {
34522
+ await this.sourceFs.writeFile(tempPath, new Uint8Array(0), { flag: "wx", signal: this.signal });
34523
+ owned = true;
34524
+ } catch (error) {
34525
+ this.signal.throwIfAborted();
34526
+ if (!(error instanceof FsError) || error.code !== "EEXIST") throw error;
34527
+ }
34528
+ }
34801
34529
  if (part.direction === "<") {
34802
34530
  const capture = new Capture();
34803
34531
  const child = await cloneState(state, this.signal);
@@ -34807,7 +34535,6 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34807
34535
  if (state.profile !== "sh") child.errexit = false;
34808
34536
  delete child.redirectAssignments;
34809
34537
  child.depth++;
34810
- child.loopDepth = 0;
34811
34538
  const references = new PipeDescriptorFrame(io[invocationScope]);
34812
34539
  const lifetime = new DescriptorLifetime();
34813
34540
  const captureIO = isolateIO({
@@ -34856,7 +34583,6 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34856
34583
  if (state.profile !== "sh") child.errexit = false;
34857
34584
  delete child.redirectAssignments;
34858
34585
  child.depth++;
34859
- child.loopDepth = 0;
34860
34586
  const prepared = prepareBytesInput(bytes, this.budget);
34861
34587
  const input = new ShellInput(prepared.source, this.budget, this.commandSignal, prepared.options);
34862
34588
  const lifetime = new DescriptorLifetime(async () => {
@@ -34900,14 +34626,13 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
34900
34626
  child.isolated = true;
34901
34627
  child.variables.BASH_SUBSHELL = String(Number(state.variables.BASH_SUBSHELL ?? 0) + 1);
34902
34628
  child.extensions = forkExtensions(state.extensions, "substitution");
34903
- if (state.profile !== "sh") child.errexit = false;
34629
+ if (state.profile !== "sh" && !state.inherit_errexit) child.errexit = false;
34904
34630
  for (const [name2, value2] of state.redirectAssignments ?? []) {
34905
34631
  await this.writeVariable(child, name2, value2, io);
34906
34632
  child.exported.add(name2);
34907
34633
  }
34908
34634
  delete child.redirectAssignments;
34909
34635
  child.depth++;
34910
- child.loopDepth = 0;
34911
34636
  const pipeline = part.script.lists.length === 1 && part.script.lists[0].pipelines.length === 1 ? part.script.lists[0].pipelines[0] : void 0;
34912
34637
  const command = pipeline && !pipeline.negate && pipeline.commands.length === 1 ? pipeline.commands[0] : void 0;
34913
34638
  const fileShortcut = command?.kind === "simple" && command.words.length === 0 && command.redirects.length === 1 && command.redirects[0].operator === "<";
@@ -35028,16 +34753,17 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35028
34753
  if (operator === "+" && !missing || operator !== "+" && missing) {
35029
34754
  const operandIO = this.parameterOperandIO(part.alternate, state, io);
35030
34755
  let alternate;
34756
+ const altWord = !hereDocument && !part.quoted && operator === "=" ? { ...part.alternate, parts: expandTildes(part.alternate.parts, state.variables, this.budget, void 0, true) } : part.alternate;
35031
34757
  if (operator === "=" && arrayStore(state)?.get(part.name)) {
35032
34758
  alternate = "";
35033
34759
  await this.arrayZero(state, part.name, io, async () => {
35034
- retained = await this.arrayJoin(requireArrays(state).owner, await this.valueWord(part.alternate, state, operandIO, false, false, hereString, false, void 0, hereDocument), "");
34760
+ retained = await this.arrayJoin(requireArrays(state).owner, await this.valueWord(altWord, state, operandIO, false, false, hereString, false, void 0, hereDocument || part.quoted || operator === "="), "");
35035
34761
  return retained;
35036
34762
  });
35037
34763
  value = shellValueText(retained);
35038
34764
  return part.length ? this.valueLength(retained, state, io) : retained;
35039
34765
  }
35040
- retained = concatShellValues(await this.valueWord(part.alternate, state, operandIO, false, false, hereString, false, void 0, hereDocument), io[valueScope]);
34766
+ retained = concatShellValues(await this.valueWord(altWord, state, operandIO, false, false, hereString, false, void 0, hereDocument || part.quoted || operator === "="), io[valueScope]);
35041
34767
  alternate = shellValueText(retained);
35042
34768
  if (operator === "?") throw new ParameterExpansionFailure(`${part.name}: ${alternate || (part.operator.startsWith(":") ? "parameter null or not set" : "parameter not set")}`, io.diagnosticLine ?? part.line);
35043
34769
  if (operator === "=") {
@@ -35489,7 +35215,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35489
35215
  continue;
35490
35216
  }
35491
35217
  if (part.indirect || part.specialParameter) return void 0;
35492
- if (part.name === "@" || part.name === "*" || part.name === "PIPESTATUS" || part.name === "LINENO" || part.name === "BASH_SUBSHELL" || part.name === "_" || part.name === "FUNCNAME" || part.name === "DIRSTACK") return void 0;
35218
+ if (part.name === "@" || part.name === "*" || part.name === "PIPESTATUS" || part.name === "LINENO" || part.name === "BASH_SUBSHELL" || part.name === "BASHPID" || part.name === "_" || part.name === "FUNCNAME" || part.name === "DIRSTACK") return void 0;
35493
35219
  if (!isShellIdentifier(part.name)) return void 0;
35494
35220
  const selector = getArraySelector(part);
35495
35221
  const arrayBinding = activeArrayStore?.get(part.name);
@@ -43090,7 +42816,7 @@ unsigned int ${ident}_len = ${view.byteLength};
43090
42816
  const p = word.parts[i];
43091
42817
  if (p.kind === "text") continue;
43092
42818
  if (p.kind === "variable") {
43093
- if (p.name === "BASH_SUBSHELL" || p.name === "RANDOM" || p.name === "SECONDS") return false;
42819
+ if (p.name === "BASH_SUBSHELL" || p.name === "BASHPID" || p.name === "RANDOM" || p.name === "SECONDS") return false;
43094
42820
  if (!p.indirect && !p.prefixNames && !p.length && !p.substring && !p.transform && p.operator === void 0 && getArraySelector(p) === void 0 && (p.name === "?" || p.name === "#" || p.name.length === 1 && p.name >= "1" && p.name <= "9")) {
43095
42821
  const activePos = this._fastSubPositional ?? rawState.positional;
43096
42822
  if (rawState.nounset && p.name >= "1" && p.name <= "9" && activePos[p.name.charCodeAt(0) - 49] === void 0) return false;
@@ -43111,6 +42837,8 @@ unsigned int ${ident}_len = ${view.byteLength};
43111
42837
  return true;
43112
42838
  }
43113
42839
  tryFastPureSubstitution(part, state, rawState, io) {
42840
+ if (!cCollation(rawState.variables.LC_ALL || rawState.variables.LC_COLLATE || rawState.variables.LANG || "C")) return void 0;
42841
+ if (this.budget.limits.maxPipelineBytes !== Infinity) return void 0;
43114
42842
  if (this.budget.limits.maxInputBytes !== Infinity) return void 0;
43115
42843
  const cachedInv = this._syncLoopInvariantSubMap?.get(part);
43116
42844
  if (cachedInv !== void 0 && !cachedInv.dynamic) {
@@ -43147,7 +42875,7 @@ unsigned int ${ident}_len = ${view.byteLength};
43147
42875
  const definition = this.commands.get(name2);
43148
42876
  if (definition && customRegisteredCommands.has(definition.execute)) return void 0;
43149
42877
  if (name2 === "uname" || name2 === "nproc" || name2 === "hostname" || name2 === "id" || name2 === "whoami") {
43150
- if (!definition || !builtInDirectContextExecutors.has(definition.execute)) return void 0;
42878
+ if (!definition || !builtInDirectContextExecutors2.has(definition.execute)) return void 0;
43151
42879
  }
43152
42880
  }
43153
42881
  if (pipeline.commands.length >= 2 && pipeline.commands.length <= 5) {
@@ -43168,7 +42896,7 @@ unsigned int ${ident}_len = ${view.byteLength};
43168
42896
  if (cmd0HereStringRedir && w0Plain0 === "cat" && cmd0.words.length !== 1) return void 0;
43169
42897
  if (!cmd0StdinRedir && !cmd0HereStringRedir && w0Plain0 === "cat" && cmd0.words.length < 2) return void 0;
43170
42898
  const def0 = this.commands.get(w0Plain0);
43171
- if (!def0 || (w0Plain0 === "printf" ? def0.execute !== printfCommand.execute : w0Plain0 === "echo" ? !defaultEchoExecutors.has(def0.execute) : w0Plain0 === "cat" || w0Plain0 === "seq" || cmd0YesStage || cmd0SysStage || cmd0StdinRedir || cmd0HereStringRedir || cmd0FileStage ? w0Plain0 !== "rev" && w0Plain0 !== "tac" && w0Plain0 !== "nl" && w0Plain0 !== "paste" && w0Plain0 !== "comm" && w0Plain0 !== "join" && w0Plain0 !== "jq" && w0Plain0 !== "strings" && w0Plain0 !== "bc" && w0Plain0 !== "factor" && w0Plain0 !== "tsort" && w0Plain0 !== "envsubst" && w0Plain0 !== "xxd" && w0Plain0 !== "od" && w0Plain0 !== "hexdump" && w0Plain0 !== "hd" && w0Plain0 !== "fmt" && w0Plain0 !== "md5sum" && w0Plain0 !== "sha1sum" && w0Plain0 !== "sha224sum" && w0Plain0 !== "sha256sum" && w0Plain0 !== "sha384sum" && w0Plain0 !== "sha512sum" && w0Plain0 !== "cksum" && w0Plain0 !== "base32" && w0Plain0 !== "base64" && w0Plain0 !== "csvcut" && w0Plain0 !== "csvgrep" && w0Plain0 !== "dos2unix" && w0Plain0 !== "unix2dos" && w0Plain0 !== "iconv" && w0Plain0 !== "gzip" && w0Plain0 !== "gunzip" && w0Plain0 !== "zcat" && w0Plain0 !== "unzstd" && w0Plain0 !== "zstdcat" && w0Plain0 !== "htmlq" && w0Plain0 !== "xmllint" && w0Plain0 !== "xq" && w0Plain0 !== "yq" && w0Plain0 !== "mdq" && w0Plain0 !== "shuf" && w0Plain0 !== "html-to-markdown" && w0Plain0 !== "unrtf" && w0Plain0 !== "pr" && w0Plain0 !== "file" && w0Plain0 !== "diff3" && w0Plain0 !== "cmp" && w0Plain0 !== "which" && w0Plain0 !== "diff" && w0Plain0 !== "xan" && w0Plain0 !== "less" && w0Plain0 !== "more" && w0Plain0 !== "df" && w0Plain0 !== "du" && w0Plain0 !== "tree" && w0Plain0 !== "stat" && w0Plain0 !== "fd" && w0Plain0 !== "rg" && w0Plain0 !== "readlink" && w0Plain0 !== "realpath" && w0Plain0 !== "ls" && w0Plain0 !== "find" && w0Plain0 !== "csvlook" && w0Plain0 !== "csvjson" && w0Plain0 !== "csvsort" && w0Plain0 !== "csvformat" && w0Plain0 !== "csvstat" && w0Plain0 !== "in2csv" && w0Plain0 !== "csvstack" && w0Plain0 !== "csvjoin" && w0Plain0 !== "dd" && w0Plain0 !== "env" && w0Plain0 !== "xargs" && w0Plain0 !== "openssl" && w0Plain0 !== "sqlite3" && w0Plain0 !== "gpg" && w0Plain0 !== "ssh" && w0Plain0 !== "ssh-keygen" && w0Plain0 !== "pdfinfo" && w0Plain0 !== "pdffonts" && w0Plain0 !== "pdftotext" && w0Plain0 !== "pdftohtml" && w0Plain0 !== "exiftool" && w0Plain0 !== "qpdf" && w0Plain0 !== "pdftk" && w0Plain0 !== "sips" && w0Plain0 !== "identify" && w0Plain0 !== "magick" && w0Plain0 !== "convert" && w0Plain0 !== "pdfimages" && w0Plain0 !== "pdfdetach" && w0Plain0 !== "ffprobe" && w0Plain0 !== "ffmpeg" && w0Plain0 !== "gh" && w0Plain0 !== "pdftoppm" && w0Plain0 !== "pdftocairo" && w0Plain0 !== "mmdc" && w0Plain0 !== "pandoc" && w0Plain0 !== "soffice" && w0Plain0 !== "libreoffice" && w0Plain0 !== "ssconvert" && w0Plain0 !== "wkhtmltopdf" && w0Plain0 !== "op" && w0Plain0 !== "date" && w0Plain0 !== "printenv" && w0Plain0 !== "egrep" && w0Plain0 !== "fgrep" && w0Plain0 !== "yes" && w0Plain0 !== "cal" && w0Plain0 !== "ncal" && w0Plain0 !== "expr" && w0Plain0 !== "getopt" && w0Plain0 !== "pathchk" && !builtInDirectContextExecutors.has(def0.execute) : customRegisteredCommands.has(def0.execute) || customRegisteredRegistries.has(this.commands))) return void 0;
42899
+ if (!def0 || (w0Plain0 === "printf" ? def0.execute !== printfCommand.execute : w0Plain0 === "echo" ? !defaultEchoExecutors.has(def0.execute) : w0Plain0 === "cat" || w0Plain0 === "seq" || cmd0YesStage || cmd0SysStage || cmd0StdinRedir || cmd0HereStringRedir || cmd0FileStage ? w0Plain0 !== "rev" && w0Plain0 !== "tac" && w0Plain0 !== "nl" && w0Plain0 !== "paste" && w0Plain0 !== "comm" && w0Plain0 !== "join" && w0Plain0 !== "jq" && w0Plain0 !== "strings" && w0Plain0 !== "bc" && w0Plain0 !== "factor" && w0Plain0 !== "tsort" && w0Plain0 !== "envsubst" && w0Plain0 !== "xxd" && w0Plain0 !== "od" && w0Plain0 !== "hexdump" && w0Plain0 !== "hd" && w0Plain0 !== "fmt" && w0Plain0 !== "md5sum" && w0Plain0 !== "sha1sum" && w0Plain0 !== "sha224sum" && w0Plain0 !== "sha256sum" && w0Plain0 !== "sha384sum" && w0Plain0 !== "sha512sum" && w0Plain0 !== "cksum" && w0Plain0 !== "base32" && w0Plain0 !== "base64" && w0Plain0 !== "csvcut" && w0Plain0 !== "csvgrep" && w0Plain0 !== "dos2unix" && w0Plain0 !== "unix2dos" && w0Plain0 !== "iconv" && w0Plain0 !== "gzip" && w0Plain0 !== "gunzip" && w0Plain0 !== "zcat" && w0Plain0 !== "unzstd" && w0Plain0 !== "zstdcat" && w0Plain0 !== "htmlq" && w0Plain0 !== "xmllint" && w0Plain0 !== "xq" && w0Plain0 !== "yq" && w0Plain0 !== "mdq" && w0Plain0 !== "shuf" && w0Plain0 !== "html-to-markdown" && w0Plain0 !== "unrtf" && w0Plain0 !== "pr" && w0Plain0 !== "file" && w0Plain0 !== "diff3" && w0Plain0 !== "cmp" && w0Plain0 !== "which" && w0Plain0 !== "diff" && w0Plain0 !== "xan" && w0Plain0 !== "less" && w0Plain0 !== "more" && w0Plain0 !== "df" && w0Plain0 !== "du" && w0Plain0 !== "tree" && w0Plain0 !== "stat" && w0Plain0 !== "fd" && w0Plain0 !== "rg" && w0Plain0 !== "readlink" && w0Plain0 !== "realpath" && w0Plain0 !== "ls" && w0Plain0 !== "find" && w0Plain0 !== "csvlook" && w0Plain0 !== "csvjson" && w0Plain0 !== "csvsort" && w0Plain0 !== "csvformat" && w0Plain0 !== "csvstat" && w0Plain0 !== "in2csv" && w0Plain0 !== "csvstack" && w0Plain0 !== "csvjoin" && w0Plain0 !== "dd" && w0Plain0 !== "env" && w0Plain0 !== "xargs" && w0Plain0 !== "openssl" && w0Plain0 !== "sqlite3" && w0Plain0 !== "gpg" && w0Plain0 !== "ssh" && w0Plain0 !== "ssh-keygen" && w0Plain0 !== "pdfinfo" && w0Plain0 !== "pdffonts" && w0Plain0 !== "pdftotext" && w0Plain0 !== "pdftohtml" && w0Plain0 !== "exiftool" && w0Plain0 !== "qpdf" && w0Plain0 !== "pdftk" && w0Plain0 !== "sips" && w0Plain0 !== "identify" && w0Plain0 !== "magick" && w0Plain0 !== "convert" && w0Plain0 !== "pdfimages" && w0Plain0 !== "pdfdetach" && w0Plain0 !== "ffprobe" && w0Plain0 !== "ffmpeg" && w0Plain0 !== "gh" && w0Plain0 !== "pdftoppm" && w0Plain0 !== "pdftocairo" && w0Plain0 !== "mmdc" && w0Plain0 !== "pandoc" && w0Plain0 !== "soffice" && w0Plain0 !== "libreoffice" && w0Plain0 !== "ssconvert" && w0Plain0 !== "wkhtmltopdf" && w0Plain0 !== "op" && w0Plain0 !== "date" && w0Plain0 !== "printenv" && w0Plain0 !== "egrep" && w0Plain0 !== "fgrep" && w0Plain0 !== "yes" && w0Plain0 !== "cal" && w0Plain0 !== "ncal" && w0Plain0 !== "expr" && w0Plain0 !== "getopt" && w0Plain0 !== "pathchk" && !builtInDirectContextExecutors2.has(def0.execute) : customRegisteredCommands.has(def0.execute) || customRegisteredRegistries.has(this.commands))) return void 0;
43172
42900
  if (!this.arePureArgWords(cmd0.words, rawState)) return void 0;
43173
42901
  const n = pipeline.commands.length;
43174
42902
  const stageDefs = [];
@@ -43181,8 +42909,8 @@ unsigned int ${ident}_len = ${view.byteLength};
43181
42909
  const sName = sCmd.words[0].plain;
43182
42910
  if (!sName || hasShellFunction(rawState, sName) || rawState.extensions?.builtins.has(sName)) return void 0;
43183
42911
  const extDef = this.commands.get(sName);
43184
- if (!extDef || (sName !== "cat" || startStageIdx === 0) && sName !== "rev" && sName !== "tac" && sName !== "nl" && sName !== "paste" && sName !== "column" && sName !== "fold" && sName !== "expand" && sName !== "unexpand" && sName !== "strings" && sName !== "comm" && sName !== "join" && sName !== "jq" && sName !== "bc" && sName !== "factor" && sName !== "tsort" && sName !== "envsubst" && sName !== "xxd" && sName !== "od" && sName !== "hexdump" && sName !== "hd" && sName !== "fmt" && sName !== "md5sum" && sName !== "sha1sum" && sName !== "sha224sum" && sName !== "sha256sum" && sName !== "sha384sum" && sName !== "sha512sum" && sName !== "cksum" && sName !== "base32" && sName !== "base64" && sName !== "csvcut" && sName !== "csvgrep" && sName !== "dos2unix" && sName !== "unix2dos" && sName !== "iconv" && sName !== "gzip" && sName !== "gunzip" && sName !== "zcat" && sName !== "unzstd" && sName !== "zstdcat" && sName !== "htmlq" && sName !== "xmllint" && sName !== "xq" && sName !== "yq" && sName !== "mdq" && sName !== "shuf" && sName !== "html-to-markdown" && sName !== "unrtf" && sName !== "pr" && sName !== "file" && sName !== "diff3" && sName !== "cmp" && sName !== "which" && sName !== "diff" && sName !== "xan" && sName !== "less" && sName !== "more" && sName !== "df" && sName !== "du" && sName !== "tree" && sName !== "stat" && sName !== "fd" && sName !== "rg" && sName !== "readlink" && sName !== "realpath" && sName !== "ls" && sName !== "find" && sName !== "csvlook" && sName !== "csvjson" && sName !== "csvsort" && sName !== "csvformat" && sName !== "csvstat" && sName !== "in2csv" && sName !== "csvstack" && sName !== "csvjoin" && sName !== "dd" && sName !== "xargs" && sName !== "openssl" && sName !== "sqlite3" && sName !== "gpg" && sName !== "ssh" && sName !== "ssh-keygen" && sName !== "pdfinfo" && sName !== "pdffonts" && sName !== "pdftotext" && sName !== "pdftohtml" && sName !== "exiftool" && sName !== "qpdf" && sName !== "pdftk" && sName !== "sips" && sName !== "identify" && sName !== "magick" && sName !== "convert" && sName !== "pdfimages" && sName !== "pdfdetach" && sName !== "ffprobe" && sName !== "ffmpeg" && sName !== "gh" && sName !== "pdftoppm" && sName !== "pdftocairo" && sName !== "mmdc" && sName !== "pandoc" && sName !== "soffice" && sName !== "libreoffice" && sName !== "ssconvert" && sName !== "wkhtmltopdf" && sName !== "op" && sName !== "date" && sName !== "cal" && sName !== "ncal" && sName !== "getopt" && sName !== "pathchk" && sName !== "printenv" && sName !== "env" && sName !== "egrep" && sName !== "fgrep" && !builtInDirectContextExecutors.has(extDef.execute) || customRegisteredCommands.has(extDef.execute)) return void 0;
43185
- if ((sName === "xxd" || sName === "od") && !builtInDirectContextExecutors.has(extDef.execute)) return void 0;
42912
+ if (!extDef || (sName !== "cat" || startStageIdx === 0) && sName !== "rev" && sName !== "tac" && sName !== "nl" && sName !== "paste" && sName !== "column" && sName !== "fold" && sName !== "expand" && sName !== "unexpand" && sName !== "strings" && sName !== "comm" && sName !== "join" && sName !== "jq" && sName !== "bc" && sName !== "factor" && sName !== "tsort" && sName !== "envsubst" && sName !== "xxd" && sName !== "od" && sName !== "hexdump" && sName !== "hd" && sName !== "fmt" && sName !== "md5sum" && sName !== "sha1sum" && sName !== "sha224sum" && sName !== "sha256sum" && sName !== "sha384sum" && sName !== "sha512sum" && sName !== "cksum" && sName !== "base32" && sName !== "base64" && sName !== "csvcut" && sName !== "csvgrep" && sName !== "dos2unix" && sName !== "unix2dos" && sName !== "iconv" && sName !== "gzip" && sName !== "gunzip" && sName !== "zcat" && sName !== "unzstd" && sName !== "zstdcat" && sName !== "htmlq" && sName !== "xmllint" && sName !== "xq" && sName !== "yq" && sName !== "mdq" && sName !== "shuf" && sName !== "html-to-markdown" && sName !== "unrtf" && sName !== "pr" && sName !== "file" && sName !== "diff3" && sName !== "cmp" && sName !== "which" && sName !== "diff" && sName !== "xan" && sName !== "less" && sName !== "more" && sName !== "df" && sName !== "du" && sName !== "tree" && sName !== "stat" && sName !== "fd" && sName !== "rg" && sName !== "readlink" && sName !== "realpath" && sName !== "ls" && sName !== "find" && sName !== "csvlook" && sName !== "csvjson" && sName !== "csvsort" && sName !== "csvformat" && sName !== "csvstat" && sName !== "in2csv" && sName !== "csvstack" && sName !== "csvjoin" && sName !== "dd" && sName !== "xargs" && sName !== "openssl" && sName !== "sqlite3" && sName !== "gpg" && sName !== "ssh" && sName !== "ssh-keygen" && sName !== "pdfinfo" && sName !== "pdffonts" && sName !== "pdftotext" && sName !== "pdftohtml" && sName !== "exiftool" && sName !== "qpdf" && sName !== "pdftk" && sName !== "sips" && sName !== "identify" && sName !== "magick" && sName !== "convert" && sName !== "pdfimages" && sName !== "pdfdetach" && sName !== "ffprobe" && sName !== "ffmpeg" && sName !== "gh" && sName !== "pdftoppm" && sName !== "pdftocairo" && sName !== "mmdc" && sName !== "pandoc" && sName !== "soffice" && sName !== "libreoffice" && sName !== "ssconvert" && sName !== "wkhtmltopdf" && sName !== "op" && sName !== "date" && sName !== "cal" && sName !== "ncal" && sName !== "getopt" && sName !== "pathchk" && sName !== "printenv" && sName !== "env" && sName !== "egrep" && sName !== "fgrep" && !builtInDirectContextExecutors2.has(extDef.execute) || customRegisteredCommands.has(extDef.execute)) return void 0;
42913
+ if ((sName === "xxd" || sName === "od") && !builtInDirectContextExecutors2.has(extDef.execute)) return void 0;
43186
42914
  if (!this.arePureArgWords(sCmd.words, rawState)) return void 0;
43187
42915
  const sArgs = [];
43188
42916
  for (let w = 1; w < sCmd.words.length; w++) {
@@ -43405,8 +43133,6 @@ unsigned int ${ident}_len = ${view.byteLength};
43405
43133
  syncPurePipelineSlotInUse = true;
43406
43134
  this.budget.enterPipelineStages(n);
43407
43135
  this.budget.commands += n;
43408
- const scope = io[invocationScope];
43409
- let context = pooledSyncPipeContext;
43410
43136
  let prevBuf = sharedSyncPipeBuf0;
43411
43137
  let prevLen = fastSharedTextEncoder.encodeInto(stage0Formatted, sharedSyncPipeBuf0).written;
43412
43138
  try {
@@ -44024,35 +43750,7 @@ unsigned int ${ident}_len = ${view.byteLength};
44024
43750
  prevLen = written;
44025
43751
  continue;
44026
43752
  }
44027
- sharedSyncPipeReader.reset(prevBuf, prevLen, this.signal, -1);
44028
- sharedSyncPipeWriter.reset(this.budget, this.signal, nextBuf, -1);
44029
- if (!context) {
44030
- context = new FastShellCommandContext(this, rawState, io, scope, firstName, stageArgs, void 0, void 0, true);
44031
- pooledSyncPipeContext = context;
44032
- }
44033
- context.resetDirectStage(this, rawState, io, scope, firstName, stageArgs, sharedSyncPipeReader, false, sharedSyncPipeWriter, this.signal);
44034
- sharedSyncPipeReader.abortSignal = context.signal;
44035
- scope.enterWork();
44036
- this.budget.beginPathLookupSuspension();
44037
- let resPromise;
44038
- try {
44039
- resPromise = extDef.execute(context);
44040
- } finally {
44041
- this.budget.endPathLookupSuspension();
44042
- scope.leaveWork();
44043
- }
44044
- if (resPromise !== RESOLVED_EXIT_ZERO) {
44045
- if (resPromise && typeof resPromise.catch === "function") {
44046
- resPromise.catch(() => {
44047
- });
44048
- }
44049
- pooledSyncPipeContext = void 0;
44050
- context = void 0;
44051
- return void 0;
44052
- }
44053
- this.signal.throwIfAborted();
44054
- prevBuf = nextBuf;
44055
- prevLen = sharedSyncPipeWriter.used;
43753
+ return void 0;
44056
43754
  }
44057
43755
  if (prevBuf.subarray(0, prevLen).includes(0)) return void 0;
44058
43756
  completed = true;
@@ -44061,11 +43759,6 @@ unsigned int ${ident}_len = ${view.byteLength};
44061
43759
  this.budget.bytes = previousBytes;
44062
43760
  this.budget.commands = previousCommands;
44063
43761
  }
44064
- if (context) context.releaseDirectStage();
44065
- sharedSyncPipeWriter.budget = void 0;
44066
- sharedSyncPipeWriter.signal = void 0;
44067
- sharedSyncPipeWriter.target = EMPTY_BYTES;
44068
- sharedSyncPipeReader.reset(EMPTY_BYTES, 0);
44069
43762
  syncPurePipelineSlotInUse = false;
44070
43763
  this.budget.leavePipelineStages(n);
44071
43764
  }
@@ -44139,13 +43832,13 @@ unsigned int ${ident}_len = ${view.byteLength};
44139
43832
  if (w0Plain === "fmt" && !hasSingleStdinRedir && !hasSingleHereStringRedir && !io.stdinIsDefault) return void 0;
44140
43833
  if (w0Plain === "xxd" || w0Plain === "od" || w0Plain === "mktemp" || w0Plain === "chmod" || w0Plain === "uname" || w0Plain === "nproc" || w0Plain === "hostname" || w0Plain === "id" || w0Plain === "whoami") {
44141
43834
  const definition = this.commands.get(w0Plain);
44142
- if (!definition || !builtInDirectContextExecutors.has(definition.execute)) return void 0;
43835
+ if (!definition || !builtInDirectContextExecutors2.has(definition.execute)) return void 0;
44143
43836
  }
44144
43837
  if (cmd.words.length === 2 && cmd.redirects.length === 0 && (cmd.words[1]?.plain === "--help" || cmd.words[1]?.plain === "--version")) {
44145
43838
  const gnuInfo = gnuInformationSync(w0Plain, [cmd.words[1].plain], false, (rawState.exported.has("POSIXLY_CORRECT") || rawState.allexport) && rawState.variables.POSIXLY_CORRECT !== void 0);
44146
43839
  if (gnuInfo !== void 0) {
44147
43840
  const extDef = this.commands.get(w0Plain);
44148
- if (!extDef || !builtInDirectContextExecutors.has(extDef.execute)) return void 0;
43841
+ if (!extDef || !builtInDirectContextExecutors2.has(extDef.execute)) return void 0;
44149
43842
  return gnuInfo.replace(/\n+$/, "");
44150
43843
  }
44151
43844
  }
@@ -45751,8 +45444,8 @@ unsigned int ${ident}_len = ${view.byteLength};
45751
45444
  if (!def) return void 0;
45752
45445
  if (w0Plain === "printf" && def.execute !== printfCommand.execute) return void 0;
45753
45446
  if (w0Plain === "echo" && !defaultEchoExecutors.has(def.execute)) return void 0;
45754
- if ((w0Plain === "dirname" || w0Plain === "basename") && (!builtInDirectContextExecutors.has(def.execute) || customRegisteredCommands.has(def.execute))) return void 0;
45755
- if (w0Plain === "seq" && !builtInDirectContextExecutors.has(def.execute) && (customRegisteredCommands.has(def.execute) || customRegisteredRegistries.has(this.commands))) return void 0;
45447
+ if ((w0Plain === "dirname" || w0Plain === "basename") && (!builtInDirectContextExecutors2.has(def.execute) || customRegisteredCommands.has(def.execute))) return void 0;
45448
+ if (w0Plain === "seq" && !builtInDirectContextExecutors2.has(def.execute) && (customRegisteredCommands.has(def.execute) || customRegisteredRegistries.has(this.commands))) return void 0;
45756
45449
  if (cmd.words.length > this.budget.maxExpansionFieldsSmi && cmd.words.length > this.budget.limits.maxExpansionFields) return void 0;
45757
45450
  for (let i = 0; i < cmd.words.length; i++) {
45758
45451
  if (!this.isPureArgWord(cmd.words[i], rawState)) return void 0;
@@ -46535,6 +46228,7 @@ unsigned int ${ident}_len = ${view.byteLength};
46535
46228
  }
46536
46229
  }
46537
46230
  await sortExpansionStrings(found, work, true);
46231
+ if (!found.length && state.failglob) throw new FailglobFailure(`no match: ${value}`);
46538
46232
  return found.length ? found : state.nullglob ? [] : [value];
46539
46233
  } finally {
46540
46234
  scratch.close();
@@ -46615,6 +46309,7 @@ unsigned int ${ident}_len = ${view.byteLength};
46615
46309
  exhausted: () => this.budget.fail("maxExpansionBytes")
46616
46310
  };
46617
46311
  await sortExpansionStrings(found, sortingWork, true);
46312
+ if (!found.length && state.failglob) throw new FailglobFailure(`no match: ${value}`);
46618
46313
  return found.length ? found : state.nullglob ? [] : [value];
46619
46314
  }
46620
46315
  };
@@ -46653,6 +46348,7 @@ var RootShellState = class {
46653
46348
  this.substitutionStatus = 0;
46654
46349
  this.lastArgument = "";
46655
46350
  this.secondsOrigin = Date.now();
46351
+ this.processSubstitutionIds = { next: 0 };
46656
46352
  }
46657
46353
  get exported() {
46658
46354
  const raw = stateMonitor(this)?.raw;
@@ -46769,6 +46465,10 @@ function captureShellSessionState(state, exitCode) {
46769
46465
  dotglob: Boolean(state.dotglob),
46770
46466
  globstar: Boolean(state.globstar),
46771
46467
  nullglob: Boolean(state.nullglob),
46468
+ failglob: Boolean(state.failglob),
46469
+ lastpipe: Boolean(state.lastpipe),
46470
+ inherit_errexit: Boolean(state.inherit_errexit),
46471
+ expand_aliases: Boolean(state.expand_aliases),
46772
46472
  nocaseglob: Boolean(state.nocaseglob),
46773
46473
  nocasematch: Boolean(state.nocasematch),
46774
46474
  extglob: Boolean(state.extglob),
@@ -46782,6 +46482,7 @@ function captureShellSessionState(state, exitCode) {
46782
46482
  nounset: Boolean(state.nounset)
46783
46483
  };
46784
46484
  const snapshot = {
46485
+ aliases: Object.fromEntries(state.aliases ?? []),
46785
46486
  cwd: state.cwd,
46786
46487
  umask: state.umask ?? 18,
46787
46488
  variables,
@@ -46802,6 +46503,17 @@ function captureShellSessionState(state, exitCode) {
46802
46503
  async function restoreShellSessionState(state, snapshot, explicitOptions, budget, scope, syntax) {
46803
46504
  const resolvedCwd = explicitOptions.cwd !== void 0 ? resolvePath("/", explicitOptions.cwd) : resolvePath("/", snapshot.cwd || "/");
46804
46505
  state.cwd = resolvedCwd;
46506
+ if (snapshot.aliases) {
46507
+ let bytes = 0;
46508
+ const aliases = /* @__PURE__ */ new Map();
46509
+ for (const [name2, value] of Object.entries(snapshot.aliases)) {
46510
+ budget.signal.throwIfAborted();
46511
+ bytes += shellValueByteLength(name2) + shellValueByteLength(value);
46512
+ if (bytes > budget.limits.maxExpansionBytes) budget.fail("maxExpansionBytes");
46513
+ aliases.set(name2, value);
46514
+ }
46515
+ state.aliases = aliases;
46516
+ }
46805
46517
  if (typeof snapshot.umask === "number") {
46806
46518
  state.umask = snapshot.umask & 511;
46807
46519
  }
@@ -46880,6 +46592,10 @@ async function restoreShellSessionState(state, snapshot, explicitOptions, budget
46880
46592
  if (opts.dotglob !== void 0) state.dotglob = opts.dotglob;
46881
46593
  if (opts.globstar !== void 0) state.globstar = opts.globstar;
46882
46594
  if (opts.nullglob !== void 0) state.nullglob = opts.nullglob;
46595
+ if (opts.failglob !== void 0) state.failglob = opts.failglob;
46596
+ if (opts.lastpipe !== void 0) state.lastpipe = opts.lastpipe;
46597
+ if (opts.inherit_errexit !== void 0) state.inherit_errexit = opts.inherit_errexit;
46598
+ if (opts.expand_aliases !== void 0) state.expand_aliases = opts.expand_aliases;
46883
46599
  if (opts.nocaseglob !== void 0) state.nocaseglob = opts.nocaseglob;
46884
46600
  if (opts.nocasematch !== void 0) state.nocasematch = opts.nocasematch;
46885
46601
  if (opts.extglob !== void 0) state.extglob = opts.extglob;
@@ -46947,23 +46663,6 @@ async function restoreShellSessionState(state, snapshot, explicitOptions, budget
46947
46663
  }
46948
46664
 
46949
46665
  // packages/safe-bash/src/shell/shell.ts
46950
- function utf8ByteLength(str) {
46951
- if (typeof globalThis.Buffer === "function") return globalThis.Buffer.byteLength(str);
46952
- let bytes = str.length;
46953
- for (let i = 0; i < str.length; i++) {
46954
- const code = str.charCodeAt(i);
46955
- if (code >= 128) {
46956
- if (code <= 2047) bytes += 1;
46957
- else if (code >= 55296 && code <= 56319 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) === 56320) {
46958
- bytes += 2;
46959
- i++;
46960
- } else {
46961
- bytes += 2;
46962
- }
46963
- }
46964
- }
46965
- return bytes;
46966
- }
46967
46666
  var EMPTY_CAPTURED_EXTENSIONS = captureShellExtensions([]);
46968
46667
  var sharedUtf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });
46969
46668
  var sharedUtf8Encoder = new TextEncoder();
@@ -47003,26 +46702,28 @@ var EMPTY_STDIN_OPTIONS = Object.freeze({
47003
46702
  });
47004
46703
  var EMPTY_EXEC_OPTIONS = Object.freeze({});
47005
46704
  var EMPTY_STDOUT_BYTES = new Uint8Array(0);
47006
- var warmSyncExecJitWarmed = false;
47007
- var parsedSourceCache = /* @__PURE__ */ new Map();
47008
- var lastSourceCacheKey = "";
47009
- var lastSourceCacheVal;
47010
- function getSourceParseCache(source) {
47011
- if (source === lastSourceCacheKey && lastSourceCacheVal !== void 0) return lastSourceCacheVal;
47012
- let entry = parsedSourceCache.get(source);
47013
- if (!entry) {
47014
- if (parsedSourceCache.size >= 64) {
47015
- const oldest = parsedSourceCache.keys().next().value;
47016
- if (oldest !== void 0) parsedSourceCache.delete(oldest);
47017
- }
47018
- entry = { byteLength: utf8ByteLength(source) };
47019
- parsedSourceCache.set(source, entry);
47020
- }
47021
- lastSourceCacheKey = source;
47022
- lastSourceCacheVal = entry;
47023
- return entry;
46705
+ function syntaxDiagnostic(source, error) {
46706
+ const line = source.slice(0, error.offset).split("\n").length;
46707
+ if (error.unclosedQuote) {
46708
+ return `shell: -c: line ${error.unclosedQuote.line}: unexpected EOF while looking for matching \`${error.unclosedQuote.quote}'
46709
+ `;
46710
+ }
46711
+ if (error.exitCode === 127) {
46712
+ const token = /^[;&|()<>]|^[^\s;&|()<>]+/u.exec(source.slice(error.offset))?.[0] ?? "newline";
46713
+ return `shell: -c: line ${line}: syntax error near unexpected token \`${token}'
46714
+ shell: -c: line ${line}: \`${source.split("\n")[line - 1] ?? ""}'
46715
+ `;
46716
+ }
46717
+ if (error.offset >= source.length && !/Unterminated|nesting|Unsupported/u.test(error.reason)) {
46718
+ const context = error.incompleteCommand ? ` from \`${error.incompleteCommand.name}' command on line ${error.incompleteCommand.line}` : "";
46719
+ return `shell: -c: line ${source.split("\n").length + Number(!source.endsWith("\n"))}: syntax error: unexpected end of file${context}
46720
+ `;
46721
+ }
46722
+ return `shell: ${error.message}
46723
+ `;
47024
46724
  }
47025
- function getOrParseUnitFromCache(source, offset, unitLocale, sourceCache, parseState, budget, syntax) {
46725
+ function getOrParseUnitFromCache(source, offset, unitLocale, sourceCache, parseState, budget, syntax, aliases) {
46726
+ if (aliases?.size) sourceCache = void 0;
47026
46727
  let cached;
47027
46728
  if (sourceCache !== void 0) {
47028
46729
  if (offset === 0) {
@@ -47048,7 +46749,7 @@ function getOrParseUnitFromCache(source, offset, unitLocale, sourceCache, parseS
47048
46749
  parseState.lineIndexUnits = budget.parsing.admittedUnits - beforeLineIdx;
47049
46750
  }
47050
46751
  const beforeParse = budget.parsing.admittedUnits;
47051
- const parsed = parseShellUnit(source, offset, unitLocale, budget.parsing, parseState.lineIndex, void 0, false, syntax);
46752
+ const parsed = parseShellUnit(source, offset, unitLocale, budget.parsing, parseState.lineIndex, void 0, false, syntax, aliases);
47052
46753
  const parseUnits = budget.parsing.admittedUnits - beforeParse;
47053
46754
  const unitsCharged = (offset === 0 ? parseState.lineIndexUnits : 0) + parseUnits;
47054
46755
  if (sourceCache !== void 0 && (!parsed.script.warnings || parsed.script.warnings.length === 0)) {
@@ -47214,11 +46915,12 @@ function createInvocationSink(budget, capture, external) {
47214
46915
  }
47215
46916
  });
47216
46917
  }
47217
- var Shell = class _Shell {
46918
+ var Shell = class {
47218
46919
  commands;
47219
46920
  #middleware = [];
47220
46921
  #filesystems = /* @__PURE__ */ new Map();
47221
46922
  #plugins = [];
46923
+ #processSubstitutionIds = { next: 0 };
47222
46924
  #capabilities = {};
47223
46925
  #options;
47224
46926
  #resolvedLimits;
@@ -47235,10 +46937,36 @@ var Shell = class _Shell {
47235
46937
  #singleActiveOwner;
47236
46938
  #active;
47237
46939
  #warmedInvocation;
46940
+ #parsedSourceCache = /* @__PURE__ */ new Map();
46941
+ #getSourceParseCache(source) {
46942
+ let entry = this.#parsedSourceCache.get(source);
46943
+ if (!entry) {
46944
+ if (this.#parsedSourceCache.size >= 64) {
46945
+ const oldest = this.#parsedSourceCache.keys().next().value;
46946
+ if (oldest !== void 0) this.#parsedSourceCache.delete(oldest);
46947
+ }
46948
+ entry = { byteLength: utf8ByteLength(source) };
46949
+ this.#parsedSourceCache.set(source, entry);
46950
+ }
46951
+ return entry;
46952
+ }
47238
46953
  constructor(options) {
47239
46954
  if (!options?.fs) throw new TypeError("Shell requires an explicit filesystem");
47240
46955
  if (options.deviceView !== void 0 && options.deviceView !== "default" && options.deviceView !== "provided") throw new TypeError("deviceView must be default or provided");
47241
- const commands = options.commands ?? new CommandRegistry();
46956
+ const onRegister = (command) => {
46957
+ this.#clearWarmedInvocation();
46958
+ if (!builtInDirectContextExecutors.has(command.execute)) {
46959
+ this.#hasCustomCommands = true;
46960
+ customRegisteredCommands.add(command.execute);
46961
+ }
46962
+ };
46963
+ const commands = options.commands ?? new class extends CommandRegistry {
46964
+ register(command, options2) {
46965
+ super.register(command, options2);
46966
+ onRegister(command);
46967
+ return this;
46968
+ }
46969
+ }();
47242
46970
  if (!(commands instanceof CommandRegistry)) throw new TypeError("CommandRegistry requires its matching shell runtime; do not mix source and compiled runtime modules");
47243
46971
  if (options.commands) {
47244
46972
  this.#hasCustomCommands = true;
@@ -47309,6 +47037,7 @@ var Shell = class _Shell {
47309
47037
  }
47310
47038
  register(command, options) {
47311
47039
  if (this.#disposed) throw new Error("Shell is disposed");
47040
+ this.#clearWarmedInvocation();
47312
47041
  this.#hasCustomCommands = true;
47313
47042
  if (command && typeof command.execute === "function") customRegisteredCommands.add(command.execute);
47314
47043
  this.commands.register(command, options);
@@ -47359,76 +47088,15 @@ var Shell = class _Shell {
47359
47088
  void warm.stdin.close();
47360
47089
  warm.budget.close();
47361
47090
  void warm.scope.close();
47091
+ warm.owner.finish({ kind: "return", value: void 0 });
47362
47092
  warm.cancellationState.close();
47363
47093
  }
47364
47094
  #isDefaultExecOptions(options, currentScope) {
47365
47095
  return options.signal === void 0 && options.limits === void 0 && options.onInternalError === void 0 && options.stdin === void 0 && options.stdout === void 0 && options.stderr === void 0 && options.env === void 0 && options.cwd === void 0 && options.state === void 0 && options.onState === void 0 && options.hooks === void 0 && options.capabilities === void 0 && options.admittedHandles === void 0 && options.processSignals === void 0 && options.fs === void 0 && !this.#hasCustomCommands && this.#middleware.length === 0 && (!this.#options.extensions || this.#options.extensions.length === 0) && this.#options.hooks === void 0 && !this.#hasInitialEnv && isSyncResolved(this.#ready) && (!this.#singleActiveScope || this.#singleActiveScope === currentScope) && !this.#active;
47366
47096
  }
47367
- static #enginePrewarmed = false;
47368
- async #prewarmIsolatedSandbox() {
47369
- if (_Shell.#enginePrewarmed) return;
47370
- _Shell.#enginePrewarmed = true;
47371
- await this.#ready;
47372
- if (!this.commands.get("rg") || !this.commands.get("jq") || !this.commands.get("awk")) {
47373
- _Shell.#enginePrewarmed = false;
47374
- return;
47375
- }
47376
- try {
47377
- const enc = new TextEncoder();
47378
- const dBytes = enc.encode(Array.from({ length: 120 }, (_, i) => `${i % 3 === 0 ? "alpha" : i % 3 === 1 ? "beta" : "gamma"}:val_${i * 17 % 97}:${i}
47379
- `).join(""));
47380
- const jBytes = enc.encode(Array.from({ length: 60 }, (_, i) => `{"id":${i},"active":${i % 2 === 0},"score":${i * 7 % 100},"tag":"t_${i % 10}"}
47381
- `).join(""));
47382
- const sandboxFs = new MemoryFileSystem();
47383
- await sandboxFs.writeFile("/data.txt", dBytes);
47384
- await sandboxFs.writeFile("/items.jsonl", jBytes);
47385
- for (let d = 0; d < 2; d++) {
47386
- await sandboxFs.mkdir(`/src/pkg_${d}`, { recursive: true });
47387
- for (let f = 0; f < 2; f++) {
47388
- await sandboxFs.writeFile(`/src/pkg_${d}/mod_${f}.ts`, enc.encode(Array.from({ length: 20 }, (_, l) => `export const v_${d}_${f}_${l} = "${(d + f + l) % 11 === 0 ? "NEEDLE_TOKEN" : "normal"}_${l}";
47389
- `).join("")));
47390
- }
47391
- }
47392
- const fsScript = [
47393
- "mkdir -p /work/a /work/b",
47394
- ...Array.from({ length: 12 }, (_, i) => `echo "item_${i}" > /work/a/f_${i}.txt`),
47395
- ...Array.from({ length: 12 }, (_, i) => `echo "item_${i}" >> /work/b/f_${i}.txt`),
47396
- "rm -rf /work/b",
47397
- "find /work/a -name 'f_1*.txt' | wc -l"
47398
- ].join("\n");
47399
- const scripts = [
47400
- "grep '^alpha' /data.txt | cut -d: -f2 | tr 'a-z' 'A-Z' | sort | head -n 5",
47401
- "rg -c NEEDLE_TOKEN /src",
47402
- "sed 's/^alpha:/ALPHA_REPLACED:/g; s/:val_/:VALUE_/g' /data.txt > /out.txt",
47403
- "awk -F: '/^alpha/ { sum += $3; cnt++ } END { print cnt, sum }' /data.txt",
47404
- "jq -c 'select(.active) | {id, score}' /items.jsonl > /filtered.jsonl",
47405
- fsScript,
47406
- "acc=0; i=0; for i in {1..80}; do acc=$((acc + i)); done; echo $acc",
47407
- 'declare -a arr=(); declare -A map=(); fn() { local x="$1"; case "$x" in *0) return 0;; *) return 1;; esac; }; for ((i=0; i<40; i++)); do s="p_m_${i}_s_e"; a="${s#p_}"; b="${a%_e}"; c="${b//_/}"; arr+=("e_$i"); map["k_$i"]=$((i + ${#c})); if [[ "$s" =~ ^p_m_([0-9]+)_s_e$ ]]; then fn "${BASH_REMATCH[1]}"; fi; done'
47408
- ];
47409
- const sandboxShell = new _Shell({ fs: sandboxFs });
47410
- for (const plugin of this.#plugins) {
47411
- sandboxShell.use(plugin);
47412
- }
47413
- for (const s of scripts) {
47414
- const isFs = s === fsScript;
47415
- const isSed = s.startsWith("sed ");
47416
- const isJq = s.startsWith("jq ");
47417
- for (let i = 0; i < 4; i++) {
47418
- if (isFs && i > 0) await sandboxFs.rm("/work", { recursive: true, force: true });
47419
- else if (isSed && i > 0) await sandboxFs.rm("/out.txt", { force: true });
47420
- else if (isJq && i > 0) await sandboxFs.rm("/filtered.jsonl", { force: true });
47421
- await sandboxShell.exec("");
47422
- await sandboxShell.exec(s);
47423
- }
47424
- }
47425
- sandboxShell.#clearWarmedInvocation();
47426
- } catch {
47427
- }
47428
- }
47429
47097
  exec(source, options = EMPTY_EXEC_OPTIONS) {
47430
- if (!this.#disposed && this.#warmedInvocation && typeof source === "string" && source.length <= 16384 && (options === EMPTY_EXEC_OPTIONS || this.#isDefaultExecOptions(options))) {
47431
- const sourceCache = getSourceParseCache(source);
47098
+ if (!this.#disposed && this.#warmedInvocation && typeof source === "string" && source.length > 0 && source.length <= 16384 && (options === EMPTY_EXEC_OPTIONS || this.#isDefaultExecOptions(options))) {
47099
+ const sourceCache = this.#getSourceParseCache(source);
47432
47100
  const firstCached = sourceCache?.first0;
47433
47101
  if (firstCached && (!firstCached.unit.script.warnings || firstCached.unit.script.warnings.length === 0)) {
47434
47102
  return this.#execWarmSyncOrFallback(source, options, sourceCache, firstCached);
@@ -47560,14 +47228,14 @@ var Shell = class _Shell {
47560
47228
  budget.signal.throwIfAborted();
47561
47229
  const vars = currentState.variables;
47562
47230
  const nextLocale = vars.LC_ALL || vars.LC_CTYPE || vars.LANG ? byteLocale(vars) : false;
47563
- if (currentCachedUnit && currentCachedUnit.locale === nextLocale && currentCachedUnit.nextCached !== void 0) {
47231
+ if (!currentState.expand_aliases && currentCachedUnit && currentCachedUnit.locale === nextLocale && currentCachedUnit.nextCached !== void 0) {
47564
47232
  currentCachedUnit = currentCachedUnit.nextCached;
47565
47233
  budget.parsing.admit(currentCachedUnit.unitsCharged);
47566
47234
  unit = currentCachedUnit.unit;
47567
47235
  } else {
47568
47236
  parseState ??= { lineIndex: void 0, lineIndexUnits: 0, currentCachedUnit };
47569
47237
  parseState.currentCachedUnit = currentCachedUnit;
47570
- unit = getOrParseUnitFromCache(source, unit.next, nextLocale, sourceCache, parseState, budget, void 0);
47238
+ unit = getOrParseUnitFromCache(source, unit.next, nextLocale, sourceCache, parseState, budget, void 0, currentState.expand_aliases ? currentState.aliases : void 0);
47571
47239
  currentCachedUnit = parseState.currentCachedUnit;
47572
47240
  }
47573
47241
  if (unit.script.warnings) {
@@ -47591,8 +47259,7 @@ var Shell = class _Shell {
47591
47259
  }
47592
47260
  } catch (error) {
47593
47261
  if (error instanceof ShellSyntaxError) {
47594
- await writeDiagnostic(io.stderr, `shell: ${error.message}
47595
- `);
47262
+ await writeDiagnostic(io.stderr, syntaxDiagnostic(source, error));
47596
47263
  exitCode = error.exitCode;
47597
47264
  } else {
47598
47265
  failed = true;
@@ -47727,18 +47394,6 @@ var Shell = class _Shell {
47727
47394
  }
47728
47395
  if (selection.outcome.kind === "throw") throw selection.outcome.reason;
47729
47396
  if (scope.hasFailures) throwCleanupFailures(scope.failures);
47730
- if (!warmSyncExecJitWarmed && source === "" && this.#warmedInvocation) {
47731
- warmSyncExecJitWarmed = true;
47732
- await this.#prewarmIsolatedSandbox();
47733
- for (let w = 0; w < 24; w++) {
47734
- globalThis.process?.memoryUsage?.();
47735
- performance.now();
47736
- }
47737
- for (let w = 0; w < 16; w++) {
47738
- await this.exec(":", EMPTY_EXEC_OPTIONS);
47739
- await this.#execAsync("", EMPTY_EXEC_OPTIONS);
47740
- }
47741
- }
47742
47397
  return selection.outcome.value;
47743
47398
  }
47744
47399
  async #execute(source, options, scope, budget, cancellation, cancellationState, owner, admission, warm) {
@@ -47784,18 +47439,10 @@ var Shell = class _Shell {
47784
47439
  const extensions = !rawExtensions || rawExtensions.length === 0 ? EMPTY_CAPTURED_EXTENSIONS : captureShellExtensions(rawExtensions);
47785
47440
  const locale = options.env === void 0 ? this.#initialLocale : !this.#hasInitialEnv ? byteLocale(options.env) : byteLocale({ ...this.#options.env, ...options.env });
47786
47441
  const canCacheParse = extensions === EMPTY_CAPTURED_EXTENSIONS && source.length <= 16384;
47787
- const sourceCache = canCacheParse ? getSourceParseCache(source) : void 0;
47442
+ const sourceCache = canCacheParse ? this.#getSourceParseCache(source) : void 0;
47788
47443
  let parseState;
47789
47444
  let currentCachedUnit = sourceCache !== void 0 ? locale ? sourceCache.first1 : sourceCache.first0 : void 0;
47790
47445
  let unit;
47791
- if (currentCachedUnit) {
47792
- budget.parsing.admit(currentCachedUnit.unitsCharged);
47793
- unit = currentCachedUnit.unit;
47794
- } else {
47795
- parseState = { lineIndex: void 0, lineIndexUnits: 0, currentCachedUnit: void 0 };
47796
- unit = getOrParseUnitFromCache(source, 0, locale, sourceCache, parseState, budget, extensions.syntax);
47797
- currentCachedUnit = parseState.currentCachedUnit;
47798
- }
47799
47446
  let currentState;
47800
47447
  if (warm) {
47801
47448
  currentState = warm.currentState;
@@ -47842,6 +47489,7 @@ var Shell = class _Shell {
47842
47489
  exported,
47843
47490
  extensionState(extensions.definitions, void 0, void 0, defaultPortableTrapExtension)
47844
47491
  );
47492
+ currentState.processSubstitutionIds = this.#processSubstitutionIds;
47845
47493
  state = currentState;
47846
47494
  const beforeExecHook = options.hooks?.beforeExec ?? this.#options.hooks?.beforeExec;
47847
47495
  const restoredSnapshot = options.state ?? (beforeExecHook ? await beforeExecHook({ source, options }) : void 0);
@@ -47889,6 +47537,15 @@ var Shell = class _Shell {
47889
47537
  );
47890
47538
  scope.registerFinalizer(runtime.releaseAnchorResources.bind(runtime));
47891
47539
  }
47540
+ const aliases = currentState.expand_aliases ? currentState.aliases : void 0;
47541
+ if (currentCachedUnit && !aliases?.size) {
47542
+ budget.parsing.admit(currentCachedUnit.unitsCharged);
47543
+ unit = currentCachedUnit.unit;
47544
+ } else {
47545
+ parseState = { lineIndex: void 0, lineIndexUnits: 0, currentCachedUnit: void 0 };
47546
+ unit = getOrParseUnitFromCache(source, 0, byteLocale(currentState.variables), sourceCache, parseState, budget, extensions.syntax, aliases);
47547
+ currentCachedUnit = parseState.currentCachedUnit;
47548
+ }
47892
47549
  exitCode = 0;
47893
47550
  while (true) {
47894
47551
  if (unit.script.warnings) {
@@ -47906,34 +47563,20 @@ var Shell = class _Shell {
47906
47563
  budget.signal.throwIfAborted();
47907
47564
  const vars = currentState.variables;
47908
47565
  const nextLocale = vars.LC_ALL || vars.LC_CTYPE || vars.LANG ? byteLocale(vars) : false;
47909
- if (currentCachedUnit && currentCachedUnit.locale === nextLocale && currentCachedUnit.nextCached !== void 0) {
47566
+ if (!currentState.expand_aliases && currentCachedUnit && currentCachedUnit.locale === nextLocale && currentCachedUnit.nextCached !== void 0) {
47910
47567
  currentCachedUnit = currentCachedUnit.nextCached;
47911
47568
  budget.parsing.admit(currentCachedUnit.unitsCharged);
47912
47569
  unit = currentCachedUnit.unit;
47913
47570
  } else {
47914
47571
  parseState ??= { lineIndex: void 0, lineIndexUnits: 0, currentCachedUnit };
47915
47572
  parseState.currentCachedUnit = currentCachedUnit;
47916
- unit = getOrParseUnitFromCache(source, unit.next, nextLocale, sourceCache, parseState, budget, extensions.syntax);
47573
+ unit = getOrParseUnitFromCache(source, unit.next, nextLocale, sourceCache, parseState, budget, extensions.syntax, currentState.expand_aliases ? currentState.aliases : void 0);
47917
47574
  currentCachedUnit = parseState.currentCachedUnit;
47918
47575
  }
47919
47576
  }
47920
47577
  } catch (error) {
47921
47578
  if (!(error instanceof ShellSyntaxError)) throw error;
47922
- const line = source.slice(0, error.offset).split("\n").length;
47923
- if (error.unclosedQuote) {
47924
- await writeDiagnostic(io.stderr, `shell: -c: line ${error.unclosedQuote.line}: unexpected EOF while looking for matching \`${error.unclosedQuote.quote}'
47925
- `);
47926
- } else if (error.exitCode === 127) {
47927
- const token = /^[;&|()<>]|^[^\s;&|()<>]+/u.exec(source.slice(error.offset))?.[0] ?? "newline";
47928
- await writeDiagnostic(io.stderr, `shell: -c: line ${line}: syntax error near unexpected token \`${token}'
47929
- shell: -c: line ${line}: \`${source.split("\n")[line - 1] ?? ""}'
47930
- `);
47931
- } else if (error.offset >= source.length && !/Unterminated|nesting|Unsupported/u.test(error.reason)) {
47932
- const context = error.incompleteCommand ? ` from \`${error.incompleteCommand.name}' command on line ${error.incompleteCommand.line}` : "";
47933
- await writeDiagnostic(io.stderr, `shell: -c: line ${source.split("\n").length + Number(!source.endsWith("\n"))}: syntax error: unexpected end of file${context}
47934
- `);
47935
- } else await writeDiagnostic(io.stderr, `shell: ${error.message}
47936
- `);
47579
+ await writeDiagnostic(io.stderr, syntaxDiagnostic(source, error));
47937
47580
  exitCode = error.exitCode;
47938
47581
  }
47939
47582
  if (runtime && state && !runtime.tryFinishShellSync(state)) {
@@ -47944,7 +47587,9 @@ shell: -c: line ${line}: \`${source.split("\n")[line - 1] ?? ""}'
47944
47587
  if (budget.hasExecutionCleanup) budget.executionCleanup.abort(error);
47945
47588
  throw error;
47946
47589
  } finally {
47947
- if (source === "" && !warm && !failed && !this.#warmedInvocation && !budget.hasExecutionCleanup && !scope.hasFailures && !budget.signal.aborted && stdin && runtime && // Host runtimes own native signals tied to the current Worker request.
47590
+ if (source === "" && !failed && // A retained invocation keeps its parse admissions and clock origins.
47591
+ // Bounded executions must create their own budget and deadline instead.
47592
+ budget.limits.maxParseUnits === Infinity && budget.limits.maxCpuMs === Infinity && budget.limits.maxWallClockMs === Infinity && !this.#warmedInvocation && !budget.hasExecutionCleanup && !scope.hasFailures && !budget.signal.aborted && stdin && runtime && // Host runtimes own native signals tied to the current Worker request.
47948
47593
  // Only the direct memory path can retain an invocation for a later call.
47949
47594
  runtime._isMemoryBackingFs && state && this.#isDefaultExecOptions(options, scope)) {
47950
47595
  if (state.extensions) {
@@ -48037,6 +47682,7 @@ shell: -c: line ${line}: \`${source.split("\n")[line - 1] ?? ""}'
48037
47682
  dispose() {
48038
47683
  if (this.#disposal) return this.#disposal;
48039
47684
  this.#disposed = true;
47685
+ this.#parsedSourceCache.clear();
48040
47686
  Runtime.clearStaticPools();
48041
47687
  clearAwkReaderPool();
48042
47688
  clearRgFastRunnerPool();
@@ -48073,27 +47719,9 @@ shell: -c: line ${line}: \`${source.split("\n")[line - 1] ?? ""}'
48073
47719
  };
48074
47720
 
48075
47721
  export {
48076
- createMemoryFileSystem,
48077
- defaultMemoryFileSystemLimits,
48078
- MemoryFileSystem,
48079
47722
  ShellSyntaxError,
48080
47723
  ShellLimitError,
48081
47724
  parseShell,
48082
- createCsvcutCommand,
48083
- createCsvcutCommands,
48084
- csvcutCommands,
48085
- createCsvgrepCommand,
48086
- createCsvgrepCommands,
48087
- csvgrepCommands,
48088
- createHtmlqCommand,
48089
- createHtmlqCommands,
48090
- htmlqCommands,
48091
- createUnrtfCommand,
48092
- createUnrtfCommands,
48093
- unrtfCommands,
48094
- createDiff3Command,
48095
- createDiff3Commands,
48096
- diff3Commands,
48097
47725
  createSearchCommands,
48098
47726
  searchCommands,
48099
47727
  evalSyncRg,