@opencode/core 2.0.23 → 2.0.24

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 (794) hide show
  1. package/dist/account/sql.js +1 -1
  2. package/dist/agent.js +77 -77
  3. package/dist/aisdk-native.js +89 -89
  4. package/dist/aisdk.js +94 -94
  5. package/dist/app.js +9 -9
  6. package/dist/bus.js +69 -69
  7. package/dist/chunks/{generate-f5k9xycy.js → repository-00e0wh3q.js} +12 -12
  8. package/dist/chunks/{generate-529vcnym.js → repository-012g15cx.js} +10 -10
  9. package/dist/chunks/{generate-v1rqtb9w.js → repository-042aawn8.js} +23 -23
  10. package/dist/chunks/{generate-rpztatg6.js → repository-05t95569.js} +20 -20
  11. package/dist/chunks/{generate-nyhzf7s9.js → repository-067895h7.js} +17 -17
  12. package/dist/chunks/{generate-n92tnbgp.js → repository-0f0pgr2e.js} +1 -1
  13. package/dist/chunks/{generate-h9jzhyk0.js → repository-0g25qkkf.js} +11 -11
  14. package/dist/chunks/{generate-jjw1xd6n.js → repository-0h1qn0y5.js} +10 -10
  15. package/dist/chunks/{generate-0j77ygfz.js → repository-0j77ygfz.js} +2 -2
  16. package/dist/chunks/{generate-0paq2nw3.js → repository-0paq2nw3.js} +1 -1
  17. package/dist/chunks/{generate-te8w5cgp.js → repository-0qpq6ar5.js} +13 -13
  18. package/dist/chunks/{generate-ntmn2n27.js → repository-0qqvk1tp.js} +11 -11
  19. package/dist/chunks/{generate-0vbcp93d.js → repository-0vbcp93d.js} +2 -2
  20. package/dist/chunks/{generate-h7aewrw9.js → repository-16558gs3.js} +48 -48
  21. package/dist/chunks/{generate-yp2x3t23.js → repository-1acjjqhc.js} +4 -4
  22. package/dist/chunks/{generate-73tb2d7t.js → repository-1bbkgx8g.js} +3 -3
  23. package/dist/chunks/{generate-cj02erkw.js → repository-1cw3fj19.js} +3 -3
  24. package/dist/chunks/{generate-1dazxqgg.js → repository-1dazxqgg.js} +2 -2
  25. package/dist/chunks/{generate-1dvck2a7.js → repository-1dvck2a7.js} +2 -2
  26. package/dist/chunks/{generate-qwjmgwmn.js → repository-1gfgk62c.js} +8 -8
  27. package/dist/chunks/{generate-qgatrawj.js → repository-1vvm3xv7.js} +11 -11
  28. package/dist/chunks/{generate-782xyd0k.js → repository-1wb0x8n3.js} +5 -5
  29. package/dist/chunks/{generate-6ywhdf6k.js → repository-23294nz8.js} +10 -10
  30. package/dist/chunks/{generate-nwgjszw0.js → repository-2455wr4j.js} +14 -13
  31. package/dist/chunks/{generate-2a5m3afh.js → repository-2a5m3afh.js} +1 -1
  32. package/dist/chunks/{generate-2ccvkpx1.js → repository-2ccvkpx1.js} +2 -2
  33. package/dist/chunks/{generate-7dqw4kz8.js → repository-2k8khapm.js} +5 -5
  34. package/dist/chunks/{generate-zfs8ae4p.js → repository-2m8jawch.js} +4 -4
  35. package/dist/chunks/{generate-arb3wnqs.js → repository-2t9hnq90.js} +10 -10
  36. package/dist/chunks/{generate-hrs38e71.js → repository-2texf5vf.js} +20 -20
  37. package/dist/chunks/{generate-y5pnfqkr.js → repository-2tyga0yy.js} +19 -51
  38. package/dist/chunks/{generate-zwhxpsnh.js → repository-2wredcz9.js} +17 -17
  39. package/dist/chunks/{generate-3x5f6s31.js → repository-32xj3ztx.js} +31 -31
  40. package/dist/chunks/{generate-znsx74x0.js → repository-3556dn8t.js} +1 -1
  41. package/dist/chunks/repository-3b3navdj.js +253 -0
  42. package/dist/chunks/{generate-3fc6dm20.js → repository-3fc6dm20.js} +1 -1
  43. package/dist/chunks/{generate-3hepkmqq.js → repository-3hepkmqq.js} +1 -1
  44. package/dist/chunks/{generate-3smtnn6g.js → repository-3smtnn6g.js} +1 -1
  45. package/dist/chunks/{generate-14vr5qa8.js → repository-3t7hfzt0.js} +17 -17
  46. package/dist/chunks/{generate-3tvqynh2.js → repository-3tvqynh2.js} +1 -1
  47. package/dist/chunks/{generate-bq4mvesw.js → repository-3vy5pcbx.js} +34 -34
  48. package/dist/chunks/{generate-3zsf4n22.js → repository-3zsf4n22.js} +1 -1
  49. package/dist/chunks/{generate-y8zbdhhn.js → repository-4344f0hm.js} +25 -25
  50. package/dist/chunks/repository-45085rbj.js +26 -0
  51. package/dist/chunks/{generate-330q9b0x.js → repository-46tr0mr7.js} +32 -36
  52. package/dist/chunks/{generate-3dgfh0cr.js → repository-47phkfqm.js} +39 -39
  53. package/dist/chunks/{generate-jrw39j1g.js → repository-4azg6a58.js} +10 -10
  54. package/dist/chunks/{generate-eqfn0pk5.js → repository-4c5k237e.js} +34 -34
  55. package/dist/chunks/{generate-dwxaxj0c.js → repository-4cw36es0.js} +9 -9
  56. package/dist/chunks/{generate-5tznt6k3.js → repository-4ege8dpt.js} +10 -10
  57. package/dist/chunks/{generate-n5gzjg8d.js → repository-4y69v0zr.js} +13 -13
  58. package/dist/chunks/{generate-h9wp8z5w.js → repository-4z58m4b4.js} +4 -4
  59. package/dist/chunks/{generate-zpzjyv2k.js → repository-4z7pkycv.js} +19 -19
  60. package/dist/chunks/{generate-54ma36ye.js → repository-54ma36ye.js} +1 -1
  61. package/dist/chunks/{generate-k5tx4xwh.js → repository-56a9smke.js} +15 -15
  62. package/dist/chunks/{generate-1ygqh575.js → repository-56gdpj1q.js} +9 -9
  63. package/dist/chunks/{generate-aqdbyk8h.js → repository-56gyfky0.js} +5 -5
  64. package/dist/chunks/{generate-w2h15q85.js → repository-57myy5jh.js} +5 -5
  65. package/dist/chunks/{generate-5daktx2q.js → repository-5daktx2q.js} +1 -1
  66. package/dist/chunks/repository-5ej07zgb.js +143 -0
  67. package/dist/chunks/{generate-s3pcx2b8.js → repository-5k54pn5m.js} +7 -7
  68. package/dist/chunks/{generate-vzcthcp8.js → repository-5m9w47nd.js} +1 -1
  69. package/dist/chunks/{generate-spja3q52.js → repository-5ng375bv.js} +12 -12
  70. package/dist/chunks/{generate-7bftgs18.js → repository-5pptr25h.js} +40 -25
  71. package/dist/chunks/{generate-8mnpn7jw.js → repository-5r637m3f.js} +33 -33
  72. package/dist/chunks/{generate-5t3nmthw.js → repository-5t3nmthw.js} +2 -2
  73. package/dist/chunks/{generate-jb9mn43j.js → repository-5t80mpw4.js} +19 -19
  74. package/dist/chunks/{generate-gk28ph79.js → repository-5w6ne2rj.js} +11 -11
  75. package/dist/chunks/{generate-yfxkm5w6.js → repository-68ga000j.js} +34 -34
  76. package/dist/chunks/{generate-z15fp2pm.js → repository-6b1pjwt3.js} +3 -3
  77. package/dist/chunks/{generate-hjbc5kem.js → repository-6q2bdcd1.js} +4 -1
  78. package/dist/chunks/{generate-xgaq9ax1.js → repository-6r4hjhnf.js} +20 -20
  79. package/dist/chunks/{generate-jmdp6qyf.js → repository-6x4qebe7.js} +33 -33
  80. package/dist/chunks/{generate-x1ezjp6w.js → repository-6xb47vfp.js} +4 -2
  81. package/dist/chunks/{generate-71az546q.js → repository-71az546q.js} +2 -2
  82. package/dist/chunks/{generate-zp2fsh7c.js → repository-77apbbcp.js} +17 -17
  83. package/dist/chunks/{generate-7bmhse3q.js → repository-7bmhse3q.js} +1 -1
  84. package/dist/chunks/{generate-3rd28rcz.js → repository-7c08hygz.js} +8 -8
  85. package/dist/chunks/{generate-pfh2gawv.js → repository-7d05dvcz.js} +6 -6
  86. package/dist/chunks/{generate-wdshzat6.js → repository-7wnc14t4.js} +21 -21
  87. package/dist/chunks/{generate-z872cvkj.js → repository-7z6z4pna.js} +5 -5
  88. package/dist/chunks/{generate-84txncab.js → repository-84txncab.js} +1 -1
  89. package/dist/chunks/{generate-1z18ck0n.js → repository-89za3yyg.js} +3 -3
  90. package/dist/chunks/{generate-8d7r5vzw.js → repository-8d7r5vzw.js} +1 -1
  91. package/dist/chunks/{generate-sgpy7nbp.js → repository-8hjmwb77.js} +16 -16
  92. package/dist/chunks/{generate-82czg0r8.js → repository-8kys6q5k.js} +9 -9
  93. package/dist/chunks/{generate-vbfgae2j.js → repository-8tsdq50x.js} +4 -4
  94. package/dist/chunks/{generate-kb6gw2zp.js → repository-96ctqc5x.js} +4 -4
  95. package/dist/chunks/{generate-3edgjjmd.js → repository-9815d8pv.js} +24 -21
  96. package/dist/chunks/{generate-9e5bzkjp.js → repository-9e5bzkjp.js} +3 -3
  97. package/dist/chunks/{generate-mt68kget.js → repository-9mhtj97w.js} +24 -24
  98. package/dist/chunks/{generate-an75rhmh.js → repository-9mxexfbd.js} +16 -16
  99. package/dist/chunks/{generate-t3cgces8.js → repository-9s1pr29s.js} +39 -39
  100. package/dist/chunks/{generate-4kfhygng.js → repository-9yaf30yb.js} +36 -36
  101. package/dist/chunks/{generate-z8hrkqzq.js → repository-9yxvhatz.js} +4 -4
  102. package/dist/chunks/{generate-pxhak851.js → repository-a199weyn.js} +6 -6
  103. package/dist/chunks/{generate-b27vhd2z.js → repository-a2ew8a62.js} +4 -4
  104. package/dist/chunks/{generate-gknnw9w7.js → repository-a6rczh0a.js} +30 -30
  105. package/dist/chunks/{generate-zqkxpfgh.js → repository-a7cd87s2.js} +65 -65
  106. package/dist/chunks/{generate-aaet6srn.js → repository-aaet6srn.js} +2 -2
  107. package/dist/chunks/{generate-addxnjmp.js → repository-addxnjmp.js} +1 -1
  108. package/dist/chunks/{generate-29x9jy0f.js → repository-ajh7mqgq.js} +34 -34
  109. package/dist/chunks/{generate-9pvxkkw3.js → repository-aqryd466.js} +22 -22
  110. package/dist/chunks/{generate-5kp03ppx.js → repository-b20bdvd4.js} +12 -12
  111. package/dist/chunks/{generate-v1v20ddn.js → repository-b3cm3psy.js} +10 -7
  112. package/dist/chunks/{generate-94jj38jg.js → repository-b5f9cqb8.js} +24 -20
  113. package/dist/chunks/{generate-b6gygkdw.js → repository-b6gygkdw.js} +2 -2
  114. package/dist/chunks/{generate-6zp854ra.js → repository-b751st24.js} +3 -3
  115. package/dist/chunks/{generate-kkndcpqr.js → repository-bzadqhw2.js} +4 -4
  116. package/dist/chunks/{generate-6m42r3np.js → repository-c20khjev.js} +4 -4
  117. package/dist/chunks/{generate-cdm0dq9n.js → repository-c8bydgjz.js} +6 -6
  118. package/dist/chunks/{generate-w8vdqaq3.js → repository-cb3fgacg.js} +25 -25
  119. package/dist/chunks/{generate-61fzh3cq.js → repository-ce3pkz8w.js} +8 -8
  120. package/dist/chunks/{generate-w92k2e0p.js → repository-cfsekr6v.js} +8 -8
  121. package/dist/chunks/{generate-3q48ekr2.js → repository-chyvjp63.js} +16 -16
  122. package/dist/chunks/{generate-q3ersh05.js → repository-cjwramev.js} +4 -4
  123. package/dist/chunks/{generate-ejbv3g31.js → repository-cs63tcvs.js} +9 -9
  124. package/dist/chunks/{generate-qmqgtz8f.js → repository-d4he2qe1.js} +9 -9
  125. package/dist/chunks/{generate-evhyysd2.js → repository-dbp4m4ge.js} +33 -33
  126. package/dist/chunks/{generate-wj2bx7an.js → repository-dfcrteyq.js} +13 -13
  127. package/dist/chunks/{generate-qq54afgs.js → repository-dp8mmgq4.js} +15 -15
  128. package/dist/chunks/{generate-dpkg50ah.js → repository-dpkg50ah.js} +1 -1
  129. package/dist/chunks/{generate-5pyjqqve.js → repository-drnf6xwf.js} +2 -2
  130. package/dist/chunks/{generate-exjwxjfq.js → repository-dt6m3qwv.js} +18 -18
  131. package/dist/chunks/{generate-bepbq8jj.js → repository-ecwx0042.js} +15 -15
  132. package/dist/chunks/{generate-nz1ptcx7.js → repository-ef2cw19s.js} +14 -14
  133. package/dist/chunks/{generate-ef5x83kb.js → repository-ef5x83kb.js} +1 -1
  134. package/dist/chunks/{generate-t2az9yje.js → repository-embw8kgh.js} +4 -4
  135. package/dist/chunks/{generate-ffxkc1dx.js → repository-eqh5fpv6.js} +9 -9
  136. package/dist/chunks/{generate-gya1c0vy.js → repository-erq8vxjr.js} +1 -1
  137. package/dist/chunks/{generate-h6310vsd.js → repository-espax8zg.js} +4 -4
  138. package/dist/chunks/{generate-dfc208d8.js → repository-etdaqrbr.js} +30 -30
  139. package/dist/chunks/{generate-etq0c3wd.js → repository-etq0c3wd.js} +1 -1
  140. package/dist/chunks/{generate-hn4yapt1.js → repository-f6sbv01c.js} +31 -30
  141. package/dist/chunks/{generate-trc3n3qb.js → repository-f8tnf7f1.js} +14 -19
  142. package/dist/chunks/{generate-ejg73w2g.js → repository-f8xdbq78.js} +6 -6
  143. package/dist/chunks/{generate-ntev6yqw.js → repository-fj3b7143.js} +8 -8
  144. package/dist/chunks/{generate-g9c3k2sz.js → repository-fy3w4x98.js} +18 -18
  145. package/dist/chunks/{generate-vswtd384.js → repository-fy698pgn.js} +20 -20
  146. package/dist/chunks/{generate-ajmxk7z2.js → repository-g34b934z.js} +15 -15
  147. package/dist/chunks/{generate-ee09rdq3.js → repository-g4nj3be3.js} +311 -311
  148. package/dist/chunks/repository-g50bcqhp.js +43 -0
  149. package/dist/chunks/{generate-57b9ws8p.js → repository-g5w8qwbj.js} +7 -7
  150. package/dist/chunks/{generate-gjv38h0k.js → repository-g69c5a8v.js} +16 -16
  151. package/dist/chunks/{generate-w1ad28wa.js → repository-gc135ar8.js} +8 -8
  152. package/dist/chunks/{generate-gd4qta3r.js → repository-gd4qta3r.js} +1 -1
  153. package/dist/chunks/{generate-z3507kbh.js → repository-gkcjs2dn.js} +11 -11
  154. package/dist/chunks/{generate-t55xhmjx.js → repository-gpng080p.js} +16 -16
  155. package/dist/chunks/{generate-rv4s02rg.js → repository-gry8sgkd.js} +7 -7
  156. package/dist/chunks/{generate-6p2526mp.js → repository-gy4662d6.js} +11 -11
  157. package/dist/chunks/{generate-atz6g77g.js → repository-h16n41p4.js} +21 -21
  158. package/dist/chunks/{generate-h2b79v29.js → repository-h2b79v29.js} +2 -2
  159. package/dist/chunks/{generate-bzqyrf6j.js → repository-h2yw0gk4.js} +20 -20
  160. package/dist/chunks/{generate-435eggbz.js → repository-h4jx6m0r.js} +15 -15
  161. package/dist/chunks/{generate-7keeseff.js → repository-h4p4pa57.js} +8 -8
  162. package/dist/chunks/{generate-5txw87z1.js → repository-h6c2yg5r.js} +8 -8
  163. package/dist/chunks/{generate-ywacswhv.js → repository-h6qw898r.js} +11 -11
  164. package/dist/chunks/{generate-h6vf3j39.js → repository-h6vf3j39.js} +1 -1
  165. package/dist/chunks/{generate-14qr745v.js → repository-h6yzxz9r.js} +17 -17
  166. package/dist/chunks/{generate-34bnvpfh.js → repository-hdjgtqrb.js} +29 -29
  167. package/dist/chunks/{generate-5v5aasd4.js → repository-hkgfm0m5.js} +17 -17
  168. package/dist/chunks/{generate-tbp0qxg2.js → repository-hp7m3mgg.js} +26 -26
  169. package/dist/chunks/{generate-mmy17vwk.js → repository-hw3ewgqj.js} +5 -5
  170. package/dist/chunks/{generate-39k0hmda.js → repository-j2htzqze.js} +2 -2
  171. package/dist/chunks/{generate-jpep6vf5.js → repository-j3pg2mx4.js} +1 -1
  172. package/dist/chunks/{generate-j56e64zr.js → repository-j56e64zr.js} +1 -1
  173. package/dist/chunks/{generate-bydnjh3t.js → repository-j58c5xyq.js} +9 -9
  174. package/dist/chunks/{generate-6cjqe6sy.js → repository-jnevnthy.js} +27 -27
  175. package/dist/chunks/repository-jqh9b0xq.js +18 -0
  176. package/dist/chunks/{generate-6nv25w3f.js → repository-k02x6tcx.js} +31 -31
  177. package/dist/chunks/{generate-xer3snnb.js → repository-k37ga4vh.js} +13 -9
  178. package/dist/chunks/{generate-gh5z95q3.js → repository-k70p9jzb.js} +9 -9
  179. package/dist/chunks/{generate-kygz6673.js → repository-kfj4fg87.js} +3 -3
  180. package/dist/chunks/{generate-qb7y9a6p.js → repository-kxam66j6.js} +11 -11
  181. package/dist/chunks/{generate-m3fdjcah.js → repository-m3fdjcah.js} +1 -1
  182. package/dist/chunks/{generate-pvkpwa2b.js → repository-m44fkk4m.js} +6 -6
  183. package/dist/chunks/{generate-06wny47j.js → repository-m993mvxq.js} +135 -135
  184. package/dist/chunks/{generate-m9w0rfyh.js → repository-m9w0rfyh.js} +1 -1
  185. package/dist/chunks/{generate-r7pm0y1x.js → repository-mfct962c.js} +18 -18
  186. package/dist/chunks/{generate-stnmwbvn.js → repository-mfmqp3ds.js} +43 -43
  187. package/dist/chunks/{generate-mjqndqed.js → repository-mjqndqed.js} +5 -5
  188. package/dist/chunks/{generate-9pwf6adz.js → repository-mn0942hp.js} +30 -30
  189. package/dist/chunks/{generate-02hj8zpc.js → repository-mpd66srn.js} +1 -1
  190. package/dist/chunks/{generate-k1qrnqst.js → repository-mxr1v1s0.js} +8 -8
  191. package/dist/chunks/{generate-vx3jgdek.js → repository-my4zabxr.js} +3 -3
  192. package/dist/chunks/{generate-e0ne0z26.js → repository-nszdq9jy.js} +83 -83
  193. package/dist/chunks/{generate-01s90evy.js → repository-ntaqe8vs.js} +19 -19
  194. package/dist/chunks/{generate-1ader487.js → repository-ntbz9wjc.js} +11 -11
  195. package/dist/chunks/{generate-cmwkp3r5.js → repository-p42hj8p8.js} +8 -8
  196. package/dist/chunks/{generate-3j10s7ay.js → repository-p5ev1zz5.js} +9 -9
  197. package/dist/chunks/{generate-8f9gr54c.js → repository-pe71rtbx.js} +11 -11
  198. package/dist/chunks/{generate-vnh00gv4.js → repository-pg4zag0e.js} +24 -24
  199. package/dist/chunks/{generate-gra2jmjd.js → repository-pgze7171.js} +1 -1
  200. package/dist/chunks/{generate-pjvnvgmy.js → repository-pjvnvgmy.js} +1 -1
  201. package/dist/chunks/{generate-5yzz6hd1.js → repository-pk7hbv6p.js} +4 -4
  202. package/dist/chunks/{generate-pknna89w.js → repository-pknna89w.js} +1 -1
  203. package/dist/chunks/repository-prjw6x41.js +31 -0
  204. package/dist/chunks/{generate-g2xfdbz5.js → repository-q0cdrezg.js} +14 -14
  205. package/dist/chunks/{generate-0at0q6bk.js → repository-q6vgfyay.js} +6 -6
  206. package/dist/chunks/{generate-m4b4ezfy.js → repository-q76xcmv9.js} +16 -16
  207. package/dist/chunks/{generate-afv7vh30.js → repository-q7jxq9y7.js} +18 -18
  208. package/dist/chunks/{generate-x0y04rr6.js → repository-q7ngdz78.js} +27 -27
  209. package/dist/chunks/{generate-qnc92qwc.js → repository-qnc92qwc.js} +1 -1
  210. package/dist/chunks/{generate-zmr78fwr.js → repository-qne3fa44.js} +5 -5
  211. package/dist/chunks/{generate-qsdy395h.js → repository-qsdy395h.js} +1 -1
  212. package/dist/chunks/{generate-9sy6gwjh.js → repository-qv02qg64.js} +5 -5
  213. package/dist/chunks/{generate-qxjc9qry.js → repository-qxjc9qry.js} +3 -3
  214. package/dist/chunks/{generate-xf4rrgwy.js → repository-qy0n8417.js} +23 -23
  215. package/dist/chunks/{generate-4eax54pa.js → repository-r3c58j5g.js} +3 -3
  216. package/dist/chunks/{generate-ze7rj9cq.js → repository-rb8xm6cm.js} +14 -14
  217. package/dist/chunks/{generate-rdw6cm16.js → repository-rdw6cm16.js} +1 -1
  218. package/dist/chunks/{generate-8zvk0rgz.js → repository-rjfypheq.js} +27 -27
  219. package/dist/chunks/{generate-q0jhbe3n.js → repository-rjsk0n41.js} +9 -9
  220. package/dist/chunks/{generate-q0808tka.js → repository-rk3ekeb4.js} +5 -5
  221. package/dist/chunks/{generate-wg7dvnk1.js → repository-rm4s95e7.js} +85 -85
  222. package/dist/chunks/{generate-hyxvh71r.js → repository-rn938jk3.js} +42 -42
  223. package/dist/chunks/{generate-2pcsyv91.js → repository-rpp7c75e.js} +48 -48
  224. package/dist/chunks/{generate-qs9jyzer.js → repository-s4075y1x.js} +3 -3
  225. package/dist/chunks/{generate-m26jacn4.js → repository-s8qvywtq.js} +14 -14
  226. package/dist/chunks/{generate-823qfcak.js → repository-s8v3amej.js} +1 -1
  227. package/dist/chunks/{generate-0q2zy8rk.js → repository-s9nwmxxs.js} +27 -27
  228. package/dist/chunks/{generate-1fs3aa3n.js → repository-srhj5f56.js} +9 -9
  229. package/dist/chunks/{generate-fjh44twp.js → repository-t5483b9c.js} +2 -2
  230. package/dist/chunks/{generate-s8d7rejh.js → repository-t550f9t1.js} +4 -4
  231. package/dist/chunks/{generate-21tjqxxf.js → repository-t7wcnk30.js} +14 -14
  232. package/dist/chunks/{generate-067vzkwc.js → repository-t7y8x8j8.js} +16 -16
  233. package/dist/chunks/{generate-p5cm9qbj.js → repository-t8n7ymvq.js} +56 -45
  234. package/dist/chunks/{generate-z32f8zps.js → repository-tarna68p.js} +9 -9
  235. package/dist/chunks/{generate-tazgh4e4.js → repository-tazgh4e4.js} +1 -1
  236. package/dist/chunks/{generate-0z57cqh9.js → repository-tbs2jyb2.js} +7 -7
  237. package/dist/chunks/{generate-tcezcvh9.js → repository-tcezcvh9.js} +1 -1
  238. package/dist/chunks/{generate-t0sqncza.js → repository-tdpndm1c.js} +5 -5
  239. package/dist/chunks/{generate-tdstcens.js → repository-tdstcens.js} +1 -1
  240. package/dist/chunks/{generate-0n25afzx.js → repository-tg6e69q8.js} +2 -2
  241. package/dist/chunks/{generate-gej6rn0s.js → repository-tgah08rb.js} +27 -27
  242. package/dist/chunks/{generate-peckcdzj.js → repository-tk5m56y0.js} +13 -13
  243. package/dist/chunks/{generate-j7vp94m4.js → repository-tzy9a5tv.js} +15 -15
  244. package/dist/chunks/{generate-v0es1rhs.js → repository-v0es1rhs.js} +2 -2
  245. package/dist/chunks/{generate-ppcxd43r.js → repository-ve1j3q85.js} +15 -15
  246. package/dist/chunks/{generate-veqvce7d.js → repository-veqvce7d.js} +1 -1
  247. package/dist/chunks/{generate-5swqfww9.js → repository-vngdzw63.js} +28 -28
  248. package/dist/chunks/{generate-z3ra53tp.js → repository-vqkmcgyv.js} +3 -3
  249. package/dist/chunks/{generate-zq24ypn2.js → repository-vt8dt6j6.js} +30 -30
  250. package/dist/chunks/{generate-vzs5sf6e.js → repository-vzs5sf6e.js} +1 -1
  251. package/dist/chunks/{generate-w3wsvvr9.js → repository-w3wsvvr9.js} +1 -1
  252. package/dist/chunks/{generate-bh5cssh3.js → repository-w5ystqj3.js} +6 -6
  253. package/dist/chunks/{generate-gtvea8z9.js → repository-w6gqnbcy.js} +3 -3
  254. package/dist/chunks/{generate-yhecr6n4.js → repository-w7a2abxy.js} +12 -12
  255. package/dist/chunks/{generate-n7fmmpds.js → repository-wb70vhte.js} +11 -11
  256. package/dist/chunks/{generate-wd87259q.js → repository-wd87259q.js} +1 -1
  257. package/dist/chunks/{generate-b9rmm35c.js → repository-wnfszx78.js} +10 -10
  258. package/dist/chunks/{generate-wrp5ry2f.js → repository-wnh11861.js} +13 -13
  259. package/dist/chunks/{generate-gcxxm8yg.js → repository-x4k83k5f.js} +9 -9
  260. package/dist/chunks/{generate-7xf5yptx.js → repository-xhv84ab7.js} +28 -28
  261. package/dist/chunks/{generate-xkntkrq7.js → repository-xkntkrq7.js} +2 -2
  262. package/dist/chunks/{generate-34manr0f.js → repository-xmy45d6e.js} +23 -23
  263. package/dist/chunks/{generate-x4csn5yb.js → repository-xpwv3d90.js} +12 -12
  264. package/dist/chunks/{generate-qbyggmx7.js → repository-xvvw76kz.js} +7 -7
  265. package/dist/chunks/{generate-q0raz0xt.js → repository-y16p1w2y.js} +9 -9
  266. package/dist/chunks/{generate-y1fvbwt7.js → repository-y1fvbwt7.js} +1 -1
  267. package/dist/chunks/{generate-4ntq7m4z.js → repository-y1w7bwtd.js} +20 -20
  268. package/dist/chunks/{generate-wc2m80g2.js → repository-y6brtjeh.js} +39 -34
  269. package/dist/chunks/repository-y6mhs71q.js +72 -0
  270. package/dist/chunks/{generate-7naq09xc.js → repository-ydszhw6d.js} +19 -19
  271. package/dist/chunks/{generate-bkrwt1n9.js → repository-yf33k1p3.js} +22 -22
  272. package/dist/chunks/{generate-01vz176c.js → repository-yfe405ny.js} +12 -12
  273. package/dist/chunks/{generate-pd0d3v86.js → repository-yn96zvvk.js} +8 -8
  274. package/dist/chunks/{generate-fep41vc5.js → repository-yprc5htm.js} +22 -22
  275. package/dist/chunks/{generate-thtzhryg.js → repository-yqt58wae.js} +13 -13
  276. package/dist/chunks/{generate-z0bkrqjs.js → repository-z0bkrqjs.js} +1 -1
  277. package/dist/chunks/{generate-d2eqb18p.js → repository-z6b5w8cf.js} +2 -2
  278. package/dist/chunks/{generate-hbyhqfhs.js → repository-zd30eb5w.js} +5 -5
  279. package/dist/chunks/{generate-aer73x3z.js → repository-zhwzkc0c.js} +18 -18
  280. package/dist/chunks/{generate-rh2b0agp.js → repository-zk46kswf.js} +10 -10
  281. package/dist/chunks/{generate-zr2ceqn5.js → repository-zr2ceqn5.js} +1 -1
  282. package/dist/chunks/{generate-7s2tn799.js → repository-zvjhkatg.js} +8 -8
  283. package/dist/chunks/{generate-zxq2ej10.js → repository-zxq2ej10.js} +1 -1
  284. package/dist/chunks/{generate-scgrse2b.js → repository-zyk1yjk8.js} +5 -5
  285. package/dist/codemode/catalog.js +1 -1
  286. package/dist/codemode/instructions.js +7 -7
  287. package/dist/codemode/tool.js +3 -3
  288. package/dist/codemode/web.js +1 -1
  289. package/dist/command.js +81 -81
  290. package/dist/config/discovery.js +82 -82
  291. package/dist/config/markdown.js +1 -1
  292. package/dist/config/normalize.js +99 -99
  293. package/dist/config/plugin/agent.js +118 -118
  294. package/dist/config/plugin/command.js +207 -207
  295. package/dist/config/plugin/compaction.js +154 -154
  296. package/dist/config/plugin/compatibility.js +134 -134
  297. package/dist/config/plugin/entry-observer.js +1 -1
  298. package/dist/config/plugin/formatter.js +117 -117
  299. package/dist/config/plugin/image.js +114 -114
  300. package/dist/config/plugin/instruction.js +88 -88
  301. package/dist/config/plugin/location-watcher.js +116 -116
  302. package/dist/config/plugin/mcp.js +125 -125
  303. package/dist/config/plugin/policy.js +117 -117
  304. package/dist/config/plugin/provider.js +114 -114
  305. package/dist/config/plugin/reference.js +118 -118
  306. package/dist/config/plugin/shell.js +118 -118
  307. package/dist/config/plugin/skill-file.js +102 -102
  308. package/dist/config/plugin/skill.js +135 -135
  309. package/dist/config/plugin/snapshot.js +116 -116
  310. package/dist/config/plugin/source.js +119 -119
  311. package/dist/config/plugin/tool-output.js +117 -117
  312. package/dist/config/plugin/websearch.js +117 -117
  313. package/dist/config/plugin/worktree.js +118 -118
  314. package/dist/config/variable.js +3 -3
  315. package/dist/config/watch.js +1 -1
  316. package/dist/config.js +119 -119
  317. package/dist/credential/sql.js +2 -2
  318. package/dist/credential.js +77 -77
  319. package/dist/database/database.js +66 -66
  320. package/dist/database/drizzle/effect-sqlite/driver.js +12 -12
  321. package/dist/database/drizzle/effect-sqlite/index.js +12 -12
  322. package/dist/database/drizzle/effect-sqlite/session.js +11 -11
  323. package/dist/database/drizzle/index.js +13 -13
  324. package/dist/database/drizzle/internal/drizzle-utils.js +1 -1
  325. package/dist/database/drizzle/sqlite-core/effect/count.js +1 -1
  326. package/dist/database/drizzle/sqlite-core/effect/db.js +9 -9
  327. package/dist/database/drizzle/sqlite-core/effect/delete.js +2 -2
  328. package/dist/database/drizzle/sqlite-core/effect/index.js +10 -10
  329. package/dist/database/drizzle/sqlite-core/effect/insert.js +2 -2
  330. package/dist/database/drizzle/sqlite-core/effect/query.js +1 -1
  331. package/dist/database/drizzle/sqlite-core/effect/raw.js +1 -1
  332. package/dist/database/drizzle/sqlite-core/effect/select.js +2 -2
  333. package/dist/database/drizzle/sqlite-core/effect/session.js +10 -10
  334. package/dist/database/drizzle/sqlite-core/effect/update.js +2 -2
  335. package/dist/database/drizzle.js +14 -14
  336. package/dist/database/migration/20260127222353_familiar_lady_ursula.js +1 -1
  337. package/dist/database/migration/20260211171708_add_project_commands.js +1 -1
  338. package/dist/database/migration/20260213144116_wakeful_the_professor.js +1 -1
  339. package/dist/database/migration/20260225215848_workspace.js +1 -1
  340. package/dist/database/migration/20260227213759_add_session_workspace_id.js +1 -1
  341. package/dist/database/migration/20260228203230_blue_harpoon.js +1 -1
  342. package/dist/database/migration/20260303231226_add_workspace_fields.js +1 -1
  343. package/dist/database/migration/20260309230000_move_org_to_state.js +1 -1
  344. package/dist/database/migration/20260312043431_session_message_cursor.js +1 -1
  345. package/dist/database/migration/20260323234822_events.js +1 -1
  346. package/dist/database/migration/20260410174513_workspace-name.js +1 -1
  347. package/dist/database/migration/20260413175956_chief_energizer.js +1 -1
  348. package/dist/database/migration/20260423070820_add_icon_url_override.js +1 -1
  349. package/dist/database/migration/20260427172553_slow_nightmare.js +1 -1
  350. package/dist/database/migration/20260428004200_add_session_path.js +1 -1
  351. package/dist/database/migration/20260501142318_next_venus.js +1 -1
  352. package/dist/database/migration/20260504145000_add_sync_owner.js +1 -1
  353. package/dist/database/migration/20260507164347_add_workspace_time.js +1 -1
  354. package/dist/database/migration/20260510033149_session_usage.js +1 -1
  355. package/dist/database/migration/20260511000411_data_migration_state.js +1 -1
  356. package/dist/database/migration/20260511173437_session-metadata.js +1 -1
  357. package/dist/database/migration/20260601010001_normalize_storage_paths.js +1 -1
  358. package/dist/database/migration/20260601202201_amazing_prowler.js +1 -1
  359. package/dist/database/migration/20260602002951_lowly_union_jack.js +1 -1
  360. package/dist/database/migration/20260602182828_add_project_directories.js +1 -1
  361. package/dist/database/migration/20260603001617_session_message_projection_indexes.js +1 -1
  362. package/dist/database/migration/20260603040000_session_message_projection_order.js +1 -1
  363. package/dist/database/migration/20260603141458_session_input_inbox.js +1 -1
  364. package/dist/database/migration/20260603160727_jittery_ezekiel_stane.js +1 -1
  365. package/dist/database/migration/20260604172448_event_sourced_session_input.js +1 -1
  366. package/dist/database/migration/20260605003541_add_session_context_snapshot.js +1 -1
  367. package/dist/database/migration/20260605042240_add_context_epoch_agent.js +1 -1
  368. package/dist/database/migration/20260611035744_credential.js +1 -1
  369. package/dist/database/migration/20260611192811_lush_chimera.js +1 -1
  370. package/dist/database/migration/20260612174303_project_dir_strategy.js +1 -1
  371. package/dist/database/migration/20260622142730_simplify_session_context_epoch.js +1 -1
  372. package/dist/database/migration/20260622170816_reset_v2_session_state.js +1 -1
  373. package/dist/database/migration/20260622202450_simplify_session_input.js +1 -1
  374. package/dist/database/migration/20260804233008_loose_psylocke.js +1 -1
  375. package/dist/database/migration/20260805200742_import_legacy_credentials.js +1 -1
  376. package/dist/database/migration/20260808023530_workspace_domain.js +1 -1
  377. package/dist/database/migration/20260811161259_execution_claim_attempts.js +1 -1
  378. package/dist/database/migration/20260812181746_session_inbox.js +1 -1
  379. package/dist/database/migration/20260812213948_worktree.js +1 -1
  380. package/dist/database/migration/20260819222447_session_viewed_state.js +1 -1
  381. package/dist/database/migration/20260823191254_nullable_workspace_binding.js +1 -1
  382. package/dist/database/migration/20260910120000_clear_v1_session_permission.js +1 -1
  383. package/dist/database/migration/20260923013825_project_time_active.js +1 -1
  384. package/dist/database/migration.gen.js +49 -49
  385. package/dist/database/migration.js +51 -51
  386. package/dist/database/path.js +2 -2
  387. package/dist/database/schema.gen.js +1 -1
  388. package/dist/database/schema.sql.js +1 -1
  389. package/dist/database/sqlite.bun.js +1 -1
  390. package/dist/database/sqlite.js +1 -1
  391. package/dist/database/sqlite.node.js +1 -1
  392. package/dist/database/sqlite.workerd.js +1 -1
  393. package/dist/database/v1-migration.bun.js +76 -76
  394. package/dist/database/v1-migration.js +1 -1
  395. package/dist/effect/app-node-builder.js +363 -363
  396. package/dist/effect/app-node-platform.js +2 -2
  397. package/dist/effect/keyed-mutex.js +1 -1
  398. package/dist/effect/websocket-constructor.js +1 -1
  399. package/dist/environment/driver.js +1 -1
  400. package/dist/environment/environment.js +91 -91
  401. package/dist/environment/exec-defaults.js +2 -2
  402. package/dist/environment/files.js +1 -1
  403. package/dist/environment/index.js +93 -93
  404. package/dist/environment/local.js +2 -2
  405. package/dist/environment/memory.js +2 -2
  406. package/dist/environment/unavailable.js +1 -1
  407. package/dist/event/sql.js +1 -1
  408. package/dist/event-logger.js +70 -70
  409. package/dist/file-access.js +104 -104
  410. package/dist/file-mutation.js +94 -94
  411. package/dist/file-retention.js +1 -1
  412. package/dist/filesystem/fff.bun.js +2 -2
  413. package/dist/filesystem/fff.js +1 -1
  414. package/dist/filesystem/fff.node.js +2 -2
  415. package/dist/filesystem/fff.workerd.js +2 -2
  416. package/dist/filesystem/location-watcher-policy.js +6 -6
  417. package/dist/filesystem/location-watcher.js +218 -218
  418. package/dist/filesystem/protected.js +1 -1
  419. package/dist/filesystem/search.js +103 -103
  420. package/dist/filesystem/watcher-binding.js +1 -1
  421. package/dist/filesystem/watcher.js +15 -15
  422. package/dist/filesystem.js +104 -104
  423. package/dist/form.js +72 -72
  424. package/dist/formatter/builtins.js +4 -4
  425. package/dist/formatter.js +87 -87
  426. package/dist/generate.js +103 -103
  427. package/dist/git.js +6 -6
  428. package/dist/github-copilot/chat/convert-to-openai-compatible-chat-messages.js +1 -1
  429. package/dist/github-copilot/chat/get-response-metadata.js +1 -1
  430. package/dist/github-copilot/chat/map-openai-compatible-finish-reason.js +1 -1
  431. package/dist/github-copilot/chat/openai-compatible-chat-language-model.js +7 -7
  432. package/dist/github-copilot/chat/openai-compatible-chat-options.js +1 -1
  433. package/dist/github-copilot/chat/openai-compatible-prepare-tools.js +1 -1
  434. package/dist/github-copilot/copilot-provider.js +17 -17
  435. package/dist/github-copilot/models.js +99 -99
  436. package/dist/github-copilot/openai-compatible-error.js +1 -1
  437. package/dist/github-copilot/responses/convert-to-openai-responses-input.js +1 -1
  438. package/dist/github-copilot/responses/map-openai-responses-finish-reason.js +1 -1
  439. package/dist/github-copilot/responses/openai-error.js +1 -1
  440. package/dist/github-copilot/responses/openai-responses-language-model.js +10 -10
  441. package/dist/github-copilot/responses/openai-responses-prepare-tools.js +6 -6
  442. package/dist/github-copilot/responses/tool/code-interpreter.js +1 -1
  443. package/dist/github-copilot/responses/tool/file-search.js +1 -1
  444. package/dist/github-copilot/responses/tool/image-generation.js +1 -1
  445. package/dist/github-copilot/responses/tool/web-search-preview.js +1 -1
  446. package/dist/github-copilot/responses/tool/web-search.js +1 -1
  447. package/dist/image/photon.js +2 -2
  448. package/dist/image.js +6 -6
  449. package/dist/instance/service.js +5 -5
  450. package/dist/instance.js +354 -354
  451. package/dist/instruction-discovery.js +83 -83
  452. package/dist/instructions/builtins.js +87 -87
  453. package/dist/instructions/index.js +3 -3
  454. package/dist/integration/connection.js +1 -1
  455. package/dist/integration.js +81 -81
  456. package/dist/job.js +78 -78
  457. package/dist/kv/sql.js +2 -2
  458. package/dist/kv.js +73 -73
  459. package/dist/location-activity.js +131 -131
  460. package/dist/location-lifecycle.js +107 -107
  461. package/dist/location-service-map.js +86 -86
  462. package/dist/location-services.js +351 -351
  463. package/dist/location.js +87 -87
  464. package/dist/managed-policy.js +5 -5
  465. package/dist/mcp/client.js +91 -91
  466. package/dist/mcp/index.js +105 -105
  467. package/dist/mcp/instructions.js +129 -129
  468. package/dist/mcp/oauth.js +92 -87
  469. package/dist/mcp/stdio.js +90 -90
  470. package/dist/mime.js +1 -1
  471. package/dist/modal/models.js +99 -99
  472. package/dist/model-resolver.js +98 -98
  473. package/dist/model.js +97 -95
  474. package/dist/models-dev.js +107 -107
  475. package/dist/oauth/page.js +1 -1
  476. package/dist/permission/saved.js +78 -78
  477. package/dist/permission/sql.js +5 -5
  478. package/dist/permission.js +105 -105
  479. package/dist/persistent-pty/binary.bun.js +1 -1
  480. package/dist/persistent-pty/daemon.js +1 -1
  481. package/dist/persistent-pty/index.js +80 -80
  482. package/dist/persistent-pty/pty-binding.js +1 -1
  483. package/dist/persistent-pty.js +75 -75
  484. package/dist/plugin/agent.js +104 -104
  485. package/dist/plugin/command.js +102 -102
  486. package/dist/plugin/hooks.js +5 -5
  487. package/dist/plugin/host.js +211 -211
  488. package/dist/plugin/identity.js +3 -3
  489. package/dist/plugin/instance.js +5 -5
  490. package/dist/plugin/internal.js +326 -326
  491. package/dist/plugin/mcp-codemode-defaults.js +3 -3
  492. package/dist/plugin/models-dev.js +96 -96
  493. package/dist/plugin/module.js +5 -5
  494. package/dist/plugin/optimize.js +4 -4
  495. package/dist/plugin/plan.js +102 -102
  496. package/dist/plugin/promise.js +1 -1
  497. package/dist/plugin/provider/amazon-bedrock.js +90 -90
  498. package/dist/plugin/provider/azure.js +117 -117
  499. package/dist/plugin/provider/cerebras.js +1 -1
  500. package/dist/plugin/provider/chatgpt.js +93 -93
  501. package/dist/plugin/provider/cloudflare-ai-gateway.js +113 -113
  502. package/dist/plugin/provider/cloudflare-workers-ai.js +114 -114
  503. package/dist/plugin/provider/cohere.js +2 -2
  504. package/dist/plugin/provider/configured.js +112 -112
  505. package/dist/plugin/provider/digitalocean.js +93 -93
  506. package/dist/plugin/provider/dynamic.js +2 -2
  507. package/dist/plugin/provider/factory.js +1 -1
  508. package/dist/plugin/provider/github-copilot.js +95 -95
  509. package/dist/plugin/provider/gitlab.js +93 -93
  510. package/dist/plugin/provider/google-vertex.js +90 -90
  511. package/dist/plugin/provider/kilo.js +1 -1
  512. package/dist/plugin/provider/llmgateway.js +78 -78
  513. package/dist/plugin/provider/lmstudio.js +116 -115
  514. package/dist/plugin/provider/local.js +118 -0
  515. package/dist/plugin/provider/modal.js +92 -92
  516. package/dist/plugin/provider/nvidia.js +1 -1
  517. package/dist/plugin/provider/ollama.js +116 -115
  518. package/dist/plugin/provider/openai.js +95 -95
  519. package/dist/plugin/provider/opencode.js +96 -96
  520. package/dist/plugin/provider/openrouter.js +91 -91
  521. package/dist/plugin/provider/perplexity.js +2 -2
  522. package/dist/plugin/provider/poe.js +79 -79
  523. package/dist/plugin/provider/prompt-cache-key.js +90 -90
  524. package/dist/plugin/provider/sap-ai-core.js +91 -91
  525. package/dist/plugin/provider/sdk-factory.js +1 -1
  526. package/dist/plugin/provider/snowflake-cortex.js +115 -115
  527. package/dist/plugin/provider/vercel.js +90 -90
  528. package/dist/plugin/provider/vllm.js +116 -115
  529. package/dist/plugin/provider/xai.js +91 -91
  530. package/dist/plugin/provider/zenmux.js +1 -1
  531. package/dist/plugin/provider.js +155 -155
  532. package/dist/plugin/sdk.js +76 -76
  533. package/dist/plugin/service.js +3 -3
  534. package/dist/plugin/skill.js +134 -134
  535. package/dist/plugin/source-directory.js +1 -1
  536. package/dist/plugin/supervisor.js +341 -341
  537. package/dist/plugin/tool-input-repair.js +4 -4
  538. package/dist/plugin/update.js +6 -6
  539. package/dist/plugin/vcs/git.js +86 -86
  540. package/dist/plugin/vcs/hg.js +86 -86
  541. package/dist/plugin/verbosity.js +93 -93
  542. package/dist/plugin/warming.js +114 -114
  543. package/dist/plugin/websearch/exa.js +7 -7
  544. package/dist/plugin/websearch/firecrawl.js +8 -8
  545. package/dist/plugin/websearch/index.js +9 -9
  546. package/dist/plugin/websearch/mcp.js +6 -6
  547. package/dist/plugin/websearch/parallel.js +6 -6
  548. package/dist/plugin/websearch/tavily.js +6 -6
  549. package/dist/plugin/websearch/tinyfish.js +8 -8
  550. package/dist/plugin.js +222 -222
  551. package/dist/project/schema.js +2 -2
  552. package/dist/project/sql.js +4 -4
  553. package/dist/project.js +80 -80
  554. package/dist/provider.js +93 -93
  555. package/dist/pty/protocol.js +1 -1
  556. package/dist/pty/ticket.js +1 -1
  557. package/dist/pty.js +99 -99
  558. package/dist/reference/instructions.js +89 -89
  559. package/dist/reference.js +81 -81
  560. package/dist/repository-cache.js +81 -81
  561. package/dist/repository.js +1 -1
  562. package/dist/ripgrep/binary.js +2 -2
  563. package/dist/ripgrep.js +97 -97
  564. package/dist/rpc.js +86 -86
  565. package/dist/schema.js +1 -1
  566. package/dist/session/affinity.js +1 -1
  567. package/dist/session/command.js +74 -74
  568. package/dist/session/compaction.js +129 -129
  569. package/dist/session/context.js +153 -153
  570. package/dist/session/diff.js +88 -88
  571. package/dist/session/environment.js +5 -5
  572. package/dist/session/error.js +3 -3
  573. package/dist/session/event.js +1 -1
  574. package/dist/session/execution/restart.js +214 -214
  575. package/dist/session/execution.js +125 -125
  576. package/dist/session/generate.js +154 -154
  577. package/dist/session/history.js +13 -13
  578. package/dist/session/inbox.js +88 -88
  579. package/dist/session/info.js +3 -3
  580. package/dist/session/instruction-entry.js +79 -79
  581. package/dist/session/instruction-state.js +8 -8
  582. package/dist/session/instructions.js +97 -97
  583. package/dist/session/message-updater.js +2 -2
  584. package/dist/session/message.js +1 -1
  585. package/dist/session/model-request.js +118 -118
  586. package/dist/session/model-transport.js +7 -7
  587. package/dist/session/move.js +129 -129
  588. package/dist/session/projector.js +86 -86
  589. package/dist/session/prompt.js +105 -105
  590. package/dist/session/provider-context.js +3 -3
  591. package/dist/session/revert.js +90 -90
  592. package/dist/session/run-coordinator.js +3 -3
  593. package/dist/session/runner/index.js +3 -3
  594. package/dist/session/runner/llm.js +224 -224
  595. package/dist/session/runner/max-steps.js +1 -1
  596. package/dist/session/runner/model.js +98 -98
  597. package/dist/session/runner/publish-llm-event.js +113 -113
  598. package/dist/session/runner/retry.js +4 -4
  599. package/dist/session/runner/step.js +123 -123
  600. package/dist/session/runner/to-llm-message.js +2 -2
  601. package/dist/session/schema.js +5 -5
  602. package/dist/session/session.js +164 -164
  603. package/dist/session/shell.js +130 -130
  604. package/dist/session/skill.js +103 -103
  605. package/dist/session/sql.js +5 -5
  606. package/dist/session/stats.js +73 -73
  607. package/dist/session/store.js +87 -87
  608. package/dist/session/subagent-completion.js +1 -1
  609. package/dist/session/subagent-job.js +203 -203
  610. package/dist/session/system-prompt.js +5 -5
  611. package/dist/session/title.js +155 -155
  612. package/dist/session/to-session-error.js +111 -111
  613. package/dist/session/transfer.js +207 -207
  614. package/dist/session/usage.js +1 -1
  615. package/dist/session.js +211 -211
  616. package/dist/shell/parse.js +6 -6
  617. package/dist/shell/result.js +1 -1
  618. package/dist/shell/scan.js +1561 -1030
  619. package/dist/shell/select.js +13 -13
  620. package/dist/shell.js +130 -130
  621. package/dist/skill/discovery.js +6 -6
  622. package/dist/skill/instructions.js +107 -107
  623. package/dist/skill.js +110 -110
  624. package/dist/snapshot.js +91 -91
  625. package/dist/state.js +1 -1
  626. package/dist/tool/html-markdown.js +1 -1
  627. package/dist/tool/http-body.js +1 -1
  628. package/dist/tool/mcp.js +126 -126
  629. package/dist/tool/plugin/edit.js +120 -120
  630. package/dist/tool/plugin/file-diff.js +1 -1
  631. package/dist/tool/plugin/glob.js +124 -124
  632. package/dist/tool/plugin/grep.js +124 -124
  633. package/dist/tool/plugin/mcp-resource.js +117 -117
  634. package/dist/tool/plugin/opencode.js +3 -3
  635. package/dist/tool/plugin/patch.js +116 -116
  636. package/dist/tool/plugin/question.js +101 -101
  637. package/dist/tool/plugin/read.js +125 -125
  638. package/dist/tool/plugin/shell.js +210 -210
  639. package/dist/tool/plugin/skill.js +113 -113
  640. package/dist/tool/plugin/subagent.js +212 -212
  641. package/dist/tool/plugin/webfetch.js +112 -112
  642. package/dist/tool/plugin/websearch.js +114 -114
  643. package/dist/tool/plugin/write.js +122 -122
  644. package/dist/tool/read-filesystem.js +100 -100
  645. package/dist/tool/runtime.js +1 -1
  646. package/dist/tool-output.js +7 -7
  647. package/dist/tool.js +14 -14
  648. package/dist/types/aisdk-native.d.ts +1 -0
  649. package/dist/types/mcp/oauth.d.ts +1 -10
  650. package/dist/types/model.d.ts +1 -0
  651. package/dist/types/plugin/provider/chatgpt.d.ts +1 -1
  652. package/dist/types/plugin/provider/lmstudio.d.ts +2 -5
  653. package/dist/types/plugin/provider/local.d.ts +29 -0
  654. package/dist/types/plugin/provider/ollama.d.ts +2 -5
  655. package/dist/types/plugin/provider/vllm.d.ts +2 -5
  656. package/dist/types/shell/scan.d.ts +2 -1
  657. package/dist/util/error-summary.js +1 -1
  658. package/dist/util/error.js +1 -1
  659. package/dist/util/git-executable.js +2 -2
  660. package/dist/util/iife.js +1 -1
  661. package/dist/util/lazy.js +1 -1
  662. package/dist/util/slug.js +1 -1
  663. package/dist/util/token.js +1 -1
  664. package/dist/util/which.js +1 -1
  665. package/dist/util/wildcard.js +1 -1
  666. package/dist/v1/config/agent.js +5 -5
  667. package/dist/v1/config/command.js +3 -3
  668. package/dist/v1/config/error.js +2 -2
  669. package/dist/v1/config/mcp.js +4 -4
  670. package/dist/v1/config/migrate.js +92 -92
  671. package/dist/v1/config/permission.js +3 -3
  672. package/dist/v1/config/plugin.js +3 -3
  673. package/dist/v1/config/provider-options.js +1 -1
  674. package/dist/v1/config/provider.js +4 -4
  675. package/dist/variant.js +93 -93
  676. package/dist/vcs/patch.js +1 -1
  677. package/dist/vcs.js +89 -89
  678. package/dist/websearch.js +82 -82
  679. package/dist/wellknown/plugin.js +74 -74
  680. package/dist/wellknown.js +79 -79
  681. package/dist/workspace/driver.js +3 -3
  682. package/dist/workspace/sql.js +1 -1
  683. package/dist/workspace.js +78 -78
  684. package/dist/worktree/directory.js +2 -2
  685. package/dist/worktree/git.js +10 -10
  686. package/dist/worktree/sql.js +5 -5
  687. package/dist/worktree/strategies.js +89 -89
  688. package/dist/worktree.js +98 -98
  689. package/package.json +9 -10
  690. package/dist/chunks/generate-1vsafbzv.js +0 -173
  691. package/dist/chunks/generate-669tq793.js +0 -15
  692. package/dist/chunks/generate-81f48a1k.js +0 -137
  693. package/dist/chunks/generate-bp27thah.js +0 -145
  694. package/dist/chunks/generate-mzmyqq3a.js +0 -253
  695. package/dist/chunks/generate-phz3h32g.js +0 -18
  696. package/dist/chunks/generate-tc5sgnzb.js +0 -26
  697. package/dist/plugin/provider/gateway.js +0 -7
  698. package/dist/types/plugin/provider/gateway.d.ts +0 -1
  699. /package/dist/chunks/{generate-0qkdqm5v.js → repository-0qkdqm5v.js} +0 -0
  700. /package/dist/chunks/{generate-0zkw76rk.js → repository-0zkw76rk.js} +0 -0
  701. /package/dist/chunks/{generate-17cy0kzp.js → repository-17cy0kzp.js} +0 -0
  702. /package/dist/chunks/{generate-1cnp2v09.js → repository-1cnp2v09.js} +0 -0
  703. /package/dist/chunks/{generate-1kg9ymc8.js → repository-1kg9ymc8.js} +0 -0
  704. /package/dist/chunks/{generate-24dcb14g.js → repository-24dcb14g.js} +0 -0
  705. /package/dist/chunks/{generate-2710q6r3.js → repository-2710q6r3.js} +0 -0
  706. /package/dist/chunks/{generate-2axfhc9x.js → repository-2axfhc9x.js} +0 -0
  707. /package/dist/chunks/{generate-2c3vjs8z.js → repository-2c3vjs8z.js} +0 -0
  708. /package/dist/chunks/{generate-34c7v6d4.js → repository-34c7v6d4.js} +0 -0
  709. /package/dist/chunks/{generate-359p4xyc.js → repository-359p4xyc.js} +0 -0
  710. /package/dist/chunks/{generate-3asan66x.js → repository-3asan66x.js} +0 -0
  711. /package/dist/chunks/{generate-3t0ybcrp.js → repository-3t0ybcrp.js} +0 -0
  712. /package/dist/chunks/{generate-3v8g72cx.js → repository-3v8g72cx.js} +0 -0
  713. /package/dist/chunks/{generate-3w5fmr99.js → repository-3w5fmr99.js} +0 -0
  714. /package/dist/chunks/{generate-3wcehsnq.js → repository-3wcehsnq.js} +0 -0
  715. /package/dist/chunks/{generate-43n2bw4t.js → repository-43n2bw4t.js} +0 -0
  716. /package/dist/chunks/{generate-4knz6hnm.js → repository-4knz6hnm.js} +0 -0
  717. /package/dist/chunks/{generate-4vcrnpx2.js → repository-4vcrnpx2.js} +0 -0
  718. /package/dist/chunks/{generate-4y7fprxs.js → repository-4y7fprxs.js} +0 -0
  719. /package/dist/chunks/{generate-53557ph1.js → repository-53557ph1.js} +0 -0
  720. /package/dist/chunks/{generate-550bvhaj.js → repository-550bvhaj.js} +0 -0
  721. /package/dist/chunks/{generate-6prwharc.js → repository-6prwharc.js} +0 -0
  722. /package/dist/chunks/{generate-7akdwqpd.js → repository-7akdwqpd.js} +0 -0
  723. /package/dist/chunks/{generate-7m9af43g.js → repository-7m9af43g.js} +0 -0
  724. /package/dist/chunks/{generate-822emrt2.js → repository-822emrt2.js} +0 -0
  725. /package/dist/chunks/{generate-88xbtdfr.js → repository-88xbtdfr.js} +0 -0
  726. /package/dist/chunks/{generate-8n3pysct.js → repository-8n3pysct.js} +0 -0
  727. /package/dist/chunks/{generate-8wj87zfr.js → repository-8wj87zfr.js} +0 -0
  728. /package/dist/chunks/{generate-9a4afbnw.js → repository-9a4afbnw.js} +0 -0
  729. /package/dist/chunks/{generate-9rqn6x4v.js → repository-9rqn6x4v.js} +0 -0
  730. /package/dist/chunks/{generate-a6k6eb26.js → repository-a6k6eb26.js} +0 -0
  731. /package/dist/chunks/{generate-af5trqkr.js → repository-af5trqkr.js} +0 -0
  732. /package/dist/chunks/{generate-afrmfg78.js → repository-afrmfg78.js} +0 -0
  733. /package/dist/chunks/{generate-aqzs7mqg.js → repository-aqzs7mqg.js} +0 -0
  734. /package/dist/chunks/{generate-atq7p7m5.js → repository-atq7p7m5.js} +0 -0
  735. /package/dist/chunks/{generate-bkyjaxrp.js → repository-bkyjaxrp.js} +0 -0
  736. /package/dist/chunks/{generate-bmr6ed5q.js → repository-bmr6ed5q.js} +0 -0
  737. /package/dist/chunks/{generate-cf4snx6d.js → repository-cf4snx6d.js} +0 -0
  738. /package/dist/chunks/{generate-cvy3z8tj.js → repository-cvy3z8tj.js} +0 -0
  739. /package/dist/chunks/{generate-d9fn303g.js → repository-d9fn303g.js} +0 -0
  740. /package/dist/chunks/{generate-d9jj8t3e.js → repository-d9jj8t3e.js} +0 -0
  741. /package/dist/chunks/{generate-dajrwvna.js → repository-dajrwvna.js} +0 -0
  742. /package/dist/chunks/{generate-dap0rakb.js → repository-dap0rakb.js} +0 -0
  743. /package/dist/chunks/{generate-df08tz66.js → repository-df08tz66.js} +0 -0
  744. /package/dist/chunks/{generate-dy18nga0.js → repository-dy18nga0.js} +0 -0
  745. /package/dist/chunks/{generate-e3qxr5gk.js → repository-e3qxr5gk.js} +0 -0
  746. /package/dist/chunks/{generate-e5kj55wp.js → repository-e5kj55wp.js} +0 -0
  747. /package/dist/chunks/{generate-e73j6tqm.js → repository-e73j6tqm.js} +0 -0
  748. /package/dist/chunks/{generate-ec1grn59.js → repository-ec1grn59.js} +0 -0
  749. /package/dist/chunks/{generate-eh3zwz77.js → repository-eh3zwz77.js} +0 -0
  750. /package/dist/chunks/{generate-emrn6kk6.js → repository-emrn6kk6.js} +0 -0
  751. /package/dist/chunks/{generate-f0mxakyp.js → repository-f0mxakyp.js} +0 -0
  752. /package/dist/chunks/{generate-f6n9ztr4.js → repository-f6n9ztr4.js} +0 -0
  753. /package/dist/chunks/{generate-faypxj3z.js → repository-faypxj3z.js} +0 -0
  754. /package/dist/chunks/{generate-fd410y7t.js → repository-fd410y7t.js} +0 -0
  755. /package/dist/chunks/{generate-fxgpk5d8.js → repository-fxgpk5d8.js} +0 -0
  756. /package/dist/chunks/{generate-g4wezp1m.js → repository-g4wezp1m.js} +0 -0
  757. /package/dist/chunks/{generate-g86h250q.js → repository-g86h250q.js} +0 -0
  758. /package/dist/chunks/{generate-gebd4c9n.js → repository-gebd4c9n.js} +0 -0
  759. /package/dist/chunks/{generate-gftt206x.js → repository-gftt206x.js} +0 -0
  760. /package/dist/chunks/{generate-hk9envan.js → repository-hk9envan.js} +0 -0
  761. /package/dist/chunks/{generate-j2ntwpah.js → repository-j2ntwpah.js} +0 -0
  762. /package/dist/chunks/{generate-j5zkgpj8.js → repository-j5zkgpj8.js} +0 -0
  763. /package/dist/chunks/{generate-jjkms2e6.js → repository-jjkms2e6.js} +0 -0
  764. /package/dist/chunks/{generate-jr7sbwjy.js → repository-jr7sbwjy.js} +0 -0
  765. /package/dist/chunks/{generate-jwfs4k6c.js → repository-jwfs4k6c.js} +0 -0
  766. /package/dist/chunks/{generate-jzg6c2d5.js → repository-jzg6c2d5.js} +0 -0
  767. /package/dist/chunks/{generate-mp448xyj.js → repository-mp448xyj.js} +0 -0
  768. /package/dist/chunks/{generate-msx8hqn2.js → repository-msx8hqn2.js} +0 -0
  769. /package/dist/chunks/{generate-n05xt0ee.js → repository-n05xt0ee.js} +0 -0
  770. /package/dist/chunks/{generate-n3j8tn72.js → repository-n3j8tn72.js} +0 -0
  771. /package/dist/chunks/{generate-njntx4h6.js → repository-njntx4h6.js} +0 -0
  772. /package/dist/chunks/{generate-q3sfg36h.js → repository-q3sfg36h.js} +0 -0
  773. /package/dist/chunks/{generate-q74kybfr.js → repository-q74kybfr.js} +0 -0
  774. /package/dist/chunks/{generate-qaymkmh1.js → repository-qaymkmh1.js} +0 -0
  775. /package/dist/chunks/{generate-qb87gjwd.js → repository-qb87gjwd.js} +0 -0
  776. /package/dist/chunks/{generate-qfa1cgps.js → repository-qfa1cgps.js} +0 -0
  777. /package/dist/chunks/{generate-qg3g05ea.js → repository-qg3g05ea.js} +0 -0
  778. /package/dist/chunks/{generate-qrg20bc0.js → repository-qrg20bc0.js} +0 -0
  779. /package/dist/chunks/{generate-rcb2kzg1.js → repository-rcb2kzg1.js} +0 -0
  780. /package/dist/chunks/{generate-sdp7kfr6.js → repository-sdp7kfr6.js} +0 -0
  781. /package/dist/chunks/{generate-ssg3fenm.js → repository-ssg3fenm.js} +0 -0
  782. /package/dist/chunks/{generate-w803qqfp.js → repository-w803qqfp.js} +0 -0
  783. /package/dist/chunks/{generate-wc3fc9cn.js → repository-wc3fc9cn.js} +0 -0
  784. /package/dist/chunks/{generate-wer8tq1h.js → repository-wer8tq1h.js} +0 -0
  785. /package/dist/chunks/{generate-wtztk69x.js → repository-wtztk69x.js} +0 -0
  786. /package/dist/chunks/{generate-x0ckcb58.js → repository-x0ckcb58.js} +0 -0
  787. /package/dist/chunks/{generate-x61499pn.js → repository-x61499pn.js} +0 -0
  788. /package/dist/chunks/{generate-y44na4kk.js → repository-y44na4kk.js} +0 -0
  789. /package/dist/chunks/{generate-y8cydn3q.js → repository-y8cydn3q.js} +0 -0
  790. /package/dist/chunks/{generate-y8f7s663.js → repository-y8f7s663.js} +0 -0
  791. /package/dist/chunks/{generate-ygaqb7jw.js → repository-ygaqb7jw.js} +0 -0
  792. /package/dist/chunks/{generate-ym463w8f.js → repository-ym463w8f.js} +0 -0
  793. /package/dist/chunks/{generate-z5v4ffb3.js → repository-z5v4ffb3.js} +0 -0
  794. /package/dist/chunks/{generate-z9919s4g.js → repository-z9919s4g.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "../chunks/generate-9rqn6x4v.js";
3
+ } from "../chunks/repository-9rqn6x4v.js";
4
4
 
5
5
  // src/shell/scan.ts
6
6
  var exports_scan = {};
@@ -10,716 +10,1271 @@ __export(exports_scan, {
10
10
  scanPowerShell: () => scanPowerShell
11
11
  });
12
12
  var BASH_REDIRECTS = ["&>>", "&>", "<<<", "<<-", "<<", "<>", "<&", ">&", ">|", ">>", ">", "<"];
13
- var BASH_DECLARATIONS = new Set(["declare", "typeset", "export", "readonly", "local", "unset", "unsetenv"]);
13
+ var BASH_LIST_OPERATORS = ["&&", "||", "|&"];
14
+ var BASH_CASE_OPERATORS = [";;&", ";;", ";&", ";|", ...BASH_LIST_OPERATORS];
15
+ var BASH_BINDING_BUILTINS = new Set([
16
+ "declare",
17
+ "typeset",
18
+ "local",
19
+ "export",
20
+ "readonly",
21
+ "private",
22
+ "unset",
23
+ "read",
24
+ "getln",
25
+ "vared",
26
+ "getopts",
27
+ "mapfile",
28
+ "readarray",
29
+ "compgen",
30
+ "zparseopts",
31
+ "zregexparse",
32
+ "zformat",
33
+ "zstyle",
34
+ "zstat",
35
+ "stat"
36
+ ]);
37
+ var BASH_ARITHMETIC_COMPARISONS = new Set(["-eq", "-ne", "-lt", "-le", "-gt", "-ge"]);
38
+ var BASH_EXPANSION_RE = /\$(?:\\.|\\\n)*[({]|`/;
39
+ var BASH_ESCAPE_RE = /\\(?:x[\da-fA-F]{1,2}|[0-7]{1,3}|u[\da-fA-F]{1,4}|U[\da-fA-F]{1,8})/;
40
+ var BASH_ASSIGNMENT_DECLARATIONS = new Set(["declare", "typeset", "export", "readonly", "local"]);
41
+ var BASH_DECLARATIONS = new Set([...BASH_ASSIGNMENT_DECLARATIONS, "unset", "unsetenv"]);
42
+ var BASH_PRECOMMANDS = new Set(["builtin", "command", "time", "coproc", "!"]);
43
+ var ZSH_PRECOMMANDS = new Set(["noglob", "nocorrect", "exec", "-"]);
44
+ var ZSH_ARITHMETIC_BUILTINS = new Set([
45
+ "integer",
46
+ "float",
47
+ "exit",
48
+ "return",
49
+ "shift",
50
+ "break",
51
+ "continue",
52
+ "bye",
53
+ "logout"
54
+ ]);
55
+ var BASH_NON_FUNCTION_KEYWORDS = new Set([
56
+ "if",
57
+ "for",
58
+ "select",
59
+ "case",
60
+ "then",
61
+ "elif",
62
+ "else",
63
+ "fi",
64
+ "do",
65
+ "done",
66
+ "in",
67
+ "esac"
68
+ ]);
69
+ var BASH_UNIT_STARTS = "\\$'\"`<>";
14
70
  var MAX_INPUT_LENGTH = 64 * 1024;
15
71
  var MAX_SUBSTITUTION_DEPTH = 32;
16
- function scan(input) {
17
- return scanBash(input, 0, { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH });
72
+ var TOKEN_RE = /[A-Za-z_][A-Za-z0-9_]*(?=(?:\\\n)*(?:[ \t\n;|&()<>]|$))/y;
73
+ var BRACE_CLOSE_AHEAD_RE = /(?:\\\n)*(?:[ \t\n;&|()<>]|$)/y;
74
+ var SPACE_CONTINUATION_AHEAD_RE = /(?:\\\n)*[ \t\n]/y;
75
+ var NEGATION_AHEAD_RE = /(?:\\\n)*[ \t\n(]/y;
76
+ var COPROC_AHEAD_RE = /coproc(?:[ \t]|\\\n)+(?:--(?:[ \t]|\\\n)+)?(?:[A-Za-z_][A-Za-z0-9_]*(?:[ \t]|\\\n)+)?(?=(?:!(?:[ \t]|\\\n)*)*(?:[{(]|\[\[(?:\\\n)*[ \t\n]|(?:if|while|until|for|select|case|repeat)\b))/y;
77
+ var TIME_AHEAD_RE = /time(?:[ \t]|\\\n)+(?:-p(?:[ \t]|\\\n)+)?(?:--(?:[ \t]|\\\n)+)?(?=(?:!(?:[ \t]|\\\n)*)*(?:[{(]|\[\[(?:\\\n)*[ \t\n]|(?:if|while|until|for|select|case|repeat)\b))/y;
78
+ var FUNCTION_HEAD_RE = /(function[ \t](?:[ \t]|\\\n)*)?([A-Za-z_][\w.:+@%-]*)?(?:[ \t]|\\\n)*(\([ \t]*\))?((?:[ \t\n]|\\\n|#[^\n]*\n)*)/y;
79
+ var FUNCTION_BODY_RE = /[{(]|\[\[(?=(?:\\\n)*[ \t\n])|(?:if|while|until|for|select|case|repeat)(?=(?:\\\n)*(?:[ \t\n(]|$))/y;
80
+ var DO_AHEAD_RE = /(?:[ \t\n;]|\\\n|#[^\n]*(?:\n|$))*(?:do(?=(?:\\\n)*(?:[ \t\n;{(]|$))|\{(?=(?:\\\n)*[ \t\n]))/y;
81
+ var NOFORK_OPEN_RE = /\$\{(?:\\\n)*(?:[ \t\n]|\|)/y;
82
+ var ZSH_SAFE_FLAGS_RE = /\$\{\((?:[@AaBbCcDEfFikLMmNnOopqStUuVvWwXZz0-]|q[-+]?|[js]([^({[<\\])(?:(?!\1)[^)])*\1)*\)/y;
83
+ var ZSH_GLOB_MODIFIER_RE = /(?:[\^=~#+]|\\\n)*~/y;
84
+ var ZSH_SUBSCRIPT_RE = /\$(?:[\^=+~#]|\\\n)*(?:[A-Za-z_](?:[A-Za-z0-9_]|\\\n)*|[@*#?$!0-9-])(?:\\\n)*\[/y;
85
+ var LINE_CONTINUATION_RE = /(?:\\\n)*/y;
86
+ var PARAMETER_PREFIX_RE = /(?:\\\n)*(?:\([^)]*\))?(?:[!#^=+~]|\\\n)*/y;
87
+ var PARAMETER_NAME_RE = /(?:[A-Za-z_](?:[A-Za-z0-9_]|\\\n)*|\d(?:\d|\\\n)*|[@*#?$!-])(?:\\\n)*/y;
88
+ var PARAMETER_PROMPT_RE = /@(?:\\\n)*[EP](?:\\\n)*\}/y;
89
+ var BASH_ANSI_ESCAPES = {
90
+ a: "\x07",
91
+ b: "\b",
92
+ e: "\x1B",
93
+ E: "\x1B",
94
+ f: "\f",
95
+ n: `
96
+ `,
97
+ r: "\r",
98
+ t: "\t",
99
+ v: "\v",
100
+ "\\": "\\",
101
+ "'": "'",
102
+ '"': '"',
103
+ "?": "?"
104
+ };
105
+ function scan(input, dialect = "posix") {
106
+ if (input.length > MAX_INPUT_LENGTH)
107
+ return { kind: "opaque", reason: "invalid-structure" };
108
+ const context = { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH, dialect };
109
+ const result = scanBash(input, 0, 0, context);
110
+ if (result.kind === "opaque")
111
+ return result;
112
+ if (context.boundDollar && context.boundOpen && context.variableSink)
113
+ return { kind: "opaque", reason: "dynamic-execution" };
114
+ return { kind: "scanned", commands: result.commands };
115
+ }
116
+ function bashStatement(state) {
117
+ const structure = state.structures.at(-1);
118
+ if (structure)
119
+ structure.count++;
18
120
  }
19
- function scanBash(input, depth, budget) {
20
- budget.remaining -= input.length;
21
- if (input.length > MAX_INPUT_LENGTH || budget.remaining < 0 || depth > MAX_SUBSTITUTION_DEPTH)
121
+ function bashInHeader(state) {
122
+ const phase = state.structures.at(-1)?.phase;
123
+ return phase === "header" || phase === "pattern" || phase === "do";
124
+ }
125
+ function atCommandStart(state) {
126
+ return !state.words.length && !state.hasRedirect && !state.compoundEnd && !bashInHeader(state);
127
+ }
128
+ function pending(state) {
129
+ return state.wordStarted || state.words.length > 0 || state.hasRedirect || state.compoundEnd;
130
+ }
131
+ function endBashList(state) {
132
+ if (pending(state))
133
+ finishBashCommand(state);
134
+ return !state.dangling;
135
+ }
136
+ function closeBashList(state, end) {
137
+ if (!endBashList(state))
22
138
  return { kind: "opaque", reason: "invalid-structure" };
23
- const commands = [];
24
- const nestedCommands = [];
25
- const words = [];
26
- const rawWords = [];
27
- const assignmentWords = [];
28
- let word = "";
29
- let wordStarted = false;
30
- let wordStart = 0;
31
- let wordEnd = 0;
32
- let commandEnd = 0;
33
- let resourceEnd;
34
- let redirectWordCount;
35
- let assignmentWord = false;
36
- let assignmentHeadUnsafe = false;
37
- let segment = 0;
38
- let quote;
39
- let invalidRedirect = false;
40
- let invalidStructure = false;
41
- let separated = false;
42
- let redirectTarget = false;
43
- let hasRedirect = false;
44
- let dangling = false;
45
- let inList = false;
46
- let compoundEnd = false;
47
- const heredocs = [];
48
- const structures = [];
49
- const addSubstitutions = (substitution) => {
50
- for (const source of substitution.substitutions ?? [substitution.source]) {
51
- const result = scanBash(source, depth + 1, budget);
52
- if (result.kind === "opaque")
53
- return result;
54
- nestedCommands.push(...result.commands);
55
- }
56
- };
57
- const statement = () => {
58
- const structure = structures.at(-1);
59
- if (structure)
60
- structure.count++;
61
- };
62
- const header = () => ["header", "pattern", "do"].includes(structures.at(-1)?.phase ?? "");
63
- const finishWord = () => {
64
- if (!wordStarted)
65
- return;
66
- if (!redirectTarget) {
67
- words.push(word);
68
- rawWords.push(input.slice(wordStart, wordEnd));
69
- assignmentWords.push(assignmentWord);
70
- commandEnd = wordEnd;
139
+ if (state.invalid)
140
+ return { kind: "opaque", reason: state.invalid };
141
+ if (state.structures.length)
142
+ return { kind: "opaque", reason: "compound-command" };
143
+ return { kind: "scanned", commands: state.commands, end };
144
+ }
145
+ function finishBashWord(state) {
146
+ if (!state.wordStarted)
147
+ return;
148
+ if (/PS4/.test(state.word))
149
+ state.context.variableSink = true;
150
+ const evaluation = bashWordEvaluation(state);
151
+ if (state.context.dialect !== "bash" && (/(?:READ)?NULLCMD/.test(state.word) || (state.assignmentWord || evaluation === "binding") && /^(?:-[A-Za-z]*v)?(?:(?:dis_)?(?:functions|[gs]?aliases)|options|commands)(?:\+?=|\[|$)/.test(state.word)))
152
+ state.invalid ??= "dynamic-execution";
153
+ if (evaluation && bashEvaluatesExpansion(state, evaluation, state.context))
154
+ state.invalid ??= "dynamic-execution";
155
+ if (state.outer)
156
+ state.outer.output += ` ${state.literal} ${state.output}`;
157
+ const structure = state.structures.at(-1);
158
+ const repeatHeader = structure?.kind === "repeat" && structure.phase === "header";
159
+ if (!state.redirectTarget && repeatHeader)
160
+ structure.phase = "do";
161
+ if (!state.redirectTarget && !repeatHeader) {
162
+ if (!state.assignmentWord && state.commandWordIndex < 0)
163
+ state.commandWordIndex = state.words.length;
164
+ state.commandStart ??= state.wordStart;
165
+ state.words.push(state.word);
166
+ state.rawWords.push(state.input.slice(state.wordStart, state.wordEnd));
167
+ state.commandEnd = state.wordEnd;
168
+ }
169
+ state.redirectTarget = false;
170
+ state.hereString = false;
171
+ state.word = "";
172
+ state.literal = "";
173
+ state.output = "";
174
+ state.wordStarted = false;
175
+ state.assignmentWord = false;
176
+ state.assignmentHeadUnsafe = false;
177
+ }
178
+ function bashWordEvaluation(state) {
179
+ if (state.redirectTarget)
180
+ return state.hereString ? "deferred" : undefined;
181
+ const structure = state.structures.at(-1);
182
+ if (structure?.kind === "repeat" && structure.phase === "header")
183
+ return "arithmetic";
184
+ if (structure?.kind === "for" && structure.phase === "header" && structure.sawIn)
185
+ return "deferred";
186
+ if (state.commandWordIndex < 0)
187
+ return state.assignmentWord ? "deferred" : undefined;
188
+ const name = bashBuiltinIndex(state);
189
+ const command = state.words[name];
190
+ if (command === undefined)
191
+ return;
192
+ if (command === "let" || state.context.dialect !== "bash" && ZSH_ARITHMETIC_BUILTINS.has(command))
193
+ return "arithmetic";
194
+ if (command === "set")
195
+ return state.words.slice(name + 1).some((word) => /^[-+][A-Za-z0-9]*A/.test(word)) ? "binding" : "deferred";
196
+ if (BASH_BINDING_BUILTINS.has(command)) {
197
+ const options = state.words.slice(name + 1);
198
+ if (options.some((word) => word.startsWith("-") && /[EFin]/.test(word)))
199
+ return "arithmetic";
200
+ if (state.assignmentWord && BASH_ASSIGNMENT_DECLARATIONS.has(command) && options.every((word) => !word.startsWith("-")) && (command === "export" || command === "readonly" || state.context.dialect === "zsh" || !/\+?=(?:\(|[$`])/.test(state.word)))
201
+ return "deferred";
202
+ return "binding";
203
+ }
204
+ if (command === "printf" || command === "print") {
205
+ const options = [...state.words.slice(name + 1), state.word];
206
+ const flag = command === "print" ? /^-[A-Za-z]*v/ : /^-v/;
207
+ return options.some((word) => flag.test(word)) ? "binding" : undefined;
208
+ }
209
+ if (command === "wait")
210
+ return /^-[nf]*p/.test(state.word) || /^-[nf]*p$/.test(state.words.at(-1) ?? "") ? "binding" : undefined;
211
+ if (command === "test" || command === "[") {
212
+ if (state.words.at(-1) === "-v")
213
+ return "binding";
214
+ if (state.context.dialect !== "bash" && state.words.at(-1) === "-t")
215
+ return "arithmetic";
216
+ }
217
+ return;
218
+ }
219
+ function bashBuiltinIndex(state) {
220
+ let name = state.commandWordIndex;
221
+ while (BASH_PRECOMMANDS.has(state.words[name] ?? "") || state.context.dialect !== "bash" && ZSH_PRECOMMANDS.has(state.words[name] ?? "")) {
222
+ const precommand = state.words[name++];
223
+ while (precommand !== "-" && state.words[name]?.startsWith("-")) {
224
+ if (precommand === "exec" && /^-[cl]*a$/.test(state.words[name]))
225
+ name++;
226
+ name++;
71
227
  }
72
- redirectTarget = false;
73
- word = "";
74
- wordStarted = false;
75
- assignmentWord = false;
76
- assignmentHeadUnsafe = false;
77
- };
78
- const finishCommand = (boundary = false) => {
79
- finishWord();
80
- if (redirectTarget)
81
- invalidRedirect = true;
82
- redirectTarget = false;
83
- if (compoundEnd && words.length > 0)
84
- invalidStructure = true;
85
- const resource = input.slice(segment, resourceEnd ?? wordEnd).replace(/^[ \t\n]+|[ \t\n]+$/g, "");
86
- const name = assignmentWords.findIndex((assignment) => !assignment);
87
- if (name >= 0 && !words[name])
88
- invalidStructure = true;
89
- if (rawWords[name] === "}")
90
- invalidStructure = true;
91
- if (resource && name >= 0 && !header()) {
92
- const command = {
93
- resource,
94
- words: words.slice(name),
95
- rawWords: rawWords.slice(name),
96
- ...name === 0 && BASH_DECLARATIONS.has(rawWords[0]) && resource.startsWith(rawWords[0]) ? { declaration: true } : {},
97
- ...redirectWordCount !== undefined && redirectWordCount < words.length ? { redirectWordCount: redirectWordCount - name } : {}
98
- };
99
- commands.push(command);
100
- if (resourceEnd === undefined) {
101
- for (const heredoc of heredocs) {
102
- if (heredoc.command)
103
- continue;
104
- heredoc.command = command;
105
- heredoc.start = segment;
106
- }
228
+ }
229
+ return name;
230
+ }
231
+ function finishBashCommand(state, boundary = false) {
232
+ finishBashWord(state);
233
+ if (state.redirectTarget)
234
+ state.invalid ??= "invalid-redirect";
235
+ state.redirectTarget = false;
236
+ if (state.compoundEnd && state.words.length > 0)
237
+ state.invalid ??= "invalid-structure";
238
+ const name = state.commandWordIndex;
239
+ const inHeader = bashInHeader(state);
240
+ if (name >= 0 && !state.words[name])
241
+ state.invalid ??= "invalid-structure";
242
+ if (name >= 0 && !inHeader) {
243
+ const resource = state.input.slice(state.commandStart, state.resourceEnd ?? state.wordEnd).replace(/^[ \t\n]+|[ \t\n]+$/g, "");
244
+ const command = {
245
+ resource,
246
+ words: state.words.slice(name),
247
+ rawWords: state.rawWords.slice(name),
248
+ ...name === 0 && BASH_DECLARATIONS.has(state.rawWords[0]) && resource.startsWith(state.rawWords[0]) ? { declaration: true } : {},
249
+ ...state.redirectWordCount !== undefined && state.redirectWordCount < state.words.length ? { redirectWordCount: state.redirectWordCount - name } : {}
250
+ };
251
+ state.commands.push(command);
252
+ const builtin = bashBuiltinIndex(state);
253
+ const builtinName = state.words[builtin];
254
+ const builtinArgs = state.words.slice(builtin + 1);
255
+ if (builtinName === "eval")
256
+ state.context.variableSink = true;
257
+ if (builtinName === "set" && builtinArgs.some((word) => /^-[A-Za-z0-9]*k/.test(word) || word === "keyword"))
258
+ state.invalid ??= "dynamic-execution";
259
+ if (builtinName === "alias" && builtinArgs.some((word) => word.includes("=")))
260
+ state.invalid ??= "dynamic-execution";
261
+ if (state.context.dialect !== "bash" && (builtinName === "emulate" || (builtinName === "setopt" || builtinName === "unsetopt" || builtinName === "set" && builtinArgs.some((word) => /^[-+][A-Za-z0-9]*o/.test(word))) && builtinArgs.some((word) => /^-[A-Za-z0-9]*m/.test(word) || /^(?:no)?(?:globsubst|kshglob|promptsubst|promptvars|aliases)$/.test(word.replace(/^[-+][A-Za-z0-9]*?o/i, "").toLowerCase().replace(/[_-]/g, "")))))
262
+ state.invalid ??= "dynamic-execution";
263
+ if (state.context.dialect !== "zsh" && builtinName === "compgen" && builtinArgs.some((word) => word.startsWith("-") && /[CF]/.test(word)))
264
+ state.invalid ??= "dynamic-execution";
265
+ if (BASH_BINDING_BUILTINS.has(builtinName ?? "")) {
266
+ for (const heredoc of state.heredocs)
267
+ heredoc.binding ??= true;
268
+ }
269
+ if (state.resourceEnd === undefined) {
270
+ for (const heredoc of state.heredocs) {
271
+ if (heredoc.command)
272
+ continue;
273
+ heredoc.command = command;
274
+ heredoc.start = state.commandStart;
107
275
  }
108
- } else if (!header() && !compoundEnd && (hasRedirect || boundary || separated)) {
109
- const assignmentOnly = assignmentWords.length > 0 && assignmentWords.every(Boolean);
110
- if (!assignmentOnly && !hasRedirect)
111
- invalidStructure = true;
112
276
  }
113
- commands.push(...nestedCommands.splice(0));
114
- if (!header() && (words.length > 0 || hasRedirect))
115
- statement();
116
- words.length = 0;
117
- rawWords.length = 0;
118
- assignmentWords.length = 0;
119
- separated = true;
120
- hasRedirect = false;
121
- resourceEnd = undefined;
122
- redirectWordCount = undefined;
123
- compoundEnd = false;
277
+ }
278
+ if (boundary && !state.words.length && !state.hasRedirect && !state.compoundEnd && !inHeader)
279
+ state.invalid ??= "invalid-structure";
280
+ if (state.words.length > (state.ampersandRedirectWords ?? Infinity))
281
+ state.invalid ??= "invalid-redirect";
282
+ state.commands.push(...state.nestedCommands.splice(0));
283
+ if (!inHeader && (state.words.length > 0 || state.hasRedirect))
284
+ bashStatement(state);
285
+ state.words.length = 0;
286
+ state.rawWords.length = 0;
287
+ state.commandWordIndex = -1;
288
+ state.commandStart = undefined;
289
+ state.hasRedirect = false;
290
+ state.resourceEnd = undefined;
291
+ state.redirectWordCount = undefined;
292
+ state.ampersandRedirectWords = undefined;
293
+ state.compoundEnd = false;
294
+ state.dangling = false;
295
+ }
296
+ function scanBash(input, start, depth, context, close, heredocs, outer) {
297
+ if (depth > MAX_SUBSTITUTION_DEPTH || context.remaining < 0)
298
+ return { kind: "opaque", reason: "invalid-structure" };
299
+ const state = {
300
+ input,
301
+ context,
302
+ commands: [],
303
+ nestedCommands: [],
304
+ words: [],
305
+ rawWords: [],
306
+ heredocs: heredocs ?? [],
307
+ structures: [],
308
+ word: "",
309
+ literal: "",
310
+ output: "",
311
+ wordStarted: false,
312
+ wordStart: start,
313
+ wordEnd: start,
314
+ commandStart: undefined,
315
+ commandEnd: start,
316
+ resourceEnd: undefined,
317
+ redirectWordCount: undefined,
318
+ ampersandRedirectWords: undefined,
319
+ commandWordIndex: -1,
320
+ assignmentWord: false,
321
+ assignmentHeadUnsafe: false,
322
+ invalid: undefined,
323
+ redirectTarget: false,
324
+ hereString: false,
325
+ hasRedirect: false,
326
+ compoundEnd: false,
327
+ dangling: false,
328
+ outer
124
329
  };
125
- for (let index = 0;index < input.length; index++) {
330
+ for (let index = start;index < input.length; index++) {
331
+ if (--context.remaining < 0)
332
+ return { kind: "opaque", reason: "invalid-structure" };
126
333
  const char = input[index];
127
- if (!wordStarted)
128
- wordStart = index;
129
- if (!quote && !wordStarted) {
334
+ if (char === "\\" && input[index + 1] === `
335
+ `) {
336
+ index++;
337
+ continue;
338
+ }
339
+ if (!state.wordStarted) {
340
+ state.wordStart = index;
130
341
  if (char === " " || char === "\t")
131
342
  continue;
132
- const structure = structures.at(-1);
133
- const token = /^[A-Za-z_][A-Za-z0-9_]*(?=[ \t\n;()<>]|$)/.exec(input.slice(index))?.[0];
134
- if (structure?.kind === "case" && structure.phase === "header" && token === "in") {
135
- finishCommand();
136
- structure.phase = "pattern";
137
- index += token.length - 1;
138
- segment = index + 1;
139
- continue;
140
- }
141
- if (structure?.phase === "pattern" && (char === "(" || char === "|"))
142
- continue;
143
- if (structure?.phase === "pattern" && char === ")") {
144
- finishCommand();
145
- structure.phase = "body";
146
- structure.count = 0;
147
- segment = index + 1;
148
- continue;
149
- }
150
- if (structure?.kind === "for" && structure.phase === "header" && char === "(" && input[index + 1] !== "(") {
151
- const values = bashExpansion(input, index, depth, "array");
152
- if (!values)
153
- return { kind: "opaque", reason: "compound-command" };
154
- finishCommand();
155
- const failure = addSubstitutions(values);
156
- if (failure)
157
- return failure;
158
- commands.push(...nestedCommands.splice(0));
159
- structure.phase = "do";
160
- if (!/^(?:[ \t\n;]|\\\n|#[^\n]*(?:\n|$))*do(?=[ \t\n;]|$)/.test(input.slice(values.end + 1)))
161
- structures.pop();
162
- index = values.end;
163
- segment = index + 1;
164
- continue;
165
- }
166
- if (!words.length && !hasRedirect && !compoundEnd) {
167
- const definition = bashFunctionHead(input, index);
168
- if (definition && !header()) {
169
- index += definition.length - 1;
170
- segment = index + 1;
171
- continue;
172
- }
173
- if (!header() && (token === "if" || token === "while" || token === "until" || token === "for" || token === "select" || token === "case")) {
174
- if (depth + structures.length >= MAX_SUBSTITUTION_DEPTH)
175
- return { kind: "opaque", reason: "compound-command" };
176
- structures.push({
177
- kind: token === "select" ? "for" : token,
178
- phase: ["for", "select", "case"].includes(token) ? "header" : "condition",
179
- count: 0
180
- });
181
- index += token.length - 1;
182
- segment = index + 1;
183
- inList = false;
184
- continue;
185
- }
186
- if (token && ["then", "elif", "else", "fi", "do", "done", "esac"].includes(token) && (!header() || token === "do" && structure?.phase === "do" || token === "esac" && structure?.phase === "pattern")) {
187
- if (!structure || dangling)
188
- return { kind: "opaque", reason: "compound-command" };
189
- if (token === "then") {
190
- if (structure.kind !== "if" || structure.phase !== "condition" || !structure.count)
191
- return { kind: "opaque", reason: "compound-command" };
192
- structure.phase = "body";
193
- } else if (token === "elif" || token === "else") {
194
- if (structure.kind !== "if" || structure.phase !== "body" || !structure.count || structure.sawElse)
195
- return { kind: "opaque", reason: "compound-command" };
196
- structure.phase = token === "elif" ? "condition" : "body";
197
- structure.sawElse = token === "else";
198
- } else if (token === "do") {
199
- if (!["for", "while", "until"].includes(structure.kind) || !["condition", "do"].includes(structure.phase) || structure.kind !== "for" && !structure.count)
200
- return { kind: "opaque", reason: "compound-command" };
201
- structure.phase = "body";
202
- } else {
203
- if (token === "fi" && (structure.kind !== "if" || structure.phase !== "body" || !structure.count) || token === "done" && (!["for", "while", "until"].includes(structure.kind) || structure.phase !== "body" || !structure.count) || token === "esac" && (structure.kind !== "case" || structure.phase === "header"))
204
- return { kind: "opaque", reason: "compound-command" };
205
- structures.pop();
206
- statement();
207
- compoundEnd = true;
208
- dangling = false;
209
- }
210
- structure.count = 0;
211
- index += token.length - 1;
212
- segment = index + 1;
213
- inList = false;
214
- continue;
215
- }
216
- if (!header() && (char === "!" && /[ \t\n]/.test(input[index + 1] ?? "") || token === "coproc" && /^coproc[ \t]+(?:[A-Za-z_][A-Za-z0-9_]*[ \t]+)?(?:[{(]|(?:if|while|until|for|case)\b)/.test(input.slice(index)) || token === "time" && /^time[ \t]+(?:-p[ \t]+)?(?:[{(]|(?:if|while|until|for|case)\b)/.test(input.slice(index)))) {
217
- index += token ? token.length - 1 : 0;
218
- if (token === "time")
219
- index += /^[ \t]+-p\b/.exec(input.slice(index + 1))?.[0].length ?? 0;
220
- if (token === "coproc")
221
- index += /^[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t]+(?=[{(]|(?:if|while|until|for|case)\b)/.exec(input.slice(index + 1))?.[0].length ?? 0;
222
- segment = index + 1;
223
- continue;
224
- }
225
- }
226
- if ((!words.length && !hasRedirect && !header() || structure?.kind === "for" && structure.phase === "header") && input.startsWith("((", index)) {
227
- const expression = bashExpansion(input, index, depth, "arithmetic");
228
- if (!expression)
229
- return { kind: "opaque", reason: "invalid-structure" };
230
- const failure = addSubstitutions(expression);
231
- if (failure)
232
- return failure;
233
- commands.push(...nestedCommands.splice(0));
234
- statement();
235
- compoundEnd = !header();
236
- dangling = false;
237
- index = expression.end;
238
- segment = index + 1;
239
- continue;
240
- }
241
- if (!words.length && !hasRedirect && !header() && (char === "(" || char === "{" && /[ \t\n]/.test(input[index + 1] ?? ""))) {
242
- const group = bashDelimited(input, index, depth);
243
- if (!group || !group.source.trim())
244
- return { kind: "opaque", reason: "invalid-structure" };
245
- const result = scanBash(group.source, depth + 1, budget);
246
- if (result.kind === "opaque")
247
- return result;
248
- commands.push(...result.commands);
249
- statement();
250
- compoundEnd = true;
251
- dangling = false;
252
- index = group.end;
253
- segment = index + 1;
343
+ if (char === "}" && state.words.length === 0 && !state.redirectTarget && (close === "}" || close === "nofork") && state.structures.length === 0 && (heredocs !== undefined || state.heredocs.length === 0) && (close === "nofork" || (BRACE_CLOSE_AHEAD_RE.lastIndex = index + 1, BRACE_CLOSE_AHEAD_RE.test(input))))
344
+ return closeBashList(state, index);
345
+ if (char === "}")
346
+ return { kind: "opaque", reason: state.structures.length ? "compound-command" : "invalid-structure" };
347
+ const step = scanBashCommandStart(state, index, depth, context);
348
+ if (typeof step === "object")
349
+ return step;
350
+ if (step !== undefined) {
351
+ index = step;
254
352
  continue;
255
353
  }
256
- if (!words.length && !hasRedirect && input.startsWith("[[", index)) {
257
- const expression = bashExpansion(input, index, depth, "test");
258
- if (!expression)
354
+ }
355
+ if (char === "\\" && index + 1 >= input.length)
356
+ return { kind: "opaque", reason: "unterminated-escape" };
357
+ if (!state.assignmentWord && (`'"\\`.includes(char) || char === "$" && (input[index + 1] === "'" || input[index + 1] === '"')))
358
+ state.assignmentHeadUnsafe = true;
359
+ const inCasePattern = state.structures.at(-1)?.phase === "pattern";
360
+ const array = (char === "=" || char === "(") && state.assignmentWord && state.word.length > 1 && state.word.endsWith("=") && !state.word.endsWith("==") && (state.commandWordIndex < 0 || BASH_ASSIGNMENT_DECLARATIONS.has(state.rawWords[state.commandWordIndex]));
361
+ if (char === "=" && (!state.wordStarted || array) && input[index + 1] === "(") {
362
+ const end = scanBashNested(input, index + 2, depth, context, state.nestedCommands, ")");
363
+ if (typeof end === "object")
364
+ return end;
365
+ state.wordStarted = true;
366
+ state.word += input.slice(index, end + 1);
367
+ index = end;
368
+ state.wordEnd = index + 1;
369
+ continue;
370
+ }
371
+ const unit = BASH_UNIT_STARTS.includes(char) ? scanBashUnit(input, index, depth, context, state.nestedCommands, "word", !state.assignmentWord && state.commandWordIndex >= 0 && !BASH_DECLARATIONS.has(state.rawWords[0]), state) : undefined;
372
+ if (typeof unit === "object")
373
+ return unit;
374
+ if (unit !== undefined) {
375
+ state.wordStarted = true;
376
+ index = unit;
377
+ state.wordEnd = index + 1;
378
+ continue;
379
+ }
380
+ if (char === "[" && !inCasePattern && !state.assignmentWord && !state.assignmentHeadUnsafe && state.commandWordIndex < 0 && /^[A-Za-z_][A-Za-z0-9_]*$/.test(state.word)) {
381
+ const subscript = [];
382
+ const end = scanBashSubscript(input, index + 1, depth, context, subscript, BASH_SPANS.assignmentSubscript);
383
+ if (typeof end === "object")
384
+ return end;
385
+ const assign = bashOperator(input, end + 1, ["+=", "="]);
386
+ if (typeof assign === "object")
387
+ return assign;
388
+ if (assign) {
389
+ if (context.dialect === "posix" && /[$`]/.test(input.slice(index + 1, end)))
259
390
  return { kind: "opaque", reason: "invalid-structure" };
260
- const failure = addSubstitutions(expression);
261
- if (failure)
262
- return failure;
263
- commands.push(...nestedCommands.splice(0));
264
- statement();
265
- compoundEnd = true;
266
- dangling = false;
267
- index = expression.end;
268
- segment = index + 1;
391
+ state.nestedCommands.push(...subscript);
392
+ state.assignmentWord = true;
393
+ state.word += input.slice(index, end + 1);
394
+ index = end;
395
+ state.wordEnd = index + 1;
269
396
  continue;
270
397
  }
271
398
  }
272
- if (quote === "single") {
273
- wordStarted = true;
274
- wordEnd = index + 1;
275
- if (char === "'")
276
- quote = undefined;
277
- else
278
- word += char;
279
- continue;
280
- }
281
- if (quote === "double") {
282
- wordStarted = true;
283
- if (char === '"')
284
- quote = undefined;
285
- else if (char === "\\" && index + 1 < input.length) {
286
- const next = input[index + 1];
287
- if ('$`"\\\n'.includes(next)) {
288
- index++;
289
- if (next !== `
290
- `)
291
- word += next;
292
- } else
293
- word += char;
294
- } else if (char === "$" && "({[".includes(input[index + 1] ?? "\x00") || char === "`") {
295
- const substitution = bashExpansion(input, index, depth, undefined, true);
296
- if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
297
- return { kind: "opaque", reason: "command-substitution" };
298
- const failure = addSubstitutions(substitution);
299
- if (failure)
300
- return failure;
301
- word += input.slice(index, substitution.end + 1);
302
- index = substitution.end;
303
- } else
304
- word += char;
305
- wordEnd = index + 1;
306
- continue;
307
- }
308
- if (char === "$" && input[index + 1] === "'") {
309
- const literal = bashAnsiQuote(input, index + 1);
310
- if (!literal)
311
- return { kind: "opaque", reason: "unterminated-quote" };
312
- wordStarted = true;
313
- if (!assignmentWord)
314
- assignmentHeadUnsafe = true;
315
- word += literal.value;
316
- index = literal.end;
317
- wordEnd = index + 1;
318
- continue;
319
- }
320
- if (char === "$" && input[index + 1] === '"') {
321
- quote = "double";
322
- wordStarted = true;
323
- if (!assignmentWord)
324
- assignmentHeadUnsafe = true;
325
- wordEnd = ++index + 1;
326
- continue;
327
- }
328
- if (char === "'") {
329
- quote = "single";
330
- wordStarted = true;
331
- wordEnd = index + 1;
332
- if (!assignmentWord)
333
- assignmentHeadUnsafe = true;
334
- continue;
335
- }
336
- if (char === '"') {
337
- quote = "double";
338
- wordStarted = true;
339
- wordEnd = index + 1;
340
- if (!assignmentWord)
341
- assignmentHeadUnsafe = true;
342
- continue;
343
- }
344
- if (char === "\\") {
345
- if (index + 1 >= input.length)
346
- return { kind: "opaque", reason: "unterminated-escape" };
347
- if (input[index + 1] === `
348
- `)
349
- index++;
350
- else {
351
- wordStarted = true;
352
- if (!assignmentWord)
353
- assignmentHeadUnsafe = true;
354
- word += input[++index];
355
- wordEnd = index + 1;
356
- }
357
- continue;
358
- }
359
- if (char === "$" && "({[".includes(input[index + 1] ?? "\x00") || char === "`" || char === "[" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(word) && /^\[[\s\S]*?\]\+?=/.test(input.slice(index)) || char === "(" && (assignmentWord || /[?*+@!]$/.test(word))) {
360
- const substitution = char === "(" ? bashExpansion(input, index, depth, assignmentWord ? "array" : "pattern") : char === "[" ? bashExpansion(input, index, depth, "subscript") : bashExpansion(input, index, depth);
361
- if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
362
- return { kind: "opaque", reason: "command-substitution" };
363
- const failure = addSubstitutions(substitution);
364
- if (failure)
365
- return failure;
366
- wordStarted = true;
367
- word += input.slice(index, substitution.end + 1);
368
- index = substitution.end;
369
- wordEnd = index + 1;
370
- continue;
371
- }
372
- if ((char === "<" || char === ">" || char === "=" && !wordStarted) && input[index + 1] === "(") {
373
- const substitution = bashDelimited(input, index + 1, depth);
374
- if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
375
- return { kind: "opaque", reason: "command-substitution" };
376
- const failure = addSubstitutions(substitution);
377
- if (failure)
378
- return failure;
379
- wordStarted = true;
380
- word += input.slice(index, substitution.end + 1);
381
- index = substitution.end;
382
- wordEnd = index + 1;
399
+ if (char === "(" && (array || (inCasePattern || context.dialect === "bash") && /[?*+@!]$/.test(state.word))) {
400
+ const mode = array ? "array" : "pattern";
401
+ const end = scanBashArrayOrPattern(input, index, depth + 1, context, state.nestedCommands, mode);
402
+ if (typeof end === "object")
403
+ return end;
404
+ if (bashCrossesHeredoc(state, index, end))
405
+ return { kind: "opaque", reason: "heredoc" };
406
+ if (array && end + 1 < input.length && !`
407
+ ;&|<>)`.includes(input[end + 1]))
408
+ return { kind: "opaque", reason: "invalid-structure" };
409
+ state.wordStarted = true;
410
+ state.word += input.slice(index, end + 1);
411
+ index = end;
412
+ state.wordEnd = index + 1;
383
413
  continue;
384
414
  }
385
- if (char === "#" && !wordStarted) {
415
+ if (char === "#" && !state.wordStarted) {
386
416
  const newline = input.indexOf(`
387
417
  `, index);
388
- if (words.length > 0 || hasRedirect) {
389
- finishCommand();
390
- dangling = false;
391
- inList = false;
392
- }
393
418
  if (newline === -1)
394
419
  break;
395
420
  index = newline - 1;
396
- segment = newline;
397
421
  continue;
398
422
  }
399
- const redirect = "<>&".includes(char) ? BASH_REDIRECTS.find((candidate) => input.startsWith(candidate, index)) : undefined;
400
- if (redirect) {
401
- hasRedirect = true;
402
- if (redirectTarget)
403
- invalidRedirect = true;
404
- if (wordStarted && !assignmentHeadUnsafe && /^(?:\d+|\{[A-Za-z_][A-Za-z0-9_]*\})$/.test(word)) {
405
- if (wordEnd < index)
406
- commandEnd = wordEnd;
407
- word = "";
408
- wordStarted = false;
409
- } else
410
- finishWord();
411
- if (redirectWordCount === undefined && assignmentWords.some((assignment) => !assignment)) {
412
- redirectWordCount = words.length;
413
- if (inList)
414
- resourceEnd = commandEnd;
415
- }
416
- if (redirect === "<<" || redirect === "<<-") {
417
- const delimiter = bashHeredocDelimiter(input, index);
418
- if (!delimiter)
419
- return { kind: "opaque", reason: "invalid-redirect" };
420
- heredocs.push(delimiter);
421
- wordEnd = delimiter.end + 1;
422
- index = delimiter.end;
423
- redirectTarget = false;
424
- continue;
425
- }
426
- redirectTarget = true;
427
- index += redirect.length - 1;
423
+ if (`<>&|;
424
+ `.includes(char)) {
425
+ const step = scanBashOperatorOrSeparator(state, index, depth, context);
426
+ if (typeof step === "object")
427
+ return step;
428
+ index = step;
428
429
  continue;
429
430
  }
430
- if (structures.at(-1)?.phase === "pattern" && (char === ")" || char === "|")) {
431
- finishWord();
431
+ if (inCasePattern && char === ")") {
432
+ finishBashWord(state);
432
433
  index--;
433
434
  continue;
434
435
  }
435
- if ("()".includes(char))
436
- return { kind: "opaque", reason: "compound-command" };
436
+ if (char === ")") {
437
+ if (close !== ")" || state.structures.length > 0 || heredocs === undefined && state.heredocs.length > 0)
438
+ return { kind: "opaque", reason: "compound-command" };
439
+ return closeBashList(state, index);
440
+ }
441
+ if (char === "(")
442
+ return { kind: "opaque", reason: state.wordStarted ? "dynamic-execution" : "compound-command" };
437
443
  if (/\s/.test(char) && !`
438
444
  `.includes(char))
439
445
  return { kind: "opaque", reason: "invalid-structure" };
440
446
  if (char === " " || char === "\t") {
441
- finishWord();
447
+ finishBashWord(state);
442
448
  continue;
443
449
  }
444
- const next = input[index + 1];
445
- const separator = char === "&" && next === "&" || char === "|" && (next === "|" || next === "&") ? char + next : char === ";" || char === "|" || char === "&" || char === `
446
- ` ? char : undefined;
447
- if (separator) {
448
- const structure = structures.at(-1);
449
- if (char === ";" && structure?.kind === "case" && structure.phase === "body" && (next === ";" || next === "&")) {
450
- if (wordStarted || words.length || hasRedirect || compoundEnd)
451
- finishCommand();
452
- structure.phase = "pattern";
453
- index += input.startsWith(";;&", index) ? 2 : 1;
454
- segment = index + 1;
455
- inList = false;
456
- continue;
457
- }
458
- if (separator === `
459
- ` && !wordStarted && words.length === 0 && !hasRedirect && !compoundEnd) {
460
- if (heredocs.length) {
461
- for (const heredoc of heredocs.splice(0)) {
462
- const body = bashHeredoc(input, index + 1, heredoc);
463
- if (!body)
464
- return { kind: "opaque", reason: "heredoc" };
465
- if (heredoc.command)
466
- heredoc.command.resource = input.slice(heredoc.start, body.end).trim();
467
- if (!heredoc.quoted) {
468
- const expansion = bashExpansion(body.source, 0, depth, "heredoc");
469
- if (!expansion)
470
- return { kind: "opaque", reason: "command-substitution" };
471
- const failure = addSubstitutions(expansion);
472
- if (failure)
473
- return failure;
474
- commands.push(...nestedCommands.splice(0));
475
- }
476
- index = body.end;
477
- }
478
- }
479
- segment = index + 1;
480
- continue;
450
+ state.wordStarted = true;
451
+ if (char === "=" && !state.assignmentWord && !state.assignmentHeadUnsafe && /^[A-Za-z_][A-Za-z0-9_]*\+?$/.test(state.word))
452
+ state.assignmentWord = true;
453
+ bashAppend(state, char);
454
+ state.wordEnd = index + 1;
455
+ }
456
+ if (close)
457
+ return { kind: "opaque", reason: close === ")" ? "command-substitution" : "invalid-structure" };
458
+ if (state.heredocs.length)
459
+ return { kind: "opaque", reason: "heredoc" };
460
+ return closeBashList(state, input.length);
461
+ }
462
+ function scanBashOperatorOrSeparator(state, index, depth, context) {
463
+ const input = state.input;
464
+ const char = input[index];
465
+ const redirect = "<>&".includes(char) ? bashOperator(input, index, BASH_REDIRECTS) : undefined;
466
+ if (typeof redirect === "object")
467
+ return redirect;
468
+ const caseHead = state.structures.at(-1);
469
+ if (redirect && caseHead?.kind === "case" && caseHead.phase !== "body")
470
+ return { kind: "opaque", reason: "invalid-redirect" };
471
+ if (redirect) {
472
+ state.hasRedirect = true;
473
+ state.commandStart ??= state.wordStart;
474
+ if (state.redirectTarget)
475
+ state.invalid ??= "invalid-redirect";
476
+ const fdPrefix = state.wordStarted && !state.assignmentHeadUnsafe && /^(?:\d+|\{[A-Za-z_][A-Za-z0-9_]*\})$/.test(state.word);
477
+ if (fdPrefix) {
478
+ if (state.wordEnd < index)
479
+ state.commandEnd = state.wordEnd;
480
+ state.word = "";
481
+ state.literal = "";
482
+ state.output = "";
483
+ state.wordStarted = false;
484
+ }
485
+ if (!fdPrefix)
486
+ finishBashWord(state);
487
+ if (redirect.startsWith("&") && context.dialect === "posix")
488
+ state.ampersandRedirectWords ??= state.words.length;
489
+ if (state.redirectWordCount === undefined && state.commandWordIndex >= 0) {
490
+ state.redirectWordCount = state.words.length;
491
+ if (state.dangling)
492
+ state.resourceEnd = state.commandEnd;
493
+ }
494
+ if (redirect === "<<" || redirect === "<<-") {
495
+ const delimiter = bashHeredocDelimiter(input, index + redirect.length, redirect === "<<-");
496
+ if (!delimiter)
497
+ return { kind: "opaque", reason: "invalid-redirect" };
498
+ state.heredocs.push(delimiter);
499
+ state.wordEnd = delimiter.end + 1;
500
+ state.redirectTarget = false;
501
+ return delimiter.end;
502
+ }
503
+ state.redirectTarget = true;
504
+ state.hereString = redirect === "<<<";
505
+ return index + redirect.length - 1;
506
+ }
507
+ if (state.structures.at(-1)?.phase === "pattern" && char === "|") {
508
+ finishBashWord(state);
509
+ return index - 1;
510
+ }
511
+ const structure = state.structures.at(-1);
512
+ const caseBody = structure?.kind === "case" && structure.phase === "body";
513
+ const operator = bashOperator(input, index, caseBody ? BASH_CASE_OPERATORS : BASH_LIST_OPERATORS);
514
+ if (typeof operator === "object")
515
+ return operator;
516
+ const separator = operator ?? char;
517
+ if (caseBody && separator.startsWith(";") && separator.length > 1) {
518
+ if (!endBashList(state))
519
+ return { kind: "opaque", reason: "invalid-structure" };
520
+ structure.phase = "pattern";
521
+ structure.patternStarted = false;
522
+ return index + separator.length - 1;
523
+ }
524
+ if (structure?.kind === "case" && (structure.phase === "header" || structure.phase === "pattern")) {
525
+ if (separator !== `
526
+ `)
527
+ return { kind: "opaque", reason: "compound-command" };
528
+ if (structure.phase === "pattern" && (state.wordStarted || state.words.length > 0))
529
+ return { kind: "opaque", reason: "compound-command" };
530
+ finishBashWord(state);
531
+ return readBashHeredocs(state, index, depth, context);
532
+ }
533
+ if ((structure?.kind === "for" || structure?.kind === "repeat") && (structure.phase === "header" || structure.phase === "do")) {
534
+ if (separator !== ";" && separator !== `
535
+ `)
536
+ return { kind: "opaque", reason: "compound-command" };
537
+ if (structure.phase === "header" && !structure.sawIn && !state.wordStarted && state.words.length === 0)
538
+ return { kind: "opaque", reason: "compound-command" };
539
+ }
540
+ if (separator === `
541
+ ` && !pending(state))
542
+ return readBashHeredocs(state, index, depth, context);
543
+ finishBashCommand(state, true);
544
+ if (structure?.kind === "for" && structure.phase === "header")
545
+ structure.phase = "do";
546
+ state.dangling = separator !== "&" && separator !== ";" && separator !== `
547
+ `;
548
+ if (separator === `
549
+ ` && state.heredocs.length)
550
+ return index - 1;
551
+ return index + separator.length - 1;
552
+ }
553
+ function bashCommandKey(command) {
554
+ return JSON.stringify([command.resource, command.words]);
555
+ }
556
+ function readBashHeredocs(state, index, depth, context) {
557
+ let end = index;
558
+ for (const heredoc of state.heredocs.splice(0)) {
559
+ const body = bashHeredoc(state.input, end + 1, heredoc);
560
+ if (!body)
561
+ return { kind: "opaque", reason: "heredoc" };
562
+ if (heredoc.command)
563
+ heredoc.command.resource = state.input.slice(heredoc.start, body.end).trim();
564
+ const text = heredoc.quoted ? { word: body.source, literal: body.source, output: "" } : bashText();
565
+ if (!heredoc.quoted) {
566
+ const expansion = scanBashSpan(body.source, 0, depth, context, state.commands, BASH_SPANS.heredoc, true, text);
567
+ if (typeof expansion === "object")
568
+ return expansion;
569
+ }
570
+ if (heredoc.binding)
571
+ bashEvaluatesExpansion(text, "deferred", context);
572
+ end = body.end;
573
+ }
574
+ return end;
575
+ }
576
+ function bashCrossesHeredoc(state, start, end) {
577
+ return state.heredocs.length > 0 && state.input.slice(start, end).includes(`
578
+ `);
579
+ }
580
+ function scanBashCommandStart(state, index, depth, context) {
581
+ const input = state.input;
582
+ const char = input[index];
583
+ const structure = state.structures.at(-1);
584
+ if (structure?.phase === "pattern" && !structure.patternStarted && !state.words.length && char === "(") {
585
+ structure.patternStarted = true;
586
+ return index;
587
+ }
588
+ if (structure?.phase === "pattern" && char === "|") {
589
+ if (!state.words.length)
590
+ return { kind: "opaque", reason: "compound-command" };
591
+ finishBashWord(state);
592
+ structure.patternStarted = true;
593
+ return index;
594
+ }
595
+ if (structure?.phase === "pattern" && char === ")") {
596
+ if (!state.words.length)
597
+ return { kind: "opaque", reason: "compound-command" };
598
+ finishBashCommand(state);
599
+ structure.phase = "body";
600
+ structure.count = 0;
601
+ return index;
602
+ }
603
+ if (structure?.kind === "for" && structure.phase === "header" && char === "(" && input[index + 1] !== "(") {
604
+ const end = scanBashArrayOrPattern(input, index, depth + 1, context, state.nestedCommands, "array");
605
+ if (typeof end === "object")
606
+ return end;
607
+ if (bashCrossesHeredoc(state, index, end))
608
+ return { kind: "opaque", reason: "heredoc" };
609
+ finishBashCommand(state);
610
+ structure.phase = "do";
611
+ structure.parenthesized = true;
612
+ DO_AHEAD_RE.lastIndex = end + 1;
613
+ if (!DO_AHEAD_RE.test(input))
614
+ state.structures.pop();
615
+ return end;
616
+ }
617
+ if (structure?.kind === "repeat" && structure.phase === "do" && char !== `
618
+ ` && char !== "#" && char !== ";") {
619
+ TOKEN_RE.lastIndex = index;
620
+ if (TOKEN_RE.exec(input)?.[0] !== "do")
621
+ state.structures.pop();
622
+ }
623
+ const keywordStep = scanBashKeyword(state, index, depth, context);
624
+ if (keywordStep !== undefined)
625
+ return keywordStep;
626
+ if (structure?.kind === "for" && structure.phase === "do" && char !== `
627
+ ` && char !== "#" && char !== ";") {
628
+ SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 1;
629
+ if (char !== "{" || !SPACE_CONTINUATION_AHEAD_RE.test(input))
630
+ return { kind: "opaque", reason: "compound-command" };
631
+ state.structures.pop();
632
+ }
633
+ const atStart = atCommandStart(state);
634
+ const functionHead = atStart && char === "(" ? bashFunctionHeadLength(input, index) : 0;
635
+ if (functionHead)
636
+ return index + functionHead - 1;
637
+ if (atStart && char === "!") {
638
+ NEGATION_AHEAD_RE.lastIndex = index + 1;
639
+ if (NEGATION_AHEAD_RE.test(input))
640
+ return index;
641
+ }
642
+ const forHeader = structure?.kind === "for" && structure.phase === "header";
643
+ const compoundOpen = (atStart || forHeader) && "([".includes(char) ? bashOperator(input, index, ["((", "[["]) : undefined;
644
+ if (typeof compoundOpen === "object")
645
+ return compoundOpen;
646
+ if (compoundOpen === "((") {
647
+ if (forHeader && state.words.length > 0)
648
+ return { kind: "opaque", reason: "compound-command" };
649
+ const span = forHeader ? BASH_SPANS.forArithmetic : BASH_SPANS.arithmetic;
650
+ const end = scanBashArithmetic(input, index + 2, depth, context, state.commands, span);
651
+ if (typeof end === "number") {
652
+ if (bashCrossesHeredoc(state, index, end))
653
+ return { kind: "opaque", reason: "heredoc" };
654
+ if (!forHeader && context.dialect === "posix") {
655
+ const subshells = scanBash(input, index + 1, depth + 1, context, ")");
656
+ if (subshells.kind === "opaque")
657
+ return subshells;
658
+ if (subshells.end !== end)
659
+ return { kind: "opaque", reason: "compound-command" };
660
+ const seen = new Set(state.commands.map(bashCommandKey));
661
+ state.commands.push(...subshells.commands.filter((command) => !seen.has(bashCommandKey(command))));
481
662
  }
482
- finishCommand(true);
483
- if (structure?.kind === "for" && structure.phase === "header")
663
+ if (forHeader) {
484
664
  structure.phase = "do";
485
- dangling = separator !== "&" && separator !== ";" && separator !== `
486
- `;
487
- inList = dangling;
488
- if (separator === `
489
- ` && heredocs.length) {
490
- index--;
491
- continue;
665
+ structure.sawIn = true;
492
666
  }
493
- index += separator.length - 1;
494
- segment = index + 1;
495
- continue;
667
+ if (!forHeader) {
668
+ bashStatement(state);
669
+ state.compoundEnd = true;
670
+ }
671
+ return end;
496
672
  }
497
- wordStarted = true;
498
- if (char === "=" && !assignmentHeadUnsafe && /^[A-Za-z_][A-Za-z0-9_]*(?:\[.*\])?\+?$/.test(word))
499
- assignmentWord = true;
500
- word += char;
501
- wordEnd = index + 1;
673
+ if (end)
674
+ return end;
675
+ if (forHeader)
676
+ return { kind: "opaque", reason: "invalid-structure" };
502
677
  }
503
- if (quote)
504
- return { kind: "opaque", reason: "unterminated-quote" };
505
- if (heredocs.length)
506
- return { kind: "opaque", reason: "heredoc" };
507
- if (wordStarted || words.length > 0 || hasRedirect) {
508
- finishCommand();
509
- dangling = false;
678
+ if (atStart && (char === "(" || char === "{" && (SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 1, SPACE_CONTINUATION_AHEAD_RE.test(input)))) {
679
+ const group = scanBash(input, index + 1, depth + 1, context, char === "{" ? "}" : ")", state.heredocs);
680
+ if (group.kind === "opaque")
681
+ return group;
682
+ if (!input.slice(index + 1, group.end).trim())
683
+ return { kind: "opaque", reason: "invalid-structure" };
684
+ state.commands.push(...group.commands);
685
+ bashStatement(state);
686
+ state.compoundEnd = true;
687
+ return group.end;
510
688
  }
511
- if (dangling)
512
- invalidStructure = true;
513
- if (invalidStructure)
514
- return { kind: "opaque", reason: "invalid-structure" };
515
- if (invalidRedirect)
516
- return { kind: "opaque", reason: "invalid-redirect" };
517
- if (structures.length)
518
- return { kind: "opaque", reason: "compound-command" };
519
- return { kind: "scanned", commands };
689
+ if (atStart && compoundOpen === "[[" && (SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 2, SPACE_CONTINUATION_AHEAD_RE.test(input))) {
690
+ const end = scanBashConditional(input, index + 2, depth, context, state.commands);
691
+ if (typeof end === "object")
692
+ return end;
693
+ if (bashCrossesHeredoc(state, index, end))
694
+ return { kind: "opaque", reason: "heredoc" };
695
+ bashStatement(state);
696
+ state.compoundEnd = true;
697
+ return end;
698
+ }
699
+ return;
700
+ }
701
+ function scanBashKeyword(state, index, depth, context) {
702
+ const input = state.input;
703
+ const char = input[index];
704
+ if (!(char >= "A" && char <= "Z" || char >= "a" && char <= "z" || char === "_"))
705
+ return;
706
+ const structure = state.structures.at(-1);
707
+ TOKEN_RE.lastIndex = index;
708
+ const token = TOKEN_RE.exec(input)?.[0];
709
+ const end = index + (token?.length ?? 0) - 1;
710
+ if (structure?.kind === "case" && structure.phase === "header" && token === "in") {
711
+ if (state.words.length !== 1 || state.hasRedirect)
712
+ return { kind: "opaque", reason: "compound-command" };
713
+ finishBashCommand(state);
714
+ structure.phase = "pattern";
715
+ structure.patternStarted = false;
716
+ return end;
717
+ }
718
+ if (structure?.kind === "for" && (structure.phase === "header" || structure.phase === "do") && !structure.sawIn && !structure.parenthesized && token === "in" && (structure.phase === "do" || state.words.length >= 1)) {
719
+ structure.sawIn = true;
720
+ structure.phase = "header";
721
+ return end;
722
+ }
723
+ if (structure?.phase === "pattern" && !structure.patternStarted && !state.words.length && token === "esac") {
724
+ state.structures.pop();
725
+ bashStatement(state);
726
+ state.compoundEnd = true;
727
+ return end;
728
+ }
729
+ if (structure?.kind === "for" && structure.phase === "header" && !structure.sawIn && state.words.length === 1 && !state.hasRedirect && token === "do") {
730
+ finishBashCommand(state);
731
+ structure.phase = "do";
732
+ }
733
+ const inHeader = bashInHeader(state);
734
+ if (token && ["then", "elif", "else", "fi", "do", "done", "esac"].includes(token) && !state.words.length && !state.redirectTarget && (!inHeader || token === "do" && structure?.phase === "do")) {
735
+ if (state.hasRedirect && context.dialect !== "zsh" || !endBashList(state) || !structure)
736
+ return { kind: "opaque", reason: "compound-command" };
737
+ if (token === "then") {
738
+ if (structure.kind !== "if" || structure.phase !== "condition" || !structure.count)
739
+ return { kind: "opaque", reason: "compound-command" };
740
+ structure.phase = "body";
741
+ structure.count = 0;
742
+ return end;
743
+ }
744
+ if (token === "elif" || token === "else") {
745
+ if (structure.kind !== "if" || structure.phase !== "body" || !structure.count || structure.sawElse)
746
+ return { kind: "opaque", reason: "compound-command" };
747
+ structure.phase = token === "elif" ? "condition" : "body";
748
+ structure.sawElse = token === "else";
749
+ structure.count = 0;
750
+ return end;
751
+ }
752
+ if (token === "do") {
753
+ if (!["for", "while", "until", "repeat"].includes(structure.kind) || !["condition", "do"].includes(structure.phase) || structure.kind !== "for" && structure.kind !== "repeat" && !structure.count)
754
+ return { kind: "opaque", reason: "compound-command" };
755
+ structure.phase = "body";
756
+ structure.count = 0;
757
+ return end;
758
+ }
759
+ if (token === "fi" && (structure.kind !== "if" || structure.phase !== "body" || !structure.count) || token === "done" && (!["for", "while", "until", "repeat"].includes(structure.kind) || structure.phase !== "body" || !structure.count) || token === "esac" && (structure.kind !== "case" || structure.phase === "header"))
760
+ return { kind: "opaque", reason: "compound-command" };
761
+ state.structures.pop();
762
+ bashStatement(state);
763
+ state.compoundEnd = true;
764
+ return end;
765
+ }
766
+ if (!atCommandStart(state))
767
+ return;
768
+ const definitionLength = bashFunctionHeadLength(input, index);
769
+ if (definitionLength > 0)
770
+ return index + definitionLength - 1;
771
+ if (token === "if" || token === "while" || token === "until" || token === "for" || token === "select" || token === "case" || token === "repeat" && context.dialect !== "bash") {
772
+ if (depth + state.structures.length >= MAX_SUBSTITUTION_DEPTH)
773
+ return { kind: "opaque", reason: "compound-command" };
774
+ state.structures.push({
775
+ kind: token === "select" ? "for" : token,
776
+ phase: ["for", "select", "case", "repeat"].includes(token) ? "header" : "condition",
777
+ count: 0
778
+ });
779
+ state.dangling = false;
780
+ return end;
781
+ }
782
+ if (token === "coproc") {
783
+ COPROC_AHEAD_RE.lastIndex = index;
784
+ const coprocMatch = COPROC_AHEAD_RE.exec(input)?.[0];
785
+ if (coprocMatch)
786
+ return index + coprocMatch.length - 1;
787
+ }
788
+ if (token === "time") {
789
+ TIME_AHEAD_RE.lastIndex = index;
790
+ const timeMatch = TIME_AHEAD_RE.exec(input)?.[0];
791
+ if (timeMatch)
792
+ return index + timeMatch.length - 1;
793
+ }
794
+ return;
795
+ }
796
+ function bashFunctionHeadLength(input, start) {
797
+ FUNCTION_HEAD_RE.lastIndex = start;
798
+ const head = FUNCTION_HEAD_RE.exec(input);
799
+ if (!head || (head[1] ? !head[2] : !head[3] || BASH_NON_FUNCTION_KEYWORDS.has(head[2] ?? "")))
800
+ return 0;
801
+ FUNCTION_BODY_RE.lastIndex = start + head[0].length;
802
+ return FUNCTION_BODY_RE.test(input) ? head[0].length - head[4].length : 0;
803
+ }
804
+ var BASH_SPANS = {
805
+ double: { close: '"', reject: "", mode: "quoted" },
806
+ heredoc: { reject: "", mode: "quoted" },
807
+ arithmetic: { open: "(", close: ")", reject: ";#}", mode: "arithmetic" },
808
+ forArithmetic: { open: "(", close: ")", reject: "#}", mode: "arithmetic" },
809
+ bracketArithmetic: { close: "]", reject: `;|&<>()[
810
+ '"\\#`, mode: "arithmetic" },
811
+ subscript: { open: "[", close: "]", reject: '"}', mode: "arithmetic" },
812
+ quotedSubscript: { open: "[", close: "]", reject: '"', mode: "quoted" },
813
+ assignmentSubscript: { open: "[", close: "]", reject: `
814
+ \r\v\f;&|<>()`, mode: "arithmetic" },
815
+ arithmeticQuote: { close: "'", reject: '()[];"}', mode: "quoted" },
816
+ arithmeticDouble: { close: '"', reject: "()[];}", mode: "quoted" },
817
+ parameterQuote: { close: "'", reject: '"}[]', mode: "quoted" }
818
+ };
819
+ function scanBashUnit(input, index, depth, context, commands, mode, allowBracket, text) {
820
+ const char = input[index];
821
+ const next = input[index + 1] ?? "\x00";
822
+ if (char === "\\") {
823
+ if (mode === "quoted" && !'$`"\\\n'.includes(next))
824
+ return;
825
+ if (text && next !== `
826
+ `)
827
+ bashAppend(text, input.slice(index + 1, index + 2));
828
+ return index + 1;
829
+ }
830
+ if (char === "$" && context.dialect !== "bash" && zshEvaluates(input, index))
831
+ return { kind: "opaque", reason: "dynamic-execution" };
832
+ if (char === "$" && context.dialect !== "bash" && (mode === "word" || mode === "quoted") && (ZSH_SUBSCRIPT_RE.lastIndex = index, ZSH_SUBSCRIPT_RE.test(input))) {
833
+ const bracket = ZSH_SUBSCRIPT_RE.lastIndex;
834
+ const subscript = bashText();
835
+ const span = mode === "quoted" ? BASH_SPANS.quotedSubscript : BASH_SPANS.subscript;
836
+ const end = scanBashSpan(input, bracket, depth, context, commands, span, false, subscript);
837
+ if (typeof end === "object")
838
+ return end;
839
+ if (bashEvaluatesExpansion(subscript, "arithmetic", context))
840
+ return { kind: "opaque", reason: "dynamic-execution" };
841
+ if (text)
842
+ text.word += `${input.slice(index, bracket)}${subscript.word}]`;
843
+ return end;
844
+ }
845
+ const opener = char === "$" ? bashOperator(input, index, ["$$", "$((", "$(", "${", "$[", "$'", '$"']) : mode === "word" && (char === "<" || char === ">") ? bashOperator(input, index, [`${char}(`]) : undefined;
846
+ if (typeof opener === "object")
847
+ return opener;
848
+ if (opener === "$$") {
849
+ LINE_CONTINUATION_RE.lastIndex = index + 2;
850
+ const quoteStart = LINE_CONTINUATION_RE.exec(input) ? LINE_CONTINUATION_RE.lastIndex : index + 2;
851
+ if (input[quoteStart] === "'") {
852
+ const nextQuote = input.indexOf("'", quoteStart + 1);
853
+ if (nextQuote < 0)
854
+ return { kind: "opaque", reason: "unterminated-quote" };
855
+ if (input.slice(quoteStart + 1, nextQuote).includes("\\") && input.includes("'", nextQuote + 1))
856
+ return { kind: "opaque", reason: "unterminated-quote" };
857
+ }
858
+ if (text)
859
+ text.word += "$$";
860
+ return index + 1;
861
+ }
862
+ if (mode === "word" && opener === "$'") {
863
+ const quote = bashAnsiQuote(input, index + 1);
864
+ if (!quote)
865
+ return { kind: "opaque", reason: "unterminated-quote" };
866
+ const firstQuote = input.indexOf("'", index + 2);
867
+ if (quote.end !== firstQuote && (context.dialect !== "bash" && index >= 2 && input[index - 2] === "$" || context.dialect === "posix" && (input.indexOf("'", firstQuote + 1) < quote.end || /[#"\n]|\\'/.test(input.slice(firstQuote + 1)))))
868
+ return { kind: "opaque", reason: "unterminated-quote" };
869
+ if (text)
870
+ bashAppend(text, quote.value);
871
+ return quote.end;
872
+ }
873
+ if (mode === "arithmetic" && opener === "$'") {
874
+ const quote = bashAnsiQuote(input, index + 1);
875
+ if (!quote || quote.end !== input.indexOf("'", index + 2) || /[()[\];"}]/.test(quote.value))
876
+ return { kind: "opaque", reason: "invalid-structure" };
877
+ if (text)
878
+ bashAppend(text, quote.value);
879
+ return scanBashSpan(input, index + 2, depth, context, commands, BASH_SPANS.arithmeticQuote, allowBracket, text);
880
+ }
881
+ if (mode === "word" && char === "'") {
882
+ const end = input.indexOf("'", index + 1);
883
+ if (end < 0)
884
+ return { kind: "opaque", reason: "unterminated-quote" };
885
+ if (text)
886
+ bashAppend(text, input.slice(index + 1, end));
887
+ return end;
888
+ }
889
+ if (mode === "arithmetic" && char === "'")
890
+ return scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.arithmeticQuote, allowBracket, text);
891
+ if (mode === "word" && opener === '$"')
892
+ return scanBashSpan(input, index + 2, depth, context, commands, BASH_SPANS.double, allowBracket, text);
893
+ if (mode !== "quoted" && char === '"') {
894
+ const span = mode === "arithmetic" ? BASH_SPANS.arithmeticDouble : BASH_SPANS.double;
895
+ return scanBashSpan(input, index + 1, depth, context, commands, span, allowBracket, text);
896
+ }
897
+ const end = opener === "<(" || opener === ">(" ? scanBashNested(input, index + 2, depth, context, commands, ")") : opener && opener !== "$'" && opener !== '$"' || char === "`" ? scanBashDollarOrBacktick(input, index, depth, context, commands, mode !== "word", allowBracket, text) : undefined;
898
+ if (end === undefined && char === "$" && /[A-Za-z_0-9@*#?$!-]/.test(next)) {
899
+ if (text)
900
+ text.word += "$";
901
+ return index;
902
+ }
903
+ if (text && typeof end === "number")
904
+ text.word += input.slice(index, end + 1);
905
+ return end;
906
+ }
907
+ function zshEvaluates(input, index) {
908
+ let at = index + 1;
909
+ if (input.startsWith("{\\\n", at))
910
+ return true;
911
+ if (input[at] === "{" && input[at + 1] === "(") {
912
+ ZSH_SAFE_FLAGS_RE.lastIndex = index;
913
+ if (!ZSH_SAFE_FLAGS_RE.test(input))
914
+ return true;
915
+ at = ZSH_SAFE_FLAGS_RE.lastIndex;
916
+ }
917
+ if (input[at] === "{")
918
+ at++;
919
+ ZSH_GLOB_MODIFIER_RE.lastIndex = at;
920
+ return ZSH_GLOB_MODIFIER_RE.test(input);
921
+ }
922
+ function bashAppend(text, value) {
923
+ text.word += value;
924
+ text.literal += value;
520
925
  }
521
- function bashFunctionHead(input, start) {
522
- return /^(?!if(?:[ \t]|\\\n)*\()(?:function[ \t]+(?:\\\n[ \t]*)*[A-Za-z_][A-Za-z0-9_.:-]*(?:(?:[ \t]|\\\n)*\([ \t]*\))?|(?:[A-Za-z_][A-Za-z0-9_.:-]*(?:[ \t]|\\\n)*)?\([ \t]*\))(?:[ \t\n]|\\\n|#[^\n]*(?:\n|$))*(?=[{(]|\[\[(?=[ \t\n])|(?:if|while|until|for|select|case)[ \t\n])/.exec(input.slice(start))?.[0];
926
+ function bashEvaluatesExpansion(text, evaluation, context) {
927
+ const combined = `${text.literal} ${text.output}`;
928
+ const hasExpansion = BASH_EXPANSION_RE.test(combined);
929
+ const hasEscape = BASH_ESCAPE_RE.test(text.literal);
930
+ if (hasExpansion || hasEscape || /[$`]/.test(text.literal))
931
+ context.boundDollar = true;
932
+ if (hasExpansion || hasEscape || /[({`]/.test(text.literal))
933
+ context.boundOpen = true;
934
+ if (evaluation === "deferred")
935
+ return false;
936
+ if (evaluation === "arithmetic" ? /[A-Za-z_]|(?:\$(?![?#!-]|\$(?!\[)))/.test(text.word) : text.word.includes("$") || combined.includes("["))
937
+ context.variableSink = true;
938
+ if (evaluation === "arithmetic")
939
+ return hasExpansion;
940
+ return combined.includes("[") && hasExpansion;
941
+ }
942
+ function bashText() {
943
+ return { word: "", literal: "", output: "" };
944
+ }
945
+ function scanBashSubscript(input, start, depth, context, commands, span = BASH_SPANS.subscript) {
946
+ const text = bashText();
947
+ const end = scanBashSpan(input, start, depth, context, commands, span, false, text);
948
+ if (typeof end === "number" && bashEvaluatesExpansion(text, "arithmetic", context))
949
+ return { kind: "opaque", reason: "dynamic-execution" };
950
+ return end;
951
+ }
952
+ function scanBashSpan(input, start, depth, context, commands, span, allowBracket, text) {
953
+ let nesting = 0;
954
+ for (let index = start;index < input.length; index++) {
955
+ if (--context.remaining < 0)
956
+ return { kind: "opaque", reason: "invalid-structure" };
957
+ const char = input[index];
958
+ if (char === span.close && !nesting)
959
+ return index;
960
+ if (span.reject.includes(char) && !(char === "#" && /[\d$]/.test(input[index - 1] ?? "")))
961
+ return { kind: "opaque", reason: "invalid-structure" };
962
+ if (char === span.open && ++nesting + depth > MAX_SUBSTITUTION_DEPTH)
963
+ return { kind: "opaque", reason: "invalid-structure" };
964
+ if (char === span.close)
965
+ nesting--;
966
+ const unit = char === span.open || char === span.close ? undefined : scanBashUnit(input, index, depth, context, commands, span.mode, allowBracket, text);
967
+ if (typeof unit === "object")
968
+ return unit;
969
+ if (unit !== undefined)
970
+ index = unit;
971
+ else if (char === "\\" && (input[index + 1] === span.open || input[index + 1] === span.close)) {
972
+ if (text)
973
+ bashAppend(text, input.slice(index, index + 2));
974
+ index++;
975
+ } else if (text)
976
+ bashAppend(text, char);
977
+ }
978
+ return span.close ? { kind: "opaque", reason: "unterminated-quote" } : input.length;
979
+ }
980
+ function scanBashNested(input, start, depth, context, commands, close, text) {
981
+ const nested = scanBash(input, start, depth + 1, context, close, undefined, text);
982
+ if (nested.kind === "opaque")
983
+ return nested;
984
+ commands.push(...nested.commands);
985
+ return nested.end;
986
+ }
987
+ function bashOperator(input, index, operators) {
988
+ let text = "";
989
+ for (let cursor = index;text.length < 3 && cursor < input.length; cursor++) {
990
+ if (input.startsWith("\\\n", cursor))
991
+ cursor++;
992
+ else
993
+ text += input[cursor];
994
+ }
995
+ const operator = operators.find((candidate) => text.startsWith(candidate));
996
+ if (operator && !input.startsWith(operator, index))
997
+ return { kind: "opaque", reason: "invalid-structure" };
998
+ return operator;
523
999
  }
524
- function bashDelimited(input, start, depth) {
1000
+ function scanBashDollarOrBacktick(input, start, depth, context, commands, quoted, allowBracket, text) {
525
1001
  if (depth >= MAX_SUBSTITUTION_DEPTH)
1002
+ return { kind: "opaque", reason: "command-substitution" };
1003
+ if (input[start] === "`")
1004
+ return scanBashBacktick(input, start, depth + 1, context, commands, quoted, text);
1005
+ if (input.startsWith("$((", start)) {
1006
+ const end = scanBashArithmetic(input, start + 3, depth + 1, context, commands, BASH_SPANS.arithmetic);
1007
+ if (end !== undefined)
1008
+ return end;
1009
+ }
1010
+ if (input.startsWith("$(", start))
1011
+ return scanBashNested(input, start + 2, depth, context, commands, ")", text);
1012
+ NOFORK_OPEN_RE.lastIndex = start;
1013
+ const nofork = NOFORK_OPEN_RE.exec(input);
1014
+ if (nofork)
1015
+ return scanBashNested(input, start + nofork[0].length, depth, context, commands, "nofork", text);
1016
+ if (input.startsWith("${", start)) {
1017
+ const parameter = bashText();
1018
+ const end = scanBashParameter(input, start + 2, depth + 1, context, commands, quoted, parameter);
1019
+ if (/^(?:\\\n)*!/.test(input.slice(start + 2))) {
1020
+ context.variableSink = true;
1021
+ if (bashEvaluatesExpansion(parameter, "binding", context))
1022
+ return { kind: "opaque", reason: "dynamic-execution" };
1023
+ }
1024
+ if (text) {
1025
+ text.literal += parameter.literal;
1026
+ text.output += parameter.output;
1027
+ }
1028
+ return end;
1029
+ }
1030
+ if (!allowBracket && context.dialect === "posix")
1031
+ return { kind: "opaque", reason: "command-substitution" };
1032
+ const expression = bashText();
1033
+ const end = scanBashSpan(input, start + 2, depth + 1, context, commands, BASH_SPANS.bracketArithmetic, true, expression);
1034
+ if (typeof end === "number" && bashEvaluatesExpansion(expression, "arithmetic", context))
1035
+ return { kind: "opaque", reason: "dynamic-execution" };
1036
+ return end;
1037
+ }
1038
+ function scanBashArithmetic(input, start, depth, context, commands, span) {
1039
+ const arithmetic = [];
1040
+ const text = bashText();
1041
+ const end = scanBashSpan(input, start, depth, context, arithmetic, span, true, text);
1042
+ if (typeof end === "object")
1043
+ return { kind: "opaque", reason: "invalid-structure" };
1044
+ const close = bashOperator(input, end, ["))"]);
1045
+ if (typeof close === "object")
1046
+ return close;
1047
+ if (!close)
526
1048
  return;
527
- const close = input[start] === "{" ? "}" : ")";
528
- const cases = [];
529
- const heredocs = [];
530
- let commandStart = true;
1049
+ if (bashEvaluatesExpansion(text, "arithmetic", context))
1050
+ return { kind: "opaque", reason: "dynamic-execution" };
1051
+ commands.push(...arithmetic);
1052
+ return end + 1;
1053
+ }
1054
+ function scanBashBacktick(input, start, depth, context, commands, quoted, text) {
1055
+ let source = "";
531
1056
  for (let index = start + 1;index < input.length; index++) {
532
- const char = input[index];
533
- if (char === " " || char === "\t")
534
- continue;
535
- if (char === "\\") {
536
- if (input[index + 1] !== `
537
- `)
538
- commandStart = false;
539
- index++;
540
- continue;
1057
+ if (--context.remaining < 0)
1058
+ return { kind: "opaque", reason: "invalid-structure" };
1059
+ if (input[index] === "`") {
1060
+ const inner = scanBash(source, 0, depth, context, undefined, undefined, text);
1061
+ if (inner.kind === "opaque")
1062
+ return { kind: "opaque", reason: "command-substitution" };
1063
+ commands.push(...inner.commands);
1064
+ return index;
541
1065
  }
542
- if (char === "'" || char === '"' || char === "`" || char === "$" && `({['"`.includes(input[index + 1] ?? "\x00")) {
543
- commandStart = false;
544
- if (char === "'" || input.startsWith("$'", index)) {
545
- const end = char === "'" ? input.indexOf("'", index + 1) : bashAnsiQuote(input, index + 1)?.end;
546
- if (end === undefined || end < 0)
547
- return;
548
- index = end;
549
- continue;
550
- }
551
- const nested = char === '"' || input.startsWith('$"', index) ? bashExpansion(input, index + (char === "$" ? 1 : 0), depth + 1, "double") : bashExpansion(input, index, depth + 1);
552
- if (!nested)
553
- return;
554
- index = nested.end;
1066
+ const next = input[index + 1] ?? "\x00";
1067
+ if (input[index] === "\\" && ("$`\\\n".includes(next) || quoted && next === '"')) {
1068
+ index++;
1069
+ if (next !== `
1070
+ `)
1071
+ source += next;
555
1072
  continue;
556
1073
  }
557
- const boundary = index === start + 1 || /[ \t\n;|&(){}]/.test(input[index - 1]);
558
- const definition = commandStart && boundary ? bashFunctionHead(input, index) : undefined;
559
- if (definition) {
560
- index += definition.length - 1;
561
- continue;
1074
+ source += input[index];
1075
+ }
1076
+ return { kind: "opaque", reason: "command-substitution" };
1077
+ }
1078
+ function scanBashParameter(input, start, depth, context, commands, quoted, text) {
1079
+ PARAMETER_PREFIX_RE.lastIndex = start;
1080
+ const nameStart = PARAMETER_PREFIX_RE.exec(input) ? PARAMETER_PREFIX_RE.lastIndex : start;
1081
+ PARAMETER_NAME_RE.lastIndex = nameStart;
1082
+ let colon = PARAMETER_NAME_RE.test(input) ? PARAMETER_NAME_RE.lastIndex : -1;
1083
+ const name = colon > nameStart ? input.slice(nameStart, colon).replace(/\\\n/g, "") : "";
1084
+ if (context.dialect !== "bash" && (/^(?:READ)?NULLCMD$/.test(name) || /^(?:(?:dis_)?(?:functions|[gs]?aliases)|options|commands)$/.test(name) && "[=:".includes(input[colon] ?? "")))
1085
+ return { kind: "opaque", reason: "dynamic-execution" };
1086
+ if (name === "PS4")
1087
+ context.variableSink = true;
1088
+ let evaluation;
1089
+ let wordOffset = 0;
1090
+ let literalOffset = 0;
1091
+ for (let index = start;index < input.length; index++) {
1092
+ if (--context.remaining < 0)
1093
+ return { kind: "opaque", reason: "invalid-structure" };
1094
+ const char = input[index];
1095
+ if (char === "}") {
1096
+ if (evaluation && bashEvaluatesExpansion({ word: text.word.slice(wordOffset), literal: text.literal.slice(literalOffset), output: text.output }, evaluation, context))
1097
+ return { kind: "opaque", reason: "dynamic-execution" };
1098
+ return index;
562
1099
  }
563
- if (char === "#" && boundary) {
564
- const newline = input.indexOf(`
565
- `, index);
566
- if (newline < 0)
567
- return;
568
- index = newline - 1;
569
- continue;
1100
+ if (index === colon && !evaluation) {
1101
+ if (char === ":" && !"-=?+".includes(input[index + 1] ?? ""))
1102
+ evaluation = "arithmetic";
1103
+ if (char === "=" || char === ":" && input[index + 1] === "=")
1104
+ evaluation = "deferred";
1105
+ if (evaluation) {
1106
+ wordOffset = text.word.length;
1107
+ literalOffset = text.literal.length;
1108
+ }
570
1109
  }
571
- if (input.startsWith("<<<", index)) {
572
- index += 2;
573
- continue;
1110
+ if (char === "@") {
1111
+ PARAMETER_PROMPT_RE.lastIndex = index;
1112
+ if (PARAMETER_PROMPT_RE.test(input))
1113
+ return { kind: "opaque", reason: "dynamic-execution" };
574
1114
  }
575
- if (input.startsWith("<<", index)) {
576
- const delimiter = bashHeredocDelimiter(input, index);
577
- if (!delimiter)
578
- return;
579
- heredocs.push(delimiter);
580
- index = delimiter.end;
1115
+ if (!quoted && context.dialect !== "bash" && char === "(" && index > start)
1116
+ return { kind: "opaque", reason: "dynamic-execution" };
1117
+ if (quoted && char === "'" && input[index - 1] === "$") {
1118
+ const ansi = bashAnsiQuote(input, index);
1119
+ if (!ansi)
1120
+ return { kind: "opaque", reason: "unterminated-quote" };
1121
+ text.literal += ansi.value;
1122
+ }
1123
+ const subscript = index === colon && char === "[";
1124
+ const unit = subscript ? scanBashSubscript(input, index + 1, depth, context, commands) : quoted && char === "'" ? scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.parameterQuote, false, text) : quoted && char === '"' ? scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.double, false, text) : scanBashUnit(input, index, depth, context, commands, quoted ? "quoted" : "word", false, text);
1125
+ if (typeof unit === "object")
1126
+ return unit;
1127
+ if (quoted && unit !== undefined && input.startsWith("$(", index) && input.slice(index, unit + 1).includes("}"))
1128
+ return { kind: "opaque", reason: "command-substitution" };
1129
+ if (subscript || index === nameStart && input.startsWith("${", index) && unit !== undefined) {
1130
+ LINE_CONTINUATION_RE.lastIndex = Number(unit) + 1;
1131
+ colon = LINE_CONTINUATION_RE.exec(input) ? LINE_CONTINUATION_RE.lastIndex : Number(unit) + 1;
1132
+ }
1133
+ if (unit !== undefined)
1134
+ index = unit;
1135
+ else
1136
+ bashAppend(text, char);
1137
+ }
1138
+ return { kind: "opaque", reason: "command-substitution" };
1139
+ }
1140
+ function scanBashConditional(input, start, depth, context, commands) {
1141
+ const words = [];
1142
+ let text = bashText();
1143
+ let wordStarted = false;
1144
+ let hasWord = false;
1145
+ let parenDepth = 0;
1146
+ let patternParenDepth = 0;
1147
+ const flushWord = () => {
1148
+ if (!hasWord)
1149
+ return;
1150
+ words.push(text);
1151
+ text = bashText();
1152
+ hasWord = false;
1153
+ };
1154
+ for (let index = start;index < input.length; index++) {
1155
+ if (--context.remaining < 0)
1156
+ return { kind: "opaque", reason: "invalid-structure" };
1157
+ const char = input[index];
1158
+ if (char === "\\" && input[index + 1] === `
1159
+ `) {
1160
+ index++;
581
1161
  continue;
582
1162
  }
583
- if (char === `
584
- ` && heredocs.length) {
585
- for (const heredoc of heredocs.splice(0)) {
586
- const body = bashHeredoc(input, index + 1, heredoc);
587
- if (!body)
588
- return;
589
- index = body.end;
1163
+ if (!wordStarted)
1164
+ flushWord();
1165
+ const close = !wordStarted && char === "]" ? bashOperator(input, index, ["]]"]) : undefined;
1166
+ if (typeof close === "object")
1167
+ return close;
1168
+ if (close) {
1169
+ BRACE_CLOSE_AHEAD_RE.lastIndex = index + 2;
1170
+ if (BRACE_CLOSE_AHEAD_RE.test(input)) {
1171
+ if (parenDepth !== 0)
1172
+ return { kind: "opaque", reason: "invalid-structure" };
1173
+ const evaluated = words.some((word, at) => words[at - 1]?.word === "-v" && bashEvaluatesExpansion(word, "binding", context) || (context.dialect !== "bash" && words[at - 1]?.word === "-t" || BASH_ARITHMETIC_COMPARISONS.has(words[at - 1]?.word ?? "") || BASH_ARITHMETIC_COMPARISONS.has(words[at + 1]?.word ?? "")) && bashEvaluatesExpansion(word, "arithmetic", context));
1174
+ if (evaluated)
1175
+ return { kind: "opaque", reason: "dynamic-execution" };
1176
+ return index + 1;
590
1177
  }
591
- commandStart = true;
592
- continue;
593
- }
594
- const token = boundary ? /^[A-Za-z_][A-Za-z0-9_]*(?=[ \t\n;()<>]|$)/.exec(input.slice(index))?.[0] : undefined;
595
- if (token === "case" && commandStart)
596
- cases.push("header");
597
- if (token === "in" && cases.at(-1) === "header")
598
- cases[cases.length - 1] = "pattern";
599
- if (token === "esac" && (commandStart || cases.at(-1) === "pattern"))
600
- cases.pop();
601
- if (token) {
602
- commandStart = commandStart && ["if", "while", "until", "then", "elif", "else", "do"].includes(token);
603
- index += token.length - 1;
604
- continue;
605
- }
606
- if (cases.length && char === ";" && /[;&]/.test(input[index + 1] ?? ""))
607
- cases[cases.length - 1] = "pattern";
608
- if (cases.at(-1) === "pattern" && char === "(")
609
- continue;
610
- if (cases.at(-1) === "pattern" && char === ")") {
611
- cases[cases.length - 1] = "body";
612
- commandStart = true;
613
- continue;
614
1178
  }
615
- if (input.startsWith("((", index)) {
616
- const nested = bashExpansion(input, index, depth + 1, "arithmetic");
617
- if (!nested)
618
- return;
619
- index = nested.end;
620
- commandStart = false;
1179
+ if (!wordStarted && char === "#") {
1180
+ const newline = input.indexOf(`
1181
+ `, index);
1182
+ if (newline < 0)
1183
+ return { kind: "opaque", reason: "invalid-structure" };
1184
+ index = newline;
621
1185
  continue;
622
1186
  }
623
- if (char === "(" || char === "{" && boundary && /[ \t\n]/.test(input[index + 1] ?? "")) {
624
- const nested = bashDelimited(input, index, depth + 1);
625
- if (!nested)
626
- return;
627
- index = nested.end;
628
- commandStart = false;
1187
+ if (char === " " || char === "\t" || char === `
1188
+ `) {
1189
+ if (!patternParenDepth)
1190
+ wordStarted = false;
629
1191
  continue;
630
1192
  }
631
- if (char === close && (close === ")" || boundary))
632
- return { source: input.slice(start + 1, index), end: index };
633
- if (/[\n;&|]/.test(char))
634
- commandStart = true;
635
- else if (!/[ \t]/.test(char))
636
- commandStart = false;
637
- }
638
- }
639
- function bashExpansion(input, start, depth, mode, quoted = false) {
640
- if (depth >= MAX_SUBSTITUTION_DEPTH)
641
- return;
642
- if (!mode && input[start] === "`") {
643
- let source = "";
644
- for (let index = start + 1;index < input.length; index++) {
645
- if (input[index] === "`")
646
- return { source, end: index };
647
- if (input[index] === "\\" && "$`\\\n".includes(input[index + 1] ?? "\x00")) {
648
- if (input[++index] !== `
649
- `)
650
- source += input[index];
651
- continue;
652
- }
653
- source += input[index];
654
- }
655
- return;
656
- }
657
- if (!mode && input.startsWith("$(", start) && !input.startsWith("$((", start))
658
- return bashDelimited(input, start + 1, depth);
659
- if (!mode && /^\$\{[ \t\n|]/.test(input.slice(start))) {
660
- const nested = bashDelimited(input, start + 1, depth);
661
- if (!nested)
662
- return;
663
- return { ...nested, source: nested.source.startsWith("|") ? nested.source.slice(1) : nested.source };
664
- }
665
- const kind = mode ?? (input[start + 1] === "{" ? "parameter" : input[start + 1] === "[" ? "subscript" : "arithmetic");
666
- const arithmetic = ["arithmetic", "arithmetic-group", "subscript"].includes(kind);
667
- const offset = mode ? kind === "heredoc" ? 0 : kind === "arithmetic" || kind === "test" ? 2 : 1 : kind === "arithmetic" ? 3 : 2;
668
- const close = kind === "heredoc" ? undefined : kind === "double" ? '"' : kind === "parameter" ? "}" : kind === "subscript" ? "]" : kind === "test" ? "]]" : kind === "arithmetic" ? "))" : ")";
669
- const substitutions = [];
670
- for (let index = start + offset;index < input.length; index++) {
671
- const char = input[index];
672
- if (close && input.startsWith(close, index))
673
- return { source: input.slice(start + offset, index), end: index + close.length - 1, substitutions };
674
- if (char === "\\") {
675
- if (kind !== "heredoc" && kind !== "double" || '$`\\\n"'.includes(input[index + 1] ?? "\x00"))
676
- index++;
1193
+ if (char === ";")
1194
+ return { kind: "opaque", reason: "invalid-structure" };
1195
+ if (char === "(" || char === ")") {
1196
+ if (char === ")" && parenDepth === 0)
1197
+ return { kind: "opaque", reason: "invalid-structure" };
1198
+ const inPattern = patternParenDepth > 0 || char === "(" && ["=", "==", "!=", "=~"].includes(words.at(-1)?.word ?? "");
1199
+ parenDepth += char === "(" ? 1 : -1;
1200
+ if (inPattern) {
1201
+ patternParenDepth += char === "(" ? 1 : -1;
1202
+ wordStarted = true;
1203
+ hasWord = true;
1204
+ bashAppend(text, char);
1205
+ continue;
1206
+ }
1207
+ flushWord();
1208
+ words.push({ word: char, literal: "", output: "" });
1209
+ wordStarted = false;
677
1210
  continue;
678
1211
  }
679
- if ((char === "'" || input.startsWith("$'", index)) && kind !== "double" && kind !== "heredoc" && !arithmetic && !(kind === "parameter" && quoted)) {
680
- const end = char === "'" ? input.indexOf("'", index + 1) : bashAnsiQuote(input, index + 1)?.end;
681
- if (end === undefined || end < 0)
682
- return;
683
- index = end;
1212
+ const unit = scanBashUnit(input, index, depth, context, commands, "word", true, text);
1213
+ if (typeof unit === "object")
1214
+ return unit;
1215
+ if (unit !== undefined)
1216
+ index = unit;
1217
+ if (unit === undefined && !patternParenDepth && "&|<>".includes(char)) {
1218
+ flushWord();
1219
+ words.push({ word: char, literal: "", output: "" });
1220
+ wordStarted = false;
684
1221
  continue;
685
1222
  }
686
- if (char === '"' && kind !== "heredoc") {
687
- const nested = bashExpansion(input, index, depth + 1, "double");
688
- if (!nested)
689
- return;
690
- substitutions.push(...nested.substitutions);
691
- index = nested.end;
1223
+ wordStarted = true;
1224
+ hasWord = true;
1225
+ if (unit === undefined)
1226
+ bashAppend(text, char);
1227
+ }
1228
+ return { kind: "opaque", reason: "invalid-structure" };
1229
+ }
1230
+ function scanBashArrayOrPattern(input, start, depth, context, commands, mode) {
1231
+ if (depth > MAX_SUBSTITUTION_DEPTH)
1232
+ return { kind: "opaque", reason: "command-substitution" };
1233
+ const text = mode === "array" ? bashText() : undefined;
1234
+ let wordStarted = false;
1235
+ for (let index = start + 1;index < input.length; index++) {
1236
+ if (--context.remaining < 0)
1237
+ return { kind: "opaque", reason: "invalid-structure" };
1238
+ const char = input[index];
1239
+ if (char === "\\" && input[index + 1] === `
1240
+ `) {
1241
+ index++;
692
1242
  continue;
693
1243
  }
694
- if (char === "`" || char === "$" && "({[".includes(input[index + 1] ?? "\x00")) {
695
- const nested = bashExpansion(input, index, depth + 1, undefined, kind === "double" || quoted);
696
- if (!nested)
697
- return;
698
- substitutions.push(...nested.substitutions ?? [nested.source]);
699
- index = nested.end;
700
- continue;
1244
+ if (text && (char === ")" || char === " " || char === "\t" || char === `
1245
+ `)) {
1246
+ bashEvaluatesExpansion(text, "deferred", context);
1247
+ text.literal = "";
1248
+ text.output = "";
701
1249
  }
702
- if ((kind === "array" && "<>=".includes(char) || kind === "test" && "<>".includes(char)) && input[index + 1] === "(") {
703
- const nested = bashDelimited(input, index + 1, depth + 1);
704
- if (!nested)
705
- return;
706
- substitutions.push(nested.source);
707
- index = nested.end;
1250
+ if (char === ")")
1251
+ return index;
1252
+ if (mode === "array" && !wordStarted && char === "#") {
1253
+ const newline = input.indexOf(`
1254
+ `, index);
1255
+ if (newline < 0)
1256
+ return { kind: "opaque", reason: "command-substitution" };
1257
+ index = newline;
708
1258
  continue;
709
1259
  }
710
- if ((arithmetic || kind === "array" || kind === "pattern") && (char === "(" || char === "[") || kind === "parameter" && char === "[" && /^[!#]?[A-Za-z_][A-Za-z0-9_]*$/.test(input.slice(start + offset, index))) {
711
- const nested = bashExpansion(input, index, depth + 1, char === "[" ? "subscript" : arithmetic ? "arithmetic-group" : kind);
712
- if (!nested)
713
- return;
714
- substitutions.push(...nested.substitutions);
715
- index = nested.end;
1260
+ if (char === " " || char === "\t" || mode === "array" && char === `
1261
+ `) {
1262
+ wordStarted = false;
716
1263
  continue;
717
1264
  }
718
- if (!mode && kind === "arithmetic" && char === ";")
719
- return;
1265
+ if (char === `
1266
+ ` || char === ";" || char === "&" || mode === "array" && "|(".includes(char))
1267
+ return { kind: "opaque", reason: "command-substitution" };
1268
+ wordStarted = true;
1269
+ const unit = mode === "array" && char === "=" && input[index + 1] === "(" ? scanBashNested(input, index + 2, depth, context, commands, ")") : char === "(" ? scanBashArrayOrPattern(input, index, depth + 1, context, commands, mode) : char === "[" ? scanBashSubscript(input, index + 1, depth, context, commands) : scanBashUnit(input, index, depth, context, commands, "word", false, text);
1270
+ if (typeof unit === "object")
1271
+ return unit;
1272
+ if (unit !== undefined)
1273
+ index = unit;
1274
+ else if (text)
1275
+ text.literal += char;
720
1276
  }
721
- if (kind === "heredoc")
722
- return { source: input.slice(start), end: input.length - 1, substitutions };
1277
+ return { kind: "opaque", reason: "command-substitution" };
723
1278
  }
724
1279
  function bashAnsiQuote(input, start) {
725
1280
  let value = "";
@@ -731,58 +1286,45 @@ function bashAnsiQuote(input, start) {
731
1286
  continue;
732
1287
  }
733
1288
  const escaped = input[++index];
734
- const simple = {
735
- a: "\x07",
736
- b: "\b",
737
- e: "\x1B",
738
- E: "\x1B",
739
- f: "\f",
740
- n: `
741
- `,
742
- r: "\r",
743
- t: "\t",
744
- v: "\v",
745
- "\\": "\\",
746
- "'": "'",
747
- '"': '"',
748
- "?": "?"
749
- };
750
- if (escaped in simple)
751
- value += simple[escaped];
752
- else if (escaped === "c" && index + 1 < input.length)
753
- value += String.fromCharCode(input[++index].toUpperCase().charCodeAt(0) & 31);
754
- else {
755
- const digits = escaped === "x" ? /^[\da-fA-F]{1,2}/.exec(input.slice(index + 1))?.[0] : escaped === "u" ? /^[\da-fA-F]{1,4}/.exec(input.slice(index + 1))?.[0] : escaped === "U" ? /^[\da-fA-F]{1,8}/.exec(input.slice(index + 1))?.[0] : /[0-7]/.test(escaped ?? "") ? /^[0-7]{1,3}/.exec(input.slice(index))?.[0] : undefined;
756
- if (!digits)
757
- value += `\\${escaped}`;
758
- else {
759
- const octal = /[0-7]/.test(escaped);
760
- const point = parseInt(digits, octal ? 8 : 16);
761
- value += point <= 1114111 ? String.fromCodePoint(point) : "";
762
- index += digits.length - (octal ? 1 : 0);
763
- }
1289
+ if (escaped === undefined)
1290
+ return;
1291
+ if (escaped in BASH_ANSI_ESCAPES) {
1292
+ value += BASH_ANSI_ESCAPES[escaped];
1293
+ continue;
764
1294
  }
1295
+ const digits = escaped === "x" ? /^[\da-fA-F]{1,2}/.exec(input.slice(index + 1, index + 3))?.[0] : /[0-7]/.test(escaped) ? /^[0-7]{1,3}/.exec(input.slice(index, index + 3))?.[0] : undefined;
1296
+ if (!digits)
1297
+ return;
1298
+ const octal = /[0-7]/.test(escaped);
1299
+ const point = parseInt(digits, octal ? 8 : 16);
1300
+ if (point === 0)
1301
+ return;
1302
+ value += String.fromCodePoint(point);
1303
+ index += digits.length - (octal ? 1 : 0);
765
1304
  }
766
1305
  }
767
- function bashHeredocDelimiter(input, start) {
768
- const tabs = input[start + 2] === "-";
1306
+ function bashHeredocDelimiter(input, start, tabs) {
769
1307
  let delimiter = "";
1308
+ let dashDelimiter;
770
1309
  let quoted = false;
771
1310
  let quote;
772
1311
  let end = start;
773
1312
  let started = false;
774
- for (let index = start + (tabs ? 3 : 2);index < input.length; index++) {
1313
+ for (let index = start;index < input.length; index++) {
775
1314
  const char = input[index];
776
1315
  if (!started && /[ \t]/.test(char))
777
1316
  continue;
778
1317
  if (!started && char === "#")
779
1318
  return;
780
1319
  if (!quote && /[ \t\n;&|()<>]/.test(char))
781
- return started ? { delimiter, quoted, tabs, end } : undefined;
1320
+ return started ? { delimiter, dashDelimiter, quoted, tabs, end } : undefined;
1321
+ if (!quote && char === "$" && input.startsWith("\\\n", index + 1))
1322
+ return;
782
1323
  if (!quote && input.startsWith("$'", index)) {
783
1324
  const literal = bashAnsiQuote(input, index + 1);
784
- if (!literal)
1325
+ if (!literal || literal.end !== input.indexOf("'", index + 2))
785
1326
  return;
1327
+ dashDelimiter = `${dashDelimiter ?? delimiter}$${input.slice(index + 2, literal.end)}`;
786
1328
  delimiter += literal.value;
787
1329
  quoted = true;
788
1330
  started = true;
@@ -790,13 +1332,8 @@ function bashHeredocDelimiter(input, start) {
790
1332
  end = index;
791
1333
  continue;
792
1334
  }
793
- if (!quote && input.startsWith('$"', index)) {
794
- quote = '"';
795
- quoted = true;
796
- started = true;
797
- end = ++index;
798
- continue;
799
- }
1335
+ if (!quote && input.startsWith('$"', index))
1336
+ return;
800
1337
  if (char === quote) {
801
1338
  quote = undefined;
802
1339
  end = index;
@@ -814,7 +1351,10 @@ function bashHeredocDelimiter(input, start) {
814
1351
  if (!quote || '$`"\\'.includes(next)) {
815
1352
  quoted = true;
816
1353
  started = true;
817
- delimiter += input[++index];
1354
+ const escaped = input[++index];
1355
+ if (dashDelimiter !== undefined)
1356
+ dashDelimiter += escaped;
1357
+ delimiter += escaped;
818
1358
  end = index;
819
1359
  continue;
820
1360
  }
@@ -826,69 +1366,92 @@ function bashHeredocDelimiter(input, start) {
826
1366
  end = index;
827
1367
  continue;
828
1368
  }
1369
+ if (dashDelimiter !== undefined)
1370
+ dashDelimiter += char;
829
1371
  delimiter += char;
830
1372
  started = true;
831
1373
  end = index;
832
1374
  }
833
1375
  if (started && !quote)
834
- return { delimiter, quoted, tabs, end };
1376
+ return { delimiter, dashDelimiter, quoted, tabs, end };
835
1377
  }
836
1378
  function bashHeredoc(input, start, delimiter) {
837
1379
  const bodyStart = start;
838
1380
  let lineStart = start;
839
1381
  let line = "";
1382
+ let backslashes = 0;
840
1383
  for (let index = start;index <= input.length; index++) {
841
1384
  if (index < input.length && input[index] !== `
842
1385
  `)
843
1386
  continue;
844
- const text = input.slice(start, index);
845
- line += delimiter.tabs ? text.replace(/^\t+/, "") : text;
846
- if (!delimiter.quoted && /(?<!\\)(?:\\\\)*\\$/.test(line) && index < input.length) {
847
- line = line.slice(0, -1);
1387
+ const text = delimiter.tabs && start === lineStart ? input.slice(start, index).replace(/^\t+/, "") : input.slice(start, index);
1388
+ let run = 0;
1389
+ while (text[text.length - 1 - run] === "\\")
1390
+ run++;
1391
+ backslashes = run === text.length ? backslashes + run : run;
1392
+ const continued = !delimiter.quoted && backslashes % 2 === 1 && index < input.length;
1393
+ const maxLength = Math.max(delimiter.delimiter.length, delimiter.dashDelimiter?.length ?? 0);
1394
+ if (line.length <= maxLength)
1395
+ line += continued ? text.slice(0, -1) : text;
1396
+ if (continued) {
1397
+ backslashes--;
848
1398
  start = index + 1;
849
1399
  continue;
850
1400
  }
851
- if (line === delimiter.delimiter)
1401
+ if (delimiter.dashDelimiter !== undefined && line === delimiter.dashDelimiter)
1402
+ return;
1403
+ if (line === delimiter.delimiter) {
1404
+ if (start > lineStart && input.slice(index + 1).includes(delimiter.delimiter))
1405
+ return;
852
1406
  return { source: input.slice(bodyStart, lineStart), end: index };
1407
+ }
853
1408
  line = "";
1409
+ backslashes = 0;
854
1410
  start = index + 1;
855
1411
  lineStart = start;
856
1412
  }
857
1413
  }
858
1414
  function scanPowerShell(input) {
859
- return scanPowerShellNested(input, 0, { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH });
860
- }
861
- function scanPowerShellNested(input, depth, budget, hash = false) {
862
- budget.remaining -= input.length;
863
- if (input.length > MAX_INPUT_LENGTH || depth >= MAX_SUBSTITUTION_DEPTH || budget.remaining < 0)
1415
+ if (input.length > MAX_INPUT_LENGTH)
864
1416
  return { kind: "opaque", reason: "invalid-structure" };
865
1417
  if (/[\0\u0085\u2013-\u2015\u2018-\u201e\ufeff]/.test(input))
866
1418
  return { kind: "opaque", reason: "invalid-structure" };
1419
+ const result = scanPowerShellList(input, 0, 0, { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH });
1420
+ if (result.kind === "opaque")
1421
+ return result;
1422
+ return { kind: "scanned", commands: result.commands };
1423
+ }
1424
+ function scanPowerShellList(input, start, depth, budget, close, hash = false, skipped) {
1425
+ if (depth >= MAX_SUBSTITUTION_DEPTH || budget.remaining < 0)
1426
+ return { kind: "opaque", reason: "invalid-structure" };
867
1427
  const commands = [];
868
1428
  const nestedCommands = [];
869
1429
  const words = [];
870
1430
  const rawWords = [];
871
1431
  const wordEnds = [];
872
- let segment = 0;
1432
+ const initialExpression = hash === true || hash === "clause";
1433
+ const initialClause = hash === "clause" || hash === "switch" ? "member" : undefined;
1434
+ let segment = start;
873
1435
  let word = "";
874
1436
  let started = false;
875
- let wordStart = 0;
1437
+ let wordStart = start;
876
1438
  let quote;
877
1439
  let standalone = false;
878
- let expression = hash;
879
- let compound = false;
1440
+ let expression = initialExpression;
1441
+ let clause = initialClause;
1442
+ let after;
1443
+ let indexable = false;
880
1444
  let stopParsing = false;
881
- let commandEnd = 0;
1445
+ let commandEnd = start;
882
1446
  let statementHead = true;
883
1447
  let invalid = false;
884
1448
  let redirectTarget = false;
885
- let comment = false;
886
1449
  let dangling = false;
887
1450
  let invocation = false;
888
1451
  const finishWord = (end) => {
889
1452
  if (!started)
890
1453
  return;
891
- if (word === "--%" && words.length > 0 && !expression && !/['"]/.test(input[wordStart]))
1454
+ if (word === "--%" && words.length > 0 && !expression && !clause && !redirectTarget && !/['"]/.test(input[wordStart]) && !rawWords.at(-1)?.endsWith(",") && !POWERSHELL_PARAMETER_COLON_RE.test(rawWords.at(-1) ?? ""))
892
1455
  stopParsing = true;
893
1456
  if (!redirectTarget) {
894
1457
  if (!words.length && !invocation && !expression)
@@ -905,17 +1468,15 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
905
1468
  };
906
1469
  const finishCommand = (end, required = false) => {
907
1470
  finishWord(end);
908
- const start = segment + input.slice(segment, commandEnd).search(/\S|$/);
909
- const resource = input.slice(start, commandEnd).trimEnd();
910
- if (words.length && !expression)
1471
+ if (words.length && !expression && !clause)
911
1472
  commands.push({
912
- resource,
1473
+ resource: input.slice(segment, commandEnd).trimEnd(),
913
1474
  words: [...words],
914
1475
  rawWords: [...rawWords],
915
- wordEnds: wordEnds.map((end) => end - start),
1476
+ wordEnds: wordEnds.map((value) => value - segment),
916
1477
  ...statementHead && !invocation ? { statementHead: true } : {}
917
1478
  });
918
- else if (!expression && invocation || required && !words.length && !nestedCommands.length)
1479
+ else if (!expression && !clause && invocation || required && !words.length && !nestedCommands.length || clause !== undefined && clause !== "member")
919
1480
  invalid = true;
920
1481
  if (redirectTarget)
921
1482
  invalid = true;
@@ -925,16 +1486,25 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
925
1486
  wordEnds.length = 0;
926
1487
  redirectTarget = false;
927
1488
  invocation = false;
928
- expression = hash;
929
- compound = false;
1489
+ expression = initialExpression;
1490
+ clause = initialClause;
1491
+ after = undefined;
1492
+ indexable = false;
930
1493
  stopParsing = false;
931
1494
  };
932
- for (let index = 0;index < input.length; index++) {
1495
+ let index = start;
1496
+ for (;index < input.length; index++) {
1497
+ if (--budget.remaining < 0)
1498
+ return { kind: "opaque", reason: "invalid-structure" };
1499
+ if (skipped?.has(index))
1500
+ continue;
933
1501
  const char = input[index];
1502
+ const inExpression = expression && !redirectTarget;
1503
+ const atBoundary = !started || !inExpression && word.endsWith(",");
934
1504
  if (!started)
935
1505
  wordStart = index;
936
1506
  if (stopParsing) {
937
- const stop = powerShellStopParsing(input, index);
1507
+ const stop = powerShellStopParsing(input, index, skipped);
938
1508
  const text = input.slice(index, stop).trim();
939
1509
  if (text) {
940
1510
  wordStart = index + input.slice(index, stop).search(/\S/);
@@ -946,43 +1516,42 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
946
1516
  index = stop - 1;
947
1517
  continue;
948
1518
  }
949
- if (quote === "single") {
950
- started = true;
951
- if (char === "'" && input[index + 1] === "'") {
952
- word += "'";
953
- index++;
954
- } else if (char === "'") {
955
- quote = undefined;
956
- if (standalone)
957
- finishWord(index + 1);
958
- } else
959
- word += char;
960
- continue;
961
- }
962
- if (quote === "double") {
963
- if (char === '"' && input[index + 1] === '"') {
964
- word += '"';
965
- index++;
966
- } else if (char === '"') {
1519
+ if (quote) {
1520
+ let nextQuote = index + 1;
1521
+ while (skipped?.has(nextQuote))
1522
+ nextQuote++;
1523
+ if (char === quote && input[nextQuote] === quote) {
1524
+ word += quote;
1525
+ index = nextQuote;
1526
+ } else if (char === quote) {
967
1527
  quote = undefined;
968
- if (standalone)
1528
+ if (standalone) {
969
1529
  finishWord(index + 1);
970
- } else if (char === "`") {
971
- const escape = powerShellEscape(input, index);
1530
+ indexable = "closed";
1531
+ }
1532
+ } else if (quote === '"' && char === "`") {
1533
+ const escape = powerShellEscape(input, index, false, skipped);
972
1534
  if (!escape)
973
1535
  return { kind: "opaque", reason: "unterminated-escape" };
974
1536
  word += escape.value;
975
1537
  index = escape.end;
976
- } else if (char === "$" && input[index + 1] === "(") {
977
- const block = powerShellBlock(input, index + 1, depth);
978
- if (!block)
1538
+ } else if (quote === '"' && char === "$" && input[index + 1] === "{") {
1539
+ const end = powerShellBracedVariable(input, index, skipped);
1540
+ if (end === undefined)
1541
+ return { kind: "opaque", reason: "invalid-structure" };
1542
+ word += input.slice(index, end + 1);
1543
+ index = end;
1544
+ } else if (quote === '"' && char === "$" && input[index + 1] === "(") {
1545
+ const sub = powerShellSubExpression(input, index + 2, false, budget, skipped);
1546
+ if (!sub)
979
1547
  return { kind: "opaque", reason: "invalid-structure" };
980
- const result = scanPowerShellNested(block.source, depth + 1, budget);
1548
+ const result = scanPowerShellList(input, index + 2, depth + 1, budget, ")", false, sub.skipped);
981
1549
  if (result.kind === "opaque")
982
1550
  return result;
983
1551
  nestedCommands.push(...result.commands);
984
- word += input.slice(index, block.end + 1);
985
- index = block.end;
1552
+ const end = sub.rawEnd !== undefined && sub.rawEnd > result.end ? sub.rawEnd : result.end;
1553
+ word += input.slice(index, end + 1);
1554
+ index = end;
986
1555
  } else
987
1556
  word += char;
988
1557
  continue;
@@ -990,176 +1559,203 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
990
1559
  if (char === "'" || char === '"') {
991
1560
  if (!started && words.length === 0 && !invocation)
992
1561
  expression = true;
993
- quote = char === "'" ? "single" : "double";
994
- standalone = !started;
1562
+ quote = char;
1563
+ standalone = atBoundary || expression && !redirectTarget || indexable === "member" && /[.:]$/.test(word);
1564
+ if (!standalone)
1565
+ indexable = false;
995
1566
  started = true;
996
1567
  continue;
997
1568
  }
998
1569
  if (char === "`") {
999
- const escape = powerShellEscape(input, index);
1570
+ const escape = powerShellEscape(input, index, atBoundary || inExpression, skipped);
1000
1571
  if (!escape)
1001
1572
  return { kind: "opaque", reason: "unterminated-escape" };
1002
- if (started || /\S/.test(escape.value)) {
1573
+ const rawSpace = /\s/.test(input[index + 1] ?? "");
1574
+ if ((inExpression || atBoundary) && started && rawSpace)
1575
+ finishWord(index);
1576
+ else if (!atBoundary || !rawSpace) {
1003
1577
  started = true;
1578
+ indexable = false;
1004
1579
  word += escape.value;
1005
1580
  }
1006
1581
  index = escape.end;
1007
1582
  continue;
1008
1583
  }
1009
- if (!started && words.length > 0 && !expression && /^--%(?=$|[\s;|&(){}])/.test(input.slice(index))) {
1584
+ if (!started && words.length > 0 && !expression && !clause && !redirectTarget && testAt(POWERSHELL_STOP_PARSING_RE, input, index)) {
1010
1585
  word = "--%";
1011
1586
  started = true;
1012
1587
  finishWord(index + 3);
1013
- stopParsing = true;
1014
1588
  index += 2;
1015
1589
  continue;
1016
1590
  }
1017
- if (char === "<" && input[index + 1] === "#" && !started) {
1018
- const end = powerShellComment(input, index);
1019
- if (end === undefined)
1591
+ if (char === "<" && input[index + 1] === "#" && (atBoundary || inExpression || indexable === "member")) {
1592
+ const memberOperator = indexable === "member" && /[.:]$/.test(started ? word : words.at(-1) ?? "");
1593
+ if (started)
1594
+ finishWord(index);
1595
+ const end = input.indexOf("#>", index + 2);
1596
+ if (end < 0)
1020
1597
  return { kind: "opaque", reason: "invalid-structure" };
1021
- if (!words.length && !invocation)
1022
- segment = end + 1;
1023
- index = end;
1598
+ if (!memberOperator)
1599
+ indexable = false;
1600
+ index = end + 1;
1024
1601
  continue;
1025
1602
  }
1026
- if (char === "#" && (!started || expression)) {
1027
- if (words.length || started || invocation)
1603
+ if (char === "#" && (atBoundary || indexable === "member" || inExpression && !(close === "]" && /^[\p{L}\p{Nl}_][\p{L}\p{Nl}\d_.#+`\\]*$/u.test(word)))) {
1604
+ const prev = started ? word : words.at(-1) ?? "";
1605
+ const memberOperator = indexable === "member" && /[.:]$/.test(prev);
1606
+ if (clause && clause !== "member" || prev.endsWith(",") || memberOperator)
1607
+ finishWord(index);
1608
+ else if (words.length || started || invocation)
1028
1609
  finishCommand(index);
1029
1610
  statementHead = !dangling;
1030
- comment = true;
1031
1611
  const endings = [input.indexOf(`
1032
1612
  `, index), input.indexOf("\r", index)].filter((ending) => ending >= 0);
1033
1613
  const newline = endings.length > 0 ? Math.min(...endings) : -1;
1034
- if (newline === -1)
1614
+ if (newline === -1) {
1615
+ index = input.length;
1035
1616
  break;
1036
- comment = false;
1617
+ }
1037
1618
  index = input[newline] === "\r" && input[newline + 1] === `
1038
1619
  ` ? newline + 1 : newline;
1039
- segment = index + 1;
1040
1620
  continue;
1041
1621
  }
1042
- const redirect = !started && (char === ">" || char === "*" || /\d/.test(char)) ? powerShellRedirect(input, index) : undefined;
1622
+ if (inExpression && started && (char === ">" || char === "*" && input[index + 1] === ">"))
1623
+ finishWord(index);
1624
+ const redirect = !started && (char === ">" || char === "*" || /\d/.test(char) && (words.length > 0 || testAt(POWERSHELL_MERGE_REDIRECT_RE, input, index))) ? powerShellRedirect(input, index) : undefined;
1043
1625
  if (redirect === false)
1044
1626
  return { kind: "opaque", reason: "invalid-redirect" };
1045
1627
  if (redirect) {
1046
- if (redirectTarget)
1047
- return { kind: "opaque", reason: "invalid-redirect" };
1048
- if (words.length === 0)
1628
+ if (redirectTarget || words.length === 0 || clause && clause !== "member")
1049
1629
  return { kind: "opaque", reason: "invalid-redirect" };
1050
1630
  redirectTarget = !redirect.includes("&");
1631
+ indexable = false;
1051
1632
  index += redirect.length - 1;
1052
1633
  commandEnd = index + 1;
1053
1634
  continue;
1054
1635
  }
1055
- if (!started && !words.length && !invocation && !expression && /[A-Za-z]/.test(char)) {
1056
- const keyword = /^[A-Za-z]+(?=$|[\s({])/.exec(input.slice(index))?.[0]?.toLowerCase();
1057
- if (keyword && /^(?:if|elseif|else|for|while|do|until|switch|function|filter|try|catch|finally|begin|process|end|clean|param|trap|class|enum|data|dynamicparam|using)$/.test(keyword)) {
1058
- expression = true;
1059
- compound = true;
1060
- index += keyword.length - 1;
1636
+ if (!started && !words.length && !invocation && !expression && !clause && char === ":") {
1637
+ const label = matchAt(POWERSHELL_LABEL_RE, input, index);
1638
+ if (label) {
1639
+ index += label[0].length - 1;
1061
1640
  continue;
1062
1641
  }
1063
- if (keyword === "foreach" && /^foreach\s*\(/i.test(input.slice(index))) {
1064
- expression = true;
1065
- compound = true;
1642
+ }
1643
+ if (!started && !invocation && !clause && (!words.length ? !expression : words.every((item) => item.startsWith("["))) && /[A-Za-z]/.test(char)) {
1644
+ const keyword = matchAt(POWERSHELL_KEYWORD_RE, input, index)?.[0]?.toLowerCase();
1645
+ if (keyword && (words.length > 0 ? keyword === "param" && testAt(POWERSHELL_PARAM_RE, input, index) || keyword === "class" || keyword === "enum" : keyword === "param" && testAt(POWERSHELL_PARAM_RE, input, index) || keyword === "foreach" && testAt(POWERSHELL_FOREACH_RE, input, index) || keyword === "until" && after === "do" || (keyword === "else" || keyword === "elseif") && after === "if" || (keyword === "catch" || keyword === "finally") && after === "try" || /^(?:if|for|while|do|switch|function|filter|workflow|parallel|sequence|configuration|try|begin|process|end|clean|trap|class|enum|data|dynamicparam|using|break|continue)$/.test(keyword))) {
1646
+ expression = /^(?:class|enum|break|continue)$/.test(keyword);
1647
+ clause = keyword === "using" || keyword === "break" || keyword === "continue" ? "member" : keyword === "param" || keyword === "until" || keyword === "while" && after === "do" ? "paren" : keyword === "do" ? "do" : keyword === "if" || keyword === "elseif" ? "if" : keyword === "try" || keyword === "catch" ? "try" : keyword === "switch" ? "switch" : keyword === "class" || keyword === "enum" ? "clause" : "block";
1648
+ after = undefined;
1066
1649
  index += keyword.length - 1;
1067
1650
  continue;
1068
1651
  }
1069
- if (keyword && /^(?:return|throw|exit|break|continue)$/.test(keyword)) {
1652
+ if (!words.length && keyword && /^(?:return|throw|exit)$/.test(keyword)) {
1653
+ after = undefined;
1070
1654
  index += keyword.length - 1;
1071
- segment = index + 1;
1072
1655
  continue;
1073
1656
  }
1074
1657
  }
1075
- if (expression && !compound && (char === "=" || /[-+*/%]/.test(char) && input[index + 1] === "=")) {
1076
- finishWord(index);
1658
+ const assign = inExpression && !clause && (char === "=" || /[-+*/%]/.test(char) && input[index + 1] === "=");
1659
+ if (assign || inExpression && close === ")" && !started && testAt(POWERSHELL_IN_RE, input, index)) {
1660
+ if (assign)
1661
+ finishWord(index);
1077
1662
  words.length = 0;
1078
1663
  rawWords.length = 0;
1079
1664
  wordEnds.length = 0;
1080
1665
  expression = false;
1081
- if (char !== "=")
1666
+ indexable = false;
1667
+ if (!assign || char !== "=")
1082
1668
  index++;
1083
- segment = index + 1;
1084
- continue;
1085
- }
1086
- if (expression && !started && /^in\b/i.test(input.slice(index))) {
1087
- words.length = 0;
1088
- rawWords.length = 0;
1089
- wordEnds.length = 0;
1090
- expression = false;
1091
- index++;
1092
- segment = index + 1;
1093
1669
  continue;
1094
1670
  }
1095
- if (char === "@" && /['"]/.test(input[index + 1] ?? "")) {
1096
- const literal = powerShellHereString(input, index);
1097
- if (!literal)
1098
- return { kind: "opaque", reason: "unterminated-quote" };
1671
+ if (atBoundary && char === "@" && !testAt(POWERSHELL_AT_OPENER_RE, input, index + 1))
1672
+ return { kind: "opaque", reason: "invalid-structure" };
1673
+ if (atBoundary && char === "@" && (input[index + 1] === "'" || input[index + 1] === '"')) {
1674
+ if (started)
1675
+ finishWord(index);
1676
+ wordStart = index;
1677
+ const literal = powerShellHereString(input, index, depth, budget, skipped);
1678
+ if (literal.kind === "opaque")
1679
+ return literal;
1099
1680
  if (!words.length && !invocation)
1100
1681
  expression = true;
1101
- if (input[index + 1] === '"') {
1102
- const result = powerShellExpansions(literal.source, depth + 1, budget);
1103
- if (result.kind === "opaque")
1104
- return result;
1105
- nestedCommands.push(...result.commands);
1106
- }
1682
+ nestedCommands.push(...literal.commands);
1107
1683
  word = literal.source;
1108
1684
  started = true;
1109
1685
  index = literal.end;
1110
1686
  finishWord(index + 1);
1687
+ indexable = "closed";
1111
1688
  continue;
1112
1689
  }
1113
1690
  if (char === "$" && input[index + 1] === "{") {
1114
- const end = input.indexOf("}", index + 2);
1115
- if (end < 0)
1691
+ const end = powerShellBracedVariable(input, index, skipped);
1692
+ if (end === undefined)
1116
1693
  return { kind: "opaque", reason: "invalid-structure" };
1117
- if (!started && !words.length && !invocation)
1694
+ if (!started && !words.length && !invocation && hash !== "switch")
1118
1695
  expression = true;
1696
+ indexable = atBoundary || indexable === "member" && /[.:]$/.test(word) ? "closed" : false;
1119
1697
  word += input.slice(index, end + 1);
1120
1698
  started = true;
1121
1699
  index = end;
1700
+ if (expression && !redirectTarget && input[index + 1] !== "[")
1701
+ finishWord(index + 1);
1122
1702
  continue;
1123
1703
  }
1124
- const opener = (char === "$" || char === "@") && input[index + 1] === "(" ? index + 1 : char === "@" && input[index + 1] === "{" ? index + 1 : char === "(" || char === "{" || char === "[" && (expression || !started) ? index : undefined;
1704
+ const opener = (char === "$" || atBoundary && char === "@") && input[index + 1] === "(" ? index + 1 : atBoundary && char === "@" && input[index + 1] === "{" ? index + 1 : char === "(" || char === "{" || char === "[" && (inExpression || Boolean(indexable) || !started && !invocation && (!words.length || clause === "block" || clause === "try")) ? index : undefined;
1125
1705
  if (opener !== undefined) {
1126
- if (started && (char === "{" || char === "(")) {
1706
+ const openChar = input[opener];
1707
+ const standaloneBlock = atBoundary || inExpression || char === "(" || openChar === "{";
1708
+ const blockClose = openChar === "(" ? ")" : openChar === "[" ? "]" : "}";
1709
+ const blockHash = openChar === "[" ? true : char === "@" && openChar === "{" ? true : clause === "switch" && openChar === "{" ? "switch" : clause === "clause" && openChar === "{" ? "clause" : close === "]" && char === "(" && started ? "clause" : false;
1710
+ if (started && (char === "{" || char === "(" || char === "@" && atBoundary)) {
1127
1711
  finishWord(index);
1712
+ if (stopParsing) {
1713
+ index--;
1714
+ continue;
1715
+ }
1128
1716
  wordStart = index;
1129
1717
  }
1130
1718
  if (!started && !words.length && !invocation)
1131
1719
  expression = true;
1132
- const block = powerShellBlock(input, opener, depth);
1133
- if (!block)
1134
- return { kind: "opaque", reason: "invalid-structure" };
1135
- const result = scanPowerShellNested(block.source, depth + 1, budget, input[opener] === "[" || char === "@" && input[opener] === "{");
1720
+ const result = scanPowerShellList(input, opener + 1, depth + 1, budget, blockClose, blockHash, skipped);
1136
1721
  if (result.kind === "opaque")
1137
1722
  return result;
1138
1723
  nestedCommands.push(...result.commands);
1139
1724
  started = true;
1140
- word += input.slice(index, block.end + 1);
1141
- index = block.end;
1142
- if (input[opener] === "{" || char === "(")
1725
+ word += input.slice(index, result.end + 1);
1726
+ index = result.end;
1727
+ if (openChar === "[") {
1728
+ indexable = "closed";
1729
+ if (input[index + 1] !== "[")
1730
+ finishWord(index + 1);
1731
+ } else if (standaloneBlock) {
1143
1732
  finishWord(index + 1);
1144
- if (compound && input[opener] === "{") {
1733
+ indexable = "closed";
1734
+ }
1735
+ if (clause === "paren" && char === "(" || clause && clause !== "paren" && char === "{") {
1736
+ const completed = clause === "do" || clause === "if" || clause === "try" ? clause : undefined;
1737
+ clause = "member";
1145
1738
  finishCommand(index + 1);
1146
- segment = index + 1;
1739
+ after = completed;
1147
1740
  }
1148
1741
  continue;
1149
1742
  }
1150
- if (char === "}" || char === ")")
1743
+ if (char === close)
1744
+ break;
1745
+ if (char === "}" || char === ")" || char === "]" && inExpression)
1151
1746
  return { kind: "opaque", reason: "invalid-structure" };
1152
- if (!started && words.length === 0 && (char === "&" && input[index + 1] !== "&" || char === "." && (/\s/.test(input[index + 1] ?? "") || !input[index + 1]))) {
1747
+ if (!started && words.length === 0 && (char === "&" && input[index + 1] !== "&" || char === "." && (!input[index + 1] || /[\s"'$(),;{|}&]/.test(input[index + 1])))) {
1153
1748
  if (invocation)
1154
1749
  return { kind: "opaque", reason: "invalid-structure" };
1750
+ segment = index;
1155
1751
  invocation = true;
1752
+ after = undefined;
1156
1753
  continue;
1157
1754
  }
1158
- if (!started && !words.length && !invocation && powerShellExpression(input.slice(index)))
1159
- expression = true;
1160
1755
  if (/\s/.test(char) && char !== `
1161
1756
  ` && char !== "\r") {
1162
1757
  finishWord(index);
1758
+ indexable = false;
1163
1759
  continue;
1164
1760
  }
1165
1761
  const next = input[index + 1];
@@ -1167,12 +1763,25 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
1167
1763
  ` ? char + next : char === "&" && next === "&" || char === "|" && next === "|" ? char + next : char === ";" || char === "|" || char === "&" || char === `
1168
1764
  ` || char === "\r" ? char : undefined;
1169
1765
  if (separator) {
1170
- if ((separator === `
1766
+ if (close === "]" && (separator === ";" || separator === "|" || separator === "||" || separator === "&&" || separator === "&"))
1767
+ return { kind: "opaque", reason: "invalid-structure" };
1768
+ if (separator === `
1171
1769
  ` || separator === "\r" || separator === `\r
1172
- `) && !started && !words.length && !invocation) {
1173
- index += separator.length - 1;
1174
- segment = index + 1;
1175
- continue;
1770
+ `) {
1771
+ const prev = started ? word : words.at(-1) ?? "";
1772
+ const memberOperator = indexable === "member" && /[.:]$/.test(prev);
1773
+ if (clause && clause !== "member" || prev.endsWith(",") || memberOperator) {
1774
+ finishWord(index);
1775
+ index += separator.length - 1;
1776
+ if (!memberOperator)
1777
+ indexable = false;
1778
+ continue;
1779
+ }
1780
+ if (!started && !words.length && !invocation) {
1781
+ index += separator.length - 1;
1782
+ indexable = false;
1783
+ continue;
1784
+ }
1176
1785
  }
1177
1786
  finishCommand(index, dangling || ![";", `
1178
1787
  `, "\r", `\r
@@ -1182,190 +1791,47 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
1182
1791
  `].includes(separator);
1183
1792
  statementHead = !dangling;
1184
1793
  index += separator.length - 1;
1185
- segment = index + 1;
1186
1794
  continue;
1187
1795
  }
1796
+ if (!started && !words.length && !invocation && hash !== "switch" && testAt(POWERSHELL_EXPRESSION_RE, input, index))
1797
+ expression = true;
1798
+ if ((atBoundary || indexable === "member" && /[.:]$/.test(word)) && char === "$")
1799
+ indexable = testAt(POWERSHELL_INDEXABLE_VAR_RE, input, index + 1) ? "variable" : false;
1800
+ else if (indexable === "closed")
1801
+ indexable = char === "." && input[index + 1] !== "." && !/\s/.test(input[index + 1] ?? "") || !started && char === ":" && input[index + 1] === ":" && !/\s/.test(input[index + 2] ?? "") || !started && char === "?" && input[index + 1] === "." && input[index + 2] !== "." && !/\s/.test(input[index + 2] ?? "") ? "member" : !started && char === "?" && input[index + 1] === "[" ? "closed" : false;
1802
+ else if (indexable === "variable")
1803
+ indexable = char === "." && input[index + 1] !== "." && !/\s/.test(input[index + 1] ?? "") || char === ":" && input[index + 1] === ":" && !/\s/.test(input[index + 2] ?? "") ? "member" : char === "." && input[index + 1] === "." || !/[\p{L}\p{Nl}\d_:?]/u.test(char) ? false : "variable";
1804
+ else if (indexable === "member")
1805
+ indexable = char === "." && input[index + 1] === "." ? false : char === "." && !/\s/.test(input[index + 1] ?? "") || char === ":" && (input[index + 1] === ":" || input[index - 1] === ":") || char === "?" && input[index + 1] === "." && input[index + 2] !== "." || /[\p{L}\p{Nl}\d_]/u.test(char) ? "member" : false;
1806
+ after = undefined;
1188
1807
  started = true;
1189
1808
  dangling = false;
1190
1809
  word += char;
1191
1810
  }
1811
+ if (close !== undefined && input[index] !== close)
1812
+ return { kind: "opaque", reason: "invalid-structure" };
1192
1813
  if (quote)
1193
1814
  return { kind: "opaque", reason: "unterminated-quote" };
1194
- if (!comment)
1195
- finishCommand(input.length);
1815
+ finishCommand(index);
1196
1816
  if (redirectTarget || invalid || dangling)
1197
1817
  return { kind: "opaque", reason: "invalid-structure" };
1198
1818
  if (commands.some((command) => !command.words[0]))
1199
1819
  return { kind: "opaque", reason: "dynamic-command-name" };
1200
- return { kind: "scanned", commands };
1201
- }
1202
- function powerShellBlock(input, start, depth) {
1203
- if (depth >= MAX_SUBSTITUTION_DEPTH)
1204
- return;
1205
- let quote;
1206
- let standalone = false;
1207
- let started = false;
1208
- let head = true;
1209
- let expression = false;
1210
- let token = "";
1211
- const close = input[start] === "(" ? ")" : input[start] === "[" ? "]" : "}";
1212
- for (let index = start + 1;index < input.length; index++) {
1213
- const char = input[index];
1214
- if (quote === "single") {
1215
- if (char === "'" && input[index + 1] === "'") {
1216
- token += "'";
1217
- index++;
1218
- } else if (char === "'") {
1219
- quote = undefined;
1220
- started = !standalone;
1221
- if (standalone)
1222
- token = "";
1223
- } else
1224
- token += char;
1225
- continue;
1226
- }
1227
- if (quote === "double") {
1228
- if (char === "`") {
1229
- const escape = powerShellEscape(input, index);
1230
- if (!escape)
1231
- return;
1232
- token += escape.value;
1233
- index = escape.end;
1234
- } else if (char === '"' && input[index + 1] === '"') {
1235
- token += '"';
1236
- index++;
1237
- } else if (char === '"') {
1238
- quote = undefined;
1239
- started = !standalone;
1240
- if (standalone)
1241
- token = "";
1242
- } else if (char === "$" && input[index + 1] === "(") {
1243
- const nested = powerShellBlock(input, index + 1, depth + 1);
1244
- if (!nested)
1245
- return;
1246
- index = nested.end;
1247
- } else
1248
- token += char;
1249
- continue;
1250
- }
1251
- if (char === "`") {
1252
- const escape = powerShellEscape(input, index);
1253
- if (!escape)
1254
- return;
1255
- if (started || /\S/.test(escape.value)) {
1256
- started = true;
1257
- token += escape.value;
1258
- }
1259
- index = escape.end;
1260
- continue;
1261
- }
1262
- if (char === "<" && input[index + 1] === "#" && !started) {
1263
- const end = powerShellComment(input, index);
1264
- if (end === undefined)
1265
- return;
1266
- index = end;
1267
- continue;
1268
- }
1269
- if (char === "#" && (!started || expression)) {
1270
- const endings = [input.indexOf(`
1271
- `, index), input.indexOf("\r", index)].filter((ending) => ending >= 0);
1272
- const newline = endings.length > 0 ? Math.min(...endings) : -1;
1273
- if (newline < 0)
1274
- return;
1275
- index = newline;
1276
- started = false;
1277
- head = true;
1278
- expression = false;
1279
- token = "";
1280
- continue;
1281
- }
1282
- if (char === "@" && /['"]/.test(input[index + 1] ?? "")) {
1283
- const literal = powerShellHereString(input, index);
1284
- if (!literal)
1285
- return;
1286
- index = literal.end;
1287
- started = false;
1288
- head = false;
1289
- continue;
1290
- }
1291
- if (head && !started && (char === "&" && input[index + 1] !== "&" || char === "." && /\s/.test(input[index + 1] ?? ""))) {
1292
- head = false;
1293
- continue;
1294
- }
1295
- if (expression && (char === "=" || !started && /^in\b/i.test(input.slice(index)))) {
1296
- if (char !== "=")
1297
- index++;
1298
- expression = false;
1299
- head = true;
1300
- started = false;
1301
- token = "";
1302
- continue;
1303
- }
1304
- if (char === "'" || char === '"') {
1305
- quote = char === "'" ? "single" : "double";
1306
- standalone = !started;
1307
- if (head && !started)
1308
- expression = true;
1309
- started = true;
1310
- continue;
1311
- }
1312
- const redirect = !started && (char === ">" || char === "*" || /\d/.test(char)) ? powerShellRedirect(input, index) : undefined;
1313
- if (redirect === false)
1314
- return;
1315
- if (redirect) {
1316
- index += redirect.length - 1;
1317
- token = "";
1318
- continue;
1319
- }
1320
- if (char === "$" && input[index + 1] === "{") {
1321
- const end = input.indexOf("}", index + 2);
1322
- if (end < 0)
1323
- return;
1324
- if (head && !started)
1325
- expression = true;
1326
- index = end;
1327
- started = true;
1328
- continue;
1329
- }
1330
- if (!started && !head && !expression && /^--%(?=$|[\s;|&(){}])/.test(input.slice(index))) {
1331
- index = powerShellStopParsing(input, index + 3) - 1;
1332
- continue;
1333
- }
1334
- if (char === close)
1335
- return { source: input.slice(start + 1, index), end: index };
1336
- if (char === "(" || char === "{" || char === "[" && (!started || expression)) {
1337
- if (head && !started)
1338
- expression = true;
1339
- const nested = powerShellBlock(input, index, depth + 1);
1340
- if (!nested)
1341
- return;
1342
- index = nested.end;
1343
- started = false;
1344
- head = false;
1345
- token = "";
1346
- continue;
1347
- }
1348
- if (/[\s;&|]/.test(char)) {
1349
- if (token === "--%" && !expression) {
1350
- index = powerShellStopParsing(input, index) - 1;
1351
- token = "";
1352
- continue;
1353
- }
1354
- if (/[;&|\r\n]/.test(char)) {
1355
- head = true;
1356
- expression = false;
1357
- } else if (started)
1358
- head = false;
1359
- started = false;
1360
- token = "";
1361
- continue;
1362
- }
1363
- if (head && !started && powerShellExpression(input.slice(index)))
1364
- expression = true;
1365
- started = true;
1366
- token += char;
1367
- }
1820
+ return { kind: "scanned", commands, end: index };
1368
1821
  }
1822
+ var POWERSHELL_STOP_PARSING_RE = /--%(?=$|[\s;|&(){}])/y;
1823
+ var POWERSHELL_PARAMETER_COLON_RE = /^-[\p{L}\p{Nl}_?][\p{L}\p{Nl}\d_?-]*:$/u;
1824
+ var POWERSHELL_MERGE_REDIRECT_RE = /\d>&/y;
1825
+ var POWERSHELL_LABEL_RE = /:[A-Za-z_]\w*(?=\s*(?:while|for|foreach|do|switch)(?=$|[\s&(),;{|}]))/iy;
1826
+ var POWERSHELL_KEYWORD_RE = /[A-Za-z]+(?=$|[\s&(),;{|}])/y;
1827
+ var POWERSHELL_FOREACH_RE = /foreach\s*\(/isy;
1828
+ var POWERSHELL_PARAM_RE = /param\s*\(/isy;
1829
+ var POWERSHELL_IN_RE = /in(?=$|[\s&(),;{|}])/iy;
1830
+ var POWERSHELL_AT_OPENER_RE = /[({'"\p{L}\p{Nl}\d_?]/uy;
1831
+ var POWERSHELL_INDEXABLE_VAR_RE = /(?::[\p{L}\p{Nl}\d_?]+|[\p{L}\p{Nl}\d_][\p{L}\p{Nl}\d_?]*)/uy;
1832
+ var POWERSHELL_HERE_HEADER_RE = /@['"][^\S\r\n]*(?:\r\n|\r|\n)/y;
1833
+ var POWERSHELL_UNICODE_ESCAPE_RE = /u\{([0-9a-f]{1,6})\}/iy;
1834
+ var POWERSHELL_EXPRESSION_RE = /(?:!*(?:\+\+|--|[+-])?\$(?:\{|(?:\?|\$|\^)(?=$|[\s;|&(){},#>])|:[\p{L}\p{Nl}\d_?]+|[\p{L}\p{Nl}\d_][\p{L}\p{Nl}\d_?]*(?::[\p{L}\p{Nl}\d_?]+)?)|!(?![\p{L}\p{Nl}_.\d])|\+(?![=\p{L}\p{Nl}_.\d])|--(?!=)|-(?![=\p{L}\p{Nl}\d_?.])|,(?!\s*$)|!*[+-]?(?:0[xX][\da-fA-F]+|0[bB][01]+|(?:\d+(?:\.(?!\.)\d*|(?!\.(?!\.)))|\.\d+)(?:[eE][+-]?\d+)?)(?:[dDlLnN]|[uU][sSyYlL]?|[sSyY])?(?:[kKmMgGtTpP][bB])?(?=$|[\s!#%&()*+,\-/.;<=>\]|{}])|-(?:not|bnot|join|[ic]?split)(?![\p{L}\p{Nl}]))/iuy;
1369
1835
  var POWERSHELL_ESCAPES = {
1370
1836
  "0": "\x00",
1371
1837
  a: "\x07",
@@ -1378,80 +1844,145 @@ var POWERSHELL_ESCAPES = {
1378
1844
  t: "\t",
1379
1845
  v: "\v"
1380
1846
  };
1381
- function powerShellEscape(input, start) {
1382
- const char = input[start + 1];
1847
+ function matchAt(regex, input, index) {
1848
+ regex.lastIndex = index;
1849
+ return regex.exec(input);
1850
+ }
1851
+ function testAt(regex, input, index) {
1852
+ regex.lastIndex = index;
1853
+ return regex.test(input);
1854
+ }
1855
+ function powerShellEscape(input, start, lineContinuation = false, skipped) {
1856
+ let next = start + 1;
1857
+ while (skipped?.has(next))
1858
+ next++;
1859
+ const char = input[next];
1383
1860
  if (char === undefined)
1384
1861
  return;
1385
1862
  if (char === "\r" || char === `
1386
1863
  `)
1387
1864
  return {
1388
- value: char === "\r" && input[start + 2] === `
1865
+ value: lineContinuation && char === "\r" && input[next + 1] === `
1389
1866
  ` ? `\r
1390
1867
  ` : char,
1391
- end: start + (char === "\r" && input[start + 2] === `
1392
- ` ? 2 : 1)
1868
+ end: next + (lineContinuation && char === "\r" && input[next + 1] === `
1869
+ ` ? 1 : 0)
1393
1870
  };
1394
- if (char === "u" && input[start + 2] === "{") {
1395
- const code = /^u\{([0-9a-f]{1,6})\}/i.exec(input.slice(start + 1));
1871
+ if (char === "u" && input[next + 1] === "{") {
1872
+ const code = matchAt(POWERSHELL_UNICODE_ESCAPE_RE, input, next);
1396
1873
  if (!code || Number.parseInt(code[1], 16) > 1114111)
1397
1874
  return;
1398
- return { value: String.fromCodePoint(Number.parseInt(code[1], 16)), end: start + code[0].length };
1875
+ return { value: String.fromCodePoint(Number.parseInt(code[1], 16)), end: next + code[0].length - 1 };
1876
+ }
1877
+ return { value: POWERSHELL_ESCAPES[char] ?? char, end: next };
1878
+ }
1879
+ function powerShellBracedVariable(input, start, skipped) {
1880
+ for (let index = start + 2;index < input.length; index++) {
1881
+ if (skipped?.has(index))
1882
+ continue;
1883
+ if (input[index] === "`") {
1884
+ const escape = powerShellEscape(input, index, false, skipped);
1885
+ if (!escape)
1886
+ return;
1887
+ index = escape.end;
1888
+ continue;
1889
+ }
1890
+ if (input[index] === "}")
1891
+ return index > start + 2 ? index : undefined;
1399
1892
  }
1400
- return { value: POWERSHELL_ESCAPES[char] ?? char, end: start + 1 };
1401
1893
  }
1402
- function powerShellExpression(input) {
1403
- return /^(?:[$!,+]|[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?(?:[dDlLnNuU]|[kKmMgGtTpP][bB])?(?![\w'"`])|0[xX][\da-fA-F]+\b|0[bB][01]+\b|\.[0-9]|-(?:not|bnot|join|split)\b)/i.test(input);
1894
+ function powerShellSubExpression(input, start, hereString, budget, skipped) {
1895
+ const nextSkipped = new Set(skipped);
1896
+ let depth = 1;
1897
+ let rawEnd;
1898
+ for (let index = start;index < input.length; index++) {
1899
+ if (--budget.remaining < 0)
1900
+ return;
1901
+ if (nextSkipped.has(index))
1902
+ continue;
1903
+ const char = input[index];
1904
+ if (char === "(")
1905
+ depth++;
1906
+ else if (char === ")") {
1907
+ if (--depth === 0 && rawEnd === undefined)
1908
+ rawEnd = index;
1909
+ } else if (!hereString && (char === '"' || char === "`")) {
1910
+ let next = index + 1;
1911
+ while (nextSkipped.has(next))
1912
+ next++;
1913
+ if (input[next] === '"') {
1914
+ nextSkipped.add(index);
1915
+ index = next;
1916
+ }
1917
+ }
1918
+ }
1919
+ return { skipped: nextSkipped, rawEnd };
1404
1920
  }
1405
- function powerShellStopParsing(input, start) {
1921
+ function powerShellStopParsing(input, start, skipped) {
1406
1922
  let quoted = false;
1407
1923
  for (let index = start;index < input.length; index++) {
1924
+ if (skipped?.has(index))
1925
+ continue;
1408
1926
  if (input[index] === '"')
1409
1927
  quoted = !quoted;
1410
1928
  if (input[index] === "\r" || input[index] === `
1411
- ` || input[index] === "|" && !quoted)
1929
+ ` || (input[index] === "|" || input[index] === "&" && input[index + 1] === "&") && !quoted)
1412
1930
  return index;
1413
1931
  }
1414
1932
  return input.length;
1415
1933
  }
1416
- function powerShellComment(input, start) {
1417
- const end = input.indexOf("#>", start + 2);
1418
- return end < 0 ? undefined : end + 1;
1419
- }
1420
- function powerShellHereString(input, start) {
1421
- const header = /^@['"][ \t]*(?:\r\n|\r|\n)/.exec(input.slice(start));
1934
+ function powerShellHereString(input, start, depth, budget, skipped) {
1935
+ const header = matchAt(POWERSHELL_HERE_HEADER_RE, input, start);
1422
1936
  if (!header)
1423
- return;
1937
+ return { kind: "opaque", reason: "unterminated-quote" };
1938
+ const quote = input[start + 1];
1424
1939
  const body = start + header[0].length;
1940
+ const commands = [];
1941
+ let lineStart = true;
1425
1942
  for (let index = body;index < input.length; index++) {
1426
- if (index !== body && input[index - 1] !== "\r" && input[index - 1] !== `
1427
- `)
1428
- continue;
1429
- if (input[index] !== input[start + 1] || input[index + 1] !== "@")
1943
+ if (--budget.remaining < 0)
1944
+ return { kind: "opaque", reason: "invalid-structure" };
1945
+ if (skipped?.has(index))
1430
1946
  continue;
1431
- const end = index > body && input[index - 1] === `
1947
+ if (lineStart && input[index] === quote && input[index + 1] === "@") {
1948
+ const end = index > body && input[index - 1] === `
1432
1949
  ` && input[index - 2] === "\r" ? index - 2 : index > body ? index - 1 : index;
1433
- return { source: input.slice(body, end), end: index + 1 };
1434
- }
1435
- }
1436
- function powerShellExpansions(input, depth, budget) {
1437
- const commands = [];
1438
- for (let index = 0;index < input.length; index++) {
1439
- if (input[index] === "`") {
1440
- index++;
1441
- continue;
1950
+ return { kind: "scanned", commands, source: input.slice(body, end), end: index + 1 };
1442
1951
  }
1443
- if (!input.startsWith("$(", index))
1444
- continue;
1445
- const block = powerShellBlock(input, index + 1, depth);
1446
- if (!block)
1447
- return { kind: "opaque", reason: "invalid-structure" };
1448
- const result = scanPowerShellNested(block.source, depth + 1, budget);
1449
- if (result.kind === "opaque")
1450
- return result;
1451
- commands.push(...result.commands);
1452
- index = block.end;
1952
+ if (quote === '"') {
1953
+ if (input[index] === "`") {
1954
+ const escape = powerShellEscape(input, index, false, skipped);
1955
+ if (!escape)
1956
+ return { kind: "opaque", reason: "unterminated-escape" };
1957
+ index = escape.end;
1958
+ lineStart = false;
1959
+ continue;
1960
+ }
1961
+ if (input[index] === "$" && input[index + 1] === "{") {
1962
+ const end = powerShellBracedVariable(input, index, skipped);
1963
+ if (end === undefined)
1964
+ return { kind: "opaque", reason: "invalid-structure" };
1965
+ index = end;
1966
+ lineStart = false;
1967
+ continue;
1968
+ }
1969
+ if (input[index] === "$" && input[index + 1] === "(") {
1970
+ const sub = powerShellSubExpression(input, index + 2, true, budget, skipped);
1971
+ if (!sub)
1972
+ return { kind: "opaque", reason: "invalid-structure" };
1973
+ const result = scanPowerShellList(input, index + 2, depth + 1, budget, ")", false, sub.skipped);
1974
+ if (result.kind === "opaque")
1975
+ return result;
1976
+ commands.push(...result.commands);
1977
+ index = sub.rawEnd !== undefined && sub.rawEnd > result.end ? sub.rawEnd : result.end;
1978
+ lineStart = false;
1979
+ continue;
1980
+ }
1981
+ }
1982
+ lineStart = input[index] === "\r" || input[index] === `
1983
+ `;
1453
1984
  }
1454
- return { kind: "scanned", commands };
1985
+ return { kind: "opaque", reason: "unterminated-quote" };
1455
1986
  }
1456
1987
  function powerShellRedirect(input, index) {
1457
1988
  let cursor = index;