@oxide/skepsis 0.8.0 → 0.10.0

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 (214) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +19 -0
  3. package/dist/cli.js +343 -172
  4. package/dist/web/assets/{angular-html-COh-KPpr.js → angular-html-5MzbtJIG.js} +1 -1
  5. package/dist/web/assets/angular-html-DSsqKJnE.js +1 -0
  6. package/dist/web/assets/{angular-ts-Bs3k8Lx3.js → angular-ts-BUZc-QMo.js} +1 -1
  7. package/dist/web/assets/{angular-ts-5Qr-6WKq.js → angular-ts-DjuPMmKe.js} +1 -1
  8. package/dist/web/assets/{apl-C3IBd5Ec.js → apl-7OkT0_3X.js} +1 -1
  9. package/dist/web/assets/{apl-Cam3gGMJ.js → apl-Dy3ijG3Z.js} +1 -1
  10. package/dist/web/assets/{appendItems-BDl89Ia1.js → appendItems-BZdu8tZw.js} +2 -2
  11. package/dist/web/assets/{astro-DHwQCx_S.js → astro-D4DWP-oB.js} +1 -1
  12. package/dist/web/assets/{astro-CB4EBpEZ.js → astro-jTEWNzdc.js} +1 -1
  13. package/dist/web/assets/{blade-CsYhucH4.js → blade-BQDm3JnY.js} +1 -1
  14. package/dist/web/assets/{blade-7Gr43jAz.js → blade-CLHf_0CD.js} +1 -1
  15. package/dist/web/assets/{c-CkABhGr_.js → c-DPYCDro8.js} +1 -1
  16. package/dist/web/assets/c-NZxYjD9R.js +1 -0
  17. package/dist/web/assets/{chapel-Dwj8O2q6.js → chapel-B1lx1D1q.js} +1 -1
  18. package/dist/web/assets/{chapel-gVV5MuZI.js → chapel-C_yIxKK6.js} +1 -1
  19. package/dist/web/assets/{cobol-GP8_rz83.js → cobol-1bSCo05L.js} +1 -1
  20. package/dist/web/assets/{cobol-CVXz0kDC.js → cobol-B_BGY4um.js} +1 -1
  21. package/dist/web/assets/{coffee-WP4QzeAH.js → coffee-DCXaW2x4.js} +1 -1
  22. package/dist/web/assets/{coffee-DS21iOTn.js → coffee-DaqRbLNJ.js} +1 -1
  23. package/dist/web/assets/{core-DknSirba.js → core-CRVWVlRh.js} +1 -1
  24. package/dist/web/assets/{core-B7Q2IdxQ.js → core-R2hgk4px.js} +1 -1
  25. package/dist/web/assets/{cpp-rVDWY1B4.js → cpp-BenE1WSd.js} +1 -1
  26. package/dist/web/assets/cpp-Y8tBED_W.js +1 -0
  27. package/dist/web/assets/{crystal-B73bNONC.js → crystal-CL-nV_wK.js} +1 -1
  28. package/dist/web/assets/{crystal-CJgdSGk6.js → crystal-DySjQVz6.js} +1 -1
  29. package/dist/web/assets/{css-BRWMIktL.js → css-CCGU7JQN.js} +1 -1
  30. package/dist/web/assets/css-DSv6eINm.js +1 -0
  31. package/dist/web/assets/{edge-CRP7Pjnm.js → edge-Ptsnv57g.js} +1 -1
  32. package/dist/web/assets/{edge-CO1vXbsX.js → edge-klD0zTmA.js} +1 -1
  33. package/dist/web/assets/{elixir-5PogCxpo.js → elixir-B-ndCQO5.js} +1 -1
  34. package/dist/web/assets/{elixir-DDt1vet7.js → elixir-DshgV81z.js} +1 -1
  35. package/dist/web/assets/{elm-4zjcvGmW.js → elm-D2n9196z.js} +1 -1
  36. package/dist/web/assets/{elm-Bpk1i0aW.js → elm-x2IF6yQx.js} +1 -1
  37. package/dist/web/assets/{erb-BTpr085n.js → erb-C0ZpwTHn.js} +1 -1
  38. package/dist/web/assets/{erb-DYx04lM6.js → erb-D3looOT0.js} +1 -1
  39. package/dist/web/assets/{git-rebase-eULKDkUM.js → git-rebase-F5tLQboz.js} +1 -1
  40. package/dist/web/assets/{git-rebase-DAwuX6ns.js → git-rebase-WKrMcflD.js} +1 -1
  41. package/dist/web/assets/{glimmer-js-Bd6hYqnW.js → glimmer-js-BLIJc5Je.js} +1 -1
  42. package/dist/web/assets/{glimmer-js-kUebRGTr.js → glimmer-js-BU40Zlfs.js} +1 -1
  43. package/dist/web/assets/{glimmer-ts-URXNoheO.js → glimmer-ts-CbYtb0cA.js} +1 -1
  44. package/dist/web/assets/{glimmer-ts-_NOcSQHg.js → glimmer-ts-CszlCsRI.js} +1 -1
  45. package/dist/web/assets/{glsl-_TNA_iPI.js → glsl-C7aPe9Y0.js} +1 -1
  46. package/dist/web/assets/glsl-DBf8kQxW.js +1 -0
  47. package/dist/web/assets/{graphql-BcoDnwxt.js → graphql-BPV6O51F.js} +1 -1
  48. package/dist/web/assets/graphql-DTnqPoeZ.js +1 -0
  49. package/dist/web/assets/{hack-6dbksEaW.js → hack-B5UVchbm.js} +1 -1
  50. package/dist/web/assets/{hack-KnsIb8er.js → hack-Ce8F0CRx.js} +1 -1
  51. package/dist/web/assets/haml-BWO1n66w.js +1 -0
  52. package/dist/web/assets/{haml-C9u41EHO.js → haml-Dg7mgbjq.js} +1 -1
  53. package/dist/web/assets/{handlebars-BqTIBvWu.js → handlebars-_diw2t9J.js} +1 -1
  54. package/dist/web/assets/{handlebars-C5nSeJyv.js → handlebars-vqgG93Z8.js} +1 -1
  55. package/dist/web/assets/highlights-CpZm9DAR-B656DLug.js +3 -0
  56. package/dist/web/assets/highlights-CvrDXW6q.js +3 -0
  57. package/dist/web/assets/{html-8-42-UO1.js → html-BVL4G_If.js} +1 -1
  58. package/dist/web/assets/html-D79_dBdy.js +1 -0
  59. package/dist/web/assets/{html-derivative-DrvI0STr.js → html-derivative-DhiGeiCI.js} +1 -1
  60. package/dist/web/assets/{html-derivative-B7x_cJcn.js → html-derivative-vX6yKx4E.js} +1 -1
  61. package/dist/web/assets/{http-D-cSncI7.js → http-BqrodHMJ.js} +1 -1
  62. package/dist/web/assets/{http-Vh3wh7WS.js → http-ynmm9XFY.js} +1 -1
  63. package/dist/web/assets/hurl-BNDj6hBh.js +1 -0
  64. package/dist/web/assets/hurl-jiJ4Cyz5.js +1 -0
  65. package/dist/web/assets/{index-w_HTIb39.js → index-BgHojdcr.js} +18 -11
  66. package/dist/web/assets/{index-Ds8xdel2.css → index-BoRhJKSU.css} +1 -1
  67. package/dist/web/assets/{java-DG6fEa85.js → java-B3pBe3t3.js} +1 -1
  68. package/dist/web/assets/java-DmZF03nx.js +1 -0
  69. package/dist/web/assets/javascript-DF6j-435.js +1 -0
  70. package/dist/web/assets/{javascript-CZJj_7h7.js → javascript-xZXkzgNu.js} +1 -1
  71. package/dist/web/assets/{jinja-BoDLIHig.js → jinja-BHauAflC.js} +1 -1
  72. package/dist/web/assets/{jinja-Dl8NsVnE.js → jinja-nrK8_DQP.js} +1 -1
  73. package/dist/web/assets/{jison-79ResrTb.js → jison-CZsiyrSO.js} +1 -1
  74. package/dist/web/assets/{jison-BDfR587C.js → jison-l3loiiW8.js} +1 -1
  75. package/dist/web/assets/json-42mipy3Q.js +1 -0
  76. package/dist/web/assets/{json-Bi5hPIRb.js → json-Ce4-oRop.js} +1 -1
  77. package/dist/web/assets/{jsx-CL3_uAqH.js → jsx-BV-prmL-.js} +1 -1
  78. package/dist/web/assets/jsx-vimVRUsC.js +1 -0
  79. package/dist/web/assets/julia-DXGUWCmN.js +1 -0
  80. package/dist/web/assets/julia-MekFIo3G.js +1 -0
  81. package/dist/web/assets/{just-DkmBkWVk.js → just-DTbwj7KW.js} +1 -1
  82. package/dist/web/assets/{just-BuTSF8Ij.js → just-DsJi-m0I.js} +1 -1
  83. package/dist/web/assets/{langs-BG3qRjWN.js → langs-AipD3sBt.js} +1 -1
  84. package/dist/web/assets/{langs-BzPOrwLe.js → langs-BEm5AYVx.js} +2 -2
  85. package/dist/web/assets/{latex-BE8KnReL.js → latex-ClPNQOTt.js} +1 -1
  86. package/dist/web/assets/{latex-43AwF19G.js → latex-H4OTh4b8.js} +1 -1
  87. package/dist/web/assets/lib-6HYXi0_j.js +9 -0
  88. package/dist/web/assets/{liquid-CEs4fy4H.js → liquid-ATVC5stg.js} +1 -1
  89. package/dist/web/assets/{liquid-Df-B1-mv.js → liquid-CMYe73f3.js} +1 -1
  90. package/dist/web/assets/{loader-Dbltcnnq.js → loader-mmgKmkUH.js} +1 -1
  91. package/dist/web/assets/{lua-DDcZHfDR.js → lua-CiynuoyW.js} +1 -1
  92. package/dist/web/assets/lua-CxMwO_Mz.js +1 -0
  93. package/dist/web/assets/marko-4AR0TJLV.js +1 -0
  94. package/dist/web/assets/marko-BQXHQuP5.js +1 -0
  95. package/dist/web/assets/{mdc-B5DMKffA.js → mdc-C-oN4fAN.js} +1 -1
  96. package/dist/web/assets/{mdc-9JXHdPDD.js → mdc-DqTUtnLz.js} +1 -1
  97. package/dist/web/assets/{nginx-kt4v8xQN.js → nginx-BUkWEK1v.js} +1 -1
  98. package/dist/web/assets/{nginx-COrZQv6r.js → nginx-BiHSRcGz.js} +1 -1
  99. package/dist/web/assets/{nim-DqJnPM0H.js → nim-BrNFeMUq.js} +1 -1
  100. package/dist/web/assets/{nim-aq2q6ZbC.js → nim-CM_g0s8g.js} +1 -1
  101. package/dist/web/assets/{org-CR4Z2IuN.js → org-D29ZI6ja.js} +1 -1
  102. package/dist/web/assets/{org-BJB0m7Ur.js → org-i4uigk09.js} +1 -1
  103. package/dist/web/assets/{perl-DTj1siyS.js → perl-CwypTNVd.js} +1 -1
  104. package/dist/web/assets/{perl-DBpyycoj.js → perl-LZlJPipU.js} +1 -1
  105. package/dist/web/assets/{php-b2GZj8e2.js → php-BPEOleJP.js} +1 -1
  106. package/dist/web/assets/{php-DAWfLnBS.js → php-C3bghuse.js} +1 -1
  107. package/dist/web/assets/{preload-helper-BLdHbfdN.js → preload-helper-7y9sWmk5.js} +1 -1
  108. package/dist/web/assets/{pug-BUREn_XQ.js → pug-9kU_hbhF.js} +1 -1
  109. package/dist/web/assets/{pug-BbFUUH4z.js → pug-DePZMqG6.js} +1 -1
  110. package/dist/web/assets/{qml-BpPAa8e_.js → qml-BQ_VstfA.js} +1 -1
  111. package/dist/web/assets/{qml-B2VMv5Ik.js → qml-DgcKxrNn.js} +1 -1
  112. package/dist/web/assets/r-C0eHyz6n.js +1 -0
  113. package/dist/web/assets/{r-DVQval5L.js → r-D29zO6IP.js} +1 -1
  114. package/dist/web/assets/{razor-PQAc47IJ.js → razor-BvyoAyYp.js} +1 -1
  115. package/dist/web/assets/{razor-Bsu5czGw.js → razor-Dv7qBGH7.js} +1 -1
  116. package/dist/web/assets/regexp-CCN76yWg.js +1 -0
  117. package/dist/web/assets/{regexp-B1nQ4d6K.js → regexp-CCRxPdFq.js} +1 -1
  118. package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  119. package/dist/web/assets/rst-_BKuzc31.js +1 -0
  120. package/dist/web/assets/rst-exK5jWka.js +1 -0
  121. package/dist/web/assets/{ruby-CRNUjKY4.js → ruby-CIC5g-Fx.js} +1 -1
  122. package/dist/web/assets/{ruby-Bk02onyY.js → ruby-Cr9v_Obl.js} +1 -1
  123. package/dist/web/assets/{sas-DPps5dcl.js → sas-Dd5vYuby.js} +1 -1
  124. package/dist/web/assets/{sas-BWv-mXim.js → sas-DdICJ59Y.js} +1 -1
  125. package/dist/web/assets/{scss-B8kCig9_.js → scss-7X82IZHP.js} +1 -1
  126. package/dist/web/assets/scss-BkHGVRy5.js +1 -0
  127. package/dist/web/assets/{shellscript-CZyEWgnz.js → shellscript-CtYpgNtQ.js} +1 -1
  128. package/dist/web/assets/shellscript-DG0er0mb.js +1 -0
  129. package/dist/web/assets/{shellsession-D_ni3iv7.js → shellsession-C-bwFs2c.js} +1 -1
  130. package/dist/web/assets/{shellsession-tWlSCRM2.js → shellsession-DZdJuHd_.js} +1 -1
  131. package/dist/web/assets/shiki-Ci4cdHsM-DofO8uLv.js +1 -0
  132. package/dist/web/assets/shiki-DWIk2nNk.js +1 -0
  133. package/dist/web/assets/{soy-B74jDL0m.js → soy-DZwks24U.js} +1 -1
  134. package/dist/web/assets/{soy-D3hKJHak.js → soy-Zo1x9xrc.js} +1 -1
  135. package/dist/web/assets/{sql-Dy8GON95.js → sql-B3_1KnPR.js} +1 -1
  136. package/dist/web/assets/sql-BsVsuJ1z.js +1 -0
  137. package/dist/web/assets/{stata-CPMn7118.js → stata-Dc59EJVv.js} +1 -1
  138. package/dist/web/assets/{stata-Fy4mjA9x.js → stata-Y9QSLa7w.js} +1 -1
  139. package/dist/web/assets/{stream-tokenizer-Baxxf9P5.js → stream-tokenizer-BGZQmGYG.js} +1 -1
  140. package/dist/web/assets/{stream-tokenizer-DK9xp5M5-B9Yp7Cx4.js → stream-tokenizer-DK9xp5M5-BRcfCBU9.js} +2 -2
  141. package/dist/web/assets/{surrealql-cEXWOziL.js → surrealql-BZ8wMp-0.js} +1 -1
  142. package/dist/web/assets/{surrealql-D_7o_iay.js → surrealql-h0PQCFLw.js} +1 -1
  143. package/dist/web/assets/{svelte-BCjhcijb.js → svelte-CEfeKWRu.js} +1 -1
  144. package/dist/web/assets/{svelte-BayBCB9R.js → svelte-bN9iV2sq.js} +1 -1
  145. package/dist/web/assets/{templ-ZeRLU1VO.js → templ-DGapOspH.js} +1 -1
  146. package/dist/web/assets/{templ-BpmciQhe.js → templ-ufYP5kCi.js} +1 -1
  147. package/dist/web/assets/tex-Bmmg45Le.js +1 -0
  148. package/dist/web/assets/{tex-CQrSZYyI.js → tex-CLnvG3aM.js} +1 -1
  149. package/dist/web/assets/themes-BSeJ3lIS.js +2 -0
  150. package/dist/web/assets/{themes-DWlo6UXs.js → themes-CLt8sw9m.js} +1 -1
  151. package/dist/web/assets/{ts-tags-RefINoqB.js → ts-tags-B7Ks-5qe.js} +1 -1
  152. package/dist/web/assets/{ts-tags-dbn1zgzd.js → ts-tags-CwIy--wZ.js} +1 -1
  153. package/dist/web/assets/{tsx-CNQsUXBX.js → tsx-Dr-F9mBX.js} +1 -1
  154. package/dist/web/assets/tsx-r6-X8vM1.js +1 -0
  155. package/dist/web/assets/{twig-DPNRm8S5.js → twig-BG5fbyXh.js} +1 -1
  156. package/dist/web/assets/{twig-CQ7MNML9.js → twig-Pt_twgz0.js} +1 -1
  157. package/dist/web/assets/{typescript-D9toDPHP.js → typescript-D7Ndy8oU.js} +1 -1
  158. package/dist/web/assets/typescript-Dvuj33DD.js +1 -0
  159. package/dist/web/assets/typst-CPcUz0OK.js +1 -0
  160. package/dist/web/assets/typst-DN6uQrAt.js +1 -0
  161. package/dist/web/assets/{vue-CHyKH4ea.js → vue-B8KSVBoP.js} +1 -1
  162. package/dist/web/assets/{vue-QRCjPxoW.js → vue-CdNXO_c4.js} +1 -1
  163. package/dist/web/assets/{vue-html-B4WW7nL4.js → vue-html-BBM4UO8W.js} +1 -1
  164. package/dist/web/assets/{vue-html-DILG-Ac1.js → vue-html-_883cUM-.js} +1 -1
  165. package/dist/web/assets/{vue-vine-gnSqwsqh.js → vue-vine-D8Bsu-p9.js} +1 -1
  166. package/dist/web/assets/{vue-vine-DdbvyGyD.js → vue-vine-fPGNMMyu.js} +1 -1
  167. package/dist/web/assets/{worker-wj5ld8rp.js → worker-5RC4eUGv.js} +1 -1
  168. package/dist/web/assets/{xml-M2cAPWa7.js → xml-BQrQN_aN.js} +1 -1
  169. package/dist/web/assets/xml-CJx_hAt3.js +1 -0
  170. package/dist/web/assets/{xsl-B9_l5w_y.js → xsl-Bd7alYZi.js} +1 -1
  171. package/dist/web/assets/{xsl-xj3duciK.js → xsl-nrcFEV7P.js} +1 -1
  172. package/dist/web/assets/yaml-BY1dOrT3.js +1 -0
  173. package/dist/web/assets/{yaml-Bbif-_Mh.js → yaml-ejl6cTPF.js} +1 -1
  174. package/dist/web/index.html +6 -5
  175. package/package.json +2 -1
  176. package/dist/web/assets/angular-html-5GmA-hSw.js +0 -1
  177. package/dist/web/assets/c-CLwiXg5O.js +0 -1
  178. package/dist/web/assets/cpp-Byv33xdN.js +0 -1
  179. package/dist/web/assets/css-Bs6D4HF4.js +0 -1
  180. package/dist/web/assets/glsl-BcRvLkeT.js +0 -1
  181. package/dist/web/assets/graphql-B6jCVif-.js +0 -1
  182. package/dist/web/assets/haml-BxhOlGS6.js +0 -1
  183. package/dist/web/assets/highlights-CpZm9DAR-CXj5Yczo.js +0 -3
  184. package/dist/web/assets/highlights-xCDO0bP7.js +0 -3
  185. package/dist/web/assets/html-LUUSgi3q.js +0 -1
  186. package/dist/web/assets/hurl-9CBBhkNv.js +0 -1
  187. package/dist/web/assets/hurl-C6YQR2YO.js +0 -1
  188. package/dist/web/assets/java-B7vhloBe.js +0 -1
  189. package/dist/web/assets/javascript-DOhcNjS7.js +0 -1
  190. package/dist/web/assets/json-B0_M4KlT.js +0 -1
  191. package/dist/web/assets/jsx-CT1bysQ8.js +0 -1
  192. package/dist/web/assets/julia-CblJgi4T.js +0 -1
  193. package/dist/web/assets/julia-D1-pyI7C.js +0 -1
  194. package/dist/web/assets/lib-K5iW4li2.js +0 -9
  195. package/dist/web/assets/lua-C6rFsMIk.js +0 -1
  196. package/dist/web/assets/marko-BzTRPaaJ.js +0 -1
  197. package/dist/web/assets/marko-BzjzFSPL.js +0 -1
  198. package/dist/web/assets/r-R4JF1X__.js +0 -1
  199. package/dist/web/assets/regexp-0DWh2Y48.js +0 -1
  200. package/dist/web/assets/rst-DXQ1xgo1.js +0 -1
  201. package/dist/web/assets/rst-DiPipfrX.js +0 -1
  202. package/dist/web/assets/scss-DG7aZuBL.js +0 -1
  203. package/dist/web/assets/shellscript-CkprpoE1.js +0 -1
  204. package/dist/web/assets/shiki-Ci4cdHsM-D4nI5uwI.js +0 -1
  205. package/dist/web/assets/shiki-CoZZwYQ-.js +0 -1
  206. package/dist/web/assets/sql-BiiM1y38.js +0 -1
  207. package/dist/web/assets/tex-Dev9lWw2.js +0 -1
  208. package/dist/web/assets/themes-CNupbtPL.js +0 -2
  209. package/dist/web/assets/tsx-tchOdLd3.js +0 -1
  210. package/dist/web/assets/typescript-GAgH1cvu.js +0 -1
  211. package/dist/web/assets/typst-1RSlaUvv.js +0 -1
  212. package/dist/web/assets/typst-jMKJwoxw.js +0 -1
  213. package/dist/web/assets/xml-BZ2PL6B3.js +0 -1
  214. package/dist/web/assets/yaml-T4JQ2P-P.js +0 -1
