just-bash 1.4.0 → 1.4.2

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.
@@ -1,6 +1,6 @@
1
- var qu=Object.create;var Cn=Object.defineProperty;var Vu=Object.getOwnPropertyDescriptor;var Zu=Object.getOwnPropertyNames;var Qu=Object.getPrototypeOf,Xu=Object.prototype.hasOwnProperty;var An=(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 wt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$=(t,e)=>{for(var r in e)Cn(t,r,{get:e[r],enumerable:!0})},Ku=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Zu(e))!Xu.call(t,s)&&s!==r&&Cn(t,s,{get:()=>e[s],enumerable:!(n=Vu(e,s))||n.enumerable});return t};var hi=(t,e,r)=>(r=t!=null?qu(Qu(t)):{},Ku(e||!t||!t.__esModule?Cn(r,"default",{value:t,enumerable:!0}):r,t));var mi={};$(mi,{echoCommand:()=>Yu});function Ju(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 o=parseInt(s,8)%256;e+=String.fromCharCode(o)}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 o=parseInt(s,16);e+=String.fromCharCode(o),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 o=parseInt(s,16);e+=String.fromCodePoint(o),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 o=parseInt(s,16);try{e+=String.fromCodePoint(o)}catch{e+=`\\U${s}`}r=i}break}default:e+=`\\${n}`,r+=2}}else e+=t[r],r++;return{output:e,stop:!1}}var Yu,gi=C(()=>{"use strict";Yu={name:"echo",async execute(t,e){let r=!1,n=!1,s=0;for(;s<t.length;){let o=t[s];if(o==="-n")r=!0,s++;else if(o==="-e")n=!0,s++;else if(o==="-E")n=!1,s++;else if(o==="-ne"||o==="-en")r=!0,n=!0,s++;else break}let i=t.slice(s).join(" ");if(n){let o=Ju(i);if(i=o.output,o.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}
1
+ var cf=Object.create;var In=Object.defineProperty;var lf=Object.getOwnPropertyDescriptor;var uf=Object.getOwnPropertyNames;var ff=Object.getPrototypeOf,pf=Object.prototype.hasOwnProperty;var vn=(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 A=(t,e)=>()=>(t&&(e=t(t=0)),e);var St=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$=(t,e)=>{for(var r in e)In(t,r,{get:e[r],enumerable:!0})},df=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of uf(e))!pf.call(t,s)&&s!==r&&In(t,s,{get:()=>e[s],enumerable:!(n=lf(e,s))||n.enumerable});return t};var Si=(t,e,r)=>(r=t!=null?cf(ff(t)):{},df(e||!t||!t.__esModule?In(r,"default",{value:t,enumerable:!0}):r,t));var Ai={};$(Ai,{echoCommand:()=>mf});function hf(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 o=parseInt(s,8)%256;e+=String.fromCharCode(o)}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 o=parseInt(s,16);e+=String.fromCharCode(o),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 o=parseInt(s,16);e+=String.fromCodePoint(o),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 o=parseInt(s,16);try{e+=String.fromCodePoint(o)}catch{e+=`\\U${s}`}r=i}break}default:e+=`\\${n}`,r+=2}}else e+=t[r],r++;return{output:e,stop:!1}}var mf,Ci=A(()=>{"use strict";mf={name:"echo",async execute(t,e){let r=!1,n=!1,s=0;for(;s<t.length;){let o=t[s];if(o==="-n")r=!0,s++;else if(o==="-e")n=!0,s++;else if(o==="-E")n=!1,s++;else if(o==="-ne"||o==="-en")r=!0,n=!0,s++;else break}let i=t.slice(s).join(" ");if(n){let o=hf(i);if(i=o.output,o.stop)return{stdout:i,stderr:"",exitCode:0}}return r||(i+=`
3
+ `),{stdout:i,stderr:"",exitCode:0}}}});function N(t){let e=`${t.name} - ${t.summary}
4
4
 
5
5
  `;if(e+=`Usage: ${t.usage}
6
6
  `,t.description){if(e+=`
@@ -19,176 +19,176 @@ 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 v(t){return t.includes("--help")}function T(t,e){return{stdout:"",stderr:e.startsWith("--")?`${t}: unrecognized option '${e}'
22
+ `}return{stdout:e,stderr:"",exitCode:0}}function I(t){return t.includes("--help")}function L(t,e){return{stdout:"",stderr:e.startsWith("--")?`${t}: unrecognized option '${e}'
23
23
  `:`${t}: invalid option -- '${e.replace(/^-/,"")}'
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 o=[],a=!1;for(let l=0;l<e.length;l++){let c=e[l];if(a||!c.startsWith("-")||c==="-"){o.push(c);continue}if(c==="--"){a=!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 p=s.get(f);if(!p)return{ok:!1,error:T(t,c)};let{name:h,type:w}=p;if(w==="boolean")i[h]=!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[h]=w==="number"?parseInt(d,10):d}}else{let u=c.slice(1);for(let f=0;f<u.length;f++){let d=u[f],p=n.get(d);if(!p)return{ok:!1,error:T(t,`-${d}`)};let{name:h,type:w}=p;if(w==="boolean")i[h]=!0;else{let g;if(f+1<u.length)g=u.slice(f+1);else if(l+1<e.length)g=e[++l];else return{ok:!1,error:{stdout:"",stderr:`${t}: option requires an argument -- '${d}'
26
- `,exitCode:1}};i[h]=w==="number"?parseInt(g,10):g;break}}}}return{ok:!0,result:{flags:i,positional:o}}}var ue=C(()=>{"use strict";M()});async function zt(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 o=[],a="",l=0;for(let c of e){if(s&&c==="-"){o.push({filename:"-",content:t.stdin});continue}try{let u=t.fs.resolvePath(t.cwd,c),f=await t.fs.readFile(u);o.push({filename:c,content:f})}catch{if(a+=`${n}: ${c}: No such file or directory
27
- `,l=1,i)return{files:o,stderr:a,exitCode:l}}}return{files:o,stderr:a,exitCode:l}}async function Et(t,e,r){let n=await zt(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 bt=C(()=>{"use strict"});var xi={};$(xi,{catCommand:()=>rf});function nf(t,e){let r=t.split(`
24
+ `,exitCode:1}}var _=A(()=>{"use strict"});function G(t,e,r){let n=new Map,s=new Map;for(let[c,l]of Object.entries(r)){let u={name:c,type:l.type};l.short&&n.set(l.short,u),l.long&&s.set(l.long,u)}let i={};for(let[c,l]of Object.entries(r))l.default!==void 0?i[c]=l.default:l.type==="boolean"&&(i[c]=!1);let o=[],a=!1;for(let c=0;c<e.length;c++){let l=e[c];if(a||!l.startsWith("-")||l==="-"){o.push(l);continue}if(l==="--"){a=!0;continue}if(l.startsWith("--")){let u=l.indexOf("="),f,p;u!==-1?(f=l.slice(2,u),p=l.slice(u+1)):f=l.slice(2);let d=s.get(f);if(!d)return{ok:!1,error:L(t,l)};let{name:h,type:g}=d;if(g==="boolean")i[h]=!0;else{if(p===void 0){if(c+1>=e.length)return{ok:!1,error:{stdout:"",stderr:`${t}: option '--${f}' requires an argument
25
+ `,exitCode:1}};p=e[++c]}i[h]=g==="number"?parseInt(p,10):p}}else{let u=l.slice(1);for(let f=0;f<u.length;f++){let p=u[f],d=n.get(p);if(!d)return{ok:!1,error:L(t,`-${p}`)};let{name:h,type:g}=d;if(g==="boolean")i[h]=!0;else{let y;if(f+1<u.length)y=u.slice(f+1);else if(c+1<e.length)y=e[++c];else return{ok:!1,error:{stdout:"",stderr:`${t}: option requires an argument -- '${p}'
26
+ `,exitCode:1}};i[h]=g==="number"?parseInt(y,10):y;break}}}}return{ok:!0,result:{flags:i,positional:o}}}var fe=A(()=>{"use strict";_()});async function qt(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 o=[],a="",c=0;for(let l of e){if(s&&l==="-"){o.push({filename:"-",content:t.stdin});continue}try{let u=t.fs.resolvePath(t.cwd,l),f=await t.fs.readFile(u);o.push({filename:l,content:f})}catch{if(a+=`${n}: ${l}: No such file or directory
27
+ `,c=1,i)return{files:o,stderr:a,exitCode:c}}}return{files:o,stderr:a,exitCode:c}}async function At(t,e,r){let n=await qt(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 Ct=A(()=>{"use strict"});var ki={};$(ki,{catCommand:()=>xf});function wf(t,e){let r=t.split(`
28
28
  `),n=t.endsWith(`
29
29
  `),s=n?r.slice(0,-1):r;return{content:s.map((o,a)=>`${String(e+a).padStart(6," ")} ${o}`).join(`
30
30
  `)+(n?`
31
- `:""),nextLineNumber:e+s.length}}var ef,tf,rf,yi=C(()=>{"use strict";ue();bt();M();ef={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"]},tf={number:{short:"n",long:"number",type:"boolean"}},rf={name:"cat",async execute(t,e){if(v(t))return k(ef);let r=j("cat",t,tf);if(!r.ok)return r.error;let n=r.result.flags.number,s=r.result.positional,i=await zt(e,s,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),o="",a=1;for(let{content:l}of i.files)if(n){let c=nf(l,a);o+=c.content,a=c.nextLineNumber}else o+=l;return{stdout:o,stderr:i.stderr,exitCode:i.exitCode}}}});function te(t){return t instanceof Error?t.message:String(t)}var _e=C(()=>{"use strict"});function mr(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 wi(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 gr(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 kn=C(()=>{"use strict"});var bi={};$(bi,{printfCommand:()=>of});import{sprintf as St}from"sprintf-js";function af(t,e,r){let n="",s=0,i=0,o=!1,a="";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 p=t.slice(l,s);if(c){let b=parseInt(e[r+i]||"0",10);i++,p=p.replace("*",String(b))}if(u){let b=parseInt(e[r+i]||"0",10);i++,p=p.replace(".*",`.${b}`)}let h=e[r+i]||"";i++;let{value:w,parseError:g,parseErrMsg:y,stopped:E}=lf(p,f,h);if(n+=w,g&&(o=!0,y&&(a=y)),E)return{result:n,argsConsumed:i,error:o,errMsg:a,stopped:!0}}else n+=t[s],s++;return{result:n,argsConsumed:i,error:o,errMsg:a,stopped:!1}}function lf(t,e,r){let n=!1,s="";switch(e){case"d":case"i":{let i=xr(r);return n=Be,n&&(s=`printf: ${r}: invalid number
33
- `),{value:Ei(t,i),parseError:n,parseErrMsg:s}}case"o":{let i=xr(r);return n=Be,n&&(s=`printf: ${r}: invalid number
34
- `),{value:cf(t,i),parseError:n,parseErrMsg:s}}case"u":{let i=xr(r);n=Be,n&&(s=`printf: ${r}: invalid number
35
- `);let o=i<0?i>>>0:i;return{value:Ei(t.replace("u","d"),o),parseError:n,parseErrMsg:s}}case"x":case"X":{let i=xr(r);return n=Be,n&&(s=`printf: ${r}: invalid number
36
- `),{value:uf(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:hf(t,e,i),parseError:!1,parseErrMsg:""}}case"c":return{value:r.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:df(t,r),parseError:!1,parseErrMsg:""};case"q":return{value:pf(t,r),parseError:!1,parseErrMsg:""};case"b":{let i=mf(r);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:St(t,r),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
37
- `}}}}function xr(t){Be=!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)?(Be=!0,0):(r&&(Be=!0),n)}if(t.startsWith("0")&&t.length>1&&/^-?0[0-7]+$/.test(t))return r&&(Be=!0),parseInt(t,8)||0;if(/^\d+#/.test(t)){Be=!0;let n=t.match(/^(\d+)#/);return n?parseInt(n[1],10):0}if(t!==""&&!/^-?\d+$/.test(t)){Be=!0;let n=parseInt(t,10);return Number.isNaN(n)?0:n}return r&&(Be=!0),parseInt(t,10)||0}function Ei(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!r)return St(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,o=e<0,a=Math.abs(e),l=String(a);i>=0&&(l=l.padStart(i,"0"));let c="";o?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 cf(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!r)return St(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,o=Math.abs(e).toString(8);i>=0&&(o=o.padStart(i,"0")),n.includes("#")&&!o.startsWith("0")&&(o=`0${o}`);let a=o;return s>a.length&&(n.includes("-")?a=a.padEnd(s," "):n.includes("0")&&i<0?a=a.padStart(s,"0"):a=a.padStart(s," ")),a}function uf(t,e){let r=t.includes("X"),n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!n)return St(t,e);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,o=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,a=Math.abs(e).toString(16);r&&(a=a.toUpperCase()),o>=0&&(a=a.padStart(o,"0"));let l="";s.includes("#")&&e!==0&&(l=r?"0X":"0x");let c=l+a;return i>c.length&&(s.includes("-")?c=c.padEnd(i," "):s.includes("0")&&o<0?c=l+a.padStart(i-l.length,"0"):c=c.padStart(i," ")),c}function ff(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 df(t,e){let r=t.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!r)return St(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,o=n?-s:s;return mr(e,o,i)}function pf(t,e){let r=ff(e),n=t.match(/^%(-?)(\d*)q$/);if(!n)return r;let s=n[1]==="-",i=n[2]?parseInt(n[2],10):0,o=r;return i>o.length&&(s?o=o.padEnd(i," "):o=o.padStart(i," ")),o}function hf(t,e,r){let n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!n)return St(t,r);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,o=n[3]!==void 0?n[4]?parseInt(n[4],10):0:6,a,l=e.toLowerCase();if(l==="e"?(a=r.toExponential(o),a=a.replace(/e([+-])(\d)$/,"e$10$2"),e==="E"&&(a=a.toUpperCase())):l==="f"?(a=r.toFixed(o),s.includes("#")&&o===0&&!a.includes(".")&&(a+=".")):l==="g"?(a=r.toPrecision(o||1),s.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),e==="G"&&(a=a.toUpperCase())):a=r.toString(),r>=0&&(s.includes("+")?a=`+${a}`:s.includes(" ")&&(a=` ${a}`)),i>a.length)if(s.includes("-"))a=a.padEnd(i," ");else if(s.includes("0")){let c=a.match(/^[+ -]/)?.[0]||"",u=c?a.slice(1):a;a=c+u.padStart(i-c.length,"0")}else a=a.padStart(i," ");return a}function mf(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 sf,of,Be,Si=C(()=>{"use strict";_e();M();kn();sf={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)"]},of={name:"printf",async execute(t,e){if(v(t))return k(sf);if(t.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
31
+ `:""),nextLineNumber:e+s.length}}var yf,gf,xf,Ni=A(()=>{"use strict";fe();Ct();_();yf={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"]},gf={number:{short:"n",long:"number",type:"boolean"}},xf={name:"cat",async execute(t,e){if(I(t))return N(yf);let r=G("cat",t,gf);if(!r.ok)return r.error;let n=r.result.flags.number,s=r.result.positional,i=await qt(e,s,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),o="",a=1;for(let{content:c}of i.files)if(n){let l=wf(c,a);o+=l.content,a=l.nextLineNumber}else o+=c;return{stdout:o,stderr:i.stderr,exitCode:i.exitCode}}}});function re(t){return t instanceof Error?t.message:String(t)}var We=A(()=>{"use strict"});function gr(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 Ii(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 xr(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 Rn=A(()=>{"use strict"});var Ri={};$(Ri,{printfCommand:()=>bf});import{sprintf as kt}from"sprintf-js";function Sf(t,e,r){let n="",s=0,i=0,o=!1,a="";for(;s<t.length;)if(t[s]==="%"&&s+1<t.length){let c=s;if(s++,t[s]==="%"){n+="%",s++;continue}for(;s<t.length&&"+-0 #'".includes(t[s]);)s++;let l=!1;if(t[s]==="*")l=!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 d=t.slice(c,s);if(l){let b=parseInt(e[r+i]||"0",10);i++,d=d.replace("*",String(b))}if(u){let b=parseInt(e[r+i]||"0",10);i++,d=d.replace(".*",`.${b}`)}let h=e[r+i]||"";i++;let{value:g,parseError:y,parseErrMsg:w,stopped:E}=Af(d,f,h);if(n+=g,y&&(o=!0,w&&(a=w)),E)return{result:n,argsConsumed:i,error:o,errMsg:a,stopped:!0}}else n+=t[s],s++;return{result:n,argsConsumed:i,error:o,errMsg:a,stopped:!1}}function Af(t,e,r){let n=!1,s="";switch(e){case"d":case"i":{let i=wr(r);return n=Ue,n&&(s=`printf: ${r}: invalid number
33
+ `),{value:vi(t,i),parseError:n,parseErrMsg:s}}case"o":{let i=wr(r);return n=Ue,n&&(s=`printf: ${r}: invalid number
34
+ `),{value:Cf(t,i),parseError:n,parseErrMsg:s}}case"u":{let i=wr(r);n=Ue,n&&(s=`printf: ${r}: invalid number
35
+ `);let o=i<0?i>>>0:i;return{value:vi(t.replace("u","d"),o),parseError:n,parseErrMsg:s}}case"x":case"X":{let i=wr(r);return n=Ue,n&&(s=`printf: ${r}: invalid number
36
+ `),{value:kf(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:Rf(t,e,i),parseError:!1,parseErrMsg:""}}case"c":return{value:r.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:If(t,r),parseError:!1,parseErrMsg:""};case"q":return{value:vf(t,r),parseError:!1,parseErrMsg:""};case"b":{let i=$f(r);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:kt(t,r),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
37
+ `}}}}function wr(t){Ue=!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)?(Ue=!0,0):(r&&(Ue=!0),n)}if(t.startsWith("0")&&t.length>1&&/^-?0[0-7]+$/.test(t))return r&&(Ue=!0),parseInt(t,8)||0;if(/^\d+#/.test(t)){Ue=!0;let n=t.match(/^(\d+)#/);return n?parseInt(n[1],10):0}if(t!==""&&!/^-?\d+$/.test(t)){Ue=!0;let n=parseInt(t,10);return Number.isNaN(n)?0:n}return r&&(Ue=!0),parseInt(t,10)||0}function vi(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!r)return kt(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,o=e<0,a=Math.abs(e),c=String(a);i>=0&&(c=c.padStart(i,"0"));let l="";o?l="-":n.includes("+")?l="+":n.includes(" ")&&(l=" ");let u=l+c;return s>u.length&&(n.includes("-")?u=u.padEnd(s," "):n.includes("0")&&i<0?u=l+c.padStart(s-l.length,"0"):u=u.padStart(s," ")),u}function Cf(t,e){let r=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!r)return kt(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,o=Math.abs(e).toString(8);i>=0&&(o=o.padStart(i,"0")),n.includes("#")&&!o.startsWith("0")&&(o=`0${o}`);let a=o;return s>a.length&&(n.includes("-")?a=a.padEnd(s," "):n.includes("0")&&i<0?a=a.padStart(s,"0"):a=a.padStart(s," ")),a}function kf(t,e){let r=t.includes("X"),n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!n)return kt(t,e);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,o=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,a=Math.abs(e).toString(16);r&&(a=a.toUpperCase()),o>=0&&(a=a.padStart(o,"0"));let c="";s.includes("#")&&e!==0&&(c=r?"0X":"0x");let l=c+a;return i>l.length&&(s.includes("-")?l=l.padEnd(i," "):s.includes("0")&&o<0?l=c+a.padStart(i-c.length,"0"):l=l.padStart(i," ")),l}function Nf(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 If(t,e){let r=t.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!r)return kt(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,o=n?-s:s;return gr(e,o,i)}function vf(t,e){let r=Nf(e),n=t.match(/^%(-?)(\d*)q$/);if(!n)return r;let s=n[1]==="-",i=n[2]?parseInt(n[2],10):0,o=r;return i>o.length&&(s?o=o.padEnd(i," "):o=o.padStart(i," ")),o}function Rf(t,e,r){let n=t.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!n)return kt(t,r);let s=n[1]||"",i=n[2]?parseInt(n[2],10):0,o=n[3]!==void 0?n[4]?parseInt(n[4],10):0:6,a,c=e.toLowerCase();if(c==="e"?(a=r.toExponential(o),a=a.replace(/e([+-])(\d)$/,"e$10$2"),e==="E"&&(a=a.toUpperCase())):c==="f"?(a=r.toFixed(o),s.includes("#")&&o===0&&!a.includes(".")&&(a+=".")):c==="g"?(a=r.toPrecision(o||1),s.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),e==="G"&&(a=a.toUpperCase())):a=r.toString(),r>=0&&(s.includes("+")?a=`+${a}`:s.includes(" ")&&(a=` ${a}`)),i>a.length)if(s.includes("-"))a=a.padEnd(i," ");else if(s.includes("0")){let l=a.match(/^[+ -]/)?.[0]||"",u=l?a.slice(1):a;a=l+u.padStart(i-l.length,"0")}else a=a.padStart(i," ");return a}function $f(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 Ef,bf,Ue,$i=A(()=>{"use strict";We();_();Rn();Ef={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)"]},bf={name:"printf",async execute(t,e){if(I(t))return N(Ef);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 o=t[n];if(o==="--"){n++;break}if(o==="-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(o.startsWith("-")&&o!=="-")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 o=gr(s),a="",l=0,c=!1,u="";do{let{result:f,argsConsumed:d,error:p,errMsg:h,stopped:w}=af(o,i,l);if(a+=f,l+=d,p&&(c=!0,h&&(u=h)),w)break}while(l<i.length&&l>0);return l===0&&i.length>0,r?(e.env[r]=a,{stdout:"",stderr:u,exitCode:c?1:0}):{stdout:a,stderr:u,exitCode:c?1:0}}catch(o){return{stdout:"",stderr:`printf: ${te(o)}
44
- `,exitCode:1}}}};Be=!1});var ki={};$(ki,{lsCommand:()=>yf});import{minimatch as Ci}from"minimatch";function yr(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 wr(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 a=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${r} ${n} ${a}:${l}`}let o=t.getFullYear();return`${r} ${n} ${o}`}async function wf(t,e,r,n,s,i=!1,o=!1,a=!1){let l=r||n,c=e.fs.getAllPaths(),u=e.fs.resolvePath(e.cwd,"."),f=[];for(let d of c){let p=d.startsWith(u)&&d.slice(u.length+1)||d;if(Ci(p,t)||Ci(d,t)){let h=p.split("/").pop()||p;if(!l&&h.startsWith("."))continue;f.push(p||d)}}if(f.length===0)return{stdout:"",stderr:`ls: ${t}: No such file or directory
45
- `,exitCode:2};if(a){let d=[];for(let p of f){let h=e.fs.resolvePath(e.cwd,p);try{let w=await e.fs.stat(h);d.push({path:p,size:w.size??0})}catch{d.push({path:p,size:0})}}d.sort((p,h)=>h.size-p.size),f.length=0,f.push(...d.map(p=>p.path))}else f.sort();if(i&&f.reverse(),s){let d=[];for(let p of f){let h=e.fs.resolvePath(e.cwd,p);try{let w=await e.fs.stat(h),g=w.isDirectory?"drwxr-xr-x":"-rw-r--r--",y=w.isDirectory?"/":"",E=w.size??0,b=o?yr(E).padStart(5):String(E).padStart(5),S=w.mtime??new Date(0),A=wr(S);d.push(`${g} 1 user user ${b} ${A} ${p}${y}`)}catch{d.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${p}`)}}return{stdout:`${d.join(`
43
+ `,exitCode:1};let s=t[n],i=t.slice(n+1);try{let o=xr(s),a="",c=0,l=!1,u="";do{let{result:f,argsConsumed:p,error:d,errMsg:h,stopped:g}=Sf(o,i,c);if(a+=f,c+=p,d&&(l=!0,h&&(u=h)),g)break}while(c<i.length&&c>0);return c===0&&i.length>0,r?(e.env[r]=a,{stdout:"",stderr:u,exitCode:l?1:0}):{stdout:a,stderr:u,exitCode:l?1:0}}catch(o){return{stdout:"",stderr:`printf: ${re(o)}
44
+ `,exitCode:1}}}};Ue=!1});var Ti={};$(Ti,{lsCommand:()=>Tf});import{minimatch as Oi}from"minimatch";function Er(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 br(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 a=String(t.getHours()).padStart(2,"0"),c=String(t.getMinutes()).padStart(2,"0");return`${r} ${n} ${a}:${c}`}let o=t.getFullYear();return`${r} ${n} ${o}`}async function Ff(t,e,r,n,s,i=!1,o=!1,a=!1){let c=r||n,l=e.fs.getAllPaths(),u=e.fs.resolvePath(e.cwd,"."),f=[];for(let p of l){let d=p.startsWith(u)&&p.slice(u.length+1)||p;if(Oi(d,t)||Oi(p,t)){let h=d.split("/").pop()||d;if(!c&&h.startsWith("."))continue;f.push(d||p)}}if(f.length===0)return{stdout:"",stderr:`ls: ${t}: No such file or directory
45
+ `,exitCode:2};if(a){let p=[];for(let d of f){let h=e.fs.resolvePath(e.cwd,d);try{let g=await e.fs.stat(h);p.push({path:d,size:g.size??0})}catch{p.push({path:d,size:0})}}p.sort((d,h)=>h.size-d.size),f.length=0,f.push(...p.map(d=>d.path))}else f.sort();if(i&&f.reverse(),s){let p=[];for(let d of f){let h=e.fs.resolvePath(e.cwd,d);try{let g=await e.fs.stat(h),y=g.isDirectory?"drwxr-xr-x":"-rw-r--r--",w=g.isDirectory?"/":"",E=g.size??0,b=o?Er(E).padStart(5):String(E).padStart(5),S=g.mtime??new Date(0),C=br(S);p.push(`${y} 1 user user ${b} ${C} ${d}${w}`)}catch{p.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${d}`)}}return{stdout:`${p.join(`
46
46
  `)}
47
47
  `,stderr:"",exitCode:0}}return{stdout:`${f.join(`
48
48
  `)}
49
- `,stderr:"",exitCode:0}}async function Ai(t,e,r,n,s,i,o,a=!1,l=!1,c=!1,u=!1){let f=r||n,d=e.fs.resolvePath(e.cwd,t);try{let p=await e.fs.stat(d);if(!p.isDirectory){if(s){let g=p.size??0,y=l?yr(g).padStart(5):String(g).padStart(5),E=p.mtime??new Date(0),b=wr(E);return{stdout:`-rw-r--r-- 1 user user ${y} ${b} ${t}
49
+ `,stderr:"",exitCode:0}}async function Pi(t,e,r,n,s,i,o,a=!1,c=!1,l=!1,u=!1){let f=r||n,p=e.fs.resolvePath(e.cwd,t);try{let d=await e.fs.stat(p);if(!d.isDirectory){if(s){let y=d.size??0,w=c?Er(y).padStart(5):String(y).padStart(5),E=d.mtime??new Date(0),b=br(E);return{stdout:`-rw-r--r-- 1 user user ${w} ${b} ${t}
50
50
  `,stderr:"",exitCode:0}}return{stdout:`${t}
51
- `,stderr:"",exitCode:0}}let h=await e.fs.readdir(d);if(f||(h=h.filter(g=>!g.startsWith("."))),c){let g=[];for(let y of h){let E=d==="/"?`/${y}`:`${d}/${y}`;try{let b=await e.fs.stat(E);g.push({name:y,size:b.size??0})}catch{g.push({name:y,size:0})}}g.sort((y,E)=>E.size-y.size),h=g.map(y=>y.name)}else h.sort();r&&(h=[".","..",...h]),a&&h.reverse();let w="";if((i||o)&&(w+=`${t}:
52
- `),s){w+=`total ${h.length}
53
- `;for(let g of h){if(g==="."||g===".."){w+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${g}
54
- `;continue}let y=d==="/"?`/${g}`:`${d}/${g}`;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?yr(A).padStart(5):String(A).padStart(5),P=E.mtime??new Date(0),F=wr(P);w+=`${b} 1 user user ${D} ${F} ${g}${S}
55
- `}catch{w+=`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${g}
56
- `}}}else w+=h.join(`
51
+ `,stderr:"",exitCode:0}}let h=await e.fs.readdir(p);if(f||(h=h.filter(y=>!y.startsWith("."))),l){let y=[];for(let w of h){let E=p==="/"?`/${w}`:`${p}/${w}`;try{let b=await e.fs.stat(E);y.push({name:w,size:b.size??0})}catch{y.push({name:w,size:0})}}y.sort((w,E)=>E.size-w.size),h=y.map(w=>w.name)}else h.sort();r&&(h=[".","..",...h]),a&&h.reverse();let g="";if((i||o)&&(g+=`${t}:
52
+ `),s){g+=`total ${h.length}
53
+ `;for(let y of h){if(y==="."||y===".."){g+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${y}
54
+ `;continue}let w=p==="/"?`/${y}`:`${p}/${y}`;try{let E=await e.fs.stat(w),b=E.isDirectory?"drwxr-xr-x":"-rw-r--r--",S=E.isDirectory?"/":"",C=E.size??0,O=c?Er(C).padStart(5):String(C).padStart(5),D=E.mtime??new Date(0),F=br(D);g+=`${b} 1 user user ${O} ${F} ${y}${S}
55
+ `}catch{g+=`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${y}
56
+ `}}}else g+=h.join(`
57
57
  `)+(h.length?`
58
- `:"");if(i)for(let g of h){if(g==="."||g==="..")continue;let y=d==="/"?`/${g}`:`${d}/${g}`;try{if((await e.fs.stat(y)).isDirectory){w+=`
59
- `;let b=t==="."?`./${g}`:`${t}/${g}`,S=await Ai(b,e,r,n,s,i,!1,a,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 gf,xf,yf,vi=C(()=>{"use strict";ue();M();gf={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"]},xf={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"}},yf={name:"ls",async execute(t,e){if(v(t))return k(gf);let r=j("ls",t,xf);if(!r.ok)return r.error;let n=r.result.flags.showAll,s=r.result.flags.showAlmostAll,i=r.result.flags.longFormat,o=r.result.flags.humanReadable,a=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 p="",h="",w=0;for(let g=0;g<d.length;g++){let y=d[g];if(g>0&&p&&!p.endsWith(`
58
+ `:"");if(i)for(let y of h){if(y==="."||y==="..")continue;let w=p==="/"?`/${y}`:`${p}/${y}`;try{if((await e.fs.stat(w)).isDirectory){g+=`
59
+ `;let b=t==="."?`./${y}`:`${t}/${y}`,S=await Pi(b,e,r,n,s,i,!1,a,c,l,!0);g+=S.stdout}}catch{}}return{stdout:g,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${t}: No such file or directory
60
+ `,exitCode:2}}}var Of,Pf,Tf,Fi=A(()=>{"use strict";fe();_();Of={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"]},Pf={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"}},Tf={name:"ls",async execute(t,e){if(I(t))return N(Of);let r=G("ls",t,Pf);if(!r.ok)return r.error;let n=r.result.flags.showAll,s=r.result.flags.showAlmostAll,i=r.result.flags.longFormat,o=r.result.flags.humanReadable,a=r.result.flags.recursive,c=r.result.flags.reverse,l=r.result.flags.sortBySize,u=r.result.flags.directoryOnly,f=r.result.flags.sortByTime;r.result.flags.onePerLine;let p=r.result.positional;p.length===0&&p.push(".");let d="",h="",g=0;for(let y=0;y<p.length;y++){let w=p[y];if(y>0&&d&&!d.endsWith(`
61
61
 
62
- `)&&(p+=`
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,P=o?yr(D).padStart(5):String(D).padStart(5),F=b.mtime??new Date(0),B=wr(F);p+=`${S} 1 user user ${P} ${B} ${y}${A}
64
- `}else p+=`${y}
65
- `}catch{h+=`ls: cannot access '${y}': No such file or directory
66
- `,w=2}continue}if(y.includes("*")||y.includes("?")||y.includes("[")){let E=await wf(y,e,n,s,i,l,o,c);p+=E.stdout,h+=E.stderr,E.exitCode!==0&&(w=E.exitCode)}else{let E=await Ai(y,e,n,s,i,a,d.length>1,l,o,c);p+=E.stdout,h+=E.stderr,E.exitCode!==0&&(w=E.exitCode)}}return{stdout:p,stderr:h,exitCode:w}}}});var Ni={};$(Ni,{mkdirCommand:()=>bf});var Ef,bf,Ii=C(()=>{"use strict";_e();ue();Ef={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},bf={name:"mkdir",async execute(t,e){let r=j("mkdir",t,Ef);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 o="",a="",l=0;for(let c of i)try{let u=e.fs.resolvePath(e.cwd,c);await e.fs.mkdir(u,{recursive:n}),s&&(o+=`mkdir: created directory '${c}'
68
- `)}catch(u){let f=te(u);f.includes("ENOENT")||f.includes("no such file")?a+=`mkdir: cannot create directory '${c}': No such file or directory
69
- `:f.includes("EEXIST")||f.includes("already exists")?a+=`mkdir: cannot create directory '${c}': File exists
70
- `:a+=`mkdir: cannot create directory '${c}': ${f}
71
- `,l=1}return{stdout:o,stderr:a,exitCode:l}}}});var $i={};$($i,{touchCommand:()=>Sf});var Sf,Ri=C(()=>{"use strict";_e();M();Sf={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 o=e.fs.resolvePath(e.cwd,i);await e.fs.exists(o)||await e.fs.writeFile(o,"")}catch(o){n+=`touch: cannot touch '${i}': ${te(o)}
73
- `,s=1}return{stdout:"",stderr:n,exitCode:s}}}});var Oi={};$(Oi,{rmCommand:()=>Af});var Cf,Af,Fi=C(()=>{"use strict";_e();ue();Cf={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"}},Af={name:"rm",async execute(t,e){let r=j("rm",t,Cf);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,o=r.result.positional;if(o.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
74
- `,exitCode:1};let a="",l="",c=0;for(let u of o)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&&(a+=`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:a,stderr:l,exitCode:c}}}});var Pi={};$(Pi,{cpCommand:()=>Nf});var kf,vf,Nf,Ti=C(()=>{"use strict";_e();ue();M();kf={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"]},vf={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"}},Nf={name:"cp",async execute(t,e){if(v(t))return k(kf);let r=j("cp",t,vf);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,o=r.result.flags.verbose,a=r.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand
80
- `,exitCode:1};let l=a.pop()??"",c=a,u=e.fs.resolvePath(e.cwd,l),f="",d="",p=0,h=!1;try{h=(await e.fs.stat(u)).isDirectory}catch{}if(c.length>1&&!h)return{stdout:"",stderr:`cp: target '${l}' is not a directory
81
- `,exitCode:1};for(let w of c)try{let g=e.fs.resolvePath(e.cwd,w),y=await e.fs.stat(g),E=u;if(h){let b=w.split("/").pop()||w;E=u==="/"?`/${b}`:`${u}/${b}`}if(y.isDirectory&&!n){d+=`cp: -r not specified; omitting directory '${w}'
82
- `,p=1;continue}if(s)try{await e.fs.stat(E);continue}catch{}await e.fs.cp(g,E,{recursive:n}),o&&(f+=`'${w}' -> '${E}'
83
- `)}catch(g){let y=te(g);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
- `,p=1}return{stdout:f,stderr:d,exitCode:p}}}});var Di={};$(Di,{mvCommand:()=>Rf});var If,$f,Rf,Li=C(()=>{"use strict";_e();ue();M();If={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"]},$f={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},Rf={name:"mv",async execute(t,e){if(v(t))return k(If);let r=j("mv",t,$f);if(!r.ok)return r.error;let n=r.result.flags.force,s=r.result.flags.noClobber,i=r.result.flags.verbose,o=r.result.positional;if(s&&(n=!1),o.length<2)return{stdout:"",stderr:`mv: missing destination file operand
86
- `,exitCode:1};let a=o.pop()??"",l=o,c=e.fs.resolvePath(e.cwd,a),u="",f="",d=0,p=!1;try{p=(await e.fs.stat(c)).isDirectory}catch{}if(l.length>1&&!p)return{stdout:"",stderr:`mv: target '${a}' is not a directory
87
- `,exitCode:1};for(let h of l)try{let w=e.fs.resolvePath(e.cwd,h),g=c;if(p){let y=h.split("/").pop()||h;g=c==="/"?`/${y}`:`${c}/${y}`}if(s)try{await e.fs.stat(g);continue}catch{}if(await e.fs.mv(w,g),i){let y=p?`${a}/${h.split("/").pop()||h}`:a;u+=`renamed '${h}' -> '${y}'
88
- `}}catch(w){let g=te(w);g.includes("ENOENT")||g.includes("no such file")?f+=`mv: cannot stat '${h}': No such file or directory
89
- `:f+=`mv: cannot move '${h}': ${g}
90
- `,d=1}return{stdout:u,stderr:f,exitCode:d}}}});var Mi={};$(Mi,{lnCommand:()=>Ff});var Of,Ff,_i=C(()=>{"use strict";M();Of={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"]},Ff={name:"ln",async execute(t,e){if(v(t))return k(Of);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)}'
62
+ `)&&(d+=`
63
+ `),u){let E=e.fs.resolvePath(e.cwd,w);try{let b=await e.fs.stat(E);if(i){let S=b.isDirectory?"drwxr-xr-x":"-rw-r--r--",C=b.isDirectory?"/":"",O=b.size??0,D=o?Er(O).padStart(5):String(O).padStart(5),F=b.mtime??new Date(0),U=br(F);d+=`${S} 1 user user ${D} ${U} ${w}${C}
64
+ `}else d+=`${w}
65
+ `}catch{h+=`ls: cannot access '${w}': No such file or directory
66
+ `,g=2}continue}if(w.includes("*")||w.includes("?")||w.includes("[")){let E=await Ff(w,e,n,s,i,c,o,l);d+=E.stdout,h+=E.stderr,E.exitCode!==0&&(g=E.exitCode)}else{let E=await Pi(w,e,n,s,i,a,p.length>1,c,o,l);d+=E.stdout,h+=E.stderr,E.exitCode!==0&&(g=E.exitCode)}}return{stdout:d,stderr:h,exitCode:g}}}});var Di={};$(Di,{mkdirCommand:()=>Lf});var Df,Lf,Li=A(()=>{"use strict";We();fe();Df={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},Lf={name:"mkdir",async execute(t,e){let r=G("mkdir",t,Df);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 o="",a="",c=0;for(let l of i)try{let u=e.fs.resolvePath(e.cwd,l);await e.fs.mkdir(u,{recursive:n}),s&&(o+=`mkdir: created directory '${l}'
68
+ `)}catch(u){let f=re(u);f.includes("ENOENT")||f.includes("no such file")?a+=`mkdir: cannot create directory '${l}': No such file or directory
69
+ `:f.includes("EEXIST")||f.includes("already exists")?a+=`mkdir: cannot create directory '${l}': File exists
70
+ `:a+=`mkdir: cannot create directory '${l}': ${f}
71
+ `,c=1}return{stdout:o,stderr:a,exitCode:c}}}});var Mi={};$(Mi,{touchCommand:()=>Mf});var Mf,_i=A(()=>{"use strict";We();_();Mf={name:"touch",async execute(t,e){let r=[];for(let i of t){if(i.startsWith("--"))return L("touch",i);if(i.startsWith("-")&&i.length>1)return L("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 o=e.fs.resolvePath(e.cwd,i);await e.fs.exists(o)||await e.fs.writeFile(o,"")}catch(o){n+=`touch: cannot touch '${i}': ${re(o)}
73
+ `,s=1}return{stdout:"",stderr:n,exitCode:s}}}});var Bi={};$(Bi,{rmCommand:()=>Bf});var _f,Bf,Wi=A(()=>{"use strict";We();fe();_f={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"}},Bf={name:"rm",async execute(t,e){let r=G("rm",t,_f);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,o=r.result.positional;if(o.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
74
+ `,exitCode:1};let a="",c="",l=0;for(let u of o)try{let f=e.fs.resolvePath(e.cwd,u);if((await e.fs.stat(f)).isDirectory&&!n){c+=`rm: cannot remove '${u}': Is a directory
75
+ `,l=1;continue}await e.fs.rm(f,{recursive:n,force:s}),i&&(a+=`removed '${u}'
76
+ `)}catch(f){if(!s){let p=re(f);p.includes("ENOENT")||p.includes("no such file")?c+=`rm: cannot remove '${u}': No such file or directory
77
+ `:p.includes("ENOTEMPTY")||p.includes("not empty")?c+=`rm: cannot remove '${u}': Directory not empty
78
+ `:c+=`rm: cannot remove '${u}': ${p}
79
+ `,l=1}}return{stdout:a,stderr:c,exitCode:l}}}});var Ui={};$(Ui,{cpCommand:()=>Hf});var Wf,Uf,Hf,Hi=A(()=>{"use strict";We();fe();_();Wf={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"]},Uf={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"}},Hf={name:"cp",async execute(t,e){if(I(t))return N(Wf);let r=G("cp",t,Uf);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,o=r.result.flags.verbose,a=r.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand
80
+ `,exitCode:1};let c=a.pop()??"",l=a,u=e.fs.resolvePath(e.cwd,c),f="",p="",d=0,h=!1;try{h=(await e.fs.stat(u)).isDirectory}catch{}if(l.length>1&&!h)return{stdout:"",stderr:`cp: target '${c}' is not a directory
81
+ `,exitCode:1};for(let g of l)try{let y=e.fs.resolvePath(e.cwd,g),w=await e.fs.stat(y),E=u;if(h){let b=g.split("/").pop()||g;E=u==="/"?`/${b}`:`${u}/${b}`}if(w.isDirectory&&!n){p+=`cp: -r not specified; omitting directory '${g}'
82
+ `,d=1;continue}if(s)try{await e.fs.stat(E);continue}catch{}await e.fs.cp(y,E,{recursive:n}),o&&(f+=`'${g}' -> '${E}'
83
+ `)}catch(y){let w=re(y);w.includes("ENOENT")||w.includes("no such file")?p+=`cp: cannot stat '${g}': No such file or directory
84
+ `:p+=`cp: cannot copy '${g}': ${w}
85
+ `,d=1}return{stdout:f,stderr:p,exitCode:d}}}});var ji={};$(ji,{mvCommand:()=>Gf});var jf,zf,Gf,zi=A(()=>{"use strict";We();fe();_();jf={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"]},zf={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},Gf={name:"mv",async execute(t,e){if(I(t))return N(jf);let r=G("mv",t,zf);if(!r.ok)return r.error;let n=r.result.flags.force,s=r.result.flags.noClobber,i=r.result.flags.verbose,o=r.result.positional;if(s&&(n=!1),o.length<2)return{stdout:"",stderr:`mv: missing destination file operand
86
+ `,exitCode:1};let a=o.pop()??"",c=o,l=e.fs.resolvePath(e.cwd,a),u="",f="",p=0,d=!1;try{d=(await e.fs.stat(l)).isDirectory}catch{}if(c.length>1&&!d)return{stdout:"",stderr:`mv: target '${a}' is not a directory
87
+ `,exitCode:1};for(let h of c)try{let g=e.fs.resolvePath(e.cwd,h),y=l;if(d){let w=h.split("/").pop()||h;y=l==="/"?`/${w}`:`${l}/${w}`}if(s)try{await e.fs.stat(y);continue}catch{}if(await e.fs.mv(g,y),i){let w=d?`${a}/${h.split("/").pop()||h}`:a;u+=`renamed '${h}' -> '${w}'
88
+ `}}catch(g){let y=re(g);y.includes("ENOENT")||y.includes("no such file")?f+=`mv: cannot stat '${h}': No such file or directory
89
+ `:f+=`mv: cannot move '${h}': ${y}
90
+ `,p=1}return{stdout:u,stderr:f,exitCode:p}}}});var Gi={};$(Gi,{lnCommand:()=>Vf});var qf,Vf,qi=A(()=>{"use strict";_();qf={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"]},Vf={name:"ln",async execute(t,e){if(I(t))return N(qf);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 o=t.slice(i);if(o.length<2)return{stdout:"",stderr:`ln: missing file operand
92
- `,exitCode:1};let a=o[0],l=o[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(a,c);else{let f=e.fs.resolvePath(e.cwd,a);if(!await e.fs.exists(f))return{stdout:"",stderr:`ln: failed to access '${a}': 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: '${a}': hard link not allowed for directory
96
- `,exitCode:1}:{stdout:"",stderr:`ln: ${d.message}
97
- `,exitCode:1}}let u="";return s&&(u=`'${l}' -> '${a}'
98
- `),{stdout:u,stderr:"",exitCode:0}}}});var Wi={};$(Wi,{chmodCommand:()=>Tf});async function Bi(t,e,r,n){let s="",i=await t.fs.readdir(e);for(let o of i){let a=e==="/"?`/${o}`:`${e}/${o}`;await t.fs.chmod(a,r),n&&(s+=`mode of '${a}' changed to ${r.toString(8).padStart(4,"0")}
99
- `),(await t.fs.stat(a)).isDirectory&&(s+=await Bi(t,a,r,n))}return s}function Df(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",o=s[2],a=s[3];(i==="a"||i==="")&&(i="ugo");let l=0;a.includes("r")&&(l|=4),a.includes("w")&&(l|=2),(a.includes("x")||a.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;o==="+"?e|=f:o==="-"?e&=~f:o==="="&&(e&=~(7<<u),e|=f)}}return e}var Pf,Tf,Ui=C(()=>{"use strict";M();Pf={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"]},Tf={name:"chmod",async execute(t,e){if(v(t))return k(Pf);if(t.length<2)return{stdout:"",stderr:`chmod: missing operand
92
+ `,exitCode:1};let a=o[0],c=o[1],l=e.fs.resolvePath(e.cwd,c);if(await e.fs.exists(l))if(n)try{await e.fs.rm(l,{force:!0})}catch{return{stdout:"",stderr:`ln: cannot remove '${c}': Permission denied
93
+ `,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${r?"symbolic ":""}link '${c}': File exists
94
+ `,exitCode:1};try{if(r)await e.fs.symlink(a,l);else{let f=e.fs.resolvePath(e.cwd,a);if(!await e.fs.exists(f))return{stdout:"",stderr:`ln: failed to access '${a}': No such file or directory
95
+ `,exitCode:1};await e.fs.link(f,l)}}catch(f){let p=f;return p.message.includes("EPERM")?{stdout:"",stderr:`ln: '${a}': hard link not allowed for directory
96
+ `,exitCode:1}:{stdout:"",stderr:`ln: ${p.message}
97
+ `,exitCode:1}}let u="";return s&&(u=`'${c}' -> '${a}'
98
+ `),{stdout:u,stderr:"",exitCode:0}}}});var Ki={};$(Ki,{chmodCommand:()=>Zf});async function Vi(t,e,r,n){let s="",i=await t.fs.readdir(e);for(let o of i){let a=e==="/"?`/${o}`:`${e}/${o}`;await t.fs.chmod(a,r),n&&(s+=`mode of '${a}' changed to ${r.toString(8).padStart(4,"0")}
99
+ `),(await t.fs.stat(a)).isDirectory&&(s+=await Vi(t,a,r,n))}return s}function Qf(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",o=s[2],a=s[3];(i==="a"||i==="")&&(i="ugo");let c=0;a.includes("r")&&(c|=4),a.includes("w")&&(c|=2),(a.includes("x")||a.includes("X"))&&(c|=1);for(let l of i){let u=0;l==="u"?u=6:l==="g"?u=3:l==="o"&&(u=0);let f=c<<u;o==="+"?e|=f:o==="-"?e&=~f:o==="="&&(e&=~(7<<u),e|=f)}}return e}var Kf,Zf,Zi=A(()=>{"use strict";_();Kf={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"]},Zf={name:"chmod",async execute(t,e){if(I(t))return N(Kf);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],o=t.slice(s+1),a;try{a=Df(i)}catch{return{stdout:"",stderr:`chmod: invalid mode: '${i}'
103
- `,exitCode:1}}let l="",c="",u=!1;for(let f of o){let d=e.fs.resolvePath(e.cwd,f);try{if(await e.fs.chmod(d,a),n&&(l+=`mode of '${f}' changed to ${a.toString(8).padStart(4,"0")}
104
- `),r&&(await e.fs.stat(d)).isDirectory){let h=await Bi(e,d,a,n);l+=h}}catch{c+=`chmod: cannot access '${f}': No such file or directory
105
- `,u=!0}}return{stdout:l,stderr:c,exitCode:u?1:0}}}});var Hi={};$(Hi,{pwdCommand:()=>Lf});var Lf,zi=C(()=>{"use strict";Lf={name:"pwd",async execute(t,e){return{stdout:`${e.cwd}
106
- `,stderr:"",exitCode:0}}}});var ji={};$(ji,{readlinkCommand:()=>_f});var Mf,_f,Gi=C(()=>{"use strict";M();Mf={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"]},_f={name:"readlink",async execute(t,e){if(v(t))return k(Mf);let r=!1,n=0;for(;n<t.length&&t[n].startsWith("-");){let a=t[n];if(a==="-f"||a==="--canonicalize")r=!0,n++;else if(a==="--"){n++;break}else return{stdout:"",stderr:`readlink: invalid option -- '${a.slice(1)}'
102
+ `,exitCode:1};let i=t[s],o=t.slice(s+1),a;try{a=Qf(i)}catch{return{stdout:"",stderr:`chmod: invalid mode: '${i}'
103
+ `,exitCode:1}}let c="",l="",u=!1;for(let f of o){let p=e.fs.resolvePath(e.cwd,f);try{if(await e.fs.chmod(p,a),n&&(c+=`mode of '${f}' changed to ${a.toString(8).padStart(4,"0")}
104
+ `),r&&(await e.fs.stat(p)).isDirectory){let h=await Vi(e,p,a,n);c+=h}}catch{l+=`chmod: cannot access '${f}': No such file or directory
105
+ `,u=!0}}return{stdout:c,stderr:l,exitCode:u?1:0}}}});var Qi={};$(Qi,{pwdCommand:()=>Xf});var Xf,Xi=A(()=>{"use strict";Xf={name:"pwd",async execute(t,e){return{stdout:`${e.cwd}
106
+ `,stderr:"",exitCode:0}}}});var Ji={};$(Ji,{readlinkCommand:()=>Yf});var Jf,Yf,Yi=A(()=>{"use strict";_();Jf={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"]},Yf={name:"readlink",async execute(t,e){if(I(t))return N(Jf);let r=!1,n=0;for(;n<t.length&&t[n].startsWith("-");){let a=t[n];if(a==="-f"||a==="--canonicalize")r=!0,n++;else if(a==="--"){n++;break}else return{stdout:"",stderr:`readlink: invalid option -- '${a.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="",o=!1;for(let a of s){let l=e.fs.resolvePath(e.cwd,a);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
- `:o=!0}}return{stdout:i,stderr:"",exitCode:o?1:0}}}});function Er(t,e){let r=10,n=null,s=!1,i=!1,o=!1,a=[];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("+")?(o=!0,r=parseInt(u.slice(1),10)):r=parseInt(u,10)}else if(e==="tail"&&c.startsWith("-n+"))o=!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)};a.push(c)}}return n!==null&&(Number.isNaN(n)||n<0)?{ok:!1,error:{stdout:"",stderr:`${e}: invalid number of bytes
108
+ `,exitCode:1};let i="",o=!1;for(let a of s){let c=e.fs.resolvePath(e.cwd,a);try{if(r){let l=c,u=new Set;for(;!u.has(l);){u.add(l);try{let f=await e.fs.readlink(l);if(f.startsWith("/"))l=f;else{let p=l.substring(0,l.lastIndexOf("/"))||"/";l=e.fs.resolvePath(p,f)}}catch{break}}i+=`${l}
109
+ `}else{let l=await e.fs.readlink(c);i+=`${l}
110
+ `}}catch{r?i+=`${c}
111
+ `:o=!0}}return{stdout:i,stderr:"",exitCode:o?1:0}}}});function Sr(t,e){let r=10,n=null,s=!1,i=!1,o=!1,a=[];for(let c=0;c<t.length;c++){let l=t[c];if(l==="-n"&&c+1<t.length){let u=t[++c];e==="tail"&&u.startsWith("+")?(o=!0,r=parseInt(u.slice(1),10)):r=parseInt(u,10)}else if(e==="tail"&&l.startsWith("-n+"))o=!0,r=parseInt(l.slice(3),10);else if(l.startsWith("-n"))r=parseInt(l.slice(2),10);else if(l==="-c"&&c+1<t.length)n=parseInt(t[++c],10);else if(l.startsWith("-c"))n=parseInt(l.slice(2),10);else if(l.startsWith("--bytes="))n=parseInt(l.slice(8),10);else if(l.startsWith("--lines="))r=parseInt(l.slice(8),10);else if(l==="-q"||l==="--quiet"||l==="--silent")s=!0;else if(l==="-v"||l==="--verbose")i=!0;else if(l.match(/^-\d+$/))r=parseInt(l.slice(1),10);else{if(l.startsWith("--"))return{ok:!1,error:L(e,l)};if(l.startsWith("-")&&l!=="-")return{ok:!1,error:L(e,l)};a.push(l)}}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:a,fromLine:o}}}async function br(t,e,r,n){let{quiet:s,verbose:i,files:o}=e;if(o.length===0)return{stdout:n(t.stdin),stderr:"",exitCode:0};let a="",l="",c=0,u=i||!s&&o.length>1;for(let f=0;f<o.length;f++){let d=o[f];u&&(f>0&&(a+=`
114
- `),a+=`==> ${d} <==
115
- `);try{let p=t.fs.resolvePath(t.cwd,d),h=await t.fs.readFile(p);a+=n(h)}catch{l+=`${r}: ${d}: No such file or directory
116
- `,c=1}}return{stdout:a,stderr:l,exitCode:c}}function qi(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 o=t.indexOf(`
113
+ `,exitCode:1}}:{ok:!0,options:{lines:r,bytes:n,quiet:s,verbose:i,files:a,fromLine:o}}}async function Ar(t,e,r,n){let{quiet:s,verbose:i,files:o}=e;if(o.length===0)return{stdout:n(t.stdin),stderr:"",exitCode:0};let a="",c="",l=0,u=i||!s&&o.length>1;for(let f=0;f<o.length;f++){let p=o[f];u&&(f>0&&(a+=`
114
+ `),a+=`==> ${p} <==
115
+ `);try{let d=t.fs.resolvePath(t.cwd,p),h=await t.fs.readFile(d);a+=n(h)}catch{c+=`${r}: ${p}: No such file or directory
116
+ `,l=1}}return{stdout:a,stderr:c,exitCode:l}}function eo(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 o=t.indexOf(`
117
117
  `,n);if(o===-1)return`${t}
118
- `;s++,n=o+1}return n>0?t.slice(0,n):""}function Vi(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(`
118
+ `;s++,n=o+1}return n>0?t.slice(0,n):""}function to(t,e,r,n){if(r!==null)return t.slice(-r);let s=t.length;if(s===0)return"";if(n){let c=0,l=1;for(;c<s&&l<e;){let f=t.indexOf(`
119
+ `,c);if(f===-1)break;l++,c=f+1}let u=t.slice(c);return u.endsWith(`
120
120
  `)?u:`${u}
121
121
  `}if(e===0)return"";let i=s-1;t[i]===`
122
122
  `&&i--;let o=0;for(;i>=0&&o<e;){if(t[i]===`
123
123
  `&&(o++,o===e)){i++;break}i--}i<0&&(i=0);let a=t.slice(i);return t[s-1]===`
124
124
  `?a:`${a}
125
- `}var vn=C(()=>{"use strict";M()});var Zi={};$(Zi,{headCommand:()=>Wf});var Bf,Wf,Qi=C(()=>{"use strict";M();vn();Bf={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"]},Wf={name:"head",async execute(t,e){if(v(t))return k(Bf);let r=Er(t,"head");if(!r.ok)return r.error;let{lines:n,bytes:s}=r.options;return br(e,r.options,"head",i=>qi(i,n,s))}}});var Xi={};$(Xi,{tailCommand:()=>Hf});var Uf,Hf,Ki=C(()=>{"use strict";vn();M();Uf={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"]},Hf={name:"tail",async execute(t,e){if(v(t))return k(Uf);let r=Er(t,"tail");if(!r.ok)return r.error;let{lines:n,bytes:s,fromLine:i}=r.options;return br(e,r.options,"tail",o=>Vi(o,n,s,i??!1))}}});var Yi={};$(Yi,{wcCommand:()=>Gf});function Ji(t){let e=t.length,r=0,n=0,s=!1;for(let i=0;i<e;i++){let o=t[i];o===`
126
- `?(r++,s&&(n++,s=!1)):o===" "||o===" "||o==="\r"?s&&(n++,s=!1):s=!0}return s&&n++,{lines:r,words:n,chars:e}}function Nn(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 o=i.join(" ");return s&&(o+=` ${s}`),o}var zf,jf,Gf,eo=C(()=>{"use strict";ue();bt();M();zf={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"]},jf={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"}},Gf={name:"wc",async execute(t,e){if(v(t))return k(zf);let r=j("wc",t,jf);if(!r.ok)return r.error;let{lines:n,words:s}=r.result.flags,i=r.result.flags.bytes||r.result.flags.chars,o=r.result.positional;!n&&!s&&!i&&(n=s=i=!0);let a=await zt(e,o,{cmdName:"wc",stopOnError:!1});if(o.length===0){let d=Ji(a.files[0].content);return{stdout:`${Nn(d,n,s,i,"")}
127
- `,stderr:"",exitCode:0}}let l="",c=0,u=0,f=0;for(let{filename:d,content:p}of a.files){let h=Ji(p);c+=h.lines,u+=h.words,f+=h.chars,l+=`${Nn(h,n,s,i,d)}
128
- `}return o.length>1&&(l+=`${Nn({lines:c,words:u,chars:f},n,s,i,"total")}
129
- `),{stdout:l,stderr:a.stderr,exitCode:a.exitCode}}}});var ro={};$(ro,{statCommand:()=>Zf});function to(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 qf,Vf,Zf,no=C(()=>{"use strict";ue();M();qf={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"]},Vf={format:{short:"c",type:"string"}},Zf={name:"stat",async execute(t,e){if(v(t))return k(qf);let r=j("stat",t,Vf);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="",o="",a=!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),p=to(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,p),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=to(u.mode,u.isDirectory);i+=` File: ${l}
125
+ `}var $n=A(()=>{"use strict";_()});var ro={};$(ro,{headCommand:()=>tp});var ep,tp,no=A(()=>{"use strict";_();$n();ep={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"]},tp={name:"head",async execute(t,e){if(I(t))return N(ep);let r=Sr(t,"head");if(!r.ok)return r.error;let{lines:n,bytes:s}=r.options;return Ar(e,r.options,"head",i=>eo(i,n,s))}}});var so={};$(so,{tailCommand:()=>np});var rp,np,io=A(()=>{"use strict";$n();_();rp={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"]},np={name:"tail",async execute(t,e){if(I(t))return N(rp);let r=Sr(t,"tail");if(!r.ok)return r.error;let{lines:n,bytes:s,fromLine:i}=r.options;return Ar(e,r.options,"tail",o=>to(o,n,s,i??!1))}}});var ao={};$(ao,{wcCommand:()=>op});function oo(t){let e=t.length,r=0,n=0,s=!1;for(let i=0;i<e;i++){let o=t[i];o===`
126
+ `?(r++,s&&(n++,s=!1)):o===" "||o===" "||o==="\r"?s&&(n++,s=!1):s=!0}return s&&n++,{lines:r,words:n,chars:e}}function On(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 o=i.join(" ");return s&&(o+=` ${s}`),o}var sp,ip,op,co=A(()=>{"use strict";fe();Ct();_();sp={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"]},ip={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"}},op={name:"wc",async execute(t,e){if(I(t))return N(sp);let r=G("wc",t,ip);if(!r.ok)return r.error;let{lines:n,words:s}=r.result.flags,i=r.result.flags.bytes||r.result.flags.chars,o=r.result.positional;!n&&!s&&!i&&(n=s=i=!0);let a=await qt(e,o,{cmdName:"wc",stopOnError:!1});if(o.length===0){let p=oo(a.files[0].content);return{stdout:`${On(p,n,s,i,"")}
127
+ `,stderr:"",exitCode:0}}let c="",l=0,u=0,f=0;for(let{filename:p,content:d}of a.files){let h=oo(d);l+=h.lines,u+=h.words,f+=h.chars,c+=`${On(h,n,s,i,p)}
128
+ `}return o.length>1&&(c+=`${On({lines:l,words:u,chars:f},n,s,i,"total")}
129
+ `),{stdout:c,stderr:a.stderr,exitCode:a.exitCode}}}});var uo={};$(uo,{statCommand:()=>lp});function lo(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 ap,cp,lp,fo=A(()=>{"use strict";fe();_();ap={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"]},cp={format:{short:"c",type:"string"}},lp={name:"stat",async execute(t,e){if(I(t))return N(ap);let r=G("stat",t,cp);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="",o="",a=!1;for(let c of s){let l=e.fs.resolvePath(e.cwd,c);try{let u=await e.fs.stat(l);if(n){let f=n,p=u.mode.toString(8),d=lo(u.mode,u.isDirectory);f=f.replace(/%n/g,c),f=f.replace(/%N/g,`'${c}'`),f=f.replace(/%s/g,String(u.size)),f=f.replace(/%F/g,u.isDirectory?"directory":"regular file"),f=f.replace(/%a/g,p),f=f.replace(/%A/g,d),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"),p=lo(u.mode,u.isDirectory);i+=` File: ${c}
132
132
  `,i+=` Size: ${u.size} Blocks: ${Math.ceil(u.size/512)}
133
- `,i+=`Access: (${f}/${d})
133
+ `,i+=`Access: (${f}/${p})
134
134
  `,i+=`Modify: ${u.mtime.toISOString()}
135
- `}}catch{o+=`stat: cannot stat '${l}': No such file or directory
136
- `,a=!0}}return{stdout:i,stderr:o,exitCode:a?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,o=so.get(i);return o||(o=Qf(s,n.ignoreCase),so.set(i,o)),o.test(t)}function Qf(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 so,In=C(()=>{"use strict";so=new Map});var Sr={};$(Sr,{egrepCommand:()=>ed,fgrepCommand:()=>Yf,grepCommand:()=>Rn});function Kf(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 io(t,e,r,n,s,i,o=!1,a=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(a===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++,o){e.lastIndex=0;for(let P=e.exec(A);P!==null;P=e.exec(A))y.push(i?`${i}:${P[0]}`:P[0]),P[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(`
135
+ `}}catch{o+=`stat: cannot stat '${c}': No such file or directory
136
+ `,a=!0}}return{stdout:i,stderr:o,exitCode:a?1:0}}}});function $e(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,o=po.get(i);return o||(o=up(s,n.ignoreCase),po.set(i,o)),o.test(t)}function up(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 po,Pn=A(()=>{"use strict";po=new Map});var Cr={};$(Cr,{egrepCommand:()=>mp,fgrepCommand:()=>hp,grepCommand:()=>Fn});function pp(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 ho(t,e,r,n,s,i,o=!1,a=0,c=0,l=0){let u=t.split(`
137
+ `),f=u.length,p=f>0&&u[f-1]===""?f-1:f;if(s){let w=0;for(let b=0;b<p;b++)e.lastIndex=0,e.test(u[b])!==r&&w++;return{output:`${i?`${i}:${w}`:String(w)}
138
+ `,matched:w>0}}if(a===0&&c===0){let w=[],E=!1,b=0;for(let S=0;S<p&&!(l>0&&b>=l);S++){let C=u[S];if(e.lastIndex=0,e.test(C)!==r)if(E=!0,b++,o){e.lastIndex=0;for(let D=e.exec(C);D!==null;D=e.exec(C))w.push(i?`${i}:${D[0]}`:D[0]),D[0].length===0&&e.lastIndex++}else n?w.push(i?`${i}:${S+1}:${C}`:`${S+1}:${C}`):w.push(i?`${i}:${C}`:C)}return{output:w.length>0?`${w.join(`
139
139
  `)}
140
- `:"",matched:E}}let p=[],h=0,w=new Set,g=[];for(let y=0;y<d&&!(c>0&&h>=c);y++)e.lastIndex=0,e.test(u[y])!==r&&(g.push(y),h++);for(let y of g){for(let b=Math.max(0,y-a);b<y;b++)if(!w.has(b)){w.add(b);let S=u[b];n&&(S=`${b+1}-${S}`),i&&(S=`${i}-${S}`),p.push(S)}if(!w.has(y)){w.add(y);let b=u[y];if(o){e.lastIndex=0;for(let S=e.exec(b);S!==null;S=e.exec(b))p.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}`),p.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}`),p.push(S)}}return{output:p.length>0?`${p.join(`
140
+ `:"",matched:E}}let d=[],h=0,g=new Set,y=[];for(let w=0;w<p&&!(l>0&&h>=l);w++)e.lastIndex=0,e.test(u[w])!==r&&(y.push(w),h++);for(let w of y){for(let b=Math.max(0,w-a);b<w;b++)if(!g.has(b)){g.add(b);let S=u[b];n&&(S=`${b+1}-${S}`),i&&(S=`${i}-${S}`),d.push(S)}if(!g.has(w)){g.add(w);let b=u[w];if(o){e.lastIndex=0;for(let S=e.exec(b);S!==null;S=e.exec(b))d.push(i?`${i}:${S[0]}`:S[0]),S[0].length===0&&e.lastIndex++}else{let S=b;n&&(S=`${w+1}:${S}`),i&&(S=`${i}:${S}`),d.push(S)}}let E=Math.min(p-1,w+c);for(let b=w+1;b<=E;b++)if(!g.has(b)){g.add(b);let S=u[b];n&&(S=`${b+1}-${S}`),i&&(S=`${i}-${S}`),d.push(S)}}return{output:d.length>0?`${d.join(`
141
141
  `)}
142
- `:"",matched:h>0}}async function $n(t,e,r=[],n=[],s=[]){let i=e.fs.resolvePath(e.cwd,t),o=[];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 $n(f,e,r,n,s);o.push(...d)}}catch{}return o}async function Jf(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 a=t.split("**"),l=a[0].replace(/\/$/,"")||".",c=a[1]||"";return await oo(l,c,e,r),r}let o=e.fs.resolvePath(e.cwd,s);try{let a=await e.fs.readdir(o);for(let l of a)if(Ie(l,i,{stripQuotes:!0})){let c=n===-1?l:`${s}/${l}`;r.push(c)}}catch{}return r.sort()}async function oo(t,e,r,n){let s=r.fs.resolvePath(r.cwd,t);try{if(!(await r.fs.stat(s)).isDirectory){let a=t.split("/").pop()||"";if(e){let l=e.replace(/^\//,"");Ie(a,l,{stripQuotes:!0})&&n.push(t)}return}let o=await r.fs.readdir(s);for(let a of o){let l=t==="."?a:`${t}/${a}`,c=r.fs.resolvePath(r.cwd,l);if((await r.fs.stat(c)).isDirectory)await oo(l,e,r,n);else if(e){let f=e.replace(/^\//,"");Ie(a,f,{stripQuotes:!0})&&n.push(l)}}}catch{}}var Xf,Rn,Yf,ed,Cr=C(()=>{"use strict";In();M();Xf={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"]},Rn={name:"grep",async execute(t,e){if(v(t))return k(Xf);let r=!1,n=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,p=!1,h=!1,w=!1,g=!1,y=0,E=0,b=0,S=[],A=[],D=[],P=null,F=[];for(let W=0;W<t.length;W++){let U=t[W];if(U.startsWith("-")&&U!=="-"){if(U==="-e"&&W+1<t.length){P=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 Me=U.match(/^-([ABC])(\d+)$/);if(Me){let L=parseInt(Me[2],10);Me[1]==="A"?b=L:Me[1]==="B"?E=L:Me[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 Sn=U.startsWith("--")?[U]:U.slice(1).split("");for(let L of Sn)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")o=!0;else if(L==="L"||L==="--files-without-match")a=!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")p=!0;else if(L==="o"||L==="--only-matching")h=!0;else if(L==="h"||L==="--no-filename")w=!0;else if(L==="q"||L==="--quiet"||L==="--silent")g=!0;else{if(L.startsWith("--"))return T("grep",L);if(L.length===1)return T("grep",`-${L}`)}}else P===null?P=U:F.push(U)}if(P===null)return{stdout:"",stderr:`grep: missing pattern
143
- `,exitCode:2};let B;p?B=P.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):f||d?B=P:B=Kf(P),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: ${P}
144
- `,exitCode:2}}if(F.length===0&&e.stdin){let W=io(e.stdin,ee,s,n,i,"",h,E,b,y);return g?{stdout:"",stderr:"",exitCode:W.matched?0:1}:{stdout:W.output,stderr:"",exitCode:W.matched?0:1}}if(F.length===0)return{stdout:"",stderr:`grep: no input files
145
- `,exitCode:2};let de="",ne="",Se=!1,He=!1,De=[];for(let W of F)if(W.includes("*")||W.includes("?")||W.includes("[")){let U=await Jf(W,e);if(l)for(let Ce of U){let Me=await $n(Ce,e,S,A,D);De.push(...Me)}else De.push(...U)}else if(l){let U=await $n(W,e,S,A,D);De.push(...U)}else De.push(W);let hr=(De.length>1||l)&&!w;for(let W of De){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 Sn=await e.fs.readFile(Ce),L=io(Sn,ee,s,n,i,hr?W:"",h,E,b,y);if(L.matched){if(Se=!0,g)return{stdout:"",stderr:"",exitCode:0};o?de+=`${W}
147
- `:a||(de+=L.output)}else a?de+=`${W}
148
- `:i&&!o&&(de+=L.output)}catch{ne+=`grep: ${W}: No such file or directory
149
- `,He=!0}}let Le;return He?Le=2:a?Le=de.length>0?0:1:Le=Se?0:1,g?{stdout:"",stderr:"",exitCode:Le}:{stdout:de,stderr:ne,exitCode:Le}}};Yf={name:"fgrep",async execute(t,e){return Rn.execute(["-F",...t],e)}},ed={name:"egrep",async execute(t,e){return Rn.execute(["-E",...t],e)}}});function Ar(t){return t instanceof he||t instanceof ye||t instanceof me}var $e,he,ye,me,We,Re,X,oe,qe,H,ze,J=C(()=>{"use strict";$e=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}},he=class extends $e{levels;name="BreakError";constructor(e=1,r="",n=""){super("break",r,n),this.levels=e}},ye=class extends $e{levels;name="ContinueError";constructor(e=1,r="",n=""){super("continue",r,n),this.levels=e}},me=class extends $e{exitCode;name="ReturnError";constructor(e=0,r="",n=""){super("return",r,n),this.exitCode=e}},We=class extends $e{exitCode;name="ErrexitError";constructor(e,r="",n=""){super(`errexit: command exited with status ${e}`,r,n),this.exitCode=e}},Re=class extends $e{varName;name="NounsetError";constructor(e,r=""){super(`${e}: unbound variable`,r,`bash: ${e}: unbound variable
150
- `),this.varName=e}},X=class extends $e{exitCode;name="ExitError";constructor(e,r="",n=""){super("exit",r,n),this.exitCode=e}},oe=class extends $e{name="ArithmeticError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}
151
- `}},qe=class extends $e{name="BadSubstitutionError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}: bad substitution
152
- `}},H=class extends $e{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 $e{name="SubshellExitError";constructor(e="",r=""){super("subshell exit",e,r)}}});function lo(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 rd(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(rd(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 nd(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 Ct(t,e,r,n,s){if(!t||!t.start&&!t.end)return!0;let i=t.start,o=t.end;if(i!==void 0&&o===void 0)return jt(i,e,r,n);if(i!==void 0&&o!==void 0){let a=typeof i=="object"&&"pattern"in i,l=typeof o=="object"&&"pattern"in o;if(!a&&!l){let u=typeof i=="number"?i:i==="$"?r:1,f=typeof o=="number"?o:r;return e>=u&&e<=f}if(s){let u=nd(t),f=s.get(u);return f||(f={active:!1},s.set(u,f)),f.active?(jt(o,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(o,e,r,n)&&(f.active=!1,s.set(u,f)),!0):!1}return jt(i,e,r,n)}return!0}function sd(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 id(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===`
142
+ `:"",matched:h>0}}async function Tn(t,e,r=[],n=[],s=[]){let i=e.fs.resolvePath(e.cwd,t),o=[];try{if(!(await e.fs.stat(i)).isDirectory){let u=t.split("/").pop()||t;return n.length>0&&n.some(f=>$e(u,f,{stripQuotes:!0}))?[]:r.length>0&&!r.some(f=>$e(u,f,{stripQuotes:!0}))?[]:[t]}let c=t.split("/").pop()||t;if(s.length>0&&s.some(u=>$e(c,u,{stripQuotes:!0})))return[];let l=await e.fs.readdir(i);for(let u of l){if(u.startsWith("."))continue;let f=t==="."?u:`${t}/${u}`,p=await Tn(f,e,r,n,s);o.push(...p)}}catch{}return o}async function dp(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 a=t.split("**"),c=a[0].replace(/\/$/,"")||".",l=a[1]||"";return await mo(c,l,e,r),r}let o=e.fs.resolvePath(e.cwd,s);try{let a=await e.fs.readdir(o);for(let c of a)if($e(c,i,{stripQuotes:!0})){let l=n===-1?c:`${s}/${c}`;r.push(l)}}catch{}return r.sort()}async function mo(t,e,r,n){let s=r.fs.resolvePath(r.cwd,t);try{if(!(await r.fs.stat(s)).isDirectory){let a=t.split("/").pop()||"";if(e){let c=e.replace(/^\//,"");$e(a,c,{stripQuotes:!0})&&n.push(t)}return}let o=await r.fs.readdir(s);for(let a of o){let c=t==="."?a:`${t}/${a}`,l=r.fs.resolvePath(r.cwd,c);if((await r.fs.stat(l)).isDirectory)await mo(c,e,r,n);else if(e){let f=e.replace(/^\//,"");$e(a,f,{stripQuotes:!0})&&n.push(c)}}}catch{}}var fp,Fn,hp,mp,kr=A(()=>{"use strict";Pn();_();fp={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"]},Fn={name:"grep",async execute(t,e){if(I(t))return N(fp);let r=!1,n=!1,s=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=!1,f=!1,p=!1,d=!1,h=!1,g=!1,y=!1,w=0,E=0,b=0,S=[],C=[],O=[],D=null,F=[];for(let H=0;H<t.length;H++){let j=t[H];if(j.startsWith("-")&&j!=="-"){if(j==="-e"&&H+1<t.length){D=t[++H];continue}if(j.startsWith("--include=")){S.push(j.slice(10));continue}if(j.startsWith("--exclude=")){C.push(j.slice(10));continue}if(j.startsWith("--exclude-dir=")){O.push(j.slice(14));continue}if(j.startsWith("--max-count=")){w=parseInt(j.slice(12),10);continue}let ke=j.match(/^-m(\d+)$/);if(ke){w=parseInt(ke[1],10);continue}if(j==="-m"&&H+1<t.length){w=parseInt(t[++H],10);continue}let Be=j.match(/^-([ABC])(\d+)$/);if(Be){let M=parseInt(Be[2],10);Be[1]==="A"?b=M:Be[1]==="B"?E=M:Be[1]==="C"&&(E=M,b=M);continue}if((j==="-A"||j==="-B"||j==="-C")&&H+1<t.length){let M=parseInt(t[++H],10);j==="-A"?b=M:j==="-B"?E=M:(E=M,b=M);continue}let Nn=j.startsWith("--")?[j]:j.slice(1).split("");for(let M of Nn)if(M==="i"||M==="--ignore-case")r=!0;else if(M==="n"||M==="--line-number")n=!0;else if(M==="v"||M==="--invert-match")s=!0;else if(M==="c"||M==="--count")i=!0;else if(M==="l"||M==="--files-with-matches")o=!0;else if(M==="L"||M==="--files-without-match")a=!0;else if(M==="r"||M==="R"||M==="--recursive")c=!0;else if(M==="w"||M==="--word-regexp")l=!0;else if(M==="x"||M==="--line-regexp")u=!0;else if(M==="E"||M==="--extended-regexp")f=!0;else if(M==="P"||M==="--perl-regexp")p=!0;else if(M==="F"||M==="--fixed-strings")d=!0;else if(M==="o"||M==="--only-matching")h=!0;else if(M==="h"||M==="--no-filename")g=!0;else if(M==="q"||M==="--quiet"||M==="--silent")y=!0;else{if(M.startsWith("--"))return L("grep",M);if(M.length===1)return L("grep",`-${M}`)}}else D===null?D=j:F.push(j)}if(D===null)return{stdout:"",stderr:`grep: missing pattern
143
+ `,exitCode:2};let U;d?U=D.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):f||p?U=D:U=pp(D),l&&(U=`\\b${U}\\b`),u&&(U=`^${U}$`);let te;try{te=new RegExp(U,r?"gi":"g")}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${D}
144
+ `,exitCode:2}}if(F.length===0&&e.stdin){let H=ho(e.stdin,te,s,n,i,"",h,E,b,w);return y?{stdout:"",stderr:"",exitCode:H.matched?0:1}:{stdout:H.output,stderr:"",exitCode:H.matched?0:1}}if(F.length===0)return{stdout:"",stderr:`grep: no input files
145
+ `,exitCode:2};let de="",se="",Ce=!1,ze=!1,Me=[];for(let H of F)if(H.includes("*")||H.includes("?")||H.includes("[")){let j=await dp(H,e);if(c)for(let ke of j){let Be=await Tn(ke,e,S,C,O);Me.push(...Be)}else Me.push(...j)}else if(c){let j=await Tn(H,e,S,C,O);Me.push(...j)}else Me.push(H);let yr=(Me.length>1||c)&&!g;for(let H of Me){let j=H.split("/").pop()||H;if(!(C.length>0&&!c&&C.some(ke=>$e(j,ke,{stripQuotes:!0})))&&!(S.length>0&&!c&&!S.some(ke=>$e(j,ke,{stripQuotes:!0}))))try{let ke=e.fs.resolvePath(e.cwd,H);if((await e.fs.stat(ke)).isDirectory){c||(se+=`grep: ${H}: Is a directory
146
+ `);continue}let Nn=await e.fs.readFile(ke),M=ho(Nn,te,s,n,i,yr?H:"",h,E,b,w);if(M.matched){if(Ce=!0,y)return{stdout:"",stderr:"",exitCode:0};o?de+=`${H}
147
+ `:a||(de+=M.output)}else a?de+=`${H}
148
+ `:i&&!o&&(de+=M.output)}catch{se+=`grep: ${H}: No such file or directory
149
+ `,ze=!0}}let _e;return ze?_e=2:a?_e=de.length>0?0:1:_e=Ce?0:1,y?{stdout:"",stderr:"",exitCode:_e}:{stdout:de,stderr:se,exitCode:_e}}};hp={name:"fgrep",async execute(t,e){return Fn.execute(["-F",...t],e)}},mp={name:"egrep",async execute(t,e){return Fn.execute(["-E",...t],e)}}});function Nr(t){return t instanceof me||t instanceof Ee||t instanceof ye}var Oe,me,Ee,ye,He,Pe,X,ae,Ke,W,Ge,J=A(()=>{"use strict";Oe=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}},me=class extends Oe{levels;name="BreakError";constructor(e=1,r="",n=""){super("break",r,n),this.levels=e}},Ee=class extends Oe{levels;name="ContinueError";constructor(e=1,r="",n=""){super("continue",r,n),this.levels=e}},ye=class extends Oe{exitCode;name="ReturnError";constructor(e=0,r="",n=""){super("return",r,n),this.exitCode=e}},He=class extends Oe{exitCode;name="ErrexitError";constructor(e,r="",n=""){super(`errexit: command exited with status ${e}`,r,n),this.exitCode=e}},Pe=class extends Oe{varName;name="NounsetError";constructor(e,r=""){super(`${e}: unbound variable`,r,`bash: ${e}: unbound variable
150
+ `),this.varName=e}},X=class extends Oe{exitCode;name="ExitError";constructor(e,r="",n=""){super("exit",r,n),this.exitCode=e}},ae=class extends Oe{name="ArithmeticError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}
151
+ `}},Ke=class extends Oe{name="BadSubstitutionError";constructor(e,r="",n=""){super(e,r,n),this.stderr=n||`bash: ${e}: bad substitution
152
+ `}},W=class extends Oe{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
+ `}},Ge=class extends Oe{name="SubshellExitError";constructor(e="",r=""){super("subshell exit",e,r)}}});function go(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 gp(t){return typeof t=="object"&&"first"in t&&"step"in t}function Vt(t,e,r,n){if(t==="$")return e===r;if(typeof t=="number")return e===t;if(gp(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 xp(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 Nt(t,e,r,n,s){if(!t||!t.start&&!t.end)return!0;let i=t.start,o=t.end;if(i!==void 0&&o===void 0)return Vt(i,e,r,n);if(i!==void 0&&o!==void 0){let a=typeof i=="object"&&"pattern"in i,c=typeof o=="object"&&"pattern"in o;if(!a&&!c){let u=typeof i=="number"?i:i==="$"?r:1,f=typeof o=="number"?o:r;return e>=u&&e<=f}if(s){let u=xp(t),f=s.get(u);return f||(f={active:!1},s.set(u,f)),f.active?(Vt(o,e,r,n)&&(f.active=!1,s.set(u,f)),!0):Vt(i,e,r,n)?(f.active=!0,f.startLine=e,s.set(u,f),Vt(o,e,r,n)&&(f.active=!1,s.set(u,f)),!0):!1}return Vt(i,e,r,n)}return!0}function wp(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 Ep(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 ao(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 o=parseInt(i,10);if(o>=1&&o<=9){n+=r[o-1]||"",s+=2;continue}n+=i,s+=2;continue}if(t[s]==="&"){n+=e,s++;continue}n+=t[s],s++}return n}function od(t,e){let{lineNumber:r,totalLines:n,patternSpace:s}=e;if(t.type!=="label"&&Ct(t.address,r,n,s,e.rangeStates))switch(t.type){case"substitute":{let i=t,o="";i.global&&(o+="g"),i.ignoreCase&&(o+="i");let a=i.extendedRegex?i.pattern:sd(i.pattern);try{let l=new RegExp(a,o),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(a,`g${i.ignoreCase?"i":""}`),(d,...p)=>{if(u++,u===f){let h=p.slice(0,-2);return ao(i.replacement,d,h)}return d})}else e.patternSpace=e.patternSpace.replace(l,(u,...f)=>{let d=f.slice(0,-2);return ao(i.replacement,u,d)});i.printOnMatch&&(e.printed=!0)}}catch{}break}case"print":e.printed=!0;break;case"printFirstLine":{let i=e.patternSpace.indexOf(`
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 yo(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 o=parseInt(i,10);if(o>=1&&o<=9){n+=r[o-1]||"",s+=2;continue}n+=i,s+=2;continue}if(t[s]==="&"){n+=e,s++;continue}n+=t[s],s++}return n}function bp(t,e){let{lineNumber:r,totalLines:n,patternSpace:s}=e;if(t.type!=="label"&&Nt(t.address,r,n,s,e.rangeStates))switch(t.type){case"substitute":{let i=t,o="";i.global&&(o+="g"),i.ignoreCase&&(o+="i");let a=i.extendedRegex?i.pattern:wp(i.pattern);try{let c=new RegExp(a,o),l=c.test(e.patternSpace);if(c.lastIndex=0,l){if(e.substitutionMade=!0,i.nthOccurrence&&i.nthOccurrence>0&&!i.global){let u=0,f=i.nthOccurrence;e.patternSpace=e.patternSpace.replace(new RegExp(a,`g${i.ignoreCase?"i":""}`),(p,...d)=>{if(u++,u===f){let h=d.slice(0,-2);return yo(i.replacement,p,h)}return p})}else e.patternSpace=e.patternSpace.replace(c,(u,...f)=>{let p=f.slice(0,-2);return yo(i.replacement,u,p)});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=id(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}
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=Ep(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
  `),o=i!==-1?e.patternSpace.slice(0,i):e.patternSpace;e.pendingFileWrites.push({filename:t.filename,content:`${o}
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=ad(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 ad(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 On(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??td,o=0,a=0,l=0;for(;l<t.length;){if(o++,o>i)throw new H(`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(Ct(c.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates))if(r&&r.currentLineIndex+a+1<r.lines.length){a++;let u=r.lines[r.currentLineIndex+a];e.patternSpace+=`
164
- ${u}`,e.lineNumber=r.currentLineIndex+a+1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(c.type==="branch"){let u=c;if(Ct(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(Ct(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(Ct(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;Ct(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&On(u.commands,e,r,n),l++;continue}od(c,e),l++}return a}var td,co=C(()=>{"use strict";J();td=1e4});var I,kr,uo=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={}));kr=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===`
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=Sp(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 Sp(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 Dn(t,e,r,n){let s=new Map;for(let l=0;l<t.length;l++){let u=t[l];u.type==="label"&&s.set(u.name,l)}let i=n?.maxIterations??yp,o=0,a=0,c=0;for(;c<t.length;){if(o++,o>i)throw new W(`sed: command execution exceeded maximum iterations (${i})`,"iterations");if(e.deleted||e.quit||e.quitSilent||e.restartCycle)break;let l=t[c];if(l.type==="nextAppend"){if(Nt(l.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates))if(r&&r.currentLineIndex+a+1<r.lines.length){a++;let u=r.lines[r.currentLineIndex+a];e.patternSpace+=`
164
+ ${u}`,e.lineNumber=r.currentLineIndex+a+1}else{e.quit=!0,e.deleted=!0;break}c++;continue}if(l.type==="branch"){let u=l;if(Nt(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)){if(u.label){let f=s.get(u.label);if(f!==void 0){c=f;continue}}break}c++;continue}if(l.type==="branchOnSubst"){let u=l;if(Nt(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){c=f;continue}}break}c++;continue}if(l.type==="branchOnNoSubst"){let u=l;if(Nt(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){c=f;continue}}break}c++;continue}if(l.type==="group"){let u=l;Nt(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&Dn(u.commands,e,r,n),c++;continue}bp(l,e),c++}return a}var yp,xo=A(()=>{"use strict";J();yp=1e4});var R,Ir,wo=A(()=>{"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"})(R||(R={}));Ir=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(R.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
- `?(this.advance(),{type:I.NEWLINE,value:`
168
- `,line:e,column:r}):n===";"?(this.advance(),{type:I.SEMICOLON,value:";",line:e,column:r}):n==="{"?(this.advance(),{type:I.LBRACE,value:"{",line:e,column:r}):n==="}"?(this.advance(),{type:I.RBRACE,value:"}",line:e,column:r}):n===","?(this.advance(),{type:I.COMMA,value:",",line:e,column:r}):n==="$"?(this.advance(),{type:I.DOLLAR,value:"$",line:e,column:r}):this.isDigit(n)?this.readNumber():n==="/"?this.readPattern():n===":"?this.readLabelDef():this.readCommand()}readNumber(){let e=this.line,r=this.column,n="";for(;this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="~"){this.advance();let s="";for(;this.isDigit(this.peek());)s+=this.advance();let i=parseInt(n,10),o=parseInt(s,10)||0;return{type:I.STEP,value:`${i}~${o}`,first:i,step:o,line:e,column:r}}return{type:I.NUMBER,value:parseInt(n,10),line:e,column:r}}readPattern(){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()===`
169
- `)break;n+=this.advance()}return this.peek()==="/"&&this.advance(),{type:I.PATTERN,value:n,pattern:n,line:e,column:r}}readLabelDef(){let e=this.line,r=this.column;this.advance();let n="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
170
- `||s===";"||s==="}"||s==="{")break;n+=this.advance()}return{type:I.LABEL_DEF,value:n,label:n,line:e,column:r}}readCommand(){let e=this.line,r=this.column,n=this.advance();switch(n){case"s":return this.readSubstitute(e,r);case"y":return this.readTransliterate(e,r);case"a":case"i":case"c":return this.readTextCommand(n,e,r);case"b":return this.readBranch(I.BRANCH,"b",e,r);case"t":return this.readBranch(I.BRANCH_ON_SUBST,"t",e,r);case"T":return this.readBranch(I.BRANCH_ON_NO_SUBST,"T",e,r);case"r":return this.readFileCommand(I.FILE_READ,"r",e,r);case"R":return this.readFileCommand(I.FILE_READ_LINE,"R",e,r);case"w":return this.readFileCommand(I.FILE_WRITE,"w",e,r);case"W":return this.readFileCommand(I.FILE_WRITE_LINE,"W",e,r);case"e":return this.readExecute(e,r);case"p":case"P":case"d":case"D":case"h":case"H":case"g":case"G":case"x":case"n":case"N":case"q":case"Q":case"z":case"=":case"l":case"F":case"v":return{type:I.COMMAND,value:n,line:e,column:r};default:return{type:I.ERROR,value:n,line:e,column:r}}}readSubstitute(e,r){let n=this.advance();if(!n||n===`
171
- `)return{type:I.ERROR,value:"s",line:e,column:r};let s="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\")s+=this.advance(),this.pos<this.input.length&&this.peek()!==`
167
+ `?(this.advance(),{type:R.NEWLINE,value:`
168
+ `,line:e,column:r}):n===";"?(this.advance(),{type:R.SEMICOLON,value:";",line:e,column:r}):n==="{"?(this.advance(),{type:R.LBRACE,value:"{",line:e,column:r}):n==="}"?(this.advance(),{type:R.RBRACE,value:"}",line:e,column:r}):n===","?(this.advance(),{type:R.COMMA,value:",",line:e,column:r}):n==="$"?(this.advance(),{type:R.DOLLAR,value:"$",line:e,column:r}):this.isDigit(n)?this.readNumber():n==="/"?this.readPattern():n===":"?this.readLabelDef():this.readCommand()}readNumber(){let e=this.line,r=this.column,n="";for(;this.isDigit(this.peek());)n+=this.advance();if(this.peek()==="~"){this.advance();let s="";for(;this.isDigit(this.peek());)s+=this.advance();let i=parseInt(n,10),o=parseInt(s,10)||0;return{type:R.STEP,value:`${i}~${o}`,first:i,step:o,line:e,column:r}}return{type:R.NUMBER,value:parseInt(n,10),line:e,column:r}}readPattern(){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()===`
169
+ `)break;n+=this.advance()}return this.peek()==="/"&&this.advance(),{type:R.PATTERN,value:n,pattern:n,line:e,column:r}}readLabelDef(){let e=this.line,r=this.column;this.advance();let n="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
170
+ `||s===";"||s==="}"||s==="{")break;n+=this.advance()}return{type:R.LABEL_DEF,value:n,label:n,line:e,column:r}}readCommand(){let e=this.line,r=this.column,n=this.advance();switch(n){case"s":return this.readSubstitute(e,r);case"y":return this.readTransliterate(e,r);case"a":case"i":case"c":return this.readTextCommand(n,e,r);case"b":return this.readBranch(R.BRANCH,"b",e,r);case"t":return this.readBranch(R.BRANCH_ON_SUBST,"t",e,r);case"T":return this.readBranch(R.BRANCH_ON_NO_SUBST,"T",e,r);case"r":return this.readFileCommand(R.FILE_READ,"r",e,r);case"R":return this.readFileCommand(R.FILE_READ_LINE,"R",e,r);case"w":return this.readFileCommand(R.FILE_WRITE,"w",e,r);case"W":return this.readFileCommand(R.FILE_WRITE_LINE,"W",e,r);case"e":return this.readExecute(e,r);case"p":case"P":case"d":case"D":case"h":case"H":case"g":case"G":case"x":case"n":case"N":case"q":case"Q":case"z":case"=":case"l":case"F":case"v":return{type:R.COMMAND,value:n,line:e,column:r};default:return{type:R.ERROR,value:n,line:e,column:r}}}readSubstitute(e,r){let n=this.advance();if(!n||n===`
171
+ `)return{type:R.ERROR,value:"s",line:e,column:r};let s="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\")s+=this.advance(),this.pos<this.input.length&&this.peek()!==`
172
172
  `&&(s+=this.advance());else{if(this.peek()===`
173
- `)break;s+=this.advance()}if(this.peek()!==n)return{type:I.ERROR,value:"unterminated substitution pattern",line:e,column:r};this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&this.peek()!==`
173
+ `)break;s+=this.advance()}if(this.peek()!==n)return{type:R.ERROR,value:"unterminated substitution pattern",line:e,column:r};this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&this.peek()!==`
174
174
  `&&(i+=this.advance());else{if(this.peek()===`
175
- `)break;i+=this.advance()}this.peek()===n&&this.advance();let o="";for(;this.pos<this.input.length;){let a=this.peek();if(a==="g"||a==="i"||a==="p"||a==="I"||this.isDigit(a))o+=this.advance();else break}return{type:I.SUBSTITUTE,value:`s${n}${s}${n}${i}${n}${o}`,pattern:s,replacement:i,flags:o,line:e,column:r}}readTransliterate(e,r){let n=this.advance();if(!n||n===`
176
- `)return{type:I.ERROR,value:"y",line:e,column:r};let s="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\"){this.advance();let o=this.advance();o==="n"?s+=`
175
+ `)break;i+=this.advance()}this.peek()===n&&this.advance();let o="";for(;this.pos<this.input.length;){let a=this.peek();if(a==="g"||a==="i"||a==="p"||a==="I"||this.isDigit(a))o+=this.advance();else break}return{type:R.SUBSTITUTE,value:`s${n}${s}${n}${i}${n}${o}`,pattern:s,replacement:i,flags:o,line:e,column:r}}readTransliterate(e,r){let n=this.advance();if(!n||n===`
176
+ `)return{type:R.ERROR,value:"y",line:e,column:r};let s="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\"){this.advance();let o=this.advance();o==="n"?s+=`
177
177
  `:o==="t"?s+=" ":s+=o}else{if(this.peek()===`
178
- `)break;s+=this.advance()}if(this.peek()!==n)return{type:I.ERROR,value:"unterminated transliteration source",line:e,column:r};this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\"){this.advance();let o=this.advance();o==="n"?i+=`
178
+ `)break;s+=this.advance()}if(this.peek()!==n)return{type:R.ERROR,value:"unterminated transliteration source",line:e,column:r};this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!==n;)if(this.peek()==="\\"){this.advance();let o=this.advance();o==="n"?i+=`
179
179
  `:o==="t"?i+=" ":i+=o}else{if(this.peek()===`
180
- `)break;i+=this.advance()}return this.peek()===n&&this.advance(),{type:I.TRANSLITERATE,value:`y${n}${s}${n}${i}${n}`,source:s,dest:i,line:e,column:r}}readTextCommand(e,r,n){this.peek()==="\\"&&this.advance(),this.peek()===" "&&this.advance();let s="";for(;this.pos<this.input.length&&this.peek()!==`
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 o=this.peek();if(o===" "||o===" "||o===`
180
+ `)break;i+=this.advance()}return this.peek()===n&&this.advance(),{type:R.TRANSLITERATE,value:`y${n}${s}${n}${i}${n}`,source:s,dest:i,line:e,column:r}}readTextCommand(e,r,n){this.peek()==="\\"&&this.advance(),this.peek()===" "&&this.advance();let s="";for(;this.pos<this.input.length&&this.peek()!==`
181
+ `;)s+=this.advance();return{type:R.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 o=this.peek();if(o===" "||o===" "||o===`
182
182
  `||o===";"||o==="}"||o==="{")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 o=this.peek();if(o===`
183
183
  `||o===";")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 fo(t,e=!1){return new Fn(t,e).parse()}var Fn,po=C(()=>{"use strict";uo();Fn=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 kr(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 ho={};$(ho,{sedCommand:()=>cd});async function Pn(t,e,r,n={}){let{limits:s,filename:i,fs:o,cwd:a}=n,l=t.split(`
185
- `);l.length>0&&l[l.length-1]===""&&l.pop();let c=l.length,u="",f,d="",p=new Map,h=new Map,w=new Map,g=new Map,y=s?{maxIterations:s.maxSedIterations}:void 0;for(let E=0;E<l.length;E++){let b={...lo(c,i,p),patternSpace:l[E],holdSpace:d,lineNumber:E+1,totalLines:c,substitutionMade:!1},S={lines:l,currentLineIndex:E},A=0,D=1e4,P=0;do{if(A++,A>D)break;b.restartCycle=!1,b.pendingFileReads=[],b.pendingFileWrites=[];let ee=On(e,b,S,y);if(P+=ee,o&&a){for(let de of b.pendingFileReads){let ne=o.resolvePath(a,de.filename);try{if(de.wholeFile){let Se=await o.readFile(ne);b.appendBuffer.push(Se.replace(/\n$/,""))}else{if(!h.has(ne)){let De=await o.readFile(ne);h.set(ne,De.split(`
186
- `)),w.set(ne,0)}let Se=h.get(ne),He=w.get(ne);Se&&He!==void 0&&He<Se.length&&(b.appendBuffer.push(Se[He]),w.set(ne,He+1))}}catch{}}for(let de of b.pendingFileWrites){let ne=o.resolvePath(a,de.filename),Se=g.get(ne)||"";g.set(ne,Se+de.content)}}S.currentLineIndex+=ee}while(b.restartCycle&&!b.deleted&&!b.quit&&!b.quitSilent);E+=P,d=b.holdSpace;for(let ee of b.lineNumberOutput)u+=`${ee}
187
- `;let F=[],B=[];for(let ee of b.appendBuffer)ee.startsWith("__INSERT__")?F.push(ee.slice(10)):B.push(ee);for(let ee of F)u+=`${ee}
184
+ `||s===";")break;n+=this.advance()}return{type:R.EXECUTE,value:"e",command:n.trim()||void 0,line:e,column:r}}isDigit(e){return e>="0"&&e<="9"}}});function Eo(t,e=!1){return new Ln(t,e).parse()}var Ln,bo=A(()=>{"use strict";wo();Ln=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 Ir(r);for(this.tokens=n.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(R.NEWLINE)||this.check(R.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(R.NEWLINE)||this.check(R.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 R.COMMAND:return this.parseSimpleCommand(r,e);case R.SUBSTITUTE:return this.parseSubstituteFromToken(r,e);case R.TRANSLITERATE:return this.parseTransliterateFromToken(r,e);case R.LABEL_DEF:return this.advance(),{command:{type:"label",name:r.label||""}};case R.BRANCH:return this.advance(),{command:{type:"branch",address:e,label:r.label}};case R.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:e,label:r.label}};case R.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:e,label:r.label}};case R.TEXT_CMD:return this.advance(),this.parseTextCommand(r,e);case R.FILE_READ:return this.advance(),{command:{type:"readFile",address:e,filename:r.filename||""}};case R.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:e,filename:r.filename||""}};case R.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:e,filename:r.filename||""}};case R.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:e,filename:r.filename||""}};case R.EXECUTE:return this.advance(),{command:{type:"execute",address:e,command:r.command}};case R.LBRACE:return this.parseGroup(e);case R.RBRACE:return{command:null};case R.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(R.RBRACE);){if(this.check(R.NEWLINE)||this.check(R.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(R.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(R.COMMA)&&(this.advance(),r=this.parseAddress()),{start:e,end:r}}parseAddress(){let e=this.peek();switch(e.type){case R.NUMBER:return this.advance(),e.value;case R.DOLLAR:return this.advance(),"$";case R.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case R.STEP:return this.advance(),{first:e.first||0,step:e.step||0};default:return}}peek(){return this.tokens[this.pos]||{type:R.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===R.EOF}}});var So={};$(So,{sedCommand:()=>Cp});async function Mn(t,e,r,n={}){let{limits:s,filename:i,fs:o,cwd:a}=n,c=t.split(`
185
+ `);c.length>0&&c[c.length-1]===""&&c.pop();let l=c.length,u="",f,p="",d=new Map,h=new Map,g=new Map,y=new Map,w=s?{maxIterations:s.maxSedIterations}:void 0;for(let E=0;E<c.length;E++){let b={...go(l,i,d),patternSpace:c[E],holdSpace:p,lineNumber:E+1,totalLines:l,substitutionMade:!1},S={lines:c,currentLineIndex:E},C=0,O=1e4,D=0;do{if(C++,C>O)break;b.restartCycle=!1,b.pendingFileReads=[],b.pendingFileWrites=[];let te=Dn(e,b,S,w);if(D+=te,o&&a){for(let de of b.pendingFileReads){let se=o.resolvePath(a,de.filename);try{if(de.wholeFile){let Ce=await o.readFile(se);b.appendBuffer.push(Ce.replace(/\n$/,""))}else{if(!h.has(se)){let Me=await o.readFile(se);h.set(se,Me.split(`
186
+ `)),g.set(se,0)}let Ce=h.get(se),ze=g.get(se);Ce&&ze!==void 0&&ze<Ce.length&&(b.appendBuffer.push(Ce[ze]),g.set(se,ze+1))}}catch{}}for(let de of b.pendingFileWrites){let se=o.resolvePath(a,de.filename),Ce=y.get(se)||"";y.set(se,Ce+de.content)}}S.currentLineIndex+=te}while(b.restartCycle&&!b.deleted&&!b.quit&&!b.quitSilent);E+=D,p=b.holdSpace;for(let te of b.lineNumberOutput)u+=`${te}
187
+ `;let F=[],U=[];for(let te of b.appendBuffer)te.startsWith("__INSERT__")?F.push(te.slice(10)):U.push(te);for(let te of F)u+=`${te}
188
188
  `;!b.deleted&&!b.quitSilent&&(r?b.printed&&(u+=`${b.patternSpace}
189
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(o&&a)for(let[E,b]of g)try{await o.writeFile(E,b)}catch{}return{output:u,exitCode:f}}var ld,cd,mo=C(()=>{"use strict";J();M();co();po();ld={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:
190
+ `);for(let te of U)u+=`${te}
191
+ `;if(b.quit||b.quitSilent){b.exitCode!==void 0&&(f=b.exitCode);break}}if(o&&a)for(let[E,b]of y)try{await o.writeFile(E,b)}catch{}return{output:u,exitCode:f}}var Ap,Cp,Ao=A(()=>{"use strict";J();_();xo();bo();Ap={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,36 +217,36 @@ 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`};cd={name:"sed",async execute(t,e){if(v(t))return k(ld);let r=[],n=[],s=!1,i=!1,o=!1,a=[];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")o=!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 p of d.slice(1))if(p!=="n"&&p!=="e"&&p!=="f"&&p!=="i"&&p!=="E"&&p!=="r")return T("sed",`-${p}`);d.includes("n")&&(s=!0),d.includes("i")&&(i=!0),(d.includes("E")||d.includes("r"))&&(o=!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("-")||a.push(d)}}for(let f of n){let d=e.fs.resolvePath(e.cwd,f);try{let p=await e.fs.readFile(d);for(let h of p.split(`
221
- `)){let w=h.trim();w&&!w.startsWith("#")&&r.push(w)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${f}: No such file or directory
220
+ first~step every step-th line starting at first`};Cp={name:"sed",async execute(t,e){if(I(t))return N(Ap);let r=[],n=[],s=!1,i=!1,o=!1,a=[];for(let f=0;f<t.length;f++){let p=t[f];if(p==="-n"||p==="--quiet"||p==="--silent")s=!0;else if(p==="-i"||p==="--in-place")i=!0;else if(p.startsWith("-i"))i=!0;else if(p==="-E"||p==="-r"||p==="--regexp-extended")o=!0;else if(p==="-e")f+1<t.length&&r.push(t[++f]);else if(p==="-f")f+1<t.length&&n.push(t[++f]);else{if(p.startsWith("--"))return L("sed",p);if(p.startsWith("-")&&p.length>1){for(let d of p.slice(1))if(d!=="n"&&d!=="e"&&d!=="f"&&d!=="i"&&d!=="E"&&d!=="r")return L("sed",`-${d}`);p.includes("n")&&(s=!0),p.includes("i")&&(i=!0),(p.includes("E")||p.includes("r"))&&(o=!0),p.includes("e")&&!p.includes("n")&&!p.includes("i")&&f+1<t.length&&r.push(t[++f]),p.includes("f")&&!p.includes("e")&&f+1<t.length&&n.push(t[++f])}else!p.startsWith("-")&&r.length===0&&n.length===0?r.push(p):p.startsWith("-")||a.push(p)}}for(let f of n){let p=e.fs.resolvePath(e.cwd,f);try{let d=await e.fs.readFile(p);for(let h of d.split(`
221
+ `)){let g=h.trim();g&&!g.startsWith("#")&&r.push(g)}}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:l,error:c}=fo(r,o);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(a.length===0){u=e.stdin;try{let f=await Pn(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 H)return{stdout:"",stderr:`sed: ${f.message}
226
- `,exitCode:H.EXIT_CODE};throw f}}if(i){for(let f of a){let d=e.fs.resolvePath(e.cwd,f);try{let p=await e.fs.readFile(d),h=await Pn(p,l,s,{limits:e.limits,filename:f,fs:e.fs,cwd:e.cwd});await e.fs.writeFile(d,h.output)}catch(p){return p instanceof H?{stdout:"",stderr:`sed: ${p.message}
227
- `,exitCode:H.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
228
- `,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}for(let f of a){let d=e.fs.resolvePath(e.cwd,f);try{u+=await e.fs.readFile(d)}catch(p){return p instanceof H?{stdout:"",stderr:`sed: ${p.message}
229
- `,exitCode:H.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
230
- `,exitCode:1}}}try{let f=await Pn(u,l,s,{limits:e.limits,filename:a.length===1?a[0]:void 0,fs:e.fs,cwd:e.cwd});return{stdout:f.output,stderr:"",exitCode:f.exitCode??0}}catch(f){if(f instanceof H)return{stdout:"",stderr:`sed: ${f.message}
231
- `,exitCode:H.EXIT_CODE};throw f}}}});function Tn(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 go=C(()=>{"use strict"});function xo(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 yo=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 ud(t,e,r){return t.length===0?e.line.length:se(await r.evalExpr(t[0])).length}async function fd(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 dd(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 pd(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,o=e.FS;if(t.length>=3){let l=se(await r.evalExpr(t[2]));o=l===" "?/\s+/:l}else e.FS===" "&&(o=/\s+/);let a=n.split(o);e.arrays[i]={};for(let l=0;l<a.length;l++)e.arrays[i][String(l+1)]=a[l];return a.length}async function hd(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 a=t[2];a.type==="variable"?i=a.name:a.type==="field"&&(i=`$${Math.floor(Ae(await r.evalExpr(a.index)))}`)}let o;if(i==="$0")o=e.line;else if(i.startsWith("$")){let a=parseInt(i.slice(1),10)-1;o=e.fields[a]||""}else o=se(e.vars[i]??"");try{let a=new RegExp(n),l=o.replace(a,Eo(s)),c=l!==o?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 md(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 a=t[2];a.type==="variable"?i=a.name:a.type==="field"&&(i=`$${Math.floor(Ae(await r.evalExpr(a.index)))}`)}let o;if(i==="$0")o=e.line;else if(i.startsWith("$")){let a=parseInt(i.slice(1),10)-1;o=e.fields[a]||""}else o=se(e.vars[i]??"");try{let a=new RegExp(n,"g"),l=o.match(a),c=l?l.length:0,u=o.replace(a,Eo(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 Eo(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 gd(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 o=new RegExp(s).exec(n);if(o)return e.RSTART=o.index+1,e.RLENGTH=o[0].length,e.RSTART}catch{}return e.RSTART=0,e.RLENGTH=-1,0}async function xd(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])),o=t.length>=4?se(await r.evalExpr(t[3])):e.line;try{let a=i.toLowerCase()==="g",l=a?0:parseInt(i,10)||1;if(a){let c=new RegExp(n,"g");return o.replace(c,(u,...f)=>wo(s,u,f.slice(0,-2)))}else{let c=0,u=new RegExp(n,"g");return o.replace(u,(f,...d)=>(c++,c===l?wo(s,f,d.slice(0,-2)):f))}}catch{return o}}function wo(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 o=parseInt(i,10)-1;n+=r[o]||"",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 yd(t,e,r){return t.length===0?"":se(await r.evalExpr(t[0])).toLowerCase()}async function wd(t,e,r){return t.length===0?"":se(await r.evalExpr(t[0])).toUpperCase()}async function Ed(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 Mn(n,s)}async function bd(t,e,r){return t.length===0?0:Math.floor(Ae(await r.evalExpr(t[0])))}async function Sd(t,e,r){return t.length===0?0:Math.sqrt(Ae(await r.evalExpr(t[0])))}async function Cd(t,e,r){return t.length===0?0:Math.sin(Ae(await r.evalExpr(t[0])))}async function Ad(t,e,r){return t.length===0?0:Math.cos(Ae(await r.evalExpr(t[0])))}async function kd(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 vd(t,e,r){return t.length===0?0:Math.log(Ae(await r.evalExpr(t[0])))}async function Nd(t,e,r){return t.length===0?1:Math.exp(Ae(await r.evalExpr(t[0])))}function Id(t,e,r){return e.random?e.random():Math.random()}async function $d(t,e,r){let n=t.length>0?Ae(await r.evalExpr(t[0])):Date.now();return e.vars._srand_seed=n,n}function Dn(t,e){return()=>{throw new Error(`${t}() is not supported - ${e}`)}}function Ln(t){return()=>{throw new Error(`function '${t}()' is not implemented`)}}function Mn(t,e){let r=0,n="",s=0;for(;s<t.length;)if(t[s]==="%"&&s+1<t.length){let i=s+1,o="",a="",l="";for(;i<t.length&&/[-+ #0]/.test(t[i]);)o+=t[i++];for(;i<t.length&&/\d/.test(t[i]);)a+=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))),a){let d=parseInt(a,10);o.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(a){let p=parseInt(a,10);if(o.includes("-"))d=d.padEnd(p);else if(o.includes("0")&&!o.includes("-")){let h=f<0?"-":"";d=h+Math.abs(f).toString().padStart(p-h.length,"0")}else d=d.padStart(p)}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,p=f.toFixed(d);if(a){let h=parseInt(a,10);o.includes("-")?p=p.padEnd(h):p=p.padStart(h)}n+=p,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,p=f.toExponential(d);if(c==="E"&&(p=p.toUpperCase()),a){let h=parseInt(a,10);o.includes("-")?p=p.padEnd(h):p=p.padStart(h)}n+=p,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,p=f!==0?Math.floor(Math.log10(Math.abs(f))):0,h;if(f===0?h="0":p<-4||p>=d?(h=f.toExponential(d-1),c==="G"&&(h=h.toUpperCase())):h=f.toPrecision(d),h=h.replace(/\.?0+$/,"").replace(/\.?0+e/,"e"),a){let w=parseInt(a,10);o.includes("-")?h=h.padEnd(w):h=h.padStart(w)}n+=h,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()),a){let p=parseInt(a,10);o.includes("0")?d=d.padStart(p,"0"):o.includes("-")?d=d.padEnd(p):d=d.padStart(p)}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(a){let p=parseInt(a,10);o.includes("0")?d=d.padStart(p,"0"):o.includes("-")?d=d.padEnd(p):d=d.padStart(p)}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 bo,_n=C(()=>{"use strict";bo={length:ud,substr:fd,index:dd,split:pd,sub:hd,gsub:md,match:gd,gensub:xd,tolower:yd,toupper:wd,sprintf:Ed,int:bd,sqrt:Sd,sin:Cd,cos:Ad,atan2:kd,log:vd,exp:Nd,rand:Id,srand:$d,system:Dn("system","shell execution not allowed in sandboxed environment"),close:Dn("close","file operations not allowed"),fflush:Dn("fflush","file operations not allowed"),systime:Ln("systime"),mktime:Ln("mktime"),strftime:Ln("strftime")}});function xe(t){return typeof t=="number"?t!==0:t!==""}function z(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 Bn(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 At=C(()=>{"use strict"});function So(t,e){return t.FS===" "?e.trim().split(/\s+/).filter(Boolean):e.split(t.fieldSep)}function at(t,e){return e===0?t.line:e<0||e>t.fields.length?"":t.fields[e-1]??""}function kt(t,e,r){if(e===0)t.line=G(r),t.fields=So(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=So(t,e),t.NF=t.fields.length}function Co(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 vr=C(()=>{"use strict";At()});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":Co(t,G(r));return;case"OFS":t.OFS=G(r);return;case"ORS":t.ORS=G(r);return;case"NR":t.NR=Math.floor(z(r));return;case"NF":{let n=Math.floor(z(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(z(r));return;case"FILENAME":t.FILENAME=G(r);return;case"RSTART":t.RSTART=Math.floor(z(r));return;case"RLENGTH":t.RLENGTH=Math.floor(z(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 vt(t,e,r,n){t.arrays[e]||(t.arrays[e]={}),t.arrays[e][r]=n}function Ao(t,e,r){return e==="ARGV"?t.ARGV[r]!==void 0:t.arrays[e]?.[r]!==void 0}function ko(t,e,r){t.arrays[e]&&delete t.arrays[e][r]}function vo(t,e){delete t.arrays[e]}var Wn=C(()=>{"use strict";vr();At()});function No(t){Un=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 Rd(t,e);case"variable":return lt(t,e.name);case"array_access":return Od(t,e);case"binary":return Fd(t,e);case"unary":return Dd(t,e);case"ternary":return xe(await O(t,e.condition))?O(t,e.consequent):O(t,e.alternate);case"call":return Ld(t,e.name,e.args);case"assignment":return _d(t,e);case"pre_increment":return Bd(t,e.operand);case"pre_decrement":return Wd(t,e.operand);case"post_increment":return Ud(t,e.operand);case"post_decrement":return Hd(t,e.operand);case"in":return zd(t,e.key,e.array);case"getline":return jd(t,e.variable,e.file);case"tuple":return qd(t,e.elements);default:return""}}async function Rd(t,e){let r=Math.floor(z(await O(t,e.index)));return at(t,r)}async function Od(t,e){let r=G(await O(t,e.key));return ct(t,e.array,r)}async function Fd(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 a=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(a))?1:0}catch{return 0}}if(r==="!~"){let a=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(a))?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(Pd(r))return Td(n,s,r);let i=z(n),o=z(s);return xo(i,o,r)}function Pd(t){return["<","<=",">",">=","==","!="].includes(t)}function Td(t,e,r){let n=Bn(t),s=Bn(e);if(n&&s){let a=z(t),l=z(e);switch(r){case"<":return a<l?1:0;case"<=":return a<=l?1:0;case">":return a>l?1:0;case">=":return a>=l?1:0;case"==":return a===l?1:0;case"!=":return a!==l?1:0}}let i=G(t),o=G(e);switch(r){case"<":return i<o?1:0;case"<=":return i<=o?1:0;case">":return i>o?1:0;case">=":return i>=o?1:0;case"==":return i===o?1:0;case"!=":return i!==o?1:0}return 0}async function Dd(t,e){let r=await O(t,e.operand);switch(e.operator){case"!":return xe(r)?0:1;case"-":return-z(r);case"+":return+z(r);default:return r}}async function Ld(t,e,r){let n=bo[e];if(n)return n(r,t,{evalExpr:i=>O(t,i)});let s=t.functions.get(e);return s?Md(t,s,r):""}async function Md(t,e,r){if(t.currentRecursionDepth++,t.currentRecursionDepth>t.maxRecursionDepth)throw t.currentRecursionDepth--,new H(`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 o=e.params[i],a=i<r.length?await O(t,r[i]):"";t.vars[o]=a}t.hasReturn=!1,t.returnValue=void 0,Un&&await Un(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 _d(t,e){let r=await O(t,e.value),n=e.target,s=e.operator,i;if(s==="=")i=r;else{let o;if(n.type==="field"){let c=Math.floor(z(await O(t,n.index)));o=at(t,c)}else if(n.type==="variable")o=lt(t,n.name);else{let c=G(await O(t,n.key));o=ct(t,n.array,c)}let a=z(o),l=z(r);switch(s){case"+=":i=a+l;break;case"-=":i=a-l;break;case"*=":i=a*l;break;case"/=":i=l!==0?a/l:0;break;case"%=":i=l!==0?a%l:0;break;case"^=":i=a**l;break;default:i=r}}if(n.type==="field"){let o=Math.floor(z(await O(t,n.index)));kt(t,o,i)}else if(n.type==="variable")Je(t,n.name,i);else{let o=G(await O(t,n.key));vt(t,n.array,o,i)}return i}async function Bd(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await O(t,e.index)));r=z(at(t,n))+1,kt(t,n,r)}else if(e.type==="variable")r=z(lt(t,e.name))+1,Je(t,e.name,r);else{let n=G(await O(t,e.key));r=z(ct(t,e.array,n))+1,vt(t,e.array,n,r)}return r}async function Wd(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await O(t,e.index)));r=z(at(t,n))-1,kt(t,n,r)}else if(e.type==="variable")r=z(lt(t,e.name))-1,Je(t,e.name,r);else{let n=G(await O(t,e.key));r=z(ct(t,e.array,n))-1,vt(t,e.array,n,r)}return r}async function Ud(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await O(t,e.index)));r=z(at(t,n)),kt(t,n,r+1)}else if(e.type==="variable")r=z(lt(t,e.name)),Je(t,e.name,r+1);else{let n=G(await O(t,e.key));r=z(ct(t,e.array,n)),vt(t,e.array,n,r+1)}return r}async function Hd(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await O(t,e.index)));r=z(at(t,n)),kt(t,n,r-1)}else if(e.type==="variable")r=z(lt(t,e.name)),Je(t,e.name,r-1);else{let n=G(await O(t,e.key));r=z(ct(t,e.array,n)),vt(t,e.array,n,r-1)}return r}async function zd(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 Ao(t,r,n)?1:0}async function jd(t,e,r){if(r)return Gd(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 Gd(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}`,o=`__fi_${s}`,a,l;if(t.vars[i]===void 0)try{a=(await t.fs.readFile(s)).split(`
235
- `),a.length>0&&a[a.length-1]===""&&a.pop(),t.vars[i]=JSON.stringify(a),t.vars[o]=-1,l=-1}catch{return-1}else a=JSON.parse(t.vars[i]),l=t.vars[o];let c=l+1;if(c>=a.length)return 0;let u=a[c];return t.vars[o]=c,e?Je(t,e,u):qt(t,u),1}async function qd(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 Un,Hn=C(()=>{"use strict";J();yo();_n();vr();At();Wn();Un=null});async function Nt(t,e){for(let r of e)if(await ut(t,r),Vd(t))break}function Vd(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 Nt(t,e.statements);break;case"expr_stmt":await O(t,e.expression);break;case"print":await Zd(t,e.args,e.output);break;case"printf":await Qd(t,e.format,e.args,e.output);break;case"if":await Xd(t,e);break;case"while":await Kd(t,e);break;case"do_while":await Jd(t,e);break;case"for":await Yd(t,e);break;case"for_in":await ep(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(z(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 tp(t,e.target);break}}async function Zd(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 Io(t,r.redirect,r.file,s):t.output+=s}async function Qd(t,e,r,n){let s=G(await O(t,e)),i=[];for(let a of r)i.push(await O(t,a));let o=Mn(s,i);n?await Io(t,n.redirect,n.file,o):t.output+=o}async function Io(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 Xd(t,e){xe(await O(t,e.condition))?await ut(t,e.consequent):e.alternate&&await ut(t,e.alternate)}async function Kd(t,e){let r=0;for(;xe(await O(t,e.condition));){if(r++,r>t.maxIterations)throw new H(`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 Jd(t,e){let r=0;do{if(r++,r>t.maxIterations)throw new H(`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 Yd(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 H(`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 ep(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 tp(t,e){if(e.type==="array_access"){let r=G(await O(t,e.key));ko(t,e.array,r)}else e.type==="variable"&&vo(t,e.name)}var $o=C(()=>{"use strict";J();_n();Hn();At();Wn();No(Nt)});var Vt,Ro=C(()=>{"use strict";Hn();vr();At();$o();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 Nt(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 Nt(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 Nt(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 Oo=C(()=>{"use strict";go();Ro()});function np(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 x,rp,Nr,Fo=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"})(x||(x={}));rp={BEGIN:x.BEGIN,END:x.END,if:x.IF,else:x.ELSE,while:x.WHILE,do:x.DO,for:x.FOR,in:x.IN,break:x.BREAK,continue:x.CONTINUE,next:x.NEXT,nextfile:x.NEXTFILE,exit:x.EXIT,return:x.RETURN,delete:x.DELETE,function:x.FUNCTION,print:x.PRINT,printf:x.PRINTF,getline:x.GETLINE};Nr=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(x.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===`
223
+ `,exitCode:1};let{commands:c,error:l}=Eo(r,o);if(l)return{stdout:"",stderr:`sed: ${l}
224
+ `,exitCode:1};if(c.length===0)return{stdout:"",stderr:`sed: no valid commands
225
+ `,exitCode:1};let u="";if(a.length===0){u=e.stdin;try{let f=await Mn(u,c,s,{limits:e.limits,fs:e.fs,cwd:e.cwd});return{stdout:f.output,stderr:"",exitCode:f.exitCode??0}}catch(f){if(f instanceof W)return{stdout:"",stderr:`sed: ${f.message}
226
+ `,exitCode:W.EXIT_CODE};throw f}}if(i){for(let f of a){let p=e.fs.resolvePath(e.cwd,f);try{let d=await e.fs.readFile(p),h=await Mn(d,c,s,{limits:e.limits,filename:f,fs:e.fs,cwd:e.cwd});await e.fs.writeFile(p,h.output)}catch(d){return d instanceof W?{stdout:"",stderr:`sed: ${d.message}
227
+ `,exitCode:W.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
228
+ `,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}for(let f of a){let p=e.fs.resolvePath(e.cwd,f);try{u+=await e.fs.readFile(p)}catch(d){return d instanceof W?{stdout:"",stderr:`sed: ${d.message}
229
+ `,exitCode:W.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
230
+ `,exitCode:1}}}try{let f=await Mn(u,c,s,{limits:e.limits,filename:a.length===1?a[0]:void 0,fs:e.fs,cwd:e.cwd});return{stdout:f.output,stderr:"",exitCode:f.exitCode??0}}catch(f){if(f instanceof W)return{stdout:"",stderr:`sed: ${f.message}
231
+ `,exitCode:W.EXIT_CODE};throw f}}}});function _n(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 Co=A(()=>{"use strict"});function ko(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 No=A(()=>{"use strict"});function Ne(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function ie(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}async function kp(t,e,r){return t.length===0?e.line.length:ie(await r.evalExpr(t[0])).length}async function Np(t,e,r){if(t.length<2)return"";let n=ie(await r.evalExpr(t[0])),s=Math.floor(Ne(await r.evalExpr(t[1])))-1;if(t.length>=3){let i=Math.floor(Ne(await r.evalExpr(t[2])));return n.substr(Math.max(0,s),i)}return n.substr(Math.max(0,s))}async function Ip(t,e,r){if(t.length<2)return 0;let n=ie(await r.evalExpr(t[0])),s=ie(await r.evalExpr(t[1])),i=n.indexOf(s);return i===-1?0:i+1}async function vp(t,e,r){if(t.length<2)return 0;let n=ie(await r.evalExpr(t[0])),s=t[1];if(s.type!=="variable")return 0;let i=s.name,o=e.FS;if(t.length>=3){let c=ie(await r.evalExpr(t[2]));o=c===" "?/\s+/:c}else e.FS===" "&&(o=/\s+/);let a=n.split(o);e.arrays[i]={};for(let c=0;c<a.length;c++)e.arrays[i][String(c+1)]=a[c];return a.length}async function Rp(t,e,r){if(t.length<2)return 0;let n;t[0].type==="regex"?n=t[0].pattern:(n=ie(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=ie(await r.evalExpr(t[1])),i="$0";if(t.length>=3){let a=t[2];a.type==="variable"?i=a.name:a.type==="field"&&(i=`$${Math.floor(Ne(await r.evalExpr(a.index)))}`)}let o;if(i==="$0")o=e.line;else if(i.startsWith("$")){let a=parseInt(i.slice(1),10)-1;o=e.fields[a]||""}else o=ie(e.vars[i]??"");try{let a=new RegExp(n),c=o.replace(a,vo(s)),l=c!==o?1:0;if(i==="$0")e.line=c,e.fields=e.FS===" "?c.trim().split(/\s+/).filter(Boolean):c.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]=c,e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}else e.vars[i]=c;return l}catch{return 0}}async function $p(t,e,r){if(t.length<2)return 0;let n;t[0].type==="regex"?n=t[0].pattern:(n=ie(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=ie(await r.evalExpr(t[1])),i="$0";if(t.length>=3){let a=t[2];a.type==="variable"?i=a.name:a.type==="field"&&(i=`$${Math.floor(Ne(await r.evalExpr(a.index)))}`)}let o;if(i==="$0")o=e.line;else if(i.startsWith("$")){let a=parseInt(i.slice(1),10)-1;o=e.fields[a]||""}else o=ie(e.vars[i]??"");try{let a=new RegExp(n,"g"),c=o.match(a),l=c?c.length:0,u=o.replace(a,vo(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 l}catch{return 0}}function vo(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 Op(t,e,r){if(t.length<2)return e.RSTART=0,e.RLENGTH=-1,0;let n=ie(await r.evalExpr(t[0])),s;t[1].type==="regex"?s=t[1].pattern:(s=ie(await r.evalExpr(t[1])),s.startsWith("/")&&s.endsWith("/")&&(s=s.slice(1,-1)));try{let o=new RegExp(s).exec(n);if(o)return e.RSTART=o.index+1,e.RLENGTH=o[0].length,e.RSTART}catch{}return e.RSTART=0,e.RLENGTH=-1,0}async function Pp(t,e,r){if(t.length<3)return"";let n;t[0].type==="regex"?n=t[0].pattern:(n=ie(await r.evalExpr(t[0])),n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)));let s=ie(await r.evalExpr(t[1])),i=ie(await r.evalExpr(t[2])),o=t.length>=4?ie(await r.evalExpr(t[3])):e.line;try{let a=i.toLowerCase()==="g",c=a?0:parseInt(i,10)||1;if(a){let l=new RegExp(n,"g");return o.replace(l,(u,...f)=>Io(s,u,f.slice(0,-2)))}else{let l=0,u=new RegExp(n,"g");return o.replace(u,(f,...p)=>(l++,l===c?Io(s,f,p.slice(0,-2)):f))}}catch{return o}}function Io(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 o=parseInt(i,10)-1;n+=r[o]||"",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 Tp(t,e,r){return t.length===0?"":ie(await r.evalExpr(t[0])).toLowerCase()}async function Fp(t,e,r){return t.length===0?"":ie(await r.evalExpr(t[0])).toUpperCase()}async function Dp(t,e,r){if(t.length===0)return"";let n=ie(await r.evalExpr(t[0])),s=[];for(let i=1;i<t.length;i++)s.push(await r.evalExpr(t[i]));return Un(n,s)}async function Lp(t,e,r){return t.length===0?0:Math.floor(Ne(await r.evalExpr(t[0])))}async function Mp(t,e,r){return t.length===0?0:Math.sqrt(Ne(await r.evalExpr(t[0])))}async function _p(t,e,r){return t.length===0?0:Math.sin(Ne(await r.evalExpr(t[0])))}async function Bp(t,e,r){return t.length===0?0:Math.cos(Ne(await r.evalExpr(t[0])))}async function Wp(t,e,r){let n=t.length>0?Ne(await r.evalExpr(t[0])):0,s=t.length>1?Ne(await r.evalExpr(t[1])):0;return Math.atan2(n,s)}async function Up(t,e,r){return t.length===0?0:Math.log(Ne(await r.evalExpr(t[0])))}async function Hp(t,e,r){return t.length===0?1:Math.exp(Ne(await r.evalExpr(t[0])))}function jp(t,e,r){return e.random?e.random():Math.random()}async function zp(t,e,r){let n=t.length>0?Ne(await r.evalExpr(t[0])):Date.now();return e.vars._srand_seed=n,n}function Bn(t,e){return()=>{throw new Error(`${t}() is not supported - ${e}`)}}function Wn(t){return()=>{throw new Error(`function '${t}()' is not implemented`)}}function Un(t,e){let r=0,n="",s=0;for(;s<t.length;)if(t[s]==="%"&&s+1<t.length){let i=s+1,o="",a="",c="";for(;i<t.length&&/[-+ #0]/.test(t[i]);)o+=t[i++];for(;i<t.length&&/\d/.test(t[i]);)a+=t[i++];if(t[i]===".")for(i++;i<t.length&&/\d/.test(t[i]);)c+=t[i++];let l=t[i],u=e[r];switch(l){case"s":{let f=u!==void 0?String(u):"";if(c&&(f=f.substring(0,parseInt(c,10))),a){let p=parseInt(a,10);o.includes("-")?f=f.padEnd(p):f=f.padStart(p)}n+=f,r++;break}case"d":case"i":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let p=String(f);if(a){let d=parseInt(a,10);if(o.includes("-"))p=p.padEnd(d);else if(o.includes("0")&&!o.includes("-")){let h=f<0?"-":"";p=h+Math.abs(f).toString().padStart(d-h.length,"0")}else p=p.padStart(d)}n+=p,r++;break}case"f":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let p=c?parseInt(c,10):6,d=f.toFixed(p);if(a){let h=parseInt(a,10);o.includes("-")?d=d.padEnd(h):d=d.padStart(h)}n+=d,r++;break}case"e":case"E":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let p=c?parseInt(c,10):6,d=f.toExponential(p);if(l==="E"&&(d=d.toUpperCase()),a){let h=parseInt(a,10);o.includes("-")?d=d.padEnd(h):d=d.padStart(h)}n+=d,r++;break}case"g":case"G":{let f=u!==void 0?Number(u):0;Number.isNaN(f)&&(f=0);let p=c?parseInt(c,10):6,d=f!==0?Math.floor(Math.log10(Math.abs(f))):0,h;if(f===0?h="0":d<-4||d>=p?(h=f.toExponential(p-1),l==="G"&&(h=h.toUpperCase())):h=f.toPrecision(p),h=h.replace(/\.?0+$/,"").replace(/\.?0+e/,"e"),a){let g=parseInt(a,10);o.includes("-")?h=h.padEnd(g):h=h.padStart(g)}n+=h,r++;break}case"x":case"X":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let p=Math.abs(f).toString(16);if(l==="X"&&(p=p.toUpperCase()),a){let d=parseInt(a,10);o.includes("0")?p=p.padStart(d,"0"):o.includes("-")?p=p.padEnd(d):p=p.padStart(d)}n+=f<0?`-${p}`:p,r++;break}case"o":{let f=u!==void 0?Math.floor(Number(u)):0;Number.isNaN(f)&&(f=0);let p=Math.abs(f).toString(8);if(a){let d=parseInt(a,10);o.includes("0")?p=p.padStart(d,"0"):o.includes("-")?p=p.padEnd(d):p=p.padStart(d)}n+=f<0?`-${p}`:p,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 Ro,Hn=A(()=>{"use strict";Ro={length:kp,substr:Np,index:Ip,split:vp,sub:Rp,gsub:$p,match:Op,gensub:Pp,tolower:Tp,toupper:Fp,sprintf:Dp,int:Lp,sqrt:Mp,sin:_p,cos:Bp,atan2:Wp,log:Up,exp:Hp,rand:jp,srand:zp,system:Bn("system","shell execution not allowed in sandboxed environment"),close:Bn("close","file operations not allowed"),fflush:Bn("fflush","file operations not allowed"),systime:Wn("systime"),mktime:Wn("mktime"),strftime:Wn("strftime")}});function we(t){return typeof t=="number"?t!==0:t!==""}function z(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function q(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}function jn(t){if(typeof t=="number")return!0;let e=String(t).trim();return e===""?!1:!Number.isNaN(Number(e))}function Kt(t,e){try{return new RegExp(t).test(e)}catch{return!1}}var It=A(()=>{"use strict"});function $o(t,e){return t.FS===" "?e.trim().split(/\s+/).filter(Boolean):e.split(t.fieldSep)}function ct(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=q(r),t.fields=$o(t,t.line),t.NF=t.fields.length;else if(e>0){for(;t.fields.length<e;)t.fields.push("");t.fields[e-1]=q(r),t.NF=t.fields.length,t.line=t.fields.join(t.OFS)}}function Zt(t,e){t.line=e,t.fields=$o(t,e),t.NF=t.fields.length}function Oo(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 vr=A(()=>{"use strict";It()});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 et(t,e,r){switch(e){case"FS":Oo(t,q(r));return;case"OFS":t.OFS=q(r);return;case"ORS":t.ORS=q(r);return;case"NR":t.NR=Math.floor(z(r));return;case"NF":{let n=Math.floor(z(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(z(r));return;case"FILENAME":t.FILENAME=q(r);return;case"RSTART":t.RSTART=Math.floor(z(r));return;case"RLENGTH":t.RLENGTH=Math.floor(z(r));return;case"SUBSEP":t.SUBSEP=q(r);return}t.vars[e]=r}function ut(t,e,r){return e==="ARGV"?t.ARGV[r]??"":t.arrays[e]?.[r]??""}function Rt(t,e,r,n){t.arrays[e]||(t.arrays[e]={}),t.arrays[e][r]=n}function Po(t,e,r){return e==="ARGV"?t.ARGV[r]!==void 0:t.arrays[e]?.[r]!==void 0}function To(t,e,r){t.arrays[e]&&delete t.arrays[e][r]}function Fo(t,e){delete t.arrays[e]}var zn=A(()=>{"use strict";vr();It()});function Do(t){Gn=t}async function T(t,e){switch(e.type){case"number":return e.value;case"string":return e.value;case"regex":return Kt(e.pattern,t.line)?1:0;case"field":return Gp(t,e);case"variable":return lt(t,e.name);case"array_access":return qp(t,e);case"binary":return Vp(t,e);case"unary":return Qp(t,e);case"ternary":return we(await T(t,e.condition))?T(t,e.consequent):T(t,e.alternate);case"call":return Xp(t,e.name,e.args);case"assignment":return Yp(t,e);case"pre_increment":return ed(t,e.operand);case"pre_decrement":return td(t,e.operand);case"post_increment":return rd(t,e.operand);case"post_decrement":return nd(t,e.operand);case"in":return sd(t,e.key,e.array);case"getline":return id(t,e.variable,e.file);case"tuple":return ad(t,e.elements);default:return""}}async function Gp(t,e){let r=Math.floor(z(await T(t,e.index)));return ct(t,r)}async function qp(t,e){let r=q(await T(t,e.key));return ut(t,e.array,r)}async function Vp(t,e){let r=e.operator;if(r==="||")return we(await T(t,e.left))||we(await T(t,e.right))?1:0;if(r==="&&")return we(await T(t,e.left))&&we(await T(t,e.right))?1:0;if(r==="~"){let a=await T(t,e.left),c=e.right.type==="regex"?e.right.pattern:q(await T(t,e.right));try{return new RegExp(c).test(q(a))?1:0}catch{return 0}}if(r==="!~"){let a=await T(t,e.left),c=e.right.type==="regex"?e.right.pattern:q(await T(t,e.right));try{return new RegExp(c).test(q(a))?0:1}catch{return 1}}let n=await T(t,e.left),s=await T(t,e.right);if(r===" ")return q(n)+q(s);if(Kp(r))return Zp(n,s,r);let i=z(n),o=z(s);return ko(i,o,r)}function Kp(t){return["<","<=",">",">=","==","!="].includes(t)}function Zp(t,e,r){let n=jn(t),s=jn(e);if(n&&s){let a=z(t),c=z(e);switch(r){case"<":return a<c?1:0;case"<=":return a<=c?1:0;case">":return a>c?1:0;case">=":return a>=c?1:0;case"==":return a===c?1:0;case"!=":return a!==c?1:0}}let i=q(t),o=q(e);switch(r){case"<":return i<o?1:0;case"<=":return i<=o?1:0;case">":return i>o?1:0;case">=":return i>=o?1:0;case"==":return i===o?1:0;case"!=":return i!==o?1:0}return 0}async function Qp(t,e){let r=await T(t,e.operand);switch(e.operator){case"!":return we(r)?0:1;case"-":return-z(r);case"+":return+z(r);default:return r}}async function Xp(t,e,r){let n=Ro[e];if(n)return n(r,t,{evalExpr:i=>T(t,i)});let s=t.functions.get(e);return s?Jp(t,s,r):""}async function Jp(t,e,r){if(t.currentRecursionDepth++,t.currentRecursionDepth>t.maxRecursionDepth)throw t.currentRecursionDepth--,new W(`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 o=e.params[i],a=i<r.length?await T(t,r[i]):"";t.vars[o]=a}t.hasReturn=!1,t.returnValue=void 0,Gn&&await Gn(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 Yp(t,e){let r=await T(t,e.value),n=e.target,s=e.operator,i;if(s==="=")i=r;else{let o;if(n.type==="field"){let l=Math.floor(z(await T(t,n.index)));o=ct(t,l)}else if(n.type==="variable")o=lt(t,n.name);else{let l=q(await T(t,n.key));o=ut(t,n.array,l)}let a=z(o),c=z(r);switch(s){case"+=":i=a+c;break;case"-=":i=a-c;break;case"*=":i=a*c;break;case"/=":i=c!==0?a/c:0;break;case"%=":i=c!==0?a%c:0;break;case"^=":i=a**c;break;default:i=r}}if(n.type==="field"){let o=Math.floor(z(await T(t,n.index)));vt(t,o,i)}else if(n.type==="variable")et(t,n.name,i);else{let o=q(await T(t,n.key));Rt(t,n.array,o,i)}return i}async function ed(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await T(t,e.index)));r=z(ct(t,n))+1,vt(t,n,r)}else if(e.type==="variable")r=z(lt(t,e.name))+1,et(t,e.name,r);else{let n=q(await T(t,e.key));r=z(ut(t,e.array,n))+1,Rt(t,e.array,n,r)}return r}async function td(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await T(t,e.index)));r=z(ct(t,n))-1,vt(t,n,r)}else if(e.type==="variable")r=z(lt(t,e.name))-1,et(t,e.name,r);else{let n=q(await T(t,e.key));r=z(ut(t,e.array,n))-1,Rt(t,e.array,n,r)}return r}async function rd(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await T(t,e.index)));r=z(ct(t,n)),vt(t,n,r+1)}else if(e.type==="variable")r=z(lt(t,e.name)),et(t,e.name,r+1);else{let n=q(await T(t,e.key));r=z(ut(t,e.array,n)),Rt(t,e.array,n,r+1)}return r}async function nd(t,e){let r;if(e.type==="field"){let n=Math.floor(z(await T(t,e.index)));r=z(ct(t,n)),vt(t,n,r-1)}else if(e.type==="variable")r=z(lt(t,e.name)),et(t,e.name,r-1);else{let n=q(await T(t,e.key));r=z(ut(t,e.array,n)),Rt(t,e.array,n,r-1)}return r}async function sd(t,e,r){let n;if(e.type==="tuple"){let s=[];for(let i of e.elements)s.push(q(await T(t,i)));n=s.join(t.SUBSEP)}else n=q(await T(t,e));return Po(t,r,n)?1:0}async function id(t,e,r){if(r)return od(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?et(t,e,s):Zt(t,s),t.NR++,t.lineIndex=n,1}async function od(t,e,r){if(!t.fs||!t.cwd)return-1;let n=q(await T(t,r)),s=t.fs.resolvePath(t.cwd,n),i=`__fc_${s}`,o=`__fi_${s}`,a,c;if(t.vars[i]===void 0)try{a=(await t.fs.readFile(s)).split(`
235
+ `),a.length>0&&a[a.length-1]===""&&a.pop(),t.vars[i]=JSON.stringify(a),t.vars[o]=-1,c=-1}catch{return-1}else a=JSON.parse(t.vars[i]),c=t.vars[o];let l=c+1;if(l>=a.length)return 0;let u=a[l];return t.vars[o]=l,e?et(t,e,u):Zt(t,u),1}async function ad(t,e){if(e.length===0)return"";for(let r=0;r<e.length-1;r++)await T(t,e[r]);return T(t,e[e.length-1])}var Gn,qn=A(()=>{"use strict";J();No();Hn();vr();It();zn();Gn=null});async function $t(t,e){for(let r of e)if(await ft(t,r),cd(t))break}function cd(t){return t.shouldExit||t.shouldNext||t.shouldNextFile||t.loopBreak||t.loopContinue||t.hasReturn}async function ft(t,e){switch(e.type){case"block":await $t(t,e.statements);break;case"expr_stmt":await T(t,e.expression);break;case"print":await ld(t,e.args,e.output);break;case"printf":await ud(t,e.format,e.args,e.output);break;case"if":await fd(t,e);break;case"while":await pd(t,e);break;case"do_while":await dd(t,e);break;case"for":await hd(t,e);break;case"for_in":await md(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(z(await T(t,e.code))):0;break;case"return":t.hasReturn=!0,t.returnValue=e.value?await T(t,e.value):"";break;case"delete":await yd(t,e.target);break}}async function ld(t,e,r){let n=[];for(let i of e)n.push(q(await T(t,i)));let s=n.join(t.OFS)+t.ORS;r?await Lo(t,r.redirect,r.file,s):t.output+=s}async function ud(t,e,r,n){let s=q(await T(t,e)),i=[];for(let a of r)i.push(await T(t,a));let o=Un(s,i);n?await Lo(t,n.redirect,n.file,o):t.output+=o}async function Lo(t,e,r,n){if(!t.fs||!t.cwd){t.output+=n;return}let s=q(await T(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 fd(t,e){we(await T(t,e.condition))?await ft(t,e.consequent):e.alternate&&await ft(t,e.alternate)}async function pd(t,e){let r=0;for(;we(await T(t,e.condition));){if(r++,r>t.maxIterations)throw new W(`awk: while loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ft(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}}async function dd(t,e){let r=0;do{if(r++,r>t.maxIterations)throw new W(`awk: do-while loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ft(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}while(we(await T(t,e.condition)))}async function hd(t,e){e.init&&await T(t,e.init);let r=0;for(;!e.condition||we(await T(t,e.condition));){if(r++,r>t.maxIterations)throw new W(`awk: for loop exceeded maximum iterations (${t.maxIterations})`,"iterations",t.output);if(t.loopContinue=!1,await ft(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break;e.update&&await T(t,e.update)}}async function md(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 ft(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}}async function yd(t,e){if(e.type==="array_access"){let r=q(await T(t,e.key));To(t,e.array,r)}else e.type==="variable"&&Fo(t,e.name)}var Mo=A(()=>{"use strict";J();Hn();qn();It();zn();Do($t)});var Qt,_o=A(()=>{"use strict";qn();vr();It();Mo();Qt=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 $t(this.ctx,e.action.statements),this.ctx.shouldExit))break}}async executeLine(e){if(!(!this.program||this.ctx.shouldExit)){Zt(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 $t(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 $t(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 Kt(n.pattern,this.ctx.line);case"expr_pattern":return we(await T(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 Kt(e.pattern,this.ctx.line);case"expr_pattern":return we(await T(this.ctx,e.expression));default:return!1}}}});var Bo=A(()=>{"use strict";Co();_o()});function xd(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 x,gd,Rr,Wo=A(()=>{"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"})(x||(x={}));gd={BEGIN:x.BEGIN,END:x.END,if:x.IF,else:x.ELSE,while:x.WHILE,do:x.DO,for:x.FOR,in:x.IN,break:x.BREAK,continue:x.CONTINUE,next:x.NEXT,nextfile:x.NEXTFILE,exit:x.EXIT,return:x.RETURN,delete:x.DELETE,function:x.FUNCTION,print:x.PRINT,printf:x.PRINTF,getline:x.GETLINE};Rr=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(x.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
239
  `?(this.advance(),{type:x.NEWLINE,value:`
240
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,x.NEWLINE,x.SEMICOLON,x.LBRACE,x.RBRACE,x.LPAREN,x.LBRACKET,x.COMMA,x.ASSIGN,x.PLUS_ASSIGN,x.MINUS_ASSIGN,x.STAR_ASSIGN,x.SLASH_ASSIGN,x.PERCENT_ASSIGN,x.CARET_ASSIGN,x.AND,x.OR,x.NOT,x.MATCH,x.NOT_MATCH,x.QUESTION,x.COLON,x.LT,x.GT,x.LE,x.GE,x.EQ,x.NE,x.PLUS,x.MINUS,x.STAR,x.PERCENT,x.CARET,x.PRINT,x.PRINTF,x.IF,x.WHILE,x.DO,x.FOR,x.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
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:x.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=np(n),{type:x.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:x.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=rp[n];return s?{type:s,value:n,line:e,column:r}:{type:x.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:x.INCREMENT,value:"++",line:e,column:r}):s==="="?(this.advance(),{type:x.PLUS_ASSIGN,value:"+=",line:e,column:r}):{type:x.PLUS,value:"+",line:e,column:r};case"-":return s==="-"?(this.advance(),{type:x.DECREMENT,value:"--",line:e,column:r}):s==="="?(this.advance(),{type:x.MINUS_ASSIGN,value:"-=",line:e,column:r}):{type:x.MINUS,value:"-",line:e,column:r};case"*":return s==="*"?(this.advance(),{type:x.CARET,value:"**",line:e,column:r}):s==="="?(this.advance(),{type:x.STAR_ASSIGN,value:"*=",line:e,column:r}):{type:x.STAR,value:"*",line:e,column:r};case"/":return s==="="?(this.advance(),{type:x.SLASH_ASSIGN,value:"/=",line:e,column:r}):{type:x.SLASH,value:"/",line:e,column:r};case"%":return s==="="?(this.advance(),{type:x.PERCENT_ASSIGN,value:"%=",line:e,column:r}):{type:x.PERCENT,value:"%",line:e,column:r};case"^":return s==="="?(this.advance(),{type:x.CARET_ASSIGN,value:"^=",line:e,column:r}):{type:x.CARET,value:"^",line:e,column:r};case"=":return s==="="?(this.advance(),{type:x.EQ,value:"==",line:e,column:r}):{type:x.ASSIGN,value:"=",line:e,column:r};case"!":return s==="="?(this.advance(),{type:x.NE,value:"!=",line:e,column:r}):s==="~"?(this.advance(),{type:x.NOT_MATCH,value:"!~",line:e,column:r}):{type:x.NOT,value:"!",line:e,column:r};case"<":return s==="="?(this.advance(),{type:x.LE,value:"<=",line:e,column:r}):{type:x.LT,value:"<",line:e,column:r};case">":return s==="="?(this.advance(),{type:x.GE,value:">=",line:e,column:r}):s===">"?(this.advance(),{type:x.APPEND,value:">>",line:e,column:r}):{type:x.GT,value:">",line:e,column:r};case"&":return s==="&"?(this.advance(),{type:x.AND,value:"&&",line:e,column:r}):{type:x.IDENT,value:"&",line:e,column:r};case"|":return s==="|"?(this.advance(),{type:x.OR,value:"||",line:e,column:r}):{type:x.PIPE,value:"|",line:e,column:r};case"~":return{type:x.MATCH,value:"~",line:e,column:r};case"?":return{type:x.QUESTION,value:"?",line:e,column:r};case":":return{type:x.COLON,value:":",line:e,column:r};case",":return{type:x.COMMA,value:",",line:e,column:r};case";":return{type:x.SEMICOLON,value:";",line:e,column:r};case"(":return{type:x.LPAREN,value:"(",line:e,column:r};case")":return{type:x.RPAREN,value:")",line:e,column:r};case"{":return{type:x.LBRACE,value:"{",line:e,column:r};case"}":return{type:x.RBRACE,value:"}",line:e,column:r};case"[":return{type:x.LBRACKET,value:"[",line:e,column:r};case"]":return{type:x.RBRACKET,value:"]",line:e,column:r};case"$":return{type:x.DOLLAR,value:"$",line:e,column:r};default:return{type:x.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 Ir,Po=C(()=>{"use strict";Fo();Ir=class{tokens=[];pos=0;parse(e){let r=new Nr(e);return this.tokens=r.tokenize(),this.pos=0,this.parseProgram()}current(){return this.tokens[this.pos]||{type:x.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(x.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(x.NEWLINE)||this.check(x.SEMICOLON);)this.advance()}parseProgram(){let e=[],r=[];for(this.skipNewlines();!this.check(x.EOF)&&(this.skipNewlines(),!this.check(x.EOF));)this.check(x.FUNCTION)?e.push(this.parseFunction()):r.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:r}}parseFunction(){this.expect(x.FUNCTION);let e=this.expect(x.IDENT).value;this.expect(x.LPAREN);let r=[];if(!this.check(x.RPAREN))for(r.push(this.expect(x.IDENT).value);this.check(x.COMMA);)this.advance(),r.push(this.expect(x.IDENT).value);this.expect(x.RPAREN),this.skipNewlines();let n=this.parseBlock();return{name:e,params:r,body:n}}parseRule(){let e;if(this.check(x.BEGIN))this.advance(),e={type:"begin"};else if(this.check(x.END))this.advance(),e={type:"end"};else if(this.check(x.LBRACE))e=void 0;else if(this.check(x.REGEX)){let n=this.advance();if(this.check(x.AND)||this.check(x.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(x.COMMA)){this.advance();let i;this.check(x.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(x.COMMA)){this.advance();let i;this.check(x.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(x.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(x.LBRACE),this.skipNewlines();let e=[];for(;!this.check(x.RBRACE)&&!this.check(x.EOF);)e.push(this.parseStatement()),this.skipTerminators();return this.expect(x.RBRACE),{type:"block",statements:e}}parseStatement(){if(this.check(x.LBRACE))return this.parseBlock();if(this.check(x.IF))return this.parseIf();if(this.check(x.WHILE))return this.parseWhile();if(this.check(x.DO))return this.parseDoWhile();if(this.check(x.FOR))return this.parseFor();if(this.check(x.BREAK))return this.advance(),{type:"break"};if(this.check(x.CONTINUE))return this.advance(),{type:"continue"};if(this.check(x.NEXT))return this.advance(),{type:"next"};if(this.check(x.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(x.EXIT)){this.advance();let r;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(r=this.parseExpression()),{type:"exit",code:r}}if(this.check(x.RETURN)){this.advance();let r;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(r=this.parseExpression()),{type:"return",value:r}}if(this.check(x.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(x.PRINT)?this.parsePrint():this.check(x.PRINTF)?this.parsePrintf():{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(x.IF),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let r=this.parseStatement();this.skipTerminators();let n;return this.check(x.ELSE)&&(this.advance(),this.skipNewlines(),n=this.parseStatement()),{type:"if",condition:e,consequent:r,alternate:n}}parseWhile(){this.expect(x.WHILE),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let r=this.parseStatement();return{type:"while",condition:e,body:r}}parseDoWhile(){this.expect(x.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(x.WHILE),this.expect(x.LPAREN);let r=this.parseExpression();return this.expect(x.RPAREN),{type:"do_while",body:e,condition:r}}parseFor(){if(this.expect(x.FOR),this.expect(x.LPAREN),this.check(x.IDENT)){let i=this.advance();if(this.check(x.IN)){this.advance();let o=this.expect(x.IDENT).value;this.expect(x.RPAREN),this.skipNewlines();let a=this.parseStatement();return{type:"for_in",variable:i.value,array:o,body:a}}this.pos--}let e;this.check(x.SEMICOLON)||(e=this.parseExpression()),this.expect(x.SEMICOLON);let r;this.check(x.SEMICOLON)||(r=this.parseExpression()),this.expect(x.SEMICOLON);let n;this.check(x.RPAREN)||(n=this.parseExpression()),this.expect(x.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:r,update:n,body:s}}parsePrint(){this.expect(x.PRINT);let e=[];if(this.check(x.NEWLINE)||this.check(x.SEMICOLON)||this.check(x.RBRACE)||this.check(x.PIPE)||this.check(x.GT)||this.check(x.APPEND))e.push({type:"field",index:{type:"number",value:0}});else for(e.push(this.parsePrintArg());this.check(x.COMMA);)this.advance(),e.push(this.parsePrintArg());let r;return this.check(x.GT)?(this.advance(),r={redirect:">",file:this.parsePrimary()}):this.check(x.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===x.LPAREN&&e++,n.type===x.RPAREN&&e--,n.type===x.QUESTION&&e===0)return!0;if(n.type===x.NEWLINE||n.type===x.SEMICOLON||n.type===x.RBRACE||n.type===x.COMMA||n.type===x.PIPE)return!1;r++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(x.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(x.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(x.IN)){this.advance();let r=String(this.expect(x.IDENT).value);return{type:"in",key:e,array:r}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let r=this.advance().type===x.MATCH?"~":"!~",n=this.parsePrintComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GE,x.EQ,x.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parsePrintf(){this.expect(x.PRINTF);let e=this.parsePrintArg(),r=[];for(;this.check(x.COMMA);)this.advance(),r.push(this.parsePrintArg());let n;return this.check(x.GT)?(this.advance(),n={redirect:">",file:this.parsePrimary()}):this.check(x.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(x.ASSIGN,x.PLUS_ASSIGN,x.MINUS_ASSIGN,x.STAR_ASSIGN,x.SLASH_ASSIGN,x.PERCENT_ASSIGN,x.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(x.QUESTION)){this.advance();let r=this.parseExpression();this.expect(x.COLON);let n=this.parseExpression();e={type:"ternary",condition:e,consequent:r,alternate:n}}return e}parseOr(){let e=this.parseAnd();for(;this.check(x.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(x.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalAndRest(e){for(;this.check(x.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(x.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(x.IN)){this.advance();let r=this.expect(x.IDENT).value;return{type:"in",key:e,array:r}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let r=this.advance().type===x.MATCH?"~":"!~",n=this.parseComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.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(x.NUMBER,x.STRING,x.IDENT,x.DOLLAR,x.LPAREN,x.NOT,x.MINUS,x.PLUS,x.INCREMENT,x.DECREMENT)}isComparisonOrHigherOp(){return this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.NE,x.AND,x.OR,x.QUESTION,x.MATCH,x.NOT_MATCH,x.ASSIGN,x.PLUS_ASSIGN,x.MINUS_ASSIGN,x.STAR_ASSIGN,x.SLASH_ASSIGN,x.PERCENT_ASSIGN,x.CARET_ASSIGN,x.COMMA,x.SEMICOLON,x.NEWLINE,x.RBRACE,x.RPAREN,x.RBRACKET,x.COLON,x.PIPE,x.APPEND,x.IN)}parseAddSub(){let e=this.parseMulDiv();for(;this.match(x.PLUS,x.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(x.STAR,x.SLASH,x.PERCENT);){let r=this.advance(),n=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[r.value],left:e,right:n}}return e}parseUnary(){if(this.check(x.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(x.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(x.NOT,x.MINUS,x.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(x.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(x.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(x.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(x.NUMBER))return{type:"number",value:this.advance().value};if(this.check(x.STRING))return{type:"string",value:this.advance().value};if(this.check(x.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(x.DOLLAR))return this.advance(),{type:"field",index:this.parsePrimary()};if(this.check(x.LPAREN)){this.advance();let e=this.parseExpression();if(this.check(x.COMMA)){let r=[e];for(;this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(x.RPAREN),{type:"tuple",elements:r}}return this.expect(x.RPAREN),e}if(this.check(x.GETLINE)){this.advance();let e,r;return this.check(x.IDENT)&&(e=this.advance().value),this.check(x.LT)&&(this.advance(),r=this.parsePrimary()),{type:"getline",variable:e,file:r}}if(this.check(x.IDENT)){let e=this.advance().value;if(this.check(x.LPAREN)){this.advance();let r=[];if(!this.check(x.RPAREN))for(r.push(this.parseExpression());this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(x.RPAREN),{type:"call",name:e,args:r}}if(this.check(x.LBRACKET)){this.advance();let r=[this.parseExpression()];for(;this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());this.expect(x.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 Mo={};$(Mo,{awkCommand2:()=>ip});function To(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
243
- `).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Do(t){if(t===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(t))try{return new RegExp(t)}catch{return new RegExp(Lo(t))}return new RegExp(Lo(t))}function Lo(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var sp,ip,_o=C(()=>{"use strict";J();M();Oo();Po();sp={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"]},ip={name:"awk",async execute(t,e){if(v(t))return k(sp);let r=/\s+/,n=" ",s={},i=0;for(let p=0;p<t.length;p++){let h=t[p];if(h==="-F"&&p+1<t.length)n=To(t[++p]),r=Do(n),i=p+1;else if(h.startsWith("-F"))n=To(h.slice(2)),r=Do(n),i=p+1;else if(h==="-v"&&p+1<t.length){let w=t[++p],g=w.indexOf("=");if(g>0){let y=w.slice(0,g),E=w.slice(g+1);s[y]=E}i=p+1}else{if(h.startsWith("--"))return T("awk",h);if(h.startsWith("-")&&h.length>1){let w=h[1];if(w!=="F"&&w!=="v")return T("awk",`-${w}`);i=p+1}else if(!h.startsWith("-")){i=p;break}}}if(i>=t.length)return{stdout:"",stderr:`awk: missing program
244
- `,exitCode:1};let o=t[i],a=t.slice(i+1),l=new Ir,c;try{c=l.parse(o)}catch(p){return{stdout:"",stderr:`awk: ${p instanceof Error?p.message:String(p)}
245
- `,exitCode:1}}let u={readFile:e.fs.readFile.bind(e.fs),writeFile:e.fs.writeFile.bind(e.fs),appendFile:async(p,h)=>{try{let w=await e.fs.readFile(p);await e.fs.writeFile(p,w+h)}catch{await e.fs.writeFile(p,h)}},resolvePath:e.fs.resolvePath.bind(e.fs)},f=Tn({fieldSep:r,maxIterations:e.limits?.maxAwkIterations,fs:u,cwd:e.cwd});f.FS=n,f.vars={...s},f.ARGC=a.length+1,f.ARGV={0:"awk"};for(let p=0;p<a.length;p++)f.ARGV[String(p+1)]=a[p];let d=new Vt(f);d.execute(c);try{if(await d.executeBegin(),f.shouldExit)return{stdout:d.getOutput(),stderr:"",exitCode:d.getExitCode()};let p=[];if(a.length>0)for(let h of a)try{let w=e.fs.resolvePath(e.cwd,h),y=(await e.fs.readFile(w)).split(`
246
- `);y.length>0&&y[y.length-1]===""&&y.pop(),p.push({filename:h,lines:y})}catch{return{stdout:"",stderr:`awk: ${h}: No such file or directory
242
+ `)break;n+=this.advance()}return this.peek()==="/"&&this.advance(),n=xd(n),{type:x.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:x.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=gd[n];return s?{type:s,value:n,line:e,column:r}:{type:x.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:x.INCREMENT,value:"++",line:e,column:r}):s==="="?(this.advance(),{type:x.PLUS_ASSIGN,value:"+=",line:e,column:r}):{type:x.PLUS,value:"+",line:e,column:r};case"-":return s==="-"?(this.advance(),{type:x.DECREMENT,value:"--",line:e,column:r}):s==="="?(this.advance(),{type:x.MINUS_ASSIGN,value:"-=",line:e,column:r}):{type:x.MINUS,value:"-",line:e,column:r};case"*":return s==="*"?(this.advance(),{type:x.CARET,value:"**",line:e,column:r}):s==="="?(this.advance(),{type:x.STAR_ASSIGN,value:"*=",line:e,column:r}):{type:x.STAR,value:"*",line:e,column:r};case"/":return s==="="?(this.advance(),{type:x.SLASH_ASSIGN,value:"/=",line:e,column:r}):{type:x.SLASH,value:"/",line:e,column:r};case"%":return s==="="?(this.advance(),{type:x.PERCENT_ASSIGN,value:"%=",line:e,column:r}):{type:x.PERCENT,value:"%",line:e,column:r};case"^":return s==="="?(this.advance(),{type:x.CARET_ASSIGN,value:"^=",line:e,column:r}):{type:x.CARET,value:"^",line:e,column:r};case"=":return s==="="?(this.advance(),{type:x.EQ,value:"==",line:e,column:r}):{type:x.ASSIGN,value:"=",line:e,column:r};case"!":return s==="="?(this.advance(),{type:x.NE,value:"!=",line:e,column:r}):s==="~"?(this.advance(),{type:x.NOT_MATCH,value:"!~",line:e,column:r}):{type:x.NOT,value:"!",line:e,column:r};case"<":return s==="="?(this.advance(),{type:x.LE,value:"<=",line:e,column:r}):{type:x.LT,value:"<",line:e,column:r};case">":return s==="="?(this.advance(),{type:x.GE,value:">=",line:e,column:r}):s===">"?(this.advance(),{type:x.APPEND,value:">>",line:e,column:r}):{type:x.GT,value:">",line:e,column:r};case"&":return s==="&"?(this.advance(),{type:x.AND,value:"&&",line:e,column:r}):{type:x.IDENT,value:"&",line:e,column:r};case"|":return s==="|"?(this.advance(),{type:x.OR,value:"||",line:e,column:r}):{type:x.PIPE,value:"|",line:e,column:r};case"~":return{type:x.MATCH,value:"~",line:e,column:r};case"?":return{type:x.QUESTION,value:"?",line:e,column:r};case":":return{type:x.COLON,value:":",line:e,column:r};case",":return{type:x.COMMA,value:",",line:e,column:r};case";":return{type:x.SEMICOLON,value:";",line:e,column:r};case"(":return{type:x.LPAREN,value:"(",line:e,column:r};case")":return{type:x.RPAREN,value:")",line:e,column:r};case"{":return{type:x.LBRACE,value:"{",line:e,column:r};case"}":return{type:x.RBRACE,value:"}",line:e,column:r};case"[":return{type:x.LBRACKET,value:"[",line:e,column:r};case"]":return{type:x.RBRACKET,value:"]",line:e,column:r};case"$":return{type:x.DOLLAR,value:"$",line:e,column:r};default:return{type:x.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 $r,Uo=A(()=>{"use strict";Wo();$r=class{tokens=[];pos=0;parse(e){let r=new Rr(e);return this.tokens=r.tokenize(),this.pos=0,this.parseProgram()}current(){return this.tokens[this.pos]||{type:x.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(x.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(x.NEWLINE)||this.check(x.SEMICOLON);)this.advance()}parseProgram(){let e=[],r=[];for(this.skipNewlines();!this.check(x.EOF)&&(this.skipNewlines(),!this.check(x.EOF));)this.check(x.FUNCTION)?e.push(this.parseFunction()):r.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:r}}parseFunction(){this.expect(x.FUNCTION);let e=this.expect(x.IDENT).value;this.expect(x.LPAREN);let r=[];if(!this.check(x.RPAREN))for(r.push(this.expect(x.IDENT).value);this.check(x.COMMA);)this.advance(),r.push(this.expect(x.IDENT).value);this.expect(x.RPAREN),this.skipNewlines();let n=this.parseBlock();return{name:e,params:r,body:n}}parseRule(){let e;if(this.check(x.BEGIN))this.advance(),e={type:"begin"};else if(this.check(x.END))this.advance(),e={type:"end"};else if(this.check(x.LBRACE))e=void 0;else if(this.check(x.REGEX)){let n=this.advance();if(this.check(x.AND)||this.check(x.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(x.COMMA)){this.advance();let i;this.check(x.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(x.COMMA)){this.advance();let i;this.check(x.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(x.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(x.LBRACE),this.skipNewlines();let e=[];for(;!this.check(x.RBRACE)&&!this.check(x.EOF);)e.push(this.parseStatement()),this.skipTerminators();return this.expect(x.RBRACE),{type:"block",statements:e}}parseStatement(){if(this.check(x.LBRACE))return this.parseBlock();if(this.check(x.IF))return this.parseIf();if(this.check(x.WHILE))return this.parseWhile();if(this.check(x.DO))return this.parseDoWhile();if(this.check(x.FOR))return this.parseFor();if(this.check(x.BREAK))return this.advance(),{type:"break"};if(this.check(x.CONTINUE))return this.advance(),{type:"continue"};if(this.check(x.NEXT))return this.advance(),{type:"next"};if(this.check(x.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(x.EXIT)){this.advance();let r;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(r=this.parseExpression()),{type:"exit",code:r}}if(this.check(x.RETURN)){this.advance();let r;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(r=this.parseExpression()),{type:"return",value:r}}if(this.check(x.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(x.PRINT)?this.parsePrint():this.check(x.PRINTF)?this.parsePrintf():{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(x.IF),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let r=this.parseStatement();this.skipTerminators();let n;return this.check(x.ELSE)&&(this.advance(),this.skipNewlines(),n=this.parseStatement()),{type:"if",condition:e,consequent:r,alternate:n}}parseWhile(){this.expect(x.WHILE),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let r=this.parseStatement();return{type:"while",condition:e,body:r}}parseDoWhile(){this.expect(x.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(x.WHILE),this.expect(x.LPAREN);let r=this.parseExpression();return this.expect(x.RPAREN),{type:"do_while",body:e,condition:r}}parseFor(){if(this.expect(x.FOR),this.expect(x.LPAREN),this.check(x.IDENT)){let i=this.advance();if(this.check(x.IN)){this.advance();let o=this.expect(x.IDENT).value;this.expect(x.RPAREN),this.skipNewlines();let a=this.parseStatement();return{type:"for_in",variable:i.value,array:o,body:a}}this.pos--}let e;this.check(x.SEMICOLON)||(e=this.parseExpression()),this.expect(x.SEMICOLON);let r;this.check(x.SEMICOLON)||(r=this.parseExpression()),this.expect(x.SEMICOLON);let n;this.check(x.RPAREN)||(n=this.parseExpression()),this.expect(x.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:r,update:n,body:s}}parsePrint(){this.expect(x.PRINT);let e=[];if(this.check(x.NEWLINE)||this.check(x.SEMICOLON)||this.check(x.RBRACE)||this.check(x.PIPE)||this.check(x.GT)||this.check(x.APPEND))e.push({type:"field",index:{type:"number",value:0}});else for(e.push(this.parsePrintArg());this.check(x.COMMA);)this.advance(),e.push(this.parsePrintArg());let r;return this.check(x.GT)?(this.advance(),r={redirect:">",file:this.parsePrimary()}):this.check(x.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===x.LPAREN&&e++,n.type===x.RPAREN&&e--,n.type===x.QUESTION&&e===0)return!0;if(n.type===x.NEWLINE||n.type===x.SEMICOLON||n.type===x.RBRACE||n.type===x.COMMA||n.type===x.PIPE)return!1;r++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(x.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(x.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(x.IN)){this.advance();let r=String(this.expect(x.IDENT).value);return{type:"in",key:e,array:r}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let r=this.advance().type===x.MATCH?"~":"!~",n=this.parsePrintComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GE,x.EQ,x.NE);){let r=this.advance(),n=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[r.value],left:e,right:n}}return e}parsePrintf(){this.expect(x.PRINTF);let e=this.parsePrintArg(),r=[];for(;this.check(x.COMMA);)this.advance(),r.push(this.parsePrintArg());let n;return this.check(x.GT)?(this.advance(),n={redirect:">",file:this.parsePrimary()}):this.check(x.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(x.ASSIGN,x.PLUS_ASSIGN,x.MINUS_ASSIGN,x.STAR_ASSIGN,x.SLASH_ASSIGN,x.PERCENT_ASSIGN,x.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(x.QUESTION)){this.advance();let r=this.parseExpression();this.expect(x.COLON);let n=this.parseExpression();e={type:"ternary",condition:e,consequent:r,alternate:n}}return e}parseOr(){let e=this.parseAnd();for(;this.check(x.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(x.OR);){this.advance();let r=this.parseAnd();e={type:"binary",operator:"||",left:e,right:r}}return e}parseLogicalAndRest(e){for(;this.check(x.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(x.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(x.IN)){this.advance();let r=this.expect(x.IDENT).value;return{type:"in",key:e,array:r}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let r=this.advance().type===x.MATCH?"~":"!~",n=this.parseComparison();e={type:"binary",operator:r,left:e,right:n}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.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(x.NUMBER,x.STRING,x.IDENT,x.DOLLAR,x.LPAREN,x.NOT,x.MINUS,x.PLUS,x.INCREMENT,x.DECREMENT)}isComparisonOrHigherOp(){return this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.NE,x.AND,x.OR,x.QUESTION,x.MATCH,x.NOT_MATCH,x.ASSIGN,x.PLUS_ASSIGN,x.MINUS_ASSIGN,x.STAR_ASSIGN,x.SLASH_ASSIGN,x.PERCENT_ASSIGN,x.CARET_ASSIGN,x.COMMA,x.SEMICOLON,x.NEWLINE,x.RBRACE,x.RPAREN,x.RBRACKET,x.COLON,x.PIPE,x.APPEND,x.IN)}parseAddSub(){let e=this.parseMulDiv();for(;this.match(x.PLUS,x.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(x.STAR,x.SLASH,x.PERCENT);){let r=this.advance(),n=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[r.value],left:e,right:n}}return e}parseUnary(){if(this.check(x.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(x.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(x.NOT,x.MINUS,x.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(x.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(x.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(x.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(x.NUMBER))return{type:"number",value:this.advance().value};if(this.check(x.STRING))return{type:"string",value:this.advance().value};if(this.check(x.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(x.DOLLAR))return this.advance(),{type:"field",index:this.parsePrimary()};if(this.check(x.LPAREN)){this.advance();let e=this.parseExpression();if(this.check(x.COMMA)){let r=[e];for(;this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(x.RPAREN),{type:"tuple",elements:r}}return this.expect(x.RPAREN),e}if(this.check(x.GETLINE)){this.advance();let e,r;return this.check(x.IDENT)&&(e=this.advance().value),this.check(x.LT)&&(this.advance(),r=this.parsePrimary()),{type:"getline",variable:e,file:r}}if(this.check(x.IDENT)){let e=this.advance().value;if(this.check(x.LPAREN)){this.advance();let r=[];if(!this.check(x.RPAREN))for(r.push(this.parseExpression());this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());return this.expect(x.RPAREN),{type:"call",name:e,args:r}}if(this.check(x.LBRACKET)){this.advance();let r=[this.parseExpression()];for(;this.check(x.COMMA);)this.advance(),r.push(this.parseExpression());this.expect(x.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 Go={};$(Go,{awkCommand2:()=>Ed});function Ho(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
243
+ `).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function jo(t){if(t===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(t))try{return new RegExp(t)}catch{return new RegExp(zo(t))}return new RegExp(zo(t))}function zo(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var wd,Ed,qo=A(()=>{"use strict";J();_();Bo();Uo();wd={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"]},Ed={name:"awk",async execute(t,e){if(I(t))return N(wd);let r=/\s+/,n=" ",s={},i=0;for(let d=0;d<t.length;d++){let h=t[d];if(h==="-F"&&d+1<t.length)n=Ho(t[++d]),r=jo(n),i=d+1;else if(h.startsWith("-F"))n=Ho(h.slice(2)),r=jo(n),i=d+1;else if(h==="-v"&&d+1<t.length){let g=t[++d],y=g.indexOf("=");if(y>0){let w=g.slice(0,y),E=g.slice(y+1);s[w]=E}i=d+1}else{if(h.startsWith("--"))return L("awk",h);if(h.startsWith("-")&&h.length>1){let g=h[1];if(g!=="F"&&g!=="v")return L("awk",`-${g}`);i=d+1}else if(!h.startsWith("-")){i=d;break}}}if(i>=t.length)return{stdout:"",stderr:`awk: missing program
244
+ `,exitCode:1};let o=t[i],a=t.slice(i+1),c=new $r,l;try{l=c.parse(o)}catch(d){return{stdout:"",stderr:`awk: ${d instanceof Error?d.message:String(d)}
245
+ `,exitCode:1}}let u={readFile:e.fs.readFile.bind(e.fs),writeFile:e.fs.writeFile.bind(e.fs),appendFile:async(d,h)=>{try{let g=await e.fs.readFile(d);await e.fs.writeFile(d,g+h)}catch{await e.fs.writeFile(d,h)}},resolvePath:e.fs.resolvePath.bind(e.fs)},f=_n({fieldSep:r,maxIterations:e.limits?.maxAwkIterations,fs:u,cwd:e.cwd});f.FS=n,f.vars={...s},f.ARGC=a.length+1,f.ARGV={0:"awk"};for(let d=0;d<a.length;d++)f.ARGV[String(d+1)]=a[d];let p=new Qt(f);p.execute(l);try{if(await p.executeBegin(),f.shouldExit)return{stdout:p.getOutput(),stderr:"",exitCode:p.getExitCode()};let d=[];if(a.length>0)for(let h of a)try{let g=e.fs.resolvePath(e.cwd,h),w=(await e.fs.readFile(g)).split(`
246
+ `);w.length>0&&w[w.length-1]===""&&w.pop(),d.push({filename:h,lines:w})}catch{return{stdout:"",stderr:`awk: ${h}: No such file or directory
247
247
  `,exitCode:1}}else{let h=e.stdin.split(`
248
- `);h.length>0&&h[h.length-1]===""&&h.pop(),p.push({filename:"",lines:h})}for(let h of p){for(f.FILENAME=h.filename,f.FNR=0,f.lines=h.lines,f.lineIndex=-1,f.shouldNextFile=!1;f.lineIndex<h.lines.length-1&&(f.lineIndex++,await d.executeLine(h.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(p){let h=p instanceof Error?p.message:String(p),w=p instanceof H?H.EXIT_CODE:2;return{stdout:d.getOutput(),stderr:`awk: ${h}
249
- `,exitCode:w}}}}});function Bo(t){let e=t.trim(),r=e.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!r){let o=parseFloat(e);return Number.isNaN(o)?0:o}let n=parseFloat(r[1]),s=(r[2]||"").toLowerCase(),i=op[s]||1;return n*i}function Wo(t){let e=t.trim().toLowerCase().slice(0,3);return ap[e]||0}function lp(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 o=r[i]||"",a=n[i]||"",l=/^\d+$/.test(o)?parseInt(o,10):null,c=/^\d+$/.test(a)?parseInt(a,10):null;if(l!==null&&c!==null){if(l!==c)return l-c}else if(o!==a)return o.localeCompare(a)}return 0}function Uo(t){return t.replace(/[^a-zA-Z0-9\s]/g,"")}function zn(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 o=Math.min(e.endField-1,s.length-1),a="";for(let l=i;l<=o&&l<s.length;l++){let c=s[l]||"";if(l===i&&e.startChar!==void 0&&(c=c.slice(e.startChar-1)),l===o&&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&&(a+=r||" "),a+=c}return e.ignoreLeading&&(a=a.trimStart()),a}function Ho(t,e,r){let n=t,s=e;if(r.dictionaryOrder&&(n=Uo(n),s=Uo(s)),r.ignoreCase&&(n=n.toLowerCase(),s=s.toLowerCase()),r.monthSort){let i=Wo(n),o=Wo(s);return i-o}if(r.humanNumeric){let i=Bo(n),o=Bo(s);return i-o}if(r.versionSort)return lp(n,s);if(r.numeric){let i=parseFloat(n)||0,o=parseFloat(s)||0;return i-o}return n.localeCompare(s)}function zo(t){let{keys:e,fieldDelimiter:r,numeric:n,ignoreCase:s,reverse:i,humanNumeric:o,versionSort:a,dictionaryOrder:l,monthSort:c,ignoreLeadingBlanks:u,stable:f}=t;return(d,p)=>{let h=d,w=p;if(u&&(h=h.trimStart(),w=w.trimStart()),e.length===0){let y=Ho(h,w,{numeric:n,ignoreCase:s,humanNumeric:o,versionSort:a,dictionaryOrder:l,monthSort:c});if(y!==0)return i?-y:y;if(!f){let E=d.localeCompare(p);return i?-E:E}return 0}for(let g of e){let y=zn(h,g,r),E=zn(w,g,r);g.ignoreLeading&&(y=y.trimStart(),E=E.trimStart());let b={numeric:g.numeric??n,ignoreCase:g.ignoreCase??s,humanNumeric:g.humanNumeric??o,versionSort:g.versionSort??a,dictionaryOrder:g.dictionaryOrder??l,monthSort:g.monthSort??c},S=g.reverse??i,A=Ho(y,E,b);if(A!==0)return S?-A:A}if(!f){let g=d.localeCompare(p);return i?-g:g}return 0}}function jo(t,e){if(e.keys.length===0){if(e.ignoreCase){let s=new Set;return t.filter(i=>{let o=i.toLowerCase();return s.has(o)?!1:(s.add(o),!0)})}return[...new Set(t)]}let r=e.keys[0],n=new Set;return t.filter(s=>{let i=zn(s,r,e.fieldDelimiter);return(r.ignoreCase??e.ignoreCase)&&(i=i.toLowerCase()),n.has(i)?!1:(n.add(i),!0)})}var op,ap,Go=C(()=>{"use strict";op={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},ap={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 $r(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 o=i[0].split("."),a=parseInt(o[0],10);if(Number.isNaN(a)||a<1)return null;if(e.startField=a,o.length>1&&o[1]){let l=parseInt(o[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 qo=C(()=>{"use strict"});var Vo={};$(Vo,{sortCommand:()=>up});var cp,up,Zo=C(()=>{"use strict";bt();M();Go();qo();cp={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]]
248
+ `);h.length>0&&h[h.length-1]===""&&h.pop(),d.push({filename:"",lines:h})}for(let h of d){for(f.FILENAME=h.filename,f.FNR=0,f.lines=h.lines,f.lineIndex=-1,f.shouldNextFile=!1;f.lineIndex<h.lines.length-1&&(f.lineIndex++,await p.executeLine(h.lines[f.lineIndex]),!(f.shouldExit||f.shouldNextFile)););if(f.shouldExit)break}return f.shouldExit||await p.executeEnd(),{stdout:p.getOutput(),stderr:"",exitCode:p.getExitCode()}}catch(d){let h=d instanceof Error?d.message:String(d),g=d instanceof W?W.EXIT_CODE:2;return{stdout:p.getOutput(),stderr:`awk: ${h}
249
+ `,exitCode:g}}}}});function Vo(t){let e=t.trim(),r=e.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!r){let o=parseFloat(e);return Number.isNaN(o)?0:o}let n=parseFloat(r[1]),s=(r[2]||"").toLowerCase(),i=bd[s]||1;return n*i}function Ko(t){let e=t.trim().toLowerCase().slice(0,3);return Sd[e]||0}function Ad(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 o=r[i]||"",a=n[i]||"",c=/^\d+$/.test(o)?parseInt(o,10):null,l=/^\d+$/.test(a)?parseInt(a,10):null;if(c!==null&&l!==null){if(c!==l)return c-l}else if(o!==a)return o.localeCompare(a)}return 0}function Zo(t){return t.replace(/[^a-zA-Z0-9\s]/g,"")}function Vn(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 c=s[i]||"";return e.startChar!==void 0&&(c=c.slice(e.startChar-1)),e.ignoreLeading&&(c=c.trimStart()),c}let o=Math.min(e.endField-1,s.length-1),a="";for(let c=i;c<=o&&c<s.length;c++){let l=s[c]||"";if(c===i&&e.startChar!==void 0&&(l=l.slice(e.startChar-1)),c===o&&e.endChar!==void 0){let u=c===i&&e.startChar!==void 0?e.endChar-e.startChar+1:e.endChar;l=l.slice(0,u)}c>i&&(a+=r||" "),a+=l}return e.ignoreLeading&&(a=a.trimStart()),a}function Qo(t,e,r){let n=t,s=e;if(r.dictionaryOrder&&(n=Zo(n),s=Zo(s)),r.ignoreCase&&(n=n.toLowerCase(),s=s.toLowerCase()),r.monthSort){let i=Ko(n),o=Ko(s);return i-o}if(r.humanNumeric){let i=Vo(n),o=Vo(s);return i-o}if(r.versionSort)return Ad(n,s);if(r.numeric){let i=parseFloat(n)||0,o=parseFloat(s)||0;return i-o}return n.localeCompare(s)}function Xo(t){let{keys:e,fieldDelimiter:r,numeric:n,ignoreCase:s,reverse:i,humanNumeric:o,versionSort:a,dictionaryOrder:c,monthSort:l,ignoreLeadingBlanks:u,stable:f}=t;return(p,d)=>{let h=p,g=d;if(u&&(h=h.trimStart(),g=g.trimStart()),e.length===0){let w=Qo(h,g,{numeric:n,ignoreCase:s,humanNumeric:o,versionSort:a,dictionaryOrder:c,monthSort:l});if(w!==0)return i?-w:w;if(!f){let E=p.localeCompare(d);return i?-E:E}return 0}for(let y of e){let w=Vn(h,y,r),E=Vn(g,y,r);y.ignoreLeading&&(w=w.trimStart(),E=E.trimStart());let b={numeric:y.numeric??n,ignoreCase:y.ignoreCase??s,humanNumeric:y.humanNumeric??o,versionSort:y.versionSort??a,dictionaryOrder:y.dictionaryOrder??c,monthSort:y.monthSort??l},S=y.reverse??i,C=Qo(w,E,b);if(C!==0)return S?-C:C}if(!f){let y=p.localeCompare(d);return i?-y:y}return 0}}function Jo(t,e){if(e.keys.length===0){if(e.ignoreCase){let s=new Set;return t.filter(i=>{let o=i.toLowerCase();return s.has(o)?!1:(s.add(o),!0)})}return[...new Set(t)]}let r=e.keys[0],n=new Set;return t.filter(s=>{let i=Vn(s,r,e.fieldDelimiter);return(r.ignoreCase??e.ignoreCase)&&(i=i.toLowerCase()),n.has(i)?!1:(n.add(i),!0)})}var bd,Sd,Yo=A(()=>{"use strict";bd={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},Sd={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 Or(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 o=i[0].split("."),a=parseInt(o[0],10);if(Number.isNaN(a)||a<1)return null;if(e.startField=a,o.length>1&&o[1]){let c=parseInt(o[1],10);!Number.isNaN(c)&&c>=1&&(e.startChar=c)}if(i.length>1&&i[1]){let c=i[1],l=c.match(/([bdfhMnrV]+)$/);if(l){let f=l[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),c=c.slice(0,-f.length)}let u=c.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 p=parseInt(u[1],10);!Number.isNaN(p)&&p>=1&&(e.endChar=p)}}}return e}var ea=A(()=>{"use strict"});var ta={};$(ta,{sortCommand:()=>kd});var Cd,kd,ra=A(()=>{"use strict";Ct();_();Yo();ea();Cd={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
252
  OPTS can be: b d f h M n r V (per-key modifiers)
@@ -256,36 +256,36 @@ Examples:
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`},up={name:"sort",async execute(t,e){if(v(t))return k(cp);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=$r(f);d&&r.keys.push(d)}}else if(u.startsWith("-k")){let f=$r(u.slice(2));f&&r.keys.push(f)}else if(u.startsWith("--key=")){let f=$r(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 Et(e,n,{cmdName:"sort"});if(!s.ok)return s.error;let o=s.content.split(`
260
- `);o.length>0&&o[o.length-1]===""&&o.pop();let a=zo(r);if(r.checkOnly){let c=n.length>0?n[0]:"-";for(let u=1;u<o.length;u++)if(a(o[u-1],o[u])>0)return{stdout:"",stderr:`sort: ${c}:${u+1}: disorder: ${o[u]}
261
- `,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}o.sort(a),r.unique&&(o=jo(o,r));let l=o.length>0?`${o.join(`
259
+ -k2 -k1 sort by field 2, then by field 1`},kd={name:"sort",async execute(t,e){if(I(t))return N(Cd);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 l=0;l<t.length;l++){let u=t[l];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[++l]||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[++l]||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[++l];if(f){let p=Or(f);p&&r.keys.push(p)}}else if(u.startsWith("-k")){let f=Or(u.slice(2));f&&r.keys.push(f)}else if(u.startsWith("--key=")){let f=Or(u.slice(6));f&&r.keys.push(f)}else{if(u.startsWith("--"))return L("sort",u);if(u.startsWith("-")&&!u.startsWith("--")){let f=!1;for(let p of u.slice(1))if(p==="r")r.reverse=!0;else if(p==="n")r.numeric=!0;else if(p==="u")r.unique=!0;else if(p==="f")r.ignoreCase=!0;else if(p==="h")r.humanNumeric=!0;else if(p==="V")r.versionSort=!0;else if(p==="d")r.dictionaryOrder=!0;else if(p==="M")r.monthSort=!0;else if(p==="b")r.ignoreLeadingBlanks=!0;else if(p==="s")r.stable=!0;else if(p==="c")r.checkOnly=!0;else{f=!0;break}if(f)return L("sort",u)}else n.push(u)}}let s=await At(e,n,{cmdName:"sort"});if(!s.ok)return s.error;let o=s.content.split(`
260
+ `);o.length>0&&o[o.length-1]===""&&o.pop();let a=Xo(r);if(r.checkOnly){let l=n.length>0?n[0]:"-";for(let u=1;u<o.length;u++)if(a(o[u-1],o[u])>0)return{stdout:"",stderr:`sort: ${l}:${u+1}: disorder: ${o[u]}
261
+ `,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}o.sort(a),r.unique&&(o=Jo(o,r));let c=o.length>0?`${o.join(`
262
262
  `)}
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 Qo={};$(Qo,{uniqCommand:()=>pp});var fp,dp,pp,Xo=C(()=>{"use strict";ue();bt();M();fp={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"]},dp={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"}},pp={name:"uniq",async execute(t,e){if(v(t))return k(fp);let r=j("uniq",t,dp);if(!r.ok)return r.error;let{count:n,duplicatesOnly:s,uniqueOnly:i,ignoreCase:o}=r.result.flags,a=r.result.positional,l=await Et(e,a,{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],p=1,h=(y,E)=>o?y.toLowerCase()===E.toLowerCase():y===E;for(let y=1;y<u.length;y++)h(u[y],d)?p++:(f.push({line:d,count:p}),d=u[y],p=1);f.push({line:d,count:p});let w=f;s?w=f.filter(y=>y.count>1):i&&(w=f.filter(y=>y.count===1));let g="";for(let{line:y,count:E}of w)n?g+=`${String(E).padStart(4)} ${y}
265
- `:g+=`${y}
266
- `;return{stdout:g,stderr:"",exitCode:0}}}});var Ko={};$(Ko,{commCommand:()=>mp});var hp,mp,Jo=C(()=>{"use strict";M();hp={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"]},mp={name:"comm",async execute(t,e){if(v(t))return k(hp);let r=!1,n=!1,s=!1,i=[];for(let g of t)if(g==="-1")r=!0;else if(g==="-2")n=!0;else if(g==="-3")s=!0;else if(g==="-12"||g==="-21")r=!0,n=!0;else if(g==="-13"||g==="-31")r=!0,s=!0;else if(g==="-23"||g==="-32")n=!0,s=!0;else if(g==="-123"||g==="-132"||g==="-213"||g==="-231"||g==="-312"||g==="-321")r=!0,n=!0,s=!0;else{if(g.startsWith("-")&&g!=="-")return T("comm",g);i.push(g)}if(i.length!==2)return{stdout:"",stderr:`comm: missing operand
263
+ `:"";if(r.outputFile){let l=e.fs.resolvePath(e.cwd,r.outputFile);return await e.fs.writeFile(l,c),{stdout:"",stderr:"",exitCode:0}}return{stdout:c,stderr:"",exitCode:0}}}});var na={};$(na,{uniqCommand:()=>vd});var Nd,Id,vd,sa=A(()=>{"use strict";fe();Ct();_();Nd={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"]},Id={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"}},vd={name:"uniq",async execute(t,e){if(I(t))return N(Nd);let r=G("uniq",t,Id);if(!r.ok)return r.error;let{count:n,duplicatesOnly:s,uniqueOnly:i,ignoreCase:o}=r.result.flags,a=r.result.positional,c=await At(e,a,{cmdName:"uniq"});if(!c.ok)return c.error;let u=c.content.split(`
264
+ `);if(u.length>0&&u[u.length-1]===""&&u.pop(),u.length===0)return{stdout:"",stderr:"",exitCode:0};let f=[],p=u[0],d=1,h=(w,E)=>o?w.toLowerCase()===E.toLowerCase():w===E;for(let w=1;w<u.length;w++)h(u[w],p)?d++:(f.push({line:p,count:d}),p=u[w],d=1);f.push({line:p,count:d});let g=f;s?g=f.filter(w=>w.count>1):i&&(g=f.filter(w=>w.count===1));let y="";for(let{line:w,count:E}of g)n?y+=`${String(E).padStart(4)} ${w}
265
+ `:y+=`${w}
266
+ `;return{stdout:y,stderr:"",exitCode:0}}}});var ia={};$(ia,{commCommand:()=>$d});var Rd,$d,oa=A(()=>{"use strict";_();Rd={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"]},$d={name:"comm",async execute(t,e){if(I(t))return N(Rd);let r=!1,n=!1,s=!1,i=[];for(let y of t)if(y==="-1")r=!0;else if(y==="-2")n=!0;else if(y==="-3")s=!0;else if(y==="-12"||y==="-21")r=!0,n=!0;else if(y==="-13"||y==="-31")r=!0,s=!0;else if(y==="-23"||y==="-32")n=!0,s=!0;else if(y==="-123"||y==="-132"||y==="-213"||y==="-231"||y==="-312"||y==="-321")r=!0,n=!0,s=!0;else{if(y.startsWith("-")&&y!=="-")return L("comm",y);i.push(y)}if(i.length!==2)return{stdout:"",stderr:`comm: missing operand
267
267
  Try 'comm --help' for more information.
268
- `,exitCode:1};let o=async g=>{if(g==="-")return e.stdin;try{let y=e.fs.resolvePath(e.cwd,g);return await e.fs.readFile(y)}catch{return null}},a=await o(i[0]);if(a===null)return{stdout:"",stderr:`comm: ${i[0]}: No such file or directory
269
- `,exitCode:1};let l=await o(i[1]);if(l===null)return{stdout:"",stderr:`comm: ${i[1]}: No such file or directory
270
- `,exitCode:1};let c=a.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,p="",h=r?"":" ",w=(r?"":" ")+(n?"":" ");for(;f<c.length||d<u.length;)f>=c.length?(n||(p+=`${h}${u[d]}
273
- `),d++):d>=u.length?(r||(p+=`${c[f]}
274
- `),f++):c[f]<u[d]?(r||(p+=`${c[f]}
275
- `),f++):c[f]>u[d]?(n||(p+=`${h}${u[d]}
276
- `),d++):(s||(p+=`${w}${c[f]}
277
- `),f++,d++);return{stdout:p,stderr:"",exitCode:0}}}});var Yo={};$(Yo,{cutCommand:()=>wp});function xp(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 yp(t,e){let r=[];for(let n of e){let s=n.start-1,i=n.end===null?t.length:n.end;for(let o=s;o<i&&o<t.length;o++)o>=0&&!r.includes(t[o])&&r.push(t[o])}return r}var gp,wp,ea=C(()=>{"use strict";bt();M();gp={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"]};wp={name:"cut",async execute(t,e){if(v(t))return k(gp);let r=" ",n=null,s=null,i=!1,o=[];for(let d=0;d<t.length;d++){let p=t[d];if(p==="-d")r=t[++d]||" ";else if(p.startsWith("-d"))r=p.slice(2);else if(p==="-f")n=t[++d];else if(p.startsWith("-f"))n=p.slice(2);else if(p==="-c")s=t[++d];else if(p.startsWith("-c"))s=p.slice(2);else if(p==="-s"||p==="--only-delimited")i=!0;else{if(p.startsWith("--"))return T("cut",p);if(p.startsWith("-")){let h=!1;for(let w of p.slice(1))if(w==="s")i=!0;else if(!"dfc".includes(w)){h=!0;break}if(h)return T("cut",p)}else o.push(p)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
278
- `,exitCode:1};let a=await Et(e,o,{cmdName:"cut"});if(!a.ok)return a.error;let c=a.content.split(`
279
- `);c.length>0&&c[c.length-1]===""&&c.pop();let u=xp(n||s||"1"),f="";for(let d of c)if(s){let p=d.split(""),h=[];for(let w of u){let g=w.start-1,y=w.end===null?p.length:w.end;for(let E=g;E<y&&E<p.length;E++)E>=0&&h.push(p[E])}f+=`${h.join("")}
280
- `}else{if(i&&!d.includes(r))continue;let p=d.split(r),h=yp(p,u);f+=`${h.join(r)}
281
- `}return{stdout:f,stderr:"",exitCode:0}}}});var ra={};$(ra,{pasteCommand:()=>Sp});function ta(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 Ep,bp,Sp,na=C(()=>{"use strict";ue();M();Ep={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"]},bp={delimiter:{short:"d",long:"delimiters",type:"string",default:" "},serial:{short:"s",long:"serial",type:"boolean"}},Sp={name:"paste",async execute(t,e){if(v(t))return k(Ep);let r=j("paste",t,bp);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 ...
268
+ `,exitCode:1};let o=async y=>{if(y==="-")return e.stdin;try{let w=e.fs.resolvePath(e.cwd,y);return await e.fs.readFile(w)}catch{return null}},a=await o(i[0]);if(a===null)return{stdout:"",stderr:`comm: ${i[0]}: No such file or directory
269
+ `,exitCode:1};let c=await o(i[1]);if(c===null)return{stdout:"",stderr:`comm: ${i[1]}: No such file or directory
270
+ `,exitCode:1};let l=a.split(`
271
+ `),u=c.split(`
272
+ `);l.length>0&&l[l.length-1]===""&&l.pop(),u.length>0&&u[u.length-1]===""&&u.pop();let f=0,p=0,d="",h=r?"":" ",g=(r?"":" ")+(n?"":" ");for(;f<l.length||p<u.length;)f>=l.length?(n||(d+=`${h}${u[p]}
273
+ `),p++):p>=u.length?(r||(d+=`${l[f]}
274
+ `),f++):l[f]<u[p]?(r||(d+=`${l[f]}
275
+ `),f++):l[f]>u[p]?(n||(d+=`${h}${u[p]}
276
+ `),p++):(s||(d+=`${g}${l[f]}
277
+ `),f++,p++);return{stdout:d,stderr:"",exitCode:0}}}});var aa={};$(aa,{cutCommand:()=>Fd});function Pd(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 Td(t,e){let r=[];for(let n of e){let s=n.start-1,i=n.end===null?t.length:n.end;for(let o=s;o<i&&o<t.length;o++)o>=0&&!r.includes(t[o])&&r.push(t[o])}return r}var Od,Fd,ca=A(()=>{"use strict";Ct();_();Od={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"]};Fd={name:"cut",async execute(t,e){if(I(t))return N(Od);let r=" ",n=null,s=null,i=!1,o=[];for(let p=0;p<t.length;p++){let d=t[p];if(d==="-d")r=t[++p]||" ";else if(d.startsWith("-d"))r=d.slice(2);else if(d==="-f")n=t[++p];else if(d.startsWith("-f"))n=d.slice(2);else if(d==="-c")s=t[++p];else if(d.startsWith("-c"))s=d.slice(2);else if(d==="-s"||d==="--only-delimited")i=!0;else{if(d.startsWith("--"))return L("cut",d);if(d.startsWith("-")){let h=!1;for(let g of d.slice(1))if(g==="s")i=!0;else if(!"dfc".includes(g)){h=!0;break}if(h)return L("cut",d)}else o.push(d)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
278
+ `,exitCode:1};let a=await At(e,o,{cmdName:"cut"});if(!a.ok)return a.error;let l=a.content.split(`
279
+ `);l.length>0&&l[l.length-1]===""&&l.pop();let u=Pd(n||s||"1"),f="";for(let p of l)if(s){let d=p.split(""),h=[];for(let g of u){let y=g.start-1,w=g.end===null?d.length:g.end;for(let E=y;E<w&&E<d.length;E++)E>=0&&h.push(d[E])}f+=`${h.join("")}
280
+ `}else{if(i&&!p.includes(r))continue;let d=p.split(r),h=Td(d,u);f+=`${h.join(r)}
281
+ `}return{stdout:f,stderr:"",exitCode:0}}}});var ua={};$(ua,{pasteCommand:()=>Md});function la(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 Dd,Ld,Md,fa=A(()=>{"use strict";fe();_();Dd={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"]},Ld={delimiter:{short:"d",long:"delimiters",type:"string",default:" "},serial:{short:"s",long:"serial",type:"boolean"}},Md={name:"paste",async execute(t,e){if(I(t))return N(Dd);let r=G("paste",t,Ld);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 ...
282
282
  `,exitCode:1};let o=e.stdin?e.stdin.split(`
283
- `):[""];o.length>0&&o[o.length-1]===""&&o.pop();let a=i.filter(f=>f==="-").length,l=[],c=0;for(let f of i)if(f==="-"){let d=[];for(let p=c;p<o.length;p+=a)d.push(o[p]);l.push(d),c++}else{let d=e.fs.resolvePath(e.cwd,f);try{let h=(await e.fs.readFile(d)).split(`
284
- `);h.length>0&&h[h.length-1]===""&&h.pop(),l.push(h)}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+=`${ta(f,n)}
286
- `);else{let f=Math.max(...l.map(d=>d?.length??0));for(let d=0;d<f;d++){let p=[];for(let h of l)p.push(h?.[d]??"");u+=`${ta(p,n)}
287
- `}}return{stdout:u,stderr:"",exitCode:0}}}});var ia={};$(ia,{trCommand:()=>vp});function sa(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(Ap))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 Cp,Ap,kp,vp,oa=C(()=>{"use strict";ue();M();Cp={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:
283
+ `):[""];o.length>0&&o[o.length-1]===""&&o.pop();let a=i.filter(f=>f==="-").length,c=[],l=0;for(let f of i)if(f==="-"){let p=[];for(let d=l;d<o.length;d+=a)p.push(o[d]);c.push(p),l++}else{let p=e.fs.resolvePath(e.cwd,f);try{let h=(await e.fs.readFile(p)).split(`
284
+ `);h.length>0&&h[h.length-1]===""&&h.pop(),c.push(h)}catch{return{stdout:"",stderr:`paste: ${f}: No such file or directory
285
+ `,exitCode:1}}}let u="";if(s)for(let f of c)f&&(u+=`${la(f,n)}
286
+ `);else{let f=Math.max(...c.map(p=>p?.length??0));for(let p=0;p<f;p++){let d=[];for(let h of c)d.push(h?.[p]??"");u+=`${la(d,n)}
287
+ `}}return{stdout:u,stderr:"",exitCode:0}}}});var da={};$(da,{trCommand:()=>Ud});function pa(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(Bd))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 _d,Bd,Wd,Ud,ha=A(()=>{"use strict";fe();_();_d={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:
289
289
  a-z character range
290
290
  [:alnum:] all letters and digits
291
291
  [:alpha:] all letters
@@ -299,144 +299,149 @@ Try 'comm --help' for more information.
299
299
  [:graph:] all printable characters except space
300
300
  [:cntrl:] all control characters
301
301
  [:xdigit:] all hexadecimal digits
302
- \\n, \\t, \\r escape sequences`},Ap={"[: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"};kp={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"}},vp={name:"tr",async execute(t,e){if(v(t))return k(Cp);let r=j("tr",t,kp);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,o=r.result.positional;if(o.length<1)return{stdout:"",stderr:`tr: missing operand
302
+ \\n, \\t, \\r escape sequences`},Bd={"[: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"};Wd={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"}},Ud={name:"tr",async execute(t,e){if(I(t))return N(_d);let r=G("tr",t,Wd);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,o=r.result.positional;if(o.length<1)return{stdout:"",stderr:`tr: missing operand
304
304
  `,exitCode:1};if(!s&&!i&&o.length<2)return{stdout:"",stderr:`tr: missing operand after SET1
305
- `,exitCode:1};let a=sa(o[0]),l=o.length>1?sa(o[1]):"",c=e.stdin,u=d=>{let p=a.includes(d);return n?!p:p},f="";if(s)for(let d of c)u(d)||(f+=d);else if(i&&o.length===1){let d="";for(let p of c)u(p)&&p===d||(f+=p,d=p)}else{if(n){let d=l.length>0?l[l.length-1]:"";for(let p of c)a.includes(p)?f+=p:f+=d}else{let d=new Map;for(let p=0;p<a.length;p++){let h=p<l.length?l[p]:l[l.length-1];d.set(a[p],h)}for(let p of c)f+=d.get(p)??p}if(i){let d="",p="";for(let h of f)l.includes(h)&&h===p||(d+=h,p=h);f=d}}return{stdout:f,stderr:"",exitCode:0}}}});var aa={};$(aa,{teeCommand:()=>$p});var Np,Ip,$p,la=C(()=>{"use strict";ue();M();Np={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"]},Ip={append:{short:"a",long:"append",type:"boolean"}},$p={name:"tee",async execute(t,e){if(v(t))return k(Np);let r=j("tee",t,Ip);if(!r.ok)return r.error;let{append:n}=r.result.flags,s=r.result.positional,i=e.stdin,o="",a=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{o+=`tee: ${l}: No such file or directory
306
- `,a=1}return{stdout:i,stderr:o,exitCode:a}}}});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 ca(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 ua=C(()=>{"use strict";In()});function fa(t,e){let r=[],n=[],s=e;for(;s<t.length;){let o=t[s];if(o==="("||o==="\\("){r.push({type:"lparen"}),s++;continue}if(o===")"||o==="\\)"){r.push({type:"rparen"}),s++;continue}if(o==="-name"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s]}});else if(o==="-iname"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s],ignoreCase:!0}});else if(o==="-path"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s]}});else if(o==="-ipath"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s],ignoreCase:!0}});else if(o==="-regex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s]}});else if(o==="-iregex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s],ignoreCase:!0}});else if(o==="-type"&&s+1<t.length){let a=t[++s];if(a==="f"||a==="d")r.push({type:"expr",expr:{type:"type",fileType:a}});else return{expr:null,pathIndex:s,error:`find: Unknown argument to -type: ${a}
307
- `,actions:[]}}else if(o==="-empty")r.push({type:"expr",expr:{type:"empty"}});else if(o==="-mtime"&&s+1<t.length){let a=t[++s],l="exact",c=a;a.startsWith("+")?(l="more",c=a.slice(1)):a.startsWith("-")&&(l="less",c=a.slice(1));let u=parseInt(c,10);Number.isNaN(u)||r.push({type:"expr",expr:{type:"mtime",days:u,comparison:l}})}else if(o==="-newer"&&s+1<t.length){let a=t[++s];r.push({type:"expr",expr:{type:"newer",refPath:a}})}else if(o==="-size"&&s+1<t.length){let a=t[++s],l="exact",c=a;a.startsWith("+")?(l="more",c=a.slice(1)):a.startsWith("-")&&(l="less",c=a.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(o==="-perm"&&s+1<t.length){let a=t[++s],l="exact",c=a;a.startsWith("-")?(l="all",c=a.slice(1)):a.startsWith("/")&&(l="any",c=a.slice(1));let u=parseInt(c,8);Number.isNaN(u)||r.push({type:"expr",expr:{type:"perm",mode:u,matchType:l}})}else if(o==="-prune")r.push({type:"expr",expr:{type:"prune"}});else if(o==="-not"||o==="!")r.push({type:"not"});else if(o==="-o"||o==="-or")r.push({type:"op",op:"or"});else if(o==="-a"||o==="-and")r.push({type:"op",op:"and"});else if(o==="-maxdepth"||o==="-mindepth")s++;else if(o!=="-depth")if(o==="-exec"){let a=[];for(s++;s<t.length&&t[s]!==";"&&t[s]!=="+";)a.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:a,batchMode:l})}else if(o==="-print")r.push({type:"expr",expr:{type:"print"}}),n.push({type:"print"});else if(o==="-print0")n.push({type:"print0"});else if(o==="-printf"&&s+1<t.length){let a=t[++s];n.push({type:"printf",format:a})}else if(o==="-delete")n.push({type:"delete"});else{if(o.startsWith("-"))return{expr:null,pathIndex:s,error:`find: unknown predicate '${o}'
308
- `,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=Rp(r);return i.error?{expr:null,pathIndex:s,error:i.error,actions:n}:{expr:i.expr,pathIndex:s,actions:n}}function Rp(t){let e=0;function r(){let a=n();if(!a)return null;for(;e<t.length;){let l=t[e];if(l.type==="op"&&l.op==="or"){e++;let c=n();if(!c)return a;a={type:"or",left:a,right:c}}else break}return a}function n(){let a=s();if(!a)return null;for(;e<t.length;){let l=t[e];if(l.type==="op"&&l.op==="and"){e++;let c=s();if(!c)return a;a={type:"and",left:a,right:c}}else if(l.type==="expr"||l.type==="not"||l.type==="lparen"){let c=s();if(!c)return a;a={type:"and",left:a,right:c}}else break}return a}function s(){if(e<t.length&&t[e].type==="not"){e++;let a=s();return a?{type:"not",expr:a}:null}return i()}function i(){if(e>=t.length)return null;let a=t[e];if(a.type==="lparen"){e++;let l=r();return e<t.length&&t[e].type==="rparen"&&e++,l}return a.type==="expr"?(e++,a.expr):(a.type==="rparen",null)}return{expr:r()}}var da=C(()=>{"use strict"});var pa={};$(pa,{findCommand:()=>Pp});function Tp(t,e){let r=gr(t),n="",s=0;for(;s<r.length;)if(r[s]==="%"&&s+1<r.length){if(s++,r[s]==="%"){n+="%",s++;continue}let[i,o,a]=wi(r,s);if(s+=a,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=Dp(e.mode,e.isDirectory),s++;break;case"t":{let u=new Date(e.mtime);c=Lp(u),s++;break}case"T":{if(s+1<r.length){let u=r[s+1],f=new Date(e.mtime);c=Mp(f,u),s+=2}else c="%T",s++;break}default:n+=`%${i!==0||o!==-1?`${i}.${o}`:""}${l}`,s++;continue}n+=mr(c,i,o)}else n+=r[s],s++;return n}function Dp(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 Lp(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," "),o=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0"),l=String(t.getSeconds()).padStart(2,"0"),c=t.getFullYear();return`${n} ${s} ${i} ${o}:${a}:${l} ${c}`}function Mp(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 Op,Fp,Pp,ha=C(()=>{"use strict";M();kn();ua();da();Op={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"]},Fp=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Pp={name:"find",async execute(t,e){if(v(t))return k(Op);let r=[],n=null,s=null,i=!1,o=!1;for(let S=0;S<t.length;S++){let A=t[S];if(A==="-maxdepth"&&S+1<t.length)o=!0,n=parseInt(t[++S],10);else if(A==="-mindepth"&&S+1<t.length)o=!0,s=parseInt(t[++S],10);else if(A==="-depth")o=!0,i=!0;else if(A==="-exec")for(o=!0,S++;S<t.length&&t[S]!==";"&&t[S]!=="+";)S++;else!A.startsWith("-")&&A!==";"&&A!=="+"&&A!=="("&&A!==")"&&A!=="\\("&&A!=="\\)"&&A!=="!"?o||r.push(A):Fp.has(A)?(o=!0,S++):(A.startsWith("-")||A==="("||A==="\\("||A==="!")&&(o=!0)}r.length===0&&r.push(".");let{expr:a,error:l,actions:c}=fa(t,0);if(l)return{stdout:"",stderr:l,exitCode:1};let u=c.some(S=>S.type==="print"),f=c.length===0,d=[],p=c.some(S=>S.type==="printf"),h=[],w="",g=0,y=ca(a),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
- `,g=1;continue}async function D(P,F){if(n!==null&&F>n)return;let B;try{B=await e.fs.stat(P)}catch{return}if(!B)return;let ee;P===A?ee=S.split("/").pop()||S:ee=P.split("/").pop()||"";let de=P===A?S:S==="."?`./${P.slice(A.length+1)}`:S+P.slice(A.length),ne=null;B.isDirectory&&(ne=await e.fs.readdir(P));let Se=B.isFile?B.size===0:ne!==null&&ne.length===0,He=()=>{let W=s===null||F>=s,U=!1;if(W&&a!==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},Me=Ye(a,Ce);W=Me.matches,u?U=Me.printed:U=W}else W&&(U=!0);U&&(d.push(de),p&&h.push({path:de,name:ee,size:B.size??0,mtime:B.mtime?.getTime()??Date.now(),mode:B.mode??420,isDirectory:B.isDirectory,depth:F,startingPoint:S}))},De=async()=>{if(ne!==null)for(let Le of ne){let W=P==="/"?`/${Le}`:`${P}/${Le}`;await D(W,F+1)}},hr=!1;if(!i&&a!==null){let Le={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};hr=Ye(a,Le).pruned}i?(await De(),He()):(He(),hr||await De())}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(`
305
+ `,exitCode:1};let a=pa(o[0]),c=o.length>1?pa(o[1]):"",l=e.stdin,u=p=>{let d=a.includes(p);return n?!d:d},f="";if(s)for(let p of l)u(p)||(f+=p);else if(i&&o.length===1){let p="";for(let d of l)u(d)&&d===p||(f+=d,p=d)}else{if(n){let p=c.length>0?c[c.length-1]:"";for(let d of l)a.includes(d)?f+=d:f+=p}else{let p=new Map;for(let d=0;d<a.length;d++){let h=d<c.length?c[d]:c[c.length-1];p.set(a[d],h)}for(let d of l)f+=p.get(d)??d}if(i){let p="",d="";for(let h of f)c.includes(h)&&h===d||(p+=h,d=h);f=p}}return{stdout:f,stderr:"",exitCode:0}}}});var ma={};$(ma,{teeCommand:()=>zd});var Hd,jd,zd,ya=A(()=>{"use strict";fe();_();Hd={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"]},jd={append:{short:"a",long:"append",type:"boolean"}},zd={name:"tee",async execute(t,e){if(I(t))return N(Hd);let r=G("tee",t,jd);if(!r.ok)return r.error;let{append:n}=r.result.flags,s=r.result.positional,i=e.stdin,o="",a=0;for(let c of s)try{let l=e.fs.resolvePath(e.cwd,c);n?await e.fs.appendFile(l,i):await e.fs.writeFile(l,i)}catch{o+=`tee: ${c}: No such file or directory
306
+ `,a=1}return{stdout:i,stderr:o,exitCode:a}}}});function tt(t,e){switch(t.type){case"name":return{matches:$e(e.name,t.pattern,t.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:$e(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=tt(t.expr,e);return{matches:!r.matches,pruned:r.pruned,printed:!1}}case"and":{let r=tt(t.left,e);if(!r.matches)return{matches:!1,pruned:r.pruned,printed:!1};let n=tt(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:r.printed||n.printed}}case"or":{let r=tt(t.left,e);if(r.matches)return r;let n=tt(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:n.printed}}}}function ga(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 xa=A(()=>{"use strict";Pn()});function wa(t,e){let r=[],n=[],s=e;for(;s<t.length;){let o=t[s];if(o==="("||o==="\\("){r.push({type:"lparen"}),s++;continue}if(o===")"||o==="\\)"){r.push({type:"rparen"}),s++;continue}if(o==="-name"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s]}});else if(o==="-iname"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s],ignoreCase:!0}});else if(o==="-path"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s]}});else if(o==="-ipath"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s],ignoreCase:!0}});else if(o==="-regex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s]}});else if(o==="-iregex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s],ignoreCase:!0}});else if(o==="-type"&&s+1<t.length){let a=t[++s];if(a==="f"||a==="d")r.push({type:"expr",expr:{type:"type",fileType:a}});else return{expr:null,pathIndex:s,error:`find: Unknown argument to -type: ${a}
307
+ `,actions:[]}}else if(o==="-empty")r.push({type:"expr",expr:{type:"empty"}});else if(o==="-mtime"&&s+1<t.length){let a=t[++s],c="exact",l=a;a.startsWith("+")?(c="more",l=a.slice(1)):a.startsWith("-")&&(c="less",l=a.slice(1));let u=parseInt(l,10);Number.isNaN(u)||r.push({type:"expr",expr:{type:"mtime",days:u,comparison:c}})}else if(o==="-newer"&&s+1<t.length){let a=t[++s];r.push({type:"expr",expr:{type:"newer",refPath:a}})}else if(o==="-size"&&s+1<t.length){let a=t[++s],c="exact",l=a;a.startsWith("+")?(c="more",l=a.slice(1)):a.startsWith("-")&&(c="less",l=a.slice(1));let u=l.match(/^(\d+)([ckMGb])?$/);if(u){let f=parseInt(u[1],10),p=u[2]||"b";r.push({type:"expr",expr:{type:"size",value:f,unit:p,comparison:c}})}}else if(o==="-perm"&&s+1<t.length){let a=t[++s],c="exact",l=a;a.startsWith("-")?(c="all",l=a.slice(1)):a.startsWith("/")&&(c="any",l=a.slice(1));let u=parseInt(l,8);Number.isNaN(u)||r.push({type:"expr",expr:{type:"perm",mode:u,matchType:c}})}else if(o==="-prune")r.push({type:"expr",expr:{type:"prune"}});else if(o==="-not"||o==="!")r.push({type:"not"});else if(o==="-o"||o==="-or")r.push({type:"op",op:"or"});else if(o==="-a"||o==="-and")r.push({type:"op",op:"and"});else if(o==="-maxdepth"||o==="-mindepth")s++;else if(o!=="-depth")if(o==="-exec"){let a=[];for(s++;s<t.length&&t[s]!==";"&&t[s]!=="+";)a.push(t[s]),s++;if(s>=t.length)return{expr:null,pathIndex:s,error:"find: missing argument to `-exec'\n",actions:[]};let c=t[s]==="+";n.push({type:"exec",command:a,batchMode:c})}else if(o==="-print")r.push({type:"expr",expr:{type:"print"}}),n.push({type:"print"});else if(o==="-print0")n.push({type:"print0"});else if(o==="-printf"&&s+1<t.length){let a=t[++s];n.push({type:"printf",format:a})}else if(o==="-delete")n.push({type:"delete"});else{if(o.startsWith("-"))return{expr:null,pathIndex:s,error:`find: unknown predicate '${o}'
308
+ `,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=Gd(r);return i.error?{expr:null,pathIndex:s,error:i.error,actions:n}:{expr:i.expr,pathIndex:s,actions:n}}function Gd(t){let e=0;function r(){let a=n();if(!a)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="or"){e++;let l=n();if(!l)return a;a={type:"or",left:a,right:l}}else break}return a}function n(){let a=s();if(!a)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="and"){e++;let l=s();if(!l)return a;a={type:"and",left:a,right:l}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let l=s();if(!l)return a;a={type:"and",left:a,right:l}}else break}return a}function s(){if(e<t.length&&t[e].type==="not"){e++;let a=s();return a?{type:"not",expr:a}:null}return i()}function i(){if(e>=t.length)return null;let a=t[e];if(a.type==="lparen"){e++;let c=r();return e<t.length&&t[e].type==="rparen"&&e++,c}return a.type==="expr"?(e++,a.expr):(a.type==="rparen",null)}return{expr:r()}}var Ea=A(()=>{"use strict"});var ba={};$(ba,{findCommand:()=>Kd});function Zd(t,e){let r=xr(t),n="",s=0;for(;s<r.length;)if(r[s]==="%"&&s+1<r.length){if(s++,r[s]==="%"){n+="%",s++;continue}let[i,o,a]=Ii(r,s);if(s+=a,s>=r.length){n+="%";break}let c=r[s],l;switch(c){case"f":l=e.name,s++;break;case"h":{let u=e.path.lastIndexOf("/");l=u>0?e.path.slice(0,u):".",s++;break}case"p":l=e.path,s++;break;case"P":{let u=e.startingPoint;e.path===u?l="":e.path.startsWith(`${u}/`)?l=e.path.slice(u.length+1):u==="."&&e.path.startsWith("./")?l=e.path.slice(2):l=e.path,s++;break}case"s":l=String(e.size),s++;break;case"d":l=String(e.depth),s++;break;case"m":l=(e.mode&511).toString(8),s++;break;case"M":l=Qd(e.mode,e.isDirectory),s++;break;case"t":{let u=new Date(e.mtime);l=Xd(u),s++;break}case"T":{if(s+1<r.length){let u=r[s+1],f=new Date(e.mtime);l=Jd(f,u),s+=2}else l="%T",s++;break}default:n+=`%${i!==0||o!==-1?`${i}.${o}`:""}${c}`,s++;continue}n+=gr(l,i,o)}else n+=r[s],s++;return n}function Qd(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 Xd(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," "),o=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0"),l=t.getFullYear();return`${n} ${s} ${i} ${o}:${a}:${c} ${l}`}function Jd(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 qd,Vd,Kd,Sa=A(()=>{"use strict";_();Rn();xa();Ea();qd={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"]},Vd=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Kd={name:"find",async execute(t,e){if(I(t))return N(qd);let r=[],n=null,s=null,i=!1,o=!1;for(let S=0;S<t.length;S++){let C=t[S];if(C==="-maxdepth"&&S+1<t.length)o=!0,n=parseInt(t[++S],10);else if(C==="-mindepth"&&S+1<t.length)o=!0,s=parseInt(t[++S],10);else if(C==="-depth")o=!0,i=!0;else if(C==="-exec")for(o=!0,S++;S<t.length&&t[S]!==";"&&t[S]!=="+";)S++;else!C.startsWith("-")&&C!==";"&&C!=="+"&&C!=="("&&C!==")"&&C!=="\\("&&C!=="\\)"&&C!=="!"?o||r.push(C):Vd.has(C)?(o=!0,S++):(C.startsWith("-")||C==="("||C==="\\("||C==="!")&&(o=!0)}r.length===0&&r.push(".");let{expr:a,error:c,actions:l}=wa(t,0);if(c)return{stdout:"",stderr:c,exitCode:1};let u=l.some(S=>S.type==="print"),f=l.length===0,p=[],d=l.some(S=>S.type==="printf"),h=[],g="",y=0,w=ga(a),E=new Map;for(let S of w){let C=e.fs.resolvePath(e.cwd,S);try{let O=await e.fs.stat(C);E.set(S,O.mtime?.getTime()??Date.now())}catch{}}for(let S of r){S.length>1&&S.endsWith("/")&&(S=S.slice(0,-1));let C=e.fs.resolvePath(e.cwd,S);try{await e.fs.stat(C)}catch{g+=`find: ${S}: No such file or directory
309
+ `,y=1;continue}async function O(D,F){if(n!==null&&F>n)return;let U;try{U=await e.fs.stat(D)}catch{return}if(!U)return;let te;D===C?te=S.split("/").pop()||S:te=D.split("/").pop()||"";let de=D===C?S:S==="."?`./${D.slice(C==="/"?C.length:C.length+1)}`:S+D.slice(C.length),se=null;U.isDirectory&&(se=await e.fs.readdir(D));let Ce=U.isFile?U.size===0:se!==null&&se.length===0,ze=()=>{let H=s===null||F>=s,j=!1;if(H&&a!==null){let ke={name:te,relativePath:de,isFile:U.isFile,isDirectory:U.isDirectory,isEmpty:Ce,mtime:U.mtime?.getTime()??Date.now(),size:U.size??0,mode:U.mode??420,newerRefTimes:E},Be=tt(a,ke);H=Be.matches,u?j=Be.printed:j=H}else H&&(j=!0);j&&(p.push(de),d&&h.push({path:de,name:te,size:U.size??0,mtime:U.mtime?.getTime()??Date.now(),mode:U.mode??420,isDirectory:U.isDirectory,depth:F,startingPoint:S}))},Me=async()=>{if(se!==null)for(let _e of se){let H=D==="/"?`/${_e}`:`${D}/${_e}`;await O(H,F+1)}},yr=!1;if(!i&&a!==null){let _e={name:te,relativePath:de,isFile:U.isFile,isDirectory:U.isDirectory,isEmpty:Ce,mtime:U.mtime?.getTime()??Date.now(),size:U.size??0,mode:U.mode??420,newerRefTimes:E};yr=tt(a,_e).pruned}i?(await Me(),ze()):(ze(),yr||await Me())}await O(C,0)}let b="";if(l.length>0)for(let S of l)switch(S.type){case"print":b+=p.length>0?`${p.join(`
310
310
  `)}
311
- `:"";break;case"print0":b+=d.length>0?`${d.join("\0")}\0`:"";break;case"delete":{let A=[...d].sort((D,P)=>P.length-D.length);for(let D of A){let P=e.fs.resolvePath(e.cwd,D);try{await e.fs.rm(P,{recursive:!1})}catch(F){let B=F instanceof Error?F.message:String(F);w+=`find: cannot delete '${D}': ${B}
312
- `,g=1}}break}case"printf":for(let A of h)b+=Tp(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 F of S.command)F==="{}"?A.push(...d):A.push(F);let D=A.map(F=>`"${F}"`).join(" "),P=await e.exec(D,{cwd:e.cwd});b+=P.stdout,w+=P.stderr,P.exitCode!==0&&(g=P.exitCode)}else for(let A of d){let P=S.command.map(B=>B==="{}"?A:B).map(B=>`"${B}"`).join(" "),F=await e.exec(P,{cwd:e.cwd});b+=F.stdout,w+=F.stderr,F.exitCode!==0&&(g=F.exitCode)}break}else f&&(b=d.length>0?`${d.join(`
311
+ `:"";break;case"print0":b+=p.length>0?`${p.join("\0")}\0`:"";break;case"delete":{let C=[...p].sort((O,D)=>D.length-O.length);for(let O of C){let D=e.fs.resolvePath(e.cwd,O);try{await e.fs.rm(D,{recursive:!1})}catch(F){let U=F instanceof Error?F.message:String(F);g+=`find: cannot delete '${O}': ${U}
312
+ `,y=1}}break}case"printf":for(let C of h)b+=Zd(S.format,C);break;case"exec":if(!e.exec)return{stdout:"",stderr:`find: -exec not supported in this context
313
+ `,exitCode:1};if(S.batchMode){let C=[];for(let F of S.command)F==="{}"?C.push(...p):C.push(F);let O=C.map(F=>`"${F}"`).join(" "),D=await e.exec(O,{cwd:e.cwd});b+=D.stdout,g+=D.stderr,D.exitCode!==0&&(y=D.exitCode)}else for(let C of p){let D=S.command.map(U=>U==="{}"?C:U).map(U=>`"${U}"`).join(" "),F=await e.exec(D,{cwd:e.cwd});b+=F.stdout,g+=F.stderr,F.exitCode!==0&&(y=F.exitCode)}break}else f&&(b=p.length>0?`${p.join(`
314
314
  `)}
315
- `:"");return{stdout:b,stderr:w,exitCode:g}}}});var ma={};$(ma,{basenameCommand:()=>Bp});var _p,Bp,ga=C(()=>{"use strict";M();_p={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"]},Bp={name:"basename",async execute(t,e){if(v(t))return k(_p);let r=!1,n="",s=[];for(let o=0;o<t.length;o++){let a=t[o];a==="-a"||a==="--multiple"?r=!0:a==="-s"&&o+1<t.length?(n=t[++o],r=!0):a.startsWith("--suffix=")?(n=a.slice(9),r=!0):a.startsWith("-")||s.push(a)}if(s.length===0)return{stdout:"",stderr:`basename: missing operand
317
- `,exitCode:1};!r&&s.length>=2&&(n=s.pop()??"");let i=[];for(let o of s){let a=o.replace(/\/+$/,""),l=a.split("/").pop()||a;n&&l.endsWith(n)&&(l=l.slice(0,-n.length)),i.push(l)}return{stdout:`${i.join(`
315
+ `:"");return{stdout:b,stderr:g,exitCode:y}}}});var Aa={};$(Aa,{basenameCommand:()=>eh});var Yd,eh,Ca=A(()=>{"use strict";_();Yd={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"]},eh={name:"basename",async execute(t,e){if(I(t))return N(Yd);let r=!1,n="",s=[];for(let o=0;o<t.length;o++){let a=t[o];a==="-a"||a==="--multiple"?r=!0:a==="-s"&&o+1<t.length?(n=t[++o],r=!0):a.startsWith("--suffix=")?(n=a.slice(9),r=!0):a.startsWith("-")||s.push(a)}if(s.length===0)return{stdout:"",stderr:`basename: missing operand
317
+ `,exitCode:1};!r&&s.length>=2&&(n=s.pop()??"");let i=[];for(let o of s){let a=o.replace(/\/+$/,""),c=a.split("/").pop()||a;n&&c.endsWith(n)&&(c=c.slice(0,-n.length)),i.push(c)}return{stdout:`${i.join(`
318
318
  `)}
319
- `,stderr:"",exitCode:0}}}});var xa={};$(xa,{dirnameCommand:()=>Up});var Wp,Up,ya=C(()=>{"use strict";M();Wp={name:"dirname",summary:"strip last component from file name",usage:"dirname [OPTION] NAME...",options:[" --help display this help and exit"]},Up={name:"dirname",async execute(t,e){if(v(t))return k(Wp);let r=t.filter(s=>!s.startsWith("-"));if(r.length===0)return{stdout:"",stderr:`dirname: missing operand
319
+ `,stderr:"",exitCode:0}}}});var ka={};$(ka,{dirnameCommand:()=>rh});var th,rh,Na=A(()=>{"use strict";_();th={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(I(t))return N(th);let r=t.filter(s=>!s.startsWith("-"));if(r.length===0)return{stdout:"",stderr:`dirname: missing operand
320
320
  `,exitCode:1};let n=[];for(let s of r){let i=s.replace(/\/+$/,""),o=i.lastIndexOf("/");o===-1?n.push("."):o===0?n.push("/"):n.push(i.slice(0,o))}return{stdout:`${n.join(`
321
321
  `)}
322
- `,stderr:"",exitCode:0}}}});var Ea={};$(Ea,{treeCommand:()=>jp});async function Gp(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0},o=t.fs.resolvePath(t.cwd,e);try{if(!(await t.fs.stat(o)).isDirectory)return i.output=`${e}
322
+ `,stderr:"",exitCode:0}}}});var va={};$(va,{treeCommand:()=>ih});async function oh(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0},o=t.fs.resolvePath(t.cwd,e);try{if(!(await t.fs.stat(o)).isDirectory)return i.output=`${e}
323
323
  `,i.fileCount=1,i}catch{return i.stderr=`tree: ${e}: No such file or directory
324
324
  `,i}if(i.output=`${e}
325
- `,r.maxDepth!==null&&s>=r.maxDepth)return i;try{let l=(await t.fs.readdir(o)).filter(c=>!(!r.showHidden&&c.startsWith(".")));l.sort();for(let c=0;c<l.length;c++){let u=l[c],f=o==="/"?`/${u}`:`${o}/${u}`,d=c===l.length-1,p=d?"`-- ":"|-- ",h=n+(d?" ":"| ");try{if((await t.fs.stat(f)).isDirectory){i.dirCount++;let g=r.fullPath?f:u;if(i.output+=`${n+p+g}
326
- `,r.maxDepth===null||s+1<r.maxDepth){let y=await wa(t,f,r,h,s+1);i.output+=y.output,i.dirCount+=y.dirCount,i.fileCount+=y.fileCount}}else if(!r.directoriesOnly){i.fileCount++;let g=r.fullPath?f:u;i.output+=`${n+p+g}
325
+ `,r.maxDepth!==null&&s>=r.maxDepth)return i;try{let c=(await t.fs.readdir(o)).filter(l=>!(!r.showHidden&&l.startsWith(".")));c.sort();for(let l=0;l<c.length;l++){let u=c[l],f=o==="/"?`/${u}`:`${o}/${u}`,p=l===c.length-1,d=p?"`-- ":"|-- ",h=n+(p?" ":"| ");try{if((await t.fs.stat(f)).isDirectory){i.dirCount++;let y=r.fullPath?f:u;if(i.output+=`${n+d+y}
326
+ `,r.maxDepth===null||s+1<r.maxDepth){let w=await Ia(t,f,r,h,s+1);i.output+=w.output,i.dirCount+=w.dirCount,i.fileCount+=w.fileCount}}else if(!r.directoriesOnly){i.fileCount++;let y=r.fullPath?f:u;i.output+=`${n+d+y}
327
327
  `}}catch{}}}catch{i.stderr=`tree: ${e}: Permission denied
328
- `}return i}async function wa(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0};if(r.maxDepth!==null&&s>=r.maxDepth)return i;try{let a=(await t.fs.readdir(e)).filter(l=>!(!r.showHidden&&l.startsWith(".")));a.sort();for(let l=0;l<a.length;l++){let c=a[l],u=e==="/"?`/${c}`:`${e}/${c}`,f=l===a.length-1,d=f?"`-- ":"|-- ",p=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 g=await wa(t,u,r,p,s+1);i.output+=g.output,i.dirCount+=g.dirCount,i.fileCount+=g.fileCount}else if(!r.directoriesOnly){i.fileCount++;let w=r.fullPath?u:c;i.output+=`${n+d+w}
330
- `}}catch{}}}catch{}return i}var Hp,zp,jp,ba=C(()=>{"use strict";ue();M();Hp={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"]},zp={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},jp={name:"tree",async execute(t,e){if(v(t))return k(Hp);let r=j("tree",t,zp);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="",o="",a=0,l=0;for(let c of s){let u=await Gp(e,c,n,"",0);i+=u.output,o+=u.stderr,a+=u.dirCount,l+=u.fileCount}return i+=`
331
- ${a} director${a===1?"y":"ies"}`,n.directoriesOnly||(i+=`, ${l} file${l===1?"":"s"}`),i+=`
332
- `,{stdout:i,stderr:o,exitCode:o?1:0}}}});var Ca={};$(Ca,{duCommand:()=>Zp});async function Sa(t,e,r,n,s){let i={output:"",totalSize:0,stderr:""};try{let o=await t.fs.stat(e);if(!o.isDirectory)return i.totalSize=o.size,(n.allFiles||s===0)&&(i.output=Rr(o.size,n.humanReadable)+" "+r+`
333
- `),i;let a=await t.fs.readdir(e),l=0;for(let c of a){let u=e==="/"?`/${c}`:`${e}/${c}`,f=r==="."?c:`${r}/${c}`;try{let d=await t.fs.stat(u);if(d.isDirectory){let p=await Sa(t,u,f,n,s+1);l+=p.totalSize,n.summarize||(n.maxDepth===null||s+1<=n.maxDepth?i.output+=p.output:l+=0)}else l+=d.size,n.allFiles&&!n.summarize&&(i.output+=Rr(d.size,n.humanReadable)+" "+f+`
334
- `)}catch{}}i.totalSize=l,(n.summarize||n.maxDepth===null||s<=n.maxDepth)&&(i.output+=`${Rr(l,n.humanReadable)} ${r}
328
+ `}return i}async function Ia(t,e,r,n,s){let i={output:"",stderr:"",dirCount:0,fileCount:0};if(r.maxDepth!==null&&s>=r.maxDepth)return i;try{let a=(await t.fs.readdir(e)).filter(c=>!(!r.showHidden&&c.startsWith(".")));a.sort();for(let c=0;c<a.length;c++){let l=a[c],u=e==="/"?`/${l}`:`${e}/${l}`,f=c===a.length-1,p=f?"`-- ":"|-- ",d=n+(f?" ":"| ");try{if((await t.fs.stat(u)).isDirectory){i.dirCount++;let g=r.fullPath?u:l;i.output+=`${n+p+g}
329
+ `;let y=await Ia(t,u,r,d,s+1);i.output+=y.output,i.dirCount+=y.dirCount,i.fileCount+=y.fileCount}else if(!r.directoriesOnly){i.fileCount++;let g=r.fullPath?u:l;i.output+=`${n+p+g}
330
+ `}}catch{}}}catch{}return i}var nh,sh,ih,Ra=A(()=>{"use strict";fe();_();nh={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"]},sh={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},ih={name:"tree",async execute(t,e){if(I(t))return N(nh);let r=G("tree",t,sh);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="",o="",a=0,c=0;for(let l of s){let u=await oh(e,l,n,"",0);i+=u.output,o+=u.stderr,a+=u.dirCount,c+=u.fileCount}return i+=`
331
+ ${a} director${a===1?"y":"ies"}`,n.directoriesOnly||(i+=`, ${c} file${c===1?"":"s"}`),i+=`
332
+ `,{stdout:i,stderr:o,exitCode:o?1:0}}}});var Oa={};$(Oa,{duCommand:()=>lh});async function $a(t,e,r,n,s){let i={output:"",totalSize:0,stderr:""};try{let o=await t.fs.stat(e);if(!o.isDirectory)return i.totalSize=o.size,(n.allFiles||s===0)&&(i.output=Pr(o.size,n.humanReadable)+" "+r+`
333
+ `),i;let a=await t.fs.readdir(e),c=0;for(let l of a){let u=e==="/"?`/${l}`:`${e}/${l}`,f=r==="."?l:`${r}/${l}`;try{let p=await t.fs.stat(u);if(p.isDirectory){let d=await $a(t,u,f,n,s+1);c+=d.totalSize,n.summarize||(n.maxDepth===null||s+1<=n.maxDepth?i.output+=d.output:c+=0)}else c+=p.size,n.allFiles&&!n.summarize&&(i.output+=Pr(p.size,n.humanReadable)+" "+f+`
334
+ `)}catch{}}i.totalSize=c,(n.summarize||n.maxDepth===null||s<=n.maxDepth)&&(i.output+=`${Pr(c,n.humanReadable)} ${r}
335
335
  `)}catch{i.stderr=`du: cannot read directory '${r}': Permission denied
336
- `}return i}function Rr(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 qp,Vp,Zp,Aa=C(()=>{"use strict";ue();M();qp={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"]},Vp={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"}},Zp={name:"du",async execute(t,e){if(v(t))return k(qp);let r=j("du",t,Vp);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="",o="",a=0;for(let l of s){let c=e.fs.resolvePath(e.cwd,l);try{await e.fs.stat(c);let u=await Sa(e,c,l,n,0);i+=u.output,a+=u.totalSize,o+=u.stderr}catch{o+=`du: cannot access '${l}': No such file or directory
337
- `}}return n.grandTotal&&s.length>0&&(i+=`${Rr(a,n.humanReadable)} total
338
- `),{stdout:i,stderr:o,exitCode:o?1:0}}}});var jn={};$(jn,{envCommand:()=>Xp,printenvCommand:()=>Jp});var Qp,Xp,Kp,Jp,Gn=C(()=>{"use strict";M();Qp={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"]},Xp={name:"env",async execute(t,e){if(v(t))return k(Qp);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("="),p=f.slice(0,d),h=f.slice(d+1);s[p]=h}else{i=u;break}}}let o;if(r)o={...s};else{o={...e.env};for(let u of n)delete o[u];Object.assign(o,s)}if(i===-1){let u=[];for(let[f,d]of Object.entries(o))u.push(`${f}=${d}`);return{stdout:u.join(`
336
+ `}return i}function Pr(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 ah,ch,lh,Pa=A(()=>{"use strict";fe();_();ah={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"]},ch={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(I(t))return N(ah);let r=G("du",t,ch);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="",o="",a=0;for(let c of s){let l=e.fs.resolvePath(e.cwd,c);try{await e.fs.stat(l);let u=await $a(e,l,c,n,0);i+=u.output,a+=u.totalSize,o+=u.stderr}catch{o+=`du: cannot access '${c}': No such file or directory
337
+ `}}return n.grandTotal&&s.length>0&&(i+=`${Pr(a,n.humanReadable)} total
338
+ `),{stdout:i,stderr:o,exitCode:o?1:0}}}});var Kn={};$(Kn,{envCommand:()=>fh,printenvCommand:()=>dh});var uh,fh,ph,dh,Zn=A(()=>{"use strict";_();uh={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"]},fh={name:"env",async execute(t,e){if(I(t))return N(uh);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 L("env",f);if(f.startsWith("-")&&f!=="-"){for(let p of f.slice(1))if(p!=="i"&&p!=="u")return L("env",`-${p}`);f.includes("i")&&(r=!0)}else if(f.includes("=")&&i===-1){let p=f.indexOf("="),d=f.slice(0,p),h=f.slice(p+1);s[d]=h}else{i=u;break}}}let o;if(r)o={...s};else{o={...e.env};for(let u of n)delete o[u];Object.assign(o,s)}if(i===-1){let u=[];for(let[f,p]of Object.entries(o))u.push(`${f}=${p}`);return{stdout:u.join(`
339
339
  `)+(u.length>0?`
340
340
  `:""),stderr:"",exitCode:0}}if(!e.exec)return{stdout:"",stderr:`env: command execution not supported in this context
341
- `,exitCode:1};let a=t.slice(i).join(" "),l=Object.entries(s).map(([u,f])=>`${u}="${f}"`).join(" "),c=l?`${l} ${a}`:a;return e.exec(c,{cwd:e.cwd})}},Kp={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:[" --help display this help and exit"]},Jp={name:"printenv",async execute(t,e){if(v(t))return k(Kp);let r=t.filter(i=>!i.startsWith("-"));if(r.length===0){let i=[];for(let[o,a]of Object.entries(e.env))i.push(`${o}=${a}`);return{stdout:i.join(`
341
+ `,exitCode:1};let a=t.slice(i).join(" "),c=Object.entries(s).map(([u,f])=>`${u}="${f}"`).join(" "),l=c?`${c} ${a}`:a;return e.exec(l,{cwd:e.cwd})}},ph={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:[" --help display this help and exit"]},dh={name:"printenv",async execute(t,e){if(I(t))return N(ph);let r=t.filter(i=>!i.startsWith("-"));if(r.length===0){let i=[];for(let[o,a]of Object.entries(e.env))i.push(`${o}=${a}`);return{stdout:i.join(`
342
342
  `)+(i.length>0?`
343
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(`
344
344
  `)+(n.length>0?`
345
- `:""),stderr:"",exitCode:s}}}});var qn={};$(qn,{aliasCommand:()=>eh,unaliasCommand:()=>th});var Yp,It,eh,th,Vn=C(()=>{"use strict";M();Yp={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},It="BASH_ALIAS_",eh={name:"alias",async execute(t,e){if(v(t))return k(Yp);if(t.length===0){let r="";for(let[n,s]of Object.entries(e.env))if(n.startsWith(It)){let i=n.slice(It.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=It+r;return e.env[s]?{stdout:`alias ${r}='${e.env[s]}'
345
+ `:""),stderr:"",exitCode:s}}}});var Qn={};$(Qn,{aliasCommand:()=>mh,unaliasCommand:()=>yh});var hh,Ot,mh,yh,Xn=A(()=>{"use strict";_();hh={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},Ot="BASH_ALIAS_",mh={name:"alias",async execute(t,e){if(I(t))return N(hh);if(t.length===0){let r="";for(let[n,s]of Object.entries(e.env))if(n.startsWith(Ot)){let i=n.slice(Ot.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=Ot+r;return e.env[s]?{stdout:`alias ${r}='${e.env[s]}'
347
347
  `,stderr:"",exitCode:0}:{stdout:"",stderr:`alias: ${r}: not found
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[It+s]=i}}return{stdout:"",stderr:"",exitCode:0}}},th={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(It)&&delete e.env[s];return{stdout:"",stderr:"",exitCode:0}}let r=!1,n="";for(let s of t){let i=It+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 va={};$(va,{historyCommand:()=>nh});var rh,ka,nh,Na=C(()=>{"use strict";M();rh={name:"history",summary:"display command history",usage:"history [n]",options:["-c clear the history list"," --help display this help and exit"]},ka="BASH_HISTORY",nh={name:"history",async execute(t,e){if(v(t))return k(rh);let r=e.env[ka]||"[]",n;try{n=JSON.parse(r)}catch{n=[]}if(t[0]==="-c")return e.env[ka]="[]",{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,o="";for(let a=i;a<n.length;a++){let l=(a+1).toString().padStart(5," ");o+=`${l} ${n[a]}
351
- `}return{stdout:o,stderr:"",exitCode:0}}}});var Ia={};$(Ia,{xargsCommand:()=>ih});var sh,ih,$a=C(()=>{"use strict";M();sh={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"]},ih={name:"xargs",async execute(t,e){if(v(t))return k(sh);let r=null,n=null,s=null,i=!1,o=!1,a=!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")o=!0,l=y+1;else if(E==="-r"||E==="--no-run-if-empty")a=!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")&&(o=!0),E.includes("r")&&(a=!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 a?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let d="",p="",h=0,w=async y=>{let E=y.join(" ");return o&&(p+=`${E}
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[Ot+s]=i}}return{stdout:"",stderr:"",exitCode:0}}},yh={name:"unalias",async execute(t,e){if(I(t))return N({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(Ot)&&delete e.env[s];return{stdout:"",stderr:"",exitCode:0}}let r=!1,n="";for(let s of t){let i=Ot+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 Fa={};$(Fa,{historyCommand:()=>xh});var gh,Ta,xh,Da=A(()=>{"use strict";_();gh={name:"history",summary:"display command history",usage:"history [n]",options:["-c clear the history list"," --help display this help and exit"]},Ta="BASH_HISTORY",xh={name:"history",async execute(t,e){if(I(t))return N(gh);let r=e.env[Ta]||"[]",n;try{n=JSON.parse(r)}catch{n=[]}if(t[0]==="-c")return e.env[Ta]="[]",{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,o="";for(let a=i;a<n.length;a++){let c=(a+1).toString().padStart(5," ");o+=`${c} ${n[a]}
351
+ `}return{stdout:o,stderr:"",exitCode:0}}}});var La={};$(La,{xargsCommand:()=>Eh});var wh,Eh,Ma=A(()=>{"use strict";_();wh={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"]},Eh={name:"xargs",async execute(t,e){if(I(t))return N(wh);let r=null,n=null,s=null,i=!1,o=!1,a=!1,c=0;for(let w=0;w<t.length;w++){let E=t[w];if(E==="-I"&&w+1<t.length)r=t[++w],c=w+1;else if(E==="-n"&&w+1<t.length)n=parseInt(t[++w],10),c=w+1;else if(E==="-P"&&w+1<t.length)s=parseInt(t[++w],10),c=w+1;else if(E==="-0"||E==="--null")i=!0,c=w+1;else if(E==="-t"||E==="--verbose")o=!0,c=w+1;else if(E==="-r"||E==="--no-run-if-empty")a=!0,c=w+1;else{if(E.startsWith("--"))return L("xargs",E);if(E.startsWith("-")&&E.length>1){for(let b of E.slice(1))if(!"0tr".includes(b))return L("xargs",`-${b}`);E.includes("0")&&(i=!0),E.includes("t")&&(o=!0),E.includes("r")&&(a=!0),c=w+1}else if(!E.startsWith("-")){c=w;break}}}let l=t.slice(c);l.length===0&&l.push("echo");let u=i?"\0":/\s+/,f=e.stdin.split(u).map(w=>w.trim()).filter(w=>w.length>0);if(f.length===0)return a?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let p="",d="",h=0,g=async w=>{let E=w.join(" ");return o&&(d+=`${E}
352
352
  `),e.exec?e.exec(E,{cwd:e.cwd}):{stdout:`${E}
353
- `,stderr:"",exitCode:0}},g=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,p+=A.stderr,A.exitCode!==0&&(h=A.exitCode)}else for(let E of y){let b=await w(E);d+=b.stdout,p+=b.stderr,b.exitCode!==0&&(h=b.exitCode)}};if(r!==null){let y=f.map(E=>c.map(b=>b.replaceAll(r,E)));await g(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 g(y)}else{let y=[...c,...f],E=await w(y);d+=E.stdout,p+=E.stderr,h=E.exitCode}return{stdout:d,stderr:p,exitCode:h}}}});var Zn={};$(Zn,{falseCommand:()=>ah,trueCommand:()=>oh});var oh,ah,Qn=C(()=>{"use strict";oh={name:"true",async execute(){return{stdout:"",stderr:"",exitCode:0}}},ah={name:"false",async execute(){return{stdout:"",stderr:"",exitCode:1}}}});var Ra={};$(Ra,{clearCommand:()=>ch});var lh,ch,Oa=C(()=>{"use strict";M();lh={name:"clear",summary:"clear the terminal screen",usage:"clear [OPTIONS]",options:[" --help display this help and exit"]},ch={name:"clear",async execute(t,e){return v(t)?k(lh):{stdout:"\x1B[2J\x1B[H",stderr:"",exitCode:0}}}});var Xn={};$(Xn,{bashCommand:()=>uh,shCommand:()=>fh});async function Or(t,e,r,n){if(!n.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
353
+ `,stderr:"",exitCode:0}},y=async w=>{if(s!==null&&s>1)for(let E=0;E<w.length;E+=s){let b=w.slice(E,E+s),S=await Promise.all(b.map(g));for(let C of S)p+=C.stdout,d+=C.stderr,C.exitCode!==0&&(h=C.exitCode)}else for(let E of w){let b=await g(E);p+=b.stdout,d+=b.stderr,b.exitCode!==0&&(h=b.exitCode)}};if(r!==null){let w=f.map(E=>l.map(b=>b.replaceAll(r,E)));await y(w)}else if(n!==null){let w=[];for(let E=0;E<f.length;E+=n){let b=f.slice(E,E+n);w.push([...l,...b])}await y(w)}else{let w=[...l,...f],E=await g(w);p+=E.stdout,d+=E.stderr,h=E.exitCode}return{stdout:p,stderr:d,exitCode:h}}}});var Jn={};$(Jn,{falseCommand:()=>Sh,trueCommand:()=>bh});var bh,Sh,Yn=A(()=>{"use strict";bh={name:"true",async execute(){return{stdout:"",stderr:"",exitCode:0}}},Sh={name:"false",async execute(){return{stdout:"",stderr:"",exitCode:1}}}});var _a={};$(_a,{clearCommand:()=>Ch});var Ah,Ch,Ba=A(()=>{"use strict";_();Ah={name:"clear",summary:"clear the terminal screen",usage:"clear [OPTIONS]",options:[" --help display this help and exit"]},Ch={name:"clear",async execute(t,e){return I(t)?N(Ah):{stdout:"\x1B[2J\x1B[H",stderr:"",exitCode:0}}}});var es={};$(es,{bashCommand:()=>kh,shCommand:()=>Nh});async function Tr(t,e,r,n){if(!n.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
354
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(`
355
355
  `);u!==-1&&(i=i.slice(u+1))}let o=i.split(`
356
- `),a=[];for(let u of o){let f=u.trim();f&&!f.startsWith("#")&&a.push(f)}let l=a.join("; ");return await n.exec(l,{env:s,cwd:n.cwd})}var Fa,uh,fh,Kn=C(()=>{"use strict";M();Fa={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).']},uh={name:"bash",async execute(t,e){if(v(t))return k(Fa);if(t[0]==="-c"&&t.length>=2){let s=t[1],i=t[2]||"bash",o=t.slice(3);return Or(s,i,o,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 Or(i,r,n,e)}catch{return{stdout:"",stderr:`bash: ${r}: No such file or directory
357
- `,exitCode:127}}}},fh={name:"sh",async execute(t,e){if(v(t))return k({...Fa,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",o=t.slice(3);return Or(s,i,o,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 Or(i,r,n,e)}catch{return{stdout:"",stderr:`sh: ${r}: No such file or directory
358
- `,exitCode:127}}}}});var Pa={};$(Pa,{jqCommand:()=>ph});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(`,
356
+ `),a=[];for(let u of o){let f=u.trim();f&&!f.startsWith("#")&&a.push(f)}let c=a.join("; ");return await n.exec(c,{env:s,cwd:n.cwd})}var Wa,kh,Nh,ts=A(()=>{"use strict";_();Wa={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).']},kh={name:"bash",async execute(t,e){if(I(t))return N(Wa);if(t[0]==="-c"&&t.length>=2){let s=t[1],i=t[2]||"bash",o=t.slice(3);return Tr(s,i,o,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 Tr(i,r,n,e)}catch{return{stdout:"",stderr:`bash: ${r}: No such file or directory
357
+ `,exitCode:127}}}},Nh={name:"sh",async execute(t,e){if(I(t))return N({...Wa,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",o=t.slice(3);return Tr(s,i,o,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 Tr(i,r,n,e)}catch{return{stdout:"",stderr:`sh: ${r}: No such file or directory
358
+ `,exitCode:127}}}}});function vh(t){return{vars:new Map,limits:{maxIterations:t?.maxIterations??Ih}}}function rs(t,e,r){let n=new Map(t.vars);return n.set(e,r),{vars:n,limits:t.limits}}function k(t,e,r){let n=r&&"vars"in r?r:vh(r?.limits);switch(e.type){case"Identity":return[t];case"Field":return(e.base?k(t,e.base,n):[t]).flatMap(i=>i&&typeof i=="object"&&!Array.isArray(i)?[i[e.name]]:[null]);case"Index":return(e.base?k(t,e.base,n):[t]).flatMap(i=>k(i,e.index,n).flatMap(a=>{if(typeof a=="number"&&Array.isArray(i)){let c=a<0?i.length+a:a;return c>=0&&c<i.length?[i[c]]:[null]}return typeof a=="string"&&i&&typeof i=="object"&&!Array.isArray(i)?[i[a]]:[null]}));case"Slice":return(e.base?k(t,e.base,n):[t]).flatMap(i=>{if(!Array.isArray(i)&&typeof i!="string")return[null];let o=i.length,a=e.start?k(t,e.start,n):[0],c=e.end?k(t,e.end,n):[o];return a.flatMap(l=>c.map(u=>{let f=Ua(l,o),p=Ua(u,o);return Array.isArray(i),i.slice(f,p)}))});case"Iterate":return(e.base?k(t,e.base,n):[t]).flatMap(i=>Array.isArray(i)?i:i&&typeof i=="object"?Object.values(i):[]);case"Pipe":return k(t,e.left,n).flatMap(i=>k(i,e.right,n));case"Comma":{let s=k(t,e.left,n),i=k(t,e.right,n);return[...s,...i]}case"Literal":return[e.value];case"Array":return e.elements?[k(t,e.elements,n)]:[[]];case"Object":{let s=[{}];for(let i of e.entries){let o=typeof i.key=="string"?[i.key]:k(t,i.key,n),a=k(t,i.value,n),c=[];for(let l of s)for(let u of o)for(let f of a)c.push({...l,[String(u)]:f});s.length=0,s.push(...c)}return s}case"Paren":return k(t,e.expr,n);case"BinaryOp":return Oh(t,e.op,e.left,e.right,n);case"UnaryOp":return k(t,e.operand,n).map(i=>e.op==="-"?typeof i=="number"?-i:null:e.op==="not"?!ge(i):null);case"Cond":return k(t,e.cond,n).flatMap(i=>{if(ge(i))return k(t,e.then,n);for(let o of e.elifs)if(k(t,o.cond,n).some(ge))return k(t,o.then,n);return e.else?k(t,e.else,n):[null]});case"Try":try{return k(t,e.body,n)}catch{return e.catch?k(t,e.catch,n):[]}case"Call":return ja(t,e.name,e.args,n);case"VarBind":return k(t,e.value,n).flatMap(i=>{let o=rs(n,e.name,i);return k(t,e.body,o)});case"VarRef":{let s=n.vars.get(e.name);return s!==void 0?[s]:[null]}case"Recurse":{let s=[],i=new WeakSet,o=a=>{if(a&&typeof a=="object"){if(i.has(a))return;i.add(a)}if(s.push(a),Array.isArray(a))for(let c of a)o(c);else if(a&&typeof a=="object")for(let c of Object.keys(a))o(a[c])};return o(t),s}case"Optional":try{return k(t,e.expr,n)}catch{return[]}case"StringInterp":return[e.parts.map(i=>typeof i=="string"?i:k(t,i,n).map(a=>typeof a=="string"?a:JSON.stringify(a)).join("")).join("")];case"UpdateOp":return[Rh(t,e.path,e.op,e.value,n)];case"Reduce":{let s=k(t,e.expr,n),i=k(t,e.init,n)[0];for(let o of s){let a=rs(n,e.varName,o);i=k(i,e.update,a)[0]}return[i]}case"Foreach":{let s=k(t,e.expr,n),i=k(t,e.init,n)[0],o=[];for(let a of s){let c=rs(n,e.varName,a);if(i=k(i,e.update,c)[0],e.extract){let l=k(i,e.extract,c);o.push(...l)}else o.push(i)}return o}default:{let s=e;throw new Error(`Unknown AST node type: ${s.type}`)}}}function Ua(t,e){return t<0?Math.max(0,e+t):Math.min(t,e)}function Rh(t,e,r,n,s){function i(c,l){switch(r){case"=":return l;case"|=":return k(c,n,s)[0]??null;case"+=":return typeof c=="number"&&typeof l=="number"||typeof c=="string"&&typeof l=="string"?c+l:Array.isArray(c)&&Array.isArray(l)?[...c,...l]:c&&l&&typeof c=="object"&&typeof l=="object"?{...c,...l}:l;case"-=":return typeof c=="number"&&typeof l=="number"?c-l:c;case"*=":return typeof c=="number"&&typeof l=="number"?c*l:c;case"/=":return typeof c=="number"&&typeof l=="number"?c/l:c;case"%=":return typeof c=="number"&&typeof l=="number"?c%l:c;case"//=":return c===null||c===!1?l:c;default:return l}}function o(c,l,u){switch(l.type){case"Identity":return u(c);case"Field":{if(l.base)return o(c,l.base,f=>{if(f&&typeof f=="object"&&!Array.isArray(f)){let p={...f};return p[l.name]=u(p[l.name]),p}return f});if(c&&typeof c=="object"&&!Array.isArray(c)){let f={...c};return f[l.name]=u(f[l.name]),f}return c}case"Index":{let p=k(t,l.index,s)[0];if(l.base)return o(c,l.base,d=>{if(typeof p=="number"&&Array.isArray(d)){let h=[...d],g=p<0?h.length+p:p;return g>=0&&g<h.length&&(h[g]=u(h[g])),h}if(typeof p=="string"&&d&&typeof d=="object"&&!Array.isArray(d)){let h={...d};return h[p]=u(h[p]),h}return d});if(typeof p=="number"&&Array.isArray(c)){let d=[...c],h=p<0?d.length+p:p;return h>=0&&h<d.length&&(d[h]=u(d[h])),d}if(typeof p=="string"&&c&&typeof c=="object"&&!Array.isArray(c)){let d={...c};return d[p]=u(d[p]),d}return c}case"Iterate":{let f=p=>{if(Array.isArray(p))return p.map(d=>u(d));if(p&&typeof p=="object"){let d={};for(let[h,g]of Object.entries(p))d[h]=u(g);return d}return p};return l.base?o(c,l.base,f):f(c)}case"Pipe":{let f=o(c,l.left,p=>p);return o(f,l.right,u)}default:return u(c)}}return o(t,e,c=>{if(r==="|=")return i(c,c);let l=k(t,n,s);return i(c,l[0]??null)})}function $h(t,e,r){function n(s,i){switch(i.type){case"Identity":return null;case"Field":{if(s&&typeof s=="object"&&!Array.isArray(s)){let o={...s};return delete o[i.name],o}return s}case"Index":{let a=k(t,i.index,r)[0];if(typeof a=="number"&&Array.isArray(s)){let c=[...s],l=a<0?c.length+a:a;return l>=0&&l<c.length&&c.splice(l,1),c}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){let c={...s};return delete c[a],c}return s}case"Iterate":return Array.isArray(s)?[]:s&&typeof s=="object"?{}:s;default:return s}}return n(t,e)}function ge(t){return t!==null&&t!==!1}function Oh(t,e,r,n,s){if(e==="and")return k(t,r,s).flatMap(c=>ge(c)?k(t,n,s).map(u=>ge(u)):[!1]);if(e==="or")return k(t,r,s).flatMap(c=>ge(c)?[!0]:k(t,n,s).map(u=>ge(u)));if(e==="//"){let c=k(t,r,s).filter(l=>l!=null&&l!==!1);return c.length>0?c:k(t,n,s)}let i=k(t,r,s),o=k(t,n,s);return i.flatMap(a=>o.map(c=>{switch(e){case"+":return typeof a=="number"&&typeof c=="number"||typeof a=="string"&&typeof c=="string"?a+c:Array.isArray(a)&&Array.isArray(c)?[...a,...c]:a&&c&&typeof a=="object"&&typeof c=="object"&&!Array.isArray(a)&&!Array.isArray(c)?{...a,...c}:null;case"-":if(typeof a=="number"&&typeof c=="number")return a-c;if(Array.isArray(a)&&Array.isArray(c)){let l=new Set(c.map(u=>JSON.stringify(u)));return a.filter(u=>!l.has(JSON.stringify(u)))}return null;case"*":return typeof a=="number"&&typeof c=="number"?a*c:typeof a=="string"&&typeof c=="number"?a.repeat(c):a&&c&&typeof a=="object"&&typeof c=="object"&&!Array.isArray(a)&&!Array.isArray(c)?Ha(a,c):null;case"/":return typeof a=="number"&&typeof c=="number"?a/c:typeof a=="string"&&typeof c=="string"?a.split(c):null;case"%":return typeof a=="number"&&typeof c=="number"?a%c:null;case"==":return Pt(a,c);case"!=":return!Pt(a,c);case"<":return Fr(a,c)<0;case"<=":return Fr(a,c)<=0;case">":return Fr(a,c)>0;case">=":return Fr(a,c)>=0;default:return null}}))}function Pt(t,e){return JSON.stringify(t)===JSON.stringify(e)}function Fr(t,e){return typeof t=="number"&&typeof e=="number"?t-e:typeof t=="string"&&typeof e=="string"?t.localeCompare(e):0}function Ha(t,e){let r={...t};for(let n of Object.keys(e))n in r&&r[n]&&typeof r[n]=="object"&&!Array.isArray(r[n])&&e[n]&&typeof e[n]=="object"&&!Array.isArray(e[n])?r[n]=Ha(r[n],e[n]):r[n]=e[n];return r}function ja(t,e,r,n){switch(e){case"keys":return Array.isArray(t)?[t.map((s,i)=>i)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((s,i)=>i)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"values":return Array.isArray(t)?[t]:t&&typeof t=="object"?[Object.values(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:[null];case"utf8bytelength":return typeof t=="string"?[new TextEncoder().encode(t).length]:[null];case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"empty":return[];case"error":{let s=r.length>0?k(t,r[0],n)[0]:t;throw new Error(String(s))}case"not":return[!ge(t)];case"null":return[null];case"true":return[!0];case"false":return[!1];case"first":if(r.length>0){let s=k(t,r[0],n);return s.length>0?[s[0]]:[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(r.length>0){let s=k(t,r[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(r.length<1)return[null];let i=k(t,r[0],n)[0];if(r.length>1){let o=k(t,r[1],n);return i>=0&&i<o.length?[o[i]]:[]}return Array.isArray(t)?i>=0&&i<t.length?[t[i]]:[null]:[null]}case"range":{if(r.length===0)return[];let s=k(t,r[0],n);if(r.length===1){let l=s[0];return Array.from({length:l},(u,f)=>f)}let i=k(t,r[1],n),o=s[0],a=i[0],c=[];for(let l=o;l<a;l++)c.push(l);return c}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"sort":return Array.isArray(t)?[[...t].sort(pt)]:[null];case"sort_by":return!Array.isArray(t)||r.length===0?[null]:[[...t].sort((i,o)=>{let a=k(i,r[0],n)[0],c=k(o,r[0],n)[0];return pt(a,c)})];case"unique":if(Array.isArray(t)){let s=new Set,i=[];for(let o of t){let a=JSON.stringify(o);s.has(a)||(s.add(a),i.push(o))}return[i]}return[null];case"unique_by":{if(!Array.isArray(t)||r.length===0)return[null];let s=new Set,i=[];for(let o of t){let a=JSON.stringify(k(o,r[0],n)[0]);s.has(a)||(s.add(a),i.push(o))}return[i]}case"group_by":{if(!Array.isArray(t)||r.length===0)return[null];let s=new Map;for(let i of t){let o=JSON.stringify(k(i,r[0],n)[0]);s.has(o)||s.set(o,[]),s.get(o)?.push(i)}return[[...s.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((s,i)=>pt(s,i)>0?s:i)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||r.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,r[0],n)[0],a=k(i,r[0],n)[0];return pt(o,a)>0?s:i})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((s,i)=>pt(s,i)<0?s:i)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||r.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,r[0],n)[0],a=k(i,r[0],n)[0];return pt(o,a)<0?s:i})];case"flatten":{if(!Array.isArray(t))return[null];let s=r.length>0?k(t,r[0],n)[0]:Number.POSITIVE_INFINITY;return[t.flat(s)]}case"add":if(Array.isArray(t)){if(t.length===0)return[null];if(t.every(s=>typeof s=="number"))return[t.reduce((s,i)=>s+i,0)];if(t.every(s=>typeof s=="string"))return[t.join("")];if(t.every(s=>Array.isArray(s)))return[t.flat()];if(t.every(s=>s&&typeof s=="object"&&!Array.isArray(s)))return[Object.assign({},...t)]}return[null];case"any":return r.length>0?Array.isArray(t)?[t.some(s=>ge(k(s,r[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(ge)]:[!1];case"all":return r.length>0?Array.isArray(t)?[t.every(s=>ge(k(s,r[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(ge)]:[!0];case"select":return r.length===0?[t]:k(t,r[0],n).some(ge)?[t]:[];case"map":return r.length===0||!Array.isArray(t)?[null]:[t.flatMap(i=>k(i,r[0],n))];case"map_values":{if(r.length===0)return[null];if(Array.isArray(t))return[t.flatMap(s=>k(s,r[0],n))];if(t&&typeof t=="object"){let s={};for(let[i,o]of Object.entries(t)){let a=k(o,r[0],n);a.length>0&&(s[i]=a[0])}return[s]}return[null]}case"has":{if(r.length===0)return[!1];let i=k(t,r[0],n)[0];return Array.isArray(t)&&typeof i=="number"?[i>=0&&i<t.length]:t&&typeof t=="object"&&typeof i=="string"?[i in t]:[!1]}case"in":{if(r.length===0)return[!1];let i=k(t,r[0],n)[0];return Array.isArray(i)&&typeof t=="number"?[t>=0&&t<i.length]:i&&typeof i=="object"&&typeof t=="string"?[t in i]:[!1]}case"contains":{if(r.length===0)return[!1];let s=k(t,r[0],n);return[Dr(t,s[0])]}case"inside":{if(r.length===0)return[!1];let s=k(t,r[0],n);return[Dr(s[0],t)]}case"getpath":{if(r.length===0)return[null];let i=k(t,r[0],n)[0],o=t;for(let a of i){if(o==null)return[null];if(Array.isArray(o)&&typeof a=="number")o=o[a];else if(typeof o=="object"&&typeof a=="string")o=o[a];else return[null]}return[o]}case"setpath":{if(r.length<2)return[null];let i=k(t,r[0],n)[0],a=k(t,r[1],n)[0];return[ns(t,i,a)]}case"delpaths":{if(r.length===0)return[t];let i=k(t,r[0],n)[0],o=t;for(let a of i.sort((c,l)=>l.length-c.length))o=ss(o,a);return[o]}case"path":{if(r.length===0)return[[]];let s=[];return Ph(t,r[0],n,[],s),s}case"del":return r.length===0?[t]:[$h(t,r[0],n)];case"paths":{let s=[],i=(o,a)=>{if(o&&typeof o=="object")if(Array.isArray(o))for(let c=0;c<o.length;c++)s.push([...a,c]),i(o[c],[...a,c]);else for(let c of Object.keys(o))s.push([...a,c]),i(o[c],[...a,c])};return i(t,[]),r.length>0?s.filter(o=>{let a=t;for(let l of o)if(Array.isArray(a)&&typeof l=="number")a=a[l];else if(a&&typeof a=="object"&&typeof l=="string")a=a[l];else return!1;return k(a,r[0],n).some(ge)}):s}case"leaf_paths":{let s=[],i=(o,a)=>{if(o===null||typeof o!="object")s.push(a);else if(Array.isArray(o))for(let c=0;c<o.length;c++)i(o[c],[...a,c]);else for(let c of Object.keys(o))i(o[c],[...a,c])};return i(t,[]),[s]}case"to_entries":return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([s,i])=>({key:s,value:i}))]:[null];case"from_entries":if(Array.isArray(t)){let s={};for(let i of t)if(i&&typeof i=="object"){let o=i,a=o.key??o.name??o.k,c=o.value??o.v;a!==void 0&&(s[String(a)]=c)}return[s]}return[null];case"with_entries":{if(r.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let i=Object.entries(t).map(([a,c])=>({key:a,value:c})).flatMap(a=>k(a,r[0],n)),o={};for(let a of i)if(a&&typeof a=="object"){let c=a,l=c.key??c.name??c.k,u=c.value??c.v;l!==void 0&&(o[String(l)]=u)}return[o]}return[null]}case"join":{if(!Array.isArray(t))return[null];let s=r.length>0?k(t,r[0],n):[""],i=String(s[0]);return[t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(i)]}case"split":{if(typeof t!="string"||r.length===0)return[null];let s=k(t,r[0],n),i=String(s[0]);return[t.split(i)]}case"test":{if(typeof t!="string"||r.length===0)return[!1];let s=k(t,r[0],n),i=String(s[0]);try{let o=r.length>1?String(k(t,r[1],n)[0]):"";return[new RegExp(i,o).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||r.length===0)return[null];let s=k(t,r[0],n),i=String(s[0]);try{let o=r.length>1?String(k(t,r[1],n)[0]):"",c=new RegExp(i,`${o}d`).exec(t);if(!c)return[];let l=c.indices;return[{offset:c.index,length:c[0].length,string:c[0],captures:c.slice(1).map((u,f)=>({offset:l?.[f+1]?.[0]??null,length:u?.length??0,string:u??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||r.length===0)return[null];let s=k(t,r[0],n),i=String(s[0]);try{let o=r.length>1?String(k(t,r[1],n)[0]):"",a=new RegExp(i,o),c=t.match(a);return!c||!c.groups?[{}]:[c.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||r.length<2)return[null];let s=k(t,r[0],n),i=k(t,r[1],n),o=String(s[0]),a=String(i[0]);try{let c=r.length>2?String(k(t,r[2],n)[0]):"";return[t.replace(new RegExp(o,c),a)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||r.length<2)return[null];let s=k(t,r[0],n),i=k(t,r[1],n),o=String(s[0]),a=String(i[0]);try{let c=r.length>2?String(k(t,r[2],n)[0]):"g",l=c.includes("g")?c:`${c}g`;return[t.replace(new RegExp(o,l),a)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.toLowerCase()]:[null];case"ascii_upcase":return typeof t=="string"?[t.toUpperCase()]:[null];case"ltrimstr":{if(typeof t!="string"||r.length===0)return[t];let s=k(t,r[0],n),i=String(s[0]);return[t.startsWith(i)?t.slice(i.length):t]}case"rtrimstr":{if(typeof t!="string"||r.length===0)return[t];let s=k(t,r[0],n),i=String(s[0]);return[t.endsWith(i)?t.slice(0,-i.length):t]}case"startswith":{if(typeof t!="string"||r.length===0)return[!1];let s=k(t,r[0],n);return[t.startsWith(String(s[0]))]}case"endswith":{if(typeof t!="string"||r.length===0)return[!1];let s=k(t,r[0],n);return[t.endsWith(String(s[0]))]}case"index":{if(r.length===0)return[null];let i=k(t,r[0],n)[0];if(typeof t=="string"&&typeof i=="string"){let o=t.indexOf(i);return[o>=0?o:null]}if(Array.isArray(t)){let o=t.findIndex(a=>Pt(a,i));return[o>=0?o:null]}return[null]}case"rindex":{if(r.length===0)return[null];let i=k(t,r[0],n)[0];if(typeof t=="string"&&typeof i=="string"){let o=t.lastIndexOf(i);return[o>=0?o:null]}if(Array.isArray(t)){for(let o=t.length-1;o>=0;o--)if(Pt(t[o],i))return[o];return[null]}return[null]}case"indices":{if(r.length===0)return[[]];let i=k(t,r[0],n)[0],o=[];if(typeof t=="string"&&typeof i=="string"){let a=t.indexOf(i);for(;a!==-1;)o.push(a),a=t.indexOf(i,a+1)}else if(Array.isArray(t))for(let a=0;a<t.length;a++)Pt(t[a],i)&&o.push(a);return[o]}case"floor":return typeof t=="number"?[Math.floor(t)]:[null];case"ceil":return typeof t=="number"?[Math.ceil(t)]:[null];case"round":return typeof t=="number"?[Math.round(t)]:[null];case"sqrt":return typeof t=="number"?[Math.sqrt(t)]:[null];case"fabs":case"abs":return typeof t=="number"?[Math.abs(t)]:[null];case"log":return typeof t=="number"?[Math.log(t)]:[null];case"log10":return typeof t=="number"?[Math.log10(t)]:[null];case"log2":return typeof t=="number"?[Math.log2(t)]:[null];case"exp":return typeof t=="number"?[Math.exp(t)]:[null];case"exp10":return typeof t=="number"?[10**t]:[null];case"exp2":return typeof t=="number"?[2**t]:[null];case"pow":{if(typeof t!="number"||r.length===0)return[null];let i=k(t,r[0],n)[0];return[t**i]}case"sin":return typeof t=="number"?[Math.sin(t)]:[null];case"cos":return typeof t=="number"?[Math.cos(t)]:[null];case"tan":return typeof t=="number"?[Math.tan(t)]:[null];case"asin":return typeof t=="number"?[Math.asin(t)]:[null];case"acos":return typeof t=="number"?[Math.acos(t)]:[null];case"atan":return typeof t=="number"?[Math.atan(t)]:[null];case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let s=Number(t);return[Number.isNaN(s)?null:s]}return[null];case"infinite":return[!Number.isFinite(t)];case"nan":return[Number.isNaN(t)];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"now":return[Date.now()/1e3];case"env":return[{}];case"recurse":{if(r.length===0){let a=[],c=l=>{if(a.push(l),Array.isArray(l))for(let u of l)c(u);else if(l&&typeof l=="object")for(let u of Object.keys(l))c(l[u])};return c(t),a}let s=[],i=new Set,o=a=>{let c=JSON.stringify(a);if(i.has(c))return;i.add(c),s.push(a);let l=k(a,r[0],n);for(let u of l)u!=null&&o(u)};return o(t),s}case"recurse_down":return ja(t,"recurse",r,n);case"walk":{if(r.length===0)return[t];let s=new WeakSet,i=o=>{if(o&&typeof o=="object"){if(s.has(o))return o;s.add(o)}let a;if(Array.isArray(o))a=o.map(i);else if(o&&typeof o=="object"){let l={};for(let[u,f]of Object.entries(o))l[u]=i(f);a=l}else a=o;return k(a,r[0],n)[0]};return[i(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(o=>Array.isArray(o)?o.length:0)),i=[];for(let o=0;o<s;o++)i.push(t.map(a=>Array.isArray(a)?a[o]:null));return[i]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(s=>s.codePointAt(0))]:[null];case"implode":return Array.isArray(t)?[String.fromCodePoint(...t)]:[null];case"tojson":case"tojsonstream":return[JSON.stringify(t)];case"fromjson":{if(typeof t=="string")try{return[JSON.parse(t)]}catch{return[null]}return[null]}case"limit":{if(r.length<2)return[];let i=k(t,r[0],n)[0];return k(t,r[1],n).slice(0,i)}case"until":{if(r.length<2)return[t];let s=t,i=n.limits.maxIterations;for(let o=0;o<i;o++){if(k(s,r[0],n).some(ge))return[s];let c=k(s,r[1],n);if(c.length===0)return[s];s=c[0]}throw new W(`jq until: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(r.length<2)return[t];let s=[],i=t,o=n.limits.maxIterations;for(let a=0;a<o&&k(i,r[0],n).some(ge);a++){s.push(i);let l=k(i,r[1],n);if(l.length===0)break;i=l[0]}if(s.length>=o)throw new W(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(r.length===0)return[t];let s=[],i=t,o=n.limits.maxIterations;for(let a=0;a<o;a++){s.push(i);let c=k(i,r[0],n);if(c.length===0)break;i=c[0]}if(s.length>=o)throw new W(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"debug":return[t];case"input_line_number":return[1];default:throw new Error(`Unknown function: ${e}`)}}function pt(t,e){let r=i=>i===null?0:typeof i=="boolean"?1:typeof i=="number"?2:typeof i=="string"?3:Array.isArray(i)?4:typeof i=="object"?5:6,n=r(t),s=r(e);if(n!==s)return n-s;if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t.localeCompare(e);if(typeof t=="boolean"&&typeof e=="boolean")return(t?1:0)-(e?1:0);if(Array.isArray(t)&&Array.isArray(e)){for(let i=0;i<Math.min(t.length,e.length);i++){let o=pt(t[i],e[i]);if(o!==0)return o}return t.length-e.length}return 0}function Dr(t,e){if(Pt(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return e.every(r=>t.some(n=>Dr(n,r)));if(t&&e&&typeof t=="object"&&typeof e=="object"&&!Array.isArray(t)&&!Array.isArray(e)){let r=t,n=e;return Object.keys(n).every(s=>s in r&&Dr(r[s],n[s]))}return!1}function ns(t,e,r){if(e.length===0)return r;let[n,...s]=e;if(typeof n=="number"){let o=Array.isArray(t)?[...t]:[];for(;o.length<=n;)o.push(null);return o[n]=ns(o[n],s,r),o}let i=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{};return i[n]=ns(i[n],s,r),i}function ss(t,e){if(e.length===0)return null;if(e.length===1){let s=e[0];if(Array.isArray(t)&&typeof s=="number"){let i=[...t];return i.splice(s,1),i}if(t&&typeof t=="object"&&!Array.isArray(t)){let i={...t};return delete i[String(s)],i}return t}let[r,...n]=e;if(Array.isArray(t)&&typeof r=="number"){let s=[...t];return s[r]=ss(s[r],n),s}if(t&&typeof t=="object"&&!Array.isArray(t)){let s={...t};return s[String(r)]=ss(s[String(r)],n),s}return t}function Ph(t,e,r,n,s){k(t,e,r).length>0&&s.push(n)}var Ih,za=A(()=>{"use strict";J();Ih=1e4});function Ga(t){let e=[],r=0,n=(l=0)=>t[r+l],s=()=>t[r++],i=()=>r>=t.length,o=l=>l>="0"&&l<="9",a=l=>l>="a"&&l<="z"||l>="A"&&l<="Z"||l==="_",c=l=>a(l)||o(l);for(;!i();){let l=r,u=s();if(!(u===" "||u===" "||u===`
359
+ `||u==="\r")){if(u==="#"){for(;!i()&&n()!==`
360
+ `;)s();continue}if(u==="."&&n()==="."){s(),e.push({type:"DOTDOT",pos:l});continue}if(u==="="&&n()==="="){s(),e.push({type:"EQ",pos:l});continue}if(u==="!"&&n()==="="){s(),e.push({type:"NE",pos:l});continue}if(u==="<"&&n()==="="){s(),e.push({type:"LE",pos:l});continue}if(u===">"&&n()==="="){s(),e.push({type:"GE",pos:l});continue}if(u==="/"&&n()==="/"){s(),n()==="="?(s(),e.push({type:"UPDATE_ALT",pos:l})):e.push({type:"ALT",pos:l});continue}if(u==="+"&&n()==="="){s(),e.push({type:"UPDATE_ADD",pos:l});continue}if(u==="-"&&n()==="="){s(),e.push({type:"UPDATE_SUB",pos:l});continue}if(u==="*"&&n()==="="){s(),e.push({type:"UPDATE_MUL",pos:l});continue}if(u==="/"&&n()==="="){s(),e.push({type:"UPDATE_DIV",pos:l});continue}if(u==="%"&&n()==="="){s(),e.push({type:"UPDATE_MOD",pos:l});continue}if(u==="="&&n()!=="="){e.push({type:"ASSIGN",pos:l});continue}if(u==="."){e.push({type:"DOT",pos:l});continue}if(u==="|"){n()==="="?(s(),e.push({type:"UPDATE_PIPE",pos:l})):e.push({type:"PIPE",pos:l});continue}if(u===","){e.push({type:"COMMA",pos:l});continue}if(u===":"){e.push({type:"COLON",pos:l});continue}if(u===";"){e.push({type:"SEMICOLON",pos:l});continue}if(u==="("){e.push({type:"LPAREN",pos:l});continue}if(u===")"){e.push({type:"RPAREN",pos:l});continue}if(u==="["){e.push({type:"LBRACKET",pos:l});continue}if(u==="]"){e.push({type:"RBRACKET",pos:l});continue}if(u==="{"){e.push({type:"LBRACE",pos:l});continue}if(u==="}"){e.push({type:"RBRACE",pos:l});continue}if(u==="?"){e.push({type:"QUESTION",pos:l});continue}if(u==="+"){e.push({type:"PLUS",pos:l});continue}if(u==="-"){if(o(n())){let f=u;for(;!i()&&(o(n())||n()===".");)f+=s();e.push({type:"NUMBER",value:Number(f),pos:l});continue}e.push({type:"MINUS",pos:l});continue}if(u==="*"){e.push({type:"STAR",pos:l});continue}if(u==="/"){e.push({type:"SLASH",pos:l});continue}if(u==="%"){e.push({type:"PERCENT",pos:l});continue}if(u==="<"){e.push({type:"LT",pos:l});continue}if(u===">"){e.push({type:"GT",pos:l});continue}if(o(u)){let f=u;for(;!i()&&(o(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[r+1]==="+"||t[r+1]==="-")&&(f+=s()),f+=s();e.push({type:"NUMBER",value:Number(f),pos:l});continue}if(u==='"'){let f="";for(;!i()&&n()!=='"';)if(n()==="\\"){if(s(),i())break;let p=s();switch(p){case"n":f+=`
361
+ `;break;case"r":f+="\r";break;case"t":f+=" ";break;case"\\":f+="\\";break;case'"':f+='"';break;case"(":f+="\\(";break;default:f+=p}}else f+=s();i()||s(),e.push({type:"STRING",value:f,pos:l});continue}if(a(u)||u==="$"||u==="@"){let f=u;for(;!i()&&c(n());)f+=s();let p=Th[f];p?e.push({type:p,pos:l}):e.push({type:"IDENT",value:f,pos:l});continue}throw new Error(`Unexpected character '${u}' at position ${l}`)}}return e.push({type:"EOF",pos:r}),e}function qa(t){let e=Ga(t);return new is(e).parse()}var Th,is,Va=A(()=>{"use strict";Th={and:"AND",or:"OR",not:"NOT",if:"IF",then:"THEN",elif:"ELIF",else:"ELSE",end:"END",as:"AS",try:"TRY",catch:"CATCH",true:"TRUE",false:"FALSE",null:"NULL",reduce:"REDUCE",foreach:"FOREACH"};is=class t{tokens;pos=0;constructor(e){this.tokens=e}peek(e=0){return this.tokens[this.pos+e]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(e){return this.peek().type===e}match(...e){for(let r of e)if(this.check(r))return this.advance();return null}expect(e,r){if(!this.check(e))throw new Error(`${r} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}parse(){let e=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return e}parseExpr(){return this.parsePipe()}parsePipe(){let e=this.parseComma();for(;this.match("PIPE");){let r=this.parseComma();e={type:"Pipe",left:e,right:r}}return e}parseComma(){let e=this.parseVarBind();for(;this.match("COMMA");){let r=this.parseVarBind();e={type:"Comma",left:e,right:r}}return e}parseVarBind(){let e=this.parseUpdate();if(this.match("AS")){let r=this.expect("IDENT","Expected variable name after 'as'"),n=r.value;if(!n.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after variable binding");let s=this.parseExpr();return{type:"VarBind",name:n,value:e,body:s}}return e}parseUpdate(){let e=this.parseAlt(),r={ASSIGN:"=",UPDATE_ADD:"+=",UPDATE_SUB:"-=",UPDATE_MUL:"*=",UPDATE_DIV:"/=",UPDATE_MOD:"%=",UPDATE_ALT:"//=",UPDATE_PIPE:"|="},n=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(n){let s=this.parseVarBind();return{type:"UpdateOp",op:r[n.type],path:e,value:s}}return e}parseAlt(){let e=this.parseOr();for(;this.match("ALT");){let r=this.parseOr();e={type:"BinaryOp",op:"//",left:e,right:r}}return e}parseOr(){let e=this.parseAnd();for(;this.match("OR");){let r=this.parseAnd();e={type:"BinaryOp",op:"or",left:e,right:r}}return e}parseAnd(){let e=this.parseNot();for(;this.match("AND");){let r=this.parseNot();e={type:"BinaryOp",op:"and",left:e,right:r}}return e}parseNot(){return this.parseComparison()}parseComparison(){let e=this.parseAddSub(),r={EQ:"==",NE:"!=",LT:"<",LE:"<=",GT:">",GE:">="},n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let s=this.parseAddSub();e={type:"BinaryOp",op:r[n.type],left:e,right:s}}return e}parseAddSub(){let e=this.parseMulDiv();for(;;)if(this.match("PLUS")){let r=this.parseMulDiv();e={type:"BinaryOp",op:"+",left:e,right:r}}else if(this.match("MINUS")){let r=this.parseMulDiv();e={type:"BinaryOp",op:"-",left:e,right:r}}else break;return e}parseMulDiv(){let e=this.parseUnary();for(;;)if(this.match("STAR")){let r=this.parseUnary();e={type:"BinaryOp",op:"*",left:e,right:r}}else if(this.match("SLASH")){let r=this.parseUnary();e={type:"BinaryOp",op:"/",left:e,right:r}}else if(this.match("PERCENT")){let r=this.parseUnary();e={type:"BinaryOp",op:"%",left:e,right:r}}else break;return e}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("QUESTION"))e={type:"Optional",expr:e};else if(this.check("DOT")&&this.peek(1).type==="IDENT")this.advance(),e={type:"Field",name:this.expect("IDENT","Expected field name").value,base:e};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))e={type:"Iterate",base:e};else if(this.check("COLON")){this.advance();let r=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",end:r,base:e}}else{let r=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",start:r,end:n,base:e}}else this.expect("RBRACKET","Expected ']'"),e={type:"Index",index:r,base:e}}else break;return e}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.match("DOT")){if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let r=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:r}}let e=this.parseExpr();if(this.match("COLON")){let r=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:e,end:r}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:e}}return this.check("IDENT")?{type:"Field",name:this.advance().value}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let r=this.advance().value;return r.includes("\\(")?this.parseStringInterpolation(r):{type:"Literal",value:r}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let e=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:e}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let e=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:e}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let e=this.parsePostfix(),r;return this.match("CATCH")&&(r=this.parsePostfix()),{type:"Try",body:e,catch:r}}if(this.match("REDUCE")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after reduce expression");let r=this.expect("IDENT","Expected variable name"),n=r.value;if(!n.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);this.expect("LPAREN","Expected '(' after variable");let s=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let i=this.parseExpr();return this.expect("RPAREN","Expected ')' after update expression"),{type:"Reduce",expr:e,varName:n,init:s,update:i}}if(this.match("FOREACH")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after foreach expression");let r=this.expect("IDENT","Expected variable name"),n=r.value;if(!n.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);this.expect("LPAREN","Expected '(' after variable");let s=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let i=this.parseExpr(),o;return this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions"),{type:"Foreach",expr:e,varName:n,init:s,update:i,extract:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let r=this.advance().value;if(r.startsWith("$"))return{type:"VarRef",name:r};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:r,args:n}}return{type:"Call",name:r,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let e=[];if(!this.check("RBRACE"))do{let r,n;if(this.match("LPAREN"))r=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.check("IDENT")){let s=this.advance().value;this.match("COLON")?(r=s,n=this.parseObjectValue()):(r=s,n={type:"Field",name:s})}else if(this.check("STRING"))r=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);e.push({key:r,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:e}}parseObjectValue(){let e=this.parseVarBind();for(;this.match("PIPE");){let r=this.parseVarBind();e={type:"Pipe",left:e,right:r}}return e}parseIf(){let e=this.parseExpr();this.expect("THEN","Expected 'then'");let r=this.parseExpr(),n=[];for(;this.match("ELIF");){let i=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let o=this.parseExpr();n.push({cond:i,then:o})}let s;return this.match("ELSE")&&(s=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:e,then:r,elifs:n,else:s}}parseStringInterpolation(e){let r=[],n="",s=0;for(;s<e.length;)if(e[s]==="\\"&&e[s+1]==="("){n&&(r.push(n),n=""),s+=2;let i=1,o="";for(;s<e.length&&i>0;)e[s]==="("?i++:e[s]===")"&&i--,i>0&&(o+=e[s]),s++;let a=Ga(o),c=new t(a);r.push(c.parse())}else n+=e[s],s++;return n&&r.push(n),{type:"StringInterp",parts:r}}}});var Ka={};$(Ka,{jqCommand:()=>Dh});function Xt(t,e,r,n,s,i=0){if(t===null||t===void 0)return"null";if(typeof t=="boolean")return String(t);if(typeof t=="number")return Number.isFinite(t)?String(t):"null";if(typeof t=="string")return r?t:JSON.stringify(t);let o=s?" ":" ";if(Array.isArray(t))return t.length===0?"[]":e?`[${t.map(c=>Xt(c,!0,!1,n,s)).join(",")}]`:`[
362
+ ${t.map(c=>o.repeat(i+1)+Xt(c,!1,!1,n,s,i+1)).join(`,
360
363
  `)}
361
- ${" ".repeat(n)}]`;if(typeof t=="object"){let s=Object.keys(t);return s.length===0?"{}":e?`{${s.map(o=>`${JSON.stringify(o)}:${Zt(t[o],!0,!1)}`).join(",")}}`:`{
362
- ${s.map(o=>{let a=Zt(t[o],!1,!1,n+1);return`${" ".repeat(n+1)}${JSON.stringify(o)}: ${a}`}).join(`,
364
+ ${o.repeat(i)}]`;if(typeof t=="object"){let a=Object.keys(t);return n&&(a=a.sort()),a.length===0?"{}":e?`{${a.map(l=>`${JSON.stringify(l)}:${Xt(t[l],!0,!1,n,s)}`).join(",")}}`:`{
365
+ ${a.map(l=>{let u=Xt(t[l],!1,!1,n,s,i+1);return`${o.repeat(i+1)}${JSON.stringify(l)}: ${u}`}).join(`,
363
366
  `)}
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 o=r.slice(2);return Array.isArray(t)?t.flatMap(a=>et(a,`.${o}`)):t&&typeof t=="object"?Object.values(t).flatMap(a=>et(a,`.${o}`)):[]}let n=r.match(/^\[(-?\d+)\](.*)/);if(n){let o=Number.parseInt(n[1],10),a=n[2];if(Array.isArray(t)){let l=o<0?t.length+o:o;if(l>=0&&l<t.length)return et(t[l],`.${a}`)}return[null]}let s=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(s){let o=s[1],a=s[2];if(t&&typeof t=="object"&&!Array.isArray(t)){let c=t[o];if(a.startsWith("[]"))return a=a.slice(2),Array.isArray(c)?c.flatMap(u=>et(u,`.${a}`)):c&&typeof c=="object"?Object.values(c).flatMap(u=>et(u,`.${a}`)):[];if(a.startsWith(".")||a.startsWith("[")||a==="")return et(c,a||".")}return[null]}let i=r.match(/^\["([^"]+)"\](.*)/);if(i){let o=i[1],a=i[2];return t&&typeof t=="object"&&!Array.isArray(t)?et(t[o],`.${a}`):[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(o=>Qt(o,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,o=i.key??i.name??i.k,a=i.value??i.v;o!==void 0&&(n[String(o)]=a)}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,o)=>{if(i&&typeof i=="object")if(Array.isArray(i))for(let a=0;a<i.length;a++)n.push([...o,a]),s(i[a],[...o,a]);else for(let a of Object.keys(i))n.push([...o,a]),s(i[a],[...o,a])};return s(t,[]),[n]}if(r==="leaf_paths"){let n=[],s=(i,o)=>{if(i&&typeof i=="object")if(Array.isArray(i))if(i.length===0)n.push(o);else for(let a=0;a<i.length;a++)s(i[a],[...o,a]);else{let a=Object.keys(i);if(a.length===0)n.push(o);else for(let l of a)s(i[l],[...o,l])}else n.push(o)};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 o of i)s(o);else if(i&&typeof i=="object")for(let o of Object.keys(i))s(i[o])};return s(t),n}return et(t,r)}var dh,ph,Ta=C(()=>{"use strict";M();dh={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"]};ph={name:"jq",async execute(t,e){if(v(t))return k(dh);let r=!1,n=!1,s=!1,i=!1,o=!1,a=".",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")o=!0;else if(d==="-")c.push("-");else{if(d.startsWith("--"))return T("jq",d);if(d.startsWith("-"))for(let p of d.slice(1))if(p==="r")r=!0;else if(p==="c")n=!0;else if(p==="e")s=!0;else if(p==="s")i=!0;else if(p==="n")o=!0;else return T("jq",`-${p}`);else l?c.push(d):(a=d,l=!0)}}let u;if(o)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(o)f=Qt(null,a);else if(i){let h=[];for(let w of u.trim().split(`
366
- `))w.trim()&&h.push(JSON.parse(w));f=Qt(h,a)}else{let h=u.trim();if(h.startsWith("{")||h.startsWith("["))f=Qt(JSON.parse(h),a);else{f=[];for(let w of h.split(`
367
- `))w.trim()&&f.push(...Qt(JSON.parse(w),a))}}let d=f.map(h=>Zt(h,n,r)).join(`
368
- `),p=s&&(f.length===0||f.every(h=>h==null||h===!1))?1:0;return{stdout:d?`${d}
369
- `:"",stderr:"",exitCode:p}}catch(f){return{stdout:"",stderr:`jq: parse error: ${f.message}
370
- `,exitCode:5}}}}});var La={};$(La,{base64Command:()=>gh});async function Da(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 a of e){if(a==="-"){n.push(new TextEncoder().encode(t.stdin));continue}try{let l=t.fs.resolvePath(t.cwd,a),c=await t.fs.readFileBuffer(l);n.push(c)}catch{return{ok:!1,error:{stdout:"",stderr:`${r}: ${a}: No such file or directory
371
- `,exitCode:1}}}}let s=n.reduce((a,l)=>a+l.length,0),i=new Uint8Array(s),o=0;for(let a of n)i.set(a,o),o+=a.length;return{ok:!0,data:i}}var hh,mh,gh,Ma=C(()=>{"use strict";ue();M();hh={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"]},mh={decode:{short:"d",long:"decode",type:"boolean"},wrap:{short:"w",long:"wrap",type:"number",default:76}};gh={name:"base64",async execute(t,e){if(v(t))return k(hh);let r=j("base64",t,mh);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 Da(e,i,"base64");if(!l.ok)return l.error;let u=new TextDecoder().decode(l.data).replace(/\s/g,""),f=Uint8Array.from(atob(u),p=>p.charCodeAt(0));return{stdout:new TextDecoder().decode(f),stderr:"",exitCode:0}}let o=await Da(e,i,"base64");if(!o.ok)return o.error;let a=btoa(String.fromCharCode(...o.data));if(s>0){let l=[];for(let c=0;c<a.length;c+=s)l.push(a.slice(c,c+s));a=l.join(`
367
+ ${o.repeat(i)}}`}return String(t)}var Fh,Dh,Za=A(()=>{"use strict";J();_();za();Va();Fh={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","-j, --join-output don't print newlines after each output","-a, --ascii force ASCII output","-S, --sort-keys sort object keys","-C, --color colorize output (ignored)","-M, --monochrome monochrome output (ignored)"," --tab use tabs for indentation"," --help display this help and exit"]};Dh={name:"jq",async execute(t,e){if(I(t))return N(Fh);let r=!1,n=!1,s=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=".",f=!1,p=[];for(let h=0;h<t.length;h++){let g=t[h];if(g==="-r"||g==="--raw-output")r=!0;else if(g==="-c"||g==="--compact-output")n=!0;else if(g==="-e"||g==="--exit-status")s=!0;else if(g==="-s"||g==="--slurp")i=!0;else if(g==="-n"||g==="--null-input")o=!0;else if(g==="-j"||g==="--join-output")a=!0;else if(!(g==="-a"||g==="--ascii")){if(g==="-S"||g==="--sort-keys")c=!0;else if(!(g==="-C"||g==="--color")){if(!(g==="-M"||g==="--monochrome"))if(g==="--tab")l=!0;else if(g==="-")p.push("-");else{if(g.startsWith("--"))return L("jq",g);if(g.startsWith("-")){for(let y of g.slice(1))if(y==="r")r=!0;else if(y==="c")n=!0;else if(y==="e")s=!0;else if(y==="s")i=!0;else if(y==="n")o=!0;else if(y==="j")a=!0;else if(y!=="a"){if(y==="S")c=!0;else if(y!=="C"){if(y!=="M")return L("jq",`-${y}`)}}}else f?p.push(g):(u=g,f=!0)}}}}let d;if(o)d="";else if(p.length===0||p.length===1&&p[0]==="-")d=e.stdin;else try{let h=e.fs.resolvePath(e.cwd,p[0]);d=await e.fs.readFile(h)}catch{return{stdout:"",stderr:`jq: ${p[0]}: No such file or directory
368
+ `,exitCode:2}}try{let h=qa(u),g,y={limits:e.limits?{maxIterations:e.limits.maxJqIterations}:void 0};if(o)g=k(null,h,y);else if(i){let C=[];for(let O of d.trim().split(`
369
+ `))O.trim()&&C.push(JSON.parse(O));g=k(C,h,y)}else{let C=d.trim();if(C.startsWith("{")||C.startsWith("["))g=k(JSON.parse(C),h,y);else{g=[];for(let O of C.split(`
370
+ `))O.trim()&&g.push(...k(JSON.parse(O),h,y))}}let w=g.map(C=>Xt(C,n,r,c,l)),E=a?"":`
371
+ `,b=w.join(E),S=s&&(g.length===0||g.every(C=>C==null||C===!1))?1:0;return{stdout:b?a?b:`${b}
372
+ `:"",stderr:"",exitCode:S}}catch(h){if(h instanceof W)return{stdout:"",stderr:`jq: ${h.message}
373
+ `,exitCode:W.EXIT_CODE};let g=h.message;return g.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${g}
374
+ `,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${g}
375
+ `,exitCode:5}}}}});var Xa={};$(Xa,{base64Command:()=>_h});async function Qa(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 a of e){if(a==="-"){n.push(new TextEncoder().encode(t.stdin));continue}try{let c=t.fs.resolvePath(t.cwd,a),l=await t.fs.readFileBuffer(c);n.push(l)}catch{return{ok:!1,error:{stdout:"",stderr:`${r}: ${a}: No such file or directory
376
+ `,exitCode:1}}}}let s=n.reduce((a,c)=>a+c.length,0),i=new Uint8Array(s),o=0;for(let a of n)i.set(a,o),o+=a.length;return{ok:!0,data:i}}var Lh,Mh,_h,Ja=A(()=>{"use strict";fe();_();Lh={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"]},Mh={decode:{short:"d",long:"decode",type:"boolean"},wrap:{short:"w",long:"wrap",type:"number",default:76}};_h={name:"base64",async execute(t,e){if(I(t))return N(Lh);let r=G("base64",t,Mh);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 c=await Qa(e,i,"base64");if(!c.ok)return c.error;let u=new TextDecoder().decode(c.data).replace(/\s/g,""),f=Uint8Array.from(atob(u),d=>d.charCodeAt(0));return{stdout:new TextDecoder().decode(f),stderr:"",exitCode:0}}let o=await Qa(e,i,"base64");if(!o.ok)return o.error;let a=btoa(String.fromCharCode(...o.data));if(s>0){let c=[];for(let l=0;l<a.length;l+=s)c.push(a.slice(l,l+s));a=c.join(`
372
377
  `)+(a.length>0?`
373
378
  `:"")}return{stdout:a,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`base64: invalid input
374
- `,exitCode:1}}}}});var Ba={};$(Ba,{diffCommand:()=>wh});import*as _a from"diff";var xh,yh,wh,Wa=C(()=>{"use strict";ue();M();xh={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"]},yh={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"}},wh={name:"diff",async execute(t,e){if(v(t))return k(xh);let r=j("diff",t,yh);if(!r.ok)return r.error;let n=r.result.flags.brief,s=r.result.flags.reportSame,i=r.result.flags.ignoreCase,o=r.result.positional;if(r.result.flags.unified,o.length<2)return{stdout:"",stderr:`diff: missing operand
375
- `,exitCode:2};let a,l,[c,u]=o;try{a=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=a,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:_a.createTwoFilesPatch(c,u,a,l,"","",{context:3}),stderr:"",exitCode:1}}}});var Ua={};$(Ua,{dateCommand:()=>kh});function ge(t,e=2){return String(t).padStart(e,"0")}function Ch(t){let e=-t.getTimezoneOffset();return`${e>=0?"+":"-"}${ge(Math.floor(Math.abs(e)/60))}${ge(Math.abs(e)%60)}`}function Fr(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 o=e[++i];switch(o){case"%":s+="%";break;case"a":s+=bh[n.w];break;case"b":case"h":s+=Sh[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":Ch(t);break;case"Z":s+=r?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone;break;default:s+=`%${o}`}}else s+=e[i];i++}return s}function Ah(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 Eh,bh,Sh,kh,Ha=C(()=>{"use strict";M();Eh={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"]},bh=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Sh=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];kh={name:"date",async execute(t,e){if(v(t))return k(Eh);let r=!1,n=null,s=null,i=!1,o=!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")o=!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")o=!0;else return T("date",`-${f}`)}}let a=n!==null?Ah(n):new Date;if(!a)return{stdout:"",stderr:`date: invalid date '${n}'
381
- `,exitCode:1};let l;return s?l=Fr(a,s,r):i?l=Fr(a,"%Y-%m-%dT%H:%M:%S%z",r):o?l=Fr(a,"%a, %d %b %Y %H:%M:%S %z",r):l=Fr(a,"%a %b %e %H:%M:%S %Z %Y",r),{stdout:`${l}
382
- `,stderr:"",exitCode:0}}}});var za={};$(za,{sleepCommand:()=>Ih});function Nh(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 vh,Ih,ja=C(()=>{"use strict";M();vh={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
379
+ `,exitCode:1}}}}});var ec={};$(ec,{diffCommand:()=>Uh});import*as Ya from"diff";var Bh,Wh,Uh,tc=A(()=>{"use strict";fe();_();Bh={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"]},Wh={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"}},Uh={name:"diff",async execute(t,e){if(I(t))return N(Bh);let r=G("diff",t,Wh);if(!r.ok)return r.error;let n=r.result.flags.brief,s=r.result.flags.reportSame,i=r.result.flags.ignoreCase,o=r.result.positional;if(r.result.flags.unified,o.length<2)return{stdout:"",stderr:`diff: missing operand
380
+ `,exitCode:2};let a,c,[l,u]=o;try{a=l==="-"?e.stdin:await e.fs.readFile(e.fs.resolvePath(e.cwd,l))}catch{return{stdout:"",stderr:`diff: ${l}: No such file or directory
381
+ `,exitCode:2}}try{c=u==="-"?e.stdin:await e.fs.readFile(e.fs.resolvePath(e.cwd,u))}catch{return{stdout:"",stderr:`diff: ${u}: No such file or directory
382
+ `,exitCode:2}}let f=a,p=c;return i&&(f=f.toLowerCase(),p=p.toLowerCase()),f===p?s?{stdout:`Files ${l} and ${u} are identical
383
+ `,stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0}:n?{stdout:`Files ${l} and ${u} differ
384
+ `,stderr:"",exitCode:1}:{stdout:Ya.createTwoFilesPatch(l,u,a,c,"","",{context:3}),stderr:"",exitCode:1}}}});var rc={};$(rc,{dateCommand:()=>Vh});function xe(t,e=2){return String(t).padStart(e,"0")}function Gh(t){let e=-t.getTimezoneOffset();return`${e>=0?"+":"-"}${xe(Math.floor(Math.abs(e)/60))}${xe(Math.abs(e)%60)}`}function Lr(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 o=e[++i];switch(o){case"%":s+="%";break;case"a":s+=jh[n.w];break;case"b":case"h":s+=zh[n.m];break;case"d":s+=xe(n.D);break;case"e":s+=String(n.D).padStart(2," ");break;case"F":s+=`${n.Y}-${xe(n.m+1)}-${xe(n.D)}`;break;case"H":s+=xe(n.H);break;case"I":s+=xe(n.H%12||12);break;case"m":s+=xe(n.m+1);break;case"M":s+=xe(n.M);break;case"n":s+=`
385
+ `;break;case"p":s+=n.H<12?"AM":"PM";break;case"P":s+=n.H<12?"am":"pm";break;case"R":s+=`${xe(n.H)}:${xe(n.M)}`;break;case"s":s+=Math.floor(t.getTime()/1e3);break;case"S":s+=xe(n.S);break;case"t":s+=" ";break;case"T":s+=`${xe(n.H)}:${xe(n.M)}:${xe(n.S)}`;break;case"u":s+=n.w||7;break;case"w":s+=n.w;break;case"y":s+=xe(n.Y%100);break;case"Y":s+=n.Y;break;case"z":s+=r?"+0000":Gh(t);break;case"Z":s+=r?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone;break;default:s+=`%${o}`}}else s+=e[i];i++}return s}function qh(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 Hh,jh,zh,Vh,nc=A(()=>{"use strict";_();Hh={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"]},jh=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],zh=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Vh={name:"date",async execute(t,e){if(I(t))return N(Hh);let r=!1,n=null,s=null,i=!1,o=!1;for(let l=0;l<t.length;l++){let u=t[l];if(u==="-u"||u==="--utc")r=!0;else if(u==="-d"||u==="--date")n=t[++l]??"";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")o=!0;else if(u.startsWith("+"))s=u.slice(1);else{if(u.startsWith("--"))return L("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")o=!0;else return L("date",`-${f}`)}}let a=n!==null?qh(n):new Date;if(!a)return{stdout:"",stderr:`date: invalid date '${n}'
386
+ `,exitCode:1};let c;return s?c=Lr(a,s,r):i?c=Lr(a,"%Y-%m-%dT%H:%M:%S%z",r):o?c=Lr(a,"%a, %d %b %Y %H:%M:%S %z",r):c=Lr(a,"%a %b %e %H:%M:%S %Z %Y",r),{stdout:`${c}
387
+ `,stderr:"",exitCode:0}}}});var sc={};$(sc,{sleepCommand:()=>Qh});function Zh(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 Kh,Qh,ic=A(()=>{"use strict";_();Kh={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
383
388
  s - seconds (default)
384
389
  m - minutes
385
390
  h - hours
386
391
  d - days
387
392
 
388
- NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};Ih={name:"sleep",async execute(t,e){if(v(t))return k(vh);if(t.length===0)return{stdout:"",stderr:`sleep: missing operand
389
- `,exitCode:1};let r=0;for(let n of t){let s=Nh(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 Ga={};$(Ga,{timeoutCommand:()=>Oh});function Rh(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 $h,Oh,qa=C(()=>{"use strict";M();$h={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.
393
+ NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};Qh={name:"sleep",async execute(t,e){if(I(t))return N(Kh);if(t.length===0)return{stdout:"",stderr:`sleep: missing operand
394
+ `,exitCode:1};let r=0;for(let n of t){let s=Zh(n);if(s===null)return{stdout:"",stderr:`sleep: invalid time interval '${n}'
395
+ `,exitCode:1};r+=s}return e.sleep?await e.sleep(r):await new Promise(n=>setTimeout(n,r)),{stdout:"",stderr:"",exitCode:0}}}});var oc={};$(oc,{timeoutCommand:()=>Yh});function Jh(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 Xh,Yh,ac=A(()=>{"use strict";_();Xh={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.
391
396
 
392
397
  DURATION is a number with optional suffix:
393
398
  s - seconds (default)
394
399
  m - minutes
395
400
  h - hours
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"]};Oh={name:"timeout",async execute(t,e){if(v(t))return k($h);let r=!1,n=0;for(let d=0;d<t.length;d++){let p=t[d];if(p==="--preserve-status")r=!0,n=d+1;else if(p==="--foreground")n=d+1;else if(p==="-k"||p==="--kill-after")d++,n=d+1;else if(p.startsWith("--kill-after="))n=d+1;else if(p==="-s"||p==="--signal")d++,n=d+1;else if(p.startsWith("--signal="))n=d+1;else{if(p.startsWith("--")&&p!=="--")return T("timeout",p);if(p.startsWith("-")&&p.length>1&&p!=="--")if(p.startsWith("-k"))n=d+1;else if(p.startsWith("-s"))n=d+1;else return T("timeout",p);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],o=Rh(i);if(o===null)return{stdout:"",stderr:`timeout: invalid time interval '${i}'
401
+ 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"]};Yh={name:"timeout",async execute(t,e){if(I(t))return N(Xh);let r=!1,n=0;for(let p=0;p<t.length;p++){let d=t[p];if(d==="--preserve-status")r=!0,n=p+1;else if(d==="--foreground")n=p+1;else if(d==="-k"||d==="--kill-after")p++,n=p+1;else if(d.startsWith("--kill-after="))n=p+1;else if(d==="-s"||d==="--signal")p++,n=p+1;else if(d.startsWith("--signal="))n=p+1;else{if(d.startsWith("--")&&d!=="--")return L("timeout",d);if(d.startsWith("-")&&d.length>1&&d!=="--")if(d.startsWith("-k"))n=p+1;else if(d.startsWith("-s"))n=p+1;else return L("timeout",d);else{n=p;break}}}let s=t.slice(n);if(s.length===0)return{stdout:"",stderr:`timeout: missing operand
402
+ `,exitCode:1};let i=s[0],o=Jh(i);if(o===null)return{stdout:"",stderr:`timeout: invalid time interval '${i}'
398
403
  `,exitCode:1};let a=s.slice(1);if(a.length===0)return{stdout:"",stderr:`timeout: missing operand
399
404
  `,exitCode:1};if(!e.exec)return{stdout:"",stderr:`timeout: exec not available
400
- `,exitCode:1};let l=a.map(d=>d.includes(" ")||d.includes(" ")?`'${d.replace(/'/g,"'\\''")}'`:d).join(" "),c=new Promise(d=>{setTimeout(()=>d({timedOut:!0}),o)}),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 Va={};$(Va,{seqCommand:()=>Fh});var Fh,Za=C(()=>{"use strict";Fh={name:"seq",async execute(t){let e=`
405
+ `,exitCode:1};let c=a.map(p=>p.includes(" ")||p.includes(" ")?`'${p.replace(/'/g,"'\\''")}'`:p).join(" "),l=new Promise(p=>{setTimeout(()=>p({timedOut:!0}),o)}),u=e.exec(c,{cwd:e.cwd}).then(p=>({timedOut:!1,result:p})),f=await Promise.race([l,u]);return f.timedOut?{stdout:"",stderr:"",exitCode:124}:f.result}}});var cc={};$(cc,{seqCommand:()=>em});var em,lc=A(()=>{"use strict";em={name:"seq",async execute(t){let e=`
401
406
  `,r=!1,n=[],s=0;for(;s<t.length;){let h=t[s];if(h==="-s"&&s+1<t.length){e=t[s+1],s+=2;continue}if(h==="-w"){r=!0,s++;continue}if(h==="--"){s++;break}if(h.startsWith("-")&&h!=="-"){if(h.startsWith("-s")&&h.length>2){e=h.slice(2),s++;continue}if((h==="-ws"||h==="-sw")&&(r=!0,s+1<t.length)){e=t[s+1],s+=2;continue}}n.push(h),s++}for(;s<t.length;)n.push(t[s]),s++;if(n.length===0)return{stdout:"",stderr:`seq: missing operand
402
- `,exitCode:1};let i=1,o=1,a;if(n.length===1?a=parseFloat(n[0]):n.length===2?(i=parseFloat(n[0]),a=parseFloat(n[1])):(i=parseFloat(n[0]),o=parseFloat(n[1]),a=parseFloat(n[2])),Number.isNaN(i)||Number.isNaN(o)||Number.isNaN(a))return{stdout:"",stderr:`seq: invalid floating point argument: '${n.find(w=>Number.isNaN(parseFloat(w)))}'
407
+ `,exitCode:1};let i=1,o=1,a;if(n.length===1?a=parseFloat(n[0]):n.length===2?(i=parseFloat(n[0]),a=parseFloat(n[1])):(i=parseFloat(n[0]),o=parseFloat(n[1]),a=parseFloat(n[2])),Number.isNaN(i)||Number.isNaN(o)||Number.isNaN(a))return{stdout:"",stderr:`seq: invalid floating point argument: '${n.find(g=>Number.isNaN(parseFloat(g)))}'
403
408
  `,exitCode:1};if(o===0)return{stdout:"",stderr:`seq: invalid Zero increment value: '0'
404
- `,exitCode:1};let l=[],c=h=>{let w=String(h),g=w.indexOf(".");return g===-1?0:w.length-g-1},u=Math.max(c(i),c(o),c(a)),f=1e5,d=0;if(o>0)for(let h=i;h<=a+1e-10&&!(d++>f);h+=o)l.push(u>0?h.toFixed(u):String(Math.round(h)));else for(let h=i;h>=a-1e-10&&!(d++>f);h+=o)l.push(u>0?h.toFixed(u):String(Math.round(h)));if(r&&l.length>0){let h=Math.max(...l.map(w=>w.replace("-","").length));for(let w=0;w<l.length;w++){let g=l[w].startsWith("-"),E=(g?l[w].slice(1):l[w]).padStart(h,"0");l[w]=g?`-${E}`:E}}let p=l.join(e);return{stdout:p?`${p}
405
- `:"",stderr:"",exitCode:0}}}});var Qa={};$(Qa,{exprCommand:()=>Ph});function Th(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),p=parseInt(f,10),h=!Number.isNaN(d)&&!Number.isNaN(p),w;u==="="?w=h?d===p:c===f:u==="!="?w=h?d!==p:c!==f:u==="<"?w=h?d<p:c<f:u===">"?w=h?d>p:c>f:u==="<="?w=h?d<=p:c<=f:w=h?d>=p:c>=f,c=w?"1":"0"}else break}return c}function i(){let c=o();for(;e<t.length;){let u=t[e];if(u==="+"||u==="-"){e++;let f=o(),d=parseInt(c,10),p=parseInt(f,10);if(Number.isNaN(d)||Number.isNaN(p))throw new Error("non-integer argument");c=String(u==="+"?d+p:d-p)}else break}return c}function o(){let c=a();for(;e<t.length;){let u=t[e];if(u==="*"||u==="/"||u==="%"){e++;let f=a(),d=parseInt(c,10),p=parseInt(f,10);if(Number.isNaN(d)||Number.isNaN(p))throw new Error("non-integer argument");if((u==="/"||u==="%")&&p===0)throw new Error("division by zero");u==="*"?c=String(d*p):u==="/"?c=String(Math.trunc(d/p)):c=String(d%p)}else break}return c}function a(){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),p=u.match(d);return p?p[1]!==void 0?p[1]:String(p[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 Ph,Xa=C(()=>{"use strict";Ph={name:"expr",async execute(t,e){if(t.length===0)return{stdout:"",stderr:`expr: missing operand
406
- `,exitCode:2};try{let r=Th(t),n=r==="0"||r===""?1:0;return{stdout:`${r}
409
+ `,exitCode:1};let c=[],l=h=>{let g=String(h),y=g.indexOf(".");return y===-1?0:g.length-y-1},u=Math.max(l(i),l(o),l(a)),f=1e5,p=0;if(o>0)for(let h=i;h<=a+1e-10&&!(p++>f);h+=o)c.push(u>0?h.toFixed(u):String(Math.round(h)));else for(let h=i;h>=a-1e-10&&!(p++>f);h+=o)c.push(u>0?h.toFixed(u):String(Math.round(h)));if(r&&c.length>0){let h=Math.max(...c.map(g=>g.replace("-","").length));for(let g=0;g<c.length;g++){let y=c[g].startsWith("-"),E=(y?c[g].slice(1):c[g]).padStart(h,"0");c[g]=y?`-${E}`:E}}let d=c.join(e);return{stdout:d?`${d}
410
+ `:"",stderr:"",exitCode:0}}}});var uc={};$(uc,{exprCommand:()=>tm});function rm(t){if(t.length===1)return t[0];let e=0;function r(){let l=n();for(;e<t.length&&t[e]==="|";){e++;let u=n();if(l!=="0"&&l!=="")return l;l=u}return l}function n(){let l=s();for(;e<t.length&&t[e]==="&";){e++;let u=s();(l==="0"||l===""||u==="0"||u==="")&&(l="0")}return l}function s(){let l=i();for(;e<t.length;){let u=t[e];if(["=","!=","<",">","<=",">="].includes(u)){e++;let f=i(),p=parseInt(l,10),d=parseInt(f,10),h=!Number.isNaN(p)&&!Number.isNaN(d),g;u==="="?g=h?p===d:l===f:u==="!="?g=h?p!==d:l!==f:u==="<"?g=h?p<d:l<f:u===">"?g=h?p>d:l>f:u==="<="?g=h?p<=d:l<=f:g=h?p>=d:l>=f,l=g?"1":"0"}else break}return l}function i(){let l=o();for(;e<t.length;){let u=t[e];if(u==="+"||u==="-"){e++;let f=o(),p=parseInt(l,10),d=parseInt(f,10);if(Number.isNaN(p)||Number.isNaN(d))throw new Error("non-integer argument");l=String(u==="+"?p+d:p-d)}else break}return l}function o(){let l=a();for(;e<t.length;){let u=t[e];if(u==="*"||u==="/"||u==="%"){e++;let f=a(),p=parseInt(l,10),d=parseInt(f,10);if(Number.isNaN(p)||Number.isNaN(d))throw new Error("non-integer argument");if((u==="/"||u==="%")&&d===0)throw new Error("division by zero");u==="*"?l=String(p*d):u==="/"?l=String(Math.trunc(p/d)):l=String(p%d)}else break}return l}function a(){let l=c();for(;e<t.length&&t[e]===":";){e++;let u=c(),f=new RegExp(`^${u}`),p=l.match(f);p?l=p[1]!==void 0?p[1]:String(p[0].length):l="0"}return l}function c(){if(e>=t.length)throw new Error("syntax error");let l=t[e];if(l==="match"){e++;let u=c(),f=c(),p=new RegExp(f),d=u.match(p);return d?d[1]!==void 0?d[1]:String(d[0].length):"0"}if(l==="substr"){e++;let u=c(),f=parseInt(c(),10),p=parseInt(c(),10);if(Number.isNaN(f)||Number.isNaN(p))throw new Error("non-integer argument");return u.substring(f-1,f-1+p)}if(l==="index"){e++;let u=c(),f=c();for(let p=0;p<u.length;p++)if(f.includes(u[p]))return String(p+1);return"0"}if(l==="length"){e++;let u=c();return String(u.length)}if(l==="("){e++;let u=r();if(e>=t.length||t[e]!==")")throw new Error("syntax error");return e++,u}return e++,l}return r()}var tm,fc=A(()=>{"use strict";tm={name:"expr",async execute(t,e){if(t.length===0)return{stdout:"",stderr:`expr: missing operand
411
+ `,exitCode:2};try{let r=rm(t),n=r==="0"||r===""?1:0;return{stdout:`${r}
407
412
  `,stderr:"",exitCode:n}}catch(r){return{stdout:"",stderr:`expr: ${r.message}
408
- `,exitCode:2}}}}});function Lh(t){function e(p,h){return p<<h|p>>>32-h}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,o=new Uint8Array(t.length+i+8);o.set(t),o[t.length]=128;let a=new DataView(o.buffer);a.setUint32(o.length-8,s>>>0,!0),a.setUint32(o.length-4,Math.floor(s/4294967296),!0);let l=1732584193,c=4023233417,u=2562383102,f=271733878;for(let p=0;p<o.length;p+=64){let h=new Uint32Array(16);for(let b=0;b<16;b++)h[b]=a.getUint32(p+b*4,!0);let w=l,g=c,y=u,E=f;for(let b=0;b<64;b++){let S,A;b<16?(S=g&y|~g&E,A=b):b<32?(S=E&g|~E&y,A=(5*b+1)%16):b<48?(S=g^y^E,A=(3*b+5)%16):(S=y^(g|~E),A=7*b%16),S=S+w+r[b]+h[A]>>>0,w=E,E=y,y=g,g=g+e(S,n[b])>>>0}l=l+w>>>0,c=c+g>>>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(p=>p.toString(16).padStart(2,"0")).join("")}async function Ka(t,e){if(t==="md5")return Lh(e);let r=await globalThis.crypto.subtle.digest(Dh[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 o=!1,a=[];for(let f of s)if(f==="-c"||f==="--check")o=!0;else if(!(f==="-b"||f==="-t"||f==="--binary"||f==="--text")){if(f.startsWith("-")&&f!=="-")return T(t,f);a.push(f)}a.length===0&&a.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(o){let f=0,d="";for(let p of a){let h=p==="-"?i.stdin:await i.fs.readFile(i.fs.resolvePath(i.cwd,p)).catch(()=>null);if(h===null)return{stdout:"",stderr:`${t}: ${p}: No such file or directory
409
- `,exitCode:1};for(let w of h.split(`
410
- `)){let g=w.match(/^([a-fA-F0-9]+)\s+[* ]?(.+)$/);if(!g)continue;let[,y,E]=g,b=await l(E);if(b===null){d+=`${E}: FAILED open or read
411
- `,f++;continue}let S=await Ka(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 a){let d=await l(f);if(d===null){c+=`${t}: ${f}: No such file or directory
414
- `,u=1;continue}c+=`${await Ka(e,d)} ${f}
415
- `}return{stdout:c,stderr:"",exitCode:u}}}}var Dh,Pr=C(()=>{"use strict";M();Dh={sha1:"SHA-1",sha256:"SHA-256"}});var Ja={};$(Ja,{md5sumCommand:()=>Mh});var Mh,Ya=C(()=>{"use strict";Pr();Mh=$t("md5sum","md5","compute MD5 message digest")});var el={};$(el,{sha1sumCommand:()=>_h});var _h,tl=C(()=>{"use strict";Pr();_h=$t("sha1sum","sha1","compute SHA1 message digest")});var rl={};$(rl,{sha256sumCommand:()=>Bh});var Bh,nl=C(()=>{"use strict";Pr();Bh=$t("sha256sum","sha256","compute SHA256 message digest")});var Wh,Q,ft,Xt=C(()=>{Wh="End-Of-Stream",Q=class extends Error{constructor(){super(Wh),this.name="EndOfStreamError"}},ft=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}}});var sl=C(()=>{});var dt,Tr=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 il=C(()=>{Xt();sl();Tr()});var Dr,ol=C(()=>{Tr();Dr=class extends dt{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}}});var Kt,Jn=C(()=>{ol();Kt=class extends Dr{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 Rt,Yn=C(()=>{Xt();Tr();Rt=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 es(t){try{let e=t.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new Rt(e):new Kt(e)}catch(e){if(e instanceof TypeError)return new Rt(t.getReader());throw e}}var al=C(()=>{Jn();Yn()});var tt=C(()=>{Xt();il();Jn();Yn();al()});var Ue,Ot=C(()=>{tt();Ue=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 Hh,Lr,ll=C(()=>{Ot();tt();Hh=256e3,Lr=class extends Ue{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 o=new Uint8Array(n.length+i);return s=await this.peekBuffer(o,{mayBeLess:n.mayBeLess}),e.set(o.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(Hh,e),n=new Uint8Array(r),s=0;for(;s<e;){let i=e-s,o=await this.readBuffer(n,{length:Math.min(r,i)});if(o<0)return o;s+=o}return s}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}}});var Mr,cl=C(()=>{tt();Ot();Mr=class extends Ue{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 _r,ul=C(()=>{tt();Ot();_r=class extends Ue{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 ts(t,e){let r=es(t),n=e??{},s=n.onClose;return n.onClose=async()=>{if(await r.close(),s)return s()},new Lr(r,n)}function fl(t,e){return new Mr(t,e)}function dl(t,e){return new _r(t,e)}var Br=C(()=>{tt();ll();cl();ul();tt();Ot()});import{open as jh}from"node:fs/promises";var Jt,rs=C(()=>{Ot();tt();Jt=class t extends Ue{static async fromFile(e){let r=await jh(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 Gh,pl=C(()=>{Br();rs();rs();Br();Gh=Jt.fromFile});var hl=wt(ns=>{ns.read=function(t,e,r,n,s){var i,o,a=s*8-n-1,l=(1<<a)-1,c=l>>1,u=-7,f=r?s-1:0,d=r?-1:1,p=t[e+f];for(f+=d,i=p&(1<<-u)-1,p>>=-u,u+=a;u>0;i=i*256+t[e+f],f+=d,u-=8);for(o=i&(1<<-u)-1,i>>=-u,u+=n;u>0;o=o*256+t[e+f],f+=d,u-=8);if(i===0)i=1-c;else{if(i===l)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,n),i=i-c}return(p?-1:1)*o*Math.pow(2,i-n)};ns.write=function(t,e,r,n,s,i){var o,a,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,p=n?0:i-1,h=n?1:-1,w=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),o+f>=1?e+=d/l:e+=d*Math.pow(2,1-f),e*l>=2&&(o++,l/=2),o+f>=u?(a=0,o=u):o+f>=1?(a=(e*l-1)*Math.pow(2,s),o=o+f):(a=e*Math.pow(2,f-1)*Math.pow(2,s),o=0));s>=8;t[r+p]=a&255,p+=h,a/=256,s-=8);for(o=o<<s|a,c+=s;c>0;t[r+p]=o&255,p+=h,o/=256,c-=8);t[r+p-h]|=w*128}});function ml(t,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":return typeof globalThis.TextDecoder<"u"?new globalThis.TextDecoder("utf-8").decode(t):Zh(t);case"utf-16le":return Qh(t);case"ascii":return Xh(t);case"latin1":case"iso-8859-1":return Kh(t);case"windows-1252":return Jh(t);default:throw new RangeError(`Encoding '${e}' not supported`)}}function Zh(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,o=t[r++]&63,a=(n&7)<<18|s<<12|i<<6|o;a-=65536,e+=String.fromCharCode(55296+(a>>10&1023),56320+(a&1023))}}return e}function Qh(t){let e="";for(let r=0;r<t.length;r+=2)e+=String.fromCharCode(t[r]|t[r+1]<<8);return e}function Xh(t){return String.fromCharCode(...t.map(e=>e&127))}function Kh(t){return String.fromCharCode(...t)}function Jh(t){let e="";for(let r of t)r>=128&&r<=159&&ss[r]?e+=ss[r]:e+=String.fromCharCode(r);return e}var ss,Vh,gl=C(()=>{ss={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"},Vh={};for(let[t,e]of Object.entries(ss))Vh[e]=Number.parseInt(t)});function we(t){return new DataView(t.buffer,t.byteOffset)}var xl,yl,Y,Ft,ie,wl,El,bl,Ee,Yt=C(()=>{xl=hi(hl(),1);gl();yl={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}},wl={len:4,get(t,e){return we(t).getUint32(e)},put(t,e,r){return we(t).setUint32(e,r),e+4}},El={len:4,get(t,e){return we(t).getInt32(e)},put(t,e,r){return we(t).setInt32(e,r),e+4}},bl={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 ml(n,this.encoding)}}});var Cl=wt((Kw,Sl)=>{var Pt=1e3,Tt=Pt*60,Dt=Tt*60,pt=Dt*24,em=pt*7,tm=pt*365.25;Sl.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return rm(t);if(r==="number"&&isFinite(t))return e.long?sm(t):nm(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function rm(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*tm;case"weeks":case"week":case"w":return r*em;case"days":case"day":case"d":return r*pt;case"hours":case"hour":case"hrs":case"hr":case"h":return r*Dt;case"minutes":case"minute":case"mins":case"min":case"m":return r*Tt;case"seconds":case"second":case"secs":case"sec":case"s":return r*Pt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function nm(t){var e=Math.abs(t);return e>=pt?Math.round(t/pt)+"d":e>=Dt?Math.round(t/Dt)+"h":e>=Tt?Math.round(t/Tt)+"m":e>=Pt?Math.round(t/Pt)+"s":t+"ms"}function sm(t){var e=Math.abs(t);return e>=pt?Wr(t,e,pt,"day"):e>=Dt?Wr(t,e,Dt,"hour"):e>=Tt?Wr(t,e,Tt,"minute"):e>=Pt?Wr(t,e,Pt,"second"):t+" ms"}function Wr(t,e,r,n){var s=e>=r*1.5;return Math.round(t/r)+" "+n+(s?"s":"")}});var is=wt((Jw,Al)=>{function im(t){r.debug=r,r.default=r,r.coerce=l,r.disable=o,r.enable=s,r.enabled=a,r.humanize=Cl(),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,p,h;function w(...g){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,g[0]=r.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let S=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(D,P)=>{if(D==="%%")return"%";S++;let F=r.formatters[P];if(typeof F=="function"){let B=g[S];D=F.call(y,B),g.splice(S,1),S--}return D}),r.formatArgs.call(y,g),(y.log||r.log).apply(y,g)}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:(p!==r.namespaces&&(p=r.namespaces,h=r.enabled(u)),h),set:g=>{d=g}}),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,p=0,h=-1,w=0;for(;d<u.length;)if(p<f.length&&(f[p]===u[d]||f[p]==="*"))f[p]==="*"?(h=p,w=d,p++):(d++,p++);else if(h!==-1)p=h+1,w++,d=w;else return!1;for(;p<f.length&&f[p]==="*";)p++;return p===f.length}function o(){let u=[...r.names,...r.skips.map(f=>"-"+f)].join(",");return r.enable(""),u}function a(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}Al.exports=im});var kl=wt((be,Ur)=>{be.formatArgs=am;be.save=lm;be.load=cm;be.useColors=om;be.storage=um();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 om(){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 am(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Ur.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 lm(t){try{t?be.storage.setItem("debug",t):be.storage.removeItem("debug")}catch{}}function cm(){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 um(){try{return localStorage}catch{}}Ur.exports=is()(be);var{formatters:fm}=Ur.exports;fm.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Nl=wt((fe,zr)=>{var dm=An("tty"),Hr=An("util");fe.init=wm;fe.log=gm;fe.formatArgs=hm;fe.save=xm;fe.load=ym;fe.useColors=pm;fe.destroy=Hr.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=An("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 pm(){return"colors"in fe.inspectOpts?!!fe.inspectOpts.colors:dm.isatty(process.stderr.fd)}function hm(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(`
413
+ `,exitCode:2}}}}});function sm(t){function e(d,h){return d<<h|d>>>32-h}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,o=new Uint8Array(t.length+i+8);o.set(t),o[t.length]=128;let a=new DataView(o.buffer);a.setUint32(o.length-8,s>>>0,!0),a.setUint32(o.length-4,Math.floor(s/4294967296),!0);let c=1732584193,l=4023233417,u=2562383102,f=271733878;for(let d=0;d<o.length;d+=64){let h=new Uint32Array(16);for(let b=0;b<16;b++)h[b]=a.getUint32(d+b*4,!0);let g=c,y=l,w=u,E=f;for(let b=0;b<64;b++){let S,C;b<16?(S=y&w|~y&E,C=b):b<32?(S=E&y|~E&w,C=(5*b+1)%16):b<48?(S=y^w^E,C=(3*b+5)%16):(S=w^(y|~E),C=7*b%16),S=S+g+r[b]+h[C]>>>0,g=E,E=w,w=y,y=y+e(S,n[b])>>>0}c=c+g>>>0,l=l+y>>>0,u=u+w>>>0,f=f+E>>>0}let p=new Uint8Array(16);return new DataView(p.buffer).setUint32(0,c,!0),new DataView(p.buffer).setUint32(4,l,!0),new DataView(p.buffer).setUint32(8,u,!0),new DataView(p.buffer).setUint32(12,f,!0),Array.from(p).map(d=>d.toString(16).padStart(2,"0")).join("")}async function pc(t,e){if(t==="md5")return sm(e);let r=await globalThis.crypto.subtle.digest(nm[t],new Uint8Array(e).buffer);return Array.from(new Uint8Array(r)).map(n=>n.toString(16).padStart(2,"0")).join("")}function Tt(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(I(s))return N(n);let o=!1,a=[];for(let f of s)if(f==="-c"||f==="--check")o=!0;else if(!(f==="-b"||f==="-t"||f==="--binary"||f==="--text")){if(f.startsWith("-")&&f!=="-")return L(t,f);a.push(f)}a.length===0&&a.push("-");let c=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(o){let f=0,p="";for(let d of a){let h=d==="-"?i.stdin:await i.fs.readFile(i.fs.resolvePath(i.cwd,d)).catch(()=>null);if(h===null)return{stdout:"",stderr:`${t}: ${d}: No such file or directory
414
+ `,exitCode:1};for(let g of h.split(`
415
+ `)){let y=g.match(/^([a-fA-F0-9]+)\s+[* ]?(.+)$/);if(!y)continue;let[,w,E]=y,b=await c(E);if(b===null){p+=`${E}: FAILED open or read
416
+ `,f++;continue}let S=await pc(e,b)===w.toLowerCase();p+=`${E}: ${S?"OK":"FAILED"}
417
+ `,S||f++}}return f>0&&(p+=`${t}: WARNING: ${f} computed checksum${f>1?"s":""} did NOT match
418
+ `),{stdout:p,stderr:"",exitCode:f>0?1:0}}let l="",u=0;for(let f of a){let p=await c(f);if(p===null){l+=`${t}: ${f}: No such file or directory
419
+ `,u=1;continue}l+=`${await pc(e,p)} ${f}
420
+ `}return{stdout:l,stderr:"",exitCode:u}}}}var nm,Mr=A(()=>{"use strict";_();nm={sha1:"SHA-1",sha256:"SHA-256"}});var dc={};$(dc,{md5sumCommand:()=>im});var im,hc=A(()=>{"use strict";Mr();im=Tt("md5sum","md5","compute MD5 message digest")});var mc={};$(mc,{sha1sumCommand:()=>om});var om,yc=A(()=>{"use strict";Mr();om=Tt("sha1sum","sha1","compute SHA1 message digest")});var gc={};$(gc,{sha256sumCommand:()=>am});var am,xc=A(()=>{"use strict";Mr();am=Tt("sha256sum","sha256","compute SHA256 message digest")});var cm,Q,dt,Jt=A(()=>{cm="End-Of-Stream",Q=class extends Error{constructor(){super(cm),this.name="EndOfStreamError"}},dt=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}}});var wc=A(()=>{});var ht,_r=A(()=>{Jt();ht=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 dt;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 Ec=A(()=>{Jt();wc();_r()});var Br,bc=A(()=>{_r();Br=class extends ht{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}}});var Yt,os=A(()=>{bc();Yt=class extends Br{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 Ft,as=A(()=>{Jt();_r();Ft=class extends ht{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 cs(t){try{let e=t.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new Ft(e):new Yt(e)}catch(e){if(e instanceof TypeError)return new Ft(t.getReader());throw e}}var Sc=A(()=>{os();as()});var rt=A(()=>{Jt();Ec();os();as();Sc()});var je,Dt=A(()=>{rt();je=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 um,Wr,Ac=A(()=>{Dt();rt();um=256e3,Wr=class extends je{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 o=new Uint8Array(n.length+i);return s=await this.peekBuffer(o,{mayBeLess:n.mayBeLess}),e.set(o.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(um,e),n=new Uint8Array(r),s=0;for(;s<e;){let i=e-s,o=await this.readBuffer(n,{length:Math.min(r,i)});if(o<0)return o;s+=o}return s}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}}});var Ur,Cc=A(()=>{rt();Dt();Ur=class extends je{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 Hr,kc=A(()=>{rt();Dt();Hr=class extends je{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 ls(t,e){let r=cs(t),n=e??{},s=n.onClose;return n.onClose=async()=>{if(await r.close(),s)return s()},new Wr(r,n)}function Nc(t,e){return new Ur(t,e)}function Ic(t,e){return new Hr(t,e)}var jr=A(()=>{rt();Ac();Cc();kc();rt();Dt()});import{open as pm}from"node:fs/promises";var er,us=A(()=>{Dt();rt();er=class t extends je{static async fromFile(e){let r=await pm(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 dm,vc=A(()=>{jr();us();us();jr();dm=er.fromFile});var Rc=St(fs=>{fs.read=function(t,e,r,n,s){var i,o,a=s*8-n-1,c=(1<<a)-1,l=c>>1,u=-7,f=r?s-1:0,p=r?-1:1,d=t[e+f];for(f+=p,i=d&(1<<-u)-1,d>>=-u,u+=a;u>0;i=i*256+t[e+f],f+=p,u-=8);for(o=i&(1<<-u)-1,i>>=-u,u+=n;u>0;o=o*256+t[e+f],f+=p,u-=8);if(i===0)i=1-l;else{if(i===c)return o?NaN:(d?-1:1)*(1/0);o=o+Math.pow(2,n),i=i-l}return(d?-1:1)*o*Math.pow(2,i-n)};fs.write=function(t,e,r,n,s,i){var o,a,c,l=i*8-s-1,u=(1<<l)-1,f=u>>1,p=s===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,h=n?1:-1,g=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+f>=1?e+=p/c:e+=p*Math.pow(2,1-f),e*c>=2&&(o++,c/=2),o+f>=u?(a=0,o=u):o+f>=1?(a=(e*c-1)*Math.pow(2,s),o=o+f):(a=e*Math.pow(2,f-1)*Math.pow(2,s),o=0));s>=8;t[r+d]=a&255,d+=h,a/=256,s-=8);for(o=o<<s|a,l+=s;l>0;t[r+d]=o&255,d+=h,o/=256,l-=8);t[r+d-h]|=g*128}});function $c(t,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":return typeof globalThis.TextDecoder<"u"?new globalThis.TextDecoder("utf-8").decode(t):ym(t);case"utf-16le":return gm(t);case"ascii":return xm(t);case"latin1":case"iso-8859-1":return wm(t);case"windows-1252":return Em(t);default:throw new RangeError(`Encoding '${e}' not supported`)}}function ym(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,o=t[r++]&63,a=(n&7)<<18|s<<12|i<<6|o;a-=65536,e+=String.fromCharCode(55296+(a>>10&1023),56320+(a&1023))}}return e}function gm(t){let e="";for(let r=0;r<t.length;r+=2)e+=String.fromCharCode(t[r]|t[r+1]<<8);return e}function xm(t){return String.fromCharCode(...t.map(e=>e&127))}function wm(t){return String.fromCharCode(...t)}function Em(t){let e="";for(let r of t)r>=128&&r<=159&&ps[r]?e+=ps[r]:e+=String.fromCharCode(r);return e}var ps,mm,Oc=A(()=>{ps={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"},mm={};for(let[t,e]of Object.entries(ps))mm[e]=Number.parseInt(t)});function be(t){return new DataView(t.buffer,t.byteOffset)}var Pc,Tc,ee,Lt,oe,Fc,Dc,Lc,Se,tr=A(()=>{Pc=Si(Rc(),1);Oc();Tc={len:1,get(t,e){return be(t).getUint8(e)},put(t,e,r){return be(t).setUint8(e,r),e+1}},ee={len:2,get(t,e){return be(t).getUint16(e,!0)},put(t,e,r){return be(t).setUint16(e,r,!0),e+2}},Lt={len:2,get(t,e){return be(t).getUint16(e)},put(t,e,r){return be(t).setUint16(e,r),e+2}},oe={len:4,get(t,e){return be(t).getUint32(e,!0)},put(t,e,r){return be(t).setUint32(e,r,!0),e+4}},Fc={len:4,get(t,e){return be(t).getUint32(e)},put(t,e,r){return be(t).setUint32(e,r),e+4}},Dc={len:4,get(t,e){return be(t).getInt32(e)},put(t,e,r){return be(t).setInt32(e,r),e+4}},Lc={len:8,get(t,e){return be(t).getBigUint64(e,!0)},put(t,e,r){return be(t).setBigUint64(e,r,!0),e+8}},Se=class{constructor(e,r){this.len=e,this.encoding=r}get(e,r=0){let n=e.subarray(r,r+this.len);return $c(n,this.encoding)}}});var _c=St((kE,Mc)=>{var Mt=1e3,_t=Mt*60,Bt=_t*60,mt=Bt*24,Sm=mt*7,Am=mt*365.25;Mc.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return Cm(t);if(r==="number"&&isFinite(t))return e.long?Nm(t):km(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Cm(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*Am;case"weeks":case"week":case"w":return r*Sm;case"days":case"day":case"d":return r*mt;case"hours":case"hour":case"hrs":case"hr":case"h":return r*Bt;case"minutes":case"minute":case"mins":case"min":case"m":return r*_t;case"seconds":case"second":case"secs":case"sec":case"s":return r*Mt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function km(t){var e=Math.abs(t);return e>=mt?Math.round(t/mt)+"d":e>=Bt?Math.round(t/Bt)+"h":e>=_t?Math.round(t/_t)+"m":e>=Mt?Math.round(t/Mt)+"s":t+"ms"}function Nm(t){var e=Math.abs(t);return e>=mt?zr(t,e,mt,"day"):e>=Bt?zr(t,e,Bt,"hour"):e>=_t?zr(t,e,_t,"minute"):e>=Mt?zr(t,e,Mt,"second"):t+" ms"}function zr(t,e,r,n){var s=e>=r*1.5;return Math.round(t/r)+" "+n+(s?"s":"")}});var ds=St((NE,Bc)=>{function Im(t){r.debug=r,r.default=r,r.coerce=c,r.disable=o,r.enable=s,r.enabled=a,r.humanize=_c(),r.destroy=l,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let f=0;for(let p=0;p<u.length;p++)f=(f<<5)-f+u.charCodeAt(p),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=e;function r(u){let f,p=null,d,h;function g(...y){if(!g.enabled)return;let w=g,E=Number(new Date),b=E-(f||E);w.diff=b,w.prev=f,w.curr=E,f=E,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let S=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(O,D)=>{if(O==="%%")return"%";S++;let F=r.formatters[D];if(typeof F=="function"){let U=y[S];O=F.call(w,U),y.splice(S,1),S--}return O}),r.formatArgs.call(w,y),(w.log||r.log).apply(w,y)}return g.namespace=u,g.useColors=r.useColors(),g.color=r.selectColor(u),g.extend=n,g.destroy=r.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(d!==r.namespaces&&(d=r.namespaces,h=r.enabled(u)),h),set:y=>{p=y}}),typeof r.init=="function"&&r.init(g),g}function n(u,f){let p=r(this.namespace+(typeof f>"u"?":":f)+u);return p.log=this.log,p}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 p of f)p[0]==="-"?r.skips.push(p.slice(1)):r.names.push(p)}function i(u,f){let p=0,d=0,h=-1,g=0;for(;p<u.length;)if(d<f.length&&(f[d]===u[p]||f[d]==="*"))f[d]==="*"?(h=d,g=p,d++):(p++,d++);else if(h!==-1)d=h+1,g++,p=g;else return!1;for(;d<f.length&&f[d]==="*";)d++;return d===f.length}function o(){let u=[...r.names,...r.skips.map(f=>"-"+f)].join(",");return r.enable(""),u}function a(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 c(u){return u instanceof Error?u.stack||u.message:u}function l(){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}Bc.exports=Im});var Wc=St((Ae,Gr)=>{Ae.formatArgs=Rm;Ae.save=$m;Ae.load=Om;Ae.useColors=vm;Ae.storage=Pm();Ae.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`."))}})();Ae.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 vm(){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 Rm(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Gr.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)}Ae.log=console.debug||console.log||(()=>{});function $m(t){try{t?Ae.storage.setItem("debug",t):Ae.storage.removeItem("debug")}catch{}}function Om(){let t;try{t=Ae.storage.getItem("debug")||Ae.storage.getItem("DEBUG")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function Pm(){try{return localStorage}catch{}}Gr.exports=ds()(Ae);var{formatters:Tm}=Gr.exports;Tm.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var Hc=St((pe,Vr)=>{var Fm=vn("tty"),qr=vn("util");pe.init=Um;pe.log=_m;pe.formatArgs=Lm;pe.save=Bm;pe.load=Wm;pe.useColors=Dm;pe.destroy=qr.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");pe.colors=[6,2,3,4,5,1];try{let t=vn("supports-color");t&&(t.stderr||t).level>=2&&(pe.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{}pe.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 Dm(){return"colors"in pe.inspectOpts?!!pe.inspectOpts.colors:Fm.isatty(process.stderr.fd)}function Lm(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
421
  `).join(`
417
- `+i),t.push(s+"m+"+zr.exports.humanize(this.diff)+"\x1B[0m")}else t[0]=mm()+e+" "+t[0]}function mm(){return fe.inspectOpts.hideDate?"":new Date().toISOString()+" "}function gm(...t){return process.stderr.write(Hr.formatWithOptions(fe.inspectOpts,...t)+`
418
- `)}function xm(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function ym(){return process.env.DEBUG}function wm(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]]}zr.exports=is()(fe);var{formatters:vl}=zr.exports;vl.o=function(t){return this.inspectOpts.colors=this.useColors,Hr.inspect(t,this.inspectOpts).split(`
419
- `).map(e=>e.trim()).join(" ")};vl.O=function(t){return this.inspectOpts.colors=this.useColors,Hr.inspect(t,this.inspectOpts)}});var Il=wt((Yw,os)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?os.exports=kl():os.exports=Nl()});var ht,as,$l,Rl,Ol,Fl=C(()=>{Yt();ht={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},as={get(t){return{signature:ie.get(t,0),compressedSize:ie.get(t,8),uncompressedSize:ie.get(t,12)}},len:16},$l={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},Rl={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},Ol={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 Tl(t){let e=new Uint8Array(ie.len);return ie.put(e,0,t),e}function bm(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 o=0;o<n;o++)if(t[s+o]!==e[o]){i=!1;break}if(i)return s}return-1}function Sm(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 Pl,je,ls,Em,jr,er,Dl=C(()=>{Yt();Pl=hi(Il(),1);Fl();je=(0,Pl.default)("tokenizer:inflate"),ls=256*1024,Em=Tl(ht.DataDescriptor),jr=Tl(ht.EndOfCentralDirectory),er=class t{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(ls)}async isZip(){return await this.peekSignature()===ht.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]===jr[0]&&n[s+1]===jr[1]&&n[s+2]===jr[2]&&n[s+3]===jr[3])return e.fileInfo.size-r+s;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){je("Cannot reading central-directory without random-read support");return}je("Reading central-directory...");let e=this.tokenizer.position,r=await this.findEndOfCentralDirectoryLocator();if(r>0){je("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(Rl,r),s=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let o=await this.tokenizer.readToken(Ol);if(o.signature!==ht.CentralFileHeader)throw new Error("Expected Central-File-Header signature");o.filename=await this.tokenizer.readToken(new Ee(o.filenameLength,"utf-8")),await this.tokenizer.ignore(o.extraFieldLength),await this.tokenizer.ignore(o.fileCommentLength),s.push(o),je(`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 o;if(await this.tokenizer.ignore(s.extraFieldLength),s.dataDescriptor&&s.compressedSize===0){let a=[],l=ls;je("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let c=-1;for(;c<0&&l===ls;){l=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),c=bm(this.syncBuffer.subarray(0,l),Em);let u=c>=0?c:l;if(i.handler){let f=new Uint8Array(u);await this.tokenizer.readBuffer(f),a.push(f)}else await this.tokenizer.ignore(u)}je(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(s,Sm(a),i.handler)}else i.handler?(je(`Reading compressed-file-data: ${s.compressedSize} bytes`),o=new Uint8Array(s.compressedSize),await this.tokenizer.readBuffer(o),await this.inflate(s,o,i.handler)):(je(`Ignoring compressed-file-data: ${s.compressedSize} bytes`),await this.tokenizer.ignore(s.compressedSize));if(je(`Reading data-descriptor at pos=${this.tokenizer.position}`),s.dataDescriptor&&(await this.tokenizer.readToken(as)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-as.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 o=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(o),await this.inflate(i,o,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}`);je(`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 o=await new Response(s).arrayBuffer();return new Uint8Array(o)}catch(i){let o=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(o)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(ie);if(e===ht.LocalFileHeader){let r=await this.tokenizer.readToken($l);return r.filename=await this.tokenizer.readToken(new Ee(r.filenameLength,"utf-8")),r}if(e===ht.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}}});var tr,Ll=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 Ml=C(()=>{Dl();Ll()});function cs(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 cE,uE,fE,_l=C(()=>{cE={utf8:new globalThis.TextDecoder("utf8")},uE=new globalThis.TextEncoder,fE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"))});function Bl(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 Wl(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 Ul,Hl=C(()=>{Yt();Ul={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4}});var zl,jl,Gl=C(()=>{zl=["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"],jl=["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 ps(t,e){return new ds(e).fromBuffer(t)}function fs(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 Ge(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 us,ds,Cm,Am,ql=C(()=>{Yt();Br();Ml();_l();Hl();Gl();us=4100;ds=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(fl(r,this.tokenizerOptions))}async fromBlob(e){let r=dl(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async fromStream(e){let r=ts(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async toDetectionStream(e,r){let{sampleSize:n=us}=r,s,i,o=e.getReader({mode:"byob"});try{let{value:c,done:u}=await o.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{o.releaseLock()}let a=new TransformStream({async start(c){c.enqueue(i)},transform(c,u){u.enqueue(c)}}),l=e.pipeThrough(a);return l.fileType=s,l}check(e,r){return Ge(this.buffer,e,r)}checkString(e,r){return this.check(Bl(e,r?.encoding),r)}detectConfident=async e=>{if(this.buffer=new Uint8Array(us),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(Ul);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=fs(i)},stop:!0};case"[Content_Types].xml":return{async handler(s){let i=new TextDecoder("utf-8").decode(s),o=i.indexOf('.main+xml"');if(o===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(r=fs(a))}else{i=i.slice(0,Math.max(0,o));let a=i.lastIndexOf('"'),l=i.slice(Math.max(0,a+1));r=fs(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),Ge(r,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:Ge(r,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:Ge(r,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:Ge(r,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:Ge(r,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:Ge(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 a=await e.peekNumber(yl),l=128,c=0;for(;(a&l)===0&&l!==0;)++c,l>>=1;let u=new Uint8Array(c+1);return await e.readBuffer(u),u}async function n(){let a=await r(),l=await r();l[0]^=128>>l.length-1;let c=Math.min(6,l.length),u=new DataView(a.buffer),f=new DataView(l.buffer,l.length-c,c);return{id:cs(u),len:cs(f)}}async function s(a){for(;a>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),--a}}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(El),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(bl))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await r(),s=n.size-24;if(Ge(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),Ge(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(Ge(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})&&Wl(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(us),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?wl: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),o=(e?Ft:Y).get(this.buffer,10);if(i===28&&o===254||i===31&&o===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"}}}},Cm=new Set(zl),Am=new Set(jl)});var Vl=C(()=>{pl();ql()});var Xl={};$(Xl,{fileCommand:()=>Rm});function vm(t,e){if(Ql[t])return Ql[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 Nm(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 Im(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 o=Nm(e);if(o&&Zl[o]){let l=Zl[o];return l.mime.startsWith("text/")&&i?{description:`${l.description}${i}`,mime:l.mime}:l}let a=!1;for(let l=0;l<Math.min(t.length,8192);l++)if(t.charCodeAt(l)>127){a=!0;break}return a?{description:`UTF-8 Unicode text${i}`,mime:"text/plain; charset=utf-8"}:{description:`ASCII text${i}`,mime:"text/plain"}}async function $m(t,e){if(e.length===0)return{description:"empty",mime:"inode/x-empty"};let r=await ps(e);if(r)return{description:vm(r.ext,r.mime),mime:r.mime};let n=new TextDecoder("utf-8",{fatal:!1}).decode(e);return Im(n,t)}var km,Zl,Ql,Rm,Kl=C(()=>{"use strict";Vl();M();km={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"]},Zl={".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"}},Ql={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"};Rm={name:"file",async execute(t,e){if(v(t))return k(km);let r=!1,n=!1,s=[];for(let a of t)if(a.startsWith("--")){if(a==="--brief")r=!0;else if(a==="--mime"||a==="--mime-type")n=!0;else if(a!=="--dereference")return T("file",a)}else if(a.startsWith("-")&&a!=="-"){for(let l of a.slice(1))if(l==="b")r=!0;else if(l==="i")n=!0;else if(l!=="L")return T("file",`-${l}`)}else s.push(a);if(s.length===0)return{stdout:"",stderr:`Usage: file [-bLi] FILE...
425
- `,exitCode:1};let i="",o=0;for(let a of s)try{let l=e.fs.resolvePath(e.cwd,a);if((await e.fs.stat(l)).isDirectory){let p=n?"inode/directory":"directory";i+=r?`${p}
426
- `:`${a}: ${p}
427
- `;continue}let u=await e.fs.readFileBuffer(l),f=await $m(a,u),d=n?f.mime:f.description;i+=r?`${d}
422
+ `+i),t.push(s+"m+"+Vr.exports.humanize(this.diff)+"\x1B[0m")}else t[0]=Mm()+e+" "+t[0]}function Mm(){return pe.inspectOpts.hideDate?"":new Date().toISOString()+" "}function _m(...t){return process.stderr.write(qr.formatWithOptions(pe.inspectOpts,...t)+`
423
+ `)}function Bm(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function Wm(){return process.env.DEBUG}function Um(t){t.inspectOpts={};let e=Object.keys(pe.inspectOpts);for(let r=0;r<e.length;r++)t.inspectOpts[e[r]]=pe.inspectOpts[e[r]]}Vr.exports=ds()(pe);var{formatters:Uc}=Vr.exports;Uc.o=function(t){return this.inspectOpts.colors=this.useColors,qr.inspect(t,this.inspectOpts).split(`
424
+ `).map(e=>e.trim()).join(" ")};Uc.O=function(t){return this.inspectOpts.colors=this.useColors,qr.inspect(t,this.inspectOpts)}});var jc=St((IE,hs)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?hs.exports=Wc():hs.exports=Hc()});var yt,ms,zc,Gc,qc,Vc=A(()=>{tr();yt={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},ms={get(t){return{signature:oe.get(t,0),compressedSize:oe.get(t,8),uncompressedSize:oe.get(t,12)}},len:16},zc={get(t){let e=ee.get(t,6);return{signature:oe.get(t,0),minVersion:ee.get(t,4),dataDescriptor:!!(e&8),compressedMethod:ee.get(t,8),compressedSize:oe.get(t,18),uncompressedSize:oe.get(t,22),filenameLength:ee.get(t,26),extraFieldLength:ee.get(t,28),filename:null}},len:30},Gc={get(t){return{signature:oe.get(t,0),nrOfThisDisk:ee.get(t,4),nrOfThisDiskWithTheStart:ee.get(t,6),nrOfEntriesOnThisDisk:ee.get(t,8),nrOfEntriesOfSize:ee.get(t,10),sizeOfCd:oe.get(t,12),offsetOfStartOfCd:oe.get(t,16),zipFileCommentLength:ee.get(t,20)}},len:22},qc={get(t){let e=ee.get(t,8);return{signature:oe.get(t,0),minVersion:ee.get(t,6),dataDescriptor:!!(e&8),compressedMethod:ee.get(t,10),compressedSize:oe.get(t,20),uncompressedSize:oe.get(t,24),filenameLength:ee.get(t,28),extraFieldLength:ee.get(t,30),fileCommentLength:ee.get(t,32),relativeOffsetOfLocalHeader:oe.get(t,42),filename:null}},len:46}});function Zc(t){let e=new Uint8Array(oe.len);return oe.put(e,0,t),e}function jm(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 o=0;o<n;o++)if(t[s+o]!==e[o]){i=!1;break}if(i)return s}return-1}function zm(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 Kc,qe,ys,Hm,Kr,rr,Qc=A(()=>{tr();Kc=Si(jc(),1);Vc();qe=(0,Kc.default)("tokenizer:inflate"),ys=256*1024,Hm=Zc(yt.DataDescriptor),Kr=Zc(yt.EndOfCentralDirectory),rr=class t{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(ys)}async isZip(){return await this.peekSignature()===yt.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(oe)}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]===Kr[0]&&n[s+1]===Kr[1]&&n[s+2]===Kr[2]&&n[s+3]===Kr[3])return e.fileInfo.size-r+s;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){qe("Cannot reading central-directory without random-read support");return}qe("Reading central-directory...");let e=this.tokenizer.position,r=await this.findEndOfCentralDirectoryLocator();if(r>0){qe("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(Gc,r),s=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let o=await this.tokenizer.readToken(qc);if(o.signature!==yt.CentralFileHeader)throw new Error("Expected Central-File-Header signature");o.filename=await this.tokenizer.readToken(new Se(o.filenameLength,"utf-8")),await this.tokenizer.ignore(o.extraFieldLength),await this.tokenizer.ignore(o.fileCommentLength),s.push(o),qe(`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 o;if(await this.tokenizer.ignore(s.extraFieldLength),s.dataDescriptor&&s.compressedSize===0){let a=[],c=ys;qe("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let l=-1;for(;l<0&&c===ys;){c=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),l=jm(this.syncBuffer.subarray(0,c),Hm);let u=l>=0?l:c;if(i.handler){let f=new Uint8Array(u);await this.tokenizer.readBuffer(f),a.push(f)}else await this.tokenizer.ignore(u)}qe(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(s,zm(a),i.handler)}else i.handler?(qe(`Reading compressed-file-data: ${s.compressedSize} bytes`),o=new Uint8Array(s.compressedSize),await this.tokenizer.readBuffer(o),await this.inflate(s,o,i.handler)):(qe(`Ignoring compressed-file-data: ${s.compressedSize} bytes`),await this.tokenizer.ignore(s.compressedSize));if(qe(`Reading data-descriptor at pos=${this.tokenizer.position}`),s.dataDescriptor&&(await this.tokenizer.readToken(ms)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-ms.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 o=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(o),await this.inflate(i,o,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}`);qe(`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 o=await new Response(s).arrayBuffer();return new Uint8Array(o)}catch(i){let o=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(o)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(oe);if(e===yt.LocalFileHeader){let r=await this.tokenizer.readToken(zc);return r.filename=await this.tokenizer.readToken(new Se(r.filenameLength,"utf-8")),r}if(e===yt.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}}});var nr,Xc=A(()=>{nr=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 Jc=A(()=>{Qc();Xc()});function gs(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 ME,_E,BE,Yc=A(()=>{ME={utf8:new globalThis.TextDecoder("utf8")},_E=new globalThis.TextEncoder,BE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"))});function el(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 tl(t,e=0){let r=Number.parseInt(new Se(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 rl,nl=A(()=>{tr();rl={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4}});var sl,il,ol=A(()=>{sl=["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"],il=["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 bs(t,e){return new Es(e).fromBuffer(t)}function ws(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 Ve(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 xs,Es,Gm,qm,al=A(()=>{tr();jr();Jc();Yc();nl();ol();xs=4100;Es=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(Nc(r,this.tokenizerOptions))}async fromBlob(e){let r=Ic(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async fromStream(e){let r=ls(e,this.tokenizerOptions);try{return await this.fromTokenizer(r)}finally{await r.close()}}async toDetectionStream(e,r){let{sampleSize:n=xs}=r,s,i,o=e.getReader({mode:"byob"});try{let{value:l,done:u}=await o.read(new Uint8Array(n));if(i=l,!u&&l)try{s=await this.fromBuffer(l.subarray(0,n))}catch(f){if(!(f instanceof Q))throw f;s=void 0}i=l}finally{o.releaseLock()}let a=new TransformStream({async start(l){l.enqueue(i)},transform(l,u){u.enqueue(l)}}),c=e.pipeThrough(a);return c.fileType=s,c}check(e,r){return Ve(this.buffer,e,r)}checkString(e,r){return this.check(el(e,r?.encoding),r)}detectConfident=async e=>{if(this.buffer=new Uint8Array(xs),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 nr(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(rl);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 rr(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=ws(i)},stop:!0};case"[Content_Types].xml":return{async handler(s){let i=new TextDecoder("utf-8").decode(s),o=i.indexOf('.main+xml"');if(o===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(r=ws(a))}else{i=i.slice(0,Math.max(0,o));let a=i.lastIndexOf('"'),c=i.slice(Math.max(0,a+1));r=ws(c)}},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),Ve(r,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:Ve(r,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:Ve(r,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:Ve(r,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:Ve(r,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:Ve(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 a=await e.peekNumber(Tc),c=128,l=0;for(;(a&c)===0&&c!==0;)++l,c>>=1;let u=new Uint8Array(l+1);return await e.readBuffer(u),u}async function n(){let a=await r(),c=await r();c[0]^=128>>c.length-1;let l=Math.min(6,c.length),u=new DataView(a.buffer),f=new DataView(c.buffer,c.length-l,l);return{id:gs(u),len:gs(f)}}async function s(a){for(;a>0;){let c=await n();if(c.id===17026)return(await e.readToken(new Se(c.len))).replaceAll(/\00.*$/g,"");await e.ignore(c.len),--a}}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 Se(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 Se(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
425
+ `,"\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(Dc),type:await e.readToken(new Se(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 Se(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
426
+ `))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(Lc))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await r(),s=n.size-24;if(Ve(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),Ve(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(Ve(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 Se(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})&&tl(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
427
+ `,{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(xs),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?Lt:ee);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?Lt:ee);for(let n=0;n<r;++n){let s=await this.readTiffTag(e);if(s)return s}}async readTiffHeader(e){let r=(e?Lt:ee).get(this.buffer,2),n=(e?Fc:oe).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?Lt:ee).get(this.buffer,8),o=(e?Lt:ee).get(this.buffer,10);if(i===28&&o===254||i===31&&o===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"}}}},Gm=new Set(sl),qm=new Set(il)});var cl=A(()=>{vc();al()});var fl={};$(fl,{fileCommand:()=>Jm});function Km(t,e){if(ul[t])return ul[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 Zm(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 Qm(t,e){if(t.startsWith("#!")){let c=t.split(`
428
+ `)[0];return c.includes("python")?{description:"Python script, ASCII text executable",mime:"text/x-python"}:c.includes("node")||c.includes("bun")||c.includes("deno")?{description:"JavaScript script, ASCII text executable",mime:"text/javascript"}:c.includes("bash")?{description:"Bourne-Again shell script, ASCII text executable",mime:"text/x-shellscript"}:c.includes("sh")?{description:"POSIX shell script, ASCII text executable",mime:"text/x-shellscript"}:c.includes("ruby")?{description:"Ruby script, ASCII text executable",mime:"text/x-ruby"}:c.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
429
+ `),s=t.includes("\r")&&!n,i="";n?i=", with CRLF line terminators":s&&(i=", with CR line terminators");let o=Zm(e);if(o&&ll[o]){let c=ll[o];return c.mime.startsWith("text/")&&i?{description:`${c.description}${i}`,mime:c.mime}:c}let a=!1;for(let c=0;c<Math.min(t.length,8192);c++)if(t.charCodeAt(c)>127){a=!0;break}return a?{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 bs(e);if(r)return{description:Km(r.ext,r.mime),mime:r.mime};let n=new TextDecoder("utf-8",{fatal:!1}).decode(e);return Qm(n,t)}var Vm,ll,ul,Jm,pl=A(()=>{"use strict";cl();_();Vm={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"]},ll={".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"}},ul={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"};Jm={name:"file",async execute(t,e){if(I(t))return N(Vm);let r=!1,n=!1,s=[];for(let a of t)if(a.startsWith("--")){if(a==="--brief")r=!0;else if(a==="--mime"||a==="--mime-type")n=!0;else if(a!=="--dereference")return L("file",a)}else if(a.startsWith("-")&&a!=="-"){for(let c of a.slice(1))if(c==="b")r=!0;else if(c==="i")n=!0;else if(c!=="L")return L("file",`-${c}`)}else s.push(a);if(s.length===0)return{stdout:"",stderr:`Usage: file [-bLi] FILE...
430
+ `,exitCode:1};let i="",o=0;for(let a of s)try{let c=e.fs.resolvePath(e.cwd,a);if((await e.fs.stat(c)).isDirectory){let d=n?"inode/directory":"directory";i+=r?`${d}
428
431
  `:`${a}: ${d}
432
+ `;continue}let u=await e.fs.readFileBuffer(c),f=await Xm(a,u),p=n?f.mime:f.description;i+=r?`${p}
433
+ `:`${a}: ${p}
429
434
  `}catch{i+=r?`cannot open
430
435
  `:`${a}: cannot open (No such file or directory)
431
- `,o=1}return{stdout:i,stderr:"",exitCode:o}}}});var Jl={};$(Jl,{htmlToMarkdownCommand:()=>Pm});import Om from"turndown";var Fm,Pm,Yl=C(()=>{"use strict";M();Fm={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 ![alt](src)"," - 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"]},Pm={name:"html-to-markdown",async execute(t,e){if(v(t))return k(Fm);let r="-",n="```",s="---",i="atx",o=[];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==="-")o.push("-");else{if(c.startsWith("--"))return T("html-to-markdown",c);if(c.startsWith("-"))return T("html-to-markdown",c);o.push(c)}}let a;if(o.length===0||o.length===1&&o[0]==="-")a=e.stdin;else try{let l=e.fs.resolvePath(e.cwd,o[0]);a=await e.fs.readFile(l)}catch{return{stdout:"",stderr:`html-to-markdown: ${o[0]}: No such file or directory
432
- `,exitCode:1}}if(!a.trim())return{stdout:"",stderr:"",exitCode:0};try{let l=new Om({bulletListMarker:r,codeBlockStyle:"fenced",fence:n,hr:s,headingStyle:i});return l.remove(["script","style","footer"]),{stdout:`${l.turndown(a).trim()}
433
- `,stderr:"",exitCode:0}}catch(l){return{stdout:"",stderr:`html-to-markdown: conversion error: ${l.message}
434
- `,exitCode:1}}}}});var ec={};$(ec,{helpCommand:()=>Lm});function Dm(t){let e=[],r=new Set(t);e.push(`Available commands:
435
- `);let n=[];for(let[s,i]of Object.entries(Tm)){let o=i.filter(a=>r.has(a));if(o.length>0){e.push(` ${s}:`),e.push(` ${o.join(", ")}
436
+ `,o=1}return{stdout:i,stderr:"",exitCode:o}}}});var dl={};$(dl,{htmlToMarkdownCommand:()=>t0});import Ym from"turndown";var e0,t0,hl=A(()=>{"use strict";_();e0={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 ![alt](src)"," - 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"]},t0={name:"html-to-markdown",async execute(t,e){if(I(t))return N(e0);let r="-",n="```",s="---",i="atx",o=[];for(let c=0;c<t.length;c++){let l=t[c];if(l==="-b"||l==="--bullet")r=t[++c]??"-";else if(l.startsWith("--bullet="))r=l.slice(9);else if(l==="-c"||l==="--code")n=t[++c]??"```";else if(l.startsWith("--code="))n=l.slice(7);else if(l==="-r"||l==="--hr")s=t[++c]??"---";else if(l.startsWith("--hr="))s=l.slice(5);else if(l.startsWith("--heading-style=")){let u=l.slice(16);(u==="setext"||u==="atx")&&(i=u)}else if(l==="-")o.push("-");else{if(l.startsWith("--"))return L("html-to-markdown",l);if(l.startsWith("-"))return L("html-to-markdown",l);o.push(l)}}let a;if(o.length===0||o.length===1&&o[0]==="-")a=e.stdin;else try{let c=e.fs.resolvePath(e.cwd,o[0]);a=await e.fs.readFile(c)}catch{return{stdout:"",stderr:`html-to-markdown: ${o[0]}: No such file or directory
437
+ `,exitCode:1}}if(!a.trim())return{stdout:"",stderr:"",exitCode:0};try{let c=new Ym({bulletListMarker:r,codeBlockStyle:"fenced",fence:n,hr:s,headingStyle:i});return c.remove(["script","style","footer"]),{stdout:`${c.turndown(a).trim()}
438
+ `,stderr:"",exitCode:0}}catch(c){return{stdout:"",stderr:`html-to-markdown: conversion error: ${c.message}
439
+ `,exitCode:1}}}}});var ml={};$(ml,{helpCommand:()=>s0});function n0(t){let e=[],r=new Set(t);e.push(`Available commands:
440
+ `);let n=[];for(let[s,i]of Object.entries(r0)){let o=i.filter(a=>r.has(a));if(o.length>0){e.push(` ${s}:`),e.push(` ${o.join(", ")}
436
441
  `);for(let a of o)r.delete(a)}}for(let s of r)n.push(s);return n.length>0&&(e.push(" Other:"),e.push(` ${n.sort().join(", ")}
437
442
  `)),e.push("Use '<command> --help' for details on a specific command."),`${e.join(`
438
443
  `)}
439
- `}var Tm,Lm,tc=C(()=>{"use strict";Tm={"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"]};Lm={name:"help",async execute(t,e){if(t.includes("--help")||t.includes("-h"))return{stdout:`help - display available commands
444
+ `}var r0,s0,yl=A(()=>{"use strict";r0={"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"]};s0={name:"help",async execute(t,e){if(t.includes("--help")||t.includes("-h"))return{stdout:`help - display available commands
440
445
 
441
446
  Usage: help [command]
442
447
 
@@ -445,119 +450,119 @@ Options:
445
450
 
446
451
  If a command name is provided, shows help for that command.
447
452
  Otherwise, lists all available commands.
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:Dm(r),stderr:"",exitCode:0}}}});var rc={};$(rc,{whichCommand:()=>Bm});var Mm,_m,Bm,nc=C(()=>{"use strict";ue();M();Mm={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"]},_m={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},Bm={name:"which",async execute(t,e){if(v(t))return k(Mm);let r=j("which",t,_m);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 a=(e.env.PATH||"/bin:/usr/bin").split(":"),l="",c=!0;for(let u of i){let f=!1;for(let d of a){if(!d)continue;let p=`${d}/${u}`;if(await e.fs.exists(p)&&(f=!0,s||(l+=`${p}
449
- `),!n))break}f||(c=!1)}return{stdout:l,stderr:"",exitCode:c?0:1}}}});var sc={};$(sc,{tac:()=>Um});async function Wm(t,e){if(t.length>0&&t[0]!=="-"){let s=t[0].startsWith("/")?t[0]:`${e.cwd}/${t[0]}`;try{let o=(await e.fs.readFile(s)).split(`
453
+ `,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:n0(r),stderr:"",exitCode:0}}}});var gl={};$(gl,{whichCommand:()=>a0});var i0,o0,a0,xl=A(()=>{"use strict";fe();_();i0={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"]},o0={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},a0={name:"which",async execute(t,e){if(I(t))return N(i0);let r=G("which",t,o0);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 a=(e.env.PATH||"/bin:/usr/bin").split(":"),c="",l=!0;for(let u of i){let f=!1;for(let p of a){if(!p)continue;let d=`${p}/${u}`;if(await e.fs.exists(d)&&(f=!0,s||(c+=`${d}
454
+ `),!n))break}f||(l=!1)}return{stdout:c,stderr:"",exitCode:l?0:1}}}});var wl={};$(wl,{tac:()=>l0});async function c0(t,e){if(t.length>0&&t[0]!=="-"){let s=t[0].startsWith("/")?t[0]:`${e.cwd}/${t[0]}`;try{let o=(await e.fs.readFile(s)).split(`
450
455
  `);o[o.length-1]===""&&o.pop();let a=o.reverse();return{stdout:a.length>0?`${a.join(`
451
456
  `)}
452
457
  `:"",stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`tac: ${t[0]}: No such file or directory
453
458
  `,exitCode:1}}}let r=e.stdin.split(`
454
459
  `);r[r.length-1]===""&&r.pop();let n=r.reverse();return{stdout:n.length>0?`${n.join(`
455
460
  `)}
456
- `:"",stderr:"",exitCode:0}}var Um,ic=C(()=>{"use strict";Um={name:"tac",execute:Wm}});var oc={};$(oc,{hostname:()=>zm});async function Hm(t,e){return{stdout:`localhost
457
- `,stderr:"",exitCode:0}}var zm,ac=C(()=>{"use strict";zm={name:"hostname",execute:Hm}});var lc={};$(lc,{od:()=>Gm});async function jm(t,e){let r=t.includes("-c"),n=t.includes("-An")?"none":"octal",s=e.stdin,i=t.filter(l=>!l.startsWith("-")&&l!=="-");if(i.length>0){let l=i[0].startsWith("/")?i[0]:`${e.cwd}/${i[0]}`;try{s=await e.fs.readFile(l)}catch{return{stdout:"",stderr:`od: ${i[0]}: No such file or directory
458
- `,exitCode:1}}}if(r){let l=[];for(let u of s){let f=u.charCodeAt(0);f===0?l.push("\\0"):f===9?l.push("\\t"):f===10?l.push("\\n"):f===13?l.push("\\r"):f===32?l.push(" "):f>=32&&f<127?l.push(` ${u}`):l.push(`\\${f.toString(8).padStart(3,"0")}`)}let c=[];for(let u=0;u<l.length;u+=16){let f=l.slice(u,u+16),d=n==="none"?"":`${u.toString(8).padStart(7,"0")} `;c.push(d+f.join(" "))}return n!=="none"&&c.push(s.length.toString(8).padStart(7,"0")),{stdout:`${c.join(`
461
+ `:"",stderr:"",exitCode:0}}var l0,El=A(()=>{"use strict";l0={name:"tac",execute:c0}});var bl={};$(bl,{hostname:()=>f0});async function u0(t,e){return{stdout:`localhost
462
+ `,stderr:"",exitCode:0}}var f0,Sl=A(()=>{"use strict";f0={name:"hostname",execute:u0}});var Al={};$(Al,{od:()=>d0});async function p0(t,e){let r=t.includes("-c"),n=t.includes("-An")?"none":"octal",s=e.stdin,i=t.filter(c=>!c.startsWith("-")&&c!=="-");if(i.length>0){let c=i[0].startsWith("/")?i[0]:`${e.cwd}/${i[0]}`;try{s=await e.fs.readFile(c)}catch{return{stdout:"",stderr:`od: ${i[0]}: No such file or directory
463
+ `,exitCode:1}}}if(r){let c=[];for(let u of s){let f=u.charCodeAt(0);f===0?c.push("\\0"):f===9?c.push("\\t"):f===10?c.push("\\n"):f===13?c.push("\\r"):f===32?c.push(" "):f>=32&&f<127?c.push(` ${u}`):c.push(`\\${f.toString(8).padStart(3,"0")}`)}let l=[];for(let u=0;u<c.length;u+=16){let f=c.slice(u,u+16),p=n==="none"?"":`${u.toString(8).padStart(7,"0")} `;l.push(p+f.join(" "))}return n!=="none"&&l.push(s.length.toString(8).padStart(7,"0")),{stdout:`${l.join(`
459
464
  `)}
460
- `,stderr:"",exitCode:0}}let o=[];for(let l of s)o.push(l.charCodeAt(0).toString(8).padStart(3,"0"));let a=[];for(let l=0;l<o.length;l+=8){let c=o.slice(l,l+8),u=n==="none"?"":`${l.toString(8).padStart(7,"0")} `;a.push(u+c.join(" "))}return n!=="none"&&o.length>0&&a.push(s.length.toString(8).padStart(7,"0")),{stdout:a.length>0?`${a.join(`
465
+ `,stderr:"",exitCode:0}}let o=[];for(let c of s)o.push(c.charCodeAt(0).toString(8).padStart(3,"0"));let a=[];for(let c=0;c<o.length;c+=8){let l=o.slice(c,c+8),u=n==="none"?"":`${c.toString(8).padStart(7,"0")} `;a.push(u+l.join(" "))}return n!=="none"&&o.length>0&&a.push(s.length.toString(8).padStart(7,"0")),{stdout:a.length>0?`${a.join(`
461
466
  `)}
462
- `:"",stderr:"",exitCode:0}}var Gm,cc=C(()=>{"use strict";Gm={name:"od",execute:jm}});function hs(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 ms(t){let e=t.indexOf("=");if(e<0)return null;let r=t.slice(0,e),n=t.slice(e+1),s,i,o=n.match(/;type=([^;]+)$/);o&&(i=o[1],n=n.slice(0,-o[0].length));let a=n.match(/;filename=([^;]+)/);return a&&(s=a[1],n=n.replace(a[0],"")),(n.startsWith("@")||n.startsWith("<"))&&(s=s??n.slice(1).split("/").pop()),{name:r,value:n,filename:s,contentType:i}}function uc(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 a=i.slice(1);i=e.get(a)??""}let o=`--${r}\r
467
+ `:"",stderr:"",exitCode:0}}var d0,Cl=A(()=>{"use strict";d0={name:"od",execute:p0}});function Ss(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 As(t){let e=t.indexOf("=");if(e<0)return null;let r=t.slice(0,e),n=t.slice(e+1),s,i,o=n.match(/;type=([^;]+)$/);o&&(i=o[1],n=n.slice(0,-o[0].length));let a=n.match(/;filename=([^;]+)/);return a&&(s=a[1],n=n.replace(a[0],"")),(n.startsWith("@")||n.startsWith("<"))&&(s=s??n.slice(1).split("/").pop()),{name:r,value:n,filename:s,contentType:i}}function kl(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 a=i.slice(1);i=e.get(a)??""}let o=`--${r}\r
463
468
  `;s.filename?(o+=`Content-Disposition: form-data; name="${s.name}"; filename="${s.filename}"\r
464
469
  `,s.contentType&&(o+=`Content-Type: ${s.contentType}\r
465
470
  `)):o+=`Content-Disposition: form-data; name="${s.name}"\r
466
471
  `,o+=`\r
467
472
  ${i}\r
468
473
  `,n.push(o)}return n.push(`--${r}--\r
469
- `),{body:n.join(""),boundary:r}}var gs=C(()=>{"use strict"});var fc,dc=C(()=>{"use strict";fc={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 pc(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 o=s.slice(0,i).trim(),a=s.slice(i+1).trim();e.headers[o]=a}}}else if(n.startsWith("--header=")){let s=n.slice(9),i=s.indexOf(":");if(i>0){let o=s.slice(0,i).trim(),a=s.slice(i+1).trim();e.headers[o]=a}}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}&`:"")+hs(s),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--data-urlencode=")){let s=n.slice(17);e.data=(e.data?`${e.data}&`:"")+hs(s),e.method==="GET"&&(e.method="POST")}else if(n==="-F"||n==="--form"){let s=t[++r]??"",i=ms(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--form=")){let s=n.slice(7),i=ms(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 hc=C(()=>{"use strict";M();gs()});function xs(t){return Object.entries(t).map(([e,r])=>`${e}: ${r}`).join(`\r
470
- `)}function mc(t){try{return new URL(t).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function ys(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,`
471
- `),r}var gc=C(()=>{"use strict"});var xc={};$(xc,{curlCommand:()=>Xm});async function qm(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 o=e.fs.resolvePath(e.cwd,i.value.slice(1));try{let a=await e.fs.readFile(o);r.set(i.value.slice(1),a)}catch{r.set(i.value.slice(1),"")}}let{body:n,boundary:s}=uc(t.formFields,r);return{body:n,contentType:`multipart/form-data; boundary=${s}`}}return t.data!==void 0?{body:t.data}:{}}function Vm(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 Zm(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 Qm(t,e,r){let n="";if(t.verbose){n+=`> ${t.method} ${r}
474
+ `),{body:n.join(""),boundary:r}}var Cs=A(()=>{"use strict"});var Nl,Il=A(()=>{"use strict";Nl={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 vl(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 o=s.slice(0,i).trim(),a=s.slice(i+1).trim();e.headers[o]=a}}}else if(n.startsWith("--header=")){let s=n.slice(9),i=s.indexOf(":");if(i>0){let o=s.slice(0,i).trim(),a=s.slice(i+1).trim();e.headers[o]=a}}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}&`:"")+Ss(s),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--data-urlencode=")){let s=n.slice(17);e.data=(e.data?`${e.data}&`:"")+Ss(s),e.method==="GET"&&(e.method="POST")}else if(n==="-F"||n==="--form"){let s=t[++r]??"",i=As(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(n.startsWith("--form=")){let s=n.slice(7),i=As(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 L("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 L("curl",`-${s}`)}else n.startsWith("-")||(e.url=n)}}return e}var Rl=A(()=>{"use strict";_();Cs()});function ks(t){return Object.entries(t).map(([e,r])=>`${e}: ${r}`).join(`\r
475
+ `)}function $l(t){try{return new URL(t).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function Ns(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,`
476
+ `),r}var Ol=A(()=>{"use strict"});var Pl={};$(Pl,{curlCommand:()=>x0});async function h0(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 o=e.fs.resolvePath(e.cwd,i.value.slice(1));try{let a=await e.fs.readFile(o);r.set(i.value.slice(1),a)}catch{r.set(i.value.slice(1),"")}}let{body:n,boundary:s}=kl(t.formFields,r);return{body:n,contentType:`multipart/form-data; boundary=${s}`}}return t.data!==void 0?{body:t.data}:{}}function m0(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 y0(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 g0(t,e,r){let n="";if(t.verbose){n+=`> ${t.method} ${r}
472
477
  `;for(let[s,i]of Object.entries(t.headers))n+=`> ${s}: ${i}
473
478
  `;n+=`>
474
479
  `,n+=`< HTTP/1.1 ${e.status} ${e.statusText}
475
480
  `;for(let[s,i]of Object.entries(e.headers))n+=`< ${s}: ${i}
476
481
  `;n+=`<
477
482
  `}return t.includeHeaders&&!t.verbose&&(n+=`HTTP/1.1 ${e.status} ${e.statusText}\r
478
- `,n+=xs(e.headers),n+=`\r
483
+ `,n+=ks(e.headers),n+=`\r
479
484
  \r
480
485
  `),t.headOnly?t.includeHeaders||t.verbose||(n+=`HTTP/1.1 ${e.status} ${e.statusText}\r
481
- `,n+=xs(e.headers),n+=`\r
482
- `):n+=e.body,t.writeOut&&(n+=ys(t.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.length})),n}var Xm,yc=C(()=>{"use strict";_e();M();gs();dc();hc();gc();Xm={name:"curl",async execute(t,e){if(v(t))return k(fc);let r=pc(t);if("exitCode"in r)return r;let n=r;if(!n.url)return{stdout:"",stderr:`curl: no URL specified
486
+ `,n+=ks(e.headers),n+=`\r
487
+ `):n+=e.body,t.writeOut&&(n+=Ns(t.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.length})),n}var x0,Tl=A(()=>{"use strict";We();_();Cs();Il();Rl();Ol();x0={name:"curl",async execute(t,e){if(I(t))return N(Nl);let r=vl(t);if("exitCode"in r)return r;let n=r;if(!n.url)return{stdout:"",stderr:`curl: no URL specified
483
488
  `,exitCode:2};if(!e.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
484
- `,exitCode:1};let s=n.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:o}=await qm(n,e),a=Vm(n,o),l=await e.fetch(s,{method:n.method,headers:Object.keys(a).length>0?a:void 0,body:i,followRedirects:n.followRedirects,timeoutMs:n.timeoutMs});if(await Zm(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}
485
- `:"",exitCode:22};let c=Qm(n,l,s);if(n.outputFile||n.useRemoteName){let u=n.outputFile||mc(s),f=e.fs.resolvePath(e.cwd,u);await e.fs.writeFile(f,n.headOnly?"":l.body),n.verbose||(c=""),n.writeOut&&(c=ys(n.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:c,stderr:"",exitCode:0}}catch(i){let o=te(i),a=1;return o.includes("Network access denied")?a=7:o.includes("HTTP method")&&o.includes("not allowed")?a=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?a=47:o.includes("aborted")&&(a=28),{stdout:"",stderr:!n.silent||n.showError?`curl: (${a}) ${o}
486
- `:"",exitCode:a}}}}});import{tool as dg,zodSchema as pg}from"ai";import{z as Gu}from"zod";var wc=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(gi(),mi))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(yi(),xi))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>(Si(),bi))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(vi(),ki))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(Ii(),Ni))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(Ri(),$i))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>(Fi(),Oi))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>(Ti(),Pi))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(Li(),Di))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>(_i(),Mi))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Ui(),Wi))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(zi(),Hi))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Gi(),ji))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(Qi(),Zi))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(Ki(),Xi))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(eo(),Yi))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(no(),ro))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(Cr(),Sr))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(Cr(),Sr))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(Cr(),Sr))).egrepCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(mo(),ho))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(_o(),Mo))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(Zo(),Vo))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(Xo(),Qo))).uniqCommand},{name:"comm",load:async()=>(await Promise.resolve().then(()=>(Jo(),Ko))).commCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(ea(),Yo))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(na(),ra))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(oa(),ia))).trCommand},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(la(),aa))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(ha(),pa))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(ga(),ma))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(ya(),xa))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(ba(),Ea))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(Aa(),Ca))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Gn(),jn))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Gn(),jn))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(Vn(),qn))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(Vn(),qn))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(Na(),va))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>($a(),Ia))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(Qn(),Zn))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(Qn(),Zn))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(Oa(),Ra))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(Kn(),Xn))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(Kn(),Xn))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(Ta(),Pa))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(Ma(),La))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(Wa(),Ba))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(Ha(),Ua))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(ja(),za))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>(qa(),Ga))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(Za(),Va))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(Xa(),Qa))).exprCommand},{name:"md5sum",load:async()=>(await Promise.resolve().then(()=>(Ya(),Ja))).md5sumCommand},{name:"sha1sum",load:async()=>(await Promise.resolve().then(()=>(tl(),el))).sha1sumCommand},{name:"sha256sum",load:async()=>(await Promise.resolve().then(()=>(nl(),rl))).sha256sumCommand},{name:"file",load:async()=>(await Promise.resolve().then(()=>(Kl(),Xl))).fileCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(Yl(),Jl))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(tc(),ec))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(nc(),rc))).whichCommand},{name:"tac",load:async()=>(await Promise.resolve().then(()=>(ic(),sc))).tac},{name:"hostname",load:async()=>(await Promise.resolve().then(()=>(ac(),oc))).hostname},{name:"od",load:async()=>(await Promise.resolve().then(()=>(cc(),lc))).od}],Km=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(yc(),xc))).curlCommand}],Ec=new Map;function bc(t){return{name:t.name,async execute(e,r){let n=Ec.get(t.name);return n||(n=await t.load(),Ec.set(t.name,n)),n.execute(e,r)}}}function Sc(t){return(t?wc.filter(r=>t.includes(r.name)):wc).map(bc)}function Cc(){return Km.map(bc)}function Ac(t){return"load"in t&&typeof t.load=="function"}function kc(t){let e=null;return{name:t.name,async execute(r,n){return e||(e=await t.load()),e.execute(r,n)}}}var Jm=new TextEncoder,Ym=new TextDecoder;function ws(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 Jm.encode(t)}}function vc(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 Ym.decode(t)}}function Gr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var qr=new TextEncoder;function e0(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var rr=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))e0(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 o=Gr(n),a=ws(r,o);this.data.set(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,r){let n=await this.readFileBuffer(e),s=Gr(r);return vc(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:qr.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 o=Gr(n),a=ws(r,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:qr.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,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),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);n=o}let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=qr.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=qr.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 o of this.data.keys())if(o!==r&&o.startsWith(s)){let l=o.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 o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,r)}}}this.data.delete(n)}async cp(e,r,n){let s=this.normalizePath(e),i=this.normalizePath(r),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){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}};var Nc="5.1.0(1)-release",Ic="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function nr(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function $c(){let{pid:t,ppid:e,uid:r,gid:n}=nr();return`Name: bash
489
+ `,exitCode:1};let s=n.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:o}=await h0(n,e),a=m0(n,o),c=await e.fetch(s,{method:n.method,headers:Object.keys(a).length>0?a:void 0,body:i,followRedirects:n.followRedirects,timeoutMs:n.timeoutMs});if(await y0(n,c.headers,e),n.failSilently&&c.status>=400)return{stdout:"",stderr:n.showError||!n.silent?`curl: (22) The requested URL returned error: ${c.status}
490
+ `:"",exitCode:22};let l=g0(n,c,s);if(n.outputFile||n.useRemoteName){let u=n.outputFile||$l(s),f=e.fs.resolvePath(e.cwd,u);await e.fs.writeFile(f,n.headOnly?"":c.body),n.verbose||(l=""),n.writeOut&&(l=Ns(n.writeOut,{status:c.status,headers:c.headers,url:c.url,bodyLength:c.body.length}))}return{stdout:l,stderr:"",exitCode:0}}catch(i){let o=re(i),a=1;return o.includes("Network access denied")?a=7:o.includes("HTTP method")&&o.includes("not allowed")?a=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?a=47:o.includes("aborted")&&(a=28),{stdout:"",stderr:!n.silent||n.showError?`curl: (${a}) ${o}
491
+ `:"",exitCode:a}}}}});import{tool as Fy,zodSchema as Dy}from"ai";import{z as af}from"zod";var Fl=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(Ci(),Ai))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(Ni(),ki))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>($i(),Ri))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(Fi(),Ti))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(Li(),Di))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(_i(),Mi))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>(Wi(),Bi))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>(Hi(),Ui))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(zi(),ji))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>(qi(),Gi))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Zi(),Ki))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(Xi(),Qi))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Yi(),Ji))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(no(),ro))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(io(),so))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(co(),ao))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(fo(),uo))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(kr(),Cr))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(kr(),Cr))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(kr(),Cr))).egrepCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(Ao(),So))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(qo(),Go))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(ra(),ta))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(sa(),na))).uniqCommand},{name:"comm",load:async()=>(await Promise.resolve().then(()=>(oa(),ia))).commCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(ca(),aa))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(fa(),ua))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(ha(),da))).trCommand},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(ya(),ma))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(Sa(),ba))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(Ca(),Aa))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(Na(),ka))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(Ra(),va))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(Pa(),Oa))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Zn(),Kn))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Zn(),Kn))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(Xn(),Qn))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(Xn(),Qn))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(Da(),Fa))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>(Ma(),La))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(Yn(),Jn))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(Yn(),Jn))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(Ba(),_a))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(ts(),es))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(ts(),es))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(Za(),Ka))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(Ja(),Xa))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(tc(),ec))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(nc(),rc))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(ic(),sc))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>(ac(),oc))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(lc(),cc))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(fc(),uc))).exprCommand},{name:"md5sum",load:async()=>(await Promise.resolve().then(()=>(hc(),dc))).md5sumCommand},{name:"sha1sum",load:async()=>(await Promise.resolve().then(()=>(yc(),mc))).sha1sumCommand},{name:"sha256sum",load:async()=>(await Promise.resolve().then(()=>(xc(),gc))).sha256sumCommand},{name:"file",load:async()=>(await Promise.resolve().then(()=>(pl(),fl))).fileCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(hl(),dl))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(yl(),ml))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(xl(),gl))).whichCommand},{name:"tac",load:async()=>(await Promise.resolve().then(()=>(El(),wl))).tac},{name:"hostname",load:async()=>(await Promise.resolve().then(()=>(Sl(),bl))).hostname},{name:"od",load:async()=>(await Promise.resolve().then(()=>(Cl(),Al))).od}],w0=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(Tl(),Pl))).curlCommand}],Dl=new Map;function Ll(t){return{name:t.name,async execute(e,r){let n=Dl.get(t.name);return n||(n=await t.load(),Dl.set(t.name,n)),n.execute(e,r)}}}function Ml(t){return(t?Fl.filter(r=>t.includes(r.name)):Fl).map(Ll)}function _l(){return w0.map(Ll)}function Bl(t){return"load"in t&&typeof t.load=="function"}function Wl(t){let e=null;return{name:t.name,async execute(r,n){return e||(e=await t.load()),e.execute(r,n)}}}var E0=new TextEncoder,b0=new TextDecoder;function Is(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 E0.encode(t)}}function Ul(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 b0.decode(t)}}function Zr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Qr=new TextEncoder;function S0(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var sr=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))S0(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 o=Zr(n),a=Is(r,o);this.data.set(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,r){let n=await this.readFileBuffer(e),s=Zr(r);return Ul(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:Qr.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 o=Zr(n),a=Is(r,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:Qr.encode(i.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,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),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);n=o}let s=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?s=n.content.length:s=Qr.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=Qr.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 o of this.data.keys())if(o!==r&&o.startsWith(s)){let c=o.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 o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,r)}}}this.data.delete(n)}async cp(e,r,n){let s=this.normalizePath(e),i=this.normalizePath(r),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let c of a){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}};var Hl="5.1.0(1)-release",jl="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function ir(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function zl(){let{pid:t,ppid:e,uid:r,gid:n}=ir();return`Name: bash
487
492
  State: R (running)
488
493
  Pid: ${t}
489
494
  PPid: ${e}
490
495
  Uid: ${r} ${r} ${r} ${r}
491
496
  Gid: ${n} ${n} ${n} ${n}
492
- `}function t0(t){let e=t;return typeof e.mkdirSync=="function"&&typeof e.writeFileSync=="function"}function r0(t,e){t.mkdirSync("/bin",{recursive:!0}),t.mkdirSync("/usr/bin",{recursive:!0}),e&&(t.mkdirSync("/home/user",{recursive:!0}),t.mkdirSync("/tmp",{recursive:!0}))}function n0(t){t.mkdirSync("/dev",{recursive:!0}),t.writeFileSync("/dev/null",""),t.writeFileSync("/dev/zero",new Uint8Array(0)),t.writeFileSync("/dev/stdin",""),t.writeFileSync("/dev/stdout",""),t.writeFileSync("/dev/stderr","")}function s0(t){t.mkdirSync("/proc/self/fd",{recursive:!0}),t.writeFileSync("/proc/version",`${Ic}
497
+ `}function A0(t){let e=t;return typeof e.mkdirSync=="function"&&typeof e.writeFileSync=="function"}function C0(t,e){t.mkdirSync("/bin",{recursive:!0}),t.mkdirSync("/usr/bin",{recursive:!0}),e&&(t.mkdirSync("/home/user",{recursive:!0}),t.mkdirSync("/tmp",{recursive:!0}))}function k0(t){t.mkdirSync("/dev",{recursive:!0}),t.writeFileSync("/dev/null",""),t.writeFileSync("/dev/zero",new Uint8Array(0)),t.writeFileSync("/dev/stdin",""),t.writeFileSync("/dev/stdout",""),t.writeFileSync("/dev/stderr","")}function N0(t){t.mkdirSync("/proc/self/fd",{recursive:!0}),t.writeFileSync("/proc/version",`${jl}
493
498
  `),t.writeFileSync("/proc/self/exe","/bin/bash"),t.writeFileSync("/proc/self/cmdline","bash\0"),t.writeFileSync("/proc/self/comm",`bash
494
- `),t.writeFileSync("/proc/self/status",$c()),t.writeFileSync("/proc/self/fd/0","/dev/stdin"),t.writeFileSync("/proc/self/fd/1","/dev/stdout"),t.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Rc(t,e){t0(t)&&(r0(t,e),n0(t),s0(t))}J();J();function le(t,e){return{type:"ArithmeticExpression",expression:Ve(t,e,0).expr}}function Ve(t,e,r){return i0(t,e,r)}function i0(t,e,r){let{expr:n,pos:s}=Zr(t,e,r);for(s=re(e,s);e[s]===",";){s++;let{expr:i,pos:o}=Zr(t,e,s);n={type:"ArithBinary",operator:",",left:n,right:i},s=re(e,o)}return{expr:n,pos:s}}function Zr(t,e,r){let{expr:n,pos:s}=o0(t,e,r);if(s=re(e,s),e[s]==="?"){s++;let{expr:i,pos:o}=Ve(t,e,s);if(s=re(e,o),e[s]===":"){s++;let{expr:a,pos:l}=Ve(t,e,s);return{expr:{type:"ArithTernary",condition:n,consequent:i,alternate:a},pos:l}}}return{expr:n,pos:s}}function o0(t,e,r){let{expr:n,pos:s}=Oc(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:i,pos:o}=Oc(t,e,s);n={type:"ArithBinary",operator:"||",left:n,right:i},s=o}return{expr:n,pos:s}}function Oc(t,e,r){let{expr:n,pos:s}=Fc(t,e,r);for(;s=re(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:i,pos:o}=Fc(t,e,s);n={type:"ArithBinary",operator:"&&",left:n,right:i},s=o}return{expr:n,pos:s}}function Fc(t,e,r){let{expr:n,pos:s}=Pc(t,e,r);for(;s=re(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:i,pos:o}=Pc(t,e,s);n={type:"ArithBinary",operator:"|",left:n,right:i},s=o}return{expr:n,pos:s}}function Pc(t,e,r){let{expr:n,pos:s}=Tc(t,e,r);for(;s=re(e,s),e[s]==="^";){s++;let{expr:i,pos:o}=Tc(t,e,s);n={type:"ArithBinary",operator:"^",left:n,right:i},s=o}return{expr:n,pos:s}}function Tc(t,e,r){let{expr:n,pos:s}=Dc(t,e,r);for(;s=re(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:i,pos:o}=Dc(t,e,s);n={type:"ArithBinary",operator:"&",left:n,right:i},s=o}return{expr:n,pos:s}}function Dc(t,e,r){let{expr:n,pos:s}=Lc(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:o,pos:a}=Lc(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function Lc(t,e,r){let{expr:n,pos:s}=Es(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:o,pos:a}=Es(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else if(e[s]==="<"||e[s]===">"){let i=e[s];s++;let{expr:o,pos:a}=Es(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else break;return{expr:n,pos:s}}function Es(t,e,r){let{expr:n,pos:s}=Mc(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:o,pos:a}=Mc(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function Mc(t,e,r){let{expr:n,pos:s}=_c(t,e,r);for(;s=re(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let i=e[s];s++;let{expr:o,pos:a}=_c(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function _c(t,e,r){let{expr:n,pos:s}=Vr(t,e,r);for(;;)if(s=re(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:i,pos:o}=Vr(t,e,s);n={type:"ArithBinary",operator:"*",left:n,right:i},s=o}else if(e[s]==="/"||e[s]==="%"){let i=e[s];s++;let{expr:o,pos:a}=Vr(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else break;return{expr:n,pos:s}}function Vr(t,e,r){let{expr:n,pos:s}=bs(t,e,r),i=re(e,s);if(e.slice(i,i+2)==="**"){i+=2;let{expr:o,pos:a}=Vr(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:n,right:o},pos:a}}return{expr:n,pos:s}}function bs(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:o}=bs(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(e[n]==="+"||e[n]==="-"||e[n]==="!"||e[n]==="~"){let s=e[n];n++;let{expr:i,pos:o}=bs(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return l0(t,e,n)}function a0(t,e){let r=t[e];return r==="$"||r==="`"}function l0(t,e,r){let{expr:n,pos:s}=Bc(t,e,r),i=[n];for(;a0(e,s);){let{expr:o,pos:a}=Bc(t,e,s);i.push(o),s=a}if(i.length>1&&(n={type:"ArithConcat",parts:i}),s=re(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let o=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:o,operand:n,prefix:!1},pos:s}}return{expr:n,pos:s}}function Bc(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 o=e.slice(i,n),{expr:a}=Ve(t,o,0);return n+=2,{expr:{type:"ArithNested",expression:a},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 o=e.slice(i,n);return n++,{expr:{type:"ArithCommandSubst",command:o},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 a=e[n];if(i)if(/[0-9a-zA-Z@_]/.test(a))s+=a,n++;else break;else if(a==="#")i=!0,s+=a,n++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,n++;else break}if(e[n]==="."&&/[0-9]/.test(e[n+1]))throw new oe(`${s}.${e[n+1]}...: syntax error: invalid arithmetic operator`);if(e[n]==="["){let a=e.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Lt(s)},pos:n}}if(e[n]==="$"&&e[n+1]==="{"){let s=n+2,i=1,o=s;for(;o<e.length&&i>0;)e[o]==="{"?i++:e[o]==="}"&&i--,i>0&&o++;let a=e.slice(s,o),l=o+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:a,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:a,suffix:u},pos:c}}return n=l,{expr:{type:"ArithBracedExpansion",content:a},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 o;if(e[n]==="'"||e[n]==='"'){let c=e[n];for(n++,o="";n<e.length&&e[n]!==c;)o+=e[n],n++;e[n]===c&&n++,n=re(e,n),e[n]==="]"&&n++}let a;if(o===void 0){let{expr:c,pos:u}=Ve(t,e,n);a=c,n=u,e[n]==="]"&&n++}if(n=re(e,n),e[n]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},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}=Zr(t,e,n);return{expr:{type:"ArithAssignment",operator:c,variable:s,subscript:a,stringKey:o,value:u},pos:f}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:o},pos:n}}n=re(e,n);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let o of i)if(e.slice(n,n+o.length)===o&&e.slice(n,n+o.length+1)!=="=="){n+=o.length;let{expr:a,pos:l}=Zr(t,e,n);return{expr:{type:"ArithAssignment",operator:o,variable:s,value:a},pos:l}}return{expr:{type:"ArithVariable",name:s},pos:n}}return{expr:{type:"ArithNumber",value:0},pos:n}}function Lt(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 o;if(i>="0"&&i<="9")o=i.charCodeAt(0)-48;else if(i>="a"&&i<="z")o=i.charCodeAt(0)-97+10;else if(i>="A"&&i<="Z")o=i.charCodeAt(0)-65+36;else if(i==="@")o=62;else if(i==="_")o=63;else return Number.NaN;if(o>=n)return Number.NaN;s=s*n+o}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]===`
495
- `){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 Qr={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 Uc(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 c0=[[";",";","&",m.SEMI_SEMI_AND],["<","<","<",m.TLESS],["&",">",">",m.AND_DGREAT]],u0=[["[","[",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]],f0={"|":m.PIPE,"&":m.AMP,";":m.SEMICOLON,"(":m.LPAREN,")":m.RPAREN,"<":m.LESS,">":m.GREAT};function d0(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Xr=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 o=e[n];if(o===" "||o===" ")n++,s++;else if(o==="\\"&&e[n+1]===`
499
+ `),t.writeFileSync("/proc/self/status",zl()),t.writeFileSync("/proc/self/fd/0","/dev/stdin"),t.writeFileSync("/proc/self/fd/1","/dev/stdout"),t.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Gl(t,e){A0(t)&&(C0(t,e),k0(t),N0(t))}J();J();function le(t,e){return{type:"ArithmeticExpression",expression:Ze(t,e,0).expr}}function Ze(t,e,r){return I0(t,e,r)}function I0(t,e,r){let{expr:n,pos:s}=Jr(t,e,r);for(s=ne(e,s);e[s]===",";){s++;let{expr:i,pos:o}=Jr(t,e,s);n={type:"ArithBinary",operator:",",left:n,right:i},s=ne(e,o)}return{expr:n,pos:s}}function Jr(t,e,r){let{expr:n,pos:s}=v0(t,e,r);if(s=ne(e,s),e[s]==="?"){s++;let{expr:i,pos:o}=Ze(t,e,s);if(s=ne(e,o),e[s]===":"){s++;let{expr:a,pos:c}=Ze(t,e,s);return{expr:{type:"ArithTernary",condition:n,consequent:i,alternate:a},pos:c}}}return{expr:n,pos:s}}function v0(t,e,r){let{expr:n,pos:s}=ql(t,e,r);for(;s=ne(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:i,pos:o}=ql(t,e,s);n={type:"ArithBinary",operator:"||",left:n,right:i},s=o}return{expr:n,pos:s}}function ql(t,e,r){let{expr:n,pos:s}=Vl(t,e,r);for(;s=ne(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:i,pos:o}=Vl(t,e,s);n={type:"ArithBinary",operator:"&&",left:n,right:i},s=o}return{expr:n,pos:s}}function Vl(t,e,r){let{expr:n,pos:s}=Kl(t,e,r);for(;s=ne(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:i,pos:o}=Kl(t,e,s);n={type:"ArithBinary",operator:"|",left:n,right:i},s=o}return{expr:n,pos:s}}function Kl(t,e,r){let{expr:n,pos:s}=Zl(t,e,r);for(;s=ne(e,s),e[s]==="^";){s++;let{expr:i,pos:o}=Zl(t,e,s);n={type:"ArithBinary",operator:"^",left:n,right:i},s=o}return{expr:n,pos:s}}function Zl(t,e,r){let{expr:n,pos:s}=Ql(t,e,r);for(;s=ne(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:i,pos:o}=Ql(t,e,s);n={type:"ArithBinary",operator:"&",left:n,right:i},s=o}return{expr:n,pos:s}}function Ql(t,e,r){let{expr:n,pos:s}=Xl(t,e,r);for(;s=ne(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let i=e.slice(s,s+2);s+=2;let{expr:o,pos:a}=Xl(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function Xl(t,e,r){let{expr:n,pos:s}=vs(t,e,r);for(;;)if(s=ne(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let i=e.slice(s,s+2);s+=2;let{expr:o,pos:a}=vs(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else if(e[s]==="<"||e[s]===">"){let i=e[s];s++;let{expr:o,pos:a}=vs(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else break;return{expr:n,pos:s}}function vs(t,e,r){let{expr:n,pos:s}=Jl(t,e,r);for(;s=ne(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let i=e.slice(s,s+2);s+=2;let{expr:o,pos:a}=Jl(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function Jl(t,e,r){let{expr:n,pos:s}=Yl(t,e,r);for(;s=ne(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let i=e[s];s++;let{expr:o,pos:a}=Yl(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}return{expr:n,pos:s}}function Yl(t,e,r){let{expr:n,pos:s}=Xr(t,e,r);for(;;)if(s=ne(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:i,pos:o}=Xr(t,e,s);n={type:"ArithBinary",operator:"*",left:n,right:i},s=o}else if(e[s]==="/"||e[s]==="%"){let i=e[s];s++;let{expr:o,pos:a}=Xr(t,e,s);n={type:"ArithBinary",operator:i,left:n,right:o},s=a}else break;return{expr:n,pos:s}}function Xr(t,e,r){let{expr:n,pos:s}=Rs(t,e,r),i=ne(e,s);if(e.slice(i,i+2)==="**"){i+=2;let{expr:o,pos:a}=Xr(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:n,right:o},pos:a}}return{expr:n,pos:s}}function Rs(t,e,r){let n=ne(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:o}=Rs(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(e[n]==="+"||e[n]==="-"||e[n]==="!"||e[n]==="~"){let s=e[n];n++;let{expr:i,pos:o}=Rs(t,e,n);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return $0(t,e,n)}function R0(t,e){let r=t[e];return r==="$"||r==="`"}function $0(t,e,r){let{expr:n,pos:s}=eu(t,e,r),i=[n];for(;R0(e,s);){let{expr:o,pos:a}=eu(t,e,s);i.push(o),s=a}if(i.length>1&&(n={type:"ArithConcat",parts:i}),s=ne(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let o=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:o,operand:n,prefix:!1},pos:s}}return{expr:n,pos:s}}function eu(t,e,r){let n=ne(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 o=e.slice(i,n),{expr:a}=Ze(t,o,0);return n+=2,{expr:{type:"ArithNested",expression:a},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 o=e.slice(i,n);return n++,{expr:{type:"ArithCommandSubst",command:o},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}=Ze(t,e,n);return n=ne(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 a=e[n];if(i)if(/[0-9a-zA-Z@_]/.test(a))s+=a,n++;else break;else if(a==="#")i=!0,s+=a,n++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,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 a=e.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Wt(s)},pos:n}}if(e[n]==="$"&&e[n+1]==="{"){let s=n+2,i=1,o=s;for(;o<e.length&&i>0;)e[o]==="{"?i++:e[o]==="}"&&i--,i>0&&o++;let a=e.slice(s,o),c=o+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:a,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:a,suffix:u},pos:l}}return n=c,{expr:{type:"ArithBracedExpansion",content:a},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 o;if(e[n]==="'"||e[n]==='"'){let l=e[n];for(n++,o="";n<e.length&&e[n]!==l;)o+=e[n],n++;e[n]===l&&n++,n=ne(e,n),e[n]==="]"&&n++}let a;if(o===void 0){let{expr:l,pos:u}=Ze(t,e,n);a=l,n=u,e[n]==="]"&&n++}if(n=ne(e,n),e[n]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},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}=Jr(t,e,n);return{expr:{type:"ArithAssignment",operator:l,variable:s,subscript:a,stringKey:o,value:u},pos:f}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:o},pos:n}}n=ne(e,n);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let o of i)if(e.slice(n,n+o.length)===o&&e.slice(n,n+o.length+1)!=="=="){n+=o.length;let{expr:a,pos:c}=Jr(t,e,n);return{expr:{type:"ArithAssignment",operator:o,variable:s,value:a},pos:c}}return{expr:{type:"ArithVariable",name:s},pos:n}}return{expr:{type:"ArithNumber",value:0},pos:n}}function Wt(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 o;if(i>="0"&&i<="9")o=i.charCodeAt(0)-48;else if(i>="a"&&i<="z")o=i.charCodeAt(0)-97+10;else if(i>="A"&&i<="Z")o=i.charCodeAt(0)-65+36;else if(i==="@")o=62;else if(i==="_")o=63;else return Number.NaN;if(o>=n)return Number.NaN;s=s*n+o}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 ne(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
500
+ `){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var v={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 Yr={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 ru(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 O0=[[";",";","&",m.SEMI_SEMI_AND],["<","<","<",m.TLESS],["&",">",">",m.AND_DGREAT]],P0=[["[","[",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]],T0={"|":m.PIPE,"&":m.AMP,";":m.SEMICOLON,"(":m.LPAREN,")":m.RPAREN,"<":m.LESS,">":m.GREAT};function F0(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var en=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 o=e[n];if(o===" "||o===" ")n++,s++;else if(o==="\\"&&e[n+1]===`
496
501
  `)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],o=e[r+1],a=e[r+2];if(i==="#")return this.readComment(r,n,s);if(i===`
497
502
  `)return this.pos=r+1,this.line++,this.column=1,{type:m.NEWLINE,value:`
498
- `,start:r,end:r+1,line:n,column:s};if(i==="<"&&o==="<"&&a==="-")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 c0)if(i===c&&o===u&&a===f)return this.pos=r+3,this.column=s+3,this.makeToken(d,c+u+f,r,n,s);if(i==="<"&&o==="<")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 u0)if(i===c&&o===u)return this.pos=r+2,this.column=s+2,this.makeToken(f,c+u,r,n,s);let l=f0[i];return l?(this.pos=r+1,this.column=s+1,this.makeToken(l,i,r,n,s)):i==="{"?o==="}"?(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):o!==void 0&&o!==" "&&o!==" "&&o!==`
503
+ `,start:r,end:r+1,line:n,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=r+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(m.DLESSDASH,"<<-",r,n,s);for(let[l,u,f,p]of O0)if(i===l&&o===u&&a===f)return this.pos=r+3,this.column=s+3,this.makeToken(p,l+u+f,r,n,s);if(i==="<"&&o==="<")return this.pos=r+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(m.DLESS,"<<",r,n,s);for(let[l,u,f]of P0)if(i===l&&o===u)return this.pos=r+2,this.column=s+2,this.makeToken(f,l+u,r,n,s);let c=T0[i];return c?(this.pos=r+1,this.column=s+1,this.makeToken(c,i,r,n,s)):i==="{"?o==="}"?(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):o!==void 0&&o!==" "&&o!==" "&&o!==`
499
504
  `?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==="!"?o==="="?(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,o=this.pos;for(;o<i&&s[o]!==`
500
- `;)o++;let a=s.slice(e,o);return this.pos=o,this.column=n+(o-e),{type:m.COMMENT,value:a,start:e,end:o,line:r,column:n}}readWord(e,r,n){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let g=s[o];if(g===" "||g===" "||g===`
501
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"||g==="'"||g==='"'||g==="\\"||g==="$"||g==="`"||g==="{"||g==="}"||g==="~"||g==="*"||g==="?"||g==="[")break;o++}if(o>a){let g=s[o];if(o>=i||g===" "||g===" "||g===`
502
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"){let y=s.slice(a,o);if(this.pos=o,this.column=n+(o-a),Qr[y])return{type:Qr[y],value:y,start:e,end:o,line:r,column:n};let E=y.indexOf("=");return E>0&&Uc(y.slice(0,E))?{type:m.ASSIGNMENT_WORD,value:y,start:e,end:o,line:r,column:n}:/^[0-9]+$/.test(y)?{type:m.NUMBER,value:y,start:e,end:o,line:r,column:n}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(y)?{type:m.NAME,value:y,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}:{type:m.WORD,value:y,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}}}o=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,p=!1,h=!1,w=s[o]==='"'||s[o]==="'";for(;o<i;){let g=s[o];if(!p&&!h&&(g===" "||g===" "||g===`
503
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"))break;if(g==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(g==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,u===""&&(w=!0),o++,l++;continue}if(g==="'"&&!h){p?(p=!1,w||(u+=g)):(p=!0,w?(d=!0,f=!0):u+=g),o++,l++;continue}if(g==='"'&&!p){h?(h=!1,w||(u+=g)):(h=!0,w?f=!0:u+=g),o++,l++;continue}if(g==="\\"&&!p&&o+1<i){let y=s[o+1];if(y===`
504
- `){o+=2,c++,l=1;continue}if(h){if(y==='"'||y==="\\"||y==="$"||y==="`"||y===`
505
- `){y==="$"||y==="`"?u+=g+y:u+=y,o+=2,l+=2;continue}}else{y==='"'||y==="'"?u+=g+y:u+=y,o+=2,l+=2;continue}}if(g==="$"&&o+1<i&&s[o+1]==="("){u+=g,o++,l++,u+=s[o],o++,l++;let y=1,E=!1,b=!1,S=0,A=!1,D="",P=s[o]==="(";for(;y>0&&o<i;){let F=s[o];if(u+=F,E)F==="'"&&(E=!1);else if(b)F==="\\"&&o+1<i?(u+=s[o+1],o++,l++):F==='"'&&(b=!1);else if(F==="'")E=!0,D="";else if(F==='"')b=!0,D="";else if(F==="\\"&&o+1<i)u+=s[o+1],o++,l++,D="";else if(F==="#"&&!P&&(D===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
506
- `;)o++,l++,u+=s[o];D=""}else/[a-zA-Z_]/.test(F)?D+=F:(D==="case"?(S++,A=!1):D==="in"&&S>0?A=!0:D==="esac"&&S>0&&(S--,A=!1),D="",F==="("?o>0&&s[o-1]==="$"?y++:A||y++:F===")"?A?A=!1:y--:F===";"&&S>0&&o+1<i&&s[o+1]===";"&&(A=!0));F===`
507
- `&&(c++,l=0,D=""),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="["){u+=g,o++,l++,u+=s[o],o++,l++;let y=1;for(;y>0&&o<i;){let E=s[o];u+=E,E==="["?y++:E==="]"?y--:E===`
508
- `&&(c++,l=0),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="{"){u+=g,o++,l++,u+=s[o],o++,l++;let y=1;for(;y>0&&o<i;){let E=s[o];u+=E,E==="{"?y++:E==="}"?y--:E===`
509
- `&&(c++,l=0),o++,l++}continue}if(g==="$"&&o+1<i){let y=s[o+1];if(y==="#"||y==="?"||y==="$"||y==="!"||y==="@"||y==="*"||y==="-"||y>="0"&&y<="9"){u+=g+y,o+=2,l+=2;continue}}if(g==="`"){for(u+=g,o++,l++;o<i&&s[o]!=="`";){let y=s[o];u+=y,y==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),y===`
510
- `&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=g,o++,g===`
511
- `?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,u==="")return{type:m.WORD,value:"",start:e,end:o,line:r,column:n,quoted:f,singleQuoted:d};if(!f&&Qr[u])return{type:Qr[u],value:u,start:e,end:o,line:r,column:n};if(!w){let g=u.indexOf("=");if(g>0&&Uc(u.slice(0,g)))return{type:m.ASSIGNMENT_WORD,value:u,start:e,end:o,line:r,column:n,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:m.NUMBER,value:u,start:e,end:o,line:r,column:n}:d0(u)?{type:m.NAME,value:u,start:e,end:o,line:r,column:n,quoted:f,singleQuoted:d}:{type:m.WORD,value:u,start:e,end:o,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 o=this.pos,a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
505
+ `;)o++;let a=s.slice(e,o);return this.pos=o,this.column=n+(o-e),{type:m.COMMENT,value:a,start:e,end:o,line:r,column:n}}readWord(e,r,n){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let y=s[o];if(y===" "||y===" "||y===`
506
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;o++}if(o>a){let y=s[o];if(o>=i||y===" "||y===" "||y===`
507
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let w=s.slice(a,o);if(this.pos=o,this.column=n+(o-a),Yr[w])return{type:Yr[w],value:w,start:e,end:o,line:r,column:n};let E=w.indexOf("=");return E>0&&ru(w.slice(0,E))?{type:m.ASSIGNMENT_WORD,value:w,start:e,end:o,line:r,column:n}:/^[0-9]+$/.test(w)?{type:m.NUMBER,value:w,start:e,end:o,line:r,column:n}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:m.NAME,value:w,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}:{type:m.WORD,value:w,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}}}o=this.pos;let c=this.column,l=this.line,u="",f=!1,p=!1,d=!1,h=!1,g=s[o]==='"'||s[o]==="'";for(;o<i;){let y=s[o];if(!d&&!h&&(y===" "||y===" "||y===`
508
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"))break;if(y==="$"&&o+1<i&&s[o+1]==="'"&&!d&&!h){for(u+="$'",o+=2,c+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,c+=2):(u+=s[o],o++,c++);o<i&&(u+="'",o++,c++);continue}if(y==="$"&&o+1<i&&s[o+1]==='"'&&!d&&!h){o++,c++,h=!0,f=!0,u===""&&(g=!0),o++,c++;continue}if(y==="'"&&!h){d?(d=!1,g||(u+=y)):(d=!0,g?(p=!0,f=!0):u+=y),o++,c++;continue}if(y==='"'&&!d){h?(h=!1,g||(u+=y)):(h=!0,g?f=!0:u+=y),o++,c++;continue}if(y==="\\"&&!d&&o+1<i){let w=s[o+1];if(w===`
509
+ `){o+=2,l++,c=1;continue}if(h){if(w==='"'||w==="\\"||w==="$"||w==="`"||w===`
510
+ `){w==="$"||w==="`"?u+=y+w:u+=w,o+=2,c+=2;continue}}else{w==='"'||w==="'"?u+=y+w:u+=w,o+=2,c+=2;continue}}if(y==="$"&&o+1<i&&s[o+1]==="("){u+=y,o++,c++,u+=s[o],o++,c++;let w=1,E=!1,b=!1,S=0,C=!1,O="",D=s[o]==="(";for(;w>0&&o<i;){let F=s[o];if(u+=F,E)F==="'"&&(E=!1);else if(b)F==="\\"&&o+1<i?(u+=s[o+1],o++,c++):F==='"'&&(b=!1);else if(F==="'")E=!0,O="";else if(F==='"')b=!0,O="";else if(F==="\\"&&o+1<i)u+=s[o+1],o++,c++,O="";else if(F==="#"&&!D&&(O===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
511
+ `;)o++,c++,u+=s[o];O=""}else/[a-zA-Z_]/.test(F)?O+=F:(O==="case"?(S++,C=!1):O==="in"&&S>0?C=!0:O==="esac"&&S>0&&(S--,C=!1),O="",F==="("?o>0&&s[o-1]==="$"?w++:C||w++:F===")"?C?C=!1:w--:F===";"&&S>0&&o+1<i&&s[o+1]===";"&&(C=!0));F===`
512
+ `&&(l++,c=0,O=""),o++,c++}continue}if(y==="$"&&o+1<i&&s[o+1]==="["){u+=y,o++,c++,u+=s[o],o++,c++;let w=1;for(;w>0&&o<i;){let E=s[o];u+=E,E==="["?w++:E==="]"?w--:E===`
513
+ `&&(l++,c=0),o++,c++}continue}if(y==="$"&&o+1<i&&s[o+1]==="{"){u+=y,o++,c++,u+=s[o],o++,c++;let w=1;for(;w>0&&o<i;){let E=s[o];u+=E,E==="{"?w++:E==="}"?w--:E===`
514
+ `&&(l++,c=0),o++,c++}continue}if(y==="$"&&o+1<i){let w=s[o+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){u+=y+w,o+=2,c+=2;continue}}if(y==="`"){for(u+=y,o++,c++;o<i&&s[o]!=="`";){let w=s[o];u+=w,w==="\\"&&o+1<i&&(u+=s[o+1],o++,c++),w===`
515
+ `&&(l++,c=0),o++,c++}o<i&&(u+=s[o],o++,c++);continue}u+=y,o++,y===`
516
+ `?(l++,c=1):c++}if(this.pos=o,this.column=c,this.line=l,u==="")return{type:m.WORD,value:"",start:e,end:o,line:r,column:n,quoted:f,singleQuoted:p};if(!f&&Yr[u])return{type:Yr[u],value:u,start:e,end:o,line:r,column:n};if(!g){let y=u.indexOf("=");if(y>0&&ru(u.slice(0,y)))return{type:m.ASSIGNMENT_WORD,value:u,start:e,end:o,line:r,column:n,quoted:f,singleQuoted:p}}return/^[0-9]+$/.test(u)?{type:m.NUMBER,value:u,start:e,end:o,line:r,column:n}:F0(u)?{type:m.NAME,value:u,start:e,end:o,line:r,column:n,quoted:f,singleQuoted:p}:{type:m.WORD,value:u,start:e,end:o,line:r,column:n,quoted:f,singleQuoted:p}}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 o=this.pos,a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
512
517
  `;)a+=this.input[this.pos],this.pos++,this.column++;if((e.stripTabs?a.replace(/^\t+/,""):a)===e.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
513
518
  `&&(this.pos++,this.line++,this.column=1);break}i+=a,this.pos<this.input.length&&this.input[this.pos]===`
514
519
  `&&(i+=`
515
520
  `,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,o=this.input[this.pos];if(o==="'"||o==='"'){i=!0;let a=o;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==a;)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===`
516
- `||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(e,r,n){let s=this.input,i=s.length,o=e,a=n;for(;o<i;){let c=s[o];if(c===" "||c===" "||c===`
517
- `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(e,o);return this.pos=o,this.column=a,{type:m.WORD,value:l,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let r=this.input,n=r.length,s=e+1,i=1,o=!1,a=!1;for(;s<n&&i>0;){let l=r[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<n&&r[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
518
- `||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(o||a)?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 o=r[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return r.slice(e,s+1);s++}else{if(o===" "||o===" "||o===`
519
- `||o===";"||o==="&"||o==="|")return null;s++}}return null}};var Ss=1e6,Cs=1e5,Hc=1e6,zc=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]),jc=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 qc(t,e,r){let n=r+1;for(;n<e.length&&/[a-zA-Z0-9_-]/.test(e[n]);)n++;return n}function As(t,e,r,n,s){let i=1,o=r+1;for(;o<e.length&&i>0;)e[o]===n?i++:e[o]===s&&i--,i>0&&o++;return i===0?o:-1}function mt(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 o=e.indexOf("'",n+1);if(o!==-1){n=o+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 Vc(t,e,r){let n=r,s=!1;for(;n<e.length;){let i=e[n];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=e.indexOf("'",n+1);if(o!==-1){n=o+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 Zc(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 o=p0(e,n);o===-1?(s+=i,n++):(s+=e.slice(n,o+1),n=o+1)}else break}return{pattern:s,endIndex:n}}function p0(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]}]`,o=t.indexOf(i,r+2);if(o!==-1){r=o+2;continue}}r++}return-1}function Qc(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+=`
520
- `,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 a=e.slice(s+2,s+4),l=parseInt(a,16);Number.isNaN(l)?(n+="\\x",s+=2):(n+=String.fromCharCode(l),s+=4);break}case"u":{let a=e.slice(s+2,s+6),l=parseInt(a,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 a="",l=s+1;for(;l<e.length&&l<s+4&&/[0-7]/.test(e[l]);)a+=e[l],l++;let c=parseInt(a,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 ks(t,e){let r=e.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:le(t,r)}function Gc(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 Xc(t,e,r,n){let s=As(t,e,r,"{","}");if(s===-1)return null;let i=e.slice(r+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&n?{part:{type:"BraceExpansion",items:Gc(i).map(u=>({type:"Word",word:N.word(n(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Gc(i).map(u=>({type:"Word",word:N.word([N.literal(u)])}))},endIndex:s+1}:null}function Kc(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 Jc(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 Kr(t){let e=t.current(),r=e.type;if(r===m.NUMBER){let n=t.peek(1);return e.end!==n.start?!1:jc.has(n.type)}return zc.has(r)}function Jr(t){let e=null;t.check(m.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let r=t.advance(),n=Jc(t,r.type);if(r.type===m.DLESS||r.type===m.DLESSDASH)return h0(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 h0(t,e,r,n){t.isWord()||t.error("Expected here-document delimiter");let s=t.advance(),i=s.value,o=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let a=N.redirection(n?"<<-":"<<",N.hereDoc(i,N.word([]),n,o),r);return t.addPendingHeredoc(a,i,n,o),a}function eu(t){let e=t.current().line,r=[],n=null,s=[],i=[];for(;t.check(m.ASSIGNMENT_WORD);)t.checkIterationLimit(),r.push(m0(t));for(;Kr(t);)t.checkIterationLimit(),i.push(Jr(t));for(t.isWord()&&(n=t.parseWord());(!t.isStatementEnd()||t.check(m.RBRACE))&&!t.check(m.PIPE,m.PIPE_AMP);)if(t.checkIterationLimit(),Kr(t))i.push(Jr(t));else if(t.check(m.RBRACE)){let a=t.advance();s.push(t.parseWordFromString(a.value,!1,!1))}else if(t.isWord())s.push(t.parseWord());else if(t.check(m.ASSIGNMENT_WORD)){let a=t.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||t.check(m.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||t.expect(m.LPAREN);let d=vs(t);t.expect(m.RPAREN);let p=d.map(w=>Kc(t,w)),h=`${f}=(${p.join(" ")})`;s.push(t.parseWordFromString(h,!1,!1))}else s.push(t.parseWordFromString(l,a.quoted,a.singleQuoted))}else if(t.check(m.LPAREN))t.error("syntax error near unexpected token `('");else break;let o=N.simpleCommand(n,s,r,i);return o.line=e,o}function m0(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,o=s.length;if(r[o]==="["){let f=0,d=o+1;for(;o<r.length;o++)if(r[o]==="[")f++;else if(r[o]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${r}`),i=r.slice(d,o),o++}let a=r[o]==="+";a&&o++,r[o]!=="="&&t.error(`Invalid assignment: ${r}`),o++;let l=r.slice(o);if(l==="("){let f=vs(t);t.expect(m.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return N.assignment(d,null,a,f)}if(l===""&&t.check(m.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let d=vs(t);t.expect(m.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return N.assignment(p,null,a,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,a,null)}function vs(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 Ns(t){t.expect(m.IF);let e=[],r=t.parseCompoundList();t.expect(m.THEN);let n=t.parseCompoundList();if(n.length===0){let o=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${o}'`)}for(e.push({condition:r,body:n});t.check(m.ELIF);){t.advance();let o=t.parseCompoundList();t.expect(m.THEN);let a=t.parseCompoundList();if(a.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:o,body:a})}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 Is(t){if(t.expect(m.FOR),t.check(m.DPAREN_START))return x0(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 x0(t){t.expect(m.DPAREN_START);let e=null,r=null,n=null,s=["","",""],i=0,o=0;for(;!t.check(m.DPAREN_END,m.EOF);){let c=t.advance();if(c.type===m.SEMICOLON&&o===0){if(i++,i>2)break}else c.value==="("&&o++,c.value===")"&&o--,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 a=t.parseCompoundList();t.expect(m.DONE);let l=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:r,update:n,body:a,redirections:l}}function $s(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 Rs(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 Os(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=y0(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 y0(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 Fs(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 Ps(t){t.expect(m.LBRACE);let e=t.parseCompoundList();t.expect(m.RBRACE);let r=t.parseOptionalRedirections();return N.group(e,r)}var E0=["-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"],b0=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Ds(t){return t.skipNewlines(),S0(t)}function S0(t){let e=tu(t);for(t.skipNewlines();t.check(m.OR_OR);){t.advance(),t.skipNewlines();let r=tu(t);e={type:"CondOr",left:e,right:r},t.skipNewlines()}return e}function tu(t){let e=Ts(t);for(t.skipNewlines();t.check(m.AND_AND);){t.advance(),t.skipNewlines();let r=Ts(t);e={type:"CondAnd",left:e,right:r},t.skipNewlines()}return e}function Ts(t){return t.skipNewlines(),t.check(m.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Ts(t)}):C0(t)}function C0(t){if(t.check(m.LPAREN)){t.advance();let e=Ds(t);return t.expect(m.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),r=e.value;if(E0.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()&&b0.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 k0(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 v0(t,e,r,n=!1){let s=r+2,i=!1;e[s]==="!"&&(i=!0,s++);let o=!1;e[s]==="#"&&!/[}:#%/^,]/.test(e[s+1]||"}")&&(o=!0,s++);let a="",l=e[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(e[s+1]||""))a=l,s++;else for(;s<e.length&&/[a-zA-Z0-9_]/.test(e[s]);)a+=e[s],s++;if(e[s]==="["){let u=As(t,e,s,"[","]");a+=e.slice(s,u+1),s=u+1}a===""&&!i&&!o&&e[s]!=="}"&&t.error(`\${${e[s]}}: bad substitution`);let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(e[s]==="*"||e[s]==="@"){let f=e[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else c={type:"Indirection"}}else if(o)if(e[s]===":")for(c={type:"LengthSliceError"};s<e.length&&e[s]!=="}";)s++;else e[s]!=="}"&&/[-+=?]/.test(e[s])?t.error(`\${#${a}${e.slice(s,e.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<e.length&&e[s]!=="}"){let u=N0(t,e,s,a,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(a,c),endIndex:s+1}}function N0(t,e,r,n,s=!1){let i=r,o=e[i],a=e[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let y=mt(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=mt(t,e,i),u=e.slice(i,c),f=-1,d=0,p=0;for(let g=0;g<u.length;g++){let y=u[g];if(y==="("||y==="[")d++;else if(y===")"||y==="]")d--;else if(y==="?"&&d===0)p++;else if(y===":"&&d===0)if(p>0)p--;else{f=g;break}}let h=f>=0?u.slice(0,f):u,w=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:ks(t,h),length:w?ks(t,w):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=mt(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(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=mt(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(o==="/"){let l=a==="/";i+=l?2:1;let c=null;e[i]==="#"?(c="start",i++):e[i]==="%"&&(c="end",i++);let u=Vc(t,e,i),f=e.slice(i,u),d=rt(t,f,!1,!1,!1),p=N.word(d.length>0?d:[N.literal("")]),h=null,w=u;if(e[u]==="/"){let g=u+1,y=mt(t,e,g),E=e.slice(g,y),b=rt(t,E,!1,!1,!1);h=N.word(b.length>0?b:[N.literal("")]),w=y}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:w}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=mt(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 o==="@"&&/[QPaAEK]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Ls(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 o=1,a=s+1;for(;a<e.length&&o>0;)e[a]==="["?o++:e[a]==="]"&&o--,o>0&&a++;if(o===0){let l=e.slice(s+1,a),c=le(t,l);return{part:N.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?t.parseCommandSubstitution(e,r):i==="{"?v0(t,e,r,n):/[a-zA-Z_0-9@*#?$!-]/.test(i)?k0(t,e,r):{part:N.literal("$"),endIndex:s}}function I0(t,e){let r=[],n=0,s="",i=()=>{s&&(r.push(N.literal(s)),s="")};for(;n<e.length;){let o=e[n];if(o==="\\"&&n+1<e.length){let a=e[n+1];if(a==="$"||a==="`"){s+=a,n+=2;continue}s+=o,n++;continue}if(o==="$"){i();let{part:a,endIndex:l}=Ls(t,e,n,!0);a&&r.push(a),n=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=t.parseBacktickSubstitution(e,n,!0);r.push(a),n=l;continue}s+=o,n++}return i(),r}function $0(t,e,r){let n=[],s=r,i="",o=()=>{i&&(n.push(N.literal(i)),i="")};for(;s<e.length&&e[s]!=='"';){let a=e[s];if(a==="\\"&&s+1<e.length){let l=e[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:c}=Ls(t,e,s,!0);l&&n.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=t.parseBacktickSubstitution(e,s,!0);n.push(l),s=c;continue}i+=a,s++}return o(),{part:N.doubleQuoted(n),endIndex:s}}function rt(t,e,r=!1,n=!1,s=!1,i=!1,o=!1){if(n)return[N.singleQuoted(e)];if(r){let f=I0(t,e);return[N.doubleQuoted(f)]}let a=[],l=0,c="",u=()=>{c&&(a.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===`
521
- `:d==="$"||d==="`"||d==="\\"||d==='"'||d===`
522
- `)?c+=d:c+=`\\${d}`,l+=2;continue}if(f==="'"&&!o&&!i){u();let d=e.indexOf("'",l+1);if(d===-1){c+=e.slice(l);break}a.push(N.singleQuoted(e.slice(l+1,d))),l=d+1;continue}if(f==='"'&&!i){u();let{part:d,endIndex:p}=$0(t,e,l+1);a.push(d),l=p+1;continue}if(f==="$"&&e[l+1]==="'"){u();let{part:d,endIndex:p}=Qc(t,e,l+2);a.push(d),l=p;continue}if(f==="$"){u();let{part:d,endIndex:p}=Ls(t,e,l);d&&a.push(d),l=p;continue}if(f==="`"){u();let{part:d,endIndex:p}=t.parseBacktickSubstitution(e,l);a.push(d),l=p;continue}if(f==="~"){let d=l>0?e[l-1]:"";if(l===0||d==="="||s&&d===":"){let h=qc(t,e,l),w=e[h];if(w===void 0||w==="/"||w===":"){u();let g=e.slice(l+1,h)||null;a.push({type:"TildeExpansion",user:g}),l=h;continue}}}if(f==="*"||f==="?"||f==="["){u();let{pattern:d,endIndex:p}=Zc(t,e,l);a.push({type:"Glob",pattern:d}),l=p;continue}if(f==="{"&&!s){let d=Xc(t,e,l,rt);if(d){u(),a.push(d.part),l=d.endIndex;continue}}c+=f,l++}return u(),a}var pe=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Hc)throw new Ze("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>Ss)throw new Ze(`Input too large: ${e.length} bytes exceeds limit of ${Ss}`,1,1);let r=new Xr(e);if(this.tokens=r.tokenize(),this.tokens.length>Cs)throw new Ze(`Too many tokens: ${this.tokens.length} exceeds limit of ${Cs}`,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 o=this.tokens[this.pos]?.type;return o===e||r!==void 0&&o===r||n!==void 0&&o===n||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!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||e===m.LESS||e===m.GREAT||e===m.DLESS||e===m.DGREAT||e===m.LESSAND||e===m.GREATAND||e===m.LESSGREAT||e===m.DLESSDASH||e===m.CLOBBER||e===m.TLESS||e===m.AND_GREAT||e===m.AND_DGREAT}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 o=this.parsePipeline();e.push(o)}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 o=this.parseCommand();i.type===m.PIPE_AMP&&o.type==="SimpleCommand"&&o.redirections.unshift(N.redirection(">&",N.word([N.literal("1")]),2)),n.push(o)}return N.pipeline(n,r)}parseCommand(){return this.check(m.IF)?Ns(this):this.check(m.FOR)?Is(this):this.check(m.WHILE)?$s(this):this.check(m.UNTIL)?Rs(this):this.check(m.CASE)?Os(this):this.check(m.LPAREN)?Fs(this):this.check(m.LBRACE)?Ps(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():eu(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 o=rt(this,e,r,n,s,i);return N.word(o)}parseCommandSubstitution(e,r){let n=r+2,s=1,i=n,o=!1,a=!1,l=0,c=!1,u="";for(;i<e.length&&s>0;){let h=e[i];o?h==="'"&&(o=!1):a?h==="\\"&&i+1<e.length?i++:h==='"'&&(a=!1):h==="'"?(o=!0,u=""):h==='"'?(a=!0,u=""):h==="\\"&&i+1<e.length?(i++,u=""):/[a-zA-Z_]/.test(h)?u+=h:(u==="case"?(l++,c=!1):u==="in"&&l>0?c=!0:u==="esac"&&l>0&&(l--,c=!1),u="",h==="("?i>0&&e[i-1]==="$"?s++:c||s++:h===")"?c?c=!1:s--:h===";"&&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),p=new t().parse(f);return{part:N.commandSubstitution(p,!1),endIndex:i+1}}parseBacktickSubstitution(e,r,n=!1){let i=r+1,o="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let c=e[i+1];c==="$"||c==="`"||c==="\\"||c===`
523
- `||n&&c==='"'?(c!==`
524
- `&&(o+=c),i+=2):(o+=e[i],i++)}else o+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let l=new t().parse(o);return{part:N.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,r){let n=r+3,s=1,i=0,o=n;for(;o<e.length-1&&s>0;)e[o]==="$"&&e[o+1]==="("?e[o+2]==="("?(s++,o+=3):(i++,o+=2):e[o]==="("&&e[o+1]==="("?(s++,o+=2):e[o]===")"&&e[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):e[o]==="("?(i++,o++):(e[o]===")"&&i>0&&i--,o++);let a=e.slice(n,o),l=this.parseArithmeticExpression(a);return{part:N.arithmeticExpansion(l),endIndex:o+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 o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return N.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(m.DBRACK_START);let e=Ds(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 Ps(this);if(this.check(m.LPAREN))return Fs(this);if(this.check(m.IF))return Ns(this);if(this.check(m.FOR))return Is(this);if(this.check(m.WHILE))return $s(this);if(this.check(m.UNTIL))return Rs(this);if(this.check(m.CASE))return Os(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(;Kr(this);){this.checkIterationLimit();let r=this.pos;if(e.push(Jr(this)),this.pos===r)break}return e}parseArithmeticExpression(e){return le(this,e)}};function nt(t){return new pe().parse(t)}J();var Mt=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 a=await this.expand(i);a.length>0?n.push(...a):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 o=this.fs.resolvePath(this.cwd,s);try{let a=await this.fs.readdir(o);for(let l of a)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(/\/$/,"")||".",o=e.slice(n+2).replace(/^\//,"");return await this.walkDirectory(s,o,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 o of i){let a=e==="."?o:`${e}/${o}`,l=this.fs.resolvePath(this.cwd,a);try{(await this.fs.stat(l)).isDirectory?await this.walkDirectory(a,r,n):r&&this.matchPattern(o,r)&&n.push(a)}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,o="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(o+="^",i++),i<e.length&&e[i]==="]"&&(o+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let a=e.indexOf(":]",i+2);if(a!==-1){let l=e.slice(i+2,a),c=this.posixClassToRegex(l);o+=c,i=a+2;continue}}if(e[i]==="\\"&&i+1<e.length){o+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?o+="\\-":o+=e[i],i++}o+="]",r+=o,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 Ms(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 Yr(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Oe(t.expression.expression);case"DoubleQuoted":return t.parts.some(Yr);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&Qe(e.word));case"ParameterExpansion":return Ms(t);default:return!1}}function Qe(t){return t.parts.some(Yr)}function _s(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 ru(t){let e=!1,r=!1,n=!1,s=!1,i=!1;for(let o of t){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(e=!0,o.type==="DoubleQuoted"))for(let a of o.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(s=!0);o.type==="CommandSubstitution"&&(r=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(n=!0),_s(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:r,hasArrayVar:n,hasArrayAtExpansion:s,hasParamExpansion:i}}function O0(t,e,r,n,s){let i=r??1;i===0&&(i=1);let o=Math.abs(i),a=[],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+=o,f++)a.push(c(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=o,f++)a.push(c(u));return a}function F0(t,e,r){let n=r??1;n===0&&(n=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(n),a=t>="A"&&t<="Z",l=t>="a"&&t<="z",c=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(a&&u||l&&c)return null;let f=[];if(s<=i)for(let d=s,p=0;d<=i&&p<1e4;d+=o,p++)f.push(String.fromCharCode(d));else for(let d=s,p=0;d>=i&&p<1e4;d-=o,p++)f.push(String.fromCharCode(d));return f}function sr(t,e,r,n,s){let i=r!==void 0?`..${r}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:O0(t,e,r,n,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:F0(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=P0(t,n);if(i===-1)r+="\\[",n++;else{let o=t.slice(n+1,i);r+=T0(o),n=i+1}}else/[\^$.|+(){}]/.test(s)?(r+=`\\${s}`,n++):(r+=s,n++)}return r}function P0(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 T0(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 o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;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+=L0(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 D0={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 L0(t){return D0[t]??""}J();function ir(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),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&n.push(o)}return n.sort((s,i)=>s-i)}function or(t,e){let r=`${e}_`;for(let n of Object.keys(t.state.env))n.startsWith(r)&&delete t.state.env[n]}function Bs(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 nu(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function en(t){return t.IFS??`
525
- `}function su(t){return t.IFS===""}function ar(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
526
- `?"\\n":e).join("")}function M0(t,e){let r=ar(t);return new RegExp(`[${r}]+`,e)}function _0(t){let e=ar(t);return new RegExp(`^[${e}]+`)}function B0(t){let e=ar(t);return new RegExp(`[${e}]+$`)}function _t(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function iu(t,e){if(e==="")return{words:[t],wordStarts:[0]};let r=[],n=[],s=M0(e,"g"),i=0,o=t.match(_0(e));o&&(i=o[0].length),s.lastIndex=i;let a=s.exec(t);for(;a!==null;)a.index>i&&(n.push(i),r.push(t.substring(i,a.index))),i=s.lastIndex,a=s.exec(t);return i<t.length&&(n.push(i),r.push(t.substring(i))),{words:r,wordStarts:n}}function ou(t,e){return e===""?t:t.replace(B0(e),"")}function ce(t,e){return t.state.associativeArrays?.has(e)?Bs(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):ir(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function au(t,e){return t.state.associativeArrays?.has(e)?Bs(t,e).length>0:ir(t,e).length>0}function Fe(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 o="";return t.state.options.errexit&&(o+="e"),t.state.options.nounset&&(o+="u"),t.state.options.verbose&&(o+="v"),t.state.options.xtrace&&(o+="x"),t.state.options.pipefail&&(o+="p"),o}case"*":{let o=Number.parseInt(t.state.env["#"]||"0",10);if(o===0)return"";let a=[];for(let l=1;l<=o;l++)a.push(t.state.env[String(l)]||"");return a.join(_t(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:"";case"PPID":{let{ppid:o}=nr();return String(o)}case"UID":{let{uid:o}=nr();return String(o)}case"EUID":return String(process.geteuid?.()??nr().uid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-t.state.startTime)/1e3));case"BASH_VERSION":return Nc;case"!":return String(t.state.lastBackgroundPid);case"LINENO":return String(t.state.currentLine)}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 o=s[1],a=s[2];if(a==="@"||a==="*"){let f=ce(t,o);if(f.length>0)return f.map(([,p])=>p).join(" ");let d=t.state.env[o];return d!==void 0?d:""}if(t.state.associativeArrays?.has(o)){let f=nu(a),d=t.state.env[`${o}_${f}`];if(d===void 0&&r&&t.state.options.nounset)throw new Re(`${o}[${a}]`);return d||""}let c;if(/^-?\d+$/.test(a))c=Number.parseInt(a,10);else try{let f=new pe,d=le(f,a);c=V(t,d.expression)}catch{let f=t.state.env[a];c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=ce(t,o);if(f.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
527
- `,"";let p=Math.max(...f.map(([w])=>typeof w=="number"?w:0))+1+c;return p<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
528
- `,""):t.state.env[`${o}_${p}`]||""}let u=t.state.env[`${o}_${c}`];if(u===void 0&&r&&t.state.options.nounset)throw new Re(`${o}[${c}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let o=t.state.env[e];if(o===void 0&&r&&t.state.options.nounset)throw new Re(e);return o||""}let i=t.state.env[e];if(i===void 0&&r&&t.state.options.nounset)throw new Re(e);return i||""}async function lu(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"&&_s(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 a=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(a);for(let p=0;p<d.length;p++)p===0?c+=d[p]:(c!==""&&l.push(c),c=d[p])}}return c!==""&&l.push(c),l}function ve(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cu(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function uu(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Ws(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`
529
- `: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 gt(t,e,r=!1){return e.map(n=>Xe(t,n,r)).join("")}async function xt(t,e,r=!1){let n=[];for(let s of e)n.push(await Pe(t,s));return n.join("")}function W0(t){return uu(t)}function fu(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!W0(e))return!1;return!0}function du(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function pu(t,e,r=!1){let n=cu(e);if(n!==null)return n;switch(e.type){case"ParameterExpansion":return yu(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=pu(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 o=sr(i.start,i.end,i.step,i.startStr,i.endStr);if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(tn(t,i.word));return s.join(" ")}default:return""}}function tn(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)?xu(t,e):tn(t,e)}function rn(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&rn(e.parts))return!0;return!1}function U0(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(Yr(e))return!0}return!1}var hu=1e4,Bt=1e5;function mu(t,e,r={count:0}){if(r.count>Bt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of s.items)if(u.type==="Range"){let f=sr(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{o=!0,a=f.literal;break}}else{let f=mu(t,u.word.parts,r);for(let d of f)r.count++,i.push(d.join(""))}if(o){for(let u of n)r.count++,u.push(a);continue}if(n.length*i.length>hu||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 o of n)r.count++,o.push(i)}return n}function H0(t,e){let r=e.parts;return rn(r)?mu(t,r).map(s=>s.join("")):[tn(t,e)]}async function gu(t,e,r={count:0}){if(r.count>Bt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of s.items)if(u.type==="Range"){let f=sr(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{o=!0,a=f.literal;break}}else{let f=await gu(t,u.word.parts,r);for(let d of f)r.count++,i.push(d.join(""))}if(o){for(let u of n)r.count++,u.push(a);continue}if(n.length*i.length>hu||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 Pe(t,s);for(let o of n)r.count++,o.push(i)}return n}async function z0(t,e){let r=e.parts;return rn(r)?(await gu(t,r)).map(s=>s.join("")):[await K(t,e)]}async function lr(t,e){let r=e.parts,{hasQuoted:n,hasCommandSub:s,hasArrayVar:i,hasArrayAtExpansion:o,hasParamExpansion:a}=ru(r),c=rn(r)?U0(r)?await z0(t,e):H0(t,e):null;if(c&&c.length>1){let d=[];for(let p of c)if(!n&&/[*?[]/.test(p)){let w=await new Mt(t.fs,t.state.cwd).expand(p);w.length>0?d.push(...w):d.push(p)}else d.push(p);return{values:d,quoted:!1}}if(o&&r.length===1&&r[0].type==="DoubleQuoted"){let d=r[0];if(d.parts.length===1&&d.parts[0].type==="ParameterExpansion"){let h=d.parts[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@]\]$/);if(h){let w=h[1],g=ce(t,w);if(g.length>0)return{values:g.map(([,E])=>E),quoted:!0};let y=t.state.env[w];return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}}}if(r.length===1&&r[0].type==="DoubleQuoted"){let d=r[0],p=-1,h=!1;for(let w=0;w<d.parts.length;w++){let g=d.parts[w];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")){p=w,h=g.parameter==="*";break}}if(p!==-1){let w=d.parts[p];w.type==="ParameterExpansion"&&w.operation&&(p=-1)}if(p!==-1){let w=Number.parseInt(t.state.env["#"]||"0",10),g="";for(let S=0;S<p;S++)g+=await Pe(t,d.parts[S]);let y="";for(let S=p+1;S<d.parts.length;S++)y+=await Pe(t,d.parts[S]);if(w===0){if(h)return{values:[g+y],quoted:!0};let S=g+y;return{values:S?[S]:[],quoted:!0}}let E=[];for(let S=1;S<=w;S++)E.push(t.state.env[String(S)]||"");if(h){let S=_t(t.state.env);return{values:[g+E.join(S)+y],quoted:!0}}return E.length===1?{values:[g+E[0]+y],quoted:!0}:{values:[g+E[0],...E.slice(1,-1),E[E.length-1]+y],quoted:!0}}}if((s||i||a)&&!su(t.state.env)){let d=en(t.state.env),p=ar(d),h=await lu(t,r,d,p,Pe),w=[],g=new Mt(t.fs,t.state.cwd);for(let y of h)if(/[*?[]/.test(y)){let E=await g.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 xu(t,e):tn(t,e);if(!n&&/[*?[]/.test(f)){let p=await new Mt(t.fs,t.state.cwd).expand(f);if(p.length>0)return{values:p,quoted:!1}}return f===""&&!n?{values:[],quoted:!1}:{values:[f],quoted:n}}async function xu(t,e){let r=e.parts,n=r.length;if(n===1)return Pe(t,r[0]);let s=[];for(let i=0;i<n;i++)s.push(await Pe(t,r[i]));return s.join("")}async function Pe(t,e){if(e.type==="ParameterExpansion"&&Ms(e))return j0(t,e);let r=pu(t,e);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let n=[];for(let s of e.parts)n.push(await Pe(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 H)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=sr(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 yu(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Fe(t,n,!i);if(!s)return o;let a=!(n in t.state.env),l=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&l)&&s.word?gt(t,s.word.parts,r):o;case"AssignDefault":{if((a||s.checkEmpty&&l)&&s.word){let u=gt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,d,p]=f,h;if(/^\d+$/.test(p))h=Number.parseInt(p,10);else{try{let g=new pe,y=le(g,p);h=V(t,y.expression)}catch{let g=t.state.env[p];h=g?Number.parseInt(g,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${d}_${h}`]=u;let w=Number.parseInt(t.state.env[`${d}__length`]||"0",10);h>=w&&(t.state.env[`${d}__length`]=String(h+1))}else t.state.env[n]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&l){let u=s.word?gt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
530
- `)}return o}case"UseAlternative":return!(a||s.checkEmpty&&l)&&s.word?gt(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)&&au(t,n)){let u=t.state.env[`${n}_0`]||"";return String(u.length)}return String(o.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 h=(t.state.env["@"]||"").split(" ").filter(E=>E),w=t.state.env[0]||"bash",g=c===0?[w,...h]:h,y=c===0?0:c-1;if(y<0||y>=g.length)return"";if(u!==void 0){let E=u<0?g.length+u:y+u;return g.slice(y,Math.max(y,E)).join(" ")}return g.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),g=c;if(g<0&&(g=w.length+g,g<0))return"";if(u!==void 0){if(u<0){let y=w.length+u;return w.slice(g,Math.max(g,y)).join(" ")}return w.slice(g,g+u).join(" ")}return w.slice(g).join(" ")}let d=[...o],p=c;if(p<0&&(p=Math.max(0,d.length+p)),u!==void 0){if(u<0){let h=d.length+u;return d.slice(p,Math.max(p,h)).join("")}return d.slice(p,p+u).join("")}return d.slice(p).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=gt(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 o.replace(new RegExp(`^${c}`),"");let u=new RegExp(`${c}$`);if(s.greedy)return o.replace(u,"");for(let f=o.length;f>=0;f--){let d=o.slice(f);if(u.test(d))return o.slice(0,f)}return o}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 p=gt(t,d.parts);c+=ve(p)}else if(d.type==="ParameterExpansion"){let p=Xe(t,d);c+=ke(p,!0)}else{let p=Xe(t,d);c+=ve(p)}let u=s.replacement?gt(t,s.replacement.parts):"";if(c==="")return o;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 p="",h=0,w=d.exec(o);for(;w!==null&&!(w[0].length===0&&w.index===o.length);)p+=o.slice(h,w.index)+u,h=w.index+w[0].length,w[0].length===0&&h++,w=d.exec(o);return p+=o.slice(h),p}return o.replace(d,u)}catch{return o}}case"CaseModification":return s.direction==="upper"?s.all?o.toUpperCase():o.charAt(0).toUpperCase()+o.slice(1):s.all?o.toLowerCase():o.charAt(0).toLowerCase()+o.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])=>Ws(d)).join(" ");switch(s.operator){case"Q":return Ws(o);case"P":return o;case"a":return"";case"A":return`${n}=${Ws(o)}`;case"E":return o.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`
531
- `;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 o}}case"Indirection":return Fe(t,o);case"ArrayKeys":{let u=ce(t,s.array).map(([f])=>String(f));return s.star?u.join(_t(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(_t(t.state.env)):c.join(" ")}default:return o}}async function j0(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Fe(t,n,!i);if(!s)return o;let a=!(n in t.state.env),l=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&l)&&s.word?xt(t,s.word.parts,r):o;case"AssignDefault":{if((a||s.checkEmpty&&l)&&s.word){let u=await xt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,d,p]=f,h;if(/^\d+$/.test(p))h=Number.parseInt(p,10);else{try{let g=new pe,y=le(g,p);h=await Z(t,y.expression)}catch{let g=t.state.env[p];h=g?Number.parseInt(g,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${d}_${h}`]=u;let w=Number.parseInt(t.state.env[`${d}__length`]||"0",10);h>=w&&(t.state.env[`${d}__length`]=String(h+1))}else t.state.env[n]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&l){let u=s.word?await xt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
532
- `)}return o}case"UseAlternative":return!(a||s.checkEmpty&&l)&&s.word?xt(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 xt(t,f.parts);c+=ve(d)}else if(f.type==="ParameterExpansion"){let d=await Pe(t,f);c+=ke(d,s.greedy)}else{let d=await Pe(t,f);c+=ve(d)}if(s.side==="prefix")return o.replace(new RegExp(`^${c}`),"");let u=new RegExp(`${c}$`);if(s.greedy)return o.replace(u,"");for(let f=o.length;f>=0;f--){let d=o.slice(f);if(u.test(d))return o.slice(0,f)}return o}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 p=await xt(t,d.parts);c+=ve(p)}else if(d.type==="ParameterExpansion"){let p=await Pe(t,d);c+=ke(p,!0)}else{let p=await Pe(t,d);c+=ve(p)}let u=s.replacement?await xt(t,s.replacement.parts):"";if(c==="")return o;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 p="",h=0,w=d.exec(o);for(;w!==null&&!(w[0].length===0&&w.index===o.length);)p+=o.slice(h,w.index)+u,h=w.index+w[0].length,w[0].length===0&&h++,w=d.exec(o);return p+=o.slice(h),p}return o.replace(d,u)}catch{return o}}default:return yu(t,e,r)}}function Us(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 oe("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 wu(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 Hs(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function G0(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:Fe(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 pe,{expr:s,pos:i}=Ve(n,r,0);if(i<r.length){let o=r.slice(i).trim().split(/\s+/)[0];throw new oe(`${r}: syntax error in expression (error token is "${o}")`)}return s.type==="ArithNumber"?s.value:e||0}catch(n){if(n instanceof oe)throw n;let s=r.split(/\s+/).slice(1)[0]||r;throw new oe(`${r}: syntax error in expression (error token is "${s}")`)}}function nn(t,e,r=new Set){if(r.has(e))return 0;r.add(e);let n=G0(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 nn(t,i,r);try{let o=new pe,{expr:a}=Ve(o,i,0);return Te(t,a,r)}catch{return 0}}function Te(t,e,r){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new oe("value too great for base");return e.value;case"ArithVariable":return nn(t,e.name,r);case"ArithBinary":{if(e.operator==="||")return Te(t,e.left,r)||Te(t,e.right,r)?1:0;if(e.operator==="&&")return Te(t,e.left,r)&&Te(t,e.right,r)?1:0;let n=Te(t,e.left,r),s=Te(t,e.right,r);return Us(n,s,e.operator)}case"ArithUnary":{let n=Te(t,e.operand,r);return Hs(n,e.operator)}case"ArithTernary":return Te(t,e.condition,r)?Te(t,e.consequent,r):Te(t,e.alternate,r);case"ArithGroup":return Te(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 Fe(t,e);let i=e.slice(0,n),o=e.slice(n+s.length),a=t.state.env[i],l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(t.state.env[i]=o,o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}function V(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new oe("value too great for base");return e.value;case"ArithVariable":return nn(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 Lt(s)}case"ArithDynamicNumber":{let n=st(t,e.prefix)+e.suffix;return Lt(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 a=ce(t,e.array);if(a.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
533
- `,0;let c=Math.max(...a.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
534
- `,0;i=c}n=`${e.array}_${i}`;let o=t.state.env[n];if(o!==void 0)return Wt(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return Wt(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new Re(`${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 oe("double subscript","","");case"ArithNumberSubscript":throw new oe(`${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 Us(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(Fe(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 o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return r}return Hs(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 a=t.state.associativeArrays?.has(r);if(a&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(a){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),o=wu(s,i,e.operator);return t.state.env[n]=String(o),o}case"ArithGroup":return V(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=Eu(t,n);return Number.parseInt(r,10)||0}default:return 0}}function Eu(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Fe(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+=Eu(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 oe("value too great for base");return e.value;case"ArithVariable":return nn(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 Lt(s)}case"ArithDynamicNumber":{let n=st(t,e.prefix)+e.suffix;return Lt(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 o=t.state.env[n];if(o!==void 0)return Wt(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return Wt(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new Re(`${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 oe("double subscript","","");case"ArithNumberSubscript":throw new oe(`${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 Us(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(Fe(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 o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return r}return Hs(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 a=t.state.associativeArrays?.has(r);if(a&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(a){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),o=wu(s,i,e.operator);return t.state.env[n]=String(o),o}case"ArithGroup":return await Z(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=await bu(t,n);return Number.parseInt(r,10)||0}default:return 0}}async function bu(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Fe(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 bu(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 R(t,e,r){return{stdout:t,stderr:e,exitCode:r}}function ae(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function Ke(t,e,r="",n=""){throw new H(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
535
- `);r=n}throw new he(r)}async function js(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 o=e.slice(i);if(o.length===0||o[0]==="~"?r=t.state.env.HOME||"/":o[0]==="-"?(r=t.state.previousDir,n=!0):r=o[0],!r.startsWith("/")&&!r.startsWith("./")&&!r.startsWith("../")&&r!=="."&&r!==".."){let f=t.state.env.CDPATH;if(f){let d=f.split(":").filter(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${r}`:`${t.state.cwd}/${p}/${r}`;try{if((await t.fs.stat(h)).isDirectory){r=h,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
536
- `)}catch{return _(`bash: cd: ${r}: No such file or directory
537
- `)}}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}
538
- `:"")}J();function Gs(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new ze;return q}if(e.length>1)throw new he(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
539
- `);r=n}throw new ye(r)}function yt(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function q0(t,e){return t.state.readonlyVars?.has(e)??!1}function it(t,e,r="bash"){return q0(t,e)?_(`${r}: ${e}: readonly variable
540
- `):null}function Su(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:qs(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 Cu(t,e,r={}){let{name:n,isArray:s,arrayElements:i,value:o}=e,{makeReadonly:a=!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 o!==void 0&&(t.state.env[n]=o);return a&&yt(t,n),null}function Vs(t,e){let r=!1,n=!1,s=!1,i=!1,o=!1,a=[];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")o=!0;else if(c==="--"){a.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"&&(o=!0);else a.push(c)}if(o&&a.length>0){let l="";for(let c of a){let u=t.state.env[c];if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');l+=`declare -- ${c}="${f}"
541
- `}}return Ne(l)}if(a.length===0&&!o){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}'
542
- `}return Ne(l)}for(let l of a){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=V0(f);for(let[p,h]of d)t.state.env[`${u}_${p}`]=h}else{let d=qs(f);for(let p=0;p<d.length;p++)t.state.env[`${u}_${p}`]=d[p];t.state.env[`${u}__length`]=String(d.length)}s&&yt(t,u);continue}if(l.includes("=")){let u=l.indexOf("="),f=l.slice(0,u),d=l.slice(u+1),p=it(t,f);if(p)return p;t.state.env[f]=d,s&&yt(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&&yt(t,u)}}return q}function qs(t){let e=[],r="",n=!1,s=!1,i=!1;for(let o of t){if(i){r+=o,i=!1;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!s){n=!n;continue}if(o==='"'&&!n){s=!s;continue}if((o===" "||o===" "||o===`
543
- `)&&!n&&!s){r&&(e.push(r),r="");continue}r+=o}return r&&e.push(r),e}function V0(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 Zs(t,e){let r=!1,n=!1,s=[];for(let i=0;i<e.length;i++){let o=e[i];if(o==="-a")r=!0;else if(o==="-A")n=!0;else if(o==="-p"){if(e.length===1){let a="";for(let l of t.state.readonlyVars||[]){let c=t.state.env[l];c!==void 0&&(a+=`declare -r ${l}="${c}"
544
- `)}return Ne(a)}}else if(o==="--"){s.push(...e.slice(i+1));break}else o.startsWith("-")||s.push(o)}for(let i of s){let o=Su(i);if(o.value===void 0&&!o.isArray){yt(t,o.name);continue}let a=Cu(t,o,{makeReadonly:!0});if(a)return a}return q}J();async function Qs(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
521
+ `||r===";"||r==="&"||r==="|"||r==="("||r===")"||r==="<"||r===">")}readWordWithBraceExpansion(e,r,n){let s=this.input,i=s.length,o=e,a=n;for(;o<i;){let l=s[o];if(l===" "||l===" "||l===`
522
+ `||l===";"||l==="&"||l==="|"||l==="("||l===")"||l==="<"||l===">")break;if(l==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(l==="}"){o++,a++;continue}if(l==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(l==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(l==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let c=s.slice(e,o);return this.pos=o,this.column=a,{type:m.WORD,value:c,start:e,end:o,line:r,column:n,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let r=this.input,n=r.length,s=e+1,i=1,o=!1,a=!1;for(;s<n&&i>0;){let c=r[s];if(c==="{")i++,s++;else if(c==="}")i--,s++;else if(c===","&&i===1)o=!0,s++;else if(c==="."&&s+1<n&&r[s+1]===".")a=!0,s+=2;else{if(c===" "||c===" "||c===`
523
+ `||c===";"||c==="&"||c==="|")return null;s++}}return i===0&&(o||a)?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 o=r[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return r.slice(e,s+1);s++}else{if(o===" "||o===" "||o===`
524
+ `||o===";"||o==="&"||o==="|")return null;s++}}return null}};var $s=1e6,Os=1e5,nu=1e6,su=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]),iu=new Set([m.LESS,m.GREAT,m.DLESS,m.DGREAT,m.LESSAND,m.GREATAND,m.LESSGREAT,m.DLESSDASH,m.CLOBBER,m.TLESS]),Qe=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 au(t,e,r){let n=r+1;for(;n<e.length&&/[a-zA-Z0-9_-]/.test(e[n]);)n++;return n}function Ps(t,e,r,n,s){let i=1,o=r+1;for(;o<e.length&&i>0;)e[o]===n?i++:e[o]===s&&i--,i>0&&o++;return i===0?o:-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 o=e.indexOf("'",n+1);if(o!==-1){n=o+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 cu(t,e,r){let n=r,s=!1;for(;n<e.length;){let i=e[n];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=e.indexOf("'",n+1);if(o!==-1){n=o+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 lu(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 o=D0(e,n);o===-1?(s+=i,n++):(s+=e.slice(n,o+1),n=o+1)}else break}return{pattern:s,endIndex:n}}function D0(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]}]`,o=t.indexOf(i,r+2);if(o!==-1){r=o+2;continue}}r++}return-1}function uu(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+=`
525
+ `,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 a=e.slice(s+2,s+4),c=parseInt(a,16);Number.isNaN(c)?(n+="\\x",s+=2):(n+=String.fromCharCode(c),s+=4);break}case"u":{let a=e.slice(s+2,s+6),c=parseInt(a,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 a="",c=s+1;for(;c<e.length&&c<s+4&&/[0-7]/.test(e[c]);)a+=e[c],c++;let l=parseInt(a,8);n+=String.fromCharCode(l),s=c;break}default:n+=i,s++}else n+=i,s++}return s<e.length&&e[s]==="'"&&s++,{part:v.literal(n),endIndex:s}}function Ts(t,e){let r=e.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:le(t,r)}function ou(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 fu(t,e,r,n){let s=Ps(t,e,r,"{","}");if(s===-1)return null;let i=e.slice(r+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&n?{part:{type:"BraceExpansion",items:ou(i).map(u=>({type:"Word",word:v.word(n(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:ou(i).map(u=>({type:"Word",word:v.word([v.literal(u)])}))},endIndex:s+1}:null}function pu(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 du(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 tn(t){let e=t.current(),r=e.type;if(r===m.NUMBER){let n=t.peek(1);return e.end!==n.start?!1:iu.has(n.type)}return su.has(r)}function rn(t){let e=null;t.check(m.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let r=t.advance(),n=du(t,r.type);if(r.type===m.DLESS||r.type===m.DLESSDASH)return L0(t,n,e,r.type===m.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return v.redirection(n,s,e)}function L0(t,e,r,n){t.isWord()||t.error("Expected here-document delimiter");let s=t.advance(),i=s.value,o=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let a=v.redirection(n?"<<-":"<<",v.hereDoc(i,v.word([]),n,o),r);return t.addPendingHeredoc(a,i,n,o),a}function mu(t){let e=t.current().line,r=[],n=null,s=[],i=[];for(;t.check(m.ASSIGNMENT_WORD);)t.checkIterationLimit(),r.push(M0(t));for(;tn(t);)t.checkIterationLimit(),i.push(rn(t));for(t.isWord()&&(n=t.parseWord());(!t.isStatementEnd()||t.check(m.RBRACE))&&!t.check(m.PIPE,m.PIPE_AMP);)if(t.checkIterationLimit(),tn(t))i.push(rn(t));else if(t.check(m.RBRACE)){let a=t.advance();s.push(t.parseWordFromString(a.value,!1,!1))}else if(t.isWord())s.push(t.parseWord());else if(t.check(m.ASSIGNMENT_WORD)){let a=t.advance(),c=a.value,l=c.endsWith("="),u=c.endsWith("=(");if((l||u)&&(u||t.check(m.LPAREN))){let f=u?c.slice(0,-2):c.slice(0,-1);u||t.expect(m.LPAREN);let p=Fs(t);t.expect(m.RPAREN);let d=p.map(g=>pu(t,g)),h=`${f}=(${d.join(" ")})`;s.push(t.parseWordFromString(h,!1,!1))}else s.push(t.parseWordFromString(c,a.quoted,a.singleQuoted))}else if(t.check(m.LPAREN))t.error("syntax error near unexpected token `('");else break;let o=v.simpleCommand(n,s,r,i);return o.line=e,o}function M0(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,o=s.length;if(r[o]==="["){let f=0,p=o+1;for(;o<r.length;o++)if(r[o]==="[")f++;else if(r[o]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${r}`),i=r.slice(p,o),o++}let a=r[o]==="+";a&&o++,r[o]!=="="&&t.error(`Invalid assignment: ${r}`),o++;let c=r.slice(o);if(c==="("){let f=Fs(t);t.expect(m.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return v.assignment(p,null,a,f)}if(c===""&&t.check(m.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let p=Fs(t);t.expect(m.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return v.assignment(d,null,a,p)}}let l=c?t.parseWordFromString(c,e.quoted,e.singleQuoted,!0):null,u=i!==void 0?`${s}[${i}]`:s;return v.assignment(u,l,a,null)}function Fs(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 Ds(t){t.expect(m.IF);let e=[],r=t.parseCompoundList();t.expect(m.THEN);let n=t.parseCompoundList();if(n.length===0){let o=t.check(m.FI)?"fi":t.check(m.ELSE)?"else":t.check(m.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${o}'`)}for(e.push({condition:r,body:n});t.check(m.ELIF);){t.advance();let o=t.parseCompoundList();t.expect(m.THEN);let a=t.parseCompoundList();if(a.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:o,body:a})}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 v.ifNode(e,s,i)}function Ls(t){if(t.expect(m.FOR),t.check(m.DPAREN_START))return B0(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 v.forNode(r,n,s,i)}function B0(t){t.expect(m.DPAREN_START);let e=null,r=null,n=null,s=["","",""],i=0,o=0;for(;!t.check(m.DPAREN_END,m.EOF);){let l=t.advance();if(l.type===m.SEMICOLON&&o===0){if(i++,i>2)break}else l.value==="("&&o++,l.value===")"&&o--,s[i]+=l.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 a=t.parseCompoundList();t.expect(m.DONE);let c=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:r,update:n,body:a,redirections:c}}function Ms(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 v.whileNode(e,r,n)}function _s(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 v.untilNode(e,r,n)}function Bs(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=W0(t);if(i&&r.push(i),t.skipNewlines(),t.getPos()===s&&!i)break}t.expect(m.ESAC);let n=t.parseOptionalRedirections();return v.caseNode(e,r,n)}function W0(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=";;&"),v.caseItem(e,r,n)}function Ws(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 v.subshell(e,r)}function Us(t){t.expect(m.LBRACE);let e=t.parseCompoundList();t.expect(m.RBRACE);let r=t.parseOptionalRedirections();return v.group(e,r)}var H0=["-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"],j0=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function js(t){return t.skipNewlines(),z0(t)}function z0(t){let e=yu(t);for(t.skipNewlines();t.check(m.OR_OR);){t.advance(),t.skipNewlines();let r=yu(t);e={type:"CondOr",left:e,right:r},t.skipNewlines()}return e}function yu(t){let e=Hs(t);for(t.skipNewlines();t.check(m.AND_AND);){t.advance(),t.skipNewlines();let r=Hs(t);e={type:"CondAnd",left:e,right:r},t.skipNewlines()}return e}function Hs(t){return t.skipNewlines(),t.check(m.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Hs(t)}):G0(t)}function G0(t){if(t.check(m.LPAREN)){t.advance();let e=js(t);return t.expect(m.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),r=e.value;if(H0.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()&&j0.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 V0(t,e,r){let n=r+1,s=e[n];if("@*#?$!-0123456789".includes(s))return{part:v.parameterExpansion(s),endIndex:n+1};let i="";for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)i+=e[n],n++;return{part:v.parameterExpansion(i),endIndex:n}}function K0(t,e,r,n=!1){let s=r+2,i=!1;e[s]==="!"&&(i=!0,s++);let o=!1;e[s]==="#"&&!/[}:#%/^,]/.test(e[s+1]||"}")&&(o=!0,s++);let a="",c=e[s];if(/[@*#?$!-]/.test(c)&&!/[a-zA-Z0-9_]/.test(e[s+1]||""))a=c,s++;else for(;s<e.length&&/[a-zA-Z0-9_]/.test(e[s]);)a+=e[s],s++;if(e[s]==="["){let u=Ps(t,e,s,"[","]");a+=e.slice(s,u+1),s=u+1}a===""&&!i&&!o&&e[s]!=="}"&&t.error(`\${${e[s]}}: bad substitution`);let l=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)l={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(e[s]==="*"||e[s]==="@"){let f=e[s];s++,l={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else l={type:"Indirection"}}else if(o)if(e[s]===":")for(l={type:"LengthSliceError"};s<e.length&&e[s]!=="}";)s++;else e[s]!=="}"&&/[-+=?]/.test(e[s])?t.error(`\${#${a}${e.slice(s,e.indexOf("}",s))}}: bad substitution`):l={type:"Length"};if(!l&&s<e.length&&e[s]!=="}"){let u=Z0(t,e,s,a,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 p=e.slice(r,f+1);t.error(`\${${p.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:v.parameterExpansion(a,l),endIndex:s+1}}function Z0(t,e,r,n,s=!1){let i=r,o=e[i],a=e[i+1]||"";if(o===":"){let c=a;if("-=?+".includes(c)){i+=2;let w=gt(t,e,i),E=e.slice(i,w),b=nt(t,E,!1,!1,!0,!1,s),S=v.word(b.length>0?b:[v.literal("")]);if(c==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:w};if(c==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:w};if(c==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:w};if(c==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:w}}i++;let l=gt(t,e,i),u=e.slice(i,l),f=-1,p=0,d=0;for(let y=0;y<u.length;y++){let w=u[y];if(w==="("||w==="[")p++;else if(w===")"||w==="]")p--;else if(w==="?"&&p===0)d++;else if(w===":"&&p===0)if(d>0)d--;else{f=y;break}}let h=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Ts(t,h),length:g?Ts(t,g):null},endIndex:l}}if("-=?+".includes(o)){i++;let c=gt(t,e,i),l=e.slice(i,c),u=nt(t,l,!1,!1,!0,!1,s),f=v.word(u.length>0?u:[v.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:c};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:c};if(o==="?")return{operation:{type:"ErrorIfUnset",word:l?f:null,checkEmpty:!1},endIndex:c};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:c}}if(o==="#"||o==="%"){let c=a===o,l=o==="#"?"prefix":"suffix";i+=c?2:1;let u=gt(t,e,i),f=e.slice(i,u),p=nt(t,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:v.word(p.length>0?p:[v.literal("")]),side:l,greedy:c},endIndex:u}}if(o==="/"){let c=a==="/";i+=c?2:1;let l=null;e[i]==="#"?(l="start",i++):e[i]==="%"&&(l="end",i++);let u=cu(t,e,i),f=e.slice(i,u),p=nt(t,f,!1,!1,!1),d=v.word(p.length>0?p:[v.literal("")]),h=null,g=u;if(e[u]==="/"){let y=u+1,w=gt(t,e,y),E=e.slice(y,w),b=nt(t,E,!1,!1,!1);h=v.word(b.length>0?b:[v.literal("")]),g=w}return{operation:{type:"PatternReplacement",pattern:d,replacement:h,all:c,anchor:l},endIndex:g}}if(o==="^"||o===","){let c=a===o,l=o==="^"?"upper":"lower";i+=c?2:1;let u=gt(t,e,i),f=e.slice(i,u),p=f?v.word([v.literal(f)]):null;return{operation:{type:"CaseModification",direction:l,all:c,pattern:p},endIndex:u}}return o==="@"&&/[QPaAEK]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function zs(t,e,r,n=!1){let s=r+1;if(s>=e.length)return{part:v.literal("$"),endIndex:s};let i=e[s];if(i==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,r);if(i==="["){let o=1,a=s+1;for(;a<e.length&&o>0;)e[a]==="["?o++:e[a]==="]"&&o--,o>0&&a++;if(o===0){let c=e.slice(s+1,a),l=le(t,c);return{part:v.arithmeticExpansion(l),endIndex:a+1}}}return i==="("?t.parseCommandSubstitution(e,r):i==="{"?K0(t,e,r,n):/[a-zA-Z_0-9@*#?$!-]/.test(i)?V0(t,e,r):{part:v.literal("$"),endIndex:s}}function Q0(t,e){let r=[],n=0,s="",i=()=>{s&&(r.push(v.literal(s)),s="")};for(;n<e.length;){let o=e[n];if(o==="\\"&&n+1<e.length){let a=e[n+1];if(a==="$"||a==="`"){s+=a,n+=2;continue}s+=o,n++;continue}if(o==="$"){i();let{part:a,endIndex:c}=zs(t,e,n,!0);a&&r.push(a),n=c;continue}if(o==="`"){i();let{part:a,endIndex:c}=t.parseBacktickSubstitution(e,n,!0);r.push(a),n=c;continue}s+=o,n++}return i(),r}function X0(t,e,r){let n=[],s=r,i="",o=()=>{i&&(n.push(v.literal(i)),i="")};for(;s<e.length&&e[s]!=='"';){let a=e[s];if(a==="\\"&&s+1<e.length){let c=e[s+1];if('"\\$`\n'.includes(c)){i+=c,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:c,endIndex:l}=zs(t,e,s,!0);c&&n.push(c),s=l;continue}if(a==="`"){o();let{part:c,endIndex:l}=t.parseBacktickSubstitution(e,s,!0);n.push(c),s=l;continue}i+=a,s++}return o(),{part:v.doubleQuoted(n),endIndex:s}}function nt(t,e,r=!1,n=!1,s=!1,i=!1,o=!1){if(n)return[v.singleQuoted(e)];if(r){let f=Q0(t,e);return[v.doubleQuoted(f)]}let a=[],c=0,l="",u=()=>{l&&(a.push(v.literal(l)),l="")};for(;c<e.length;){let f=e[c];if(f==="\\"&&c+1<e.length){let p=e[c+1];(i?p==="$"||p==="`"||p==="\\"||p===`
526
+ `:p==="$"||p==="`"||p==="\\"||p==='"'||p===`
527
+ `)?l+=p:l+=`\\${p}`,c+=2;continue}if(f==="'"&&!o&&!i){u();let p=e.indexOf("'",c+1);if(p===-1){l+=e.slice(c);break}a.push(v.singleQuoted(e.slice(c+1,p))),c=p+1;continue}if(f==='"'&&!i){u();let{part:p,endIndex:d}=X0(t,e,c+1);a.push(p),c=d+1;continue}if(f==="$"&&e[c+1]==="'"){u();let{part:p,endIndex:d}=uu(t,e,c+2);a.push(p),c=d;continue}if(f==="$"){u();let{part:p,endIndex:d}=zs(t,e,c);p&&a.push(p),c=d;continue}if(f==="`"){u();let{part:p,endIndex:d}=t.parseBacktickSubstitution(e,c);a.push(p),c=d;continue}if(f==="~"){let p=c>0?e[c-1]:"";if(c===0||p==="="||s&&p===":"){let h=au(t,e,c),g=e[h];if(g===void 0||g==="/"||g===":"){u();let y=e.slice(c+1,h)||null;a.push({type:"TildeExpansion",user:y}),c=h;continue}}}if(f==="*"||f==="?"||f==="["){u();let{pattern:p,endIndex:d}=lu(t,e,c);a.push({type:"Glob",pattern:p}),c=d;continue}if(f==="{"&&!s){let p=fu(t,e,c,nt);if(p){u(),a.push(p.part),c=p.endIndex;continue}}l+=f,c++}return u(),a}var he=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>nu)throw new Qe("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>$s)throw new Qe(`Input too large: ${e.length} bytes exceeds limit of ${$s}`,1,1);let r=new en(e);if(this.tokens=r.tokenize(),this.tokens.length>Os)throw new Qe(`Too many tokens: ${this.tokens.length} exceeds limit of ${Os}`,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 o=this.tokens[this.pos]?.type;return o===e||r!==void 0&&o===r||n!==void 0&&o===n||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(e,r){if(this.check(e))return this.advance();let n=this.current();throw new Qe(r||`Expected ${e}, got ${n.type}`,n.line,n.column,n)}error(e){let r=this.current();throw new Qe(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=v.word([v.literal(r.value)]):n=this.parseWordFromString(r.value,!1,!1,!1,!0),e.redirect.target=v.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||e===m.LESS||e===m.GREAT||e===m.DLESS||e===m.DGREAT||e===m.LESSAND||e===m.GREATAND||e===m.LESSGREAT||e===m.DLESSDASH||e===m.CLOBBER||e===m.TLESS||e===m.AND_GREAT||e===m.AND_DGREAT}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 v.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 o=this.parsePipeline();e.push(o)}return this.check(m.AMP)&&(this.advance(),n=!0),v.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 o=this.parseCommand();i.type===m.PIPE_AMP&&o.type==="SimpleCommand"&&o.redirections.unshift(v.redirection(">&",v.word([v.literal("1")]),2)),n.push(o)}return v.pipeline(n,r)}parseCommand(){return this.check(m.IF)?Ds(this):this.check(m.FOR)?Ls(this):this.check(m.WHILE)?Ms(this):this.check(m.UNTIL)?_s(this):this.check(m.CASE)?Bs(this):this.check(m.LPAREN)?Ws(this):this.check(m.LBRACE)?Us(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():mu(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 o=nt(this,e,r,n,s,i);return v.word(o)}parseCommandSubstitution(e,r){let n=r+2,s=1,i=n,o=!1,a=!1,c=0,l=!1,u="";for(;i<e.length&&s>0;){let h=e[i];o?h==="'"&&(o=!1):a?h==="\\"&&i+1<e.length?i++:h==='"'&&(a=!1):h==="'"?(o=!0,u=""):h==='"'?(a=!0,u=""):h==="\\"&&i+1<e.length?(i++,u=""):/[a-zA-Z_]/.test(h)?u+=h:(u==="case"?(c++,l=!1):u==="in"&&c>0?l=!0:u==="esac"&&c>0&&(c--,l=!1),u="",h==="("?i>0&&e[i-1]==="$"?s++:l||s++:h===")"?l?l=!1:s--:h===";"&&c>0&&i+1<e.length&&e[i+1]===";"&&(l=!0)),s>0&&i++}s>0&&this.error("unexpected EOF while looking for matching `)'");let f=e.slice(n,i),d=new t().parse(f);return{part:v.commandSubstitution(d,!1),endIndex:i+1}}parseBacktickSubstitution(e,r,n=!1){let i=r+1,o="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let l=e[i+1];l==="$"||l==="`"||l==="\\"||l===`
528
+ `||n&&l==='"'?(l!==`
529
+ `&&(o+=l),i+=2):(o+=e[i],i++)}else o+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let c=new t().parse(o);return{part:v.commandSubstitution(c,!0),endIndex:i+1}}parseArithmeticExpansion(e,r){let n=r+3,s=1,i=0,o=n;for(;o<e.length-1&&s>0;)e[o]==="$"&&e[o+1]==="("?e[o+2]==="("?(s++,o+=3):(i++,o+=2):e[o]==="("&&e[o+1]==="("?(s++,o+=2):e[o]===")"&&e[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):e[o]==="("?(i++,o++):(e[o]===")"&&i>0&&i--,o++);let a=e.slice(n,o),c=this.parseArithmeticExpression(a);return{part:v.arithmeticExpansion(c),endIndex:o+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 o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return v.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(m.DBRACK_START);let e=js(this);this.expect(m.DBRACK_END);let r=this.parseOptionalRedirections();return v.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 v.functionDef(e,r,n)}parseCompoundCommandBody(){if(this.check(m.LBRACE))return Us(this);if(this.check(m.LPAREN))return Ws(this);if(this.check(m.IF))return Ds(this);if(this.check(m.FOR))return Ls(this);if(this.check(m.WHILE))return Ms(this);if(this.check(m.UNTIL))return _s(this);if(this.check(m.CASE))return Bs(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(;tn(this);){this.checkIterationLimit();let r=this.pos;if(e.push(rn(this)),this.pos===r)break}return e}parseArithmeticExpression(e){return le(this,e)}};function st(t){return new he().parse(t)}J();var Ut=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 a=await this.expand(i);a.length>0?n.push(...a):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 o=this.fs.resolvePath(this.cwd,s);try{let a=await this.fs.readdir(o);for(let c of a)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(/\/$/,"")||".",o=e.slice(n+2).replace(/^\//,"");return await this.walkDirectory(s,o,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 o of i){let a=e==="."?o:`${e}/${o}`,c=this.fs.resolvePath(this.cwd,a);try{(await this.fs.stat(c)).isDirectory?await this.walkDirectory(a,r,n):r&&this.matchPattern(o,r)&&n.push(a)}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,o="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(o+="^",i++),i<e.length&&e[i]==="]"&&(o+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let a=e.indexOf(":]",i+2);if(a!==-1){let c=e.slice(i+2,a),l=this.posixClassToRegex(c);o+=l,i=a+2;continue}}if(e[i]==="\\"&&i+1<e.length){o+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?o+="\\-":o+=e[i],i++}o+="]",r+=o,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 Te(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Te(t.expression);case"ArithBinary":return Te(t.left)||Te(t.right);case"ArithUnary":return Te(t.operand);case"ArithTernary":return Te(t.condition)||Te(t.consequent)||Te(t.alternate);case"ArithAssignment":return Te(t.value);case"ArithGroup":return Te(t.expression);case"ArithArrayElement":return t.index?Te(t.index):!1;case"ArithConcat":return t.parts.some(Te);default:return!1}}function Gs(t){let e=t.operation;return e?!!("word"in e&&e.word&&Xe(e.word)||e.type==="PatternReplacement"&&(e.pattern&&Xe(e.pattern)||e.replacement&&Xe(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&Xe(e.pattern)):!1}function nn(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Te(t.expression.expression);case"DoubleQuoted":return t.parts.some(nn);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&Xe(e.word));case"ParameterExpansion":return Gs(t);default:return!1}}function Xe(t){return t.parts.some(nn)}function qs(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 gu(t){let e=!1,r=!1,n=!1,s=!1,i=!1;for(let o of t){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(e=!0,o.type==="DoubleQuoted"))for(let a of o.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(s=!0);o.type==="CommandSubstitution"&&(r=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(n=!0),qs(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:r,hasArrayVar:n,hasArrayAtExpansion:s,hasParamExpansion:i}}function Y0(t,e,r,n,s){let i=r??1;i===0&&(i=1);let o=Math.abs(i),a=[],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,p=String(Math.abs(u)).padStart(c,"0");return f?`-${p}`:p}return String(u)};if(t<=e)for(let u=t,f=0;u<=e&&f<1e4;u+=o,f++)a.push(l(u));else for(let u=t,f=0;u>=e&&f<1e4;u-=o,f++)a.push(l(u));return a}function ey(t,e,r){let n=r??1;n===0&&(n=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(n),a=t>="A"&&t<="Z",c=t>="a"&&t<="z",l=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(a&&u||c&&l)return null;let f=[];if(s<=i)for(let p=s,d=0;p<=i&&d<1e4;p+=o,d++)f.push(String.fromCharCode(p));else for(let p=s,d=0;p>=i&&d<1e4;p-=o,d++)f.push(String.fromCharCode(p));return f}function or(t,e,r,n,s){let i=r!==void 0?`..${r}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:Y0(t,e,r,n,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:ey(t,e,r),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function Ie(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=ty(t,n);if(i===-1)r+="\\[",n++;else{let o=t.slice(n+1,i);r+=ry(o),n=i+1}}else/[\^$.|+(){}]/.test(s)?(r+=`\\${s}`,n++):(r+=s,n++)}return r}function ty(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 ry(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 o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;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+=sy(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 ny={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 sy(t){return ny[t]??""}J();function ar(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),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&n.push(o)}return n.sort((s,i)=>s-i)}function cr(t,e){let r=`${e}_`;for(let n of Object.keys(t.state.env))n.startsWith(r)&&delete t.state.env[n]}function Vs(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 xu(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function sn(t){return t.IFS??`
530
+ `}function wu(t){return t.IFS===""}function lr(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
531
+ `?"\\n":e).join("")}function iy(t,e){let r=lr(t);return new RegExp(`[${r}]+`,e)}function oy(t){let e=lr(t);return new RegExp(`^[${e}]+`)}function ay(t){let e=lr(t);return new RegExp(`[${e}]+$`)}function Ht(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function Eu(t,e){if(e==="")return{words:[t],wordStarts:[0]};let r=[],n=[],s=iy(e,"g"),i=0,o=t.match(oy(e));o&&(i=o[0].length),s.lastIndex=i;let a=s.exec(t);for(;a!==null;)a.index>i&&(n.push(i),r.push(t.substring(i,a.index))),i=s.lastIndex,a=s.exec(t);return i<t.length&&(n.push(i),r.push(t.substring(i))),{words:r,wordStarts:n}}function bu(t,e){return e===""?t:t.replace(ay(e),"")}function ue(t,e){return t.state.associativeArrays?.has(e)?Vs(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):ar(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function Su(t,e){return t.state.associativeArrays?.has(e)?Vs(t,e).length>0:ar(t,e).length>0}function Fe(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 o="";return t.state.options.errexit&&(o+="e"),t.state.options.nounset&&(o+="u"),t.state.options.verbose&&(o+="v"),t.state.options.xtrace&&(o+="x"),t.state.options.pipefail&&(o+="p"),o}case"*":{let o=Number.parseInt(t.state.env["#"]||"0",10);if(o===0)return"";let a=[];for(let c=1;c<=o;c++)a.push(t.state.env[String(c)]||"");return a.join(Ht(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:"";case"PPID":{let{ppid:o}=ir();return String(o)}case"UID":{let{uid:o}=ir();return String(o)}case"EUID":return String(process.geteuid?.()??ir().uid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-t.state.startTime)/1e3));case"BASH_VERSION":return Hl;case"!":return String(t.state.lastBackgroundPid);case"LINENO":return String(t.state.currentLine)}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(e))throw new Ke(`\${${e}}`);let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let o=s[1],a=s[2];if(a==="@"||a==="*"){let f=ue(t,o);if(f.length>0)return f.map(([,d])=>d).join(" ");let p=t.state.env[o];return p!==void 0?p:""}if(t.state.associativeArrays?.has(o)){let f=xu(a),p=t.state.env[`${o}_${f}`];if(p===void 0&&r&&t.state.options.nounset)throw new Pe(`${o}[${a}]`);return p||""}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let f=new he,p=le(f,a);l=K(t,p.expression)}catch{let f=t.state.env[a];l=f?Number.parseInt(f,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let f=ue(t,o);if(f.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
532
+ `,"";let d=Math.max(...f.map(([g])=>typeof g=="number"?g:0))+1+l;return d<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
533
+ `,""):t.state.env[`${o}_${d}`]||""}let u=t.state.env[`${o}_${l}`];if(u===void 0&&r&&t.state.options.nounset)throw new Pe(`${o}[${l}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let o=t.state.env[e];if(o===void 0&&r&&t.state.options.nounset)throw new Pe(e);return o||""}let i=t.state.env[e];if(i===void 0&&r&&t.state.options.nounset)throw new Pe(e);return i||""}async function Au(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"&&qs(u)){let p=await s(t,u);i.push({value:p,splittable:!1})}else{let p=await s(t,u);i.push({value:p,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 a=new RegExp(`[${n}]+`),c=[],l="";for(let u=0;u<i.length;u++){let f=i[u];if(!f.splittable)l+=f.value;else{let p=f.value.split(a);for(let d=0;d<p.length;d++)d===0?l+=p[d]:(l!==""&&c.push(l),l=p[d])}}return l!==""&&c.push(l),c}function ve(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Cu(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function ku(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Ks(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`
534
+ `: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=>Je(t,n,r)).join("")}async function wt(t,e,r=!1){let n=[];for(let s of e)n.push(await De(t,s));return n.join("")}function cy(t){return ku(t)}function Nu(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!cy(e))return!1;return!0}function Iu(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function vu(t,e,r=!1){let n=Cu(e);if(n!==null)return n;switch(e.type){case"ParameterExpansion":return Tu(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 Je(t,e,r=!1){let n=vu(t,e,r);if(n!==null)return n;switch(e.type){case"DoubleQuoted":{let s=[];for(let i of e.parts)s.push(Je(t,i,!0));return s.join("")}case"ArithmeticExpansion":return String(K(t,e.expression.expression));case"BraceExpansion":{let s=[];for(let i of e.items)if(i.type==="Range"){let o=or(i.start,i.end,i.step,i.startStr,i.endStr);if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(on(t,i.word));return s.join(" ")}default:return""}}function on(t,e){let r=e.parts,n=r.length;if(n===1)return Je(t,r[0]);let s=[];for(let i=0;i<n;i++)s.push(Je(t,r[i]));return s.join("")}async function Y(t,e){return Xe(e)?Pu(t,e):on(t,e)}function an(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&an(e.parts))return!0;return!1}function ly(t){for(let e of t){if(e.type==="BraceExpansion"){for(let r of e.items)if(r.type==="Word"&&Xe(r.word))return!0}if(nn(e))return!0}return!1}var Ru=1e4,jt=1e5;function $u(t,e,r={count:0}){if(r.count>jt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of s.items)if(u.type==="Range"){let f=or(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let p of f.expanded)r.count++,i.push(p);else{o=!0,a=f.literal;break}}else{let f=$u(t,u.word.parts,r);for(let p of f)r.count++,i.push(p.join(""))}if(o){for(let u of n)r.count++,u.push(a);continue}if(n.length*i.length>Ru||r.count>jt)return n;let l=[];for(let u of n)for(let f of i){if(r.count++,r.count>jt)return l.length>0?l:n;l.push([...u,f])}n=l}else{let i=Je(t,s);for(let o of n)r.count++,o.push(i)}return n}function uy(t,e){let r=e.parts;return an(r)?$u(t,r).map(s=>s.join("")):[on(t,e)]}async function Ou(t,e,r={count:0}){if(r.count>jt)return[[]];let n=[[]];for(let s of e)if(s.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of s.items)if(u.type==="Range"){let f=or(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let p of f.expanded)r.count++,i.push(p);else{o=!0,a=f.literal;break}}else{let f=await Ou(t,u.word.parts,r);for(let p of f)r.count++,i.push(p.join(""))}if(o){for(let u of n)r.count++,u.push(a);continue}if(n.length*i.length>Ru||r.count>jt)return n;let l=[];for(let u of n)for(let f of i){if(r.count++,r.count>jt)return l.length>0?l:n;l.push([...u,f])}n=l}else{let i=await De(t,s);for(let o of n)r.count++,o.push(i)}return n}async function fy(t,e){let r=e.parts;return an(r)?(await Ou(t,r)).map(s=>s.join("")):[await Y(t,e)]}async function ur(t,e){let r=e.parts,{hasQuoted:n,hasCommandSub:s,hasArrayVar:i,hasArrayAtExpansion:o,hasParamExpansion:a}=gu(r),l=an(r)?ly(r)?await fy(t,e):uy(t,e):null;if(l&&l.length>1){let p=[];for(let d of l)if(!n&&/[*?[]/.test(d)){let g=await new Ut(t.fs,t.state.cwd).expand(d);g.length>0?p.push(...g):p.push(d)}else p.push(d);return{values:p,quoted:!1}}if(o&&r.length===1&&r[0].type==="DoubleQuoted"){let p=r[0];if(p.parts.length===1&&p.parts[0].type==="ParameterExpansion"){let h=p.parts[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@]\]$/);if(h){let g=h[1],y=ue(t,g);if(y.length>0)return{values:y.map(([,E])=>E),quoted:!0};let w=t.state.env[g];return w!==void 0?{values:[w],quoted:!0}:{values:[],quoted:!0}}}}if(r.length===1&&r[0].type==="DoubleQuoted"){let p=r[0],d=-1,h=!1;for(let g=0;g<p.parts.length;g++){let y=p.parts[g];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")){d=g,h=y.parameter==="*";break}}if(d!==-1){let g=p.parts[d];g.type==="ParameterExpansion"&&g.operation&&(d=-1)}if(d!==-1){let g=Number.parseInt(t.state.env["#"]||"0",10),y="";for(let S=0;S<d;S++)y+=await De(t,p.parts[S]);let w="";for(let S=d+1;S<p.parts.length;S++)w+=await De(t,p.parts[S]);if(g===0){if(h)return{values:[y+w],quoted:!0};let S=y+w;return{values:S?[S]:[],quoted:!0}}let E=[];for(let S=1;S<=g;S++)E.push(t.state.env[String(S)]||"");if(h){let S=Ht(t.state.env);return{values:[y+E.join(S)+w],quoted:!0}}return E.length===1?{values:[y+E[0]+w],quoted:!0}:{values:[y+E[0],...E.slice(1,-1),E[E.length-1]+w],quoted:!0}}}if((s||i||a)&&!wu(t.state.env)){let p=sn(t.state.env),d=lr(p),h=await Au(t,r,p,d,De),g=[],y=new Ut(t.fs,t.state.cwd);for(let w of h)if(/[*?[]/.test(w)){let E=await y.expand(w);E.length>0?g.push(...E):g.push(w)}else g.push(w);return{values:g,quoted:!1}}let f=Xe(e)?await Pu(t,e):on(t,e);if(!n&&/[*?[]/.test(f)){let d=await new Ut(t.fs,t.state.cwd).expand(f);if(d.length>0)return{values:d,quoted:!1}}return f===""&&!n?{values:[],quoted:!1}:{values:[f],quoted:n}}async function Pu(t,e){let r=e.parts,n=r.length;if(n===1)return De(t,r[0]);let s=[];for(let i=0;i<n;i++)s.push(await De(t,r[i]));return s.join("")}async function De(t,e){if(e.type==="ParameterExpansion"&&Gs(e))return py(t,e);let r=vu(t,e);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let n=[];for(let s of e.parts)n.push(await De(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 W)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=or(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 Y(t,s.word));return n.join(" ")}default:return""}}function Tu(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Fe(t,n,!i);if(!s)return o;let a=!(n in t.state.env),c=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&c)&&s.word?xt(t,s.word.parts,r):o;case"AssignDefault":{if((a||s.checkEmpty&&c)&&s.word){let u=xt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,p,d]=f,h;if(/^\d+$/.test(d))h=Number.parseInt(d,10);else{try{let y=new he,w=le(y,d);h=K(t,w.expression)}catch{let y=t.state.env[d];h=y?Number.parseInt(y,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${p}_${h}`]=u;let g=Number.parseInt(t.state.env[`${p}__length`]||"0",10);h>=g&&(t.state.env[`${p}__length`]=String(h+1))}else t.state.env[n]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&c){let u=s.word?xt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
535
+ `)}return o}case"UseAlternative":return!(a||s.checkEmpty&&c)&&s.word?xt(t,s.word.parts,r):"";case"Length":{let l=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l){let u=ue(t,l[1]);return String(u.length)}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Su(t,n)){let u=t.state.env[`${n}_0`]||"";return String(u.length)}return String(o.length)}case"LengthSliceError":throw new Ke(n);case"Substring":{let l=s.offset?K(t,s.offset.expression):0,u=s.length?K(t,s.length.expression):void 0;if(n==="@"||n==="*"){let h=(t.state.env["@"]||"").split(" ").filter(E=>E),g=t.state.env[0]||"bash",y=l===0?[g,...h]:h,w=l===0?0:l-1;if(w<0||w>=y.length)return"";if(u!==void 0){let E=u<0?y.length+u:w+u;return y.slice(w,Math.max(w,E)).join(" ")}return y.slice(w).join(" ")}let f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(f){let g=ue(t,f[1]).map(([,w])=>w),y=l;if(y<0&&(y=g.length+y,y<0))return"";if(u!==void 0){if(u<0){let w=g.length+u;return g.slice(y,Math.max(y,w)).join(" ")}return g.slice(y,y+u).join(" ")}return g.slice(y).join(" ")}let p=[...o],d=l;if(d<0&&(d=Math.max(0,p.length+d)),u!==void 0){if(u<0){let h=p.length+u;return p.slice(d,Math.max(d,h)).join("")}return p.slice(d,d+u).join("")}return p.slice(d).join("")}case"PatternRemoval":{let l="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")l+=Ie(f.pattern,s.greedy);else if(f.type==="Literal")l+=Ie(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")l+=ve(f.value);else if(f.type==="DoubleQuoted"){let p=xt(t,f.parts);l+=ve(p)}else if(f.type==="ParameterExpansion"){let p=Je(t,f);l+=Ie(p,s.greedy)}else{let p=Je(t,f);l+=ve(p)}if(s.side==="prefix")return o.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(s.greedy)return o.replace(u,"");for(let f=o.length;f>=0;f--){let p=o.slice(f);if(u.test(p))return o.slice(0,f)}return o}case"PatternReplacement":{let l="";if(s.pattern)for(let p of s.pattern.parts)if(p.type==="Glob")l+=Ie(p.pattern,!0);else if(p.type==="Literal")l+=Ie(p.value,!0);else if(p.type==="SingleQuoted"||p.type==="Escaped")l+=ve(p.value);else if(p.type==="DoubleQuoted"){let d=xt(t,p.parts);l+=ve(d)}else if(p.type==="ParameterExpansion"){let d=Je(t,p);l+=Ie(d,!0)}else{let d=Je(t,p);l+=ve(d)}let u=s.replacement?xt(t,s.replacement.parts):"";if(l==="")return o;s.anchor==="start"?l=`^${l}`:s.anchor==="end"&&(l=`${l}$`);let f=s.all?"g":"";try{let p=new RegExp(l,f);if(s.all){let d="",h=0,g=p.exec(o);for(;g!==null&&!(g[0].length===0&&g.index===o.length);)d+=o.slice(h,g.index)+u,h=g.index+g[0].length,g[0].length===0&&h++,g=p.exec(o);return d+=o.slice(h),d}return o.replace(p,u)}catch{return o}}case"CaseModification":return s.direction==="upper"?s.all?o.toUpperCase():o.charAt(0).toUpperCase()+o.slice(1):s.all?o.toLowerCase():o.charAt(0).toLowerCase()+o.slice(1);case"Transform":{let l=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l&&s.operator==="Q")return ue(t,l[1]).map(([,p])=>Ks(p)).join(" ");switch(s.operator){case"Q":return Ks(o);case"P":return o;case"a":return"";case"A":return`${n}=${Ks(o)}`;case"E":return o.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`
536
+ `;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 o}}case"Indirection":return Fe(t,o);case"ArrayKeys":{let u=ue(t,s.array).map(([f])=>String(f));return s.star?u.join(Ht(t.state.env)):u.join(" ")}case"VarNamePrefix":{let l=Object.keys(t.state.env).filter(u=>u.startsWith(s.prefix)&&!u.includes("__")).sort();return s.star?l.join(Ht(t.state.env)):l.join(" ")}default:return o}}async function py(t,e,r=!1){let{parameter:n,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Fe(t,n,!i);if(!s)return o;let a=!(n in t.state.env),c=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&c)&&s.word?wt(t,s.word.parts,r):o;case"AssignDefault":{if((a||s.checkEmpty&&c)&&s.word){let u=await wt(t,s.word.parts,r),f=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let[,p,d]=f,h;if(/^\d+$/.test(d))h=Number.parseInt(d,10);else{try{let y=new he,w=le(y,d);h=await Z(t,w.expression)}catch{let y=t.state.env[d];h=y?Number.parseInt(y,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${p}_${h}`]=u;let g=Number.parseInt(t.state.env[`${p}__length`]||"0",10);h>=g&&(t.state.env[`${p}__length`]=String(h+1))}else t.state.env[n]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&c){let u=s.word?await wt(t,s.word.parts,r):`${n}: parameter null or not set`;throw new X(1,"",`bash: ${u}
537
+ `)}return o}case"UseAlternative":return!(a||s.checkEmpty&&c)&&s.word?wt(t,s.word.parts,r):"";case"PatternRemoval":{let l="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")l+=Ie(f.pattern,s.greedy);else if(f.type==="Literal")l+=Ie(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")l+=ve(f.value);else if(f.type==="DoubleQuoted"){let p=await wt(t,f.parts);l+=ve(p)}else if(f.type==="ParameterExpansion"){let p=await De(t,f);l+=Ie(p,s.greedy)}else{let p=await De(t,f);l+=ve(p)}if(s.side==="prefix")return o.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(s.greedy)return o.replace(u,"");for(let f=o.length;f>=0;f--){let p=o.slice(f);if(u.test(p))return o.slice(0,f)}return o}case"PatternReplacement":{let l="";if(s.pattern)for(let p of s.pattern.parts)if(p.type==="Glob")l+=Ie(p.pattern,!0);else if(p.type==="Literal")l+=Ie(p.value,!0);else if(p.type==="SingleQuoted"||p.type==="Escaped")l+=ve(p.value);else if(p.type==="DoubleQuoted"){let d=await wt(t,p.parts);l+=ve(d)}else if(p.type==="ParameterExpansion"){let d=await De(t,p);l+=Ie(d,!0)}else{let d=await De(t,p);l+=ve(d)}let u=s.replacement?await wt(t,s.replacement.parts):"";if(l==="")return o;s.anchor==="start"?l=`^${l}`:s.anchor==="end"&&(l=`${l}$`);let f=s.all?"g":"";try{let p=new RegExp(l,f);if(s.all){let d="",h=0,g=p.exec(o);for(;g!==null&&!(g[0].length===0&&g.index===o.length);)d+=o.slice(h,g.index)+u,h=g.index+g[0].length,g[0].length===0&&h++,g=p.exec(o);return d+=o.slice(h),d}return o.replace(p,u)}catch{return o}}default:return Tu(t,e,r)}}function Zs(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 Fu(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 Qs(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function dy(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:Fe(t,e)}function zt(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}=Ze(n,r,0);if(i<r.length){let o=r.slice(i).trim().split(/\s+/)[0];throw new ae(`${r}: syntax error in expression (error token is "${o}")`)}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 cn(t,e,r=new Set){if(r.has(e))return 0;r.add(e);let n=dy(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 cn(t,i,r);try{let o=new he,{expr:a}=Ze(o,i,0);return Le(t,a,r)}catch{return 0}}function Le(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 cn(t,e.name,r);case"ArithBinary":{if(e.operator==="||")return Le(t,e.left,r)||Le(t,e.right,r)?1:0;if(e.operator==="&&")return Le(t,e.left,r)&&Le(t,e.right,r)?1:0;let n=Le(t,e.left,r),s=Le(t,e.right,r);return Zs(n,s,e.operator)}case"ArithUnary":{let n=Le(t,e.operand,r);return Qs(n,e.operator)}case"ArithTernary":return Le(t,e.condition,r)?Le(t,e.consequent,r):Le(t,e.alternate,r);case"ArithGroup":return Le(t,e.expression,r);default:return K(t,e)}}function it(t,e){if(e.startsWith("#")){let f=e.slice(1),p=t.state.env[f]||"";return String(p.length)}if(e.startsWith("!")){let f=e.slice(1),p=t.state.env[f]||"";return t.state.env[p]||""}let r=[":-",":=",":?",":+","-","=","?","+"],n=-1,s="";for(let f of r){let p=e.indexOf(f);p>0&&(n===-1||p<n)&&(n=p,s=f)}if(n===-1)return Fe(t,e);let i=e.slice(0,n),o=e.slice(n+s.length),a=t.state.env[i],c=a===void 0,l=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return c||u&&l?o:a||"";case":=":case"=":return c||u&&l?(t.state.env[i]=o,o):a||"";case":+":case"+":return!(c||u&&l)?o:"";case":?":case"?":{if(c||u&&l)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}function K(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 cn(t,e.name);case"ArithNested":return K(t,e.expression);case"ArithCommandSubst":return 0;case"ArithBracedExpansion":{let r=it(t,e.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=it(t,e.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let s=`${n}#${e.value}`;return Wt(s)}case"ArithDynamicNumber":{let n=it(t,e.prefix)+e.suffix;return Wt(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=K(t,e.index);if(i<0){let a=ue(t,e.array);if(a.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
538
+ `,0;let l=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1+i;if(l<0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
539
+ `,0;i=l}n=`${e.array}_${i}`;let o=t.state.env[n];if(o!==void 0)return zt(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return zt(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(c=>c===e.array||c.startsWith(`${e.array}_`)))throw new Pe(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[n];return s!==void 0?zt(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 K(t,e.left)||K(t,e.right)?1:0;if(e.operator==="&&")return K(t,e.left)&&K(t,e.right)?1:0;let r=K(t,e.left),n=K(t,e.right);return Zs(r,n,e.operator)}case"ArithUnary":{let r=K(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let n=e.operand.name,s=Number.parseInt(Fe(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 c=K(t,e.operand.index);i=`${n}_${c}`}else return r;let o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return r}return Qs(r,e.operator)}case"ArithTernary":return K(t,e.condition)?K(t,e.consequent):K(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 a=t.state.associativeArrays?.has(r);if(a&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(a){let c=K(t,e.subscript);n=`${r}_${c}`}else{let c=K(t,e.subscript);if(c<0){let l=ue(t,r);l.length>0&&(c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+c)}n=`${r}_${c}`}}let s=Number.parseInt(t.state.env[n]||"0",10)||0,i=K(t,e.value),o=Fu(s,i,e.operator);return t.state.env[n]=String(o),o}case"ArithGroup":return K(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=Du(t,n);return Number.parseInt(r,10)||0}default:return 0}}function Du(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Fe(t,e.name);case"ArithBracedExpansion":return it(t,e.content);case"ArithCommandSubst":return"0";case"ArithConcat":{let r="";for(let n of e.parts)r+=Du(t,n);return r}default:return String(K(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 cn(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=it(t,e.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=it(t,e.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let s=`${n}#${e.value}`;return Wt(s)}case"ArithDynamicNumber":{let n=it(t,e.prefix)+e.suffix;return Wt(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 o=t.state.env[n];if(o!==void 0)return zt(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return zt(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(c=>c===e.array||c.startsWith(`${e.array}_`)))throw new Pe(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[n];return s!==void 0?zt(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 Zs(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(Fe(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 c=await Z(t,e.operand.index);i=`${n}_${c}`}else return r;let o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return r}return Qs(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 a=t.state.associativeArrays?.has(r);if(a&&e.subscript.type==="ArithVariable")n=`${r}_${e.subscript.name}`;else if(a){let c=await Z(t,e.subscript);n=`${r}_${c}`}else{let c=await Z(t,e.subscript);if(c<0){let l=ue(t,r);l.length>0&&(c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+c)}n=`${r}_${c}`}}let s=Number.parseInt(t.state.env[n]||"0",10)||0,i=await Z(t,e.value),o=Fu(s,i,e.operator);return t.state.env[n]=String(o),o}case"ArithGroup":return await Z(t,e.expression);case"ArithConcat":{let r="";for(let n of e.parts)r+=await Lu(t,n);return Number.parseInt(r,10)||0}default:return 0}}async function Lu(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Fe(t,e.name);case"ArithBracedExpansion":return it(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 Lu(t,n);return r}default:return String(await Z(t,e))}}J();J();var V=Object.freeze({stdout:"",stderr:"",exitCode:0});function Re(t=""){return{stdout:t,stderr:"",exitCode:0}}function B(t,e=1){return{stdout:"",stderr:t,exitCode:e}}function P(t,e,r){return{stdout:t,stderr:e,exitCode:r}}function ce(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function Ye(t,e,r="",n=""){throw new W(t,e,r,n)}function Xs(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new Ge;return V}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
540
+ `);r=n}throw new me(r)}async function Js(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 o=e.slice(i);if(o.length===0||o[0]==="~"?r=t.state.env.HOME||"/":o[0]==="-"?(r=t.state.previousDir,n=!0):r=o[0],!r.startsWith("/")&&!r.startsWith("./")&&!r.startsWith("../")&&r!=="."&&r!==".."){let f=t.state.env.CDPATH;if(f){let p=f.split(":").filter(d=>d);for(let d of p){let h=d.startsWith("/")?`${d}/${r}`:`${t.state.cwd}/${d}/${r}`;try{if((await t.fs.stat(h)).isDirectory){r=h,n=!0;break}}catch{}}}}let c=(r.startsWith("/")?r:`${t.state.cwd}/${r}`).split("/").filter(f=>f&&f!=="."),l="";for(let f of c)if(f==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${f}`:`/${f}`;try{if(!(await t.fs.stat(l)).isDirectory)return B(`bash: cd: ${r}: Not a directory
541
+ `)}catch{return B(`bash: cd: ${r}: No such file or directory
542
+ `)}}let u=l||"/";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,Re(n?`${u}
543
+ `:"")}J();function Ys(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new Ge;return V}if(e.length>1)throw new me(1);let r=1;if(e.length>0){let n=Number.parseInt(e[0],10);if(Number.isNaN(n)||n<1)return B(`bash: continue: ${e[0]}: numeric argument required
544
+ `);r=n}throw new Ee(r)}function Et(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function hy(t,e){return t.state.readonlyVars?.has(e)??!1}function ot(t,e,r="bash"){return hy(t,e)?B(`${r}: ${e}: readonly variable
545
+ `):null}function Mu(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:ei(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 _u(t,e,r={}){let{name:n,isArray:s,arrayElements:i,value:o}=e,{makeReadonly:a=!1,checkReadonly:c=!0}=r;if(c){let l=ot(t,n);if(l)return l}if(s&&i){for(let l=0;l<i.length;l++)t.state.env[`${n}_${l}`]=i[l];t.state.env[`${n}__length`]=String(i.length)}else o!==void 0&&(t.state.env[n]=o);return a&&Et(t,n),null}function ti(t,e){let r=!1,n=!1,s=!1,i=!1,o=!1,a=[];for(let c=0;c<e.length;c++){let l=e[c];if(l==="-a")r=!0;else if(l==="-A")n=!0;else if(l==="-r")s=!0;else if(l==="-x")i=!0;else if(l==="-p")o=!0;else if(l==="--"){a.push(...e.slice(c+1));break}else if(l.startsWith("-"))for(let u of l.slice(1))u==="a"?r=!0:u==="A"?n=!0:u==="r"?s=!0:u==="x"?i=!0:u==="p"&&(o=!0);else a.push(l)}if(o&&a.length>0){let c="";for(let l of a){let u=t.state.env[l];if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');c+=`declare -- ${l}="${f}"
546
+ `}}return Re(c)}if(a.length===0&&!o){let c="",l=Object.entries(t.state.env).filter(([u])=>!u.startsWith("BASH_")).sort(([u],[f])=>u.localeCompare(f));for(let[u,f]of l){let p=f.replace(/'/g,"'\\''");c+=`declare -- ${u}='${p}'
547
+ `}return Re(c)}for(let c of a){let l=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(l){let u=l[1],f=l[2];if(n&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),n&&f.includes("[")){let p=my(f);for(let[d,h]of p)t.state.env[`${u}_${d}`]=h}else{let p=ei(f);for(let d=0;d<p.length;d++)t.state.env[`${u}_${d}`]=p[d];t.state.env[`${u}__length`]=String(p.length)}s&&Et(t,u);continue}if(c.includes("=")){let u=c.indexOf("="),f=c.slice(0,u),p=c.slice(u+1),d=ot(t,f);if(d)return d;t.state.env[f]=p,s&&Et(t,f)}else{let u=c;n&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u));let f=Object.keys(t.state.env).some(p=>p.startsWith(`${u}_`)&&!p.startsWith(`${u}__length`));!(u in t.state.env)&&!f&&(r||n?t.state.env[`${u}__length`]="0":t.state.env[u]=""),s&&Et(t,u)}}return V}function ei(t){let e=[],r="",n=!1,s=!1,i=!1;for(let o of t){if(i){r+=o,i=!1;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!s){n=!n;continue}if(o==='"'&&!n){s=!s;continue}if((o===" "||o===" "||o===`
548
+ `)&&!n&&!s){r&&(e.push(r),r="");continue}r+=o}return r&&e.push(r),e}function my(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 ri(t,e){let r=!1,n=!1,s=[];for(let i=0;i<e.length;i++){let o=e[i];if(o==="-a")r=!0;else if(o==="-A")n=!0;else if(o==="-p"){if(e.length===1){let a="";for(let c of t.state.readonlyVars||[]){let l=t.state.env[c];l!==void 0&&(a+=`declare -r ${c}="${l}"
549
+ `)}return Re(a)}}else if(o==="--"){s.push(...e.slice(i+1));break}else o.startsWith("-")||s.push(o)}for(let i of s){let o=Mu(i);if(o.value===void 0&&!o.isArray){Et(t,o.name);continue}let a=_u(t,o,{makeReadonly:!0});if(a)return a}return V}J();async function ni(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 B(`bash: eval: ${s}: invalid option
545
550
  eval: usage: eval [arg ...]
546
- `,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 he||s instanceof ye||s instanceof me||s instanceof X)throw s;if(s.name==="ParseException")return _(`bash: eval: ${s.message}
547
- `);throw s}}J();function Xs(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
548
- `,r=2):r=(i%256+256)%256}throw new X(r,"",n)}function Ks(t,e){let r=!1,n=[];for(let o of e)o==="-n"?r=!0:o==="-p"||o==="--"||n.push(o);if(n.length===0&&!r){let o="",a=Object.entries(t.state.env).filter(([l])=>!l.startsWith("BASH_ALIAS_")).sort(([l],[c])=>l.localeCompare(c));for(let[l,c]of a){let u=c.replace(/'/g,"'\\''");o+=`declare -x ${l}='${u}'
549
- `}return Ne(o)}if(r){for(let o of n){let a=o.split("=")[0];delete t.state.env[a]}return q}let s="",i=0;for(let o of n){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
550
- `,i=1;continue}l!==void 0?t.state.env[a]=l:a in t.state.env||(t.state.env[a]="")}return R("",s,i)}function Z0(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 Js(t,e){if(e.length===0)return _(`bash: let: expression expected
551
- `);let r=Z0(e),n=0;for(let s of r)try{let o=nt(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await Z(t,a.expression.expression))}}catch(i){return _(`bash: let: ${s}: ${i.message}
552
- `)}return R("","",n===0?1:0)}function Q0(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 Ys(t,e){if(t.state.localScopes.length===0)return _(`bash: local: can only be used in a function
553
- `);let r=t.state.localScopes[t.state.localScopes.length-1],n="",s=0;for(let i of e){let o,a;if(i.includes("=")){let l=i.indexOf("=");o=i.slice(0,l),a=Q0(t,i.slice(l+1))}else o=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){n+=`bash: local: \`${i}': not a valid identifier
554
- `,s=1;continue}r.has(o)||r.set(o,t.state.env[o]),a!==void 0&&(t.state.env[o]=a)}return R("",n,s)}function ei(t,e,r){let n=`
555
- `,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<e.length;){let w=e[c];w==="-d"&&c+1<e.length?(n=e[c+1]||`
556
- `,c+=2):w==="-n"&&c+1<e.length?(s=Number.parseInt(e[c+1],10)||0,c+=2):w==="-O"&&c+1<e.length?(i=Number.parseInt(e[c+1],10)||0,c+=2):w==="-s"&&c+1<e.length?(o=Number.parseInt(e[c+1],10)||0,c+=2):w==="-t"?(a=!0,c++):w==="-u"||w==="-C"||w==="-c"?c+=2:(w.startsWith("-")||(l=w),c++)}let u=r;!u&&t.state.groupStdin!==void 0&&(u=t.state.groupStdin);let f=[],d=u,p=0,h=0;for(;d.length>0;){let w=d.indexOf(n);if(w===-1){d.length>0&&(h<o?h++:(s===0||p<s)&&(f.push(d),p++));break}let g=d.substring(0,w);if(a||(g+=n),d=d.substring(w+n.length),h<o){h++;continue}if(s>0&&p>=s)break;f.push(g),p++}or(t,l);for(let w=0;w<f.length;w++)t.state.env[`${l}_${i+w}`]=f[w];return f.length>0&&(t.state.env[`${l}__length`]=String(i+f.length)),t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=""),R("","",0)}function ti(t,e,r){let n=!1,s=`
557
- `,i="",o=-1,a=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?(o=Number.parseInt(e[c+1],10),(Number.isNaN(o)||o<0)&&(u=!0,o=0),c++):E==="-a"&&c+1<e.length?(a=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 R("","",1);l.length===0&&a===null&&l.push("REPLY");let f=r;!f&&t.state.groupStdin!==void 0&&(f=t.state.groupStdin);let d="",p=0,h=!0;if(o>=0){for(let E=0;E<f.length&&E<o;E++){let b=f[E];if(b===s){p=E+1;break}d+=b,p=E+1}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(p))}else{let E=f;for(p=0;;){let b=E.indexOf(s);if(b!==-1){let S=E.substring(0,b);if(p+=b+s.length,E=E.substring(b+s.length),!n&&S.endsWith("\\")){d+=S.slice(0,-1);continue}d+=S,h=!0;break}else if(E.length>0){d+=E,p+=E.length,h=!1,E="";break}else{if(d.length===0){for(let S of l)t.state.env[S]="";return a&&or(t,a),R("","",1)}h=!1;break}}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(p))}if(s===`
558
- `&&d.endsWith(`
559
- `)&&(d=d.slice(0,-1)),n||(d=d.replace(/\\(.)/g,"$1")),l.length===1&&l[0]==="REPLY")return t.state.env.REPLY=d,R("","",h?0:1);let w=en(t.state.env),{words:g,wordStarts:y}=iu(d,w);if(a){or(t,a);for(let E=0;E<g.length;E++)t.state.env[`${a}_${E}`]=g[E];return R("","",h?0:1)}for(let E=0;E<l.length;E++){let b=l[E];if(E<l.length-1)t.state.env[b]=g[E]??"";else if(E<y.length){let S=ou(d.substring(y[E]),w);t.state.env[b]=S}else t.state.env[b]=""}return R("","",h?0:1)}J();function ri(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
560
- `,2);r=(s%256+256)%256}throw new me(r)}function X0(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var sn=`set: usage: set [-eux] [+eux] [-o option] [+o option]
551
+ `,2)}if(r.length===0)return V;let n=r.join(" ");if(n.trim()==="")return V;try{let s=st(n);return t.executeScript(s)}catch(s){if(s instanceof me||s instanceof Ee||s instanceof ye||s instanceof X)throw s;if(s.name==="ParseException")return B(`bash: eval: ${s.message}
552
+ `);throw s}}J();function si(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
553
+ `,r=2):r=(i%256+256)%256}throw new X(r,"",n)}function ii(t,e){let r=!1,n=[];for(let o of e)o==="-n"?r=!0:o==="-p"||o==="--"||n.push(o);if(n.length===0&&!r){let o="",a=Object.entries(t.state.env).filter(([c])=>!c.startsWith("BASH_ALIAS_")).sort(([c],[l])=>c.localeCompare(l));for(let[c,l]of a){let u=l.replace(/'/g,"'\\''");o+=`declare -x ${c}='${u}'
554
+ `}return Re(o)}if(r){for(let o of n){let a=o.split("=")[0];delete t.state.env[a]}return V}let s="",i=0;for(let o of n){let a,c;if(o.includes("=")){let l=o.indexOf("=");a=o.slice(0,l),c=o.slice(l+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
555
+ `,i=1;continue}c!==void 0?t.state.env[a]=c:a in t.state.env||(t.state.env[a]="")}return P("",s,i)}function yy(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 oi(t,e){if(e.length===0)return B(`bash: let: expression expected
556
+ `);let r=yy(e),n=0;for(let s of r)try{let o=st(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await Z(t,a.expression.expression))}}catch(i){return B(`bash: let: ${s}: ${i.message}
557
+ `)}return P("","",n===0?1:0)}function gy(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 ai(t,e){if(t.state.localScopes.length===0)return B(`bash: local: can only be used in a function
558
+ `);let r=t.state.localScopes[t.state.localScopes.length-1],n="",s=0;for(let i of e){let o,a;if(i.includes("=")){let c=i.indexOf("=");o=i.slice(0,c),a=gy(t,i.slice(c+1))}else o=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){n+=`bash: local: \`${i}': not a valid identifier
559
+ `,s=1;continue}r.has(o)||r.set(o,t.state.env[o]),a!==void 0&&(t.state.env[o]=a)}return P("",n,s)}function ci(t,e,r){let n=`
560
+ `,s=0,i=0,o=0,a=!1,c="MAPFILE",l=0;for(;l<e.length;){let g=e[l];g==="-d"&&l+1<e.length?(n=e[l+1]||`
561
+ `,l+=2):g==="-n"&&l+1<e.length?(s=Number.parseInt(e[l+1],10)||0,l+=2):g==="-O"&&l+1<e.length?(i=Number.parseInt(e[l+1],10)||0,l+=2):g==="-s"&&l+1<e.length?(o=Number.parseInt(e[l+1],10)||0,l+=2):g==="-t"?(a=!0,l++):g==="-u"||g==="-C"||g==="-c"?l+=2:(g.startsWith("-")||(c=g),l++)}let u=r;!u&&t.state.groupStdin!==void 0&&(u=t.state.groupStdin);let f=[],p=u,d=0,h=0;for(;p.length>0;){let g=p.indexOf(n);if(g===-1){p.length>0&&(h<o?h++:(s===0||d<s)&&(f.push(p),d++));break}let y=p.substring(0,g);if(a||(y+=n),p=p.substring(g+n.length),h<o){h++;continue}if(s>0&&d>=s)break;f.push(y),d++}cr(t,c);for(let g=0;g<f.length;g++)t.state.env[`${c}_${i+g}`]=f[g];return f.length>0&&(t.state.env[`${c}__length`]=String(i+f.length)),t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=""),P("","",0)}function li(t,e,r){let n=!1,s=`
562
+ `,i="",o=-1,a=null,c=[],l=0,u=!1;for(;l<e.length;){let E=e[l];E==="-r"?n=!0:E==="-d"&&l+1<e.length?(s=e[l+1],l++):E==="-p"&&l+1<e.length?(i=e[l+1],l++):E==="-n"&&l+1<e.length?(o=Number.parseInt(e[l+1],10),(Number.isNaN(o)||o<0)&&(u=!0,o=0),l++):E==="-a"&&l+1<e.length?(a=e[l+1],l++):E==="-t"?l+1<e.length&&!e[l+1].startsWith("-")&&l++:E==="-s"||E.startsWith("-")||c.push(E),l++}if(u)return P("","",1);c.length===0&&a===null&&c.push("REPLY");let f=r;!f&&t.state.groupStdin!==void 0&&(f=t.state.groupStdin);let p="",d=0,h=!0;if(o>=0){for(let E=0;E<f.length&&E<o;E++){let b=f[E];if(b===s){d=E+1;break}p+=b,d=E+1}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(d))}else{let E=f;for(d=0;;){let b=E.indexOf(s);if(b!==-1){let S=E.substring(0,b);if(d+=b+s.length,E=E.substring(b+s.length),!n&&S.endsWith("\\")){p+=S.slice(0,-1);continue}p+=S,h=!0;break}else if(E.length>0){p+=E,d+=E.length,h=!1,E="";break}else{if(p.length===0){for(let S of c)t.state.env[S]="";return a&&cr(t,a),P("","",1)}h=!1;break}}t.state.groupStdin!==void 0&&!r&&(t.state.groupStdin=f.substring(d))}if(s===`
563
+ `&&p.endsWith(`
564
+ `)&&(p=p.slice(0,-1)),n||(p=p.replace(/\\(.)/g,"$1")),c.length===1&&c[0]==="REPLY")return t.state.env.REPLY=p,P("","",h?0:1);let g=sn(t.state.env),{words:y,wordStarts:w}=Eu(p,g);if(a){cr(t,a);for(let E=0;E<y.length;E++)t.state.env[`${a}_${E}`]=y[E];return P("","",h?0:1)}for(let E=0;E<c.length;E++){let b=c[E];if(E<c.length-1)t.state.env[b]=y[E]??"";else if(E<w.length){let S=bu(p.substring(w[E]),g);t.state.env[b]=S}else t.state.env[b]=""}return P("","",h?0:1)}J();function ui(t,e){if(t.state.callDepth===0&&t.state.sourceDepth===0)return B("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 B(`bash: return: ${n}: numeric argument required
565
+ `,2);r=(s%256+256)%256}throw new ye(r)}function xy(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var ln=`set: usage: set [-eux] [+eux] [-o option] [+o option]
561
566
  Options:
562
567
  -e Exit immediately if a command exits with non-zero status
563
568
  +e Disable -e
@@ -573,68 +578,68 @@ Options:
573
578
  +o pipefail Disable pipefail
574
579
  -o xtrace Same as -x
575
580
  +o xtrace Disable xtrace
576
- `,Au={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},ku={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},vu=["errexit","nounset","pipefail","verbose","xtrace"],Nu=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function Iu(t,e,r){e!==null&&(t.state.options[e]=r)}function K0(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function si(t,e){if(e.includes("--help"))return Ne(sn);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}=${X0(i)}`).join(`
577
- `);return Ne(n?`${n}
578
- `:"")}let r=0;for(;r<e.length;){let n=e[r];if((n==="-o"||n==="+o")&&K0(e,r)){let s=e[r+1];if(!(s in ku))return _(`bash: set: ${s}: invalid option name
579
- ${sn}`);Iu(t,ku[s],n==="-o"),r+=2;continue}if(n==="-o"){let s=vu.map(a=>`${a.padEnd(16)}${t.state.options[a]?"on":"off"}`),i=Nu.map(a=>`${a.padEnd(16)}off`),o=[...s,...i].sort();return Ne(`${o.join(`
581
+ `,Bu={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},Wu={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},Uu=["errexit","nounset","pipefail","verbose","xtrace"],Hu=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function ju(t,e,r){e!==null&&(t.state.options[e]=r)}function wy(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function pi(t,e){if(e.includes("--help"))return Re(ln);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}=${xy(i)}`).join(`
582
+ `);return Re(n?`${n}
583
+ `:"")}let r=0;for(;r<e.length;){let n=e[r];if((n==="-o"||n==="+o")&&wy(e,r)){let s=e[r+1];if(!(s in Wu))return B(`bash: set: ${s}: invalid option name
584
+ ${ln}`);ju(t,Wu[s],n==="-o"),r+=2;continue}if(n==="-o"){let s=Uu.map(a=>`${a.padEnd(16)}${t.state.options[a]?"on":"off"}`),i=Hu.map(a=>`${a.padEnd(16)}off`),o=[...s,...i].sort();return Re(`${o.join(`
580
585
  `)}
581
- `)}if(n==="+o"){let s=vu.map(a=>`set ${t.state.options[a]?"-o":"+o"} ${a}`),i=Nu.map(a=>`set +o ${a}`),o=[...s,...i].sort();return Ne(`${o.join(`
586
+ `)}if(n==="+o"){let s=Uu.map(a=>`set ${t.state.options[a]?"-o":"+o"} ${a}`),i=Hu.map(a=>`set +o ${a}`),o=[...s,...i].sort();return Re(`${o.join(`
582
587
  `)}
583
- `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let s=n[0]==="-";for(let i=1;i<n.length;i++){let o=n[i];if(!(o in Au))return _(`bash: set: ${n[0]}${o}: invalid option
584
- ${sn}`);Iu(t,Au[o],s)}r++;continue}if(n==="--")return ni(t,e.slice(r+1)),q;if(n==="-"){if(t.state.options.xtrace=!1,t.state.options.verbose=!1,r+1<e.length)return ni(t,e.slice(r+1)),q;r++;continue}if(n==="+"){r++;continue}return n.startsWith("-")||n.startsWith("+")?_(`bash: set: ${n}: invalid option
585
- ${sn}`):(ni(t,e.slice(r)),q)}return q}function ni(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 ii(t,e){let r=1;if(e.length>0){let o=Number.parseInt(e[0],10);if(Number.isNaN(o)||o<0)return _(`bash: shift: ${e[0]}: numeric argument required
586
- `);r=o}let n=Number.parseInt(t.state.env["#"]||"0",10);if(r>n)return _(`bash: shift: shift count out of range
587
- `);if(r===0)return q;let s=[];for(let o=1;o<=n;o++)s.push(t.state.env[String(o)]||"");let i=s.slice(r);for(let o=1;o<=n;o++)delete t.state.env[String(o)];for(let o=0;o<i.length;o++)t.state.env[String(o+1)]=i[o];return t.state.env["#"]=String(i.length),t.state.env["@"]=i.join(" "),q}J();async function oi(t,e){let r=e;if(r.length>0&&r[0]==="--"&&(r=r.slice(1)),r.length===0)return R("",`bash: source: filename argument required
588
- `,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
589
- `);let o={};if(r.length>1){for(let c=1;c<=9;c++)o[String(c)]=t.state.env[String(c)];o["#"]=t.state.env["#"],o["@"]=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 a=()=>{if(t.state.sourceDepth--,r.length>1)for(let[l,c]of Object.entries(o))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 a(),c}catch(l){if(a(),l instanceof X)throw l;if(l instanceof me)return R(l.stdout,l.stderr,l.exitCode);if(l.name==="ParseException")return _(`bash: ${n}: ${l.message}
590
- `);throw l}}function ai(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 o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let a=o[1],l=o[2];if(l==="@"||l==="*"){let u=ce(t,a);for(let[f]of u)delete t.state.env[`${a}_${f}`];delete t.state.env[a];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,a),f=u.length;if(f===0){n+=`bash: unset: [${c}]: bad array subscript
591
- `,s=1;continue}let d=f+c;if(d<0){n+=`bash: unset: [${c}]: bad array subscript
592
- `,s=1;continue}let p=u[d][0];delete t.state.env[`${a}_${p}`];continue}delete t.state.env[`${a}_${c}`];continue}delete t.state.env[i],t.state.functions.delete(i)}return R("",n,s)}function li(t,e){return t.fs.resolvePath(t.state.cwd,e)}var J0=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function on(t){return J0.includes(t)}async function an(t,e,r){let n=li(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 Y0=["-nt","-ot","-ef"];function ln(t){return Y0.includes(t)}async function cn(t,e,r,n){let s=li(t,r),i=li(t,n);switch(e){case"-nt":try{let o=await t.fs.stat(s),a=await t.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await t.fs.stat(s),a=await t.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await t.fs.exists(s)||!await t.fs.exists(i))return!1;let o=t.fs.resolvePath(t.state.cwd,s),a=t.fs.resolvePath(t.state.cwd,i);return o===a}catch{return!1}default:return!1}}var eg=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function un(t){return eg.has(t)}function fn(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 dn(t){return t==="="||t==="=="||t==="!="}function pn(t,e,r,n=!1){let s=n?hn(e,r):e===r;return t==="!="?!s:s}var tg=new Set(["-z","-n"]);function mn(t){return tg.has(t)}function gn(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function xn(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,(o,a)=>t.state.env[a]||"");let i;if(/^-?\d+$/.test(s))i=Number.parseInt(s,10);else try{let o=Function(`"use strict"; return (${s})`)();i=typeof o=="number"?Math.floor(o):0}catch{let o=t.state.env[s];i=o?Number.parseInt(o,10):0}if(i<0){let o=ir(t,n);if(o.length===0||(i=Math.max(...o)+1+i,i<0))return!1}return`${n}_${i}`in t.state.env}return e in t.state.env}async function ot(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(dn(e.operator))return pn(e.operator,r,n,!s);if(un(e.operator))return fn(e.operator,Ru(t,r),Ru(t,n));if(ln(e.operator))return cn(t,e.operator,r,n);switch(e.operator){case"=~":try{let i=new RegExp(n),o=r.match(i);if(o){t.state.env.BASH_REMATCH=o[0];for(let a=1;a<o.length;a++)t.state.env[`BASH_REMATCH_${a}`]=o[a]||""}return o!==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 on(e.operator)?an(t,e.operator,r):mn(e.operator)?gn(e.operator,r):e.operator==="-v"?xn(t,r):e.operator==="-o"?ui(t,r):!1}case"CondNot":return!await ot(t,e.operand);case"CondAnd":return await ot(t,e.left)?await ot(t,e.right):!1;case"CondOr":return await ot(t,e.left)?!0:await ot(t,e.right);case"CondGroup":return await ot(t,e.expression);case"CondWord":return await K(t,e.word)!=="";default:return!1}}async function Ut(t,e){if(e.length===0)return R("","",1);if(e.length===1)return ae(!!e[0]);if(e.length===2){let n=e[0],s=e[1];return n==="("?_(`test: '(' without matching ')'
593
- `,2):on(n)?ae(await an(t,n,s)):mn(n)?ae(gn(n,s)):n==="!"?ae(!s):n==="-v"?ae(xn(t,s)):n==="-o"?ae(ui(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
594
- `,2):R("","",1)}if(e.length===3){let n=e[0],s=e[1],i=e[2];if(dn(s))return ae(pn(s,n,i));if(un(s)){let o=yn(n),a=yn(i);return!o.valid||!a.valid?R("","",2):ae(fn(s,o.value,a.value))}if(ln(s))return ae(await cn(t,s,n,i));switch(s){case"-a":return ae(n!==""&&i!=="");case"-o":return ae(n!==""||i!=="");case">":return ae(n>i);case"<":return ae(n<i)}if(n==="!"){let o=await Ut(t,[s,i]);return R("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return ae(s!=="")}if(e.length===4){if(e[0]==="!"){let n=await Ut(t,e.slice(1));return R("",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 Fu(t,e,0);return r.pos<e.length?_(`test: too many arguments
595
- `,2):ae(r.value)}async function Fu(t,e,r){return rg(t,e,r)}async function rg(t,e,r){let{value:n,pos:s}=await $u(t,e,r);for(;e[s]==="-o";){let i=await $u(t,e,s+1);n=n||i.value,s=i.pos}return{value:n,pos:s}}async function $u(t,e,r){let{value:n,pos:s}=await ci(t,e,r);for(;e[s]==="-a";){let i=await ci(t,e,s+1);n=n&&i.value,s=i.pos}return{value:n,pos:s}}async function ci(t,e,r){if(e[r]==="!"){let{value:n,pos:s}=await ci(t,e,r+1);return{value:!n,pos:s}}return ng(t,e,r)}async function ng(t,e,r){let n=e[r];if(n==="("){let{value:i,pos:o}=await Fu(t,e,r+1);return{value:i,pos:e[o]===")"?o+1:o}}if(on(n)){let i=e[r+1]??"";return{value:await an(t,n,i),pos:r+2}}if(mn(n)){let i=e[r+1]??"";return{value:gn(n,i),pos:r+2}}if(n==="-v"){let i=e[r+1]??"";return{value:xn(t,i),pos:r+2}}if(n==="-o"){let i=e[r+1]??"";return{value:ui(t,i),pos:r+2}}let s=e[r+1];if(dn(s)){let i=n,o=e[r+2]??"";return{value:pn(s,i,o),pos:r+3}}if(un(s)){let i=yn(n),o=yn(e[r+2]??"0");return!i.valid||!o.valid?{value:!1,pos:r+3}:{value:fn(s,i.value,o.value),pos:r+3}}if(ln(s)){let i=n,o=e[r+2]??"";return{value:await cn(t,s,i,o),pos:r+3}}return{value:n!==void 0&&n!=="",pos:r+1}}function hn(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 ui(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 Ru(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 Ou(e);try{let r=new pe,n=le(r,e);return V(t,n.expression)}catch{return Ou(e)}}function sg(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 Ou(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=sg(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 yn(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 fi(t,e){let r=t.state.inCondition;t.state.inCondition=!0;let n="",s="",i=0;try{for(let o of e){let a=await t.executeStatement(o);n+=a.stdout,s+=a.stderr,i=a.exitCode}}finally{t.state.inCondition=r}return{stdout:n,stderr:s,exitCode:i}}J();_e();function cr(t,e,r,n){if(t instanceof he)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 We||t instanceof X||t instanceof H)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}
596
- `,exitCode:1}}J();_e();async function wn(t,e,r="",n=""){let s=r,i=n,o=0;try{for(let a of e){let l=await t.executeStatement(a);s+=l.stdout,i+=l.stderr,o=l.exitCode}}catch(a){if(Ar(a)||a instanceof We||a instanceof X||a instanceof H||a instanceof ze)throw a.prependOutput(s,i),a;return{stdout:s,stderr:`${i}${te(a)}
597
- `,exitCode:1}}return{stdout:s,stderr:i,exitCode:o}}async function Pu(t,e){let r="",n="";for(let s of e.clauses){let i=await fi(t,s.condition);if(r+=i.stdout,n+=i.stderr,i.exitCode===0)return wn(t,s.body,r,n)}return e.elseBody?wn(t,e.elseBody,r,n):R(r,n,0)}async function Tu(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
598
- `);let o=[];if(e.words===null)o=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)o=[];else for(let a of e.words){let l=await lr(t,a);o.push(...l.values)}t.state.loopDepth++;try{for(let a of o){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]=a;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=cr(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(r,n,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return R(r,n,s)}async function Du(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 o of e.body){let a=await t.executeStatement(o);r+=a.stdout,n+=a.stderr,s=a.exitCode}}catch(o){let a=cr(o,r,n,t.state.loopDepth);if(r=a.stdout,n=a.stderr,a.action==="break")break;if(a.action==="continue"){e.update&&await Z(t,e.update.expression);continue}if(a.action==="error")return R(r,n,a.exitCode??1);throw a.error}e.update&&await Z(t,e.update.expression)}}finally{t.state.loopDepth--}return R(r,n,s)}async function Lu(t,e,r=""){let n="",s="",i=0,o=0,a=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(`
599
- `).map(d=>d.replace(/^\t+/,"")).join(`
600
- `)),a=f}else if(c.operator==="<<<"&&c.target.type==="Word")a=`${await K(t,c.target)}
601
- `;else if(c.operator==="<"&&c.target.type==="Word")try{let u=await K(t,c.target),f=t.fs.resolvePath(t.state.cwd,u);a=await t.fs.readFile(f)}catch{let u=await K(t,c.target);return _(`bash: ${u}: No such file or directory
602
- `)}let l=t.state.groupStdin;a&&(t.state.groupStdin=a),t.state.loopDepth++;try{for(;;){o++,o>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 p of e.condition){let h=await t.executeStatement(p);n+=h.stdout,s+=h.stderr,c=h.exitCode}}catch(p){if(p instanceof he){if(n+=p.stdout,s+=p.stderr,p.levels>1&&t.state.loopDepth>1)throw p.levels--,p.stdout=n,p.stderr=s,t.state.inCondition=d,p;u=!0}else if(p instanceof ye){if(n+=p.stdout,s+=p.stderr,p.levels>1&&t.state.loopDepth>1)throw p.levels--,p.stdout=n,p.stderr=s,t.state.inCondition=d,p;f=!0}else throw t.state.inCondition=d,p}finally{t.state.inCondition=d}if(u)break;if(!f){if(c!==0)break;try{for(let p of e.body){let h=await t.executeStatement(p);n+=h.stdout,s+=h.stderr,i=h.exitCode}}catch(p){let h=cr(p,n,s,t.state.loopDepth);if(n=h.stdout,s=h.stderr,h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return R(n,s,h.exitCode??1);throw h.error}}}}finally{t.state.loopDepth--,t.state.groupStdin=l}return R(n,s,i)}async function Mu(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 o=await fi(t,e.condition);if(r+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of e.body){let l=await t.executeStatement(a);r+=l.stdout,n+=l.stderr,s=l.exitCode}}catch(a){let l=cr(a,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(r,n,l.exitCode??1);throw l.error}}}finally{t.state.loopDepth--}return R(r,n,s)}async function _u(t,e){let r="",n="",s=0,i=await K(t,e.word),o=!1;for(let a=0;a<e.items.length;a++){let l=e.items[a],c=o;if(!o)for(let u of l.patterns){let f=await K(t,u);if(fu(u)&&(f=du(f)),hn(i,f)){c=!0;break}}if(c){let u=await wn(t,l.body,r,n);if(r=u.stdout,n=u.stderr,s=u.exitCode,l.terminator===";;")break;l.terminator===";&"?o=!0:o=!1}else o=!1}return R(r,n,s)}J();J();function Bu(t,e){return t.state.functions.set(e.name,e),q}async function Wu(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[o,a]of i)a===void 0?delete t.state.env[o]:t.state.env[o]=a;for(let[o,a]of Object.entries(n))a===void 0?delete t.state.env[o]:t.state.env[o]=a;t.state.callDepth--};try{let i=await t.executeCommand(e.body,"");return s(),i}catch(i){if(s(),i instanceof me)return R(i.stdout,i.stderr,i.exitCode);throw i}}_e();async function Uu(t,e,r){let{stdout:n,stderr:s,exitCode:i}=e;for(let o of r){if(o.target.type==="HereDoc")continue;let a=await K(t,o.target);switch(o.operator){case">":{let l=o.fd??1;if(l===1){let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${a}: Is a directory
603
- `,i=1,n="";break}}catch{}await t.fs.writeFile(c,n),n=""}else if(l===2)if(a==="/dev/null")s="";else{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${a}: Is a directory
604
- `,i=1;break}}catch{}await t.fs.writeFile(c,s),s=""}break}case">>":{let l=o.fd??1;if(l===1){let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${a}: Is a directory
605
- `,i=1,n="";break}}catch{}await t.fs.appendFile(c,n),n=""}else if(l===2){let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s+=`bash: ${a}: Is a directory
606
- `,i=1;break}}catch{}await t.fs.appendFile(c,s),s=""}break}case">&":{let l=o.fd??1;a==="2"||a==="&2"?l===1&&(s+=n,n=""):(a==="1"||a==="&1")&&(n+=s,s="");break}case"&>":{let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s=`bash: ${a}: Is a directory
607
- `,i=1,n="";break}}catch{}await t.fs.writeFile(l,n+s),n="",s="";break}case"&>>":{let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s=`bash: ${a}: Is a directory
608
- `,i=1,n="";break}}catch{}await t.fs.appendFile(l,n+s),n="",s="";break}}}return R(n,s,i)}var ur=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 o=await this.executeStatement(i);r+=o.stdout,n+=o.stderr,s=o.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}catch(o){if(o instanceof X)throw o.prependOutput(r,n),o;if(o instanceof H)throw o;if(o instanceof We)return r+=o.stdout,n+=o.stderr,s=o.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}};if(o instanceof Re)return r+=o.stdout,n+=o.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(o instanceof qe)return r+=o.stdout,n+=o.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(o instanceof he||o instanceof ye){if(this.ctx.state.loopDepth>0)throw o.prependOutput(r,n),o;r+=o.stdout,n+=o.stderr;continue}throw o instanceof me&&o.prependOutput(r,n),o}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,o=!1;for(let a=0;a<e.pipelines.length;a++){let l=e.pipelines[a],c=a>0?e.operators[a-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=a,o=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&&!o&&!this.ctx.state.inCondition)throw new We(s,r,n);return R(r,n,s)}async executePipeline(e){let r="",n=q,s=0,i=[];for(let o=0;o<e.commands.length;o++){let a=e.commands[o],l=o===e.commands.length-1,c;try{c=await this.executeCommand(a,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 o of Object.keys(this.ctx.state.env))o.startsWith("PIPESTATUS_")&&delete this.ctx.state.env[o];for(let o=0;o<i.length;o++)this.ctx.state.env[`PIPESTATUS_${o}`]=String(i[o]);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 Pu(this.ctx,e);case"For":return Tu(this.ctx,e);case"CStyleFor":return Du(this.ctx,e);case"While":return Lu(this.ctx,e,r);case"Until":return Mu(this.ctx,e);case"Case":return _u(this.ctx,e);case"Subshell":return this.executeSubshell(e,r);case"Group":return this.executeGroup(e,r);case"FunctionDef":return Bu(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 oe)return _(n.stderr);throw n}}async executeSimpleCommandInner(e,r){e.line!==void 0&&(this.ctx.state.currentLine=e.line),this.ctx.state.expansionStderr="";let n={};for(let l of e.assignments){let c=l.name;if(l.array){if(/\[.+\]$/.test(c))return R("",`bash: ${c}: cannot assign list to array member
609
- `,1);let w=it(this.ctx,c);if(w)return w;let g=[];for(let E of l.array){let b=await lr(this.ctx,E);g.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<g.length;E++)this.ctx.state.env[`${c}_${y+E}`]=g[E];l.append||(this.ctx.state.env[`${c}__length`]=String(g.length));continue}let u=l.value?await K(this.ctx,l.value):"";if(c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return R("",`bash: ${c}: bad array subscript
610
- `,1);let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let w=d[1],g=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(g.startsWith("'")&&g.endsWith("'"))A=g.slice(1,-1);else if(g.startsWith('"')&&g.endsWith('"')){let D=g.slice(1,-1),F=new pe().parseWordFromString(D,!0,!1);A=await K(this.ctx,F)}else if(g.includes("$")){let P=new pe().parseWordFromString(g,!1,!1);A=await K(this.ctx,P)}else A=g;b=`${w}_${A}`}else{let A;if(/^-?\d+$/.test(g))A=Number.parseInt(g,10);else{try{let D=new pe,P=le(D,g);A=V(this.ctx,P.expression)}catch{let D=this.ctx.state.env[g];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 R("",`bash: ${w}[${g}]: bad array subscript
611
- `,1);if(A=Math.max(...D.map(([F])=>typeof F=="number"?F:0))+1+A,A<0)return R("",`bash: ${w}[${g}]: bad array subscript
612
- `,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 p=it(this.ctx,c);if(p)return p;let h=l.append?(this.ctx.state.env[c]||"")+u:u;e.name?(n[c]=this.ctx.state.env[c],this.ctx.state.env[c]=h):this.ctx.state.env[c]=h}if(!e.name)return R("","",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(`
588
+ `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let s=n[0]==="-";for(let i=1;i<n.length;i++){let o=n[i];if(!(o in Bu))return B(`bash: set: ${n[0]}${o}: invalid option
589
+ ${ln}`);ju(t,Bu[o],s)}r++;continue}if(n==="--")return fi(t,e.slice(r+1)),V;if(n==="-"){if(t.state.options.xtrace=!1,t.state.options.verbose=!1,r+1<e.length)return fi(t,e.slice(r+1)),V;r++;continue}if(n==="+"){r++;continue}return n.startsWith("-")||n.startsWith("+")?B(`bash: set: ${n}: invalid option
590
+ ${ln}`):(fi(t,e.slice(r)),V)}return V}function fi(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 di(t,e){let r=1;if(e.length>0){let o=Number.parseInt(e[0],10);if(Number.isNaN(o)||o<0)return B(`bash: shift: ${e[0]}: numeric argument required
591
+ `);r=o}let n=Number.parseInt(t.state.env["#"]||"0",10);if(r>n)return B(`bash: shift: shift count out of range
592
+ `);if(r===0)return V;let s=[];for(let o=1;o<=n;o++)s.push(t.state.env[String(o)]||"");let i=s.slice(r);for(let o=1;o<=n;o++)delete t.state.env[String(o)];for(let o=0;o<i.length;o++)t.state.env[String(o+1)]=i[o];return t.state.env["#"]=String(i.length),t.state.env["@"]=i.join(" "),V}J();async function hi(t,e){let r=e;if(r.length>0&&r[0]==="--"&&(r=r.slice(1)),r.length===0)return P("",`bash: source: filename argument required
593
+ `,2);let n=r[0],s=null,i=null;if(n.includes("/")){let c=t.fs.resolvePath(t.state.cwd,n);try{i=await t.fs.readFile(c),s=c}catch{}}else{let l=(t.state.env.PATH||"").split(":").filter(u=>u);for(let u of l){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 B(`bash: ${n}: No such file or directory
594
+ `);let o={};if(r.length>1){for(let l=1;l<=9;l++)o[String(l)]=t.state.env[String(l)];o["#"]=t.state.env["#"],o["@"]=t.state.env["@"];let c=r.slice(1);t.state.env["#"]=String(c.length),t.state.env["@"]=c.join(" ");for(let l=0;l<c.length&&l<9;l++)t.state.env[String(l+1)]=c[l];for(let l=c.length+1;l<=9;l++)delete t.state.env[String(l)]}let a=()=>{if(t.state.sourceDepth--,r.length>1)for(let[c,l]of Object.entries(o))l===void 0?delete t.state.env[c]:t.state.env[c]=l};t.state.sourceDepth++;try{let c=st(i),l=await t.executeScript(c);return a(),l}catch(c){if(a(),c instanceof X)throw c;if(c instanceof ye)return P(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return B(`bash: ${n}: ${c.message}
595
+ `);throw c}}function mi(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 o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let a=o[1],c=o[2];if(c==="@"||c==="*"){let u=ue(t,a);for(let[f]of u)delete t.state.env[`${a}_${f}`];delete t.state.env[a];continue}let l;if(/^-?\d+$/.test(c))l=Number.parseInt(c,10);else{let u=t.state.env[c];l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=ue(t,a),f=u.length;if(f===0){n+=`bash: unset: [${l}]: bad array subscript
596
+ `,s=1;continue}let p=f+l;if(p<0){n+=`bash: unset: [${l}]: bad array subscript
597
+ `,s=1;continue}let d=u[p][0];delete t.state.env[`${a}_${d}`];continue}delete t.state.env[`${a}_${l}`];continue}delete t.state.env[i],t.state.functions.delete(i)}return P("",n,s)}function yi(t,e){return t.fs.resolvePath(t.state.cwd,e)}var Ey=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function un(t){return Ey.includes(t)}async function fn(t,e,r){let n=yi(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 by=["-nt","-ot","-ef"];function pn(t){return by.includes(t)}async function dn(t,e,r,n){let s=yi(t,r),i=yi(t,n);switch(e){case"-nt":try{let o=await t.fs.stat(s),a=await t.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await t.fs.stat(s),a=await t.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await t.fs.exists(s)||!await t.fs.exists(i))return!1;let o=t.fs.resolvePath(t.state.cwd,s),a=t.fs.resolvePath(t.state.cwd,i);return o===a}catch{return!1}default:return!1}}var Sy=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function hn(t){return Sy.has(t)}function mn(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 yn(t){return t==="="||t==="=="||t==="!="}function gn(t,e,r,n=!1){let s=n?xn(e,r):e===r;return t==="!="?!s:s}var Ay=new Set(["-z","-n"]);function wn(t){return Ay.has(t)}function En(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function bn(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,(o,a)=>t.state.env[a]||"");let i;if(/^-?\d+$/.test(s))i=Number.parseInt(s,10);else try{let o=Function(`"use strict"; return (${s})`)();i=typeof o=="number"?Math.floor(o):0}catch{let o=t.state.env[s];i=o?Number.parseInt(o,10):0}if(i<0){let o=ar(t,n);if(o.length===0||(i=Math.max(...o)+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 Y(t,e.left),n=await Y(t,e.right),s=e.right.parts.length>0&&e.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped");if(yn(e.operator))return gn(e.operator,r,n,!s);if(hn(e.operator))return mn(e.operator,Gu(t,r),Gu(t,n));if(pn(e.operator))return dn(t,e.operator,r,n);switch(e.operator){case"=~":try{let i=new RegExp(n),o=r.match(i);if(o){t.state.env.BASH_REMATCH=o[0];for(let a=1;a<o.length;a++)t.state.env[`BASH_REMATCH_${a}`]=o[a]||""}return o!==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 Y(t,e.operand);return un(e.operator)?fn(t,e.operator,r):wn(e.operator)?En(e.operator,r):e.operator==="-v"?bn(t,r):e.operator==="-o"?xi(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 Y(t,e.word)!=="";default:return!1}}async function Gt(t,e){if(e.length===0)return P("","",1);if(e.length===1)return ce(!!e[0]);if(e.length===2){let n=e[0],s=e[1];return n==="("?B(`test: '(' without matching ')'
598
+ `,2):un(n)?ce(await fn(t,n,s)):wn(n)?ce(En(n,s)):n==="!"?ce(!s):n==="-v"?ce(bn(t,s)):n==="-o"?ce(xi(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"?B(`test: ${n}: unary operator expected
599
+ `,2):P("","",1)}if(e.length===3){let n=e[0],s=e[1],i=e[2];if(yn(s))return ce(gn(s,n,i));if(hn(s)){let o=Sn(n),a=Sn(i);return!o.valid||!a.valid?P("","",2):ce(mn(s,o.value,a.value))}if(pn(s))return ce(await dn(t,s,n,i));switch(s){case"-a":return ce(n!==""&&i!=="");case"-o":return ce(n!==""||i!=="");case">":return ce(n>i);case"<":return ce(n<i)}if(n==="!"){let o=await Gt(t,[s,i]);return P("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return ce(s!=="")}if(e.length===4){if(e[0]==="!"){let n=await Gt(t,e.slice(1));return P("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(e[0]==="("&&e[3]===")")return Gt(t,[e[1],e[2]])}let r=await Vu(t,e,0);return r.pos<e.length?B(`test: too many arguments
600
+ `,2):ce(r.value)}async function Vu(t,e,r){return Cy(t,e,r)}async function Cy(t,e,r){let{value:n,pos:s}=await zu(t,e,r);for(;e[s]==="-o";){let i=await zu(t,e,s+1);n=n||i.value,s=i.pos}return{value:n,pos:s}}async function zu(t,e,r){let{value:n,pos:s}=await gi(t,e,r);for(;e[s]==="-a";){let i=await gi(t,e,s+1);n=n&&i.value,s=i.pos}return{value:n,pos:s}}async function gi(t,e,r){if(e[r]==="!"){let{value:n,pos:s}=await gi(t,e,r+1);return{value:!n,pos:s}}return ky(t,e,r)}async function ky(t,e,r){let n=e[r];if(n==="("){let{value:i,pos:o}=await Vu(t,e,r+1);return{value:i,pos:e[o]===")"?o+1:o}}if(un(n)){let i=e[r+1]??"";return{value:await fn(t,n,i),pos:r+2}}if(wn(n)){let i=e[r+1]??"";return{value:En(n,i),pos:r+2}}if(n==="-v"){let i=e[r+1]??"";return{value:bn(t,i),pos:r+2}}if(n==="-o"){let i=e[r+1]??"";return{value:xi(t,i),pos:r+2}}let s=e[r+1];if(yn(s)){let i=n,o=e[r+2]??"";return{value:gn(s,i,o),pos:r+3}}if(hn(s)){let i=Sn(n),o=Sn(e[r+2]??"0");return!i.valid||!o.valid?{value:!1,pos:r+3}:{value:mn(s,i.value,o.value),pos:r+3}}if(pn(s)){let i=n,o=e[r+2]??"";return{value:await dn(t,s,i,o),pos:r+3}}return{value:n!==void 0&&n!=="",pos:r+1}}function xn(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 xi(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 Gu(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 qu(e);try{let r=new he,n=le(r,e);return K(t,n.expression)}catch{return qu(e)}}function Ny(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 qu(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=Ny(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 Sn(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 wi(t,e){let r=t.state.inCondition;t.state.inCondition=!0;let n="",s="",i=0;try{for(let o of e){let a=await t.executeStatement(o);n+=a.stdout,s+=a.stderr,i=a.exitCode}}finally{t.state.inCondition=r}return{stdout:n,stderr:s,exitCode:i}}J();We();function fr(t,e,r,n){if(t instanceof me)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 Ee)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 ye||t instanceof He||t instanceof X||t instanceof W)return t.prependOutput(e,r),{action:"rethrow",stdout:e,stderr:r,error:t};let s=re(t);return{action:"error",stdout:e,stderr:`${r}${s}
601
+ `,exitCode:1}}J();We();async function An(t,e,r="",n=""){let s=r,i=n,o=0;try{for(let a of e){let c=await t.executeStatement(a);s+=c.stdout,i+=c.stderr,o=c.exitCode}}catch(a){if(Nr(a)||a instanceof He||a instanceof X||a instanceof W||a instanceof Ge)throw a.prependOutput(s,i),a;return{stdout:s,stderr:`${i}${re(a)}
602
+ `,exitCode:1}}return{stdout:s,stderr:i,exitCode:o}}async function Ku(t,e){let r="",n="";for(let s of e.clauses){let i=await wi(t,s.condition);if(r+=i.stdout,n+=i.stderr,i.exitCode===0)return An(t,s.body,r,n)}return e.elseBody?An(t,e.elseBody,r,n):P(r,n,0)}async function Zu(t,e){let r="",n="",s=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.variable))return B(`bash: \`${e.variable}': not a valid identifier
603
+ `);let o=[];if(e.words===null)o=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)o=[];else for(let a of e.words){let c=await ur(t,a);o.push(...c.values)}t.state.loopDepth++;try{for(let a of o){i++,i>t.limits.maxLoopIterations&&Ye(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),t.state.env[e.variable]=a;try{for(let c of e.body){let l=await t.executeStatement(c);r+=l.stdout,n+=l.stderr,s=l.exitCode}}catch(c){let l=fr(c,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 P(r,n,l.exitCode??1);throw l.error}}}finally{t.state.loopDepth--}return P(r,n,s)}async function Qu(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&&Ye(`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 o of e.body){let a=await t.executeStatement(o);r+=a.stdout,n+=a.stderr,s=a.exitCode}}catch(o){let a=fr(o,r,n,t.state.loopDepth);if(r=a.stdout,n=a.stderr,a.action==="break")break;if(a.action==="continue"){e.update&&await Z(t,e.update.expression);continue}if(a.action==="error")return P(r,n,a.exitCode??1);throw a.error}e.update&&await Z(t,e.update.expression)}}finally{t.state.loopDepth--}return P(r,n,s)}async function Xu(t,e,r=""){let n="",s="",i=0,o=0,a=r;for(let l of e.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let u=l.target,f=await Y(t,u.content);u.stripTabs&&(f=f.split(`
604
+ `).map(p=>p.replace(/^\t+/,"")).join(`
605
+ `)),a=f}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await Y(t,l.target)}
606
+ `;else if(l.operator==="<"&&l.target.type==="Word")try{let u=await Y(t,l.target),f=t.fs.resolvePath(t.state.cwd,u);a=await t.fs.readFile(f)}catch{let u=await Y(t,l.target);return B(`bash: ${u}: No such file or directory
607
+ `)}let c=t.state.groupStdin;a&&(t.state.groupStdin=a),t.state.loopDepth++;try{for(;;){o++,o>t.limits.maxLoopIterations&&Ye(`while loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,s);let l=0,u=!1,f=!1,p=t.state.inCondition;t.state.inCondition=!0;try{for(let d of e.condition){let h=await t.executeStatement(d);n+=h.stdout,s+=h.stderr,l=h.exitCode}}catch(d){if(d instanceof me){if(n+=d.stdout,s+=d.stderr,d.levels>1&&t.state.loopDepth>1)throw d.levels--,d.stdout=n,d.stderr=s,t.state.inCondition=p,d;u=!0}else if(d instanceof Ee){if(n+=d.stdout,s+=d.stderr,d.levels>1&&t.state.loopDepth>1)throw d.levels--,d.stdout=n,d.stderr=s,t.state.inCondition=p,d;f=!0}else throw t.state.inCondition=p,d}finally{t.state.inCondition=p}if(u)break;if(!f){if(l!==0)break;try{for(let d of e.body){let h=await t.executeStatement(d);n+=h.stdout,s+=h.stderr,i=h.exitCode}}catch(d){let h=fr(d,n,s,t.state.loopDepth);if(n=h.stdout,s=h.stderr,h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return P(n,s,h.exitCode??1);throw h.error}}}}finally{t.state.loopDepth--,t.state.groupStdin=c}return P(n,s,i)}async function Ju(t,e){let r="",n="",s=0,i=0;t.state.loopDepth++;try{for(;;){i++,i>t.limits.maxLoopIterations&&Ye(`until loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let o=await wi(t,e.condition);if(r+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of e.body){let c=await t.executeStatement(a);r+=c.stdout,n+=c.stderr,s=c.exitCode}}catch(a){let c=fr(a,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 P(r,n,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return P(r,n,s)}async function Yu(t,e){let r="",n="",s=0,i=await Y(t,e.word),o=!1;for(let a=0;a<e.items.length;a++){let c=e.items[a],l=o;if(!o)for(let u of c.patterns){let f=await Y(t,u);if(Nu(u)&&(f=Iu(f)),xn(i,f)){l=!0;break}}if(l){let u=await An(t,c.body,r,n);if(r=u.stdout,n=u.stderr,s=u.exitCode,c.terminator===";;")break;c.terminator===";&"?o=!0:o=!1}else o=!1}return P(r,n,s)}J();J();function ef(t,e){return t.state.functions.set(e.name,e),V}async function tf(t,e,r){t.state.callDepth++,t.state.callDepth>t.limits.maxCallDepth&&(t.state.callDepth--,Ye(`${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[o,a]of i)a===void 0?delete t.state.env[o]:t.state.env[o]=a;for(let[o,a]of Object.entries(n))a===void 0?delete t.state.env[o]:t.state.env[o]=a;t.state.callDepth--};try{let i=await t.executeCommand(e.body,"");return s(),i}catch(i){if(s(),i instanceof ye)return P(i.stdout,i.stderr,i.exitCode);throw i}}We();async function rf(t,e,r){let{stdout:n,stderr:s,exitCode:i}=e;for(let o of r){if(o.target.type==="HereDoc")continue;let a=await Y(t,o.target);switch(o.operator){case">":{let c=o.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
608
+ `,i=1,n="";break}}catch{}await t.fs.writeFile(l,n),n=""}else if(c===2)if(a==="/dev/null")s="";else{let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
609
+ `,i=1;break}}catch{}await t.fs.writeFile(l,s),s=""}break}case">>":{let c=o.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
610
+ `,i=1,n="";break}}catch{}await t.fs.appendFile(l,n),n=""}else if(c===2){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
611
+ `,i=1;break}}catch{}await t.fs.appendFile(l,s),s=""}break}case">&":{let c=o.fd??1;a==="2"||a==="&2"?c===1&&(s+=n,n=""):(a==="1"||a==="&1")&&(n+=s,s="");break}case"&>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s=`bash: ${a}: Is a directory
612
+ `,i=1,n="";break}}catch{}await t.fs.writeFile(c,n+s),n="",s="";break}case"&>>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s=`bash: ${a}: Is a directory
613
+ `,i=1,n="";break}}catch{}await t.fs.appendFile(c,n+s),n="",s="";break}}}return P(n,s,i)}var pr=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 o=await this.executeStatement(i);r+=o.stdout,n+=o.stderr,s=o.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}catch(o){if(o instanceof X)throw o.prependOutput(r,n),o;if(o instanceof W)throw o;if(o instanceof He)return r+=o.stdout,n+=o.stderr,s=o.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:r,stderr:n,exitCode:s,env:{...this.ctx.state.env}};if(o instanceof Pe)return r+=o.stdout,n+=o.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(o instanceof Ke)return r+=o.stdout,n+=o.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(o instanceof me||o instanceof Ee){if(this.ctx.state.loopDepth>0)throw o.prependOutput(r,n),o;r+=o.stdout,n+=o.stderr;continue}throw o instanceof ye&&o.prependOutput(r,n),o}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&&Ye(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands");let r="",n="",s=0,i=-1,o=!1;for(let a=0;a<e.pipelines.length;a++){let c=e.pipelines[a],l=a>0?e.operators[a-1]:null;if(l==="&&"&&s!==0||l==="||"&&s===0)continue;let u=await this.executePipeline(c);r+=u.stdout,n+=u.stderr,s=u.exitCode,i=a,o=c.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&&!o&&!this.ctx.state.inCondition)throw new He(s,r,n);return P(r,n,s)}async executePipeline(e){let r="",n=V,s=0,i=[];for(let o=0;o<e.commands.length;o++){let a=e.commands[o],c=o===e.commands.length-1,l;try{l=await this.executeCommand(a,r)}catch(u){if(u instanceof Ke)l={stdout:u.stdout,stderr:u.stderr,exitCode:1};else if(u instanceof X&&e.commands.length>1)l={stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode};else throw u}i.push(l.exitCode),l.exitCode!==0&&(s=l.exitCode),c?n=l:(r=l.stdout,n={stdout:"",stderr:l.stderr,exitCode:l.exitCode})}for(let o of Object.keys(this.ctx.state.env))o.startsWith("PIPESTATUS_")&&delete this.ctx.state.env[o];for(let o=0;o<i.length;o++)this.ctx.state.env[`PIPESTATUS_${o}`]=String(i[o]);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 Ku(this.ctx,e);case"For":return Zu(this.ctx,e);case"CStyleFor":return Qu(this.ctx,e);case"While":return Xu(this.ctx,e,r);case"Until":return Ju(this.ctx,e);case"Case":return Yu(this.ctx,e);case"Subshell":return this.executeSubshell(e,r);case"Group":return this.executeGroup(e,r);case"FunctionDef":return ef(this.ctx,e);case"ArithmeticCommand":return this.executeArithmeticCommand(e);case"ConditionalCommand":return this.executeConditionalCommand(e);default:return V}}async executeSimpleCommand(e,r){try{return await this.executeSimpleCommandInner(e,r)}catch(n){if(n instanceof ae)return B(n.stderr);throw n}}async executeSimpleCommandInner(e,r){e.line!==void 0&&(this.ctx.state.currentLine=e.line),this.ctx.state.expansionStderr="";let n={};for(let c of e.assignments){let l=c.name;if(c.array){if(/\[.+\]$/.test(l))return P("",`bash: ${l}: cannot assign list to array member
614
+ `,1);let g=ot(this.ctx,l);if(g)return g;let y=[];for(let E of c.array){let b=await ur(this.ctx,E);y.push(...b.values)}let w=0;if(c.append){let E=ue(this.ctx,l);E.length>0&&(w=Math.max(...E.map(([S])=>typeof S=="number"?S:0))+1)}else{let E=`${l}_`;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<y.length;E++)this.ctx.state.env[`${l}_${w+E}`]=y[E];c.append||(this.ctx.state.env[`${l}__length`]=String(y.length));continue}let u=c.value?await Y(this.ctx,c.value):"";if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return P("",`bash: ${l}: bad array subscript
615
+ `,1);let p=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let g=p[1],y=p[2],w=ot(this.ctx,g);if(w)return w;let E=this.ctx.state.associativeArrays?.has(g),b;if(E){let C;if(y.startsWith("'")&&y.endsWith("'"))C=y.slice(1,-1);else if(y.startsWith('"')&&y.endsWith('"')){let O=y.slice(1,-1),F=new he().parseWordFromString(O,!0,!1);C=await Y(this.ctx,F)}else if(y.includes("$")){let D=new he().parseWordFromString(y,!1,!1);C=await Y(this.ctx,D)}else C=y;b=`${g}_${C}`}else{let C;if(/^-?\d+$/.test(y))C=Number.parseInt(y,10);else{try{let O=new he,D=le(O,y);C=K(this.ctx,D.expression)}catch{let O=this.ctx.state.env[y];C=O?Number.parseInt(O,10):0}Number.isNaN(C)&&(C=0)}if(C<0){let O=ue(this.ctx,g);if(O.length===0)return P("",`bash: ${g}[${y}]: bad array subscript
616
+ `,1);if(C=Math.max(...O.map(([F])=>typeof F=="number"?F:0))+1+C,C<0)return P("",`bash: ${g}[${y}]: bad array subscript
617
+ `,1)}b=`${g}_${C}`}let S=c.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 d=ot(this.ctx,l);if(d)return d;let h=c.append?(this.ctx.state.env[l]||"")+u:u;e.name?(n[l]=this.ctx.state.env[l],this.ctx.state.env[l]=h):this.ctx.state.env[l]=h}if(!e.name)return P("","",this.ctx.state.lastExitCode);for(let c of e.redirections){if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let l=c.target,u=await Y(this.ctx,l.content);l.stripTabs&&(u=u.split(`
613
618
  `).map(f=>f.replace(/^\t+/,"")).join(`
614
- `)),r=u;continue}if(l.operator==="<<<"&&l.target.type==="Word"){r=`${await K(this.ctx,l.target)}
615
- `;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
616
- `)}}let s=await K(this.ctx,e.name),i=[],o=[];for(let l of e.args){let c=await lr(this.ctx,l);for(let u of c.values)i.push(u),o.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 o.shift(),await this.runCommand(c,i,o,r)}return R("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found
617
- `,127)}let a=await this.runCommand(s,i,o,r);a=await Uu(this.ctx,a,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&&(a={...a,stderr:this.ctx.state.expansionStderr+a.stderr},this.ctx.state.expansionStderr=""),a}async runCommand(e,r,n,s,i=!1){if(e==="cd")return await js(this.ctx,r);if(e==="export")return Ks(this.ctx,r);if(e==="unset")return ai(this.ctx,r);if(e==="exit")return Xs(this.ctx,r);if(e==="local")return Ys(this.ctx,r);if(e==="set")return si(this.ctx,r);if(e==="break")return zs(this.ctx,r);if(e==="continue")return Gs(this.ctx,r);if(e==="return")return ri(this.ctx,r);if(e==="eval")return Qs(this.ctx,r);if(e==="shift")return ii(this.ctx,r);if(e==="source"||e===".")return oi(this.ctx,r);if(e==="read")return ti(this.ctx,r,s);if(e==="mapfile"||e==="readarray")return ei(this.ctx,r,s);if(e==="declare"||e==="typeset")return Vs(this.ctx,r);if(e==="readonly")return Zs(this.ctx,r);if(!i){let u=this.ctx.state.functions.get(e);if(u)return Wu(this.ctx,u,r)}if(e===":"||e==="true")return q;if(e==="false")return ae(!1);if(e==="let")return Js(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 o=await this.resolveCommand(e);if(!o)return _(`bash: ${e}: command not found
618
- `,127);let{cmd:a,path:l}=o,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 a.execute(r,c)}catch(u){return _(`${e}: ${te(u)}
619
+ `)),r=u;continue}if(c.operator==="<<<"&&c.target.type==="Word"){r=`${await Y(this.ctx,c.target)}
620
+ `;continue}if(c.operator==="<"&&c.target.type==="Word")try{let l=await Y(this.ctx,c.target),u=this.ctx.fs.resolvePath(this.ctx.state.cwd,l);r=await this.ctx.fs.readFile(u)}catch{let l=await Y(this.ctx,c.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 B(`bash: ${l}: No such file or directory
621
+ `)}}let s=await Y(this.ctx,e.name),i=[],o=[];for(let c of e.args){let l=await ur(this.ctx,c);for(let u of l.values)i.push(u),o.push(l.quoted)}if(!s){if(e.name.parts.every(l=>l.type==="CommandSubstitution"||l.type==="ParameterExpansion"||l.type==="ArithmeticExpansion")){if(i.length>0){let l=i.shift();return o.shift(),await this.runCommand(l,i,o,r)}return P("","",this.ctx.state.lastExitCode)}return B(`bash: : command not found
622
+ `,127)}let a=await this.runCommand(s,i,o,r);a=await rf(this.ctx,a,e.redirections),this.ctx.state.lastArg=i.length>0?i[i.length-1]:s;for(let[c,l]of Object.entries(n))l===void 0?delete this.ctx.state.env[c]:this.ctx.state.env[c]=l;return this.ctx.state.expansionStderr&&(a={...a,stderr:this.ctx.state.expansionStderr+a.stderr},this.ctx.state.expansionStderr=""),a}async runCommand(e,r,n,s,i=!1){if(e==="cd")return await Js(this.ctx,r);if(e==="export")return ii(this.ctx,r);if(e==="unset")return mi(this.ctx,r);if(e==="exit")return si(this.ctx,r);if(e==="local")return ai(this.ctx,r);if(e==="set")return pi(this.ctx,r);if(e==="break")return Xs(this.ctx,r);if(e==="continue")return Ys(this.ctx,r);if(e==="return")return ui(this.ctx,r);if(e==="eval")return ni(this.ctx,r);if(e==="shift")return di(this.ctx,r);if(e==="source"||e===".")return hi(this.ctx,r);if(e==="read")return li(this.ctx,r,s);if(e==="mapfile"||e==="readarray")return ci(this.ctx,r,s);if(e==="declare"||e==="typeset")return ti(this.ctx,r);if(e==="readonly")return ri(this.ctx,r);if(!i){let u=this.ctx.state.functions.get(e);if(u)return tf(this.ctx,u,r)}if(e===":"||e==="true")return V;if(e==="false")return ce(!1);if(e==="let")return oi(this.ctx,r);if(e==="command"){if(r.length===0)return V;let u=r;for(;u.length>0&&u[0].startsWith("-");)u=u.slice(1);if(u.length===0)return V;let[f,...p]=u;return this.runCommand(f,p,[],s,!0)}if(e==="builtin"){if(r.length===0)return V;let[u,...f]=r;return this.runCommand(u,f,[],s)}if(e==="shopt")return V;if(e==="exec"){if(r.length===0)return V;let[u,...f]=r;return this.runCommand(u,f,[],s)}if(e==="wait")return V;if(e==="type")return this.handleType(r);if(e==="[["){let u=r.lastIndexOf("]]");if(u!==-1){let f=r.slice(0,u);return Gt(this.ctx,f)}return B("bash: [[: missing `]]'\n",2)}if(e==="["||e==="test"){let u=r;if(e==="["){if(r[r.length-1]!=="]")return B("[: missing `]'\n",2);u=r.slice(0,-1)}return Gt(this.ctx,u)}let o=await this.resolveCommand(e);if(!o)return B(`bash: ${e}: command not found
623
+ `,127);let{cmd:a,path:c}=o,l={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 a.execute(r,l)}catch(u){return B(`${e}: ${re(u)}
619
624
  `)}}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 o=i.split("/").pop()||e,a=this.ctx.commands.get(o);return a?{cmd:a,path:i}:null}let n=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let i of n){if(!i)continue;let o=`${i}/${e}`;if(await this.ctx.fs.exists(o)){let a=this.ctx.commands.get(e);if(a)return{cmd:a,path:o}}}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 o=`${i}/${e}`;await this.ctx.fs.exists(o)&&r.push(o)}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="",o=0;for(let a of e)r.has(a)?s+=`${a} is a shell keyword
620
625
  `:n.has(a)?s+=`${a} is a shell builtin
621
626
  `:this.ctx.state.functions.has(a)?s+=`${a} is a function
622
627
  `:this.ctx.commands.has(a)?s+=`${a} is /bin/${a}
623
628
  `:(i+=`bash: type: ${a}: not found
624
- `,o=1);return R(s,i,o)}async executeSubshell(e,r=""){let n={...this.ctx.state.env},s=this.ctx.state.cwd,i=this.ctx.state.loopDepth,o=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=i>0,this.ctx.state.loopDepth=0;let a=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=o,this.ctx.state.groupStdin=a,f instanceof H)throw f;if(f instanceof ze)return l+=f.stdout,c+=f.stderr,R(l,c,0);if(f instanceof he||f instanceof ye)return l+=f.stdout,c+=f.stderr,R(l,c,0);if(f instanceof X)return l+=f.stdout,c+=f.stderr,R(l,c,f.exitCode);if(f instanceof me)return l+=f.stdout,c+=f.stderr,R(l,c,f.exitCode);if(f instanceof We)throw f.stdout=l+f.stdout,f.stderr=c+f.stderr,f;return R(l,`${c}${te(f)}
625
- `,1)}return this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,R(l,c,u)}async executeGroup(e,r=""){let n="",s="",i=0,o=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);try{for(let a of e.body){let l=await this.executeStatement(a);n+=l.stdout,s+=l.stderr,i=l.exitCode}}catch(a){if(this.ctx.state.groupStdin=o,a instanceof H)throw a;if(Ar(a)||a instanceof We||a instanceof X)throw a.prependOutput(n,s),a;return R(n,`${s}${te(a)}
626
- `,1)}return this.ctx.state.groupStdin=o,R(n,s,i)}async executeArithmeticCommand(e){try{let r=await Z(this.ctx,e.expression.expression);return ae(r!==0)}catch(r){return _(`bash: arithmetic expression: ${r.message}
627
- `)}}async executeConditionalCommand(e){try{let r=await ot(this.ctx,e.expression);return ae(r)}catch(r){return _(`bash: conditional expression: ${r.message}
628
- `,2)}}};var Ht={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4};function Hu(t){return t?{maxCallDepth:t.maxCallDepth??Ht.maxCallDepth,maxCommandCount:t.maxCommandCount??Ht.maxCommandCount,maxLoopIterations:t.maxLoopIterations??Ht.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??Ht.maxAwkIterations,maxSedIterations:t.maxSedIterations??Ht.maxSedIterations}:{...Ht}}function zu(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function ig(t){let e=zu(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function og(t,e){let r=zu(t);if(!r)return!1;let n=ig(e);return!n||r.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:r.pathname.startsWith(n.pathPrefix)}function di(t,e){return!e||e.length===0?!1:e.some(r=>og(t,r))}var fr=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},dr=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},pr=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},En=class extends Error{constructor(e,r){super(`HTTP method '${e}' not allowed. Allowed methods: ${r.join(", ")}`),this.name="MethodNotAllowedError"}};var ag=20,lg=3e4,cg=["GET","HEAD"],ug=new Set(["GET","HEAD","OPTIONS"]),fg=new Set([301,302,303,307,308]);function pi(t){let e=t.maxRedirects??ag,r=t.timeoutMs??lg,n=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??cg;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!di(a,t.allowedUrlPrefixes??[]))throw new fr(a)}function i(a){if(t.dangerouslyAllowFullInternetAccess)return;let l=a.toUpperCase();if(!n.includes(l))throw new En(l,n)}async function o(a,l={}){let c=l.method?.toUpperCase()??"GET";s(a),i(c);let u=a,f=0,d=l.followRedirects??!0,p=l.timeoutMs!==void 0?Math.min(l.timeoutMs,r):r;for(;;){let h=new AbortController,w=setTimeout(()=>h.abort(),p);try{let g={method:c,headers:l.headers,signal:h.signal,redirect:"manual"};l.body&&!ug.has(c)&&(g.body=l.body);let y=await fetch(u,g);if(fg.has(y.status)&&d){let E=y.headers.get("location");if(!E)return await ju(y,u);let b=new URL(E,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!di(b,t.allowedUrlPrefixes??[]))throw new pr(b);if(f++,f>e)throw new dr(e);u=b;continue}return await ju(y,u)}finally{clearTimeout(w)}}}return o}async function ju(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 bn=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;logger;state;constructor(e={}){let r=e.fs??new rr(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:`
629
- `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:n,OLDPWD:n,...e.env};if(this.limits=Hu({...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=pi(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:"",startTime:Date.now(),lastBackgroundPid:0,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},Rc(r,this.useDefaultLayout),n!=="/"&&r instanceof rr)try{r.mkdirSync(n,{recursive:!0})}catch{}for(let i of Sc(e.commands))this.registerCommand(i);if(e.network)for(let i of Cc())this.registerCommand(i);if(e.customCommands)for(let i of e.customCommands)Ac(i)?this.registerCommand(kc(i)):this.registerCommand(i)}registerCommand(e){this.commands.set(e.name,e);let r=this.fs;if(typeof r.writeFileSync=="function")try{r.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
629
+ `,o=1);return P(s,i,o)}async executeSubshell(e,r=""){let n={...this.ctx.state.env},s=this.ctx.state.cwd,i=this.ctx.state.loopDepth,o=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=i>0,this.ctx.state.loopDepth=0;let a=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);let c="",l="",u=0;try{for(let f of e.body){let p=await this.executeStatement(f);c+=p.stdout,l+=p.stderr,u=p.exitCode}}catch(f){if(this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,f instanceof W)throw f;if(f instanceof Ge)return c+=f.stdout,l+=f.stderr,P(c,l,0);if(f instanceof me||f instanceof Ee)return c+=f.stdout,l+=f.stderr,P(c,l,0);if(f instanceof X)return c+=f.stdout,l+=f.stderr,P(c,l,f.exitCode);if(f instanceof ye)return c+=f.stdout,l+=f.stderr,P(c,l,f.exitCode);if(f instanceof He)throw f.stdout=c+f.stdout,f.stderr=l+f.stderr,f;return P(c,`${l}${re(f)}
630
+ `,1)}return this.ctx.state.env=n,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,P(c,l,u)}async executeGroup(e,r=""){let n="",s="",i=0,o=this.ctx.state.groupStdin;r&&(this.ctx.state.groupStdin=r);try{for(let a of e.body){let c=await this.executeStatement(a);n+=c.stdout,s+=c.stderr,i=c.exitCode}}catch(a){if(this.ctx.state.groupStdin=o,a instanceof W)throw a;if(Nr(a)||a instanceof He||a instanceof X)throw a.prependOutput(n,s),a;return P(n,`${s}${re(a)}
631
+ `,1)}return this.ctx.state.groupStdin=o,P(n,s,i)}async executeArithmeticCommand(e){try{let r=await Z(this.ctx,e.expression.expression);return ce(r!==0)}catch(r){return B(`bash: arithmetic expression: ${r.message}
632
+ `)}}async executeConditionalCommand(e){try{let r=await at(this.ctx,e.expression);return ce(r)}catch(r){return B(`bash: conditional expression: ${r.message}
633
+ `,2)}}};var bt={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4};function nf(t){return t?{maxCallDepth:t.maxCallDepth??bt.maxCallDepth,maxCommandCount:t.maxCommandCount??bt.maxCommandCount,maxLoopIterations:t.maxLoopIterations??bt.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??bt.maxAwkIterations,maxSedIterations:t.maxSedIterations??bt.maxSedIterations,maxJqIterations:t.maxJqIterations??bt.maxJqIterations}:{...bt}}function sf(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function Iy(t){let e=sf(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function vy(t,e){let r=sf(t);if(!r)return!1;let n=Iy(e);return!n||r.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:r.pathname.startsWith(n.pathPrefix)}function Ei(t,e){return!e||e.length===0?!1:e.some(r=>vy(t,r))}var dr=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},hr=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},mr=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},Cn=class extends Error{constructor(e,r){super(`HTTP method '${e}' not allowed. Allowed methods: ${r.join(", ")}`),this.name="MethodNotAllowedError"}};var Ry=20,$y=3e4,Oy=["GET","HEAD"],Py=new Set(["GET","HEAD","OPTIONS"]),Ty=new Set([301,302,303,307,308]);function bi(t){let e=t.maxRedirects??Ry,r=t.timeoutMs??$y,n=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??Oy;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!Ei(a,t.allowedUrlPrefixes??[]))throw new dr(a)}function i(a){if(t.dangerouslyAllowFullInternetAccess)return;let c=a.toUpperCase();if(!n.includes(c))throw new Cn(c,n)}async function o(a,c={}){let l=c.method?.toUpperCase()??"GET";s(a),i(l);let u=a,f=0,p=c.followRedirects??!0,d=c.timeoutMs!==void 0?Math.min(c.timeoutMs,r):r;for(;;){let h=new AbortController,g=setTimeout(()=>h.abort(),d);try{let y={method:l,headers:c.headers,signal:h.signal,redirect:"manual"};c.body&&!Py.has(l)&&(y.body=c.body);let w=await fetch(u,y);if(Ty.has(w.status)&&p){let E=w.headers.get("location");if(!E)return await of(w,u);let b=new URL(E,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!Ei(b,t.allowedUrlPrefixes??[]))throw new mr(b);if(f++,f>e)throw new hr(e);u=b;continue}return await of(w,u)}finally{clearTimeout(g)}}}return o}async function of(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 kn=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;logger;state;constructor(e={}){let r=e.fs??new sr(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:`
634
+ `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:n,OLDPWD:n,...e.env};if(this.limits=nf({...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=bi(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:"",startTime:Date.now(),lastBackgroundPid:0,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},Gl(r,this.useDefaultLayout),n!=="/"&&r instanceof sr)try{r.mkdirSync(n,{recursive:!0})}catch{}for(let i of Ml(e.commands))this.registerCommand(i);if(e.network)for(let i of _l())this.registerCommand(i);if(e.customCommands)for(let i of e.customCommands)Bl(i)?this.registerCommand(Wl(i)):this.registerCommand(i)}registerCommand(e){this.commands.set(e.name,e);let r=this.fs;if(typeof r.writeFileSync=="function")try{r.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
630
635
  # Built-in command: ${e.name}
631
636
  `)}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.
632
637
  `,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(`
633
638
  `).map(a=>a.trimStart()).join(`
634
- `));try{let o=nt(i),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn},c=await new ur(a,s).executeScript(o);return this.logResult(c)}catch(o){if(o instanceof X)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,env:{...this.state.env,...r?.env}});if(o instanceof oe)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:1,env:{...this.state.env,...r?.env}});if(o instanceof H)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:H.EXIT_CODE,env:{...this.state.env,...r?.env}});if(o.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${o.message}
639
+ `));try{let o=st(i),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn},l=await new pr(a,s).executeScript(o);return this.logResult(l)}catch(o){if(o instanceof X)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,env:{...this.state.env,...r?.env}});if(o instanceof ae)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:1,env:{...this.state.env,...r?.env}});if(o instanceof W)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:W.EXIT_CODE,env:{...this.state.env,...r?.env}});if(o.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${o.message}
635
640
  `,exitCode:2,env:{...this.state.env,...r?.env}});if(o instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${o.message}
636
- `,exitCode:1,env:{...this.state.env,...r?.env}});throw o}}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 hg(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(`
637
- `).trim()}var mg=Gu.object({command:Gu.string().describe("The bash command to execute")});function jC(t={}){let e=new bn({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 dg({description:hg(t),inputSchema:pg(mg),execute:async({command:r})=>{t.onCall?.(r);let n=await e.exec(r);return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}}})}export{jC as createBashTool};
641
+ `,exitCode:1,env:{...this.state.env,...r?.env}});throw o}}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 Ly(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(`
642
+ `).trim()}var My=af.object({command:af.string().describe("The bash command to execute")});function xC(t={}){let e=new kn({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 Fy({description:Ly(t),inputSchema:Dy(My),execute:async({command:r})=>{t.onCall?.(r);let n=await e.exec(r);return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}}})}export{xC as createBashTool};
638
643
  /*! Bundled license information:
639
644
 
640
645
  ieee754/index.js: