@opencode/core 0.0.0-dev-20573 → 0.0.0-dev-20577

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 (781) hide show
  1. package/dist/account/sql.js +1 -1
  2. package/dist/agent.js +83 -83
  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/{managed-policy-6h1ernme.js → command-03xyy9gs.js} +11 -11
  8. package/dist/chunks/{managed-policy-x87fjewg.js → command-04jjrec1.js} +15 -15
  9. package/dist/chunks/{managed-policy-6sef0hhh.js → command-090p1w3a.js} +5 -5
  10. package/dist/chunks/{managed-policy-8nxh848s.js → command-09e69a7b.js} +18 -18
  11. package/dist/chunks/{managed-policy-tawa04ge.js → command-0e74cksd.js} +10 -10
  12. package/dist/chunks/{managed-policy-0paq2nw3.js → command-0paq2nw3.js} +1 -1
  13. package/dist/chunks/{managed-policy-6bt18bw3.js → command-0sqmrpn2.js} +32 -32
  14. package/dist/chunks/{managed-policy-0vbcp93d.js → command-0vbcp93d.js} +2 -2
  15. package/dist/chunks/{managed-policy-ryv7kf54.js → command-0vsnxwjm.js} +3 -3
  16. package/dist/chunks/{managed-policy-xpy2c5sa.js → command-0xf97k36.js} +11 -11
  17. package/dist/chunks/{managed-policy-0w1gqsy8.js → command-0y86tmwb.js} +6 -6
  18. package/dist/chunks/{managed-policy-y0ckc452.js → command-117ga8q0.js} +27 -27
  19. package/dist/chunks/{managed-policy-ypg8t1cz.js → command-124e8td1.js} +13 -13
  20. package/dist/chunks/command-13dwg0c6.js +253 -0
  21. package/dist/chunks/{managed-policy-esn5ytq2.js → command-14tdwscn.js} +17 -17
  22. package/dist/chunks/{managed-policy-aj7dfagr.js → command-15nnh4s6.js} +3 -3
  23. package/dist/chunks/{managed-policy-vwvztrq4.js → command-18htcbrq.js} +9 -9
  24. package/dist/chunks/command-1d727dm9.js +507 -0
  25. package/dist/chunks/{managed-policy-1dazxqgg.js → command-1dazxqgg.js} +2 -2
  26. package/dist/chunks/{managed-policy-1dvck2a7.js → command-1dvck2a7.js} +2 -2
  27. package/dist/chunks/{managed-policy-wex1rs68.js → command-1n8tchc4.js} +19 -19
  28. package/dist/chunks/command-1x11rq2a.js +18 -0
  29. package/dist/chunks/{managed-policy-1ygqh575.js → command-1ygqh575.js} +2 -2
  30. package/dist/chunks/{managed-policy-7knbcmrm.js → command-1ytwep67.js} +5 -5
  31. package/dist/chunks/{managed-policy-s3y29egc.js → command-1zc1gz4g.js} +12 -12
  32. package/dist/chunks/{managed-policy-ja0sgbvz.js → command-22qzwdfx.js} +11 -11
  33. package/dist/chunks/{managed-policy-25y70375.js → command-261teatt.js} +5 -5
  34. package/dist/chunks/{managed-policy-2a5m3afh.js → command-2a5m3afh.js} +1 -1
  35. package/dist/chunks/{managed-policy-3h1mrgx9.js → command-2avtt150.js} +20 -20
  36. package/dist/chunks/{managed-policy-0zc2mhc2.js → command-2g0f3sn5.js} +24 -24
  37. package/dist/chunks/{managed-policy-vy06qy77.js → command-2rx8305r.js} +21 -21
  38. package/dist/chunks/{managed-policy-8ypw52cc.js → command-2y035twn.js} +10 -10
  39. package/dist/chunks/{managed-policy-vxp78acx.js → command-2zqhm02j.js} +9 -9
  40. package/dist/chunks/{managed-policy-0cv4znyc.js → command-359sf8pg.js} +26 -26
  41. package/dist/chunks/{managed-policy-4t8tabd3.js → command-364yjtd9.js} +11 -11
  42. package/dist/chunks/{managed-policy-511tn27r.js → command-39yjv8hn.js} +51 -51
  43. package/dist/chunks/{managed-policy-f8cwpv8g.js → command-3ac3enw2.js} +24 -24
  44. package/dist/chunks/{managed-policy-3fc6dm20.js → command-3fc6dm20.js} +1 -1
  45. package/dist/chunks/{managed-policy-e84pketw.js → command-3haxx6pm.js} +23 -23
  46. package/dist/chunks/{managed-policy-3hepkmqq.js → command-3hepkmqq.js} +1 -1
  47. package/dist/chunks/{managed-policy-3smtnn6g.js → command-3smtnn6g.js} +1 -1
  48. package/dist/chunks/{managed-policy-3tvqynh2.js → command-3tvqynh2.js} +1 -1
  49. package/dist/chunks/{managed-policy-3zsf4n22.js → command-3zsf4n22.js} +1 -1
  50. package/dist/chunks/{managed-policy-c72jpxp5.js → command-43krc4bk.js} +9 -9
  51. package/dist/chunks/{managed-policy-5evqd07b.js → command-43ya1ftk.js} +37 -37
  52. package/dist/chunks/{managed-policy-dkkqkk8e.js → command-44wsf4p6.js} +8 -8
  53. package/dist/chunks/{managed-policy-3dktm290.js → command-48cj2z6f.js} +22 -22
  54. package/dist/chunks/{managed-policy-atvzh22c.js → command-4ampwn7w.js} +18 -18
  55. package/dist/chunks/{managed-policy-mjx80hf2.js → command-4gm9b3mc.js} +90 -90
  56. package/dist/chunks/{managed-policy-2nfjsejh.js → command-4m4650rm.js} +15 -15
  57. package/dist/chunks/{managed-policy-2ccvkpx1.js → command-4ts7tf6z.js} +2 -2
  58. package/dist/chunks/{managed-policy-h6310vsd.js → command-4v7ngy20.js} +4 -4
  59. package/dist/chunks/{managed-policy-j8ayz9nh.js → command-4yhhdjvm.js} +16 -16
  60. package/dist/chunks/{managed-policy-3mq0jxky.js → command-51rych25.js} +69 -69
  61. package/dist/chunks/{managed-policy-54ma36ye.js → command-54ma36ye.js} +1 -1
  62. package/dist/chunks/{managed-policy-5daktx2q.js → command-5daktx2q.js} +1 -1
  63. package/dist/chunks/{managed-policy-drnf6xwf.js → command-5pyjqqve.js} +2 -2
  64. package/dist/chunks/{managed-policy-e3qxr5gk.js → command-5qd3pb7m.js} +2 -2
  65. package/dist/chunks/{managed-policy-5t3nmthw.js → command-5t3nmthw.js} +2 -2
  66. package/dist/chunks/{managed-policy-fer3tpfm.js → command-5w6ne2rj.js} +11 -11
  67. package/dist/chunks/{managed-policy-p37cw4rj.js → command-5yzzbxa7.js} +8 -8
  68. package/dist/chunks/{managed-policy-x8qskf82.js → command-6238m7q1.js} +3 -3
  69. package/dist/chunks/{managed-policy-djxtchgp.js → command-62yts832.js} +29 -29
  70. package/dist/chunks/{managed-policy-669tq793.js → command-669tq793.js} +1 -1
  71. package/dist/chunks/{managed-policy-129ea1c5.js → command-66c3eymz.js} +5 -5
  72. package/dist/chunks/{managed-policy-h04cqsq0.js → command-69j91c1q.js} +8 -8
  73. package/dist/chunks/{managed-policy-5xb9sx95.js → command-6etn2fpm.js} +18 -18
  74. package/dist/chunks/{managed-policy-4t68vy7n.js → command-6gwd6jt4.js} +5 -5
  75. package/dist/chunks/{managed-policy-7a16p2b4.js → command-6kz41x2h.js} +8 -8
  76. package/dist/chunks/{managed-policy-cbkntbps.js → command-6q6vmr50.js} +3 -3
  77. package/dist/chunks/{managed-policy-6xb47vfp.js → command-6xb47vfp.js} +1 -1
  78. package/dist/chunks/{managed-policy-71az546q.js → command-71az546q.js} +2 -2
  79. package/dist/chunks/{managed-policy-zsg1x2zr.js → command-759ca8qw.js} +11 -11
  80. package/dist/chunks/{managed-policy-qmqgtz8f.js → command-79qaa2kf.js} +9 -9
  81. package/dist/chunks/{managed-policy-7bmhse3q.js → command-7bmhse3q.js} +1 -1
  82. package/dist/chunks/{managed-policy-3ejrkq1r.js → command-7pjv18ns.js} +10 -10
  83. package/dist/chunks/{managed-policy-vzza7dkm.js → command-7rbxqkgq.js} +29 -29
  84. package/dist/chunks/{managed-policy-84txncab.js → command-84txncab.js} +1 -1
  85. package/dist/chunks/{managed-policy-2pmt9451.js → command-873y03zv.js} +17 -17
  86. package/dist/chunks/{managed-policy-8d7r5vzw.js → command-8d7r5vzw.js} +1 -1
  87. package/dist/chunks/{managed-policy-ntxzz37g.js → command-8fgecypx.js} +9 -9
  88. package/dist/chunks/{managed-policy-339zj8hc.js → command-8htcd2rv.js} +24 -24
  89. package/dist/chunks/{managed-policy-b27vhd2z.js → command-8rqycdgd.js} +7 -7
  90. package/dist/chunks/{managed-policy-ryhmzq0e.js → command-930nf9me.js} +21 -21
  91. package/dist/chunks/{managed-policy-cdm0dq9n.js → command-93ygb5af.js} +6 -6
  92. package/dist/chunks/{managed-policy-psf6hctd.js → command-9898pk67.js} +20 -20
  93. package/dist/chunks/{managed-policy-9e5bzkjp.js → command-9e5bzkjp.js} +3 -3
  94. package/dist/chunks/{managed-policy-6faxztjw.js → command-9fn597ry.js} +11 -11
  95. package/dist/chunks/{managed-policy-r27td32p.js → command-9kr67f7m.js} +33 -33
  96. package/dist/chunks/{managed-policy-vxefasdb.js → command-9p61zhgr.js} +11 -11
  97. package/dist/chunks/{managed-policy-3rzf3ge5.js → command-9xs2qmrx.js} +15 -15
  98. package/dist/chunks/{managed-policy-atpyhfjn.js → command-a03229d4.js} +13 -13
  99. package/dist/chunks/{managed-policy-mhkvc446.js → command-a1gpj94z.js} +3 -3
  100. package/dist/chunks/{managed-policy-9tkeerev.js → command-a2ccr785.js} +16 -16
  101. package/dist/chunks/{managed-policy-0t08qwy3.js → command-a2w70vx4.js} +11 -11
  102. package/dist/chunks/{managed-policy-aaet6srn.js → command-aaet6srn.js} +2 -2
  103. package/dist/chunks/{managed-policy-ydce7fv0.js → command-aaz61dev.js} +16 -16
  104. package/dist/chunks/{managed-policy-x661k3y3.js → command-addxnjmp.js} +4 -4
  105. package/dist/chunks/{managed-policy-ca7w653e.js → command-afdssyjb.js} +4 -4
  106. package/dist/chunks/{managed-policy-ayb7n7km.js → command-agq9zd11.js} +15 -15
  107. package/dist/chunks/{managed-policy-53yba217.js → command-b1enpsaa.js} +18 -18
  108. package/dist/chunks/{managed-policy-b6gygkdw.js → command-b6gygkdw.js} +2 -2
  109. package/dist/chunks/{managed-policy-m5n4tx0e.js → command-b9xnfexb.js} +1 -1
  110. package/dist/chunks/command-bb7jf4d3.js +26 -0
  111. package/dist/chunks/{managed-policy-dddb8f4m.js → command-bgtt2kw4.js} +24 -24
  112. package/dist/chunks/{managed-policy-q6nwrqf2.js → command-bkwxdpdb.js} +11 -11
  113. package/dist/chunks/{managed-policy-ry082wg0.js → command-bsprd9wx.js} +9 -9
  114. package/dist/chunks/{managed-policy-hs1x7rht.js → command-c2qavkps.js} +12 -12
  115. package/dist/chunks/{managed-policy-ef4wyqj0.js → command-cb72tr97.js} +24 -24
  116. package/dist/chunks/{managed-policy-b1a0f7dt.js → command-cb8p8a9z.js} +9 -9
  117. package/dist/chunks/{managed-policy-ny1k4mkg.js → command-cg85h34c.js} +14 -9
  118. package/dist/chunks/{managed-policy-8cy1jxbx.js → command-ck8npcm5.js} +11 -11
  119. package/dist/chunks/{managed-policy-smdvcsfx.js → command-cmkc9sfw.js} +33 -33
  120. package/dist/chunks/{managed-policy-p46h068t.js → command-denjr0qg.js} +3 -3
  121. package/dist/chunks/{managed-policy-nnaaypem.js → command-dfajfnkg.js} +32 -32
  122. package/dist/chunks/{managed-policy-51b900pe.js → command-dm4vbrvx.js} +2 -2
  123. package/dist/chunks/{managed-policy-r3gavybk.js → command-dm5ssyfm.js} +37 -37
  124. package/dist/chunks/{managed-policy-dpkg50ah.js → command-dpkg50ah.js} +1 -1
  125. package/dist/chunks/{managed-policy-57myy5jh.js → command-dssbfrwz.js} +5 -5
  126. package/dist/chunks/{managed-policy-9285ze7h.js → command-e3ecsdy8.js} +17 -17
  127. package/dist/chunks/{managed-policy-dzbnqpsq.js → command-e55nq1dx.js} +16 -16
  128. package/dist/chunks/{managed-policy-z4gw67s9.js → command-edajgpnh.js} +16 -16
  129. package/dist/chunks/{managed-policy-ef5x83kb.js → command-ef5x83kb.js} +1 -1
  130. package/dist/chunks/{managed-policy-2ycyqxta.js → command-ehq1cete.js} +3 -3
  131. package/dist/chunks/{managed-policy-gh5z95q3.js → command-en9mxp96.js} +9 -9
  132. package/dist/chunks/{managed-policy-etq0c3wd.js → command-etq0c3wd.js} +1 -1
  133. package/dist/chunks/{managed-policy-x2dbcb4h.js → command-evpm7vcg.js} +31 -31
  134. package/dist/chunks/{managed-policy-w8hsdjbm.js → command-f18tyt2v.js} +17 -17
  135. package/dist/chunks/{managed-policy-agr05fc9.js → command-f2hjv5fy.js} +5 -5
  136. package/dist/chunks/{managed-policy-1wzqj0s9.js → command-f3e4f3ew.js} +15 -15
  137. package/dist/chunks/{managed-policy-4n607a2z.js → command-f62qkzqr.js} +5 -5
  138. package/dist/chunks/{managed-policy-7cfvasrj.js → command-fkscjsp5.js} +11 -11
  139. package/dist/chunks/{managed-policy-dacqb9yg.js → command-fp6k91eh.js} +31 -31
  140. package/dist/chunks/{managed-policy-v0es1rhs.js → command-fpecnkgp.js} +9 -9
  141. package/dist/chunks/{managed-policy-3mqxf2xp.js → command-g53c9fq7.js} +5 -5
  142. package/dist/chunks/{managed-policy-gd4qta3r.js → command-gd4qta3r.js} +1 -1
  143. package/dist/chunks/{managed-policy-0v8xwd3z.js → command-gh22p3be.js} +27 -27
  144. package/dist/chunks/{managed-policy-y9jxj3xf.js → command-gh3sjhhn.js} +14 -14
  145. package/dist/chunks/{managed-policy-qw80rk8q.js → command-gpygzsz4.js} +15 -15
  146. package/dist/chunks/{managed-policy-m648ver0.js → command-gq98prpa.js} +13 -13
  147. package/dist/chunks/{managed-policy-c27esgm9.js → command-gs3s1a1g.js} +8 -8
  148. package/dist/chunks/{managed-policy-h2b79v29.js → command-h2b79v29.js} +2 -2
  149. package/dist/chunks/{managed-policy-h6vf3j39.js → command-h6vf3j39.js} +1 -1
  150. package/dist/chunks/{managed-policy-39x1ek8q.js → command-h9hcchbf.js} +85 -85
  151. package/dist/chunks/{managed-policy-mt2x9463.js → command-h9rj7vgp.js} +11 -11
  152. package/dist/chunks/{managed-policy-6v0ne2a7.js → command-hbj68pgm.js} +36 -36
  153. package/dist/chunks/{managed-policy-hxa2e638.js → command-hbqne9jm.js} +48 -48
  154. package/dist/chunks/{managed-policy-w4raeb9k.js → command-hdy9dvcx.js} +4 -4
  155. package/dist/chunks/{managed-policy-bn8byrsw.js → command-hndmfkfz.js} +10 -10
  156. package/dist/chunks/{managed-policy-1dnkanva.js → command-hphxefgw.js} +10 -10
  157. package/dist/chunks/{managed-policy-a3s4m96j.js → command-hwc5fhjs.js} +35 -35
  158. package/dist/chunks/{managed-policy-4ysfdygz.js → command-j0gyfj28.js} +45 -45
  159. package/dist/chunks/{managed-policy-q6yya7b3.js → command-j34dxvpb.js} +5 -5
  160. package/dist/chunks/{managed-policy-j56e64zr.js → command-j56e64zr.js} +1 -1
  161. package/dist/chunks/{managed-policy-2a190g8q.js → command-j6zg015w.js} +42 -42
  162. package/dist/chunks/{managed-policy-srrtgwss.js → command-j74e336s.js} +13 -13
  163. package/dist/chunks/{managed-policy-q7sc1zt6.js → command-jaa0b0hs.js} +17 -17
  164. package/dist/chunks/{managed-policy-53smy2sa.js → command-jb4r1kxp.js} +16 -16
  165. package/dist/chunks/{managed-policy-6yvhnn4s.js → command-jfvphnye.js} +26 -26
  166. package/dist/chunks/{managed-policy-c0g4z4r6.js → command-jkwx8shz.js} +8 -8
  167. package/dist/chunks/{managed-policy-s1twwq6b.js → command-jsf24svj.js} +40 -40
  168. package/dist/chunks/{managed-policy-aag4dp4v.js → command-jyrncrt6.js} +20 -20
  169. package/dist/chunks/{managed-policy-yts3es8x.js → command-k1qrnqst.js} +8 -8
  170. package/dist/chunks/{managed-policy-hd34jy2k.js → command-k2srk8cp.js} +3 -3
  171. package/dist/chunks/{managed-policy-veaq2k26.js → command-k5vew2r0.js} +20 -20
  172. package/dist/chunks/{managed-policy-4wwqnvbr.js → command-kb6vbnxp.js} +4 -4
  173. package/dist/chunks/{managed-policy-qp68tzqz.js → command-kenkf5s7.js} +57 -57
  174. package/dist/chunks/{managed-policy-4vzctj39.js → command-kfmjg78y.js} +6 -6
  175. package/dist/chunks/{managed-policy-44zeqmfs.js → command-kp93eabn.js} +15 -15
  176. package/dist/chunks/{managed-policy-yp5sqj81.js → command-krz37b5z.js} +54 -54
  177. package/dist/chunks/{managed-policy-0qhbbj6s.js → command-kt2w57dr.js} +44 -44
  178. package/dist/chunks/{managed-policy-h19p288y.js → command-kz5zsevx.js} +2 -2
  179. package/dist/chunks/{managed-policy-8hqjmg8z.js → command-m0kkpct9.js} +5 -5
  180. package/dist/chunks/{managed-policy-m3fdjcah.js → command-m3fdjcah.js} +1 -1
  181. package/dist/chunks/{managed-policy-e0k1gts1.js → command-m9bwhd6g.js} +24 -24
  182. package/dist/chunks/{managed-policy-m9w0rfyh.js → command-m9w0rfyh.js} +1 -1
  183. package/dist/chunks/{managed-policy-mesbzd6m.js → command-mac87736.js} +6 -6
  184. package/dist/chunks/{managed-policy-hra4v9c4.js → command-max5zner.js} +29 -29
  185. package/dist/chunks/{managed-policy-8ypdmw1d.js → command-mj9cksj0.js} +22 -22
  186. package/dist/chunks/{managed-policy-2pnhn36q.js → command-mjymc32g.js} +21 -21
  187. package/dist/chunks/{managed-policy-s2skr6r0.js → command-mq1114ms.js} +4 -4
  188. package/dist/chunks/{managed-policy-epqykn4s.js → command-mydvvph4.js} +26 -26
  189. package/dist/chunks/{managed-policy-5amwhyk8.js → command-n0pywpq4.js} +6 -6
  190. package/dist/chunks/{managed-policy-z95wdz15.js → command-n71h44cm.js} +17 -17
  191. package/dist/chunks/{managed-policy-8whseyrk.js → command-ncnm8wen.js} +1 -1
  192. package/dist/chunks/{managed-policy-p7dv4t4h.js → command-nf8njrqz.js} +13 -13
  193. package/dist/chunks/{managed-policy-p04qdsev.js → command-nz49q0p3.js} +26 -26
  194. package/dist/chunks/{managed-policy-pjvnvgmy.js → command-pjvnvgmy.js} +1 -1
  195. package/dist/chunks/{managed-policy-pknna89w.js → command-pknna89w.js} +1 -1
  196. package/dist/chunks/{managed-policy-py3kkmfq.js → command-py3kkmfq.js} +2 -2
  197. package/dist/chunks/{managed-policy-4nqf33ty.js → command-pz4bzxx2.js} +24 -24
  198. package/dist/chunks/{managed-policy-0j77ygfz.js → command-q0xm7vwc.js} +6 -6
  199. package/dist/chunks/{managed-policy-hxv6k9fk.js → command-q1dr63v1.js} +11 -11
  200. package/dist/chunks/{managed-policy-9t2hev6v.js → command-q36shhmj.js} +16 -16
  201. package/dist/chunks/{managed-policy-3pv9q41e.js → command-q43fwr5x.js} +13 -13
  202. package/dist/chunks/{managed-policy-t0pyhqcw.js → command-q8ejgrh7.js} +11 -11
  203. package/dist/chunks/{managed-policy-n828b74y.js → command-qfaf6res.js} +20 -20
  204. package/dist/chunks/{managed-policy-mm29tsj0.js → command-qgma0hvn.js} +10 -10
  205. package/dist/chunks/{managed-policy-2k8khapm.js → command-qgn6gcr1.js} +5 -5
  206. package/dist/chunks/{managed-policy-e97nvsvy.js → command-qh49khd6.js} +6 -6
  207. package/dist/chunks/{managed-policy-sjccd0hs.js → command-qkj8hkyk.js} +46 -46
  208. package/dist/chunks/{managed-policy-aq9ba85s.js → command-qkr42znk.js} +9 -9
  209. package/dist/chunks/{managed-policy-qnc92qwc.js → command-qnc92qwc.js} +1 -1
  210. package/dist/chunks/{managed-policy-vkt5fbj2.js → command-qp3v07n2.js} +6 -6
  211. package/dist/chunks/{managed-policy-1b7h3mkk.js → command-qqdfvssg.js} +15 -15
  212. package/dist/chunks/{managed-policy-qsdy395h.js → command-qsdy395h.js} +1 -1
  213. package/dist/chunks/{managed-policy-qxjc9qry.js → command-qxjc9qry.js} +3 -3
  214. package/dist/chunks/{managed-policy-0xwy5psd.js → command-r0wedrkd.js} +18 -18
  215. package/dist/chunks/{managed-policy-jr4wt5sk.js → command-r1g3ttfx.js} +30 -30
  216. package/dist/chunks/{managed-policy-yp2x3t23.js → command-r8xr0va3.js} +4 -4
  217. package/dist/chunks/{managed-policy-z3vw1wky.js → command-r8ys1pjh.js} +4 -4
  218. package/dist/chunks/{managed-policy-11dqjexa.js → command-r9w3djhf.js} +9 -9
  219. package/dist/chunks/{managed-policy-hdqdgbqm.js → command-rawzh9f5.js} +28 -28
  220. package/dist/chunks/{managed-policy-rdw6cm16.js → command-rdw6cm16.js} +1 -1
  221. package/dist/chunks/{managed-policy-dvzj1xmf.js → command-rjq8wmvv.js} +9 -9
  222. package/dist/chunks/{managed-policy-npjvna1z.js → command-rkrj05tv.js} +35 -35
  223. package/dist/chunks/{managed-policy-mppj3p12.js → command-rkrkq154.js} +9 -9
  224. package/dist/chunks/{managed-policy-b68cts8r.js → command-rscwbd1b.js} +18 -18
  225. package/dist/chunks/{managed-policy-kbbj3a53.js → command-rt384jmm.js} +19 -19
  226. package/dist/chunks/{managed-policy-nsyzjj6a.js → command-ry3ffff2.js} +10 -10
  227. package/dist/chunks/{managed-policy-dxzdnpxn.js → command-s1jqa0rv.js} +30 -30
  228. package/dist/chunks/{managed-policy-17gtpqw6.js → command-s3qw8jyq.js} +14 -14
  229. package/dist/chunks/{managed-policy-k35j7qts.js → command-s4tt0pef.js} +5 -5
  230. package/dist/chunks/{managed-policy-t093606p.js → command-s6grk335.js} +34 -34
  231. package/dist/chunks/{managed-policy-0gdmqesm.js → command-s8d7rejh.js} +4 -4
  232. package/dist/chunks/{managed-policy-mhq80y5h.js → command-s9de47m6.js} +12 -12
  233. package/dist/chunks/{managed-policy-n458ncje.js → command-s9spdbfy.js} +32 -32
  234. package/dist/chunks/{managed-policy-qygbw77c.js → command-scgrse2b.js} +5 -5
  235. package/dist/chunks/{managed-policy-g886xbse.js → command-sh0fsxwf.js} +11 -11
  236. package/dist/chunks/{managed-policy-zfq14k8e.js → command-srkatn7d.js} +24 -24
  237. package/dist/chunks/{managed-policy-tsty0ewe.js → command-swwzfrs7.js} +3 -3
  238. package/dist/chunks/{managed-policy-hn0gh7rr.js → command-t18afxp3.js} +12 -12
  239. package/dist/chunks/{managed-policy-0d31m9dq.js → command-t2pgk753.js} +6 -6
  240. package/dist/chunks/{managed-policy-tazgh4e4.js → command-tazgh4e4.js} +1 -1
  241. package/dist/chunks/{managed-policy-tcezcvh9.js → command-tcezcvh9.js} +1 -1
  242. package/dist/chunks/{managed-policy-tdstcens.js → command-tdstcens.js} +1 -1
  243. package/dist/chunks/{managed-policy-xg99tpzv.js → command-tet8e841.js} +4 -4
  244. package/dist/chunks/{managed-policy-1jndjv4e.js → command-tfrvwkgh.js} +10 -10
  245. package/dist/chunks/{managed-policy-0rv4tyzv.js → command-tgdgvz5m.js} +12 -12
  246. package/dist/chunks/{managed-policy-gwaz485a.js → command-tj3amwcq.js} +15 -15
  247. package/dist/chunks/{managed-policy-mrz2e164.js → command-tsjzc549.js} +24 -24
  248. package/dist/chunks/{managed-policy-k4sk2925.js → command-v04mbsyc.js} +7 -7
  249. package/dist/chunks/{managed-policy-veqvce7d.js → command-veqvce7d.js} +1 -1
  250. package/dist/chunks/{managed-policy-277eer69.js → command-vkfdnwpx.js} +4 -4
  251. package/dist/chunks/{managed-policy-1r9jwgz4.js → command-vmmvzryc.js} +11 -11
  252. package/dist/chunks/{managed-policy-w3nq1sqw.js → command-vps92m75.js} +9 -9
  253. package/dist/chunks/{managed-policy-1by2d8c2.js → command-vqjs8hv7.js} +27 -27
  254. package/dist/chunks/{managed-policy-my4zabxr.js → command-vx3jgdek.js} +3 -3
  255. package/dist/chunks/{managed-policy-vzcthcp8.js → command-vzcthcp8.js} +1 -1
  256. package/dist/chunks/{managed-policy-vzs5sf6e.js → command-vzs5sf6e.js} +1 -1
  257. package/dist/chunks/{managed-policy-w3wsvvr9.js → command-w3wsvvr9.js} +1 -1
  258. package/dist/chunks/{managed-policy-efwz9154.js → command-w7620n11.js} +24 -24
  259. package/dist/chunks/{managed-policy-3qgxwrwk.js → command-w9czef0s.js} +7 -7
  260. package/dist/chunks/{managed-policy-wd87259q.js → command-wd87259q.js} +1 -1
  261. package/dist/chunks/{managed-policy-dryr0n1e.js → command-wmh05qp9.js} +39 -39
  262. package/dist/chunks/{managed-policy-78q1j9vk.js → command-wq97ata3.js} +28 -28
  263. package/dist/chunks/{managed-policy-mzt1zc7x.js → command-xbvc458q.js} +8 -8
  264. package/dist/chunks/{managed-policy-g40r2f4p.js → command-xcng2btc.js} +5 -5
  265. package/dist/chunks/{managed-policy-v27atcgm.js → command-xeqfr83e.js} +23 -23
  266. package/dist/chunks/{managed-policy-xfkkasph.js → command-xfkkasph.js} +1 -1
  267. package/dist/chunks/{managed-policy-1jeevf2h.js → command-xhvk1hh0.js} +4 -4
  268. package/dist/chunks/{managed-policy-xkntkrq7.js → command-xkntkrq7.js} +2 -2
  269. package/dist/chunks/{managed-policy-y1fvbwt7.js → command-y1fvbwt7.js} +1 -1
  270. package/dist/chunks/{managed-policy-batcdr2g.js → command-y6k2xs97.js} +1 -1
  271. package/dist/chunks/{managed-policy-axxv0vp4.js → command-y6vx5mph.js} +43 -43
  272. package/dist/chunks/{managed-policy-z6c3x22d.js → command-ygdna4kr.js} +5 -5
  273. package/dist/chunks/{managed-policy-mqg8d1gn.js → command-yp6aabyp.js} +24 -24
  274. package/dist/chunks/{managed-policy-sw56qyd1.js → command-yr7n59b3.js} +11 -11
  275. package/dist/chunks/{managed-policy-d2gm2qbm.js → command-ys3m2q03.js} +47 -47
  276. package/dist/chunks/{managed-policy-rhgqra20.js → command-yvd9mjph.js} +28 -28
  277. package/dist/chunks/{managed-policy-z0bkrqjs.js → command-z0bkrqjs.js} +1 -1
  278. package/dist/chunks/{managed-policy-9ydax63h.js → command-zeh40njd.js} +181 -181
  279. package/dist/chunks/{managed-policy-wqxhcm17.js → command-zfs8ae4p.js} +4 -4
  280. package/dist/chunks/{managed-policy-zr2ceqn5.js → command-zr2ceqn5.js} +1 -1
  281. package/dist/chunks/{managed-policy-8zp79j7j.js → command-zsr4wwhv.js} +4 -4
  282. package/dist/chunks/{managed-policy-zxq2ej10.js → command-zxq2ej10.js} +1 -1
  283. package/dist/chunks/{managed-policy-1f2jh182.js → command-zytxgpcz.js} +22 -22
  284. package/dist/chunks/{managed-policy-rphtw9c5.js → command-zz9x0err.js} +28 -28
  285. package/dist/codemode/catalog.js +1 -1
  286. package/dist/codemode/instructions.js +5 -5
  287. package/dist/codemode/tool.js +3 -3
  288. package/dist/codemode/web.js +1 -1
  289. package/dist/command.js +85 -85
  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 +116 -116
  294. package/dist/config/plugin/command.js +205 -205
  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 +116 -116
  300. package/dist/config/plugin/instruction.js +90 -90
  301. package/dist/config/plugin/location-watcher.js +116 -116
  302. package/dist/config/plugin/mcp.js +123 -123
  303. package/dist/config/plugin/policy.js +117 -117
  304. package/dist/config/plugin/provider.js +116 -116
  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 +137 -137
  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 +121 -121
  317. package/dist/credential/sql.js +2 -2
  318. package/dist/credential.js +83 -83
  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 +93 -93
  401. package/dist/environment/exec-defaults.js +2 -2
  402. package/dist/environment/files.js +1 -1
  403. package/dist/environment/index.js +95 -95
  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 +3 -3
  421. package/dist/filesystem/watcher.js +15 -15
  422. package/dist/filesystem.js +104 -104
  423. package/dist/form.js +78 -78
  424. package/dist/formatter/builtins.js +4 -4
  425. package/dist/formatter.js +87 -87
  426. package/dist/generate.js +101 -101
  427. package/dist/git.js +10 -10
  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 +91 -91
  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 +85 -85
  452. package/dist/instructions/builtins.js +87 -87
  453. package/dist/instructions/index.js +3 -3
  454. package/dist/integration/connection.js +3 -3
  455. package/dist/integration.js +85 -85
  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 +109 -109
  467. package/dist/mcp/instructions.js +129 -129
  468. package/dist/mcp/oauth.js +78 -78
  469. package/dist/mcp/stdio.js +90 -90
  470. package/dist/mime.js +1 -1
  471. package/dist/modal/models.js +91 -91
  472. package/dist/model-resolver.js +98 -98
  473. package/dist/model.js +98 -98
  474. package/dist/models-dev.js +107 -107
  475. package/dist/oauth/page.js +1 -1
  476. package/dist/permission/saved.js +80 -80
  477. package/dist/permission/sql.js +5 -5
  478. package/dist/permission.js +115 -115
  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 +88 -88
  482. package/dist/persistent-pty/pty-binding.js +1 -1
  483. package/dist/persistent-pty.js +75 -75
  484. package/dist/plugin/agent.js +102 -102
  485. package/dist/plugin/command.js +100 -100
  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 +2 -2
  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/gateway.js +2 -2
  509. package/dist/plugin/provider/github-copilot.js +95 -95
  510. package/dist/plugin/provider/gitlab.js +93 -93
  511. package/dist/plugin/provider/google-vertex.js +90 -90
  512. package/dist/plugin/provider/kilo.js +1 -1
  513. package/dist/plugin/provider/llmgateway.js +78 -78
  514. package/dist/plugin/provider/lmstudio.js +115 -115
  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 +115 -115
  518. package/dist/plugin/provider/openai.js +93 -93
  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 +115 -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 +70 -70
  533. package/dist/plugin/service.js +3 -3
  534. package/dist/plugin/skill.js +132 -132
  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 +91 -91
  542. package/dist/plugin/warming.js +114 -114
  543. package/dist/plugin/websearch/exa.js +5 -5
  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 +2 -2
  547. package/dist/plugin/websearch/parallel.js +8 -8
  548. package/dist/plugin/websearch/tavily.js +6 -6
  549. package/dist/plugin/websearch/tinyfish.js +8 -8
  550. package/dist/plugin.js +218 -218
  551. package/dist/project/schema.js +8 -8
  552. package/dist/project/sql.js +4 -4
  553. package/dist/project.js +88 -88
  554. package/dist/provider.js +97 -97
  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 +89 -89
  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 +95 -95
  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 +133 -133
  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 +7 -7
  573. package/dist/session/event.js +1 -1
  574. package/dist/session/execution/restart.js +214 -214
  575. package/dist/session/execution.js +127 -127
  576. package/dist/session/generate.js +152 -152
  577. package/dist/session/history.js +15 -15
  578. package/dist/session/inbox.js +90 -90
  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 +120 -120
  586. package/dist/session/model-transport.js +9 -9
  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 +162 -162
  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 +201 -201
  610. package/dist/session/system-prompt.js +1 -1
  611. package/dist/session/title.js +157 -157
  612. package/dist/session/to-session-error.js +111 -111
  613. package/dist/session/transfer.js +210 -210
  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 +1238 -682
  619. package/dist/shell/select.js +15 -15
  620. package/dist/shell.js +132 -132
  621. package/dist/skill/discovery.js +6 -6
  622. package/dist/skill/instructions.js +105 -105
  623. package/dist/skill.js +112 -112
  624. package/dist/snapshot.js +93 -93
  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 +128 -128
  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 +120 -120
  636. package/dist/tool/plugin/question.js +103 -103
  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 +210 -210
  641. package/dist/tool/plugin/webfetch.js +110 -110
  642. package/dist/tool/plugin/websearch.js +114 -114
  643. package/dist/tool/plugin/write.js +120 -120
  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/shell/scan.d.ts +2 -1
  649. package/dist/util/error-summary.js +1 -1
  650. package/dist/util/error.js +1 -1
  651. package/dist/util/git-executable.js +2 -2
  652. package/dist/util/iife.js +1 -1
  653. package/dist/util/lazy.js +1 -1
  654. package/dist/util/slug.js +1 -1
  655. package/dist/util/token.js +1 -1
  656. package/dist/util/which.js +1 -1
  657. package/dist/util/wildcard.js +1 -1
  658. package/dist/v1/config/agent.js +7 -7
  659. package/dist/v1/config/command.js +5 -5
  660. package/dist/v1/config/error.js +4 -4
  661. package/dist/v1/config/mcp.js +4 -4
  662. package/dist/v1/config/migrate.js +92 -92
  663. package/dist/v1/config/permission.js +7 -7
  664. package/dist/v1/config/plugin.js +3 -3
  665. package/dist/v1/config/provider-options.js +1 -1
  666. package/dist/v1/config/provider.js +4 -4
  667. package/dist/variant.js +93 -93
  668. package/dist/vcs/patch.js +1 -1
  669. package/dist/vcs.js +89 -89
  670. package/dist/websearch.js +78 -78
  671. package/dist/wellknown/plugin.js +76 -76
  672. package/dist/wellknown.js +79 -79
  673. package/dist/workspace/driver.js +5 -5
  674. package/dist/workspace/sql.js +1 -1
  675. package/dist/workspace.js +80 -80
  676. package/dist/worktree/directory.js +2 -2
  677. package/dist/worktree/git.js +10 -10
  678. package/dist/worktree/sql.js +5 -5
  679. package/dist/worktree/strategies.js +89 -89
  680. package/dist/worktree.js +98 -98
  681. package/package.json +8 -8
  682. package/dist/chunks/managed-policy-hgd4btym.js +0 -18
  683. package/dist/chunks/managed-policy-n5ptys0j.js +0 -26
  684. package/dist/chunks/managed-policy-nwtmy77b.js +0 -507
  685. package/dist/chunks/managed-policy-zcnfg22j.js +0 -253
  686. /package/dist/chunks/{managed-policy-0qkdqm5v.js → command-0qkdqm5v.js} +0 -0
  687. /package/dist/chunks/{managed-policy-0zkw76rk.js → command-0zkw76rk.js} +0 -0
  688. /package/dist/chunks/{managed-policy-17cy0kzp.js → command-17cy0kzp.js} +0 -0
  689. /package/dist/chunks/{managed-policy-1cnp2v09.js → command-1cnp2v09.js} +0 -0
  690. /package/dist/chunks/{managed-policy-1kg9ymc8.js → command-1kg9ymc8.js} +0 -0
  691. /package/dist/chunks/{managed-policy-24dcb14g.js → command-24dcb14g.js} +0 -0
  692. /package/dist/chunks/{managed-policy-2710q6r3.js → command-2710q6r3.js} +0 -0
  693. /package/dist/chunks/{managed-policy-2axfhc9x.js → command-2axfhc9x.js} +0 -0
  694. /package/dist/chunks/{managed-policy-2c3vjs8z.js → command-2c3vjs8z.js} +0 -0
  695. /package/dist/chunks/{managed-policy-34c7v6d4.js → command-34c7v6d4.js} +0 -0
  696. /package/dist/chunks/{managed-policy-359p4xyc.js → command-359p4xyc.js} +0 -0
  697. /package/dist/chunks/{managed-policy-3asan66x.js → command-3asan66x.js} +0 -0
  698. /package/dist/chunks/{managed-policy-3t0ybcrp.js → command-3t0ybcrp.js} +0 -0
  699. /package/dist/chunks/{managed-policy-3v8g72cx.js → command-3v8g72cx.js} +0 -0
  700. /package/dist/chunks/{managed-policy-3w5fmr99.js → command-3w5fmr99.js} +0 -0
  701. /package/dist/chunks/{managed-policy-3wcehsnq.js → command-3wcehsnq.js} +0 -0
  702. /package/dist/chunks/{managed-policy-43n2bw4t.js → command-43n2bw4t.js} +0 -0
  703. /package/dist/chunks/{managed-policy-4knz6hnm.js → command-4knz6hnm.js} +0 -0
  704. /package/dist/chunks/{managed-policy-4vcrnpx2.js → command-4vcrnpx2.js} +0 -0
  705. /package/dist/chunks/{managed-policy-4y7fprxs.js → command-4y7fprxs.js} +0 -0
  706. /package/dist/chunks/{managed-policy-53557ph1.js → command-53557ph1.js} +0 -0
  707. /package/dist/chunks/{managed-policy-550bvhaj.js → command-550bvhaj.js} +0 -0
  708. /package/dist/chunks/{managed-policy-6prwharc.js → command-6prwharc.js} +0 -0
  709. /package/dist/chunks/{managed-policy-7akdwqpd.js → command-7akdwqpd.js} +0 -0
  710. /package/dist/chunks/{managed-policy-7m9af43g.js → command-7m9af43g.js} +0 -0
  711. /package/dist/chunks/{managed-policy-822emrt2.js → command-822emrt2.js} +0 -0
  712. /package/dist/chunks/{managed-policy-88xbtdfr.js → command-88xbtdfr.js} +0 -0
  713. /package/dist/chunks/{managed-policy-8n3pysct.js → command-8n3pysct.js} +0 -0
  714. /package/dist/chunks/{managed-policy-8wj87zfr.js → command-8wj87zfr.js} +0 -0
  715. /package/dist/chunks/{managed-policy-9a4afbnw.js → command-9a4afbnw.js} +0 -0
  716. /package/dist/chunks/{managed-policy-9rqn6x4v.js → command-9rqn6x4v.js} +0 -0
  717. /package/dist/chunks/{managed-policy-a6k6eb26.js → command-a6k6eb26.js} +0 -0
  718. /package/dist/chunks/{managed-policy-af5trqkr.js → command-af5trqkr.js} +0 -0
  719. /package/dist/chunks/{managed-policy-afrmfg78.js → command-afrmfg78.js} +0 -0
  720. /package/dist/chunks/{managed-policy-aqzs7mqg.js → command-aqzs7mqg.js} +0 -0
  721. /package/dist/chunks/{managed-policy-atq7p7m5.js → command-atq7p7m5.js} +0 -0
  722. /package/dist/chunks/{managed-policy-bkyjaxrp.js → command-bkyjaxrp.js} +0 -0
  723. /package/dist/chunks/{managed-policy-bmr6ed5q.js → command-bmr6ed5q.js} +0 -0
  724. /package/dist/chunks/{managed-policy-cf4snx6d.js → command-cf4snx6d.js} +0 -0
  725. /package/dist/chunks/{managed-policy-cvy3z8tj.js → command-cvy3z8tj.js} +0 -0
  726. /package/dist/chunks/{managed-policy-d9fn303g.js → command-d9fn303g.js} +0 -0
  727. /package/dist/chunks/{managed-policy-d9jj8t3e.js → command-d9jj8t3e.js} +0 -0
  728. /package/dist/chunks/{managed-policy-dajrwvna.js → command-dajrwvna.js} +0 -0
  729. /package/dist/chunks/{managed-policy-dap0rakb.js → command-dap0rakb.js} +0 -0
  730. /package/dist/chunks/{managed-policy-df08tz66.js → command-df08tz66.js} +0 -0
  731. /package/dist/chunks/{managed-policy-dy18nga0.js → command-dy18nga0.js} +0 -0
  732. /package/dist/chunks/{managed-policy-e5kj55wp.js → command-e5kj55wp.js} +0 -0
  733. /package/dist/chunks/{managed-policy-e73j6tqm.js → command-e73j6tqm.js} +0 -0
  734. /package/dist/chunks/{managed-policy-ec1grn59.js → command-ec1grn59.js} +0 -0
  735. /package/dist/chunks/{managed-policy-eh3zwz77.js → command-eh3zwz77.js} +0 -0
  736. /package/dist/chunks/{managed-policy-emrn6kk6.js → command-emrn6kk6.js} +0 -0
  737. /package/dist/chunks/{managed-policy-f0mxakyp.js → command-f0mxakyp.js} +0 -0
  738. /package/dist/chunks/{managed-policy-f6n9ztr4.js → command-f6n9ztr4.js} +0 -0
  739. /package/dist/chunks/{managed-policy-faypxj3z.js → command-faypxj3z.js} +0 -0
  740. /package/dist/chunks/{managed-policy-fd410y7t.js → command-fd410y7t.js} +0 -0
  741. /package/dist/chunks/{managed-policy-fxgpk5d8.js → command-fxgpk5d8.js} +0 -0
  742. /package/dist/chunks/{managed-policy-g4wezp1m.js → command-g4wezp1m.js} +0 -0
  743. /package/dist/chunks/{managed-policy-g86h250q.js → command-g86h250q.js} +0 -0
  744. /package/dist/chunks/{managed-policy-gebd4c9n.js → command-gebd4c9n.js} +0 -0
  745. /package/dist/chunks/{managed-policy-gftt206x.js → command-gftt206x.js} +0 -0
  746. /package/dist/chunks/{managed-policy-hjbc5kem.js → command-hjbc5kem.js} +0 -0
  747. /package/dist/chunks/{managed-policy-hk9envan.js → command-hk9envan.js} +0 -0
  748. /package/dist/chunks/{managed-policy-j2ntwpah.js → command-j2ntwpah.js} +0 -0
  749. /package/dist/chunks/{managed-policy-j5zkgpj8.js → command-j5zkgpj8.js} +0 -0
  750. /package/dist/chunks/{managed-policy-jjkms2e6.js → command-jjkms2e6.js} +0 -0
  751. /package/dist/chunks/{managed-policy-jr7sbwjy.js → command-jr7sbwjy.js} +0 -0
  752. /package/dist/chunks/{managed-policy-jwfs4k6c.js → command-jwfs4k6c.js} +0 -0
  753. /package/dist/chunks/{managed-policy-jzg6c2d5.js → command-jzg6c2d5.js} +0 -0
  754. /package/dist/chunks/{managed-policy-mp448xyj.js → command-mp448xyj.js} +0 -0
  755. /package/dist/chunks/{managed-policy-msx8hqn2.js → command-msx8hqn2.js} +0 -0
  756. /package/dist/chunks/{managed-policy-n05xt0ee.js → command-n05xt0ee.js} +0 -0
  757. /package/dist/chunks/{managed-policy-n3j8tn72.js → command-n3j8tn72.js} +0 -0
  758. /package/dist/chunks/{managed-policy-njntx4h6.js → command-njntx4h6.js} +0 -0
  759. /package/dist/chunks/{managed-policy-q3sfg36h.js → command-q3sfg36h.js} +0 -0
  760. /package/dist/chunks/{managed-policy-q74kybfr.js → command-q74kybfr.js} +0 -0
  761. /package/dist/chunks/{managed-policy-qaymkmh1.js → command-qaymkmh1.js} +0 -0
  762. /package/dist/chunks/{managed-policy-qb87gjwd.js → command-qb87gjwd.js} +0 -0
  763. /package/dist/chunks/{managed-policy-qfa1cgps.js → command-qfa1cgps.js} +0 -0
  764. /package/dist/chunks/{managed-policy-qg3g05ea.js → command-qg3g05ea.js} +0 -0
  765. /package/dist/chunks/{managed-policy-qrg20bc0.js → command-qrg20bc0.js} +0 -0
  766. /package/dist/chunks/{managed-policy-rcb2kzg1.js → command-rcb2kzg1.js} +0 -0
  767. /package/dist/chunks/{managed-policy-sdp7kfr6.js → command-sdp7kfr6.js} +0 -0
  768. /package/dist/chunks/{managed-policy-ssg3fenm.js → command-ssg3fenm.js} +0 -0
  769. /package/dist/chunks/{managed-policy-w803qqfp.js → command-w803qqfp.js} +0 -0
  770. /package/dist/chunks/{managed-policy-wc3fc9cn.js → command-wc3fc9cn.js} +0 -0
  771. /package/dist/chunks/{managed-policy-wer8tq1h.js → command-wer8tq1h.js} +0 -0
  772. /package/dist/chunks/{managed-policy-wtztk69x.js → command-wtztk69x.js} +0 -0
  773. /package/dist/chunks/{managed-policy-x0ckcb58.js → command-x0ckcb58.js} +0 -0
  774. /package/dist/chunks/{managed-policy-x61499pn.js → command-x61499pn.js} +0 -0
  775. /package/dist/chunks/{managed-policy-y44na4kk.js → command-y44na4kk.js} +0 -0
  776. /package/dist/chunks/{managed-policy-y8cydn3q.js → command-y8cydn3q.js} +0 -0
  777. /package/dist/chunks/{managed-policy-y8f7s663.js → command-y8f7s663.js} +0 -0
  778. /package/dist/chunks/{managed-policy-ygaqb7jw.js → command-ygaqb7jw.js} +0 -0
  779. /package/dist/chunks/{managed-policy-ym463w8f.js → command-ym463w8f.js} +0 -0
  780. /package/dist/chunks/{managed-policy-z5v4ffb3.js → command-z5v4ffb3.js} +0 -0
  781. /package/dist/chunks/{managed-policy-z9919s4g.js → command-z9919s4g.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "../chunks/managed-policy-9rqn6x4v.js";
3
+ } from "../chunks/command-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 };
18
115
  }
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)
116
+ function bashStatement(state) {
117
+ const structure = state.structures.at(-1);
118
+ if (structure)
119
+ structure.count++;
120
+ }
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;
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;
164
352
  continue;
