just-bash 1.2.5 → 1.3.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.
- package/README.md +1 -1
- package/dist/ai/index.d.ts +5 -0
- package/dist/bin/chunks/alias-ZAQAKC5X.js +7 -0
- package/dist/bin/chunks/awk2-A73ZNFXJ.js +20 -0
- package/dist/bin/chunks/base64-JPITV4MD.js +6 -0
- package/dist/bin/chunks/base64-KNBBHA5Y.js +5 -0
- package/dist/bin/chunks/basename-IYEP3AMY.js +6 -0
- package/dist/bin/chunks/bash-WZYHIZP6.js +7 -0
- package/dist/bin/chunks/cat-XILYL7NW.js +6 -0
- package/dist/bin/chunks/chmod-EXWX4N7Y.js +9 -0
- package/dist/bin/chunks/chunk-7Q4WQLOS.js +9 -0
- package/dist/bin/chunks/chunk-GX4MPCG6.js +9 -0
- package/dist/bin/chunks/chunk-SJXDWN5X.js +2 -0
- package/dist/bin/chunks/clear-2APRIRCF.js +2 -0
- package/dist/bin/chunks/comm-KY3COLF5.js +13 -0
- package/dist/bin/chunks/cp-HES4UN7K.js +8 -0
- package/dist/bin/chunks/curl-BN5M3BUX.js +26 -0
- package/dist/bin/chunks/cut-JSIPAKOX.js +6 -0
- package/dist/bin/chunks/date-CU4J7GHI.js +5 -0
- package/dist/bin/chunks/diff-W4JRNHXW.js +19 -0
- package/dist/bin/chunks/dirname-UTCUUILN.js +5 -0
- package/dist/bin/chunks/du-2JU3PUTM.js +8 -0
- package/dist/bin/chunks/echo-HKLPYMNC.js +4 -0
- package/dist/bin/chunks/env-2SBJNP7X.js +9 -0
- package/dist/bin/chunks/expr-M74QZQ6C.js +5 -0
- package/dist/bin/chunks/file-Q4UOC4J2.js +23 -0
- package/dist/bin/chunks/file-QPD3U2H7.js +23 -0
- package/dist/bin/chunks/find-D3ZC5DXH.js +11 -0
- package/dist/bin/chunks/grep-BEZRXAWL.js +15 -0
- package/dist/bin/chunks/head-YGMY3DHE.js +2 -0
- package/dist/bin/chunks/help-UEF7LW7F.js +16 -0
- package/dist/bin/chunks/history-OGBCIAR5.js +3 -0
- package/dist/bin/chunks/html-to-markdown-HTGML4TH.js +84 -0
- package/dist/bin/chunks/jq-ME57VHK6.js +14 -0
- package/dist/bin/chunks/ln-RUR4ALOJ.js +10 -0
- package/dist/bin/chunks/ls-GU5227KE.js +26 -0
- package/dist/bin/chunks/md5sum-C7WDEYN5.js +2 -0
- package/dist/bin/chunks/md5sum-KZ4MRIXM.js +2 -0
- package/dist/bin/chunks/mkdir-4OYU22AA.js +7 -0
- package/dist/bin/chunks/mv-H3S4FEWR.js +7 -0
- package/dist/bin/chunks/paste-HHCFASL4.js +8 -0
- package/dist/bin/chunks/printf-2JFCUFOA.js +14 -0
- package/dist/bin/chunks/pwd-T5Q3JEBO.js +3 -0
- package/dist/bin/chunks/readlink-M44TLMFS.js +7 -0
- package/dist/bin/chunks/rm-R4M647EC.js +8 -0
- package/dist/bin/chunks/sed-QLLAZYHH.js +80 -0
- package/dist/bin/chunks/seq-GJMQM7SP.js +7 -0
- package/dist/bin/chunks/sha1sum-WKCGV66X.js +2 -0
- package/dist/bin/chunks/sha1sum-XLRE72T4.js +2 -0
- package/dist/bin/chunks/sha256sum-3ZDGP5WC.js +2 -0
- package/dist/bin/chunks/sha256sum-BBKWFA43.js +2 -0
- package/dist/bin/chunks/sleep-OJPODQGM.js +10 -0
- package/dist/bin/chunks/sort-JL33INQB.js +16 -0
- package/dist/bin/chunks/sort-NCQNGVCX.js +16 -0
- package/dist/bin/chunks/sort-WGKQ3WYR.js +15 -0
- package/dist/bin/chunks/stat-CR2INBC2.js +9 -0
- package/dist/bin/chunks/tail-BYPLMYMZ.js +2 -0
- package/dist/bin/chunks/tee-HOMRRC3X.js +3 -0
- package/dist/bin/chunks/timeout-MYKG34DQ.js +12 -0
- package/dist/bin/chunks/touch-3ZANYAXI.js +4 -0
- package/dist/bin/chunks/tr-E66N7IS2.js +20 -0
- package/dist/bin/chunks/tree-EE2PYIMV.js +12 -0
- package/dist/bin/chunks/true-OWPVS7U4.js +2 -0
- package/dist/bin/chunks/uniq-F5NP3LLU.js +5 -0
- package/dist/bin/chunks/wc-NBMNJDZL.js +6 -0
- package/dist/bin/chunks/which-6MRG2UCF.js +3 -0
- package/dist/bin/chunks/xargs-EMY5BOJ2.js +4 -0
- package/dist/bin/chunks/xargs-XAZFX5J3.js +4 -0
- package/dist/bin/just-bash.js +36 -36
- package/dist/bin/shell/chunks/alias-ZAQAKC5X.js +7 -0
- package/dist/bin/shell/chunks/awk2-A73ZNFXJ.js +20 -0
- package/dist/bin/shell/chunks/base64-JPITV4MD.js +6 -0
- package/dist/bin/shell/chunks/base64-KNBBHA5Y.js +5 -0
- package/dist/bin/shell/chunks/basename-IYEP3AMY.js +6 -0
- package/dist/bin/shell/chunks/bash-WZYHIZP6.js +7 -0
- package/dist/bin/shell/chunks/cat-XILYL7NW.js +6 -0
- package/dist/bin/shell/chunks/chmod-EXWX4N7Y.js +9 -0
- package/dist/bin/shell/chunks/chunk-7Q4WQLOS.js +9 -0
- package/dist/bin/shell/chunks/chunk-GX4MPCG6.js +9 -0
- package/dist/bin/shell/chunks/chunk-SJXDWN5X.js +2 -0
- package/dist/bin/shell/chunks/clear-2APRIRCF.js +2 -0
- package/dist/bin/shell/chunks/comm-KY3COLF5.js +13 -0
- package/dist/bin/shell/chunks/cp-HES4UN7K.js +8 -0
- package/dist/bin/shell/chunks/curl-BN5M3BUX.js +26 -0
- package/dist/bin/shell/chunks/cut-JSIPAKOX.js +6 -0
- package/dist/bin/shell/chunks/date-CU4J7GHI.js +5 -0
- package/dist/bin/shell/chunks/diff-W4JRNHXW.js +19 -0
- package/dist/bin/shell/chunks/dirname-UTCUUILN.js +5 -0
- package/dist/bin/shell/chunks/du-2JU3PUTM.js +8 -0
- package/dist/bin/shell/chunks/echo-HKLPYMNC.js +4 -0
- package/dist/bin/shell/chunks/env-2SBJNP7X.js +9 -0
- package/dist/bin/shell/chunks/expr-M74QZQ6C.js +5 -0
- package/dist/bin/shell/chunks/file-Q4UOC4J2.js +23 -0
- package/dist/bin/shell/chunks/file-QPD3U2H7.js +23 -0
- package/dist/bin/shell/chunks/find-D3ZC5DXH.js +11 -0
- package/dist/bin/shell/chunks/grep-BEZRXAWL.js +15 -0
- package/dist/bin/shell/chunks/head-YGMY3DHE.js +2 -0
- package/dist/bin/shell/chunks/help-UEF7LW7F.js +16 -0
- package/dist/bin/shell/chunks/history-OGBCIAR5.js +3 -0
- package/dist/bin/shell/chunks/html-to-markdown-HTGML4TH.js +84 -0
- package/dist/bin/shell/chunks/jq-ME57VHK6.js +14 -0
- package/dist/bin/shell/chunks/ln-RUR4ALOJ.js +10 -0
- package/dist/bin/shell/chunks/ls-GU5227KE.js +26 -0
- package/dist/bin/shell/chunks/md5sum-C7WDEYN5.js +2 -0
- package/dist/bin/shell/chunks/md5sum-KZ4MRIXM.js +2 -0
- package/dist/bin/shell/chunks/mkdir-4OYU22AA.js +7 -0
- package/dist/bin/shell/chunks/mv-H3S4FEWR.js +7 -0
- package/dist/bin/shell/chunks/paste-HHCFASL4.js +8 -0
- package/dist/bin/shell/chunks/printf-2JFCUFOA.js +14 -0
- package/dist/bin/shell/chunks/pwd-T5Q3JEBO.js +3 -0
- package/dist/bin/shell/chunks/readlink-M44TLMFS.js +7 -0
- package/dist/bin/shell/chunks/rm-R4M647EC.js +8 -0
- package/dist/bin/shell/chunks/sed-QLLAZYHH.js +80 -0
- package/dist/bin/shell/chunks/seq-GJMQM7SP.js +7 -0
- package/dist/bin/shell/chunks/sha1sum-WKCGV66X.js +2 -0
- package/dist/bin/shell/chunks/sha1sum-XLRE72T4.js +2 -0
- package/dist/bin/shell/chunks/sha256sum-3ZDGP5WC.js +2 -0
- package/dist/bin/shell/chunks/sha256sum-BBKWFA43.js +2 -0
- package/dist/bin/shell/chunks/sleep-OJPODQGM.js +10 -0
- package/dist/bin/shell/chunks/sort-JL33INQB.js +16 -0
- package/dist/bin/shell/chunks/sort-NCQNGVCX.js +16 -0
- package/dist/bin/shell/chunks/sort-WGKQ3WYR.js +15 -0
- package/dist/bin/shell/chunks/stat-CR2INBC2.js +9 -0
- package/dist/bin/shell/chunks/tail-BYPLMYMZ.js +2 -0
- package/dist/bin/shell/chunks/tee-HOMRRC3X.js +3 -0
- package/dist/bin/shell/chunks/timeout-MYKG34DQ.js +12 -0
- package/dist/bin/shell/chunks/touch-3ZANYAXI.js +4 -0
- package/dist/bin/shell/chunks/tr-E66N7IS2.js +20 -0
- package/dist/bin/shell/chunks/tree-EE2PYIMV.js +12 -0
- package/dist/bin/shell/chunks/true-OWPVS7U4.js +2 -0
- package/dist/bin/shell/chunks/uniq-F5NP3LLU.js +5 -0
- package/dist/bin/shell/chunks/wc-NBMNJDZL.js +6 -0
- package/dist/bin/shell/chunks/which-6MRG2UCF.js +3 -0
- package/dist/bin/shell/chunks/xargs-EMY5BOJ2.js +4 -0
- package/dist/bin/shell/chunks/xargs-XAZFX5J3.js +4 -0
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/ai/index.js +384 -343
- package/dist/bundle/chunks/alias-JFIUWFGE.js +6 -0
- package/dist/bundle/chunks/awk2-QWBT4IFJ.js +19 -0
- package/dist/bundle/chunks/base64-JN6XXTIG.js +4 -0
- package/dist/bundle/chunks/base64-TUA2XORD.js +5 -0
- package/dist/bundle/chunks/basename-5UVU5RXR.js +5 -0
- package/dist/bundle/chunks/bash-BASUPKHJ.js +6 -0
- package/dist/bundle/chunks/cat-47EP4IAV.js +5 -0
- package/dist/bundle/chunks/chmod-XJXFAD4M.js +8 -0
- package/dist/bundle/chunks/chunk-2RUN43TJ.js +1 -0
- package/dist/bundle/chunks/chunk-46TSKXFW.js +8 -0
- package/dist/bundle/chunks/chunk-4HEWHW5W.js +8 -0
- package/dist/bundle/chunks/clear-XD3TJRVQ.js +1 -0
- package/dist/bundle/chunks/comm-KSJ4BBRQ.js +12 -0
- package/dist/bundle/chunks/cp-37OVLNLD.js +7 -0
- package/dist/bundle/chunks/curl-C43O5WQS.js +25 -0
- package/dist/bundle/chunks/cut-FIZRELKC.js +5 -0
- package/dist/bundle/chunks/date-NN5C354M.js +4 -0
- package/dist/bundle/chunks/diff-GLRVCAKJ.js +6 -0
- package/dist/bundle/chunks/dirname-U2KVUSQY.js +4 -0
- package/dist/bundle/chunks/du-KRAFOIQK.js +7 -0
- package/dist/bundle/chunks/echo-WUKBESC7.js +3 -0
- package/dist/bundle/chunks/env-MSPSPGCD.js +8 -0
- package/dist/bundle/chunks/expr-HYOCSWK6.js +4 -0
- package/dist/bundle/chunks/file-JMDIXLHY.js +22 -0
- package/dist/bundle/chunks/file-LQXX6P4Y.js +22 -0
- package/dist/bundle/chunks/find-R6LJIRBI.js +10 -0
- package/dist/bundle/chunks/grep-ZJVDG3FA.js +14 -0
- package/dist/bundle/chunks/head-6PAUYCDP.js +1 -0
- package/dist/bundle/chunks/help-5E6PYJWQ.js +15 -0
- package/dist/bundle/chunks/history-SG6VRATI.js +2 -0
- package/dist/bundle/chunks/html-to-markdown-ZSZ34PAN.js +4 -0
- package/dist/bundle/chunks/jq-ABWUP4LV.js +13 -0
- package/dist/bundle/chunks/ln-XFYHBIFL.js +9 -0
- package/dist/bundle/chunks/ls-JGYJQA2Y.js +23 -0
- package/dist/bundle/chunks/md5sum-3BXZVFKC.js +1 -0
- package/dist/bundle/chunks/md5sum-PIH6F3O3.js +1 -0
- package/dist/bundle/chunks/mkdir-HA2FJX4O.js +6 -0
- package/dist/bundle/chunks/mv-7I62SB3I.js +6 -0
- package/dist/bundle/chunks/paste-QBGVCQFT.js +7 -0
- package/dist/bundle/chunks/printf-HBP44PXI.js +13 -0
- package/dist/bundle/chunks/pwd-CEF235GL.js +2 -0
- package/dist/bundle/chunks/readlink-MQIMKDSA.js +6 -0
- package/dist/bundle/chunks/rm-NF3FNLAY.js +7 -0
- package/dist/bundle/chunks/sed-H2RWPMTM.js +79 -0
- package/dist/bundle/chunks/seq-VKYIUOPJ.js +6 -0
- package/dist/bundle/chunks/sha1sum-HVHNZSEC.js +1 -0
- package/dist/bundle/chunks/sha1sum-MSBXCB4N.js +1 -0
- package/dist/bundle/chunks/sha256sum-REOOJORK.js +1 -0
- package/dist/bundle/chunks/sha256sum-YMKJMSTW.js +1 -0
- package/dist/bundle/chunks/sleep-AFN3PHJW.js +9 -0
- package/dist/bundle/chunks/sort-R3YWDMTV.js +14 -0
- package/dist/bundle/chunks/sort-TEXV7CUR.js +15 -0
- package/dist/bundle/chunks/sort-XODGFZC4.js +15 -0
- package/dist/bundle/chunks/stat-FVFLDQGP.js +8 -0
- package/dist/bundle/chunks/tail-QXKYHAML.js +1 -0
- package/dist/bundle/chunks/tee-W5HCCBPO.js +2 -0
- package/dist/bundle/chunks/timeout-XAA3N7CF.js +11 -0
- package/dist/bundle/chunks/touch-FOE745V2.js +3 -0
- package/dist/bundle/chunks/tr-LMLGE4IE.js +19 -0
- package/dist/bundle/chunks/tree-WBUGLVP5.js +11 -0
- package/dist/bundle/chunks/true-6LGCG4EY.js +1 -0
- package/dist/bundle/chunks/uniq-7PFWPNWK.js +4 -0
- package/dist/bundle/chunks/wc-GV5WUREX.js +5 -0
- package/dist/bundle/chunks/which-KHFYPBWW.js +2 -0
- package/dist/bundle/chunks/xargs-7KV5F66T.js +3 -0
- package/dist/bundle/chunks/xargs-NQBNFMCT.js +3 -0
- package/dist/bundle/index.js +1 -1
- package/dist/commands/comm/comm.d.ts +10 -0
- package/dist/commands/file/file.d.ts +7 -0
- package/dist/commands/md5sum/checksum.d.ts +7 -0
- package/dist/commands/md5sum/md5sum.d.ts +2 -0
- package/dist/commands/md5sum/sha1sum.d.ts +2 -0
- package/dist/commands/md5sum/sha256sum.d.ts +2 -0
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/sort/types.d.ts +12 -0
- package/package.json +2 -1
package/dist/bundle/ai/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"e":case"E":e+="\x1B",r+=2;break;case"c":return{output:e,stop:!0};case"0":{let s="",i=r+2;for(;i<t.length&&i<r+5&&/[0-7]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\0";else{let a=parseInt(s,8)%256;e+=String.fromCharCode(a)}r=i;break}case"x":{let s="",i=r+2;for(;i<t.length&&i<r+4&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\x",r+=2;else{let a=parseInt(s,16);e+=String.fromCharCode(a),r=i}break}case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\u",r+=2;else{let a=parseInt(s,16);e+=String.fromCodePoint(a),r=i}break}case"U":{let s="",i=r+2;for(;i<t.length&&i<r+10&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\U",r+=2;else{let a=parseInt(s,16);try{e+=String.fromCodePoint(a)}catch{e+=`\\U${s}`}r=i}break}default:e+=`\\${n}`,r+=2}}else e+=t[r],r++;return{output:e,stop:!1}}var
|
|
3
|
-
`),{stdout:i,stderr:"",exitCode:0}}}});function
|
|
1
|
+
var Tu=Object.create;var bn=Object.defineProperty;var Du=Object.getOwnPropertyDescriptor;var Lu=Object.getOwnPropertyNames;var Mu=Object.getPrototypeOf,_u=Object.prototype.hasOwnProperty;var Sn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var C=(t,e)=>()=>(t&&(e=t(t=0)),e);var Et=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),R=(t,e)=>{for(var r in e)bn(t,r,{get:e[r],enumerable:!0})},Bu=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Lu(e))!_u.call(t,s)&&s!==r&&bn(t,s,{get:()=>e[s],enumerable:!(n=Du(e,s))||n.enumerable});return t};var di=(t,e,r)=>(r=t!=null?Tu(Mu(t)):{},Bu(e||!t||!t.__esModule?bn(r,"default",{value:t,enumerable:!0}):r,t));var hi={};R(hi,{echoCommand:()=>Uu});function Wu(t){let e="",r=0;for(;r<t.length;)if(t[r]==="\\"){if(r+1>=t.length){e+="\\";break}let n=t[r+1];switch(n){case"\\":e+="\\",r+=2;break;case"n":e+=`
|
|
2
|
+
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"e":case"E":e+="\x1B",r+=2;break;case"c":return{output:e,stop:!0};case"0":{let s="",i=r+2;for(;i<t.length&&i<r+5&&/[0-7]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\0";else{let a=parseInt(s,8)%256;e+=String.fromCharCode(a)}r=i;break}case"x":{let s="",i=r+2;for(;i<t.length&&i<r+4&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\x",r+=2;else{let a=parseInt(s,16);e+=String.fromCharCode(a),r=i}break}case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\u",r+=2;else{let a=parseInt(s,16);e+=String.fromCodePoint(a),r=i}break}case"U":{let s="",i=r+2;for(;i<t.length&&i<r+10&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;if(s.length===0)e+="\\U",r+=2;else{let a=parseInt(s,16);try{e+=String.fromCodePoint(a)}catch{e+=`\\U${s}`}r=i}break}default:e+=`\\${n}`,r+=2}}else e+=t[r],r++;return{output:e,stop:!1}}var Uu,pi=C(()=>{"use strict";Uu={name:"echo",async execute(t,e){let r=!1,n=!1,s=0;for(;s<t.length;){let a=t[s];if(a==="-n")r=!0,s++;else if(a==="-e")n=!0,s++;else if(a==="-E")n=!1,s++;else if(a==="-ne"||a==="-en")r=!0,n=!0,s++;else break}let i=t.slice(s).join(" ");if(n){let a=Wu(i);if(i=a.output,a.stop)return{stdout:i,stderr:"",exitCode:0}}return r||(i+=`
|
|
3
|
+
`),{stdout:i,stderr:"",exitCode:0}}}});function k(t){let e=`${t.name} - ${t.summary}
|
|
4
4
|
|
|
5
5
|
`;if(e+=`Usage: ${t.usage}
|
|
6
6
|
`,t.description){if(e+=`
|
|
@@ -19,149 +19,149 @@ Examples:
|
|
|
19
19
|
`}if(t.notes&&t.notes.length>0){e+=`
|
|
20
20
|
Notes:
|
|
21
21
|
`;for(let r of t.notes)e+=` ${r}
|
|
22
|
-
`}return{stdout:e,stderr:"",exitCode:0}}function
|
|
22
|
+
`}return{stdout:e,stderr:"",exitCode:0}}function v(t){return t.includes("--help")}function T(t,e){return{stdout:"",stderr:e.startsWith("--")?`${t}: unrecognized option '${e}'
|
|
23
23
|
`:`${t}: invalid option -- '${e.replace(/^-/,"")}'
|
|
24
|
-
`,exitCode:1}}var
|
|
25
|
-
`,exitCode:1}};d=e[++
|
|
26
|
-
`,exitCode:1}};i[p]=
|
|
27
|
-
`,
|
|
24
|
+
`,exitCode:1}}var M=C(()=>{"use strict"});function j(t,e,r){let n=new Map,s=new Map;for(let[l,c]of Object.entries(r)){let u={name:l,type:c.type};c.short&&n.set(c.short,u),c.long&&s.set(c.long,u)}let i={};for(let[l,c]of Object.entries(r))c.default!==void 0?i[l]=c.default:c.type==="boolean"&&(i[l]=!1);let a=[],o=!1;for(let l=0;l<e.length;l++){let c=e[l];if(o||!c.startsWith("-")||c==="-"){a.push(c);continue}if(c==="--"){o=!0;continue}if(c.startsWith("--")){let u=c.indexOf("="),f,d;u!==-1?(f=c.slice(2,u),d=c.slice(u+1)):f=c.slice(2);let h=s.get(f);if(!h)return{ok:!1,error:T(t,c)};let{name:p,type:w}=h;if(w==="boolean")i[p]=!0;else{if(d===void 0){if(l+1>=e.length)return{ok:!1,error:{stdout:"",stderr:`${t}: option '--${f}' requires an argument
|
|
25
|
+
`,exitCode:1}};d=e[++l]}i[p]=w==="number"?parseInt(d,10):d}}else{let u=c.slice(1);for(let f=0;f<u.length;f++){let d=u[f],h=n.get(d);if(!h)return{ok:!1,error:T(t,`-${d}`)};let{name:p,type:w}=h;if(w==="boolean")i[p]=!0;else{let x;if(f+1<u.length)x=u.slice(f+1);else if(l+1<e.length)x=e[++l];else return{ok:!1,error:{stdout:"",stderr:`${t}: option requires an argument -- '${d}'
|
|
26
|
+
`,exitCode:1}};i[p]=w==="number"?parseInt(x,10):x;break}}}}return{ok:!0,result:{flags:i,positional:a}}}var ue=C(()=>{"use strict";M()});async function Ht(t,e,r){let{cmdName:n,allowStdinMarker:s=!0,stopOnError:i=!1}=r;if(e.length===0)return{files:[{filename:"",content:t.stdin}],stderr:"",exitCode:0};let a=[],o="",l=0;for(let c of e){if(s&&c==="-"){a.push({filename:"-",content:t.stdin});continue}try{let u=t.fs.resolvePath(t.cwd,c),f=await t.fs.readFile(u);a.push({filename:c,content:f})}catch{if(o+=`${n}: ${c}: No such file or directory
|
|
27
|
+
`,l=1,i)return{files:a,stderr:o,exitCode:l}}}return{files:a,stderr:o,exitCode:l}}async function bt(t,e,r){let n=await Ht(t,e,{...r,stopOnError:!0});return n.exitCode!==0?{ok:!1,error:{stdout:"",stderr:n.stderr,exitCode:n.exitCode}}:{ok:!0,content:n.files.map(i=>i.content).join("")}}var St=C(()=>{"use strict"});var mi={};R(mi,{catCommand:()=>ju});function Gu(t,e){let r=t.split(`
|
|
28
28
|
`),n=t.endsWith(`
|
|
29
29
|
`),s=n?r.slice(0,-1):r;return{content:s.map((a,o)=>`${String(e+o).padStart(6," ")} ${a}`).join(`
|
|
30
30
|
`)+(n?`
|
|
31
|
-
`:""),nextLineNumber:e+s.length}}var
|
|
32
|
-
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"\\":e+="\\",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"e":case"E":e+="\x1B",r+=2;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let s="",i=r+1;for(;i<t.length&&i<r+4&&/[0-7]/.test(t[i]);)s+=t[i],i++;e+=String.fromCharCode(parseInt(s,8)),r=i;break}case"x":r+3<t.length&&/[0-9a-fA-F]{2}/.test(t.slice(r+2,r+4))?(e+=String.fromCharCode(parseInt(t.slice(r+2,r+4),16)),r+=4):(e+=t[r],r++);break;case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\u",r+=2);break}case"U":{let s="",i=r+2;for(;i<t.length&&i<r+10&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\U",r+=2);break}default:e+=t[r],r++}else e+=t[r],r++;return e}var
|
|
33
|
-
`),{value:
|
|
34
|
-
`),{value:
|
|
35
|
-
`);let a=i<0?i>>>0:i;return{value:
|
|
36
|
-
`),{value:
|
|
37
|
-
`}}}}function
|
|
38
|
-
`?n+="\\n":s===" "?n+="\\t":s==="\r"?n+="\\r":s==="\x07"?n+="\\a":s==="\b"?n+="\\b":s==="\f"?n+="\\f":s==="\v"?n+="\\v":s==="\x1B"?n+="\\E":i<32||i>126?n+=`\\x${i.toString(16).padStart(2,"0")}`:s==='"'?n+='\\"':n+=s}return n+="'",n}let r="";for(let n of t)" |&;<>()$`\\\"'*?[#~=%!{}".includes(n)?r+=`\\${n}`:r+=n;return r}function
|
|
39
|
-
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"\\":e+="\\",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"c":return{value:e,stopped:!0};case"x":{let s="",i=r+2;for(;i<t.length&&i<r+4&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCharCode(parseInt(s,16)),r=i):(e+="\\x",r+=2);break}case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\u",r+=2);break}case"0":{let s="",i=r+2;for(;i<t.length&&i<r+5&&/[0-7]/.test(t[i]);)s+=t[i],i++;s?e+=String.fromCharCode(parseInt(s,8)):e+="\0",r=i;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let s="",i=r+1;for(;i<t.length&&i<r+4&&/[0-7]/.test(t[i]);)s+=t[i],i++;e+=String.fromCharCode(parseInt(s,8)),r=i;break}default:e+=t[r],r++}else e+=t[r],r++;return{value:e,stopped:!1}}var
|
|
31
|
+
`:""),nextLineNumber:e+s.length}}var zu,Hu,ju,gi=C(()=>{"use strict";ue();St();M();zu={name:"cat",summary:"concatenate files and print on the standard output",usage:"cat [OPTION]... [FILE]...",options:["-n, --number number all output lines"," --help display this help and exit"]},Hu={number:{short:"n",long:"number",type:"boolean"}},ju={name:"cat",async execute(t,e){if(v(t))return k(zu);let r=j("cat",t,Hu);if(!r.ok)return r.error;let n=r.result.flags.number,s=r.result.positional,i=await Ht(e,s,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),a="",o=1;for(let{content:l}of i.files)if(n){let c=Gu(l,o);a+=c.content,o=c.nextLineNumber}else a+=l;return{stdout:a,stderr:i.stderr,exitCode:i.exitCode}}}});function te(t){return t instanceof Error?t.message:String(t)}var Me=C(()=>{"use strict"});function hr(t,e,r){let n=t;r>=0&&n.length>r&&(n=n.slice(0,r));let s=Math.abs(e);return s>n.length&&(e<0?n=n.padEnd(s," "):n=n.padStart(s," ")),n}function xi(t,e){let r=e,n=0,s=-1,i=!1;for(r<t.length&&t[r]==="-"&&(i=!0,r++);r<t.length&&/\d/.test(t[r]);)n=n*10+parseInt(t[r],10),r++;if(r<t.length&&t[r]===".")for(r++,s=0;r<t.length&&/\d/.test(t[r]);)s=s*10+parseInt(t[r],10),r++;return i&&n>0&&(n=-n),[n,s,r-e]}function pr(t){let e="",r=0;for(;r<t.length;)if(t[r]==="\\"&&r+1<t.length)switch(t[r+1]){case"n":e+=`
|
|
32
|
+
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"\\":e+="\\",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"e":case"E":e+="\x1B",r+=2;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let s="",i=r+1;for(;i<t.length&&i<r+4&&/[0-7]/.test(t[i]);)s+=t[i],i++;e+=String.fromCharCode(parseInt(s,8)),r=i;break}case"x":r+3<t.length&&/[0-9a-fA-F]{2}/.test(t.slice(r+2,r+4))?(e+=String.fromCharCode(parseInt(t.slice(r+2,r+4),16)),r+=4):(e+=t[r],r++);break;case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\u",r+=2);break}case"U":{let s="",i=r+2;for(;i<t.length&&i<r+10&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\U",r+=2);break}default:e+=t[r],r++}else e+=t[r],r++;return e}var Cn=C(()=>{"use strict"});var wi={};R(wi,{printfCommand:()=>Vu});import{sprintf as Ct}from"sprintf-js";function Zu(t,e,r){let n="",s=0,i=0,a=!1,o="";for(;s<t.length;)if(t[s]==="%"&&s+1<t.length){let l=s;if(s++,t[s]==="%"){n+="%",s++;continue}for(;s<t.length&&"+-0 #'".includes(t[s]);)s++;let c=!1;if(t[s]==="*")c=!0,s++;else for(;s<t.length&&/\d/.test(t[s]);)s++;let u=!1;if(t[s]===".")if(s++,t[s]==="*")u=!0,s++;else for(;s<t.length&&/\d/.test(t[s]);)s++;s<t.length&&"hlL".includes(t[s])&&s++;let f=t[s]||"";s++;let h=t.slice(l,s);if(c){let b=parseInt(e[r+i]||"0",10);i++,h=h.replace("*",String(b))}if(u){let b=parseInt(e[r+i]||"0",10);i++,h=h.replace(".*",`.${b}`)}let p=e[r+i]||"";i++;let{value:w,parseError:x,parseErrMsg:y,stopped:E}=Qu(h,f,p);if(n+=w,x&&(a=!0,y&&(o=y)),E)return{result:n,argsConsumed:i,error:a,errMsg:o,stopped:!0}}else n+=t[s],s++;return{result:n,argsConsumed:i,error:a,errMsg:o,stopped:!1}}function Qu(t,e,r){let n=!1,s="";switch(e){case"d":case"i":{let i=mr(r);return n=_e,n&&(s=`printf: ${r}: invalid number
|
|
33
|
+
`),{value:yi(t,i),parseError:n,parseErrMsg:s}}case"o":{let i=mr(r);return n=_e,n&&(s=`printf: ${r}: invalid number
|
|
34
|
+
`),{value:Xu(t,i),parseError:n,parseErrMsg:s}}case"u":{let i=mr(r);n=_e,n&&(s=`printf: ${r}: invalid number
|
|
35
|
+
`);let a=i<0?i>>>0:i;return{value:yi(t.replace("u","d"),a),parseError:n,parseErrMsg:s}}case"x":case"X":{let i=mr(r);return n=_e,n&&(s=`printf: ${r}: invalid number
|
|
36
|
+
`),{value:Ku(t,i),parseError:n,parseErrMsg:s}}case"e":case"E":case"f":case"F":case"g":case"G":{let i=parseFloat(r)||0;return{value:tf(t,e,i),parseError:!1,parseErrMsg:""}}case"c":return{value:r.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:Yu(t,r),parseError:!1,parseErrMsg:""};case"q":return{value:ef(t,r),parseError:!1,parseErrMsg:""};case"b":{let i=rf(r);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:Ct(t,r),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
|
|
37
|
+
`}}}}function mr(t){_e=!1;let e=t.trimStart(),r=e!==e.trimEnd();if(t=e.trimEnd(),t.startsWith("'")&&t.length>=2||t.startsWith('"')&&t.length>=2)return t.charCodeAt(1);if(t.startsWith("\\'")&&t.length>=3||t.startsWith('\\"')&&t.length>=3)return t.charCodeAt(2);if(t.startsWith("+")&&(t=t.slice(1)),t.startsWith("0x")||t.startsWith("0X")){let n=parseInt(t,16);return Number.isNaN(n)?(_e=!0,0):(r&&(_e=!0),n)}if(t.startsWith("0")&&t.length>1&&/^-?0[0-7]+$/.test(t))return r&&(_e=!0),parseInt(t,8)||0;if(/^\d+#/.test(t)){_e=!0;let n=t.match(/^(\d+)#/);return n?parseInt(n[1],10):0}if(t!==""&&!/^-?\d+$/.test(t)){_e=!0;let n=parseInt(t,10);return Number.isNaN(n)?0:n}return r&&(_e=!0),parseInt(t,10)||0}function yi(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!r)return Ct(t.replace(/\.\d*/,""),e);let n=r[1]||"",s=r[2]?parseInt(r[2],10):0,i=r[3]!==void 0?r[4]?parseInt(r[4],10):0:-1,a=e<0,o=Math.abs(e),l=String(o);i>=0&&(l=l.padStart(i,"0"));let c="";a?c="-":n.includes("+")?c="+":n.includes(" ")&&(c=" ");let u=c+l;return s>u.length&&(n.includes("-")?u=u.padEnd(s," "):n.includes("0")&&i<0?u=c+l.padStart(s-c.length,"0"):u=u.padStart(s," ")),u}function Xu(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!r)return Ct(t,e);let n=r[1]||"",s=r[2]?parseInt(r[2],10):0,i=r[3]!==void 0?r[4]?parseInt(r[4],10):0:-1,a=Math.abs(e).toString(8);i>=0&&(a=a.padStart(i,"0")),n.includes("#")&&!a.startsWith("0")&&(a=`0${a}`);let o=a;return s>o.length&&(n.includes("-")?o=o.padEnd(s," "):n.includes("0")&&i<0?o=o.padStart(s,"0"):o=o.padStart(s," ")),o}function Ku(t,e){let r=t.includes("X"),n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!n)return Ct(t,e);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,a=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,o=Math.abs(e).toString(16);r&&(o=o.toUpperCase()),a>=0&&(o=o.padStart(a,"0"));let l="";s.includes("#")&&e!==0&&(l=r?"0X":"0x");let c=l+o;return i>c.length&&(s.includes("-")?c=c.padEnd(i," "):s.includes("0")&&a<0?c=l+o.padStart(i-l.length,"0"):c=c.padStart(i," ")),c}function Ju(t){if(t==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(t))return t;if(/[\x00-\x1f\x7f]/.test(t)){let n="$'";for(let s of t){let i=s.charCodeAt(0);s==="'"?n+="\\'":s==="\\"?n+="\\\\":s===`
|
|
38
|
+
`?n+="\\n":s===" "?n+="\\t":s==="\r"?n+="\\r":s==="\x07"?n+="\\a":s==="\b"?n+="\\b":s==="\f"?n+="\\f":s==="\v"?n+="\\v":s==="\x1B"?n+="\\E":i<32||i>126?n+=`\\x${i.toString(16).padStart(2,"0")}`:s==='"'?n+='\\"':n+=s}return n+="'",n}let r="";for(let n of t)" |&;<>()$`\\\"'*?[#~=%!{}".includes(n)?r+=`\\${n}`:r+=n;return r}function Yu(t,e){let r=t.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!r)return Ct(t.replace(/0+(?=\d)/,""),e);let n=r[1]==="-",s=r[2]?parseInt(r[2],10):0,i=r[3]!==void 0?r[4]?parseInt(r[4],10):0:-1,a=n?-s:s;return hr(e,a,i)}function ef(t,e){let r=Ju(e),n=t.match(/^%(-?)(\d*)q$/);if(!n)return r;let s=n[1]==="-",i=n[2]?parseInt(n[2],10):0,a=r;return i>a.length&&(s?a=a.padEnd(i," "):a=a.padStart(i," ")),a}function tf(t,e,r){let n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!n)return Ct(t,r);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,a=n[3]!==void 0?n[4]?parseInt(n[4],10):0:6,o,l=e.toLowerCase();if(l==="e"?(o=r.toExponential(a),o=o.replace(/e([+-])(\d)$/,"e$10$2"),e==="E"&&(o=o.toUpperCase())):l==="f"?(o=r.toFixed(a),s.includes("#")&&a===0&&!o.includes(".")&&(o+=".")):l==="g"?(o=r.toPrecision(a||1),s.includes("#")||(o=o.replace(/\.?0+$/,""),o=o.replace(/\.?0+e/,"e")),o=o.replace(/e([+-])(\d)$/,"e$10$2"),e==="G"&&(o=o.toUpperCase())):o=r.toString(),r>=0&&(s.includes("+")?o=`+${o}`:s.includes(" ")&&(o=` ${o}`)),i>o.length)if(s.includes("-"))o=o.padEnd(i," ");else if(s.includes("0")){let c=o.match(/^[+ -]/)?.[0]||"",u=c?o.slice(1):o;o=c+u.padStart(i-c.length,"0")}else o=o.padStart(i," ");return o}function rf(t){let e="",r=0;for(;r<t.length;)if(t[r]==="\\"&&r+1<t.length)switch(t[r+1]){case"n":e+=`
|
|
39
|
+
`,r+=2;break;case"t":e+=" ",r+=2;break;case"r":e+="\r",r+=2;break;case"\\":e+="\\",r+=2;break;case"a":e+="\x07",r+=2;break;case"b":e+="\b",r+=2;break;case"f":e+="\f",r+=2;break;case"v":e+="\v",r+=2;break;case"c":return{value:e,stopped:!0};case"x":{let s="",i=r+2;for(;i<t.length&&i<r+4&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCharCode(parseInt(s,16)),r=i):(e+="\\x",r+=2);break}case"u":{let s="",i=r+2;for(;i<t.length&&i<r+6&&/[0-9a-fA-F]/.test(t[i]);)s+=t[i],i++;s?(e+=String.fromCodePoint(parseInt(s,16)),r=i):(e+="\\u",r+=2);break}case"0":{let s="",i=r+2;for(;i<t.length&&i<r+5&&/[0-7]/.test(t[i]);)s+=t[i],i++;s?e+=String.fromCharCode(parseInt(s,8)):e+="\0",r=i;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let s="",i=r+1;for(;i<t.length&&i<r+4&&/[0-7]/.test(t[i]);)s+=t[i],i++;e+=String.fromCharCode(parseInt(s,8)),r=i;break}default:e+=t[r],r++}else e+=t[r],r++;return{value:e,stopped:!1}}var qu,Vu,_e,Ei=C(()=>{"use strict";Me();M();Cn();qu={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},Vu={name:"printf",async execute(t,e){if(v(t))return k(qu);if(t.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
40
40
|
`,exitCode:2};let r=null,n=0;for(;n<t.length;){let a=t[n];if(a==="--"){n++;break}if(a==="-v"){if(n+1>=t.length)return{stdout:"",stderr:`printf: -v: option requires an argument
|
|
41
41
|
`,exitCode:1};if(r=t[n+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[^\]]+\])?$/.test(r))return{stdout:"",stderr:`printf: \`${r}': not a valid identifier
|
|
42
42
|
`,exitCode:2};n+=2}else{if(a.startsWith("-")&&a!=="-")break;break}}if(n>=t.length)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
43
|
-
`,exitCode:1};let s=t[n],i=t.slice(n+1);try{let a=
|
|
44
|
-
`,exitCode:1}}}}
|
|
45
|
-
`,exitCode:2};if(o){let d=[];for(let h of f){let p=e.fs.resolvePath(e.cwd,h);try{let
|
|
43
|
+
`,exitCode:1};let s=t[n],i=t.slice(n+1);try{let a=pr(s),o="",l=0,c=!1,u="";do{let{result:f,argsConsumed:d,error:h,errMsg:p,stopped:w}=Zu(a,i,l);if(o+=f,l+=d,h&&(c=!0,p&&(u=p)),w)break}while(l<i.length&&l>0);return l===0&&i.length>0,r?(e.env[r]=o,{stdout:"",stderr:u,exitCode:c?1:0}):{stdout:o,stderr:u,exitCode:c?1:0}}catch(a){return{stdout:"",stderr:`printf: ${te(a)}
|
|
44
|
+
`,exitCode:1}}}};_e=!1});var Ci={};R(Ci,{lsCommand:()=>af});import{minimatch as bi}from"minimatch";function gr(t){if(t<1024)return String(t);if(t<1024*1024){let r=t/1024;return r<10?`${r.toFixed(1)}K`:`${Math.round(r)}K`}if(t<1024*1024*1024){let r=t/1048576;return r<10?`${r.toFixed(1)}M`:`${Math.round(r)}M`}let e=t/(1024*1024*1024);return e<10?`${e.toFixed(1)}G`:`${Math.round(e)}G`}function xr(t){let r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()],n=String(t.getDate()).padStart(2," "),s=new Date,i=new Date(s.getTime()-4320*60*60*1e3);if(t>i){let o=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${r} ${n} ${o}:${l}`}let a=t.getFullYear();return`${r} ${n} ${a}`}async function of(t,e,r,n,s,i=!1,a=!1,o=!1){let l=r||n,c=e.fs.getAllPaths(),u=e.fs.resolvePath(e.cwd,"."),f=[];for(let d of c){let h=d.startsWith(u)&&d.slice(u.length+1)||d;if(bi(h,t)||bi(d,t)){let p=h.split("/").pop()||h;if(!l&&p.startsWith("."))continue;f.push(h||d)}}if(f.length===0)return{stdout:"",stderr:`ls: ${t}: No such file or directory
|
|
45
|
+
`,exitCode:2};if(o){let d=[];for(let h of f){let p=e.fs.resolvePath(e.cwd,h);try{let w=await e.fs.stat(p);d.push({path:h,size:w.size??0})}catch{d.push({path:h,size:0})}}d.sort((h,p)=>p.size-h.size),f.length=0,f.push(...d.map(h=>h.path))}else f.sort();if(i&&f.reverse(),s){let d=[];for(let h of f){let p=e.fs.resolvePath(e.cwd,h);try{let w=await e.fs.stat(p),x=w.isDirectory?"drwxr-xr-x":"-rw-r--r--",y=w.isDirectory?"/":"",E=w.size??0,b=a?gr(E).padStart(5):String(E).padStart(5),S=w.mtime??new Date(0),A=xr(S);d.push(`${x} 1 user user ${b} ${A} ${h}${y}`)}catch{d.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${h}`)}}return{stdout:`${d.join(`
|
|
46
46
|
`)}
|
|
47
47
|
`,stderr:"",exitCode:0}}return{stdout:`${f.join(`
|
|
48
48
|
`)}
|
|
49
|
-
`,stderr:"",exitCode:0}}async function
|
|
49
|
+
`,stderr:"",exitCode:0}}async function Si(t,e,r,n,s,i,a,o=!1,l=!1,c=!1,u=!1){let f=r||n,d=e.fs.resolvePath(e.cwd,t);try{let h=await e.fs.stat(d);if(!h.isDirectory){if(s){let x=h.size??0,y=l?gr(x).padStart(5):String(x).padStart(5),E=h.mtime??new Date(0),b=xr(E);return{stdout:`-rw-r--r-- 1 user user ${y} ${b} ${t}
|
|
50
50
|
`,stderr:"",exitCode:0}}return{stdout:`${t}
|
|
51
|
-
`,stderr:"",exitCode:0}}let p=await e.fs.readdir(d);if(f||(p=p.filter(
|
|
52
|
-
`),s){
|
|
53
|
-
`;for(let
|
|
54
|
-
`;continue}let
|
|
55
|
-
`}catch{
|
|
56
|
-
`}}}else
|
|
51
|
+
`,stderr:"",exitCode:0}}let p=await e.fs.readdir(d);if(f||(p=p.filter(x=>!x.startsWith("."))),c){let x=[];for(let y of p){let E=d==="/"?`/${y}`:`${d}/${y}`;try{let b=await e.fs.stat(E);x.push({name:y,size:b.size??0})}catch{x.push({name:y,size:0})}}x.sort((y,E)=>E.size-y.size),p=x.map(y=>y.name)}else p.sort();r&&(p=[".","..",...p]),o&&p.reverse();let w="";if((i||a)&&(w+=`${t}:
|
|
52
|
+
`),s){w+=`total ${p.length}
|
|
53
|
+
`;for(let x of p){if(x==="."||x===".."){w+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${x}
|
|
54
|
+
`;continue}let y=d==="/"?`/${x}`:`${d}/${x}`;try{let E=await e.fs.stat(y),b=E.isDirectory?"drwxr-xr-x":"-rw-r--r--",S=E.isDirectory?"/":"",A=E.size??0,D=l?gr(A).padStart(5):String(A).padStart(5),F=E.mtime??new Date(0),P=xr(F);w+=`${b} 1 user user ${D} ${P} ${x}${S}
|
|
55
|
+
`}catch{w+=`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${x}
|
|
56
|
+
`}}}else w+=p.join(`
|
|
57
57
|
`)+(p.length?`
|
|
58
|
-
`:"");if(i)for(let
|
|
59
|
-
`;let
|
|
60
|
-
`,exitCode:2}}}var
|
|
58
|
+
`:"");if(i)for(let x of p){if(x==="."||x==="..")continue;let y=d==="/"?`/${x}`:`${d}/${x}`;try{if((await e.fs.stat(y)).isDirectory){w+=`
|
|
59
|
+
`;let b=t==="."?`./${x}`:`${t}/${x}`,S=await Si(b,e,r,n,s,i,!1,o,l,c,!0);w+=S.stdout}}catch{}}return{stdout:w,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${t}: No such file or directory
|
|
60
|
+
`,exitCode:2}}}var nf,sf,af,Ai=C(()=>{"use strict";ue();M();nf={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},sf={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},af={name:"ls",async execute(t,e){if(v(t))return k(nf);let r=j("ls",t,sf);if(!r.ok)return r.error;let n=r.result.flags.showAll,s=r.result.flags.showAlmostAll,i=r.result.flags.longFormat,a=r.result.flags.humanReadable,o=r.result.flags.recursive,l=r.result.flags.reverse,c=r.result.flags.sortBySize,u=r.result.flags.directoryOnly,f=r.result.flags.sortByTime;r.result.flags.onePerLine;let d=r.result.positional;d.length===0&&d.push(".");let h="",p="",w=0;for(let x=0;x<d.length;x++){let y=d[x];if(x>0&&h&&!h.endsWith(`
|
|
61
61
|
|
|
62
62
|
`)&&(h+=`
|
|
63
|
-
`),u){let
|
|
64
|
-
`}else h+=`${
|
|
65
|
-
`}catch{p+=`ls: cannot access '${
|
|
66
|
-
`,
|
|
67
|
-
`,exitCode:1};let a="",o="",
|
|
68
|
-
`)}catch(u){let f=
|
|
69
|
-
`:f.includes("EEXIST")||f.includes("already exists")?o+=`mkdir: cannot create directory '${
|
|
70
|
-
`:o+=`mkdir: cannot create directory '${
|
|
71
|
-
`,
|
|
72
|
-
`,exitCode:1};let n="",s=0;for(let i of r)try{let a=e.fs.resolvePath(e.cwd,i);await e.fs.exists(a)||await e.fs.writeFile(a,"")}catch(a){n+=`touch: cannot touch '${i}': ${
|
|
73
|
-
`,s=1}return{stdout:"",stderr:n,exitCode:s}}}});var
|
|
74
|
-
`,exitCode:1};let o="",
|
|
75
|
-
`,
|
|
76
|
-
`)}catch(f){if(!s){let d=
|
|
77
|
-
`:d.includes("ENOTEMPTY")||d.includes("not empty")?
|
|
78
|
-
`:
|
|
79
|
-
`,
|
|
80
|
-
`,exitCode:1};let
|
|
81
|
-
`,exitCode:1};for(let
|
|
82
|
-
`,h=1;continue}if(s)try{await e.fs.stat(
|
|
83
|
-
`)}catch(
|
|
84
|
-
`:d+=`cp: cannot copy '${
|
|
85
|
-
`,h=1}return{stdout:f,stderr:d,exitCode:h}}}});var
|
|
86
|
-
`,exitCode:1};let o=a.pop()??"",
|
|
87
|
-
`,exitCode:1};for(let p of
|
|
88
|
-
`}}catch(
|
|
89
|
-
`:f+=`mv: cannot move '${p}': ${
|
|
90
|
-
`,d=1}return{stdout:u,stderr:f,exitCode:d}}}});var
|
|
63
|
+
`),u){let E=e.fs.resolvePath(e.cwd,y);try{let b=await e.fs.stat(E);if(i){let S=b.isDirectory?"drwxr-xr-x":"-rw-r--r--",A=b.isDirectory?"/":"",D=b.size??0,F=a?gr(D).padStart(5):String(D).padStart(5),P=b.mtime??new Date(0),B=xr(P);h+=`${S} 1 user user ${F} ${B} ${y}${A}
|
|
64
|
+
`}else h+=`${y}
|
|
65
|
+
`}catch{p+=`ls: cannot access '${y}': No such file or directory
|
|
66
|
+
`,w=2}continue}if(y.includes("*")||y.includes("?")||y.includes("[")){let E=await of(y,e,n,s,i,l,a,c);h+=E.stdout,p+=E.stderr,E.exitCode!==0&&(w=E.exitCode)}else{let E=await Si(y,e,n,s,i,o,d.length>1,l,a,c);h+=E.stdout,p+=E.stderr,E.exitCode!==0&&(w=E.exitCode)}}return{stdout:h,stderr:p,exitCode:w}}}});var ki={};R(ki,{mkdirCommand:()=>cf});var lf,cf,vi=C(()=>{"use strict";Me();ue();lf={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},cf={name:"mkdir",async execute(t,e){let r=j("mkdir",t,lf);if(!r.ok)return r.error;let n=r.result.flags.recursive,s=r.result.flags.verbose,i=r.result.positional;if(i.length===0)return{stdout:"",stderr:`mkdir: missing operand
|
|
67
|
+
`,exitCode:1};let a="",o="",l=0;for(let c of i)try{let u=e.fs.resolvePath(e.cwd,c);await e.fs.mkdir(u,{recursive:n}),s&&(a+=`mkdir: created directory '${c}'
|
|
68
|
+
`)}catch(u){let f=te(u);f.includes("ENOENT")||f.includes("no such file")?o+=`mkdir: cannot create directory '${c}': No such file or directory
|
|
69
|
+
`:f.includes("EEXIST")||f.includes("already exists")?o+=`mkdir: cannot create directory '${c}': File exists
|
|
70
|
+
`:o+=`mkdir: cannot create directory '${c}': ${f}
|
|
71
|
+
`,l=1}return{stdout:a,stderr:o,exitCode:l}}}});var Ni={};R(Ni,{touchCommand:()=>uf});var uf,Ii=C(()=>{"use strict";Me();M();uf={name:"touch",async execute(t,e){let r=[];for(let i of t){if(i.startsWith("--"))return T("touch",i);if(i.startsWith("-")&&i.length>1)return T("touch",i);r.push(i)}if(r.length===0)return{stdout:"",stderr:`touch: missing file operand
|
|
72
|
+
`,exitCode:1};let n="",s=0;for(let i of r)try{let a=e.fs.resolvePath(e.cwd,i);await e.fs.exists(a)||await e.fs.writeFile(a,"")}catch(a){n+=`touch: cannot touch '${i}': ${te(a)}
|
|
73
|
+
`,s=1}return{stdout:"",stderr:n,exitCode:s}}}});var Ri={};R(Ri,{rmCommand:()=>df});var ff,df,$i=C(()=>{"use strict";Me();ue();ff={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},df={name:"rm",async execute(t,e){let r=j("rm",t,ff);if(!r.ok)return r.error;let n=r.result.flags.recursive||r.result.flags.recursiveUpper,s=r.result.flags.force,i=r.result.flags.verbose,a=r.result.positional;if(a.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
|
|
74
|
+
`,exitCode:1};let o="",l="",c=0;for(let u of a)try{let f=e.fs.resolvePath(e.cwd,u);if((await e.fs.stat(f)).isDirectory&&!n){l+=`rm: cannot remove '${u}': Is a directory
|
|
75
|
+
`,c=1;continue}await e.fs.rm(f,{recursive:n,force:s}),i&&(o+=`removed '${u}'
|
|
76
|
+
`)}catch(f){if(!s){let d=te(f);d.includes("ENOENT")||d.includes("no such file")?l+=`rm: cannot remove '${u}': No such file or directory
|
|
77
|
+
`:d.includes("ENOTEMPTY")||d.includes("not empty")?l+=`rm: cannot remove '${u}': Directory not empty
|
|
78
|
+
`:l+=`rm: cannot remove '${u}': ${d}
|
|
79
|
+
`,c=1}}return{stdout:o,stderr:l,exitCode:c}}}});var Oi={};R(Oi,{cpCommand:()=>mf});var hf,pf,mf,Pi=C(()=>{"use strict";Me();ue();M();hf={name:"cp",summary:"copy files and directories",usage:"cp [OPTION]... SOURCE... DEST",options:["-r, -R, --recursive copy directories recursively","-n, --no-clobber do not overwrite an existing file","-p, --preserve preserve file attributes","-v, --verbose explain what is being done"," --help display this help and exit"]},pf={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},preserve:{short:"p",long:"preserve",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},mf={name:"cp",async execute(t,e){if(v(t))return k(hf);let r=j("cp",t,pf);if(!r.ok)return r.error;let n=r.result.flags.recursive||r.result.flags.recursiveUpper,s=r.result.flags.noClobber,i=r.result.flags.preserve,a=r.result.flags.verbose,o=r.result.positional;if(o.length<2)return{stdout:"",stderr:`cp: missing destination file operand
|
|
80
|
+
`,exitCode:1};let l=o.pop()??"",c=o,u=e.fs.resolvePath(e.cwd,l),f="",d="",h=0,p=!1;try{p=(await e.fs.stat(u)).isDirectory}catch{}if(c.length>1&&!p)return{stdout:"",stderr:`cp: target '${l}' is not a directory
|
|
81
|
+
`,exitCode:1};for(let w of c)try{let x=e.fs.resolvePath(e.cwd,w),y=await e.fs.stat(x),E=u;if(p){let b=w.split("/").pop()||w;E=u==="/"?`/${b}`:`${u}/${b}`}if(y.isDirectory&&!n){d+=`cp: -r not specified; omitting directory '${w}'
|
|
82
|
+
`,h=1;continue}if(s)try{await e.fs.stat(E);continue}catch{}await e.fs.cp(x,E,{recursive:n}),a&&(f+=`'${w}' -> '${E}'
|
|
83
|
+
`)}catch(x){let y=te(x);y.includes("ENOENT")||y.includes("no such file")?d+=`cp: cannot stat '${w}': No such file or directory
|
|
84
|
+
`:d+=`cp: cannot copy '${w}': ${y}
|
|
85
|
+
`,h=1}return{stdout:f,stderr:d,exitCode:h}}}});var Fi={};R(Fi,{mvCommand:()=>yf});var gf,xf,yf,Ti=C(()=>{"use strict";Me();ue();M();gf={name:"mv",summary:"move (rename) files",usage:"mv [OPTION]... SOURCE... DEST",options:["-f, --force do not prompt before overwriting","-n, --no-clobber do not overwrite an existing file","-v, --verbose explain what is being done"," --help display this help and exit"]},xf={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},yf={name:"mv",async execute(t,e){if(v(t))return k(gf);let r=j("mv",t,xf);if(!r.ok)return r.error;let n=r.result.flags.force,s=r.result.flags.noClobber,i=r.result.flags.verbose,a=r.result.positional;if(s&&(n=!1),a.length<2)return{stdout:"",stderr:`mv: missing destination file operand
|
|
86
|
+
`,exitCode:1};let o=a.pop()??"",l=a,c=e.fs.resolvePath(e.cwd,o),u="",f="",d=0,h=!1;try{h=(await e.fs.stat(c)).isDirectory}catch{}if(l.length>1&&!h)return{stdout:"",stderr:`mv: target '${o}' is not a directory
|
|
87
|
+
`,exitCode:1};for(let p of l)try{let w=e.fs.resolvePath(e.cwd,p),x=c;if(h){let y=p.split("/").pop()||p;x=c==="/"?`/${y}`:`${c}/${y}`}if(s)try{await e.fs.stat(x);continue}catch{}if(await e.fs.mv(w,x),i){let y=h?`${o}/${p.split("/").pop()||p}`:o;u+=`renamed '${p}' -> '${y}'
|
|
88
|
+
`}}catch(w){let x=te(w);x.includes("ENOENT")||x.includes("no such file")?f+=`mv: cannot stat '${p}': No such file or directory
|
|
89
|
+
`:f+=`mv: cannot move '${p}': ${x}
|
|
90
|
+
`,d=1}return{stdout:u,stderr:f,exitCode:d}}}});var Di={};R(Di,{lnCommand:()=>Ef});var wf,Ef,Li=C(()=>{"use strict";M();wf={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},Ef={name:"ln",async execute(t,e){if(v(t))return k(wf);let r=!1,n=!1,s=!1,i=0;for(;i<t.length&&t[i].startsWith("-");){let f=t[i];if(f==="-s"||f==="--symbolic")r=!0,i++;else if(f==="-f"||f==="--force")n=!0,i++;else if(f==="-v"||f==="--verbose")s=!0,i++;else if(f==="-n"||f==="--no-dereference")i++;else if(/^-[sfvn]+$/.test(f))f.includes("s")&&(r=!0),f.includes("f")&&(n=!0),f.includes("v")&&(s=!0),i++;else if(f==="--"){i++;break}else return{stdout:"",stderr:`ln: invalid option -- '${f.slice(1)}'
|
|
91
91
|
`,exitCode:1}}let a=t.slice(i);if(a.length<2)return{stdout:"",stderr:`ln: missing file operand
|
|
92
|
-
`,exitCode:1};let o=a[0],
|
|
93
|
-
`,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${r?"symbolic ":""}link '${
|
|
94
|
-
`,exitCode:1};try{if(r)await e.fs.symlink(o,
|
|
95
|
-
`,exitCode:1};await e.fs.link(f,
|
|
92
|
+
`,exitCode:1};let o=a[0],l=a[1],c=e.fs.resolvePath(e.cwd,l);if(await e.fs.exists(c))if(n)try{await e.fs.rm(c,{force:!0})}catch{return{stdout:"",stderr:`ln: cannot remove '${l}': Permission denied
|
|
93
|
+
`,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${r?"symbolic ":""}link '${l}': File exists
|
|
94
|
+
`,exitCode:1};try{if(r)await e.fs.symlink(o,c);else{let f=e.fs.resolvePath(e.cwd,o);if(!await e.fs.exists(f))return{stdout:"",stderr:`ln: failed to access '${o}': No such file or directory
|
|
95
|
+
`,exitCode:1};await e.fs.link(f,c)}}catch(f){let d=f;return d.message.includes("EPERM")?{stdout:"",stderr:`ln: '${o}': hard link not allowed for directory
|
|
96
96
|
`,exitCode:1}:{stdout:"",stderr:`ln: ${d.message}
|
|
97
|
-
`,exitCode:1}}let u="";return s&&(u=`'${
|
|
98
|
-
`),{stdout:u,stderr:"",exitCode:0}}}});var
|
|
99
|
-
`),(await t.fs.stat(o)).isDirectory&&(s+=await
|
|
97
|
+
`,exitCode:1}}let u="";return s&&(u=`'${l}' -> '${o}'
|
|
98
|
+
`),{stdout:u,stderr:"",exitCode:0}}}});var _i={};R(_i,{chmodCommand:()=>Sf});async function Mi(t,e,r,n){let s="",i=await t.fs.readdir(e);for(let a of i){let o=e==="/"?`/${a}`:`${e}/${a}`;await t.fs.chmod(o,r),n&&(s+=`mode of '${o}' changed to ${r.toString(8).padStart(4,"0")}
|
|
99
|
+
`),(await t.fs.stat(o)).isDirectory&&(s+=await Mi(t,o,r,n))}return s}function Cf(t){if(/^[0-7]+$/.test(t))return parseInt(t,8);let e=420,r=t.split(",");for(let n of r){let s=n.match(/^([ugoa]*)([+\-=])([rwxXst]*)$/);if(!s)throw new Error(`Invalid mode: ${t}`);let i=s[1]||"a",a=s[2],o=s[3];(i==="a"||i==="")&&(i="ugo");let l=0;o.includes("r")&&(l|=4),o.includes("w")&&(l|=2),(o.includes("x")||o.includes("X"))&&(l|=1);for(let c of i){let u=0;c==="u"?u=6:c==="g"?u=3:c==="o"&&(u=0);let f=l<<u;a==="+"?e|=f:a==="-"?e&=~f:a==="="&&(e&=~(7<<u),e|=f)}}return e}var bf,Sf,Bi=C(()=>{"use strict";M();bf={name:"chmod",summary:"change file mode bits",usage:"chmod [OPTIONS] MODE FILE...",options:["-R change files recursively","-v output a diagnostic for every file processed"," --help display this help and exit"]},Sf={name:"chmod",async execute(t,e){if(v(t))return k(bf);if(t.length<2)return{stdout:"",stderr:`chmod: missing operand
|
|
100
100
|
`,exitCode:1};let r=!1,n=!1,s=0;for(;s<t.length&&t[s].startsWith("-");){let f=t[s];if(f==="-R"||f==="--recursive")r=!0,s++;else if(f==="-v"||f==="--verbose")n=!0,s++;else if(f==="--"){s++;break}else{if(/^[+-]?[rwxugo]+/.test(f)||/^\d+$/.test(f))break;if(/^-[Rv]+$/.test(f)){f.includes("R")&&(r=!0),f.includes("v")&&(n=!0),s++;continue}return{stdout:"",stderr:`chmod: invalid option -- '${f.slice(1)}'
|
|
101
101
|
`,exitCode:1}}}if(t.length-s<2)return{stdout:"",stderr:`chmod: missing operand
|
|
102
|
-
`,exitCode:1};let i=t[s],a=t.slice(s+1),o;try{o=
|
|
103
|
-
`,exitCode:1}}let
|
|
104
|
-
`),r&&(await e.fs.stat(d)).isDirectory){let p=await
|
|
105
|
-
`,u=!0}}return{stdout:
|
|
106
|
-
`,stderr:"",exitCode:0}}}});var
|
|
102
|
+
`,exitCode:1};let i=t[s],a=t.slice(s+1),o;try{o=Cf(i)}catch{return{stdout:"",stderr:`chmod: invalid mode: '${i}'
|
|
103
|
+
`,exitCode:1}}let l="",c="",u=!1;for(let f of a){let d=e.fs.resolvePath(e.cwd,f);try{if(await e.fs.chmod(d,o),n&&(l+=`mode of '${f}' changed to ${o.toString(8).padStart(4,"0")}
|
|
104
|
+
`),r&&(await e.fs.stat(d)).isDirectory){let p=await Mi(e,d,o,n);l+=p}}catch{c+=`chmod: cannot access '${f}': No such file or directory
|
|
105
|
+
`,u=!0}}return{stdout:l,stderr:c,exitCode:u?1:0}}}});var Wi={};R(Wi,{pwdCommand:()=>Af});var Af,Ui=C(()=>{"use strict";Af={name:"pwd",async execute(t,e){return{stdout:`${e.cwd}
|
|
106
|
+
`,stderr:"",exitCode:0}}}});var zi={};R(zi,{readlinkCommand:()=>vf});var kf,vf,Hi=C(()=>{"use strict";M();kf={name:"readlink",summary:"print resolved symbolic links or canonical file names",usage:"readlink [OPTIONS] FILE...",options:["-f canonicalize by following every symlink in every component of the given name recursively"," --help display this help and exit"]},vf={name:"readlink",async execute(t,e){if(v(t))return k(kf);let r=!1,n=0;for(;n<t.length&&t[n].startsWith("-");){let o=t[n];if(o==="-f"||o==="--canonicalize")r=!0,n++;else if(o==="--"){n++;break}else return{stdout:"",stderr:`readlink: invalid option -- '${o.slice(1)}'
|
|
107
107
|
`,exitCode:1}}let s=t.slice(n);if(s.length===0)return{stdout:"",stderr:`readlink: missing operand
|
|
108
|
-
`,exitCode:1};let i="",a=!1;for(let o of s){let
|
|
109
|
-
`}else{let
|
|
110
|
-
`}}catch{r?i+=`${
|
|
111
|
-
`:a=!0}}return{stdout:i,stderr:"",exitCode:a?1:0}}}});function
|
|
108
|
+
`,exitCode:1};let i="",a=!1;for(let o of s){let l=e.fs.resolvePath(e.cwd,o);try{if(r){let c=l,u=new Set;for(;!u.has(c);){u.add(c);try{let f=await e.fs.readlink(c);if(f.startsWith("/"))c=f;else{let d=c.substring(0,c.lastIndexOf("/"))||"/";c=e.fs.resolvePath(d,f)}}catch{break}}i+=`${c}
|
|
109
|
+
`}else{let c=await e.fs.readlink(l);i+=`${c}
|
|
110
|
+
`}}catch{r?i+=`${l}
|
|
111
|
+
`:a=!0}}return{stdout:i,stderr:"",exitCode:a?1:0}}}});function yr(t,e){let r=10,n=null,s=!1,i=!1,a=!1,o=[];for(let l=0;l<t.length;l++){let c=t[l];if(c==="-n"&&l+1<t.length){let u=t[++l];e==="tail"&&u.startsWith("+")?(a=!0,r=parseInt(u.slice(1),10)):r=parseInt(u,10)}else if(e==="tail"&&c.startsWith("-n+"))a=!0,r=parseInt(c.slice(3),10);else if(c.startsWith("-n"))r=parseInt(c.slice(2),10);else if(c==="-c"&&l+1<t.length)n=parseInt(t[++l],10);else if(c.startsWith("-c"))n=parseInt(c.slice(2),10);else if(c.startsWith("--bytes="))n=parseInt(c.slice(8),10);else if(c.startsWith("--lines="))r=parseInt(c.slice(8),10);else if(c==="-q"||c==="--quiet"||c==="--silent")s=!0;else if(c==="-v"||c==="--verbose")i=!0;else if(c.match(/^-\d+$/))r=parseInt(c.slice(1),10);else{if(c.startsWith("--"))return{ok:!1,error:T(e,c)};if(c.startsWith("-")&&c!=="-")return{ok:!1,error:T(e,c)};o.push(c)}}return n!==null&&(Number.isNaN(n)||n<0)?{ok:!1,error:{stdout:"",stderr:`${e}: invalid number of bytes
|
|
112
112
|
`,exitCode:1}}:Number.isNaN(r)||r<0?{ok:!1,error:{stdout:"",stderr:`${e}: invalid number of lines
|
|
113
|
-
`,exitCode:1}}:{ok:!0,options:{lines:r,bytes:n,quiet:s,verbose:i,files:o,fromLine:a}}}async function
|
|
113
|
+
`,exitCode:1}}:{ok:!0,options:{lines:r,bytes:n,quiet:s,verbose:i,files:o,fromLine:a}}}async function wr(t,e,r,n){let{quiet:s,verbose:i,files:a}=e;if(a.length===0)return{stdout:n(t.stdin),stderr:"",exitCode:0};let o="",l="",c=0,u=i||!s&&a.length>1;for(let f=0;f<a.length;f++){let d=a[f];u&&(f>0&&(o+=`
|
|
114
114
|
`),o+=`==> ${d} <==
|
|
115
|
-
`);try{let h=t.fs.resolvePath(t.cwd,d),p=await t.fs.readFile(h);o+=n(p)}catch{
|
|
116
|
-
`,
|
|
115
|
+
`);try{let h=t.fs.resolvePath(t.cwd,d),p=await t.fs.readFile(h);o+=n(p)}catch{l+=`${r}: ${d}: No such file or directory
|
|
116
|
+
`,c=1}}return{stdout:o,stderr:l,exitCode:c}}function ji(t,e,r){if(r!==null)return t.slice(0,r);if(e===0)return"";let n=0,s=0,i=t.length;for(;n<i&&s<e;){let a=t.indexOf(`
|
|
117
117
|
`,n);if(a===-1)return`${t}
|
|
118
|
-
`;s++,n=a+1}return n>0?t.slice(0,n):""}function
|
|
119
|
-
`,
|
|
118
|
+
`;s++,n=a+1}return n>0?t.slice(0,n):""}function Gi(t,e,r,n){if(r!==null)return t.slice(-r);let s=t.length;if(s===0)return"";if(n){let l=0,c=1;for(;l<s&&c<e;){let f=t.indexOf(`
|
|
119
|
+
`,l);if(f===-1)break;c++,l=f+1}let u=t.slice(l);return u.endsWith(`
|
|
120
120
|
`)?u:`${u}
|
|
121
121
|
`}if(e===0)return"";let i=s-1;t[i]===`
|
|
122
122
|
`&&i--;let a=0;for(;i>=0&&a<e;){if(t[i]===`
|
|
123
123
|
`&&(a++,a===e)){i++;break}i--}i<0&&(i=0);let o=t.slice(i);return t[s-1]===`
|
|
124
124
|
`?o:`${o}
|
|
125
|
-
`}var
|
|
126
|
-
`?(r++,s&&(n++,s=!1)):a===" "||a===" "||a==="\r"?s&&(n++,s=!1):s=!0}return s&&n++,{lines:r,words:n,chars:e}}function
|
|
127
|
-
`,stderr:"",exitCode:0}}let
|
|
128
|
-
`}return a.length>1&&(
|
|
129
|
-
`),{stdout:
|
|
130
|
-
`,exitCode:1};let i="",a="",o=!1;for(let
|
|
131
|
-
`}else{let f=u.mode.toString(8).padStart(4,"0"),d=
|
|
125
|
+
`}var An=C(()=>{"use strict";M()});var qi={};R(qi,{headCommand:()=>If});var Nf,If,Vi=C(()=>{"use strict";M();An();Nf={name:"head",summary:"output the first part of files",usage:"head [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the first NUM bytes","-n, --lines=NUM print the first NUM lines (default 10)","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},If={name:"head",async execute(t,e){if(v(t))return k(Nf);let r=yr(t,"head");if(!r.ok)return r.error;let{lines:n,bytes:s}=r.options;return wr(e,r.options,"head",i=>ji(i,n,s))}}});var Zi={};R(Zi,{tailCommand:()=>$f});var Rf,$f,Qi=C(()=>{"use strict";An();M();Rf={name:"tail",summary:"output the last part of files",usage:"tail [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the last NUM bytes","-n, --lines=NUM print the last NUM lines (default 10)","-n +NUM print starting from line NUM","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},$f={name:"tail",async execute(t,e){if(v(t))return k(Rf);let r=yr(t,"tail");if(!r.ok)return r.error;let{lines:n,bytes:s,fromLine:i}=r.options;return wr(e,r.options,"tail",a=>Gi(a,n,s,i??!1))}}});var Ki={};R(Ki,{wcCommand:()=>Ff});function Xi(t){let e=t.length,r=0,n=0,s=!1;for(let i=0;i<e;i++){let a=t[i];a===`
|
|
126
|
+
`?(r++,s&&(n++,s=!1)):a===" "||a===" "||a==="\r"?s&&(n++,s=!1):s=!0}return s&&n++,{lines:r,words:n,chars:e}}function kn(t,e,r,n,s){let i=[];e&&i.push(String(t.lines)),r&&i.push(String(t.words)),n&&i.push(String(t.chars));let a=i.join(" ");return s&&(a+=` ${s}`),a}var Of,Pf,Ff,Ji=C(()=>{"use strict";ue();St();M();Of={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes print the byte counts","-m, --chars print the character counts","-l, --lines print the newline counts","-w, --words print the word counts"," --help display this help and exit"]},Pf={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},Ff={name:"wc",async execute(t,e){if(v(t))return k(Of);let r=j("wc",t,Pf);if(!r.ok)return r.error;let{lines:n,words:s}=r.result.flags,i=r.result.flags.bytes||r.result.flags.chars,a=r.result.positional;!n&&!s&&!i&&(n=s=i=!0);let o=await Ht(e,a,{cmdName:"wc",stopOnError:!1});if(a.length===0){let d=Xi(o.files[0].content);return{stdout:`${kn(d,n,s,i,"")}
|
|
127
|
+
`,stderr:"",exitCode:0}}let l="",c=0,u=0,f=0;for(let{filename:d,content:h}of o.files){let p=Xi(h);c+=p.lines,u+=p.words,f+=p.chars,l+=`${kn(p,n,s,i,d)}
|
|
128
|
+
`}return a.length>1&&(l+=`${kn({lines:c,words:u,chars:f},n,s,i,"total")}
|
|
129
|
+
`),{stdout:l,stderr:o.stderr,exitCode:o.exitCode}}}});var ea={};R(ea,{statCommand:()=>Lf});function Yi(t,e){let r=e?"d":"-",n=[t&256?"r":"-",t&128?"w":"-",t&64?"x":"-",t&32?"r":"-",t&16?"w":"-",t&8?"x":"-",t&4?"r":"-",t&2?"w":"-",t&1?"x":"-"];return r+n.join("")}var Tf,Df,Lf,ta=C(()=>{"use strict";ue();M();Tf={name:"stat",summary:"display file or file system status",usage:"stat [OPTION]... FILE...",options:["-c FORMAT use the specified FORMAT instead of the default"," --help display this help and exit"]},Df={format:{short:"c",type:"string"}},Lf={name:"stat",async execute(t,e){if(v(t))return k(Tf);let r=j("stat",t,Df);if(!r.ok)return r.error;let n=r.result.flags.format??null,s=r.result.positional;if(s.length===0)return{stdout:"",stderr:`stat: missing operand
|
|
130
|
+
`,exitCode:1};let i="",a="",o=!1;for(let l of s){let c=e.fs.resolvePath(e.cwd,l);try{let u=await e.fs.stat(c);if(n){let f=n,d=u.mode.toString(8),h=Yi(u.mode,u.isDirectory);f=f.replace(/%n/g,l),f=f.replace(/%N/g,`'${l}'`),f=f.replace(/%s/g,String(u.size)),f=f.replace(/%F/g,u.isDirectory?"directory":"regular file"),f=f.replace(/%a/g,d),f=f.replace(/%A/g,h),f=f.replace(/%u/g,"1000"),f=f.replace(/%U/g,"user"),f=f.replace(/%g/g,"1000"),f=f.replace(/%G/g,"group"),i+=`${f}
|
|
131
|
+
`}else{let f=u.mode.toString(8).padStart(4,"0"),d=Yi(u.mode,u.isDirectory);i+=` File: ${l}
|
|
132
132
|
`,i+=` Size: ${u.size} Blocks: ${Math.ceil(u.size/512)}
|
|
133
133
|
`,i+=`Access: (${f}/${d})
|
|
134
134
|
`,i+=`Modify: ${u.mtime.toISOString()}
|
|
135
|
-
`}}catch{a+=`stat: cannot stat '${
|
|
136
|
-
`,o=!0}}return{stdout:i,stderr:a,exitCode:o?1:0}}}});function
|
|
137
|
-
`),f=u.length,d=f>0&&u[f-1]===""?f-1:f;if(s){let
|
|
138
|
-
`,matched:
|
|
135
|
+
`}}catch{a+=`stat: cannot stat '${l}': No such file or directory
|
|
136
|
+
`,o=!0}}return{stdout:i,stderr:a,exitCode:o?1:0}}}});function Ie(t,e,r){let n=typeof r=="boolean"?{ignoreCase:r}:r??{},s=e;n.stripQuotes&&(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"))&&(s=s.slice(1,-1));let i=n.ignoreCase?`i:${s}`:s,a=ra.get(i);return a||(a=Mf(s,n.ignoreCase),ra.set(i,a)),a.test(t)}function Mf(t,e){let r="^";for(let n=0;n<t.length;n++){let s=t[n];if(s==="*")r+=".*";else if(s==="?")r+=".";else if(s==="["){let i=n+1;for(;i<t.length&&t[i]!=="]";)i++;r+=t.slice(n,i+1),n=i}else s==="."||s==="+"||s==="^"||s==="$"||s==="{"||s==="}"||s==="("||s===")"||s==="|"||s==="\\"?r+=`\\${s}`:r+=s}return r+="$",new RegExp(r,e?"i":"")}var ra,vn=C(()=>{"use strict";ra=new Map});var Er={};R(Er,{egrepCommand:()=>zf,fgrepCommand:()=>Uf,grepCommand:()=>In});function Bf(t){let e="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){let s=t[r+1];if(s==="|"||s==="("||s===")"){e+=s,r+=2;continue}else if(s==="{"||s==="}"){e+=`\\${s}`,r+=2;continue}}n==="+"||n==="?"||n==="|"||n==="("||n===")"||n==="{"||n==="}"?e+=`\\${n}`:e+=n,r++}return e}function na(t,e,r,n,s,i,a=!1,o=0,l=0,c=0){let u=t.split(`
|
|
137
|
+
`),f=u.length,d=f>0&&u[f-1]===""?f-1:f;if(s){let y=0;for(let b=0;b<d;b++)e.lastIndex=0,e.test(u[b])!==r&&y++;return{output:`${i?`${i}:${y}`:String(y)}
|
|
138
|
+
`,matched:y>0}}if(o===0&&l===0){let y=[],E=!1,b=0;for(let S=0;S<d&&!(c>0&&b>=c);S++){let A=u[S];if(e.lastIndex=0,e.test(A)!==r)if(E=!0,b++,a){e.lastIndex=0;for(let F=e.exec(A);F!==null;F=e.exec(A))y.push(i?`${i}:${F[0]}`:F[0]),F[0].length===0&&e.lastIndex++}else n?y.push(i?`${i}:${S+1}:${A}`:`${S+1}:${A}`):y.push(i?`${i}:${A}`:A)}return{output:y.length>0?`${y.join(`
|
|
139
139
|
`)}
|
|
140
|
-
`:"",matched:
|
|
140
|
+
`:"",matched:E}}let h=[],p=0,w=new Set,x=[];for(let y=0;y<d&&!(c>0&&p>=c);y++)e.lastIndex=0,e.test(u[y])!==r&&(x.push(y),p++);for(let y of x){for(let b=Math.max(0,y-o);b<y;b++)if(!w.has(b)){w.add(b);let S=u[b];n&&(S=`${b+1}-${S}`),i&&(S=`${i}-${S}`),h.push(S)}if(!w.has(y)){w.add(y);let b=u[y];if(a){e.lastIndex=0;for(let S=e.exec(b);S!==null;S=e.exec(b))h.push(i?`${i}:${S[0]}`:S[0]),S[0].length===0&&e.lastIndex++}else{let S=b;n&&(S=`${y+1}:${S}`),i&&(S=`${i}:${S}`),h.push(S)}}let E=Math.min(d-1,y+l);for(let b=y+1;b<=E;b++)if(!w.has(b)){w.add(b);let S=u[b];n&&(S=`${b+1}-${S}`),i&&(S=`${i}-${S}`),h.push(S)}}return{output:h.length>0?`${h.join(`
|
|
141
141
|
`)}
|
|
142
|
-
`:"",matched:p>0}}async function
|
|
143
|
-
`,exitCode:2};let
|
|
144
|
-
`,exitCode:2}}if(
|
|
145
|
-
`,exitCode:2};let
|
|
146
|
-
`);continue}let
|
|
147
|
-
`:o||(
|
|
148
|
-
`:i&&!a&&(
|
|
149
|
-
`,
|
|
150
|
-
`),this.varName=e}},
|
|
151
|
-
`}},
|
|
152
|
-
`}},
|
|
153
|
-
`}},
|
|
142
|
+
`:"",matched:p>0}}async function Nn(t,e,r=[],n=[],s=[]){let i=e.fs.resolvePath(e.cwd,t),a=[];try{if(!(await e.fs.stat(i)).isDirectory){let u=t.split("/").pop()||t;return n.length>0&&n.some(f=>Ie(u,f,{stripQuotes:!0}))?[]:r.length>0&&!r.some(f=>Ie(u,f,{stripQuotes:!0}))?[]:[t]}let l=t.split("/").pop()||t;if(s.length>0&&s.some(u=>Ie(l,u,{stripQuotes:!0})))return[];let c=await e.fs.readdir(i);for(let u of c){if(u.startsWith("."))continue;let f=t==="."?u:`${t}/${u}`,d=await Nn(f,e,r,n,s);a.push(...d)}}catch{}return a}async function Wf(t,e){let r=[],n=t.lastIndexOf("/"),s,i;if(n===-1?(s=e.cwd,i=t):(s=t.slice(0,n)||"/",i=t.slice(n+1)),t.includes("**")){let o=t.split("**"),l=o[0].replace(/\/$/,"")||".",c=o[1]||"";return await sa(l,c,e,r),r}let a=e.fs.resolvePath(e.cwd,s);try{let o=await e.fs.readdir(a);for(let l of o)if(Ie(l,i,{stripQuotes:!0})){let c=n===-1?l:`${s}/${l}`;r.push(c)}}catch{}return r.sort()}async function sa(t,e,r,n){let s=r.fs.resolvePath(r.cwd,t);try{if(!(await r.fs.stat(s)).isDirectory){let o=t.split("/").pop()||"";if(e){let l=e.replace(/^\//,"");Ie(o,l,{stripQuotes:!0})&&n.push(t)}return}let a=await r.fs.readdir(s);for(let o of a){let l=t==="."?o:`${t}/${o}`,c=r.fs.resolvePath(r.cwd,l);if((await r.fs.stat(c)).isDirectory)await sa(l,e,r,n);else if(e){let f=e.replace(/^\//,"");Ie(o,f,{stripQuotes:!0})&&n.push(l)}}}catch{}}var _f,In,Uf,zf,br=C(()=>{"use strict";vn();M();_f={name:"grep",summary:"print lines that match patterns",usage:"grep [OPTION]... PATTERN [FILE]...",options:["-E, --extended-regexp PATTERN is an extended regular expression","-P, --perl-regexp PATTERN is a Perl regular expression","-F, --fixed-strings PATTERN is a set of newline-separated strings","-i, --ignore-case ignore case distinctions","-v, --invert-match select non-matching lines","-w, --word-regexp match only whole words","-x, --line-regexp match only whole lines","-c, --count print only a count of matching lines","-l, --files-with-matches print only names of files with matches","-L, --files-without-match print names of files with no matches","-m NUM, --max-count=NUM stop after NUM matches","-n, --line-number print line number with output lines","-h, --no-filename suppress the file name prefix on output","-o, --only-matching show only nonempty parts of lines that match","-q, --quiet, --silent suppress all normal output","-r, -R, --recursive search directories recursively","-A NUM print NUM lines of trailing context","-B NUM print NUM lines of leading context","-C NUM print NUM lines of context","-e PATTERN use PATTERN for matching"," --include=GLOB search only files matching GLOB"," --exclude=GLOB skip files matching GLOB"," --exclude-dir=DIR skip directories matching DIR"," --help display this help and exit"]},In={name:"grep",async execute(t,e){if(v(t))return k(_f);let r=!1,n=!1,s=!1,i=!1,a=!1,o=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,p=!1,w=!1,x=!1,y=0,E=0,b=0,S=[],A=[],D=[],F=null,P=[];for(let W=0;W<t.length;W++){let U=t[W];if(U.startsWith("-")&&U!=="-"){if(U==="-e"&&W+1<t.length){F=t[++W];continue}if(U.startsWith("--include=")){S.push(U.slice(10));continue}if(U.startsWith("--exclude=")){A.push(U.slice(10));continue}if(U.startsWith("--exclude-dir=")){D.push(U.slice(14));continue}if(U.startsWith("--max-count=")){y=parseInt(U.slice(12),10);continue}let Ce=U.match(/^-m(\d+)$/);if(Ce){y=parseInt(Ce[1],10);continue}if(U==="-m"&&W+1<t.length){y=parseInt(t[++W],10);continue}let Le=U.match(/^-([ABC])(\d+)$/);if(Le){let L=parseInt(Le[2],10);Le[1]==="A"?b=L:Le[1]==="B"?E=L:Le[1]==="C"&&(E=L,b=L);continue}if((U==="-A"||U==="-B"||U==="-C")&&W+1<t.length){let L=parseInt(t[++W],10);U==="-A"?b=L:U==="-B"?E=L:(E=L,b=L);continue}let En=U.startsWith("--")?[U]:U.slice(1).split("");for(let L of En)if(L==="i"||L==="--ignore-case")r=!0;else if(L==="n"||L==="--line-number")n=!0;else if(L==="v"||L==="--invert-match")s=!0;else if(L==="c"||L==="--count")i=!0;else if(L==="l"||L==="--files-with-matches")a=!0;else if(L==="L"||L==="--files-without-match")o=!0;else if(L==="r"||L==="R"||L==="--recursive")l=!0;else if(L==="w"||L==="--word-regexp")c=!0;else if(L==="x"||L==="--line-regexp")u=!0;else if(L==="E"||L==="--extended-regexp")f=!0;else if(L==="P"||L==="--perl-regexp")d=!0;else if(L==="F"||L==="--fixed-strings")h=!0;else if(L==="o"||L==="--only-matching")p=!0;else if(L==="h"||L==="--no-filename")w=!0;else if(L==="q"||L==="--quiet"||L==="--silent")x=!0;else{if(L.startsWith("--"))return T("grep",L);if(L.length===1)return T("grep",`-${L}`)}}else F===null?F=U:P.push(U)}if(F===null)return{stdout:"",stderr:`grep: missing pattern
|
|
143
|
+
`,exitCode:2};let B;h?B=F.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):f||d?B=F:B=Bf(F),c&&(B=`\\b${B}\\b`),u&&(B=`^${B}$`);let ee;try{ee=new RegExp(B,r?"gi":"g")}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${F}
|
|
144
|
+
`,exitCode:2}}if(P.length===0&&e.stdin){let W=na(e.stdin,ee,s,n,i,"",p,E,b,y);return x?{stdout:"",stderr:"",exitCode:W.matched?0:1}:{stdout:W.output,stderr:"",exitCode:W.matched?0:1}}if(P.length===0)return{stdout:"",stderr:`grep: no input files
|
|
145
|
+
`,exitCode:2};let de="",ne="",Se=!1,Ue=!1,Te=[];for(let W of P)if(W.includes("*")||W.includes("?")||W.includes("[")){let U=await Wf(W,e);if(l)for(let Ce of U){let Le=await Nn(Ce,e,S,A,D);Te.push(...Le)}else Te.push(...U)}else if(l){let U=await Nn(W,e,S,A,D);Te.push(...U)}else Te.push(W);let dr=(Te.length>1||l)&&!w;for(let W of Te){let U=W.split("/").pop()||W;if(!(A.length>0&&!l&&A.some(Ce=>Ie(U,Ce,{stripQuotes:!0})))&&!(S.length>0&&!l&&!S.some(Ce=>Ie(U,Ce,{stripQuotes:!0}))))try{let Ce=e.fs.resolvePath(e.cwd,W);if((await e.fs.stat(Ce)).isDirectory){l||(ne+=`grep: ${W}: Is a directory
|
|
146
|
+
`);continue}let En=await e.fs.readFile(Ce),L=na(En,ee,s,n,i,dr?W:"",p,E,b,y);if(L.matched){if(Se=!0,x)return{stdout:"",stderr:"",exitCode:0};a?de+=`${W}
|
|
147
|
+
`:o||(de+=L.output)}else o?de+=`${W}
|
|
148
|
+
`:i&&!a&&(de+=L.output)}catch{ne+=`grep: ${W}: No such file or directory
|
|
149
|
+
`,Ue=!0}}let De;return Ue?De=2:o?De=de.length>0?0:1:De=Se?0:1,x?{stdout:"",stderr:"",exitCode:De}:{stdout:de,stderr:ne,exitCode:De}}};Uf={name:"fgrep",async execute(t,e){return In.execute(["-F",...t],e)}},zf={name:"egrep",async execute(t,e){return In.execute(["-E",...t],e)}}});function Sr(t){return t instanceof pe||t instanceof ye||t instanceof me}var Re,pe,ye,me,Be,$e,X,ae,qe,z,ze,J=C(()=>{"use strict";Re=class extends Error{stdout;stderr;constructor(e,r="",n=""){super(e),this.stdout=r,this.stderr=n}prependOutput(e,r){this.stdout=e+this.stdout,this.stderr=r+this.stderr}},pe=class extends Re{levels;name="BreakError";constructor(e=1,r="",n=""){super("break",r,n),this.levels=e}},ye=class extends Re{levels;name="ContinueError";constructor(e=1,r="",n=""){super("continue",r,n),this.levels=e}},me=class extends Re{exitCode;name="ReturnError";constructor(e=0,r="",n=""){super("return",r,n),this.exitCode=e}},Be=class extends Re{exitCode;name="ErrexitError";constructor(e,r="",n=""){super(`errexit: command exited with status ${e}`,r,n),this.exitCode=e}},$e=class extends Re{varName;name="NounsetError";constructor(e,r=""){super(`${e}: unbound variable`,r,`bash: ${e}: unbound variable
|
|
150
|
+
`),this.varName=e}},X=class extends Re{exitCode;name="ExitError";constructor(e,r="",n=""){super("exit",r,n),this.exitCode=e}},ae=class extends Re{name="ArithmeticError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}
|
|
151
|
+
`}},qe=class extends Re{name="BadSubstitutionError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}: bad substitution
|
|
152
|
+
`}},z=class extends Re{limitType;name="ExecutionLimitError";static EXIT_CODE=126;constructor(e,r,n="",s=""){super(e,n,s),this.limitType=r,this.stderr=s||`bash: ${e}
|
|
153
|
+
`}},ze=class extends Re{name="SubshellExitError";constructor(e="",r=""){super("subshell exit",e,r)}}});function aa(t,e,r){return{patternSpace:"",holdSpace:"",lineNumber:0,totalLines:t,deleted:!1,printed:!1,quit:!1,quitSilent:!1,exitCode:void 0,appendBuffer:[],substitutionMade:!1,lineNumberOutput:[],restartCycle:!1,currentFilename:e,pendingFileReads:[],pendingFileWrites:[],pendingExecute:void 0,rangeStates:r||new Map}}function jf(t){return typeof t=="object"&&"first"in t&&"step"in t}function jt(t,e,r,n){if(t==="$")return e===r;if(typeof t=="number")return e===t;if(jf(t)){let{first:s,step:i}=t;return i===0?e===s:(e-s)%i===0&&e>=s}if(typeof t=="object"&&"pattern"in t)try{return new RegExp(t.pattern).test(n)}catch{return!1}return!1}function Gf(t){let e=r=>r===void 0?"undefined":r==="$"?"$":typeof r=="number"?String(r):"pattern"in r?`/${r.pattern}/`:"first"in r?`${r.first}~${r.step}`:"unknown";return`${e(t.start)},${e(t.end)}`}function At(t,e,r,n,s){if(!t||!t.start&&!t.end)return!0;let i=t.start,a=t.end;if(i!==void 0&&a===void 0)return jt(i,e,r,n);if(i!==void 0&&a!==void 0){let o=typeof i=="object"&&"pattern"in i,l=typeof a=="object"&&"pattern"in a;if(!o&&!l){let u=typeof i=="number"?i:i==="$"?r:1,f=typeof a=="number"?a:r;return e>=u&&e<=f}if(s){let u=Gf(t),f=s.get(u);return f||(f={active:!1},s.set(u,f)),f.active?(jt(a,e,r,n)&&(f.active=!1,s.set(u,f)),!0):jt(i,e,r,n)?(f.active=!0,f.startLine=e,s.set(u,f),jt(a,e,r,n)&&(f.active=!1,s.set(u,f)),!0):!1}return jt(i,e,r,n)}return!0}function qf(t){let e="",r=0;for(;r<t.length;){if(t[r]==="\\"&&r+1<t.length){let n=t[r+1];if(n==="+"||n==="?"||n==="|"){e+=n,r+=2;continue}if(n==="("||n===")"){e+=n,r+=2;continue}if(n==="{"||n==="}"){e+=n,r+=2;continue}e+=t[r]+n,r+=2;continue}if(t[r]==="+"||t[r]==="?"||t[r]==="|"||t[r]==="("||t[r]===")"){e+=`\\${t[r]}`,r++;continue}e+=t[r],r++}return e}function Vf(t){let e="";for(let r=0;r<t.length;r++){let n=t[r],s=n.charCodeAt(0);n==="\\"?e+="\\\\":n===" "?e+="\\t":n===`
|
|
154
154
|
`?e+=`$
|
|
155
|
-
`:n==="\r"?e+="\\r":n==="\x07"?e+="\\a":n==="\b"?e+="\\b":n==="\f"?e+="\\f":n==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=n}return`${e}$`}function
|
|
156
|
-
`,s+=2;continue}if(i==="t"){n+=" ",s+=2;continue}let a=parseInt(i,10);if(a>=1&&a<=9){n+=r[a-1]||"",s+=2;continue}n+=i,s+=2;continue}if(t[s]==="&"){n+=e,s++;continue}n+=t[s],s++}return n}function
|
|
155
|
+
`:n==="\r"?e+="\\r":n==="\x07"?e+="\\a":n==="\b"?e+="\\b":n==="\f"?e+="\\f":n==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=n}return`${e}$`}function ia(t,e,r){let n="",s=0;for(;s<t.length;){if(t[s]==="\\"&&s+1<t.length){let i=t[s+1];if(i==="&"){n+="&",s+=2;continue}if(i==="n"){n+=`
|
|
156
|
+
`,s+=2;continue}if(i==="t"){n+=" ",s+=2;continue}let a=parseInt(i,10);if(a>=1&&a<=9){n+=r[a-1]||"",s+=2;continue}n+=i,s+=2;continue}if(t[s]==="&"){n+=e,s++;continue}n+=t[s],s++}return n}function Zf(t,e){let{lineNumber:r,totalLines:n,patternSpace:s}=e;if(t.type!=="label"&&At(t.address,r,n,s,e.rangeStates))switch(t.type){case"substitute":{let i=t,a="";i.global&&(a+="g"),i.ignoreCase&&(a+="i");let o=i.extendedRegex?i.pattern:qf(i.pattern);try{let l=new RegExp(o,a),c=l.test(e.patternSpace);if(l.lastIndex=0,c){if(e.substitutionMade=!0,i.nthOccurrence&&i.nthOccurrence>0&&!i.global){let u=0,f=i.nthOccurrence;e.patternSpace=e.patternSpace.replace(new RegExp(o,`g${i.ignoreCase?"i":""}`),(d,...h)=>{if(u++,u===f){let p=h.slice(0,-2);return ia(i.replacement,d,p)}return d})}else e.patternSpace=e.patternSpace.replace(l,(u,...f)=>{let d=f.slice(0,-2);return ia(i.replacement,u,d)});i.printOnMatch&&(e.printed=!0)}}catch{}break}case"print":e.printed=!0;break;case"printFirstLine":{let i=e.patternSpace.indexOf(`
|
|
157
157
|
`);i!==-1?e.lineNumberOutput.push(e.patternSpace.slice(0,i)):e.lineNumberOutput.push(e.patternSpace);break}case"delete":e.deleted=!0;break;case"deleteFirstLine":{let i=e.patternSpace.indexOf(`
|
|
158
158
|
`);i!==-1?(e.patternSpace=e.patternSpace.slice(i+1),e.restartCycle=!0):e.deleted=!0;break}case"zap":e.patternSpace="";break;case"append":e.appendBuffer.push(t.text);break;case"insert":e.appendBuffer.unshift(`__INSERT__${t.text}`);break;case"change":e.patternSpace=t.text,e.deleted=!0,e.appendBuffer.push(t.text);break;case"hold":e.holdSpace=e.patternSpace;break;case"holdAppend":e.holdSpace?e.holdSpace+=`
|
|
159
159
|
${e.patternSpace}`:e.holdSpace=e.patternSpace;break;case"get":e.patternSpace=e.holdSpace;break;case"getAppend":e.patternSpace+=`
|
|
160
|
-
${e.holdSpace}`;break;case"exchange":{let i=e.patternSpace;e.patternSpace=e.holdSpace,e.holdSpace=i;break}case"next":e.printed=!0;break;case"quit":e.quit=!0,t.exitCode!==void 0&&(e.exitCode=t.exitCode);break;case"quitSilent":e.quit=!0,e.quitSilent=!0,t.exitCode!==void 0&&(e.exitCode=t.exitCode);break;case"list":{let i=
|
|
160
|
+
${e.holdSpace}`;break;case"exchange":{let i=e.patternSpace;e.patternSpace=e.holdSpace,e.holdSpace=i;break}case"next":e.printed=!0;break;case"quit":e.quit=!0,t.exitCode!==void 0&&(e.exitCode=t.exitCode);break;case"quitSilent":e.quit=!0,e.quitSilent=!0,t.exitCode!==void 0&&(e.exitCode=t.exitCode);break;case"list":{let i=Vf(e.patternSpace);e.lineNumberOutput.push(i);break}case"printFilename":e.currentFilename&&e.lineNumberOutput.push(e.currentFilename);break;case"version":break;case"readFile":e.pendingFileReads.push({filename:t.filename,wholeFile:!0});break;case"readFileLine":e.pendingFileReads.push({filename:t.filename,wholeFile:!1});break;case"writeFile":e.pendingFileWrites.push({filename:t.filename,content:`${e.patternSpace}
|
|
161
161
|
`});break;case"writeFirstLine":{let i=e.patternSpace.indexOf(`
|
|
162
162
|
`),a=i!==-1?e.patternSpace.slice(0,i):e.patternSpace;e.pendingFileWrites.push({filename:t.filename,content:`${a}
|
|
163
|
-
`});break}case"execute":t.command?e.pendingExecute={command:t.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=
|
|
164
|
-
${u}`,e.lineNumber=r.currentLineIndex+o+1}else{e.quit=!0,e.deleted=!0;break}
|
|
163
|
+
`});break}case"execute":t.command?e.pendingExecute={command:t.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=Qf(e.patternSpace,t);break;case"lineNumber":e.lineNumberOutput.push(String(e.lineNumber));break;case"branch":break;case"branchOnSubst":break;case"branchOnNoSubst":break;case"group":break}}function Qf(t,e){let r="";for(let n of t){let s=e.source.indexOf(n);s!==-1?r+=e.dest[s]:r+=n}return r}function Rn(t,e,r,n){let s=new Map;for(let c=0;c<t.length;c++){let u=t[c];u.type==="label"&&s.set(u.name,c)}let i=n?.maxIterations??Hf,a=0,o=0,l=0;for(;l<t.length;){if(a++,a>i)throw new z(`sed: command execution exceeded maximum iterations (${i})`,"iterations");if(e.deleted||e.quit||e.quitSilent||e.restartCycle)break;let c=t[l];if(c.type==="nextAppend"){if(At(c.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates))if(r&&r.currentLineIndex+o+1<r.lines.length){o++;let u=r.lines[r.currentLineIndex+o];e.patternSpace+=`
|
|
164
|
+
${u}`,e.lineNumber=r.currentLineIndex+o+1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(c.type==="branch"){let u=c;if(At(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)){if(u.label){let f=s.get(u.label);if(f!==void 0){l=f;continue}}break}l++;continue}if(c.type==="branchOnSubst"){let u=c;if(At(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&e.substitutionMade){if(e.substitutionMade=!1,u.label){let f=s.get(u.label);if(f!==void 0){l=f;continue}}break}l++;continue}if(c.type==="branchOnNoSubst"){let u=c;if(At(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&!e.substitutionMade){if(u.label){let f=s.get(u.label);if(f!==void 0){l=f;continue}}break}l++;continue}if(c.type==="group"){let u=c;At(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&Rn(u.commands,e,r,n),l++;continue}Zf(c,e),l++}return o}var Hf,oa=C(()=>{"use strict";J();Hf=1e4});var I,Cr,la=C(()=>{"use strict";(function(t){t.NUMBER="NUMBER",t.DOLLAR="DOLLAR",t.PATTERN="PATTERN",t.STEP="STEP",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.SEMICOLON="SEMICOLON",t.NEWLINE="NEWLINE",t.COMMA="COMMA",t.COMMAND="COMMAND",t.SUBSTITUTE="SUBSTITUTE",t.TRANSLITERATE="TRANSLITERATE",t.LABEL_DEF="LABEL_DEF",t.BRANCH="BRANCH",t.BRANCH_ON_SUBST="BRANCH_ON_SUBST",t.BRANCH_ON_NO_SUBST="BRANCH_ON_NO_SUBST",t.TEXT_CMD="TEXT_CMD",t.FILE_READ="FILE_READ",t.FILE_READ_LINE="FILE_READ_LINE",t.FILE_WRITE="FILE_WRITE",t.FILE_WRITE_LINE="FILE_WRITE_LINE",t.EXECUTE="EXECUTE",t.EOF="EOF",t.ERROR="ERROR"})(I||(I={}));Cr=class{input;pos=0;line=1;column=1;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let r=this.nextToken();r&&e.push(r)}return e.push(this.makeToken(I.EOF,"")),e}makeToken(e,r,n){return{type:e,value:r,line:this.line,column:this.column,...n}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
165
165
|
`?(this.line++,this.column=1):this.column++,e}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.peek();if(e===" "||e===" "||e==="\r")this.advance();else if(e==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
166
166
|
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,r=this.column,n=this.peek();return n===`
|
|
167
167
|
`?(this.advance(),{type:I.NEWLINE,value:`
|
|
@@ -181,14 +181,14 @@ ${u}`,e.lineNumber=r.currentLineIndex+o+1}else{e.quit=!0,e.deleted=!0;break}c++;
|
|
|
181
181
|
`;)s+=this.advance();return{type:I.TEXT_CMD,value:e,text:s.trim(),line:r,column:n}}readBranch(e,r,n,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let a=this.peek();if(a===" "||a===" "||a===`
|
|
182
182
|
`||a===";"||a==="}"||a==="{")break;i+=this.advance()}return{type:e,value:r,label:i||void 0,line:n,column:s}}readFileCommand(e,r,n,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let a=this.peek();if(a===`
|
|
183
183
|
`||a===";")break;i+=this.advance()}return{type:e,value:r,filename:i.trim(),line:n,column:s}}readExecute(e,r){for(;this.peek()===" "||this.peek()===" ";)this.advance();let n="";for(;this.pos<this.input.length;){let s=this.peek();if(s===`
|
|
184
|
-
`||s===";")break;n+=this.advance()}return{type:I.EXECUTE,value:"e",command:n.trim()||void 0,line:e,column:r}}isDigit(e){return e>="0"&&e<="9"}}});function
|
|
185
|
-
`);
|
|
186
|
-
`)),
|
|
187
|
-
`;let
|
|
188
|
-
`;!
|
|
189
|
-
`):u+=`${
|
|
190
|
-
`);for(let
|
|
191
|
-
`;if(
|
|
184
|
+
`||s===";")break;n+=this.advance()}return{type:I.EXECUTE,value:"e",command:n.trim()||void 0,line:e,column:r}}isDigit(e){return e>="0"&&e<="9"}}});function ca(t,e=!1){return new $n(t,e).parse()}var $n,ua=C(()=>{"use strict";la();$n=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,r=!1){this.scripts=e,this.extendedRegex=r}parse(){let e=[];for(let r of this.scripts){let n=new Cr(r);for(this.tokens=n.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(I.NEWLINE)||this.check(I.SEMICOLON)){this.advance();continue}let s=this.parseCommand();if(s.error)return{commands:[],error:s.error};s.command&&e.push(s.command)}}return{commands:e}}parseCommand(){let e=this.parseAddressRange();for(;this.check(I.NEWLINE)||this.check(I.SEMICOLON);)this.advance();if(this.isAtEnd())return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null};let r=this.peek();switch(r.type){case I.COMMAND:return this.parseSimpleCommand(r,e);case I.SUBSTITUTE:return this.parseSubstituteFromToken(r,e);case I.TRANSLITERATE:return this.parseTransliterateFromToken(r,e);case I.LABEL_DEF:return this.advance(),{command:{type:"label",name:r.label||""}};case I.BRANCH:return this.advance(),{command:{type:"branch",address:e,label:r.label}};case I.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:e,label:r.label}};case I.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:e,label:r.label}};case I.TEXT_CMD:return this.advance(),this.parseTextCommand(r,e);case I.FILE_READ:return this.advance(),{command:{type:"readFile",address:e,filename:r.filename||""}};case I.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:e,filename:r.filename||""}};case I.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:e,filename:r.filename||""}};case I.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:e,filename:r.filename||""}};case I.EXECUTE:return this.advance(),{command:{type:"execute",address:e,command:r.command}};case I.LBRACE:return this.parseGroup(e);case I.RBRACE:return{command:null};case I.ERROR:return{command:null,error:`invalid command: ${r.value}`};default:return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null}}}parseSimpleCommand(e,r){this.advance();let n=e.value;switch(n){case"p":return{command:{type:"print",address:r}};case"P":return{command:{type:"printFirstLine",address:r}};case"d":return{command:{type:"delete",address:r}};case"D":return{command:{type:"deleteFirstLine",address:r}};case"h":return{command:{type:"hold",address:r}};case"H":return{command:{type:"holdAppend",address:r}};case"g":return{command:{type:"get",address:r}};case"G":return{command:{type:"getAppend",address:r}};case"x":return{command:{type:"exchange",address:r}};case"n":return{command:{type:"next",address:r}};case"N":return{command:{type:"nextAppend",address:r}};case"q":return{command:{type:"quit",address:r}};case"Q":return{command:{type:"quitSilent",address:r}};case"z":return{command:{type:"zap",address:r}};case"=":return{command:{type:"lineNumber",address:r}};case"l":return{command:{type:"list",address:r}};case"F":return{command:{type:"printFilename",address:r}};case"v":return{command:{type:"version",address:r}};default:return{command:null,error:`unknown command: ${n}`}}}parseSubstituteFromToken(e,r){this.advance();let n=e.flags||"",s,i=n.match(/(\d+)/);return i&&(s=parseInt(i[1],10)),{command:{type:"substitute",address:r,pattern:e.pattern||"",replacement:e.replacement||"",global:n.includes("g"),ignoreCase:n.includes("i")||n.includes("I"),printOnMatch:n.includes("p"),nthOccurrence:s,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,r){this.advance();let n=e.source||"",s=e.dest||"";return n.length!==s.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:r,source:n,dest:s}}}parseTextCommand(e,r){let n=e.value,s=e.text||"";switch(n){case"a":return{command:{type:"append",address:r,text:s}};case"i":return{command:{type:"insert",address:r,text:s}};case"c":return{command:{type:"change",address:r,text:s}};default:return{command:null,error:`unknown text command: ${n}`}}}parseGroup(e){this.advance();let r=[];for(;!this.isAtEnd()&&!this.check(I.RBRACE);){if(this.check(I.NEWLINE)||this.check(I.SEMICOLON)){this.advance();continue}let n=this.parseCommand();if(n.error)return{command:null,error:n.error};n.command&&r.push(n.command)}return this.check(I.RBRACE)?(this.advance(),{command:{type:"group",address:e,commands:r}}):{command:null,error:"unmatched brace in grouped commands"}}parseAddressRange(){let e=this.parseAddress();if(e===void 0)return;let r;return this.check(I.COMMA)&&(this.advance(),r=this.parseAddress()),{start:e,end:r}}parseAddress(){let e=this.peek();switch(e.type){case I.NUMBER:return this.advance(),e.value;case I.DOLLAR:return this.advance(),"$";case I.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case I.STEP:return this.advance(),{first:e.first||0,step:e.step||0};default:return}}peek(){return this.tokens[this.pos]||{type:I.EOF,value:"",line:0,column:0}}advance(){return this.isAtEnd()||this.pos++,this.tokens[this.pos-1]}check(e){return this.peek().type===e}isAtEnd(){return this.peek().type===I.EOF}}});var fa={};R(fa,{sedCommand:()=>Kf});async function On(t,e,r,n={}){let{limits:s,filename:i,fs:a,cwd:o}=n,l=t.split(`
|
|
185
|
+
`);l.length>0&&l[l.length-1]===""&&l.pop();let c=l.length,u="",f,d="",h=new Map,p=new Map,w=new Map,x=new Map,y=s?{maxIterations:s.maxSedIterations}:void 0;for(let E=0;E<l.length;E++){let b={...aa(c,i,h),patternSpace:l[E],holdSpace:d,lineNumber:E+1,totalLines:c,substitutionMade:!1},S={lines:l,currentLineIndex:E},A=0,D=1e4,F=0;do{if(A++,A>D)break;b.restartCycle=!1,b.pendingFileReads=[],b.pendingFileWrites=[];let ee=Rn(e,b,S,y);if(F+=ee,a&&o){for(let de of b.pendingFileReads){let ne=a.resolvePath(o,de.filename);try{if(de.wholeFile){let Se=await a.readFile(ne);b.appendBuffer.push(Se.replace(/\n$/,""))}else{if(!p.has(ne)){let Te=await a.readFile(ne);p.set(ne,Te.split(`
|
|
186
|
+
`)),w.set(ne,0)}let Se=p.get(ne),Ue=w.get(ne);Se&&Ue!==void 0&&Ue<Se.length&&(b.appendBuffer.push(Se[Ue]),w.set(ne,Ue+1))}}catch{}}for(let de of b.pendingFileWrites){let ne=a.resolvePath(o,de.filename),Se=x.get(ne)||"";x.set(ne,Se+de.content)}}S.currentLineIndex+=ee}while(b.restartCycle&&!b.deleted&&!b.quit&&!b.quitSilent);E+=F,d=b.holdSpace;for(let ee of b.lineNumberOutput)u+=`${ee}
|
|
187
|
+
`;let P=[],B=[];for(let ee of b.appendBuffer)ee.startsWith("__INSERT__")?P.push(ee.slice(10)):B.push(ee);for(let ee of P)u+=`${ee}
|
|
188
|
+
`;!b.deleted&&!b.quitSilent&&(r?b.printed&&(u+=`${b.patternSpace}
|
|
189
|
+
`):u+=`${b.patternSpace}
|
|
190
|
+
`);for(let ee of B)u+=`${ee}
|
|
191
|
+
`;if(b.quit||b.quitSilent){b.exitCode!==void 0&&(f=b.exitCode);break}}if(a&&o)for(let[E,b]of x)try{await a.writeFile(E,b)}catch{}return{output:u,exitCode:f}}var Xf,Kf,da=C(()=>{"use strict";J();M();oa();ua();Xf={name:"sed",summary:"stream editor for filtering and transforming text",usage:"sed [OPTION]... {script} [input-file]...",options:["-n, --quiet, --silent suppress automatic printing of pattern space","-e script add the script to commands to be executed","-f script-file read script from file","-i, --in-place edit files in place","-E, -r, --regexp-extended use extended regular expressions"," --help display this help and exit"],description:`Commands:
|
|
192
192
|
s/regexp/replacement/[flags] substitute
|
|
193
193
|
d delete pattern space
|
|
194
194
|
p print pattern space
|
|
@@ -217,63 +217,75 @@ Addresses:
|
|
|
217
217
|
$ last line
|
|
218
218
|
/regexp/ lines matching regexp
|
|
219
219
|
N,M range from line N to M
|
|
220
|
-
first~step every step-th line starting at first`};
|
|
221
|
-
`)){let
|
|
220
|
+
first~step every step-th line starting at first`};Kf={name:"sed",async execute(t,e){if(v(t))return k(Xf);let r=[],n=[],s=!1,i=!1,a=!1,o=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-n"||d==="--quiet"||d==="--silent")s=!0;else if(d==="-i"||d==="--in-place")i=!0;else if(d.startsWith("-i"))i=!0;else if(d==="-E"||d==="-r"||d==="--regexp-extended")a=!0;else if(d==="-e")f+1<t.length&&r.push(t[++f]);else if(d==="-f")f+1<t.length&&n.push(t[++f]);else{if(d.startsWith("--"))return T("sed",d);if(d.startsWith("-")&&d.length>1){for(let h of d.slice(1))if(h!=="n"&&h!=="e"&&h!=="f"&&h!=="i"&&h!=="E"&&h!=="r")return T("sed",`-${h}`);d.includes("n")&&(s=!0),d.includes("i")&&(i=!0),(d.includes("E")||d.includes("r"))&&(a=!0),d.includes("e")&&!d.includes("n")&&!d.includes("i")&&f+1<t.length&&r.push(t[++f]),d.includes("f")&&!d.includes("e")&&f+1<t.length&&n.push(t[++f])}else!d.startsWith("-")&&r.length===0&&n.length===0?r.push(d):d.startsWith("-")||o.push(d)}}for(let f of n){let d=e.fs.resolvePath(e.cwd,f);try{let h=await e.fs.readFile(d);for(let p of h.split(`
|
|
221
|
+
`)){let w=p.trim();w&&!w.startsWith("#")&&r.push(w)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${f}: No such file or directory
|
|
222
222
|
`,exitCode:1}}}if(r.length===0)return{stdout:"",stderr:`sed: no script specified
|
|
223
|
-
`,exitCode:1};let{commands:
|
|
224
|
-
`,exitCode:1};if(
|
|
225
|
-
`,exitCode:1};let u="";if(o.length===0){u=e.stdin;try{let f=await
|
|
226
|
-
`,exitCode:
|
|
227
|
-
`,exitCode:
|
|
228
|
-
`,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}for(let f of o){let d=e.fs.resolvePath(e.cwd,f);try{u+=await e.fs.readFile(d)}catch(h){return h instanceof
|
|
229
|
-
`,exitCode:
|
|
230
|
-
`,exitCode:1}}}try{let f=await
|
|
231
|
-
`,exitCode:
|
|
232
|
-
`,NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:{},arrays:{},ARGC:0,ARGV:{},functions:new Map,fieldSep:e,maxIterations:r,maxRecursionDepth:n,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,output:"",openedFiles:new Set,fs:s,cwd:i}}var
|
|
233
|
-
`,s+=2):i==="t"?(n+=" ",s+=2):(n+=i,s+=2)}else t[s]==="&"?(n+=e,s++):(n+=t[s],s++);return n}async function
|
|
234
|
-
`;break;case"t":n+=" ";break;case"r":n+="\r";break;case"\\":n+="\\";break;default:n+=i}s+=2}else n+=t[s++];return n}var
|
|
235
|
-
`),o.length>0&&o[o.length-1]===""&&o.pop(),t.vars[i]=JSON.stringify(o),t.vars[a]=-1,
|
|
223
|
+
`,exitCode:1};let{commands:l,error:c}=ca(r,a);if(c)return{stdout:"",stderr:`sed: ${c}
|
|
224
|
+
`,exitCode:1};if(l.length===0)return{stdout:"",stderr:`sed: no valid commands
|
|
225
|
+
`,exitCode:1};let u="";if(o.length===0){u=e.stdin;try{let f=await On(u,l,s,{limits:e.limits,fs:e.fs,cwd:e.cwd});return{stdout:f.output,stderr:"",exitCode:f.exitCode??0}}catch(f){if(f instanceof z)return{stdout:"",stderr:`sed: ${f.message}
|
|
226
|
+
`,exitCode:z.EXIT_CODE};throw f}}if(i){for(let f of o){let d=e.fs.resolvePath(e.cwd,f);try{let h=await e.fs.readFile(d),p=await On(h,l,s,{limits:e.limits,filename:f,fs:e.fs,cwd:e.cwd});await e.fs.writeFile(d,p.output)}catch(h){return h instanceof z?{stdout:"",stderr:`sed: ${h.message}
|
|
227
|
+
`,exitCode:z.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
|
|
228
|
+
`,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}for(let f of o){let d=e.fs.resolvePath(e.cwd,f);try{u+=await e.fs.readFile(d)}catch(h){return h instanceof z?{stdout:"",stderr:`sed: ${h.message}
|
|
229
|
+
`,exitCode:z.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
|
|
230
|
+
`,exitCode:1}}}try{let f=await On(u,l,s,{limits:e.limits,filename:o.length===1?o[0]:void 0,fs:e.fs,cwd:e.cwd});return{stdout:f.output,stderr:"",exitCode:f.exitCode??0}}catch(f){if(f instanceof z)return{stdout:"",stderr:`sed: ${f.message}
|
|
231
|
+
`,exitCode:z.EXIT_CODE};throw f}}}});function Pn(t={}){let{fieldSep:e=/\s+/,maxIterations:r=1e4,maxRecursionDepth:n=100,fs:s,cwd:i}=t;return{FS:" ",OFS:" ",ORS:`
|
|
232
|
+
`,NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:{},arrays:{},ARGC:0,ARGV:{},functions:new Map,fieldSep:e,maxIterations:r,maxRecursionDepth:n,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,output:"",openedFiles:new Set,fs:s,cwd:i}}var ha=C(()=>{"use strict"});function pa(t,e,r){switch(r){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":return e!==0?t/e:0;case"%":return e!==0?t%e:0;case"^":case"**":return t**e;default:return 0}}var ma=C(()=>{"use strict"});function Ae(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function se(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}async function Jf(t,e,r){return t.length===0?e.line.length:se(await r.evalExpr(t[0])).length}async function Yf(t,e,r){if(t.length<2)return"";let n=se(await r.evalExpr(t[0])),s=Math.floor(Ae(await r.evalExpr(t[1])))-1;if(t.length>=3){let i=Math.floor(Ae(await r.evalExpr(t[2])));return n.substr(Math.max(0,s),i)}return n.substr(Math.max(0,s))}async function ed(t,e,r){if(t.length<2)return 0;let n=se(await r.evalExpr(t[0])),s=se(await r.evalExpr(t[1])),i=n.indexOf(s);return i===-1?0:i+1}async function td(t,e,r){if(t.length<2)return 0;let n=se(await r.evalExpr(t[0])),s=t[1];if(s.type!=="variable")return 0;let i=s.name,a=e.FS;if(t.length>=3){let l=se(await r.evalExpr(t[2]));a=l===" "?/\s+/:l}else e.FS===" "&&(a=/\s+/);let o=n.split(a);e.arrays[i]={};for(let l=0;l<o.length;l++)e.arrays[i][String(l+1)]=o[l];return o.length}async function rd(t,e,r){if(t.length<2)return 0;let n;t[0].type==="regex"?n=t[0].pattern:(n=se(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=se(await r.evalExpr(t[1])),i="$0";if(t.length>=3){let o=t[2];o.type==="variable"?i=o.name:o.type==="field"&&(i=`$${Math.floor(Ae(await r.evalExpr(o.index)))}`)}let a;if(i==="$0")a=e.line;else if(i.startsWith("$")){let o=parseInt(i.slice(1),10)-1;a=e.fields[o]||""}else a=se(e.vars[i]??"");try{let o=new RegExp(n),l=a.replace(o,xa(s)),c=l!==a?1:0;if(i==="$0")e.line=l,e.fields=e.FS===" "?l.trim().split(/\s+/).filter(Boolean):l.split(e.fieldSep),e.NF=e.fields.length;else if(i.startsWith("$")){let u=parseInt(i.slice(1),10)-1;for(;e.fields.length<=u;)e.fields.push("");e.fields[u]=l,e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}else e.vars[i]=l;return c}catch{return 0}}async function nd(t,e,r){if(t.length<2)return 0;let n;t[0].type==="regex"?n=t[0].pattern:(n=se(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=se(await r.evalExpr(t[1])),i="$0";if(t.length>=3){let o=t[2];o.type==="variable"?i=o.name:o.type==="field"&&(i=`$${Math.floor(Ae(await r.evalExpr(o.index)))}`)}let a;if(i==="$0")a=e.line;else if(i.startsWith("$")){let o=parseInt(i.slice(1),10)-1;a=e.fields[o]||""}else a=se(e.vars[i]??"");try{let o=new RegExp(n,"g"),l=a.match(o),c=l?l.length:0,u=a.replace(o,xa(s));if(i==="$0")e.line=u,e.fields=e.FS===" "?u.trim().split(/\s+/).filter(Boolean):u.split(e.fieldSep),e.NF=e.fields.length;else if(i.startsWith("$")){let f=parseInt(i.slice(1),10)-1;for(;e.fields.length<=f;)e.fields.push("");e.fields[f]=u,e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}else e.vars[i]=u;return c}catch{return 0}}function xa(t){return e=>{let r="",n=0;for(;n<t.length;)if(t[n]==="\\"&&n+1<t.length){let s=t[n+1];s==="&"?(r+="&",n+=2):s==="\\"?(r+="\\",n+=2):(r+=t[n+1],n+=2)}else t[n]==="&"?(r+=e,n++):(r+=t[n],n++);return r}}async function sd(t,e,r){if(t.length<2)return e.RSTART=0,e.RLENGTH=-1,0;let n=se(await r.evalExpr(t[0])),s;t[1].type==="regex"?s=t[1].pattern:(s=se(await r.evalExpr(t[1])),s.startsWith("/")&&s.endsWith("/")&&(s=s.slice(1,-1)));try{let a=new RegExp(s).exec(n);if(a)return e.RSTART=a.index+1,e.RLENGTH=a[0].length,e.RSTART}catch{}return e.RSTART=0,e.RLENGTH=-1,0}async function id(t,e,r){if(t.length<3)return"";let n;t[0].type==="regex"?n=t[0].pattern:(n=se(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=se(await r.evalExpr(t[1])),i=se(await r.evalExpr(t[2])),a=t.length>=4?se(await r.evalExpr(t[3])):e.line;try{let o=i.toLowerCase()==="g",l=o?0:parseInt(i,10)||1;if(o){let c=new RegExp(n,"g");return a.replace(c,(u,...f)=>ga(s,u,f.slice(0,-2)))}else{let c=0,u=new RegExp(n,"g");return a.replace(u,(f,...d)=>(c++,c===l?ga(s,f,d.slice(0,-2)):f))}}catch{return a}}function ga(t,e,r){let n="",s=0;for(;s<t.length;)if(t[s]==="\\"&&s+1<t.length){let i=t[s+1];if(i==="&")n+="&",s+=2;else if(i==="0")n+=e,s+=2;else if(i>="1"&&i<="9"){let a=parseInt(i,10)-1;n+=r[a]||"",s+=2}else i==="n"?(n+=`
|
|
233
|
+
`,s+=2):i==="t"?(n+=" ",s+=2):(n+=i,s+=2)}else t[s]==="&"?(n+=e,s++):(n+=t[s],s++);return n}async function ad(t,e,r){return t.length===0?"":se(await r.evalExpr(t[0])).toLowerCase()}async function od(t,e,r){return t.length===0?"":se(await r.evalExpr(t[0])).toUpperCase()}async function ld(t,e,r){if(t.length===0)return"";let n=se(await r.evalExpr(t[0])),s=[];for(let i=1;i<t.length;i++)s.push(await r.evalExpr(t[i]));return Dn(n,s)}async function cd(t,e,r){return t.length===0?0:Math.floor(Ae(await r.evalExpr(t[0])))}async function ud(t,e,r){return t.length===0?0:Math.sqrt(Ae(await r.evalExpr(t[0])))}async function fd(t,e,r){return t.length===0?0:Math.sin(Ae(await r.evalExpr(t[0])))}async function dd(t,e,r){return t.length===0?0:Math.cos(Ae(await r.evalExpr(t[0])))}async function hd(t,e,r){let n=t.length>0?Ae(await r.evalExpr(t[0])):0,s=t.length>1?Ae(await r.evalExpr(t[1])):0;return Math.atan2(n,s)}async function pd(t,e,r){return t.length===0?0:Math.log(Ae(await r.evalExpr(t[0])))}async function md(t,e,r){return t.length===0?1:Math.exp(Ae(await r.evalExpr(t[0])))}function gd(t,e,r){return e.random?e.random():Math.random()}async function xd(t,e,r){let n=t.length>0?Ae(await r.evalExpr(t[0])):Date.now();return e.vars._srand_seed=n,n}function Fn(t,e){return()=>{throw new Error(`${t}() is not supported - ${e}`)}}function Tn(t){return()=>{throw new Error(`function '${t}()' is not implemented`)}}function Dn(t,e){let r=0,n="",s=0;for(;s<t.length;)if(t[s]==="%"&&s+1<t.length){let i=s+1,a="",o="",l="";for(;i<t.length&&/[-+ #0]/.test(t[i]);)a+=t[i++];for(;i<t.length&&/\d/.test(t[i]);)o+=t[i++];if(t[i]===".")for(i++;i<t.length&&/\d/.test(t[i]);)l+=t[i++];let c=t[i],u=e[r];switch(c){case"s":{let f=u!==void 0?String(u):"";if(l&&(f=f.substring(0,parseInt(l,10))),o){let d=parseInt(o,10);a.includes("-")?f=f.padEnd(d):f=f.padStart(d)}n+=f,r++;break}case"d":case"i":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let d=String(f);if(o){let h=parseInt(o,10);if(a.includes("-"))d=d.padEnd(h);else if(a.includes("0")&&!a.includes("-")){let p=f<0?"-":"";d=p+Math.abs(f).toString().padStart(h-p.length,"0")}else d=d.padStart(h)}n+=d,r++;break}case"f":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let d=l?parseInt(l,10):6,h=f.toFixed(d);if(o){let p=parseInt(o,10);a.includes("-")?h=h.padEnd(p):h=h.padStart(p)}n+=h,r++;break}case"e":case"E":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let d=l?parseInt(l,10):6,h=f.toExponential(d);if(c==="E"&&(h=h.toUpperCase()),o){let p=parseInt(o,10);a.includes("-")?h=h.padEnd(p):h=h.padStart(p)}n+=h,r++;break}case"g":case"G":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let d=l?parseInt(l,10):6,h=f!==0?Math.floor(Math.log10(Math.abs(f))):0,p;if(f===0?p="0":h<-4||h>=d?(p=f.toExponential(d-1),c==="G"&&(p=p.toUpperCase())):p=f.toPrecision(d),p=p.replace(/\.?0+$/,"").replace(/\.?0+e/,"e"),o){let w=parseInt(o,10);a.includes("-")?p=p.padEnd(w):p=p.padStart(w)}n+=p,r++;break}case"x":case"X":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let d=Math.abs(f).toString(16);if(c==="X"&&(d=d.toUpperCase()),o){let h=parseInt(o,10);a.includes("0")?d=d.padStart(h,"0"):a.includes("-")?d=d.padEnd(h):d=d.padStart(h)}n+=f<0?`-${d}`:d,r++;break}case"o":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let d=Math.abs(f).toString(8);if(o){let h=parseInt(o,10);a.includes("0")?d=d.padStart(h,"0"):a.includes("-")?d=d.padEnd(h):d=d.padStart(h)}n+=f<0?`-${d}`:d,r++;break}case"c":{typeof u=="number"?n+=String.fromCharCode(u):n+=String(u??"").charAt(0)||"",r++;break}case"%":n+="%";break;default:n+=t.substring(s,i+1)}s=i+1}else if(t[s]==="\\"&&s+1<t.length){let i=t[s+1];switch(i){case"n":n+=`
|
|
234
|
+
`;break;case"t":n+=" ";break;case"r":n+="\r";break;case"\\":n+="\\";break;default:n+=i}s+=2}else n+=t[s++];return n}var ya,Ln=C(()=>{"use strict";ya={length:Jf,substr:Yf,index:ed,split:td,sub:rd,gsub:nd,match:sd,gensub:id,tolower:ad,toupper:od,sprintf:ld,int:cd,sqrt:ud,sin:fd,cos:dd,atan2:hd,log:pd,exp:md,rand:gd,srand:xd,system:Fn("system","shell execution not allowed in sandboxed environment"),close:Fn("close","file operations not allowed"),fflush:Fn("fflush","file operations not allowed"),systime:Tn("systime"),mktime:Tn("mktime"),strftime:Tn("strftime")}});function xe(t){return typeof t=="number"?t!==0:t!==""}function H(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function G(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}function Mn(t){if(typeof t=="number")return!0;let e=String(t).trim();return e===""?!1:!Number.isNaN(Number(e))}function Gt(t,e){try{return new RegExp(t).test(e)}catch{return!1}}var kt=C(()=>{"use strict"});function wa(t,e){return t.FS===" "?e.trim().split(/\s+/).filter(Boolean):e.split(t.fieldSep)}function ot(t,e){return e===0?t.line:e<0||e>t.fields.length?"":t.fields[e-1]??""}function vt(t,e,r){if(e===0)t.line=G(r),t.fields=wa(t,t.line),t.NF=t.fields.length;else if(e>0){for(;t.fields.length<e;)t.fields.push("");t.fields[e-1]=G(r),t.NF=t.fields.length,t.line=t.fields.join(t.OFS)}}function qt(t,e){t.line=e,t.fields=wa(t,e),t.NF=t.fields.length}function Ea(t,e){if(t.FS=e,e===" ")t.fieldSep=/\s+/;else try{t.fieldSep=new RegExp(e)}catch{t.fieldSep=new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}var Ar=C(()=>{"use strict";kt()});function lt(t,e){switch(e){case"FS":return t.FS;case"OFS":return t.OFS;case"ORS":return t.ORS;case"NR":return t.NR;case"NF":return t.NF;case"FNR":return t.FNR;case"FILENAME":return t.FILENAME;case"RSTART":return t.RSTART;case"RLENGTH":return t.RLENGTH;case"SUBSEP":return t.SUBSEP;case"ARGC":return t.ARGC}return t.vars[e]??""}function Je(t,e,r){switch(e){case"FS":Ea(t,G(r));return;case"OFS":t.OFS=G(r);return;case"ORS":t.ORS=G(r);return;case"NR":t.NR=Math.floor(H(r));return;case"NF":{let n=Math.floor(H(r));if(n<t.NF)t.fields=t.fields.slice(0,n),t.line=t.fields.join(t.OFS);else if(n>t.NF){for(;t.fields.length<n;)t.fields.push("");t.line=t.fields.join(t.OFS)}t.NF=n;return}case"FNR":t.FNR=Math.floor(H(r));return;case"FILENAME":t.FILENAME=G(r);return;case"RSTART":t.RSTART=Math.floor(H(r));return;case"RLENGTH":t.RLENGTH=Math.floor(H(r));return;case"SUBSEP":t.SUBSEP=G(r);return}t.vars[e]=r}function ct(t,e,r){return e==="ARGV"?t.ARGV[r]??"":t.arrays[e]?.[r]??""}function Nt(t,e,r,n){t.arrays[e]||(t.arrays[e]={}),t.arrays[e][r]=n}function ba(t,e,r){return e==="ARGV"?t.ARGV[r]!==void 0:t.arrays[e]?.[r]!==void 0}function Sa(t,e,r){t.arrays[e]&&delete t.arrays[e][r]}function Ca(t,e){delete t.arrays[e]}var _n=C(()=>{"use strict";Ar();kt()});function Aa(t){Bn=t}async function O(t,e){switch(e.type){case"number":return e.value;case"string":return e.value;case"regex":return Gt(e.pattern,t.line)?1:0;case"field":return yd(t,e);case"variable":return lt(t,e.name);case"array_access":return wd(t,e);case"binary":return Ed(t,e);case"unary":return Cd(t,e);case"ternary":return xe(await O(t,e.condition))?O(t,e.consequent):O(t,e.alternate);case"call":return Ad(t,e.name,e.args);case"assignment":return vd(t,e);case"pre_increment":return Nd(t,e.operand);case"pre_decrement":return Id(t,e.operand);case"post_increment":return Rd(t,e.operand);case"post_decrement":return $d(t,e.operand);case"in":return Od(t,e.key,e.array);case"getline":return Pd(t,e.variable,e.file);case"tuple":return Td(t,e.elements);default:return""}}async function yd(t,e){let r=Math.floor(H(await O(t,e.index)));return ot(t,r)}async function wd(t,e){let r=G(await O(t,e.key));return ct(t,e.array,r)}async function Ed(t,e){let r=e.operator;if(r==="||")return xe(await O(t,e.left))||xe(await O(t,e.right))?1:0;if(r==="&&")return xe(await O(t,e.left))&&xe(await O(t,e.right))?1:0;if(r==="~"){let o=await O(t,e.left),l=e.right.type==="regex"?e.right.pattern:G(await O(t,e.right));try{return new RegExp(l).test(G(o))?1:0}catch{return 0}}if(r==="!~"){let o=await O(t,e.left),l=e.right.type==="regex"?e.right.pattern:G(await O(t,e.right));try{return new RegExp(l).test(G(o))?0:1}catch{return 1}}let n=await O(t,e.left),s=await O(t,e.right);if(r===" ")return G(n)+G(s);if(bd(r))return Sd(n,s,r);let i=H(n),a=H(s);return pa(i,a,r)}function bd(t){return["<","<=",">",">=","==","!="].includes(t)}function Sd(t,e,r){let n=Mn(t),s=Mn(e);if(n&&s){let o=H(t),l=H(e);switch(r){case"<":return o<l?1:0;case"<=":return o<=l?1:0;case">":return o>l?1:0;case">=":return o>=l?1:0;case"==":return o===l?1:0;case"!=":return o!==l?1:0}}let i=G(t),a=G(e);switch(r){case"<":return i<a?1:0;case"<=":return i<=a?1:0;case">":return i>a?1:0;case">=":return i>=a?1:0;case"==":return i===a?1:0;case"!=":return i!==a?1:0}return 0}async function Cd(t,e){let r=await O(t,e.operand);switch(e.operator){case"!":return xe(r)?0:1;case"-":return-H(r);case"+":return+H(r);default:return r}}async function Ad(t,e,r){let n=ya[e];if(n)return n(r,t,{evalExpr:i=>O(t,i)});let s=t.functions.get(e);return s?kd(t,s,r):""}async function kd(t,e,r){if(t.currentRecursionDepth++,t.currentRecursionDepth>t.maxRecursionDepth)throw t.currentRecursionDepth--,new z(`awk: recursion depth exceeded maximum (${t.maxRecursionDepth})`,"recursion",t.output);let n={};for(let i of e.params)n[i]=t.vars[i];for(let i=0;i<e.params.length;i++){let a=e.params[i],o=i<r.length?await O(t,r[i]):"";t.vars[a]=o}t.hasReturn=!1,t.returnValue=void 0,Bn&&await Bn(t,e.body.statements);let s=t.returnValue??"";for(let i of e.params)n[i]!==void 0?t.vars[i]=n[i]:delete t.vars[i];return t.hasReturn=!1,t.returnValue=void 0,t.currentRecursionDepth--,s}async function vd(t,e){let r=await O(t,e.value),n=e.target,s=e.operator,i;if(s==="=")i=r;else{let a;if(n.type==="field"){let c=Math.floor(H(await O(t,n.index)));a=ot(t,c)}else if(n.type==="variable")a=lt(t,n.name);else{let c=G(await O(t,n.key));a=ct(t,n.array,c)}let o=H(a),l=H(r);switch(s){case"+=":i=o+l;break;case"-=":i=o-l;break;case"*=":i=o*l;break;case"/=":i=l!==0?o/l:0;break;case"%=":i=l!==0?o%l:0;break;case"^=":i=o**l;break;default:i=r}}if(n.type==="field"){let a=Math.floor(H(await O(t,n.index)));vt(t,a,i)}else if(n.type==="variable")Je(t,n.name,i);else{let a=G(await O(t,n.key));Nt(t,n.array,a,i)}return i}async function Nd(t,e){let r;if(e.type==="field"){let n=Math.floor(H(await O(t,e.index)));r=H(ot(t,n))+1,vt(t,n,r)}else if(e.type==="variable")r=H(lt(t,e.name))+1,Je(t,e.name,r);else{let n=G(await O(t,e.key));r=H(ct(t,e.array,n))+1,Nt(t,e.array,n,r)}return r}async function Id(t,e){let r;if(e.type==="field"){let n=Math.floor(H(await O(t,e.index)));r=H(ot(t,n))-1,vt(t,n,r)}else if(e.type==="variable")r=H(lt(t,e.name))-1,Je(t,e.name,r);else{let n=G(await O(t,e.key));r=H(ct(t,e.array,n))-1,Nt(t,e.array,n,r)}return r}async function Rd(t,e){let r;if(e.type==="field"){let n=Math.floor(H(await O(t,e.index)));r=H(ot(t,n)),vt(t,n,r+1)}else if(e.type==="variable")r=H(lt(t,e.name)),Je(t,e.name,r+1);else{let n=G(await O(t,e.key));r=H(ct(t,e.array,n)),Nt(t,e.array,n,r+1)}return r}async function $d(t,e){let r;if(e.type==="field"){let n=Math.floor(H(await O(t,e.index)));r=H(ot(t,n)),vt(t,n,r-1)}else if(e.type==="variable")r=H(lt(t,e.name)),Je(t,e.name,r-1);else{let n=G(await O(t,e.key));r=H(ct(t,e.array,n)),Nt(t,e.array,n,r-1)}return r}async function Od(t,e,r){let n;if(e.type==="tuple"){let s=[];for(let i of e.elements)s.push(G(await O(t,i)));n=s.join(t.SUBSEP)}else n=G(await O(t,e));return ba(t,r,n)?1:0}async function Pd(t,e,r){if(r)return Fd(t,e,r);if(!t.lines||t.lineIndex===void 0)return-1;let n=t.lineIndex+1;if(n>=t.lines.length)return 0;let s=t.lines[n];return e?Je(t,e,s):qt(t,s),t.NR++,t.lineIndex=n,1}async function Fd(t,e,r){if(!t.fs||!t.cwd)return-1;let n=G(await O(t,r)),s=t.fs.resolvePath(t.cwd,n),i=`__fc_${s}`,a=`__fi_${s}`,o,l;if(t.vars[i]===void 0)try{o=(await t.fs.readFile(s)).split(`
|
|
235
|
+
`),o.length>0&&o[o.length-1]===""&&o.pop(),t.vars[i]=JSON.stringify(o),t.vars[a]=-1,l=-1}catch{return-1}else o=JSON.parse(t.vars[i]),l=t.vars[a];let c=l+1;if(c>=o.length)return 0;let u=o[c];return t.vars[a]=c,e?Je(t,e,u):qt(t,u),1}async function Td(t,e){if(e.length===0)return"";for(let r=0;r<e.length-1;r++)await O(t,e[r]);return O(t,e[e.length-1])}var Bn,Wn=C(()=>{"use strict";J();ma();Ln();Ar();kt();_n();Bn=null});async function It(t,e){for(let r of e)if(await ut(t,r),Dd(t))break}function Dd(t){return t.shouldExit||t.shouldNext||t.shouldNextFile||t.loopBreak||t.loopContinue||t.hasReturn}async function ut(t,e){switch(e.type){case"block":await It(t,e.statements);break;case"expr_stmt":await O(t,e.expression);break;case"print":await Ld(t,e.args,e.output);break;case"printf":await Md(t,e.format,e.args,e.output);break;case"if":await _d(t,e);break;case"while":await Bd(t,e);break;case"do_while":await Wd(t,e);break;case"for":await Ud(t,e);break;case"for_in":await zd(t,e);break;case"break":t.loopBreak=!0;break;case"continue":t.loopContinue=!0;break;case"next":t.shouldNext=!0;break;case"nextfile":t.shouldNextFile=!0;break;case"exit":t.shouldExit=!0,t.exitCode=e.code?Math.floor(H(await O(t,e.code))):0;break;case"return":t.hasReturn=!0,t.returnValue=e.value?await O(t,e.value):"";break;case"delete":await Hd(t,e.target);break}}async function Ld(t,e,r){let n=[];for(let i of e)n.push(G(await O(t,i)));let s=n.join(t.OFS)+t.ORS;r?await ka(t,r.redirect,r.file,s):t.output+=s}async function Md(t,e,r,n){let s=G(await O(t,e)),i=[];for(let o of r)i.push(await O(t,o));let a=Dn(s,i);n?await ka(t,n.redirect,n.file,a):t.output+=a}async function ka(t,e,r,n){if(!t.fs||!t.cwd){t.output+=n;return}let s=G(await O(t,r)),i=t.fs.resolvePath(t.cwd,s);e===">"?t.openedFiles.has(i)?await t.fs.appendFile(i,n):(await t.fs.writeFile(i,n),t.openedFiles.add(i)):(t.openedFiles.has(i)||t.openedFiles.add(i),await t.fs.appendFile(i,n))}async function _d(t,e){xe(await O(t,e.condition))?await ut(t,e.consequent):e.alternate&&await ut(t,e.alternate)}async function Bd(t,e){let r=0;for(;xe(await O(t,e.condition));){if(r++,r>t.maxIterations)throw new z(`awk: while loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ut(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}}async function Wd(t,e){let r=0;do{if(r++,r>t.maxIterations)throw new z(`awk: do-while loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ut(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}while(xe(await O(t,e.condition)))}async function Ud(t,e){e.init&&await O(t,e.init);let r=0;for(;!e.condition||xe(await O(t,e.condition));){if(r++,r>t.maxIterations)throw new z(`awk: for loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ut(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break;e.update&&await O(t,e.update)}}async function zd(t,e){let r=t.arrays[e.array];if(r)for(let n of Object.keys(r)){if(t.vars[e.variable]=n,t.loopContinue=!1,await ut(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}}async function Hd(t,e){if(e.type==="array_access"){let r=G(await O(t,e.key));Sa(t,e.array,r)}else e.type==="variable"&&Ca(t,e.name)}var va=C(()=>{"use strict";J();Ln();Wn();kt();_n();Aa(It)});var Vt,Na=C(()=>{"use strict";Wn();Ar();kt();va();Vt=class{ctx;program=null;rangeStates=[];constructor(e){this.ctx=e}execute(e){this.program=e,this.ctx.output="";for(let r of e.functions)this.ctx.functions.set(r.name,r);this.rangeStates=e.rules.map(()=>!1)}async executeBegin(){if(this.program){for(let e of this.program.rules)if(e.pattern?.type==="begin"&&(await It(this.ctx,e.action.statements),this.ctx.shouldExit))break}}async executeLine(e){if(!(!this.program||this.ctx.shouldExit)){qt(this.ctx,e),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let r=0;r<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);r++){let n=this.program.rules[r];n.pattern?.type==="begin"||n.pattern?.type==="end"||await this.matchesRule(n,r)&&await It(this.ctx,n.action.statements)}}}async executeEnd(){if(!(!this.program||this.ctx.shouldExit)){for(let e of this.program.rules)if(e.pattern?.type==="end"&&(await It(this.ctx,e.action.statements),this.ctx.shouldExit))break}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(e,r){let n=e.pattern;if(!n)return!0;switch(n.type){case"begin":case"end":return!1;case"regex_pattern":return Gt(n.pattern,this.ctx.line);case"expr_pattern":return xe(await O(this.ctx,n.expression));case"range":{let s=await this.matchPattern(n.start),i=await this.matchPattern(n.end);return this.rangeStates[r]?(i&&(this.rangeStates[r]=!1),!0):s?(this.rangeStates[r]=!0,i&&(this.rangeStates[r]=!1),!0):!1}default:return!1}}async matchPattern(e){switch(e.type){case"regex_pattern":return Gt(e.pattern,this.ctx.line);case"expr_pattern":return xe(await O(this.ctx,e.expression));default:return!1}}}});var Ia=C(()=>{"use strict";ha();Na()});function Gd(t){return t.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var g,jd,kr,Ra=C(()=>{"use strict";(function(t){t.NUMBER="NUMBER",t.STRING="STRING",t.REGEX="REGEX",t.IDENT="IDENT",t.BEGIN="BEGIN",t.END="END",t.IF="IF",t.ELSE="ELSE",t.WHILE="WHILE",t.DO="DO",t.FOR="FOR",t.IN="IN",t.BREAK="BREAK",t.CONTINUE="CONTINUE",t.NEXT="NEXT",t.NEXTFILE="NEXTFILE",t.EXIT="EXIT",t.RETURN="RETURN",t.DELETE="DELETE",t.FUNCTION="FUNCTION",t.PRINT="PRINT",t.PRINTF="PRINTF",t.GETLINE="GETLINE",t.PLUS="PLUS",t.MINUS="MINUS",t.STAR="STAR",t.SLASH="SLASH",t.PERCENT="PERCENT",t.CARET="CARET",t.EQ="EQ",t.NE="NE",t.LT="LT",t.GT="GT",t.LE="LE",t.GE="GE",t.MATCH="MATCH",t.NOT_MATCH="NOT_MATCH",t.AND="AND",t.OR="OR",t.NOT="NOT",t.ASSIGN="ASSIGN",t.PLUS_ASSIGN="PLUS_ASSIGN",t.MINUS_ASSIGN="MINUS_ASSIGN",t.STAR_ASSIGN="STAR_ASSIGN",t.SLASH_ASSIGN="SLASH_ASSIGN",t.PERCENT_ASSIGN="PERCENT_ASSIGN",t.CARET_ASSIGN="CARET_ASSIGN",t.INCREMENT="INCREMENT",t.DECREMENT="DECREMENT",t.QUESTION="QUESTION",t.COLON="COLON",t.COMMA="COMMA",t.SEMICOLON="SEMICOLON",t.NEWLINE="NEWLINE",t.LPAREN="LPAREN",t.RPAREN="RPAREN",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.LBRACKET="LBRACKET",t.RBRACKET="RBRACKET",t.DOLLAR="DOLLAR",t.APPEND="APPEND",t.PIPE="PIPE",t.EOF="EOF"})(g||(g={}));jd={BEGIN:g.BEGIN,END:g.END,if:g.IF,else:g.ELSE,while:g.WHILE,do:g.DO,for:g.FOR,in:g.IN,break:g.BREAK,continue:g.CONTINUE,next:g.NEXT,nextfile:g.NEXTFILE,exit:g.EXIT,return:g.RETURN,delete:g.DELETE,function:g.FUNCTION,print:g.PRINT,printf:g.PRINTF,getline:g.GETLINE};kr=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let r=this.nextToken();r&&(e.push(r),this.lastTokenType=r.type)}return e.push(this.makeToken(g.EOF,"")),e}makeToken(e,r){return{type:e,value:r,line:this.line,column:this.column}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
236
236
|
`?(this.line++,this.column=1):this.column++,e}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.peek();if(e===" "||e===" "||e==="\r")this.advance();else if(e==="\\")if(this.peek(1)===`
|
|
237
237
|
`)this.advance(),this.advance();else break;else if(e==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
238
238
|
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,r=this.column,n=this.peek();return n===`
|
|
239
|
-
`?(this.advance(),{type:
|
|
240
|
-
`,line:e,column:r}):n==='"'?this.readString():n==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(n)||n==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(n)||n==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,
|
|
241
|
-
`;break;case"t":n+=" ";break;case"r":n+="\r";break;case"\\":n+="\\";break;case'"':n+='"';break;case"/":n+="/";break;default:n+=s}}else n+=this.advance();return this.peek()==='"'&&this.advance(),{type:
|
|
242
|
-
`)break;n+=this.advance()}return this.peek()==="/"&&this.advance(),n=Cu(n),{type:y.REGEX,value:n,line:e,column:r}}readNumber(){let e=this.line,r=this.column,n="";for(;this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(n+=this.advance();this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(n+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(n+=this.advance());this.isDigit(this.peek());)n+=this.advance();return{type:y.NUMBER,value:parseFloat(n),line:e,column:r}}readIdentifier(){let e=this.line,r=this.column,n="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)n+=this.advance();let s=Au[n];return s?{type:s,value:n,line:e,column:r}:{type:y.IDENT,value:n,line:e,column:r}}readOperator(){let e=this.line,r=this.column,n=this.advance(),s=this.peek();switch(n){case"+":return s==="+"?(this.advance(),{type:y.INCREMENT,value:"++",line:e,column:r}):s==="="?(this.advance(),{type:y.PLUS_ASSIGN,value:"+=",line:e,column:r}):{type:y.PLUS,value:"+",line:e,column:r};case"-":return s==="-"?(this.advance(),{type:y.DECREMENT,value:"--",line:e,column:r}):s==="="?(this.advance(),{type:y.MINUS_ASSIGN,value:"-=",line:e,column:r}):{type:y.MINUS,value:"-",line:e,column:r};case"*":return s==="*"?(this.advance(),{type:y.CARET,value:"**",line:e,column:r}):s==="="?(this.advance(),{type:y.STAR_ASSIGN,value:"*=",line:e,column:r}):{type:y.STAR,value:"*",line:e,column:r};case"/":return s==="="?(this.advance(),{type:y.SLASH_ASSIGN,value:"/=",line:e,column:r}):{type:y.SLASH,value:"/",line:e,column:r};case"%":return s==="="?(this.advance(),{type:y.PERCENT_ASSIGN,value:"%=",line:e,column:r}):{type:y.PERCENT,value:"%",line:e,column:r};case"^":return s==="="?(this.advance(),{type:y.CARET_ASSIGN,value:"^=",line:e,column:r}):{type:y.CARET,value:"^",line:e,column:r};case"=":return s==="="?(this.advance(),{type:y.EQ,value:"==",line:e,column:r}):{type:y.ASSIGN,value:"=",line:e,column:r};case"!":return s==="="?(this.advance(),{type:y.NE,value:"!=",line:e,column:r}):s==="~"?(this.advance(),{type:y.NOT_MATCH,value:"!~",line:e,column:r}):{type:y.NOT,value:"!",line:e,column:r};case"<":return s==="="?(this.advance(),{type:y.LE,value:"<=",line:e,column:r}):{type:y.LT,value:"<",line:e,column:r};case">":return s==="="?(this.advance(),{type:y.GE,value:">=",line:e,column:r}):s===">"?(this.advance(),{type:y.APPEND,value:">>",line:e,column:r}):{type:y.GT,value:">",line:e,column:r};case"&":return s==="&"?(this.advance(),{type:y.AND,value:"&&",line:e,column:r}):{type:y.IDENT,value:"&",line:e,column:r};case"|":return s==="|"?(this.advance(),{type:y.OR,value:"||",line:e,column:r}):{type:y.PIPE,value:"|",line:e,column:r};case"~":return{type:y.MATCH,value:"~",line:e,column:r};case"?":return{type:y.QUESTION,value:"?",line:e,column:r};case":":return{type:y.COLON,value:":",line:e,column:r};case",":return{type:y.COMMA,value:",",line:e,column:r};case";":return{type:y.SEMICOLON,value:";",line:e,column:r};case"(":return{type:y.LPAREN,value:"(",line:e,column:r};case")":return{type:y.RPAREN,value:")",line:e,column:r};case"{":return{type:y.LBRACE,value:"{",line:e,column:r};case"}":return{type:y.RBRACE,value:"}",line:e,column:r};case"[":return{type:y.LBRACKET,value:"[",line:e,column:r};case"]":return{type:y.RBRACKET,value:"]",line:e,column:r};case"$":return{type:y.DOLLAR,value:"$",line:e,column:r};default:return{type:y.IDENT,value:n,line:e,column:r}}}isDigit(e){return e>="0"&&e<="9"}isAlpha(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}isAlphaNumeric(e){return this.isDigit(e)||this.isAlpha(e)}}});var Xt,Ai=v(()=>{"use strict";xi();Xt=class{tokens=[];pos=0;parse(e){let r=new Kt(e);return this.tokens=r.tokenize(),this.pos=0,this.parseProgram()}current(){return this.tokens[this.pos]||{type:y.EOF,value:"",line:0,column:0}}advance(){let e=this.current();return this.pos<this.tokens.length&&this.pos++,e}match(...e){return e.includes(this.current().type)}check(e){return this.current().type===e}expect(e,r){if(!this.check(e)){let n=this.current();throw new Error(r||`Expected ${e}, got ${n.type} at line ${n.line}:${n.column}`)}return this.advance()}skipNewlines(){for(;this.check(y.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(y.NEWLINE)||this.check(y.SEMICOLON);)this.advance()}parseProgram(){let e=[],r=[];for(this.skipNewlines();!this.check(y.EOF)&&(this.skipNewlines(),!this.check(y.EOF));)this.check(y.FUNCTION)?e.push(this.parseFunction()):r.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:r}}parseFunction(){this.expect(y.FUNCTION);let e=this.expect(y.IDENT).value;this.expect(y.LPAREN);let r=[];if(!this.check(y.RPAREN))for(r.push(this.expect(y.IDENT).value);this.check(y.COMMA);)this.advance(),r.push(this.expect(y.IDENT).value);this.expect(y.RPAREN),this.skipNewlines();let n=this.parseBlock();return{name:e,params:r,body:n}}parseRule(){let e;if(this.check(y.BEGIN))this.advance(),e={type:"begin"};else if(this.check(y.END))this.advance(),e={type:"end"};else if(this.check(y.LBRACE))e=void 0;else if(this.check(y.REGEX)){let n=this.advance();if(this.check(y.AND)||this.check(y.OR)){let s={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:n.value}};e={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:n.value};if(this.check(y.COMMA)){this.advance();let i;this.check(y.REGEX)?i={type:"regex_pattern",pattern:this.advance().value}:i={type:"expr_pattern",expression:this.parseExpression()},e={type:"range",start:s,end:i}}else e=s}}else{let s={type:"expr_pattern",expression:this.parseExpression()};if(this.check(y.COMMA)){this.advance();let i;this.check(y.REGEX)?i={type:"regex_pattern",pattern:this.advance().value}:i={type:"expr_pattern",expression:this.parseExpression()},e={type:"range",start:s,end:i}}else e=s}this.skipNewlines();let r;return this.check(y.LBRACE)?r=this.parseBlock():r={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:e,action:r}}parseBlock(){this.expect(y.LBRACE),this.skipNewlines();let e=[];for(;!this.check(y.RBRACE)&&!this.check(y.EOF);)e.push(this.parseStatement()),this.skipTerminators();return this.expect(y.RBRACE),{type:"block",statements:e}}parseStatement(){if(this.check(y.LBRACE))return this.parseBlock();if(this.check(y.IF))return this.parseIf();if(this.check(y.WHILE))return this.parseWhile();if(this.check(y.DO))return this.parseDoWhile();if(this.check(y.FOR))return this.parseFor();if(this.check(y.BREAK))return this.advance(),{type:"break"};if(this.check(y.CONTINUE))return this.advance(),{type:"continue"};if(this.check(y.NEXT))return this.advance(),{type:"next"};if(this.check(y.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(y.EXIT)){this.advance();let r;return!this.check(y.NEWLINE)&&!this.check(y.SEMICOLON)&&!this.check(y.RBRACE)&&!this.check(y.EOF)&&(r=this.parseExpression()),{type:"exit",code:r}}if(this.check(y.RETURN)){this.advance();let r;return!this.check(y.NEWLINE)&&!this.check(y.SEMICOLON)&&!this.check(y.RBRACE)&&!this.check(y.EOF)&&(r=this.parseExpression()),{type:"return",value:r}}if(this.check(y.DELETE)){this.advance();let r=this.parsePrimary();if(r.type!=="array_access"&&r.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:r}}return this.check(y.PRINT)?this.parsePrint():this.check(y.PRINTF)?this.parsePrintf():{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(y.IF),this.expect(y.LPAREN);let e=this.parseExpression();this.expect(y.RPAREN),this.skipNewlines();let r=this.parseStatement();this.skipTerminators();let n;return this.check(y.ELSE)&&(this.advance(),this.skipNewlines(),n=this.parseStatement()),{type:"if",condition:e,consequent:r,alternate:n}}parseWhile(){this.expect(y.WHILE),this.expect(y.LPAREN);let e=this.parseExpression();this.expect(y.RPAREN),this.skipNewlines();let r=this.parseStatement();return{type:"while",condition:e,body:r}}parseDoWhile(){this.expect(y.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(y.WHILE),this.expect(y.LPAREN);let r=this.parseExpression();return this.expect(y.RPAREN),{type:"do_while",body:e,condition:r}}parseFor(){if(this.expect(y.FOR),this.expect(y.LPAREN),this.check(y.IDENT)){let i=this.advance();if(this.check(y.IN)){this.advance();let a=this.expect(y.IDENT).value;this.expect(y.RPAREN),this.skipNewlines();let o=this.parseStatement();return{type:"for_in",variable:i.value,array:a,body:o}}this.pos--}let e;this.check(y.SEMICOLON)||(e=this.parseExpression()),this.expect(y.SEMICOLON);let r;this.check(y.SEMICOLON)||(r=this.parseExpression()),this.expect(y.SEMICOLON);let n;this.check(y.RPAREN)||(n=this.parseExpression()),this.expect(y.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:r,update:n,body:s}}parsePrint(){this.expect(y.PRINT);let e=[];if(this.check(y.NEWLINE)||this.check(y.SEMICOLON)||this.check(y.RBRACE)||this.check(y.PIPE)||this.check(y.GT)||this.check(y.APPEND))e.push({type:"field",index:{type:"number",value:0}});else for(e.push(this.parsePrintArg());this.check(y.COMMA);)this.advance(),e.push(this.parsePrintArg());let r;return this.check(y.GT)?(this.advance(),r={redirect:">",file:this.parsePrimary()}):this.check(y.APPEND)&&(this.advance(),r={redirect:">>",file:this.parsePrimary()}),{type:"print",args:e,output:r}}parsePrintArg(){return this.lookAheadForTernary()?this.parseTernary():this.parsePrintOr()}lookAheadForTernary(){let e=0,r=this.pos;for(;r<this.tokens.length;){let n=this.tokens[r];if(n.type===y.LPAREN&&e++,n.type===y.RPAREN&&e--,n.type===y.QUESTION&&e===0)return!0;if(n.type===y.NEWLINE||n.type===y.SEMICOLON||n.type===y.RBRACE||n.type===y.COMMA||n.type===y.PIPE)return!1;r++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(y.OR);){this.advance();let r=this.parsePrintAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parsePrintAnd(){let e=this.parsePrintIn();for(;this.check(y.AND);){this.advance();let r=this.parsePrintIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parsePrintIn(){let e=this.parsePrintMatch();if(this.check(y.IN)){this.advance();let r=String(this.expect(y.IDENT).value);return{type:"in",key:e,array:r}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(y.MATCH,y.NOT_MATCH);){let r=this.advance().type===y.MATCH?"~":"!~",n=this.parsePrintComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(y.LT,y.LE,y.GE,y.EQ,y.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parsePrintf(){this.expect(y.PRINTF);let e=this.parsePrintArg(),r=[];for(;this.check(y.COMMA);)this.advance(),r.push(this.parsePrintArg());let n;return this.check(y.GT)?(this.advance(),n={redirect:">",file:this.parsePrimary()}):this.check(y.APPEND)&&(this.advance(),n={redirect:">>",file:this.parsePrimary()}),{type:"printf",format:e,args:r,output:n}}parseExpression(){return this.parseAssignment()}parseAssignment(){let e=this.parseTernary();if(this.match(y.ASSIGN,y.PLUS_ASSIGN,y.MINUS_ASSIGN,y.STAR_ASSIGN,y.SLASH_ASSIGN,y.PERCENT_ASSIGN,y.CARET_ASSIGN)){let r=this.advance(),n=this.parseAssignment();if(e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[r.value],target:e,value:n}}return e}parseTernary(){let e=this.parseOr();if(this.check(y.QUESTION)){this.advance();let r=this.parseExpression();this.expect(y.COLON);let n=this.parseExpression();e={type:"ternary",condition:e,consequent:r,alternate:n}}return e}parseOr(){let e=this.parseAnd();for(;this.check(y.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalOrRest(e){for(e=this.parseLogicalAndRest(e);this.check(y.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalAndRest(e){for(;this.check(y.AND);){this.advance();let r=this.parseIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parseAnd(){let e=this.parseIn();for(;this.check(y.AND);){this.advance();let r=this.parseIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parseIn(){let e=this.parseMatch();if(this.check(y.IN)){this.advance();let r=this.expect(y.IDENT).value;return{type:"in",key:e,array:r}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(y.MATCH,y.NOT_MATCH);){let r=this.advance().type===y.MATCH?"~":"!~",n=this.parseComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(y.LT,y.LE,y.GT,y.GE,y.EQ,y.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parseConcatenation(){let e=this.parseAddSub();for(;this.canStartExpression()&&!this.isComparisonOrHigherOp();){let r=this.parseAddSub();e={type:"binary",operator:" ",left:e,right:r}}return e}canStartExpression(){return this.match(y.NUMBER,y.STRING,y.IDENT,y.DOLLAR,y.LPAREN,y.NOT,y.MINUS,y.PLUS,y.INCREMENT,y.DECREMENT)}isComparisonOrHigherOp(){return this.match(y.LT,y.LE,y.GT,y.GE,y.EQ,y.NE,y.AND,y.OR,y.QUESTION,y.MATCH,y.NOT_MATCH,y.ASSIGN,y.PLUS_ASSIGN,y.MINUS_ASSIGN,y.STAR_ASSIGN,y.SLASH_ASSIGN,y.PERCENT_ASSIGN,y.CARET_ASSIGN,y.COMMA,y.SEMICOLON,y.NEWLINE,y.RBRACE,y.RPAREN,y.RBRACKET,y.COLON,y.PIPE,y.APPEND,y.IN)}parseAddSub(){let e=this.parseMulDiv();for(;this.match(y.PLUS,y.MINUS);){let r=this.advance().value,n=this.parseMulDiv();e={type:"binary",operator:r,left:e,right:n}}return e}parseMulDiv(){let e=this.parseUnary();for(;this.match(y.STAR,y.SLASH,y.PERCENT);){let r=this.advance(),n=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[r.value],left:e,right:n}}return e}parseUnary(){if(this.check(y.INCREMENT)){this.advance();let e=this.parseUnary();return e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:e}}:{type:"pre_increment",operand:e}}if(this.check(y.DECREMENT)){this.advance();let e=this.parseUnary();return e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:e}}:{type:"pre_decrement",operand:e}}if(this.match(y.NOT,y.MINUS,y.PLUS)){let e=this.advance().value,r=this.parseUnary();return{type:"unary",operator:e,operand:r}}return this.parsePower()}parsePower(){let e=this.parsePostfix();if(this.check(y.CARET)){this.advance();let r=this.parsePower();e={type:"binary",operator:"^",left:e,right:r}}return e}parsePostfix(){let e=this.parsePrimary();if(this.check(y.INCREMENT)){if(this.advance(),e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:e}}if(this.check(y.DECREMENT)){if(this.advance(),e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:e}}return e}parsePrimary(){if(this.check(y.NUMBER))return{type:"number",value:this.advance().value};if(this.check(y.STRING))return{type:"string",value:this.advance().value};if(this.check(y.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(y.DOLLAR))return this.advance(),{type:"field",index:this.parsePrimary()};if(this.check(y.LPAREN)){this.advance();let e=this.parseExpression();if(this.check(y.COMMA)){let r=[e];for(;this.check(y.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(y.RPAREN),{type:"tuple",elements:r}}return this.expect(y.RPAREN),e}if(this.check(y.GETLINE)){this.advance();let e,r;return this.check(y.IDENT)&&(e=this.advance().value),this.check(y.LT)&&(this.advance(),r=this.parsePrimary()),{type:"getline",variable:e,file:r}}if(this.check(y.IDENT)){let e=this.advance().value;if(this.check(y.LPAREN)){this.advance();let r=[];if(!this.check(y.RPAREN))for(r.push(this.parseExpression());this.check(y.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(y.RPAREN),{type:"call",name:e,args:r}}if(this.check(y.LBRACKET)){this.advance();let r=[this.parseExpression()];for(;this.check(y.COMMA);)this.advance(),r.push(this.parseExpression());this.expect(y.RBRACKET);let n;if(r.length===1)n=r[0];else{n=r[0];for(let s=1;s<r.length;s++)n={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:n,right:{type:"variable",name:"SUBSEP"}},right:r[s]}}return{type:"array_access",array:e,key:n}}return{type:"variable",name:e}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}}});var ki={};D(ki,{awkCommand2:()=>vu});function Ci(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
|
|
243
|
-
`).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function
|
|
244
|
-
`,exitCode:1};let a=t[i],o=t.slice(i+1),
|
|
245
|
-
`,exitCode:1}}let u={readFile:e.fs.readFile.bind(e.fs),writeFile:e.fs.writeFile.bind(e.fs),appendFile:async(h,p)=>{try{let
|
|
246
|
-
`);
|
|
239
|
+
`?(this.advance(),{type:g.NEWLINE,value:`
|
|
240
|
+
`,line:e,column:r}):n==='"'?this.readString():n==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(n)||n==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(n)||n==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,g.NEWLINE,g.SEMICOLON,g.LBRACE,g.RBRACE,g.LPAREN,g.LBRACKET,g.COMMA,g.ASSIGN,g.PLUS_ASSIGN,g.MINUS_ASSIGN,g.STAR_ASSIGN,g.SLASH_ASSIGN,g.PERCENT_ASSIGN,g.CARET_ASSIGN,g.AND,g.OR,g.NOT,g.MATCH,g.NOT_MATCH,g.QUESTION,g.COLON,g.LT,g.GT,g.LE,g.GE,g.EQ,g.NE,g.PLUS,g.MINUS,g.STAR,g.PERCENT,g.CARET,g.PRINT,g.PRINTF,g.IF,g.WHILE,g.DO,g.FOR,g.RETURN]).has(this.lastTokenType)}readString(){let e=this.line,r=this.column;this.advance();let n="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let s=this.advance();switch(s){case"n":n+=`
|
|
241
|
+
`;break;case"t":n+=" ";break;case"r":n+="\r";break;case"\\":n+="\\";break;case'"':n+='"';break;case"/":n+="/";break;default:n+=s}}else n+=this.advance();return this.peek()==='"'&&this.advance(),{type:g.STRING,value:n,line:e,column:r}}readRegex(){let e=this.line,r=this.column;this.advance();let n="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")n+=this.advance(),this.pos<this.input.length&&(n+=this.advance());else{if(this.peek()===`
|
|
242
|
+
`)break;n+=this.advance()}return this.peek()==="/"&&this.advance(),n=Gd(n),{type:g.REGEX,value:n,line:e,column:r}}readNumber(){let e=this.line,r=this.column,n="";for(;this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(n+=this.advance();this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(n+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(n+=this.advance());this.isDigit(this.peek());)n+=this.advance();return{type:g.NUMBER,value:parseFloat(n),line:e,column:r}}readIdentifier(){let e=this.line,r=this.column,n="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)n+=this.advance();let s=jd[n];return s?{type:s,value:n,line:e,column:r}:{type:g.IDENT,value:n,line:e,column:r}}readOperator(){let e=this.line,r=this.column,n=this.advance(),s=this.peek();switch(n){case"+":return s==="+"?(this.advance(),{type:g.INCREMENT,value:"++",line:e,column:r}):s==="="?(this.advance(),{type:g.PLUS_ASSIGN,value:"+=",line:e,column:r}):{type:g.PLUS,value:"+",line:e,column:r};case"-":return s==="-"?(this.advance(),{type:g.DECREMENT,value:"--",line:e,column:r}):s==="="?(this.advance(),{type:g.MINUS_ASSIGN,value:"-=",line:e,column:r}):{type:g.MINUS,value:"-",line:e,column:r};case"*":return s==="*"?(this.advance(),{type:g.CARET,value:"**",line:e,column:r}):s==="="?(this.advance(),{type:g.STAR_ASSIGN,value:"*=",line:e,column:r}):{type:g.STAR,value:"*",line:e,column:r};case"/":return s==="="?(this.advance(),{type:g.SLASH_ASSIGN,value:"/=",line:e,column:r}):{type:g.SLASH,value:"/",line:e,column:r};case"%":return s==="="?(this.advance(),{type:g.PERCENT_ASSIGN,value:"%=",line:e,column:r}):{type:g.PERCENT,value:"%",line:e,column:r};case"^":return s==="="?(this.advance(),{type:g.CARET_ASSIGN,value:"^=",line:e,column:r}):{type:g.CARET,value:"^",line:e,column:r};case"=":return s==="="?(this.advance(),{type:g.EQ,value:"==",line:e,column:r}):{type:g.ASSIGN,value:"=",line:e,column:r};case"!":return s==="="?(this.advance(),{type:g.NE,value:"!=",line:e,column:r}):s==="~"?(this.advance(),{type:g.NOT_MATCH,value:"!~",line:e,column:r}):{type:g.NOT,value:"!",line:e,column:r};case"<":return s==="="?(this.advance(),{type:g.LE,value:"<=",line:e,column:r}):{type:g.LT,value:"<",line:e,column:r};case">":return s==="="?(this.advance(),{type:g.GE,value:">=",line:e,column:r}):s===">"?(this.advance(),{type:g.APPEND,value:">>",line:e,column:r}):{type:g.GT,value:">",line:e,column:r};case"&":return s==="&"?(this.advance(),{type:g.AND,value:"&&",line:e,column:r}):{type:g.IDENT,value:"&",line:e,column:r};case"|":return s==="|"?(this.advance(),{type:g.OR,value:"||",line:e,column:r}):{type:g.PIPE,value:"|",line:e,column:r};case"~":return{type:g.MATCH,value:"~",line:e,column:r};case"?":return{type:g.QUESTION,value:"?",line:e,column:r};case":":return{type:g.COLON,value:":",line:e,column:r};case",":return{type:g.COMMA,value:",",line:e,column:r};case";":return{type:g.SEMICOLON,value:";",line:e,column:r};case"(":return{type:g.LPAREN,value:"(",line:e,column:r};case")":return{type:g.RPAREN,value:")",line:e,column:r};case"{":return{type:g.LBRACE,value:"{",line:e,column:r};case"}":return{type:g.RBRACE,value:"}",line:e,column:r};case"[":return{type:g.LBRACKET,value:"[",line:e,column:r};case"]":return{type:g.RBRACKET,value:"]",line:e,column:r};case"$":return{type:g.DOLLAR,value:"$",line:e,column:r};default:return{type:g.IDENT,value:n,line:e,column:r}}}isDigit(e){return e>="0"&&e<="9"}isAlpha(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}isAlphaNumeric(e){return this.isDigit(e)||this.isAlpha(e)}}});var vr,$a=C(()=>{"use strict";Ra();vr=class{tokens=[];pos=0;parse(e){let r=new kr(e);return this.tokens=r.tokenize(),this.pos=0,this.parseProgram()}current(){return this.tokens[this.pos]||{type:g.EOF,value:"",line:0,column:0}}advance(){let e=this.current();return this.pos<this.tokens.length&&this.pos++,e}match(...e){return e.includes(this.current().type)}check(e){return this.current().type===e}expect(e,r){if(!this.check(e)){let n=this.current();throw new Error(r||`Expected ${e}, got ${n.type} at line ${n.line}:${n.column}`)}return this.advance()}skipNewlines(){for(;this.check(g.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(g.NEWLINE)||this.check(g.SEMICOLON);)this.advance()}parseProgram(){let e=[],r=[];for(this.skipNewlines();!this.check(g.EOF)&&(this.skipNewlines(),!this.check(g.EOF));)this.check(g.FUNCTION)?e.push(this.parseFunction()):r.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:r}}parseFunction(){this.expect(g.FUNCTION);let e=this.expect(g.IDENT).value;this.expect(g.LPAREN);let r=[];if(!this.check(g.RPAREN))for(r.push(this.expect(g.IDENT).value);this.check(g.COMMA);)this.advance(),r.push(this.expect(g.IDENT).value);this.expect(g.RPAREN),this.skipNewlines();let n=this.parseBlock();return{name:e,params:r,body:n}}parseRule(){let e;if(this.check(g.BEGIN))this.advance(),e={type:"begin"};else if(this.check(g.END))this.advance(),e={type:"end"};else if(this.check(g.LBRACE))e=void 0;else if(this.check(g.REGEX)){let n=this.advance();if(this.check(g.AND)||this.check(g.OR)){let s={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:n.value}};e={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:n.value};if(this.check(g.COMMA)){this.advance();let i;this.check(g.REGEX)?i={type:"regex_pattern",pattern:this.advance().value}:i={type:"expr_pattern",expression:this.parseExpression()},e={type:"range",start:s,end:i}}else e=s}}else{let s={type:"expr_pattern",expression:this.parseExpression()};if(this.check(g.COMMA)){this.advance();let i;this.check(g.REGEX)?i={type:"regex_pattern",pattern:this.advance().value}:i={type:"expr_pattern",expression:this.parseExpression()},e={type:"range",start:s,end:i}}else e=s}this.skipNewlines();let r;return this.check(g.LBRACE)?r=this.parseBlock():r={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:e,action:r}}parseBlock(){this.expect(g.LBRACE),this.skipNewlines();let e=[];for(;!this.check(g.RBRACE)&&!this.check(g.EOF);)e.push(this.parseStatement()),this.skipTerminators();return this.expect(g.RBRACE),{type:"block",statements:e}}parseStatement(){if(this.check(g.LBRACE))return this.parseBlock();if(this.check(g.IF))return this.parseIf();if(this.check(g.WHILE))return this.parseWhile();if(this.check(g.DO))return this.parseDoWhile();if(this.check(g.FOR))return this.parseFor();if(this.check(g.BREAK))return this.advance(),{type:"break"};if(this.check(g.CONTINUE))return this.advance(),{type:"continue"};if(this.check(g.NEXT))return this.advance(),{type:"next"};if(this.check(g.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(g.EXIT)){this.advance();let r;return!this.check(g.NEWLINE)&&!this.check(g.SEMICOLON)&&!this.check(g.RBRACE)&&!this.check(g.EOF)&&(r=this.parseExpression()),{type:"exit",code:r}}if(this.check(g.RETURN)){this.advance();let r;return!this.check(g.NEWLINE)&&!this.check(g.SEMICOLON)&&!this.check(g.RBRACE)&&!this.check(g.EOF)&&(r=this.parseExpression()),{type:"return",value:r}}if(this.check(g.DELETE)){this.advance();let r=this.parsePrimary();if(r.type!=="array_access"&&r.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:r}}return this.check(g.PRINT)?this.parsePrint():this.check(g.PRINTF)?this.parsePrintf():{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(g.IF),this.expect(g.LPAREN);let e=this.parseExpression();this.expect(g.RPAREN),this.skipNewlines();let r=this.parseStatement();this.skipTerminators();let n;return this.check(g.ELSE)&&(this.advance(),this.skipNewlines(),n=this.parseStatement()),{type:"if",condition:e,consequent:r,alternate:n}}parseWhile(){this.expect(g.WHILE),this.expect(g.LPAREN);let e=this.parseExpression();this.expect(g.RPAREN),this.skipNewlines();let r=this.parseStatement();return{type:"while",condition:e,body:r}}parseDoWhile(){this.expect(g.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(g.WHILE),this.expect(g.LPAREN);let r=this.parseExpression();return this.expect(g.RPAREN),{type:"do_while",body:e,condition:r}}parseFor(){if(this.expect(g.FOR),this.expect(g.LPAREN),this.check(g.IDENT)){let i=this.advance();if(this.check(g.IN)){this.advance();let a=this.expect(g.IDENT).value;this.expect(g.RPAREN),this.skipNewlines();let o=this.parseStatement();return{type:"for_in",variable:i.value,array:a,body:o}}this.pos--}let e;this.check(g.SEMICOLON)||(e=this.parseExpression()),this.expect(g.SEMICOLON);let r;this.check(g.SEMICOLON)||(r=this.parseExpression()),this.expect(g.SEMICOLON);let n;this.check(g.RPAREN)||(n=this.parseExpression()),this.expect(g.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:r,update:n,body:s}}parsePrint(){this.expect(g.PRINT);let e=[];if(this.check(g.NEWLINE)||this.check(g.SEMICOLON)||this.check(g.RBRACE)||this.check(g.PIPE)||this.check(g.GT)||this.check(g.APPEND))e.push({type:"field",index:{type:"number",value:0}});else for(e.push(this.parsePrintArg());this.check(g.COMMA);)this.advance(),e.push(this.parsePrintArg());let r;return this.check(g.GT)?(this.advance(),r={redirect:">",file:this.parsePrimary()}):this.check(g.APPEND)&&(this.advance(),r={redirect:">>",file:this.parsePrimary()}),{type:"print",args:e,output:r}}parsePrintArg(){return this.lookAheadForTernary()?this.parseTernary():this.parsePrintOr()}lookAheadForTernary(){let e=0,r=this.pos;for(;r<this.tokens.length;){let n=this.tokens[r];if(n.type===g.LPAREN&&e++,n.type===g.RPAREN&&e--,n.type===g.QUESTION&&e===0)return!0;if(n.type===g.NEWLINE||n.type===g.SEMICOLON||n.type===g.RBRACE||n.type===g.COMMA||n.type===g.PIPE)return!1;r++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(g.OR);){this.advance();let r=this.parsePrintAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parsePrintAnd(){let e=this.parsePrintIn();for(;this.check(g.AND);){this.advance();let r=this.parsePrintIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parsePrintIn(){let e=this.parsePrintMatch();if(this.check(g.IN)){this.advance();let r=String(this.expect(g.IDENT).value);return{type:"in",key:e,array:r}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(g.MATCH,g.NOT_MATCH);){let r=this.advance().type===g.MATCH?"~":"!~",n=this.parsePrintComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(g.LT,g.LE,g.GE,g.EQ,g.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parsePrintf(){this.expect(g.PRINTF);let e=this.parsePrintArg(),r=[];for(;this.check(g.COMMA);)this.advance(),r.push(this.parsePrintArg());let n;return this.check(g.GT)?(this.advance(),n={redirect:">",file:this.parsePrimary()}):this.check(g.APPEND)&&(this.advance(),n={redirect:">>",file:this.parsePrimary()}),{type:"printf",format:e,args:r,output:n}}parseExpression(){return this.parseAssignment()}parseAssignment(){let e=this.parseTernary();if(this.match(g.ASSIGN,g.PLUS_ASSIGN,g.MINUS_ASSIGN,g.STAR_ASSIGN,g.SLASH_ASSIGN,g.PERCENT_ASSIGN,g.CARET_ASSIGN)){let r=this.advance(),n=this.parseAssignment();if(e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[r.value],target:e,value:n}}return e}parseTernary(){let e=this.parseOr();if(this.check(g.QUESTION)){this.advance();let r=this.parseExpression();this.expect(g.COLON);let n=this.parseExpression();e={type:"ternary",condition:e,consequent:r,alternate:n}}return e}parseOr(){let e=this.parseAnd();for(;this.check(g.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalOrRest(e){for(e=this.parseLogicalAndRest(e);this.check(g.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalAndRest(e){for(;this.check(g.AND);){this.advance();let r=this.parseIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parseAnd(){let e=this.parseIn();for(;this.check(g.AND);){this.advance();let r=this.parseIn();e={type:"binary",operator:"&&",left:e,right:r}}return e}parseIn(){let e=this.parseMatch();if(this.check(g.IN)){this.advance();let r=this.expect(g.IDENT).value;return{type:"in",key:e,array:r}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(g.MATCH,g.NOT_MATCH);){let r=this.advance().type===g.MATCH?"~":"!~",n=this.parseComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(g.LT,g.LE,g.GT,g.GE,g.EQ,g.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parseConcatenation(){let e=this.parseAddSub();for(;this.canStartExpression()&&!this.isComparisonOrHigherOp();){let r=this.parseAddSub();e={type:"binary",operator:" ",left:e,right:r}}return e}canStartExpression(){return this.match(g.NUMBER,g.STRING,g.IDENT,g.DOLLAR,g.LPAREN,g.NOT,g.MINUS,g.PLUS,g.INCREMENT,g.DECREMENT)}isComparisonOrHigherOp(){return this.match(g.LT,g.LE,g.GT,g.GE,g.EQ,g.NE,g.AND,g.OR,g.QUESTION,g.MATCH,g.NOT_MATCH,g.ASSIGN,g.PLUS_ASSIGN,g.MINUS_ASSIGN,g.STAR_ASSIGN,g.SLASH_ASSIGN,g.PERCENT_ASSIGN,g.CARET_ASSIGN,g.COMMA,g.SEMICOLON,g.NEWLINE,g.RBRACE,g.RPAREN,g.RBRACKET,g.COLON,g.PIPE,g.APPEND,g.IN)}parseAddSub(){let e=this.parseMulDiv();for(;this.match(g.PLUS,g.MINUS);){let r=this.advance().value,n=this.parseMulDiv();e={type:"binary",operator:r,left:e,right:n}}return e}parseMulDiv(){let e=this.parseUnary();for(;this.match(g.STAR,g.SLASH,g.PERCENT);){let r=this.advance(),n=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[r.value],left:e,right:n}}return e}parseUnary(){if(this.check(g.INCREMENT)){this.advance();let e=this.parseUnary();return e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:e}}:{type:"pre_increment",operand:e}}if(this.check(g.DECREMENT)){this.advance();let e=this.parseUnary();return e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:e}}:{type:"pre_decrement",operand:e}}if(this.match(g.NOT,g.MINUS,g.PLUS)){let e=this.advance().value,r=this.parseUnary();return{type:"unary",operator:e,operand:r}}return this.parsePower()}parsePower(){let e=this.parsePostfix();if(this.check(g.CARET)){this.advance();let r=this.parsePower();e={type:"binary",operator:"^",left:e,right:r}}return e}parsePostfix(){let e=this.parsePrimary();if(this.check(g.INCREMENT)){if(this.advance(),e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:e}}if(this.check(g.DECREMENT)){if(this.advance(),e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:e}}return e}parsePrimary(){if(this.check(g.NUMBER))return{type:"number",value:this.advance().value};if(this.check(g.STRING))return{type:"string",value:this.advance().value};if(this.check(g.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(g.DOLLAR))return this.advance(),{type:"field",index:this.parsePrimary()};if(this.check(g.LPAREN)){this.advance();let e=this.parseExpression();if(this.check(g.COMMA)){let r=[e];for(;this.check(g.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(g.RPAREN),{type:"tuple",elements:r}}return this.expect(g.RPAREN),e}if(this.check(g.GETLINE)){this.advance();let e,r;return this.check(g.IDENT)&&(e=this.advance().value),this.check(g.LT)&&(this.advance(),r=this.parsePrimary()),{type:"getline",variable:e,file:r}}if(this.check(g.IDENT)){let e=this.advance().value;if(this.check(g.LPAREN)){this.advance();let r=[];if(!this.check(g.RPAREN))for(r.push(this.parseExpression());this.check(g.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(g.RPAREN),{type:"call",name:e,args:r}}if(this.check(g.LBRACKET)){this.advance();let r=[this.parseExpression()];for(;this.check(g.COMMA);)this.advance(),r.push(this.parseExpression());this.expect(g.RBRACKET);let n;if(r.length===1)n=r[0];else{n=r[0];for(let s=1;s<r.length;s++)n={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:n,right:{type:"variable",name:"SUBSEP"}},right:r[s]}}return{type:"array_access",array:e,key:n}}return{type:"variable",name:e}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}}});var Ta={};R(Ta,{awkCommand2:()=>Vd});function Oa(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
|
|
243
|
+
`).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Pa(t){if(t===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(t))try{return new RegExp(t)}catch{return new RegExp(Fa(t))}return new RegExp(Fa(t))}function Fa(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var qd,Vd,Da=C(()=>{"use strict";J();M();Ia();$a();qd={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},Vd={name:"awk",async execute(t,e){if(v(t))return k(qd);let r=/\s+/,n=" ",s={},i=0;for(let h=0;h<t.length;h++){let p=t[h];if(p==="-F"&&h+1<t.length)n=Oa(t[++h]),r=Pa(n),i=h+1;else if(p.startsWith("-F"))n=Oa(p.slice(2)),r=Pa(n),i=h+1;else if(p==="-v"&&h+1<t.length){let w=t[++h],x=w.indexOf("=");if(x>0){let y=w.slice(0,x),E=w.slice(x+1);s[y]=E}i=h+1}else{if(p.startsWith("--"))return T("awk",p);if(p.startsWith("-")&&p.length>1){let w=p[1];if(w!=="F"&&w!=="v")return T("awk",`-${w}`);i=h+1}else if(!p.startsWith("-")){i=h;break}}}if(i>=t.length)return{stdout:"",stderr:`awk: missing program
|
|
244
|
+
`,exitCode:1};let a=t[i],o=t.slice(i+1),l=new vr,c;try{c=l.parse(a)}catch(h){return{stdout:"",stderr:`awk: ${h instanceof Error?h.message:String(h)}
|
|
245
|
+
`,exitCode:1}}let u={readFile:e.fs.readFile.bind(e.fs),writeFile:e.fs.writeFile.bind(e.fs),appendFile:async(h,p)=>{try{let w=await e.fs.readFile(h);await e.fs.writeFile(h,w+p)}catch{await e.fs.writeFile(h,p)}},resolvePath:e.fs.resolvePath.bind(e.fs)},f=Pn({fieldSep:r,maxIterations:e.limits?.maxAwkIterations,fs:u,cwd:e.cwd});f.FS=n,f.vars={...s},f.ARGC=o.length+1,f.ARGV={0:"awk"};for(let h=0;h<o.length;h++)f.ARGV[String(h+1)]=o[h];let d=new Vt(f);d.execute(c);try{if(await d.executeBegin(),f.shouldExit)return{stdout:d.getOutput(),stderr:"",exitCode:d.getExitCode()};let h=[];if(o.length>0)for(let p of o)try{let w=e.fs.resolvePath(e.cwd,p),y=(await e.fs.readFile(w)).split(`
|
|
246
|
+
`);y.length>0&&y[y.length-1]===""&&y.pop(),h.push({filename:p,lines:y})}catch{return{stdout:"",stderr:`awk: ${p}: No such file or directory
|
|
247
247
|
`,exitCode:1}}else{let p=e.stdin.split(`
|
|
248
|
-
`);p.length>0&&p[p.length-1]===""&&p.pop(),h.push({filename:"",lines:p})}for(let p of h){for(f.FILENAME=p.filename,f.FNR=0,f.lines=p.lines,f.lineIndex=-1,f.shouldNextFile=!1;f.lineIndex<p.lines.length-1&&(f.lineIndex++,await d.executeLine(p.lines[f.lineIndex]),!(f.shouldExit||f.shouldNextFile)););if(f.shouldExit)break}return f.shouldExit||await d.executeEnd(),{stdout:d.getOutput(),stderr:"",exitCode:d.getExitCode()}}catch(h){let p=h instanceof Error?h.message:String(h),
|
|
249
|
-
`,exitCode:
|
|
248
|
+
`);p.length>0&&p[p.length-1]===""&&p.pop(),h.push({filename:"",lines:p})}for(let p of h){for(f.FILENAME=p.filename,f.FNR=0,f.lines=p.lines,f.lineIndex=-1,f.shouldNextFile=!1;f.lineIndex<p.lines.length-1&&(f.lineIndex++,await d.executeLine(p.lines[f.lineIndex]),!(f.shouldExit||f.shouldNextFile)););if(f.shouldExit)break}return f.shouldExit||await d.executeEnd(),{stdout:d.getOutput(),stderr:"",exitCode:d.getExitCode()}}catch(h){let p=h instanceof Error?h.message:String(h),w=h instanceof z?z.EXIT_CODE:2;return{stdout:d.getOutput(),stderr:`awk: ${p}
|
|
249
|
+
`,exitCode:w}}}}});function La(t){let e=t.trim(),r=e.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!r){let a=parseFloat(e);return Number.isNaN(a)?0:a}let n=parseFloat(r[1]),s=(r[2]||"").toLowerCase(),i=Zd[s]||1;return n*i}function Ma(t){let e=t.trim().toLowerCase().slice(0,3);return Qd[e]||0}function Xd(t,e){let r=t.split(/(\d+)/),n=e.split(/(\d+)/),s=Math.max(r.length,n.length);for(let i=0;i<s;i++){let a=r[i]||"",o=n[i]||"",l=/^\d+$/.test(a)?parseInt(a,10):null,c=/^\d+$/.test(o)?parseInt(o,10):null;if(l!==null&&c!==null){if(l!==c)return l-c}else if(a!==o)return a.localeCompare(o)}return 0}function _a(t){return t.replace(/[^a-zA-Z0-9\s]/g,"")}function Un(t,e,r){let n=r!==null?r:/\s+/,s=t.split(n),i=e.startField-1;if(i>=s.length)return"";if(e.endField===void 0){let l=s[i]||"";return e.startChar!==void 0&&(l=l.slice(e.startChar-1)),e.ignoreLeading&&(l=l.trimStart()),l}let a=Math.min(e.endField-1,s.length-1),o="";for(let l=i;l<=a&&l<s.length;l++){let c=s[l]||"";if(l===i&&e.startChar!==void 0&&(c=c.slice(e.startChar-1)),l===a&&e.endChar!==void 0){let u=l===i&&e.startChar!==void 0?e.endChar-e.startChar+1:e.endChar;c=c.slice(0,u)}l>i&&(o+=r||" "),o+=c}return e.ignoreLeading&&(o=o.trimStart()),o}function Ba(t,e,r){let n=t,s=e;if(r.dictionaryOrder&&(n=_a(n),s=_a(s)),r.ignoreCase&&(n=n.toLowerCase(),s=s.toLowerCase()),r.monthSort){let i=Ma(n),a=Ma(s);return i-a}if(r.humanNumeric){let i=La(n),a=La(s);return i-a}if(r.versionSort)return Xd(n,s);if(r.numeric){let i=parseFloat(n)||0,a=parseFloat(s)||0;return i-a}return n.localeCompare(s)}function Wa(t){let{keys:e,fieldDelimiter:r,numeric:n,ignoreCase:s,reverse:i,humanNumeric:a,versionSort:o,dictionaryOrder:l,monthSort:c,ignoreLeadingBlanks:u,stable:f}=t;return(d,h)=>{let p=d,w=h;if(u&&(p=p.trimStart(),w=w.trimStart()),e.length===0){let y=Ba(p,w,{numeric:n,ignoreCase:s,humanNumeric:a,versionSort:o,dictionaryOrder:l,monthSort:c});if(y!==0)return i?-y:y;if(!f){let E=d.localeCompare(h);return i?-E:E}return 0}for(let x of e){let y=Un(p,x,r),E=Un(w,x,r);x.ignoreLeading&&(y=y.trimStart(),E=E.trimStart());let b={numeric:x.numeric??n,ignoreCase:x.ignoreCase??s,humanNumeric:x.humanNumeric??a,versionSort:x.versionSort??o,dictionaryOrder:x.dictionaryOrder??l,monthSort:x.monthSort??c},S=x.reverse??i,A=Ba(y,E,b);if(A!==0)return S?-A:A}if(!f){let x=d.localeCompare(h);return i?-x:x}return 0}}function Ua(t,e){if(e.keys.length===0){if(e.ignoreCase){let s=new Set;return t.filter(i=>{let a=i.toLowerCase();return s.has(a)?!1:(s.add(a),!0)})}return[...new Set(t)]}let r=e.keys[0],n=new Set;return t.filter(s=>{let i=Un(s,r,e.fieldDelimiter);return(r.ignoreCase??e.ignoreCase)&&(i=i.toLowerCase()),n.has(i)?!1:(n.add(i),!0)})}var Zd,Qd,za=C(()=>{"use strict";Zd={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},Qd={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12}});function Nr(t){let e={startField:1},r="",n=t,s=n.match(/([bdfhMnrV]+)$/);s&&(r=s[1],n=n.slice(0,-r.length)),r.includes("n")&&(e.numeric=!0),r.includes("r")&&(e.reverse=!0),r.includes("f")&&(e.ignoreCase=!0),r.includes("b")&&(e.ignoreLeading=!0),r.includes("h")&&(e.humanNumeric=!0),r.includes("V")&&(e.versionSort=!0),r.includes("d")&&(e.dictionaryOrder=!0),r.includes("M")&&(e.monthSort=!0);let i=n.split(",");if(i.length===0||i[0]==="")return null;let a=i[0].split("."),o=parseInt(a[0],10);if(Number.isNaN(o)||o<1)return null;if(e.startField=o,a.length>1&&a[1]){let l=parseInt(a[1],10);!Number.isNaN(l)&&l>=1&&(e.startChar=l)}if(i.length>1&&i[1]){let l=i[1],c=l.match(/([bdfhMnrV]+)$/);if(c){let f=c[1];f.includes("n")&&(e.numeric=!0),f.includes("r")&&(e.reverse=!0),f.includes("f")&&(e.ignoreCase=!0),f.includes("b")&&(e.ignoreLeading=!0),f.includes("h")&&(e.humanNumeric=!0),f.includes("V")&&(e.versionSort=!0),f.includes("d")&&(e.dictionaryOrder=!0),f.includes("M")&&(e.monthSort=!0),l=l.slice(0,-f.length)}let u=l.split(".");if(u[0]){let f=parseInt(u[0],10);if(!Number.isNaN(f)&&f>=1&&(e.endField=f),u.length>1&&u[1]){let d=parseInt(u[1],10);!Number.isNaN(d)&&d>=1&&(e.endChar=d)}}}return e}var Ha=C(()=>{"use strict"});var ja={};R(ja,{sortCommand:()=>Jd});var Kd,Jd,Ga=C(()=>{"use strict";St();M();za();Ha();Kd={name:"sort",summary:"sort lines of text files",usage:"sort [OPTION]... [FILE]...",options:["-b, --ignore-leading-blanks ignore leading blanks","-d, --dictionary-order consider only blanks and alphanumeric characters","-f, --ignore-case fold lower case to upper case characters","-h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)","-M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'","-n, --numeric-sort compare according to string numerical value","-r, --reverse reverse the result of comparisons","-V, --version-sort natural sort of (version) numbers within text","-c, --check check for sorted input; do not sort","-o, --output=FILE write result to FILE instead of stdout","-s, --stable stabilize sort by disabling last-resort comparison","-u, --unique output only unique lines","-k, --key=KEYDEF sort via a key; KEYDEF gives location and type","-t, --field-separator=SEP use SEP as field separator"," --help display this help and exit"],description:`KEYDEF is F[.C][OPTS][,F[.C][OPTS]]
|
|
250
250
|
F is a field number (1-indexed)
|
|
251
251
|
C is a character position within the field (1-indexed)
|
|
252
|
-
OPTS can be:
|
|
252
|
+
OPTS can be: b d f h M n r V (per-key modifiers)
|
|
253
253
|
|
|
254
254
|
Examples:
|
|
255
255
|
-k1 sort by first field
|
|
256
256
|
-k2,2 sort by second field only
|
|
257
257
|
-k1.3 sort by first field starting at 3rd character
|
|
258
258
|
-k1,2n sort by fields 1-2 numerically
|
|
259
|
-
-k2 -k1 sort by field 2, then by field 1`}
|
|
260
|
-
`);a.length>0&&a[a.length-1]===""&&a.pop();let o
|
|
259
|
+
-k2 -k1 sort by field 2, then by field 1`},Jd={name:"sort",async execute(t,e){if(v(t))return k(Kd);let r={reverse:!1,numeric:!1,unique:!1,ignoreCase:!1,humanNumeric:!1,versionSort:!1,dictionaryOrder:!1,monthSort:!1,ignoreLeadingBlanks:!1,stable:!1,checkOnly:!1,outputFile:null,keys:[],fieldDelimiter:null},n=[];for(let c=0;c<t.length;c++){let u=t[c];if(u==="-r"||u==="--reverse")r.reverse=!0;else if(u==="-n"||u==="--numeric-sort")r.numeric=!0;else if(u==="-u"||u==="--unique")r.unique=!0;else if(u==="-f"||u==="--ignore-case")r.ignoreCase=!0;else if(u==="-h"||u==="--human-numeric-sort")r.humanNumeric=!0;else if(u==="-V"||u==="--version-sort")r.versionSort=!0;else if(u==="-d"||u==="--dictionary-order")r.dictionaryOrder=!0;else if(u==="-M"||u==="--month-sort")r.monthSort=!0;else if(u==="-b"||u==="--ignore-leading-blanks")r.ignoreLeadingBlanks=!0;else if(u==="-s"||u==="--stable")r.stable=!0;else if(u==="-c"||u==="--check")r.checkOnly=!0;else if(u==="-o"||u==="--output")r.outputFile=t[++c]||null;else if(u.startsWith("-o"))r.outputFile=u.slice(2)||null;else if(u.startsWith("--output="))r.outputFile=u.slice(9)||null;else if(u==="-t"||u==="--field-separator")r.fieldDelimiter=t[++c]||null;else if(u.startsWith("-t"))r.fieldDelimiter=u.slice(2)||null;else if(u.startsWith("--field-separator="))r.fieldDelimiter=u.slice(18)||null;else if(u==="-k"||u==="--key"){let f=t[++c];if(f){let d=Nr(f);d&&r.keys.push(d)}}else if(u.startsWith("-k")){let f=Nr(u.slice(2));f&&r.keys.push(f)}else if(u.startsWith("--key=")){let f=Nr(u.slice(6));f&&r.keys.push(f)}else{if(u.startsWith("--"))return T("sort",u);if(u.startsWith("-")&&!u.startsWith("--")){let f=!1;for(let d of u.slice(1))if(d==="r")r.reverse=!0;else if(d==="n")r.numeric=!0;else if(d==="u")r.unique=!0;else if(d==="f")r.ignoreCase=!0;else if(d==="h")r.humanNumeric=!0;else if(d==="V")r.versionSort=!0;else if(d==="d")r.dictionaryOrder=!0;else if(d==="M")r.monthSort=!0;else if(d==="b")r.ignoreLeadingBlanks=!0;else if(d==="s")r.stable=!0;else if(d==="c")r.checkOnly=!0;else{f=!0;break}if(f)return T("sort",u)}else n.push(u)}}let s=await bt(e,n,{cmdName:"sort"});if(!s.ok)return s.error;let a=s.content.split(`
|
|
260
|
+
`);a.length>0&&a[a.length-1]===""&&a.pop();let o=Wa(r);if(r.checkOnly){let c=n.length>0?n[0]:"-";for(let u=1;u<a.length;u++)if(o(a[u-1],a[u])>0)return{stdout:"",stderr:`sort: ${c}:${u+1}: disorder: ${a[u]}
|
|
261
|
+
`,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}a.sort(o),r.unique&&(a=Ua(a,r));let l=a.length>0?`${a.join(`
|
|
261
262
|
`)}
|
|
262
|
-
`:"",stderr:"",exitCode:0}}}});var
|
|
263
|
-
`);if(u.length>0&&u[u.length-1]===""&&u.pop(),u.length===0)return{stdout:"",stderr:"",exitCode:0};let f=[],d=u[0],h=1,p=(
|
|
264
|
-
`:
|
|
265
|
-
`;return{stdout:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
263
|
+
`:"";if(r.outputFile){let c=e.fs.resolvePath(e.cwd,r.outputFile);return await e.fs.writeFile(c,l),{stdout:"",stderr:"",exitCode:0}}return{stdout:l,stderr:"",exitCode:0}}}});var qa={};R(qa,{uniqCommand:()=>th});var Yd,eh,th,Va=C(()=>{"use strict";ue();St();M();Yd={name:"uniq",summary:"report or omit repeated lines",usage:"uniq [OPTION]... [INPUT [OUTPUT]]",options:["-c, --count prefix lines by the number of occurrences","-d, --repeated only print duplicate lines","-i, --ignore-case ignore case when comparing","-u, --unique only print unique lines"," --help display this help and exit"]},eh={count:{short:"c",long:"count",type:"boolean"},duplicatesOnly:{short:"d",long:"repeated",type:"boolean"},uniqueOnly:{short:"u",long:"unique",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},th={name:"uniq",async execute(t,e){if(v(t))return k(Yd);let r=j("uniq",t,eh);if(!r.ok)return r.error;let{count:n,duplicatesOnly:s,uniqueOnly:i,ignoreCase:a}=r.result.flags,o=r.result.positional,l=await bt(e,o,{cmdName:"uniq"});if(!l.ok)return l.error;let u=l.content.split(`
|
|
264
|
+
`);if(u.length>0&&u[u.length-1]===""&&u.pop(),u.length===0)return{stdout:"",stderr:"",exitCode:0};let f=[],d=u[0],h=1,p=(y,E)=>a?y.toLowerCase()===E.toLowerCase():y===E;for(let y=1;y<u.length;y++)p(u[y],d)?h++:(f.push({line:d,count:h}),d=u[y],h=1);f.push({line:d,count:h});let w=f;s?w=f.filter(y=>y.count>1):i&&(w=f.filter(y=>y.count===1));let x="";for(let{line:y,count:E}of w)n?x+=`${String(E).padStart(4)} ${y}
|
|
265
|
+
`:x+=`${y}
|
|
266
|
+
`;return{stdout:x,stderr:"",exitCode:0}}}});var Za={};R(Za,{commCommand:()=>nh});var rh,nh,Qa=C(()=>{"use strict";M();rh={name:"comm",summary:"compare two sorted files line by line",usage:"comm [OPTION]... FILE1 FILE2",options:["-1 suppress column 1 (lines unique to FILE1)","-2 suppress column 2 (lines unique to FILE2)","-3 suppress column 3 (lines that appear in both files)"," --help display this help and exit"]},nh={name:"comm",async execute(t,e){if(v(t))return k(rh);let r=!1,n=!1,s=!1,i=[];for(let x of t)if(x==="-1")r=!0;else if(x==="-2")n=!0;else if(x==="-3")s=!0;else if(x==="-12"||x==="-21")r=!0,n=!0;else if(x==="-13"||x==="-31")r=!0,s=!0;else if(x==="-23"||x==="-32")n=!0,s=!0;else if(x==="-123"||x==="-132"||x==="-213"||x==="-231"||x==="-312"||x==="-321")r=!0,n=!0,s=!0;else{if(x.startsWith("-")&&x!=="-")return T("comm",x);i.push(x)}if(i.length!==2)return{stdout:"",stderr:`comm: missing operand
|
|
267
|
+
Try 'comm --help' for more information.
|
|
268
|
+
`,exitCode:1};let a=async x=>{if(x==="-")return e.stdin;try{let y=e.fs.resolvePath(e.cwd,x);return await e.fs.readFile(y)}catch{return null}},o=await a(i[0]);if(o===null)return{stdout:"",stderr:`comm: ${i[0]}: No such file or directory
|
|
269
|
+
`,exitCode:1};let l=await a(i[1]);if(l===null)return{stdout:"",stderr:`comm: ${i[1]}: No such file or directory
|
|
270
|
+
`,exitCode:1};let c=o.split(`
|
|
271
|
+
`),u=l.split(`
|
|
272
|
+
`);c.length>0&&c[c.length-1]===""&&c.pop(),u.length>0&&u[u.length-1]===""&&u.pop();let f=0,d=0,h="",p=r?"":" ",w=(r?"":" ")+(n?"":" ");for(;f<c.length||d<u.length;)f>=c.length?(n||(h+=`${p}${u[d]}
|
|
273
|
+
`),d++):d>=u.length?(r||(h+=`${c[f]}
|
|
274
|
+
`),f++):c[f]<u[d]?(r||(h+=`${c[f]}
|
|
275
|
+
`),f++):c[f]>u[d]?(n||(h+=`${p}${u[d]}
|
|
276
|
+
`),d++):(s||(h+=`${w}${c[f]}
|
|
277
|
+
`),f++,d++);return{stdout:h,stderr:"",exitCode:0}}}});var Xa={};R(Xa,{cutCommand:()=>oh});function ih(t){let e=[],r=t.split(",");for(let n of r)if(n.includes("-")){let[s,i]=n.split("-");e.push({start:s?parseInt(s,10):1,end:i?parseInt(i,10):null})}else{let s=parseInt(n,10);e.push({start:s,end:s})}return e}function ah(t,e){let r=[];for(let n of e){let s=n.start-1,i=n.end===null?t.length:n.end;for(let a=s;a<i&&a<t.length;a++)a>=0&&!r.includes(t[a])&&r.push(t[a])}return r}var sh,oh,Ka=C(()=>{"use strict";St();M();sh={name:"cut",summary:"remove sections from each line of files",usage:"cut [OPTION]... [FILE]...",options:["-c LIST select only these characters","-d DELIM use DELIM instead of TAB for field delimiter","-f LIST select only these fields","-s, --only-delimited do not print lines without delimiters"," --help display this help and exit"]};oh={name:"cut",async execute(t,e){if(v(t))return k(sh);let r=" ",n=null,s=null,i=!1,a=[];for(let d=0;d<t.length;d++){let h=t[d];if(h==="-d")r=t[++d]||" ";else if(h.startsWith("-d"))r=h.slice(2);else if(h==="-f")n=t[++d];else if(h.startsWith("-f"))n=h.slice(2);else if(h==="-c")s=t[++d];else if(h.startsWith("-c"))s=h.slice(2);else if(h==="-s"||h==="--only-delimited")i=!0;else{if(h.startsWith("--"))return T("cut",h);if(h.startsWith("-")){let p=!1;for(let w of h.slice(1))if(w==="s")i=!0;else if(!"dfc".includes(w)){p=!0;break}if(p)return T("cut",h)}else a.push(h)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
|
|
278
|
+
`,exitCode:1};let o=await bt(e,a,{cmdName:"cut"});if(!o.ok)return o.error;let c=o.content.split(`
|
|
279
|
+
`);c.length>0&&c[c.length-1]===""&&c.pop();let u=ih(n||s||"1"),f="";for(let d of c)if(s){let h=d.split(""),p=[];for(let w of u){let x=w.start-1,y=w.end===null?h.length:w.end;for(let E=x;E<y&&E<h.length;E++)E>=0&&p.push(h[E])}f+=`${p.join("")}
|
|
280
|
+
`}else{if(i&&!d.includes(r))continue;let h=d.split(r),p=ah(h,u);f+=`${p.join(r)}
|
|
281
|
+
`}return{stdout:f,stderr:"",exitCode:0}}}});var Ya={};R(Ya,{pasteCommand:()=>uh});function Ja(t,e){if(t.length===0)return"";if(t.length===1)return t[0];let r=t[0];for(let n=1;n<t.length;n++){let s=(n-1)%e.length;r+=e[s]+t[n]}return r}var lh,ch,uh,eo=C(()=>{"use strict";ue();M();lh={name:"paste",summary:"merge lines of files",usage:"paste [OPTION]... [FILE]...",description:["Write lines consisting of the sequentially corresponding lines from","each FILE, separated by TABs, to standard output.","","With no FILE, or when FILE is -, read standard input."],options:["-d, --delimiters=LIST reuse characters from LIST instead of TABs","-s, --serial paste one file at a time instead of in parallel"," --help display this help and exit"],examples:["paste file1 file2 Merge file1 and file2 side by side","paste -d, file1 file2 Use comma as delimiter","paste -s file1 Paste all lines of file1 on one line","paste - - < file Paste pairs of lines from file"]},ch={delimiter:{short:"d",long:"delimiters",type:"string",default:" "},serial:{short:"s",long:"serial",type:"boolean"}},uh={name:"paste",async execute(t,e){if(v(t))return k(lh);let r=j("paste",t,ch);if(!r.ok)return r.error;let n=r.result.flags.delimiter,s=r.result.flags.serial,i=r.result.positional;if(i.length===0)return{stdout:"",stderr:`usage: paste [-s] [-d delimiters] file ...
|
|
270
282
|
`,exitCode:1};let a=e.stdin?e.stdin.split(`
|
|
271
|
-
`):[""];a.length>0&&a[a.length-1]===""&&a.pop();let o=i.filter(f=>f==="-").length,
|
|
272
|
-
`);p.length>0&&p[p.length-1]===""&&p.pop(),
|
|
273
|
-
`,exitCode:1}}}let u="";if(s)for(let f of
|
|
274
|
-
`);else{let f=Math.max(...
|
|
275
|
-
`}}return{stdout:u,stderr:"",exitCode:0}}}});var
|
|
276
|
-
`:n==="t"?e+=" ":n==="r"?e+="\r":e+=n,r+=2;continue}if(r+2<t.length&&t[r+1]==="-"){let n=t.charCodeAt(r),s=t.charCodeAt(r+2);for(let i=n;i<=s;i++)e+=String.fromCharCode(i);r+=3;continue}e+=t[r],r++}return e}var
|
|
283
|
+
`):[""];a.length>0&&a[a.length-1]===""&&a.pop();let o=i.filter(f=>f==="-").length,l=[],c=0;for(let f of i)if(f==="-"){let d=[];for(let h=c;h<a.length;h+=o)d.push(a[h]);l.push(d),c++}else{let d=e.fs.resolvePath(e.cwd,f);try{let p=(await e.fs.readFile(d)).split(`
|
|
284
|
+
`);p.length>0&&p[p.length-1]===""&&p.pop(),l.push(p)}catch{return{stdout:"",stderr:`paste: ${f}: No such file or directory
|
|
285
|
+
`,exitCode:1}}}let u="";if(s)for(let f of l)f&&(u+=`${Ja(f,n)}
|
|
286
|
+
`);else{let f=Math.max(...l.map(d=>d?.length??0));for(let d=0;d<f;d++){let h=[];for(let p of l)h.push(p?.[d]??"");u+=`${Ja(h,n)}
|
|
287
|
+
`}}return{stdout:u,stderr:"",exitCode:0}}}});var ro={};R(ro,{trCommand:()=>ph});function to(t){let e="",r=0;for(;r<t.length;){if(t[r]==="["&&t[r+1]===":"){let n=!1;for(let[s,i]of Object.entries(dh))if(t.slice(r).startsWith(s)){e+=i,r+=s.length,n=!0;break}if(n)continue}if(t[r]==="\\"&&r+1<t.length){let n=t[r+1];n==="n"?e+=`
|
|
288
|
+
`:n==="t"?e+=" ":n==="r"?e+="\r":e+=n,r+=2;continue}if(r+2<t.length&&t[r+1]==="-"){let n=t.charCodeAt(r),s=t.charCodeAt(r+2);for(let i=n;i<=s;i++)e+=String.fromCharCode(i);r+=3;continue}e+=t[r],r++}return e}var fh,dh,hh,ph,no=C(()=>{"use strict";ue();M();fh={name:"tr",summary:"translate or delete characters",usage:"tr [OPTION]... SET1 [SET2]",options:["-c, -C, --complement use the complement of SET1","-d, --delete delete characters in SET1","-s, --squeeze-repeats squeeze repeated characters"," --help display this help and exit"],description:`SET syntax:
|
|
277
289
|
a-z character range
|
|
278
290
|
[:alnum:] all letters and digits
|
|
279
291
|
[:alpha:] all letters
|
|
@@ -287,120 +299,144 @@ Examples:
|
|
|
287
299
|
[:graph:] all printable characters except space
|
|
288
300
|
[:cntrl:] all control characters
|
|
289
301
|
[:xdigit:] all hexadecimal digits
|
|
290
|
-
\\n, \\t, \\r escape sequences`},
|
|
291
|
-
\r\f\v`,"[:upper:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","[:xdigit:]":"0123456789ABCDEFabcdef"};
|
|
302
|
+
\\n, \\t, \\r escape sequences`},dh={"[:alnum:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","[:alpha:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz","[:blank:]":" ","[:cntrl:]":Array.from({length:32},(t,e)=>String.fromCharCode(e)).join("").concat("\x7F"),"[:digit:]":"0123456789","[:graph:]":Array.from({length:94},(t,e)=>String.fromCharCode(33+e)).join(""),"[:lower:]":"abcdefghijklmnopqrstuvwxyz","[:print:]":Array.from({length:95},(t,e)=>String.fromCharCode(32+e)).join(""),"[:punct:]":"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~","[:space:]":`
|
|
303
|
+
\r\f\v`,"[:upper:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","[:xdigit:]":"0123456789ABCDEFabcdef"};hh={complement:{short:"c",long:"complement",type:"boolean"},complementUpper:{short:"C",type:"boolean"},delete:{short:"d",long:"delete",type:"boolean"},squeeze:{short:"s",long:"squeeze-repeats",type:"boolean"}},ph={name:"tr",async execute(t,e){if(v(t))return k(fh);let r=j("tr",t,hh);if(!r.ok)return r.error;let n=r.result.flags.complement||r.result.flags.complementUpper,s=r.result.flags.delete,i=r.result.flags.squeeze,a=r.result.positional;if(a.length<1)return{stdout:"",stderr:`tr: missing operand
|
|
292
304
|
`,exitCode:1};if(!s&&!i&&a.length<2)return{stdout:"",stderr:`tr: missing operand after SET1
|
|
293
|
-
`,exitCode:1};let o=
|
|
294
|
-
`,o=1}return{stdout:i,stderr:a,exitCode:o}}}});function
|
|
295
|
-
`,actions:[]}}else if(a==="-empty")r.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&s+1<t.length){let o=t[++s],
|
|
296
|
-
`,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=
|
|
297
|
-
`,
|
|
305
|
+
`,exitCode:1};let o=to(a[0]),l=a.length>1?to(a[1]):"",c=e.stdin,u=d=>{let h=o.includes(d);return n?!h:h},f="";if(s)for(let d of c)u(d)||(f+=d);else if(i&&a.length===1){let d="";for(let h of c)u(h)&&h===d||(f+=h,d=h)}else{if(n){let d=l.length>0?l[l.length-1]:"";for(let h of c)o.includes(h)?f+=h:f+=d}else{let d=new Map;for(let h=0;h<o.length;h++){let p=h<l.length?l[h]:l[l.length-1];d.set(o[h],p)}for(let h of c)f+=d.get(h)??h}if(i){let d="",h="";for(let p of f)l.includes(p)&&p===h||(d+=p,h=p);f=d}}return{stdout:f,stderr:"",exitCode:0}}}});var so={};R(so,{teeCommand:()=>xh});var mh,gh,xh,io=C(()=>{"use strict";ue();M();mh={name:"tee",summary:"read from stdin and write to stdout and files",usage:"tee [OPTION]... [FILE]...",options:["-a, --append append to the given FILEs, do not overwrite"," --help display this help and exit"]},gh={append:{short:"a",long:"append",type:"boolean"}},xh={name:"tee",async execute(t,e){if(v(t))return k(mh);let r=j("tee",t,gh);if(!r.ok)return r.error;let{append:n}=r.result.flags,s=r.result.positional,i=e.stdin,a="",o=0;for(let l of s)try{let c=e.fs.resolvePath(e.cwd,l);n?await e.fs.appendFile(c,i):await e.fs.writeFile(c,i)}catch{a+=`tee: ${l}: No such file or directory
|
|
306
|
+
`,o=1}return{stdout:i,stderr:a,exitCode:o}}}});function Ye(t,e){switch(t.type){case"name":return{matches:Ie(e.name,t.pattern,t.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:Ie(e.relativePath,t.pattern,t.ignoreCase),pruned:!1,printed:!1};case"regex":try{let r=t.ignoreCase?"i":"";return{matches:new RegExp(t.pattern,r).test(e.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return t.fileType==="f"?{matches:e.isFile,pruned:!1,printed:!1}:t.fileType==="d"?{matches:e.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:e.isEmpty,pruned:!1,printed:!1};case"mtime":{let n=(Date.now()-e.mtime)/(1e3*60*60*24),s;return t.comparison==="more"?s=n>t.days:t.comparison==="less"?s=n<t.days:s=Math.floor(n)===t.days,{matches:s,pruned:!1,printed:!1}}case"newer":{let r=e.newerRefTimes.get(t.refPath);return r===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:e.mtime>r,pruned:!1,printed:!1}}case"size":{let r=t.value;switch(t.unit){case"c":r=t.value;break;case"k":r=t.value*1024;break;case"M":r=t.value*1024*1024;break;case"G":r=t.value*1024*1024*1024;break;case"b":r=t.value*512;break}let n;return t.comparison==="more"?n=e.size>r:t.comparison==="less"?n=e.size<r:t.unit==="b"?n=Math.ceil(e.size/512)===t.value:n=e.size===r,{matches:n,pruned:!1,printed:!1}}case"perm":{let r=e.mode&511,n=t.mode&511,s;return t.matchType==="exact"?s=r===n:t.matchType==="all"?s=(r&n)===n:s=(r&n)!==0,{matches:s,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let r=Ye(t.expr,e);return{matches:!r.matches,pruned:r.pruned,printed:!1}}case"and":{let r=Ye(t.left,e);if(!r.matches)return{matches:!1,pruned:r.pruned,printed:!1};let n=Ye(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:r.printed||n.printed}}case"or":{let r=Ye(t.left,e);if(r.matches)return r;let n=Ye(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:n.printed}}}}function ao(t){let e=[],r=n=>{n&&(n.type==="newer"?e.push(n.refPath):n.type==="not"?r(n.expr):(n.type==="and"||n.type==="or")&&(r(n.left),r(n.right)))};return r(t),e}var oo=C(()=>{"use strict";vn()});function lo(t,e){let r=[],n=[],s=e;for(;s<t.length;){let a=t[s];if(a==="("||a==="\\("){r.push({type:"lparen"}),s++;continue}if(a===")"||a==="\\)"){r.push({type:"rparen"}),s++;continue}if(a==="-name"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s]}});else if(a==="-iname"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s],ignoreCase:!0}});else if(a==="-path"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s]}});else if(a==="-ipath"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s],ignoreCase:!0}});else if(a==="-regex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s]}});else if(a==="-iregex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s],ignoreCase:!0}});else if(a==="-type"&&s+1<t.length){let o=t[++s];if(o==="f"||o==="d")r.push({type:"expr",expr:{type:"type",fileType:o}});else return{expr:null,pathIndex:s,error:`find: Unknown argument to -type: ${o}
|
|
307
|
+
`,actions:[]}}else if(a==="-empty")r.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&s+1<t.length){let o=t[++s],l="exact",c=o;o.startsWith("+")?(l="more",c=o.slice(1)):o.startsWith("-")&&(l="less",c=o.slice(1));let u=parseInt(c,10);Number.isNaN(u)||r.push({type:"expr",expr:{type:"mtime",days:u,comparison:l}})}else if(a==="-newer"&&s+1<t.length){let o=t[++s];r.push({type:"expr",expr:{type:"newer",refPath:o}})}else if(a==="-size"&&s+1<t.length){let o=t[++s],l="exact",c=o;o.startsWith("+")?(l="more",c=o.slice(1)):o.startsWith("-")&&(l="less",c=o.slice(1));let u=c.match(/^(\d+)([ckMGb])?$/);if(u){let f=parseInt(u[1],10),d=u[2]||"b";r.push({type:"expr",expr:{type:"size",value:f,unit:d,comparison:l}})}}else if(a==="-perm"&&s+1<t.length){let o=t[++s],l="exact",c=o;o.startsWith("-")?(l="all",c=o.slice(1)):o.startsWith("/")&&(l="any",c=o.slice(1));let u=parseInt(c,8);Number.isNaN(u)||r.push({type:"expr",expr:{type:"perm",mode:u,matchType:l}})}else if(a==="-prune")r.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")r.push({type:"not"});else if(a==="-o"||a==="-or")r.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")r.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")s++;else if(a!=="-depth")if(a==="-exec"){let o=[];for(s++;s<t.length&&t[s]!==";"&&t[s]!=="+";)o.push(t[s]),s++;if(s>=t.length)return{expr:null,pathIndex:s,error:"find: missing argument to `-exec'\n",actions:[]};let l=t[s]==="+";n.push({type:"exec",command:o,batchMode:l})}else if(a==="-print")r.push({type:"expr",expr:{type:"print"}}),n.push({type:"print"});else if(a==="-print0")n.push({type:"print0"});else if(a==="-printf"&&s+1<t.length){let o=t[++s];n.push({type:"printf",format:o})}else if(a==="-delete")n.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:s,error:`find: unknown predicate '${a}'
|
|
308
|
+
`,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=yh(r);return i.error?{expr:null,pathIndex:s,error:i.error,actions:n}:{expr:i.expr,pathIndex:s,actions:n}}function yh(t){let e=0;function r(){let o=n();if(!o)return null;for(;e<t.length;){let l=t[e];if(l.type==="op"&&l.op==="or"){e++;let c=n();if(!c)return o;o={type:"or",left:o,right:c}}else break}return o}function n(){let o=s();if(!o)return null;for(;e<t.length;){let l=t[e];if(l.type==="op"&&l.op==="and"){e++;let c=s();if(!c)return o;o={type:"and",left:o,right:c}}else if(l.type==="expr"||l.type==="not"||l.type==="lparen"){let c=s();if(!c)return o;o={type:"and",left:o,right:c}}else break}return o}function s(){if(e<t.length&&t[e].type==="not"){e++;let o=s();return o?{type:"not",expr:o}:null}return i()}function i(){if(e>=t.length)return null;let o=t[e];if(o.type==="lparen"){e++;let l=r();return e<t.length&&t[e].type==="rparen"&&e++,l}return o.type==="expr"?(e++,o.expr):(o.type==="rparen",null)}return{expr:r()}}var co=C(()=>{"use strict"});var uo={};R(uo,{findCommand:()=>bh});function Sh(t,e){let r=pr(t),n="",s=0;for(;s<r.length;)if(r[s]==="%"&&s+1<r.length){if(s++,r[s]==="%"){n+="%",s++;continue}let[i,a,o]=xi(r,s);if(s+=o,s>=r.length){n+="%";break}let l=r[s],c;switch(l){case"f":c=e.name,s++;break;case"h":{let u=e.path.lastIndexOf("/");c=u>0?e.path.slice(0,u):".",s++;break}case"p":c=e.path,s++;break;case"P":{let u=e.startingPoint;e.path===u?c="":e.path.startsWith(`${u}/`)?c=e.path.slice(u.length+1):u==="."&&e.path.startsWith("./")?c=e.path.slice(2):c=e.path,s++;break}case"s":c=String(e.size),s++;break;case"d":c=String(e.depth),s++;break;case"m":c=(e.mode&511).toString(8),s++;break;case"M":c=Ch(e.mode,e.isDirectory),s++;break;case"t":{let u=new Date(e.mtime);c=Ah(u),s++;break}case"T":{if(s+1<r.length){let u=r[s+1],f=new Date(e.mtime);c=kh(f,u),s+=2}else c="%T",s++;break}default:n+=`%${i!==0||a!==-1?`${i}.${a}`:""}${l}`,s++;continue}n+=hr(c,i,a)}else n+=r[s],s++;return n}function Ch(t,e){let r=t&511,n=e?"d":"-";return n+=r&256?"r":"-",n+=r&128?"w":"-",n+=r&64?"x":"-",n+=r&32?"r":"-",n+=r&16?"w":"-",n+=r&8?"x":"-",n+=r&4?"r":"-",n+=r&2?"w":"-",n+=r&1?"x":"-",n}function Ah(t){let e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],n=e[t.getDay()],s=r[t.getMonth()],i=String(t.getDate()).padStart(2," "),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0"),l=String(t.getSeconds()).padStart(2,"0"),c=t.getFullYear();return`${n} ${s} ${i} ${a}:${o}:${l} ${c}`}function kh(t,e){switch(e){case"@":return String(t.getTime()/1e3);case"Y":return String(t.getFullYear());case"m":return String(t.getMonth()+1).padStart(2,"0");case"d":return String(t.getDate()).padStart(2,"0");case"H":return String(t.getHours()).padStart(2,"0");case"M":return String(t.getMinutes()).padStart(2,"0");case"S":return String(t.getSeconds()).padStart(2,"0");case"T":return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`;case"F":return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;default:return`%T${e}`}}var wh,Eh,bh,fo=C(()=>{"use strict";M();Cn();oo();co();wh={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},Eh=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),bh={name:"find",async execute(t,e){if(v(t))return k(wh);let r=[],n=null,s=null,i=!1,a=!1;for(let S=0;S<t.length;S++){let A=t[S];if(A==="-maxdepth"&&S+1<t.length)a=!0,n=parseInt(t[++S],10);else if(A==="-mindepth"&&S+1<t.length)a=!0,s=parseInt(t[++S],10);else if(A==="-depth")a=!0,i=!0;else if(A==="-exec")for(a=!0,S++;S<t.length&&t[S]!==";"&&t[S]!=="+";)S++;else!A.startsWith("-")&&A!==";"&&A!=="+"&&A!=="("&&A!==")"&&A!=="\\("&&A!=="\\)"&&A!=="!"?a||r.push(A):Eh.has(A)?(a=!0,S++):(A.startsWith("-")||A==="("||A==="\\("||A==="!")&&(a=!0)}r.length===0&&r.push(".");let{expr:o,error:l,actions:c}=lo(t,0);if(l)return{stdout:"",stderr:l,exitCode:1};let u=c.some(S=>S.type==="print"),f=c.length===0,d=[],h=c.some(S=>S.type==="printf"),p=[],w="",x=0,y=ao(o),E=new Map;for(let S of y){let A=e.fs.resolvePath(e.cwd,S);try{let D=await e.fs.stat(A);E.set(S,D.mtime?.getTime()??Date.now())}catch{}}for(let S of r){let A=e.fs.resolvePath(e.cwd,S);try{await e.fs.stat(A)}catch{w+=`find: ${S}: No such file or directory
|
|
309
|
+
`,x=1;continue}async function D(F,P){if(n!==null&&P>n)return;let B;try{B=await e.fs.stat(F)}catch{return}if(!B)return;let ee;F===A?ee=S.split("/").pop()||S:ee=F.split("/").pop()||"";let de=F===A?S:S==="."?`./${F.slice(A.length+1)}`:S+F.slice(A.length),ne=null;B.isDirectory&&(ne=await e.fs.readdir(F));let Se=B.isFile?B.size===0:ne!==null&&ne.length===0,Ue=()=>{let W=s===null||P>=s,U=!1;if(W&&o!==null){let Ce={name:ee,relativePath:de,isFile:B.isFile,isDirectory:B.isDirectory,isEmpty:Se,mtime:B.mtime?.getTime()??Date.now(),size:B.size??0,mode:B.mode??420,newerRefTimes:E},Le=Ye(o,Ce);W=Le.matches,u?U=Le.printed:U=W}else W&&(U=!0);U&&(d.push(de),h&&p.push({path:de,name:ee,size:B.size??0,mtime:B.mtime?.getTime()??Date.now(),mode:B.mode??420,isDirectory:B.isDirectory,depth:P,startingPoint:S}))},Te=async()=>{if(ne!==null)for(let De of ne){let W=F==="/"?`/${De}`:`${F}/${De}`;await D(W,P+1)}},dr=!1;if(!i&&o!==null){let De={name:ee,relativePath:de,isFile:B.isFile,isDirectory:B.isDirectory,isEmpty:Se,mtime:B.mtime?.getTime()??Date.now(),size:B.size??0,mode:B.mode??420,newerRefTimes:E};dr=Ye(o,De).pruned}i?(await Te(),Ue()):(Ue(),dr||await Te())}await D(A,0)}let b="";if(c.length>0)for(let S of c)switch(S.type){case"print":b+=d.length>0?`${d.join(`
|
|
298
310
|
`)}
|
|
299
|
-
`:"";break;case"print0":
|
|
300
|
-
`,
|
|
301
|
-
`,exitCode:1};if(
|
|
311
|
+
`:"";break;case"print0":b+=d.length>0?`${d.join("\0")}\0`:"";break;case"delete":{let A=[...d].sort((D,F)=>F.length-D.length);for(let D of A){let F=e.fs.resolvePath(e.cwd,D);try{await e.fs.rm(F,{recursive:!1})}catch(P){let B=P instanceof Error?P.message:String(P);w+=`find: cannot delete '${D}': ${B}
|
|
312
|
+
`,x=1}}break}case"printf":for(let A of p)b+=Sh(S.format,A);break;case"exec":if(!e.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
313
|
+
`,exitCode:1};if(S.batchMode){let A=[];for(let P of S.command)P==="{}"?A.push(...d):A.push(P);let D=A.map(P=>`"${P}"`).join(" "),F=await e.exec(D,{cwd:e.cwd});b+=F.stdout,w+=F.stderr,F.exitCode!==0&&(x=F.exitCode)}else for(let A of d){let F=S.command.map(B=>B==="{}"?A:B).map(B=>`"${B}"`).join(" "),P=await e.exec(F,{cwd:e.cwd});b+=P.stdout,w+=P.stderr,P.exitCode!==0&&(x=P.exitCode)}break}else f&&(b=d.length>0?`${d.join(`
|
|
302
314
|
`)}
|
|
303
|
-
`:"");return{stdout:
|
|
304
|
-
basename OPTION... NAME...`,options:["-a, --multiple support multiple arguments","-s, --suffix=SUFFIX remove a trailing SUFFIX"," --help display this help and exit"]},
|
|
305
|
-
`,exitCode:1};!r&&s.length>=2&&(n=s.pop()??"");let i=[];for(let a of s){let o=a.replace(/\/+$/,""),
|
|
315
|
+
`:"");return{stdout:b,stderr:w,exitCode:x}}}});var ho={};R(ho,{basenameCommand:()=>Nh});var vh,Nh,po=C(()=>{"use strict";M();vh={name:"basename",summary:"strip directory and suffix from filenames",usage:`basename NAME [SUFFIX]
|
|
316
|
+
basename OPTION... NAME...`,options:["-a, --multiple support multiple arguments","-s, --suffix=SUFFIX remove a trailing SUFFIX"," --help display this help and exit"]},Nh={name:"basename",async execute(t,e){if(v(t))return k(vh);let r=!1,n="",s=[];for(let a=0;a<t.length;a++){let o=t[a];o==="-a"||o==="--multiple"?r=!0:o==="-s"&&a+1<t.length?(n=t[++a],r=!0):o.startsWith("--suffix=")?(n=o.slice(9),r=!0):o.startsWith("-")||s.push(o)}if(s.length===0)return{stdout:"",stderr:`basename: missing operand
|
|
317
|
+
`,exitCode:1};!r&&s.length>=2&&(n=s.pop()??"");let i=[];for(let a of s){let o=a.replace(/\/+$/,""),l=o.split("/").pop()||o;n&&l.endsWith(n)&&(l=l.slice(0,-n.length)),i.push(l)}return{stdout:`${i.join(`
|
|
306
318
|
`)}
|
|
307
|
-
`,stderr:"",exitCode:0}}}});var
|
|
319
|
+
`,stderr:"",exitCode:0}}}});var mo={};R(mo,{dirnameCommand:()=>Rh});var Ih,Rh,go=C(()=>{"use strict";M();Ih={name:"dirname",summary:"strip last component from file name",usage:"dirname [OPTION] NAME...",options:[" --help display this help and exit"]},Rh={name:"dirname",async execute(t,e){if(v(t))return k(Ih);let r=t.filter(s=>!s.startsWith("-"));if(r.length===0)return{stdout:"",stderr:`dirname: missing operand
|
|
308
320
|
`,exitCode:1};let n=[];for(let s of r){let i=s.replace(/\/+$/,""),a=i.lastIndexOf("/");a===-1?n.push("."):a===0?n.push("/"):n.push(i.slice(0,a))}return{stdout:`${n.join(`
|
|
309
321
|
`)}
|
|
310
|
-
`,stderr:"",exitCode:0}}}});var
|
|
322
|
+
`,stderr:"",exitCode:0}}}});var yo={};R(yo,{treeCommand:()=>Ph});async function Fh(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0},a=t.fs.resolvePath(t.cwd,e);try{if(!(await t.fs.stat(a)).isDirectory)return i.output=`${e}
|
|
311
323
|
`,i.fileCount=1,i}catch{return i.stderr=`tree: ${e}: No such file or directory
|
|
312
324
|
`,i}if(i.output=`${e}
|
|
313
|
-
`,r.maxDepth!==null&&s>=r.maxDepth)return i;try{let
|
|
314
|
-
`,r.maxDepth===null||s+1<r.maxDepth){let
|
|
325
|
+
`,r.maxDepth!==null&&s>=r.maxDepth)return i;try{let l=(await t.fs.readdir(a)).filter(c=>!(!r.showHidden&&c.startsWith(".")));l.sort();for(let c=0;c<l.length;c++){let u=l[c],f=a==="/"?`/${u}`:`${a}/${u}`,d=c===l.length-1,h=d?"`-- ":"|-- ",p=n+(d?" ":"| ");try{if((await t.fs.stat(f)).isDirectory){i.dirCount++;let x=r.fullPath?f:u;if(i.output+=`${n+h+x}
|
|
326
|
+
`,r.maxDepth===null||s+1<r.maxDepth){let y=await xo(t,f,r,p,s+1);i.output+=y.output,i.dirCount+=y.dirCount,i.fileCount+=y.fileCount}}else if(!r.directoriesOnly){i.fileCount++;let x=r.fullPath?f:u;i.output+=`${n+h+x}
|
|
315
327
|
`}}catch{}}}catch{i.stderr=`tree: ${e}: Permission denied
|
|
316
|
-
`}return i}async function
|
|
317
|
-
`;let
|
|
318
|
-
`}}catch{}}}catch{}return i}var
|
|
319
|
-
${o} director${o===1?"y":"ies"}`,n.directoriesOnly||(i+=`, ${
|
|
320
|
-
`,{stdout:i,stderr:a,exitCode:a?1:0}}}});var
|
|
321
|
-
`),i;let o=await t.fs.readdir(e),
|
|
322
|
-
`)}catch{}}i.totalSize=
|
|
328
|
+
`}return i}async function xo(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0};if(r.maxDepth!==null&&s>=r.maxDepth)return i;try{let o=(await t.fs.readdir(e)).filter(l=>!(!r.showHidden&&l.startsWith(".")));o.sort();for(let l=0;l<o.length;l++){let c=o[l],u=e==="/"?`/${c}`:`${e}/${c}`,f=l===o.length-1,d=f?"`-- ":"|-- ",h=n+(f?" ":"| ");try{if((await t.fs.stat(u)).isDirectory){i.dirCount++;let w=r.fullPath?u:c;i.output+=`${n+d+w}
|
|
329
|
+
`;let x=await xo(t,u,r,h,s+1);i.output+=x.output,i.dirCount+=x.dirCount,i.fileCount+=x.fileCount}else if(!r.directoriesOnly){i.fileCount++;let w=r.fullPath?u:c;i.output+=`${n+d+w}
|
|
330
|
+
`}}catch{}}}catch{}return i}var $h,Oh,Ph,wo=C(()=>{"use strict";ue();M();$h={name:"tree",summary:"list contents of directories in a tree-like format",usage:"tree [OPTION]... [DIRECTORY]...",options:["-a include hidden files","-d list directories only","-L LEVEL limit depth of directory tree","-f print full path prefix for each file"," --help display this help and exit"]},Oh={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},Ph={name:"tree",async execute(t,e){if(v(t))return k($h);let r=j("tree",t,Oh);if(!r.ok)return r.error;let n={showHidden:r.result.flags.showHidden,directoriesOnly:r.result.flags.directoriesOnly,maxDepth:r.result.flags.maxDepth??null,fullPath:r.result.flags.fullPath},s=r.result.positional;s.length===0&&s.push(".");let i="",a="",o=0,l=0;for(let c of s){let u=await Fh(e,c,n,"",0);i+=u.output,a+=u.stderr,o+=u.dirCount,l+=u.fileCount}return i+=`
|
|
331
|
+
${o} director${o===1?"y":"ies"}`,n.directoriesOnly||(i+=`, ${l} file${l===1?"":"s"}`),i+=`
|
|
332
|
+
`,{stdout:i,stderr:a,exitCode:a?1:0}}}});var bo={};R(bo,{duCommand:()=>Lh});async function Eo(t,e,r,n,s){let i={output:"",totalSize:0,stderr:""};try{let a=await t.fs.stat(e);if(!a.isDirectory)return i.totalSize=a.size,(n.allFiles||s===0)&&(i.output=Ir(a.size,n.humanReadable)+" "+r+`
|
|
333
|
+
`),i;let o=await t.fs.readdir(e),l=0;for(let c of o){let u=e==="/"?`/${c}`:`${e}/${c}`,f=r==="."?c:`${r}/${c}`;try{let d=await t.fs.stat(u);if(d.isDirectory){let h=await Eo(t,u,f,n,s+1);l+=h.totalSize,n.summarize||(n.maxDepth===null||s+1<=n.maxDepth?i.output+=h.output:l+=0)}else l+=d.size,n.allFiles&&!n.summarize&&(i.output+=Ir(d.size,n.humanReadable)+" "+f+`
|
|
334
|
+
`)}catch{}}i.totalSize=l,(n.summarize||n.maxDepth===null||s<=n.maxDepth)&&(i.output+=`${Ir(l,n.humanReadable)} ${r}
|
|
323
335
|
`)}catch{i.stderr=`du: cannot read directory '${r}': Permission denied
|
|
324
|
-
`}return i}function
|
|
325
|
-
`}}return n.grandTotal&&s.length>0&&(i+=`${
|
|
326
|
-
`),{stdout:i,stderr:a,exitCode:a?1:0}}}});var
|
|
336
|
+
`}return i}function Ir(t,e){return e?t<1024?`${t}`:t<1024*1024?`${(t/1024).toFixed(1)}K`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)}M`:`${(t/(1024*1024*1024)).toFixed(1)}G`:String(Math.ceil(t/1024)||1)}var Th,Dh,Lh,So=C(()=>{"use strict";ue();M();Th={name:"du",summary:"estimate file space usage",usage:"du [OPTION]... [FILE]...",options:["-a write counts for all files, not just directories","-h print sizes in human readable format","-s display only a total for each argument","-c produce a grand total","--max-depth=N print total for directory only if N or fewer levels deep"," --help display this help and exit"]},Dh={allFiles:{short:"a",type:"boolean"},humanReadable:{short:"h",type:"boolean"},summarize:{short:"s",type:"boolean"},grandTotal:{short:"c",type:"boolean"},maxDepth:{long:"max-depth",type:"number"}},Lh={name:"du",async execute(t,e){if(v(t))return k(Th);let r=j("du",t,Dh);if(!r.ok)return r.error;let n={allFiles:r.result.flags.allFiles,humanReadable:r.result.flags.humanReadable,summarize:r.result.flags.summarize,grandTotal:r.result.flags.grandTotal,maxDepth:r.result.flags.maxDepth??null},s=r.result.positional;s.length===0&&s.push(".");let i="",a="",o=0;for(let l of s){let c=e.fs.resolvePath(e.cwd,l);try{await e.fs.stat(c);let u=await Eo(e,c,l,n,0);i+=u.output,o+=u.totalSize,a+=u.stderr}catch{a+=`du: cannot access '${l}': No such file or directory
|
|
337
|
+
`}}return n.grandTotal&&s.length>0&&(i+=`${Ir(o,n.humanReadable)} total
|
|
338
|
+
`),{stdout:i,stderr:a,exitCode:a?1:0}}}});var zn={};R(zn,{envCommand:()=>_h,printenvCommand:()=>Wh});var Mh,_h,Bh,Wh,Hn=C(()=>{"use strict";M();Mh={name:"env",summary:"run a program in a modified environment",usage:"env [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]",options:["-i, --ignore-environment start with an empty environment","-u NAME, --unset=NAME remove NAME from the environment"," --help display this help and exit"]},_h={name:"env",async execute(t,e){if(v(t))return k(Mh);let r=!1,n=[],s={},i=-1;for(let u=0;u<t.length;u++){let f=t[u];if(f==="-i"||f==="--ignore-environment")r=!0;else if(f==="-u"&&u+1<t.length)n.push(t[++u]);else if(f.startsWith("-u"))n.push(f.slice(2));else if(f.startsWith("--unset="))n.push(f.slice(8));else{if(f.startsWith("--")&&f!=="--")return T("env",f);if(f.startsWith("-")&&f!=="-"){for(let d of f.slice(1))if(d!=="i"&&d!=="u")return T("env",`-${d}`);f.includes("i")&&(r=!0)}else if(f.includes("=")&&i===-1){let d=f.indexOf("="),h=f.slice(0,d),p=f.slice(d+1);s[h]=p}else{i=u;break}}}let a;if(r)a={...s};else{a={...e.env};for(let u of n)delete a[u];Object.assign(a,s)}if(i===-1){let u=[];for(let[f,d]of Object.entries(a))u.push(`${f}=${d}`);return{stdout:u.join(`
|
|
327
339
|
`)+(u.length>0?`
|
|
328
340
|
`:""),stderr:"",exitCode:0}}if(!e.exec)return{stdout:"",stderr:`env: command execution not supported in this context
|
|
329
|
-
`,exitCode:1};let o=t.slice(i).join(" "),
|
|
341
|
+
`,exitCode:1};let o=t.slice(i).join(" "),l=Object.entries(s).map(([u,f])=>`${u}="${f}"`).join(" "),c=l?`${l} ${o}`:o;return e.exec(c,{cwd:e.cwd})}},Bh={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:[" --help display this help and exit"]},Wh={name:"printenv",async execute(t,e){if(v(t))return k(Bh);let r=t.filter(i=>!i.startsWith("-"));if(r.length===0){let i=[];for(let[a,o]of Object.entries(e.env))i.push(`${a}=${o}`);return{stdout:i.join(`
|
|
330
342
|
`)+(i.length>0?`
|
|
331
343
|
`:""),stderr:"",exitCode:0}}let n=[],s=0;for(let i of r)i in e.env?n.push(e.env[i]):s=1;return{stdout:n.join(`
|
|
332
344
|
`)+(n.length>0?`
|
|
333
|
-
`:""),stderr:"",exitCode:s}}}});var
|
|
334
|
-
`}return{stdout:r,stderr:"",exitCode:0}}for(let r of t){let n=r.indexOf("=");if(n===-1){let s=
|
|
345
|
+
`:""),stderr:"",exitCode:s}}}});var jn={};R(jn,{aliasCommand:()=>zh,unaliasCommand:()=>Hh});var Uh,Rt,zh,Hh,Gn=C(()=>{"use strict";M();Uh={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},Rt="BASH_ALIAS_",zh={name:"alias",async execute(t,e){if(v(t))return k(Uh);if(t.length===0){let r="";for(let[n,s]of Object.entries(e.env))if(n.startsWith(Rt)){let i=n.slice(Rt.length);r+=`alias ${i}='${s}'
|
|
346
|
+
`}return{stdout:r,stderr:"",exitCode:0}}for(let r of t){let n=r.indexOf("=");if(n===-1){let s=Rt+r;return e.env[s]?{stdout:`alias ${r}='${e.env[s]}'
|
|
335
347
|
`,stderr:"",exitCode:0}:{stdout:"",stderr:`alias: ${r}: not found
|
|
336
|
-
`,exitCode:1}}else{let s=r.slice(0,n),i=r.slice(n+1);(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1)),e.env[
|
|
337
|
-
`,exitCode:1};if(t[0]==="-a"){for(let s of Object.keys(e.env))s.startsWith(
|
|
338
|
-
`,r=!0)}return{stdout:"",stderr:n,exitCode:r?1:0}}}});var
|
|
339
|
-
`}return{stdout:a,stderr:"",exitCode:0}}}});var
|
|
340
|
-
`),e.exec?e.exec(
|
|
341
|
-
`,stderr:"",exitCode:0}},
|
|
348
|
+
`,exitCode:1}}else{let s=r.slice(0,n),i=r.slice(n+1);(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1)),e.env[Rt+s]=i}}return{stdout:"",stderr:"",exitCode:0}}},Hh={name:"unalias",async execute(t,e){if(v(t))return k({name:"unalias",summary:"remove alias definitions",usage:"unalias name [name ...]",options:["-a remove all aliases"," --help display this help and exit"]});if(t.length===0)return{stdout:"",stderr:`unalias: usage: unalias [-a] name [name ...]
|
|
349
|
+
`,exitCode:1};if(t[0]==="-a"){for(let s of Object.keys(e.env))s.startsWith(Rt)&&delete e.env[s];return{stdout:"",stderr:"",exitCode:0}}let r=!1,n="";for(let s of t){let i=Rt+s;e.env[i]?delete e.env[i]:(n+=`unalias: ${s}: not found
|
|
350
|
+
`,r=!0)}return{stdout:"",stderr:n,exitCode:r?1:0}}}});var Ao={};R(Ao,{historyCommand:()=>Gh});var jh,Co,Gh,ko=C(()=>{"use strict";M();jh={name:"history",summary:"display command history",usage:"history [n]",options:["-c clear the history list"," --help display this help and exit"]},Co="BASH_HISTORY",Gh={name:"history",async execute(t,e){if(v(t))return k(jh);let r=e.env[Co]||"[]",n;try{n=JSON.parse(r)}catch{n=[]}if(t[0]==="-c")return e.env[Co]="[]",{stdout:"",stderr:"",exitCode:0};let s=n.length;t[0]&&/^\d+$/.test(t[0])&&(s=Math.min(parseInt(t[0],10),n.length));let i=n.length-s,a="";for(let o=i;o<n.length;o++){let l=(o+1).toString().padStart(5," ");a+=`${l} ${n[o]}
|
|
351
|
+
`}return{stdout:a,stderr:"",exitCode:0}}}});var vo={};R(vo,{xargsCommand:()=>Vh});var qh,Vh,No=C(()=>{"use strict";M();qh={name:"xargs",summary:"build and execute command lines from standard input",usage:"xargs [OPTION]... [COMMAND [INITIAL-ARGS]]",options:["-I REPLACE replace occurrences of REPLACE with input","-n NUM use at most NUM arguments per command line","-P NUM run at most NUM processes at a time","-0, --null items are separated by null, not whitespace","-t, --verbose print commands before executing","-r, --no-run-if-empty do not run command if input is empty"," --help display this help and exit"]},Vh={name:"xargs",async execute(t,e){if(v(t))return k(qh);let r=null,n=null,s=null,i=!1,a=!1,o=!1,l=0;for(let y=0;y<t.length;y++){let E=t[y];if(E==="-I"&&y+1<t.length)r=t[++y],l=y+1;else if(E==="-n"&&y+1<t.length)n=parseInt(t[++y],10),l=y+1;else if(E==="-P"&&y+1<t.length)s=parseInt(t[++y],10),l=y+1;else if(E==="-0"||E==="--null")i=!0,l=y+1;else if(E==="-t"||E==="--verbose")a=!0,l=y+1;else if(E==="-r"||E==="--no-run-if-empty")o=!0,l=y+1;else{if(E.startsWith("--"))return T("xargs",E);if(E.startsWith("-")&&E.length>1){for(let b of E.slice(1))if(!"0tr".includes(b))return T("xargs",`-${b}`);E.includes("0")&&(i=!0),E.includes("t")&&(a=!0),E.includes("r")&&(o=!0),l=y+1}else if(!E.startsWith("-")){l=y;break}}}let c=t.slice(l);c.length===0&&c.push("echo");let u=i?"\0":/\s+/,f=e.stdin.split(u).map(y=>y.trim()).filter(y=>y.length>0);if(f.length===0)return o?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let d="",h="",p=0,w=async y=>{let E=y.join(" ");return a&&(h+=`${E}
|
|
352
|
+
`),e.exec?e.exec(E,{cwd:e.cwd}):{stdout:`${E}
|
|
353
|
+
`,stderr:"",exitCode:0}},x=async y=>{if(s!==null&&s>1)for(let E=0;E<y.length;E+=s){let b=y.slice(E,E+s),S=await Promise.all(b.map(w));for(let A of S)d+=A.stdout,h+=A.stderr,A.exitCode!==0&&(p=A.exitCode)}else for(let E of y){let b=await w(E);d+=b.stdout,h+=b.stderr,b.exitCode!==0&&(p=b.exitCode)}};if(r!==null){let y=f.map(E=>c.map(b=>b.replaceAll(r,E)));await x(y)}else if(n!==null){let y=[];for(let E=0;E<f.length;E+=n){let b=f.slice(E,E+n);y.push([...c,...b])}await x(y)}else{let y=[...c,...f],E=await w(y);d+=E.stdout,h+=E.stderr,p=E.exitCode}return{stdout:d,stderr:h,exitCode:p}}}});var qn={};R(qn,{falseCommand:()=>Qh,trueCommand:()=>Zh});var Zh,Qh,Vn=C(()=>{"use strict";Zh={name:"true",async execute(){return{stdout:"",stderr:"",exitCode:0}}},Qh={name:"false",async execute(){return{stdout:"",stderr:"",exitCode:1}}}});var Io={};R(Io,{clearCommand:()=>Kh});var Xh,Kh,Ro=C(()=>{"use strict";M();Xh={name:"clear",summary:"clear the terminal screen",usage:"clear [OPTIONS]",options:[" --help display this help and exit"]},Kh={name:"clear",async execute(t,e){return v(t)?k(Xh):{stdout:"\x1B[2J\x1B[H",stderr:"",exitCode:0}}}});var Zn={};R(Zn,{bashCommand:()=>Jh,shCommand:()=>Yh});async function Rr(t,e,r,n){if(!n.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
|
|
342
354
|
`,exitCode:1};let s={0:e,"#":String(r.length),"@":r.join(" "),"*":r.join(" ")};r.forEach((u,f)=>{s[String(f+1)]=u});let i=t;if(i.startsWith("#!")){let u=i.indexOf(`
|
|
343
355
|
`);u!==-1&&(i=i.slice(u+1))}let a=i.split(`
|
|
344
|
-
`),o=[];for(let u of a){let f=u.trim();f&&!f.startsWith("#")&&o.push(f)}let
|
|
345
|
-
`,exitCode:127}}}}
|
|
346
|
-
`,exitCode:127}}}}});var
|
|
347
|
-
${t.map(i=>" ".repeat(n+1)+
|
|
356
|
+
`),o=[];for(let u of a){let f=u.trim();f&&!f.startsWith("#")&&o.push(f)}let l=o.join("; ");return await n.exec(l,{env:s,cwd:n.cwd})}var $o,Jh,Yh,Qn=C(()=>{"use strict";M();$o={name:"bash",summary:"execute shell commands or scripts",usage:"bash [OPTIONS] [SCRIPT_FILE] [ARGUMENTS...]",options:["-c COMMAND execute COMMAND string"," --help display this help and exit"],notes:["Without -c, reads and executes commands from SCRIPT_FILE.","Arguments are passed as $1, $2, etc. to the script.",'$0 is set to the script name (or "bash" with -c).']},Jh={name:"bash",async execute(t,e){if(v(t))return k($o);if(t[0]==="-c"&&t.length>=2){let s=t[1],i=t[2]||"bash",a=t.slice(3);return Rr(s,i,a,e)}if(t.length===0)return{stdout:"",stderr:"",exitCode:0};let r=t[0],n=t.slice(1);try{let s=e.fs.resolvePath(e.cwd,r),i=await e.fs.readFile(s);return Rr(i,r,n,e)}catch{return{stdout:"",stderr:`bash: ${r}: No such file or directory
|
|
357
|
+
`,exitCode:127}}}},Yh={name:"sh",async execute(t,e){if(v(t))return k({...$o,name:"sh",summary:"execute shell commands or scripts (POSIX shell)"});if(t[0]==="-c"&&t.length>=2){let s=t[1],i=t[2]||"sh",a=t.slice(3);return Rr(s,i,a,e)}if(t.length===0)return{stdout:"",stderr:"",exitCode:0};let r=t[0],n=t.slice(1);try{let s=e.fs.resolvePath(e.cwd,r),i=await e.fs.readFile(s);return Rr(i,r,n,e)}catch{return{stdout:"",stderr:`sh: ${r}: No such file or directory
|
|
358
|
+
`,exitCode:127}}}}});var Oo={};R(Oo,{jqCommand:()=>tp});function Zt(t,e,r,n=0){if(t===null||t===void 0)return"null";if(typeof t=="boolean"||typeof t=="number")return String(t);if(typeof t=="string")return r?t:JSON.stringify(t);if(Array.isArray(t))return t.length===0?"[]":e?`[${t.map(i=>Zt(i,!0,!1)).join(",")}]`:`[
|
|
359
|
+
${t.map(i=>" ".repeat(n+1)+Zt(i,!1,!1,n+1)).join(`,
|
|
348
360
|
`)}
|
|
349
|
-
${" ".repeat(n)}]`;if(typeof t=="object"){let s=Object.keys(t);return s.length===0?"{}":e?`{${s.map(a=>`${JSON.stringify(a)}:${
|
|
350
|
-
${s.map(a=>{let o=
|
|
361
|
+
${" ".repeat(n)}]`;if(typeof t=="object"){let s=Object.keys(t);return s.length===0?"{}":e?`{${s.map(a=>`${JSON.stringify(a)}:${Zt(t[a],!0,!1)}`).join(",")}}`:`{
|
|
362
|
+
${s.map(a=>{let o=Zt(t[a],!1,!1,n+1);return`${" ".repeat(n+1)}${JSON.stringify(a)}: ${o}`}).join(`,
|
|
351
363
|
`)}
|
|
352
|
-
${" ".repeat(n)}}`}return String(t)}function
|
|
353
|
-
`,exitCode:2}}try{let f;if(a)f=
|
|
354
|
-
`))
|
|
355
|
-
`))
|
|
364
|
+
${" ".repeat(n)}}`}return String(t)}function et(t,e){if(e===""||e===".")return[t];let r=e.startsWith(".")?e.slice(1):e;if(r==="")return[t];if(r.startsWith("[]")){let a=r.slice(2);return Array.isArray(t)?t.flatMap(o=>et(o,`.${a}`)):t&&typeof t=="object"?Object.values(t).flatMap(o=>et(o,`.${a}`)):[]}let n=r.match(/^\[(-?\d+)\](.*)/);if(n){let a=Number.parseInt(n[1],10),o=n[2];if(Array.isArray(t)){let l=a<0?t.length+a:a;if(l>=0&&l<t.length)return et(t[l],`.${o}`)}return[null]}let s=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(s){let a=s[1],o=s[2];if(t&&typeof t=="object"&&!Array.isArray(t)){let c=t[a];if(o.startsWith("[]"))return o=o.slice(2),Array.isArray(c)?c.flatMap(u=>et(u,`.${o}`)):c&&typeof c=="object"?Object.values(c).flatMap(u=>et(u,`.${o}`)):[];if(o.startsWith(".")||o.startsWith("[")||o==="")return et(c,o||".")}return[null]}let i=r.match(/^\["([^"]+)"\](.*)/);if(i){let a=i[1],o=i[2];return t&&typeof t=="object"&&!Array.isArray(t)?et(t[a],`.${o}`):[null]}return[null]}function Qt(t,e){let r=e.trim();if(r.includes("|")){let n=r.split("|").map(i=>i.trim()),s=[t];for(let i of n)s=s.flatMap(a=>Qt(a,i));return s}if(r==="keys")return Array.isArray(t)?[t.map((n,s)=>s)]:t&&typeof t=="object"?[Object.keys(t)]:[null];if(r==="values")return Array.isArray(t)?[t]:t&&typeof t=="object"?[Object.values(t)]:[null];if(r==="length")return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:[null];if(r==="type")return t===null?["null"]:Array.isArray(t)?["array"]:[typeof t];if(r==="first")return Array.isArray(t)&&t.length>0?[t[0]]:[null];if(r==="last")return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];if(r==="reverse")return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];if(r==="sort")return Array.isArray(t)?[[...t].sort()]:[null];if(r==="unique")return Array.isArray(t)?[[...new Set(t.map(n=>JSON.stringify(n)))].map(n=>JSON.parse(n))]:[null];if(r==="flatten")return Array.isArray(t)?[t.flat()]:[null];if(r==="add")return Array.isArray(t)?t.length===0?[null]:t.every(n=>typeof n=="number")?[t.reduce((n,s)=>n+s,0)]:t.every(n=>typeof n=="string")?[t.join("")]:t.every(n=>Array.isArray(n))?[t.flat()]:[null]:[null];if(r==="min")return Array.isArray(t)&&t.length>0?[Math.min(...t)]:[null];if(r==="max")return Array.isArray(t)&&t.length>0?[Math.max(...t)]:[null];if(r==="empty")return[];if(r==="not")return[!t];if(r==="to_entries")return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([n,s])=>({key:n,value:s}))]:[null];if(r==="from_entries"){if(Array.isArray(t)){let n={};for(let s of t)if(s&&typeof s=="object"){let i=s,a=i.key??i.name??i.k,o=i.value??i.v;a!==void 0&&(n[String(a)]=o)}return[n]}return[null]}if(r==="with_entries")return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([n,s])=>({key:n,value:s}))]:[null];if(r==="has")return[t!=null];if(r==="in")return[!1];if(r==="getpath")return[t];if(r==="paths"){let n=[],s=(i,a)=>{if(i&&typeof i=="object")if(Array.isArray(i))for(let o=0;o<i.length;o++)n.push([...a,o]),s(i[o],[...a,o]);else for(let o of Object.keys(i))n.push([...a,o]),s(i[o],[...a,o])};return s(t,[]),[n]}if(r==="leaf_paths"){let n=[],s=(i,a)=>{if(i&&typeof i=="object")if(Array.isArray(i))if(i.length===0)n.push(a);else for(let o=0;o<i.length;o++)s(i[o],[...a,o]);else{let o=Object.keys(i);if(o.length===0)n.push(a);else for(let l of o)s(i[l],[...a,l])}else n.push(a)};return s(t,[]),[n]}if(r==="any")return Array.isArray(t)?[t.some(Boolean)]:[!1];if(r==="all")return Array.isArray(t)?[t.every(Boolean)]:[!0];if(r==="group_by")return Array.isArray(t)?[[t]]:[null];if(r==="unique_by")return Array.isArray(t)?[t]:[null];if(r==="join")return Array.isArray(t)?[t.join("")]:[null];if(r==="splits"||r==="split")return typeof t=="string"?[[t]]:[null];if(r==="ascii_downcase"||r==="ascii_upcase")return typeof t=="string"?[r==="ascii_downcase"?t.toLowerCase():t.toUpperCase()]:[null];if(r==="ltrimstr"||r==="rtrimstr")return[t];if(r==="startswith"||r==="endswith")return[!1];if(r==="contains")return[!1];if(r==="inside")return[!1];if(r==="indices")return[[]];if(r==="index"||r==="rindex")return[null];if(r==="test"||r==="match"||r==="capture")return[null];if(r==="floor")return typeof t=="number"?[Math.floor(t)]:[null];if(r==="ceil")return typeof t=="number"?[Math.ceil(t)]:[null];if(r==="round")return typeof t=="number"?[Math.round(t)]:[null];if(r==="sqrt")return typeof t=="number"?[Math.sqrt(t)]:[null];if(r==="fabs"||r==="abs")return typeof t=="number"?[Math.abs(t)]:[null];if(r==="tostring")return typeof t=="string"?[t]:[JSON.stringify(t)];if(r==="tonumber"){if(typeof t=="number")return[t];if(typeof t=="string"){let n=Number(t);return[Number.isNaN(n)?null:n]}return[null]}if(r==="infinite")return[!Number.isFinite(t)];if(r==="nan")return[Number.isNaN(t)];if(r==="isinfinite")return[typeof t=="number"&&!Number.isFinite(t)];if(r==="isnan")return[typeof t=="number"&&Number.isNaN(t)];if(r==="isnormal")return[typeof t=="number"&&Number.isFinite(t)&&t!==0];if(r==="env")return[{}];if(r==="now")return[Date.now()/1e3];if(r===".."){let n=[],s=i=>{if(n.push(i),Array.isArray(i))for(let a of i)s(a);else if(i&&typeof i=="object")for(let a of Object.keys(i))s(i[a])};return s(t),n}return et(t,r)}var ep,tp,Po=C(()=>{"use strict";M();ep={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input"," --help display this help and exit"]};tp={name:"jq",async execute(t,e){if(v(t))return k(ep);let r=!1,n=!1,s=!1,i=!1,a=!1,o=".",l=!1,c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-r"||d==="--raw-output")r=!0;else if(d==="-c"||d==="--compact-output")n=!0;else if(d==="-e"||d==="--exit-status")s=!0;else if(d==="-s"||d==="--slurp")i=!0;else if(d==="-n"||d==="--null-input")a=!0;else if(d==="-")c.push("-");else{if(d.startsWith("--"))return T("jq",d);if(d.startsWith("-"))for(let h of d.slice(1))if(h==="r")r=!0;else if(h==="c")n=!0;else if(h==="e")s=!0;else if(h==="s")i=!0;else if(h==="n")a=!0;else return T("jq",`-${h}`);else l?c.push(d):(o=d,l=!0)}}let u;if(a)u="";else if(c.length===0||c.length===1&&c[0]==="-")u=e.stdin;else try{let f=e.fs.resolvePath(e.cwd,c[0]);u=await e.fs.readFile(f)}catch{return{stdout:"",stderr:`jq: ${c[0]}: No such file or directory
|
|
365
|
+
`,exitCode:2}}try{let f;if(a)f=Qt(null,o);else if(i){let p=[];for(let w of u.trim().split(`
|
|
366
|
+
`))w.trim()&&p.push(JSON.parse(w));f=Qt(p,o)}else{let p=u.trim();if(p.startsWith("{")||p.startsWith("["))f=Qt(JSON.parse(p),o);else{f=[];for(let w of p.split(`
|
|
367
|
+
`))w.trim()&&f.push(...Qt(JSON.parse(w),o))}}let d=f.map(p=>Zt(p,n,r)).join(`
|
|
356
368
|
`),h=s&&(f.length===0||f.every(p=>p==null||p===!1))?1:0;return{stdout:d?`${d}
|
|
357
369
|
`:"",stderr:"",exitCode:h}}catch(f){return{stdout:"",stderr:`jq: parse error: ${f.message}
|
|
358
|
-
`,exitCode:5}}}}});var
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
`,exitCode:
|
|
363
|
-
`,exitCode:2}
|
|
364
|
-
`,exitCode:2}}
|
|
365
|
-
`,
|
|
366
|
-
`,stderr:"",exitCode:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
`,
|
|
370
|
+
`,exitCode:5}}}}});var To={};R(To,{base64Command:()=>sp});async function Fo(t,e,r){if(e.length===0||e.length===1&&e[0]==="-")return{ok:!0,data:new TextEncoder().encode(t.stdin)};let n=[];for(let o of e){if(o==="-"){n.push(new TextEncoder().encode(t.stdin));continue}try{let l=t.fs.resolvePath(t.cwd,o),c=await t.fs.readFileBuffer(l);n.push(c)}catch{return{ok:!1,error:{stdout:"",stderr:`${r}: ${o}: No such file or directory
|
|
371
|
+
`,exitCode:1}}}}let s=n.reduce((o,l)=>o+l.length,0),i=new Uint8Array(s),a=0;for(let o of n)i.set(o,a),a+=o.length;return{ok:!0,data:i}}var rp,np,sp,Do=C(()=>{"use strict";ue();M();rp={name:"base64",summary:"base64 encode/decode data and print to standard output",usage:"base64 [OPTION]... [FILE]",options:["-d, --decode decode data","-w, --wrap=COLS wrap encoded lines after COLS character (default 76, 0 to disable)"," --help display this help and exit"]},np={decode:{short:"d",long:"decode",type:"boolean"},wrap:{short:"w",long:"wrap",type:"number",default:76}};sp={name:"base64",async execute(t,e){if(v(t))return k(rp);let r=j("base64",t,np);if(!r.ok)return r.error;let n=r.result.flags.decode,s=r.result.flags.wrap,i=r.result.positional;try{if(n){let l=await Fo(e,i,"base64");if(!l.ok)return l.error;let u=new TextDecoder().decode(l.data).replace(/\s/g,""),f=Uint8Array.from(atob(u),h=>h.charCodeAt(0));return{stdout:new TextDecoder().decode(f),stderr:"",exitCode:0}}let a=await Fo(e,i,"base64");if(!a.ok)return a.error;let o=btoa(String.fromCharCode(...a.data));if(s>0){let l=[];for(let c=0;c<o.length;c+=s)l.push(o.slice(c,c+s));o=l.join(`
|
|
372
|
+
`)+(o.length>0?`
|
|
373
|
+
`:"")}return{stdout:o,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`base64: invalid input
|
|
374
|
+
`,exitCode:1}}}}});var Mo={};R(Mo,{diffCommand:()=>op});import*as Lo from"diff";var ip,ap,op,_o=C(()=>{"use strict";ue();M();ip={name:"diff",summary:"compare files line by line",usage:"diff [OPTION]... FILE1 FILE2",options:["-u, --unified output unified diff format (default)","-q, --brief report only whether files differ","-s, --report-identical-files report when files are the same","-i, --ignore-case ignore case differences"," --help display this help and exit"]},ap={unified:{short:"u",long:"unified",type:"boolean"},brief:{short:"q",long:"brief",type:"boolean"},reportSame:{short:"s",long:"report-identical-files",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},op={name:"diff",async execute(t,e){if(v(t))return k(ip);let r=j("diff",t,ap);if(!r.ok)return r.error;let n=r.result.flags.brief,s=r.result.flags.reportSame,i=r.result.flags.ignoreCase,a=r.result.positional;if(r.result.flags.unified,a.length<2)return{stdout:"",stderr:`diff: missing operand
|
|
375
|
+
`,exitCode:2};let o,l,[c,u]=a;try{o=c==="-"?e.stdin:await e.fs.readFile(e.fs.resolvePath(e.cwd,c))}catch{return{stdout:"",stderr:`diff: ${c}: No such file or directory
|
|
376
|
+
`,exitCode:2}}try{l=u==="-"?e.stdin:await e.fs.readFile(e.fs.resolvePath(e.cwd,u))}catch{return{stdout:"",stderr:`diff: ${u}: No such file or directory
|
|
377
|
+
`,exitCode:2}}let f=o,d=l;return i&&(f=f.toLowerCase(),d=d.toLowerCase()),f===d?s?{stdout:`Files ${c} and ${u} are identical
|
|
378
|
+
`,stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0}:n?{stdout:`Files ${c} and ${u} differ
|
|
379
|
+
`,stderr:"",exitCode:1}:{stdout:Lo.createTwoFilesPatch(c,u,o,l,"","",{context:3}),stderr:"",exitCode:1}}}});var Bo={};R(Bo,{dateCommand:()=>hp});function ge(t,e=2){return String(t).padStart(e,"0")}function fp(t){let e=-t.getTimezoneOffset();return`${e>=0?"+":"-"}${ge(Math.floor(Math.abs(e)/60))}${ge(Math.abs(e)%60)}`}function $r(t,e,r){let n=r?{Y:t.getUTCFullYear(),m:t.getUTCMonth(),D:t.getUTCDate(),H:t.getUTCHours(),M:t.getUTCMinutes(),S:t.getUTCSeconds(),w:t.getUTCDay()}:{Y:t.getFullYear(),m:t.getMonth(),D:t.getDate(),H:t.getHours(),M:t.getMinutes(),S:t.getSeconds(),w:t.getDay()},s="",i=0;for(;i<e.length;){if(e[i]==="%"&&i+1<e.length){let a=e[++i];switch(a){case"%":s+="%";break;case"a":s+=cp[n.w];break;case"b":case"h":s+=up[n.m];break;case"d":s+=ge(n.D);break;case"e":s+=String(n.D).padStart(2," ");break;case"F":s+=`${n.Y}-${ge(n.m+1)}-${ge(n.D)}`;break;case"H":s+=ge(n.H);break;case"I":s+=ge(n.H%12||12);break;case"m":s+=ge(n.m+1);break;case"M":s+=ge(n.M);break;case"n":s+=`
|
|
380
|
+
`;break;case"p":s+=n.H<12?"AM":"PM";break;case"P":s+=n.H<12?"am":"pm";break;case"R":s+=`${ge(n.H)}:${ge(n.M)}`;break;case"s":s+=Math.floor(t.getTime()/1e3);break;case"S":s+=ge(n.S);break;case"t":s+=" ";break;case"T":s+=`${ge(n.H)}:${ge(n.M)}:${ge(n.S)}`;break;case"u":s+=n.w||7;break;case"w":s+=n.w;break;case"y":s+=ge(n.Y%100);break;case"Y":s+=n.Y;break;case"z":s+=r?"+0000":fp(t);break;case"Z":s+=r?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone;break;default:s+=`%${a}`}}else s+=e[i];i++}return s}function dp(t){let e=new Date(t);if(!Number.isNaN(e.getTime()))return e;if(/^\d+$/.test(t))return new Date(Number.parseInt(t,10)*1e3);let r=t.toLowerCase();return r==="now"||r==="today"?new Date:r==="yesterday"?new Date(Date.now()-864e5):r==="tomorrow"?new Date(Date.now()+864e5):null}var lp,cp,up,hp,Wo=C(()=>{"use strict";M();lp={name:"date",summary:"display the current time in the given FORMAT",usage:"date [OPTION]... [+FORMAT]",options:["-d, --date=STRING display time described by STRING","-u, --utc print Coordinated Universal Time (UTC)","-I, --iso-8601 output date/time in ISO 8601 format","-R, --rfc-email output RFC 5322 date format"," --help display this help and exit"]},cp=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],up=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];hp={name:"date",async execute(t,e){if(v(t))return k(lp);let r=!1,n=null,s=null,i=!1,a=!1;for(let c=0;c<t.length;c++){let u=t[c];if(u==="-u"||u==="--utc")r=!0;else if(u==="-d"||u==="--date")n=t[++c]??"";else if(u.startsWith("--date="))n=u.slice(7);else if(u==="-I"||u==="--iso-8601")i=!0;else if(u==="-R"||u==="--rfc-email")a=!0;else if(u.startsWith("+"))s=u.slice(1);else{if(u.startsWith("--"))return T("date",u);if(u.startsWith("-"))for(let f of u.slice(1))if(f==="u")r=!0;else if(f==="I")i=!0;else if(f==="R")a=!0;else return T("date",`-${f}`)}}let o=n!==null?dp(n):new Date;if(!o)return{stdout:"",stderr:`date: invalid date '${n}'
|
|
381
|
+
`,exitCode:1};let l;return s?l=$r(o,s,r):i?l=$r(o,"%Y-%m-%dT%H:%M:%S%z",r):a?l=$r(o,"%a, %d %b %Y %H:%M:%S %z",r):l=$r(o,"%a %b %e %H:%M:%S %Z %Y",r),{stdout:`${l}
|
|
382
|
+
`,stderr:"",exitCode:0}}}});var Uo={};R(Uo,{sleepCommand:()=>gp});function mp(t){let e=t.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!e)return null;let r=parseFloat(e[1]);switch(e[2]||"s"){case"s":return r*1e3;case"m":return r*60*1e3;case"h":return r*60*60*1e3;case"d":return r*24*60*60*1e3;default:return null}}var pp,gp,zo=C(()=>{"use strict";M();pp={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
370
383
|
s - seconds (default)
|
|
371
384
|
m - minutes
|
|
372
385
|
h - hours
|
|
373
386
|
d - days
|
|
374
387
|
|
|
375
|
-
NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};
|
|
376
|
-
`,exitCode:1};let r=0;for(let n of t){let s=
|
|
377
|
-
`,exitCode:1};r+=s}return e.sleep?await e.sleep(r):await new Promise(n=>setTimeout(n,r)),{stdout:"",stderr:"",exitCode:0}}}});var
|
|
388
|
+
NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};gp={name:"sleep",async execute(t,e){if(v(t))return k(pp);if(t.length===0)return{stdout:"",stderr:`sleep: missing operand
|
|
389
|
+
`,exitCode:1};let r=0;for(let n of t){let s=mp(n);if(s===null)return{stdout:"",stderr:`sleep: invalid time interval '${n}'
|
|
390
|
+
`,exitCode:1};r+=s}return e.sleep?await e.sleep(r):await new Promise(n=>setTimeout(n,r)),{stdout:"",stderr:"",exitCode:0}}}});var Ho={};R(Ho,{timeoutCommand:()=>wp});function yp(t){let e=t.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!e)return null;let r=parseFloat(e[1]);switch(e[2]||"s"){case"s":return r*1e3;case"m":return r*60*1e3;case"h":return r*60*60*1e3;case"d":return r*24*60*60*1e3;default:return null}}var xp,wp,jo=C(()=>{"use strict";M();xp={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
|
|
378
391
|
|
|
379
392
|
DURATION is a number with optional suffix:
|
|
380
393
|
s - seconds (default)
|
|
381
394
|
m - minutes
|
|
382
395
|
h - hours
|
|
383
|
-
d - days`,options:["-k, --kill-after=DURATION send KILL signal after DURATION if still running","-s, --signal=SIGNAL specify signal to send (default: TERM)"," --preserve-status exit with same status as COMMAND, even on timeout"," --foreground run command in foreground"," --help display this help and exit"]};
|
|
384
|
-
`,exitCode:1};let i=s[0],a=
|
|
396
|
+
d - days`,options:["-k, --kill-after=DURATION send KILL signal after DURATION if still running","-s, --signal=SIGNAL specify signal to send (default: TERM)"," --preserve-status exit with same status as COMMAND, even on timeout"," --foreground run command in foreground"," --help display this help and exit"]};wp={name:"timeout",async execute(t,e){if(v(t))return k(xp);let r=!1,n=0;for(let d=0;d<t.length;d++){let h=t[d];if(h==="--preserve-status")r=!0,n=d+1;else if(h==="--foreground")n=d+1;else if(h==="-k"||h==="--kill-after")d++,n=d+1;else if(h.startsWith("--kill-after="))n=d+1;else if(h==="-s"||h==="--signal")d++,n=d+1;else if(h.startsWith("--signal="))n=d+1;else{if(h.startsWith("--")&&h!=="--")return T("timeout",h);if(h.startsWith("-")&&h.length>1&&h!=="--")if(h.startsWith("-k"))n=d+1;else if(h.startsWith("-s"))n=d+1;else return T("timeout",h);else{n=d;break}}}let s=t.slice(n);if(s.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
397
|
+
`,exitCode:1};let i=s[0],a=yp(i);if(a===null)return{stdout:"",stderr:`timeout: invalid time interval '${i}'
|
|
385
398
|
`,exitCode:1};let o=s.slice(1);if(o.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
386
399
|
`,exitCode:1};if(!e.exec)return{stdout:"",stderr:`timeout: exec not available
|
|
387
|
-
`,exitCode:1};let
|
|
400
|
+
`,exitCode:1};let l=o.map(d=>d.includes(" ")||d.includes(" ")?`'${d.replace(/'/g,"'\\''")}'`:d).join(" "),c=new Promise(d=>{setTimeout(()=>d({timedOut:!0}),a)}),u=e.exec(l,{cwd:e.cwd}).then(d=>({timedOut:!1,result:d})),f=await Promise.race([c,u]);return f.timedOut?{stdout:"",stderr:"",exitCode:124}:f.result}}});var Go={};R(Go,{seqCommand:()=>Ep});var Ep,qo=C(()=>{"use strict";Ep={name:"seq",async execute(t){let e=`
|
|
388
401
|
`,r=!1,n=[],s=0;for(;s<t.length;){let p=t[s];if(p==="-s"&&s+1<t.length){e=t[s+1],s+=2;continue}if(p==="-w"){r=!0,s++;continue}if(p==="--"){s++;break}if(p.startsWith("-")&&p!=="-"){if(p.startsWith("-s")&&p.length>2){e=p.slice(2),s++;continue}if((p==="-ws"||p==="-sw")&&(r=!0,s+1<t.length)){e=t[s+1],s+=2;continue}}n.push(p),s++}for(;s<t.length;)n.push(t[s]),s++;if(n.length===0)return{stdout:"",stderr:`seq: missing operand
|
|
389
|
-
`,exitCode:1};let i=1,a=1,o;if(n.length===1?o=parseFloat(n[0]):n.length===2?(i=parseFloat(n[0]),o=parseFloat(n[1])):(i=parseFloat(n[0]),a=parseFloat(n[1]),o=parseFloat(n[2])),Number.isNaN(i)||Number.isNaN(a)||Number.isNaN(o))return{stdout:"",stderr:`seq: invalid floating point argument: '${n.find(
|
|
402
|
+
`,exitCode:1};let i=1,a=1,o;if(n.length===1?o=parseFloat(n[0]):n.length===2?(i=parseFloat(n[0]),o=parseFloat(n[1])):(i=parseFloat(n[0]),a=parseFloat(n[1]),o=parseFloat(n[2])),Number.isNaN(i)||Number.isNaN(a)||Number.isNaN(o))return{stdout:"",stderr:`seq: invalid floating point argument: '${n.find(w=>Number.isNaN(parseFloat(w)))}'
|
|
390
403
|
`,exitCode:1};if(a===0)return{stdout:"",stderr:`seq: invalid Zero increment value: '0'
|
|
391
|
-
`,exitCode:1};let
|
|
392
|
-
`:"",stderr:"",exitCode:0}}}});var
|
|
393
|
-
`,exitCode:2};try{let r=
|
|
404
|
+
`,exitCode:1};let l=[],c=p=>{let w=String(p),x=w.indexOf(".");return x===-1?0:w.length-x-1},u=Math.max(c(i),c(a),c(o)),f=1e5,d=0;if(a>0)for(let p=i;p<=o+1e-10&&!(d++>f);p+=a)l.push(u>0?p.toFixed(u):String(Math.round(p)));else for(let p=i;p>=o-1e-10&&!(d++>f);p+=a)l.push(u>0?p.toFixed(u):String(Math.round(p)));if(r&&l.length>0){let p=Math.max(...l.map(w=>w.replace("-","").length));for(let w=0;w<l.length;w++){let x=l[w].startsWith("-"),E=(x?l[w].slice(1):l[w]).padStart(p,"0");l[w]=x?`-${E}`:E}}let h=l.join(e);return{stdout:h?`${h}
|
|
405
|
+
`:"",stderr:"",exitCode:0}}}});var Vo={};R(Vo,{exprCommand:()=>bp});function Sp(t){if(t.length===1)return t[0];let e=0;function r(){let c=n();for(;e<t.length&&t[e]==="|";){e++;let u=n();if(c!=="0"&&c!=="")return c;c=u}return c}function n(){let c=s();for(;e<t.length&&t[e]==="&";){e++;let u=s();(c==="0"||c===""||u==="0"||u==="")&&(c="0")}return c}function s(){let c=i();for(;e<t.length;){let u=t[e];if(["=","!=","<",">","<=",">="].includes(u)){e++;let f=i(),d=parseInt(c,10),h=parseInt(f,10),p=!Number.isNaN(d)&&!Number.isNaN(h),w;u==="="?w=p?d===h:c===f:u==="!="?w=p?d!==h:c!==f:u==="<"?w=p?d<h:c<f:u===">"?w=p?d>h:c>f:u==="<="?w=p?d<=h:c<=f:w=p?d>=h:c>=f,c=w?"1":"0"}else break}return c}function i(){let c=a();for(;e<t.length;){let u=t[e];if(u==="+"||u==="-"){e++;let f=a(),d=parseInt(c,10),h=parseInt(f,10);if(Number.isNaN(d)||Number.isNaN(h))throw new Error("non-integer argument");c=String(u==="+"?d+h:d-h)}else break}return c}function a(){let c=o();for(;e<t.length;){let u=t[e];if(u==="*"||u==="/"||u==="%"){e++;let f=o(),d=parseInt(c,10),h=parseInt(f,10);if(Number.isNaN(d)||Number.isNaN(h))throw new Error("non-integer argument");if((u==="/"||u==="%")&&h===0)throw new Error("division by zero");u==="*"?c=String(d*h):u==="/"?c=String(Math.trunc(d/h)):c=String(d%h)}else break}return c}function o(){let c=l();for(;e<t.length&&t[e]===":";){e++;let u=l(),f=new RegExp(`^${u}`),d=c.match(f);d?c=d[1]!==void 0?d[1]:String(d[0].length):c="0"}return c}function l(){if(e>=t.length)throw new Error("syntax error");let c=t[e];if(c==="match"){e++;let u=l(),f=l(),d=new RegExp(f),h=u.match(d);return h?h[1]!==void 0?h[1]:String(h[0].length):"0"}if(c==="substr"){e++;let u=l(),f=parseInt(l(),10),d=parseInt(l(),10);if(Number.isNaN(f)||Number.isNaN(d))throw new Error("non-integer argument");return u.substring(f-1,f-1+d)}if(c==="index"){e++;let u=l(),f=l();for(let d=0;d<u.length;d++)if(f.includes(u[d]))return String(d+1);return"0"}if(c==="length"){e++;let u=l();return String(u.length)}if(c==="("){e++;let u=r();if(e>=t.length||t[e]!==")")throw new Error("syntax error");return e++,u}return e++,c}return r()}var bp,Zo=C(()=>{"use strict";bp={name:"expr",async execute(t,e){if(t.length===0)return{stdout:"",stderr:`expr: missing operand
|
|
406
|
+
`,exitCode:2};try{let r=Sp(t),n=r==="0"||r===""?1:0;return{stdout:`${r}
|
|
394
407
|
`,stderr:"",exitCode:n}}catch(r){return{stdout:"",stderr:`expr: ${r.message}
|
|
395
|
-
`,exitCode:2}}}}});
|
|
396
|
-
`,exitCode:1}
|
|
397
|
-
|
|
398
|
-
`,
|
|
399
|
-
|
|
408
|
+
`,exitCode:2}}}}});function Ap(t){function e(h,p){return h<<p|h>>>32-p}let r=new Uint32Array([3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745]),n=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],s=t.length*8,i=(t.length%64<56?56:120)-t.length%64,a=new Uint8Array(t.length+i+8);a.set(t),a[t.length]=128;let o=new DataView(a.buffer);o.setUint32(a.length-8,s>>>0,!0),o.setUint32(a.length-4,Math.floor(s/4294967296),!0);let l=1732584193,c=4023233417,u=2562383102,f=271733878;for(let h=0;h<a.length;h+=64){let p=new Uint32Array(16);for(let b=0;b<16;b++)p[b]=o.getUint32(h+b*4,!0);let w=l,x=c,y=u,E=f;for(let b=0;b<64;b++){let S,A;b<16?(S=x&y|~x&E,A=b):b<32?(S=E&x|~E&y,A=(5*b+1)%16):b<48?(S=x^y^E,A=(3*b+5)%16):(S=y^(x|~E),A=7*b%16),S=S+w+r[b]+p[A]>>>0,w=E,E=y,y=x,x=x+e(S,n[b])>>>0}l=l+w>>>0,c=c+x>>>0,u=u+y>>>0,f=f+E>>>0}let d=new Uint8Array(16);return new DataView(d.buffer).setUint32(0,l,!0),new DataView(d.buffer).setUint32(4,c,!0),new DataView(d.buffer).setUint32(8,u,!0),new DataView(d.buffer).setUint32(12,f,!0),Array.from(d).map(h=>h.toString(16).padStart(2,"0")).join("")}async function Qo(t,e){if(t==="md5")return Ap(e);let r=await globalThis.crypto.subtle.digest(Cp[t],new Uint8Array(e).buffer);return Array.from(new Uint8Array(r)).map(n=>n.toString(16).padStart(2,"0")).join("")}function $t(t,e,r){let n={name:t,summary:r,usage:`${t} [OPTION]... [FILE]...`,options:["-c, --check read checksums from FILEs and check them"," --help display this help and exit"]};return{name:t,async execute(s,i){if(v(s))return k(n);let a=!1,o=[];for(let f of s)if(f==="-c"||f==="--check")a=!0;else if(!(f==="-b"||f==="-t"||f==="--binary"||f==="--text")){if(f.startsWith("-")&&f!=="-")return T(t,f);o.push(f)}o.length===0&&o.push("-");let l=async f=>{if(f==="-")return new TextEncoder().encode(i.stdin);try{return await i.fs.readFileBuffer(i.fs.resolvePath(i.cwd,f))}catch{return null}};if(a){let f=0,d="";for(let h of o){let p=h==="-"?i.stdin:await i.fs.readFile(i.fs.resolvePath(i.cwd,h)).catch(()=>null);if(p===null)return{stdout:"",stderr:`${t}: ${h}: No such file or directory
|
|
409
|
+
`,exitCode:1};for(let w of p.split(`
|
|
410
|
+
`)){let x=w.match(/^([a-fA-F0-9]+)\s+[* ]?(.+)$/);if(!x)continue;let[,y,E]=x,b=await l(E);if(b===null){d+=`${E}: FAILED open or read
|
|
411
|
+
`,f++;continue}let S=await Qo(e,b)===y.toLowerCase();d+=`${E}: ${S?"OK":"FAILED"}
|
|
412
|
+
`,S||f++}}return f>0&&(d+=`${t}: WARNING: ${f} computed checksum${f>1?"s":""} did NOT match
|
|
413
|
+
`),{stdout:d,stderr:"",exitCode:f>0?1:0}}let c="",u=0;for(let f of o){let d=await l(f);if(d===null){c+=`${t}: ${f}: No such file or directory
|
|
414
|
+
`,u=1;continue}c+=`${await Qo(e,d)} ${f}
|
|
415
|
+
`}return{stdout:c,stderr:"",exitCode:u}}}}var Cp,Or=C(()=>{"use strict";M();Cp={sha1:"SHA-1",sha256:"SHA-256"}});var Xo={};R(Xo,{md5sumCommand:()=>kp});var kp,Ko=C(()=>{"use strict";Or();kp=$t("md5sum","md5","compute MD5 message digest")});var Jo={};R(Jo,{sha1sumCommand:()=>vp});var vp,Yo=C(()=>{"use strict";Or();vp=$t("sha1sum","sha1","compute SHA1 message digest")});var el={};R(el,{sha256sumCommand:()=>Np});var Np,tl=C(()=>{"use strict";Or();Np=$t("sha256sum","sha256","compute SHA256 message digest")});var Ip,Q,ft,Xt=C(()=>{Ip="End-Of-Stream",Q=class extends Error{constructor(){super(Ip),this.name="EndOfStreamError"}},ft=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}}});var rl=C(()=>{});var dt,Pr=C(()=>{Xt();dt=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,r=!1){let n=await this.read(e,r);return this.peekQueue.push(e.subarray(0,n)),n}async read(e,r=!1){if(e.length===0)return 0;let n=this.readFromPeekBuffer(e);if(this.endOfStream||(n+=await this.readRemainderFromStream(e.subarray(n),r)),n===0&&!r)throw new Q;return n}readFromPeekBuffer(e){let r=e.length,n=0;for(;this.peekQueue.length>0&&r>0;){let s=this.peekQueue.pop();if(!s)throw new Error("peekData should be defined");let i=Math.min(s.length,r);e.set(s.subarray(0,i),n),n+=i,r-=i,i<s.length&&this.peekQueue.push(s.subarray(i))}return n}async readRemainderFromStream(e,r){let n=0;for(;n<e.length&&!this.endOfStream;){if(this.interrupted)throw new ft;let s=await this.readFromStream(e.subarray(n),r);if(s===0)break;n+=s}if(!r&&n<e.length)throw new Q;return n}}});var nl=C(()=>{Xt();rl();Pr()});var Fr,sl=C(()=>{Pr();Fr=class extends dt{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}}});var Kt,Xn=C(()=>{sl();Kt=class extends Fr{async readFromStream(e,r){if(e.length===0)return 0;let n=await this.reader.read(new Uint8Array(e.length),{min:r?void 0:e.length});return n.done&&(this.endOfStream=n.done),n.value?(e.set(n.value),n.value.length):0}}});var Ot,Kn=C(()=>{Xt();Pr();Ot=class extends dt{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,r){let n=Math.min(r.length,e.length);return e.set(r.subarray(0,n)),n<r.length?this.buffer=r.subarray(n):this.buffer=null,n}async readFromStream(e,r){if(e.length===0)return 0;let n=0;for(this.buffer&&(n+=this.writeChunk(e,this.buffer));n<e.length&&!this.endOfStream;){let s=await this.reader.read();if(s.done){this.endOfStream=!0;break}s.value&&(n+=this.writeChunk(e.subarray(n),s.value))}if(!r&&n===0&&this.endOfStream)throw new Q;return n}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}}});function Jn(t){try{let e=t.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new Ot(e):new Kt(e)}catch(e){if(e instanceof TypeError)return new Ot(t.getReader());throw e}}var il=C(()=>{Xn();Kn()});var tt=C(()=>{Xt();nl();Xn();Kn();il()});var We,Pt=C(()=>{tt();We=class{constructor(e){this.numBuffer=new Uint8Array(8),this.position=0,this.onClose=e?.onClose,e?.abortSignal&&e.abortSignal.addEventListener("abort",()=>{this.abort()})}async readToken(e,r=this.position){let n=new Uint8Array(e.len);if(await this.readBuffer(n,{position:r})<e.len)throw new Q;return e.get(n,0)}async peekToken(e,r=this.position){let n=new Uint8Array(e.len);if(await this.peekBuffer(n,{position:r})<e.len)throw new Q;return e.get(n,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new Q;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new Q;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let r=this.fileInfo.size-this.position;if(e>r)return this.position+=r,r}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,r){if(!this.supportsRandomAccess()&&r&&r.position!==void 0&&r.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return{mayBeLess:!1,offset:0,length:e.length,position:this.position,...r}}abort(){return Promise.resolve()}}});var $p,Tr,al=C(()=>{Pt();tt();$p=256e3,Tr=class extends We{constructor(e,r){super(r),this.streamReader=e,this.fileInfo=r?.fileInfo??{}}async readBuffer(e,r){let n=this.normalizeOptions(e,r),s=n.position-this.position;if(s>0)return await this.ignore(s),this.readBuffer(e,r);if(s<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(n.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,n.length),n.mayBeLess);if(this.position+=i,(!r||!r.mayBeLess)&&i<n.length)throw new Q;return i}async peekBuffer(e,r){let n=this.normalizeOptions(e,r),s=0;if(n.position){let i=n.position-this.position;if(i>0){let a=new Uint8Array(n.length+i);return s=await this.peekBuffer(a,{mayBeLess:n.mayBeLess}),e.set(a.subarray(i)),s-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(n.length>0){try{s=await this.streamReader.peek(e.subarray(0,n.length),n.mayBeLess)}catch(i){if(r?.mayBeLess&&i instanceof Q)return 0;throw i}if(!n.mayBeLess&&s<n.length)throw new Q}return s}async ignore(e){let r=Math.min($p,e),n=new Uint8Array(r),s=0;for(;s<e;){let i=e-s,a=await this.readBuffer(n,{length:Math.min(r,i)});if(a<0)return a;s+=a}return s}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}}});var Dr,ol=C(()=>{tt();Pt();Dr=class extends We{constructor(e,r){super(r),this.uint8Array=e,this.fileInfo={...r?.fileInfo??{},size:e.length}}async readBuffer(e,r){r?.position&&(this.position=r.position);let n=await this.peekBuffer(e,r);return this.position+=n,n}async peekBuffer(e,r){let n=this.normalizeOptions(e,r),s=Math.min(this.uint8Array.length-n.position,n.length);if(!n.mayBeLess&&s<n.length)throw new Q;return e.set(this.uint8Array.subarray(n.position,n.position+s)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});var Lr,ll=C(()=>{tt();Pt();Lr=class extends We{constructor(e,r){super(r),this.blob=e,this.fileInfo={...r?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,r){r?.position&&(this.position=r.position);let n=await this.peekBuffer(e,r);return this.position+=n,n}async peekBuffer(e,r){let n=this.normalizeOptions(e,r),s=Math.min(this.blob.size-n.position,n.length);if(!n.mayBeLess&&s<n.length)throw new Q;let i=await this.blob.slice(n.position,n.position+s).arrayBuffer();return e.set(new Uint8Array(i)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});function Yn(t,e){let r=Jn(t),n=e??{},s=n.onClose;return n.onClose=async()=>{if(await r.close(),s)return s()},new Tr(r,n)}function cl(t,e){return new Dr(t,e)}function ul(t,e){return new Lr(t,e)}var Mr=C(()=>{tt();al();ol();ll();tt();Pt()});import{open as Pp}from"node:fs/promises";var Jt,es=C(()=>{Pt();tt();Jt=class t extends We{static async fromFile(e){let r=await Pp(e,"r"),n=await r.stat();return new t(r,{fileInfo:{path:e,size:n.size}})}constructor(e,r){super(r),this.fileHandle=e,this.fileInfo=r.fileInfo}async readBuffer(e,r){let n=this.normalizeOptions(e,r);if(this.position=n.position,n.length===0)return 0;let s=await this.fileHandle.read(e,0,n.length,n.position);if(this.position+=s.bytesRead,s.bytesRead<n.length&&(!r||!r.mayBeLess))throw new Q;return s.bytesRead}async peekBuffer(e,r){let n=this.normalizeOptions(e,r),s=await this.fileHandle.read(e,0,n.length,n.position);if(!n.mayBeLess&&s.bytesRead<n.length)throw new Q;return s.bytesRead}async close(){return await this.fileHandle.close(),super.close()}setPosition(e){this.position=e}supportsRandomAccess(){return!0}}});var Fp,fl=C(()=>{Mr();es();es();Mr();Fp=Jt.fromFile});var dl=Et(ts=>{ts.read=function(t,e,r,n,s){var i,a,o=s*8-n-1,l=(1<<o)-1,c=l>>1,u=-7,f=r?s-1:0,d=r?-1:1,h=t[e+f];for(f+=d,i=h&(1<<-u)-1,h>>=-u,u+=o;u>0;i=i*256+t[e+f],f+=d,u-=8);for(a=i&(1<<-u)-1,i>>=-u,u+=n;u>0;a=a*256+t[e+f],f+=d,u-=8);if(i===0)i=1-c;else{if(i===l)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,n),i=i-c}return(h?-1:1)*a*Math.pow(2,i-n)};ts.write=function(t,e,r,n,s,i){var a,o,l,c=i*8-s-1,u=(1<<c)-1,f=u>>1,d=s===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,p=n?1:-1,w=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=u):(a=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-a))<1&&(a--,l*=2),a+f>=1?e+=d/l:e+=d*Math.pow(2,1-f),e*l>=2&&(a++,l/=2),a+f>=u?(o=0,a=u):a+f>=1?(o=(e*l-1)*Math.pow(2,s),a=a+f):(o=e*Math.pow(2,f-1)*Math.pow(2,s),a=0));s>=8;t[r+h]=o&255,h+=p,o/=256,s-=8);for(a=a<<s|o,c+=s;c>0;t[r+h]=a&255,h+=p,a/=256,c-=8);t[r+h-p]|=w*128}});function hl(t,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":return typeof globalThis.TextDecoder<"u"?new globalThis.TextDecoder("utf-8").decode(t):Lp(t);case"utf-16le":return Mp(t);case"ascii":return _p(t);case"latin1":case"iso-8859-1":return Bp(t);case"windows-1252":return Wp(t);default:throw new RangeError(`Encoding '${e}' not supported`)}}function Lp(t){let e="",r=0;for(;r<t.length;){let n=t[r++];if(n<128)e+=String.fromCharCode(n);else if(n<224){let s=t[r++]&63;e+=String.fromCharCode((n&31)<<6|s)}else if(n<240){let s=t[r++]&63,i=t[r++]&63;e+=String.fromCharCode((n&15)<<12|s<<6|i)}else{let s=t[r++]&63,i=t[r++]&63,a=t[r++]&63,o=(n&7)<<18|s<<12|i<<6|a;o-=65536,e+=String.fromCharCode(55296+(o>>10&1023),56320+(o&1023))}}return e}function Mp(t){let e="";for(let r=0;r<t.length;r+=2)e+=String.fromCharCode(t[r]|t[r+1]<<8);return e}function _p(t){return String.fromCharCode(...t.map(e=>e&127))}function Bp(t){return String.fromCharCode(...t)}function Wp(t){let e="";for(let r of t)r>=128&&r<=159&&rs[r]?e+=rs[r]:e+=String.fromCharCode(r);return e}var rs,Dp,pl=C(()=>{rs={128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"},Dp={};for(let[t,e]of Object.entries(rs))Dp[e]=Number.parseInt(t)});function we(t){return new DataView(t.buffer,t.byteOffset)}var ml,gl,Y,Ft,ie,xl,yl,wl,Ee,Yt=C(()=>{ml=di(dl(),1);pl();gl={len:1,get(t,e){return we(t).getUint8(e)},put(t,e,r){return we(t).setUint8(e,r),e+1}},Y={len:2,get(t,e){return we(t).getUint16(e,!0)},put(t,e,r){return we(t).setUint16(e,r,!0),e+2}},Ft={len:2,get(t,e){return we(t).getUint16(e)},put(t,e,r){return we(t).setUint16(e,r),e+2}},ie={len:4,get(t,e){return we(t).getUint32(e,!0)},put(t,e,r){return we(t).setUint32(e,r,!0),e+4}},xl={len:4,get(t,e){return we(t).getUint32(e)},put(t,e,r){return we(t).setUint32(e,r),e+4}},yl={len:4,get(t,e){return we(t).getInt32(e)},put(t,e,r){return we(t).setInt32(e,r),e+4}},wl={len:8,get(t,e){return we(t).getBigUint64(e,!0)},put(t,e,r){return we(t).setBigUint64(e,r,!0),e+8}},Ee=class{constructor(e,r){this.len=e,this.encoding=r}get(e,r=0){let n=e.subarray(r,r+this.len);return hl(n,this.encoding)}}});var bl=Et((Rw,El)=>{var Tt=1e3,Dt=Tt*60,Lt=Dt*60,ht=Lt*24,zp=ht*7,Hp=ht*365.25;El.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return jp(t);if(r==="number"&&isFinite(t))return e.long?qp(t):Gp(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function jp(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*Hp;case"weeks":case"week":case"w":return r*zp;case"days":case"day":case"d":return r*ht;case"hours":case"hour":case"hrs":case"hr":case"h":return r*Lt;case"minutes":case"minute":case"mins":case"min":case"m":return r*Dt;case"seconds":case"second":case"secs":case"sec":case"s":return r*Tt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function Gp(t){var e=Math.abs(t);return e>=ht?Math.round(t/ht)+"d":e>=Lt?Math.round(t/Lt)+"h":e>=Dt?Math.round(t/Dt)+"m":e>=Tt?Math.round(t/Tt)+"s":t+"ms"}function qp(t){var e=Math.abs(t);return e>=ht?_r(t,e,ht,"day"):e>=Lt?_r(t,e,Lt,"hour"):e>=Dt?_r(t,e,Dt,"minute"):e>=Tt?_r(t,e,Tt,"second"):t+" ms"}function _r(t,e,r,n){var s=e>=r*1.5;return Math.round(t/r)+" "+n+(s?"s":"")}});var ns=Et(($w,Sl)=>{function Vp(t){r.debug=r,r.default=r,r.coerce=l,r.disable=a,r.enable=s,r.enabled=o,r.humanize=bl(),r.destroy=c,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let f=0;for(let d=0;d<u.length;d++)f=(f<<5)-f+u.charCodeAt(d),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=e;function r(u){let f,d=null,h,p;function w(...x){if(!w.enabled)return;let y=w,E=Number(new Date),b=E-(f||E);y.diff=b,y.prev=f,y.curr=E,f=E,x[0]=r.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let S=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(D,F)=>{if(D==="%%")return"%";S++;let P=r.formatters[F];if(typeof P=="function"){let B=x[S];D=P.call(y,B),x.splice(S,1),S--}return D}),r.formatArgs.call(y,x),(y.log||r.log).apply(y,x)}return w.namespace=u,w.useColors=r.useColors(),w.color=r.selectColor(u),w.extend=n,w.destroy=r.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(h!==r.namespaces&&(h=r.namespaces,p=r.enabled(u)),p),set:x=>{d=x}}),typeof r.init=="function"&&r.init(w),w}function n(u,f){let d=r(this.namespace+(typeof f>"u"?":":f)+u);return d.log=this.log,d}function s(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let d of f)d[0]==="-"?r.skips.push(d.slice(1)):r.names.push(d)}function i(u,f){let d=0,h=0,p=-1,w=0;for(;d<u.length;)if(h<f.length&&(f[h]===u[d]||f[h]==="*"))f[h]==="*"?(p=h,w=d,h++):(d++,h++);else if(p!==-1)h=p+1,w++,d=w;else return!1;for(;h<f.length&&f[h]==="*";)h++;return h===f.length}function a(){let u=[...r.names,...r.skips.map(f=>"-"+f)].join(",");return r.enable(""),u}function o(u){for(let f of r.skips)if(i(u,f))return!1;for(let f of r.names)if(i(u,f))return!0;return!1}function l(u){return u instanceof Error?u.stack||u.message:u}function c(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}Sl.exports=Vp});var Cl=Et((be,Br)=>{be.formatArgs=Qp;be.save=Xp;be.load=Kp;be.useColors=Zp;be.storage=Jp();be.destroy=(()=>{let t=!1;return()=>{t||(t=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();be.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Zp(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let t;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(t=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(t[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Qp(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Br.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(r++,s==="%c"&&(n=r))}),t.splice(n,0,e)}be.log=console.debug||console.log||(()=>{});function Xp(t){try{t?be.storage.setItem("debug",t):be.storage.removeItem("debug")}catch{}}function Kp(){let t;try{t=be.storage.getItem("debug")||be.storage.getItem("DEBUG")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function Jp(){try{return localStorage}catch{}}Br.exports=ns()(be);var{formatters:Yp}=Br.exports;Yp.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var kl=Et((fe,Ur)=>{var em=Sn("tty"),Wr=Sn("util");fe.init=om;fe.log=sm;fe.formatArgs=rm;fe.save=im;fe.load=am;fe.useColors=tm;fe.destroy=Wr.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");fe.colors=[6,2,3,4,5,1];try{let t=Sn("supports-color");t&&(t.stderr||t).level>=2&&(fe.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}fe.inspectOpts=Object.keys(process.env).filter(t=>/^debug_/i.test(t)).reduce((t,e)=>{let r=e.substring(6).toLowerCase().replace(/_([a-z])/g,(s,i)=>i.toUpperCase()),n=process.env[e];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),t[r]=n,t},{});function tm(){return"colors"in fe.inspectOpts?!!fe.inspectOpts.colors:em.isatty(process.stderr.fd)}function rm(t){let{namespace:e,useColors:r}=this;if(r){let n=this.color,s="\x1B[3"+(n<8?n:"8;5;"+n),i=` ${s};1m${e} \x1B[0m`;t[0]=i+t[0].split(`
|
|
416
|
+
`).join(`
|
|
417
|
+
`+i),t.push(s+"m+"+Ur.exports.humanize(this.diff)+"\x1B[0m")}else t[0]=nm()+e+" "+t[0]}function nm(){return fe.inspectOpts.hideDate?"":new Date().toISOString()+" "}function sm(...t){return process.stderr.write(Wr.formatWithOptions(fe.inspectOpts,...t)+`
|
|
418
|
+
`)}function im(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function am(){return process.env.DEBUG}function om(t){t.inspectOpts={};let e=Object.keys(fe.inspectOpts);for(let r=0;r<e.length;r++)t.inspectOpts[e[r]]=fe.inspectOpts[e[r]]}Ur.exports=ns()(fe);var{formatters:Al}=Ur.exports;Al.o=function(t){return this.inspectOpts.colors=this.useColors,Wr.inspect(t,this.inspectOpts).split(`
|
|
419
|
+
`).map(e=>e.trim()).join(" ")};Al.O=function(t){return this.inspectOpts.colors=this.useColors,Wr.inspect(t,this.inspectOpts)}});var vl=Et((Ow,ss)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?ss.exports=Cl():ss.exports=kl()});var pt,is,Nl,Il,Rl,$l=C(()=>{Yt();pt={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},is={get(t){return{signature:ie.get(t,0),compressedSize:ie.get(t,8),uncompressedSize:ie.get(t,12)}},len:16},Nl={get(t){let e=Y.get(t,6);return{signature:ie.get(t,0),minVersion:Y.get(t,4),dataDescriptor:!!(e&8),compressedMethod:Y.get(t,8),compressedSize:ie.get(t,18),uncompressedSize:ie.get(t,22),filenameLength:Y.get(t,26),extraFieldLength:Y.get(t,28),filename:null}},len:30},Il={get(t){return{signature:ie.get(t,0),nrOfThisDisk:Y.get(t,4),nrOfThisDiskWithTheStart:Y.get(t,6),nrOfEntriesOnThisDisk:Y.get(t,8),nrOfEntriesOfSize:Y.get(t,10),sizeOfCd:ie.get(t,12),offsetOfStartOfCd:ie.get(t,16),zipFileCommentLength:Y.get(t,20)}},len:22},Rl={get(t){let e=Y.get(t,8);return{signature:ie.get(t,0),minVersion:Y.get(t,6),dataDescriptor:!!(e&8),compressedMethod:Y.get(t,10),compressedSize:ie.get(t,20),uncompressedSize:ie.get(t,24),filenameLength:Y.get(t,28),extraFieldLength:Y.get(t,30),fileCommentLength:Y.get(t,32),relativeOffsetOfLocalHeader:ie.get(t,42),filename:null}},len:46}});function Pl(t){let e=new Uint8Array(ie.len);return ie.put(e,0,t),e}function cm(t,e){let r=t.length,n=e.length;if(n>r)return-1;for(let s=0;s<=r-n;s++){let i=!0;for(let a=0;a<n;a++)if(t[s+a]!==e[a]){i=!1;break}if(i)return s}return-1}function um(t){let e=t.reduce((s,i)=>s+i.length,0),r=new Uint8Array(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return r}var Ol,He,as,lm,zr,er,Fl=C(()=>{Yt();Ol=di(vl(),1);$l();He=(0,Ol.default)("tokenizer:inflate"),as=256*1024,lm=Pl(pt.DataDescriptor),zr=Pl(pt.EndOfCentralDirectory),er=class t{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(as)}async isZip(){return await this.peekSignature()===pt.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(ie)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,r=Math.min(16*1024,e.fileInfo.size),n=this.syncBuffer.subarray(0,r);await this.tokenizer.readBuffer(n,{position:e.fileInfo.size-r});for(let s=n.length-4;s>=0;s--)if(n[s]===zr[0]&&n[s+1]===zr[1]&&n[s+2]===zr[2]&&n[s+3]===zr[3])return e.fileInfo.size-r+s;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){He("Cannot reading central-directory without random-read support");return}He("Reading central-directory...");let e=this.tokenizer.position,r=await this.findEndOfCentralDirectoryLocator();if(r>0){He("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(Il,r),s=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let a=await this.tokenizer.readToken(Rl);if(a.signature!==pt.CentralFileHeader)throw new Error("Expected Central-File-Header signature");a.filename=await this.tokenizer.readToken(new Ee(a.filenameLength,"utf-8")),await this.tokenizer.ignore(a.extraFieldLength),await this.tokenizer.ignore(a.fileCommentLength),s.push(a),He(`Add central-directory file-entry: n=${i+1}/${s.length}: filename=${s[i].filename}`)}return this.tokenizer.setPosition(e),s}this.tokenizer.setPosition(e)}async unzip(e){let r=await this.readCentralDirectory();if(r)return this.iterateOverCentralDirectory(r,e);let n=!1;do{let s=await this.readLocalFileHeader();if(!s)break;let i=e(s);n=!!i.stop;let a;if(await this.tokenizer.ignore(s.extraFieldLength),s.dataDescriptor&&s.compressedSize===0){let o=[],l=as;He("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let c=-1;for(;c<0&&l===as;){l=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),c=cm(this.syncBuffer.subarray(0,l),lm);let u=c>=0?c:l;if(i.handler){let f=new Uint8Array(u);await this.tokenizer.readBuffer(f),o.push(f)}else await this.tokenizer.ignore(u)}He(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(s,um(o),i.handler)}else i.handler?(He(`Reading compressed-file-data: ${s.compressedSize} bytes`),a=new Uint8Array(s.compressedSize),await this.tokenizer.readBuffer(a),await this.inflate(s,a,i.handler)):(He(`Ignoring compressed-file-data: ${s.compressedSize} bytes`),await this.tokenizer.ignore(s.compressedSize));if(He(`Reading data-descriptor at pos=${this.tokenizer.position}`),s.dataDescriptor&&(await this.tokenizer.readToken(is)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-is.len}`)}while(!n)}async iterateOverCentralDirectory(e,r){for(let n of e){let s=r(n);if(s.handler){this.tokenizer.setPosition(n.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let a=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(a),await this.inflate(i,a,s.handler)}}if(s.stop)break}}async inflate(e,r,n){if(e.compressedMethod===0)return n(r);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);He(`Decompress filename=${e.filename}, compressed-size=${r.length}`);let s=await t.decompressDeflateRaw(r);return n(s)}static async decompressDeflateRaw(e){let r=new ReadableStream({start(i){i.enqueue(e),i.close()}}),n=new DecompressionStream("deflate-raw"),s=r.pipeThrough(n);try{let a=await new Response(s).arrayBuffer();return new Uint8Array(a)}catch(i){let a=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(a)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(ie);if(e===pt.LocalFileHeader){let r=await this.tokenizer.readToken(Nl);return r.filename=await this.tokenizer.readToken(new Ee(r.filenameLength,"utf-8")),r}if(e===pt.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}}});var tr,Tl=C(()=>{tr=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(r){let n=new Uint8Array(1024),s=await e.readBuffer(n,{mayBeLess:!0});if(s===0){r.close();return}r.enqueue(n.subarray(0,s))}}).pipeThrough(new DecompressionStream("gzip"))}}});var Dl=C(()=>{Fl();Tl()});function os(t){let{byteLength:e}=t;if(e===6)return t.getUint16(0)*2**32+t.getUint32(2);if(e===5)return t.getUint8(0)*2**32+t.getUint32(1);if(e===4)return t.getUint32(0);if(e===3)return t.getUint8(0)*2**16+t.getUint16(1);if(e===2)return t.getUint16(0);if(e===1)return t.getUint8(0)}var Uw,zw,Hw,Ll=C(()=>{Uw={utf8:new globalThis.TextDecoder("utf8")},zw=new globalThis.TextEncoder,Hw=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"))});function Ml(t,e){if(e==="utf-16le"){let r=[];for(let n=0;n<t.length;n++){let s=t.charCodeAt(n);r.push(s&255,s>>8&255)}return r}if(e==="utf-16be"){let r=[];for(let n=0;n<t.length;n++){let s=t.charCodeAt(n);r.push(s>>8&255,s&255)}return r}return[...t].map(r=>r.charCodeAt(0))}function _l(t,e=0){let r=Number.parseInt(new Ee(6).get(t,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(r))return!1;let n=256;for(let s=e;s<e+148;s++)n+=t[s];for(let s=e+156;s<e+512;s++)n+=t[s];return r===n}var Bl,Wl=C(()=>{Yt();Bl={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4}});var Ul,zl,Hl=C(()=>{Ul=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","macho","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ttc","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc","fbx","vsdx","vtt","apk","drc","lz4","potx","xltx","dotx","xltm","ott","ots","otp","odg","otg","xlsm","docm","dotm","potm","pptm","jar","jmp","rm","sav","ppsm","ppsx","tar.gz","reg","dat"],zl=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.ms-powerpoint.slideshow.macroenabled.12","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.slideshow","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/vnd.apache.arrow.file","video/mp4","audio/midi","video/matroska","video/webm","video/quicktime","video/vnd.avi","audio/wav","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","video/ogg","audio/ogg","audio/ogg; codecs=opus","application/ogg","audio/flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-mach-binary","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","font/collection","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","text/vtt","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/vnd.apache.parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile","application/x.autodesk.fbx","application/vnd.visio","application/vnd.android.package-archive","application/vnd.google.draco","application/x-lz4","application/vnd.openxmlformats-officedocument.presentationml.template","application/vnd.openxmlformats-officedocument.spreadsheetml.template","application/vnd.openxmlformats-officedocument.wordprocessingml.template","application/vnd.ms-excel.template.macroenabled.12","application/vnd.oasis.opendocument.text-template","application/vnd.oasis.opendocument.spreadsheet-template","application/vnd.oasis.opendocument.presentation-template","application/vnd.oasis.opendocument.graphics","application/vnd.oasis.opendocument.graphics-template","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-word.template.macroenabled.12","application/vnd.ms-powerpoint.template.macroenabled.12","application/vnd.ms-powerpoint.presentation.macroenabled.12","application/java-archive","application/vnd.rn-realmedia","application/x-spss-sav","application/x-ms-regedit","application/x-ft-windows-registry-hive","application/x-jmp-data"]});async function fs(t,e){return new us(e).fromBuffer(t)}function cs(t){switch(t=t.toLowerCase(),t){case"application/epub+zip":return{ext:"epub",mime:t};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:t};case"application/vnd.oasis.opendocument.text-template":return{ext:"ott",mime:t};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:t};case"application/vnd.oasis.opendocument.spreadsheet-template":return{ext:"ots",mime:t};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:t};case"application/vnd.oasis.opendocument.presentation-template":return{ext:"otp",mime:t};case"application/vnd.oasis.opendocument.graphics":return{ext:"odg",mime:t};case"application/vnd.oasis.opendocument.graphics-template":return{ext:"otg",mime:t};case"application/vnd.openxmlformats-officedocument.presentationml.slideshow":return{ext:"ppsx",mime:t};case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return{ext:"xlsx",mime:t};case"application/vnd.ms-excel.sheet.macroenabled":return{ext:"xlsm",mime:"application/vnd.ms-excel.sheet.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.spreadsheetml.template":return{ext:"xltx",mime:t};case"application/vnd.ms-excel.template.macroenabled":return{ext:"xltm",mime:"application/vnd.ms-excel.template.macroenabled.12"};case"application/vnd.ms-powerpoint.slideshow.macroenabled":return{ext:"ppsm",mime:"application/vnd.ms-powerpoint.slideshow.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return{ext:"docx",mime:t};case"application/vnd.ms-word.document.macroenabled":return{ext:"docm",mime:"application/vnd.ms-word.document.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.template":return{ext:"dotx",mime:t};case"application/vnd.ms-word.template.macroenabledtemplate":return{ext:"dotm",mime:"application/vnd.ms-word.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.template":return{ext:"potx",mime:t};case"application/vnd.ms-powerpoint.template.macroenabled":return{ext:"potm",mime:"application/vnd.ms-powerpoint.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return{ext:"pptx",mime:t};case"application/vnd.ms-powerpoint.presentation.macroenabled":return{ext:"pptm",mime:"application/vnd.ms-powerpoint.presentation.macroenabled.12"};case"application/vnd.ms-visio.drawing":return{ext:"vsdx",mime:"application/vnd.visio"};case"application/vnd.ms-package.3dmanufacturing-3dmodel+xml":return{ext:"3mf",mime:"model/3mf"};default:}}function je(t,e,r){r={offset:0,...r};for(let[n,s]of e.entries())if(r.mask){if(s!==(r.mask[n]&t[n+r.offset]))return!1}else if(s!==t[n+r.offset])return!1;return!0}var ls,us,fm,dm,jl=C(()=>{Yt();Mr();Dl();Ll();Wl();Hl();ls=4100;us=class{constructor(e){this.options={mpegOffsetTolerance:0,...e},this.detectors=[...e?.customDetectors??[],{id:"core",detect:this.detectConfident},{id:"core.imprecise",detect:this.detectImprecise}],this.tokenizerOptions={abortSignal:e?.signal}}async fromTokenizer(e){let r=e.position;for(let n of this.detectors){let s=await n.detect(e);if(s)return s;if(r!==e.position)return}}async fromBuffer(e){if(!(e instanceof Uint8Array||e instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);let r=e instanceof Uint8Array?e:new Uint8Array(e);if(r?.length>1)return this.fromTokenizer(cl(r,this.tokenizerOptions))}async fromBlob(e){let r=ul(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async fromStream(e){let r=Yn(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async toDetectionStream(e,r){let{sampleSize:n=ls}=r,s,i,a=e.getReader({mode:"byob"});try{let{value:c,done:u}=await a.read(new Uint8Array(n));if(i=c,!u&&c)try{s=await this.fromBuffer(c.subarray(0,n))}catch(f){if(!(f instanceof Q))throw f;s=void 0}i=c}finally{a.releaseLock()}let o=new TransformStream({async start(c){c.enqueue(i)},transform(c,u){u.enqueue(c)}}),l=e.pipeThrough(o);return l.fileType=s,l}check(e,r){return je(this.buffer,e,r)}checkString(e,r){return this.check(Ml(e,r?.encoding),r)}detectConfident=async e=>{if(this.buffer=new Uint8Array(ls),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:32,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.detectConfident(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8])){let n=new tr(e).inflate(),s=!0;try{let i;try{i=await this.fromStream(n)}catch{s=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{s&&await n.cancel()}return{ext:"gz",mime:"application/gzip"}}if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let r=await e.readToken(Bl);return e.position+r>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(r),this.fromTokenizer(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){let r;return await new er(e).unzip(n=>{switch(n.filename){case"META-INF/mozilla.rsa":return r={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return r={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(s){let i=new TextDecoder("utf-8").decode(s).trim();r=cs(i)},stop:!0};case"[Content_Types].xml":return{async handler(s){let i=new TextDecoder("utf-8").decode(s),a=i.indexOf('.main+xml"');if(a===-1){let o="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${o}"`)&&(r=cs(o))}else{i=i.slice(0,Math.max(0,a));let o=i.lastIndexOf('"'),l=i.slice(Math.max(0,o+1));r=cs(l)}},stop:!0};default:return/classes\d*\.dex/.test(n.filename)?(r={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(n=>{if(!(n instanceof Q))throw n}),r??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let r=new Uint8Array(8);return await e.readBuffer(r),je(r,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:je(r,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:je(r,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:je(r,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:je(r,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:je(r,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF"))return{ext:"pdf",mime:"application/pdf"};if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let r=await this.readTiffHeader(!1);if(r)return r}if(this.check([77,77])){let r=await this.readTiffHeader(!0);if(r)return r}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function r(){let o=await e.peekNumber(gl),l=128,c=0;for(;(o&l)===0&&l!==0;)++c,l>>=1;let u=new Uint8Array(c+1);return await e.readBuffer(u),u}async function n(){let o=await r(),l=await r();l[0]^=128>>l.length-1;let c=Math.min(6,l.length),u=new DataView(o.buffer),f=new DataView(l.buffer,l.length-c,c);return{id:os(u),len:os(f)}}async function s(o){for(;o>0;){let l=await n();if(l.id===17026)return(await e.readToken(new Ee(l.len))).replaceAll(/\00.*$/g,"");await e.ignore(l.len),--o}}let i=await n();switch(await s(i.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/matroska"};default:return}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1")||this.checkString("PARE"))return{ext:"parquet",mime:"application/vnd.apache.parquet"};if(this.checkString("ttcf"))return{ext:"ttc",mime:"font/collection"};if(this.check([207,250,237,254]))return{ext:"macho",mime:"application/x-mach-binary"};if(this.check([4,34,77,24]))return{ext:"lz4",mime:"application/x-lz4"};if(this.checkString("regf"))return{ext:"dat",mime:"application/x-ft-windows-registry-hive"};if(this.checkString("$FL2")||this.checkString("$FL3"))return{ext:"sav",mime:"application/x-spss-sav"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190]))return{ext:"class",mime:"application/java-vm"};if(this.checkString(".RMF"))return{ext:"rm",mime:"application/vnd.rn-realmedia"};if(this.checkString("DRACO"))return{ext:"drc",mime:"application/vnd.google.draco"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let r=new Ee(4,"latin1").get(this.buffer,2);if(r.match("^d*")&&r>=1e3&&r<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new Ee(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
420
|
+
`,"\r"," "," ","\0"].some(r=>this.checkString(r,{offset:6})))return{ext:"vtt",mime:"text/vtt"};if(this.check([137,80,78,71,13,10,26,10])){await e.ignore(8);async function r(){return{length:await e.readToken(yl),type:await e.readToken(new Ee(4,"latin1"))}}do{let n=await r();if(n.length<0)return;switch(n.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(n.length+4)}}while(e.position+8<e.fileInfo.size);return{ext:"png",mime:"image/png"}}if(this.check([65,82,82,79,87,49,0,0]))return{ext:"arrow",mime:"application/vnd.apache.arrow.file"};if(this.check([103,108,84,70,2,0,0,0]))return{ext:"glb",mime:"model/gltf-binary"};if(this.check([102,114,101,101],{offset:4})||this.check([109,100,97,116],{offset:4})||this.check([109,111,111,118],{offset:4})||this.check([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(this.check([73,73,82,79,8,0,0,0,24]))return{ext:"orf",mime:"image/x-olympus-orf"};if(this.checkString("gimp xcf "))return{ext:"xcf",mime:"image/x-xcf"};if(this.checkString("ftyp",{offset:4})&&(this.buffer[8]&96)!==0){let r=new Ee(4,"latin1").get(this.buffer,8).replace("\0"," ").trim();switch(r){case"avif":case"avis":return{ext:"avif",mime:"image/avif"};case"mif1":return{ext:"heic",mime:"image/heif"};case"msf1":return{ext:"heic",mime:"image/heif-sequence"};case"heic":case"heix":return{ext:"heic",mime:"image/heic"};case"hevc":case"hevx":return{ext:"heic",mime:"image/heic-sequence"};case"qt":return{ext:"mov",mime:"video/quicktime"};case"M4V":case"M4VH":case"M4VP":return{ext:"m4v",mime:"video/x-m4v"};case"M4P":return{ext:"m4p",mime:"video/mp4"};case"M4B":return{ext:"m4b",mime:"audio/mp4"};case"M4A":return{ext:"m4a",mime:"audio/x-m4a"};case"F4V":return{ext:"f4v",mime:"video/mp4"};case"F4P":return{ext:"f4p",mime:"video/mp4"};case"F4A":return{ext:"f4a",mime:"audio/mp4"};case"F4B":return{ext:"f4b",mime:"audio/mp4"};case"crx":return{ext:"cr3",mime:"image/x-canon-cr3"};default:return r.startsWith("3g")?r.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.checkString(`REGEDIT4\r
|
|
421
|
+
`))return{ext:"reg",mime:"application/x-ms-regedit"};if(this.check([82,73,70,70])){if(this.checkString("WEBP",{offset:8}))return{ext:"webp",mime:"image/webp"};if(this.check([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(this.check([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/wav"};if(this.check([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(this.check([73,73,85,0,24,0,0,0,136,231,116,216]))return{ext:"rw2",mime:"image/x-panasonic-rw2"};if(this.check([48,38,178,117,142,102,207,17,166,217])){async function r(){let n=new Uint8Array(16);return await e.readBuffer(n),{id:n,size:Number(await e.readToken(wl))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await r(),s=n.size-24;if(je(n.id,[145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101])){let i=new Uint8Array(16);if(s-=await e.readBuffer(i),je(i,[64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"audio/x-ms-asf"};if(je(i,[192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"video/x-ms-asf"};break}await e.ignore(s)}return{ext:"asf",mime:"application/vnd.ms-asf"}}if(this.check([171,75,84,88,32,49,49,187,13,10,26,10]))return{ext:"ktx",mime:"image/ktx"};if((this.check([126,16,4])||this.check([126,24,4]))&&this.check([48,77,73,69],{offset:4}))return{ext:"mie",mime:"application/x-mie"};if(this.check([39,10,0,0,0,0,0,0,0,0,0,0],{offset:2}))return{ext:"shp",mime:"application/x-esri-shape"};if(this.check([255,79,255,81]))return{ext:"j2c",mime:"image/j2c"};if(this.check([0,0,0,12,106,80,32,32,13,10,135,10]))switch(await e.ignore(20),await e.readToken(new Ee(4,"ascii"))){case"jp2 ":return{ext:"jp2",mime:"image/jp2"};case"jpx ":return{ext:"jpx",mime:"image/jpx"};case"jpm ":return{ext:"jpm",mime:"image/jpm"};case"mjp2":return{ext:"mj2",mime:"image/mj2"};default:return}if(this.check([255,10])||this.check([0,0,0,12,74,88,76,32,13,10,135,10]))return{ext:"jxl",mime:"image/jxl"};if(this.check([254,255]))return this.checkString("<?xml ",{offset:2,encoding:"utf-16be"})?{ext:"xml",mime:"application/xml"}:void 0;if(this.check([208,207,17,224,161,177,26,225]))return{ext:"cfb",mime:"application/x-cfb"};if(await e.peekBuffer(this.buffer,{length:Math.min(256,e.fileInfo.size),mayBeLess:!0}),this.check([97,99,115,112],{offset:36}))return{ext:"icc",mime:"application/vnd.iccprofile"};if(this.checkString("**ACE",{offset:7})&&this.checkString("**",{offset:12}))return{ext:"ace",mime:"application/x-ace-compressed"};if(this.checkString("BEGIN:")){if(this.checkString("VCARD",{offset:6}))return{ext:"vcf",mime:"text/vcard"};if(this.checkString("VCALENDAR",{offset:6}))return{ext:"ics",mime:"text/calendar"}}if(this.checkString("FUJIFILMCCD-RAW"))return{ext:"raf",mime:"image/x-fujifilm-raf"};if(this.checkString("Extended Module:"))return{ext:"xm",mime:"audio/x-xm"};if(this.checkString("Creative Voice File"))return{ext:"voc",mime:"audio/x-voc"};if(this.check([4,0,0,0])&&this.buffer.length>=16){let r=new DataView(this.buffer.buffer).getUint32(12,!0);if(r>12&&this.buffer.length>=r+16)try{let n=new TextDecoder().decode(this.buffer.subarray(16,r+16));if(JSON.parse(n).files)return{ext:"asar",mime:"application/x-asar"}}catch{}}if(this.check([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(this.checkString("SCRM",{offset:44}))return{ext:"s3m",mime:"audio/x-s3m"};if(this.check([71])&&this.check([71],{offset:188}))return{ext:"mts",mime:"video/mp2t"};if(this.check([71],{offset:4})&&this.check([71],{offset:196}))return{ext:"mts",mime:"video/mp2t"};if(this.check([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(this.check([68,73,67,77],{offset:128}))return{ext:"dcm",mime:"application/dicom"};if(this.check([76,0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70]))return{ext:"lnk",mime:"application/x.ms.shortcut"};if(this.check([98,111,111,107,0,0,0,0,109,97,114,107,0,0,0,0]))return{ext:"alias",mime:"application/x.apple.alias"};if(this.checkString("Kaydara FBX Binary \0"))return{ext:"fbx",mime:"application/x.autodesk.fbx"};if(this.check([76,80],{offset:34})&&(this.check([0,0,1],{offset:8})||this.check([1,0,2],{offset:8})||this.check([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(this.check([6,6,237,245,216,29,70,229,189,49,239,231,254,116,183,29]))return{ext:"indd",mime:"application/x-indesign"};if(this.check([255,255,0,0,7,0,0,0,4,0,0,0,1,0,1,0])||this.check([0,0,255,255,0,0,0,7,0,0,0,4,0,1,0,1]))return{ext:"jmp",mime:"application/x-jmp-data"};if(await e.peekBuffer(this.buffer,{length:Math.min(512,e.fileInfo.size),mayBeLess:!0}),this.checkString("ustar",{offset:257})&&(this.checkString("\0",{offset:262})||this.checkString(" ",{offset:262}))||this.check([0,0,0,0,0,0],{offset:257})&&_l(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254])){let r="utf-16le";return this.checkString("<?xml ",{offset:2,encoding:r})?{ext:"xml",mime:"application/xml"}:this.check([255,14],{offset:2})&&this.checkString("SketchUp Model",{offset:4,encoding:r})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:this.checkString(`Windows Registry Editor Version 5.00\r
|
|
422
|
+
`,{offset:2,encoding:r})?{ext:"reg",mime:"application/x-ms-regedit"}:void 0}if(this.checkString("-----BEGIN PGP MESSAGE-----"))return{ext:"pgp",mime:"application/pgp-encrypted"}};detectImprecise=async e=>{if(this.buffer=new Uint8Array(ls),await e.peekBuffer(this.buffer,{length:Math.min(8,e.fileInfo.size),mayBeLess:!0}),this.check([0,0,1,186])||this.check([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(this.check([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(this.check([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(this.check([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(await e.peekBuffer(this.buffer,{length:Math.min(2+this.options.mpegOffsetTolerance,e.fileInfo.size),mayBeLess:!0}),this.buffer.length>=2+this.options.mpegOffsetTolerance)for(let r=0;r<=this.options.mpegOffsetTolerance;++r){let n=this.scanMpeg(r);if(n)return n}};async readTiffTag(e){let r=await this.tokenizer.readToken(e?Ft:Y);switch(this.tokenizer.ignore(10),r){case 50341:return{ext:"arw",mime:"image/x-sony-arw"};case 50706:return{ext:"dng",mime:"image/x-adobe-dng"};default:}}async readTiffIFD(e){let r=await this.tokenizer.readToken(e?Ft:Y);for(let n=0;n<r;++n){let s=await this.readTiffTag(e);if(s)return s}}async readTiffHeader(e){let r=(e?Ft:Y).get(this.buffer,2),n=(e?xl:ie).get(this.buffer,4);if(r===42){if(n>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(n>=8){let i=(e?Ft:Y).get(this.buffer,8),a=(e?Ft:Y).get(this.buffer,10);if(i===28&&a===254||i===31&&a===11)return{ext:"nef",mime:"image/x-nikon-nef"}}}return await this.tokenizer.ignore(n),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(r===43)return{ext:"tif",mime:"image/tiff"}}scanMpeg(e){if(this.check([255,224],{offset:e,mask:[255,224]})){if(this.check([16],{offset:e+1,mask:[22]}))return this.check([8],{offset:e+1,mask:[8]})?{ext:"aac",mime:"audio/aac"}:{ext:"aac",mime:"audio/aac"};if(this.check([2],{offset:e+1,mask:[6]}))return{ext:"mp3",mime:"audio/mpeg"};if(this.check([4],{offset:e+1,mask:[6]}))return{ext:"mp2",mime:"audio/mpeg"};if(this.check([6],{offset:e+1,mask:[6]}))return{ext:"mp1",mime:"audio/mpeg"}}}},fm=new Set(Ul),dm=new Set(zl)});var Gl=C(()=>{fl();jl()});var Zl={};R(Zl,{fileCommand:()=>ym});function pm(t,e){if(Vl[t])return Vl[t];let[r,n]=e.split("/"),s=n?.split("+")[0]?.replace(/-/g," ")||t;switch(r){case"image":return`${s.toUpperCase()} image data`;case"audio":return`${s.toUpperCase()} audio`;case"video":return`${s.toUpperCase()} video`;case"font":return`${s} font`;case"model":return`${s} 3D model`;case"application":return n?.includes("zip")||n?.includes("compressed")?`${s} archive data`:n?.includes("executable")?`${s} executable`:`${t.toUpperCase()} data`;default:return`${t.toUpperCase()} data`}}function mm(t){let e=t.split("/").pop()||t;if(e.startsWith(".")&&!e.includes(".",1))return e;let r=e.lastIndexOf(".");return r===-1||r===0?"":e.slice(r).toLowerCase()}function gm(t,e){if(t.startsWith("#!")){let l=t.split(`
|
|
423
|
+
`)[0];return l.includes("python")?{description:"Python script, ASCII text executable",mime:"text/x-python"}:l.includes("node")||l.includes("bun")||l.includes("deno")?{description:"JavaScript script, ASCII text executable",mime:"text/javascript"}:l.includes("bash")?{description:"Bourne-Again shell script, ASCII text executable",mime:"text/x-shellscript"}:l.includes("sh")?{description:"POSIX shell script, ASCII text executable",mime:"text/x-shellscript"}:l.includes("ruby")?{description:"Ruby script, ASCII text executable",mime:"text/x-ruby"}:l.includes("perl")?{description:"Perl script, ASCII text executable",mime:"text/x-perl"}:{description:"script, ASCII text executable",mime:"text/plain"}}let r=t.trimStart();if(r.startsWith("<?xml"))return{description:"XML document",mime:"application/xml"};if(r.startsWith("<!DOCTYPE html")||r.toLowerCase().startsWith("<html"))return{description:"HTML document",mime:"text/html"};let n=t.includes(`\r
|
|
424
|
+
`),s=t.includes("\r")&&!n,i="";n?i=", with CRLF line terminators":s&&(i=", with CR line terminators");let a=mm(e);if(a&&ql[a]){let l=ql[a];return l.mime.startsWith("text/")&&i?{description:`${l.description}${i}`,mime:l.mime}:l}let o=!1;for(let l=0;l<Math.min(t.length,8192);l++)if(t.charCodeAt(l)>127){o=!0;break}return o?{description:`UTF-8 Unicode text${i}`,mime:"text/plain; charset=utf-8"}:{description:`ASCII text${i}`,mime:"text/plain"}}async function xm(t,e){if(e.length===0)return{description:"empty",mime:"inode/x-empty"};let r=await fs(e);if(r)return{description:pm(r.ext,r.mime),mime:r.mime};let n=new TextDecoder("utf-8",{fatal:!1}).decode(e);return gm(n,t)}var hm,ql,Vl,ym,Ql=C(()=>{"use strict";Gl();M();hm={name:"file",summary:"determine file type",usage:"file [OPTION]... FILE...",options:["-b, --brief do not prepend filenames to output","-i, --mime output MIME type strings","-L, --dereference follow symlinks"," --help display this help and exit"]},ql={".js":{description:"JavaScript source",mime:"text/javascript"},".mjs":{description:"JavaScript module",mime:"text/javascript"},".cjs":{description:"CommonJS module",mime:"text/javascript"},".ts":{description:"TypeScript source",mime:"text/typescript"},".tsx":{description:"TypeScript JSX source",mime:"text/typescript"},".jsx":{description:"JavaScript JSX source",mime:"text/javascript"},".py":{description:"Python script",mime:"text/x-python"},".rb":{description:"Ruby script",mime:"text/x-ruby"},".go":{description:"Go source",mime:"text/x-go"},".rs":{description:"Rust source",mime:"text/x-rust"},".c":{description:"C source",mime:"text/x-c"},".h":{description:"C header",mime:"text/x-c"},".cpp":{description:"C++ source",mime:"text/x-c++"},".hpp":{description:"C++ header",mime:"text/x-c++"},".java":{description:"Java source",mime:"text/x-java"},".sh":{description:"Bourne-Again shell script",mime:"text/x-shellscript"},".bash":{description:"Bourne-Again shell script",mime:"text/x-shellscript"},".zsh":{description:"Zsh shell script",mime:"text/x-shellscript"},".json":{description:"JSON data",mime:"application/json"},".yaml":{description:"YAML data",mime:"text/yaml"},".yml":{description:"YAML data",mime:"text/yaml"},".xml":{description:"XML document",mime:"application/xml"},".csv":{description:"CSV text",mime:"text/csv"},".toml":{description:"TOML data",mime:"text/toml"},".html":{description:"HTML document",mime:"text/html"},".htm":{description:"HTML document",mime:"text/html"},".css":{description:"CSS stylesheet",mime:"text/css"},".svg":{description:"SVG image",mime:"image/svg+xml"},".md":{description:"Markdown document",mime:"text/markdown"},".markdown":{description:"Markdown document",mime:"text/markdown"},".txt":{description:"ASCII text",mime:"text/plain"},".rst":{description:"reStructuredText",mime:"text/x-rst"},".env":{description:"ASCII text",mime:"text/plain"},".gitignore":{description:"ASCII text",mime:"text/plain"},".dockerignore":{description:"ASCII text",mime:"text/plain"}},Vl={jpg:"JPEG image data",jpeg:"JPEG image data",png:"PNG image data",gif:"GIF image data",webp:"WebP image data",bmp:"PC bitmap",ico:"MS Windows icon resource",tif:"TIFF image data",tiff:"TIFF image data",psd:"Adobe Photoshop Document",avif:"AVIF image",heic:"HEIC image",heif:"HEIF image",jxl:"JPEG XL image",icns:"Mac OS X icon",svg:"SVG Scalable Vector Graphics image",pdf:"PDF document",epub:"EPUB document",mobi:"Mobipocket E-book",djvu:"DjVu document",zip:"Zip archive data",gz:"gzip compressed data",gzip:"gzip compressed data",bz2:"bzip2 compressed data",xz:"XZ compressed data",tar:"POSIX tar archive",rar:"RAR archive data","7z":"7-zip archive data",lz:"lzip compressed data",lzma:"LZMA compressed data",zst:"Zstandard compressed data",cab:"Microsoft Cabinet archive",ar:"Unix ar archive",rpm:"RPM package",deb:"Debian binary package",apk:"Android Package",dmg:"Apple disk image",iso:"ISO 9660 CD-ROM filesystem data",vhd:"Microsoft Virtual Hard Disk",vhdx:"Microsoft Virtual Hard Disk (new format)",qcow2:"QEMU QCOW Image",mp3:"Audio file with ID3",m4a:"MPEG-4 audio",aac:"AAC audio",wav:"RIFF (little-endian) data, WAVE audio",flac:"FLAC audio bitstream data",ogg:"Ogg data",oga:"Ogg audio",opus:"Ogg Opus audio",aiff:"AIFF audio",wma:"Windows Media Audio",amr:"AMR audio",mid:"MIDI audio",midi:"MIDI audio",ape:"Monkey's Audio",mp4:"ISO Media, MPEG-4",m4v:"MPEG-4 video",webm:"WebM",avi:"RIFF (little-endian) data, AVI",mov:"ISO Media, Apple QuickTime movie",mkv:"Matroska data",wmv:"Windows Media Video",flv:"Flash Video","3gp":"3GPP multimedia","3g2":"3GPP2 multimedia",ogv:"Ogg video",mts:"MPEG transport stream",m2ts:"MPEG transport stream",ts:"MPEG transport stream",mpg:"MPEG video",mpeg:"MPEG video",exe:"PE32 executable",dll:"PE32 DLL",elf:"ELF executable",mach:"Mach-O executable",wasm:"WebAssembly (wasm) binary module",dex:"Android Dalvik executable",class:"Java class file",swf:"Adobe Flash",doc:"Microsoft Word Document",docx:"Microsoft Word 2007+ Document",xls:"Microsoft Excel Spreadsheet",xlsx:"Microsoft Excel 2007+ Spreadsheet",ppt:"Microsoft PowerPoint Presentation",pptx:"Microsoft PowerPoint 2007+ Presentation",odt:"OpenDocument Text",ods:"OpenDocument Spreadsheet",odp:"OpenDocument Presentation",ttf:"TrueType Font",otf:"OpenType Font",woff:"Web Open Font Format",woff2:"Web Open Font Format 2",eot:"Embedded OpenType font",stl:"Stereolithography CAD",obj:"Wavefront 3D Object",gltf:"GL Transmission Format",glb:"GL Transmission Format (binary)",sqlite:"SQLite 3.x database",mdb:"Microsoft Access Database",xml:"XML document",json:"JSON data",macho:"Mach-O binary",ics:"iCalendar data",vcf:"vCard data",msi:"Microsoft Installer",ps:"PostScript",ai:"Adobe Illustrator",indd:"Adobe InDesign",sketch:"Sketch design file",fig:"Figma design file",xd:"Adobe XD",blend:"Blender",fbx:"Autodesk FBX",lnk:"MS Windows shortcut",alias:"Mac OS alias",torrent:"BitTorrent file",pcap:"pcap capture file",arrow:"Apache Arrow",parquet:"Apache Parquet"};ym={name:"file",async execute(t,e){if(v(t))return k(hm);let r=!1,n=!1,s=[];for(let o of t)if(o.startsWith("--")){if(o==="--brief")r=!0;else if(o==="--mime"||o==="--mime-type")n=!0;else if(o!=="--dereference")return T("file",o)}else if(o.startsWith("-")&&o!=="-"){for(let l of o.slice(1))if(l==="b")r=!0;else if(l==="i")n=!0;else if(l!=="L")return T("file",`-${l}`)}else s.push(o);if(s.length===0)return{stdout:"",stderr:`Usage: file [-bLi] FILE...
|
|
425
|
+
`,exitCode:1};let i="",a=0;for(let o of s)try{let l=e.fs.resolvePath(e.cwd,o);if((await e.fs.stat(l)).isDirectory){let h=n?"inode/directory":"directory";i+=r?`${h}
|
|
426
|
+
`:`${o}: ${h}
|
|
427
|
+
`;continue}let u=await e.fs.readFileBuffer(l),f=await xm(o,u),d=n?f.mime:f.description;i+=r?`${d}
|
|
428
|
+
`:`${o}: ${d}
|
|
429
|
+
`}catch{i+=r?`cannot open
|
|
430
|
+
`:`${o}: cannot open (No such file or directory)
|
|
431
|
+
`,a=1}return{stdout:i,stderr:"",exitCode:a}}}});var Xl={};R(Xl,{htmlToMarkdownCommand:()=>bm});import wm from"turndown";var Em,bm,Kl=C(()=>{"use strict";M();Em={name:"html-to-markdown",summary:"convert HTML to Markdown (BashEnv extension)",usage:"html-to-markdown [OPTION]... [FILE]",description:["Convert HTML content to Markdown format using the turndown library.","This is a non-standard BashEnv extension command, not available in regular bash.","","Read HTML from FILE or standard input and output Markdown to standard output.","Commonly used with curl to convert web pages:"," curl -s https://example.com | html-to-markdown","","Supported HTML elements:"," - Headings (h1-h6) \u2192 # Markdown headings"," - Paragraphs (p) \u2192 Plain text with blank lines"," - Links (a) \u2192 [text](url)"," - Images (img) \u2192 "," - Bold/Strong \u2192 **text**"," - Italic/Em \u2192 _text_"," - Code (code, pre) \u2192 `inline` or fenced blocks"," - Lists (ul, ol, li) \u2192 - or 1. items"," - Blockquotes \u2192 > quoted text"," - Horizontal rules (hr) \u2192 ---"],options:["-b, --bullet=CHAR bullet character for unordered lists (-, +, or *)","-c, --code=FENCE fence style for code blocks (``` or ~~~)","-r, --hr=STRING string for horizontal rules (default: ---)"," --heading-style=STYLE"," heading style: 'atx' for # headings (default),"," 'setext' for underlined headings (h1/h2 only)"," --help display this help and exit"],examples:["echo '<h1>Hello</h1><p>World</p>' | html-to-markdown","html-to-markdown page.html","curl -s https://example.com | html-to-markdown > page.md"]},bm={name:"html-to-markdown",async execute(t,e){if(v(t))return k(Em);let r="-",n="```",s="---",i="atx",a=[];for(let l=0;l<t.length;l++){let c=t[l];if(c==="-b"||c==="--bullet")r=t[++l]??"-";else if(c.startsWith("--bullet="))r=c.slice(9);else if(c==="-c"||c==="--code")n=t[++l]??"```";else if(c.startsWith("--code="))n=c.slice(7);else if(c==="-r"||c==="--hr")s=t[++l]??"---";else if(c.startsWith("--hr="))s=c.slice(5);else if(c.startsWith("--heading-style=")){let u=c.slice(16);(u==="setext"||u==="atx")&&(i=u)}else if(c==="-")a.push("-");else{if(c.startsWith("--"))return T("html-to-markdown",c);if(c.startsWith("-"))return T("html-to-markdown",c);a.push(c)}}let o;if(a.length===0||a.length===1&&a[0]==="-")o=e.stdin;else try{let l=e.fs.resolvePath(e.cwd,a[0]);o=await e.fs.readFile(l)}catch{return{stdout:"",stderr:`html-to-markdown: ${a[0]}: No such file or directory
|
|
432
|
+
`,exitCode:1}}if(!o.trim())return{stdout:"",stderr:"",exitCode:0};try{let l=new wm({bulletListMarker:r,codeBlockStyle:"fenced",fence:n,hr:s,headingStyle:i});return l.remove(["script","style","footer"]),{stdout:`${l.turndown(o).trim()}
|
|
433
|
+
`,stderr:"",exitCode:0}}catch(l){return{stdout:"",stderr:`html-to-markdown: conversion error: ${l.message}
|
|
434
|
+
`,exitCode:1}}}}});var Jl={};R(Jl,{helpCommand:()=>Am});function Cm(t){let e=[],r=new Set(t);e.push(`Available commands:
|
|
435
|
+
`);let n=[];for(let[s,i]of Object.entries(Sm)){let a=i.filter(o=>r.has(o));if(a.length>0){e.push(` ${s}:`),e.push(` ${a.join(", ")}
|
|
400
436
|
`);for(let o of a)r.delete(o)}}for(let s of r)n.push(s);return n.length>0&&(e.push(" Other:"),e.push(` ${n.sort().join(", ")}
|
|
401
437
|
`)),e.push("Use '<command> --help' for details on a specific command."),`${e.join(`
|
|
402
438
|
`)}
|
|
403
|
-
`}var
|
|
439
|
+
`}var Sm,Am,Yl=C(()=>{"use strict";Sm={"File operations":["ls","cat","head","tail","wc","touch","mkdir","rm","cp","mv","ln","chmod","stat","readlink"],"Text processing":["grep","sed","awk","sort","uniq","cut","tr","tee","diff"],Search:["find"],"Navigation & paths":["pwd","basename","dirname","tree","du"],"Environment & shell":["echo","printf","env","printenv","export","alias","unalias","history","clear","true","false","bash","sh"],"Data processing":["xargs","jq","base64","date"],Network:["curl","html-to-markdown"]};Am={name:"help",async execute(t,e){if(t.includes("--help")||t.includes("-h"))return{stdout:`help - display available commands
|
|
404
440
|
|
|
405
441
|
Usage: help [command]
|
|
406
442
|
|
|
@@ -409,96 +445,96 @@ Options:
|
|
|
409
445
|
|
|
410
446
|
If a command name is provided, shows help for that command.
|
|
411
447
|
Otherwise, lists all available commands.
|
|
412
|
-
`,stderr:"",exitCode:0};if(t.length>0&&e.exec){let n=t[0];return e.exec(`${n} --help`,{cwd:e.cwd})}let r=e.getRegisteredCommands?.()??[];return{stdout:
|
|
413
|
-
`),!n))break}f||(
|
|
448
|
+
`,stderr:"",exitCode:0};if(t.length>0&&e.exec){let n=t[0];return e.exec(`${n} --help`,{cwd:e.cwd})}let r=e.getRegisteredCommands?.()??[];return{stdout:Cm(r),stderr:"",exitCode:0}}}});var ec={};R(ec,{whichCommand:()=>Nm});var km,vm,Nm,tc=C(()=>{"use strict";ue();M();km={name:"which",summary:"locate a command",usage:"which [-as] program ...",options:["-a List all instances of executables found","-s No output, just return 0 if found, 1 if not","--help display this help and exit"]},vm={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},Nm={name:"which",async execute(t,e){if(v(t))return k(km);let r=j("which",t,vm);if(!r.ok)return r.error;let n=r.result.flags.showAll,s=r.result.flags.silent,i=r.result.positional;if(i.length===0)return{stdout:"",stderr:"",exitCode:1};let o=(e.env.PATH||"/bin:/usr/bin").split(":"),l="",c=!0;for(let u of i){let f=!1;for(let d of o){if(!d)continue;let h=`${d}/${u}`;if(await e.fs.exists(h)&&(f=!0,s||(l+=`${h}
|
|
449
|
+
`),!n))break}f||(c=!1)}return{stdout:l,stderr:"",exitCode:c?0:1}}}});function ds(t){let e=t.indexOf("=");if(e>=0){let r=t.slice(0,e),n=t.slice(e+1);return r?`${encodeURIComponent(r)}=${encodeURIComponent(n)}`:encodeURIComponent(n)}return encodeURIComponent(t)}function hs(t){let e=t.indexOf("=");if(e<0)return null;let r=t.slice(0,e),n=t.slice(e+1),s,i,a=n.match(/;type=([^;]+)$/);a&&(i=a[1],n=n.slice(0,-a[0].length));let o=n.match(/;filename=([^;]+)/);return o&&(s=o[1],n=n.replace(o[0],"")),(n.startsWith("@")||n.startsWith("<"))&&(s=s??n.slice(1).split("/").pop()),{name:r,value:n,filename:s,contentType:i}}function rc(t,e){let r=`----CurlFormBoundary${Date.now().toString(36)}`,n=[];for(let s of t){let i=s.value;if(i.startsWith("@")||i.startsWith("<")){let o=i.slice(1);i=e.get(o)??""}let a=`--${r}\r
|
|
414
450
|
`;s.filename?(a+=`Content-Disposition: form-data; name="${s.name}"; filename="${s.filename}"\r
|
|
415
451
|
`,s.contentType&&(a+=`Content-Type: ${s.contentType}\r
|
|
416
452
|
`)):a+=`Content-Disposition: form-data; name="${s.name}"\r
|
|
417
453
|
`,a+=`\r
|
|
418
454
|
${i}\r
|
|
419
455
|
`,n.push(a)}return n.push(`--${r}--\r
|
|
420
|
-
`),{body:n.join(""),boundary:r}}var
|
|
421
|
-
`)}function
|
|
422
|
-
`),r}var
|
|
456
|
+
`),{body:n.join(""),boundary:r}}var ps=C(()=>{"use strict"});var nc,sc=C(()=>{"use strict";nc={name:"curl",summary:"transfer a URL",usage:"curl [OPTIONS] URL",options:["-X, --request METHOD HTTP method (GET, POST, PUT, DELETE, etc.)","-H, --header HEADER Add header (can be used multiple times)","-d, --data DATA HTTP POST data"," --data-raw DATA HTTP POST data (no @ interpretation)"," --data-binary DATA HTTP POST binary data"," --data-urlencode DATA URL-encode and POST data","-F, --form NAME=VALUE Multipart form data","-u, --user USER:PASS HTTP authentication","-A, --user-agent STR Set User-Agent header","-e, --referer URL Set Referer header","-b, --cookie DATA Send cookies (name=value or @file)","-c, --cookie-jar FILE Save cookies to file","-T, --upload-file FILE Upload file (PUT)","-o, --output FILE Write output to file","-O, --remote-name Write to file named from URL","-I, --head Show headers only (HEAD request)","-i, --include Include response headers in output","-s, --silent Silent mode (no progress)","-S, --show-error Show errors even when silent","-f, --fail Fail silently on HTTP errors (no output)","-L, --location Follow redirects (default)"," --max-redirs NUM Maximum redirects (default: 20)","-m, --max-time SECS Maximum time for request"," --connect-timeout SECS Connection timeout","-w, --write-out FMT Output format after completion","-v, --verbose Verbose output"," --help Display this help and exit","","Note: Network access must be configured via BashEnv network option."," curl is not available by default for security reasons."]}});function ic(t){let e={method:"GET",headers:{},dataBinary:!1,formFields:[],useRemoteName:!1,headOnly:!1,includeHeaders:!1,silent:!1,showError:!1,failSilently:!1,followRedirects:!0,verbose:!1};for(let r=0;r<t.length;r++){let n=t[r];if(n==="-X"||n==="--request")e.method=t[++r]??"GET";else if(n.startsWith("-X"))e.method=n.slice(2);else if(n.startsWith("--request="))e.method=n.slice(10);else if(n==="-H"||n==="--header"){let s=t[++r];if(s){let i=s.indexOf(":");if(i>0){let a=s.slice(0,i).trim(),o=s.slice(i+1).trim();e.headers[a]=o}}}else if(n.startsWith("--header=")){let s=n.slice(9),i=s.indexOf(":");if(i>0){let a=s.slice(0,i).trim(),o=s.slice(i+1).trim();e.headers[a]=o}}else if(n==="-d"||n==="--data"||n==="--data-raw")e.data=t[++r]??"",e.method==="GET"&&(e.method="POST");else if(n.startsWith("-d"))e.data=n.slice(2),e.method==="GET"&&(e.method="POST");else if(n.startsWith("--data="))e.data=n.slice(7),e.method==="GET"&&(e.method="POST");else if(n.startsWith("--data-raw="))e.data=n.slice(11),e.method==="GET"&&(e.method="POST");else if(n==="--data-binary")e.data=t[++r]??"",e.dataBinary=!0,e.method==="GET"&&(e.method="POST");else if(n.startsWith("--data-binary="))e.data=n.slice(14),e.dataBinary=!0,e.method==="GET"&&(e.method="POST");else if(n==="--data-urlencode"){let s=t[++r]??"";e.data=(e.data?`${e.data}&`:"")+ds(s),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--data-urlencode=")){let s=n.slice(17);e.data=(e.data?`${e.data}&`:"")+ds(s),e.method==="GET"&&(e.method="POST")}else if(n==="-F"||n==="--form"){let s=t[++r]??"",i=hs(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--form=")){let s=n.slice(7),i=hs(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(n==="-u"||n==="--user")e.user=t[++r];else if(n.startsWith("-u"))e.user=n.slice(2);else if(n.startsWith("--user="))e.user=n.slice(7);else if(n==="-A"||n==="--user-agent")e.headers["User-Agent"]=t[++r]??"";else if(n.startsWith("-A"))e.headers["User-Agent"]=n.slice(2);else if(n.startsWith("--user-agent="))e.headers["User-Agent"]=n.slice(13);else if(n==="-e"||n==="--referer")e.headers.Referer=t[++r]??"";else if(n.startsWith("-e"))e.headers.Referer=n.slice(2);else if(n.startsWith("--referer="))e.headers.Referer=n.slice(10);else if(n==="-b"||n==="--cookie")e.headers.Cookie=t[++r]??"";else if(n.startsWith("-b"))e.headers.Cookie=n.slice(2);else if(n.startsWith("--cookie="))e.headers.Cookie=n.slice(9);else if(n==="-c"||n==="--cookie-jar")e.cookieJar=t[++r];else if(n.startsWith("--cookie-jar="))e.cookieJar=n.slice(13);else if(n==="-T"||n==="--upload-file")e.uploadFile=t[++r],e.method==="GET"&&(e.method="PUT");else if(n.startsWith("--upload-file="))e.uploadFile=n.slice(14),e.method==="GET"&&(e.method="PUT");else if(n==="-m"||n==="--max-time"){let s=parseFloat(t[++r]??"0");!Number.isNaN(s)&&s>0&&(e.timeoutMs=s*1e3)}else if(n.startsWith("--max-time=")){let s=parseFloat(n.slice(11));!Number.isNaN(s)&&s>0&&(e.timeoutMs=s*1e3)}else if(n==="--connect-timeout"){let s=parseFloat(t[++r]??"0");!Number.isNaN(s)&&s>0&&e.timeoutMs===void 0&&(e.timeoutMs=s*1e3)}else if(n.startsWith("--connect-timeout=")){let s=parseFloat(n.slice(18));!Number.isNaN(s)&&s>0&&e.timeoutMs===void 0&&(e.timeoutMs=s*1e3)}else if(n==="-o"||n==="--output")e.outputFile=t[++r];else if(n.startsWith("--output="))e.outputFile=n.slice(9);else if(n==="-O"||n==="--remote-name")e.useRemoteName=!0;else if(n==="-I"||n==="--head")e.headOnly=!0,e.method="HEAD";else if(n==="-i"||n==="--include")e.includeHeaders=!0;else if(n==="-s"||n==="--silent")e.silent=!0;else if(n==="-S"||n==="--show-error")e.showError=!0;else if(n==="-f"||n==="--fail")e.failSilently=!0;else if(n==="-L"||n==="--location")e.followRedirects=!0;else if(n==="--max-redirs")r++;else if(!n.startsWith("--max-redirs="))if(n==="-w"||n==="--write-out")e.writeOut=t[++r];else if(n.startsWith("--write-out="))e.writeOut=n.slice(12);else if(n==="-v"||n==="--verbose")e.verbose=!0;else{if(n.startsWith("--")&&n!=="--")return T("curl",n);if(n.startsWith("-")&&n!=="-")for(let s of n.slice(1))switch(s){case"s":e.silent=!0;break;case"S":e.showError=!0;break;case"f":e.failSilently=!0;break;case"L":e.followRedirects=!0;break;case"I":e.headOnly=!0,e.method="HEAD";break;case"i":e.includeHeaders=!0;break;case"O":e.useRemoteName=!0;break;case"v":e.verbose=!0;break;default:return T("curl",`-${s}`)}else n.startsWith("-")||(e.url=n)}}return e}var ac=C(()=>{"use strict";M();ps()});function ms(t){return Object.entries(t).map(([e,r])=>`${e}: ${r}`).join(`\r
|
|
457
|
+
`)}function oc(t){try{return new URL(t).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function gs(t,e){let r=t;return r=r.replace(/%\{http_code\}/g,String(e.status)),r=r.replace(/%\{content_type\}/g,e.headers["content-type"]||""),r=r.replace(/%\{url_effective\}/g,e.url),r=r.replace(/%\{size_download\}/g,String(e.bodyLength)),r=r.replace(/\\n/g,`
|
|
458
|
+
`),r}var lc=C(()=>{"use strict"});var cc={};R(cc,{curlCommand:()=>Pm});async function Im(t,e){if(t.uploadFile){let r=e.fs.resolvePath(e.cwd,t.uploadFile);return{body:await e.fs.readFile(r)}}if(t.formFields.length>0){let r=new Map;for(let i of t.formFields)if(i.value.startsWith("@")||i.value.startsWith("<")){let a=e.fs.resolvePath(e.cwd,i.value.slice(1));try{let o=await e.fs.readFile(a);r.set(i.value.slice(1),o)}catch{r.set(i.value.slice(1),"")}}let{body:n,boundary:s}=rc(t.formFields,r);return{body:n,contentType:`multipart/form-data; boundary=${s}`}}return t.data!==void 0?{body:t.data}:{}}function Rm(t,e){let r={...t.headers};if(t.user){let n=Buffer.from(t.user).toString("base64");r.Authorization=`Basic ${n}`}return e&&!r["Content-Type"]&&(r["Content-Type"]=e),r}async function $m(t,e,r){if(!t.cookieJar)return;let n=e["set-cookie"];if(!n)return;let s=r.fs.resolvePath(r.cwd,t.cookieJar);await r.fs.writeFile(s,n)}function Om(t,e,r){let n="";if(t.verbose){n+=`> ${t.method} ${r}
|
|
423
459
|
`;for(let[s,i]of Object.entries(t.headers))n+=`> ${s}: ${i}
|
|
424
460
|
`;n+=`>
|
|
425
461
|
`,n+=`< HTTP/1.1 ${e.status} ${e.statusText}
|
|
426
462
|
`;for(let[s,i]of Object.entries(e.headers))n+=`< ${s}: ${i}
|
|
427
463
|
`;n+=`<
|
|
428
464
|
`}return t.includeHeaders&&!t.verbose&&(n+=`HTTP/1.1 ${e.status} ${e.statusText}\r
|
|
429
|
-
`,n+=
|
|
465
|
+
`,n+=ms(e.headers),n+=`\r
|
|
430
466
|
\r
|
|
431
467
|
`),t.headOnly?t.includeHeaders||t.verbose||(n+=`HTTP/1.1 ${e.status} ${e.statusText}\r
|
|
432
|
-
`,n+=
|
|
433
|
-
`):n+=e.body,t.writeOut&&(n+=
|
|
468
|
+
`,n+=ms(e.headers),n+=`\r
|
|
469
|
+
`):n+=e.body,t.writeOut&&(n+=gs(t.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.length})),n}var Pm,uc=C(()=>{"use strict";Me();M();ps();sc();ac();lc();Pm={name:"curl",async execute(t,e){if(v(t))return k(nc);let r=ic(t);if("exitCode"in r)return r;let n=r;if(!n.url)return{stdout:"",stderr:`curl: no URL specified
|
|
434
470
|
`,exitCode:2};if(!e.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
|
|
435
|
-
`,exitCode:1};let s=n.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:a}=await
|
|
436
|
-
`:"",exitCode:22};let
|
|
437
|
-
`:"",exitCode:o}}}}});import{tool as Ch,zodSchema as Nh}from"ai";import{z as wl}from"zod";var Qa=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(os(),as))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(cs(),ls))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>(hs(),ds))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(gs(),ys))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(Es(),ws))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(Ss(),bs))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>(As(),xs))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>(Ns(),Cs))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(ks(),vs))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>($s(),Is))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Os(),Ps))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(Ts(),Ds))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Fs(),Ls))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(Bs(),Ws))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(Us(),Hs))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(js(),Gs))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(Zs(),Vs))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(qt(),jt))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(qt(),jt))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(qt(),jt))).egrepCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(ii(),si))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(Ii(),ki))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(Ti(),Di))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(Fi(),Li))).uniqCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(_i(),Mi))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(Hi(),Bi))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(Gi(),zi))).trCommand},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(qi(),ji))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(Yi(),Xi))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(ea(),Ji))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(ra(),ta))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(ia(),sa))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(la(),oa))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Yr(),Xr))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Yr(),Xr))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(en(),Jr))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(en(),Jr))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(fa(),ua))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>(ha(),da))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(rn(),tn))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(rn(),tn))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(ma(),pa))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(sn(),nn))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(sn(),nn))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(wa(),ga))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(ba(),Ea))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(Aa(),xa))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(Na(),Ca))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(ka(),va))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>($a(),Ia))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(Pa(),Ra))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(Da(),Oa))).exprCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(La(),Ta))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(Ma(),Fa))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(Wa(),_a))).whichCommand}],hd=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(Za(),Va))).curlCommand}],Ka=new Map;function Xa(t){return{name:t.name,async execute(e,r){let n=Ka.get(t.name);return n||(n=await t.load(),Ka.set(t.name,n)),n.execute(e,r)}}}function Ya(t){return(t?Qa.filter(r=>t.includes(r.name)):Qa).map(Xa)}function Ja(){return hd.map(Xa)}function eo(t){return"load"in t&&typeof t.load=="function"}function to(t){let e=null;return{name:t.name,async execute(r,n){return e||(e=await t.load()),e.execute(r,n)}}}var pd=new TextEncoder,md=new TextDecoder;function fn(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),r=>r.charCodeAt(0));case"hex":{let r=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2)r[n/2]=parseInt(t.slice(n,n+2),16);return r}case"binary":case"latin1":return Uint8Array.from(t,r=>r.charCodeAt(0));default:return pd.encode(t)}}function ro(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(r=>r.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return md.decode(t)}}function rr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var nr=new TextEncoder;function yd(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var tt=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[r,n]of Object.entries(e))yd(n)?this.writeFileSync(r,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(r,n)}normalizePath(e){if(!e||e==="/")return"/";let r=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;r.startsWith("/")||(r=`/${r}`);let n=r.split("/").filter(i=>i&&i!=="."),s=[];for(let i of n)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}dirname(e){let r=this.normalizePath(e);if(r==="/")return"/";let n=r.lastIndexOf("/");return n===0?"/":r.slice(0,n)}ensureParentDirs(e){let r=this.dirname(e);r!=="/"&&(this.data.has(r)||(this.ensureParentDirs(r),this.data.set(r,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,r,n,s){let i=this.normalizePath(e);this.ensureParentDirs(i);let a=rr(n),o=fn(r,a);this.data.set(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,r){let n=await this.readFileBuffer(e),s=rr(r);return ro(n,s)}async readFileBuffer(e){let r=this.normalizePath(e),n=this.data.get(r),s=r;if(!n)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=new Set;for(;n&&n.type==="symlink";){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);i.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return n.content instanceof Uint8Array?n.content:nr.encode(n.content)}async writeFile(e,r,n){this.writeFileSync(e,r,n)}async appendFile(e,r,n){let s=this.normalizePath(e),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let a=rr(n),o=fn(r,a);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:nr.encode(i.content),l=new Uint8Array(c.length+o.length);l.set(c),l.set(o,c.length),this.data.set(s,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(e,r,n)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(n.type==="symlink"){let i=this.resolveSymlink(r,n.target),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);n=a}let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=nr.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:s,mtime:n.mtime||new Date}}async lstat(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=nr.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:s,mtime:n.mtime||new Date}}resolveSymlink(e,r){if(r.startsWith("/"))return this.normalizePath(r);let n=this.dirname(e);return this.normalizePath(n==="/"?`/${r}`:`${n}/${r}`)}async mkdir(e,r){this.mkdirSync(e,r)}mkdirSync(e,r){let n=this.normalizePath(e);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!r?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(n);if(s!=="/"&&!this.data.has(s))if(r?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=r==="/"?"/":`${r}/`,i=[];for(let a of this.data.keys())if(a!==r&&a.startsWith(s)){let c=a.slice(s.length).split("/")[0];c&&!i.includes(c)&&i.push(c)}return i.sort()}async rm(e,r){let n=this.normalizePath(e),s=this.data.get(n);if(!s){if(r?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!r?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,r)}}}this.data.delete(n)}async cp(e,r,n){let s=this.normalizePath(e),i=this.normalizePath(r),a=this.data.get(s);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(s);for(let c of o){let l=s==="/"?`/${c}`:`${s}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(l,u,n)}}}async mv(e,r){await this.cp(e,r,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,r){if(r.startsWith("/"))return this.normalizePath(r);let n=e==="/"?`/${r}`:`${e}/${r}`;return this.normalizePath(n)}async chmod(e,r){let n=this.normalizePath(e),s=this.data.get(n);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=r}async symlink(e,r){let n=this.normalizePath(r);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${r}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,r){let n=this.normalizePath(e),s=this.normalizePath(r),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${r}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return n.target}};Y();Y();function ie(t,e){return{type:"ArithmeticExpression",expression:Le(t,e,0).expr}}function Le(t,e,r){return gd(t,e,r)}function gd(t,e,r){let{expr:n,pos:s}=ir(t,e,r);for(s=ee(e,s);e[s]===",";){s++;let{expr:i,pos:a}=ir(t,e,s);n={type:"ArithBinary",operator:",",left:n,right:i},s=ee(e,a)}return{expr:n,pos:s}}function ir(t,e,r){let{expr:n,pos:s}=wd(t,e,r);if(s=ee(e,s),e[s]==="?"){s++;let{expr:i,pos:a}=Le(t,e,s);if(s=ee(e,a),e[s]===":"){s++;let{expr:o,pos:c}=Le(t,e,s);return{expr:{type:"ArithTernary",condition:n,consequent:i,alternate:o},pos:c}}}return{expr:n,pos:s}}function wd(t,e,r){let{expr:n,pos:s}=no(t,e,r);for(;s=ee(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:i,pos:a}=no(t,e,s);n={type:"ArithBinary",operator:"||",left:n,right:i},s=a}return{expr:n,pos:s}}function no(t,e,r){let{expr:n,pos:s}=so(t,e,r);for(;s=ee(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:i,pos:a}=so(t,e,s);n={type:"ArithBinary",operator:"&&",left:n,right:i},s=a}return{expr:n,pos:s}}function so(t,e,r){let{expr:n,pos:s}=io(t,e,r);for(;s=ee(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:i,pos:a}=io(t,e,s);n={type:"ArithBinary",operator:"|",left:n,right:i},s=a}return{expr:n,pos:s}}function io(t,e,r){let{expr:n,pos:s}=ao(t,e,r);for(;s=ee(e,s),e[s]==="^";){s++;let{expr:i,pos:a}=ao(t,e,s);n={type:"ArithBinary",operator:"^",left:n,right:i},s=a}return{expr:n,pos:s}}function ao(t,e,r){let{expr:n,pos:s}=oo(t,e,r);for(;s=ee(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:i,pos:a}=oo(t,e,s);n={type:"ArithBinary",operator:"&",left:n,right:i},s=a}return{expr:n,pos:s}}function oo(t,e,r){let{expr:n,pos:s}=lo(t,e,r);for(;s=ee(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=lo(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function lo(t,e,r){let{expr:n,pos:s}=dn(t,e,r);for(;;)if(s=ee(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=dn(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else if(e[s]==="<"||e[s]===">"){let i=e[s];s++;let{expr:a,pos:o}=dn(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else break;return{expr:n,pos:s}}function dn(t,e,r){let{expr:n,pos:s}=co(t,e,r);for(;s=ee(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=co(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function co(t,e,r){let{expr:n,pos:s}=uo(t,e,r);for(;s=ee(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let i=e[s];s++;let{expr:a,pos:o}=uo(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function uo(t,e,r){let{expr:n,pos:s}=sr(t,e,r);for(;;)if(s=ee(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:i,pos:a}=sr(t,e,s);n={type:"ArithBinary",operator:"*",left:n,right:i},s=a}else if(e[s]==="/"||e[s]==="%"){let i=e[s];s++;let{expr:a,pos:o}=sr(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else break;return{expr:n,pos:s}}function sr(t,e,r){let{expr:n,pos:s}=hn(t,e,r),i=ee(e,s);if(e.slice(i,i+2)==="**"){i+=2;let{expr:a,pos:o}=sr(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:n,right:a},pos:o}}return{expr:n,pos:s}}function hn(t,e,r){let n=ee(e,r);if(e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let s=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=hn(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}if(e[n]==="+"||e[n]==="-"||e[n]==="!"||e[n]==="~"){let s=e[n];n++;let{expr:i,pos:a}=hn(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return bd(t,e,n)}function Ed(t,e){let r=t[e];return r==="$"||r==="`"}function bd(t,e,r){let{expr:n,pos:s}=fo(t,e,r),i=[n];for(;Ed(e,s);){let{expr:a,pos:o}=fo(t,e,s);i.push(a),s=o}if(i.length>1&&(n={type:"ArithConcat",parts:i}),s=ee(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let a=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:n,prefix:!1},pos:s}}return{expr:n,pos:s}}function fo(t,e,r){let n=ee(e,r);if(e.slice(n,n+3)==="$(("){n+=3;let s=1,i=n;for(;n<e.length-1&&s>0;)e[n]==="("&&e[n+1]==="("?(s++,n+=2):e[n]===")"&&e[n+1]===")"?(s--,s>0&&(n+=2)):n++;let a=e.slice(i,n),{expr:o}=Le(t,a,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}if(e.slice(n,n+2)==="$("&&e[n+2]!=="("){n+=2;let s=1,i=n;for(;n<e.length&&s>0;)e[n]==="("?s++:e[n]===")"&&s--,s>0&&n++;let a=e.slice(i,n);return n++,{expr:{type:"ArithCommandSubst",command:a},pos:n}}if(e[n]==="`"){n++;let s=n;for(;n<e.length&&e[n]!=="`";)n++;let i=e.slice(s,n);return e[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:i},pos:n}}if(e[n]==="("){n++;let{expr:s,pos:i}=Le(t,e,n);return n=ee(e,i),e[n]===")"&&n++,{expr:{type:"ArithGroup",expression:s},pos:n}}if(/[0-9]/.test(e[n])){let s="",i=!1;for(;n<e.length;){let o=e[n];if(i)if(/[0-9a-zA-Z@_]/.test(o))s+=o,n++;else break;else if(o==="#")i=!0,s+=o,n++;else if(/[0-9a-fA-FxX]/.test(o))s+=o,n++;else break}if(e[n]==="."&&/[0-9]/.test(e[n+1]))throw new ne(`${s}.${e[n+1]}...: syntax error: invalid arithmetic operator`);if(e[n]==="["){let o=e.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:o},pos:e.length}}return{expr:{type:"ArithNumber",value:mt(s)},pos:n}}if(e[n]==="$"&&e[n+1]==="{"){let s=n+2,i=1,a=s;for(;a<e.length&&i>0;)e[a]==="{"?i++:e[a]==="}"&&i--,i>0&&a++;let o=e.slice(s,a),c=a+1;if(e[c]==="#"){let l=c+1;for(;l<e.length&&/[0-9a-zA-Z@_]/.test(e[l]);)l++;let u=e.slice(c+1,l);return{expr:{type:"ArithDynamicBase",baseExpr:o,value:u},pos:l}}if(/[0-9]/.test(e[c])||e[c]==="x"||e[c]==="X"){let l=c;if(e[c]==="x"||e[c]==="X")for(l++;l<e.length&&/[0-9a-fA-F]/.test(e[l]);)l++;else for(;l<e.length&&/[0-9]/.test(e[l]);)l++;let u=e.slice(c,l);return{expr:{type:"ArithDynamicNumber",prefix:o,suffix:u},pos:l}}return n=c,{expr:{type:"ArithBracedExpansion",content:o},pos:n}}if(e[n]==="$"&&n+1<e.length&&/[0-9]/.test(e[n+1])){n++;let s="";for(;n<e.length&&/[0-9]/.test(e[n]);)s+=e[n],n++;return{expr:{type:"ArithVariable",name:s},pos:n}}if(e[n]==="$"&&n+1<e.length&&/[a-zA-Z_]/.test(e[n+1])&&n++,/[a-zA-Z_]/.test(e[n])){let s="";for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)s+=e[n],n++;if(e[n]==="["){n++;let a;if(e[n]==="'"||e[n]==='"'){let l=e[n];for(n++,a="";n<e.length&&e[n]!==l;)a+=e[n],n++;e[n]===l&&n++,n=ee(e,n),e[n]==="]"&&n++}let o;if(a===void 0){let{expr:l,pos:u}=Le(t,e,n);o=l,n=u,e[n]==="]"&&n++}if(n=ee(e,n),e[n]==="["&&o)return{expr:{type:"ArithDoubleSubscript",array:s,index:o},pos:n};let c=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let l of c)if(e.slice(n,n+l.length)===l&&e.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:u,pos:f}=ir(t,e,n);return{expr:{type:"ArithAssignment",operator:l,variable:s,subscript:o,stringKey:a,value:u},pos:f}}return{expr:{type:"ArithArrayElement",array:s,index:o,stringKey:a},pos:n}}n=ee(e,n);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let a of i)if(e.slice(n,n+a.length)===a&&e.slice(n,n+a.length+1)!=="=="){n+=a.length;let{expr:o,pos:c}=ir(t,e,n);return{expr:{type:"ArithAssignment",operator:a,variable:s,value:o},pos:c}}return{expr:{type:"ArithVariable",name:s},pos:n}}return{expr:{type:"ArithNumber",value:0},pos:n}}function mt(t){if(t.includes("#")){let[e,r]=t.split("#"),n=Number.parseInt(e,10);if(n<2||n>64)return Number.NaN;if(n<=36)return Number.parseInt(r,n);let s=0;for(let i of r){let a;if(i>="0"&&i<="9")a=i.charCodeAt(0)-48;else if(i>="a"&&i<="z")a=i.charCodeAt(0)-97+10;else if(i>="A"&&i<="Z")a=i.charCodeAt(0)-65+36;else if(i==="@")a=62;else if(i==="_")a=63;else return Number.NaN;if(a>=n)return Number.NaN;s=s*n+a}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function ee(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
438
|
-
`){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var
|
|
471
|
+
`,exitCode:1};let s=n.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:a}=await Im(n,e),o=Rm(n,a),l=await e.fetch(s,{method:n.method,headers:Object.keys(o).length>0?o:void 0,body:i,followRedirects:n.followRedirects,timeoutMs:n.timeoutMs});if(await $m(n,l.headers,e),n.failSilently&&l.status>=400)return{stdout:"",stderr:n.showError||!n.silent?`curl: (22) The requested URL returned error: ${l.status}
|
|
472
|
+
`:"",exitCode:22};let c=Om(n,l,s);if(n.outputFile||n.useRemoteName){let u=n.outputFile||oc(s),f=e.fs.resolvePath(e.cwd,u);await e.fs.writeFile(f,n.headOnly?"":l.body),n.verbose||(c=""),n.writeOut&&(c=gs(n.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:c,stderr:"",exitCode:0}}catch(i){let a=te(i),o=1;return a.includes("Network access denied")?o=7:a.includes("HTTP method")&&a.includes("not allowed")?o=3:a.includes("Redirect target not in allow-list")||a.includes("Too many redirects")?o=47:a.includes("aborted")&&(o=28),{stdout:"",stderr:!n.silent||n.showError?`curl: (${o}) ${a}
|
|
473
|
+
`:"",exitCode:o}}}}});import{tool as j0,zodSchema as G0}from"ai";import{z as Fu}from"zod";var fc=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(pi(),hi))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(gi(),mi))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>(Ei(),wi))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(Ai(),Ci))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(vi(),ki))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(Ii(),Ni))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>($i(),Ri))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>(Pi(),Oi))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(Ti(),Fi))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>(Li(),Di))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Bi(),_i))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(Ui(),Wi))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Hi(),zi))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(Vi(),qi))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(Qi(),Zi))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(Ji(),Ki))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(ta(),ea))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(br(),Er))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(br(),Er))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(br(),Er))).egrepCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(da(),fa))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(Da(),Ta))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(Ga(),ja))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(Va(),qa))).uniqCommand},{name:"comm",load:async()=>(await Promise.resolve().then(()=>(Qa(),Za))).commCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(Ka(),Xa))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(eo(),Ya))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(no(),ro))).trCommand},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(io(),so))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(fo(),uo))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(po(),ho))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(go(),mo))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(wo(),yo))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(So(),bo))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Hn(),zn))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Hn(),zn))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(Gn(),jn))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(Gn(),jn))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(ko(),Ao))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>(No(),vo))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(Vn(),qn))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(Vn(),qn))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(Ro(),Io))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(Qn(),Zn))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(Qn(),Zn))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(Po(),Oo))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(Do(),To))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(_o(),Mo))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(Wo(),Bo))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(zo(),Uo))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>(jo(),Ho))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(qo(),Go))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(Zo(),Vo))).exprCommand},{name:"md5sum",load:async()=>(await Promise.resolve().then(()=>(Ko(),Xo))).md5sumCommand},{name:"sha1sum",load:async()=>(await Promise.resolve().then(()=>(Yo(),Jo))).sha1sumCommand},{name:"sha256sum",load:async()=>(await Promise.resolve().then(()=>(tl(),el))).sha256sumCommand},{name:"file",load:async()=>(await Promise.resolve().then(()=>(Ql(),Zl))).fileCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(Kl(),Xl))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(Yl(),Jl))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(tc(),ec))).whichCommand}],Fm=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(uc(),cc))).curlCommand}],dc=new Map;function hc(t){return{name:t.name,async execute(e,r){let n=dc.get(t.name);return n||(n=await t.load(),dc.set(t.name,n)),n.execute(e,r)}}}function pc(t){return(t?fc.filter(r=>t.includes(r.name)):fc).map(hc)}function mc(){return Fm.map(hc)}function gc(t){return"load"in t&&typeof t.load=="function"}function xc(t){let e=null;return{name:t.name,async execute(r,n){return e||(e=await t.load()),e.execute(r,n)}}}var Tm=new TextEncoder,Dm=new TextDecoder;function xs(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),r=>r.charCodeAt(0));case"hex":{let r=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2)r[n/2]=parseInt(t.slice(n,n+2),16);return r}case"binary":case"latin1":return Uint8Array.from(t,r=>r.charCodeAt(0));default:return Tm.encode(t)}}function yc(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(r=>r.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Dm.decode(t)}}function Hr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var jr=new TextEncoder;function Lm(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var mt=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[r,n]of Object.entries(e))Lm(n)?this.writeFileSync(r,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(r,n)}normalizePath(e){if(!e||e==="/")return"/";let r=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;r.startsWith("/")||(r=`/${r}`);let n=r.split("/").filter(i=>i&&i!=="."),s=[];for(let i of n)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}dirname(e){let r=this.normalizePath(e);if(r==="/")return"/";let n=r.lastIndexOf("/");return n===0?"/":r.slice(0,n)}ensureParentDirs(e){let r=this.dirname(e);r!=="/"&&(this.data.has(r)||(this.ensureParentDirs(r),this.data.set(r,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,r,n,s){let i=this.normalizePath(e);this.ensureParentDirs(i);let a=Hr(n),o=xs(r,a);this.data.set(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,r){let n=await this.readFileBuffer(e),s=Hr(r);return yc(n,s)}async readFileBuffer(e){let r=this.normalizePath(e),n=this.data.get(r),s=r;if(!n)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let i=new Set;for(;n&&n.type==="symlink";){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);i.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return n.content instanceof Uint8Array?n.content:jr.encode(n.content)}async writeFile(e,r,n){this.writeFileSync(e,r,n)}async appendFile(e,r,n){let s=this.normalizePath(e),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let a=Hr(n),o=xs(r,a);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:jr.encode(i.content),c=new Uint8Array(l.length+o.length);c.set(l),c.set(o,l.length),this.data.set(s,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(e,r,n)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(n.type==="symlink"){let i=this.resolveSymlink(r,n.target),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);n=a}let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=jr.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:s,mtime:n.mtime||new Date}}async lstat(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=jr.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:s,mtime:n.mtime||new Date}}resolveSymlink(e,r){if(r.startsWith("/"))return this.normalizePath(r);let n=this.dirname(e);return this.normalizePath(n==="/"?`/${r}`:`${n}/${r}`)}async mkdir(e,r){this.mkdirSync(e,r)}mkdirSync(e,r){let n=this.normalizePath(e);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!r?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(n);if(s!=="/"&&!this.data.has(s))if(r?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=r==="/"?"/":`${r}/`,i=[];for(let a of this.data.keys())if(a!==r&&a.startsWith(s)){let l=a.slice(s.length).split("/")[0];l&&!i.includes(l)&&i.push(l)}return i.sort()}async rm(e,r){let n=this.normalizePath(e),s=this.data.get(n);if(!s){if(r?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!r?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,r)}}}this.data.delete(n)}async cp(e,r,n){let s=this.normalizePath(e),i=this.normalizePath(r),a=this.data.get(s);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(s);for(let l of o){let c=s==="/"?`/${l}`:`${s}/${l}`,u=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,u,n)}}}async mv(e,r){await this.cp(e,r,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,r){if(r.startsWith("/"))return this.normalizePath(r);let n=e==="/"?`/${r}`:`${e}/${r}`;return this.normalizePath(n)}async chmod(e,r){let n=this.normalizePath(e),s=this.data.get(n);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=r}async symlink(e,r){let n=this.normalizePath(r);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${r}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,r){let n=this.normalizePath(e),s=this.normalizePath(r),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${r}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(e){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return n.target}};J();J();function le(t,e){return{type:"ArithmeticExpression",expression:Ve(t,e,0).expr}}function Ve(t,e,r){return Mm(t,e,r)}function Mm(t,e,r){let{expr:n,pos:s}=qr(t,e,r);for(s=re(e,s);e[s]===",";){s++;let{expr:i,pos:a}=qr(t,e,s);n={type:"ArithBinary",operator:",",left:n,right:i},s=re(e,a)}return{expr:n,pos:s}}function qr(t,e,r){let{expr:n,pos:s}=_m(t,e,r);if(s=re(e,s),e[s]==="?"){s++;let{expr:i,pos:a}=Ve(t,e,s);if(s=re(e,a),e[s]===":"){s++;let{expr:o,pos:l}=Ve(t,e,s);return{expr:{type:"ArithTernary",condition:n,consequent:i,alternate:o},pos:l}}}return{expr:n,pos:s}}function _m(t,e,r){let{expr:n,pos:s}=wc(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:i,pos:a}=wc(t,e,s);n={type:"ArithBinary",operator:"||",left:n,right:i},s=a}return{expr:n,pos:s}}function wc(t,e,r){let{expr:n,pos:s}=Ec(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:i,pos:a}=Ec(t,e,s);n={type:"ArithBinary",operator:"&&",left:n,right:i},s=a}return{expr:n,pos:s}}function Ec(t,e,r){let{expr:n,pos:s}=bc(t,e,r);for(;s=re(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:i,pos:a}=bc(t,e,s);n={type:"ArithBinary",operator:"|",left:n,right:i},s=a}return{expr:n,pos:s}}function bc(t,e,r){let{expr:n,pos:s}=Sc(t,e,r);for(;s=re(e,s),e[s]==="^";){s++;let{expr:i,pos:a}=Sc(t,e,s);n={type:"ArithBinary",operator:"^",left:n,right:i},s=a}return{expr:n,pos:s}}function Sc(t,e,r){let{expr:n,pos:s}=Cc(t,e,r);for(;s=re(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:i,pos:a}=Cc(t,e,s);n={type:"ArithBinary",operator:"&",left:n,right:i},s=a}return{expr:n,pos:s}}function Cc(t,e,r){let{expr:n,pos:s}=Ac(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=Ac(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function Ac(t,e,r){let{expr:n,pos:s}=ys(t,e,r);for(;;)if(s=re(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=ys(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else if(e[s]==="<"||e[s]===">"){let i=e[s];s++;let{expr:a,pos:o}=ys(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else break;return{expr:n,pos:s}}function ys(t,e,r){let{expr:n,pos:s}=kc(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let i=e.slice(s,s+2);s+=2;let{expr:a,pos:o}=kc(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function kc(t,e,r){let{expr:n,pos:s}=vc(t,e,r);for(;s=re(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let i=e[s];s++;let{expr:a,pos:o}=vc(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}return{expr:n,pos:s}}function vc(t,e,r){let{expr:n,pos:s}=Gr(t,e,r);for(;;)if(s=re(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:i,pos:a}=Gr(t,e,s);n={type:"ArithBinary",operator:"*",left:n,right:i},s=a}else if(e[s]==="/"||e[s]==="%"){let i=e[s];s++;let{expr:a,pos:o}=Gr(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:a},s=o}else break;return{expr:n,pos:s}}function Gr(t,e,r){let{expr:n,pos:s}=ws(t,e,r),i=re(e,s);if(e.slice(i,i+2)==="**"){i+=2;let{expr:a,pos:o}=Gr(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:n,right:a},pos:o}}return{expr:n,pos:s}}function ws(t,e,r){let n=re(e,r);if(e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let s=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=ws(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}if(e[n]==="+"||e[n]==="-"||e[n]==="!"||e[n]==="~"){let s=e[n];n++;let{expr:i,pos:a}=ws(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return Wm(t,e,n)}function Bm(t,e){let r=t[e];return r==="$"||r==="`"}function Wm(t,e,r){let{expr:n,pos:s}=Nc(t,e,r),i=[n];for(;Bm(e,s);){let{expr:a,pos:o}=Nc(t,e,s);i.push(a),s=o}if(i.length>1&&(n={type:"ArithConcat",parts:i}),s=re(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let a=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:n,prefix:!1},pos:s}}return{expr:n,pos:s}}function Nc(t,e,r){let n=re(e,r);if(e.slice(n,n+3)==="$(("){n+=3;let s=1,i=n;for(;n<e.length-1&&s>0;)e[n]==="("&&e[n+1]==="("?(s++,n+=2):e[n]===")"&&e[n+1]===")"?(s--,s>0&&(n+=2)):n++;let a=e.slice(i,n),{expr:o}=Ve(t,a,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}if(e.slice(n,n+2)==="$("&&e[n+2]!=="("){n+=2;let s=1,i=n;for(;n<e.length&&s>0;)e[n]==="("?s++:e[n]===")"&&s--,s>0&&n++;let a=e.slice(i,n);return n++,{expr:{type:"ArithCommandSubst",command:a},pos:n}}if(e[n]==="`"){n++;let s=n;for(;n<e.length&&e[n]!=="`";)n++;let i=e.slice(s,n);return e[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:i},pos:n}}if(e[n]==="("){n++;let{expr:s,pos:i}=Ve(t,e,n);return n=re(e,i),e[n]===")"&&n++,{expr:{type:"ArithGroup",expression:s},pos:n}}if(/[0-9]/.test(e[n])){let s="",i=!1;for(;n<e.length;){let o=e[n];if(i)if(/[0-9a-zA-Z@_]/.test(o))s+=o,n++;else break;else if(o==="#")i=!0,s+=o,n++;else if(/[0-9a-fA-FxX]/.test(o))s+=o,n++;else break}if(e[n]==="."&&/[0-9]/.test(e[n+1]))throw new ae(`${s}.${e[n+1]}...: syntax error: invalid arithmetic operator`);if(e[n]==="["){let o=e.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:o},pos:e.length}}return{expr:{type:"ArithNumber",value:Mt(s)},pos:n}}if(e[n]==="$"&&e[n+1]==="{"){let s=n+2,i=1,a=s;for(;a<e.length&&i>0;)e[a]==="{"?i++:e[a]==="}"&&i--,i>0&&a++;let o=e.slice(s,a),l=a+1;if(e[l]==="#"){let c=l+1;for(;c<e.length&&/[0-9a-zA-Z@_]/.test(e[c]);)c++;let u=e.slice(l+1,c);return{expr:{type:"ArithDynamicBase",baseExpr:o,value:u},pos:c}}if(/[0-9]/.test(e[l])||e[l]==="x"||e[l]==="X"){let c=l;if(e[l]==="x"||e[l]==="X")for(c++;c<e.length&&/[0-9a-fA-F]/.test(e[c]);)c++;else for(;c<e.length&&/[0-9]/.test(e[c]);)c++;let u=e.slice(l,c);return{expr:{type:"ArithDynamicNumber",prefix:o,suffix:u},pos:c}}return n=l,{expr:{type:"ArithBracedExpansion",content:o},pos:n}}if(e[n]==="$"&&n+1<e.length&&/[0-9]/.test(e[n+1])){n++;let s="";for(;n<e.length&&/[0-9]/.test(e[n]);)s+=e[n],n++;return{expr:{type:"ArithVariable",name:s},pos:n}}if(e[n]==="$"&&n+1<e.length&&/[a-zA-Z_]/.test(e[n+1])&&n++,/[a-zA-Z_]/.test(e[n])){let s="";for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)s+=e[n],n++;if(e[n]==="["){n++;let a;if(e[n]==="'"||e[n]==='"'){let c=e[n];for(n++,a="";n<e.length&&e[n]!==c;)a+=e[n],n++;e[n]===c&&n++,n=re(e,n),e[n]==="]"&&n++}let o;if(a===void 0){let{expr:c,pos:u}=Ve(t,e,n);o=c,n=u,e[n]==="]"&&n++}if(n=re(e,n),e[n]==="["&&o)return{expr:{type:"ArithDoubleSubscript",array:s,index:o},pos:n};let l=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let c of l)if(e.slice(n,n+c.length)===c&&e.slice(n,n+c.length+1)!=="=="){n+=c.length;let{expr:u,pos:f}=qr(t,e,n);return{expr:{type:"ArithAssignment",operator:c,variable:s,subscript:o,stringKey:a,value:u},pos:f}}return{expr:{type:"ArithArrayElement",array:s,index:o,stringKey:a},pos:n}}n=re(e,n);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let a of i)if(e.slice(n,n+a.length)===a&&e.slice(n,n+a.length+1)!=="=="){n+=a.length;let{expr:o,pos:l}=qr(t,e,n);return{expr:{type:"ArithAssignment",operator:a,variable:s,value:o},pos:l}}return{expr:{type:"ArithVariable",name:s},pos:n}}return{expr:{type:"ArithNumber",value:0},pos:n}}function Mt(t){if(t.includes("#")){let[e,r]=t.split("#"),n=Number.parseInt(e,10);if(n<2||n>64)return Number.NaN;if(n<=36)return Number.parseInt(r,n);let s=0;for(let i of r){let a;if(i>="0"&&i<="9")a=i.charCodeAt(0)-48;else if(i>="a"&&i<="z")a=i.charCodeAt(0)-97+10;else if(i>="A"&&i<="Z")a=i.charCodeAt(0)-65+36;else if(i==="@")a=62;else if(i==="_")a=63;else return Number.NaN;if(a>=n)return Number.NaN;s=s*n+a}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function re(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
474
|
+
`){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var N={script(t){return{type:"Script",statements:t}},statement(t,e=[],r=!1){return{type:"Statement",pipelines:t,operators:e,background:r}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],r=[],n=[]){return{type:"SimpleCommand",name:t,args:e,assignments:r,redirections:n}},word(t){return{type:"Word",parts:t}},literal(t){return{type:"Literal",value:t}},singleQuoted(t){return{type:"SingleQuoted",value:t}},doubleQuoted(t){return{type:"DoubleQuoted",parts:t}},escaped(t){return{type:"Escaped",value:t}},parameterExpansion(t,e=null){return{type:"ParameterExpansion",parameter:t,operation:e}},commandSubstitution(t,e=!1){return{type:"CommandSubstitution",body:t,legacy:e}},arithmeticExpansion(t){return{type:"ArithmeticExpansion",expression:t}},assignment(t,e,r=!1,n=null){return{type:"Assignment",name:t,value:e,append:r,array:n}},redirection(t,e,r=null){return{type:"Redirection",fd:r,operator:t,target:e}},hereDoc(t,e,r=!1,n=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:r,quoted:n}},ifNode(t,e=null,r=[]){return{type:"If",clauses:t,elseBody:e,redirections:r}},forNode(t,e,r,n=[]){return{type:"For",variable:t,words:e,body:r,redirections:n}},whileNode(t,e,r=[]){return{type:"While",condition:t,body:e,redirections:r}},untilNode(t,e,r=[]){return{type:"Until",condition:t,body:e,redirections:r}},caseNode(t,e,r=[]){return{type:"Case",word:t,items:e,redirections:r}},caseItem(t,e,r=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:r}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,r=[]){return{type:"FunctionDef",name:t,body:e,redirections:r}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var m;(function(t){t.EOF="EOF",t.NEWLINE="NEWLINE",t.SEMICOLON="SEMICOLON",t.AMP="AMP",t.PIPE="PIPE",t.PIPE_AMP="PIPE_AMP",t.AND_AND="AND_AND",t.OR_OR="OR_OR",t.BANG="BANG",t.LESS="LESS",t.GREAT="GREAT",t.DLESS="DLESS",t.DGREAT="DGREAT",t.LESSAND="LESSAND",t.GREATAND="GREATAND",t.LESSGREAT="LESSGREAT",t.DLESSDASH="DLESSDASH",t.CLOBBER="CLOBBER",t.TLESS="TLESS",t.AND_GREAT="AND_GREAT",t.AND_DGREAT="AND_DGREAT",t.LPAREN="LPAREN",t.RPAREN="RPAREN",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.DSEMI="DSEMI",t.SEMI_AND="SEMI_AND",t.SEMI_SEMI_AND="SEMI_SEMI_AND",t.DBRACK_START="DBRACK_START",t.DBRACK_END="DBRACK_END",t.DPAREN_START="DPAREN_START",t.DPAREN_END="DPAREN_END",t.IF="IF",t.THEN="THEN",t.ELSE="ELSE",t.ELIF="ELIF",t.FI="FI",t.FOR="FOR",t.WHILE="WHILE",t.UNTIL="UNTIL",t.DO="DO",t.DONE="DONE",t.CASE="CASE",t.ESAC="ESAC",t.IN="IN",t.FUNCTION="FUNCTION",t.SELECT="SELECT",t.TIME="TIME",t.COPROC="COPROC",t.WORD="WORD",t.NAME="NAME",t.NUMBER="NUMBER",t.ASSIGNMENT_WORD="ASSIGNMENT_WORD",t.COMMENT="COMMENT",t.HEREDOC_CONTENT="HEREDOC_CONTENT"})(m||(m={}));var Vr={if:m.IF,then:m.THEN,else:m.ELSE,elif:m.ELIF,fi:m.FI,for:m.FOR,while:m.WHILE,until:m.UNTIL,do:m.DO,done:m.DONE,case:m.CASE,esac:m.ESAC,in:m.IN,function:m.FUNCTION,select:m.SELECT,time:m.TIME,coproc:m.COPROC};function Rc(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let r=t.slice(e[0].length);if(r===""||r==="+")return!0;if(r[0]==="["){let n=0,s=0;for(;s<r.length;s++)if(r[s]==="[")n++;else if(r[s]==="]"&&(n--,n===0))break;if(n!==0||s>=r.length)return!1;let i=r.slice(s+1);return i===""||i==="+"}return!1}var Um=[[";",";","&",m.SEMI_SEMI_AND],["<","<","<",m.TLESS],["&",">",">",m.AND_DGREAT]],zm=[["[","[",m.DBRACK_START],["]","]",m.DBRACK_END],["(","(",m.DPAREN_START],[")",")",m.DPAREN_END],["&","&",m.AND_AND],["|","|",m.OR_OR],[";",";",m.DSEMI],[";","&",m.SEMI_AND],["|","&",m.PIPE_AMP],[">",">",m.DGREAT],["<","&",m.LESSAND],[">","&",m.GREATAND],["<",">",m.LESSGREAT],[">","|",m.CLOBBER],["&",">",m.AND_GREAT]],Hm={"|":m.PIPE,"&":m.AMP,";":m.SEMICOLON,"(":m.LPAREN,")":m.RPAREN,"<":m.LESS,">":m.GREAT};function jm(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Zr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let r=this.input.length,n=this.tokens,s=this.pendingHeredocs;for(;this.pos<r&&(this.skipWhitespace(),!(this.pos>=r));){if(s.length>0&&n.length>0&&n[n.length-1].type===m.NEWLINE){this.readHeredocContent();continue}let i=this.nextToken();i&&n.push(i)}return n.push({type:m.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),n}skipWhitespace(){let e=this.input,r=e.length,n=this.pos,s=this.column,i=this.line;for(;n<r;){let a=e[n];if(a===" "||a===" ")n++,s++;else if(a==="\\"&&e[n+1]===`
|
|
439
475
|
`)n+=2,i++,s=1;else break}this.pos=n,this.column=s,this.line=i}nextToken(){let e=this.input,r=this.pos,n=this.line,s=this.column,i=e[r],a=e[r+1],o=e[r+2];if(i==="#")return this.readComment(r,n,s);if(i===`
|
|
440
476
|
`)return this.pos=r+1,this.line++,this.column=1,{type:m.NEWLINE,value:`
|
|
441
|
-
`,start:r,end:r+1,line:n,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=r+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(m.DLESSDASH,"<<-",r,n,s);for(let[
|
|
477
|
+
`,start:r,end:r+1,line:n,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=r+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(m.DLESSDASH,"<<-",r,n,s);for(let[c,u,f,d]of Um)if(i===c&&a===u&&o===f)return this.pos=r+3,this.column=s+3,this.makeToken(d,c+u+f,r,n,s);if(i==="<"&&a==="<")return this.pos=r+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(m.DLESS,"<<",r,n,s);for(let[c,u,f]of zm)if(i===c&&a===u)return this.pos=r+2,this.column=s+2,this.makeToken(f,c+u,r,n,s);let l=Hm[i];return l?(this.pos=r+1,this.column=s+1,this.makeToken(l,i,r,n,s)):i==="{"?a==="}"?(this.pos=r+2,this.column=s+2,{type:m.WORD,value:"{}",start:r,end:r+2,line:n,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(r)!==null?this.readWordWithBraceExpansion(r,n,s):this.scanLiteralBraceWord(r)!==null?this.readWordWithBraceExpansion(r,n,s):a!==void 0&&a!==" "&&a!==" "&&a!==`
|
|
442
478
|
`?this.readWord(r,n,s):(this.pos=r+1,this.column=s+1,this.makeToken(m.LBRACE,"{",r,n,s)):i==="}"?this.isWordCharFollowing(r+1)?this.readWord(r,n,s):(this.pos=r+1,this.column=s+1,this.makeToken(m.RBRACE,"}",r,n,s)):i==="!"?a==="="?(this.pos=r+2,this.column=s+2,this.makeToken(m.WORD,"!=",r,n,s)):(this.pos=r+1,this.column=s+1,this.makeToken(m.BANG,"!",r,n,s)):this.readWord(r,n,s)}makeToken(e,r,n,s,i){return{type:e,value:r,start:n,end:this.pos,line:s,column:i}}readComment(e,r,n){let s=this.input,i=s.length,a=this.pos;for(;a<i&&s[a]!==`
|
|
443
|
-
`;)a++;let o=s.slice(e,a);return this.pos=a,this.column=n+(a-e),{type:m.COMMENT,value:o,start:e,end:a,line:r,column:n}}readWord(e,r,n){let s=this.input,i=s.length,a=this.pos,o=a;for(;a<i;){let
|
|
444
|
-
`||
|
|
445
|
-
`||
|
|
446
|
-
`||
|
|
447
|
-
`){a+=2,l
|
|
448
|
-
`){
|
|
449
|
-
`;)a++,
|
|
450
|
-
`&&(l
|
|
451
|
-
`&&(l
|
|
452
|
-
`&&(l
|
|
453
|
-
`&&(l
|
|
454
|
-
`?(l
|
|
479
|
+
`;)a++;let o=s.slice(e,a);return this.pos=a,this.column=n+(a-e),{type:m.COMMENT,value:o,start:e,end:a,line:r,column:n}}readWord(e,r,n){let s=this.input,i=s.length,a=this.pos,o=a;for(;a<i;){let x=s[a];if(x===" "||x===" "||x===`
|
|
480
|
+
`||x===";"||x==="&"||x==="|"||x==="("||x===")"||x==="<"||x===">"||x==="'"||x==='"'||x==="\\"||x==="$"||x==="`"||x==="{"||x==="}"||x==="~"||x==="*"||x==="?"||x==="[")break;a++}if(a>o){let x=s[a];if(a>=i||x===" "||x===" "||x===`
|
|
481
|
+
`||x===";"||x==="&"||x==="|"||x==="("||x===")"||x==="<"||x===">"){let y=s.slice(o,a);if(this.pos=a,this.column=n+(a-o),Vr[y])return{type:Vr[y],value:y,start:e,end:a,line:r,column:n};let E=y.indexOf("=");return E>0&&Rc(y.slice(0,E))?{type:m.ASSIGNMENT_WORD,value:y,start:e,end:a,line:r,column:n}:/^[0-9]+$/.test(y)?{type:m.NUMBER,value:y,start:e,end:a,line:r,column:n}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(y)?{type:m.NAME,value:y,start:e,end:a,line:r,column:n,quoted:!1,singleQuoted:!1}:{type:m.WORD,value:y,start:e,end:a,line:r,column:n,quoted:!1,singleQuoted:!1}}}a=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,h=!1,p=!1,w=s[a]==='"'||s[a]==="'";for(;a<i;){let x=s[a];if(!h&&!p&&(x===" "||x===" "||x===`
|
|
482
|
+
`||x===";"||x==="&"||x==="|"||x==="("||x===")"||x==="<"||x===">"))break;if(x==="$"&&a+1<i&&s[a+1]==="'"&&!h&&!p){for(u+="$'",a+=2,l+=2;a<i&&s[a]!=="'";)s[a]==="\\"&&a+1<i?(u+=s[a]+s[a+1],a+=2,l+=2):(u+=s[a],a++,l++);a<i&&(u+="'",a++,l++);continue}if(x==="$"&&a+1<i&&s[a+1]==='"'&&!h&&!p){a++,l++,p=!0,f=!0,u===""&&(w=!0),a++,l++;continue}if(x==="'"&&!p){h?(h=!1,w||(u+=x)):(h=!0,w?(d=!0,f=!0):u+=x),a++,l++;continue}if(x==='"'&&!h){p?(p=!1,w||(u+=x)):(p=!0,w?f=!0:u+=x),a++,l++;continue}if(x==="\\"&&!h&&a+1<i){let y=s[a+1];if(y===`
|
|
483
|
+
`){a+=2,c++,l=1;continue}if(p){if(y==='"'||y==="\\"||y==="$"||y==="`"||y===`
|
|
484
|
+
`){y==="$"||y==="`"?u+=x+y:u+=y,a+=2,l+=2;continue}}else{y==='"'||y==="'"?u+=x+y:u+=y,a+=2,l+=2;continue}}if(x==="$"&&a+1<i&&s[a+1]==="("){u+=x,a++,l++,u+=s[a],a++,l++;let y=1,E=!1,b=!1,S=0,A=!1,D="",F=s[a]==="(";for(;y>0&&a<i;){let P=s[a];if(u+=P,E)P==="'"&&(E=!1);else if(b)P==="\\"&&a+1<i?(u+=s[a+1],a++,l++):P==='"'&&(b=!1);else if(P==="'")E=!0,D="";else if(P==='"')b=!0,D="";else if(P==="\\"&&a+1<i)u+=s[a+1],a++,l++,D="";else if(P==="#"&&!F&&(D===""||/\s/.test(s[a-1]||""))){for(;a+1<i&&s[a+1]!==`
|
|
485
|
+
`;)a++,l++,u+=s[a];D=""}else/[a-zA-Z_]/.test(P)?D+=P:(D==="case"?(S++,A=!1):D==="in"&&S>0?A=!0:D==="esac"&&S>0&&(S--,A=!1),D="",P==="("?a>0&&s[a-1]==="$"?y++:A||y++:P===")"?A?A=!1:y--:P===";"&&S>0&&a+1<i&&s[a+1]===";"&&(A=!0));P===`
|
|
486
|
+
`&&(c++,l=0,D=""),a++,l++}continue}if(x==="$"&&a+1<i&&s[a+1]==="["){u+=x,a++,l++,u+=s[a],a++,l++;let y=1;for(;y>0&&a<i;){let E=s[a];u+=E,E==="["?y++:E==="]"?y--:E===`
|
|
487
|
+
`&&(c++,l=0),a++,l++}continue}if(x==="$"&&a+1<i&&s[a+1]==="{"){u+=x,a++,l++,u+=s[a],a++,l++;let y=1;for(;y>0&&a<i;){let E=s[a];u+=E,E==="{"?y++:E==="}"?y--:E===`
|
|
488
|
+
`&&(c++,l=0),a++,l++}continue}if(x==="$"&&a+1<i){let y=s[a+1];if(y==="#"||y==="?"||y==="$"||y==="!"||y==="@"||y==="*"||y==="-"||y>="0"&&y<="9"){u+=x+y,a+=2,l+=2;continue}}if(x==="`"){for(u+=x,a++,l++;a<i&&s[a]!=="`";){let y=s[a];u+=y,y==="\\"&&a+1<i&&(u+=s[a+1],a++,l++),y===`
|
|
489
|
+
`&&(c++,l=0),a++,l++}a<i&&(u+=s[a],a++,l++);continue}u+=x,a++,x===`
|
|
490
|
+
`?(c++,l=1):l++}if(this.pos=a,this.column=l,this.line=c,u==="")return{type:m.WORD,value:"",start:e,end:a,line:r,column:n,quoted:f,singleQuoted:d};if(!f&&Vr[u])return{type:Vr[u],value:u,start:e,end:a,line:r,column:n};if(!w){let x=u.indexOf("=");if(x>0&&Rc(u.slice(0,x)))return{type:m.ASSIGNMENT_WORD,value:u,start:e,end:a,line:r,column:n,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:m.NUMBER,value:u,start:e,end:a,line:r,column:n}:jm(u)?{type:m.NAME,value:u,start:e,end:a,line:r,column:n,quoted:f,singleQuoted:d}:{type:m.WORD,value:u,start:e,end:a,line:r,column:n,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let e=this.pendingHeredocs.shift();if(!e)break;let r=this.pos,n=this.line,s=this.column,i="";for(;this.pos<this.input.length;){let a=this.pos,o="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
455
491
|
`;)o+=this.input[this.pos],this.pos++,this.column++;if((e.stripTabs?o.replace(/^\t+/,""):o)===e.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
|
|
456
492
|
`&&(this.pos++,this.line++,this.column=1);break}i+=o,this.pos<this.input.length&&this.input[this.pos]===`
|
|
457
493
|
`&&(i+=`
|
|
458
494
|
`,this.pos++,this.line++,this.column=1)}this.tokens.push({type:m.HEREDOC_CONTENT,value:i,start:r,end:this.pos,line:n,column:s})}}addPendingHeredoc(e,r,n){this.pendingHeredocs.push({delimiter:e,stripTabs:r,quoted:n})}registerHeredocFromLookahead(e){let r=this.pos,n=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let s="",i=!1,a=this.input[this.pos];if(a==="'"||a==='"'){i=!0;let o=a;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==o;)s+=this.input[this.pos],this.pos++,this.column++}else for(;this.pos<this.input.length&&!/[\s;<>&|()]/.test(this.input[this.pos]);)s+=this.input[this.pos],this.pos++,this.column++;this.pos=r,this.column=n,s&&this.pendingHeredocs.push({delimiter:s,stripTabs:e,quoted:i})}isWordCharFollowing(e){if(e>=this.input.length)return!1;let r=this.input[e];return!(r===" "||r===" "||r===`
|
|
459
|
-
`||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(e,r,n){let s=this.input,i=s.length,a=e,o=n;for(;a<i;){let
|
|
460
|
-
`||
|
|
461
|
-
`||
|
|
462
|
-
`||a===";"||a==="&"||a==="|")return null;s++}}return null}};var
|
|
463
|
-
`,s+=2;break;case"t":n+=" ",s+=2;break;case"r":n+="\r",s+=2;break;case"\\":n+="\\",s+=2;break;case"'":n+="'",s+=2;break;case'"':n+='"',s+=2;break;case"a":n+="\x07",s+=2;break;case"b":n+="\b",s+=2;break;case"e":case"E":n+="\x1B",s+=2;break;case"f":n+="\f",s+=2;break;case"v":n+="\v",s+=2;break;case"x":{let o=e.slice(s+2,s+4),c=parseInt(o,16);Number.isNaN(c)?(n+="\\x",s+=2):(n+=String.fromCharCode(c),s+=4);break}case"u":{let o=e.slice(s+2,s+6),c=parseInt(o,16);Number.isNaN(c)?(n+="\\u",s+=2):(n+=String.fromCharCode(c),s+=6);break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let o="",c=s+1;for(;c<e.length&&c<s+4&&/[0-7]/.test(e[c]);)o+=e[c],c++;let l=parseInt(o,8);n+=String.fromCharCode(l),s=c;break}default:n+=i,s++}else n+=i,s++}return s<e.length&&e[s]==="'"&&s++,{part:k.literal(n),endIndex:s}}function gn(t,e){let r=e.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:ie(t,r)}function wo(t){let e=[],r="",n=0;for(let s=0;s<t.length;s++){let i=t[s];i==="{"?(n++,r+=i):i==="}"?(n--,r+=i):i===","&&n===0?(e.push(r),r=""):r+=i}return e.push(r),e}function Ao(t,e,r,n){let s=yn(t,e,r,"{","}");if(s===-1)return null;let i=e.slice(r+1,s),a=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(a)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(a[1],10),end:Number.parseInt(a[2],10),step:a[3]?Number.parseInt(a[3],10):void 0,startStr:a[1],endStr:a[2]}]},endIndex:s+1};let o=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return o?{part:{type:"BraceExpansion",items:[{type:"Range",start:o[1],end:o[2],step:o[3]?Number.parseInt(o[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&n?{part:{type:"BraceExpansion",items:wo(i).map(u=>({type:"Word",word:k.word(n(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:wo(i).map(u=>({type:"Word",word:k.word([k.literal(u)])}))},endIndex:s+1}:null}function Co(t,e){let r="";for(let n of e.parts)switch(n.type){case"Literal":case"SingleQuoted":case"Escaped":r+=n.value;break;case"DoubleQuoted":r+='"';for(let s of n.parts)s.type==="Literal"||s.type==="Escaped"?r+=s.value:s.type==="ParameterExpansion"&&(r+=`\${${s.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${n.parameter}}`;break;case"Glob":r+=n.pattern;break;default:r+=n.type}return r}function No(t,e){return{[m.LESS]:"<",[m.GREAT]:">",[m.DGREAT]:">>",[m.LESSAND]:"<&",[m.GREATAND]:">&",[m.LESSGREAT]:"<>",[m.CLOBBER]:">|",[m.TLESS]:"<<<",[m.AND_GREAT]:"&>",[m.AND_DGREAT]:"&>>",[m.DLESS]:"<",[m.DLESSDASH]:"<"}[e]||">"}function lr(t){let e=t.current(),r=e.type;if(r===m.NUMBER){let n=t.peek(1);return e.end!==n.start?!1:go.has(n.type)}return yo.has(r)}function cr(t){let e=null;t.check(m.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let r=t.advance(),n=No(t,r.type);if(r.type===m.DLESS||r.type===m.DLESSDASH)return vd(t,n,e,r.type===m.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return k.redirection(n,s,e)}function vd(t,e,r,n){t.isWord()||t.error("Expected here-document delimiter");let s=t.advance(),i=s.value,a=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let o=k.redirection(n?"<<-":"<<",k.hereDoc(i,k.word([]),n,a),r);return t.addPendingHeredoc(o,i,n,a),o}function ko(t){let e=[],r=null,n=[],s=[];for(;t.check(m.ASSIGNMENT_WORD);)t.checkIterationLimit(),e.push(kd(t));for(;lr(t);)t.checkIterationLimit(),s.push(cr(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(m.RBRACE))&&!t.check(m.PIPE,m.PIPE_AMP);)if(t.checkIterationLimit(),lr(t))s.push(cr(t));else if(t.check(m.RBRACE)){let i=t.advance();n.push(t.parseWordFromString(i.value,!1,!1))}else if(t.isWord())n.push(t.parseWord());else if(t.check(m.ASSIGNMENT_WORD)){let i=t.advance(),a=i.value,o=a.endsWith("="),c=a.endsWith("=(");if((o||c)&&(c||t.check(m.LPAREN))){let l=c?a.slice(0,-2):a.slice(0,-1);c||t.expect(m.LPAREN);let u=wn(t);t.expect(m.RPAREN);let f=u.map(h=>Co(t,h)),d=`${l}=(${f.join(" ")})`;n.push(t.parseWordFromString(d,!1,!1))}else n.push(t.parseWordFromString(a,i.quoted,i.singleQuoted))}else if(t.check(m.LPAREN))t.error("syntax error near unexpected token `('");else break;return k.simpleCommand(r,n,e,s)}function kd(t){let e=t.expect(m.ASSIGNMENT_WORD),r=e.value,n=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);n||t.error(`Invalid assignment: ${r}`);let s=n[0],i,a=s.length;if(r[a]==="["){let f=0,d=a+1;for(;a<r.length;a++)if(r[a]==="[")f++;else if(r[a]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${r}`),i=r.slice(d,a),a++}let o=r[a]==="+";o&&a++,r[a]!=="="&&t.error(`Invalid assignment: ${r}`),a++;let c=r.slice(a);if(c==="("){let f=wn(t);t.expect(m.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return k.assignment(d,null,o,f)}if(c===""&&t.check(m.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let d=wn(t);t.expect(m.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return k.assignment(h,null,o,d)}}let l=c?t.parseWordFromString(c,e.quoted,e.singleQuoted,!0):null,u=i!==void 0?`${s}[${i}]`:s;return k.assignment(u,l,o,null)}function wn(t){let e=[];for(t.skipNewlines();!t.check(m.RPAREN,m.EOF);)t.checkIterationLimit(),t.isWord()?e.push(t.parseWord()):t.advance(),t.skipNewlines();return e}function En(t){t.expect(m.IF);let e=[],r=t.parseCompoundList();t.expect(m.THEN);let n=t.parseCompoundList();if(n.length===0){let a=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${a}'`)}for(e.push({condition:r,body:n});t.check(m.ELIF);){t.advance();let a=t.parseCompoundList();t.expect(m.THEN);let o=t.parseCompoundList();if(o.length===0){let c=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${c}'`)}e.push({condition:a,body:o})}let s=null;t.check(m.ELSE)&&(t.advance(),s=t.parseCompoundList(),s.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(m.FI);let i=t.parseOptionalRedirections();return k.ifNode(e,s,i)}function bn(t){if(t.expect(m.FOR),t.check(m.DPAREN_START))return $d(t);t.isWord()||t.error("Expected variable name in for loop");let r=t.advance().value,n=null;if(t.skipNewlines(),t.check(m.IN))for(t.advance(),n=[];!t.check(m.SEMICOLON,m.NEWLINE,m.DO,m.EOF)&&t.isWord();)n.push(t.parseWord());t.check(m.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(m.DO);let s=t.parseCompoundList();t.expect(m.DONE);let i=t.parseOptionalRedirections();return k.forNode(r,n,s,i)}function $d(t){t.expect(m.DPAREN_START);let e=null,r=null,n=null,s=["","",""],i=0,a=0;for(;!t.check(m.DPAREN_END,m.EOF);){let l=t.advance();if(l.type===m.SEMICOLON&&a===0){if(i++,i>2)break}else l.value==="("&&a++,l.value===")"&&a--,s[i]+=l.value}t.expect(m.DPAREN_END),s[0].trim()&&(e=ie(t,s[0].trim())),s[1].trim()&&(r=ie(t,s[1].trim())),s[2].trim()&&(n=ie(t,s[2].trim())),t.skipNewlines(),t.check(m.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(m.DO);let o=t.parseCompoundList();t.expect(m.DONE);let c=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:r,update:n,body:o,redirections:c}}function Sn(t){t.expect(m.WHILE);let e=t.parseCompoundList();t.expect(m.DO);let r=t.parseCompoundList();r.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(m.DONE);let n=t.parseOptionalRedirections();return k.whileNode(e,r,n)}function xn(t){t.expect(m.UNTIL);let e=t.parseCompoundList();t.expect(m.DO);let r=t.parseCompoundList();r.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(m.DONE);let n=t.parseOptionalRedirections();return k.untilNode(e,r,n)}function An(t){t.expect(m.CASE),t.isWord()||t.error("Expected word after 'case'");let e=t.parseWord();t.skipNewlines(),t.expect(m.IN),t.skipNewlines();let r=[];for(;!t.check(m.ESAC,m.EOF);){t.checkIterationLimit();let s=t.getPos(),i=Rd(t);if(i&&r.push(i),t.skipNewlines(),t.getPos()===s&&!i)break}t.expect(m.ESAC);let n=t.parseOptionalRedirections();return k.caseNode(e,r,n)}function Rd(t){t.check(m.LPAREN)&&t.advance();let e=[];for(;t.isWord()&&(e.push(t.parseWord()),t.check(m.PIPE));)t.advance();if(e.length===0)return null;t.expect(m.RPAREN),t.skipNewlines();let r=[];for(;!t.check(m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND,m.ESAC,m.EOF);){t.checkIterationLimit(),t.isWord()&&t.peek(1).type===m.RPAREN&&t.error("syntax error near unexpected token `)'"),t.check(m.LPAREN)&&t.peek(1).type===m.WORD&&t.error(`syntax error near unexpected token \`${t.peek(1).value}'`);let s=t.getPos(),i=t.parseStatement();if(i&&r.push(i),t.skipSeparators(!1),t.getPos()===s&&!i)break}let n=";;";return t.check(m.DSEMI)?(t.advance(),n=";;"):t.check(m.SEMI_AND)?(t.advance(),n=";&"):t.check(m.SEMI_SEMI_AND)&&(t.advance(),n=";;&"),k.caseItem(e,r,n)}function Cn(t){t.peek(1).type,m.LPAREN,t.expect(m.LPAREN),t.check(m.LPAREN)&&t.advance();let e=t.parseCompoundList();t.expect(m.RPAREN);let r=t.parseOptionalRedirections();return k.subshell(e,r)}function Nn(t){t.expect(m.LBRACE);let e=t.parseCompoundList();t.expect(m.RBRACE);let r=t.parseOptionalRedirections();return k.group(e,r)}var Od=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Dd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function kn(t){return t.skipNewlines(),Td(t)}function Td(t){let e=Io(t);for(t.skipNewlines();t.check(m.OR_OR);){t.advance(),t.skipNewlines();let r=Io(t);e={type:"CondOr",left:e,right:r},t.skipNewlines()}return e}function Io(t){let e=vn(t);for(t.skipNewlines();t.check(m.AND_AND);){t.advance(),t.skipNewlines();let r=vn(t);e={type:"CondAnd",left:e,right:r},t.skipNewlines()}return e}function vn(t){return t.skipNewlines(),t.check(m.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:vn(t)}):Ld(t)}function Ld(t){if(t.check(m.LPAREN)){t.advance();let e=kn(t);return t.expect(m.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),r=e.value;if(Od.includes(r)&&!e.quoted&&(t.advance(),t.check(m.DBRACK_END)&&t.error(`Expected operand after ${r}`),t.isWord())){let s=t.parseWord();return{type:"CondUnary",operator:r,operand:s}}let n=t.parseWord();if(t.isWord()&&Dd.includes(t.current().value)){let s=t.advance().value,i=t.parseWord();return{type:"CondBinary",operator:s,left:n,right:i}}if(t.check(m.LESS)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"<",left:n,right:s}}if(t.check(m.GREAT)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:">",left:n,right:s}}if(t.isWord()&&t.current().value==="="){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"==",left:n,right:s}}return{type:"CondWord",word:n}}t.error("Expected conditional expression")}function Md(t,e,r){let n=r+1,s=e[n];if("@*#?$!-0123456789".includes(s))return{part:k.parameterExpansion(s),endIndex:n+1};let i="";for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)i+=e[n],n++;return{part:k.parameterExpansion(i),endIndex:n}}function _d(t,e,r,n=!1){let s=r+2,i=!1;e[s]==="!"&&(i=!0,s++);let a=!1;e[s]==="#"&&!/[}:#%/^,]/.test(e[s+1]||"}")&&(a=!0,s++);let o="",c=e[s];if(/[@*#?$!-]/.test(c)&&!/[a-zA-Z0-9_]/.test(e[s+1]||""))o=c,s++;else for(;s<e.length&&/[a-zA-Z0-9_]/.test(e[s]);)o+=e[s],s++;if(e[s]==="["){let u=yn(t,e,s,"[","]");o+=e.slice(s,u+1),s=u+1}o===""&&!i&&!a&&e[s]!=="}"&&t.error(`\${${e[s]}}: bad substitution`);let l=null;if(i){let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)l={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="";else if(e[s]==="*"||e[s]==="@"){let f=e[s];s++,l={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else l={type:"Indirection"}}else if(a)if(e[s]===":")for(l={type:"LengthSliceError"};s<e.length&&e[s]!=="}";)s++;else e[s]!=="}"&&/[-+=?]/.test(e[s])?t.error(`\${#${o}${e.slice(s,e.indexOf("}",s))}}: bad substitution`):l={type:"Length"};if(!l&&s<e.length&&e[s]!=="}"){let u=Wd(t,e,s,o,n);l=u.operation,s=u.endIndex}if(s<e.length&&e[s]!=="}"){let u=e[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<e.length&&e[f]!=="}";)f++;let d=e.slice(r,f+1);t.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:k.parameterExpansion(o,l),endIndex:s+1}}function Wd(t,e,r,n,s=!1){let i=r,a=e[i],o=e[i+1]||"";if(a===":"){let c=o;if("-=?+".includes(c)){i+=2;let g=rt(t,e,i),b=e.slice(i,g),S=je(t,b,!1,!1,!0,!1,s),x=k.word(S.length>0?S:[k.literal("")]);if(c==="-")return{operation:{type:"DefaultValue",word:x,checkEmpty:!0},endIndex:g};if(c==="=")return{operation:{type:"AssignDefault",word:x,checkEmpty:!0},endIndex:g};if(c==="?")return{operation:{type:"ErrorIfUnset",word:x,checkEmpty:!0},endIndex:g};if(c==="+")return{operation:{type:"UseAlternative",word:x,checkEmpty:!0},endIndex:g}}i++;let l=rt(t,e,i),u=e.slice(i,l),f=-1,d=0,h=0;for(let w=0;w<u.length;w++){let g=u[w];if(g==="("||g==="[")d++;else if(g===")"||g==="]")d--;else if(g==="?"&&d===0)h++;else if(g===":"&&d===0)if(h>0)h--;else{f=w;break}}let p=f>=0?u.slice(0,f):u,E=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:gn(t,p),length:E?gn(t,E):null},endIndex:l}}if("-=?+".includes(a)){i++;let c=rt(t,e,i),l=e.slice(i,c),u=je(t,l,!1,!1,!0,!1,s),f=k.word(u.length>0?u:[k.literal("")]);if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:c};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:c};if(a==="?")return{operation:{type:"ErrorIfUnset",word:l?f:null,checkEmpty:!1},endIndex:c};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:c}}if(a==="#"||a==="%"){let c=o===a,l=a==="#"?"prefix":"suffix";i+=c?2:1;let u=rt(t,e,i),f=e.slice(i,u),d=je(t,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:k.word(d.length>0?d:[k.literal("")]),side:l,greedy:c},endIndex:u}}if(a==="/"){let c=o==="/";i+=c?2:1;let l=null;e[i]==="#"?(l="start",i++):e[i]==="%"&&(l="end",i++);let u=bo(t,e,i),f=e.slice(i,u),d=je(t,f,!1,!1,!1),h=k.word(d.length>0?d:[k.literal("")]),p=null,E=u;if(e[u]==="/"){let w=u+1,g=rt(t,e,w),b=e.slice(w,g),S=je(t,b,!1,!1,!1);p=k.word(S.length>0?S:[k.literal("")]),E=g}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:c,anchor:l},endIndex:E}}if(a==="^"||a===","){let c=o===a,l=a==="^"?"upper":"lower";i+=c?2:1;let u=rt(t,e,i),f=e.slice(i,u),d=f?k.word([k.literal(f)]):null;return{operation:{type:"CaseModification",direction:l,all:c,pattern:d},endIndex:u}}return a==="@"&&/[QPaAEK]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function In(t,e,r,n=!1){let s=r+1;if(s>=e.length)return{part:k.literal("$"),endIndex:s};let i=e[s];if(i==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,r);if(i==="["){let a=1,o=s+1;for(;o<e.length&&a>0;)e[o]==="["?a++:e[o]==="]"&&a--,a>0&&o++;if(a===0){let c=e.slice(s+1,o),l=ie(t,c);return{part:k.arithmeticExpansion(l),endIndex:o+1}}}return i==="("?t.parseCommandSubstitution(e,r):i==="{"?_d(t,e,r,n):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Md(t,e,r):{part:k.literal("$"),endIndex:s}}function Bd(t,e){let r=[],n=0,s="",i=()=>{s&&(r.push(k.literal(s)),s="")};for(;n<e.length;){let a=e[n];if(a==="\\"&&n+1<e.length){let o=e[n+1];if(o==="$"||o==="`"){s+=o,n+=2;continue}s+=a,n++;continue}if(a==="$"){i();let{part:o,endIndex:c}=In(t,e,n,!0);o&&r.push(o),n=c;continue}if(a==="`"){i();let{part:o,endIndex:c}=t.parseBacktickSubstitution(e,n,!0);r.push(o),n=c;continue}s+=a,n++}return i(),r}function Hd(t,e,r){let n=[],s=r,i="",a=()=>{i&&(n.push(k.literal(i)),i="")};for(;s<e.length&&e[s]!=='"';){let o=e[s];if(o==="\\"&&s+1<e.length){let c=e[s+1];if('"\\$`\n'.includes(c)){i+=c,s+=2;continue}i+=o,s++;continue}if(o==="$"){a();let{part:c,endIndex:l}=In(t,e,s,!0);c&&n.push(c),s=l;continue}if(o==="`"){a();let{part:c,endIndex:l}=t.parseBacktickSubstitution(e,s,!0);n.push(c),s=l;continue}i+=o,s++}return a(),{part:k.doubleQuoted(n),endIndex:s}}function je(t,e,r=!1,n=!1,s=!1,i=!1,a=!1){if(n)return[k.singleQuoted(e)];if(r){let f=Bd(t,e);return[k.doubleQuoted(f)]}let o=[],c=0,l="",u=()=>{l&&(o.push(k.literal(l)),l="")};for(;c<e.length;){let f=e[c];if(f==="\\"&&c+1<e.length){let d=e[c+1];(i?d==="$"||d==="`"||d==="\\"||d===`
|
|
495
|
+
`||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(e,r,n){let s=this.input,i=s.length,a=e,o=n;for(;a<i;){let c=s[a];if(c===" "||c===" "||c===`
|
|
496
|
+
`||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,o++;a<i&&f>0;)s[a]==="{"?f++:s[a]==="}"&&f--,a++,o++;continue}a++,o++;continue}if(c==="}"){a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="("){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="("?u++:s[a]===")"&&u--,a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="{"){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="{"?u++:s[a]==="}"&&u--,a++,o++;continue}if(c==="`"){for(a++,o++;a<i&&s[a]!=="`";)s[a]==="\\"&&a+1<i?(a+=2,o+=2):(a++,o++);a<i&&(a++,o++);continue}a++,o++}let l=s.slice(e,a);return this.pos=a,this.column=o,{type:m.WORD,value:l,start:e,end:a,line:r,column:n,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let r=this.input,n=r.length,s=e+1,i=1,a=!1,o=!1;for(;s<n&&i>0;){let l=r[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)a=!0,s++;else if(l==="."&&s+1<n&&r[s+1]===".")o=!0,s+=2;else{if(l===" "||l===" "||l===`
|
|
497
|
+
`||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(a||o)?r.slice(e,s):null}scanLiteralBraceWord(e){let r=this.input,n=r.length,s=e+1,i=1;for(;s<n&&i>0;){let a=r[s];if(a==="{")i++,s++;else if(a==="}"){if(i--,i===0)return r.slice(e,s+1);s++}else{if(a===" "||a===" "||a===`
|
|
498
|
+
`||a===";"||a==="&"||a==="|")return null;s++}}return null}};var Es=1e6,bs=1e5,$c=1e6,Oc=new Set([m.LESS,m.GREAT,m.DLESS,m.DGREAT,m.LESSAND,m.GREATAND,m.LESSGREAT,m.DLESSDASH,m.CLOBBER,m.TLESS,m.AND_GREAT,m.AND_DGREAT]),Pc=new Set([m.LESS,m.GREAT,m.DLESS,m.DGREAT,m.LESSAND,m.GREATAND,m.LESSGREAT,m.DLESSDASH,m.CLOBBER,m.TLESS]),Ze=class extends Error{line;column;token;constructor(e,r,n,s=void 0){super(`Parse error at ${r}:${n}: ${e}`),this.line=r,this.column=n,this.token=s,this.name="ParseException"}};function Tc(t,e,r){let n=r+1;for(;n<e.length&&/[a-zA-Z0-9_-]/.test(e[n]);)n++;return n}function Ss(t,e,r,n,s){let i=1,a=r+1;for(;a<e.length&&i>0;)e[a]===n?i++:e[a]===s&&i--,i>0&&a++;return i===0?a:-1}function gt(t,e,r){let n=r,s=1;for(;n<e.length&&s>0;){let i=e[n];if(i==="\\"&&n+1<e.length){n+=2;continue}if(i==="'"){let a=e.indexOf("'",n+1);if(a!==-1){n=a+1;continue}}if(i==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?n+=2:n++;n<e.length&&n++;continue}i==="{"?s++:i==="}"&&s--,s>0&&n++}return n}function Dc(t,e,r){let n=r,s=!1;for(;n<e.length;){let i=e[n];if(i==="/"&&s||i==="}")break;if(i==="'"){let a=e.indexOf("'",n+1);if(a!==-1){n=a+1,s=!0;continue}}if(i==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?n+=2:n++;n<e.length&&n++,s=!0;continue}i==="\\"?(n+=2,s=!0):(n++,s=!0)}return n}function Lc(t,e,r){let n=r,s="";for(;n<e.length;){let i=e[n];if(i==="*"||i==="?")s+=i,n++;else if(i==="["){let a=Gm(e,n);a===-1?(s+=i,n++):(s+=e.slice(n,a+1),n=a+1)}else break}return{pattern:s,endIndex:n}}function Gm(t,e){let r=e+1;for(r<t.length&&t[r]==="^"&&r++,r<t.length&&t[r]==="]"&&r++;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){r+=2;continue}if(n==="]")return r;if(n==='"'||n==="$"||n==="`")return-1;if(n==="'"){let s=t.indexOf("'",r+1);if(s!==-1){r=s+1;continue}}if(n==="["&&r+1<t.length&&t[r+1]===":"){let s=t.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}if(n==="["&&r+1<t.length&&(t[r+1]==="."||t[r+1]==="=")){let i=`${t[r+1]}]`,a=t.indexOf(i,r+2);if(a!==-1){r=a+2;continue}}r++}return-1}function Mc(t,e,r){let n="",s=r;for(;s<e.length&&e[s]!=="'";){let i=e[s];if(i==="\\"&&s+1<e.length)switch(e[s+1]){case"n":n+=`
|
|
499
|
+
`,s+=2;break;case"t":n+=" ",s+=2;break;case"r":n+="\r",s+=2;break;case"\\":n+="\\",s+=2;break;case"'":n+="'",s+=2;break;case'"':n+='"',s+=2;break;case"a":n+="\x07",s+=2;break;case"b":n+="\b",s+=2;break;case"e":case"E":n+="\x1B",s+=2;break;case"f":n+="\f",s+=2;break;case"v":n+="\v",s+=2;break;case"x":{let o=e.slice(s+2,s+4),l=parseInt(o,16);Number.isNaN(l)?(n+="\\x",s+=2):(n+=String.fromCharCode(l),s+=4);break}case"u":{let o=e.slice(s+2,s+6),l=parseInt(o,16);Number.isNaN(l)?(n+="\\u",s+=2):(n+=String.fromCharCode(l),s+=6);break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let o="",l=s+1;for(;l<e.length&&l<s+4&&/[0-7]/.test(e[l]);)o+=e[l],l++;let c=parseInt(o,8);n+=String.fromCharCode(c),s=l;break}default:n+=i,s++}else n+=i,s++}return s<e.length&&e[s]==="'"&&s++,{part:N.literal(n),endIndex:s}}function Cs(t,e){let r=e.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:le(t,r)}function Fc(t){let e=[],r="",n=0;for(let s=0;s<t.length;s++){let i=t[s];i==="{"?(n++,r+=i):i==="}"?(n--,r+=i):i===","&&n===0?(e.push(r),r=""):r+=i}return e.push(r),e}function _c(t,e,r,n){let s=Ss(t,e,r,"{","}");if(s===-1)return null;let i=e.slice(r+1,s),a=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(a)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(a[1],10),end:Number.parseInt(a[2],10),step:a[3]?Number.parseInt(a[3],10):void 0,startStr:a[1],endStr:a[2]}]},endIndex:s+1};let o=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return o?{part:{type:"BraceExpansion",items:[{type:"Range",start:o[1],end:o[2],step:o[3]?Number.parseInt(o[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&n?{part:{type:"BraceExpansion",items:Fc(i).map(u=>({type:"Word",word:N.word(n(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Fc(i).map(u=>({type:"Word",word:N.word([N.literal(u)])}))},endIndex:s+1}:null}function Bc(t,e){let r="";for(let n of e.parts)switch(n.type){case"Literal":case"SingleQuoted":case"Escaped":r+=n.value;break;case"DoubleQuoted":r+='"';for(let s of n.parts)s.type==="Literal"||s.type==="Escaped"?r+=s.value:s.type==="ParameterExpansion"&&(r+=`\${${s.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${n.parameter}}`;break;case"Glob":r+=n.pattern;break;default:r+=n.type}return r}function Wc(t,e){return{[m.LESS]:"<",[m.GREAT]:">",[m.DGREAT]:">>",[m.LESSAND]:"<&",[m.GREATAND]:">&",[m.LESSGREAT]:"<>",[m.CLOBBER]:">|",[m.TLESS]:"<<<",[m.AND_GREAT]:"&>",[m.AND_DGREAT]:"&>>",[m.DLESS]:"<",[m.DLESSDASH]:"<"}[e]||">"}function Qr(t){let e=t.current(),r=e.type;if(r===m.NUMBER){let n=t.peek(1);return e.end!==n.start?!1:Pc.has(n.type)}return Oc.has(r)}function Xr(t){let e=null;t.check(m.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let r=t.advance(),n=Wc(t,r.type);if(r.type===m.DLESS||r.type===m.DLESSDASH)return qm(t,n,e,r.type===m.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return N.redirection(n,s,e)}function qm(t,e,r,n){t.isWord()||t.error("Expected here-document delimiter");let s=t.advance(),i=s.value,a=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let o=N.redirection(n?"<<-":"<<",N.hereDoc(i,N.word([]),n,a),r);return t.addPendingHeredoc(o,i,n,a),o}function zc(t){let e=[],r=null,n=[],s=[];for(;t.check(m.ASSIGNMENT_WORD);)t.checkIterationLimit(),e.push(Vm(t));for(;Qr(t);)t.checkIterationLimit(),s.push(Xr(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(m.RBRACE))&&!t.check(m.PIPE,m.PIPE_AMP);)if(t.checkIterationLimit(),Qr(t))s.push(Xr(t));else if(t.check(m.RBRACE)){let i=t.advance();n.push(t.parseWordFromString(i.value,!1,!1))}else if(t.isWord())n.push(t.parseWord());else if(t.check(m.ASSIGNMENT_WORD)){let i=t.advance(),a=i.value,o=a.endsWith("="),l=a.endsWith("=(");if((o||l)&&(l||t.check(m.LPAREN))){let c=l?a.slice(0,-2):a.slice(0,-1);l||t.expect(m.LPAREN);let u=As(t);t.expect(m.RPAREN);let f=u.map(h=>Bc(t,h)),d=`${c}=(${f.join(" ")})`;n.push(t.parseWordFromString(d,!1,!1))}else n.push(t.parseWordFromString(a,i.quoted,i.singleQuoted))}else if(t.check(m.LPAREN))t.error("syntax error near unexpected token `('");else break;return N.simpleCommand(r,n,e,s)}function Vm(t){let e=t.expect(m.ASSIGNMENT_WORD),r=e.value,n=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);n||t.error(`Invalid assignment: ${r}`);let s=n[0],i,a=s.length;if(r[a]==="["){let f=0,d=a+1;for(;a<r.length;a++)if(r[a]==="[")f++;else if(r[a]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${r}`),i=r.slice(d,a),a++}let o=r[a]==="+";o&&a++,r[a]!=="="&&t.error(`Invalid assignment: ${r}`),a++;let l=r.slice(a);if(l==="("){let f=As(t);t.expect(m.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return N.assignment(d,null,o,f)}if(l===""&&t.check(m.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let d=As(t);t.expect(m.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return N.assignment(h,null,o,d)}}let c=l?t.parseWordFromString(l,e.quoted,e.singleQuoted,!0):null,u=i!==void 0?`${s}[${i}]`:s;return N.assignment(u,c,o,null)}function As(t){let e=[];for(t.skipNewlines();!t.check(m.RPAREN,m.EOF);)t.checkIterationLimit(),t.isWord()?e.push(t.parseWord()):t.advance(),t.skipNewlines();return e}function ks(t){t.expect(m.IF);let e=[],r=t.parseCompoundList();t.expect(m.THEN);let n=t.parseCompoundList();if(n.length===0){let a=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${a}'`)}for(e.push({condition:r,body:n});t.check(m.ELIF);){t.advance();let a=t.parseCompoundList();t.expect(m.THEN);let o=t.parseCompoundList();if(o.length===0){let l=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${l}'`)}e.push({condition:a,body:o})}let s=null;t.check(m.ELSE)&&(t.advance(),s=t.parseCompoundList(),s.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(m.FI);let i=t.parseOptionalRedirections();return N.ifNode(e,s,i)}function vs(t){if(t.expect(m.FOR),t.check(m.DPAREN_START))return Qm(t);t.isWord()||t.error("Expected variable name in for loop");let r=t.advance().value,n=null;if(t.skipNewlines(),t.check(m.IN))for(t.advance(),n=[];!t.check(m.SEMICOLON,m.NEWLINE,m.DO,m.EOF)&&t.isWord();)n.push(t.parseWord());t.check(m.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(m.DO);let s=t.parseCompoundList();t.expect(m.DONE);let i=t.parseOptionalRedirections();return N.forNode(r,n,s,i)}function Qm(t){t.expect(m.DPAREN_START);let e=null,r=null,n=null,s=["","",""],i=0,a=0;for(;!t.check(m.DPAREN_END,m.EOF);){let c=t.advance();if(c.type===m.SEMICOLON&&a===0){if(i++,i>2)break}else c.value==="("&&a++,c.value===")"&&a--,s[i]+=c.value}t.expect(m.DPAREN_END),s[0].trim()&&(e=le(t,s[0].trim())),s[1].trim()&&(r=le(t,s[1].trim())),s[2].trim()&&(n=le(t,s[2].trim())),t.skipNewlines(),t.check(m.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(m.DO);let o=t.parseCompoundList();t.expect(m.DONE);let l=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:r,update:n,body:o,redirections:l}}function Ns(t){t.expect(m.WHILE);let e=t.parseCompoundList();t.expect(m.DO);let r=t.parseCompoundList();r.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(m.DONE);let n=t.parseOptionalRedirections();return N.whileNode(e,r,n)}function Is(t){t.expect(m.UNTIL);let e=t.parseCompoundList();t.expect(m.DO);let r=t.parseCompoundList();r.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(m.DONE);let n=t.parseOptionalRedirections();return N.untilNode(e,r,n)}function Rs(t){t.expect(m.CASE),t.isWord()||t.error("Expected word after 'case'");let e=t.parseWord();t.skipNewlines(),t.expect(m.IN),t.skipNewlines();let r=[];for(;!t.check(m.ESAC,m.EOF);){t.checkIterationLimit();let s=t.getPos(),i=Xm(t);if(i&&r.push(i),t.skipNewlines(),t.getPos()===s&&!i)break}t.expect(m.ESAC);let n=t.parseOptionalRedirections();return N.caseNode(e,r,n)}function Xm(t){t.check(m.LPAREN)&&t.advance();let e=[];for(;t.isWord()&&(e.push(t.parseWord()),t.check(m.PIPE));)t.advance();if(e.length===0)return null;t.expect(m.RPAREN),t.skipNewlines();let r=[];for(;!t.check(m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND,m.ESAC,m.EOF);){t.checkIterationLimit(),t.isWord()&&t.peek(1).type===m.RPAREN&&t.error("syntax error near unexpected token `)'"),t.check(m.LPAREN)&&t.peek(1).type===m.WORD&&t.error(`syntax error near unexpected token \`${t.peek(1).value}'`);let s=t.getPos(),i=t.parseStatement();if(i&&r.push(i),t.skipSeparators(!1),t.getPos()===s&&!i)break}let n=";;";return t.check(m.DSEMI)?(t.advance(),n=";;"):t.check(m.SEMI_AND)?(t.advance(),n=";&"):t.check(m.SEMI_SEMI_AND)&&(t.advance(),n=";;&"),N.caseItem(e,r,n)}function $s(t){t.peek(1).type,m.LPAREN,t.expect(m.LPAREN),t.check(m.LPAREN)&&t.advance();let e=t.parseCompoundList();t.expect(m.RPAREN);let r=t.parseOptionalRedirections();return N.subshell(e,r)}function Os(t){t.expect(m.LBRACE);let e=t.parseCompoundList();t.expect(m.RBRACE);let r=t.parseOptionalRedirections();return N.group(e,r)}var Jm=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Ym=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Fs(t){return t.skipNewlines(),e0(t)}function e0(t){let e=Hc(t);for(t.skipNewlines();t.check(m.OR_OR);){t.advance(),t.skipNewlines();let r=Hc(t);e={type:"CondOr",left:e,right:r},t.skipNewlines()}return e}function Hc(t){let e=Ps(t);for(t.skipNewlines();t.check(m.AND_AND);){t.advance(),t.skipNewlines();let r=Ps(t);e={type:"CondAnd",left:e,right:r},t.skipNewlines()}return e}function Ps(t){return t.skipNewlines(),t.check(m.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Ps(t)}):t0(t)}function t0(t){if(t.check(m.LPAREN)){t.advance();let e=Fs(t);return t.expect(m.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),r=e.value;if(Jm.includes(r)&&!e.quoted&&(t.advance(),t.check(m.DBRACK_END)&&t.error(`Expected operand after ${r}`),t.isWord())){let s=t.parseWord();return{type:"CondUnary",operator:r,operand:s}}let n=t.parseWord();if(t.isWord()&&Ym.includes(t.current().value)){let s=t.advance().value,i=t.parseWord();return{type:"CondBinary",operator:s,left:n,right:i}}if(t.check(m.LESS)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"<",left:n,right:s}}if(t.check(m.GREAT)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:">",left:n,right:s}}if(t.isWord()&&t.current().value==="="){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"==",left:n,right:s}}return{type:"CondWord",word:n}}t.error("Expected conditional expression")}function n0(t,e,r){let n=r+1,s=e[n];if("@*#?$!-0123456789".includes(s))return{part:N.parameterExpansion(s),endIndex:n+1};let i="";for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)i+=e[n],n++;return{part:N.parameterExpansion(i),endIndex:n}}function s0(t,e,r,n=!1){let s=r+2,i=!1;e[s]==="!"&&(i=!0,s++);let a=!1;e[s]==="#"&&!/[}:#%/^,]/.test(e[s+1]||"}")&&(a=!0,s++);let o="",l=e[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(e[s+1]||""))o=l,s++;else for(;s<e.length&&/[a-zA-Z0-9_]/.test(e[s]);)o+=e[s],s++;if(e[s]==="["){let u=Ss(t,e,s,"[","]");o+=e.slice(s,u+1),s=u+1}o===""&&!i&&!a&&e[s]!=="}"&&t.error(`\${${e[s]}}: bad substitution`);let c=null;if(i){let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="";else if(e[s]==="*"||e[s]==="@"){let f=e[s];s++,c={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else c={type:"Indirection"}}else if(a)if(e[s]===":")for(c={type:"LengthSliceError"};s<e.length&&e[s]!=="}";)s++;else e[s]!=="}"&&/[-+=?]/.test(e[s])?t.error(`\${#${o}${e.slice(s,e.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<e.length&&e[s]!=="}"){let u=i0(t,e,s,o,n);c=u.operation,s=u.endIndex}if(s<e.length&&e[s]!=="}"){let u=e[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<e.length&&e[f]!=="}";)f++;let d=e.slice(r,f+1);t.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:N.parameterExpansion(o,c),endIndex:s+1}}function i0(t,e,r,n,s=!1){let i=r,a=e[i],o=e[i+1]||"";if(a===":"){let l=o;if("-=?+".includes(l)){i+=2;let y=gt(t,e,i),E=e.slice(i,y),b=rt(t,E,!1,!1,!0,!1,s),S=N.word(b.length>0?b:[N.literal("")]);if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:y};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:y};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:y};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:y}}i++;let c=gt(t,e,i),u=e.slice(i,c),f=-1,d=0,h=0;for(let x=0;x<u.length;x++){let y=u[x];if(y==="("||y==="[")d++;else if(y===")"||y==="]")d--;else if(y==="?"&&d===0)h++;else if(y===":"&&d===0)if(h>0)h--;else{f=x;break}}let p=f>=0?u.slice(0,f):u,w=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Cs(t,p),length:w?Cs(t,w):null},endIndex:c}}if("-=?+".includes(a)){i++;let l=gt(t,e,i),c=e.slice(i,l),u=rt(t,c,!1,!1,!0,!1,s),f=N.word(u.length>0?u:[N.literal("")]);if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(a==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(a==="#"||a==="%"){let l=o===a,c=a==="#"?"prefix":"suffix";i+=l?2:1;let u=gt(t,e,i),f=e.slice(i,u),d=rt(t,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:N.word(d.length>0?d:[N.literal("")]),side:c,greedy:l},endIndex:u}}if(a==="/"){let l=o==="/";i+=l?2:1;let c=null;e[i]==="#"?(c="start",i++):e[i]==="%"&&(c="end",i++);let u=Dc(t,e,i),f=e.slice(i,u),d=rt(t,f,!1,!1,!1),h=N.word(d.length>0?d:[N.literal("")]),p=null,w=u;if(e[u]==="/"){let x=u+1,y=gt(t,e,x),E=e.slice(x,y),b=rt(t,E,!1,!1,!1);p=N.word(b.length>0?b:[N.literal("")]),w=y}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:w}}if(a==="^"||a===","){let l=o===a,c=a==="^"?"upper":"lower";i+=l?2:1;let u=gt(t,e,i),f=e.slice(i,u),d=f?N.word([N.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return a==="@"&&/[QPaAEK]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function Ts(t,e,r,n=!1){let s=r+1;if(s>=e.length)return{part:N.literal("$"),endIndex:s};let i=e[s];if(i==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,r);if(i==="["){let a=1,o=s+1;for(;o<e.length&&a>0;)e[o]==="["?a++:e[o]==="]"&&a--,a>0&&o++;if(a===0){let l=e.slice(s+1,o),c=le(t,l);return{part:N.arithmeticExpansion(c),endIndex:o+1}}}return i==="("?t.parseCommandSubstitution(e,r):i==="{"?s0(t,e,r,n):/[a-zA-Z_0-9@*#?$!-]/.test(i)?n0(t,e,r):{part:N.literal("$"),endIndex:s}}function a0(t,e){let r=[],n=0,s="",i=()=>{s&&(r.push(N.literal(s)),s="")};for(;n<e.length;){let a=e[n];if(a==="\\"&&n+1<e.length){let o=e[n+1];if(o==="$"||o==="`"){s+=o,n+=2;continue}s+=a,n++;continue}if(a==="$"){i();let{part:o,endIndex:l}=Ts(t,e,n,!0);o&&r.push(o),n=l;continue}if(a==="`"){i();let{part:o,endIndex:l}=t.parseBacktickSubstitution(e,n,!0);r.push(o),n=l;continue}s+=a,n++}return i(),r}function o0(t,e,r){let n=[],s=r,i="",a=()=>{i&&(n.push(N.literal(i)),i="")};for(;s<e.length&&e[s]!=='"';){let o=e[s];if(o==="\\"&&s+1<e.length){let l=e[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=o,s++;continue}if(o==="$"){a();let{part:l,endIndex:c}=Ts(t,e,s,!0);l&&n.push(l),s=c;continue}if(o==="`"){a();let{part:l,endIndex:c}=t.parseBacktickSubstitution(e,s,!0);n.push(l),s=c;continue}i+=o,s++}return a(),{part:N.doubleQuoted(n),endIndex:s}}function rt(t,e,r=!1,n=!1,s=!1,i=!1,a=!1){if(n)return[N.singleQuoted(e)];if(r){let f=a0(t,e);return[N.doubleQuoted(f)]}let o=[],l=0,c="",u=()=>{c&&(o.push(N.literal(c)),c="")};for(;l<e.length;){let f=e[l];if(f==="\\"&&l+1<e.length){let d=e[l+1];(i?d==="$"||d==="`"||d==="\\"||d===`
|
|
464
500
|
`:d==="$"||d==="`"||d==="\\"||d==='"'||d===`
|
|
465
|
-
`)?
|
|
466
|
-
`||n&&
|
|
467
|
-
`&&(a+=l),i+=2):(a+=e[i],i++)}else a+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let c=new t().parse(a);return{part:k.commandSubstitution(c,!0),endIndex:i+1}}parseArithmeticExpansion(e,r){let n=r+3,s=1,i=0,a=n;for(;a<e.length-1&&s>0;)e[a]==="$"&&e[a+1]==="("?e[a+2]==="("?(s++,a+=3):(i++,a+=2):e[a]==="("&&e[a+1]==="("?(s++,a+=2):e[a]===")"&&e[a+1]===")"?i>0?(i--,a++):(s--,s>0&&(a+=2)):e[a]==="("?(i++,a++):(e[a]===")"&&i>0&&i--,a++);let o=e.slice(n,a),c=this.parseArithmeticExpression(o);return{part:k.arithmeticExpansion(c),endIndex:a+2}}parseArithmeticCommand(){this.expect(m.DPAREN_START);let e="",r=1,n=0,s=!1,i=!1;for(;r>0&&!this.check(m.EOF);){if(s){if(s=!1,n>0){n--,e+=")";continue}if(this.check(m.RPAREN)){r--,i=!0,this.advance();continue}if(this.check(m.DPAREN_END)){r--,i=!0;continue}e+=")";continue}this.check(m.DPAREN_START)?(r++,e+="((",this.advance()):this.check(m.DPAREN_END)?n>=2?(n-=2,e+="))",this.advance()):n===1?(n--,e+=")",s=!0,this.advance()):(r--,i=!0,r>0&&(e+="))"),this.advance()):this.check(m.LPAREN)?(n++,e+="(",this.advance()):this.check(m.RPAREN)?(n>0&&n--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(m.DPAREN_END);let a=this.parseArithmeticExpression(e.trim()),o=this.parseOptionalRedirections();return k.arithmeticCommand(a,o)}parseConditionalCommand(){this.expect(m.DBRACK_START);let e=kn(this);this.expect(m.DBRACK_END);let r=this.parseOptionalRedirections();return k.conditionalCommand(e,r)}parseFunctionDef(){let e;this.check(m.FUNCTION)?(this.advance(),e=this.expect(m.NAME,"Expected function name").value,this.check(m.LPAREN)&&(this.advance(),this.expect(m.RPAREN))):(e=this.advance().value,this.expect(m.LPAREN),this.expect(m.RPAREN)),this.skipNewlines();let r=this.parseCompoundCommandBody(),n=this.parseOptionalRedirections();return k.functionDef(e,r,n)}parseCompoundCommandBody(){if(this.check(m.LBRACE))return Nn(this);if(this.check(m.LPAREN))return Cn(this);if(this.check(m.IF))return En(this);if(this.check(m.FOR))return bn(this);if(this.check(m.WHILE))return Sn(this);if(this.check(m.UNTIL))return xn(this);if(this.check(m.CASE))return An(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(m.EOF,m.FI,m.ELSE,m.ELIF,m.THEN,m.DO,m.DONE,m.ESAC,m.RPAREN,m.RBRACE,m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,n=this.parseStatement();if(n&&e.push(n),this.skipSeparators(),this.pos===r&&!n)break}return e}parseOptionalRedirections(){let e=[];for(;lr(this);){this.checkIterationLimit();let r=this.pos;if(e.push(cr(this)),this.pos===r)break}return e}parseArithmeticExpression(e){return ie(this,e)}};function qe(t){return new le().parse(t)}Y();var yt=class{fs;cwd;constructor(e,r){this.fs=e,this.cwd=r}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,r){let n=[];for(let s=0;s<e.length;s++){let i=e[s];if((r?.[s]??!1)||!this.isGlobPattern(i))n.push(i);else{let o=await this.expand(i);o.length>0?n.push(...o):n.push(i)}}return n}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}async expandSimple(e){let r=[],n=e.lastIndexOf("/"),s,i;n===-1?(s=this.cwd,i=e):(s=e.slice(0,n)||"/",i=e.slice(n+1));let a=this.fs.resolvePath(this.cwd,s);try{let o=await this.fs.readdir(a);for(let c of o)if(this.matchPattern(c,i)){let l=n===-1?c:`${s}/${c}`;r.push(l)}}catch{}return r.sort()}async expandRecursive(e){let r=[],n=e.indexOf("**"),s=e.slice(0,n).replace(/\/$/,"")||".",a=e.slice(n+2).replace(/^\//,"");return await this.walkDirectory(s,a,r),r.sort()}async walkDirectory(e,r,n){let s=this.fs.resolvePath(this.cwd,e);try{let i=await this.fs.readdir(s);for(let a of i){let o=e==="."?a:`${e}/${a}`,c=this.fs.resolvePath(this.cwd,o);try{(await this.fs.stat(c)).isDirectory?await this.walkDirectory(o,r,n):r&&this.matchPattern(a,r)&&n.push(o)}catch{}}}catch{}}matchPattern(e,r){return this.patternToRegex(r).test(e)}patternToRegex(e){let r="^";for(let n=0;n<e.length;n++){let s=e[n];if(s==="*")r+=".*";else if(s==="?")r+=".";else if(s==="["){let i=n+1,a="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(a+="^",i++),i<e.length&&e[i]==="]"&&(a+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){let c=e.slice(i+2,o),l=this.posixClassToRegex(c);a+=l,i=o+2;continue}}if(e[i]==="\\"&&i+1<e.length){a+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?a+="\\-":a+=e[i],i++}a+="]",r+=a,n=i}else if(s==="\\"&&n+1<e.length){let i=e[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(s)?r+=`\\${s}`:r+=s}return r+="$",new RegExp(r)}posixClassToRegex(e){return{alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:" \\t\\n\\r\\f\\v",upper:"A-Z",word:"a-zA-Z0-9_",xdigit:"0-9a-fA-F"}[e]||""}};Y();function Ne(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Ne(t.expression);case"ArithBinary":return Ne(t.left)||Ne(t.right);case"ArithUnary":return Ne(t.operand);case"ArithTernary":return Ne(t.condition)||Ne(t.consequent)||Ne(t.alternate);case"ArithAssignment":return Ne(t.value);case"ArithGroup":return Ne(t.expression);case"ArithArrayElement":return t.index?Ne(t.index):!1;case"ArithConcat":return t.parts.some(Ne);default:return!1}}function $n(t){let e=t.operation;return e?!!("word"in e&&e.word&&Me(e.word)||e.type==="PatternReplacement"&&(e.pattern&&Me(e.pattern)||e.replacement&&Me(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&Me(e.pattern)):!1}function ur(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Ne(t.expression.expression);case"DoubleQuoted":return t.parts.some(ur);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&Me(e.word));case"ParameterExpansion":return $n(t);default:return!1}}function Me(t){return t.parts.some(ur)}function Rn(t){if(!t.operation)return!1;let e=t.operation,r;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(r=e.word?.parts),!r)return!1;for(let n of r)if(n.type==="DoubleQuoted"||n.type==="SingleQuoted")return!0;return!1}function $o(t){let e=!1,r=!1,n=!1,s=!1,i=!1;for(let a of t){if((a.type==="SingleQuoted"||a.type==="DoubleQuoted")&&(e=!0,a.type==="DoubleQuoted"))for(let o of a.parts)o.type==="ParameterExpansion"&&o.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!o.operation&&(s=!0);a.type==="CommandSubstitution"&&(r=!0),a.type==="ParameterExpansion"&&(i=!0,(a.parameter==="@"||a.parameter==="*")&&(n=!0),Rn(a)&&(e=!0))}return{hasQuoted:e,hasCommandSub:r,hasArrayVar:n,hasArrayAtExpansion:s,hasParamExpansion:i}}function zd(t,e,r,n,s){let i=r??1;i===0&&(i=1);let a=Math.abs(i),o=[],c=0;n?.match(/^-?0\d/)&&(c=Math.max(c,n.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length));let l=u=>{if(c>0){let f=u<0,d=String(Math.abs(u)).padStart(c,"0");return f?`-${d}`:d}return String(u)};if(t<=e)for(let u=t,f=0;u<=e&&f<1e4;u+=a,f++)o.push(l(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=a,f++)o.push(l(u));return o}function Gd(t,e,r){let n=r??1;n===0&&(n=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),a=Math.abs(n),o=t>="A"&&t<="Z",c=t>="a"&&t<="z",l=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(o&&u||c&&l)return null;let f=[];if(s<=i)for(let d=s,h=0;d<=i&&h<1e4;d+=a,h++)f.push(String.fromCharCode(d));else for(let d=s,h=0;d>=i&&h<1e4;d-=a,h++)f.push(String.fromCharCode(d));return f}function It(t,e,r,n,s){let i=r!==void 0?`..${r}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:zd(t,e,r,n,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:Gd(t,e,r),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function Ee(t,e){let r="",n=0;for(;n<t.length;){let s=t[n];if(s==="\\")if(n+1<t.length){let i=t[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?r+=`\\${i}`:r+=i,n+=2}else r+="\\\\",n++;else if(s==="*")r+=e?".*":".*?",n++;else if(s==="?")r+=".",n++;else if(s==="["){let i=jd(t,n);if(i===-1)r+="\\[",n++;else{let a=t.slice(n+1,i);r+=qd(a),n=i+1}}else/[\^$.|+(){}]/.test(s)?(r+=`\\${s}`,n++):(r+=s,n++)}return r}function jd(t,e){let r=e+1;for(r<t.length&&t[r]==="^"&&r++,r<t.length&&t[r]==="]"&&r++;r<t.length;){if(t[r]==="\\"&&r+1<t.length){r+=2;continue}if(t[r]==="]")return r;if(t[r]==="'"){let n=t.indexOf("'",r+1);if(n!==-1){r=n+1;continue}}if(t[r]==="["&&r+1<t.length&&t[r+1]===":"){let n=t.indexOf(":]",r+2);if(n!==-1){r=n+2;continue}}r++}return-1}function qd(t){let e="[",r=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",r++);r<t.length;){if(t[r]==="'"){let s=t.indexOf("'",r+1);if(s!==-1){let i=t.slice(r+1,s);for(let a of i)a==="\\"?e+="\\\\":a==="]"?e+="\\]":a==="^"&&e==="["?e+="\\^":e+=a;r=s+1;continue}}if(t[r]==="["&&r+1<t.length&&t[r+1]===":"){let s=t.indexOf(":]",r+2);if(s!==-1){let i=t.slice(r+2,s);e+=Zd(i),r=s+2;continue}}let n=t[r];n==="\\"?r+1<t.length?(e+=`\\${t[r+1]}`,r+=2):(e+="\\\\",r++):n==="-"&&r>0&&r<t.length-1?(e+="-",r++):n==="^"&&r===0?(e+="^",r++):(n==="]"&&r===0?e+="\\]":e+=n,r++)}return e+="]",e}var Vd={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:" \\t\\n\\r\\f\\v",upper:"A-Z",word:"a-zA-Z0-9_",xdigit:"0-9A-Fa-f"};function Zd(t){return Vd[t]??""}Y();function $t(t,e){let r=`${e}_`,n=[];for(let s of Object.keys(t.state.env))if(s.startsWith(r)){let i=s.slice(r.length),a=Number.parseInt(i,10);!Number.isNaN(a)&&String(a)===i&&n.push(a)}return n.sort((s,i)=>s-i)}function Pn(t,e){let r=`${e}_`;for(let n of Object.keys(t.state.env))n.startsWith(r)&&delete t.state.env[n]}function On(t,e){let r=`${e}_`,n=[];for(let s of Object.keys(t.state.env))if(s.startsWith(r)&&!s.includes("__")){let i=s.slice(r.length);n.push(i)}return n.sort()}function Ro(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function fr(t){return t.IFS??`
|
|
468
|
-
`}function
|
|
469
|
-
`?"\\n":e).join("")}function
|
|
470
|
-
`,"";let h=Math.max(...f.map(([
|
|
471
|
-
`,""):t.state.env[`${a}_${h}`]||""}let u=t.state.env[`${a}_${
|
|
472
|
-
`:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let n=r.charCodeAt(0);n<32||n===127?e+=`\\x${n.toString(16).padStart(2,"0")}`:e+=r}}return`${e}'`}function
|
|
473
|
-
`)}return a}case"UseAlternative":return!(o||s.checkEmpty&&
|
|
474
|
-
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return f}});case"K":return"";default:return a}}case"Indirection":return
|
|
475
|
-
`)}return a}case"UseAlternative":return!(o||s.checkEmpty&&
|
|
476
|
-
`,0;let
|
|
477
|
-
`,0;i=
|
|
478
|
-
`);r=n}throw new
|
|
501
|
+
`)?c+=d:c+=`\\${d}`,l+=2;continue}if(f==="'"&&!a){u();let d=e.indexOf("'",l+1);if(d===-1){c+=e.slice(l);break}o.push(N.singleQuoted(e.slice(l+1,d))),l=d+1;continue}if(f==='"'){u();let{part:d,endIndex:h}=o0(t,e,l+1);o.push(d),l=h+1;continue}if(f==="$"&&e[l+1]==="'"){u();let{part:d,endIndex:h}=Mc(t,e,l+2);o.push(d),l=h;continue}if(f==="$"){u();let{part:d,endIndex:h}=Ts(t,e,l);d&&o.push(d),l=h;continue}if(f==="`"){u();let{part:d,endIndex:h}=t.parseBacktickSubstitution(e,l);o.push(d),l=h;continue}if(f==="~"){let d=l>0?e[l-1]:"";if(l===0||d==="="||s&&d===":"){let p=Tc(t,e,l),w=e[p];if(w===void 0||w==="/"||w===":"){u();let x=e.slice(l+1,p)||null;o.push({type:"TildeExpansion",user:x}),l=p;continue}}}if(f==="*"||f==="?"||f==="["){u();let{pattern:d,endIndex:h}=Lc(t,e,l);o.push({type:"Glob",pattern:d}),l=h;continue}if(f==="{"&&!s){let d=_c(t,e,l,rt);if(d){u(),o.push(d.part),l=d.endIndex;continue}}c+=f,l++}return u(),o}var he=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>$c)throw new Ze("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>Es)throw new Ze(`Input too large: ${e.length} bytes exceeds limit of ${Es}`,1,1);let r=new Zr(e);if(this.tokens=r.tokenize(),this.tokens.length>bs)throw new Ze(`Too many tokens: ${this.tokens.length} exceeds limit of ${bs}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseScript()}parseTokens(e){return this.tokens=e,this.pos=0,this.pendingHeredocs=[],this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}advance(){let e=this.current();return this.pos<this.tokens.length-1&&this.pos++,e}getPos(){return this.pos}check(e,r,n,s,...i){let a=this.tokens[this.pos]?.type;return a===e||r!==void 0&&a===r||n!==void 0&&a===n||s!==void 0&&a===s?!0:i.length>0?i.includes(a):!1}expect(e,r){if(this.check(e))return this.advance();let n=this.current();throw new Ze(r||`Expected ${e}, got ${n.type}`,n.line,n.column,n)}error(e){let r=this.current();throw new Ze(e,r.line,r.column,r)}skipNewlines(){for(;this.check(m.NEWLINE,m.COMMENT);)this.check(m.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(e=!0){for(;;){if(this.check(m.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(m.SEMICOLON,m.COMMENT)){this.advance();continue}if(e&&this.check(m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(e,r,n,s){this.pendingHeredocs.push({redirect:e,delimiter:r,stripTabs:n,quoted:s})}processHeredocs(){for(let e of this.pendingHeredocs)if(this.check(m.HEREDOC_CONTENT)){let r=this.advance(),n;e.quoted?n=N.word([N.literal(r.value)]):n=this.parseWordFromString(r.value,!1,!1,!1,!0),e.redirect.target=N.hereDoc(e.delimiter,n,e.stripTabs,e.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(m.EOF,m.NEWLINE,m.SEMICOLON,m.AMP,m.AND_AND,m.OR_OR,m.RPAREN,m.RBRACE,m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND)}isCommandStart(){let e=this.current().type;return e===m.WORD||e===m.NAME||e===m.NUMBER||e===m.ASSIGNMENT_WORD||e===m.IF||e===m.FOR||e===m.WHILE||e===m.UNTIL||e===m.CASE||e===m.LPAREN||e===m.LBRACE||e===m.DPAREN_START||e===m.DBRACK_START||e===m.FUNCTION||e===m.BANG||e===m.IN}parseScript(){let e=[],n=0;for(this.skipNewlines();!this.check(m.EOF);){n++,n>1e4&&this.error("Parser stuck: too many iterations (>10000)"),this.checkUnexpectedToken();let s=this.pos,i=this.parseStatement();i&&e.push(i),this.skipSeparators(!1),this.check(m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===s&&!this.check(m.EOF)&&this.advance()}return N.script(e)}checkUnexpectedToken(){let e=this.current().type,r=this.current().value;(e===m.DO||e===m.DONE||e===m.THEN||e===m.ELSE||e===m.ELIF||e===m.FI||e===m.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),(e===m.RBRACE||e===m.RPAREN)&&this.error(`syntax error near unexpected token \`${r}'`),(e===m.DSEMI||e===m.SEMI_AND||e===m.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),e===m.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`)}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let e=[],r=[],n=!1,s=this.parsePipeline();for(e.push(s);this.check(m.AND_AND,m.OR_OR);){let i=this.advance();r.push(i.type===m.AND_AND?"&&":"||"),this.skipNewlines();let a=this.parsePipeline();e.push(a)}return this.check(m.AMP)&&(this.advance(),n=!0),N.statement(e,r,n)}parsePipeline(){let e=0;for(;this.check(m.BANG);)this.advance(),e++;let r=e%2===1,n=[],s=this.parseCommand();for(n.push(s);this.check(m.PIPE,m.PIPE_AMP);){let i=this.advance();this.skipNewlines();let a=this.parseCommand();i.type===m.PIPE_AMP&&a.type==="SimpleCommand"&&a.redirections.unshift(N.redirection(">&",N.word([N.literal("1")]),2)),n.push(a)}return N.pipeline(n,r)}parseCommand(){return this.check(m.IF)?ks(this):this.check(m.FOR)?vs(this):this.check(m.WHILE)?Ns(this):this.check(m.UNTIL)?Is(this):this.check(m.CASE)?Rs(this):this.check(m.LPAREN)?$s(this):this.check(m.LBRACE)?Os(this):this.check(m.DPAREN_START)?this.parseArithmeticCommand():this.check(m.DBRACK_START)?this.parseConditionalCommand():this.check(m.FUNCTION)?this.parseFunctionDef():this.check(m.NAME,m.WORD)&&this.peek(1).type===m.LPAREN&&this.peek(2).type===m.RPAREN?this.parseFunctionDef():zc(this)}isWord(){let e=this.current().type;return e===m.WORD||e===m.NAME||e===m.NUMBER||e===m.IF||e===m.FOR||e===m.WHILE||e===m.UNTIL||e===m.CASE||e===m.FUNCTION||e===m.ELSE||e===m.ELIF||e===m.FI||e===m.THEN||e===m.DO||e===m.DONE||e===m.ESAC||e===m.IN||e===m.BANG}parseWord(){let e=this.advance();return this.parseWordFromString(e.value,e.quoted,e.singleQuoted)}parseWordFromString(e,r=!1,n=!1,s=!1,i=!1){let a=rt(this,e,r,n,s,i);return N.word(a)}parseCommandSubstitution(e,r){let n=r+2,s=1,i=n,a=!1,o=!1,l=0,c=!1,u="";for(;i<e.length&&s>0;){let p=e[i];a?p==="'"&&(a=!1):o?p==="\\"&&i+1<e.length?i++:p==='"'&&(o=!1):p==="'"?(a=!0,u=""):p==='"'?(o=!0,u=""):p==="\\"&&i+1<e.length?(i++,u=""):/[a-zA-Z_]/.test(p)?u+=p:(u==="case"?(l++,c=!1):u==="in"&&l>0?c=!0:u==="esac"&&l>0&&(l--,c=!1),u="",p==="("?i>0&&e[i-1]==="$"?s++:c||s++:p===")"?c?c=!1:s--:p===";"&&l>0&&i+1<e.length&&e[i+1]===";"&&(c=!0)),s>0&&i++}s>0&&this.error("unexpected EOF while looking for matching `)'");let f=e.slice(n,i),h=new t().parse(f);return{part:N.commandSubstitution(h,!1),endIndex:i+1}}parseBacktickSubstitution(e,r,n=!1){let i=r+1,a="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let c=e[i+1];c==="$"||c==="`"||c==="\\"||c===`
|
|
502
|
+
`||n&&c==='"'?(c!==`
|
|
503
|
+
`&&(a+=c),i+=2):(a+=e[i],i++)}else a+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let l=new t().parse(a);return{part:N.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,r){let n=r+3,s=1,i=0,a=n;for(;a<e.length-1&&s>0;)e[a]==="$"&&e[a+1]==="("?e[a+2]==="("?(s++,a+=3):(i++,a+=2):e[a]==="("&&e[a+1]==="("?(s++,a+=2):e[a]===")"&&e[a+1]===")"?i>0?(i--,a++):(s--,s>0&&(a+=2)):e[a]==="("?(i++,a++):(e[a]===")"&&i>0&&i--,a++);let o=e.slice(n,a),l=this.parseArithmeticExpression(o);return{part:N.arithmeticExpansion(l),endIndex:a+2}}parseArithmeticCommand(){this.expect(m.DPAREN_START);let e="",r=1,n=0,s=!1,i=!1;for(;r>0&&!this.check(m.EOF);){if(s){if(s=!1,n>0){n--,e+=")";continue}if(this.check(m.RPAREN)){r--,i=!0,this.advance();continue}if(this.check(m.DPAREN_END)){r--,i=!0;continue}e+=")";continue}this.check(m.DPAREN_START)?(r++,e+="((",this.advance()):this.check(m.DPAREN_END)?n>=2?(n-=2,e+="))",this.advance()):n===1?(n--,e+=")",s=!0,this.advance()):(r--,i=!0,r>0&&(e+="))"),this.advance()):this.check(m.LPAREN)?(n++,e+="(",this.advance()):this.check(m.RPAREN)?(n>0&&n--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(m.DPAREN_END);let a=this.parseArithmeticExpression(e.trim()),o=this.parseOptionalRedirections();return N.arithmeticCommand(a,o)}parseConditionalCommand(){this.expect(m.DBRACK_START);let e=Fs(this);this.expect(m.DBRACK_END);let r=this.parseOptionalRedirections();return N.conditionalCommand(e,r)}parseFunctionDef(){let e;this.check(m.FUNCTION)?(this.advance(),e=this.expect(m.NAME,"Expected function name").value,this.check(m.LPAREN)&&(this.advance(),this.expect(m.RPAREN))):(e=this.advance().value,this.expect(m.LPAREN),this.expect(m.RPAREN)),this.skipNewlines();let r=this.parseCompoundCommandBody(),n=this.parseOptionalRedirections();return N.functionDef(e,r,n)}parseCompoundCommandBody(){if(this.check(m.LBRACE))return Os(this);if(this.check(m.LPAREN))return $s(this);if(this.check(m.IF))return ks(this);if(this.check(m.FOR))return vs(this);if(this.check(m.WHILE))return Ns(this);if(this.check(m.UNTIL))return Is(this);if(this.check(m.CASE))return Rs(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(m.EOF,m.FI,m.ELSE,m.ELIF,m.THEN,m.DO,m.DONE,m.ESAC,m.RPAREN,m.RBRACE,m.DSEMI,m.SEMI_AND,m.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,n=this.parseStatement();if(n&&e.push(n),this.skipSeparators(),this.pos===r&&!n)break}return e}parseOptionalRedirections(){let e=[];for(;Qr(this);){this.checkIterationLimit();let r=this.pos;if(e.push(Xr(this)),this.pos===r)break}return e}parseArithmeticExpression(e){return le(this,e)}};function nt(t){return new he().parse(t)}J();var _t=class{fs;cwd;constructor(e,r){this.fs=e,this.cwd=r}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,r){let n=[];for(let s=0;s<e.length;s++){let i=e[s];if((r?.[s]??!1)||!this.isGlobPattern(i))n.push(i);else{let o=await this.expand(i);o.length>0?n.push(...o):n.push(i)}}return n}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}async expandSimple(e){let r=[],n=e.lastIndexOf("/"),s,i;n===-1?(s=this.cwd,i=e):(s=e.slice(0,n)||"/",i=e.slice(n+1));let a=this.fs.resolvePath(this.cwd,s);try{let o=await this.fs.readdir(a);for(let l of o)if(this.matchPattern(l,i)){let c=n===-1?l:`${s}/${l}`;r.push(c)}}catch{}return r.sort()}async expandRecursive(e){let r=[],n=e.indexOf("**"),s=e.slice(0,n).replace(/\/$/,"")||".",a=e.slice(n+2).replace(/^\//,"");return await this.walkDirectory(s,a,r),r.sort()}async walkDirectory(e,r,n){let s=this.fs.resolvePath(this.cwd,e);try{let i=await this.fs.readdir(s);for(let a of i){let o=e==="."?a:`${e}/${a}`,l=this.fs.resolvePath(this.cwd,o);try{(await this.fs.stat(l)).isDirectory?await this.walkDirectory(o,r,n):r&&this.matchPattern(a,r)&&n.push(o)}catch{}}}catch{}}matchPattern(e,r){return this.patternToRegex(r).test(e)}patternToRegex(e){let r="^";for(let n=0;n<e.length;n++){let s=e[n];if(s==="*")r+=".*";else if(s==="?")r+=".";else if(s==="["){let i=n+1,a="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(a+="^",i++),i<e.length&&e[i]==="]"&&(a+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){let l=e.slice(i+2,o),c=this.posixClassToRegex(l);a+=c,i=o+2;continue}}if(e[i]==="\\"&&i+1<e.length){a+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?a+="\\-":a+=e[i],i++}a+="]",r+=a,n=i}else if(s==="\\"&&n+1<e.length){let i=e[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(s)?r+=`\\${s}`:r+=s}return r+="$",new RegExp(r)}posixClassToRegex(e){return{alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:" \\t\\n\\r\\f\\v",upper:"A-Z",word:"a-zA-Z0-9_",xdigit:"0-9a-fA-F"}[e]||""}};J();function Oe(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Oe(t.expression);case"ArithBinary":return Oe(t.left)||Oe(t.right);case"ArithUnary":return Oe(t.operand);case"ArithTernary":return Oe(t.condition)||Oe(t.consequent)||Oe(t.alternate);case"ArithAssignment":return Oe(t.value);case"ArithGroup":return Oe(t.expression);case"ArithArrayElement":return t.index?Oe(t.index):!1;case"ArithConcat":return t.parts.some(Oe);default:return!1}}function Ds(t){let e=t.operation;return e?!!("word"in e&&e.word&&Qe(e.word)||e.type==="PatternReplacement"&&(e.pattern&&Qe(e.pattern)||e.replacement&&Qe(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&Qe(e.pattern)):!1}function Kr(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Oe(t.expression.expression);case"DoubleQuoted":return t.parts.some(Kr);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&Qe(e.word));case"ParameterExpansion":return Ds(t);default:return!1}}function Qe(t){return t.parts.some(Kr)}function Ls(t){if(!t.operation)return!1;let e=t.operation,r;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(r=e.word?.parts),!r)return!1;for(let n of r)if(n.type==="DoubleQuoted"||n.type==="SingleQuoted")return!0;return!1}function jc(t){let e=!1,r=!1,n=!1,s=!1,i=!1;for(let a of t){if((a.type==="SingleQuoted"||a.type==="DoubleQuoted")&&(e=!0,a.type==="DoubleQuoted"))for(let o of a.parts)o.type==="ParameterExpansion"&&o.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!o.operation&&(s=!0);a.type==="CommandSubstitution"&&(r=!0),a.type==="ParameterExpansion"&&(i=!0,(a.parameter==="@"||a.parameter==="*")&&(n=!0),Ls(a)&&(e=!0))}return{hasQuoted:e,hasCommandSub:r,hasArrayVar:n,hasArrayAtExpansion:s,hasParamExpansion:i}}function c0(t,e,r,n,s){let i=r??1;i===0&&(i=1);let a=Math.abs(i),o=[],l=0;n?.match(/^-?0\d/)&&(l=Math.max(l,n.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(l=Math.max(l,s.replace(/^-/,"").length));let c=u=>{if(l>0){let f=u<0,d=String(Math.abs(u)).padStart(l,"0");return f?`-${d}`:d}return String(u)};if(t<=e)for(let u=t,f=0;u<=e&&f<1e4;u+=a,f++)o.push(c(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=a,f++)o.push(c(u));return o}function u0(t,e,r){let n=r??1;n===0&&(n=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),a=Math.abs(n),o=t>="A"&&t<="Z",l=t>="a"&&t<="z",c=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(o&&u||l&&c)return null;let f=[];if(s<=i)for(let d=s,h=0;d<=i&&h<1e4;d+=a,h++)f.push(String.fromCharCode(d));else for(let d=s,h=0;d>=i&&h<1e4;d-=a,h++)f.push(String.fromCharCode(d));return f}function rr(t,e,r,n,s){let i=r!==void 0?`..${r}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:c0(t,e,r,n,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:u0(t,e,r),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function ke(t,e){let r="",n=0;for(;n<t.length;){let s=t[n];if(s==="\\")if(n+1<t.length){let i=t[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?r+=`\\${i}`:r+=i,n+=2}else r+="\\\\",n++;else if(s==="*")r+=e?".*":".*?",n++;else if(s==="?")r+=".",n++;else if(s==="["){let i=f0(t,n);if(i===-1)r+="\\[",n++;else{let a=t.slice(n+1,i);r+=d0(a),n=i+1}}else/[\^$.|+(){}]/.test(s)?(r+=`\\${s}`,n++):(r+=s,n++)}return r}function f0(t,e){let r=e+1;for(r<t.length&&t[r]==="^"&&r++,r<t.length&&t[r]==="]"&&r++;r<t.length;){if(t[r]==="\\"&&r+1<t.length){r+=2;continue}if(t[r]==="]")return r;if(t[r]==="'"){let n=t.indexOf("'",r+1);if(n!==-1){r=n+1;continue}}if(t[r]==="["&&r+1<t.length&&t[r+1]===":"){let n=t.indexOf(":]",r+2);if(n!==-1){r=n+2;continue}}r++}return-1}function d0(t){let e="[",r=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",r++);r<t.length;){if(t[r]==="'"){let s=t.indexOf("'",r+1);if(s!==-1){let i=t.slice(r+1,s);for(let a of i)a==="\\"?e+="\\\\":a==="]"?e+="\\]":a==="^"&&e==="["?e+="\\^":e+=a;r=s+1;continue}}if(t[r]==="["&&r+1<t.length&&t[r+1]===":"){let s=t.indexOf(":]",r+2);if(s!==-1){let i=t.slice(r+2,s);e+=p0(i),r=s+2;continue}}let n=t[r];n==="\\"?r+1<t.length?(e+=`\\${t[r+1]}`,r+=2):(e+="\\\\",r++):n==="-"&&r>0&&r<t.length-1?(e+="-",r++):n==="^"&&r===0?(e+="^",r++):(n==="]"&&r===0?e+="\\]":e+=n,r++)}return e+="]",e}var h0={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:" \\t\\n\\r\\f\\v",upper:"A-Z",word:"a-zA-Z0-9_",xdigit:"0-9A-Fa-f"};function p0(t){return h0[t]??""}J();function nr(t,e){let r=`${e}_`,n=[];for(let s of Object.keys(t.state.env))if(s.startsWith(r)){let i=s.slice(r.length),a=Number.parseInt(i,10);!Number.isNaN(a)&&String(a)===i&&n.push(a)}return n.sort((s,i)=>s-i)}function Ms(t,e){let r=`${e}_`;for(let n of Object.keys(t.state.env))n.startsWith(r)&&delete t.state.env[n]}function _s(t,e){let r=`${e}_`,n=[];for(let s of Object.keys(t.state.env))if(s.startsWith(r)&&!s.includes("__")){let i=s.slice(r.length);n.push(i)}return n.sort()}function Gc(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Jr(t){return t.IFS??`
|
|
504
|
+
`}function qc(t){return t.IFS===""}function sr(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
|
|
505
|
+
`?"\\n":e).join("")}function m0(t,e){let r=sr(t);return new RegExp(`[${r}]+`,e)}function g0(t){let e=sr(t);return new RegExp(`^[${e}]+`)}function x0(t){let e=sr(t);return new RegExp(`[${e}]+$`)}function ir(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function Vc(t,e){if(e==="")return{words:[t],wordStarts:[0]};let r=[],n=[],s=m0(e,"g"),i=0,a=t.match(g0(e));a&&(i=a[0].length),s.lastIndex=i;let o=s.exec(t);for(;o!==null;)o.index>i&&(n.push(i),r.push(t.substring(i,o.index))),i=s.lastIndex,o=s.exec(t);return i<t.length&&(n.push(i),r.push(t.substring(i))),{words:r,wordStarts:n}}function Zc(t,e){return e===""?t:t.replace(x0(e),"")}function ce(t,e){return t.state.associativeArrays?.has(e)?_s(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):nr(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function Qc(t,e){return t.state.associativeArrays?.has(e)?_s(t,e).length>0:nr(t,e).length>0}function Pe(t,e,r=!0,n=!1){switch(e){case"?":return String(t.state.lastExitCode);case"$":return String(process.pid);case"#":return t.state.env["#"]||"0";case"@":return t.state.env["@"]||"";case"_":return t.state.lastArg;case"-":{let a="";return t.state.options.errexit&&(a+="e"),t.state.options.nounset&&(a+="u"),t.state.options.verbose&&(a+="v"),t.state.options.xtrace&&(a+="x"),t.state.options.pipefail&&(a+="p"),a}case"*":{let a=Number.parseInt(t.state.env["#"]||"0",10);if(a===0)return"";let o=[];for(let l=1;l<=a;l++)o.push(t.state.env[String(l)]||"");return o.join(ir(t.state.env))}case"0":return t.state.env[0]||"bash";case"PWD":return t.state.env.PWD!==void 0?t.state.env.PWD:"";case"OLDPWD":return t.state.env.OLDPWD!==void 0?t.state.env.OLDPWD:""}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(e))throw new qe(`\${${e}}`);let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let a=s[1],o=s[2];if(o==="@"||o==="*"){let f=ce(t,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=t.state.env[a];return d!==void 0?d:""}if(t.state.associativeArrays?.has(a)){let f=Gc(o),d=t.state.env[`${a}_${f}`];if(d===void 0&&r&&t.state.options.nounset)throw new $e(`${a}[${o}]`);return d||""}let c;if(/^-?\d+$/.test(o))c=Number.parseInt(o,10);else try{let f=new he,d=le(f,o);c=V(t,d.expression)}catch{let f=t.state.env[o];c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=ce(t,a);if(f.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${a}: bad array subscript
|
|
506
|
+
`,"";let h=Math.max(...f.map(([w])=>typeof w=="number"?w:0))+1+c;return h<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${a}: bad array subscript
|
|
507
|
+
`,""):t.state.env[`${a}_${h}`]||""}let u=t.state.env[`${a}_${c}`];if(u===void 0&&r&&t.state.options.nounset)throw new $e(`${a}[${c}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let a=t.state.env[e];if(a===void 0&&r&&t.state.options.nounset)throw new $e(e);return a||""}let i=t.state.env[e];if(i===void 0&&r&&t.state.options.nounset)throw new $e(e);return i||""}async function Xc(t,e,r,n,s){let i=[];for(let u of e){let f=u.type==="ParameterExpansion"||u.type==="CommandSubstitution"||u.type==="ArithmeticExpansion";if(u.type==="ParameterExpansion"&&Ls(u)){let d=await s(t,u);i.push({value:d,splittable:!1})}else{let d=await s(t,u);i.push({value:d,splittable:f})}}if(!i.some(u=>u.splittable&&new RegExp(`[${n}]`).test(u.value))){let u=i.map(f=>f.value).join("");return u?[u]:[]}let o=new RegExp(`[${n}]+`),l=[],c="";for(let u=0;u<i.length;u++){let f=i[u];if(!f.splittable)c+=f.value;else{let d=f.value.split(o);for(let h=0;h<d.length;h++)h===0?c+=d[h]:(c!==""&&l.push(c),c=d[h])}}return c!==""&&l.push(c),l}function ve(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Kc(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function Jc(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Bs(t){if(t==="")return"''";if(!/['\\\n\r\t\x00-\x1f\x7f]/.test(t))return`'${t}'`;let e="$'";for(let r of t)switch(r){case"'":e+="\\'";break;case"\\":e+="\\\\";break;case`
|
|
508
|
+
`:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let n=r.charCodeAt(0);n<32||n===127?e+=`\\x${n.toString(16).padStart(2,"0")}`:e+=r}}return`${e}'`}function xt(t,e,r=!1){return e.map(n=>Xe(t,n,r)).join("")}async function yt(t,e,r=!1){let n=[];for(let s of e)n.push(await Ge(t,s));return n.join("")}function y0(t){return Jc(t)}function Yc(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!y0(e))return!1;return!0}function eu(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function tu(t,e,r=!1){let n=Kc(e);if(n!==null)return n;switch(e.type){case"ParameterExpansion":return au(t,e,r);case"TildeExpansion":return r?e.user===null?"~":`~${e.user}`:e.user===null?t.state.env.HOME||"/home/user":e.user==="root"?"/root":`~${e.user}`;case"Glob":return e.pattern;default:return null}}function Xe(t,e,r=!1){let n=tu(t,e,r);if(n!==null)return n;switch(e.type){case"DoubleQuoted":{let s=[];for(let i of e.parts)s.push(Xe(t,i,!0));return s.join("")}case"ArithmeticExpansion":return String(V(t,e.expression.expression));case"BraceExpansion":{let s=[];for(let i of e.items)if(i.type==="Range"){let a=rr(i.start,i.end,i.step,i.startStr,i.endStr);if(a.expanded)s.push(...a.expanded);else return a.literal}else s.push(Yr(t,i.word));return s.join(" ")}default:return""}}function Yr(t,e){let r=e.parts,n=r.length;if(n===1)return Xe(t,r[0]);let s=[];for(let i=0;i<n;i++)s.push(Xe(t,r[i]));return s.join("")}async function K(t,e){return Qe(e)?iu(t,e):Yr(t,e)}function en(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&en(e.parts))return!0;return!1}function w0(t){for(let e of t){if(e.type==="BraceExpansion"){for(let r of e.items)if(r.type==="Word"&&Qe(r.word))return!0}if(Kr(e))return!0}return!1}var ru=1e4,Bt=1e5;function nu(t,e,r={count:0}){if(r.count>Bt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],a=!1,o="";for(let u of s.items)if(u.type==="Range"){let f=rr(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let d of f.expanded)r.count++,i.push(d);else{a=!0,o=f.literal;break}}else{let f=nu(t,u.word.parts,r);for(let d of f)r.count++,i.push(d.join(""))}if(a){for(let u of n)r.count++,u.push(o);continue}if(n.length*i.length>ru||r.count>Bt)return n;let c=[];for(let u of n)for(let f of i){if(r.count++,r.count>Bt)return c.length>0?c:n;c.push([...u,f])}n=c}else{let i=Xe(t,s);for(let a of n)r.count++,a.push(i)}return n}function E0(t,e){let r=e.parts;return en(r)?nu(t,r).map(s=>s.join("")):[Yr(t,e)]}async function su(t,e,r={count:0}){if(r.count>Bt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],a=!1,o="";for(let u of s.items)if(u.type==="Range"){let f=rr(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let d of f.expanded)r.count++,i.push(d);else{a=!0,o=f.literal;break}}else{let f=await su(t,u.word.parts,r);for(let d of f)r.count++,i.push(d.join(""))}if(a){for(let u of n)r.count++,u.push(o);continue}if(n.length*i.length>ru||r.count>Bt)return n;let c=[];for(let u of n)for(let f of i){if(r.count++,r.count>Bt)return c.length>0?c:n;c.push([...u,f])}n=c}else{let i=await Ge(t,s);for(let a of n)r.count++,a.push(i)}return n}async function b0(t,e){let r=e.parts;return en(r)?(await su(t,r)).map(s=>s.join("")):[await K(t,e)]}async function ar(t,e){let r=e.parts,{hasQuoted:n,hasCommandSub:s,hasArrayVar:i,hasArrayAtExpansion:a,hasParamExpansion:o}=jc(r),c=en(r)?w0(r)?await b0(t,e):E0(t,e):null;if(c&&c.length>1){let d=[];for(let h of c)if(!n&&/[*?[]/.test(h)){let w=await new _t(t.fs,t.state.cwd).expand(h);w.length>0?d.push(...w):d.push(h)}else d.push(h);return{values:d,quoted:!1}}if(a&&r.length===1&&r[0].type==="DoubleQuoted"){let d=r[0];if(d.parts.length===1&&d.parts[0].type==="ParameterExpansion"){let p=d.parts[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@]\]$/);if(p){let w=p[1],x=ce(t,w);if(x.length>0)return{values:x.map(([,E])=>E),quoted:!0};let y=t.state.env[w];return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}}}if(!n&&i&&r.length===1&&r[0].type==="ParameterExpansion"){let d=r[0].parameter;if(d==="@"||d==="*"){let h=Number.parseInt(t.state.env["#"]||"0",10);if(h===0)return{values:[],quoted:!1};let p=[];for(let w=1;w<=h;w++)p.push(t.state.env[String(w)]||"");return{values:p,quoted:!1}}}if(!n&&(s||i||o)&&!qc(t.state.env)){let d=Jr(t.state.env),h=sr(d),p=await Xc(t,r,d,h,Ge),w=[],x=new _t(t.fs,t.state.cwd);for(let y of p)if(/[*?[]/.test(y)){let E=await x.expand(y);E.length>0?w.push(...E):w.push(y)}else w.push(y);return{values:w,quoted:!1}}let f=Qe(e)?await iu(t,e):Yr(t,e);if(!n&&/[*?[]/.test(f)){let h=await new _t(t.fs,t.state.cwd).expand(f);if(h.length>0)return{values:h,quoted:!1}}return f===""&&!n?{values:[],quoted:!1}:{values:[f],quoted:n}}async function iu(t,e){let r=e.parts,n=r.length;if(n===1)return Ge(t,r[0]);let s=[];for(let i=0;i<n;i++)s.push(await Ge(t,r[i]));return s.join("")}async function Ge(t,e){if(e.type==="ParameterExpansion"&&Ds(e))return S0(t,e);let r=tu(t,e);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let n=[];for(let s of e.parts)n.push(await Ge(t,s));return n.join("")}case"CommandSubstitution":try{let n=await t.executeScript(e.body);return t.state.lastExitCode=n.exitCode,t.state.env["?"]=String(n.exitCode),n.stdout.replace(/\n+$/,"")}catch(n){if(n instanceof z)throw n;if(n instanceof X)return t.state.lastExitCode=n.exitCode,t.state.env["?"]=String(n.exitCode),n.stdout.replace(/\n+$/,"");throw n}case"ArithmeticExpansion":return String(await Z(t,e.expression.expression));case"BraceExpansion":{let n=[];for(let s of e.items)if(s.type==="Range"){let i=rr(s.start,s.end,s.step,s.startStr,s.endStr);if(i.expanded)n.push(...i.expanded);else return i.literal}else n.push(await K(t,s.word));return n.join(" ")}default:return""}}function au(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=Pe(t,n,!i);if(!s)return a;let o=!(n in t.state.env),l=a==="";switch(s.type){case"DefaultValue":return(o||s.checkEmpty&&l)&&s.word?xt(t,s.word.parts,r):a;case"AssignDefault":{if((o||s.checkEmpty&&l)&&s.word){let u=xt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,d,h]=f,p;if(/^\d+$/.test(h))p=Number.parseInt(h,10);else{try{let x=new he,y=le(x,h);p=V(t,y.expression)}catch{let x=t.state.env[h];p=x?Number.parseInt(x,10):0}Number.isNaN(p)&&(p=0)}t.state.env[`${d}_${p}`]=u;let w=Number.parseInt(t.state.env[`${d}__length`]||"0",10);p>=w&&(t.state.env[`${d}__length`]=String(p+1))}else t.state.env[n]=u;return u}return a}case"ErrorIfUnset":{if(o||s.checkEmpty&&l){let u=s.word?xt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
|
|
509
|
+
`)}return a}case"UseAlternative":return!(o||s.checkEmpty&&l)&&s.word?xt(t,s.word.parts,r):"";case"Length":{let c=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(c){let u=ce(t,c[1]);return String(u.length)}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Qc(t,n)){let u=t.state.env[`${n}_0`]||"";return String(u.length)}return String(a.length)}case"LengthSliceError":throw new qe(n);case"Substring":{let c=s.offset?V(t,s.offset.expression):0,u=s.length?V(t,s.length.expression):void 0;if(n==="@"||n==="*"){let p=(t.state.env["@"]||"").split(" ").filter(E=>E),w=t.state.env[0]||"bash",x=c===0?[w,...p]:p,y=c===0?0:c-1;if(y<0||y>=x.length)return"";if(u!==void 0){let E=u<0?x.length+u:y+u;return x.slice(y,Math.max(y,E)).join(" ")}return x.slice(y).join(" ")}let f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(f){let w=ce(t,f[1]).map(([,y])=>y),x=c;if(x<0&&(x=w.length+x,x<0))return"";if(u!==void 0){if(u<0){let y=w.length+u;return w.slice(x,Math.max(x,y)).join(" ")}return w.slice(x,x+u).join(" ")}return w.slice(x).join(" ")}let d=[...a],h=c;if(h<0&&(h=Math.max(0,d.length+h)),u!==void 0){if(u<0){let p=d.length+u;return d.slice(h,Math.max(h,p)).join("")}return d.slice(h,h+u).join("")}return d.slice(h).join("")}case"PatternRemoval":{let c="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")c+=ke(f.pattern,s.greedy);else if(f.type==="Literal")c+=ke(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")c+=ve(f.value);else if(f.type==="DoubleQuoted"){let d=xt(t,f.parts);c+=ve(d)}else if(f.type==="ParameterExpansion"){let d=Xe(t,f);c+=ke(d,s.greedy)}else{let d=Xe(t,f);c+=ve(d)}if(s.side==="prefix")return a.replace(new RegExp(`^${c}`),"");let u=new RegExp(`${c}$`);if(s.greedy)return a.replace(u,"");for(let f=a.length;f>=0;f--){let d=a.slice(f);if(u.test(d))return a.slice(0,f)}return a}case"PatternReplacement":{let c="";if(s.pattern)for(let d of s.pattern.parts)if(d.type==="Glob")c+=ke(d.pattern,!0);else if(d.type==="Literal")c+=ke(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")c+=ve(d.value);else if(d.type==="DoubleQuoted"){let h=xt(t,d.parts);c+=ve(h)}else if(d.type==="ParameterExpansion"){let h=Xe(t,d);c+=ke(h,!0)}else{let h=Xe(t,d);c+=ve(h)}let u=s.replacement?xt(t,s.replacement.parts):"";if(c==="")return a;s.anchor==="start"?c=`^${c}`:s.anchor==="end"&&(c=`${c}$`);let f=s.all?"g":"";try{let d=new RegExp(c,f);if(s.all){let h="",p=0,w=d.exec(a);for(;w!==null&&!(w[0].length===0&&w.index===a.length);)h+=a.slice(p,w.index)+u,p=w.index+w[0].length,w[0].length===0&&p++,w=d.exec(a);return h+=a.slice(p),h}return a.replace(d,u)}catch{return a}}case"CaseModification":return s.direction==="upper"?s.all?a.toUpperCase():a.charAt(0).toUpperCase()+a.slice(1):s.all?a.toLowerCase():a.charAt(0).toLowerCase()+a.slice(1);case"Transform":{let c=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(c&&s.operator==="Q")return ce(t,c[1]).map(([,d])=>Bs(d)).join(" ");switch(s.operator){case"Q":return Bs(a);case"P":return a;case"a":return"";case"A":return`${n}=${Bs(a)}`;case"E":return a.replace(/\\([\\abefnrtv'"?])/g,(u,f)=>{switch(f){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
|
|
510
|
+
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return f}});case"K":return"";default:return a}}case"Indirection":return Pe(t,a);case"ArrayKeys":{let u=ce(t,s.array).map(([f])=>String(f));return s.star?u.join(ir(t.state.env)):u.join(" ")}case"VarNamePrefix":{let c=Object.keys(t.state.env).filter(u=>u.startsWith(s.prefix)&&!u.includes("__")).sort();return s.star?c.join(ir(t.state.env)):c.join(" ")}default:return a}}async function S0(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=Pe(t,n,!i);if(!s)return a;let o=!(n in t.state.env),l=a==="";switch(s.type){case"DefaultValue":return(o||s.checkEmpty&&l)&&s.word?yt(t,s.word.parts,r):a;case"AssignDefault":{if((o||s.checkEmpty&&l)&&s.word){let u=await yt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,d,h]=f,p;if(/^\d+$/.test(h))p=Number.parseInt(h,10);else{try{let x=new he,y=le(x,h);p=await Z(t,y.expression)}catch{let x=t.state.env[h];p=x?Number.parseInt(x,10):0}Number.isNaN(p)&&(p=0)}t.state.env[`${d}_${p}`]=u;let w=Number.parseInt(t.state.env[`${d}__length`]||"0",10);p>=w&&(t.state.env[`${d}__length`]=String(p+1))}else t.state.env[n]=u;return u}return a}case"ErrorIfUnset":{if(o||s.checkEmpty&&l){let u=s.word?await yt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
|
|
511
|
+
`)}return a}case"UseAlternative":return!(o||s.checkEmpty&&l)&&s.word?yt(t,s.word.parts,r):"";case"PatternRemoval":{let c="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")c+=ke(f.pattern,s.greedy);else if(f.type==="Literal")c+=ke(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")c+=ve(f.value);else if(f.type==="DoubleQuoted"){let d=await yt(t,f.parts);c+=ve(d)}else if(f.type==="ParameterExpansion"){let d=await Ge(t,f);c+=ke(d,s.greedy)}else{let d=await Ge(t,f);c+=ve(d)}if(s.side==="prefix")return a.replace(new RegExp(`^${c}`),"");let u=new RegExp(`${c}$`);if(s.greedy)return a.replace(u,"");for(let f=a.length;f>=0;f--){let d=a.slice(f);if(u.test(d))return a.slice(0,f)}return a}case"PatternReplacement":{let c="";if(s.pattern)for(let d of s.pattern.parts)if(d.type==="Glob")c+=ke(d.pattern,!0);else if(d.type==="Literal")c+=ke(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")c+=ve(d.value);else if(d.type==="DoubleQuoted"){let h=await yt(t,d.parts);c+=ve(h)}else if(d.type==="ParameterExpansion"){let h=await Ge(t,d);c+=ke(h,!0)}else{let h=await Ge(t,d);c+=ve(h)}let u=s.replacement?await yt(t,s.replacement.parts):"";if(c==="")return a;s.anchor==="start"?c=`^${c}`:s.anchor==="end"&&(c=`${c}$`);let f=s.all?"g":"";try{let d=new RegExp(c,f);if(s.all){let h="",p=0,w=d.exec(a);for(;w!==null&&!(w[0].length===0&&w.index===a.length);)h+=a.slice(p,w.index)+u,p=w.index+w[0].length,w[0].length===0&&p++,w=d.exec(a);return h+=a.slice(p),h}return a.replace(d,u)}catch{return a}}default:return au(t,e,r)}}function Ws(t,e,r){switch(r){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":return e!==0?Math.trunc(t/e):0;case"%":return e!==0?t%e:0;case"**":if(e<0)throw new ae("exponent less than 0");return t**e;case"<<":return t<<e;case">>":return t>>e;case"<":return t<e?1:0;case"<=":return t<=e?1:0;case">":return t>e?1:0;case">=":return t>=e?1:0;case"==":return t===e?1:0;case"!=":return t!==e?1:0;case"&":return t&e;case"|":return t|e;case"^":return t^e;case",":return e;default:return 0}}function ou(t,e,r){switch(r){case"=":return e;case"+=":return t+e;case"-=":return t-e;case"*=":return t*e;case"/=":return e!==0?Math.trunc(t/e):0;case"%=":return e!==0?t%e:0;case"<<=":return t<<e;case">>=":return t>>e;case"&=":return t&e;case"|=":return t|e;case"^=":return t^e;default:return e}}function Us(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function C0(t,e){let r=t.state.env[e];if(r!==void 0)return r;let n=t.state.env[`${e}_0`];return n!==void 0?n:Pe(t,e)}function Wt(t){if(!t)return 0;let e=Number.parseInt(t,10);if(!Number.isNaN(e)&&/^-?\d+$/.test(t.trim()))return e;let r=t.trim();if(!r)return 0;try{let n=new he,{expr:s,pos:i}=Ve(n,r,0);if(i<r.length){let a=r.slice(i).trim().split(/\s+/)[0];throw new ae(`${r}: syntax error in expression (error token is "${a}")`)}return s.type==="ArithNumber"?s.value:e||0}catch(n){if(n instanceof ae)throw n;let s=r.split(/\s+/).slice(1)[0]||r;throw new ae(`${r}: syntax error in expression (error token is "${s}")`)}}function tn(t,e,r=new Set){if(r.has(e))return 0;r.add(e);let n=C0(t,e);if(!n)return 0;let s=Number.parseInt(n,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(n.trim()))return s;let i=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return tn(t,i,r);try{let a=new he,{expr:o}=Ve(a,i,0);return Fe(t,o,r)}catch{return 0}}function Fe(t,e,r){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ae("value too great for base");return e.value;case"ArithVariable":return tn(t,e.name,r);case"ArithBinary":{if(e.operator==="||")return Fe(t,e.left,r)||Fe(t,e.right,r)?1:0;if(e.operator==="&&")return Fe(t,e.left,r)&&Fe(t,e.right,r)?1:0;let n=Fe(t,e.left,r),s=Fe(t,e.right,r);return Ws(n,s,e.operator)}case"ArithUnary":{let n=Fe(t,e.operand,r);return Us(n,e.operator)}case"ArithTernary":return Fe(t,e.condition,r)?Fe(t,e.consequent,r):Fe(t,e.alternate,r);case"ArithGroup":return Fe(t,e.expression,r);default:return V(t,e)}}function st(t,e){if(e.startsWith("#")){let f=e.slice(1),d=t.state.env[f]||"";return String(d.length)}if(e.startsWith("!")){let f=e.slice(1),d=t.state.env[f]||"";return t.state.env[d]||""}let r=[":-",":=",":?",":+","-","=","?","+"],n=-1,s="";for(let f of r){let d=e.indexOf(f);d>0&&(n===-1||d<n)&&(n=d,s=f)}if(n===-1)return Pe(t,e);let i=e.slice(0,n),a=e.slice(n+s.length),o=t.state.env[i],l=o===void 0,c=o==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?a:o||"";case":=":case"=":return l||u&&c?(t.state.env[i]=a,a):o||"";case":+":case"+":return!(l||u&&c)?a:"";case":?":case"?":{if(l||u&&c)throw new Error(a||`${i}: parameter null or not set`);return o||""}default:return o||""}}function V(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ae("value too great for base");return e.value;case"ArithVariable":return tn(t,e.name);case"ArithNested":return V(t,e.expression);case"ArithCommandSubst":return 0;case"ArithBracedExpansion":{let r=st(t,e.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=st(t,e.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let s=`${n}#${e.value}`;return Mt(s)}case"ArithDynamicNumber":{let n=st(t,e.prefix)+e.suffix;return Mt(n)}case"ArithArrayElement":{let r=t.state.associativeArrays?.has(e.array),n;if(e.stringKey!==void 0)n=`${e.array}_${e.stringKey}`;else if(r&&e.index?.type==="ArithVariable")n=`${e.array}_${e.index.name}`;else if(e.index){let i=V(t,e.index);if(i<0){let o=ce(t,e.array);if(o.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
|
|
512
|
+
`,0;let c=Math.max(...o.map(([u])=>typeof u=="number"?u:0))+1+i;if(c<0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
|
|
513
|
+
`,0;i=c}n=`${e.array}_${i}`;let a=t.state.env[n];if(a!==void 0)return Wt(a);if(i===0){let o=t.state.env[e.array];if(o!==void 0)return Wt(o)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new $e(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[n];return s!==void 0?Wt(s):0}case"ArithDoubleSubscript":throw new ae("double subscript","","");case"ArithNumberSubscript":throw new ae(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return V(t,e.left)||V(t,e.right)?1:0;if(e.operator==="&&")return V(t,e.left)&&V(t,e.right)?1:0;let r=V(t,e.left),n=V(t,e.right);return Ws(r,n,e.operator)}case"ArithUnary":{let r=V(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let n=e.operand.name,s=Number.parseInt(Pe(t,n),10)||0,i=e.operator==="++"?s+1:s-1;return t.state.env[n]=String(i),e.prefix?i:s}if(e.operand.type==="ArithArrayElement"){let n=e.operand.array,s=t.state.associativeArrays?.has(n),i;if(e.operand.stringKey!==void 0)i=`${n}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")i=`${n}_${e.operand.index.name}`;else if(e.operand.index){let l=V(t,e.operand.index);i=`${n}_${l}`}else return r;let a=Number.parseInt(t.state.env[i]||"0",10)||0,o=e.operator==="++"?a+1:a-1;return t.state.env[i]=String(o),e.prefix?o:a}return r}return Us(r,e.operator)}case"ArithTernary":return V(t,e.condition)?V(t,e.consequent):V(t,e.alternate);case"ArithAssignment":{let r=e.variable,n=r;if(e.stringKey!==void 0)n=`${r}_${e.stringKey}`;else if(e.subscript){let o=t.state.associativeArrays?.has(r);if(o&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(o){let l=V(t,e.subscript);n=`${r}_${l}`}else{let l=V(t,e.subscript);if(l<0){let c=ce(t,r);c.length>0&&(l=Math.max(...c.map(([f])=>typeof f=="number"?f:0))+1+l)}n=`${r}_${l}`}}let s=Number.parseInt(t.state.env[n]||"0",10)||0,i=V(t,e.value),a=ou(s,i,e.operator);return t.state.env[n]=String(a),a}case"ArithGroup":return V(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=lu(t,n);return Number.parseInt(r,10)||0}default:return 0}}function lu(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Pe(t,e.name);case"ArithBracedExpansion":return st(t,e.content);case"ArithCommandSubst":return"0";case"ArithConcat":{let r="";for(let n of e.parts)r+=lu(t,n);return r}default:return String(V(t,e))}}async function Z(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ae("value too great for base");return e.value;case"ArithVariable":return tn(t,e.name);case"ArithNested":return Z(t,e.expression);case"ArithCommandSubst":{if(t.execFn){let n=(await t.execFn(e.command)).stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let r=st(t,e.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=st(t,e.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let s=`${n}#${e.value}`;return Mt(s)}case"ArithDynamicNumber":{let n=st(t,e.prefix)+e.suffix;return Mt(n)}case"ArithArrayElement":{let r=t.state.associativeArrays?.has(e.array),n;if(e.stringKey!==void 0)n=`${e.array}_${e.stringKey}`;else if(r&&e.index?.type==="ArithVariable")n=`${e.array}_${e.index.name}`;else if(e.index){let i=await Z(t,e.index);n=`${e.array}_${i}`;let a=t.state.env[n];if(a!==void 0)return Wt(a);if(i===0){let o=t.state.env[e.array];if(o!==void 0)return Wt(o)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new $e(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[n];return s!==void 0?Wt(s):0}case"ArithDoubleSubscript":throw new ae("double subscript","","");case"ArithNumberSubscript":throw new ae(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return await Z(t,e.left)||await Z(t,e.right)?1:0;if(e.operator==="&&")return await Z(t,e.left)&&await Z(t,e.right)?1:0;let r=await Z(t,e.left),n=await Z(t,e.right);return Ws(r,n,e.operator)}case"ArithUnary":{let r=await Z(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let n=e.operand.name,s=Number.parseInt(Pe(t,n),10)||0,i=e.operator==="++"?s+1:s-1;return t.state.env[n]=String(i),e.prefix?i:s}if(e.operand.type==="ArithArrayElement"){let n=e.operand.array,s=t.state.associativeArrays?.has(n),i;if(e.operand.stringKey!==void 0)i=`${n}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")i=`${n}_${e.operand.index.name}`;else if(e.operand.index){let l=await Z(t,e.operand.index);i=`${n}_${l}`}else return r;let a=Number.parseInt(t.state.env[i]||"0",10)||0,o=e.operator==="++"?a+1:a-1;return t.state.env[i]=String(o),e.prefix?o:a}return r}return Us(r,e.operator)}case"ArithTernary":return await Z(t,e.condition)?await Z(t,e.consequent):await Z(t,e.alternate);case"ArithAssignment":{let r=e.variable,n=r;if(e.stringKey!==void 0)n=`${r}_${e.stringKey}`;else if(e.subscript){let o=t.state.associativeArrays?.has(r);if(o&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(o){let l=await Z(t,e.subscript);n=`${r}_${l}`}else{let l=await Z(t,e.subscript);if(l<0){let c=ce(t,r);c.length>0&&(l=Math.max(...c.map(([f])=>typeof f=="number"?f:0))+1+l)}n=`${r}_${l}`}}let s=Number.parseInt(t.state.env[n]||"0",10)||0,i=await Z(t,e.value),a=ou(s,i,e.operator);return t.state.env[n]=String(a),a}case"ArithGroup":return await Z(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=await cu(t,n);return Number.parseInt(r,10)||0}default:return 0}}async function cu(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Pe(t,e.name);case"ArithBracedExpansion":return st(t,e.content);case"ArithCommandSubst":return t.execFn?(await t.execFn(e.command)).stdout.trim():"0";case"ArithConcat":{let r="";for(let n of e.parts)r+=await cu(t,n);return r}default:return String(await Z(t,e))}}J();J();var q=Object.freeze({stdout:"",stderr:"",exitCode:0});function Ne(t=""){return{stdout:t,stderr:"",exitCode:0}}function _(t,e=1){return{stdout:"",stderr:t,exitCode:e}}function $(t,e,r){return{stdout:t,stderr:e,exitCode:r}}function oe(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function Ke(t,e,r="",n=""){throw new z(t,e,r,n)}function zs(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new ze;return q}let r=1;if(e.length>0){let n=Number.parseInt(e[0],10);if(Number.isNaN(n)||n<1)throw new X(128,"",`bash: break: ${e[0]}: numeric argument required
|
|
514
|
+
`);r=n}throw new pe(r)}async function Hs(t,e){let r,n=!1,s=!1,i=0;for(;i<e.length;)if(e[i]==="--"){i++;break}else if(e[i]==="-L")s=!1,i++;else if(e[i]==="-P")s=!0,i++;else if(e[i].startsWith("-")&&e[i]!=="-")i++;else break;let a=e.slice(i);if(a.length===0||a[0]==="~"?r=t.state.env.HOME||"/":a[0]==="-"?(r=t.state.previousDir,n=!0):r=a[0],!r.startsWith("/")&&!r.startsWith("./")&&!r.startsWith("../")&&r!=="."&&r!==".."){let f=t.state.env.CDPATH;if(f){let d=f.split(":").filter(h=>h);for(let h of d){let p=h.startsWith("/")?`${h}/${r}`:`${t.state.cwd}/${h}/${r}`;try{if((await t.fs.stat(p)).isDirectory){r=p,n=!0;break}}catch{}}}}let l=(r.startsWith("/")?r:`${t.state.cwd}/${r}`).split("/").filter(f=>f&&f!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await t.fs.stat(c)).isDirectory)return _(`bash: cd: ${r}: Not a directory
|
|
479
515
|
`)}catch{return _(`bash: cd: ${r}: No such file or directory
|
|
480
|
-
`)}}let u=
|
|
481
|
-
`:"")}
|
|
482
|
-
`);r=n}throw new ye(r)}function
|
|
483
|
-
`):null}function
|
|
484
|
-
`}}return
|
|
485
|
-
`}return
|
|
486
|
-
`)&&!n&&!s){r&&(e.push(r),r="");continue}r+=a}return r&&e.push(r),e}function
|
|
487
|
-
`)}return
|
|
516
|
+
`)}}let u=c||"/";return t.state.previousDir=t.state.cwd,t.state.cwd=u,t.state.env.PWD=t.state.cwd,t.state.env.OLDPWD=t.state.previousDir,Ne(n?`${u}
|
|
517
|
+
`:"")}J();function js(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new ze;return q}if(e.length>1)throw new pe(1);let r=1;if(e.length>0){let n=Number.parseInt(e[0],10);if(Number.isNaN(n)||n<1)return _(`bash: continue: ${e[0]}: numeric argument required
|
|
518
|
+
`);r=n}throw new ye(r)}function wt(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function A0(t,e){return t.state.readonlyVars?.has(e)??!1}function it(t,e,r="bash"){return A0(t,e)?_(`${r}: ${e}: readonly variable
|
|
519
|
+
`):null}function uu(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:Gs(e[2])};if(t.includes("=")){let r=t.indexOf("=");return{name:t.slice(0,r),isArray:!1,value:t.slice(r+1)}}return{name:t,isArray:!1}}function fu(t,e,r={}){let{name:n,isArray:s,arrayElements:i,value:a}=e,{makeReadonly:o=!1,checkReadonly:l=!0}=r;if(l){let c=it(t,n);if(c)return c}if(s&&i){for(let c=0;c<i.length;c++)t.state.env[`${n}_${c}`]=i[c];t.state.env[`${n}__length`]=String(i.length)}else a!==void 0&&(t.state.env[n]=a);return o&&wt(t,n),null}function qs(t,e){let r=!1,n=!1,s=!1,i=!1,a=!1,o=[];for(let l=0;l<e.length;l++){let c=e[l];if(c==="-a")r=!0;else if(c==="-A")n=!0;else if(c==="-r")s=!0;else if(c==="-x")i=!0;else if(c==="-p")a=!0;else if(c==="--"){o.push(...e.slice(l+1));break}else if(c.startsWith("-"))for(let u of c.slice(1))u==="a"?r=!0:u==="A"?n=!0:u==="r"?s=!0:u==="x"?i=!0:u==="p"&&(a=!0);else o.push(c)}if(a&&o.length>0){let l="";for(let c of o){let u=t.state.env[c];if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');l+=`declare -- ${c}="${f}"
|
|
520
|
+
`}}return Ne(l)}if(o.length===0&&!a){let l="",c=Object.entries(t.state.env).filter(([u])=>!u.startsWith("BASH_")).sort(([u],[f])=>u.localeCompare(f));for(let[u,f]of c){let d=f.replace(/'/g,"'\\''");l+=`declare -- ${u}='${d}'
|
|
521
|
+
`}return Ne(l)}for(let l of o){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(c){let u=c[1],f=c[2];if(n&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),n&&f.includes("[")){let d=k0(f);for(let[h,p]of d)t.state.env[`${u}_${h}`]=p}else{let d=Gs(f);for(let h=0;h<d.length;h++)t.state.env[`${u}_${h}`]=d[h];t.state.env[`${u}__length`]=String(d.length)}s&&wt(t,u);continue}if(l.includes("=")){let u=l.indexOf("="),f=l.slice(0,u),d=l.slice(u+1),h=it(t,f);if(h)return h;t.state.env[f]=d,s&&wt(t,f)}else{let u=l;n&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u));let f=Object.keys(t.state.env).some(d=>d.startsWith(`${u}_`)&&!d.startsWith(`${u}__length`));!(u in t.state.env)&&!f&&(r||n?t.state.env[`${u}__length`]="0":t.state.env[u]=""),s&&wt(t,u)}}return q}function Gs(t){let e=[],r="",n=!1,s=!1,i=!1;for(let a of t){if(i){r+=a,i=!1;continue}if(a==="\\"){i=!0;continue}if(a==="'"&&!s){n=!n;continue}if(a==='"'&&!n){s=!s;continue}if((a===" "||a===" "||a===`
|
|
522
|
+
`)&&!n&&!s){r&&(e.push(r),r="");continue}r+=a}return r&&e.push(r),e}function k0(t){let e=[],r=0;for(;r<t.length;){for(;r<t.length&&/\s/.test(t[r]);)r++;if(r>=t.length)break;if(t[r]!=="["){r++;continue}r++;let n="";if(t[r]==="'"||t[r]==='"'){let i=t[r];for(r++;r<t.length&&t[r]!==i;)n+=t[r],r++;t[r]===i&&r++}else for(;r<t.length&&t[r]!=="]"&&t[r]!=="=";)n+=t[r],r++;for(;r<t.length&&t[r]!=="]";)r++;if(t[r]==="]"&&r++,t[r]!=="=")continue;r++;let s="";if(t[r]==="'"||t[r]==='"'){let i=t[r];for(r++;r<t.length&&t[r]!==i;)t[r]==="\\"&&r+1<t.length&&r++,s+=t[r],r++;t[r]===i&&r++}else for(;r<t.length&&!/\s/.test(t[r]);)s+=t[r],r++;e.push([n,s])}return e}function Vs(t,e){let r=!1,n=!1,s=[];for(let i=0;i<e.length;i++){let a=e[i];if(a==="-a")r=!0;else if(a==="-A")n=!0;else if(a==="-p"){if(e.length===1){let o="";for(let l of t.state.readonlyVars||[]){let c=t.state.env[l];c!==void 0&&(o+=`declare -r ${l}="${c}"
|
|
523
|
+
`)}return Ne(o)}}else if(a==="--"){s.push(...e.slice(i+1));break}else a.startsWith("-")||s.push(a)}for(let i of s){let a=uu(i);if(a.value===void 0&&!a.isArray){wt(t,a.name);continue}let o=fu(t,a,{makeReadonly:!0});if(o)return o}return q}J();async function Zs(t,e){let r=e;if(r.length>0){let s=r[0];if(s==="--")r=r.slice(1);else if(s.startsWith("-")&&s!=="-"&&s.length>1)return _(`bash: eval: ${s}: invalid option
|
|
488
524
|
eval: usage: eval [arg ...]
|
|
489
|
-
`,2)}if(r.length===0)return q;let n=r.join(" ");if(n.trim()==="")return q;try{let s=
|
|
490
|
-
`);throw s}}
|
|
491
|
-
`,r=2):r=(i%256+256)%256}throw new
|
|
492
|
-
`}return
|
|
493
|
-
`,i=1;continue}
|
|
494
|
-
`);let r=
|
|
495
|
-
`)}return $("","",n===0?1:0)}function
|
|
496
|
-
`);let r=t.state.localScopes[t.state.localScopes.length-1],n="",s=0;for(let i of e){let a,o;if(i.includes("=")){let
|
|
497
|
-
`,s=1;continue}r.has(a)||r.set(a,t.state.env[a]),o!==void 0&&(t.state.env[a]=o)}return $("",n,s)}function
|
|
498
|
-
`,i="",a=-1,o=null,
|
|
525
|
+
`,2)}if(r.length===0)return q;let n=r.join(" ");if(n.trim()==="")return q;try{let s=nt(n);return t.executeScript(s)}catch(s){if(s instanceof pe||s instanceof ye||s instanceof me||s instanceof X)throw s;if(s.name==="ParseException")return _(`bash: eval: ${s.message}
|
|
526
|
+
`);throw s}}J();function Qs(t,e){let r,n="";if(e.length===0)r=t.state.lastExitCode;else{let s=e[0],i=Number.parseInt(s,10);s===""||Number.isNaN(i)||!/^-?\d+$/.test(s)?(n=`bash: exit: ${s}: numeric argument required
|
|
527
|
+
`,r=2):r=(i%256+256)%256}throw new X(r,"",n)}function Xs(t,e){let r=!1,n=[];for(let a of e)a==="-n"?r=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!r){let a="",o=Object.entries(t.state.env).filter(([l])=>!l.startsWith("BASH_ALIAS_")).sort(([l],[c])=>l.localeCompare(c));for(let[l,c]of o){let u=c.replace(/'/g,"'\\''");a+=`declare -x ${l}='${u}'
|
|
528
|
+
`}return Ne(a)}if(r){for(let a of n){let o=a.split("=")[0];delete t.state.env[o]}return q}let s="",i=0;for(let a of n){let o,l;if(a.includes("=")){let c=a.indexOf("=");o=a.slice(0,c),l=a.slice(c+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){s+=`bash: export: \`${a}': not a valid identifier
|
|
529
|
+
`,i=1;continue}l!==void 0?t.state.env[o]=l:o in t.state.env||(t.state.env[o]="")}return $("",s,i)}function v0(t){let e=[],r="",n=0;for(let s of t){for(let i of s)i==="("?n++:i===")"&&n--;r?r+=` ${s}`:r=s,n===0&&(e.push(r),r="")}return r&&e.push(r),e}async function Ks(t,e){if(e.length===0)return _(`bash: let: expression expected
|
|
530
|
+
`);let r=v0(e),n=0;for(let s of r)try{let a=nt(`(( ${s} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await Z(t,o.expression.expression))}}catch(i){return _(`bash: let: ${s}: ${i.message}
|
|
531
|
+
`)}return $("","",n===0?1:0)}function N0(t,e){let r=t.state.env.HOME||"/home/user";return e.split(":").map(i=>i==="~"?r:i==="~root"?"/root":i.startsWith("~/")?r+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Js(t,e){if(t.state.localScopes.length===0)return _(`bash: local: can only be used in a function
|
|
532
|
+
`);let r=t.state.localScopes[t.state.localScopes.length-1],n="",s=0;for(let i of e){let a,o;if(i.includes("=")){let l=i.indexOf("=");a=i.slice(0,l),o=N0(t,i.slice(l+1))}else a=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){n+=`bash: local: \`${i}': not a valid identifier
|
|
533
|
+
`,s=1;continue}r.has(a)||r.set(a,t.state.env[a]),o!==void 0&&(t.state.env[a]=o)}return $("",n,s)}function Ys(t,e,r){let n=!1,s=`
|
|
534
|
+
`,i="",a=-1,o=null,l=[],c=0,u=!1;for(;c<e.length;){let E=e[c];E==="-r"?n=!0:E==="-d"&&c+1<e.length?(s=e[c+1],c++):E==="-p"&&c+1<e.length?(i=e[c+1],c++):E==="-n"&&c+1<e.length?(a=Number.parseInt(e[c+1],10),(Number.isNaN(a)||a<0)&&(u=!0,a=0),c++):E==="-a"&&c+1<e.length?(o=e[c+1],c++):E==="-t"?c+1<e.length&&!e[c+1].startsWith("-")&&c++:E==="-s"||E.startsWith("-")||l.push(E),c++}if(u)return $("","",1);l.length===0&&o===null&&l.push("REPLY");let f=r;!f&&t.state.groupStdin!==void 0&&(f=t.state.groupStdin);let d="",h=0,p=!0;if(a>=0){for(let E=0;E<f.length&&E<a;E++){let b=f[E];if(b===s){h=E+1;break}d+=b,h=E+1}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(h))}else{let E=f;for(h=0;;){let b=E.indexOf(s);if(b!==-1){let S=E.substring(0,b);if(h+=b+s.length,E=E.substring(b+s.length),!n&&S.endsWith("\\")){d+=S.slice(0,-1);continue}d+=S,p=!0;break}else if(E.length>0){d+=E,h+=E.length,p=!1,E="";break}else{if(d.length===0){for(let S of l)t.state.env[S]="";return o&&Ms(t,o),$("","",1)}p=!1;break}}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(h))}if(s===`
|
|
499
535
|
`&&d.endsWith(`
|
|
500
|
-
`)&&(d=d.slice(0,-1)),n||(d=d.replace(/\\(.)/g,"$1")),
|
|
501
|
-
`,2);r=(s%256+256)%256}throw new
|
|
536
|
+
`)&&(d=d.slice(0,-1)),n||(d=d.replace(/\\(.)/g,"$1")),l.length===1&&l[0]==="REPLY")return t.state.env.REPLY=d,$("","",p?0:1);let w=Jr(t.state.env),{words:x,wordStarts:y}=Vc(d,w);if(o){Ms(t,o);for(let E=0;E<x.length;E++)t.state.env[`${o}_${E}`]=x[E];return $("","",p?0:1)}for(let E=0;E<l.length;E++){let b=l[E];if(E<l.length-1)t.state.env[b]=x[E]??"";else if(E<y.length){let S=Zc(d.substring(y[E]),w);t.state.env[b]=S}else t.state.env[b]=""}return $("","",p?0:1)}J();function ei(t,e){if(t.state.callDepth===0&&t.state.sourceDepth===0)return _("bash: return: can only `return' from a function or sourced script\n");let r=t.state.lastExitCode;if(e.length>0){let n=e[0],s=Number.parseInt(n,10);if(n===""||Number.isNaN(s)||!/^-?\d+$/.test(n))return _(`bash: return: ${n}: numeric argument required
|
|
537
|
+
`,2);r=(s%256+256)%256}throw new me(r)}function I0(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var rn=`set: usage: set [-eux] [+eux] [-o option] [+o option]
|
|
502
538
|
Options:
|
|
503
539
|
-e Exit immediately if a command exits with non-zero status
|
|
504
540
|
+e Disable -e
|
|
@@ -514,65 +550,70 @@ Options:
|
|
|
514
550
|
+o pipefail Disable pipefail
|
|
515
551
|
-o xtrace Same as -x
|
|
516
552
|
+o xtrace Disable xtrace
|
|
517
|
-
`,
|
|
518
|
-
`);return
|
|
519
|
-
`:"")}let r=0;for(;r<e.length;){let n=e[r];if((n==="-o"||n==="+o")&&
|
|
520
|
-
${
|
|
553
|
+
`,du={e:"errexit",u:"nounset",x:"xtrace",v:"verbose",f:null,h:null,C:null,n:null,a:null,b:null,m:null,B:null,H:null,P:null,T:null,E:null,p:null},hu={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",noclobber:null,noglob:null,noexec:null,allexport:null,notify:null,monitor:null,braceexpand:null,histexpand:null,physical:null,functrace:null,errtrace:null,privileged:null,hashall:null,posix:null,vi:null,emacs:null,ignoreeof:null,"interactive-comments":null,keyword:null,onecmd:null},pu=["errexit","nounset","pipefail","verbose","xtrace"],mu=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function gu(t,e,r){e!==null&&(t.state.options[e]=r)}function R0(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function ri(t,e){if(e.includes("--help"))return Ne(rn);if(e.length===0){let n=Object.entries(t.state.env).filter(([s])=>/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)).sort(([s],[i])=>s.localeCompare(i)).map(([s,i])=>`${s}=${I0(i)}`).join(`
|
|
554
|
+
`);return Ne(n?`${n}
|
|
555
|
+
`:"")}let r=0;for(;r<e.length;){let n=e[r];if((n==="-o"||n==="+o")&&R0(e,r)){let s=e[r+1];if(!(s in hu))return _(`bash: set: ${s}: invalid option name
|
|
556
|
+
${rn}`);gu(t,hu[s],n==="-o"),r+=2;continue}if(n==="-o"){let s=pu.map(o=>`${o.padEnd(16)}${t.state.options[o]?"on":"off"}`),i=mu.map(o=>`${o.padEnd(16)}off`),a=[...s,...i].sort();return Ne(`${a.join(`
|
|
521
557
|
`)}
|
|
522
|
-
`)}if(n==="+o"){let s=
|
|
558
|
+
`)}if(n==="+o"){let s=pu.map(o=>`set ${t.state.options[o]?"-o":"+o"} ${o}`),i=mu.map(o=>`set +o ${o}`),a=[...s,...i].sort();return Ne(`${a.join(`
|
|
523
559
|
`)}
|
|
524
|
-
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let s=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!(a in
|
|
525
|
-
${
|
|
526
|
-
${
|
|
560
|
+
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let s=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!(a in du))return _(`bash: set: ${n[0]}${a}: invalid option
|
|
561
|
+
${rn}`);gu(t,du[a],s)}r++;continue}if(n==="--")return ti(t,e.slice(r+1)),q;if(n==="-"){if(t.state.options.xtrace=!1,t.state.options.verbose=!1,r+1<e.length)return ti(t,e.slice(r+1)),q;r++;continue}if(n==="+"){r++;continue}return n.startsWith("-")||n.startsWith("+")?_(`bash: set: ${n}: invalid option
|
|
562
|
+
${rn}`):(ti(t,e.slice(r)),q)}return q}function ti(t,e){let r=1;for(;t.state.env[String(r)]!==void 0;)delete t.state.env[String(r)],r++;for(let n=0;n<e.length;n++)t.state.env[String(n+1)]=e[n];t.state.env["#"]=String(e.length),t.state.env["@"]=e.join(" "),t.state.env["*"]=e.join(" ")}function ni(t,e){let r=1;if(e.length>0){let a=Number.parseInt(e[0],10);if(Number.isNaN(a)||a<0)return _(`bash: shift: ${e[0]}: numeric argument required
|
|
527
563
|
`);r=a}let n=Number.parseInt(t.state.env["#"]||"0",10);if(r>n)return _(`bash: shift: shift count out of range
|
|
528
|
-
`);if(r===0)return q;let s=[];for(let a=1;a<=n;a++)s.push(t.state.env[String(a)]||"");let i=s.slice(r);for(let a=1;a<=n;a++)delete t.state.env[String(a)];for(let a=0;a<i.length;a++)t.state.env[String(a+1)]=i[a];return t.state.env["#"]=String(i.length),t.state.env["@"]=i.join(" "),q}
|
|
529
|
-
`,2);let n=r[0],s=null,i=null;if(n.includes("/")){let
|
|
530
|
-
`);let a={};if(r.length>1){for(let
|
|
531
|
-
`);throw
|
|
532
|
-
`,s=1;continue}let d=f+
|
|
533
|
-
`,s=1;continue}let h=u[d][0];delete t.state.env[`${o}_${h}`];continue}delete t.state.env[`${o}_${
|
|
534
|
-
`,2):
|
|
535
|
-
`,2):$("","",1)}if(e.length===3){let n=e[0],s=e[1],i=e[2];if(
|
|
536
|
-
`,2):
|
|
537
|
-
`,exitCode:1}}
|
|
538
|
-
`,exitCode:1}}return{stdout:s,stderr:i,exitCode:a}}async function
|
|
539
|
-
`);let a=[];if(e.words===null)a=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)a=[];else for(let o of e.words){let
|
|
564
|
+
`);if(r===0)return q;let s=[];for(let a=1;a<=n;a++)s.push(t.state.env[String(a)]||"");let i=s.slice(r);for(let a=1;a<=n;a++)delete t.state.env[String(a)];for(let a=0;a<i.length;a++)t.state.env[String(a+1)]=i[a];return t.state.env["#"]=String(i.length),t.state.env["@"]=i.join(" "),q}J();async function si(t,e){let r=e;if(r.length>0&&r[0]==="--"&&(r=r.slice(1)),r.length===0)return $("",`bash: source: filename argument required
|
|
565
|
+
`,2);let n=r[0],s=null,i=null;if(n.includes("/")){let l=t.fs.resolvePath(t.state.cwd,n);try{i=await t.fs.readFile(l),s=l}catch{}}else{let c=(t.state.env.PATH||"").split(":").filter(u=>u);for(let u of c){let f=t.fs.resolvePath(t.state.cwd,`${u}/${n}`);try{if((await t.fs.stat(f)).isDirectory)continue;i=await t.fs.readFile(f),s=f;break}catch{}}if(i===null){let u=t.fs.resolvePath(t.state.cwd,n);try{i=await t.fs.readFile(u),s=u}catch{}}}if(i===null)return _(`bash: ${n}: No such file or directory
|
|
566
|
+
`);let a={};if(r.length>1){for(let c=1;c<=9;c++)a[String(c)]=t.state.env[String(c)];a["#"]=t.state.env["#"],a["@"]=t.state.env["@"];let l=r.slice(1);t.state.env["#"]=String(l.length),t.state.env["@"]=l.join(" ");for(let c=0;c<l.length&&c<9;c++)t.state.env[String(c+1)]=l[c];for(let c=l.length+1;c<=9;c++)delete t.state.env[String(c)]}let o=()=>{if(t.state.sourceDepth--,r.length>1)for(let[l,c]of Object.entries(a))c===void 0?delete t.state.env[l]:t.state.env[l]=c};t.state.sourceDepth++;try{let l=nt(i),c=await t.executeScript(l);return o(),c}catch(l){if(o(),l instanceof X)throw l;if(l instanceof me)return $(l.stdout,l.stderr,l.exitCode);if(l.name==="ParseException")return _(`bash: ${n}: ${l.message}
|
|
567
|
+
`);throw l}}function ii(t,e){let r="variable",n="",s=0;for(let i of e){if(i==="-v"){r="variable";continue}if(i==="-f"){r="function";continue}if(r==="function"){t.state.functions.delete(i);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let o=a[1],l=a[2];if(l==="@"||l==="*"){let u=ce(t,o);for(let[f]of u)delete t.state.env[`${o}_${f}`];delete t.state.env[o];continue}let c;if(/^-?\d+$/.test(l))c=Number.parseInt(l,10);else{let u=t.state.env[l];c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let u=ce(t,o),f=u.length;if(f===0){n+=`bash: unset: [${c}]: bad array subscript
|
|
568
|
+
`,s=1;continue}let d=f+c;if(d<0){n+=`bash: unset: [${c}]: bad array subscript
|
|
569
|
+
`,s=1;continue}let h=u[d][0];delete t.state.env[`${o}_${h}`];continue}delete t.state.env[`${o}_${c}`];continue}delete t.state.env[i],t.state.functions.delete(i)}return $("",n,s)}function ai(t,e){return t.fs.resolvePath(t.state.cwd,e)}var $0=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function nn(t){return $0.includes(t)}async function sn(t,e,r){let n=ai(t,r);switch(e){case"-e":case"-a":return t.fs.exists(n);case"-f":return await t.fs.exists(n)?(await t.fs.stat(n)).isFile:!1;case"-d":return await t.fs.exists(n)?(await t.fs.stat(n)).isDirectory:!1;case"-r":case"-w":case"-x":return t.fs.exists(n);case"-s":return await t.fs.exists(n)?(await t.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await t.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await t.fs.exists(n)?((await t.fs.stat(n)).mode&512)!==0:!1;case"-g":return await t.fs.exists(n)?((await t.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await t.fs.exists(n)?((await t.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return t.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return t.fs.exists(n);default:return!1}}var O0=["-nt","-ot","-ef"];function an(t){return O0.includes(t)}async function on(t,e,r,n){let s=ai(t,r),i=ai(t,n);switch(e){case"-nt":try{let a=await t.fs.stat(s),o=await t.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await t.fs.stat(s),o=await t.fs.stat(i);return a.mtime<o.mtime}catch{return!1}case"-ef":try{if(!await t.fs.exists(s)||!await t.fs.exists(i))return!1;let a=t.fs.resolvePath(t.state.cwd,s),o=t.fs.resolvePath(t.state.cwd,i);return a===o}catch{return!1}default:return!1}}var P0=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ln(t){return P0.has(t)}function cn(t,e,r){switch(t){case"-eq":return e===r;case"-ne":return e!==r;case"-lt":return e<r;case"-le":return e<=r;case"-gt":return e>r;case"-ge":return e>=r}}function un(t){return t==="="||t==="=="||t==="!="}function fn(t,e,r,n=!1){let s=n?dn(e,r):e===r;return t==="!="?!s:s}var F0=new Set(["-z","-n"]);function hn(t){return F0.has(t)}function pn(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function mn(t,e){let r=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],s=r[2];s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(a,o)=>t.state.env[o]||"");let i;if(/^-?\d+$/.test(s))i=Number.parseInt(s,10);else try{let a=Function(`"use strict"; return (${s})`)();i=typeof a=="number"?Math.floor(a):0}catch{let a=t.state.env[s];i=a?Number.parseInt(a,10):0}if(i<0){let a=nr(t,n);if(a.length===0||(i=Math.max(...a)+1+i,i<0))return!1}return`${n}_${i}`in t.state.env}return e in t.state.env}async function at(t,e){switch(e.type){case"CondBinary":{let r=await K(t,e.left),n=await K(t,e.right),s=e.right.parts.length>0&&e.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped");if(un(e.operator))return fn(e.operator,r,n,!s);if(ln(e.operator))return cn(e.operator,yu(t,r),yu(t,n));if(an(e.operator))return on(t,e.operator,r,n);switch(e.operator){case"=~":try{let i=new RegExp(n),a=r.match(i);if(a){t.state.env.BASH_REMATCH=a[0];for(let o=1;o<a.length;o++)t.state.env[`BASH_REMATCH_${o}`]=a[o]||""}return a!==null}catch{throw new Error("syntax error in regular expression")}case"<":return r<n;case">":return r>n;default:return!1}}case"CondUnary":{let r=await K(t,e.operand);return nn(e.operator)?sn(t,e.operator,r):hn(e.operator)?pn(e.operator,r):e.operator==="-v"?mn(t,r):e.operator==="-o"?li(t,r):!1}case"CondNot":return!await at(t,e.operand);case"CondAnd":return await at(t,e.left)?await at(t,e.right):!1;case"CondOr":return await at(t,e.left)?!0:await at(t,e.right);case"CondGroup":return await at(t,e.expression);case"CondWord":return await K(t,e.word)!=="";default:return!1}}async function Ut(t,e){if(e.length===0)return $("","",1);if(e.length===1)return oe(!!e[0]);if(e.length===2){let n=e[0],s=e[1];return n==="("?_(`test: '(' without matching ')'
|
|
570
|
+
`,2):nn(n)?oe(await sn(t,n,s)):hn(n)?oe(pn(n,s)):n==="!"?oe(!s):n==="-v"?oe(mn(t,s)):n==="-o"?oe(li(t,s)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?_(`test: ${n}: unary operator expected
|
|
571
|
+
`,2):$("","",1)}if(e.length===3){let n=e[0],s=e[1],i=e[2];if(un(s))return oe(fn(s,n,i));if(ln(s)){let a=gn(n),o=gn(i);return!a.valid||!o.valid?$("","",2):oe(cn(s,a.value,o.value))}if(an(s))return oe(await on(t,s,n,i));switch(s){case"-a":return oe(n!==""&&i!=="");case"-o":return oe(n!==""||i!=="");case">":return oe(n>i);case"<":return oe(n<i)}if(n==="!"){let a=await Ut(t,[s,i]);return $("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(n==="("&&i===")")return oe(s!=="")}if(e.length===4){if(e[0]==="!"){let n=await Ut(t,e.slice(1));return $("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(e[0]==="("&&e[3]===")")return Ut(t,[e[1],e[2]])}let r=await Eu(t,e,0);return r.pos<e.length?_(`test: too many arguments
|
|
572
|
+
`,2):oe(r.value)}async function Eu(t,e,r){return T0(t,e,r)}async function T0(t,e,r){let{value:n,pos:s}=await xu(t,e,r);for(;e[s]==="-o";){let i=await xu(t,e,s+1);n=n||i.value,s=i.pos}return{value:n,pos:s}}async function xu(t,e,r){let{value:n,pos:s}=await oi(t,e,r);for(;e[s]==="-a";){let i=await oi(t,e,s+1);n=n&&i.value,s=i.pos}return{value:n,pos:s}}async function oi(t,e,r){if(e[r]==="!"){let{value:n,pos:s}=await oi(t,e,r+1);return{value:!n,pos:s}}return D0(t,e,r)}async function D0(t,e,r){let n=e[r];if(n==="("){let{value:i,pos:a}=await Eu(t,e,r+1);return{value:i,pos:e[a]===")"?a+1:a}}if(nn(n)){let i=e[r+1]??"";return{value:await sn(t,n,i),pos:r+2}}if(hn(n)){let i=e[r+1]??"";return{value:pn(n,i),pos:r+2}}if(n==="-v"){let i=e[r+1]??"";return{value:mn(t,i),pos:r+2}}if(n==="-o"){let i=e[r+1]??"";return{value:li(t,i),pos:r+2}}let s=e[r+1];if(un(s)){let i=n,a=e[r+2]??"";return{value:fn(s,i,a),pos:r+3}}if(ln(s)){let i=gn(n),a=gn(e[r+2]??"0");return!i.valid||!a.valid?{value:!1,pos:r+3}:{value:cn(s,i.value,a.value),pos:r+3}}if(an(s)){let i=n,a=e[r+2]??"";return{value:await on(t,s,i,a),pos:r+3}}return{value:n!==void 0&&n!=="",pos:r+1}}function dn(t,e){let r="^";for(let n=0;n<e.length;n++){let s=e[n];if(s==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?r+=`\\${i}`:r+=i,n++}else r+="\\\\";else if(s==="*")r+=".*";else if(s==="?")r+=".";else if(s==="["){let i=e.indexOf("]",n+1);i!==-1?(r+=e.slice(n,i+1),n=i):r+="\\["}else/[\\^$.|+(){}]/.test(s)?r+=`\\${s}`:r+=s}return r+="$",new RegExp(r).test(t)}function li(t,e){let n={errexit:()=>t.state.options.errexit===!0,nounset:()=>t.state.options.nounset===!0,pipefail:()=>t.state.options.pipefail===!0,xtrace:()=>t.state.options.xtrace===!0,e:()=>t.state.options.errexit===!0,u:()=>t.state.options.nounset===!0,x:()=>t.state.options.xtrace===!0}[e];return n?n():!1}function yu(t,e){if(e=e.trim(),e==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(e))return wu(e);try{let r=new he,n=le(r,e);return V(t,n.expression)}catch{return wu(e)}}function L0(t,e){let r=0;for(let n of t){let s;if(n>="0"&&n<="9")s=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")s=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")s=n.charCodeAt(0)-65+36;else if(n==="@")s=62;else if(n==="_")s=63;else return Number.NaN;if(s>=e)return Number.NaN;r=r*e+s}return r}function wu(t){if(t=t.trim(),t==="")return 0;let e=!1;t.startsWith("-")?(e=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));let r,n=t.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let s=Number.parseInt(n[1],10);s>=2&&s<=64?r=L0(n[2],s):r=0}else/^0[xX][0-9a-fA-F]+$/.test(t)?r=Number.parseInt(t,16):/^0[0-7]+$/.test(t)?r=Number.parseInt(t,8):r=Number.parseInt(t,10);return Number.isNaN(r)&&(r=0),e?-r:r}function gn(t){if(t=t.trim(),t==="")return{value:0,valid:!0};let e=!1;if(t.startsWith("-")?(e=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1)),!/^\d+$/.test(t))return{value:0,valid:!1};let r=Number.parseInt(t,10);return Number.isNaN(r)?{value:0,valid:!1}:{value:e?-r:r,valid:!0}}J();async function ci(t,e){let r=t.state.inCondition;t.state.inCondition=!0;let n="",s="",i=0;try{for(let a of e){let o=await t.executeStatement(a);n+=o.stdout,s+=o.stderr,i=o.exitCode}}finally{t.state.inCondition=r}return{stdout:n,stderr:s,exitCode:i}}J();Me();function or(t,e,r,n){if(t instanceof pe)return e+=t.stdout,r+=t.stderr,t.levels>1&&n>1?(t.levels--,t.stdout=e,t.stderr=r,{action:"rethrow",stdout:e,stderr:r,error:t}):{action:"break",stdout:e,stderr:r};if(t instanceof ye)return e+=t.stdout,r+=t.stderr,t.levels>1&&n>1?(t.levels--,t.stdout=e,t.stderr=r,{action:"rethrow",stdout:e,stderr:r,error:t}):{action:"continue",stdout:e,stderr:r};if(t instanceof me||t instanceof Be||t instanceof X||t instanceof z)return t.prependOutput(e,r),{action:"rethrow",stdout:e,stderr:r,error:t};let s=te(t);return{action:"error",stdout:e,stderr:`${r}${s}
|
|
573
|
+
`,exitCode:1}}J();Me();async function xn(t,e,r="",n=""){let s=r,i=n,a=0;try{for(let o of e){let l=await t.executeStatement(o);s+=l.stdout,i+=l.stderr,a=l.exitCode}}catch(o){if(Sr(o)||o instanceof Be||o instanceof X||o instanceof z||o instanceof ze)throw o.prependOutput(s,i),o;return{stdout:s,stderr:`${i}${te(o)}
|
|
574
|
+
`,exitCode:1}}return{stdout:s,stderr:i,exitCode:a}}async function bu(t,e){let r="",n="";for(let s of e.clauses){let i=await ci(t,s.condition);if(r+=i.stdout,n+=i.stderr,i.exitCode===0)return xn(t,s.body,r,n)}return e.elseBody?xn(t,e.elseBody,r,n):$(r,n,0)}async function Su(t,e){let r="",n="",s=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.variable))return _(`bash: \`${e.variable}': not a valid identifier
|
|
575
|
+
`);let a=[];if(e.words===null)a=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)a=[];else for(let o of e.words){let l=await ar(t,o);a.push(...l.values)}t.state.loopDepth++;try{for(let o of a){i++,i>t.limits.maxLoopIterations&&Ke(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),t.state.env[e.variable]=o;try{for(let l of e.body){let c=await t.executeStatement(l);r+=c.stdout,n+=c.stderr,s=c.exitCode}}catch(l){let c=or(l,r,n,t.state.loopDepth);if(r=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return $(r,n,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return $(r,n,s)}async function Cu(t,e){let r="",n="",s=0,i=0;e.init&&await Z(t,e.init.expression),t.state.loopDepth++;try{for(;i++,i>t.limits.maxLoopIterations&&Ke(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),!(e.condition&&await Z(t,e.condition.expression)===0);){try{for(let a of e.body){let o=await t.executeStatement(a);r+=o.stdout,n+=o.stderr,s=o.exitCode}}catch(a){let o=or(a,r,n,t.state.loopDepth);if(r=o.stdout,n=o.stderr,o.action==="break")break;if(o.action==="continue"){e.update&&await Z(t,e.update.expression);continue}if(o.action==="error")return $(r,n,o.exitCode??1);throw o.error}e.update&&await Z(t,e.update.expression)}}finally{t.state.loopDepth--}return $(r,n,s)}async function Au(t,e,r=""){let n="",s="",i=0,a=0,o=r;for(let c of e.redirections)if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let u=c.target,f=await K(t,u.content);u.stripTabs&&(f=f.split(`
|
|
540
576
|
`).map(d=>d.replace(/^\t+/,"")).join(`
|
|
541
|
-
`)),o=f}else if(
|
|
542
|
-
`;else if(
|
|
543
|
-
`)}let
|
|
544
|
-
`,i=1,n="";break}}catch{}await t.fs.writeFile(
|
|
545
|
-
`,i=1;break}}catch{}await t.fs.writeFile(
|
|
546
|
-
`,i=1,n="";break}}catch{}await t.fs.appendFile(
|
|
547
|
-
`,i=1;break}}catch{}await t.fs.appendFile(
|
|
548
|
-
`,i=1,n="";break}}catch{}await t.fs.writeFile(
|
|
549
|
-
`,i=1,n="";break}}catch{}await t.fs.appendFile(
|
|
550
|
-
`,1);let
|
|
551
|
-
`,1);let d=
|
|
552
|
-
`,1);if(A=Math.max(...
|
|
553
|
-
`,1)}
|
|
577
|
+
`)),o=f}else if(c.operator==="<<<"&&c.target.type==="Word")o=`${await K(t,c.target)}
|
|
578
|
+
`;else if(c.operator==="<"&&c.target.type==="Word")try{let u=await K(t,c.target),f=t.fs.resolvePath(t.state.cwd,u);o=await t.fs.readFile(f)}catch{let u=await K(t,c.target);return _(`bash: ${u}: No such file or directory
|
|
579
|
+
`)}let l=t.state.groupStdin;o&&(t.state.groupStdin=o),t.state.loopDepth++;try{for(;;){a++,a>t.limits.maxLoopIterations&&Ke(`while loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,s);let c=0,u=!1,f=!1,d=t.state.inCondition;t.state.inCondition=!0;try{for(let h of e.condition){let p=await t.executeStatement(h);n+=p.stdout,s+=p.stderr,c=p.exitCode}}catch(h){if(h instanceof pe){if(n+=h.stdout,s+=h.stderr,h.levels>1&&t.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=s,t.state.inCondition=d,h;u=!0}else if(h instanceof ye){if(n+=h.stdout,s+=h.stderr,h.levels>1&&t.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=s,t.state.inCondition=d,h;f=!0}else throw t.state.inCondition=d,h}finally{t.state.inCondition=d}if(u)break;if(!f){if(c!==0)break;try{for(let h of e.body){let p=await t.executeStatement(h);n+=p.stdout,s+=p.stderr,i=p.exitCode}}catch(h){let p=or(h,n,s,t.state.loopDepth);if(n=p.stdout,s=p.stderr,p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return $(n,s,p.exitCode??1);throw p.error}}}}finally{t.state.loopDepth--,t.state.groupStdin=l}return $(n,s,i)}async function ku(t,e){let r="",n="",s=0,i=0;t.state.loopDepth++;try{for(;;){i++,i>t.limits.maxLoopIterations&&Ke(`until loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let a=await ci(t,e.condition);if(r+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of e.body){let l=await t.executeStatement(o);r+=l.stdout,n+=l.stderr,s=l.exitCode}}catch(o){let l=or(o,r,n,t.state.loopDepth);if(r=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return $(r,n,l.exitCode??1);throw l.error}}}finally{t.state.loopDepth--}return $(r,n,s)}async function vu(t,e){let r="",n="",s=0,i=await K(t,e.word),a=!1;for(let o=0;o<e.items.length;o++){let l=e.items[o],c=a;if(!a)for(let u of l.patterns){let f=await K(t,u);if(Yc(u)&&(f=eu(f)),dn(i,f)){c=!0;break}}if(c){let u=await xn(t,l.body,r,n);if(r=u.stdout,n=u.stderr,s=u.exitCode,l.terminator===";;")break;l.terminator===";&"?a=!0:a=!1}else a=!1}return $(r,n,s)}J();J();function Nu(t,e){return t.state.functions.set(e.name,e),q}async function Iu(t,e,r){t.state.callDepth++,t.state.callDepth>t.limits.maxCallDepth&&(t.state.callDepth--,Ke(`${e.name}: maximum recursion depth (${t.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),t.state.localScopes.push(new Map);let n={};for(let i=0;i<r.length;i++)n[String(i+1)]=t.state.env[String(i+1)],t.state.env[String(i+1)]=r[i];n["@"]=t.state.env["@"],n["#"]=t.state.env["#"],t.state.env["@"]=r.join(" "),t.state.env["#"]=String(r.length);let s=()=>{let i=t.state.localScopes.pop();if(i)for(let[a,o]of i)o===void 0?delete t.state.env[a]:t.state.env[a]=o;for(let[a,o]of Object.entries(n))o===void 0?delete t.state.env[a]:t.state.env[a]=o;t.state.callDepth--};try{let i=await t.executeCommand(e.body,"");return s(),i}catch(i){if(s(),i instanceof me)return $(i.stdout,i.stderr,i.exitCode);throw i}}Me();async function Ru(t,e,r){let{stdout:n,stderr:s,exitCode:i}=e;for(let a of r){if(a.target.type==="HereDoc")continue;let o=await K(t,a.target);switch(a.operator){case">":{let l=a.fd??1;if(l===1){let c=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${o}: Is a directory
|
|
580
|
+
`,i=1,n="";break}}catch{}await t.fs.writeFile(c,n),n=""}else if(l===2)if(o==="/dev/null")s="";else{let c=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${o}: Is a directory
|
|
581
|
+
`,i=1;break}}catch{}await t.fs.writeFile(c,s),s=""}break}case">>":{let l=a.fd??1;if(l===1){let c=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${o}: Is a directory
|
|
582
|
+
`,i=1,n="";break}}catch{}await t.fs.appendFile(c,n),n=""}else if(l===2){let c=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${o}: Is a directory
|
|
583
|
+
`,i=1;break}}catch{}await t.fs.appendFile(c,s),s=""}break}case">&":{let l=a.fd??1;o==="2"||o==="&2"?l===1&&(s+=n,n=""):(o==="1"||o==="&1")&&(n+=s,s="");break}case"&>":{let l=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(l)).isDirectory){s=`bash: ${o}: Is a directory
|
|
584
|
+
`,i=1,n="";break}}catch{}await t.fs.writeFile(l,n+s),n="",s="";break}case"&>>":{let l=t.fs.resolvePath(t.state.cwd,o);try{if((await t.fs.stat(l)).isDirectory){s=`bash: ${o}: Is a directory
|
|
585
|
+
`,i=1,n="";break}}catch{}await t.fs.appendFile(l,n+s),n="",s="";break}}}return $(n,s,i)}var lr=class{ctx;constructor(e,r){this.ctx={state:r,fs:e.fs,commands:e.commands,limits:e.limits,execFn:e.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:e.fetch,sleep:e.sleep}}async executeScript(e){let r="",n="",s=0;for(let i of e.statements)try{let a=await this.executeStatement(i);r+=a.stdout,n+=a.stderr,s=a.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}catch(a){if(a instanceof X)throw a.prependOutput(r,n),a;if(a instanceof z)throw a;if(a instanceof Be)return r+=a.stdout,n+=a.stderr,s=a.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}};if(a instanceof $e)return r+=a.stdout,n+=a.stderr,s=1,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}};if(a instanceof qe)return r+=a.stdout,n+=a.stderr,s=1,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}};if(a instanceof pe||a instanceof ye){if(this.ctx.state.loopDepth>0)throw a.prependOutput(r,n),a;r+=a.stdout,n+=a.stderr;continue}throw a instanceof me&&a.prependOutput(r,n),a}return{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}}}async executeStatement(e){this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Ke(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands");let r="",n="",s=0,i=-1,a=!1;for(let o=0;o<e.pipelines.length;o++){let l=e.pipelines[o],c=o>0?e.operators[o-1]:null;if(c==="&&"&&s!==0||c==="||"&&s===0)continue;let u=await this.executePipeline(l);r+=u.stdout,n+=u.stderr,s=u.exitCode,i=o,a=l.negated,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}if(this.ctx.state.options.errexit&&s!==0&&i===e.pipelines.length-1&&!a&&!this.ctx.state.inCondition)throw new Be(s,r,n);return $(r,n,s)}async executePipeline(e){let r="",n=q,s=0,i=[];for(let a=0;a<e.commands.length;a++){let o=e.commands[a],l=a===e.commands.length-1,c;try{c=await this.executeCommand(o,r)}catch(u){if(u instanceof qe)c={stdout:u.stdout,stderr:u.stderr,exitCode:1};else if(u instanceof X&&e.commands.length>1)c={stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode};else throw u}i.push(c.exitCode),c.exitCode!==0&&(s=c.exitCode),l?n=c:(r=c.stdout,n={stdout:"",stderr:c.stderr,exitCode:c.exitCode})}for(let a of Object.keys(this.ctx.state.env))a.startsWith("PIPESTATUS_")&&delete this.ctx.state.env[a];for(let a=0;a<i.length;a++)this.ctx.state.env[`PIPESTATUS_${a}`]=String(i[a]);return this.ctx.state.env.PIPESTATUS__length=String(i.length),this.ctx.state.options.pipefail&&s!==0&&(n={...n,exitCode:s}),e.negated&&(n={...n,exitCode:n.exitCode===0?1:0}),n}async executeCommand(e,r){switch(e.type){case"SimpleCommand":return this.executeSimpleCommand(e,r);case"If":return bu(this.ctx,e);case"For":return Su(this.ctx,e);case"CStyleFor":return Cu(this.ctx,e);case"While":return Au(this.ctx,e,r);case"Until":return ku(this.ctx,e);case"Case":return vu(this.ctx,e);case"Subshell":return this.executeSubshell(e,r);case"Group":return this.executeGroup(e,r);case"FunctionDef":return Nu(this.ctx,e);case"ArithmeticCommand":return this.executeArithmeticCommand(e);case"ConditionalCommand":return this.executeConditionalCommand(e);default:return q}}async executeSimpleCommand(e,r){try{return await this.executeSimpleCommandInner(e,r)}catch(n){if(n instanceof ae)return _(n.stderr);throw n}}async executeSimpleCommandInner(e,r){this.ctx.state.expansionStderr="";let n={};for(let l of e.assignments){let c=l.name;if(l.array){if(/\[.+\]$/.test(c))return $("",`bash: ${c}: cannot assign list to array member
|
|
586
|
+
`,1);let w=it(this.ctx,c);if(w)return w;let x=[];for(let E of l.array){let b=await ar(this.ctx,E);x.push(...b.values)}let y=0;if(l.append){let E=ce(this.ctx,c);E.length>0&&(y=Math.max(...E.map(([S])=>typeof S=="number"?S:0))+1)}else{let E=`${c}_`;for(let b of Object.keys(this.ctx.state.env))b.startsWith(E)&&!b.includes("__")&&delete this.ctx.state.env[b]}for(let E=0;E<x.length;E++)this.ctx.state.env[`${c}_${y+E}`]=x[E];l.append||(this.ctx.state.env[`${c}__length`]=String(x.length));continue}let u=l.value?await K(this.ctx,l.value):"";if(c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return $("",`bash: ${c}: bad array subscript
|
|
587
|
+
`,1);let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let w=d[1],x=d[2],y=it(this.ctx,w);if(y)return y;let E=this.ctx.state.associativeArrays?.has(w),b;if(E){let A;if(x.startsWith("'")&&x.endsWith("'"))A=x.slice(1,-1);else if(x.startsWith('"')&&x.endsWith('"')){let D=x.slice(1,-1),P=new he().parseWordFromString(D,!0,!1);A=await K(this.ctx,P)}else if(x.includes("$")){let F=new he().parseWordFromString(x,!1,!1);A=await K(this.ctx,F)}else A=x;b=`${w}_${A}`}else{let A;if(/^-?\d+$/.test(x))A=Number.parseInt(x,10);else{try{let D=new he,F=le(D,x);A=V(this.ctx,F.expression)}catch{let D=this.ctx.state.env[x];A=D?Number.parseInt(D,10):0}Number.isNaN(A)&&(A=0)}if(A<0){let D=ce(this.ctx,w);if(D.length===0)return $("",`bash: ${w}[${x}]: bad array subscript
|
|
588
|
+
`,1);if(A=Math.max(...D.map(([P])=>typeof P=="number"?P:0))+1+A,A<0)return $("",`bash: ${w}[${x}]: bad array subscript
|
|
589
|
+
`,1)}b=`${w}_${A}`}let S=l.append?(this.ctx.state.env[b]||"")+u:u;e.name?(n[b]=this.ctx.state.env[b],this.ctx.state.env[b]=S):this.ctx.state.env[b]=S;continue}let h=it(this.ctx,c);if(h)return h;let p=l.append?(this.ctx.state.env[c]||"")+u:u;e.name?(n[c]=this.ctx.state.env[c],this.ctx.state.env[c]=p):this.ctx.state.env[c]=p}if(!e.name)return $("","",this.ctx.state.lastExitCode);for(let l of e.redirections){if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let c=l.target,u=await K(this.ctx,c.content);c.stripTabs&&(u=u.split(`
|
|
554
590
|
`).map(f=>f.replace(/^\t+/,"")).join(`
|
|
555
|
-
`)),r=u;continue}if(
|
|
556
|
-
`;continue}if(
|
|
557
|
-
`)}}let s=await
|
|
558
|
-
`,127)}let o=await this.runCommand(s,i,a,r);o=await
|
|
559
|
-
`,127);let{cmd:o,path:
|
|
591
|
+
`)),r=u;continue}if(l.operator==="<<<"&&l.target.type==="Word"){r=`${await K(this.ctx,l.target)}
|
|
592
|
+
`;continue}if(l.operator==="<"&&l.target.type==="Word")try{let c=await K(this.ctx,l.target),u=this.ctx.fs.resolvePath(this.ctx.state.cwd,c);r=await this.ctx.fs.readFile(u)}catch{let c=await K(this.ctx,l.target);for(let[u,f]of Object.entries(n))f===void 0?delete this.ctx.state.env[u]:this.ctx.state.env[u]=f;return _(`bash: ${c}: No such file or directory
|
|
593
|
+
`)}}let s=await K(this.ctx,e.name),i=[],a=[];for(let l of e.args){let c=await ar(this.ctx,l);for(let u of c.values)i.push(u),a.push(c.quoted)}if(!s){if(e.name.parts.every(c=>c.type==="CommandSubstitution"||c.type==="ParameterExpansion"||c.type==="ArithmeticExpansion")){if(i.length>0){let c=i.shift();return a.shift(),await this.runCommand(c,i,a,r)}return $("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found
|
|
594
|
+
`,127)}let o=await this.runCommand(s,i,a,r);o=await Ru(this.ctx,o,e.redirections),this.ctx.state.lastArg=i.length>0?i[i.length-1]:s;for(let[l,c]of Object.entries(n))c===void 0?delete this.ctx.state.env[l]:this.ctx.state.env[l]=c;return this.ctx.state.expansionStderr&&(o={...o,stderr:this.ctx.state.expansionStderr+o.stderr},this.ctx.state.expansionStderr=""),o}async runCommand(e,r,n,s,i=!1){if(e==="cd")return await Hs(this.ctx,r);if(e==="export")return Xs(this.ctx,r);if(e==="unset")return ii(this.ctx,r);if(e==="exit")return Qs(this.ctx,r);if(e==="local")return Js(this.ctx,r);if(e==="set")return ri(this.ctx,r);if(e==="break")return zs(this.ctx,r);if(e==="continue")return js(this.ctx,r);if(e==="return")return ei(this.ctx,r);if(e==="eval")return Zs(this.ctx,r);if(e==="shift")return ni(this.ctx,r);if(e==="source"||e===".")return si(this.ctx,r);if(e==="read")return Ys(this.ctx,r,s);if(e==="declare"||e==="typeset")return qs(this.ctx,r);if(e==="readonly")return Vs(this.ctx,r);if(!i){let u=this.ctx.state.functions.get(e);if(u)return Iu(this.ctx,u,r)}if(e===":"||e==="true")return q;if(e==="false")return oe(!1);if(e==="let")return Ks(this.ctx,r);if(e==="command"){if(r.length===0)return q;let u=r;for(;u.length>0&&u[0].startsWith("-");)u=u.slice(1);if(u.length===0)return q;let[f,...d]=u;return this.runCommand(f,d,[],s,!0)}if(e==="builtin"){if(r.length===0)return q;let[u,...f]=r;return this.runCommand(u,f,[],s)}if(e==="shopt")return q;if(e==="exec"){if(r.length===0)return q;let[u,...f]=r;return this.runCommand(u,f,[],s)}if(e==="wait")return q;if(e==="type")return this.handleType(r);if(e==="[["){let u=r.lastIndexOf("]]");if(u!==-1){let f=r.slice(0,u);return Ut(this.ctx,f)}return _("bash: [[: missing `]]'\n",2)}if(e==="["||e==="test"){let u=r;if(e==="["){if(r[r.length-1]!=="]")return _("[: missing `]'\n",2);u=r.slice(0,-1)}return Ut(this.ctx,u)}let a=await this.resolveCommand(e);if(!a)return _(`bash: ${e}: command not found
|
|
595
|
+
`,127);let{cmd:o,path:l}=a,c={fs:this.ctx.fs,cwd:this.ctx.state.cwd,env:this.ctx.state.env,stdin:s,limits:this.ctx.limits,exec:this.ctx.execFn,fetch:this.ctx.fetch,getRegisteredCommands:()=>Array.from(this.ctx.commands.keys()),sleep:this.ctx.sleep};try{return await o.execute(r,c)}catch(u){return _(`${e}: ${te(u)}
|
|
560
596
|
`)}}async resolveCommand(e){if(e.includes("/")){let i=this.ctx.fs.resolvePath(this.ctx.state.cwd,e);if(!await this.ctx.fs.exists(i))return null;let a=i.split("/").pop()||e,o=this.ctx.commands.get(a);return o?{cmd:o,path:i}:null}let n=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let i of n){if(!i)continue;let a=`${i}/${e}`;if(await this.ctx.fs.exists(a)){let o=this.ctx.commands.get(e);if(o)return{cmd:o,path:a}}}if(!await this.ctx.fs.exists("/bin")){let i=this.ctx.commands.get(e);if(i)return{cmd:i,path:`/bin/${e}`}}return null}async findCommandInPath(e){let r=[],s=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let i of s){if(!i)continue;let a=`${i}/${e}`;await this.ctx.fs.exists(a)&&r.push(a)}return r}handleType(e){let r=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),n=new Set(["cd","export","unset","exit","local","set","break","continue","return","eval","shift","source",".","read","declare","typeset","readonly",":","true","false","let","command","builtin","shopt","exec","wait","type","[","test"]),s="",i="",a=0;for(let o of e)r.has(o)?s+=`${o} is a shell keyword
|
|
561
597
|
`:n.has(o)?s+=`${o} is a shell builtin
|
|
562
598
|
`:this.ctx.state.functions.has(o)?s+=`${o} is a function
|
|
563
599
|
`:this.ctx.commands.has(o)?s+=`${o} is /bin/${o}
|
|
564
600
|
`:(i+=`bash: type: ${o}: not found
|
|
565
|
-
`,a=1);return $(s,i,a)}async executeSubshell(e,r=""){let n={...this.ctx.state.env},s=this.ctx.state.cwd,i=this.ctx.state.loopDepth,a=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=i>0,this.ctx.state.loopDepth=0;let o=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);let
|
|
566
|
-
`,1)}return this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=a,this.ctx.state.groupStdin=o,$(c,
|
|
567
|
-
`,1)}return this.ctx.state.groupStdin=a,$(n,s,i)}async executeArithmeticCommand(e){try{let r=await Z(this.ctx,e.expression.expression);return
|
|
568
|
-
`)}}async executeConditionalCommand(e){try{let r=await
|
|
569
|
-
`,2)}}};var
|
|
570
|
-
`,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:n,OLDPWD:n,...e.env};if(this.limits
|
|
601
|
+
`,a=1);return $(s,i,a)}async executeSubshell(e,r=""){let n={...this.ctx.state.env},s=this.ctx.state.cwd,i=this.ctx.state.loopDepth,a=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=i>0,this.ctx.state.loopDepth=0;let o=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);let l="",c="",u=0;try{for(let f of e.body){let d=await this.executeStatement(f);l+=d.stdout,c+=d.stderr,u=d.exitCode}}catch(f){if(this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=a,this.ctx.state.groupStdin=o,f instanceof z)throw f;if(f instanceof ze)return l+=f.stdout,c+=f.stderr,$(l,c,0);if(f instanceof pe||f instanceof ye)return l+=f.stdout,c+=f.stderr,$(l,c,0);if(f instanceof X)return l+=f.stdout,c+=f.stderr,$(l,c,f.exitCode);if(f instanceof me)return l+=f.stdout,c+=f.stderr,$(l,c,f.exitCode);if(f instanceof Be)throw f.stdout=l+f.stdout,f.stderr=c+f.stderr,f;return $(l,`${c}${te(f)}
|
|
602
|
+
`,1)}return this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=a,this.ctx.state.groupStdin=o,$(l,c,u)}async executeGroup(e,r=""){let n="",s="",i=0,a=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);try{for(let o of e.body){let l=await this.executeStatement(o);n+=l.stdout,s+=l.stderr,i=l.exitCode}}catch(o){if(this.ctx.state.groupStdin=a,o instanceof z)throw o;if(Sr(o)||o instanceof Be||o instanceof X)throw o.prependOutput(n,s),o;return $(n,`${s}${te(o)}
|
|
603
|
+
`,1)}return this.ctx.state.groupStdin=a,$(n,s,i)}async executeArithmeticCommand(e){try{let r=await Z(this.ctx,e.expression.expression);return oe(r!==0)}catch(r){return _(`bash: arithmetic expression: ${r.message}
|
|
604
|
+
`)}}async executeConditionalCommand(e){try{let r=await at(this.ctx,e.expression);return oe(r)}catch(r){return _(`bash: conditional expression: ${r.message}
|
|
605
|
+
`,2)}}};var zt={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4};function $u(t){return t?{maxCallDepth:t.maxCallDepth??zt.maxCallDepth,maxCommandCount:t.maxCommandCount??zt.maxCommandCount,maxLoopIterations:t.maxLoopIterations??zt.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??zt.maxAwkIterations,maxSedIterations:t.maxSedIterations??zt.maxSedIterations}:{...zt}}function Ou(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function M0(t){let e=Ou(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function _0(t,e){let r=Ou(t);if(!r)return!1;let n=M0(e);return!n||r.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:r.pathname.startsWith(n.pathPrefix)}function ui(t,e){return!e||e.length===0?!1:e.some(r=>_0(t,r))}var cr=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},ur=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},fr=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},yn=class extends Error{constructor(e,r){super(`HTTP method '${e}' not allowed. Allowed methods: ${r.join(", ")}`),this.name="MethodNotAllowedError"}};var B0=20,W0=3e4,U0=["GET","HEAD"],z0=new Set(["GET","HEAD","OPTIONS"]),H0=new Set([301,302,303,307,308]);function fi(t){let e=t.maxRedirects??B0,r=t.timeoutMs??W0,n=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??U0;function s(o){if(!t.dangerouslyAllowFullInternetAccess&&!ui(o,t.allowedUrlPrefixes??[]))throw new cr(o)}function i(o){if(t.dangerouslyAllowFullInternetAccess)return;let l=o.toUpperCase();if(!n.includes(l))throw new yn(l,n)}async function a(o,l={}){let c=l.method?.toUpperCase()??"GET";s(o),i(c);let u=o,f=0,d=l.followRedirects??!0,h=l.timeoutMs!==void 0?Math.min(l.timeoutMs,r):r;for(;;){let p=new AbortController,w=setTimeout(()=>p.abort(),h);try{let x={method:c,headers:l.headers,signal:p.signal,redirect:"manual"};l.body&&!z0.has(c)&&(x.body=l.body);let y=await fetch(u,x);if(H0.has(y.status)&&d){let E=y.headers.get("location");if(!E)return await Pu(y,u);let b=new URL(E,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!ui(b,t.allowedUrlPrefixes??[]))throw new fr(b);if(f++,f>e)throw new ur(e);u=b;continue}return await Pu(y,u)}finally{clearTimeout(w)}}}return a}async function Pu(t,e){let r={};return t.headers.forEach((n,s)=>{r[s.toLowerCase()]=n}),{status:t.status,statusText:t.statusText,headers:r,body:await t.text(),url:e}}var wn=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;logger;state;constructor(e={}){let r=e.fs??new mt(e.files);this.fs=r,this.useDefaultLayout=!e.cwd&&!e.files;let n=e.cwd||(this.useDefaultLayout?"/home/user":"/"),s={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
|
|
606
|
+
`,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:n,OLDPWD:n,...e.env};if(this.limits=$u({...e.executionLimits,...e.maxCallDepth!==void 0&&{maxCallDepth:e.maxCallDepth},...e.maxCommandCount!==void 0&&{maxCommandCount:e.maxCommandCount},...e.maxLoopIterations!==void 0&&{maxLoopIterations:e.maxLoopIterations}}),e.network&&(this.secureFetch=fi(e.network)),this.sleepFn=e.sleep,this.logger=e.logger,this.state={env:s,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},r instanceof mt)try{r.mkdirSync("/bin",{recursive:!0}),r.mkdirSync("/usr/bin",{recursive:!0}),this.useDefaultLayout&&(r.mkdirSync("/home/user",{recursive:!0}),r.mkdirSync("/tmp",{recursive:!0}))}catch{}if(n!=="/"&&r instanceof mt)try{r.mkdirSync(n,{recursive:!0})}catch{}for(let i of pc(e.commands))this.registerCommand(i);if(e.network)for(let i of mc())this.registerCommand(i);if(e.customCommands)for(let i of e.customCommands)gc(i)?this.registerCommand(xc(i)):this.registerCommand(i)}registerCommand(e){if(this.commands.set(e.name,e),this.fs instanceof mt)try{this.fs.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
|
|
571
607
|
# Built-in command: ${e.name}
|
|
572
608
|
`)}catch{}}logResult(e){return this.logger&&(e.stdout&&this.logger.debug("stdout",{output:e.stdout}),e.stderr&&this.logger.info("stderr",{output:e.stderr}),this.logger.info("exit",{exitCode:e.exitCode})),e}async exec(e,r){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
|
|
573
609
|
`,exitCode:1,env:{...this.state.env,...r?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...r?.env}};this.logger?.info("exec",{command:e});let n=r?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...r?.env,...r?.cwd?{PWD:r.cwd}:{}},cwd:n,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},i=e;r?.rawScript||(i=e.split(`
|
|
574
610
|
`).map(o=>o.trimStart()).join(`
|
|
575
|
-
`));try{let a=
|
|
611
|
+
`));try{let a=nt(i),o={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn},c=await new lr(o,s).executeScript(a);return this.logResult(c)}catch(a){if(a instanceof X)return this.logResult({stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode,env:{...this.state.env,...r?.env}});if(a instanceof ae)return this.logResult({stdout:a.stdout,stderr:a.stderr,exitCode:1,env:{...this.state.env,...r?.env}});if(a instanceof z)return this.logResult({stdout:a.stdout,stderr:a.stderr,exitCode:z.EXIT_CODE,env:{...this.state.env,...r?.env}});if(a.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${a.message}
|
|
576
612
|
`,exitCode:2,env:{...this.state.env,...r?.env}});if(a instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${a.message}
|
|
577
|
-
`,exitCode:1,env:{...this.state.env,...r?.env}});throw a}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,r){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),r)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function
|
|
578
|
-
`).trim()}var
|
|
613
|
+
`,exitCode:1,env:{...this.state.env,...r?.env}});throw a}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,r){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),r)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function q0(t){let e=["Execute bash commands in a virtual environment.","","This is a simulated bash environment with a virtual filesystem. Commands run in isolation without access to the host system.",""];if(t.files&&Object.keys(t.files).length>0){let r=Object.keys(t.files),n=r.slice(0,5);e.push("Available files:");for(let s of n)e.push(` ${s}`);r.length>5&&e.push(` ... and ${r.length-5} more`),e.push(""),e.push("Common operations:"),e.push(" ls -la # List files with details"),e.push(" find . -name '*.ts' # Find files by pattern"),e.push(" grep -r 'pattern' . # Search file contents"),e.push(" cat <file> # View file contents"),e.push("")}return e.push("To discover commands and their options:"),e.push(" help # List all available commands"),e.push(" <command> --help # Show options for a specific command"),e.push(""),t.commands?.length&&(e.push(`Available commands: ${t.commands.join(", ")}`),e.push("")),t.network&&(e.push("Network access via curl is enabled for this environment."),e.push("")),t.extraInstructions&&e.push(t.extraInstructions),e.join(`
|
|
614
|
+
`).trim()}var V0=Fu.object({command:Fu.string().describe("The bash command to execute")});function hC(t={}){let e=new wn({fs:t.fs,files:t.fs?void 0:t.files,env:t.env,cwd:t.cwd,network:t.network,commands:t.commands,customCommands:t.customCommands,logger:t.logger});return j0({description:q0(t),inputSchema:G0(V0),execute:async({command:r})=>{t.onCall?.(r);let n=await e.exec(r);return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}}})}export{hC as createBashTool};
|
|
615
|
+
/*! Bundled license information:
|
|
616
|
+
|
|
617
|
+
ieee754/index.js:
|
|
618
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
619
|
+
*/
|