package/dist/cli.js CHANGED
@@ -9,21 +9,21 @@ import { promisify, stripVTControlCharacters } from "node:util";
9
9
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
10
10
  import { Http2ServerRequest, constants } from "node:http2";
11
11
  import { Readable } from "node:stream";
12
- import { lstat, open, readFile, readlink, writeFile } from "node:fs/promises";
12
+ import { lstat, open as open$1, readFile, readlink, writeFile } from "node:fs/promises";
13
13
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
14
14
  import { join as join$1 } from "path";
15
15
  import { createHash as createHash$1 } from "crypto";
16
16
  import { mkdir, readFile as readFile$1, writeFile as writeFile$1 } from "fs/promises";
17
17
  // \0rolldown/runtime.js
18
18
  var __defProp = Object.defineProperty;
19
- var __exportAll = (all, no_symbols) => {
20
- let target = {};
19
+ var __exportAll = (all, flags) => {
20
+ let target = Object.setPrototypeOf({}, null);
21
21
  for (var name in all) __defProp(target, name, {
22
22
  get: all[name],
23
23
  enumerable: true
24
24
  });
25
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
26
- return target;
25
+ if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
26
+ return flags & 2 ? target : Object.preventExtensions(target);
27
27
  };
28
28
  // node_modules/commander/lib/error.js
29
29
  /**
@@ -3106,6 +3106,7 @@ const handleParsingAllValues = (form, key, value) => {
3106
3106
  * @param {BodyData} form - The form data object.
3107
3107
  * @param {string} key - The dot notation key.
3108
3108
  * @param {BodyDataValue} value - The value to assign.
3109
+ * @param {{ count: number }} state - The state object tracking nesting depth.
3109
3110
  */
3110
3111
  const handleParsingNestedValues = (form, key, value, state) => {
3111
3112
  if (/(?:^|\.)__proto__\./.test(key)) return;
@@ -3198,16 +3199,7 @@ const tryDecode$1 = (str, decoder) => {
3198
3199
  });
3199
3200
  }