165
353
  }
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;
254
- continue;
255
- }
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 = state.assignmentWord && /[^=]=$/.test(state.word) && (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;
520
795
  }
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];
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;
523
803
  }
524
- function bashDelimited(input, start, depth) {
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;
925
+ }
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;
999
+ }
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;
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;
1065
+ }
1066
+ const next = input[index + 1] ?? "\x00";
1067
+ if (input[index] === "\\" && ("$`\\\n".includes(next) || quoted && next === '"')) {
539
1068
  index++;
1069
+ if (next !== `
1070
+ `)
1071
+ source += next;
540
1072
  continue;
541
1073
  }
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;
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;
1099
+ }
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;
550
1108
  }
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;
555
- continue;
556
1109
  }
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;
1110
+ if (char === "@") {
1111
+ PARAMETER_PROMPT_RE.lastIndex = index;
1112
+ if (PARAMETER_PROMPT_RE.test(input))
1113
+ return { kind: "opaque", reason: "dynamic-execution" };
1114
+ }
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++;
561
1161
  continue;
562
1162
  }
563
- if (char === "#" && boundary) {
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;
1177
+ }
1178
+ }
1179
+ if (!wordStarted && char === "#") {
564
1180
  const newline = input.indexOf(`
565
1181
  `, index);
566
1182
  if (newline < 0)
567
- return;
568
- index = newline - 1;
569
- continue;
570
- }
571
- if (input.startsWith("<<<", index)) {
572
- index += 2;
1183
+ return { kind: "opaque", reason: "invalid-structure" };
1184
+ index = newline;
573
1185
  continue;
574
1186
  }
575
- if (input.startsWith("<<", index)) {
576
- const delimiter = bashHeredocDelimiter(input, index);
577
- if (!delimiter)
578
- return;
579
- heredocs.push(delimiter);
580
- index = delimiter.end;
1187
+ if (char === " " || char === "\t" || char === `
1188
+ `) {
1189
+ if (!patternParenDepth)
1190
+ wordStarted = false;
581
1191
  continue;
582
1192
  }
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;
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;
590
1206
  }
591
- commandStart = true;
1207
+ flushWord();
1208
+ words.push({ word: char, literal: "", output: "" });
1209
+ wordStarted = false;
592
1210
  continue;
593
1211
  }
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;
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;
613
1221
  continue;
614
1222
  }
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;
621
- continue;
622
- }
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;
629
- continue;
630
- }
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;
1223
+ wordStarted = true;
1224
+ hasWord = true;
1225
+ if (unit === undefined)
1226
+ bashAppend(text, char);
637
1227
  }
1228
+ return { kind: "opaque", reason: "invalid-structure" };
638
1229
  }
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++) {
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" };
671
1238
  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++;
1239
+ if (char === "\\" && input[index + 1] === `
1240
+ `) {
1241
+ index++;
677
1242
  continue;
678
1243
  }
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;
684
- continue;
1244
+ if (text && (char === ")" || char === " " || char === "\t" || char === `
1245
+ `)) {
1246
+ bashEvaluatesExpansion(text, "deferred", context);
1247
+ text.literal = "";
1248
+ text.output = "";
685
1249
  }
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;
692
- continue;
693
- }
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;
701
- }
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,31 +1366,47 @@ 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
  }