3200
3201
  };
3201
- /**
3202
- * Try to apply decodeURI() to given string.
3203
- * If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
3204
- * @param str The string to decode.
3205
- * @returns The decoded string that sometimes contains undecodable percent encoding.
3206
- * @example
3207
- * tryDecodeURI('Hello%20World') // 'Hello World'
3208
- * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
3209
- */
3210
- const tryDecodeURI$1 = (str) => tryDecode$1(str, decodeURI);
3202
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
3211
3203
  const getPath = (request) => {
3212
3204
  const url = request.url;
3213
3205
  const start = url.indexOf("/", url.indexOf(":") + 4);
@@ -3219,7 +3211,13 @@ const getPath = (request) => {
3219
3211
  const hashIndex = url.indexOf("#", i);
3220
3212
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
3221
3213
  const path = url.slice(start, end);
3222
- return tryDecodeURI$1(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
3214
+ const decoded = tryDecode$1(path, decodeURIWithPreservedPercent);
3215
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
3216
+ const rewritten = new URL("http://localhost");
3217
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
3218
+ if (tryDecode$1(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode$1(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
3219
+ }
3220
+ return decoded;
3223
3221
  } else if (charCode === 63 || charCode === 35) break;
3224
3222
  }
3225
3223
  return url.slice(start, i);
@@ -3270,17 +3268,22 @@ const _getQueryParam = (url, key, multiple) => {
3270
3268
  const hashIndex = url.indexOf("#", 8);
3271
3269
  if (hashIndex !== -1) url = url.slice(0, hashIndex);
3272
3270
  let encoded;
3273
- if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
3274
- let keyIndex = url.indexOf("?", 8);
3271
+ if (!multiple && key && !/[%+&=]/.test(key)) {
3272
+ const queryIndex = url.indexOf("?", 8);
3273
+ let keyIndex = queryIndex;
3275
3274
  if (keyIndex === -1) return;
3276
3275
  if (!url.startsWith(key, keyIndex + 1)) keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
3277
3276
  while (keyIndex !== -1) {
3278
3277
  const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
3279
- if (trailingKeyCode === 61) {
3280
- const valueIndex = keyIndex + key.length + 2;
3281
- const endIndex = url.indexOf("&", valueIndex);
3282
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
3283
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
3278
+ if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
3279
+ if (keyIndex > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex))) break;
3280
+ if (trailingKeyCode === 61) {
3281
+ const valueIndex = keyIndex + key.length + 2;
3282
+ const endIndex = url.indexOf("&", valueIndex);
3283
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
3284
+ }
3285
+ return "";
3286
+ }
3284
3287
  keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
3285
3288
  }
3286
3289
  encoded = /[%+]/.test(url);
@@ -3814,7 +3817,7 @@ var Context = class {
3814
3817
  * ```
3815
3818
  */
3816
3819
  header = (name, value, options) => {
3817
- if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
3820
+ if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
3818
3821
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
3819
3822
  if (value === void 0) headers.delete(name);
3820
3823
  else if (options?.append) headers.append(name, value);
@@ -4042,6 +4045,57 @@ const compose = (middleware, onError, onNotFound) => {
4042
4045
  }
4043
4046
  };
4044
4047
  };
4048
+ // node_modules/hono/dist/helper/route/index.js
4049
+ /**
4050
+ * Get matched routes in the handler
4051
+ *
4052
+ * @param {Context} c - The context object
4053
+ * @returns An array of matched routes
4054
+ *
4055
+ * @example
4056
+ * ```ts
4057
+ * import { matchedRoutes } from 'hono/route'
4058
+ *
4059
+ * app.use('*', async function logger(c, next) {
4060
+ * await next()
4061
+ * matchedRoutes(c).forEach(({ handler, method, path }, i) => {
4062
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
4063
+ * console.log(
4064
+ * method,
4065
+ * ' ',
4066
+ * path,
4067
+ * ' '.repeat(Math.max(10 - path.length, 0)),
4068
+ * name,
4069
+ * i === c.req.routeIndex ? '<- respond from here' : ''
4070
+ * )
4071
+ * })
4072
+ * })
4073
+ * ```
4074
+ */
4075
+ const matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
4076
+ /**
4077
+ * Get the route path registered within the handler
4078
+ *
4079
+ * @param {Context} c - The context object
4080
+ * @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
4081
+ * @returns The route path registered within the handler
4082
+ *
4083
+ * @example
4084
+ * ```ts
4085
+ * import { routePath } from 'hono/route'
4086
+ *
4087
+ * app.use('*', (c, next) => {
4088
+ * console.log(routePath(c)) // '*'
4089
+ * console.log(routePath(c, -1)) // '/posts/:id'
4090
+ * return next()
4091
+ * })
4092
+ *
4093
+ * app.get('/posts/:id', (c) => {
4094
+ * return c.text(routePath(c)) // '/posts/:id'
4095
+ * })
4096
+ * ```
4097
+ */
4098
+ const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
4045
4099
  // node_modules/hono/dist/router.js
4046
4100
  /**
4047
4101
  * Array of supported HTTP methods.
@@ -4068,6 +4122,51 @@ var UnsupportedPathError = class extends Error {};
4068
4122
  * Constant used to mark a composed handler.
4069
4123
  */
4070
4124
  const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
4125
+ // node_modules/hono/dist/utils/mount.js
4126
+ const countTrailingSlashes = (path) => {
4127
+ let index = path.length;
4128
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
4129
+ return path.length - index;
4130
+ };
4131
+ const getPathPrefixLength = (c, pathPrefix, routePath) => {
4132
+ if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
4133
+ const path = c.req.path;
4134
+ const matchResult = c.req[GET_MATCH_RESULT];
4135
+ const paramNames = /* @__PURE__ */ new Set();
4136
+ let length = 0;
4137
+ for (const part of splitRoutingPath(pathPrefix)) {
4138
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
4139
+ const pattern = getPattern(part);
4140
+ if (pattern && pattern !== "*") {
4141
+ const name = pattern[1];
4142
+ if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
4143
+ paramNames.add(name);
4144
+ }
4145
+ if (pattern && pattern !== "*" && pattern[2] !== true) {
4146
+ const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
4147
+ length += value.length + 1;
4148
+ } else if (pattern || part.endsWith("*")) {
4149
+ const end = path.indexOf("/", length + 1);
4150
+ length = end === -1 ? path.length : end;
4151
+ } else length += part.length + 1;
4152
+ }
4153
+ return length;
4154
+ };
4155
+ const createMountedRequest = (c, pathPrefix, routePath) => {
4156
+ if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
4157
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
4158
+ const path = c.req.path.slice(prefixLength) || "/";
4159
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
4160
+ const rawUrl = c.req.raw.url;
4161
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
4162
+ const rawPathEnd = rawUrl.search(/[?#]/);
4163
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
4164
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
4165
+ const url = new URL(rawUrl);
4166
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
4167
+ if (path.includes("%")) {}
4168
+ return new Request(url, c.req.raw);
4169
+ };
4071
4170
  // node_modules/hono/dist/hono-base.js
4072
4171
  /**
4073
4172
  * @module
@@ -4248,6 +4347,8 @@ var Hono$1 = class Hono {
4248
4347
  * @param {Function} applicationHandler - other Request Handler
4249
4348
  * @param {MountOptions} [options] - options of `.mount()`
4250
4349
  * @returns {Hono} mounted Hono instance
4350
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
4351
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
4251
4352
  *
4252
4353
  * @example
4253
4354
  * ```ts
@@ -4292,17 +4393,12 @@ var Hono$1 = class Hono {
4292
4393
  } catch {}
4293
4394
  return [c.env, executionContext];
4294
4395
  };
4295
- replaceRequest ||= (() => {
4296
- const mergedPath = mergePath(this._basePath, path);
4297
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
4298
- return (request) => {
4299
- const url = new URL(request.url);
4300
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
4301
- return new Request(url, request);
4302
- };
4303
- })();
4396
+ const defaultReplaceRequest = (c) => {
4397
+ const mountedRoutePath = routePath(c);
4398
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
4399
+ };
4304
4400
  const handler = async (c, next) => {
4305
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
4401
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
4306
4402
  if (res) return res;
4307
4403
  await next();
4308
4404
  };
@@ -4431,7 +4527,8 @@ function match(method, path) {
4431
4527
  }
4432
4528
  // node_modules/hono/dist/router/reg-exp-router/node.js
4433
4529
  const LABEL_REG_EXP_STR = "[^/]+";
4434
- const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
4530
+ const ONLY_WILDCARD_REG_EXP_STR = "[^]*";
4531
+ const TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
4435
4532
  const PATH_ERROR = Symbol();
4436
4533
  const regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
4437
4534
  /**
@@ -4444,8 +4541,8 @@ const regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
4444
4541
  function compareKey(a, b) {
4445
4542
  if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
4446
4543
  if (b.length === 1) return 1;
4447
- if (a === ".*" || a === "(?:|/.*)") return b === "(?:|/.*)" ? -1 : 1;
4448
- else if (b === ".*" || b === "(?:|/.*)") return -1;
4544
+ if (a === "[^]*" || a === "(?:|/[^]*)") return b === "[^]*" ? -1 : 1;
4545
+ else if (b === "[^]*" || b === "(?:|/[^]*)") return -1;
4449
4546
  if (a === "[^/]+") return 1;
4450
4547
  else if (b === "[^/]+") return -1;
4451
4548
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
@@ -4454,14 +4551,14 @@ var Node$1 = class Node {
4454
4551
  #index;
4455
4552
  #varIndex;
4456
4553
  #children = createNullObject();
4457
- insert(tokens, index, paramMap, context, isStatic) {
4554
+ insert(tokens, index, paramMap, context, keys) {
4458
4555
  let node = this;
4459
4556
  for (let i = 0, len = tokens.length; i < len; i++) {
4460
4557
  const token = tokens[i];
4461
4558
  const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
4462
4559
  "",
4463
4560
  "",
4464
- ".*"
4561
+ ONLY_WILDCARD_REG_EXP_STR
4465
4562
  ] : [
4466
4563
  "",
4467
4564
  "",
@@ -4476,15 +4573,16 @@ var Node$1 = class Node {
4476
4573
  const name = pattern[1];
4477
4574
  let regexpStr = pattern[2] || "[^/]+";
4478
4575
  if (name && pattern[2]) {
4479
- if (regexpStr === ".*") throw PATH_ERROR;
4576
+ if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
4480
4577
  regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
4481
4578
  if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
4482
4579
  if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
4483
4580
  }
4581
+ keys.push(regexpStr);
4484
4582
  nextNode = node.#children[regexpStr];
4485
4583
  if (!nextNode) {
4486
- if (regexpStr !== ".*" && regexpStr !== "(?:|/.*)") {
4487
- for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== ".*" && k !== "(?:|/.*)") throw PATH_ERROR;
4584
+ if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
4585
+ for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
4488
4586
  }
4489
4587
  nextNode = node.#children[regexpStr] = new Node();
4490
4588
  }
@@ -4493,16 +4591,17 @@ var Node$1 = class Node {
4493
4591
  paramMap.push([name, nextNode.#varIndex]);
4494
4592
  }
4495
4593
  } else {
4594
+ keys.push(token);
4496
4595
  nextNode = node.#children[token];
4497
4596
  if (!nextNode) {
4498
- for (const k in node.#children) if (k.length > 1 && k !== ".*" && k !== "(?:|/.*)") throw PATH_ERROR;
4597
+ for (const k in node.#children) if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
4499
4598
  nextNode = node.#children[token] = new Node();
4500
4599
  }
4501
4600
  }
4502
4601
  node = nextNode;
4503
4602
  }
4504
4603
  if (node.#index !== void 0) throw PATH_ERROR;
4505
- node.#index = isStatic ? -1 : index;
4604
+ node.#index = index;
4506
4605
  }
4507
4606
  buildRegExpStr() {
4508
4607
  const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
@@ -4523,8 +4622,14 @@ var Trie = class {
4523
4622
  #index = 0;
4524
4623
  paths = createNullObject();
4525
4624
  insert(path, isStatic) {
4625
+ const keys = [];
4526
4626
  if (isStatic) {
4527
- this.#root.insert(path.split(""), 0, [], this.#context, true);
4627
+ this.#root.insert(path.split(""), -1, [], this.#context, keys);
4628
+ this.paths[path] = [
4629
+ -1,
4630
+ [],
4631
+ keys
4632
+ ];
4528
4633
  return;
4529
4634
  }
4530
4635
  const paramAssoc = [];
@@ -4532,7 +4637,7 @@ var Trie = class {
4532
4637
  let markedPath = path;
4533
4638
  for (let i = 0;;) {
4534
4639
  let replaced = false;
4535
- markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
4640
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
4536
4641
  const mark = `@\\${i}`;
4537
4642
  groups[i] = [mark, m];
4538
4643
  i++;
@@ -4546,7 +4651,7 @@ var Trie = class {
4546
4651
  * - /* wildcard
4547
4652
  * - character
4548
4653
  */
4549
- const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
4654
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
4550
4655
  for (let i = groups.length - 1; i >= 0; i--) {
4551
4656
  const [mark] = groups[i];
4552
4657
  for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
@@ -4554,8 +4659,12 @@ var Trie = class {
4554
4659
  break;
4555
4660
  }
4556
4661
  }
4557
- this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
4558
- this.paths[path] = [this.#index++, paramAssoc];
4662
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
4663
+ this.paths[path] = [
4664
+ this.#index++,
4665
+ paramAssoc,
4666
+ keys
4667
+ ];
4559
4668
  }
4560
4669
  buildRegExp() {
4561
4670
  let regexp = this.#root.buildRegExpStr();
@@ -4586,21 +4695,21 @@ var Trie = class {
4586
4695
  }
4587
4696
  };
4588
4697
  // node_modules/hono/dist/router/reg-exp-router/router.js
4589
- let wildcardRegExpCache = createNullObject();
4590
- function buildWildcardRegExp(path) {
4591
- return wildcardRegExpCache[path] ??= new RegExp(`^${path.replace(/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g, (match, metaChar) => metaChar ? `\\${metaChar}` : match === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match === "*" ? ".*" : `/:${LABEL_REG_EXP_STR}`)}$`);
4698
+ function endsWithWildcard(keys) {
4699
+ const tail = keys[keys.length - 1];
4700
+ return tail === "[^]*" || tail === "(?:|/[^]*)";
4592
4701
  }
4593
- function findMiddleware(middleware, path) {
4594
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
4702
+ function covers(wildcard, target) {
4703
+ const last = wildcard.length - 1;
4704
+ for (let i = 0; i < last; i++) if (wildcard[i] !== target[i]) return false;
4705
+ return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
4595
4706
  }
4596
4707
  var RegExpRouter = class {
4597
4708
  name = "RegExpRouter";
4598
- #middleware;
4599
- #routes;
4709
+ #handlers;
4600
4710
  #tries;
4601
4711
  constructor() {
4602
- this.#middleware = { ["ALL"]: createNullObject() };
4603
- this.#routes = { ["ALL"]: createNullObject() };
4712
+ this.#handlers = { ["ALL"]: [] };
4604
4713
  this.#tries = { ["ALL"]: new Trie() };
4605
4714
  }
4606
4715
  #insertPath(method, path) {
@@ -4611,65 +4720,53 @@ var RegExpRouter = class {
4611
4720
  }
4612
4721
  }
4613
4722
  add(method, path, handler) {
4614
- const middleware = this.#middleware;
4615
- const routes = this.#routes;
4616
- if (!middleware) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
4617
- if (!middleware[method]) {
4618
- this.#tries[method] = new Trie();
4619
- for (const handlerMap of [middleware, routes]) {
4620
- handlerMap[method] = createNullObject();
4621
- for (const p in handlerMap["ALL"]) {
4622
- handlerMap[method][p] = [...handlerMap["ALL"][p]];
4623
- this.#insertPath(method, p);
4624
- }
4625
- }
4723
+ const handlers = this.#handlers;
4724
+ if (!handlers) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
4725
+ const tries = this.#tries;
4726
+ if (!handlers[method]) {
4727
+ tries[method] = new Trie();
4728
+ handlers[method] = [...handlers["ALL"]];
4729
+ for (const p in tries["ALL"].paths) this.#insertPath(method, p);
4626
4730
  }
4627
4731
  if (path === "/*") path = "*";
4628
- const methods = method === "ALL" ? Object.keys(middleware) : [method];
4629
- if (/\*$/.test(path)) {
4630
- const re = buildWildcardRegExp(path);
4631
- for (const m of methods) if (!middleware[m][path]) {
4632
- this.#insertPath(m, path);
4633
- middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
4634
- }
4635
- for (const handlerMap of [middleware, routes]) for (const m of methods) for (const p in handlerMap[m]) re.test(p) && handlerMap[m][p].push([handler, path]);
4636
- return;
4637
- }
4732
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
4638
4733
  const paths = checkOptionalParameter(path) || [path];
4639
4734
  for (const path of paths) for (const m of methods) {
4640
- if (!routes[m][path]) {
4641
- this.#insertPath(m, path);
4642
- routes[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
4643
- }
4644
- routes[m][path].push([handler, path]);
4735
+ if (!tries[m].paths[path]) this.#insertPath(m, path);
4736
+ handlers[m].push([handler, path]);
4645
4737
  }
4646
4738
  }
4647
4739
  match = match;
4648
4740
  buildAllMatchers() {
4649
4741
  const matchers = createNullObject();
4650
- for (const method of Object.keys(this.#routes)) matchers[method] = this.#buildMatcher(method);
4651
- this.#middleware = this.#routes = this.#tries = void 0;
4652
- wildcardRegExpCache = createNullObject();
4742
+ for (const method of Object.keys(this.#handlers)) matchers[method] = this.#buildMatcher(method);
4743
+ this.#handlers = this.#tries = void 0;
4653
4744
  return matchers;
4654
4745
  }
4655
4746
  #buildMatcher(method) {
4656
- const middleware = this.#middleware[method];
4657
- const routes = this.#routes[method];
4747
+ const handlers = this.#handlers[method];
4658
4748
  const trie = this.#tries[method];
4659
4749
  const staticMap = createNullObject();
4660
4750
  const handlerData = [];
4661
4751
  const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
4662
- for (const r of [middleware, routes]) for (const path in r) {
4663
- const handlers = r[path];
4664
- const pathData = trie.paths[path];
4665
- if (!pathData) {
4666
- staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
4667
- continue;
4668
- }
4669
- handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [h, trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
4670
- map[key] = paramReplacementMap[pathData[1][i][1]];
4752
+ const own = createNullObject();
4753
+ const entries = handlers.map(([h, p], i) => {
4754
+ (own[p] ??= []).push(i);
4755
+ return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
4756
+ map[key] = paramReplacementMap[varIndex];
4671
4757
  return map;
4672
- }, createNullObject())]);
4758
+ }, createNullObject())];
4759
+ });
4760
+ const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
4761
+ for (const path in trie.paths) {
4762
+ const [index, , keys] = trie.paths[path];
4763
+ const indexes = [...own[path]];
4764
+ for (const p of wildcards) if (p !== path && covers(trie.paths[p][2], keys)) indexes.push(...own[p]);
4765
+ const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
4766
+ if (index === -1) {
4767
+ const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
4768
+ staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
4769
+ } else handlerData[index] = data;
4673
4770
  }
4674
4771
  return [
4675
4772
  regexp,
@@ -4820,7 +4917,7 @@ var Node = class Node {
4820
4917
  const restPathString = path.slice(partOffsets[i]);
4821
4918
  const m = matcher.exec(restPathString);
4822
4919
  if (m) {
4823
- params[name] = m[0];
4920
+ if (!Object.hasOwn(params, name)) params[name] = m[0];
4824
4921
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
4825
4922
  if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
4826
4923
  for (const _ in child.#children) {
@@ -4833,7 +4930,7 @@ var Node = class Node {
4833
4930
  }
4834
4931
  }
4835
4932
  if (matcher === true || matcher.test(part)) {
4836
- params[name] = part;
4933
+ if (!Object.hasOwn(params, name)) params[name] = part;
4837
4934
  if (isLast) {
4838
4935
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
4839
4936
  if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
@@ -5042,16 +5139,27 @@ const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeader
5042
5139
  const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
5043
5140
  const reDotSegment = /\/\.\.?(?:[/?#]|$)/;
5044
5141
  const reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
5142
+ const validateRequestTarget = (target) => {
5143
+ const backslash = target.indexOf("\\");
5144
+ if (backslash !== -1) {
5145
+ const query = target.indexOf("?");
5146
+ if (query === -1 || backslash < query) throw new RequestError("Backslash in request path");
5147
+ }
5148
+ };
5045
5149
  const buildUrl = (scheme, host, incomingUrl) => {
5046
5150
  const url = `${scheme}://${host}${incomingUrl}`;
5047
5151
  if (!reValidHost.test(host)) {
5152
+ validateRequestTarget(incomingUrl);
5048
5153
  const urlObj = new URL(url);
5049
5154
  if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
5050
5155
  return urlObj.href;
5051
5156
  } else if (incomingUrl.length === 0) return url + "/";
5052
5157
  else {
5053
5158
  if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
5054
- if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) return new URL(url).href;
5159
+ if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) {
5160
+ validateRequestTarget(incomingUrl);
5161
+ return new URL(url).href;
5162
+ }
5055
5163
  return url;
5056
5164
  }
5057
5165
  };
@@ -5060,7 +5168,11 @@ const toRequestError = (e) => {
5060
5168
  return new RequestError(e.message, { cause: e });
5061
5169
  };
5062
5170
  const GlobalRequest = global.Request;
5063
- var Request$1 = class extends GlobalRequest {
5171
+ var Request$1 = class Request$1 extends GlobalRequest {
5172
+ static [Symbol.hasInstance](instance) {
5173
+ if (this === Request$1) return instance instanceof GlobalRequest || Function.prototype[Symbol.hasInstance].call(this, instance);
5174
+ return Function.prototype[Symbol.hasInstance].call(this, instance);
5175
+ }
5064
5176
  constructor(input, options) {
5065
5177
  if (typeof input === "object" && getRequestCache in input) {
5066
5178
  const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
@@ -5099,8 +5211,8 @@ const readBodyBufferedBeforeDisconnect = (incoming, chunks) => {
5099
5211
  else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== void 0 && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey]) result = newBodyUnusableError();
5100
5212
  else {
5101
5213
  const bodyChunks = chunks ?? [];
5102
- const chunk = incoming.read();
5103
- if (chunk !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
5214
+ let chunk;
5215
+ while ((chunk = incoming.read()) !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
5104
5216
  const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
5105
5217
  result = buffer;
5106
5218
  const contentLength = incoming.headers["content-length"];
@@ -5404,6 +5516,7 @@ Object.defineProperty(requestPrototype, "signal", { get() {
5404
5516
  "cache",
5405
5517
  "credentials",
5406
5518
  "destination",
5519
+ "duplex",
5407
5520
  "integrity",
5408
5521
  "mode",
5409
5522
  "redirect",
@@ -5436,6 +5549,9 @@ Object.defineProperty(requestPrototype, "blob", { value: function() {
5436
5549
  return new Response(buf, type ? { headers: { "content-type": type } } : void 0).blob();
5437
5550
  });
5438
5551
  } });
5552
+ Object.defineProperty(requestPrototype, "bytes", { value: function() {
5553
+ return this.arrayBuffer().then((buf) => new Uint8Array(buf));
5554
+ } });
5439
5555
  Object.defineProperty(requestPrototype, "json", { value: function() {
5440
5556
  if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
5441
5557
  return this.text().then(JSON.parse);
@@ -5460,6 +5576,7 @@ const newRequest = (incoming, defaultHostname) => {
5460
5576
  if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
5461
5577
  if (incoming instanceof Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
5462
5578
  try {
5579
+ validateRequestTarget(incomingUrl);
5463
5580
  req[urlKey] = new URL(incomingUrl).href;
5464
5581
  } catch (e) {
5465
5582
  throw new RequestError("Invalid absolute URL", { cause: e });
@@ -5489,6 +5606,10 @@ const GlobalResponse = global.Response;
5489
5606
  var Response$1 = class Response$1 {
5490
5607
  #body;
5491
5608
  #init;
5609
+ static [Symbol.hasInstance](instance) {
5610
+ if (this === Response$1) return instance instanceof GlobalResponse || Function.prototype[Symbol.hasInstance].call(this, instance);
5611
+ return Function.prototype[Symbol.hasInstance].call(this, instance);
5612
+ }
5492
5613
  [getResponseCache]() {
5493
5614
  const cache = this[cacheKey];
5494
5615
  const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
@@ -5509,7 +5630,7 @@ var Response$1 = class Response$1 {
5509
5630
  this[getResponseCache]();
5510
5631
  return;
5511
5632
  }
5512
- this.#init = init instanceof Response$1 ? init.#init : init;
5633
+ this.#init = #init in init ? init.#init : init;
5513
5634
  headers = new Headers(init.headers);
5514
5635
  } else this.#init = init;
5515
5636
  if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
@@ -5550,6 +5671,7 @@ var Response$1 = class Response$1 {
5550
5671
  [
5551
5672
  "arrayBuffer",
5552
5673
  "blob",
5674
+ "bytes",
5553
5675
  "clone",
5554
5676
  "formData",
5555
5677
  "json",
@@ -5622,6 +5744,11 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
5622
5744
  const cancel = (error) => {
5623
5745
  reader.cancel(error).catch(() => {});
5624
5746
  };
5747
+ const stream = writable.stream;
5748
+ if (writable.destroyed || stream?.closed || stream?.destroyed) {
5749
+ cancel();
5750
+ return reader.closed;
5751
+ }
5625
5752
  writable.on("close", cancel);
5626
5753
  writable.on("error", cancel);
5627
5754
  (currentReadPromise ?? reader.read()).then(flow, handleStreamError);
@@ -5639,7 +5766,7 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
5639
5766
  try {
5640
5767
  if (done) writable.end();
5641
5768
  else if (!writable.write(value)) writable.once("drain", onDrain);
5642
- else return reader.read().then(flow, handleStreamError);
5769
+ else reader.read().then(flow, handleStreamError);
5643
5770
  } catch (e) {
5644
5771
  handleStreamError(e);
5645
5772
  }
@@ -5647,7 +5774,10 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
5647
5774
  }
5648
5775
  function writeFromReadableStream(stream, writable) {
5649
5776
  if (stream.locked) throw new TypeError("ReadableStream is locked.");
5650
- else if (writable.destroyed) return;
5777
+ else if (writable.destroyed) {
5778
+ stream.cancel().catch(() => {});
5779
+ return;
5780
+ }
5651
5781
  return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
5652
5782
  }
5653
5783
  const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
@@ -5706,7 +5836,7 @@ const makeCloseHandler = (req, incoming, outgoing, needsBodyCleanup) => () => {
5706
5836
  if (incoming.errored) {
5707
5837
  recordBodyBufferedBeforeDisconnect(incoming);
5708
5838
  req[abortRequest](incoming.errored.toString());
5709
- } else if (!outgoing.writableFinished) {
5839
+ } else if (!outgoing.writableFinished || incoming instanceof Http2ServerRequest && incoming.aborted) {
5710
5840
  recordBodyBufferedBeforeDisconnect(incoming);
5711
5841
  req[abortRequest]("Client connection prematurely closed.");
5712
5842
  }
@@ -5838,10 +5968,7 @@ const responseViaResponseObject = async (res, outgoing, options = {}) => {
5838
5968
  let maxReadCount = 2;
5839
5969
  for (let i = 0; i < maxReadCount; i++) {
5840
5970
  currentReadPromise ||= reader.read();
5841
- const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
5842
- console.error(e);
5843
- done = true;
5844
- });
5971
+ const chunk = await readWithoutBlocking(currentReadPromise);
5845
5972
  if (!chunk) {
5846
5973
  if (i === 1) {
5847
5974
  await new Promise((resolve) => setTimeout(resolve));
@@ -5956,6 +6083,7 @@ const appendResponseHeaders = (headers, responseHeaders) => {
5956
6083
  });
5957
6084
  };
5958
6085
  const rejectUpgradeRequest = (socket, status, responseHeaders) => {
6086
+ if (socket.destroyed) return;
5959
6087
  const responseLines = ["Connection: close", "Content-Length: 0"];
5960
6088
  appendResponseHeaders(responseLines, responseHeaders);
5961
6089
  socket.end(`HTTP/1.1 ${status.toString()} ${STATUS_CODES[status] ?? ""}\r\n${responseLines.join("\r\n")}\r\n\r
@@ -5963,7 +6091,12 @@ const rejectUpgradeRequest = (socket, status, responseHeaders) => {
5963
6091
  };
5964
6092
  const createUpgradeRequest = (request) => {
5965
6093
  const protocol = request.socket.encrypted ? "https" : "http";
5966
- const url = new URL(request.url ?? "/", `${protocol}://${request.headers.host ?? "localhost"}`);
6094
+ const incomingUrl = request.url ?? "/";
6095
+ let url;
6096
+ if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
6097
+ validateRequestTarget(incomingUrl);
6098
+ url = new URL(incomingUrl).href;
6099
+ } else url = buildUrl(protocol, request.headers.host ?? "localhost", incomingUrl);
5967
6100
  const headers = new Headers();
5968
6101
  for (const key in request.headers) {
5969
6102
  const value = request.headers[key];
@@ -6000,6 +6133,10 @@ const setupWebSocket = (options) => {
6000
6133
  };
6001
6134
  server.on("upgrade", async (request, socket, head) => {
6002
6135
  if (request.headers.upgrade?.toLowerCase() !== "websocket") return;
6136
+ const ignoreSocketError = () => {};
6137
+ const reclaimWaiterOnClose = () => rejectWaiter(request);
6138
+ socket.on("error", ignoreSocketError);
6139
+ socket.once("close", reclaimWaiterOnClose);
6003
6140
  const env = {
6004
6141
  incoming: request,
6005
6142
  outgoing: void 0,
@@ -6014,8 +6151,12 @@ const setupWebSocket = (options) => {
6014
6151
  status = response.status;
6015
6152
  responseHeaders = response.headers;
6016
6153
  }
6017
- } catch {
6018
- if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 500);
6154
+ } catch (error) {
6155
+ if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, error instanceof RequestError ? 400 : 500);
6156
+ return;
6157
+ }
6158
+ if (socket.destroyed) {
6159
+ rejectWaiter(request);
6019
6160
  return;
6020
6161
  }
6021
6162
  const waiter = waiterMap.get(request);
@@ -6027,12 +6168,11 @@ const setupWebSocket = (options) => {
6027
6168
  const addResponseHeaders = (headers) => {
6028
6169
  appendResponseHeaders(headers, responseHeaders);
6029
6170
  };
6030
- const reclaimWaiterOnClose = () => rejectWaiter(request);
6031
- socket.once("close", reclaimWaiterOnClose);
6032
6171
  wss.on("headers", addResponseHeaders);
6033
6172
  try {
6034
6173
  wss.handleUpgrade(request, socket, head, (ws) => {
6035
6174
  socket.off("close", reclaimWaiterOnClose);
6175
+ socket.off("error", ignoreSocketError);
6036
6176
  wss.emit("connection", ws, request);
6037
6177
  });
6038
6178
  } finally {
@@ -6265,11 +6405,12 @@ const serveStatic = (options = { root: "" }) => {
6265
6405
  if (root !== "" && !existsSync(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
6266
6406
  return async (c, next) => {
6267
6407
  if (c.finalized) return next();
6408
+ if (c.req.method !== "GET" && c.req.method !== "HEAD") return next();
6268
6409
  let filename;
6269
6410
  if (optionPath) filename = optionPath;
6270
6411
  else try {
6271
- if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
6272
6412
  filename = tryDecodeURI(c.req.path);
6413
+ if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
6273
6414
  if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
6274
6415
  } catch {
6275
6416
  await options.onNotFound?.(c.req.path, c);
@@ -6306,7 +6447,7 @@ const serveStatic = (options = { root: "" }) => {
6306
6447
  const size = stats.size;
6307
6448
  const range = c.req.header("range") || "";
6308
6449
  c.header("Last-Modified", stats.mtime.toUTCString());
6309
- if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
6450
+ if (c.req.method === "HEAD") {
6310
6451
  c.header("Content-Length", size.toString());
6311
6452
  c.status(200);
6312
6453
  result = c.body(null);
@@ -6388,16 +6529,16 @@ const getCookie = (c, key, prefix) => {
6388
6529
  return parse$1(cookie);
6389
6530
  };
6390
6531
  // node_modules/hono/dist/validator/validator.js
6391
- const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
6392
- const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/i;
6393
- const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
6532
+ const jsonRegex = /^application\/([\w.-]+\+)?json$/i;
6533
+ const getMediaType = (contentType) => contentType.split(";")[0].trim().toLowerCase();
6394
6534
  const validator = (target, validationFunc) => {
6395
6535
  return async (c, next) => {
6396
6536
  let value = {};
6397
6537
  const contentType = c.req.header("Content-Type");
6538
+ const mediaType = contentType ? getMediaType(contentType) : "";
6398
6539
  switch (target) {
6399
6540
  case "json":
6400
- if (!contentType || !jsonRegex.test(contentType)) break;
6541
+ if (!jsonRegex.test(mediaType)) break;
6401
6542
  try {
6402
6543
  value = await c.req.json();
6403
6544
  } catch {
@@ -6405,7 +6546,7 @@ const validator = (target, validationFunc) => {
6405
6546
  }
6406
6547
  break;
6407
6548
  case "form": {
6408
- if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
6549
+ if (mediaType !== "multipart/form-data" && mediaType !== "application/x-www-form-urlencoded") break;
6409
6550
  let formData;
6410
6551
  if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
6411
6552
  else try {
@@ -6495,14 +6636,25 @@ const GIT_PREFIX_OVERRIDE = [
6495
6636
  "-c",
6496
6637
  "diff.dstPrefix=b/"
6497
6638
  ];
6639
+ const GIT_PLAIN_PATCH = [
6640
+ "--no-ext-diff",
6641
+ "--no-textconv",
6642
+ "--no-color"
6643
+ ];
6498
6644
  const JJ_PREFIX_OVERRIDE = ["--config", "diff.git.show-path-prefix=true"];
6645
+ const JJ_NO_COLOR = ["--color=never"];
6646
+ /** `interdiff` or `diff`, the subcommand that produces the patch */
6647
+ function subcommand(src) {
6648
+ return src.interdiff ? "interdiff" : "diff";
6649
+ }
6499
6650
  function diffCommand(src) {
6500
6651
  const fileArgs = src.files.length > 0 ? ["--", ...src.files] : [];
6501
6652
  if (src.vcs === "jj") return {
6502
6653
  cmd: "jj",
6503
6654
  args: [
6504
6655
  ...JJ_PREFIX_OVERRIDE,
6505
- "diff",
6656
+ ...JJ_NO_COLOR,
6657
+ subcommand(src),
6506
6658
  ...src.args,
6507
6659
  "--git",
6508
6660
  ...fileArgs
@@ -6513,6 +6665,7 @@ function diffCommand(src) {
6513
6665
  args: [
6514
6666
  ...GIT_PREFIX_OVERRIDE,
6515
6667
  "diff",
6668
+ ...GIT_PLAIN_PATCH,
6516
6669
  ...src.args,
6517
6670
  ...fileArgs
6518
6671
  ]
@@ -6548,11 +6701,11 @@ function normalizeJjRenames(patch) {
6548
6701
  async function getDiff(src) {
6549
6702
  const { cmd, args } = diffCommand(src);
6550
6703
  const { stdout, stderr, code } = await run(cmd, args);
6551
- if (code !== 0) throw new Error(`${cmd} diff failed (exit ${code}): ${stderr}`);
6704
+ if (code !== 0) throw new Error(`${cmd} ${subcommand(src)} failed (exit ${code}): ${stderr}`);
6552
6705
  const patch = src.vcs === "jj" ? normalizeJjRenames(stdout) : stdout;
6553
6706
  return {
6554
6707
  patch,
6555
- fileHashes: extractFileHashes(patch)
6708
+ fileHashes: extractFileHashes(patch, src.interdiff)
6556
6709
  };
6557
6710
  }
6558
6711
  /** A short content hash of the whole patch, so the page can ask whether the
@@ -6571,31 +6724,35 @@ function patchHash(patch) {
6571
6724
  * of their extended header lines instead. That changes when the rename or
6572
6725
  * mode does, and a content change adds an index line, so viewed state still
6573
6726
  * resets whenever there is something new to look at.
6727
+ *
6728
+ * An interdiff hashes each file's whole block instead. It shows only how the
6729
+ * change to a file changed, so keying on the new blob would mark the file
6730
+ * viewed in the commit's own diff too, where most of it is unseen.
6574
6731
  */
6575
- function extractFileHashes(patch) {
6732
+ function extractFileHashes(patch, interdiff = false) {
6576
6733
  const hashes = {};
6577
6734
  let currentFile = null;
6578
- let header = [];
6579
- const finishHeaderOnly = () => {
6735
+ let block = [];
6736
+ const hashBlock = () => {
6580
6737
  if (currentFile == null) return;
6581
- hashes[currentFile] = createHash("sha1").update(header.join("\n")).digest("hex").slice(0, 12);
6738
+ hashes[currentFile] = createHash("sha1").update(block.join("\n")).digest("hex").slice(0, 12);
6582
6739
  };
6583
6740
  for (const line of patch.split("\n")) {
6584
6741
  const diffMatch = line.match(/^diff --git a\/.+ b\/(.+)$/);
6585
6742
  if (diffMatch) {
6586
- finishHeaderOnly();
6743
+ hashBlock();
6587
6744
  currentFile = diffMatch[1];
6588
- header = [line];
6745
+ block = [line];
6589
6746
  continue;
6590
6747
  }
6591
6748
  if (currentFile == null) continue;
6592
- if (line.startsWith("index ")) {
6749
+ if (line.startsWith("index ") && !interdiff) {
6593
6750
  const indexMatch = line.match(/^index [0-9a-f]+\.\.([0-9a-f]+)/);
6594
6751
  if (indexMatch) hashes[currentFile] = indexMatch[1];
6595
6752
  currentFile = null;
6596
- } else header.push(line);
6753
+ } else block.push(line);
6597
6754
  }
6598
- finishHeaderOnly();
6755
+ hashBlock();
6599
6756
  return hashes;
6600
6757
  }
6601
6758
  // server/displayCommand.ts
@@ -6610,7 +6767,7 @@ function displayCommand(diffSource) {
6610
6767
  const args = (diffSource.displayArgs ?? diffSource.args).map(shellQuote);
6611
6768
  const files = diffSource.files.map(shellQuote);
6612
6769
  const fileSuffix = files.length > 0 ? ` -- ${files.join(" ")}` : "";
6613
- return `${diffSource.vcs} diff ${args.join(" ")}${fileSuffix}`;
6770
+ return `${diffSource.vcs} ${subcommand(diffSource)} ${args.join(" ")}${fileSuffix}`;
6614
6771
  }
6615
6772
  // server/fileContents.ts
6616
6773
  /**
@@ -23275,7 +23432,7 @@ function inJsxChildren(code, offset) {
23275
23432
  }
23276
23433
  const FIRST_LINE_BYTES = 256;
23277
23434
  async function readFirstLine(path) {
23278
- const fh = await open(path);
23435
+ const fh = await open$1(path);
23279
23436
  try {
23280
23437
  const buf = Buffer.alloc(FIRST_LINE_BYTES);
23281
23438
  const { bytesRead } = await fh.read(buf, 0, FIRST_LINE_BYTES, 0);
@@ -26182,7 +26339,7 @@ function bucketFor(state, inst) {
26182
26339
  return bucket;
26183
26340
  }
26184
26341
  let handoff;
26185
- const open$1 = [];
26342
+ const open = [];
26186
26343
  const memo = {
26187
26344
  alloc(_inst, payload, empty) {
26188
26345
  const bucket = handoff;
@@ -26193,7 +26350,7 @@ const memo = {
26193
26350
  issues: null
26194
26351
  };
26195
26352
  bucket.set(payload.value, entry);
26196
- open$1.push(entry);
26353
+ open.push(entry);
26197
26354
  return empty;
26198
26355
  },
26199
26356
  guard(inst) {
@@ -26259,10 +26416,10 @@ const memo = {
26259
26416
  return payload;
26260
26417
  }
26261
26418
  handoff = bucket;
26262
- const depth = open$1.length;
26419
+ const depth = open.length;
26263
26420
  const result = base(payload, ctx);
26264
26421
  handoff = void 0;
26265
- const entry = open$1.length > depth ? open$1.pop() : void 0;
26422
+ const entry = open.length > depth ? open.pop() : void 0;
26266
26423
  if (result instanceof Promise) return result.then((r) => {
26267
26424
  if (entry) entry.issues = r.issues.length ? cloneIssues(r.issues) : NO_ISSUES;
26268
26425
  return r;
@@ -28804,7 +28961,7 @@ function buildPayload(diffSource, root, input) {
28804
28961
  root,
28805
28962
  diff: {
28806
28963
  command: displayCommand(diffSource),
28807
- toWorkingCopy: diffSource.commentsEnabled
28964
+ toWorkingCopy: diffSource.toWorkingCopy
28808
28965
  },
28809
28966
  file: input.file,
28810
28967
  side: input.side,
@@ -28941,6 +29098,7 @@ function runSend(command, payload, { env, cwd, timeoutMs = TIMEOUT_MS, maxOutput
28941
29098
  // server/main.ts
28942
29099
  async function startServer(opts) {
28943
29100
  const { diffSource, port = 0, hostname = "localhost", cwd, poll = true, send } = opts;
29101
+ const { tabSize = 2 } = opts;
28944
29102
  await getDiff(diffSource);
28945
29103
  const app = new Hono();
28946
29104
  const token = newToken();
@@ -28948,25 +29106,28 @@ async function startServer(opts) {
28948
29106
  if (c.req.path === "/api/theme.js" || tokenMatches(c.req.header("X-Skepsis-Token"), token)) return next();
28949
29107
  return c.json({ error: "This page has no valid token. Open the URL skepsis printed when it started." }, 401);
28950
29108
  });
29109
+ const commentsEnabled = diffSource.toWorkingCopy && !diffSource.interdiff;
28951
29110
  app.get("/api/diff", async (c) => {
28952
29111
  const { patch, fileHashes } = await getDiff(diffSource);
28953
29112
  const files = Object.keys(fileHashes);
28954
29113
  const [viewed, generated, commentSyntaxes] = await Promise.all([
28955
29114
  loadViewed(cwd, fileHashes),
28956
29115
  getGeneratedFiles(cwd, files),
28957
- diffSource.commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
29116
+ commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
28958
29117
  ]);
28959
29118
  return c.json({
28960
29119
  patch,
28961
29120
  revset: displayCommand(diffSource),
28962
29121
  repo: basename(cwd),
28963
29122
  vcs: diffSource.vcs,
28964
- commentsEnabled: diffSource.commentsEnabled,
29123
+ interdiff: !!diffSource.interdiff,
29124
+ commentsEnabled,
28965
29125
  expandable: diffSource.endpoints !== null,
28966
29126
  fileHashes,
28967
29127
  patchHash: patchHash(patch),
28968
29128
  poll,
28969
29129
  send: !!send,
29130
+ tabSize,
28970
29131
  viewed,
28971
29132
  commentSyntaxes,
28972
29133
  generated
@@ -29088,16 +29249,23 @@ function parsePort(value) {
29088
29249
  if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("port must be an integer between 0 and 65535");
29089
29250
  return port;
29090
29251
  }
29091
- const program = new Command().name("skepsis").description("Local diff review UI (auto-detects jj or git)").option("-r, --revisions <revsets>", "Show changes in these revisions").option("-f, --from <rev>", "Show changes from this revision").option("-t, --to <rev>", "Show changes to this revision").option("--git", "force git mode (skip jj detection)").option("--dev", "run with Vite dev server for development").option("--host <address>", "address to bind the HTTP server to", "localhost").option("-p, --port <number>", "port for the browser UI (default: a free one)", parsePort).option("--no-open", "don't open a browser").option("--open-cmd <command>", "shell command that opens the page, given the URL as its last argument (default: $SKEPSIS_OPEN, else the system opener)").option("--no-poll", "don't check for changes to the diff while the page is open").option("--send <command>", "add a Send button that pipes the comment to this shell command (default: $SKEPSIS_SEND)").argument("[files...]", "Limit diff to these paths (passed through to jj/git)").addHelpText("after", "\nOnce the server is listening, it prints one line to stdout,\n`skepsis on <url> (<diff command>)`, for scripts that start it in the\nbackground with --no-open. The URL ends in a per-run #token= the page\nneeds, so open it whole.\n\nWith --send, the comment box sends to `sh -c <command>`, run in this\ndirectory, with the comment as one JSON object on stdin (its `prompt`\nfield has it all as plain text). Exit 0 means delivered; anything else,\nor taking over 10 s, is an error, and stderr is shown.\nSee the README for the fields and recipes.").parse();
29252
+ function parseTabSize(value) {
29253
+ const size = /^\d+$/.test(value) ? Number(value) : NaN;
29254
+ if (!(size >= 1 && size <= 16)) throw new InvalidArgumentError("tab size must be an integer between 1 and 16");
29255
+ return size;
29256
+ }
29257
+ for (const [name, value] of Object.entries(process.env)) if (name.startsWith("SKEPSIS_") && value === "") delete process.env[name];
29258
+ const program = new Command().name("skepsis").description("Local diff review UI (auto-detects jj or git)").option("-r, --revisions <revsets>", "Show changes in these revisions").option("-f, --from <rev>", "Show changes from this revision").option("-t, --to <rev>", "Show changes to this revision").option("--interdiff", "Show how the change in --to differs from the change in --from (jj only)").option("--git", "force git mode (skip jj detection)").option("--dev", "run with Vite dev server for development").option("--host <address>", "address to bind the HTTP server to", "localhost").option("-p, --port <number>", "port for the browser UI (default: a free one)", parsePort).option("--no-open", "don't open a browser").addOption(new Option("--open-cmd <command>", "shell command that opens the page, given the URL as its last argument").env("SKEPSIS_OPEN").default("", "the system opener")).option("--no-poll", "don't check for changes to the diff while the page is open").addOption(new Option("--tab-size <columns>", "tab width in columns").env("SKEPSIS_TAB_SIZE").argParser(parseTabSize).default(2)).addOption(new Option("--send <command>", "add a Send button that pipes the comment to this shell command").env("SKEPSIS_SEND")).argument("[files...]", "Limit diff to these paths (passed through to jj/git)").addHelpText("after", "\nOnce the server is listening, it prints one line to stdout,\n`skepsis on <url> (<diff command>)`, for scripts that start it in the\nbackground with --no-open. The URL ends in a per-run #token= the page\nneeds, so open it whole.\n\nWith --send, the comment box sends to `sh -c <command>`, run in this\ndirectory, with the comment as one JSON object on stdin (its `prompt`\nfield has it all as plain text). Exit 0 means delivered; anything else,\nor taking over 10 s, is an error, and stderr is shown.\nSee the README for the fields and recipes.").parse();
29092
29259
  const opts = program.opts();
29093
- const files = program.processedArgs[0] ?? [];
29094
- const hostname = opts.host;
29095
- const openCmd = (opts.openCmd ?? process.env["SKEPSIS_OPEN"]) || null;
29096
- const send = (opts.send ?? process.env["SKEPSIS_SEND"]) || null;
29097
- if (send && !LOOPBACK.has(hostname === "::1" ? "[::1]" : hostname)) {
29098
- console.error(`--send runs a command on request from the page, so it needs a loopback\n--host (localhost, 127.0.0.1 or ::1), not ${hostname}.`);
29260
+ function fail(message) {
29261
+ console.error(message);
29099
29262
  process.exit(1);
29100
29263
  }
29264
+ const files = program.processedArgs[0] ?? [];
29265
+ const hostname = opts.host;
29266
+ const openCmd = opts.openCmd || null;
29267
+ const send = opts.send || null;
29268
+ if (send && !LOOPBACK.has(hostname === "::1" ? "[::1]" : hostname)) fail(`--send runs a command on request from the page, so it needs a loopback\n--host (localhost, 127.0.0.1 or ::1), not ${hostname}.`);
29101
29269
  function detectVcs() {
29102
29270
  try {
29103
29271
  execFileSync("jj", ["root"], { stdio: "ignore" });
@@ -29112,6 +29280,11 @@ function detectVcs() {
29112
29280
  }
29113
29281
  }
29114
29282
  const vcs = opts.git ? "git" : detectVcs();
29283
+ if (opts.interdiff) {
29284
+ if (vcs !== "jj") fail("--interdiff needs jj");
29285
+ if (opts.revisions) fail("--interdiff can't be combined with -r");
29286
+ if (!opts.from && !opts.to) fail("--interdiff needs -f, -t, or both");
29287
+ }
29115
29288
  const GIT_BASE_CANDIDATES = [
29116
29289
  "origin/HEAD",
29117
29290
  "origin/main",
@@ -29141,13 +29314,9 @@ function resolveGitBase() {
29141
29314
  };
29142
29315
  } catch (error) {
29143
29316
  const { code, stderr } = error;
29144
- if (code === "ENOENT" || stderr?.includes("not a git repository")) {
29145
- console.error(stderr?.trim() || error.message);
29146
- process.exit(1);
29147
- }
29317
+ if (code === "ENOENT" || stderr?.includes("not a git repository")) fail(stderr?.trim() || error.message);
29148
29318
  }
29149
- console.error(`No base revision found for the default diff (tried ${GIT_BASE_CANDIDATES.join(", ")}).\nSpecify a range explicitly with -r or -f/-t.`);
29150
- process.exit(1);
29319
+ fail(`No base revision found for the default diff (tried ${GIT_BASE_CANDIDATES.join(", ")}).\nSpecify a range explicitly with -r or -f/-t.`);
29151
29320
  }
29152
29321
  /** Split an `A..B` range into its two revs. Returns null for anything that
29153
29322
  * isn't a simple two-sided range with both sides non-empty. */
@@ -29165,21 +29334,21 @@ function parseRange(rev) {
29165
29334
  function buildDiffSource() {
29166
29335
  if (vcs === "jj") {
29167
29336
  const args = [];
29168
- let commentsEnabled;
29337
+ let toWorkingCopy;
29169
29338
  let endpoints;
29170
29339
  if (opts.from || opts.to || !opts.revisions) {
29171
29340
  const from = opts.from ?? (opts.to ? void 0 : "fork_point(trunk() | @)");
29172
29341
  if (from) args.push("--from", from);
29173
29342
  if (opts.to) args.push("--to", opts.to);
29174
- commentsEnabled = !opts.to || opts.to === "@";
29175
- endpoints = {
29343
+ toWorkingCopy = !opts.to || opts.to === "@";
29344
+ endpoints = opts.interdiff ? null : {
29176
29345
  left: from ?? "@",
29177
29346
  right: { rev: opts.to ?? "@" }
29178
29347
  };
29179
29348
  } else {
29180
29349
  const rev = opts.revisions;
29181
29350
  args.push("-r", rev);
29182
- commentsEnabled = rev === "@" || rev.endsWith("..@");
29351
+ toWorkingCopy = rev === "@" || rev.endsWith("..@");
29183
29352
  const range = parseRange(rev);
29184
29353
  if (range) endpoints = {
29185
29354
  left: range.left,
@@ -29193,27 +29362,28 @@ function buildDiffSource() {
29193
29362
  }
29194
29363
  return {
29195
29364
  vcs: "jj",
29365
+ interdiff: opts.interdiff,
29196
29366
  args,
29197
- commentsEnabled,
29367
+ toWorkingCopy,
29198
29368
  files,
29199
29369
  endpoints
29200
29370
  };
29201
29371
  } else {
29202
29372
  let args;
29203
- let commentsEnabled;
29373
+ let toWorkingCopy;
29204
29374
  let endpoints;
29205
29375
  let displayArgs;
29206
29376
  if (opts.from || opts.to) {
29207
29377
  if (opts.to) {
29208
29378
  args = [opts.from ?? "HEAD", opts.to];
29209
- commentsEnabled = false;
29379
+ toWorkingCopy = false;
29210
29380
  endpoints = {
29211
29381
  left: opts.from ?? "HEAD",
29212
29382
  right: { rev: opts.to }
29213
29383
  };
29214
29384
  } else {
29215
29385
  args = [opts.from];
29216
- commentsEnabled = true;
29386
+ toWorkingCopy = true;
29217
29387
  endpoints = {
29218
29388
  left: opts.from,
29219
29389
  right: "workingCopy"
@@ -29223,14 +29393,14 @@ function buildDiffSource() {
29223
29393
  const { base, mergeBase } = resolveGitBase();
29224
29394
  args = [mergeBase];
29225
29395
  displayArgs = ["--merge-base", base];
29226
- commentsEnabled = true;
29396
+ toWorkingCopy = true;
29227
29397
  endpoints = {
29228
29398
  left: mergeBase,
29229
29399
  right: "workingCopy"
29230
29400
  };
29231
29401
  } else {
29232
29402
  const rev = opts.revisions;
29233
- commentsEnabled = !rev.includes("..");
29403
+ toWorkingCopy = !rev.includes("..");
29234
29404
  args = [rev];
29235
29405
  const range = parseRange(rev);
29236
29406
  if (range) endpoints = {
@@ -29246,7 +29416,7 @@ function buildDiffSource() {
29246
29416
  return {
29247
29417
  vcs: "git",
29248
29418
  args,
29249
- commentsEnabled,
29419
+ toWorkingCopy,
29250
29420
  files,
29251
29421
  endpoints,
29252
29422
  displayArgs
@@ -29284,7 +29454,8 @@ const { port: apiPort, token } = await startServer({
29284
29454
  hostname,
29285
29455
  port: opts.dev ? void 0 : opts.port,
29286
29456
  poll: opts.poll,
29287
- send
29457
+ send,
29458
+ tabSize: opts.tabSize
29288
29459
  }).catch((err) => {
29289
29460
  console.error(err.message);
29290
29461
  return cleanup(1);